@extends('admin.layouts.app')

@section('title', 'Preview Blog Post')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Preview Blog Post</h3>
                    <div class="card-tools">
                        <a href="{{ route('admin.blog.edit', $blog) }}" class="btn btn-warning">
                            <i class="fas fa-edit"></i> Edit
                        </a>
                        <a href="{{ route('admin.blog.index') }}" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> Back to List
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-8">
                            <!-- Blog Content Preview -->
                            <article class="blog-preview">
                                <header class="mb-4">
                                    <h1 class="display-5 fw-bold">{{ $blog->title }}</h1>
                                    <div class="text-muted mb-3">
                                        <i class="fas fa-calendar"></i>
                                        @if($blog->published_at)
                                            Published on {{ $blog->published_at->format('F d, Y') }}
                                        @else
                                            Created on {{ $blog->created_at->format('F d, Y') }}
                                        @endif
                                    </div>
                                    <div class="mb-3">
                                        @if($blog->status === 'published')
                                            <span class="badge bg-success fs-6">
                                                <i class="fas fa-check-circle"></i> Published
                                            </span>
                                        @else
                                            <span class="badge bg-warning fs-6">
                                                <i class="fas fa-clock"></i> Draft
                                            </span>
                                        @endif
                                    </div>
                                </header>

                                <div class="blog-content">
                                    {!! $blog->content !!}
                                </div>
                            </article>
                        </div>

                        <div class="col-md-4">
                            <!-- Post Information Sidebar -->
                            <div class="card">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">Post Information</h5>
                                </div>
                                <div class="card-body">
                                    <dl class="row">
                                        <dt class="col-sm-4">Status:</dt>
                                        <dd class="col-sm-8">
                                            @if($blog->status === 'published')
                                                <span class="badge bg-success">Published</span>
                                            @else
                                                <span class="badge bg-warning">Draft</span>
                                            @endif
                                        </dd>

                                        <dt class="col-sm-4">Slug:</dt>
                                        <dd class="col-sm-8">
                                            <code>{{ $blog->slug }}</code>
                                        </dd>

                                        <dt class="col-sm-4">Created:</dt>
                                        <dd class="col-sm-8">{{ $blog->created_at->format('M d, Y H:i') }}</dd>

                                        <dt class="col-sm-4">Updated:</dt>
                                        <dd class="col-sm-8">{{ $blog->updated_at->format('M d, Y H:i') }}</dd>

                                        @if($blog->published_at)
                                            <dt class="col-sm-4">Published:</dt>
                                            <dd class="col-sm-8">{{ $blog->published_at->format('M d, Y H:i') }}</dd>
                                        @endif
                                    </dl>
                                </div>
                            </div>

                            @if($blog->meta_description || $blog->meta_keywords)
                                <div class="card mt-3">
                                    <div class="card-header">
                                        <h5 class="card-title mb-0">SEO Information</h5>
                                    </div>
                                    <div class="card-body">
                                        @if($blog->meta_description)
                                            <div class="mb-3">
                                                <strong>Meta Description:</strong>
                                                <p class="text-muted small">{{ $blog->meta_description }}</p>
                                            </div>
                                        @endif

                                        @if($blog->meta_keywords)
                                            <div class="mb-0">
                                                <strong>Meta Keywords:</strong>
                                                <div class="mt-1">
                                                    @foreach(explode(',', $blog->meta_keywords) as $keyword)
                                                        <span class="badge bg-secondary me-1">{{ trim($keyword) }}</span>
                                                    @endforeach
                                                </div>
                                            </div>
                                        @endif
                                    </div>
                                </div>
                            @endif

                            <!-- Quick Actions -->
                            <div class="card mt-3">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">Quick Actions</h5>
                                </div>
                                <div class="card-body">
                                    <div class="d-grid gap-2">
                                        <a href="{{ route('admin.blog.edit', $blog) }}" class="btn btn-warning">
                                            <i class="fas fa-edit"></i> Edit Post
                                        </a>
                                        
                                        @if($blog->status === 'published')
                                            <a href="{{ route('top-universities-uk') }}" class="btn btn-success" target="_blank">
                                                <i class="fas fa-external-link-alt"></i> View Live
                                            </a>
                                        @endif

                                        <form action="{{ route('admin.blog.destroy', $blog) }}" method="POST" 
                                              onsubmit="return confirm('Are you sure you want to delete this post? This action cannot be undone.')">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-danger w-100">
                                                <i class="fas fa-trash"></i> Delete Post
                                            </button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('styles')
<style>
.blog-preview {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
}

.blog-preview h1, .blog-preview h2, .blog-preview h3, 
.blog-preview h4, .blog-preview h5, .blog-preview h6 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.blog-preview p {
    margin-bottom: 1rem;
    text-align: justify;
}

.blog-preview img {
    max-width: 100%;
    height: auto;
    border-radius: 0.375rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.blog-preview blockquote {
    border-left: 4px solid #007bff;
    padding-left: 1rem;
    margin: 1.5rem 0;
    font-style: italic;
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 0.375rem;
}

.blog-preview table {
    width: 100%;
    margin: 1.5rem 0;
    border-collapse: collapse;
}

.blog-preview table th,
.blog-preview table td {
    border: 1px solid #dee2e6;
    padding: 0.75rem;
    text-align: left;
}

.blog-preview table th {
    background-color: #f8f9fa;
    font-weight: 600;
}

.blog-preview ul, .blog-preview ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.blog-preview li {
    margin-bottom: 0.5rem;
}
</style>
@endpush