<?php
// components/Newsletter/WizardSteps.php
namespace Components\Newsletter;

class WizardSteps
{
    public const STEP_AUDIENCE = 'audience';
    public const STEP_TEMPLATE = 'template';
    public const STEP_DETAILS = 'details';
    public const STEP_CONFIRMATION = 'confirmation';

    /**
     * Get the wizard steps based on the current context (provided IDs).
     *
     * @return array
     */
    public static function getSteps(): array
    {
        $skipTemplate = ((\mh_get('skip_template') !== '' && \mh_get('skip_template') !== null) || (\mh_post('skip_template') !== '' && \mh_post('skip_template') !== null));
        $skipAudience = ((\mh_get('skip_audience') !== '' && \mh_get('skip_audience') !== null) || (\mh_post('skip_audience') !== '' && \mh_post('skip_audience') !== null));

        $steps = [];
        if (!$skipAudience) {
            $steps[] = [
                'id' => self::STEP_AUDIENCE,
                'label' => (string) \mh_lng('UI_STEP_AUDIENCE', 'Audience'),
                'description' => (string) \mh_lng('UI_STEP_AUDIENCE_DESC', 'Select existing or create new'),
            ];
        }
        if (!$skipTemplate) {
            $steps[] = [
                'id' => self::STEP_TEMPLATE,
                'label' => (string) \mh_lng('UI_STEP_TEMPLATE', 'Template'),
                'description' => (string) \mh_lng('UI_STEP_TEMPLATE_DESC', 'Select template and edit it after creating the flow'),
            ];
        }
        $steps[] = [
            'id' => self::STEP_DETAILS,
            'label' => (string) \mh_lng('UI_STEP_DETAILS', 'Details'),
            'description' => (string) \mh_lng('UI_STEP_DETAILS_DESC', 'Sending time, collection, coupon'),
        ];
        $steps[] = [
            'id' => self::STEP_CONFIRMATION,
            'label' => (string) \mh_lng('UI_STEP_CONFIRMATION', 'Next Steps'),
            'description' => (string) \mh_lng('UI_STEP_CONFIRMATION_DESC', 'Go directly to email editing or expand the flow'),
        ];

        return $steps;
    }

    /**
     * Render the Stepper component for the current wizard state.
     *
     * @param string $currentStepId
     * @return string
     */
    public static function renderStepper(string $currentStepId): string
    {
        $steps = self::getSteps();
        $stepper = \Components\Ui\Stepper::render($steps, $currentStepId);
        return '<div class="absolute z-100 w-full px-6 py-4 border-b border-zinc-200 bg-zinc-50/80 -m-6 ">' . $stepper . '</div><div class="h-18"></div>';
    }
}
