import { useState } from "react"; import { Link2, X } from "lucide-react"; import { Button, Dialog, i18nMessage } from "@govoplan/core-webui"; import type { CampaignAttachmentPreviewFile, CampaignAttachmentPreviewResponse } from "../../../api/campaigns"; import { attachmentPreviewLinkableFiles, attachmentPreviewMatchedFiles } from "../utils/attachmentPreview"; import { WorkflowFact } from "./WorkflowNavigation"; export default function AttachmentLinkingPreview({ preview, loading, error, linking, disabled, onRefresh, onLink }: { preview: CampaignAttachmentPreviewResponse | null; loading: boolean; error: string; linking: boolean; disabled: boolean; onRefresh: () => void; onLink: () => void; }) { const [detailsOpen, setDetailsOpen] = useState(false); const matchedFiles = attachmentPreviewMatchedFiles(preview); const linkableFiles = attachmentPreviewLinkableFiles(preview); const linkedCount = preview?.linked_file_count ?? matchedFiles.filter((file) => file.linked_to_campaign !== false).length; const matchedCount = preview?.matched_file_count ?? matchedFiles.length; const unlinkedCount = preview?.unlinked_file_count ?? linkableFiles.length; return ( <>
i18n:govoplan-campaign.preview_includes_already_linked_files_and_access.dfef92af
{error}
} {!error && unlinkedCount > 0 && (i18n:govoplan-campaign.unlinked_candidate_files_are_not_yet_part_of_the.b8fd5998
)} {!error && !loading && matchedFiles.length === 0 && (i18n:govoplan-campaign.no_managed_files_matched_the_current_attachment_.dba99f5c
)} {matchedFiles.length > 0 &&