@import "../variables/variables";
@import "../mixins/private/button-mixins";
@import "../mixins/private/token-mixins";

button.btn,
a.fake-btn {
    background-color: transparent;
    border-radius: var(--btn-border-radius, calc($button-height-regular / 2));
    color: inherit;
    display: inline-block;
    font-size: var(--font-size-default);
    min-height: $button-height-regular;
    min-width: 88px;
    padding: $button-padding-vertical $button-padding-horizontal;

    @include btn-base();
}

button.btn[disabled],
button.btn[aria-disabled="true"] {
    @include border-color-token(
        expand-btn-disabled-border-color,
        color-stroke-disabled
    );
    @include color-token(
        expand-btn-disabled-foreground-color,
        color-foreground-disabled
    );
}

a.fake-btn:not([href]),
a.fake-btn[aria-disabled="true"] {
    @include color-token(
        link-foreground-color-disabled,
        color-foreground-disabled
    );
}

button.btn--borderless,
a.fake-btn--borderless {
    border-color: transparent;
    min-width: auto;
    padding-left: 0;
    vertical-align: initial;

    &:focus,
    &:hover {
        background-color: transparent;
        outline: none;
        text-decoration: underline;
    }
}

button.btn--borderless[disabled],
a.fake-btn--borderless[disabled],
button.btn--borderless[aria-disabled="true"],
a.fake-btn--borderless[aria-disabled="true"] {
    border-color: transparent;
}

button.btn--borderless.btn--destructive,
a.fake-btn--borderless.btn--destructive {
    @include color-token(
        btn-secondary-destructive-foreground-color,
        color-foreground-attention
    );
}

button.btn--slim,
a.fake-btn--slim {
    height: $button-height-regular;
    min-width: auto;
    padding-left: var(--spacing-100);
    padding-right: var(--spacing-100);
}

a.fake-btn:visited {
    color: inherit;
}

button.btn--fluid,
a.fake-btn--fluid {
    width: 100%;
}

.btn__cell,
.fake-btn__cell {
    justify-content: center;

    @include btn-cell-base();
    @include btn-cell-fixed-height();
    @include btn-cell-truncated();
}

button.btn--form .btn__cell,
a.fake-btn--form .fake-btn__cell,
button.btn--borderless .btn__cell,
a.fake-btn--borderless .fake-btn__cell {
    justify-content: space-between;
}

button.btn svg.icon,
a.fake-btn svg.icon {
    @include btn-icon-base();
}

button.btn__cell--fixed-height svg.icon,
a.fake-btn__cell--fixed-height svg.icon {
    align-self: center;
    height: 1rem;
    overflow: visible;
    width: 1rem;
}

button.btn--primary,
a.fake-btn--primary {
    @include background-color-token(
        btn-primary-background-color,
        color-background-accent
    );
    @include border-color-token(btn-primary-border-color, color-stroke-accent);
    @include color-token(
        btn-primary-foreground-color,
        color-foreground-on-accent
    );

    @include btn-animations();

    font-weight: bold;
}

a.fake-btn--primary {
    outline-color: var(
        --color-foreground-primary
    ); /* fixes invisible focus outline in Firefox */
}

a.fake-btn--primary:visited {
    @include color-token(
        btn-primary-foreground-color,
        color-foreground-on-accent
    );
}

button.btn--primary:not([disabled], [aria-disabled="true"]),
a.fake-btn--primary[href] {
    &:focus,
    &:hover {
        background-blend-mode: multiply;
        filter: brightness(96%);
    }

    &:active {
        filter: brightness(92%);
    }
}

button.btn--primary.btn--destructive,
a.fake-btn--primary.fake-btn--destructive {
    @include background-color-token(
        btn-primary-destructive-background-color,
        color-background-attention
    );
    @include border-color-token(
        btn-primary-destructive-border-color,
        color-stroke-attention
    );
    @include color-token(
        btn-primary-destructive-foreground-color,
        color-foreground-on-attention
    );

    font-weight: bold;
}

