import { Text, Textinput } from '@/components';
import PaymentTab from '@/components/Cards/PaymentsTab';
import CustomModal from '@/components/CustomModal';
import Button from '@/components/ui/Button';
import PageHeader from '@/components/ui/PageHeader';
import Head from 'next/head';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useState } from 'react';
import { Card, Col, Form, Row } from 'react-bootstrap';
import InputMask from 'react-input-mask'; // Importing react-input-mask
import style from './index.module.scss';

const PaymentMethod = () => {
  // State for controlling modal visibility
  const [show, setShow] = useState(false);
  const [bookedSuccessfully, setBookedSuccessfully] = useState<boolean>(false);

  // Functions to open and close the modal
  const handleShow = () => setShow(true);
  const handleClose = () => setShow(false);

  const router = useRouter();

  return (
    <>
      <Head>
        <title>Payment Method | Deliver X</title>
      </Head>
      <>
        <PageHeader title="Payment Method" isShowBackButton />

        <Row className="mt-4">
          <Col xl={10} xxl={8} className="">
            <Card.Body className={`${style.paymentCard} p-3 `}>
              <h6 className="fs-sm-5">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do.
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do.
              </h6>

              <ul className="list-group">
                <li className="list-group-item">
                  <h6>Price</h6>
                  <h5>$ 25.00</h5>
                </li>
                <li className="list-group-item">
                  <h6>Tax</h6>
                  <h5>$2.30</h5>
                </li>
                <li className="list-group-item">
                  <h6>Subtotal (incl.VAT)</h6>
                  <h3 className="fw-bolder fs-4">$27.30</h3>
                </li>
              </ul>

              <div className="row mt-3 gy-3">
                <div className="col-md-6">
                  <PaymentTab
                    image="/images/icons/google-pay.png"
                    title="**** **** **** 1234"
                  />
                </div>
                <div className="col-md-6">
                  <PaymentTab
                    image="/images/icons/paypal-icon.png"
                    title="**** **** **** 1234"
                  />
                </div>
                <div className="col-md-6">
                  <PaymentTab
                    image="/images/icons/apple-pay-icon.png"
                    title="**** **** **** 1234"
                  />
                </div>
                <div className="col-md-6">
                  {/* <PaperCard
                    className={`${style.paymentItemCard} h-100 d-flex  ps-sm-3 justify-content-start align-items-center gap-2`}
                    onClick={handleShow}
                  >
                    <img src="/images/icons/cards.png" alt="" />
                    <h5 className="mb-0 fs-5 fw-bolder">Add New Card</h5>
                  </PaperCard> */}

                  <PaymentTab
                    image="/images/icons/cards.png"
                    title="Add New Card"
                    onClick={handleShow}
                    isCheckedFunctionality
                  />
                </div>
              </div>
            </Card.Body>

            <Button
              className="btn btn-feature mt-3"
              onClick={() => setBookedSuccessfully(true)}
              size="md"
            >
              Confirm Payment
            </Button>
          </Col>
        </Row>
      </>

      {/* Modal for adding new card */}
      <CustomModal show={show} size="lg" handleClose={handleClose} isCloseBtn>
        <div className="p-sm-3 p-2">
          <div className="modal-head text-center">
            <h4 className="fs-3 fw-bolder mb-0">Add Card</h4>
          </div>

          <Row>
            <Col md={12}>
              <Form.Group controlId="formEmail" className="mt-4 w-100">
                <Form.Label className="">Card Holder</Form.Label>
                <Textinput
                  type="text"
                  placeholder="John Smith"
                  inputGroupBoxCss="w-100"
                />
              </Form.Group>
            </Col>
            <Col md={12}>
              <Form.Group controlId="formEmail" className="mt-4 w-100">
                <Form.Label className="">Card Number</Form.Label>
                <InputMask
                  mask="9999 9999 9999 9999"
                  maskChar=" "
                  alwaysShowMask={false}
                >
                  {(inputProps: any) => (
                    <Textinput
                      {...inputProps}
                      type="text"
                      placeholder="**** **** **** ***4"
                      inputGroupBoxCss="w-100"
                    />
                  )}
                </InputMask>
              </Form.Group>
            </Col>
            <Col md={6}>
              <Form.Group controlId="formEmail" className="mt-4 w-100">
                <Form.Label className="">Exp Month</Form.Label>
                <InputMask mask="99" maskChar=" " alwaysShowMask={false}>
                  {(inputProps: any) => (
                    <Textinput
                      {...inputProps}
                      type="text"
                      placeholder="07"
                      inputGroupBoxCss="w-100"
                    />
                  )}
                </InputMask>
              </Form.Group>
            </Col>
            <Col md={6}>
              <Form.Group controlId="formEmail" className="mt-4 w-100">
                <Form.Label className="">Exp Year</Form.Label>
                <InputMask mask="9999" maskChar=" " alwaysShowMask={false}>
                  {(inputProps: any) => (
                    <Textinput
                      {...inputProps}
                      type="text"
                      placeholder="2028"
                      inputGroupBoxCss="w-100"
                    />
                  )}
                </InputMask>
              </Form.Group>
            </Col>
            <Col md={12}>
              <Form.Group controlId="formEmail" className="mt-4 w-100">
                <Form.Label className="">CVC</Form.Label>
                <InputMask mask="999" maskChar=" " alwaysShowMask={false}>
                  {(inputProps) => (
                    <Textinput
                      {...inputProps}
                      type="text"
                      placeholder="565"
                      inputGroupBoxCss="w-100"
                    />
                  )}
                </InputMask>
              </Form.Group>
            </Col>

            <Col md={12} className="mt-5">
              <div className="text-center">
                <Button
                  onClick={() => handleClose()}
                  className="btn btn-feature"
                  size="lg"
                >
                  Add
                </Button>
              </div>
            </Col>
          </Row>
        </div>
      </CustomModal>

      <CustomModal
        show={bookedSuccessfully}
        handleClose={() => setBookedSuccessfully(false)}
        className="text-center"
      >
        <div className="d-flex flex-column justify-content-center align-items-center gap-2">
          <Image
            src={'/images/icons/checked-icon.svg'}
            width={100}
            height={100}
            alt="checkked-icon"
          />
          <Text size={{ default: '20px', sm: '30px' }} weight={'bold'}>
            Booked Successfully
          </Text>
          <Text size={{ default: '16px', sm: '18px' }} color="#777">
            Your request for delivery service is booked successfully
          </Text>
          <Button
            className="btn btn-feature mt-4 UrbanistRegular"
            onClick={() =>
              router.push('/user/booking-overview/pending')
            }
            size="lg"
          >
            Done
          </Button>
        </div>
      </CustomModal>
    </>
  );
};

export default PaymentMethod;
