@use '../variables'as *;
@use '../mixins'as *;

$notification-width-small     :90vw;
$notification-width           : 350px;
$notification-z-index         : 1500;
$notification-background      : $component-background-default;
$notification-background-dark : $component-background-default-dark;
$nofitication-color           : $component-color-default;
$nofitication-color-muted     : $component-color-muted;
$nofitication-color-muted-dark: $component-color-muted-dark;

$nofitication-color-dark    : $component-color-default-dark;
$notification-border-radius : $border-radius-default;
$notification-shadow        : $shadow2;
$notification-margin        : $margin-global-small;
$notification-font-bold     : $text-weight-semi-bold;
$notification-font-normal   : $font-normal;
$notification-font-small    : $font-small;

$notification-color-accent     : $component-background-accent;
$notification-color-accent-dark: $component-background-accent-dark;

$notification-color-secondary     : $component-background-secondary;
$notification-color-secondary-dark: $component-background-secondary-dark;

$notification-color-success     : $component-background-success;
$notification-color-success-dark: $component-background-success-dark;

$notification-color-warning     : $component-background-warning;
$notification-color-warning-dark: $component-background-warning-dark;

$notification-color-error     : $component-background-error;
$notification-color-error-dark: $component-background-error-dark;

$notification-animation-duration: $animation-duration-default;
// HELPERS

@mixin base {
    .#{$prefix}-notification {
        @content;
    }
}

@mixin header {
    .#{$prefix}-notification-header {
        @content;
    }
}

@mixin body {
    .#{$prefix}-notification-body {
        @content;
    }
}

@mixin footer {
    .#{$prefix}-notification-footer {
        @content;
    }
}

@mixin icon {
    .#{$prefix}-notification-icon {
        @content;
    }
}

@mixin close {
    .#{$prefix}-notification-close {
        @content;
    }
}

@mixin title {
    .#{$prefix}-notification-title {
        @content;
    }
}

// MAIN
@mixin notification {
    @include base {
        width           : 100%;
        background-color: $notification-background;
        color           : $nofitication-color;
        border-radius   : $notification-border-radius;
        box-shadow      : $notification-shadow;
        opacity         : 0;
        margin          : $notification-margin;

        &.#{$prefix}-active {
            opacity: 1;
        }

        @include header() {
            @include component-padding-complex(header);
            display  : flex;
            flex-wrap: nowrap;
            font-size: $notification-font-normal;


            &:only-child {
                @include component-padding(normal, same);
            }

            @include icon() {
                margin-right: $notification-margin;
                flex        : 0 0 auto;
                order       : 1;
            }

            @include title {
                @include text-nowrap;
                margin-right: $notification-margin;
                font-weight : $notification-font-bold;
                flex        : 1 1 auto;
                order       : 2;


            }

            @include close() {
                flex : 0 0 auto;
                order: 3;
            }
        }

        @include body() {
            @include component-padding-complex(body);
            overflow: hidden;

            &>* {
                max-height: 150px;
                text-align: justify;
                overflow-y: auto;
            }
        }

        @include footer() {
            @include component-padding-complex(footer);
            display   : flex;
            flex-wrap : nowrap;
            overflow-y: auto;

            ul {
                margin : 0;
                padding: 0;

                li {
                    display: inline-block;

                    a {
                        text-decoration: none;
                        cursor         : pointer;
                        color          : $nofitication-color-muted;
                        padding        : $notification-margin;

                        &:hover {
                            @include text-shadow($nofitication-color-muted);
                        }
                    }

                    &:first-child a {
                        padding-left: 0;
                    }
                }
            }
        }
    }
}

@mixin notification-theme {
    @include base() {
        &.#{$prefix}-accent {
            background-color: $notification-color-accent;
            color           : $nofitication-color-dark;


            @include footer() {
                ul li a {
                    color: $nofitication-color-muted-dark;
                }
            }
        }

        &.#{$prefix}-secondary {
            background-color: $notification-color-secondary;
            color           : $nofitication-color-dark;


            @include footer() {
                ul li a {
                    color: $nofitication-color-muted-dark;
                }

            }
        }
    }
}

