/*
How to use
@import '~matcha-ds/assets/scss/components/matcha-progress-bar.scss';
@include matcha-progress-bar($theme);
*/

@mixin keyframes($animation-name) {
    @-webkit-keyframes #{$animation-name} {
        @content;
    }

    @-moz-keyframes #{$animation-name} {
        @content;
    }

    @keyframes #{$animation-name} {
        @content;
    }
}

@mixin generate-matcha-progress-bar-size-classes($helper-breakpoints) {
    @each $breakpoint, $materialBreakpoint in $helper-breakpoints {
        @include media-breakpoint($materialBreakpoint) {
            $infix: if($materialBreakpoint ==null, "", "-#{$breakpoint}");

            &[size#{$infix}="tiny"] {
                .progress {
                    height: px-to-rem(8px);
                }
            }

            &[size#{$infix}="small"] {
                .progress {
                    height: px-to-rem(16px);
                }
            }

            &[size#{$infix}="medium"] {
                .progress {
                    height: px-to-rem(32px);
                }
            }
        }
    }

    &:not([size]) {
        .progress {
            height: px-to-rem(4px);
        }
    }
}

@mixin matcha-progress-bar-theme($theme) {
    matcha-progress-bar:not([color]) {

        .determinate,
        .indeterminate {
            background-color: getAccent($theme);
        }
    }

    matcha-progress-bar {

        .matcha-progress-bar {
            overflow: hidden;
            border-radius: px-to-rem(8px);
        }

        .progress {
            position: relative;
            display: block;
            width: 100%;
            background-color: getDisabled($theme);
            border-radius: px-to-rem(2px);
            background-clip: padding-box;
            overflow: hidden;

            .progress-text {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 0.75rem;
                font-weight: 600;
                pointer-events: none;
                white-space: nowrap;
            }

            .progress-text-bg {
                color: getForeground($theme);
                z-index: 1;
            }

            .progress-text-fg {
                color: getDisabled($theme);
                z-index: 3;
                transition: clip-path 0.3s linear;
            }

            .determinate {
                position: absolute;
                top: 0;
                bottom: 0;
                left: 0;
                transition: width 0.3s linear;
                z-index: 2;
            }

            .indeterminate {
                &:before {
                    content: '';
                    position: absolute;
                    background-color: inherit;
                    top: 0;
                    left: 0;
                    bottom: 0;
                    will-change: left, right;
                    animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
                }

                &:after {
                    content: '';
                    position: absolute;
                    background-color: inherit;
                    top: 0;
                    left: 0;
                    bottom: 0;
                    will-change: left, right;
                    animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
                    animation-delay: 1.15s;
                }
            }
        }

        // Informative card styles
        .progress-info-card {
            border-radius: 8px;
            width: 100%;
            display: block;
        }

        @include generate-matcha-progress-bar-size-classes($helper-breakpoints);
    }

    @include keyframes(indeterminate) {
        0% {
            left: -35%;
            right: 100%;
        }

        60% {
            left: 100%;
            right: -90%;
        }

        100% {
            left: 100%;
            right: -90%;
        }
    }

    @include keyframes(indeterminate-short) {
        0% {
            left: -200%;
            right: 100%;
        }

        60% {
            left: 107%;
            right: -8%;
        }

        100% {
            left: 107%;
            right: -8%;
        }
    }
}


matcha-progress-bar {
    display: flex;
    width: 100%;
    border-radius: px-to-rem(8px);

    .matcha-progress-bar {
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
    }
}

.progress {
    overflow: hidden;
}