/**
* 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 '../mixins/common.less';
@import '../custom.less';
@import './vars.less';
@import '../checkbox/vars.less';

@checkbox-button-prefix-cls: ~'@{css-prefix}checkbox-button';

.@{checkbox-button-prefix-cls} {
  .component-css-vars-checkbox();
  .component-css-vars-checkbox-button();

  position: relative;
  display: inline-block;
  margin-top: var(--ti-checkbox-button-margin-top);

  &:first-child &__inner {
    border-radius: var(--ti-common-border-radius-normal) var(--ti-checkbox-button-right-border-radius)
      var(--ti-checkbox-button-right-border-radius) var(--ti-common-border-radius-normal);
  }

  &:last-child &__inner {
    border-radius: var(--ti-checkbox-button-left-border-radius) var(--ti-common-border-radius-normal)
      var(--ti-common-border-radius-normal) var(--ti-checkbox-button-left-border-radius);
  }

  &.is-checked {
    &::after {
      content: '';
      position: absolute;
      width: 0;
      height: 0;
      right: 4px;
      top: 0;
      border-bottom: 20px solid transparent;
      border-right: 20px solid var(--ti-checkbox-button-checked-border-color);
      border-top-right-radius: 6px;
      display: var(--ti-checkbox-button-checked-display);
    }

    &::before {
      display: var(--ti-checkbox-button-checked-display);
      right: 7px;
      top: 1px;
      box-sizing: content-box;
      content: '';
      border: 0.5px solid #fff;
      border-width: 0 var(--ti-checkbox-checkline-width) var(--ti-checkbox-checkline-width) 0;
      border-left: 0;
      border-top: 0;
      height: 8px;
      width: 4px;
      position: absolute;
      margin-left: var(--ti-checkbox-icon-margin-left);
      margin-top: var(--ti-checkbox-icon-margin-top);
      transition:
        transform 0.15s ease-in 0.05s,
        -webkit-transform 0.15s ease-in 0.05s;
      transform-origin: center;
      z-index: 3;
      transform: rotate(45deg) scale(0.7);
    }

    .@{checkbox-button-prefix-cls}__inner {
      color: var(--ti-checkbox-button-checked-text-color);
      border-color: var(--ti-checkbox-button-checked-border-color);
      box-shadow: -1px 0 0 0 var(--ti-checkbox-shadow-color);
      background-color: var(--ti-checkbox-button-checked-bg-color);
    }

    &:first-child .@{checkbox-button-prefix-cls}__inner {
      border-left-color: var(--ti-checkbox-button-checked-border-color);
      box-shadow: none;
    }
  }

  &.is-disabled {
    .@{checkbox-button-prefix-cls}__inner {
      color: var(--ti-checkbox-button-disabled-text-color);
      cursor: not-allowed;
      background-image: none;
      background-color: var(--ti-checkbox-button-disabled-bg-color);
      border-color: var(--ti-checkbox-disabled-border-color);
      box-shadow: none;
    }

    &:first-child .@{checkbox-button-prefix-cls}__inner {
      border-left-color: var(--ti-checkbox-border-color);
    }
  }
  &.is-disabled.is-checked {
    &::after {
      border-right: 20px solid var(--ti-checkbox-disabled-border-color);
    }
    .@{checkbox-button-prefix-cls}__inner {
      color: var(--ti-checkbox-button-disabled-text-color);
      border-color: var(--ti-checkbox-disabled-border-color);
      background-color: var(--ti-checkbox-button-disabled-bg-color);
    }
  }

  &__inner {
    position: relative;
    display: inline-block;
    white-space: nowrap;
    vertical-align: middle;
    outline: 0;
    line-height: 1;
    font-weight: 500;
    cursor: pointer;
    background: var(--ti-checkbox-button-bg-color);
    border-left: 0;
    border: 1px solid var(--ti-checkbox-button-border-color);
    color: var(--ti-checkbox-button-text-color);
    appearance: none;
    text-align: center;
    box-sizing: border-box;
    margin: 0 var(--ti-checkbox-button-margin-horizontal);
    transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
    padding: 12px 20px;
    font-size: var(--ti-checkbox-button-font-size);
    border-radius: var(--ti-checkbox-button-border-radius);
    .user-select(none);

    &.is-round {
      padding: 12px 20px;
    }

    &:hover {
      background: var(--ti-checkbox-button-bg-color-hover);
      color: var(--ti-checkbox-button-hover-text-color);
      border: 1px solid var(--ti-checkbox-button-border-color-hover);
    }
  }

  &__original {
    opacity: 0;
    outline: 0;
    position: absolute;
    margin: 0;
    z-index: -1;
  }

  &--medium &__inner {
    padding: 14px 20px;
    font-size: var(--ti-common-font-size-1);
    border-radius: var(--ti-checkbox-button-border-radius);

    &.is-round {
      padding: 14px 20px;
    }
  }

  &--small &__inner {
    height: var(--ti-checkbox-button-size-small-height);
    line-height: calc(var(--ti-checkbox-button-size-small-height) - 2px);
    padding: 0 var(--ti-checkbox-button-size-small-padding-horizontal);
    font-size: var(--ti-common-font-size-base);
    border-radius: var(--ti-checkbox-button-border-radius);

    &.is-round {
      padding: 8px 15px;
    }
  }

  &--mini &__inner {
    padding: var(--ti-checkbox-button-padding-vertical) var(--ti-checkbox-button-mini-padding-horizontal);
    height: var(--ti-checkbox-button-height);
    margin: 0 var(--ti-checkbox-button-mini-margin-horizontal);
    font-size: var(--ti-checkbox-button-size-mini-font-size);
    border-radius: var(--ti-checkbox-button-size-mini-border-radius);

    &.is-round {
      padding: 5px 15px;
    }
  }

  &&--mini:first-child &__inner {
    border-radius: var(--ti-checkbox-button-mini-left-border-radius) var(--ti-checkbox-button-mini-right-border-radius)
      var(--ti-checkbox-button-mini-right-border-radius) var(--ti-checkbox-button-mini-left-border-radius);
  }

  &&--mini:last-child &__inner {
    border-radius: var(--ti-checkbox-button-mini-last-left-border-radius)
      var(--ti-checkbox-button-mini-right-border-radius) var(--ti-checkbox-button-mini-last-right-border-radius)
      var(--ti-checkbox-button-mini-last-left-border-radius);
  }

  &--mini {
    &.is-checked {
      &::after {
        border-bottom: 16px solid transparent;
        border-right: 16px solid var(--ti-checkbox-button-checked-border-color);
        border-top-right-radius: 4px;
        right: 3px;
      }

      &::before {
        height: 8px;
        width: 4px;
        right: 3px;
        top: 1px;
      }
    }
  }
}
