@extends ('layouts/empty')

@section('content')
<div class="mcp-theme-1">
    <div class="card-body">

        <div class="mcp-theme-1">

            <div class="card">
                <div class="card-body p-0">

                    <table class="table table-sm table-striped p-0 m-0">
                        <thead class="bg-light">
                            <tr>
                                <th class="border-0">Created At</th>
                                <th class="border-0">Patient</th>
                                <th class="border-0">Insurance</th>
                                <th class="border-0">State</th>
                                <th class="border-0">MCP</th>
                                <th class="border-0">Def. MCP CP</th>
                                <th class="border-0">Def. MCP<br>Company Pro Payer</th>
                                <th class="border-0">Def. MCP<br>Company Location</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($rows as $row)
                            <tr>
                                <td>{{ friendly_date_time($row->created_at, true) }}</td>
                                <td>
                                    <a native target="_blank" href="/patients/view/{{ $row->uid }}">{{ $row->displayName() }}</a>
                                </td>
                                <td>
                                    <?php $_cpc = $row->getPrimaryCoverage();?>
                                    @if($_cpc && $row->getPrimaryCoverageStatus() === 'YES')
                                        {{$_cpc->insuranceDisplayPayerName()}}
                                    @else
                                        No
                                    @endif
                                </td>
                                <td>
                                    {{$row->mailing_address_state}}
                                </td>
                                <td>{{ $row->mcp ? $row->mcp->displayName() : '-' }}</td>
                                <td>
                                    <div>
                                        <b>{{$row->default_mcp_company_pro_id? $row->defaultMcpCompanyPro->company->name:'-'}}</b>
                                        @if($row->default_mcp_company_pro_id)
                                            <div moe bottom relative class="ml-1">
                                                <a start show><i class="fa fa-times text-danger"></i></a>
                                                <form url="/api/client/wipeDefaultMcpCompanyPro"
                                                      class="mcp-theme-1 min-width-200px" right>
                                                    <input type="hidden" name="uid" value="{{$row->uid}}">
                                                    <p>Remove default MCP company pro?</p>
                                                    <div>
                                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                                    </div>
                                                </form>
                                            </div>
                                        @elseif($row->mcp)
                                            <div moe bottom relative class="ml-2">
                                                <a start show>Edit</a>
                                                <form url="/api/client/putDefaultMcpCompanyPro"
                                                      class="mcp-theme-1  min-width-200px" right>
                                                    <input type="hidden" name="uid" value="{{$row->uid}}">
                                                    <div class="mb-2">
                                                        <label class="text-sm text-secondary mb-1">Company</label>
                                                        <select name="defaultMcpCompanyProUid" class="form-control form-control-sm">
                                                            <option value="">-- select --</option>
                                                            @foreach($row->mcp->companyPros as $companyPro)
                                                                <option value="{{$companyPro->uid}}">{{$companyPro->company->name}}</option>
                                                            @endforeach
                                                        </select>
                                                    </div>
                                                    <div>
                                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                                    </div>
                                                </form>
                                            </div>
                                        @endif
                                    </div>
                                </td>
                                <td>
                                    @if($row->defaultMcpCompanyPro)
                                        <div>
                                            <b>{{$row->default_mcp_company_pro_payer_id? $row->defaultMcpCompanyProPayer->payer->name:'No'}}</b>
                                            @if($row->default_mcp_company_pro_payer_id)
                                                <div moe bottom relative class="ml-1">
                                                    <a start show><i class="fa fa-times text-danger"></i></a>
                                                    <form url="/api/client/wipeDefaultMcpCompanyProPayer"
                                                          class="mcp-theme-1 min-width-200px" right>
                                                        <input type="hidden" name="uid" value="{{$row->uid}}">
                                                        <p>Remove default MCP company pro payer?</p>
                                                        <div>
                                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @else
                                                <div moe bottom relative class="ml-2">
                                                    <a start show>Edit</a>
                                                    <form url="/api/client/putDefaultMcpCompanyProPayer"
                                                          class="mcp-theme-1  min-width-200px" right>
                                                        <input type="hidden" name="uid" value="{{$row->uid}}">
                                                        <div class="mb-2">
                                                            <label class="text-sm text-secondary mb-1">Payer</label>
                                                            <select name="defaultMcpCompanyProPayerUid" class="form-control form-control-sm">
                                                                <option value="">-- select --</option>
                                                                @foreach($row->defaultMcpCompanyPro->companyProPayers as $companyProPayer)
                                                                    <option value="{{$companyProPayer->uid}}">{{$companyProPayer->payer->name}}</option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                        <div>
                                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @endif
                                        </div>
                                    @endif
                                </td>
                                <td>
                                    @if($row->defaultMcpCompanyPro)
                                        <div>
                                            <b>{{$row->default_mcp_company_location_id? implode(" ", [$row->defaultMcpCompanyLocation->line1, $row->defaultMcpCompanyLocation->city, $row->defaultMcpCompanyLocation->state]):'No'}}</b>
                                            @if($row->default_mcp_company_location_id)
                                                <div moe bottom relative class="ml-1">
                                                    <a start show><i class="fa fa-times text-danger"></i></a>
                                                    <form url="/api/client/wipeDefaultMcpCompanyLocation"
                                                          class="mcp-theme-1 min-width-200px" right>
                                                        <input type="hidden" name="uid" value="{{$row->uid}}">
                                                        <p>Remove default MCP company location?</p>
                                                        <div>
                                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @else
                                                <div moe bottom relative class="ml-2">
                                                    <a start show>Edit</a>
                                                    <form url="/api/client/putDefaultMcpCompanyLocation"
                                                          class="mcp-theme-1  min-width-200px" right>
                                                        <input type="hidden" name="uid" value="{{$row->uid}}">
                                                        <div class="mb-2">
                                                            <label class="text-sm text-secondary mb-1">Location</label>
                                                            <select name="defaultCompanyLocationUid" class="form-control form-control-sm">
                                                                <option value="">-- select --</option>
                                                                @foreach($row->defaultMcpCompanyPro->company->locations as $location)
                                                                    <option value="{{$location->uid}}">
                                                                        {{implode(" ", [$location->line1, $location->city, $location->state])}}
                                                                    </option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                        <div>
                                                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @endif
                                        </div>
                                    @endif
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                    <div class="pt-3 px-3">
                        {{ $rows->links() }}
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
@endsection