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