import { SectionHeader, SectionHeaderProps, Text, CounterBadge, Box, Tooltip, } from '@wix/design-system'; import React, { cloneElement, isValidElement, ReactElement, ReactNode, } from 'react'; import { st, classes } from './CollectionSectionHeader.st.css.js'; import { CollectionSectionHeaderActionBar } from './CollectionSectionHeaderActionBar'; import { Section } from './CollectionSectionHeader.types'; export interface CollectionSectionHeaderProps extends Pick { sectionId: string; sectionIndex: number; section: Section & { count: number; hasMore?: boolean; items?: T[]; collapsed?: boolean; }; biComponentType: string; collapsible?: boolean; onToggleCollapse?: (sectionId: string) => void; } export const CollectionSectionHeader = ({ sectionId, sectionIndex, section, skin, dataHook, biComponentType, collapsible, onToggleCollapse, }: CollectionSectionHeaderProps) => { const renderBadge = (): ReactNode => { const { badge } = section; if (!badge || !badge.visible) { return null; } return ( {section.count} {section.hasMore ? '+' : ''} ); }; const renderSummary = (): ReactNode => { const { summary } = section; if (!summary || summary.length === 0) { return null; } return ( {summary.map((item, index) => ( {isValidElement(item.icon) ? cloneElement(item.icon as ReactElement, { className: st( classes.summaryIcon, item.icon.props?.className, ), }) : item.icon} {item.count} ))} ); }; const title = ( {section.title} {renderBadge()} {renderSummary()} ); return ( } /> ); };