@import '../abstracts/variables';

.table {
    color: var(--palette-text-primary);
    background-color: var(--palette-surface);
    border-radius: var(--default-borderradius);
    transition: box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;

    &.table-square {
        border-radius: 0px;
    }

    &.table-outlined {
        border: 1px solid var(--palette-lines-default);
    }
}

.table-container {
    width: 100%;
    overflow-y: auto;
}

.table-root {
    width: 100%;
    border-spacing: 0;

    & .table-head {
        display: table-header-group;

        & .table-cell {
            color: var(--palette-text-primary);
            font-weight: 500;
            line-height: 1.5rem;
        }
    }

    & .table-body {
        display: table-row-group;

        & .table-cell {
            color: var(--palette-text-primary);
        }
    }

    & .table-body:last-child {
        & .table-row:last-child {
            & .table-cell {
                border-bottom: none;
            }
        }
    }
}

.table-sort-label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    flex-direction: inherit;
    justify-content: flex-start;

    &:hover {
        color: var(--palette-action-default);

        .table-sort-label-icon {
            opacity: 0.8;
        }
    }

    .table-sort-label-icon {
        font-size: 18px;
        transition: opacity 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,transform 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
        margin-left: 4px;
        user-select: none;
        margin-right: 4px;
        opacity: 0;

        &.direction-desc {
            opacity: 1;
            transform: rotate(180deg);
        }

        &.direction-asc {
            opacity: 1;
            transform: rotate(0deg);
        }
    }
}

.table-toolbar {
    padding-left: 16px;
    padding-right: 8px;
    padding-inline-start: 16px;
    padding-inline-end: 8px;
}



.table-cell {
    display: table-cell;
    padding: 16px;
    font-size: 0.875rem;
    text-align: start;
    font-weight: 400;
    line-height: 1.43;
    border-bottom: 1px solid var(--palette-table-lines);
    letter-spacing: 0.01071em;
    vertical-align: inherit;

    & .checkbox {
        margin: -12px;
    }
}

.table-cell-footer {
    color: var(--palette-text-secondary);
    font-size: 0.75rem;
    line-height: 1.3125rem;
}

.table-dense {
    & * .table-row {
        & .table-cell {
            padding: 6px 24px 6px 16px;
            padding-inline-start: 16px;
            padding-inline-end: 24px;

            .table-cell-checkbox {
                .button-root {
                    padding: 4px;
                }
            }

            .table-row-expander {
                padding: 4px;
            }
        }

        & .table-cell:last-child {
            padding-right: 16px;
            padding-inline-end: 16px;
        }
    }
}

.table-bordered {
    & .table-container .table-root .table-body {
        & .table-row {
            .table-cell:not(:last-child) {
                border-right: 1px solid var(--palette-table-lines);
            }
        }
    }

    & .table-container .table-root .table-head.table-head-bordered {
        & .table-row {
            .table-cell:not(:last-child) {
                border-right: 1px solid var(--palette-table-lines);
            }
        }
    }

    & .table-container .table-root .table-foot.table-foot-bordered {
        & .table-row {
            .table-cell:not(:last-child) {
                border-right: 1px solid var(--palette-table-lines);
            }
        }
    }
}

.table-sticky-header {
    .table-container {
        overflow-x: auto;
    }

    & * .table-root {

        .table-head {
            & * .table-cell:first-child {
                border-radius: var(--default-borderradius) 0px 0px 0px;
            }

            & * .table-cell:last-child {
                border-radius: 0px var(--default-borderradius) 0px 0px;
            }

            & * .table-cell {
                background-color: var(--palette-surface);
                position: sticky;
                z-index: 2;
                top: 0;
            }
        }
    }
}

.table-sticky-footer {
    .table-container {
        overflow-x: auto;
    }

    & * .table-root {

        .table-foot {

            & * .table-cell {
                background-color: var(--palette-surface);
                position: sticky;
                z-index: 2;
                bottom: 0;
            }
        }
    }
}


.table-row {
    color: inherit;
    display: table-row;
    outline: 0;
    vertical-align: middle;
}

.table-hover {
    & .table-container .table-root .table-body {
        & .table-row:hover {
            background-color: var(--palette-table-hover);
        }
    }
}

.table-striped {
    & .table-container .table-root .table-body {
        & .table-row:nth-of-type(odd) {
            background-color: var(--palette-table-striped);
        }
    }
}

.table-hover.table-striped {
    & .table-container .table-root .table-body {
        & .table-row:nth-of-type(odd):hover {
            background-color: var(--palette-table-hover);
        }
    }
}


.table-cell {
    & > .input-control {
        & > div.input.input-text {
            color: var(--theme-on-surface);
            font-size: 0.875rem;
            margin-top: -14px;
            margin-bottom: -8px;
        }
    }

    & > .select {
        & > .input-control {
            & > div.input.input-text {
                color: var(--theme-on-surface);
                font-size: 0.875rem;
                margin-top: -14px;
                margin-bottom: -8px;
            }
        }
    }
}

.table-cell-align {
    &-left {
        text-align: left;
    }

    &-center {
        text-align: center;
    }

    &-right {
        text-align: right;
        flex-direction: row-reverse;
    }

    &-justify {
        text-align: justify;
    }
}

