"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CustomFieldsWidget = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _CustomFieldsWidgetContext = require("../CustomFieldsWidgetContext");
var _useCustomFieldsWidget = require("../../hooks/useCustomFieldsWidget");
var _CustomFieldsWidgetInline = require("./CustomFieldsWidgetInline");
var _CustomFieldsWidgetCard = require("./CustomFieldsWidgetCard");
var _mobx = require("mobx");
var _CustomFieldsWidgetCommonComponents = require("./CustomFieldsWidgetCommonComponents");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomFieldsWidget/CustomFieldsWidget.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const _CustomFieldsWidgetBase = ({
  subtitle,
  dataHook,
  hideEmptyState,
  emptyStateOverrides = {},
  state,
  theme = 'card',
  onChange,
  extendedFields
}) => {
  (0, _react.useState)(() => {
    (0, _mobx.runInAction)(() => {
      state._extendedFields = extendedFields;
    });
  });
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      state._extendedFields = extendedFields;
    });
  }, [extendedFields]);
  const hideWidget = hideEmptyState && (state.isLoading || state.dataExtension.availableCustomFields.length === 0);
  return /*#__PURE__*/_react.default.createElement(_CustomFieldsWidgetContext.CustomFieldsWidgetContextProvider, {
    value: state,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 44,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_CustomFieldsWidgetCommonComponents.CustomFieldsWidgetCommonComponents, {
    state: state,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 45,
      columnNumber: 7
    }
  }), !hideWidget && (theme === 'card' ? /*#__PURE__*/_react.default.createElement(_CustomFieldsWidgetCard.CustomFieldsWidgetCard, {
    state: state,
    emptyStateOverrides: emptyStateOverrides,
    subtitle: subtitle,
    dataHook: dataHook,
    onChange: onChange,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 48,
      columnNumber: 11
    }
  }) : /*#__PURE__*/_react.default.createElement(_CustomFieldsWidgetInline.CustomFieldsWidgetInline, {
    state: state,
    emptyStateOverrides: emptyStateOverrides,
    onChange: onChange,
    dataHook: dataHook,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 56,
      columnNumber: 11
    }
  })));
};
const CustomFieldsWidgetBase = (0, _mobxReactLite.observer)(_CustomFieldsWidgetBase);
const _CustomFieldsWidgetWithoutState = props => {
  const state = (0, _useCustomFieldsWidget.useCustomFieldsWidget)(props);
  return /*#__PURE__*/_react.default.createElement(CustomFieldsWidgetBase, (0, _extends2.default)({}, props, {
    state: state,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 73,
      columnNumber: 10
    }
  }));
};
const CustomFieldsWidgetWithoutState = (0, _mobxReactLite.observer)(_CustomFieldsWidgetWithoutState);
const _CustomFieldsWidget = props => {
  return props.state ? /*#__PURE__*/_react.default.createElement(CustomFieldsWidgetBase, (0, _extends2.default)({}, props, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 82,
      columnNumber: 5
    }
  })) : /*#__PURE__*/_react.default.createElement(CustomFieldsWidgetWithoutState, (0, _extends2.default)({}, props, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 84,
      columnNumber: 5
    }
  }));
};
const CustomFieldsWidget = exports.CustomFieldsWidget = (0, _mobxReactLite.observer)(_CustomFieldsWidget);
//# sourceMappingURL=CustomFieldsWidget.js.map