#import "/src/cetz.typ": draw

#import "/src/core/utils.typ": normalize-measure
#import "/src/consts.typ": *

#let name = "queue"

#let render(x, y, p, bottom) = {
  let m = measure(p.display-name)
  let style = p.resolved-style
  let w = (m.width + QUEUE-PAD.last() * 2) / 1pt
  let h = (m.height + QUEUE-PAD.first() * 2) / 1pt
  let total-h = h
  let ry = total-h / 2
  let rx = ry / 2
  let total-w = w + 3 + 3 * rx

  let x0 = x - total-w / 2
  let y0 = if bottom {y} else {y + total-h}
  let y1 = y0 - total-h
  let x-left = x0 + rx
  let x-right = x-left + w + rx
  draw.merge-path(
    close: true,
    fill: style.fill,
    stroke: style.stroke,
    {
      draw.bezier((x-right, y0), (x-right + rx, y0 - ry), (x-right + rx/2, y0), (x-right + rx, y0 - ry/2))
      draw.bezier((), (x-right, y1), (x-right + rx, y1 + ry/2), (x-right + rx/2, y1))
      draw.line((), (x-left, y1))
      draw.bezier((), (x-left - rx, y0 - ry), (x-left - rx/2, y1), (x-left - rx, y1 + ry/2))
      draw.bezier((), (x-left, y0), (x-left - rx, y0 - ry/2), (x-left - rx/2, y0))
    }
  )
  draw.merge-path(
    stroke: style.stroke,
    {
      draw.bezier((x-right, y0), (x-right - rx, y0 - ry), (x-right - rx/2, y0), (x-right - rx, y0 - ry/2))
      draw.bezier((), (x-right, y1), (x-right - rx, y1 + ry/2), (x-right - rx/2, y1))
    }
  )
  draw.content(
    ((x-left + x-right - rx) / 2, y0 - ry),
    p.display-name,
    anchor: "mid"
  )
}

#let get-size(par) = {
  let m = normalize-measure(par.display-name)

  // w + QUEUE-PAD.last() * 2 + 3 * (h + QUEUE-PAD.first() * 2) / 4
  // h + QUEUE-PAD.first() * 2

  return m
}

#let default-style = (
  :
)