"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ImportButtonModalLayout = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _getImportModalStepProps = require("./getImportModalStepProps");
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _bexCore = require("@wix/bex-core");
var _util = require("@wix/bex-core/util");
var _useIsMobile = require("../../hooks/useIsMobile");
var _CustomDrawerLayout = require("../CustomDrawerLayout");
var _ImportStepper = require("./ImportStepper");
var _ActionModal = require("../ActionModal");
var _CollectionModal = require("../CollectionModal");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/ImportButton/ImportButtonModalLayout.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 _ImportButtonModalLayout(props) {
  const {
    fields,
    bulkUploadItems,
    backup,
    batchSize,
    importModalState,
    ...rest
  } = props;
  const isMobile = (0, _useIsMobile.useIsMobile)();
  const createImport = (0, _bexCore.useCreateImport)({
    fields,
    bulkUploadItems,
    backup,
    batchSize,
    importModalState
  });
  const [state] = (0, _react.useState)(() => createImport());
  const {
    onRequestClose,
    children,
    removeContentPadding,
    ...customModalLayoutProps
  } = (0, _getImportModalStepProps.getImportModalStepProps)({
    state,
    isMobile
  });
  const wrappedChildren = state.currentStep !== 'progress' ? /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    direction: "vertical",
    gap: "SP3",
    width: "100%",
    height: "100%",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 55,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_ImportStepper.ImportStepper, {
    state: state,
    removeContentPadding: !removeContentPadding,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 56,
      columnNumber: 9
    }
  }), children) : children;
  (0, _react.useEffect)(() => {
    if (onRequestClose) {
      return (0, _util.addEventListener)(importModalState.events, 'requestClose', onRequestClose);
    }
    return undefined;
  }, [onRequestClose]);
  (0, _react.useEffect)(() => state.init(), []);
  const t = state.translate;
  const {
    modal: discardModal
  } = state.discardChangesModal;
  if (isMobile) {
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CustomDrawerLayout.CustomDrawerLayout, (0, _extends2.default)({
      dataHook: "import-modal-layout",
      removeContentPadding: removeContentPadding
    }, rest, customModalLayoutProps, {
      children: wrappedChildren,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 87,
        columnNumber: 9
      }
    })), /*#__PURE__*/_react.default.createElement(_CollectionModal.ModalWrapper, {
      state: discardModal,
      onAfterClose: () => state.discardChangesModal.afterClose(),
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 94,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.ModalMobileLayout, {
      dataHook: "import-discard-changes-modal",
      title: /*#__PURE__*/_react.default.createElement(_designSystem.Heading, {
        size: "small",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 101,
          columnNumber: 15
        }
      }, t('cairo.import.discardChanges.title')),
      content: /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 106,
          columnNumber: 15
        }
      }, t('cairo.import.discardChanges.description')),
      onCloseButtonClick: () => discardModal.close(),
      stickyFooter: true,
      footer: /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        direction: "vertical",
        gap: "SP3",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 111,
          columnNumber: 15
        }
      }, /*#__PURE__*/_react.default.createElement(_designSystem.Button, {
        dataHook: "import-discard-confirm",
        fullWidth: true,
        skin: "destructive",
        onClick: () => discardModal.confirm(),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 112,
          columnNumber: 17
        }
      }, t('cairo.import.discardChanges.confirm')), /*#__PURE__*/_react.default.createElement(_designSystem.Button, {
        dataHook: "import-discard-cancel",
        fullWidth: true,
        priority: "secondary",
        onClick: () => discardModal.decline(),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 120,
          columnNumber: 17
        }
      }, t('cairo.import.discardChanges.cancel'))),
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 98,
        columnNumber: 11
      }
    })));
  }
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_designSystem.CustomModalLayout, (0, _extends2.default)({
    width: "600px",
    maxHeight: "80vh",
    dataHook: "import-modal-layout",
    removeContentPadding: removeContentPadding
  }, rest, customModalLayoutProps, {
    children: wrappedChildren,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 138,
      columnNumber: 7
    }
  })), /*#__PURE__*/_react.default.createElement(_ActionModal.MessageActionModal, {
    dataHook: "import-discard-changes-modal",
    state: state.discardChangesModal,
    title: t('cairo.import.discardChanges.title'),
    content: t('cairo.import.discardChanges.description'),
    primaryButtonText: t('cairo.import.discardChanges.confirm'),
    secondaryButtonText: t('cairo.import.discardChanges.cancel'),
    theme: "destructive",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 147,
      columnNumber: 7
    }
  }));
}
const ImportButtonModalLayout = exports.ImportButtonModalLayout = (0, _mobxReactLite.observer)(_ImportButtonModalLayout);
//# sourceMappingURL=ImportButtonModalLayout.js.map