"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.PickerModal = PickerModal;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@wix/bex-utils/react");
var _PickerModalSplash = require("../PickerModalSplash");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/PickerModal/PickerModal.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); }
function PickerModal(props) {
  const {
    dataHook,
    state,
    modalProps,
    renderError,
    width = '618px',
    multiple,
    ...rest
  } = props;
  const {
    _isModalOpen,
    _customContent,
    _isCustomContentVisible,
    fetchPickerComponent,
    fetchFirstPage,
    fetchInitialProps
  } = state;
  const isModalOpen = (0, _react2.useReactive)(_isModalOpen);
  const fetchPickerComponentStatus = (0, _react2.useReactive)(fetchPickerComponent.status);
  const fetchFirstPageStatus = (0, _react2.useReactive)(fetchFirstPage.status);
  const fetchInitialPropsStatus = (0, _react2.useReactive)(fetchInitialProps.status);
  const customContent = (0, _react2.useReactive)(_customContent);
  const isCustomContentVisible = (0, _react2.useReactive)(_isCustomContentVisible);
  (0, _react.useState)(() => {
    state.multipleRef.current = multiple;
  });
  (0, _react.useEffect)(() => {
    state.multipleRef.current = multiple;
  }, [multiple]);
  (0, _react.useEffect)(() => {
    state.onIsOpenChanged();
  }, [isModalOpen]);
  (0, _react.useEffect)(() => state.init(), []);
  let child;
  if (fetchPickerComponentStatus.type === 'success' && fetchFirstPageStatus.type === 'success' && fetchInitialPropsStatus.type === 'success') {
    const {
      data: PickerContentComponent
    } = fetchPickerComponentStatus;
    child = /*#__PURE__*/_react.default.createElement(PickerContentComponent, (0, _extends2.default)({
      dataHook: dataHook,
      width: "100%",
      modalState: state,
      renderError: renderError,
      multiple: multiple
    }, rest, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 83,
        columnNumber: 7
      }
    }));
  } else {
    child = /*#__PURE__*/_react.default.createElement(_PickerModalSplash.PickerModalSplash, (0, _extends2.default)({
      dataHook: dataHook,
      state: state,
      width: "100%",
      renderError: renderError
    }, rest, {
      primaryButtonText: undefined,
      secondaryButtonText: undefined,
      primaryButtonOnClick: undefined,
      secondaryButtonOnClick: undefined,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 94,
        columnNumber: 7
      }
    }));
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_designSystem.Modal, (0, _extends2.default)({
    dataHook: dataHook ? `${dataHook}-picker-modal` : 'picker-modal-lazy-modal',
    onRequestClose: () => state.closeModal()
  }, modalProps, {
    isOpen: isModalOpen,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 110,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement("div", {
    "data-wix-patterns": true,
    style: {
      width,
      maxHeight: '100%',
      display: 'flex'
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 118,
      columnNumber: 9
    }
  }, child)), customContent == null ? void 0 : customContent({
    isOpen: isCustomContentVisible,
    width,
    close: state.onCreateNew
  }));
}
//# sourceMappingURL=PickerModal.js.map