<%= content_tag_for :li, node, data: { node_id: node.id, label: node.label, url: main_app.project_node_path(node.project, node) }, class: css_class_for_node(node) do %>
  <%= link_to(
    main_app.tree_project_node_path(node.project, node, format: :js),
    class: 'toggle',
    # Use 'visibility: hidden' rather than just not outputting the link at
    # all, so that the node's name is still indented the same amount as nodes
    # which do have a toggle link
    style: ('visibility: hidden' if node.children_count == 0)

  ) do %>
    <i class="fa-solid fa-caret-right fa-fw"></i>
    <span class="visually-hidden">Toggle child nodes</span>
  <% end %>

  <%= link_to main_app.project_node_path(node.project, node), title: node.label, data: { behavior: 'sidebar-link sidebar-node-link' } do %>
    <%= colored_icon_for_model(node, nil) %>
    <%= node.label %>
  <% end %>

  <%= content_tag :ul, data: {id: dom_id(node, 'menu')}, class: "children #{css_class_for_sub_nodes(node)}" do %>
    <% if node.ancestor_of?(@node) %>
      <%= render partial: "layouts/hera/node", collection: node.children %>
    <% else %>
      <li class="loading ps-3 ms-3">Loading...</li>
      <li class="error ps-3 ms-3">Loading error. Please try again.</li>
    <% end %>
  <% end %>
<% end %>
