Files
nobat724_front/components/doctors/index.js
T
2025-05-18 01:18:35 +03:30

75 lines
2.5 KiB
JavaScript

"use client";
import { useEffect, useState } from "react";
import SearchBar from "./search";
import SortList from "./sortlist";
import { Button } from "@mui/material";
import ListDoctors from "./listDoctors";
import LocationD from "../icons/LocationD";
import ModalSearchCity from "@/app/component/modalSearchCity";
// Data
import specialties from "@/data/specialties.json";
function DoctorsPage({ params, matchedCity, matchedState }) {
const [loading, setLoading] = useState(true);
const [open, setOpen] = useState(false);
const [selected, setSelected] = useState({
province: matchedState?.name || params?.province,
city: matchedCity?.name || params?.city,
});
const findItem = (name, value) =>
specialties.find((item) => item[name] === value);
const itemCategory = findItem("id", params.category);
const itemSpecialties = findItem("id", params.specialties);
const [data, setData] = useState({
category: itemCategory || "",
specialties: itemSpecialties
? { ...itemSpecialties, label: itemSpecialties.name }
: "",
turn: params && params.hasOwnProperty("turn") ? JSON.parse(params.turn) : 1,
gender: params.gender || "هر دو",
degree: params.degree || "متخصص",
});
useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 2000);
}, []);
return (
<div className="pt-[95px] sm:pt-[120px] padding-responsive">
<div className="flex justify-center gap-[16px] sm:gap-[19px] md:gap-[22px] lg:gap-[24px] flex-col items-center mt-0 md:mt-[40px] lg:mt-[90px]">
<ModalSearchCity
open={open}
setOpen={setOpen}
selected={selected}
setSelected={setSelected}
>
<Button
className="!flex !ml-auto !w-fit !px-3 !py-1 !items-center !justify-start !gap-2 !cursor-pointer"
onClick={() => setOpen(true)}
>
<LocationD />
<h1 className="text-[#525252] text-[16px] font-semibold">
{" "}
{selected.province || "استان"}
{" / "}
{selected.city || "شهر"}
</h1>
</Button>
</ModalSearchCity>
<div className="flex flex-col lg:flex-row items-start lg:items-center justify-center gap-[24px] lg:gap-[32px] w-full">
<SearchBar data={data} setData={setData} params={params} />
<SortList data={data} setData={setData} />
</div>
</div>
<ListDoctors loading={loading} />
</div>
);
}
export default DoctorsPage;