//~ EVENTS:
//~   link -  Handler for the link click event
//~           fields:
//~             originEvent - click event
//~ 
//~ 

//~OPTIONS
{
  lockTemplate: false,
}

//~ARGUMENTS
{
  fcfClassInner:  "fcf-two-level-menu",
  root:           "/",
  current:        "",
  acordeon:       true,
  items:          fcf.argProg(),
}

//~TEMPLATE
%{{ 
  fcf.each(args.items.parts, (a_key, a_node)=>{ 
    let active = a_node.uri == route.uri;
    let isOpen = true;
    if (args.acordeon)
      isOpen = a_node.uri == args.current ||
               fcf.find(a_node.parts, (k, v) => { return v.uri == args.current; }) !== undefined;
}}%
    <div class="fcf-two-level-menu-item @{{active ? "active" : ""}}@">
      <a 
        class="@{{active ? "active" : ""}}@" 
        href="@{{a_node.uri}}@"
        fcfEventClick="wrapper.emit('link', {originEvent: event});"
        >
        @{{a_node.title}}@
      </a>
    </div>
  %{{ 
    if (isOpen) {
      fcf.each(a_node.parts, (a_key, a_subEndpoint)=>{ 
        let active = a_subEndpoint.uri == route.uri;
  }}%
        <div class="fcf-two-level-menu-subitem @{{active ? "active" : ""}}@">
          <a 
            class="@{{active ? "active" : ""}}@" 
            href="@{{a_subEndpoint.uri}}@"
            fcfEventClick="wrapper.emit('link', {originEvent: event});"
          >
          @{{a_subEndpoint.title}}@
          </a>
        </div>
  %{{ 
      }) 
    }
  }}%
%{{ 
  }) 
}}%
