// 字体
#let font = (
  main: "IBM Plex Serif",
  mono: "IBM Plex Mono",
  cjk: "Noto Serif CJK SC",
  size: 11pt,
)

// 图标
#let icon(path) = box(
  baseline: 0.125em,
  height: 1.0em,
  width: 1.25em,
  image(path)
)

#let faAngleRight = icon("fa-angle-right.svg")

// 主体
#let resume(
  size: 10pt,
  themeColor: rgb(38, 38, 125),
  top: 2cm,
  bottom: 2cm,
  left: 2cm,
  right: 2cm,
  photograph: "",
  photographWidth: 0em,
  gutterWidth: 0em,
  header,
  body
) = {
  // 页边距设定
  set page(paper: "a4", numbering: "1", margin: (
    top: top,
    bottom: bottom,
    left: left,
    right: right,
  ))

  // 基础字体设定
  set text(font: (font.main, font.cjk), size: size, lang: "zh")

  // 标题及小标题样式
  show heading: set text(themeColor, 1.1em)

  // 二级标题下加一条横线
  show heading.where(level: 2): it => stack(
    // v(0.2em),
    it,
    v(0.2em),
    line(length: 100%, stroke: 0.05em + themeColor),
    // v(0.1em),
  )
  
  // 更改 bullet list 的图标
  // set list(indent: 1em, body-indent: 0.8em, marker: faAngleRight)
  // 上面的语句无法精确控制图标位置, 因此改用了下列方法重写 list
  show list: it => stack(spacing: 0.4em, ..it.children.map(item => {
    grid(
      columns: (2em, 1fr),
      gutter: (0em),
      box({
        h(0.75em)
        faAngleRight
      }),
      pad(top: 0.15em, item.body)
    )
  }))
  
  // 链接颜色
  show link: set text(fill: themeColor)
  
  // 主体设定
  set par(justify: true)
  show par: set block(spacing: 0.65em)
  
  // 首部与照片
  grid(
    columns: (photographWidth, 1fr, auto),
    if (photograph != "") {
      image(photograph, width: photographWidth)
    },
    gutter: (gutterWidth, 0em),
    header
  )
  body
}


// 带竖线的侧边栏
#let sidebar(side, content, withLine: true, sideWidth: 12%) = style(styles => {
  let sideSize = measure(side, styles)
  let contentSize = measure(content, styles)
  let height = calc.max(sideSize.height, contentSize.height) + 0.5em
  grid(
    columns: (sideWidth, 0%, 1fr),
    gutter: (0.75em),
    {
      set align(right)
      v(0.25em)
      side
      v(0.25em)
    },
    if (withLine) {line(end: (0em, height), stroke: 0.05em)},
    {
      v(0.25em)
      content
      v(0.25em)
    },
  )
})

#let infoitem(
  icon: icon,
  content: content,
) = {
  set align(left)
  set text(font: (font.mono, font.cjk), fill: black)
  grid(
    columns: (auto, auto),
    gutter: (5pt),
    icon, content
  )
}


// person info
#let person(
  color: black,
  // ap,
  home,
  school,
  major,
  phone,
  email,
  github
) = {
  set align(left+bottom)
  v(0.3em)
  set text(font: (font.mono, font.cjk), fill: color, size: 14pt)
  // ap
  set text(size: 10pt)
  grid(
    columns: (1fr, 1fr, 1fr),
    gutter: (1em),
    home, school, major,
    phone, email, github
  )
}


// 教育背景
#let education(
  date,
  school,
  desc
) = {
  set align(right)
  set text(font: (font.main, font.cjk), size: 1em)
  grid(
    columns: (auto, 1fr),
    gutter: (5pt),
    date, school
  )
  desc
}



#let internship(
  date,
  position,
  desc
) = {
  set text(font: (font.main, font.cjk), size: 1em)
  v(0.1em)
  grid(
    columns: (1fr, auto),
    gutter: (0em),
    date, position
  )
  v(-0.5em)
  grid(
    gutter: (0em),
    desc
  )
}


// 日期： 
#let date(body) = text(
  weight: "extralight",
  fill: rgb(0, 0, 0),
  size: 1.2em,
  body
)

// 技术: 字体变细
#let tech(body) = block({
  set text(weight: "extralight", size: 1em)
  body
})

// 项目
#let item(
  title,
  desc,
  endnote,
  data,
) = {
  set text(font: (font.main, font.cjk), size: 1em)
  // v(0.1em)
  grid(
    columns: (30%, 1fr, auto),
    gutter: (0em),
    title, desc, endnote
  )
  v(-0.4em)
  data
}

// 研究
#let researchitem(
  title,
  endnote,
) = {
  v(0.25em)
  grid(
    columns: (1fr, auto),
    gutter: (0em),
    title, endnote
  )
}
