<?php include APP_PATH . '/views/layouts/header.php'; ?>

<div class="container-fluid">
    <!-- Page Header -->
    <div class="page-header">
        <h1>Dashboard</h1>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item active">Dashboard</li>
            </ol>
        </nav>
    </div>
    
    <!-- Statistics Cards -->
    <div class="row">
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card stat-card position-relative" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
                <h3><?php echo $totalUsers; ?></h3>
                <p>Total Users</p>
                <i class="bi bi-people"></i>
            </div>
        </div>
        
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card stat-card position-relative" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
                <h3><?php echo $totalContacts; ?></h3>
                <p>Total Contacts</p>
                <i class="bi bi-person-lines-fill"></i>
            </div>
        </div>
        
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card stat-card position-relative" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
                <h3><?php echo $totalTemplates; ?></h3>
                <p>Active Templates</p>
                <i class="bi bi-file-text"></i>
            </div>
        </div>
        
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card stat-card position-relative" style="background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);">
                <h3><?php echo $totalNotes; ?></h3>
                <p>Total Notes</p>
                <i class="bi bi-sticky"></i>
            </div>
        </div>
    </div>
    
    <!-- Today's Summary -->
    <div class="row">
        <div class="col-md-6 mb-4">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <span><i class="bi bi-cake2"></i> Today's Birthdays</span>
                    <span class="badge bg-primary"><?php echo $todayBirthdays; ?></span>
                </div>
                <div class="card-body">
                    <?php if ($todayBirthdays > 0): ?>
                        <p class="text-success mb-0">
                            <i class="bi bi-check-circle"></i> 
                            <?php echo $todayBirthdays; ?> birthday<?php echo $todayBirthdays > 1 ? 's' : ''; ?> today!
                        </p>
                    <?php else: ?>
                        <p class="text-muted mb-0">No birthdays today</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        
        <div class="col-md-6 mb-4">
            <div class="card">
                <div class="card-header d-flex align-items-center justify-content-between">
                    <span><i class="bi bi-bell"></i> Today's Reminders</span>
                    <span class="badge bg-warning"><?php echo $todayReminders; ?></span>
                </div>
                <div class="card-body">
                    <?php if ($todayReminders > 0): ?>
                        <p class="text-warning mb-0">
                            <i class="bi bi-exclamation-circle"></i> 
                            <?php echo $todayReminders; ?> reminder<?php echo $todayReminders > 1 ? 's' : ''; ?> today!
                        </p>
                    <?php else: ?>
                        <p class="text-muted mb-0">No reminders today</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Recent Contacts & Upcoming Birthdays -->
    <div class="row">
        <div class="col-lg-6 mb-4">
            <div class="card">
                <div class="card-header">
                    <i class="bi bi-clock-history"></i> Recent Contacts
                </div>
                <div class="card-body">
                    <?php if (!empty($recentContacts)): ?>
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Phone</th>
                                        <th>User</th>
                                        <th>Added</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($recentContacts as $contact): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($contact['full_name']); ?></td>
                                            <td><?php echo htmlspecialchars($contact['contact_number']); ?></td>
                                            <td><?php echo htmlspecialchars($contact['username']); ?></td>
                                            <td><?php echo formatDateTime($contact['created_at'], 'd M Y'); ?></td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else: ?>
                        <p class="text-muted mb-0">No contacts yet</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        
        <div class="col-lg-6 mb-4">
            <div class="card">
                <div class="card-header">
                    <i class="bi bi-calendar-event"></i> Upcoming Birthdays (Next 7 Days)
                </div>
                <div class="card-body">
                    <?php if (!empty($upcomingBirthdays)): ?>
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Date</th>
                                        <th>User</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($upcomingBirthdays as $birthday): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($birthday['full_name']); ?></td>
                                            <td><?php echo formatDate($birthday['next_birthday'], 'd M'); ?></td>
                                            <td><?php echo htmlspecialchars($birthday['username']); ?></td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else: ?>
                        <p class="text-muted mb-0">No upcoming birthdays in the next 7 days</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Quick Actions -->
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <i class="bi bi-lightning"></i> Quick Actions
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3 mb-3">
                            <a href="<?php echo URL_PATH; ?>/admin/contacts/create" class="btn btn-primary w-100">
                                <i class="bi bi-person-plus"></i> Add Contact
                            </a>
                        </div>
                        <div class="col-md-3 mb-3">
                            <a href="<?php echo URL_PATH; ?>/admin/templates/create" class="btn btn-info w-100">
                                <i class="bi bi-file-plus"></i> Add Template
                            </a>
                        </div>
                        <div class="col-md-3 mb-3">
                            <a href="<?php echo URL_PATH; ?>/admin/notes/create" class="btn btn-warning w-100">
                                <i class="bi bi-sticky"></i> Add Note
                            </a>
                        </div>
                        <div class="col-md-3 mb-3">
                            <a href="<?php echo URL_PATH; ?>/admin/excel" class="btn btn-success w-100">
                                <i class="bi bi-file-earmark-excel"></i> Import Excel
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include APP_PATH . '/views/layouts/footer.php'; ?>
