'use client'

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

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

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

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