@zonetrix/viewer 2.11.2 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),n=require("react"),N=require("react-konva"),A=require("firebase/database"),lt=require("@zonetrix/shared");function Ee(s){const[i,t]=n.useState(null),[r,h]=n.useState(!1),[u,c]=n.useState(null),S=n.useCallback(async()=>{if(s){h(!0),c(null);try{const f=await fetch(s);if(!f.ok)throw new Error(`Failed to fetch config: ${f.statusText}`);const a=await f.json();t(a)}catch(f){const a=f instanceof Error?f:new Error("Unknown error occurred");c(a),console.error("Failed to fetch seat map config:",a)}finally{h(!1)}}},[s]);return n.useEffect(()=>{S()},[S]),{config:i,loading:r,error:u,refetch:S}}function Fe(s){const[i,t]=n.useState({width:0,height:0});return n.useEffect(()=>{const r=s.current;if(!r)return;const{width:h,height:u}=r.getBoundingClientRect();h>0&&u>0&&t({width:h,height:u});const c=new ResizeObserver(S=>{const f=S[0];if(!f)return;const{width:a,height:b}=f.contentRect;a>0&&b>0&&t(m=>m.width===a&&m.height===b?m:{width:a,height:b})});return c.observe(r),()=>{c.disconnect()}},[s]),i}function Me(s,i){return Math.sqrt(Math.pow(i.x-s.x,2)+Math.pow(i.y-s.y,2))}function je(s,i){return{x:(s.x+i.x)/2,y:(s.y+i.y)/2}}function ke(s,i){const t=n.useRef(null),r=n.useRef(null),h=n.useRef(1),{enabled:u,minScale:c,maxScale:S,currentScale:f,currentPosition:a,onScaleChange:b}=i;n.useEffect(()=>{const m=s.current;if(!m||!u)return;const g=m.container(),C=p=>{if(p.touches.length===2){p.preventDefault();const F={x:p.touches[0].clientX,y:p.touches[0].clientY},R={x:p.touches[1].clientX,y:p.touches[1].clientY};t.current=Me(F,R),r.current=je(F,R),h.current=f}},y=p=>{if(p.touches.length!==2)return;p.preventDefault();const F={x:p.touches[0].clientX,y:p.touches[0].clientY},R={x:p.touches[1].clientX,y:p.touches[1].clientY},k=Me(F,R),E=je(F,R);if(t.current!==null&&r.current!==null){const I=k/t.current,T=Math.min(Math.max(f*I,c),S),W=g.getBoundingClientRect(),Y=E.x-W.left,ne=E.y-W.top,se=f,re={x:(Y-a.x)/se,y:(ne-a.y)/se},oe=E.x-r.current.x,P=E.y-r.current.y,U={x:Y-re.x*T+oe,y:ne-re.y*T+P};b(T,U),t.current=k,r.current=E}},j=p=>{p.touches.length<2&&(t.current=null,r.current=null)};return g.addEventListener("touchstart",C,{passive:!1}),g.addEventListener("touchmove",y,{passive:!1}),g.addEventListener("touchend",j),()=>{g.removeEventListener("touchstart",C),g.removeEventListener("touchmove",y),g.removeEventListener("touchend",j)}},[s,u,c,S,f,a,b])}const Ie={canvasBackground:"#1a1a1a",stageColor:"#808080",seatAvailable:"#2C2B30",seatReserved:"#FCEA00",seatSelected:"#3A7DE5",seatUnavailable:"#6b7280",seatHidden:"#4a4a4a",gridLines:"#404040",currency:"KD"},Le=n.memo(({seat:s,state:i,colors:t,onClick:r,onMouseEnter:h,onMouseLeave:u})=>{const f={available:t.seatAvailable,reserved:t.seatReserved,selected:t.seatSelected,unavailable:t.seatUnavailable,hidden:t.seatHidden}[i],a=i==="available"||i==="selected",b=n.useCallback(()=>{a&&r(s)},[s,r,a]),m=n.useCallback(y=>{h(s,y);const j=y.target.getStage();j&&a&&(j.container().style.cursor="pointer")},[s,h,a]),g=n.useCallback(y=>{u();const j=y.target.getStage();j&&(j.container().style.cursor="grab")},[u]),C={x:s.position.x,y:s.position.y,fill:f,stroke:"#ffffff",strokeWidth:1,onClick:b,onTap:b,onMouseEnter:m,onMouseLeave:g};return s.shape==="circle"?o.jsx(N.Circle,{...C,radius:12}):o.jsx(N.Rect,{...C,width:24,height:24,offsetX:12,offsetY:12,cornerRadius:s.shape==="square"?0:4})});Le.displayName="ViewerSeat";const Te=n.memo(({stage:s,stageColor:i})=>{const t=s.config,r=t.shape||"rectangle",h=t.showLabel!==!1,u=t.color||i,c=t.width/t.height,S=c<.5,f=c>2;let a;S?a=t.width*.25:f?a=t.height*.35:a=Math.min(t.width,t.height)*.25;const b=t.label?.length||6,C=t.width*.85/b*1.5,y=Math.max(10,Math.min(24,Math.min(a,C))),j=4,p=Math.max(20,t.width-j*2),F=(t.width-p)/2,R={fill:u+"80",stroke:"#ffffff",strokeWidth:2,perfectDrawEnabled:!1,hitStrokeWidth:0},k=()=>{switch(r){case"circle":{const E=Math.min(t.width,t.height)/2;return o.jsx(N.Circle,{x:t.width/2,y:t.height/2,radius:E,...R})}case"triangle":{const E=Math.min(t.width,t.height)/2;return o.jsx(N.RegularPolygon,{x:t.width/2,y:t.height/2,sides:3,radius:E,rotation:-90,...R})}case"arrow":{const E=t.width/24,I=t.height/24,T=`M${9*E},${18*I} v${-8*I} H${5*E} l${7*E},${-7*I} l${7*E},${7*I} h${-4*E} v${8*I} Z`;return o.jsx(N.Path,{data:T,...R})}default:return o.jsx(N.Rect,{width:t.width,height:t.height,cornerRadius:10,...R})}};return o.jsxs(N.Group,{x:s.position.x,y:s.position.y,rotation:t.rotation||0,children:[k(),h&&o.jsx(N.Text,{text:t.label,x:F,y:j,width:p,height:t.height-j*2,fontSize:y,fontStyle:"bold",fill:"#ffffff",align:"center",verticalAlign:"middle",wrap:"word",ellipsis:!0})]})});Te.displayName="ViewerStage";const ze=n.memo(({text:s})=>o.jsx(N.Text,{x:s.position.x,y:s.position.y,text:s.config.text,fontSize:s.config.fontSize,fill:s.config.color,rotation:s.config.rotation||0,listening:!1}));ze.displayName="ViewerText";const De=n.memo(({floors:s,currentFloorId:i,onFloorChange:t,showAllOption:r,allLabel:h,position:u,className:c})=>{const S=n.useMemo(()=>[...s].sort((g,C)=>g.order-C.order),[s]),a={position:"absolute",display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:"rgba(26, 26, 26, 0.95)",borderRadius:"8px",margin:"12px",zIndex:10,...{"top-left":{top:0,left:0},"top-right":{top:0,right:0},"bottom-left":{bottom:0,left:0},"bottom-right":{bottom:0,right:0}}[u]},b={padding:"10px 16px",fontSize:"14px",fontWeight:500,border:"1px solid #444",borderRadius:"6px",backgroundColor:"transparent",color:"#fff",cursor:"pointer",transition:"all 0.2s ease",minHeight:"44px",touchAction:"manipulation"},m={...b,backgroundColor:"#3A7DE5",borderColor:"#3A7DE5"};return o.jsxs("div",{className:c,style:a,children:[r&&o.jsx("button",{type:"button",onClick:()=>t(null),style:i===null?m:b,children:h}),S.map(g=>o.jsx("button",{type:"button",onClick:()=>t(g.id),style:i===g.id?m:b,children:g.name},g.id))]})});De.displayName="FloorSelectorBar";const Ne=n.memo(({scale:s,minScale:i,maxScale:t,onZoomIn:r,onZoomOut:h,position:u,className:c})=>{const f={position:"absolute",display:"flex",flexDirection:"column",gap:"4px",padding:"8px",backgroundColor:"rgba(26, 26, 26, 0.95)",borderRadius:"8px",margin:"12px",zIndex:10,...{"top-left":{top:0,left:0},"top-right":{top:0,right:0},"bottom-left":{bottom:0,left:0},"bottom-right":{bottom:0,right:0}}[u]},a={width:"44px",height:"44px",minWidth:"44px",minHeight:"44px",fontSize:"22px",fontWeight:"bold",border:"1px solid #444",borderRadius:"6px",backgroundColor:"transparent",color:"#fff",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease",touchAction:"manipulation"},b={...a,opacity:.4,cursor:"not-allowed"},m=s<t,g=s>i;return o.jsxs("div",{className:c,style:f,children:[o.jsx("button",{type:"button",onClick:r,disabled:!m,style:m?a:b,title:"Zoom In",children:"+"}),o.jsx("button",{type:"button",onClick:h,disabled:!g,style:g?a:b,title:"Zoom Out",children:"−"})]})});Ne.displayName="ZoomControls";const $e=n.memo(({visible:s,x:i,y:t,seat:r,currency:h,state:u})=>{if(!s||!r)return null;const c=r.seatNumber||(r.rowLabel&&r.columnLabel?`${r.rowLabel}-${r.columnLabel}`:"N/A"),S={position:"fixed",left:`${i+15}px`,top:`${t+15}px`,zIndex:1e3,pointerEvents:"none"},f={backgroundColor:"rgba(26, 26, 26, 0.95)",color:"#fff",border:"1px solid #444",borderRadius:"8px",padding:"8px 12px",fontSize:"13px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)",minWidth:"140px"},a={color:"#9ca3af",marginRight:"4px"},b={fontWeight:600},m={color:"#4ade80",fontWeight:600},g={fontSize:"11px",color:"#6b7280",textTransform:"capitalize",marginTop:"4px"};return o.jsx("div",{style:S,children:o.jsxs("div",{style:f,children:[r.sectionName&&o.jsxs("div",{style:{marginBottom:"4px"},children:[o.jsx("span",{style:a,children:"Section:"}),o.jsx("span",{style:{...b,color:"#3b82f6"},children:r.sectionName})]}),o.jsxs("div",{style:{marginBottom:"4px"},children:[o.jsx("span",{style:a,children:"Seat:"}),o.jsx("span",{style:b,children:c})]}),r.price!==void 0&&r.price>0&&u==="available"&&o.jsxs("div",{style:{marginBottom:"4px"},children:[o.jsx("span",{style:a,children:"Price:"}),o.jsxs("span",{style:m,children:[h," ",r.price.toFixed(2)]})]}),o.jsxs("div",{style:g,children:["Status: ",u]})]})})});$e.displayName="SeatTooltip";const ut=({config:s,configUrl:i,floorId:t,onFloorChange:r,reservedSeats:h=[],otherReservedSeats:u,unavailableSeats:c=[],selectedSeats:S,myReservedSeats:f=[],onSeatSelect:a,onSeatDeselect:b,onSelectionChange:m,colorOverrides:g,showTooltip:C=!0,zoomEnabled:y=!0,className:j="",onConfigLoad:p,onError:F,showFloorSelector:R,floorSelectorPosition:k="top-left",floorSelectorClassName:E,showAllFloorsOption:I=!0,allFloorsLabel:T="All",fitToView:W=!0,fitPadding:Y=40,showZoomControls:ne=!0,zoomControlsPosition:se="bottom-right",zoomControlsClassName:re,minZoom:oe,maxZoom:P=3,zoomStep:U=.25,touchEnabled:Xe=!0})=>{const ve=u!==void 0?u:h,ge=n.useRef(null),we=n.useRef(null),L=Fe(we),[H,Ce]=n.useState(new Set),[z,Z]=n.useState(1),[$,O]=n.useState({x:0,y:0}),[Ae,Ye]=n.useState(null),[Be,Ve]=n.useState(1),ie=n.useRef({width:0,height:0}),[K,Re]=n.useState({visible:!1,x:0,y:0,seat:null,state:"available"}),{config:Ue,loading:He,error:J}=Ee(i),d=s||Ue,pe=t!==void 0,D=pe?t||null:Ae,ae=S!==void 0,Oe=n.useCallback(e=>{pe||Ye(e),r?.(e)},[pe,r]),xe=d?.floors||[],qe=R!==void 0?R:xe.length>1,ce=n.useMemo(()=>d?{...d.colors,...g}:{...Ie,...g},[d,g]),q=n.useMemo(()=>{if(!d)return[];let e=d.seats.filter(l=>l.state!=="hidden");return D&&(e=e.filter(l=>l.floorId===D||!l.floorId&&D==="floor_default")),e},[d,D]),le=n.useMemo(()=>d?.stages?D?d.stages.filter(e=>e.floorId===D||!e.floorId&&D==="floor_default"):d.stages:[],[d,D]),ue=n.useMemo(()=>d?.texts?D?d.texts.filter(e=>e.floorId===D||!e.floorId&&D==="floor_default"):d.texts:[],[d,D]),X=n.useMemo(()=>{if(!d||q.length===0&&le.length===0&&ue.length===0)return null;const e=12;let l=1/0,x=1/0,v=-1/0,M=-1/0;return q.forEach(w=>{l=Math.min(l,w.position.x-e),x=Math.min(x,w.position.y-e),v=Math.max(v,w.position.x+e),M=Math.max(M,w.position.y+e)}),le.forEach(w=>{l=Math.min(l,w.position.x),x=Math.min(x,w.position.y),v=Math.max(v,w.position.x+(w.config?.width||200)),M=Math.max(M,w.position.y+(w.config?.height||100))}),ue.forEach(w=>{const V=w.config.text.length*w.config.fontSize*.6,G=w.config.fontSize;l=Math.min(l,w.position.x),x=Math.min(x,w.position.y),v=Math.max(v,w.position.x+V),M=Math.max(M,w.position.y+G)}),{minX:l,minY:x,maxX:v,maxY:M,width:v-l,height:M-x}},[d,q,le,ue]);n.useEffect(()=>{if(!W||!d||!X||L.width===0||L.height===0)return;const e=Math.abs(L.width-ie.current.width),l=Math.abs(L.height-ie.current.height);if(!(ie.current.width===0)&&e<10&&l<10)return;ie.current=L;const v=L.width,M=L.height,w=v-Y*2,V=M-Y*2,G=w/X.width,Se=V/X.height,de=Math.min(G,Se,P),st=X.minX+X.width/2,rt=X.minY+X.height/2,ot=v/2,it=M/2,at=ot-st*de,ct=it-rt*de;Z(de),O({x:at,y:ct}),Ve(de)},[W,d,X,Y,P,L,D]);const B=n.useMemo(()=>{const e=new Set(ve),l=new Set(c),x=new Set(f);return{reserved:e,unavailable:l,myReserved:x}},[ve,c,f]),be=n.useMemo(()=>S?new Set(S):null,[S]),Q=n.useCallback(e=>{const l=e.id,x=e.seatNumber||"";return B.unavailable.has(l)||B.unavailable.has(x)?"unavailable":B.reserved.has(l)||B.reserved.has(x)?"reserved":B.myReserved.has(l)||B.myReserved.has(x)||H.has(l)?"selected":e.state},[B,H]);n.useEffect(()=>{d&&p&&p(d)},[d,p]),n.useEffect(()=>{J&&F&&F(J)},[J,F]),n.useEffect(()=>{ae&&be&&Ce(be)},[ae,be]);const _e=n.useCallback(e=>{const l=Q(e);if(l!=="available"&&l!=="selected")return;const x=H.has(e.id);ae||Ce(v=>{const M=new Set(v);return x?M.delete(e.id):M.add(e.id),M}),x?b?.(e):(a?.(e),a||console.log("Seat selected:",e))},[Q,H,ae,a,b]),ee=n.useMemo(()=>d?q.filter(e=>H.has(e.id)):[],[d,q,H]);n.useEffect(()=>{m?.(ee)},[ee,m]);const _=oe!==void 0?oe:Be,Ge=n.useCallback(()=>{if(!y)return;const e=Math.min(z+U,P);if(e!==z){const l=L.width||d?.canvas.width||800,x=L.height||d?.canvas.height||600,v=l/2,M=x/2,w={x:(v-$.x)/z,y:(M-$.y)/z};Z(e),O({x:v-w.x*e,y:M-w.y*e})}},[y,z,U,P,L,d,$]),Ze=n.useCallback(()=>{if(!y)return;const e=Math.max(z-U,_);if(e!==z){const l=L.width||d?.canvas.width||800,x=L.height||d?.canvas.height||600,v=l/2,M=x/2,w={x:(v-$.x)/z,y:(M-$.y)/z};Z(e),O({x:v-w.x*e,y:M-w.y*e})}},[y,z,U,_,L,d,$]),Ke=n.useCallback(e=>{O({x:e.target.x(),y:e.target.y()})},[]),Je=n.useCallback(e=>{if(!y)return;e.evt.preventDefault();const l=ge.current;if(!l)return;const x=l.scaleX(),v=l.getPointerPosition();if(!v)return;const M=1.1,w=e.evt.deltaY>0?x/M:x*M,V=Math.min(Math.max(w,_),P),G={x:(v.x-$.x)/x,y:(v.y-$.y)/x},Se={x:v.x-G.x*V,y:v.y-G.y*V};Z(V),O(Se)},[y,$,_,P]);ke(ge,{enabled:Xe&&y,minScale:_,maxScale:P,currentScale:z,currentPosition:$,onScaleChange:(e,l)=>{Z(e),O(l)}});const Qe=n.useCallback((e,l)=>{if(!C)return;const x=l.target.getStage();if(!x)return;const v=x.getPointerPosition();if(!v)return;const M=x.container().getBoundingClientRect();Re({visible:!0,x:M.left+v.x,y:M.top+v.y,seat:e,state:Q(e)})},[C,Q]),et=n.useCallback(()=>{Re(e=>({...e,visible:!1}))},[]);if(He)return o.jsx("div",{className:`flex items-center justify-center h-full ${j}`,children:o.jsx("p",{children:"Loading seat map..."})});if(J)return o.jsx("div",{className:`flex items-center justify-center h-full ${j}`,children:o.jsxs("p",{className:"text-red-500",children:["Error loading seat map: ",J.message]})});if(!d)return o.jsx("div",{className:`flex items-center justify-center h-full ${j}`,children:o.jsx("p",{children:"No configuration provided"})});const tt=L.width||d.canvas.width,nt=L.height||d.canvas.height;return o.jsxs("div",{ref:we,className:`relative ${j}`,style:{width:"100%",height:"100%"},children:[qe&&xe.length>0&&o.jsx(De,{floors:xe,currentFloorId:D,onFloorChange:Oe,showAllOption:I,allLabel:T,position:k,className:E}),o.jsxs(N.Stage,{ref:ge,width:tt,height:nt,scaleX:z,scaleY:z,x:$.x,y:$.y,draggable:!0,onDragEnd:Ke,onWheel:Je,style:{backgroundColor:d.canvas.backgroundColor,cursor:"grab"},children:[o.jsx(N.Layer,{listening:!1,children:le.map(e=>o.jsx(Te,{stage:e,stageColor:ce.stageColor},e.id))}),o.jsx(N.Layer,{listening:!1,children:ue.map(e=>o.jsx(ze,{text:e},e.id))}),o.jsx(N.Layer,{children:q.map(e=>o.jsx(Le,{seat:e,state:Q(e),colors:ce,onClick:_e,onMouseEnter:Qe,onMouseLeave:et},e.id))})]}),C&&o.jsx($e,{visible:K.visible,x:K.x,y:K.y,seat:K.seat,currency:ce.currency,state:K.state}),ne&&y&&o.jsx(Ne,{scale:z,minScale:_,maxScale:P,onZoomIn:Ge,onZoomOut:Ze,position:se,className:re}),ee.length>0&&o.jsxs("div",{className:"absolute top-4 right-4 bg-white dark:bg-gray-800 p-4 rounded shadow-lg",children:[o.jsxs("h3",{className:"font-semibold mb-2",children:["Selected Seats (",ee.length,")"]}),o.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:ee.map(e=>o.jsxs("div",{className:"text-sm",children:[e.seatNumber,e.price&&` - ${ce.currency} ${e.price.toFixed(2)}`]},e.id))})]})]})};let te=null;function dt(s){te=s}function ye(){if(!te)throw new Error("Firebase database not initialized. Call initializeFirebaseForViewer(db) first.");return te}function fe(){return te!==null}function ht(){te=null}function me(s,i){if(s.length!==i.length)return!1;const t=[...s].sort(),r=[...i].sort();return t.every((h,u)=>h===r[u])}function ft(s,i){const t=[],r=[],h=[];return Object.entries(s).forEach(([u,c])=>{c&&typeof c=="object"&&c.state&&(c.state==="unavailable"?h.push(u):c.state==="reserved"&&(i&&c.userId===i?t.push(u):r.push(u)))}),{myReserved:t.sort(),otherReserved:r.sort(),unavailable:h.sort()}}const he={states:null,loading:!0,error:null,lastUpdated:null,myReservedSeats:[],otherReservedSeats:[],unavailableSeats:[]};function We(s){const{seatMapId:i,currentUserId:t,enabled:r=!0,onStateChange:h,onError:u}=s,c=n.useRef({...he}),S=n.useRef(h),f=n.useRef(u),a=n.useRef(t);S.current=h,f.current=u,a.current=t;const b=n.useCallback(y=>{if(!r||!i)return(c.current.loading!==!1||c.current.states!==null)&&(c.current={...he,loading:!1},y()),()=>{};if(!fe()){const k="Firebase not initialized. Call initializeFirebaseForViewer first.";return c.current.error?.message!==k&&(c.current={...he,loading:!1,error:new Error(k)},y()),()=>{}}const j=ye(),p=A.ref(j,`seatmaps/${i}/seat_states`),F=k=>{const I=k.val()||{},T=ft(I,a.current),W=c.current;(W.loading||!me(W.myReservedSeats,T.myReserved)||!me(W.otherReservedSeats,T.otherReserved)||!me(W.unavailableSeats,T.unavailable))&&(c.current={states:I,loading:!1,error:null,lastUpdated:Date.now(),myReservedSeats:T.myReserved,otherReservedSeats:T.otherReserved,unavailableSeats:T.unavailable},S.current?.(I),y())},R=k=>{c.current={...c.current,loading:!1,error:k},f.current?.(k),y()};return A.onValue(p,F,R),()=>{A.off(p)}},[i,r]),m=n.useCallback(()=>c.current,[]),g=n.useCallback(()=>he,[]),C=n.useSyncExternalStore(b,m,g);return{states:C.states,loading:C.loading,error:C.error,lastUpdated:C.lastUpdated,myReservedSeats:C.myReservedSeats,otherReservedSeats:C.otherReservedSeats,unavailableSeats:C.unavailableSeats,reservedSeats:C.otherReservedSeats}}function Pe(s){const{seatMapId:i,enabled:t=!0,subscribeToChanges:r=!1,onConfigLoad:h,onError:u}=s,[c,S]=n.useState(null),[f,a]=n.useState(!0),[b,m]=n.useState(null),g=n.useRef(h),C=n.useRef(u);g.current=h,C.current=u;const y=n.useCallback(async()=>{if(!i)return;if(!fe()){m(new Error("Firebase not initialized. Call initializeFirebaseForViewer first.")),a(!1);return}const j=ye(),p=A.ref(j,`seatmaps/${i}`);try{a(!0),m(null);const R=(await A.get(p)).val();if(R){const k=lt.fromFirebaseSeatMap(R);S(k),g.current?.(k)}else m(new Error(`Seat map ${i} not found in Firebase`))}catch(F){const R=F instanceof Error?F:new Error("Unknown error");m(R),C.current?.(R)}finally{a(!1)}},[i]);return n.useEffect(()=>{if(!t||!i){a(!1);return}if(y(),r&&fe()){const j=ye(),p=A.ref(j,`seatmaps/${i}/meta/updated_at`);let F=!0,R=null;const k=E=>{if(F){F=!1,R=E.val();return}const I=E.val();E.exists()&&I!==R&&(R=I,y())};return A.onValue(p,k),()=>{A.off(p)}}},[i,t,r]),{config:c,loading:f,error:b,refetch:y}}function gt(s){const{seatMapId:i,userId:t,enabled:r=!0,subscribeToDesignChanges:h=!1,onConfigLoad:u,onStateChange:c,onError:S}=s,{config:f,loading:a,error:b,refetch:m}=Pe({seatMapId:i,enabled:r,subscribeToChanges:h,onConfigLoad:u,onError:S}),{states:g,loading:C,error:y,lastUpdated:j,myReservedSeats:p,otherReservedSeats:F,unavailableSeats:R,reservedSeats:k}=We({seatMapId:i,currentUserId:t,enabled:r,onStateChange:c,onError:S});return{config:f,loading:a||C,error:b||y,myReservedSeats:p,otherReservedSeats:F,unavailableSeats:R,reservedSeats:k,seatStates:g,lastUpdated:j,refetch:m}}exports.DEFAULT_COLORS=Ie;exports.SeatMapViewer=ut;exports.clearFirebaseInstance=ht;exports.initializeFirebaseForViewer=dt;exports.isFirebaseInitialized=fe;exports.useConfigFetcher=Ee;exports.useContainerSize=Fe;exports.useFirebaseConfig=Pe;exports.useFirebaseSeatStates=We;exports.useRealtimeSeatMap=gt;exports.useTouchGestures=ke;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),n=require("react"),N=require("react-konva"),Y=require("firebase/database"),at=require("@zonetrix/shared");function Fe(s){const[i,t]=n.useState(null),[r,f]=n.useState(!1),[d,a]=n.useState(null),y=n.useCallback(async()=>{if(s){f(!0),a(null);try{const b=await fetch(s);if(!b.ok)throw new Error(`Failed to fetch config: ${b.statusText}`);const c=await b.json();t(c)}catch(b){const c=b instanceof Error?b:new Error("Unknown error occurred");a(c),console.error("Failed to fetch seat map config:",c)}finally{f(!1)}}},[s]);return n.useEffect(()=>{y()},[y]),{config:i,loading:r,error:d,refetch:y}}function Ee(s){const[i,t]=n.useState({width:0,height:0});return n.useEffect(()=>{const r=s.current;if(!r)return;const{width:f,height:d}=r.getBoundingClientRect();f>0&&d>0&&t({width:f,height:d});const a=new ResizeObserver(y=>{const b=y[0];if(!b)return;const{width:c,height:x}=b.contentRect;c>0&&x>0&&t(v=>v.width===c&&v.height===x?v:{width:c,height:x})});return a.observe(r),()=>{a.disconnect()}},[s]),i}function Me(s,i){return Math.sqrt(Math.pow(i.x-s.x,2)+Math.pow(i.y-s.y,2))}function je(s,i){return{x:(s.x+i.x)/2,y:(s.y+i.y)/2}}function ke(s,i){const t=n.useRef(null),r=n.useRef(null),f=n.useRef(1),{enabled:d,minScale:a,maxScale:y,currentScale:b,currentPosition:c,onScaleChange:x}=i;n.useEffect(()=>{const v=s.current;if(!v||!d)return;const g=v.container(),w=S=>{if(S.touches.length===2){S.preventDefault();const F={x:S.touches[0].clientX,y:S.touches[0].clientY},R={x:S.touches[1].clientX,y:S.touches[1].clientY};t.current=Me(F,R),r.current=je(F,R),f.current=b}},m=S=>{if(S.touches.length!==2)return;S.preventDefault();const F={x:S.touches[0].clientX,y:S.touches[0].clientY},R={x:S.touches[1].clientX,y:S.touches[1].clientY},E=Me(F,R),j=je(F,R);if(t.current!==null&&r.current!==null){const I=E/t.current,L=Math.min(Math.max(b*I,a),y),W=g.getBoundingClientRect(),B=j.x-W.left,te=j.y-W.top,ne=b,se={x:(B-c.x)/ne,y:(te-c.y)/ne},re=j.x-r.current.x,P=j.y-r.current.y,O={x:B-se.x*L+re,y:te-se.y*L+P};x(L,O),t.current=E,r.current=j}},M=S=>{S.touches.length<2&&(t.current=null,r.current=null)};return g.addEventListener("touchstart",w,{passive:!1}),g.addEventListener("touchmove",m,{passive:!1}),g.addEventListener("touchend",M),()=>{g.removeEventListener("touchstart",w),g.removeEventListener("touchmove",m),g.removeEventListener("touchend",M)}},[s,d,a,y,b,c,x])}const Ie={canvasBackground:"#1a1a1a",stageColor:"#808080",seatAvailable:"#2C2B30",seatReserved:"#FCEA00",seatSelected:"#3A7DE5",seatUnavailable:"#6b7280",seatHidden:"#4a4a4a",gridLines:"#404040",currency:"KD"},Te=n.memo(({seat:s,state:i,colors:t,onClick:r,onMouseEnter:f,onMouseLeave:d})=>{const a=(s.size||24)/2,b={available:t.seatAvailable,reserved:t.seatReserved,selected:t.seatSelected,unavailable:t.seatUnavailable,hidden:t.seatHidden}[i],c=i==="available"||i==="selected",x=n.useCallback(()=>{c&&r(s)},[s,r,c]),v=n.useCallback(m=>{f(s,m);const M=m.target.getStage();M&&c&&(M.container().style.cursor="pointer")},[s,f,c]),g=n.useCallback(m=>{d();const M=m.target.getStage();M&&(M.container().style.cursor="grab")},[d]),w={x:s.position.x,y:s.position.y,fill:b,stroke:"#ffffff",strokeWidth:1,onClick:x,onTap:x,onMouseEnter:v,onMouseLeave:g};return s.shape==="circle"?o.jsx(N.Circle,{...w,radius:a}):o.jsx(N.Rect,{...w,width:a*2,height:a*2,offsetX:a,offsetY:a,cornerRadius:s.shape==="square"?0:4})});Te.displayName="ViewerSeat";const Le=n.memo(({stage:s,stageColor:i})=>{const t=s.config,r=t.shape||"rectangle",f=t.showLabel!==!1,d=t.color||i,a=t.width/t.height,y=a<.5,b=a>2;let c;y?c=t.width*.25:b?c=t.height*.35:c=Math.min(t.width,t.height)*.25;const x=t.label?.length||6,w=t.width*.85/x*1.5,m=Math.max(10,Math.min(24,Math.min(c,w))),M=4,S=Math.max(20,t.width-M*2),F=(t.width-S)/2,R={fill:d+"80",stroke:"#ffffff",strokeWidth:2,perfectDrawEnabled:!1,hitStrokeWidth:0},E=()=>{switch(r){case"circle":{const j=Math.min(t.width,t.height)/2;return o.jsx(N.Circle,{x:t.width/2,y:t.height/2,radius:j,...R})}case"triangle":{const j=Math.min(t.width,t.height)/2;return o.jsx(N.RegularPolygon,{x:t.width/2,y:t.height/2,sides:3,radius:j,rotation:-90,...R})}case"arrow":{const j=t.width/24,I=t.height/24,L=`M${9*j},${18*I} v${-8*I} H${5*j} l${7*j},${-7*I} l${7*j},${7*I} h${-4*j} v${8*I} Z`;return o.jsx(N.Path,{data:L,...R})}default:return o.jsx(N.Rect,{width:t.width,height:t.height,cornerRadius:10,...R})}};return o.jsxs(N.Group,{x:s.position.x,y:s.position.y,rotation:t.rotation||0,children:[E(),f&&o.jsx(N.Text,{text:t.label,x:F,y:M,width:S,height:t.height-M*2,fontSize:m,fontStyle:"bold",fill:"#ffffff",align:"center",verticalAlign:"middle",wrap:"word",ellipsis:!0})]})});Le.displayName="ViewerStage";const De=n.memo(({text:s})=>o.jsx(N.Text,{x:s.position.x,y:s.position.y,text:s.config.text,fontSize:s.config.fontSize,fill:s.config.color,rotation:s.config.rotation||0,listening:!1}));De.displayName="ViewerText";const ze=n.memo(({floors:s,currentFloorId:i,onFloorChange:t,showAllOption:r,allLabel:f,position:d,className:a})=>{const y=n.useMemo(()=>[...s].sort((g,w)=>g.order-w.order),[s]),c={position:"absolute",display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:"rgba(26, 26, 26, 0.95)",borderRadius:"8px",margin:"12px",zIndex:10,...{"top-left":{top:0,left:0},"top-right":{top:0,right:0},"bottom-left":{bottom:0,left:0},"bottom-right":{bottom:0,right:0}}[d]},x={padding:"10px 16px",fontSize:"14px",fontWeight:500,border:"1px solid #444",borderRadius:"6px",backgroundColor:"transparent",color:"#fff",cursor:"pointer",transition:"all 0.2s ease",minHeight:"44px",touchAction:"manipulation"},v={...x,backgroundColor:"#3A7DE5",borderColor:"#3A7DE5"};return o.jsxs("div",{className:a,style:c,children:[r&&o.jsx("button",{type:"button",onClick:()=>t(null),style:i===null?v:x,children:f}),y.map(g=>o.jsx("button",{type:"button",onClick:()=>t(g.id),style:i===g.id?v:x,children:g.name},g.id))]})});ze.displayName="FloorSelectorBar";const Ne=n.memo(({scale:s,minScale:i,maxScale:t,onZoomIn:r,onZoomOut:f,onFitToScreen:d,position:a,className:y})=>{const c={position:"absolute",display:"flex",flexDirection:"column",gap:"4px",padding:"8px",backgroundColor:"rgba(26, 26, 26, 0.95)",borderRadius:"8px",margin:"12px",zIndex:10,...{"top-left":{top:0,left:0},"top-right":{top:0,right:0},"bottom-left":{bottom:0,left:0},"bottom-right":{bottom:0,right:0}}[a]},x={width:"44px",height:"44px",minWidth:"44px",minHeight:"44px",fontSize:"22px",fontWeight:"bold",border:"1px solid #444",borderRadius:"6px",backgroundColor:"transparent",color:"#fff",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.2s ease",touchAction:"manipulation"},v={...x,opacity:.4,cursor:"not-allowed"},g=s<t,w=s>i,m=Math.abs(s-i)<.01;return o.jsxs("div",{className:y,style:c,children:[o.jsx("button",{type:"button",onClick:r,disabled:!g,style:g?x:v,title:"Zoom In","aria-label":"Zoom In",children:"+"}),o.jsx("button",{type:"button",onClick:d,disabled:m,style:m?v:x,title:"Fit to Screen","aria-label":"Fit to Screen",children:"⤢"}),o.jsx("button",{type:"button",onClick:f,disabled:!w,style:w?x:v,title:"Zoom Out","aria-label":"Zoom Out",children:"−"})]})});Ne.displayName="ZoomControls";const $e=n.memo(({visible:s,x:i,y:t,seat:r,currency:f,state:d})=>{if(!s||!r)return null;const a=r.seatNumber||(r.rowLabel&&r.columnLabel?`${r.rowLabel}-${r.columnLabel}`:"N/A"),y={position:"fixed",left:`${i+15}px`,top:`${t+15}px`,zIndex:1e3,pointerEvents:"none"},b={backgroundColor:"rgba(26, 26, 26, 0.95)",color:"#fff",border:"1px solid #444",borderRadius:"8px",padding:"8px 12px",fontSize:"13px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)",minWidth:"140px"},c={color:"#9ca3af",marginRight:"4px"},x={fontWeight:600},v={color:"#4ade80",fontWeight:600},g={fontSize:"11px",color:"#6b7280",textTransform:"capitalize",marginTop:"4px"};return o.jsx("div",{style:y,children:o.jsxs("div",{style:b,children:[r.sectionName&&o.jsxs("div",{style:{marginBottom:"4px"},children:[o.jsx("span",{style:c,children:"Section:"}),o.jsx("span",{style:{...x,color:"#3b82f6"},children:r.sectionName})]}),o.jsxs("div",{style:{marginBottom:"4px"},children:[o.jsx("span",{style:c,children:"Seat:"}),o.jsx("span",{style:x,children:a})]}),r.price!==void 0&&r.price>0&&d==="available"&&o.jsxs("div",{style:{marginBottom:"4px"},children:[o.jsx("span",{style:c,children:"Price:"}),o.jsxs("span",{style:v,children:[f," ",r.price.toFixed(2)]})]}),o.jsxs("div",{style:g,children:["Status: ",d]})]})})});$e.displayName="SeatTooltip";const ct=({config:s,configUrl:i,floorId:t,onFloorChange:r,reservedSeats:f=[],otherReservedSeats:d,unavailableSeats:a=[],selectedSeats:y,myReservedSeats:b=[],onSeatSelect:c,onSeatDeselect:x,onSelectionChange:v,colorOverrides:g,showTooltip:w=!0,zoomEnabled:m=!0,className:M="",onConfigLoad:S,onError:F,showFloorSelector:R,floorSelectorPosition:E="top-left",floorSelectorClassName:j,showAllFloorsOption:I=!0,allFloorsLabel:L="All",fitToView:W=!0,fitPadding:B=40,showZoomControls:te=!0,zoomControlsPosition:ne="bottom-right",zoomControlsClassName:se,minZoom:re,maxZoom:P=3,zoomStep:O=.25,touchEnabled:Xe=!0})=>{const ve=d!==void 0?d:f,fe=n.useRef(null),we=n.useRef(null),k=Ee(we),[U,Ce]=n.useState(new Set),[D,Z]=n.useState(1),[$,H]=n.useState({x:0,y:0}),[Ae,Ye]=n.useState(null),[Be,Ve]=n.useState(1),oe=n.useRef({width:0,height:0}),[G,Re]=n.useState({visible:!1,x:0,y:0,seat:null,state:"available"}),{config:Oe,loading:Ue,error:K}=Fe(i),h=s||Oe,ge=t!==void 0,z=ge?t||null:Ae,ie=y!==void 0,He=n.useCallback(e=>{ge||Ye(e),r?.(e)},[ge,r]),pe=h?.floors||[],qe=R!==void 0?R:pe.length>1,ae=n.useMemo(()=>h?{...h.colors,...g}:{...Ie,...g},[h,g]),q=n.useMemo(()=>{if(!h)return[];let e=h.seats.filter(l=>l.state!=="hidden");return z&&(e=e.filter(l=>l.floorId===z||!l.floorId&&z==="floor_default")),e},[h,z]),ce=n.useMemo(()=>h?.stages?z?h.stages.filter(e=>e.floorId===z||!e.floorId&&z==="floor_default"):h.stages:[],[h,z]),le=n.useMemo(()=>h?.texts?z?h.texts.filter(e=>e.floorId===z||!e.floorId&&z==="floor_default"):h.texts:[],[h,z]),X=n.useMemo(()=>{if(!h||q.length===0&&ce.length===0&&le.length===0)return null;let e=1/0,l=1/0,p=-1/0,C=-1/0;return q.forEach(u=>{const T=(u.size||24)/2;e=Math.min(e,u.position.x-T),l=Math.min(l,u.position.y-T),p=Math.max(p,u.position.x+T),C=Math.max(C,u.position.y+T)}),ce.forEach(u=>{e=Math.min(e,u.position.x),l=Math.min(l,u.position.y),p=Math.max(p,u.position.x+(u.config?.width||200)),C=Math.max(C,u.position.y+(u.config?.height||100))}),le.forEach(u=>{const T=u.config.text.length*u.config.fontSize*.6,A=u.config.fontSize;e=Math.min(e,u.position.x),l=Math.min(l,u.position.y),p=Math.max(p,u.position.x+T),C=Math.max(C,u.position.y+A)}),{minX:e,minY:l,maxX:p,maxY:C,width:p-e,height:C-l}},[h,q,ce,le]),be=n.useCallback(()=>{if(!h||!X||k.width===0||k.height===0)return;const e=k.width,l=k.height,p=e-B*2,C=l-B*2,u=p/X.width,T=C/X.height,A=Math.min(u,T,P),ue=X.minX+X.width/2,me=X.minY+X.height/2,st=e/2,rt=l/2,ot=st-ue*A,it=rt-me*A;Z(A),H({x:ot,y:it}),Ve(A)},[h,X,k,B,P]);n.useEffect(()=>{if(!W||!h||!X||k.width===0||k.height===0)return;const e=Math.abs(k.width-oe.current.width),l=Math.abs(k.height-oe.current.height);!(oe.current.width===0)&&e<10&&l<10||(oe.current=k,be())},[W,h,X,k,z,be]);const V=n.useMemo(()=>{const e=new Set(ve),l=new Set(a),p=new Set(b);return{reserved:e,unavailable:l,myReserved:p}},[ve,a,b]),xe=n.useMemo(()=>y?new Set(y):null,[y]),J=n.useCallback(e=>{const l=e.id,p=e.seatNumber||"";return V.unavailable.has(l)||V.unavailable.has(p)?"unavailable":V.reserved.has(l)||V.reserved.has(p)?"reserved":V.myReserved.has(l)||V.myReserved.has(p)||U.has(l)?"selected":e.state},[V,U]);n.useEffect(()=>{h&&S&&S(h)},[h,S]),n.useEffect(()=>{K&&F&&F(K)},[K,F]),n.useEffect(()=>{ie&&xe&&Ce(xe)},[ie,xe]);const _e=n.useCallback(e=>{const l=J(e);if(l!=="available"&&l!=="selected")return;const p=U.has(e.id);ie||Ce(C=>{const u=new Set(C);return p?u.delete(e.id):u.add(e.id),u}),p?x?.(e):(c?.(e),c||console.log("Seat selected:",e))},[J,U,ie,c,x]),Q=n.useMemo(()=>h?q.filter(e=>U.has(e.id)):[],[h,q,U]);n.useEffect(()=>{v?.(Q)},[Q,v]);const _=re!==void 0?re:Be,Ze=n.useCallback(()=>{if(!m)return;const e=Math.min(D+O,P);if(e!==D){const l=k.width||h?.canvas.width||800,p=k.height||h?.canvas.height||600,C=l/2,u=p/2,T={x:(C-$.x)/D,y:(u-$.y)/D};Z(e),H({x:C-T.x*e,y:u-T.y*e})}},[m,D,O,P,k,h,$]),Ge=n.useCallback(()=>{if(!m)return;const e=Math.max(D-O,_);if(e!==D){const l=k.width||h?.canvas.width||800,p=k.height||h?.canvas.height||600,C=l/2,u=p/2,T={x:(C-$.x)/D,y:(u-$.y)/D};Z(e),H({x:C-T.x*e,y:u-T.y*e})}},[m,D,O,_,k,h,$]),Ke=n.useCallback(e=>{H({x:e.target.x(),y:e.target.y()})},[]),Je=n.useCallback(e=>{if(!m)return;e.evt.preventDefault();const l=fe.current;if(!l)return;const p=l.scaleX(),C=l.getPointerPosition();if(!C)return;const u=1.1,T=e.evt.deltaY>0?p/u:p*u,A=Math.min(Math.max(T,_),P),ue={x:(C.x-$.x)/p,y:(C.y-$.y)/p},me={x:C.x-ue.x*A,y:C.y-ue.y*A};Z(A),H(me)},[m,$,_,P]);ke(fe,{enabled:Xe&&m,minScale:_,maxScale:P,currentScale:D,currentPosition:$,onScaleChange:(e,l)=>{Z(e),H(l)}});const Qe=n.useCallback((e,l)=>{if(!w)return;const p=l.target.getStage();if(!p)return;const C=p.getPointerPosition();if(!C)return;const u=p.container().getBoundingClientRect();Re({visible:!0,x:u.left+C.x,y:u.top+C.y,seat:e,state:J(e)})},[w,J]),et=n.useCallback(()=>{Re(e=>({...e,visible:!1}))},[]);if(Ue)return o.jsx("div",{className:`flex items-center justify-center h-full ${M}`,children:o.jsx("p",{children:"Loading seat map..."})});if(K)return o.jsx("div",{className:`flex items-center justify-center h-full ${M}`,children:o.jsxs("p",{className:"text-red-500",children:["Error loading seat map: ",K.message]})});if(!h)return o.jsx("div",{className:`flex items-center justify-center h-full ${M}`,children:o.jsx("p",{children:"No configuration provided"})});const tt=k.width||h.canvas.width,nt=k.height||h.canvas.height;return o.jsxs("div",{ref:we,className:`relative ${M}`,style:{width:"100%",height:"100%"},children:[qe&&pe.length>0&&o.jsx(ze,{floors:pe,currentFloorId:z,onFloorChange:He,showAllOption:I,allLabel:L,position:E,className:j}),o.jsxs(N.Stage,{ref:fe,width:tt,height:nt,scaleX:D,scaleY:D,x:$.x,y:$.y,draggable:!0,onDragEnd:Ke,onWheel:Je,style:{backgroundColor:h.canvas.backgroundColor,cursor:"grab"},children:[o.jsx(N.Layer,{listening:!1,children:ce.map(e=>o.jsx(Le,{stage:e,stageColor:ae.stageColor},e.id))}),o.jsx(N.Layer,{listening:!1,children:le.map(e=>o.jsx(De,{text:e},e.id))}),o.jsx(N.Layer,{children:q.map(e=>o.jsx(Te,{seat:e,state:J(e),colors:ae,onClick:_e,onMouseEnter:Qe,onMouseLeave:et},e.id))})]}),w&&o.jsx($e,{visible:G.visible,x:G.x,y:G.y,seat:G.seat,currency:ae.currency,state:G.state}),te&&m&&o.jsx(Ne,{scale:D,minScale:_,maxScale:P,onZoomIn:Ze,onZoomOut:Ge,onFitToScreen:be,position:ne,className:se}),Q.length>0&&o.jsxs("div",{className:"absolute top-4 right-4 bg-white dark:bg-gray-800 p-4 rounded shadow-lg",children:[o.jsxs("h3",{className:"font-semibold mb-2",children:["Selected Seats (",Q.length,")"]}),o.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:Q.map(e=>o.jsxs("div",{className:"text-sm",children:[e.seatNumber,e.price&&` - ${ae.currency} ${e.price.toFixed(2)}`]},e.id))})]})]})};let ee=null;function lt(s){ee=s}function ye(){if(!ee)throw new Error("Firebase database not initialized. Call initializeFirebaseForViewer(db) first.");return ee}function he(){return ee!==null}function ut(){ee=null}function Se(s,i){if(s.length!==i.length)return!1;const t=[...s].sort(),r=[...i].sort();return t.every((f,d)=>f===r[d])}function dt(s,i){const t=[],r=[],f=[];return Object.entries(s).forEach(([d,a])=>{a&&typeof a=="object"&&a.state&&(a.state==="unavailable"?f.push(d):a.state==="reserved"&&(i&&a.userId===i?t.push(d):r.push(d)))}),{myReserved:t.sort(),otherReserved:r.sort(),unavailable:f.sort()}}const de={states:null,loading:!0,error:null,lastUpdated:null,myReservedSeats:[],otherReservedSeats:[],unavailableSeats:[]};function We(s){const{seatMapId:i,currentUserId:t,enabled:r=!0,onStateChange:f,onError:d}=s,a=n.useRef({...de}),y=n.useRef(f),b=n.useRef(d),c=n.useRef(t);y.current=f,b.current=d,c.current=t;const x=n.useCallback(m=>{if(!r||!i)return(a.current.loading!==!1||a.current.states!==null)&&(a.current={...de,loading:!1},m()),()=>{};if(!he()){const E="Firebase not initialized. Call initializeFirebaseForViewer first.";return a.current.error?.message!==E&&(a.current={...de,loading:!1,error:new Error(E)},m()),()=>{}}const M=ye(),S=Y.ref(M,`seatmaps/${i}/seat_states`),F=E=>{const I=E.val()||{},L=dt(I,c.current),W=a.current;(W.loading||!Se(W.myReservedSeats,L.myReserved)||!Se(W.otherReservedSeats,L.otherReserved)||!Se(W.unavailableSeats,L.unavailable))&&(a.current={states:I,loading:!1,error:null,lastUpdated:Date.now(),myReservedSeats:L.myReserved,otherReservedSeats:L.otherReserved,unavailableSeats:L.unavailable},y.current?.(I),m())},R=E=>{a.current={...a.current,loading:!1,error:E},b.current?.(E),m()};return Y.onValue(S,F,R),()=>{Y.off(S)}},[i,r]),v=n.useCallback(()=>a.current,[]),g=n.useCallback(()=>de,[]),w=n.useSyncExternalStore(x,v,g);return{states:w.states,loading:w.loading,error:w.error,lastUpdated:w.lastUpdated,myReservedSeats:w.myReservedSeats,otherReservedSeats:w.otherReservedSeats,unavailableSeats:w.unavailableSeats,reservedSeats:w.otherReservedSeats}}function Pe(s){const{seatMapId:i,enabled:t=!0,subscribeToChanges:r=!1,onConfigLoad:f,onError:d}=s,[a,y]=n.useState(null),[b,c]=n.useState(!0),[x,v]=n.useState(null),g=n.useRef(f),w=n.useRef(d);g.current=f,w.current=d;const m=n.useCallback(async()=>{if(!i)return;if(!he()){v(new Error("Firebase not initialized. Call initializeFirebaseForViewer first.")),c(!1);return}const M=ye(),S=Y.ref(M,`seatmaps/${i}`);try{c(!0),v(null);const R=(await Y.get(S)).val();if(R){const E=at.fromFirebaseSeatMap(R);y(E),g.current?.(E)}else v(new Error(`Seat map ${i} not found in Firebase`))}catch(F){const R=F instanceof Error?F:new Error("Unknown error");v(R),w.current?.(R)}finally{c(!1)}},[i]);return n.useEffect(()=>{if(!t||!i){c(!1);return}if(m(),r&&he()){const M=ye(),S=Y.ref(M,`seatmaps/${i}/meta/updated_at`);let F=!0,R=null;const E=j=>{if(F){F=!1,R=j.val();return}const I=j.val();j.exists()&&I!==R&&(R=I,m())};return Y.onValue(S,E),()=>{Y.off(S)}}},[i,t,r]),{config:a,loading:b,error:x,refetch:m}}function ht(s){const{seatMapId:i,userId:t,enabled:r=!0,subscribeToDesignChanges:f=!1,onConfigLoad:d,onStateChange:a,onError:y}=s,{config:b,loading:c,error:x,refetch:v}=Pe({seatMapId:i,enabled:r,subscribeToChanges:f,onConfigLoad:d,onError:y}),{states:g,loading:w,error:m,lastUpdated:M,myReservedSeats:S,otherReservedSeats:F,unavailableSeats:R,reservedSeats:E}=We({seatMapId:i,currentUserId:t,enabled:r,onStateChange:a,onError:y});return{config:b,loading:c||w,error:x||m,myReservedSeats:S,otherReservedSeats:F,unavailableSeats:R,reservedSeats:E,seatStates:g,lastUpdated:M,refetch:v}}exports.DEFAULT_COLORS=Ie;exports.SeatMapViewer=ct;exports.clearFirebaseInstance=ut;exports.initializeFirebaseForViewer=lt;exports.isFirebaseInitialized=he;exports.useConfigFetcher=Fe;exports.useContainerSize=Ee;exports.useFirebaseConfig=Pe;exports.useFirebaseSeatStates=We;exports.useRealtimeSeatMap=ht;exports.useTouchGestures=ke;