<title>Contact Request</title>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-6">
            <app-breadcrumb [title]="'Contact Requests'" [active_item]="'Contact Requests'"></app-breadcrumb>
        </div>
        <div class="col-sm-6 text-right">
            <div ngbDropdown class="btn-group">
                <div class="ml-2">
                    <button type="button" class="btn btn-info filterbtn" title="{{ 'tooltip_filter_order'|translate }}"
                        (click)="drawer.toggle();">
                        <i class="icon-filter pr-1"></i>
                        <span>{{'button_lbl_filter'| translate}}</span>
                    </button>
                </div>
            </div>
        </div>
        <div class="col-sm-12">
            <mat-drawer-container class="example-container" autosize>
                <div class="card">
                    <ng-container *ngIf="contactRequests && contactRequests.length > 0 else NoOrders">
                        <div class="contentcard table-responsive userlist-table lastcolumntable">
                            <table mat-table [dataSource]="contactRequests"
                                class="mat-elevation-z8 table-striped table-vcenter"
                                style="min-width: 1350px; box-shadow: none;" aria-label="contact">
                                <ng-container matColumnDef="id">
                                    <th mat-header-cell *matHeaderCellDef style="width:5%">#</th>
                                    <td mat-cell *matCellDef="let element; let i = index;" style="width:5%">
                                        {{(paginate.currentPage - 1) * paginate.pageSize + i + 1}}
                                    </td>
                                </ng-container>

                                <ng-container matColumnDef="name">
                                    <th mat-header-cell *matHeaderCellDef style="width: 15%;">{{'lbl_name'| translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let element" style="width: 15%;">
                                        <div *ngIf="element.name else NoValue">
                                            {{element.name}}
                                        </div>
                                        <ng-template #NoValue>
                                            --
                                        </ng-template>
                                    </td>
                                </ng-container>
                                <ng-container matColumnDef="contactNo">
                                    <th mat-header-cell *matHeaderCellDef>{{'lbl_contact_no'| translate}}</th>
                                    <td mat-cell *matCellDef="let element">
                                        <div *ngIf="element.contactNo else NoValue">
                                            {{element.contactNo}}
                                        </div>
                                        <ng-template #NoValue>
                                            --
                                        </ng-template>
                                    </td>
                                </ng-container>
                                <ng-container matColumnDef="email">
                                    <th mat-header-cell *matHeaderCellDef>{{'lbl_email'| translate}}</th>
                                    <td mat-cell *matCellDef="let element">
                                        <div *ngIf="element.email  else NoValue">
                                            {{element.email}}
                                        </div>
                                        <ng-template #NoValue>
                                            --
                                        </ng-template>
                                    </td>
                                </ng-container>
                                <ng-container matColumnDef="subject">
                                    <th mat-header-cell *matHeaderCellDef style="width: 14%;">
                                        {{'contact_request_lbl_subject'| translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let element" style="width: 14%;">
                                        <div *ngIf="element.subject else NoValue">
                                            {{element.subject}}
                                        </div>
                                        <ng-template #NoValue>
                                            --
                                        </ng-template>
                                    </td>
                                </ng-container>
                                <ng-container matColumnDef="message">
                                    <th mat-header-cell *matHeaderCellDef>{{'contact_request_lbl_message'| translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let element">
                                        <div *ngIf="element.message else NoValue">
                                            {{element.message}}
                                        </div>
                                        <ng-template #NoValue>
                                            --
                                        </ng-template>
                                    </td>
                                </ng-container>
                                <ng-container matColumnDef="contactDate">
                                    <th mat-header-cell *matHeaderCellDef>{{'contact_request_lbl_contact_date'|
                                        translate}}</th>
                                    <td mat-cell *matCellDef="let element">
                                        <div *ngIf="element.contactDate else NoValue">
                                            {{element.contactDate | date:'medium'}}
                                        </div>
                                        <ng-template #NoValue>
                                            --
                                        </ng-template>
                                    </td>
                                </ng-container>
                                <ng-container matColumnDef="status">
                                    <th mat-header-cell *matHeaderCellDef>{{'lbl_status'| translate}}</th>
                                    <td mat-cell *matCellDef="let element">
                                        {{element.status}}
                                    </td>
                                </ng-container>
                                <ng-container matColumnDef="action" stickyEnd>
                                    <th mat-header-cell *matHeaderCellDef translate class="text-right">{{'lbl_action'|
                                        translate}}</th>
                                    <td mat-cell *matCellDef="let element" class="text-right">
                                        <a title="{{ 'tooltip_lbl_change_status' |translate}}" href="javascript:;"
                                            class="btn btn-sm btn-info filterbtn"
                                            (click)="modalOpen(basicmodal,element)">
                                            <i class="icon-control-forward"></i>
                                        </a>
                                    </td>
                                </ng-container>

                                <tr mat-header-row *matHeaderRowDef="displayColumns; sticky: true"></tr>
                                <tr mat-row *matRowDef="let row; columns: displayColumns;" class="student-element-row"
                                    style="cursor: pointer;" [ngStyle]="{'background-color': row.color}"></tr>
                            </table>
                        </div>
                    </ng-container>

                    <ng-template #NoOrders>
                        <div class="d-flex vertical-center nodata">
                        </div>
                    </ng-template>

                    <div class="card-footer" *ngIf="contactRequests && contactRequests.length > 0">
                        <ul class="pagination mb-0 float-right">
                            <li [ngClass]="{ disabled: paginate.currentPage == 1 }" class="page-item page-prev">
                                <a class="page-link" href="javascript:;" tabindex="-1"
                                    (click)="setPage(paginate.currentPage - 1)">
                                    <span>{{'button_lbl_prev'| translate}}</span>
                                </a>
                            </li>
                            <li *ngFor="let page of paginate.pages" class="page-item active"
                                [ngClass]="{ active: paginate.currentPage == page }"><a
                                    [ngClass]="{current:paginate.currentPage == page}" class="page-link"
                                    href="javascript:;" (click)="setPage(page)">{{page}}</a></li>
                            <li [ngClass]="{ disabled: paginate.currentPage === paginate.totalPages}"
                                (click)="setPage(paginate.currentPage + 1)" class="page-item page-next">
                                <a class="page-link" href="javascript:;"><span>{{'button_lbl_next'|
                                        translate}}</span></a>
                            </li>
                        </ul>
                    </div>

                </div>

                <mat-drawer #drawer class="example-sidenav" mode="over" position="end">
                    <div class="col-lg-12 px-3 pt-3">
                        <div class="d-inline" style="width: 100%;"><i class="fa fa-filter"><span>{{'button_lbl_filter'|
                                    translate}}</span></i>
                            <button v class="close" aria-label="Close" (click)="drawer.toggle();">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                    </div>
                    <hr>
                    <div class="position px-3">
                        <div class="form-group">
                            <label>{{'lbl_select_status'| translate}}</label>
                            <ng-select [items]="statuses" class="js-example-basic-single p-0"
                                placeholder="Search by  Status" bindLabel="status" bindValue="status"
                                name="selectedStatus" [(ngModel)]="selectedStatus">
                            </ng-select>
                        </div>
                        <div class="mt-3" style="padding-bottom: 15px;">
                            <div class="col-form-label">{{'lbl_from_date'| translate}}</div>
                            <mat-form-field appearance="outline" class="d-block w-100"
                                (click)="toggleMenuService.togglePickerStyles()">

                                <input matInput [matDatepicker]="pickerFrom" [max]="toDate"
                                    placeholder="{{ 'lbl_from_date' |translate}}" [(ngModel)]="fromDate" name="fromDate"
                                    [readonly]="true" (focus)="pickerFrom.open()"
                                    (click)="toggleMenuService.togglePickerStyles()">
                                <mat-datepicker-toggle matSuffix [for]="pickerFrom"
                                    (click)="toggleMenuService.togglePickerStyles()"></mat-datepicker-toggle>
                                <mat-datepicker #pickerFrom></mat-datepicker>
                            </mat-form-field>
                        </div>
                        <div class="col-form-label">{{'lbl_to_date'| translate}}</div>
                        <mat-form-field appearance="outline" class="d-block w-100"
                            (click)="toggleMenuService.togglePickerStyles()">
                            <input matInput [matDatepicker]="pickerTo" [min]="fromDate"
                                placeholder="{{ 'lbl_to_date' |translate}}" [(ngModel)]="toDate" name="toDate"
                                [readonly]="true" (focus)="pickerTo.open()"
                                (click)="toggleMenuService.togglePickerStyles()">
                            <mat-datepicker-toggle matSuffix [for]="pickerTo"
                                (click)="toggleMenuService.togglePickerStyles()"></mat-datepicker-toggle>
                            <mat-datepicker #pickerTo></mat-datepicker>
                        </mat-form-field>
                    </div>
                    <div class="modal-footer px-3" style="padding-bottom: 35px;justify-content: center;">
                        <div class="float-right d-inline">
                            <button type="button" class="btn btn-secondary filterbtn"
                                title="{{ 'tooltip_lbl_clear_filter' |translate}}"
                                (click)="drawer.toggle();clearSearch();">
                                <span>{{'button_lbl_clear'| translate}}</span>
                            </button>
                            <button type="button" class="btn btn-info filterbtn"
                                title="{{ 'tooltip_lbl_filter_dsa' |translate}}" (click)="drawer.toggle();setPage(1);">
                                <span>{{'lbl_search'| translate}}</span>
                            </button>
                        </div>
                    </div>

                    <div class="px-3">
                    </div>
                </mat-drawer>

            </mat-drawer-container>
        </div>
    </div>
</div>

<ng-template #basicmodal let-modal>
    <div>
        <form #StatusForm="ngForm">
            <div class="modal-header">
                <h4 class="modal-title" id="modal-basic-title">{{'lbl_change_status'| translate}}</h4>
                <button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body pd-20">
                <div class="form-group">
                    <label for="orderStatusId">{{'lbl_change_status'| translate}} <span
                            style="color: red;">*</span></label>
                    <ng-select [items]="statuses" class="js-example-basic-single p-0"
                        [(ngModel)]="selectedRequestStatus" placeholder="{{ 'lbl_select_status' |translate}}"
                        bindLabel="status" bindValue="status" name="Status" required #orderStatusId="ngModel"
                        name="orderStatusId">
                    </ng-select>
                    <mat-error *ngIf="(orderStatusId!.touched) && (orderStatusId.errors?.['required'])">
                        {{'message_lbl_status_is_required'| translate}}
                    </mat-error>
                </div>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-sm btn-info filterbtn" (click)="changeStatus(StatusForm)">
                    {{'button_lbl_change'| translate}}
                </button>
                <button type="reset" class="btn btn-sm btn-secondary filterbtn" (click)="closeDialog()">
                    {{'button_lbl_cancel'| translate}}
                </button>
            </div>
        </form>
    </div>
</ng-template>