@extends ('layouts.patient')
@section('inner-content')
    <div class="">
        <div class="d-flex align-items-end pb-3">
            <h4 class="font-weight-bold m-0">
                <i class="fa fa-link"></i>
                Linked Companies
            </h4>
            <span class="mx-2 text-secondary">|</span>
            <div moe relative class="">
                <a href="#" start show class="col-2-button">
                    + Add
                </a>
                <form url="/api/companyClient/create" class="mcp-theme-1">
                    <input type="hidden" name="clientUid" value="{{$patient->uid}}">
                    <div class="mb-2">
                        <label class="text-secondary text-sm">Company</label>
                        <select name="companyUid" class="form-control form-control-sm" required>
                            <option value="">--select--</option>
                            @foreach($companies as $company)
                                @if($company->name) <!-- remove blank companies-->
                                    <option value="{{$company->uid}}">{{$company->name}}</option>
                                @endif
                            @endforeach
                        </select>
                    </div>
                    <div class="mb-2">
                        <label for="" class="control-label">Date Referred</label>
                        <input type="date" name="dateReferred"  class="form-control">
                    </div>
                    <div>
                        <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
                    </div>
                </form>
            </div>
        </div>
        <table class="table table-sm table-striped table-bordered mb-0">
            @if($patient->linkedCompanies && count($patient->linkedCompanies))
                <thead>
                <tr class="bg-light">
                    <th class="text-secondary border-0">Created At</th>
                    <th class="text-secondary border-0">Name</th>
                    <th class="text-secondary border-0">Is Active?</th>
                    <th class="text-secondary border-0">Date Referred</th>
                    <th class="text-secondary border-0">Status</th>
                    <th class="text-secondary border-0">Documents</th>
                </tr>
                </thead>
                <tbody>
                @foreach($patient->linkedCompanies as $linkedCompany)
                    <tr>
                        <td>{{ friendlier_date_time($linkedCompany->created_at) }}</td>
                        <td>{{$linkedCompany->company->name}}</td>
                        <td>{{ $linkedCompany->is_active? 'Yes': 'No' }}</td>
                        <td>
                            {{ friendlier_date($linkedCompany->date_referred) }}
                            <span moe class="ml-1" relative>
                                <a class="" href="" show start><i class="fa fa-edit"></i></a>
                                <form url="/api/companyClient/updateDateReferred" right>
                                    <input type="hidden" name="uid" value="{{$linkedCompany->uid}}">
                                    <div class="m-2">
                                        <label for="" class="control-label">Date Referred</label>
                                        <input type="date" name="dateReferred" value="{{$linkedCompany->date_referred}}" class="form-control">
                                    </div>
                                    <div class="mb-0">
                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                        </td>
                        <td>
                            {{ isset($companyClientStatusMap[$linkedCompany->status])? $companyClientStatusMap[$linkedCompany->status] : '' }}
                            @if($linkedCompany->status_memo)
                                - {{$linkedCompany->status_memo}}
                            @endif
                            <br/>
                            Effective: {{$linkedCompany->status_effective_date}}
                            <span moe class="ml-1" relative>
                                <a class="" href="" show start><i class="fa fa-edit"></i></a>
                                <form url="/api/companyClient/update-status" right>
                                    <input type="hidden" name="uid" value="{{$linkedCompany->uid}}">
                                    <select name="status" required>
                                        <option {{$linkedCompany->status == 'NEW' ? 'selected': ''}} value="NEW">New<option/>
                                        <option {{$linkedCompany->status == 'ELIGIBILITY_VERIFIED' ? 'selected': ''}} value="ELIGIBILITY_VERIFIED">Eligibility Verified<option/>
                                        <option {{$linkedCompany->status == 'ELIGIBILITY_PENDING' ? 'selected': ''}} value="ELIGIBILITY_PENDING">Eligibility Pending<option/>
                                        <option {{$linkedCompany->status == 'NOT_ELIGIBLE' ? 'selected': ''}} value="NOT_ELIGIBLE">Eligibility Denied/Not Eligibility<option/>
                                        <option {{$linkedCompany->status == 'INITIAL_CONSULT' ? 'selected': ''}} value="INITIAL_CONSULT">Initial Consult<option/>
                                        <option {{$linkedCompany->status == 'HST_DELIVERED' ? 'selected': ''}} value="HST_DELIVERED">HST Delivered<option/>
                                        <option {{$linkedCompany->status == 'STUDY_PENDING' ? 'selected': ''}} value="STUDY_PENDING">Study Pending<option/>
                                        <option {{$linkedCompany->status == 'STUDY_COMPLETED' ? 'selected': ''}} value="STUDY_COMPLETED">Study Completed<option/>
                                        <option {{$linkedCompany->status == 'STUDY_INTERPRETED' ? 'selected': ''}} value="STUDY_INTERPRETED">Study Interpreted<option/>
                                        <option {{$linkedCompany->status == 'POST_HST_VISIT' ? 'selected': ''}} value="POST_HST_VISIT">Post HST Visit<option/>
                                        <option {{$linkedCompany->status == 'CPAP_RX' ? 'selected': ''}} value="CPAP_RX">CPAP Rx<option/>
                                        <option {{$linkedCompany->status == 'ORAL_APPLIANCE_RX' ? 'selected': ''}} value="ORAL_APPLIANCE_RX">Oral Appliance Rx<option/>
                                        <option {{$linkedCompany->status == 'NOT_INTERESTED' ? 'selected': ''}} value="NOT_INTERESTED">Not Interested<option/>
                                        <option {{$linkedCompany->status == 'IN_LAB_STUDY' ? 'selected': ''}} value="IN_LAB_STUDY">In Lab Study<option/>
                                        <option {{$linkedCompany->status == 'UNRESPONSIVE' ? 'selected': ''}} value="UNRESPONSIVE">Unresponsive<option/>
                                    </select>
                                    <div class="m-2">
                                        <textarea name="memo">{{$linkedCompany->status_memo}}</textarea>
                                    </div>
                                    <div class="mb-2">
                                      <label for="" class="control-label">Effective Date</label>
                                      <input type="date" name="statusEffectiveDate" class="form-control" value="{{$linkedCompany->status_effective_date}}">
                                    </div>
                                    <div class="mb-0">
                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                        </td>
                        <td>
                            <h6>Documents</h6>
                            <span moe class="ml-1" relative>
                                <a class="" href="" show start>Upload</a>
                                <form url="/api/companyClientDocument/create" right>
                                    <input type="hidden" name="companyClientUid" value="{{$linkedCompany->uid}}">
                                    <div class="m-2">
                                        <label for="" class="control-label">File name</label>
                                        <input type="text" class="form-control" name="name" required>
                                    </div>
                                    <div class="m-2">
                                        <input type="file" class="form-control" name="file">
                                    </div>
                                    <div class="mb-0">
                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                            @if(count($linkedCompany->documents))
                                <table class="table">
                                    @foreach($linkedCompany->allowedDocuments as $document)
                                        <tr>
                                            <td>
                                                <a native target="_blank" href="/api/companyClientDocument/download/{{$document->uid}}">
                                                    {{$document->name}}
                                                </a>
                                            </td>
                                            <td>
                                               <span moe class="ml-1" relative>
                                                    <a class="" href="" show start><i class="fa fa-edit"></i></a>
                                                    <form url="/api/companyClientDocument/updateName" right>
                                                        <input type="hidden" name="uid" value="{{$document->uid}}">
                                                        <div class="m-2">
                                                            <label for="" class="control-label">File name</label>
                                                            <input type="text" class="form-control" name="name" value="{{$document->name}}" required>
                                                        </div>

                                                        <div class="mb-0">
                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </span>
                                                <span moe class="ml-1" relative>
                                                    <a class="" href="" show start><i class="fa fa-trash-alt text-danger"></i></a>
                                                    <form url="/api/companyClientDocument/remove" right>
                                                        <input type="hidden" name="uid" value="{{$document->uid}}">
                                                        <div class="m-2">
                                                            <label for="" class="control-label">Are you sure?</label>
                                                        </div>

                                                        <div class="mb-0">
                                                            <button class="btn btn-primary btn-sm" submit>Remove</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </span>
                                            </td>
                                        </tr>
                                    @endforeach
                                </table>
                            @endif
                        </td>

                    </tr>
                @endforeach
                </tbody>
            @else
                <tbody>
                <tr>
                    <td class="text-secondary p-3">No linked accounts</td>
                </tr>
                </tbody>
            @endif
        </table>

    </div>
@endsection
