"use client" import * as React from "react" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Input } from "@/components/ui/input" import { Eye, Copy, Check, Settings2 } from "lucide-react" import { toast } from "sonner" import { cn } from "@/lib/utils" import { type GtcClauseTreeView } from "@/db/schema/gtc" interface ViewClauseVariablesDialogProps extends React.ComponentPropsWithRef { clause: GtcClauseTreeView | null onEditVariables?: () => void } export function ViewClauseVariablesDialog({ clause, onEditVariables, ...props }: ViewClauseVariablesDialogProps) { const [copiedField, setCopiedField] = React.useState(null) const copyToClipboard = async (text: string, fieldName: string) => { try { await navigator.clipboard.writeText(text) setCopiedField(fieldName) toast.success(`${fieldName} 변수명이 복사되었습니다.`) // 2초 후 복사 상태 초기화 setTimeout(() => { setCopiedField(null) }, 2000) } catch (error) { toast.error("복사 중 오류가 발생했습니다.") } } const copyAllVariables = async () => { if (!clause) return const allVariables = [ clause.autoNumberVariable, clause.autoSubtitleVariable, clause.autoContentVariable ].filter(Boolean).join('\n') try { await navigator.clipboard.writeText(allVariables) toast.success("모든 변수명이 복사되었습니다.") } catch (error) { toast.error("복사 중 오류가 발생했습니다.") } } if (!clause) { return null } const variables = [ { label: "채번 변수명", value: clause.autoNumberVariable, fieldName: "채번", description: "조항 번호를 표시하는 변수" }, { label: "소제목 변수명", value: clause.autoSubtitleVariable, fieldName: "소제목", description: "조항 제목을 표시하는 변수" }, { label: "상세항목 변수명", value: clause.autoContentVariable, fieldName: "상세항목", description: "조항 내용을 표시하는 변수" } ] return ( PDFTron 변수명 보기 현재 조항에 설정된 PDFTron 변수명을 확인하고 복사할 수 있습니다. {/* 조항 정보 */}
조항 정보
{clause.itemNumber} {clause.subtitle} {clause.hasAllVariableNames ? "설정됨" : "미설정"}
{clause.fullPath && (
경로: {clause.fullPath}
)} {clause.category && (
분류: {clause.category}
)}
{/* 변수명 목록 */}

설정된 변수명

{variables.map((variable, index) => (
{variable.label}
{variable.description}
))}
{/* PDFTron 템플릿 미리보기 */}

PDFTron 템플릿 미리보기

{"{{" + clause.autoNumberVariable + "}}"}. {"{{" + clause.autoSubtitleVariable + "}}"}
{"{{" + clause.autoContentVariable + "}}"}
실제 문서에서 위와 같은 형태로 표시됩니다.
{/* 실제 값 미리보기 */}

실제 값 미리보기

{clause.itemNumber}. {clause.subtitle}
{clause.content && (
{clause.content.length > 150 ? `${clause.content.substring(0, 150)}...` : clause.content }
)} {!clause.content && (
(그룹핑 조항 - 상세내용 없음)
)}
{onEditVariables && ( )}
) }