<div class="container-fluid px-lg-0">
	<div class="row">
		<div class="col-lg-5">
			<h4 class="font-weight-bold">Patient Name / Demographics</h4>
			<div class="table-responsive">
				<table class="table table-sm table-bordered table-striped">
					<tbody>
						<tr>
							<td>Patient First Name</td>
							<td>{{$cpc->patient_name_first}}</td>
						</tr>
						<tr>
							<td>Patient Middle Name / MI</td>
							<td>{{$cpc->patient_name_middle}}</td>
						</tr>
						<tr>
							<td>Patient Last Name</td>
							<td>{{$cpc->patient_name_last}}</td>
						</tr>
						<tr>
							<td>Patient Suffix</td>
							<td>{{$cpc->patient_name_suffix}}</td>
						</tr>
						<tr>
							<td>Patient Dob</td>
							<td>{{$cpc->patient_dob ? date_format(date_create($cpc->patient_dob), 'm/d/Y') : '-'}}</td>
						</tr>
						<tr>
							<td>Patient Sex</td>
							<td>{{$cpc->patient_sex ?? '-'}}</td>
						</tr>
					</tbody>
				</table>
			</div>

			<h4 class="font-weight-bold">Primary Coverage Information</h4>
			<div id="primaryCoverageLatestCoverage">
				<div class="table-responsive">
					<table class="table table-sm table-bordered table-striped">
						<tbody>
							<tr>
								<td>Plan Type</td>
								<td>{{$cpc->plan_type}}</td>
							</tr>
							<tr v-if="cpc.plan_type == 'COMMERCIAL'">
								<td>Commercial Payer</td>
								<td>{{$cpc->commercial_payer_id ? $cpc->payer->name : ($cpc->carrier_free_text ?: '-')}}</td>
							</tr>
							<tr v-if="cpc.plan_type == 'COMMERCIAL'">
								<td>Carrier Free Text</td>
								<td>{{$cpc->carrier_free_text}}</td>
							</tr>
							<tr v-if="cpc.plan_type == 'COMMERCIAL'">
								<td>Carrier Free Text Memo</td>
								<td>{{$cpc->carrier_free_text_memo}}</td>
							</tr>
							<tr v-if="cpc.plan_type == 'COMMERCIAL'">
								<td>Patient Member Identifier</td>
								<td>
									@if($performer->pro->pro_type === 'ADMIN')
										{{$cpc->commercial_member_identifier ?? '-'}}
									@else
										{{$cpc->commercial_member_identifier ? mask_string($cpc->commercial_member_identifier, '*', 4) : '-'}}
									@endif
								</td>
							</tr>
							<tr v-if="cpc.plan_type == 'COMMERCIAL'">
								<td>Patient Group Name</td>
								<td>{{$cpc->commercial_group_number ?? '-'}}</td>
							</tr>
							<tr v-if="cpc.plan_type == 'COMMERCIAL' || cpc.plan_type == 'MEDICAID'">
								<td colspan="2">
									<h5 class="font-weight-bold">Subscriber Details</h5>
									<div class="table-responsive">
										<table class="table table-bordered">
											<tbody>
												<tr class="bg-white">
													<td>Is Patient the subscriber?</td>
													<td>{{$cpc->is_patient_subscriber ? 'Yes' : 'No'}}</td>
												</tr>
												@if(!$cpc->is_patient_subscriber)
												<tr class="bg-white">
													<td>First Name</td>
													<td>{{$cpc->subscriber_name_first ?? '-'}}</td>
												</tr>
												<tr class="bg-white">
													<td>Middle Name / MI</td>
													<td>{{$cpc->subscriber_name_middle ?? '-'}}</td>
												</tr>
												<tr class="bg-white">
													<td>Last Name</td>
													<td>{{$cpc->subscriber_name_last ?? '-'}}</td>
												</tr>
												<tr class="bg-white">
													<td>Suffix</td>
													<td>{{$cpc->subscriber_name_suffix ?? '-'}}</td>
												</tr>
												<tr class="bg-white">
													<td>Sex</td>
													<td>{{$cpc->subscriber_sex ?? '-'}}</td>
												</tr>
												<tr class="bg-white">
													<td>Dob</td>
													<td>{{$cpc->subscriber_dob ? date_format(date_create($cpc->subscriber_dob), 'm/d/Y') : '-'}}</td>
												</tr>
												@endif
											</tbody>
										</table>
									</div>
								</td>
							</tr>
							<tr>
								<td>Date of Service</td>
								<td>{{$cpc->date_of_service ? date_format(date_create($cpc->date_of_service), 'm/d/Y') : '-'}}</td>
							</tr>
							<tr v-if="cpc.plan_type == 'MEDICAID' || (cpc.plan_type == 'COMMERCIAL' && cpc.mcd_number)">
								<td>Medicaid State</td>
								<td>{{$cpc->mcd_payer_id ? $cpc->mcdPayer->name : '-'}}</td>
							</tr>
							<tr v-if="cpc.plan_type == 'MEDICAID' || (cpc.plan_type == 'COMMERCIAL' && cpc.mcd_number)">
								<td>Medicaid Number</td>
								<td class="text-uppercase">
									@if($performer->pro->pro_type === 'ADMIN')
										{{$cpc->mcd_number ?? '-'}}
									@else
										{{$cpc->mcd_number ? mask_string($cpc->mcd_number, '*', 4) : '-'}}
									@endif
								</td>
							</tr>
							<tr v-if="cpc.plan_type == 'MEDICARE' || (cpc.plan_type == 'COMMERCIAL' && cpc.mcr_number)">
								<td>Medicare Number</td>
								<td class="text-uppercase">
									@if($performer->pro->pro_type === 'ADMIN')
										{{$cpc->mcr_number ?? '-'}}
									@else
										{{$cpc->mcr_number ? mask_string($cpc->mcr_number, '*', 4) : '-'}}
									@endif
								</td>
							</tr>
							
							<tr>
								<td>Created At</td>
								<td class="text-uppercase">{{friendly_date_time($cpc->created_at)}}</td>
							</tr>

						</tbody>
					</table>
				</div>
				<div class="table-responsive">
					<h4 class="font-weight-bold">Other Coverage Details</h4>
					<table class="table table-sm table-bordered table-striped">
						<tbody>
							<tr>
								<td>Plan Effective Date</td>
								<td>{{ $cpc->plan_effective_date }}</td>
							</tr>
							<tr>
								<td>Plan Description</td>
								<td>{{ $cpc->plan_description }}</td>
							</tr>
							<tr>
								<td>Provider Status</td>
								<td>{{ $cpc->provider_status }}</td>
							</tr>
							<tr>
								<td>Mental Health Coverage</td>
								<td>{{ $cpc->mental_health_coverage }}</td>
							</tr>
							<tr>
								<td>Telehealth Coverage</td>
								<td>{{ $cpc->telehealth_coverage }}</td>
							</tr>
							<tr>
								<td>Deductible Amount</td>
								<td>{{ $cpc->deductible_amount }}</td>
							</tr>
							<tr>
								<td>Family Deductible</td>
								<td>{{ $cpc->family_deductible }}</td>
							</tr>
							<tr>
								<td>Member Accumulated Total</td>
								<td>{{ $cpc->member_accumulated_total }}</td>
							</tr>
							<tr>
								<td>Total Individual Balance</td>
								<td>{{ $cpc->total_individual_balance }}</td>
							</tr>
							<tr>
								<td>Total Family Balance</td>
								<td>{{ $cpc->total_family_balance }}</td>
							</tr>
						</tbody>
					</table>
				</div>
				@if($cpc->autoMedicareResult)
				<div class="table-responsive">
					<h4 class="font-weight-bold">Auto Medicare Result</h4>
					<table class="table table-sm table-bordered table-striped">
						<tbody>
							<tr>
								<td>Was Successful</td>
								<td>{{$cpc->autoMedicareResult->was_successful ? 'YES':'NO' }}</td>
							</tr>
							<tr>
								<td>Reject Reason Code</td>
								<td>{{$cpc->autoMedicareResult->reject_reason_code}}</td>
							</tr>
							<tr>
								<td>Reject Reason Description</td>
								<td>{{$cpc->autoMedicareResult->reject_reason_description}}</td>
							</tr>
							<tr>
								<td>Follow Up Action Code</td>
								<td>{{$cpc->autoMedicareResult->follow_up_action_code}}</td>
							</tr>
							<tr>
								<td>Follow Up Action Description</td>
								<td>{{$cpc->autoMedicareResult->follow_up_action_description}}</td>
							</tr>
							<tr>
								<td>Details</td>
								<td>{{$cpc->autoMedicareResult->details}}</td>
							</tr>
							<tr>
								<td>Is Mcn Valid Number</td>
								<td>{{$cpc->autoMedicareResult->is_mcn_valid_number}}</td>
							</tr>
							<tr>
								<td>Address Street Line1</td>
								<td>{{$cpc->autoMedicareResult->address_street_line1}}</td>
							</tr>
							<tr>
								<td>Address Street Line2</td>
								<td>{{$cpc->autoMedicareResult->address_street_line2}}</td>
							</tr>
							<tr>
								<td>Address City</td>
								<td>{{$cpc->autoMedicareResult->address_city}}</td>
							</tr>
							<tr>
								<td>Address State</td>
								<td>{{$cpc->autoMedicareResult->address_state}}</td>
							</tr>
							<tr>
								<td>Address Zip</td>
								<td>{{$cpc->autoMedicareResult->address_zip}}</td>
							</tr>
							<tr>
								<td>Is Partbprimary</td>
								<td>{{$cpc->autoMedicareResult->is_partbprimary}}</td>
							</tr>
							<tr>
								<td>Is Hospice</td>
								<td>{{$cpc->autoMedicareResult->is_hospice}}</td>
							</tr>
							<tr>
								<td>Mcn Response Detail</td>
								<td>
									@if($cpc->autoMedicareResult->mcn_response_detail)
									<?php $parsed = json_decode($cpc->autoMedicareResult->mcn_response_detail); ?>
									<?php parseRender($parsed); ?>
									@else
									&hyphen;
									@endif
								</td>
							</tr>
							<tr>
								<td>Billing Address</td>
								<td>{{$cpc->autoMedicareResult->billing_address}}</td>
							</tr>
							<tr>
								<td>Reason Not Partb</td>
								<td>{{$cpc->autoMedicareResult->reason_not_partb}}</td>
							</tr>
							<tr>
								<td>Reason Not Partbmemo</td>
								<td>{{$cpc->autoMedicareResult->reason_not_partbmemo}}</td>
							</tr>
							<tr>
								<td>Is Medicare Advantage</td>
								<td>{{$cpc->autoMedicareResult->is_medicare_advantage}}</td>
							</tr>
							<tr>
								<td>Medicare Advantage Plan</td>
								<td>{{$cpc->autoMedicareResult->medicare_advantage_plan}}</td>
							</tr>
						</tbody>
					</table>
				</div>
				@endif
			</div>

		</div>
		<div class="col-lg-7">
			<div class="mb-3">
				<h4 class="font-weight-bold">Manual Determination Information</h4>
				@if($cpc->creation_strategy === 'MANUAL_DETERMINATION')
				@if($cpc->plan_type == 'MEDICARE')
				@include('app.patient.primary-coverage-manual-determination-view-medicare', ['coverage' => $patient->getPrimaryCoverage()])
				@elseif($cpc->plan_type == 'MEDICAID')
				@include('app.patient.primary-coverage-manual-determination-view-medicaid', ['coverage' => $patient->getPrimaryCoverage()])
				@elseif($cpc->plan_type == 'COMMERCIAL')
				@include('app.patient.primary-coverage-manual-determination-view-commercial', ['coverage' => $patient->getPrimaryCoverage()])
				@else
				No plan Type specified.
				@endif
				@else
				<small class="text-muted">Not manually determined.</small>
				@endif
			</div>

			@if($cpc->is_manually_determined)
			<!-- Accordion -->
			<div class="card mb-1" stag-collapsible-card="mcp-key-numbers">
				<div class="card-header pl-2">
					<div class="d-flex align-items-center">
						<strong>
							Parent Coverage Information
						</strong>
						<a href="#" class="stag-collapse-trigger ml-auto"></a>
					</div>
				</div>
				<div class="card-body p-0 no-column-wrap">
					@include('app.patient.partials.display-coverage-details', ['displayCoverage' => $patient->latestManualParentClientPrimaryCoverage ])
				</div>
			</div>
			<!-- Accordion -->
			@endif
			@if($patient->latestAutoRefreshClientPrimaryCoverage)
			<!-- Accordion -->
			<div class="card mb-1" stag-collapsible-card="mcp-key-numbers">
				<div class="card-header pl-2">
					<div class="d-flex align-items-center">
						<strong>
							Latest Auto Refresh Coverage Information
						</strong>
						<a href="#" class="stag-collapse-trigger ml-auto"></a>
					</div>
				</div>
				<div class="card-body p-0 no-column-wrap">
					@include('app.patient.partials.display-coverage-details', ['displayCoverage' => $patient->latestAutoRefreshClientPrimaryCoverage ])
				</div>
			</div>
			<!-- Accordion -->
			@endif
		</div>
	</div>
</div>

<script type="text/javascript">
	var primaryCoverageLatestCoverage = new Vue({
		el: '#primaryCoverageLatestCoverage',
		data: {
			cpc: <?= json_encode($cpc); ?>,
		}
	})
</script>