import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { FileIcon, FileTextIcon, ImageIcon, CodeIcon, Trash2Icon, Loader2Icon } from 'lucide-react';
import { cn } from '../../../lib/utils.js';
import { Button } from '../../ui/button.js';
export function AttachmentCard({ name, size, mimeType: _mimeType, onRemove, loading = false, disabled = false, subtitle, }) {
    const ext = getExtension(name);
    const Icon = getFileIcon(ext);
    const iconColorClass = getFileIconColor(ext);
    return (_jsxs("div", { className: "flex items-center gap-3 rounded-md border p-2", children: [_jsx("div", { className: cn('flex h-8 w-8 shrink-0 items-center justify-center rounded', iconColorClass), children: _jsx(Icon, { className: "h-4 w-4" }) }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { className: "truncate text-sm font-medium", children: name }), subtitle ? (_jsx("span", { className: "text-muted-foreground truncate text-xs", children: subtitle })) : null, _jsx("span", { className: "text-muted-foreground text-xs", children: loading ? 'Uploading...' : formatFileSize(size) })] }), loading ? (_jsx(Loader2Icon, { className: "text-muted-foreground h-4 w-4 animate-spin" })) : (_jsx(Button, { type: "button", variant: "ghost", size: "icon-xs", onClick: onRemove, disabled: disabled, "aria-label": `Remove ${name}`, children: _jsx(Trash2Icon, { className: "h-3 w-3" }) }))] }));
}
function getExtension(filename) {
    const dot = filename.lastIndexOf('.');
    return dot >= 0 ? filename.slice(dot).toLowerCase() : '';
}
const IMAGE_EXTS = new Set(['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.ico', '.bmp']);
const CODE_EXTS = new Set([
    '.ts',
    '.tsx',
    '.js',
    '.jsx',
    '.json',
    '.yaml',
    '.yml',
    '.xml',
    '.html',
    '.css',
    '.md',
]);
export function getFileIcon(ext) {
    if (IMAGE_EXTS.has(ext))
        return ImageIcon;
    if (ext === '.pdf')
        return FileTextIcon;
    if (CODE_EXTS.has(ext))
        return CodeIcon;
    return FileIcon;
}
export function getFileIconColor(ext) {
    if (ext === '.pdf')
        return 'bg-red-50 text-red-600';
    if (IMAGE_EXTS.has(ext))
        return 'bg-blue-50 text-blue-600';
    if (CODE_EXTS.has(ext))
        return 'bg-emerald-50 text-emerald-600';
    return 'bg-gray-50 text-gray-600';
}
export function formatFileSize(bytes) {
    if (bytes === 0)
        return '0 B';
    const units = ['B', 'KB', 'MB', 'GB'];
    const i = Math.floor(Math.log(bytes) / Math.log(1024));
    return `${(bytes / Math.pow(1024, i)).toFixed(i === 0 ? 0 : 1)} ${units[i]}`;
}
