import { GroupElement } from '../../../surface-block/index.js';
import { getElementsFromGroup } from '../../../surface-block/managers/group-manager.js';
import { isConnectable, isNoteBlock } from './query.js';
export function deleteElements(surface, elements) {
    const set = new Set(elements);
    elements.forEach(element => {
        if (isConnectable(element)) {
            const connectors = surface.connector.getConnecttedConnectors([
                element,
            ]);
            connectors.forEach(connector => set.add(connector));
        }
        if (element instanceof GroupElement) {
            getElementsFromGroup(element).forEach(child => {
                set.add(child);
            });
        }
    });
    set.forEach(element => {
        if (isNoteBlock(element)) {
            const children = surface.page.root?.children ?? [];
            // FIXME: should always keep at least 1 note
            if (children.length > 1) {
                surface.page.deleteBlock(element);
            }
        }
        else {
            surface.removeElement(element.id);
        }
    });
}
//# sourceMappingURL=crud.js.map