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

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}
    />
  );
}
