.#{$table} {
  --table-gap: var(--xs);
  --table-radius: #{size(map.get($conf_table, 'radius'))};
  --table-padding: #{size(map.get($conf_table, 'padding'))};
  --table-td-padding: #{size(map.get($conf_table, 'td-padding'))};
  --table-cell-padding: #{size(map.get($conf_table, 'cell-padding'))};
  --table-font-color: #{map.get($conf_table, 'font-color')};
  --table-font-size: #{size(map.get($conf_table, 'font-size'))};
  --table-border-color: #{map.get($conf_table, 'border-color')};
  --table-th-height: #{size(map.get($conf_table, 'th-height'))};
  --table-th-bg-color: #{map.get($conf_table, 'th-bg-color')};
  --table-th-font-weight: #{map.get($conf_table, 'th-font-weight')};
  --table-th-font-color: #{map.get($conf_table, 'th-font-color')};
  --table-td-height: #{size(map.get($conf_table, 'td-height'))};
  --table-td-bg-color: #{map.get($conf_table, 'td-bg-color')};
  --table-td-bg-color-hover: #{map.get($conf_table, 'td-bg-color-hover')};
  --table-striped-color: #{map.get($conf_table, 'striped-color')};
  --table-tree-indent: #{size(map.get($conf_table, 'tree-indent'))};
  --table-list-td-bg-color: #{map.get($conf_table, 'list-td-bg-color')};
  --table-highlight-color: #{map.get($conf_table, 'highlight-color')};
  --table-fixed-th-bg-color: #{map.get($conf_table, 'fixed-th-bg-color')};
  --table-fixed-td-bg-color: #{map.get($conf_table, 'fixed-td-bg-color')};
  --table-fixed-shadow-left: #{map.get($conf_table, 'fixed-shadow-left')};
  --table-fixed-shadow-right: #{map.get($conf_table, 'fixed-shadow-right')};

  position: relative;
  overflow: hidden;
  height: fit-content;
  width: 100%;
  max-width: 100%;
  font-size: var(--table-font-size);
  color: var(--table-font-color);
  thead {
    color: var(--table-th-font-color);
    font-weight: var(--table-th-font-weight);
    tr {
      background-color: var(--table-th-bg-color);
      th {
        min-width: 0;
        box-sizing: border-box;
        text-overflow: ellipsis;
        vertical-align: middle;
        position: relative;
        text-align: left;
        z-index: 1;
        user-select: none;
        padding: var(--table-td-padding) 0;
        border-bottom: var(--border-width) solid var(--table-border-color);
        &.is-center {
          text-align: center;
        }
        &.is-right {
          text-align: right;
        }
        &.is-sortable {
          cursor: pointer;
        }
        &.required {
          > div {
            &::before {
              display: inline-block;
              content: '';
              width: size(8px);
              height: size(8px);
              border-radius: 50%;
              background: #ff4d51;
              margin-right: size(5px);
              vertical-align: middle;
            }
          }
        }
        .is-hidden {
          > * {
            visibility: hidden;
          }
        }
        .cell {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: normal;
          word-break: break-all;
          text-align: left;
          padding: 0 var(--table-cell-padding);
          &.#{$popover} {
            &.tooltip {
              white-space: nowrap;
              min-width: size(56px);
            }
          }
        }
      }
    }
    &.is-group {
      background-color: #ff4d51;
      tr {
        th {
        }
      }
    }
  }

  tbody {
    tr {
      td {
        background-color: var(--table-td-bg-color);
        padding: var(--table-td-padding) 0;
        border-bottom: var(--border-width) solid var(--table-border-color);
        &.table-expanded-cell {
          padding: 0;
          &:hover {
            background-color: unset !important;
          }
        }
        &.is-center {
          .cell {
            justify-content: center;
            &.show-tooltip {
              text-align: center;
            }
          }
        }
        &.is-right {
          .cell {
            justify-content: right;
            &.show-tooltip {
              text-align: right;
            }
          }
        }
        .cell {
          display: flex;
          align-items: center;
          padding: 0 var(--table-cell-padding);
          &.show-tooltip {
            white-space: nowrap;
            min-width: size(56px);
            word-break: break-all;
            overflow: hidden;
            text-overflow: ellipsis;
            display: block;
          }
        }
      }
      &.current-row {
        td {
          background-color: var(--table-td-bg-color-hover);
        }
      }
    }
    &:focus-visible {
      outline: none;
    }
  }

  th,
  td {
    &.fixed-column-left,
    &.fixed-column-right {
      position: sticky;
      z-index: 2;
      &.is-first-column,
      &.is-last-column {
        &::before {
          content: '';
          position: absolute;
          top: 0;
          width: 10px;
          bottom: -1px;
          overflow-x: hidden;
          overflow-y: hidden;
          box-shadow: none;
          touch-action: none;
          pointer-events: none;
        }
      }
      &.is-first-column {
        &::before {
          left: -10px;
        }
      }
      &.is-last-column {
        &::before {
          right: -10px;
          box-shadow: none;
        }
      }
    }
    &.fixed-right-patch {
      position: sticky !important;
      z-index: 2;
      background: #fff;
      right: 0;
    }
  }
  th {
    &.fixed-column-left,
    &.fixed-column-right {
      background-color: var(--table-fixed-th-bg-color);
    }
  }
  td {
    &.fixed-column-left,
    &.fixed-column-right {
      background-color: var(--table-fixed-td-bg-color);
    }
  }

  // table
  .table-body,
  .table-footer,
  .table-header {
    table-layout: fixed;
    border-collapse: separate;
    th,
    td {
      &:first-child:not(.table-expand-column) {
        .cell {
          padding-left: var(--table-padding);
        }
      }
      &:last-child {
        .cell {
          padding-right: var(--table-padding);
        }
      }
    }
  }

  // footer
  &.has-footer {
    > .table-inner-wrapper {
      > .table-body-wrapper {
        &,
        > .#{$scrollbar} > .scrollbar-wrap > .scrollbar-view {
          > .table-body {
            > tbody {
              > tr {
                &:last-child {
                  > td {
                    border-bottom: none;
                  }
                }

              }
            }
          }
        }
      }
    }
  }

  // empty
  .empty-block {
    position: -webkit-sticky;
    position: sticky;
    left: 0;
    min-height: size(60px);
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .empty-text {
    line-height: size(60px);
    width: 50%;
    color: var(--text-light);
  }

  // expand
  .table-expand-column {
    .cell {
      padding: 0;
      justify-content: center;
      user-select: none;
    }
  }
  .table-expand-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: size(16px);
    height: size(16px);
    color: var(--form-icon-color);
    font-size: size(16px);
    cursor: pointer;
    @include transition(all 0.2s var(--timing));
    > .#{$icon} {
      color: currentColor;
      width: 100%;
      height: 100%;
    }
    &.table-expand-icon-expanded {
      transform: rotate(90deg);
    }
  }
  [class*='table-row-level'] {
    .table-expand-icon {
      display: inline-flex;
      margin-right: size(8px);
    }
  }
  .table-placeholder {
    width: size(20px);
  }

  .caret-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: size(10px);
    width: size(24px);
    vertical-align: middle;
    cursor: pointer;
    overflow: initial;
    position: relative;
  }
  .sort-caret {
    width: 0;
    height: 0;
    border: solid size(4px) transparent;
    position: absolute;
    left: size(8px);
    &.ascending {
      border-bottom-color: var(--text-secondary);
      top: size(-5px);
      .sort-caret.ascending {
        border-bottom-color: var(--primary);
      }
    }
    &.descending {
      border-top-color: var(--text-secondary);
      bottom: -3px;
      .sort-caret {
        &.descending {
          border-top-color: var(--primary);
        }
      }
    }
  }
  .hidden-columns {
    visibility: hidden;
    position: absolute;
    z-index: -1;
  }
  .table-hidden {
    visibility: hidden;
  }

  // wrapper
  .table-body-wrapper,
  .table-footer-wrapper,
  .table-header-wrapper {
    width: 100%;
  }
  .table-header-wrapper {
    flex-shrink: 0;
  }
  .table-body-wrapper {
    overflow: hidden;
    position: relative;
    flex: 1;
    .table-column-selection {
      > .cell {
        display: flex;
        align-items: center;
      }
    }
  }
  .table-inner-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  .table-append-wrapper {
    overflow: hidden;
  }
  .table-footer-wrapper {
    border-top: var(--border-width) solid var(--table-border-color);
  }

  // fixed
  &.is-scrolling-left {
    th {
      &.fixed-column-left {
        background-color: var(--table-fixed-th-bg-color);
      }
    }
    .fixed-column-right {
      &.is-first-column {
        &::before {
          box-shadow: var(--table-fixed-shadow-right);
        }
      }
    }
  }
  &.is-scrolling-right {
    th {
      &.fixed-column-right {
        background-color: var(--table-fixed-th-bg-color);
      }
    }
    .fixed-column-left {
      &.is-last-column {
        &::before {
          box-shadow: var(--table-fixed-shadow-left);
        }
      }
      &.cell {
        border-right: none;
      }
    }
  }
  &.is-scrolling-middle {
    .fixed-column-left {
      &.is-last-column {
        &::before {
          box-shadow: var(--table-fixed-shadow-left);
        }
        &.cell {
          border-right: none;
        }
      }
    }
    .fixed-column-right {
      &.is-first-column {
        &::before {
          box-shadow: var(--table-fixed-shadow-right);
        }
      }
    }
  }
  &.is-scrolling-none {
    .fixed-column-left,
    .fixed-column-right {
      &.is-first-column,
      &.is-last-column {
        &::before {
          box-shadow: none;
        }
      }
    }
    th {
      &.fixed-column-left,
      &.fixed-column-right {
        background-color: var(--table-th-bg-color);
      }
    }
  }
  // border
  &.borderless {
    > .table-inner-wrapper {
      > .table-header-wrapper,
      > .table-body-wrapper,
      > .table-footer-wrapper {
        &,
        > .#{$scrollbar} > .scrollbar-wrap > .scrollbar-view {
          > table {
            > thead,
            > tbody {
              > tr {
                > th,
                > td {
                  border-bottom: none;
                }
              }
            }
          }
        }
      }
    }
  }
  &.border-y {
    border: var(--border-width) solid var(--table-border-color);
    border-right: none;
    > .table-inner-wrapper {
      > .table-header-wrapper,
      > .table-body-wrapper,
      > .table-footer-wrapper {
        &,
        > .#{$scrollbar} > .scrollbar-wrap > .scrollbar-view {
          > table {
            > thead,
            > tbody {
              > tr {
                > th,
                > td {
                  border-right: var(--border-width) solid var(--table-border-color);
                  border-bottom: none;
                }
                > th {
                  border-bottom: var(--border-width) solid var(--table-border-color);
                }
              }
            }
          }
        }
      }
    }
  }
  &.border-x {
    > .table-inner-wrapper {
      > .table-header-wrapper,
      > .table-body-wrapper,
      > .table-footer-wrapper {
        &,
        > .#{$scrollbar} > .scrollbar-wrap > .scrollbar-view {
          > table {
            > thead,
            > tbody {
              > tr {
                > th,
                > td {
                  border-right: none;
                  border-bottom: var(--border-width) solid var(--table-border-color);
                }
              }
            }
          }
        }
      }
    }
  }

  &.bordered {
    border-left: var(--border-width) solid var(--table-border-color);
    border-top: var(--border-width) solid var(--table-border-color);
    &::after {
      content: "";
      position: absolute;
      background-color: var(--table-border-color);
      z-index: 3;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
    }
    tr {
      th, td {
        border-right: var(--border-width) solid var(--table-border-color);
      }
    }
  }
  &:not(.bordered) {
    tr {
      th, td {
        border-right: none;
      }
    }
  }


  &.border-outline {
    border: var(--border-width) solid var(--table-border-color);
    > .table-inner-wrapper {
      > .table-header-wrapper,
      > .table-body-wrapper,
      > .table-footer-wrapper {
        &,
        > .#{$scrollbar} > .scrollbar-wrap > .scrollbar-view {
          > table {
            > thead,
            > tbody {
              > tr {
                > th,
                > td {
                  border-bottom: none;
                }
                > th {
                  border-bottom: var(--border-width) solid var(--table-border-color);
                }
              }
            }
          }
        }
      }
    }
  }
  &.borderless-last {
    > .table-inner-wrapper {
      > .table-header-wrapper,
      > .table-body-wrapper,
      > .table-footer-wrapper {
        &,
        > .#{$scrollbar} > .scrollbar-wrap > .scrollbar-view {
          > table {
            > thead,
            > tbody {
              > tr {
                > th,
                > td {
                  border-right: none;
                  border-bottom: var(--border-width) solid var(--table-border-color);
                }
                &:not(:only-child) {
                  &:last-child {
                    > td {
                      border-bottom: none;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }


  // striped
  &.striped-even {
    .table-body {
      > tbody {
        > tr {
          &:nth-child(even) {
            td {
              background-color: var(--table-striped-color);
            }
          }
        }
      }
    }
  }
  &.striped-odd {
    .table-body {
      > tbody {
        > tr {
          &:nth-child(odd) {
            td {
              background-color: var(--table-striped-color);
            }
          }
        }
      }
    }
  }

  &.list {
    border-collapse: separate;
    border: none;
    .table-body {
      border-spacing: 0 var(--table-gap);
    }
    .table-header,
    .table-body,
    .table-footer {
      > thead,
      > tfoot,
      > tbody {
        tr {
          border: 0;
          th,
          td {
            border: 0;
            background-color: transparent;
            &:first-child {
              border-left: 0;
              border-radius: var(--table-radius) 0 0 var(--table-radius);
            }

            &:last-child {
              border-left: 0;
              border-radius: 0 var(--table-radius) var(--table-radius) 0;
            }
          }
        }
      }

      > tbody {
        tr {
          background-color: var(--table-list-td-bg-color);
        }
      }
      > thead,
      > tfoot {
        tr {
          background-color: var(--table-th-bg-color);
        }
      }
    }
  }

  .table-column-resize-proxy {
    position: absolute;
    left: 200px;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: 1px solid var(--primary);
    z-index: 10;
  }

  .table-column-filter-trigger {
    display: inline-block;
    cursor: pointer;
    i {
      color: var(--info);
      font-size: 14px;
      vertical-align: middle;
    }
  }


  .table-enable-row-transition .table-body td.cell {
    transition: background-color 0.25s ease;
  }

  .table-enable-row-hover .table-body tr:hover > td.cell {
    background-color: var(--table-td-bg-color-hover);
  }

  .table-filter {
    border: solid 1px var(--table-border-color);
    border-radius: 2px;
    background-color: #fff;
    box-shadow: var(--box-shadow-sm);
    box-sizing: border-box;
  }

  .table-filter-list {
    padding: size(5px) 0;
    margin: 0;
    list-style: none;
    min-width: size(100px);
  }

  .table-filte-list-item {
    line-height: 36px;
    padding: 0 10px;
    cursor: pointer;
    &:hover {
      background-color: var(--table-td-bg-color-hover);
      color: var(--primary);
    }
    &.is-active {
      background-color: var(--primary);
      color: #fff;
    }
  }

  .table-filter-content {
    min-width: 100px;
  }

  .table-filter-bottom {
    border-top: 1px solid var(--table-border-color);
    padding: 8px;
    button {
      background: 0 0;
      border: none;
      color: var(--text-regular);
      cursor: pointer;
      font-size: var(--font-sm);
      padding: 0 3px;
      &:hover {
        color: var(--primary);
      }
      :focus {
        outline: 0;
      }
      &.is-disabled {
        color: var(--form-disabled-font-color);
        cursor: not-allowed;
      }
    }
  }

  .table-filter-wrap {
    max-height: 280px;
  }

  .table-filter-checkbox-group {
    padding: 10px;
    .#{$checkbox} {
      display: flex;
      align-items: center;
      margin-right: 5px;
      margin-bottom: 12px;
      margin-left: 5px;
      height: unset;
      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}

