import React from 'react'
import type { Channel, LocalMessage } from 'stream-chat'

import type { ChannelListProps } from '../../types'

type ChannelListContextValue = {
  selectedChannel?: Channel | null
  onChannelSelect: (channel: Channel) => void
  debug: boolean
  renderMessagePreview?: (
    message: LocalMessage | undefined,
    defaultPreview?: string
  ) => React.ReactNode
  channelPreview?: ChannelListProps['channelPreview']
  viewerLanguage?: string
}

const ChannelListContext = React.createContext<ChannelListContextValue>({
  selectedChannel: undefined,
  onChannelSelect: () => {},
  debug: false,
  renderMessagePreview: undefined,
  channelPreview: undefined,
  viewerLanguage: undefined,
})

export const ChannelListProvider = ChannelListContext.Provider

export const useChannelListContext = () => React.useContext(ChannelListContext)
