import { useMemo } from 'react';
import { DEFAULT_NEXT_BUTTON_TEXT, DEFAULT_PREV_BUTTON_TEXT, } from './constants';
export const useLogic = ({ currentStepId, steps, submitButtonText, isLastStep, }) => {
    const indexStep = useMemo(() => currentStepId
        ? steps?.findIndex(({ id }) => Object.is(id, currentStepId))
        : 0, [currentStepId, steps]);
    const currentStep = steps[indexStep];
    const stepsByLabel = steps.map(({ label }, index) => ({
        label,
        stepId: index,
    }));
    const prevButtonText = currentStep.prevButtonText || DEFAULT_PREV_BUTTON_TEXT;
    const nextButtonText = currentStep.nextButtonText || DEFAULT_NEXT_BUTTON_TEXT;
    return {
        Component: currentStep.component,
        steps: stepsByLabel,
        activeStep: indexStep,
        footerProps: {
            prevButtonText,
            submitButtonText: isLastStep ? submitButtonText : nextButtonText,
        },
    };
};
