//
// Copyright 2016 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/animation/functions";
@import "@material/ripple/common";
@import "@material/ripple/mixins";
@import "@material/ripple/variables";
@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, 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(border-color);
    border-width: 10px;
    border-style: solid;
    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--background-focused {
    .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(border-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(border-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 {
      border-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: map-get($mdc-ripple-dark-ink-opacities, focus);
  }
}

// postcss-bem-linter: end
