// @import './elevation';
@import './helpers/color-functions';
@import './helpers/ripple';


/*         */
/* BUTTONS */
/*         */


@function default-button-config_() {
    @return (
        font-color: '',
        is-flat: 'false',
        is-raised: 'true',
        radius: 100%,

        // Primary flat button.
        base-color: $primary-button-color,
        opacity: 0.09,

        // Chartreuse flat button.
        // base-color: #64DD17,
        // opacity: 0.32,

        // Black flat button.
        // base-color: #000,
        // opacity: 0.06,
    );
}

@mixin immaterial-button($config: ()) {
    $config: map-merge(default-button-config_(), $config);

    $base-color: map-get($config, base-color);
    $font-color: map-get($config, font-color);
    $is-flat: map-get($config, is-flat);
    $is-raised: map-get($config, is-raised);
    $opacity: map-get($config, opacity);
    $radius: map-get($config, radius);

    $accent-color: #000000;

    @if map-has-key($config, accent-color) {
        $accent-color: map-get($config, accent-color);
    } @else {
        $reverse-text: is-reverse-text($base-color);
        @if ($reverse-text == 'yes') {
            $accent-color: #FFFFFF;
        }
    }

    @if ($font-color == '') {
        $font-color: $accent-color;
    }

    $flat: false;
    @if $is-flat == true or
    $is-flat == "true" or
    $is-flat == 'true' or
    $is-flat == 1 {
        $flat: true;
    }

    $raised: false;
    @if ($flat == false) {
        @if $is-raised == true or
        $is-raised == "true" or
        $is-raised == 'true' or
        $is-raised == 1 {
            $raised: true;
        }
    }

    // @if ($raised == true) {
    //     content: 'rY';
    // } @else {
    //     content: 'rN';
    // }

    background-color: $base-color;
        @if ($flat == true) { background: transparent; }
    border: none;
    border-radius: 2px;
    box-sizing: border-box;
    color: $font-color;
        @if ($flat == true) { color: $base-color; }
    cursor: pointer;
    display: inline-block;
    height: 36px;
    margin: 6px;
    min-width: 96px;
    outline: none;
    padding: 6px 16px;
    position: relative;
    text-decoration: none;
    text-align: center;
    text-transform: uppercase;
    transition: box-shadow 0.2s cubic-bezier(0.4, 0, 1, 1);
    will-change: box-shadow;
    z-index: 1;

    @include typography-button-text();

    -moz-osx-font-smoothing: grayscale;
    -webkit-appearance: none;
    -webkit-box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;

    -webkit-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;

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

        @if ($raised == true) { @include z-depth(2); }
    }

    &:active {
        outline: none;
    }

    &::-moz-focus-inner {
        border: 0;
        padding: 0;
    }

    &:disabled {
        @if ($flat != true) {
          background-color: rgba(0, 0, 0, 0.12);
        }

        box-shadow: none;
        color: rgba(0, 0, 0, 0.38);
        cursor: default;
        pointer-events: none;

        &::before,
        &::after {
            display: none;
        }
    }

    &:not(:disabled) {
        --ripple-surface-width: 0;
        --ripple-surface-height: 0;
        --ripple-foreground-size: 0;
        --ripple-left: 0;
        --ripple-top: 0;
        --ripple-foreground-scale: 1;
        --ripple-foreground-translate-end: 0;
        --ripple-foreground-translate-start: 0;

        will-change: transform, opacity;
        -webkit-tap-highlight-color: transparent;

        &:not(.has-js) {
            &::before {
                background-color: transparent;
                content: '';
                left: -6px;
                position: absolute;
                top: -6px;
                bottom: -6px;
                right: -6px;
            }

            &::after {
                @if ($flat == true) {
                    background-color: transparentize($base-color, (1 - $opacity));
                } @else {
                    background-color: transparentize($accent-color, (1 - $opacity));
                }
                border-radius: 2px;
                bottom: 0;
                content: '';
                left: 0;
                opacity: 0;
                position: absolute;
                right: 0;
                top: 0;
                transition: opacity 250ms linear, z-index 250ms linear;
                z-index: -1;
            }

            &:hover,
            &:focus {
                &::after {
                    opacity: 0.6;
                    transition-duration: 83ms;
                }
            }

            &:active {
                &::after {
                    $offset: (1 - $opacity);

                    @if ($flat == true) {
                        background-color: transparentize($base-color, ($offset * $offset));
                    } @else {
                        background-color: transparentize($accent-color, ($offset * $offset));
                    }

                    opacity: 0.64;
                    z-index: 3;
                }
            }
        }

        &.has-js {
            &::before {
                @if ($flat == true) {
                    background-color: transparentize($base-color, (1 - $opacity));
                } @else {
                    background-color: transparentize($accent-color, (1 - $opacity));
                }

                border-radius: 50%;
                content: '';
                height: $radius * 2;
                left: calc(50% - #{$radius});
                opacity: 0;
                pointer-events: none;
                position: absolute;
                top: calc(50% - #{$radius});
                transform: scale(0);
                transition: opacity 250ms linear;
                width: $radius * 2;

                /* @alternate */
                height: $radius * 2;
                left: calc(50% - #{$radius});
                top: calc(50% - #{$radius});
                transform: scale(var(--ripple-foreground-scale, 0));
                width: $radius * 2;
            }

            &:hover::before {
              opacity: 0.6;
            }

            &.ripple--background-focused::before {
                opacity: .99999;
            }

            &.ripple--background-active-fill::before {
                opacity: 1;
                transition-duration: 120ms;
            }

            &.ripple--unbounded::before {
                /* @alternate */
                height: $radius;
                height: var(--ripple-foreground-size, $radius);

                /* @alternate */
                left: calc(50% - #{$radius / 2});
                left: var(--ripple-left, calc(50% - #{$radius / 2}));

                /* @alternate */
                top: calc(50% - #{$radius / 2});
                top: var(--ripple-top, calc(50% - #{$radius / 2}));

                /* @alternate */
                transform: scale(0);
                transform: scale(var(--ripple-foreground-scale, 0));

                /* @alternate */
                width: $radius;
                width: var(--ripple-foreground-size, $radius);
            }

            &::after {
                @if ($flat == true) {
                    background-color: transparentize($base-color, (1 - $opacity));
                } @else {
                    background-color: transparentize($accent-color, (1 - $opacity));
                }

                border-radius: 50%;
                content: '';
                height: $radius * 2;
                left: calc(50% - #{$radius});
                opacity: 0;
                pointer-events: none;
                position: absolute;
                top: calc(50% - #{$radius});
                transform: scale(0);
                transform-origin: center center;
                transition: opacity 250ms linear;
                width: $radius * 2;

                /* @alternate */
                height: $radius;
                height: var(--ripple-foreground-size, $radius);

                left: 0;

                top: 0;

                /* @alternate */
                width: $radius;
                width: var(--ripple-foreground-size, $radius);
            }

            &:not(.ripple--unbounded)::after {
                transform-origin: center center;
            }

            &.ripple--unbounded::after {
                /* @alternate */
                height: $radius;
                height: var(--ripple-foreground-size, $radius);

                /* @alternate */
                left: 0;
                left: var(--ripple-left, 0);

                /* @alternate */
                top: 0;
                top: var(--ripple-top, 0);

                transform: scale(0);
                transform-origin: center center;

                /* @alternate */
                width: $radius;
                width: var(--ripple-foreground-size, $radius);
            }

            &.ripple--foreground-activation::after {
                animation: 300ms ripple-fg-radius-in forwards,
                            83ms ripple-fg-opacity-in forwards;
            }
            &.ripple--foreground-deactivation::after {
                animation: 83ms ripple-fg-opacity-out;
                // Retain transform from ripple-fg-radius-in activation
                transform: translate(var(--ripple-foreground-translate-end, 0))
                            scale(var(--ripple-foreground-scale, 1));
            }
        }
    }

    .btn-icon {
        display: inline-block;
        font-size: 18px;
        height: 18px;
        line-height: inherit;
        margin-right: 8px;
        vertical-align: top;
        width: 18px;
    }
}

.btn-primary {
    @include immaterial-button();

    &-flat {
        @include immaterial-button((
            // Primary flat button.
            base-color: $primary-button-color,
            opacity: 0.21,
            is-flat: 'true',
        ));
    }
}

// .btn-primary-flat {
//
// }

.btn-danger {
    @include immaterial-button((
        // Primary flat button.
        base-color: $danger-button-color,
        opacity: 0.12,
    ));

    &-flat {
        @include immaterial-button((
            // Primary flat button.
            base-color: $danger-button-color,
            opacity: 0.2,
            is-flat: 'true',
        ));
    }
}
