"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useState } from "react";
import { cn } from "@stigmer/theme";
import { WorkspaceEntryFiles } from "../../workspace/WorkspaceEntryFiles";
/**
 * Dedicated workspace tab for the SessionInspector.
 *
 * Provides a full-height layout for managing workspace entries:
 * - Entry list with expandable file trees (accordion, one at a time)
 * - Add actions: Browse Folder and Connect GitHub
 * - Short display names with full path on hover
 *
 * Entries start collapsed by default to avoid expensive file-listing
 * fetches until the user explicitly expands one.
 *
 * All visual properties flow through `--stgm-*` tokens (DD-005).
 */
export function WorkspaceTab({ actions }) {
    const { workspace, enableGitHub = true, enableLocal = false, onBrowseLocalFolder, workspaceFileLister, } = actions;
    const canBrowse = enableLocal && onBrowseLocalFolder;
    const hasEntries = workspace.entries.length > 0;
    return (_jsxs("div", { className: "flex h-full flex-col gap-3", children: [hasEntries && (_jsx(WorkspaceEntryList, { entries: workspace.entries, onRemove: workspace.remove, lister: workspaceFileLister })), !hasEntries && (_jsx(EmptyState, {})), _jsxs("div", { className: "flex flex-col gap-0.5", children: [canBrowse && (_jsxs("button", { type: "button", onClick: async () => {
                            const path = await onBrowseLocalFolder();
                            if (path)
                                workspace.addLocalPath(path);
                        }, className: "flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-xs text-foreground transition-colors hover:bg-accent-hover", children: [_jsx(FolderPlusIcon, {}), _jsx("span", { className: "flex-1 text-left", children: "Browse Folder" })] })), enableGitHub && (_jsxs("button", { type: "button", onClick: () => {
                            /* GitHub picker is handled via the composer's Configure menu.
                               This button is a placeholder affordance for visual parity. */
                        }, className: "flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-xs text-foreground transition-colors hover:bg-accent-hover", children: [_jsx(GitHubIcon, {}), _jsx("span", { className: "flex-1 text-left", children: "Connect GitHub" })] }))] })] }));
}
// ---------------------------------------------------------------------------
// Workspace entry list — accordion with file tree expansion
// ---------------------------------------------------------------------------
function WorkspaceEntryList({ entries, onRemove, lister, }) {
    const [expandedId, setExpandedId] = useState(null);
    const toggleExpand = useCallback((id) => {
        setExpandedId((prev) => (prev === id ? null : id));
    }, []);
    return (_jsx("div", { className: "flex flex-col gap-1.5", children: entries.map((entry) => {
            const isExpandable = !!lister;
            const isExpanded = expandedId === entry.id;
            return (_jsxs("div", { className: "flex flex-col", children: [_jsxs("div", { className: cn("flex items-center gap-2 rounded-md border border-border bg-muted-faint px-2.5 py-2 text-xs", isExpandable && "cursor-pointer hover:bg-muted transition-colors"), onClick: isExpandable ? () => toggleExpand(entry.id) : undefined, role: isExpandable ? "button" : undefined, "aria-expanded": isExpandable ? isExpanded : undefined, tabIndex: isExpandable ? 0 : undefined, onKeyDown: isExpandable ? (e) => {
                            if (e.key === "Enter" || e.key === " ") {
                                e.preventDefault();
                                toggleExpand(entry.id);
                            }
                        } : undefined, children: [isExpandable && (_jsx("span", { className: "shrink-0 text-[10px] text-muted-foreground-subtle", children: isExpanded ? "▼" : "▶" })), entry.type === "git" ? (_jsx(GitHubIcon, {})) : (_jsx(FolderIcon, {})), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("span", { className: "block truncate font-medium text-foreground", title: entry.type === "local" ? entry.localPath : entry.gitUrl, children: entry.name }), entry.type === "git" && entry.gitBranch && (_jsx("span", { className: "block truncate text-[0.6rem] text-muted-foreground", children: entry.gitBranch }))] }), _jsx("button", { type: "button", onClick: (e) => {
                                    e.stopPropagation();
                                    onRemove(entry.id);
                                }, className: "shrink-0 text-muted-foreground hover:text-destructive transition-colors", "aria-label": `Remove ${entry.name}`, children: _jsx(XIcon, {}) })] }), isExpandable && lister && (_jsx(WorkspaceEntryFiles, { entry: entry, lister: lister, isExpanded: isExpanded }))] }, entry.id));
        }) }));
}
// ---------------------------------------------------------------------------
// Empty state
// ---------------------------------------------------------------------------
function EmptyState() {
    return (_jsxs("div", { className: "flex flex-col items-center justify-center gap-2 py-8 text-center", children: [_jsx(FolderIcon, { className: "h-8 w-8 text-muted-foreground/40" }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-xs font-medium text-foreground", children: "No workspace attached" }), _jsx("p", { className: "text-[0.65rem] text-muted-foreground", children: "Add a folder or GitHub repo for the agent to work with." })] })] }));
}
// ---------------------------------------------------------------------------
// Inline SVG icons (SDK independence — no lucide dependency)
// ---------------------------------------------------------------------------
function XIcon() {
    return (_jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M4 4L10 10M10 4L4 10" }) }));
}
function FolderIcon({ className: cls }) {
    return (_jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", className: cn("shrink-0 text-muted-foreground", cls), children: _jsx("path", { d: "M1.5 3.5V11a1 1 0 001 1h9a1 1 0 001-1V5.5a1 1 0 00-1-1H7L5.5 3H2.5a1 1 0 00-1 .5z" }) }));
}
function FolderPlusIcon() {
    return (_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", className: "shrink-0 text-muted-foreground", children: [_jsx("path", { d: "M1.5 3.5V11a1 1 0 001 1h9a1 1 0 001-1V5.5a1 1 0 00-1-1H7L5.5 3H2.5a1 1 0 00-1 .5z" }), _jsx("path", { d: "M7 7v3M5.5 8.5h3" })] }));
}
function GitHubIcon() {
    return (_jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "currentColor", className: "shrink-0 text-muted-foreground", children: _jsx("path", { d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" }) }));
}
//# sourceMappingURL=WorkspaceTab.js.map