// 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 { deleteMainThreadDynamicAttrStateForSubtree, initializeMainThreadDynamicAttrSlots, } from './main-thread-dynamic-attr-state.js';
import { deleteElementTemplateNativeRef, setElementTemplateNativeRef } from './registry.js';
import { elementTemplateTypeTag } from '../../protocol/template-type.js';
// Main-thread IFR allocates ids as consecutive negative integers.
let nextId = -1;
export function reserveElementTemplateId() {
    const id = nextId--;
    return id;
}
export function createElementTemplateWithReservedHandle(handleId, templateKey, bundleUrl, attributeSlots, elementSlots) {
    const nativeRef = __CreateElementTemplate(templateKey, bundleUrl, attributeSlots, elementSlots, handleId);
    if (nativeRef) {
        setElementTemplateNativeRef(handleId, nativeRef);
        initializeMainThreadDynamicAttrSlots(handleId, elementTemplateTypeTag(templateKey, bundleUrl), attributeSlots);
    }
    return nativeRef;
}
export function createTypedElementTemplateWithReservedHandle(handleId, type, attributes, elementSlots, options) {
    const nativeRef = __CreateTypedElementTemplate(type, attributes, elementSlots, handleId, options);
    setElementTemplateNativeRef(handleId, nativeRef);
    return nativeRef;
}
export function resetTemplateId() {
    nextId = -1;
}
export function destroyElementTemplateId(id) {
    deleteElementTemplateNativeRef(id);
    deleteMainThreadDynamicAttrStateForSubtree([id]);
}
//# sourceMappingURL=handle.js.map