defmodule PhoenixKit.Modules.Shop.Web.Components.ShopLayouts do
@moduledoc """
Shared layout components for the shop storefront public pages.
Provides two components:
- `shop_public_layout/1` - Public navbar + flash + main content wrapper for guest users
- `shop_layout/1` - Top-level layout dispatcher: dashboard for authenticated, public/app for guests
"""
use Phoenix.Component
import PhoenixKitWeb.Components.Core.Icon, only: [icon: 1]
import PhoenixKitWeb.Components.Core.Flash, only: [flash_group: 1]
import PhoenixKitWeb.Components.Core.LanguageSwitcher, only: [language_switcher_dropdown: 1]
import PhoenixKitWeb.LayoutHelpers, only: [dashboard_assigns: 1]
alias PhoenixKit.Modules.Shop
alias PhoenixKit.Utils.Routes
@doc """
Public shop layout with navbar, flash messages, and main content area.
Used for guest users on catalog/category/product pages.
"""
slot :inner_block, required: true
attr :current_language, :string, required: true
attr :current_path, :string, required: true
attr :flash, :map, required: true
def shop_public_layout(assigns) do
~H"""
<%!-- Simple navbar for shop --%>
<%!-- Flash messages --%>
<.flash_group flash={@flash} />
<%!-- Wide content area --%>
{render_slot(@inner_block)}
"""
end
@doc """
Top-level layout wrapper for shop pages.
Routes to:
- Dashboard layout for authenticated users
- `shop_public_layout` for guests when `show_sidebar` is true (catalog/category/product pages)
- `LayoutWrapper.app_layout` for guests when `show_sidebar` is false (cart/checkout pages)
"""
slot :inner_block, required: true
attr :authenticated, :boolean, required: true
attr :show_sidebar, :boolean, default: false
attr :flash, :map, required: true
attr :phoenix_kit_current_scope, :any, required: true
attr :url_path, :string, required: true
attr :current_locale, :string, required: true
attr :page_title, :string, required: true
attr :sidebar_after_shop, :any, default: nil
# Used when show_sidebar is true (catalog/category/product pages)
attr :current_language, :string, default: nil
attr :current_path, :string, default: nil
def shop_layout(assigns) do
~H"""
<%= if @authenticated do %>
{render_slot(@inner_block)}
<% else %>
<%= if @show_sidebar do %>
<.shop_public_layout
flash={@flash}
current_language={@current_language}
current_path={@current_path}
>
{render_slot(@inner_block)}
<% else %>
{render_slot(@inner_block)}
<% end %>
<% end %>
"""
end
end