"use strict";

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

require("./czi-custom-button.css");

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

var _UICommand = _interopRequireDefault(require("./UICommand"));

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

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

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

require("./custom-dropdown.css");

var _customStyle = require("../customStyle");

var _findActiveHeading = require("./findActiveHeading");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }

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

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

    _defineProperty(this, "_onUIEnter", (command, event) => {
      this._execute(command, event);
    });

    _defineProperty(this, "_execute", (command, e) => {
      const {
        dispatch,
        editorState,
        editorView,
        onCommand
      } = this.props;
      command.execute(editorState, dispatch, editorView, e);
      onCommand && onCommand();
    });
  }

  render() {
    const {
      command,
      label,
      onClick,
      hasText
    } = this.props;
    let text = '';
    let customStyle;
    text = this.sampleText();
    const style = (0, _customStyle.getCustomStyleByName)(label);

    if (style) {
      customStyle = (0, _findActiveHeading.getCustomStyle)(style);
    }

    return /*#__PURE__*/React.createElement("div", {
      id: "container1",
      tag: label
    }, /*#__PURE__*/React.createElement("div", {
      onClick: e => this._onUIEnter(command, e),
      style: {
        width: '140px',
        height: 'auto'
      }
    }, label), /*#__PURE__*/React.createElement("div", {
      onClick: e => this._onUIEnter(command, e),
      style: {
        width: '100px'
      },
      style: customStyle
    }, " ", text), /*#__PURE__*/React.createElement("div", {
      className: "arrow_right",
      onClick: onClick.bind(this, command),
      style: {
        width: '50px'
      },
      style: hasText ? {
        display: 'block'
      } : {
        display: 'none'
      }
    }, /*#__PURE__*/React.createElement("span", {
      className: "czi-icon keyboard_arrow_down"
    }, "keyboard_arrow_down")));
  }

  // temp method to clear sample text for new and clear command menu item
  sampleText() {
    let text = 'AaBbCcDd';

    if (!this.props.hasText) {
      text = '';
    }

    return text;
  }

}

var _default = CustomStyleItem;
exports.default = _default;