<?php include 'header_siswa.php'; ?>
<?php 
include 'koneksi.php';
$data = mysqli_query($koneksi, "SELECT * FROM guru");

// Mengecek apakah ada data yang ditemukan
$jumlah_data = mysqli_num_rows($data);
?>

<div class="container mt-3">
    <h2 class="text-center mb-3">Data Guru</h2>
    
    <?php if ($jumlah_data > 0): ?>
        <div class="table-wrapper">
            <table class="table custom-table">
                <thead>
                    <tr>
                        <th>NIP</th>
                        <th>Nama Guru</th>
                        <th>Alamat</th>
                        <th>No Handphone</th>
                    </tr>
                </thead>
                <tbody>
                    <?php while ($d = mysqli_fetch_array($data)) { ?>
                        <tr>
                            <td data-label="NIP"><?php echo $d['nip']; ?></td>
                            <td data-label="Nama Guru"><?php echo $d['nama_guru']; ?></td>
                            <td data-label="Alamat"><?php echo $d['alamat']; ?></td>
                            <td data-label="No Handphone"><?php echo $d['no_telepon']; ?></td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    <?php else: ?>
        <div class="alert alert-info text-center" role="alert">
            Belum Mendapatkan Prestasi Belajar Yang Giat ya?
        </div>
    <?php endif; ?>
</div>

<style>
:root {
    --primary-color: #007bff;
    --border-color: #dee2e6;
    --hover-bg: #f8f9fa;
    --header-bg: #007bff;
    --header-color: #ffffff;
}

/* Container Styles */
.container {
    padding: 15px;
    width: 100%;
    margin: 0 auto;
}

/* Table Wrapper */
.table-wrapper {
    width: 100%;
    justify-content: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
}

/* Table Styles */
.custom-table {
    width: 100%;
    min-width: 800px; /* Ensures horizontal scroll on small screens */
    margin-bottom: 0;
    background-color: white;
    border-collapse: collapse;
}

.custom-table thead {
    background-color: var(--header-bg);
}

.custom-table th {
    color: var(--header-color);
    font-weight: 500;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

.custom-table td {
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

.custom-table tbody tr:hover {
    background-color: var(--hover-bg);
}

/* Custom Scrollbar */
.table-wrapper::-webkit-scrollbar {
    height: 6px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #0056b3;
}

/* Mobile Styles - Maintains table format */
@media screen and (max-width: 768px) {
    .container {
        padding: 10px;
    }

    h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .table-wrapper {
        margin: 0px;
        border-radius: 0;
    }

    .custom-table {
        min-width: 600px; /* Adjust based on your needs */
    }

    .custom-table th,
    .custom-table td {
        padding: 10px;
        font-size: 0.9rem;
    }

    /* Alert for no data */
    .alert {
        margin: 10px;
        padding: 10px;
        font-size: 0.9rem;
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .table-wrapper {
        -webkit-overflow-scrolling: touch;
    }
}

/* Ensure table cells don't wrap */
.custom-table th,
.custom-table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Optional: Add scroll indicator */
.table-wrapper::after {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary-color);
    animation: scrollIndicator 1.5s infinite;
    opacity: 0;
}

@keyframes scrollIndicator {
    0% { opacity: 0; right: 10px; }
    50% { opacity: 1; right: 5px; }
    100% { opacity: 0; right: 10px; }
}

/* Show scroll indicator only when table is scrollable */
@media screen and (max-width: 768px) {
    .table-wrapper::after {
        opacity: 1;
    }
}
</style>

