import { c as MapToComponentField, M as MapToComponentMethod } from './global-slimmer-registry-0a7aa308.js';

/**
 * The `createDynamicSlimmer` function creates an instance of a dynamically generated class based on
 * mappings provided.
 *
 * @param mapFromClass - The `mapFromClass` parameter is the class prototype from which you want to
 * create a dynamic slimmer instance. It represents the class that you want to map from.
 * @param mapToClass - The `mapToClass` parameter is the class prototype that you want to create an
 * instance of. It represents the class that you want to map the properties and methods from
 * `mapFromClass` to.
 * @param {DynamicFieldMapEntry<T, U>[]} fieldsMap - An array of objects that define the mapping
 * between fields of the `mapFromClass` class and the `mapToClass` class. Each object in the array
 * should have the following properties:
 * @param {DynamicMethodMapEntry<T, U>[]} methodsMap - `methodsMap` is an array of
 * `DynamicMethodMapEntry` objects. Each `DynamicMethodMapEntry` object represents a mapping between a
 * method in the `mapFromClass` class and a method in the `mapToClass` class.
 * @param {unknown[]} initDatas - An array of unknown values that will be passed as arguments to the
 * constructor of the dynamically created class.
 * @returns The function `createDynamicSlimmer` returns an instance of the class
 * `mapFromClass.prototype[key]`, which is an instance of the dynamically created class.
 */
function createDynamicSlimmer(mapFromClass, mapToClass, fieldsMap = [], methodsMap = [], initDatas = []) {
  var _a;
  const key = [
    mapFromClass.name,
    mapToClass.name,
    ...fieldsMap.map((field) => field.mapFrom),
    ...methodsMap.map((method) => method.mapFrom),
  ].join('-');
  (_a = mapFromClass.prototype)[key] || (_a[key] = createDynamicClass(mapToClass, fieldsMap, methodsMap));
  return new mapFromClass.prototype[key](...initDatas);
}
/**
 * The function `createDynamicClass` creates a dynamic class by mapping fields and methods from one
 * class to another.
 *
 * @param mapToClass - The `mapToClass` parameter is the class prototype that you want to extend and
 * create a dynamic class from. It should be a valid class prototype that can be extended using the
 * `class extends` syntax in JavaScript.
 * @param {DynamicFieldMapEntry<T, U>[]} fieldsMap - An array of objects that define the mapping
 * between fields in the original class (T) and fields in the slimmer class (U). Each object in the
 * array should have the following properties:
 * @param {DynamicMethodMapEntry<T, U>[]} methodsMap - `methodsMap` is an array of objects that define
 * the mapping between methods of the original class (`mapFrom`) and the methods of the dynamic class
 * (`mapTo`). Each object in the array has the following properties:
 * @returns a dynamically created class prototype.
 */
const createDynamicClass = (mapToClass, fieldsMap, methodsMap) => {
  const slimmerClass = class extends mapToClass {
  };
  fieldsMap.forEach((fieldEntry) => {
    MapToComponentField(Object.assign(fieldEntry, { componentFieldName: fieldEntry.mapFrom }))(slimmerClass.prototype, fieldEntry.mapTo);
  });
  methodsMap.forEach((methodEntry) => {
    MapToComponentMethod(methodEntry.mapFrom)(slimmerClass.prototype, methodEntry.mapTo);
  });
  return slimmerClass;
};

export { createDynamicSlimmer as c };
