// (C) 2026 GoodData Corporation

@use "../UiToolbar/toolbarItem";

.gd-ui-kit-toolbar-stepper {
    $root: &;

    display: inline-flex;
    align-items: center;
    gap: toolbarItem.$toolbar-item-gap;
    box-sizing: border-box;
    height: toolbarItem.$toolbar-item-size;
    padding: 0 toolbarItem.$toolbar-item-padding;

    &__value {
        @include toolbarItem.toolbar-item-base;

        --gd-icon-fill-color: var(--gd-palette-complementary-7);

        min-width: 0;
        color: var(--gd-palette-complementary-7);
        text-align: center;
        cursor: default;

        &--isEditable {
            // A constant width so the toolbar does not move while the value is typed or stepped.
            // Fits four characters: percentages up to "100%" and whole numbers up to four digits.
            width: calc(4.5ch + 2 * #{toolbarItem.$toolbar-field-padding});
            padding: 0 toolbarItem.$toolbar-field-padding;
            text-align: center;
            cursor: text;

            @include toolbarItem.toolbar-field-border(var(--gd-palette-complementary-4));

            &::placeholder {
                color: var(--gd-palette-complementary-6);
            }

            &:not([aria-disabled="true"]) {
                &:hover {
                    @include toolbarItem.toolbar-field-border(var(--gd-palette-complementary-5));
                }

                // The preset list is on screen.
                &#{$root}__value--isActive {
                    background-color: var(--gd-palette-complementary-2);

                    @include toolbarItem.toolbar-field-border(var(--gd-palette-complementary-4));
                }

                &:active {
                    background-color: var(--gd-palette-complementary-3);

                    @include toolbarItem.toolbar-field-border(var(--gd-palette-complementary-5));
                }

                // After the hover rule so an invalid value stays red under the pointer.
                &#{$root}__value--isInvalid {
                    color: var(--gd-palette-error-base);

                    @include toolbarItem.toolbar-field-border(var(--gd-palette-error-base));
                }

                // Last, so the ring replaces whichever border the state above drew.
                &:focus-visible {
                    box-shadow: inset 0 0 0 2px var(--gd-palette-primary-base);
                }
            }

            &[aria-disabled="true"] {
                color: var(--gd-palette-complementary-5);
                cursor: default;

                @include toolbarItem.toolbar-focus-ring;
            }
        }
    }
}
