import { auth } from '@/lib/auth';
import { headers } from 'next/headers';
import { redirect } from 'next/navigation';
import Link from 'next/link';
import { getAdminRequests, getAdminProposals } from '@/features/admin/actions/requests';
import { OpportunityHubClient } from './hub-client';

export default async function AdminRequestsPage() {
    const session = await auth.api.getSession({
        headers: await headers(),
    });

    if (!session?.user) {
        redirect('/login');
    }

    const requests = await getAdminRequests();
    const proposals = await getAdminProposals();

    return (
        <div className="space-y-6">
            <div className="flex flex-col gap-2">
                <div className="flex items-center gap-2 text-xs text-muted-foreground mb-1">
                    <Link href="/admin/dashboard" className="hover:text-primary transition-colors">Dashboard</Link>
                    <span>/</span>
                    <span className="text-foreground font-medium">Opportunities Hub</span>
                </div>
                <div className="flex items-center justify-between">
                    <div>
                        <h1 className="text-3xl font-bold tracking-tight">Opportunities Hub</h1>
                        <p className="text-muted-foreground">
                            Manage fan requests and community link proposals across all creators.
                        </p>
                    </div>
                </div>
            </div>

            <OpportunityHubClient
                initialRequests={requests}
                initialProposals={proposals}
            />
        </div>
    );
}
