<?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-200 leading-tight">
            <?php echo e(__('Manage Buyer Queue')); ?>

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

    <div class="py-12">
        <div class="max-w-4xl mx-auto sm:px-6 lg:px-8">
            <!-- Item Summary -->
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg mb-8">
                <div class="p-6">
                    <div class="flex items-start space-x-4">
                        <div class="w-24 h-24 bg-gray-200 dark:bg-gray-700 rounded-lg overflow-hidden flex-shrink-0">
                            <?php if($item->primaryPhoto): ?>
                                <img src="<?php echo e(asset($item->primaryPhoto->url)); ?>" alt="<?php echo e($item->title); ?>" class="w-full h-full object-cover">
                            <?php else: ?>
                                <div class="w-full h-full flex items-center justify-center">
                                    <span class="text-gray-400 dark:text-gray-500 text-xs">No Image</span>
                                </div>
                            <?php endif; ?>
                        </div>
                        <div class="flex-1">
                            <h1 class="text-2xl font-bold text-gray-900 dark:text-gray-100"><?php echo e($item->title); ?></h1>
                            <?php if($item->category): ?>
                                <p class="text-gray-600 dark:text-gray-400"><?php echo e($item->category->name); ?></p>
                            <?php endif; ?>
                            <p class="text-2xl font-bold text-gray-900 dark:text-gray-100 mt-2">$<?php echo e(number_format($item->price, 2)); ?></p>
                            <div class="flex items-center space-x-4 mt-4">
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300">
                                    <?php echo e(ucfirst(str_replace('_', ' ', $item->status))); ?>

                                </span>
                                <a href="<?php echo e(route('items.show', $item)); ?>" class="text-xs text-gray-600 dark:text-gray-400 hover:opacity-60 transition-opacity">
                                    View Public Listing →
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <?php if($item->buyQueue->count() > 0): ?>
                <!-- Buyer Queue -->
                <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                    <div class="p-6">
                        <div class="flex justify-between items-center mb-6">
                            <h2 class="text-xl font-bold text-gray-900 dark:text-gray-100">Buyer Queue (<?php echo e($item->buyQueue->count()); ?> interested buyers)</h2>
                            <p class="text-sm text-gray-600 dark:text-gray-400">Manage your buyers and complete the sale</p>
                        </div>

                        <div class="space-y-4">
                            <?php $__currentLoopData = $item->buyQueue; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $queue): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="border border-gray-200 dark:border-gray-700 rounded-lg p-4 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
                                    <div class="flex items-center justify-between">
                                        <div class="flex items-center space-x-4">
                                            <div class="w-12 h-12 bg-gray-100 dark:bg-gray-700 rounded-full flex items-center justify-center">
                                                <span class="text-gray-700 dark:text-gray-300 font-bold"><?php echo e($queue->position); ?></span>
                                            </div>
                                            <div>
                                                <h3 class="font-semibold text-gray-900 dark:text-gray-100"><?php echo e($queue->user->name); ?></h3>
                                                <p class="text-sm text-gray-600 dark:text-gray-400"><?php echo e($queue->user->email); ?></p>
                                                <p class="text-xs text-gray-500 dark:text-gray-400">
                                                    <?php if($queue->position === 1): ?>
                                                        Primary buyer
                                                    <?php else: ?>
                                                        Backup buyer #<?php echo e($queue->position - 1); ?>

                                                    <?php endif; ?>
                                                    • Joined <?php echo e($queue->created_at->diffForHumans()); ?>

                                                </p>
                                            </div>
                                        </div>
                                        
                                        <div class="flex items-center space-x-3">
                                            <!-- Message Buyer -->
                                            <button onclick="messageUser('<?php echo e($queue->user->id); ?>', '<?php echo e($queue->user->name); ?>', '<?php echo e($item->id); ?>')" class="inline-flex items-center px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
                                                <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path>
                                                </svg>
                                                Message
                                            </button>

                                            <!-- Sell to This Buyer -->
                                            <button onclick="showSellModal('<?php echo e($queue->user->id); ?>', '<?php echo e($queue->user->name); ?>', '<?php echo e($queue->position); ?>')" class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 transition ease-in-out duration-150">
                                                <?php if($queue->position === 1): ?>
                                                    Sell to Primary Buyer
                                                <?php else: ?>
                                                    Sell to This Buyer
                                                <?php endif; ?>
                                            </button>

                                            <!-- Remove from Queue -->
                                            <form method="POST" action="<?php echo e(route('items.queue.remove', [$item, $queue->user])); ?>" class="inline" onsubmit="return confirm('Remove <?php echo e($queue->user->name); ?> from the queue? They will be notified<?php echo e($queue->position === 1 && $item->buyQueue->count() > 1 ? ', and the next buyer will be promoted to primary' : ''); ?>.')">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('DELETE'); ?>
                                                <button type="submit" class="inline-flex items-center px-3 py-2 border border-red-200 rounded-md text-sm font-medium text-red-600 bg-white dark:bg-gray-800 hover:bg-red-50 transition-colors">
                                                    Remove
                                                </button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>

                        <!-- Tips for Sellers -->
                        <div class="mt-8 bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-4">
                            <h4 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Tips for Managing Your Sale:</h4>
                            <ul class="text-sm text-gray-700 dark:text-gray-300 space-y-1">
                                <li>• Contact the primary buyer first to arrange payment and delivery</li>
                                <li>• Only mark as "sold" once you've received payment</li>
                                <li>• If the primary buyer doesn't respond, try the backup buyers in order</li>
                                <li>• Use the messaging system to keep all communication documented</li>
                            </ul>
                        </div>
                    </div>
                </div>
            <?php else: ?>
                <!-- No Buyers -->
                <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                    <div class="p-6 text-center">
                        <svg class="mx-auto h-12 w-12 text-gray-400 dark:text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM9 9a2 2 0 11-4 0 2 2 0 014 0z"></path>
                        </svg>
                        <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2 mt-4">No interested buyers yet</h3>
                        <p class="text-gray-600 dark:text-gray-400 mb-6">When buyers commit to purchasing your item, they'll appear here in order.</p>
                        
                        <div class="flex justify-center space-x-4">
                            <a href="<?php echo e(route('items.show', $item)); ?>" class="inline-flex items-center px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-md font-semibold text-xs text-gray-700 dark:text-gray-300 uppercase tracking-widest hover:bg-gray-50 dark:hover:bg-gray-700 transition ease-in-out duration-150">
                                View Public Listing
                            </a>
                            <a href="<?php echo e(route('my-items.edit', $item)); ?>" class="inline-flex items-center px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-md font-semibold text-xs text-gray-700 dark:text-gray-300 uppercase tracking-widest hover:bg-gray-50 dark:hover:bg-gray-700 transition ease-in-out duration-150">
                                Edit Listing
                            </a>
                        </div>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Sell Modal -->
    <div id="sellModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 hidden items-center justify-center z-50">
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full mx-4">
            <div class="p-6">
                <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4">Confirm Sale</h3>
                <form id="sellForm" method="POST" action="<?php echo e(route('items.mark-sold', $item)); ?>">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" id="selectedBuyerId" name="buyer_id" value="">
                    
                    <div class="mb-4">
                        <p class="text-sm text-gray-600 dark:text-gray-400 mb-2">You are about to sell this item to:</p>
                        <p class="font-semibold text-gray-900 dark:text-gray-100" id="selectedBuyerName"></p>
                        <p class="text-xs text-gray-500 dark:text-gray-400" id="selectedBuyerPosition"></p>
                    </div>

                    <div class="mb-6">
                        <label for="final_price" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Final Sale Price</label>
                        <div class="mt-1 relative rounded-md shadow-sm">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <span class="text-gray-500 dark:text-gray-400 sm:text-sm">$</span>
                            </div>
                            <input type="number" id="final_price" name="final_price" step="0.01" min="0" value="<?php echo e($item->price); ?>" required
                                   class="focus:ring-gray-400 focus:border-gray-400 block w-full pl-7 pr-12 sm:text-sm border-gray-300 dark:border-gray-600 rounded-md">
                        </div>
                        <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">Enter the final agreed price (can be different from listing price)</p>
                    </div>

                    <div class="bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-md p-3 mb-4">
                        <div class="flex">
                            <svg class="h-5 w-5 text-gray-400 dark:text-gray-500 mr-2" fill="currentColor" viewBox="0 0 20 20">
                                <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"></path>
                            </svg>
                            <div class="text-sm text-gray-700 dark:text-gray-300">
                                <p><strong>Important:</strong> Only mark as sold after receiving payment. This will:</p>
                                <ul class="list-disc list-inside mt-1 text-xs">
                                    <li>Create a transaction record</li>
                                    <li>Remove the item from public listings</li>
                                    <li>Notify all backup buyers</li>
                                    <li>Cannot be undone</li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <div class="flex justify-end space-x-3">
                        <button type="button" onclick="hideSellModal()" class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700">
                            Cancel
                        </button>
                        <button type="submit" class="px-4 py-2 bg-gray-800 border border-transparent rounded-md text-sm font-medium text-white hover:bg-gray-700">
                            Confirm Sale
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        function showSellModal(buyerId, buyerName, position) {
            document.getElementById('selectedBuyerId').value = buyerId;
            document.getElementById('selectedBuyerName').textContent = buyerName;
            document.getElementById('selectedBuyerPosition').textContent = position === 1 ? 'Primary buyer' : `Backup buyer #${position - 1}`;
            document.getElementById('sellModal').classList.remove('hidden');
            document.getElementById('sellModal').classList.add('flex');
        }

        function hideSellModal() {
            document.getElementById('sellModal').classList.add('hidden');
            document.getElementById('sellModal').classList.remove('flex');
        }

        function messageUser(userId, userName, itemId) {
            // Create a form and submit to create/find conversation
            const form = document.createElement('form');
            form.method = 'POST';
            form.action = '<?php echo e(route("messages.create-direct")); ?>';
            
            const csrfToken = document.createElement('input');
            csrfToken.type = 'hidden';
            csrfToken.name = '_token';
            csrfToken.value = '<?php echo e(csrf_token()); ?>';
            
            const userIdInput = document.createElement('input');
            userIdInput.type = 'hidden';
            userIdInput.name = 'user_id';
            userIdInput.value = userId;
            
            const itemIdInput = document.createElement('input');
            itemIdInput.type = 'hidden';
            itemIdInput.name = 'item_id';
            itemIdInput.value = itemId;
            
            form.appendChild(csrfToken);
            form.appendChild(userIdInput);
            form.appendChild(itemIdInput);
            
            document.body.appendChild(form);
            form.submit();
        }

        // Close modal when clicking outside
        document.getElementById('sellModal').addEventListener('click', function(e) {
            if (e.target === this) {
                hideSellModal();
            }
        });
    </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/manage-queue.blade.php ENDPATH**/ ?>