<?php
// pages/components/main_template_created_success.php
require_once BEEZUI_ROOT . '/components/index.php';

use Components\Base;
use Components\Button;
use Components\Router;
use Components\Support\Htmx;
use Components\MainTemplate\WizardSteps;

$maintemplateId = (string)\mh_get('maintemplate_id');
$templateName = (string)\mh_get('template_name');
$lngId = (int)\mh_get('lng_id', \mh_session('languages_id', 1), 'int');
$modalId = Htmx::resolvePanelId();

$editorUrl = Router::url('email_editor', [
    'context' => 'main',
    'maintemplate_id' => $maintemplateId,
    'lng_id' => $lngId,
    'partial' => 1,
    'scroll_hints' => 'false',
]);

ob_start();
?>
<div class="text-center" id="config-modal-body">
    <script>
        (function() {
            var modal = document.getElementById('<?= Base::h($modalId, false) ?>');
            if (modal) {
                modal.setAttribute('data-title', <?= json_encode(\mh_lng('UI_TITLE_MAIN_TEMPLATE_CREATED', 'Main Template Created')); ?>);
                modal.setAttribute('data-size', '2xl');
            }
        })();
    </script>

    <?= WizardSteps::renderStepper(WizardSteps::STEP_CONTINUE) ?>

    <div class="p-8 pt-0 mt-6">
        <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_TEXT_MAIN_TEMPLATE_CREATED_SUCCESS', 'Your main template is ready.') ?></h2>
        <p class="text-secondary mb-8"><?= \mh_lng('UI_TEXT_MAIN_TEMPLATE_CREATED_NEXT_STEPS', 'What would you like to do next?') ?></p>

        <?php if ($templateName !== ''): ?>
            <p class="mb-8 inline-flex items-center rounded-full border border-divider px-3 py-1.5 text-xs text-secondary">
                <?= Base::h($templateName) ?>
            </p>
        <?php endif; ?>

        <div class="flex flex-col gap-3 max-w-sm mx-auto">
            <?= Button::render(\mh_lng('UI_BUTTON_OPEN_TEMPLATE_FOR_EDITING', 'Open template for editing'), [
                'variant' => 'primary',
                'size' => 'lg',
                'class' => 'inline!',
                'attrs' => [
                    'command' => 'show-modal',
                    'commandfor' => $modalId,
                    'data-title' => \mh_lng('MAILBEEZ_BUTTON_EDITOR_LABEL', 'Editor'),
                    'data-size' => 'full',
                    'data-body-class' => 'p-2!',
                    'data-scroll-hints' => 'false',
                    'hx-get' => $editorUrl,
                    'hx-target' => '#' . $modalId . '-body',
                    'hx-swap' => 'innerHTML',
                    'hx-push-url' => 'false',
                ],
            ]) ?>

            <?= Button::render(\mh_lng('UI_BUTTON_SKIP', 'Skip'), [
                'variant' => 'ghost',
                'size' => 'md',
                'class' => 'inline!',
                'attrs' => [
                    'command' => 'close',
                    'commandfor' => $modalId,
                ],
            ]) ?>
        </div>
    </div>
</div>
<?php
echo ob_get_clean();
