@extends('back-end.master.app')

@section('title', 'Post Details')

@section('body')
<main class="app-content">
    <section class="gradient-custom-2">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h4>Post Details</h4>
                            <a href="{{ route('posts.index') }}" class="btn btn-sm btn-secondary">Back to List</a>
                        </div>
                        <div class="card-body">
                            {{-- Post Image --}}
                            @if($post->image && $post->image != 'image/noimage.jpg')
                                <div class="text-center mb-4">
                                    <img src="{{ asset('storage/'.$post->image) }}" alt="{{ $post->title }}" style="max-width: 100%; max-height: 400px;">
                                </div>
                            @endif

                            {{-- Post Info Table --}}
                            <table class="table table-bordered">
                                <tr>
                                    <th style="width: 200px;">Title</th>
                                    <td>{{ $post->title }}</td>
                                </tr>
                                <tr>
                                    <th>Category</th>
                                    <td>{{ $post->category->title_en ?? '-' }}</td>
                                </tr>
                                <tr>
                                    <th>Language</th>
                                    <td>{{ $post->language->title_en ?? '-' }}</td>
                                </tr>
                                <tr>
                                    <th>Date</th>
                                    <td>{{ $post->date }}</td>
                                </tr>
                                <tr>
                                    <th>Status</th>
                                    <td>
                                        @if($post->status == 1)
                                            <span class="badge bg-success">Published</span>
                                        @else
                                            <span class="badge bg-warning">Draft</span>
                                        @endif
                                    </td>
                                </tr>
                            </table>

                            {{-- Post Body --}}
                            <div class="card mt-3">
                                <div class="card-header">
                                    <h5>Content</h5>
                                </div>
                                <div class="card-body">
                                    {!! $post->body !!}
                                </div>
                            </div>

                            {{-- Comments Section --}}
                            <div class="card mt-3">
                                <div class="card-header d-flex justify-content-between">
                                    <h5>Comments ({{ $comments->count() }})</h5>
                                </div>
                                <div class="card-body">
                                    @if($comments->count() > 0)
                                        <table class="table table-hover">
                                            <thead>
                                                <tr>
                                                    <th>#</th>
                                                    <th>Name</th>
                                                    <th>Email</th>
                                                    <th>Message</th>
                                                    <th>Status</th>
                                                    <th>Actions</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                @foreach($comments as $comment)
                                                <tr>
                                                    <td>{{ $loop->iteration }}</td>
                                                    <td>{{ $comment->name }}</td>
                                                    <td>{{ $comment->email }}</td>
                                                    <td>{{ Str::limit($comment->message, 50) }}</td>
                                                    <td>
                                                        @if($comment->seen_status)
                                                            <span class="badge bg-success">Seen</span>
                                                        @else
                                                            <span class="badge bg-warning">Pending</span>
                                                        @endif
                                                    </td>
                                                    <td>
                                                        @if(!$comment->seen_status)
                                                            <a href="{{ route('comments.seen', $comment->id) }}" class="btn btn-sm btn-warning" title="Mark as seen">
                                                                <i class="fa fa-eye"></i>
                                                            </a>
                                                        @endif
                                                        <form action="{{ route('comments.destroy', $comment->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Delete comment?')">
                                                            @csrf
                                                            @method('DELETE')
                                                            <button class="btn btn-sm btn-danger" title="Delete"><i class="fa fa-trash"></i></button>
                                                        </form>
                                                    </td>
                                                </tr>
                                                @endforeach
                                            </tbody>
                                        </table>
                                    @else
                                        <p class="text-muted">No comments yet.</p>
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
@endsection

@section('pageJs')
<script>
    $(".app-menu").removeClass("active");
    $("#nav_stocki").addClass("active");
    $("#stocki").addClass("is-expanded");
    $("#posts").addClass("active");
</script>
@endsection
