'use client'

import Link, { type LinkProps } from '../Link'
import { login } from '@scandic-hotels/common/constants/routes/handleAuth'

import type { PropsWithChildren } from 'react'
import type { Lang } from '@scandic-hotels/common/constants/language'

export function LoginButton({
  lang,
  pathName,
  trackingId,
  children,
  ...props
}: PropsWithChildren<
  {
    lang: Lang
    pathName: string | null
    trackingId: string
  } & Omit<LinkProps, 'href'>
>) {
  const href = pathName
    ? `${login[lang]}?redirectTo=${encodeURIComponent(pathName)}`
    : login[lang]

  return (
    <Link id={trackingId} href={href} prefetch={false} {...props}>
      {children}
    </Link>
  )
}
