<?php $__env->startSection('title', 'Харилцагчид'); ?>
<?php $__env->startSection('page_title', 'Харилцагчид (CRM)'); ?>

<?php $__env->startSection('content'); ?>


<div class="flex flex-wrap items-center gap-2 mb-6">
    <?php
        $tabs = [
            ''         => ['Бүгд',          'all',      'gray'],
            'lead'     => ['Lead',          'lead',     'gray'],
            'prospect' => ['Prospect',      'prospect', 'blue'],
            'active'   => ['Идэвхтэй',      'active',   'green'],
            'inactive' => ['Идэвхгүй',      'inactive', 'yellow'],
            'archived' => ['Архивласан',    'archived', 'gray'],
        ];
    ?>
    <?php $__currentLoopData = $tabs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => [$label, $countKey, $color]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <a href="<?php echo e(route('admin.clients.index', array_filter(['status' => $key, 'search' => request('search')]))); ?>"
           class="px-4 py-2 rounded-lg text-sm font-semibold transition <?php echo e(request('status', '') === $key ? 'bg-nsma-red text-white' : 'bg-white border border-gray-200 hover:border-nsma-red'); ?>">
            <?php echo e($label); ?> <span class="opacity-60">(<?php echo e($statusCounts[$countKey] ?? 0); ?>)</span>
        </a>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>

<div class="flex items-center justify-between mb-6">
    <form method="GET" class="flex items-center gap-2">
        <input type="hidden" name="status" value="<?php echo e(request('status')); ?>">
        <input type="text" name="search" value="<?php echo e(request('search')); ?>" placeholder="Нэр, и-мэйл, утсаар хайх..." class="px-4 py-2 border border-gray-200 rounded-lg outline-none w-72">
        <select name="source" class="px-4 py-2 border border-gray-200 rounded-lg outline-none">
            <option value="">Бүх эх үүсвэр</option>
            <option value="website" <?php if(request('source') === 'website'): echo 'selected'; endif; ?>>Вэбсайт</option>
            <option value="referral" <?php if(request('source') === 'referral'): echo 'selected'; endif; ?>>Танилцуулга</option>
            <option value="cold_outreach" <?php if(request('source') === 'cold_outreach'): echo 'selected'; endif; ?>>Cold outreach</option>
            <option value="social" <?php if(request('source') === 'social'): echo 'selected'; endif; ?>>Сошиал</option>
            <option value="event" <?php if(request('source') === 'event'): echo 'selected'; endif; ?>>Эвэнт</option>
            <option value="other" <?php if(request('source') === 'other'): echo 'selected'; endif; ?>>Бусад</option>
        </select>
        <button class="px-4 py-2 bg-nsma-dark text-white rounded-lg">Шүүх</button>
    </form>
    <a href="<?php echo e(route('admin.clients.create')); ?>" class="bg-nsma-red text-white font-semibold px-4 py-2 rounded-lg">+ Шинэ харилцагч</a>
</div>

<div class="bg-white rounded-2xl border border-gray-100 overflow-hidden">
    <table class="w-full">
        <thead class="bg-gray-50 border-b">
            <tr>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Харилцагч</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Холбоо барих</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Эх үүсвэр</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Захиалга</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Төлөв</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Огноо</th>
                <th class="text-right px-4 py-3 text-xs font-semibold uppercase">Үйлдэл</th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $clients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr class="border-b border-gray-100 hover:bg-gray-50">
                    <td class="px-4 py-3">
                        <div class="font-semibold"><?php echo e($c->name); ?></div>
                        <?php if($c->company_name): ?> <div class="text-xs text-gray-500"><?php echo e($c->company_name); ?></div> <?php endif; ?>
                    </td>
                    <td class="px-4 py-3 text-sm">
                        <div><?php echo e($c->email); ?></div>
                        <div class="text-xs text-gray-500"><?php echo e($c->phone); ?></div>
                    </td>
                    <td class="px-4 py-3 text-sm capitalize"><?php echo e(str_replace('_', ' ', $c->source)); ?></td>
                    <td class="px-4 py-3 text-sm"><?php echo e($c->orders_count); ?></td>
                    <td class="px-4 py-3">
                        <span class="text-xs px-2 py-1 rounded-full bg-<?php echo e($c->statusColor()); ?>-100 text-<?php echo e($c->statusColor()); ?>-700"><?php echo e($c->statusLabel()); ?></span>
                    </td>
                    <td class="px-4 py-3 text-xs text-gray-500"><?php echo e($c->created_at->format('Y-m-d')); ?></td>
                    <td class="px-4 py-3 text-right">
                        <a href="<?php echo e(route('admin.clients.show', $c)); ?>" class="px-3 py-1 text-xs bg-nsma-red text-white rounded">Дэлгэрэнгүй</a>
                    </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="7" class="text-center py-12 text-gray-500">Харилцагч олдсонгүй.</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

<div class="mt-4"><?php echo e($clients->links()); ?></div>

<?php $__env->stopSection(); ?>

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