@use 'sass:color';

$bar-spacing: $spacing * .3;
$button-radius: $radius;

@mixin panel-button($flat: true, $reactive: true) {
    @include accs-button($flat, $reactive);

    >* {
        border-radius: $button-radius;
        margin: $bar-spacing;
    }

    label,
    image {
        font-weight: bold;
    }

    >* {
        padding: $padding * 0.4 $padding * 0.8;
    }
}

.bar {
    transition: $transition;
    background-color: $bg;

    .panel-button {
        @include panel-button;

        &:not(.flat) {

            @include accs-button($flat: false);
        }
    }

    .launcher {
        .colored {
            color: transparentize($primary-bg, 0.2);
        }

        &:hover .colored {
            color: $primary-bg;
        }

        &:active .colored,
        &.active .colored {
            color: $primary-fg;
        }
    }

    .workspaces {
        label {
            font-size: 0;
            min-width: 5pt;
            min-height: 5pt;
            border-radius: $radius*.6;
            box-shadow: inset 0 0 0 $border-width $border-color;
            margin: 0 $padding * .5;
            transition: $transition* .5;
            background-color: transparentize($fg, .8);

            &.occupied {
                background-color: transparentize($fg, .2);
                min-width: 7pt;
                min-height: 7pt;
            }

            &.active {
                // background-color: $primary-bg;
                background-image: $active-gradient;
                min-width: 20pt;
                min-height: 12pt;
            }
        }

        &.active,
        &:active {
            label {
                background-color: transparentize($primary-fg, .3);

                &.occupied {
                    background-color: transparentize($primary-fg, .15);
                }

                &.active {
                    background-color: $primary-fg;
                }
            }
        }
    }

    .media label {
        margin: 0 ($spacing * .5)
    }

    .taskbar .indicator.active {
        background-color: $primary-bg;
        border-radius: $radius;
        min-height: 4pt;
        min-width: 6pt;
        margin: 2pt;
    }

    .powermenu.colored,
    .recorder {
        image {
            color: transparentize($error-bg, 0.3);
        }

        &:hover image {
            color: transparentize($error-bg, 0.15);
        }

        &:active image {
            color: $primary-fg;
        }
    }

    .quicksettings>box>box {
        @include spacing($spacing: if($bar-spacing==0, $padding / 2, $bar-spacing));
    }

    .quicksettings:not(.active):not(:active) {
        .bluetooth {
            color: $primary-bg;

            label {
                font-size: $font-size * .7;
                color: $fg;
                text-shadow: $text-shadow;
            }
        }
    }

    .battery-bar {
        >* {
            padding: 0;
        }

        &.bar-hidden>box {
            padding: 0 $spacing * .5;

            image {
                margin: 0;
            }
        }

        levelbar * {
            all: unset;
            transition: $transition;
        }

        .whole {
            @if $shadows {
                image {
                    -gtk-icon-shadow: $text-shadow;
                }

                label {
                    text-shadow: $text-shadow;
                }
            }
        }

        .regular image {
            margin-left: $spacing * .5;
        }

        trough {
            @include widget;
            min-height: 12pt;
            min-width: 12pt;
        }

        .regular trough {
            margin-right: $spacing * .5;
        }

        block {
            margin: 0;

            &:last-child {
                border-radius: 0 $button-radius $button-radius 0;
            }

            &:first-child {
                border-radius: $button-radius 0 0 $button-radius;
            }
        }

        .vertical {
            block {
                &:last-child {
                    border-radius: 0 0 $button-radius $button-radius;
                }

                &:first-child {
                    border-radius: $button-radius $button-radius 0 0;
                }
            }

        }

        @for $i from 1 through $bar-battery-blocks {
            block:nth-child(#{$i}).filled {
                background-color: color.mix($bg, $primary-bg, $i*3)
            }

            &.low block:nth-child(#{$i}).filled {
                background-color: color.mix($bg, $error-bg, $i*3)
            }

            &.charging block:nth-child(#{$i}).filled {
                background-color: color.mix($bg, $charging-bg, $i*3)
            }

            &:active .regular block:nth-child(#{$i}).filled {
                background-color: color.mix($bg, $primary-fg, $i*3)
            }
        }

        &.low image {
            color: $error-bg
        }

        &.charging image {
            color: $charging-bg
        }

        &:active image {
            color: $primary-fg
        }
    }
}

.bar.transparent {
    background-color: transparent;

    .panel-button {
        &:hover>* {
            box-shadow: 1px 1px 3px 0 $shadow-color, inset 0 0 0 $border-width $border-color;
            background-color: $bg;
        }

        &:not(:hover):not(.active) {

            label,
            image {
                text-shadow: $text-shadow;
                -gtk-icon-shadow: $text-shadow;
            }
        }
    }

    .workspaces label {
        box-shadow: inset 0 0 0 $border-width $border-color,
            1px 1px 3px 0 $shadow-color;
    }

    .battery-bar trough {
        box-shadow: 1px 1px 3px 0 $shadow-color;

    }
}
