import { Effect } from 'effect';
export function createEngineEventService(state) {
    return {
        subscribe(listener) {
            return Effect.sync(() => state.events.subscribe(listener));
        },
        subscribeCell(sheetName, address, listener) {
            return Effect.sync(() => {
                const cellIndex = state.workbook.getCellIndex(sheetName, address);
                if (cellIndex !== undefined) {
                    return state.events.subscribeCellIndex(cellIndex, listener);
                }
                return state.events.subscribeCellAddress(`${sheetName}!${address}`, listener);
            });
        },
        subscribeCells(sheetName, addresses, listener) {
            return Effect.sync(() => {
                const cellIndices = [];
                const qualifiedAddresses = [];
                addresses.forEach((address) => {
                    const cellIndex = state.workbook.getCellIndex(sheetName, address);
                    if (cellIndex !== undefined) {
                        cellIndices.push(cellIndex);
                        return;
                    }
                    qualifiedAddresses.push(`${sheetName}!${address}`);
                });
                return state.events.subscribeCells(cellIndices, qualifiedAddresses, listener);
            });
        },
        subscribeBatches(listener) {
            return Effect.sync(() => {
                state.batchListeners.add(listener);
                return () => {
                    state.batchListeners.delete(listener);
                };
            });
        },
    };
}
//# sourceMappingURL=event-service.js.map