<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

include 'includes/header.php'; 

// Salvar a URL enviada
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $novaUrl = trim($_POST['url']);
    if (filter_var($novaUrl, FILTER_VALIDATE_URL)) {
        file_put_contents('jogos_url.txt', $novaUrl);
        $mensagem = "✅ URL salva com sucesso!";
    } else {
        $mensagem = "❌ URL inválida!";
    }
}

$urlAtual = file_exists('jogos_url.txt') ? file_get_contents('jogos_url.txt') : '';
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <title>Configurar URL dos Jogos</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
    <style>
        :root {
            --md-bg: #f0f1f6;
            --md-card: #ffffff;
            --md-primary: #4a5fc1;
            --md-success: #28a745;
            --md-error: #dc3545;
            --md-text: #121212;
            --md-shadow: rgba(0,0,0,0.15);
            --md-radius: 16px;
        }

        * {
            box-sizing: border-box;
        }

        html, body {
            margin: 0;
            padding: 0;
            font-family: 'Inter', sans-serif;
            height: 100%;
            background-color: var(--md-bg);
        }

        .container {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }

        .form-box {
            background-color: var(--md-card);
            padding: 40px 30px;
            border-radius: var(--md-radius);
            box-shadow: 0 10px 30px var(--md-shadow);
            max-width: 500px;
            width: 100%;
            text-align: center;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .form-box:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px var(--md-shadow);
        }

        h2 {
            margin-bottom: 25px;
            font-weight: 600;
            font-size: 1.8rem;
            color: var(--md-primary);
        }

        input[type="text"] {
            width: 100%;
            padding: 14px 16px;
            font-size: 1rem;
            border: 1px solid #ccc;
            border-radius: 12px;
            margin-bottom: 20px;
            transition: border 0.3s ease, box-shadow 0.3s ease;
        }

        input[type="text"]:focus {
            border-color: var(--md-primary);
            box-shadow: 0 0 6px rgba(74,95,193,0.4);
            outline: none;
        }

        button {
            width: 100%;
            padding: 14px 0;
            font-size: 1rem;
            border: none;
            border-radius: 12px;
            color: #fff;
            background-color: var(--md-primary);
            cursor: pointer;
            font-weight: 600;
            transition: background 0.3s ease, transform 0.2s ease;
        }

        button:hover {
            background-color: #3a4aad;
            transform: translateY(-2px);
        }

        .mensagem {
            margin-top: 18px;
            font-weight: 500;
            font-size: 0.95rem;
            color: var(--md-text);
        }

        .mensagem.success { color: var(--md-success); }
        .mensagem.error { color: var(--md-error); }

        @media (max-width: 480px) {
            .form-box {
                padding: 30px 20px;
            }

            h2 {
                font-size: 1.5rem;
            }

            input[type="text"], button {
                font-size: 0.95rem;
                padding: 12px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="form-box">
            <h2>🔗 Configurar URL da Página de Jogos</h2>
            <form method="POST">
                <input type="text" name="url" placeholder="https://seudominio.com/pagina.html" value="<?= htmlspecialchars($urlAtual) ?>" required>
                <button type="submit">Salvar URL</button>
            </form>
            <?php if (!empty($mensagem)): ?>
                <div class="mensagem <?= strpos($mensagem,'✅')!==false ? 'success' : 'error' ?>">
                    <?= $mensagem ?>
                </div>
            <?php endif; ?>
        </div>
    </div>
</body>
</html>
