<.breadcrumb items={[ %{label: "Dashboard", navigate: ~p"/dashboard"}, %{label: "Settings", navigate: ~p"/orgs/#{@organization.slug}/settings"}, %{label: "Integrations", navigate: ~p"/orgs/#{@organization.slug}/settings/integrations"}, %{label: "Gaiia"} ]} />

{t("Link Devices & Sites to Gaiia")}

{t( "For each of your monitored devices and sites, find the matching Gaiia inventory item. This enables subscriber impact data when devices go down." )}

<%!-- Sub-navigation tabs --%>
<%!-- Tab navigation --%>
<%!-- Filter pills --%>
<.link :for={{f, label} <- [{"all", "All"}, {"linked", "Linked"}, {"unlinked", "Unlinked"}]} patch={ ~p"/orgs/#{@organization.slug}/settings/integrations/gaiia/mapping?tab=#{@tab}&filter=#{f}" } class={[ "rounded-full px-3 py-1 text-xs font-medium", if(@filter == f, do: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300", else: "bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-white/5 dark:text-gray-400 dark:hover:bg-white/10" ) ]} > {label}
<%!-- Content --%>
<%= if @items == [] do %>
<.icon name={if(@tab == "sites", do: "hero-map-pin", else: "hero-cpu-chip")} class="mx-auto h-12 w-12 text-gray-400 dark:text-gray-500" />

<%= case {@tab, @filter} do %> <% {"devices", "linked"} -> %> {t("No linked devices yet")} <% {"devices", "unlinked"} -> %> {t("All devices are linked to Gaiia")} <% {"sites", "linked"} -> %> {t("No linked sites yet")} <% {"sites", "unlinked"} -> %> {t("All sites are linked to Gaiia")} <% {"devices", _} -> %> {t("No devices in your organization")} <% _ -> %> {t("No sites in your organization")} <% end %>

<%= case {@tab, @filter} do %> <% {_, "unlinked"} -> %> {t("Nothing left to do here.")} <% {_, "linked"} -> %> {t("Link devices or sites using the Unlinked filter.")} <% _ -> %> {t("Add devices to TowerOps to get started.")} <% end %>

<% else %>
<%= if @tab == "devices" do %> <% end %> <%= for row <- @items do %> <% row_id = if @tab == "devices", do: row.device.id, else: row.site.id is_linked = if @tab == "devices", do: not is_nil(row.inventory_item), else: not is_nil(row.network_site) %> <%!-- Device / Site column --%> <%!-- IP Address (devices only) --%> <%= if @tab == "devices" do %> <% end %> <%!-- Gaiia Item / Network Site column --%> <%!-- Actions column --%> <%!-- Inline linking row --%> <%= if row_id == @linking_id do %> <% end %> <% end %>
{if @tab == "devices", do: t("Your Device"), else: t("Your Site")} {t("Actions")}
<%= if @tab == "devices" do %>
<.link navigate={~p"/devices/#{row.device.id}"} class="font-medium text-gray-900 hover:text-indigo-600 dark:text-white dark:hover:text-indigo-400" > {row.device.name || row.device.ip_address || "Unnamed"} <%= if Map.has_key?(@suggestions, row.device.id) do %> <.icon name="hero-light-bulb-mini" class="mr-0.5 h-3 w-3" /> Match found <% end %>
<%= if row.device.site do %>
{row.device.site.name}
<% end %>
<% else %>
{row.site.name || "Unnamed"} <%= if Map.has_key?(@suggestions, row.site.id) do %> <.icon name="hero-light-bulb-mini" class="mr-0.5 h-3 w-3" /> Match found <% end %>
<% end %>
<%= if @tab == "devices" do %> <%= if row.inventory_item do %> <% else %> <% end %> <% else %> <%= if row.network_site do %> <% else %> <% end %> <% end %>

<%= if @tab == "devices" do %> Find a Gaiia item to link to {row.device.name || row.device.ip_address} <% else %> Find a Gaiia network site to link to {row.site.name} <% end %>

<%!-- Suggestions --%> <%= if suggestions = @suggestions[row_id] do %>

<.icon name="hero-light-bulb-mini" class="inline h-3 w-3 mr-0.5" /> {t("Suggested match (same IP):")}

<%= for suggestion <- suggestions do %> <% end %>
<% end %> <%!-- Search --%>
<%= if @search_results != [] do %>
<% end %> <%= if @search_query != "" and String.length(@search_query) >= 2 and @search_results == [] do %>

No Gaiia {if(@tab == "sites", do: "network sites", else: "inventory items" )} matching "{@search_query}"

<% end %>
<% end %>