@extends('layouts.app')
@section('title', __('clinicSite::lang.messages'))

@section('content')
<section class="content-header">
    <h1><i class="fas fa-inbox"></i> {{ __('clinicSite::lang.messages') }}
        <small>Contact-form leads from your website</small></h1>
</section>

<section class="content">
    @include('clinicSite::admin._flash')
    <div class="row"><div class="col-md-12">
        @component('components.widget', ['class' => 'box-primary'])
            <table class="table table-hover">
                <thead><tr><th></th><th>Name</th><th>Contact</th><th>Subject</th><th>Received</th><th></th></tr></thead>
                <tbody>
                @forelse($messages as $m)
                    <tr style="{{ $m->is_read ? '' : 'font-weight:600;background:#f6fbff;' }}">
                        <td>@if(!$m->is_read)<span class="label label-info">New</span>@endif</td>
                        <td>{{ $m->name }}</td>
                        <td>
                            @if($m->email)<a href="mailto:{{ $m->email }}">{{ $m->email }}</a><br>@endif
                            @if($m->phone)<small>{{ $m->phone }}</small>@endif
                        </td>
                        <td>{{ \Illuminate\Support\Str::limit($m->subject ?: $m->message, 40) }}</td>
                        <td><small>{{ $m->created_at->diffForHumans() }}</small></td>
                        <td class="text-right">
                            <a href="{{ route('cs.messages.show', $m->id) }}" class="btn btn-xs btn-primary">Open</a>
                            <form method="POST" action="{{ route('cs.messages.destroy', $m->id) }}" style="display:inline" onsubmit="return confirm('Delete?')">@csrf @method('DELETE')
                                <button class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button></form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="text-center text-muted" style="padding:24px;">No messages yet.</td></tr>
                @endforelse
                </tbody>
            </table>
            {{ $messages->links() }}
        @endcomponent
    </div></div>
</section>
@endsection
