import { createSlice, type PayloadAction } from '@reduxjs/toolkit' export interface TabItem { key: string title: string path: string } interface TabsState { items: TabItem[] } const initialState: TabsState = { items: [], } const slice = createSlice({ name: 'tabs', initialState, reducers: { openTab(state, action: PayloadAction) { const exists = state.items.find(t => t.key === action.payload.key) if (!exists) state.items.push(action.payload) }, closeTab(state, action: PayloadAction) { state.items = state.items.filter(t => t.key !== action.payload) }, resetTabs(state) { state.items = [] }, }, }) export const { openTab, closeTab, resetTabs } = slice.actions export default slice.reducer