@extends('admin.layouts.app')

@section('title', 'View Certificate')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Certificate Details</h3>
                    <div class="card-tools">
                        <a href="{{ route('admin.graduation-certificates.download', $certificate) }}" class="btn btn-success">
                            <i class="fas fa-download"></i> Download Certificate
                        </a>
                        <a href="{{ route('admin.graduation-certificates.index') }}" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> Back to Certificates
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-8">
                            <div class="form-group">
                                <label>Generated Certificate</label>
                                <div class="border rounded p-2" style="background: #f8f9fa;">
                                    @if($certificate->generated_image_path)
                                        <img src="{{ $certificate->generated_image_url }}"
                                             alt="Generated Certificate"
                                             style="max-width: 100%; height: auto; display: block; margin: 0 auto;">
                                    @else
                                        <div class="text-center text-muted py-5">
                                            <i class="fas fa-image fa-3x mb-3"></i>
                                            <p>Certificate image not found</p>
                                        </div>
                                    @endif
                                </div>
                            </div>
                        </div>

                        <div class="col-md-4">
                            <div class="form-group">
                                <label>Certificate Information</label>
                                <div class="border rounded p-3" style="background: #f8f9fa;">
                                    <table class="table table-borderless">
                                        <tr>
                                            <td><strong>ID:</strong></td>
                                            <td>{{ $certificate->id }}</td>
                                        </tr>
                                        <tr>
                                            <td><strong>Student:</strong></td>
                                            <td>
                                                {{ $certificate->user->name }}<br>
                                                <small class="text-muted">{{ $certificate->user->email }}</small>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><strong>Template:</strong></td>
                                            <td>{{ $certificate->template->name }}</td>
                                        </tr>
                                        <tr>
                                            <td><strong>Graduation Date:</strong></td>
                                            <td>{{ $certificate->graduation_date->format('F j, Y') }}</td>
                                        </tr>
                                        <tr>
                                            <td><strong>Generated:</strong></td>
                                            <td>{{ $certificate->created_at->format('F j, Y \a\t g:i A') }}</td>
                                        </tr>
                                        <tr>
                                            <td><strong>Serial Number:</strong></td>
                                            <td>CERT-{{ str_pad($certificate->user->id, 6, '0', STR_PAD_LEFT) }}-{{ $certificate->graduation_date->format('Y') }}</td>
                                        </tr>
                                    </table>
                                </div>
                            </div>

                            <div class="form-group">
                                <label>Template Details</label>
                                <div class="border rounded p-3" style="background: #f8f9fa;">
                                    <table class="table table-borderless">
                                        <tr>
                                            <td><strong>Name Position:</strong></td>
                                            <td>({{ $certificate->template->name_x }}, {{ $certificate->template->name_y }})</td>
                                        </tr>
                                        <tr>
                                            <td><strong>Date Position:</strong></td>
                                            <td>({{ $certificate->template->date_x }}, {{ $certificate->template->date_y }})</td>
                                        </tr>
                                        <tr>
                                            <td><strong>Serial Position:</strong></td>
                                            <td>({{ $certificate->template->serial_x }}, {{ $certificate->template->serial_y }})</td>
                                        </tr>
                                    </table>
                                </div>
                            </div>

                            <div class="form-group">
                                <label>Actions</label>
                                <div class="d-grid gap-2">
                                    <a href="{{ route('admin.graduation-certificates.download', $certificate) }}"
                                       class="btn btn-success btn-block">
                                        <i class="fas fa-download"></i> Download
                                    </a>

                                    <form action="{{ route('admin.graduation-certificates.destroy', $certificate) }}"
                                          method="POST"
                                          onsubmit="return confirm('Are you sure you want to delete this certificate?')">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-danger btn-block">
                                            <i class="fas fa-trash"></i> Delete Certificate
                                        </button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
