import qs from 'qs';

import { TabObject } from 'src/components/tabs/Tabs';

export const getPath = (pathname: string, routeParam: string): string => {
  const params = { [routeParam]: true };
  const path = `${pathname}?${qs.stringify(params)}`;

  return path;
};

export const findTabIndexByParam = (
  tabs: TabObject[],
  search: string,
): number => {
  const params = qs.parse(search, { ignoreQueryPrefix: true });
  const param = Object.keys(params)[0];

  return tabs.findIndex(tab => tab.routeParam === param);
};
