import { f as useEffect } from './dom-context-hooks.module-50442785.js';
import { _, y as yn } from './index.module-b23fdad8.js';

const RENDER_EVENT = "sqm:request-rerender";
/**
 * Requests a re-render for the wrapping table
 *
 * Useful when an attribute or other internal state changes
 *
 * @param deps an array of dependencies used for useEffect
 */
function useRequestRerender(deps) {
  const host = _();
  useEffect(() => {
    host.dispatchEvent(new CustomEvent(RENDER_EVENT, {
      detail: true,
      bubbles: true,
      composed: true,
    }));
  }, deps);
}
/**
 * Re-renders a parent component when child components make the request
 */
function useRerenderListener() {
  const host = _();
  const [tick, rerender] = yn();
  useEffect(() => {
    const listener = (e) => {
      // Preventes recursively nested components from sending requests up all the way
      e.stopPropagation();
      rerender();
    };
    host.addEventListener(RENDER_EVENT, listener);
    return () => {
      host.removeEventListener(RENDER_EVENT, listener);
    };
  }, []);
  return tick;
}

export { useRequestRerender as a, useRerenderListener as u };
