/**
* Copyright (c) 2022 - present TinyVue Authors.
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

@import '../custom.less';
@import './vars.less';

@switch-prefix-cls: ~'@{css-prefix}switch';

.@{switch-prefix-cls} {
  .inject-Switch-vars();

  display: inline-block;
  width: var(--tv-Switch-width);
  height: var(--tv-Switch-height);
  line-height: var(--tv-Switch-height);
  border-radius: var(--tv-Switch-border-radius);
  vertical-align: middle;
  background-color: var(--tv-Switch-off-bg-color);
  position: relative;
  cursor: pointer;
  outline: none;
  transition:
    border 0.2s ease-in-out,
    background-color 0.2s ease-in-out;

  &:focus-visible {
    outline: 2px solid var(--tv-Switch-on-bg-color);
    outline-offset: 1px;
  }

  & &-inner {
    color: var(--tv-Switch-text-color);
    font-size: var(--tv-Switch-inner-font-size);
    position: absolute;
  }

  &__text {
    width: var(--tv-Switch-text-width);
    .@{switch-prefix-cls}-inner {
      left: calc(var(--tv-Switch-dot-size));
      width: calc(100% - var(--tv-Switch-dot-size));
      text-align: center;
      overflow: hidden;
    }
  }

  &__on-loading {
    font-size: var(--tv-Switch-on-loading-font-size);
    fill: var(--tv-Switch-on-loading-fill);
  }

  &__off-loading {
    font-size: var(--tv-Switch-off-loading-font-size);
    fill: var(--tv-Switch-off-loading-fill);
  }

  &__loading-mini {
    font-size: var(--tv-Switch-loading-mini-font-size);
  }

  &.mini {
    width: var(--tv-Switch-mini-width);
    height: var(--tv-Switch-mini-height);
  }

  &&-checked.disabled,
  &.disabled {
    cursor: not-allowed;
    background: var(--tv-Switch-disabled-bg-color);
    border-color: var(--tv-Switch-disabled-bg-color);

    &:after {
      cursor: not-allowed;
    }
  }

  &&-checked.disabled {
    background: var(--tv-Switch-checked-disabled-bg-color);
  }

  &__button {
    display: flex;
    justify-content: center;
    align-items: center;
    content: '';
    width: var(--tv-Switch-dot-size);
    height: var(--tv-Switch-dot-size);
    border-radius: 50%;
    background-color: var(--tv-Switch-dot-bg-color);
    position: absolute;
    left: var(--tv-Switch-dot-position-left);
    top: var(--tv-Switch-dot-position-top);
    cursor: pointer;
    transition:
      left 0.2s ease-in-out,
      width 0.2s ease-in-out;
  }

  &.mini &__button {
    height: var(--tv-Switch-mini-button-height);
    width: var(--tv-Switch-mini-button-width);
  }

  &&-checked {
    background-color: var(--tv-Switch-on-bg-color);

    .@{switch-prefix-cls}-inner {
      left: 2px;
      width: calc(100% - var(--tv-Switch-dot-size));
      text-align: center;
      overflow: hidden;
    }
  }

  &&-checked .@{switch-prefix-cls}__button {
    left: calc(100% - var(--tv-Switch-dot-offset));
  }

  &&-checked&.mini &__button {
    left: var(--tv-Switch-mini-button-left);
  }

  .disabled &__button {
    background-color: var(--tv-color-bg-inverse-disabled);
  }
}