{#
/**
 * Copyright © 2003-2024 The Galette Team
 *
 * This file is part of Galette (https://galette.eu).
 *
 * Galette is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Galette 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
 */
#}
{% extends 'page.html.twig' %}

{% import "macros.twig" as macros %}

{% block content %}
    <div class="ui grid">
{% if not hide_telemetry and not callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
        <div class="sixteen wide column">
            <div class="ui yellow message">
                <div class="header">{{ _T("Help us know about you!") }}</div>
                <div class="ui stackable grid">
                    <div class="sixteen wide column">
                        <p>
                            {{ _T("Take a moment to share some information with us so we can know better Galette's uses.") }}
                        </p>
                    </div>
                    <div class="sixteen wide column">
                        <div class="ui wrapping spaced buttons">
            {% if not telemetry_sent %}
                            <a id="telemetry" class="large ui blue button" href="#" title="{{ _T("Send anonymous and imprecise data about your Galette instance") }}">
                                <i class="chart bar icon" aria-hidden="true"></i>
                                {{ _T("Telemetry") }}
                            </a>
            {% endif %}
            {% if not registered %}
                            <a class="large ui blue button" href="{{ constant('GALETTE_TELEMETRY_URI') }}reference?showmodal&uuid={{ reguuid }}" title="{{ _T("Register your organization as a Galette user") }}" target="_blank">
                                <i class="id card icon" aria-hidden="true"></i>
                                {{ _T("Register") }}
                            </a>
            {% endif %}
                        </div>
                        <div class="tooltip jsonly displaynone ui toggle checkbox" title="{{ _T("The panel will be automatically hidden once you have registered and send telemetry data. Check the box if you want to hide it anyways.") }}">
                            <input type="checkbox" name="hide_telemetry" id="hide_telemetry" value="1" {% if hide_telemetry %} checked="checked"{% endif %} />
                            <label for="hide_telemetry">{{ _T("Hide this panel") }}</label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
{% endif %}
        <div class="sixteen wide{% if news|length > 0 %} tablet ten wide computer{% endif %} column">
            <div class="ui attached yellow segment">
                <div class="ui medium header">{{ _T("Activities") }}</div>
            </div>
            <div id="main-activities" class="ui bottom attached segment">
                <div class="ui three stackable cards">
                    {% set dashboard_entries = callstatic('\\Galette\\Core\\Galette', 'getDashboards') %}
                    {% for dashboard_entry in dashboard_entries %}
                        {{ macros.dashboardCard(
                            dashboard_entry.label,
                            dashboard_entry.title ?? null,
                            dashboard_entry.route,
                            dashboard_entry.icon,
                        ) }}
                    {% endfor %}
                 </div>
             </div>
        </div>
{% if news|length > 0 %}
        <div class="sixteen wide tablet six wide computer column">
            <div class="ui attached yellow segment">
                <div class="ui medium header">{{ _T("News") }}</div>
            </div>
            <div class="ui bottom attached segment">
                <div class="ui bulleted list">
    {% for post in news %}
                    <div class="item">
                        <a href="{{ post.url }}" target="_blank">{{ post.title }}</a>
                    </div>
    {% endfor %}
                </div>
            </div>
        </div>
{% endif %}
        <div class="jsonly displaynone sixteen wide column">
            <div class="ui basic vertically fitted segment">
                <div class="ui toggle checkbox">
                    <input type="checkbox" name="show_dashboard" id="show_dashboard" value="1"{% if show_dashboard %} checked="checked"{% endif %}/>
                    <label for="show_dashboard">{{ _T("Show dashboard on login") }}</label>
                </div>
            </div>
        </div>
    </div>

    {% if not hide_telemetry and not telemetry_sent %}
        {% include "modals/telemetry.html.twig" with {part: "dialog"} %}
    {% endif %}
{% endblock %}

{% block javascripts %}
    <script>
        $(function() {
            $('#show_dashboard').change(function(){
                var _checked = $(this).is(':checked');
                Cookies.set(
                    'show_galette_dashboard',
                    (_checked ? 1 : 0),
                        {
                            expires: 365,
                            path: '/'
                        }
                );
                if ( !_checked ) {
                    var _url = '{{ url_for('members') }}';
                    window.location.replace(_url);
                }
            });

{% if not hide_telemetry %}
            $('#hide_telemetry').change(function(){
                var _checked = $(this).is(':checked');
                Cookies.set(
                    'hide_galette_telemetry',
                    (_checked ? 1 : 0),
                        {
                            expires: 365,
                            path: '/'
                        }
                );
                var _url = '{{ url_for('dashboard') }}';
                window.location.replace(_url);
            });

    {% if not telemetry_sent %}
        {% include "modals/telemetry.html.twig" with {part: "jsdialog", orig: "desktop"} %}
    {% endif %}
    {% if not registered %}
        {% include "modals/telemetry.html.twig" with {part: "jsregister", orig: "desktop"} %}
    {% endif %}
{% endif %}
        });
    </script>
{% endblock %}
