"use client";

import { IconMoon, IconSun } from "@tabler/icons-react";
import classNames from "classnames";
import {
    Button,
    useComputedColorScheme,
    useMantineColorScheme,
} from "@mantine/core";
import style from "./ColorSchemeToggle.module.css";

export function ColorSchemeToggle() {
    const { setColorScheme } = useMantineColorScheme();
    const computedColorScheme = useComputedColorScheme(undefined, {
        getInitialValueInEffect: true,
    });

    const toggleColorScheme = () => {
        setColorScheme(computedColorScheme === "light" ? "dark" : "light");
    };

    return (
        <Button
            unstyled
            onClick={toggleColorScheme}
            size="xl"
            radius="lg"
            aria-label="Сменить тему"
            className={style.container}>
            <IconSun
                className={classNames(style.icon, style.light)}
                stroke={1.5}
            />
            <IconMoon
                className={classNames(style.icon, style.dark)}
                stroke={1.5}
            />
        </Button>
    );
}
