{#
 # This file is part of SolidInvoice package.
 #
 # (c) Pierre du Plessis <open-source@solidworx.co>
 #
 # This source file is subject to the MIT license that is bundled
 # with this source code in the file LICENSE.
 #}

{% extends '@SolidInvoiceInstall/layout.html.twig' %}

{% block subtitle %}
    Requirements Check
{% endblock subtitle %}

{% from _self import requirementCheck %}

{% macro requirementCheck(requirement) %}
    <li class="list-group-item">
        {% if requirement.fulfilled %}
            <span class="text-success">
                {{ icon('check') }}
            </span>
        {% elseif not requirement.optional %}
            <span class="text-danger">
                {{ icon('ban') }}
            </span>
        {% else %}
            <span class="text-warning">
                {{ icon('exclamation-triangle') }}
            </span>
        {% endif %}

        {{ requirement.testMessage }}

        {% if not requirement.fulfilled %}
            <p class="list-group-item-text">
                <small><i>{{ requirement.helpHtml|raw }}</i></small>
            </p>
        {% endif %}
    </li>
{% endmacro %}

{% block content %}
    {% if requirements.failedRequirements|length > 0 %}
        <div class="alert alert-danger">
            <div class="d-none col-sm-1">
                {{ icon('ban', ['fa-4x']) }}
            </div>
            <strong>{{ 'installation.requirements.not_met'|trans }}</strong>
            <br />
            {{ 'installation.requirements.message'|trans }}
            <br class="clear" />
        </div>
    {% endif %}

    <div class="row">
        <div class="col-10 offset-1">
            <div class="card card-primary">
                <div class="card-header with-border">
                    <h3 class="card-title">{{ icon('check') }} {{ 'installation.config.title.requirements_check'|trans }}</h3>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6 d-flex">
                            <ul class="list-group">
                                <li class="list-group-item disabled" aria-disabled="true">
                                    {{ 'installation.requirements.mandatory'|trans }}
                                </li>
                                {% for requirement in requirements.requirements %}
                                    {{ requirementCheck(requirement) }}
                                {% endfor %}
                            </ul>
                        </div>
                        <div class="col-md-6 d-flex">
                            <ul class="list-group">
                                <li class="list-group-item disabled" aria-disabled="true">
                                    {{ 'installation.requirements.optional'|trans }}
                                </li>
                                {% for requirement in requirements.recommendations %}
                                    {{ requirementCheck(requirement) }}
                                {% endfor %}
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="card-footer">
                    <div class="row">
                        <div class="col align-self-start">
                            <a href="{{ path('_install_check_requirements') }}" class="btn btn-warning btn-block">
                                {{ icon('refresh') }} {{ "installation.action.refresh"|trans }}
                            </a>
                        </div>
                        <div class="col-7">
                        </div>
                        <div class="col">
                            <a id="continue_step" href="{{ path('_install_config') }}" class="btn btn-success float-right btn-block{% if requirements.failedRequirements|length > 0 %} disabled{% endif %}">
                                {{ "installation.action.next"|trans }} {{ icon('arrow-right') }}
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
