{% extends "admin.html.twig" %}

{% block adminContent %}
    <h1>
        {{ 'admin.services.title'|trans }}
        <small>
            {{ 'admin.services.subtitle'|trans }}
        </small>
    </h1>

    <hr>

    {{ form_start(form) }}

        {% include 'flashMessages.html.twig' %}

        <div class="row">
            <div class="col-md-12">
                {{ form_row(form.ativo) }}
            </div>
            <div class="col-md-6">

                {{ form_row(form.nome) }}

                {{ form_row(form.descricao) }}

                {{ form_row(form.peso) }}

                {% if form.mestre is defined %}
                    {{ form_row(form.mestre) }}
                {% endif %}
            </div>
            <div class="col-md-6">
                {% if entity.subServicos|length %}
                    <fieldset>
                        <legend>{{ 'admin.services.childs'|trans }}</legend>
                        <table class="table table-bordered">
                            <thead class="thead-light">
                                <tr>
                                    <th>{{ 'admin.services.field.name'|trans }}</th>
                                    <th>{{ 'admin.services.field.weight'|trans }}</th>
                                    <th>{{ 'label.status'|trans }}</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for sub in entity.subServicos %}
                                    {% if not sub.deletedAt %}
                                        <tr>
                                            <td>{{ sub.nome }}</td>
                                            <td>{{ sub.peso }}</td>
                                            <td>
                                                {% if sub.ativo %}
                                                    <span class="text-success">{{ 'label.enabled'|trans }}</span>
                                                {% else %}
                                                    <span class="text-danger">{{ 'label.disabled'|trans }}</span>
                                                {% endif %}
                                            </td>
                                            <td class="text-center">
                                                <a href="{{ path('admin_servicos_edit', {id: sub.id }) }}" class="btn btn-secondary">
                                                    <i class="fa fa-edit"></i>
                                                </a>
                                            </td>
                                        </tr>
                                    {% endif %}
                                {% endfor %}
                            </tbody>
                        </table>
                    </fieldset>
                {% endif %}
            </div>
        </div>

        <button type="submit" class="btn btn-primary">
            <i class="fa fa-check"></i>
            {{ 'button.save'|trans }}
        </button>
        <a href="{{ path('admin_servicos_index') }}" class="btn btn-secondary">
            <i class="fa fa-chevron-left"></i>
            {{ 'button.back'|trans }}
        </a>
        {% if entity.id %}
            <button type="submit" class="btn btn-danger pull-right" name="_method" value="DELETE">
                <i class="fa fa-trash"></i>
                {{ 'button.remove'|trans }}
            </button>
        {% endif %}

    {{ form_end(form) }}
{% endblock %}
