"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseStyleColorValue = exports.validateClassNameColorName = exports.chainAND = exports.chainOR = void 0;
const const_1 = require("./const.js");
var prosemirror_commands_1 = require("prosemirror-commands");
Object.defineProperty(exports, "chainOR", { enumerable: true, get: function () { return prosemirror_commands_1.chainCommands; } });
/**
 * @unsafe
 *
 * Combine a number of command functions into a single function
 * (which calls them one by one until one returns false).
 * If all commands are executed successfully, the changes are applied in a single transaction.
 * If at least one command fails, no changes are applied.
 */
const chainAND = (...commands) => {
    return (state, dispatch, view) => {
        let tr = state.tr;
        for (const cmd of commands) {
            if (!cmd(
            // @ts-expect-error – missing the following properties: apply, applyTransaction, reconfigure, toJSON
            // @d3m1d0v: probably these props should not be used inside commands
            // TODO: think about way of chaining commads fithout such hacks
            { ...state, ...tr, tr }, dispatch
                ? // eslint-disable-next-line @typescript-eslint/no-loop-func
                    (newTr) => {
                        tr = newTr;
                    }
                : undefined, view)) {
                return false;
            }
        }
        dispatch?.(tr);
        return true;
    };
};
exports.chainAND = chainAND;
// see styles
const COLORS = [
    const_1.Colors.Gray,
    const_1.Colors.Yellow,
    const_1.Colors.Orange,
    const_1.Colors.Red,
    const_1.Colors.Green,
    const_1.Colors.Blue,
    const_1.Colors.Violet,
];
const validateClassNameColorName = (color) => COLORS.includes(color);
exports.validateClassNameColorName = validateClassNameColorName;
// eslint-disable-next-line complexity
const parseStyleColorValue = (color) => {
    switch (color) {
        case 'gray':
        case 'grey':
        case 'lightgray':
        case 'lightgrey':
        case 'darkgray':
        case 'darkgrey':
            return const_1.Colors.Gray;
        case 'yellow':
        case 'lightyellow':
            return const_1.Colors.Yellow;
        case 'orange':
        case 'darkorange':
            return const_1.Colors.Orange;
        case 'red':
        case 'darkred':
            return const_1.Colors.Red;
        case 'green':
        case 'lightgreen':
        case 'darkgreen':
            return const_1.Colors.Green;
        case 'blue':
        case 'lightblue':
        case 'mediumblue':
        case 'darkblue':
            return const_1.Colors.Blue;
        case 'violet':
        case 'darkviolet':
        case 'purple':
        case 'mediumpurple':
            return const_1.Colors.Violet;
        default:
            return null;
    }
};
exports.parseStyleColorValue = parseStyleColorValue;
//# sourceMappingURL=utils.js.map
