@csrf
<div class="row g-3">
    <div class="col-md-6">
        <label class="form-label">Name <span class="text-danger">*</span></label>
        <input type="text" name="name" value="{{ old('name', $method->name) }}" class="form-control @error('name') is-invalid @enderror" placeholder="e.g. JazzCash Main" required>
        @error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
    </div>
    <div class="col-md-6">
        <label class="form-label">Type <span class="text-danger">*</span></label>
        <select name="channel" class="form-select">
            @foreach(App\Models\PaymentMethod::CHANNELS as $val => $label)
                <option value="{{ $val }}" @selected(old('channel', $method->channel ?? 'cash') === $val)>{{ $label }}</option>
            @endforeach
        </select>
        <div class="form-text">Used for accounting and labels.</div>
    </div>
    <div class="col-md-6">
        <label class="form-label">Account Number</label>
        <input type="text" name="account_number" value="{{ old('account_number', $method->account_number) }}" class="form-control" placeholder="e.g. 0333-0000330">
    </div>
    <div class="col-md-6">
        <label class="form-label">Account Title</label>
        <input type="text" name="account_title" value="{{ old('account_title', $method->account_title) }}" class="form-control" placeholder="e.g. The School (Pvt) Ltd">
    </div>
    <div class="col-md-6">
        <label class="form-label">Posts to Ledger Account</label>
        <select name="account_id" class="form-select">
            <option value="">— Auto (Cash → Cash, others → Bank) —</option>
            @foreach($accounts as $acc)
                <option value="{{ $acc->id }}" @selected(old('account_id', $method->account_id) == $acc->id)>{{ $acc->code }} · {{ $acc->name }} ({{ ucfirst($acc->cash_bank) }})</option>
            @endforeach
        </select>
        <div class="form-text">Where collections via this method appear in accounting. Create a dedicated account in the Chart of Accounts for per-channel tracking.</div>
    </div>
    <div class="col-md-3">
        <label class="form-label">Sort Order</label>
        <input type="number" name="sort_order" value="{{ old('sort_order', $method->sort_order ?? 0) }}" class="form-control" min="0">
    </div>
    <div class="col-md-3 d-flex align-items-end">
        <div class="form-check">
            <input type="hidden" name="is_active" value="0">
            <input type="checkbox" class="form-check-input" id="is_active" name="is_active" value="1" @checked(old('is_active', $method->is_active ?? true))>
            <label class="form-check-label" for="is_active">Active (available for new payments)</label>
        </div>
    </div>
</div>

<div class="mt-4 d-flex gap-2">
    <button class="btn btn-primary"><i class="bi bi-check-lg me-1"></i>{{ $submitLabel ?? 'Save' }}</button>
    <a href="{{ route('payment-methods.index') }}" class="btn btn-light border">Cancel</a>
</div>
