import { headMakeprfmnc } from "@/app/(with-layout)/ruseFcltMng/prfmncReg/chkgdnReg/TableHead"; import type { TableUpperProps } from "@/app/store/common/type/header"; import type { chHeadType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList"; import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; import { DatePicker, SelectBox, type SelectDataType, } from "@common/business_components/ui"; import { Checkbox, Input, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@common/components/ui"; import React, { useEffect, useState } from "react"; type RuseMngTableProps = { tableData: any[]; headList: TableUpperProps[]; upHeadList: chHeadType[]; code?: { name: string; val: SelectDataType[] }[]; onTableSet?: (item: any) => void; indexMng?: number; indexBiz?: number; }; const RuseMngTable = React.forwardRef( ( { tableData, headList, upHeadList, code, onTableSet, indexMng, indexBiz }, ref ) => { const [tableState, setTableState] = useState([...tableData]); useEffect(() => { if (ref && typeof ref === "object" && "current" in ref) { ref.current = tableState; } if (onTableSet) onTableSet(tableState); }, [tableState, onTableSet]); useEffect(() => { if (tableData) setTableState(tableData); }, [tableData]); return ( <> {upHeadList ? ( headMakeprfmnc(headList, upHeadList) ) : ( {headList.map((head) => ( {head.title} ))} )} {tableState.map((item, i) => ( {headList.map((head, j) => ( {}} > {head.edit === true ? ( { setTableState((prev) => { const next = [...prev]; next[i] = { ...next[i], [head.id]: txt.target.value, }; return next; }); }} value={ head.type === "number" ? Number(tableState[i][head.id]) || 0 : tableState[i][head.id] || "" } /> ) : head.type === "select" ? ( item.name === head.selectData) ?.val ?? [] } value={tableState[i][head.id] || ""} className={""} selectClass={selectClass} onSelectValue={(val) => { setTableState((prev) => { prev[i][head.id] = val; return [...prev]; }); }} > ) : head.type === "date" ? ( { setTableState((prev) => { const next = [...prev]; next[i] = { ...next[i], [head.id]: date }; return next; }); }, }} selectClass={"w-full"} /> ) : head.type === "checkbox" ? ( { console.log("checked", checked); setTableState((prev) => { prev[i][head.id] = checked; return [...prev]; }); }} > ) : ( `${item[head.id] || ""}` )} ))} ))}
); } ); RuseMngTable.displayName = "RuseMngTable"; export default RuseMngTable;