// Copyright 2025 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { componentAtIndexFactory, enqueueComponentFactory, gRecycleMap, gSignMap } from '../list/list.js';
import { hydrate } from '../renderToOpcodes/hydrate.js';
const destroyLifetimeHandlerMap = new Map();
export function snapshotCreateList(pageId, _ctx, _expIndex) {
    const signMap = new Map();
    const recycleMap = new Map();
    const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory([], hydrate);
    const list = __CreateList(pageId, componentAtIndex, enqueueComponentFactory(), {}, componentAtIndexes);
    const listID = __GetElementUniqueID(list);
    if (typeof lynx !== 'undefined' && typeof lynx.getNative === 'function') {
        const cb = () => {
            __UpdateListCallbacks(list, null, null, null);
            destroyLifetimeHandlerMap.delete(listID);
        };
        lynx.getNative()?.addEventListener('__DestroyLifetime', cb);
        destroyLifetimeHandlerMap.set(listID, cb);
    }
    gSignMap[listID] = signMap;
    gRecycleMap[listID] = recycleMap;
    return list;
}
export function snapshotDestroyList(si) {
    const [, elementIndex] = si.__snapshot_def.slot[0];
    const list = si.__elements[elementIndex];
    const listID = __GetElementUniqueID(list);
    __UpdateListCallbacks(list, () => -1, () => { }, () => { });
    if (typeof lynx !== 'undefined' && typeof lynx.getNative === 'function') {
        const cb = destroyLifetimeHandlerMap.get(listID);
        if (cb) {
            lynx.getNative()?.removeEventListener('__DestroyLifetime', cb);
            destroyLifetimeHandlerMap.delete(listID);
        }
    }
    delete gSignMap[listID];
    delete gRecycleMap[listID];
}
//# sourceMappingURL=list.js.map