<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Gestione Banche') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900 dark:text-gray-100">
                    
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h1 class="h3 mb-0 text-gray-800">
                            <i class="fas fa-university"></i>
                            Gestione Banche
                        </h1>
                        <a href="{{ route('admin.banche.create') }}" class="btn btn-primary">
                            <i class="fas fa-plus"></i>
                            Nuova Banca
                        </a>
                    </div>

    @if(session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
    @endif

    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Elenco Banche</h6>
        </div>
        <div class="card-body">
            @if($banche->count() > 0)
                <div class="table-responsive">
                    <table class="table table-bordered" id="dataTable">
                        <thead>
                            <tr>
                                <th>Denominazione</th>
                                <th>Codice ABI</th>
                                <th>Codice CAB</th>
                                <th>IBAN</th>
                                <th>Saldo Corrente</th>
                                <th class="text-center">Azioni</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($banche as $banca)
                                <tr>
                                    <td>
                                        <strong>{{ $banca->denominazione }}</strong>
                                        @if($banca->filiale)
                                            <br><small class="text-muted">{{ $banca->filiale }}</small>
                                        @endif
                                    </td>
                                    <td>{{ $banca->codice_abi }}</td>
                                    <td>{{ $banca->codice_cab }}</td>
                                    <td>
                                        <code>{{ $banca->iban }}</code>
                                    </td>
                                    <td class="text-right">
                                        <span class="badge badge-{{ $banca->saldo_corrente >= 0 ? 'success' : 'danger' }}">
                                            € {{ number_format($banca->saldo_corrente, 2, ',', '.') }}
                                        </span>
                                    </td>
                                    <td class="text-center">
                                        <a href="{{ route('admin.banche.show', $banca) }}" class="btn btn-sm btn-info" title="Visualizza">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                        <a href="{{ route('admin.banche.edit', $banca) }}" class="btn btn-sm btn-warning" title="Modifica">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        <form action="{{ route('admin.banche.destroy', $banca) }}" method="POST" class="d-inline" onsubmit="return confirm('Sei sicuro di voler eliminare questa banca?')">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-sm btn-danger" title="Elimina">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>

                <div class="d-flex justify-content-center">
                    {{ $banche->links() }}
                </div>
            @else
                <div class="text-center py-4">
                    <i class="fas fa-university fa-3x text-gray-300 mb-3"></i>
                    <h5 class="text-gray-500">Nessuna banca presente</h5>
                    <p class="text-gray-400 mb-4">Inizia aggiungendo la prima banca del condominio.</p>
                    <a href="{{ route('admin.banche.create') }}" class="btn btn-primary">
                        <i class="fas fa-plus"></i>
                        Aggiungi Prima Banca
                    </a>
                </div>
            @endif
        </div>
                </div>
            </div>
        </div>
    </div>

    @push('scripts')
    <script>
    $(document).ready(function() {
        $('#dataTable').DataTable({
            "language": {
                "url": "//cdn.datatables.net/plug-ins/1.10.24/i18n/Italian.json"
            },
            "pageLength": 25,
            "order": [[ 0, "asc" ]],
            "columnDefs": [
                { "orderable": false, "targets": -1 }
            ]
        });
    });
    </script>
    @endpush
</x-app-layout>
