<?php $__env->startSection('titulo','Plan'); ?>
<?php $__env->startSection('contenido'); ?>
<?php $editando = (bool) $plan->id; ?>
<h4><i class="fa fa-clipboard-list"></i> <?php echo e($editando?'Editar':'Nuevo'); ?> plan (<?php echo e(ucfirst($plan->clase)); ?>)</h4>
<form method="POST" action="<?php echo e($editando ? route('planes.update',$plan) : route('planes.store')); ?>" class="card p-3 mb-3">
  <?php echo csrf_field(); ?> <?php if($editando): ?> <?php echo method_field('PUT'); ?> <?php endif; ?>
  <div class="row g-3">
    <div class="col-md-3"><label class="form-label small">Código</label>
      <input name="codigo" value="<?php echo e(old('codigo',$plan->codigo)); ?>" class="form-control" placeholder="Auto si se deja vacío"></div>
    <div class="col-md-6"><label class="form-label small">Nombre *</label>
      <input name="nombre" value="<?php echo e(old('nombre',$plan->nombre)); ?>" class="form-control" required></div>
    <div class="col-md-3"><label class="form-label small">Clase *</label>
      <select name="clase" class="form-select" required>
        <option value="preventivo" <?php if(old('clase',$plan->clase)==='preventivo'): echo 'selected'; endif; ?>>Preventivo</option>
        <option value="correctivo" <?php if(old('clase',$plan->clase)==='correctivo'): echo 'selected'; endif; ?>>Correctivo</option>
      </select></div>
    <div class="col-md-3"><label class="form-label small">Área</label>
      <select name="area_id" class="form-select"><option value="">—</option>
        <?php $__currentLoopData = $areas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $a): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($a->id); ?>" <?php if(old('area_id',$plan->area_id)==$a->id): echo 'selected'; endif; ?>><?php echo e($a->nombre); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </select></div>
    <div class="col-md-3"><label class="form-label small">Sistema</label>
      <select name="sistema_id" class="form-select"><option value="">—</option>
        <?php $__currentLoopData = $sistemas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($s->id); ?>" <?php if(old('sistema_id',$plan->sistema_id)==$s->id): echo 'selected'; endif; ?>><?php echo e($s->nombre); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </select></div>
    <div class="col-md-3"><label class="form-label small">Equipo</label>
      <select name="equipo_id" class="form-select"><option value="">—</option>
        <?php $__currentLoopData = $equipos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($e->id); ?>" <?php if(old('equipo_id',$plan->equipo_id)==$e->id): echo 'selected'; endif; ?>><?php echo e($e->codigo); ?> — <?php echo e($e->nombre); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </select></div>
    <div class="col-md-3"><label class="form-label small">Inicio</label>
      <input type="date" name="fecha_inicio" value="<?php echo e(old('fecha_inicio',optional($plan->fecha_inicio)->format('Y-m-d'))); ?>" class="form-control"></div>
    <div class="col-md-3"><label class="form-label small">Fin</label>
      <input type="date" name="fecha_fin" value="<?php echo e(old('fecha_fin',optional($plan->fecha_fin)->format('Y-m-d'))); ?>" class="form-control"></div>
    <div class="col-md-12"><label class="form-label small">Descripción</label>
      <textarea name="descripcion" class="form-control" rows="2"><?php echo e(old('descripcion',$plan->descripcion)); ?></textarea></div>
    <div class="col-md-12"><label class="form-label small">Observaciones</label>
      <textarea name="observaciones" class="form-control" rows="2"><?php echo e(old('observaciones',$plan->observaciones)); ?></textarea></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" <?php echo e(old('activo',$plan->activo??1)?'checked':''); ?>>
        <label class="form-check-label">Activo</label>
      </div>
    </div>
  </div>
  <div class="mt-3 text-end">
    <a href="<?php echo e(route('planes.index',['clase'=>$plan->clase])); ?>" class="btn btn-outline-secondary">Volver</a>
    <button class="btn btn-primario"><i class="fa fa-save"></i> Guardar</button>
  </div>
