@import 'helpers/animation';


@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,
    );
}


.fab {
    // --ripple-fg-size: 0;
    // --ripple-fg-scale: 1;
    // --ripple-fg-translate-end: 0;
    // --ripple-fg-translate-start: 0;

    --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;

    text-decoration: none;
    will-change: transform, opacity;

    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);

    &:not(.has-js) {
        &:hover::before,
        &:focus::before,
        &:active::after {
            opacity: 0.6;
            transition-duration: 85ms;
        }
    }

    @include z-depth(6);

    background-color: $secondary-color;
    border: none;
    border-radius: 50%;
    box-sizing: border-box;
    color: $fab-color;  // Was 'text-primary-on-secondary'.
    cursor: pointer;
    display: inline-flex;
    fill: currentColor;
    height: 56px;
    justify-content: center;
    overflow: hidden;
    padding: 0;
    position: relative;
    transition:
        box-shadow 280ms $animation-standard-curve-timing-function,
        opacity 15ms linear 30ms,
        animation-enter(transform, $fab-icon-enter-duration_ + $fab-icon-enter-delay_);
    user-select: none;
    width: 56px;

    -webkit-appearance: none;
       -moz-appearance: none;
            appearance: none;

    &:hover,
    &:focus {
        @include z-depth(8);
    }

    &:active {
        @include z-depth(12);
    }

    &:active,
    &:focus {
        outline: none;
    }

    &:hover {
        cursor: pointer;
    }

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

    // Allows for using SVGs within them to align properly in all browsers.
    // Can remove once: https://bugzilla.mozilla.org/show_bug.cgi?id=1294515 is resolved.
    > svg {
        width: 100%;
    }

    $config: map-merge(default-button-config_(), $fab-light-ripple-config);

    $base-color: map-get($config, base-color);
    $opacity: map-get($config, opacity);
    $pseudo: map-get($config, pseudo);
    $radius: map-get($config, radius);

    &::before {
        background-color: rgba($base-color, $opacity);
        border-radius: 50%;
        content: '';
        height: $radius * 2;
        left: calc(50% - #{$radius});
        opacity: 0;
        pointer-events: none;
        position: absolute;
        top: calc(50% - #{$radius});
        transition: opacity 250ms linear;
        width: $radius * 2;
    }

    &.has-js::before {
      top: calc(50% - #{$radius});
      left: calc(50% - #{$radius});
      width: $radius * 2;
      height: $radius * 2;

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

    &.ripple--background-focused::before {
      opacity: 0.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 {
        background-color: rgba($base-color, $opacity);
        border-radius: 50%;
        content: '';
        height: $radius * 2;
        left: calc(50% - #{$radius});
        opacity: 0;
        pointer-events: none;
        position: absolute;
        top: calc(50% - #{$radius});
        transition: opacity 250ms linear;
        width: $radius * 2;
    }

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

            left: 0;
            opacity: 0;
            top: 0;
            transform: scale(0);
            transform-origin: center center;

            /* @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));
    }

    &:not(.has-js) {
        -webkit-tap-highlight-color: rgba(0, 0, 0, .18);
    }
}

.fab-mini {
    height: 40px;
    width: 40px;
}

.fab__icon {
    align-items: center;
    display: flex;
    justify-content: center;
    transition: animation-enter(transform, $fab-icon-enter-duration_, $fab-icon-enter-delay_);
    width: 100%;
    will-change: transform;
}

.fab-exited {
    opacity: 0;
    transform: scale(0);
    transition:
        opacity 15ms linear 150ms,
        animation-exit-permanent(transform, 180ms);

    .fab__icon {
        transform: scale(0);
        transition: animation-exit-permanent(transform, 135ms);
    }
}
