<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=" h-45px 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-10 m-0 shadow-md"
                data-hs-overlay="#supjob-upload-modal"
                (click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
                <i class="ti ti-file-plus"></i>
                {{'Import' | translate}}
            </button>
        </div>
        <div class="px-1">
            <button type="button" class="ti-btn ti-btn-soft-secondary h-45px m-0 shadow-md"
                data-hs-overlay="#sub-job-competency-component-modal-edit" (click)="add();currentModal='add';">
                <i class="ri-add-line"></i>
                {{'Add' | translate}}
            </button>
        </div>
        <div class="px-1">
            <button type="button" class="ti-btn ti-btn-soft-danger  h-45px m-0 shadow-md"
                data-hs-overlay="#company-registration-page-alert-modal" (click)="currentModal='delete'">
                <i class="ri-delete-bin-6-line"></i>
                {{'Delete' | translate}}
            </button>
        </div>
    </div>
</div>

<div class="page px-rem">
    <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="jobCodeList"
        [columns]="columns" [selectedItems]="selectedItems" modalName="#sub-job-competency-component-modal-edit"
        (sendSelectData)="currentModal='edit';edit($event)" (sendSelectedItems)="onSelectItemChange($event)">
    </app-datagrid-syncfution>
</div>


<div id="sub-job-competency-component-modal-edit" 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)]">
        <div class="max-h-full overflow-hidden ti-modal-content">
            <div class="ti-modal-header">
                <h3 class="text-xxl font-bold text-primary">
                    {{currentModal== "add"?'เพิ่มข้อมูลทั่วไป':'เเก้ไขข้อมูลทั่วไป'}}
                </h3>
                <div class="flex justify-end">
                    <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
                        data-hs-overlay="#sub-job-competency-component-modal-edit">
                        <span class="sr-only">Close</span>
                        <i class="ti ti-circle-x fs-xxl"></i>
                    </button>
                </div>
            </div>
            <div class="ti-modal-center">
                <div class="flex justify-end" style="padding-right: 1rem;">
                    <div class="px-1">
                        <button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md"
                            (click)="clearValue()">
                            <svg class="svg-indigo" width="16" height="16" viewBox="0 0 64.00 64.00"
                                xmlns="http://www.w3.org/2000/svg" fill="none" stroke="#595BEA" stroke-width="3.84"
                                transform="rotate(45)matrix(-1, 0, 0, 1, 0, 0)">
                                <g id="SVGRepo_bgCarrier" stroke-width="0"></g>
                                <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
                                <g id="SVGRepo_iconCarrier">
                                    <path d="M15 49A24 24 0 0 1 32 8"></path>
                                    <path d="M49 15a24 24 0 0 1-17 41"></path>
                                    <polyline points="15.03 40 15.03 48.97 8 48.97"></polyline>
                                    <polyline points="48.97 24 48.97 15.03 56 15.03"></polyline>
                                </g>
                            </svg>
                            Clear
                        </button>
                    </div>
                </div>
            </div>
            <div class="ti-modal-body" style="padding-top: 0px;">
                <label for="input-label" class="ti-form-label mt-1rem">รหัสงาน<span class="text-danger">*
                        <ng-container *ngIf="currentModal=='add'&&checkPrimary()">
                            รหัสงานซ้ำ
                        </ng-container>
                    </span></label>
                <input type="text" id="input-label"
                    class="ti-form-input {{currentModal == 'edit' ? 'bg-input-readonly' : ''}}"
                    [attr.readonly]="currentModal == 'edit' ? true : null" [(ngModel)]="selectJob.jobcodeId"
                    (ngModelChange)="checkJodid()">
                <label for="detail_th" class="ti-form-label mt-1rem">ชื่อลักษณะงาน (ไทย)<span
                        class="text-danger">*</span></label>
                <input type="text" id="detail_th" class="ti-form-input " [(ngModel)]="selectJob.tdesc">
                <label for="detail_eng" class="ti-form-label mt-1rem">ชื่อลักษณะงาน (อังกฤษ)</label>
                <input type="text" id="detail_eng" class="ti-form-input " [(ngModel)]="selectJob.edesc">

                <label for="detail_eng" class="ti-form-label mt-2rem">ตำแหน่ง</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-position"
                    id="choices-single-position" [(ngModel)]="positionId" (ngModelChange)="changPosition()">
                    <ng-option *ngFor="let item of positionList" [value]="item.positionId">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ฝ่าย</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-bu1" id="choices-single-bu1"
                    [(ngModel)]="bu1Id" (ngModelChange)="changBu1()">
                    <ng-option *ngFor="let item of bu1List" [value]="item.bu1id">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">แผนก</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-bu2" id="choices-single-bu2"
                    [(ngModel)]="bu2Id" (ngModelChange)="changBu2()">
                    <ng-option *ngFor="let item of bu2List" [value]="item.bu2id">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ส่วน</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-bu3" id="choices-single-bu3"
                    [(ngModel)]="bu3Id" (ngModelChange)="changBu3()">
                    <ng-option *ngFor="let item of bu3List" [value]="item.bu3id">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ส่วนย่อย1</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-bu4" id="choices-single-bu4"
                    [(ngModel)]="bu4Id" (ngModelChange)="changBu4()">
                    <ng-option *ngFor="let item of bu4List" [value]="item.bu4id">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ส่วนย่อย2</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-bu5" id="choices-single-bu5"
                    [(ngModel)]="bu5Id" (ngModelChange)="changBu5()">
                    <ng-option *ngFor="let item of bu5List" [value]="item.bu5id">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ส่วนย่อย3</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-bu6" id="choices-single-bu6"
                    [(ngModel)]="bu6Id" (ngModelChange)="changBu6()">
                    <ng-option *ngFor="let item of bu6List" [value]="item.bu6id">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ส่วนย่อย4</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-bu7" id="choices-single-bu7"
                    [(ngModel)]="bu7Id" (ngModelChange)="changBu7()">
                    <ng-option *ngFor="let item of bu7List" [value]="item.bu7id">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ตำแหน่งผู้บังคับบัญชา</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-supervisorJobCode"
                    id="choices-single-supervisorJobCode" [(ngModel)]="jd" (ngModelChange)="changSupervisorJobCode()">
                    <ng-option *ngFor="let item of jdList" [value]="item.jobCodeId">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ระดับพนักงาน</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-jl" id="choices-single-jl"
                    [(ngModel)]="jl" (ngModelChange)="changJl()">
                    <ng-option *ngFor="let item of jlList" [value]="item.plId">{{item.tdesc}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">ระดับความคาดหวัง</label>
                <ng-select class="ti-form-select" data-trigger name="choices-single-expectation"
                    id="choices-single-expectation" [(ngModel)]="expectation" (ngModelChange)="changExpectation()">
                    <ng-option *ngFor="let item of [1,2,3,4,5]" [value]="item">{{item}}</ng-option>
                </ng-select>

                <label for="detail_eng" class="ti-form-label mt-2rem">วัตถุประสงค์ของตำแหน่งงาน (Objective)</label>
                <input type="text" id="detail_eng" class="ti-form-input h-16" [(ngModel)]="selectJob.jobObjective">

                <div class="flex justify-end mt-2rem mb-1rem">
                    <button type="button" (click)="save()"
                        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="#sub-job-competency-component-modal-edit">
                        ย้อนกลับ
                    </button>
                    <button
                        class="ti-btn ti-btn-success {{checkJobCodeId&&currentModal=='add'||!selectJob.jobcodeId||!selectJob.tdesc||(currentModal=='add'&&checkPrimary()) ? 'ti-btn-disabled' : ''}}"
                        [disabled]="checkJobCodeId&&currentModal=='add'||!selectJob.jobcodeId||!selectJob.tdesc||(currentModal=='add'&&checkPrimary())"
                        data-hs-overlay="#company-registration-page-alert-modal">
                        บันทึกข้อมูล
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="company-registration-page-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="#company-registration-page-alert-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="currentModal=='add'||currentModal=='edit'">
                        ยืนยันการบันทึกข้อมูลหรือไม่
                    </ng-container>
                    <ng-container *ngIf="currentModal=='delete'">
                        <ng-container *ngIf="numSelectItem()">
                            ยืนยันการลบข้อมูลหรือไม่
                        </ng-container>
                        <ng-container *ngIf="!numSelectItem()">
                            เลือกข้อมูลที่ต้องการลบ
                        </ng-container>
                    </ng-container>
                </p>

                <div class="flex justify-end mt-2rem mb-1rem">
                    <ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
                        <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="#company-registration-page-alert-modal">
                            ย้อนกลับ
                        </button>
                        <a class="ti-btn ti-btn-success" href="javascript:void(0);"
                            data-hs-overlay="#company-registration-page-alert-modal" (click)="save()">
                            บันทึกข้อมูล
                        </a>
                    </ng-container>
                    <ng-container *ngIf="currentModal=='delete'">
                        <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="#company-registration-page-alert-modal">
                            ย้อนกลับ
                        </button>
                        <a class="ti-btn ti-btn-danger" href="javascript:void(0);"
                            data-hs-overlay="#company-registration-page-alert-modal" (click)="deleteJob()"
                            *ngIf="numSelectItem()">
                            ลบข้อมูล
                        </a>
                    </ng-container>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="supjob-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="#section-registration-upload-modal" (click)="uploadFile()"
                        [class.ti-btn-disabled]="!selectedFile" [disabled]="!selectedFile">
                        อัปโหลด
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>