.table-pagination-display {
    display: flex;
    flex-shrink: 0;

    & .tablepager-left {
        flex-direction: row !important;
    }

    & .tablepager-right {
        flex-direction: row-reverse !important;
    }
}

.table-pagination-information {
    white-space: nowrap;
    direction: initial;
}

.table-page-number-information {
    white-space: nowrap;
    direction: initial;
}

.table-pagination {
    color: var(--theme-on-surface);
    overflow: auto;
    font-size: 0.875rem;
    display: initial;
}

.table-pagination:last-child {
    padding: 0;
}

.table-pagination-toolbar {
    border-top: 1px solid var(--palette-table-lines);
    height: 52px;
    padding-right: 2px;
    padding-inline-end: 2px;
    padding-inline-start: unset;

    & .tablepager-left {
        flex-direction: row !important;
    }

    & .tablepager-right {
        flex-direction: row-reverse !important;
    }
}

.table-pagination-spacer {
    flex: 1 1 100%;
}

.table-pagination-caption {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    padding-left: 10px;
    padding-right: 10px;
}

.table-pagination-select {
    cursor: pointer;
    margin-left: 10px !important;
    margin-right: 10px !important;
    margin-top: 0px !important;
    min-width: 52px;

    & .select-input {
        margin-top: 0px !important;
    }

    & .input .input-root {
        max-width: 80px;
        cursor: pointer;
        margin-top: 2px;
        border: none;
        font-size: .875rem;
        font-weight: 400;
        line-height: 1.43;
        letter-spacing: .01071em;
        color: var(--theme-on-surface)
    }
}

.table-pagination-actions {
    flex-shrink: 0;
    align-items: center;
    margin-left: 10px;
    margin-inline-start: 10px;
    margin-inline-end: unset;
}

.table-smalldevices-sortselect {
    display: none;
}

.table-loading {
    position: relative;

    & .table-loading-progress {
        position: absolute;
        width: 100%;
    }
}

.table-empty-row {
    background-color: var(--palette-surface);
    vertical-align: middle;
    text-align: center;
}


@for $i from 1 through 5 {
    tr.table-row-group-indented-#{$i} td:first-child {
        padding-left: #{$i * 48}px !important;
    }
}

.table-row-expander {
    margin: -12px -2px -12px -12px;
}

@mixin table-display-smalldevices ($breakpoint) {
    .#{$breakpoint}table {
        .table-root .table-head,
        .table-root .table-foot {
            display: none;
        }

        .table-smalldevices-sortselect {
            display: block;
            padding: 4px 16px 8px;
        }

        .table-body {
            border-top: 1px solid var(--palette-table-lines);
        }

        .table-row {
            display: initial;

            .table-cell:last-child {
                border-bottom: 1px solid var(--palette-table-lines);
            }
        }

        .table-cell {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border: none;
            padding: 14px 16px;
            text-align: start !important;
        }

        &.table-dense {
            & .table-cell {
                padding: 6px 16px;
            }
        }

        .table-cell:before {
            content: attr(data-label);
            font-weight: 500;
            padding-right: 16px;
            padding-inline-end: 16px;
            padding-inline-start: unset;
        }

        &.table-small-alignright .table-cell:before {
            margin-right: auto;
        }

        .table-cell-hide {
            visibility: collapse;
            height: 0;
            padding: 0;
            margin: 0;
        }

        .table-pagination {

            .table-pagination-spacer {
                flex: none;
            }

            .table-pagination-actions {
                .button-root:first-child {
                    display: none;
                }

                .button-root:last-child {
                    display: none;
                }
            }

            .select ~ .table-pagination-caption {
                margin-left: auto;
                margin-inline-start: auto;
            }
        }
    }
}

// Table Pagination Flex Wrapper on old as phones
@media (max-width:360px) {
    .table {
        .table-pagination {
            .select {
                margin-left: auto;
                margin-right: -14px;
                margin-inline-start: auto;
                margin-inline-end: -14px;
            }

            .select ~ .table-pagination-caption {
                margin-left: unset !important;
                margin-inline-start: unset !important;
            }
        }
    }
}

@media (max-width:416px) {
    .table {
        .table-pagination {
            .table-pagination-toolbar {
                flex-wrap: wrap;
                padding-top: 16px;
                padding-right: 16px;
                padding-inline-end: 16px;
                padding-inline-start: unset;
                min-height: 100px;

                .table-pagination-actions {
                    margin-left: auto;
                    margin-right: -14px;
                    margin-inline-start: auto;
                    margin-inline-end: -14px;
                }
            }
        }
    }
}

@media (max-width:$breakpoint-sm) {
    @include table-display-smalldevices("xs-");
}

@media (max-width:$breakpoint-md) {
    @include table-display-smalldevices("sm-");
}

@media (max-width:$breakpoint-lg) {
    @include table-display-smalldevices("md-");
}

@media (max-width:$breakpoint-xl) {
    @include table-display-smalldevices("lg-");
}

@media (max-width:$breakpoint-xxl) {
  @include table-display-smalldevices("xl-");
}

@media (min-width:$breakpoint-xxl) {
  @include table-display-smalldevices("xxl-");
}
