@extends('layouts.app')
@section('title', 'Centros de Costo')
@section('content')
<div class="d-flex justify-content-between align-items-center mb-3">
    <h4 class="mb-0"><i class="bi bi-diagram-3 me-1"></i> Centros de Costo</h4>
    <a href="{{ route('centros-costo.create') }}" class="btn btn-primary btn-sm">
        <i class="bi bi-plus-circle me-1"></i> Nuevo
    </a>
</div>
<div class="card">
    <div class="card-body p-0">
        <table class="table table-hover mb-0">
            <thead class="table-light">
                <tr>
                    <th style="width:70px">Cód.</th>
                    <th>Nombre</th>
                    <th>Área</th>
                    <th class="text-center">Exento</th>
                    <th class="text-center">Estado</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @forelse($centros as $c)
                <tr>
                    <td><code>{{ $c->codigo }}</code></td>
                    <td>
                        {{ $c->nombre }}
                        @if($c->descripcion)
                            <i class="bi bi-info-circle text-muted ms-1" title="{{ $c->descripcion }}"></i>
                        @endif
                    </td>
                    <td>{{ $c->area }}</td>
                    <td class="text-center">
                        @if($c->es_exento)
                            <span class="badge badge-exento">Sí</span>
                        @else
                            <span class="text-muted">—</span>
                        @endif
                    </td>
                    <td class="text-center">
                        @if($c->activo) <span class="badge bg-success">Activo</span>
                        @else <span class="badge bg-secondary">Inactivo</span> @endif
                    </td>
                    <td>
                        <a href="{{ route('centros-costo.edit', $c) }}" class="btn btn-sm btn-outline-primary">
                            <i class="bi bi-pencil"></i>
                        </a>
                        <form action="{{ route('centros-costo.destroy', $c) }}" method="POST" class="d-inline">
                            @csrf @method('DELETE')
                            <button class="btn btn-sm btn-outline-danger"
                                onclick="return confirm('¿Eliminar?')">
                                <i class="bi bi-trash"></i>
                            </button>
                        </form>
                    </td>
                </tr>
                @empty
                <tr><td colspan="6" class="text-center text-muted py-3">Sin centros de costo.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    @if($centros->hasPages())
    <div class="card-footer">{{ $centros->links() }}</div>
    @endif
</div>
@endsection
