@use 'variables' as *;
@use '@xui/theme-core' as core;

@mixin theme() {
  .x-switch {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
    padding: 4px;

    #{$background-color-variable}: var(--color-bg-accent);

    input {
      opacity: 0;
      width: 100%;
      height: 100%;
      cursor: pointer;
    }

    &--disabled {
      @include core.disabled();
      cursor: not-allowed;

      input {
        cursor: not-allowed;
      }
    }

    &-element {
      position: relative;
      width: 42px;
      height: 24px;

      background-color: var(#{$background-color-variable});
      border-radius: 100px;
      cursor: pointer;

      @include core.focusable();
    }

    &-handle {
      display: grid;
      place-items: center;
      background-color: $handle-color;
      color: core.modifier-accent();
      border-radius: 50%;

      position: absolute;
      top: 3px;
      left: 3px;
      width: 18px;
      height: 18px;
      transition: all 0.4s ease-out;

      .x-icon {
        font-size: 16px;
      }
    }

    &-toggled {
      .x-switch-handle {
        left: calc(100% - 21px);
        transform: rotate(360deg);
      }
    }

    @each $name in core.$color-variations {
      &-#{$name} {
        background-color: var(--color-#{$name}-default);

        .x-switch-handle {
          color: var(--color-#{$name}-default);
        }
      }
    }
  }
}
