@import '../../_style/animation/variables.scss';
@import '../../_style/elevation/mixins.scss';

$md-switch-width: 34px;
$md-switch-height: 14px;
$md-switch-size: 20px;
$md-switch-touch-size: 48px;

.md-switch {
  width: auto;
  margin: 16px 16px 16px 0;
  display: inline-flex;
  align-items: center;
  position: relative;

  &:not(.md-disabled) {
    cursor: pointer;

    .md-switch-label {
      cursor: pointer;
    }
  }

  .md-switch-container {
    width: $md-switch-width;
    min-width: $md-switch-width;
    height: $md-switch-height;
    position: relative;

    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      opacity: 0.38;
      z-index: 0;
      border-radius: $md-switch-height;
      transition: $md-transition-stand;
      background-color: var(--md-on-surface-disabled);
    }
  }

  .md-switch-thumb {
    @include md-elevation(1);

    width: $md-switch-size;
    height: $md-switch-size;
    position: absolute;
    z-index: 99;
    left: 0;
    top: 50%;
    border-radius: 50%;
    transition: $md-transition-stand;
    background-color: var(--md-on-surface-medium);
    transform: translate3d(0, -50%, 0);

    &::before {
      width: $md-switch-touch-size;
      height: $md-switch-touch-size;
      position: absolute;
      top: 50%;
      left: 50%;
      z-index: 11;
      transform: translate(-50%, -50%);
      content: ' ';
    }

    .md-ripple {
      width: $md-switch-touch-size !important;
      height: $md-switch-touch-size !important;
      top: 50% !important;
      left: 50% !important;
      position: absolute;
      transform: translate(-50%, -50%);
      border-radius: 50%;
    }

    input {
      position: absolute;
      left: -999em;
    }
  }

  .md-switch-label {
    height: $md-switch-size;
    padding-left: 16px;
    position: relative;
    line-height: $md-switch-size;
  }
}

.md-switch.md-checked {
  .md-switch-container::before {
    background-color: var(--md-secondary);
  }

  .md-switch-thumb {
    transform: translate3d(15px, -50%, 0);
    background-color: var(--md-secondary);
  }

  .md-ripple {
    color: var(--md-secondary);
  }

  &.md-primary {
    .md-switch-container::before,
    .md-switch-thumb {
      background-color: var(--md-primary);
    }

    .md-ripple {
      color: var(--md-primary);
    }
  }
}

.md-switch.md-required {
  label::after {
    position: absolute;
    top: 2px;
    right: 0;
    transform: translateX(calc(100% + 2px));
    content: '*';
    line-height: 1em;
    vertical-align: top;
  }
}

.md-switch.md-disabled {
  opacity: 0.38;
}
