///|
/// Named palette intended for predictable design exports.
pub(all) struct Palette {
  name : String
  colors : Array[Color]
} derive(Eq, Debug, ToJson)

///|
pub fn Palette::new(name : String, colors : Array[Color]) -> Palette {
  { name, colors }
}

///|
pub fn Palette::at(self : Palette, index : Int) -> Color? {
  if index < 0 || index >= self.colors.length() {
    None
  } else {
    Some(self.colors[index])
  }
}

///|
pub fn Palette::with_alpha(self : Palette, alpha : Double) -> Palette {
  let colors = []
  for color in self.colors {
    colors.push(color.with_alpha(alpha))
  }
  { ..self, colors, }
}

///|
pub fn Palette::lerp(
  self : Palette,
  other : Palette,
  amount : Double,
) -> Palette {
  let size = if self.colors.length() < other.colors.length() {
    self.colors.length()
  } else {
    other.colors.length()
  }
  let colors = []
  for i in 0.. String {
  let builder = StringBuilder()
  builder.write_string(":root {\n")
  for i in 0.. Palette {
  let colors = []
  for i in 0.. Palette {
  Palette::new("sunset", [
    Color::rgb8(34, 20, 74),
    Color::rgb8(129, 45, 91),
    Color::rgb8(230, 92, 75),
    Color::rgb8(255, 184, 77),
  ])
}

///|
pub fn ocean_palette() -> Palette {
  Palette::new("ocean", [
    Color::rgb8(3, 27, 46),
    Color::rgb8(0, 87, 122),
    Color::rgb8(0, 168, 150),
    Color::rgb8(191, 232, 229),
  ])
}

///|
pub fn forest_palette() -> Palette {
  Palette::new("forest", [
    Color::rgb8(18, 45, 32),
    Color::rgb8(42, 92, 56),
    Color::rgb8(103, 145, 67),
    Color::rgb8(222, 220, 155),
  ])
}