<?php
include 'header.php';
include '../koneksi/koneksi.php';

$id = $_GET['id'];
$result = mysqli_query($conn, "SELECT * FROM admin WHERE id = '$id'");
$row = mysqli_fetch_assoc($result);
?>

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Master Produk - UMKM Galeri 3D</title>
<style>
body {
    background: #f3f4f6;
    font-family: 'Poppins', sans-serif;
    margin: 0;
    padding: 0;
}
.container {
  	max-width: 1200px;
    margin: 5px auto;
    padding: 0 30px;
}
/* Umum (untuk semua perangkat) */
.button-row .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
}

/* Untuk tampilan HP (maksimal 767px) */
@media (max-width: 767px) {
  .button-row {
    display: block;
    margin-top: 15px;
  }
  .button-row .col-md-6 {
    width: 100%;
    padding: 0 10px;
  }
  .button-row .btn {
    width: 100%;
    margin-bottom: 10px;
  }
}

/* Untuk tampilan Desktop (min 768px) */
@media (min-width: 768px) {
  .button-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    margin-bottom: 40px;
  }
  .button-row .col-md-6 {
    flex: 0 0 48%;
  }
}
</style>
</head>
<body>
<div class="container">
   	<h2 style=" width: 100%; border-bottom: 4px solid gray"><b>Edit Admin</b></h2>

    <form action="proses/edit_admin.php" method="post">
        <input type="hidden" name="id" value="<?= $row['id']; ?>">
        
        <div class="row">
        <!-- Kolom kiri -->
        <div class="col-md-6">
            <div class="form-group">
                <label>Nama Toko</label>
                <input type="text" name="nama_toko" class="form-control" 
                       value="<?= $row['nama_toko']; ?>" required>
            </div>

             <div class="form-group">
                <label>Username</label>
                <input type="text" name="username" class="form-control" 
                       value="<?= $row['username']; ?>" required>
            </div>

            <div class="form-group">
                <label>Level</label>
                <select class="form-control" name="level" required>
                    <option value="">-- Pilih level --</option>
                    <option value="admin" <?= ($row['level'] == 'admin') ? 'selected' : ''; ?>>Admin</option>
                    <option value="kasir" <?= ($row['level'] == 'kasir') ? 'selected' : ''; ?>>Kasir</option>
                    <option value="cabang" <?= ($row['level'] == 'cabang') ? 'selected' : ''; ?>>cabang</option>
                </select>
            </div>
        </div>

        <!-- Kolom kanan -->
        <div class="col-md-6">
            <div class="form-group">
                <label>Nama Admin</label>
                <input type="text" name="nama_admin" class="form-control" 
                       value="<?= $row['nama_admin']; ?>" required>
            </div>

            <div class="form-group">
                <label>Password (biarkan kosong jika tidak ingin diubah)</label>
                <input type="password" name="password" class="form-control">
            </div>
        </div>
    </div>
		<div class="row button-row" style="margin-top: 20px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 40px;">
			<div class="col-md-6 mb-2">
				<button type="submit" class="btn btn-warning btn-block">
				<i class="glyphicon glyphicon-edit"></i> Edit
				</button>
			</div>
			<div class="col-md-6 mb-2">
				<a href="m_admin.php" class="btn btn-danger btn-block">
				<i class="glyphicon glyphicon-remove"></i> Cancel
				</a>
			</div>
		</div>
    </form>

</div>

</body>
</html>