import specialties from "@/data/specialties.json";
import Form from "./form";

function Content({ filter, setFilter, updateData, setDataInURL }) {
  const changeSpecialty = (name, value) => {
    const newFilter = { ...filter, [name]: value };

    if (name === "category") {
      if (value) {
        const filtered = specialties
          .filter((item) => item.parent_id)
          .filter((item) => String(item.parent_id) === String(value.id));
        newFilter.specialty = filtered[0] || null;
      } else {
        newFilter.specialty = null;
      }
    }

    setFilter(newFilter);
    setDataInURL(newFilter);
    return newFilter;
  };

  return (
    <div className="mt-[50px] px-[0px] md:px-[19px] lg:px-[38px] mb-[32px]">
      <Form
        filter={filter}
        updateData={updateData}
        changeSpecialty={changeSpecialty}
      />
    </div>
  );
}

export default Content;
