@extends('frontend.layouts.main')
@section('meta_title', $post->meta_title ?? $post->title)
@section('meta_keywords', $post->meta_keywords ?? 'news, article')
@section('meta_description', $post->meta_description ?? Str::limit(strip_tags($post->content), 150))

@section('section')

    <!-- Breadcrumb Start -->
    <div class="breadcrumb-wrap">
        <div class="container">
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="#">Home</a></li>
                <li class="breadcrumb-item"><a href="#">News</a></li>
                <li class="breadcrumb-item active">News details</li>
            </ul>
        </div>
    </div>
    <!-- Breadcrumb End -->

    <!-- Single News Start-->
    <div class="single-news">
        <div class="container">
            <div class="row">
                <div class="col-lg-8">
                    <div class="sn-container">
                        <div class="sn-img">
                            <img src="{{ asset($post->post_image) }}" alt="{{ $post->title }}" />
                        </div>
                        <div class="sn-content">
                            <h1 class="sn-title">{{ $post->title }}</h1>
                            {!! $post->content !!}
                        </div>
                    </div>
                    <div class="sn-related">
                        <h2>Related News</h2>
                        <div class="row sn-slider">
                            @foreach ($btmrtldPosts as $btmrtldPost)
                                <div class="col-md-4">
                                    <div class="sn-img">
                                        <img src="{{ asset($btmrtldPost->post_image) }}"
                                            alt="{{ $btmrtldPost->title }}">
                                        <div class="sn-title">
                                            <a
                                                href="{{ route('post.view', $btmrtldPost->slug) }}">{{ Str::limit($btmrtldPost->title, 70) }}</a>
                                        </div>
                                    </div>
                                </div>
                            @endforeach
                        </div>
                    </div>

                    <!-- Comments Section Start -->
                    <div class="sn-comments mt-5">
                      

                        {{-- Comment form --}}
                        <div class="comment-form mb-4">
                            <h3>Leave a Comment</h3>

                            <form action="{{ route('post.comments') }}" method="POST" class="comment-form">
                                @csrf

                                <input type="hidden" name="post_id" value="{{ $post->id }}">

                                {{-- Name Field --}}
                                <div class="form-group mb-2">
                                    <input type="text" name="name"
                                        class="form-control @error('name') is-invalid @enderror" placeholder="Your Name"
                                        value="{{ old('name') }}" required>
                                    @error('name')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>

                                {{-- Email Field --}}
                                <div class="form-group mb-2">
                                    <input type="email" name="email"
                                        class="form-control @error('email') is-invalid @enderror" placeholder="Your Email"
                                        value="{{ old('email') }}" required>
                                    @error('email')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>

                                {{-- Comment Content --}}
                                <div class="form-group mb-2">
                                    <textarea name="content" class="form-control @error('content') is-invalid @enderror" rows="4"
                                        placeholder="Your Comment" required>{{ old('content') }}</textarea>
                                    @error('content')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>

                                <button type="submit" class="btn btn-primary">Submit Comment</button>
                            </form>
                        </div>


                        <h2>Comments</h2>
                        <div class="comments-list ">
                            @forelse ($post->comments as $comment)
                                <div class="comment mb-3 p-3 border rounded">
                                    <strong>{{ $comment->name }}</strong>
                                    <span class="text-muted small">{{ $comment->created_at->diffForHumans() }}</span>
                                    <div>{{ $comment->content }}</div>
                                </div>
                            @empty
                                <p>No comments yet. Be the first to comment!</p>
                            @endforelse
                        </div>

                    </div>
                    <!-- Comments Section End -->
                </div>

                <div class="col-lg-4">
                    <div class="sidebar">
                        <div class="sidebar-widget">
                            <h2 class="sw-title">In This Category</h2>
                            <div class="news-list">
                                @foreach ($relatedPosts as $rpost)
                                    <div class="nl-item">
                                        <div class="nl-img">
                                            <img src="{{ asset($rpost->post_image) }}"
                                                alt="{{ $rpost->title }}">
                                        </div>
                                        <div class="nl-title">
                                            <a
                                                href="{{ route('post.view', $rpost->slug) }}">{{ Str::limit($rpost->title, 70) }}</a>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        </div>


                        {{-- <div class="sidebar-widget">
                            <div class="image">
                                <a href="https://htmlcodex.com/"><img src="img/ads-2.jpg" alt="Image"></a>
                            </div>
                        </div> --}}

                        <div class="sidebar-widget">
                            <div class="tab-news">
                                <ul class="nav nav-pills nav-justified">
                                    <li class="nav-item">
                                        <a class="nav-link active" data-toggle="pill" href="#featured">Featured</a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link" data-toggle="pill" href="#popular">Popular</a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link" data-toggle="pill" href="#latest">Latest</a>
                                    </li>
                                </ul>

                                <div class="tab-content">
                                    {{-- Featured Tab --}}
                                    <div id="featured" class="container tab-pane active">
                                        @foreach ($featuredPosts as $post)
                                            <div class="tn-news">
                                                <div class="tn-img">
                                                    <img src="{{ asset($post->post_image) }}"
                                                        alt="{{ $post->title }}">
                                                </div>
                                                <div class="tn-title">
                                                    <a
                                                        href="{{ route('post.view', $post->slug) }}">{{ Str::limit($post->title, 70) }}</a>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>

                                    {{-- Popular Tab --}}
                                    <div id="popular" class="container tab-pane fade">
                                        @foreach ($popularPosts as $post)
                                            <div class="tn-news">
                                                <div class="tn-img">
                                                    <img src="{{ asset($post->post_image) }}"
                                                        alt="{{ $post->title }}">
                                                </div>
                                                <div class="tn-title">
                                                    <a
                                                        href="{{ route('post.view', $post->slug) }}">{{ Str::limit($post->title, 70) }}</a>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>

                                    {{-- Latest Tab --}}
                                    <div id="latest" class="container tab-pane fade">
                                        @foreach ($latestPosts as $post)
                                            <div class="tn-news">
                                                <div class="tn-img">
                                                    <img src="{{ asset($post->post_image) }}"
                                                        alt="{{ $post->title }}">
                                                </div>
                                                <div class="tn-title">
                                                    <a
                                                        href="{{ route('post.view', $post->slug) }}">{{ Str::limit($post->title, 70) }}</a>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        </div>


                        {{-- <div class="sidebar-widget">
                            <div class="image">
                                <a href="https://htmlcodex.com/"><img src="img/ads-2.jpg" alt="Image"></a>
                            </div>
                        </div> --}}

                        <div class="sidebar-widget">
                            <h2 class="sw-title">News Category</h2>
                            <div class="category">
                                <ul>
                                    @foreach ($categories as $category)
                                        <li>
                                            <a href="{{ route('category', $category->slug) }}">{{ $category->name }}</a>
                                            <span>({{ $category->posts_count }})</span>
                                        </li>
                                    @endforeach
                                </ul>

                            </div>
                        </div>

                        {{-- <div class="sidebar-widget">
                            <div class="image">
                                <a href="https://htmlcodex.com/"><img src="img/ads-2.jpg" alt="Image"></a>
                            </div>
                        </div> --}}

                        <div class="sidebar-widget">
                            <h2 class="sw-title">Tags Cloud</h2>
                            <div class="tags">
                                @foreach ($tags as $tag)
                                    <a href="{{ route('tag', $tag->slug) }}">{{ $tag->name }}</a>
                                @endforeach
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Single News End-->
@endsection
