'use client'

import Link from 'next/link'
import { useRouter } from 'next/navigation'

export function LoginRequiredActions({ loginHref, fallbackHref }: { loginHref: string; fallbackHref: string }) {
  const router = useRouter()

  return (
    <div className="mt-9 flex flex-wrap gap-3">
      <button
        type="button"
        onClick={() => {
          if (window.history.length > 1) {
            router.back()
            return
          }
          router.push(fallbackHref || '/')
        }}
        className="inline-flex h-12 items-center justify-center rounded-[4px] border border-line px-7 text-sm font-extrabold text-muted hover:border-brand hover:text-brand"
      >
        返回上一页
      </button>
      <Link href={loginHref} className="inline-flex h-12 items-center justify-center rounded-[4px] bg-brand px-8 text-sm font-extrabold text-white hover:bg-brand-dark">
        登录 / 注册
      </Link>
    </div>
  )
}
