# `PhoenixKitPhotos.Viewer`
[🔗](https://github.com/BeamLabEU/phoenix_kit_photos/blob/v0.3.0/lib/phoenix_kit_photos/viewer.ex#L1)

Which viewer a library's photos open in.

Two are offered:

  * `"photoswipe"` — the swipe viewer (`PhoenixKitPhotos.Components.PhotoTimeline`'s `pager`,
    engine `photoswipe`): swipe between photos and videos, pinch and double-tap zoom, drag
    down to close;
  * `"classic"` — PhoenixKit's own media viewer (`MediaCanvasViewer`), one file at a time
    with its sidebar and comments.

A library chooses one. The choice is this package's own setting for the library
(`Libraries.module_setting(library, "photos", "viewer")`, kept in the library's `settings`
under this package's namespace, so it follows the library and not the browser, and core knows
nothing of it). A library that has not chosen
follows `default/0`: `config :phoenix_kit_photos, default_viewer: "classic"`, otherwise
`"photoswipe"`. A name stored that this package does not offer (an engine it no longer
has) is ignored: the library follows the default.

The viewer's *engines* (`assets/js/viewer`) are a finer list than this one: `snap` is an
engine and is not offered here.

# `can_set?`

```elixir
@spec can_set?(
  PhoenixKit.Users.Auth.Scope.t() | nil,
  PhoenixKit.Modules.Storage.Library.t() | nil
) ::
  boolean()
```

Whether `scope` may choose the viewer of `library`: a user library's owner and managers,
and for a system library (Media) the site's owners and admins.

# `chosen`

```elixir
@spec chosen(PhoenixKit.Modules.Storage.Library.t() | String.t() | nil) ::
  String.t() | nil
```

A library's own choice, or nil when it follows the default.

# `default`

```elixir
@spec default() :: String.t()
```

The viewer a library follows until it chooses.

# `for_library`

```elixir
@spec for_library(PhoenixKit.Modules.Storage.Library.t() | String.t() | nil) ::
  String.t()
```

The viewer for a library (or its uuid; nil is Media): its own choice, or the
default when it has none or a name this package does not offer.

# `options`

```elixir
@spec options() :: [{String.t(), String.t()}]
```

The viewers a library can choose between, as `{name, label}`.

# `pager`

```elixir
@spec pager(String.t()) :: false | String.t()
```

What `PhotoTimeline`'s `pager` takes for a viewer: `false` for the classic one (the host
opens its own on `on_open`), the engine's name for the swipe viewer.

# `put`

```elixir
@spec put(
  PhoenixKit.Users.Auth.Scope.t() | nil,
  PhoenixKit.Modules.Storage.Library.t(),
  String.t() | nil
) ::
  {:ok, PhoenixKit.Modules.Storage.Library.t()}
  | {:error, :not_allowed | :unknown_viewer | term()}
```

Sets the viewer of `library` for `scope`: a name from `options/0`, or nil to follow the
default. `{:error, :not_allowed}` for someone who may not, `{:error, :unknown_viewer}`
for a name not offered.

---

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