// 通用基准值
$--size-offset-base: if($--size-height-base <= 26, 6px, if($--size-height-base > 30, 10px, 8px));

// 定制类型：根据定制高度的范围，划分为small 、normal、large（不同于组件的size） 用于一些分三种情况拥有不同规则的组件
$--size-base-type: if($--size-height-base <= 26, small, if($--size-height-base > 30, large, normal));

// 通用行高
$--size-line-height-base: $--size-font-size-base + $--size-offset-base;


@mixin computed-line-height($font-size: $--size-font-size-base) {
  line-height: $font-size + $--size-offset-base;
}

// 通用计算行高与内距
@mixin computed-height($base-height: $--size-height-base, $border-width: 1px) {
  border-width: $border-width;
  line-height: $--size-line-height-base;
  padding: max(($base-height - $--size-line-height-base) / 2 - $border-width, 0) $--size-offset-base;
}

// 特殊场景：计算正方形元素的行高与内距
@mixin computed-square($base-height: $--size-height-base, $border-width: 1px) {
  border-width: $border-width;
  width: $base-height;
  line-height: $--size-line-height-base;
  padding: max(($base-height - $--size-line-height-base) / 2 - $border-width, 0);
}

// 按钮计算行高与内距，区分size为normal，large，small
@mixin computed-height-btn($base-height: $--size-height-base, $size: normal, $border-width: 1px) {
  @if $size == large {
    @include computed-height($base-height + 4px, $border-width);
  } @else if $size == small {
    font-size: 12px;
    line-height: 18px;
    padding: 1px $--size-offset-base;
  } @else {
    @include computed-height($base-height, $border-width);
  }
}

// 图标按钮特殊情况使用
@mixin computed-height-btn-icon($base-height: $--size-height-base, $size: normal, $border-width: 1px) {
  @if $size == large {
    @include computed-square($base-height + 4px, $border-width);
  } @else if $size == small {
    font-size: 12px;
    line-height: 18px;
    padding: 1px;
    width: 22px;
  } @else {
    @include computed-square($base-height, $border-width);
  }
}

// 上下内边距
@function computed-padding-vertical($base-height, $font-size: $--size-font-size-base, $border-width: 1px) {
  @return max(($base-height - $font-size - $--size-offset-base)/2 - $border-width, 0);
}

// date-picker，纯高度计算
@mixin computed-height-dataPicker($base-height, $size) {
  @if $size == large {
    height: $base-height + 4;
  } @else if $size == small {
    height: $base-height - 4;
  } @else {
    height: $base-height;
  }
}

// 计算表格h-table th表头高度
@function computed-table-th-height($component-size,$base-height:$--size-height-base){
  // 表头计算基准值，取决于定制高度所在范围
  $table-th-height-offset : if($--size-base-type == small, 4, if($--size-base-type == large, 8, 8)); 

  @if $--size-base-type == large { 
    @if $component-size == large {
      @return $base-height + 3 * $table-th-height-offset ;
    } @else if $component-size == small {
      @return $base-height +  $table-th-height-offset ;
    } @else {
      @return $base-height + 2 * $table-th-height-offset ;
    }
  } @else{
    @if $component-size == large {
      @return $base-height + 2 * $table-th-height-offset ;
    } @else if $component-size == small {
      @return $base-height;
    } @else {
      @return $base-height + $table-th-height-offset ;
    }
  }
}

// 计算表格h-table td表体单元格高度
@function computed-table-td-height($component-size,$base-height:$--size-height-base){
  // 单元格计算基准值，取决于定制高度所在范围
  $table-td-height-offset : if($--size-base-type == small, 4, if($--size-base-type == large, 8, 4)); 

  @if $--size-base-type == small { 
    @if $component-size == large {
      @return $base-height + $table-td-height-offset ;
    }@else {
      @return $base-height;
    }
  } @else{
    @if $component-size == large {
      @return $base-height + 2 * $table-td-height-offset ;
    } @else if $component-size == small {
      @return $base-height;
    } @else {
      @return $base-height + $table-td-height-offset ;
    }
  }
}

// 定制高度 <=26：使用定制字号, 26 < 定制高度 <=30：定制字号 14以下（含）为14，,14以上+2
// 使用组件有：Alert,Collapse,Card,
@mixin computed-font-size($height) {
  @if $--size-height-base <= $height {
    font-size: $--size-font-size-base;
  } @else {
    @if $--size-font-size-base <= 14 {
      font-size: 14px;
    } @else {
      font-size: $--size-font-size-base + 2;
    }
  }
}

@mixin custom-line-height($height: $--size-line-height-base) {
  line-height: min($height, $--size-line-height-base);
}

@mixin computed-typefield-line-height($component-size: small, $height: $--size-height-base) {
  $typefield-height-offset : if($component-size == small, $height - 4px , if($component-size == large, $height + 4px, 0)); 
  height: ($typefield-height-offset - 2px) / 2;
  line-height: ($typefield-height-offset - 2px) / 2;
}

// select、selectTree内部tag高度无规则计算
@mixin computed-select-tag-height($component-size: small, $height: $--size-height-base) {
  line-height: computed-tag-height($component-size, $height);
  height: computed-tag-height($component-size, $height);
}

@function computed-tag-height($component-size: small, $height: $--size-height-base) {
  $select-tag-height-offset : if($component-size == small, 8, if($component-size == large, 0, 4)); 

  @if $--size-base-type == small {
    @return $height - $select-tag-height-offset;
  } @else if $--size-base-type == large {
    @if $component-size == large {
      @return $height;
    }@else {
      @return $height - 10px;
    }
  } @else {
    @if $component-size == small {
      @return $height - $select-tag-height-offset;
    }@else if $component-size == large {
      @return $height;
    }@else {
      @return $height - 6px;
    }
  }
}

// select tag 默认情况下 margin 值
@mixin computed-select-tag-margin-vertical($component-size: normal, $height: $--size-height-base) {
  $tag-vertical: ($height - computed-tag-height($component-size))/2;
  margin-top: $tag-vertical;
  margin-bottom: $tag-vertical;
}

// select 上下padding值
@mixin computed-select-padding-vertical($base-height: $--size-height-base, $font-size: $--size-font-size-base, $border-width: 1px) {
  $padding-vertical: computed-padding-vertical($base-height, $font-size, $border-width);
  padding-top: $padding-vertical;
  padding-bottom: $padding-vertical;
}
