use brisk_it::generator::{Generator, Result};

#[derive(Default)]
pub(super) struct MessageDialog {}

impl Generator for MessageDialog {
    fn generate(
        &self,
        input: brisk_it::component::ComponentInput,
        _manager: &brisk_it::generator::Manager,
    ) -> Result<proc_macro2::TokenStream> {
        let mut modifiers = Vec::<proc_macro2::TokenStream>::new();

        let var = crate::utils::component_variable(&input);

        for prop in input.properties {
            if prop.name == "level" {
                let expr = prop.expr;
                modifiers.push(quote::quote! {
                    .set_level(#expr)
                });
            } else if prop.name == "description" {
                let expr = prop.expr;
                modifiers.push(quote::quote! {
                    .set_description(#expr)
                });
            } else if prop.name == "title" {
                let expr = prop.expr;
                modifiers.push(quote::quote! {
                    .set_title(#expr)
                });
            } else if prop.name == "buttons" {
                let expr = prop.expr;
                modifiers.push(quote::quote! {
                    .set_buttons(#expr)
                });
            } else {
                return Err(brisk_it::errors::unknown_property(prop));
            }
        }

        Ok(quote::quote! {
            let #var = rfd::MessageDialog::new()#(#modifiers)*;
        })
    }
    fn boxed_clone(&self) -> Box<dyn Generator> {
        Box::new(Self {})
    }
}
