<?php

/**
 * @var Mobicms\Render\Template\Template $this
 * @var string|null $message
 * @var array<string, array<string, mixed>> $languages
 * @var string $manage_url
 * @var string $csrf_token
 */

$this->layout('system::layout/default');

$action = function (string $action, string $code, string $label) use ($manage_url): string {
    return '<form method="post" action="' . $this->e($manage_url . '/' . $action) . '" class="d-inline me-2">'
        . '<input type="hidden" name="csrf_token" value="' . $csrf_token . '">'
        . '<input type="hidden" name="code" value="' . $this->e($code) . '">'
        . '<button type="submit" class="btn btn-link p-0 align-baseline">' . $label . '</button>'
        . '</form>';
};
?>
<?php if (! empty($message)): ?>
    <div class="alert alert-success shadow border-0"><?= $this->e($message) ?></div>
<?php endif; ?>
<div>
    <?php foreach ($languages as $key => $val): ?>
        <div class="new_post-item without_avatar">
            <div class="d-flex justify-content-between">
                <div>
                    <?php if (! empty($val['flag'])): ?>
                        <img src="<?= $this->e($val['flag']) ?>" alt="." class="me-2 icon icon-flag">
                    <?php endif ?>
                    <?= $this->e($val['name']) ?>
                </div>
            </div>
            <div class="post-body">
                <span class="me-2"><?= __('Version:') ?> <?= number_format((float) $val['version'], 1) ?></span>
                <?php if (! empty($val['need_update'])): ?>
                    <span class="me-2 fw-bold"><?= __('New version:') ?> <?= number_format((float) $val['new_version'], 1) ?></span>
                <?php endif; ?>
                <?php if (! empty($val['installed'])): ?>
                    <span class="text-success"><?= __('Installed') ?></span>
                <?php else: ?>
                    <span class="text-danger"><?= __('Not installed') ?></span>
                <?php endif; ?>
            </div>
            <div class="post-meta d-flex align-items-baseline">
                <?php if (! empty($val['access_problem'])): ?>
                    <div class="fw-bold text-danger"><?= __('The language files of this language are not writable! ') ?></div>
                <?php else: ?>
                    <?php if (! empty($val['installed'])): ?>
                        <?= $action('delete', (string) $key, __('Delete')) ?>
                    <?php else: ?>
                        <?= $action('install', (string) $key, __('Install')) ?>
                    <?php endif; ?>
                    <?php if (! empty($val['need_update'])): ?>
                        <?= $action('update', (string) $key, __('Update')) ?>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
        </div>
    <?php endforeach ?>
    <div class="mt-3">
        <a href="/admin/languages"><?= __('Back') ?></a>
    </div>
</div>
