<?php
/**
 * (c) ININOUT & PYXIS. All Rights Reserved.
 * Wszelkie modyfikacje tego pliku wymagaja zgloszenia oraz zgody autorow.
 * Any modifications to this file require notification and consent of the authors.
 */
/**
 * i-BOK 5 - Infrastruktura sieciowa (admin)
 */

$devices = vbk_read_infra();
?>

<div class="fade-in">
    <h4 class="mb-4">
        <i class="bi bi-hdd-network me-2"></i> <?= __('admin_infra.title') ?>
        <span class="badge bg-secondary ms-2"><?= count($devices) ?></span>
    </h4>

    <?= ibok_help_section('admin_infra', __('help.show_help'), __('help_admin.infra_section_content')) ?>

    <div class="card">
        <div class="card-body">
            <?php if (empty($devices)): ?>
                <p class="text-muted text-center py-4"><?= __('admin_infra.no_data') ?></p>
            <?php else: ?>
                <div class="table-responsive">
                    <table class="table table-hover ibok-table" id="tblInfra">
                        <thead>
                            <tr>
                                <th><?= __('admin_infra.id') ?></th>
                                <th><?= __('admin_infra.ip') ?></th>
                                <th><?= __('admin_infra.mac') ?></th>
                                <th><?= __('admin_infra.name') ?></th>
                                <th><?= __('admin_infra.model') ?></th>
                                <th><?= __('admin_infra.function') ?></th>
                                <th><?= __('admin_infra.group') ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($devices as $d): ?>
                            <tr class="<?= ($d['wylaczony'] !== '0') ? 'text-muted' : '' ?>">
                                <td><?= e($d['nr']) ?></td>
                                <td class="font-monospace"><?= e($d['ip']) ?></td>
                                <td class="font-monospace small"><?= e($d['mac']) ?></td>
                                <td class="fw-bold"><?= e($d['nazwa']) ?></td>
                                <td><?= e($d['typ_model']) ?></td>
                                <td>
                                    <?php
                                    $fn = strtolower($d['funkcja']);
                                    $icon = 'hdd-network';
                                    if (strpos($fn, 'router') !== false) $icon = 'router';
                                    elseif (strpos($fn, 'ap') !== false) $icon = 'wifi';
                                    elseif (strpos($fn, 'switch') !== false) $icon = 'diagram-3';
                                    elseif (strpos($fn, 'serwer') !== false || strpos($fn, 'server') !== false) $icon = 'server';
                                    ?>
                                    <i class="bi bi-<?= $icon ?> me-1"></i> <?= e($d['funkcja']) ?>
                                </td>
                                <td class="small"><?= e($d['grupa']) ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>
