<div class="pagemain">
    <div class="main-pagemain">
        <div class="pagetitle">
            <h3>Materials</h3>
        </div>
        <div class="search-wrap">
            <div class="search-icon">
                <input placeholder="Search by Material Name, Number, Certificate..." [(ngModel)]="Search"
                    autocomplete="off" (keyup)="filter()" name="search" />
                <span class="material-icons">search</span>
            </div>
            <button (click)="addNewDomain()">Add Material</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 element"><span title="{{ element.srno }}">{{ element.srno }}</span>
                    </td>
                </ng-container>
                <ng-container matColumnDef="domain_number">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Material #</th>
                    <td mat-cell *matCellDef="let element"><span title="{{ element.domain_number }}">{{
                            element.domain_number }}</span></td>
                </ng-container>
                <ng-container matColumnDef="domin_name">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>Material Name</th>
                    <td mat-cell *matCellDef="let element"><span title="{{ element.domin_name }}">{{ element.domin_name
                            }}</span></td>
                </ng-container>
                <ng-container matColumnDef="certificate_name">
                    <th mat-header-cell *matHeaderCellDef mat-sort-header>
                        Certification
                    </th>
                    <td mat-cell *matCellDef="let element">
                        <span title="{{ element.certificate_name }}">{{ element.certificate_name }}</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="addDomain">
    <div class="cutome-modal-content">
        <div class="modal-header">
            <p *ngIf="!IsUpdate">Add Material</p>
            <p *ngIf="IsUpdate">Edit Material</p>
            <span (click)="closeModal()" class="material-icons">close</span>
        </div>
        <div class="modal-body">
            <div>
                <form class="example-form" [formGroup]="DomainForm">
                    <div class="formwrapper">
                        <div>
                            <div class="select-box">
                                <select [(ngModel)]="CertificateName" formControlName="CertificateName" required
                                    [ngClass]="{ err: DomainForm.controls['CertificateName'].hasError( 'required' ) && (DomainForm.controls['CertificateName'].dirty || DomainForm.controls['CertificateName'].touched) }">
                                    <option value="">Select Certification</option>
                                    <option *ngFor="let items of ListCerficateData" value="{{ items.id }}">
                                        {{ items.certificate_name }}
                                    </option>
                                </select>
                                <span></span>
                            </div>
                        </div>
                        <div class="d-flex">
                            <div class="w-20">
                                <input formControlName="DomainNumber" [(ngModel)]="DomainNumber" placeholder="Material #"
                                    required
                                    [ngClass]="{ err: DomainForm.controls['DomainNumber'].hasError('required') && (DomainForm.controls['DomainNumber'].dirty || DomainForm.controls['DomainNumber'].touched) }" />
                            </div>
                            <div class="w-78">
                                <input formControlName="DomainName" [(ngModel)]="DomainName" placeholder="Material Name"
                                    required
                                    [ngClass]="{ err: DomainForm.controls['DomainName'].hasError('required') && (DomainForm.controls['DomainName'].dirty || DomainForm.controls['DomainName'].touched) }" />
                            </div>
                        </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)="SaveCohort()">Save</button>
            </div>
            <div *ngIf="IsUpdate">
                <button class="submit-btn" (click)="UpdateCohort()">Save</button>
            </div>
        </div>
    </div>
</div>