<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Edit Produk | Admin Panel</title>
    <script src="https://cdn.tailwindcss.com"></script>
    
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <style> 
        body { font-family: 'Plus Jakarta Sans', sans-serif; background-color: #F1F4F9; }
        .form-input { background-color: #F8FAFD; border: 1px solid #E2E8F0; border-radius: 1rem; padding: 0.875rem 1.25rem; width: 100%; transition: all 0.2s; font-weight: 500; color: #1E293B; }
        .form-input:focus { outline: none; border-color: #3B82F6; background-color: #FFFFFF; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1); }
        .card-shadow { box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05); }
        /* Custom SweetAlert border radius biar senada dengan UI */
        div:where(.swal2-container) div:where(.swal2-popup) { border-radius: 1.5rem !important; font-family: 'Plus Jakarta Sans', sans-serif !important; }
    </style>
    <?php if (isset($component)) { $__componentOriginal95a0f28579ba3dc881cdd6af09f638a4 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal95a0f28579ba3dc881cdd6af09f638a4 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.pwa','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('pwa'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal95a0f28579ba3dc881cdd6af09f638a4)): ?>
<?php $attributes = $__attributesOriginal95a0f28579ba3dc881cdd6af09f638a4; ?>
<?php unset($__attributesOriginal95a0f28579ba3dc881cdd6af09f638a4); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal95a0f28579ba3dc881cdd6af09f638a4)): ?>
<?php $component = $__componentOriginal95a0f28579ba3dc881cdd6af09f638a4; ?>
<?php unset($__componentOriginal95a0f28579ba3dc881cdd6af09f638a4); ?>
<?php endif; ?>
</head>
<body class="antialiased text-gray-900 pb-20">
    <?php if (isset($component)) { $__componentOriginal84bc13f46ede078ae58666238de3da00 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal84bc13f46ede078ae58666238de3da00 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.loading','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('loading'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal84bc13f46ede078ae58666238de3da00)): ?>
