'use client'; import { useState } from 'react'; import { PageLayout, FilterBar, EmptyState } from '@/components/ui'; import { documentTemplatesApi } from '@/lib/api/api-client'; import useSWR from 'swr'; import DocumentPreviewModal from '@/components/DocumentPreviewModal'; const CATEGORIES = [ { value: undefined, label: 'Все' }, { value: 'application', label: '📝 Заявки' }, { value: 'certificate', label: '📜 Сертификаты' }, { value: 'act', label: '📋 Акты' }, { value: 'letter', label: '✉️ Письма' }, { value: 'form', label: '📄 Формы' }, { value: 'report', label: '📊 Отчёты' }, { value: 'order', label: '📌 Приказы' }, ]; const STANDARDS = [ { value: undefined, label: 'Все' }, { value: 'RF', label: '🇷🇺 РФ' }, { value: 'ICAO', label: '🌐 ИКАО' }, { value: 'EASA', label: '🇪🇺 EASA' }, { value: 'FAA', label: '🇺🇸 FAA' }, { value: 'INTERNAL', label: '🏢 Внутренние' }, ]; const CATEGORY_ICONS: Record = { application: '📝', certificate: '📜', act: '📋', letter: '✉️', form: '📄', report: '📊', order: '📌', }; export default function TemplatesPage() { const [category, setCategory] = useState(); const [standard, setStandard] = useState(); const [preview, setPreview] = useState(null); const params: Record = {}; if (category) params.category = category; if (standard) params.standard = standard; const { data, isLoading, mutate } = useSWR( ['doc-templates', category, standard], () => documentTemplatesApi.list(params) ); const templates = data?.items || []; return (
{!isLoading && templates.length > 0 ? (
{templates.map((t: any) => (
setPreview(t)} className="group cursor-pointer rounded-lg border border-gray-200 bg-white p-5 shadow-sm transition-all hover:border-primary-300 hover:shadow-md" >
{CATEGORY_ICONS[t.category] || '📄'}
{t.name}
{t.code} · v{t.version}
{t.description && (
{t.description}
)}
{t.standard} {t.category}
))}
) : !isLoading ? ( ) : null} {preview && ( setPreview(null)} onSaved={() => mutate()} /> )}
); }