"use client"; /** * Document detail on `ResponsiveSheet` (bottom sheet on phones, dialog on * desktop). Inline-class documents (PDF / browser-native images) preview * inline against the owner-scoped decrypt-and-serve route — skeleton first, * content on load, internal scroll only (`overscroll-contain`). Attachment- * class documents get NO fake preview: type glyph, filename, size, and a * prominent Download button. * * Metadata edits save on commit (title on Enter/blur, kind and filing date * on change, condition links on toggle — replace-set PATCH). Mutation * errors surface inline (`role="alert"`), never as a QueryErrorCard. * Delete soft-deletes with an Undo toast (restore endpoint); a restore * refusal maps `meta.reason` (`purged`, `duplicateExists`) to translated * copy. A Share action in the footer opens the clinician share-link create * flow (shared `ShareLinkCreateForm`) with this document pre-attached. */ import { X } from "lucide-react"; import { DocumentReadingConsentPrompt } from "@/components/ai/document-reading-consent-prompt"; import { RelatedRecordsBlock } from "@/components/links/related-records"; import { Button } from "@/components/ui/button"; import { ConfirmDialog } from "@/components/ui/confirm-button"; import { QueryErrorRow } from "@/components/ui/query-error-row"; import { ResponsiveSheet } from "@/components/ui/responsive-sheet"; import { Skeleton } from "@/components/ui/skeleton"; import { VaccinationDocumentSuggestion } from "@/components/vaccinations/vaccination-document-suggestion"; import { DOCUMENT_PURGE_GRACE_DAYS } from "@/lib/documents/inbound-constants"; import { formatBytes } from "@/lib/format/bytes"; import { useFormatters, useTranslations } from "@/lib/i18n/context"; import type { RelatedLink } from "@/lib/links/related"; import { DocumentDetailFields, DocumentDetailFooter, DocumentDetailMeta, } from "./detail/detail-sections"; import { DocumentDownloadButton, InlinePreview } from "./detail/original-file"; import { useDocumentDetail } from "./detail/use-document-detail"; import { useDocumentDetailAi } from "./detail/use-document-detail-ai"; import { DocumentAiSection } from "./document-ai-section"; import { DocumentEncounterSuggestion } from "./document-encounter-suggestion"; import { DocumentFactsSection } from "./document-facts-review"; import { DocumentRecordLinks } from "./document-record-links"; import { DocumentShareSheet } from "./document-share-sheet"; import { DocumentSummaryBlock } from "./document-summary-block"; /** The grace window the delete confirmation names. */ const GRACE = { days: DOCUMENT_PURGE_GRACE_DAYS }; export function DocumentDetailSheet({ documentId, open, onOpenChange, assistAvailable, contentIndexEnabled, }: { documentId: string | null; open: boolean; onOpenChange: (open: boolean) => void; /** * Whether the AI "Suggest details" / summary actions can run (from * `usage.assistAvailable`). When false the AI area shows a calm pointer to * the AI settings instead of an error — the manual form stays fully usable. */ assistAvailable?: boolean; /** Whether content indexing is available (from `usage.contentIndex.enabled`). */ contentIndexEnabled?: boolean; }) { const { t, locale } = useTranslations(); const format = useFormatters(); const detail = useDocumentDetail({ documentId, open, onOpenChange }); const { detail: detailQuery, doc, linkSeedFresh, canManageDocuments, labsModuleEnabled, mutationError, linkResets, shareOpen, setShareOpen, confirmDeleteOpen, setConfirmDeleteOpen, pickedEncounterId, patch, remove, setSuggestedEncounter, title, Icon, inlineSrc, inlineFailed, } = detail; const { documentAi, coach, capability, suggest, summary, storedSummary, indexDoc, aiErrorText, suggestion, setSuggestion, appliedFields, summaryOutput, setSummaryOutput, aiEnabled, indexEnabled, autoReadEnabled, runSuggest, runSummary, generateStoredSummary, runIndex, applyTitle, applyKind, applyDate, suggestionKindLabel, suggestionDateLabel, } = useDocumentDetailAi({ documentId, open, assistAvailable, contentIndexEnabled, detail, }); return ( <> onOpenChange(false)} className="text-muted-foreground hover:text-foreground min-h-11 min-w-11 sm:size-9" > {doc ? ( ) : null} {doc ? ( remove.mutate(doc.id)} pending={remove.isPending} slot="document-detail-delete" destructive /> ) : null} ); }