import { r as registerInstance, h, H as Host, g as getElement } from './core-095fd691.js';
var BceElementRadio = /** @class */ (function () {
    function class_1(hostRef) {
        var _this = this;
        registerInstance(this, hostRef);
        this.handleFocus = function (event) {
            var input = event.target;
            _this.value = {
                index: _this.template.options.length - 1,
                text: input.value
            };
            _this.el.dispatchEvent(new Event('input', { bubbles: true }));
        };
        this.handleOption = function (event) {
            if (!_this.template)
                return;
            event.cancelBubble = true;
            var input = event.target;
            var index = parseInt(input.value, 10);
            var text = _this.template.options[index].text;
            _this.value = { index: index, text: text };
            if (_this.template.other && index === _this.template.options.length - 1) {
                var query = _this.el.querySelector('bce-option bce-input');
                var input_1 = query;
                _this.value.text = input_1.value;
                input_1.querySelector('input').focus();
            }
            _this.el.dispatchEvent(new Event('input', { bubbles: true }));
        };
        this.handleInput = function (event) {
            event.cancelBubble = true;
            _this.value = {
                index: _this.template.options.length - 1,
                text: event.target.value
            };
            _this.el.dispatchEvent(new Event('input', { bubbles: true }));
        };
    }
    class_1.prototype.renderOther = function (option) {
        return (h("bce-input", { placeholder: option.text, onFocus: this.handleFocus, onInput: this.handleInput }));
    };
    class_1.prototype.renderOption = function (option, index) {
        if (!this.template)
            return null;
        var other = this.template.other && index === this.template.options.length - 1;
        return (h("bce-option", { value: '' + index }, other ? this.renderOther(option) : option.text));
    };
    class_1.prototype.render = function () {
        var _this = this;
        if (!this.template)
            return null;
        return (h(Host, { orientation: this.template.orientation }, h("p", null, this.template.question), h("bce-input", { type: "radio", validation: this.template.required ? 'required' : '', value: '' + (this.value ? this.value.index : -1), onInput: this.handleOption }, this.template.options.map(function (o, i) { return _this.renderOption(o, i); }))));
    };
    Object.defineProperty(class_1.prototype, "el", {
        get: function () { return getElement(this); },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(class_1, "style", {
        get: function () { return "bce-element-radio p{font-weight:500;text-align:center}\@media screen and (min-width:1024px){bce-element-radio p{text-align:left}}bce-element-radio[orientation=horizontal] bce-input>[data-input]{display:-ms-flexbox;display:flex}bce-element-radio[orientation=horizontal] bce-input>[data-input] bce-option{margin-right:1.5rem}bce-element-radio bce-option[type=radio][checked] bce-input[focus] input{border-color:var(--bce-color-n)}bce-element-radio bce-option[type=radio][checked] bce-input input{border:1px solid var(--bce-color-light-d)}bce-element-radio bce-option[type=radio] bce-input{margin:0;width:auto;min-width:200px}bce-element-radio bce-option[type=radio] bce-input input{margin:0;min-width:200px;border-radius:4px}"; },
        enumerable: true,
        configurable: true
    });
    return class_1;
}());
export { BceElementRadio as bce_element_radio };
