<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            <?php echo e(__('Review Parsed Items')); ?>

        </h2>
     <?php $__env->endSlot(); ?>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="mb-6">
                <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                    <div class="p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <h3 class="text-lg font-semibold text-gray-900"><?php echo e(count($parsedItems)); ?> Items Parsed</h3>
                                <p class="text-sm text-gray-600">Review and edit the items below, then create them as drafts.</p>
                            </div>
                            <div class="flex space-x-3">
                                <a href="<?php echo e(route('items.mass-listing')); ?>" class="inline-flex items-center px-4 py-2 bg-gray-300 border border-transparent rounded-md font-semibold text-xs text-gray-700 uppercase tracking-widest hover:bg-gray-400 transition ease-in-out duration-150">
                                    Back to Import
                                </a>
                                <button onclick="createAllDraftsSimple()" class="inline-flex items-center px-4 py-2 bg-green-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-green-700 transition ease-in-out duration-150">
                                    Create All as Drafts
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="space-y-6">
                <?php $__currentLoopData = $parsedItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                        <div class="p-6">
                            <form id="item-form-<?php echo e($index); ?>" class="space-y-4">
                                <div class="flex items-center justify-between mb-4">
                                    <h4 class="text-lg font-medium text-gray-900">Item <?php echo e($index + 1); ?></h4>
                                    <div class="flex space-x-2">
                                        <button type="button" onclick="createSingleDraft(<?php echo e($index); ?>)" class="inline-flex items-center px-3 py-1 bg-blue-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-blue-700 transition ease-in-out duration-150">
                                            Create Draft
                                        </button>
                                        <button type="button" onclick="removeItem(<?php echo e($index); ?>)" class="inline-flex items-center px-3 py-1 bg-red-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-red-700 transition ease-in-out duration-150">
                                            Remove
                                        </button>
                                    </div>
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Title</label>
                                        <input type="text" name="title" value="<?php echo e($item['title']); ?>" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                    </div>
                                    
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Price ($)</label>
                                        <input type="number" name="price" value="<?php echo e($item['price']); ?>" step="0.01" min="0" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                    </div>
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Manufacturer</label>
                                        <input type="text" name="manufacturer" value="<?php echo e($item['manufacturer']); ?>" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500" placeholder="Auto-detected or manual entry">
                                    </div>
                                    
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Model</label>
                                        <input type="text" name="model" value="<?php echo e($item['model']); ?>" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                    </div>

                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Condition</label>
                                        <select name="condition" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                            <option value="New" <?php echo e($item['condition'] == 'New' ? 'selected' : ''); ?>>New</option>
                                            <option value="Like New" <?php echo e($item['condition'] == 'Like New' ? 'selected' : ''); ?>>Like New</option>
                                            <option value="Excellent" <?php echo e($item['condition'] == 'Excellent' ? 'selected' : ''); ?>>Excellent</option>
                                            <option value="Very Good" <?php echo e($item['condition'] == 'Very Good' ? 'selected' : ''); ?>>Very Good</option>
                                            <option value="Good" <?php echo e($item['condition'] == 'Good' ? 'selected' : ''); ?>>Good</option>
                                            <option value="Fair" <?php echo e($item['condition'] == 'Fair' ? 'selected' : ''); ?>>Fair</option>
                                            <option value="Poor" <?php echo e($item['condition'] == 'Poor' ? 'selected' : ''); ?>>Poor</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Category</label>
                                        <select name="category_id" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                            <option value="">Select category (optional)</option>
                                            <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>

                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Quantity</label>
                                        <input type="number" name="quantity" value="<?php echo e($item['quantity']); ?>" min="1" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                    </div>
                                </div>

                                <div>
                                    <label class="block text-sm font-medium text-gray-700">Description</label>
                                    <textarea name="description" rows="4" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500"><?php echo e($item['description']); ?></textarea>
                                </div>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <div>
                                        <label class="block text-sm font-medium text-gray-700">Listing Type</label>
                                        <select name="listing_type" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                            <option value="sale" <?php echo e($item['listing_type'] == 'sale' ? 'selected' : ''); ?>>For Sale</option>
                                            <option value="inventory_open" <?php echo e($item['listing_type'] == 'inventory_open' ? 'selected' : ''); ?>>Personal Inventory + Open to Offers</option>
                                            <option value="inventory" <?php echo e($item['listing_type'] == 'inventory' ? 'selected' : ''); ?>>Personal Inventory (Private)</option>
                                        </select>
                                    </div>

                                    <div class="flex items-center space-x-4 pt-6">
                                        <label class="flex items-center">
                                            <input type="checkbox" name="open_to_trades" value="1" <?php echo e($item['open_to_trades'] ? 'checked' : ''); ?> class="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500">
                                            <span class="ml-2 text-sm text-gray-700">Open to trades</span>
                                        </label>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            <?php if(empty($parsedItems)): ?>
                <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                    <div class="p-6 text-center">
                        <p class="text-gray-500">No items were found to review.</p>
                        <a href="<?php echo e(route('items.mass-listing')); ?>" class="mt-4 inline-flex items-center px-4 py-2 bg-blue-600 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-blue-700 transition ease-in-out duration-150">
                            Import Items
                        </a>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>

    <script>
        function createSingleDraft(index) {
            const form = document.getElementById(`item-form-${index}`);
            const formData = new FormData(form);
            
            createDraft(formData).then(response => {
                if (response.success) {
                    // Remove the item from view
                    form.closest('.bg-white').remove();
                    showNotification('Draft created successfully!', 'success');
                } else {
                    showNotification('Error creating draft: ' + response.message, 'error');
                }
            });
        }

        function createAllDrafts() {
            const forms = document.querySelectorAll('[id^="item-form-"]');
            let completed = 0;
            let total = forms.length;

            if (total === 0) {
                showNotification('No items to create', 'error');
                return;
            }

            forms.forEach((form, index) => {
                const formData = new FormData(form);
                
                createDraft(formData).then(response => {
                    completed++;
                    
                    if (response.success) {
                        form.closest('.bg-white').style.opacity = '0.5';
                    }
                    
                    if (completed === total) {
                        showNotification(`Created ${total} draft items!`, 'success');
                        setTimeout(() => {
                            window.location.href = '<?php echo e(route("items.my-drafts")); ?>';
                        }, 2000);
                    }
                });
            });
        }

        function removeItem(index) {
            if (confirm('Remove this item from the list?')) {
                document.getElementById(`item-form-${index}`).closest('.bg-white').remove();
                showNotification('Item removed', 'success');
            }
        }

        async function createDraft(formData) {
            // Add CSRF token and action
            formData.append('_token', '<?php echo e(csrf_token()); ?>');
            formData.append('action', 'draft');

            try {
                const response = await fetch('<?php echo e(route("my-items.store")); ?>', {
                    method: 'POST',
                    body: formData,
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest'
                    }
                });

                const responseText = await response.text();
                console.log('Response:', responseText);

                if (response.ok) {
                    return { success: true };
                } else {
                    return { success: false, message: `HTTP ${response.status}: ${responseText}` };
                }
            } catch (error) {
                console.error('Fetch error:', error);
                return { success: false, message: error.message };
            }
        }

        async function createAllDraftsSimple() {
            try {
                const response = await fetch('<?php echo e(route("items.create-all-drafts")); ?>', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>',
                        'X-Requested-With': 'XMLHttpRequest'
                    }
                });

                const result = await response.json();
                
                if (result.success) {
                    showNotification(`Created ${result.created} draft items!`, 'success');
                    setTimeout(() => {
                        window.location.href = '<?php echo e(route("items.my-drafts")); ?>';
                    }, 2000);
                } else {
                    showNotification('Error: ' + result.message, 'error');
                }
            } catch (error) {
                showNotification('Error creating drafts: ' + error.message, 'error');
            }
        }

        function showNotification(message, type) {
            // Create notification element
            const notification = document.createElement('div');
            notification.className = `fixed top-4 right-4 z-50 px-4 py-2 rounded-md text-white ${type === 'success' ? 'bg-green-600' : 'bg-red-600'}`;
            notification.textContent = message;
            
            document.body.appendChild(notification);
            
            // Remove after 3 seconds
            setTimeout(() => {
                notification.remove();
            }, 3000);
        }
    </script>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?><?php /**PATH /var/www/html/resources/views/items/review-mass-listing.blade.php ENDPATH**/ ?>