function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { AlignCenterOutlined, AlignLeftOutlined, AlignRightOutlined, BoldOutlined, ItalicOutlined, StrikethroughOutlined } from "@ant-design/icons";
import React, { useContext } from "react";
import { Editor, Element } from "slate";
import { I18nContext } from "../../../../../I18n";
import { EditorUtils } from "../../../utils/editorUtils";
var LineCode = /*#__PURE__*/ React.memo(function() {
    return /*#__PURE__*/ React.createElement("svg", {
        viewBox: "0 0 1024 1024",
        version: "1.1",
        width: "1.3em",
        height: "1.3em"
    }, /*#__PURE__*/ React.createElement("path", {
        fill: "currentColor",
        d: "M153.770667 517.558857l200.387047-197.241905L302.86019 268.190476 48.761905 518.290286l254.439619 243.614476 50.590476-52.833524-200.021333-191.512381zM658.285714 320.316952L709.583238 268.190476l254.098286 250.09981L709.241905 761.904762l-50.590476-52.833524 200.021333-191.512381L658.285714 320.316952z m-112.981333-86.186666L393.99619 785.554286l70.534096 19.358476 151.30819-551.399619-70.534095-19.358476z"
    }));
});
LineCode.displayName = 'LineCode';
export var isCodeNode = function isCodeNode(editor) {
    if (!editor) return false;
    var _Editor_nodes = _sliced_to_array(Editor.nodes(editor, {
        match: function match(n) {
            return Element.isElement(n);
        },
        mode: 'lowest'
    }), 1), node = _Editor_nodes[0];
    return node && node[0].type === 'code';
};
export var useToolsConfig = function useToolsConfig() {
    var locale = useContext(I18nContext).locale;
    return [
        {
            key: 'bold',
            type: 'bold',
            title: (locale === null || locale === void 0 ? void 0 : locale['toolbar.bold']) || '加粗',
            icon: /*#__PURE__*/ React.createElement(BoldOutlined, null)
        },
        {
            key: 'italic',
            title: (locale === null || locale === void 0 ? void 0 : locale['toolbar.italic']) || '斜体',
            type: 'italic',
            icon: /*#__PURE__*/ React.createElement(ItalicOutlined, null)
        },
        {
            key: 'strikethrough',
            title: (locale === null || locale === void 0 ? void 0 : locale['toolbar.strikethrough']) || '删除线',
            type: 'strikethrough',
            icon: /*#__PURE__*/ React.createElement(StrikethroughOutlined, null)
        },
        {
            key: 'inline-code',
            title: (locale === null || locale === void 0 ? void 0 : locale['toolbar.inlineCode']) || '行内代码',
            type: 'code',
            icon: /*#__PURE__*/ React.createElement(LineCode, null)
        },
        {
            key: 'align-left',
            title: (locale === null || locale === void 0 ? void 0 : locale['toolbar.alignLeft']) || '左对齐',
            type: 'align-left',
            icon: /*#__PURE__*/ React.createElement(AlignLeftOutlined, null),
            onClick: function onClick(editor) {
                if (!isCodeNode(editor)) {
                    EditorUtils.setAlignment(editor, 'left');
                }
            },
            isActive: function isActive(editor) {
                var _EditorUtils_isAlignmentActive;
                return EditorUtils === null || EditorUtils === void 0 ? void 0 : (_EditorUtils_isAlignmentActive = EditorUtils.isAlignmentActive) === null || _EditorUtils_isAlignmentActive === void 0 ? void 0 : _EditorUtils_isAlignmentActive.call(EditorUtils, editor, 'left');
            }
        },
        {
            key: 'align-center',
            title: (locale === null || locale === void 0 ? void 0 : locale['toolbar.alignCenter']) || '居中对齐',
            type: 'align-center',
            icon: /*#__PURE__*/ React.createElement(AlignCenterOutlined, null),
            onClick: function onClick(editor) {
                if (!isCodeNode(editor)) {
                    EditorUtils.setAlignment(editor, 'center');
                }
            },
            isActive: function isActive(editor) {
                var _EditorUtils_isAlignmentActive;
                return EditorUtils === null || EditorUtils === void 0 ? void 0 : (_EditorUtils_isAlignmentActive = EditorUtils.isAlignmentActive) === null || _EditorUtils_isAlignmentActive === void 0 ? void 0 : _EditorUtils_isAlignmentActive.call(EditorUtils, editor, 'center');
            }
        },
        {
            key: 'align-right',
            title: (locale === null || locale === void 0 ? void 0 : locale['toolbar.alignRight']) || '右对齐',
            type: 'align-right',
            icon: /*#__PURE__*/ React.createElement(AlignRightOutlined, null),
            onClick: function onClick(editor) {
                if (!isCodeNode(editor)) {
                    EditorUtils.setAlignment(editor, 'right');
                }
            },
            isActive: function isActive(editor) {
                var _EditorUtils_isAlignmentActive;
                return EditorUtils === null || EditorUtils === void 0 ? void 0 : (_EditorUtils_isAlignmentActive = EditorUtils.isAlignmentActive) === null || _EditorUtils_isAlignmentActive === void 0 ? void 0 : _EditorUtils_isAlignmentActive.call(EditorUtils, editor, 'right');
            }
        }
    ];
};
