// (C) 2007-2020 GoodData Corporation
@import "mixins";

/* Basic button variants
   ========================================================================== */

/* disable max length */
/* stylelint-disable max-line-length */

.gd-button {
    & + & {
        margin-left: 10px;
    }
}

.gd-button-primary,
.gd-button-secondary {
    @extend %btn;

    box-shadow: 0 1px 1px 0 $button-shadow-darker;
    color: $button-normal-color;
    background: $button-normal-bg;
    border-color: $button-normal-border-color;

    &:hover {
        box-shadow: 0 1px 1px 0 $button-shadow-darker, inset 0 -1px 0 0 $button-normal-hover-box-shadow;
        color: $gd-color-text;
        background: $button-normal-hover-bg;
        border-color: $button-normal-hover-border-color;
    }

    &:focus,
    &.is-focus {
        box-shadow: 0 0 3px 1px $button-normal-focus-shadow, 0 1px 2px 0 $button-shadow-darker,
            inset 0 -1px 0 0 $button-normal-hover-box-shadow;
        border-color: transparentize($gd-color-highlight, 0.25);
    }

    &:active,
    &.is-active {
        box-shadow: inset 0 1px 0 0 $button-normal-active-shadow;
        color: $gd-color-text;
        border-color: $button-normal-active-border-color;

        @include gradient-linear($button-normal-active-gradient-top, $button-normal-active-gradient-bottom);
    }
}

.gd-button-positive,
.gd-button-negative,
.gd-button-action {
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: $gd-color-text-light;

    &[class*="icon-"],
    .gd-button-icon {
        color: $gd-color-text-light;

        &,
        &:hover {
            &::before,
            &::after,
            .gd-button-icon {
                color: $gd-color-text-light;
            }
        }
    }
}

.gd-button-positive,
.gd-button-negative,
.gd-button-action,
.gd-button-primary {
    font-weight: 700;
}

.gd-button-positive {
    box-shadow: 0 1px 1px 0 $button-shadow-lighter;
    background: $gd-color-positive;

    @extend %btn;

    &:hover {
        box-shadow: 0 1px 1px 0 $button-shadow-darker, inset 0 -1px 0 0 rgba(0, 0, 0, 0.15);
        background: $button-positive-hover-bg;
    }

    &:focus {
        box-shadow: 0 0 3px 1px $button-positive-focus-shadow, 0 1px 1px 0 $button-shadow-darker,
            inset 0 -2px 0 0 rgba(0, 0, 0, 0.15);
    }

    &:active,
    &.is-active {
        box-shadow: inset 0 2px 0 0 rgba(0, 0, 0, 0.15);

        @include gradient-linear(
            $button-positive-active-gradient-top,
            $button-positive-active-gradient-bottom
        );
    }
}

.gd-button-negative {
    box-shadow: 0 1px 0 0 $button-shadow-lighter;
    background: $gd-color-negative;

    @extend %btn;

    &:hover {
        box-shadow: 0 1px 1px 0 $button-shadow-darker, inset 0 -1px 0 0 rgba(0, 0, 0, 0.15);
        background: $button-negative-hover-bg;
    }

    &:focus {
        box-shadow: 0 0 3px 1px $button-negative-focus-shadow, 0 1px 1px 0 $button-shadow-darker,
            inset 0 -1px 0 0 rgba(0, 0, 0, 0.15);
    }

    &:active,
    &.is-active {
        box-shadow: inset 0 2px 0 0 rgba(0, 0, 0, 0.15);

        @include gradient-linear(
            $button-negative-active-gradient-top,
            $button-negative-active-gradient-bottom
        );
    }
}

.gd-button-action {
    box-shadow: 1px 1px 0 $button-shadow-lighter;
    background: $gd-color-highlight;

    @extend %btn;

    &:hover {
        box-shadow: 0 1px 1px 0 $button-shadow-darker, inset 0 -1px 0 0 rgba(0, 0, 0, 0.15);
        background: $button-action-hover-bg;
    }

    &:focus {
        box-shadow: 0 0 3px 1px $button-action-focus-shadow, 0 1px 1px 0 $button-shadow-darker,
            inset 0 -1px 0 0 rgba(0, 0, 0, 0.15);
    }

    &:active,
    &.is-active {
        box-shadow: inset 0 2px 0 0 rgba(0, 0, 0, 0.15);

        @include gradient-linear($button-action-active-gradient-top, $button-action-active-gradient-bottom);
    }
}

