@use "sass:color";
@use "sass:map";
@use "sass:list";

$button-height: $pt-button-height;
$button-border-width: 1px; // !default;
$button-padding: ($pt-grid-size * 0.5) $pt-grid-size; // !default;
$button-border-radius: $pt-border-radius;

// $button-padding-small: 0 ($pt-grid-size * 0.7) !default;
// $button-padding-large: ($pt-grid-size * 0.5) ($pt-grid-size * 1.5) !default;
$button-icon-spacing: $pt-grid-size * 0.5; // ($pt-button-height - $pt-icon-size-standard) * 0.5 !default;
// $button-icon-spacing-large: ($pt-button-height-large - $pt-icon-size-large) * 0.5 !default;
// $button-box-shadow: inset 0 0 0 $button-border-width rgba($black, 0.2), inset 0 (-$button-border-width) 0 rgba($black, 0.1) !default;
// $button-box-shadow-active: inset 0 0 0 $button-border-width rgba($black, 0.2), inset 0 1px 2px rgba($black, 0.2) !default;
// $button-intent-box-shadow: inset 0 0 0 $button-border-width rgba($black, 0.4), inset 0 (-$button-border-width) 0 rgba($black, 0.2) !default;
// $button-intent-box-shadow-active: inset 0 0 0 $button-border-width rgba($black, 0.4), inset 0 1px 2px rgba($black, 0.2) !default;
// $button-box-shadow-overlay: 0 0 0 $button-border-width rgba($black, 0.2), 0 1px 1px rgba($black, 0.2) !default;
// $button-box-shadow-overlay-active: 0 0 0 $button-border-width rgba($black, 0.2), inset 0 1px 1px rgba($black, 0.1) !default;
// $dark-button-box-shadow: 0 0 0 $button-border-width rgba($black, 0.4) !default;
// $dark-button-box-shadow-active: 0 0 0 $button-border-width rgba($black, 0.6), inset 0 1px 2px rgba($black, 0.2) !default;
// $dark-button-intent-box-shadow: 0 0 0 $button-border-width rgba($black, 0.4) !default;
// $dark-button-intent-box-shadow-active: 0 0 0 $button-border-width rgba($black, 0.4), inset 0 1px 2px rgba($black, 0.2) !default;
$button-gradient: none; // !default;
$button-intent-gradient: $button-gradient; // !default;
$dark-button-gradient: $button-gradient; // !default;
// $button-color-disabled: $pt-text-color-disabled !default;
// $button-background-color: $light-gray5 !default;
// $button-background-color-hover: $light-gray4 !default;
// $button-background-color-active: $light-gray2 !default;
// $button-background-color-disabled: rgba($light-gray1, 0.5) !default;
// $button-background-color-active-disabled: rgba($light-gray1, 0.7) !default;
// $button-intent-color-disabled: rgba($white, 0.6);
// $dark-button-color-disabled: $pt-dark-text-color-disabled !default;
// $dark-button-background-color: $dark-gray5 !default;
// $dark-button-background-color-hover: $dark-gray4 !default;
// $dark-button-background-color-active: $dark-gray2 !default;
// $dark-button-background-color-disabled: rgba($dark-gray5, 0.5) !default;
// $dark-button-background-color-active-disabled: rgba($dark-gray5, 0.7) !default;
// $dark-button-intent-color-disabled: rgba($white, 0.3);
// $minimal-button-divider-width: 1px !default;
// $minimal-button-background-color: none !default;
// $minimal-button-background-color-hover: rgba($gray4, 0.3) !default;
// $minimal-button-background-color-active: rgba($gray2, 0.3) !default;
// $dark-minimal-button-background-color: none !default;
// $dark-minimal-button-background-color-hover: rgba($gray3, 0.15) !default;
// $dark-minimal-button-background-color-active: rgba($gray3, 0.3) !default;
// $button-outlined-width: 1px !default;
// $button-outlined-border-intent-opacity: 0.6 !default;
// $button-outlined-border-disabled-intent-opacity: 0.2 !default;

