<.breadcrumb items={[ %{label: "Dashboard", navigate: ~p"/dashboard"}, %{label: "Settings"} ]} />

{t("Organization Settings")}

{t("Manage organization defaults, integrations, and configuration")}

<%= if @active_tab not in ["integrations", "members"] do %> <.form for={@form} id="organization-form" phx-change="validate" phx-submit="save" data-1p-ignore data-form-type="other" >
<%= if @active_tab == "general" do %>

{t("Organization Name")}

{t("Update the name of your organization.")}

<.input field={@form[:name]} type="text" label={t("Organization Name")} required />
<%= if @user_orgs_count > 1 do %>

{t("Default Organization")}

{t( "Set this organization as your default. When you log in, you'll be directed to your default organization." )}

<%= if @membership.is_default do %>
<.icon name="hero-check-circle" class="h-5 w-5 text-green-600 dark:text-green-400" />

{t("This is your default organization")}

<% else %>

{t("Click to make this your default organization")}

<% end %>
<% end %>

{t("Site Organization")}

{t( "Enable site organization to group devices into physical locations (offices, datacenters, etc.)." )}

<.input field={@form[:use_sites]} type="checkbox" label={t("Use sites to organize devices")} />

{t( "When enabled, you can organize devices into sites. When disabled, all devices belong directly to the organization." )}

<%= if @organization.use_sites && @form[:use_sites].value == false do %>
<.icon name="hero-exclamation-triangle" class="h-5 w-5 text-amber-400" />

{t("Warning: Disabling Sites")}

{t( "All devices will be removed from their current sites and assigned directly to the organization." )} {t( "Site assignments will be lost, but devices will remain in the organization." )}

<% end %>

{t("Alert Routing")}

{t("Choose how alerts are routed for on-call notifications.")}

{t("Alert routing method")}
<% routing_value = to_string(@form[:alert_routing].value || "builtin") %>
<% end %> <%= if @active_tab == "snmp" do %>

{t("SNMP Configuration")}

{t( "Set default SNMP settings for all devices in this organization. These can be overridden at the site or device level." )}

<.icon name="hero-information-circle" class="h-4 w-4 inline" /> Hierarchy: Device > Site > Organization

<.input field={@form[:snmp_version]} type="select" label={t("SNMP Version")} prompt="Select SNMP version" 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="e.g., public" /> <% 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="e.g., snmpuser" /> <%= 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="161" /> <%= if @organization.snmp_community do %>

{t("Force Apply to All Devices")}

{t( "This will override SNMP settings for ALL devices across all sites in this organization." )}

<% end %>
<% end %> <%= if false && @active_tab == "mikrotik" && @current_scope.user.is_superuser do %>

{t("MikroTik API Configuration")}

{t( "Set default MikroTik RouterOS API credentials for all devices in this organization. Only applies to devices detected as MikroTik." )}

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

<.icon name="hero-information-circle" class="h-4 w-4 inline" /> Hierarchy: Device > Site > Organization

<.input field={@form[:mikrotik_enabled]} type="checkbox" label={t("Enable MikroTik API")} />
<.input field={@form[:mikrotik_username]} type="text" label={t("Username")} placeholder="e.g., admin" autocomplete="off" />
<.input field={@form[:mikrotik_password]} type="password" label={t("Password")} placeholder={t("RouterOS API password")} autocomplete="off" />
<.input field={@form[:mikrotik_port]} type="number" label={t("API Port")} placeholder="8729" autocomplete="off" />
<.input field={@form[:mikrotik_use_ssl]} type="checkbox" label={t("Use SSL (API-SSL)")} />

