"use client";
import {
  useMergeRefs
} from "./KPHZR4MB.js";
import {
  getRefProperty,
  mergeProps
} from "./YXGXYGQX.js";

// src/utils/system.tsx
import * as React from "react";
import { jsx } from "react/jsx-runtime";
function forwardRef2(render) {
  const Role = React.forwardRef(
    // @ts-ignore Incompatible with React 19 types. Ignore for now.
    (props, ref) => render({ ...props, ref })
  );
  Role.displayName = render.displayName || render.name;
  return Role;
}
function memo2(Component, propsAreEqual) {
  return React.memo(Component, propsAreEqual);
}
function createElement(Type, props) {
  const { wrapElement, render, ...rest } = props;
  const mergedRef = useMergeRefs(props.ref, getRefProperty(render));
  let element;
  if (React.isValidElement(render)) {
    const renderProps = {
      // @ts-ignore Incompatible with React 19 types. Ignore for now.
      ...render.props,
      ref: mergedRef
    };
    element = React.cloneElement(render, mergeProps(rest, renderProps));
  } else if (render) {
    element = render(rest);
  } else {
    element = /* @__PURE__ */ jsx(Type, { ...rest });
  }
  if (wrapElement) {
    return wrapElement(element);
  }
  return element;
}
function createHook(useProps) {
  const useRole = (props = {}) => {
    return useProps(props);
  };
  useRole.displayName = useProps.name;
  return useRole;
}
function createStoreContext(providers = [], scopedProviders = []) {
  const context = React.createContext(void 0);
  const scopedContext = React.createContext(void 0);
  const useContext2 = () => React.useContext(context);
  const useScopedContext = (onlyScoped = false) => {
    const scoped = React.useContext(scopedContext);
    const store = useContext2();
    if (onlyScoped) return scoped;
    return scoped || store;
  };
  const useProviderContext = () => {
    const scoped = React.useContext(scopedContext);
    const store = useContext2();
    if (scoped && scoped === store) return;
    return store;
  };
  const ContextProvider = (props) => {
    return providers.reduceRight(
      (children, Provider) => /* @__PURE__ */ jsx(Provider, { ...props, children }),
      /* @__PURE__ */ jsx(context.Provider, { ...props })
    );
  };
  const ScopedContextProvider = (props) => {
    return /* @__PURE__ */ jsx(ContextProvider, { ...props, children: scopedProviders.reduceRight(
      (children, Provider) => /* @__PURE__ */ jsx(Provider, { ...props, children }),
      /* @__PURE__ */ jsx(scopedContext.Provider, { ...props })
    ) });
  };
  return {
    context,
    scopedContext,
    useContext: useContext2,
    useScopedContext,
    useProviderContext,
    ContextProvider,
    ScopedContextProvider
  };
}

export {
  forwardRef2 as forwardRef,
  memo2 as memo,
  createElement,
  createHook,
  createStoreContext
};
