@import "./toggle";
@import "./toggle.ios.vars";

// iOS Toggle
// -----------------------------------------

.toggle-ios {
  box-sizing: content-box;
  position: relative;

  width: $toggle-ios-width;
  height: $toggle-ios-height;

  contain: strict;
}


// iOS Toggle Background Track: Unchecked
// -----------------------------------------

.toggle-ios .toggle-icon {
  @include border-radius($toggle-ios-border-radius);

  position: relative;
  display: block;

  width: 100%;
  height: 100%;

  background-color: $toggle-ios-border-color-off;
  transition: background-color $toggle-ios-transition-duration;

  pointer-events: none;
}


// iOS Toggle Background Oval: Unchecked
// -----------------------------------------

.toggle-ios .toggle-icon::before {
  @include position($toggle-ios-border-width, $toggle-ios-border-width, $toggle-ios-border-width, $toggle-ios-border-width);
  @include border-radius($toggle-ios-border-radius);

  position: absolute;

  background-color: $toggle-ios-background-color-off;

  content: "";
  transform: scale3d(1, 1, 1);
  transition: transform $toggle-ios-transition-duration;
}


// iOS Toggle Inner Knob: Unchecked
// -----------------------------------------

.toggle-ios .toggle-inner {
  @include position($toggle-ios-border-width, null, null, $toggle-ios-border-width);
  @include border-radius($toggle-ios-handle-border-radius);

  position: absolute;

  width: $toggle-ios-handle-width;
  height: $toggle-ios-handle-height;

  background-color: $toggle-ios-handle-background-color;
  box-shadow: $toggle-ios-handle-box-shadow;

  transition: transform $toggle-ios-transition-duration, width 120ms ease-in-out 80ms, left 110ms ease-in-out 80ms, right 110ms ease-in-out 80ms;

  will-change: transform;
  contain: strict;
}


// iOS Toggle Background Track: Checked
// -----------------------------------------

.toggle-ios.toggle-checked .toggle-icon {
  background-color: $toggle-ios-background-color-on;
}


// iOS Toggle Background Oval: Activated or Checked
// -----------------------------------------

.toggle-ios.toggle-activated .toggle-icon::before,
.toggle-ios.toggle-checked .toggle-icon::before {
  transform: scale3d(0, 0, 0);
}


// iOS Toggle Inner Knob: Checked
// -----------------------------------------

.toggle-ios.toggle-checked .toggle-inner {
  @include transform(translate3d($toggle-ios-width - $toggle-ios-handle-width - ($toggle-ios-border-width * 2), 0, 0));
}


// iOS Toggle Background Oval: Activated and Checked
// -----------------------------------------

.toggle-ios.toggle-activated.toggle-checked .toggle-inner::before {
  transform: scale3d(0, 0, 0);
}


// iOS Toggle Inner Knob: Activated and Unchecked
// -----------------------------------------

.toggle-ios.toggle-activated .toggle-inner {
  width: $toggle-ios-handle-width + 6;
}


// iOS Toggle Inner Knob: Activated and Checked
// -----------------------------------------

.toggle-ios.toggle-activated.toggle-checked .toggle-inner {
  // when pressing down on the toggle and IS checked
  // make the knob wider and move it left a bit
  @include position-horizontal($toggle-ios-border-width - 6, null);
}


// iOS Toggle: Disabled
// -----------------------------------------

.toggle-ios.toggle-disabled,
.item-ios.item-toggle-disabled ion-label {
  opacity: $toggle-ios-disabled-opacity;

  pointer-events: none;
}


// iOS Toggle Within An Item
// -----------------------------------------

.item-ios .toggle-ios[slot] {
  @include margin($toggle-ios-media-margin);
  @include padding($toggle-ios-item-end-padding-top, $toggle-ios-item-end-padding-end, $toggle-ios-item-end-padding-bottom, $toggle-ios-item-end-padding-start);
}

.item-ios .toggle-ios[slot="start"] {
  @include padding($toggle-ios-item-start-padding-top, $toggle-ios-item-start-padding-end, $toggle-ios-item-start-padding-bottom, $toggle-ios-item-start-padding-start);
}


// iOS Toggle Color Mixin
// --------------------------------------------------

@mixin ios-toggle-theme($color-name) {
  $color-base: ion-color($colors-ios, $color-name, base, ios);

  .toggle-ios-#{$color-name}.toggle-checked .toggle-icon {
    background-color: $color-base;
  }
}


// Generate iOS Toggle Colors
// --------------------------------------------------

@each $color-name, $color-value in $colors-ios {
  @include ios-toggle-theme($color-name);
}
