"use client";
/**
* v1.27.22 (Document vault P2) — the presentational AI panels for the document
* detail sheet. Pure (props in, markup out) so the review-first contract and
* the session-only note are pinned by static-render tests.
*
* - `AiUnavailableHint` — the calm "set up an AI provider" pointer shown in
* place of the AI actions when no provider is configured (never an error).
* - `AssistSuggestionReview` — the reviewed DRAFT card: suggested title / type
* / date, each applied only by an explicit tap. Nothing is written until the
* user applies it (and the title lands in the editable field, not on disk).
* - `DocumentSummaryPanel` — the transient summary / extracted-text panel with
* the persistent "not saved · not a diagnosis" note.
* - `ContentSearchStatus` — the per-document searchable pill reflecting the
* auto-index: "Read by AI" (provider read the original), "Searchable"
* (locally indexed), "Making searchable…" (a read is running), or the calm
* "not searchable yet". A STATUS, never a chore button.
*/
import { Loader2, ScanSearch, Sparkles } from "lucide-react";
import { Check, FileText, X } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton";
import { useTranslations } from "@/lib/i18n/context";
import { cn } from "@/lib/utils";
import {
isAiReadSource,
type DocumentContentIndexSourceValue,
type DocumentSuggestionDto,
type DocumentSummaryMode,
} from "@/lib/validations/inbound-documents";
import type { DocumentDescribeResult } from "./use-document-assist";
/**
* Calm pointer to the AI settings, shown when assist is unavailable. When the
* document is already searchable (auto-indexed locally) the copy stays honest —
* it is searchable, an AI provider only adds a richer read.
*/
export function AiUnavailableHint({
reason,
}: {
reason: "no-provider" | "enable-local-ocr" | null;
}) {
const { t } = useTranslations();
const body =
reason === "enable-local-ocr"
? t("documents.assist.unavailableLocalOcr")
: t("documents.assist.unavailableBody");
return (
);
}
/**
* The review-first suggestion card. Suggestions are DRAFTS: applying the title
* seeds the editable title field (the user still saves it); applying the type
* or date commits that single field through the existing edit-on-commit path —
* always an explicit tap, never automatic.
*/
export function AssistSuggestionReview({
suggestion,
kindLabel,
dateLabel,
applied,
onUseTitle,
onUseKind,
onUseDate,
onDismiss,
}: {
suggestion: DocumentSuggestionDto;
/** Translated label for the suggested kind, or null when none was read. */
kindLabel: string | null;
/** Formatted suggested date, or null when none was read. */
dateLabel: string | null;
applied: { title: boolean; kind: boolean; date: boolean };
onUseTitle: () => void;
onUseKind: () => void;
onUseDate: () => void;
onDismiss: () => void;
}) {
const { t } = useTranslations();
const hasAny =
suggestion.title !== null ||
suggestion.kind !== null ||
suggestion.documentDate !== null;
return (
);
}
/**
* The transient summary / extracted-text panel. The result is shown once and
* never persisted; the "not saved · not a diagnosis" note is always present.
*/
export function DocumentSummaryPanel({
output,
result,
isPending,
errorKey,
onClose,
}: {
output: DocumentSummaryMode;
result: DocumentDescribeResult | null;
isPending: boolean;
errorKey: string | null;
onClose: () => void;
}) {
const { t } = useTranslations();
const heading =
output === "text"
? t("documents.summary.textTitle")
: t("documents.summary.summaryTitle");
const body =
result === null ? null : "summary" in result ? result.summary : result.text;
return (
{heading}
{isPending ? (
) : errorKey ? (
{t(errorKey)}
) : body !== null ? (
{body}
) : null}
);
}
/**
* The per-document searchable status pill. Reflects the auto-index (indexing is
* automatic on upload, so this is a state, never a to-do): a document is "Read
* by AI" when a provider read the original, "Searchable" when it is only locally
* indexed, "Making searchable…" while a read runs, and a calm "not searchable
* yet" otherwise. The AI-read pill is highlighted (primary) — that read is the
* richer one and worth surfacing.
*/
export function ContentSearchStatus({
hasContentIndex,
source,
isPending,
}: {
hasContentIndex: boolean;
source: DocumentContentIndexSourceValue | null;
/** A read/index is running right now. */
isPending: boolean;
}) {
const { t } = useTranslations();
if (isPending) {
return (
{t("documents.ai.statusIndexing")}
);
}
if (!hasContentIndex) {
return (
{t("documents.ai.statusNotYet")}
);
}
if (isAiReadSource(source)) {
return (
{t("documents.ai.statusAiRead")}
);
}
return (
{t("documents.ai.statusSearchable")}
);
}