"use client";
import { useRef, useState } from "react";

import { styleDefault } from "@/mui";
import ShareDI from "@/components/icons/ShareDI";
import { Box, Button, Modal } from "@mui/material";
import CloseModalD from "@/components/icons/CloseModalD";
import List from "./List";
import Poster from "../poster";

function Share({ data }) {
  const hiddenRef = useRef();
  const [open, setOpen] = useState(false);

  const handleOpen = () => setOpen(true);
  const handleClose = () => setOpen(false);

  return (
    <div className="w-full text-left">
      <Button
        className="!gap-1 !border-none lg:!border-[#EFEFEF] !p-2 !rounded-lg !text-[#525252] !text-[14px]"
        onClick={handleOpen}
        variant="outlined"
      >
        <ShareDI />
        <p className="hidden lg:flex">اشتراک گذاری</p>
      </Button>
      <div className="fixed min-w-[600px] min-h-[700px] w-[600px] h-[700px] top-0 left-0 opacity-0 pointer-events-none -z-10">
        <div ref={hiddenRef}>
          <Poster data={data} />
        </div>
      </div>
      <Modal open={open} onClose={handleClose}>
        <Box
          sx={styleDefault}
          className="!pt-[12px] md:!pt-[14px] lg:!py-[16px] !overflow-hidden
            !px-[12px] sm:!px-[16px] md:!px-[20px] lg:!px-[24px]
            !pb-[12px] sm:!pb-[16px] lg:!pb-[20px] !rounded-[8px]"
        >
          <div className="flex items-center justify-between w-full">
            <p className="text-[#3B3B3B] text-[14px] sm:text-[16px] md:text-[18px] lg:text-[20px] font-medium">
              اشتراک گذاری
            </p>
            <Button
              className="!min-w-0 !p-1"
              onClick={handleClose}
              variant="text"
            >
              <CloseModalD />
            </Button>
          </div>
          <span className="block h-px w-full bg-[#EFEFEF] mt-[8px] mb-[8px] sm:mb-[10px] md:mb-[12px] lg:mb-[14px]"></span>
          <p className="text-[#525252] text-[11px] md:text-[12px] lg:text-[14px] font-normal">
            شما می توانید این پزشک را با دیگران به اشتراک بگذارید:
          </p>
          <List hiddenRef={hiddenRef} />
        </Box>
      </Modal>
    </div>
  );
}

export default Share;
