@charset "UTF-8";

// GTK functions

// escape string entirely
@function gtk ($str) {
  @return unquote("#{$str}_breeze");
}

// alpha function
@function gtkalpha($c,$a) {
  @return unquote("alpha(#{$c},#{$a})");
}

// shade function
@function gtkshade($c, $a) {
  @return unquote("shade(#{$c}_breeze,#{$a})");
}

// mix function
@function gtkmix($c1, $c2, $m) {
  @return unquote("mix(#{$c1},#{$c2},#{$m})");
}

//
// Theme color functions
//

// Button Color
@function internal_b_color($c: normal) {
  @if $c == normal {
    @return $ButtonBackgroundNormal;
  }
  @if $c == hover {
    @return $ButtonDecorationHover;
  }
  @if $c == active {
    @return $ButtonDecorationFocus;
  }
  @if $c == text {
    @return $ButtonForegroundNormal;
  }
  @if $c == active-text {
    @return $SelectionForegroundNormal;
  }
}

// Selection Color
@function internal_s_color($c: normal) {
  @if $c == normal {
    @return $SelectionBackgroundNormal;
  }
  @if $c == hover {
    @return $SelectionDecorationHover;
  }
  @if $c == text {
    @return $SelectionForegroundNormal;
  }
  @if $c == backdrop {
    @return transparentize($SelectionBackgroundNormal,0.5);
  }
}

// View Color
@function internal_v_color($c: normal) {
  @if $c == normal {
    @return $ViewBackgroundNormal;
  }
  @if $c == hover {
    @return $ViewDecorationHover;
  }
  @if $c == active {
    @return $ViewDecorationFocus;
  }
  @if $c == text {
    @return $ViewForegroundNormal;
  }
}

// Window Color
@function internal_w_color($c: normal) {
  @if $c == normal {
    @return $WindowBackgroundNormal;
  }
  @if $c == text {
    @return $WindowForegroundNormal;
  }
}

// Titlebar color
@function internal_t_color($c: text) {
  @if $c == text {
    @return $WMactiveForeground;
  }
  @if $c == background {
    @return $WMactiveBackground;
  }
  @if $c == background-light {
    @return $WindowBackgroundNormal;
  }
  @if $c == backdrop-text {
    @return $WMinactiveForeground;
  }
  @if $c == backdrop-background {
    @return $WMinactiveBackground;
  }
}

@function internal_tooltip($c: text) {
  @if $c == text {
    @return $TooltipForegroundNormal;
  }
  @if $c == background {
    @return $TooltipBackgroundNormal;
  }
  @if $c == border {
    @return mix($TooltipForegroundNormal, $TooltipBackgroundNormal, 25%);
  }
}

@function internal_button_gradient($c, $state: normal) {
  @if $state == normal {
    @return linear-gradient(to bottom, change-color($c, $lightness: min(lightness($c)*1.01,100%)), change-color($c, $lightness:min(lightness($c)/1.03,100%)));
  }
  @else {
    @return linear-gradient(to bottom, change-color($c, $lightness: min(lightness($c)*1.03,100%)), change-color($c, $lightness:min(lightness($c)/1.10,100%)));
  }
}

$border_color: mix($WindowBackgroundNormal,$WindowForegroundNormal, 75%);
$menu_color: internal_w_color(normal);
$link_color: $ViewForegroundLink;
$link_visited_color: $ViewForegroundVisited;

$warning_color: $ViewForegroundNeutral;
$error_color: $ViewForegroundNegative;
$success_color: $ViewForegroundPositive;
$destructive_color: $error_color;

$trough_color:                      gtkmix(gtk("@theme_bg_color"),gtk("@theme_fg_color"),0.7);
$trough_color_backdrop:             gtkmix(gtk("@theme_unfocused_bg_color"),gtk("@theme_unfocused_fg_color"),0.7);
$trough_color_insensitive:          gtkmix(gtk("@insensitive_bg_color"),gtk("@insensitive_fg_color"),0.7);
$trough_color_backdrop_insensitive: gtkmix(gtk("@insensitive_unfocused_bg_color"),gtk("@insensitive_unfocused_fg_color"),0.7);

$scrollbar_color: gtkmix($trough_color,gtk("@theme_text_color"),0.5);
$scrollbar_color_backdrop: gtkmix($trough_color_backdrop,gtk("@theme_unfocused_text_color"),0.5);

//
// Color effects
//
//
// Color maps for color effect functions
//
$Color: (
  Disabled: $DisabledColor,
  Inactive: $InactiveColor
  );
$ColorAmount: (
  Disabled: $DisabledColorAmount,
  Inactive: $InactiveColorAmount
  );
