<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Dettaglio Banca') }}
        </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>
                            {{ $banca->denominazione }}
                            @if($banca->filiale)
                                <small class="text-muted">- {{ $banca->filiale }}</small>
                            @endif
                        </h1>
                        <div>
            <a href="{{ route('admin.banche.edit', $banca) }}" class="btn btn-warning">
                <i class="fas fa-edit"></i>
                Modifica
            </a>
            <a href="{{ route('admin.banche.index') }}" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i>
                Torna all'Elenco
            </a>
        </div>
    </div>

    <div class="row">
        <!-- Informazioni principali -->
        <div class="col-lg-8">
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">Dati Bancari</h6>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <p><strong>Denominazione:</strong><br>{{ $banca->denominazione }}</p>
                        </div>
                        <div class="col-md-6">
                            @if($banca->filiale)
                                <p><strong>Filiale:</strong><br>{{ $banca->filiale }}</p>
                            @endif
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-3">
                            <p><strong>Codice ABI:</strong><br><code>{{ $banca->codice_abi }}</code></p>
                        </div>
                        <div class="col-md-3">
                            <p><strong>Codice CAB:</strong><br><code>{{ $banca->codice_cab }}</code></p>
                        </div>
                        <div class="col-md-6">
                            <p><strong>IBAN:</strong><br><code class="h6">{{ $banca->iban }}</code></p>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-6">
                            <p><strong>Saldo Corrente:</strong><br>
                                <span class="h5 badge badge-{{ $banca->saldo_corrente >= 0 ? 'success' : 'danger' }}">
                                    € {{ number_format($banca->saldo_corrente, 2, ',', '.') }}
                                </span>
                            </p>
                        </div>
                    </div>

                    @if($banca->indirizzo || $banca->citta || $banca->cap)
                        <hr>
                        <h6 class="font-weight-bold text-secondary">Indirizzo</h6>
                        <div class="row">
                            <div class="col-md-6">
                                @if($banca->indirizzo)
                                    <p><strong>Indirizzo:</strong><br>{{ $banca->indirizzo }}</p>
                                @endif
                            </div>
                            <div class="col-md-4">
                                @if($banca->citta)
                                    <p><strong>Città:</strong><br>{{ $banca->citta }}</p>
                                @endif
                            </div>
                            <div class="col-md-2">
                                @if($banca->cap)
                                    <p><strong>CAP:</strong><br>{{ $banca->cap }}</p>
                                @endif
                            </div>
                        </div>
                    @endif

                    @if($banca->telefono || $banca->email)
                        <hr>
                        <h6 class="font-weight-bold text-secondary">Contatti</h6>
                        <div class="row">
                            <div class="col-md-6">
                                @if($banca->telefono)
                                    <p><strong>Telefono:</strong><br>
                                        <a href="tel:{{ $banca->telefono }}">{{ $banca->telefono }}</a>
                                    </p>
                                @endif
                            </div>
                            <div class="col-md-6">
                                @if($banca->email)
                                    <p><strong>Email:</strong><br>
                                        <a href="mailto:{{ $banca->email }}">{{ $banca->email }}</a>
                                    </p>
                                @endif
                            </div>
                        </div>
                    @endif

                    @if($banca->note)
                        <hr>
                        <h6 class="font-weight-bold text-secondary">Note</h6>
                        <p>{{ $banca->note }}</p>
                    @endif
                </div>
            </div>

            <!-- Movimenti recenti -->
            <div class="card shadow mb-4">
                <div class="card-header py-3 d-flex justify-content-between align-items-center">
                    <h6 class="m-0 font-weight-bold text-primary">Movimenti Recenti</h6>
                    <a href="{{ route('admin.movimenti-bancari.index', ['banca' => $banca->id]) }}" class="btn btn-sm btn-outline-primary">
                        Vedi Tutti
                    </a>
                </div>
                <div class="card-body">
                    {{-- Qui potrebbero essere visualizzati i movimenti recenti se esiste la relazione --}}
                    <div class="text-center py-3">
                        <i class="fas fa-exchange-alt fa-2x text-gray-300 mb-2"></i>
                        <p class="text-muted">Nessun movimento recente</p>
                        <a href="{{ route('admin.movimenti-bancari.create', ['banca' => $banca->id]) }}" class="btn btn-sm btn-primary">
                            <i class="fas fa-plus"></i>
                            Nuovo Movimento
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <!-- Sidebar con azioni e informazioni -->
        <div class="col-lg-4">
            <!-- Azioni rapide -->
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-success">
                        <i class="fas fa-cogs"></i>
                        Azioni Rapide
                    </h6>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2">
                        <a href="{{ route('admin.movimenti-bancari.create', ['banca' => $banca->id]) }}" class="btn btn-outline-primary btn-sm">
                            <i class="fas fa-plus"></i>
                            Nuovo Movimento
                        </a>
                        <a href="{{ route('admin.movimenti-bancari.index', ['banca' => $banca->id]) }}" class="btn btn-outline-info btn-sm">
                            <i class="fas fa-list"></i>
                            Tutti i Movimenti
                        </a>
                        <hr>
                        <a href="{{ route('admin.banche.edit', $banca) }}" class="btn btn-outline-warning btn-sm">
                            <i class="fas fa-edit"></i>
                            Modifica Banca
                        </a>
                        <form action="{{ route('admin.banche.destroy', $banca) }}" method="POST" 
                              onsubmit="return confirm('Sei sicuro di voler eliminare questa banca?')">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-outline-danger btn-sm w-100">
                                <i class="fas fa-trash"></i>
                                Elimina Banca
                            </button>
                        </form>
                    </div>
                </div>
            </div>

            <!-- Informazioni di sistema -->
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-info">
                        <i class="fas fa-info-circle"></i>
                        Informazioni Sistema
                    </h6>
                </div>
                <div class="card-body">
                    <p class="small text-muted">
                        <strong>Creato il:</strong><br>
                        {{ $banca->created_at?->format('d/m/Y \a\l\l\e H:i') ?? 'N/D' }}
                    </p>
                    <p class="small text-muted">
                        <strong>Ultima modifica:</strong><br>
                        {{ $banca->updated_at?->format('d/m/Y \a\l\l\e H:i') ?? 'N/D' }}
                    </p>
                    @if($banca->updated_at && $banca->created_at)
                        <p class="small text-muted">
                            <strong>Ultima modifica fa:</strong><br>
                            {{ $banca->updated_at->diffForHumans() }}
                        </p>
                    @endif
                </div>
            </div>

            <!-- Statistiche -->
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-warning">
                        <i class="fas fa-chart-bar"></i>
                        Statistiche
                    </h6>
                </div>
                <div class="card-body">
                    <div class="text-center">
                        <div class="mb-2">
                            <span class="h4 text-primary">0</span>
                            <p class="small text-muted mb-0">Movimenti Totali</p>
                        </div>
                        <div class="mb-2">
                            <span class="h4 text-success">€ 0,00</span>
                            <p class="small text-muted mb-0">Entrate</p>
                        </div>
                        <div class="mb-2">
                            <span class="h4 text-danger">€ 0,00</span>
                            <p class="small text-muted mb-0">Uscite</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

                </div>
            </div>
        </div>
    </div>
</x-app-layout>
