<?php 
include 'db.php'; 
if(!isset($_SESSION['admin_id'])) { header("Location: login.php"); exit(); }
$id = $_GET['id'];
$item = $conn->query("SELECT * FROM items WHERE id = $id")->fetch_assoc();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Edit Item</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body class="bg-[#010409] text-white p-6">
    <div class="max-w-md mx-auto">
        <h1 class="text-xl font-bold text-cyan-500 mb-6">EDIT ITEM</h1>
        <form action="actions.php" method="POST" enctype="multipart/form-data" class="bg-[#0d1117] p-6 rounded-3xl border border-gray-800 space-y-4">
            <input type="hidden" name="id" value="<?php echo $item['id']; ?>">
            <img src="<?php echo $item['image_path']; ?>" class="w-20 h-20 rounded-xl mb-4 mx-auto object-cover">
            <input type="file" name="image" class="w-full text-xs">
            <input type="text" name="title" value="<?php echo htmlspecialchars($item['title']); ?>" required class="w-full bg-black border border-gray-700 rounded-xl p-3 outline-none text-sm">
            <input type="text" name="tags" value="<?php echo htmlspecialchars($item['tags']); ?>" required class="w-full bg-black border border-gray-700 rounded-xl p-3 outline-none text-sm">
            <input type="text" name="code" value="<?php echo htmlspecialchars($item['code']); ?>" required class="w-full bg-black border border-gray-700 rounded-xl p-3 outline-none text-sm font-bold text-green-500">
            <textarea name="description" rows="3" required class="w-full bg-black border border-gray-700 rounded-xl p-3 outline-none text-sm"><?php echo htmlspecialchars($item['description']); ?></textarea>
            <!-- ভ্যালু এডিট -->
            <label class="text-xs text-gray-500">Sort Value</label>
            <input type="number" name="sort_order" value="<?php echo $item['sort_order']; ?>" required class="w-full bg-black border border-gray-700 rounded-xl p-3 outline-none text-sm">
            <button type="submit" name="update_item" class="w-full bg-cyan-600 text-black font-bold py-3 rounded-xl">SAVE UPDATES</button>
        </form>
    </div>
</body>
</html>