import React, { ComponentType } from 'react'
import { ChatAttachmentModel, ChatMessageModel, ParticipantModel, ZocksChatActions } from '../../store'
import { StyledComponent } from '../common'

export interface ChatProps extends StyledComponent {
  chatActions: ZocksChatActions
  dismiss?: () => void
  components?: {
    ParticipantNotConnected?: ComponentType<StyledComponent>
    ChatMessage?: ComponentType<ChatMessageProps>
    ChatInput?: ComponentType<ChatInputProps>
  }
}

export interface ChatMessageProps extends StyledComponent {
  chatMessage: ChatMessageModel
  getAttachmentLocation?: (fileId: string) => Promise<string | undefined>
  components?: {
    ChatMessageAttachment?: ComponentType<ChatMessageAttachmentProps>
  }
}

export interface ChatMessageAttachmentProps extends StyledComponent {
  attachment: ChatAttachmentModel
  getAttachmentLocation: (fileId: string) => Promise<string | undefined>
}

export interface ChatInputProps extends StyledComponent {
  messageRecipient: string
  remoteParticipants?: ParticipantModel[]
  onRecipientSelected?: (recipientId: string) => void
  sendPublicMessage?: (message: string, attachment?: ChatAttachmentModel) => void
  sendPrivateMessage?: (message: string, remoteParticipant: ParticipantModel, attachment?: ChatAttachmentModel) => void
  uploadAttachment?: (file: File, remoteParticipant?: ParticipantModel) => Promise<string | undefined>
  components?: {
    ChatMessageInput?: ComponentType<ChatMessageInputProps>
    SendButton?: ComponentType<SendButtonProps>
    RecipientSelector?: ComponentType<RecipientSelectorProps>
    EmojiSelector?: ComponentType<EmojiSelectorProps>
    AttachmentUploader?: ComponentType<AttachmentUploaderProps>
    AttachmentDisplay?: ComponentType<AttachmentDisplayProps>
  }
}

export interface ChatMessageInputProps extends React.ComponentPropsWithoutRef<any>, StyledComponent {
  currentChatMessage: string
  onChatMessageChanged: (message: string) => void
  placeholderText?: string
  sendMessage?: () => void
}

export interface SendButtonProps extends StyledComponent {
  disabled?: boolean
  onClick?: () => void
  buttonText?: string
}

export interface RecipientSelectorProps extends StyledComponent {
  remoteParticipants?: ParticipantModel[]
  onRecipientSelected: (recipientId: string) => void
  selectInfoText?: string
  allParticipantsLabel?: string
}

export interface EmojiSelectorProps extends StyledComponent {
  onSelectEmoji: (emoji: string) => void
  emojis?: string[]
  currentMessage?: string
  components?: {
    OpenButton?: ComponentType<EmojiSelectorOpenButtonProps>
  }
}

export interface EmojiSelectorOpenButtonProps extends React.ComponentPropsWithoutRef<any>, StyledComponent {
  onClick: () => void
}

export interface AttachmentUploaderProps extends StyledComponent {
  uploadAttachment: (file: File, remoteParticipant?: ParticipantModel) => Promise<string | undefined>
  attachmentRecipient?: ParticipantModel
  onAttachmentUploadStarted?: (file: File) => void
  onAttachmentUploadFinished?: (file: File, fileId: string) => void
  onAttachmentUploadFailed?: (file: File) => void
  components?: {
    UploadAttachment?: ComponentType<UploadAttachmentButtonProps>
  }
}

export interface UploadAttachmentButtonProps extends StyledComponent {
  onClick: () => void
  disabled?: boolean
  hasError?: boolean
}

export interface AttachmentDisplayProps extends StyledComponent {
  attachment?: ChatAttachmentModel
  hasAttachmentError?: boolean
  onClearAttachment?: () => void
  components?: {
    ClearAttachmentButton?: ComponentType<ClearAttachmentButtonProps>
  }
}

export interface ClearAttachmentButtonProps extends StyledComponent {
  onClick: () => void
}

export interface SplitChatProps extends ChatProps {
  components?: {
    ChatMessage?: ComponentType<ChatMessageProps>
    ChatInput?: ComponentType<ChatInputProps>
    RecipientSelector?: ComponentType<RecipientSelectorProps>
    ParticipantNotConnected?: ComponentType<StyledComponent>
  }
}
