use std::time::Duration;
use dioxus::prelude::*;
use freya_elements::elements as dioxus_elements;
use freya_hooks::{use_applied_theme, LoaderTheme, LoaderThemeWith};
use tokio::time::interval;
#[derive(Props, Clone, PartialEq)]
pub struct LoaderProps {
    pub theme: Option<LoaderThemeWith>,
}
#[allow(non_snake_case)]
pub fn Loader(props: LoaderProps) -> Element {
    let theme = use_applied_theme!(&props.theme, loader);
    let mut degrees = use_signal(|| 0);
    let LoaderTheme {
        primary_color,
        secondary_color,
    } = theme;
    use_hook(move || {
        spawn(async move {
            let mut ticker = interval(Duration::from_millis(28));
            loop {
                ticker.tick().await;
                if *degrees.peek() > 360 {
                    degrees.set(0);
                } else {
                    degrees += 10;
                }
            }
        });
    });
    rsx!(svg {
        rotate: "{degrees}deg",
        width: "31",
        height: "31",
        svg_content: r#"
                <svg width="31" height="31" viewBox="0 0 31 31" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M15.5235 27.6652C22.2292 27.6652 27.6652 22.2292 27.6652 15.5235C27.6652 8.81783 22.2292 3.38182 15.5235 3.38182C8.81783 3.38182 3.38182 8.81783 3.38182 15.5235C3.38182 22.2292 8.81783 27.6652 15.5235 27.6652Z" stroke="{primary_color}"  stroke-width="4"/>
                    <path d="M27.6652 15.5235C27.6652 8.81859 22.2284 3.38182 15.5235 3.38182" stroke="{secondary_color}" stroke-width="4"/>
                </svg>
            "#
    })
}