<?php $__env->startSection('title', 'Manage Partners & Clients'); ?>

<?php $__env->startPush('extra_head'); ?>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.2/Sortable.min.js"></script>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<div class="container mx-auto">
    <div class="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-8">
        <div>
            <h1 class="text-2xl font-bold text-slate-900 tracking-tight">Partners & Clients</h1>
            <p class="text-slate-500 mt-1">Manage logos shown in the frontend partners carousel. Drag to reorder.</p>
        </div>
        <a href="<?php echo e(route('admin.partners.create')); ?>" class="bg-brand-primary hover:bg-brand-accent text-white font-bold py-2.5 px-6 rounded-xl shadow-sm shadow-brand-primary/30 transition-all duration-300 flex items-center gap-2">
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
            Add Partner
        </a>
    </div>

    <!-- Partner Grid -->
    <div id="partner-grid" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6">
        <?php $__empty_1 = true; $__currentLoopData = $partners; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $partner): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
        <div class="bg-white rounded-2xl p-6 shadow-sm border border-slate-100 flex flex-col items-center group relative cursor-move" data-id="<?php echo e($partner->id); ?>">
            <!-- Status Badge -->
            <div class="absolute top-3 right-3">
                <span class="w-3 h-3 rounded-full <?php echo e($partner->is_active ? 'bg-green-500' : 'bg-slate-300'); ?> border-2 border-white shadow-sm shadow-black/10"></span>
            </div>

            <!-- Logo Display -->
            <div class="w-full aspect-square flex items-center justify-center p-4 bg-slate-50 rounded-xl mb-4 group-hover:bg-slate-100/50 transition-colors">
                <img src="<?php echo e(asset($partner->logo_path)); ?>" alt="<?php echo e($partner->name); ?>" class="max-w-full max-h-full object-contain filter group-hover:drop-shadow-md transition-all duration-300">
            </div>

            <h3 class="font-bold text-slate-800 text-sm text-center line-clamp-1 mb-4"><?php echo e($partner->name); ?></h3>

            <!-- Actions -->
            <div class="flex items-center gap-2 mt-auto w-full pt-4 border-t border-slate-50">
                <a href="<?php echo e(route('admin.partners.edit', $partner)); ?>" class="flex-1 flex justify-center py-2 text-slate-400 hover:text-brand-primary hover:bg-brand-primary/10 rounded-lg transition" title="Edit">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>
                </a>
                
                <form action="<?php echo e(route('admin.partners.destroy', $partner)); ?>" method="POST" class="flex-1" onsubmit="return confirm('Are you sure you want to delete this partner?');">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('DELETE'); ?>
                    <button type="submit" class="w-full flex justify-center py-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition" title="Delete">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
                    </button>
                </form>
            </div>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
        <div class="col-span-full py-20 bg-white rounded-3xl border border-dashed border-slate-200 flex flex-col items-center justify-center">
            <div class="w-20 h-20 rounded-full bg-slate-50 flex items-center justify-center mb-4">
                <svg class="w-10 h-10 text-slate-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path></svg>
            </div>
            <h3 class="text-xl font-bold text-slate-900">No Partners Added</h3>
            <p class="text-slate-500 mt-1 mb-6">Start by adding your first partner or client logo.</p>
            <a href="<?php echo e(route('admin.partners.create')); ?>" class="bg-brand-primary text-white font-bold py-2.5 px-6 rounded-xl">Add Partner</a>
        </div>
        <?php endif; ?>
    </div>
</div>

<div id="reorder-saving" class="fixed bottom-8 left-1/2 -translate-x-1/2 bg-slate-900 text-white px-6 py-3 rounded-2xl shadow-2xl z-[100] flex items-center gap-3 opacity-0 pointer-events-none transition-all">
    <svg class="w-5 h-5 animate-spin text-brand-accent" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg>
    <span class="font-bold text-sm tracking-wide">Saving Order...</span>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('extra_scripts'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const grid = document.getElementById('partner-grid');
        if (!grid) return;

        new Sortable(grid, {
            animation: 150,
            ghostClass: 'opacity-50',
            dragClass: 'shadow-2xl',
            onEnd: function() {
                const savingIndicator = document.getElementById('reorder-saving');
                savingIndicator.classList.remove('opacity-0', 'pointer-events-none');
                savingIndicator.classList.add('opacity-100');

                const order = Array.from(grid.querySelectorAll('[data-id]')).map(el => el.dataset.id);

                fetch("<?php echo e(route('admin.partners.reorder')); ?>", {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'X-CSRF-TOKEN': "<?php echo e(csrf_token()); ?>"
                    },
                    body: JSON.stringify({ order : order })
                })
                .then(response => response.json())
                .then(data => {
                    setTimeout(() => {
                        savingIndicator.classList.replace('opacity-100', 'opacity-0');
                        savingIndicator.classList.add('pointer-events-none');
                    }, 500);
                });
            }
        });
    });
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\ecs\resources\views/admin/partners/index.blade.php ENDPATH**/ ?>