import { Pencil } from "lucide-react"; import type { ApiSettings } from "../../../types"; import type { CampaignPostboxCatalog } from "../../../api/campaigns"; import { Button, DataGridRowActions, ToggleSwitch, i18nMessage, type DataGridColumn } from "@govoplan/core-webui"; import AttachmentRulesOverlay from "../components/AttachmentRulesOverlay"; import FieldValueInput from "../components/FieldValueInput"; import { normalizePostboxTargets } from "../components/PostboxTargetsDialog"; import { buildTemplatePreviewContext } from "../utils/templatePlaceholders"; import { getIndividualAttachmentBasePaths, normalizeAttachmentRules, type AttachmentRule, type AttachmentZipCollection } from "../utils/attachments"; import { getDraftFields } from "../utils/fieldDefinitions"; import { asRecord } from "../utils/campaignView"; import { hiddenRecipientAddressMatch, recipientAddressFilterValue, recipientAddressSummary } from "./RecipientAddressEditor"; export type RecipientProfileColumnContext = { settings: ApiSettings; campaignId: string; draft: Record; locked: boolean; filesModuleInstalled: boolean; postboxModuleInstalled: boolean; templatesModuleInstalled: boolean; postboxCatalog: CampaignPostboxCatalog; entries: Record[]; fieldDefinitions: ReturnType; individualAttachmentBasePaths: ReturnType; zipConfig: AttachmentZipCollection; addressFilter: string; translateText: (value: string) => string; openAddressEditor: (index: number) => void; openPostboxTargetEditor: (index: number) => void; updateEntry: (index: number, updater: (entry: Record) => Record) => void; updateEntryAttachments: (index: number, attachments: AttachmentRule[]) => void; updateEntryField: (index: number, field: string, value: unknown) => void; addRecipient: (afterIndex?: number) => void; moveEntry: (index: number, targetIndex: number) => void; removeEntry: (index: number) => void; }; export function recipientProfileColumns({ settings, campaignId, draft, locked, filesModuleInstalled, postboxModuleInstalled, templatesModuleInstalled, postboxCatalog, entries, fieldDefinitions, individualAttachmentBasePaths, zipConfig, addressFilter, translateText, openAddressEditor, openPostboxTargetEditor, updateEntry, updateEntryAttachments, updateEntryField, addRecipient, moveEntry, removeEntry }: RecipientProfileColumnContext): DataGridColumn>[] { return [ { id: "number", header: "#", width: 72, sortable: true, filterType: "integer", sticky: "start", render: (_entry, index) => {index + 1} , value: (_entry, index) => index + 1 }, { id: "recipients", header: "Recipient(s)", width: "minmax(320px, 1.4fr)", preferredMaxWidth: 640, resizable: true, filterable: true, render: (entry, index) => { const summary = recipientAddressSummary(entry, translateText); const hiddenMatch = hiddenRecipientAddressMatch(entry, addressFilter); const content = ( <> {summary.primary} {summary.badges.map((badge) => {badge} )} {hiddenMatch && Matched in {hiddenMatch.label}: {hiddenMatch.address} } {!locked &&