<div class=" content">
    <div class="row">
        <div class="col-sm-8">
            <div class="card">
                <div class="card-body">
                    <form class="form-inline">
                        <div class="form-group hidden">
                            <div class="input-group">
                                <input name="datepicker" class="form-control" ngbDatepicker #datepicker="ngbDatepicker"
                                    [autoClose]="'outside'" (dateSelect)="onDateSelection($event)" [displayMonths]="2"
                                    [dayTemplate]="t" outsideDays="hidden" [startDate]="fromDate!" tabindex="-1">
                                <ng-template #t let-date let-focused="focused">
                                    <span class="custom-day" [class.focused]="focused" [class.range]="isRange(date)"
                                        [class.faded]="isHovered(date) || isInside(date)"
                                        (mouseenter)="hoveredDate = date" (mouseleave)="hoveredDate = null">
                                        {{ date.day }}
                                    </span>
                                </ng-template>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <input #dpFromDate class="form-control" placeholder="yyyy-mm-dd" name="dpFromDate"
                                    [value]="formatter.format(fromDate)"
                                    (input)="fromDate = validateInput(fromDate, dpFromDate.value)">
                                <div class="input-group-append">
                                    <button class="btn btn-outline-secondary calendar" (click)="datepicker.toggle()"
                                        type="button"></button>
                                </div>
                            </div>
                        </div>
                        <div class="form-group ml-2">
                            <div class="input-group">
                                <input #dpToDate class="form-control" placeholder="yyyy-mm-dd" name="dpToDate"
                                    [value]="formatter.format(toDate)"
                                    (input)="toDate = validateInput(toDate, dpToDate.value)">
                                <div class="input-group-append">
                                    <button class="btn btn-outline-secondary calendar" (click)="datepicker.toggle()"
                                        type="button"></button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-4">
            <div class="card">
                <div class="card-body">
                    <div ngbDropdown class="d-inline-block">
                        <button class="btn btn-sm btn-outline-primary" id="dropdownBasic1"
                            ngbDropdownToggle>ประเภทการค้นหา</button>
                        <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
                            <button ngbDropdownItem>รอดำเนินการ</button>
                            <button ngbDropdownItem>อนุมัติ</button>
                            <button ngbDropdownItem>ยกเลิก</button>
                            <button ngbDropdownItem>สำเร็จแล้ว</button>
                        </div>
                        <button class="btn btn-sm btn-outline-success" type="submit">Search</button>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <ul ngbNav #nav="ngbNav" class="nav-tabs">
        <li ngbNavItem>
            <a ngbNavLink>การจอง</a>
            <ng-template ngbNavContent>
                <div class="row text-center">
                    <div class="col-sm-12">
                        <div class="card">
                            <div class="card-body">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th scope="col">#</th>
                                            <th scope="col">ชื่อห้อง</th>
                                            <th scope="col">รายละเอียด</th>
                                            <th scope="col">ชื่อผู้เบิก</th>
                                            <th scope="col">วันที่เริ่มต้น</th>
                                            <th scope="col">วันที่สิ้นสุด</th>
                                            <th scope="col">สถานะ</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr *ngFor="let item of listroomDetail">
                                            <th scope="row">{{ item.Id }}</th>
                                            <td>{{ item.room.rName }}</td>
                                            <td>{{ item.room.rDesc }}</td>
                                            <td>{{ item.userName }}</td>
                                            <td>{{ item.sDate.replaceAll("/","-") }} {{ item.sTime.hour }}:{{
                                                item.sTime.minute }}</td>
                                            <td>{{ item.eDate.replaceAll("/","-") }} {{ item.eTime.hour }}:{{
                                                item.eTime.minute }}</td>
                                            <td>{{ item.rStatus }}</td>
                                            <div class="text-center">
                                                <button type="button" class="btn btn-info btn-sm btn-circle "
                                                    style="line-height: 0px" (click)="openRoomDetail(Room,item)"><i
                                                        class="fa fa-search"></i> </button>
                                            </div>
                                        </tr>
                                    </tbody>
                                </table>
                                <div class="d-flex justify-content-between p-2">
                                    <ngb-pagination [collectionSize]="collectionSizeListRoom" [(page)]="pageListRoom"
                                        [pageSize]="pageSizeListRoom">
                                        <ng-template ngbPaginationPrevious>Previous</ng-template>
                                        <ng-template ngbPaginationNext>Next</ng-template>
                                    </ngb-pagination>
    
                                    <select class="custom-select" style="width: auto" [(ngModel)]="pageSizeListRoom"
                                        (ngModelChange)="pageListRoom=1">
                                        <option [ngValue]="10">10 items per page</option>
                                        <option [ngValue]="50">50 items per page</option>
                                        <option [ngValue]="100">100 items per page</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </ng-template>

        </li>
        <li ngbNavItem>
            <a ngbNavLink>การเบิก</a>
            <ng-template ngbNavContent>
                <div class="row text-center">
                    <div class="col-sm-12">
                        <div class="card">
                            <div class="card-body">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th scope="col">#</th>
                                            <th scope="col">หมวดหมู่</th>
                                            <th scope="col">ประเภท</th>
                                            <th scope="col">รายละเอียด</th>
                                            <th scope="col">ชื่อ</th>
                                            <th scope="col">วันที่เริ่มใช้</th>
                                            <th scope="col">วันที่สิ้นสุด</th>
                                            <th scope="col">จำนวน</th>
                                            <th scope="col">สถานะ</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr *ngFor="let item of listitemDetail">
                                            <th scope="row">{{ item.Id }}</th>
                                            <td>{{ item.equirment.eqType }}</td>
                                            <td>{{ item.equirment.eqName }}</td>
                                            <td>{{ item.equirment.eqDesc }}</td>
                                            <td>{{ item.userName }}</td>
                                            <td>{{ item.sDate.replaceAll("/","-")}} {{ item.sTime.hour }}:{{
                                                item.sTime.minute }}</td>
                                            <td>{{ item.eDate.replaceAll("/","-")}} {{ item.eTime.hour }}:{{
                                                item.eTime.minute }}</td>
                                            <td>{{ item.Quantity }}</td>
                                            <td>{{ item.eStatus }}</td>
                                            <div class="text-center">
                                                <button type="button" class="btn btn-info btn-sm btn-circle "
                                                    style="line-height: 0px" (click)="openItemDetail(lend,item)"><i
                                                        class="fa fa-search"></i> </button>
                                            </div>
                                        </tr>
                                    </tbody>
                                </table>
                                <div class="d-flex justify-content-between p-2">
                                    <ngb-pagination [collectionSize]="collectionSizeListRoom" [(page)]="pageListRoom"
                                        [pageSize]="pageSizeListRoom">
                                        <ng-template ngbPaginationPrevious>Previous</ng-template>
                                        <ng-template ngbPaginationNext>Next</ng-template>
                                    </ngb-pagination>
    
                                    <select class="custom-select" style="width: auto" [(ngModel)]="pageSizeListRoom"
                                        (ngModelChange)="pageListRoom=1">
                                        <option [ngValue]="10">10 items per page</option>
                                        <option [ngValue]="50">50 items per page</option>
                                        <option [ngValue]="100">100 items per page</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </ng-template>
        </li>
    </ul>
    <div [ngbNavOutlet]="nav"></div>
