//
// Copyright 2019 Stijn de Witt. Some rights reserved.
// Licensed under the MIT Open Source license. 
// https://opensource.org/licenses/MIT
// See LICENSE for details.
//
// Based on code copyright 2018 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// http://www.apache.org/licenses/LICENSE-2.0
// See LICENSE-MDC for details.
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under these licenses is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the licenses for the specific language governing permissions and
// limitations under these licenses.
// 

@import "../animation/functions";
@import "../ripple/common";
@import "../ripple/mixins";
@import "./functions";
@import "./mixins";
@import "./variables";

// postcss-bem-linter: define radio
.mdc-radio {
  @include mdc-radio-unchecked-stroke-color($mdc-radio-unchecked-color);
  @include mdc-radio-checked-stroke-color($mdc-radio-baseline-theme-color);
  @include mdc-radio-ink-color($mdc-radio-baseline-theme-color);
  @include mdc-radio-focus-indicator-color($mdc-radio-baseline-theme-color);
  @include mdc-ripple-surface;
  @include mdc-ripple-radius-unbounded;
  @include mdc-states($mdc-radio-baseline-theme-color);

  display: inline-block;
  position: relative;
  flex: 0 0 auto;
  box-sizing: border-box;
  width: $mdc-radio-touch-area;
  height: $mdc-radio-touch-area;
  padding: ($mdc-radio-touch-area - $mdc-radio-ui-size) / 2;
  cursor: pointer;

  /* @alternate */
  will-change: opacity, transform, border-color, background-color, color;

  // Container for radio circles and ripple.
  &__background {
    display: inline-block;
    position: absolute;
    left: ($mdc-radio-touch-area - $mdc-radio-ui-size) / 2;
    box-sizing: border-box;
    width: $mdc-radio-ui-pct;
    height: $mdc-radio-ui-pct;

    &::before {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      transform: scale(0, 0);
      transition: mdc-radio-exit(opacity), mdc-radio-exit(transform);
      border-radius: 50%;
      opacity: 0;
      pointer-events: none;
      content: "";
    }
  }

  &__outer-circle {
    position: absolute;
    top: 0;
    left: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    transition: mdc-radio-exit(border-color);
    border-width: 2px;
    border-style: solid;
    border-radius: 50%;
  }

  &__inner-circle {
    position: absolute;
    top: 0;
    left: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    transform: scale(0, 0);
    transition: mdc-radio-exit(transform), mdc-radio-exit(background-color);
    border-radius: 50%;
  }

  &__native-control {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    opacity: 0;
    cursor: inherit;
    z-index: 1;
  }

  // stylelint-disable plugin/selector-bem-pattern
  &.mdc-ripple-upgraded {
    .mdc-radio__background::before {
      content: none;
    }
  }
  // stylelint-enable plugin/selector-bem-pattern
}

.mdc-radio__native-control:checked,
.mdc-radio__native-control:disabled {
  + .mdc-radio__background {
    transition: mdc-radio-enter(opacity), mdc-radio-enter(transform);

    .mdc-radio__outer-circle {
      transition: mdc-radio-enter(border-color);
    }

    .mdc-radio__inner-circle {
      transition: mdc-radio-enter(transform), mdc-radio-enter(background-color);
    }
  }
}

.mdc-radio--disabled {
  cursor: default;
  pointer-events: none;
}

.mdc-radio__native-control:checked {
  + .mdc-radio__background {
    .mdc-radio__inner-circle {
      transform: scale(.5);
      transition: mdc-radio-enter(transform), mdc-radio-enter(background-color);
    }
  }
}

.mdc-radio__native-control:disabled,
[aria-disabled="true"] .mdc-radio__native-control {
  + .mdc-radio__background {
    cursor: default;

    .mdc-radio__outer-circle {
      border-color: $mdc-radio-circle-color;
    }

    .mdc-radio__inner-circle {
      background-color: $mdc-radio-circle-color;
    }
  }
}

.mdc-radio__native-control:focus {
  + .mdc-radio__background::before {
    transform: scale(2, 2);
    transition: mdc-radio-enter(opacity), mdc-radio-enter(transform);
    opacity: .26;
  }
}

// postcss-bem-linter: end
