<div [@routerTransition]>
 
    <div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor">
        <div class="kt-subheader kt-grid__item">
            <div [class]="containerClass">
                <div class="kt-subheader__main">
                    <h3 class="kt-subheader__title">
                        <span>{{"Vehicle" | localize}}</span>
                    </h3>
                    <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                    <span class="kt-subheader__desc">
                        {{"VehicleManagement" | localize}}
                    </span>
                </div>
                <div class="kt-subheader__toolbar">
                    <div class="kt-subheader__wrapper">
                        <button (click)="exportToExcel()" class="btn btn-outline-success btn-pill"><i class="fa fa-file-excel"></i> {{l("ExportToExcel")}}</button>
                        <button class="btn btn-primary btn-pill" (click)="createVehicleModal.show()"><i class="fa fa-plus"></i>{{"CreatingNewVehicle" | localize}}</button>
                    </div>
                </div>
            </div>
        </div>
        <div [class]="containerClass + ' kt-grid__item kt-grid__item--fluid'">
            <div class="kt-portlet kt-portlet--mobile">
                <div class="kt-portlet__body">
                    <div class="row align-items-center">
                        <div class="col-md-12">
                            <form class="kt-form" autocomplete="off" (ngSubmit) = "getVehicle()">
                                <div class="row align-items-center mb-4">
                                    <div class="col-md-12">                                         
                                        <div class="kt-searchbar">
                                            <div class="kt-input-icon kt-input-icon--right">                                                   
                                                <input type="text" class="form-control" placeholder="Search" id="generalSearch" name="name" [(ngModel)]="filters.vehicleName" name="name" autoFocus>                                                   
                                                <span class="kt-input-icon__icon kt-input-icon__icon--right">
                                                    <button (click)="getVehicle()" class="btn btn-primary" type="submit"><i class="flaticon-search-1"></i></button> 
                                                </span>
                                            </div>  
                                        </div>
                                    </div>
                                </div>
                                <div class="row" [hidden]="!advancedFiltersAreShown">
                                        <div class="col-md-12">
                                            <div class="kt-separator kt-separator--border-dashed"></div>
                                        </div>
           
                                       <div class="col-md-3">
                                           <div class="form-group">
                                               <label for="VehicleFilter">{{l("VehicleName")}}</label>
                                               <input type="text" class="form-control" id="VehicleFilter" name="vehicleFilter" [(ngModel)]="vehicleFilter">
                                           </div>
                                       </div>
                                       <div class="col-md-3">
                                            <div class="form-group">
                                                <label for="LicenseFilter">{{l("LicenseNumber")}}</label>
                                                <input type="text" class="form-control" id="LicenseFilter" name="licenseFilter" [(ngModel)]="licenseFilter">
                                            </div>
                                        </div>
                                        <div class="col-md-3">
                                                <div class="form-group">
                                                    <label for="DriverFilter">{{l("DriverName")}}</label>
                                                    <input type="text" class="form-control" id="DriverFilter" name="driverFilter" [(ngModel)]="driverFilter">
                                                </div>
                                            </div>
           
                                   </div>
                                   <div class="row mb-2">
                                        <div class="col-sm-12">
                                            <span class="clickable-item text-muted" *ngIf="!advancedFiltersAreShown" (click)="advancedFiltersAreShown=!advancedFiltersAreShown"><i class="fa fa-angle-down"></i> {{l("ShowAdvancedFilters")}}</span>
                                            <span class="clickable-item text-muted" *ngIf="advancedFiltersAreShown" (click)="advancedFiltersAreShown=!advancedFiltersAreShown"><i class="fa fa-angle-up"></i> {{l("HideAdvancedFilters")}}</span>
                                        </div>
                                    </div>           
                            </form>
                        </div>
                        <div class="col-md-12">
                            <div class="primeng-datatable-container">
                            <p-table #dataTable
                                    (onLazyLoad)="getVehicle($event)"
                                    [value]="primengTableHelper.records"
                                    rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                                    [paginator]="false"
                                    [lazy]="true"
                                    [scrollable]="true"
                                    ScrollWidth="100%"
                                    [responsive]="primengTableHelper.isResponsive"
                                    [resizableColumns]="primengTableHelper.resizableColumns">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th style="width: 130px" [hidden]="!isGrantedAny('Pages.Shipping.Vehicles.Edit', 'Pages.Shipping.Vehicles.Delete')">
                                            {{'Actions' | localize}}
                                        </th>
                                        <th style="width: 150px" pSortableColumn="name">
                                            {{'VehicleName' | localize}}
                                            <p-sortIcon field="name"></p-sortIcon>
                                        </th>
                                        <th style="width: 150px" pSortableColumn="licenseNumber">
                                            {{'LicenseNumber' | localize}}
                                            <p-sortIcon field="licenseNumber"></p-sortIcon>
                                        </th>
                                        <th style="width: 150px" pSortableColumn="user.name">
                                            {{'DriverName' | localize}}
                                            <p-sortIcon field="user.name"></p-sortIcon>
                                        </th>
                                        <th style="width: 150px" pSortableColumn="color">
                                            {{'Marker' | localize}}
                                            <p-sortIcon field="color"></p-sortIcon>
                                        </th>
                                        
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record="$implicit">
                                    <tr>
                                        <td style="width: 130px"
                                        [hidden]="!isGrantedAny('Pages.Shipping.Vehicles.Edit','Pages.Shipping.Vehicles.Delete')">
                                            <div class="btn-group dropdown" dropdown container="body">
                                                <button dropdownToggle class="dropdown-toggle btn btn-sm btn-primary btn-pill">
                                                    <i class="fa fa-cog"></i><span class="caret"></span> {{"Actions" | localize}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li>
                                                        <a href="javascript:;" *ngIf="'Pages.Shipping.Vehicles.Edit' | permission"
                                                            (click)="editVehicleModal.show(record.id)">{{'Edit' | localize}}</a>
                                                    </li>                                              
                                                    <li>
                                                        <a href="javascript:;" *ngIf="'Pages.Shipping.Vehicles.Delete' | permission"
                                                            (click)="deleteVehicle(record)">{{'Delete' | localize}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>                                   
                                        <td style="width: 150px">
                                            <span class="ui-column-title"> {{'VehicleName' | localize}}</span>
                                            {{record.name}}
                                        </td>
                                        <td style="width: 150px">
                                            <span class="ui-column-title"> {{'LicenseNumber' | localize}}</span>
                                            {{record.licenseNumber}}
                                        </td>
                                        <td style="width: 150px">
                                            <span class="ui-column-title"> {{'DriverName' | localize}}</span>
                                            
                                            {{record.user === undefined ? 'n/a' : record.user.name +" "+ record.user.surname}}
                                        </td>
                                        <td style="width: 150px">
                                            <span class="ui-column-title"> {{'Marker' | localize}}</span>
                                                <i class="flaticon-truck" style="font-size: 30px !important;" [style.color]="record.color"></i>
                                        </td>
                                        
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                                {{'NoData' | localize}}
                            </div>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage"
                                            #paginator
                                            (onPageChange)="getVehicle($event)"
                                            [totalRecords]="primengTableHelper.totalRecordsCount"
                                            [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">

                                </p-paginator>
                                <span class="total-records-count">
                                    {{'TotalRecordsCount' | localize:primengTableHelper.totalRecordsCount}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-TurboTable-End>-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <createVehicleModal #createVehicleModal (modalSave)="getVehicle()"></createVehicleModal>
    <editVehicleModal #editVehicleModal (modalSave)="getVehicle()"></editVehicleModal>
</div>

