<?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 dark:text-gray-100 leading-tight">
            <?php echo e(__('Review Listings')); ?>

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

    <div class="py-12">
        <div class="max-w-4xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">

                    <div class="flex items-center justify-between mb-4">
                        <div>
                            <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100" id="item-count"><?php echo e(count($parsedItems)); ?> items</h3>
                            <p class="text-sm text-gray-500 dark:text-gray-400">Fix titles and prices right in the list. Open a row for description, condition, and category.</p>
                        </div>
                        <a href="<?php echo e(route('items.mass-listing')); ?>" class="text-sm text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200">&larr; Back to paste</a>
                    </div>

                    
                    <div class="flex flex-wrap items-center gap-3 mb-4 p-3 bg-gray-50 dark:bg-gray-900/50 rounded-md text-sm">
                        <span class="text-gray-600 dark:text-gray-400 font-medium">Apply to all:</span>
                        <select id="bulk-condition" class="border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm py-1">
                            <option value="">condition&hellip;</option>
                            <?php $__currentLoopData = ['New', 'Like New', 'Excellent', 'Very Good', 'Good', 'Fair', 'Poor']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $condition): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($condition); ?>"><?php echo e($condition); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <select id="bulk-category" class="border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm py-1">
                            <option value="">category&hellip;</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>

                    
                    <ul id="item-list" class="divide-y divide-gray-100 dark:divide-gray-700">
                        <?php $__currentLoopData = $parsedItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li class="item-row py-3" data-index="<?php echo e($index); ?>">
                            <div class="flex items-center gap-2">
                                <span class="text-gray-400 dark:text-gray-500 text-sm">$</span>
                                <input type="number" step="1" min="0" max="999999" value="<?php echo e(round($item['price'])); ?>"
                                    class="row-price w-24 border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm py-1.5">
                                <input type="text" value="<?php echo e($item['title']); ?>" maxlength="255"
                                    class="row-title flex-1 min-w-0 border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm py-1.5">
                                <button type="button" class="row-toggle text-xs text-indigo-600 dark:text-indigo-400 hover:text-indigo-800 dark:hover:text-indigo-300 font-medium shrink-0 px-1">
                                    Details
                                </button>
                                <button type="button" class="row-remove text-xs text-red-500 hover:text-red-700 dark:hover:text-red-400 font-medium shrink-0 px-1">
                                    Remove
                                </button>
                                <button type="button" class="row-undo hidden text-xs text-green-600 dark:text-green-400 hover:text-green-800 font-semibold shrink-0 px-1">
                                    Undo
                                </button>
                            </div>

                            <div class="row-details hidden mt-3 ml-6 grid grid-cols-1 sm:grid-cols-3 gap-3">
                                <div>
                                    <label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">Condition</label>
                                    <select class="row-condition w-full border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm py-1.5">
                                        <?php $__currentLoopData = ['New', 'Like New', 'Excellent', 'Very Good', 'Good', 'Fair', 'Poor']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $condition): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($condition); ?>" <?php echo e(($item['condition'] ?? 'Good') === $condition ? 'selected' : ''); ?>><?php echo e($condition); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div>
                                    <label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">Category</label>
                                    <select class="row-category w-full border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm py-1.5">
                                        <option value="">None</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-xs font-medium text-gray-500 dark:text-gray-400 mb-1">Quantity</label>
                                    <input type="number" min="1" max="999" value="<?php echo e($item['quantity'] ?? 1); ?>"
                                        class="row-quantity w-full border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm py-1.5">
                                </div>
                                <div class="sm:col-span-3">
                                    <label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">Description</label>
                                    <textarea rows="2" maxlength="10000"
                                        class="row-description w-full border-gray-300 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100 rounded-md text-sm"><?php echo e($item['description'] ?? ''); ?></textarea>
                                </div>
                            </div>
                        </li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </ul>

                    
                    <div id="empty-state" class="hidden py-8 text-center text-gray-400 dark:text-gray-500 text-sm">
                        All items removed. <a href="<?php echo e(route('items.mass-listing')); ?>" class="text-indigo-600 dark:text-indigo-400 hover:underline">Go back and paste more.</a>
                    </div>

                    
                    <div class="mt-6 flex flex-wrap items-center justify-between gap-3">
                        <p class="text-xs text-gray-400 dark:text-gray-500 max-w-xs">
                            Tip: drafts let you add photos before going live &mdash; listings with photos show up first in the marketplace.
                        </p>
                        <div class="flex items-center gap-3">
                            <button id="draft-btn" onclick="createAll('draft')"
                                class="inline-flex items-center px-4 py-2.5 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200 font-semibold text-sm rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-offset-2">
                                Save as drafts
                            </button>
                            <button id="publish-btn" onclick="createAll('active')"
                                class="inline-flex items-center px-5 py-2.5 bg-green-600 hover:bg-green-700 text-white font-semibold text-sm rounded-lg transition focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2">
                                Publish now
                            </button>
                        </div>
                    </div>

                    <p id="submit-error" class="hidden mt-3 text-sm text-red-600 dark:text-red-400 text-right"></p>
                </div>
            </div>
        </div>
    </div>

    <script>
        const rows = () => Array.from(document.querySelectorAll('.item-row'));
        const liveRows = () => rows().filter(row => row.dataset.deleted !== '1');

        function updateCount() {
            const remaining = liveRows().length;
            document.getElementById('item-count').textContent = remaining + (remaining === 1 ? ' item' : ' items');
            document.getElementById('empty-state').classList.toggle('hidden', remaining > 0);
            document.getElementById('draft-btn').disabled = remaining === 0;
            document.getElementById('publish-btn').disabled = remaining === 0;
        }

        document.getElementById('item-list').addEventListener('click', (e) => {
            const row = e.target.closest('.item-row');
            if (!row) return;

            if (e.target.classList.contains('row-toggle')) {
                row.querySelector('.row-details').classList.toggle('hidden');
            } else if (e.target.classList.contains('row-remove')) {
                row.dataset.deleted = '1';
                row.classList.add('opacity-40');
                row.querySelectorAll('input, select, textarea').forEach(el => el.disabled = true);
                row.querySelector('.row-details').classList.add('hidden');
                e.target.classList.add('hidden');
                row.querySelector('.row-undo').classList.remove('hidden');
                updateCount();
            } else if (e.target.classList.contains('row-undo')) {
                row.dataset.deleted = '';
                row.classList.remove('opacity-40');
                row.querySelectorAll('input, select, textarea').forEach(el => el.disabled = false);
                e.target.classList.add('hidden');
                row.querySelector('.row-remove').classList.remove('hidden');
                updateCount();
            }
        });

        document.getElementById('bulk-condition').addEventListener('change', (e) => {
            if (!e.target.value) return;
            liveRows().forEach(row => row.querySelector('.row-condition').value = e.target.value);
        });

        document.getElementById('bulk-category').addEventListener('change', (e) => {
            if (!e.target.value) return;
            liveRows().forEach(row => row.querySelector('.row-category').value = e.target.value);
        });

        function collectItems() {
            return liveRows().map(row => ({
                title: row.querySelector('.row-title').value.trim(),
                price: parseFloat(row.querySelector('.row-price').value),
                condition: row.querySelector('.row-condition').value,
                category_id: row.querySelector('.row-category').value || null,
                quantity: parseInt(row.querySelector('.row-quantity').value) || 1,
                description: row.querySelector('.row-description').value,
            }));
        }

        async function createAll(status) {
            const items = collectItems();
            const errorEl = document.getElementById('submit-error');
            errorEl.classList.add('hidden');

            const invalid = items.find(item => !item.title || isNaN(item.price) || item.price < 0);
            if (invalid) {
                errorEl.textContent = 'Every item needs a title and a price of $0 or more.';
                errorEl.classList.remove('hidden');
                return;
            }

            const draftBtn = document.getElementById('draft-btn');
            const publishBtn = document.getElementById('publish-btn');
            const activeBtn = status === 'draft' ? draftBtn : publishBtn;
            const originalText = activeBtn.textContent;
            draftBtn.disabled = publishBtn.disabled = true;
            activeBtn.textContent = status === 'draft' ? 'Saving…' : 'Publishing…';

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

                const result = await response.json();

                if (response.ok && result.success) {
                    window.location.href = result.redirect;
                    return;
                }

                errorEl.textContent = result.message
                    || (result.errors ? Object.values(result.errors)[0][0] : 'Something went wrong. Please try again.');
                errorEl.classList.remove('hidden');
            } catch (err) {
                errorEl.textContent = 'Something went wrong: ' + err.message;
                errorEl.classList.remove('hidden');
            }

            draftBtn.disabled = publishBtn.disabled = false;
            activeBtn.textContent = originalText;
        }
    </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-quick.blade.php ENDPATH**/ ?>