'use strict';

var VDHZ5F7K = require('./VDHZ5F7K.cjs');
var LMDWO4NN = require('./LMDWO4NN.cjs');
var ABQUS43J = require('./ABQUS43J.cjs');
var _3YLGPPWQ = require('./3YLGPPWQ.cjs');
var PBFD2E7P = require('../../../../../../@ariakit_core@0.4.15/node_modules/@ariakit/core/esm/__chunks/PBFD2E7P.cjs');
var React = require('react');

var TagName = "div";
var useCollectionItem = LMDWO4NN.createHook(
  function useCollectionItem2(_a) {
    var _b = _a, {
      store,
      shouldRegisterItem = true,
      getItem = PBFD2E7P.identity,
      element: element
    } = _b, props = _3YLGPPWQ.__objRest(_b, [
      "store",
      "shouldRegisterItem",
      "getItem",
      // @ts-expect-error This prop may come from a collection renderer.
      "element"
    ]);
    const context = VDHZ5F7K.useCollectionContext();
    store = store || context;
    const id = ABQUS43J.useId(props.id);
    const ref = React.useRef(element);
    React.useEffect(() => {
      const element2 = ref.current;
      if (!id) return;
      if (!element2) return;
      if (!shouldRegisterItem) return;
      const item = getItem({ id, element: element2 });
      return store == null ? void 0 : store.renderItem(item);
    }, [id, shouldRegisterItem, getItem, store]);
    props = _3YLGPPWQ.__spreadProps(_3YLGPPWQ.__spreadValues({}, props), {
      ref: ABQUS43J.useMergeRefs(ref, props.ref)
    });
    return PBFD2E7P.removeUndefinedValues(props);
  }
);
LMDWO4NN.forwardRef(function CollectionItem2(props) {
  const htmlProps = useCollectionItem(props);
  return LMDWO4NN.createElement(TagName, htmlProps);
});

exports.useCollectionItem = useCollectionItem;
//# sourceMappingURL=RZ4GPYOB.cjs.map
