'use client' import { 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 { onSelect: (bank: Bank) => void selectedBank?: Bank | null isLoading?: boolean className?: string country?: string sandbox?: boolean } export function BankSelector({ onSelect, isLoading = false, className, country = 'SE', sandbox = true, // Default to sandbox for development }: BankSelectorProps) { const widgetRef = useRef(null) const [scriptLoaded, setScriptLoaded] = useState(false) useEffect(() => { if (!scriptLoaded) return const widget = widgetRef.current if (!widget) return const handleSelected = (e: Event) => { const customEvent = e as CustomEvent const detail = customEvent.detail as { name: string country: string psuType: string sandbox: boolean } onSelect({ name: detail.name, country: detail.country, }) } widget.addEventListener('selected', handleSelected) return () => { widget.removeEventListener('selected', handleSelected) } }, [onSelect, scriptLoaded]) const handleScriptLoad = () => { setScriptLoaded(true) } if (isLoading) { return (
Ansluter...
) } return (