/**
 * Selection Slice - 选择状态管理
 */
import { CanvasState } from './types';

export const createSelectionActions = (set: any) => ({
    setSelectedNodeIds: (updater: string[] | ((prev: string[]) => string[])) => set((state: CanvasState) => {
        state.selectedNodeIds = typeof updater === 'function' ? updater(state.selectedNodeIds) : updater;
    }),

    setSelectedGroupId: (updater: string | null | ((prev: string | null) => string | null)) => set((state: CanvasState) => {
        state.selectedGroupId = typeof updater === 'function' ? updater(state.selectedGroupId) : updater;
    }),

    setLastOperationType: (type: 'node-move' | 'node-resize' | 'text-edit' | 'node-add' | 'node-delete' | 'other' | null) => set((state: CanvasState) => {
        state.lastOperationType = type;
    }),

    setScale: (updater: number | ((prev: number) => number)) => set((state: CanvasState) => {
        state.scale = typeof updater === 'function' ? updater(state.scale) : updater;
    }),

    setPan: (updater: { x: number; y: number } | ((prev: { x: number; y: number }) => { x: number; y: number })) => set((state: CanvasState) => {
        state.pan = typeof updater === 'function' ? updater(state.pan) : updater;
    }),
});
