declare global {
  interface Window {
    SearchWidget: { open: (() => void) | undefined } | undefined;
  }
}

export const initDevcmActivityActions = () => {
  document.addEventListener("click", (event) => {
    const target = event.target;

    if (!(target instanceof Element)) {
      return;
    }

    const actionTrigger = target.closest<HTMLElement>('[data-devcm-action="search"]');

    if (!actionTrigger) {
      return;
    }

    event.preventDefault();
    window.SearchWidget?.open?.();
  });
};
