@extends('layouts.app') @php $pageTitle = $decision['title'] ?? 'Report Details'; // Try to get text from the first successfully extracted PDF $pdfText = ''; if (isset($extractedPreviews) && is_array($extractedPreviews)) { foreach ($extractedPreviews as $preview) { if (!empty($preview['text'])) { $pdfText = $preview['text']; break; } } } // Use PDF text if available, fallback to hidden indexable content, then description $rawText = !empty($pdfText) ? $pdfText : ($decision['details']['metadata']['hidden_indexable_content'] ?? ($decision['description'] ?? '')); // Remove boilerplate lines before generating the snippet $rawText = preg_replace('/^.*(?:Crown copyright|All times are UTC).*$/mi', '', $rawText); $cleanText = trim(preg_replace('/\s+/', ' ', strip_tags($rawText))); $extract = \Illuminate\Support\Str::limit($cleanText, 200); $metaDescription = 'Accident Report - ' . $extract; @endphp @section('title', $pageTitle) @section('meta_description', $metaDescription) @section('content')
Back to Search

{{ $decision['title'] ?? 'Report Details' }}

@if (isset($decision['document_type'])) @php $formatLabels = [ 'aaib_report' => 'Air Accidents (AAIB)', 'maib_report' => 'Marine Accidents (MAIB)', 'raib_report' => 'Rail Accidents (RAIB)', ]; $label = $formatLabels[$decision['document_type']] ?? 'Report'; @endphp
{{ $label }}
@endif

@php $publishedDate = $decision['public_updated_at'] ?? ($decision['first_published_at'] ?? null); @endphp Published on {{ $publishedDate ? \Carbon\Carbon::parse($publishedDate)->format('d F Y, H:i') : 'Unknown' }}

Summary
{{ $decision['description'] ?? 'No summary available.' }}
@if (isset($decision['details']['metadata'])) @foreach ($decision['details']['metadata'] as $key => $value) @if ($key === 'hidden_indexable_content') @continue @endif
{{ str_replace('_', ' ', $key) }}
@if (is_array($value))
@foreach ($value as $item) @php $label = is_array($item) && isset($item['label']) ? $item['label'] : (is_array($item) ? implode(', ', $item) : $item); @endphp {{ $label }} @endforeach
@else {{ $value }} @endif
@endforeach @endif
@php $bodyHtml = $decision['details']['body'] ?? ''; // Smart Hiding Logic: Check if body is just boilerplate $strippedBody = trim(strip_tags($bodyHtml)); $cleanText = str_replace(['Read the full report in', '.', ','], '', $strippedBody); $cleanText = preg_replace('/\s+/', '', $cleanText); foreach ($attachments as $attachment) { $cleanTitle = preg_replace('/\s+/', '', $attachment['title'] ?? ''); if (!empty($cleanTitle)) { $cleanText = str_replace($cleanTitle, '', $cleanText); } } $showDecisionContent = !empty($bodyHtml) && strlen($cleanText) > 20; if (count($attachments) === 0 && !empty($bodyHtml)) { $showDecisionContent = true; } @endphp @if ($showDecisionContent)

Report Overview

@php $bodyHtml = str_replace('href="/', 'href="https://www.gov.uk/', $bodyHtml); $bodyHtml = preg_replace_callback( '/]*>(.*?)<\/a>/i', function ($matches) { $url = $matches[1]; $title = strip_tags($matches[2]); $svg = ''; return '' . $svg . '' . $title . 'Download'; }, $bodyHtml, ); preg_match_all('/(.*?<\/(?:p|ul|ol|h[1-6])>)/is', $bodyHtml, $matches); $truncatedBody = ''; $textLen = 0; if (!empty($matches[1])) { foreach ($matches[1] as $block) { $truncatedBody .= $block; $textLen += mb_strlen(strip_tags($block)); if ($textLen > 400) { break; } } } if (empty($truncatedBody)) { $truncatedBody = $bodyHtml; } elseif (strlen($truncatedBody) < strlen($bodyHtml)) { $truncatedBody .= '

This overview has been truncated. Please refer to the official documents below for the complete canonical report.

'; } @endphp {!! $truncatedBody !!}
@endif @if (count($attachments) > 0)

Official Documents

    @foreach ($attachments as $attachment)
  • {{ $attachment['title'] ?? 'Document' }}
  • @endforeach
@endif @if (isset($extractedPreviews) && count($extractedPreviews) > 0)

Document Content Preview

Extracted text from the first few pages of the official documents.

@foreach ($extractedPreviews as $preview)

{{ $preview['title'] ?? 'Document' }}

@if (isset($preview['error']) && $preview['error'])

Unable to extract preview for this document.

@elseif (!empty($preview['text']))
{!! $preview['text'] !!}
@if ($preview['is_truncated'] ?? false)

Text truncated. The original document has {{ $preview['total_pages'] }} pages.

Read the full text here

@endif @else

No text could be extracted from this document.

@endif
@endforeach
@endif
@if (!empty($decision['details']['change_history']))

Change History

    @foreach ($decision['details']['change_history'] as $index => $history)
  • @if (!$loop->last) @endif

    {{ $history['note'] ?? 'Updated' }}

  • @endforeach
@endif
@if (!empty($decision['details']['metadata']['hidden_indexable_content']))

Full Report Text

Raw text extracted from the official documents.

{{ $decision['details']['metadata']['hidden_indexable_content'] }}
@endif @php $entities = []; $metadata = $decision['details']['metadata'] ?? []; // Extract useful entities from metadata for SEO links $usefulKeys = ['registration', 'aircraft_type', 'location', 'vessel_name', 'vessel_type', 'railway_type']; foreach ($usefulKeys as $key) { if (!empty($metadata[$key])) { $value = $metadata[$key]; if (is_array($value)) { foreach ($value as $item) { $val = is_array($item) && isset($item['label']) ? $item['label'] : (is_array($item) ? implode(' ', $item) : $item); if (!empty($val)) { $entities[] = $val; } } } else { $entities[] = $value; } } } // Remove duplicates $entities = array_unique($entities); @endphp @if (count($entities) > 0)

Related Entities

Search the database for other reports involving these entities.

@foreach ($entities as $entity) {{ $entity }} @endforeach
@endif @endsection