</div>

<ng-template #Room let-modal>
    <div class=" col-md-12" style="padding: 0;">
        <div class="card" style="margin: 0; ">
            <div class=" card-header">
                <h5 class=" title">การจอง</h5>
            </div>
            <div class=" card-body">
                <div class=" row">
                    <div class=" col-md-12">
                        <div class=" form-group">
                            <label> ชื่อผู้จอง </label>
                            <input class=" form-control" placeholder="" type="text" [(ngModel)]="modelRoomDetail.userName" />
                        </div>
                    </div>
                </div>
                <div class=" row">
                    <div class=" col-sm-12 mb-1">
                        <div class=" form-group">
                            <label> อีเมล </label>
                            <input class=" form-control" placeholder="" type="text" [(ngModel)]="modelRoomDetail.email" />
                        </div>
                    </div>
                </div>
                <div class=" row">
                    <div class=" col-md-12">
                        <div class=" form-group">
                            <label> เบอร์โทร </label>
                            <input class=" form-control" placeholder="" type="text" [(ngModel)]="modelRoomDetail.room.rTelephone" />
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12 mb-1">
                        <label for="exampleFormControlSelect1">ชื่อห้อง</label>
                        <input class="form-control" type="text" [(ngModel)]="modelRoomDetail.room.rName"/>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12 mb-1">
                        <label for="exampleFormControlSelect1">รายละเอียด</label>
                        <input class="form-control" type="text" [(ngModel)]="modelRoomDetail.room.rDesc" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">วันที่เริ่มต้น</label>
                        <input type="date" class="form-control" [(ngModel)]="sDate" (ngModelChange)="rDate(sDate,'sdate')" />
                    </div>
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">วันที่สิ้นสุด</label>
                        <input type="date" class="form-control" [(ngModel)]="eDate" (ngModelChange)="rDate(eDate,'edate')" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">เวลาที่เริ่มต้น</label>
                        <input class="form-control" type="time"
                        [(ngModel)]="thStime" (ngModelChange)="thtimeChange(thStime,modelRoomDetail.sTime)" />
                    </div>
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">เวลาที่สิ้นสุด</label>
                        <input class="form-control" type="time"
                        [(ngModel)]="thEtime" (ngModelChange)="thtimeChange(thEtime,modelRoomDetail.eTime)" />
                    </div>
                </div>
                <div class=" row">
                    <div class=" col-md-12">
                        <div class=" form-group">
                            <label> หมายเหตุ </label>
                            <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"
                                placeholder="......" [(ngModel)]="modelRoomDetail.Remark"></textarea>
                        </div>
                    </div>
                </div>
                <div class=" card-footer">
                    <button class=" btn btn-fill btn-danger" type="submit" (click)="saveRoom()">อนุมัติ</button>
                    <button class=" btn btn-fill btn-danger" type="cancel"
                        (click)="modal.dismiss('Cross click')">ยกเลิก</button>
                    <div ngbDropdown class="d-inline-block">
                        <button class="btn btn-sm btn-outline-primary" id="dropdownBasic1"
                            ngbDropdownToggle>สถานะ</button>
                        <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
                            <button ngbDropdownItem>รอดำเนินการ</button>
                            <button ngbDropdownItem>อนุมัติ</button>
                            <button ngbDropdownItem>ยกเลิก</button>
                            <button ngbDropdownItem>สำเร็จแล้ว</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</ng-template>

