import { Button } from "@mui/material";
import SearchD from "@/components/icons/SearchD";
import { useState } from "react";
import specialties from "@/data/specialties.json";

function SendReq({ filter, setFilter, setDataInURL, sendReq }) {
  const [loading, setLoading] = useState(false);
  // const checkName = () => {
  //   let newFilter = filter;
  //   const specialtyItem =
  //     filter.name &&
  //     specialties.find((item) => item.name.includes(filter.name));

  //   if (specialtyItem) {
  //     if (specialtyItem.parent) {
  //       newFilter.specialty = specialtyItem;
  //       newFilter.category = specialties.find(
  //         (item) => item.id === specialtyItem.parent
  //       );
  //     } else {
  //       newFilter.specialty = specialtyItem;
  //     }
  //   }

  //   return newFilter;
  // };

  const filterData = () => {
    setLoading(true);
    // const newFilter = checkName();
    // setFilter(filter);
    // setDataInURL(filter);

    sendReq(filter).finally(() => {
      setLoading(false);
    });
  };

  return (
    <Button
      disabled={loading}
      onClick={filterData}
      aria-label="جستجوی پزشک"
      className="!flex !m-1 !rounded-[4px] !w-[36px] sm:!w-[42px] md:!w-[49px] lg:!w-[56px] !min-w-[36px] sm:!min-w-[42px] md:!min-w-[49px] lg:!min-w-[56px] !gap-2.5 !p-2.5 md:!p-4 !h-[calc(100%_-_8px)]"
    >
      <div className="w-[24px] h-[24px] min-w-[24px] min-h-[24px]">
        {!loading && <SearchD />}
      </div>
    </Button>
  );
}

export default SendReq;
