import { defineStore } from 'pinia';

interface ContextMenuState {
  isOpen: boolean;
  x: number;
  y: number;
  itemId: string | null;
  itemType?: 'icon' | 'widget' | 'folder' | 'desktop';
}

interface UIState {
  contextMenu: ContextMenuState;
  pendingDelete: { id: string; type: 'icon' | 'widget' | 'folder' } | null;
}

export const useUIStore = defineStore('ui', {
  state: (): UIState => ({
    contextMenu: {
      isOpen: false,
      x: 0,
      y: 0,
      itemId: null,
      itemType: 'icon',
    },
    pendingDelete: null,
  }),
  actions: {
    openContextMenu(
      x: number,
      y: number,
      itemId: string | null,
      itemType: 'icon' | 'widget' | 'folder' | 'desktop'
    ) {
      this.contextMenu = {
        isOpen: true,
        x,
        y,
        itemId,
        itemType,
      };
    },
    closeContextMenu() {
      this.contextMenu.isOpen = false;
      this.contextMenu.itemId = null;
    },
    requestDelete(id: string, type: 'icon' | 'widget' | 'folder') {
      this.pendingDelete = { id, type };
    },
    clearPendingDelete() {
      this.pendingDelete = null;
    },
  },
});
