"use strict";

exports.__esModule = true;
exports.ExportButton = 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 _ExportButtonModalLayout = require("./ExportButtonModalLayout");
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/ExportButton/ExportButton.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 _ExportButton(props) {
  const {
    toolbarType = 'default',
    renderError,
    transformPlatformizedQuery,
    differentQueryEndpointThanCollection,
    customTotal,
    methodMetadata,
    arrayFieldDelimiter,
    methodSpec,
    fields,
    saveAs,
    exportModalFooter,
    exportModalTitle,
    onProgressModalTitle,
    exportToCSVMessage
  } = props;
  const table = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const {
    toolbar: {
      responsive
    }
  } = table;
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const [state] = (0, _react.useState)(() => table.exportState ?? (table.exportState = new _bexCore.ModalState()));
  const isMobile = (0, _useIsMobile.useIsMobile)();
  (0, _react.useEffect)(() => {
    table.featuredComponents.exportModal.set(/*#__PURE__*/_react.default.createElement(_mobxReactLite.Observer, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 47,
        columnNumber: 7
      }
    }, () => {
      const child = /*#__PURE__*/_react.default.createElement(_ExportButtonModalLayout.ExportButtonModalLayout, {
        exportModalState: state,
        renderError: renderError,
        transformPlatformizedQuery: transformPlatformizedQuery,
        customTotal: customTotal,
        arrayFieldDelimiter: arrayFieldDelimiter,
        differentQueryEndpointThanCollection: differentQueryEndpointThanCollection,
        methodMetadata: methodMetadata,
        methodSpec: methodSpec,
        fields: fields,
        saveAs: saveAs,
        exportModalFooter: exportModalFooter,
        exportModalTitle: exportModalTitle,
        onProgressModalTitle: onProgressModalTitle,
        exportToCSVMessage: exportToCSVMessage,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 50,
          columnNumber: 13
        }
      });
      if (isMobile) {
        return /*#__PURE__*/_react.default.createElement(_designSystem.Drawer, {
          dataHook: "export-modal",
          open: state.isOpen,
          onClose: state.requestClose,
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 72,
            columnNumber: 15
          }
        }, child);
      }
      return /*#__PURE__*/_react.default.createElement(_designSystem.Modal, {
        onRequestClose: state.requestClose,
        isOpen: state.isOpen,
        dataHook: "export-modal",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 83,
          columnNumber: 13
        }
      }, child);
    }));
    return () => {
      table.featuredComponents.exportModal.set(null);
    };
  }, []);
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-hook": "export-container",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 101,
      columnNumber: 5
    }
  }, toolbarType === 'default' ? /*#__PURE__*/_react.default.createElement(_ResponsiveButton.ResponsiveButton, {
    state: responsive.actions,
    dataHook: "export-button",
    onClick: state.open,
    icon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.UploadExport, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 107,
        columnNumber: 17
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 103,
      columnNumber: 9
    }
  }, t('cairo.export.export')) : /*#__PURE__*/_react.default.createElement(_designSystem.Button, {
    skin: "standard",
    priority: "secondary",
    size: "small",
    ellipsis: true,
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.UploadExport, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 117,
        columnNumber: 23
      }
    }),
    dataHook: "export-button",
    onClick: state.open,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 112,
      columnNumber: 9
    }
  }, t('cairo.export.export')));
}
const ExportButton = exports.ExportButton = (0, _mobxReactLite.observer)(_ExportButton);
//# sourceMappingURL=ExportButton.js.map