"use client"; import { useEffect, useState } from "react"; import { useParams } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Loader2 } from "lucide-react"; import { screenApi } from "@/lib/api/screen"; import { ScreenDefinition, LayoutData } from "@/types/screen"; import { InteractiveScreenViewer } from "@/components/screen/InteractiveScreenViewerDynamic"; import { DynamicComponentRenderer } from "@/lib/registry/DynamicComponentRenderer"; import { DynamicWebTypeRenderer } from "@/lib/registry"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { initializeComponents } from "@/lib/registry/components"; export default function ScreenViewPage() { const params = useParams(); const router = useRouter(); const screenId = parseInt(params.screenId as string); const [screen, setScreen] = useState(null); const [layout, setLayout] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [formData, setFormData] = useState>({}); useEffect(() => { const initComponents = async () => { try { console.log("πŸš€ ν• λ‹Ήλœ ν™”λ©΄μ—μ„œ μ»΄ν¬λ„ŒνŠΈ μ‹œμŠ€ν…œ μ΄ˆκΈ°ν™” μ‹œμž‘..."); await initializeComponents(); console.log("βœ… ν• λ‹Ήλœ ν™”λ©΄μ—μ„œ μ»΄ν¬λ„ŒνŠΈ μ‹œμŠ€ν…œ μ΄ˆκΈ°ν™” μ™„λ£Œ"); } catch (error) { console.error("❌ ν• λ‹Ήλœ ν™”λ©΄μ—μ„œ μ»΄ν¬λ„ŒνŠΈ μ‹œμŠ€ν…œ μ΄ˆκΈ°ν™” μ‹€νŒ¨:", error); } }; initComponents(); }, []); useEffect(() => { const loadScreen = async () => { try { setLoading(true); setError(null); // ν™”λ©΄ 정보 λ‘œλ“œ const screenData = await screenApi.getScreen(screenId); setScreen(screenData); // λ ˆμ΄μ•„μ›ƒ λ‘œλ“œ try { const layoutData = await screenApi.getLayout(screenId); setLayout(layoutData); } catch (layoutError) { console.warn("λ ˆμ΄μ•„μ›ƒ λ‘œλ“œ μ‹€νŒ¨, 빈 λ ˆμ΄μ•„μ›ƒ μ‚¬μš©:", layoutError); setLayout({ components: [], gridSettings: { columns: 12, gap: 16, padding: 16 }, }); } } catch (error) { console.error("ν™”λ©΄ λ‘œλ“œ μ‹€νŒ¨:", error); setError("화면을 λΆˆλŸ¬μ˜€λŠ”λ° μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."); toast.error("화면을 λΆˆλŸ¬μ˜€λŠ”λ° μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."); } finally { setLoading(false); } }; if (screenId) { loadScreen(); } }, [screenId]); if (loading) { return (

화면을 λΆˆλŸ¬μ˜€λŠ” 쀑...

); } if (error || !screen) { return (
⚠️

화면을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€

{error || "μš”μ²­ν•˜μ‹  화면이 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."}

); } // ν™”λ©΄ 해상도 정보가 있으면 ν•΄λ‹Ή 크기둜, μ—†μœΌλ©΄ κΈ°λ³Έ 크기 μ‚¬μš© const screenWidth = layout?.screenResolution?.width || 1200; const screenHeight = layout?.screenResolution?.height || 800; return (
{layout && layout.components.length > 0 ? ( // μΊ”λ²„μŠ€ μ»΄ν¬λ„ŒνŠΈλ“€μ„ μ •ν™•ν•œ ν•΄μƒλ„λ‘œ ν‘œμ‹œ
{layout.components .filter((comp) => !comp.parentId) // μ΅œμƒμœ„ μ»΄ν¬λ„ŒνŠΈλ§Œ λ Œλ”λ§ (κ·Έλ£Ή 포함) .map((component) => { // κ·Έλ£Ή μ»΄ν¬λ„ŒνŠΈμΈ 경우 νŠΉλ³„ 처리 if (component.type === "group") { const groupChildren = layout.components.filter((child) => child.parentId === component.id); return (
{/* κ·Έλ£Ή 제λͺ© */} {(component as any).title && (
{(component as any).title}
)} {/* κ·Έλ£Ή λ‚΄ μžμ‹ μ»΄ν¬λ„ŒνŠΈλ“€ λ Œλ”λ§ */} {groupChildren.map((child) => (
{ console.log("πŸ“ 폼 데이터 λ³€κ²½:", { fieldName, value }); setFormData((prev) => { const newFormData = { ...prev, [fieldName]: value, }; console.log("πŸ“Š 전체 폼 데이터:", newFormData); return newFormData; }); }} screenInfo={{ id: screenId, tableName: screen?.tableName, }} />
))}
); } // 라벨 ν‘œμ‹œ μ—¬λΆ€ 계산 const templateTypes = ["datatable"]; const shouldShowLabel = component.style?.labelDisplay !== false && (component.label || component.style?.labelText) && !templateTypes.includes(component.type); const labelText = component.style?.labelText || component.label || ""; const labelStyle = { fontSize: component.style?.labelFontSize || "14px", color: component.style?.labelColor || "#374151", fontWeight: component.style?.labelFontWeight || "500", backgroundColor: component.style?.labelBackgroundColor || "transparent", padding: component.style?.labelPadding || "0", borderRadius: component.style?.labelBorderRadius || "0", marginBottom: component.style?.labelMarginBottom || "4px", }; // 일반 μ»΄ν¬λ„ŒνŠΈ λ Œλ”λ§ return (
{/* 라벨을 외뢀에 λ³„λ„λ‘œ λ Œλ”λ§ */} {shouldShowLabel && (
{labelText} {component.required && *}
)} {/* μ‹€μ œ μ»΄ν¬λ„ŒνŠΈ */}
{ console.log("🎯 ν• λ‹Ήλœ ν™”λ©΄ μ»΄ν¬λ„ŒνŠΈ:", { id: component.id, type: component.type, position: component.position, size: component.size, styleWidth: component.style?.width, styleHeight: component.style?.height, finalWidth: `${component.size.width}px`, finalHeight: `${component.size.height}px`, }); }} > {/* μœ„μ ― μ»΄ν¬λ„ŒνŠΈκ°€ μ•„λ‹Œ 경우 DynamicComponentRenderer μ‚¬μš© */} {component.type !== "widget" ? ( { setFormData((prev) => ({ ...prev, [fieldName]: value, })); }} screenId={screenId} tableName={screen?.tableName} onRefresh={() => { console.log("ν™”λ©΄ μƒˆλ‘œκ³ μΉ¨ μš”μ²­"); }} onClose={() => { console.log("ν™”λ©΄ λ‹«κΈ° μš”μ²­"); }} /> ) : ( { setFormData((prev) => ({ ...prev, [fieldName]: value, })); }} /> )}
); })}
) : ( // 빈 화면일 λ•Œλ„ κΉ”λ”ν•˜κ²Œ ν‘œμ‹œ
πŸ“„

화면이 λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€

이 ν™”λ©΄μ—λŠ” 아직 μ„€κ³„λœ μ»΄ν¬λ„ŒνŠΈκ°€ μ—†μŠ΅λ‹ˆλ‹€.

)}
); }