<div class="mt-2 pt-2">
    @php
        $cpc = $coverage;
        $latestCpc = $patient->latestClientPrimaryCoverage;
    @endphp
</div>
    @if(!$cpc)
        <div class="alert alert-info">No coverage for this client</div>
    @else
        <?php
            $cpc->auto_detail_json = null;
            $creationStrategy = $cpc->creation_strategy ?? null;
            if($creationStrategy === 'NEW' || $creationStrategy === 'AUTO_REFRESH'){
                if($cpc->plan_type === 'MEDICARE'){
                   $cpc->auto_detail_json = json_decode($cpc->auto_medicare_detail_json ?? null); 
                }
                if($cpc->plan_type === 'MEDICID'){
                    $cpc->auto_detail_json = json_decode($cpc->auto_medicaid_detail_json ?? null); 
                }
                if($cpc->plan_type === 'COMMERCIAL'){
                    $cpc->auto_detail_json = json_decode($cpc->auto_commercial_detail_json ?? null); 
                }
                
            }
        ?>
        <div class="d-flex align-items-center mb-2">
            <span class="">Plan Type: <b>{{ $latestCpc->plan_type }}</b></span>
            <span class="mx-1 text-muted text-sm">|</span>
            @if($cpc->is_manually_determined)
                <div>
                    <span class="d-inline bg-warning px-2 py-1 rounded mr-1"><i class="fas fa-map-pin"></i> Manually Determined</span> 
                    @if($cpc->is_cancelled)
                    <span class="mr-1 text-danger text-sm">Cancelled</span>
                    @else
                        @include('app.patient.partials.undo-manual-determination')
                    @endif
                    <span class="mx-1 text-muted text-sm">|</span>
                </div>
                
            @else

            @endif
            <h1 class="mr-3 mb-0">Basic: {{$cpc->is_covered}}</h1>
            @if($patient->rmCompany)
                <h1 class="mr-3 mb-0">RPM: {{$cpc->manual_rpm_determination_category}}</h1>
                <h1 class="mr-3 mb-0">TV: {{$cpc->manual_televisit_determination_category}}</h1>
            @endif
            @if(!$cpc->is_manually_determined)
                @if($cpc->plan_type == 'MEDICARE')
                    @include('app.patient.primary-coverage-refresh', ['endpoint'=>'refreshCoverageForMedicare'])
                    <span class="mx-2 text-secondary text-sm">|</span>
                    <a native target="_blank"
                    open-in-stag-popup
                    mc-initer="manual-determination-form-{{$patient->uid}}"
                    title="Medicare Part B (Primary)"
                    href="/patients/view/primary-coverage-manual-determination-modal/{{$patient->uid}}?coverageUid={{ $cpc->uid }}">
                        Manual Determination for Medicare Part B (Primary)
                    </a>
                @endif
                @if($cpc->plan_type == 'MEDICAID')
                    @include('app.patient.primary-coverage-refresh', ['endpoint'=>'refreshCoverageForMedicaid'])
                    <span class="mx-2 text-secondary text-sm">|</span>
                    <a native target="_blank"
                    open-in-stag-popup
                    mc-initer="manual-determination-form-{{$patient->uid}}"
                    title="Medicaid (Primary)"
                    href="/patients/view/primary-coverage-manual-determination-modal/{{$patient->uid}}?coverageUid={{ $cpc->uid }}">
                        Manual Determination for Medicaid (Primary)
                    </a>
                @endif
                @if($cpc->plan_type == 'COMMERCIAL')
                    @include('app.patient.primary-coverage-refresh', ['endpoint'=>'refreshCoverageForCommercial'])
                    <span class="mx-2 text-secondary text-sm">|</span>
                    <a native target="_blank"
                    open-in-stag-popup
                    mc-initer="manual-determination-form-{{$patient->uid}}"
                    title="Commercial (Primary)"
                    href="/patients/view/primary-coverage-manual-determination-modal/{{$patient->uid}}?coverageUid={{ $cpc->uid }}">
                        Manual Determination for Commercial (Primary)
                    </a>
                @endif
            @endif
            <span class="mx-2">Created At: {{ friendly_date_time($cpc->created_at) }} by {{ $cpc->createdByPro ? $cpc->createdByPro->displayName() : '---' }}</span>
        </div>

        <div class="mt-4 {{ $cpc->is_cancelled ? 'cpc-cancelled':'' }}">
          <div class="row">
            <div class="col-md-12">
              @include('app.patient.primary-coverage-view')
            </div>
          </div>
            {{--
            @php
            dump(json_decode($cpc->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)));
            @endphp
            --}}
            {{--
            @php
            dump($cpc->auto_detail_json);
            @endphp
            --}}
        </div>
    @endif