button.btn--primary.btn--destructive[disabled],
button.btn--primary.btn--destructive[aria-disabled="true"] {
    @include background-color-token(
        btn-primary-destructive-disabled-background,
        color-background-disabled
    );
    @include border-color-token(
        btn-primary-destructive-disabled-border,
        color-stroke-disabled
    );
}

button.btn--primary.btn--destructive:not([disabled], [aria-disabled="true"]),
a.fake-btn--primary.fake-btn--destructive[href] {
    &:focus,
    &:hover {
        background-color: var(--color-state-attention-hover);
    }

    &:active {
        background-color: var(--color-state-attention-active);
    }
}

button.btn .progress-spinner {
    height: 24px;
    margin: -4px 0;
    width: 24px;
}

button.btn--form .progress-spinner {
    margin-left: auto;
    margin-right: auto;
}

button.btn--primary .progress-spinner {
    --color-spinner-icon-background: var(--color-background-primary);
    --color-spinner-icon-foreground: #8fa3f8; /* 40% of white on top of --color-foreground-on-accent */
}

button.btn--primary.btn--destructive .progress-spinner {
    --color-spinner-icon-background: var(--color-foreground-on-accent);
    --color-spinner-icon-foreground: #ec7089;
}

button.btn[aria-expanded="true"] svg.icon--12,
a.fake-btn[aria-expanded="true"] svg.icon--12 {
    transform: rotate(180deg);
}

button.btn--large svg.icon,
a.fake-btn--large svg.icon {
    max-height: $button-height-large - ($button-padding-vertical-large * 2);
}

button.btn--small svg.icon,
a.fake-btn--small svg.icon {
    max-height: $button-height-small - ($button-padding-vertical-small * 2);
}

button.btn--primary[disabled],
button.btn--primary[aria-disabled="true"] {
    @include background-color-token(
        btn-primary-disabled-background-color,
        color-foreground-disabled
    );
    @include border-color-token(
        btn-primary-disabled-border-color,
        color-foreground-disabled
    );
    @include color-token(
        btn-primary-foreground-color,
        color-foreground-on-accent
    );

    svg.icon {
        @include fill-token(
            btn-primary-disabled-foreground-color,
            color-background-primary
        );
    }
}

a.fake-btn--primary:not([href]),
a.fake-btn--primary[aria-disabled="true"] {
    @include background-color-token(
        btn-primary-disabled-background-color,
        color-foreground-disabled
    );
    @include border-color-token(
        btn-primary-disabled-border-color,
        color-foreground-disabled
    );
    @include color-token(
        btn-primary-foreground-color,
        color-foreground-on-accent
    );
}

button.btn--secondary,
a.fake-btn--secondary {
    background-color: var(--btn-secondary-background-color, transparent);
    @include border-color-token(
        btn-secondary-border-color,
        color-stroke-accent
    );
    @include color-token(
        btn-secondary-foreground-color,
        color-foreground-accent
    );

    @include btn-animations();
}

a.fake-btn--secondary:visited {
    @include color-token(
        btn-secondary-foreground-color,
        color-foreground-accent
    );
}

button.btn--secondary:not([disabled], [aria-disabled="true"]),
a.fake-btn--secondary[href] {
    &:active {
        background-color: var(--color-state-primary-active);
        border-color: var(--color-state-active-foreground-on-secondary);
        color: var(--color-state-active-foreground-on-secondary);
    }

    &:hover,
    &:focus {
        background-color: var(--color-state-primary-hover);
        border-color: var(--color-state-hover-foreground-on-secondary);
        color: var(--color-state-hover-foreground-on-secondary);
    }
}

button.btn--secondary.btn--destructive,
a.fake-btn--secondary.fake-btn--destructive {
    background-color: var(
        --btn-secondary-destructive-background-color,
        transparent
    );
    @include border-color-token(
        btn-secondary-destructive-border-color,
        color-stroke-attention
    );
    @include color-token(
        btn-secondary-destructive-foreground-color,
        color-foreground-attention
    );
}

