1import type { EnvironmentId } from "@t3tools/contracts";
2import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
3
4import { useFileMetadata } from "../../hooks/useFileMetadata";
5import { PierreEntryIcon } from "./PierreEntryIcon";
6
7/** Path chips share metadata queries across messages and the composer. A file
8 * icon is neutral while the environment is offline or the path is unknown. */
9export function WorkspaceEntryIcon(props: {
10 path: string;
11 environmentId?: EnvironmentId | null | undefined;
12 cwd?: string | undefined;
13 theme: "light" | "dark";
14}) {
15 const metadata = useFileMetadata(props.environmentId, props.path, props.cwd);
16 return (
17 <PierreEntryIcon
18 pathValue={props.path}
19 kind={metadata?.kind === "directory" ? "directory" : "file"}
20 mimeType={metadata?.mimeType}
21 theme={props.theme}
22 />
23 );
24}
25
26export function WorkspaceEntryTooltip(props: {
27 path: string;
28 label?: string;
29 environmentId?: EnvironmentId | null | undefined;
30 cwd?: string | undefined;
31}) {
32 const metadata = useFileMetadata(props.environmentId, props.path, props.cwd);
33 return (
34 <>
35 {props.label ?? props.path}
36 {metadata?.byteLength === undefined
37 ? null
38 : ` · ${formatAttachmentSize(metadata.byteLength)}`}
39 </>
40 );
41}