#let kL = $L$
#let dotss = $space dots.c space$

// #let statement-style = (name, numbered: false) => it => {
//   set align(start)
//   block({
//     strong({
//       it.supplement
//       if numbered and it.numbering != none {
//         [ ]
//         // current chapter and section

//         [#(
//             ..counter(heading).get().slice(0, 1).map(it => str(it)),
//             numbering(it.numbering, ..it.counter.at(it.location())),
//           ).join(".")]
//       }
//       if name != none {
//         [ (#name)]
//       }
//       [.]
//     })
//     [ ]
//     it.body
//   })
// }

#let definition(body, name: none) = {
  // show figure: statement-style(name, numbered: false)
  figure(
    body,
    kind: "definition",
    supplement: {
      [Definizione]
      if name != none {
        [ -- ]
        name
      }
    },
  )
}

#let fact(body, name: none) = {
  // show figure: statement-style(name, numbered: false)
  figure(
    body,
    kind: "fact",
    supplement: {
      [Fatto]
      if name != none {
        [ -- ]
        name
      }
    },
  )
}

#let proposition(body, numbered: true) = {
  // show figure: statement-style(name, numbered: numbered)

  return figure(
    body,
    // kind: "proposition",
    kind: "proposition",
    supplement: [Proposizione],
    numbering: if numbered { "1" },
  )
}

#let lemma(body, numbered: true) = {
  // show figure: statement-style(name, numbered: numbered)
  figure(
    body,
    // kind: "lemma",
    kind: "proposition",
    supplement: [Lemma],
    numbering: if numbered { "1" },
  )
}

#let theorem(body, name: none, numbered: true) = {
  // show figure: statement-style(name, numbered: numbered)
  figure(
    body,
    kind: "theorem",
    supplement: {
      [Teorema]
      if name != none {
        [ (#name)]
      }
    },
    numbering: if numbered { "1" },
  )
}

#let proof(body) = block({
  // v(-0.25em)
  emph[Dimostrazione.]
  [ ]
  body
  h(1fr)

  // Add a word-joiner so that the proof square and the last word before the
  // 1fr spacing are kept together.
  sym.wj

  // Add a non-breaking space to ensure a minimum amount of space between the
  // text and the proof square.
  sym.space.nobreak

  $square$
})

#let ref-link(target, content) = {
  show link: it => {
    set text(luma(10%))

    // remove underline for this
    show underline: it => it.body

    it
  }

  link(target, emph(content))
}

#let todo-color = color.mix((red, 10%), (yellow, 90%))
#let todo(content) = block(
  breakable: false,
  grid(
    rows: 2,
    align: left,
    block(
      fill: todo-color.desaturate(60%),
      inset: (x: 0.5em, y: 0.35em),
      radius: (top: 0.25em),
      {
        set text(fill: black.transparentize(15%), size: 8pt, font: "Open Sans")
        [*TODO*]
      },
    ),
    block(
      width: 100%,
      fill: todo-color.desaturate(75%),
      inset: (x: 0.5em, y: 0.5em),
      radius: (bottom: 0.25em, top-right: 0.25em),
      {
        set text(fill: black.transparentize(15%), size: 9pt, font: "Open Sans")
        content
      },
    ),
  ),
)

#let scr(it) = text(
  features: ("ss01",),
  box($cal(it)$),
)
