<?php
// pages/components/audience_created_success_step.php

use Components\Router;
use Components\Legacy\LegacyRouter;
use Components\Button;

/** @var string $panelId */
/** @var string $panelTarget */
/** @var int $listId */
/** @var string $pageMode */
/** @var int $campaignId */
/** @var string $templateId */
/** @var string $date */
/** @var string $headerHtml */
/** @var bool $isNewsletterFlow */
/** @var callable $getFinalUrl */

echo $headerHtml;
?>
<div class="p-8 text-center">
    <script>
        (function() {
            var m = document.getElementById('<?= $panelId ?>');
            if (m) {
                m.setAttribute('data-title', <?= json_encode(\mh_lng('UI_AUDIENCE_CREATED_TITLE', 'Audience created')); ?>);
                m.setAttribute('data-size', '3xl');
            }
        })();
    </script>
    <div class="size-20 rounded-full bg-green-100 text-green-600 flex items-center justify-center mx-auto mb-6">
        <svg class="size-10" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
        </svg>
    </div>
    <h2 class="text-2xl font-bold mb-2"><?= \mh_lng('UI_AUDIENCE_CREATED_TITLE', 'Audience created'); ?></h2>
    <p class="text-secondary mb-8"><?= \mh_lng('UI_AUDIENCE_CREATED_CONFIRM_SEGMENTATION', 'Your new audience is ready. Would you like to configure segmentation now?'); ?></p>

    <div class="flex flex-col gap-3 max-w-sm mx-auto">
        <?= Button::render(\mh_lng('UI_AUDIENCE_CONFIGURE_SEGMENTATION', 'Configure segmentation'), [
            'variant' => 'primary',
            'size' => 'lg',
            'class' => 'inline!',
            'attrs' => [
                'command' => 'show-modal',
                'commandfor' => $panelId,
                'data-size' => '4xl',
                'data-url' => LegacyRouter::url('listSegmentationEdit', [
                    'list_id' => $listId,
                    'module' => 'shop_customers_all',
                    'return_to' => $isNewsletterFlow ? 'audience_item_create' : 'audience_standalone',
                    'page_mode' => $pageMode,
                    'newsletter_campaign_id' => $campaignId,
                    'template_id' => $templateId,
                    'date' => $date,
                ]),
                'hx-target' => $panelTarget,
                'hx-swap' => 'innerHTML',
            ],
        ]); ?>

        <?php
        $finalUrl = $getFinalUrl($listId);
        $skipButtonAttrs = [
            'hx-target' => $panelTarget,
            'hx-swap' => 'innerHTML',
            'hx-push-url' => 'false',
        ];
        if ($finalUrl) {
            $skipButtonAttrs['hx-get'] = $finalUrl;
        } else {
            $skipButtonAttrs = [
                'command' => 'close',
                'commandfor' => $panelId,
            ];
        }
        ?>

        <?= Button::render(\mh_lng('UI_AUDIENCE_SKIP_FOR_NOW', 'Skip for now'), [
            'variant' => 'ghost',
            'size' => 'md',
            'class' => 'inline!',
            'attrs' => $skipButtonAttrs,
        ]); ?>
    </div>
</div>
