<!doctype html>
<html lang="en">
    <head>
        <title>{{ repository }}</title>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="shortcut icon" href="/static/favicon.ico">

        {% include "utils/style.jinja2" %}
    </head>

    <body>

        <div class="container">
            <h1>ahriman
                {% if auth.authenticated %}
                    <img src="https://img.shields.io/badge/version-{{ version }}-informational" alt="{{ version }}">
                    <img src="https://img.shields.io/badge/repository-{{ repository }}-informational" alt="{{ repository }}">
                    <img src="https://img.shields.io/badge/architecture-{{ architecture }}-informational" alt="{{ architecture }}">
                    <img src="https://img.shields.io/badge/service%20status-{{ service.status }}-{{ service.status_color }}" alt="{{ service.status }}" title="{{ service.timestamp }}">
                {% endif %}
            </h1>
        </div>

        <div class="container">
            <div id="toolbar">
                {% if not auth.enabled or auth.username is not none %}
                    <button id="add" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addForm">
                        <i class="fa fa-plus"></i> Add
                    </button>
                    <button id="update" class="btn btn-secondary" onclick="updatePackages()" disabled>
                        <i class="fa fa-play"></i> Update
                    </button>
                    <button id="remove" class="btn btn-danger" onclick="removePackages()" disabled>
                        <i class="fa fa-trash"></i> Remove
                    </button>
                {% endif %}
            </div>

            <table id="packages" class="table table-striped table-hover"
                   data-click-to-select="true"
                   data-export-options='{"fileName": "packages"}'
                   data-page-list="[10, 25, 50, 100, all]"
                   data-page-size="10"
                   data-pagination="true"
                   data-resizable="true"
                   data-search="true"
                   data-show-columns="true"
                   data-show-columns-search="true"
                   data-show-columns-toggle-all="true"
                   data-show-export="true"
                   data-show-fullscreen="true"
                   data-show-search-clear-button="true"
                   data-sortable="true"
                   data-sort-reset="true"
                   data-toggle="table"
                   data-toolbar="#toolbar">
                <thead class="table-primary">
                    <tr>
                        <th data-checkbox="true"></th>
                        <th data-sortable="true" data-switchable="false">package base</th>
                        <th data-sortable="true">version</th>
                        <th data-sortable="true">packages</th>
                        <th data-sortable="true" data-visible="false">groups</th>
                        <th data-sortable="true" data-visible="false">licenses</th>
                        <th data-sortable="true">last update</th>
                        <th data-sortable="true">status</th>
                    </tr>
                </thead>

                <tbody>
                {% if auth.authenticated %}
                    {% for package in packages %}
                        <tr data-package-base="{{ package.base }}">
                            <td data-checkbox="true"></td>
                            <td><a href="{{ package.web_url }}" title="{{ package.base }}">{{ package.base }}</a></td>
                            <td>{{ package.version }}</td>
                            <td>{{ package.packages|join("<br>"|safe) }}</td>
                            <td>{{ package.groups|join("<br>"|safe) }}</td>
                            <td>{{ package.licenses|join("<br>"|safe) }}</td>
                            <td>{{ package.timestamp }}</td>
                            <td class="table-{{ package.status_color }}">{{ package.status }}</td>
                        </tr>
                    {% endfor %}
                {% else %}
                    <tr>
                        <td colspan="100%">In order to see statuses you must login first.</td>
                    </tr>
                {% endif %}
                </tbody>
            </table>
        </div>

        <div class="container">
            <footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
                <ul class="nav">
                    <li><a class="nav-link" href="https://github.com/arcan1s/ahriman" title="sources">ahriman</a></li>
                    <li><a class="nav-link" href="https://github.com/arcan1s/ahriman/releases" title="releases list">releases</a></li>
                    <li><a class="nav-link" href="https://github.com/arcan1s/ahriman/issues" title="issues tracker">report a bug</a></li>
                </ul>

                {% if index_url is not none %}
                    <ul class="nav">
                        <li><a class="nav-link" href="{{ index_url }}" title="repo index">repo index</a></li>
                    </ul>
                {% endif %}

                {% if auth.enabled %}
                    {% if auth.username is none %}
                        {{ auth.control|safe }}
                    {% else %}
                        <form action="/user-api/v1/logout" method="post">
                            <button class="btn btn-link" style="text-decoration: none">logout ({{ auth.username }})</button>
                        </form>
                    {% endif %}
                {% endif %}
            </footer>
        </div>

        {% if auth.enabled %}
            {% include "build-status/login-modal.jinja2" %}
        {% endif %}

        {% include "build-status/package-actions-modals.jinja2" %}

        {% include "utils/bootstrap-scripts.jinja2" %}

        {% include "build-status/package-actions-script.jinja2" %}

    </body>

</html>
