import { h } from "@stencil/core";
export class PwcDynamicForm {
    handleFieldChanged(fieldChangedEventPayload) {
        const rootElement = this.rootElement;
        this.getFieldValues().then(v => {
            const formChangedEventPayload = {
                type: "change",
                fieldChangedEventPayload,
                formResetEvent: null,
                formValues: v,
                formElement: rootElement
            };
            this.formChanged.emit(formChangedEventPayload);
        });
    }
    handleFormReset(formResetEvent) {
        const rootElement = this.rootElement;
        this.getFieldValues().then(v => {
            const formChangedEventPayload = {
                type: "reset",
                fieldChangedEventPayload: null,
                formResetEvent,
                formValues: v,
                formElement: rootElement
            };
            this.formChanged.emit(formChangedEventPayload);
        });
    }
    async getFieldValues() {
        const fieldRefs = await this.contentRef.getFieldRefs();
        const vals = {};
        fieldRefs.forEach(async (field) => {
            const val = await field.getValue();
            vals[field.config.name] = val;
        });
        return vals;
    }
    componentDidRender() {
        this.contentRef = this.rootElement.querySelector("pwc-dynamic-form-content");
    }
    render() {
        return (h("form", null,
            h("slot", null)));
    }
    static get is() { return "pwc-dynamic-form"; }
    static get originalStyleUrls() { return {
        "$": ["pwc-dynamic-form.css"]
    }; }
    static get styleUrls() { return {
        "$": ["pwc-dynamic-form.css"]
    }; }
    static get events() { return [{
            "method": "formChanged",
            "name": "formChanged",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "complexType": {
                "original": "FormChangedEventPayload",
                "resolved": "FormChangedEventPayload",
                "references": {
                    "FormChangedEventPayload": {
                        "location": "import",
                        "path": "./FormChangedEventPayload"
                    }
                }
            }
        }]; }
    static get methods() { return {
        "getFieldValues": {
            "complexType": {
                "signature": "() => Promise<FormValuesType>",
                "parameters": [],
                "references": {
                    "Promise": {
                        "location": "global"
                    },
                    "FormValuesType": {
                        "location": "import",
                        "path": "./FormValuesType"
                    }
                },
                "return": "Promise<FormValuesType>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        }
    }; }
    static get elementRef() { return "rootElement"; }
    static get listeners() { return [{
            "name": "fieldChanged",
            "method": "handleFieldChanged",
            "target": undefined,
            "capture": false,
            "passive": false
        }, {
            "name": "reset",
            "method": "handleFormReset",
            "target": undefined,
            "capture": false,
            "passive": false
        }]; }
}
