// The monthly sales report for the plain-text e-mail, the server log and the README: one set of rows, several tables.
//
//   quillo run text_table.qwe      then open http://localhost:8080/report.txt

use "text_table.qwer"

let SALES = [
    { region: "North", product: "Coffee beans 1 kg", units: 1240, revenue: 18476.5 },
    { region: "South", product: "Thé vert 東京", units: 86, revenue: 1032.0 },
    { region: "East", product: "Espresso machine with a very long product name", units: 12, revenue: 7188.75 },
]

route GET /report.txt = respond(200, text_table(SALES, { style: "box", titles: { region: "Region", product: "Product", units: "Units", revenue: "Revenue €" }, decimals: 2, max_width: 24 })?, { "content-type": "text/plain; charset=utf-8" })

route GET /tables {
    {
        ascii: text_table([["Plan", "Seats", "Price"], ["Starter", 3, 9.0], ["Team", 25, 49.0]], { style: "ascii", decimals: 2 })?,
        plain: text_table(SALES, { style: "plain", columns: ["region", "units"] })?,
        markdown: text_table_markdown(SALES, { columns: ["region", "units", "revenue"] })?,
        read_back: text_table_from_markdown("Intro text\n\n| name | qty |\n|------|----:|\n| pens | 12 |\n| ink \\| blue | 3 |\n")?,
    }
}