button.btn--secondary.btn--destructive:not([disabled], [aria-disabled="true"]),
a.fake-btn--secondary.fake-btn--destructive[href] {
    &:hover,
    &:focus {
        background-color: var(--color-state-primary-hover);
        border-color: var(
            --color-state-hover-foreground-on-secondary-desctructive
        );
        color: var(--color-state-hover-foreground-on-secondary-desctructive);
    }

    &:active {
        background-color: var(--color-state-primary-active);
        border-color: var(
            --color-state-active-foreground-on-secondary-desctructive
        );
        color: var(--color-state-active-foreground-on-secondary-desctructive);
    }
}

button.btn--secondary.btn--destructive .progress-spinner {
    --color-spinner-icon-background: #f39fb0;
    --color-spinner-icon-foreground: #e0103a;
}

button.btn--secondary[disabled],
button.btn--secondary[aria-disabled="true"] {
    @include background-color-token(
        btn-secondary-disabled-background-color,
        color-background-primary
    );
    @include border-color-token(
        btn-secondary-disabled-border-color,
        color-stroke-disabled
    );
    @include color-token(
        btn-secondary-disabled-foreground-color,
        color-background-disabled
    );

    svg.icon {
        @include fill-token(
            btn-secondary-disabled-foreground-color,
            color-foreground-disabled
        );
    }
}

a.fake-btn--secondary:not([href]),
a.fake-btn--secondary[aria-disabled="true"] {
    @include border-color-token(
        btn-secondary-disabled-border-color,
        color-background-disabled
    );
    @include color-token(
        btn-secondary-disabled-foreground-color,
        color-background-disabled
    );
}

button.btn--tertiary,
a.fake-btn--tertiary {
    @include border-color-token(
        btn-tertiary-border-color,
        color-stroke-default
    );

    @include btn-animations();
}

button.btn--tertiary:not([disabled], [aria-disabled="true"]),
a.fake-btn--tertiary[href] {
    &:focus,
    &:hover {
        background-color: var(--color-state-secondary-hover);
    }

    &:active {
        background-color: var(--color-state-secondary-active);
    }
}

button.btn--tertiary[disabled],
button.btn--tertiary[aria-disabled="true"]:not(
        [aria-live="polite"][aria-disabled="true"]
    ),
a.fake-btn--tertiary:not([href]),
a.fake-btn--tertiary[aria-disabled="true"] {
    @include color-token(
        btn-tertiary-disabled-foreground-color,
        color-background-disabled
    );
    @include border-color-token(
        expand-btn-disabled-border-color,
        color-stroke-disabled
    );
}

button.btn--tertiary.btn--destructive,
a.fake-btn--tertiary.fake-btn--destructive {
    @include border-color-token(
        btn-tertiary-destructive-foreground-color,
        color-stroke-subtle
    );
}

button.btn--tertiary.btn--destructive:not([disabled], [aria-disabled="true"]),
a.fake-btn--tertiary.fake-btn--destructive[href] {
    &:focus,
    &:hover {
        background-color: var(--color-state-secondary-hover);
    }

    &:active {
        background-color: var(--color-state-secondary-active);
    }
}

button.btn--tertiary.btn--destructive[disabled],
button.btn--tertiary.btn--destructive[aria-disabled="true"] {
    @include color-token(
        btn-tertiary-destructive-disabled-foreground-color,
        color-foreground-disabled
    );
}

button.btn--tertiary.btn--destructive .progress-spinner {
    --color-spinner-icon-background: #ee9aab;
    --color-spinner-icon-foreground: #e0103a;
}

button.btn--large,
a.fake-btn--large {
    @include btn-large();
}

button.btn--small,
a.fake-btn--small {
    border-radius: var(--btn-border-radius, calc($button-height-small / 2));
    font-size: var(--font-size-default);
    min-height: $button-height-small;
    padding: $button-padding-vertical-small $button-padding-horizontal-small;
}

button.btn--form,
a.fake-btn--form {
    border-color: inherit;
    max-width: 100%;
    @include border-radius-token(expand-btn-border-radius, border-radius-50);
}