/* Button links
   ========================================================================== */

.gd-button-link[class*="icon-"] {
    position: relative;
    padding-left: 32px;
}

.gd-button-link[class*="icon-"].icon-right {
    padding-left: 11px;
    padding-right: 30px;

    &::after {
        position: absolute;
        right: 5px;
        font-size: 18px;
    }
}

.gd-button-link {
    box-sizing: border-box;
    display: inline-flex;
    padding: 0 6px;
    border: 1px solid transparent;
    font: 400 14px/30px $gd-font-primary;
    vertical-align: middle;
    color: $button-action-color;
    background: none;
    cursor: pointer;

    @include transition(all, 0.25s, ease-in-out);

    > span {
        text-decoration: none;
    }

    &::before,
    &::after {
        position: absolute;
        top: 50%;
        width: 20px;
        transform: translateY(-50%);
        font-size: $button-icon-width;
        text-align: center;

        @include transition(color, 0.25s, ease-in-out);
    }

    &::before,
    &::after,
    .gd-button-icon {
        color: $button-action-color;
    }

    &::before {
        left: 6px;
    }

    &::after {
        right: 6px;
    }

    .gd-button-icon {
        width: 20px;
        margin: 0 6px;
        font-size: $button-icon-width;

        &:first-child {
            margin-left: 0;
        }

        &:last-child {
            margin-right: 0;
        }

        &:only-child {
            position: relative;
            left: -3px;
        }
    }

    &:hover,
    &:active,
    &.is-active {
        color: $button-action-color-hover;

        &::after,
        &::before,
        .gd-button-icon {
            color: $gd-color-highlight;
        }
    }

    &:focus {
        box-shadow: 0 0 3px 0 transparentize($gd-color-highlight, 0.8);
        color: $button-action-color;
        border-color: transparentize($gd-color-highlight, 0.7);
        border-radius: 2px;
    }

    &:hover,
    &:focus,
    &:active,
    &.is-active {
        .gd-button-text {
            text-decoration: underline;
        }
    }
}

.gd-button-link-dimmed {
    @extend .gd-button-link;

    color: $button-normal-color;

    &::before,
    &::after,
    .gd-button-icon {
        color: $gd-color-text-dimmed;
    }

    &.is-active,
    &:hover,
    &:focus,
    &:active {
        color: #000;
    }

    .gd-button-text {
        text-decoration: underline;
    }
}

.gd-button-link.gd-button-icon-only[class*="icon-"] {
    width: 31px;
    height: 29px;
    line-height: 27px;

    @extend .gd-button-primary;

    @include active-states-and-self {
        border: 0;
        box-shadow: none;
        background: none;
        padding-left: 0;
    }

    &.gd-button-small::before {
        font-size: $button-small-icon-width;
    }

    &::before,
    .gd-button-icon {
        color: $gd-color-link;
    }

    &:active {
        &::before,
        .gd-button-icon {
            color: $button-action-hover-bg;
        }
    }

    &:focus,
    &:hover {
        &::before,
        .gd-button-icon {
            color: $gd-color-highlight;
        }
    }

    &.disabled {
        @include active-states-and-self {
            &::before,
            .gd-button-icon {
                color: $gd-color-disabled;
            }
        }
    }
}

:not(button) {
    &.gd-button-link,
    &.gd-button-link-dimmed {
        line-height: 0.8;

        &:focus {
            outline: none;
            box-shadow: none;
            border-color: transparent;
        }
    }
}

.button-dropdown {
    font-weight: 400;

    &::after,
    &::before,
    .gd-button-icon {
        color: $gd-color-state-blank;
    }

    &:focus,
    &:hover,
    &:active,
    &.is-active {
        &::after,
        &::before,
        .gd-button-icon {
            color: $gd-color-link;
        }
    }
}

/* Button sizes
   ========================================================================== */

.gd-button-small {
    height: 27px;
    padding: 0 11px;
    line-height: 25px;
    font-size: 12px;

    &[class*="icon-"] {
        padding-left: 32px;

        &::before,
        &::after {
            width: 18px;
            font-size: 15px;

            @include transition(color, 0.25s, ease-in-out);
        }

        &::before {
            left: 9px;
        }

        &::after {
            right: 7px;
        }

        &.gd-button-icon-only {
            height: 27px;

            &::before {
                width: auto;
            }
        }
    }

    .gd-button-icon {
        width: $button-small-icon-width;
        height: $button-small-icon-width;
        line-height: $button-small-icon-width;
        font-size: $button-small-icon-width;
    }
}

