import { createSearch, decodeHtmlEntities } from 'common/string';
import { Fragment } from 'inferno';
import { useBackend, useLocalState } from '../backend';
import { Box, Button, Flex, Input, Section, Table, Tabs, NoticeBox, LabeledList } from '../components';
import { formatMoney } from '../format';
import { Window } from '../layouts';
const MAX_SEARCH_RESULTS = 25;
export const Uplink = (props, context) => {
const { data } = useBackend(context);
const [screen, setScreen] = useLocalState(context, 'screen', 0);
const { telecrystals } = data;
return (
{(screen === 0 && ) ||
(screen === 1 && ) || }
);
};
const UplinkHeader = (props, context) => {
const { act, data } = useBackend(context);
const { screen, setScreen } = props;
const { discount_name, discount_amount, offer_expiry } = data;
return (
setScreen(0)}>
Request Items
setScreen(1)}>
Exploitable Information
{(discount_amount < 100 && (
{discount_name} - {discount_amount}% off. Offer expires at: {offer_expiry}
)) || No items currently discounted.}
);
};
const ExploitableInformation = (props, context) => {
const { act, data } = useBackend(context);
const { exploit, locked_records } = data;
return (
act('view_exploits', { id: 0 })} />}>
{(exploit && (
{exploit.name}
{exploit.sex}
{exploit.species}
{exploit.age}
{exploit.rank}
{exploit.home_system}
{exploit.birthplace}
{exploit.citizenship}
{exploit.faction}
{exploit.religion}
{exploit.fingerprint}
{exploit.antagfaction}
Acquired Information
{exploit.nanoui_exploit_record.split('
').map((m) => (
{m}
))}
)) ||
locked_records.map((record) => (
);
};
export const GenericUplink = (props, context) => {
const { currencyAmount = 0, currencySymbol = '₮' } = props;
const { act, data } = useBackend(context);
const { compactMode, lockable, categories = [] } = data;
const [searchText, setSearchText] = useLocalState(context, 'searchText', '');
const [selectedCategory, setSelectedCategory] = useLocalState(context, 'category', categories[0]?.name);
const testSearch = createSearch(searchText, (item) => {
return item.name + item.desc;
});
const items =
(searchText.length > 0 &&
// Flatten all categories and apply search to it
categories
.flatMap((category) => category.items || [])
.filter(testSearch)
.filter((item, i) => i < MAX_SEARCH_RESULTS)) ||
// Select a category and show all items in it
categories.find((category) => category.name === selectedCategory)?.items ||
// If none of that results in a list, return an empty list
[];
return (
);
};
const ItemList = (props, context) => {
const { compactMode, currencyAmount, currencySymbol } = props;
const { act } = useBackend(context);
const [hoveredItem, setHoveredItem] = useLocalState(context, 'hoveredItem', {});
const hoveredCost = (hoveredItem && hoveredItem.cost) || 0;
// Append extra hover data to items
const items = props.items.map((item) => {
const notSameItem = hoveredItem && hoveredItem.name !== item.name;
const notEnoughHovered = currencyAmount - hoveredCost < item.cost;
const disabledDueToHovered = notSameItem && notEnoughHovered;
const disabled = currencyAmount < item.cost || disabledDueToHovered;
return {
...item,
disabled,
};
});
if (compactMode) {
return (
{items.map((item) => (
{decodeHtmlEntities(item.name)}
))}
);
}
return items.map((item) => (
setHoveredItem(item)}
onmouseout={() => setHoveredItem({})}
onClick={() =>
act('buy', {
ref: item.ref,
})
}
/>
}>
{decodeHtmlEntities(item.desc)}
));
};