<div class="table-responsive">
    @php
        $coverage = $patient->getPrimaryCoverage();
        $mcnDetails = json_decode($patient->mcn_response_detail ?? null);
    @endphp
    @if(!$coverage)
        <table class="table table-sm table-bordered mb-0">
          <tr>
            <td>
              <b>No coverage info!</b>
            </td>
          </tr>
        </table>
    @elseif($coverage->plan_type === 'MEDICARE')
      @if($coverage->creation_strategy == 'NEW' || $coverage->creation_strategy == 'AUTO_REFRESH')
      <table class="table table-sm table-bordered mb-0">
        <tr>
          <td class="font-weight-bold">Medicare Part B<br>(Primary)</td>
          <td>
            @if($mcnDetails && $mcnDetails->plan_details)
            <span class="font-weight-bold">{{ $mcnDetails->plan_details->MC->payer_name }}</span> <br>
              @if($mcnDetails->plan_details && $mcnDetails->plan_details->MC && $mcnDetails->plan_details->MC->contacts)
	      @foreach($mcnDetails->plan_details->MC->contacts as $contact)
                @if($contact->contact_type == 'telephone')
                  <a href="tel:{{ $contact->contact_value }}"><b><i class="fas fa-phone-alt"></i></b> {{ $contact->contact_value }}</a> <br>
                @endif
              @endforeach
	      @endif
            @endif
            @if($coverage->auto_medicare_is_partbprimary == 'YES')
              <span><i class="fas fa-check-circle text-success"></i> <b>Part B Primary:</b> YES (auto)</span> <br>
            @elseif(!$coverage->auto_medicare_is_match_found)
              <span><i class="fas fa-times text-danger"></i> record not found (auto)</span> <br>
            @else
              <span><i class="fas fa-check-circle text-success"></i> record found</span> <br>
              <span><i class="fas fa-times text-danger"></i> <b>Part B Primary:</b> {{$coverage->auto_medicare_is_partbprimary}}</span> <br>
              <span><b>Part B Active:</b> {{$coverage->auto_medicare_is_partbactive}}</span> <br>
              <span><b>Part C Active:</b> {{$coverage->auto_medicare_is_partcactive}}</span>
            @endif
          </td>
        </tr>
        @if($coverage->auto_medicare_is_partbactive == 'YES' && !$coverage->auto_medicare_is_partcactive)
        <tr>
          <td class="font-weight-bold">Part B Deductible</td>
          <td>{{number_format($coverage->auto_medicare_mpb_deductible, 2, '.',',') ?? '-'}}</td>
        </tr>
        <tr>
          <td class="font-weight-bold">Part B Remaining</td>
          <td>{{number_format($coverage->auto_medicare_mpb_remaining,2, '.',',') ?? '-'}}</td>
        </tr>
        @endif
        @if($coverage->manual_determination_category_memo)
        <tr>
          <td><b>Manual Determination Memo: </b></td>
          <td>{{$coverage->manual_determination_category_memo}}</td>
        </tr>
        @endif
      </table>
      @else
      <!-- Manual determination -->
      <table class="table table-sm table-bordered mb-0">
        <tr>
          <td class="font-weight-bold">Medicare Part B<br>(Primary)</td>
          <td>
            @if($mcnDetails && $mcnDetails->plan_details)
              <span class="font-weight-bold">{{ $mcnDetails->plan_details->MC->payer_name }}</span> <br>
              @if($mcnDetails->plan_details->MC->contacts)
              @foreach($mcnDetails->plan_details->MC->contacts as $contact)
                @if($contact->contact_type == 'telephone')
                  <a href="tel:{{ $contact->contact_value }}"><b><i class="fas fa-phone-alt"></i></b> {{ $contact->contact_value }}</a> <br>
                @endif
              @endforeach
              @endif
            @endif

            @if($coverage->manual_medicare_is_partbprimary == 'YES')
              <span><i class="fas fa-check-circle text-success"></i> <b>Part B Primary:</b> YES ({{strtolower(implode(' ', explode('_', strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy))))))}})</span> <br>
            @elseif($coverage->manual_medicare_is_matched == 'NO')
              <span><i class="fas fa-times text-danger"></i> record not found ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span> <br>
            @else
              <span><i class="fas fa-check-circle text-success"></i> record found</span> <br>
              <span><i class="fas fa-times text-danger"></i> <b>Part B Primary:</b> {{$coverage->manual_medicare_is_partbprimary}}</span> <br>
              <span><b>Part B Active:</b> {{$coverage->manual_medicare_is_partbactive}}</span> <br>
              @if($coverage->manual_medicare_is_partcactive)
              <span><b>Part C Active:</b> {{$coverage->manual_medicare_is_partcactive}}</span>
              @endif
              @endif
          </td>
        </tr>
        @if($coverage->auto_medicare_is_partbactive && !$coverage->manual_medicare_is_partcactive)
        <tr>
          <td class="font-weight-bold">Part B Deductible</td>
          <td>{{number_format($coverage->auto_medicare_mpb_deductible,2,'.',',') ?? '-'}}</td>
        </tr>
        <tr>
          <td class="font-weight-bold">Part B Remaining</td>
          <td>{{number_format($coverage->auto_medicare_mpb_remaining, 2, '.',',') ?? '-'}}</td>
        </tr>
        @endif
        @if($coverage->manual_determination_category_memo)
        <tr>
          <td><b>Manual Determination Memo: </b></td>
          <td>{{$coverage->manual_determination_category_memo}}</td>
        </tr>
        @endif
      </table>
      @endif

    @elseif($coverage->plan_type === 'MEDICAID')
      @if($coverage->creation_strategy == 'NEW' || $coverage->creation_strategy == 'AUTO_REFRESH')
      <table class="table table-sm table-bordered mb-0">
        <tr>
          <td class="font-weight-bold">Medicaid<br>(Primary):</td>
          <td>
            <span class="coverage-payer-name" title="{{$coverage->mcdPayer->name ?? '-'}}"><b>{{$coverage->mcdPayer->name ?? '-'}}</b></span> <br>
            <span><i class="fas fa-hourglass-half text-warning"></i> Pending Validation</span> <br>
          </td>
        </tr>
        <tr>
          <td class="font-weight-bold">Date Created:</td>
          <td><span>{{date_format($coverage->created_at, 'm/d/Y')}}</span></td>
        </tr>
        @if($coverage->manual_determination_category_memo)
        <tr>
          <td><b>Manual Determination Memo: </b></td>
          <td>{{$coverage->manual_determination_category_memo}}</td>
        </tr>
        @endif
      </table>
      @else
        <table class="table table-sm table-bordered mb-0">
          <tr>
            <td class="font-weight-bold">Medicaid<br>(Primary):</td>
            <td>
              <span class="coverage-payer-name" title="{{$coverage->mcd_payer_name ?? '-'}}"><b>{{$coverage->mcd_payer_name ?? '-'}}</b></span> <br>
              @if($coverage->manual_determination_category == 'COVERED')
              <span><i class="fas fa-check-circle text-success"></i></span>
              @elseif($coverage->manual_determination_category == 'NOT_COVERED')
              <span><i class="fas fa-check-circle text-success"></i> record found</span> <br>
              <span><i class="fas fa-times text-danger"></i> not covered ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
              @elseif($coverage->manual_determination_category == 'INVALID')
              <span><i class="fas fa-times text-danger"></i> record not found ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
              @else
              <span><i class="fas fa-hourglass-half text-warning"></i> pending ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
              @endif
            </td>
          </tr>
          @if($coverage->manual_determination_category_memo)
          <tr>
            <td><b>Manual Determination Memo: </b></td>
            <td>{{$coverage->manual_determination_category_memo}}</td>
          </tr>
          @endif
        </table>
      @endif

    @elseif($coverage->plan_type === 'COMMERCIAL')
      @if($coverage->creation_strategy == 'NEW' || $coverage->creation_strategy == 'AUTO_REFRESH')
      <table class="table table-sm table-bordered mb-0">
        <tr>
          <td class="font-weight-bold">Commercial<br>(Primary):</td>
          <td>
            <span class="coverage-payer-name" title="{{$coverage->payer->name ?? '-'}}"><b>{{$coverage->payer->name ?? '-'}}</b></span> <br>
            <span><i class="fas fa-hourglass-half text-warning"></i> Pending Validation</span> <br>
          </td>
        </tr>
        <tr>
          <td class="font-weight-bold">Date Created:</td>
          <td><span>{{date_format($coverage->created_at, 'm/d/Y')}}</span></td>
        </tr>
        @if($coverage->manual_determination_category_memo)
        <tr>
          <td><b>Manual Determination Memo: </b></td>
          <td>{{$coverage->manual_determination_category_memo}}</td>
        </tr>
        @endif
      </table>
      @else
        <table class="table table-sm table-bordered mb-0">
          <tr>
            <td class="font-weight-bold">Commercial<br>(Primary):</td>
            <td>
              <span class="coverage-payer-name" title="{{$coverage->payer->name ?? '-'}}"><b>{{$coverage->payer->name ?? '-'}}</b></span> <br>
              @if($coverage->manual_determination_category == 'COVERED')
              <span><i class="fas fa-check-circle text-success"></i></span>
              @elseif($coverage->manual_determination_category == 'NOT_COVERED')
              <span><i class="fas fa-check-circle text-success"></i> record found</span> <br>
              <span><i class="fas fa-times text-danger"></i> not covered ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
              @elseif($coverage->manual_determination_category == 'INVALID')
              <span><i class="fas fa-times text-danger"></i> record not found ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
              @else
              <span><i class="fas fa-hourglass-half text-warning"></i> pending ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
              @endif
            </td>
          </tr>
          @if($coverage->manual_determination_category_memo)
          <tr>
            <td><b>Manual Determination Memo: </b></td>
            <td>{{$coverage->manual_determination_category_memo}}</td>
          </tr>
          @endif
        </table>
      @endif
    @endif
</div>
