defmodule OutlookWeb.HtmlTreeComponent do

   use Phoenix.Component
  # use OutlookWeb, :html
  import OutlookWeb.CoreComponents

  alias Phoenix.LiveView.JS

  attr :tree, :list, required: true

  def render_tree(assigns) do
    ~H"""
    <.tnode :for={node <- @tree} node={node} />
    """
  end

  def attributes(assigns) do
    ~H"&nbsp; <%= @name %>=&quot;<%= @value %>&quot;"
  end

  def tnode(%{node: %{status: _}} = assigns), do: ~H"<%= String.slice(@node.content, 0..20) %><%= if String.length(@node.content) > 20 do %>...<% end %><br>"

  def tnode(assigns) when assigns.node.type == :element do
    ~H"""
     &lt;<%= @node.name %><.attributes :for={{k,v} <- @node.attributes} name={k} value={v}
     />&gt;<br>
    <div class="ml-8">
      <.tnode :for={child_node <- @node.content} node={child_node} />
    </div>
    """
  end

  def tnode(assigns) when assigns.node.type == :text do
    ~H"""
     "<%= String.slice(@node.content, 0..35) %><%= if String.length(@node.content) > 35 do %>..."<% end %><br>
    """
  end

  def tnode(assigns) when assigns.node.type == :comment do
    ~H"""
     &lt;!--<%= String.slice(@node.content, 0..35) %>
      <%= if String.length(@node.content) > 35 do %>"..."<% end %>--&gt;
    """
  end
end
