// TO-DO: Separar tudo o que for estilo estrutural do componente do que é estilo de tema
// levar todos os estilos estruturais para o arquivo de scss do componente
// na biblioteca  matcha-components

//  <button matcha-button size="tiny" color="primary">tiny</button>
//  <button matcha-button size="small" color="primary">small</button>
//  <button matcha-button size="medium" color="primary">medium</button>
//  <button matcha-button size="large" color="primary">large</button>
//  <button matcha-button size="huge" color="primary">huge</button>

// <button matcha-button
//  [color]="color"
//  [basic]="basic"
//  [size]="size"
//  [pill]="pill"
//  [outline]="outline"
//  [link]="link"
//  [icon]="icon"
//  [size-xs]="sizeXs"
//  [size-sm]="sizeSm"
//  [size-md]="sizeMd"
//  [size-lg]="sizeLg"
//  [size-xl]="sizeXl">

@mixin _disabled-solid-button($theme) {
    background: getDisabled($theme);
    color: getDisabledBgContrast($theme);
    box-shadow: 0 0 0 0px inset;
    pointer-events: none;
}

@mixin _disabled-basic-button($theme) {
    background: getSurface($theme);
    color: getDisabled($theme);
    box-shadow: 0 0 0 0px inset;
    pointer-events: none;
}

@mixin _disabled-outline-button($theme) {
    background: transparent;
    color: getDisabled($theme);
    box-shadow: 0 0 0 2px inset;
    pointer-events: none;
}

@mixin _disabled-alpha-button($theme) {
    background: getDisabledAlpha($theme);
    color: getDisabled($theme);
    box-shadow: 0 0 0 0px inset;
    pointer-events: none;
}

@mixin _disabled-link-button($theme) {
    background: transparent;
    color: getDisabled($theme);
    box-shadow: 0 0 0 0px inset;
    pointer-events: none;
}

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

            &[size#{$infix}="tiny"] {
                padding: 0 px-to-rem(32px);
                line-height: px-to-rem(20px);
                max-height: px-to-rem(32px);
            }

            &[size#{$infix}="small"] {
                padding: 0 px-to-rem(32px);
                line-height: px-to-rem(20px);
                max-height: px-to-rem(40px);
            }

            &[size#{$infix}="medium"] {
                padding: 0 px-to-rem(32px);
                line-height: px-to-rem(20px);
                max-height: px-to-rem(48px);
            }

            &[size#{$infix}="large"] {
                padding: 0 px-to-rem(32px);
                line-height: px-to-rem(20px);
                max-height: px-to-rem(56px);
            }

            &[size#{$infix}="huge"] {
                padding: 0 px-to-rem(32px);
                line-height: px-to-rem(20px);
                max-height: px-to-rem(56px);
            }
        }
    }
}