$ColorEffect: (
  Disabled: $DisabledColorEffect,
  Inactive: $InactiveColorEffect
  );
$ContrastAmount: (
  Disabled: $DisabledContrastAmount,
  Inactive: $InactiveContrastAmount
  );
$ContrastEffect: (
  Disabled: $DisabledContrastEffect,
  Inactive: $InactiveContrastEffect
  );
$IntensityAmount: (
  Disabled: $DisabledIntensityAmount,
  Inactive: $InactiveIntensityAmount
  );
$IntensityEffect: (
  Disabled: $DisabledIntensityEffect,
  Inactive: $InactiveIntensityEffect
  );

$r: 3px; // standard radius

@function internal_insensitive($c) {
  @return internal_Color(internal_Intensity(internal_Contrast($c, Disabled), Disabled), Disabled);
}

@function internal_backdrop($c) {
  @if $InactiveEnable == true {
    @return internal_Color(internal_Intensity(internal_Contrast($c, Inactive), Inactive), Inactive);
  }
  @else {
    @return $c;
  }
}

@function internal_Contrast($c, $state) {

  @if map-get($ContrastEffect, $state) == 0 {
    @return $c;
  }

  @if map-get($ContrastEffect, $state) == 1 {
    @if lightness(internal_w_color()) > lightness(internal_w_color(text)) {
      @if lightness($c) < lightness(internal_w_color()) or ($c == internal_t_color(text) and lightness(internal_t_color(background)) <= lightness(internal_t_color(text))) {
        @return transparentize($c, map-get($ContrastAmount, $state));
      }
      @else { @return $c; }
    }
    @if lightness(internal_w_color()) <= lightness(internal_w_color(text)) {
      @if lightness($c) > lightness(internal_w_color()) or ($c == internal_t_color(text) and lightness(internal_t_color(background)) > lightness(internal_t_color(text))) {
        @return transparentize($c, map-get($ContrastAmount, $state));
      }
      @else { @return $c; }
    }
  }

  @if map-get($ContrastEffect, $state) == 2 {
    @if lightness(internal_w_color()) > lightness(internal_w_color(text)) {  // don't know what a reasonable lightness treshhold is for Contrast
      @if lightness($c) < lightness(internal_w_color()) or ($c == internal_t_color(text) and lightness(internal_t_color(background)) <= lightness(internal_t_color(text))) {
        @return transparentize($c, map-get($ContrastAmount, $state));
      }
      @else { @return $c; }
    }
    @if lightness(internal_w_color()) <= lightness(internal_w_color(text)) {
      @if lightness($c) > lightness(internal_w_color()) or ($c == internal_t_color(text) and lightness(internal_t_color(background)) > lightness(internal_t_color(text))){
        @return transparentize($c, map-get($ContrastAmount, $state));
      }
      @else { @return $c; }
    }
  }
}

@function internal_Color($c, $state) {

  @if map-get($ColorEffect, $state) ==0 {
    @return $c;
  }

  @if map-get($ColorEffect, $state) ==1 {
    @if map-get($ColorAmount, $state) >=0 {
      @return desaturate($c, percentage(map-get($ColorAmount, $state)));
    }
    @else {
      @return saturate($c, percentage(abs(map-get($ColorAmount, $state))));
    }
  }

  @if map-get($ColorEffect, $state)==2 or map-get($ColorEffect, $state)==3 { // 2 and 3 seem to do the same
    @return mix(map-get($Color, $state),$c, percentage(map-get($ColorAmount, $state)));
  }
}

@function internal_Intensity($c, $state) {

  @if map-get($IntensityEffect, $state) == 0 {
    @return $c;
  }
  @if map-get($IntensityEffect, $state) == 1 {
    @if map-get($IntensityAmount, $state) >= 0 {
      @return mix(white, $c, percentage(map-get($IntensityAmount, $state)));
    }
    @else {
      @return mix(black, $c, percentage(abs(map-get($IntensityAmount, $state))));
    }
  }

  @if map-get($IntensityEffect, $state) == 2 {
    @if map-get($IntensityAmount, $state) == -1 {
      @return change-color($c, $lightness: 100%);
    }
    @else {
      @return change-color($c, $lightness: min(lightness($c)/(1+map-get($IntensityAmount, $state)),100%));
    }
  }

  @if map-get($IntensityEffect, $state) == 3 {
    @return change-color($c, $lightness: min(lightness($c)*(1+map-get($IntensityAmount, $state)),100%));
  }
}

@function internal_alpha2solid($c,$background) {
  $amount:alpha($c);
  $c:rgb(red($c),green($c),blue($c));
  @return mix($c,$background,$amount);
}
