/**
 * TreeView type definitions
 * @countermeasure/web-components/components/tree-view
 */

export interface TreeNode {
  /** Stable unique identifier used for selection state. */
  id: string
  /** Display text for the node. */
  label: string
  /** Optional icon HTML rendered before the label. */
  icon?: string
  /** Free-form classifier (e.g. `'file'`, `'folder'`) consumed by the renderer. */
  type?: string
  /**
   * Whether the node renders an expand chevron.
   * @default false
   */
  expandable?: boolean
  /**
   * Initial expanded state for `expandable` nodes.
   * @default false
   */
  expanded?: boolean
  /** Statically-known child nodes. */
  children?: TreeNode[]
  /** Async loader invoked the first time the node is expanded. */
  lazyLoad?: () => Promise<TreeNode[]>
  /** Arbitrary application data attached to the node. */
  data?: unknown
}

export interface TreeViewConfig {
  /** Container element (or selector) the tree is mounted into. */
  container: HTMLElement | string
  /**
   * Initial tree data.
   * @default []
   */
  data?: TreeNode[]
  /**
   * Show a search box that filters visible nodes.
   * @default false
   */
  searchable?: boolean
  /** Called when a node is selected via click or keyboard. */
  onSelect?: (node: TreeNode) => void
  /** Called when a node is double-clicked. */
  onDoubleClick?: (node: TreeNode) => void
  /** Called when a node is expanded. */
  onExpand?: (node: TreeNode) => void
}
