{"version":3,"file":"use-form-action.cjs","names":[],"sources":["../../../src/inputs/shared/use-form-action.ts"],"sourcesContent":["import type { Readable } from '@vielzeug/ripple';\n\nimport type { ButtonType } from '../../shared';\n\n/**\n * Handles form submission relay for form-associated button-like components.\n *\n * The inner `<button>` always has `type=\"button\"` so the shadow DOM never\n * drives native form actions directly. This composable intercepts clicks and\n * forwards submit/reset to the associated form via `ElementInternals`.\n *\n * @param form      - The associated HTMLFormElement (from `useField().internals.form`).\n * @param type      - Reactive signal for the button `type` prop.\n * @param isDisabled - Reactive signal indicating whether the button is disabled/loading.\n * @param host       - The host custom element.\n * @returns A click handler to attach to the inner element.\n */\nexport function useFormAction(\n  getForm: () => HTMLFormElement | null,\n  type: Readable<ButtonType | undefined>,\n  isDisabled: Readable<boolean>,\n  host: HTMLElement,\n): (e: MouseEvent) => void {\n  return (e: MouseEvent) => {\n    if (isDisabled.value) {\n      e.preventDefault();\n      e.stopImmediatePropagation();\n\n      return;\n    }\n\n    const form = getForm();\n\n    if (form) {\n      if (type.value === 'submit') {\n        e.preventDefault();\n        form.requestSubmit();\n      } else if (type.value === 'reset') {\n        e.preventDefault();\n        form.reset();\n      }\n    }\n\n    // Re-dispatch if the native click didn't bubble to host (shadow DOM interop).\n    if (!e.composedPath().includes(host)) {\n      host.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, composed: true }));\n    }\n  };\n}\n"],"mappings":"AAiBA,SAAgB,EACd,EACA,EACA,EACA,EACyB,CACzB,MAAQ,IAAkB,CACxB,GAAI,EAAW,MAAO,CACpB,EAAE,eAAe,EACjB,EAAE,yBAAyB,EAE3B,MACF,CAEA,IAAM,EAAO,EAAQ,EAEjB,IACE,EAAK,QAAU,UACjB,EAAE,eAAe,EACjB,EAAK,cAAc,GACV,EAAK,QAAU,UACxB,EAAE,eAAe,EACjB,EAAK,MAAM,IAKV,EAAE,aAAa,CAAC,CAAC,SAAS,CAAI,GACjC,EAAK,cAAc,IAAI,WAAW,QAAS,CAAE,QAAS,GAAM,WAAY,GAAM,SAAU,EAAK,CAAC,CAAC,CAEnG,CACF"}