@extends("layouts.dashboard")

@section("title", "Posts - Dashboard | TechnoBlog")

@section("dashboard_content")

	<div class="my-3 my-md-5">

		<div class="container">

			<div class="page-header">
				<h1 class="page-title">Posts</h1>
			</div>

			<div class="row">

				<div class="col-sm-12">
					<div class="card">

						<div class="card-header">
							<h3 class="card-title">List of posts</h3>
							<a href="{{ route("dashboard.posts.create") }}" style='margin-left: auto;order: 2;'>
								<button type="button" class="btn btn-primary">Add new</button>
							</a>
						</div>

						<div class="table-responsive pt-5 pb-5">

							<table id="dttable" class="table table-hover table-outline table-vcenter text-nowrap card-table">
								<thead>
									<tr>
										<th>Image</th>
										<th>Title</th>
										<th>Category</th>
										<th>User</th>
										<th>Status</th>
										<th>Confirmed By</th>
										<th>Actions</th>
									</tr>
								</thead>
								<tbody>
									@foreach ($posts as $post)
										<tr>
											<td class="text-center">
												<div class="avatar d-block" style="width: 5rem; height: 5rem; border-radius: 5%; background-image: url(/uploads/{{ $post->image_link }})"></div>
											</td>
											<td>{{ $post->title }}</td>
											<td class="{{ $post->category->is_active ? "" : "text-danger" }}">{{ $post->category->name }}</td>
											<td>{{ $post->user->getFullName() }}</td>
											<td>
												@if($post->is_confirmed)
													@if($post->is_active)
														Active
													@else
														Blocked
													@endif
												@else
													Not confirmed yet
												@endif
											</td>
											<td>
												@if ($post->is_confirmed)
													{{ $post->getConfirmedBy() }}
												@else
													Not confirmed yet
												@endif
											</td>
											<td class="text-center">
												@if($post->is_confirmed || $currentUser->hasPermission("confirm_post"))
													<div class="item-action dropdown">
														<a href="javascript:void(0)" data-toggle="dropdown" class="icon" aria-expanded="false"><i class="fe fe-more-vertical"></i></a>
														<div class="dropdown-menu dropdown-menu-right" x-placement="bottom-end" style="position: absolute; transform: translate3d(15px, 20px, 0px); top: 0px; left: 0px; will-change: transform;">

															@if ($post->is_confirmed)
																<a href="{{ route("blog.post", ["category" => strtolower($post->category->name), "slug" => $post->slug]) }}" target="_blank" class="dropdown-item"><i class="dropdown-icon fe fe-file-text"></i> View Post </a>
															@endif

															<a href="{{ route("dashboard.posts.edit", ["id" => $post->id]) }}" class="dropdown-item"><i class="dropdown-icon fe fe-edit"></i> Edit Post </a>

															@if($post->category->is_active)
																@if ($post->is_confirmed)
																	@if ($post->is_active)
																	<a href="javascript:void(0)" class="actionLink dropdown-item" style="cursor: pointer;" data-action="{{ route("dashboard.posts.block", ["id" => $post->id]) }}" data-method="patch"><i class="dropdown-icon fe fe-lock"></i> Block </a>
																		<div class="dropdown-divider"></div>
																	@else
																		<a href="javascript:void(0)" class="actionLink dropdown-item" style="cursor: pointer;" data-action="{{ route("dashboard.posts.unblock", ["id" => $post->id]) }}" data-method="patch"><i class="dropdown-icon fe fe-unlock"></i> Publish </a>
																		<div class="dropdown-divider"></div>
																	@endif
																@else
																	<a href="javascript:void(0)" class="actionLink dropdown-item" style="cursor: pointer;" data-action="{{ route("dashboard.posts.confirm", ["id" => $post->id]) }}" data-method="patch"><i class="dropdown-icon fe fe-check"></i> Confirm </a>
																	<div class="dropdown-divider"></div>
																@endif
															@endif

															<a href="javascript:void(0)" class="actionLink dropdown-item" style="cursor: pointer;" data-action="{{ route("dashboard.posts.destroy", ["id" => $post->id]) }}" data-method="delete"><i class="dropdown-icon fe fe-trash-2 text-danger"></i> Delete </a>

														</div>
													</div>
												@endif
											</td>
										</tr>
									@endforeach
								</tbody>
							</table>

						</div>

					</div>

				</div>

			</div>

		</div>

	</div>

@endsection
