///|
pub fn Palette::render_color_table(self : Palette) -> String {
  let lines : Array[String] = [
    "| Token | Value | Role |", "| --- | --- | --- |",
  ]
  for color in self.colors {
    lines.push(
      "| `" + color.name + "` | `" + color.value + "` | " + color.role + " |",
    )
  }
  lines.join("\n")
}

///|
pub fn Palette::render_gradient_table(self : Palette) -> String {
  let lines : Array[String] = [
    "| Gradient | Angle | Stops | Usage |", "| --- | ---: | --- | --- |",
  ]
  for gradient in self.gradients {
    lines.push(
      "| " +
      gradient.name +
      " | " +
      gradient.angle.to_string() +
      "° | " +
      gradient.stops.join(" → ") +
      " | " +
      gradient.usage +
      " |",
    )
  }
  if self.gradients.length() == 0 {
    lines.push("| (none) | - | - | - |")
  }
  lines.join("\n")
}

///|
pub fn Typography::render_family_table(self : Typography) -> String {
  let lines : Array[String] = [
    "| Family | Fallback | Usage |", "| --- | --- | --- |",
  ]
  for family in self.families {
    lines.push(
      "| " +
      family.name +
      " | `" +
      family.fallback +
      "` | " +
      family.usage +
      " |",
    )
  }
  lines.join("\n")
}

///|
pub fn Typography::render_scale_table(self : Typography) -> String {
  let lines : Array[String] = [
    "| Step | Size | Line height |", "| --- | ---: | ---: |",
  ]
  for step in self.scale {
    lines.push(
      "| " +
      step.name +
      " | " +
      step.size_px.to_string() +
      "px | " +
      step.line_height_px.to_string() +
      "px |",
    )
  }
  lines.join("\n")
}

///|
pub fn BrandBook::render_reference_tables(self : BrandBook) -> String {
  join_lines([
    "### Colors",
    "",
    self.palette.render_color_table(),
    "",
    "### Gradients",
    "",
    self.palette.render_gradient_table(),
    "",
    "### Font families",
    "",
    self.typography.render_family_table(),
    "",
    "### Type scale",
    "",
    self.typography.render_scale_table(),
  ])
}