<?php $__env->startSection('title', 'Kelola Iklan'); ?>

<?php $__env->startSection('content'); ?>
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6">
    <p class="text-sm text-gray-500">Kelola iklan Adsterra atau native ads lainnya</p>
    <a href="<?php echo e(route('admin.ads.create')); ?>" class="inline-flex items-center justify-center bg-indigo-600 text-white px-5 py-2.5 rounded-lg text-sm font-medium hover:bg-indigo-700 whitespace-nowrap">
        + Tambah Iklan
    </a>
</div>


<div class="grid grid-cols-2 md:grid-cols-4 gap-3 sm:gap-4 mb-6">
    <div class="bg-white rounded-xl border border-gray-100 p-3 sm:p-4 text-center">
        <div class="text-xl sm:text-2xl font-bold text-gray-800"><?php echo e($ads->count()); ?></div>
        <div class="text-[10px] sm:text-xs text-gray-400 mt-0.5">Total Iklan</div>
    </div>
    <div class="bg-white rounded-xl border border-gray-100 p-3 sm:p-4 text-center">
        <div class="text-xl sm:text-2xl font-bold text-green-600"><?php echo e($ads->where('is_active', true)->count()); ?></div>
        <div class="text-[10px] sm:text-xs text-gray-400 mt-0.5">Aktif</div>
    </div>
    <div class="bg-white rounded-xl border border-gray-100 p-3 sm:p-4 text-center">
        <div class="text-xl sm:text-2xl font-bold text-gray-400"><?php echo e($ads->where('is_active', false)->count()); ?></div>
        <div class="text-[10px] sm:text-xs text-gray-400 mt-0.5">Nonaktif</div>
    </div>
    <div class="bg-white rounded-xl border border-gray-100 p-3 sm:p-4 text-center">
        <div class="text-xl sm:text-2xl font-bold text-indigo-600"><?php echo e($ads->pluck('position')->unique()->count()); ?></div>
        <div class="text-[10px] sm:text-xs text-gray-400 mt-0.5">Posisi Terpakai</div>
    </div>
</div>


<?php
    $grouped = $ads->groupBy('position');
?>

<?php if($ads->count() > 0): ?>
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
    <?php $__currentLoopData = $grouped; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $position => $posAds): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php $__currentLoopData = $posAds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ad): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="bg-white rounded-xl border border-gray-100 p-4 sm:p-5 flex flex-col <?php echo e(!$ad->is_active ? 'opacity-60' : ''); ?>">
            
            <div class="mb-2">
                <span class="inline-flex items-center text-[10px] sm:text-xs font-medium text-indigo-600 bg-indigo-50 px-2 py-0.5 rounded-full">
                    <span class="w-1.5 h-1.5 rounded-full bg-indigo-500 mr-1.5"></span>
                    <?php echo e($positions[$position] ?? ucfirst(str_replace('_', ' ', $position))); ?>

                </span>
            </div>

            
            <div class="flex items-start justify-between gap-3 mb-2">
                <div class="flex-1 min-w-0">
                    <h4 class="font-semibold text-gray-800 text-sm truncate"><?php echo e($ad->name); ?></h4>
                    <?php if($ad->size): ?>
                    <span class="inline-block px-2 py-0.5 text-xs font-mono bg-gray-100 text-gray-600 rounded mt-1"><?php echo e($ad->size); ?></span>
                    <?php endif; ?>
                </div>
                <form action="<?php echo e(route('admin.ads.toggle', $ad)); ?>" method="POST" class="flex-shrink-0">
                    <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                    <button type="submit" title="<?php echo e($ad->is_active ? 'Nonaktifkan' : 'Aktifkan'); ?>"
                        class="relative w-10 h-[22px] rounded-full <?php echo e($ad->is_active ? 'bg-green-500' : 'bg-gray-300'); ?> focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-indigo-400">
                        <span class="absolute top-[3px] <?php echo e($ad->is_active ? 'right-[3px]' : 'left-[3px]'); ?> w-4 h-4 rounded-full bg-white shadow"></span>
                    </button>
                </form>
            </div>

            
            <?php if($ad->description): ?>
            <p class="text-xs text-gray-400 mb-2 line-clamp-2"><?php echo e($ad->description); ?></p>
            <?php endif; ?>

            
            <div class="bg-gray-50 rounded-lg p-2.5 mb-3 text-xs text-gray-500 max-h-16 overflow-hidden font-mono leading-relaxed break-all flex-grow">
                <?php echo e(Str::limit($ad->code, 100)); ?>

            </div>

            
            <div class="flex items-center justify-between mt-auto pt-2">
                <div class="flex items-center space-x-3">
                    <a href="<?php echo e(route('admin.ads.edit', $ad)); ?>" class="text-indigo-600 hover:text-indigo-800 text-sm font-medium">Edit</a>
                    <form action="<?php echo e(route('admin.ads.destroy', $ad)); ?>" method="POST" onsubmit="return confirm('Yakin hapus iklan ini?')">
                        <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                        <button class="text-red-500 hover:text-red-700 text-sm font-medium">Hapus</button>
                    </form>
                </div>
                <span class="text-xs text-gray-400">Order: <?php echo e($ad->sort_order); ?></span>
            </div>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>
<?php else: ?>
<div class="bg-white rounded-xl border border-gray-100 p-8 sm:p-12 text-center">
    <svg class="w-12 h-12 mx-auto text-gray-300 mb-4" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M10.34 15.84c-.688-.06-1.386-.09-2.09-.09H7.5a4.5 4.5 0 110-9h.75c.704 0 1.402-.03 2.09-.09m0 9.18c.253.962.584 1.892.985 2.783.247.55.06 1.21-.463 1.511l-.657.38c-.551.318-1.26.117-1.527-.461a20.845 20.845 0 01-1.44-4.282m3.102.069a18.03 18.03 0 01-.59-4.59c0-1.586.205-3.124.59-4.59m0 9.18a23.848 23.848 0 018.835 2.535M10.34 6.66a23.847 23.847 0 008.835-2.535m0 0A23.74 23.74 0 0018.795 3m.38 1.125a23.91 23.91 0 011.014 5.395m-1.014 8.855c-.118.38-.245.754-.38 1.125m.38-1.125a23.91 23.91 0 001.014-5.395m0-3.46c.495.413.811 1.035.811 1.73 0 .695-.316 1.317-.811 1.73m0-3.46a24.347 24.347 0 010 3.46"/></svg>
    <p class="text-gray-500 mb-2">Belum ada iklan.</p>
    <p class="text-gray-400 text-sm">Tambahkan kode iklan dari Adsterra untuk mulai monetisasi.</p>
</div>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/bursakerja/resources/views/admin/ads/index.blade.php ENDPATH**/ ?>