@extends('layouts.worker') @section('title', \App\Helpers\TranslationHelper::getUserTranslations()['translations']['intervention_details']['title'] ?? 'Détails de l\'intervention') @push('styles') @endpush @section('content')
{{-- Bouton de retour --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['back_to_interventions'] ?? 'Retour aux interventions' }}
{{-- En-tête avec numéro d'intervention, logo client, nom client et date --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['intervention_details']['intervention_number'] ?? 'INTERVENTION Nº' }}{{ $intervention->id }}
{{ $intervention->client_name }}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['intervention_details']['intervention_date'] ?? 'Date d\'intervention' }}
@if($intervention->intervention_date) {{ $intervention->intervention_date->locale('fr')->isoFormat('dddd D/MM/YYYY') }} @php $today = \Carbon\Carbon::today(); $interventionDate = \Carbon\Carbon::parse($intervention->intervention_date)->startOfDay(); $diffInDays = $today->diffInDays($interventionDate, false); $status = $intervention->status; @endphp @if($status === \App\Enums\InterventionStatus::COMPLETED->value) {{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['status_completed'] ?? '(terminée)' }} @elseif($status === \App\Enums\InterventionStatus::IN_PROGRESS->value) ({{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['today'] ?? 'aujourd\'hui' }}) @elseif($diffInDays === 0) ({{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['today'] ?? 'aujourd\'hui' }}) @elseif($diffInDays < 0) @php $daysLate = abs($diffInDays); $pluralS = $daysLate > 1 ? 's' : ''; $lateTpl = \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['days_ago'] ?? '%days% jour%s% en retard'; $lateText = str_replace(['%days%', '%s%'], [$daysLate, $pluralS], $lateTpl); @endphp ({{ $lateText }}) @elseif($diffInDays > 0) @php $daysFuture = $diffInDays; $pluralS = $daysFuture > 1 ? 's' : ''; $futureTpl = \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['in_days'] ?? 'dans %days% jour%s%'; $futureText = str_replace(['%days%', '%s%'], [$daysFuture, $pluralS], $futureTpl); @endphp ({{ $futureText }}) @endif @else {{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['intervention_details']['not_defined'] ?? 'Non définie' }} @endif
{{-- Adresse --}}

{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['intervention_address'] ?? 'Adresse d\'intervention' }}

{{ $intervention->address ?? \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['address_not_provided'] ?? 'Adresse non renseignée' }}

@if($intervention->client && $intervention->client->primaryAddress)

@if($intervention->client->primaryAddress->floor) {{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['floor_label'] ?? 'Étage' }}: {{ $intervention->client->primaryAddress->floor }}@endif @if($intervention->client->primaryAddress->side) {{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['side_label'] ?? 'Côté' }}: {{ $intervention->client->primaryAddress->side }}@endif

@endif
{{-- Séparateur horizontal --}}
@php // Utiliser directement la valeur de priorité depuis la base de données $dbPriority = $intervention->priority; // Déterminer la classe CSS, le texte et l'icône en fonction de la priorité $priorityClass = match($dbPriority) { 'urgent' => 'priority-badge--urgent', 'normal', 'low' => 'priority-badge--normal', default => 'priority-badge--normal' }; $priorityText = match($dbPriority) { 'urgent' => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['priority_urgent'] ?? 'Urgent', 'normal' => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['priority_normal'] ?? 'Normal', 'low' => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['priority_low'] ?? 'Faible', default => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['priority_normal'] ?? 'Normal' }; $priorityIcon = match($dbPriority) { 'urgent' => 'fa-exclamation-triangle', 'normal' => 'fa-check-circle', 'low' => 'fa-arrow-down', default => 'fa-check-circle' }; @endphp {{ $priorityText }}
@php $status = $intervention->status; $statusClass = match($status) { \App\Enums\InterventionStatus::IN_PROGRESS->value => 'status-badge--in_progress', \App\Enums\InterventionStatus::PLANNED->value => 'status-badge--planned', \App\Enums\InterventionStatus::COMPLETED->value => 'status-badge--completed', \App\Enums\InterventionStatus::LATE->value => 'status-badge--late', default => 'status-badge--planned' }; $statusText = match($status) { \App\Enums\InterventionStatus::IN_PROGRESS->value => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['status_in_progress'] ?? 'En cours', \App\Enums\InterventionStatus::PLANNED->value => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['status_planned'] ?? 'Planifiée', \App\Enums\InterventionStatus::LATE->value => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['status_late'] ?? 'En retard', \App\Enums\InterventionStatus::COMPLETED->value => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['status_completed'] ?? 'Terminée', default => \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['status_planned'] ?? 'Planifiée' }; $statusIcon = match($status) { \App\Enums\InterventionStatus::IN_PROGRESS->value => 'fa-clock', \App\Enums\InterventionStatus::PLANNED->value => 'fa-calendar-days', \App\Enums\InterventionStatus::COMPLETED->value => 'fa-check', \App\Enums\InterventionStatus::LATE->value => 'fa-exclamation-triangle', default => 'fa-calendar-days' }; @endphp {{ $statusText }}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['intervention_title'] ?? 'Titre de l\'intervention' }}
{{ $intervention->title }}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['intervention_description'] ?? 'Description de l\'intervention' }}
{{ $intervention->description ?? \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['no_description_available'] ?? 'Aucune description disponible' }}
{{-- Bouton de traduction --}}
{{-- Carte de l'équipe --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['assigned_team'] ?? 'Équipe assignée' }}
@if($intervention->workers && $intervention->workers->count() > 0)
@foreach($intervention->workers as $worker)
{{ strtoupper(substr($worker->first_name ?? '', 0, 1) . substr($worker->last_name ?? '', 0, 1)) }}
{{ $worker->first_name ?? '' }} {{ $worker->last_name ?? '' }}
@endforeach
@else

{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['no_workers_assigned'] ?? 'Aucun intervenant assigné à cette intervention.' }}

@endif
{{-- Carte des médias --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['media']['title'] ?? 'Médias' }}
{{-- Photos de l'administrateur --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['media']['admin_photos'] ?? 'Photos de l\'administrateur' }}
@if($adminPhotos->count() > 0)
@foreach($adminPhotos as $photo) @php $fileExtension = strtolower(pathinfo($photo->file_path, PATHINFO_EXTENSION)); $isVideo = in_array($fileExtension, ['mp4', 'mov', 'avi', 'webm', 'mkv', 'm4v', '3gp', 'flv', 'wmv']); @endphp @endforeach
@else

{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['media']['no_admin_media'] ?? 'Aucun média de l\'administrateur.' }}

