defmodule CanneryWeb.Components.ContainerCard do @moduledoc """ Display card for a container """ use CanneryWeb, :component import CanneryWeb.Components.TagCard alias Cannery.{Containers, Containers.Container, Repo} alias CanneryWeb.Endpoint alias Phoenix.LiveView.Rendered attr :container, Container, required: true slot(:tag_actions) slot(:inner_block) @spec container_card(assigns :: map()) :: Rendered.t() def container_card(%{container: container} = assigns) do assigns = assigns |> assign(container: container |> Repo.preload([:tags, :ammo_groups])) |> assign_new(:tag_actions, fn -> [] end) ~H"""
<.link navigate={Routes.container_show_path(Endpoint, :show, @container)} class="link">

<%= @container.name %>

<%= if @container.desc do %> <%= gettext("Description:") %> <%= @container.desc %> <% end %> <%= gettext("Type:") %> <%= @container.type %> <%= if @container.location do %> <%= gettext("Location:") %> <%= @container.location %> <% end %> <%= unless @container.ammo_groups |> Enum.empty?() do %> <%= gettext("Packs:") %> <%= @container |> Containers.get_container_ammo_group_count!() %> <%= gettext("Rounds:") %> <%= @container |> Containers.get_container_rounds!() %> <% end %>
<%= unless @container.tags |> Enum.empty?() do %> <%= for tag <- @container.tags do %> <.simple_tag_card tag={tag} /> <% end %> <% end %> <%= render_slot(@tag_actions) %>
<%= if assigns |> Map.has_key?(:inner_block) do %>
<%= render_slot(@inner_block) %>
<% end %>
""" end end