"use client";
var P=Object.create;var{getPrototypeOf:_,defineProperty:X,getOwnPropertyNames:M,getOwnPropertyDescriptor:v}=Object,V=Object.prototype.hasOwnProperty;var F=(p,w,A)=>{A=p!=null?P(_(p)):{};let D=w||!p||!p.__esModule?X(A,"default",{value:p,enumerable:!0}):A;for(let U of M(p))if(!V.call(D,U))X(D,U,{get:()=>p[U],enumerable:!0});return D},K=new WeakMap,b=(p)=>{var w=K.get(p),A;if(w)return w;if(w=X({},"__esModule",{value:!0}),p&&typeof p==="object"||typeof p==="function")M(p).map((D)=>!V.call(w,D)&&X(w,D,{get:()=>p[D],enumerable:!(A=v(p,D))||A.enumerable}));return K.set(p,w),w};var s=(p,w)=>{for(var A in w)X(p,A,{get:w[A],enumerable:!0,configurable:!0,set:(D)=>w[A]=()=>D})};var g={};s(g,{withPieCard:()=>Q,usePieStorybookEmitter:()=>G,firePieMethod:()=>I,PieStorybookProviders:()=>L,PieStorybookChannelBridge:()=>R,PieMethodTrigger:()=>h,PIE_STORYBOOK_FIRE_EVENT:()=>Z,PIECARD_PARAM_KEY:()=>Y});module.exports=b(g);var J=require("react"),$=require("@tanstack/react-query"),k=F(require("mitt")),T=require("@swarm.ing/pieui");var Y="piecard",Z="piecard/fire";var z=require("react/jsx-runtime"),y={apiServer:"",centrifugeServer:"",enableRenderingLog:!1,pageProcessor:""},q={current:null},O=()=>{if(!q.current)q.current=new $.QueryClient({defaultOptions:{queries:{retry:!1,staleTime:1/0}}});return q.current},H=J.createContext(null),G=()=>{let p=J.useContext(H);if(!p)throw Error("usePieStorybookEmitter must be used inside <PieStorybookProviders />");return p},L=({children:p,emitter:w,pieConfig:A})=>{let D=J.useMemo(()=>w??k.default(),[w]),U=J.useMemo(()=>({...y,...A??{}}),[A]);return z.jsx($.QueryClientProvider,{client:O(),children:z.jsx(T.PieConfigContext.Provider,{value:U,children:z.jsx(T.FallbackContext.Provider,{value:z.jsx(z.Fragment,{}),children:z.jsx(H.Provider,{value:D,children:z.jsx(T.MittContext.Provider,{value:D,children:z.jsx(T.SocketIOContext.Provider,{value:null,children:z.jsx(T.CentrifugeIOContext.Provider,{value:null,children:p})})})})})})})},Q=(p)=>z.jsxs(L,{children:[z.jsx(R,{}),z.jsx(p,{})]}),c=(p,w)=>`pie${w}_${p}`,I=(p,w,A,D)=>{p.emit(c(w,A),D)},h=({card:p,method:w,payload:A,label:D})=>{let U=G();return z.jsx("button",{type:"button",onClick:()=>I(U,p,w,A),style:{padding:"6px 12px",marginRight:8,marginBottom:8,fontSize:12,border:"1px solid #ccc",borderRadius:4,cursor:"pointer",background:"#f7f7f7"},children:D??`${p}.${w}`})},B=()=>{return globalThis.__STORYBOOK_ADDONS_CHANNEL__??null},R=()=>{let p=G(),w=J.useRef(p);return w.current=p,J.useEffect(()=>{let A=B();if(!A)return;let D=(...U)=>{let W=U[0];if(!W||!W.card||!W.method)return;I(w.current,W.card,W.method,W.payload)};return A.on(Z,D),()=>A.off(Z,D)},[]),null};
