// (C) 2026 GoodData Corporation

@use "../../../styles/scss/Button/variables" as button-variables;
@use "../../../styles/scss/Button/mixins" as button-mixins;
@use "../../../styles/scss/variables";

$drag-handle-icon: "data:image/svg+xml,%3Csvg width='7' height='26' viewBox='0 0 7 26' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 4h2v2H0V4zm0-4h2v2H0V0zm5 4h2v2H5V4zm0-4h2v2H5V0zm0 8h2v2H5V8zM0 8h2v2H0V8zm0 4h2v2H0v-2zm5 4h2v2H5v-2zm-5 0h2v2H0v-2zm5 4h2v2H5v-2zm-5 0h2v2H0v-2zm5 4h2v2H5v-2zm-5 0h2v2H0v-2zm5-12h2v2H5v-2z' fill='%23B0BECA' fill-rule='evenodd'/%3E%3C/svg%3E";

.gd-ui-kit-control-button {
    $root: &;

    position: relative;
    max-width: 230px;
    padding: 5px 10px;
    font-family: variables.$gd-font-primary;
    font-size: 12px;
    font-weight: 400;
    line-height: 16px;
    cursor: pointer;
    user-select: none;
    border-radius: 3px;

    &--isDraggable {
        padding-left: 23px;
    }

    &::before,
    &::after {
        content: "";
        position: absolute;
        transition: all 0.2s ease;
    }

    &::before {
        z-index: 1;
        top: 8px;
        left: 9px;
        width: 7px;
        height: 26px;
        background: url("#{$drag-handle-icon}") no-repeat;
        opacity: 0;
    }

    &::after {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        border: 1px solid transparent;
        background: transparent;
        transform: translateZ(-1px);
        border-radius: 3px;
    }

    &:hover {
        &::after {
            border-color: button-variables.$button-normal-hover-border-color;
        }

        &#{$root}--isDraggable {
            box-shadow:
                0 1px 3px 0 button-variables.$button-shadow-lighter,
                0 2px 9px 0 button-variables.$button-shadow-darker;

            &::before {
                opacity: 1;
            }
        }
    }

    &--isOpen {
        &::after {
            box-shadow: inset 0 1px 0 0 button-variables.$button-normal-active-shadow;
            border-color: var(
                --gd-palette-complementary-5-from-theme,
                button-variables.$button-normal-hover-border-color
            );

            @include button-mixins.button-normal-active-gradient;
        }

        &#{$root}--isDraggable::before {
            opacity: 1;
        }

        #{$root}__subtitle-row::after {
            content: "\e613";
        }
    }

    &--isDragging {
        display: inline-block;

        &::after {
            border-color: button-variables.$button-normal-hover-border-color;
            background: var(--gd-palette-complementary-0-from-theme, rgba(255, 255, 255, 0.95));
        }

        &#{$root}--isDraggable::before {
            opacity: 1;
        }
    }

    &--isError {
        font-size: 12px;
        color: variables.$gd-palette-error-base;
        background: var(--gd-palette-error-base-t85, rgba(229, 77, 66, 0.15));
    }

    &--isWarning {
        font-size: 12px;
        color: variables.$gd-palette-warning-base;
        background: var(--gd-palette-warning-base-t85, rgba(241, 134, 0, 0.15));
    }

    &--disabled {
        cursor: default;

        &:hover,
        &:focus,
        &:active {
            user-select: auto;
            box-shadow: none;
            background: transparent;
            border-color: transparent;
            text-decoration: none;
        }
    }

    // Single full-width line, flat (no border/gradient), chevron pinned right.
    // Declared after the state modifiers so its flat `::after` wins.
    &--layout-row {
        width: 100%;
        max-width: none;
        box-sizing: border-box;
        font-size: 14px;
        border-radius: 0;
        padding-top: 15px;
        padding-bottom: 15px;
        // Room for the pinned chevron
        padding-right: 28px;

        // Flat: no border or open-state gradient.
        &::after {
            display: none;
        }

        #{$root}__icon {
            display: flex;
            height: 100%;
            align-items: center;
        }

        // One left-aligned line; chevron is taken out of flow.
        #{$root}__content {
            flex-direction: row;
            align-items: center;
            justify-content: flex-start;
        }

        // min-width: 0 lets a long label ellipsise instead of overflowing.
        #{$root}__title-row {
            flex: 0 1 auto;
            min-width: 0;
            max-width: 100%;
            margin-right: 5px;
        }

        #{$root}__title--withColon::after {
            content: ":";
        }

        #{$root}__subtitle-row {
            flex: 1 1 auto;
            min-width: 0;
            max-width: none;

            // Chevron
            &::after {
                position: absolute;
                top: 50%;
                // `content` is inset by padding-right lands it 12px from the button edge.
                right: -16px;
                margin-left: 0;
                font-size: 18px;
                transform: translateY(-50%);
            }
        }
    }

    &--hideChevron {
        #{$root}__subtitle-row::after {
            display: none;
        }
    }

    &__icon {
        position: relative;
        z-index: 1;
        float: left;
        padding-right: 5px;
    }

    &__content {
        position: relative;
        z-index: 1;
        display: flex;
        flex-direction: column;
        min-width: 0;
        flex: 1 1 auto;
    }

    &__title-row {
        display: flex;
        justify-content: space-between;
        max-width: 100%;
        white-space: nowrap;
    }

    &__title {
        overflow: hidden;
        color: variables.$gd-color-label;
        margin-right: auto;
        max-width: 100%;
        white-space: nowrap;
        text-overflow: ellipsis;

        .gd-bubble-trigger,
        .shortened {
            display: inline-flex;
        }

        .shortened {
            max-width: 100%;
        }
    }

    &__subtitle-row {
        display: inline-flex;
        flex-wrap: nowrap;
        max-width: 100%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-weight: bold;
        color: variables.$gd-color-dark;

        &::after {
            content: "\e612";
            display: inline-block;
            margin-left: 0.5em;
            font-family: variables.$gd-font-indigo;
            font-weight: normal;
            font-size: inherit;
            vertical-align: top;
            color: variables.$gd-color-state-blank;
            transition: all 0.2s ease;
        }
    }

    &__subtitle {
        display: inline-block;
        flex: 0 1 auto;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: bottom;

        .gd-bubble-trigger,
        .shortened {
            display: inline-flex;
        }

        .shortened {
            max-width: 100%;
        }
    }
}
