@php $it = $item ?? null; @endphp
<div class="row g-2">
  <div class="col-md-1"><label class="form-label small">N°</label>
    <input type="number" name="numero_item" value="{{ old('numero_item', $it?->numero_item) }}" class="form-control form-control-sm"></div>
  <div class="col-md-7"><label class="form-label small">Descripción *</label>
    <textarea name="descripcion" class="form-control form-control-sm" rows="1" required>{{ old('descripcion', $it?->descripcion) }}</textarea></div>
  <div class="col-md-2"><label class="form-label small">Cód. componente</label>
    <input name="codigo_componente" value="{{ old('codigo_componente', $it?->codigo_componente) }}" class="form-control form-control-sm"></div>
  <div class="col-md-2"><label class="form-label small">Cambio/Lubricación</label>
    <input name="cambio_lubricacion" value="{{ old('cambio_lubricacion', $it?->cambio_lubricacion) }}" class="form-control form-control-sm"></div>

  <div class="col-md-2"><label class="form-label small">Componente catálogo</label>
    <select name="componente_id" class="form-select form-select-sm"><option value="">—</option>
      @foreach(\App\Models\Componente::where('activo',1)->orderBy('nombre')->get() as $cp)
        <option value="{{ $cp->id }}" @selected(old('componente_id', $it?->componente_id)==$cp->id)>{{ $cp->codigo }} - {{ $cp->nombre }}</option>
      @endforeach
    </select></div>
  <div class="col-md-1"><label class="form-label small">Cantidad</label>
    <input type="number" step="0.001" name="cantidad" value="{{ old('cantidad', $it?->cantidad ?? 1) }}" class="form-control form-control-sm"></div>
  <div class="col-md-2"><label class="form-label small">Unidad</label>
    <select name="unidad_id" class="form-select form-select-sm"><option value="">—</option>
      @foreach($unidades as $u)<option value="{{ $u->id }}" @selected(old('unidad_id', $it?->unidad_id)==$u->id)>{{ $u->codigo }}</option>@endforeach
    </select></div>
  <div class="col-md-2"><label class="form-label small">Frecuencia</label>
    <select name="frecuencia_id" class="form-select form-select-sm"><option value="">—</option>
      @foreach($frecuencias as $f)<option value="{{ $f->id }}" @selected(old('frecuencia_id', $it?->frecuencia_id)==$f->id)>{{ $f->nombre }}</option>@endforeach
    </select></div>
  <div class="col-md-2"><label class="form-label small">Tipo mantenimiento</label>
    <select name="tipo_mantenimiento_id" class="form-select form-select-sm"><option value="">—</option>
      @foreach($tipos as $t)<option value="{{ $t->id }}" @selected(old('tipo_mantenimiento_id', $it?->tipo_mantenimiento_id)==$t->id)>{{ $t->nombre }}</option>@endforeach
    </select></div>
  <div class="col-md-3"><label class="form-label small">Responsable</label>
    <select name="responsable_id" class="form-select form-select-sm"><option value="">—</option>
      @foreach($usuarios as $u)<option value="{{ $u->id }}" @selected(old('responsable_id', $it?->responsable_id)==$u->id)>{{ $u->nombre_completo ?: $u->usuario }}</option>@endforeach
    </select></div>

  <div class="col-12"><div class="row g-2">
    @foreach([['lila_l_limpieza','L (limpieza)'],['lila_i_inspeccion','I (inspección)'],
              ['lila_l_lubricacion','Lu (lubricación)'],['lila_a_ajuste','A (ajuste)'],
              ['pm_360','PM 01 - 360h'],['pm_720','PM 02 - 720h'],
              ['pm_4320','PM 03 - 4320h'],['pm_8640','PM 04 - 8640h']] as [$campo,$lbl])
      <div class="col-md-3 col-6">
        <div class="form-check">
          <input type="hidden" name="{{ $campo }}" value="0">
          <input type="checkbox" name="{{ $campo }}" value="1" class="form-check-input" {{ old($campo, $it?->$campo)?'checked':'' }}>
          <label class="form-check-label small">{{ $lbl }}</label>
        </div>
      </div>
    @endforeach
  </div></div>

  <div class="col-md-3"><label class="form-label small">Costo estimado</label>
    <input type="number" step="0.01" name="costo_estimado" value="{{ old('costo_estimado', $it?->costo_estimado) }}" class="form-control form-control-sm"></div>
  <div class="col-md-3"><label class="form-label small">Costo promedio</label>
    <input type="number" step="0.01" name="costo_promedio" value="{{ old('costo_promedio', $it?->costo_promedio) }}" class="form-control form-control-sm"></div>
  <div class="col-md-3"><label class="form-label small">Costo actual</label>
    <input type="number" step="0.01" name="costo_actual" value="{{ old('costo_actual', $it?->costo_actual) }}" class="form-control form-control-sm"></div>
  <div class="col-md-3 d-flex align-items-end">
    <div class="form-check form-switch">
      <input type="hidden" name="activo" value="0">
      <input type="checkbox" name="activo" value="1" class="form-check-input" {{ old('activo', $it?->activo ?? 1)?'checked':'' }}>
      <label class="form-check-label small">Activo</label>
    </div>
  </div>
  <div class="col-12"><label class="form-label small">Observaciones</label>
    <textarea name="observaciones" class="form-control form-control-sm" rows="1">{{ old('observaciones', $it?->observaciones) }}</textarea></div>
</div>
