"use client"; import React, { useState, useEffect } from "react"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Switch } from "@/components/ui/switch"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Plus, Trash2, GripVertical, Loader2 } from "lucide-react"; import { ConditionalContainerConfig, ConditionalSection } from "./types"; import { screenApi } from "@/lib/api/screen"; interface ConditionalContainerConfigPanelProps { config: ConditionalContainerConfig; onConfigChange: (config: ConditionalContainerConfig) => void; } export function ConditionalContainerConfigPanel({ config, onConfigChange, }: ConditionalContainerConfigPanelProps) { const [localConfig, setLocalConfig] = useState({ controlField: config.controlField || "condition", controlLabel: config.controlLabel || "조건 선택", sections: config.sections || [], defaultValue: config.defaultValue || "", showBorder: config.showBorder ?? true, spacing: config.spacing || "normal", }); // 화면 목록 상태 const [screens, setScreens] = useState([]); const [screensLoading, setScreensLoading] = useState(false); // 화면 목록 로드 useEffect(() => { const loadScreens = async () => { setScreensLoading(true); try { const response = await screenApi.getScreens({ page: 1, size: 1000 }); if (response.data) { setScreens(response.data); } } catch (error) { console.error("화면 목록 로드 실패:", error); } finally { setScreensLoading(false); } }; loadScreens(); }, []); // 설정 업데이트 헬퍼 const updateConfig = (updates: Partial) => { const newConfig = { ...localConfig, ...updates }; setLocalConfig(newConfig); onConfigChange(newConfig); }; // 새 섹션 추가 const addSection = () => { const newSection: ConditionalSection = { id: `section_${Date.now()}`, condition: `condition_${localConfig.sections.length + 1}`, label: `조건 ${localConfig.sections.length + 1}`, screenId: null, screenName: undefined, }; updateConfig({ sections: [...localConfig.sections, newSection], }); }; // 섹션 삭제 const removeSection = (sectionId: string) => { updateConfig({ sections: localConfig.sections.filter((s) => s.id !== sectionId), }); }; // 섹션 업데이트 const updateSection = ( sectionId: string, updates: Partial ) => { updateConfig({ sections: localConfig.sections.map((s) => s.id === sectionId ? { ...s, ...updates } : s ), }); }; return (

조건부 컨테이너 설정

{/* 제어 필드 설정 */}
updateConfig({ controlField: e.target.value })} placeholder="예: inputMode" className="h-8 text-xs" />

formData에 저장될 필드명

updateConfig({ controlLabel: e.target.value })} placeholder="예: 입력 방식" className="h-8 text-xs" />
{/* 조건별 섹션 설정 */}
{localConfig.sections.length === 0 ? (

조건별 섹션을 추가하세요

) : (
{localConfig.sections.map((section, index) => (
{/* 섹션 헤더 */}
섹션 {index + 1}
{/* 조건 값 */}
updateSection(section.id, { condition: e.target.value }) } placeholder="예: customer_first" className="h-7 text-xs" />
{/* 조건 라벨 */}
updateSection(section.id, { label: e.target.value }) } placeholder="예: 거래처 우선" className="h-7 text-xs" />
{/* 화면 선택 */}
{screensLoading ? (
로딩 중...
) : ( )} {section.screenId && (
화면 ID: {section.screenId}
)}
))}
)}
{/* 기본값 설정 */} {localConfig.sections.length > 0 && (
)} {/* 스타일 설정 */}
{/* 테두리 표시 */}
updateConfig({ showBorder: checked }) } />
{/* 간격 설정 */}
); }