"use client"; import React, { useState, useEffect } from "react"; import { CustomerItemMappingConfig } from "./types"; import { Checkbox } from "@/components/ui/checkbox"; import { X } from "lucide-react"; import { cn } from "@/lib/utils"; export interface CustomerItemMappingComponentProps { component: any; isDesignMode?: boolean; isSelected?: boolean; isInteractive?: boolean; config?: CustomerItemMappingConfig; className?: string; style?: React.CSSProperties; onClick?: (e?: React.MouseEvent) => void; onDragStart?: (e: React.DragEvent) => void; onDragEnd?: (e: React.DragEvent) => void; } export const CustomerItemMappingComponent: React.FC = ({ component, isDesignMode = false, isSelected = false, config, className, style, onClick, onDragStart, onDragEnd, }) => { const finalConfig = { ...config, ...component.config, } as CustomerItemMappingConfig; const [data, setData] = useState([]); const [selectedRows, setSelectedRows] = useState>(new Set()); const [isAllSelected, setIsAllSelected] = useState(false); // 데이터 로드 (실제 구현 시 API 호출) useEffect(() => { if (!isDesignMode && finalConfig.selectedTable) { // TODO: API 호출로 데이터 로드 setData([]); } }, [finalConfig.selectedTable, isDesignMode]); const handleSelectAll = (checked: boolean) => { if (checked) { const allIds = data.map((_, index) => `row-${index}`); setSelectedRows(new Set(allIds)); setIsAllSelected(true); } else { setSelectedRows(new Set()); setIsAllSelected(false); } }; const handleRowSelection = (rowId: string, checked: boolean) => { const newSelected = new Set(selectedRows); if (checked) { newSelected.add(rowId); } else { newSelected.delete(rowId); } setSelectedRows(newSelected); setIsAllSelected(newSelected.size === data.length && data.length > 0); }; const columns = finalConfig.columns || []; const showCheckbox = finalConfig.checkbox?.enabled !== false; // 스타일 계산 const componentStyle: React.CSSProperties = { position: "relative", display: "flex", flexDirection: "column", backgroundColor: "hsl(var(--background))", overflow: "hidden", boxSizing: "border-box", width: "100%", height: "100%", minHeight: isDesignMode ? "300px" : "100%", ...style, // style prop이 위의 기본값들을 덮어씀 }; // 이벤트 핸들러 const handleClick = (e: React.MouseEvent) => { e.stopPropagation(); onClick?.(); }; return (
{/* 헤더 */}

품목 추가 - {finalConfig.selectedTable || "[테이블 선택]"} {finalConfig.showCompanyName && finalConfig.companyNameColumn && ( | {finalConfig.companyNameColumn} )}

{/* 검색/카테고리 영역 */} {finalConfig.showSearchArea && (
{/* 검색 입력 */}
{/* 카테고리 필터 */} {finalConfig.enableCategoryFilter && (
)}
)} {/* 목록 헤더 */}
판매품목 목록
{showCheckbox && finalConfig.checkbox?.selectAll && ( )} 선택: {selectedRows.size}개
{/* 테이블 컨테이너 */}
{/* 테이블 헤더 */} {columns.length > 0 && (
{showCheckbox && ( )} {columns.map((col, index) => ( ))}
{col}
)} {/* 데이터 영역 */}
{data.length === 0 ? (

{finalConfig.emptyMessage || "데이터가 없습니다"}

{finalConfig.emptyDescription || "품목 데이터가 추가되면 여기에 표시됩니다"}

) : (
{data.map((row, index) => ( {showCheckbox && ( )} {columns.map((col, colIndex) => ( ))} ))}
handleRowSelection(`row-${index}`, checked as boolean) } /> {row[col] || "-"}
)}
); };