import type { FC } from 'react';

import { User } from 'src/types/user';

import {
  ProfilePicture,
  ProfilePictureProps,
} from 'src/components/user/ProfilePicture';

export type RegularChatAvatarProps = Omit<
  ProfilePictureProps,
  'id' | 'user' | 'withLink' | 'openInNewTab'
> & {
  otherUser: User;
  otherUserId?: number;
  withLink?: boolean;
  withUserDeleted?: boolean;
};

export const RegularChatAvatar: FC<RegularChatAvatarProps> = props => {
  const {
    otherUser,
    otherUserId,
    withLink = true,
    withUserDeleted = false,
    ...profileProps
  } = props;

  const showLink = withLink && !otherUser?.deleted;
  const id = otherUser?.id || otherUserId;

  if (showLink && id) {
    return (
      <ProfilePicture
        user={otherUser}
        withLink
        id={id}
        withUserDeleted={withUserDeleted && otherUser?.deleted}
        {...profileProps}
      />
    );
  }

  return (
    <ProfilePicture
      user={otherUser}
      withUserDeleted={withUserDeleted && otherUser?.deleted}
      {...profileProps}
    />
  );
};

export default RegularChatAvatar;
