{% set assign=true %}
{% set signal=true %}
{% set resolve=true %}

{% import "src/default/types/block.js.njk" as block with context %}

{% call block.header() %}

  {% for child in childs %}
    {% if not child.definition.dynamic %}
      // CHILD: {{child.indexKey}}
      import {{child.codeKey}} from "./{{child.codeKey}}.js";
    {% endif %}
  {% endfor%}

{% endcall %}

{% call block.definition() %}
  
  {% for child in childs %}
    {% if loop.first %}
      if ({{child.context.transform.condition | safe}}) 
    {% else %}
      {%if child.context.transform.condition %}
        else if ({{child.context.transform.condition | safe}}) 
      {% else %}
        else
      {% endif %}
    {% endif %} 
      {
        {% if child.definition.dynamic %}
          // CHILD: {{child.indexKey}}
          const { default: {{child.codeKey}} } = await import("./{{child.codeKey}}.js");
        {% endif %}

        const current=new {{child.codeKey}}({ parent:_this, engine, flow, caller:c, error });

        {% if workflow.parent.context.atom.doc.features.print_runners %}
          console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
        {% endif %}

        return resolve(Array.isArray(args)? await current.run.apply(current,args) : await current.run(args));
      }
  {% endfor%}

{% endcall %}

{% call block.footer()%} 
{% endcall %}