#!/usr/bin/env bash

apply_osc4() {
  local idx=$1 hex=$2
  printf '\e]4;%d;rgb:%s/%s/%s\007' \
    "$idx" "${hex:0:2}" "${hex:2:2}" "${hex:4:2}"
}

apply_fg() {
  local h=$1
  printf '\e]10;rgb:%s/%s/%s\007' "${h:0:2}" "${h:2:2}" "${h:4:2}"
}
apply_bg() {
  local h=$1
  printf '\e]11;rgb:%s/%s/%s\007' "${h:0:2}" "${h:2:2}" "${h:4:2}"
}
apply_sel_bg() {
  local h=$1
  printf '\e]17;rgb:%s/%s/%s\007' "${h:0:2}" "${h:2:2}" "${h:4:2}"
}
apply_sel_fg() {
  local h=$1
  printf '\e]19;rgb:%s/%s/%s\007' "${h:0:2}" "${h:2:2}" "${h:4:2}"
}

apply_fg "{{colors.on_surface.default.hex_stripped}}"
apply_bg "{{colors.surface.default.hex_stripped}}"
apply_sel_bg "{{colors.primary_container.default.hex_stripped}}"
apply_sel_fg "{{colors.on_primary_container.default.hex_stripped}}"

apply_osc4 0 "{{colors.surface_container_lowest.default.hex_stripped}}"
apply_osc4 1 "{{colors.error.default.hex_stripped}}"
apply_osc4 2 "{{colors.tertiary.default.hex_stripped}}"
apply_osc4 3 "{{colors.secondary.default.hex_stripped}}"
apply_osc4 4 "{{colors.primary.default.hex_stripped}}"
apply_osc4 5 "{{colors.secondary_container.default.hex_stripped}}"
apply_osc4 6 "{{colors.tertiary_container.default.hex_stripped}}"
apply_osc4 7 "{{colors.on_surface_variant.default.hex_stripped}}"
apply_osc4 8 "{{colors.surface_container_high.default.hex_stripped}}"
apply_osc4 9 "{{colors.error_container.default.hex_stripped}}"
apply_osc4 10 "{{colors.tertiary_container.default.hex_stripped}}"
apply_osc4 11 "{{colors.secondary_container.default.hex_stripped}}"
apply_osc4 12 "{{colors.primary_container.default.hex_stripped}}"
apply_osc4 13 "{{colors.inverse_primary.default.hex_stripped}}"
apply_osc4 14 "{{colors.surface_bright.default.hex_stripped}}"
apply_osc4 15 "{{colors.on_surface.default.hex_stripped}}"
