import { Effect } from 'effect';
export function createEngineSelectionService(state) {
    return {
        subscribe(listener) {
            return Effect.sync(() => {
                state.selectionListeners.add(listener);
                return () => {
                    state.selectionListeners.delete(listener);
                };
            });
        },
        getSelectionState() {
            return Effect.sync(() => state.getSelection());
        },
        setSelection(sheetName, address, options = {}) {
            return Effect.sync(() => {
                const current = state.getSelection();
                const nextSelection = {
                    sheetName,
                    address,
                    anchorAddress: options.anchorAddress ?? address,
                    range: options.range ?? (address ? { startAddress: address, endAddress: address } : null),
                    editMode: options.editMode ?? current.editMode,
                };
                if (current.sheetName === nextSelection.sheetName &&
                    current.address === nextSelection.address &&
                    current.anchorAddress === nextSelection.anchorAddress &&
                    current.editMode === nextSelection.editMode &&
                    current.range?.startAddress === nextSelection.range?.startAddress &&
                    current.range?.endAddress === nextSelection.range?.endAddress) {
                    return false;
                }
                state.setSelection(nextSelection);
                state.selectionListeners.forEach((listener) => listener());
                return true;
            });
        },
    };
}
//# sourceMappingURL=selection-service.js.map