@extends('layouts.app')
@section('titulo','Planes '.$clase)
@section('contenido')
<div class="d-flex flex-wrap justify-content-between align-items-center mb-3">
  <h4><i class="fa fa-clipboard-list"></i> Planes maestros — {{ ucfirst($clase) }}</h4>
  @can('planes.crear')
    <a href="{{ route('planes.create', ['clase'=>$clase]) }}" class="btn btn-primario"><i class="fa fa-plus"></i> Nuevo plan</a>
  @endcan
</div>
<form method="GET" class="row g-2 mb-3">
  <input type="hidden" name="clase" value="{{ $clase }}">
  <div class="col-md-4"><input name="q" value="{{ $busqueda }}" class="form-control" placeholder="Código o nombre..."></div>
  <div class="col-md-3"><select name="area_id" class="form-select"><option value="">— Área —</option>
    @foreach($areas as $a)<option value="{{ $a->id }}" @selected($area_id==$a->id)>{{ $a->nombre }}</option>@endforeach
  </select></div>
  <div class="col-md-2"><button class="btn btn-outline-primary w-100"><i class="fa fa-filter"></i> Filtrar</button></div>
</form>
<div class="card"><div class="table-responsive"><table class="table table-hover mb-0">
<thead><tr><th>Código</th><th>Nombre</th><th>Área</th><th>Equipo</th><th>Vigencia</th><th>Ítems</th><th>Activo</th><th></th></tr></thead><tbody>
@forelse($registros as $p)
<tr>
  <td><strong>{{ $p->codigo }}</strong></td>
  <td>{{ $p->nombre }}</td>
  <td>{{ optional($p->area)->nombre }}</td>
  <td>{{ optional($p->equipo)->nombre }}</td>
  <td><small>{{ $p->fecha_inicio?->format('d/m/Y') }} → {{ $p->fecha_fin?->format('d/m/Y') }}</small></td>
  <td>{{ $p->items_count }}</td>
  <td><span class="badge text-bg-{{ $p->activo?'success':'secondary' }}">{{ $p->activo?'Sí':'No' }}</span></td>
  <td class="text-end">
    <a href="{{ route('planes.show',$p) }}" class="btn btn-sm btn-outline-info"><i class="fa fa-eye"></i></a>
    <a href="{{ route('planes.edit',$p) }}" class="btn btn-sm btn-outline-primary"><i class="fa fa-pen"></i></a>
    <a href="{{ route('planes.pdf',$p) }}" target="_blank" class="btn btn-sm btn-outline-danger"><i class="fa fa-file-pdf"></i></a>
    <form method="POST" action="{{ route('planes.destroy',$p) }}" class="d-inline" onsubmit="return confirm('¿Eliminar plan?');">
      @csrf @method('DELETE')<button class="btn btn-sm btn-outline-danger"><i class="fa fa-trash"></i></button></form>
  </td>
</tr>
@empty <tr><td colspan="8" class="text-muted text-center py-4">Sin planes</td></tr> @endforelse
</tbody></table></div></div>
<div class="mt-2">{{ $registros->links() }}</div>
@endsection
