import * as react_jsx_runtime from 'react/jsx-runtime';
import * as React$1 from 'react';
import { CSSProperties, ReactNode } from 'react';

type TreeDensity = 'compact' | 'cozy' | 'comfortable';
type TreeAccentIntensity = 'subtle' | 'default' | 'strong';
type TreeRadius = 'none' | 'sm' | 'md';
/**
 * Cosmetic configuration. Every field is optional; missing values fall
 * back to the `cozy` preset (a comfortable VSCode-Explorer-like density).
 *
 * Customize the look without re-implementing slots.
 */
interface TreeAppearance {
    /** Built-in size preset. Default: `'cozy'`. */
    density?: TreeDensity;
    /** Override row height in px (wins over density). */
    rowHeight?: number;
    /** Override icon + chevron size in px (wins over density). */
    iconSize?: number;
    /** Lucide stroke width for icon + chevron. Default: 1.5. */
    iconStrokeWidth?: number;
    /** Override label font size in px (wins over density). */
    fontSize?: number;
    /** Pixels between chevron / icon / label. Default depends on density. */
    gap?: number;
    /** Pixels between nesting levels. Default: 16. */
    indent?: number;
    /** Hover / selected highlight intensity. Default: `'default'`. */
    accent?: TreeAccentIntensity;
    /** Row corner radius. Default: `'sm'`. */
    radius?: TreeRadius;
    /** Indent-guide line opacity (0..1). Default: 0.4. */
    indentGuideOpacity?: number;
    /**
     * Show a 2px primary-tinted bar on the left of the selected row.
     * Mimics the VSCode active-tab indicator. Default: `true`.
     */
    showActiveIndicator?: boolean;
}
interface ResolvedAppearance {
    density: TreeDensity;
    rowHeight: number;
    iconSize: number;
    iconStrokeWidth: number;
    fontSize: number;
    gap: number;
    indent: number;
    accent: TreeAccentIntensity;
    radius: TreeRadius;
    indentGuideOpacity: number;
    showActiveIndicator: boolean;
}
declare const DEFAULT_TREE_APPEARANCE: ResolvedAppearance;
/**
 * Merge a partial appearance with the default + density preset.
 *
 * Explicit numeric overrides (e.g. `rowHeight`) win over the density preset.
 */
declare function resolveAppearance(input?: TreeAppearance, 
/** Outer `indent` prop (kept on TreeRoot for back-compat). */
outerIndent?: number): ResolvedAppearance;
/**
 * Build the `style` object that exposes the resolved appearance to any
 * descendant via CSS variables. Set on `<TreeRoot>`'s outer div.
 */
declare function appearanceToStyle(a: ResolvedAppearance): CSSProperties;

type TreeItemId = string;
/** A single node in the consumer's tree data. Generic over your payload. */
interface TreeNode<T = unknown> {
    id: TreeItemId;
    data: T;
    /** Inline children. Omit (and provide a `loadChildren`) for async loading. */
    children?: TreeNode<T>[];
    /**
     * Set to `true` to mark a node as a folder even when its `children` array
     * is empty (e.g. an unloaded async folder). Default: derived from
     * `Array.isArray(children)`.
     */
    isFolder?: boolean;
    /** Disable interaction. */
    disabled?: boolean;
}
interface TreeLabels {
    loading: string;
    empty: string;
    error: string;
    searchPlaceholder: string;
    searchMatches: (count: number) => string;
    ariaLabel: string;
}
declare const DEFAULT_TREE_LABELS: TreeLabels;
type TreeSelectionMode = 'none' | 'single' | 'multiple';
/**
 * Async loader: called the first time a folder is expanded with no inline
 * `children`. Result is cached; concurrent expansions are de-duplicated.
 */
