import "core-js/modules/es.symbol.to-primitive.js";
import "core-js/modules/es.date.to-primitive.js";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.number.constructor.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/web.dom-collections.iterator.js";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import * as C from "../../../i18n/constants.mjs";
import { checkSelectionConsistency, markLabelAsSelected } from "../../contextMenu/utils.mjs";
import { META_READONLY } from "../comments.mjs";
/**
 * @param {Comments} plugin The Comments plugin instance.
 * @returns {object}
 */
export default function readOnlyCommentItem(plugin) {
  return {
    key: 'commentsReadOnly',
    name: function name() {
      var label = this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_READ_ONLY_COMMENT);
      var areReadOnly = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
        return plugin.getCommentMeta(row, col, META_READONLY);
      });
      return areReadOnly ? markLabelAsSelected(label) : label;
    },
    callback: function callback() {
      var range = this.getSelectedRangeLast();
      range.forAll(function (row, column) {
        if (row >= 0 && column >= 0) {
          var currentState = !!plugin.getCommentMeta(row, column, META_READONLY);
          plugin.updateCommentMeta(row, column, _defineProperty({}, META_READONLY, !currentState));
        }
      });
    },
    disabled: function disabled() {
      var range = this.getSelectedRangeLast();
      if (!range) {
        return true;
      }
      if (range.highlight.isHeader()) {
        return true;
      }
      if (!plugin.getCommentAtCell(range.highlight.row, range.highlight.col)) {
        return true;
      }
      return this.countRenderedRows() === 0 || this.countRenderedCols() === 0;
    }
  };
}