import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo, useState, useSyncExternalStore } from "react";
import { FolderPlus, LayoutGrid, Search } from "lucide-react";
import { Input } from "../../components/ui/input";
import { cn } from "../../lib/utils";
import { SimpleIconButton } from "../../editor/ui/SimpleIconButton";
import { SimpleToolbar } from "../../editor/ui/SimpleToolbar";
import { getTaskBoardNavSnapshot, subscribeTaskBoardNav, } from "../taskBoardNavStore";
export function TaskBoardProjectListSidebar() {
    const nav = useSyncExternalStore(subscribeTaskBoardNav, getTaskBoardNavSnapshot, getTaskBoardNavSnapshot);
    const [search, setSearch] = useState("");
    const [hideArchived, setHideArchived] = useState(true);
    const projects = useMemo(() => {
        const query = search.trim().toLowerCase();
        return nav.projectOptions.filter((project) => {
            if (hideArchived && project.status?.toLowerCase() === "archived") {
                return false;
            }
            if (!query)
                return true;
            const title = project.title?.toLowerCase() ?? "";
            const description = project.description?.toLowerCase() ?? "";
            const status = project.status?.toLowerCase() ?? "";
            return (title.includes(query) ||
                description.includes(query) ||
                status.includes(query));
        });
    }, [hideArchived, nav.projectOptions, search]);
    return (_jsxs("div", { className: "flex h-full min-h-0 flex-col bg-white", "data-testid": "taskboard-project-list-sidebar", children: [_jsx(SimpleToolbar, { children: _jsx(SimpleIconButton, { onClick: () => nav.onCreateProject?.(), icon: _jsx(FolderPlus, { className: "h-4 w-4", strokeWidth: 1 }), label: "New project", "data-testid": "taskboard-project-list-create-button" }) }), _jsxs("div", { className: "border-border-default border-b px-3 py-2.5", children: [_jsxs("div", { className: "relative mb-2", children: [_jsx(Search, { className: "text-neutral-grey-50 pointer-events-none absolute top-1/2 left-2.5 h-3.5 w-3.5 -translate-y-1/2" }), _jsx(Input, { value: search, onChange: (event) => setSearch(event.target.value), placeholder: "Search projects...", className: "h-8 pl-8 text-xs", "data-testid": "taskboard-project-list-search" })] }), _jsxs("label", { className: "text-neutral-grey-50 flex items-center gap-2 text-xs", children: [_jsx("input", { type: "checkbox", checked: hideArchived, onChange: (event) => setHideArchived(event.target.checked), "data-testid": "taskboard-project-list-hide-archived" }), "Hide archived projects"] })] }), _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: projects.length === 0 ? (_jsx("div", { className: "text-neutral-grey-50 rounded-md border border-dashed px-3 py-8 text-center text-xs", children: "No projects found" })) : (_jsx("div", { className: "flex flex-col gap-1", children: projects.map((project) => {
                        const selected = project.projectId === nav.selectedProjectId;
                        const depth = Math.max(0, Math.min(project.depth ?? 0, 6));
                        return (_jsxs("button", { type: "button", className: cn("w-full rounded-md border px-2 py-2 text-left transition-colors", selected
                                ? "border-border-default bg-neutral-grey-5"
                                : "hover:border-border-default hover:bg-neutral-grey-5/70 border-transparent"), style: { paddingLeft: `${8 + depth * 12}px` }, onClick: () => nav.onSelectProject?.(project.projectId), "data-testid": `taskboard-project-list-option-${project.projectId}`, children: [_jsxs("div", { className: "flex items-center gap-1.5", children: [_jsx(LayoutGrid, { className: "text-neutral-grey-50 h-3.5 w-3.5" }), _jsx("span", { className: "text-neutral-grey-100 truncate text-xs font-medium", children: project.title })] }), project.description ? (_jsx("div", { className: "text-neutral-grey-50 mt-0.5 line-clamp-2 pl-5 text-[10px]", children: project.description })) : null] }, project.projectId));
                    }) })) })] }));
}
//# sourceMappingURL=TaskBoardProjectListSidebar.js.map