| import type { TabType, TabVisibilityConfig } from '~/components/@settings/core/types'; |
| import { DEFAULT_TAB_CONFIG } from '~/components/@settings/core/constants'; |
|
|
| export const getVisibleTabs = ( |
| tabConfiguration: { userTabs: TabVisibilityConfig[]; developerTabs?: TabVisibilityConfig[] }, |
| isDeveloperMode: boolean, |
| notificationsEnabled: boolean, |
| ): TabVisibilityConfig[] => { |
| if (!tabConfiguration?.userTabs || !Array.isArray(tabConfiguration.userTabs)) { |
| console.warn('Invalid tab configuration, using defaults'); |
| return DEFAULT_TAB_CONFIG as TabVisibilityConfig[]; |
| } |
|
|
| |
| if (isDeveloperMode) { |
| |
| const allTabs = new Set([ |
| ...DEFAULT_TAB_CONFIG.map((tab) => tab.id), |
| ...tabConfiguration.userTabs.map((tab) => tab.id), |
| ...(tabConfiguration.developerTabs || []).map((tab) => tab.id), |
| 'task-manager' as TabType, |
| ]); |
|
|
| |
| const devTabs = Array.from(allTabs).map((tabId) => { |
| |
| const existingTab = |
| tabConfiguration.developerTabs?.find((t) => t.id === tabId) || |
| tabConfiguration.userTabs?.find((t) => t.id === tabId) || |
| DEFAULT_TAB_CONFIG.find((t) => t.id === tabId); |
|
|
| return { |
| id: tabId as TabType, |
| visible: true, |
| window: 'developer' as const, |
| order: existingTab?.order || DEFAULT_TAB_CONFIG.findIndex((t) => t.id === tabId), |
| } as TabVisibilityConfig; |
| }); |
|
|
| return devTabs.sort((a, b) => a.order - b.order); |
| } |
|
|
| |
| return tabConfiguration.userTabs |
| .filter((tab) => { |
| if (!tab || typeof tab.id !== 'string') { |
| console.warn('Invalid tab entry:', tab); |
| return false; |
| } |
|
|
| |
| if (tab.id === 'notifications' && !notificationsEnabled) { |
| return false; |
| } |
|
|
| |
| if (tab.id === 'task-manager') { |
| return tab.visible; |
| } |
|
|
| |
| return tab.visible && tab.window === 'user'; |
| }) |
| .sort((a, b) => a.order - b.order); |
| }; |
|
|
| export const reorderTabs = ( |
| tabs: TabVisibilityConfig[], |
| startIndex: number, |
| endIndex: number, |
| ): TabVisibilityConfig[] => { |
| const result = Array.from(tabs); |
| const [removed] = result.splice(startIndex, 1); |
| result.splice(endIndex, 0, removed); |
|
|
| |
| return result.map((tab, index) => ({ |
| ...tab, |
| order: index, |
| })); |
| }; |
|
|
| export const resetToDefaultConfig = (isDeveloperMode: boolean): TabVisibilityConfig[] => { |
| return DEFAULT_TAB_CONFIG.map((tab) => ({ |
| ...tab, |
| visible: isDeveloperMode ? true : tab.window === 'user', |
| window: isDeveloperMode ? 'developer' : tab.window, |
| })) as TabVisibilityConfig[]; |
| }; |
|
|