<?php

declare(strict_types=1);

use App\Core\Csrf;
use App\Core\Permission;

$statusLabels = [
    'importe'      => 'Importé',
    'pret'         => 'Prêt à installer',
    'installation' => 'Installation',
    'installe'     => 'Installé',
    'echec'        => 'Échec',
];

$lockState = $lockState ?? [
    'locked'      => false,
    'stale'       => false,
    'age_seconds' => 0,
    'data'        => [],
];

?>

<link rel="stylesheet" href="/public/assets/css/cda-update-center.css">

<section class="update-center-hero">
<?php if (!empty($_SESSION['success'])): ?>
    <div class="alert alert-success">
        <?= htmlspecialchars($_SESSION['success']) ?>
    </div>
    <?php unset($_SESSION['success']); ?>
<?php endif; ?>

<?php if (!empty($_SESSION['error'])): ?>
    <div class="alert alert-danger">
        <?= htmlspecialchars($_SESSION['error']) ?>
    </div>
    <?php unset($_SESSION['error']); ?>
<?php endif; ?>
    <div>

        <span class="page-kicker">

            Studio AXIOM

        </span>

        <h2>

            Centre de mise à jour

        </h2>

        <p>

            Version installée

            <strong>

                <?= htmlspecialchars((string) $version) ?>

            </strong>

        </p>

    </div>

    <div class="update-health">

        <span class="health-icon">

            ✓

        </span>

        <div>

            <strong>

                Plateforme opérationnelle

            </strong>

            <small>

                Validation • Déploiement • Sécurité • Rollback

            </small>

        </div>

    </div>

</section>

<nav class="update-engine-shortcuts">

    <a href="/public/administration/plateforme/validation">
        Validation
    </a>

    <a href="/public/administration/plateforme/confiance-packages">
        Trust Engine
    </a>

    <a href="/public/administration/plateforme/compatibilite-packages">
        Compatibilité
    </a>

    <a href="/public/administration/plateforme/certification-packages">
        Certification
    </a>

    <a href="/public/administration/plateforme/politiques-packages">
        Policy Engine
    </a>

    <a href="/public/administration/plateforme/packages/catalogue">
        Catalogue
    </a>

    <a href="/public/administration/plateforme/packages/dependances">
        Dépendances
    </a>

    <a href="/public/administration/plateforme/deploiement-orchestre">
        Orchestrateur
    </a>

    <a href="/public/administration/plateforme/packages/reparation">
        Réparation
    </a>

    <a href="/public/administration/plateforme/rollback">
        Rollback
    </a>

</nav>

<?php if (!empty($lockState['locked']) && Permission::can('updates.unlock')): ?>

<section class="update-center-card update-lock-card">

    <header>

        <div>

            <h3>

                Installation verrouillée

            </h3>

            <p>

                Une installation est actuellement verrouillée.

            </p>

        </div>

        <span class="status-installation">

            Installation

        </span>

    </header>

    <p>

        Si aucun processus n'est réellement en cours,
        vous pouvez libérer le verrou.

    </p>

    <form
        method="post"
        action="/public/studio/mises-a-jour/debloquer">

        <?= Csrf::field() ?>

        <button
            class="button button-danger"
            type="submit">

            Débloquer

        </button>

    </form>

</section>

<?php endif; ?>

<section class="update-center-card">

    <header>

        <div>

            <h3>

                🚀 Développement

            </h3>

            <p>

                Préparer les futures mises à jour AXIOM.

            </p>

        </div>

    </header>

    <div class="update-dev-panel">

        <div class="update-dev-actions">

            <button
                type="button"
                class="button button-primary">

                + Nouvelle mise à jour

            </button>

        </div>

        <div class="update-empty">

            Aucun brouillon disponible.

        </div>

    </div>

</section>

<section class="update-center-card">

    <header>

        <div>

            <h3>

                Workflow de publication

            </h3>

            <p>

                Cycle de vie complet d'une mise à jour AXIOM.

            </p>

        </div>

    </header>

    <div class="update-workflow">

        <div class="workflow-step">

            <span class="workflow-dot"></span>

            <div>

                <strong>

                    Création

                </strong>

                <small>

                    Préparer une nouvelle mise à jour.

                </small>

            </div>

        </div>

        <div class="workflow-arrow">

            ↓

        </div>

        <div class="workflow-step">

            <span class="workflow-dot"></span>

            <div>

                <strong>

                    Analyse

                </strong>

                <small>

                    Contrôles de sécurité et préflight.

                </small>

            </div>

        </div>

        <div class="workflow-arrow">

            ↓

        </div>

       

               

        <div class="workflow-step">

    <span class="workflow-dot"></span>

    <div>

        <strong>
            Construction
        </strong>

        <small>
            Génération du package signé.
        </small>

        <a
            href="/public/studio/mises-a-jour/build"
            class="button button-primary"
            style="margin-top:12px;display:inline-block;">

            Construire

        </a>

    </div>

</div>

        <div class="workflow-arrow">

            ↓

        </div>

        <div class="workflow-step">

            <span class="workflow-dot"></span>

            <div>

                <strong>

                    Publication

                </strong>

                <small>

                    Disponible dans le Centre de mise à jour.

                </small>

            </div>

        </div>

    </div>

</section>