import { ArrowSquareOutIcon, FileIcon, HourglassIcon } from "@phosphor-icons/react";
import type { DataType, FileRef, OutputValue } from "../lib/types";
const isRef = (v: unknown): v is FileRef => !!v && typeof v === "object" && typeof (v as FileRef).url === "string";
const isImageUrl = (u: string) => /\.(png|jpe?g|webp|gif|avif|bmp|svg)(\?|$)/i.test(u);
const isAudioUrl = (u: string) => /\.(mp3|wav|ogg|flac|m4a|aac|opus)(\?|$)/i.test(u);
const isVideoUrl = (u: string) => /\.(mp4|webm|mov|mkv)(\?|$)/i.test(u);
const kindOf = (ref: FileRef, hint: DataType): "image" | "audio" | "video" | "file" => {
const m = ref.mime ?? "";
if (m.startsWith("image/") || isImageUrl(ref.url)) return "image";
if (m.startsWith("audio/") || isAudioUrl(ref.url)) return "audio";
if (m.startsWith("video/") || isVideoUrl(ref.url)) return "video";
if (hint === "image" || hint === "audio" || hint === "video") return hint;
return "file";
};
function FileView({ file, hint }: { file: FileRef; hint: DataType }) {
const kind = kindOf(file, hint);
const open = (
e.stopPropagation()}>
{open}
>
);
case "audio":
return (
<>
{open}
>
);
case "video":
return (
<>
{open}
>
);
default:
return (
{text.length > 2000 ? `${text.slice(0, 2000)}…` : text}