@use '../variables'as *;
@use '../mixins'as *;

$button-background-default               : $component-background-default;
$button-background-default-active        : $component-background-shade;
$button-background-default-active-dark   : $component-background-shade-dark;
$button-background-inverse               : $component-background-default;
$button-background-shade                 : $component-background-shade;
$button-background-shade-active          : $component-background-shade-active;
$button-background-shade-dark            : $component-background-shade-dark;
$button-background-shade-dark-active     : $component-background-shade-dark-active;
$button-background-default-dark          : $component-background-default-dark;
$button-background-inverse-dark          : $component-background-default-dark;
// Accent
$button-background-accent                : $component-background-accent;
$button-background-accent-hover          : $component-background-accent-hover;
$button-background-accent-active         : $component-background-accent-active;
// Accent dark
$button-background-accent-dark           : $component-background-accent-dark;
$button-background-accent-dark-hover     : $component-background-accent-dark-hover;
$button-background-accent-dark-active    : $component-background-accent-dark-active;
// Secondary
$button-background-secondary             : $component-background-secondary;
$button-background-secondary-hover       : $component-background-secondary-hover;
$button-background-secondary-active      : $component-background-secondary-active;
// Secondary dark
$button-background-secondary-dark        : $component-background-secondary-dark;
$button-background-secondary-dark-hover  : $component-background-secondary-dark-hover;
$button-background-secondary-dark-active : $component-background-secondary-dark-active;
// Error
$button-background-error                 : $component-background-error;
$button-background-error-hover           : $component-background-error-hover;
$button-background-error-active          : $component-background-error-active;
// Error dark
$button-background-error-dark            : $component-background-error-dark;
$button-background-error-dark-hover      : $component-background-error-dark-hover;
$button-background-error-dark-active     : $component-background-error-dark-active;
// Warning
$button-background-warning               : $component-background-warning;
$button-background-warning-hover         : $component-background-warning-hover;
$button-background-warning-active        : $component-background-warning-active;
// Warning dark
$button-background-warning-dark          : $component-background-warning-dark;
$button-background-warning-dark-hover    : $component-background-warning-dark-hover;
$button-background-warning-dark-active   : $component-background-warning-dark-active;
// Success
$button-background-success               : $component-background-success;
$button-background-success-hover         : $component-background-success-hover;
$button-background-success-active        : $component-background-success-active;
// Success dark
$button-background-success-dark          : $component-background-success-dark;
$button-background-success-dark-hover    : $component-background-success-dark-hover;
$button-background-success-dark-active   : $component-background-success-dark-active;
// Disabled
$button-color-disabled                   : $component-background-shade-active;
$button-color-disabled-dark              : $component-background-shade-dark-active;
$button-color-default                    : $component-color-default;
$button-color-inverse                    : $component-color-inverse;
$button-color-default-dark               : $component-color-default-dark;
$button-color-inverse-dark               : $component-color-inverse-dark;
$button-border-color                     : $component-border-default; //$component-color-muted;
$button-border-color-hover               : $component-border-default-hover; //$component-color-default;
$button-border-color-active              : $component-border-default-active;
$button-border-color-dark                : $component-border-default-dark; //$component-color-muted-dark;
$button-border-color-hover-dark          : $component-border-default-hover-dark; //$component-color-default-dark;
$button-border-color-active-dark         : $component-border-default-active-dark;
$button-outline                          : $outline-default;
$button-line-height                      : $line-height;
$button-font-size                        : $font-normal;
$button-disabled-border-style            : $component-disabled-border-style;

