"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ManageFieldsPopoverMenu = void 0;
var _designSystem = require("@wix/design-system");
var _react = _interopRequireDefault(require("react"));
var _react2 = require("@wix/bex-core/react");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _bexCore = require("@wix/bex-core");
var _bi = require("@wix/bex-core/bi");
var _mobxReactLite = require("mobx-react-lite");
var _CustomFields = require("../CustomFields");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomFieldsPanel/ManageFieldsPopoverMenu.tsx";
function _ManageFieldsPopoverMenu({
  state,
  id,
  origin,
  location
}) {
  const container = (0, _react2.useWixPatternsContainer)();
  const {
    translate: t
  } = container;
  if (!state.dataExtension.hasWritePermissions) {
    return /*#__PURE__*/_react.default.createElement(_CustomFields.CustomFieldsDisabledTooltip, {
      disabled: !state.dataExtension.hasWritePermissions,
      content: t('cairo.customFields.writePermission.tooltip'),
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 29,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.IconButton, {
      size: "tiny",
      dataHook: "custom-field-options-icon-button",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 33,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.MoreSmall, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 34,
        columnNumber: 11
      }
    })));
  }
  const reportCtaClickedBi = ({
    ctaIndex,
    ctaName,
    moreActionsIndex
  }) => {
    state == null || state.reportBi((0, _bexCore.withoutDefaults)(_bi.cairoCtaClicked)({
      ctaIndex,
      ctaName,
      filteredListSize: state == null ? void 0 : state.dataExtension.availableUserCustomFields.length,
      isSelectAll: false,
      location,
      moreActionsIndex,
      numCtas: 2,
      numItems: 1,
      url: typeof window !== 'undefined' ? window.location.href : ''
    }));
  };
  const onTriggerMenu = () => {
    reportCtaClickedBi({
      ctaIndex: 0,
      ctaName: 'More Actions Menu'
    });
  };
  return /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu, {
    textSize: "small",
    placement: "bottom-end",
    dataHook: "custom-field-options",
    onShow: onTriggerMenu,
    triggerElement: /*#__PURE__*/_react.default.createElement(_designSystem.Tooltip, {
      content: t('cairo.custom-columns.more-actions.tooltip'),
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 78,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.IconButton, {
      size: "tiny",
      dataHook: "custom-field-options-icon-button",
      skin: "light",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 79,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.MoreSmall, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 84,
        columnNumber: 13
      }
    }))),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 72,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, {
    dataHook: "custom-field-options-edit",
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.EditSmall, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 91,
        columnNumber: 21
      }
    }),
    text: t('cairo.customFields.edit.CTA'),
    onClick: () => {
      reportCtaClickedBi({
        ctaIndex: 1,
        ctaName: 'Edit',
        moreActionsIndex: 1
      });
      state.openCustomFieldModal({
        fieldId: id,
        origin
      });
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 89,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.PopoverMenu.MenuItem, {
    dataHook: "custom-field-options-archive",
    prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.ArchiveSmall, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 108,
        columnNumber: 21
      }
    }),
    text: t('cairo.customFields.archive.CTA'),
    onClick: () => {
      reportCtaClickedBi({
        ctaIndex: 2,
        ctaName: 'Archive',
        moreActionsIndex: 2
      });
      state.archiveFieldModal.modal.open({
        id,
        origin
      });
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 106,
      columnNumber: 7
    }
  }));
}
const ManageFieldsPopoverMenu = exports.ManageFieldsPopoverMenu = (0, _mobxReactLite.observer)(_ManageFieldsPopoverMenu);
//# sourceMappingURL=ManageFieldsPopoverMenu.js.map