"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var React = _interopRequireWildcard(require("react"));

var _prosemirrorState = require("prosemirror-state");

var _prosemirrorTransform = require("prosemirror-transform");

var _prosemirrorView = require("prosemirror-view");

var _ListToggleCommand = require("../ListToggleCommand");

var _ListTypeButton = _interopRequireDefault(require("./ListTypeButton"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const LIST_TYPE_NAMES = [{
  name: 'decimal',
  label: '1.'
}, {
  name: 'x.x.x',
  label: '1.1.1'
}, {
  name: 'num_bracket',
  label: '1)'
}, {
  name: 'num_bracket_closed',
  label: '(1)'
}, {
  name: 'upper_alpha_bracket',
  label: 'A)'
}, {
  name: 'lower_alpha_bracket',
  label: 'a)'
}, {
  name: 'lower_alpha_bracket_closed',
  label: '(a)'
}];
const LIST_TYPE_COMMANDS = {
  ['decimal']: new _ListToggleCommand.ListToggleCommand(true, 'decimal')
};
LIST_TYPE_NAMES.forEach(obj => {
  LIST_TYPE_COMMANDS[obj.name] = new _ListToggleCommand.ListToggleCommand(true, obj.name);
  LIST_TYPE_COMMANDS[obj.name].label = obj.label;
});
const COMMAND_GROUPS = [LIST_TYPE_COMMANDS];

class ListTypeCommandButton extends React.PureComponent {
  constructor() {
    super(...arguments);

    _defineProperty(this, "props", void 0);
  }

  render() {
    const {
      dispatch,
      editorState,
      editorView
    } = this.props;
    let disabled = false;

    if (editorState && editorView) {
      // [FS] IRAD-1317 2021-05-06
      // To disable the list menu when select an image
      disabled = (0, _ListToggleCommand.hasCustomNumberedList)(editorState) || (0, _ListToggleCommand.hasImageNode)(editorState);
      disabled = editorView.disabled || disabled ? true : false;
    }

    return /*#__PURE__*/React.createElement(_ListTypeButton.default, {
      className: "width-50 czi-icon format_list_numbered",
      commandGroups: COMMAND_GROUPS,
      disabled: disabled,
      dispatch: dispatch,
      editorState: editorState,
      editorView: editorView,
      icon: 'format_list_numbered'
    });
  }

}

var _default = ListTypeCommandButton;
exports.default = _default;