@extends('layouts.master') @section('title') {{ __('Comments') }} — {{ $requestItem->document_name }} @endsection @section('css') @endsection @section('content') @php $authUser = Auth::user(); $from = request()->query('from'); $viewerDashboardContext = strtolower(trim((string) request()->query('view', ''))); $documentViewerQuery = in_array($viewerDashboardContext, ['work', 'requests'], true) ? ['view' => $viewerDashboardContext] : []; $backUrl = route('document-viewer.show', array_merge(['id' => $requestItem->id], $documentViewerQuery)); $backLabel = __('Back to Document'); $commentFormUrl = route('document-viewer.comment', array_merge(['id' => $requestItem->id], $documentViewerQuery)); $currentState = $requestItem->workflow_state ?? 'submitted'; $stateBadgeColor = match($currentState) { 'completed' => 'success', 'rejected' => 'danger', 'v_rector_processing' => 'primary', default => 'info', }; $ext = strtolower((string) ($mainFile['extension'] ?? '')); $mime = strtolower((string) ($mainFile['mime_type'] ?? '')); $isPdfPreview = $ext === 'pdf' || $mime === 'application/pdf'; $isImagePreview = in_array($ext, ['jpg','jpeg','png','gif','webp'], true) || str_starts_with($mime, 'image/'); $currentUserId = (int) ($authUser->id ?? 0); $builderTemplateUrl = $builderTemplateUrl ?? null; $builderTemplateIsImage = (bool) ($builderTemplateIsImage ?? false); $builderSchemaFields = is_array($builderSchemaFields ?? null) ? $builderSchemaFields : []; $builderSubmittedData = is_array($builderSubmittedData ?? null) ? $builderSubmittedData : []; $hasTemplateFilledData = !empty($builderTemplateUrl) && is_array($builderSubmittedData) && count($builderSubmittedData) > 0; $filledPreviewUrl = $hasTemplateFilledData ? route('document-viewer.main-file.preview', $requestItem->id) : null; $filledDownloadUrl = $hasTemplateFilledData ? route('document-viewer.filled-pdf.export', ['id' => $requestItem->id, 'action' => 'download']) : null; $originalOpenUrl = null; $originalDownloadUrl = null; if ($hasTemplateFilledData && !empty($filledPreviewUrl)) { $originalOpenUrl = $filledPreviewUrl; $originalDownloadUrl = $filledDownloadUrl; } elseif ($mainFile && ($mainFile['exists'] ?? false)) { $originalOpenUrl = $mainFile['preview_url'] ?? $mainFile['url'] ?? null; $originalDownloadUrl = $mainFile['download_url'] ?? $mainFile['url'] ?? null; } elseif (!empty($builderTemplateUrl)) { $originalOpenUrl = $builderTemplateUrl; $originalDownloadUrl = null; } $avatarColors = [ 'bg-primary-subtle text-primary', 'bg-success-subtle text-success', 'bg-danger-subtle text-danger', 'bg-warning-subtle text-warning', 'bg-info-subtle text-info', 'bg-secondary-subtle text-secondary', ]; $userAvatarHtml = function (?\App\Models\User $actor) use ($avatarColors) { if (!$actor) { return 'S'; } $colorClass = $avatarColors[$actor->id % count($avatarColors)]; $initial = strtoupper(substr($actor->name ?? 'S', 0, 1)); return '' . e($initial) . ''; }; $roleDisplayLabel = fn (string $role): string => \App\Support\RoleDisplay::label($role); $initialOpenUrl = null; $initialDownloadUrl = null; if ($hasTemplateFilledData && !empty($filledPreviewUrl)) { $initialOpenUrl = $filledPreviewUrl; $initialDownloadUrl = !empty($filledDownloadUrl) ? $filledDownloadUrl : null; } elseif ($mainFile && ($mainFile['exists'] ?? false)) { $initialOpenUrl = $mainFile['preview_url'] ?? $mainFile['url'] ?? null; $initialDownloadUrl = $mainFile['download_url'] ?? $mainFile['url'] ?? null; } elseif (!empty($builderTemplateUrl)) { $initialOpenUrl = $builderTemplateUrl; $initialDownloadUrl = null; } $documentVersionName = function (?string $name): string { $name = trim((string) $name); return $name !== '' ? $name : __('Document'); }; $originalVersionName = $documentVersionName( $mainFile['name'] ?? (!empty($builderTemplateUrl) ? __('Template Preview') : __('Document')) ); $commentDateTime = function ($date): string { if (!$date) { return __('N/A'); } return \App\Support\DateFormatter::localized($date, 'F j') . ' ' . __('time') . ' ' . \App\Support\DateFormatter::localized($date, 'g:i A'); }; $translateSystemText = function ($value): string { $value = trim((string) $value); return $value !== '' ? __($value) : ''; }; @endphp @component('components.breadcrumb') @slot('li_1') {{ __('Documents') }} @endslot @slot('li_2') {{ $requestItem->document_name }} @endslot @slot('title') {{ __('Comments') }} @endslot @endcomponent @if(session('success')) @endif {{-- Page title bar --}}
{{ $backLabel }}
{{ __(\App\Models\RequesterRequest::workflowLabel($currentState)) }}
{{ __('Submitted by') }} {{ $requestItem->submitter_label ?: 'N/A' }} • {{ \App\Support\DateFormatter::localized($requestItem->created_at, 'F j, Y') }}
{{-- Split pane --}}
{{-- LEFT: document preview --}}
V1 {{ $originalVersionName }} {{ __('Document Version Control') }}
@if(true)
{{ __('Document Version Control') }}
@if($mainFile && $mainFile['exists'] && $isPdfPreview)
@elseif($mainFile && $mainFile['exists'] && $isImagePreview)
{{ __('Document') }}
@elseif($mainFile && $mainFile['exists'])

