defmodule BerrypodWeb.Shop.Cart do
  use BerrypodWeb, :live_view

  alias Berrypod.{Cart, Pages}

  @impl true
  def mount(_params, _session, socket) do
    page = Pages.get_page("cart")
    {:ok, socket |> assign(:page_title, "Cart") |> assign(:page, page)}
  end

  @impl true
  def render(assigns) do
    assigns = assign(assigns, :cart_page_subtotal, Cart.calculate_subtotal(assigns.cart_items))

    ~H"""
    <BerrypodWeb.PageRenderer.render_page {assigns} />
    """
  end
end
