@mixin switch-theme($name, $color) {
  &.ui-#{$name}:not(.ui-checked):active {
    box-shadow: inset 0 0 0 1em $color;
  }
  &.ui-#{$name}.ui-checked {
    box-shadow: inset 0 0 0 1em $color;
  }

  &.ui-#{$name}:not(.ui-checked).ui-focus {
    box-shadow: inset 0 0 0 2px $color;
  }
}

ui-switch {
  display: inline-block;
  height: 32px;
  width: 52px;
  font-size: 32px;
  background: none;
  box-shadow: inset 0 0 0 2px darken($color-gray-light, 20);
  vertical-align: middle;
  border-radius: 16px;
  position: relative;
  padding: 2px;
  transition: all .2s;
  cursor: pointer;
  > .ui-input-raw {
    opacity: 0;
    padding: 0;
    position: absolute;
    left: 0;
    top: 0;
    width: inherit;
    height: inherit;
    right: 0;
    bottom: 0;
    cursor: pointer;
  }
  &[readonly] {
    cursor: auto;
  }
  &.ui-checked {
    .ui-switch-btn {
      transform: translateX(20px);
    }
  }
  &:active {
    .ui-switch-btn {
      width: 34px;
    }
    &.ui-checked {
      .ui-switch-btn {
        left: -6px;
      }
    }
  }
  &:not(.ui-checked):active {
    box-shadow: inset 0 0 0 1em $color-default;
    border-color: $color-default;
  }
  &.ui-checked {
    box-shadow: inset 0 0 0 1em $color-default;
    border-color: $color-default;
  }
  @include switch-theme(dark, $color-dark);
  @include switch-theme(gray, $color-gray);
  @include switch-theme(primary, $color-primary);
  @include switch-theme(success, $color-success);
  @include switch-theme(info, $color-info);
  @include switch-theme(warning, $color-warning);
  @include switch-theme(danger, $color-danger);

  &.disabled, &[disabled] {
    opacity: .5;
    cursor: not-allowed;
  }
}

.ui-switch {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 14px;
  cursor: inherit;
  background: none;
  border: none;
  padding: 0;
  display: block;
}

.ui-switch-btn {
  width: 28px;
  height: 28px;
  border-radius: 14px;
  background-color: #fff;
  border: none;
  position: absolute;
  left: 0;
  top: 0;
  transition: all .3s;
  box-shadow: 0 .05em .3em rgba(0, 0, 0, .4);
  overflow: hidden;
  > span {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
  }
}