<ng-template #lend let-modal>
    <div class=" col-md-12" style="padding: 0; ">
        <div class="card" style="margin: 0; ">
            <div class=" card-header">
                <h5 class=" title">การเบิก</h5>
            </div>
            <div class=" card-body">
                <div class=" row">
                    <div class=" col-sm-12 mb-1">
                        <div class=" form-group">
                            <label> ชื่อผู้จอง </label>
                            <input class=" form-control" placeholder="" type="text"
                            [(ngModel)]="modelItemDetail.userName" />
                        </div>
                    </div>
                </div>
                <div class=" row">
                    <div class=" col-sm-12 mb-1">
                        <div class=" form-group">
                            <label> อีเมล </label>
                            <input class=" form-control" placeholder="" type="text" [(ngModel)]="modelItemDetail.email" />
                        </div>
                    </div>
                </div>
                <div class=" row">
                    <div class=" col-md-12">
                        <div class=" form-group">
                            <label> เบอร์โทร </label>
                            <input class=" form-control" placeholder="" type="text" [(ngModel)]="modelItemDetail.equirment.eTelephone" />
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12 mb-1">
                        <label for="exampleFormControlSelect1">ชื่ออุปกรณ์</label>
                        <input class="form-control" type="text" [(ngModel)]="modelItemDetail.equirment.eqName" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12 mb-1">
                        <label for="exampleFormControlSelect1">รายละเอียดอุปกรณ์</label>
                        <input class="form-control" type="text" [(ngModel)]="modelItemDetail.equirment.eqDesc" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">วันที่เริ่มต้น</label>
                        <input type="date" class="form-control" [(ngModel)]="sDate" (ngModelChange)="rDate(sDate,'sdate')" />
                    </div>
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">วันที่สิ้นสุด</label>
                        <input type="date" class="form-control" [(ngModel)]="eDate" (ngModelChange)="rDate(eDate,'edate')" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">เวลาที่เริ่มต้น</label>
                        <input class="form-control" type="time"
                        [(ngModel)]="thStime" (ngModelChange)="thtimeChange(thStime,modelItemDetail.sTime)" />
                    </div>
                    <div class="col-6 mb-1">
                        <label for="exampleFormControlSelect1">เวลาที่สิ้นสุด</label>
                        <input class="form-control" type="text"
                        [(ngModel)]="thEtime" (ngModelChange)="thtimeChange(thStime,modelItemDetail.eTime)" />
                    </div>
                </div>
                <div class=" row">
                    <div class=" col-sm-6 mb-1">
                        <label for="changequantity">จำนวน</label>
                        <input id="changequantity" type="number" class="form-control form-control-sm"
                        [(ngModel)]="modelItemDetail.Quantity" />
                    </div>
                </div>
                <div class=" row">
                    <div class=" col-md-12">
                        <div class=" form-group">
                            <label> หมายเหตุ </label>
                            <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"
                                placeholder="......" [(ngModel)]="modelItemDetail.Remark"></textarea>
                        </div>
                    </div>
                </div>
                <div class=" card-footer">
                    <button class=" btn btn-fill btn-danger" type="submit" (click)="saveEquirment()">อนุมัติ</button>
                    <button class=" btn btn-fill btn-danger" type="cancel"
                        (click)="modal.dismiss('Cross click')">ยกเลิก</button>
                    <div ngbDropdown class="d-inline-block">
                        <button class="btn btn-sm btn-outline-primary" id="dropdownBasic1"
                            ngbDropdownToggle>สถานะ</button>
                        <div ngbDropdownMenu aria-labelledby="dropdownBasic1">
                            <button ngbDropdownItem>รอดำเนินการ</button>
                            <button ngbDropdownItem>อนุมัติ</button>
                            <button ngbDropdownItem>ยกเลิก</button>
                            <button ngbDropdownItem>สำเร็จแล้ว</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</ng-template>