@extends ('layouts.patient')
@section('inner-content')
    <div class="">
        <div class="d-flex align-items-center pb-2">
            <h4 class="font-weight-bold m-0">Pros With Access</h4>
            <div class="d-inline ml-2">
                <div moe>
                    <a show href="" start>Add Client Pro Access</a>
                    <form action="" url="/api/clientProAccess/create">
                        <input type="hidden" value="{{$patient->uid}}" name="clientUid">
                        <div class="form-group">
                            <label for="" class="control-label">Pro</label>
                            <select provider-search name="proUid" id="" class="form-control input-sm">
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="" class="control-label">Reason category</label>
                            <input type="text" name="reasonCategory" class="form-control input-sm">
                        </div>
                        <div class="form-group">
                            <label for="" class="control-label">Reason memo</label>
                            <textarea name="reasonMemo" class="form-control input-sm"></textarea>
                        </div>
                        <div class="form-group">
                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                            <button class="btn btn-danger btn-sm" cancel>Cancel</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <table class="table table-striped table-sm table-bordered mb-0">
            @php $prosWithAccess = $patient->prosWithAccess(); @endphp
            @if($prosWithAccess && count($prosWithAccess))
                <thead class="bg-light">
                <tr>
                    <th class="border-0 text-secondary">Pro</th>
                    <th class="border-0 text-secondary w-75">Association</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                @php $prevPro = ''; @endphp
                @foreach($prosWithAccess as $aPro)
                    <tr>
                        @if($pro->pro_type === 'ADMIN')
                            <td class="{{ $aPro['pro'] !== $prevPro ? 'font-weight-bold' : 'text-secondary' }}">{{ $aPro['pro'] }}</td>
                            <td>{{ $aPro['association'] }}</td>
                            <td>
                                @if(isset($aPro['isClientProAccess']))
                                <div moe>
                                    <a href="" show start>Update Reason</a>
                                    <form action="" url="/api/clientProAccess/updateReason">
                                        <input type="hidden" value="{{$aPro['clientProAccess']->uid}}" name="uid">

                                        <div class="form-group">
                                            <label for="" class="control-label">Reason category</label>
                                            <input type="text" name="reasonCategory" class="form-control input-sm" value="{{$aPro['clientProAccess']->reason_category}}">
                                        </div>
                                        <div class="form-group">
                                            <label for="" class="control-label">Reason memo</label>
                                            <textarea name="reasonMemo" class="form-control input-sm">{{$aPro['clientProAccess']->reason_memo}}</textarea>
                                        </div>
                                        <div class="form-group">
                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                            <button class="btn btn-danger btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                                <div moe>
                                    <a href="" show start>Remove</a>
                                    <form action="" url="/api/clientProAccess/deactivate">
                                        <input type="hidden" value="{{$aPro['clientProAccess']->uid}}" name="uid">

                                        <div class="form-group">
                                            <label for="" class="control-label">Memo</label>
                                            <textarea name="deactivationMemo" class="form-control input-sm"></textarea>
                                        </div>
                                        <div class="form-group">
                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                            <button class="btn btn-danger btn-sm" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                                @endif
                            </td>
                        @else
                            @if($aPro['pro'] !== $prevPro)
                                <td class="{{ $aPro['pro'] !== $prevPro ? 'font-weight-bold' : 'text-secondary' }}">{{ $aPro['pro'] }}</td>
                                <td>{{ $aPro['association'] }}</td>
                                <td></td>
                            @endif
                        @endif
                        @php $prevPro = $aPro['pro']; @endphp

                    </tr>
                @endforeach
                </tbody>
            @else
                <tbody>
                    <tr>
                        <td class="text-secondary p-3">No pros (other than admin pros) have access to this patient</td>
                    </tr>
                </tbody>
            @endif
        </table>
    </div>
@endsection
