<?php
require_once __DIR__ . '/includes/session_check.php';
checkSession();

$pageTitle = 'Previsualizar Mensaje';

$content = $_GET['content'] ?? '';
$platform = $_GET['platform'] ?? 'discord';

require_once __DIR__ . '/common/helpers/converter_factory.php';

$convertedContent = '';
if ($content) {
    $convertedContent = \Common\Helpers\ConverterFactory::convert($platform, $content);
}

require_once __DIR__ . '/templates/header.php';
?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-eye"></i> Previsualizar Mensaje</h2>
    <div>
        <a href="create_message.php" class="btn btn-outline-secondary">
            <i class="bi bi-arrow-left"></i> Volver
        </a>
    </div>
</div>

<form method="GET" class="mb-4">
    <div class="row">
        <div class="col-md-4">
            <select name="platform" class="form-select" onchange="this.form.submit()">
                <option value="discord" <?= $platform === 'discord' ? 'selected' : '' ?>>Discord (Markdown)</option>
                <option value="telegram" <?= $platform === 'telegram' ? 'selected' : '' ?>>Telegram (HTML)</option>
            </select>
        </div>
        <div class="col-md-8">
            <input type="hidden" name="content" value="<?= htmlspecialchars($_GET['content'] ?? '') ?>">
        </div>
    </div>
</form>

<div class="card border-0 shadow-sm">
    <div class="card-header bg-white border-0">
        <h5 class="mb-0">
            <?= $platform === 'discord' ? '<i class="bi bi-discord platform-discord"></i> Discord' : '<i class="bi bi-telegram platform-telegram"></i> Telegram' ?>
        </h5>
    </div>
    <div class="card-body">
        <?php if ($convertedContent): ?>
            <pre class="bg-light p-3 rounded" style="white-space: pre-wrap; word-wrap: break-word;"><?= htmlspecialchars($convertedContent) ?></pre>
        <?php else: ?>
            <p class="text-muted text-center py-4">No hay contenido para previsualizar</p>
        <?php endif; ?>
    </div>
</div>

<?php require_once __DIR__ . '/templates/footer.php'; ?>
