import _union from '../../utils/union';
export default function correctMark(markList, rootInfoMap, disabled, isInit) {
    if (markList === void 0) { markList = []; }
    if (disabled === void 0) { disabled = []; }
    var nextMarkList = [];
    var markMap = {};
    markList.forEach(function (rootId) {
        if (!rootInfoMap[rootId]) {
            return;
        }
        var rootIncludes = isInit
            ? rootInfoMap[rootId].rootIncludeIds
            : rootInfoMap[rootId].rootIncludeIds.filter(function (id) {
                return disabled.indexOf(id) === -1;
            });
        nextMarkList.push.apply(nextMarkList, rootIncludes);
        markMap[rootId] = true;
    });
    markList.forEach(function (item) {
        if (!rootInfoMap[item]) {
            return;
        }
        var markParentId = rootInfoMap[item].parentId;
        while (markParentId) {
            if (markMap[markParentId]) {
                markParentId = undefined;
            }
            else {
                if (rootInfoMap[markParentId].son.every(function (id) { return markMap[id] || disabled.indexOf(id) > -1; })) {
                    markMap[markParentId] = true;
                    markParentId = rootInfoMap[markParentId].parentId;
                }
                else {
                    markParentId = undefined;
                }
            }
        }
    });
    return _union(Object.keys(markMap).map(function (id) { return rootInfoMap[id].id; }), nextMarkList);
}
