import { CustomFieldsViewWidgetState, parseFqdn } from '@wix/bex-core';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { useEffect, useMemo, useState } from 'react';
export const useCustomFieldsViewWidget = ({ fqdn, extendedFields, theme, extensionPoint, }) => {
    const container = useWixPatternsContainer();
    const [state] = useState(() => new CustomFieldsViewWidgetState({
        container,
        fqdn: parseFqdn(fqdn),
        url: window.location.href,
        route: window.location.pathname,
        theme,
        extensionPoint,
    }));
    useEffect(() => state.init(), []);
    const userCustomFields = state.dataExtension.availableUserCustomFields;
    const appsCustomFields = state.dataExtension.availableAppsCustomFields;
    const areAllCustomFieldsEmpty = useMemo(() => {
        return state.dataExtension.allNamespaces.every((namespace) => state.getExtendedFieldsToDisplayForNamespace(namespace, extendedFields)
            .length === 0);
    }, [extendedFields, userCustomFields, state.dataExtension.appSchemas]);
    return {
        state,
        userCustomFields,
        appsCustomFields,
        container,
        areAllCustomFieldsEmpty,
    };
};
//# sourceMappingURL=useCustomFieldsViewWidget.js.map