import { notFound } from 'next/navigation';
import { SponsorshipRequestsPageQuery } from '@/lib/page-queries/SponsorshipRequestsPageQuery';
import { SponsorshipRequestsClient } from '@/client-wrapper/SponsorshipRequestsClient';
import { acceptSponsorshipRequest, rejectSponsorshipRequest } from '@/app/actions/sponsorshipActions';

export default async function SponsorshipRequestsPage() {
  // Execute PageQuery
  const queryResult = await SponsorshipRequestsPageQuery.execute();
  
  if (queryResult.isErr()) {
    const error = queryResult.getError();
    
    if (error === 'notFound') {
      notFound();
    } else if (error === 'redirect') {
      // In a real implementation, you'd use redirect('/')
      notFound();
    } else {
      // For other errors, show notFound for now
      notFound();
    }
  }
  
  const viewData = queryResult.unwrap();

  return (
    <SponsorshipRequestsClient
      viewData={viewData}
      onAccept={acceptSponsorshipRequest}
      onReject={rejectSponsorshipRequest}
    />
  );
}
