@extends("layouts.dashboard")

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

@section("dashboard_content")

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

		<div class="container">

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

			<div class="row row-cards">

				@if(auth()->user()->hasPermission("access_all_posts"))
				<div class="col">
					<div class="card">
						<div class="card-body p-3 text-center">
							<div class="h1 m-0 pt-4">{{ $counters["allPosts"] }}</div>
							<div class="text-muted mb-4 font-weight-bold"><a href="{{ route("dashboard.posts.index") }}">Total Posts</a></div>
						</div>
					</div>
				</div>
				@endif

				<div class="col">
					<div class="card">
						<div class="card-body p-3 text-center">
							<div class="h1 m-0 pt-4">{{ $counters["currentUserPosts"] }}</div>
							<div class="text-muted mb-4 font-weight-bold"><a href="{{ route("blog.user-profile", ["profileLink" => auth()->user()->userProfile->profile_link]) }}">Your Posts</a></div>
						</div>
					</div>
				</div>

				@if(auth()->user()->hasPermission("access_all_users"))
				<div class="col">
					<div class="card">
						<div class="card-body p-3 text-center">
							<div class="h1 m-0 pt-4">{{ $counters["users"] }}</div>
							<div class="text-muted mb-4 font-weight-bold"><a href="{{ route("dashboard.users.index") }}">Users</a></div>
						</div>
					</div>
				</div>
				@endif

				@if(auth()->user()->hasPermission("approve_all_comments"))
				<div class="col">
					<div class="card">
						<div class="card-body p-3 text-center">
							<div class="h1 m-0 pt-4">{{ $counters["total_comments"] }}</div>
							<div class="text-muted mb-4 font-weight-bold"><a href="{{ route("dashboard.comments.index") }}">Total Comments</a></div>
						</div>
					</div>
				</div>
				@endif

				<div class="col">
					<div class="card">
						<div class="card-body p-3 text-center">
							<div class="h1 m-0 pt-4">{{ $counters["comments"] }}</div>
							<div class="text-muted mb-4 font-weight-bold"><a href="{{ route("dashboard.comments.index") }}">Your Post Comments</a></div>
						</div>
					</div>
				</div>

			</div>

			<div class="row row-cards row-deck">

				@if(auth()->user()->hasPermission("confirm_post"))
				<div class="col">
					<div class="card">
						<div class="card-header">
							<h3 class="card-title">Pending Posts</h3>
						</div>
						<div class="card-body o-auto" style="height: 15rem">
							<ul class="list-unstyled list-separated">
								@foreach ($pendingPosts as $post)
								<li class="list-separated-item">
										<div class="row align-items-center">
											<div class="col">
												<div>
													<a href="javascript:void(0)" class="text-inherit">{{ $post->title }}</a>
												</div>
												<small class="d-block item-except text-sm text-muted h-1x">{{ $post->user->getFullName() }}</small>
											</div>
											<div class="col-auto">
												<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;">
														<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>
														<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>
											</div>
										</div>
									</li>
								@endforeach
							</ul>
						</div>
					</div>
				</div>
				@endif

				@php

					$flag = true;

					if(!auth()->user()->hasPermission("confirm_post")) {
						$flag = false;
					}

				@endphp

				<div class="{{ $flag ? "col" : "col-md-6" }}">
					<div class="card">
						<div class="card-header">
							<h3 class="card-title">Pending Comments</h3>
						</div>
						<div class="card-body o-auto" style="height: 15rem">
							<ul class="list-unstyled list-separated">
								@foreach ($pendingComments as $comment)
								<li class="list-separated-item">
									<div class="row align-items-center">
										<div class="col">
											<div>
												<a href="javascript:void(0)" class="text-inherit">{{ $comment->comment }}</a>
											</div>
											<small class="d-block item-except text-sm text-muted h-1x">{{ $comment->name }}</small>
										</div>
										<div class="col-auto">
											<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;">
													<a href="javascript:void(0)" class="actionLink dropdown-item" style="cursor: pointer;" data-action="{{ route("dashboard.comments.confirm", ["id" => $comment->id]) }}" data-method="patch"><i class="dropdown-icon fe fe-check"></i> Confirm </a>
													<a href="javascript:void(0)" class="actionLink dropdown-item" style="cursor: pointer;" data-action="{{ route("dashboard.comments.destroy", ["id" => $comment->id]) }}" data-method="delete"><i class="dropdown-icon fe fe-trash-2 text-danger"></i> Delete </a>
												</div>
											</div>
										</div>
									</div>
								</li>
								@endforeach
							</ul>
						</div>
					</div>
				</div>

			@if($flag)
			</div>
			@endif

			<div class="{{ $flag ? "row row-cards row-deck" : "col-md-6" }}">

				<div class="{{ $flag ? "col-md-12" : "" }}">
					<div class="card">
						<div class="card-header">
							<h4 class="card-title">Popular Posts</h4>
						</div>
						<table class="table card-table">
							<tbody>
								@foreach ($mostLikedPosts as $post)
								<tr>
									<td><a href="{{ route("blog.post", ["category" => strtolower($post->category->name), "slug" => $post->slug]) }}" target="_blank">{{ $post->title }}</a></td>
									<td width="1"></td>
									<td class="text-right"><span class="text-muted">{{ $post->total_likes }}</span></td>
								</tr>
								@endforeach
							</tbody>
						</table>
					</div>
				</div>

			</div>

			@if(!$flag)
			</div>
			@endif

		</div>

	</div>

@endsection