@mixin notification-theme-dark {
    @include mode-dark {
        @include base() {
            &.#{$prefix}-accent {
                background-color: $notification-color-accent-dark;
                color           : $nofitication-color-dark;


                @include footer() {
                    ul li a {
                        color: $nofitication-color-muted-dark;
                    }
                }
            }

            &.#{$prefix}-secondary {
                background-color: $notification-color-secondary-dark;
                color           : $nofitication-color-dark;


                @include footer() {
                    ul li a {
                        color: $nofitication-color-muted-dark;
                    }
                }
            }
        }
    }
}

@mixin notification-signal {
    @include base() {
        &.#{$prefix}-success {
            background-color: $notification-color-success;
            color           : $nofitication-color-dark;


            @include footer() {
                ul li a {
                    color: $nofitication-color-muted-dark;
                }
            }
        }

        &.#{$prefix}-warning {
            background-color: $notification-color-warning;
            color           : $nofitication-color-dark;


            @include footer() {
                ul li a {
                    color: $nofitication-color-muted-dark;
                }
            }
        }

        &.#{$prefix}-error {
            background-color: $notification-color-error;
            color           : $nofitication-color-dark;


            @include footer() {
                ul li a {
                    color: $nofitication-color-muted-dark;
                }
            }
        }
    }
}

@mixin notification-signal-dark {
    @include mode-dark {
        @include base() {
            &.#{$prefix}-success {
                background-color: $notification-color-success-dark;
                color           : $nofitication-color-dark;


                @include footer() {
                    ul li a {
                        color: $nofitication-color-muted-dark;
                    }
                }
            }

            &.#{$prefix}-warning {
                background-color: $notification-color-warning-dark;
                color           : $nofitication-color-dark;


                @include footer() {
                    ul li a {
                        color: $nofitication-color-muted-dark;
                    }
                }
            }

            &.#{$prefix}-error {
                background-color: $notification-color-error-dark;
                color           : $nofitication-color-dark;


                @include footer() {
                    ul li a {
                        color: $nofitication-color-muted-dark;
                    }
                }
            }
        }
    }
}

@mixin notification-dark() {
    @include mode-dark {
        @include base() {
            background-color: $notification-background-dark;
            color           : $nofitication-color-dark;

            @include footer() {
                ul li a {
                    color: $nofitication-color-muted-dark;
                }
            }
        }
    }
}

@mixin container() {
    .#{$prefix}-notification-container {
        position    : fixed;
        top         : 0;
        left        : 50%;
        transform   : translateX(-50%);
        width       : $notification-width-small;
        max-height  : 100vh;
        //overflow-y: auto;
        z-index     : $notification-z-index;
    }

    @include media-screen-min-small {
        .#{$prefix}-notification-container {
            width: $notification-width;
        }

    }

    @include media-screen-min-large {
        .#{$prefix}-notification-container {
            left        : auto;
            right       : 0;
            transform   : translateX(0%);
            margin-right: $notification-margin;
        }
    }
}

@mixin animation() {
    @include not-reduced-motion {
        .#{$prefix}-notification-animation-in {
            transform: scale(1, 1) translateY(0);
            opacity  : 1;

            animation: notificationIn $notification-animation-duration ease-out;
        }

        .#{$prefix}-notification-animation-out {
            transform: scale(0, 0) translateY(60%);
            opacity  : 0;
            animation: notificationOut $notification-animation-duration ease-out;
        }
    }


    @keyframes notificationIn {
        0% {
            opacity  : 0;
            transform: scale(0, 0) translateY(-60%);
        }

        80% {
            opacity  : 1;
            transform: scale(1.1, 1.1) translateY(0%);
        }

        100% {
            opacity  : 1;
            transform: scale(1, 1) translateY(0%);
        }
    }

    @keyframes notificationOut {
        0% {
            opacity  : 1;
            transform: scale(1, 1) translateY(0%);
        }

        100% {
            opacity  : 0;
            transform: scale(0, 0) translateY(60%);
        }
    }
}

@mixin definitions($options:()) {

    @include notification();

    @include container();

    @include animation();

    @if(not-option-disabled($options, 'theme')) {
        @include notification-theme();

        @if(not-option-disabled($options, 'dark')) {
            @include notification-theme-dark();
        }
    }

    @if(not-option-disabled($options, 'signal')) {
        @include notification-signal();

        @if(not-option-disabled($options, 'dark')) {
            @include notification-signal-dark();
        }
    }

    @if(not-option-disabled($options, 'dark')) {
        @include notification-dark();
    }
}