{{-- Counts tab — sponge / instrument / needle. Discrepancy computed on save. --}}
<div class="tab-pane" id="tab_counts">
  <p class="text-muted">@lang('medsurgery::lang.counts_help')</p>

  <div class="row">
    @foreach($countTypes as $type)
      @php $ct = $countsByType[$type] ?? null; @endphp
      <div class="col-md-4">
        @component('components.widget', ['class' => 'box-default'])
          <form class="medsx-form" action="{{ route('medsx.cases.count', $case->id) }}" method="POST" data-reload="true">
            {{ csrf_field() }}
            <input type="hidden" name="count_type" value="{{ $type }}">
            <div class="clearfix" style="margin-bottom:6px;">
              <strong>@lang('medsurgery::lang.count_' . $type)</strong>
              @if($ct && $ct->discrepancy)
                <span class="label label-danger pull-right"><i class="fa fa-exclamation-triangle"></i> @lang('medsurgery::lang.discrepancy')</span>
              @elseif($ct)
                <span class="label label-success pull-right">@lang('medsurgery::lang.no_discrepancy')</span>
              @endif
            </div>
            <div class="form-group">
              <label>@lang('medsurgery::lang.pre_count')</label>
              <input type="number" min="0" name="pre_count" class="form-control input-sm" value="{{ $ct->pre_count ?? 0 }}">
            </div>
            <div class="form-group">
              <label>@lang('medsurgery::lang.close_count')</label>
              <input type="number" min="0" name="close_count" class="form-control input-sm" value="{{ $ct->close_count ?? '' }}">
            </div>
            <div class="form-group">
              <label>@lang('medsurgery::lang.final_count')</label>
              <input type="number" min="0" name="final_count" class="form-control input-sm" value="{{ $ct->final_count ?? '' }}">
            </div>
            <button type="submit" class="btn btn-primary btn-sm">@lang('medsurgery::lang.save_count')</button>
          </form>
        @endcomponent
      </div>
    @endforeach
  </div>

  @if($countsByType->contains('discrepancy', true))
    <div class="callout callout-danger">
      <i class="fa fa-exclamation-triangle"></i>
      @lang('medsurgery::lang.gate_count_discrepancy')
    </div>
  @endif
</div>
