/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { makeGenericController } from "@arcgis/lumina/controllers";
const useFormTrigger = (options) => makeGenericController((component) => {
  function clickHandler(event) {
    const { form } = component.elementInternals;
    if (event.defaultPrevented || component.disabled || options?.disabled?.() || !form || component.type === "button") {
      return;
    }
    if (component.type === "submit") {
      form.requestSubmit();
      return;
    }
    form.reset();
  }
  component.listen("luminaFormAssociatedCallback", ({ detail: [form] }) => {
    if (form) {
      component.el.addEventListener("click", clickHandler);
    } else {
      component.el.removeEventListener("click", clickHandler);
    }
  });
});
export {
  useFormTrigger as u
};
