<?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, []); ?> 
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                <?php echo e($deal->title); ?>

            </h2>
            <div class="flex space-x-2">
                <a href="<?php echo e(route('deals.index')); ?>" class="inline-flex items-center px-3 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 Deals
                </a>
                <a href="<?php echo e($deal->url); ?>" target="_blank" rel="noopener" class="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">
                    View Deal
                    <svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
                    </svg>
                </a>
            </div>
        </div>
     <?php $__env->endSlot(); ?>

    <div class="py-12">
        <div class="max-w-4xl mx-auto sm:px-6 lg:px-8 space-y-6">
            <!-- Deal Details -->
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg <?php echo e($deal->is_pinned ? 'ring-2 ring-yellow-400' : ''); ?>">
                <?php if($deal->image_url): ?>
                    <div class="max-h-80 overflow-hidden bg-gray-100">
                        <img src="<?php echo e($deal->image_url); ?>" alt="<?php echo e($deal->title); ?>" class="w-full max-h-80 object-cover" onerror="this.parentElement.remove()">
                    </div>
                <?php endif; ?>
                <div class="p-6">
                    <div class="flex justify-between items-start">
                        <div class="flex-1">
                            <!-- Deal Header -->
                            <div class="flex items-center space-x-3 mb-4">
                                <?php if($deal->is_pinned): ?>
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800">
                                        📌 Pinned
                                    </span>
                                <?php endif; ?>
                                <?php if($deal->is_expired): ?>
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
                                        Expired
                                    </span>
                                <?php endif; ?>
                                <span class="text-sm font-medium text-blue-600"><?php echo e($deal->store_name); ?></span>
                                <?php if($deal->savings_percent): ?>
                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
                                        <?php echo e($deal->savings_percent); ?>% off
                                    </span>
                                <?php endif; ?>
                            </div>

                            <!-- Pricing -->
                            <?php if($deal->price): ?>
                                <div class="flex items-center space-x-3 mb-4">
                                    <span class="text-3xl font-bold text-green-600">$<?php echo e(number_format($deal->price, 2)); ?></span>
                                    <?php if($deal->original_price): ?>
                                        <span class="text-xl text-gray-500 line-through">$<?php echo e(number_format($deal->original_price, 2)); ?></span>
                                        <?php if($deal->savings): ?>
                                            <span class="text-lg text-green-600 font-medium">Save $<?php echo e(number_format($deal->savings, 2)); ?></span>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                            <?php endif; ?>

                            <!-- Description -->
                            <div class="prose max-w-none mb-6">
                                <p class="text-gray-700 whitespace-pre-line"><?php echo e($deal->description); ?></p>
                            </div>

                            <!-- Deal Meta -->
                            <div class="flex items-center justify-between text-sm text-gray-500 border-t pt-4">
                                <div class="flex items-center space-x-4">
                                    <span>Submitted by <?php echo e($deal->user->name); ?></span>
                                    <span><?php echo e($deal->created_at->diffForHumans()); ?></span>
                                </div>
                                <?php if($deal->expires_at): ?>
                                    <span class="<?php echo e($deal->is_expired ? 'text-red-600 font-medium' : 'text-orange-600'); ?>">
                                        <?php echo e($deal->is_expired ? 'Expired' : 'Expires'); ?> <?php echo e($deal->expires_at->format('M j, Y g:i A')); ?>

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

                        <!-- Voting -->
                        <div class="flex flex-col items-center space-y-2 ml-6">
                            <button onclick="vote(<?php echo e($deal->id); ?>, 'up')" class="p-3 text-gray-400 hover:text-green-600 transition-colors">
                                <svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M5.293 7.707a1 1 0 010-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L6.707 7.707a1 1 0 01-1.414 0z" clip-rule="evenodd"></path>
                                </svg>
                            </button>
                            <span class="text-lg font-bold text-gray-900" id="score-<?php echo e($deal->id); ?>">
                                <?php echo e($deal->upvotes - $deal->downvotes); ?>

                            </span>
                            <button onclick="vote(<?php echo e($deal->id); ?>, 'down')" class="p-3 text-gray-400 hover:text-red-600 transition-colors">
                                <svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M14.707 12.293a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 111.414-1.414L9 14.586V3a1 1 0 012 0v11.586l2.293-2.293a1 1 0 011.414 0z" clip-rule="evenodd"></path>
                                </svg>
                            </button>
                            <div class="text-xs text-gray-500 text-center">
                                <div><?php echo e($deal->upvotes); ?> up</div>
                                <div><?php echo e($deal->downvotes); ?> down</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Comments Section -->
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <h3 class="text-lg font-semibold text-gray-900 mb-4">
                        Comments (<?php echo e($deal->comments->count()); ?>)
                    </h3>

                    <!-- Add Comment Form -->
                    <?php if(auth()->guard()->check()): ?>
                        <form id="add-comment" method="POST" action="<?php echo e(route('deals.comment', $deal)); ?>" class="mb-6">
                            <?php echo csrf_field(); ?>
                            <div class="flex space-x-3">
                                <div class="flex-shrink-0">
                                    <div class="w-8 h-8 bg-gray-300 rounded-full flex items-center justify-center">
                                        <span class="text-xs font-medium text-gray-700"><?php echo e(substr(auth()->user()->name, 0, 1)); ?></span>
                                    </div>
                                </div>
                                <div class="flex-1">
                                    <textarea name="comment" rows="3" class="w-full border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm" placeholder="Add a comment..." required><?php echo e(old('comment')); ?></textarea>
                                    <?php $__errorArgs = ['comment'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <p class="text-red-600 text-sm mt-1"><?php echo e($message); ?></p>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                    <div class="mt-2">
                                        <button type="submit" class="inline-flex items-center px-3 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">
                                            Post Comment
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    <?php else: ?>
                        <div class="mb-6 p-4 bg-gray-50 rounded-lg">
                            <p class="text-gray-600">
                                <a href="<?php echo e(route('login')); ?>" class="text-blue-600 hover:text-blue-800">Login</a> to comment on this deal.
                            </p>
                        </div>
                    <?php endif; ?>

                    <!-- Comments List -->
                    <?php if($deal->comments->count() > 0): ?>
                        <div class="space-y-4">
                            <?php $__currentLoopData = $deal->comments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $comment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="flex space-x-3">
                                    <div class="flex-shrink-0">
                                        <div class="w-8 h-8 bg-gray-300 rounded-full flex items-center justify-center">
                                            <span class="text-xs font-medium text-gray-700"><?php echo e(substr($comment->user->name, 0, 1)); ?></span>
                                        </div>
                                    </div>
                                    <div class="flex-1">
                                        <div class="bg-gray-50 rounded-lg p-3">
                                            <div class="flex items-center justify-between mb-1">
                                                <span class="text-sm font-medium text-gray-900"><?php echo e($comment->user->name); ?></span>
                                                <span class="text-xs text-gray-500"><?php echo e($comment->created_at->diffForHumans()); ?></span>
                                            </div>
                                            <p class="text-gray-700 whitespace-pre-line"><?php echo e($comment->comment); ?></p>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php else: ?>
                        <p class="text-gray-500 text-center py-8">No comments yet. Be the first to comment!</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <script>
        async function vote(dealId, type) {
            if (!<?php echo json_encode(auth()->check(), 15, 512) ?>) {
                alert('Please login to vote on deals');
                return;
            }

            try {
                const response = await fetch(`/deals/${dealId}/vote`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>',
                        'X-Requested-With': 'XMLHttpRequest'
                    },
                    body: JSON.stringify({ type: type })
                });

                const result = await response.json();
                
                if (result.success) {
                    const score = result.upvotes - result.downvotes;
                    document.getElementById(`score-${dealId}`).textContent = score;
                }
            } catch (error) {
                console.error('Error voting:', error);
            }
        }
    </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/deals/show.blade.php ENDPATH**/ ?>