@import '../constants/typography';
@import '../constants/layout';
@import '../constants/buttons';
@import '../mixins/buttons';

/**************************************
 * Buttons
 **************************************/

.btn {
    $bdl-btn-padding-vertical: 10px; // @deprecated Use flexbox or line-height instead in future implementation

    position: relative;
    display: inline-block;
    box-sizing: border-box;
    margin: 5px; // This causes problems for composition (breaking change needed to fix)
    padding: $bdl-btn-padding-vertical $bdl-btn-padding-horizontal;
    color: $bdl-gray-80;
    font-weight: bold;
    font-size: $bdl-fontSize;
    line-height: $bdl-btn-height - 2 * $bdl-btn-border-width - 2 * $bdl-btn-padding-vertical;
    letter-spacing: 0.035em;
    white-space: nowrap;
    text-align: center;
    text-decoration: none;
    text-shadow: none;
    vertical-align: top;
    background-color: $white;
    border-color: $bdl-gray-30;
    border-style: solid;
    border-width: $bdl-btn-border-width;
    border-radius: $bdl-border-radius-size-med;
    cursor: pointer;
    -webkit-transition:
        border-color linear 0.15s,
        box-shadow linear 0.15s,
        background-color linear 0.15s;
    transition:
        background-color 0.05s ease-in-out,
        border-color 0.05s ease-in-out;
    -webkit-appearance: none;
    zoom: 1;
    -webkit-font-smoothing: antialiased;

    &.bdl-btn--large {
        @include bdl-Button--large;
    }

    &.bdl-has-icon {
        // Buttons with icons use flexbox to align content instead of line-height/padding
        display: inline-flex;
        align-items: center;
        justify-content: center;
        height: $bdl-btn-height;
        padding: 0; // Content provides padding
        line-height: 0;

        .btn-content {
            margin-left: $bdl-btn-padding-horizontal;
        }

        .bdl-btn-icon {
            // Icon without text:
            margin: ($bdl-btn-height - $bdl-btn-icon-size) * 0.5 - $bdl-btn-border-width;

            // Icon with text:
            & + .btn-content {
                // Buttons with icons have a smaller margin on the icon side for optical alignment:
                margin-right: $bdl-grid-unit * 3;

                // Spacing between button and text:
                margin-left: $bdl-grid-unit * 2;
            }
        }

        &.bdl-btn--large {
            height: $bdl-btn-height-large;

            .bdl-btn-icon {
                margin: ($bdl-btn-height-large - $bdl-btn-icon-size) * 0.5 - $bdl-btn-border-width;
            }
        }
    }

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

    &:not(.bdl-is-disabled),
    &:not(.is-disabled) {
        &:hover {
            background-color: darken($white, 3%);
        }

        &:active {
            background-color: darken($white, 8%);
            border-color: $bdl-gray-30;
        }

        &:focus {
            border-color: $bdl-gray;
            box-shadow: 0 1px 2px fade-out($black, 0.9);
        }
    }

    &.bdl-is-disabled,
    &.is-disabled,
    &.is-loading {
        top: 0; /* prevents disabled button from being depressed on click */
        cursor: default;
    }

    &.is-loading {
        .btn-content,
        .bdl-btn-icon {
            visibility: hidden;
        }

        .btn-loading-indicator {
            position: absolute;
            top: 0;
            left: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 100%;
            height: 100%;
        }
    }

    &.bdl-is-disabled,
    &.is-disabled {
        box-shadow: none;
        opacity: 0.4;
    }
}

// TODO: :hover/:active should inherit styles instead of specifying
// This would be a breaking change to fix
.btn-plain,
.btn-plain:hover,
.btn-plain:active {
    margin: 0;
    padding: 0;
    font-weight: normal;
    border: none;
    cursor: pointer;
}

.btn-plain,
.btn-plain:hover,
.btn-plain:active,
.btn-plain:focus {
    background: transparent;
    box-shadow: none;
}

.btn-plain[aria-disabled] {
    cursor: default;
}

/* This setting is being used to override the dotted border on a firefox button */
button.btn-plain::-moz-focus-inner {
    border: 0 none;
}

button svg {
    pointer-events: none;
}

.btn-primary {
    color: $white;
    background-color: $primary-color;
    border-color: $primary-color;
    -webkit-font-smoothing: antialiased;

    &:not(.bdl-is-disabled),
    &:not(.is-disabled) {
        &:focus {
            background-color: lighten($primary-color, 8%);
            border: $bdl-btn-border-width solid $primary-color;
            box-shadow: $bdl-btn-primary-box-shadow;
        }

        &:hover {
            background-color: lighten($primary-color, 8%);
            border-color: lighten($primary-color, 8%);
        }

        &:active {
            background-color: darken($primary-color, 8%);
            border-color: darken($primary-color, 8%);
            box-shadow: none;
        }
    }

    &.is-loading {
        .btn-content,
        .bdl-btn-icon {
            background-color: $bdl-gray-30;
        }
    }
}
