import { HydrationBoundary, dehydrate } from '@tanstack/react-query';
import PageContainer from '@/components/layout/page-container';
import { opportunityByIdOptions } from '@/features/crm-demo/api/queries';
import { OpportunityDetailPage } from '@/features/crm-demo/components/opportunity-detail';
import { getQueryClient } from '@/lib/query-client';

type PageProps = { params: Promise<{ id: string }> };

export default async function OpportunityDetailRoute({ params }: PageProps) {
  const { id } = await params;
  const queryClient = getQueryClient();
  void queryClient.prefetchQuery(opportunityByIdOptions(id));

  return (
    <PageContainer
      pageTitle='Opportunity Detail'
      pageDescription='Header summary, customer/contact, requirement summary, timeline, and related quotations'
    >
      <HydrationBoundary state={dehydrate(queryClient)}>
        <OpportunityDetailPage id={id} />
      </HydrationBoundary>
    </PageContainer>
  );
}

