/*
* Copyright (C) 2025 Jonni Liljamo <jonni@liljamo.com>
*
* This file is licensed under GPL-3.0-only, see NOTICE and LICENSE for
* more information.
*/
package types
import (
"fmt"
"io"
"strings"
"git.src.quest/~skye/tamma/styles"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
)
// TargetItem represents a target item.
type TargetItem struct {
Name string
IP string
Data map[string]interface{}
}
// FilterValue returns the value to filter on.
func (i TargetItem) FilterValue() string { return i.Name }
// TargetItemDelegate represents the visual of a TargetItem.
type TargetItemDelegate struct{}
// Height returns the needed height.
func (d TargetItemDelegate) Height() int { return 1 }
// Spacing returns the needed spacing.
func (d TargetItemDelegate) Spacing() int { return 0 }
// Update is the tea update loop.
func (d TargetItemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil }
// Render renders the component.
func (d TargetItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
i, ok := listItem.(TargetItem)
if !ok {
return
}
str := fmt.Sprintf("%s", i.Name)
fn := styles.ListItem.Render
if index == m.Index() {
fn = func(s ...string) string {
return styles.ListItemSelected.Render("> " + strings.Join(s, " "))
}
}
fmt.Fprint(w, fn(str))
}