import { LibraryCollaborator } from 'src/types/library';
import { useLokaliseTranslation } from 'src/utils/i18n';
import { getFullname } from 'src/utils/userUtils';

const useFormatEditorsOptions = () => {
  const { t } = useLokaliseTranslation('libraries');

  /*
   * @description - format editors options for CheckboxAutocomplete
   * @param editors - array of LibraryCollaborator
   * @returns - {
   *   id: number,
   *   label: string,
   *   description: string,
   *   checked: boolean,
   *   disabled: boolean,
   *   info: string,
   * }[]
   */
  const formatEditorsOptions = (editors: LibraryCollaborator[]) => {
    return (
      editors?.map(editor => ({
        id: editor.id,
        label: getFullname(editor),
        description: editor.employeeInternalId,
        checked: editor.isParentEditor,
        disabled: editor.isParentEditor,
        info: editor.isParentEditor
          ? t('article.permissions.edit.title')
          : undefined,
      })) || []
    );
  };

  return formatEditorsOptions;
};

export default useFormatEditorsOptions;
