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

{% block adminContent %}
    <div>
        <h1>Geral</h1>
        <p>Configurações gerais</p>
    </div>

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

    <div class="row row-cols-2">
        <div class="col mb-3">
            {{ form_start(appearanceForm) }}
                <div class="card h-100">
                    <div class="card-header">
                        <i class="fa fa-paint-brush"></i>
                        {{ 'admin.system.appearance'|trans }}
                    </div>
                    <div class="card-body">
                        {{ form_row(appearanceForm.theme) }}

                        {{ form_row(appearanceForm.navbarColor) }}

                        <div class="row">
                            <div class="col-8">
                                <div class="form-group">
                                    <div class="custom-file">
                                        {{ form_label(appearanceForm.logoNavbar) }}
                                        {{ form_widget(appearanceForm.logoNavbar) }}
                                        <small class="form-text text-muted">Tamanho da imagem (100x38)</small>
                                    </div>
                                </div>
                            </div>
                            <div class="col-4">
                                {% if appearanceForm.vars.data.logoNavbar %}
                                    <div>
                                        <img src="{{ appearanceForm.vars.data.logoNavbar }}" style="max-width: 100%">
                                        <button type="button" class="btn btn-danger" data-remove-file="logoNavbar">
                                            <i class="fa fa-trash"></i>
                                        </button>
                                    </div>
                                {% endif %}
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-8">
                                <div class="custom-file">
                                    {{ form_label(appearanceForm.logoLogin) }}
                                    {{ form_widget(appearanceForm.logoLogin) }}
                                    <small class="form-text text-muted">Tamanho da imagem (270x107)</small>
                                </div>
                            </div>
                            <div class="col-4">
                                {% if appearanceForm.vars.data.logoLogin %}
                                    <div>
                                        <img src="{{ appearanceForm.vars.data.logoLogin }}" style="max-width: 100%">
                                        <button type="button" class="btn btn-danger" data-remove-file="logoLogin">
                                            <i class="fa fa-trash"></i>
                                        </button>
                                    </div>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">
                            <i class="fa fa-save"></i>
                            {{ 'button.save'|trans }}
                        </button>
                    </div>
                </div>
            {{ form_end(appearanceForm) }}
        </div>
        <div class="col mb-3">
            {{ form_start(queueForm) }}
                <div class="card h-100">
                    <div class="card-header">
                        <i class="fa fa-cogs"></i>
                        {{ 'admin.system.queue_ordering'|trans }}
                    </div>
                    {{ form_row(queueForm.ordering, { label: false }) }}
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">
                            <i class="fa fa-save"></i>
                            {{ 'button.save'|trans }}
                        </button>
                    </div>
                </div>
            {{ form_end(queueForm) }}
        </div>
    </div>
    <div class="row">
        <div class="col">
            {{ form_start(behaviorForm) }}
                <div class="card mb-3">
                    <div class="card-header">
                        <i class="fa fa-handshake-o"></i>
                        {{ 'admin.system.behavior'|trans }}
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col">
                                {{ form_row(behaviorForm.prioritySwap) }}
                                {{ form_row(behaviorForm.prioritySwapMethod) }}
                                {{ form_row(behaviorForm.prioritySwapCount) }}
                                {{ form_row(behaviorForm.appointmentConfirmationDelay) }}
                            </div>
                            <div class="col">
                                {{ form_row(behaviorForm.callTicketByService) }}
                                {{ form_row(behaviorForm.callTicketOutOfOrder) }}
                                {{ form_row(behaviorForm.changeTicketType) }}
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">
                            <i class="fa fa-save"></i>
                            {{ 'button.save'|trans }}
                        </button>
                    </div>
                </div>
            {{ form_end(behaviorForm) }}
        </div>
    </div>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script>
        (function () {
            'use strict'

            const btns = [...document.querySelectorAll('[data-remove-file]')];
            btns.forEach((elem) => {
                elem.addEventListener('click', (e) => {
                    if (confirm('Deseja realmente remover o arquivo?')) {
                        fetch(`{{ path("admin_remove_settings_file") }}?key=${e.currentTarget.dataset.removeFile}`, {
                            method: 'DELETE',
                        }).then(() => {
                            window.location.reload();
                        });
                    }
                });
            });
        })();
    </script>
{% endblock %}
