@import '../../style/mixins';
@import '../../style/themes/default';

@listPrefixCls: fm-list;
.fmCheckboxFn(@checkboxPrefixCls:~'fm-checkbox') {
  @checkboxInnerPrefixCls: ~'@{checkboxPrefixCls}-inner';
  // 一般状态
  .@{checkboxPrefixCls} {
    position: relative;
    display: inline-block;
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
    outline: none;

    &-checked::after {
      position: absolute;
      width: 100%;
      height: 100%;
      border: 1*@hd solid @brand-primary;
      border-radius: 50%;
      visibility: hidden;
      content: '';
    }

    &-inner {
      position: relative;
      display: block;
      width: @checkbox-size;
      height: @checkbox-size;
      background-color: @checkbox-check-color;
      border: 1*@hd solid @border-color-base;
      border-radius: 50%;
      transition: all 0.3s;

      &::after {
        @check-width: (@checkbox-size / 16) * 4 * @hd;
        @check-height: (@checkbox-size / 16) * 8 * @hd;

        position: absolute;
        top: 49%;
        left: 24%;
        display: table;
        width: @check-width;
        height: @check-height;
        border: 2px solid @checkbox-check-color;
        border-top: 0;
        border-left: 0;
        transform: rotate(45deg) scale(0) translate(-50%, -50%);
        opacity: 0;
        content: ' ';
      }
    }

    &-input {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 100%;
      opacity: 0;
    }
  }

  // 选中状态
  .@{checkboxPrefixCls}-checked .@{checkboxInnerPrefixCls}::after {
    position: absolute;
    display: table;
    border: 1*@hd solid @checkbox-check-color;
    border-top: 0;
    border-left: 0;
    transform: rotate(45deg) scale(1) translate(-50%, -50%);
    opacity: 1;
    content: ' ';
  }

  .@{checkboxPrefixCls}-checked {
    // 选中时标签文字高亮
    & + span {
      color: @brand-primary;
    }
    .@{checkboxInnerPrefixCls} {
      background-color: @brand-primary;
      border-color: @brand-primary;
    }
  }

  // 禁用状态
  .@{checkboxPrefixCls}-disabled {
    opacity: @opacity-disabled;

    &.@{checkboxPrefixCls}-checked {
      .@{checkboxInnerPrefixCls} {
        border-color: @color-text-caption;
        background: none;

        &:after {
          border-color: @color-text-caption;
        }
      }
    }
    // 单个 checkbox 的右边提示
    & + span {
      color: @color-text-disabled;
    }
  }

  .@{checkboxPrefixCls}-wrapper {
    display: inline-block;
    line-height: unset;
  }

  .@{checkboxPrefixCls} + span {
    padding-right: 8px;
    padding-left: 8px;
    vertical-align: middle;
  }

  // 半选状态
  .@{checkboxPrefixCls}-indeterminate {
    .@{checkboxInnerPrefixCls} {
      background-color: @brand-primary;
      border-color: @border-color-base;
    }
    .@{checkboxInnerPrefixCls}::after {
      top: 50%;
      left: 50%;
      width: @indeterminate-width;
      height: @indeterminate-height;
      border: 1px solid @checkbox-check-color;
      transform: translate(-50%, -50%) scale(1);
      opacity: 1;
      content: ' ';
    }

    &.@{checkboxPrefixCls}-disabled .@{checkboxInnerPrefixCls} {
      background-color: #fff;
      &::after {
        border-color: @color-text-disabled;
      }
    }
  }

  .@{listPrefixCls} {
    & &-item {
      &.@{checkboxPrefixCls}-item {
        .@{listPrefixCls}-content {
          width: @icon-size-sm;
          height: @icon-size-sm;

          .@{checkboxPrefixCls} {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            height: @list-item-height;

            &-inner {
              position: absolute;
              display: inline-block;
              right: @h-spacing-lg;
              top: 12 * @hd;
            }
          }
        }

        &.@{checkboxPrefixCls}-item-disabled {
          .@{listPrefixCls}-label {
            color: @color-text-disabled;
          }
        }
      }
    }
  }
}

.fmCheckboxFn();
