components_data_MusicAlbumData.bs

import "pkg:/source/api/Image.bs"
import "pkg:/source/utils/backdropUtils.bs"
import "pkg:/source/utils/misc.bs"
sub setFields()
  datum = m.top.json

  m.top.id = datum.id
  m.top.title = datum.name
  m.top.overview = datum.overview
  setPoster()
end sub

sub setPoster()
  if isValid(m.top.image)
    m.top.posterURL = m.top.image.url
  else if isValid(m.top.json) and isValid(m.top.json.ImageTags) and isValidAndNotEmpty(m.top.json.ImageTags.Primary)
    imgParams = { "maxHeight": 440, "maxWidth": 440, "tag": m.top.json.ImageTags.Primary }
    m.top.posterURL = ImageURL(m.top.json.id, "Primary", imgParams)
  else
    ' Set posterURL to empty string when no valid tags exist to prevent 404 requests
    m.top.posterURL = ""
  end if

  ' Always set backdrop URL using centralized utility (outside of poster logic)
  if isValid(m.top.json)
    localDevice = m.global.device
    deviceResolution = [localDevice.uiResolution[0], localDevice.uiResolution[1]]
    m.top.backdropUrl = getBackdropUrl(m.top.json, deviceResolution)
  end if
end sub