@extends ('layouts/template')

@section('content')
<div class="p-3 mcp-theme-1" id="patients-list">
    <div class="card">

        <div class="card-header px-3 py-2 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-notes-medical"></i>
                Encounters
            </strong>
        </div>

        <div class="card-body p-0">
            <div class="p-3">
                @include('app.dna.encounters_filters')
            </div>
            <table class="table table-sm table-striped p-0 m-0">
                <thead class="bg-light border-top">
                    <tr>
                        <th class="border-0">Chart #</th>
                        <th class="border-0">Name</th>
                        <th class="border-0">DOB</th>
                        <th class="border-0">Age</th>
                        <th class="border-0">Sex</th>
                        <th class="border-0">Insurance</th>
                        <th class="border-0">HCP</th>
                        <th class="border-0">Visit Date</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($notes as $note)
                    <tr class="{{ $note->is_cancelled ? 'cancelled-item always-clickable' : '' }}">
                        <td class="text-nowrap">
                            <a native target="_blank" href="{{route('patients.view.dashboard', $note->client)}}">
                                {{$note->client->chart_number}}
                            </a>
                        </td>
                        <td class="text-nowrap">
                            <a native target="_blank" href="{{route('patients.view.dashboard', $note->client)}}">
                                {{$note->client->displayName()}}
                            </a>
                        </td>
                        <td class="text-nowrap">{{ friendly_date_time($note->client->dob, false) }}</td>
                        <td>{{ $note->client->age_in_years ?  $note->client->age_in_years : '-' }}</td>
                        <td>{{ $note->client->sex }}</td>
                        <td>
                            <?php $coverageStatus = $note->client->getPrimaryCoverageStatus(); ?>
                            <div class="text-nowrap">
                                @if($coverageStatus === 'YES')
                                <i class="fa fa-check-circle text-success" data-toggle="tooltip" data-placement="bottom" title="Covered"></i>
                                @elseif($coverageStatus === 'NO')
                                <i class="fa fa-times text-danger" data-toggle="tooltip" data-placement="bottom" title="Not Covered"></i>
                                @else
                                <i class="fa fa-exclamation-triangle text-warning-mellow" data-toggle="tooltip" data-placement="bottom" title="Unknown"></i>
                                @endif
                                <?php $coverage = $note->client->getPrimaryCoverage(); ?>
                                @if($coverage)
                                {{$coverage->insuranceDisplayName()}}
                                @endif
                            </div>
                        </td>
                        <td>{{ $note->hcpPro ? $note->hcpPro->displayName() : '' }}</td>
                        <td class="px-2">
                            <a href="/patients/view/{{ $note->client->uid }}/notes/view/{{ $note->uid }}" class="font-weight-bold">
                                {{ friendly_date_time($note->effective_dateest, false) }}
                            </a>
                            @if(!!$note->visitTemplate)
                            <span class="text-info font-weight-bold">*</span>
                            @endif
                            <span class="ml-1">{{ $note->is_cancelled ? '[cancelled]' : '' }}</span>
                        </td>
                    </tr>
                    @endforeach

                    @if(count($notes) === 0)
                    <tr>
                        <td colspan="8">No records found!</td>
                    </tr>
                    @endif
                </tbody>

            </table>
            @if($notes->hasPages())
                <div class="ml-2 mt-2">
                    {{ $notes->appends(request()->input())->links() }}
                </div>
            @endif
        </div>
    </div>
</div>
@endsection