<.link
navigate={
if @live_action == :edit,
do: ~p"/orgs/#{@organization.slug}/sites/#{@site.id}",
else: ~p"/orgs/#{@organization.slug}/sites"
}
class="inline-flex items-center gap-1 text-sm text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100"
>
<.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="Site Name" required />
<.input
field={@form[:parent_site_id]}
type="select"
label="Parent Site (optional)"
prompt="No parent site"
options={Enum.map(@available_parent_sites, &{&1.name, &1.id})}
/>
<.input field={@form[:location]} type="text" label="Location" />
<%= if @available_agents != [] do %>
<.input
field={@form[:agent_token_id]}
type="select"
label="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" />
Overriding organization default -
all equipment at this site will use this agent
<% 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 %>
Set a default agent for all equipment at this site. Equipment can override this setting individually.
<% end %>
<% end %>
<% end %>
<.input field={@form[:description]} type="textarea" label="Description" />
<.button phx-disable-with="Saving..." variant="primary">Save Site
<.button navigate={~p"/orgs/#{@organization.slug}/sites"}>Cancel
<%= if @live_action == :edit do %>
Danger Zone
Once you delete a site, there is no going back. This will also delete all equipment at this site.
<.button
phx-click="delete"
data-confirm="Are you sure you want to delete this site? This will also delete all equipment at this site."
variant="danger"
>
<.icon name="hero-trash" class="h-4 w-4" /> Delete Site
<% end %>