{t("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.

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

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

{t("Default Agent")}

{t( "Select a default agent for SNMP polling. This will be used for all devices in this organization unless overridden at the site or device level." )}

<.icon name="hero-information-circle" class="h-4 w-4 inline" /> Hierarchy: Device > Site > Organization

<.input field={@form[:default_agent_token_id]} type="select" label={t("Default Remote Agent")} prompt="No default agent - cloud polling" options={Enum.map(@available_agents, &{&1.name, &1.id})} />

{t("Current Device Assignment:")}

<.icon name="hero-server" class="h-4 w-4" /> {@assignment_breakdown.direct} device-level override
<.icon name="hero-building-office" class="h-4 w-4" /> {@assignment_breakdown.site} inherited from site
<.icon name="hero-building-office-2" class="h-4 w-4" /> {@assignment_breakdown.organization} inheriting organization default
<.icon name="hero-cloud" class="h-4 w-4" /> {@assignment_breakdown.cloud} cloud polling (no agent)
<%= if @organization.default_agent_token_id do %>

{t("Force Apply to All Devices")}

{t( "This will assign the default agent to ALL devices across all sites in this organization." )}

<% end %>
<% else %>

{t("Default Agent")}

{t("No agents configured yet.")} <.link navigate={~p"/agents"} class="text-indigo-600 hover:text-indigo-700 dark:text-indigo-400 dark:hover:text-indigo-300" > {t("Create an agent")} to enable remote polling.

<% end %> <% end %>
<.link navigate={~p"/dashboard"} class="text-sm font-semibold text-gray-900 dark:text-white" > {t("Cancel")}
<% end %> <%= if @active_tab == "members" do %>
<%= if @membership.role in [:owner, :admin] do %>

{t("Invite a Team Member")}

{t("Send an invitation email to add someone to this organization.")}

<.form for={@invite_form} id="invite-form" phx-submit="send_invitation">
<.input field={@invite_form[:email]} type="email" label={t("Email address")} placeholder="colleague@example.com" required /> <.input field={@invite_form[:role]} type="select" label={t("Role")} options={[ {"Admin", "admin"}, {"Executive", "executive"}, {"Technician", "technician"}, {"Viewer", "viewer"} ]} />
<% end %> <%= if @pending_invitations != [] do %>

{t("Pending Invitations")}

{t("Invitations that haven't been accepted yet.")}

<%= if @membership.role in [:owner, :admin] do %> <% end %> <%= if @membership.role in [:owner, :admin] do %> <% end %>
{t("Email")} {t("Role")} {t("Sent")} {t("Expires")} {t("Actions")}
{invitation.email} {invitation.role} <.timestamp datetime={invitation.inserted_at} timezone={@timezone} format="relative" /> <.timestamp datetime={invitation.expires_at} timezone={@timezone} format="date" />
<% end %>

{t("Members")}

{t("People who have access to this organization.")}

<%= if @membership.role in [:owner, :admin] do %> <% end %> <%= if @membership.role in [:owner, :admin] do %> <% end %>
{t("User")} {t("Role")} {t("Joined")} {t("Actions")}
{member.user.email}
"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400" :admin -> "bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400" :executive -> "bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400" role when role in [:technician, :member] -> "bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400" :viewer -> "bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-400" end ]}> {member.role} <.timestamp datetime={member.inserted_at} timezone={@timezone} format="absolute" /> <%= if member.role != :owner do %>
<.button type="button" phx-click="remove_member" phx-value-user-id={member.user_id} data-confirm={t("Remove this member from the organization?")} variant="danger" > {t("Remove")}
<% end %>
<% end %> <%= if @active_tab == "integrations" do %>
<.icon name="hero-arrow-top-right-on-square" class="mx-auto h-10 w-10 text-indigo-400" />

{t("Integrations have moved to their own page")}

{t("Manage all your integrations from the dedicated integrations page.")}

<.link navigate={~p"/orgs/#{@organization.slug}/settings/integrations"} class="rounded-md bg-indigo-600 px-4 py-2.5 text-sm font-semibold text-white shadow-xs hover:bg-indigo-500 dark:bg-indigo-500 dark:hover:bg-indigo-400" > {t("Go to Integrations")}
<% end %> <%= if @active_tab == "billing" do %>

{t("Subscription & Billing")}

{t("Current Plan")}
{@organization.subscription_plan || "free"}
{t("Device Usage")}
{@current_devices} {t("devices")} <%= if @device_limit != :unlimited do %> / {@device_limit} {t("limit")} <% end %>
<%= if @organization.subscription_plan == "paid" do %>
{t("Estimated Monthly Cost")}
${@estimated_cost.cost_usd}

{@estimated_cost.billable} {t("billable devices")} × ${@estimated_cost.price_per_device}

<%= if @organization.subscription_status == "active" do %>

✓ {t("Subscription Active")}

<%= if @organization.subscription_current_period_end do %>

{t("Next billing")}: {Calendar.strftime( @organization.subscription_current_period_end, "%B %d, %Y" )}

<% end %>
<% end %> <%= if @organization.subscription_status == "past_due" do %>

⚠ {t("Payment Past Due")}

{t("Please update your payment method to avoid service interruption.")}

<% end %> <% else %>

{t("Free Plan - First %{count} devices included", count: @estimated_cost.free_included )}

{t("Upgrade to monitor unlimited devices at $%{price}/device/month", price: @estimated_cost.price_per_device )}

<% end %>
<%= if @organization.subscription_plan == "free" do %> <.button phx-click="upgrade_to_paid" class="btn-primary"> {t("Upgrade to Paid Plan")} <% else %> <.button phx-click="manage_billing" class="btn-secondary"> {t("Manage Billing")} <% end %>
<%= if @organization.subscription_plan == "paid" do %>

{t("Billing Information")}

{t("Subscription Status")}
{@organization.subscription_status}
<%= if @organization.subscription_current_period_start do %>
{t("Current Period Start")}
{Calendar.strftime(@organization.subscription_current_period_start, "%B %d, %Y")}
<% end %> <%= if @organization.subscription_current_period_end do %>
{t("Current Period End")}
{Calendar.strftime(@organization.subscription_current_period_end, "%B %d, %Y")}
<% end %> <%= if @organization.payment_method_status do %>
{t("Payment Method")}
{String.replace(@organization.payment_method_status, "_", " ")}
<% end %>
<% end %>
<% end %>