<?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(__('My Offers')); ?>

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

    <div class="py-12">
        <div class="max-w-5xl mx-auto sm:px-6 lg:px-8">
            <!-- Tabs -->
            <div class="mb-6 border-b border-gray-200">
                <div class="flex space-x-8">
                    <button class="tab-button active py-4 px-1 border-b-2 border-gray-800 font-medium text-gray-900 hover:text-gray-700 transition" data-tab="received">
                        Offers Received (<?php echo e($receivedOffers->count()); ?>)
                    </button>
                    <button class="tab-button py-4 px-1 border-b-2 border-transparent font-medium text-gray-600 hover:text-gray-700 transition" data-tab="sent">
                        Offers Sent (<?php echo e($sentOffers->count()); ?>)
                    </button>
                </div>
            </div>

            <!-- Offers Received Tab -->
            <div id="received-tab" class="tab-content">
                <?php if($receivedOffers->count() === 0): ?>
                    <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                        <div class="p-12 text-center">
                            <p class="text-gray-500 text-lg mb-2">No offers yet.</p>
                            <p class="text-gray-400 text-sm">When buyers make offers on your items, they'll appear here.</p>
                            <a href="<?php echo e(route('items.my-listings')); ?>" class="mt-6 inline-flex items-center px-4 py-2 bg-gray-800 text-white text-sm font-semibold rounded-md hover:bg-gray-700 transition">
                                View my listings
                            </a>
                        </div>
                    </div>
                <?php else: ?>
                    <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                        <div class="divide-y divide-gray-100">
                            <?php $__currentLoopData = $receivedOffers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $offer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $statusColor = match($offer->status) {
                                        'pending' => 'bg-blue-50 text-blue-700 border-blue-200',
                                        'counter_offered' => 'bg-yellow-50 text-yellow-700 border-yellow-200',
                                        'accepted' => 'bg-green-50 text-green-700 border-green-200',
                                        'rejected' => 'bg-red-50 text-red-700 border-red-200',
                                        'expired' => 'bg-gray-50 text-gray-600 border-gray-200',
                                        default => 'bg-gray-50 text-gray-600 border-gray-200',
                                    };
                                ?>
                                <div class="p-4 hover:bg-gray-50 transition">
                                    <div class="flex items-start gap-4">
                                        
                                        <div class="shrink-0">
                                            <a href="<?php echo e(route('items.show', $offer->item)); ?>" class="w-16 h-16 rounded-lg bg-gray-100 overflow-hidden block hover:opacity-75 transition">
                                                <?php if($offer->item->primaryPhoto): ?>
                                                    <img src="<?php echo e(asset($offer->item->primaryPhoto->url)); ?>" alt="<?php echo e($offer->item->title); ?>" class="w-full h-full object-cover">
                                                <?php else: ?>
                                                    <div class="w-full h-full flex items-center justify-center text-gray-300">
                                                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                                                    </div>
                                                <?php endif; ?>
                                            </a>
                                        </div>

                                        
                                        <div class="flex-1 min-w-0">
                                            <div class="flex items-start justify-between gap-4">
                                                <div>
                                                    <h3 class="font-semibold text-gray-900">
                                                        <a href="<?php echo e(route('items.show', $offer->item)); ?>" class="hover:text-gray-600 transition">
                                                            <?php echo e($offer->item->title); ?>

                                                        </a>
                                                    </h3>
                                                    <p class="text-sm text-gray-500 mt-1">
                                                        <strong>From:</strong> <?php echo e($offer->buyer->name); ?>

                                                    </p>
                                                    <p class="text-xs text-gray-400 mt-0.5"><?php echo e($offer->created_at->diffForHumans()); ?></p>
                                                </div>

                                                
                                                <div class="text-right shrink-0">
                                                    <div class="text-lg font-bold text-gray-900">$<?php echo e(number_format($offer->offered_price, 2)); ?></div>
                                                    <div class="text-xs text-gray-500">
                                                        Your asking: $<?php echo e(number_format($offer->item->price, 2)); ?>

                                                    </div>
                                                    <div class="text-xs text-gray-500 mt-1">
                                                        <?php if($offer->offered_price < $offer->item->price): ?>
                                                            <?php echo e(number_format(round((1 - $offer->offered_price / $offer->item->price) * 100), 0)); ?>% below
                                                        <?php elseif($offer->offered_price > $offer->item->price): ?>
                                                            +<?php echo e(number_format(round(($offer->offered_price / $offer->item->price - 1) * 100), 0)); ?>% above
                                                        <?php else: ?>
                                                            At asking
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                            </div>

                                            
                                            <div class="mt-3 space-y-2">
                                                <div class="inline-block text-xs font-semibold px-2 py-1 rounded <?php echo e($offer->is_committed ? 'bg-blue-100 text-blue-700' : 'bg-purple-100 text-purple-700'); ?>">
                                                    <?php echo e($offer->getOfferTypeLabel()); ?>

                                                </div>
                                                <?php if($offer->message): ?>
                                                    <p class="text-sm text-gray-600 italic"><?php echo e($offer->message); ?></p>
                                                <?php endif; ?>
                                            </div>

                                            
                                            <div class="mt-3 flex items-center justify-between">
                                                <div>
                                                    <span class="inline-block text-xs font-semibold px-2.5 py-0.5 rounded border <?php echo e($statusColor); ?>">
                                                        <?php echo e($offer->getStatusLabel()); ?>

                                                    </span>
                                                    <?php if($offer->status === 'pending' || $offer->status === 'counter_offered'): ?>
                                                        <span class="inline-block text-xs text-gray-500 ml-2">
                                                            Expires <?php echo e($offer->expires_at->diffForHumans()); ?>

                                                        </span>
                                                    <?php endif; ?>
                                                </div>

                                                
                                                <?php if($offer->status === 'pending' || $offer->status === 'counter_offered'): ?>
                                                    <div class="flex gap-2">
                                                        <form method="POST" action="<?php echo e(route('offers.accept', $offer)); ?>" class="inline">
                                                            <?php echo csrf_field(); ?>
                                                            <button type="submit" class="text-xs px-3 py-1 bg-gray-800 text-white rounded-md hover:bg-gray-700 transition">
                                                                Accept
                                                            </button>
                                                        </form>
                                                        <button type="button" class="text-xs px-3 py-1 bg-white border border-gray-300 text-gray-700 rounded-md hover:bg-gray-50 transition" onclick="openCounterModal(<?php echo e($offer->id); ?>, <?php echo e($offer->offered_price); ?>)">
                                                            Counter
                                                        </button>
                                                        <button type="button" class="text-xs px-3 py-1 bg-white border border-red-300 text-red-700 rounded-md hover:bg-red-50 transition" onclick="openRejectModal(<?php echo e($offer->id); ?>)">
                                                            Reject
                                                        </button>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    </div>
                <?php endif; ?>
            </div>

            <!-- Offers Sent Tab -->
            <div id="sent-tab" class="tab-content hidden">
                <?php if($sentOffers->count() === 0): ?>
                    <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                        <div class="p-12 text-center">
                            <p class="text-gray-500 text-lg mb-2">You haven't made any offers yet.</p>
                            <p class="text-gray-400 text-sm">Browse items and make offers on things you're interested in.</p>
                            <a href="<?php echo e(route('items.index')); ?>" class="mt-6 inline-flex items-center px-4 py-2 bg-gray-800 text-white text-sm font-semibold rounded-md hover:bg-gray-700 transition">
                                Browse listings
                            </a>
                        </div>
                    </div>
                <?php else: ?>
                    <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                        <div class="divide-y divide-gray-100">
                            <?php $__currentLoopData = $sentOffers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $offer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $statusColor = match($offer->status) {
                                        'pending' => 'bg-blue-50 text-blue-700 border-blue-200',
                                        'counter_offered' => 'bg-yellow-50 text-yellow-700 border-yellow-200',
                                        'accepted' => 'bg-green-50 text-green-700 border-green-200',
                                        'rejected' => 'bg-red-50 text-red-700 border-red-200',
                                        'expired' => 'bg-gray-50 text-gray-600 border-gray-200',
                                        'withdrawn' => 'bg-gray-50 text-gray-600 border-gray-200',
                                        default => 'bg-gray-50 text-gray-600 border-gray-200',
                                    };
                                ?>
                                <div class="p-4 hover:bg-gray-50 transition">
                                    <div class="flex items-start gap-4">
                                        
                                        <div class="shrink-0">
                                            <a href="<?php echo e(route('items.show', $offer->item)); ?>" class="w-16 h-16 rounded-lg bg-gray-100 overflow-hidden block hover:opacity-75 transition">
                                                <?php if($offer->item->primaryPhoto): ?>
                                                    <img src="<?php echo e(asset($offer->item->primaryPhoto->url)); ?>" alt="<?php echo e($offer->item->title); ?>" class="w-full h-full object-cover">
                                                <?php else: ?>
                                                    <div class="w-full h-full flex items-center justify-center text-gray-300">
                                                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                                                    </div>
                                                <?php endif; ?>
                                            </a>
                                        </div>

                                        
                                        <div class="flex-1 min-w-0">
                                            <div class="flex items-start justify-between gap-4">
                                                <div>
                                                    <h3 class="font-semibold text-gray-900">
                                                        <a href="<?php echo e(route('items.show', $offer->item)); ?>" class="hover:text-gray-600 transition">
                                                            <?php echo e($offer->item->title); ?>

                                                        </a>
                                                    </h3>
                                                    <p class="text-sm text-gray-500 mt-1">
                                                        <strong>Seller:</strong> <?php echo e($offer->seller->name); ?>

                                                    </p>
                                                    <p class="text-xs text-gray-400 mt-0.5"><?php echo e($offer->created_at->diffForHumans()); ?></p>
                                                </div>

                                                
                                                <div class="text-right shrink-0">
                                                    <div class="text-lg font-bold text-gray-900">$<?php echo e(number_format($offer->offered_price, 2)); ?></div>
                                                    <div class="text-xs text-gray-500">
                                                        Asking: $<?php echo e(number_format($offer->item->price, 2)); ?>

                                                    </div>
                                                    <div class="text-xs text-gray-500 mt-1">
                                                        <?php if($offer->offered_price < $offer->item->price): ?>
                                                            <?php echo e(number_format(round((1 - $offer->offered_price / $offer->item->price) * 100), 0)); ?>% below
                                                        <?php elseif($offer->offered_price > $offer->item->price): ?>
                                                            +<?php echo e(number_format(round(($offer->offered_price / $offer->item->price - 1) * 100), 0)); ?>% above
                                                        <?php else: ?>
                                                            At asking
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                            </div>

                                            
                                            <div class="mt-3 space-y-2">
                                                <div class="inline-block text-xs font-semibold px-2 py-1 rounded <?php echo e($offer->is_committed ? 'bg-blue-100 text-blue-700' : 'bg-purple-100 text-purple-700'); ?>">
                                                    <?php echo e($offer->getOfferTypeLabel()); ?>

                                                </div>
                                                <?php if($offer->message): ?>
                                                    <p class="text-sm text-gray-600 italic"><?php echo e($offer->message); ?></p>
                                                <?php endif; ?>
                                            </div>

                                            
                                            <div class="mt-3 flex items-center justify-between">
                                                <div>
                                                    <span class="inline-block text-xs font-semibold px-2.5 py-0.5 rounded border <?php echo e($statusColor); ?>">
                                                        <?php echo e($offer->getStatusLabel()); ?>

                                                    </span>
                                                    <?php if($offer->status === 'counter_offered'): ?>
                                                        <div class="mt-2">
                                                            <div class="text-xs text-gray-600">
                                                                Seller countered at: <strong>$<?php echo e(number_format($offer->counter_price, 2)); ?></strong>
                                                            </div>
                                                            <?php if($offer->seller_message): ?>
                                                                <p class="text-xs text-gray-600 mt-1 italic"><?php echo e($offer->seller_message); ?></p>
                                                            <?php endif; ?>
                                                        </div>
                                                    <?php elseif($offer->status === 'pending'): ?>
                                                        <span class="inline-block text-xs text-gray-500 ml-2">
                                                            Expires <?php echo e($offer->expires_at->diffForHumans()); ?>

                                                        </span>
                                                    <?php endif; ?>
                                                </div>

                                                
                                                <?php if($offer->status === 'pending' || $offer->status === 'counter_offered'): ?>
                                                    <div class="flex gap-2">
                                                        <?php if($offer->status === 'counter_offered'): ?>
                                                            <form method="POST" action="<?php echo e(route('offers.accept', $offer)); ?>" class="inline">
                                                                <?php echo csrf_field(); ?>
                                                                <button type="submit" class="text-xs px-3 py-1 bg-gray-800 text-white rounded-md hover:bg-gray-700 transition">
                                                                    Accept Counter
                                                                </button>
                                                            </form>
                                                        <?php endif; ?>
                                                        <form method="POST" action="<?php echo e(route('offers.withdraw', $offer)); ?>" class="inline" onsubmit="return confirm('Withdraw this offer?');">
                                                            <?php echo csrf_field(); ?>
                                                            <button type="submit" class="text-xs px-3 py-1 bg-white border border-gray-300 text-gray-700 rounded-md hover:bg-gray-50 transition">
                                                                Withdraw
                                                            </button>
                                                        </form>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <!-- Counter Modal -->
    <div id="counter-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50">
        <div class="bg-white rounded-lg shadow-xl max-w-md w-full">
            <div class="p-6">
                <h3 class="text-lg font-semibold text-gray-900 mb-4">Make a Counter Offer</h3>
                <form id="counter-form" method="POST" class="space-y-4">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" id="counter-offer-id" name="offer_id">

                    <div>
                        <label for="counter_price" class="block text-sm font-medium text-gray-700 mb-2">Counter Price</label>
                        <input type="number" id="counter_price" name="counter_price" step="0.01" min="0.01" class="w-full border-gray-300 rounded-md shadow-sm focus:border-gray-300 focus:ring focus:ring-gray-200" required>
                    </div>

                    <div>
                        <label for="seller_message" class="block text-sm font-medium text-gray-700 mb-2">Message (Optional)</label>
                        <textarea id="seller_message" name="seller_message" rows="3" maxlength="500" class="w-full border-gray-300 rounded-md shadow-sm focus:border-gray-300 focus:ring focus:ring-gray-200"></textarea>
                        <p class="text-xs text-gray-500 mt-1">Up to 500 characters</p>
                    </div>

                    <div class="flex gap-2 pt-4 border-t">
                        <button type="button" onclick="closeCounterModal()" class="flex-1 px-4 py-2 border border-gray-300 rounded-md text-gray-700 font-semibold hover:bg-gray-50 transition">
                            Cancel
                        </button>
                        <button type="submit" class="flex-1 px-4 py-2 bg-gray-800 text-white font-semibold rounded-md hover:bg-gray-700 transition">
                            Send Counter
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Reject Modal -->
    <div id="reject-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50">
        <div class="bg-white rounded-lg shadow-xl max-w-md w-full">
            <div class="p-6">
                <h3 class="text-lg font-semibold text-gray-900 mb-4">Reject Offer</h3>
                <form id="reject-form" method="POST" class="space-y-4">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" id="reject-offer-id" name="offer_id">

                    <div>
                        <label for="reject_message" class="block text-sm font-medium text-gray-700 mb-2">Message (Optional)</label>
                        <textarea id="reject_message" name="seller_message" rows="3" maxlength="500" class="w-full border-gray-300 rounded-md shadow-sm focus:border-gray-300 focus:ring focus:ring-gray-200" placeholder="Let the buyer know why you're rejecting (optional)"></textarea>
                        <p class="text-xs text-gray-500 mt-1">Up to 500 characters</p>
                    </div>

                    <div class="flex gap-2 pt-4 border-t">
                        <button type="button" onclick="closeRejectModal()" class="flex-1 px-4 py-2 border border-gray-300 rounded-md text-gray-700 font-semibold hover:bg-gray-50 transition">
                            Cancel
                        </button>
                        <button type="submit" class="flex-1 px-4 py-2 bg-white border border-red-300 text-red-700 font-semibold rounded-md hover:bg-red-50 transition">
                            Reject
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        // Tab switching
        document.querySelectorAll('.tab-button').forEach(btn => {
            btn.addEventListener('click', function() {
                const tab = this.dataset.tab;

                // Hide all tabs and remove active class
                document.querySelectorAll('.tab-content').forEach(el => el.classList.add('hidden'));
                document.querySelectorAll('.tab-button').forEach(el => {
                    el.classList.remove('active', 'border-gray-800', 'text-gray-900');
                    el.classList.add('border-transparent', 'text-gray-500');
                });

                // Show selected tab and mark button as active
                document.getElementById(tab + '-tab').classList.remove('hidden');
                this.classList.add('active', 'border-gray-800', 'text-gray-900');
                this.classList.remove('border-transparent', 'text-gray-500');
            });
        });

        // Counter offer modal
        function openCounterModal(offerId, currentPrice) {
            document.getElementById('counter-offer-id').value = offerId;
            document.getElementById('counter_price').value = currentPrice;
            document.getElementById('counter-form').action = `/offers/${offerId}/counter`;
            document.getElementById('counter-modal').classList.remove('hidden');
        }

        function closeCounterModal() {
            document.getElementById('counter-modal').classList.add('hidden');
        }

        // Reject offer modal
        function openRejectModal(offerId) {
            document.getElementById('reject-offer-id').value = offerId;
            document.getElementById('reject-form').action = `/offers/${offerId}/reject`;
            document.getElementById('reject-modal').classList.remove('hidden');
        }

        function closeRejectModal() {
            document.getElementById('reject-modal').classList.add('hidden');
        }
    </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/offers/index.blade.php ENDPATH**/ ?>