<?php
require_once 'config/koneksi.php';

$data = mysqli_query($conn,"
SELECT *
FROM rsvp
ORDER BY id DESC
");
?>

<section id="rsvp">

    <div class="container">

        <div class="section-title">

            <small>RSVP</small>

            <h2>Konfirmasi Kehadiran</h2>

            <p>
                Merupakan suatu kehormatan bagi kami apabila
                Bapak/Ibu/Saudara/i dapat hadir dan memberikan doa restu.
            </p>

        </div>

        <div class="row justify-content-center">

            <div class="col-lg-8">

                <div class="rsvp-card">

                    <form action="proses/rsvp.php" method="POST">

                        <div class="mb-3">

                            <input
                                type="text"
                                class="form-control"
                                name="nama"
                                placeholder="Nama Lengkap"
                                required>

                        </div>

                        <div class="mb-3">

                            <input
                                type="number"
                                class="form-control"
                                name="jumlah"
                                placeholder="Jumlah Tamu"
                                min="1"
                                required>

                        </div>

                        <div class="mb-3">

                            <select
                                class="form-select"
                                name="status"
                                required>

                                <option value="">
                                    Konfirmasi Kehadiran
                                </option>

                                <option value="Hadir">
                                    Hadir
                                </option>

                                <option value="Tidak Hadir">
                                    Tidak Hadir
                                </option>

                            </select>

                        </div>

                        <div class="mb-3">

                            <textarea

                                class="form-control"

                                rows="5"

                                name="pesan"

                                placeholder="Tulis ucapan dan doa..."

                                required></textarea>

                        </div>

                        <button class="btn-send">

                            <i class="fa-solid fa-paper-plane"></i>

                            Kirim Ucapan

                        </button>

                    </form>

                </div>

            </div>

        </div>

        <!-- UCAPAN -->

        <div class="comment-wrapper">

            <h3>Ucapan & Doa</h3>

            <?php while($d=mysqli_fetch_assoc($data)){ ?>

            <div class="comment-item">

                <h5>

                    <?= htmlspecialchars($d['nama']) ?>

                </h5>

                <span>

                    <?= htmlspecialchars($d['status']) ?>

                    •

                    <?= (int)$d['jumlah'] ?> Orang

                    •

                    <?= date('d M Y', strtotime($d['created_at'])) ?>

                </span>

                <p>

                    <?= nl2br(htmlspecialchars($d['pesan'])) ?>

                </p>

            </div>

            <?php } ?>

        </div>

    </div>

</section>