import{r as h}from"./react-vendor-BJie2xkO.js";import{g as m,a as C}from"./guestService-CqI2mvSO.js";import{a as I}from"./api-DAXyRoTB.js";import{u as p}from"./main-Bfm0Ar4t.js";const k=/\/checkin\/(\d+)\/guest\/(\d+)/i;function T(t){const n=t.trim();if(n.startsWith("http://")||n.startsWith("https://")){const r=k.exec(n);return r?{eventId:Number(r[1]),guestId:Number(r[2]),raw:n}:null}const u=k.exec(n);if(u)return{eventId:Number(u[1]),guestId:Number(u[2]),raw:n};const d=n.includes("-")?n.split("-").pop():n;return/^\d+$/.test(d)?{eventId:0,guestId:0,raw:n}:null}function y(t){if(t.startsWith("http"))return!1;const n=t.includes("-")?t.split("-").pop():t;return/^\d+$/.test(n.trim())}function b(t){return(t.includes("-")?t.split("-").pop():t).trim()}function G(){const t=p(e=>e.eventId),n=p(e=>e.updateGuest),u=h.useCallback(async(e,c)=>{var a,i;if(e.checked_in_count>=e.total_attendees)return{status:"already_checked_in",guest:e};try{const o=await I(e.id,c),s={...e,checked_in_count:o.checked_in_count,checked_in_at:o.checked_in_at??new Date().toISOString()};return n(e.id,{checked_in_count:o.checked_in_count,checked_in_at:o.checked_in_at}),{status:"checked_in",guest:s,message:s.checked_in_count<s.total_attendees?`Checked in ${s.checked_in_count} of ${s.total_attendees}`:"All attendees checked in"}}catch(o){const s=(a=o==null?void 0:o.response)==null?void 0:a.data;return((i=o==null?void 0:o.response)==null?void 0:i.status)===422&&typeof(s==null?void 0:s.checked_in_count)=="number"?(n(e.id,{checked_in_count:s.checked_in_count}),{status:"already_checked_in",guest:{...e,checked_in_count:s.checked_in_count}}):{status:"error",message:(s==null?void 0:s.error)||(s==null?void 0:s.message)||"Check-in failed. Please try again."}}},[n]),d=h.useCallback(async e=>{let c;if(e.guestId>0)return c=m(e.guestId),!c||c.event_id!==t?{status:"not_found",message:"Invitee not found for this event."}:u(c,"qr_scan");if(y(e.raw)){const a=b(e.raw);return c=C(a),!c||c.event_id!==t?{status:"not_found",message:"Card number not found in this event."}:u(c,"qr_scan")}return{status:"not_found",message:"Unrecognized QR code format."}},[t,u]),r=h.useCallback(async e=>{const c=m(e);return!c||c.event_id!==t?{status:"not_found"}:u(c,"manual_search")},[t,u]);return{handleScan:d,handleManualCheckIn:r}}let l=null;function g(){return l||(l=new(window.AudioContext||window.webkitAudioContext)),l.state==="suspended"&&l.resume(),l}function f(t,n,u=0,d="sine",r=.28){try{const e=g(),c=e.createOscillator(),a=e.createGain();c.connect(a),a.connect(e.destination),c.type=d,c.frequency.value=t;const i=e.currentTime+u;a.gain.setValueAtTime(r,i),a.gain.exponentialRampToValueAtTime(.001,i+n),c.start(i),c.stop(i+n)}catch{}}let _=null;function v(){return _||(_=new Audio("/beep2.wav"),_.preload="auto"),_}function R(){try{const t=v();t.currentTime=0,t.play().catch(()=>{})}catch{}}function S(){f(440,.22,0,"sine",.2)}function E(){f(280,.15,0,"sawtooth",.18),f(200,.18,.12,"sawtooth",.18)}function $(){try{g()}catch{}}export{R as a,E as b,S as c,$ as d,T as p,G as u};
