// Drawing mixins

// generic drawing of more complex things

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

// Entries

@mixin entry($t, $dark:false) {
//
// Entries drawing function
//
  //@extend %reset_style;

  @if $t==normal {
    color: $text_color;
    background-color: $entry_bg;
    border: 1px solid $entry_border !important;
    box-shadow: inset 0 2px 4px transparentize($entry_bg, 0.95) !important;
  }

  @if $t==hover {
    color: $fg_color;
    background-color: $entry_bg;
    border: 1px solid $entry_border !important;
    box-shadow: inset 0 2px 4px transparentize($entry_bg, 0.95) !important;
  }

  @if $t==focus {
    color: $fg_color;
    background-color: $entry_bg;
    border: 1px solid $selected_bg_color !important;
    box-shadow: inset 0 2px 4px transparentize($entry_bg, 0.95) !important;
  }

  @if $t==insensitive {
    color: $insensitive_fg_color;
    background-color: mix($entry_bg, $bg_color, 55%);
    border-color: 1px solid mix($entry_border, $bg_color, 55%) !important;
    box-shadow: inset 0 2px 4px transparentize(mix($entry_bg, $bg_color, 55%), 0.95) !important;
  }

  @if $t==osd {
    color: $osd_fg_color;
    background-color: $osd_entry_bg;
    border: 1px solid $osd_entry_border !important;
    box-shadow: inset 0 2px 4px transparentize(black, 0.95) !important;
  }

  @if $t==osd-focus {
    color: $selected_fg_color;
    background-color: $selected_bg_color;
    border: 1px solid $osd_entry_border !important;
    box-shadow: inset 0 2px 4px transparentize(black, 0.95) !important;
  }

  @if $t==osd-insensitive {
    color: transparentize($osd_fg_color, 0.45);
    background-color: transparentize($osd_entry_bg, 0.15);
    border: 1px solid $osd_entry_border !important;
    box-shadow: inset 0 2px 4px transparentize(black, 0.95) !important;
  }
}

// Buttons

@mixin button($t, $c:$button_bg, $tc:$fg_color) {
//
// Button drawing function
//
  //@extend %reset_style;

  text-shadow: none;

  @if $t==normal {
  //
  // normal button
  //
    color: $tc;
    background-color: $c;
    border: 1px solid if($tc == $fg_color, $button_border, mix($tc, $c, 12%));
    box-shadow: none;
  }

  @else if $t==focus {
  //
  // focused button
  //
    color: $tc;
    background-color: $c;
    border: 1px solid if($tc == $fg_color, $button_border, rgba($fg_color, 0.12));
    box-shadow: none !important;
  }

  @else if $t==focus-hover {
  //
  // focused button
  //
    color: $tc;
    background-color: if($variant=='light', mix($tc, $c, 3%), mix($tc, $c, 6%));
    border: 1px solid if($tc == $fg_color, $button_border, mix($tc, $c, 12%));
    box-shadow: none !important;
  }

  @else if $t==hover {
  //
  // hovered button
  //
    color: $tc;
    background-color: mix($tc, $c, 6%);
    border: 1px solid mix($tc, $c, 16%);
    box-shadow: none;
  }

  @else if $t==active {
  //
  // pushed button
  //
    color: $selected_fg_color;
    background-color: $selected_bg_color;
    border: 1px solid if($variant == 'light', $sec_selected_bg_color, $alt_selected_bg_color);
    box-shadow: none;
  }

  @else if $t==active-hover {
  //
  // pushed button
  //
    color: $selected_fg_color;
    background-color: lighten($selected_bg_color, 5%);
    border: 1px solid if($variant == 'light', darken($selected_bg_color, 5%), lighten($selected_bg_color, 10%));
    box-shadow: none;
  }

  @else if $t==insensitive {
  //
  // insensitive button
  //
    color: $insensitive_fg_color;
    border: 1px solid transparentize($button_border, 0.45);
    background-color: transparentize($c, 0.45);
    box-shadow: none;
  }

  @else if $t==osd {
  //
  // normal osd button
  //
    color: $osd_fg_color;
    border: 1px solid transparent;
    background-color: transparent;
    box-shadow: none;
  }

  @else if $t==osd-focus {
  //
  // active osd button
  //
    color: $osd_fg_color;
    border-color: darken($selected_bg_color, 15%);
    background-color: $osd_bg_color;
    box-shadow: none;
  }

  @else if $t==osd-hover {
  //
  // active osd button
  //
    color: $osd_fg_color;
    border-color: lighten($osd_bg_color, 10%);
    background-color: lighten($osd_bg_color, 5%);
    box-shadow: none;
  }

  @else if $t==osd-active {
  //
  // active osd button
  //
    color: $selected_fg_color;
    border-color: $selected_bg_color;
    background-color: $selected_bg_color;
    box-shadow: none;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd button
  //
    color: rgba($osd_fg_color, 0.35);
    border-color: lighten($osd_bg_color, 2%);
    background-color: rgba($osd_bg_color, 0.35);
    box-shadow: none;
  }

  @if $t==flat {
    //
    // flat button
    //
    color: $tc;
    background-color: transparent;
    border: none;
    box-shadow: none;
  }

  @else if $t==flat-focus {
    //
    // flat focused button
    //
    color: $tc;
    background-color: rgba($tc, 0.05);
  }

  @else if $t==flat-hover {
    //
    // flat hovered button
    //
    color: $tc;
    background-color: rgba($tc, 0.1);
    border: none;
    box-shadow: none;
  }

  @else if $t==flat-active {
    //
    // flat pushed button
    //
    color: $tc;
    background-color: rgba($tc, 0.2);
    border: none;
    box-shadow: none;
   }

  @else if $t==flat-checked {
    //
    // flat checked button
    //
    color: $tc;
    background-color: rgba($tc, 0.12);
    border: none;
    box-shadow: none;
  }

  @else if $t==flat-insensitive {
    //
    // flat insensitive button
    //
    color: $insensitive_fg_color;
    background-color: transparent;
    border: none;
    box-shadow: none;
  }
}

// Panel menu/button drawing function
@mixin panel_button($bg:$panel_fg, $fg:$panel_fg, $style: null) {
  //
  // $bg:    background color, derived from $panel_fg
  // $fg:    foreground color, also derived from $panel
  // $style: can be set to 'filled' if button uses a colored background
  //

  transition-duration: 150ms;

  font-weight: bold;
  color: $fg;

  // background fill defines
  $fill:              transparent;
  $hover_fill:        transparentize($fg, .83);
  $active_fill:       transparentize($fg, .72);
  $active_hover_fill: transparentize($fg, .68);

  @if $style == 'filled' {
    $fill:              $bg;
    $hover_fill:        if($variant == 'light', darken($bg, 5%), lighten($bg, 5%));
    $active_fill:       if($variant == 'light', darken($bg, 9%), lighten($bg, 9%));
    $active_hover_fill: if($variant == 'light', darken($bg, 11%), lighten($bg, 11%));
  }

  background-color: $fill;

  &:focus, &:hover {
    background-color: $hover_fill;
  }

  &:active, &:checked  {
    background-color: $active_fill;

    &:hover{
      background-color: $active_hover_fill;
    }
  }
}
