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

#import "/src/core/utils.typ": normalize-measure, normalize-units

#let name = "custom"

#let render(x, y, p, bottom) = {
  let style = p.resolved-style
  let shape = align(
    center,
    stack(
      dir: ttb,
      spacing: normalize-units(style.spacing) * 1pt,
      style.image,
      p.display-name
    )
  )
  let anchor = if bottom {"north"} else {"base"}
  draw.content(
    (x, y),
    shape,
    anchor: anchor
  )
}

#let get-size(par) = {
  let name-m = normalize-measure(par.display-name)
  let img-m = normalize-measure(par.resolved-style.image)
  let spacing = normalize-units(par.resolved-style.spacing)

  return (
    width: calc.max(name-m.width, img-m.width),
    height: name-m.height + spacing + img-m.height
  )
}

#let default-style = (
  image: none,
  spacing: 5pt
)