'use client';

import { useAccount } from 'wagmi';
import { formatAddress } from '@/utils/format';

export function ConnectButton() {
  const { address, isConnected } = useAccount();

  const handleConnect = () => {
    try {
      // Minimal connect without WalletConnect modal
      if (typeof window !== 'undefined' && (window as any).ethereum?.request) {
        (window as any).ethereum.request({ method: 'eth_requestAccounts' });
      }
    } catch {}
  };

  if (isConnected && address) {
    return (
      <div className="inline-flex items-center gap-2 rounded-full border border-line bg-cloud/80 px-3 py-1.5 text-sm font-medium text-forest-deep">
        <span className="h-2 w-2 rounded-full bg-forest animate-breathe" aria-hidden />
        {formatAddress(address)}
        {/* Disconnect can be done from the wallet UI; no WalletConnect here */}
      </div>
    );
  }

  return (
    <button
      onClick={handleConnect}
      className="gh-btn gh-btn-primary text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-sky-deep"
    >
      🍃 Connect Wallet
    </button>
  );
}
