import { Tab } from '@/models';
import { sanitizeString } from '@/helpers/string.helper';
import { RouteLocation } from 'vue-router';

export const getTabId = (tab: Tab) => tab.id || sanitizeString(tab.name);

export const isTabSelectedByRoute = (
  tab: Tab,
  currentRoute: RouteLocation,
): boolean =>
  tab.routePath
    ? currentRoute.path.includes(tab.routePath)
    : tab.routeName
      ? !!currentRoute.name &&
        (currentRoute.name as string).includes(tab.routeName)
      : false;

export const isTabSelected = (
  tab: Tab,
  selectedTabId: string | null,
): boolean => (tab && tab.id === selectedTabId) || false;
