"use client"; import { useRef, useState } from "react"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { Slider } from "@/components/ui/slider"; import { Loader2, Trash2, Upload, ChevronRight, FileText, Maximize2, Space, Droplet } from "lucide-react"; import { useReportDesigner } from "@/contexts/ReportDesignerContext"; import { reportApi } from "@/lib/api/reportApi"; import { useToast } from "@/hooks/use-toast"; export function PageSettingsTab() { const { currentPage, currentPageId, updatePageSettings, layoutConfig, updateWatermark } = useReportDesigner(); const [uploadingWatermarkImage, setUploadingWatermarkImage] = useState(false); const watermarkFileInputRef = useRef(null); const [expandedSection, setExpandedSection] = useState("page-info"); const { toast } = useToast(); const handleWatermarkImageUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; if (!file.type.startsWith("image/")) { toast({ title: "오류", description: "이미지 파일만 업로드 가능합니다.", variant: "destructive" }); return; } if (file.size > 5 * 1024 * 1024) { toast({ title: "오류", description: "파일 크기는 5MB 이하여야 합니다.", variant: "destructive" }); return; } try { setUploadingWatermarkImage(true); const result = await reportApi.uploadImage(file); if (result.success) { updateWatermark({ ...layoutConfig.watermark!, imageUrl: result.data.fileUrl }); toast({ title: "성공", description: "워터마크 이미지가 업로드되었습니다." }); } } catch { toast({ title: "오류", description: "이미지 업로드 중 오류가 발생했습니다.", variant: "destructive" }); } finally { setUploadingWatermarkImage(false); if (watermarkFileInputRef.current) watermarkFileInputRef.current.value = ""; } }; if (!currentPage || !currentPageId) { return (

페이지를 선택하세요

); } const toggleSection = (id: string) => { setExpandedSection(expandedSection === id ? "" : id); }; return (
{/* 페이지 정보 (아코디언) */}
{expandedSection === "page-info" && (
updatePageSettings(currentPageId, { page_name: e.target.value })} className="h-10 border-2 text-sm focus:border-blue-500" />
)}
{/* 페이지 크기 (아코디언) */}
{expandedSection === "page-size" && (
updatePageSettings(currentPageId, { width: Math.max(1, Number(e.target.value)) })} className="h-10 border-2 text-sm focus:border-blue-500" />
updatePageSettings(currentPageId, { height: Math.max(1, Number(e.target.value)) })} className="h-10 border-2 text-sm focus:border-blue-500" />
)}
{/* 여백 설정 (아코디언) */}
{expandedSection === "margin" && (
{(["top", "bottom", "left", "right"] as const).map((side) => (
updatePageSettings(currentPageId, { margins: { ...currentPage.margins, [side]: Math.max(0, Number(e.target.value)) }, }) } className="h-10 border-2 text-sm focus:border-blue-500" />
))}
{[ { label: "좁게", value: 10 }, { label: "보통", value: 20 }, { label: "넓게", value: 30 }, ].map(({ label, value }) => ( ))}
)}
{/* 워터마크 설정 (아코디언) */}
{expandedSection === "watermark" && (
updateWatermark({ ...layoutConfig.watermark, enabled: checked, type: layoutConfig.watermark?.type ?? "text", opacity: layoutConfig.watermark?.opacity ?? 0.3, style: layoutConfig.watermark?.style ?? "diagonal", }) } />
{layoutConfig.watermark?.enabled && ( <>
{layoutConfig.watermark?.type === "text" && ( <>
updateWatermark({ ...layoutConfig.watermark!, text: e.target.value })} placeholder="CONFIDENTIAL" className="h-10 border-2 text-sm focus:border-blue-500" />
updateWatermark({ ...layoutConfig.watermark!, fontSize: Number(e.target.value) })} className="h-10 border-2 text-sm focus:border-blue-500" min={12} max={200} />
updateWatermark({ ...layoutConfig.watermark!, fontColor: e.target.value })} className="h-10 w-12 cursor-pointer p-1" /> updateWatermark({ ...layoutConfig.watermark!, fontColor: e.target.value })} className="h-10 flex-1 border-2 text-sm" />
)} {layoutConfig.watermark?.type === "image" && (
{layoutConfig.watermark?.imageUrl && ( )}
)}
{(layoutConfig.watermark?.style === "diagonal" || layoutConfig.watermark?.style === "tile") && (
updateWatermark({ ...layoutConfig.watermark!, rotation: Number(e.target.value) })} className="h-10 border-2 text-sm focus:border-blue-500" min={-180} max={180} />
)}
{Math.round((layoutConfig.watermark?.opacity ?? 0.3) * 100)}%
updateWatermark({ ...layoutConfig.watermark!, opacity: value[0] / 100 })} min={5} max={100} step={5} className="my-2" />
{[ { label: "초안", text: "DRAFT", fontSize: 64, fontColor: "#cccccc", style: "diagonal" as const, opacity: 0.2, rotation: -45 }, { label: "대외비", text: "대외비", fontSize: 64, fontColor: "#ff0000", style: "diagonal" as const, opacity: 0.15, rotation: -45 }, { label: "샘플", text: "SAMPLE", fontSize: 48, fontColor: "#888888", style: "tile" as const, opacity: 0.1, rotation: -30 }, { label: "사본", text: "COPY", fontSize: 56, fontColor: "#aaaaaa", style: "center" as const, opacity: 0.25 }, ].map(({ label, ...preset }) => ( ))}
)}
)}
); }