"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
class PiActionsUtil {
    static join(defaultActions, newActions) {
        newActions.forEach(newA => this.remove(defaultActions, newA));
        return lodash_1.union(defaultActions, newActions);
    }
    static remove(from, item) {
        lodash_1.remove(from, (value, index, collection) => this.equalsTrigger(value.trigger, item.trigger));
    }
    static equalsTrigger(trigger1, trigger2) {
        let type1 = typeof trigger1;
        let type2 = typeof trigger2;
        if (type1 === type2) {
            if (type1 === "string") {
                return trigger1 === trigger2;
            }
            else if (type1 === "object") {
                type1 = trigger1["meta"] === undefined ? "PiKey" : "RegExp";
                type2 = trigger2["meta"] === undefined ? "PiKey" : "RegExp";
                if (type1 === type2) {
                    if (type1 === "PiKey") {
                        const key1 = trigger1;
                        const key2 = trigger2;
                        return key1.meta === key2.meta && key1.keyCode === key2.keyCode;
                    }
                    else {
                        const regexp1 = trigger1;
                        const regexp2 = trigger2;
                        return regexp1.source === regexp2.source;
                    }
                }
            }
        }
        return false;
    }
}
exports.PiActionsUtil = PiActionsUtil;
//# sourceMappingURL=PiActionsUtil.js.map