# `MishkaGervaz.Table.Web.Events.SelectionHandler`
[🔗](https://github.com/mishka-group/mishka_gervaz/blob/v0.0.1-alpha.3/lib/mishka_gervaz/table/web/events/selection_handler.ex#L1)

Handles selection operations for Events module.

This module provides functions for managing row selection state,
including individual selection, select-all, and clear selection.

## Customization

You can create a custom SelectionHandler:

    defmodule MyApp.CustomSelectionHandler do
      use MishkaGervaz.Table.Web.Events.SelectionHandler

      # Custom toggle that limits selection to 10 items
      def toggle_select(state, id) do
        if MapSet.size(state.selected_ids) >= 10 and
           not MapSet.member?(state.selected_ids, id) do
          {:error, :max_selection_reached}
        else
          super(state, id)
        end
      end
    end

Then configure it in your resource's DSL:

    mishka_gervaz do
      table do
        events do
          selection MyApp.CustomSelectionHandler
        end
      end
    end

See `MishkaGervaz.Table.Web.Events`,
`MishkaGervaz.Table.Web.State`,
and the sibling handlers `SanitizationHandler`, `RecordHandler`,
`BulkActionHandler`, `HookRunner`, `RelationFilterHandler`.

# `state`

```elixir
@type state() :: MishkaGervaz.Table.Web.State.t()
```

# `clear_selection`

```elixir
@callback clear_selection(state :: state()) :: state()
```

Clears all selection state.

Resets `select_all?`, `selected_ids`, and `excluded_ids`.
Returns the updated state.

# `get_selected_ids`

```elixir
@callback get_selected_ids(state :: state()) :: list() | :all | {:all_except, list()}
```

Returns the effective selected IDs for bulk actions.

Returns one of:
- `list()` - List of selected IDs
- `:all` - All items selected
- `{:all_except, list()}` - All items except the excluded ones

# `toggle_select`

```elixir
@callback toggle_select(state :: state(), id :: String.t()) :: state()
```

Toggles selection for a single row.

When `select_all?` is true, toggles the ID in `excluded_ids`.
When `select_all?` is false, toggles the ID in `selected_ids`.

Returns the updated state.

# `toggle_select_all`

```elixir
@callback toggle_select_all(state :: state()) :: state()
```

Toggles select-all state.

Resets both `selected_ids` and `excluded_ids` when toggling.
Returns the updated state.

---

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