{t("Network Insights")}

{t("Proactive network health observations from all sources.")}

<%!-- Filter bar --%>
<%!-- Status filter tabs --%> <%!-- Source filter pills --%>
Source: <.link id="filter-source-all" patch={ ~p"/insights?#{build_filter_params(%{status: @filter_status, urgency: @filter_urgency}, %{})}" } class={[ "rounded-md px-2 py-1 text-xs font-medium", if(is_nil(@filter_source), do: "bg-gray-200 text-gray-800 dark:bg-white/20 dark:text-white", else: "text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-white/10" ) ]} > {t("All")} <.link :for={source <- ~w(preseem gaiia snmp system)} id={"filter-source-#{source}"} patch={ ~p"/insights?#{build_filter_params(%{status: @filter_status, urgency: @filter_urgency}, %{source: source})}" } class={[ "rounded-md px-2 py-1 text-xs font-medium capitalize", if(@filter_source == source, do: "bg-gray-200 text-gray-800 dark:bg-white/20 dark:text-white", else: "text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-white/10" ) ]} > {source}
<%!-- Urgency filter --%>
Urgency: <.link id="filter-urgency-all" patch={ ~p"/insights?#{build_filter_params(%{status: @filter_status, source: @filter_source}, %{})}" } class={[ "rounded-md px-2 py-1 text-xs font-medium", if(is_nil(@filter_urgency), do: "bg-gray-200 text-gray-800 dark:bg-white/20 dark:text-white", else: "text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-white/10" ) ]} > {t("All")} <.link :for={ {urgency, classes} <- [ {"critical", "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"}, {"warning", "bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400"}, {"info", "bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400"} ] } id={"filter-urgency-#{urgency}"} patch={ ~p"/insights?#{build_filter_params(%{status: @filter_status, source: @filter_source}, %{urgency: urgency})}" } class={[ "rounded-md px-2 py-1 text-xs font-medium capitalize", if(@filter_urgency == urgency, do: classes, else: "text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-white/10" ) ]} > {urgency}
<%!-- Bulk actions bar --%> <%= if any_selected?(@selected_ids) do %>
{MapSet.size(@selected_ids)} selected
<% end %> <%!-- Insights list --%>
<%= if @insights == [] do %>
<.icon name="hero-light-bulb-solid" class="h-12 w-12 text-amber-500 dark:text-amber-400" />

{t("No Insights Yet")}

<%= cond do %> <% @filter_status == "dismissed" -> %> {t("No dismissed insights.")} <% @filter_source != nil -> %> No {@filter_source} insights right now. <% @filter_urgency != nil -> %> No {@filter_urgency} insights right now. <% true -> %> {t("Connect Preseem or enable SNMP monitoring to get started.")} <% end %>

{t("Go to your org settings to connect an integration.")}
<% else %> <%!-- Select all bar --%>
<%!-- Checkbox --%>
<%!-- Urgency badge --%> {insight.urgency} <%!-- Source badge --%> {insight.source} <%!-- Type badge --%> {String.replace(insight.type, "_", " ")}

{insight.title}

<%= if insight.description do %>

{insight.description}

<% end %> <%= if insight.llm_summary do %>

{t("Summary")}

{insight.llm_summary}

<%= if insight.recommended_action do %>

{t("Recommended action:")} {insight.recommended_action}

<% end %>

AI-generated{if insight.llm_model, do: " ยท " <> insight.llm_model, else: ""}

<% end %> <%!-- Affected devices list (from metadata) --%> <%= if insight.metadata["device_names"] && length(insight.metadata["device_names"]) > 0 do %>

{t("Affected devices:")}

