@use "../colors";

$elevation-1: 0px 1px 2px rgba(colors.$shadow, 0.6);
$elevation-2: 0px 1px 2px rgba(colors.$shadow, 0.6);
$elevation-3: 0px 1px 3px rgba(colors.$shadow, 0.6);
$elevation-4: 0px 2px 3px rgba(colors.$shadow, 0.6);
$elevation-5: 0px 4px 4px rgba(colors.$shadow, 0.6);
$square-radius: 12px;

.m3-testing-window {
    background-color: colors.$background;
}

.m3-icon {
    font-family: "Material Symbols Outlined", "Material Icons Outlined";
}

.m3-button {
    /* Base */
    transition-timing-function: cubic-bezier(0.3, 0, 0, 1);
    transition:
        border-radius 50ms,
        background-color 200ms;
    label {
        font-weight: 400;
        line-height: 0px;
    }
    .m3-button-icon {
        font-family: "Material Symbols Outlined", "Material Icons Outlined";
    }
    .m3-button-label {
        color: colors.$on_background;
    }
    &:focus-visible {
        outline: 3px solid colors.$secondary;
        outline-offset: 2px;
    }

    &.icon-only {
        .m3-button-icon {
            font-variation-settings: "FILL" 1;
        }
    }

    /* -- TYPES -- */
    /* Elevated */
    &.elevated {
        background-color: colors.$surface_container;
        box-shadow: $elevation-1;
        label {
            color: colors.$primary;
        }

        &:hover {
            background-color: mix(
                colors.$surface_container,
                colors.$primary,
                $weight: 92%,
                $method: hsl
            );
            box-shadow: $elevation-4;
        }

        &:focus-visible,
        &:active {
            background-color: mix(
                colors.$surface_container,
                colors.$primary,
                $weight: 90%,
                $method: hsl
            );
        }
    }

    /* Filled */
    &.filled {
        background-color: colors.$primary;
        label {
            color: colors.$on_primary;
        }

        &:hover {
            background-color: mix(
                colors.$primary,
                colors.$on_primary,
                $weight: 92%,
                $method: hsl
            );
        }

        &:focus-visible,
        &:active {
            background-color: mix(
                colors.$primary,
                colors.$on_primary,
                $weight: 90%,
                $method: hsl
            );
        }
    }

    /* Tonal */
    &.tonal {
        background-color: colors.$secondary_container;
        label {
            color: colors.$on_secondary_container;
        }

        &:hover {
            background-color: mix(
                colors.$secondary_container,
                colors.$on_secondary_container,
                $weight: 92%,
                $method: hsl
            );
        }

        &:focus-visible,
        &:active {
            background-color: mix(
                colors.$secondary_container,
                colors.$on_secondary_container,
                $weight: 90%,
                $method: hsl
            );
        }
    }

    /* Outlined */
    &.outlined {
        box-shadow: 0px 0px 1px colors.$outline_variant;
        background-color: transparent;
        label {
            color: colors.$on_surface_variant;
        }

        &:hover {
            background-color: rgba(colors.$on_surface_variant, 0.08);
        }

        &:focus-visible,
        &:active {
            background-color: rgba(colors.$on_surface_variant, 0.1);
        }
    }

    /* Text */
    &.text {
        background-color: transparent;
        label {
            color: colors.$primary;
        }

        &:hover {
            background-color: rgba(colors.$primary, 0.08);
        }

        &:focus-visible,
        &:active {
            background-color: rgba(colors.$primary, 0.1);
        }
    }

    /* -- SIZES -- */
    /* Extra Small */
    &.xs {
        min-height: 32px;
        padding: 0px 12px;

        .m3-button-icon {
            font-size: 20px;
        }

        &.square {
            border-radius: 12px;
        }

        &:active {
            border-radius: 8px;
        }

        &.icon-only {
            padding: 0px 6px;
        }
    }

    /* Small */
    &.s {
        min-height: 40px;
        padding: 0px 16px;

        .m3-button-icon {
            font-size: 20px;
        }
        .m3-button-label {
            font-size: 10pt;
        }

        &.square {
            border-radius: 12px;
        }

        &:active {
            border-radius: 8px;
        }

        &.icon-only {
            padding: 0px 10px;
        }
    }

    /* Medium */
    &.m {
        min-height: 56px;
        padding: 0px 24px;

        .m3-button-icon {
            font-size: 24px;
        }
        .m3-button-label {
            font-size: 12pt;
        }

        &.square {
            border-radius: 16px;
        }

        &:active {
            border-radius: 12px;
        }

        &.icon-only {
            padding: 0px 16px;
        }
    }

    /* Large */
    &.l {
        min-height: 96px;
        padding: 0px 48px;

        .m3-button-icon {
            font-size: 32px;
        }
        .m3-button-label {
            font-size: 16pt;
            font-weight: 400;
        }

        &.square {
            border-radius: 28px;
        }

        &:active {
            border-radius: 12px;
        }

        &.icon-only {
            padding: 0px 32px;
        }
    }

    /* Extra Large */
    &.xl {
        min-height: 136px;
        padding: 0px 64px;

        .m3-button-icon {
            font-size: 40px;
        }
        .m3-button-label {
            font-size: 24pt;
            font-weight: 400;
        }

        &.square {
            border-radius: 28px;
        }

        &:active {
            border-radius: 16px;
        }

        &.icon-only {
            padding: 0px 48px;
        }
    }

    /* -- SHAPES -- */
    &.round {
        border-radius: 50rem;
    }
}

