"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ManageViewPopover = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _react2 = require("@wix/bex-core/react");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CollectionViewsDropdown/ManageViewPopover.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 _ManageViewPopover(props, ref) {
  var _views$currentView, _views$currentView2, _views$currentView3;
  const container = (0, _react2.useWixPatternsContainer)();
  const {
    state,
    redesign
  } = props;
  const {
    views,
    table,
    emitter,
    isViewChanged
  } = state;
  const buttonRef = (0, _react.useRef)(null);
  (0, _react.useImperativeHandle)(ref, () => ({
    focusTrigger: () => {
      var _buttonRef$current;
      return (_buttonRef$current = buttonRef.current) == null ? void 0 : _buttonRef$current.focus();
    }
  }));
  const {
    translate: t
  } = container;
  const triggerElement = redesign ? /*#__PURE__*/_react.default.createElement(_designSystem.IconButton, {
    ref: buttonRef,
    tabIndex: 0,
    size: "tiny",
    dataHook: "manage-view-popover-button",
    onClick: e => {
      // Stop propagation so clicking the 3-dots button doesn't select
      // the dropdown option it sits inside of.
      e.stopPropagation();
      // Prevent default so the click doesn't trigger form submission
      // or other native behavior while inside DropdownLayout.
      e.preventDefault();
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 47,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.MoreSmall, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 61,
      columnNumber: 7
    }
  })) : /*#__PURE__*/_react.default.createElement(_designSystem.TextButton, {
    size: "small",
    as: "button",
    dataHook: "manage-view-popover-button",
    suffixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.ChevronDown, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 68,
        columnNumber: 19
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 64,
      columnNumber: 5
    }
  }, t('cairo.manageView.CTA'));
  return /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu, (0, _extends2.default)({
    minWidth: 271
  }, redesign && {
    placement: 'right',
    appendTo: 'window'
  }, {
    onShow: () => {
      emitter.emit('openManageViewPopoverMenu');
    },
    dataHook: "manage-view-popover",
    triggerElement: triggerElement,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 75,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, {
    text: t('cairo.manageView.saveChanges.CTA'),
    dataHook: "save-changes-to-view",
    disabled: !views.isCurrentViewSelected || !isViewChanged || ((_views$currentView = views.currentView) == null ? void 0 : _views$currentView.isPreset),
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Confirm, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 92,
        columnNumber: 21
      }
    }),
    onClick: () => {
      state.saveViewChanges();
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 84,
      columnNumber: 7
    }
  }), !redesign && /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, {
    dataHook: "save-new-view",
    disabled: views.reachedViewsLimit,
    onClick: () => {
      views.saveViewModal.open();
      table.closeSidePanel();
    },
    text: t('cairo.manageView.saveNewView.CTA'),
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Duplicate, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 106,
        columnNumber: 23
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 98,
      columnNumber: 9
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, {
    dataHook: "rename-view",
    disabled: ((_views$currentView2 = views.currentView) == null ? void 0 : _views$currentView2.isPreset) || isViewChanged,
    onClick: () => {
      views.renameViewModal.open();
      table.closeSidePanel();
    },
    text: t('cairo.manageView.Rename.CTA'),
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Edit, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 117,
        columnNumber: 21
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 109,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, {
    dataHook: "set-as-default-view",
    disabled: !views.currentView || isViewChanged && !views.isDefaultView,
    onClick: () => {
      state.setAsDefaultView();
    },
    text: views.isDefaultView ? t('cairo.manageView.setAsDefault.reset.CTA') : t('cairo.manageView.setAsDefault.CTA'),
    prefixIcon: views.isDefaultView ? redesign ? /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Revert, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 133,
        columnNumber: 15
      }
    }) : /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.FlagDismiss, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 135,
        columnNumber: 15
      }
    }) : redesign ? /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Pin, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 138,
        columnNumber: 13
      }
    }) : /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Flag, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 140,
        columnNumber: 13
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 119,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, {
    dataHook: "delete-view",
    disabled: !views.isCurrentViewSelected || ((_views$currentView3 = views.currentView) == null ? void 0 : _views$currentView3.isPreset),
    onClick: () => {
      state.deleteView();
    },
    text: t('cairo.manageView.Delete.CTA'),
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Delete, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 151,
        columnNumber: 21
      }
    }),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 144,
      columnNumber: 7
    }
  }));
}
const ManageViewPopover = exports.ManageViewPopover = (0, _mobxReactLite.observer)(/*#__PURE__*/(0, _react.forwardRef)(_ManageViewPopover));
//# sourceMappingURL=ManageViewPopover.js.map