import { r as registerInstance, c as createEvent, h, d as getElement } from './core-ef7fea85.js';

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

export { PwcDynamicForm as pwc_dynamic_form };
