"use client"; import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead"; import { useWrStore } from "@/app/store"; import type { } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn"; import type { TableUpperProps } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; import { Input, Table, TableBody, TableCell, TableHeader, TableRow, } from "@common/components/ui"; import { useEffect, useState } from "react"; export function GuideDetailsTable({ chgRes, headList, type, setChGuidData, }: { chgRes: any[]; headList: TableUpperProps[]; type: string; setChGuidData: (chgRes: any[]) => void; }) { const { code, rainChkgdn } = useWrStore((state) => state); const [guidData, setGuidData] = useState(); const handleChange = ( rowIndex: number, field: any, value: string | number ) => { if(Number(value) < 0 ||! Number(value)){ value = 0; }else{ value = Number(value); } setGuidData((prevData) => prevData?.map((row, index) => { if (index === rowIndex) { return { ...row, [field as any]: value, }; } return row; }) ); }; const tableBody = (chgRes: any[] | []) => { return ( <> {chgRes.map((data, dataIndex) => ( {headList.map((head, headIndex) => ( {head.edit ===true && data.edit !==false? handleChange(dataIndex, head.id, e.target.value) } value={data[head.id as keyof any] ?? ""} /> : (
{data[head.id as keyof any] ?? ""}
) }
))}
))} ); }; useEffect(() => { setGuidData(chgRes); }, [chgRes]); useEffect(() => { setChGuidData(guidData??[] ); }, [guidData]); return ( <>
{headMakeprfmnc(headList, rainChkgdn?.rainHeadNm)} {tableBody(guidData ?? [])}
); }