<div class="w-full min-height-50px mb-10px justify-between items-center border-b-2 border-collapse">
    <div class="flex justify-between">
        <div class="flex">
            <button type="button" class="ti-btn ti-btn-outline ti-btn-outline-light h-20px m-0 shadow-md text-blue-500"
                (click)="onEdit()">
                <i class="ti ti-chevron-left"></i>
                {{'Back' | translate}}
            </button>
            <div class="font-size-18px font-weight-700 align-center font-bold py-2 text-primary px-4">
                {{'EditCompetencyMapping' | translate}}
            </div>
        </div>
    </div>
</div>
<div *ngIf="jobCode" class="py-2 border-b-2 border-collapse ">
    <div class="grid grid-cols-3 gap-6">
        <div class="col-span-1">
            <label for="hs-trailing-button-add-on-with-icon" class="ti-form-label">{{'JDCode' | translate}}</label>
        </div>
    </div>
    <div class="grid grid-cols-3 gap-6">
        <div class="col-span-1">
            <input type="text" id="input-label"
                class="py-2 px-3  ltr:pr-11 rtl:pl-11 ti-form-input w-2/3 rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10 bg-input-readonly"
                readonly [(ngModel)]="jobCode.jobCodeId">
        </div>
    </div>
    <div class="grid grid-cols-3 gap-6 mt-5">
        <div class="col-span-1">
            <label for="hs-trailing-button-add-on-with-icon" class="ti-form-label">{{'JobDescriptionThai'|
                translate}}</label>
        </div>
        <div class="col-span-1">
            <label for="hs-trailing-button-add-on-with-icon" class="ti-form-label">{{'JobDescriptionEng'|
                translate}}</label>
        </div>
    </div>
    <div class="grid grid-cols-3 gap-6">
        <div class="col-span-1">
            <input type="text" id="input-label"
                class="py-2 px-3  ltr:pr-11 rtl:pl-11 ti-form-input w-2/3 rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10 bg-input-readonly"
                readonly [(ngModel)]="jobCode.tdesc">
        </div>
        <div class="col-span-1">
            <input type="text" id="input-label"
                class="py-2 px-3  ltr:pr-11 rtl:pl-11 ti-form-input w-2/3 rounded-md ltr:rounded-r-md rtl:rounded-l-md focus:z-10 bg-input-readonly"
                readonly [(ngModel)]="jobCode.edesc">
        </div>
    </div>
</div>

