// 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 { getEventValue } from './event-value.js';
const eventPropKeyRegExp = /^(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;
const namespacedEventKeyRegExp = /^[A-Za-z-]+:(?:global-bind|bind|catch|capture-bind|capture-catch)[A-Za-z]+$/;
function isEventPropKey(key) {
    return eventPropKeyRegExp.test(key);
}
function isSpreadRecord(value) {
    return value !== null && typeof value === 'object' && !Array.isArray(value);
}
export function prepareSpreadAttrSlot(handleId, attrSlotIndex, value, _context) {
    if (value === false || !isSpreadRecord(value)) {
        return null;
    }
    const prepared = {};
    for (const key in value) {
        const spreadValue = value[key];
        if (key === '__spread' || key === '__self' || key === '__source') {
            continue;
        }
        if (key === 'class' || key === 'className') {
            prepared['class'] = (spreadValue ?? '');
            continue;
        }
        if (isEventPropKey(key)) {
            prepared[key] = spreadValue === null || spreadValue === undefined || spreadValue === false
                ? null
                : getEventValue(handleId, attrSlotIndex, key);
            continue;
        }
        if (spreadValue === undefined
            || key === 'ref'
            || key.endsWith(':ref')
            || key.endsWith(':gesture')
            || namespacedEventKeyRegExp.test(key)
            || typeof spreadValue === 'function') {
            continue;
        }
        prepared[key] = spreadValue;
    }
    return prepared;
}
//# sourceMappingURL=spread.js.map