button.btn--form:not([disabled], [aria-disabled="true"]),
a.fake-btn--form:not([href]) {
    &:hover,
    &:focus {
        background-color: var(--color-state-primary-hover);
    }

    &:active {
        background-color: var(--color-state-primary-active);
    }
}

button.btn--form.btn--large {
    padding: $button-padding-vertical-large $button-padding-horizontal-large;
}

button.btn--form.btn--small {
    padding: $button-padding-vertical-small $button-padding-horizontal-small;
}

button.btn--transparent,
a.fake-btn--transparent {
    background-color: transparent;

    &:hover,
    &:focus {
        background-color: transparent;
    }
}

button.btn--fixed-height,
a.fake-btn--fixed-height {
    padding-top: calc(21.5px - 0.75em);
}

button.btn--large-fixed-height,
a.fake-btn--large-fixed-height {
    height: $button-height-large;
    min-height: $button-height-large;
    padding-top: calc(27px - 0.75em);
}

button.btn--truncated,
a.fake-btn--truncated {
    @include btn-truncate();
}

button.btn--large-truncated,
a.fake-btn--large-truncated {
    font-size: var(--font-size-medium);
    height: $button-height-large;
    min-height: $button-height-large;
    padding: $button-padding-vertical-large $button-padding-horizontal;

    @include btn-truncate();
}

button.btn--split-start,
a.fake-btn--split-start {
    border-radius: 24px 0 0 24px;
}

button.btn--split-end,
a.fake-btn--split-end {
    border-radius: 0 24px 24px 0;
    margin-left: -1px;
    min-width: 40px;
    padding-left: 8px;
    padding-right: 8px;
}

button.btn.btn--tertiary.btn--split-end,
a.fake-btn.fake-btn--tertiary.fake-btn--split-end {
    margin-left: -2px;
}

button.btn.btn--primary.btn--split-end,
a.fake-btn.fake-btn--primary.fake-btn--split-end {
    @include border-left-color-token(
        btn-primary-border-split-color,
        color-background-primary
    );
    &:hover,
    &:focus {
        @include border-left-color-token(
            btn-primary-border-split-color,
            color-background-primary
        );
    }
}

button.btn--floating-label {
    padding-bottom: 0;
    padding-top: 0;
}

button.btn--floating-label .btn__text {
    min-height: 19px;
    padding-bottom: 2px;
    padding-top: 17px;
}

button.btn--floating-label .btn__floating-label {
    align-self: flex-start;
    display: inline-block;
    overflow: hidden;
    padding-bottom: 2px;
    padding-top: 17px;
    pointer-events: none;
    position: absolute;
    text-align: left;
    text-overflow: ellipsis;
    transform: scale(0.75, 0.75) translate(0, -18px);
    transform-origin: left;
    white-space: nowrap;
    width: calc(100% - 24px);
    z-index: 1;
}

button.btn--floating-label .btn__floating-label--animate {
    transition:
        transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1),
        bottom 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

button.btn--floating-label .btn__floating-label--inline {
    font-size: 0.875rem;
    position: unset;
    transform: translate(0, -6px);
}

[dir="rtl"] {
    button.btn--split-start,
    a.fake-btn--split-start {
        border-radius: 0 24px 24px 0;
    }

    button.btn--split-end,
    a.fake-btn--split-end {
        border-radius: 24px 0 0 24px;
        margin-left: inherit;
        margin-right: -1px;
    }

    button.btn.btn--tertiary.btn--split-end,
    a.fake-btn.fake-btn--tertiary.fake-btn--split-end {
        margin-right: -2px;
    }

    button.btn.btn--primary.btn--split-end,
    a.fake-btn.fake-btn--primary.fake-btn--split-end {
        @include border-left-color-token(
            btn-primary-border-color,
            color-stroke-accent
        );
        @include border-right-color-token(
            primary-border-split-color,
            color-stroke-subtle
        );

        &:hover,
        &:focus {
            @include border-left-color-token(
                btn-primary-border-color,
                color-stroke-accent
            );
            @include border-right-color-token(
                primary-border-split-color,
                color-stroke-subtle
            );
        }
    }
}
