import { useState, type ReactNode } from "react";
import { FileText, ImageIcon, Video } from "lucide-react";
import { useTranslation } from "react-i18next";
import { PendingEdgeOverlay, type PendingEdgeState } from "@/components/PendingEdgeOverlay";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import type { UIMediaKind } from "@/lib/types";
import { cn } from "@/lib/utils";
export const attachmentCardActionClassName = "absolute right-0 top-0 grid h-11 w-11 place-items-center rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring";
/** The card owns only its information surface; callers own removal, download, and status. */
export function AttachmentCard({ name, description, children, action, invalid = false, edgeState = "solid", onSealEnd }: {
name: string;
description?: string;
children: ReactNode;
action?: ReactNode;
invalid?: boolean;
edgeState?: PendingEdgeState;
onSealEnd?: () => void;
}) {
const [detailsOpen, setDetailsOpen] = useState(false);
const [hintOpen, setHintOpen] = useState(false);
const changeDetailsOpen = (open: boolean) => { setDetailsOpen(open); setHintOpen(false); };
const details = <>
{name}
{description ? {description} : null}
>;
return
event.preventDefault()}
// Focus stays on the trigger; delayed restoration must not steal the next Tab.
onCloseAutoFocus={(event) => event.preventDefault()}
className="w-max max-w-[min(20rem,calc(100vw-2rem))] break-words px-3 py-1.5 text-caption">
{details}
{details}
{action}
;
}
export function AttachmentTypeFace({ name, kind = "file" }: { name: string; kind?: UIMediaKind }) {
const { t } = useTranslation();
const type = name.match(/\.(tar\.(?:gz|bz2|xz)|[a-z0-9]{1,12})$/i)?.[1].toUpperCase()
|| t(kind === "image" ? "message.imageAttachment" : kind === "video" ? "message.videoAttachment" : "message.fileAttachment");
const Icon = kind === "image" ? ImageIcon : kind === "video" ? Video : FileText;
return
{type}
;
}