"use strict";

exports.__esModule = true;
exports.ImportButton = void 0;
var _react = _interopRequireWildcard(require("react"));
var _bexCore = require("@wix/bex-core");
var _designSystem = require("@wix/design-system");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _mobxReactLite = require("mobx-react-lite");
var _ImportButtonModalLayout = require("./ImportButtonModalLayout");
var _react2 = require("@wix/bex-core/react");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _ResponsiveButton = require("../ResponsiveButton/ResponsiveButton");
var _useIsMobile = require("../../hooks/useIsMobile");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/ImportButton/ImportButton.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 _ImportButton(props) {
  const {
    toolbarType = 'default',
    fields,
    bulkUploadItems,
    backup,
    batchSize
  } = props;
  const table = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const {
    toolbar: {
      responsive
    }
  } = table;
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const [state] = (0, _react.useState)(() => table.importState ?? (table.importState = new _bexCore.ModalState()));
  const isMobile = (0, _useIsMobile.useIsMobile)();
  (0, _react.useEffect)(() => {
    table.featuredComponents.importModal.set(/*#__PURE__*/_react.default.createElement(_mobxReactLite.Observer, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 33,
        columnNumber: 7
      }
    }, () => {
      const child = /*#__PURE__*/_react.default.createElement(_ImportButtonModalLayout.ImportButtonModalLayout, {
        importModalState: state,
        fields: fields,
        bulkUploadItems: bulkUploadItems,
        backup: backup,
        batchSize: batchSize,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 36,
          columnNumber: 13
        }
      });
      if (isMobile) {
        return /*#__PURE__*/_react.default.createElement(_designSystem.Drawer, {
          dataHook: "import-modal",
          open: state.isOpen,
          onClose: state.requestClose,
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 47,
            columnNumber: 15
          }
        }, child);
      }
      return /*#__PURE__*/_react.default.createElement(_designSystem.Modal, {
        onRequestClose: state.requestClose,
        isOpen: state.isOpen,
        dataHook: "import-modal",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 58,
          columnNumber: 13
        }
      }, child);
    }));
    return () => {
      table.featuredComponents.importModal.set(null);
    };
  }, []);
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-hook": "import-container",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 76,
      columnNumber: 5
    }
  }, toolbarType === 'default' ? /*#__PURE__*/_react.default.createElement(_ResponsiveButton.ResponsiveButton, {
    state: responsive.actions,
    dataHook: "import-button",
    onClick: state.open,
    icon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.DownloadImport, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 82,
        columnNumber: 17
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 78,
      columnNumber: 9
    }
  }, t('cairo.import.import')) : /*#__PURE__*/_react.default.createElement(_designSystem.Button, {
    skin: "standard",
    priority: "secondary",
    size: "small",
    ellipsis: true,
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.DownloadImport, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 92,
        columnNumber: 23
      }
    }),
    dataHook: "import-button",
    onClick: state.open,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 87,
      columnNumber: 9
    }
  }, t('cairo.import.import')));
}
const ImportButton = exports.ImportButton = (0, _mobxReactLite.observer)(_ImportButton);
//# sourceMappingURL=ImportButton.js.map