import { r as registerInstance, h, g as getElement } from './index-b13326fc.js';

const BceElementMatrix = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.value = this.template
            ? Array(this.template.rows.length).fill(null)
            : [];
        this.handleInput = (event) => {
            event.cancelBubble = true;
            const rows = this.el.shadowRoot.querySelectorAll('bce-select');
            this.value = Array.from(rows).map(el => {
                const str = typeof el.value === 'string' && el.value.split(',')[1];
                return str ? parseInt(str, 10) : null;
            });
            this.el.dispatchEvent(new Event('input', { bubbles: true }));
        };
    }
    async validate(silent = false) {
        const root = this.el.shadowRoot;
        const inputs = Array.from(root.querySelectorAll('bce-select'));
        const errors = await Promise.all(inputs.map(el => el.validate(silent)));
        return [].concat(...errors);
    }
    renderHeader() {
        return this.handler.t('columns').map(col => {
            if (col.icon)
                return h("bce-icon", { raw: col.icon, style: { color: col.color } });
            return h("label", null, col.text);
        });
    }
    renderRow(r) {
        if (!this.template)
            return null;
        const value = this.value[r] != null ? `${r},${this.value[r]}` : null;
        return (h("bce-select", { allowNull: this.allowNull, design: "matrix", type: "radio", value: value, validation: this.template.required ? 'required' : '', onInput: this.handleInput }, this.template.columns.map((_, c) => (h("bce-option", { allowNull: this.allowNull, value: `${r},${c}` })))));
    }
    render() {
        if (!this.template)
            return null;
        const { orientation } = this.template;
        const rows = this.handler
            .t('rows')
            .map((row, i) => [
            h("label", { class: "row" }, row.text),
            this.renderRow(i)
        ]);
        return [
            h("p", null, this.handler.t('question')),
            h("div", null),
            h("div", { class: "cl", "data-orientation": orientation }, this.renderHeader()),
            rows
        ];
    }
    get el() { return getElement(this); }
    static get style() { return ":host{display:grid;grid-template:\"qu qu\" \".. cl\" auto/auto auto;margin:20px 0}:host>p{font-weight:500;text-align:center;grid-area:qu;text-align:center}\@media screen and (min-width: 1024px){:host>p{text-align:left}}:host .row{margin:0 10px 10px 0}:host bce-select{-ms-flex-pack:center;justify-content:center;margin:0 0 10px}:host .cl{grid-area:cl;position:relative;display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;text-align:center}:host .cl bce-icon{font-size:40px}:host .cl label{display:-ms-flexbox;display:flex;-ms-flex-pack:start;justify-content:flex-start;-ms-flex-align:center;align-items:center;width:25px;padding:16px 0 0 7px;-webkit-writing-mode:vertical-rl;-ms-writing-mode:tb-rl;writing-mode:vertical-rl;-webkit-transform:rotate(180deg);transform:rotate(180deg)}:host .cl label:before{content:\"\";margin-left:-100%}:host .cl label:after{content:\"\";margin-right:-100%}\@media screen and (min-width: 1024px){:host bce-select,:host .cl{margin:0 40px 10px}:host .cl[data-orientation=horizontal] label{-ms-flex-pack:center;justify-content:center;padding:0 0 16px 7px;-webkit-writing-mode:horizontal-tb;-ms-writing-mode:lr-tb;writing-mode:horizontal-tb;-webkit-transform:none;transform:none}}"; }
};

export { BceElementMatrix as bce_element_matrix };
