{"version":3,"file":"_getVariableProps.mjs","names":[],"sources":["../../../src/utils/variables/_getVariableProps.ts"],"sourcesContent":["import { VariableTransformationSuffix } from 'generaltranslation/types';\nimport { GTTag, VariableProps } from '../types';\nimport { getVariableName } from './getVariableName';\nimport { minifyVariableType } from 'generaltranslation/internal';\n\ntype VariableElementProps = {\n  'data-_gt': GTTag & {\n    transformation: 'variable';\n  };\n  [key: string]: unknown;\n};\n\nexport function isVariableElementProps(\n  props: unknown\n): props is VariableElementProps {\n  return (\n    typeof props === 'object' &&\n    !!props &&\n    'data-_gt' in props &&\n    typeof props['data-_gt'] === 'object' &&\n    !!props['data-_gt'] &&\n    'transformation' in props['data-_gt'] &&\n    props['data-_gt']?.transformation === 'variable'\n  );\n}\n\nexport function getVariableProps(props: VariableElementProps): VariableProps {\n  const variableType: VariableTransformationSuffix =\n    props['data-_gt']?.variableType || 'variable';\n\n  const result: VariableProps = {\n    variableName: getVariableName(props, variableType),\n    variableType: minifyVariableType(variableType),\n    injectionType: props['data-_gt']?.injectionType || 'manual',\n    variableValue: (() => {\n      if (typeof props.value !== 'undefined') return props.value;\n      if (typeof props.date !== 'undefined') return props.date;\n      if (typeof props['data-_gt-unformatted-value'] !== 'undefined')\n        return props['data-_gt-unformatted-value'];\n      if (typeof props.children !== 'undefined') return props.children;\n      return undefined;\n    })(),\n    variableOptions: (() => {\n      const variableOptions = {\n        ...(typeof props.currency !== 'undefined' && {\n          currency: props.currency,\n        }),\n        ...(typeof props.unit !== 'undefined' && {\n          unit: props.unit,\n        }),\n        ...(typeof props.baseDate !== 'undefined' && {\n          baseDate: props.baseDate,\n        }),\n        ...(typeof props.options !== 'undefined' && props.options),\n      };\n      if (Object.keys(variableOptions).length) return variableOptions;\n      if (typeof props['data-_gt-variable-options'] === 'string')\n        return JSON.parse(props['data-_gt-variable-options']);\n      return props['data-_gt-variable-options'] || undefined;\n    })(),\n  };\n\n  return result;\n}\n"],"mappings":"yHAYA,SAAgB,EACd,EAC+B,CAC/B,OACE,OAAO,GAAU,UACjB,CAAC,CAAC,GACF,aAAc,GACd,OAAO,EAAM,aAAgB,UAC7B,CAAC,CAAC,EAAM,aACR,mBAAoB,EAAM,aAC1B,EAAM,aAAa,iBAAmB,WAI1C,SAAgB,EAAiB,EAA4C,CAC3E,IAAM,EACJ,EAAM,aAAa,cAAgB,WAkCrC,MAAO,CA/BL,aAAc,EAAgB,EAAO,EAAa,CAClD,aAAc,EAAmB,EAAa,CAC9C,cAAe,EAAM,aAAa,eAAiB,SACnD,mBAAsB,CACpB,GAAW,EAAM,QAAU,OAAa,OAAO,EAAM,MACrD,GAAW,EAAM,OAAS,OAAa,OAAO,EAAM,KACpD,GAAW,EAAM,gCAAkC,OACjD,OAAO,EAAM,8BACf,GAAW,EAAM,WAAa,OAAa,OAAO,EAAM,YAEtD,CACJ,qBAAwB,CACtB,IAAM,EAAkB,CACtB,GAAW,EAAM,WAAa,QAAe,CAC3C,SAAU,EAAM,SACjB,CACD,GAAW,EAAM,OAAS,QAAe,CACvC,KAAM,EAAM,KACb,CACD,GAAW,EAAM,WAAa,QAAe,CAC3C,SAAU,EAAM,SACjB,CACD,GAAW,EAAM,UAAY,QAAe,EAAM,QACnD,CAID,OAHI,OAAO,KAAK,EAAgB,CAAC,OAAe,EAC5C,OAAO,EAAM,8BAAiC,SACzC,KAAK,MAAM,EAAM,6BAA6B,CAChD,EAAM,8BAAgC,IAAA,MAC3C,CAGO"}