import { useMemo, useState } from "react"; import { ExternalLink } from "lucide-react"; import { Button } from "@govoplan/core-webui"; import { Card } from "@govoplan/core-webui"; import { PageTitle } from "@govoplan/core-webui"; import { FieldLabel } from "@govoplan/core-webui"; import { StatusBadge, i18nMessage } from "@govoplan/core-webui"; import { usePlatformLanguage } from "@govoplan/core-webui"; import ModuleSubnav, { type ModuleSubnavGroup } from "../../layout/ModuleSubnav"; import DataGrid, { type DataGridColumn } from "../../components/table/DataGrid"; 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) => }]; } function templateTypeLabel(type: string): string { if (type === "html_ready") return "i18n:govoplan-campaign.html_ready_template_type"; return "i18n:govoplan-campaign.plain_text_template_type"; } function templateFieldColumns(): DataGridColumn<{id: string;field: string;source: string;required: string;}>[] { return [ { id: "field", header: "i18n:govoplan-campaign.field.c326a466", width: "minmax(180px, 1fr)", sortable: true, filterable: true, sticky: "start", render: (row) => {row.field}, value: (row) => row.field }, { id: "source", header: "i18n:govoplan-campaign.source.6da13add", width: 190, sortable: true, filterable: true, columnType: "from-list", list: { options: [{ value: "detected_placeholder", label: "i18n:govoplan-campaign.detected_placeholder.094b5214" }] }, value: (row) => row.source }, { id: "required", header: "i18n:govoplan-campaign.required.eed6bfb4", width: 120, sortable: true, filterable: true, columnType: "from-list", list: { options: [{ value: "yes", label: "i18n:govoplan-campaign.yes.5397e058" }, { value: "no", label: "i18n:govoplan-campaign.no.816c52fd" }] }, value: (row) => row.required }, { id: "actions", header: "i18n:govoplan-campaign.actions.c3cd636a", width: 130, sticky: "end", render: () => }]; } export default function TemplatesPage() { const [selectedId, setSelectedId] = useState(null); const [active, setActive] = useState("overview"); const selectedTemplate = useMemo( () => templateRecords.find((template) => template.id === selectedId) ?? null, [selectedId] ); function openTemplate(templateId: string) { setSelectedId(templateId); setActive("overview"); } if (selectedTemplate) { return (
setSelectedId(null))} onSelect={setActive} />
{selectedTemplate.name}

{selectedTemplate.description}

{active === "overview" && } {active === "content" && } {active === "fields" && } {active === "preview" && } {active === "usage" && } {active === "versions" && }
); } return (
i18n:govoplan-campaign.templates.f25b700e

i18n:govoplan-campaign.reusable_message_templates_open_a_template_to_ed.792e2afb

i18n:govoplan-campaign.all_templates.0bba114c

i18n:govoplan-campaign.last_loaded_local_demo_data.62ee2f5d
} actions={}> template.id} emptyText="i18n:govoplan-campaign.no_templates_found.326abcdd" className="compact-table-wrap module-table-wrap module-entry-table" /> ); } function TemplateOverview({ template }: {template: TemplateRecord;}) { return (
i18n:govoplan-campaign.status.bae7d5be
i18n:govoplan-campaign.type.3deb7456
{templateTypeLabel(template.type)}
i18n:govoplan-campaign.updated.f2f8570d
{template.updatedAt}
i18n:govoplan-campaign.versions.a239107e
{template.versions}

i18n:govoplan-campaign.campaigns_can_reuse_this_template_but_each_campa.bdb25009

i18n:govoplan-campaign.subject_placeholders_are_detected.96663276 i18n:govoplan-campaign.body_placeholders_are_compared_with_campaign_fie.bbd1d67f i18n:govoplan-campaign.a_mapping_wizard_can_be_added_later.6b2fe0f3
); } function TemplateContent({ template }: {template: TemplateRecord;}) { const { translateText } = usePlatformLanguage(); const subject = translateText(template.subject); const body = translateText(template.body); return ( i18n:govoplan-campaign.save_changes.179359b3}>