<%= for {name, idx} <- Enum.with_index(insight.metadata["device_names"]) do %> <%= if insight.metadata["device_ids"] && Enum.at(insight.metadata["device_ids"], idx) do %> <.link navigate={ ~p"/devices/#{Enum.at(insight.metadata["device_ids"], idx)}" } class="inline-flex items-center rounded-md bg-white px-2 py-0.5 text-xs font-medium text-indigo-700 ring-1 ring-inset ring-indigo-700/10 hover:bg-indigo-50 dark:bg-indigo-900/20 dark:text-indigo-400 dark:ring-indigo-400/20 dark:hover:bg-indigo-900/40" > {name || "Unnamed"} <% else %> {name || "Unnamed"} <% end %> <% end %> <%= if insight.metadata["count"] && insight.metadata["count"] > length(insight.metadata["device_names"]) do %> +{insight.metadata["count"] - length(insight.metadata["device_names"])} more <% end %>
<% end %> <%!-- Actionable recommendations --%> <%= if insight.source == "gaiia" && insight.metadata["finding_type"] == "untracked" do %>

<.icon name="hero-light-bulb" class="h-3.5 w-3.5 inline" /> {t("To fix this:")}

<.link navigate={ ~p"/orgs/#{@organization.slug}/settings/integrations/gaiia/mapping" } class="inline-flex items-center gap-1 rounded-md bg-blue-600 px-2.5 py-1.5 text-xs font-medium text-white shadow-xs hover:bg-blue-700" > <.icon name="hero-arrows-right-left" class="h-3.5 w-3.5" /> {t("Link devices to Gaiia")} <.link navigate={ ~p"/orgs/#{@organization.slug}/settings/integrations/gaiia/reconciliation" } class="inline-flex items-center gap-1 rounded-md bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 shadow-xs ring-1 ring-inset ring-gray-300 hover:bg-gray-50 dark:bg-white/10 dark:text-gray-300 dark:ring-white/10 dark:hover:bg-white/20" > <.icon name="hero-table-cells" class="h-3.5 w-3.5" /> {t("View comparison report")}
<% end %> <%= if insight.source == "gaiia" && insight.metadata["finding_type"] == "ghost" do %>

<.icon name="hero-light-bulb" class="h-3.5 w-3.5 inline" /> {t("To fix this:")}

<.link navigate={ ~p"/orgs/#{@organization.slug}/settings/integrations/gaiia/mapping" } class="inline-flex items-center gap-1 rounded-md bg-amber-600 px-2.5 py-1.5 text-xs font-medium text-white shadow-xs hover:bg-amber-700" > <.icon name="hero-trash" class="h-3.5 w-3.5" /> {t("Remove stale device links")}
<% end %> <%= if insight.source == "gaiia" && insight.metadata["finding_type"] == "mismatch" do %>

<.icon name="hero-light-bulb" class="h-3.5 w-3.5 inline" /> {t("To fix this:")}

<.link navigate={ ~p"/orgs/#{@organization.slug}/settings/integrations/gaiia/reconciliation" } class="inline-flex items-center gap-1 rounded-md bg-blue-600 px-2.5 py-1.5 text-xs font-medium text-white shadow-xs hover:bg-blue-700" > <.icon name="hero-table-cells" class="h-3.5 w-3.5" /> {t("Review conflicting data")}
<% end %>
<%!-- Access point --%> <%= if insight.preseem_access_point do %> <.icon name="hero-signal" class="h-3.5 w-3.5" /> {insight.preseem_access_point.name} <% end %> <%!-- Linked device --%> <%= if insight.device do %> <.link navigate={~p"/devices/#{insight.device.id}"} class="flex items-center gap-1 text-indigo-600 hover:text-indigo-800 dark:text-indigo-400 dark:hover:text-indigo-300" > <.icon name="hero-server" class="h-3.5 w-3.5" /> {insight.device.name || "Device"} <% end %> <%!-- Timestamp --%> <.icon name="hero-clock" class="h-3.5 w-3.5" /> {ToweropsWeb.TimeHelpers.format_datetime( insight.inserted_at, @current_scope.timezone, @current_scope.time_format )}
<%!-- Dismiss button --%> <%= if insight.status == "active" do %> <% end %>
<% end %>