"use client";
import { OsIcon } from "./OsIcon";
import { FOLDER_ICONS, MIMETYPE_ICONS } from "./icon-assets";
type IconProps = { className?: string };
// Shared paper body used by every file-type icon.
// The paper is tinted with `c` at low opacity so the color reads at small sizes
// even when the embedded symbol is too tiny to distinguish.
function PaperBase({ c, children }: { c: string; children?: React.ReactNode }) {
return (
<>
{/* Body */}
{/* Fold corner fill */}
{/* Fold crease */}
{children}
>
);
}
// ─── Folder badge system ──────────────────────────────────────────────────────
// Maps lowercase folder names to a badge type. Add entries here to support more.
type BadgeType =
| "download" | "upload"
| "music" | "video" | "image"
| "document" | "code" | "archive"
| "network" | "backup" | "share"
| "desktop" | "trash" | "app";
const FOLDER_BADGE_MAP: Record = {
// Downloads
download: "download", downloads: "download",
// Music / Audio
music: "music", audio: "music", songs: "music",
// Video / Media
video: "video", videos: "video", movies: "video",
movie: "video", media: "video", films: "video", film: "video",
// Images / Photos
pictures: "image", picture: "image", photos: "image",
photo: "image", images: "image", gallery: "image",
screenshots: "image", screenshot: "image", wallpapers: "image",
// Documents
documents: "document", document: "document", docs: "document",
// Code / Dev
code: "code", dev: "code", development: "code",
projects: "code", src: "code", repos: "code", github: "code",
// Archives
archive: "archive", archives: "archive",
// Network / Shared
shared: "share", network: "network",
// Backup
backup: "backup", backups: "backup",
// Desktop
desktop: "desktop",
// Apps / AppData
apps: "app", appdata: "app",
// Trash
trash: "trash", ".trash": "trash",
};
// Badge rendered at bottom-right corner inside the 48×48 folder SVG.
// Circle at (36, 37) r=11 gives ~22 px badge area.
function FolderBadgeOverlay({ type }: { type: BadgeType }) {
const s = { stroke: "white", strokeWidth: "1.7", strokeLinecap: "round" as const, strokeLinejoin: "round" as const, fill: "none" };
return (
// translate(-12, -10) shifts badge center from (36,37) → (24,27), the visual center of the folder body
{type === "download" && (
)}
{type === "upload" && (
)}
{type === "music" && (
<>
>
)}
{type === "video" && (
)}
{type === "image" && (
<>
>
)}
{type === "document" && (
)}
{type === "code" && (
)}
{type === "archive" && (
)}
{type === "network" && (
<>
>
)}
{type === "backup" && (
)}
{type === "share" && (
<>
>
)}
{type === "desktop" && (
)}
{type === "trash" && (
)}
{type === "app" && (
)}
);
}
function getFolderBadge(name: string): BadgeType | null {
return FOLDER_BADGE_MAP[name.toLowerCase()] ?? null;
}
// ─── Folder (closed) ─────────────────────────────────────────────────────────
function FolderSvg({ className, name }: IconProps & { name?: string }) {
const badge = name ? getFolderBadge(name) : null;
return (
);
}
export function FolderIcon({ className, name }: IconProps & { name?: string }) {
const badge = name ? getFolderBadge(name) : null;
const osSrc = FOLDER_ICONS[badge ?? "default"] ?? FOLDER_ICONS.default;
return (
}
/>
);
}
// ─── Folder (open) ────────────────────────────────────────────────────────────
function OpenFolderSvg({ className, name }: IconProps & { name?: string }) {
const badge = name ? getFolderBadge(name) : null;
return (
);
}
export function OpenFolderIcon({ className, name }: IconProps & { name?: string }) {
const badge = name ? getFolderBadge(name) : null;
const osSrc = FOLDER_ICONS[badge ?? "default"] ?? FOLDER_ICONS.default;
return (
}
/>
);
}
// ─── Image ────────────────────────────────────────────────────────────────────
export function ImageFileIcon({ className }: IconProps) {
const c = "#f472b6";
return (
}
/>
);
}
// ─── Audio ────────────────────────────────────────────────────────────────────
export function AudioFileIcon({ className }: IconProps) {
const c = "#c084fc";
return (
}
/>
);
}
// ─── Video ────────────────────────────────────────────────────────────────────
export function VideoFileIcon({ className }: IconProps) {
const c = "#fbbf24";
return (
}
/>
);
}
// ─── Archive ──────────────────────────────────────────────────────────────────
export function ArchiveFileIcon({ className }: IconProps) {
const c = "#a78bfa";
return (
}
/>
);
}
// ─── Code ─────────────────────────────────────────────────────────────────────
export function CodeFileIcon({ className }: IconProps) {
const c = "#34d399";
return (
}
/>
);
}
// ─── Document (PDF / DOC) ─────────────────────────────────────────────────────
export function DocumentFileIcon({ className }: IconProps) {
const c = "#60a5fa";
return (
}
/>
);
}
// ─── Plain text ───────────────────────────────────────────────────────────────
export function TextFileIcon({ className }: IconProps) {
const c = "#94a3b8";
return (
}
/>
);
}
// ─── Generic file ─────────────────────────────────────────────────────────────
export function GenericFileIcon({ className }: IconProps) {
const c = "#6b7280";
return (
}
/>
);
}
export function KoraFileIcon({ className, iconKey }: IconProps & { iconKey: string }) {
const src = MIMETYPE_ICONS[iconKey] ?? MIMETYPE_ICONS.generic;
return (
}
/>
);
}