var ICFChat=function(e){"use strict";class t{constructor(e,t){this.customerName="You",this.recordingTimer=null,this.config=e,this.container=document.createElement("div"),this.container.id="icf-widget-root",this.container.setAttribute("aria-live","polite"),this.injectStyles(e.primaryColor,e.position),this.bubble=this.createBubble(t.onOpen,t.onClose),this.panel=this.createPanel(e,t),this.messagesEl=this.panel.querySelector(".icf-messages"),this.typingEl=this.panel.querySelector(".icf-typing"),this.inputEl=this.panel.querySelector(".icf-input"),this.preChatForm=this.panel.querySelector(".icf-prechat"),this.chatView=this.panel.querySelector(".icf-chat-view"),this.container.appendChild(this.bubble),this.container.appendChild(this.panel),document.body.appendChild(this.container)}setCustomerName(e){this.customerName=e||"You"}injectStyles(e,t){const i=document.createElement("style"),n="bottom-right"===t;i.textContent=`\n #icf-widget-root * { box-sizing: border-box; font-family: system-ui, sans-serif; }\n .icf-bubble {\n position: fixed; bottom: 20px; ${n?"right: 20px":"left: 20px"};\n width: 56px; height: 56px; border-radius: 50%;\n background: ${e}; border: none; cursor: pointer;\n display: flex; align-items: center; justify-content: center;\n box-shadow: 0 4px 12px rgba(0,0,0,.25); transition: transform .2s; z-index: 9999;\n }\n .icf-bubble:hover { transform: scale(1.08); }\n .icf-bubble svg { fill: #fff; width: 26px; height: 26px; }\n .icf-panel {\n position: fixed; bottom: 86px; ${n?"right: 20px":"left: 20px"};\n width: 360px; height: 560px; background: #fff; border-radius: 16px;\n box-shadow: 0 8px 32px rgba(0,0,0,.18); display: none; flex-direction: column;\n overflow: hidden; z-index: 9998;\n }\n .icf-panel.open { display: flex; }\n .icf-header {\n background: ${e}; color: #fff; padding: 14px 16px;\n display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;\n }\n .icf-header h3 { margin: 0; font-size: 15px; font-weight: 600; }\n .icf-header p { margin: 2px 0 0; font-size: 12px; opacity: .8; }\n .icf-close { background: none; border: none; color: #fff; cursor: pointer; font-size: 20px; line-height: 1; }\n .icf-messages {\n flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex;\n flex-direction: column; gap: 10px; min-height: 0;\n }\n .icf-msg-wrap { display: flex; flex-direction: column; gap: 2px; }\n .icf-msg-wrap.customer { align-items: flex-end; }\n .icf-msg-wrap.agent { align-items: flex-start; }\n .icf-msg-wrap.system { align-items: center; }\n .icf-msg-name {\n font-size: 10px; font-weight: 600; color: #94a3b8;\n padding: 0 4px; letter-spacing: .02em; text-transform: uppercase;\n }\n .icf-msg {\n max-width: 80%; padding: 8px 12px; border-radius: 12px;\n font-size: 13px; line-height: 1.4;\n }\n .icf-msg-wrap.customer .icf-msg { background: ${e}; color: #fff; border-bottom-right-radius: 3px; }\n .icf-msg-wrap.agent .icf-msg { background: #f1f5f9; color: #1e293b; border-bottom-left-radius: 3px; }\n .icf-msg-wrap.system .icf-msg {\n background: #f8fafc; color: #64748b; font-size: 11px;\n border-radius: 20px; padding: 4px 12px;\n }\n .icf-typing { padding: 0 12px 4px; display: none; align-items: center; gap: 4px; }\n .icf-typing.visible { display: flex; }\n .icf-typing-label { font-size: 11px; color: #94a3b8; margin-right: 4px; }\n .icf-dot { width: 6px; height: 6px; background: #94a3b8; border-radius: 50%; animation: icf-bounce .9s infinite; }\n .icf-dot:nth-child(2) { animation-delay: .15s; }\n .icf-dot:nth-child(3) { animation-delay: .3s; }\n @keyframes icf-bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-4px)} }\n .icf-recording-bar {\n display: none; align-items: center; gap: 8px;\n padding: 8px 12px; background: #fef2f2; border-top: 1px solid #fecaca;\n }\n .icf-recording-bar.visible { display: flex; }\n .icf-rec-dot {\n width: 10px; height: 10px; background: #ef4444; border-radius: 50%;\n animation: icf-pulse 1s infinite; flex-shrink: 0;\n }\n @keyframes icf-pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.5;transform:scale(.8)} }\n .icf-rec-label { font-size: 12px; color: #ef4444; font-weight: 600; flex: 1; }\n .icf-rec-stop {\n background: #ef4444; color: #fff; border: none; border-radius: 6px;\n padding: 4px 10px; font-size: 12px; cursor: pointer;\n }\n .icf-voice-preview {\n display: none; flex-direction: column; gap: 8px;\n padding: 10px 12px; border-top: 1px solid #e2e8f0; background: #f8fafc; flex-shrink: 0;\n }\n .icf-voice-preview.visible { display: flex; }\n .icf-voice-preview audio { width: 100%; height: 36px; }\n .icf-voice-actions { display: flex; gap: 8px; }\n .icf-voice-send {\n flex: 1; background: ${e}; color: #fff; border: none; border-radius: 6px;\n padding: 7px; font-size: 12px; font-weight: 600; cursor: pointer;\n }\n .icf-voice-cancel {\n flex: 1; background: none; border: 1px solid #e2e8f0; border-radius: 6px;\n padding: 7px; font-size: 12px; cursor: pointer; color: #64748b;\n }\n .icf-input-row {\n display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;\n border-top: 1px solid #e2e8f0; flex-shrink: 0;\n }\n .icf-input {\n flex: 1; border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px 10px;\n font-size: 13px; resize: none; max-height: 100px; line-height: 1.4; outline: none;\n }\n .icf-input:focus { border-color: ${e}; }\n .icf-voice-btn {\n background: none; border: 1px solid #e2e8f0; border-radius: 8px;\n width: 36px; height: 36px; cursor: pointer; display: flex; align-items: center;\n justify-content: center; color: #64748b; transition: all .2s; flex-shrink: 0;\n }\n .icf-voice-btn:hover { border-color: ${e}; color: ${e}; }\n .icf-send {\n background: ${e}; border: none; color: #fff; border-radius: 8px;\n width: 36px; height: 36px; cursor: pointer; display: flex; align-items: center;\n justify-content: center; flex-shrink: 0;\n }\n .icf-send:disabled { opacity: .4; cursor: default; }\n .icf-prechat { padding: 16px; overflow-y: auto; flex: 1; }\n .icf-prechat h4 { margin: 0 0 4px; font-size: 15px; }\n .icf-prechat p { margin: 0 0 16px; font-size: 12px; color: #64748b; }\n .icf-field { margin-bottom: 10px; }\n .icf-field label { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 3px; }\n .icf-field input, .icf-field select {\n width: 100%; border: 1px solid #e2e8f0; border-radius: 6px;\n padding: 7px 10px; font-size: 13px; outline: none;\n }\n .icf-field input:focus, .icf-field select:focus { border-color: ${e}; }\n .icf-submit {\n width: 100%; background: ${e}; color: #fff; border: none; border-radius: 8px;\n padding: 10px; font-size: 13px; font-weight: 600; cursor: pointer; margin-top: 4px;\n }\n .icf-submit:hover { opacity: .9; }\n .icf-status { font-size: 11px; color: #94a3b8; text-align: center; padding: 4px 12px; flex-shrink: 0; }\n .icf-msg-voice { display: flex; flex-direction: column; gap: 4px; }\n .icf-msg-voice audio { width: 200px; height: 32px; }\n `,document.head.appendChild(i)}createBubble(e,t){const i=document.createElement("button");return i.className="icf-bubble",i.setAttribute("aria-label","Open chat"),i.innerHTML='',i.addEventListener("click",()=>{this.panel.classList.contains("open")?t():e()}),i}createPanel(e,t){const i=document.createElement("div");i.className="icf-panel",i.innerHTML=`\n
\n
\n

${e.companyName}

\n

Typically replies in minutes

\n
\n \n
\n
\n

Start a conversation

\n

Tell us a bit about you and your vehicle

\n
\n
\n
\n
\n
\n \n
\n
\n
\n
\n
\n \n
\n
\n \n `,i.querySelector(".icf-close").addEventListener("click",t.onClose);const n=i.querySelector("#icf-prechat-form");n.addEventListener("submit",e=>{e.preventDefault();const i=new FormData(n);t.onPreChatSubmit(Object.fromEntries(i.entries()))});const s=i.querySelector(".icf-input"),o=i.querySelector(".icf-send");let a=null;s.addEventListener("input",()=>{var e;o.disabled=!s.value.trim(),s.style.height="auto",s.style.height=Math.min(s.scrollHeight,100)+"px",null==(e=t.onTyping)||e.call(t,!0),a&&clearTimeout(a),a=setTimeout(()=>{var e;return null==(e=t.onTyping)?void 0:e.call(t,!1)},3e3)});const r=()=>{var e;o.disabled||(a&&(clearTimeout(a),a=null),null==(e=t.onTyping)||e.call(t,!1),t.onSend(s.value.trim()),s.value="",s.style.height="auto",o.disabled=!0)};s.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),r())}),o.addEventListener("click",r);const c=i.querySelector(".icf-voice-btn"),l=i.querySelector(".icf-recording-bar"),d=i.querySelector(".icf-rec-label"),h=i.querySelector(".icf-rec-stop"),p=i.querySelector(".icf-voice-preview"),u=i.querySelector(".icf-voice-audio"),f=i.querySelector(".icf-voice-send"),m=i.querySelector(".icf-voice-cancel");return t.onVoiceStart&&t.onVoiceStop?(c.addEventListener("click",()=>{t.onVoiceStart()}),h.addEventListener("click",()=>{t.onVoiceStop()}),f.addEventListener("click",()=>{var e;const i=p._recording;i&&(null==(e=t.onVoiceSend)||e.call(t,i.blob,i.duration,i.mimeType),p.classList.remove("visible"),URL.revokeObjectURL(u.src),p._recording=null)}),m.addEventListener("click",()=>{var e;p.classList.remove("visible"),u.src&&URL.revokeObjectURL(u.src),p._recording=null,null==(e=t.onVoiceCancel)||e.call(t)})):c.style.display="none",i._startRecordingUI=()=>{l.classList.add("visible"),c.style.display="none";let e=0;this.recordingTimer=setInterval(()=>{e++;const t=Math.floor(e/60),i=e%60;d.textContent=`Recording… ${t}:${i.toString().padStart(2,"0")}`},1e3)},i._stopRecordingUI=()=>{l.classList.remove("visible"),c.style.display="",d.textContent="Recording… 0:00",this.recordingTimer&&(clearInterval(this.recordingTimer),this.recordingTimer=null)},i}startRecordingUI(){var e,t;null==(t=(e=this.panel)._startRecordingUI)||t.call(e)}stopRecordingUI(){var e,t;null==(t=(e=this.panel)._stopRecordingUI)||t.call(e)}showVoicePreview(e){const t=this.panel.querySelector(".icf-voice-preview"),i=this.panel.querySelector(".icf-voice-audio"),n=URL.createObjectURL(e.blob);i.src=n,t.classList.add("visible"),t._recording=e}stopVoiceRecording(){this.stopRecordingUI()}open(){this.panel.classList.add("open")}close(){this.panel.classList.remove("open")}destroy(){this.recordingTimer&&clearInterval(this.recordingTimer),this.container.remove()}showChat(){this.preChatForm.style.display="none",this.chatView.style.display="flex"}setLoading(e){const t=this.preChatForm.querySelector(".icf-submit");t.disabled=e,t.textContent=e?"Connecting...":"Start Chat →"}appendMessage(e){var t;if("internal_note"===e.message_type)return;const i=document.createElement("div");if(i.className=`icf-msg-wrap ${e.sender_type}`,i.setAttribute("data-msg-id",e.id),"system"!==e.sender_type){const t=document.createElement("div");t.className="icf-msg-name","customer"===e.sender_type?t.textContent=this.customerName:t.textContent="Support Agent",i.appendChild(t)}const n=document.createElement("div");n.className="icf-msg";const s=null==(t=e.attachments)?void 0:t.find(e=>"voice"===e.type);if(s){const e=s.url||"";n.innerHTML=`
🎤 Voice message
`}else n.textContent=e.content??"";i.appendChild(n),this.messagesEl.appendChild(i),this.messagesEl.scrollTop=this.messagesEl.scrollHeight}addSystemMessage(e){const t=document.createElement("div");t.className="icf-msg-wrap system";const i=document.createElement("div");i.className="icf-msg",i.textContent=e,t.appendChild(i),this.messagesEl.appendChild(t),this.messagesEl.scrollTop=this.messagesEl.scrollHeight}setAgentTyping(e){this.typingEl.classList.toggle("visible",e),e&&(this.messagesEl.scrollTop=this.messagesEl.scrollHeight)}setConnectionStatus(e){this.panel.querySelector(".icf-status").textContent="connected"===e?"":"Reconnecting..."}showError(e){this.addSystemMessage(`⚠ ${e}`)}}class i{constructor(e,t,i){this.ws=null,this.reconnectAttempts=0,this.maxReconnectAttempts=10,this.reconnectTimer=null,this.typingTimer=null,this.isIntentionallyClosed=!1,this._heartbeatTimer=null,this.baseUrl=e,this.params=t,this.callbacks=i}connect(){const e=new URL(this.baseUrl);e.searchParams.set("conversation_id",this.params.conversation_id),e.searchParams.set("session_id",this.params.session_id),this.ws=new WebSocket(e.toString()),this.ws.onopen=()=>{this.reconnectAttempts=0,this.callbacks.onOpen(),this._startHeartbeat()},this.ws.onmessage=e=>{try{const t=JSON.parse(e.data);this._handleFrame(t)}catch{}},this.ws.onclose=()=>{this._stopHeartbeat(),this.isIntentionallyClosed||(this.callbacks.onClose(),this._scheduleReconnect())},this.ws.onerror=()=>{}}_handleFrame(e){switch(e.type){case"message":{const t=e.payload;"customer"!==t.sender_type&&this.callbacks.onMessage(t);break}case"typing":{const t=e.payload.is_typing;"agent"===e.payload.sender_type&&(this.callbacks.onTyping(t),t&&(this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(()=>this.callbacks.onTyping(!1),6e3)));break}case"system_event":case"conversation_closed":this.callbacks.onSystemEvent({content:e.payload.content??"Chat closed"})}}_startHeartbeat(){this._heartbeatTimer=setInterval(()=>{this.send("ping",{})},25e3)}_stopHeartbeat(){this._heartbeatTimer&&clearInterval(this._heartbeatTimer)}_scheduleReconnect(){if(this.reconnectAttempts>=this.maxReconnectAttempts)return;const e=Math.min(1e3*2**this.reconnectAttempts,3e4);this.reconnectTimer=setTimeout(()=>{this.reconnectAttempts++,this.connect()},e)}send(e,t){var i;(null==(i=this.ws)?void 0:i.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:e,payload:t}))}sendMessage(e,t){this.send("message",{conversation_id:e,content:t,message_type:"text"})}sendTyping(e,t){this.send("typing",{conversation_id:e,is_typing:t})}disconnect(){var e;this.isIntentionallyClosed=!0,this._stopHeartbeat(),this.reconnectTimer&&clearTimeout(this.reconnectTimer),null==(e=this.ws)||e.close()}}class n{constructor(e){this.key=e}get(){try{const e=localStorage.getItem(this.key);if(!e)return null;const t=JSON.parse(e);return Date.now()-t.createdAt>864e5?(this.clear(),null):t}catch{return null}}save(e){try{localStorage.setItem(this.key,JSON.stringify({...e,createdAt:Date.now()}))}catch{}}clear(){localStorage.removeItem(this.key)}getOrCreateSessionId(){const e=this.get();if(null==e?void 0:e.sessionId)return e.sessionId;const t=crypto.randomUUID();try{const e=localStorage.getItem(this.key),i=e?JSON.parse(e):{};localStorage.setItem(this.key,JSON.stringify({...i,sessionId:t}))}catch{}return t}}class s{constructor(e,t){this.conversationId=null,this.pageEnteredAt=Date.now(),this.heartbeatTimer=null,this.inviteTimer=null,this.lastUrl="",this.onInvitation=null,this.apiBase=e,this.sessionId=t}setConversationId(e){this.conversationId=e}startInvitationPolling(e){this.onInvitation=e,this.inviteTimer=setInterval(()=>this._checkInvitation(),5e3)}async _checkInvitation(){if(!this.conversationId)try{const e=await fetch(`${this.apiBase}/v1/invite?session_id=${encodeURIComponent(this.sessionId)}`).then(e=>e.json()).catch(()=>null);(null==e?void 0:e.invited)&&e.conversation_id&&this.onInvitation&&(this.conversationId=e.conversation_id,this.onInvitation(e.conversation_id))}catch{}}start(){this.trackCurrentPage(),this._startHeartbeat(),this._listenForNavigation(),window.addEventListener("beforeunload",()=>{this._sendBeacon(Math.floor((Date.now()-this.pageEnteredAt)/1e3))})}trackCurrentPage(){const e=window.location.href;if(e===this.lastUrl)return;const t=this.lastUrl?Math.floor((Date.now()-this.pageEnteredAt)/1e3):void 0;this.lastUrl=e,this.pageEnteredAt=Date.now(),this._send({session_id:this.sessionId,url:e,title:document.title,referrer:document.referrer,duration:t,user_agent:navigator.userAgent,conversation_id:this.conversationId})}_startHeartbeat(){this.heartbeatTimer=setInterval(()=>{fetch(`${this.apiBase}/v1/track/heartbeat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session_id:this.sessionId}),keepalive:!0}).catch(()=>{})},3e4)}_listenForNavigation(){const e=history.pushState.bind(history);history.pushState=(...t)=>{e(...t),this.trackCurrentPage()},window.addEventListener("popstate",()=>this.trackCurrentPage())}_send(e){fetch(`${this.apiBase}/v1/track`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:!0}).catch(()=>{})}_sendBeacon(e){var t;const i=JSON.stringify({session_id:this.sessionId,url:window.location.href,duration:e});null==(t=navigator.sendBeacon)||t.call(navigator,`${this.apiBase}/v1/track/heartbeat`,i)}destroy(){this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.inviteTimer&&clearInterval(this.inviteTimer)}}class o{constructor(){this.mediaRecorder=null,this.chunks=[],this.startTime=0,this.stream=null}static isSupported(){var e;return!(!(null==(e=navigator.mediaDevices)?void 0:e.getUserMedia)||!window.MediaRecorder)}static preferredMime(){return["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/mp4"].find(e=>MediaRecorder.isTypeSupported(e))??"audio/webm"}async start(){this.stream=await navigator.mediaDevices.getUserMedia({audio:!0});const e=o.preferredMime();this.mediaRecorder=new MediaRecorder(this.stream,{mimeType:e}),this.chunks=[],this.startTime=Date.now(),this.mediaRecorder.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},this.mediaRecorder.start(100)}stop(){return new Promise((e,t)=>{if(!this.mediaRecorder)return t(new Error("Not recording"));this.mediaRecorder.onstop=()=>{var t;const i=this.mediaRecorder.mimeType||"audio/webm",n=new Blob(this.chunks,{type:i}),s=URL.createObjectURL(n),o=Math.round((Date.now()-this.startTime)/1e3);null==(t=this.stream)||t.getTracks().forEach(e=>e.stop()),e({blob:n,url:s,duration:o,mimeType:i})},this.mediaRecorder.stop()})}cancel(){var e,t;null==(e=this.mediaRecorder)||e.stop(),null==(t=this.stream)||t.getTracks().forEach(e=>e.stop()),this.chunks=[]}}class a{constructor(e){this.ws=null,this.voiceRecorder=null,this.conversationId=null,this.isOpen=!1,this.config={theme:"light",position:"bottom-right",greeting:"Hi! How can we help you today?",companyName:"Instant Car Fix",primaryColor:"#2563EB",...e},this.session=new n("icf_chat_session");const i=this.session.getOrCreateSessionId();this.tracker=new s(this.config.apiBase,i),this.tracker.start(),this.tracker.startInvitationPolling(e=>this._handleInvitation(e));const a=o.isSupported();this.ui=function(e,i){return new t(e,i)}(this.config,{onOpen:()=>this.open(),onClose:()=>this.close(),onSend:e=>this.sendMessage(e),onPreChatSubmit:e=>this.startConversation(e),onTyping:e=>this.sendTyping(e),onVoiceStart:a?()=>this.startVoice():void 0,onVoiceStop:a?()=>this.stopVoice():void 0,onVoiceSend:a?(e,t,i)=>this.sendVoice(e,t,i):void 0,onVoiceCancel:a?()=>{var e;null==(e=this.voiceRecorder)||e.cancel(),this.voiceRecorder=null,this.ui.stopRecordingUI()}:void 0})}async startConversation(e){const t=this.session.get();if(null==t?void 0:t.conversationId)return this.conversationId=t.conversationId,t.customerName&&this.ui.setCustomerName(t.customerName),await this.loadHistory(),this.connectWebSocket(),void this.ui.showChat();this.ui.setLoading(!0);try{const t=await fetch(`${this.config.apiBase}/v1/conversations`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({customer_name:e.name,customer_email:e.email,customer_phone:e.phone,channel:"web",metadata:{service_type:e.service_type,vehicle:{make:e.vehicle_make,model:e.vehicle_model,year:e.vehicle_year},zip_code:e.zip_code}})});if(!t.ok)throw new Error("Failed to start conversation");const{conversation_id:i}=await t.json();this.conversationId=i;const n=this.session.getOrCreateSessionId();this.session.save({conversationId:i,sessionId:n,customerName:e.name}),this.tracker.setConversationId(i),this.ui.setCustomerName(e.name),this.connectWebSocket(),this.ui.showChat(),this.ui.addSystemMessage(this.config.greeting)}catch(i){this.ui.showError("Unable to connect. Please try again.")}finally{this.ui.setLoading(!1)}}async loadHistory(){if(this.conversationId)try{const e=await fetch(`${this.config.apiBase}/v1/conversations/${this.conversationId}/messages`);if(!e.ok)return;const{messages:t}=await e.json();for(const i of t)this.ui.appendMessage(i)}catch{}}connectWebSocket(){if(!this.conversationId)return;const e=this.session.getOrCreateSessionId();this.ws=new i(`${this.config.wsBase}/ws/customer`,{conversation_id:this.conversationId,session_id:e},{onMessage:e=>this.ui.appendMessage(e),onTyping:e=>this.ui.setAgentTyping(e),onClose:()=>this.ui.setConnectionStatus("disconnected"),onOpen:()=>this.ui.setConnectionStatus("connected"),onSystemEvent:e=>this.ui.addSystemMessage(e.content)}),this.ws.connect()}sendMessage(e){this.ws&&this.conversationId&&(this.ws.sendMessage(this.conversationId,e),this.ui.appendMessage({id:crypto.randomUUID(),conversation_id:this.conversationId,sender_id:null,sender_type:"customer",content:e,message_type:"text",attachments:[],created_at:(new Date).toISOString()}))}_handleInvitation(e){if(this.conversationId)return;const t=this.session.getOrCreateSessionId();this.conversationId=e,this.session.save({conversationId:e,sessionId:t,customerName:"Visitor"}),this.tracker.setConversationId(e),this.open(),this.ui.showChat(),this.ui.addSystemMessage("A support agent wants to chat with you!"),this.connectWebSocket()}sendTyping(e){this.ws&&this.conversationId&&this.ws.sendTyping(this.conversationId,e)}async startVoice(){try{this.voiceRecorder=new o,await this.voiceRecorder.start(),this.ui.startRecordingUI()}catch{this.ui.showError("Microphone access denied."),this.ui.stopRecordingUI(),this.voiceRecorder=null}}async stopVoice(){if(!this.voiceRecorder)return;this.ui.stopRecordingUI();const e=await this.voiceRecorder.stop();this.voiceRecorder=null,this.ui.showVoicePreview(e)}async sendVoice(e,t,i){if(this.conversationId)try{const n={blob:e,duration:t,mimeType:i};await async function(e,t,i){var n;const s=new FormData,o=(null==(n=i.mimeType.split("/")[1])?void 0:n.split(";")[0])??"webm";s.append("file",i.blob,`voice.${o}`),s.append("duration",String(i.duration));const a=await fetch(`${e}/v1/conversations/${t}/voice`,{method:"POST",body:s});if(!a.ok)throw new Error("Voice upload failed");const r=await a.json();return{url:`${e}${r.url}`,messageId:r.message_id}}(this.config.apiBase,this.conversationId,n),this.ui.addSystemMessage("Voice message sent")}catch{this.ui.showError("Failed to send voice message.")}}open(){this.isOpen=!0,this.ui.open()}close(){this.isOpen=!1,this.ui.close()}destroy(){var e;null==(e=this.ws)||e.disconnect(),this.tracker.destroy(),this.ui.destroy()}}function r(){const e=document.currentScript;if(!e)return;const t=e.dataset.key??"",i=e.dataset.apiBase??"https://api.instantcarfix.com",n=e.dataset.wsBase??"wss://api.instantcarfix.com",s=new a({siteKey:t,apiBase:i,wsBase:n,department:e.dataset.department,theme:e.dataset.theme??"light",position:e.dataset.position??"bottom-right",primaryColor:e.dataset.color??"#2563EB",companyName:e.dataset.company??"Instant Car Fix",greeting:e.dataset.greeting??"Hi! How can we help you today?"});window.ICFChat=s}return"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r(),e.ICFChatWidget=a,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});