'use strict';

const domContextHooks_module = require('./dom-context-hooks.module-e7b6727c.js');
const index_module = require('./index.module-f8c8495f.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 = index_module._();
  domContextHooks_module.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 = index_module._();
  const [tick, rerender] = index_module.yn();
  domContextHooks_module.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;
}

exports.useRequestRerender = useRequestRerender;
exports.useRerenderListener = useRerenderListener;
