@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>
                Care Months
            </strong>
        </div>

        <div class="card-body p-0">
            <!-- <div class="p-3">
                Filter
            </div> -->
            <table class="table table-sm table-stripped p-0 m-0">
                <thead class="bg-light">
                    <tr>
                        <th class="border-0">Chart #</th>
                        <th class="border-0">Care Month</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">MCP</th>
                        <th class="border-0"># Meas. this mt.</th>
                        <th class="border-0">My Bill</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($careMonths as $careMonth)
                    <tr>

                        <td class="text-nowrap">
                            <a native target="_blank" href="{{route('patients.view.dashboard', $careMonth->client)}}">
                                {{$careMonth->client->chart_number}}
                            </a>
                        </td>
                        <td class="text-nowrap">
                            <a native target="_blank" href="{{route('patients.view.care-months.view.dashboard', ['patient' => $careMonth->client, 'careMonth' => $careMonth])}}">
                                {{friendly_month($careMonth->start_date)}}
                            </a>
                        </td>
                        <td class="text-nowrap">
                            {{$careMonth->client->displayName()}}
                        </td>
                        <td class="text-nowrap">{{ friendly_date_time($careMonth->client->dob, false) }}</td>
                        <td>{{ $careMonth->client->age_in_years ?  $careMonth->client->age_in_years : '-' }}</td>
                        <td>{{ $careMonth->client->sex }}</td>
                        <td>
                            <?php $coverageStatus = $careMonth->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 = $careMonth->client->getPrimaryCoverage(); ?>
                                @if($coverage)
                                {{$coverage->insuranceDisplayName()}}
                                @endif
                            </div>
                        </td>
                        <td>{{ $careMonth->mcp ? $careMonth->mcp->displayName() : '--' }}</td>
                        <td>{{ $careMonth->number_of_days_with_remote_measurements }}</td>
                        <td>
                            <?php $bill = $careMonth->rmBill; ?>
                            @if($bill)
                            <div class="d-flex flex-column">
                                <span>Code: {{ $bill->code }}</span>
                                <a href="/patients/view/{{ $bill->careMonth->client->uid }}/notes/view/{{ $bill->careMonth->uid }}">Note</a>
                            </div>
                            @endif
                        </td>
                    </tr>
                    @endforeach

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

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