@import "../variables/variables";
@import "../mixins/private/bubble-mixins";
@import "../mixins/private/filter-button-mixins";
@import "../mixins/private/filter-menu-mixins";
@import "../mixins/private/token-mixins";

/* .filter-group also exists in filter-button */
/* todo: move to utility/layout class and/or mixin */
div.filter-group {
    display: flex;
    flex-wrap: wrap;
}

span.filter-menu-button {
    display: inline-block;
    position: relative;

    & + & {
        margin-left: 8px;
    }
}

button.filter-menu-button__button {
    @include filter-button-base();
    @include background-color-token(
        filter-button-background-color,
        color-background-secondary
    );
    @include border-color-token(
        filter-button-selected-border-color,
        color-stroke-default
    );

    &:focus,
    &:hover,
    &:active {
        @include background-color-token(
            filter-button-background-color,
            color-state-secondary-hover
        );
    }
}

.filter-menu-button__button-cell {
    display: flex;

    svg.icon--12 {
        align-self: center;
        margin-inline-start: 8px;
        @include color-token(
            filter-menu-button-icon-color,
            color-foreground-primary
        );
    }
}

.filter-menu-button__button-text {
    display: inline-block;
    max-width: 238px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-menu-button__button[aria-expanded="true"] svg.icon {
    transform: rotate(180deg);
}

button.filter-menu-button__button[aria-pressed="true"] {
    @include border-color-token(
        filter-button-foreground-color,
        color-stroke-strong
    );

    font-weight: bold;
}

button.filter-menu-button__button[disabled],
button.filter-menu-button__button[aria-disabled="true"],
button.filter-menu-button__button[aria-pressed="true"][disabled],
button.filter-menu-button__button[aria-pressed="true"][aria-disabled="true"] {
    @include color-token(
        filter-button-disabled-foreground-color,
        color-background-disabled
    );

    font-weight: normal;

    /* todo: we can elimate the need for these overrides by using :not([disabled]) in place where defining hover states */
    &:hover,
    &:focus {
        @include background-color-token(
            filter-button-background-color,
            color-background-secondary
        );
        @include color-token(
            filter-button-disabled-foreground-color,
            color-background-disabled
        );
    }

    & .filter-menu-button__button-cell > svg.icon {
        @include color-token(
            filter-button-disabled-foreground-color,
            color-foreground-disabled
        );
    }
}

/* todo: we can elimate the need for these overrides by using :not([disabled]) in place where defining hover states */
button.filter-menu-button__button[aria-pressed="true"][disabled]:hover,
button.filter-menu-button__button[aria-pressed="true"][aria-disabled="true"]:hover {
    @include background-color-token(
        filter-button-selected-background-color,
        color-background-secondary
    );
}

.filter-menu-button__menu {
    @include background-color-token(
        filter-menu-item-background-color,
        color-background-elevated
    );

    border: none;
    border-radius: 16px;
    box-shadow: var(--bubble-shadow);
    display: none;
    min-width: 144px;
    overflow: hidden;
    position: absolute;
    top: 0;
    width: max-content;
    z-index: 1;
}

.filter-menu-button__menu--set-position {
    top: calc(100% + 8px);
}

button.filter-menu-button__button[aria-expanded="true"]
    + .filter-menu-button__menu {
    display: block;
}

.filter-menu-button__items {
    margin-top: 8px;
    max-height: 400px;
    min-width: 100%;
    overflow-y: auto;
    position: relative;
    transform: translateZ(0);
}

span.filter-menu-button__items {
    display: inline-block;
}

span.filter-menu-button__checkbox,
span.filter-menu-button__radio {
    display: block;
    flex-shrink: 1;
    height: 18px;
    min-width: 18px;
    width: 18px;
}

span.filter-menu-button__checkbox {
    svg.icon--unchecked {
        @include color-token(
            filter-menu-item-unchecked-color,
            color-foreground-secondary
        );

        display: block;
        height: 18px;
        width: 18px;
    }

    svg.icon--checked {
        @include color-token(
            filter-menu-item-checked-color,
            color-foreground-primary
        );

        display: none;
        height: 18px;
        width: 18px;
    }
}

span.filter-menu-button__radio {
    svg.icon--unchecked {
        @include color-token(
            filter-menu-item-unchecked-color,
            color-foreground-primary
        );

        display: block;
        height: 18px;
        width: 18px;
    }

    svg.icon--checked {
        @include color-token(
            filter-menu-item-checked-color,
            color-foreground-primary
        );

        display: none;
        height: 18px;
        width: 18px;
    }
}

.filter-menu-button__item {
    @include filter-menu-item-base();

    outline-offset: -4px;
    padding: 8px 16px;

    &:hover {
        background-color: var(--color-state-primary-hover);
    }

    &:last-child {
        margin-bottom: 8px;
    }

    span.checkbox,
    span.radio {
        align-items: flex-start;
        display: flex;
        flex-shrink: 1;
        justify-content: center;
    }

    svg.checkbox__unchecked {
        @include color-token(
            filter-menu-item-unchecked-color,
            color-foreground-secondary
        );
    }

    svg.checkbox__checked {
        @include color-token(
            filter-menu-item-checked-color,
            color-foreground-primary
        );
    }

    svg.radio__unchecked {
        @include color-token(
            filter-menu-item-unchecked-color,
            color-foreground-secondary
        );
    }

    svg.radio__checked {
        @include color-token(
            filter-menu-item-checked-color,
            color-foreground-primary
        );
    }
}

span.filter-menu-button__item {
    display: block;
}

button.filter-menu-button__footer {
    @include filter-menu-item-base();

    border: none;
    border-top-style: solid;
    border-top-width: 1px;
    bottom: 0;
    outline-offset: -10;
    padding: 16px;
    transform: translateZ(0);
    @include border-color-token(filter-menu-border-color, color-stroke-subtle);

    &:focus,
    &:hover {
        background-color: var(--color-state-primary-hover);
    }
}

.filter-menu-button__text {
    flex-grow: 1;
    margin-left: 8px;
}

.filter-menu-button__item[role="menuitemcheckbox"][aria-checked="true"] {
    svg.icon--unchecked {
        display: none;
    }

    svg.icon--checked {
        display: block;
    }
}

.filter-menu-button__item[role="menuitemradio"][aria-checked="true"] {
    svg.icon--unchecked {
        display: none;
    }

    svg.icon--checked {
        display: block;
    }
}

/* https://developer.paciellogroup.com/blog/2018/03/focus-visible-and-backwards-compatibility/ */
div.filter-menu-button__item[role^="menuitem"]:focus:not(:focus-visible) {
    outline: none;
}

[dir="rtl"] {
    .filter-menu-button__checkbox {
        margin-left: 8px;
    }
}
