<?php
/**
 * View — Synthèse Backups : les 10 derniers backups de base (FULL / INCR 0),
 * regroupés par îlots de 2 h. Tableau consolidé.
 *
 * @var string|null $fetchError
 * @var array|null  $dbInfo
 * @var array       $rows       [{TYPE_LABEL, FIN, NB_SETS, RANG}, …]
 * @var array|null  $diagInfo
 */
?>

<div class="page-header"><h1 style="margin:0;font-size:1.05rem">📋 <?= t('demo_oracle.dash_bksum_title') ?></h1></div>
<p style="font-size:.85rem;color:var(--color-text-muted);margin:.25rem 0 .75rem">
    <?= t('demo_oracle.dash_bksum_hint') ?>
</p>

<?php if ($fetchError): ?>
<div class="alert alert-error"><?= htmlspecialchars($fetchError) ?></div>
<?php endif; ?>

<?php if (empty($rows) && !$fetchError): ?>
<div class="card"><p style="margin:0;color:var(--color-text-muted)"><?= t('demo_oracle.bksum_no_data') ?></p></div>
<?php if (!empty($diagInfo)): ?>
<details style="margin-top:.5rem">
    <summary style="font-size:.82rem;cursor:pointer;color:var(--color-text-muted)">Diagnostic V$BACKUP_SET</summary>
    <div class="card" style="margin-top:.25rem;font-size:.82rem;font-family:monospace">
        <p style="margin:0 0 .25rem">V$BACKUP_SET accessible : <strong><?= $diagInfo['accessible'] ? 'OUI' : 'NON' ?></strong></p>
        <?php if ($diagInfo['error']): ?>
        <p style="margin:0 0 .25rem;color:var(--color-danger)">Erreur : <?= htmlspecialchars($diagInfo['error']) ?></p>
        <?php endif; ?>
        <?php if ($diagInfo['accessible']): ?>
        <p style="margin:0 0 .25rem">Nombre total de lignes : <strong><?= $diagInfo['total_rows'] ?></strong></p>
        <?php if ($diagInfo['total_rows'] === 0): ?>
        <p style="margin:.35rem 0 0;color:var(--color-warning)">La vue V$BACKUP_SET est vide — aucun backup RMAN enregistre dans cette base.</p>
        <?php endif; ?>
        <?php endif; ?>
    </div>
</details>
<?php endif; ?>
<?php endif; ?>

<?php if (!empty($rows)): ?>
<div class="card" style="padding:0;overflow-x:auto">
<table class="data-table" style="width:100%;border-collapse:collapse;font-size:.85rem">
    <thead>
        <tr style="background:var(--color-input-bg,#f8f8f8);border-bottom:1px solid var(--color-border)">
            <th style="text-align:center;padding:.4rem .6rem">#</th>
            <th style="text-align:left;padding:.4rem .6rem"><?= t('demo_oracle.bksum_type') ?></th>
            <th style="text-align:left;padding:.4rem .6rem"><?= t('demo_oracle.bksum_end') ?></th>
            <th style="text-align:right;padding:.4rem .6rem"><?= t('demo_oracle.bksum_sets') ?></th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ($rows as $r):
        $isFull = (($r['TYPE_LABEL'] ?? '') === 'FULL');
        $color  = $isFull ? '#8e44ad' : '#2980b9';
    ?>
        <tr style="border-bottom:1px solid var(--color-border)">
            <td style="padding:.35rem .6rem;text-align:center;color:var(--color-text-muted)"><?= (int)($r['RANG'] ?? 0) ?></td>
            <td style="padding:.35rem .6rem">
                <span style="display:inline-block;width:10px;height:10px;border-radius:2px;background:<?= $color ?>;vertical-align:middle;margin-right:.4rem"></span>
                <strong><?= htmlspecialchars($r['TYPE_LABEL'] ?? '') ?></strong>
            </td>
            <td style="padding:.35rem .6rem;font-family:monospace;font-size:.8rem"><?= htmlspecialchars($r['FIN'] ?? '') ?></td>
            <td style="padding:.35rem .6rem;text-align:right;font-family:monospace"><?= (int)($r['NB_SETS'] ?? 0) ?></td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
</div>
<?php endif; ?>
