import { Divider, message } from "antd"; import ProCheckboxGroups from "components/ProCheckboxGroups/ProCheckboxGroups"; import ProText from "components/ProText"; import { Dispatch, SetStateAction } from "react"; import { useTranslation } from "react-i18next"; import { useAppSelector } from "redux/hooks"; import { Extra4, TheExtrasGroup } from "utils/types/appTypes"; import styles from "../product.module.css"; export default function ExtraGroups({ groupsList, selectedExtrasByGroup, setSelectedExtrasByGroup, }: { groupsList: TheExtrasGroup[]; selectedExtrasByGroup: Record; setSelectedExtrasByGroup: Dispatch>>; }) { const { isRTL } = useAppSelector((state) => state.locale); const { t } = useTranslation(); return ( <> {groupsList.length > 0 && (
{t("menu.youMightAlsoLike")} {t("menu.optional")}
{/* {t("menu.choose1")} */}
)} {groupsList?.map((group: TheExtrasGroup) => (
{isRTL ? group.nameAR : group.name}
{group.force_limit_selection === 1 ? "Required" : "Optional"} ({selectedExtrasByGroup[group.id]?.length || 0}/{group.limit})
{group.force_limit_selection === 1 && ( * You must select exactly {group.limit} option {group.limit > 1 ? "s" : ""} )}
({ value: extra.id.toString(), label: isRTL ? extra.name : extra.nameAR, price: `+${extra.price}`, }))} value={selectedExtrasByGroup[group.id] || []} onChange={(values: string[]) => { // Check if the new selection would exceed the limit if (values.length > group.limit) { message.error( `You can only select up to ${group.limit} option${group.limit > 1 ? "s" : ""} from this group.` ); return; } setSelectedExtrasByGroup((prev) => ({ ...prev, [group.id]: values, })); }} />
))} ); }