// Drawing mixins

// generic drawing of more complex things

// @function _widget_edge($c:$borders_edge) {
// outer highlight "used" on most widgets
//   @return 0 1px $c;
// }

// provide font size in rem, with px fallback
@mixin fontsize($size: 24, $base: 16) {
  font-size: round($size) + pt;
  //font-size: ($size / $base) * 1rem;
}

@mixin _shadows($shadow1, $shadow2:none, $shadow3:none, $shadow4:none) {
//
// Helper function to stack up to 4 box-shadows;
//
  @if $shadow4!=none { box-shadow: $shadow1, $shadow2, $shadow3, $shadow4; }
  @else if $shadow3!=none { box-shadow: $shadow1, $shadow2, $shadow3; }
  @else if $shadow2!=none { box-shadow: $shadow1, $shadow2; }
  @else { box-shadow: $shadow1; }
}

// entries

@mixin entry($t, $tc: $fg_color, $c: $base_color, $fc:$selected_bg_color) {
//
// Entries drawing function
//
// $t: entry type
// $tc: text color
// $c: background color
// $fc: focus color
//
// possible $t values:
// normal, focus, insensitive
//

  @if $t==normal {
    color: $tc;
    background-color: $c;
    border-color: if($c != $base_color, if($c == $light_base_color, $light_borders_color, border_color($c)), $borders_color);
    box-shadow: none;
  }
  @if $t==focus {
    color: $tc;
    border-color: $fc;
    box-shadow: none;
  }
  @if $t==insensitive {
    $_bg: transparentize(mix($insensitive_fg_color,$c,20%),0.3); // transparentize(mix($insensitive_fg_color,$osd_bg_color,20%),0.3);
    color: $insensitive_fg_color;
    background-color: $_bg;
    border-color: $insensitive_bg_color;
    box-shadow: none;
  }
}

// buttons

@function _border_color($c, $darker: false) {
  @if $darker == true {
    @if lightness($c)<30% { @return darken($c, 20%); }
    @else { @return darken($c, 10%); }
  }
  @else {
    @if lightness($c)<30% { @return darken($c, 15%); }
    @else { @return darken($c, 5%); }
  }
}

// @function _text_shadow_color ($tc:$fg_color, $bg:$bg_color) {
//
// calculate the color of text shadows
//
// $tc is the text color
// $bg is the background color
//
//   $_lbg: lightness($bg)/100%;
//   @if lightness($tc)<50% { @return transparentize(white,1-$_lbg/($_lbg*1.3)); }
//   @else { @return transparentize(black,$_lbg*0.8); }
// }

@function _button_hilight_color($c) {

// calculate the right hilight color for buttons
  @if lightness($c)>35% { @return transparentize(black, 0.4); }
  @else { @return transparentize(white, 0.85);}
}

// @mixin _button_text_shadow ($tc:$fg_color, $bg:$bg_color) {
//
// helper function for the text emboss effect
//
// $tc is the optional text color, not the shadow color
//
// TODO: this functions needs a way to deal with special cases
//
//
//   $_shadow: _text_shadow_color($tc, $bg);
//
//   @if lightness($tc)<50% {
//     text-shadow: 0 1px $_shadow;
//     icon-shadow: 0 1px $_shadow;
//   }
//   @else {
//     text-shadow: 0 -1px $_shadow;
//     icon-shadow: 0 -1px $_shadow;
//   }
// }

@mixin button($t, $c:$button_bg_color, $tc:$osd_fg_color) {
//
// Button drawing function
//
// $t:    button type,
// $c:    base button color for colored* types
// $tc:   optional text color for colored* types
//
// possible $t values:
// normal, hover, active, focus, insensitive, undecorated
//

  $_hilight_color: _button_hilight_color($c);
  transition-duration: 200ms;

  @if $t==normal {
  // normal button
    background-color: $c;
    border-color: _border_color($c);
    // box-shadow: inset 0 -1px 0 0 $_hilight_color;
    color: $tc;
    icon-shadow: none;
    text-shadow: none;
  }

  @if $t==focus {
  // focused button
    box-shadow: inset 0px 0px 0px 1px if($c!=$success_color, $selected_bg_color, white);
  }

  @else if $t==hover {
  // active osd button
    background-color: lighten($c, 10%);
  }

  @else if $t==focus-hover {
  // active osd button
    background-color: lighten($c, 10%);
    // box-shadow: inset 0px 0px 0px 1px $selected_bg_color;
  }
  @else if $t==active {
  // active osd button
    box-shadow: none;
  }
  @else if $t==insensitive {
  // insensitive osd button
  //
    $_bg: transparentize(mix($insensitive_fg_color,$c,20%),0.3); // transparentize(mix($insensitive_fg_color,$osd_bg_color,20%),0.3);

    color: if($c != $c, mix($tc, $c, 50%), $insensitive_fg_color);
    border-color: _border_color($c);
    background-color: $_bg;
    box-shadow: none;
    text-shadow: none;
    icon-shadow: none;

    @if $c==$success_color {
      $_bg: darken($c, 20%);
      background-color: $_bg;
      border-color: $_bg;
      color: transparentize(white, 0.5)
    }
  }
  @else if $t==undecorated {
  // reset
  //
    border-color: transparent;
    background-color: transparent;
    background-image: none;
    box-shadow: none;
    text-shadow: none;
    icon-shadow: none;
  }
}
