#import "cover.typ": cover_page
#import "title.typ": title_page
#import "contents.typ": contents_page

#let conf(
  title: "",
  author: "",
  chair: "",
  school: "",
  degree: "",
  examiner: "",
  supervisor: "",
  submitted: "",
  doc
) = {
  cover_page(
    title: title,
    author: author,
    chair: chair,
    school: school
  )

  title_page(
    title: title,
    author: author,
    chair: chair,
    school: school,
    degree: degree,
    examiner: examiner,
    supervisor: supervisor,
    submitted: submitted
  )

set document(title: title, author: author)

/*
  set heading(numbering: "1.")
  show heading: it => locate(loc => {
    let levels = counter(heading).at(loc)

    set text(font: "TUM Neue Helvetica")
    if it.level == 1 [
      #if levels.at(0) != 1 {
        pagebreak(to: "odd")
      }
      #set text(size: 24pt)
      #if levels.at(0) != 0 {
        numbering("1", levels.at(0))
      }
      #it.body
      #v(1em, weak: true)
    ] else if it.level == 2 [
      #set text(size: 16pt)
      #v(1em)
      #numbering("1.1", levels.at(0), levels.at(1))
      #it.body
      #v(1em, weak: true)
    ] else if it.level == 3 [
      #set text(size: 16pt)
      #v(1em, weak: true)
      #numbering("1.1.1", levels.at(0), levels.at(1), levels.at(2))
      #it.body
      #v(1em, weak: true)
    ] else [
      #set text(size: 12pt)
      #v(1em, weak: true)
      #it.body
      #v(1em, weak: true)
    ]
  })
*/

contents_page()

// This section defines the heading numberins and stylings for different heading levels
// Kind of a hack but works.
// TODO needs some refactoring
set heading(numbering: "1.")
show heading: it => [
  #v(1em)
  #text(
    size: 12pt,
    font: "TUM Neue Helvetica",
    it.body
  )
  #v(1em, weak:true)
]

show heading.where(
  level: 1
): it => [
  #pagebreak()
  #v(1em)
  #text(
  size: 24pt,
  font: "TUM Neue Helvetica",
  //[#context counter(heading).display() ] + it.body,
  [#context{
      if counter(heading).get().at(0) == 0 [
        #it.body 
    ] else [
      #counter(heading).display()  #it.body
    ]
    }]
  )
  #v(1em, weak: true)
]

show heading.where(
  level: 3
): it => [
  #v(1em)
  #text(
    size: 16pt,
    font: "TUM Neue Helvetica",
    [#context counter(heading).display() ] + it.body
  )
  #v(1em, weak:true)
]

show heading.where(
  level: 2
): it => [
  #v(1em)
  #text(
    size: 16pt,
    font: "TUM Neue Helvetica",
    context[#counter(heading).display() ] + it.body
  )
  #v(1em, weak: true)
]



set page(
  paper: "a4",
  margin: (
    top: 3cm,
    bottom: 3cm,
    x: 2cm,
  ),
  numbering: "1",
  header: [],
    //footer: []
)


  set par(justify: true)
  set align(left)
  set text(
    lang: "de",
   // font: "Times New Roman",
    size: 12pt
  )
  doc
}
