import { format, isSameDay, isYesterday } from 'date-fns';
import { es } from 'date-fns/locale';
import { Categories } from 'emoji-picker-react';
import { type FileAsset } from '@material-hu/types/attachments';

import { FileTypes } from 'src/types/attachments';

export type AttachmentType = 'images' | 'files';

export type CommentFormValues = {
  message: string;
  images: FileAsset[];
  files: FileAsset[];
};

export const getAttachmentType = (
  newAttachments: FileAsset[],
): AttachmentType => {
  if (newAttachments.some(a => a.type === FileTypes.IMAGE)) return 'images';
  return 'files';
};

export const getDateSeparator = (
  date: Date,
  t: (key: string) => string,
  locale: Locale = es,
): string => {
  if (isSameDay(date, new Date())) return t('TODAY');
  if (isYesterday(date)) return t('YESTERDAY');
  return format(date, 'eeee, d MMMM', { locale });
};

export const getEmojiCategories = (
  t: (key: string, options?: object) => string,
) => [
  {
    category: Categories.SUGGESTED,
    name: t('emojis:suggested', { defaultValue: 'Suggested' }),
  },
  {
    category: Categories.CUSTOM,
    name: t('emojis:custom', { defaultValue: 'Custom' }),
  },
  {
    category: Categories.SMILEYS_PEOPLE,
    name: t('emojis:smileys_people', { defaultValue: 'Smileys and people' }),
  },
  {
    category: Categories.ANIMALS_NATURE,
    name: t('emojis:animals_nature', { defaultValue: 'Animals and nature' }),
  },
  {
    category: Categories.FOOD_DRINK,
    name: t('emojis:food_drink', { defaultValue: 'Food and drink' }),
  },
  {
    category: Categories.TRAVEL_PLACES,
    name: t('emojis:travel_places', { defaultValue: 'Travel and places' }),
  },
  {
    category: Categories.ACTIVITIES,
    name: t('emojis:activities', { defaultValue: 'Activities' }),
  },
  {
    category: Categories.OBJECTS,
    name: t('emojis:objects', { defaultValue: 'Objects' }),
  },
  {
    category: Categories.SYMBOLS,
    name: t('emojis:symbols', { defaultValue: 'Symbols' }),
  },
  {
    category: Categories.FLAGS,
    name: t('emojis:flags', { defaultValue: 'Flags' }),
  },
];
