import { Form, Layout } from "antd";
import InputCard from "components/InputCard";
import OrderSummary from "components/OrderSummary/OrderSummary";
import PaymentMethods from "components/PaymentMethods/PaymentMethods";
import ProHeader from "components/ProHeader/ProHeader";
import { selectCart, updateCollectionMethod } from "features/order/orderSlice";
import { useTranslation } from "react-i18next";
import { useAppSelector } from "redux/hooks";
import styles from "../address/address.module.css";
import { AddressSummary } from "./components/AddressSummary";
import BriefMenu from "./components/BriefMenu";
import CheckoutButton from "./components/CheckoutButton";
import { GiftCard } from "./components/GiftCard";
import PhoneCard from "./components/phoneCard";
import { OrderType } from "./hooks/types";
import RewardWaiterCard from "pages/cart/components/RewardWaiterCard";
import ProInputCard from "components/ProInputCard/ProInputCard";
import ProRatioGroups from "components/ProRatioGroups/ProRatioGroups";
import CouponCard from "pages/cart/components/CouponCard";

export default function CheckoutPage() {
  const { t } = useTranslation();
  const [form] = Form.useForm();
  const { phone, order, orderType, collectionMethod } =
    useAppSelector(selectCart);
  const { token } = useAppSelector((state) => state.auth);
  return (
    <>
      <Form
        form={form}
        initialValues={{
          phone,
        }}
        layout="vertical"
      >
        <Layout>
          <ProHeader>{t("checkout.title")}</ProHeader>
          <Layout.Content className={styles.checkoutContainer}>
            <AddressSummary />
            {!token && <PhoneCard />}
            {orderType === OrderType.ToRoom && (
              <InputCard
                title={t("address.roomNo")}
                name="roomNumber"
                placeholder={t("address.roomNo")}
                value={order?.roomNumber}
              />
            )}
            {orderType === OrderType.ToOffice && (
              <InputCard
                title={t("address.officeNo")}
                name="officeNumber"
                placeholder={t("address.officeNo")}
                value={order?.officeNumber}
              />
            )}
            {orderType === OrderType.Gift && <GiftCard />}
            {/* <RoomDetails />
            <OfficeDetails /> */}
            {/* <GiftDetails /> */}
            {/* <BriefMenu /> */}
            <PaymentMethods />
            <CouponCard />

            {/* Collection Method */}
            {orderType === OrderType.Pickup && (
              <ProInputCard title={t("cart.collectionMethod")}>
                <Form.Item
                  name="collectionMethod"
                  required
                  rules={[
                    {
                      required: true,
                      message: t("cart.pleaseSelectCollectionMethod"),
                    },
                  ]}
                >
                  <ProRatioGroups
                    options={[
                      { label: t("cart.Cash"), value: "cod", price: "" },
                      {
                        label: t("cart.e-payment"),
                        value: "paymentgateway",
                        price: "",
                      },
                    ]}
                    value={collectionMethod}
                    onRatioClick={(value) => {
                      if (value === "cod") {
                        updateCollectionMethod(value);
                      } else {
                        updateCollectionMethod(value);
                      }
                    }}
                  />
                </Form.Item>
              </ProInputCard>
            )}

            {/* Reward Your Waiter */}
            <RewardWaiterCard />
            <OrderSummary />
          </Layout.Content>

          <CheckoutButton form={form} />
        </Layout>
      </Form>
    </>
  );
}
