@use '../variables'as *;
@use '../mixins'as *;

$link-color-muted      : $component-color-muted;
$link-color-muted-dark : $component-color-muted-dark;
$link-color-accent     : $component-background-accent-muted;
$link-color-secondary  : $component-background-secondary-muted;
$link-color-error      : $component-background-error-muted;
$link-color-warning    : $component-background-warning-muted;
$link-color-success    : $component-background-success-muted;

$link-color-accent-dark    : $component-background-accent-dark-muted;
$link-color-secondary-dark : $component-background-secondary-dark-muted;
$link-color-error-dark     : $component-background-error-dark-muted;
$link-color-warning-dark   : $component-background-warning-dark-muted;
$link-color-success-dark   : $component-background-success-dark-muted;

$link-transition-time : $animation-duration-short;

@mixin link {
    .#{$prefix}-link {
        text-decoration: none;
        color          : $link-color-muted;
        position       : relative;
        cursor         : pointer;

        &:before {
            content         : "";
            position        : absolute;
            width           : 100%;
            height          : 1px;
            background-color: $link-color-muted;
            bottom          : 0px;
            left            : 50%;
            transform       : translateX(-50%) scale(0, 1);
            bottom          : -1px;

        }

        &:hover {
            &:before {
                transform: translateX(-50%) scale(1, 1);
            }
        }

        &:focus {
            outline: none;

            //font-weight: $text-weight-semi-bold;
            &:not(:hover) {
                &:before {
                    transform: translateX(-80%) scale(0.4, 1);
                }
            }

        }
    }
}

@mixin link-dark {
    .#{$prefix}-dark {
        .#{$prefix}-link {
            color: $link-color-muted-dark;

            &:before {
                background-color: $link-color-muted-dark;
            }
        }
    }
}

@mixin link-theme {
    .#{$prefix}-link {
        &.#{$prefix}-accent {
            color: $link-color-accent;
        }

        &.#{$prefix}-secondary {
            color: $link-color-secondary;
        }

        &:visited {
            &.#{$prefix}-accent {
                color: $link-color-accent;

                &:before {
                    background-color: $link-color-accent;
                }

            }

            &.#{$prefix}-secondary {
                color: $link-color-secondary;

                &:before {
                    background-color: $link-color-secondary;
                }
            }
        }
    }
}

@mixin link-theme-dark {
    @include mode-dark {
        .#{$prefix}-link {
            &.#{$prefix}-accent {
                color: $link-color-accent-dark;
            }

            &.#{$prefix}-secondary {
                color: $link-color-secondary-dark;
            }

            &:visited {
                &.#{$prefix}-accent {
                    color: $link-color-accent-dark;

                    &:before {
                        background-color: $link-color-accent-dark;
                    }

                }

                &.#{$prefix}-secondary {
                    color: $link-color-secondary-dark;

                    &:before {
                        background-color: $link-color-secondary-dark;
                    }
                }
            }
        }
    }
}

@mixin link-signals {
    .#{$prefix}-link {
        &.#{$prefix}-error {
            color: $link-color-error;

            &:before {
                background-color: $link-color-error;
            }
        }

        &.#{$prefix}-warning {
            color: $link-color-warning;

            &:before {
                background-color: $link-color-warning;
            }
        }

        &.#{$prefix}-success {
            color: $link-color-success;

            &:before {
                background-color: $link-color-success;
            }
        }

        &:visited {
            &.#{$prefix}-error {
                color: $link-color-error;
            }

            &.#{$prefix}-warning {
                color: $link-color-warning;
            }

            &.#{$prefix}-success {
                color: $link-color-success;
            }
        }
    }
}

@mixin link-signals-dark {
    @include mode-dark {
        .#{$prefix}-link {
            &.#{$prefix}-error {
                color: $link-color-error-dark;

                &:before {
                    background-color: $link-color-error-dark;
                }
            }

            &.#{$prefix}-warning {
                color: $link-color-warning-dark;

                &:before {
                    background-color: $link-color-warning-dark;
                }
            }

            &.#{$prefix}-success {
                color: $link-color-success-dark;

                &:before {
                    background-color: $link-color-success-dark;
                }
            }

            &:visited {
                &.#{$prefix}-error {
                    color: $link-color-error-dark;
                }

                &.#{$prefix}-warning {
                    color: $link-color-warning-dark;
                }

                &.#{$prefix}-success {
                    color: $link-color-success-dark;
                }
            }
        }
    }
}

@mixin link-print {
    .#{$prefix}-print {
        .#{$prefix}-link {
            color: $component-print-color;
        }
    }
}

@mixin link-no-transition {
    body:not(.#{$prefix}-no-transitions) {
        .#{$prefix}-link {
            &:before {
                transition: transform $link-transition-time ease-in;
            }

        }
    }
}

@mixin definitions($options:()) {
    @include link();

    @if(not-option-disabled($options, 'dark')) {
        @include link-dark();
    }

    @if(not-option-disabled($options, 'print')) {
        @include link-print();
    }

    @if(not-option-disabled($options, 'theme')) {
        @include link-theme();

        @if(not-option-disabled($options, 'dark')) {
            @include link-theme-dark();
        }
    }

    @if(not-option-disabled($options, 'signal')) {
        @include link-signals();

        @if(not-option-disabled($options, 'dark')) {
            @include link-signals-dark();
        }
    }

    @if(not-option-disabled($options, 'animation')) {
        @include link-no-transition();
    }

}