{"version":3,"file":"useProps.mjs","names":[],"sources":["../../../../../../../src/lib/hooks/useProps.ts"],"sourcesContent":["import {\n  type FlowComponentName,\n  type FlowComponentProps,\n} from \"@/components/propTypes\";\nimport { resolveDynamicProps } from \"@/lib/propsContext/dynamicProps/resolveDynamicProps\";\nimport { useComponentPropsContext } from \"@/lib/propsContext/propsContext\";\nimport { omitBy } from \"remeda\";\nimport isDynamicProp from \"@/lib/propsContext/dynamicProps/lib\";\nimport { isFlowComponentName } from \"@/lib/propsContext/isFlowComponentName\";\nimport { areChildrenEmpty } from \"@/lib/react/areChildrenEmpty\";\nimport { isNestingLevelKey } from \"@/lib/propsContext/nestedPropsContext/lib\";\nimport { getPropsMerger } from \"@/lib/react/getPropsMerger\";\n\nconst withoutChildren = <C extends FlowComponentName>(\n  props: FlowComponentProps<C>,\n) => {\n  if (\"children\" in props) {\n    if (areChildrenEmpty(props.children)) {\n      const { children: ignored, ...rest } = props;\n      return rest as FlowComponentProps<C>;\n    }\n  }\n  return props;\n};\n\nconst merger = getPropsMerger({\n  mergeRefs: true,\n});\n\nexport const useProps = <C extends FlowComponentName>(\n  component: C,\n  localProps: FlowComponentProps<C>,\n): FlowComponentProps<C> => {\n  localProps = withoutChildren(localProps);\n\n  const componentPropsContext = useComponentPropsContext(component);\n\n  const withResolvedDynamicProps = componentPropsContext\n    ? resolveDynamicProps(componentPropsContext, localProps)\n    : undefined;\n\n  const withoutInternalProps = componentPropsContext\n    ? omitBy(\n        componentPropsContext,\n        (value, key) =>\n          isFlowComponentName(key) ||\n          isNestingLevelKey(key) ||\n          isDynamicProp(value),\n      )\n    : undefined;\n\n  return merger(\n    withoutInternalProps,\n    localProps,\n    withResolvedDynamicProps,\n  ) as FlowComponentProps<C>;\n};\n\nexport default useProps;\n"],"mappings":";;;;;;;;;;;AAaA,IAAM,mBACJ,UACG;CACH,IAAI,cAAc,OACZ;MAAA,iBAAiB,MAAM,QAAQ,GAAG;GACpC,MAAM,EAAE,UAAU,SAAS,GAAG,SAAS;GACvC,OAAO;EACT;;CAEF,OAAO;AACT;AAEA,IAAM,SAAS,eAAe,EAC5B,WAAW,KACb,CAAC;AAED,IAAa,YACX,WACA,eAC0B;CAC1B,aAAa,gBAAgB,UAAU;CAEvC,MAAM,wBAAwB,yBAAyB,SAAS;CAEhE,MAAM,2BAA2B,wBAC7B,oBAAoB,uBAAuB,UAAU,IACrD,KAAA;CAYJ,OAAO,OAVsB,wBACzB,OACE,wBACC,OAAO,QACN,oBAAoB,GAAG,KACvB,kBAAkB,GAAG,KACrB,cAAc,KAAK,CACvB,IACA,KAAA,GAIF,YACA,wBACF;AACF"}