import { canCreate, canEdit } from '../../helpers/permissions';

export const getSitemapFileUrlBy = (hubId, watchId) => {
  const cdnName = process.env.APP_DWH_SEO_S3_BUCKET;

  return `https://${cdnName}/${hubId}/${hubId}_${watchId}/sitemap.xml`;
};

export const getSourceDefaultValue = () => [{ value: -1, label: 'All' }];

export const strToInt = (string = '') => parseInt(string.replace(/\D+/g, ''), 10) || 0;

export const valuesArrayToAutocomplete = (values, optionList) =>
  values.map((value) => optionList.find((opt) => opt.value === value));

export const getIsAllowedForCreateOrUpdate = (watchId, userPermissions) =>
  watchId ? canEdit(userPermissions) : canCreate(userPermissions);

export default {};
