import {browserHistory} from 'react-router'

export default function make_tabs_with_routes(tabs, root, current_path) {
  return tabs.map(({label, route}) => {
    const path = `${root}${route ? '/' : ''}${route}`
    return {
      label,
      onClick: () => browserHistory.push(path),
      active: is_active(path, route, current_path),
    }
  })
}

export function is_active(path, route, current_path) {
  return (new RegExp(`${path}${route ? "(/\\w\+)\*" : ""}/\?\$`)).test(current_path)
}
