@extends('layouts.app')
@section('title', 'Payment Methods')
@section('page_title', 'Payment Methods')
@section('breadcrumbs')
    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Home</a></li>
    <li class="breadcrumb-item active">Payment Methods</li>
@endsection
@section('page_actions')
    @can('fees.update')
        <a href="{{ route('payment-methods.create') }}" class="btn btn-primary"><i class="bi bi-plus-lg me-1"></i>Add Method</a>
    @endcan
@endsection

@section('content')
    <div class="card"><div class="card-body">
        <p class="text-muted small mb-3">
            Methods shown here appear when collecting a fee. Disable a closed account to keep its history while hiding it from new payments.
        </p>
        <div class="table-responsive">
            <table class="table table-hover align-middle">
                <thead><tr>
                    <th>Name</th><th>Type</th><th>Account Number</th><th>Title</th><th>Ledger Account</th>
                    <th class="text-center">Status</th><th class="text-end">Actions</th>
                </tr></thead>
                <tbody>
                    @forelse($methods as $m)
                        <tr class="{{ $m->is_active ? '' : 'text-muted' }}">
                            <td class="fw-semibold">{{ $m->name }}</td>
                            <td><span class="badge bg-soft-primary">{{ $m->channel_label }}</span></td>
                            <td class="small">{{ $m->account_number ?: '—' }}</td>
                            <td class="small">{{ $m->account_title ?: '—' }}</td>
                            <td class="small">{{ $m->account ? $m->account->code.' · '.$m->account->name : '—' }}</td>
                            <td class="text-center">
                                @if($m->is_active)
                                    <span class="badge bg-soft-success">Active</span>
                                @else
                                    <span class="badge bg-soft-secondary">Disabled</span>
                                @endif
                            </td>
                            <td class="text-end">
                                @can('fees.update')
                                    <a href="{{ route('payment-methods.edit', $m) }}" class="btn btn-sm btn-light border" title="Edit"><i class="bi bi-pencil"></i></a>
                                    <form method="POST" action="{{ route('payment-methods.toggle', $m) }}" class="d-inline">@csrf
                                        <button class="btn btn-sm btn-light border" title="{{ $m->is_active ? 'Disable' : 'Enable' }}">
                                            <i class="bi {{ $m->is_active ? 'bi-toggle-on text-success' : 'bi-toggle-off text-muted' }}"></i>
                                        </button>
                                    </form>
                                    <form method="POST" action="{{ route('payment-methods.destroy', $m) }}" class="d-inline" data-confirm="Delete this method? (Only allowed if it has no payments.)">@csrf @method('DELETE')
                                        <button class="btn btn-sm btn-light border text-danger" title="Delete"><i class="bi bi-trash"></i></button>
                                    </form>
                                @endcan
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="text-center text-muted py-4">No payment methods yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div></div>
@endsection
