<div class="w-full min-height-50px mb-10px justify-between items-center">
    <div class="flex justify-end">
        <div class="px-1">
            <div class="relative shadow-md">
                <input type="text" id="hs-leading-icon" name="hs-leading-icon"
                    class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 " [placeholder]="'SearchByNoOrName' | translate"
                    [(ngModel)]="search">
                <div
                    class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
                    <i class="ri-search-line text-gray"></i>
                </div>
            </div>
        </div>
        <div class="px-1">
            <button type="button"
                class="ti-btn ti-btn bg-pink-500/10 text-pink-500 hover:text-white hover:bg-pink-500 ring-offset-white focus:ring-pink-500 dark:focus:ring-offset-white/10 h-45px m-0 shadow-md"
                data-hs-overlay="#set-approvers-upload-modal"
                (click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
                <i class="ti ti-file-plus"></i>
                {{'Import' | translate}}
            </button>
        </div>
    </div>
</div>

<div class="page px-rem">
    <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="groupapprove_list"
        [columns]="columns" [checkBoxSetting]="false"
        (sendSelectData)="currentModal='edit';selectGroupapprove($event);openDialog()">
    </app-datagrid-syncfution>
</div>


<ng-template #setApproversModal let-modal>
    <h3 mat-dialog-title>
        {{currentModal=='add'?'เพิ่มหัวข้อสมรรถนะ':'AssignApprover' | translate}}
    </h3>
    <div class="w-full flex justify-end mb-1rem">
        <div class="absolute flex">
            <div class="px-1">
                <button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md" (click)="clear()">
                    <i class="ti ti-eraser text-base"></i>
                    {{'Clear' | translate}}
                </button>
            </div>
        </div>
    </div>
    <mat-dialog-content>
        <label for="input-label" class="ti-form-label">{{'EmployeeName' | translate}}<span class="text-danger">*</span></label>
        <input type="text" id="input-label" class="ti-form-input w-1/2 !bg-input-readonly" readonly
            [value]="groupapprove.apsassessy.thFullName">
        <label for="input-label" class="ti-form-label mt-2rem">{{'JobLevelJL' | translate}}</label>
        <input type="text" id="input-label" class="ti-form-input w-1/2 bg-input-readonly" readonly
            [value]="groupapprove.personalLevel.tdesc">
        <label class="ti-form-label mt-2rem">{{'Assessor1'| translate}}</label>
        <div class="flex">
            <div class="relative flex rounded-md w-2/3">
                <input type="text" name="hs-leading-button-add-on-with-icon-and-button"
                    class="ti-form-input rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10" readonly
                    style="padding-right: 2.5rem;" [value]="groupapprove.apsapprove1.thFullName">
                <div
                    class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
                    <button type="button" class="flex items-center text-red-500"
                        (click)="empnumber = 1;selectEMP();empnumber = 2;selectEMP();empnumber = 3;selectEMP();empnumber = 4;selectEMP();empnumber = 5;selectEMP()">
                        <i class="ti ti-circle-x cursor-pointer"></i>
                    </button>
                    <button type="button" class="flex items-center text-gray-500 dark:text-white/70"
                        (click)="empnumber = 1;openDialogEmp()">
                        <i class="ri-search-line cursor-pointer text-gray"></i>
                    </button>
                </div>
            </div>
        </div>
        <ng-container *ngIf="groupapprove.apsapprove1.employeeId">
            <label class="ti-form-label mt-2rem">{{'Assessor2'| translate}}</label>
            <div class="flex">
                <div class="relative flex rounded-md w-2/3">
                    <input type="text" name="hs-leading-button-add-on-with-icon-and-button"
                        class="ti-form-input rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10" readonly
                        style="padding-right: 2.5rem;" [value]="groupapprove.apsapprove2.thFullName">
                    <div
                        class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
                        <button type="button" class="flex items-center text-red-500"
                            (click)="empnumber = 2;selectEMP();empnumber = 3;selectEMP();empnumber = 4;selectEMP();empnumber = 5;selectEMP()">
                            <i class="ti ti-circle-x cursor-pointer"></i>
                        </button>
                        <button type="button" class="flex items-center text-gray-500 dark:text-white/70"
                            (click)="empnumber = 2;openDialogEmp()">
                            <i class="ri-search-line cursor-pointer text-gray"></i>
                        </button>
                    </div>
                </div>
            </div>
        </ng-container>
        <ng-container *ngIf="groupapprove.apsapprove2.employeeId">
            <label class="ti-form-label mt-2rem">{{'Assessor3'| translate}}</label>
            <div class="flex">
                <div class="relative flex rounded-md w-2/3">
                    <input type="text" name="hs-leading-button-add-on-with-icon-and-button"
                        class="ti-form-input rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10" readonly
                        style="padding-right: 2.5rem;" [value]="groupapprove.apsapprove3.thFullName">
                    <div
                        class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
                        <button type="button" class="flex items-center text-red-500"
                            (click)="empnumber = 3;selectEMP();empnumber = 4;selectEMP();empnumber = 5;selectEMP()">
                            <i class="ti ti-circle-x cursor-pointer"></i>
                        </button>
                        <button type="button" class="flex items-center text-gray-500 dark:text-white/70"
                            (click)="empnumber = 3;openDialogEmp()">
                            <i class="ri-search-line cursor-pointer text-gray"></i>
                        </button>
                    </div>
                </div>
            </div>
        </ng-container>
        <ng-container *ngIf="groupapprove.apsapprove3.employeeId">
            <label class="ti-form-label mt-2rem">{{'Assessor4'| translate}}</label>
            <div class="flex">
                <div class="relative flex rounded-md w-2/3">
                    <input type="text" name="hs-leading-button-add-on-with-icon-and-button"
                        class="ti-form-input rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10" readonly
                        style="padding-right: 2.5rem;" [value]="groupapprove.apsapprove4.thFullName">
                    <div
                        class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
                        <button type="button" class="flex items-center text-red-500"
                            (click)="empnumber = 4;selectEMP();empnumber = 5;selectEMP()">
                            <i class="ti ti-circle-x cursor-pointer"></i>
                        </button>
                        <button type="button" class="flex items-center text-gray-500 dark:text-white/70"
                            (click)="empnumber = 4;openDialogEmp()">
                            <i class="ri-search-line cursor-pointer text-gray"></i>
                        </button>
                    </div>
                </div>
            </div>
        </ng-container>
        <ng-container *ngIf="groupapprove.apsapprove4.employeeId">
            <label class="ti-form-label mt-2rem">{{'Assessor5'| translate}}</label>
            <div class="flex">
                <div class="relative flex rounded-md w-2/3">
                    <input type="text" name="hs-leading-button-add-on-with-icon-and-button"
                        class="ti-form-input rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10" readonly
                        style="padding-right: 2.5rem;" [value]="groupapprove.apsapprove5.thFullName">
                    <div
                        class="absolute inset-y-0 ltr:right-0 rtl:left-0 flex items-center z-20 ltr:pr-4 rtl:pl-4 space-x-2">
                        <button type="button" class="flex items-center text-red-500"
                            (click)="empnumber = 5;selectEMP()">
                            <i class="ti ti-circle-x cursor-pointer"></i>
                        </button>
                        <button type="button" class="flex items-center text-gray-500 dark:text-white/70"
                            (click)="empnumber = 5;openDialogEmp()">
                            <i class="ri-search-line cursor-pointer text-gray"></i>
                        </button>
                    </div>
                </div>
            </div>
        </ng-container>
    </mat-dialog-content>
    <mat-dialog-actions align="end">
        <button type="button" mat-button [mat-dialog-close]
            class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10">
            {{'Back' | translate}}
        </button>
        <button type="button" class="ti-btn ti-btn-success" mat-button (click)="addgroupapprove()"
            [class.ti-btn-disabled]="!groupapprove.apsapprove1.thFullName||(currentModal=='add')"
            [disabled]="!groupapprove.apsapprove1.thFullName||(currentModal=='add')">
            {{'SaveData' | translate}}
        </button>
    </mat-dialog-actions>
</ng-template>


<ng-template #employeeTableModal let-modal>
    <h3 mat-dialog-title>
        รายชื่อพนักงาน
    </h3>

    <mat-dialog-content>
        <div class="flex justify-end pb-1rem">
            <div class="px-1">
                <div class="relative shadow-md">
                    <input type="text" id="hs-leading-icon" name="hs-leading-icon"
                        class="ti-form-input ltr:pl-11 rtl:pr-11 focus:z-10 "
                        [placeholder]="'SearchByNoOrName' | translate" [(ngModel)]="search"
                        (ngModelChange)="searchEMP()">
                    <div
                        class="absolute inset-y-0 ltr:left-0 rtl:right-0 flex items-center pointer-events-none z-20 ltr:pl-4 rtl:pr-4">
                        <i class="ri-search-line text-gray"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="overflow-auto border">
            <table class="ti-custom-table ti-custom-table-head ti-custom-table-hover">
                <thead>
                    <tr>
                        <ng-container
                            *ngFor="let item of ['รหัส','ชื่อ','นามสกุล','ตำเเหน่ง','หน่วยงาน','การจัดการ']; let f = first; let l = last">
                            <th scope="col" class="relative px-10px py-10px bg-soft-secondary text-primary"
                                [class.!text-center]="f">
                                <span class="text-sm">{{ item }}</span>
                                <div class="absolute top-1/2 transform -translate-y-1/2 right-0" *ngIf="!l">
                                    <i class="ti ti-dots-vertical fs-l"></i>
                                </div>
                            </th>
                        </ng-container>
                    </tr>
                </thead>
                <tbody *ngIf="!employee_listFilter().length">
                    <tr>
                        <td class="text-center" colspan="100%">
                            ไม่พบข้อมูล
                        </td>
                    </tr>
                </tbody>
                <tbody *ngIf="employee_listFilter().length">
                    <tr
                        *ngFor="let item of employee_listFilter() | slice:((employeeModal.currentPage-1) * 10) : (((employeeModal.currentPage-1) * 10) + 10);let i = index">
                        <td>{{item.employeeId}}</td>
                        <td>{{item.fname}}</td>
                        <td>{{item.lname}}</td>
                        <td>
                            {{item.position.tdesc}}
                        </td>
                        <td>{{item.bu1.bu1id}}</td>
                        <td class="flex justify-center">
                            <div class="px-1">
                                <button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
                                    (click)="selectEMP(item);closeDialogEmp()">
                                    <i class="ri-add-line"></i>
                                    Select
                                </button>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <app-pagination [totalItems]="groupapprove_listFilter().length" [pageSize]="employeeModal.pageSize"
            (pageChange)="employeeModal.currentPage = $event"
            (pageSizeChange)="employeeModal.pageSize = $event;employeeModal.currentPage = 1"></app-pagination>
    </mat-dialog-content>
    <mat-dialog-actions align="end">
        <button type="button" mat-button [mat-dialog-close]
            class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10">
            ย้อนกลับ
        </button>
    </mat-dialog-actions>
</ng-template>

<div id="set-approvers-upload-modal" class="hs-overlay hidden ti-modal" aria-overlay="'false'">
    <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
        <div class="ti-modal-header bg-primary !rounded-none !rounded-t-sm">
            <h5 class="text-xxl font-bold text-white">
                นำเข้าผู้ประเมิน
            </h5>
        </div>
        <div class="ti-modal-body max-h-full overflow-hidden ti-modal-content !rounded-t-none !rounded-b-sm">
            <h1 class="mt-2" style="text-align: center;">ไฟล์</h1>
            <div class="mt-2 p-2">
                <div class="flex rounded-md">
                    <input #fileInput id="fileInput" type="file" (change)="onFileSelected($event)" hidden>
                    <input type="text" [value]="selectedFileName" readonly (click)="fileInput.click()"
                        class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10 cursor-pointer">
                    <button type="button" (click)="fileInput.click()"
                        class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm">
                        <i class="ti ti-upload"></i>
                    </button>
                </div>
                <div class="flex justify-center mt-2rem ">
                    <h1 class="cursor-pointer justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px
                    text-center text-secondary border-secondary border-b-2 align-items-end" (click)="downloadFile()">
                        ดาวน์โหลดตัวอย่างไฟล์</h1>
                </div>
                <div class="flex justify-center mt-2rem mb-1rem space-x-4">
                    <button type="submit" data-hs-overlay="#set-approvers-upload-modal" class="ti-btn ti-btn-secondary"
                        [class.ti-btn-disabled]="!selectedFile" (click)="uploadFile()" [disabled]="!selectedFile">
                        อัปโหลด
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>


<div id="set-approvers-alert-modal" class="hs-overlay hidden ti-modal">
    <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)] flex items-center">
        <div class="max-h-full overflow-hidden ti-modal-content w-full">
            <div class="ti-modal-header">
                <h3 class="text-xxl font-bold text-primary">
                    แจ้งเตือน
                </h3>
                <div class="flex justify-end">
                    <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
                        data-hs-overlay="#set-approvers-modal">
                        <span class="sr-only">Close</span>
                        <i class="ti ti-circle-x fs-xxl"></i>
                    </button>
                </div>
            </div>
            <div class="ti-modal-body ">
                <p class="mt-1 text-gray-800 dark:text-white/70">
                    ยืนยันการเเก้ไขข้อมูลหรือไม่
                </p>

                <div class="flex justify-end mt-2rem mb-1rem">
                    <button type="button"
                        class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10"
                        data-hs-overlay="#set-approvers-modal">
                        ย้อนกลับ
                    </button>
                    <a class="ti-btn ti-btn-success" href="javascript:void(0);"
                        data-hs-overlay="#set-approvers-alert-modal" (click)="addgroupapprove()">
                        บันทึกข้อมูล
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>