{% extends "base.html.twig" %}
{% trans_default_domain 'admin' %}
{% set t_root = 'admin.user' %}

{% block title %}{{ new ? (t_root ~ '.edit-page.new-title')|trans : (t_root ~ '.edit-page.edit-title')|trans({'%name%': form.vars.data.fullname})|raw }}{% endblock %}
{% block page_title %}{{ new ? (t_root ~ '.edit-page.new-title')|trans : (t_root ~ '.edit-page.edit-title')|trans({'%name%': form.vars.data.fullname})|raw }}{% endblock %}

{% block body %}

    <div class="row mt-2">

        {{ form_start(form) }}
            <div class="form-errors">
                {{ form_errors(form) }}
            </div>

            <div class="form-check form-switch">
                {{ form_label(form.active, t_root ~ '.fields.active', { 'label_attr': {'class': 'form-check-label'} }) }}
                {{ form_widget(form.active, { 'attr': {'class': 'form-check-input'} }) }}
            </div>

            <div class="col mb-3">
                {{ form_label(form.first_name, t_root ~ '.fields.@first-name.label', { 'label_attr': {'class': 'form-label'} }) }}
                <div class="form-errors"> {{ form_errors(form.first_name) }} </div>
                {{ form_widget(form.first_name, { 'attr': {'class': 'form-control', 'placeholder': t_root ~ '.fields.@first-name.placeholder'} }) }}
            </div>

            <div class="col mb-3">
                {{ form_label(form.last_name, t_root ~ '.fields.@last-name.label', { 'label_attr': {'class': 'form-label'} }) }}
                <div class="form-errors"> {{ form_errors(form.last_name) }} </div>
                {{ form_widget(form.last_name, { 'attr': {'class': 'form-control', 'placeholder': t_root ~ '.fields.@last-name.placeholder'} }) }}
            </div>

            <div class="col mb-3">
                {{ form_label(form.email, t_root ~ '.fields.@email.label', { 'label_attr': {'class': 'form-label'} }) }}
                <div class="form-errors"> {{ form_errors(form.email) }} </div>
                <react-locked-input>
                    {{ form_widget(form.email, { 'attr': {'class': 'form-control', 'placeholder': t_root ~ '.fields.@email.placeholder'} }) }}
                </react-locked-input>
            </div>

            {% if app.user.isAdmin() %}
                <div class="form-check form-switch">
                    {{ form_label(form.admin, 'user-role.admin', { 'label_attr': {'class': 'form-check-label'} }) }}
                    {{ form_widget(form.admin, { 'attr': {'class': 'form-check-input'} }) }}
                </div>

                <div class="form-check form-switch">
                    {{ form_label(form.coach, 'user-role.coach', { 'label_attr': {'class': 'form-check-label'} }) }}
                    {{ form_widget(form.coach, { 'attr': {'class': 'form-check-input'} }) }}
                </div>
            {% else %}
                <input type="hidden" name="user[admin]" value="0" />
                <input type="hidden" name="user[coach]" value="0" />
            {% endif %}

            <div class="col mb-3">
                {{ form_label(form.coach_settings.company, 'coach.profile.fields.@company.label', { 'label_attr': {'class': 'form-label'} }) }}
                <div class="form-errors"> {{ form_errors(form.coach_settings.company) }} </div>
                {{ form_widget(form.coach_settings.company, { 'attr': {'class': 'form-control', 'placeholder': 'coach.profile.fields.@company.placeholder'} }) }}
            </div>

            <div class="col mb-3">
                {{ form_label(form.coach_settings.logoFile, 'coach.profile.fields.@logo.label', { 'label_attr': {'class': 'form-label'} }) }}
                <div class="form-errors"> {{ form_errors(form.coach_settings.logoFile) }} </div>
                <twig:ImageEditor view='{{ form.coach_settings.logoFile }}' />

                {# <react-image-editor 
                    data-defaultImageURL="xxxxx" 
                    data-imgMinWidth="{{ 500 }}"
                    data-imgMinHeight="{{ 500 }}"
                    data-fileMaxSize="{{ 500 }}" 
                
                    data-inputName="{{ 'xxxx' }}"
                    data-inputId="{{ 'xxxx' }}"
                    >
                </react-image-editor> #}
            

                {{ form_help(form.coach_settings.logoFile) }}
            </div>

            {% do form.coach_settings.logoFile.setRendered() %}

            <div class="edit-actions">
                <button type="submit" class="btn btn-success">{{ (t_root ~ '.actions.save')|trans }}</button>

                {% if new == false %}
                    <react-admin-safe-delete data-safeString="user-{{ id }}" data-safeAction="{{ t_root ~ '.actions.delete' }}" data-url="{{ path('admin_user_delete', { 'user': id }) }}"></react-admin-safe-delete>
                {% endif %}
            </div>

        {{ form_end(form) }}


    </div>

    {% if new %}
        <div class="row mt-2">
            <div class="alert alert-warning">
                <i class="fa fa-warning"></i> {{ (t_root ~ ".after-creation-warning")|trans }}
            </div>
        </div>
    {% endif %}

{% endblock %}