@extends('layouts.app')

@section('title', 'Contas Bancárias')

@section('header', 'Contas Bancárias')

@section('header-actions')
<a href="{{ route('bank-accounts.create') }}" class="btn btn-primary">
    <i class="fas fa-plus me-2"></i> Nova Conta
</a>
@endsection

@section('content')
<div class="card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>Nome</th>
                        <th>Banco</th>
                        <th>Tipo</th>
                        <th>Número</th>
                        <th>Saldo</th>
                        <th>Transações</th>
                        <th>Status</th>
                        <th>Ações</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($accounts as $account)
                    <tr>
                        <td>
                            <a href="{{ route('bank-accounts.show', $account) }}">
                                {{ $account->name }}
                            </a>
                        </td>
                        <td>{{ $account->bank_name }}</td>
                        <td>
                            <span class="badge bg-secondary">
                                {{ $account->type_name }}
                            </span>
                        </td>
                        <td>{{ $account->account_number }}</td>
                        <td class="{{ $account->balance >= 0 ? 'text-success' : 'text-danger' }}">
                            R$ {{ number_format($account->balance, 2, ',', '.') }}
                        </td>
                        <td>{{ $account->transactions_count }}</td>
                        <td>
                            <span class="badge bg-{{ $account->active ? 'success' : 'danger' }}">
                                {{ $account->active ? 'Ativa' : 'Inativa' }}
                            </span>
                        </td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="{{ route('bank-accounts.edit', $account) }}" 
                                   class="btn btn-outline-primary" title="Editar">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <a href="{{ route('imports.create', ['bank_account_id' => $account->id]) }}" 
                                   class="btn btn-outline-success" title="Importar Extrato">
                                    <i class="fas fa-file-import"></i>
                                </a>
                                <a href="{{ route('reconciliations.create', ['bank_account_id' => $account->id]) }}" 
                                   class="btn btn-outline-info" title="Conciliar">
                                    <i class="fas fa-balance-scale"></i>
                                </a>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="8" class="text-center py-4">
                            Nenhuma conta bancária cadastrada.
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection