"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class TriStateCheckbox {
    onInput(input) {
        this.state = { checked: input.checked || "false" };
    }
    triggerChange() {
        if (this.state.checked === "true") {
            this.state.checked = "false";
        }
        else if (this.state.checked === "false" && !this.input.skipMixed) {
            this.state.checked = "mixed";
        }
        else {
            this.state.checked = "true";
        }
    }
    handleChange(ev, el) {
        ev.preventDefault();
        this.triggerChange();
        this.forwardEvent("change", ev, el);
    }
    handleKeydown(ev, el) {
        this.forwardEvent("keydown", ev, el);
    }
    handleFocus(ev, el) {
        this.forwardEvent("focus", ev, el);
    }
    forwardEvent(eventName, originalEvent, el) {
        var _a;
        const value = (el || ((_a = this.el) === null || _a === void 0 ? void 0 : _a.querySelector("input"))).value;
        const checked = this.state.checked;
        this.emit(`${eventName}`, {
            originalEvent,
            value,
            checked,
        });
    }
}
module.exports = TriStateCheckbox;