.gd-button-important {
    height: 38px;
    padding: 7px 19px;
    line-height: 22px;
    font-size: 16px;
}

.gd-button.gd-button-icon-only {
    width: 31px;
    height: 29px;
    line-height: 27px;
    color: $button-normal-color;
    padding-left: 0;

    &::before {
        right: 0;
        left: 0;
        margin: 0;
        padding: 0;
        color: $button-normal-color;
        font-size: $button-small-icon-width;
    }

    &:hover {
        &::before,
        .gd-button-icon {
            color: $gd-color-highlight;
        }
    }
}

/* Button states
   ========================================================================== */

// refactor needed
// stylelint-disable-next-line no-duplicate-selectors
.gd-button {
    &.disabled {
        @include active-states-and-self {
            box-shadow: none;
            background: transparent;
            cursor: default;
            border-color: transparent;
            text-decoration: none;
        }
    }
}

// refactor needed
// stylelint-disable-next-line no-duplicate-selectors
.gd-button-primary,
.gd-button-secondary {
    &.disabled {
        cursor: default;

        @include active-states-and-self {
            color: $gd-color-disabled;
            background: transparentize($gd-color-light, 0.7);
            border-color: rgba(210, 219, 227, 0.75);

            &::before,
            &::after,
            .gd-button-icon {
                color: $gd-color-disabled;
            }
        }
    }
}

// refactor needed
// stylelint-disable-next-line no-duplicate-selectors
.gd-button-positive {
    &.disabled {
        cursor: default;

        @include active-states-and-self {
            color: $gd-color-text-light;
            background: $button-positive-disabled-bg;

            &::before,
            &::after,
            .gd-button-icon {
                color: $gd-color-text-light;
            }
        }
    }
}

// refactor needed
// stylelint-disable-next-line no-duplicate-selectors
.gd-button-negative {
    &.disabled {
        cursor: default;

        @include active-states-and-self {
            color: $gd-color-text-light;
            background: $button-negative-disabled-bg;

            &::before,
            &::after,
            .gd-button-icon {
                color: $gd-color-text-light;
            }
        }
    }
}

// refactor needed
// stylelint-disable-next-line no-duplicate-selectors
.gd-button-action {
    &.disabled {
        cursor: default;

        @include active-states-and-self {
            color: $gd-color-text-light;
            background: $button-action-disabled-bg;

            @include disable-filter();

            &::before,
            &::after,
            .gd-button-icon {
                color: $gd-color-text-light;
            }
        }
    }
}

// refactor needed
// stylelint-disable-next-line no-duplicate-selectors
.gd-button-link {
    &.disabled {
        cursor: default;
        $color: $button-normal-border-color;

        @include active-states-and-self {
            color: $color;
            border-color: transparent;

            > span {
                text-decoration: none;
            }
        }

        &::before,
        &::after,
        .gd-button-icon {
            color: $color;
        }
    }

    // refactor needed
    // stylelint-disable-next-line no-duplicate-selectors
    &.gd-button-icon-only[class*="icon-"] {
        &::before,
        &::after {
            right: 0;
            left: 0;
            margin: 0 auto;
            padding: 0;
        }
    }
}

.gd-button-group {
    .gd-button {
        position: relative;
        z-index: 1;
        margin: 0 -1px 0 0;

        @include border-radius(0);

        &:focus {
            z-index: 2;
        }

        &:not(:focus) {
            box-shadow: none;
        }
    }

    > .gd-button:first-child,
    > *:not(.gd-button):first-child .gd-button {
        @include border-radius(3px 0 0 3px);
    }

    > .gd-button:last-child,
    > *:not(.gd-button):last-child .gd-button {
        margin-right: 0;

        @include border-radius(0 3px 3px 0);
    }
}

/* Alternative markup support
   ========================================================================== */

a {
    &[class*="gd-button-"] {
        box-sizing: border-box;
        display: inline-block;

        &,
        &:hover,
        &:focus {
            text-decoration: none;
        }

        &,
        &:active {
            outline: none;
        }

        .gd-button-text {
            display: initial;
        }
    }

    &.gd-button-link,
    &.gd-button-link-dimmed {
        &:hover {
            .gd-button-text {
                text-decoration: underline;
            }
        }
    }
}
