///|
pub(all) enum Paper {
  ///
  A4
  ///
  Presentation43
  ///
  Presentation169
} derive(Eq, Debug)

///|
pub extend Paper with Eq::{not_equal, equal}

///|
pub extend Paper with Debug::{to_repr}

///|
pub fn Paper::from_string(name : String) -> Result[Paper, String] {
  match name {
    "a4" => Ok(A4)
    "4-3" | "presentation-4-3" => Ok(Presentation43)
    "16-9" | "presentation-16-9" => Ok(Presentation169)
    _ => Err("unknown paper size: \{name}")
  }
}

///|
/// Print CSS for the paper size. Empty for plain documents.
fn Paper::print_css(self : Paper) -> String {
  match self {
    A4 => ""
    Presentation43 => slide_print_css("10in", "7.5in")
    Presentation169 => slide_print_css("13.33in", "7.5in")
  }
}

///|
fn slide_print_css(width : String, height : String) -> String {
  (
    $|@page {
    $|  size: \{width} \{height};
    $|  margin: 0;
    $|}
    $|@media print {
    $|  body {
    $|    display: block;
    $|    margin: 0;
    $|    padding: 0;
    $|    font-size: 18pt;
    $|  }
    $|  .paper {
    $|    width: \{width};
    $|    min-height: \{height};
    $|    max-width: none;
    $|    margin: 0;
    $|    padding: 1in;
    $|    box-sizing: border-box;
    $|  }
    $|}
    $|
  )
}