{{- $scr := .Scratch -}}
{{- $site := $scr.Get "site" -}}

{{/* Attempt to load font style specified by user. */}}
{{- $font_index := .Site.Params.font | default "default" -}}
{{ if isset .Site.Data.fonts $font_index }}
  {{- $font := index .Site.Data.fonts $font_index -}}
  {{- $scr.Set "google_fonts" $font.google_fonts -}}
  {{- $scr.Set "body_font" $font.body_font -}}
  {{- $scr.Set "heading_font" $font.heading_font -}}
  {{- $scr.Set "nav_font" $font.nav_font -}}
  {{- $scr.Set "mono_font" $font.mono_font -}}
  {{- $scr.Set "font_size" $font.font_size -}}
  {{- $scr.Set "font_size_small" $font.font_size_small -}}
{{ end }}

{{/* Attempt to load color theme specified by user. */}}
{{- $theme_index := .Site.Params.color_theme | default "default" -}}
{{ if isset .Site.Data.themes $theme_index }}
  {{ $theme := index .Site.Data.themes $theme_index }}

  {{- $scr.Set "light" $theme.light -}}

  {{ if and $theme.background $theme.light }}
    {{- $scr.Set "background" $theme.background -}}
  {{ else }}
    {{- $scr.Set "background" "#fff" -}}
  {{ end }}

  {{ if and $theme.background (not $theme.light) }}
    {{- $scr.Set "dark_background" $theme.background -}}
  {{ else }}
    {{- $scr.Set "dark_background" "rgb(40, 42, 54)" -}}
  {{ end }}

  {{ if $theme.light }}
    {{- $scr.Set "home_section_odd" $theme.home_section_odd -}}
    {{- $scr.Set "home_section_even" $theme.home_section_even -}}
  {{ else }}
    {{- $scr.Set "home_section_odd" "rgb(255, 255, 255)" -}}
    {{- $scr.Set "home_section_even" "rgb(247, 247, 247)" -}}
  {{ end }}

  {{ if not $theme.light }}
    {{- $scr.Set "dark_home_section_odd" $theme.home_section_odd -}}
    {{- $scr.Set "dark_home_section_even" $theme.home_section_even -}}
  {{ else }}
    {{- $scr.Set "dark_home_section_odd" "hsla(231, 15%, 18%, 1)" -}}
    {{- $scr.Set "dark_home_section_even" "hsla(231, 15%, 16%, 1)" -}}
  {{ end }}

  {{ if $theme.link }}
    {{- $scr.Set "link" $theme.link -}}
  {{ else }}
    {{- $scr.Set "link" $theme.primary -}}
  {{ end }}

  {{ if $theme.link_hover }}
    {{- $scr.Set "link_hover" $theme.link_hover -}}
  {{ else }}
    {{- $scr.Set "link_hover" $theme.primary -}}
  {{ end }}

  {{- $scr.Set "primary" $theme.primary -}}
  {{- $scr.Set "primary_light" $theme.primary_light -}}
  {{- $scr.Set "primary_dark" $theme.primary_dark -}}

  {{- $scr.Set "menu_primary" $theme.menu_primary -}}
  {{- $scr.Set "menu_text" $theme.menu_text -}}
  {{- $scr.Set "menu_text_active" $theme.menu_text_active -}}
  {{- $scr.Set "menu_title" $theme.menu_title -}}

{{ end }}
