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

{% block adminContent %}
    <div class="d-flex">
        <div>
            <h1>{{ 'admin.services.title'|trans }}</h1>
            <p>{{ 'admin.services.subtitle'|trans }}</p>
        </div>
    </div>

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

    {{ form_start(form) }}

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

                {{ 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">
                            <thead class="thead-light">
                                <tr>
                                    <th>{{ 'label.name'|trans }}</th>
                                    <th>{{ 'label.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>

        <div class="d-flex">
            <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-link text-decoration-none ms-2">
                <i class="fa fa-chevron-left"></i>
                {{ 'button.back'|trans }}
            </a>
            {% if entity.id %}
                <button type="submit" class="btn btn-danger ms-auto" form="delete-form">
                    <i class="fa fa-trash"></i> 
                    {{ 'button.remove'|trans }}
                </button>
            {% endif %}
        </div>

    {{ form_end(form) }}

    {% if entity.id %}
        <form
            id="delete-form"
            method="post"
            action="{{ path('admin_servicos_delete', { id: entity.id }) }}"
            onsubmit="return confirm('Você realmente deseja remover?')">
        </form>
    {% endif %}
{% endblock %}
