import { Fragment } from 'inferno';
import { useBackend, useLocalState } from '../backend';
import { Box, Button, LabeledList, ProgressBar, Modal, Section, Dropdown, AnimatedNumber, NoticeBox, Table } from '../components';
import { Window } from '../layouts';
const NIF_WORKING = 0;
const NIF_POWFAIL = 1;
const NIF_TEMPFAIL = 2;
const NIF_INSTALLING = 3;
const NIF_PREINSTALL = 4;
const validThemes = ['abductor', 'cardtable', 'hackerman', 'malfunction', 'ntos', 'paper', 'retro', 'syndicate'];
export const NIF = (props, context) => {
const { act, config, data } = useBackend(context);
const { theme, last_notification } = data;
const [settingsOpen, setSettingsOpen] = useLocalState(context, 'settingsOpen', false);
const [viewingModule, setViewing] = useLocalState(context, 'viewingModule', null);
return (
{!!last_notification && (
{last_notification}
)}
{!!viewingModule && (
{
act('uninstall', { module: viewingModule.ref });
setViewing(null);
}}
/>
)}
setSettingsOpen(!settingsOpen)}
/>
}>
{(settingsOpen && ) || }
);
};
const getNifCondition = (nif_stat, nif_percent) => {
switch (nif_stat) {
case NIF_WORKING:
if (nif_percent < 25) {
return 'Service Needed Soon';
} else {
return 'Operating Normally';
}
break;
case NIF_POWFAIL:
return 'Insufficient Energy!';
break;
case NIF_TEMPFAIL:
return 'System Failure!';
break;
case NIF_INSTALLING:
return 'Adapting To User';
break;
}
return 'Unknown';
};
const getNutritionText = (nutrition, isSynthetic) => {
if (isSynthetic) {
if (nutrition >= 450) {
return 'Overcharged';
} else if (nutrition >= 250) {
return 'Good Charge';
}
return 'Low Charge';
}
if (nutrition >= 250) {
return 'NIF Power Requirement met.';
} else if (nutrition >= 150) {
return 'Fluctuations in available power.';
}
return 'Power failure imminent.';
};
const NIFMain = (props, context) => {
const { act, config, data } = useBackend(context);
const { nif_percent, nif_stat, last_notification, nutrition, isSynthetic, modules } = data;
const { setViewing } = props;
return (
{getNifCondition(nif_stat, nif_percent)} (
%)
{getNutritionText(nutrition, isSynthetic)}
{modules.map((module) => (
act('uninstall', { module: module.ref })}
/>
))}
);
};
const NIFSettings = (props, context) => {
const { act, data } = useBackend(context);
const { theme } = data;
return (
act('setTheme', { theme: val })}
/>
);
};