@zonetrix/viewer 2.11.0 → 2.11.2

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.
@@ -21,14 +21,14 @@ export interface SeatMapViewerProps {
21
21
  onConfigLoad?: (config: SeatMapConfig) => void;
22
22
  onError?: (error: Error) => void;
23
23
  showFloorSelector?: boolean;
24
- floorSelectorPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
24
+ floorSelectorPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
25
25
  floorSelectorClassName?: string;
26
26
  showAllFloorsOption?: boolean;
27
27
  allFloorsLabel?: string;
28
28
  fitToView?: boolean;
29
29
  fitPadding?: number;
30
30
  showZoomControls?: boolean;
31
- zoomControlsPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
31
+ zoomControlsPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
32
32
  zoomControlsClassName?: string;
33
33
  /**
34
34
  * Minimum zoom level.
package/dist/index.d.ts CHANGED
@@ -6,9 +6,9 @@ export { useConfigFetcher } from './hooks/useConfigFetcher';
6
6
  export { useContainerSize } from './hooks/useContainerSize';
7
7
  export { useTouchGestures } from './hooks/useTouchGestures';
8
8
  export { useFirebaseSeatStates } from './hooks/useFirebaseSeatStates';
9
- export type { UseFirebaseSeatStatesOptions, UseFirebaseSeatStatesResult } from './hooks/useFirebaseSeatStates';
9
+ export type { UseFirebaseSeatStatesOptions, UseFirebaseSeatStatesResult, } from './hooks/useFirebaseSeatStates';
10
10
  export { useFirebaseConfig } from './hooks/useFirebaseConfig';
11
- export type { UseFirebaseConfigOptions, UseFirebaseConfigResult } from './hooks/useFirebaseConfig';
11
+ export type { UseFirebaseConfigOptions, UseFirebaseConfigResult, } from './hooks/useFirebaseConfig';
12
12
  export { useRealtimeSeatMap } from './hooks/useRealtimeSeatMap';
13
- export type { UseRealtimeSeatMapOptions, UseRealtimeSeatMapResult } from './hooks/useRealtimeSeatMap';
13
+ export type { UseRealtimeSeatMapOptions, UseRealtimeSeatMapResult, } from './hooks/useRealtimeSeatMap';
14
14
  export { initializeFirebaseForViewer, isFirebaseInitialized, clearFirebaseInstance, } from './firebase/client';
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"),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;