'use client'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Badge } from '@/components/ui/badge'; import { FileText, Package, Check, X } from 'lucide-react'; import type { SectionTemplate } from '@/contexts/ItemMasterContext'; interface SectionDialogProps { isSectionDialogOpen: boolean; setIsSectionDialogOpen: (open: boolean) => void; newSectionType: 'fields' | 'bom'; setNewSectionType: (type: 'fields' | 'bom') => void; newSectionTitle: string; setNewSectionTitle: (title: string) => void; newSectionDescription: string; setNewSectionDescription: (description: string) => void; handleAddSection: () => void; // 템플릿 선택 관련 props sectionInputMode: 'custom' | 'template'; setSectionInputMode: (mode: 'custom' | 'template') => void; sectionTemplates: SectionTemplate[]; selectedTemplateId: number | null; setSelectedTemplateId: (id: number | null) => void; handleLinkTemplate: (template: SectionTemplate) => void; } export function SectionDialog({ isSectionDialogOpen, setIsSectionDialogOpen, newSectionType, setNewSectionType, newSectionTitle, setNewSectionTitle, newSectionDescription, setNewSectionDescription, handleAddSection, sectionInputMode, setSectionInputMode, sectionTemplates, selectedTemplateId, setSelectedTemplateId, handleLinkTemplate, }: SectionDialogProps) { const handleClose = () => { setIsSectionDialogOpen(false); setNewSectionType('fields'); setNewSectionTitle(''); setNewSectionDescription(''); setSectionInputMode('custom'); setSelectedTemplateId(null); }; // 템플릿 선택 시 폼에 값 채우기 const handleSelectTemplate = (template: SectionTemplate) => { setSelectedTemplateId(template.id); setNewSectionTitle(template.template_name); setNewSectionDescription(template.description || ''); setNewSectionType(template.section_type === 'BOM' ? 'bom' : 'fields'); }; return ( { if (!open) handleClose(); else setIsSectionDialogOpen(open); }}> 섹션 추가 새로운 섹션을 추가하거나 기존 템플릿을 연결합니다.
{/* 입력 모드 선택 */}
{/* 템플릿 목록 */} {sectionInputMode === 'template' && (
{sectionTemplates.length === 0 ? (

등록된 섹션 템플릿이 없습니다.
섹션 탭에서 템플릿을 먼저 등록해주세요.

) : (
{sectionTemplates.map(template => (
handleSelectTemplate(template)} >
{template.section_type === 'BOM' ? ( ) : ( )} {template.template_name} {template.section_type === 'BOM' ? '모듈(BOM)' : '일반'}
{template.description && (

{template.description}

)} {template.fields && template.fields.length > 0 && (

{template.fields.length}개 항목 포함

)}
{selectedTemplateId === template.id && ( )}
))}
)}
)} {/* 직접 입력 폼 또는 선택된 템플릿 정보 표시 */} {(sectionInputMode === 'custom' || selectedTemplateId) && ( <> {/* 섹션 유형 선택 - 템플릿 선택 시 비활성화 */}
{/* 일반 섹션 */}
{ if (sectionInputMode === 'custom') setNewSectionType('fields'); }} className={`flex items-center gap-3 p-4 border rounded-lg transition-all ${ sectionInputMode === 'template' ? 'opacity-60 cursor-not-allowed' : 'cursor-pointer' } ${ newSectionType === 'fields' ? 'border-blue-500 bg-blue-50 ring-2 ring-blue-500' : 'border-gray-200 hover:border-gray-300' }`} >
일반 섹션
필드 항목 관리
{newSectionType === 'fields' && ( )}
{/* BOM 섹션 */}
{ if (sectionInputMode === 'custom') setNewSectionType('bom'); }} className={`flex items-center gap-3 p-4 border rounded-lg transition-all ${ sectionInputMode === 'template' ? 'opacity-60 cursor-not-allowed' : 'cursor-pointer' } ${ newSectionType === 'bom' ? 'border-blue-500 bg-blue-50 ring-2 ring-blue-500' : 'border-gray-200 hover:border-gray-300' }`} >
모듈 섹션 (BOM)
자재명세서 관리
{newSectionType === 'bom' && ( )}
setNewSectionTitle(e.target.value)} placeholder={newSectionType === 'bom' ? '예: BOM 구성' : '예: 기본 정보'} disabled={sectionInputMode === 'template'} />