source_utils_rowItemText.bs

import "pkg:/source/utils/misc.bs"

' Returns the primary display title for a row item.
'
' - Season: returns the season label (item.name, e.g. "Season 1")
' - Episode: returns the episode code and title (item.subtitle, e.g. "S1E2 - Pilot")
' - All others: returns item.name
'
' @param item - JellyfinBaseItem content node
' @returns Display title string, or "" if item is invalid
function getRowItemTitle(item as object) as string
  if not isValid(item) then return ""

  ' Season: item.name is the season label; subtitle holds seriesName (shown as secondary text)
  if item.type = "Season"
    return item.name
  end if

  ' Episode: subtitle holds the pre-computed episode code + title ("S1E2 - Name");
  ' seriesName provides context and is shown as secondary text below.
  if item.type = "Episode"
    return item.subtitle
  end if

  return item.name
end function

' Returns the secondary display subtitle for a row item.
'
' - Season: returns the series name (stored in item.subtitle by the transformer)
' - Episode: returns the series name (item.seriesName)
' - All others: returns the pre-computed subtitle field
'   (e.g., "2024 • PG-13" for Movie, "2020 - Present" for Series)
'
' @param item - JellyfinBaseItem content node
' @returns Display subtitle string, or "" if item is invalid
function getRowItemSubtitle(item as object) as string
  if not isValid(item) then return ""

  ' Season: subtitle field holds the series name; name holds "Season N" (shown as title)
  if item.type = "Season"
    return item.subtitle
  end if

  ' Episode: series name provides context for the episode code+title shown above
  if item.type = "Episode"
    return item.seriesName
  end if

  return item.subtitle
end function