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

Helper functions for thread management in collaboration components.

Provides utilities for counting replies, extracting participants,
checking resolution status, and sorting/filtering thread collections.

# `filter_threads`

```elixir
@spec filter_threads(
  [map()],
  keyword()
) :: [map()]
```

Filter threads by criteria.

Supported options:
- `:user_id` — only threads where the user participated
- `:resolved` — only threads matching the resolved status

## Examples

    iex> filter_threads(threads, user_id: "user-1")
    [%{...}]

    iex> filter_threads(threads, resolved: false)
    [%{resolved: false, ...}]

# `sort_threads`

```elixir
@spec sort_threads([map()], atom()) :: [map()]
```

Sort threads by the given strategy.

Strategies:
- `:date` — newest first by `created_at`
- `:activity` — most recently active first (last comment time)
- `:unresolved_first` — unresolved threads before resolved ones

## Examples

    iex> sort_threads(threads, :unresolved_first)
    [%{resolved: false, ...}, %{resolved: true, ...}]

# `thread_is_resolved`

```elixir
@spec thread_is_resolved(map()) :: boolean()
```

Check if a thread is resolved.

## Examples

    iex> thread_is_resolved(%{resolved: true})
    true

    iex> thread_is_resolved(%{resolved: false})
    false

# `thread_participants`

```elixir
@spec thread_participants(map()) :: [String.t()]
```

Get unique participant user IDs in a thread.

## Examples

    iex> thread_participants(%{comments: [%{user_id: "a"}, %{user_id: "b"}, %{user_id: "a"}]})
    ["a", "b"]

# `thread_reply_count`

```elixir
@spec thread_reply_count(map()) :: non_neg_integer()
```

Count replies in a thread (excludes the root comment).

## Examples

    iex> thread_reply_count(%{comments: [%{}, %{}, %{}]})
    2

    iex> thread_reply_count(%{comments: []})
    0

    iex> thread_reply_count(%{})
    0

---

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