import type { Metadata } from "next";
import Link from "next/link";

import { isBetaPublicSurfaceEnabled } from "@/lib/betaVisibility";

export const metadata: Metadata = {
  title: "Tính năng đang hoàn thiện",
  robots: { index: false, follow: false },
};

type Props = { searchParams?: Promise<{ from?: string }> };

export default async function BetaComingSoonPage(props: Props) {
  const sp = (await props.searchParams) ?? {};
  const from = typeof sp.from === "string" ? sp.from : "";

  if (!isBetaPublicSurfaceEnabled()) {
    return (
      <main className="mx-auto max-w-lg px-4 py-20 text-stone-200">
        <p className="text-sm text-stone-400">Trang này chỉ dùng khi bật chế độ beta public surface.</p>
        <Link href="/" className="ctkp-text-link mt-6 inline-block text-sm">
          Về trang chủ
        </Link>
      </main>
    );
  }

  return (
    <main className="mx-auto max-w-lg px-4 py-20 text-center text-stone-100">
      <p className="ctkp-eyebrow">Cổ thư · beta</p>
      <h1 className="font-ctkp-display mt-6 text-2xl font-semibold tracking-tight">Tính năng đang hoàn thiện</h1>
      <p className="mt-4 text-pretty text-sm leading-relaxed text-stone-500">
        Trang này chưa mở trong phiên bản beta công khai. Bạn vẫn có thể dùng trang chủ, sổ bài, gieo quẻ và lá số Tử
        Vi từ menu điều hướng.
      </p>
      {from && from !== "/" ?
        <p className="mt-3 font-mono text-[11px] text-stone-600">
          Đường dẫn yêu cầu: <span className="text-stone-500">{from}</span>
        </p>
      : null}
      <Link href="/" className="ctkp-btn-primary mt-10 inline-block px-8 py-3">
        Về trang chủ
      </Link>
      <p className="mt-12 text-[10px] text-stone-700">
        <Link href="/internal/beta-staff/login" className="text-stone-600 underline-offset-2 hover:text-stone-500 hover:underline">
          Đăng nhập nội bộ (staff)
        </Link>
      </p>
    </main>
  );
}
