import { h, Host } from "@stencil/core";
import { scrollToFirstInvalidField } from "../../utils/form";
import { waitAfterFramePaint, waitAfterIdleCallback } from "../../utils/helpers";
export class Form {
    constructor() {
        /**
         * If `true` a native form element is added as a wrapper of the slot.
         */
        this.native = false;
        /**
         * If `true` it adds the novalidate attribute to the native form element.
         */
        this.novalidate = false;
        /**
         * The css class for the inner form element
         */
        this.formClass = '';
    }
    /**
     * Scrolls to the first invalid field inside this form component.
     */
    async scrollToFirstInvalidField() {
        await waitAfterIdleCallback();
        await waitAfterFramePaint();
        scrollToFirstInvalidField({ formEl: this.el });
    }
    render() {
        const NativeEl = this.native ? 'form' : 'div';
        let attrs = {};
        if (this.native) {
            attrs = {
                novalidate: this.novalidate,
            };
        }
        return (h(Host, { key: '8b3d28034718b1594fef9900e776ff718e16441d' }, h(NativeEl, Object.assign({ key: '4a21539e4b24d63f95813654d92ac8aa2c0f948b' }, attrs, { class: this.formClass }), h("slot", { key: '9b2a367a300b2803a4868c057e54d14952a557ca' }))));
    }
    static get is() { return "bal-form"; }
    static get originalStyleUrls() {
        return {
            "$": ["bal-form.sass"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bal-form.css"]
        };
    }
    static get properties() {
        return {
            "native": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` a native form element is added as a wrapper of the slot."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "native",
                "defaultValue": "false"
            },
            "novalidate": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` it adds the novalidate attribute to the native form element."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "novalidate",
                "defaultValue": "false"
            },
            "formClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The css class for the inner form element"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "form-class",
                "defaultValue": "''"
            }
        };
    }
    static get methods() {
        return {
            "scrollToFirstInvalidField": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Scrolls to the first invalid field inside this form component.",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
}
