@use "@befe/brick-style/src/themes/base";

// 边缘阴影提示可滚动
//
// 问题：普通表格的横向滚动条是 `.brick-table-main-body-wrap`（overflow: auto hidden）的原生
// 滚动条，未自绘；macOS overlay 滚动条静止态不可见，用户不知道宽表格可以横向滚动。固定列一侧
// 有 scroll shadow 兜底（_fixed.scss），但无固定列的一侧没有任何提示。maxBodyHeight（容器内
// 纵向滚动）同理：overlay 下纵向滚动条静止隐藏，用户不知道下方还有行。
//
// 方案：可继续滚动的方向、边缘用一层与固定列同款的 inset 阴影暗示"这个方向还有内容"。复用
// `scrollXPosition` / `scrollYPosition` 的 leave-* 类，纯 CSS。
//
// 实现：阴影挂在**不随内容滚动**的 `.brick-table-main-table` 上（body-wrap 才是滚动容器），
// 用一个铺满、pointer-events: none 的 `::after` 承载三个方向的 inset 阴影，按方向用变量开关：
//   - 横向 left/right：复用 base.$box-shadow-inset-left/right，和固定列完全一致。与固定列
//     （isScrollableX）无关——普通宽表格（无固定列）同样靠原生 overflow 横向滚动、同样输出
//     leave-left/right 类。固定列一侧已有 shadow，故 :not(has-fixed-*) 时才补边缘阴影。
//   - 纵向 bottom：仅 maxBodyHeight（`brick-table-with-fixed-head`）有纵向滚动。main-table
//     底缘即 body-wrap 底缘，阴影位置正确。仅做底部（提示下方还有行），顶部不做。
//
// 滚动条避让：常驻滚动条模式下（`--brick-table-scrollbar-size` 由 table.tsx 注入，overlay 模式为 0），
// 覆盖层需从滚动条内侧起算，否则右侧阴影会落在纵向滚动条上、底部阴影会落在横向滚动条上：
//   - maxBodyHeight（有纵向滚动条）→ ::after 右缘内收一个滚动条宽度，阴影贴着表体而非盖住纵向滚动条
//   - 横向可滚动（有横向滚动条，即非 leave-neither）→ ::after 底缘内收一个滚动条宽度
.brick-table {
  &-main-table {
    position: relative;

    &::after {
      content: '';
      position: absolute;
      top: 0;
      // 右/下缘按是否存在对应滚动条内收，缺省 0（overlay 模式滚动条不占位，也为 0）
      right: var(--brick-table-edge-shadow-gutter-right, 0px);
      bottom: var(--brick-table-edge-shadow-gutter-bottom, 0px);
      left: 0;
      // 光标穿透，不挡滚动条与内容交互
      pointer-events: none;
      // 各方向默认无阴影（no-op），由下方按滚动位置逐一开启
      --brick-table-edge-shadow-left: 0 0 0 0 transparent;
      --brick-table-edge-shadow-right: 0 0 0 0 transparent;
      --brick-table-edge-shadow-bottom: 0 0 0 0 transparent;
      box-shadow:
        var(--brick-table-edge-shadow-left),
        var(--brick-table-edge-shadow-right),
        var(--brick-table-edge-shadow-bottom);
    }
  }

  // 纵向滚动条（maxBodyHeight）→ 覆盖层右缘内收，阴影贴表体、不盖纵向滚动条
  &.brick-table-with-fixed-head .brick-table-main-table::after {
    --brick-table-edge-shadow-gutter-right: var(--brick-table-scrollbar-size, 0px);
  }

  // 横向滚动条（可横向滚动，即非 leave-neither）→ 覆盖层底缘内收，阴影/底部阴影不盖横向滚动条
  &:not(.brick-table-scroll-x-position-leave-neither) .brick-table-main-table::after {
    --brick-table-edge-shadow-gutter-bottom: var(--brick-table-scrollbar-size, 0px);
  }

  // ============ 横向阴影（左 / 右边缘） ============
  &.brick-table-scroll-x-position-leave-left:not(.brick-table-has-fixed-left)
    .brick-table-main-table::after {
    --brick-table-edge-shadow-left: #{base.$box-shadow-inset-left};
  }

  &.brick-table-scroll-x-position-leave-right:not(.brick-table-has-fixed-right)
    .brick-table-main-table::after {
    --brick-table-edge-shadow-right: #{base.$box-shadow-inset-right};
  }

  // ============ 纵向阴影（仅 maxBodyHeight + overlay，底部） ============
  // 仅 overlay 滚动条环境（`brick-table-without-scrollbar`，SCROLL_BAR_WIDTH=0）才加：常驻纵向滚动条
  // 本身可见即已暗示"下方还有行"，无需底部阴影。
  &.brick-table-without-scrollbar.brick-table-with-fixed-head.brick-table-scroll-y-position-leave-bottom
    .brick-table-main-table::after {
    --brick-table-edge-shadow-bottom: inset 0 -12px 12px -12px rgb(0, 0, 0, .2);
  }
}
