defmodule AprsmeWeb.LayoutsTest do
  use ExUnit.Case, async: true

  import Phoenix.LiveViewTest

  alias AprsmeWeb.Layouts

  describe "body_class/1" do
    test "returns the default light/dark-aware class list" do
      result = Layouts.body_class(%{})
      [classes] = result
      assert classes =~ "bg-white"
      assert classes =~ "dark:bg-gray-900"
      assert classes =~ "text-gray-900"
      assert classes =~ "dark:text-white"
      assert classes =~ "antialiased"
    end

    test "ignores assigns content" do
      assert Layouts.body_class(%{theme: "dark"}) == Layouts.body_class(%{})
      assert Layouts.body_class(%{whatever: 42}) == Layouts.body_class(%{})
    end
  end

  describe "app/1 template" do
    test "renders the site header and inner content" do
      html =
        render_component(&Layouts.app/1, %{
          current_user: nil,
          flash: %{},
          map_page: false,
          inner_content: Phoenix.HTML.raw("<p>inner-content-marker</p>")
        })

      assert html =~ "aprs.me"
      assert html =~ "inner-content-marker"
      # Default map_page is false, so data-map-page="false" is emitted.
      assert html =~ ~s(data-map-page="false")
    end

    test "emits data-map-page=\"true\" for map pages" do
      html =
        render_component(&Layouts.app/1, %{
          current_user: nil,
          flash: %{},
          map_page: true,
          inner_content: Phoenix.HTML.raw("")
        })

      assert html =~ ~s(data-map-page="true")
      assert html =~ "min-h-screen"
    end
  end

  describe "root/1 template" do
    test "renders the root layout with the inner content" do
      html =
        render_component(&Layouts.root/1, %{
          current_user: nil,
          inner_content: Phoenix.HTML.raw("<main>root-layout-marker</main>"),
          conn: %Plug.Conn{},
          page_title: nil
        })

      assert html =~ "root-layout-marker"
      assert html =~ "<html"
      assert html =~ "</html>"
    end
  end
end
