// A monthly report and a customer export as Word documents.
//
//   quillo run docx.qwe      then open http://localhost:8080/report.docx

use "docx.qwer"

let orders = [
    { id: 1041, customer: "Ada Lovelace", total: 120.5, status: "paid" },
    { id: 1042, customer: "Grace Hopper", total: 99, status: "sent" },
    { id: 1043, customer: "Alan Turing", total: null, status: "draft" },
]

fn report(path) = docx_write(path, [
    { heading: "Monthly report", level: 1 },
    { runs: [{ text: "Sales rose by " }, { text: "12%", bold: true }, { text: " in October.", italic: true }] },
    { heading: "Highlights", level: 2 },
    { bullets: ["Three new shops", "A second roaster", "Card payments everywhere"] },
    { table: [["Shop", "Orders", "Revenue"], ["Lyon", 412, "18,250.50"], ["Nantes", 380, "16,410.00"]] },
    { page_break: true },
    { text: "Prepared by the Quillo Café office.", size: 9, align: "right", color: "#666666" },
])

route GET /report.docx {
    report("data/report.docx")?
    file("data/report.docx")
}

route GET /report = { blocks: report("data/report.docx")?, orders: docx_write_table("data/orders.docx", "Orders", orders, ["id", "customer", "total", "status"])? }

route GET /letter.docx {
    docx_write_text("data/letter.docx", "Dear Ada,", "Thank you for your order.\n\nIt leaves the roastery on Monday.")?
    file("data/letter.docx")
}
