import React, { type PropsWithChildren } from 'react'; import { getComponentFromMap } from '@pega/react-sdk-components/lib/bridge/helpers/sdk_component_map'; import type { PConnProps } from '@pega/react-sdk-components/lib/types/PConnProps'; import './MultiStep.css'; interface MultiStepProps extends PConnProps { // If any, enter additional props that only exist on this component itemKey: string; actionButtons: any[]; onButtonPress: any; bIsVertical: boolean; arNavigationSteps: any; } export default function MultiStep(props: PropsWithChildren) { // Get emitted components from map (so we can get any override that may exist) const AssignmentCard = getComponentFromMap('AssignmentCard'); const { getPConnect, children, itemKey = '', actionButtons, onButtonPress } = props; const { bIsVertical, arNavigationSteps } = props; let currentStep = arNavigationSteps.find(({ visited_status: vs }) => vs === 'current'); if (!currentStep) { const lastActiveStepIndex = arNavigationSteps.findLastIndex(({ visited_status: vs }) => vs === 'success'); currentStep = arNavigationSteps[lastActiveStepIndex >= 0 ? lastActiveStepIndex : 0]; } function _getVBodyClass(index: number): string { const baseClass = 'psdk-vertical-step-body'; const isNotLastStep = index < arNavigationSteps.length - 1; return isNotLastStep ? `${baseClass} psdk-vertical-step-line` : baseClass; } function _getAutoFlexClass(currentStep): string { const currentStepIndex = arNavigationSteps.findIndex(step => step.ID === currentStep?.ID); const totalSteps = arNavigationSteps.length; const lastStep = arNavigationSteps[totalSteps - 1]; // Apply flex-auto class if current step is active OR if current step is second-to-last and the last step is active const isCurrentStepActive = currentStep.visited_status === 'current'; const isSecondToLastWithActiveLastStep = currentStepIndex === totalSteps - 2 && lastStep?.visited_status === 'current'; return isCurrentStepActive || isSecondToLastWithActiveLastStep ? 'flex-auto' : ''; } function isLastStep(index: number): boolean { return index === arNavigationSteps.length - 1; } function buttonPress(sAction: string, sButtonType: string) { onButtonPress(sAction, sButtonType); } return (
{bIsVertical ? (
{arNavigationSteps.map((mainStep, index) => { return (
{index + 1}
{mainStep.visited_status === 'current' && mainStep.name}
{mainStep?.steps && (
    {mainStep.steps.forEach(subStep => {
  • {subStep.visited_status === 'current' && } {subStep.visited_status !== 'current' && } {subStep.visited_status === 'current' && } {subStep.visited_status !== 'current' && }
    {subStep.visited_status === 'current' && (
    {children}
    )}
  • ; })}
)} {!mainStep?.steps && mainStep.visited_status === 'current' && (
{children}
)}
); })}
) : (
{arNavigationSteps.map((mainStep, index) => { return (
{index + 1}
{mainStep.visited_status === 'current' && mainStep.name}
{!isLastStep(index) &&
} ); })}
{arNavigationSteps.map(mainStep => { return ( {mainStep.steps && (
    {mainStep.steps.map(subStep => (
  • {subStep.visited_status === 'current' && } {subStep.visited_status !== 'current' && } {subStep.visited_status === 'current' && } {subStep.visited_status !== 'current' && }
    {subStep.visited_status === 'current' && ( {children} )}
  • ))}
)} {!mainStep?.steps && mainStep.ID === currentStep?.ID && ( {children} )}
); })}
)}
); }