//
// General: Mixins
//


// Cards Variant
@mixin cards-variant($name, $color) {
  .card-#{$name} {
    &:not(.card-outline) {
      > .card-header {
        background-color: $color;
        border-bottom: 0;

        &,
        a {
          color: color-yiq($color);
        }
      }
    }

    &.card-outline {
      border-top: 3px solid $color;
    }
  }

  .bg-#{$name},
  .bg-gradient-#{$name},
  .card-#{$name}:not(.card-outline) {
    .btn-tool {
      color: rgba(color-yiq($color), 0.8);

      &:hover {
        color: color-yiq($color);
      }
    }
  }

  .card.bg-#{$name},
  .card.bg-gradient-#{$name} {
    .bootstrap-datetimepicker-widget {
      .table td,
      .table th {
        border: none;
      }

      table thead tr:first-child th:hover,
      table td.day:hover,
      table td.hour:hover,
      table td.minute:hover,
      table td.second:hover {
        background: darken($color, 8%);
        color: color-yiq($color);
      }

      table td.today::before {
        border-bottom-color: color-yiq($color);
      }

      table td.active,
      table td.active:hover {
        background: lighten($color, 10%);
        color: color-yiq($color);
      }
    }
  }
}

// Sidebar Color
@mixin sidebar-color($color) {
  .nav-sidebar > .nav-item {
    & > .nav-link.active {
      background-color: $color;
      color: color-yiq($color);
    }
  }
}

// Sidebar Mini Breakpoints
@mixin sidebar-mini-breakpoint() {
  // A fix for text overflow while transitioning from sidebar mini to full sidebar
  .nav-sidebar,
  .nav-sidebar > .nav-header,
  .nav-sidebar .nav-link {
    white-space: nowrap;
    overflow: hidden;
  }

  // When the sidebar is collapsed...
  &.sidebar-collapse {
    .d-hidden-mini {
      display: none;
    }

    // Apply the new margins to the main content and footer
    .content-wrapper,
    .main-footer,
    .main-header {
      margin-left: $sidebar-mini-width !important;
    }

    // Make the sidebar headers
    .nav-sidebar .nav-header {
      display: none;
    }

    .nav-sidebar .nav-link p {
      width: 0;
    }

    .sidebar .user-panel > .info,
    .nav-sidebar .nav-link p,
    .brand-text {
      margin-left: -10px;
      opacity: 0;
      visibility: hidden;
    }

    .logo-xl {
      opacity: 0;
      visibility: hidden;
    }

    .logo-xs {
      display: inline-block;
      opacity: 1;
      visibility: visible;
    }

    // Modify the sidebar to shrink instead of disappearing
    .main-sidebar {
      overflow-x: hidden;

      &,
      &::before {
        // Don't go away! Just shrink
        margin-left: 0;
        width: $sidebar-mini-width;
      }

      .user-panel {
        .image {
          float: none;
        }
      }

      &:hover,
      &.sidebar-focused {
        width: $sidebar-width;

        .nav-sidebar.nav-child-indent .nav-treeview {
          padding-left: 1rem;
        }

        .brand-link {
          width: $sidebar-width;
        }

        .user-panel {
          text-align: left;

          .image {
            float: left;
          }
        }

        .user-panel > .info,
        .nav-sidebar .nav-link p,
        .brand-text,
        .logo-xl {
          display: inline-block;
          margin-left: 0;
          opacity: 1;
          visibility: visible;
        }

        .logo-xs {
          opacity: 0;
          visibility: hidden;
        }

        .brand-image {
          margin-right: .5rem;
        }

        // Make the sidebar links, menus, labels, badges
        // and angle icons disappear
        .sidebar-form,
        .user-panel > .info {
          display: block !important;
          -webkit-transform: translateZ(0);
        }

        .nav-sidebar > .nav-item > .nav-link > span {
          display: inline-block !important;
        }
      }
    }

    // Make an element visible only when sidebar mini is active
    .visible-sidebar-mini {
      display: block !important;
    }

    &.layout-fixed {
      .main-sidebar:hover {
        .brand-link {
          width: $sidebar-width;
        }
      }

      .brand-link {
        width: $sidebar-mini-width;
      }
    }
  }
}

