<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo e(isset($product) ? 'Edit Produk' : 'Tambah Produk Baru'); ?> | Admin Haji Apud</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body class="bg-stone-50 text-gray-800 font-sans min-h-screen flex items-center justify-center py-10">

    <div class="max-w-2xl w-full mx-4 bg-white rounded-3xl border border-stone-100 shadow-xl overflow-hidden">
        <div class="px-8 py-6 border-b border-stone-100 bg-stone-50 flex justify-between items-center">
            <h2 class="text-2xl font-bold text-gray-900">
                <?php echo e(isset($product) ? 'Edit Produk' : 'Tambah Produk Baru'); ?>

            </h2>
            <a href="<?php echo e(route('admin.dashboard')); ?>" class="text-stone-500 hover:text-red-600 transition-colors">
                <i class="fas fa-times text-xl"></i>
            </a>
        </div>

        <!-- Form Setup: Enctype multipart/form-data WAJIB untuk upload file -->
        <form action="<?php echo e(isset($product) ? route('admin.product.update', $product->id) : route('admin.product.store')); ?>" method="POST" enctype="multipart/form-data" class="p-8">
            <?php echo csrf_field(); ?>
            <?php if(isset($product)): ?>
                <?php echo method_field('PUT'); ?>
            <?php endif; ?>

            <div class="space-y-6">
                <div>
                    <label class="block text-sm font-bold text-stone-700 mb-2">Nama Produk</label>
                    <input type="text" name="name" value="<?php echo e(isset($product) ? $product->name : old('name')); ?>" class="w-full bg-stone-50 border border-stone-300 text-stone-900 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-amber-500" required>
                </div>

                <div class="grid grid-cols-2 gap-6">
                    <div>
                        <label class="block text-sm font-bold text-stone-700 mb-2">Harga (Rp)</label>
                        <input type="number" name="price" value="<?php echo e(isset($product) ? $product->price : old('price')); ?>" class="w-full bg-stone-50 border border-stone-300 text-stone-900 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-amber-500" required>
                    </div>
                    <div>
                        <label class="block text-sm font-bold text-stone-700 mb-2">Berat (Gram)</label>
                        <input type="number" name="weight" value="<?php echo e(isset($product) ? $product->weight : old('weight')); ?>" class="w-full bg-stone-50 border border-stone-300 text-stone-900 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-amber-500" required>
                    </div>
                </div>

                <!-- Input stok hanya muncul saat tambah baru, jika edit stok pakai form di dashboard -->
                <?php if(!isset($product)): ?>
                <div>
                    <label class="block text-sm font-bold text-stone-700 mb-2">Stok Awal</label>
                    <input type="number" name="stock" value="<?php echo e(old('stock', 0)); ?>" class="w-full bg-stone-50 border border-stone-300 text-stone-900 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-amber-500" required>
                </div>
                <?php endif; ?>

                <div>
                    <label class="block text-sm font-bold text-stone-700 mb-2">Upload Foto Produk</label>
                    <?php if(isset($product) && $product->image): ?>
                        <div class="mb-3">
                            <img src="<?php echo e(asset('storage/' . $product->image)); ?>" alt="Current Image" class="w-32 h-32 object-cover rounded-xl border border-stone-200">
                        </div>
                    <?php endif; ?>
                    <input type="file" name="image" accept="image/*" class="w-full bg-white border border-stone-300 text-stone-900 rounded-xl px-4 py-3 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-amber-50 file:text-amber-700 hover:file:bg-amber-100">
                    <p class="text-xs text-stone-500 mt-2">Format: JPG, PNG, JPEG. Maksimal 2MB.</p>
                </div>
            </div>

            <div class="mt-8 pt-6 border-t border-stone-100 flex justify-end gap-4">
                <a href="<?php echo e(route('admin.dashboard')); ?>" class="px-6 py-3 rounded-xl font-bold text-stone-600 hover:bg-stone-100 transition-colors">Batal</a>
                <button type="submit" class="bg-gray-950 hover:bg-terracotta-600 text-white px-8 py-3 rounded-xl font-bold transition-colors shadow-lg">
                    <?php echo e(isset($product) ? 'Simpan Perubahan' : 'Tambah Produk'); ?>

                </button>
            </div>
        </form>
    </div>

</body>
</html><?php /**PATH C:\Users\USER\Documents\web\hapudstore\haji-apud-store\resources\views/admin/product_form.blade.php ENDPATH**/ ?>