{% extends 'layouts/app.twig' %}
{% import 'macros/base.twig' as m %}
{% import 'macros/form.twig' as f %}

{% block title %}{{ __('registration.title') }}{% endblock %}

{% block content %}
<div class="container">
    <div class="mb-5">
        <h1>
        {{ has_permission_to('admin_user')
            ? m.button(m.icon('chevron-left'), url('/users'), null, 'sm', __('general.back'))
            : ''
        }}
        {{ __('registration.title') }}
        </h1>
    </div>

    {% include 'layouts/parts/messages.twig' %}

    <form method="post" action="{{ url('/register') }}" novalidate class="mb-5">
        {{ csrf() }}

        <div class="mb-5">
            <h2>{{ __('registration.login_data') }}</h2>
            <div class="row">
                {% if isPronounEnabled %}
                    <div class="col-md-6">
                        {{ f.input(
                            'pronoun',
                            __('settings.profile.pronoun'),
                            {
                                'max_length': 15,
                                'required': isPronounRequired,
                                'required_icon': isPronounRequired,
                                'value': f.formData('pronoun', ''),
                            }
                        ) }}
                    </div>
                {% endif %}

                <div class="col-md-6">
                    {{ f.input(
                        'username',
                        __('general.nick'),
                        {
                            'autocomplete': 'nickname',
                            'max_length': 24,
                            'required': true,
                            'required_icon': true,
                            'value': f.formData('username', ''),
                        }
                    ) }}
                </div>

                {% if not isPronounEnabled %}
                    {# Insert an empty row to keep password / email in line #}
                    <div class="col-md-6"></div>
                {% endif %}

                {% if isPasswordEnabled %}
                    <div class="col-md-6">
                        {{ f.input(
                            'password',
                            __('settings.password'),
                            {
                                'type': 'password',
                                'autocomplete': 'new-password',
                                'required': true,
                                'required_icon': true,
                                'min_length': minPasswordLength,
                                'info': __('password.minimal_length', [minPasswordLength]),
                            }
                        ) }}
                    </div>
                    <div class="col-md-6">
                        {{ f.input(
                            "password_confirmation",
                            __('settings.password.new_password2'),
                            {
                                'type': 'password',
                                'autocomplete': 'new-password',
                                'required': true,
                                'required_icon': true,
                                'min_length': minPasswordLength,
                            }
                        ) }}
                    </div>
                {% endif %}

                <div class="col-md-6">
                    {{ f.input(
                        'email',
                        __('general.email'),
                        {
                            'type': 'email',
                            'max_length': 254,
                            'required': true,
                            'required_icon': true,
                            'value': f.formData('email', ''),
                        }
                    ) }}
                </div>
                <div class="col-md-6">
                    <label class="form-label">{{ __('settings.profile.email-preferences') }}</label>
                    <ul class="list-group">
                        <li class="list-group-item">
                            {# Empty class to prevent the default bottom margin #}
                            {{ f.checkbox(
                                'email_shiftinfo',
                                __(
                                    'settings.profile.email_shiftinfo',
                                    [config('app_name')]
                                ),
                                {
                                    'class': '',
                                    'checked': f.formData('email_shiftinfo', false),
                                },
                            ) }}
                        </li>
                        <li class="list-group-item">
                            {# Empty class to prevent the default bottom margin #}
                            {{ f.checkbox(
                                'email_news',
                                __('settings.profile.email_news'),
                                {
                                    'class': '',
                                    'checked': f.formData('email_news', false),
                                },
                            ) }}
                        </li>
                        <li class="list-group-item">
                            {# Empty class to prevent the default bottom margin #}
                            {{ f.checkbox(
                                'email_messages',
                                __('settings.profile.email_messages'),
                                {
                                    'class': '',
                                    'checked': f.formData('email_messages', false),
                                },
                            ) }}
                        </li>
                        <li class="list-group-item">
                            {# Empty class to prevent the default bottom margin #}
                            {{ f.checkbox(
                                'email_by_human_allowed',
                                __('settings.profile.email_by_human_allowed'),
                                {
                                    'class': '',
                                    'checked': f.formData('email_by_human_allowed', false),
                                },
                            ) }}
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        {% if isFullNameEnabled %}
            <div class="mb-5">
                <h2>{{ __('general.name') }}</h2>
                <div class="row">
                    <div class="col-md-6">
                        {{ f.input(
                            'firstname',
                            __('settings.profile.firstname'),
                            {
                                'autocomplete': 'given-name',
                                'max_length': 64,
                                'required': isFirstnameRequired,
                                'required_icon': isFirstnameRequired,
                                'value': f.formData('firstname', ''),
                            }
                        ) }}
                    </div>
                    <div class="col-md-6">
                        {{ f.input(
                            'lastname',
                            __('settings.profile.lastname'),
                            {
                                'autocomplete': 'family-name',
                                'max_length': 64,
                                'required': isLastnameRequired,
                                'required_icon': isLastnameRequired,
                                'value': f.formData('lastname', ''),
                            }
                        ) }}
                    </div>
                </div>
            </div>
        {% endif %}

        <div class="mb-5">
            <h2>{{ __('registration.event_data') }}</h2>
            <div class="row">
                {% if isGoodieEnabled %}
                    <div class="col-md-6">
                        {% set privacy_email = config('privacy_email') %}
                        {% set email_goody_label = __('settings.profile.email_goody') ~
                            (privacy_email ? ' ' ~ __('settings.profile.privacy', [privacy_email]) : '')
                        %}
                        {{ f.checkbox(
                            'email_goody',
                            email_goody_label,
                            {
                                'raw_label': true,
                                'checked': f.formData('email_goody', false),
                            },
                        ) }}
                    </div>
                    <div class="col-md-6"></div>
                {% endif %}

                {% if isPlannedArrivalDateEnabled %}
                    <div class="col-md-6">
                        {{ f.input(
                            'planned_arrival_date',
                            __('settings.profile.planned_arrival_date'),
                            {
                                'type': 'date',
                                'min': buildUpStartDate,
                                'max': tearDownEndDate,
                                'required': true,
                                'required_icon': true,
                                'value': f.formData('planned_arrival_date', buildUpStartDate),
                            }
                        ) }}
                    </div>
                {% endif %}

                {% if isGoodieTShirt %}
                    <div class="col-md-6">
                        {{ f.select(
                            'tshirt_size',
                            __('settings.profile.shirt_size'),
                            tShirtSizes,
                            {
                                'default_option': __('form.select_placeholder'),
                                'required': isTShirtSizeRequired,
                                'required_icon': isTShirtSizeRequired,
                                'selected': f.formData('tshirt_size', ''),
                            }
                        ) }}
                    </div>
                {% endif %}

                <div class="col-md-6">
                    {{ f.input(
                        'mobile',
                        __('settings.profile.mobile'),
                        {
                            'type': 'tel-national',
                            'max_length': 40,
                            'required': isMobileRequired,
                            'required_icon': isMobileRequired,
                            'value': f.formData('mobile', ''),
                        }
                    ) }}
                    {% if isShowMobileEnabled %}
                        {{ f.checkbox(
                            'mobile_show',
                            __('settings.profile.mobile_show'),
                            {
                                'raw_label': true,
                                'checked': f.formData('mobile_show', false),
                            },
                        ) }}
                    {% endif %}
                </div>

                {% if isDECTEnabled %}
                    <div class="col-md-6">
                        {{ f.input(
                            "dect",
                            __('general.dect'),
                            {
                                'type': 'tel-local',
                                'max_length': 40,
                                'required': isDectRequired,
                                'required_icon': isDectRequired,
                                'value': f.formData('dect', ''),
                            }
                        ) }}
                    </div>
                {% endif %}
            </div>
        </div>

        <div class="mb-5">
            <h2>{{ __('registration.what_todo') }}</h2>
            <div class="row mb-3">
                {% for angelType in angelTypes %}
                    <div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
                        {{ f.checkbox(
                            'angel_types_' ~ angelType.id,
                            angelType.name|e ~ (angelType.restricted ? ' ' ~ m.icon('mortarboard-fill', 'text-body') : ''),
                            {
                                'value': angelType.id,
                                'raw_label': true,
                                'checked': preselectedAngelTypes['angel_types_' ~ angelType.id] ?? false,
                            }
                        ) }}
                    </div>
                {% endfor %}
            </div>
            <div class="row">
                <div class="col-md-6">
                    <div class="mb-2">
                        {{ m.icon('mortarboard-fill', 'text-body') }}
                        {{ __('angeltypes.restricted.hint') }}
                    </div>
                    <div>
                        {{ m.icon('info-circle', 'text-body') }}
                        {{ __('angeltypes.can-change-later') }}
                    </div>
                </div>
            </div>
        </div>

        {#
            By assigning a name here, some magic™ will create a session var
            "form-data-register-submit" with the value 1 on submit.
        #}
        {{ f.submit(__('registration.register'), {
            'name': 'register-submit',
        }) }}
    </form>
</div>
{% endblock %}
