import { useRef } from "react";
import { partitionRecord } from "../../utils/partition";
import * as ReactPage from "../../state/react-page";
import { isLegacyDescriptor } from "../../prop-controllers/descriptors";
import { useStore } from "./hooks/use-store";
import { resolveLegacyDescriptorProp } from "./legacy-controls";
import { useResolvedProps } from "./hooks/use-resolved-props";
function useControlDefs(elementType) {
  const store = useStore();
  const all = ReactPage.getComponentPropControllerDescriptors(store.getState(), elementType) ?? {};
  return useRef(partitionRecord(all, isLegacyDescriptor)).current;
}
function ResolveProps({ element, children: renderComponent }) {
  const [legacyDescriptors, definitions] = useControlDefs(element.type);
  const resolvedProps = useResolvedProps(definitions, element.props, element.key);
  const renderFn = Object.entries(legacyDescriptors).reduceRight(
    (renderFn2, [propName, descriptor]) => (props) => resolveLegacyDescriptorProp(descriptor, propName, element.props[propName], props, renderFn2),
    renderComponent
  );
  return renderFn(resolvedProps);
}
export {
  ResolveProps
};
//# sourceMappingURL=controls.js.map