import { IconCalendarPlus } from '@material-hu/icons/tabler';

import MenuList, {
  type MenuListProps,
} from '@material-hu/components/composed-components/MenuList';

import { useLokaliseTranslation } from 'src/utils/i18n';

import { useGetSessionICS } from '../../hooks/useGetSessionICS';
import { type Session } from '../../types';

type SessionCardActionsProps = {
  session: Session;
};

const SessionCardActions = ({ session }: SessionCardActionsProps) => {
  const { t } = useLokaliseTranslation('learning');

  const calendarMutation = useGetSessionICS();

  const handleAddToCalendar = () => {
    calendarMutation.mutate({
      id: session.learningSessionId,
      title: session.title,
    });
  };

  const options: MenuListProps['options'] = [
    {
      Icon: IconCalendarPlus,
      title: t('general:add_to_calendar'),
      description: t('session.options.calendar.download'),
      onClick: handleAddToCalendar,
      disabled: calendarMutation.isLoading,
    },
  ];

  return (
    <MenuList
      aria-label={t('session.options.title')}
      options={options}
      position="right"
    />
  );
};

export default SessionCardActions;
