use once_cell::sync::Lazy;
use scraper::Selector;

pub(crate) static SELECTORS: Lazy<Selectors> = Lazy::new(Selectors::new);

#[derive(Clone)]
pub(crate) struct Selectors {
    pub(crate) shindan_title: Selector,
    pub(crate) shindan_description_display: Selector,
    pub(crate) form: Vec<Selector>,
    pub(crate) input_parts: Selector,

    #[cfg(feature = "segments")]
    pub(crate) post_display: Selector,

    #[cfg(feature = "html")]
    pub(crate) title_and_result: Selector,
    #[cfg(feature = "html")]
    pub(crate) script: Selector,
    #[cfg(feature = "html")]
    pub(crate) effects: Vec<Selector>,
}

impl Selectors {
    fn new() -> Self {
        Self {
            shindan_title: Selector::parse("#shindanTitle").expect("Failed to parse selector"),
            shindan_description_display: Selector::parse("#shindanDescriptionDisplay")
                .expect("Failed to parse selector"),
            form: vec![
                Selector::parse("input[name=_token]").expect("Failed to parse selector"),
                Selector::parse("input[name=randname]").expect("Failed to parse selector"),
                Selector::parse("input[name=type]").expect("Failed to parse selector"),
            ],
            input_parts: Selector::parse(r#"input[name^="parts["]"#)
                .expect("Failed to parse selector"),

            #[cfg(feature = "segments")]
            post_display: Selector::parse("#post_display").expect("Invalid selector"),

            #[cfg(feature = "html")]
            title_and_result: Selector::parse("#title_and_result")
                .expect("Failed to parse selector"),
            #[cfg(feature = "html")]
            script: Selector::parse("script").expect("Invalid script selector"),
            #[cfg(feature = "html")]
            effects: vec![
                Selector::parse("span.shindanEffects[data-mode=ef_typing]")
                    .expect("Invalid script selector"),
                Selector::parse("span.shindanEffects[data-mode=ef_shuffle]")
                    .expect("Invalid script selector"),
            ],
        }
    }
}
