{"version":3,"file":"nodeToValue.cjs","names":["isAtomic","isCompound","tupleOf"],"sources":["../../../src/states/functions/nodeToValue.ts"],"sourcesContent":["import tupleOf from '#bemedev/features/arrays/castings/tuple';\nimport type { ConfigNode } from '#machines';\nimport type { StateValue } from '../types';\nimport { isAtomic, isCompound } from './checks';\n\nexport type NodeToValue_F = (body: ConfigNode) => StateValue;\n\n/**\n * Converts a state machine config into a StateValue.\n *\n * @param body - The state machine configuration to process.\n * @returns A value representation of the state machine, which can be a string,\n *         an object, or an empty object if the state is atomic.\n *\n * @see {@linkcode NodeToValue_F} for more details\n * @see {@linkcode isAtomic} for checking atomic states\n * @see {@linkcode isCompound} for checking compound states\n */\nexport const nodeToValue: NodeToValue_F = body => {\n  if (isAtomic(body)) return {};\n\n  if (isCompound(body)) {\n    // const length = entries.length;\n    const __id = body.initial;\n    const initial = body.states[__id];\n\n    const check4 = !!initial && isAtomic(initial);\n    if (check4) return __id;\n\n    const keys = Object.keys(body.states);\n\n    if (keys.length === 1) {\n      const key = keys[0];\n      const value = body.states[key];\n      if (isAtomic(value)) return key;\n    }\n  }\n\n  const entries = Object.entries(body.states);\n\n  const entries2 = entries.map(([key, body]) => {\n    const __id = body.initial;\n    if (__id) {\n      const initial = body.states[__id];\n      if (initial) {\n        if (isAtomic(initial)) return tupleOf(key, __id);\n        return tupleOf(key, { [__id]: nodeToValue(initial) });\n      }\n    }\n\n    return tupleOf(key, nodeToValue(body as any));\n  });\n\n  const out = entries2.reduce((acc, [key, value]) => {\n    acc[key] = value;\n    return acc;\n  }, {} as any);\n\n  return out;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAa,eAA6B,SAAQ;AAChD,KAAIA,yCAAAA,SAAS,KAAK,CAAE,QAAO,EAAE;AAE7B,KAAIC,2CAAAA,WAAW,KAAK,EAAE;EAEpB,MAAM,OAAO,KAAK;EAClB,MAAM,UAAU,KAAK,OAAO;AAG5B,MADe,CAAC,CAAC,WAAWD,yCAAAA,SAAS,QAAQ,CACjC,QAAO;EAEnB,MAAM,OAAO,OAAO,KAAK,KAAK,OAAO;AAErC,MAAI,KAAK,WAAW,GAAG;GACrB,MAAM,MAAM,KAAK;GACjB,MAAM,QAAQ,KAAK,OAAO;AAC1B,OAAIA,yCAAAA,SAAS,MAAM,CAAE,QAAO;;;AAwBhC,QApBgB,OAAO,QAAQ,KAAK,OAAO,CAElB,KAAK,CAAC,KAAK,UAAU;EAC5C,MAAM,OAAO,KAAK;AAClB,MAAI,MAAM;GACR,MAAM,UAAU,KAAK,OAAO;AAC5B,OAAI,SAAS;AACX,QAAIA,yCAAAA,SAAS,QAAQ,CAAE,QAAOE,0DAAQ,KAAK,KAAK;AAChD,WAAOA,0DAAQ,KAAK,GAAG,OAAO,YAAY,QAAQ,EAAE,CAAC;;;AAIzD,SAAOA,0DAAQ,KAAK,YAAY,KAAY,CAAC;GAC7C,CAEmB,QAAQ,KAAK,CAAC,KAAK,WAAW;AACjD,MAAI,OAAO;AACX,SAAO;IACN,EAAE,CAAQ"}