@use "../mixins/function.scss" as *;
@use "../mixins/mixins.scss" as *;

@include b(table) {
  overflow: auto;
  box-sizing: border-box;
  background-color: getCssVar("color", "bg-2");
  display: flex;
  flex-direction: column;

  &::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  &::-webkit-scrollbar-track:horizontal {
    background-color: transparent;
    border-top: 1px solid getCssVar("color", "fill-3");
  }
  &::-webkit-scrollbar-track:vertical {
    background-color: transparent;
    border-left: 1px solid getCssVar("color", "fill-3");
  }
  &::-webkit-scrollbar-thumb:horizontal {
    background-color: getCssVar("color", "fill-3");
    -webkit-border-radius: 0;
  }
  &::-webkit-scrollbar-thumb:vertical {
    background-color: getCssVar("color", "fill-3");
    -webkit-border-radius: 0;
  }
  &::-webkit-scrollbar-thumb:hover {
    background-color: getCssVar("color", "fill-4");
    -webkit-border-radius: 0;
  }
  &::-webkit-scrollbar-track-piece {
    -webkit-border-radius: 0;
  }
  &::-webkit-scrollbar-corner {
    background-color: transparent;
  }

  @include e(inner) {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
    display: table;
    margin: 0;
  }

  @include e(header) {
    background-color: getCssVar("color", "fill-1");
    position: sticky;
    top: 0;
    z-index: 5;
  }

  @include e(header-row) {
    border-top: none;
    transition: none;
  }

  @include e(header-cell) {
    line-height: 1.5175;
    text-align: left;

    @include this-bm(table, fixed-left) {
      background-color: getCssVar("color", "fill-1");
      @include this-bm(table, has-shadow) {
        &::after {
          content: "";
          position: absolute;
          top: 0;
          right: 0;
          bottom: -1px;
          width: 30px;
          transform: translateX(100%);
          pointer-events: none;
          box-shadow: inset 12px 0 8px -12px rgba(0, 0, 0, 0.18);
          z-index: 12;
        }
      }
    }

    @include this-bm(table, fixed-right) {
      background-color: getCssVar("color", "fill-1");

      @include this-bm(table, has-shadow) {
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 0;
          bottom: -1px;
          width: 30px;
          transform: translateX(-100%);
          pointer-events: none;
          box-shadow: inset -12px 0 8px -12px rgba(0, 0, 0, 0.18);
          z-index: 12;
        }
      }
    }
  }

  @include e(body-row) {
    &:last-child {
      @include be(table, body-cell) {
        border-bottom: none;
      }
    }

    &:hover {
      background-color: getCssVar("color", "fill-1");

      @include bm(table, fixed-left) {
        background-color: getCssVar("color", "fill-1");
      }

      @include bm(table, fixed-right) {
        background-color: getCssVar("color", "fill-1");
      }
    }
    @include when(row-selected) {
      cursor: pointer;
    }
    @include when(selected) {
      background-color: getCssVar("color", "fill-2");
    }
  }
  @include e(body-cell) {
    line-height: 1.5175;
    text-align: left;

    @include this-bm(table, fixed-left) {
      background-color: getCssVar("color", "bg-2");
      @include this-bm(table, has-shadow) {
        &::after {
          content: "";
          position: absolute;
          top: 0;
          right: 0;
          bottom: -1px;
          width: 30px;
          transform: translateX(100%);
          pointer-events: none;
          box-shadow: inset 12px 0 8px -12px rgba(0, 0, 0, 0.18);
          z-index: 12;
        }
      }
    }

    @include this-bm(table, fixed-right) {
      background-color: getCssVar("color", "bg-2");

      @include this-bm(table, has-shadow) {
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 0;
          bottom: -1px;
          width: 30px;
          transform: translateX(-100%);
          pointer-events: none;
          box-shadow: inset -12px 0 8px -12px rgba(0, 0, 0, 0.18);
          z-index: 12;
        }
      }
    }
  }

  @include e(empty) {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: sticky;
    left: 0;
  }

  @include e(empty-border) {
    flex: 1;
    width: 100%;
    border-top: 1px solid getCssVar("color", "fill-3");
  }

  @include e(empty-cell) {
    flex: 1;
    padding: 20px;
  }

  @include m(align-center) {
    text-align: center;
  }

  @include m(stripe) {
    @include be(table, body-row) {
      &:nth-child(2n) {
        background-color: getCssVar("color", "fill-1");
      }
    }
  }

  @include m(border-full) {
    border: 1px solid getCssVar("color", "fill-3");

    @include be(table, header-row) {
      @include be(table, header-cell) {
        border-right: 1px solid getCssVar("color", "fill-3");
        border-bottom: 1px solid getCssVar("color", "fill-3");
      }
      @include be(table, header-cell) {
        &:last-child:not(:only-child) {
          border-right: none;
        }
      }
    }
    @include be(table, body-cell) {
      border-right: 1px solid getCssVar("color", "fill-3");
      border-bottom: 1px solid getCssVar("color", "fill-3");
      &:last-child {
        border-right: none;
      }
    }
  }

  @include m(border-outer) {
    border: 1px solid getCssVar("color", "fill-3");
  }

  @include m(border-right) {
    @include be(table, header-cell) {
      border-right: 1px solid getCssVar("color", "fill-3");
      &:last-child {
        border-right: none;
      }
    }
    @include be(table, body-cell) {
      border-right: 1px solid getCssVar("color", "fill-3");
      &:last-child {
        border-right: none;
      }
    }
  }

  @include m(border-bottom) {
    @include be(table, header-cell) {
      border-bottom: 1px solid getCssVar("color", "fill-3");
    }
    @include be(table, body-cell) {
      border-bottom: 1px solid getCssVar("color", "fill-3");
    }
  }

  @include m(small) {
    @include be(table, header-cell) {
      height: 32px;
      padding: 4px 12px;
    }
    @include be(table, body-cell) {
      height: 32px;
      padding: 4px 12px;
    }
  }

  @include m(medium) {
    @include be(table, header-cell) {
      height: 40px;
      padding: 8px 12px;
    }
    @include be(table, body-cell) {
      height: 40px;
      padding: 8px 12px;
    }
  }

  @include m(large) {
    @include be(table, header-cell) {
      height: 48px;
      padding: 12px 12px;
    }
    @include be(table, body-cell) {
      height: 48px;
      padding: 12px 12px;
    }
  }

  @include e(tree-node-toggle) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin-right: 4px;
    vertical-align: middle;
    border-radius: getCssVar("radius", "circle");
    transition: transform 0.2s getCssVar("bezier", "1");

    &:hover {
      background-color: getCssVar("color", "fill-2");
    }

    @include when(expanded) {
      @include be(table, tree-node-arrow) {
        transform: rotate(90deg);
      }
    }
  }

  @include e(tree-node-arrow) {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
  }

  @include m(ellipsis) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  @include bm(table, ellipsis) {
    overflow: hidden;
  }
}
