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