import type { ItemTemplate } from "lit-html/directives/repeat.js";
import { type RenderKeyArg } from "../../Directives/arrayRender";
import { type AtomType } from "./atom";
/** Input row: object with optional key field (default `id`). */
export type ListItemInput = T & {
[P in K]?: string;
};
/** Stored row: plain object with a required, readonly key field. */
export type ListRow = Omit & {
readonly [P in K]: string;
};
/** Ensure each object has `keyName`; generate uuid when missing. Key is readonly. */
export declare function ensureListItemKey(item: ListItemInput, keyName?: K): ListRow;
/**
* Build a keyed object array from primitives or objects.
* Primitives become `{ [keyName]: uuid, value: item }` with a readonly key.
* Objects get `keyName` stamped readonly when missing.
*
* @example
* atom.list(createList(["a", "b"]))
* atom.list(createList([{ name: "x" }]))
*/
export declare function createList(items?: readonly T[], keyName?: K): Array : {
value: T;
} & {
readonly [P in K]: string;
}>;
export type ListAtomType = Omit[]>, "update" | "set"> & {
(): ListRow[];
get(): ListRow[];
/** Property name used as the stable key (default `"id"`). */
readonly keyName: K;
/**
* Replace the whole list (or map from previous rows).
* Every item must be a plain object; missing keys are stamped.
* Throws if any two rows share the same key.
*/
setList(value: readonly ListItemInput[] | ((prev: ListRow[]) => readonly ListItemInput[]), silently?: boolean): void;
/** Append an object. Stamps `keyName` when missing. Returns the key. Throws on duplicate key. */
add(item: ListItemInput): string;
/**
* Delete by key or index.
* Key lookup uses the first matching row (keys are required to be unique on write).
*/
delete(keyOrIndex: string | number): ListAtomType;
/**
* Return the row at `keyOrIndex`, or `undefined`.
* Key lookup uses the first matching row. Does not notify.
*/
getItem(keyOrIndex: string | number): ListRow | undefined;
/**
* Whether a row exists at `keyOrIndex` (index in range, or key present).
* Key lookup uses the first matching row. Does not notify.
*/
has(keyOrIndex: string | number): boolean;
/**
* Move an item (by key or index) to `toIndex`.
* `toIndex` is applied after removal (same as `atom.array.move`).
* No-op if either side is out of range.
*/
move(fromKeyOrIndex: string | number, toIndex: number): ListAtomType;
/**
* Mutate one row by key/index in place, then notify via `set(get())`.
* The key field is readonly — delete the item and `add` a new one to change identity.
* Key lookup uses the first matching row. No-op (no notify) if missing.
*/
updateItem(keyOrIndex: string | number, fn: (item: ListRow) => void): ListAtomType;
/**
* Mutate every row in place, then notify via `set(get())`.
* Key fields are readonly.
*/
updateAll(fn: (item: ListRow, index: number) => void): ListAtomType;
deleteItems(pred: (item: ListRow, index: number) => boolean): ListAtomType;
clear(): ListAtomType;
sort(compareFn?: (a: ListRow, b: ListRow) => number): ListRow[];
sortAndSet(compareFn?: (a: ListRow, b: ListRow) => number): ListAtomType;
forEach(fn: (item: ListRow, index: number, arr: ListRow[]) => void): void;
render(template: ItemTemplate>, key?: RenderKeyArg>): unknown;
/** `JSON.stringify` of the current row array. */
toJSON(): string;
readonly size: number;
};
/**
* Ordered keyed list of **plain objects** (for dynamic UI lists).
*
* Keys (`id` by default, or custom `keyName`) are stamped **readonly** and must
* be unique. To change an item's identity, `delete` it and `add` a new row.
* Lookups by key (`getItem`, `has`, `delete`, `updateItem`) use the first match.
*
* Primitives are not allowed — use {@link createList} first:
*
* ```ts
* atom.list(createList(["a", "b"]))
* atom.list([{ name: "x" }]) // id auto-stamped (readonly)
* atom.list([{ uuid: "1", name: "x" }], "uuid")
* ```
*/
export declare function createListAtom(initial?: readonly ListItemInput[], keyName?: K): ListAtomType;
//# sourceMappingURL=createListAtom.d.ts.map