"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    GroupModificationType: ()=>GroupModificationType,
    createGroupModificationHandlers: ()=>createGroupModificationHandlers,
    getHandlerForModificationType: ()=>getHandlerForModificationType,
    mergeGroupDown: ()=>mergeGroupDown,
    mergeGroupUp: ()=>mergeGroupUp,
    moveGroupDown: ()=>moveGroupDown,
    moveGroupUp: ()=>moveGroupUp,
    removeGroup: ()=>removeGroup,
    removeTask: ()=>removeTask,
    splitGroup: ()=>splitGroup,
    ungroupAllTasks: ()=>ungroupAllTasks
});
let GroupModificationType = /*#__PURE__*/ function(GroupModificationType) {
    GroupModificationType["TASK_GROUP_UP"] = "task_group_up";
    GroupModificationType["TASK_GROUP_DOWN"] = "task_group_down";
    GroupModificationType["UNGROUP_ALL_TASKS"] = "ungroup_all_tasks";
    GroupModificationType["SPLIT_GROUP"] = "split_group";
    GroupModificationType["MERGE_GROUP_UP"] = "merge_group_up";
    GroupModificationType["MERGE_GROUP_DOWN"] = "merge_group_down";
    GroupModificationType["REMOVE_TASK"] = "remove_task";
    GroupModificationType["REMOVE_GROUP"] = "remove_group";
    return GroupModificationType;
}({});
function moveGroupUp(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length || 0 === groupIndex) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    const updatedTasks = [
        ...tasks
    ];
    const prevGroup = updatedTasks[groupIndex - 1];
    const currentGroupItem = updatedTasks[groupIndex];
    if (prevGroup && currentGroupItem) {
        updatedTasks[groupIndex - 1] = currentGroupItem;
        updatedTasks[groupIndex] = prevGroup;
    }
    return updatedTasks;
}
function moveGroupDown(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length || groupIndex >= tasks.length - 1) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    const updatedTasks = [
        ...tasks
    ];
    const currentGroupItem = updatedTasks[groupIndex];
    const nextGroup = updatedTasks[groupIndex + 1];
    if (currentGroupItem && nextGroup) {
        updatedTasks[groupIndex] = nextGroup;
        updatedTasks[groupIndex + 1] = currentGroupItem;
    }
    return updatedTasks;
}
function ungroupAllTasks(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    if (currentGroup.length > 1) {
        const updatedTasks = [
            ...tasks
        ];
        const ungroupedTasks = currentGroup.map((t)=>[
                t
            ]);
        updatedTasks.splice(groupIndex, 1, ...ungroupedTasks);
        return updatedTasks;
    }
    return tasks;
}
function splitGroup(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    const task = currentGroup[taskIndex];
    if (!task) return tasks;
    if (currentGroup.length > 1) {
        const updatedTasks = [
            ...tasks
        ];
        const remainingTasks = currentGroup.filter((_, idx)=>idx !== taskIndex);
        const splitTask = [
            task
        ];
        if (remainingTasks.length > 0) {
            updatedTasks[groupIndex] = remainingTasks;
            updatedTasks.splice(groupIndex + 1, 0, splitTask);
        } else updatedTasks[groupIndex] = splitTask;
        return updatedTasks;
    }
    return tasks;
}
function mergeGroupUp(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length || 0 === groupIndex) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    const task = currentGroup[taskIndex];
    if (!task) return tasks;
    const updatedTasks = [
        ...tasks
    ];
    const aboveGroup = updatedTasks[groupIndex - 1];
    const currentGroupWithoutTask = currentGroup.filter((_, idx)=>idx !== taskIndex);
    if (aboveGroup) {
        updatedTasks[groupIndex - 1] = [
            ...aboveGroup,
            task
        ];
        if (currentGroupWithoutTask.length > 0) updatedTasks[groupIndex] = currentGroupWithoutTask;
        else updatedTasks.splice(groupIndex, 1);
    }
    return updatedTasks;
}
function mergeGroupDown(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length || groupIndex >= tasks.length - 1) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    const task = currentGroup[taskIndex];
    if (!task) return tasks;
    const updatedTasks = [
        ...tasks
    ];
    const belowGroup = updatedTasks[groupIndex + 1];
    const currentGroupWithoutTask = currentGroup.filter((_, idx)=>idx !== taskIndex);
    if (belowGroup) {
        updatedTasks[groupIndex + 1] = [
            task,
            ...belowGroup
        ];
        if (currentGroupWithoutTask.length > 0) updatedTasks[groupIndex] = currentGroupWithoutTask;
        else updatedTasks.splice(groupIndex, 1);
    }
    return updatedTasks;
}
function removeTask(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    const updatedTasks = [
        ...tasks
    ];
    const groupWithoutTask = currentGroup.filter((_, idx)=>idx !== taskIndex);
    if (groupWithoutTask.length > 0) updatedTasks[groupIndex] = groupWithoutTask;
    else updatedTasks.splice(groupIndex, 1);
    return updatedTasks;
}
function removeGroup(tasks, groupIndex, taskIndex) {
    if (groupIndex < 0 || groupIndex >= tasks.length) return tasks;
    const currentGroup = tasks[groupIndex];
    if (!currentGroup || taskIndex < 0 || taskIndex >= currentGroup.length) return tasks;
    const updatedTasks = [
        ...tasks
    ];
    updatedTasks.splice(groupIndex, 1);
    return updatedTasks;
}
function createGroupModificationHandlers() {
    return {
        moveGroupUp: (tasks, groupIndex, taskIndex)=>moveGroupUp(tasks, groupIndex, taskIndex),
        moveGroupDown: (tasks, groupIndex, taskIndex)=>moveGroupDown(tasks, groupIndex, taskIndex),
        ungroupAll: (tasks, groupIndex, taskIndex)=>ungroupAllTasks(tasks, groupIndex, taskIndex),
        splitGroup: (tasks, groupIndex, taskIndex)=>splitGroup(tasks, groupIndex, taskIndex),
        mergeGroupUp: (tasks, groupIndex, taskIndex)=>mergeGroupUp(tasks, groupIndex, taskIndex),
        mergeGroupDown: (tasks, groupIndex, taskIndex)=>mergeGroupDown(tasks, groupIndex, taskIndex),
        removeTask: (tasks, groupIndex, taskIndex)=>removeTask(tasks, groupIndex, taskIndex),
        removeGroup: (tasks, groupIndex, taskIndex)=>removeGroup(tasks, groupIndex, taskIndex)
    };
}
function getHandlerForModificationType(handlers, type) {
    switch(type){
        case GroupModificationType.TASK_GROUP_UP:
            return handlers.moveGroupUp;
        case GroupModificationType.TASK_GROUP_DOWN:
            return handlers.moveGroupDown;
        case GroupModificationType.UNGROUP_ALL_TASKS:
            return handlers.ungroupAll;
        case GroupModificationType.SPLIT_GROUP:
            return handlers.splitGroup;
        case GroupModificationType.MERGE_GROUP_UP:
            return handlers.mergeGroupUp;
        case GroupModificationType.MERGE_GROUP_DOWN:
            return handlers.mergeGroupDown;
        case GroupModificationType.REMOVE_TASK:
            return handlers.removeTask;
        case GroupModificationType.REMOVE_GROUP:
            return handlers.removeGroup;
        default:
            {
                const _exhaustive = type;
                throw new Error(`Unknown GroupModificationType: ${_exhaustive}`);
            }
    }
}
exports.GroupModificationType = __webpack_exports__.GroupModificationType;
exports.createGroupModificationHandlers = __webpack_exports__.createGroupModificationHandlers;
exports.getHandlerForModificationType = __webpack_exports__.getHandlerForModificationType;
exports.mergeGroupDown = __webpack_exports__.mergeGroupDown;
exports.mergeGroupUp = __webpack_exports__.mergeGroupUp;
exports.moveGroupDown = __webpack_exports__.moveGroupDown;
exports.moveGroupUp = __webpack_exports__.moveGroupUp;
exports.removeGroup = __webpack_exports__.removeGroup;
exports.removeTask = __webpack_exports__.removeTask;
exports.splitGroup = __webpack_exports__.splitGroup;
exports.ungroupAllTasks = __webpack_exports__.ungroupAllTasks;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "GroupModificationType",
    "createGroupModificationHandlers",
    "getHandlerForModificationType",
    "mergeGroupDown",
    "mergeGroupUp",
    "moveGroupDown",
    "moveGroupUp",
    "removeGroup",
    "removeTask",
    "splitGroup",
    "ungroupAllTasks"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
