<?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="d-flex flex-wrap align-items-center justify-content-between gap-2">
            <div>
                <h2 class="h4 mb-0"><?php echo e($olt->name); ?></h2>
            </div>
            <div class="d-flex gap-2">
                <a href="<?php echo e(route('admin.olts.index')); ?>" class="btn btn-outline-secondary">OLT List</a>
                <button type="button" id="syncOlt" class="btn btn-primary">
                    <span data-feather="refresh-cw" class="me-1"></span> Live Sync
                </button>
            </div>
        </div>
     <?php $__env->endSlot(); ?>

    <?php ($snapshot = $olt->gateway_snapshot ?? []); ?>
    <?php ($condition = $snapshot['condition'] ?? []); ?>
    <?php ($interfaces = $snapshot['interfaces'] ?? []); ?>
    <?php ($devices = $snapshot['devices'] ?? []); ?>
    <?php ($matches = $snapshot['customer_match_summary'] ?? ['total_devices' => count($devices), 'matched' => 0, 'unmatched' => count($devices)]); ?>
    <?php ($diagramInterfaces = collect($interfaces)->filter(function ($interface) {
        $name = (string) ($interface['name'] ?? '');
        return ! str_contains(strtolower($name), 'onu')
            && preg_match('/^(?:ge|xge|gpon|epon)\d+(?:\/\d+)+(?:\s|$)/i', $name);
    })->take(32)->values()); ?>

    <div class="olt-sync-state <?php echo e($olt->gateway_error ? 'is-warning' : 'is-online'); ?>">
        <span class="olt-sync-icon" data-feather="<?php echo e($olt->gateway_error ? 'alert-triangle' : 'check-circle'); ?>"></span>
        <strong><?php echo e($olt->gateway_error ?: 'OLT connected'); ?></strong>
        <span class="olt-sync-time">Updated <?php echo e($olt->gateway_synced_at?->format('d M Y, h:i A') ?? 'Never'); ?></span>
    </div>

    <div class="row g-3 mb-3">
        <?php $__currentLoopData = [
            ['Gateway', $olt->gateway_status ?: 'Not synced', 'server'],
            ['Interfaces', $condition['interfaces_total'] ?? 0, 'layers'],
            ['Online ONU', collect($devices)->where('status', 'online')->count(), 'check-circle'],
            ['Offline ONU', collect($devices)->where('status', 'offline')->count(), 'x-circle'],
        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $card): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="col-6 col-xl-3">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body d-flex align-items-center gap-3">
                        <span class="olt-stat-icon" data-feather="<?php echo e($card[2]); ?>"></span>
                        <div class="min-w-0">
                            <div class="small text-muted"><?php echo e($card[0]); ?></div>
                            <div class="h5 mb-0 text-truncate"><?php echo e(ucfirst((string) $card[1])); ?></div>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    <div class="card border-0 shadow-sm mb-3 olt-diagram-card" id="olt-diagram">
        <div class="card-body">
            <div class="d-flex align-items-center gap-2 mb-3">
                <span class="olt-section-icon" data-feather="git-branch"></span>
                <h3 class="h6 mb-0">OLT Diagram</h3>
            </div>
            <div class="olt-diagram" aria-label="OLT interface condition diagram">
                <div class="olt-diagram-root"><span data-feather="server"></span><strong><?php echo e($olt->name); ?></strong></div>
                <div class="olt-diagram-ports">
                    <?php $__empty_1 = true; $__currentLoopData = $diagramInterfaces; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $interface): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php ($onuCount = collect($devices)->where('interface_index', (string) ($interface['index'] ?? ''))->count()); ?>
                        <a class="olt-diagram-port <?php echo e(($interface['oper_status'] ?? '') === 'up' ? 'is-up' : 'is-down'); ?>" href="<?php echo e(route('admin.olts.onus', $olt)); ?>">
                            <span class="olt-port-icon" data-feather="<?php echo e(($interface['oper_status'] ?? '') === 'up' ? 'wifi' : 'slash'); ?>"></span>
                            <strong><?php echo e($interface['name'] ?? 'PON '.$interface['index']); ?></strong>
                            <span><?php echo e($onuCount); ?> ONU</span>
                        </a>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <span class="text-muted small">No interface snapshot available.</span>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-3">
        <div class="col-lg-4">
            <a href="<?php echo e(route('admin.olts.interfaces', $olt)); ?>" class="text-decoration-none">
                <div class="card border-0 shadow-sm h-100 olt-link-card">
                    <div class="card-body">
                        <div class="d-flex align-items-center gap-3 mb-3">
                            <span class="olt-link-icon bg-primary-subtle text-primary" data-feather="activity"></span>
                            <div>
                                <h3 class="h6 mb-1 text-dark">Interface Condition</h3>
                            </div>
                        </div>
                        <div class="small text-muted">Total interfaces: <?php echo e($condition['interfaces_total'] ?? 0); ?></div>
                    </div>
                </div>
            </a>
        </div>

        <div class="col-lg-4">
            <a href="<?php echo e(route('admin.olts.onus', $olt)); ?>" class="text-decoration-none">
                <div class="card border-0 shadow-sm h-100 olt-link-card">
                    <div class="card-body">
                        <div class="d-flex align-items-center gap-3 mb-3">
                            <span class="olt-link-icon bg-success-subtle text-success" data-feather="radio"></span>
                            <div>
                                <h3 class="h6 mb-1 text-dark">ONU Tx/Rx</h3>
                            </div>
                        </div>
                        <div class="small text-muted">Total ONU: <?php echo e($matches['total_devices']); ?></div>
                    </div>
                </div>
            </a>
        </div>

        <div class="col-lg-4">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <h3 class="h6 mb-3">OLT Summary</h3>
                    <dl class="row small mb-0">
                        <dt class="col-5">Vendor</dt>
                        <dd class="col-7"><?php echo e(strtoupper($olt->brand)); ?></dd>
                        <dt class="col-5">Model</dt>
                        <dd class="col-7"><?php echo e($olt->model ?: '-'); ?></dd>
                        <dt class="col-5">System name</dt>
                        <dd class="col-7"><?php echo e(data_get($snapshot, 'system.name', '-')); ?></dd>
                        <dt class="col-5">Endpoint</dt>
                        <dd class="col-7 text-break"><?php echo e($olt->port_forward_status && $olt->mikrotik ? $olt->mikrotik->ip_address.':'.$olt->external_snmp_port : $olt->ip_address.':'.$olt->snmp_port); ?></dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>

    <?php $__env->startPush('scripts'); ?>
        <style>
            .olt-sync-state{display:flex;align-items:center;gap:.65rem;padding:.8rem 1rem;margin-bottom:1rem;border:1px solid #bbf7d0;border-radius:14px;background:#f0fdf4;color:#166534;font-size:.84rem}.olt-sync-state.is-warning{border-color:#fed7aa;background:#fff7ed;color:#9a3412}.olt-sync-icon{width:18px;height:18px;flex:0 0 auto}.olt-sync-time{margin-left:auto;color:inherit;opacity:.76;font-size:.76rem}
            .olt-stat-icon{width:44px;height:44px;border-radius:14px;display:grid;place-items:center;background:#eef2ff;color:#2563eb}.olt-stat-icon svg{width:20px;height:20px}
            .olt-link-card{transition:.2s ease}
            .olt-link-card:hover{transform:translateY(-2px);box-shadow:0 1rem 2rem rgba(15,23,42,.08)!important}
            .olt-link-icon{width:52px;height:52px;border-radius:16px;display:grid;place-items:center;font-size:1.1rem}.olt-link-icon svg{width:22px;height:22px}
            .olt-section-icon{width:32px;height:32px;display:grid;place-items:center;border-radius:10px;background:#eef2ff;color:#4f46e5}.olt-section-icon svg{width:17px;height:17px}
            .olt-diagram-card{overflow:hidden}.olt-diagram{display:grid;justify-items:center;gap:1rem;overflow:auto;padding:.75rem .25rem .25rem}
            .olt-diagram-root{display:inline-flex;align-items:center;gap:.55rem;padding:.7rem 1rem;border-radius:12px;background:#eef2ff;color:#3730a3;font-size:.85rem}.olt-diagram-root svg{width:17px;height:17px}
            .olt-diagram-ports{width:100%;display:flex;justify-content:center;gap:.65rem;flex-wrap:wrap;position:relative;padding-top:1.2rem}
            .olt-diagram-ports:before{content:"";position:absolute;top:.35rem;left:5%;right:5%;height:1px;background:#cbd5e1}
            .olt-diagram-port{position:relative;min-width:112px;padding:.7rem;border:1px solid #dbe4ee;border-radius:12px;background:#fff;text-decoration:none;color:#1e293b;text-align:center;font-size:.75rem}
            .olt-diagram-port:before{content:"";position:absolute;top:-.9rem;left:50%;width:1px;height:.9rem;background:#cbd5e1}
            .olt-diagram-port strong,.olt-diagram-port span{display:block}.olt-diagram-port span{margin-top:.2rem;color:#64748b}.olt-diagram-port .olt-port-icon{margin:.05rem auto .35rem;color:inherit}.olt-diagram-port .olt-port-icon svg{width:15px;height:15px}
            .olt-diagram-port.is-up{border-color:#86efac;background:#f0fdf4}.olt-diagram-port.is-down{border-color:#fecaca;background:#fff7f7}
            @media(max-width:575.98px){.olt-sync-state{align-items:flex-start;flex-wrap:wrap}.olt-sync-time{width:100%;margin-left:1.6rem}.olt-diagram-ports{justify-content:flex-start;min-width:640px}.olt-diagram{padding-bottom:.65rem}.olt-diagram-port{min-width:104px}}
        </style>
        <script>
            document.getElementById('syncOlt').addEventListener('click', async function () {
                const button = this;
                button.disabled = true;
                button.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span> Syncing';

                try {
                    await axios.post(<?php echo json_encode(route('admin.olts.test_connection', $olt), 512) ?>);
                    Swal.fire('Done', 'Live OLT data synced successfully. Page will refresh now.', 'success')
                        .then(() => window.location.reload());
                } catch (error) {
                    Swal.fire('Error', error.response?.data?.message || 'Sync could not be completed.', 'error');
                } finally {
                    button.disabled = false;
                button.innerHTML = '<span data-feather="refresh-cw" class="me-1"></span> Live Sync';
                if (window.feather) window.feather.replace();
                }
            });
        </script>
    <?php $__env->stopPush(); ?>
 <?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 D:\herd\billing\laravel-app\resources\views\admin\mikrotiks\olts\show.blade.php ENDPATH**/ ?>