use crate::coords::proj::Mercator;
use crate::coords::Mapper;
use crate::render::{Render, RenderConfig};
use relm4::*;

pub struct RenderModel {
    config: RenderConfig,
    mapper: Mapper,
}

#[relm4::component(pub)]
impl SimpleComponent for RenderModel {
    type Init = (Option<Mapper>, Option<RenderConfig>);
    type Output = ();
    type Input = ();

    view! {
        Render{
            set_mapper = model.mapper.clone(),
            set_cfg = model.config.clone(),
        }
    }

    fn init(
        init: Self::Init,
        root: &Self::Root,
        sender: relm4::ComponentSender<Self>,
    ) -> relm4::ComponentParts<Self> {
        let (mapper, config) = init;
        let config = config.unwrap_or(RenderConfig::default());
        let mapper = mapper.unwrap_or(Mercator::default().into());

        let model = RenderModel { config, mapper };
        let widgets = view_output!();

        ComponentParts { model, widgets }
    }

    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {}
}