@mixin button {

    .#{$prefix}-button {
        @include component-padding($size: normal, $wide: true);
        display                         : inline-flex;
        align-items                     : center;
        justify-content                 : center;
        background-color                : transparent;
        border                          : 1px solid transparent;
        border-radius                   : $border-radius-default;
        color                           : $button-color-default;
        font-size                       : $button-font-size;
        line-height                     : $button-line-height;
        text-align                      : center;
        vertical-align                  : middle;
        text-decoration                 : none;
        margin                          : 0px;
        box-sizing                      : border-box;
        font-family                     : $font-family;


        // background-color: var(--color-light-lighten);
        @include createHighlight($radius: $border-radius-default);

        cursor: pointer;

        &.#{$prefix}-large {
            @include component-padding(large);
        }

        &.#{$prefix}-small {
            @include component-padding($size: small, $wide: true);
        }

        &.#{$prefix}-fill {
            display: block;
            width  : 100%;
        }

        &.#{$prefix}-default {
            color           : $button-color-default;
            background-color: transparent;
            border-color    : $button-border-color;
        }

        &.#{$prefix}-shade {
            background-color: $button-background-shade;
            color           : $button-color-default;
            border-color    : $button-background-shade;
        }

        &.#{$prefix}-disabled {
            color         : $button-color-disabled !important;
            border-color  : $button-color-disabled !important;
            border-style  : $button-disabled-border-style !important;
            pointer-events: none;
            user-select   : none;

        }

        &.#{$prefix}-rounded {
            border-radius                   : $border-radius-round;
            @include updateHighlight($radius: $border-radius-round);
        }

        &.#{$prefix}-circle {
            border-radius                   : 100px;
            @include updateHighlight($radius: 100px);
        }

        &:hover,
        &:focus:not(:hover) {
            background-color   : $button-background-shade;
            // color           : $button-color-default;

            outline: none !important;

            &.#{$prefix}-default {
                border-color    : $button-border-color-hover;
                background-color: transparent;
            }

            &.#{$prefix}-disabled {
                background-color: transparent;
            }
        }

        &:active {
            background-color: $button-background-shade-active;
            outline         : none !important;

            &.#{$prefix}-shade {
                background-color: $button-background-shade-active;
            }

            &.#{$prefix}-default {
                border-color       : $button-border-color-active;
                background-color   : transparent;
                // background-color: $button-background-default-active;
            }
        }

        &:focus {
            outline: none !important;
        }

    }

    .#{$prefix}-inverse,
    .#{$prefix}-accent,
    .#{$prefix}-secondary,
    .#{$prefix}-error,
    .#{$prefix}-warning,
    .#{$prefix}-success {
        @include not-light-component {
            .#{$prefix}-button {
                color                          : $button-color-default-dark;
                @include updateHighlight($color: $highlight-color);
                user-select                    : none;

                &.#{$prefix}-default {
                    color           : $button-color-default-dark;
                    background-color: transparent;
                    border-color    : $button-border-color-dark;
                }

                &.#{$prefix}-shade {
                    background-color: $button-background-shade-dark;
                    color           : $button-color-default-dark;
                    border-color    : $button-background-shade-dark;
                }

                &:hover,
                &:focus:not(:hover) {
                    background-color: $button-background-shade-dark;

                    &.#{$prefix}-default {
                        color           : $button-color-default-dark;
                        border-color    : $button-border-color-hover-dark;
                        background-color: transparent;
                    }
                }

                &:active {
                    background-color: $button-background-shade-dark-active;

                    &.#{$prefix}-default {
                        color           : $button-color-default-dark;
                        border-color    : $button-border-color-active-dark;
                        background-color: $button-background-default-active-dark;
                    }

                    &.#{$prefix}-shade {
                        background-color: $button-background-shade-dark-active;
                    }
                }
            }
        }
    }
}

@mixin button-theme {

    .#{$prefix}-button,
    .#{$prefix}-icon-button {
        &.#{$prefix}-accent {
            background-color               : $button-background-accent !important;
            color                          : $button-color-inverse;
            border-color                   : $button-background-accent;
            @include updateHighlight($color: $highlight-color);

        }

        &.#{$prefix}-secondary {
            background-color               : $button-background-secondary !important;
            color                          : $button-color-inverse;
            border-color                   : $button-background-secondary;
            @include updateHighlight($color: $highlight-color);
        }

        &:hover,
        &:focus:not(:hover) {
            &.#{$prefix}-accent {
                background-color: $button-background-accent-hover !important;
                border-color    : $button-background-accent-hover;
            }

            &.#{$prefix}-secondary {
                background-color: $button-background-secondary-hover !important;
                border-color    : $button-background-secondary-hover;
            }
        }

        &:active {
            &.#{$prefix}-accent {
                background-color: $button-background-accent-active !important;
                border-color    : $button-background-accent-active;
            }

            &.#{$prefix}-secondary {
                background-color: $button-background-secondary-active !important;
                border-color    : $button-background-secondary-active;
            }
        }
    }
}

@mixin button-theme-dark {
    @include mode-dark {

        .#{$prefix}-button,
        .#{$prefix}-icon-button {
            &.#{$prefix}-accent {
                background-color               : $button-background-accent-dark !important;
                color                          : $button-color-inverse;
                border-color                   : $button-background-accent-dark;
                @include updateHighlight($color: $highlight-color);

            }

            &.#{$prefix}-secondary {
                background-color               : $button-background-secondary-dark !important;
                color                          : $button-color-inverse;
                border-color                   : $button-background-secondary-dark;
                @include updateHighlight($color: $highlight-color);
            }

            &:hover,
            &:focus:not(:hover) {
                &.#{$prefix}-accent {
                    background-color: $button-background-accent-dark-hover !important;
                    border-color    : $button-background-accent-dark-hover;
                }

                &.#{$prefix}-secondary {
                    background-color: $button-background-secondary-dark-hover !important;
                    border-color    : $button-background-secondary-dark-hover;
                }
            }

            &:active {
                &.#{$prefix}-accent {
                    background-color: $button-background-accent-dark-active !important;
                    border-color    : $button-background-accent-dark-active;
                }

                &.#{$prefix}-secondary {
                    background-color: $button-background-secondary-dark-active !important;
                    border-color    : $button-background-secondary-dark-active;
                }
            }
        }
    }
}

