import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { ExternalLink, Plus, Target, X } from "lucide-react";
import { Button } from "../../../../components/ui/button";
import { Popover, PopoverContent, PopoverTrigger, } from "../../../../components/ui/popover";
import { ScrollingContentTree } from "../../../ScrollingContentTree";
export function AgentSkillSettingsSection({ showSkillPicker, onShowSkillPickerChange, readOnly, skillRootIds, selectedSkillIds, selectableTemplateIdSet, manuallyAssignableSkillIdSet, selectedSkills, autoAssignedSkillSet, skillsLoading, skillsError, skillActionError, profileFilteredSkills, onSkillActionErrorChange, onAddSkill, onOpenSkillItem, onRemoveSkill, }) {
    return (_jsxs("div", { children: [_jsxs("div", { className: "mb-1 flex items-center justify-between gap-2", children: [_jsxs("div", { className: "text-neutral-grey-100 flex items-center gap-1 text-[11px] font-medium", children: [_jsx(Target, { className: "h-3 w-3", strokeWidth: 1 }), "Skills"] }), _jsxs(Popover, { open: showSkillPicker, onOpenChange: (open) => {
                            onShowSkillPickerChange(open);
                            if (open) {
                                onSkillActionErrorChange(null);
                            }
                        }, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { size: "xs", variant: "outline", className: "text-neutral-grey-50 h-5 rounded border px-1.5 text-[10px]", "data-testid": "agent-skill-picker-trigger", disabled: readOnly, title: readOnly ? "Read-only access" : undefined, children: [_jsx(Plus, { className: "mr-1 h-3 w-3", strokeWidth: 1.5 }), "Add"] }) }), _jsx(PopoverContent, { className: "w-88 p-2", align: "end", side: "bottom", children: _jsxs("div", { className: "space-y-2", children: [_jsx("div", { className: "text-neutral-grey-100 text-[11px] font-medium", children: "Select a skill" }), _jsxs("div", { className: "border-border-default bg-neutral-grey-5 relative h-56 rounded border", children: [_jsx(ScrollingContentTree, { rootItemIds: skillRootIds, selectedItemId: selectedSkillIds[selectedSkillIds.length - 1] || undefined, expandedItemId: selectedSkillIds[selectedSkillIds.length - 1] ||
                                                        skillRootIds[0], scrollToSelected: true, hideRootNodes: false, onSelectionChange: (selection) => {
                                                        const selected = selection[0];
                                                        if (!selected?.id)
                                                            return;
                                                        onSkillActionErrorChange(null);
                                                        if (selectableTemplateIdSet.size > 0 &&
                                                            (!selected.templateId ||
                                                                !selectableTemplateIdSet.has(selected.templateId.toLowerCase()))) {
                                                            return;
                                                        }
                                                        if (!manuallyAssignableSkillIdSet.has(selected.id.toLowerCase())) {
                                                            onSkillActionErrorChange("This skill cannot be added for the current agent profile.");
                                                            return;
                                                        }
                                                        void (async () => {
                                                            const added = await onAddSkill(selected.id);
                                                            if (added) {
                                                                onShowSkillPickerChange(false);
                                                            }
                                                        })();
                                                    } }), skillsLoading ? (_jsx("div", { className: "bg-background/70 text-neutral-grey-50 absolute inset-0 flex items-center justify-center text-[10px]", children: "Loading skills..." })) : null] }), !skillsLoading &&
                                            !skillsError &&
                                            profileFilteredSkills.length > 0 ? (_jsx("div", { className: "text-neutral-grey-50 text-[10px]", children: "Click a skill item in the tree to add it." })) : null, skillsError ? (_jsx("div", { className: "text-feedback-red text-[10px]", children: skillsError })) : null, !skillsError && skillActionError ? (_jsx("div", { className: "text-feedback-red text-[10px]", children: skillActionError })) : null, !skillsLoading && !skillsError && skillRootIds.length === 0 ? (_jsx("div", { className: "text-neutral-grey-50 text-[10px]", children: "No skill roots available." })) : null, !skillsLoading &&
                                            !skillsError &&
                                            profileFilteredSkills.length === 0 ? (_jsx("div", { className: "text-neutral-grey-50 text-[10px]", children: selectedSkillIds.length > 0
                                                ? "All addable skills are selected"
                                                : "No skills can be added for this profile" })) : null] }) })] })] }), selectedSkillIds.length > 0 ? (_jsx("div", { className: "mb-2 flex flex-wrap gap-1", children: selectedSkillIds.map((skillId) => {
                    const skill = selectedSkills.find((item) => item.id === skillId);
                    return (_jsxs("div", { className: "border-border-default bg-neutral-grey-5 badge-pad-sm text-neutral-grey-100 inline-flex items-center gap-1 rounded-full border text-[10px]", children: [_jsx("span", { children: skill?.name || skillId }), _jsx("button", { type: "button", className: "text-neutral-grey-50 hover:bg-neutral-grey-10 hover:text-neutral-grey-100 rounded p-0.5", title: "Open skill item", "aria-label": `Open ${skill?.name || skillId}`, onClick: () => {
                                    void onOpenSkillItem(skillId);
                                }, children: _jsx(ExternalLink, { className: "h-2.5 w-2.5", strokeWidth: 1.5 }) }), autoAssignedSkillSet.has(skillId.toLowerCase()) ? (_jsx("span", { className: "text-neutral-grey-50 text-[9px]", children: "auto" })) : (_jsx("button", { type: "button", className: "text-neutral-grey-50 hover:bg-neutral-grey-10 hover:text-neutral-grey-100 rounded p-0.5", onClick: () => {
                                    void onRemoveSkill(skillId);
                                }, title: "Remove skill", "aria-label": `Remove ${skill?.name || skillId}`, children: _jsx(X, { className: "h-2.5 w-2.5", strokeWidth: 1 }) }))] }, skillId));
                }) })) : null] }));
}
//# sourceMappingURL=AgentSkillSettingsSection.js.map