<?php


//<----------------------------------------------------------->
//<-------------------COPIA AI BRUXÃO------------------------->
//<-------------CONTATO: https://t.me/eonbry------------------>
//<-------------DEVELOPER: EMANUEL NASCIMENTO----------------->
//<----------------------------------------------------------->


include "includes/header.php";

$jsonPath = './a/rtx/Setting.json';

$jsonData = file_get_contents($jsonPath);

if ($jsonData === false) {
    die("Erro: arquivo JSON não encontrado.");
}

$data = json_decode($jsonData, true);

if ($data === null) {
    die("Erro: arquivo JSON inválido.");
}

$temas_permitidos = [
    "theme_d" => "Tema Futurista",
    "theme_2" => "Tema Dark",
    "theme_3" => "Tema Neon",
    "theme_4" => "Tema Cyber"
];

$show_message = false;
$message_type = '';
$message_text = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $selectedOption = $_POST['options'];

    if (array_key_exists($selectedOption, $temas_permitidos)) {
        $data[0]["RTXSetting"] = "mLayout";
        $data[0]["PanalData"] = $selectedOption;

        file_put_contents($jsonPath, json_encode($data, JSON_PRETTY_PRINT));
        $show_message = true;
        $message_type = 'success';
        $message_text = 'Tema atualizado com sucesso!';
    } else {
        $show_message = true;
        $message_type = 'error';
        $message_text = 'Tema inválido selecionado!';
    }
}

$current_layout = $data[0]["PanalData"];
$nome_tema_atual = $temas_permitidos[$current_layout] ?? "Desconhecido";
?>

<style>
  .custom-button {
    padding: 10px 20px;
  }

  .image-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
  }

  .image-container {
    flex: 1 1 300px;
    max-width: 300px;
    text-align: center;
    padding: 5px;
    border: 2px solid transparent;
    border-radius: 10px;
  }

  .image-container img {
    max-width: 100%;
    height: auto;
  }

  .tema-ativo {
    border-color: #007bff; /* azul Bootstrap */
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
  }

  label, select, input {
    margin-left: 10px;
  }

  form {
    display: flex;
    justify-content: center;
  }
</style>



<!DOCTYPE html>

<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Selecionar Tema</title>

<style>
:root {
    --primary: #00D4FF;
    --accent: #00FF88;
    --secondary: #FF6B9D;
    --surface: #0A0F1C;
    --surface-light: #1A1F2C;
    --text: #FFFFFF;
    --border: rgba(255,255,255,0.1);
    --glow: 0 0 20px rgba(0,212,255,0.3);
}

body {
    background: var(--surface);
    color: var(--text);
    font-family: "Poppins", sans-serif;
}

.card {
    background: var(--surface-light);
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    padding: 20px;
    border: 1px solid var(--border);
    margin-top: 20px;
}

h1, h6 {
    background: linear-gradient(90deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

select, input[type="submit"] {
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 10px 15px;
    transition: 0.3s ease;
}

select:focus {
    border-color: var(--primary);
    box-shadow: var(--glow);
    outline: none;
}

input[type="submit"] {
    background: linear-gradient(135deg, var(--accent), #00cc7a);
    color: #000;
    font-weight: 600;
    text-transform: uppercase;
    border: none;
    cursor: pointer;
}

input[type="submit"]:hover {
    box-shadow: 0 0 20px rgba(0,255,136,0.4);
    transform: translateY(-3px);
}

.image-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 25px;
    margin-top: 30px;
}

.image-container {
    background: var(--surface-light);
    border-radius: 12px;
    border: 2px solid var(--border);
    padding: 10px;
    text-align: center;
    width: 280px;
    cursor: pointer;
    transition: 0.3s;
}

.image-container:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: var(--glow);
}

.tema-ativo {
    border-color: var(--accent);
    box-shadow: 0 0 25px rgba(0,255,136,0.3);
}

.image-container img {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.alert-message {
    text-align: center;
    font-weight: 600;
    border-radius: 10px;
    margin: 20px 0;
    padding: 15px;
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.alert-success {
    background: linear-gradient(135deg, #00ff88, #00cc6a);
    color: #000;
}

.alert-error {
    background: linear-gradient(135deg, #ff6b9d, #ff4d8d);
    color: #fff;
}

.alert-hide {
    opacity: 0;
    transform: translateY(-20px);
}
</style>

</head>
<body>

<div class="container-fluid">
    <h1 class="h3 mb-1">🎨 Selecionar Tema</h1>
<div class="card">
    <h6><i class="fa fa-cogs"></i> Configuração de Tema</h6>

    <?php if ($show_message): ?>
        <div class="alert-message alert-<?php echo $message_type; ?>" id="autoHideMessage">
            <?php echo $message_text; ?>
        </div>
    <?php endif; ?>

    <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" style="text-align:center; margin-top:20px;">
        <select name="options" id="options">
            <?php
            foreach ($temas_permitidos as $valor => $nome) {
                $selected = $current_layout === $valor ? "selected" : "";
                echo "<option value='$valor' $selected>$nome</option>";
            }
            ?>
        </select>
        <br><br>
        <input type="submit" value="Salvar Tema">
    </form>

    <p style='text-align: center; margin-top:20px;'>Tema atual: 
        <strong style="color:var(--accent);"><?php echo $nome_tema_atual; ?></strong>
    </p>

    <div class="image-row">
        <?php
        $temas_imagem = [
            "theme_d" => "d.png",
            "theme_2" => "2.png",
            "theme_3" => "3.png",
            "theme_4" => "4.png"
        ];

        foreach ($temas_imagem as $tema => $imagem) {
            $classe_ativa = ($current_layout === $tema) ? "tema-ativo" : "";
            $nome_tema = $temas_permitidos[$tema];
            echo "<div class='image-container $classe_ativa'>";
            echo "<p>$nome_tema</p>";
            echo "<img src='./rtx/layout/$imagem' alt='$tema'>";
            echo "</div>";
        }
        ?>
    </div>
</div>

</div>

<script>
document.addEventListener("DOMContentLoaded", function() {
    // Fade automático da mensagem
    const msg = document.getElementById("autoHideMessage");
    if (msg) {
        setTimeout(() => {
            msg.classList.add("alert-hide");
            msg.addEventListener("transitionend", () => {
                msg.remove();
            });
        }, 3000);
    }

    // Clique na imagem muda seleção
    const imageContainers = document.querySelectorAll('.image-container');
    const selectElement = document.getElementById('options');

    imageContainers.forEach(container => {
        container.addEventListener('click', function() {
            const name = this.querySelector('p').textContent;
            const mapping = <?php echo json_encode($temas_permitidos); ?>;
            const value = Object.keys(mapping).find(key => mapping[key] === name);
            if (value) {
                selectElement.value = value;
                imageContainers.forEach(c => c.classList.remove('tema-ativo'));
                this.classList.add('tema-ativo');
            }
        });
    });
});
</script>

<?php include "includes/footer.php"; ?>

</body>
</html>
 