"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SegmentedButtons {
    onCreate() {
        this.state = {
            selectedIndex: 0,
        };
    }
    onInput(input) {
        let selectedIndex = (input.button || []).findIndex((button) => button.selected);
        if (selectedIndex === -1) {
            selectedIndex = 0;
        }
        this.state.selectedIndex = selectedIndex;
    }
    onButtonClick(index, ev) {
        if (index !== this.state.selectedIndex) {
            this.state.selectedIndex = index;
            const value = this.input.button
                ? [...this.input.button][index].value || undefined
                : undefined;
            this.emit("change", {
                index,
                value,
                originalEvent: ev,
            });
        }
    }
}
module.exports = SegmentedButtons;
