use crate::translator::TranslatorCollection;
use crate::{HtmlToMarkdown, Options, TranslatorConfig};

const DEFAULT_BLOCK_ELEMENTS: &[&str] = &[
    "ADDRESS",
    "ARTICLE",
    "ASIDE",
    "AUDIO",
    "BLOCKQUOTE",
    "BODY",
    "CANVAS",
    "CENTER",
    "DD",
    "DIR",
    "DIV",
    "DL",
    "DT",
    "FIELDSET",
    "FIGCAPTION",
    "FIGURE",
    "FOOTER",
    "FORM",
    "FRAMESET",
    "H1",
    "H2",
    "H3",
    "H4",
    "H5",
    "H6",
    "HEADER",
    "HGROUP",
    "HR",
    "HTML",
    "ISINDEX",
    "LI",
    "MAIN",
    "MENU",
    "NAV",
    "NOFRAMES",
    "NOSCRIPT",
    "OL",
    "OUTPUT",
    "P",
    "PRE",
    "SECTION",
    "TABLE",
    "TBODY",
    "TD",
    "TFOOT",
    "TH",
    "THEAD",
    "TR",
    "UL",
];

const DEFAULT_IGNORE_ELEMENTS: &[&str] = &[
    "AREA", "BASE", "COL", "COMMAND", "EMBED", "HEAD", "INPUT", "KEYGEN", "LINK", "META", "PARAM",
    "SCRIPT", "SOURCE", "STYLE", "TRACK", "WBR",
];

pub(crate) const fn default_block_elements() -> &'static [&'static str] {
    DEFAULT_BLOCK_ELEMENTS
}

pub(crate) const fn default_ignore_elements() -> &'static [&'static str] {
    DEFAULT_IGNORE_ELEMENTS
}

pub(crate) fn build_converter<K1, K2, I1, I2>(
    options: Options,
    custom_translators: I1,
    custom_code_block_translators: I2,
) -> HtmlToMarkdown
where
    K1: Into<String>,
    K2: Into<String>,
    I1: IntoIterator<Item = (K1, TranslatorConfig)>,
    I2: IntoIterator<Item = (K2, TranslatorConfig)>,
{
    let mut translators = TranslatorCollection::default();
    for (keys, config) in custom_translators {
        translators.set(&keys.into(), &config, true);
    }

    let mut code_block_translators = TranslatorCollection::default();
    for (keys, config) in custom_code_block_translators {
        code_block_translators.set(&keys.into(), &config, true);
    }

    HtmlToMarkdown {
        options,
        translators,
        code_block_translators,
    }
}
