//
// Copyright 2018 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions://
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

@import "@material/elevation/mixins";
@import "@material/rtl/mixins";
@import "@material/ripple/common";
@import "@material/ripple/mixins";
@import "./functions";
@import "./mixins";
@import "./variables";

.mdc-switch {
  @include mdc-switch-toggled-on-track-color($mdc-switch-baseline-theme-color);
  @include mdc-switch-toggled-on-thumb-color($mdc-switch-baseline-theme-color);
  @include mdc-switch-toggled-off-track-color($mdc-switch-toggled-off-track-color);
  @include mdc-switch-toggled-off-thumb-color($mdc-switch-toggled-off-thumb-color);
  @include mdc-switch-toggled-off-ripple-color($mdc-switch-toggled-off-ripple-color);

  display: inline-block;
  position: relative;
  outline: none;
  user-select: none;
}

.mdc-switch__native-control {
  @include mdc-rtl-reflexive-position(left, 0);

  position: absolute;
  top: 0;
  width: $mdc-switch-native-control-width;
  height: $mdc-switch-tap-target-size;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  pointer-events: auto;
}

.mdc-switch__track {
  box-sizing: border-box;
  width: $mdc-switch-track-width;
  height: $mdc-switch-track-height;
  transition:
    mdc-switch-transition(opacity),
    mdc-switch-transition(background-color),
    mdc-switch-transition(border-color);
  border: 1px solid;
  border-radius: $mdc-switch-track-height / 2;
  opacity: .38;
}

.mdc-switch__thumb-underlay {
  @include mdc-rtl-reflexive-position(left, $mdc-switch-tap-target-initial-position);
  @include mdc-ripple-surface();
  @include mdc-ripple-radius-unbounded;
  @include mdc-states($mdc-switch-baseline-theme-color);

  display: flex;
  position: absolute;
  // Ensures the knob is centered on the track.
  top: -(($mdc-switch-tap-target-size - $mdc-switch-track-height) / 2);
  align-items: center;
  justify-content: center;
  width: $mdc-switch-tap-target-size;
  height: $mdc-switch-tap-target-size;
  transform: translateX(0);
  transition:
    mdc-switch-transition(transform),
    mdc-switch-transition(background-color),
    mdc-switch-transition(border-color);
}

.mdc-switch__thumb {
  @include mdc-elevation(2);

  box-sizing: border-box;
  width: $mdc-switch-thumb-diameter;
  height: $mdc-switch-thumb-diameter;
  border: $mdc-switch-thumb-diameter / 2 solid;
  border-radius: 50%;
  // Allow events to go through to the native control, necessary for IE and Edge.
  pointer-events: none;
  z-index: 1;
}

.mdc-switch--checked {
  .mdc-switch__track {
    opacity: .54;
  }

  .mdc-switch__thumb-underlay {
    transform: translateX($mdc-switch-thumb-active-margin);

    @include mdc-rtl {
      transform: translateX(-($mdc-switch-thumb-active-margin));
    }
  }

  // Translate the native control the opposite direction so that the tap target stays the same.
  .mdc-switch__native-control {
    transform: translateX(-($mdc-switch-thumb-active-margin));

    @include mdc-rtl {
      transform: translateX($mdc-switch-thumb-active-margin);
    }
  }
}

.mdc-switch--disabled {
  opacity: .38;
  pointer-events: none;

  .mdc-switch__thumb {
    border-width: 1px;  // In high contrast mode, only show outline of knob.
  }

  .mdc-switch__native-control {
    cursor: default;
    pointer-events: none;
  }
}
