'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const core = require('./core-6c8c650d.js');

const PwcDynamicForm = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        this.formChanged = core.createEvent(this, "formChanged", 7);
    }
    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 (core.h("form", null, core.h("slot", null)));
    }
    get rootElement() { return core.getElement(this); }
    static get style() { return ""; }
};

exports.pwc_dynamic_form = PwcDynamicForm;
