import { redirect } from "next/navigation";
import { getCurrentUser } from "@/lib/auth";
import { hasLiveAgent } from "@/lib/db";
import { LiveAgentChat } from "@/components/LiveAgentChat";
import { AGENT_PRICE_GHS } from "@/lib/pricing";
import { PayBox } from "@/components/PayBox";

export const metadata = { title: "Live coach" };

export default async function AgentPage() {
  const user = await getCurrentUser();
  if (!user) redirect("/login?next=/agent");

  const active = hasLiveAgent(user);
  const wa = process.env.NEXT_PUBLIC_COACH_WHATSAPP || "233200000000";

  return (
    <div className="mx-auto max-w-3xl px-4 py-12">
      <p className="text-xs uppercase tracking-[0.28em] text-terra">Paid human</p>
      <h1 className="font-display mt-2 text-4xl text-forest">Contact a live agent</h1>
      <p className="mt-3 text-forest/75">
        The in-lesson tutor is included in your ₵50 window and with each unlocked course. A live coach is a
        separate ₵{AGENT_PRICE_GHS} pass for 30 days — in-thread replies during 8am–8pm GMT, plus WhatsApp.
      </p>
      {active ? (
        <div className="mt-8">
          <LiveAgentChat whatsapp={wa} />
        </div>
      ) : (
        <div className="mt-8">
          <PayBox kind="agent" title="Live coach · 30 days" locked={false} />
        </div>
      )}
    </div>
  );
}
