@use "sass-rem/rem" as sass-rem;
@use "typography" as *;
@use 'theme_generator' as tg;
// @import '../../native-theme/theme_palette';
// @import '../../custom/custom_palette';
// @import 'styles/theme_palette';
// @use 'theme_variables_common' as variables;

.table {
    th {
        text-transform : uppercase;
        font-size      : 13px;
    }
}

.table {
    & thead {
        & th {
            padding-left : 0;
        }
    }

    & tbody {
        & td {
            padding-left : 0;
        }
    }
}

// Work towards making table styles more consistent
// theme vars need to be generated here to be available
// to all components using nx-table -- [T]
@include tg.generate-theme-vars((
    '--reports-sidebar-background': 5,
    '--reports-sidebar-highlight-background': 7,
    '--reports-sidebar-highlight-text': -1,
    '--reports-table-header-text-color': ('dark': -4, 'light': -9),
    '--reports-hint-icon-color': ('dark': -10, 'light': 10),
    '--reports-export-button': -16,
    '--users-table-bg': 4,
    '--users-table-border': 7,
    '--users-table-header-color': -4
));

$permission-cell-size: 210px;
$large-desktop-breakpoint: 1477px;

// Table column width variables
$service-changes-table-column-width: minmax(370px, 3fr) minmax(168px, 1fr) minmax(150px, 2fr) minmax(216px, 2fr);

.nx-table {
    table-layout: auto;
    white-space: nowrap;
    margin-bottom: 0;

    thead {
        background-color: var(--card-header-bg);
        border-bottom: 1px solid var(--border-color);

        th {
            @include medium13nocolor;
            color: var(--card-header-text) !important;
            //display        : inline-block;
            white-space: normal;
            padding: .5rem 0;
            font-weight: 500 !important;
            text-transform: none;
            overflow-wrap: break-word;
            cursor: pointer;
            border: none;

            &:first-of-type {
                padding-left: .5rem;
            }

            &.table-title {
                @include regular24dark9;

                .text-placeholder {
                    color: var(--text-placeholder-color);
                    font-size: 1.25rem;
                }
            }

            .caption {
                position: relative;
                height: 2rem;

                .sort-dir {
                    top: 0;
                    right: auto;
                    position: relative;
                    bottom: 0;

                    &:after {
                        content: " ";
                    }

                    &.asc {
                        &:after {
                            content: "+";
                        }
                    }
                }
            }
        }
    }

    tbody {
        background-color: var(--body-bg);

        tr {
            //display: block;
            height: sass-rem.rem(24px);

            &:hover {
                background-color: unset !important;

                td {
                    color: var(--card-header-text) !important;;
                    background: var(--table-row-hover-bg);
                }
            }

            &.spacer {
                height: .5rem;
                background-color: var(--body-bg);
            }

            td {
                @include regular13nocolor;
                color: var(--label-color) !important;
                display: table-cell;
                vertical-align: middle;
                padding: sass-rem.rem(4px) 1rem sass-rem.rem(4px) 0;
                line-height: 1rem;
                border: none;

                &:first-of-type {
                    padding-left: .5rem;
                }

                svg {
                    float: right;

                    .st0 {
                        fill: var(--input-color) !important;
                    }
                }
            }
        }
    }

    &-header {
        @include regular13dark9;
        color: var(--card-header-text) !important;
        padding: 0.5rem 1rem;
        background-color: var(--card-header-bg);
        border: 1px solid var(--border-color);
        border-bottom: none;
        line-height: 16px;
        text-transform: none;
        overflow-wrap: break-word;

        .results {
            @include medium13dark9;
            font-weight: 500 !important;
            line-height: 16px;
        }
    }
}

