<%= @ammo_type.name %>

<%= @ammo_type.desc %>
<.link patch={Routes.ammo_type_show_path(Endpoint, :edit, @ammo_type)} class="text-primary-600 link" aria-label={gettext("Edit %{ammo_type_name}", ammo_type_name: @ammo_type.name)} > <.link href="#" class="text-primary-600 link" phx-click="delete" data-confirm={ dgettext( "prompts", "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!", name: @ammo_type.name ) } aria-label={gettext("Delete %{ammo_type_name}", ammo_type_name: @ammo_type.name)} >

<%= if @fields_to_display do %>
<%= for %{label: label, key: key, type: type} <- @fields_list do %> <%= if @ammo_type |> Map.get(key) do %>

<%= label %>

<%= case type do %> <% :boolean -> %> <%= @ammo_type |> Map.get(key) |> humanize() %> <% _ -> %> <%= @ammo_type |> Map.get(key) %> <% end %> <% end %> <% end %>

<% end %>

<%= gettext("Rounds:") %>

<%= @ammo_type |> Ammo.get_round_count_for_ammo_type(@current_user) %>

<%= gettext("Used rounds:") %>

<%= @ammo_type |> Ammo.get_used_count_for_ammo_type(@current_user) %>

<%= gettext("Total ever rounds:") %>

<%= @ammo_type |> Ammo.get_historical_count_for_ammo_type(@current_user) %>

<%= gettext("Packs:") %>

<%= @ammo_type |> Ammo.get_ammo_groups_count_for_type(@current_user) %>

<%= gettext("Used packs:") %>

<%= @ammo_type |> Ammo.get_used_ammo_groups_count_for_type(@current_user) %>

<%= gettext("Total ever packs:") %>

<%= @ammo_type |> Ammo.get_ammo_groups_count_for_type(@current_user, true) %>

<%= gettext("Added on:") %>

<.datetime datetime={@ammo_type.inserted_at} /> <%= if @avg_cost_per_round do %>

<%= gettext("Average CPR") %>:

<%= gettext("$%{amount}", amount: @avg_cost_per_round |> :erlang.float_to_binary(decimals: 2) ) %> <% else %>

<%= gettext("No cost information") %>

<% end %>

<.toggle_button action="toggle_show_used" value={@show_used}> <%= gettext("Show used") %> <.toggle_button action="toggle_table" value={@view_table}> <%= gettext("View as table") %>
<%= if @ammo_groups |> Enum.empty?() do %>

<%= gettext("No ammo for this type") %> <%= display_emoji("😔") %>

<% else %> <%= if @view_table do %> <.live_component module={CanneryWeb.Components.AmmoGroupTableComponent} id="ammo-type-show-table" ammo_groups={@ammo_groups} current_user={@current_user} > <:container :let={%{container: %{name: container_name} = container}}> <.link navigate={Routes.container_show_path(Endpoint, :show, container)} class="mx-2 my-1 link" > <%= container_name %> <% else %>
<.ammo_group_card :for={ammo_group <- @ammo_groups} ammo_group={ammo_group} show_container={true} />
<% end %> <% end %>
<.modal :if={@live_action == :edit} return_to={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)} > <.live_component module={CanneryWeb.AmmoTypeLive.FormComponent} id={@ammo_type.id} title={@page_title} action={@live_action} ammo_type={@ammo_type} return_to={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)} current_user={@current_user} />