#import "core/utils.typ": fit-canvas, set-ctx
#import "core/renderer.typ": render
#import "participant.typ" as participant: _par, PAR-SPECIALS
#import "sequence.typ": _seq
#import "core/draw/event.typ": render as evt-render
#import "core/setup.typ": setup

#let gap-render(gap) = set-ctx(ctx => {
  ctx.y -= gap.size
  return ctx
})

#let _gap(size: 20) = {
  return ((
    type: "gap",
    draw: gap-render,
    size: size
  ),)
}

#let _evt(participant, event) = {
  return ((
    type: "evt",
    draw: evt-render,
    participant: participant,
    event: event,
    lifeline-style: auto
  ),)
}

#let _col(p1, p2, width: auto, margin: 0, min-width: 0, max-width: none) = {
  return ((
    type: "col",
    p1: p1,
    p2: p2,
    width: width,
    margin: margin,
    min-width: min-width,
    max-width: max-width
  ),)
}

#let diagram(elements, width: auto) = {
  if elements == none {
    return
  }
  
  let (elmts, participants) = setup(elements)

  let canvas = render(participants, elmts)
  fit-canvas(canvas, width: width)
}

#let from-plantuml(code) = {
  let code = code.text
}