{% set userData = app.session.get('userData') %}
<form method="POST" id="form-accountUserReminder">
    <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-4 large-text-right columns">
                    {{ form_label(form.reminder_type) }}
                </div>
                <div class="large-8 columns">
                    {{ form_widget(form.reminder_type) }}
                </div>
            </div>
            <div class="row large-text-center">
                <div class="large-4 large-text-right columns">
                    {{ form_label(form.assigned_to_account_user_desc) }}
                </div>
                <div class="large-8 columns">
                    {% if action == 'n' %}
                        {{ form_widget(form.assigned_to_account_user_desc, {value: userData.fullName}) }}
                        {{ form_widget(form.assigned_to_account_user, {value: userData.id}) }}
                    {% else %}
                        {{ form_widget(form.assigned_to_account_user_desc) }}
                        {{ form_widget(form.assigned_to_account_user) }}
                    {% endif %}

                    {{ form_widget(form.assigned_to_user_group_desc) }}
                    {{ form_widget(form.assigned_to_user_group) }}
                </div>
            </div>
            <div class="row large-text-center">
                <div class="large-4 large-text-right columns">
                    {{ form_label(form.start_date) }}
                </div>
                <div class="large-8 columns">
                    {% if action == 'n' %}
                        {{ form_widget(form.start_date, {value: "now"|date('m/d/Y')}) }}
                    {% else %}
                        {{ form_widget(form.start_date) }}
                    {% endif %}
                </div>
            </div>
            {#<div class="row large-text-center">
                <div class="large-4 large-text-right columns">
                    {{ form_label(form.end_date) }}
                </div>
                <div class="large-8 columns">
                    {{ form_widget(form.end_date) }}
                </div>
            </div>#}
            <div class="row large-text-center">
                <div class="large-4 large-text-right columns">
                    {{ form_label(form.note) }}
                </div>
                <div class="large-8 columns">
                    {{ form_widget(form.note) }}
                </div>
            </div>
            <div class="row large-text-center {{ action == 'u' ? '' : 'hide' }}">
                <div class="large-4 large-text-right columns">
                    {{ form_label(form.status) }}
                </div>
                <div class="large-8 columns">
                    {% if action == 'u' %}
                        {{ form_widget(form.status) }}
                    {% else %}
                        {{ form_widget(form.status, {value: 'Pending', attr: {'class':'hide'}}) }}
                    {% endif %}
                </div>
            </div>
            <div class="row">
                <div class="large-12 columns">
                    <hr>
                    <table style="width: 100%;">
                        <thead>
                            <tr>
                                <td>Referenced Patient(s)</td>
                                <td class="text-center"><a id="global-reminder-form-add-patient" href="javascript:void(0)">Add</a></td>
                            </tr>
                        </thead>
                        <tbody id="global-reminder-patient-ref-table-body">
                        {% set initialPtIdx = 0 %}
                        {% for aurrp in form.accountUserReminderRefPatients %}
                            {% set initialPtIdx = initialPtIdx + 1 %}
                            <tr class="global-reminder-patient_row" data-idx="{{ loop.index0 }}">
                                <td>
                                    <input type="text"
                                           id="account_user_reminder_form_accountUserReminderRefPatient_patient_fullName{{ loop.index0 }}"
                                           name="account_user_reminder_form[accountUserReminderRefPatients][{{ loop.index0 }}][accountUserReminderRefPatient_fullName]"
                                           value="{{ aurrp.vars.value.patient.fullName|default('') }}"
                                           class="account_user_reminder_form_accountUserReminderRefPatient_patient_fullName"
                                           placeholder="Patient"/>
                                    <input type="hidden"
                                           id="account_user_reminder_form_accountUserReminderRefPatient_patient{{ loop.index0 }}"
                                           name="account_user_reminder_form[accountUserReminderRefPatients][{{ loop.index0 }}][patient]"
                                           value="{{ aurrp.vars.value.patient.id|default('')|base64Encode }}"
                                           class="account_user_reminder_form_accountUserReminderRefPatient_patient"/>
                                    <input type="hidden"
                                           name="account_user_reminder_form[accountUserReminderRefPatients][{{ loop.index0 }}][id]"
                                           value="{{ aurrp.vars.value.id|default('') }}"
                                    >
                                </td>
                                <td class="text-center">
                                    <button class="button tiny secondary removePatientRef" type="button">&times;</button>
                                </td>
                            </tr>
                        {% endfor %}
                        {% if defaultPatient is not null %}
                            <tr class="global-reminder-patient_row" data-idx="{{ initialPtIdx }}">
                                <td>
                                    <input type="text"
                                           id="account_user_reminder_form_accountUserReminderRefPatient_patient_fullName{{ initialPtIdx }}"
                                           name="account_user_reminder_form[accountUserReminderRefPatients][{{ initialPtIdx }}][accountUserReminderRefPatient_fullName]"
                                           value="{{ defaultPatient.fullName }}"
                                           class="account_user_reminder_form_accountUserReminderRefPatient_patient_fullName"
                                           placeholder="Patient"/>
                                    <input type="hidden"
                                           id="account_user_reminder_form_accountUserReminderRefPatient_patient{{ initialPtIdx }}"
                                           name="account_user_reminder_form[accountUserReminderRefPatients][{{ initialPtIdx }}][patient]"
                                           value="{{ defaultPatient.id|base64Encode }}"
                                           class="account_user_reminder_form_accountUserReminderRefPatient_patient"/>
                                    <input type="hidden"
                                           name="account_user_reminder_form[accountUserReminderRefPatients][{{ initialPtIdx }}][id]"
                                           value=""
                                    >
                                </td>
                                <td class="text-center">
                                    <button class="button tiny secondary removePatientRef" type="button">&times;</button>
                                </td>
                            </tr>
                        {% endif %}
                        </tbody>
                    </table>
                </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-account-user-reminder-action float-right" data-id="{{ id }}" data-value="{{ action }}" data-axn="{{ action }}"
                   data-message="Are you sure you want to save this information?"
                   style="margin-left: 10px; margin-right: 0;"
                ><i class="fa fa-save"></i> Save Reminder</a>
                {% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Account User Reminder Delete' in userData.accesses) %}
                    <a href="javascript:void(0)" class="ask-continue button alert href-patient-account-user-reminder-action float-right" data-value="d" data-id="{{ id }}" data-axn="{{ action }}"
                       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>#}
    {% if action == 'u' %}
        {{ form_widget(form.account_user) }}
    {% else %}
        {{ form_widget(form.account_user, {value: userData.id}) }}
    {% endif %}
    {{ form_widget(form.action) }}
    {{ form_widget(form.id) }}
    {{ form_widget(form._token) }}
</form>

<script>
    global_reminder.settings.initialPtIdx = {{ initialPtIdx }};
</script>