@import './variable.scss';

$css-prefix: 'cn-ui-m-';

@mixin icon-size(
  $size,
  $marginLeft: false,
  $marginRight: false,
  $transform: false
) {
  $size-static: get-compiling-value($size);
  $icon-s-static: get-compiling-value($m-icon-s);
  @if ($transform) {
    transform: $transform;
  }
  @if ($marginLeft) {
    margin-left: $marginLeft;
  }
  @if ($marginRight) {
    margin-right: $marginRight;
  }

  &:before,
  & .#{$css-prefix}icon-remote {
    width: $size;
    font-size: $size;
    line-height: inherit;
  }

  // Chrome不支持小于12px的字体，故采用缩放的方式缩小字体
  @if (type-of($size-static) == 'number') {
    @if ($size-static < 12) {
      @media all and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: 0.001dpcm) {
        @if ($transform) {
          transform: scale(divide($size-static, $icon-s-static)) $transform;
        } @else {
          transform: scale(divide($size-static, $icon-s-static));
        }
        @if ($marginLeft) {
          margin-left: calc(#{$marginLeft} - (#{$m-icon-s} - #{$size}) / 2);
        } @else {
          margin-left: calc(0px - (#{$m-icon-s} - #{$size}) / 2);
        }
        @if ($marginRight) {
          margin-right: calc(#{$marginRight} - (#{$m-icon-s} - #{$size}) / 2);
        } @else {
          margin-right: calc(0px - (#{$m-icon-s} - #{$size}) / 2);
        }

        &:before {
          width: $icon-s;
          font-size: $icon-s;
        }
      }
    }
  }
}
