/**
* 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-group-popover-prefix-cls: ~'@{css-prefix}group-item__more-popover';

.@{button-group-prefix-cls} {
  .inject-ButtonGroup-vars();

  display: inline-block;
  vertical-align: middle;
  .clearfix();

  &--empty {
    color: var(--tv-ButtonGroup-empty-text-color);
  }

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

    & li {
      line-height: var(--tv-ButtonGroup-line-height-number);
      float: left;
      position: relative;

      button {
        border: none;
        display: block;
        text-align: center;
        color: var(--tv-ButtonGroup-item-btn-text-color);
        background: var(--tv-ButtonGroup-item-bg-color);
        min-width: auto;
        height: var(--tv-ButtonGroup-item-btn-height);
        padding: 0 var(--tv-ButtonGroup-btn-padding-x);
        text-decoration: none;
        font-size: var(--tv-ButtonGroup-item-btn-font-size);

        cursor: pointer;
        transition:
          background ease-in 0.3s,
          border ease-in 0.3s;
        border-radius: var(--tv-ButtonGroup-border-radius);

        &:focus-visible {
          outline: 2px solid var(--tv-ButtonGroup-item-active-bg-color);
        }

        &.disabled,
        &[disabled] {
          background: var(--tv-ButtonGroup-item-btn-disabled-bg-color);
          border-color: var(--tv-ButtonGroup-item-btn-disabled-border-color);
          color: var(--tv-ButtonGroup-item-disabled-text-color);
          cursor: not-allowed;
          outline: none;
        }

        &.plain {
          border: 1px solid var(--tv-ButtonGroup-plain-border-color);
        }
      }

      &:hover {
        button:not(.disabled) {
          background: var(--tv-ButtonGroup-item-btn-hover-bg-color);
          color: var(--tv-ButtonGroup-item-btn-hover-text-color);

          &.plain {
            color: var(--tv-ButtonGroup-item-btn-plain-text-color);
            background-color: var(--tv-ButtonGroup-item-btn-plain-bg-color);
            border-color: var(--tv-ButtonGroup-item-btn-plain-border-color);
          }
        }
      }

      &.active {
        &:hover {
          button:not(.disabled) {
            &.plain {
              color: var(--tv-ButtonGroup-item-btn-plain-text-color);
              background-color: var(--tv-ButtonGroup-item-btn-plain-bg-color);
              border-color: var(--tv-ButtonGroup-item-btn-plain-border-color);
            }
          }
        }

        button {
          &.disabled {
            background: var(--tv-ButtonGroup-item-active-disabled-bg-color);
          }

          &:not(.disabled) {
            background: var(--tv-ButtonGroup-item-active-bg-color);
            color: var(--tv-ButtonGroup-item-active-text-color);

            &.plain {
              color: var(--tv-ButtonGroup-item-btn-plain-text-color);
              background-color: var(--tv-ButtonGroup-item-btn-plain-bg-color);
              border-color: var(--tv-ButtonGroup-item-btn-plain-border-color);
            }
          }
        }
      }

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

    // 角标相关样式
    &__sup {
      position: absolute;
      min-width: var(--tv-ButtonGroup-item-sup-height);
      height: var(--tv-ButtonGroup-item-sup-height);
      top: 0;
      color: var(--tv-ButtonGroup-item-sup-font-color);
      right: 0;
      font-size: var(--tv-ButtonGroup-item-btn-font-size);
      line-height: var(--tv-ButtonGroup-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;
    }

    .sup-tag {
      background-color: unset;
    }
  }

  // 大中小尺寸
  &&--medium {
    ul li button {
      height: var(--tv-ButtonGroup-medium-size);
    }
  }

  &&--small {
    ul li button {
      height: var(--tv-ButtonGroup-small-size);
    }
  }

  &&--mini {
    & li button {
      font-size: var(--tv-ButtonGroup-mini-font-size);
      padding: 0 var(--tv-ButtonGroup-mini-padding-x);
      height: var(--tv-ButtonGroup-mini-size);
      border-radius: var(--tv-ButtonGroup-mini-border-radius);
    }
  }
}

.@{button-group-popover-prefix-cls} {
  .inject-ButtonGroup-vars();

  &.tiny-popper {
    padding: 6px 0;
  }

  .more-list {
    .more-item {
      padding: 6px 16px;
      cursor: pointer;

      &:hover {
        background: var(--tv-ButtonGroup-more-item-bg-color-hover);
      }
    }
  }
}
