import{d as C,j as m,F as E,r,o as k,p as v,q as y}from"./index-Dw-TpOfD.js";function j(e,u){e&&window.dispatchEvent(new CustomEvent(e,{detail:{id:u}}))}function M(e){return e instanceof Promise}function B({actions:e,label:u,eventName:d,onPress:s,icon:l,id:i,appearance:h,preAction:a,postAction:t}){const n=e!=null&&e.length?C.SplitButton:C.Button;return m.jsx(n,{iconBefore:l??null,appearance:h,onPress:async()=>{M(a)?await a():a==null||a(),j(d,i),M(s)?await s():s==null||s(),M(t)?await t():t==null||t()},content:e!=null&&e.length?m.jsx(C.Menu,{items:e==null?void 0:e.map(({id:f,label:x,eventName:c,icon:g,onPress:o})=>({key:f,title:x,icon:g,onPress:()=>{a==null||a(),j(c,f),o==null||o(),t==null||t()}}))}):null,children:m.jsx(E,{id:i,defaultMessage:u})})}const w=r.createContext({actions:{}});function F(){return r.useContext(w)}function L(e,u){const{actions:d}=F();k(e,u),d[e]=u}function q(e){const{pathname:u}=v(),d=y(),s=e.backPath||(u==null?void 0:u.split("/").slice(0,-1).join("/")),l=r.useMemo(()=>(e.actions||[]).concat(d.filter(t=>{var n;return(n=t.handle)==null?void 0:n.actions}).flatMap(t=>{var n;return(n=t.handle)==null?void 0:n.actions}))??[],[d,e.actions]),i=r.useMemo(()=>l.reduce((t,{eventName:n,id:f,onPress:x})=>{const c=f;return n&&(t[c]=()=>j(n,f)),x&&(t[c]=x),t},{}),[l]),h=r.useCallback(t=>m.jsx(w.Provider,{value:{actions:i},...t}),[i]),a=r.useMemo(()=>{const t=()=>m.jsx(r.Fragment,{children:l.map(n=>"render"in n?n.render():m.jsx(B,{...n},n.id))});return t.displayName="Actions",t},[l]);return{actions:l,Actions:a,backPath:s,AdminContextProvider:h}}export{L as a,q as u};
