<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 provider in providers %}
            {% if provider.fullName != '' and provider.fullName != null %}
                <th class="custom" style="text-align: center;">{{ provider.fullName }}</th>
            {% endif %}
        {% endfor %}
    </tr>
    </thead>
    <tbody>
    {% for key,time in times %}
        <tr>
            <td class="custom" style="background-color: #e0e0e0;">{{ time.text }}</td>
            {% for provider in providers %}
                {#{% if time.text in provider.workSchedules.regular %}#}
                {% set isOut = time.text in provider.workSchedules.out %}
                {% if not isOut %}
                    {% set isOut = time.text not in provider.workSchedules.regular %}
                    {% if isOut %}
                        {% set isOut = { hfId : healthFacility_id, time : time.text } not in provider.workSchedules.irregular %}
                    {% else %}
                        {% for irreg in provider.workSchedules.irregular %}
                            {% if healthFacility_id != irreg.hfId and irreg.time == time.text %}
                                {% set isOut = true %}
                            {% endif %}
                        {% endfor %}
                    {% endif %}
                {% endif %}
                {% if provider.schedules is defined %}
                    {% set hasTd = false %}
                    {% for sched in provider.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="{{ provider.id }}"
                                data-id="{{ sched.id }}"
                                data-time="{{ time.text }}"
                                data-action='u'
                                style="background-color: {{ bgColor }}; color: black;">
                                {% if provider.schedulesNSC is defined %}
                                    {% for schedNSC in provider.schedulesNSC if sched.timeText == schedNSC.timeText or sched.timeText in schedNSC.rowSpanTimes or schedNSC.timeText in sched.rowSpanTimes %}
                                        <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                            <a class="patient_link" href="{{ path('patient_detail', {'patient_id': schedNSC.patient_id|base64Encode}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.patient }}</u></a>
                                            <div class="schedule-calendar custom"
                                                 data-provider="{{ provider.id }}"
                                                 data-id="{{ schedNSC.id }}"
                                                 data-time="{{ time.text }}"
                                                 data-action="u">
                                                ({{ schedNSC.chartType }}) <br/>
                                                {{ schedNSC.scheduleStatus }}
                                            </div>
                                        </div>
                                    {% endfor %}
                                {% endif %}
                                <div class="patient_info" style="text-align: center">
                                    <a class="patient_link" href="{{ path('patient_detail', {'patient_id': sched.patient_id|base64Encode}) }}" target="_blank" style="color:#000;"><u>{{ sched.patient }}</u></a>
                                    <div class="schedule-calendar custom"
                                         data-provider="{{ provider.id }}"
                                         data-id="{{ sched.id }}"
                                         data-time="{{ time.text }}"
                                         data-action="u">
                                        ({{ sched.chartType }})
                                        {#<br />{{ sched.chartStatus }}#}
                                        <br />{{ sched.scheduleStatus != 'Completed' ? sched.scheduleStatus : sched.chartStatus }}
                                    </div>
                                </div>
                            </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="{{ provider.id }}" data-id="0" data-time="{{ time.text }}" data-action='n' style="background-color: {{ bgColor }}">
                            {% if provider.schedulesNSC is defined %}
                                {% for schedNSC in provider.schedulesNSC if time.text == schedNSC.timeText %}
                                    <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                        <a class="patient_link" href="{{ path('patient_detail', {'patient_id': schedNSC.patient_id|base64Encode}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.patient }}</u></a>
                                        <div class="schedule-calendar custom"
                                             data-provider="{{ provider.id }}"
                                             data-id="{{ schedNSC.id }}"
                                             data-time="{{ time.text }}"
                                             data-action="u">
                                            ({{ schedNSC.chartType }}) <br/>
                                            {{ schedNSC.scheduleStatus }}
                                        </div>
                                    </div>
                                {% endfor %}
                            {% endif %}
                        </td>
                    {% endif %}
                {% else %}
                    {% set bgColor = 'inherit' %}
                    {% if isOut %}
                        {% set bgColor = '#a0a0a0' %}
                    {% endif %}
                    <td class="schedule-calendar custom" data-provider="{{ provider.id }}" data-id="0" data-time="{{ time.text }}" data-action='n' style="background-color: {{ bgColor }}">
                        {% if provider.schedulesNSC is defined %}
                            {% for schedNSC in provider.schedulesNSC if time.text == schedNSC.timeText %}
                                <div class="patient_info" style="text-align: center; background-color: #cacaca; font-size: 10px; margin-bottom: 1em;">
                                    <a class="patient_link" href="{{ path('patient_detail', {'patient_id': schedNSC.patient_id|base64Encode}) }}" target="_blank" style="color:#000;"><u>{{ schedNSC.patient }}</u></a>
                                    <div class="schedule-calendar custom"
                                         data-provider="{{ provider.id }}"
                                         data-id="{{ schedNSC.id }}"
                                         data-time="{{ time.text }}"
                                         data-action="u">
                                        ({{ schedNSC.chartType }}) <br/>
                                        {{ schedNSC.scheduleStatus }}
                                    </div>
                                </div>
                            {% 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>