"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getMenuDescibitionFromType = getMenuDescibitionFromType;
exports.handleClickToolMenu = handleClickToolMenu;
exports.headingIsActive = headingIsActive;
exports.markActive = markActive;
exports.orderedListIsActive = orderedListIsActive;

var _prosemirrorCommands = require("prosemirror-commands");

var _schemas = _interopRequireDefault(require("../schemas"));

var _commands = require("./commands");

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

function getMenuDescibitionFromType(type) {
  switch (type) {
    case 'h1':
      return {
        title: '一级标题',
        icon: 'tu-icon-text-H1'
      };

    case 'h2':
      return {
        title: '二级标题',
        icon: 'tu-icon-text-H2'
      };

    case 'h3':
      return {
        title: '三级标题',
        icon: 'tu-icon-text-H3'
      };

    case 'strong':
      return {
        title: '加粗',
        icon: 'tu-icon-text-blod'
      };

    case 'color':
      return {
        title: '文字颜色',
        icon: 'tu-icon-text-color'
      };

    case 'underLine':
      return {
        title: '下划线',
        icon: 'tu-icon-text-underline'
      };

    case 'deleteLine':
      return {
        title: '删除线',
        icon: 'tu-icon-text-delline'
      };

    case 'orderList':
      return {
        title: '有序列表',
        icon: 'tu-icon-text-number-list'
      };

    case 'unOrderList':
      return {
        title: '无序列表',
        icon: 'tu-icon-text-bullet-list'
      };

    case 'left':
      return {
        title: '左对齐',
        icon: 'tu-icon-text-left'
      };

    case 'center':
      return {
        title: '居中对齐',
        icon: 'tu-icon-text-center'
      };

    case 'right':
      return {
        title: '右对齐',
        icon: 'tu-icon-text-right'
      };

    case 'task':
      return {
        title: '任务',
        icon: 'tu-icon-text-task'
      };

    case 'checkList':
      return {
        title: '清单',
        icon: 'tu-icon-text-box'
      };

    case 'table':
      return {
        title: '表格',
        icon: 'tu-icon-text-table'
      };

    case 'image':
      return {
        title: '图片/视频',
        icon: 'tu-icon-text-photo'
      };

    case 'quote':
      return {
        title: '引用',
        icon: 'tu-icon-text-quotel'
      };

    case 'link':
      return {
        title: '链接',
        icon: 'tu-icon-text-link'
      };

    case 'at':
      return {
        title: '@人',
        icon: 'tu-icon-text-man'
      };

    default:
      return {
        title: '',
        icon: ''
      };
  }
}

function handleClickToolMenu(state, dispatchTransiction, type) {
  switch (type) {
    case 'h1':
      return (0, _commands.setHeadLine)(state, dispatchTransiction, 1);

    case 'h2':
      return (0, _commands.setHeadLine)(state, dispatchTransiction, 2);

    case 'h3':
      return (0, _commands.setHeadLine)(state, dispatchTransiction, 3);

    case 'strong':
      return (0, _prosemirrorCommands.toggleMark)(_schemas["default"].marks.strong)(state, dispatchTransiction);

    case 'color':
      return;

    case 'underLine':
      return (0, _prosemirrorCommands.toggleMark)(_schemas["default"].marks.underLine)(state, dispatchTransiction);

    case 'deleteLine':
      return (0, _prosemirrorCommands.toggleMark)(_schemas["default"].marks.deleteLine)(state, dispatchTransiction);

    case 'orderList':
      return (0, _commands.toggleList)(state, dispatchTransiction, _schemas["default"].nodes.ordered_list);

    case 'unOrderList':
      return (0, _commands.toggleList)(state, dispatchTransiction, _schemas["default"].nodes.bullet_list);

    case 'left':
    case 'center':
    case 'right':
      return (0, _commands.setAlignment)(state, dispatchTransiction, type);

    case 'task':
      return;

    case 'checkList':
      return;

    case 'table':
      return;

    case 'image':
      return;

    case 'quote':
      return;

    case 'link':
      return;

    case 'at':
      return;

    default:
      return;
  }

  return;
}

function headingIsActive(state, level) {
  var $from = state.selection.$from;
  var node = $from.node();
  return node.type === _schemas["default"].nodes.heading && node.attrs.level === level;
}

function markActive(state, type) {
  var _state$selection = state.selection,
      from = _state$selection.from,
      $from = _state$selection.$from,
      to = _state$selection.to,
      empty = _state$selection.empty;
  if (empty) return type.isInSet(state.storedMarks || $from.marks());else return state.doc.rangeHasMark(from, to, type);
}

function orderedListIsActive(state) {// const { $from,ranges } = state.selection;
  // const node = $from.node();
  // for(let range of ranges) {
  //   state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
  //     // console.log(node)
  //   })
  // }
}