// Copyright 2026 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 { __etAttrPlanMap } from '../runtime/template/attr-slot-plan.js';
function normalizeAttributeSlots(rawSlots) {
    let normalizedSlots;
    for (let slotIndex = 0; slotIndex < rawSlots.length; slotIndex += 1) {
        const rawSlot = rawSlots[slotIndex];
        if (rawSlot !== undefined) {
            continue;
        }
        normalizedSlots ??= rawSlots.slice();
        normalizedSlots[slotIndex] = null;
    }
    return normalizedSlots ?? rawSlots;
}
export function prepareAttributeSlots(templateKey, handleId, rawSlots) {
    const attrPlan = __etAttrPlanMap[templateKey];
    if (!attrPlan || attrPlan.length === 0) {
        return normalizeAttributeSlots(rawSlots);
    }
    const normalizedSlots = normalizeAttributeSlots(rawSlots);
    const preparedSlots = normalizedSlots === rawSlots
        ? rawSlots.slice()
        : normalizedSlots;
    for (let planIndex = 0; planIndex < attrPlan.length; planIndex += 2) {
        const attrSlotIndex = attrPlan[planIndex];
        const adapter = attrPlan[planIndex + 1];
        const rawValue = rawSlots[attrSlotIndex];
        preparedSlots[attrSlotIndex] = adapter(handleId, attrSlotIndex, rawValue);
    }
    return preparedSlots;
}
//# sourceMappingURL=attr-slots.js.map