<%= @ammo_type.name %>

<%= @ammo_type.desc %>
<.link patch={Routes.ammo_type_show_path(Endpoint, :edit, @ammo_type)} class="text-primary-600 link" aria-label={dgettext("actions", "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={ dgettext("actions", "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:") %>

<%= @rounds %> <%= if @show_used do %>

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

<%= @used_rounds %>

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

<%= @historical_round_count %> <% end %>

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

<%= @packs_count %> <%= if @show_used do %>

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

<%= @used_packs_count %>

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

<%= @historical_packs_count %> <% end %>

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

<.datetime id={"#{@ammo_type.id}-inserted-at"} datetime={@ammo_type.inserted_at} /> <%= if @avg_cost_per_round do %>

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

<%= gettext("$%{amount}", amount: display_currency(@avg_cost_per_round)) %> <% 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} show_used={@show_used} > <:container :let={{_ammo_group, %{name: container_name} = container}}> <.link navigate={Routes.container_show_path(Endpoint, :show, container)} class="mx-2 my-1 link" > <%= container_name %> <:actions :let={%{count: ammo_group_count} = ammo_group}>
<.link navigate={Routes.ammo_group_show_path(Endpoint, :show, ammo_group)} class="text-primary-600 link" aria-label={ dgettext("actions", "View ammo group of %{ammo_group_count} bullets", ammo_group_count: ammo_group_count ) } >
<% else %>
<.ammo_group_card :for={%{id: ammo_group_id, container_id: container_id} = ammo_group <- @ammo_groups} ammo_group={ammo_group} original_count={@original_counts && Map.fetch!(@original_counts, ammo_group_id)} cpr={Map.get(@cprs, ammo_group_id)} last_used_date={Map.get(@last_used_dates, ammo_group_id)} current_user={@current_user} container={Map.fetch!(@containers, container_id)} />
<% 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} />