/* @docs */
$table-head-bg: initial !default;
$table-head-color: initial !default;
$table-head-border-width: var(--#{$prefix}border-width) !default;
$table-sticky-zindex: 1 !default;
$table-sticky-bg: initial !default;
$table-sticky-color: initial !default;
$table-sticky-header-height: 350px !default;
$table-detail-padding: 0.5em 0.75em !default;
$table-detail-bg: var(--#{$prefix}gray-light) !default;
$table-empty-padding: 1.5em 0 !default;
$table-sortable-hover-border-color: var(--#{$prefix}secondary) !default;
$table-current-sort-bg: var(--#{$prefix}gray-light) !default;
$table-card-spacer: $spacer;
/* @docs */

/* @bootstrap docs */
// $table-cell-padding-y:        .5rem;
// $table-cell-padding-x:        .5rem;
// $table-cell-padding-y-sm:     .25rem;
// $table-cell-padding-x-sm:     .25rem;

// $table-cell-vertical-align:   top;

// $table-color:                 var(--#{$prefix}body-color);
// $table-bg:                    var(--#{$prefix}body-bg);
// $table-accent-bg:             transparent;

// $table-th-font-weight:        null;

// $table-striped-color:         $table-color;
// $table-striped-bg-factor:     .05;
// $table-striped-bg:            rgba($black, $table-striped-bg-factor);

// $table-active-color:          $table-color;
// $table-active-bg-factor:      .1;
// $table-active-bg:             rgba($black, $table-active-bg-factor);

// $table-hover-color:           $table-color;
// $table-hover-bg-factor:       .075;
// $table-hover-bg:              rgba($black, $table-hover-bg-factor);

// $table-border-factor:         .1;
// $table-border-width:          var(--#{$prefix}border-width);
// $table-border-color:          var(--#{$prefix}border-color);

// $table-striped-order:         odd;
// $table-striped-columns-order: even;

// $table-group-separator-color: currentcolor;

// $table-caption-color:         var(--#{$prefix}secondary-color);

// $table-bg-scale:              -80%;
/* @bootstrap docs */

.table-wrapper {
    --#{$prefix}table-sticky-zindex: #{$table-sticky-zindex};
    --#{$prefix}table-sticky-bg: #{$table-sticky-bg};
    --#{$prefix}table-sticky-color: #{$table-sticky-color};
    --#{$prefix}table-sticky-header-height: #{$table-sticky-header-height};
    --#{$prefix}table-sortable-hover-border-color: #{$table-sortable-hover-border-color};
    --#{$prefix}table-current-sort-bg: #{$table-current-sort-bg};

    position: relative;

    .table-inner:focus {
        border-radius: var(--#{$prefix}border-radius);
        box-shadow: var(--#{$prefix}focus-ring-x, 0)
            var(--#{$prefix}focus-ring-y, 0) var(--#{$prefix}focus-ring-blur, 0)
            var(--#{$prefix}focus-ring-width) var(--#{$prefix}focus-ring-color);
    }

    .table {
        --#{$prefix}table-head-bg: #{$table-head-bg};
        --#{$prefix}table-head-color: #{$table-head-color};
        --#{$prefix}table-head-border-width: #{$table-head-border-width};

        // override sticky hover values
        &.table-hover > tbody > tr:hover > .sticky {
            --#{$prefix}table-color-state: var(
                --#{$prefix}table-sticky-color,
                var(--#{$prefix}table-hover-color)
            );
            --#{$prefix}table-bg-state: var(
                --#{$prefix}table-sticky-bg,
                var(--#{$prefix}table-hover-bg)
            );
        }

        // override sticky striped values
        &.table-striped > tbody > tr:nth-of-type(odd) > .sticky {
            --#{$prefix}table-color-type: var(
                --#{$prefix}table-sticky-color,
                var(--#{$prefix}table-striped-color)
            );
            --#{$prefix}table-bg-type: var(
                --#{$prefix}table-sticky-bg,
                var(--#{$prefix}table-striped-bg)
            );
        }

        th,
        td {
            vertical-align: middle;

            &.sticky {
                position: -webkit-sticky;
                position: sticky;
                left: 0;
                z-index: var(--#{$prefix}table-sticky-zindex);
                --#{$prefix}table-accent-color: var(
                    --#{$prefix}table-sticky-color
                );
                --#{$prefix}table-accent-bg: var(--#{$prefix}table-sticky-bg);
            }
        }

        thead th {
            --#{$prefix}table-color-state: var(--#{$prefix}table-head-color);
            --#{$prefix}table-bg-state: var(--#{$prefix}table-head-bg);

            position: relative;
            border-bottom-width: var(--#{$prefix}table-head-border-width);

            &.sortable {
                cursor: pointer;
                position: relative;

                &:hover {
                    border-color: var(
                        --#{$prefix}table-sortable-hover-border-color
                    );
                }
            }

            &.current-sort {
                --#{$prefix}table-bg-type: var(
                    --#{$prefix}table-current-sort-bg
                );
            }

            .sort-icon {
                position: absolute;
                right: 0.5em;
            }
        }

        tbody tr {
            &.table-detail {
                --#{$prefix}table-detail-bg: #{$table-detail-bg};
                --#{$prefix}table-detail-padding: #{$table-detail-padding};

                td {
                    background-color: var(--#{$prefix}table-detail-bg);
                    padding: var(--#{$prefix}table-detail-padding);
                    box-shadow: unset;
                }
            }

            &.table-empty {
                --#{$prefix}table-detail-padding: #{$table-empty-padding};

                td {
                    text-align: center;
                    padding: var(--#{$prefix}table-detail-padding);
                }
            }
        }
    }

    .scrollable {
        -webkit-overflow-scrolling: touch;
        overflow-x: auto;
        max-width: 100%;
    }

    .table-sticky {
        height: var(--#{$prefix}table-sticky-header-height);
        overflow-y: auto;

        .table thead th {
            position: -webkit-sticky;
            position: sticky;
            top: 0;
            z-index: calc(var(--#{$prefix}table-sticky-zindex) + 10);

            &.sticky {
                z-index: calc(var(--#{$prefix}table-sticky-zindex) + 11);
            }
        }
    }

    .icon {
        transition:
            transform $animation-speed-fast $easing,
            opacity 86ms $easing;
    }

    // mobile version
    &.mobile-cards {
        --#{$prefix}table-card-spacer: #{$table-card-spacer};

        thead {
            display: none;
        }

        tbody > tr {
            @extend .card;
            overflow: hidden;
        }

        tfoot th {
            border: 0;
            display: inherit;
        }

        tr {
            width: 100%;

            td {
                border: 0;
                display: inherit;

                &:last-child {
                    border-bottom: 0 !important;
                }
            }

            &:not(:last-child) {
                margin-bottom: var(--#{$prefix}table-card-spacer);
            }

            &:has(+ .table-detail) {
                border-bottom-left-radius: 0;
                border-bottom-right-radius: 0;
                margin-bottom: 0;
            }

            &.table-detail {
                border-top-left-radius: 0;
                border-top-right-radius: 0;
            }
        }

        tr:not(.table-detail):not(.table-empty):not(.table-footer) {
            td {
                display: flex;
                justify-content: space-between;
                align-items: end;
                border-bottom: var(--#{$prefix}border-width) solid
                    var(--#{$prefix}table-border-color);

                &:before {
                    content: attr(data-label);
                    font-weight: bold;
                    padding-right: 0.5em;
                    text-align: left;
                }
            }
        }
    }
}
