@extends('layouts.app')
@section('title', __('medportal::lang.messages'))
@section('content')
<section class="content-header">
    <h1>@lang('medportal::lang.messages')</h1>
    <p>@lang('medportal::lang.messages_help')</p>
</section>
<section class="content">
    @component('components.widget', ['class' => 'box-primary'])
        <div class="mb-2" style="margin-bottom:12px;">
            <button class="btn btn-primary btn-sm mportal-modal-btn" data-href="{{ route('mportal.messages.create') }}">
                <i class="fa fa-plus"></i> @lang('medportal::lang.new_message')
            </button>
        </div>
        <div class="table-responsive">
            <table class="table table-bordered table-striped">
                <thead><tr>
                    <th>@lang('medportal::lang.patient')</th>
                    <th>@lang('medportal::lang.last_message')</th>
                    <th>@lang('medportal::lang.date')</th>
                    <th>@lang('medportal::lang.unread')</th>
                    <th class="text-right">@lang('medportal::lang.actions')</th>
                </tr></thead>
                <tbody>
                @forelse($threads as $t)
                    <tr>
                        <td>{{ $patientNames[$t->patient_id] ?? ('Patient #' . $t->patient_id) }}</td>
                        <td>{{ \Illuminate\Support\Str::limit($t->body, 60) }}</td>
                        <td>{{ optional($t->created_at)->format('Y-m-d H:i') }}</td>
                        <td>
                            @if($t->unread_count > 0)
                                <span class="label label-danger">{{ $t->unread_count }}</span>
                            @else
                                <span class="text-muted">0</span>
                            @endif
                        </td>
                        <td class="text-right">
                            <button class="btn btn-xs btn-primary mportal-modal-btn"
                                data-href="{{ route('mportal.messages.show', $t->thread_id) }}">
                                <i class="fa fa-comments"></i> @lang('medportal::lang.open')
                            </button>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="text-center text-muted">@lang('medportal::lang.no_threads')</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
        <div class="modal fade mportal_modal" tabindex="-1" role="dialog"></div>
    @endcomponent
</section>
@endsection
@section('javascript')
@include('medportal::partials.crud_scripts')
@endsection
