"use strict";

exports.__esModule = true;
exports.useCustomFieldsWidget = useCustomFieldsWidget;
var _react = require("react");
var _state = require("../state");
var _react2 = require("@wix/bex-core/react");
var _bexCore = require("@wix/bex-core");
var _useWidgetForm = require("./useWidgetForm");
function useCustomFieldsWidget({
  fqdn: fqdnString,
  fieldName = 'extendedFields',
  filterable,
  containsPii,
  defaultPermissions,
  extendedFields,
  enableArchive
}) {
  const fqdn = (0, _bexCore.parseFqdn)(fqdnString);
  const container = (0, _react2.useWixPatternsContainer)();
  const widgetForm = (0, _useWidgetForm.useWidgetForm)();
  const [{
    state,
    appLoaded
  }] = (0, _react.useState)(() => {
    const widgetState = new _state.CustomFieldsWidgetState({
      fqdn,
      container,
      filterable,
      containsPii,
      defaultPermissions,
      extendedFields,
      enableArchive
    });
    widgetForm == null || widgetForm.registerWidget(fieldName, widgetState);
    return {
      state: widgetState,
      appLoaded: widgetState._appLoadingStart()
    };
  });
  (0, _react.useEffect)(() => state.init({
    appLoaded
  }), []);
  return state;
}
//# sourceMappingURL=useCustomFieldsWidget.js.map