{{ strtoupper($ext) }} — {{ __('No inline preview available.') }}

{{ __('Download to View') }}
@elseif(!empty($builderTemplateUrl) && $builderTemplateIsImage) @php $overlayFields = collect($builderSchemaFields) ->filter(fn ($field) => is_array($field) && !empty($field['name'])) ->values(); @endphp
{{ __('Template preview') }} @foreach($overlayFields as $field) @php $fieldName = trim((string) ($field['name'] ?? '')); $fieldType = strtolower(trim((string) ($field['type'] ?? 'text'))); $rawValue = $builderSubmittedData[$fieldName] ?? null; $position = is_array($field['position'] ?? null) ? $field['position'] : $field; $x = is_numeric($position['x'] ?? null) ? (float) $position['x'] : 0.1; $y = is_numeric($position['y'] ?? null) ? (float) $position['y'] : 0.1; $w = is_numeric($position['width'] ?? null) ? (float) $position['width'] : 0.24; $h = is_numeric($position['height'] ?? null) ? (float) $position['height'] : 0.07; $x = max(0, min(0.95, $x)); $y = max(0, min(0.95, $y)); $w = max(0.06, min(0.85, $w)); $h = max(0.015, min(0.35, $h)); $savedFontSize = is_numeric(data_get($field, 'font_size')) ? (int) data_get($field, 'font_size') : null; $computedFontSize = $savedFontSize ?: max(10, min(22, (int) round($h * 110))); $isSignature = is_string($rawValue) && str_starts_with($rawValue, 'data:image/'); $displayValue = is_bool($rawValue) ? ($rawValue ? '✓' : '☐') : (is_scalar($rawValue) ? (string) $rawValue : ''); if ($displayValue === 'check' && !$isSignature) { $displayValue = '✓'; } elseif ($displayValue === 'uncheck' && !$isSignature) { $displayValue = '☐'; } elseif ($displayValue === '1' && !$isSignature) { $displayValue = '✓'; } elseif ($displayValue === '0' && !$isSignature) { $displayValue = '☐'; } $shouldRenderText = in_array($fieldType, ['text', 'date', 'checkbox'], true) && $displayValue !== ''; @endphp @if($isSignature)
{{ __('Signature') }}
@elseif($shouldRenderText)
{{ $displayValue }}
@endif @endforeach
@elseif(!empty($builderTemplateUrl))
@else

{{ __('No document file attached.') }}

@endif
@else
@if($mainFile && $mainFile['exists'] && $isPdfPreview)
@elseif($mainFile && $mainFile['exists'] && $isImagePreview)
{{ __('Document') }}
@elseif($mainFile && $mainFile['exists'])

{{ strtoupper($ext) }} — {{ __('No inline preview available.') }}

