<div style="overflow: auto">

    <div class="row">

        <div class="col-md-12">
            <label class="control-label col-md-2" style=" padding-right: 0; ">اسم الطبيب</label>
            <div class="col-md-5">
                <select class="form-control " data-placeholder="اختر الطبيب" name="doctor_id" id="doctor_id" required="">
                    <option value=""></option>
                    {foreach $doctors as $doctor}
                    <option value="{$doctor.user_id}"
                            {if $doctor_id eq $doctor.user_id}selected{/if}>
                        {$doctor.name}</option>
                    {/foreach}
                </select>
            </div>
            <div class="col-md-2">
                <button class="btn green-sharp uppercase bold" style="padding: 5px;margin-left: 5px;" type="button" id="reserve_btn">تاكيد الحجز</button>
                <button class="btn red uppercase bold" style="padding: 5px;margin-left: 5px;" type="button" id="delete_reserve_btn">الغاء الحجز</button>
            </div>


        </div>
    </div>
    <div style="width: max-content">
        <div style="float: left;width: 50%;">
            <h4 style="text-align: center;font-weight: bold">غرف العمليات</h4>
            <table class="table table-bordered table-striped table-hover" style="min-width: 975px;">
                <tr class=" even">
                    <th colspan="2" rowspan="2" class="bl">الوقت</th>
                    {foreach $floors_arr as $floor}
                    <th colspan="{$floor->o_rooms|@count}" class="bl">
                        {$floor->floorName}
                    </th>
                    {/foreach}
                </tr>
                <tr class=" bb">

                    {foreach $floors_arr as $floor}
                    {assign var=count value=1}
                    {foreach $floor->o_rooms as $o_room}
                    <th class="{if $count eq 1}bl{/if}"> {$o_room->name}</th>
                    {capture assign=count}{$count+1}{/capture}
                    {/foreach}
                    {/foreach}
                </tr>

                {for $foo=0 to 11}
                <tr class="even">
                    {if $foo eq 0}
                    <td rowspan="12" class="bt">AM</td>
                    {/if}
                    <td class="bl">{$foo}:00 - {$foo+1}:00</td>

                    {foreach $floors_arr as $floor}
                    {assign var=count value=1}
                    {foreach $floor->o_rooms as $o_room}

                    <th class='{if $count eq 1}bl{/if}
                        {assign var=is_busy value=1}
                        {foreach $o_room->reserves as $per_reserve}
                        {if $foo <= 9}{assign var=pre_foo_hour value="0$foo"}{else}{assign var=pre_foo_hour value=$foo}{/if}
                        {if $per_reserve->hour_text eq "$pre_foo_hour:00" AND $o_room->id eq $per_reserve->operations_room_id}
                        dayBusy {capture assign=is_busy}{$is_busy = 1}{/capture} {/if}{/foreach}{if $is_busy eq 1}dayFree{/if}'
                        data-hour="{if $foo <= 9}0{/if}{$foo}:00" data-type="1" data-room-id="{$o_room->id}">
                        {foreach $o_room->reserves as $per_reserve}
                        {if $foo <= 9}{assign var=pre_foo_hour value="0$foo"}{else}{assign var=pre_foo_hour value=$foo}{/if}
                        {if $per_reserve->hour_text == "$pre_foo_hour:00" AND $o_room->id eq $per_reserve->operations_room_id}
                        {$per_reserve->doctor_name}
                        <input type="hidden" name="operation_reserve_id" class="operation_reserve_id" data-tbl="doctors_reserves"
                               data-id="{$per_reserve->id}" value="{$per_reserve->operation_main_id}">
                        {/if}
                        {/foreach}
                    </th>

                    {capture assign=count}{$count+1}{/capture}
                    {/foreach}
                    {/foreach}


                </tr>
                {/for}

                {for $foo=0 to 11}
                <tr class="even">
                    {if $foo eq 0}
                    <td rowspan="12" class="bt">PM</td>
                    {/if}
                    <td class="bl">{$foo}:00 - {$foo+1}:00</td>

                    {foreach $floors_arr as $floor}
                    {assign var=count value=1}
                    {foreach $floor->o_rooms as $o_room}

                    <th class='{if $count eq 1}bl{/if}
                        {assign var=is_busy value=1}
                        {foreach $o_room->reserves as $per_reserve}
                        {assign var=foo_hour value=$foo+12}
                        {if $per_reserve->hour_text eq "$foo_hour:00" AND $o_room->id eq $per_reserve->operations_room_id}
                        dayBusy {capture assign=is_busy}{$is_busy = 1}{/capture} {/if}{/foreach} {if $is_busy eq 1}dayFree{/if}'
                        data-hour="{$foo+12}:00" data-type="1" data-room-id="{$o_room->id}">
                        {foreach $o_room->reserves as $per_reserve}
                        {assign var=foo_hour value=$foo+12}
                        {if $per_reserve->hour_text == "$foo_hour:00" AND $o_room->id eq $per_reserve->operations_room_id}
                        {$per_reserve->doctor_name}
                        <input type="hidden" name="operation_reserve_id" class="operation_reserve_id" data-tbl="doctors_reserves"
                               data-id="{$per_reserve->id}" value="{$per_reserve->operation_main_id}">
                        {/if}
                        {/foreach}
                    </th>

                    {capture assign=count}{$count+1}{/capture}
                    {/foreach}
                    {/foreach}


                </tr>
                {/for}

            </table></div>
        <div style="float: right;width: 50%;">
            <h4 style="text-align: center;font-weight: bold">غرف الاقامه</h4>
            <table class="table table-bordered table-striped table-hover" style="min-width: 975px;margin-left: 1%;">
                <tr class=" even">
                    <th colspan="2" rowspan="2" class="bl">الوقت</th>
                    {foreach $r_floors_arr as $floor}
                    <th colspan="{$floor->r_rooms|@count}" class="bl">
                        {$floor->floorName}
                    </th>
                    {/foreach}
                </tr>
                <tr class=" bb">

                    {foreach $r_floors_arr as $floor}
                    {assign var=count value=1}
                    {foreach $floor->r_rooms as $r_room}
                    <th class="{if $count eq 1}bl{/if}"> {$r_room->name}</th>
                    {capture assign=count}{$count+1}{/capture}
                    {/foreach}
                    {/foreach}
                </tr>

                {for $foo=0 to 11}
                <tr class="even">
                    {if $foo eq 0}
                    <td rowspan="12" class="bt">AM</td>
                    {/if}
                    <td class="bl">{$foo}:00 - {$foo+1}:00</td>

                    {foreach $r_floors_arr as $floor}
                    {assign var=count value=1}
                    {foreach $floor->r_rooms as $r_room}

                    <th class='{if $count eq 1}bl{/if}
                        {assign var=is_busy value=1}
                        {foreach $r_room->reserves as $per_reserve}
                        {if $foo <= 9}{assign var=pre_foo_hour value="0$foo"}{else}{assign var=pre_foo_hour value=$foo}{/if}
                        {if $per_reserve->hour_text eq "$pre_foo_hour:00" AND $r_room->id eq $per_reserve->residence_room_id}
                        dayBusy {capture assign=is_busy}{$is_busy = 1}{/capture} {/if}{/foreach} {if $is_busy eq 1}dayFree{/if}'
                        data-hour="{if $foo <= 9}0{/if}{$foo}:00" data-type="2" data-room-id="{$r_room->id}">
                        {foreach $r_room->reserves as $per_reserve}
                        {if $foo <= 9}{assign var=pre_foo_hour value="0$foo"}{else}{assign var=pre_foo_hour value=$foo}{/if}
                        {if $per_reserve->hour_text == "$pre_foo_hour:00" AND $r_room->id eq $per_reserve->residence_room_id}
                        {$per_reserve->doctor_name}
                        <input type="hidden" name="operation_reserve_id" class="operation_reserve_id" data-tbl="residence_reserves"
                               data-id="{$per_reserve->id}" value="{$per_reserve->operation_main_id}">
                        {/if}
                        {/foreach}
                    </th>

                    {capture assign=count}{$count+1}{/capture}
                    {/foreach}
                    {/foreach}


                </tr>
                {/for}

                {for $foo=0 to 11}
                <tr class="even">
                    {if $foo eq 0}
                    <td rowspan="12" class="bt">PM</td>
                    {/if}
                    <td class="bl">{$foo}:00 - {$foo+1}:00</td>

                    {foreach $r_floors_arr as $floor}
                    {assign var=count value=1}
                    {foreach $floor->r_rooms as $r_room}

                    <th class='{if $count eq 1}bl{/if}
                        {assign var=is_busy value=1}
                        {foreach $r_room->reserves as $per_reserve}
                        {assign var=foo_hour value=$foo+12}
                        {if $per_reserve->hour_text eq "$foo_hour:00" AND $r_room->id eq $per_reserve->residence_room_id}
                        dayBusy {capture assign=is_busy}{$is_busy = 1}{/capture} {/if}{/foreach} {if $is_busy eq 1}dayFree{/if}'
                        data-hour="{$foo+12}:00" data-type="2" data-room-id="{$r_room->id}">
                        {foreach $r_room->reserves as $per_reserve}
                        {assign var=foo_hour value=$foo+12}
                        {if $per_reserve->hour_text eq "$foo_hour:00" AND $r_room->id eq $per_reserve->residence_room_id}
                        {$per_reserve->doctor_name}
                        <input type="hidden" name="operation_reserve_id" class="operation_reserve_id" data-tbl="residence_reserves"
                               data-id="{$per_reserve->id}" value="{$per_reserve->operation_main_id}">
                        {/if}
                        {/foreach}
                    </th>

                    {capture assign=count}{$count+1}{/capture}
                    {/foreach}
                    {/foreach}


                </tr>
                {/for}


            </table></div>
    </div>
</div>

<input type="hidden" id="hours_string" name="hours_string" value="">
<input type="hidden" id="operation_room_id" name="operation_room_id" value="">
<input type="hidden" id="residence_hours_string" name="hours_string" value="">
<input type="hidden" id="residence_room_id" name="operation_room_id" value="">

<input type="hidden" id="remove_rooms_hours" name="remove_rooms_hours" value="">




<style>
    table th, table td {
        text-align: center;
    }

    .danger {
        color: red
    }

    .table-bordered > tbody > tr > td, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > td, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > thead > tr > th {
        border: 1px solid #656565;
    }

    .bt {
        border-top: 2px solid #000 !important;
    }

    .bl {
        border-left: 2px solid #000 !important;

    }

    .table {
        border: 2px solid #000 !important;
    }

    .bb {
        border-bottom: 2px solid #000 !important;
    }

    .dayFree {
        color: black;
        background-color: #a3dfa2;
        text-align: center;
    }

    .daySelected {
        color: black;
        background-color: #7ac720;
        text-align: center;
    }

    .dayCancel {
        color: black;
        background-color: #f36a5a;
        text-align: center;
    }

    .dayBusy {
        color: black;
        background-color: #cccccc;
        text-align: center;
    }
</style>
