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

@button-group-prefix-cls: ~'@{css-prefix}button-group';
@group-item-prefix-cls: ~'@{css-prefix}group-item';
@button-prefix-cls: ~'@{css-prefix}button';
@dropdown-prefix-cls: ~'@{css-prefix}dropdown';

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

  display: inline-block;
  vertical-align: middle;
  margin-top: var(--ti-button-group-margin-top);
  .clearfix();

  &--empty {
    color: var(--ti-common-color-placeholder);
  }

  .@{group-item-prefix-cls} {
    display: inline-block;
    vertical-align: middle;

    & li {
      line-height: 28px;
      float: left;
      position: relative;
      margin-top: var(--ti-button-group-item-margin-top);

      button {
        border: var(--ti-button-group-border-weight) solid var(--ti-button-group-border-color);
        display: block;
        text-align: center;
        color: var(--ti-button-group-item-btn-text-color);
        background: var(--ti-button-group-item-bg-color);
        min-width: var(--ti-button-group-item-btn-width);
        height: var(--ti-button-group-item-btn-height);
        padding: 0 var(--ti-button-group-btn-padding-horizontal);
        text-decoration: none;
        font-size: var(--ti-button-group-item-btn-font-size);
        outline: none;
        cursor: pointer;
        transition: all 0.3s;
        border-radius: var(--ti-button-group-middle-border-radius);

        &.disabled,
        &[disabled] {
          background: var(--ti-button-group-item-btn-disabled-bg-color);
          border-color: var(--ti-button-group-item-btn-disabled-border-color);
          cursor: not-allowed;
          color: var(--ti-button-group-item-btn-disabled-text-color);
        }

        &.plain,
        &[plain] {
          background: none;
        }
      }

      &:hover {
        z-index: 1;

        button:not(.disabled) {
          background: var(--ti-button-group-item-btn-hover-bg-color);
          color: var(--ti-button-group-item-btn-hover-text-color);
          border-color: var(--ti-button-group-item-btn-hover-border-color);
          outline: none;

          &.plain,
          &[plain] {
            color: var(--ti-button-group-item-btn-plain-text-color);
            background-color: var(--ti-button-group-item-btn-plain-bg-color);
            border-color: var(--ti-button-group-item-btn-plain-border-color);
          }
        }
      }

      &.active {
        z-index: 1;

        &:hover {
          button:not(.disabled) {
            background: var(--ti-button-group-item-btn-active-hover-bg-color);
            border-color: var(--ti-button-group-active-hover-border-color);

            &.plain,
            &[plain] {
              background-color: var(--ti-button-group-item-btn-plain-bg-color);
            }
          }
        }

        button {
          &.disabled {
            background: var(--ti-button-group-item-active-disabled-bg-color);
          }
          &:not(.disabled) {
            background: var(--ti-button-group-item-active-bg-color);
            color: var(--ti-button-group-item-active-text-color);
            border-color: var(--ti-button-group-item-active-border-color);
            outline: none;

            &.plain,
            &[plain] {
              color: var(--ti-button-group-plain-active-text-color);
              background: none;
            }
          }
        }
      }

      &:first-child {
        button {
          border-radius: var(--ti-button-group-border-radius) var(--ti-button-group-right-border-radius)
            var(--ti-button-group-right-border-radius) var(--ti-button-group-border-radius);
        }
      }

      &:last-child {
        button {
          border-radius: var(--ti-button-group-left-border-radius) var(--ti-button-group-border-radius)
            var(--ti-button-group-border-radius) var(--ti-button-group-left-border-radius);
        }
      }

      &:not(:last-child) {
        margin-right: var(--ti-button-group-item-li-margin-right);
        margin-bottom: var(--ti-button-group-item-li-margin-bottom);
      }
    }

    &__sup {
      position: absolute;
      min-width: var(--ti-button-group-item-sup-height);
      height: var(--ti-button-group-item-sup-height);
      top: calc(-1 * var(--ti-button-group-item-sup-height) / 2);
      color: var(--ti-button-group-item-sup-font-color);
      right: 0;
      font-size: var(--ti-button-group-item-btn-font-size);
      line-height: var(--ti-button-group-item-sup-height);
      text-align: center;
      background-color: #fa9841;
      .tiny-svg {
        vertical-align: unset;
      }
    }
    &__sup-icon {
      background-color: #fa9841;
      border-radius: 2px;
      fill: #fff;
    }
    &__sup-text {
      background-color: #fa9841;
      padding: 0 4px;
      border-top-left-radius: 4px;
      border-bottom-right-radius: 4px;
    }
  }

  & > .@{button-prefix-cls} {
    float: left;
    position: relative;

    & + .@{button-prefix-cls} {
      margin-left: 0;
    }

    &:first-child {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
      border-right-color: var(--ti-button-group-info-border-color);

      &.@{button-prefix-cls}--default {
        border-right-color: var(--ti-button-group-border-color);

        &:hover,
        &:active,
        &:focus {
          border-right-color: var(--ti-button-group-hover-border-color);
          z-index: 1;
        }
      }
    }

    &:last-child {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
      border-left-color: var(--ti-button-group-info-border-color);

      &.@{button-prefix-cls}--default {
        border-left-color: var(--ti-button-group-border-color);

        &:hover,
        &:active,
        &:focus {
          border-left-color: var(--ti-button-group-hover-border-color);
          z-index: 1;
        }
      }
    }

    &:first-child:last-child {
      border-radius: var(--ti-button-group-border-radius);

      &.is-round {
        border-radius: calc(var(--ti-button-size-normal-height, 30px) / 2);
      }

      &.is-circle {
        border-radius: 50%;
      }
    }

    &:not(:first-child):not(:last-child) {
      border-radius: 0;
      border-left-color: var(--ti-button-group-info-border-color);
      border-right-color: var(--ti-button-group-info-border-color);

      &.@{button-prefix-cls}--default {
        border-left-color: var(--ti-button-group-border-color);
        border-right-color: var(--ti-button-group-border-color);

        &:hover,
        &:active,
        &:focus {
          border-left-color: var(--ti-button-group-hover-border-color);
          border-right-color: var(--ti-button-group-hover-border-color);
          z-index: 1;
        }
      }
    }

    &:not(:last-child) {
      margin-right: -1px;
    }

    & > .@{dropdown-prefix-cls} > .@{button-prefix-cls} {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
      border-left-color: var(--ti-button-group-info-border-color);
    }
  }

  &&--mini {
    & li:not(:last-child) {
      margin-right: var(--ti-button-group-mini-margin-right);
    }

    & li button {
      font-size: var(--ti-button-group-mini-font-size);
      padding: 0 var(--ti-button-group-mini-padding-horizontal);
      border-radius: var(--ti-button-group-mini-border-radius);
    }
  }

  &&--borderless {
    .@{group-item-prefix-cls} li button {
      border: 1px solid transparent;
      background: transparent;
    }

    .@{group-item-prefix-cls} li:hover button:not(.disabled) {
      background-color: var(--ti-button-group-no-border-hover-bg-color);
      border-color: var(--ti-button-group-no-border-hover-border-color);
    }

    .@{group-item-prefix-cls} li.active:hover button:not(.disabled) {
      background-color: var(--ti-button-group-no-border-active-hover-bg-color);
      border-color: var(--ti-button-group-no-border-border-color);
    }

    .@{group-item-prefix-cls} li button.disabled {
      background-color: var(--ti-button-group-no-border-disabled-bg-color);
    }
  }
}
