import { Tariff, calcTariffPrice } from "@frontend/kitui"; import TariffCard from "./TariffCard"; import NumberIcon from "@icons/NumberIcon"; import { currencyFormatter } from "./currencyFormatter"; import FreeTariffCard from "./FreeTariffCard"; import { Typography } from "@mui/material"; export const createTariffElements = ( filteredTariffs: Tariff[], addFreeTariff = false, user: any, discounts: any, onclick: any, ) => { const tariffElements = filteredTariffs .filter((tariff) => tariff.privileges.length > 0) .map((tariff, index) => { const { priceBeforeDiscounts, priceAfterDiscounts } = calcTariffPrice( tariff, discounts, user.wallet.spent, [], user.isUserNko, user.id, ); return ( } buttonProps={{ text: "Выбрать", onClick: () => onclick({ id: tariff._id, price: priceAfterDiscounts / 100, }), }} headerText={tariff.name} text={tariff.privileges.map((p) => `${p.name} - ${p.amount}`)} price={ <> {priceBeforeDiscounts !== priceAfterDiscounts && ( {currencyFormatter.format(priceBeforeDiscounts / 100)} )} {currencyFormatter.format(priceAfterDiscounts / 100)} } /> ); }); if (addFreeTariff) { if (tariffElements.length < 6) tariffElements.push(); else tariffElements.splice(5, 0, ); } return tariffElements; };