# `PhiaUi.Components.Collab.CollabHelpers`
[🔗](https://github.com/charlenopires/PhiaUI/blob/v0.1.17/lib/phia_ui/components/collab/collab_helpers.ex#L1)

Shared helper functions for collaboration components.

Provides utilities for time formatting, user display, color assignment,
mention rendering, and text truncation used across the Collab Suite.

# `collab_color`

```elixir
@spec collab_color(String.t() | any()) :: String.t()
```

Deterministic OKLCH color from a user_id hash for consistent color assignment.

Uses `:erlang.phash2/2` to generate a hue value (0-359) from the user_id
string, producing the same color for the same user across sessions.

## Examples

    iex> collab_color("user-1")
    "oklch(0.7 0.15 42)"  # deterministic hue from hash

# `format_mention`

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

Formats an @mention as a display string.

## Examples

    iex> format_mention("Alice")
    "@Alice"

# `format_relative_time`

```elixir
@spec format_relative_time(DateTime.t() | nil) :: String.t()
```

Formats a DateTime as a relative time string.

Returns human-readable strings like "just now", "2 minutes ago",
"Yesterday", "3 days ago", or a formatted date for older timestamps.

## Examples

    iex> format_relative_time(nil)
    ""

    iex> format_relative_time(~U[2026-03-19 12:00:00Z])
    "just now"  # if called within 5 seconds

# `truncate_preview`

```elixir
@spec truncate_preview(String.t() | nil, non_neg_integer()) :: String.t()
```

Truncates text to max_length characters with ellipsis appended.

Returns the original text if it is shorter than or equal to max_length.

## Examples

    iex> truncate_preview("Hello world", 5)
    "Hello..."

    iex> truncate_preview("Hi", 10)
    "Hi"

    iex> truncate_preview(nil, 10)
    ""

# `user_initials`

```elixir
@spec user_initials(String.t() | nil) :: String.t()
```

Returns initials from a user name (up to 2 characters).

Splits the name on whitespace, takes the first letter of the first
two words, and uppercases them.

## Examples

    iex> user_initials("Jane Doe")
    "JD"

    iex> user_initials("alice")
    "A"

    iex> user_initials(nil)
    "?"

---

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