/* Connected Button Groups: https://m3.material.io/components/button-groups/specs */
.connected-button-group {
    .m3-button {
        transition: 200ms;

        &.xs {
            border-radius: 8px;
            min-width: 24px;
        }

        &:first-child {
            border-top-left-radius: 20px;
            border-bottom-left-radius: 20px;
        }

        &:last-child {
            border-top-right-radius: 20px;
            border-bottom-right-radius: 20px;
        }

        &.active {
            border-radius: 50rem;
            background-color: colors.$primary;
            .m3-button-icon {
                font-variation-settings: "FILL" 1;
            }

            label {
                color: colors.$on_primary;
                font-weight: 450;
            }
        }
    }
}

/* Switch: https://m3.material.io/components/switch/overview */
switch {
    background-color: colors.$surface_container_highest;
    box-shadow: inset 0px 0px 0px 2px colors.$outline;
    min-width: 52px;
    border-radius: 2rem;
    outline-offset: 2px;
    padding: 0px;
    slider {
        min-width: 16px;
        min-height: 16px;
        margin: 8px;
        margin-right: 2px;
        background-color: colors.$outline;
        box-shadow: none;
        border-radius: 50rem;
    }

    &:checked {
        box-shadow: none;
        background-color: colors.$primary;
        min-width: 52px;
        slider {
            min-width: 24px;
            min-height: 24px;
            margin: 4px;
            margin-left: -2px;
            background-color: colors.$on_primary;
        }
    }

    &:active {
        slider {
            min-width: 26px;
            min-height: 26px;
            margin: 3px;
            margin-right: -3px;
        }

        &:checked slider {
            margin-right: 3px;
            margin-left: -3px;
        }
    }

    &:hover {
        &:not(:checked) {
            background-color: mix(
                colors.$surface_container_highest,
                colors.$on_surface,
                $weight: 90%,
                $method: hsl
            );
        }

        slider {
            outline: 10px solid rgba(colors.$outline, 0.2);
        }

        &:checked slider {
            outline-width: 7px;
        }

        &:active slider {
            outline-width: 5px;
        }
    }
}

/* Sliders */
.m3-slider {
    background-color: colors.$surface_container;
    border-radius: 24px;
    padding: 10px 16px;
    .m3-icon {
        font-family: "Material Symbols Outlined", "Material Icons Outlined";
        font-size: 1.5rem;
        color: colors.$on_surface;
        margin-right: 0px;
    }
    scale {
        padding: 0px;
        trough {
            background-color: colors.$secondary_container;
            border-radius: 8px;
            highlight {
                background-color: colors.$primary;
                min-height: 16px;
                border-radius: 0px;
            }
            slider {
                min-height: 24px;
                min-width: 4px;
                padding: 0px;
                margin: -16px 0px;
                outline: 6px solid colors.$surface_container;
                outline-offset: 0px;
                border-radius: 20px;
                background-color: colors.$primary;
                transition: 100ms;
            }
        }

        value {
            margin-top: -36px;
            background-color: colors.$surface_container_high;
            border-radius: 20px;
            padding: 0.2rem 1rem;
            opacity: 0;
        }

        &:active {
            slider {
                outline-width: 4px;
                min-width: 2px;
            }
            value {
                opacity: 1;
            }
        }
    }
}