</form>

<?php if($editando): ?>
  <div class="card">
    <div class="card-header bg-light d-flex justify-content-between"><strong><i class="fa fa-list"></i> Ítems del plan</strong>
      <button class="btn btn-sm btn-primario" data-bs-toggle="collapse" data-bs-target="#nuevoItem">
        <i class="fa fa-plus"></i> Agregar ítem</button>
    </div>
    <div id="nuevoItem" class="collapse">
      <form method="POST" action="<?php echo e(route('planes.items.store', $plan)); ?>" class="p-3 border-bottom">
        <?php echo csrf_field(); ?>
        <?php echo $__env->make('planes.partials.item_form', ['item' => null], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        <div class="text-end mt-2"><button class="btn btn-primario btn-sm">Agregar</button></div>
      </form>
    </div>
    <div class="table-responsive">
      <table class="table table-sm mb-0 align-middle">
        <thead><tr>
          <th>#</th><th>Descripción</th><th>Componente</th><th>Cant.</th><th>Frec.</th>
          <th class="text-center">L</th><th class="text-center">I</th><th class="text-center">Lu</th><th class="text-center">A</th>
          <th class="text-center">PM360</th><th class="text-center">PM720</th><th class="text-center">PM4320</th><th class="text-center">PM8640</th>
          <th>Tipo</th><th>Resp.</th><th class="text-end">Costo est.</th><th></th>
        </tr></thead>
        <tbody>
        <?php $__empty_1 = true; $__currentLoopData = $plan->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $it): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
          <tr>
            <td><?php echo e($it->numero_item); ?></td>
            <td><?php echo e(Str::limit($it->descripcion, 60)); ?></td>
            <td><small><?php echo e($it->codigo_componente ?? optional($it->componente)->codigo); ?></small></td>
            <td><?php echo e($it->cantidad); ?></td>
            <td><?php echo e(optional($it->frecuencia)->codigo); ?></td>
            <?php $__currentLoopData = ['lila_l_limpieza','lila_i_inspeccion','lila_l_lubricacion','lila_a_ajuste',
                      'pm_360','pm_720','pm_4320','pm_8640']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $f): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <td class="text-center"><?php if($it->$f): ?><i class="fa fa-check text-success"></i><?php endif; ?></td>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <td><small><?php echo e(optional($it->tipoMantenimiento)->codigo); ?></small></td>
            <td><small><?php echo e(optional($it->responsable)->usuario); ?></small></td>
            <td class="text-end"><?php echo e(number_format($it->costo_estimado, 2)); ?></td>
            <td class="text-end">
              <a href="#" class="btn btn-sm btn-outline-primary" data-bs-toggle="collapse" data-bs-target="#editItem<?php echo e($it->id); ?>"><i class="fa fa-pen"></i></a>
              <form method="POST" action="<?php echo e(route('planes.items.destroy',[$plan,$it])); ?>" class="d-inline" onsubmit="return confirm('¿Eliminar?');">
                <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?><button class="btn btn-sm btn-outline-danger"><i class="fa fa-trash"></i></button></form>
            </td>
          </tr>
          <tr id="editItem<?php echo e($it->id); ?>" class="collapse"><td colspan="17" class="bg-light">
            <form method="POST" action="<?php echo e(route('planes.items.update',[$plan,$it])); ?>"><?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
              <?php echo $__env->make('planes.partials.item_form', ['item' => $it], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
              <div class="text-end mt-2"><button class="btn btn-sm btn-primario">Guardar</button></div>
            </form>
          </td></tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
          <tr><td colspan="17" class="text-center text-muted py-3">Sin ítems</td></tr>
        <?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\mto\resources\views/planes/form.blade.php ENDPATH**/ ?>