#import "misc.typ": ored, oteal

/// If false, hide instructor info.
///
/// Compile with the following command to hide solutions:
/// `typst compile main.typ --input show_solutions=false`
///
/// Solutions are shown by default. This behavior
/// is less surprising than hiding content by default.
#let show_solutions = {
  if "show_solutions" in sys.inputs {
    // Show solutions unless they're explicitly disabled
    not (
      sys.inputs.show_solutions == "false" or sys.inputs.show_solutions == "no"
    )
  } else {
    // Show solutions by default
    true
  }
}

#let if_solutions(content) = {
  if show_solutions { content }
}

#let if_no_solutions(content) = {
  if not show_solutions { content }
}

#let if_solutions_else(if_yes, if_no) = {
  if show_solutions { if_yes } else { if_no }
}

#let solution(content) = {
  if_solutions(
    align(
      center,
      stack(
        block(
          width: 100%,
          breakable: false,
          fill: ored,
          stroke: ored + 2pt,
          inset: 1.5mm,
          align(left, text(fill: white, weight: "bold", [Solution:])),
        ),

        block(
          width: 100%,
          height: auto,
          breakable: false,
          fill: ored.lighten(80%).desaturate(10%),
          stroke: ored + 2pt,
          inset: 3mm,
          align(left, content),
        ),
      ),
    ),
  )
}

#let instructornote(content) = {
  let c = oteal
  if_solutions(
    align(
      center,
      stack(
        block(
          width: 100%,
          breakable: false,
          fill: c,
          stroke: c + 2pt,
          inset: 1.5mm,
          align(left, text(fill: white, weight: "bold", [Instructor note:])),
        ),

        block(
          width: 100%,
          height: auto,
          breakable: false,
          fill: c.lighten(80%).desaturate(10%),
          stroke: c + 2pt,
          inset: 3mm,
          align(left, content),
        ),
      ),
    ),
  )
}