'use strict';

const fieldOverrideCache = /* @__PURE__ */ new Map();
const createCacheKey = (layer) => {
  const propsHash = JSON.stringify(layer.props);
  return `${layer.type}-${layer.id}-${propsHash}`;
};
const generateFieldOverrides = (registry, layer) => {
  const componentDefinition = registry[layer.type];
  if (!componentDefinition) {
    return {};
  }
  if (!componentDefinition.fieldOverrides) {
    return {};
  }
  const cacheKey = createCacheKey(layer);
  if (fieldOverrideCache.has(cacheKey)) {
    return fieldOverrideCache.get(cacheKey);
  }
  const fieldOverrides = {};
  Object.keys(componentDefinition.fieldOverrides).forEach((key) => {
    const override = componentDefinition.fieldOverrides?.[key];
    if (override) {
      fieldOverrides[key] = override(layer);
    }
  });
  fieldOverrideCache.set(cacheKey, fieldOverrides);
  if (fieldOverrideCache.size > 100) {
    const firstKey = fieldOverrideCache.keys().next().value;
    if (firstKey) {
      fieldOverrideCache.delete(firstKey);
    }
  }
  return fieldOverrides;
};
function isPrimitiveComponent(component) {
  return component.from === void 0 || component.from === null;
}

exports.generateFieldOverrides = generateFieldOverrides;
exports.isPrimitiveComponent = isPrimitiveComponent;
