<div class="pagemain">
    <div class="main-pagemain">
        <div class="pagetitle">
            <h3>Questions</h3>
        </div>
        <div class="search-wrap">
            <div class="search-icon">
                <input placeholder="Search by Certification, Topic, Material Name..." [(ngModel)]="Search"
                    autocomplete="off" (keyup)="filter()" name="search" />
                <span class="material-icons">search</span>
            </div>
            <button (click)="addNewPracticeQua()">Add Question</button>
            <button (click)="openBulkUploadModal()">Bulk Upload</button>
        </div>
    </div>

    <div class="pagesection">
        <div class="mat-elevation-z8">
            <table mat-table [dataSource]="dataSource" matSort style="border-spacing: 0 10px">
                <ng-container matColumnDef="srno">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>#</th>
                    <td mat-cell *matCellDef="let row">
                        <span>{{ row.srno }}</span>
                    </td>
                </ng-container>
                <ng-container matColumnDef="certificate_name">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>
                        Certification
                    </th>
                    <td mat-cell *matCellDef="let row"><span title="{{ row.certificate_name }}">{{ row.certificate_name
                            }}</span></td>
                </ng-container>

                <ng-container matColumnDef="domin_name">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Material</th>
                    <td mat-cell *matCellDef="let row">
                        <span title="{{ row.domin_name }}">{{ row.domin_name }}</span>
                    </td>
                </ng-container>
                <ng-container matColumnDef="subdomain_name">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>
                        Sub-Material
                    </th>
                    <td mat-cell *matCellDef="let row">
                        <span title="{{ row.subdomain_name }}">{{ row.subdomain_name }}</span>
                    </td>
                </ng-container>
                <ng-container matColumnDef="topic_name">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Topic</th>
                    <td mat-cell *matCellDef="let row">
                        <span title="{{ row.topic_name }}">{{ row.topic_name }}</span>
                    </td>
                </ng-container>

                <ng-container matColumnDef="practice_name">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Exam</th>
                    <td mat-cell *matCellDef="let row">
                        <span title="{{ row.practice_name }}">{{ row.practice_name }}</span>
                    </td>
                </ng-container>

                <ng-container matColumnDef="title">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Question</th>
                    <td mat-cell *matCellDef="let row">
                        <span title="{{ row.title }}">{{ row.title }}</span>
                    </td>
                </ng-container>


                <ng-container matColumnDef="actions">
                    <th mat-header-cell *matHeaderCellDef>Actions</th>
                    <td mat-cell *matCellDef="let row">
                        <img src="../../../assets/images/edit-1.png" (click)="edit(row)" alt="Edit" class="action-icon">
                        <img src="../../../assets/images/remove.png" (click)="delete(row)" alt="Delete"
                            class="action-icon">
                    </td>
                </ng-container>
                <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
                <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
            </table>
        </div>
    </div>
    <div class="page-footer">
        <!-- *ngIf="pagination" -->
        <mat-paginator style-paginator showFirstLastButtons [showTotalPages]="3" 
            [length]="dataSource.data ? dataSource.data.length : 0" [pageSize]="10"
            [pageSizeOptions]="[10, 20, 50, 100, 500]">
        </mat-paginator>
    </div>
</div>
<ngx-spinner bdColor="#00041aa6" size="default" color="##d7779b"
    template="<img src='../../../assets/images/loading.gif' class='loading-indicator'/>" [fullScreen]="true">
</ngx-spinner>

