'use client' import { useCallback, useEffect, useRef, useState } from 'react' import { Loader2 } from 'lucide-react' import { cn } from '@/lib/utils' import Script from 'next/script' export interface Bank { name: string country: string logo?: string bic?: string } interface BankSelectorProps { onConnect: (bank: Bank) => void isConnecting?: boolean connectingBankName?: string | null className?: string } /** * Popular Swedish banks shown as quick-access buttons above the full widget. * Country is always 'SE' since we only support Swedish banks. */ const POPULAR_BANKS: Bank[] = [ { name: 'Nordea', country: 'SE' }, { name: 'SEB', country: 'SE' }, { name: 'Swedbank', country: 'SE' }, { name: 'Handelsbanken', country: 'SE' }, { name: 'Länsförsäkringar', country: 'SE' }, { name: 'Skandia', country: 'SE' }, { name: 'Danske Bank', country: 'SE' }, ] export function BankSelector({ onConnect, isConnecting = false, connectingBankName = null, className, }: BankSelectorProps) { const widgetRef = useRef(null) const [scriptReady, setScriptReady] = useState(false) // Stable ref so the event listener never goes stale const onConnectRef = useRef(onConnect) useEffect(() => { onConnectRef.current = onConnect }, [onConnect]) const handleSelected = useCallback((e: Event) => { const detail = (e as CustomEvent).detail as { name: string country: string psuType: string sandbox: boolean } onConnectRef.current({ name: detail.name, country: detail.country, }) }, []) // Attach event listener once the script is ready and the widget is in the DOM useEffect(() => { if (!scriptReady) return const widget = widgetRef.current if (!widget) return widget.addEventListener('selected', handleSelected) return () => { widget.removeEventListener('selected', handleSelected) } }, [scriptReady, handleSelected]) return (
{/* Popular banks — one-click connect */}

Populära banker

{POPULAR_BANKS.map((bank) => { const connecting = isConnecting && connectingBankName === bank.name return ( ) })}
{/* Full bank list via Enable Banking widget — includes logos and search */}

Alla banker