/**
 * Office UI Fabric JS 1.5.0
 * The JavaScript front-end framework for building experiences for Office 365.
 **/
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE in the project root for license information.

//
// Office UI Fabric
// --------------------------------------------------
// Toggle styles


@import '../Label/Label.scss';

// Slider mixin
@mixin ms-Toggle-slider($direction) {
  // Slider pseudo element
  &::before {
    position: absolute;
    top: 3px;
    width: 10px;
    height: 10px;
    border-radius: 10px;
    content: '';
    #{$direction}: 4px;
    background-color: $ms-color-neutralSecondary;
    outline: 1px solid transparent;
    transition-property: background, left;
    transition-duration: 250ms;
    transition-timing-function: cubic-bezier(.4, 0, .23, 1);

    @media screen and (-ms-high-contrast: active) {
      border: 2.5px solid $ms-color-white;
      height: 15px;
      outline: 0;
    }

    @media screen and (-ms-high-contrast: black-on-white) {
      border-color: $ms-color-black;
    }
  }

  @if $direction == left {
    &::before {
      right: auto;
    }
  }

  @if $direction == right {
    &::before {
      background-color: $ms-color-white;
      left: 28px;
    }
  }
}

// Toggle
.ms-Toggle {
  @include ms-baseFont;
  @include ms-font-m;
  @include ms-u-normalize;
  position: relative;
  display: block;
  margin-bottom: 26px;

  // Action label (on/off) on the right of the toggle
  .ms-Label {
    position: relative;
    top: -2px;
    padding: 0 0 0 50px;
  }

  // 'Off' state - slider on the left
  & .ms-Toggle-field {
    @include ms-Toggle-slider(left);

    // Show the off label / hide the on label
    .ms-Label--off {
      display: block;
    }

    .ms-Label--on {
      display: none;
    }
  }

  // 'On' state - slider on the right
  & .ms-Toggle-field.is-selected {
    background-color: $ms-color-themePrimary;
    border-color: $ms-color-themePrimary;

    @include ms-Toggle-slider(right);

    // Show the on label / hide the off label
    .ms-Label--off {
      display: none;
    }

    .ms-Label--on {
      display: block;
    }

    @media screen and (-ms-high-contrast: active) {
      background-color: $ms-color-white;
    }

    @media screen and (-ms-high-contrast: black-on-white) {
      background-color: $ms-color-black;
    }
  }

  &:focus,
  &:hover {
    & + .ms-Toggle-field {
      border-color: $ms-color-neutralSecondary;
    }

    & + .ms-Toggle-field::before {
      background-color: $ms-color-neutralPrimary;
    }

    &:checked + .ms-Toggle-field {
      background-color: $ms-color-themeDarkAlt;
      border-color: $ms-color-themeDarkAlt;
    }

    &:checked + .ms-Toggle-field::before {
      background-color: $ms-color-white;
    }
  }

  &:active {
    &:checked + .ms-Toggle-field {
      background-color: $ms-color-themeDark;
      border-color: $ms-color-themeDark;
    }
  }

  .ms-Toggle-field {
    &:focus,
    &:hover {
      border-color: $ms-color-neutralPrimary;
    }

    &.is-selected {
      &:focus,
      &:hover {
        background-color: $ms-color-themeDarkAlt;
        border-color: $ms-color-themeDarkAlt;
      }
    }

    .ms-Label {
      color: $ms-color-black;
      user-select: none;
    }

    &:hover {
      .ms-Label {
        color: $ms-color-black;
      }
    }

    &:active {
      .ms-Label {
        color: $ms-color-neutralPrimary;
      }
    }
  }

  // Disabled state
  &.is-disabled {
    .ms-Label {
      @include ms-Label-is-disabled;
    }

    .ms-Toggle-field {
      background-color: $ms-color-white;
      border-color: $ms-color-neutralTertiaryAlt;
      pointer-events: none;
      cursor: default;

      &::before {
        background-color: $ms-color-neutralTertiaryAlt;
      }
    }

    .ms-Toggle-field,
    .ms-Toggle-field::before {
      @media screen and (-ms-high-contrast: active) {
        border-color: $ms-color-contrastBlackDisabled;
      }

      @media screen and (-ms-high-contrast: black-on-white) {
        border-color: $ms-color-contrastWhiteDisabled;
      }
    }
  }
}

// Description text
.ms-Toggle-description {
  position: relative;
  font-size: $ms-font-size-m;
  vertical-align: top;
  display: block;
  margin-bottom: 8px;
}

// Toggle input field
.ms-Toggle-field {
  position: relative;
  display: inline-block;
  width: 45px;
  height: 20px;
  box-sizing: border-box;
  border: 2px solid $ms-color-neutralTertiary;
  border-radius: 20px;
  cursor: pointer;
  transition-property: background, left, border-color;
  transition-duration: 250ms;
  transition-timing-function: cubic-bezier(.4, 0, .23, 1);
  outline: 0;

  &:hover,
  &:focus {
    border-color: $ms-color-neutralSecondary;
  }
}

// On/Off slide states
.ms-Toggle-input {
  display: none;
}

//== Modifier: Toggle with description text left
//
.ms-Toggle.ms-Toggle--textLeft {
  width: 225px;
  margin-bottom: 40px;

  .ms-Toggle-description {
    display: inline-block;
    max-width: 150px;
    top: -3px;
    margin-bottom: 0;
  }

  .ms-Toggle-field {
    float: right;
  }
}
