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

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

#let name = "entity"

#let render(x, y, p, bottom) = {
  let m = normalize-measure(p.display-name)
  let style = p.resolved-style
  let size = normalize-units(style.size)
  let spacing = normalize-units(style.spacing)
  let gap = normalize-units(style.gap)
  let r = size / 2
  let y0 = if bottom {
    y - m.height - spacing
  } else {
    y + m.height + size + spacing
  }
  let y1 = y0 - size - gap

  draw.circle(
    (x, y0 - r),
    radius: r,
    fill: style.fill,
    stroke: style.stroke
  )
  draw.line(
    (x - r, y1),
    (x + r, y1),
    stroke: style.stroke
  )
  draw.content(
    (x, y),
    p.display-name,
    anchor: if bottom {"north"} else {"base"}
  )
}

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

  let m = normalize-measure(par.display-name)

  let size = normalize-units(par.resolved-style.size)
  let spacing = normalize-units(par.resolved-style.spacing)

  return (
    width: calc.max(m.width, size),
    height: size + spacing + m.height
  )
}

#let default-style = (
  size: 20pt,
  gap: 1.5pt,
  spacing: 5pt
)