<ng-container *ngIf="!onEdit">
    <div class="header-title-type">
        <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="Search by No. or Name"
                            [(ngModel)]="search" (ngModelChange)="searchChange()">
                        <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="#evaluation-grouping-upload-modal"
                        (click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
                        <i class="ti ti-file-plus"></i>
                        import
                    </button>
                </div>
                <div class="px-1">
                    <button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-45px m-0 shadow-md">
                        <i class="ti ti-book fs-l"></i>
                        Help
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="page px-rem">
        <div class="overflow-auto table-bordered rounded-t-md">
            <div class="overflow-auto shadow-md">
                <table class="ti-custom-table ti-custom-table-head ti-custom-table-hover">
                    <thead>
                        <tr>
                            <ng-container
                                *ngFor="let item of ['รหัส','ชื่อเครื่องมือประเมิน','Action']; let f = first; let l = last; let i = index">
                                <th scope="col" class="relative px-10px py-10px bg-soft-secondary text-primary"
                                    [class.!text-center]="f||l">
                                    <span class="text-sm">{{ item }}</span>
                                    <div class="absolute top-1/2 transform -translate-y-1/2 right-0" *ngIf="!l&&!f">
                                        <svg class="head-table-icon" xmlns="http://www.w3.org/2000/svg" width="50"
                                            height="16" fill="currentColor" viewBox="0 0 16 16">
                                            <path
                                                d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z">
                                            </path>
                                        </svg>
                                    </div>
                                </th>
                            </ng-container>
                        </tr>
                    </thead>
                    <tbody *ngIf="pl.loading">
                        <tr>
                            <td class="text-center" colspan="100%">
                                <div *ngFor="let item of [1,2,3]" class="ti-spinner w-8 h-8 text-secondary mx-1"
                                    role="status" aria-label="loading">
                                    <span class="sr-only">Loading...</span>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                    <tbody *ngIf="!pl.loading&&!plListFilter().length">
                        <tr>
                            <td class="text-center" colspan="100%">
                                ไม่พบข้อมูล
                            </td>
                        </tr>
                    </tbody>
                    <tbody *ngIf="!pl.loading&&plListFilter().length">
                        <tr
                            *ngFor="let item of plListFilter()| slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
                            <td style="font-size: 12px; padding-left: 4rem;">{{item.data.plId}}</td>
                            <td style="font-size: 12px; padding-left: 1.5rem; width: 600px;">{{item.data.tdesc}}
                            </td>
                            <td class="flex justify-center">
                                <i class="ti ti-edit cursor-pointer i-gray fs-l px-1"
                                    (click)="selectPl(item.data);onEdit=true;onSendPathTitle()"></i>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <nav class="pagination-style-3 overflow-auto my-5" *ngIf="page.length">
            <ul class="ti-pagination">
                <li>
                    <a aria-label="anchor" class="page-link !pl-0" href="javascript:void(0);"
                        (click)="currentPage = (currentPage-1 || 1)">
                        <i class="ri-arrow-left-s-line align-middle rtl:rotate-180"></i>
                    </a>
                </li>
                <li *ngFor="let item of page;let f = first;let l = last">
                    <ng-container *ngIf="item==3&&currentPage!=1&&currentPage!=2&&currentPage!=3">
                        <a aria-label="anchor" class="page-link" href="javascript:void(0);"><i class="ri-more-line"></i>
                        </a>
                    </ng-container>
                    <ng-container *ngIf="(f||l)||(item==currentPage-1||item==currentPage||item==currentPage+1)">
                        <a class="page-link" href="javascript:void(0);" [class.active]="item==currentPage"
                            (click)="currentPage=item">{{item}}
                        </a>
                    </ng-container>
                    <ng-container
                        *ngIf="item==page.length-2&&currentPage!=page.length&&currentPage!=page.length-1&&currentPage!=page.length-2">
                        <a aria-label="anchor" class="page-link" href="javascript:void(0);"><i class="ri-more-line"></i>
                        </a>
                    </ng-container>
                </li>
                <li>
                    <a aria-label="anchor" class="page-link" href="javascript:void(0);"
                        (click)="currentPage = (currentPage > page.length-1 ? currentPage: currentPage+1 )">
                        <i class="ri-arrow-right-s-line align-middle rtl:rotate-180"></i>
                    </a>
                </li>
            </ul>
            <ul class="nav-tabs mt-3">
                <span>Show {{((currentPage-1) * 10)+1}} to {{plListFilter().length<10 ?plListFilter().length:
                        (currentPage==page.length ? ((currentPage * 10) - ((currentPage * 10) - plListFilter().length) )
                        :(currentPage * 10) ) }} of {{plListFilter().length}} items</span>
            </ul>
        </nav>
    </div>

    <div id="evaluation-grouping-upload-modal" class="hs-overlay hidden ti-modal">
        <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" class="ti-btn ti-btn-secondary"
                            data-hs-overlay="#evaluation-grouping-upload-modal" [class.ti-btn-disabled]="!selectedFile"
                            (click)="uploadFile()" [disabled]="!selectedFile" [disabled]="!selectedFile">
                            อัปโหลด
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</ng-container>
<ng-container *ngIf="onEdit">
    <app-edit-evaluation-grouping [pl]="pl.select"
        (sendOnEdit)="onEdit=$event;onSendPathTitle()"></app-edit-evaluation-grouping>
</ng-container>