{"size": 1391, "ext": "js", "max_stars_repo_path": "client/src/hooks/useRouting.js", "max_stars_repo_name": "ronituohino/recom", "max_stars_repo_stars_event_min_datetime": "2021-12-05T11:44:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-05T11:44:04.000Z", "max_issues_repo_path": "client/src/hooks/useRouting.js", "max_issues_repo_name": "ronituohino/react-online-store", "max_issues_repo_issues_event_min_datetime": "2022-03-08T13:41:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T13:01:53.000Z", "max_forks_repo_path": "client/src/hooks/useRouting.js", "max_forks_repo_name": "ronituohino/react-online-store", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 19.0547945205, "max_line_length": 72, "alphanum_fraction": 0.6046010065}
import { useNavigate, useLocation } from "react-router-dom"
import { useLanguage } from "./useLanguage"

export const useRouting = () => {
  const navigate = useNavigate()
  const { language } = useLanguage()
  const location = useLocation()

  const openLink = (link) => {
    navigate(link)
  }

  const back = () => {
    navigate(-1)
  }

  const inCheckout = () => {
    return location.pathname.includes("checkout")
  }

  const homeLink = () => {
    return `/${language}/home`
  }

  const accountLink = () => {
    return `/${language}/account`
  }

  const accountSettingsLink = () => {
    return `/${language}/account/settings`
  }

  const accountOrdersLink = () => {
    return `/${language}/account/orders`
  }

  const categoryLink = (category) => {
    return `/${language}/product/${category}`
  }

  const productLink = (category, productId) => {
    return `/${language}/product/${category.toLowerCase()}/${productId}`
  }

  const checkoutLink = () => {
    return `/${language}/checkout/`
  }

  const loginLink = () => {
    return `/${language}/account/login`
  }

  const registerLink = () => {
    return `/${language}/account/register`
  }

  return {
    openLink,
    back,
    inCheckout,

    homeLink,
    accountLink,
    accountSettingsLink,
    accountOrdersLink,
    categoryLink,
    productLink,
    checkoutLink,
    loginLink,
    registerLink,
  }
}
