import type { StateCreator } from "zustand";
import type { EditorState } from "./use-lesson-plan-editor";

export interface SelectionSlice {
  /** 当前在右栏详情面板显示的节点 ID */
  selectedNodeId: string | null;
  /** 纸上选中文本时，待锚定的目标节点 ID（用户从右键菜单选择节点后设置） */
  anchorNodeForSelection: string | null;
  selectNode: (id: string | null) => void;
  setAnchorNodeForSelection: (id: string | null) => void;
}

export const createSelectionSlice: StateCreator<
  EditorState,
  [],
  [],
  SelectionSlice
> = (set) => ({
  selectedNodeId: null,
  anchorNodeForSelection: null,
  selectNode: (id) => set({ selectedNodeId: id }),
  setAnchorNodeForSelection: (id) => set({ anchorNodeForSelection: id }),
});
