{{-- Patient policy create/edit modal form. --}}
@php $isEdit = $policy->exists; @endphp
<div class="modal-dialog" role="document">
  <div class="modal-content">
    <form class="medbill-form"
        action="{{ $isEdit ? route('medbill.policies.update', $policy->id) : route('medbill.policies.store') }}"
        method="POST">
      {{ csrf_field() }}
      @if($isEdit) {{ method_field('PUT') }} @endif
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">{{ $isEdit ? __('medbilling::lang.edit_policy') : __('medbilling::lang.add_policy') }}</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-6 form-group">
            <label>@lang('medbilling::lang.patient') *</label>
            <select name="patient_id" class="form-control" required>
              <option value="">—</option>
              @foreach($patients as $id => $name)
                <option value="{{ $id }}" @selected((int) $policy->patient_id === (int) $id)>{{ $name }}</option>
              @endforeach
            </select>
          </div>
          <div class="col-md-6 form-group">
            <label>@lang('medbilling::lang.payer') *</label>
            <select name="payer_id" class="form-control" required>
              <option value="">—</option>
              @foreach($payers as $id => $name)
                <option value="{{ $id }}" @selected((int) $policy->payer_id === (int) $id)>{{ $name }}</option>
              @endforeach
            </select>
          </div>
        </div>
        <div class="row">
          <div class="col-md-6 form-group">
            <label>@lang('medbilling::lang.policy_number') *</label>
            <input type="text" name="policy_number" class="form-control" required value="{{ $policy->policy_number }}">
          </div>
          <div class="col-md-6 form-group">
            <label>@lang('medbilling::lang.plan_name')</label>
            <input type="text" name="plan_name" class="form-control" value="{{ $policy->plan_name }}">
          </div>
        </div>
        <div class="row">
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.coverage_pct') *</label>
            <input type="number" step="0.01" min="0" max="100" name="coverage_pct" class="form-control" required
                value="{{ $policy->coverage_pct !== null ? $policy->coverage_pct : 100 }}">
          </div>
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.copay_fixed')</label>
            <input type="number" step="0.0001" min="0" name="copay_fixed" class="form-control" value="{{ $policy->copay_fixed ?? 0 }}">
          </div>
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.annual_limit')</label>
            <input type="number" step="0.0001" min="0" name="annual_limit" class="form-control" value="{{ $policy->annual_limit }}">
          </div>
        </div>
        <div class="row">
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.effective_from')</label>
            <input type="date" name="effective_from" class="form-control" value="{{ optional($policy->effective_from)->format('Y-m-d') }}">
          </div>
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.expiry_date')</label>
            <input type="date" name="expiry_date" class="form-control" value="{{ optional($policy->expiry_date)->format('Y-m-d') }}">
          </div>
          <div class="col-md-4 form-group">
            <label>@lang('medbilling::lang.status') *</label>
            <select name="status" class="form-control" required>
              @foreach(['active','expired','cancelled'] as $st)
                <option value="{{ $st }}" @selected(($policy->status ?? 'active') === $st)>@lang('medbilling::lang.status_' . $st)</option>
              @endforeach
            </select>
          </div>
        </div>
        <div class="form-group">
          <label>@lang('medbilling::lang.insurance_card')</label>
          <select name="clc_patient_insurance_id" class="form-control">
            <option value="">@lang('medbilling::lang.none')</option>
            @foreach($cards as $id => $label)
              <option value="{{ $id }}" @selected((int) $policy->clc_patient_insurance_id === (int) $id)>{{ $label }}</option>
            @endforeach
          </select>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">@lang('medbilling::lang.cancel')</button>
        <button type="submit" class="btn btn-primary">@lang('medbilling::lang.save')</button>
      </div>
    </form>
  </div>
</div>
