import { ReactNode } from 'react';
import { StateCreator } from 'zustand';

export type ReportTabSlice = {
  // State - actions per tab ID
  tabActions: Record<string, ReactNode>;

  // Actions
  setTabActions: (tabId: string, actions: ReactNode) => void;
  clearTabActions: (tabId: string) => void;
  clearAllTabActions: () => void;
};

export const createReportTabSlice: StateCreator<
  ReportTabSlice,
  [],
  [],
  ReportTabSlice
> = (set) => ({
  tabActions: {},

  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: {} }),
});
