import{d as e,l as t,n,o as r,r as i}from"./DP37y6wO.js";import"./BymfG72d2.js";function a(e){let r=JSON.parse(e);return r.data&&=t(r.data,n.decoders),r}function o(e){return HTMLElement.prototype.cloneNode.call(e)}function s(t,n=e){let s=async({action:e,result:n,reset:a=!0,invalidateAll:o=!0})=>{n.type===`success`&&(a&&HTMLFormElement.prototype.reset.call(t),o&&await r()),(location.origin+location.pathname===e.origin+e.pathname||n.type===`redirect`||n.type===`error`)&&await i(n)};async function c(e){if((e.submitter?.hasAttribute(`formmethod`)?e.submitter.formMethod:o(t).method)!==`post`)return;e.preventDefault();let r=new URL(e.submitter?.hasAttribute(`formaction`)?e.submitter.formAction:o(t).action),i=e.submitter?.hasAttribute(`formenctype`)?e.submitter.formEnctype:o(t).enctype,c=new FormData(t,e.submitter),l=new AbortController,u=!1,d=await n({action:r,cancel:()=>u=!0,controller:l,formData:c,formElement:t,submitter:e.submitter})??s;if(u)return;let f;try{let e=new Headers({accept:`application/json`,"x-sveltekit-action":`true`});i!==`multipart/form-data`&&e.set(`Content-Type`,/^(:?application\/x-www-form-urlencoded|text\/plain)$/.test(i)?i:`application/x-www-form-urlencoded`);let t=i===`multipart/form-data`?c:new URLSearchParams(c),n=await fetch(r,{method:`POST`,headers:e,cache:`no-store`,body:t,signal:l.signal});f=a(await n.text()),f.type===`error`&&(f.status=n.status)}catch(e){if(e?.name===`AbortError`)return;f={type:`error`,error:e}}await d({action:r,formData:c,formElement:t,update:e=>s({action:r,result:f,reset:e?.reset,invalidateAll:e?.invalidateAll}),result:f})}return HTMLFormElement.prototype.addEventListener.call(t,`submit`,c),{destroy(){HTMLFormElement.prototype.removeEventListener.call(t,`submit`,c)}}}export{s as n,a as t};