{#
/**
 * This file is part of FacturaScripts
 * Copyright (C) 2017-2023 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 "MasterMotoTaller/MenuBghTemplate.html.twig" %}

{% block bodyHeaderOptions %}
    {{ parent() }}
    {% set pageData = fsc.getPageData() %}
    {% set firstView = fsc.views | first %}
    <div class="container-fluid kanban-header mb-3 d-print-none">
        <div class="row">
            <div class="col-md-7 col-8">
                <div class="btn-group">
                    <a class="btn btn-sm btn-phoenix-secondary" href="{{ fsc.url() }}"
                       title="{{ trans('refresh') }}">
                        <i class="fas fa-redo" aria-hidden="true"></i>
                    </a>
                    {% if pageData.name == fsc.user.homepage %}
                        <a class="btn btn-sm btn-phoenix-secondary active" href="{{ fsc.url() }}?defaultPage=FALSE"
                           title="{{ trans('marked-as-homepage') }}">
                            <i class="fas fa-bookmark" aria-hidden="true"></i>
                        </a>
                    {% else %}
                        <a class="btn btn-sm btn-phoenix-secondary" href="{{ fsc.url() }}?defaultPage=TRUE"
                           title="{{ trans('mark-as-homepage') }}">
                            <i class="far fa-bookmark" aria-hidden="true"></i>
                        </a>
                    {% endif %}
                </div>
                {# -- Options button -- #}
                {% if firstView.settings.btnOptions %}
                    <div class="btn-group">
                        <div class="dropdown">
                            <button class="btn btn-sm btn-phoenix-secondary dropdown-toggle" type="button"
                                    data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <i class="fas fa-wrench fa-fw" aria-hidden="true"></i> {{ trans('options') }}
                            </button>
                            <div class="dropdown-menu">
                                <h6 class="dropdown-header">{{ trans('options-button-header') }}</h6>
                                {% for viewName, view in fsc.views %}
                                    <a class="dropdown-item"
                                       href="EditPageOption?code={{ viewName }}&url={{ view.model.url() | url_encode }}">
                                        <i class="{{ view.icon }} fa-fw" aria-hidden="true"></i> {{ view.title }}
                                        {% if view.settings.customized %}
                                            <i class="fa-solid fa-user-pen ml-2" title="{{ trans('personalized') }}"></i>
                                        {% endif %}
                                    </a>
                                {% endfor %}
                            </div>
                        </div>
                    </div>
                {% endif %}
            </div>
            <div class="col-md-5 col-4 text-end">
                <h1 class="h4 mb-0 d-md-inline-block" style="text-wrap: nowrap;">
                    {{ fsc.title }}<i class="{{ pageData.icon }} ms-2 ml-3" aria-hidden="true"></i>
                </h1>
            </div>
        </div>
    </div>
    {# -- Tabs -- #}
    <ul class="nav nav-tabs d-print-none" id="mainTabs" role="tablist">
        {% for viewName, view in fsc.views %}
            <li class="nav-item">
                {% set active = (viewName == fsc.active) ? ' active' : '' %}
                <a href="#{{ viewName }}" class="btn btn-phoenix-secondary me-1 ps-2 pe-2{{ active }}" data-bs-toggle="tab" role="tab"
                   aria-controls="{{ viewName }}" title="{{ view.title }}">
                    <i class="{{ view.icon }}" aria-hidden="true"></i>
                    {% if view.title | length > 15 %}
                        <span class="d-none d-sm-inline-block">{{ view.title | slice(0, 15) }}...</span>
                    {% else %}
                        <span class="d-none d-sm-inline-block">{{ view.title }}</span>
                    {% endif %}
                    {% if view.count > 0 %}
                        <span class="badge badge-secondary">{{ number(view.count, 0) }}</span>
                    {% endif %}
                </a>
            </li>
        {% endfor %}
    </ul>
{% endblock %}

{% block body %}
    {{ parent() }}
    {# -- Tab content -- #}
    <div class="tab-content pt-3" id="mainTabsContent">
        {% for viewName, view in fsc.views %}
            {% set active = (viewName == fsc.active) ? ' show active' : '' %}
            <div class="tab-pane fade{{ active }}" id="{{ viewName }}" role="tabpanel">
                {% do fsc.setCurrentView(viewName) %}
                {{ include(view.template) }}
            </div>
        {% endfor %}
    </div>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script>
        $(document).ready(function () {
            if (document.location.hash) {
                $(".nav-tabs a[href=\\" + document.location.hash + "]").tab('show');
            }
            if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) == false) {
                $("input[name='query']:visible").focus();
            }
            $('.nav-tabs a').click(function (e) {
                $(this).tab('show');
                var scrollmem = $('body').scrollTop();
                window.location.hash = this.hash;
                $('html,body').scrollTop(scrollmem);
            });
            $('a[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
                if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) == false) {
                    $("input[name='query']:visible").focus();
                }
            });
        });
    </script>
{% endblock %}
