@use "../core/_index.scss" as *;
@use "./_variables.scss" as *;
@use "../list/_variables.scss" as *;
@use "../popup/_variables.scss" as *;
@use "@progress/kendo-theme-core/scss/components/grid/_theme.scss" as *;


@mixin kendo-grid--theme() {

    // Theme
    .k-grid {
        @include fill( $kendo-grid-text, $kendo-grid-bg, $kendo-grid-border );

        .k-table {
            background-color: inherit;
        }

        td,
        .k-table-td,
        .k-grid-content,
        .k-grid-header-locked,
        .k-grid-content-locked {
            border-color: $kendo-grid-border;
        }

        // Alt row
        .k-table-alt-row {
            color: $kendo-grid-alt-text;
            background-color: $kendo-grid-alt-bg;
        }

        // Hover state
        tbody>tr:not(.k-detail-row):hover,
        .k-table-tbody>.k-table-row:not(.k-detail-row).k-hover {
            color: $kendo-grid-hover-text;
            background-color: $kendo-grid-hover-bg;
        }

        // Selected state
        .k-table-th.k-selected,
        td.k-selected,
        .k-table-td.k-selected,
        .k-table-row.k-selected > td,
        .k-table-row.k-selected > .k-table-td {
            color: $kendo-grid-selected-text;
            background-color: $kendo-grid-selected-bg;
        }

        // Focused state
        .k-table-th,
        td,
        .k-table-td,
        .k-master-row > td,
        .k-grouping-row > td,
        .k-detail-row > td,
        .k-group-footer > td,
        .k-master-row > .k-table-td,
        .k-grouping-row > .k-table-td,
        .k-detail-row > .k-table-td,
        .k-group-footer > .k-table-td,
        .k-grid-pager {
            &:focus,
            &.k-focus {
                box-shadow: $kendo-grid-focus-shadow;
            }
        }

        col.k-sorted,
        .k-table-th.k-sorted {
            background-color: $kendo-grid-sorted-bg;
        }

        // Locked

        .k-grid-header-locked,
        .k-grid-content-locked,
        .k-grid-header-locked .k-header,
        .k-grid-content-locked td,
        .k-grid-content-locked .k-table-td {
            border-color: $kendo-grid-sticky-header-border;
        }

        .k-grid-header-locked .k-header {
            border-bottom-color: $kendo-grid-header-border;
        }

        .k-grid-content-locked {
            .k-group-footer td,
            .k-group-footer .k-table-td,
            .k-group-cell {
                @include fill( $border: $kendo-grid-header-border );
            }

            .k-grouping-row + .k-table-row td,
            .k-grouping-row + .k-table-row .k-table-td {
                border-top-color: $kendo-grid-header-border;
            }

            // Selected state
            .k-selected td,
            .k-selected .k-table-td {
                @include fill( $bg: $kendo-grid-sticky-selected-bg );
            }

            .k-selected.k-table-alt-row td,
            .k-selected.k-table-alt-row .k-table-td {
                @include fill( $bg: $kendo-grid-sticky-selected-alt-bg );
            }

            // Selected hover
            .k-selected:hover td,
            .k-selected.k-hover td,
            .k-selected:hover .k-table-td,
            .k-selected.k-hover .k-table-td {
                @include fill( $bg: $kendo-grid-sticky-selected-hover-bg );
            }
        }
    }


    // Toolbar
    .k-grid-toolbar {
        @include fill(
            null,
            null,
            inherit,
            null
        );
    }


    // Grouping header
    .k-grouping-header {
        @include fill( $kendo-grid-header-text, $kendo-grid-header-bg, $kendo-grid-header-border );
    }

    // Header
    .k-grid-header {
        @include fill( $kendo-grid-header-text, $kendo-grid-header-bg, $kendo-grid-header-border );

        .k-sort-icon,
        .k-sort-order {
            color: $kendo-grid-sorting-indicator-text;
        }

        .k-grid-filter,
        .k-header-column-menu,
        .k-grid-header-menu,
        .k-hierarchy-cell .k-icon {
            &:focus,
            &.k-focus {
                box-shadow: inset 0 0 0 2px rgba( black, .1 );
            }
            &.k-active {
                color: $kendo-selected-text;
                background-color: $kendo-selected-bg;
            }
        }

        .k-grid-header-sticky,
        .k-grid-header-sticky.k-sorted {
            @include fill(
                $color: $kendo-grid-sticky-header-text,
                $bg: $kendo-grid-sticky-header-bg
            );

            border-right-color: $kendo-grid-sticky-header-border;
            border-left-color: $kendo-grid-sticky-header-border;
        }
    }


    // Selection Aggregates
    .k-selection-aggregates {
        @include fill(
            $kendo-grid-selection-aggregates-text,
            $kendo-grid-selection-aggregates-bg,
            $kendo-grid-selection-aggregates-border
        );
    }


    // Content
    .k-master-row {
        .k-grid-content-sticky {
            @include fill(
                $kendo-grid-sticky-text,
                $kendo-grid-sticky-bg,
                $kendo-grid-sticky-border
            );
            border-top-color: $kendo-grid-border;
        }

        .k-grid-row-sticky,
        &.k-grid-row-sticky > .k-table-td {
            border-top-color: $kendo-grid-sticky-border;
            border-bottom-color: $kendo-grid-sticky-border;
            background-color: $kendo-grid-sticky-bg;
        }

        &.k-table-alt-row {
            .k-grid-content-sticky,
            &.k-grid-row-sticky > .k-table-td,
            .k-grid-row-sticky {
                @include fill( $bg: $kendo-grid-sticky-alt-bg );
            }
        }

        // Selected state
        &.k-table-row.k-selected td.k-grid-content-sticky,
        &.k-table-row.k-selected.k-grid-row-sticky > .k-table-td,
        &.k-table-row.k-selected .k-table-td.k-grid-row-sticky,
        &.k-table-row td.k-grid-content-sticky.k-selected,
        &.k-table-row .k-table-td.k-grid-content-sticky.k-selected {
            @if($kendo-enable-color-system) {
                @include fill( $bg: $kendo-grid-sticky-bg );

                &::before {
                    @include fill( $bg: $kendo-grid-sticky-selected-bg );
                }
            } @else {
                @include fill( $bg: $kendo-grid-sticky-selected-bg );
            }
        }

        &.k-selected.k-table-alt-row td.k-grid-content-sticky,
        &.k-selected.k-table-alt-row.k-grid-row-sticky > .k-table-td,
        &.k-selected.k-table-alt-row .k-table-td.k-grid-row-sticky,
        &.k-table-alt-row td.k-grid-content-sticky.k-selected,
        &.k-table-alt-row .k-table-td.k-grid-content-sticky.k-selected {
            @if($kendo-enable-color-system) {
                @include fill( $bg: $kendo-grid-sticky-alt-bg );

                &::before {
                    @include fill( $bg: $kendo-grid-sticky-selected-alt-bg );
                }
            } @else {
                @include fill( $bg: $kendo-grid-sticky-selected-alt-bg );
            }
        }


        // Hovered state
        &:hover .k-grid-content-sticky,
        &.k-hover .k-grid-content-sticky,
        &:hover .k-grid-row-sticky,
        &.k-hover .k-grid-row-sticky,
        &:hover.k-grid-row-sticky > .k-table-td,
        &.k-hover.k-grid-row-sticky > .k-table-td {
            background-color: $kendo-grid-sticky-hover-bg;
        }


        // Selected hover
        &.k-selected:hover td.k-grid-content-sticky,
        &.k-selected.k-hover .k-table-td.k-grid-content-sticky,
        &.k-selected:hover td.k-grid-row-sticky,
        &.k-selected.k-hover .k-table-td.k-grid-row-sticky,
        &.k-selected:hover.k-grid-row-sticky > .k-table-td,
        &.k-selected.k-hover.k-grid-row-sticky > .k-table-td,
        &:hover td.k-grid-content-sticky.k-selected,
        &.k-hover td.k-grid-content-sticky.k-selected,
        &:hover .k-table-td.k-grid-content-sticky.k-selected,
        &.k-hover .k-table-td.k-grid-content-sticky.k-selected {
            @if($kendo-enable-color-system) {
                background-color: $kendo-grid-sticky-hover-bg;

                &::before {
                    background-color: $kendo-grid-sticky-selected-hover-bg;
                }
            } @else {
                background-color: $kendo-grid-sticky-selected-hover-bg;
            }
        }
    }

    .k-grouping-row {
        .k-grid-content-sticky {
            @include fill( $bg: $kendo-grid-sticky-header-bg );
        }

        &:hover .k-grid-content-sticky,
        &.k-hover .k-grid-content-sticky {
            @include fill( $bg: $kendo-grid-sticky-hover-bg );
        }
    }

    .k-group-footer {
        td,
        .k-table-td,
        .k-grid-footer-sticky {
            @include fill( $bg: $kendo-grid-sticky-footer-bg );
        }

        &:hover .k-grid-footer-sticky,
        &.k-hover .k-grid-footer-sticky {
            @include fill( $bg: $kendo-grid-sticky-footer-hover-bg );
        }
    }

    // Footer
    .k-grid-footer {
        @include fill(
            $kendo-grid-footer-text,
            $kendo-grid-footer-bg,
            $kendo-grid-footer-border
        );
        .k-grid-footer-locked {
            border-color: inherit;
        }
        .k-grid-footer-sticky {
            border-color: $kendo-grid-sticky-border;
            background-color: $kendo-grid-sticky-footer-bg;
        }
    }

    // Grouping
    .k-grouping-row,
    .k-group-cell {
        @include fill( $kendo-grid-header-text, $kendo-grid-header-bg, $kendo-grid-header-border );
    }

    .k-column-list-item:hover,
    .k-columnmenu-item:hover {
        @include fill(
            $kendo-list-item-hover-text,
            $kendo-list-item-hover-bg
        );
    }
    .k-column-list-item:focus,
    .k-column-list-item.k-focus,
    .k-columnmenu-item:focus,
    .k-columnmenu-item.k-focus {
        @include box-shadow( $kendo-list-item-focus-shadow );
    }

    .k-column-list-wrapper {
        border-color: inherit;
    }

    .k-columnmenu-item {
        &.k-selected {
            @include fill(
                $kendo-list-item-selected-text,
                $kendo-list-item-selected-bg
            );
        }
    }

    .k-column-menu {

        .k-menu:not(.k-context-menu) {

            @include fill(
                $kendo-popup-text,
                $kendo-popup-bg,
                $kendo-popup-border
            );

            .k-item {
                @include fill(
                    $kendo-list-item-text,
                    $kendo-list-item-bg
                );

                &:hover,
                &.k-hover {
                    @include fill(
                        $kendo-list-item-hover-text,
                        $kendo-list-item-hover-bg
                    );
                }

                &.k-selected {
                    @include fill(
                        $kendo-list-item-selected-text,
                        $kendo-list-item-selected-bg
                    );
                }

                &:focus,
                &.k-focus {
                    @include box-shadow( $kendo-list-item-focus-shadow );
                }
            }
        }
    }
    .k-column-menu-tabbed {
        background-color: $kendo-grid-column-menu-tabbed-bg;
    }

    .k-column-menu-group-header-text {
        @include fill(
            $kendo-grid-column-menu-group-header-text,
            $kendo-grid-column-menu-group-header-bg,
            $kendo-grid-column-menu-group-header-border
        );
    }

    .k-check-all-wrap {
        @include fill( $border: $kendo-popup-border );
    }

    .k-grid-norecords-template {
        background-color: $kendo-grid-bg;
        border-color: $kendo-grid-border;
    }

    // Row resize indicator
    .k-resizer-wrap {

        &.k-hover .k-row-resizer {
            @include fill( $bg: $kendo-grid-row-resizer-hover-bg );
        }

        &.k-active .k-row-resizer {
            @include fill( $bg: $kendo-grid-row-resizer-active-bg );
        }

    }

    .k-columnmenu-indicators {
        color: $kendo-grid-sorting-indicator-text;
    }

}
