import{router as Se}from"@inertiajs/core";import{setupProgress as Z}from"@inertiajs/core";import{createElement as ee}from"react";import{createHeadManager as z,router as $}from"@inertiajs/core";import{createElement as b,useEffect as G,useMemo as X,useState as Y}from"react";import{createContext as J}from"react";var B=J(void 0);B.displayName="InertiaHeadContext";var A=B;import{createContext as Q}from"react";var N=Q(void 0);N.displayName="InertiaPageContext";var E=N;function M({children:l,initialPage:c,initialComponent:s,resolveComponent:p,titleCallback:a,onHeadUpdate:S}){let[d,P]=Y({component:s||null,page:c,key:null}),u=X(()=>z(typeof window>"u",a||(f=>f),S||(()=>{})),[]);if(G(()=>{$.init({initialPage:c,resolveComponent:p,swapComponent:async({component:f,page:e,preserveState:i})=>{P(r=>({component:f,page:e,key:i?r.key:Date.now()}))}}),$.on("navigate",()=>u.forceUpdate())},[]),!d.component)return b(A.Provider,{value:u},b(E.Provider,{value:d.page},null));let g=l||(({Component:f,props:e,key:i})=>{let r=b(f,{key:i,...e});return typeof f.layout=="function"?f.layout(r):Array.isArray(f.layout)?f.layout.concat(r).reverse().reduce((y,T)=>b(T,{children:y,...e})):r});return b(A.Provider,{value:u},b(E.Provider,{value:d.page},g({Component:d.component,key:d.key,props:d.page.props})))}M.displayName="Inertia";async function j({id:l="app",resolve:c,setup:s,title:p,progress:a={},page:S,render:d}){let P=typeof window>"u",u=P?null:document.getElementById(l),g=S||JSON.parse(u.dataset.page),f=r=>Promise.resolve(c(r)).then(y=>y.default||y),e=[],i=await f(g.component).then(r=>s({el:u,App:M,props:{initialPage:g,initialComponent:r,resolveComponent:f,titleCallback:p,onHeadUpdate:P?y=>e=y:null}}));if(!P&&a&&Z(a),P){let r=await d(ee("div",{id:l,"data-page":JSON.stringify(g)},i));return{head:e,body:r}}}import U,{useContext as te,useEffect as re,useMemo as oe}from"react";var ne=function({children:l,title:c}){let s=te(A),p=oe(()=>s.createProvider(),[s]);re(()=>()=>{p.disconnect()},[p]);function a(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function S(e){let i=Object.keys(e.props).reduce((r,y)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(y))return r;let T=e.props[y];return T===""?r+` ${y}`:r+` ${y}="${T}"`},"");return`<${e.type}${i}>`}function d(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((i,r)=>i+P(r),"")}function P(e){let i=S(e);return e.props.children&&(i+=d(e)),e.props.dangerouslySetInnerHTML&&(i+=e.props.dangerouslySetInnerHTML.__html),a(e)||(i+=`</${e.type}>`),i}function u(e){return U.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function g(e){return P(u(e))}function f(e){let i=U.Children.toArray(e).filter(r=>r).map(r=>g(r));return c&&!i.find(r=>r.startsWith("<title"))&&i.push(`<title inertia>${c}</title>`),i}return p.update(f(l)),null},ae=ne;import{mergeDataIntoQueryString as se,router as ie,shouldIntercept as pe}from"@inertiajs/core";import{createElement as ue,forwardRef as ce,useCallback as le}from"react";var F=()=>{},V=ce(({children:l,as:c="a",data:s={},href:p,method:a="get",preserveScroll:S=!1,preserveState:d=null,replace:P=!1,only:u=[],headers:g={},queryStringArrayFormat:f="brackets",onClick:e=F,onCancelToken:i=F,onBefore:r=F,onStart:y=F,onProgress:T=F,onFinish:H=F,onCancel:h=F,onSuccess:L=F,onError:x=F,...w},R)=>{let I=le(o=>{e(o),pe(o)&&(o.preventDefault(),ie.visit(p,{data:s,method:a,preserveScroll:S,preserveState:d??a!=="get",replace:P,only:u,headers:g,onCancelToken:i,onBefore:r,onStart:y,onProgress:T,onFinish:H,onCancel:h,onSuccess:L,onError:x}))},[s,p,a,S,d,P,u,g,e,i,r,y,T,H,h,L,x]);c=c.toLowerCase(),a=a.toLowerCase();let[v,t]=se(a,p||"",s,f);return p=v,s=t,c==="a"&&a!=="get"&&console.warn(`Creating POST/PUT/PATCH/DELETE <a> links is discouraged as it causes "Open Link in New Tab/Window" accessibility issues.

Please specify a more appropriate element using the "as" attribute. For example:

<Link href="${p}" method="${a}" as="button">...</Link>`),ue(c,{...w,...c==="a"?{href:p}:{},ref:R,onClick:I},l)});V.displayName="InertiaLink";var de=V;import{router as _}from"@inertiajs/core";import ge from"lodash.isequal";import{useCallback as ye,useEffect as Pe,useRef as O,useState as k}from"react";import{router as K}from"@inertiajs/core";import{useEffect as fe,useState as me}from"react";function D(l,c){let[s,p]=me(()=>{let a=K.restore(c);return a!==void 0?a:l});return fe(()=>{K.remember(s,c)},[s,c]),[s,p]}function W(l,c){let s=O(null),p=typeof l=="string"?l:null,[a,S]=k((typeof l=="string"?c:l)||{}),d=O(null),P=O(null),[u,g]=p?D(a,`${p}:data`):k(a),[f,e]=p?D({},`${p}:errors`):k({}),[i,r]=k(!1),[y,T]=k(!1),[H,h]=k(null),[L,x]=k(!1),[w,R]=k(!1),I=t=>t;Pe(()=>(s.current=!0,()=>{s.current=!1}),[]);let v=ye((t,o,n={})=>{let C={...n,onCancelToken:m=>{if(d.current=m,n.onCancelToken)return n.onCancelToken(m)},onBefore:m=>{if(x(!1),R(!1),clearTimeout(P.current),n.onBefore)return n.onBefore(m)},onStart:m=>{if(T(!0),n.onStart)return n.onStart(m)},onProgress:m=>{if(h(m),n.onProgress)return n.onProgress(m)},onSuccess:m=>{if(s.current&&(T(!1),h(null),e({}),r(!1),x(!0),R(!0),P.current=setTimeout(()=>{s.current&&R(!1)},2e3)),n.onSuccess)return n.onSuccess(m)},onError:m=>{if(s.current&&(T(!1),h(null),e(m),r(!0)),n.onError)return n.onError(m)},onCancel:()=>{if(s.current&&(T(!1),h(null)),n.onCancel)return n.onCancel()},onFinish:()=>{if(s.current&&(T(!1),h(null)),d.current=null,n.onFinish)return n.onFinish()}};t==="delete"?_.delete(o,{...C,data:I(u)}):_[t](o,I(u),C)},[u,e]);return{data:u,setData(t,o){g(typeof t=="string"?{...u,[t]:o}:typeof t=="function"?n=>t(n):t)},isDirty:!ge(u,a),errors:f,hasErrors:i,processing:y,progress:H,wasSuccessful:L,recentlySuccessful:w,transform(t){I=t},setDefaults(t,o){S(typeof t>"u"?()=>u:n=>({...n,...typeof t=="string"?{[t]:o}:t}))},reset(...t){t.length===0?g(a):g(Object.keys(a).filter(o=>t.includes(o)).reduce((o,n)=>(o[n]=a[n],o),{...u}))},setError(t,o){e(n=>{let C={...n,...typeof t=="string"?{[t]:o}:t};return r(Object.keys(C).length>0),C})},clearErrors(...t){e(o=>{let n=Object.keys(o).reduce((C,m)=>({...C,...t.length>0&&!t.includes(m)?{[m]:o[m]}:{}}),{});return r(Object.keys(n).length>0),n})},submit:v,get(t,o){v("get",t,o)},post(t,o){v("post",t,o)},put(t,o){v("put",t,o)},patch(t,o){v("patch",t,o)},delete(t,o){v("delete",t,o)},cancel(){d.current&&d.current.cancel()}}}import{useContext as Te}from"react";function q(){let l=Te(E);if(!l)throw new Error("usePage must be used within the Inertia component");return l}var yt=Se;export{ae as Head,de as Link,j as createInertiaApp,yt as router,W as useForm,q as usePage,D as useRemember};
//# sourceMappingURL=index.esm.js.map
