@use 'sass:map';
@use 'sass-true' as *;
@use '../base' as *;
@use '../components' as *;
@use '../themes/scoping' as scoping;
@use '../themes/schemas';

@include describe('Register Component') {
    $components: () !default;

    @include it('should add new component inside components list') {
        @include register-component('my-component');
        @include assert-true(map.has-key($components, 'my-component'));
    }
}

@include describe('Restore layered properties') {
    @include it('should revert only the specified properties') {
        @include assert() {
            @include output() {
                .test {
                    @include scoping.restore-properties(display, color);
                }
            }

            @include expect() {
                .test {
                    display: revert-layer;
                    color: revert-layer;
                }
            }
        }
    }
}

// stylelint-disable max-nesting-depth
@include describe('Scope') {
    @include it('should wrap each selector of a list in its own :where()') {
        @include assert() {
            @include output() {
                @include scoping.scope(test, '.a, b, .c .d', ()) using ($schema) {
                    color: red;
                }
            }

            @include expect() {
                @layer ig.test {
                    :where(.a), :where(b), :where(.c .d) {
                        color: red;
                    }
                }
            }
        }
    }
}
// stylelint-enable max-nesting-depth

@include describe('Generate color class') {
    @include it('should concatenate the name, variant, prefix, and suffix in the correct order.') {
        $name: primary;
        $variant: 500;
        $prefix: igx;
        $suffix: bg;
        $selector: #{$prefix}-#{$name}-#{$variant}-#{$suffix};

        @include assert() {
            @include output() {
                @include gen-color-class($name, $variant, $prefix, $suffix) {
                    content: 'test';
                }
            }

            @include expect() {
                .#{$selector} {
                    content: 'test'
                }
            }
        }
    }
}

/* stylelint-disable max-nesting-depth -- the expected output nests @layer, @container and @scope inside sass-true's blocks */
@include describe('Block') {
    @include it('should scope the content to the component in the base layer') {
        @include assert() {
            @include output() {
                @include scoping.block(combo) {
                    :scope {
                        display: flex;
                    }
                }
            }

            @include expect() {
                @layer ig.base {
                    @scope (.igx-combo) to (:scope [ig-scope] > *) {
                        :scope {
                            display: flex;
                        }
                    }
                }
            }
        }
    }

    @include it('should scope the content inside the theme layer and style query') {
        @include assert() {
            @include output() {
                @include scoping.block(combo, $theme: indigo) {
                    [data-part~='toggle'] {
                        color: red;
                    }
                }
            }

            @include expect() {
                @layer ig.indigo {
                    @container style(--ig-theme: indigo) {
                        @scope (.igx-combo) to (:scope [ig-scope] > *) {
                            [data-part~='toggle'] {
                                color: red;
                            }
                        }
                    }
                }
            }
        }
    }

    @include it('should also match the theme variant when one is given') {
        @include assert() {
            @include output() {
                @include scoping.block(combo, $theme: indigo, $variant: dark) {
                    :scope {
                        --_border: 1px;
                    }
                }
            }

            @include expect() {
                @layer ig.indigo {
                    @container style(--ig-theme: indigo) and style(--ig-theme-variant: dark) {
                        @scope (.igx-combo) to (:scope [ig-scope] > *) {
                            :scope {
                                --_border: 1px;
                            }
                        }
                    }
                }
            }
        }
    }
}
/* stylelint-enable max-nesting-depth */

@include describe('Scrollbar') {
    $sb-theme: scrollbar-theme($schema: schemas.$light-material-schema);

    @include it('should declare the tokens and properties on the parent selector and the scope when nested') {
        @include assert() {
            @include output() {
                .host {
                    @include scrollbar($sb-theme);
                }
            }

            @include expect() {
                .host,
                .host .ig-scrollbar {
                    @include scoping.css-vars-from-theme($sb-theme);

                    scrollbar-width: var(--sb-width, auto);
                    scrollbar-color: var-get($sb-theme, 'sb-thumb-bg-color') var-get($sb-theme, 'sb-track-bg-color');
                }
            }
        }
    }
}
