#import "./settings.typ": *

#let titlepage(
  degree: "",
  program: "",
  title: "",
  subtitle: "",
  titleGerman: "",
  subtitleGerman: "",
  author: "",
  matriculationNumber: "",
  placeOfWork: "",
  supervisor: "",
  advisor: "",
  startDate: none,
  submissionDate: none,
) = {
  set document(title: title, author: author)
  set page(
    paper: "a4",
    margin: (left: 30mm, right: 30mm, top: 40mm, bottom: 40mm),
    numbering: "I",
    number-align: center,
    footer: ""
  )

  set text(
    font: fontBody, 
    size: 12pt, 
    lang: "en"
  )

  set par(leading: 1em)

  
  // Title Page
  grid(
    columns: (1fr, 1fr),
    align(left)[
      #image("/assets/SAPLogo.svg", height: 1.5cm)
    ],
    align(right)[
      #image("/assets/HKALogo.png", height: 2cm)
    ]
  )

  v(5mm)
  align(center, text(font: fontHeading, 1.9em, weight: 700, "University of Applied Sciences Karlsruhe"))
  
  v(15mm)

  align(center, text(font: fontHeading, 1.5em, weight: 100, degree + "’s Thesis in " + program))
  v(8mm)

  if titleGerman.len() > 0 {
    if subtitle.len() > 0 or subtitleGerman.len() > 0 {
      align(center, text(font: fontHeading, 1.2em, weight: 700, title))
      align(center, text(font: fontHeading, 1.2em, weight: 500, subtitle))
      v(10mm)
      align(center, text(font: fontHeading, 1.2em, weight: 700, titleGerman))
      align(center, text(font: fontHeading, 1.2em, weight: 500, subtitleGerman))  
    } else {
      align(center, text(font: fontHeading, 1.4em, weight: 700, title))
      v(10mm)
      align(center, text(font: fontHeading, 1.4em, weight: 700, titleGerman))
    }
  } else {
    if subtitle.len() > 0 {
      align(center, text(font: fontHeading, 1.8em, weight: 700, title))
      v(5mm)
      align(center, text(font: fontHeading, 1.4em, weight: 500, subtitle))
    } else {
      align(center, text(font: fontHeading, 2.0em, weight: 700, title))
    }
    
  }

  if advisor.len() > 0 {
    pad(
      top: 3em,
      right: 10%,
      left: 10%,
      grid(
        columns: (3fr, 3fr),
        gutter: 1em,
        strong("Author: "), author,
        strong("Matriculation Number: "), matriculationNumber,
        strong("Place of Work: "), placeOfWork,
        strong("Supervisor: "), supervisor,
        strong("Advisor: "), advisor,
        strong("Start Date: "), startDate,
        strong("Submission Date: "), submissionDate,
      )
    )
  } else {
    pad(
      top: 3em,
      right: 10%,
      left: 10%,
      grid(
        columns: (3fr, 3fr),
        gutter: 1em,
        strong("Author: "), author,
        strong("Matriculation Number: "), matriculationNumber,
        strong("Place of Work: "), placeOfWork,
        strong("Supervisor: "), supervisor,
        strong("Start Date: "), startDate,
        strong("Submission Date: "), submissionDate,
      )
    )
  }

  pagebreak()
}