<div class="cutome-modal" *ngIf="addPracticeQua">
    <div class="cutome-modal-content">
        <div class="modal-header">
            <p *ngIf="!IsUpdate">Add Question</p>
            <p *ngIf="IsUpdate">Edit Question</p>
            <span (click)="closeModal()" class="material-icons">close</span>
        </div>
        <div class="modal-body">
            <div>
                <form class="example-form" novalidate [formGroup]="PraacticeQueForm">
                    <div class="formwrapper">
                        <div>
                            <!-- <label>Certification</label> -->
                            <div class="select-box">

                                <select [(ngModel)]="CertificateName" (change)="certificatechange($event)"
                                    formControlName="CertificateName" required [ngClass]="{
                                    err:
                                    PraacticeQueForm.controls['CertificateName'].hasError(
                                    'required'
                                    ) &&
                                    (PraacticeQueForm.controls['CertificateName'].dirty ||
                                    PraacticeQueForm.controls['CertificateName'].touched)
                                    }">
                                    <option value="">Select Certification</option>
                                    <option *ngFor="let items of Certificates" value="{{ items.id }}">
                                        {{ items.certificate_name }}
                                    </option>
                                </select>
                                <span></span>
                            </div>
                        </div>
                        <div>
                            <!-- <label>Domain Name</label> -->
                            <div class="select-box">
                                <select [(ngModel)]="Domainname" (change)="domainchange($event)"
                                    formControlName="Domainname" required [ngClass]="{
                                    err:
                                    PraacticeQueForm.controls['Domainname'].hasError(
                                        'required'
                                    ) &&
                                    (PraacticeQueForm.controls['Domainname'].dirty ||
                                        PraacticeQueForm.controls['Domainname'].touched)
                                }">
                                    <option selected="true" value="">Select Material</option>
                                    <option *ngFor="let item of Domain" value="{{ item.id }}">
                                        {{ item.domin_name }}
                                    </option>
                                </select>
                                <span></span>
                            </div>
                        </div>
                        <div>
                            <!-- <label>Sub Domain Name</label> -->
                            <div class="select-box">
                                <select [(ngModel)]="subdomainname" (change)="SubDomainchange($event)"
                                    formControlName="subdomainname" required [ngClass]="{
                                    err:
                                    PraacticeQueForm.controls['subdomainname'].hasError(
                                        'required'
                                    ) &&
                                    (PraacticeQueForm.controls['subdomainname'].dirty ||
                                        PraacticeQueForm.controls['subdomainname'].touched)
                                }">
                                    <option selected="true" value="">Select Sub Material</option>
                                    <option *ngFor="let item of SubDomain" value="{{ item.id }}">
                                        {{ item.subdomain_name }}
                                    </option>
                                </select>
                                <span></span>
                            </div>
                        </div>

                        <div>
                            <!-- <label>Topic Name</label> -->
                            <div class="select-box">
                                <select [(ngModel)]="Topicname" formControlName="Topicname" required [ngClass]="{
                                    err:
                                    PraacticeQueForm.controls['Topicname'].hasError(
                                        'required'
                                    ) &&
                                    (PraacticeQueForm.controls['Topicname'].dirty ||
                                        PraacticeQueForm.controls['Topicname'].touched)
                                }">
                                    <option selected="true" value="">Select Topic</option>
                                    <option *ngFor="let item of Topic" value="{{ item.id }}">
                                        {{ item.topic_name }}
                                    </option>
                                </select>
                                <span></span>
                            </div>
                        </div>
                        <div class="w-50">
                            <!-- <label>Select Exam</label> -->
                            <div class="select-box">
                                <select [(ngModel)]="test_id" formControlName="test_id" required [ngClass]="{
                                    err:
                                    PraacticeQueForm.controls['test_id'].hasError(
                                        'required'
                                    ) &&
                                    (PraacticeQueForm.controls['test_id'].dirty ||
                                        PraacticeQueForm.controls['test_id'].touched)
                                }">
                                    <option selected="true" value="">Select Exam</option>
                                    <option *ngFor="let item of testdata" value="{{ item.id }}">
                                        {{ item.practice_name }}
                                    </option>
                                </select>
                                <span></span>
                            </div>
                        </div>
                        <div class="answers">
                            <label>Question</label>
                            <textarea placeholder="Type here..." [(ngModel)]="title" formControlName="title" type="text"
                                name="title" required [ngClass]="{
                                err:
                                PraacticeQueForm.controls['title'].hasError(
                                    'required'
                                ) &&
                                (PraacticeQueForm.controls['title'].dirty ||
                                    PraacticeQueForm.controls['title'].touched)
                            }">
                            </textarea>
                        </div>
                        <div class="answers">
                            <label>Answer A</label>
                            <textarea placeholder="Type here..." [(ngModel)]="option1" formControlName="option1"
                                type="name" name="title" required [ngClass]="{
                                err:
                                PraacticeQueForm.controls['option1'].hasError(
                                    'required'
                                ) &&
                                (PraacticeQueForm.controls['option1'].dirty ||
                                    PraacticeQueForm.controls['option1'].touched)
                            }">

                            </textarea>
                        </div>

                        <div class="answers">
                            <label>Answer B</label>

                            <textarea placeholder="Type here..." [(ngModel)]="option2" formControlName="option2"
                                type="name" name="title" required [ngClass]="{
                                err:
                                PraacticeQueForm.controls['option2'].hasError(
                                    'required'
                                ) &&
                                (PraacticeQueForm.controls['option2'].dirty ||
                                    PraacticeQueForm.controls['option2'].touched)
                            }">

                            </textarea>
                        </div>

                        <div class="answers">
                            <label>Answer C</label>
                            <textarea placeholder="Type here..." [(ngModel)]="option3" formControlName="option3"
                                type="name" name="title" required [ngClass]="{
                                err:
                                PraacticeQueForm.controls['option3'].hasError(
                                    'required'
                                ) &&
                                (PraacticeQueForm.controls['option3'].dirty ||
                                    PraacticeQueForm.controls['option3'].touched)
                            }">

                            </textarea>
                        </div>

                        <div class="answers">
                            <label>Answer D</label>
                            <textarea placeholder="Type here..." [(ngModel)]="option4" formControlName="option4"
                                type="name" name="title" required [ngClass]="{
                                err:
                                PraacticeQueForm.controls['option4'].hasError(
                                    'required'
                                ) &&
                                (PraacticeQueForm.controls['option4'].dirty ||
                                    PraacticeQueForm.controls['option4'].touched)
                            }">

                            </textarea>
                        </div>

                        <div class="w-50">
                            <div class="select-box">
                                <select [(ngModel)]="CorrectAnswer" formControlName="CorrectAnswer" required
                                    [ngClass]="{ err: PraacticeQueForm.controls['CorrectAnswer'].hasError( 'required' ) && (PraacticeQueForm.controls['CorrectAnswer'].dirty || PraacticeQueForm.controls['CorrectAnswer'].touched) }">
                                    <option selected="true" value="">Select Correct Answer</option>
                                    <option value="1">Option1</option>
                                    <option value="2">Option2</option>
                                    <option value="3">Option3</option>
                                    <option value="4">Option4</option>
                                </select>
                                <span></span>
                            </div>
                        </div>

                        <div class="w-50">
                            <div class="select-box">
                                <select [(ngModel)]="Type" formControlName="Type" required
                                    [ngClass]="{ err: PraacticeQueForm.controls['Type'].hasError( 'required' ) && (PraacticeQueForm.controls['Type'].dirty || PraacticeQueForm.controls['Type'].touched) }">
                                    <option selected="true" value="">Select Difficulty</option>
                                    <option value="VERY SIMPLE">VERY SIMPLE</option>
                                    <option value="SIMPLE">SIMPLE</option>
                                    <option value="AVERAGE">AVERAGE</option>
                                    <option value="ABOVE AVERAGE">ABOVE AVERAGE</option>
                                    <option value="HARD">HARD</option>
                                    <option value="DIFFICULT">DIFFICULT</option>
                                    <option value="TRICKY">TRICKY</option>
                                </select>
                                <span></span>
                            </div>
                        </div>
                        <div class="answers">
                            <label>Explanation</label>
                            <textarea placeholder="Type here..." formControlName="Explanation" [(ngModel)]="Explanation"
                                id="Explanation" name="Explanation"></textarea>
                        </div>
                    </div>
                </form>
                <div class="history-div" *ngIf="IsUpdate">
                    <h3><span class="material-icons"> history </span>Audit history</h3>
                    <div class="audit-table">
                        <div class="table-header">
                            <div class="date-title"><span>Date & Time</span></div>
                            <div class="action-title"><span>Action</span></div>
                        </div>
                        <div class="main-body-audit">
                            <div class="table-body" *ngFor="let log of loglist">
                                <div class="date-title"><span>{{log.createdAt | date:'medium'}}</span></div>
                                <div class="action-title">
                                    <span [innerHTML]="log.description"></span>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button class="cancel-btn" (click)="closeModal()">Cancel</button>
            <div *ngIf="!IsUpdate">
                <button class="submit-btn" (click)="onSubmit()">Save</button>
            </div>
            <div *ngIf="IsUpdate">
                <button class="submit-btn" (click)="UpdatePracticeQue()">Save</button>
            </div>
        </div>
    </div>
