<table id="calendar-datalist">
    <thead class="custom">
    {#<tr>
        #}{#<th class="custom">
            <div class="input-group">
                <div class="row">
                    <label class="input-group-label" style="background-color: #2076a9; color: #fff;">Facility</label>
                    <select class="input-group-field" id="schedule-facility-id">
                        {% for healthFacility in healthFacilities%}
                            <option value="{{ healthFacility.id }}">{{ healthFacility.description }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>
        </th>
        <th class="custom">
            <div class="input-group">
                <div class="row">
                    <label class="input-group-label" style="background-color: #2076a9; color: #fff;">Date</label>
                    <input type="text" class="date-picker input-group-field" id="calendar-appoinment-date" style="text-align: center" value="{{ 'now'|date('m/d/Y') }}" />
                </div>
            </div>
        </th>#}{#
    </tr>#}
    <tr>
        <th class="custom">Time</th>
        {% for marketingStaff in marketingStaffs %}
            {% if marketingStaff.fullName != '' and marketingStaff.fullName != null %}
                <th class="custom" style="text-align: center;">{{ marketingStaff.fullName }}</th>
            {% endif %}
        {% endfor %}
    </tr>
    </thead>
    <tbody>
    {% for key,time in times %}
        <tr>
            <td class="custom" style="background-color: #e0e0e0;">{{ time.text }}</td>
            {% for marketingStaff in marketingStaffs %}
                {#{% if time.text in marketingStaff.workSchedules.regular %}#}
                {% set isOut = time.text in marketingStaff.workSchedules.out %}
                {% if not isOut %}
                    {% set isOut = time.text not in marketingStaff.workSchedules.regular %}
                    {% if isOut %}
                        {% set isOut = { hfId : healthFacility_id, time : time.text } not in marketingStaff.workSchedules.irregular %}
                    {% else %}
                        {% for irreg in marketingStaff.workSchedules.irregular %}
                            {% if healthFacility_id != irreg.hfId and irreg.time == time.text %}
                                {% set isOut = true %}
                            {% endif %}
                        {% endfor %}
                    {% endif %}
                {% endif %}
                {% if marketingStaff.schedules is defined %}
                    {% set hasTd = false %}
                    {% for sched in marketingStaff.schedules %}
                        {% if sched.timeText == time.text %}
                            {% set hasTd = true %}
                            {% set bgColor = '#34FF2E' %}
                            {% if isOut %}
                                {% set bgColor = '#a0a0a0' %}
                            {% elseif sched.color is not empty %}
                                {% set bgColor = '#' ~ sched.color %}
                            {% endif %}
                            {% if sched.scheduleStatus == 'No Show' or sched.scheduleStatus == 'Cancelled' or sched.scheduleStatus == 'Rescheduled' %}
                                {% set bgColor = '#cacaca' %}
                            {% endif %}
                            <td rowspan="{{ sched.rowSpan }}"
                                class="schedule-calendar custom"
                                data-provider="{{ marketingStaff.id }}"
                                data-id="{{ sched.id }}"
                                data-time="{{ time.text }}"
                                data-action='u'
                                style="background-color: {{ bgColor }}; color: black;">
                                {% if marketingStaff.schedulesNSC is defined %}
                                    {% for schedNSC in marketingStaff.schedulesNSC if sched.timeText == schedNSC.timeText or sched.timeText in schedNSC.rowSpanTimes or schedNSC.timeText in sched.rowSpanTimes %}
                                        {% if schedNSC.referring_health_facility_id != '' %}
                                            <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                                <a class="patient_link" href="{{ path('referring_health_facility_detail', {'referringHealthFacility_id': schedNSC.referring_health_facility_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.referringHealthFacilityDesc }}</u></a>
                                                <div class="schedule-calendar custom"
                                                     data-provider="{{ marketingStaff.id }}"
                                                     data-id="{{ schedNSC.id }}"
                                                     data-time="{{ time.text }}"
                                                     data-action="u">
                                                    ({{ schedNSC.chartType }}) <br/>
                                                    {{ schedNSC.scheduleStatus }}
                                                </div>
                                            </div>
                                        {% endif %}
                                        {% if schedNSC.referring_provider_id != '' %}
                                            <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                                <a class="patient_link" href="{{ path('referring_provider_detail', {'referringProvider_id': schedNSC.referring_provider_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.referringProviderFullName }}</u></a>
                                                <div class="schedule-calendar custom"
                                                     data-provider="{{ marketingStaff.id }}"
                                                     data-id="{{ schedNSC.id }}"
                                                     data-time="{{ time.text }}"
                                                     data-action="u">
                                                    ({{ schedNSC.chartType }}) <br/>
                                                    {{ schedNSC.scheduleStatus }}
                                                </div>
                                            </div>
                                        {% endif %}
                                    {% endfor %}
                                {% endif %}
                                {% if sched.referring_health_facility_id != '' %}
                                    <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                        <a class="patient_link" href="{{ path('referring_health_facility_detail', {'referringHealthFacility_id': sched.referring_health_facility_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ sched.referringHealthFacilityDesc }}</u></a>
                                        <div class="schedule-calendar custom"
                                             data-provider="{{ marketingStaff.id }}"
                                             data-id="{{ sched.id }}"
                                             data-time="{{ time.text }}"
                                             data-action="u">
                                            ({{ sched.chartType }}) <br/>
                                            {{ sched.scheduleStatus }}
                                        </div>
                                    </div>
                                {% endif %}
                                {% if sched.referring_provider_id != '' %}
                                    <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                        <a class="patient_link" href="{{ path('referring_provider_detail', {'referringProvider_id':  sched.referring_provider_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ sched.referringProviderFullName }}</u></a>
                                        <div class="schedule-calendar custom"
                                             data-provider="{{ marketingStaff.id }}"
                                             data-id="{{ sched.id }}"
                                             data-time="{{ time.text }}"
                                             data-action="u">
                                            ({{ sched.chartType }}) <br/>
                                            {{ sched.scheduleStatus }}
                                        </div>
                                    </div>
                                {% endif %}
                            </td>
                        {% elseif time.text in sched.rowSpanTimes %}
                            {% set hasTd = true %}
                        {% endif %}
                    {% endfor %}
                    {% if not hasTd %}
                        {% set bgColor = 'inherit' %}
                        {% if isOut %}
                            {% set bgColor = '#a0a0a0' %}
                        {% endif %}
                        <td class="schedule-calendar custom" data-provider="{{ marketingStaff.id }}" data-id="0" data-time="{{ time.text }}" data-action='n' style="background-color: {{ bgColor }}">
                            {% if marketingStaff.schedulesNSC is defined %}
                                {% for schedNSC in marketingStaff.schedulesNSC if time.text == schedNSC.timeText %}
                                    {% if schedNSC.referring_health_facility_id != '' or schedNSC.referring_health_facility_id != 'null' %}
                                        <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                            <a class="patient_link" href="{{ path('referring_health_facility_detail', {'referringHealthFacility_id': schedNSC.referring_health_facility_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.referringHealthFacilityDesc }}</u></a>
                                            <div class="schedule-calendar custom"
                                                 data-provider="{{ marketingStaff.id }}"
                                                 data-id="{{ schedNSC.id }}"
                                                 data-time="{{ time.text }}"
                                                 data-action="u">
                                                ({{ schedNSC.chartType }}) <br/>
                                                {{ schedNSC.scheduleStatus }}
                                            </div>
                                        </div>
                                    {% endif %}
                                    {% if schedNSC.referring_provider_id != '' or schedNSC.referring_provider_id != 'null' %}
                                        <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                            <a class="patient_link" href="{{ path('referring_provider_detail', {'referringProvider_id': schedNSC.referring_provider_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.referringProviderFullName }}</u></a>
                                            <div class="schedule-calendar custom"
                                                 data-provider="{{ marketingStaff.id }}"
                                                 data-id="{{ schedNSC.id }}"
                                                 data-time="{{ time.text }}"
                                                 data-action="u">
                                                ({{ schedNSC.chartType }}) <br/>
                                                {{ schedNSC.scheduleStatus }}
                                            </div>
                                        </div>
                                    {% endif %}
                                {% endfor %}
                            {% endif %}
                        </td>
                    {% endif %}
                {% else %}
                    {% set bgColor = 'inherit' %}
                    {% if isOut %}
                        {% set bgColor = '#a0a0a0' %}
                    {% endif %}
                    <td class="schedule-calendar custom" data-provider="{{ marketingStaff.id }}" data-id="0" data-time="{{ time.text }}" data-action='n' style="background-color: {{ bgColor }}">
                        {% if marketingStaff.schedulesNSC is defined %}
                            {% for schedNSC in marketingStaff.schedulesNSC if time.text == schedNSC.timeText %}
                                {% if schedNSC.referring_health_facility_id != '' or schedNSC.referring_health_facility_id != 'null' %}
                                    <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                        <a class="patient_link" href="{{ path('referring_health_facility_detail', {'referringHealthFacility_id': schedNSC.referring_health_facility_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.referringHealthFacilityDesc }}</u></a>
                                        <div class="schedule-calendar custom"
                                             data-provider="{{ marketingStaff.id }}"
                                             data-id="{{ schedNSC.id }}"
                                             data-time="{{ time.text }}"
                                             data-action="u">
                                            ({{ schedNSC.chartType }}) <br/>
                                            {{ schedNSC.scheduleStatus }}
                                        </div>
                                    </div>
                                {% endif %}
                                {% if schedNSC.referring_provider_id != '' or schedNSC.referring_provider_id != 'null' %}
                                    <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                        <a class="patient_link" href="{{ path('referring_provider_detail', {'referringProvider_id': schedNSC.referring_provider_id|base64Encode, 'tab':'ap'}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.referringProviderFullName }}</u></a>
                                        <div class="schedule-calendar custom"
                                             data-provider="{{ marketingStaff.id }}"
                                             data-id="{{ schedNSC.id }}"
                                             data-time="{{ time.text }}"
                                             data-action="u">
                                            ({{ schedNSC.chartType }}) <br/>
                                            {{ schedNSC.scheduleStatus }}
                                        </div>
                                    </div>
                                {% endif %}
                            {% endfor %}
                        {% endif %}
                    </td>
                {% endif %}
                {#<td class="schedule-calendar" data-provider="{{ provider.id }}">
                    {% for key,schedule in time.schedules if schedule.providerId == provider.id %}
                        <div style="text-align: center">{{ schedule.patient }} ({{ schedule.chartType }})</div>
                    {% endfor %}
                </td>#}
                {#{% endif %}#}
            {% endfor %}
        </tr>
    {% endfor %}
    </tbody>
</table>