import { h } from "@stencil/core";
export class BceElementForm {
    async validate(silent = false) {
        const root = this.el.shadowRoot;
        const query = root.querySelectorAll('bce-input');
        const inputs = Array.from(query);
        const errors = await Promise.all(inputs.map(el => el.validate(silent)));
        return [].concat(...errors);
    }
    isSelect(input) {
        return input.type === 'radio';
    }
    renderInput(input) {
        return (h("bce-input", { id: input.id, key: input.id, label: input.label, type: input.type, validation: input.required ? 'required' : undefined }));
    }
    renderSelect(input) {
        return (h("bce-select", { id: input.id, key: input.id, label: input.label, type: input.type, validation: input.required ? 'required' : undefined }, (input.options || []).map((option, i) => (h("bce-option", { key: i, value: option }, option)))));
    }
    render() {
        return this.template.input.map(i => this.isSelect(i) ? this.renderSelect(i) : this.renderInput(i));
    }
    static get is() { return "bce-element-form"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() { return {
        "$": ["bce-element-form.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["bce-element-form.css"]
    }; }
    static get properties() { return {
        "handler": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "InputHandler",
                "resolved": "InputHandler",
                "references": {
                    "InputHandler": {
                        "location": "import",
                        "path": "../../../utils/input-handler"
                    }
                }
            },
            "required": true,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "language": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string | undefined",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "language",
            "reflect": false
        },
        "template": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "FormElement",
                "resolved": "FormElement",
                "references": {
                    "FormElement": {
                        "location": "import",
                        "path": "./element-form"
                    }
                }
            },
            "required": true,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        }
    }; }
    static get methods() { return {
        "validate": {
            "complexType": {
                "signature": "(silent?: boolean) => Promise<import(\"/Users/ngfk/Repositories/bce-module-editor/node_modules/@bcase/core/dist/types/index\").ValidatorError[]>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    },
                    "ValidatorError": {
                        "location": "global"
                    },
                    "HTMLBceInputElement": {
                        "location": "global"
                    },
                    "HTMLBceSelectElement": {
                        "location": "global"
                    },
                    "Inputs": {
                        "location": "global"
                    }
                },
                "return": "Promise<ValidatorError[]>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        }
    }; }
    static get elementRef() { return "el"; }
}
