
@php
    $enable_comment = false;
    $object = '';
    $objectUrl = '#';

    if (isset($page) && !empty($page->comment)) {
        $enable_comment = true;
        $object = $page;
        $objectUrl = DzHelper::laraPageLink($object->id);
    }
    if (isset($blog) && !empty($blog->comment)) {
        $enable_comment = true;
        $object = $blog;
        $objectUrl = DzHelper::laraBlogLink($object->id);
    }
@endphp

@if ($enable_comment)
    <div class="{{ isset($page) ? 'container' : '' }} clear" id="comment-list">
        <div class="comments-area style-1 clearfix" id="comments-div">
            <div class="widget-title mb-30">
                <h4 class="title text-2xl">@if ($comment_count_on){{ $total_comments }}@endif {{ _('COMMENTS') }}</h4>
            </div>
            @if($comments->isNotEmpty() && $comment_view_on)
                <div class="clearfix">
                    <ol class="comment-list pb-30">
                        @forelse($comments as $comment)
                            <li class="comment">
                                <div class="comment-body mb-30 flex gap-20 border-b pb-30 border-black/10">
                                    <div class="comment-author vcard">
                                        @if (optional($comment->user)->profile && Storage::exists('public/user-images/'.$comment->user->profile))
                                            <img class="avatar sm:size-80 size-50 rounded-full photo" src="{{ asset('storage/user-images/'.$comment->user->profile) }}" alt="">
                                        @else
                                            <img class="avatar sm:size-80 size-50 rounded-full photo" src="{{ asset('images/no-user.png') }}" alt="">
                                        @endif
                                    </div>
                                    <div class="comment-info flex-1">
                                        <div class="title dark:text-white mb-5 flex justify-between flex-wrap gap-6">
                                            <cite class="fn">
                                                {{ $comment->commenter }}
                                            </cite>
                                            <span class="max-sm:text-sm">{{ \Carbon\Carbon::parse($comment->created_at) }}</span>
                                        </div>
                                        <p class="sm:text-xl">{{ $comment->comment }}</p>
                                        <div class="reply mt-15">
                                            <a rel="nofollow" href="{{ $objectUrl }}?replytocom={{ $comment->id }}#respond" class="comment-reply-link w3-comment-reply border hover:text-secondary dark:text-white dark:border-white/10 border-black/10 hover:bg-primary rounded-full px-15 py-6 inline-block text-sm font-medium" data-commentid="{{ $comment->id }}" data-postid="{{ $object->id }}"  data-replyto="Reply to {{ $comment->commenter }}">
                                                <span>
                                                    <i class="fa fa-reply mr-2"></i>
                                                    {{ __('REPLY') }}
                                                </span>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                @if (isset($comment->child_comments) && $comment->child_comments->isNotEmpty())
                                    @include('elements.child_comments', ['comments' => $comment->child_comments,'parent_comment' => $comment->commenter, 'depth' => 1])
                                @endif
                            </li>
                        @empty
                        @endforelse
                    </ol>
                    <div class="mb-30">
                        @if(config('Discussion.page_comments'))
                            {!! $comments->links('elements.pagination') !!}
                        @endif
                    </div>
                </div>
            @endif
            @if(!config('Discussion.registration_comment'))
                <div class="bg-card sm:p-50 sm:pt-40 p-20 mb-20" id="ReplyFormContainer">
                    @if(Session::has('unapprove_comment_error'))
                        <div class="alert alert-danger alert-dismissible alert-alt fade show">
                            <strong>{{ __('common.error') }}</strong> {{ Session::get('unapprove_comment_error') }}
                            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="btn-close">
                        </div>
                    @endif
               
                    <div class="lg:mb-50 mb-30">
                        <h3 class="md:text-7xl/70 text-4xl text-white font-medium mb-10">{{ __('Leave A Reply') }}</h3>
                        <p class="sm:text-xl text-lg font-light text-white">Your email address will not be published. Required fields are marked *</p>
                    </div>

                    <h5 class="text-white text-xl">
                        <span id="reply-title"></span>
                        <small class="font-normal"> <a rel="nofollow" class="hidden" id="cancel-comment-reply" href="{{ $objectUrl }}#respond">{{ __('Cancel reply') }}</a> </small>
                    </h5>
                    @auth
                        <p class="text-white mb-30"> {{ __('You are Logged in as') }} <a class="text-primary" href="{{ route('admin.users.profile') }}">{{ Auth::user()->name }}</a></p>
                    @endauth

                    <!-- Form -->
                    <div class="comment-respond" id="respond">
                        <form action="{{ route('home.comments.store') }}" class="comment-form row" id="commentform" method="post">
                            @csrf
                            <div class="container">
                                @error('commenter')
                                    <div class="alert alert-primary alert-dismissible fade show" role="alert">
                                        {{ $message }}
                                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                    </div>
                                @enderror
                                @error('email')
                                    <div class="alert alert-primary alert-dismissible fade show" role="alert">
                                        {{ $message }}
                                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                    </div>
                                @enderror
                                @error('comment')
                                    <div class="alert alert-primary alert-dismissible fade show" role="alert">
                                        {{ $message }}
                                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                    </div>
                                @enderror
                            </div>
                            @if( Session::get('success'))
                                <p class="m-b30">
                                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                                        {{ Session::get('success') }}
                                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                    </div>
                                </p>
                            @endif
                            <input type="hidden" name="object_id" value="{{ $object->id }}">
                            <input type="hidden" name="parent_id" id="comment_parent" value="0">

                            @guest
                                <div class="grid grid-cols-12 gap-20 w-full">
                                    <div class="sm:col-span-6 col-span-12">
                                        <div class="mb-30">
                                            <label for="commenter" class="block text-white font-light mb-10">{{ __('Name') }} {!! $requiredFieldIndicator !!}</label>
                                            <input type="text" class="py-11 text-lg border-b-2 border-[#383B3F] text-white placeholder:text-white font-light h-50 w-full" name="commenter" placeholder="{{ __('Name') }}" id="commenter" value="{{ old('commenter', $comment_author) }}" {{ $isRequired }}>
                                        </div>
                                    </div>
                                   <div class="sm:col-span-6 col-span-12">
                                        <div class="mb-30">
                                            <label for="email" class="block text-white font-light mb-10">{{ __('Email') }} {!! $requiredFieldIndicator !!}</label>
                                            <input type="email" class="py-11 text-lg border-b-2 border-[#383B3F] text-white placeholder:text-white font-light h-50 w-full" placeholder="{{ __('Email') }}" name="email" id="email" value="{{ old('email', $comment_email) }}" {{ $isRequired }}>
                                        </div>
                                    </div>
                                    <div class="col-span-12">
                                        <div class="mb-40">
                                            <label for="profileurl" class="block text-white font-light mb-10">{{ __('Website url') }}</label>
                                            <input type="url" class="py-11 text-lg border-b-2 border-[#383B3F] text-white placeholder:text-white font-light h-50 w-full" placeholder="{{ __('Website url') }}" name="profile_url" id="profileurl" value="{{ old('profile_url', $comment_url) }}">
                                        </div>
                                    </div>
                                </div>
                            @endguest
                            <div class="mb-30 w-full">
                                <label for="comment" class="block text-white font-light mb-10">{{ __('Message') }}</label>
                                <textarea rows="8" class="py-11 text-lg border-b-2 border-[#383B3F] text-white placeholder:text-white font-light min-h-150 w-full" name="comment" placeholder="{{ __('Comment') }}" id="comment">{{ old('comment') }}</textarea>
                            </div>
                            @guest
                                @if(config('Discussion.save_comments_cookie'))
                                    <p class="comment-form-comment">
                                        <label class="form-check-label d-block">
                                            <input type="checkbox" name="set_comment_cookie" class="form-check-input" @checked($comment_author || $comment_email || $comment_url)>
                                            {{ __('Remember details for future comments: Name, Email, and Website.') }}
                                        </label>
                                    </p>
                                @endif
                            @endguest
                            <div class="form-submit w-full">
                                <button id="submit" type="submit" class="style-1 cursor-pointer btn btn-outline light border-white hover:border-primary text-white hover:text-dark ms-auto p-2 sm:h-60 group button--stroke flairBtn magneticBtn" data-block="button">
                                    <span class="button-flair"></span>
                                    <span class="button__label font-light xl:ps-35 px-20 inline-flex items-center gap-14">{{ __('Submit Now') }}</span>
                                    <span class="inline-flex justify-center items-center sm:size-50 size-32 rounded-full bg-white text-secondary duration-100 group-hover:bg-secondary z-0">
                                        <svg width="27" height="26" viewBox="0 0 27 26" fill="none" xmlns="http://www.w3.org/2000/svg">
                                            <path class="group-hover:stroke-white duration-100" d="M5.78711 13.1025H20.7871" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                                            <path class="group-hover:stroke-white duration-100" d="M13.2871 5.60254L20.7871 13.1025L13.2871 20.6025" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                                        </svg>
                                    </span>
                                </button>
                            </div>
                        </form>
                    </div>
                    <!-- Form -->
                    
                </div>
            @else
                <p>{{ __('Please') }} <a href="{{ route('admin.login') }}">{{ __('log in') }}</a> {{ __('to post a comment.') }}</p>
            @endif
            <!-- Form END -->
        </div>
    </div>
@endif
