<admin-page-header [title]="'Faq Category'"></admin-page-header>

<div class="col-xl-12 col-lg-12 col-md-12">
  <div class="card ">
    <div class="card-header border-0 d-sm-max-flex">
      <h4 class="card-title">{{'Faq Category' | translate}}</h4>
      <div class="card-options mt-sm-max-2">
        @if (permission?.includes('FAQ Category Create')) {
          <a (click)="createModelPopup(addFaqsmodel)" href="javascript:void(0)" class="btn btn-secondary me-3" id="addfaqcategory">{{'Add Faq Category' |
          translate}}</a>
        }
      </div>
    </div>
    <div class="card-body">
      <div class="table-responsive spruko-delete">
        <div class="table-options">
          <div class="custom-buttons">
            @if (permission?.includes('FAQ Category Delete')) {
              <button type="button" [disabled]="sendingResponse['massDelFaq']" (click)="massDeletefaqsCat('massDelFaq')" id="massdeletenotify"
                class="btn btn-outline-light btn-sm mb-4 "><i class="fe fe-trash"></i>
                {{'Delete'
                |
                translate}}@if (sendingResponse['massDelFaq']) {
                <i class="fa fa-spinner fa-spin mx-1"></i>
              }</button>
            }
          </div>
          <mat-form-field class="pull-right">

            <input type="text" matInput (keyup)="applyFilter($event)" [placeholder]="'search' | translate" #input>
          </mat-form-field>
        </div>
        <div>
          @if (isloader) {
            <mat-progress-bar mode="indeterminate"></mat-progress-bar>
          }
          <table class="table table-bordered border-bottom text-nowrap ticketdeleterow w-100 dataTable no-footer dtr-inline" mat-table [dataSource]="dataSource" matSort>

            <!-- Sno Column -->
            <ng-container matColumnDef="sno">
              <th scope="col" class="wpx-40 text-center" mat-header-cell *matHeaderCellDef mat-sort-header="id"> {{'Sl.No' | translate}}
              </th>
              <td mat-cell *matCellDef="let row; let i = index" class="wpx-40 text-center"> {{i + 1 + (paginator.pageIndex * paginator.pageSize)}}
              </td>
            </ng-container>
            <!-- Checkbox Column -->
            <ng-container matColumnDef="select">
              <th scope="col" mat-header-cell class="wpx-40 text-center" *matHeaderCellDef>
                <mat-checkbox (change)="$event ? toggleAllRows() : null" [checked]="selection.hasValue() && isAllSelected()" [indeterminate]="selection.hasValue() && !isAllSelected()"
                  [aria-label]="checkboxLabel()">
                </mat-checkbox>
              </th>
              <td mat-cell class="wpx-40 text-center" *matCellDef="let row">
                <mat-checkbox (click)="$event.stopPropagation()" (change)="$event ? selection.toggle(row) : null" [checked]="selection.isSelected(row)"
                  [aria-label]="checkboxLabel(row)">
                </mat-checkbox>
              </td>
            </ng-container>

            <!-- Faq Category Name Column -->
            <ng-container matColumnDef="faqcategorycame">
              <th scope="col" mat-header-cell *matHeaderCellDef mat-sort-header="faqcategoryname"> {{'Faq Category Name' | translate}}
              </th>
              <td mat-cell *matCellDef="let row">
                {{row?.faqcategoryname}}
              </td>

            </ng-container>
            <!-- Status Column -->
            <ng-container matColumnDef="status">
              <th scope="col" mat-header-cell *matHeaderCellDef mat-sort-header> {{'Status' | translate}}
              </th>
              <td mat-cell *matCellDef="let row">
                @if (permission?.includes('FAQ Category Edit')) {
                  <label class="custom-switch form-switch mb-0">
                    <input type="checkbox" name="status" (click)="statusUpdate(row)" id="myonoffswitch{{row.id}}" value="1" class="custom-switch-input tswitch"
                      [checked]="row.status == '1' ? true : false">
                    <span class="custom-switch-indicator"></span>
                  </label>
                }
              </td>

            </ng-container>


            <!-- Actions Column -->
            <ng-container matColumnDef="actions">
              <th scope="col" mat-header-cell *matHeaderCellDef> {{'Actions' | translate}} </th>
              <td mat-cell *matCellDef="let row; let i = index">
                <div>
                  @if (permission?.includes('FAQ Category Edit')) {
                    <button type="button" aria-label="Edit" (click)="editModelPopup(editFaqModel, row)" class="action-btns1">
                      <i class="feather feather-edit text-primary" [ngbTooltip]="'Edit' | translate"></i>
                    </button>
                  }
                  @if (permission?.includes('FAQ Category Delete')) {
                    <button type="button" aria-label="delete" [disabled]="sendingResponse['delFaq'+i]" (click)="deleteFaqCat(row, 'delFaq'+i)" class="action-btns1"
                      id="delete-testimonial">
                      <i class="feather feather-trash-2 text-danger" [ngbTooltip]="'Delete' | translate"></i>@if (sendingResponse['delFaq'+i]) {
                      <i
                      class="fa fa-spinner fa-spin mx-1"></i>
                    }
                  </button>
                }
              </div>
            </td>
          </ng-container>

          <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>

          <!-- Row shown when there is no matching data. -->
          <tr class="mat-row" *matNoDataRow>
            @if (!input.value.length) {
              <td class="mat-cell text-center" colspan="12">
                {{'No data Found'| translate}}
              </td>
            } @else {
              <td class="mat-cell text-center" colspan="12"> {{'No data matching the filter'| translate}} " {{input.value}} " </td>
            }
          </tr>
        </table>

        <mat-paginator #paginator showFirstLastButtons [pageSizeOptions]="[10, 25, 50, 100]" (page)="onPaginateTable()" aria-label="Select page of users" [length]="paginator?.length"
          [pageIndex]="paginator?.pageIndex" [pageSize]="paginator?.pageSize">
        </mat-paginator>
      </div>
    </div>
  </div>