.nx-new-table {
    &-container {
        height: calc(100% - 1rem);
        margin: 1rem 0 1rem;
    }

    .nx-new-table-wrapper {
        min-width: 787px;
    }

    .header {
        grid-template-columns: 50px repeat(4, 1fr) 32px;
        grid-template-rows: var(--table-header-height);
        border-bottom: 1px solid var(--border-color);
        background-color: var(--card-header-bg);

        & > div {
            display: flex;
            align-items: center;
            gap: 0.25rem;
            flex-wrap: wrap;
            align-content: center;
            justify-items: flex-start;
            line-height: 22px;
            cursor: default;
            border-right: 1px solid var(--border-color);
            padding-left: 8px;

            &.groups-container {
                min-width: $permission-cell-size;
            }

            &:last-child {
                border-right: none;
            }

            &.table-header {
                @include medium14nocolor;
                color: var(--reports-table-header-text-color) !important;
                padding: 0 8px;

                .hint-icon {
                    margin-left: 2px;
                    position: relative;
                    bottom: 1px;
                    color: var(--reports-hint-icon-color)
                }
            }

            .head-title {
                pointer-events: none;
                max-width: calc(100% - 30px); // minus sort svg and padding
                @include medium13nocolor;
                color: var(--card-header-text) !important;
                white-space: normal;
                padding: .5rem 0;
                text-transform: none;
            }

            .sort-svg {
                svg path {
                    fill: var(--card-support-svg-elem-bg);
                }

                //position: absolute;
                //top: 8px;
                //right: 0;
            }
        }
    }

    .big-row {
        display: grid;
        // define it per table (see .cameras) --TT
        //grid-template-columns: 50px repeat(4, 1fr) 32px;
        grid-template-rows: minmax(2.5rem, auto);
        background-color: var(--card-body-bg);
        border-bottom: 1px solid var(--border-color);

        &:hover {
            background: var(--brand-core-t10);
        }

        &.selected {
            background-color: var(--table-row-selected-bg);
            color: var(--table-row-selected-color);
        }

        //&:last-child {
        //    border-bottom: none;
        //}

        .align-right {
            justify-content: flex-end;
        }

        & div {
            svg-icon.icon-expand {
                transform: rotate(-90deg);
            }
        }

        & > div {
            display: flex;
            align-items: center;
            border-right: 1px solid var(--border-color);
            padding: 8px;
            @include ellipsis;

            *[id^='sortKey-'] {
                height: 0;
                width: 0;
                padding: 0;
            }

            &:last-child {
                border-right: 1px solid var(--border-color);
                padding-left: 8px;
            }
        }

        &.expanded {
            padding: 10px 0;

            div {
                align-content: flex-start;

                svg-icon.icon-expand {
                    transform: none;
                }
            }

            .div-container-wrapper {
                flex-direction: column;
            }
        }

        .div-container-wrapper {
            svg-icon svg .st0 {
                fill: var(--svg-std-icon-fill);
                stroke: none;
            }
        }

        .roles {
            width: 100%;

            &-container {
                min-width: $permission-cell-size;
            }
        }

        .dropdown {
            padding: 0;
        }

        // dropdown v2
        .select-wrapper {
            height: 100%;
            align-items: center;
            background-color: transparent;
            box-shadow: none;
            @include regular14nocolor;

            &:hover {
                background-color: transparent !important;
                box-shadow: none !important;
            }

            &:active {
                background-color: transparent !important;
                box-shadow: none !important;
            }
        }
    }

    .summary-row {
        & > div {
            border-right: none;
        }
    }
}

.cameras {
    .nx-new-table {
        .header {
            grid-template-columns: repeat(2, 150px) repeat(2, 100px) repeat(7, 94px);

            &.analytics {
                grid-template-columns: repeat(2, 150px) repeat(2, 100px) repeat(7, 80px) 98px;


                &.service {
                    grid-template-columns: repeat(2, 150px) repeat(2, 100px) repeat(7, 80px) 90px 80px 88px;
                }
            }
        }

        .big-row {
            grid-template-columns: repeat(2, 150px) repeat(2, 100px) repeat(7, 94px);
            grid-template-rows: 40px;

            &.analytics {
                grid-template-columns: repeat(2, 150px) repeat(2, 100px) repeat(7, 80px) 90px;

                &.service {
                    grid-template-columns: repeat(2, 150px) repeat(2, 100px) repeat(7, 80px) 90px 0 80px 80px;
                }

                &.auto-height {
                    grid-template-columns: repeat(2, 150px) repeat(2, 100px) repeat(7, 80px) 98px;
                }
            }

            & .div-container-wrapper {
                padding: 0 0 0 8px;

                & div {
                    display: flex;
                    flex-wrap: wrap;
                    align-content: center;
                    justify-items: flex-start;
                }
            }
        }
    }
}

