import { Card, Divider, Space } from "antd";
import ArabicPrice from "components/ArabicPrice";
import ProText from "components/ProText";
import {
    selectCart,
    selectGrandTotal
} from "features/order/orderSlice";
import { useTranslation } from "react-i18next";
import { useAppSelector } from "redux/hooks";
import { ProGray1 } from "ThemeConstants";
import styles from "../SplitBillPage.module.css";

interface SplitBillTmp {
  totalPeople?: number;
  payFor?: number;
}

export default function PaymentSummary() {
  const { t } = useTranslation();
  const { tmp } = useAppSelector(selectCart);
  const total = useAppSelector(selectGrandTotal);

  const costPerPerson = total / ((tmp as SplitBillTmp)?.totalPeople || 1);
  const remainingAmount = total - ((tmp as SplitBillTmp)?.payFor || 1) * costPerPerson;

  return (
    <Card className={`${styles.orderSummary}`}>
      <Space direction="vertical" style={{ width: "100%" }}>
        <div className={styles.summaryRow}>
          <ProText style={{ color: ProGray1 }}>
            {t("checkout.remainingAmount")}
          </ProText>
          <ArabicPrice price={remainingAmount} style={{ color: ProGray1 }} />
        </div>

        <Divider className={styles.summaryDivider} />
        <div className={`${styles.summaryRow} ${styles.totalRow}`}>
          <ProText strong>{t("checkout.totalAmount")}</ProText>
          <ArabicPrice price={total} strong />
        </div>
      </Space>
    </Card>
  );
}