</div>
<div class="cutome-modal" *ngIf="isBulkUpload">
    <div class="cutome-modal-content" style="width: 50%;">
        <div class="modal-header">
            <p>Bulk Upload</p>
            <span (click)="closeBulkUploadModal()" class="material-icons">close</span>
        </div>

        <div class="modal-body" style="min-height: 110px;">
            <div>
                <ngx-dropzone maxFileSize="100MB" accept=".csv,.xlsx" (change)="onSelect($event)">
                    <ngx-dropzone-label>Drag & drop here (or) <span class="browse">Browse</span></ngx-dropzone-label>
                    <div *ngFor="let f of files">
                        <ngx-dropzone-label>{{ f.name }} </ngx-dropzone-label>
                    </div>
                </ngx-dropzone>
                <div class="format" *ngIf="files.length<=0">
                    <span>Allowed Format: xlsx</span>
                </div>
                <div class="format" *ngFor="let f of files">
                    <div class="bbulkupload">
                        <span *ngFor="let t of f">{{ t.name }} </span>

                        <mat-icon (click)="onRemove(f)">close</mat-icon>
                    </div>
                </div>
                <div class="format">
                    <progress value={{progress}} max="10" id="progressBar" *ngIf="selectprogress"></progress>
                </div>
                <div class="format">
                    <a (click)="ExportExcel()">
                        <mat-icon>arrow_downward</mat-icon>
                        PracticeQuestion_sample.xlsx
                    </a>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button class="cancel-btn" (click)="closeBulkUploadModal()">Cancel</button>
            <button class="submit-btn" (click)="bulkUpload()" [disabled]="selectBulkupload">Upload</button>
        </div>
    </div>
</div>