{"version":3,"file":"toDelay.cjs","names":["reduceFnMap"],"sources":["../../../src/delays/functions/toDelay.ts"],"sourcesContent":["import type { PrimitiveObject } from '#bemedev/globals/types';\nimport type {\n  ActorsConfigMap,\n  EventsMap,\n  ToEventObject,\n  ToEvents,\n} from '#events';\nimport { reduceFnMap } from '#utils';\nimport type { DelayFunction3, DelayMap } from '../types';\n\nexport type ToDelay_F = <\n  E extends EventsMap = EventsMap,\n  A extends ActorsConfigMap = ActorsConfigMap,\n  Pc = any,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  T extends string = string,\n  Eo extends ToEventObject<ToEvents<E, A>> = ToEventObject<ToEvents<E, A>>,\n>(\n  events: E,\n  actorsMap: A,\n  delay: string,\n  delays?: DelayMap<Eo, Pc, Tc, T>,\n) => DelayFunction3<Eo, Pc, Tc, T> | undefined;\n\n/**\n * Converts a delay configuration to a function that returns the delay in milliseconds.\n * If the delay is a number, it returns a function that returns that number.\n * If the delay is a function, it reduces the function map with the provided events and actors.\n *\n * @param events of type {@linkcode EventsMap} [E], the events map to use for resolving the delay.\n * @param actorsMap of type {@linkcode ActorsConfigMap} [A], the actors map to use for resolving the delay.\n * @param delay of type string,  The delay configuration.\n * @param delays of type {@linkcode DelayMap}, the map of delays containing functions to execute.\n * @returns a function that returns the delay in milliseconds or undefined if not found.\n *\n * @see {@linkcode PrimitiveObject}\n * @see {@linkcode reduceFnMap}\n */\nexport const toDelay: ToDelay_F = (events, actorsMap, delay, delays) => {\n  const fn = delays?.[delay];\n  const check = typeof fn === 'number';\n  if (check) return () => fn;\n\n  const func = fn ? reduceFnMap(events, actorsMap, fn) : undefined;\n  return func;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsCA,MAAa,WAAsB,QAAQ,WAAW,OAAO,WAAW;CACtE,MAAM,KAAK,SAAS;AAEpB,KADc,OAAO,OAAO,SACjB,cAAa;AAGxB,QADa,KAAKA,0BAAAA,YAAY,QAAQ,WAAW,GAAG,GAAG,KAAA"}