{{ __('Download to View') }}
@elseif(!empty($builderTemplateUrl) && $builderTemplateIsImage) @php $overlayFields = collect($builderSchemaFields) ->filter(fn ($field) => is_array($field) && !empty($field['name'])) ->values(); @endphp
{{ __('Template preview') }} @foreach($overlayFields as $field) @php $fieldName = trim((string) ($field['name'] ?? '')); $fieldType = strtolower(trim((string) ($field['type'] ?? 'text'))); $rawValue = $builderSubmittedData[$fieldName] ?? null; $position = is_array($field['position'] ?? null) ? $field['position'] : $field; $x = is_numeric($position['x'] ?? null) ? (float) $position['x'] : 0.1; $y = is_numeric($position['y'] ?? null) ? (float) $position['y'] : 0.1; $w = is_numeric($position['width'] ?? null) ? (float) $position['width'] : 0.24; $h = is_numeric($position['height'] ?? null) ? (float) $position['height'] : 0.07; $x = max(0, min(0.95, $x)); $y = max(0, min(0.95, $y)); $w = max(0.06, min(0.85, $w)); $h = max(0.015, min(0.35, $h)); $savedFontSize = is_numeric(data_get($field, 'font_size')) ? (int) data_get($field, 'font_size') : null; $computedFontSize = $savedFontSize ?: max(10, min(22, (int) round($h * 110))); $isSignature = is_string($rawValue) && str_starts_with($rawValue, 'data:image/'); $displayValue = is_bool($rawValue) ? ($rawValue ? '✓' : '☐') : (is_scalar($rawValue) ? (string) $rawValue : ''); if ($displayValue === 'check' && !$isSignature) { $displayValue = '✓'; } elseif ($displayValue === 'uncheck' && !$isSignature) { $displayValue = '☐'; } elseif ($displayValue === '1' && !$isSignature) { $displayValue = '✓'; } elseif ($displayValue === '0' && !$isSignature) { $displayValue = '☐'; } $shouldRenderText = in_array($fieldType, ['text', 'date', 'checkbox'], true) && $displayValue !== ''; @endphp @if($isSignature)
{{ __('Signature') }}
@elseif($shouldRenderText)
{{ $displayValue }}
@endif @endforeach
@elseif(!empty($builderTemplateUrl))
@else

{{ __('No document file attached.') }}

@endif
@endif
{{-- Resizer handle --}} {{-- RIGHT: comment thread --}}
{{ __('Comments & Actions') }} {{ $commentEntries->count() }}
@include('document-viewer.partials.review-workflow-actions')
@forelse($commentEntries as $entry)
{!! $userAvatarHtml($entry->actor ?? null) !!}

{{ $entry->actor->name ?? __('System') }} @php $entryRole = strtolower((string) ($entry->actor_role ?? '')); @endphp

{{ $commentDateTime($entry->created_at) }} @if((int) ($entry->actor_user_id ?? 0) === $currentUserId) @endif

{{ $translateSystemText($entry->note) }}

@php $entryAttachment = data_get($entry->meta, 'attachment'); @endphp @if(is_array($entryAttachment) && !empty($entryAttachment['url']))
{{ $entryAttachment['name'] ?? __('Attached document') }}
{{ $entryAttachment['size_label'] ?? '' }}
@endif
{{-- Replies --}}
replies->isEmpty() ? ' style="display:none;"' : '' }}> @foreach($entry->replies as $reply)
{!! $userAvatarHtml($reply->actor ?? null) !!}

{{ $reply->actor->name ?? __('System') }} @php $replyRole = strtolower((string) ($reply->actor_role ?? '')); @endphp

{{ $commentDateTime($reply->created_at) }} @if((int) ($reply->actor_user_id ?? 0) === $currentUserId) @endif

{{ $translateSystemText($reply->note) }}

@php $replyAttachment = data_get($reply->meta, 'attachment'); @endphp @if(is_array($replyAttachment) && !empty($replyAttachment['url']))
{{ $replyAttachment['name'] ?? __('Attached document') }}
{{ $replyAttachment['size_label'] ?? '' }}
@endif
@endforeach
{{-- Reply toggle + form --}} @if($canComment)
@endif
@empty

{{ __('No comments yet. Be the first to comment.') }}

@endforelse
@if($canComment)
@csrf
@else
{{ __('You can view comments but cannot post on this document.') }}
@endif
@endsection @section('script') @include('document-viewer.partials.workflow-action-undo') @include('document-viewer.partials.registry-forward-warning-script') @endsection