<.link navigate={ if @live_action == :edit, do: ~p"/sites/#{@site.id}", else: ~p"/sites" } class="inline-flex items-center gap-1 text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white" > <.icon name="hero-arrow-left" class="h-4 w-4" /> {if @live_action == :edit, do: "Back to Site", else: "Back to Sites"}
<.header> {@page_title} <:subtitle> {if @live_action == :new, do: "Add a new site to your organization", else: "Update site details"}
<.form for={@form} id="site-form" phx-change="validate" phx-submit="save"> <.input field={@form[:name]} type="text" label={t("Site Name")} required />

{t("Geographic Location")} (optional)

{t("Add geographic coordinates to enable network mapping and spatial analysis.")}

<%= if @form[:latitude].value && @form[:longitude].value do %>
{t("Map Preview")}
Location preview

Coordinates: {@form[:latitude].value}, {@form[:longitude].value}

<% end %>
<%= if @available_agents != [] do %>

{t("Agent Configuration")} (optional)

{t( "Set a default agent for SNMP polling at this site. This will override the organization default for all devices at this site. Leave blank to inherit from organization." )}

<.input field={@form[:agent_token_id]} type="select" label={t("Default Agent for Site")} prompt="Inherit from organization" options={Enum.map(@available_agents, &{&1.name, &1.id})} /> <%= if @live_action == :edit and @site.agent_token_id do %>

<.icon name="hero-exclamation-triangle" class="h-4 w-4" /> {t("Overriding")} organization default - all devices at this site will use this agent

{t("Force Apply to Site Device")}

{t("This will assign this agent to ALL devices at this site.")}

<.button type="button" phx-click="apply_agent_to_all" data-confirm={ t( "This will replace agent assignments for ALL devices at this site. Are you sure?" ) } variant="danger" > <.icon name="hero-arrow-path" class="h-4 w-4" /> Apply Agent to All Device
<% else %> <%= if Map.get(assigns, :org_agent) do %>

<.icon name="hero-building-office-2" class="h-4 w-4" /> Currently inheriting organization default: {@org_agent.name}

<% else %>

{t( "Set a default agent for all devices at this site. Device can override this setting individually." )}

<% end %> <% end %>
<% end %>

{t("SNMP Configuration")} (optional)

{t( "Override organization SNMP defaults for all devices at this site. Leave blank to inherit from organization." )}

<.input field={@form[:snmp_version]} type="select" label={t("SNMP Version")} prompt="Inherit from organization" options={[{"v1", "1"}, {"v2c", "2c"}, {"v3", "3"}]} /> <%= if @form[:snmp_version].value in ["1", "2c"] do %> <.input field={@form[:snmp_community]} type="text" label={t("SNMP Community String")} placeholder={t("Leave blank to inherit from organization")} /> <% end %> <%= if @form[:snmp_version].value == "3" do %> <.input field={@form[:snmpv3_security_level]} type="select" label={t("Security Level")} prompt="Select security level" options={[ {"No Auth, No Priv", "noAuthNoPriv"}, {"Auth, No Priv", "authNoPriv"}, {"Auth, Priv", "authPriv"} ]} /> <.input field={@form[:snmpv3_username]} type="text" label={t("Username")} placeholder={t("Leave blank to inherit from organization")} /> <%= if @form[:snmpv3_security_level].value in ["authNoPriv", "authPriv"] do %> <.input field={@form[:snmpv3_auth_protocol]} type="select" label={t("Auth Protocol")} prompt="Select protocol" options={[ {"SHA-256 (recommended)", "SHA-256"}, {"SHA-512", "SHA-512"}, {"SHA-384", "SHA-384"}, {"SHA-224", "SHA-224"}, {"SHA (SHA-1)", "SHA"}, {"MD5", "MD5"} ]} /> <.input field={@form[:snmpv3_auth_password]} type="password" label={t("Auth Password")} placeholder={t("Min 8 characters")} autocomplete="off" /> <% end %> <%= if @form[:snmpv3_security_level].value == "authPriv" do %> <.input field={@form[:snmpv3_priv_protocol]} type="select" label={t("Privacy Protocol")} prompt="Select protocol" options={[ {"AES-128 (recommended)", "AES"}, {"AES-256", "AES-256"}, {"AES-192", "AES-192"}, {"AES-256-C", "AES-256-C"}, {"DES (legacy)", "DES"} ]} /> <.input field={@form[:snmpv3_priv_password]} type="password" label={t("Privacy Password")} placeholder={t("Min 8 characters")} autocomplete="off" /> <% end %> <% end %> <.input field={@form[:snmp_port]} type="number" label={t("SNMP Port")} placeholder={t("Leave blank to inherit from organization (default: 161)")} /> <%= if @live_action == :edit and @site.snmp_community do %>

{t("Force Apply to Site Device")}

{t("This will override SNMP settings for ALL devices at this site.")}

<.button type="button" phx-click="apply_snmp_to_all" data-confirm={ t("This will replace SNMP settings for ALL devices at this site. Are you sure?") } variant="danger" > <.icon name="hero-arrow-path" class="h-4 w-4" /> Apply SNMP Config to All Device
<% end %>
<%= if false and @current_scope.user.is_superuser do %>

{t("MikroTik API Configuration")} (optional)

{t( "Override organization MikroTik API defaults for all devices at this site. Leave blank to inherit from organization. Only applies to MikroTik devices." )}

<.icon name="hero-beaker" class="h-4 w-4 inline" /> {t("Experimental Feature:")} {t("MikroTik API integration is under active development.")}

<.input field={@form[:mikrotik_enabled]} type="checkbox" label={t("Enable MikroTik API")} /> <%= if @form[:mikrotik_enabled].value do %> <.input field={@form[:mikrotik_username]} type="text" label={t("Username")} placeholder={t("Leave blank to inherit from organization")} /> <.input field={@form[:mikrotik_password]} type="password" label={t("Password")} placeholder={t("Leave blank to inherit from organization")} /> <.input field={@form[:mikrotik_port]} type="number" label={t("API Port")} placeholder="8729 (SSL) or 8728 (plain)" /> <.input field={@form[:mikrotik_use_ssl]} type="checkbox" label={t("Use SSL (API-SSL)")} /> <%= if @form[:mikrotik_use_ssl].value == false do %>

🚨 Critical Security Warning: {t( "Plain API (port 8728) sends credentials unencrypted over the network. This setting is" )} blocked for devices using cloud pollers and should only be used with local agents on trusted networks.

<% else %>

⚠️ Security Warning: {t( "Plain API (port 8728) sends credentials unencrypted. Use SSL (port 8729) whenever possible." )}

<% end %> <% end %>
<% end %>
<.button phx-disable-with={t("Saving...")} variant="primary">Save Site <.button navigate={~p"/sites"}>{t("Cancel")}
<%= if @live_action == :edit do %>

{t("Danger Zone")}

{t( "Once you delete a site, there is no going back. This will also delete all devices at this site." )}

<.button phx-click="delete" data-confirm={ t( "Are you sure you want to delete this site? This will also delete all devices at this site." ) } variant="danger" > <.icon name="hero-trash" class="h-4 w-4" /> Delete Site
<% end %>