"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { ChevronDown } from "lucide-react";
import { useState } from "react";
import { Popover, PopoverContent, PopoverTrigger, } from "../../../components/ui/popover";
import { useEditContext } from "../../client/editContext";
import { ProjectTemplateSelectorList } from "./ProjectTemplateSelectorList";
function getTemplateSummary(template) {
    if (!template) {
        return "Select a template to start";
    }
    return `${template.taskTemplates.length} task templates`;
}
export function ProjectTemplateSelector({ templates, selectedTemplate, selectedTemplateId, error, deleting, loading, onSelectTemplate, onDeleteTemplate, }) {
    const editContext = useEditContext();
    const isMobile = editContext?.isMobile;
    const [open, setOpen] = useState(false);
    const selectorTitle = selectedTemplate?.name?.trim() || "Workflow Project Templates";
    const selectorSummary = getTemplateSummary(selectedTemplate);
    return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs("button", { type: "button", "data-testid": "project-template-selector-trigger", className: "group badge-pad-sm hover:bg-neutral-grey-5/70 flex min-w-0 items-center gap-2 rounded-md text-left", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-0", children: [_jsx("div", { className: "text-neutral-grey-100 truncate text-sm leading-tight font-medium", children: selectorTitle }), !isMobile ? (_jsx("div", { className: "text-neutral-grey-50 flex flex-wrap items-center gap-2 text-[11px] leading-tight", children: _jsx("span", { className: "truncate", children: selectorSummary }) })) : null] }), _jsx(ChevronDown, { className: "text-neutral-grey-50 group-hover:text-neutral-grey-100 h-4 w-4 shrink-0" })] }) }), _jsx(PopoverContent, { align: "start", sideOffset: 8, className: "flex max-h-[60vh] w-[calc(100vw-2rem)] max-w-[560px] flex-col p-0", "data-testid": "project-template-selector-popover", children: _jsx(ProjectTemplateSelectorList, { templates: templates, selectedTemplateId: selectedTemplateId, error: error, deleting: deleting, loading: loading, onSelectTemplate: onSelectTemplate, onDeleteTemplate: onDeleteTemplate, onTemplateSelected: () => setOpen(false) }) })] }));
}
//# sourceMappingURL=ProjectTemplateSelector.js.map