   end
 
   def handle_info({:flex, :open, ch, tab, nil, params} = msg, socket) do
-    warn inspect(msg), "nil"
+    debug inspect(msg), "nil"
     resp = FlexBarService.handle_flex_callback(:open, ch, tab, nil, socket, params)
     push socket, "flex:open", Enum.into([title: tab], resp)
     {:noreply, socket}
   end
   def handle_info({:flex, :open, ch, tab, args, params} = msg, socket) do
-    warn inspect(msg), "args"
+    debug inspect(msg), "args"
     resp = FlexBarService.handle_flex_callback(:open, ch, tab, args[tab], socket, params)
-    warn "resp: #{inspect resp}", ""
+    debug "resp: #{inspect resp}", ""
     push socket, "flex:open", Enum.into([title: tab], resp)
     {:noreply, socket}
   end
   def handle_info({:flex, :close, _ch, _tab, _, _params} = msg, socket) do
-    warn inspect(msg), ""
+    debug inspect(msg), ""
     push socket, "flex:close", %{}
     {:noreply, socket}
   end

        push socket, "code:update", %{html: html2, selector: ~s(.user-card-room[data-status-name="#{user.username}"]), action: "html"}
      end
    else
      # warn event, payload, "closed"
    end
    {:noreply, socket}
  end

  def handle_info(%Broadcast{topic: _, event: "user:action" = event, payload: %{action: "removed"} = payload}, %{assigns: assigns} = socket) do
    warn event, payload, "assigns: #{inspect assigns}"
    current_user = Helpers.get_user! assigns.user_id
    user = Helpers.get_user! payload.user_id
    if Flex.open? assigns.flex, assigns.channel_id, "Members List" do
      warn event, payload, "removed open"

      push socket, "code:update", %{selector: ~s(.user-card-room[data-status-name='#{user.username}']), action: "remove"}
      push socket, "code:update", %{selector: ".flex-tab-container .user-view", action: "addClass", html: "animated-hidden"}
    else
      warn event, payload, "closed"
    end
    {:noreply, socket}
  end
  def handle_info(%Broadcast{topic: _, event: "user:action" = event, payload: %{action: "unhide"} = payload}, %{assigns: assigns} = socket) do
    warn event, payload, "assigns: #{inspect assigns}"
    # current_user = Helpers.get_user! assigns.user_id
    # user = Helpers.get_user! payload.user_id

    UserSocket.push_rooms_list_update(socket, payload.channel_id, payload.user_id)

    # if Flex.open? assigns.flex, assigns.channel_id, "Members List" do
    #   warn event, payload, "removed open"

    #   push socket, "code:update", %{selector: ~s(.user-card-room[data-status-name='#{user.username}']), action: "remove"}
    #   push socket, "code:update", %{selector: ".flex-tab-container .user-view", action: "addClass", html: "animated-hidden"}
    # else
    #   warn event, payload, "closed"
    # end
    {:noreply, socket}
  end
  def handle_info(%Broadcast{topic: _, event: "user:entered" = event, payload: %{user: user} = payload}, %{assigns: %{user: user} = assigns} = socket) do
    warn event, payload, "assigns: #{inspect assigns}"
    old_channel_id = assigns[:channel_id]
    channel_id = payload[:channel_id]
    socket = %{assigns: assigns} = assign(socket, :channel_id, channel_id)


  def handle_out("room:join" = ev, msg, socket) do
    %{room: room} = msg
    debug ev, msg, "assigns: #{inspect socket.assigns}"
    UserSocket.push_message_box(socket, socket.assigns.channel_id, socket.assigns.user_id)
    update_rooms_list(socket)
    {:noreply, subscribe([room], socket)}
  end
  def handle_out("room:leave" = ev, msg, socket) do
    %{room: room} = msg
    debug ev, msg, "assigns: #{inspect socket.assigns}"
    UserSocket.push_message_box(socket, socket.assigns.channel_id, socket.assigns.user_id)
    socket.endpoint.unsubscribe(CC.chan_room <> room)
    update_rooms_list(socket)
    {:noreply, assign(socket, :subscribed, List.delete(socket.assigns[:subscribed], room))}
  end

  ###############
  # Incoming Messages

  def handle_in("subscribe" = ev, params, socket) do
    debug ev, params, "assigns: #{inspect socket.assigns}"
    {:noreply, socket}
  end

  def handle_in("flex:open:" <> tab = ev, params, socket) do
    debug ev, params, "assigns: #{inspect socket.assigns}"
    {:noreply, toggle_flex(socket, tab, params)}
  end
  def handle_in("flex:item:open:" <> tab = ev, params, socket) do
    debug ev, params, "assigns: #{inspect socket.assigns}"
    {:noreply, open_flex_item(socket, tab, params)}
  end

  def handle_in("flex:close" = ev, params, socket) do
    debug ev, params
    {:noreply, socket}
  end

  def handle_in("flex:view_all:" <> tab = ev, params, %{assigns: assigns} = socket) do
    debug ev, params
    fl = assigns[:flex] |> Flex.view_all(assigns[:channel_id], tab)
    {:noreply, assign(socket, :flex, fl)}
  end

  def handle_in("side_nav:open" = ev, %{"page" => "account"} = params, socket) do
    debug ev, params

    user = Helpers.get_user!(socket)
    account_cs = Account.changeset(user.account, %{})
    html = Helpers.render(AccountView, "account_preferences.html", user: user, account_changeset: account_cs)
    push socket, "code:update", %{html: html, selector: ".main-content", action: "html"}

