import { CreateLeagueWizard } from '@/client-wrapper/CreateLeagueWizard';
import { Section } from '@/ui/Section';
import { Container } from '@/ui/Container';
import { SearchParamParser } from '@/lib/routing/search-params/SearchParamParser';
import { SearchParamBuilder } from '@/lib/routing/search-params/SearchParamBuilder';

type StepName = 'basics' | 'visibility' | 'structure' | 'schedule' | 'scoring' | 'stewarding' | 'review';

interface CreateLeaguePageProps {
  searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}

export default async function CreateLeaguePage({ searchParams }: CreateLeaguePageProps) {
  const resolvedParams = await searchParams;
  const wizardParams = SearchParamParser.parseWizard(resolvedParams as any).unwrap();
  const rawStep = wizardParams.step;

  let currentStepName: StepName = 'basics';
  if (rawStep === 'basics' || 
      rawStep === 'visibility' || 
      rawStep === 'structure' || 
      rawStep === 'schedule' || 
      rawStep === 'scoring' || 
      rawStep === 'stewarding' || 
      rawStep === 'review') {
    currentStepName = rawStep;
  }

  return (
    <Section>
      <Container size="md">
        <CreateLeagueWizard stepName={currentStepName} />
      </Container>
    </Section>
  );
}
