import { TabActionsSlice } from '@/stores/tab-actions/tab-actions.store';
import { StateCreator } from 'zustand';

export const createTabActionsSlice: StateCreator<
  TabActionsSlice,
  [],
  [],
  TabActionsSlice
> = (set) => ({
  // Initial state
  tabActions: {},

  // Actions
  setTabActions: (tabId, actions) =>
    set((state) => ({
      tabActions: {
        ...state.tabActions,
        [tabId]: actions,
      },
    })),

  clearTabActions: (tabId) =>
    set((state) => {
      const { [tabId]: _, ...rest } = state.tabActions;
      return { tabActions: rest };
    }),

  clearAllTabActions: () => set({ tabActions: {} }),
});