.user-table {
    .nx-new-table {
        .header {
            background-color: var(--users-table-bg);
            grid-template-rows: 46px;
        }
        .big-row {
            background: none;
            border-bottom: 1px solid var(--users-table-border) !important;
        }
        .big-row > div {
            border-right: 1px solid var(--users-table-border) !important;
        }
        .header > div {
            border-right: 1px solid var(--users-table-border) !important;
            .head-title {
                color: var(--users-table-header-color) !important;
                font-size: 15px;
                font-weight: 700;
            }
        }
        .nx-new-table-horizontal-wrapper {
            .nx-new-table-wrapper {
                .header {
                    border: 1px solid var(--users-table-border) !important;
                }

                .body {
                    .content > * {
                        border-right: 1px solid var(--users-table-border) !important;
                        border-left: 1px solid var(--users-table-border) !important;
                    }
                }
            }
        }
    }
}

.CP-users {
    .nx-new-table {
        .header {
            grid-template-columns: 42px 1fr 1fr 1fr 42px;
        }

        .big-row {
            grid-template-columns: 42px 1fr 1fr 1fr 42px;
            grid-template-rows: 40px;

            & > div:last-child {
                padding-left: 8px;
            }
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.org-users {
    .nx-new-table {
        .header {
            grid-template-columns: 42px 1fr .5fr 1fr 1fr 42px 42px;
        }

        .big-row {
            grid-template-columns: 42px 1fr .5fr 1fr 1fr 42px 42px;
            grid-template-rows: 40px;

            & > div {
                align-items: center;
                display: flex;
                gap: 0.25rem;
            }

            .icon {
                cursor: pointer;
                justify-content: center;
            }

            .delete {
                svg .st0 {
                    fill: red;
                    stroke: none;
                }
            }
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.access-table {
    .nx-new-table {
        .header {
            grid-template-columns: 42px 1fr 0.5fr 42px;
        }

        .big-row {
            grid-template-columns: 42px 1fr 0.5fr 42px;
            grid-template-rows: 40px;

            & > div {
                display: flex;
                align-items: center;
                gap: 0.5rem;
            }
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.service-usage-table {
    .nx-new-table {
        .header {
            grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
        }

        .big-row {
            grid-template-columns: 2fr 1fr 1fr 1fr 1fr;

            &:hover {
                cursor: pointer;
            }

            div:last-child {
                border-right: none;
            }
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.subscription-keys-activated-keys-table {
    .header, .big-row {
        grid-template-columns: repeat(4, 1fr);
    }
    .big-row {
        &:hover {
            cursor: default;
            background-color: var(--card-body-bg);
        }

    }
    .header, .body {
        width: 100% !important;
    }
}

.service-allocation-list-table {
    .header, .big-row {
        grid-template-columns: 1fr 238px 46px;
    }

    .big-row {
      border-right: none !important;
    }

    .header, .body {
        width: 100% !important;
    }

    .summary-row {
        background-color: var(--card-header-bg);
        color: var(--light-text-color);
        border-right: none !important;

        &:hover {
            cursor: default;
            background-color: var(--card-header-bg);
        }
    }
}

.service-allocation-folder-table {
    .header, .big-row {
        grid-template-columns: 1fr 238px 46px;
    }

    .header, .body {
        width: 100% !important;
    }

    .summary-row {
        background-color: var(--card-header-bg);
        color: var(--light-text-color);
        border-right: none !important;

        &:hover {
            cursor: default;
            background-color: var(--card-header-bg);
        }
    }
}

.regular-service-details-table {
    .nx-new-table {
        .header {
            grid-template-columns: 3fr 1fr 1fr 1fr 1fr;
        }

        .big-row {
            grid-template-columns: 3fr 1fr 1fr 1fr 1fr;

            &:hover {
                cursor: pointer;
            }

            &.summary-row:hover {
                cursor: default;
            }

            div:last-child {
                border-right: none;
            }
        }

        .summary-row {
            background-color: var(--card-header-bg);
            color: var(--light-text-color);
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.expiring-service-details-table {
    .nx-new-table {
        .header {
            grid-template-columns: 5fr 1fr 1fr;
        }

        .big-row {
            grid-template-columns: 5fr 1fr 1fr;

            &:hover {
                .no-hover {
                    background-color: var(--card-body-bg);
                    cursor: default;
                }

                cursor: pointer;
            }

            &.summary-row:hover {
                cursor: default;
            }

            div:last-child {
                border-right: none;
            }
        }

        .summary-row {
            background-color: var(--card-header-bg);
            color: var(--light-text-color);
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.regular-service-details-dialog-table {
    .nx-new-table {
        grid-template-rows: auto !important;

        .header {
            grid-template-columns: 1fr 1fr 1fr 1fr;
            border-left: none !important;
            border-right: none !important;

        }

        .big-row {
            grid-template-columns: 1fr 1fr 1fr 1fr;
            border-left: none !important;
            border-right: none !important;

            &:hover {
                cursor: default;
                background-color: var(--card-body-bg);
            }

            div {
                justify-content: flex-end;

                &:last-child {
                    border-right: none;
                }
            }
        }

        .summary-row {
            background-color: var(--card-header-bg);
            color: var(--light-text-color);
            border-bottom: none !important;

            &:hover {
                cursor: default;
                background-color: var(--card-header-bg);
            }
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.expiring-service-details-dialog-table {
    .nx-new-table {
        grid-template-rows: auto !important;

        .header {
            grid-template-columns: 1fr 1fr;
            border-left: none !important;
            border-right: none !important;

        }

        .big-row {
            grid-template-columns: 1fr 1fr;
            border-left: none !important;
            border-right: none !important;

            &:hover {
                cursor: default;
                background-color: var(--card-body-bg);
            }

            div {
                justify-content: flex-end;

                &:last-child {
                    border-right: none;
                }
            }
        }

        .summary-row {
            background-color: var(--card-header-bg);
            color: var(--light-text-color);
            border-bottom: none !important;

            &:hover {
                cursor: default;
                background-color: var(--card-header-bg);
            }
        }

        .header, .body {
            width: 100% !important;
        }
    }
}

.service-changes-table {
    .nx-new-table {
        .header {
            grid-template-columns: $service-changes-table-column-width;
        }

        .big-row {
            grid-template-columns: $service-changes-table-column-width;
            user-select: none;

            &:hover {
                cursor: default;
                background-color: var(--card-body-bg);
            }

            div:last-child {
                border-right: none;
            }
        }

        .header, .body {
            width: 100% !important;
            @media screen and (max-width: $large-desktop-breakpoint) {
                width: fit-content !important;
            }
        }
    }
}

.services-table {
    .nx-new-table {
        .header {
            grid-template-columns: 542px 368px 178px;
        }

        .big-row {
            grid-template-columns: 542px 368px 178px;
        }
    }
}

.table-wrapper {
    overflow-x: scroll;
    box-shadow: none;
    border: 1px solid var(--border-color);
    background-color: var(--body-bg);

    &::-webkit-scrollbar-track {
        background-color: var(--scrollbar-thumb-border-color);
    }

    &::-webkit-scrollbar-thumb {
        background-color: var(--scrollbar-thumb-bg);
        border: 2px solid var(--scrollbar-thumb-border-color) !important;
    }
}
