import type { Metadata } from "next";
import prisma from "@/lib/prisma";
import Link from "next/link";

export const metadata: Metadata = {
  title: "Live Streams",
  description: "Watch live video streams from escorts and performers on AdultWorld. Join free or private live broadcasts.",
  openGraph: {
    title: "Live Streams | AdultWorld",
    description: "Watch live video streams from escorts and performers on AdultWorld.",
  },
};

export default async function StreamsPage() {
  const streams = await prisma.wowzaStream.findMany({
    where: { streaming: true },
    include: {
      user: { select: { id: true, username: true, id_aw: true } },
    },
    orderBy: { created_at: "desc" },
  });

  return (
    <div className="max-w-4xl mx-auto">
      <h1 className="text-3xl font-bold text-text mb-2">Live Streams</h1>

      <p className="text-text-muted mb-6">
        Watch live streams from escorts broadcasting right now. Free preview mode available, with group and private cam sessions for credits. Set up notifications to know when your favourite escorts go live.
      </p>

      {streams.length === 0 ? (
        <div className="bg-surface rounded-lg p-12 text-center">
          <p className="text-text-muted mb-2">No one is streaming right now.</p>
          <p className="text-text-muted text-sm">Check back later or browse profiles.</p>
        </div>
      ) : (
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
          {streams.map((stream) => (
            <Link
              key={stream.id}
              href={`/streams/play/${stream.id}`}
              className="bg-surface rounded-lg overflow-hidden hover:ring-2 hover:ring-primary transition-all"
            >
              <div className="h-40 bg-surface-light flex items-center justify-center relative">
                <span className="absolute top-2 left-2 bg-red-600 text-white text-xs px-2 py-0.5 rounded-full font-semibold">LIVE</span>
                <span className="text-text-muted text-sm">Stream Preview</span>
              </div>
              <div className="p-4">
                <h3 className="font-semibold text-text truncate">{stream.wowza_stream_name || "Live Stream"}</h3>
                <p className="text-text-muted text-sm">{stream.user?.username}</p>
              </div>
            </Link>
          ))}
        </div>
      )}
    </div>
  );
}
