import React from 'react'; import { Box, Text, Badge, Tag } from '@wix/design-system'; import { ChevronDown, ChevronUp } from '@wix/wix-ui-icons-common'; import { SetupWidgetStep } from '@wix/bex-core'; import { useWixPatternsContainer } from '@wix/bex-core/react'; import { SetupStepIcon } from './SetupStepIcon'; import { st, classes } from './SetupWidget.st.css.js'; export interface SetupStepGroupProps { step: SetupWidgetStep; isMobile: boolean; /** The group's children are shown. */ expanded: boolean; /** The recommended/focused row. */ isPrimary: boolean; onToggle: () => void; /** Renders a single child step (the parent supplies the row/card). */ renderChild: (child: SetupWidgetStep) => React.ReactNode; } /** * Aggregated group row (e.g. "Stores", "Bookings"). Collapsed: icon + title + * an "x/y" counter + chevron. Expanded: the children render indented below. * Completion / in-progress are derived from the children (mirrors * `AggregatedByGroupStep` in dashboard-setup). The toggle lives on the header * only, so clicking a child doesn't collapse the group. */ export const SetupStepGroup = ({ step, isMobile, expanded, isPrimary, onToggle, renderChild, }: SetupStepGroupProps) => { const { translate: t } = useWixPatternsContainer(); const children = step.steps ?? []; const total = children.length; const completed = children.filter((c) => c.status === 'completed').length; const allCompleted = total > 0 && completed === total; const anyInProgress = children.some((c) => c.status === 'in-progress'); const isFocused = expanded || isPrimary; const Chevron = expanded ? ChevronUp : ChevronDown; const header = (
{ if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onToggle(); } }} style={{ cursor: 'pointer' }} > {isMobile ? ( ) : ( )} {/* Mobile cards stack the badge under the title (matches SetupStepCard); desktop rows keep it inline next to it. */} {step.title} {anyInProgress && !allCompleted && (isMobile ? ( {t('cairo.setupWidget.step.inProgress')} ) : ( {t('cairo.setupWidget.step.inProgress')} ))} {t('cairo.setupWidget.aggregated.counter', { completed, total })}
); const childList = expanded && ( {children.map((child) => ( {renderChild(child)} ))} ); if (isMobile) { return (
{header} {childList}
); } return (
{header} {childList}
); };