{% set userData = app.session.get('userData') %}
<form method="POST" id="form-patientLetterNote">
    <h5>{{ page_title }}</h5>
    <div id="flash-messages-content-modal"></div>
    <div class="row max-width-initial">
        <div class="large-12 columns">
            <div class="row large-text-center">
                <div class="large-12 columns" style="text-align: left;">
                    {{ form_label(form.account_user_desc) }}
                </div>
                <div class="large-12 columns">
                    {% if action == 'n' %}
                        {{ form_widget(form.account_user_desc, {value: userData.fullName}) }}
                        {{ form_widget(form.account_user, {value: userData.id}) }}
                    {% else %}
                        {{ form_widget(form.account_user_desc) }}
                        {{ form_widget(form.account_user) }}
                    {% endif %}
                </div>
            </div>
            <div class="row large-text-center">
                <div class="large-12 columns">
                    {{ form_widget(form.note) }}
                </div>
                <div class="large-12 columns">
                    {{ form_widget(form.note) }}
                </div>
            </div>
        </div>
    </div>
    <div class="row max-width-initial" style="margin-bottom: 20px; margin-top: 20px;">
        <div class="large-12 columns">
            <div><strong>Reply</strong></div>
        </div>
    </div>
    <div class="row max-width-initial">
        <div class="large-12 columns">
            <div id="patient-letter-data-container" class="has-loading">
                <div id="patient-letter-data-loading" class="text-center"></div>
                <div class="patient-letter-data" style="display: none;">
                    <div class="patientLeterNotes"></div>
                </div>
            </div>
        </div>
    </div>
    <hr>
    <div class="row-max-width-initial">
        <div class="small-12 columns no-padding-right">
            <div class="button-container clearfix text-right">
                    <a href="javascript:void(0)" class="button just-continue href-patient-letter-note-action float-right" data-axn="{{ action }}"
                       data-message="Are you sure you want to save this information?"
                       style="margin-left: 10px; margin-right: 0;"
                    >Save</a>
                {% if action == 'd' and (userData.type == 'Super Admin' or 'Admin Patient Letter Note Delete' in userData.accesses) %}
                    <a href="javascript:void(0)" class="ask-continue button alert href-patient-letter-note-action float-right" data-axn="d"
                       data-message="Are you sure you want to delete this record?"
                       style="margin-left: 10px; margin-right: 0;"
                    >Delete</a>
                {% endif %}
                <a href="javascript:void(0)" class="button secondary" data-close style="margin-left: 10px; margin-right: 0;">Close</a>
            </div>
        </div>
    </div>
    {{ form_widget(form.action) }}
    {{ form_widget(form.id) }}
    {{ form_widget(form.patient_letter) }}
    {{ form_widget(form._token) }}
</form>
<script language="javascript">
    //<![CDATA[
    jQ(document).ready(function(){
        let autoCompleteUrl = '{{ path('account_user_autocomplete') }}' ;
        let patient_letter_note_viewUrl = '{{ path('patient_letter_note_view') }}' ;
        global.autocomplete.bind(autoCompleteUrl, '#patient_letter_note_account_user_desc', '#patient_letter_note_account_user');

        if(jQ('#patient-letter-data-container').length) {

            var i;
            var data = {};
            data['patientLetterId'] = jQ('#patient_letter_note_patient_letter').val();

            jQ('.patientLeterNotes').empty();
            jQ.post(patient_letter_note_viewUrl, data, function (response) {
                jQ('.patient-letter-data').css('display','block');
                jQ('#patient-letter-data-loading').addClass('hide');
                jQ('#patient-letter-data-title').removeClass('hide');
                jQ('#patient-letter-data-container').removeClass('has-loading');

                if(response.length <= 0) {
                    jQ('.patientLeterNotes').append('<li>No replies.</li>');
                } else {
                    for(i=0; i < response.length; i++) {
                        jQ('.patientLeterNotes').append(' <div class="success callout small">\n' +
                            '                    <h5>'+response[i].auTo+'</h5>\n' +
                            '                    <p>'+response[i].note+'</p>\n' +
                            '                </div>');
                    }
                }

            }, 'json');
        }
    });
    //]]>
</script>