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

if (!isset($_SESSION['eggzie_iboPlayer'])) {
    header('Location: login.php');
    exit();
}

require("includes/header.php");  // Importante para o estilo!
?>

<div class="container-fluid mt-4">
    <div class="card shadow">
        <div class="card-header">
            <h5 class="m-0 font-weight-bold text-primary">Gerador de Banner do Aplicativo</h5>
        </div>
        <div class="card-body">
          <div class="form-row align-items-center mb-3">
            <div class="col-auto">
              <select id="mediaType" class="form-control">
                <option value="movie">Filme</option>
                <option value="tv">Serie</option>
              </select>
            </div>
            <div class="col-auto">
              <input id="query" class="form-control" placeholder="Buscar...">
            </div>
            <div class="col-auto">
              <button id="btnSearch" class="btn btn-primary">Buscar</button>
            </div>
            <div class="col-auto">
              <select id="resolution" class="form-control">
                <option value="1080x1920">Stories 9:16</option>
                <option value="1080x1080">WhatsApp 1:1</option>
                <option value="1920x1080">Banner 16:9</option>
              </select>
            </div>
            <div class="col-auto">
              <label class="mb-1">Fundo do Banner</label>
              <input type="file" id="bgUpload" class="form-control-file">
            </div>
            <div class="col-auto">
              <label class="mb-1">Logo da sua Marca</label>
              <input type="file" id="logoUpload" class="form-control-file">
            </div>
            <div class="col-auto">
              <label class="mb-1">Titulo Personalizado</label>
              <div class="input-group">
                <input id="customTitle" class="form-control" placeholder="Ex: Lançamento Hoje">
                <div class="input-group-append">
                  <input type="color" id="titleColor" value="#FFD700" class="form-control form-control-color" style="width: 45px; padding: 0;">
                </div>
              </div>
            </div>
            <div class="col-auto">
              <div class="form-check form-check-inline">
                <input class="form-check-input" type="checkbox" id="showCustomTitle">
                <label class="form-check-label ml-2" for="showCustomTitle">Exibir Titulo</label>
              </div>
            </div>
            <div class="col-auto">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="checkbox" id="showDevices" checked>
                        <label class="form-check-label ml-2" for="showDevices">Exibir dispositivos</label>
                    </div>
                </div>
            <div class="col-auto">
              <button id="btnGenerate" class="btn btn-success">Gerar Banner</button>
              <button class="btn btn-warning ml-2" id="btnSalvarPrefs">💾 Salvar Preferências</button>
            </div>
          </div>
          <ul id="results" class="mb-3 d-flex flex-wrap"></ul>
          <canvas id="previewCanvas" class="d-block mx-auto mb-3" style="border:1px solid #ccc; display: none;"></canvas>
          <button id="btnDownload" class="btn btn-primary mr-2" style="display:none;">💾Baixar Banner</button>
          </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
<script src="assets/js/banner.js"></script>

<?php require("includes/footer.php"); ?>
