'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { Layers, Check, Plus, Pencil, Trash2, SlidersHorizontal } from 'lucide-react';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '../../ui/dropdown-menu.js';
import { cn } from '../../../lib/utils.js';
import { DEFAULT_WORKSPACE_ID, } from '../../../hooks/use-workspaces.js';
export function WorkspaceSelector({ workspaces, activeWorkspace, onSelect, onRequestCreate, onRequestRename, onRequestDelete, onManage, }) {
    const [open, setOpen] = useState(false);
    const isDefault = activeWorkspace.id === DEFAULT_WORKSPACE_ID;
    return (_jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs("button", { type: "button", "data-testid": "workspace-selector-trigger", className: cn('inline-flex items-center gap-1.5 rounded-lg px-2 py-1.5 text-xs font-medium transition-colors', 'hover:bg-accent hover:text-accent-foreground', isDefault ? 'text-muted-foreground' : 'text-primary bg-primary/10'), title: "Workspace", children: [_jsx(Layers, { className: "h-4 w-4" }), _jsx("span", { className: "max-w-[120px] truncate", children: activeWorkspace.name })] }) }), _jsxs(DropdownMenuContent, { align: "start", className: "min-w-[220px]", children: [_jsx(DropdownMenuLabel, { children: "Workspaces" }), _jsx(DropdownMenuSeparator, {}), workspaces.map((w) => {
                        const active = w.id === activeWorkspace.id;
                        const canDelete = w.id !== DEFAULT_WORKSPACE_ID;
                        return (_jsxs(DropdownMenuItem, { onSelect: () => onSelect(w.id), className: "group/ws-row flex items-center justify-between gap-2", children: [_jsx("span", { className: "truncate", children: w.name }), _jsxs("span", { className: "flex shrink-0 items-center gap-1", children: [active ? _jsx(Check, { className: "h-3.5 w-3.5" }) : null, canDelete ? (_jsx("button", { type: "button", "aria-label": `Delete workspace ${w.name}`, title: `Delete workspace ${w.name}`, onClick: (event) => {
                                                event.preventDefault();
                                                event.stopPropagation();
                                                setOpen(false);
                                                onRequestDelete(w.id);
                                            }, className: "text-muted-foreground hover:bg-destructive/10 hover:text-destructive rounded p-0.5 opacity-0 transition-opacity group-hover/ws-row:opacity-100 focus-visible:opacity-100", children: _jsx(Trash2, { className: "h-3.5 w-3.5" }) })) : null] })] }, w.id));
                    }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onSelect: onRequestCreate, children: [_jsx(Plus, { className: "mr-2 h-3.5 w-3.5" }), "New workspace\u2026"] }), _jsxs(DropdownMenuItem, { onSelect: onManage, disabled: isDefault, children: [_jsx(SlidersHorizontal, { className: "mr-2 h-3.5 w-3.5" }), "Manage items\u2026"] }), _jsxs(DropdownMenuItem, { onSelect: onRequestRename, disabled: isDefault, children: [_jsx(Pencil, { className: "mr-2 h-3.5 w-3.5" }), "Rename"] })] })] }));
}
