{#
/**
 * Copyright (C) 2024 Xibo Signage Ltd
 *
 * Xibo - Digital Signage - https://xibosignage.com
 *
 * This file is part of Xibo.
 *
 * Xibo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Xibo 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 */
#}

{% extends "form-base.twig" %}
{% import "forms.twig" as forms %}

{% block formTitle %}
    {% trans "Edit User Group" %}
{% endblock %}

{% block formButtons %}
    {% trans "Cancel" %}, XiboDialogClose()
    {% trans "Save" %}, $("#userGroupEditForm").submit()
{% endblock %}

{% block callBack %}userGroupFormOpen{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <ul class="nav nav-tabs" role="tablist">
                <li class="nav-item"><a class="nav-link active" href="#general-tab" role="tab" data-toggle="tab"><span>{% trans "General" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#description-tab" role="tab" data-toggle="tab"><span>{% trans "Description" %}</span></a></li>
                {% if currentUser.userTypeId == 1 %}
                <li class="nav-item"><a class="nav-link" href="#notifications-tab" role="tab" data-toggle="tab"><span>{% trans "Notifications" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#onboarding-tab" role="tab" data-toggle="tab"><span>{% trans "Onboarding Settings" %}</span></a></li>
                {% endif %}
            </ul>
            <form id="userGroupEditForm" class="UserGroupForm form-horizontal" method="put" action="{{ url_for("group.edit", {"id": group.groupId}) }}">
                <div class="tab-content">
                    <div class="tab-pane active" id="general-tab">

                        {% set title %}{% trans "Name" %}{% endset %}
                        {% set helpText %}{% trans "The Name for this User Group" %}{% endset %}
                        {{ forms.input("group", title, group.group, helpText, "", "required maxlength='50'") }}

                        {% set title %}{% trans "Library Quota" %}{% endset %}
                        {% set helpText %}{% trans "The quota that should be applied. Enter 0 for no quota." %}{% endset %}
                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="libraryQuota">{{ title }}</label>
                            <div class="col-sm-6">
                                <input class="form-control" name="libraryQuota" type="number" id="libraryQuota" value="{{ group.libraryQuota }}" />
                                <span class="help-block">{{ helpText }}</span>
                            </div>
                            <div class="col-sm-4">
                                <select name="libraryQuotaUnits" class="form-control">
                                    <option value="kb">KiB</option>
                                    <option value="mb">MiB</option>
                                    <option value="gb">GiB</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    {% if currentUser.userTypeId == 1 %}
                        <div class="tab-pane" id="notifications-tab">
                            {% set title %}{% trans "Receive System Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive system notifications?" %}{% endset %}
                            {{ forms.checkbox("isSystemNotification", title, group.isSystemNotification, helpText) }}

                            {% set title %}{% trans "Receive Display Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Display notifications for Displays they have permission to see?" %}{% endset %}
                            {{ forms.checkbox("isDisplayNotification", title, group.isDisplayNotification, helpText) }}

                            {% set title %}{% trans "Receive DataSet Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive DataSet emails?" %}{% endset %}
                            {{ forms.checkbox("isDataSetNotification", title, group.isDataSetNotification, helpText) }}

                            {% set title %}{% trans "Receive Layout Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Layout emails?" %}{% endset %}
                            {{ forms.checkbox("isLayoutNotification", title, group.isLayoutNotification, helpText) }}

                            {% set title %}{% trans "Receive Library Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Library notification emails?" %}{% endset %}
                            {{ forms.checkbox("isLibraryNotification", title, group.isLibraryNotification, helpText) }}

                            {% set title %}{% trans "Receive Report Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Report emails?" %}{% endset %}
                            {{ forms.checkbox("isReportNotification", title, group.isReportNotification, helpText) }}

                            {% set title %}{% trans "Receive Schedule Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Schedule emails?" %}{% endset %}
                            {{ forms.checkbox("isScheduleNotification", title, group.isScheduleNotification, helpText) }}

                            {% set title %}{% trans "Receive Custom Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive notifications emails for Notifications manually created in CMS?" %}{% endset %}
                            {{ forms.checkbox("isCustomNotification", title, group.isCustomNotification, helpText) }}
                        </div>
                    {% endif %}

                    <div class="tab-pane" id="description-tab">
                        {% set title %}{% trans "Description" %}{% endset %}
                        {% set helpText %}{% trans "An optional description of the user group. (1 - 500 characters)" %}{% endset %}
                        {{ forms.textarea("description", title, group.description, helpText, "", "", 15) }}
                    </div>

                    {% if currentUser.userTypeId == 1 %}
                    <div class="tab-pane" id="onboarding-tab">
                        {% set title %}{% trans "Show when onboarding a new user?" %}{% endset %}
                        {% set helpText %}{% trans "Should this User Group be available for selection when creating a New User via the onboarding form?" %}{% endset %}
                        {{ forms.checkbox("isShownForAddUser", title, group.isShownForAddUser, helpText) }}

                        {% set title %}{% trans "Default Homepage" %}{% endset %}
                        {% set helpText %}{% trans "Default Homepage for users created with this group." %}{% endset %}
                        {% set homepagesUrl %}{{ url_for("user.homepages.search") }}?userTypeId=1{% endset %}
                        {% set attributes = [
                            { name: "data-live-search", value: "true" },
                            { name: "data-allow-clear", value: "true" },
                            { name: "data-placeholder--id", value: null },
                            { name: "data-placeholder--value", value: "" },
                            { name: "data-search-url", value: homepagesUrl },
                            { name: "data-search-term", value: "homepage" },
                            { name: "data-id-property", value: "homepage" },
                            { name: "data-text-property", value: "title" },
                            { name: "data-initial-key", value: "homepage" },
                            { name: "data-initial-value", value: group.defaultHomepageId }
                        ] %}
                        {{ forms.dropdown("defaultHomepageId", "single", title, "", null, "homepage", "title", helpText, "pagedSelect", "", "", "", attributes) }}
                    </div>
                    {% endif %}
                </div>
            </form>
        </div>
    </div>
{% endblock %}