// @bun
var{defineProperty:z,getOwnPropertyNames:B,getOwnPropertyDescriptor:C}=Object,D=Object.prototype.hasOwnProperty;function E(f){return this[f]}var K=(f)=>{var k=(A??=new WeakMap).get(f),q;if(k)return k;if(k=z({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function"){for(var x of B(f))if(!D.call(k,x))z(k,x,{get:E.bind(f,x),enumerable:!(q=C(f,x))||q.enumerable})}return A.set(f,k),k},A;var F=(f)=>f;function J(f,k){this[f]=F.bind(null,k)}var L=(f,k)=>{for(var q in k)z(f,q,{get:k[q],enumerable:!0,configurable:!0,set:J.bind(k,q)})};var N=(f,k)=>()=>(f&&(k=f(f=0)),k);var O=import.meta.require;var v=new Set;function Q(){return{open(f){v.add(f),f.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close(f){v.delete(f)},message(f,k){}}}function u(f){let k=JSON.stringify({...f,timestamp:f.timestamp||Date.now()});for(let q of v)try{q.send(k)}catch{v.delete(q)}}function S(f,k){u({type:"story-update",data:{storyId:f,...k}})}function T(f,k){u({type:"story-add",data:{storyId:f,...k}})}function V(f){u({type:"story-remove",data:{storyId:f}})}function W(){u({type:"config-change"})}function X(){u({type:"full-reload"})}function Y(f){u({type:"error",data:{error:f}})}function Z(){return v.size}function _(f){return`
<script>
(function() {
  const ws = new WebSocket('${f}');

  ws.onopen = function() {
    console.log('[STX Story] HMR connected');
  };

  ws.onmessage = function(event) {
    const message = JSON.parse(event.data);

    switch (message.type) {
      case 'connected':
        console.log('[STX Story] Connected to HMR server');
        break;

      case 'story-update':
        console.log('[STX Story] Story updated:', message.data.storyId);
        // Reload the current story if it matches
        if (window.__stxStory && window.__stxStory.currentStoryId === message.data.storyId) {
          window.__stxStory.reloadCurrentStory();
        }
        break;

      case 'story-add':
        console.log('[STX Story] Story added:', message.data.storyId);
        window.__stxStory && window.__stxStory.refreshStoryList();
        break;

      case 'story-remove':
        console.log('[STX Story] Story removed:', message.data.storyId);
        window.__stxStory && window.__stxStory.refreshStoryList();
        break;

      case 'config-change':
        console.log('[STX Story] Config changed, reloading...');
        location.reload();
        break;

      case 'full-reload':
        console.log('[STX Story] Full reload requested');
        location.reload();
        break;

      case 'error':
        console.error('[STX Story] Error:', message.data.error);
        break;
    }
  };

  ws.onclose = function() {
    console.log('[STX Story] HMR disconnected, attempting reconnect...');
    setTimeout(function() {
      location.reload();
    }, 1000);
  };

  ws.onerror = function(error) {
    console.error('[STX Story] WebSocket error:', error);
  };
})();
</script>
`}export{S as notifyStoryUpdate,V as notifyStoryRemove,T as notifyStoryAdd,X as notifyFullReload,Y as notifyError,W as notifyConfigChange,_ as getHmrClientScript,Z as getClientCount,Q as createHmrHandler,u as broadcast};
