"use client"; import { useState } from "react"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { ScrollArea } from "@/components/ui/scroll-area"; import { useReportDesigner } from "@/contexts/ReportDesignerContext"; import { Plus, Copy, Trash2, GripVertical, Edit2, Check, X } from "lucide-react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; export function PageListPanel() { const { layoutConfig, currentPageId, addPage, deletePage, duplicatePage, reorderPages, selectPage, updatePageSettings, } = useReportDesigner(); const [editingPageId, setEditingPageId] = useState(null); const [editingName, setEditingName] = useState(""); const [draggedIndex, setDraggedIndex] = useState(null); const handleStartEdit = (pageId: string, currentName: string) => { setEditingPageId(pageId); setEditingName(currentName); }; const handleSaveEdit = () => { if (editingPageId && editingName.trim()) { updatePageSettings(editingPageId, { page_name: editingName.trim() }); } setEditingPageId(null); setEditingName(""); }; const handleCancelEdit = () => { setEditingPageId(null); setEditingName(""); }; const handleDragStart = (index: number) => { setDraggedIndex(index); }; const handleDragOver = (e: React.DragEvent, index: number) => { e.preventDefault(); if (draggedIndex === null || draggedIndex === index) return; // 실시간으로 순서 변경하지 않고, drop 시에만 변경 }; const handleDrop = (e: React.DragEvent, targetIndex: number) => { e.preventDefault(); if (draggedIndex === null) return; const sourceIndex = draggedIndex; if (sourceIndex !== targetIndex) { reorderPages(sourceIndex, targetIndex); } setDraggedIndex(null); }; const handleDragEnd = () => { setDraggedIndex(null); }; return (
{/* 헤더 */}

페이지

{/* 페이지 목록 */}
{layoutConfig.pages .sort((a, b) => a.page_order - b.page_order) .map((page, index) => (
selectPage(page.page_id)} onDragOver={(e) => handleDragOver(e, index)} onDrop={(e) => handleDrop(e, index)} >
{/* 드래그 핸들 */}
{ e.stopPropagation(); handleDragStart(index); }} onDragEnd={handleDragEnd} className="text-muted-foreground cursor-grab opacity-0 transition-opacity group-hover:opacity-100 active:cursor-grabbing" onClick={(e) => e.stopPropagation()} >
{/* 페이지 정보 */}
{editingPageId === page.page_id ? (
e.stopPropagation()}> setEditingName(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") handleSaveEdit(); if (e.key === "Escape") handleCancelEdit(); }} className="h-5 text-[10px]" autoFocus />
) : (
{page.page_name}
)}
{page.width}x{page.height}mm
{/* 액션 메뉴 */} e.stopPropagation()}> { e.stopPropagation(); handleStartEdit(page.page_id, page.page_name); }} > 이름 변경 { e.stopPropagation(); duplicatePage(page.page_id); }} > 복제 { e.stopPropagation(); deletePage(page.page_id); }} disabled={layoutConfig.pages.length <= 1} className="text-destructive focus:text-destructive" > 삭제
))}
{/* 푸터 */}
); }