@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

:root,
:host {
  --xzx-switch-size: 26px;
  --xzx-switch-width: 45px;
  --xzx-switch-height: 28px;
  --xzx-switch-node-size: 20px;
  --xzx-switch-node-background: var(--xzx-color-white);
  --xzx-switch-node-shadow: 0 3px 1px 0 rgba(0, 0, 0, 0.05);
  --xzx-switch-background: rgba(120, 120, 128, 0.16);
  --xzx-switch-on-background: var(--xzx-color-primary);
  --xzx-switch-duration: var(--xzx-duration-base);
  --xzx-switch-disabled-opacity: var(--xzx-disabled-opacity);
}

.xzx-theme-dark {
  --xzx-switch-background: rgba(120, 120, 128, 0.32);
}

@include b(switch) {
  position: relative;
  display: inline-block;
  box-sizing: content-box;
  width: var(--xzx-switch-width);
  height: var(--xzx-switch-height);
  font-size: var(--xzx-switch-size);
  background: var(--xzx-switch-background);
  border-radius: var(--xzx-br-round);
  cursor: pointer;
  transition: background-color var(--xzx-switch-duration);

  &__node {
    position: absolute;
    top: 4px;
    left: 4px;
    width: var(--xzx-switch-node-size);
    height: var(--xzx-switch-node-size);
    // https://github.com/vant-ui/vant/issues/9839
    font-size: inherit;
    background: var(--xzx-switch-node-background);
    border-radius: 100%;
    box-shadow: var(--xzx-switch-node-shadow);
    transition: transform var(--xzx-switch-duration)
      cubic-bezier(0.3, 1.05, 0.4, 1.05);
  }

  &__loading {
    width: 100%;
    height: 100%;
    line-height: 1;
    font-size: var(--xzx-text-sm);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  &--on {
    background: var(--xzx-switch-on-background);

    .xzx-switch__node {
      transform: translateX(
        calc(var(--xzx-switch-width) - var(--xzx-switch-node-size) - 8px)
      );
    }

    .xzx-switch__loading {
      color: var(--xzx-switch-on-background);
    }
  }

  &--disabled {
    cursor: not-allowed;
    opacity: var(--xzx-switch-disabled-opacity);
  }

  &--loading {
    cursor: default;
  }
}
