//  !!!!
//  STUDENTS, DO NOT EDIT THIS FILE!
//  !!!!

#import "../projectInfo.typ": student, report

#let coverUnit = 398.38567pt/0.9 // derived from latex template
#let cu = coverUnit // shorthand
#let pageHeight = 841.89pt

#let white = rgb(255,255,255)
#let black-ish = rgb(6, 6, 12)
#let cyan = rgb(0, 185, 242)

#let imgHeight(image) = context{ // function to measure image height
  let measurement = measure(image)
  [#measurement.height]
}

#let coverpage( // Cover page function definition
    coverIMG: "../graphics/template/COVER.jpg",
        body,
) = { //function maps to output

  set page( // Background on full page
      margin: (left: 0mm, right: 0mm, top: 0mm, bottom: 0mm),
      background: image(report.coverImage,height: 100%)
      )
  
  // Black box (Center Box)
  set align(top+center)  
  move(
    dy: 0.237*cu, // const found by trial an error
    rect(
      width: 1*cu, 
      height: 0.45*cu, 
      fill: black-ish,
      outset: 0em,
      inset: 0.05*cu,
      [
        #set align(left)
        #text(fill: white, size: 24.88pt, font: "Bookman")[#report.title] // Thesis title
  
        #place( 
          dy: -15pt,
          text(fill: white, size: 14.4pt, font: "Bookman")[#report.subtitle] // Thesis Subtitle
        ) 
  
        #set align(bottom)
        #text(fill: cyan, size: 24.88pt, font: "Bookman")[#student.name] // Student Name
      ]
    )
  )
  
  // Oormerk (Left-side box)
  set align(top+left)  
  place( // placed to fill black box left-margin
    dy: 0.237*cu+0.45*cu -38pt/2.9,
    rotate(
      -90deg,
      origin: top+left,
      rect(
        width: 0.45*cu,
        height: (21cm-1*cu)/2,
        fill: cyan, // take height from black box margin
        inset: 0em,
        place(dx: 0.05/2*cu,dy: (21cm-1*cu)/2-0.05*cu, // Place text before rotation
          text(fill: white, size: 14.4pt, font: "Fira Sans",)[#report.type] 
        )
      ) 
    )
  )
  
  //footer
  align(bottom+left)[
    #rect(width: 100%, height: 90pt, fill: white, inset: 0em, // white parent box
      [
      #place(line(length: 100%)) // black bar as footer top border
  
      #set align(center+bottom)
      #move( // white section content
      dy: 7pt,
      stack(dir: ltr, // left to right stacking
        image("../graphics/template/TU_LOGO.png"),
        text(
          font: "New Computer Modern Sans",
          weight: "semibold"
          )[Delft Center for Systems and Control],
        spacing: 20%
      ))
      
      #rect(width: 100%, height: 38pt, fill: cyan,inset: 0em , outset: 0em,[ // child cyan box (overlaps white)
      #place(dy:24pt,line(length: 100%, stroke: white)) // white stripe
      ])
    ])
  ]
  pagebreak()
  body
}  
