import { useEffect, useState } from 'react';
import { CustomFieldsWidgetState } from '../state';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { parseFqdn, } from '@wix/bex-core';
import { useWidgetForm } from './useWidgetForm';
export function useCustomFieldsWidget({ fqdn: fqdnString, fieldName = 'extendedFields', filterable, containsPii, defaultPermissions, extendedFields, enableArchive, }) {
    const fqdn = parseFqdn(fqdnString);
    const container = useWixPatternsContainer();
    const widgetForm = useWidgetForm();
    const [{ state, appLoaded }] = useState(() => {
        const widgetState = new CustomFieldsWidgetState({
            fqdn,
            container,
            filterable,
            containsPii,
            defaultPermissions,
            extendedFields,
            enableArchive,
        });
        widgetForm?.registerWidget(fieldName, widgetState);
        return {
            state: widgetState,
            appLoaded: widgetState._appLoadingStart(),
        };
    });
    useEffect(() => state.init({ appLoaded }), []);
    return state;
}
//# sourceMappingURL=useCustomFieldsWidget.js.map