const resolveElectionLink = function resolveElectionLink(opts) {
  const {
    manifest,
    link,
    pagePathPrefix = '',
    currentUrl
  } = opts;
  if (!link) {
    return {
      targetType: undefined,
      url: undefined
    };
  }
  const isPage = !link.startsWith('http') && !link.startsWith('/');
  const page = manifest && manifest.find(p => p.roles.includes(link));
  if (isPage && !page) {
    return {
      targetType: 'page',
      url: undefined
    };
  }
  const url = isPage ? `${pagePathPrefix}${page.path}` : link;
  if (url === currentUrl) {
    return {
      url: undefined
    };
  }
  return {
    targetType: isPage ? 'page' : 'external',
    url
  };
};
export default resolveElectionLink;