<?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>
            <h1 class="text-lg font-semibold text-gray-800">Businesses</h1>
            <p class="text-xs text-gray-400 mt-0.5">Manage tenant businesses & FBR credentials</p>
        </div>
     <?php $__env->endSlot(); ?>

    <div class="space-y-6" x-data="businessIndex()">

        
        <div class="lg:hidden">
            <h1 class="text-xl font-bold text-gray-900">Businesses</h1>
            <p class="text-sm text-gray-500">Manage tenant businesses & FBR credentials</p>
        </div>

        
        <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
            <div class="relative w-full sm:w-72">
                <svg class="w-4 h-4 text-gray-400 absolute left-3 top-1/2 -translate-y-1/2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-4.35-4.35M17 10a7 7 0 11-14 0 7 7 0 0114 0z"/>
                </svg>
                <input type="text" x-model="search" placeholder="Search businesses..."
                       class="w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-gray-200 focus:border-indigo-400 focus:ring-indigo-400 placeholder-gray-400">
            </div>

            <a href="<?php echo e(route('businesses.create')); ?>"
               class="inline-flex items-center justify-center gap-2 px-4 py-2 rounded-lg bg-indigo-600 text-white text-sm font-medium hover:bg-indigo-700 transition">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/></svg>
                Add Business
            </a>
        </div>

        
        <div class="bg-white rounded-xl border border-gray-100 shadow-sm overflow-hidden">
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr class="text-left text-gray-400 text-xs uppercase tracking-wide bg-gray-50/60">
                            <th class="px-5 py-3 font-medium">Business</th>
                            <th class="px-5 py-3 font-medium">NTN / CNIC</th>
                            <th class="px-5 py-3 font-medium">Province</th>
                            <th class="px-5 py-3 font-medium">Mode</th>
                            <th class="px-5 py-3 font-medium">Auto Sync</th>
                            <th class="px-5 py-3 font-medium">Status</th>
                            <th class="px-5 py-3 font-medium text-right">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-50">
                        <?php $__empty_1 = true; $__currentLoopData = $businesses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $business): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr class="hover:bg-gray-50/60" x-show="matches(<?php echo \Illuminate\Support\Js::from(strtolower($business->name.' '.$business->business_name.' '.$business->ntn_cnic))->toHtml() ?>)">
                                <td class="px-5 py-3.5">
                                    <p class="font-medium text-gray-700"><?php echo e($business->name); ?></p>
                                    <?php if($business->business_name): ?>
                                        <p class="text-xs text-gray-400"><?php echo e($business->business_name); ?></p>
                                    <?php endif; ?>
                                </td>
                                <td class="px-5 py-3.5 text-gray-500"><?php echo e($business->ntn_cnic ?? '—'); ?></td>
                                <td class="px-5 py-3.5 text-gray-500"><?php echo e($business->province ?? '—'); ?></td>
                                <td class="px-5 py-3.5">
                                    <span class="text-xs font-medium px-2 py-0.5 rounded-full <?php echo e($business->is_sandbox ? 'bg-amber-50 text-amber-700' : 'bg-green-50 text-green-700'); ?>">
                                        <?php echo e($business->is_sandbox ? 'Sandbox' : 'Production'); ?>

                                    </span>
                                </td>
                                <td class="px-5 py-3.5">
                                    <span class="text-xs font-medium px-2 py-0.5 rounded-full <?php echo e($business->auto_sync_enabled ? 'bg-indigo-50 text-indigo-700' : 'bg-gray-100 text-gray-500'); ?>">
                                        <?php echo e($business->auto_sync_enabled ? 'On' : 'Off'); ?>

                                    </span>
                                </td>
                                <td class="px-5 py-3.5">
                                    <span class="inline-flex items-center gap-1.5 text-xs font-medium px-2 py-0.5 rounded-full <?php echo e($business->is_active ? 'bg-green-50 text-green-700' : 'bg-red-50 text-red-700'); ?>">
                                        <span class="w-1.5 h-1.5 rounded-full <?php echo e($business->is_active ? 'bg-green-500' : 'bg-red-500'); ?>"></span>
                                        <?php echo e($business->is_active ? 'Active' : 'Inactive'); ?>

                                    </span>
                                </td>
                                <td class="px-5 py-3.5">
                                    <div class="flex items-center justify-end gap-1">
                                        <button @click="testConnection(<?php echo e($business->id); ?>, $event.currentTarget)"
                                                title="Test FBR Connection"
                                                class="p-1.5 rounded-md text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 transition">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/></svg>
                                        </button>
                                        <a href="<?php echo e(route('businesses.show', $business)); ?>" title="View"
                                           class="p-1.5 rounded-md text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 transition">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
                                        </a>
                                        <a href="<?php echo e(route('businesses.edit', $business)); ?>" title="Edit"
                                           class="p-1.5 rounded-md text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 transition">
                                            <svg class="w-4 h-4" 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"/></svg>
                                        </a>
                                        <button @click="remove(<?php echo e($business->id); ?>, $event.currentTarget)" title="Delete"
                                                class="p-1.5 rounded-md text-gray-400 hover:text-red-600 hover:bg-red-50 transition">
                                            <svg class="w-4 h-4" 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"/></svg>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="7" class="px-5 py-14 text-center text-gray-400 text-sm">
                                    No businesses yet — <a href="<?php echo e(route('businesses.create')); ?>" class="text-indigo-600 font-medium hover:text-indigo-700">add your first one</a>.
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

            <?php if($businesses instanceof \Illuminate\Pagination\AbstractPaginator && $businesses->hasPages()): ?>
                <div class="px-5 py-3 border-t border-gray-100">
                    <?php echo e($businesses->links()); ?>

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

        
        <div x-show="toast.show" x-transition x-cloak
             class="fixed bottom-5 right-5 px-4 py-3 rounded-lg shadow-lg text-sm font-medium text-white z-50"
             :class="toast.type === 'error' ? 'bg-red-600' : 'bg-green-600'"
             x-text="toast.message"></div>
    </div>

    <script>
        function businessIndex() {
            return {
                search: '',
                toast: { show: false, message: '', type: 'success' },

                matches(haystack) {
                    if (!this.search.trim()) return true;
                    return haystack.includes(this.search.toLowerCase());
                },

                notify(message, type = 'success') {
                    this.toast = { show: true, message, type };
                    setTimeout(() => this.toast.show = false, 3500);
                },

                async testConnection(id, btn) {
                    btn.disabled = true;
                    btn.classList.add('animate-pulse');
                    try {
                        const res = await fetch(`/businesses/${id}/test-connection`, {
                            headers: {
                                'Accept': 'application/json',
                                'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
                            },
                        });
                        const data = await res.json();
                        this.notify(data.message ?? (data.success ? 'Connection successful' : 'Connection failed'), data.success ? 'success' : 'error');
                    } catch (e) {
                        this.notify('Could not reach the server.', 'error');
                    } finally {
                        btn.disabled = false;
                        btn.classList.remove('animate-pulse');
                    }
                },

                async remove(id, btn) {
                    if (!confirm('Delete this business? This cannot be undone.')) return;
                    const row = btn.closest('tr');
                    try {
                        const res = await fetch(`/businesses/${id}`, {
                            method: 'DELETE',
                            headers: {
                                'Accept': 'application/json',
                                'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
                            },
                        });
                        const data = await res.json();
                        if (data.success) {
                            row.remove();
                            this.notify('Business deleted.');
                        } else {
                            this.notify('Delete failed.', 'error');
                        }
                    } catch (e) {
                        this.notify('Could not reach the server.', '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 /www/wwwroot/lifeelements.shiningerp.com/resources/views/businesses/index.blade.php ENDPATH**/ ?>