# `PgFlowDashboard.Router`
[🔗](https://github.com/agoodway/pgflow/blob/v0.1.0/lib/pgflow_dashboard/router.ex#L1)

Router macro for mounting the PgFlow Dashboard.

## Usage

    defmodule MyAppWeb.Router do
      use MyAppWeb, :router

      import PgFlowDashboard.Router

      scope "/" do
        pipe_through [:browser]

        pgflow_dashboard "/pgflow",
          repo: MyApp.Repo,
          pubsub: MyApp.PubSub
      end
    end

## Options

See `PgFlowDashboard.Config` for all available options.

Required:
  * `:repo` - The Ecto repository module
  * `:pubsub` - The Phoenix.PubSub module

Optional:
  * `:refresh_interval` - Polling interval (default: 5000ms)
  * `:time_zone` - Time zone for timestamps (default: "UTC")
  * `:default_time_range` - Default filter (default: :last_24h)
  * `:max_grid_runs` - Max runs in history grid (default: 50)

# `compute_base_path`

```elixir
@spec compute_base_path(String.t(), String.t()) :: String.t()
```

Derive the full base path by finding where the dashboard path appears
in the request URL. This handles outer scopes (e.g., "/admin/pgflow"
when `pgflow_dashboard("/pgflow")` is mounted inside `scope "/admin"`).

# `ensure_dashboard_dependencies!`

```elixir
@spec ensure_dashboard_dependencies!() :: :ok
```

Ensures optional dashboard dependencies are available before routes are mounted.

PgFlow can be used without PgFlowDashboard. When an application imports and
mounts `pgflow_dashboard/2`, the dashboard requires Phoenix LiveView,
LiveFilter, and Tz to be installed in the host project.

# `on_mount`

```elixir
@spec on_mount(:mount_dashboard, map(), map(), Phoenix.LiveView.Socket.t()) ::
  {:cont, Phoenix.LiveView.Socket.t()}
```

Mounts dashboard configuration into each PgFlowDashboard LiveView socket.

# `pgflow_dashboard`
*macro* 

```elixir
@spec pgflow_dashboard(
  String.t(),
  keyword()
) :: Macro.t()
```

Generates routes for the PgFlow Dashboard.

## Authentication

In production, you should protect the dashboard with authentication.
Use the `:on_mount` option to add an authentication hook:

    pgflow_dashboard "/pgflow",
      repo: MyApp.Repo,
      pubsub: MyApp.PubSub,
      on_mount: [{MyAppWeb.Auth, :ensure_admin}]

The `:on_mount` hooks are added to the LiveView session alongside
the dashboard's own mount hook. See `Phoenix.LiveView.Router` for
more information on `on_mount` hooks.

# `session`

```elixir
@spec session(Plug.Conn.t(), keyword(), String.t()) :: map()
```

Builds the LiveView session map used by PgFlowDashboard routes.

The session contains validated dashboard configuration and the resolved base
path for links inside the dashboard.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
