'use strict';

var getSeriesDetail = function getSeriesDetail(article, currentSeries) {
  //For use in getInitialProps to return series detail to display next/prev links when javascript is disabled
  if (!currentSeries || !article || !article.body) {
    return {
      seriesUrl: '',
      currentSeries: false,
      prevUrl: false,
      nextUrl: false
    };
  }
  var nextUrl = false;
  var prevUrl = false;
  var galleryBody = article.body.find(function (body) {
    if (body._type == 'youtubeGallery') {
      return body;
    }
  });
  if (currentSeries >= 1 && currentSeries < galleryBody.videos.length) {
    nextUrl = '/view/' + article.url.current + '?seriesVid=' + (parseInt(currentSeries) + 1);
  }
  if (currentSeries > 1 && currentSeries <= galleryBody.videos.length) {
    prevUrl = '/view/' + article.url.current + '?seriesVid=' + (parseInt(currentSeries) - 1);
  }
  var seriesDetail = {
    seriesUrl: article.url.current,
    currentSeries: currentSeries,
    nextUrl: nextUrl,
    prevUrl: prevUrl,
    type: 'Video'
  };

  return seriesDetail;
};

module.exports = getSeriesDetail;
