'use client' import type { SurveySection } from '~/data/surveys/state-of-startups-2026' import { useMemo, useState } from 'react' import { getDistribution } from '../lib/survey-keys' import type { Aggregation, SurveyFilters } from '../lib/survey-keys' import { CohortToggle } from './CohortToggle' import { SectionCallout } from './SectionCallout' import { SurveyChannelMixChart } from './SurveyChannelMixChart' import { SurveyChart } from './SurveyChart' import { SurveyCrossTabChart } from './SurveyCrossTabChart' import { SurveyPullQuote } from './SurveyPullQuote' import { SurveyPullQuoteGrid } from './SurveyPullQuoteGrid' import { SurveyRankedAnswersPair } from './SurveyRankedAnswersPair' import { SurveySectionBreak } from './SurveySectionBreak' import { SurveyStatCard } from './SurveyStatCard' import { SurveySummarizedAnswer } from './SurveySummarizedAnswer' import { SurveyWordCloud } from './SurveyWordCloud' import { YearProvider } from './year-context' import { YearToggle } from './YearToggle' export function SurveyChapterSection({ section }: { section: SurveySection }) { const { id, eyebrow, title, description, statsHeading, stats, charts, pullQuote, pullQuotes, cohortToggle, callout, wordCloud, summarizedAnswer, rankedAnswersPair, } = section const [cohortLabel, setCohortLabel] = useState(cohortToggle?.defaultLabel ?? '') // The active cohort toggle option merges its filter into every stat and bar // chart in the section. Cross-tab and channel-mix carry their own cohorts. const cohortFilter: SurveyFilters | undefined = useMemo(() => { if (!cohortToggle) return undefined const option = cohortToggle.options.find((o) => o.label === cohortLabel) if (!option || option.filter === null) return undefined return { [cohortToggle.key]: option.filter } }, [cohortToggle, cohortLabel]) const eyebrowColor = 'text-primary' // A section can be compared across years only if it has any 2025 data. New-in- // 2026 questions (share of codebase, auth, agents, MCP, the AI-codebase // cross-tabs) have no 2025 baseline, so we hide the year toggle for them. const hasComparison = useMemo(() => { const probe = (col: string, agg: Aggregation, f?: SurveyFilters) => getDistribution(2025, col, agg, f) !== undefined if (stats.some((s) => s.query && probe(s.query.column, s.query.aggregation, s.query.filters))) return true return charts.some((c) => { if (c.kind === 'cross-tab') { return c.cohorts.some((co) => c.series.some((s) => probe(s.query.column, s.query.aggregation, { [c.axisColumn]: co.filter }) ) ) } if (c.kind === 'channel-mix') { return c.cohorts.some((co) => probe(c.column, 'multi', { [c.cohortColumn]: co.filter })) } return probe(c.column, c.aggregation, c.filters) }) }, [stats, charts]) // Each section keeps its own 2025/2026 state so a reader can compare a single // section's stats and charts without affecting the rest of the page. return (

{eyebrow}

{title}

{description}

{/* Section-level year comparison control, sitting just above the data. Hidden for new-in-2026 sections that have no 2025 baseline. */} {hasComparison && (
Compare year
)} {cohortToggle && ( )} {/* Optional question header describing the stat cards below as the answer to a specific survey question. */} {statsHeading && (

{'Q&A'}

{statsHeading.title} {statsHeading.note && ( ({statsHeading.note}) )}

)} {stats.length > 0 && ( )} {charts.map((chart, index) => { if (chart.kind === 'cross-tab') { return ( ) } if (chart.kind === 'channel-mix') { return ( ) } return ( ) })} {rankedAnswersPair && rankedAnswersPair.length > 0 && ( )} {wordCloud && } {summarizedAnswer && ( )} {callout && }
{pullQuote && ( )} {pullQuotes && pullQuotes.length > 0 && }
) }