import React from 'react' import { ComponentsContext } from '../../RichText' import type { BodyProps } from '../../Body' import { presets, Teaser as TeaserComponent } from '@financial-times/x-teaser' import { TeaserFragment } from '@financial-times/cp-content-pipeline-client' import classnames from 'classnames' type Teasers = TeaserFragment[] function validTeasers(teasers: (TeaserFragment | null)[]) { return teasers.filter((teaser): teaser is TeaserFragment => !!teaser) } function packageIndicatorClassNames( indicators: Record | null | undefined ) { return Object.entries(indicators ?? {}) .filter(([, value]) => value === true) .map(([indicator]) => { const indicatorName = indicator.startsWith('is') ? indicator.slice('is'.length) : indicator return `${indicatorName.toLowerCase()}-package` }) } type PackageTeasersProps = { primaryTeasers: Teasers secondaryTeasers: Teasers secondaryTeaserTitle: string secondaryTeaserMods: string[] AdSlot?: React.FC } type PrimaryTeasersProps = { teasers: Teasers } type SecondaryTeasersProps = { teasers: Teasers teaserTitle: string teaserMods: string[] AdSlot?: React.FC } type ContentPackageBodyProps = BodyProps & { AdSlot?: React.FC } const ContentPackageBody: React.FC = ({ content, richTextComponents, AdSlot, }) => { if (content.__typename !== 'ContentPackage') { return null } const { design, contains: teasers } = content if (!teasers) { return null } const primaryTeasers: TeaserFragment[] = validTeasers(teasers.slice(0, 6)) const secondaryTeasers: TeaserFragment[] = validTeasers(teasers.slice(6)) const secondaryTeaserTitle = content.clientName ? `More from ${content.clientName}` : design?.theme === 'special-report' ? 'More from this Special Report' : 'More from this Series' const secondaryTeaserMods = design?.theme?.startsWith('extra') ? ['inverse'] : [] return (
) } const PackageTeasers: React.FC = ({ primaryTeasers, secondaryTeasers, secondaryTeaserTitle, secondaryTeaserMods, AdSlot, }) => { return (
{!!primaryTeasers.length && } {!!secondaryTeasers.length && ( )} {AdSlot && }
) } const PrimaryTeasers: React.FC = ({ teasers }) => { return (
    {teasers.map( (teaser: TeaserFragment | null) => teaser && (
  • ) )}
) } const SecondaryTeasers: React.FC = ({ teaserTitle, teasers, teaserMods, }) => { return (
{teaserTitle && (

{teaserTitle}

)}
    {teasers.map((teaser: TeaserFragment) => (
  • ))}
) } export default ContentPackageBody