import { useMemo, useState } from "react"; import { ExternalLink } from "lucide-react"; import { Button } from "@govoplan/core-webui"; import { Card } from "@govoplan/core-webui"; import { PageScrollViewport } from "@govoplan/core-webui"; import { PageTitle } from "@govoplan/core-webui"; import { FieldLabel } from "@govoplan/core-webui"; import { StatusBadge, TableActionGroup, i18nMessage } from "@govoplan/core-webui"; import { usePlatformLanguage } from "@govoplan/core-webui"; import { ModuleSubnav, type ModuleSubnavGroup } from "@govoplan/core-webui"; import { DataGrid, type DataGridColumn } from "@govoplan/core-webui"; type TemplateRecord = { id: string; name: string; description: string; type: string; status: string; fields: string[]; updatedAt: string; usedBy: string; subject: string; body: string; versions: number; }; type TemplateDetailSection = "overview" | "content" | "fields" | "preview" | "usage" | "versions"; const templateRecords: TemplateRecord[] = [ { id: "monthly-statement", name: "i18n:govoplan-campaign.monthly_statement.74029609", description: "i18n:govoplan-campaign.reusable_subject_and_body_for_monthly_statement_.9754240d", type: "plain_text", status: "ready", fields: ["recipient_name", "period", "amount"], updatedAt: "2026-06-08 16:42", usedBy: "i18n:govoplan-campaign.2_campaigns.35b84804", subject: "i18n:govoplan-campaign.subject_monthly_statement", body: "i18n:govoplan-campaign.hello_value_please_find_your_statement_for_value.48d94596", versions: 4 }, { id: "deadline-reminder", name: "i18n:govoplan-campaign.deadline_reminder.84977a7f", description: "i18n:govoplan-campaign.short_reminder_template_with_one_deadline_field.5f15d110", type: "plain_text", status: "draft", fields: ["recipient_name", "deadline"], updatedAt: "2026-06-07 11:18", usedBy: "i18n:govoplan-campaign.not_used_yet.962b7bbd", subject: "i18n:govoplan-campaign.subject_deadline_reminder", body: "i18n:govoplan-campaign.hello_value_this_is_a_reminder_that_the_deadline.c4fbdbd0", versions: 1 }, { id: "attachment-notice", name: "i18n:govoplan-campaign.attachment_notice.b73a59fe", description: "i18n:govoplan-campaign.generic_note_for_campaigns_where_every_recipient.f21254fa", type: "html_ready", status: "ready", fields: ["recipient_name", "file_label", "contact_email"], updatedAt: "2026-06-05 09:05", usedBy: "i18n:govoplan-campaign.1_campaign.ccd70074", subject: "i18n:govoplan-campaign.subject_documents_for_recipient", body: "i18n:govoplan-campaign.hello_value_your_value_is_attached_please_contac.da32415e", versions: 3 }]; const templateSubnav = (onBack: () => void): ModuleSubnavGroup[] => [ { items: [{ actionId: "template-library", label: "i18n:govoplan-campaign.template_library.6742c898", primary: true, onClick: onBack }] }, { title: "i18n:govoplan-campaign.template.4c31d4ef", items: [ { id: "overview", label: "i18n:govoplan-campaign.overview.0efc2e6b" }, { id: "content", label: "i18n:govoplan-campaign.content.4f9be057" }, { id: "fields", label: "i18n:govoplan-campaign.fields.e8b68527" }, { id: "preview", label: "i18n:govoplan-campaign.preview.f1fbb2b4" }, { id: "usage", label: "i18n:govoplan-campaign.usage.0bb18642" }, { id: "versions", label: "i18n:govoplan-campaign.versions.a239107e" }] }]; function templateLibraryColumns(openTemplate: (templateId: string) => void): DataGridColumn[] { return [ { id: "template", header: "i18n:govoplan-campaign.template.3ec1ae06", width: "minmax(240px, 1.4fr)", sortable: true, filterable: true, sticky: "start", render: (template) =>
{template.name}{template.description}
, value: (template) => `${template.name} ${template.description}` }, { id: "type", header: "i18n:govoplan-campaign.type.3deb7456", width: 150, sortable: true, filterable: true, columnType: "from-list", list: { options: [{ value: "plain_text", label: "i18n:govoplan-campaign.plain_text_template_type" }, { value: "html_ready", label: "i18n:govoplan-campaign.html_ready_template_type" }] }, value: (template) => template.type }, { id: "fields", header: "i18n:govoplan-campaign.fields.e8b68527", width: 240, filterable: true, render: (template) =>
{template.fields.slice(0, 3).map((field) => {field})}
, value: (template) => template.fields.join(", ") }, { id: "updated", header: "i18n:govoplan-campaign.updated.f2f8570d", width: 170, sortable: true, filterable: true, filterType: "date", render: (template) => {template.updatedAt}, value: (template) => template.updatedAt }, { id: "status", header: "i18n:govoplan-campaign.status.bae7d5be", width: 130, sortable: true, filterable: true, columnType: "from-list", list: { options: [{ value: "draft", label: "i18n:govoplan-campaign.draft.23d33e22" }, { value: "active", label: "i18n:govoplan-campaign.active.a733b809" }, { value: "archived", label: "i18n:govoplan-campaign.archived.eddc813f" }], display: "pill" }, render: (template) => , value: (template) => template.status }, { id: "actions", header: "i18n:govoplan-campaign.actions.c3cd636a", width: 70, sticky: "end", align: "right", render: (template) =>