import { FC } from 'react';

import * as HuPosts from '@material-hu/components/composed-components/posts';

import { useAuth } from 'src/contexts/JWTContext';
import { FileTypes } from 'src/types/attachments';
import { getFullName } from 'src/utils/userUtils';

import { handleUploadFile } from '../utils';

type EventPostCreateProps = Omit<
  HuPosts.CreatePostProps,
  'fullName' | 'profilePicture' | 'uploadMedia' | 'uploadFile'
>;

export const EventPostCreate: FC<EventPostCreateProps> = props => {
  const { user, instance } = useAuth();

  const maxInstanceSize = instance.maxPostSizeInMB;

  return (
    <HuPosts.CreatePost
      fullName={getFullName(user)}
      profilePicture={user.profilePicture}
      uploadMedia={file => handleUploadFile(file)}
      uploadFile={file => handleUploadFile(file, FileTypes.FILE)}
      {...props}
      maxAttachedSize={maxInstanceSize}
      maxInputSize={10000}
      filesCarrouselProps={{
        slidesPerView: 2,
      }}
    />
  );
};
