'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="flex items-center space-x-4">
        <span className="text-sm font-medium text-gray-700">
          {formatAddress(address)}
        </span>
        {/* Disconnect can be done from the wallet UI; no WalletConnect here */}
      </div>
    );
  }

  return (
    <button
      onClick={handleConnect}
      className="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
    >
      Connect Wallet
    </button>
  );
}