type TreeLoadChildren<T> = (node: TreeNode<T>) => Promise<TreeNode<T>[]>;
interface TreeRowRenderProps<T> {
    node: TreeNode<T>;
    level: number;
    isSelected: boolean;
    isExpanded: boolean;
    isFocused: boolean;
    isFolder: boolean;
    isLoading: boolean;
    isMatchingSearch: boolean;
}
type TreeRowSlot<T> = (props: TreeRowRenderProps<T>) => ReactNode;
type TreeContextMenuSlot<T> = (props: TreeRowRenderProps<T>, trigger: ReactNode) => ReactNode;
interface TreeRootProps<T> {
    /** Root nodes. Top-level items are rendered directly (no synthetic root). */
    data: TreeNode<T>[];
    /** Returns the human-readable name for a node (used by search/type-ahead). */
    getItemName: (node: TreeNode<T>) => string;
    /** Async loader for folders without inline `children`. */
    loadChildren?: TreeLoadChildren<T>;
    /** Selection behaviour. Default: `'single'`. */
    selectionMode?: TreeSelectionMode;
    /** Initially expanded ids. */
    initialExpandedIds?: TreeItemId[];
    /** Initially selected ids. */
    initialSelectedIds?: TreeItemId[];
    /** Pixels of indent per nesting level. Default: 16. (Shortcut for `appearance.indent`.) */
    indent?: number;
    /** Cosmetic configuration: density, sizes, accent intensity, radius. */
    appearance?: TreeAppearance;
    /** Triggered when selection changes. */
    onSelectionChange?: (selectedIds: TreeItemId[]) => void;
    /** Triggered when expanded set changes. */
    onExpansionChange?: (expandedIds: TreeItemId[]) => void;
    /** Enter / dblclick on a node. */
    onActivate?: (node: TreeNode<T>) => void;
    /** Show built-in search input. Default: false. */
    enableSearch?: boolean;
    /** Type printable letters to jump to a matching name. Default: true. */
    enableTypeAhead?: boolean;
    /** Render vertical indent guides under expanded folders. Default: false. */
    showIndentGuides?: boolean;
    /** Custom row renderer. Falls back to the default <TreeRow />. */
    renderRow?: TreeRowSlot<T>;
    /** Replace default folder/file icon. */
    renderIcon?: TreeRowSlot<T>;
    /** Replace default label rendering. */
    renderLabel?: TreeRowSlot<T>;
    /** Right-side actions slot (per row). */
    renderActions?: TreeRowSlot<T>;
    /** Wrap each row in a context menu (right-click). Receives the row meta + trigger element. */
    renderContextMenu?: TreeContextMenuSlot<T>;
    /** Override built-in copy in your locale. */
    labels?: Partial<TreeLabels>;
    /** Persist expanded + (optional) selected ids in localStorage under this key. */
    persistKey?: string;
    /** Persist selection alongside expansion. Default: false. */
    persistSelection?: boolean;
    className?: string;
    style?: React.CSSProperties;
}
/** Internal flat-row representation used by the renderer + keyboard nav. */
interface FlatRow<T> {
    node: TreeNode<T>;
    level: number;
    parentId: TreeItemId | null;
    isFolder: boolean;
    isExpanded: boolean;
    isLoading: boolean;
    hasError: boolean;
}

/**
 * High-level entry point. Wraps Provider + (optional) search bar + content.
 *
 * For full control, compose with <TreeProvider>, <TreeContent>,
 * <TreeSearchInput>, <TreeRow>, etc. directly from `@djangocfg/ui-tools/tree`.
 */
declare function TreeRoot<T>(props: TreeRootProps<T>): react_jsx_runtime.JSX.Element;

type ChildEntryStatus = 'idle' | 'loading' | 'loaded' | 'error';
interface ChildEntry<T> {
    status: ChildEntryStatus;
    children: TreeNode<T>[];
    error?: string;
}
type ChildCache<T> = Map<TreeItemId, ChildEntry<T>>;
declare const createChildCache: <T>() => ChildCache<T>;
/**
 * Resolve a node's children for the current render.
 *
 * - If the node carries inline `children`, those win (no async fetch).
 * - Otherwise we look in the cache.
 *
 * Returns `null` when nothing is loaded yet (caller may show a skeleton).
 */