@mixin button-signals {

    .#{$prefix}-button,
    .#{$prefix}-icon-button {
        &.#{$prefix}-success {
            background-color               : $button-background-success !important;
            color                          : $button-color-inverse;
            @include updateHighlight($color: $highlight-color);
        }

        &.#{$prefix}-error {
            background-color               : $button-background-error !important;
            color                          : $button-color-inverse;
            border-color                   : $button-background-error;
            @include updateHighlight($color: $highlight-color);
        }

        &.#{$prefix}-warning {
            background-color               : $button-background-warning !important;
            color                          : $button-color-inverse;
            border-color                   : $button-background-warning;
            @include updateHighlight($color: $highlight-color);
        }

        &:hover,
        &:focus:not(:hover) {

            &.#{$prefix}-success {
                background-color: $button-background-success-hover !important;
                border-color    : $button-background-success-hover;
            }

            &.#{$prefix}-error {
                background-color: $button-background-error-hover !important;
                border-color    : $button-background-error-hover;
            }

            &.#{$prefix}-warning {
                background-color: $button-background-warning-hover !important;
                border-color    : $button-background-warning-hover;
            }
        }

        &:active {
            &.#{$prefix}-error {
                background-color: $button-background-error-active !important;
                border-color    : $button-background-error-active;

            }

            &.#{$prefix}-warning {
                background-color: $button-background-warning-active !important;
                border-color    : $button-background-warning-active;

            }

            &.#{$prefix}-success {
                background-color: $button-background-success-active !important;
                border-color    : $button-background-success-active;

            }
        }
    }
}

@mixin button-signals-dark {
    @include mode-dark {

        .#{$prefix}-button,
        .#{$prefix}-icon-button {
            &.#{$prefix}-success {
                background-color               : $button-background-success-dark !important;
                color                          : $button-color-inverse;
                border-color                   : $button-background-success-dark;
                @include updateHighlight($color: $highlight-color);
            }

            &.#{$prefix}-error {
                background-color               : $button-background-error-dark !important;
                color                          : $button-color-inverse;
                border-color                   : $button-background-error-dark;
                @include updateHighlight($color: $highlight-color);
            }

            &.#{$prefix}-warning {
                background-color               : $button-background-warning-dark !important;
                color                          : $button-color-inverse;
                border-color                   : $button-background-warning-dark;
                @include updateHighlight($color: $highlight-color);
            }

            &:hover,
            &:focus:not(:hover) {

                &.#{$prefix}-success {
                    background-color: $button-background-success-dark-hover !important;
                    border-color    : $button-background-success-dark-hover;
                }

                &.#{$prefix}-error {
                    background-color: $button-background-error-dark-hover !important;
                    border-color    : $button-background-error-dark-hover;
                }

                &.#{$prefix}-warning {
                    background-color: $button-background-warning-dark-hover !important;
                    border-color    : $button-background-warning-dark-hover;
                }
            }

            &:active {
                &.#{$prefix}-error {
                    background-color: $button-background-error-dark-active !important;
                    border-color    : $button-background-error-dark-active;

                }

                &.#{$prefix}-warning {
                    background-color: $button-background-warning-dark-active !important;
                    border-color    : $button-background-warning-dark-active;

                }

                &.#{$prefix}-success {
                    background-color: $button-background-success-active !important;
                    border-color    : $button-background-success-active;

                }
            }
        }
    }
}