/* Navigation Rail */
.navigation-rail {
    padding: 10px;
    .rail-button {
        background-color: transparent;
        padding: 2px 0px;
        border-radius: 8px;
        .m3-button-icon {
            border-radius: 20rem;
            padding: 2px 16px;
            margin: 0px;
            margin-bottom: -5px;
            color: colors.$on_surface_variant;
            font-size: 16pt;
        }
        .m3-button-label {
            color: colors.$on_surface_variant;
            font-size: 8pt;
        }
        &:hover,
        &:focus-visible {
            background-color: transparent;
            outline: none;

            .m3-button-icon {
                background-color: rgba(colors.$secondary_container, 0.25);
            }
        }
        &.selected {
            .m3-button-icon {
                background-color: colors.$secondary_container;
                color: colors.$on_secondary_container;
                font-variation-settings: "FILL" 1;
            }
        }
    }
    .reload-button {
        min-height: 60px;
    }
}

/* Spin Buttons */
spinbutton {
    background-color: transparent;
    border-radius: 20px;
    text {
        border-radius: 20px 8px 8px 20px;
        background-color: colors.$surface_container_highest;
    }
    button {
        border: none;
        background-color: colors.$surface_container_highest;
        margin-left: 2px;
        border-radius: 8px;
        &:last-child {
            border-radius: 8px 20px 20px 8px;
        }
    }
    outline-color: colors.$tertiary;
    outline-offset: 2px;
}

/* Popovers */
popover {
    contents {
        background-color: colors.$surface_container;
        border: 1px solid rgba(colors.$outline_variant, 0.5);
        padding: 0px;
        border-radius: 15px;
        box {
            background-color: transparent;
            & > label {
                color: colors.$on_surface_variant;
            }
            modelbutton {
                background-color: transparent;
                border-radius: 10px;
                min-width: 100px;
                transition: 100ms;
                &:hover {
                    background-color: colors.$surface_container_highest;
                }
            }
        }
        label {
            font-weight: 400;
            color: colors.$on_surface;
        }
    }
    arrow {
        background-color: transparent;
    }
}

/* Tooltips */
tooltip {
    border-radius: 15px;
    background-color: colors.$surface_container_high;
    border: 1px solid rgba(colors.$outline_variant, 0.5);
    padding: 0.6rem 1rem;
}

/* Checkboxes */
checkbutton {
    check,
    radio {
        border-radius: 4px;
        background-color: transparent;
        box-shadow: inset 0px 0px 0px 2px rgba(colors.$on_surface_variant, 0.5);
        margin-right: 0.5rem;
        &:hover {
            background-color: colors.$surface_container_highest;
        }
        &:checked {
            background-color: colors.$primary;
            border-color: colors.$primary;
            color: colors.$on_primary;
            box-shadow: none;
        }
    }
    radio {
        border-radius: 100%;
    }
}

/* Scrollbars */
scrollbar {
    background-color: transparent;
    slider {
        background-color: colors.$tertiary;
        border-radius: 10px;
        margin: 2px;
    }
}

/* Font Picker */
.fontchooser {
    background-color: colors.$background;
    padding: 5px;

    entry {
        background-color: colors.$surface_container_high;
        border-radius: 10px;
    }

    .suggested-action {
        background-color: colors.$primary;
        color: colors.$on_primary;
        border-radius: 20px;
    }

    scale {
        padding: 0px;
        trough {
            background-color: colors.$secondary_container;
            border-radius: 8px;
            highlight {
                background-color: colors.$primary;
                min-height: 16px;
                border-radius: 20px;
            }
        }

        value {
            margin-top: -36px;
            background-color: colors.$surface_container_high;
            border-radius: 20px;
            padding: 0.2rem 1rem;
            opacity: 0;
        }

        &:active {
            slider {
                outline-width: 4px;
                min-width: 2px;
            }
            value {
                opacity: 1;
            }
        }

        mark {
            background-color: colors.$surface_container_highest;
        }
    }
}