declare const resolveChildren: <T>(cache: ChildCache<T>, node: TreeNode<T>) => {
    children: TreeNode<T>[] | null;
    status: ChildEntryStatus;
    error?: string;
};

interface TreeContextValue<T> {
    expanded: ReadonlySet<TreeItemId>;
    selected: ReadonlySet<TreeItemId>;
    focused: TreeItemId | null;
    query: string;
    flatRows: FlatRow<T>[];
    /** Search-matching node ids (subset of all flatRows). */
    matchingIds: ReadonlySet<TreeItemId>;
    expand: (id: TreeItemId) => void;
    collapse: (id: TreeItemId) => void;
    toggle: (id: TreeItemId) => void;
    expandAll: () => void;
    collapseAll: () => void;
    select: (id: TreeItemId) => void;
    setSelectedIds: (ids: TreeItemId[]) => void;
    clearSelection: () => void;
    setFocus: (id: TreeItemId | null) => void;
    setQuery: (q: string) => void;
    refresh: (id: TreeItemId) => Promise<void>;
    refreshAll: () => Promise<void>;
    activate: (node: TreeNode<T>) => void;
    labels: TreeLabels;
    /** Resolved cosmetic config — never null. */
    appearance: ResolvedAppearance;
    /** Convenience alias for `appearance.indent`. */
    indent: number;
    selectionMode: TreeSelectionMode;
    enableSearch: boolean;
    showIndentGuides: boolean;
    getItemName: (node: TreeNode<T>) => string;
    renderIcon?: TreeRowSlot<T>;
    renderLabel?: TreeRowSlot<T>;
    renderActions?: TreeRowSlot<T>;
    renderContextMenu?: TreeContextMenuSlot<T>;
}
declare function useTreeContext<T>(): TreeContextValue<T>;
interface TreeProviderProps<T> extends Pick<TreeRootProps<T>, 'data' | 'getItemName' | 'loadChildren' | 'selectionMode' | 'initialExpandedIds' | 'initialSelectedIds' | 'indent' | 'appearance' | 'onSelectionChange' | 'onExpansionChange' | 'onActivate' | 'enableSearch' | 'showIndentGuides' | 'renderIcon' | 'renderLabel' | 'renderActions' | 'renderContextMenu' | 'labels' | 'persistKey' | 'persistSelection'> {
    children: React$1.ReactNode;
}
declare function TreeProvider<T>(props: TreeProviderProps<T>): react_jsx_runtime.JSX.Element;

declare function useTreeLabels(): TreeLabels;
declare function useTreeRows<T>(): FlatRow<T>[];
declare function useTreeSelection<T>(): {
    selectedIds: string[];
    select: (id: TreeItemId) => void;
    setSelectedIds: (ids: TreeItemId[]) => void;
    clear: () => void;
    isSelected: (id: TreeItemId) => boolean;
};
declare function useTreeExpansion<T>(): {
    expandedIds: string[];
    expand: (id: TreeItemId) => void;
    collapse: (id: TreeItemId) => void;
    toggle: (id: TreeItemId) => void;
    expandAll: () => void;
    collapseAll: () => void;
    isExpanded: (id: TreeItemId) => boolean;
};
declare function useTreeFocus<T>(): {
    focusedId: string;
    setFocus: (id: TreeItemId | null) => void;
};
declare function useTreeSearch<T>(): {
    isOpen: boolean;
    query: string;
    setQuery: (q: string) => void;
    matchingIds: ReadonlySet<string>;
    matchCount: number;
};
declare function useTreeActions<T>(): {
    expand: (id: TreeItemId) => void;
    collapse: (id: TreeItemId) => void;
    toggle: (id: TreeItemId) => void;
    expandAll: () => void;
    collapseAll: () => void;
    refresh: (id: TreeItemId) => Promise<void>;
    refreshAll: () => Promise<void>;
    activate: (node: TreeNode<T>) => void;
};

