//! Inspector callback registration and completeness checks.

use super::{ComponentInspectorFn, EditorComponentRegistry};

impl EditorComponentRegistry {
    pub fn register_inspector_for_existing(
        &mut self,
        type_name: &'static str,
        inspector: ComponentInspectorFn,
    ) -> Result<(), String> {
        if self.by_type_name(type_name).is_none() {
            return Err(format!(
                "cannot register inspector for unknown component `{type_name}`"
            ));
        }
        if self.inspectors.insert(type_name, inspector).is_some() {
            return Err(format!("component `{type_name}` already has an inspector"));
        }
        Ok(())
    }

    pub fn visible_descriptors_have_inspectors(&self) -> bool {
        self.descriptors
            .iter()
            .filter(|descriptor| !descriptor.hidden)
            .all(|descriptor| self.inspectors.contains_key(descriptor.type_name))
    }
}
