{gettext("Ammo")}

<%= cond do %> <% @containers_count == 0 -> %>

{dgettext("prompts", "You'll need to")}

<.link navigate={~p"/containers/new"} class="btn btn-primary"> {dgettext("actions", "add a container first")}
<% @types_count == 0 -> %>

{dgettext("prompts", "You'll need to")}

<.link navigate={~p"/catalog/new"} class="btn btn-primary"> {dgettext("actions", "add a type first")}
<% @packs_count == 0 -> %>

{gettext("No ammo")} {display_emoji("😔")}

<.link patch={~p"/ammo/new"} class="btn btn-primary"> {dgettext("actions", "Add your first box!")} <% true -> %> <.link patch={~p"/ammo/new"} class="btn btn-primary"> {dgettext("actions", "Add Ammo")}
<.form :let={f} for={%{}} as={:type} phx-change="change_class" phx-submit="change_class" class="flex items-center" > {label(f, :class, gettext("Class"), class: "title text-primary-600 text-lg text-center")} {select( f, :class, [ {gettext("All"), :all}, {gettext("Rifle"), :rifle}, {gettext("Shotgun"), :shotgun}, {gettext("Pistol"), :pistol} ], class: "mx-2 my-1 min-w-20 input input-primary", value: @class )} <.form :let={f} for={%{}} as={:search} phx-change="search" phx-submit="search" class="flex items-center grow" > {text_input(f, :search_term, class: "grow input input-primary", phx_debounce: 300, placeholder: gettext("Search ammo"), role: "search", value: @search )} <.toggle_button action="toggle_show_used" value={@show_used}> {gettext("Show used")}
<%= if @packs |> Enum.empty?() do %>

{gettext("No Ammo")} {display_emoji("😔")}

<% else %> <.live_component module={CanneryWeb.Components.PackTableComponent} id="pack-index-table" packs={@packs} current_user={@current_user} show_used={@show_used} > <:type :let={%{name: type_name} = type}> <.link navigate={~p"/type/#{type}"} class="link"> {type_name} <:range :let={pack}>
<.link patch={~p"/ammo/add_shot_record/#{pack}"} class="mx-2 my-1 text-sm btn btn-primary" > {dgettext("actions", "Record shots")}
<:container :let={{pack, %{name: container_name} = container}}>
<.link navigate={~p"/container/#{container}"} class="mx-2 my-1 link"> {container_name} <.link patch={~p"/ammo/move/#{pack}"} class="mx-2 my-1 text-sm btn btn-primary"> {dgettext("actions", "Move ammo")}
<:actions :let={%{count: pack_count} = pack}>
<.link navigate={~p"/ammo/show/#{pack}"} class="text-primary-600 link" aria-label={ dgettext("actions", "View pack of %{pack_count} bullets", pack_count: pack_count ) } > <.link patch={~p"/ammo/edit/#{pack}"} class="text-primary-600 link" aria-label={ dgettext("actions", "Edit pack of %{pack_count} bullets", pack_count: pack_count ) } > <.link patch={~p"/ammo/clone/#{pack}"} class="text-primary-600 link" aria-label={ dgettext("actions", "Clone pack of %{pack_count} bullets", pack_count: pack_count ) } > <.link href="#" class="text-primary-600 link" phx-click="delete" phx-value-id={pack.id} data-confirm={dgettext("prompts", "Are you sure you want to delete this ammo?")} aria-label={ dgettext("actions", "Delete pack of %{pack_count} bullets", pack_count: pack_count ) } >
<% end %> <% end %>
<%= case @live_action do %> <% create when create in [:new, :edit, :clone] -> %> <.modal return_to={~p"/ammo"}> <.live_component module={CanneryWeb.PackLive.FormComponent} id={@pack.id || :new} title={@page_title} action={@live_action} pack={@pack} return_to={~p"/ammo"} current_user={@current_user} /> <% :add_shot_record -> %> <.modal return_to={~p"/ammo"}> <.live_component module={CanneryWeb.Components.AddShotRecordComponent} id={:new} title={@page_title} action={@live_action} pack={@pack} return_to={~p"/ammo"} current_user={@current_user} /> <% :move -> %> <.modal return_to={~p"/ammo"}> <.live_component module={CanneryWeb.Components.MovePackComponent} id={@pack.id} title={@page_title} action={@live_action} pack={@pack} return_to={~p"/ammo"} current_user={@current_user} /> <% _ -> %> <% end %>