{% extends '@RxConnexion/Admin/content.html.twig' %}
{% set userData = app.session.get('userData') %}
{% set updateEditable = action == 'u' and userData.id == chatCreatorId ? true : false %}
{% block content %}


    <form method="POST" action="{{ path('chat_form', {action: action, id: id}) }}" {{ updateEditable ? '' : 'disabled' }}>
        <div class="row max-width-initial">
            <div class="large-12 columns">
                <div id="flash-messages-content-modal"></div>
            </div>
            <div class="large-8 columns">
                <h5>Basic information</h5>
                <p class="form-hint-text">Note: Minimum of 1 participant (excluding you)</p>
                <div class="row">
                    <div class="large-4 large-text-right columns">
                        <label class="required middle required">Chat Participant(s)</label>
                    </div>
                    <div class="large-8 columns" id="account_user_container">
                        {% for chatParticipant in form.chatParticipants %}
                            {% if userData.id == chatParticipant.vars.value.accountUser.id %}
                                <input value="{{ chatParticipant.vars.value.accountUser.fullName }}" type="hidden" id="rxconnexionbundle_chatentity_chatParticipants_{{ loop.index0 }}_account_user_name" name="rxconnexionbundle_chatentity[chatParticipants][{{ loop.index0 }}][account_user_name]" value="{{ userData.id }}" required="required">
                                <input value="{{ chatParticipant.vars.value.accountUser.id }}" type="hidden" class="chatParticipants_account_user" id="rxconnexionbundle_chatentity_chatParticipants_{{ loop.index0 }}_account_user" name="rxconnexionbundle_chatentity[chatParticipants][{{ loop.index0 }}][account_user]" value="{{ userData.id }}" required="required">
                            {% else %}
                                <div class="input-group">
                                    <input {{ updateEditable ? '' : 'disabled' }} value="{{ chatParticipant.vars.value.accountUser.fullName }}" type="text" class="chatParticipants_account_user_autocomplete" id="rxconnexionbundle_chatentity_chatParticipants_{{ loop.index0 }}_account_user_name" name="rxconnexionbundle_chatentity[chatParticipants][{{ loop.index0 }}][account_user_name]" required="required">
                                    <input {{ updateEditable ? '' : 'disabled' }} value="{{ chatParticipant.vars.value.accountUser.id }}" type="hidden" class="chatParticipants_account_user" id="rxconnexionbundle_chatentity_chatParticipants_{{ loop.index0 }}_account_user" name="rxconnexionbundle_chatentity[chatParticipants][{{ loop.index0 }}][account_user]" required="required">
                                    <div class="input-group-button">
                                        {% if updateEditable %}
                                            {% if loop.index0 == 1 %}
                                                <button type="button" id="add_account_user" class="button secondary"><i class="fa fa-plus"></i></button>
                                            {% else %}
                                                <button type="button" class="button warning remove_account_user"><i class="fa fa-close"></i></button>
                                            {% endif %}
                                        {% endif %}
                                    </div>
                                </div>
                            {% endif %}
                        {% endfor %}
                        {% if form.chatParticipants|length <= 0 %}
                            <input type="hidden" id="rxconnexionbundle_chatentity_chatParticipants_0_account_user_name" name="rxconnexionbundle_chatentity[chatParticipants][0][account_user_name]" value="{{ userData.id }}" required="required">
                            <input type="hidden" class="chatParticipants_account_user" id="rxconnexionbundle_chatentity_chatParticipants_0_account_user" name="rxconnexionbundle_chatentity[chatParticipants][0][account_user]" value="{{ userData.id }}" required="required">
                            <div class="input-group">
                                <input type="text" class="chatParticipants_account_user_autocomplete" id="rxconnexionbundle_chatentity_chatParticipants_1_account_user_name" name="rxconnexionbundle_chatentity[chatParticipants][1][account_user_name]" required="required">
                                <input type="hidden" class="chatParticipants_account_user" id="rxconnexionbundle_chatentity_chatParticipants_1_account_user" name="rxconnexionbundle_chatentity[chatParticipants][1][account_user]" required="required">
                                <div class="input-group-button">
                                    <button type="button" id="add_account_user" class="button secondary"><i class="fa fa-plus"></i></button>
                                </div>
                            </div>
                        {% endif %}
                        {#<div class="input-group">
                            <input type="text" id="rxconnexionbundle_chatentity_chatParticipants_account_user_name" name="rxconnexionbundle_chatentity[chatParticipants][account_user_name]" required="required">
                            <div class="input-group-button">
                                <button type="button" class="button warning"><i class="fa fa-close"></i></button>
                            </div>
                        </div>#}
                    </div>
                </div>
                <div class="row">
                    <div class="large-4 large-text-right columns">
                        {#{{ form_label(form.description) }}#}
                    </div>
                    <div class="large-8 columns">
                        {{ form_widget(form.description) }}
                        {{ form_widget(form.chat_type) }}
                    </div>
                </div>
            </div>
            <div class="small-12 columns">
                <hr class="max-width-initial">
                <div class="button-container">
                    {% if action == 'n' %}
                        <button type="submit" class="button just-continue" name="action" value="{{ action }}"
                                data-message="Are you sure you want to save this information?"
                        >Save</button>
                    {% endif %}
                    {% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Chat Delete' in userData.accesses) and updateEditable %}
                        <button type="submit" class="button just-continue" name="action" value="{{ action }}"
                                data-message="Are you sure you want to save this information?"
                        >Save</button>
                        <button type="submit" class="ask-continue button alert" name="action" value="d"
                                data-message="Are you sure you want to delete this record?"
                        >Delete</button>
                    {% endif %}
                    <a href="{{ path('chat') }}" class="button secondary">Back</a>
                </div>
            </div>
        </div>
        {{ form_widget(form.action) }}
        {{ form_widget(form.id) }}
        {#{{ form_widget(form.is_deleted) }}#}
        {{ form_widget(form._token) }}
    </form>
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script language="javascript">
        //<![CDATA[
        jQ(document).ready(function(){
            chat_form.settings.account_user_autocomplete_url = '{{ path('account_autocomplete_chat_account_user_account') }}';
            chat_form.init();
        });
        //]]>
    </script>
{% endblock %}