@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-calendar-alt"></i>
                Appointments
            </strong>
        </div>

        <div class="card-body p-0">
            <div class="p-3">
                @include('app.dna.appointments_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">Time</th>
                        <th class="border-0">Status</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($appointments as $appointment)
                    <tr>
                        <td class="text-nowrap">
                            <a native target="_blank" href="{{route('patients.view.dashboard', $appointment->client)}}">
                                {{$appointment->client->chart_number}}
                            </a>
                        </td>
                        <td class="text-nowrap">
                            <a native target="_blank" href="{{route('patients.view.dashboard', $appointment->client)}}">
                                {{$appointment->client->displayName()}}
                            </a>
                        </td>
                        <td class="text-nowrap">{{ friendly_date_time($appointment->client->dob, false) }}</td>
                        <td>{{ $appointment->client->age_in_years ?  $appointment->client->age_in_years : '-' }}</td>
                        <td>{{ $appointment->client->sex }}</td>
                        <td>
                            <?php $coverageStatus = $appointment->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 = $appointment->client->getPrimaryCoverage(); ?>
                                @if($coverage)
                                {{$coverage->insuranceDisplayName()}}
                                @endif
                            </div>
                        </td>
                        <td>{{ $appointment->pro->displayName() }}</td>
                        <td>
                            <a href="/patients/view/{{$appointment->client->uid}}/calendar/{{$appointment->uid}}" class="text-nowrap">
                                {{friendly_date($appointment->raw_date) . ' ' . friendly_time($appointment->raw_start_time)}}
                            </a>
                        </td>
                        <td class="px-2">
                            {{ $appointment->status }}
                            @if($appointment->status_memo)
                            <hr>
                            {{$appointment->status_memo}}
                            @endif
                        </td>
                    </tr>
                    @endforeach

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

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