import { groupBy } from '../../../_common/utils/iterable.js';
import {} from '../../../surface-block/index.js';
import { getElementsWithoutGroup } from '../../../surface-block/managers/group-manager.js';
import { getCopyElements, prepareClipboardData, } from '../controllers/clipboard.js';
import { edgelessElementsBound } from './bound-utils.js';
import { isFrameBlock, isImageBlock, isNoteBlock } from './query.js';
const offset = 10;
export async function duplicate(edgeless, elements, select = true) {
    const { clipboardController } = edgeless;
    const copyElements = getCopyElements(edgeless.surface, elements);
    const totalBound = edgelessElementsBound(copyElements);
    totalBound.x += totalBound.w + offset;
    const data = JSON.parse(JSON.stringify(await prepareClipboardData(copyElements, edgeless.std)));
    const [canvasElements, blocks] = await clipboardController.createElementsFromClipboardData(data, totalBound.center);
    const newElements = [...canvasElements, ...blocks];
    edgeless.surface.fitToViewport(totalBound);
    if (select) {
        edgeless.selectionManager.set({
            elements: newElements.map(e => e.id),
            editing: false,
        });
    }
}
export const splitElements = (elements) => {
    const { notes, frames, shapes, images } = groupBy(getElementsWithoutGroup(elements), element => {
        if (isNoteBlock(element)) {
            return 'notes';
        }
        else if (isFrameBlock(element)) {
            return 'frames';
        }
        else if (isImageBlock(element)) {
            return 'images';
        }
        return 'shapes';
    });
    return {
        notes: notes ?? [],
        shapes: shapes ?? [],
        frames: frames ?? [],
        images: images ?? [],
    };
};
//# sourceMappingURL=clipboard-utils.js.map