// Smarana Library
// Core framework imported by every note

#import "fleeting.typ": fleeting-style
#import "capture.typ": capture-style
#import "atomic.typ": atomic-style
#import "dividers.typ": section-divider
#import "appendix.typ": tag-index-page

// Generate a label slug from a title string
// "Closures in Rust" → "Closures-in-Rust"
#let make-slug(title) = {
  let slug = title.replace(regex("[^a-zA-Z0-9]+"), "-").trim("-")
  if slug == "" { "untitled" } else { slug }
}

// Card show rule — the universal note wrapper
// Each note calls: #show: card.with(title: ..., type: ..., ...)
#let card(
  title: "",
  summary: "",
  date: "",
  time: "",
  tags: (),
  type: "fleeting",
  uplink: [],
  body,
) = {
  // Required for ref resolution on headings
  set heading(numbering: "1.1")

  // Hide numbering from all headings; hide level-10 title headings entirely
  // (level-10 headings exist in the note body purely for label/ref purposes)
  show heading: it => {
    if it.level >= 10 {
      box(width: 0pt, height: 0pt, clip: true, it)
    } else {
      it.body
    }
  }

  if type == "fleeting" {
    fleeting-style(
      title: title,
      date: date,
      time: time,
      body,
    )
  } else if type == "capture" {
    capture-style(
      title: title,
      date: date,
      time: time,
      tags: tags,
      body,
    )
  } else if type == "atomic" {
    atomic-style(
      title: title,
      summary: summary,
      date: date,
      time: time,
      tags: tags,
      uplink: uplink,
      body,
    )
  } else {
    // Fallback: render as fleeting
    fleeting-style(
      title: title,
      date: date,
      time: time,
      body,
    )
  }
}
