export const reorderElements = <T>(
    collection: T[],
    oldIndex: number,
    newIndex: number,
) => {
    if (newIndex < 0) {
        return [
            ...collection.slice(0, oldIndex),
            ...collection.slice(oldIndex + 1, collection.length),
        ];
    }

    if (oldIndex < newIndex) {
        return [
            ...collection.slice(0, oldIndex),
            ...collection.slice(oldIndex + 1, newIndex + 1),
            ...collection.slice(oldIndex, oldIndex + 1),
            ...collection.slice(newIndex + 1, collection.length),
        ];
    }
    if (oldIndex > newIndex) {
        return [
            ...collection.slice(0, newIndex),
            ...collection.slice(oldIndex, oldIndex + 1),
            ...collection.slice(newIndex, oldIndex),
            ...collection.slice(oldIndex + 1, collection.length),
        ];
    }

    return collection;
};
