import { LandingProblemAgitatorItem } from '@/components/landing/problem-agitator/LandingProblemAgitatorItem'; import { GlowBg } from '@/components/shared/ui/glow-bg'; import clsx from 'clsx'; import { Children, ReactElement, cloneElement, Fragment } from 'react'; type Child = ReactElement; // eslint-disable-line @typescript-eslint/no-explicit-any const Arrow = ({ className }: { className?: string }) => { return (
); }; /** * A component meant to be used in the landing page. * It displays a title, description and 3 or 4 problem agitators as children. */ export const LandingProblemAgitator = ({ className, children, title, titleComponent, description, descriptionComponent, cliffhanger, cliffhangerComponent, textPosition = 'center', withBackground = true, withBackgroundGlow = false, variant = 'primary', backgroundGlowVariant = 'primary', containerType = 'ultrawide', }: { className?: string; children?: React.ReactNode; title?: string | React.ReactNode; titleComponent?: React.ReactNode; description?: string | React.ReactNode; descriptionComponent?: React.ReactNode; cliffhanger?: string | React.ReactNode; cliffhangerComponent?: React.ReactNode; textPosition?: 'center' | 'left'; withBackground?: boolean; withBackgroundGlow?: boolean; variant?: 'primary' | 'secondary'; backgroundGlowVariant?: 'primary' | 'secondary'; containerType?: 'narrow' | 'wide' | 'ultrawide'; }) => { const childrenWithProps = Children.map(children, (child) => { if (!child) { return null; } if (typeof child !== 'object') { return child; } const reactChild = child as Child; const reactChildType = reactChild?.type; return cloneElement(reactChild, { className: ''.concat(''), ...(reactChildType === LandingProblemAgitatorItem ? {} : {}), }); }); const childNumber = Children.count(children); const rotationClassesThree = { 0: 'rotate-[220deg] items-center -translate-y-[15px] -translate-x-[30px]', 1: 'rotate-[-45deg] items-center -translate-y-[15px] translate-x-[30px]', 2: 'rotate-[90deg] items-center justify-center translate-y-[60px]', }; const rotationClassesFour = { 0: 'rotate-[220deg] items-center -translate-y-[15px] -translate-x-[30px]', 1: 'rotate-[-45deg] items-center -translate-y-[15px] translate-x-[30px]', 2: 'rotate-[45deg] items-center translate-x-[30px] translate-y-[30px]', 3: 'rotate-[120deg] items-center translate-y-[45px]', }; const renderGridItems = () => { if (!childrenWithProps) return null; if (childNumber === 3) { return ( <> {/* Row 1 */} {childrenWithProps[0]} {/* Row 2 */} {childrenWithProps[2]} {childrenWithProps[1]} ); } else { return ( <> {/* Row 1 */} {childrenWithProps[0]} {/* Row 2 */} {childrenWithProps[3]}
{childrenWithProps[1]} {/* Row 3 */} {childrenWithProps[2]} ); } }; return (
{withBackgroundGlow ? (
) : null} {title || description || titleComponent || descriptionComponent ? (
{title ? (

{title}

) : ( titleComponent )} {description ? (

{description}

) : ( descriptionComponent )}
) : null}
{renderGridItems()}
{cliffhangerComponent || cliffhanger ? (
{cliffhangerComponent ? ( cliffhangerComponent ) : (

{cliffhanger}

)}
) : null}
); };