"use strict";

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

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

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

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

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

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

var _licitDocAttrsStep = require("@modusoperandi/licit-doc-attrs-step");

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

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

var _PointerSurface = _interopRequireWildcard(require("./PointerSurface"));

var _Icon = _interopRequireDefault(require("./Icon"));

var _classnames = _interopRequireDefault(require("classnames"));

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 _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

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);
  }

  render() {
    const _this$props = this.props,
          {
      label,
      hasText
    } = _this$props,
          pointerProps = _objectWithoutProperties(_this$props, ["label", "hasText"]);

    let text = '';
    let customStyle; // [FS] IRAD-1410 2021-06-28
    // The numbering in custom style drop menu not showing properly

    text = ' AaBbCcDd';
    const level = this.sampleLevel(pointerProps.command._customStyle.styles);
    const hasBoldPartial = this.hasBoldPartial(pointerProps.command._customStyle.styles); // [FS] IRAD-1505 2021-07-07
    // Style menu not showing properly for First Word Bold

    const hasBoldSentence = this.hasBoldSentence(pointerProps.command._customStyle.styles); // [FS] IRAD-1394 2021-05-25
    // Added two divs to display Numbering and bold first word/sentece.

    const BOLD_WORD = 'AaBb  ';
    const BOLD_SENTENCE = 'AaBbCc. ';
    const styleProps = (0, _customStyle.getCustomStyleByName)(label);
    const className = 'czi-custom-menu-item';

    if (styleProps && styleProps.styles) {
      customStyle = (0, _customStyle.getCustomStyle)(styleProps.styles);
    }

    const klass = (0, _classnames.default)(className);
    return /*#__PURE__*/React.createElement("div", {
      className: this.props.selectionClassName,
      id: "container1",
      tag: label
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        width: '140px',
        height: 'auto'
      }
    }, /*#__PURE__*/React.createElement(_PointerSurface.default, _extends({}, pointerProps, {
      className: klass,
      style: {
        display: 'inline-block',
        width: '140px'
      }
    }), label)), /*#__PURE__*/React.createElement("div", {
      style: {
        display: level === '' ? 'none' : '',
        // [FS] IRAD-1410 2021-06-02
        // Issue: Number example in custom style menu box not showing properly
        marginTop: '-4px',
        fontWeight: pointerProps.command._customStyle.styles && pointerProps.command._customStyle.styles.boldNumbering ? 'bold' : 'normal'
      }
    }, /*#__PURE__*/React.createElement(_PointerSurface.default, _extends({}, pointerProps, {
      className: klass,
      style: customStyle
    }), level)), /*#__PURE__*/React.createElement("div", {
      style: {
        display: hasBoldPartial ? '' : 'none',
        // [FS] IRAD-1410 2021-06-03
        // Issue: Number example along with Bold first word in custom style menu box not showing properly
        marginTop: '-4px',
        fontWeight: hasBoldPartial ? 'bold' : 'normal'
      }
    }, /*#__PURE__*/React.createElement(_PointerSurface.default, _extends({}, pointerProps, {
      className: klass,
      style: customStyle
    }), hasBoldPartial && hasBoldSentence ? BOLD_SENTENCE : BOLD_WORD)), /*#__PURE__*/React.createElement("div", {
      className: "style-sampletext",
      style: customStyle
    }, /*#__PURE__*/React.createElement(_PointerSurface.default, _extends({}, pointerProps, {
      className: klass,
      style: customStyle
    }), text)), /*#__PURE__*/React.createElement("div", {
      className: "arrow-right",
      style: {
        width: '50px'
      },
      style: hasText ? {
        display: 'block'
      } : {
        display: 'none'
      }
    }, /*#__PURE__*/React.createElement(_PointerSurface.default, _extends({}, pointerProps, {
      className: klass + ' edit-icon'
    }), _Icon.default.get('edit'), '')));
  } // [FS] IRAD-1394 2021-05-25
  // To show Numbering in dropdown menu sample text


  sampleLevel(styles) {
    let level = '';

    if (this.props.hasText && styles && styles.hasNumbering) {
      for (let i = 0; i < parseInt(styles.styleLevel); i++) {
        level = level + '1.';
      }
    }

    return level;
  }

  hasBoldPartial(styles) {
    return styles && styles.boldPartial ? true : false;
  }

  hasBoldSentence(styles) {
    return styles && styles.boldSentence ? true : false;
  }

}

var _default = CustomStyleItem;
exports.default = _default;