'use strict';

const domContextHooks_module = require('./dom-context-hooks.module-e7b6727c.js');
const index_module = require('./index.module-f8c8495f.js');

function useChildElements() {
  const host = index_module._();
  const initialState = host.children.length
    ? Array.from(host.children)
    : [];
  const [childElements, setChildElements] = domContextHooks_module.useState(initialState);
  let observer;
  // Create observer once
  domContextHooks_module.useMemo(() => {
    observer = new MutationObserver(() => {
      const children = Array.from(host.children);
      setChildElements([...children]);
    });
  }, []);
  // Listen to host and observe / disconnect
  domContextHooks_module.useMemo(() => {
    if (!observer)
      return;
    observer.observe(host, { childList: true });
    return () => {
      observer.disconnect();
    };
  }, [host]);
  return childElements;
}

exports.useChildElements = useChildElements;
