<main id="main" class="main">
   <div class="pagetitle">
      <h1>Atur Situs</h1>
      <nav>
         <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="index.php">Home</a></li>
            <li class="breadcrumb-item active">Atur Situs</li>
         </ol>
      </nav>
   </div>
   <!-- End Page Title -->
   <section class="section dashboard">
      <div class="card recent-sales overflow-auto">
         <div class="filter">
            <!-- Modal Dialog Scrollable -->
         </div>
         <div class="card-body">
    <h5 class="card-title">Atur Situs</h5>
    <?php
    if (isset($_GET['notif'])) {
        if ($_GET['notif'] == "berhasil_tambah_data") {
            echo '
                <div class="alert alert-success" role="alert">
                    Berhasil menambahkan data.
                </div>
            ';
        } else if ($_GET['notif'] == "berhasil_ubah_data") {
            echo '
                <div class="alert alert-success" role="alert">
                    Berhasil mengubah data.
                </div>
            ';
        } else if ($_GET['notif'] == "berhasil_hapus_data") {
            echo '
                <div class="alert alert-success" role="alert">
                    Berhasil menghapus data.
                </div>
            ';
        }
    }
    ?>
    <?php
    include "koneksi.php";

    // Ambil data dari database
    $qry_hadiah = mysqli_query($koneksi, "SELECT * FROM atur_situs WHERE id='1'") or die("Query Error: " . mysqli_error($koneksi));
    $dt_bank = mysqli_fetch_array($qry_hadiah);

    // Mengambil nilai dari database atau mengatur nilai default
    $nama_situs = $dt_bank['nama_situs'] ?? '';
    $title_situs = $dt_bank['title_situs'] ?? '';
    $meta_deskripsi = $dt_bank['meta_deskripsi'] ?? '';
    $logo = $dt_bank['logo'] ?? '';
    $favicon = $dt_bank['favicon'] ?? '';
    $background_situs = $dt_bank['background_situs'] ?? '';
    $slider_banner = $dt_bank['slider_banner'] ?? '';
    $link_daftar = $dt_bank['link_daftar'] ?? '';
    $link_login = $dt_bank['link_login'] ?? '';
    $theme_color = $dt_bank['theme_color'] ?? '';
    $root_color = $dt_bank['root_color'] ?? '';  // Menambahkan pengecekan untuk root_color
    $marquee_text = $dt_bank['marquee_text'] ?? '';  // Menambahkan pengecekan untuk marquee_text
    ?>
    <form action="prs_ubah_web.php" method="post" enctype="multipart/form-data">
        <!-- Nama Situs -->
        <div class="form-group row mb-3">
            <label for="nama_situs" class="col-4 col-form-label">Nama Situs</label>
            <div class="col-8">
                <input id="nama_situs" name="nama_situs" value="<?php echo $nama_situs; ?>" type="text" class="form-control">
            </div>
        </div>
        <!-- Title Situs -->
        <div class="form-group row mb-3">
            <label for="title_situs" class="col-4 col-form-label">Title Situs</label>
            <div class="col-8">
                <input id="title_situs" name="title_situs" value="<?php echo $title_situs; ?>" type="text" class="form-control">
            </div>
        </div>
        <!-- Meta Deskripsi -->
        <div class="form-group row mb-3">
            <label for="meta_deskripsi" class="col-4 col-form-label">Meta Deskripsi</label>
            <div class="col-8">
                <textarea id="meta_deskripsi" name="meta_deskripsi" cols="40" rows="5" class="form-control"><?php echo $meta_deskripsi; ?></textarea>
            </div>
        </div>
        <!-- Logo -->
        <div class="form-group row">
            <label for="logo" class="col-4 col-form-label">Logo</label>
            <div class="col-8">
                <input id="logo" name="logo" type="file" class="form-control">
                <?php if ($logo): ?>
                    <br>
                    <small>File saat ini: <?php echo $logo; ?></small><br>
                    <img src="../img/<?php echo $logo; ?>" alt="Logo" style="max-width:150px;">
                <?php endif; ?>
            </div>
        </div>
        <!-- Favicon -->
        <div class="form-group row">
            <label for="favicon" class="col-4 col-form-label">Favicon</label>
            <div class="col-8">
                <input id="favicon" name="favicon" type="file" class="form-control">
                <?php if ($favicon): ?>
                    <br>
                    <small>File saat ini: <?php echo $favicon; ?></small><br>
                    <img src="../img/<?php echo $favicon; ?>" alt="Favicon" style="max-width:50px;">
                <?php endif; ?>
            </div>
        </div>
        <!-- Link Daftar -->
        <div class="form-group row mb-3">
            <label for="link_daftar" class="col-4 col-form-label">Link Daftar</label>
            <div class="col-8">
                <input id="link_daftar" name="link_daftar" type="url" class="form-control" value="<?php echo $link_daftar; ?>">
            </div>
        </div>
        <!-- Link Login -->
        <div class="form-group row mb-3">
            <label for="link_login" class="col-4 col-form-label">Link Login</label>
            <div class="col-8">
                <input id="link_login" name="link_login" type="url" class="form-control" value="<?php echo $link_login; ?>">
            </div>
        </div>
        <!-- Theme Color -->
        <div class="form-group row mb-3">
            <label for="theme_color" class="col-4 col-form-label">Pilih Tema Warna</label>
            <div class="col-8">
                <select id="theme_color" name="theme_color" class="form-control">
                    <option value="blue" <?= ($theme_color == 'blue') ? 'selected' : '' ?>>Blue</option>
                    <option value="dark" <?= ($theme_color == 'dark') ? 'selected' : '' ?>>Dark</option>
                    <option value="orange" <?= ($theme_color == 'orange') ? 'selected' : '' ?>>Orange</option>
                    <option value="green" <?= ($theme_color == 'green') ? 'selected' : '' ?>>Green</option>
                    <option value="purple" <?= ($theme_color == 'purple') ? 'selected' : '' ?>>Purple</option>
                    <option value="red" <?= ($theme_color == 'red') ? 'selected' : '' ?>>Red</option>
                </select>
            </div>
        </div>

        <!-- Hidden fields -->
        <div hidden>
            <!-- Hidden Link Klaim -->
            <input id="link_klaim" name="link_klaim" type="url" value="<?php echo $link_klaim; ?>">
            <!-- Hidden Marquee Text -->
            <textarea id="marquee_text" name="marquee_text" class="form-control"><?php echo $marquee_text; ?></textarea>
            <!-- Hidden Root Color -->
            <input id="root_color" name="root_color" type="text" class="form-control" value="<?php echo $root_color; ?>">
        </div>

        <!-- Submit Button -->
        <div class="form-group row mb-3">
            <div class="offset-4 col-8">
                <button name="submit" type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
    </form>
</div>

      </div>
   </section>
</main>
<!-- End #main -->