{#
    /**
     * This file is part of FacturaScripts
     * Copyright (C) 2017-2019 Carlos Garcia Gomez <carlos@facturascripts.com>
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     * GNU Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public License
     * along with this program. If not, see http://www.gnu.org/licenses/.
     */
#}
{% extends "Master/MenuTemplate.html.twig" %}

{% block body %}
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-6">
                <div class="btn-group">
                    <a href="AdminPlugins" class="btn btn-sm btn-outline-secondary">
                        <i class="fas fa-arrow-left fa-fw" aria-hidden="true"></i>
                        <span class="d-none d-md-inline-block">{{ i18n.trans('plugins') }} </span>
                    </a>
                    <a href="{{ fsc.url() }}" class="btn btn-sm btn-outline-secondary" title="{{ i18n.trans('refresh') }}">
                        <i class="fas fa-redo" aria-hidden="true"></i>
                    </a>
                </div>
                {% if fsc.telemetryManager.ready() %}
                    <button class="btn btn-sm btn-secondary" type="button" data-toggle="modal" data-target="#modalTelemetry">
                        <i class="fas fa-registered fa-fw" aria-hidden="true"></i>
                        <span class="d-none d-md-inline-block">{{ i18n.trans('register-installation') }} </span>
                    </button>
                {% else %}
                    <button class="btn btn-sm btn-warning" type="button" data-toggle="modal" data-target="#modalTelemetry">
                        <i class="fas fa-registered fa-fw" aria-hidden="true"></i>
                        <span class="d-none d-md-inline-block">{{ i18n.trans('register-installation') }}</span>
                    </button>
                {% endif %}
            </div>
            <div class="col-sm-6 text-right">
                <h1 class="h3">
                    {{ i18n.trans('updater') }}
                    <small class="text-info">{{ fsc.getCoreVersion() }}</small>
                    <i class="fas fa-cloud-download-alt" aria-hidden="true"></i>
                </h1>
            </div>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th scope="col">{{ i18n.trans('component') }}</th>
                    <th scope="col">{{ i18n.trans('description') }}</th>
                    <th scope="col" class="text-right">{{ i18n.trans('action') }}</th>
                </tr>
            </thead>
            <tbody>
                {% for item in fsc.updaterItems %}
                    <tr class="{{ item.stable ? 'table-success' : 'table-warning' }}">
                        <td>{{ item.name }}</td>
                        <td>{{ item.description }}</td>
                        <td class="text-right">
                            {% if item.downloaded %}
                                <a href="{{ fsc.url() }}?action=update&item={{ item.id }}" class="btn btn-sm btn-success">
                                    <i class="fas fa-rocket fa-fw" aria-hidden="true"></i> {{ i18n.trans('update') }}
                                </a>
                                <a href="{{ fsc.url() }}?action=cancel&item={{ item.id }}" class="btn btn-sm btn-warning">
                                    <i class="fas fa-times fa-fw" aria-hidden="true"></i> {{ i18n.trans('cancel') }}
                                </a>
                            {% elseif item.stable %}
                                <a href="{{ fsc.url() }}?action=download&item={{ item.id }}" class="btn btn-sm btn-secondary">
                                    <i class="fas fa-cloud-download-alt fa-fw" aria-hidden="true"></i> {{ i18n.trans('download') }}
                                </a>
                            {% else %}
                                <a href="{{ fsc.url() }}?action=download&item={{ item.id }}" class="btn btn-sm btn-outline-warning">
                                    <i class="fas fa-flask fa-fw" aria-hidden="true"></i> {{ i18n.trans('beta') }}
                                </a>
                            {% endif %}
                        </td>
                    </tr>
                {% else %}
                    <tr class="table-warning">
                        <td colspan="3"><b>{{ i18n.trans('no-data') }}</b></td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    <div class="modal fade" id="modalTelemetry" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                {% if fsc.telemetryManager.ready() %}
                    <div class="modal-header">
                        <h5 class="modal-title">{{ i18n.trans('registered-installation', {'%number%': fsc.telemetryManager.id()}) }}</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="{{ i18n.trans('close') }}">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <p>{{ i18n.trans('registered-installation-p') }}</p>
                        <a class="btn btn-primary" href="{{ fsc.url() }}?action=claim-install" target="_blank">
                            {{ i18n.trans('manage') }}
                        </a>
                    </div>
                {% else %}
                    <form action="{{ fsc.url() }}" method="post">
                        <input type="hidden" name="action" value="register" />
                        <div class="modal-header">
                            <h5 class="modal-title">{{ i18n.trans('register-installation') }}</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="{{ i18n.trans('close') }}">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <p>{{ i18n.trans('register-installation-p') }}</p>
                            <button type="submit" class="btn btn-primary">
                                {{ i18n.trans('register-installation') }}
                            </button>
                        </div>
                    </form>
                {% endif %}
            </div>
        </div>
    </div>
{% endblock %}
