// (C) 2022-2025 GoodData Corporation
@use "sass:color";
@use "variables";

.gd-invertable-select {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    flex-shrink: 1;
}

.gd-invertable-select-search-input {
    margin: 10px;
    width: calc(100% - 20px);
    min-width: 0;
}

input[type="search"]::-webkit-search-cancel-button {
    display: none;
}

.gd-invertable-select-all-checkbox,
.gd-invertable-select-search-bar,
.gd-invertable-select-status-bar {
    display: flex;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.gd-invertable-select-list,
.gd-invertable-select-loading,
.gd-invertable-select-error,
.gd-invertable-select-no-data {
    height: 100%;
    min-height: 0;
    flex-shrink: 1;
}

.gd-invertable-select-list {
    .gd-list-item:focus-visible {
        outline-offset: -2px; // pull outline inside to not have it clipped by item's overflow: hidden
    }
}

.gd-invertable-select-all-checkbox {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    margin: 0 10px 10px;
    font-size: 12px;
    cursor: pointer;

    // Separator line rendered outside the focus ring via ::after
    &::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: -6px;
        border-bottom: 1px solid var(--gd-palette-complementary-3, #dde4eb);
    }

    .input-checkbox-label {
        cursor: pointer;
    }

    // Pure ARIA checkbox styling based on aria-checked attribute
    &[role="checkbox"] {
        // Checked state - show checkmark
        &[aria-checked="true"] .input-label-text {
            &::before {
                border-color: transparent;
                background-color: variables.$gd-palette-primary-base;
            }

            &::after {
                transform: scale(1) rotate(315deg) skew(-2deg);
            }
        }

        // Mixed state - show dash
        &[aria-checked="mixed"] .input-label-text {
            &::before {
                border-color: transparent;
                background-color: variables.$gd-palette-primary-base;
            }

            &::after {
                top: 9px;
                left: 6px;
                width: 8px;
                height: 0;
                transform: scale(1);
                border-left: none;
                border-bottom: 2px solid variables.$gd-color-text-light;
            }
        }

        // Unchecked state - default styling from .input-label-text::before

        // Hover state
        &:hover .input-label-text::before {
            box-shadow: inset 0 1px 2px 0
                color.adjust(variables.$gd-input-text-box-shadow-color, $alpha: -0.75);
        }

        &:hover[aria-checked="true"] .input-label-text::before,
        &:hover[aria-checked="mixed"] .input-label-text::before {
            box-shadow: none;
            border-color: transparent;
        }

        // Active state
        &:active .input-label-text::before {
            border-color: variables.$gd-palette-primary-base;
            background-color: variables.$gd-palette-primary-dimmed;
        }

        // Focus visible state - use default browser outline
    }
}

.gd-invertable-list-limitExceeded {
    margin: 0 10px 10px;
}

.gd-invertable-select-selection-status {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    height: 25px;
    min-width: 0;
    margin: 5px 10px;
    line-height: 20px;
    font-size: 12px;
    padding-top: 5px;
    border-top: 1px solid variables.$gd-border-color;
    font-family: variables.$gd-font-primary;

    span,
    b {
        flex: 0 0 auto;
        height: 20px;
        min-width: 0;
        line-height: 20px;
        white-space: nowrap;
    }

    .gd-ui-kit-tooltip__anchor {
        display: flex;
        flex: 0 1 auto;
        overflow: hidden;
        width: auto;
        height: 20px;
        white-space: nowrap;
        max-width: inherit;
        text-overflow: ellipsis;

        &.gd-selection-list {
            font-weight: bold;
        }
    }

    .gd-shortened-text {
        flex: 0 1 auto;
        overflow: hidden;
        width: auto;
        height: 20px;
        white-space: nowrap;
        max-width: inherit;
        text-overflow: ellipsis;

        &.gd-selection-list {
            font-weight: bold;
        }
    }
}

.gd-invertable-select-error {
    display: flex;
    margin: 10px;

    .gd-message {
        width: 100%;
    }
}

.gd-invertable-select-actions {
    display: flex;
    flex-direction: column;
    padding: 0 10px;
}

.gd-invertable-select-actions-buttons {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 10px 0;
    gap: 10px;
}
