import UiPageNations from "@common/business_components/ui/table/uiPageNations"; import { Table, TableBody, TableCell, TableRow } from "@common/components"; import { useEffect, useState } from "react"; type UiTableProps = { headName: React.ReactNode | undefined; tableData: { [key: string]: string | number | boolean | object }[]; headlist: UiHeadProps[]; pageSize: number; total: number; children: Record | undefined; cellClick: ((index: number | undefined, headId: string) => void) | undefined; onPageChange: (page: number) => void; className?: string; resetPageNo?: boolean; isEditable?: boolean; }; type UiHeadProps = { id: string; title: string; align?: string; type?: string; options?: string[]; }; export function VerticalTable({ tableData, headlist, pageSize, total, children, headName, cellClick, onPageChange, className = "", resetPageNo = false, isEditable = false, }: UiTableProps) { const [cur, setCur] = useState(1); const [formData, setFormData] = useState<{ [key: string]: string | number | boolean }>({}); useEffect(() => { if (resetPageNo) { setCur(1); onPageChange(1); } }, [onPageChange, resetPageNo]); useEffect(() => { if (tableData.length > 0 && tableData[0]) { setFormData(tableData[0] as { [key: string]: string | number | boolean }); } }, [tableData]); const handleInputChange = (id: string, value: string | number | boolean) => { setFormData((prev) => ({ ...prev, [id]: value, })); }; const handlePageChange = (page: number) => { setCur(page); onPageChange(page); }; return ( <> {headName ? (

{headName}

) : null}
{headlist?.map((head) => ( {/* 컬럼 제목 */} {head.title} {/* 데이터 값 또는 입력 필드 */} {children && children[head.id] ? children[head.id] : isEditable ? ( head.type === "select" ? ( ) : head.type === "input" ? ( handleInputChange(head.id, e.target.value)} className="w-full text-xl border-radius-0 border border-gray-300 rounded-sm px-2 py-1" /> ) : ( {formData[head.id] ?? "-"} ) ) : ( {formData[head.id] ?? "-"} )} ))}
{total > 0 && ( )}
); }