import { storeToRefs } from 'pinia'
import { useNostrStore } from '@/stores/nostr'
import type { NostrClientConfig } from '@/lib/nostr/client'

export function useNostr(config?: NostrClientConfig) {
  const store = useNostrStore()
  
  // If custom relays are provided, update the store
  if (config?.relays) {
    store.setRelayUrls(config.relays)
  }

  // Return reactive refs from the store
  const { isConnected, isConnecting, error } = storeToRefs(store)

  return {
    isConnected,
    isConnecting,
    error,
    connect: store.connect,
    disconnect: store.disconnect,
    getClient: store.getClient
  }
} 