components_data_SeriesData.bs

import "pkg:/source/api/baserequest.bs"
import "pkg:/source/api/Image.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/utils/misc.bs"

sub setFields()
  json = m.top.json

  m.top.id = json.id
  m.top.Title = json.name
  m.top.Description = json.overview
  m.top.favorite = json.UserData.isFavorite
  m.top.watched = json.UserData.played
  m.top.Type = "Series"
  m.top.overview = json.overview

  if isValid(json.ProductionYear)
    m.top.SubTitle = json.ProductionYear
  end if

  if isValid(json.OfficialRating) and json.OfficialRating <> ""
    m.top.Rating = json.OfficialRating
    if m.top.SubTitle <> ""
      m.top.SubTitle = m.top.SubTitle + " - " + m.top.Rating
    else
      m.top.SubTitle = m.top.Rating
    end if
  end if

  setPoster()
end sub

sub setPoster()
  if isValid(m.top.image)
    m.top.posterURL = m.top.image.url
  else

    if isValid(m.top.json.ImageTags.Primary)

      imgParams = { "maxHeight": 440, "maxWidth": 295, "Tag": m.top.json.ImageTags.Primary }
      m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
    else if isValid(m.top.json.BackdropImageTags)
      imgParams = { "maxHeight": 440, "Tag": m.top.json.BackdropImageTags[0] }
      m.top.posterURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
    end if

    ' Add Backdrop Image
    if isValid(m.top.json.BackdropImageTags)
      imgParams = { "maxHeight": 720, "maxWidth": 1280, "Tag": m.top.json.BackdropImageTags[0] }
      m.top.backdropURL = ImageURL(m.top.json.id, "Backdrop", imgParams)
    end if

  end if
end sub