import { Button } from "antd"; import { ProBottomSheet } from "components/ProBottomSheet/ProBottomSheet.tsx"; import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import ProText from "components/ProText"; import ArabicPrice from "components/ArabicPrice"; import { selectCart, selectGrandTotal, updateSplitBillAmount, } from "features/order/orderSlice"; import { useAppDispatch, useAppSelector } from "redux/hooks"; import { ProGray1 } from "ThemeConstants"; import PayForActions from "../../../split-bill/components/PayForActions"; import TotalPeopleActions from "../../../split-bill/components/TotalPeopleActions"; import styles from "./SplitBill.module.css"; interface SplitBillChoiceBottomSheetProps { isOpen: boolean; onClose: () => void; onSave?: (value: string) => void; onRemoveSplitWay?: () => void; } interface SplitBillTmp { totalPeople?: number; payFor?: number; } export function EqualltyChoiceBottomSheet({ isOpen, onClose, onRemoveSplitWay, }: SplitBillChoiceBottomSheetProps) { const { t } = useTranslation(); const dispatch = useAppDispatch(); const { tmp, splitBillAmount } = useAppSelector(selectCart); const grandTotal = useAppSelector(selectGrandTotal); const splitBillTmp = tmp as SplitBillTmp; const totalPeople = splitBillTmp?.totalPeople || 2; const payFor = splitBillTmp?.payFor || 1; // Calculate original total bill (grandTotal already subtracts splitBillAmount) const originalTotalBill = grandTotal + splitBillAmount; // Calculate split amount based on original total bill const splitAmount = useMemo(() => { if (totalPeople > 0) { return (originalTotalBill / totalPeople) * payFor; } return 0; }, [originalTotalBill, totalPeople, payFor]); const handleSave = () => { dispatch(updateSplitBillAmount(splitAmount)); onClose(); }; const handleRemoveSplitWay = () => { dispatch(updateSplitBillAmount(0)); onRemoveSplitWay?.(); onClose(); }; return (
{/* Spinner Visualization - Blank Spin Wheel */} {totalPeople > 0 && (
{Array.from({ length: totalPeople }).map((_, index) => { const anglePerSlice = 360 / totalPeople; const startAngle = index * anglePerSlice; const endAngle = (index + 1) * anglePerSlice; const isSelected = index < payFor; // Convert angles to radians const startAngleRad = (startAngle * Math.PI) / 180; const endAngleRad = (endAngle * Math.PI) / 180; // Calculate path for pie slice (fit 200x200 viewBox) const radius = 90; const centerX = 100; const centerY = 100; const x1 = centerX + radius * Math.cos(startAngleRad); const y1 = centerY + radius * Math.sin(startAngleRad); const x2 = centerX + radius * Math.cos(endAngleRad); const y2 = centerY + radius * Math.sin(endAngleRad); const largeArcFlag = anglePerSlice > 180 ? 1 : 0; const pathData = [ `M ${centerX} ${centerY}`, `L ${x1} ${y1}`, `A ${radius} ${radius} 0 ${largeArcFlag} 1 ${x2} ${y2}`, "Z", ].join(" "); return ( ); })} {/* Center circle with total bill amount */}
{t("splitBill.totalBill")}
)}
{t("checkout.totalPeople")} {t("checkout.totalPeople")}
{t("checkout.payFor")} {t("checkout.payFor")}
{t("splitBill.yourShare")}
); }