<div class="w-full min-height-50px mb-10px justify-between items-center">
    <div class="flex justify-between">
        <div class="flex">

        </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" [(ngModel)]="search" style="height: 40px;">
                    <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-10 m-0 shadow-md"
                    data-hs-overlay="#type-registration-component-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-10 m-0 shadow-md"
                    data-hs-overlay="#type-registration-component-page-modal" (click)="currentModal='add';edit()"
                    (click)="openDialog()">
                    <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-10 m-0 shadow-md"
                    (click)="currentModal='delete';deleteType_registration()">
                    <i class="ri-delete-bin-6-line"></i>
                    {{'Delete' | translate}}
                </button>
            </div>
        </div>
    </div>
</div>



<div class="page px-rem">
    <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="typeList"
        [columns]="columns" [selectedItems]="selectedItems"
        (sendSelectData)="currentModal='edit';edit($event);openDialog()"
        (sendSelectedItems)="onSelectItemChange($event)">
    </app-datagrid-syncfution>
</div>


<ng-template #typeRegistrationModal let-modal>
    <h3 mat-dialog-title>
        {{currentModal=='add'?'เพิ่มประเภทสมรรถนะ':'EditCompetencyTypes' | translate}}
    </h3>
    <div class="w-full flex justify-end">
        <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)="selectCompetencyType()">
                    <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 mt-2rem">
            {{'Code' | translate}}
            <span class="text-danger">*
                <ng-container *ngIf="checkPrimary()&&currentModal=='add'">
                    รหัสซ้ำ
                </ng-container>
            </span>
        </label>
        <input type="text" id="input-label" class="ti-form-input w-1/2"
            [ngClass]="{'!bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
            [(ngModel)]="competoncy_type.competencyTypeId">
        <label for="detail_th" class="ti-form-label mt-1rem">
            {{'TypesNameThai' | translate}}<span class="text-danger">*</span></label>
        <input type="text" id="detail_th" class="ti-form-input w-2/3" [(ngModel)]="competoncy_type.tdesc">
        <label for="detail_eng" class="ti-form-label mt-1rem">
            {{'TypesNameEng' | translate}}
        </label>
        <input type="text" id="detail_eng" class="ti-form-input w-2/3" [(ngModel)]="competoncy_type.edesc">
        <label for="detail_eng" class="ti-form-label mt-1rem">
            {{'Abbreviations' | translate}}
            <span class="text-danger">*</span></label>
        <input type="text" id="detail_eng" class="ti-form-input w-2/3" [(ngModel)]="competoncy_type.shortName">
        <label for="detail_eng" class="ti-form-label mt-1rem">
            {{'ExpectationLevel' | translate}}
            <span class="text-danger">*</span></label>
        <input type="text" id="detail_eng" class="ti-form-input" style="width: 200px;"
            oninput="this.value = this.value.replace(/\D/g, '')" [(ngModel)]="competoncy_type.expectationLevel">
        <label for="detail_eng" class="ti-form-label mt-1rem">
            {{'Weight' | translate}}
        </label>
        <input type="text" id="detail_eng" class="ti-form-input" style="width: 200px;"
            oninput="this.value = this.value.replace(/[^\d.]/g, '').replace(/(\..*?)\..*/g, '$1').replace(/(\..*?)(\d{2})./g, '$1$2');"
            onchange="this.value = this.value.replace('', '0');this.value = parseFloat(this.value).toFixed(2)"
            [(ngModel)]="competoncy_type.weight">
    </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)="addType_registration()"
            [class.ti-btn-disabled]="!competoncy_type.competencyTypeId||!competoncy_type.tdesc||!competoncy_type.shortName||(currentModal=='add'&&checkPrimary())"
            [disabled]="!competoncy_type.competencyTypeId||!competoncy_type.tdesc||!competoncy_type.shortName||(currentModal=='add'&&checkPrimary())">
            {{'SaveData' | translate}}
        </button>
    </mat-dialog-actions>
</ng-template>

<div id="type-registration-component-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">
                    <ng-container *ngIf="currentModal=='add'||currentModal=='edit'">
                        <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
                            data-hs-overlay="#type-registration-component-page-modal">
                            <span class="sr-only">Close</span>
                            <i class="ti ti-circle-x fs-xxl"></i>
                        </button>
                    </ng-container>
                    <ng-container *ngIf="currentModal=='delete'">
                        <button type="button" class="hs-dropdown-toggle ti-modal-clode-btn text-danger"
                            data-hs-overlay="#type-registration-component-page-alert-modal">
                            <span class="sr-only">Close</span>
                            <i class="ti ti-circle-x fs-xxl"></i>
                        </button>
                    </ng-container>
                </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="#type-registration-component-page-modal">
                            ย้อนกลับ
                        </button>
                        <a class="ti-btn ti-btn-success" href="javascript:void(0);"
                            data-hs-overlay="#type-registration-component-page-alert-modal"
                            (click)="addType_registration()">
                            บันทึกข้อมูล
                        </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="#type-registration-component-page-alert-modal">
                            ย้อนกลับ
                        </button>
                        <a class="ti-btn ti-btn-danger" href="javascript:void(0);" *ngIf="numSelectItem()"
                            data-hs-overlay="#type-registration-component-page-alert-modal"
                            (click)="deleteType_registration()">
                            ลบข้อมูล
                        </a>
                    </ng-container>
                </div>
            </div>
        </div>
    </div>
</div>

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