interface UseTreeTypeAheadOptions<T> {
    /** Visible flat rows in render order. */
    rows: FlatRow<T>[];
    /** How to read the displayed name of a node (matched case-insensitively). */
    getItemName: (node: TreeNode<T>) => string;
    /** Element receiving keydown events. */
    containerRef: React.RefObject<HTMLElement | null>;
    /** Called with the matched node id so the consumer can focus / scroll. */
    onMatch: (id: string) => void;
    /** Disable without removing the call site. */
    enabled?: boolean;
}
/**
 * Type-ahead jump (Finder / VSCode style).
 *
 * Builds a rolling buffer of printable keys (within ~600 ms of each other)
 * and notifies the consumer of the first row whose name starts with that
 * prefix. Resets on Esc / Enter / navigation keys / timeout.
 */
declare function useTreeTypeAhead<T>({ rows, getItemName, containerRef, onMatch, enabled, }: UseTreeTypeAheadOptions<T>): void;

interface UseTreeKeyboardOptions<T> {
    rows: FlatRow<T>[];
    focusedId: TreeItemId | null;
    enabled?: boolean;
    onFocus: (id: TreeItemId) => void;
    onSelect: (id: TreeItemId) => void;
    onActivate: (id: TreeItemId) => void;
    onExpand: (id: TreeItemId) => void;
    onCollapse: (id: TreeItemId) => void;
    onClearSelection: () => void;
}
interface UseTreeKeyboardReturn {
    /** Attach to the tree container. Hotkeys only fire when focus is inside. */
    ref: (instance: HTMLElement | null) => void;
}
/**
 * Standard tree keyboard navigation, scoped to the container ref.
 *
 *  - ↑ / ↓ : prev / next visible row
 *  - Home / End : first / last visible row
 *  - → : expand folder; if already expanded, jump to first child
 *  - ← : collapse folder; if already collapsed (or leaf), jump to parent
 *  - Enter / Space : activate (folder => toggle, leaf => onActivate)
 *  - Esc : clear selection
 *
 * Built on `useHotkey` (react-hotkeys-hook) — focus gating is automatic; no
 * manual `addEventListener` or `data-scope` juggling.
 */
declare function useTreeKeyboard<T>({ rows, focusedId, enabled, onFocus, onSelect, onActivate, onExpand, onCollapse, onClearSelection, }: UseTreeKeyboardOptions<T>): UseTreeKeyboardReturn;

interface TreeChevronProps {
    isExpanded: boolean;
    isFolder: boolean;
    className?: string;
}
declare function TreeChevron({ isExpanded, isFolder, className }: TreeChevronProps): react_jsx_runtime.JSX.Element;

interface TreeIconProps {
    isFolder: boolean;
    isExpanded: boolean;
    className?: string;
}
declare function TreeIcon({ isFolder, isExpanded, className }: TreeIconProps): react_jsx_runtime.JSX.Element;

interface TreeLabelProps {
    children: React.ReactNode;
    isMatchingSearch?: boolean;
    className?: string;
}
declare function TreeLabel({ children, isMatchingSearch, className }: TreeLabelProps): react_jsx_runtime.JSX.Element;

interface TreeRowProps<T> {
    row: FlatRow<T>;
    className?: string;
}
declare function TreeRow<T>({ row, className }: TreeRowProps<T>): react_jsx_runtime.JSX.Element;

interface TreeContentProps<T> {
    /** Custom row renderer; falls back to <TreeRow />. */
    children?: TreeRowSlot<T>;
    className?: string;
    /** Override aria-label for the container. */
    ariaLabel?: string;
}
declare function TreeContent<T>({ children, className, ariaLabel }: TreeContentProps<T>): react_jsx_runtime.JSX.Element;

interface TreeSearchInputProps {
    className?: string;
    showMatches?: boolean;
}
declare function TreeSearchInput({ className, showMatches }: TreeSearchInputProps): react_jsx_runtime.JSX.Element;

