'use client'; import { useRef, useState } from 'react'; import { documentTemplatesApi } from '@/lib/api/api-client'; import { useAuth } from '@/lib/auth-context'; interface Props { template: { id: string; name: string; code: string; html_content: string }; onClose: () => void; onSaved?: () => void; } export default function DocumentPreviewModal({ template, onClose, onSaved }: Props) { const contentRef = useRef(null); const [saving, setSaving] = useState(false); const { hasRole } = useAuth(); const canEdit = hasRole('admin') || hasRole('authority_inspector'); const handlePrint = () => { window.print(); }; const handleSave = async () => { if (!contentRef.current || !canEdit) return; setSaving(true); try { const html = contentRef.current.innerHTML; await documentTemplatesApi.update(template.id, { html_content: html }); onSaved?.(); } catch (e) { console.error(e); } finally { setSaving(false); } }; return ( <>
e.stopPropagation()} >
{template.name} {template.code}
{canEdit && ( )}
); }