import { durationFormat } from '@/services/utils';
import { IChatItem } from '../ChatLogsType';

export const ChatVoiptext: React.FC<IChatItem> = (props) => {
  const invitetype: any = {
    '1': '单人视频通话',
    '2': '单人语音通话',
    '3': '多人视频通话',
    '4': '多人语音通话',
  };

  function content() {
    try {
      const msg = JSON.parse(props.chat?.content as string);
      return (
        <div style={{ display: 'flex', color: '#000', flexDirection: 'column' }}>
          <div style={{ wordBreak: 'break-all', paddingRight: 8 }}>
            音视频通话 {durationFormat(msg.callduration)}
          </div>
          <div style={{ borderTop: '1px solid #ddd', marginTop: 8, paddingTop: 8, color: '#999' }}>
            {invitetype[msg.invitetype]}
          </div>
        </div>
      );
    } catch (_e) {
      return (
        <div>
          <div style={{ wordBreak: 'break-all', paddingRight: 8 }}>{props.chat?.content}</div>
        </div>
      );
    }
  }

  return <>{content()}</>;
};
