/**
 * =============================================================================
 * ************   Checkbox 复选框   ************
 * =============================================================================
 */

.mdui-checkbox {
  position: relative;
  display: inline-block;
  height: 36px;
  padding-left: 36px;
  line-height: 36px;
  cursor: pointer;
  user-select: none;

  // 隐藏系统 input 标签，用自定义的图标代替
  input[type="checkbox"] {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    opacity: 0;
  }
}

/* 透明的圆形，用于生成圆形阴影 */
.mdui-checkbox-icon {
  position: absolute;
  top: 9px;
  left: 0;
  display: inline-block;
  width: 18px;
  height: 18px;
  vertical-align: middle;
  background-color: transparent;
  border: none;
  border-radius: 18px;
  transition: box-shadow .14s @animation-curve-default;

  // 图标的边框和背景
  &::after {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    border: 2px solid @color-black-icon;
    border-radius: 2px;
    transition: all .3s @animation-curve-default;
    content: ' ';
  }

  // 选中状态图标内部的勾
  &::before {
    position: absolute;
    top: 2px;
    left: 0;
    z-index: 1;
    box-sizing: border-box;
    width: 8px;
    height: 13px;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotateZ(37deg) scale(0);
    transform-origin: 100% 100%;
    opacity: 0;
    transition: all .3s @animation-curve-default;
    content: ' ';
  }
}

/* 各种状态的图标 */
.mdui-checkbox input[type="checkbox"] {

  // 选中状态的图标
  &:checked + .mdui-checkbox-icon {
    &::after {
      background-color: @color-default-a200;
      border-color: @color-default-a200;
    }

    &::before {
      transform: rotateZ(37deg) scale(1);
      opacity: 1;
    }
  }

  // 不确定状态的图标
  &:indeterminate + .mdui-checkbox-icon {
    &::after {
      background-color: @color-default-a200;
      border-color: @color-default-a200;
    }

    &::before {
      top: 8px;
      left: 3px;
      width: 12px;
      height: 0;
      border-right: none;
      border-bottom: 2px solid #fff;
      border-radius: 1px;
      transform: rotateZ(0) scale(1);
      opacity: 1;
    }
  }

  // 禁用状态的图标
  &:disabled + .mdui-checkbox-icon {
    &::after {
      border-color: @color-black-icon-disabled;
    }
  }

  // 禁用且选中状态
  &:disabled:checked + .mdui-checkbox-icon,
  &:disabled:indeterminate + .mdui-checkbox-icon {
    &::after {
      background-color: @color-black-icon-disabled !important;
      border-color: transparent !important;
    }
  }
}

/* 阴影 */
.mdui-checkbox:active input[type="checkbox"],
.mdui-checkbox input[type="checkbox"]:focus {
  // 未选中、禁用时 按下的阴影
  & + .mdui-checkbox-icon {
    box-shadow: 0 0 0 15px rgba(0, 0, 0, 0.1);
  }

  // 已选中时按下的阴影
  &:not(:disabled):checked,
  &:not(:disabled):indeterminate {
    & + .mdui-checkbox-icon {
      box-shadow: 0 0 0 15px rgba(red(@color-default-a200), green(@color-default-a200), blue(@color-default-a200), 0.16);
    }
  }
}


/**
 * =============================================================================
 * ************   Checkbox 强调色   ************
 * =============================================================================
 */

& {
  .loop-accent-theme(@counter-color) when (@counter-color > 0) {
    .loop-accent-theme((@counter-color - 1));
    @colorName: extract(@globalAccentColors, @counter-color);

    @color: 'color-@{colorName}-a200';

    .mdui-theme-accent-@{colorName} when not (@colorName = null) {

      // 选中状态的图标
      .mdui-checkbox input[type="checkbox"]:checked,
      .mdui-checkbox input[type="checkbox"]:indeterminate {
        & + .mdui-checkbox-icon::after {
          background-color: @@color;
          border-color: @@color;
        }
      }

      // 已选中时按下的阴影
      .mdui-checkbox:active input[type="checkbox"],
      .mdui-checkbox input[type="checkbox"]:focus {
        &:not(:disabled):checked + .mdui-checkbox-icon,
        &:not(:disabled):indeterminate + .mdui-checkbox-icon {
          box-shadow: 0 0 0 15px rgba(red(@@color), green(@@color), blue(@@color), 0.16);
        }
      }
    }
  }
  .loop-accent-theme(length(@globalAccentColors));
}


/**
 * =============================================================================
 * ************   Checkbox dark   ************
 * =============================================================================
 */
.layout-theme({
  // 未选中的图标
  .mdui-checkbox-icon {
    &::after {
      border-color: rgba(255, 255, 255, 0.7);
    }

    &::before {
      border-right-color: @layout-dark-color-3 !important;
      border-bottom-color: @layout-dark-color-3 !important;
    }
  }

  // 禁用状态
  .mdui-checkbox input[type="checkbox"]:disabled + .mdui-checkbox-icon {
    &::after {
      border-color: @color-white-icon-disabled;
    }
  }

  // 禁用且选中状态
  .mdui-checkbox input[type="checkbox"] {
    &:disabled:checked + .mdui-checkbox-icon,
    &:disabled:indeterminate + .mdui-checkbox-icon {
      &::after {
        background-color: @color-white-icon-disabled !important;
        border-color: transparent !important;
      }
    }
  }

  // 未选中或禁用时 按下的阴影
  .mdui-checkbox:active input[type="checkbox"],
  .mdui-checkbox input[type="checkbox"]:focus {
    & + .mdui-checkbox-icon {
      box-shadow: 0 0 0 15px rgba(255, 255, 255, 0.1);
    }
  }
});
