import { create } from "zustand"

export interface SelectedObjectEditTarget {
  imageId: string
  operationId: string
  objectId: number
  objectType: string
}

interface KeyboardStore {
  ctrl: boolean
  setCtrl: (v: boolean) => void
  shift: boolean
  setShift: (v: boolean) => void
  drawAction: "none" | "add" | "subtract"
  setDrawAction: (mode: "none" | "add" | "subtract") => void
  selectedObjectEditTarget: SelectedObjectEditTarget | null
  setSelectedObjectEditTarget: (target: SelectedObjectEditTarget | null) => void
  copyDataIds: number[] // ctrl + c 复制数据
  setCopyDataIds: (ids: number[]) => void
}

export const useKeyboardStore = create<KeyboardStore>((set) => ({
  ctrl: false,
  shift: false,
  drawAction: "none",
  selectedObjectEditTarget: null,
  copyDataIds: [],
  setCtrl: (v) => set((state) => ({ ...state, ctrl: v })),
  setShift: (v) => set((state) => ({ ...state, shift: v })),
  setDrawAction: (mode) => set((state) => ({ ...state, drawAction: mode })),
  setSelectedObjectEditTarget: (target) =>
    set((state) => ({ ...state, selectedObjectEditTarget: target })),
  setCopyDataIds: (ids) => set((state) => ({ ...state, copyDataIds: ids })),
}))
