@extends ('layouts.patient')
<?php
/** @var \App\Models\Client $patient */
?>
@section('inner-content')
    <div class="">
        <div class="d-flex align-items-center pb-2">
            <h4 class="font-weight-bold m-0">ERx</h4>
            <span class="mx-2 text-secondary">|</span>
            <div moe>
                <a start show class="py-0 font-weight-normal">Add</a>
                <form url="/api/actionItem/create" wide>
                    <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                    <input type="hidden" name="prescriberProUid" value="{{ $pro->uid }}">
                    <input type="hidden" name="category" value="DRUG">
                    <div class="mb-2">
                        <label for="" class="control-label text-sm text-secondary mb-1">Pharmacy</label>
                        <select name="toFacilityUid"
                                class="form-control form-control-sm">
                            <option value="">-- Pharmacy --</option>
                            @foreach ($facilities as $facility)
                                <option value="{{$facility->uid}}">{{$facility->name}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="mb-2">
                        <input type="text" class="form-control form-control-sm" name="contentText" value="" placeholder="Title *" required>
                    </div>
                    <div class="mb-2">
                        <input type="text" class="form-control form-control-sm" name="contentDetail" value="" placeholder="Directions">
                    </div>
                    <div class="d-flex align-items-center">
                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                    </div>
                </form>
            </div>
        </div>
        <table class="table table-sm table-bordered mb-0" style="table-layout: fixed">
            <thead>
            <tr>
                <th class="px-2 text-secondary border-bottom-0">Pharmacy</th>
                <th class="px-2 text-secondary border-bottom-0 w-25">Action</th>
                <th class="px-2 text-secondary border-bottom-0">Created</th>
                <th class="px-2 text-secondary border-bottom-0">Status</th>
                <th class="px-2 text-secondary border-bottom-0">&nbsp;</th>
            </tr>
            </thead>
            <tbody>
            <?php $prevItemType = false; ?>
            @foreach($patient->actionItems as $item)
                @if($item->action_item_category === 'DRUG')
                <tr>
                    <td class="px-2">
                        {{$item->facility ? $item->facility->name : ''}}
                        <span moe>
                            <a start show class="on-hover-opaque"><i class="fa fa-edit"></i></a>
                            <form url="/api/actionItem/updateToFacility">
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <label for="" class="control-label text-sm text-secondary mb-1">Facility *</label>
                                    <select name="toFacilityUid" class="form-control form-control-sm" required>
                                        <option value="">-- Facility --</option>
                                        @foreach ($facilities as $facility)
                                            <option {{ $item->to_facility_id === $facility->id ? 'selected' : '' }} value="{{$facility->uid}}">{{$facility->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                    </td>
                    <td class="px-2">
                        {{$item->content_text}}
                        <span moe>
                            <a start show class="on-hover-opaque"><i class="fa fa-edit"></i></a>
                            <form url="/api/actionItem/updateContent" wide>
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="contentText" value="{{ $item->content_text }}" placeholder="Title *" required>
                                </div>
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="contentDetail" value="{{ $item->content_detail }}" placeholder="Details">
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        <div class="text-sm text-secondary">{{$item->content_detail}}</div>
                    </td>
                    <td class="px-2">{{friendly_date_time($item->created_at, false)}}</td>
                    <td class="px-2">
                        {{$item->status_category}}
                        <span moe>
                            <a start show class="on-hover-opaque"><i class="fa fa-edit"></i></a>
                            <form url="/api/actionItem/updateStatus">
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <label for="" class="control-label text-sm text-secondary mb-1">Status *</label>
                                    <select name="statusCategory" class="form-control form-control-sm" required>
                                        <option {{ $item->status_category === 'OPEN' ? 'selected' : '' }} value="OPEN">Open</option>
                                        <option {{ $item->status_category === 'CLOSED' ? 'selected' : '' }} value="CLOSED">Closed</option>
                                    </select>
                                </div>
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="statusMemo" value="" placeholder="Memo">
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                    </td>
                    <td class="px-2 text-center">
                        <div class="d-flex align-items-center justify-content-start">
                        @if($item->is_signed_by_prescriber)
                            <span class="text-secondary">
                                <i class="fa fa-check"></i>
                                Signed
                            </span>
                            <span class="mx-2 text-secondary">|</span>
                        @else
                            @if($pro->id === $item->prescriber_pro_id)
                                <span moe relative>
                                    <a start show>Sign</a>
                                    <form url="/api/actionItem/signAsPrescriber" right>
                                        <input type="hidden" name="uid" value="{{ $item->uid }}">
                                        <p class="small min-width-200px text-left">Sign this action items as the prescriber?</p>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-success mr-2" submit>Yes</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                        </div>
                                    </form>
                                </span>
                                <span class="mx-2 text-secondary">|</span>
                            @endif
                        @endif
                        <span moe relative>
                            <a start show>eFax</a>
                            <form url="/api/actionItem/efax" right>
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="toFaxNumber" value="" placeholder="To Number *" required>
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Send</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        </div>
                    </td>
                </tr>
                @endif
            @endforeach
            </tbody>
        </table>
    </div>

    <div class="mt-5">
        <div class="d-flex align-items-center pb-2">
            <h4 class="font-weight-bold m-0">Orders</h4>
            <span class="mx-2 text-secondary">|</span>
            <div moe>
                <a start show class="py-0 font-weight-normal">Add</a>
                <form url="/api/actionItem/create" wide>
                    <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                    <input type="hidden" name="prescriberProUid" value="{{ $pro->uid }}">
                    <div class="mb-2">
                        <label for="" class="control-label text-sm text-secondary mb-1">Facility</label>
                        <select name="toFacilityUid"
                                class="form-control form-control-sm">
                            <option value="">-- Facility --</option>
                            @foreach ($facilities as $facility)
                                <option value="{{$facility->uid}}">{{$facility->name}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="mb-2">
                        <label for="" class="control-label text-sm text-secondary mb-1">Category *</label>
                        <select name="category"
                                class="form-control form-control-sm" required>
                            <option value="">-- Category --</option>
                            <option value="DIAGNOSTIC">Diagnostic</option>
                            <option value="APPOINTMENT">Appointment</option>
                            <option value="EXERCISE">Exercise</option>
                            <option value="DIETETITC">Dietetitc</option>
                            <option value="EQUIPMENT">Equipment</option>
                            <option value="GO_TO_HOSPITAL">Go to hospital</option>
                            <option value="OTHER">Other</option>
                        </select>
                    </div>
                    <div class="mb-2">
                        <input type="text" class="form-control form-control-sm" name="contentText" value="" placeholder="Title *" required>
                    </div>
                    <div class="mb-2">
                        <input type="text" class="form-control form-control-sm" name="contentDetail" value="" placeholder="Details">
                    </div>
                    <div class="d-flex align-items-center">
                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                    </div>
                </form>
            </div>
        </div>
        <table class="table table-sm table-bordered mb-0" style="table-layout: fixed">
            <thead>
            <tr>
                <th class="px-2 text-secondary border-bottom-0">Category</th>
                <th class="px-2 text-secondary border-bottom-0">Facility</th>
                <th class="px-2 text-secondary border-bottom-0 w-25">Action</th>
                <th class="px-2 text-secondary border-bottom-0">Created</th>
                <th class="px-2 text-secondary border-bottom-0">Status</th>
                <th class="px-2 text-secondary border-bottom-0">&nbsp;</th>
            </tr>
            </thead>
            <tbody>
            <?php $prevItemType = false; ?>
            @foreach($patient->actionItems as $item)
                @if($item->action_item_category !== 'DRUG')
                @if(!$prevItemType || $prevItemType !== $item->action_item_category)
                    <tr class="bg-light">
                        <td colspan="6" class="font-weight-bold px-2">
                            {{ucwords(str_replace("_", " ", strtolower($item->action_item_category)))}}
                        </td>
                    </tr>
                @endif
                <tr>
                    <td class="px-2">
                        &nbsp;
                    </td>
                    <td class="px-2">
                        {{$item->facility ? $item->facility->name : ''}}
                        <span moe>
                            <a start show class="on-hover-opaque"><i class="fa fa-edit"></i></a>
                            <form url="/api/actionItem/updateToFacility">
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <label for="" class="control-label text-sm text-secondary mb-1">Facility *</label>
                                    <select name="toFacilityUid" class="form-control form-control-sm" required>
                                        <option value="">-- Facility --</option>
                                        @foreach ($facilities as $facility)
                                            <option {{ $item->to_facility_id === $facility->id ? 'selected' : '' }} value="{{$facility->uid}}">{{$facility->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                    </td>
                    <td class="px-2">
                        {{$item->content_text}}
                        <span moe>
                            <a start show class="on-hover-opaque"><i class="fa fa-edit"></i></a>
                            <form url="/api/actionItem/updateContent" wide>
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="contentText" value="{{ $item->content_text }}" placeholder="Title *" required>
                                </div>
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="contentDetail" value="{{ $item->content_detail }}" placeholder="Details">
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        <div class="text-sm text-secondary">{{$item->content_detail}}</div>
                    </td>
                    <td class="px-2">{{friendly_date_time($item->created_at, false)}}</td>
                    <td class="px-2">
                        {{$item->status_category}}
                        <span moe>
                            <a start show class="on-hover-opaque"><i class="fa fa-edit"></i></a>
                            <form url="/api/actionItem/updateStatus">
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <label for="" class="control-label text-sm text-secondary mb-1">Status *</label>
                                    <select name="statusCategory" class="form-control form-control-sm" required>
                                        <option {{ $item->status_category === 'OPEN' ? 'selected' : '' }} value="OPEN">Open</option>
                                        <option {{ $item->status_category === 'CLOSED' ? 'selected' : '' }} value="CLOSED">Closed</option>
                                    </select>
                                </div>
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="statusMemo" value="" placeholder="Memo">
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                    </td>
                    <td class="px-2 text-center">
                        <div class="d-flex align-items-center justify-content-start">
                            @if($item->is_signed_by_prescriber)
                                <span class="text-secondary">
                                <i class="fa fa-check"></i>
                                Signed
                            </span>
                                <span class="mx-2 text-secondary">|</span>
                            @else
                                @if($pro->id === $item->prescriber_pro_id)
                                    <span moe relative>
                                    <a start show>Sign</a>
                                    <form url="/api/actionItem/signAsPrescriber" right>
                                        <input type="hidden" name="uid" value="{{ $item->uid }}">
                                        <p class="small min-width-200px text-left">Sign this action items as the prescriber?</p>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-success mr-2" submit>Yes</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                        </div>
                                    </form>
                                </span>
                                    <span class="mx-2 text-secondary">|</span>
                                @endif
                            @endif
                            <span moe relative>
                            <a start show>eFax</a>
                            <form url="/api/actionItem/efax" right>
                                <input type="hidden" name="uid" value="{{ $item->uid }}">
                                <div class="mb-2">
                                    <input type="text" class="form-control form-control-sm" name="toFaxNumber" value="" placeholder="To Number *" required>
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Send</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        </div>
                    </td>
                </tr>
                <?php $prevItemType = $item->action_item_category; ?>
                @endif
            @endforeach
            </tbody>
        </table>
    </div>
@endsection