interface TreeEmptyProps {
    children: React.ReactNode;
    className?: string;
}
declare function TreeEmpty({ children, className }: TreeEmptyProps): react_jsx_runtime.JSX.Element;

interface TreeSkeletonProps {
    rows?: number;
    className?: string;
}
declare function TreeSkeleton({ rows, className }: TreeSkeletonProps): react_jsx_runtime.JSX.Element;

interface TreeErrorProps {
    children: React.ReactNode;
    className?: string;
}
declare function TreeError({ children, className }: TreeErrorProps): react_jsx_runtime.JSX.Element;

interface TreeIndentGuidesProps {
    level: number;
    indent: number;
}
/**
 * Vertical guide lines under nested rows. Renders one absolute-positioned
 * 1px column per ancestor level. Decorative — `aria-hidden` and
 * pointer-events disabled. Opacity comes from the tree appearance.
 */
declare function TreeIndentGuides({ level, indent }: TreeIndentGuidesProps): react_jsx_runtime.JSX.Element;

interface FlattenInput<T> {
    roots: TreeNode<T>[];
    expandedIds: ReadonlySet<TreeItemId>;
    cache: ChildCache<T>;
}
/**
 * Walk the tree top-to-bottom and produce a flat list of visible rows.
 *
 * Visibility rule: a child row appears only when every ancestor is in
 * `expandedIds`. The output is ordered exactly as it should render,
 * which keeps keyboard navigation (next/prev row) trivial.
 */
declare function flattenTree<T>({ roots, expandedIds, cache }: FlattenInput<T>): FlatRow<T>[];

interface PersistedTreeState {
    expandedItems: TreeItemId[];
    selectedItems: TreeItemId[];
}
declare function loadTreeState(key: string): PersistedTreeState | null;
declare function saveTreeState(key: string, state: PersistedTreeState): void;
declare function clearTreeState(key: string): void;

interface DemoNode {
    name: string;
}
/**
 * Build a deterministic synthetic tree for stories and tests.
 *
 * @example
 *   const data = createDemoTree({ depth: 4, breadth: 3 });
 *   <TreeRoot data={data} getItemName={(n) => n.data.name} />
 */
declare function createDemoTree({ depth, breadth, rootPrefix, }?: {
    depth?: number;
    breadth?: number;
    rootPrefix?: string;
}): TreeNode<DemoNode>[];

export { type ChildCache, type ChildEntry, type ChildEntryStatus, DEFAULT_TREE_APPEARANCE, DEFAULT_TREE_LABELS, type DemoNode, type FlatRow, type FlattenInput, type PersistedTreeState, type ResolvedAppearance, TreeRoot as Tree, type TreeAccentIntensity, type TreeAppearance, TreeChevron, type TreeChevronProps, TreeContent, type TreeContentProps, type TreeContextMenuSlot, type TreeContextValue, type TreeDensity, TreeEmpty, type TreeEmptyProps, TreeError, type TreeErrorProps, TreeIcon, type TreeIconProps, TreeIndentGuides, type TreeIndentGuidesProps, type TreeItemId, TreeLabel, type TreeLabelProps, type TreeLabels, type TreeLoadChildren, type TreeNode, TreeProvider, type TreeProviderProps, type TreeRadius, TreeRoot, type TreeRootProps, TreeRow, type TreeRowProps, type TreeRowRenderProps, type TreeRowSlot, TreeSearchInput, type TreeSearchInputProps, type TreeSelectionMode, TreeSkeleton, type TreeSkeletonProps, type UseTreeKeyboardOptions, type UseTreeTypeAheadOptions, appearanceToStyle, clearTreeState, createChildCache, createDemoTree, TreeRoot as default, flattenTree, loadTreeState, resolveAppearance, resolveChildren, saveTreeState, useTreeActions, useTreeContext, useTreeExpansion, useTreeFocus, useTreeKeyboard, useTreeLabels, useTreeRows, useTreeSearch, useTreeSelection, useTreeTypeAhead };
