import CustomTable from "@/app/component/CustomTable";
import Head from "@/components/dashboard/userAccount/components/Head";
import { useState } from "react";
import ModalAddHistory from "./modal";
import ItemHistory from "./ItemHistory";

function FamilyHistory({ data, changeData, loading, updateData }) {
  const family_history = data && data.other && data.other.family_history;
  const tableHead = ["ردیف", "بیماری", "نسبت خانوادگی", ""];
  const centerTable = [0];
  const [open, setOpen] = useState(false);

  return (
    <div className="opacity-page">
      <Head text="لیست سابقه خانوادگی بیماری">
        <ModalAddHistory
          open={open}
          setOpen={setOpen}
          loading={loading}
          changeData={changeData}
          updateData={updateData}
        />
      </Head>
      {family_history?.length ? (
        <CustomTable
          zeroRadius={true}
          tableHead={tableHead}
          centerTable={centerTable}
        >
          {family_history?.map((row, idx) => (
            <ItemHistory
              key={idx}
              row={row}
              idx={idx}
              changeData={changeData}
            />
          ))}
        </CustomTable>
      ) : (
        <p className="text-center py-10 text-gray-500">
          هیچ سابقه خانوادگی وجود ندارد!
        </p>
      )}
    </div>
  );
}

export default FamilyHistory;
