<?php include 'views/layout/header.php'; ?>

<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4 shadow-sm">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">User Panel</a>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav me-auto">
        <li class="nav-item"><a class="nav-link" href="<?php echo BASE_URL; ?>?page=user&action=dashboard">Dashboard</a></li>
        <li class="nav-item"><a class="nav-link" href="<?php echo BASE_URL; ?>?page=user&action=contacts">Contacts</a></li>
        <li class="nav-item"><a class="nav-link" href="<?php echo BASE_URL; ?>?page=user&action=template">Template</a></li>
        <li class="nav-item"><a class="nav-link active" href="<?php echo BASE_URL; ?>?page=user&action=birthdays">Today's Birthdays</a></li>
      </ul>
      <a href="<?php echo BASE_URL; ?>?page=auth&action=logout" class="btn btn-outline-danger btn-sm">Logout</a>
    </div>
  </div>
</nav>

<div class="card">
    <div class="card-header bg-success text-white">
        <h5 class="mb-0">Today's Birthdays (<?php echo date('d M Y'); ?>)</h5>
    </div>
    <div class="card-body">
        <?php if (!empty($birthdays)): ?>
            <div class="alert alert-info">
                Found <strong><?php echo count($birthdays); ?></strong> birthdays today.
            </div>

            <div class="table-responsive mb-4">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Mobile</th>
                            <th>Age Turning</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($birthdays as $bday):
                            $age = date('Y') - date('Y', strtotime($bday['dob']));
                        ?>
                            <tr>
                                <td><?php echo htmlspecialchars($bday['name']); ?></td>
                                <td><?php echo htmlspecialchars($bday['mobile']); ?></td>
                                <td><?php echo $age; ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>

            <form action="<?php echo BASE_URL; ?>?page=user&action=send_wishes" method="POST" id="sendWishesForm">
                <input type="hidden" name="message_type" id="messageType" value="">

                <div class="d-flex gap-3 mt-2">
                    <!-- WhatsApp Button -->
                    <button type="button"
                            id="btnWhatsApp"
                            class="btn btn-lg flex-fill send-btn"
                            style="background: linear-gradient(135deg, #25D366, #128C7E); color:#fff; border:none; border-radius:12px; font-weight:700; letter-spacing:.5px; box-shadow:0 4px 15px rgba(37,211,102,.35); transition: transform .15s, box-shadow .15s;"
                            onclick="submitWishes('whatsapp')">
                        <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="me-2" viewBox="0 0 16 16" style="vertical-align:middle">
                            <path d="M13.601 2.326A7.854 7.854 0 0 0 7.994 0C3.627 0 .068 3.558.064 7.926c0 1.399.366 2.76 1.057 3.965L0 16l4.204-1.102a7.933 7.933 0 0 0 3.79.965h.004c4.368 0 7.926-3.558 7.93-7.93A7.898 7.898 0 0 0 13.6 2.326zM7.994 14.521a6.573 6.573 0 0 1-3.356-.92l-.24-.144-2.494.654.666-2.433-.156-.251a6.56 6.56 0 0 1-1.007-3.505c0-3.626 2.957-6.584 6.591-6.584a6.56 6.56 0 0 1 4.66 1.931 6.557 6.557 0 0 1 1.928 4.66c-.004 3.639-2.961 6.592-6.592 6.592zm3.615-4.934c-.197-.099-1.17-.578-1.353-.646-.182-.065-.315-.099-.445.099-.133.197-.513.646-.627.775-.114.133-.232.148-.43.05-.197-.1-.836-.308-1.592-.985-.59-.525-.985-1.175-1.103-1.372-.114-.198-.011-.304.088-.403.087-.088.197-.232.296-.346.1-.114.133-.198.198-.33.065-.134.034-.248-.015-.347-.05-.099-.445-1.076-.612-1.47-.16-.389-.323-.335-.445-.34-.114-.007-.247-.007-.38-.007a.729.729 0 0 0-.529.247c-.182.198-.691.677-.691 1.654 0 .977.71 1.916.81 2.049.098.133 1.394 2.132 3.383 2.992.47.205.84.326 1.129.418.475.152.904.129 1.246.08.38-.058 1.171-.48 1.338-.943.164-.464.164-.86.114-.943-.049-.084-.182-.133-.38-.232z"/>
                        </svg>
                        Send via WhatsApp
                    </button>

                    <!-- Text SMS Button -->
                    <button type="button"
                            id="btnSMS"
                            class="btn btn-lg flex-fill send-btn"
                            style="background: linear-gradient(135deg, #4f46e5, #7c3aed); color:#fff; border:none; border-radius:12px; font-weight:700; letter-spacing:.5px; box-shadow:0 4px 15px rgba(79,70,229,.35); transition: transform .15s, box-shadow .15s;"
                            onclick="submitWishes('sms')">
                        <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="me-2" viewBox="0 0 16 16" style="vertical-align:middle">
                            <path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.5a1 1 0 0 0-.8.4l-1.9 2.533a1 1 0 0 1-1.6 0L5.3 12.4a1 1 0 0 0-.8-.4H2a2 2 0 0 1-2-2V2zm3.5 1a.5.5 0 0 0 0 1h9a.5.5 0 0 0 0-1h-9zm0 2.5a.5.5 0 0 0 0 1h9a.5.5 0 0 0 0-1h-9zm0 2.5a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1h-5z"/>
                        </svg>
                        Send via Text SMS
                    </button>
                </div>

                <div class="form-text text-center mt-2 text-muted">
                    Choose how you want to send birthday wishes to all above contacts.
                </div>
            </form>

            <script>
                function submitWishes(type) {
                    document.getElementById('messageType').value = type;
                    document.getElementById('sendWishesForm').submit();
                }

                // Hover lift effect
                document.querySelectorAll('.send-btn').forEach(function(btn) {
                    btn.addEventListener('mouseenter', function() {
                        this.style.transform = 'translateY(-2px)';
                        this.style.boxShadow = this.id === 'btnWhatsApp'
                            ? '0 8px 25px rgba(37,211,102,.5)'
                            : '0 8px 25px rgba(79,70,229,.5)';
                    });
                    btn.addEventListener('mouseleave', function() {
                        this.style.transform = 'translateY(0)';
                        this.style.boxShadow = this.id === 'btnWhatsApp'
                            ? '0 4px 15px rgba(37,211,102,.35)'
                            : '0 4px 15px rgba(79,70,229,.35)';
                    });
                });
            </script>

        <?php else: ?>
            <div class="text-center py-5">
                <h3 class="text-muted">No birthdays today! 🎉</h3>
                <p>Relax and enjoy your day.</p>
            </div>
        <?php endif; ?>
    </div>
</div>

<?php include 'views/layout/footer.php'; ?>