</div>
</div>



<!-- // add Faq Category to agent modal start -->
<ng-template #addFaqsmodel let-modal>
  <div class="modal-header">
    <h5 class="modal-title">{{'Add Faq Category' | translate}}</h5>
    <button type="button" aria-label="close" class="btn-close" (click)="modal.dismiss('Cross click')">
    </button>
  </div>
  <div class="modal-body">
    <form #addFaqCategoryData="ngForm" (ngSubmit)="addFaqs(addFaqCategoryData, 'addFaq')">
      <input type="hidden" name="faqcat_id" id="faqcat_id" ngModel>
      <div class="modal-body">
        <div class="form-group">
          <label class="form-label">{{'Name' | translate}} <span class="text-red">*</span></label>
          <input required #name="ngModel" [class.is-invalid]="name.invalid && name.touched" type="text" class="form-control" [placeholder]="'FAQ Category' | translate" name="faqcategoryname"
            id="faqcatname" ngModel>
          @if ((name.invalid && name.touched) || name.dirty) {
            <div>
              @if (name.errors?.['required']) {
                <small class="text-danger">{{'Name is required' | translate}}</small>
              }
            </div>
          }
        </div>

        <div class="form-group">
          <div class="switch_section">
            <div class="switch-toggle d-flex mt-4">
              <label class="form-label pe-2">{{'Status' | translate}}</label>
              <span class="onoffswitch2">
                <input type="checkbox" name="status" id="status" ngModel class=" toggle-class onoffswitch2-checkbox" checked>
                <label for="status" class="toggle-class onoffswitch2-label"></label>
              </span>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-outline-danger" (click)="modal.dismiss('Cross click')">{{'Close' | translate}}</button>
        <button type="submit" [disabled]="addFaqCategoryData.invalid || sendingResponse['addFaq']" class="btn btn-secondary" id="btnsave">{{'Save' | translate}}@if (sendingResponse['addFaq']) {
          <i
          class="fa fa-spinner fa-spin mx-1"></i>
        }</button>
      </div>
    </form>
  </div>
</ng-template>
<!-- // add Category to agent modal end -->
<!-- // edit Category to agent modal start -->
<ng-template #editFaqModel let-modal>
  <div class="modal-header">
    <h5 class="modal-title">{{'Edit Faq Category' | translate}}</h5>
    <button type="button" aria-label="close" class="btn-close" (click)="modal.dismiss('Cross click')">
    </button>
  </div>
  <div class="modal-body">
    <form #editTestimonialData="ngForm" (ngSubmit)="editFaqs(editTestimonialData, 'editFaq')">
      <input type="hidden" name="faqcat_id" [ngModel]="pagesModel['id']">
      <div class="modal-body">
        <div class="form-group">
          <label class="form-label">{{'Name' | translate}} <span class="text-red">*</span></label>
          <input required #faqCategory="ngModel" [class.is-invalid]="faqCategory.invalid && faqCategory.touched" type="text" class="form-control" [placeholder]="'FAQ Category' | translate"
            name="faqcategoryname" [value]="pagesModel['faqcategoryname']" [ngModel]="pagesModel['faqcategoryname']">
          @if ((faqCategory.invalid && faqCategory.touched) || faqCategory.dirty) {
            <div>
              @if (faqCategory.errors?.['required']) {
                <small class="text-danger">{{'FAQ Category is required' | translate}}</small>
              }
            </div>
          }
        </div>

        <div class="form-group">
          <div class="switch_section">
            <div class="switch-toggle d-flex mt-4">
              <label class="form-label pe-2">{{'Status' | translate}}</label>
              <span class="onoffswitch2">
                <input type="checkbox" name="status" id="editstatus" class=" toggle-class onoffswitch2-checkbox" [value]="pagesModel['status']" [ngModel]="pagesModel['status']">
                <label for="editstatus" class="toggle-class onoffswitch2-label"></label>
              </span>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-outline-danger" (click)="modal.dismiss('Cross click')">{{'Close' |
        translate}}</button>
        <button type="submit" [disabled]="editTestimonialData.invalid || sendingResponse['editFaq']" class="btn btn-secondary">{{'Update' | translate}}@if (sendingResponse['editFaq']) {
          <i
          class="fa fa-spinner fa-spin mx-1"></i>
        }</button>
      </div>
    </form>
  </div>
</ng-template>
<!-- // edit Faq Category to agent modal end -->