// -----------------------------------------------------------------------------
// This file contains all application-wide Sass mixins.
// -----------------------------------------------------------------------------

/// Event wrapper
/// @author Harry Roberts
/// @param {Bool} $self [false] - Whether or not to include current selector
/// @link https://twitter.com/csswizardry/status/478938530342006784 Original tweet from Harry Roberts
@mixin on-event($self: false) {
  @if $self {
    &,
    &:hover,
    &:active,
    &:focus {
      @content;
    }
  } @else {
    &:hover,
    &:active,
    &:focus {
      @content;
    }
  }
}

// Clearfix mixin
@mixin clearfix() {
  &::after {
    clear: both;
    content: "";
    display: table;
  }
}


/// Make a context based selector a little more friendly
/// @author Hugo Giraudel
/// @param {String} $context
@mixin when-inside($context) {
  #{$context} & {
    @content;
  }
}

// 组件无使用场景
// Button variant mixin
@mixin button-variant($color: $component-color-primary) {
  color: $color;
  border-color: $color;
  &:hover {
    box-shadow: 0 2px 4px rgba(darken($color, 5%), 0.4);
  }
  &:active,
  &.#{$namespace}active {
    background: darken($color, 15%);
    @if (lightness(darken($color, 15%)) < 70) {
      color: $color-white;
    }
  }
  &[disabled],
  &:disabled,
  &.#{$namespace}disabled {
    color: $text-color-secondary-light;
    border-color: $text-color-secondary-light;
    &.#{$namespace}loading {
      &::after {
        border-bottom-color: $text-color-secondary-light;
        border-left-color: $text-color-secondary-light;
      }
    }
  }
  &.#{$namespace}loading {
    &::after {
      border-bottom-color: $color;
      border-left-color: $color;
    }
  }
  &.#{$namespace}btn-solid {
    background: $color;
    border-color: transparent;
    @if (lightness($color) < 70) {
      color: $color-white;
      &.#{$namespace}loading {
        &::after {
          border-bottom-color: $color-white;
          border-left-color: $color-white;
        }
      }
    }
    &[disabled],
    &:disabled,
    &.#{$namespace}disabled {
      background: $text-color-secondary-light;
      border-color: transparent;
    }
  }
}

// Margin utility mixin
@mixin margin-variant($id: 1, $size: $unit-1) {
  .#{$namespace}m-#{$id} {
    margin: $size;
  }

  .#{$namespace}mb-#{$id} {
    margin-bottom: $size;
  }

  .#{$namespace}ml-#{$id} {
    margin-left: $size;
  }

  .#{$namespace}mr-#{$id} {
    margin-right: $size;
  }

  .#{$namespace}mt-#{$id} {
    margin-top: $size;
  }

  .#{$namespace}mh-#{$id} {
    margin-left: $size;
    margin-right: $size;
  }

  .#{$namespace}mv-#{$id} {
    margin-bottom: $size;
    margin-top: $size;
  }
}

// Padding utility mixin
@mixin padding-variant($id: 1, $size: $unit-1) {
  .#{$namespace}p-#{$id} {
    padding: $size;
  }

  .#{$namespace}pb-#{$id} {
    padding-bottom: $size;
  }

  .#{$namespace}pl-#{$id} {
    padding-left: $size;
  }

  .#{$namespace}pr-#{$id} {
    padding-right: $size;
  }

  .#{$namespace}pt-#{$id} {
    padding-top: $size;
  }

  .#{$namespace}ph-#{$id} {
    padding-left: $size;
    padding-right: $size;
  }
  
  .#{$namespace}pv-#{$id} {
    padding-bottom: $size;
    padding-top: $size;
  }
}

// Component transition
@mixin control-transition() {
  transition: all .2s ease;
}

@mixin shadow-variant($offset) {
  box-shadow: 0 $offset ($offset + 1px) * 2 rgba(#454d5d, .3);
}

// Background color utility mixin
@mixin bg-color-variant($name: ".bg-primary", $color: $primary-color) {
  #{$name} {
    background: $color;

    @if (lightness($color) < 60) {
      color: $color-white;
    }
  }
}

// Text color utility mixin
@mixin text-color-variant($name: ".text-primary", $color: $primary-color) {
  #{$name} {
    color: $color;
  }

  a#{$name} {
    &:focus,
    &:hover {
      color: darken($color, 5%);
    }
  }
}
// Text Ellipsis
@mixin text-ellipsis() {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// Label base style
@mixin label-base($padding:2px 3px, $line-height:1.2, $border-radius:$border-radius) {
  border-radius: $border-radius;
  line-height: $line-height;
  padding: $padding;
}

@mixin label-variant($color: $color-white, $bg-color: $background-color-primary) {
  background: $bg-color;
  color: $color;
}

@mixin label-block-variant($color: $color-white) {
  border: $border-width solid $color;
  color: $color;
}

@mixin tag-variant($color: $color-white, $bg-color: $background-color-primary, $border-color: $line-color-primary) {
  background: $bg-color;
  color: $color;
  border: 1px solid transparent;
  &:hover {
    border: 1px solid $border-color;
  }
  &:active {
    background: $border-color;
    @if (lightness($border-color) < 70) {
      color: $color-white;
    }
  }
}
// Toast variant mixin, 组件无使用场景
@mixin toast-variant($color: $background-color-white) {
  background: rgba($color, .98);
  border-color: $color;
  @if (lightness($color) < 70) {
    color: $color-white;
    .#{$namespace}btn {
      color: $color-white;
    }
  }
}
// Message variant mixin, 组件无使用场景
@mixin message-variant($color: $background-color-white) {
  background: rgba($color, .9);
  border-color: $color;
  @if (lightness($color) < 60) {
    color: $color-white;
    .#{$namespace}btn {
      color: $color-white;
    }
  }
}

