
{% if is_primitive %}
{{ primitive_instance_import_path }}::instantiate(
{% else %}
instantiate_{{ snake_case_type_id }}( Rc::clone(&instance_registry),
{% endif %}
 InstantiationArgs {
    common_properties: CommonProperties {
        {% for cpl_tuple in common_properties_literal %}
            {{cpl_tuple.0}}: {{cpl_tuple.1}},
        {% endfor %}
    },
    properties: PropertiesCoproduct::{{ properties_coproduct_variant }}
    {% if properties_coproduct_variant != "None" %}
        (
            {
                let mut cps = {{component_properties_struct}}::default();

                {% for property in defined_properties %}
                    cps.{{ property.0 }} = Box::new( {{ property.1 }} );
                {% endfor %}

                cps
            }
        )
    {% endif %},
    handler_registry:  Some(Rc::new(RefCell::new({
        #[allow(unused_mut)]
        let mut handler_registry = HandlerRegistry::default();
        {% for key, value in events %}
            handler_registry.{{key}}_handlers = vec![
                {%- if key in ['will_render','did_mount'] -%}
                    |properties, ctx|{
                       let properties = &mut *properties.as_ref().borrow_mut();
                       let properties = if let PropertiesCoproduct::{{ type_id_escaped }}(p) = properties {p} else {unreachable!()};
                       {{ pascal_identifier }}::{{value}}(properties, ctx);
                    },
                {% else %}
                    |stack_frame, ctx, args|{
                        let properties = (*stack_frame).borrow().get_properties();
                        let properties = &mut *properties.as_ref().borrow_mut();
                        let properties = if let PropertiesCoproduct::{{ type_id_escaped }}(p) = properties {p} else {unreachable!()};
                        {{ pascal_identifier }}::{{value}}(properties, ctx, args);
                    },
                {% endif %}
            ];
        {% endfor %}
        handler_registry
    }))),
    instance_registry: Rc::clone(&instance_registry),
    children: Some(Rc::new(RefCell::new(vec![
        {% for child_literal in children_literal %}
            {{ child_literal }},
        {% endfor %}
    ]))),
    component_template: None,
    scroller_args: None,
    slot_index: {{slot_index_literal}},
    repeat_source_expression_vec: {{repeat_source_expression_literal_vec}},
    repeat_source_expression_range: {{repeat_source_expression_literal_range}},
    conditional_boolean_expression: {{conditional_boolean_expression_literal}},
    compute_properties_fn: None,
})
