<?php
include 'koneksi.php';
include 'header_pelanggan.php';
$id_pelanggan = 1; // Contoh, ambil dari sesi login

$query = "SELECT p.id_pesanan, s.nama_servis, s.harga, p.tanggal_pesan, p.status
          FROM tbl_pesanan p
          JOIN tbl_servis s ON p.id_servis = s.id_servis
          WHERE p.id_pelanggan = '$id_pelanggan'";
$result = mysqli_query($koneksi, $query);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Status Pesanan</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f9f9f9;
        }
        h2 {
            text-align: center;
            color: #4CAF50;
        }
        table {
            width: 80%;
            margin: 20px auto;
            border-collapse: collapse;
            background: white;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        th, td {
            padding: 12px;
            text-align: center;
            border: 1px solid #ddd;
        }
        th {
            background-color: #4CAF50;
            color: white;
        }
        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #ddd;
        }
        .status {
            font-weight: bold;
            padding: 5px 10px;
            border-radius: 5px;
            color: white;
            background-color: #333; /* Status warna hitam */
        }
        .button-container {
            text-align: center;
            margin: 20px 0;
        }
        .button-container a {
            text-decoration: none;
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border-radius: 5px;
            font-size: 14px;
            font-weight: bold;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            transition: background-color 0.3s;
        }
        .button-container a:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <h2>Status Pesanan Anda</h2>
    <table>
        <tr>
            <th>ID Pesanan</th>
            <th>Servis</th>
            <th>Harga</th>
            <th>Tanggal Pesan</th>
            <th>Status</th>
            <th>Aksi</th> <!-- Kolom Aksi -->
        </tr>
        <?php while ($row = mysqli_fetch_assoc($result)) { ?>
            <tr>
                <td><?= $row['id_pesanan']; ?></td>
                <td><?= $row['nama_servis']; ?></td>
                <td>Rp<?= number_format($row['harga'], 0, ',', '.'); ?></td>
                <td><?= date('d-m-Y', strtotime($row['tanggal_pesan'])); ?></td>
                <td><span class="status"><?= $row['status']; ?></span></td>
                <td>
                    <!-- Link ke halaman pembayaran -->
                    <?php if ($row['status'] == 'Belum Dibayar') { ?>
                        <a href="pembayaran.php?id_pesanan=<?= $row['id_pesanan']; ?>">Bayar</a>
                    <?php } else { ?>
                        <span>Sudah Dibayar</span>
                    <?php } ?>
                </td>
            </tr>
        <?php } ?>
    </table>

    <div class="button-container">
        <a href="home_pelanggan.php">Kembali ke Home</a>
    </div>
</body>
</html>