<div class="header-title-type">
    <div class="flex justify-between">
        <div class="flex">
            <!-- Content ของ div แรก -->
            <div class="flex gap-x-6">
                <div class="flex items-center">
                    <input type="checkbox" class="ti-form-checkbox pointer-events-none" id="hs-default-checkbox"
                        [(ngModel)]="isDataListChecked">
                    <label for="hs-default-checkbox" class="text-sm text-gray-500 mx-2 pointer-events-none">
                        {{numDataListChecked}} {{'Selected'| translate}}</label>
                </div>
                <div class="mx-1 flex items-center">
                    <button (click)="isDataListCheckedAll = !isDataListCheckedAll;dataListCheckAll()"
                        class="focus:ring-2 focus:ring-primary rounded-sm flex item-center">
                        <i class="fs-l transition-all duration-200"
                            [ngClass]="{'ri-checkbox-multiple-line text-gray-500': !isDataListCheckedAll, 'ri-checkbox-multiple-fill text-primary': isDataListCheckedAll}"></i>
                    </button>
                    <label class="text-sm text-gray-500 ml-2">{{'SelectAll' | translate}}</label>
                </div>
            </div>
        </div>

        <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" style="height: 40px;" [(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-soft-success h-20px m-0 shadow-md"
                    data-hs-overlay="#edit-group-competencies-alert-add-modal">
                    <i class="ri-save-3-line"></i>
                    {{'Save' | translate}}
                </button>
            </div>
            <div class="px-1">
                <button type="button" class="ti-btn ti-btn-soft-secondary h-20px m-0 shadow-md"
                    (click)="searchModalChange()" data-hs-overlay="#edit-group-competencies-table-modal-select">
                    <i class="ri-add-line"></i>
                    {{'Add'| translate}}
                </button>
            </div>
            <div class="px-1">
                <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-20px m-0 shadow-md"
                    data-hs-overlay="#edit-group-competencies-alert-delete-modal" (click)="groupAssessmentIndex=-1">
                    <i class="ri-delete-bin-6-line"></i>
                    {{'Delete' | translate}}
                </button>
            </div>
            <!-- <div class="px-1">
                <button href="javascript:void(0);" class="ti-btn ti-btn-soft-warning h-10 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 id="card-type-1" role="tabpanel" aria-labelledby="card-type-item-1">
            <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 ['CompetencyCode','CompetencyName','ProficiencyLevel']; 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 || item === 'ProficiencyLevel'">
                                    <span class="text-sm">{{ item | translate}}</span>
                                </th>
                            </ng-container>
                        </tr>
                    </thead>
                    <tbody *ngIf="dataLoading">
                        <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="!dataLoading&&!dataListFilter().length">
                        <tr>
                            <td class="text-center" colspan="100%">
                                {{'NoInformation' | translate}}
                            </td>
                        </tr>
                    </tbody>
                    <tbody *ngIf="!dataLoading&&dataListFilter().length">
                        <tr
                            *ngFor="let item of dataListFilter()| slice:((currentPage-1) * 10) : (((currentPage-1) * 10) + 10);let i = index">
                            <td class="text-center">
                                <input type="checkbox" class="ti-form-checkbox cursor-pointer"
                                    id="checkbox-{{item.data.competencyIndicatorsCourses1Mini.competencyIndicatorsCourses0.competencyTopic.competencyTopicId}}"
                                    [(ngModel)]="item.check" (ngModelChange)="dataListCheck()">
                                <label
                                    for="checkbox-{{item.data.competencyIndicatorsCourses1Mini.competencyIndicatorsCourses0.competencyTopic.competencyTopicId}}">
                                    &nbsp;{{item.data.competencyIndicatorsCourses1Mini.competencyIndicatorsCourses0.competencyTopic.competencyTopicId}}
                                </label>
                            </td>
                            <td style="font-size: 12px; width: 60%;">
                                {{item.data.competencyIndicatorsCourses1Mini.competencyIndicatorsCourses0.competencyTopic.tdesc}}
                            </td>
                            <td style="font-size: 12px;text-align: center;">
                                {{item.data.competencyIndicatorsCourses1Mini.competencyIndicatorsCourses0.expectation}}
                            </td>
                            <!-- <td class="flex justify-center">
                                <i class="ti ti-trash cursor-pointer i-gray fs-l px-1"
                                    data-hs-overlay="#edit-group-competencies-alert-delete-modal"
                                    (click)="groupAssessmentIndex=i"></i>
                            </td> -->
                        </tr>
                    </tbody>
                </table>
            </div>

        </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" 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 {{dataListFilter().length<10 ?dataListFilter().length:
                    (currentPage==page.length ? ((currentPage * 10) - ((currentPage * 10) - dataListFilter().length) )
                    :(currentPage * 10) ) }} of {{dataListFilter().length}} items</span>
        </ul>
    </nav>
</div>



