import type { Asset } from "@cloudhal/core-contracts"; import { Badge, ImagePreview, MediaKindFrame, Tooltip } from "@cloudhal/ui"; import { Archive, File, FileAudio, FileCsv, FilePdf, FileVideo, Image as ImageIcon, Robot, TextAa, } from "@phosphor-icons/react"; import { useT } from "../i18n/index.tsx"; import { type AssetKind, assetPreviewUrl, needsAlt, typeLabel } from "../lib/media.ts"; /** The kind's icon (images, video, audio, PDF and documents, data). */ export function KindIcon({ kind, size = 24 }: { kind: AssetKind | undefined; size?: number }) { const Icon = kind === "image" ? ImageIcon : kind === "video" ? FileVideo : kind === "audio" ? FileAudio : kind === "document" ? FilePdf : kind === "data" ? FileCsv : File; return ; } /** * An asset's picture in a tile, a table row or a detail card: images load from Studio's private * content route (drafts included, `assetPreviewUrl`), other files show their kind and extension. */ export function AssetFrame({ siteId, asset, size, alt, }: { siteId: string; asset: Asset; size: "tile" | "thumb" | "card"; alt?: string; }) { const t = useT("media"); const src = assetPreviewUrl(siteId, asset); if (asset.kind !== "image") return ( } label={typeLabel(asset.mediaType)} /> ); return ( ); } /** State badges of a file: retired, missing alt text, added by an agent. */ export function AssetBadges({ asset, defaultLocale, compact = false, }: { asset: Asset; defaultLocale: string; /** Tiles: icons with tooltips only where space is short. */ compact?: boolean; }) { const t = useT("media"); const badges = []; if (asset.status === "retired") badges.push( }> {t("media.badges.retired")} , ); if (needsAlt(asset, defaultLocale)) badges.push( }> {compact ? t("media.badges.missingAltShort") : t("media.badges.missingAlt")} , ); if (asset.uploadedBy.kind === "agent" && !compact) badges.push( }> {t("media.badges.agent")} , ); return badges.length ? badges : null; } /** "Used in 3 places" / "Unused" as a small badge (`overlay`: solid, legible over a picture). */ export function UsageBadge({ count, overlay = false }: { count: number; overlay?: boolean }) { const t = useT("media"); return ( 0 ? "info" : "outline"}> {count === 0 ? t("media.usage.none") : t("media.usage.used", { count })} ); }