export default defineNuxtPlugin(() => {
  const { on } = useEventBus()
  const sfx = useSfx()

  // Connection sounds
  on('socket:authenticated', ({ socketId }) => {
    sfx.playEvent('stream-on')
  })

  // Client events
  on('client:added', (client) => {
    sfx.playEvent('stream-on')
  })

  on('client:removed', () => {
    sfx.playEvent('stream-off')
  })

  // Audio mute/unmute
  on('audio:muted', () => {
    sfx.playEvent('mic-off')
  })

  on('audio:unmuted', () => {
    sfx.playEvent('mic-on')
  })

  // Video/share toggle
  on('video:enabled', () => {
    sfx.playEvent('stream-on')
  })

  on('video:disabled', () => {
    sfx.playEvent('stream-off')
  })

  on('share:enabled', () => {
    sfx.playEvent('stream-on')
  })

  on('share:disabled', () => {
    sfx.playEvent('stream-off')
  })

  // Consumer video streams
  on('consumer:added', (consumer) => {
    if (consumer.raw.kind === 'video') {
      sfx.playEvent('stream-on')
    }
  })

  on('consumer:removed', (consumer) => {
    if (consumer.raw.kind === 'video') {
      sfx.playEvent('stream-off')
    }
  })

  on('chat:new-message', () => {
    sfx.playEvent('message')
  })
})
