use refix_dictionary::{Dictionary, dictionary};
use super::declarations::emit_declarations;
use super::groups::emit_group_class;
use super::layout::indent;
use super::names::Names;
use crate::envelope::Section;
pub(super) fn emit_view(section: Section, dictionary: &Dictionary, names: &Names) -> String {
let members = section.members(dictionary);
let mut items: Vec<String> = members
.iter()
.filter_map(|member| match member {
dictionary::Member::Group(group) if *group.declared_in() == section.context() => {
Some(indent(&emit_group_class(*group, names), 1))
}
_ => None,
})
.collect();
items.push(emit_declarations(members.into_iter(), names));
format!(
"class {}(fields.Component):\n{}",
section.type_name(),
items.join("\n")
)
}
pub(super) fn emit_view_declaration(section: Section) -> String {
let (name, type_name) = (section.member_name(), section.type_name());
format!(" {name} = fields.View({type_name})\n")
}