1
use web_sys::Element;
2

            
3
use super::account::AccountAutocomplete;
4
use super::tag::{TagNameAutocomplete, TagValueAutocomplete};
5
use crate::data_attrs::{AutocompleteAttr, autocomplete_type};
6

            
7
/// Creates and attaches an autocomplete component based on the type attribute.
8
///
9
/// Reads `data-autocomplete` from the wrapper element and dispatches to the
10
/// appropriate type-specific handler.
11
#[must_use]
12
pub fn create_autocomplete(wrapper: &Element) -> Option<()> {
13
    let ac_type = wrapper.get_attribute(AutocompleteAttr::Type.as_str())?;
14

            
15
    match ac_type.as_str() {
16
        autocomplete_type::ACCOUNT => AccountAutocomplete::attach(wrapper.clone()),
17
        autocomplete_type::TAG_NAME => TagNameAutocomplete::attach(wrapper.clone()),
18
        autocomplete_type::TAG_VALUE => TagValueAutocomplete::attach(wrapper.clone()),
19
        _ => {
20
            web_sys::console::warn_1(&format!("Unknown autocomplete type: {ac_type}").into());
21
            None
22
        }
23
    }
24
}