@import '../abstracts/variables';

.slider {
    color: var(--palette-text-primary);
    display: inline-block;
    width: 100%;
    user-select: none;

    & > .typography {
        margin-top: 10px;
    }

    &.slider-vertical {
        transform: rotate(270deg);
        height: 100%;
        width: unset;
    }

    .slider-input {
        -webkit-appearance: none;
        -moz-appearance: none;
        position: relative;
        display: block;
        width: 100%;
        background-color: transparent;
        cursor: pointer;

        &:focus {
            outline: none;
        }

        &:active {
            & + .slider-value-label {
                opacity: 1;
            }
        }

        @include slider-track {
            border-radius: var(--default-borderradius);
            width: 100%;
        }


        @include slider-thumb {
            appearance: none;
            -webkit-appearance: none;
            border: none;
            border-radius: 50%;
            cursor: pointer;
            transition: box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
        }

        &:disabled {
            cursor: default;
            opacity: 0.38;

            @include slider-track {
                background-color: var(--palette-text-disabled);
            }

            @include slider-thumb {
                background-color: rgb( 0, 0, 0);
                color: rgb(255, 255, 255);
                box-shadow: 0 0 0 1px rgb( 255, 255, 255) !important;
                transform: scale(4, 4);

                &:hover {
                    box-shadow: 0 0 0 1px rgb( 255, 255, 255) !important;
                }
            }
        }
    }

    @each $color in $palette-colors {
        &.slider-#{$color} {
            .slider-filled {
                background-color: var(--palette-#{$color});
            }

            .slider-track-tick {
                background-color: var(--palette-#{$color});
            }

            .slider-value-label {
                color: var(--palette-#{$color}-text);
                background-color: var(--palette-#{$color});
            }


            .slider-input {
                @include slider-track {
                    background-color: rgba(var(--palette-#{$color}-rgb), 0.30);
                }

                @include slider-thumb {
                    background-color: var(--palette-#{$color});
                    box-shadow: 0px 1px 2px -1px rgba(var(--palette-#{$color}-rgb),0.3);
                }

                @include slider-thumb {
                    &:hover {
                        box-shadow: 0px 1px 2px -1px rgba(var(--palette-#{$color}-rgb),0.3),0 0 0 1px rgba(var(--palette-#{$color}-rgb), 0.24);
                    }
                }


                &:active, &:focus-visible {
                    @include slider-thumb {
                        box-shadow: 0px 1px 2px -1px rgba(var(--palette-#{$color}-rgb),0.3),0 0 0 2px rgba(var(--palette-#{$color}-rgb), 0.24);
                    }
                }
            }
        }
    }

    $slider-sizes: ("small": 2, "medium": 4, "large": 6);
    $tickcount: 50;
    $margincount: 10;
    $thumbscale: 6;

    @each $size, $value in $slider-sizes {
        &.slider-#{$size} {
            .slider-filled {
                height: #{$value}px;
            }

            .slider-track-tick {
                width: #{$value}px;
                height: #{$value}px;
            }

            .slider-track-tick-label {
                transform: translateX(-50%) translateY(#{$tickcount + "%"});
            }

            .slider-input {
                @include slider-track {
                    height: #{$value}px;
                    margin: #{$margincount}px 0;
                }

                @include slider-thumb {
                    height: #{$value}px;
                    width: #{$value}px;
                    transform: scale(#{$thumbscale}, #{$thumbscale});
                }
            }
        }

        $tickcount: $tickcount + 30;
        $margincount: $margincount + 2;
        $thumbscale: $thumbscale - 1;
    }



    .slider-container {
        position: relative;
        width: 100%;
        display: flex;
        align-content: center;
    }

    .slider-filled {
        border-radius: var(--default-borderradius);
    }

    .slider-inner-container {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
    }

    .slider-value-label {
        position: absolute;
        top: 0;
        transform: translateX(-50%) translateY(-125%);
        padding: 4px 8px;
        text-align: center;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        border-radius: 2px;
        line-height: normal;
        opacity: 0;
        transition: opacity .2s ease-in-out;
        pointer-events: none;
        user-select: none;
    }

    .slider-tickmarks {
        display: flex;
        justify-content: space-between;
        flex-grow: 1;
    }

    .slider-track-tick {
        border-radius: 9999%;
        background-color: var(--palette-primary);
    }

    .slider-track-tick-label {
        position: absolute;
        top: 0;
        left: 0;
    }
}
