@extends ('layouts/template')

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

            <div class="card-header px-2 py-1 d-flex align-items-center">
                <strong class="mr-4">
                    <i class="fas fa-user"></i>
                    Care Month Report: {{date('M Y', strtotime($date))}}
                </strong>
                <div class="ml-auto">
                    <input class="form-control" type="month" value="{{substr($date, 0, 7)}}" max="{{substr(date('Y-m-d'), 0, 7)}}" onchange="if(this.value){fastLoad('/pro-care-month-report?m=' + this.value.split('-')[1] + '&y=' + this.value.split('-')[0])}">
                </div>
            </div>

            <div class="card-body p-0 border-0">
                <table class="table table-sm table-striped p-0 m-0">
                    <thead class="bg-light">
                    <tr>
                        <th>Patient</th>
                        <th>Role</th>
                        <th># Days with measurements</th>
                        <?php /* <th>Last Measurement</th> */ ?>
                        <th># Minutes</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach ($records as $record)
                        <tr>
                            <td><a href="/patients/view/{{$record->client_uid}}/care-months/view/{{$record->care_month_uid}}">{{$record->client_name}}</a></td>
                            <td>{{$record->mcp_pro_id === $pro->id ? 'MCP' : ($record->rme_pro_id === $pro->id ? 'RME' : ($record->rmm_pro_id === $pro->id ? 'RMM' : '-'))}}</td>
                            <td>{{$record->number_of_days_with_remote_measurements}}</td>
                            <?php /* <td>
                                <?php
                                $lastMeasurement = \App\Models\Measurement::where('care_month_id', $record->care_month_id)
                                    ->whereNotNull('client_bdt_measurement_id')
                                    ->where('is_cellular_zero', FALSE)
                                    ->where('is_removed', FALSE)
                                    ->where('label', '!=', 'SBP')
                                    ->where('label', '!=', 'DBP')
                                    ->whereNotNull('ts')
                                    ->orderBy('ts', 'DESC')
                                    ->first();
                                ?>
                                @if(!!$lastMeasurement)
                                        @if($lastMeasurement->is_cellular_zero)
                                            <i class="font-size-11 fa fa-rss"></i>
                                        @elseif($lastMeasurement->label === 'BP')
                                            Wt. {{ $lastMeasurement->sbp_mm_hg }}/{{ $lastMeasurement->dbp_mm_hg }} mmHg
                                        @elseif($lastMeasurement->label === 'Wt. (lbs.)')
                                            BP. {{ round(floatval($lastMeasurement->numeric_value), 2) }} lbs
                                        @else
                                            {{$lastMeasurement->label}}. {{$lastMeasurement->value}}
                                        @endif
                                @else
                                    -
                                @endif
                            </td> */ ?>
                            <td>{{$record->mcp_pro_id === $pro->id ? $record->rm_total_time_in_seconds_by_mcp : ($record->rme_pro_id === $pro->id ? $record->rm_total_time_in_seconds_by_rme_pro : ($record->rmm_pro_id === $pro->id ? $record->rm_total_time_in_seconds_by_rmm_pro : '-'))}}</td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
