import { getServerSession } from "next-auth/next";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import { redirect } from "next/navigation";
import { ResponsiveIframe } from "@/app/components/responsive-iframe";

export default async function LivresPage() {
  const session = await getServerSession(authOptions);

  if (!session) {
    redirect("/signin");
  }
  
  // Get the iframe URL from environment variables
  const iframeUrl = process.env.NEXT_PUBLIC_IFRAME_LIVRE_URL || '';
  
  // If no URL is set, show an error
  if (!iframeUrl) {
    return (
      <main className="w-full h-screen bg-white">
        <div className="w-full h-full px-4 pt-12 pb-4 flex items-center justify-center">
          <div className="text-center p-8 bg-red-50 rounded-lg border border-red-200">
            <h2 className="text-xl font-bold text-red-600 mb-4">Configuration Error</h2>
            <p className="text-gray-700">
              NEXT_PUBLIC_IFRAME_LIVRE_URL environment variable is not set.
            </p>
          </div>
        </div>
      </main>
    );
  }

  return (
    <main className="w-full h-screen bg-white">
      <div className="w-full h-full px-4 pt-12 pb-4">
        <ResponsiveIframe 
          src={iframeUrl}
          allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
        />
      </div>
    </main>
  );
} 