<?php $attributes = $__attributesOriginal84bc13f46ede078ae58666238de3da00; ?>
<?php unset($__attributesOriginal84bc13f46ede078ae58666238de3da00); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal84bc13f46ede078ae58666238de3da00)): ?>
<?php $component = $__componentOriginal84bc13f46ede078ae58666238de3da00; ?>
<?php unset($__componentOriginal84bc13f46ede078ae58666238de3da00); ?>
<?php endif; ?>

    <div class="max-w-6xl mx-auto px-6 py-12">
        
        
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('success')): ?>
            <script>
                document.addEventListener('DOMContentLoaded', function() {
                    Swal.fire({
                        icon: 'success',
                        title: 'Berhasil!',
                        text: "<?php echo e(session('success')); ?>",
                        showConfirmButton: false,
                        timer: 2500,
                        background: '#ffffff',
                        iconColor: '#10B981'
                    });
                });
            </script>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

        <div class="flex justify-between items-start mb-10">
            <div>
                <h1 class="text-3xl font-extrabold text-[#1E293B] flex items-center gap-3">Edit Produk</h1>
                <p class="text-gray-400 font-medium mt-1">Perbarui informasi barang untuk pesanan *#<?php echo e($product->id); ?>*</p>
            </div>
            <a href="<?php echo e(route('admin.index')); ?>" class="flex items-center gap-2 text-gray-400 hover:text-blue-600 font-bold transition"><i class="fas fa-arrow-left"></i> Kembali</a>
        </div>

        
        <form action="<?php echo e(route('admin.update', $product->id)); ?>" method="POST" enctype="multipart/form-data">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>

            <div class="flex flex-col lg:flex-row gap-8">
                
                <div class="lg:w-1/3 space-y-8">
                    <div class="bg-white rounded-[2.5rem] p-8 card-shadow border border-white/50 text-center">
                        <label class="block text-[11px] font-black text-gray-300 uppercase tracking-widest mb-6">Foto Saat Ini</label>
                        <div class="relative group cursor-pointer">
                            <div class="aspect-square rounded-[2rem] overflow-hidden bg-gray-50 border border-gray-100 shadow-inner">
                                <img id="imgPreview" src="<?php echo e(asset('storage/' . $product->image)); ?>" class="w-full h-full object-cover">
                            </div>
                            <div class="absolute inset-0 bg-black/20 opacity-0 group-hover:opacity-100 transition-opacity rounded-[2rem] flex items-center justify-center">
                                <i class="fas fa-camera text-white text-2xl"></i>
                            </div>
                        </div>
                        <input type="file" name="image" id="fileInput" class="hidden" accept="image/*">
                    </div>

                    
                    <div class="bg-white rounded-[2.5rem] p-8 card-shadow border border-white/50 text-center relative overflow-hidden">
                        <label class="block text-[11px] font-black text-gray-400 uppercase tracking-widest mb-3">Status Ketersediaan</label>
                        
                        <p class="text-5xl font-black text-[#1E293B] mb-4"><?php echo e($product->stock ?? 0); ?> <span class="text-base text-gray-400 font-medium">Pcs</span></p>

                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(($product->stock ?? 0) > 0): ?>
                            <div class="inline-flex items-center gap-2 px-5 py-2.5 bg-green-50 text-green-600 rounded-xl font-bold text-sm border border-green-100">
                                Available
                            </div>
                            <input type="hidden" name="status" value="available">
                        <?php else: ?>
                            <div class="inline-flex items-center gap-2 px-5 py-2.5 bg-red-50 text-red-600 rounded-xl font-bold text-sm border border-red-100">
                                Sold Out
                            </div>
                            <input type="hidden" name="status" value="sold">
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                        <p class="text-[10px] text-gray-400 mt-5 leading-relaxed">*Status akan berubah otomatis mengikuti sisa stok di bawah.</p>
                    </div>
                </div>

                
                <div class="lg:w-2/3">
                    <div class="bg-white rounded-[3rem] p-10 lg:p-14 card-shadow border border-white/50 h-full">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                            <div class="md:col-span-2">
                                <label class="block text-[11px] font-black text-gray-300 uppercase tracking-widest mb-3 ml-1">Nama Produk</label>
                                <input type="text" name="name" value="<?php echo e($product->name); ?>" class="form-input text-lg" placeholder="Contoh: Jaket Vintage">
                            </div>

                            <div>
                                <label class="block text-[11px] font-black text-gray-300 uppercase tracking-widest mb-3 ml-1">Brand</label>
                                <input type="text" name="brand" value="<?php echo e($product->brand); ?>" class="form-input" placeholder="Nike, Adidas, etc.">
                            </div>

                            
                            <div>
                                <label class="block text-[11px] font-black text-gray-300 uppercase tracking-widest mb-3 ml-1">Kategori</label>
                                <select name="category_id" id="category" class="form-input appearance-none">
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($cat->id); ?>" data-name="<?php echo e($cat->name); ?>" <?php echo e($product->category_id == $cat->id ? 'selected' : ''); ?>>
                                            <?php echo e($cat->name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                </select>
                            </div>

                            
                            <div>
                                <label class="block text-[11px] font-black text-gray-300 uppercase tracking-widest mb-3 ml-1">Ukuran (Size)</label>
                                <select name="size" id="size" class="form-input appearance-none">
                                    
                                </select>
                            </div>

                            <div>
                                <label class="block text-[11px] font-black text-gray-300 uppercase tracking-widest mb-3 ml-1">Harga Jual (Rp)</label>
                                <input type="number" name="price" value="<?php echo e($product->price); ?>" class="form-input font-bold text-blue-600" placeholder="0">
                            </div>

                            <div class="md:col-span-2">
                                <label class="block text-[11px] font-black text-gray-300 uppercase tracking-widest mb-3 ml-1">Kondisi Barang</label>
                                <select name="condition" class="form-input appearance-none">
                                    <option value="Like New" <?php echo e($product->condition == 'Like New' ? 'selected' : ''); ?>>Like New (Seperti Baru)</option>
                                    <option value="Good" <?php echo e($product->condition == 'Good' ? 'selected' : ''); ?>>Good (Bagus)</option>
                                    <option value="Defect" <?php echo e($product->condition == 'Defect' ? 'selected' : ''); ?>>Defect (Ada Minus)</option>
                                </select>
                            </div>
                        </div>

                        <div class="mt-12 flex justify-end">
                            <button type="submit" class="bg-[#2563EB] hover:bg-[#1D4ED8] text-white font-black px-10 py-5 rounded-2xl shadow-xl shadow-blue-200 transition-all flex items-center gap-3 active:scale-95 uppercase tracking-widest text-sm">
                                <i class="fas fa-save"></i> Simpan Detail Produk
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </form>

        
        <div class="mt-16 pt-10 border-t-2 border-gray-200 border-dashed">
            <h2 class="text-2xl font-extrabold text-[#1E293B] flex items-center gap-3 mb-8">
                <i class="fas fa-boxes text-blue-500"></i> Inventori & Riwayat Stok
            </h2>
            
            <div class="flex flex-col lg:flex-row gap-8">
                
                
                <div class="lg:w-1/3">
                    <div class="bg-white rounded-[2.5rem] p-8 card-shadow border border-white/50 h-full">
                        <h3 class="text-sm font-bold text-gray-800 mb-6 flex items-center gap-2">
                            <i class="fas fa-plus-circle text-green-500"></i> Catat Stok Baru
                        </h3>
                        <form action="<?php echo e(route('admin.stock.add', $product->id)); ?>" method="POST" id="formTambahStok">
                            <?php echo csrf_field(); ?>
                            <div class="mb-4">
                                <label class="block text-[11px] font-black text-gray-400 uppercase tracking-widest mb-2 ml-1">Jumlah Masuk</label>
                                <input type="number" name="quantity" min="1" placeholder="Contoh: 10" required class="form-input">
                            </div>
                            <div class="mb-8">
                                <label class="block text-[11px] font-black text-gray-400 uppercase tracking-widest mb-2 ml-1">Keterangan Sumber</label>
                                <input type="text" name="description" placeholder="Cth: Restock Bal A..." required class="form-input">
                            </div>
                            <button type="submit" class="w-full bg-blue-50 text-blue-600 hover:bg-blue-600 hover:text-white font-bold py-4 rounded-xl transition text-sm flex items-center justify-center gap-2">
                                <i class="fas fa-check"></i> Simpan Stok Masuk
                            </button>
                        </form>
                    </div>
                </div>

                
                <div class="lg:w-2/3">
                    <div class="bg-white rounded-[3rem] p-8 lg:p-10 card-shadow border border-white/50 h-full overflow-hidden">
                        <div class="overflow-x-auto">
                            <table class="w-full text-left">
                                <thead>
                                    <tr class="text-gray-400 text-[10px] uppercase tracking-widest border-b-2 border-gray-100">
                                        <th class="pb-4 font-black">Tanggal</th>
                                        <th class="pb-4 font-black">Tipe</th>
                                        <th class="pb-4 font-black text-center">Jumlah</th>
                                        <th class="pb-4 font-black">Keterangan</th>
                                    </tr>
                                </thead>
                                <tbody class="divide-y divide-gray-50">
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(isset($product->logs) && $product->logs->count() > 0): ?>
                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $product->logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr class="hover:bg-gray-50 transition">
                                            <td class="py-4 text-gray-500 text-xs font-medium"><?php echo e($log->created_at->format('d M Y, H:i')); ?></td>
                                            <td class="py-4">
                                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($log->type == 'in'): ?>
                                                    <span class="px-3 py-1 bg-green-50 text-green-600 text-[10px] font-black rounded-lg"><i class="fas fa-arrow-down mr-1"></i> IN</span>
                                                <?php else: ?>
                                                    <span class="px-3 py-1 bg-red-50 text-red-600 text-[10px] font-black rounded-lg"><i class="fas fa-arrow-up mr-1"></i> OUT</span>
                                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                            </td>
                                            <td class="py-4 text-center font-bold text-sm <?php echo e($log->type == 'in' ? 'text-green-600' : 'text-red-600'); ?>">
                                                <?php echo e($log->type == 'in' ? '+' : '-'); ?><?php echo e($log->quantity); ?>

                                            </td>
                                            <td class="py-4 text-gray-700 text-sm font-medium"><?php echo e($log->description); ?></td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    <?php else: ?>
                                        <tr>
                                            <td colspan="4" class="py-12 text-center text-gray-400 text-sm font-medium">Belum ada riwayat stok tercatat.</td>
                                        </tr>
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

            </div>
        </div>

    </div>

    
    <script>
        // 1. Gambar
        document.querySelector('.group.cursor-pointer').addEventListener('click', () => document.getElementById('fileInput').click());
        const fileInput = document.getElementById('fileInput');
        const imgPreview = document.getElementById('imgPreview');
        fileInput.onchange = evt => {
            const [file] = fileInput.files;
            if (file) imgPreview.src = URL.createObjectURL(file);
        }

        // 2. Logic Ukuran (Create & Load)
        document.addEventListener('DOMContentLoaded', function () {
            const categorySelect = document.getElementById('category');
            const sizeSelect = document.getElementById('size');
            
            // Ambil data ukuran saat ini dari database
            const currentSize = "<?php echo e($product->size); ?>"; 

            const sizeOptions = {
                'Sepatu': ['36', '37', '38', '39', '40', '41', '42', '43', '44', '45'],
                'Celana': ['27', '28', '29', '30', '31', '32', '33', '34', '36', '38'],
                'Topi':   ['All Size'],
                'Default': ['XS', 'S', 'M', 'L', 'XL', 'XXL']
            };

            function updateSizes(selectedSize = null) {
                const selectedOption = categorySelect.options[categorySelect.selectedIndex];
                const categoryName = selectedOption.getAttribute('data-name');
                
                let options = sizeOptions['Default'];
                if (categoryName && categoryName.includes('Sepatu')) options = sizeOptions['Sepatu'];
                else if (categoryName && categoryName.includes('Celana')) options = sizeOptions['Celana'];
                else if (categoryName && categoryName.includes('Topi')) options = sizeOptions['Topi'];

                sizeSelect.innerHTML = '';
                options.forEach(size => {
                    const opt = document.createElement('option');
                    opt.value = size;
                    opt.textContent = size;
                    if (selectedSize && size === selectedSize) opt.selected = true;
                    sizeSelect.appendChild(opt);
                });
            }

            // Jalankan saat load (bawa size lama)
            updateSizes(currentSize);

            // Jalankan saat user ganti kategori (reset size)
            categorySelect.addEventListener('change', () => updateSizes(null));
        });
    </script>
</body>
</html><?php /**PATH C:\laragon\www\thrift-store\resources\views/admin/edit.blade.php ENDPATH**/ ?>