@use "sass:math";
@use "sass:map";
@use "@befe/brick-style/src/themes/base";
@use "@befe/brick-style/src/themes/table";
@use "@befe/brick-style/src/themes/button";
@use "@befe/brick-style/src/themes/switch";

@each $size in table.$table-size-list {
  @each $line-spacing in table.$table-line-spacing-list {
    $font-size-by-size: map.get(table.$table-font-size, $size);
    $cell-padding-vertical: map.get(table.$table-cell-padding-vertical, #{$size}-#{$line-spacing});
    $cell-line-height: base.line-height($font-size-by-size, $line-spacing);

    .brick-table-size-#{$size}.brick-table-line-spacing-#{$line-spacing} {
      font-size: $font-size-by-size;
      table {
        th, td {
          padding-top: $cell-padding-vertical;
          padding-bottom: $cell-padding-vertical;
          > * {
            line-height: $cell-line-height;
            min-height: $cell-line-height;
          }
          // 仅对"裸露"的组件进行修饰，因为
          // - 一些控件，比如 Input, Select 中有清除小叉
          // - 不假设更复杂自定义内容更复杂的情况，尽量简化
          .brick-table-cell-content > {
            .brick-checkbox,
            .brick-radio,
            .brick-button-type-plain {
              line-height: $cell-line-height;
            }
          }
        }
      }

      @if $line-spacing == 'compact' {
        td.brick-table-col-type-switch {
          $adjusting-switch-height: math.div(map.get(switch.$switch-height, $size) - $cell-line-height, 2 );
          padding-top: $cell-padding-vertical - $adjusting-switch-height;
          padding-bottom: $cell-padding-vertical - $adjusting-switch-height;
        }
      }

      // 特殊处理，因为高度刚刚够，.brick-checkbox-wrap vertical-align: sub 会稍稍撑高单元格
      @if $line-spacing == 'compact' and $size == 'sm' {
        td.brick-table-col-type-checkbox {
          .brick-checkbox-wrap {
            vertical-align: top;
          }
        }
      }

      // text type button 有外边框
      $cell-padding-vertical-operations: $cell-padding-vertical - base.$border-width-base;
      td.brick-table-col-type-operations {
        padding-top: $cell-padding-vertical-operations;
        padding-bottom: $cell-padding-vertical-operations;

        .brick-button-type-plain:not(.brick-button-icon-only) {
          &:first-child {
            margin-left: -(button.$btn-plain-padding-horizontal);
          }

          &:last-child {
            margin-right: -(button.$btn-plain-padding-horizontal);
          }
        }

        // icon 操作按钮刻意放大一号（见 table.tsx getIconButtonSize），但相邻间距应按「表格尺寸」
        // 收口为 md:16 / sm:12，而非跟随放大后按钮尺寸的 $btn-padding-horizontal（lg:20 / md:16）。
        .brick-button-type-plain.brick-button-icon-only + .brick-button-type-plain.brick-button-icon-only {
          margin-left: map.get(button.$btn-padding-horizontal, $size);
        }

        // 姑且通用一点
        > * {
          min-height: $cell-line-height + base.$border-width-base * 2;
        }
      }

      @each $illus-size in table.$table-no-data-illus-size-list {
        $illus-icon-size: map.get(table.$table-no-data-illus-size, $illus-size);
        $table-empty-body-height: table.table-empty-body-height($illus-icon-size, $cell-line-height);
        &.brick-table-illus-size-#{$illus-size} {
          .brick-table-no-data {
            height: $table-empty-body-height;
            > .brick-icon {
              font-size: $illus-icon-size;
            }
          }
          .brick-table-tbody-empty {
            tr > td {
              height: $table-empty-body-height;
            }
          }
        }
      }
    }
  }
}

// 多行截断盒子（常量部分）：-webkit-line-clamp 的数字由组件 inline 注入
.brick-table .brick-table-cell-content-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  white-space: normal;
  overflow: hidden;
}
