<kt-portlet>
	<kt-portlet-header [title]="titulo" [class]="'kt-portlet__head--lg'">
		<div ktPortletTools>
			<div class="div-group-show-hide-list">
				<div class="div-show-hide-list mr-1">
					<mat-spinner [diameter]="25" *ngIf="isLoading" class="mr-3"></mat-spinner>
					<mat-checkbox (change)="toggle($event)" style="margin-right: 20px">
						{{(deleted_at == '0') ? 'Mostrar eliminados' : 'Ocultar eliminados'}}
					</mat-checkbox>
				</div>
				<button [routerLink]="['../vehiculos/add']"  mat-raised-button class="btn btn-primary" matTooltip="Crear nuevo vehículo" *ngxPermissionsOnly="'administrador.vehiculos.store'">
					<i class="la la-plus"></i>
					<span class="kt-hidden-mobile ml-2">Nuevo vehículo</span>
				</button>
			</div>
		</div>
	</kt-portlet-header>

	<kt-portlet-body>

		<div class="kt-form kt-margin-b-30">
			<div class="kt-form__filtration">
				<div class="row align-items-center">
					<div class="col-md-1 kt-margin-bottom-10-mobile">
						<mat-form-field>
							<input matInput (keyup)="onKeyUp($event)" (keydown)="onKeyDown()" placeholder="Buscar..." class="mat-form-field mat-form-field-fluid">
							<mat-hint align="start">
								<strong>Buscar en todos los campos</strong>
							</mat-hint>
						</mat-form-field>
					</div>
				</div>
			</div>
		</div>

		<div class="mat-table__wrapper">
			<mat-table class="lmat-elevation-z8" [dataSource]="dataSourceVehiculos" (matSortChange)="sort($event)" matSort matSortActive="id" matSortDirection="asc" matSortDisableClear>

				<ng-container matColumnDef="num_economico">
					<mat-header-cell *matHeaderCellDef mat-sort-header>Número económico</mat-header-cell>
					<mat-cell *matCellDef="let vehiculo">{{vehiculo.num_economico}}</mat-cell>
				</ng-container>

				<ng-container matColumnDef="descripcion">
					<mat-header-cell *matHeaderCellDef mat-sort-header>Descripción</mat-header-cell>
					<mat-cell *matCellDef="let vehiculo">{{(vehiculo.descripcion) ? vehiculo.descripcion : 'SIN DESCRIPCIÓN'}}</mat-cell>
				</ng-container>

                <ng-container matColumnDef="tipo_vehiculo">
					<mat-header-cell *matHeaderCellDef mat-sort-header>Tipo de vehículo</mat-header-cell>
					<mat-cell *matCellDef="let vehiculo">{{vehiculo.tipo_vehiculo}}</mat-cell>
				</ng-container>

                <ng-container matColumnDef="sucursal">
					<mat-header-cell *matHeaderCellDef mat-sort-header>Sucursal</mat-header-cell>
					<mat-cell *matCellDef="let vehiculo">
                        <ng-container *ngFor="let veh of vehiculo.sucursales">
                            {{veh.sucursal}}
                        </ng-container>
                    </mat-cell>
				</ng-container>

				<ng-container matColumnDef="created_at">
					<mat-header-cell *matHeaderCellDef mat-sort-header>Fecha</mat-header-cell>
					<mat-cell *matCellDef="let vehiculo">{{vehiculo.created_at}}</mat-cell>
				</ng-container>

				<ng-container matColumnDef="actions">
					<mat-header-cell *matHeaderCellDef></mat-header-cell>
					<mat-cell *matCellDef="let vehiculo" class="justify-content-center">
						<button mat-icon-button type="button" (click)="editVehiculo(vehiculo.id)" class="btn-primary" matTooltip="Editar vehículo" *ngxPermissionsOnly="'administrador.vehiculos.show'">
							<mat-icon>create</mat-icon>
						</button>&nbsp; &nbsp;
						<button mat-icon-button type="button" (click)="deleteVehiculo(vehiculo)" class="btn-primary" matTooltip="{{!vehiculo.deleted_at ? 'Eliminar forma de pago' : 'Activar forma de pago'}}" *ngxPermissionsOnly="'administrador.vehiculos.destroy'">
							<mat-icon>{{!vehiculo.deleted_at ? 'delete' : 'done'}}</mat-icon>
						</button>
					</mat-cell>
				</ng-container>

				<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
				<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
			</mat-table>
			<div class="mat-table__message" *ngIf="dataSourceVehiculos.data.length == 0">No se encontraron registros.</div>
			<div class="mat-table__message" *ngIf="showMessageWait">Espera un momento....</div>
		</div>

		<div class="mat-table__bottom">
			<mat-spinner [diameter]="25" *ngIf="isLoading"></mat-spinner>
			<mat-paginator [pageSize]="perPage" [pageSizeOptions]="pages" [length]="total" (page)="paginator($event)"></mat-paginator>
		</div>
	</kt-portlet-body>

</kt-portlet>