button[matcha-button],
a[matcha-button] {
    transition: all 50ms linear;
    overflow: hidden;
    position: relative;
    font-size: 16px;
    font-weight: 700;
    font-family: unset;
    height: 56px;
    appearance: auto;
    text-rendering: auto;
    letter-spacing: normal;
    word-spacing: normal;
    line-height: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    text-align: center;
    text-wrap: nowrap;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-sizing: border-box;
    border-radius: px-to-rem(8px);

    * {
        pointer-events: none;
    }

    &[size="tiny"],
    &[size="small"],
    &[size="medium"],
    &[size="large"],
    &[size="huge"] {
        // min-width: 24px;
    }

    @include generate-matcha-button-size-classes($helper-breakpoints);


    &:hover {
        filter: brightness(0.98);
    }

    &:active {
        filter: brightness(0.96);
    }

    &[disabled] {
        pointer-events: none;
    }

    &[basic]:not([basic="false"]) {
        box-shadow: 0px 0px 0px 0px inset;
    }

    &[outline]:not([outline="false"]) {
        box-shadow: 0px 0px 0px 2px inset;

        &[link]:not([link="false"]) {
            &[size="tiny"] {
                padding: 0px 8px;
                gap: 4px;
            }

            &[size="small"] {
                padding: 0px 12px;
                gap: 8px;
            }

            &[size="medium"] {
                padding: 0px 16px;
                gap: 12px;
            }

            &[size="large"] {
                padding: 0px 16px;
                gap: 12px;
            }

            &[size="huge"] {
                padding: 0px 16px;
                gap: 12px;
            }
        }
    }

    &[pill]:not([pill="false"]) {
        border-radius: 999px;
    }

    &[link]:not([link="false"]) {
        text-transform: initial;
        letter-spacing: 0;
        text-decoration: none;
        padding: 0;
    }

    &[icon]:not([icon="false"]) {
        aspect-ratio: 1;
        padding: 0 !important;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    &[badge]:not([badge="false"]) {
        overflow: visible;
        position: relative;

        &::after {
            content: "";
            position: absolute;
            top: -0.25rem;
            right: -0.25rem;
            width: 1.32rem;
            height: 1.32rem;
            border-radius: 999px;
            z-index: 2;
        }

        &[size="tiny"]::after {
            width: 0.75rem;
            height: 0.75rem;
            top: -0.15rem;
            right: -0.15rem;
        }

        &[size="small"]::after {
            width: 1rem;
            height: 1rem;
            top: -0.2rem;
            right: -0.2rem;
        }

        &[size="large"]::after {
            width: 1.5rem;
            height: 1.5rem;
            top: -0.3rem;
            right: -0.3rem;
        }

        &[size="huge"]::after {
            width: 1.65rem;
            height: 1.65rem;
            top: -0.34rem;
            right: -0.34rem;
        }
    }

    .ripple {
        position: absolute;
        border-radius: 999px;
        transform: scale(0);
        pointer-events: none;
    }

    .ripple.show {
        animation: ripple 400ms ease-out;
    }

    @keyframes ripple {
        0% {
            opacity: 0;
            transform: scale(0);
        }

        25% {
            opacity: 1;
        }

        100% {
            opacity: 0;
            transform: scale(2);
        }
    }
}

@mixin matcha-button-theme($theme) {
    $color-functions: (
        red: getRed,
        pink: getPink,
        purple: getPurple,
        deep-purple: getDeepPurple,
        indigo: getIndigo,
        blue: getBlue,
        light-blue: getLightBlue,
        cyan: getCyan,
        teal: getTeal,
        green: getGreen,
        light-green: getLightGreen,
        lime: getLime,
        yellow: getYellow,
        amber: getAmber,
        orange: getOrange,
        deep-orange: getDeepOrange,
        brown: getBrown,
        grey: getGrey,
        blue-grey: getBlueGrey,
        primary: getPrimary,
        accent: getAccent,
        success: getSuccess,
        warn: getWarn,
        danger: getDanger,
        info: getInfo,
        disabled: getDisabled,
    );

button[matcha-button],
a[matcha-button] {
    &:not([color]) .ripple {
        background: getForegroundAlpha($theme)
    }

    &[badge]:not([badge="false"]) {
        &::after {
            background: getAccent($theme);
        }
    }

    @each $colorName, $colorFn in $color-functions {

        // Background do ripple para outline e basic
        &[color="#{'' + $colorName}"][outline]:not([outline="false"]) .ripple,
        &[color="#{'' + $colorName}"][basic]:not([basic="false"]) .ripple {
            background: call(#{$colorFn}Alpha, $theme)
        }

        // Background e color do botão para alpha
        &[color="#{'' + $colorName}"][alpha]:not([alpha="false"]) {
            background: call(#{$colorFn}Alpha, $theme);
            color: call(#{$colorFn}, $theme);

            // Divider dentro do botão para alpha
            matcha-divider {
                .border-color-disabled {
                    border-color: call(#{$colorFn}, $theme) !important;
                    opacity: 0.3 !important;
                }
            }
        }

        // Color do botão para outline, link e basic
        &[color="#{'' + $colorName}"][outline]:not([outline="false"]),
        &[color="#{'' + $colorName}"][link]:not([link="false"]),
        &[color="#{'' + $colorName}"][basic]:not([basic="false"]) {
            color: call(#{$colorFn}, $theme);

            // Divider dentro do botão para outline, link e basic
            matcha-divider {
                .border-color-disabled {
                    border-color: call(#{$colorFn}, $theme) !important;
                    opacity: 0.3 !important;
                }
            }
        }

        // Background e color do botão para default
        &[color="#{'' + $colorName}"] {
            background: call(#{$colorFn}, $theme);
            color: call(#{$colorFn}Contrast, $theme);

            // Divider dentro do botão para default
            matcha-divider {
                .border-color-disabled {
                    border-color: call(#{$colorFn}Contrast, $theme) !important;
                    opacity: 0.3 !important;
                }
            }
        }

        // Ripple dentro do botão para default
        &[color="#{'' + $colorName}"] .ripple {
            background: call(#{$colorFn}ContrastAlpha, $theme)
        }


        &[disabled],
        &[disabled]:not([disabled="false"]),
        &[disabled="true"] {

            &[solid],
            &[solid]:not([solid="false"]),
            &[solid="true"] {
                @include _disabled-solid-button($theme);
            }

            &[outline],
            &[outline]:not([outline="false"]),
            &[outline="true"] {
                @include _disabled-outline-button($theme);
            }

            &[basic],
            &[basic]:not([basic="false"]),
            &[basic="true"] {
                @include _disabled-basic-button($theme);
            }

            &[alpha],
            &[alpha]:not([alpha="false"]),
            &[alpha="true"] {
                @include _disabled-alpha-button($theme);
            }

            &[link],
            &[link]:not([link="false"]),
            &[link="true"] {
                @include _disabled-link-button($theme);
            }
        }
    }
}

button[matcha-button],
a[matcha-button] {
    border: 0px solid currentColor;

    &[disabled] {
        background-color: getDisabled($theme);
        color: getDisabledBgContrast($theme);
        border-color: getDisabled($theme);
    }

    &[outline]:not([outline="false"]) {
        border: 0px solid currentColor;
        background: transparent;

        &:not([color]) {
            border-color: getForeground($theme);
            color: getForeground($theme);
        }

        &[disabled] {
            box-shadow: 0 0 0 2px getDisabledContrast($theme);
            color: getDisabledContrast($theme) !important;
        }
    }

    &[basic]:not([basic="false"]) {
        background: getSurface($theme);

        &:not([color]) {
            color: getForeground($theme);
        }

        &[disabled] {
            color: getDisabledContrast($theme) !important;
        }

        &[alpha]:not([alpha="false"]) {
            background: transparent;
        }
    }

    &[alpha]:not([alpha="false"]) {
        &:not([color]) {
            background: getForegroundAlpha($theme);
            border-color: getForeground($theme);
            color: getForeground($theme);
        }

        &[disabled] {
            background: getDisabledAlpha($theme);
        }
    }

    &[link]:not([link="false"]) {
        background-color: transparent;

        &:not([color]) {
            color: getForeground($theme);
        }
    }
}
}