"use client"; /** * V2 렉 구조 설정 패널 * 토스식 단계별 UX: 필드 매핑 -> 제한 설정 -> UI 설정(접힘) */ import React, { useState, useEffect } from "react"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; import { Settings, ChevronDown } from "lucide-react"; import { cn } from "@/lib/utils"; import type { RackStructureComponentConfig, FieldMapping } from "@/lib/registry/components/v2-rack-structure/types"; interface V2RackStructureConfigPanelProps { config: RackStructureComponentConfig; onChange: (config: RackStructureComponentConfig) => void; tables?: Array<{ tableName: string; tableLabel?: string; columns: Array<{ columnName: string; columnLabel?: string; dataType?: string; }>; }>; } export const V2RackStructureConfigPanel: React.FC = ({ config, onChange, tables = [], }) => { const [availableColumns, setAvailableColumns] = useState< Array<{ value: string; label: string }> >([]); const [advancedOpen, setAdvancedOpen] = useState(false); useEffect(() => { const columns: Array<{ value: string; label: string }> = []; tables.forEach((table) => { table.columns.forEach((col) => { columns.push({ value: col.columnName, label: col.columnLabel || col.columnName, }); }); }); setAvailableColumns(columns); }, [tables]); const handleChange = (key: keyof RackStructureComponentConfig, value: any) => { onChange({ ...config, [key]: value }); }; const handleFieldMappingChange = (field: keyof FieldMapping, value: string) => { const currentMapping = config.fieldMapping || {}; onChange({ ...config, fieldMapping: { ...currentMapping, [field]: value === "__none__" ? undefined : value, }, }); }; const fieldMapping = config.fieldMapping || {}; const fieldMappingItems: Array<{ key: keyof FieldMapping; label: string; description: string; }> = [ { key: "warehouseCodeField", label: "창고 코드", description: "창고를 식별하는 코드 필드예요" }, { key: "warehouseNameField", label: "창고명", description: "창고 이름을 표시하는 필드예요" }, { key: "floorField", label: "층", description: "몇 층인지 나타내는 필드예요" }, { key: "zoneField", label: "구역", description: "구역 정보를 가져올 필드예요" }, { key: "locationTypeField", label: "위치 유형", description: "위치의 유형(선반, 바닥 등)을 나타내요" }, { key: "statusField", label: "사용 여부", description: "사용/미사용 상태를 나타내는 필드예요" }, ]; return (
{/* ─── 1단계: 필드 매핑 ─── */}

필드 매핑

상위 폼의 필드 중 렉 생성에 사용할 필드를 선택해요

{fieldMappingItems.map((item) => (
{item.label}

{item.description}

))}
{/* ─── 2단계: 제한 설정 ─── */}

제한 설정

렉 조건의 최대값을 설정해요

최대 조건 수 handleChange("maxConditions", parseInt(e.target.value) || 10)} className="h-7 w-[100px] text-xs" />
최대 열 수 handleChange("maxRows", parseInt(e.target.value) || 99)} className="h-7 w-[100px] text-xs" />
최대 단 수 handleChange("maxLevels", parseInt(e.target.value) || 20)} className="h-7 w-[100px] text-xs" />
{/* ─── 3단계: 고급 설정 (Collapsible) ─── */}

템플릿 기능

조건을 템플릿으로 저장/불러오기할 수 있어요

handleChange("showTemplates", checked)} />

미리보기

생성될 위치를 미리 확인할 수 있어요

handleChange("showPreview", checked)} />

통계 카드

총 위치 수 등 통계를 카드로 표시해요

handleChange("showStatistics", checked)} />

읽기 전용

조건을 수정할 수 없게 해요

handleChange("readonly", checked)} />
); }; V2RackStructureConfigPanel.displayName = "V2RackStructureConfigPanel"; export default V2RackStructureConfigPanel;