"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.PickerModalSplash = PickerModalSplash;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _react2 = require("@wix/bex-utils/react");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/PickerModalSplash/PickerModalSplash.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 PickerModalSplash(props) {
  const {
    state,
    renderError,
    onCloseButtonClick,
    ...rest
  } = props;
  const {
    minContentHeight,
    fetchPickerComponent,
    fetchFirstPage,
    fetchInitialProps,
    _isModalOpen
  } = state;
  const fetchPickerComponentStatus = (0, _react2.useReactive)(fetchPickerComponent.status);
  const fetchFirstPageStatus = (0, _react2.useReactive)(fetchFirstPage.status);
  const fetchInitialPropsStatus = (0, _react2.useReactive)(fetchInitialProps.status);
  const fetchStatuses = (0, _react.useMemo)(() => [fetchPickerComponentStatus, fetchFirstPageStatus, fetchInitialPropsStatus], [fetchPickerComponentStatus, fetchFirstPageStatus, fetchInitialPropsStatus]);
  const errorStatus = (0, _react.useMemo)(() => {
    return fetchStatuses.find(status => status.type === 'error');
  }, [fetchStatuses]);
  const isFetching = (0, _react.useMemo)(() => {
    return fetchStatuses.some(status => status.type === 'loading' || status.type === 'idle');
  }, [fetchStatuses]);
  let child;
  if (errorStatus) {
    child = renderError({
      err: errorStatus.error,
      isOnline: true
    });
    child = /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      dataHook: "splash-error-container",
      align: "center",
      verticalAlign: "middle",
      padding: "SP6",
      minHeight: minContentHeight,
      boxSizing: "border-box",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 64,
        columnNumber: 7
      }
    }, child);
  } else if (isFetching) {
    child = /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      height: minContentHeight,
      align: "center",
      verticalAlign: "middle",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 77,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Loader, {
      dataHook: "splash-loader",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 78,
        columnNumber: 9
      }
    }));
  }
  return /*#__PURE__*/_react.default.createElement(_designSystem.CustomModalLayout, (0, _extends2.default)({
    removeContentPadding: true,
    closeButtonProps: {
      onClick: event => {
        _isModalOpen.value = false;
        onCloseButtonClick == null || onCloseButtonClick(event);
      },
      autoFocus: true
    }
  }, rest, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 84,
      columnNumber: 5
    }
  }), child);
}
//# sourceMappingURL=PickerModalSplash.js.map