@extends('layouts.app') @section('title', __('app.teacher.chats.title') . ' - ' . config('app.name', 'CurioGPT')) @section('content')

{{ __('app.teacher.chats.title') }}

@if (request()->filled('q')) Clear @endif
@if ($conversations->isEmpty())

{{ __('app.teacher.chats.no_chats_yet') }}

@else
@foreach ($conversations as $conversation)

{{ $conversation->student_name ?? __('app.common.unknown_student') }}

@php $search = request('q'); $highlightHtml = null; if (!empty($search)) { $candidate = $conversation->match_message ?? null; if (is_string($candidate) && $candidate !== '') { $lines = preg_split("/(\r\n|\n|\r)/", $candidate) ?: []; $line = collect($lines)->first(function ($ln) use ($search) { return stripos($ln, $search) !== false; }); $line = $line ?? ($lines[0] ?? ''); $escaped = e($line); $pattern = '/' . preg_quote($search, '/') . '/i'; $highlightHtml = preg_replace( $pattern, '$0', $escaped ); } else { $titleEscaped = e($conversation->title ?? ''); $pattern = '/' . preg_quote($search, '/') . '/i'; $highlightHtml = preg_replace( $pattern, '$0', $titleEscaped ); } } @endphp @if (!empty($search))

{!! $highlightHtml !!}

@else

{{ $conversation->title }}

@endif
@if ($conversation->agent_name) {{ $conversation->agent_name }} @else {{ __('app.common.no_agent') }} @endif

{{ \Carbon\Carbon::parse($conversation->updated_at)->diffForHumans() }}

@endforeach
{{ $conversations->withQueryString()->links() }}
@endif
@endsection