<?php
include "../includes/header2.php";
?>
<style>
  .custom-button {
    padding: 10px 20px;
  }

  .image-row {
      display: flex;
      flex-direction: column;
      align-items: center; /* Centraliza as imagens */
      margin-bottom: 20px;
  }

  .image-container {
      margin-bottom: 20px; /* Espaçamento entre as imagens */
      text-align: center; /* Centraliza o texto */
      width: 100%; /* Ajusta ao tamanho da tela */
  }

  .image-container img {
      max-width: 100%; /* Garante que a imagem não ultrapasse a tela */
      height: auto; /* Mantém a proporção da imagem */
  }

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

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

<div class="container-fluid">
    <!-- Page Heading -->
    <h1 class="h3 mb-1 text-gray-800">Temas</h1>

    <!-- Custom codes -->
    <div class="card border-left-primary shadow h-100 card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary2"><i class="fa fa-cogs"></i> Escolher Temas</h6>
        </div>
        <div class="card-body">

        <?php
            if ($_SERVER['REQUEST_METHOD'] === 'POST') {
                $selectedOption = $_POST['options'];
                echo "Você selecionou: " . $selectedOption;

                // Lendo o JSON
                $jsonData = file_get_contents("../a/rtx/Setting_$seller_name.json");
                $data = json_decode($jsonData, true);

                // Atualizando os dados do JSON
                $data[0]["RTXSetting"] = "mLayout";
                $data[0]["PanalData"] = $selectedOption;

                // Codificando os dados atualizados e salvando no arquivo
                $jsonData = json_encode($data, JSON_PRETTY_PRINT);
                file_put_contents("../a/rtx/Setting_$seller_name.json", $jsonData);
            }
        ?>

        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            <select name="options" id="options">
                <option value="theme_d">Tema 1</option>
                <option value="theme_2">Tema 2</option>
                <option value="theme_3">Tema 3</option>
                <option value="theme_5">Tema 4</option>
            </select>
            <br><br>
            <input type="submit" class="btn btn-success btn-icon-split" value="Submit">
        </form>

        <br>
        <?php 
            // Lendo o JSON para exibir o tema atual
            $jsonData = file_get_contents("../a/rtx/Setting_$seller_name.json");
            $data = json_decode($jsonData, true);
            $current_layout = $data[0]["PanalData"];
            echo "<br><p style='text-align: center;'>Tema atual: $current_layout</p><br>";
        ?>

        <br>
        <div class="image-row">
            <div class="image-container">
                <p>TEMA 1</p>
                <img src="../rtx/layout/d.png" width="300" height="170" alt="theme_d">
            </div>

            <div class="image-container">
                <p>TEMA 2</p>
                <img src="../rtx/layout/2.png" width="300" height="170" alt="theme_2">
            </div>   

            <div class="image-container">
                <p>TEMA 3</p>
                <img src="../rtx/layout/3.png" width="300" height="170" alt="theme_3">
            </div>

            <div class="image-container">
                <p>TEMA 4</p>
                <img src="../rtx/layout/5.png" width="300" height="170" alt="theme_5">
            </div>
        </div>

        </div>
    </div>
</div>

<?php
include "../includes/footer2.php";
?>
</body>
</html>
