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 %>

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