> ## Documentation Index
> Fetch the complete documentation index at: https://ziva.zeleza.ru/llms.txt
> Use this file to discover all available pages before exploring further.

# MultiSelectTask

> Multiple option selection task from a list

# MultiSelectTask

`MultiSelectTask` allows users to select one or multiple items from a list.

## Creating

```go theme={null}
options := []ziva.Item{
    {Key: "item1", Name: "Item 1"},
    {Key: "item2", Name: "Item 2"},
    {Key: "item3", Name: "Item 3"},
}
task := ziva.NewMultiSelectTask("Select components", options)
```

<img src="https://mintcdn.com/terem/7tfdR1JkDhuUAiXc/images/pic_3.png?fit=max&auto=format&n=7tfdR1JkDhuUAiXc&q=85&s=918fdf279421f245c36981d6fe37018c" alt="Screenshot: multi-select task" width="966" height="499" data-path="images/pic_3.png" />

## Main Methods

```go theme={null}
// Settings
task.WithSelectAll(                                 // add "select all" option with custom texts and style
    "Select all",                                   // label when the action enables everything
    "Deselect all",                                 // label when everything is already selected
    ziva.MenuActionDefaultStyle(),                  // optional style (defaults to highlighted cyan)
)
task.WithDefaultItems([]string{"item1", "item2"})   // default selected keys
task.WithViewport(5, true)                          // viewport window
task.WithItemsDisabled([]string{"item3"})           // disable items by key

// Get results
selected := task.GetSelected() // []string
```

## Advanced configuration

### Dependencies between items

`WithDependencies` lets you describe relationships between options. Each map entry uses a `MultiSelectDependencyRule` with actions that run when the trigger item is selected or deselected. Actions accept item keys:

* `Disable` / `Enable` — temporarily lock or unlock other options.
* `ForceSelect` — automatically mark related items (for required prerequisites).
* `ForceClear` — unselect items that are no longer valid.

```go theme={null}
diagnostics := []ziva.Item{
    {Key: "logging", Name: "Logging"},
    {Key: "debug", Name: "Debug"},
    {Key: "tracing", Name: "Tracing"},
    {Key: "metrics", Name: "Metrics"},
}

rules := map[string]ziva.MultiSelectDependencyRule{
    "logging": {
        OnSelect: ziva.MultiSelectDependencyActions{
            Enable: []string{"debug"},
        },
        OnDeselect: ziva.MultiSelectDependencyActions{
            Disable:    []string{"debug"},
            ForceClear: []string{"debug", "tracing"},
        },
    },
    "debug": {
        OnSelect: ziva.MultiSelectDependencyActions{
            ForceSelect: []string{"logging"},
        },
    },
    "tracing": {
        OnSelect: ziva.MultiSelectDependencyActions{
            ForceSelect: []string{"logging"},
        },
    },
}

task := ziva.NewMultiSelectTask("Diagnostics", diagnostics).
    WithDependencies(rules).
    WithDefaultItems([]string{"logging", "metrics"})
```

### Optional empty selection

Multi-select tasks allow confirming with no items selected by default. Call `WithRequireSelection(true)` if you want to enforce the classic “select at least one item” rule and show the localized hint when Enter is pressed without a choice.

### Select-all shortcut styling

`WithSelectAll` accepts up to three arguments:

1. Label that appears when the shortcut will select every option (defaults to the localized “Select all” string).
2. Label that replaces it after all items are picked (defaults to the localized “Deselect all”).
3. Optional `lipgloss.Style` for the shortcut itself. If you skip it, Ziva highlights the entry with a cyan bold style (`ziva.MenuActionDefaultStyle()`), so it stands out from regular list elements. Pass `ziva.MenuItemDefaultStyle()` if you prefer it to look like the rest of the menu.

## Usage Example

```go theme={null}
components := []ziva.Item{
    {Key: "web", Name: "web", Description: "Web server"},
    {Key: "api", Name: "api", Description: "REST API"},
    {Key: "db", Name: "db", Description: "Database"},
}

task := ziva.NewMultiSelectTask("Components", components).
    WithSelectAll("Install all", "Disable all", ziva.MenuActionDefaultStyle()).
    WithDefaultItems([]string{"web", "api"})

queue := ziva.NewQueue("Setup")
queue.AddTasks(task)
queue.Run()

fmt.Printf("Selected: %v\n", task.GetSelected()) // keys of selected items
```
