@page "/productcategories"
@inherits PrivateRoute

<ContentHeader>
	<Header>
		<PageTitle Title="Produkt kategorie" />
	</Header>
</ContentHeader>
<ContentMain>
	<Card>
		<Title>
			<div class="row">
				<div class="col-12 col-sm-6 col-md-3 float-left">
					<input @onchange="async (ChangeEventArgs args) => await HandleSearch(args)" class="form-control rounded" placeholder="Vyhledavání" type="text" />
				</div>
			</div>
		</Title>
		<Body>
			@if (this.productCategories is not null && this.productCategories.Count > 0)
			{
				<Table>
					<TableHead>
						<TableRow>
							<th>#</th>
							<th @onclick="async () => await HandleSort(nameof(ProductCategoryDto.Name))" style="cursor:pointer">
								@if (activeSortField.Equals(nameof(ProductCategoryDto.Name)))
								{
									<i class="fas fa-arrow-@(isAscending ? "down" : "up")"></i>
								}
								Název
							</th>
							<th>Popis</th>
							<th>Možnosti</th>
						</TableRow>
					</TableHead>
					<TableBody>
						@foreach (var productCategory in productCategories)
						{
							<TableRow>
								<TableCell>@productCategory.ID</TableCell>
								<TableCell>@productCategory.Name</TableCell>
								<TableCell>
									<textarea class="w-100" readonly disabled>@productCategory.Description</textarea>
								</TableCell>
								<TableCell>
									<div class="dropdown">
										<button class="btn" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
											<i class="fas fa-ellipsis-h"></i>
										</button>
										<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
											<a class="dropdown-item" href="@("productcategory/edit/" + productCategory.ID)">
												<i class="far fa-edit"></i>
												Edit
											</a>
											<button @onclick="() => ShowDeleteConfirmModalAsync(productCategory.ID)" class="dropdown-item">
												<i class="far fa-trash-alt"></i>
												Smazat
											</button>
										</div>
									</div>
								</TableCell>
							</TableRow>
						}
					</TableBody>
				</Table>

				if (totalPages > 1)
				{
					<Pagination PagesCount="totalPages"
								ActivePageIndex="currentPageIndex"
								PageChangeAsync="async (int pageIndex) => await HandlePageChange(pageIndex)"
								PageShiftAsync="async (int shift) => await HandlePageShift(shift)" />
				}
			}
			else
			{
				<p>Žádné produkt kategorie nenalezeny!</p>
			}
		</Body>
	</Card>
	<div class="col-md-2" style="width: max-content">
		<a class="btn btn-success" href="productcategory/create">Vytvořit kategorii</a>
	</div>
</ContentMain>