2024-03-27 10:53:47 +00:00
|
|
|
import { Tariff, calcTariffPrice } from "@frontend/kitui";
|
2024-01-03 19:41:41 +00:00
|
|
|
import TariffCard from "./TariffCard";
|
|
|
|
import NumberIcon from "@icons/NumberIcon";
|
|
|
|
import { currencyFormatter } from "./currencyFormatter";
|
|
|
|
import FreeTariffCard from "./FreeTariffCard";
|
2024-01-09 12:00:42 +00:00
|
|
|
import { Typography } from "@mui/material";
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
|
|
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) => {
|
2024-03-27 10:53:47 +00:00
|
|
|
const { priceBeforeDiscounts, priceAfterDiscounts } = calcTariffPrice(
|
|
|
|
tariff,
|
|
|
|
discounts,
|
2024-04-14 17:05:01 +00:00
|
|
|
user.wallet.spent,
|
2024-04-05 21:05:51 +00:00
|
|
|
[],
|
2024-04-14 17:05:01 +00:00
|
|
|
user.isUserNko,
|
2024-04-14 17:38:30 +00:00
|
|
|
user.userId,
|
2024-03-27 10:53:47 +00:00
|
|
|
);
|
2024-01-03 19:41:41 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TariffCard
|
|
|
|
key={tariff._id}
|
|
|
|
discount={
|
|
|
|
priceBeforeDiscounts - priceAfterDiscounts
|
|
|
|
? `${(
|
|
|
|
(priceBeforeDiscounts - priceAfterDiscounts) /
|
2024-04-12 17:48:53 +00:00
|
|
|
(Math.trunc(priceBeforeDiscounts) / 100)
|
2024-01-03 19:41:41 +00:00
|
|
|
).toFixed(0)}%`
|
|
|
|
: ""
|
|
|
|
}
|
|
|
|
icon={
|
|
|
|
<NumberIcon
|
|
|
|
number={index + 1}
|
|
|
|
color={"#7e2aea"}
|
|
|
|
backgroundColor={"#EEE4FC"}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
buttonProps={{
|
|
|
|
text: "Выбрать",
|
2024-01-03 22:55:01 +00:00
|
|
|
onClick: () =>
|
2024-02-11 19:21:12 +00:00
|
|
|
onclick({
|
|
|
|
id: tariff._id,
|
2024-04-12 17:48:53 +00:00
|
|
|
price: Math.trunc(priceAfterDiscounts) / 100,
|
2024-02-11 19:21:12 +00:00
|
|
|
}),
|
2024-01-03 19:41:41 +00:00
|
|
|
}}
|
|
|
|
headerText={tariff.name}
|
2024-04-14 22:35:08 +00:00
|
|
|
text={tariff.description}
|
2024-01-03 19:41:41 +00:00
|
|
|
price={
|
|
|
|
<>
|
|
|
|
{priceBeforeDiscounts !== priceAfterDiscounts && (
|
2024-01-16 18:58:39 +00:00
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
textDecorationLine: "line-through",
|
|
|
|
color: "#FB5607",
|
|
|
|
fontSize: "15px",
|
|
|
|
lineHeight: "21px",
|
|
|
|
}}
|
|
|
|
>
|
2024-04-12 17:48:53 +00:00
|
|
|
{currencyFormatter.format(Math.trunc(priceBeforeDiscounts) / 100)}
|
2024-01-03 19:41:41 +00:00
|
|
|
</Typography>
|
|
|
|
)}
|
2024-01-16 18:58:39 +00:00
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
fontWeight: 500,
|
|
|
|
fontSize: "20px",
|
|
|
|
lineHeight: "24px",
|
|
|
|
color: "#4D4D4D",
|
|
|
|
}}
|
|
|
|
>
|
2024-04-12 17:48:53 +00:00
|
|
|
{currencyFormatter.format(Math.trunc(priceAfterDiscounts) / 100)}
|
2024-01-03 19:41:41 +00:00
|
|
|
</Typography>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (addFreeTariff) {
|
|
|
|
if (tariffElements.length < 6)
|
|
|
|
tariffElements.push(<FreeTariffCard key="free_tariff_card" />);
|
|
|
|
else tariffElements.splice(5, 0, <FreeTariffCard key="free_tariff_card" />);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tariffElements;
|
|
|
|
};
|