<div id="edit-group-competencies-table-modal-select" class="hs-overlay hidden ti-modal">
    <div
        class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out lg:!max-w-4xl lg:w-full m-3 lg:mx-auto h-[calc(100%-3.5rem)]  items-center">
        <div class="max-h-full overflow-hidden ti-modal-content">
            <div class="ti-modal-header">
                <h3 class="text-xxl font-bold text-primary">
                    {{'CompetencyTopics_list' | translate}}
                </h3>
                <div class="flex justify-end">
                    <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
                        data-hs-overlay="#edit-group-competencies-table-modal-select">
                        <span class="sr-only">Close</span>
                        <i class="ti ti-circle-x fs-xxl"></i>
                    </button>
                </div>
            </div>
            <div class="ti-modal-body">
                <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)]="searchModal"
                                (ngModelChange)="searchModalChange()">
                            <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 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 class="overflow-auto table-bordered" style="border-radius: 5px;">
                    <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 ['Competency_Code','CompetencyName','ProficiencyLevel','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 | translate}}</span>
                                            <div class="absolute top-1/2 transform -translate-y-1/2 right-0"
                                                *ngIf="!f && i==1">
                                                <svg class="head-table-icon" xmlns="http://www.w3.org/2000/svg"
                                                    width="30" height="13" 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>
                                            <div class="absolute top-1/2 transform -translate-y-1/2 right-0"
                                                *ngIf="!f && i==2">
                                                <svg class="head-table-icon" xmlns="http://www.w3.org/2000/svg"
                                                    width="20" height="13" 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="dataLoading">
                                <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="!dataLoading&&!dataListModalFilter().length">
                                <tr>
                                    <td class="text-center" colspan="100%">
                                        {{'NoInformation' | translate}}
                                    </td>
                                </tr>
                            </tbody>
                            <tbody *ngIf="!dataLoading&&dataListModalFilter().length">
                                <tr
                                    *ngFor="let item of dataListModalFilter()| slice:((currentPageModal-1) * 10) : (((currentPageModal-1) * 10) + 10);let i = index">
                                    <td class="text-center">
                                        {{item.data.competencyIndicatorsCourses0.competencyTopic.competencyTopicId}}
                                    </td>
                                    <td style="font-size: 12px; width: 60%;">
                                        {{item.data.competencyIndicatorsCourses0.competencyTopic.tdesc}}
                                    </td>
                                    <td style="font-size: 12px;text-align: center; width: 20%;">
                                        {{item.data.competencyIndicatorsCourses0.expectation}}</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)="selectIndicatorsCourses(item.data)"
                                                data-hs-overlay="#edit-group-competencies-table-modal-select">
                                                <i class="ri-add-line"></i>
                                                {{'Select' | translate}}
                                            </button>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <nav class="pagination-style-3 overflow-auto my-5" *ngIf="pageModal.length">
                    <ul class="ti-pagination">
                        <li>
                            <a aria-label="anchor" class="page-link" href="javascript:void(0);"
                                (click)="currentPageModal = (currentPageModal-1 || 1)">
                                <i class="ri-arrow-left-s-line align-middle rtl:rotate-180"></i>
                            </a>
                        </li>
                        <li *ngFor="let item of pageModal;let f = first;let l = last">
                            <ng-container
                                *ngIf="item==3&&currentPageModal!=1&&currentPageModal!=2&&currentPageModal!=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==currentPageModal-1||item==currentPageModal||item==currentPageModal+1)">
                                <a class="page-link" href="javascript:void(0);" [class.active]="item==currentPageModal"
                                    (click)="currentPageModal=item">{{item}}
                                </a>
                            </ng-container>
                            <ng-container
                                *ngIf="item==pageModal.length-2&&currentPageModal!=pageModal.length&&currentPageModal!=pageModal.length-1&&currentPageModal!=pageModal.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)="currentPageModal = (currentPageModal > pageModal.length-1 ? currentPageModal: currentPageModal+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 {{((currentPageModal-1) * 10)+1}} to {{dataListModalFilter().length<10
                                ?dataListModalFilter().length: (currentPageModal==pageModal.length ? ((currentPageModal
                                * 10) - ((currentPageModal * 10) - dataListModalFilter().length) ) :(currentPageModal *
                                10) ) }} of {{dataListModalFilter().length}} items</span>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>


<div id="edit-group-competencies-alert-add-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="#edit-group-competencies-alert-add-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="#edit-group-competencies-modal-add">
                        ย้อนกลับ
                    </button>
                    <a class="ti-btn ti-btn-success" href="javascript:void(0);"
                        data-hs-overlay="#edit-group-competencies-alert-add-modal" (click)="saveGroupAssessment1()">
                        บันทึกข้อมูล
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="edit-group-competencies-alert-edit-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="#edit-group-competencies-alert-edit-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="#edit-group-competencies-modal-edit">
                        ย้อนกลับ
                    </button>
                    <a class="ti-btn ti-btn-success" href="javascript:void(0);"
                        data-hs-overlay="#edit-group-competencies-alert-edit-modal">
                        บันทึกข้อมูล
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="edit-group-competencies-alert-delete-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="#edit-group-competencies-alert-delete-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">
                    <ng-container *ngIf="numDataListChecked">
                        ยืนยันการลบข้อมูลหรือไม่
                    </ng-container>
                    <ng-container *ngIf="!numDataListChecked">
                        เลือกข้อมูลที่ต้องการลบ
                    </ng-container>!
                </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="#edit-group-competencies-alert-delete-modal">
                        ย้อนกลับ
                    </button>
                    <a class="ti-btn ti-btn-success" href="javascript:void(0);"
                        data-hs-overlay="#edit-group-competencies-alert-delete-modal" *ngIf="numDataListChecked"
                        (click)="deleteGroupAssessmentById()">
                        ลบข้อมูล
                    </a>
                </div>

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