import { V as VegaSlimmer } from './global-slimmer-registry-17c4efd4.js';
import { c as createDynamicSlimmer } from './dynamic-slimmer-90b8af32.js';
import { g as getValueByPath, d as deepEqual } from './object-0c277f57.js';

/** DeprecatedPropertySlimmer compares new property with default value, if they are different, return new property; otherwise, return old property */
class DeprecatedPropertySlimmerBase extends VegaSlimmer {
  // eslint-disable-next-line jsdoc/require-jsdoc
  constructor({ newPropertyName, oldPropertyName, defaultValue, }) {
    super();
    this.newPropertyName = newPropertyName;
    this.oldPropertyName = oldPropertyName;
    this.defaultValue = defaultValue;
  }
  /**
   * The `getValue` function returns either the old property or the new property based on a deep equality
   * check.
   *
   * @typedef T generic type
   * @returns {T} The `getValue` method returns either the `oldProperty` or `newProperty` based on the result
   * of the `deepEqual` comparison between them. If `newProperty` is deeply equal to `oldProperty`, then
   * `oldProperty` is returned; otherwise, `newProperty` is returned.
   */
  getValue() {
    const newProperty = getValueByPath(this.host, this.newPropertyName);
    const oldProperty = getValueByPath(this.host, this.oldPropertyName);
    return deepEqual(newProperty, this.defaultValue) ? oldProperty : newProperty;
  }
}
/**
 * Create dynamic deprecated property slimmer
 *
 * @typedef K generic type
 * @param {ClassPrototype} mapFromClass - It represents the class that you want to map from.
 * @param {string} newPropertyName - The new prop name or name path
 * @param {string} oldPropertyName - The old prop name or name path
 * @param {unknown} defaultValue - The default value of the prop
 * @returns {DeprecatedPropertySlimmerBase<K>} - deprecated property slimmer
 */
function createDeprecatedPropertySlimmer(mapFromClass, newPropertyName, oldPropertyName, defaultValue) {
  return createDynamicSlimmer(mapFromClass, DeprecatedPropertySlimmerBase, [{ mapFrom: 'host', mapTo: 'host' }], [], [
    {
      newPropertyName: newPropertyName,
      oldPropertyName: oldPropertyName,
      defaultValue: defaultValue,
    },
  ]);
}

export { createDeprecatedPropertySlimmer as c };
