/**
 * Search-box.ai
 * Author: Simon-Pierre Boucher
 * Contact: contact@spboucher.ai
 * File: apps/web/app/page.tsx
 * Description: Home page — hero with blooming mark, question composer, recent sessions.
 */

import Link from "next/link";
import { sessions } from "@search-box/db";
import { ensureMigrated } from "@/lib/runner";
import { NewResearchForm } from "@/components/NewResearchForm";
import { Logo } from "@/components/Logo";

export const dynamic = "force-dynamic";

export default async function HomePage() {
  await ensureMigrated();
  const recent = await sessions.list(12);

  return (
    <main>
      <section className="hero">
        <div>
          <h1>
            Don&apos;t search the web.
            <br />
            Search the <em>answer space</em>.
          </h1>
          <p className="sub">
            An autonomous research engine that forms hypotheses, hunts evidence, surfaces
            contradictions — and writes a fully sourced answer in front of you, live.
          </p>
          <NewResearchForm />
        </div>
        <div className="hero-art" aria-hidden>
          <Logo size={260} />
        </div>
      </section>

      {recent.length > 0 && (
        <section className="recent">
          <h2>Recent research</h2>
          <ul>
            {recent.map((s) => (
              <li key={s.id}>
                <Link href={`/r/${s.id}`}>
                  <span className="q">{s.question}</span>
                  <span className={`badge ${s.status}`}>{s.status}</span>
                  <span className="arrow">→</span>
                </Link>
              </li>
            ))}
          </ul>
        </section>
      )}
    </main>
  );
}