@endif

{{-- Photos du worker --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['media']['worker_photos'] ?? 'Vos photos' }}
@csrf
@if($workerPhotos->count() > 0)
@foreach($workerPhotos as $photo) @php $fileExtension = strtolower(pathinfo($photo->file_path, PATHINFO_EXTENSION)); $isVideo = in_array($fileExtension, ['mp4', 'mov', 'avi', 'webm', 'mkv', 'm4v', '3gp', 'flv', 'wmv']); @endphp @endforeach
@else

{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['media']['no_worker_media'] ?? 'Vous n\'avez pas encore ajouté de média.' }}

@endif
{{-- Carte des commentaires --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['comments']['title'] ?? 'Commentaires' }}
{{-- Liste des commentaires existants --}}
@php // Décoder manuellement le JSON si nécessaire $comments = $intervention->comments; if (is_string($comments)) { $comments = json_decode($comments, true); } if (!is_array($comments)) { $comments = []; } @endphp @if(count($comments) > 0) @foreach($comments as $comment) @php // Vérifications de sécurité pour les champs manquants $authorType = $comment['author_type'] ?? 'worker'; $author = $comment['author'] ?? \App\Helpers\TranslationHelper::getUserTranslations()['translations']['comments']['unknown_user'] ?? 'Utilisateur inconnu'; $authorId = $comment['author_id'] ?? null; $commentId = $comment['id'] ?? ''; $commentText = $comment['text'] ?? ''; $commentDate = $comment['date'] ?? $comment['created_at'] ?? null; @endphp
@if($authorType === 'worker') @php // Extraire les initiales du nom de l'auteur $nameParts = explode(' ', $author); $initials = ''; foreach ($nameParts as $part) { if (!empty($part)) { $initials .= mb_substr($part, 0, 1, 'UTF-8'); } } // Limiter à 2 caractères maximum $initials = mb_substr($initials, 0, 2, 'UTF-8'); @endphp {{ $initials }} @else @endif
{{ $author }} {{ $authorType === 'worker' ? \App\Helpers\TranslationHelper::getUserTranslations()['translations']['comments']['worker_role'] ?? 'Intervenant' : \App\Helpers\TranslationHelper::getUserTranslations()['translations']['comments']['admin_role'] ?? 'Administrateur' }} @if($commentDate) {{ \Carbon\Carbon::parse($commentDate)->locale('fr')->format('d/m/Y H:i') }} @endif
{{ $commentText }}
@if($authorType === 'worker' && $authorId && $authorId == Auth::user()->id) @endif
@endforeach @else

{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['comments']['no_comments_yet'] ?? 'Aucun commentaire pour le moment. Commencez la conversation !' }}

@endif
{{-- Formulaire d'ajout de commentaire (toujours visible, HORS de la structure existante) --}}
@csrf @method('PUT')
@php // Extraire les initiales du nom de l'utilisateur connecté $userName = auth()->user()->prenom . ' ' . auth()->user()->nom; $nameParts = explode(' ', $userName); $initials = ''; foreach ($nameParts as $part) { if (!empty($part)) { $initials .= mb_substr($part, 0, 1, 'UTF-8'); } } // Limiter à 2 caractères maximum $initials = mb_substr($initials, 0, 2, 'UTF-8'); @endphp {{ $initials }}
{{-- Carte des actions --}}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['actions_title'] ?? 'Actions' }}
{{ \App\Helpers\TranslationHelper::getUserTranslations()['translations']['interventions']['completed_by_label'] ?? 'Intervention terminée par :' }}
@if($intervention->finished_by) @php $finishedByUser = \App\Models\User::find($intervention->finished_by); @endphp {{ $finishedByUser ? $finishedByUser->prenom . ' ' . $finishedByUser->nom : (\App\Helpers\TranslationHelper::getUserTranslations()['translations']['comments']['unknown_user'] ?? 'Utilisateur inconnu') }} @endif
{{ $intervention->finished_at ? \Carbon\Carbon::parse($intervention->finished_at)->format('d/m/Y H:i') : '' }}
@endsection @push('scripts') @endpush