@mixin button-dark {
    @include mode-dark {
        .#{$prefix}-button {
            color                          : $button-color-default-dark;
            @include updateHighlight($color: $highlight-color);

            &.#{$prefix}-default {
                color           : $button-color-default-dark;
                background-color: transparent;
                border-color    : $button-border-color-dark;
            }

            &.#{$prefix}-shade {
                background-color: $button-background-shade-dark;
                color           : $button-color-default-dark;
                border-color    : $button-background-shade-dark;
            }

            &.#{$prefix}-disabled {
                color       : $button-color-disabled-dark !important;
                border-color: $button-color-disabled-dark !important;
            }

            &:hover,
            &:focus:not(:hover) {
                background-color: $button-background-shade-dark;

                &.#{$prefix}-default {
                    color           : $button-color-default-dark;
                    background-color: transparent;
                    border-color    : $button-border-color-hover-dark;
                }

                &.#{$prefix}-shade {

                    color       : $button-color-default-dark;
                    border-color: $button-background-shade-dark;
                }
            }

            &:active {

                background-color: $button-background-shade-dark-active;

                &.#{$prefix}-default {
                    color       : $button-color-default-dark;
                    border-color: $button-border-color-active-dark;
                }

                &.#{$prefix}-shade {
                    background-color: $button-background-shade-dark-active;
                }
            }
        }

        .#{$prefix}-inverse {
            .#{$prefix}-button {
                &.#{$prefix}-default {
                    color       : $button-color-default;
                    border-color: $button-border-color;
                }

                &.#{$prefix}-shade {
                    background-color: $button-background-shade;
                    color           : $button-color-default;
                    border-color    : $button-background-shade;
                }

                &:hover,
                &:focus:not(:hover) {
                    &.#{$prefix}-default {
                        color       : $button-color-default;
                        border-color: $button-border-color-hover;
                    }
                }

                &:active {
                    &.#{$prefix}-default {
                        color           : $button-color-default;
                        border-color    : $button-border-color-active;
                        background-color: $button-background-default-active;
                    }

                    &.#{$prefix}-shade {
                        background-color: $button-background-shade-active;
                    }
                }
            }

        }
    }

}

@mixin button-print {
    .#{$prefix}-print {
        .#{$prefix}-button {
            border          : $component-print-border;
            color           : $component-print-color;
            background-color: $component-print-background;
        }
    }
}

@mixin button-print-signal {
    @include mode-print {

        .#{$prefix}-button,
        .#{$prefix}-icon-button {

            &.#{$prefix}-success,
            &.#{$prefix}-warning,
            &.#{$prefix}-error {
                border          : $component-print-border;
                color           : $component-print-color !important;
                background-color: $component-print-background;
            }

            &:hover,
            &:focus:not(:hover) {

                &.#{$prefix}-success,
                &.#{$prefix}-error,
                &.#{$prefix}-warning {
                    border          : $component-print-border;
                    color           : $component-print-color !important;
                    background-color: $component-print-background;
                }
            }

            &:active {

                &.#{$prefix}-error,
                &.#{$prefix}-warning,
                &.#{$prefix}-success {
                    border          : $component-print-border;
                    color           : $component-print-color !important;
                    background-color: $component-print-background
                }
            }
        }
    }
}

@mixin button-print-theme {
    @include mode-print {

        .#{$prefix}-button,
        .#{$prefix}-icon-button {

            &.#{$prefix}-accent,
            &.#{$prefix}-secondary {
                border          : $component-print-border;
                color           : $component-print-color !important;
                background-color: $component-print-background;

            }

            &:hover,
            &:focus:not(:hover) {

                &.#{$prefix}-accent,
                &.#{$prefix}-secondary {
                    border          : $component-print-border;
                    color           : $component-print-color !important;
                    background-color: $component-print-background;
                }
            }

            &:active {

                &.#{$prefix}-accent,
                &.#{$prefix}-secondary {
                    border          : $component-print-border;
                    color           : $component-print-color !important;
                    background-color: $component-print-background;
                }
            }
        }
    }
}

@mixin button-nav {
    .#{$prefix}-button-nav {
        display       : inline-flex;
        flex-direction: row;

        &>* {
            border-radius: 0;

            &:not(:first-child) {
                //border-left-color: transparent;
                margin-left: -1px;
            }

            &:first-child {
                border-top-left-radius   : 4px;
                border-bottom-left-radius: 4px;
            }

            &:last-child {
                border-top-right-radius   : 4px;
                border-bottom-right-radius: 4px;
            }
        }
    }
}

@mixin definitions($options: ()) {
    @include button();


    @if(not-option-disabled($options, 'print')) {
        @include button-print();
    }

    @if(not-option-disabled($options, 'dark')) {
        @include button-dark();
    }

    @if(not-option-disabled($options, 'signal')) {
        @include button-signals();

        @if(not-option-disabled($options, 'dark')) {
            @include button-signals-dark();
        }

        @if(not-option-disabled($options, 'print')) {
            @include button-print-signal();
        }
    }

    @if(not-option-disabled($options, 'theme')) {
        @include button-theme();

        @if(not-option-disabled($options, 'dark')) {
            @include button-theme-dark();
        }

        @if(not-option-disabled($options, 'print')) {
            @include button-print-theme();
        }
    }

    @if(not-option-disabled($options, 'nav')) {
        @include button-nav();
    }


}