<?php
include('../includes/config.php');

if(!isset($_GET['id'])){
    die("ID tidak ditemukan");
}

$id = intval($_GET['id']);

$data = mysqli_fetch_assoc(mysqli_query($conn,"
    SELECT p.*, pm.bukti_pembayaran 
    FROM pesanan p
    LEFT JOIN pembayaran pm ON pm.id_pesanan = p.id
    WHERE p.id = '$id'
"));
?>
<!DOCTYPE html>
<html>
<head>
<title>Verifikasi Pembayaran</title>
<style>
body{font-family:'Poppins';background:#f5f5f5;padding:20px;}
.container{background:white;padding:20px;border-radius:10px;max-width:500px;margin:auto;}
input,textarea{width:100%;padding:8px;margin-top:8px;border-radius:6px;border:1px solid #ccc;}
button{padding:10px 15px;border:none;border-radius:6px;color:white;font-weight:bold;cursor:pointer;}
.btn-approve{background:#0288d1;}
.btn-reject{background:#d32f2f;}
</style>
</head>
<body>

<div class="container">
<h2>Verifikasi Pembayaran</h2>

<p><b>No Pesanan:</b> <?= $data['no_pesanan'] ?></p>
<p><b>Total:</b> Rp <?= number_format($data['total'],0,",",".") ?></p>

<p><b>Bukti Pembayaran:</b></p>
<?php if($data['bukti_pembayaran']) { ?>
    <img src="../<?= $data['bukti_pembayaran'] ?>" width="200">
<?php } else { echo "Tidak ada bukti"; } ?>

<hr>

<h3>Approve Pesanan</h3>
<form action="pengiriman.php" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="id" value="<?= $id ?>">

    <label>Upload Foto Pengiriman</label>
    <input type="file" name="foto_kirim" required>

    <label>No Resi</label>
    <input type="text" name="no_resi" required>

    <button type="submit" name="approve" class="btn-approve">Approve</button>
</form>

<hr>

<h3>Tolak Pesanan</h3>
<form action="pengiriman.php" method="POST">
    <input type="hidden" name="id" value="<?= $id ?>">

    <label>Alasan Penolakan</label>
    <textarea name="alasan" required></textarea>

    <button type="submit" name="reject" class="btn-reject">Tolak</button>
</form>

</div>

</body>
</html>
