@extends ('layouts/template')

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

        <div class="card-header px-2 py-1 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-weight"></i>
                Clients BDT Devices
            </strong>
        </div>

        <div class="card-body p-0">
            <div class="p-3">
                @include('app.mcp.clients_bdt_devices_filters')
            </div>
            <table class="table table-sm table-striped border-top p-0 m-0">
                <thead class="bg-light">
                    <tr>
                        <th class="border-0">IMEI</th>
                        <th class="border-0">Client</th>
                        <th class="border-0">Created</th>
                        <th class="border-0">Category</th>
                        <th class="border-0">Last Measurement</th>
                        <th class="border-0">Status</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($devices as $device)
                    <tr>
                        <td>
                            <pre class="m-0">{{ $device->device->imei }}</pre>
                        </td>
                        <td>
                            <a target="_blank" native href="{{route('patients.view.dashboard', $device->client)}}">
                                {{$device->client->displayName()}}
                            </a>
                        </td>
                        <td class="text-nowrap">{{ friendly_date_time($device->device->created_at) }}</td>
                        <td>{{ $device->device->category }}</td>
                        <td class="d-flex align-items-center">
                            <?php $lastMeasurement = $device->lastDeviceMeasurement(); ?>
                            @if($lastMeasurement)
                            @if($lastMeasurement->is_cellular_zero)
                            <i class="font-size-11 fa fa-rss"></i>
                            @elseif($lastMeasurement->label === 'BP')
                            {{ $lastMeasurement->sbp_mm_hg }} / {{ $lastMeasurement->dbp_mm_hg }}
                            @elseif($lastMeasurement->label === 'Wt. (lbs.)')
                            {{ round($lastMeasurement->numeric_value, 2) }} lbs
                            @else
                            {{ $lastMeasurement->value }}
                            @endif
                            <div class="ml-2">
                                <i class="far fa-calendar-check"></i> <span class="text-secondary">{{ friendly_date_time($lastMeasurement->created_at) }}</span>
                            </div>
                            @else
                            <small class="text-muted">-</small>
                            @endif
                        </td>
                        <td>
                            @if($device->is_active)
                            <span class="text-success">Active</span>
                            @else
                            <span class="text-danger">Deactivated</span>
                            @endif
                        </td>
                    </tr>
                    @endforeach

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

            </table>

        </div>
    </div>
    <div class="mt-3">
        {{ $devices->appends(request()->input())->links() }}
    </div>
</div>
@endsection