// Navbar Variant
@mixin navbar-variant($color, $font-color: rgba(255, 255, 255, 0.8), $hover-color: #f6f6f6, $hover-bg: rgba(0, 0, 0, 0.1)) {
  background-color: $color;

  .nav > li > a {
    color: $font-color;
  }

  .nav > li > a:hover,
  .nav > li > a:active,
  .nav > li > a:focus,
  .nav .open > a,
  .nav .open > a:hover,
  .nav .open > a:focus,
  .nav > .active > a {
    background: $hover-bg;
    color: $hover-color;
  }

  // Add color to the sidebar toggle button
  .sidebar-toggle {
    color: $font-color;

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

// Logo color Variant
@mixin logo-variant($bg-color, $color: #fff, $border-bottom-color: transparent, $border-bottom-width: 0) {
  background-color: $bg-color;
  border-bottom: $border-bottom-width solid $border-bottom-color;
  color: $color;

  &:hover,
  &:focus {
    background-color: darken($bg-color, 1%);
  }
}

// Direct Chat Variant
@mixin direct-chat-variant($bg-color, $color: #fff) {
  .right > .direct-chat-text {
    background: $bg-color;
    border-color: $bg-color;
    color: color-yiq($bg-color);

    &::after,
    &::before {
      border-left-color: $bg-color;
    }
  }

  @each $name, $color in $theme-colors {
    &.bg-#{$name},
    &.bg-gradient-#{$name} {
      .direct-chat-timestamp {
        @if (color-yiq($color) == $yiq-text-dark) {
          color: lighten(color-yiq($color), 10%);
        } @else {
          color: darken(color-yiq($color), 20%);
        }
      }
    }
  }

  @each $name, $color in $colors {
    &.bg-#{$name},
    &.bg-gradient-#{$name} {
      .direct-chat-timestamp {
        @if (color-yiq($color) == $yiq-text-dark) {
          color: lighten(color-yiq($color), 10%);
        } @else {
          color: darken(color-yiq($color), 20%);
        }
      }
    }
  }
}

// Background Variant
@mixin background-variant($name, $color) {
  .bg-#{$name} {
    background-color: #{$color} !important;

    &,
    > a {
      color: color-yiq($color) !important;
    }

    &.btn {
      &:hover {
        border-color: darken($color, 10%);
        color: darken(color-yiq($color), 7.5%);
      }

      &:active,
      &.active {
        border-color: darken($color, 12.5%);
        color: darken(color-yiq($color), 10%);
      }
    }
  }
}

// Background Gradient Variant
@mixin background-gradient-variant($name, $color) {
  .bg-gradient-#{$name} {
    @include bg-gradient-variant('&', $color);
    color: color-yiq($color);

    &.btn {
      &.disabled,
      &:disabled,
      &:not(:disabled):not(.disabled):active,
      &:not(:disabled):not(.disabled).active,
      .show > &.dropdown-toggle {
        background-image: none !important;
      }

      &:hover {
        @include bg-gradient-variant('&', darken($color, 7.5%));
        border-color: darken($color, 10%);
        color: darken(color-yiq($color), 7.5%);
      }

      &:active,
      &.active {
        @include bg-gradient-variant('&', darken($color, 10%));
        border-color: darken($color, 12.5%);
        color: darken(color-yiq($color), 10%);
      }
    }
  }
}

// Custom Switch Variant
@mixin custom-switch-variant($name, $color) {
  &.custom-switch-off-#{$name} {
    & .custom-control-input ~ .custom-control-label::before {
      background: #{$color};
      border-color: darken($color, 20%);
    }

    & .custom-control-input:focus ~ .custom-control-label::before {
      box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
    }

    & .custom-control-input ~ .custom-control-label::after {
      background: darken($color, 25%);
    }
  }

  &.custom-switch-on-#{$name} {
    & .custom-control-input:checked ~ .custom-control-label::before {
      background: #{$color};
      border-color: darken($color, 20%);
    }

    & .custom-control-input:checked:focus ~ .custom-control-label::before {
      box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
    }

    & .custom-control-input:checked ~ .custom-control-label::after {
      background: lighten($color, 30%);
    }
  }
}

// Custom Range Variant
@mixin custom-range-variant($name, $color) {
  &.custom-range-#{$name} {
    &:focus {
      outline: none;

      &::-webkit-slider-thumb {
        box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
      }

      &::-moz-range-thumb     {
        box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
      }

      &::-ms-thumb            {
        box-shadow: 0 0 0 1px $body-bg, 0 0 0 2px rgba($color, .25);
      }
    }

    &::-webkit-slider-thumb {
      background-color: $color;

      &:active {
        background-color: lighten($color, 35%);
      }
    }

    &::-moz-range-thumb {
      background-color: $color;

      &:active {
        background-color: lighten($color, 35%);
      }
    }

    &::-ms-thumb {
      background-color: $color;

      &:active {
        background-color: lighten($color, 35%);
      }
    }
  }
}


// ETC
@mixin translate($x, $y) {
  transform: translate($x, $y);
}

// Different radius each side
@mixin border-radius-sides($top-left, $top-right, $bottom-left, $bottom-right) {
  border-radius: $top-left $top-right $bottom-left $bottom-right;
}

@mixin calc($property, $expression) {
  #{$property}: calc(#{$expression});
}

@mixin rotate($value) {
  transform: rotate($value);
}

@mixin animation($animation) {
  animation: $animation;
}

// Gradient background
@mixin gradient($color: #F5F5F5, $start: #EEE, $stop: #FFF) {
  background: $color;
  background: -webkit-gradient(linear, left bottom, left top, color-stop(0, $start), color-stop(1, $stop));
  background: -ms-linear-gradient(bottom, $start, $stop);
  background: -moz-linear-gradient(center bottom, $start 0%, $stop 100%);
  background: -o-linear-gradient($stop, $start);
}

