@use "@progress/kendo-theme-core/scss/components/grid/_layout.scss" as *;
@use "sass:map";
@use "../core/_index.scss" as *;
@use "../core/functions/index.scss" as *;
@use "./_variables.scss" as *;

@mixin kendo-grid--layout() {
    @include kendo-grid--layout-base();

    // Add vertical border to locked and sticky columns
    .k-grid-content-locked,
    .k-grid-footer-locked,
    .k-grid-header-locked {
        border-inline-end-width: 1px;
    }

    .k-grid {

        .k-table .k-grid-header-sticky,
        .k-table .k-grid-content-sticky,
        .k-table .k-grid-footer-sticky {
            border-inline-end-width: 1px;
        }

        @each $size, $size-props in $kendo-grid-sizes {
            $_header-padding-x: map.get( $size-props, header-padding-x );

            #{k-when-default($kendo-grid-default-size, $size)}
            &.k-grid-#{$size}{
                .k-cell-inner {
                    .k-grid-filter,
                    .k-header-column-menu,
                    .k-grid-header-menu {
                        margin-inline-end: $_header-padding-x;
                    }
                }
            }
        }

        .k-detail-row,
        .k-master-row {
            .k-group-cell + :not(.k-group-cell) {
                border-inline-start: 1px solid k-color(border);
            }
        }

        .k-table .k-table-row .k-table-group-td {
            border-width: 0;
        }

        .k-grouping-row + .k-table-row .k-table-td {
            border-block-start-width: 0;
        }

        .k-grouping-row + .k-master-row .k-table-td {
            border-block-start-width: $kendo-grid-grouping-row-border-top;
        }
    }

    // Column menu fix for action buttons focus state
    .k-filter-menu-container {
        .k-actions {
            padding: k-spacing(1);
            margin: calc( #{k-spacing(1)} * -1 );
        }
    }

    .k-column-menu .k-expander {
        backdrop-filter: none;
        border-radius: 0;
    }

    .k-grid-footer .k-table-td,
    .k-group-footer .k-table-td,
    .k-grouping-row .k-table-td {
        font-weight: var(--kendo-font-weight-medium, 500);
    }

    .k-table-group-row .k-table-td {
        border-block-end-width: 0;
    }

    // Row-span cells use an inset shadow for all borders,
    // so zero out the td's own borders to avoid doubling.
    .k-grid .k-table-td-row-span {
        border-width: 0;
    }

    // Pinned and sticky containers have their own borders,
    // so zero out the adjacent row td borders to avoid doubling.
    .k-grid-pinned-wrap,
    .k-grid-sticky-container {
        .k-table-row:first-child > .k-table-td {
            border-block-start-width: 0;
        }
        .k-table-row:last-child > .k-table-td {
            border-block-end-width: 0;
        }
    }

     .k-grid-header {
        .k-table-thead > .k-table-row:not(:only-child) > .k-table-th,
        .k-table-thead > .k-table-row:not(:only-child) > .k-table-td {
            border-inline-start: 1px solid k-color(border);
        }

        .k-table-thead > .k-table-row:not(:only-child):first-child > .k-table-th:first-child,
        .k-table-thead > .k-table-row:not(:only-child):first-child > .k-table-td:first-child {
            border-inline-start-width: 0;
        }
    }
}