$button-intents: (
    // default - hover - active
    "primary": (
            eccgui-color-var("identity", "brand", "900"),
            eccgui-color-mix(
                eccgui-color-var("identity", "brand", "900"),
                eccgui-color-var("identity", "text", "900") 10%
            ),
            eccgui-color-mix(
                eccgui-color-var("identity", "brand", "900"),
                eccgui-color-var("identity", "text", "900") 20%
            )
        ),
    "accent": (
        eccgui-color-var("identity", "accent", "900"),
        eccgui-color-mix(
            eccgui-color-var("identity", "accent", "900"),
            eccgui-color-var("identity", "text", "900") 10%
        ),
        eccgui-color-mix(eccgui-color-var("identity", "accent", "900"), eccgui-color-var("identity", "text", "900") 20%)
    ),
    "success": (
        eccgui-color-var("semantic", "success", "900"),
        eccgui-color-mix(
            eccgui-color-var("semantic", "success", "900"),
            eccgui-color-var("identity", "text", "900") 10%
        ),
        eccgui-color-mix(
            eccgui-color-var("semantic", "success", "900"),
            eccgui-color-var("identity", "text", "900") 20%
        )
    ),
    "warning": (
        eccgui-color-var("semantic", "warning", "900"),
        eccgui-color-mix(
            eccgui-color-var("semantic", "warning", "900"),
            eccgui-color-var("identity", "text", "900") 10%
        ),
        eccgui-color-mix(
            eccgui-color-var("semantic", "warning", "900"),
            eccgui-color-var("identity", "text", "900") 20%
        )
    ),
    "danger": (
        eccgui-color-var("semantic", "danger", "900"),
        eccgui-color-mix(
            eccgui-color-var("semantic", "danger", "900"),
            eccgui-color-var("identity", "text", "900") 10%
        ),
        eccgui-color-mix(eccgui-color-var("semantic", "danger", "900"), eccgui-color-var("identity", "text", "900") 20%)
    )
);

@import "~@blueprintjs/core/src/components/button/button";

@mixin eccgui-enhance-blueprint-button-intent($intentvalue) {
    &.#{$ns}-intent-#{$intentvalue} {
        @include pt-button-intent(map.get($button-intents, $intentvalue)...);

        &:not(.#{$ns}-disabled).#{$ns}-icon > svg {
            fill: eccgui-color-rgba($white, 0.7);
        }

        &:not(.#{$ns}-disabled):not(.#{$ns}-minimal):not(.#{$ns}-outlined) {
            @include pt-button-intent(map.get($button-intents, $intentvalue)...);
        }

        &:focus-visible {
            box-shadow: inset 0 0 0 $eccgui-size-inline-whitespace * 0.6
                #{eccgui-color-var("identity", "background", "100")} !important;
        }

        &.#{$ns}-minimal,
        &.#{$ns}-outlined {
            color: list.nth(map.get($button-intents, $intentvalue), 1);
            background: none;
            border-color: list.nth(map.get($button-intents, $intentvalue), 1);
            box-shadow: none;

            &:disabled,
            &.#{$ns}-disabled {
                color: eccgui-color-rgba(list.nth(map.get($button-intents, $intentvalue), 1), $eccgui-opacity-disabled);
                border-color: eccgui-color-rgba(
                    list.nth(map.get($button-intents, $intentvalue), 1),
                    $eccgui-opacity-disabled
                );
            }

            &:active:not(:disabled):not(.#{$ns}-disabled),
            &.#{$ns}-active:not(:disabled):not(.#{$ns}-disabled) {
                color: list.nth(map.get($button-intents, $intentvalue), 3);
                background-color: eccgui-color-rgba(
                    list.nth(map.get($button-intents, $intentvalue), 3),
                    $eccgui-opacity-ghostly
                );
                border-color: list.nth(map.get($button-intents, $intentvalue), 3);
            }

            &:focus:not(:disabled):not(.#{$ns}-disabled),
            &:hover:not(:disabled):not(.#{$ns}-disabled) {
                color: list.nth(map.get($button-intents, $intentvalue), 2);
                background-color: eccgui-color-rgba(
                    list.nth(map.get($button-intents, $intentvalue), 2),
                    0.5 * $eccgui-opacity-ghostly
                );
                border-color: list.nth(map.get($button-intents, $intentvalue), 2);
            }
        }
    }
}

.#{$ns}-button {
    position: relative;

    .#{$ns}-large {
        min-height: mini-units(6);
    }

    // special case override: blueprint do not use configured colors here
    @include eccgui-enhance-blueprint-button-intent("primary");
    @include eccgui-enhance-blueprint-button-intent("accent");
    @include eccgui-enhance-blueprint-button-intent("success");
    @include eccgui-enhance-blueprint-button-intent("warning");
    @include eccgui-enhance-blueprint-button-intent("danger");
}

.#{$ns}-button-text {
    min-width: 0;
}
