#import "utils.typ": format-eur

#let data_file = sys.inputs.at("data_path", default: "none")
#let data = if data_file != "none" { json(data_file) } else {
  (
    interval: "01/03/2026 - 31/03/2026",
    emissione: "03/04/2026",
    starting_balance: 0,
    ending_balance: 0,
    activity_gross: 184500, // Entrate lorde
    activity_fee: -6187, // Commissioni
    payouts: -178313, // Prelievi verso conto bancario
    movimenti: (
      (
        "date": "17/03/2026",
        "description": "Acconto Cerco Transitorio",
        "gross": 3500,
        "net": 3361,
        "fees": -139,
        "name": "Rossi Mario",
        "email": "killmyfootwithsniper@gmail.com",
      ),
      (
        "date": "17/03/2026",
        "description": "Rinnovo permanenza 6 mesi",
        "gross": 36000,
        "net": 34805,
        "fees": -1195.0000004,
        "name": "Rossi Mario",
        "email": "killmyfootwithsniper@gmail.com",
      ),
    ),
  )
}




#set page(paper: "a4", margin: (x: .5cm, y: 1.5cm))
#set text(font: "Inter 18pt", size: 10pt)

#let stripe-blue = rgb("#635BFF")
#let text-dark = rgb("#30313D")
#let text-muted = rgb("#687385")
#let border-color = rgb("#E3E8EE")
#let bg-light = rgb("#F7FAFC")

#grid(
  columns: (1fr, 1fr),
  align(left)[
    // Simulazione del logo Stripe
    #text(fill: stripe-blue, size: 28pt, weight: "bold")[Stripe]
  ],
  align(right)[
    #text(fill: text-muted, size: 14pt, weight: "bold")[ESTRATTO CONTO] \
    #v(4pt)
    #text(fill: text-dark, size: 10pt)[*Periodo:* #data.interval] \
    #text(fill: text-dark, size: 10pt)[*Generato il:* #data.emissione]
  ],
)

#v(.5cm)

#text(fill: text-muted, size: 9pt, weight: "bold")[INTESTARIO DEL CONTO:] \
#v(2pt)
#text(weight: "bold", size: 11pt, fill: text-dark)[Arcenia S.r.l.] \
Via Beata Giovanna, 1 \
36061 Bassano del Grappa (VI) \
Italia \
P.IVA: 00924740244

#v(.5cm)

#text(size: 14pt, weight: "bold", fill: stripe-blue)[Riepilogo del Conto]
#v(0.3cm)

#table(
  columns: (1fr, 1fr, 1fr, 1fr, 1fr),
  stroke: border-color,
  fill: (col, row) => if row == 0 { bg-light } else { none },
  align: center + horizon,

  [*Saldo Iniziale*], [*Totale Entrate*], [*Commissioni*], [*Prelievi*], [*Saldo Finale*],
  [#format-eur(data.starting_balance)],
  [#format-eur(data.activity_gross)],
  [#format-eur(data.activity_fee)],
  [#format-eur(data.payouts)],
  [#format-eur(data.ending_balance)],
)

#v(.5cm)

#text(size: 14pt, weight: "bold", fill: stripe-blue)[Dettaglio Movimenti]
#v(0.3cm)

#table(
  columns: (auto, 1fr, 1fr, auto, auto, auto),
  stroke: (x, y) => if y == 0 {
    (bottom: 1pt + text-muted)
  } else {
    (bottom: 0.5pt + border-color)
  },
  fill: (col, row) => if row == 0 { bg-light } else { none },
  align: (left, left, left, left, left, left),
  table.header([*Data*], [*Descrizione*], [*Cliente*], [*Lordo*], [*Comm.*], [*Netto*]),
  ..data
    .movimenti
    .map(item => {
      (
        item.date,
        item.description,
        item.name + "\n" + text(size: 8pt)[#item.email],
        format-eur(item.gross),
        format-eur(item.fees),
        format-eur(item.net),
      )
    })
    .flatten(),
)



