<?php
session_start();

require_once __DIR__ . '/../../../shared/utils/helpers.php';
require_once __DIR__ . '/../../../shared/auth/jwt.php';
require_once __DIR__ . '/../../../shared/database/connection.php';

// Verificar autenticación
$userData = JWTAuth::requireAuth();

$id = $_GET['id'] ?? null;

if (!$id) {
    die('ID no proporcionado');
}

$db = getDB();
$stmt = $db->prepare("SELECT * FROM plantillas_telegram WHERE id = ?");
$stmt->execute([$id]);
$plantilla = $stmt->fetch();

if (!$plantilla) {
    die('Plantilla no encontrada');
}
?>
<!DOCTYPE html>
<html lang="<?php echo $userData->idioma ?? 'es'; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vista Previa: <?php echo htmlspecialchars($plantilla['nombre']); ?></title>
    <style>
        body {
            font-family: 'gg sans', 'Noto Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
            background-color: #313338;
            color: #dbdee1;
            padding: 20px;
            margin: 0;
            line-height: 1.375rem;
        }
        
        .telegram-message {
            max-width: 800px;
            margin: 0 auto;
            background: #313338;
            padding: 10px;
        }
        
        .message-content {
            font-size: 1rem;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        
        /* Estilos básicos para simular Telegram */
        strong { font-weight: 700; }
        em { font-style: italic; }
        u { text-decoration: underline; }
        
        a {
            color: #00a8fc;
            text-decoration: none;
        }
        
        a:hover {
            text-decoration: underline;
        }
        
        code {
            background-color: #2b2d31;
            padding: 2px;
            border-radius: 3px;
            font-family: Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Liberation Mono', 'Nimbus Mono L', Monaco, 'Courier New', Courier, monospace;
            font-size: 0.875rem;
        }
        
        pre {
            background-color: #2b2d31;
            border: 1px solid #1e1f22;
            border-radius: 4px;
            padding: 8px;
            margin: 6px 0;
            max-width: 100%;
            overflow-x: auto;
        }
        
        pre code {
            background-color: transparent;
            padding: 0;
            border-radius: 0;
            font-size: 0.875rem;
        }
        
        blockquote {
            margin: 0;
            padding: 0 0 0 4px;
            border-left: 4px solid #4e5058;
            max-width: 100%;
        }
        
        img {
            max-width: 100%;
            height: auto;
            border-radius: 4px;
            margin-top: 5px;
        }
        
        h1, h2, h3 {
            margin: 8px 0;
            font-weight: 700;
        }
        
        h1 { font-size: 1.5rem; }
        h2 { font-size: 1.25rem; }
        h3 { font-size: 1rem; }
        
        ul, ol {
            margin: 8px 0;
            padding-left: 24px;
        }
    </style>
</head>
<body>
    <div class="telegram-message">
        <div class="message-content">
            <?php echo $plantilla['contenido']; ?>
        </div>
    </div>
</body>
</html>
