import { Container, getKeybindings, Input, SelectList, Spacer, Text } from "@voxcode-dev/voxcode-tui";
import { getSelectListTheme } from "../theme/theme.js";
import { DynamicBorder } from "./dynamic-border.js";
export class SkillsSelectorComponent extends Container {
    filterInput;
    skillList;
    _focused = false;
    get focused() {
        return this._focused;
    }
    set focused(value) {
        this._focused = value;
        this.filterInput.focused = value;
    }
    constructor(skills, onSelect) {
        super();
        this.addChild(new DynamicBorder());
        this.addChild(new Spacer(1));
        this.addChild(new Text(getSelectListTheme().selectedPrefix(` Skills (${skills.length}) `)));
        this.addChild(new Spacer(1));
        this.filterInput = new Input();
        this.addChild(this.filterInput);
        this.addChild(new Spacer(1));
        this.skillList = new SelectList(skills.map((s) => ({
            value: s.name,
            label: s.name,
            description: s.description || "No description",
        })), 10, getSelectListTheme());
        this.skillList.onSelect = (item) => {
            if (item) {
                onSelect({ skill: item.value, load: true });
            }
        };
        this.skillList.onCancel = () => {
            onSelect(null);
        };
        this.addChild(this.skillList);
        this.addChild(new Spacer(1));
        this.addChild(new DynamicBorder());
    }
    handleInput(data) {
        const kb = getKeybindings();
        // Route navigation/selection keys to the list, everything else to filter input
        if (kb.matches(data, "tui.select.up") ||
            kb.matches(data, "tui.select.down") ||
            kb.matches(data, "tui.select.confirm") ||
            kb.matches(data, "tui.select.cancel")) {
            this.skillList.handleInput(data);
        }
        else {
            this.filterInput.handleInput(data);
            const text = this.filterInput.getValue();
            this.skillList.setFilter(text);
        }
    }
}
//# sourceMappingURL=skills-selector.js.map