import { Box, useMediaQuery, useTheme } from "@mui/material"
import { NavCard } from "./components/NavCard"
import { createTariffElements } from "./tariffsUtils/createTariffElements"
import SmallIconPena from "@/assets/icons/SmallIconPena"

interface TariffCardDisplaySelectorProps {
    content: {
        title: string,
        onClick: () => void
    }[]
    selectedItem: TypePages
    tariffs: any[]
    user: any
    discounts: any[]
    openModalHC: (tariffInfo: any) => void
    userPrivilegies: any
    startRequestCreate: () => void
}

export const TariffCardDisplaySelector = ({
    content,
    selectedItem,
    tariffs,
    user,
    discounts,
    openModalHC,
    userPrivilegies,
    startRequestCreate
}: TariffCardDisplaySelectorProps) => {
    const theme = useTheme()
    const isTablet = useMediaQuery(theme.breakpoints.down(1000));
    const sendRequest = userPrivilegies?.quizManual?.amount > 0 ? startRequestCreate : undefined

    switch (selectedItem) {
        case "dop":
            return <Box
                sx={{
                    display: "flex",
                    flexWrap: "wrap",
                    width: "100%"
                }}>
                {content.map(data => <NavCard {...data} key={data.title} />)}
            </Box>

        case "hide":
            const filteredBadgeTariffs = tariffs.filter((tariff) => {
                return (
                    tariff.privileges[0].serviceKey === "squiz" &&
                    !tariff.isDeleted &&
                    !tariff.isCustom &&
                    tariff.privileges[0].privilegeId === "squizHideBadge" &&
                    tariff.privileges[0]?.type === "day"
                );
            });
            return createTariffElements(
                filteredBadgeTariffs,
                false,
                user,
                discounts,
                openModalHC,
            )

        case "create":
            const filteredCreateTariffs = tariffs.filter((tariff) => {
                return (
                    tariff.privileges[0].serviceKey === "squiz" &&
                    !tariff.isDeleted &&
                    !tariff.isCustom &&
                    tariff.privileges[0].privilegeId === "quizManual" &&
                    tariff.privileges[0]?.type === "count"
                );
            });
            return createTariffElements(
                filteredCreateTariffs,
                false,
                user,
                discounts,
                openModalHC,
                sendRequest,
                true,
                <SmallIconPena />
            )

        case "premium":
            const filteredPremiumTariffs = tariffs.filter((tariff) => {
                return (
                    tariff.privileges[0].serviceKey === "squiz" &&
                    !tariff.isDeleted &&
                    !tariff.isCustom &&
                    tariff.privileges[0].privilegeId === "squizPremium" &&
                    tariff.privileges[0]?.type === "day"
                );
            });
            return createTariffElements(
                filteredPremiumTariffs,
                false,
                user,
                discounts,
                openModalHC,
            )

        case "analytics":
            const filteredAnalyticsTariffs = tariffs.filter((tariff) => {
                return (
                    tariff.privileges[0].serviceKey === "squiz" &&
                    !tariff.isDeleted &&
                    !tariff.isCustom &&
                    tariff.privileges[0].privilegeId === "squizAnalytics" &&
                    tariff.privileges[0]?.type === "count"
                );
            });
            return createTariffElements(
                filteredAnalyticsTariffs,
                false,
                user,
                discounts,
                openModalHC,
            )

        case "custom":
            const filteredCustomTariffs = tariffs.filter((tariff) => {
                return (
                    tariff.privileges[0].serviceKey === "squiz" &&
                    !tariff.isDeleted &&
                    tariff.isCustom &&
                    tariff.privileges[0]?.type === "day"
                );
            });
            return createTariffElements(
                filteredCustomTariffs,
                false,
                user,
                discounts,
                openModalHC,
            )

        default:
            return <Box
                sx={{
                    display: "flex",
                    flexWrap: "wrap",
                    width: "100%"
                }}>
                {content.map(data => <NavCard {...data} key={data.title} />)}
            </Box>
    }
} 