@extends ('layouts.patient')

@section('inner-content')

    <div id="client-settings-container">

        <div class="row">
            <div class="col-6">

                <div class="d-flex align-items-center mb-2">
                    <div class="font-weight-bold">Home Address</div>
                    <span class="text-secondary mx-2">|</span>
                    <div moe wide>
                        <a start show><i class="fa fa-edit"></i> Edit Address</a>
                        <form url="/api/client/editAddress" class="mcp-theme-1" onbeforesubmit="setSettingsMailingAddress">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">

                            <p class="mb-2 font-weight-bold">Home Address</p>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="homeAddressLine1"
                                       placeholder="Address Line 1" value="{{ $patient->home_address_line1 }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="homeAddressLine2"
                                       placeholder="Address Line 2" value="{{ $patient->home_address_line2 }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="homeAddressCity"
                                       placeholder="City" value="{{ $patient->home_address_city }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="homeAddressState"
                                       placeholder="State" value="{{ $patient->home_address_state }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="homeAddressZip" placeholder="ZIP"
                                       value="{{ $patient->home_address_zip }}">
                            </div>

                            <p class="mb-2 mt-3 font-weight-bold">Mailing Address</p>
                            <label class="d-flex align-items-center">
                                @php
                                    $isSame = ($patient->home_address_line1 == $patient->mailing_address_line1 &&
                                                $patient->home_address_line2 == $patient->mailing_address_line2 &&
                                                $patient->home_address_city == $patient->mailing_address_city &&
                                                $patient->home_address_state == $patient->mailing_address_state &&
                                                $patient->home_address_zip == $patient->mailing_address_zip);
                                @endphp
                                <input type="checkbox" id="settingsSameAsHome"
                                       onchange="copyHomeToMailingAndReadOnly(this.checked)" {{ $isSame ? 'checked' : '' }}>
                                <span class="ml-2">Same as home address</span>
                            </label>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="mailingAddressLine1"
                                       placeholder="Address Line 1" value="{{ $patient->mailing_address_line1 }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="mailingAddressLine2"
                                       placeholder="Address Line 2" value="{{ $patient->mailing_address_line2 }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="mailingAddressCity"
                                       placeholder="City" value="{{ $patient->mailing_address_city }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="mailingAddressState"
                                       placeholder="State" value="{{ $patient->mailing_address_state }}">
                            </div>
                            <div class="mb-2">
                                <input type="text" class="form-control form-control-sm" name="mailingAddressZip"
                                       placeholder="ZIP" value="{{ $patient->mailing_address_zip }}">
                            </div>
                            <div class="mb-2">
                        <textarea type="text" class="form-control form-control-sm" name="mailingAddressMemo"
                                  placeholder="Memo">{{ $patient->mailing_address_memo }}</textarea>
                            </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>
                </div>
                <div class="pl-3">
                    <div class="mb-1">
                        Address Line 1: <b>{{ $patient->home_address_line1 }}</b>
                    </div>
                    <div class="mb-1">
                        Address Line 2: <b>{{ $patient->home_address_line2 }}</b>
                    </div>
                    <div class="mb-1">
                        City: <b>{{ $patient->home_address_city }}</b>
                    </div>
                    <div class="mb-1">
                        State: <b>{{ $patient->home_address_state }}</b>
                    </div>
                    <div class="mb-1">
                        ZIP: <b>{{ $patient->home_address_zip }}</b>
                    </div>
                </div>

                <div class="font-weight-bold mb-2 mt-3">Mailing Address</div>
                <div class="pl-3">
                    <div class="mb-1">
                        Address Line 1: <b>{{ $patient->mailing_address_line1 }}</b>
                    </div>
                    <div class="mb-1">
                        Address Line 2: <b>{{ $patient->mailing_address_line2 }}</b>
                    </div>
                    <div class="mb-1">
                        City: <b>{{ $patient->mailing_address_city }}</b>
                    </div>
                    <div class="mb-1">
                        State: <b>{{ $patient->mailing_address_state }}</b>
                    </div>
                    <div class="mb-1">
                        ZIP: <b>{{ $patient->mailing_address_zip }}</b>
                    </div>
                    <div class="mb-1">
                        Special Instructions: <b>{{ $patient->mailing_address_memo }}</b>
                    </div>
                </div>

                <hr class="m-negator-3 my-3">

                <div class="d-flex align-items-center mt-3 mb-2">
                    <div class="font-weight-bold">Contact Info</div>
                    <span class="text-secondary mx-2">|</span>
                    <div moe wide>
                        <a start show><i class="fa fa-edit"></i> Edit Contact Info</a>
                        <form url="/api/client/putContactInfo" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <div class="mb-2">
                                <label class="mb-1 text-secondary text-sm">Home Phone Number</label>
                                <input type="tel" class="form-control form-control-sm" name="homeNumber"
                                       placeholder="Home Phone Number" value="{{ $patient->phone_home }}">
                            </div>
                            <div class="mb-2">
                                <label class="mb-1 text-secondary text-sm">Cell Number</label>
                                <input type="tel" class="form-control form-control-sm" name="cellNumber"
                                       placeholder="Cell Number" value="{{ $patient->cell_number }}">
                            </div>
                            <div class="mb-2">
                                <label class="mb-1 text-secondary text-sm">Cell Number Memo</label>
                                <input type="text" class="form-control form-control-sm" name="cellNumberMemo"
                                       placeholder="Cell Number Memo" value="{{ $patient->cell_number_memo }}">
                            </div>

                            <div class="mb-2">
                                <label class="mb-1 text-secondary text-sm">Cell Phone Type</label>
                                <input type="text" class="form-control form-control-sm" name="cellPhoneType"
                                       data-option-list autocomplete="off"
                                       placeholder="Cell Phone Type" value="{{ $patient->cell_phone_type }}">
                                <div class="data-option-list">
                                    <div>Android</div>
                                    <div>iOS</div>
                                </div>
                            </div>
                            <div class="mb-2">
                                <label class="mb-1 text-secondary text-sm">Cell Phone Model</label>
                                <input type="text" class="form-control form-control-sm" name="cellPhoneModel"
                                       placeholder="Cell Phone Model" value="{{ $patient->cell_phone_model }}">
                            </div>
                            <div class="mb-2">
                                <label class="mb-1 text-secondary text-sm">Available Video Apps</label>
                                <input type="text" class="form-control form-control-sm" name="availableVideoApps"
                                       placeholder="Available Video Apps" value="{{ $patient->available_video_apps }}">
                            </div>
                            <div class="mb-2">
                                <label class="mb-1 text-secondary text-sm">Email Address</label>
                                <input type="text" class="form-control form-control-sm" name="email" placeholder="Email Address"
                                       value="{{ $patient->email_address }}">
                            </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>
                </div>
                <div class="pl-3">
                    <div class="mb-1">
                        Home Phone: <b>{{ $patient->phone_home }}</b>
                    </div>
                    <div class="mb-1">
                        Cell Phone: <b>{{ $patient->cell_number }}</b> <span
                            class="text-sm text-secondary ml-2">{{ $patient->cell_number_memo ? '(' . $patient->cell_number_memo . ')' : '' }}</span>
                    </div>
                    <div class="mb-1">
                        Cell Phone Type: <b>{{ $patient->cell_phone_type }}</b>
                    </div>
                    <div class="mb-1">
                        Cell Phone Model: <b>{{ $patient->cell_phone_model }}</b>
                    </div>
                    <div class="mb-1">
                        Available Video Apps: <b>{{ $patient->available_video_apps }}</b>
                    </div>
                    <div class="mb-1">
                        Email: <b>{{ $patient->email_address }}</b>
                    </div>
                </div>

                <hr class="m-negator-3 my-3">

                <div class="d-flex align-items-center mt-3 mb-2">
                    <div class="font-weight-bold">Associated Pros</div>
                </div>
                <div class="pl-3">
                   
                    <div class="mb-1">
                        RMM: <b>{{ $patient->rmm->name_display ?? ''}}</b>
                        @if($pro->pro_type === 'ADMIN')
                        <div moe wide>
                            <a start show><i class="fa fa-edit"></i></a>
                            <form url="/api/client/putRmmPro" class="mcp-theme-1">
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <div class="mb-2">
                                    <label class="mb-1 text-secondary text-sm">RMM Pro</label>
                                    
                                    <select class="form-control form-control-sm" name="rmmProUid">
                                        <option value="">--select--</option>
                                        @foreach($pros as $rmmPro)
                                        <option value="{{$rmmPro->uid}}">{{$rmmPro->name_display}}</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>
                    <div class="mb-1">
                        RME: <b>{{ $patient->rme->name_display ?? '' }}</b>
                        @if($pro->pro_type === 'ADMIN')
                        <div moe wide>
                            <a start show><i class="fa fa-edit"></i></a>
                            <form url="/api/client/putRmePro" class="mcp-theme-1">
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <div class="mb-2">
                                    <label class="mb-1 text-secondary text-sm">RME Pro</label>
                                    <select class="form-control form-control-sm" name="rmeProUid">
                                        <option value="">--select--</option>
                                        @foreach($pros as $rmePro)
                                        <option value="{{$rmePro->uid}}">{{$rmePro->name_display}}</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>

                    <div class="mb-1">
                        RMS: <b>{{ $patient->rms->name_display ??'' }}</b>
                        @if($pro->pro_type === 'ADMIN')
                        <div moe wide>
                            <a start show><i class="fa fa-edit"></i></a>
                            <form url="/api/client/putRmsPro" class="mcp-theme-1">
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <div class="mb-2">
                                    <label class="mb-1 text-secondary text-sm">RMS Pro</label>
                                    
                                    <select class="form-control form-control-sm" name="rmsProUid">
                                        <option value="">--select--</option>
                                        @foreach($pros as $rmsPro)
                                        <option value="{{$rmsPro->uid}}">{{$rmsPro->name_display}}</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>

                </div>

            </div>
            <div class="col-6 border-left">

                <span>MCP: <b>{{ $patient->mcp ? $patient->mcp->displayName() : '-' }}</b></span>
                @if($pro->pro_type == 'ADMIN')
                    <div moe class="ml-2">
                        <a start show><i class="fa fa-edit"></i></a>
                        <form url="/api/client/putMcp" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <div class="mb-2">
                                <label class="text-secondary text-sm">MCP Pro</label>
                                <select name="mcpProUid" class="form-control form-control-sm" provider-search data-pro-uid="{{ @$patient->mcp->uid }}" >
                                    <option value=""> --select--</option>
                                    @foreach($pros as $iPro)
                                        <option
                                            value="{{$iPro->uid}}" {{ $patient->mcp && $iPro->uid === $patient->mcp->uid ? 'selected' : '' }}>{{$iPro->displayName()}}</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

                <hr class="m-negator-3 my-3">
                <span>Physician: <b>{{ $patient->pcp ? $patient->pcp->displayName() : '-' }}</b></span>
                @if($pro->pro_type == 'ADMIN')
                    <div moe class="ml-2">
                        <a start show><i class="fa fa-edit"></i></a>
                        <form url="/api/client/putPhysicianPro" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <div class="mb-2">
                                <label class="text-secondary text-sm">Physician Pro</label>
                                <select name="physicianProUid" class="form-control form-control-sm" provider-search data-pro-uid="{{ @$patient->pcp->uid }}" >
                                    <option value=""> --select--</option>
                                    @foreach($pros as $iPro)
                                        <option
                                            value="{{$iPro->uid}}" {{ $patient->pcp && $iPro->uid === $patient->pcp->uid ? 'selected' : '' }}>{{$iPro->displayName()}}</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

                <hr class="m-negator-3 my-3">
                <span>MCP Onboarding Visit: <b>{{ $patient->has_mcp_done_onboarding_visit }}</b></span>
                <span moe class="ml-2">
            <a start show><i class="fa fa-edit"></i></a>
            <form url="/api/client/updateMcpOnboardingVisitInfo" class="mcp-theme-1">
                <input type="hidden" name="uid" value="{{$patient->uid}}">
                <div class="mb-2">
                    <select name="hasMcpDoneOnboardingVisit"
                            class="form-control form-control-sm"
                            onchange="toggleDisabledAsNeeded(this, 'YES', 'if-visit-done')">
                        <option value="">-- Select Status --</option>
                        <option
                            value="YES" {{ $patient->has_mcp_done_onboarding_visit === 'YES' ? 'selected' : '' }}>YES</option>
                        <option
                            value="NO" {{ $patient->has_mcp_done_onboarding_visit === 'NO' ? 'selected' : '' }}>NO</option>
                        <option value="UNKNOWN" {{ $patient->has_mcp_done_onboarding_visit === 'UNKNOWN' ? 'selected' : '' }}>UNKNOWN</option>
                    </select>
                </div>
                <div class="mb-2">
                    <input type="date" class="if-visit-done form-control form-control-sm" disabled
                           name="mcpOnboardingVisitDate" value="{{ date('Y-m-d') }}" max="{{ date('Y-m-d') }}">
                </div>
                <div class="mb-2">
                    <select name="mcpOnboardingVisitNoteUid" disabled
                            class="form-control form-control-sm if-visit-done"
                            onchange="if(this.value === '-- create --') createNewNote('{{$patient->uid}}', '{{$pro->uid}}', '{{date('Y-m-d')}}');">
                        <option value="">-- Visit Note --</option>
                        @foreach ($notes as $note)
                            @if(!empty($note->title) && $note->client_id === $patient->id && !$note->is_cancelled)
                                <option
                                    {{ $patient->mcp_onboarding_visit_note_id === $note->id ? 'selected' : '' }}
                                    value="{{$note->uid}}">{{$note->title}} ({{friendly_date_time($note->effective_dateest, false)}})</option>
                            @endif
                        @endforeach
                        {{--<option value="-- create --">-- Create Note --</option>--}}
                    </select>
                </div>
                <div class="mb-2 if-note-outside-system">
                    <textarea class="form-control form-control-sm" name="reasonOnboardingVisitNoteOutsideSystem"
                              placeholder="Visit note outside the system reason" spellcheck="false"
                              data-gramm="false"></textarea>
                </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>
        </span>

                <hr class="m-negator-3 my-3">
                <span>Initiative: <b>{{$patient->initiative ? $patient->initiative : 'N/A'}}</b></span>
                <span moe class="ml-2">
            <a start show><i class="fa fa-edit"></i></a>
            <form url="/api/client/updateInitiative" class="mcp-theme-1">
                <input type="hidden" name="uid" value="{{$patient->uid}}">
                <div class="mb-2">
                    <select name="initiative" class="form-control">
                        <option value="">-- select --</option>
                        @foreach($intiatives as $initiative)
                            <option value="{{$initiative}}">{{$initiative}}</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>
        </span>

                <hr class="m-negator-3 mt-3">
                <div id="preferredPharmacyApp">
                    <span>Preferred Pharmacy: <b>@{{ pharmacy() }}</b></span>
                    <span moe bottom relative large class="ml-2">
                        <a start show><i class="fa fa-edit"></i></a>
                        <form url="/api/client/updatePreferredPharmacyDetail" class="mcp-theme-1">
                            <input type="hidden" name="uid" value="{{$patient->uid}}">
                            <input type="hidden" name="preferredPharmacyDetail" v-model="json">
                            <div class="row mb-2">
                                <div class="col-12">
                                    <label class="text-sm text-secondary mb-1">Business Name</label>
                                    <input type="text" v-model="payload.pharmacyName" class="form-control form-control-sm">
                                </div>
                            </div>
                            <div class="row mb-2">
                                <div class="col-6">
                                    <label class="text-sm text-secondary mb-1">City</label>
                                    <input type="text" v-model="payload.pharmacyCity" class="form-control form-control-sm">
                                </div>
                                <div class="col-6">
                                    <label class="text-sm text-secondary mb-1">State</label>
                                    <input type="text" v-model="payload.pharmacyState" class="form-control form-control-sm">
                                </div>
                            </div>
                            <div class="row mb-2">
                                <div class="col-12">
                                    <label class="text-sm text-secondary mb-1">Address Memo</label>
                                    <input type="text" v-model="payload.pharmacyAddressMemo" class="form-control form-control-sm">
                                </div>
                            </div>
                            <div class="row mb-2">
                                <div class="col-6">
                                    <label class="text-sm text-secondary mb-1">Phone</label>
                                    <input type="text" v-model="payload.pharmacyPhone" class="form-control form-control-sm">
                                </div>
                                <div class="col-6">
                                    <label class="text-sm text-secondary mb-1">Fax</label>
                                    <input type="text" v-model="payload.pharmacyFax" class="form-control form-control-sm">
                                </div>
                            </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>
                    </span>
                </div>

                @if($pro->pro_type == 'ADMIN')
                <hr class="m-negator-3 mt-3">
                <div>
                    <div class="d-flex mb-2 align-items-center">
                        <b class="d-block">MCN Query Response</b>
                        <span class="text-secondary mx-2">|</span>
                        @if(!$patient->is_coverage_manually_verified)
                            <div moe wide>
                                <a start show><i class="fa fa-edit"></i> Set coverage to <b>Manually Verified</b></a>
                                <form url="/api/client/markCoverageAsManuallyVerified" class="mcp-theme-1">
                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary text-sm">Manual Verification Memo</label>
                                        <textarea rows="4" type="text" class="form-control form-control-sm" name="memo"
                                              placeholder="Memo">{{ $patient->coverage_manual_verification_memo }}</textarea>
                                    </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>
                        @else
                            <span class="text-info font-weight-bold"><i class="fa fa-check"></i>&nbsp;Manually Verified</span>
                            <div moe wide class="ml-3">
                                <a start show><i class="fa fa-edit"></i> Undo</a>
                                <form url="/api/client/undoMarkCoverageAsManuallyVerified" class="mcp-theme-1">
                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary text-sm">Undo Manual Verification Memo</label>
                                        <textarea rows="4" type="text" class="form-control form-control-sm" name="memo"
                                                  placeholder="Memo">{{ $patient->coverage_manual_verification_memo }}</textarea>
                                    </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>
                    <div class="bg-light border p-2">
                    @php
                    function displayNode($_key, $_node) {
                        $nodeOutput = '<div class="mb-1">' . ucwords(str_replace("_", " ", $_key)) . ': ';
                        $nodeType = gettype($_node);
                        if(is_array($_node) && count($_node)) {
                            $nodeOutput .= '<div class="border-left pl-3 my-1">';
                            foreach ($_node as $k => $v) {
                                $nodeOutput .= displayNode($k, $v);
                            }
                            $nodeOutput .= '</div>';
                        }
                        else if(!is_array($_node)) {
                            $nodeOutput .= '<b>' . (!empty($_node) ? $_node : '-') . '</b>';
                        }
                        else {
                            $nodeOutput .= '-';
                        }
                        $nodeOutput .= '</div>';
                        return $nodeOutput;
                    }
                    $mcnResponse = !empty($patient->mcn_response_detail) ? json_decode($patient->mcn_response_detail, true) : [];
                    $output = [];
                    foreach ($mcnResponse as $k => $v) {
                        $output[] = displayNode($k, $v);
                    }
                    @endphp
                    {!! implode("", $output) !!}
                    </div>
                </div>
                @endif

            </div>
        </div>

    </div>

    <script>
        window.setSettingsMailingAddress = function () {
            copyHomeToMailingAndReadOnly($('#settingsSameAsHome').is(':checked'));
        }
        window.copyHomeToMailingAndReadOnly = function (_same) {
            if (_same) {
                $('[name="mailingAddressLine1"]').val($('[name="homeAddressLine1"]').val()).prop('readonly', true);
                $('[name="mailingAddressLine2"]').val($('[name="homeAddressLine2"]').val()).prop('readonly', true);
                $('[name="mailingAddressCity"]').val($('[name="homeAddressCity"]').val()).prop('readonly', true);
                $('[name="mailingAddressState"]').val($('[name="homeAddressState"]').val()).prop('readonly', true);
                $('[name="mailingAddressZip"]').val($('[name="homeAddressZip"]').val()).prop('readonly', true);
            } else {
                $('[name="mailingAddressLine1"]').prop('readonly', false);
                $('[name="mailingAddressLine2"]').prop('readonly', false);
                $('[name="mailingAddressCity"]').prop('readonly', false);
                $('[name="mailingAddressState"]').prop('readonly', false);
                $('[name="mailingAddressZip"]').prop('readonly', false);
                $('[name="mailingAddressLine1"]').focus();
            }
        }
        @if($isSame)
        function init() {
            copyHomeToMailingAndReadOnly(true);
        }

        addMCInitializer('copy-mailing-address', init, '#client-settings-container');
        @endif
    </script>

    <script>
        <?php
        $display = '-';
        if (!empty($patient->preferred_pharmacy_detail)) {
            $parsed = json_decode($patient->preferred_pharmacy_detail);
            $parts = array_filter([
                $parsed->pharmacyName,
                $parsed->pharmacyCity,
                $parsed->pharmacyState,
                $parsed->pharmacyAddressMemo,
                $parsed->pharmacyPhone,
                $parsed->pharmacyFax,
            ], function ($_item) {
                return !!$_item;
            });
            $display = implode(", ", $parts);
        }
        ?>
        window.preferredPharmacyApp = new Vue({
            el: '#preferredPharmacyApp',
            delimiters: ['@{{', '}}'],
            data: {
                payload: {
                    pharmacyName: '{{ @$parsed->pharmacyName }}',
                    pharmacyCity: '{{ @$parsed->pharmacyCity }}',
                    pharmacyState: '{{ @$parsed->pharmacyState }}',
                    pharmacyAddressMemo: '{{ @$parsed->pharmacyAddressMemo }}',
                    pharmacyPhone: '{{ @$parsed->pharmacyPhone }}',
                    pharmacyFax: '{{ @$parsed->pharmacyFax }}'
                },
                loaded: {
                    pharmacyName: '{{ @$parsed->pharmacyName }}',
                    pharmacyCity: '{{ @$parsed->pharmacyCity }}',
                    pharmacyState: '{{ @$parsed->pharmacyState }}',
                    pharmacyAddressMemo: '{{ @$parsed->pharmacyAddressMemo }}',
                    pharmacyPhone: '{{ @$parsed->pharmacyPhone }}',
                    pharmacyFax: '{{ @$parsed->pharmacyFax }}'
                },
                json: '',
            },
            watch: {
                payload: {
                    handler: function(val, oldVal) {
                        this.json = JSON.stringify({
                            pharmacyName: this.payload.pharmacyName,
                            pharmacyCity: this.payload.pharmacyCity,
                            pharmacyState: this.payload.pharmacyState,
                            pharmacyAddressMemo: this.payload.pharmacyAddressMemo,
                            pharmacyPhone: this.payload.pharmacyPhone,
                            pharmacyFax: this.payload.pharmacyFax
                        });
                    },
                    deep: true
                },
            },
            methods: {
                pharmacy: function() {
                    return [
                        this.loaded.pharmacyName,
                        this.loaded.pharmacyCity,
                        this.loaded.pharmacyState,
                        this.loaded.pharmacyAddressMemo,
                        this.loaded.pharmacyPhone,
                        this.loaded.pharmacyFax,
                    ].filter(Boolean).join(', ');
                }
            },
            mounted: function() {
                this.json = JSON.stringify({
                    pharmacyName: this.payload.pharmacyName,
                    pharmacyCity: this.payload.pharmacyCity,
                    pharmacyState: this.payload.pharmacyState,
                    pharmacyAddressMemo: this.payload.pharmacyAddressMemo,
                    pharmacyPhone: this.payload.pharmacyPhone,
                    pharmacyFax: this.payload.pharmacyFax
                });
            }
        })
    </script>
@endsection
