@tbisoftware/phone 2.0.8 → 2.0.9

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),k=require("../index-BTMeEufy.cjs"),q={key:0,class:"flex gap-2 items-center"},W=["placeholder"],G=["disabled","title"],Q={key:0,class:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"},X={key:1,class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},Y={key:1,class:"flex flex-col items-center gap-3 py-6"},Z={class:"text-center"},ee={class:"text-base font-semibold"},te={class:"text-sm text-gray-500"},ne={key:2,class:"flex flex-col items-center gap-4 py-6"},oe={class:"text-center space-y-1"},le={class:"text-xl font-bold"},ae={class:"text-2xl font-mono text-green-600 tabular-nums"},se={key:3,class:"flex flex-col items-center gap-3 py-6"},re={key:0,d:"M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"},ce={key:1,d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"},ie={class:"text-center"},de={class:"text-base font-semibold"},ue={key:0,class:"fixed inset-0 z-50 flex"},ve={class:"fixed right-0 top-0 h-full w-full max-w-md bg-white shadow-xl",style:{"background-color":"white"}},me={class:"flex flex-col h-full"},fe={class:"flex items-center justify-between p-4 border-b"},ge={class:"text-lg font-semibold"},pe={class:"text-sm text-gray-500"},he={class:"flex-1 overflow-y-auto p-4"},ye={key:0,class:"text-center py-12 text-gray-500"},Ce={key:1,class:"space-y-2"},Ee={key:2,d:"M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"},xe={class:"flex-1 min-w-0"},we={class:"font-medium text-sm truncate"},Se={class:"flex items-center gap-2 text-xs text-gray-500"},ke={class:"font-mono tabular-nums"},be=["onClick"],F=e.defineComponent({__name:"Phone",props:{config:{},className:{default:""},labels:{default:()=>({})},onCallStart:{},onCallEnd:{},onStatusChange:{}},emits:["callStart","callEnd","statusChange"],setup(v,{emit:B}){const g=v,p=B;let i=null,m=null;function y(o){return`${o.websocketUrl}|${o.sipUri}|${o.authorizationUser}`}function d(o){const t=y(o);if(i&&m===t)return i;if(i&&m!==t){try{i.ua.stop()}catch{}i=null}m=t;const x={sockets:[new k.JsSIP.WebSocketInterface(o.websocketUrl)],uri:o.sipUri,password:o.password,registrar_server:o.registrarServer,display_name:o.displayName,authorization_user:o.authorizationUser,connection_recovery_min_interval:2,connection_recovery_max_interval:30},N=new k.JsSIP.UA(x),j=document.createElement("audio");j.autoplay=!0;const z={ua:N,audio:j,isStarted:!1,listeners:new Set};return N.on("connecting",()=>{z.listeners.forEach(w=>w.onConnecting?.())}),N.on("connected",()=>{z.listeners.forEach(w=>w.onConnected?.())}),N.on("disconnected",()=>{z.listeners.forEach(w=>w.onDisconnected?.())}),N.on("registered",()=>{z.listeners.forEach(w=>w.onRegistered?.())}),N.on("unregistered",()=>{z.listeners.forEach(w=>w.onUnregistered?.())}),N.on("registrationFailed",w=>{z.listeners.forEach(M=>M.onRegistrationFailed?.(w?.cause))}),N.on("newRTCSession",w=>{const M=w.session;M.direction==="outgoing"&&(z.listeners.forEach(U=>U.onNewSession?.(M)),M.connection&&(M.connection.addEventListener("addstream",U=>{if(!U.streams?.length)return;const I=document.createElement("audio");I.srcObject=U.streams[0],I.play()}),M.connection.addEventListener("track",U=>{const I=document.createElement("audio");I.srcObject=U.streams[0],I.play()})))}),i=z,z}const l=e.ref("disconnected"),r=e.ref(""),c=e.ref([]),C=e.ref(0),u=e.ref(!1),h=e.ref("connecting"),E=e.ref(!1);let a=null,S=null,V=null,b=null,_=null;const n=e.computed(()=>({...k.defaultLabels,...g.labels})),H=e.computed(()=>{switch(l.value){case"progress":return{text:`${n.value.calling}...`,color:"text-yellow-500",icon:"ring"};case"confirmed":return{text:`${n.value.inCall} - ${k.formatDuration(C.value)}`,color:"text-green-500",icon:"inTalk"};case"failed":return{text:n.value.callEnded,color:"text-red-500",icon:"missed"};case"ended":return{text:n.value.callEnded,color:"text-gray-500",icon:"hangup"};default:return{text:n.value.inactive,color:"text-gray-300",icon:"phone"}}});function D(o,t,s){const x={id:Date.now().toString(),number:o,timestamp:Date.now(),duration:t,status:s};c.value=[x,...c.value].slice(0,50),localStorage.setItem("tbi-phone-call-history",JSON.stringify(c.value))}function f(){S&&(S.terminate(),S=null)}function R(o){if(!o.trim()||!a)return;if(!u.value){console.warn("Phone is not ready yet. Please wait for registration.");return}r.value=o,g.onCallStart?.(o),p("callStart",o);const s={eventHandlers:{progress:()=>{l.value="progress",g.onStatusChange?.("progress"),p("statusChange","progress")},failed:x=>{console.error("Call failed:",x?.cause),l.value="failed",g.onStatusChange?.("failed"),p("statusChange","failed"),D(o,0,"failed"),g.onCallEnd?.(o,0,"failed"),p("callEnd",o,0,"failed"),S=null,setTimeout(()=>{l.value="disconnected",g.onStatusChange?.("disconnected"),p("statusChange","disconnected")},3e3)},ended:()=>{l.value="ended",g.onStatusChange?.("ended"),p("statusChange","ended");const x=V?Math.floor((Date.now()-V)/1e3):0;D(o,x,"completed"),g.onCallEnd?.(o,x,"completed"),p("callEnd",o,x,"completed"),S=null,b&&(clearInterval(b),b=null),setTimeout(()=>{l.value="disconnected",g.onStatusChange?.("disconnected"),p("statusChange","disconnected"),V=null,C.value=0},2e3)},confirmed:()=>{l.value="confirmed",g.onStatusChange?.("confirmed"),p("statusChange","confirmed"),V=Date.now(),b=setInterval(()=>{V&&(C.value=Math.floor((Date.now()-V)/1e3))},1e3)}},mediaConstraints:{audio:!0,video:!1}};l.value="progress",g.onStatusChange?.("progress"),p("statusChange","progress");try{S=a.ua.call(o,s)}catch(x){console.error("Failed to start call:",x),l.value="failed",g.onStatusChange?.("failed"),p("statusChange","failed"),D(o,0,"failed"),setTimeout(()=>{l.value="disconnected",g.onStatusChange?.("disconnected"),p("statusChange","disconnected")},3e3)}}function T(o){o.key==="Enter"&&R(r.value)}function O(o){r.value=o.number,E.value=!1,R(o.number)}function A(o){switch(o){case"completed":return"bg-green-100";case"failed":return"bg-red-100";case"missed":return"bg-yellow-100"}}function K(o){switch(o){case"completed":return"text-green-600";case"failed":return"text-red-600";case"missed":return"text-yellow-600"}}function J(o){return new Date(o).toLocaleString("es-ES",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}return e.onMounted(()=>{a=d(g.config),a.ua.isRegistered()?(u.value=!0,h.value="connected"):a.ua.isConnected()&&(h.value="connected"),_={onConnecting:()=>{h.value="connecting"},onConnected:()=>{h.value="connected"},onDisconnected:()=>{h.value="disconnected",u.value=!1},onRegistered:()=>{u.value=!0,h.value="connected"},onUnregistered:()=>{u.value=!1},onRegistrationFailed:s=>{console.error("Registration failed:",s),u.value=!1,h.value="failed"},onNewSession:s=>{S=s}},a.listeners.add(_),a.isStarted||(a.ua.start(),a.isStarted=!0);const o=localStorage.getItem("tbi-phone-call-history");if(o)try{c.value=JSON.parse(o)}catch(s){console.error("Error loading call history",s)}const t=s=>{const N=s.detail.number;l.value==="disconnected"&&R(N)};window.addEventListener("StartCallEvent",t)}),e.onUnmounted(()=>{b&&clearInterval(b),a&&_&&a.listeners.delete(_)}),(o,t)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(k.cn)("tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2",v.className))},[l.value==="disconnected"?(e.openBlock(),e.createElementBlock("div",q,[e.createElementVNode("button",{onClick:t[0]||(t[0]=s=>E.value=!0),class:"h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",type:"button"},[...t[5]||(t[5]=[e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.954 8.954 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"})],-1)])]),e.withDirectives(e.createElementVNode("input",{type:"text","onUpdate:modelValue":t[1]||(t[1]=s=>r.value=s),onKeydown:T,placeholder:n.value.placeholder,class:"flex-1 w-full h-8 px-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"},null,40,W),[[e.vModelText,r.value]]),e.createElementVNode("button",{onClick:t[2]||(t[2]=s=>R(r.value)),disabled:r.value.length<9||!u.value,class:"h-8 w-8 flex items-center justify-center rounded-xl bg-green-500 hover:bg-green-600 disabled:bg-gray-300 disabled:cursor-not-allowed text-white transition-colors",type:"button",title:u.value?"Call":"Connecting..."},[h.value==="connecting"?(e.openBlock(),e.createElementBlock("div",Q)):(e.openBlock(),e.createElementBlock("svg",X,[...t[6]||(t[6]=[e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},null,-1)])]))],8,G)])):e.createCommentVNode("",!0),l.value==="progress"?(e.openBlock(),e.createElementBlock("div",Y,[t[8]||(t[8]=e.createElementVNode("div",{class:"relative"},[e.createElementVNode("svg",{class:"w-12 h-12 text-yellow-500 animate-pulse",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M15.05 5A7 7 0 0 1 19 8.95M15.05 1A11 11 0 0 1 23 8.94m-1 7.98v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})]),e.createElementVNode("div",{class:"absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping"})],-1)),e.createElementVNode("div",Z,[e.createElementVNode("p",ee,e.toDisplayString(n.value.calling)+" "+e.toDisplayString(r.value),1),e.createElementVNode("p",te,e.toDisplayString(n.value.waitingResponse),1)]),e.createElementVNode("button",{onClick:f,class:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button"},[t[7]||(t[7]=e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})],-1)),e.createTextVNode(" "+e.toDisplayString(n.value.cancel),1)])])):e.createCommentVNode("",!0),l.value==="confirmed"?(e.openBlock(),e.createElementBlock("div",ne,[t[10]||(t[10]=e.createElementVNode("div",{class:"relative"},[e.createElementVNode("svg",{class:"w-12 h-12 text-green-500",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M20 15.5c-1.25 0-2.45-.2-3.57-.57-.35-.12-.74-.03-1.02.24l-2.2 2.2c-2.83-1.45-5.15-3.76-6.59-6.59l2.2-2.21c.28-.26.36-.65.25-1C8.7 6.45 8.5 5.25 8.5 4c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1 0 9.39 7.61 17 17 17 .55 0 1-.45 1-1v-3.5c0-.55-.45-1-1-1zM19 12h2c0-4.97-4.03-9-9-9v2c3.87 0 7 3.13 7 7zm-4 0h2c0-2.76-2.24-5-5-5v2c1.66 0 3 1.34 3 3z"})]),e.createElementVNode("div",{class:"absolute inset-0 rounded-full bg-green-500/20 animate-pulse"})],-1)),e.createElementVNode("div",oe,[e.createElementVNode("p",le,e.toDisplayString(r.value),1),e.createElementVNode("p",ae,e.toDisplayString(e.unref(k.formatDuration)(C.value)),1)]),e.createElementVNode("button",{onClick:f,class:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button"},[t[9]||(t[9]=e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})],-1)),e.createTextVNode(" "+e.toDisplayString(n.value.hangUp),1)])])):e.createCommentVNode("",!0),l.value==="failed"||l.value==="ended"?(e.openBlock(),e.createElementBlock("div",se,[(e.openBlock(),e.createElementBlock("svg",{class:e.normalizeClass(e.unref(k.cn)("w-12 h-12",l.value==="failed"?"text-red-500":"text-gray-500")),viewBox:"0 0 24 24",fill:"currentColor"},[l.value==="failed"?(e.openBlock(),e.createElementBlock("path",re)):(e.openBlock(),e.createElementBlock("path",ce))],2)),e.createElementVNode("div",ie,[e.createElementVNode("p",de,e.toDisplayString(H.value.text),1)])])):e.createCommentVNode("",!0),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[E.value?(e.openBlock(),e.createElementBlock("div",ue,[e.createElementVNode("div",{class:"fixed inset-0 bg-black/50",onClick:t[3]||(t[3]=s=>E.value=!1)}),e.createElementVNode("div",ve,[e.createElementVNode("div",me,[e.createElementVNode("div",fe,[e.createElementVNode("div",null,[e.createElementVNode("h2",ge,e.toDisplayString(n.value.callHistory),1),e.createElementVNode("p",pe,e.toDisplayString(c.value.length===0?n.value.noCallsRegistered:`${c.value.length} ${n.value.callsRegistered}`),1)]),e.createElementVNode("button",{onClick:t[4]||(t[4]=s=>E.value=!1),class:"h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",type:"button"},[...t[11]||(t[11]=[e.createElementVNode("svg",{class:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})],-1)])])]),e.createElementVNode("div",he,[c.value.length===0?(e.openBlock(),e.createElementBlock("div",ye,[t[12]||(t[12]=e.createElementVNode("svg",{class:"w-12 h-12 mx-auto mb-2 opacity-50",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})],-1)),e.createElementVNode("p",null,e.toDisplayString(n.value.noCalls),1)])):(e.openBlock(),e.createElementBlock("div",Ce,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(c.value,(s,x)=>(e.openBlock(),e.createElementBlock("div",{key:s.id,class:"flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",style:e.normalizeStyle({animationDelay:`${x*30}ms`})},[e.createElementVNode("div",{class:e.normalizeClass(e.unref(k.cn)("w-9 h-9 rounded-full flex items-center justify-center shrink-0",A(s.status)))},[(e.openBlock(),e.createElementBlock("svg",{class:e.normalizeClass(e.unref(k.cn)("w-4 h-4",K(s.status))),viewBox:"0 0 24 24",fill:"currentColor"},[s.status==="completed"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t[13]||(t[13]=e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},null,-1)),t[14]||(t[14]=e.createElementVNode("path",{d:"M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z"},null,-1))],64)):s.status==="failed"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[t[15]||(t[15]=e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},null,-1)),t[16]||(t[16]=e.createElementVNode("path",{d:"M19 6.41L17.59 5 15 7.59 12.41 5 11 6.41 13.59 9 11 11.59 12.41 13 15 10.41 17.59 13 19 11.59 16.41 9z"},null,-1))],64)):(e.openBlock(),e.createElementBlock("path",Ee))],2))],2),e.createElementVNode("div",xe,[e.createElementVNode("p",we,e.toDisplayString(s.number),1),e.createElementVNode("div",Se,[e.createElementVNode("span",null,e.toDisplayString(J(s.timestamp)),1),s.duration>0?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t[17]||(t[17]=e.createElementVNode("span",null,"•",-1)),e.createElementVNode("span",ke,e.toDisplayString(e.unref(k.formatDuration)(s.duration)),1)],64)):e.createCommentVNode("",!0)])]),e.createElementVNode("button",{onClick:N=>O(s),class:"h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",type:"button"},[...t[18]||(t[18]=[e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"})],-1)])],8,be)],4))),128))]))])])])])):e.createCommentVNode("",!0)]))],2))}}),$=Symbol("Phone");let P=null,L=null;function Ne(v){return`${v.websocketUrl}|${v.sipUri}|${v.authorizationUser}`}function Ve(v){const B=Ne(v);if(P&&L===B)return P;if(P&&L!==B){try{P.ua.stop()}catch{}P=null}L=B;const p={sockets:[new k.JsSIP.WebSocketInterface(v.websocketUrl)],uri:v.sipUri,password:v.password,registrar_server:v.registrarServer,display_name:v.displayName,authorization_user:v.authorizationUser,connection_recovery_min_interval:2,connection_recovery_max_interval:30},i=new k.JsSIP.UA(p),m=document.createElement("audio");m.autoplay=!0;const y={ua:i,audio:m,isStarted:!1,listeners:new Set};return i.on("connecting",()=>{y.listeners.forEach(d=>d.onConnecting?.())}),i.on("connected",()=>{y.listeners.forEach(d=>d.onConnected?.())}),i.on("disconnected",()=>{y.listeners.forEach(d=>d.onDisconnected?.())}),i.on("registered",()=>{y.listeners.forEach(d=>d.onRegistered?.())}),i.on("unregistered",()=>{y.listeners.forEach(d=>d.onUnregistered?.())}),i.on("registrationFailed",d=>{y.listeners.forEach(l=>l.onRegistrationFailed?.(d?.cause))}),i.on("newRTCSession",d=>{const l=d.session;l.direction==="outgoing"&&(y.listeners.forEach(r=>r.onNewSession?.(l)),l.connection&&(l.connection.addEventListener("addstream",r=>{if(!r.streams?.length)return;const c=document.createElement("audio");c.srcObject=r.streams[0],c.play()}),l.connection.addEventListener("track",r=>{const c=document.createElement("audio");c.srcObject=r.streams[0],c.play()})))}),P=y,y}function Be(v){const{config:B,onCallStart:g,onCallEnd:p,onStatusChange:i}=v,m=e.ref("disconnected"),y=e.ref(""),d=e.ref([]),l=e.ref(0),r=e.ref(!1),c=e.ref("connecting");let C=null,u=null,h=null,E=null;const a=n=>{y.value=n},S=(n,H,D)=>{const f={id:Date.now().toString(),number:n,timestamp:Date.now(),duration:H,status:D};d.value=[f,...d.value].slice(0,50),localStorage.setItem("tbi-phone-call-history",JSON.stringify(d.value))},V=()=>{u&&(u.terminate(),u=null)},b=n=>{if(!n.trim()||!C)return;if(!r.value){console.warn("Phone is not ready yet. Please wait for registration.");return}y.value=n,g?.(n);const D={eventHandlers:{progress:()=>{m.value="progress",i?.("progress")},failed:f=>{console.error("Call failed:",f?.cause),m.value="failed",i?.("failed"),S(n,0,"failed"),p?.(n,0,"failed"),u=null,setTimeout(()=>{m.value="disconnected",i?.("disconnected")},3e3)},ended:()=>{m.value="ended",i?.("ended");const f=h?Math.floor((Date.now()-h)/1e3):0;S(n,f,"completed"),p?.(n,f,"completed"),u=null,E&&(clearInterval(E),E=null),setTimeout(()=>{m.value="disconnected",i?.("disconnected"),h=null,l.value=0},2e3)},confirmed:()=>{m.value="confirmed",i?.("confirmed"),h=Date.now(),E=setInterval(()=>{h&&(l.value=Math.floor((Date.now()-h)/1e3))},1e3)}},mediaConstraints:{audio:!0,video:!1}};m.value="progress",i?.("progress");try{u=C.ua.call(n,D)}catch(f){console.error("Failed to start call:",f),m.value="failed",i?.("failed"),S(n,0,"failed"),setTimeout(()=>{m.value="disconnected",i?.("disconnected")},3e3)}};e.onMounted(()=>{C=Ve(B),C.ua.isRegistered()?(r.value=!0,c.value="connected"):C.ua.isConnected()&&(c.value="connected");const n={onConnecting:()=>{c.value="connecting"},onConnected:()=>{c.value="connected"},onDisconnected:()=>{c.value="disconnected",r.value=!1},onRegistered:()=>{r.value=!0,c.value="connected"},onUnregistered:()=>{r.value=!1},onRegistrationFailed:f=>{console.error("Registration failed:",f),r.value=!1,c.value="failed"},onNewSession:f=>{u=f}};C.listeners.add(n),C.isStarted||(C.ua.start(),C.isStarted=!0);const H=localStorage.getItem("tbi-phone-call-history");if(H)try{d.value=JSON.parse(H)}catch(f){console.error("Error loading call history",f)}const D=f=>{const T=f.detail.number;m.value==="disconnected"&&b(T)};window.addEventListener("StartCallEvent",D)}),e.onUnmounted(()=>{E&&clearInterval(E)});const _={status:e.readonly(m),callNumber:y,setCallNumber:a,callHistory:e.readonly(d),currentCallDuration:e.readonly(l),startCall:b,endCall:V,isReady:e.readonly(r),connectionStatus:e.readonly(c)};return e.provide($,_),_}function _e(){const v=e.inject($);if(!v)throw new Error("usePhone must be used within a component that has called usePhoneProvider");return v}function De(v,B={}){const{onCallStart:g,onCallEnd:p,onStatusChange:i,onConnectionChange:m,persistHistory:y=!0,historyKey:d="tbi-phone-call-history"}=B,l=e.ref("disconnected"),r=e.ref(""),c=e.ref([]),C=e.ref(0),u=e.ref(!1),h=e.ref("connecting"),E=e.ref(null);let a=null;e.onMounted(()=>{a=new k.PhoneManager(v,{onStatusChange:n=>{l.value=n,i?.(n)},onConnectionChange:n=>{h.value=n,a&&(u.value=a.state.isReady),m?.(n)},onCallStart:g,onCallEnd:p,onDurationUpdate:n=>{C.value=n},onHistoryUpdate:n=>{c.value=n},onRegistered:()=>{u.value=!0},onUnregistered:()=>{u.value=!1}},{persistHistory:y,historyKey:d}),a.initialize(),l.value=a.state.status,r.value=a.state.callNumber,c.value=a.state.callHistory,u.value=a.state.isReady,h.value=a.state.connectionStatus,E.value=a.ua}),e.onUnmounted(()=>{a&&(a.destroy(),a=null)});const S=n=>{r.value=n,a?.setCallNumber(n)},V=n=>{a?.startCall(n)},b=()=>{a?.endCall()},_=()=>{a?.clearHistory(),c.value=[]};return{status:e.readonly(l),callNumber:r,setCallNumber:S,callHistory:e.readonly(c),clearCallHistory:_,currentCallDuration:e.readonly(C),startCall:V,endCall:b,isReady:e.readonly(u),connectionStatus:e.readonly(h),ua:E}}exports.Phone=F;exports.PhoneKey=$;exports.default=F;exports.usePhone=_e;exports.usePhoneManager=De;exports.usePhoneProvider=Be;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),B=require("../index-1EBiLrV_.cjs"),Z={key:0,class:"flex gap-2 items-center"},ee=["placeholder"],te=["disabled","title"],ne={key:0,class:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"},oe={key:1,class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},le={key:1,class:"flex flex-col items-center gap-3 py-6"},ae={class:"text-center"},se={class:"text-base font-semibold"},re={class:"text-sm text-gray-500"},ce={key:2,class:"flex flex-col items-center gap-3 py-6"},ie={class:"text-center"},de={class:"text-sm text-gray-500"},ue={class:"text-base font-semibold"},me={key:0,class:"text-sm text-gray-600"},ve={class:"flex gap-3"},fe={key:3,class:"flex flex-col items-center gap-4 py-6"},ge={class:"text-center space-y-1"},pe={class:"text-xl font-bold"},he={class:"text-2xl font-mono text-green-600 tabular-nums"},ye={key:4,class:"flex flex-col items-center gap-3 py-6"},Ce={key:0,d:"M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"},Ee={key:1,d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"},xe={class:"text-center"},we={class:"text-base font-semibold"},be={key:0,class:"fixed inset-0 z-50 flex"},Se={class:"fixed right-0 top-0 h-full w-full max-w-md bg-white shadow-xl",style:{"background-color":"white"}},ke={class:"flex flex-col h-full"},Ne={class:"flex items-center justify-between p-4 border-b"},Ve={class:"text-lg font-semibold"},_e={class:"text-sm text-gray-500"},Be={class:"flex-1 overflow-y-auto p-4"},De={key:0,class:"text-center py-12 text-gray-500"},ze={key:1,class:"space-y-2"},Me={key:2,d:"M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"},Ie={class:"flex-1 min-w-0"},He={class:"font-medium text-sm truncate"},Ue={class:"flex items-center gap-2 text-xs text-gray-500"},Te={class:"font-mono tabular-nums"},Pe=["onClick"],G=e.defineComponent({__name:"Phone",props:{config:{},className:{default:""},labels:{default:()=>({})},onCallStart:{},onCallEnd:{},onStatusChange:{},onIncomingCall:{}},emits:["callStart","callEnd","statusChange","incomingCall"],setup(E,{emit:T}){const i=E,d=T;let s=null,I=null;function r(l){return`${l.websocketUrl}|${l.sipUri}|${l.authorizationUser}`}function h(l){const t=r(l);if(s&&I===t)return s;if(s&&I!==t){try{s.ua.stop()}catch{}s=null}I=t;const g={sockets:[new B.JsSIP.WebSocketInterface(l.websocketUrl)],uri:l.sipUri,password:l.password,registrar_server:l.registrarServer,display_name:l.displayName,authorization_user:l.authorizationUser,connection_recovery_min_interval:2,connection_recovery_max_interval:30},N=new B.JsSIP.UA(g),L=document.createElement("audio");L.autoplay=!0;const U={ua:N,audio:L,isStarted:!1,listeners:new Set};return N.on("connecting",()=>{U.listeners.forEach(_=>_.onConnecting?.())}),N.on("connected",()=>{U.listeners.forEach(_=>_.onConnected?.())}),N.on("disconnected",()=>{U.listeners.forEach(_=>_.onDisconnected?.())}),N.on("registered",()=>{U.listeners.forEach(_=>_.onRegistered?.())}),N.on("unregistered",()=>{U.listeners.forEach(_=>_.onUnregistered?.())}),N.on("registrationFailed",_=>{U.listeners.forEach(z=>z.onRegistrationFailed?.(_?.cause))}),N.on("newRTCSession",_=>{const z=_.session;if(z.direction==="incoming"){const R=z.remote_identity,j=R?.uri?.user||"Unknown",Y=R?.display_name||void 0;U.listeners.forEach(F=>F.onIncomingSession?.(z,j,Y)),z.on("peerconnection",()=>{z.connection.addEventListener("addstream",F=>{if(!F.streams?.length)return;const K=document.createElement("audio");K.srcObject=F.streams[0],K.play()}),z.connection.addEventListener("track",F=>{const K=document.createElement("audio");K.srcObject=F.streams[0],K.play()})});return}U.listeners.forEach(R=>R.onNewSession?.(z)),z.connection&&(z.connection.addEventListener("addstream",R=>{if(!R.streams?.length)return;const j=document.createElement("audio");j.srcObject=R.streams[0],j.play()}),z.connection.addEventListener("track",R=>{const j=document.createElement("audio");j.srcObject=R.streams[0],j.play()}))}),s=U,U}const n=e.ref("disconnected"),u=e.ref(""),v=e.ref([]),w=e.ref(0),c=e.ref(!1),f=e.ref("connecting"),b=e.ref(!1),o=e.ref(null);let p=null,k=null,C=null,V=null,x=null;const S=e.computed(()=>({...B.defaultLabels,...i.labels})),J=e.computed(()=>{switch(n.value){case"ringing":return{text:S.value.incomingCall,color:"text-blue-500",icon:"ring"};case"progress":return{text:`${S.value.calling}...`,color:"text-yellow-500",icon:"ring"};case"confirmed":return{text:`${S.value.inCall} - ${B.formatDuration(w.value)}`,color:"text-green-500",icon:"inTalk"};case"failed":return{text:S.value.callEnded,color:"text-red-500",icon:"missed"};case"ended":return{text:S.value.callEnded,color:"text-gray-500",icon:"hangup"};default:return{text:S.value.inactive,color:"text-gray-300",icon:"phone"}}});function H(l,t,a){const g={id:Date.now().toString(),number:l,timestamp:Date.now(),duration:t,status:a};v.value=[g,...v.value].slice(0,50),localStorage.setItem("tbi-phone-call-history",JSON.stringify(v.value))}function y(){k&&(k.terminate(),k=null),o.value=null}function D(){if(!o.value)return;const{session:l,callerNumber:t}=o.value,a={mediaConstraints:{audio:!0,video:!1}};try{l.answer(a),k=l,i.onCallStart?.(t),d("callStart",t)}catch(g){console.error("Failed to answer call:",g),n.value="failed",i.onStatusChange?.("failed"),d("statusChange","failed"),H(t,0,"missed"),o.value=null,setTimeout(()=>{n.value="disconnected",i.onStatusChange?.("disconnected"),d("statusChange","disconnected")},3e3)}}function M(){if(!o.value)return;const{session:l,callerNumber:t}=o.value;try{l.terminate({status_code:603,reason_phrase:"Decline"})}catch(a){console.error("Failed to reject call:",a)}H(t,0,"missed"),o.value=null,n.value="disconnected",i.onStatusChange?.("disconnected"),d("statusChange","disconnected")}function m(l){if(!l.trim()||!p)return;if(!c.value){console.warn("Phone is not ready yet. Please wait for registration.");return}u.value=l,i.onCallStart?.(l),d("callStart",l);const a={eventHandlers:{progress:()=>{n.value="progress",i.onStatusChange?.("progress"),d("statusChange","progress")},failed:g=>{console.error("Call failed:",g?.cause),n.value="failed",i.onStatusChange?.("failed"),d("statusChange","failed"),H(l,0,"failed"),i.onCallEnd?.(l,0,"failed"),d("callEnd",l,0,"failed"),k=null,setTimeout(()=>{n.value="disconnected",i.onStatusChange?.("disconnected"),d("statusChange","disconnected")},3e3)},ended:()=>{n.value="ended",i.onStatusChange?.("ended"),d("statusChange","ended");const g=C?Math.floor((Date.now()-C)/1e3):0;H(l,g,"completed"),i.onCallEnd?.(l,g,"completed"),d("callEnd",l,g,"completed"),k=null,V&&(clearInterval(V),V=null),setTimeout(()=>{n.value="disconnected",i.onStatusChange?.("disconnected"),d("statusChange","disconnected"),C=null,w.value=0},2e3)},confirmed:()=>{n.value="confirmed",i.onStatusChange?.("confirmed"),d("statusChange","confirmed"),C=Date.now(),V=setInterval(()=>{C&&(w.value=Math.floor((Date.now()-C)/1e3))},1e3)}},mediaConstraints:{audio:!0,video:!1}};n.value="progress",i.onStatusChange?.("progress"),d("statusChange","progress");try{k=p.ua.call(l,a)}catch(g){console.error("Failed to start call:",g),n.value="failed",i.onStatusChange?.("failed"),d("statusChange","failed"),H(l,0,"failed"),setTimeout(()=>{n.value="disconnected",i.onStatusChange?.("disconnected"),d("statusChange","disconnected")},3e3)}}function P(l){l.key==="Enter"&&m(u.value)}function O(l){u.value=l.number,b.value=!1,m(l.number)}function $(l){switch(l){case"completed":return"bg-green-100";case"failed":return"bg-red-100";case"missed":return"bg-yellow-100"}}function Q(l){switch(l){case"completed":return"text-green-600";case"failed":return"text-red-600";case"missed":return"text-yellow-600"}}function X(l){return new Date(l).toLocaleString("es-ES",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}return e.onMounted(()=>{p=h(i.config),p.ua.isRegistered()?(c.value=!0,f.value="connected"):p.ua.isConnected()&&(f.value="connected"),x={onConnecting:()=>{f.value="connecting"},onConnected:()=>{f.value="connected"},onDisconnected:()=>{f.value="disconnected",c.value=!1},onRegistered:()=>{c.value=!0,f.value="connected"},onUnregistered:()=>{c.value=!1},onRegistrationFailed:a=>{console.error("Registration failed:",a),c.value=!1,f.value="failed"},onNewSession:a=>{k=a},onIncomingSession:(a,g,N)=>{if(k){a.terminate({status_code:486,reason_phrase:"Busy Here"});return}o.value={session:a,callerNumber:g,callerName:N},u.value=g,n.value="ringing",i.onStatusChange?.("ringing"),d("statusChange","ringing"),i.onIncomingCall?.(g,N),d("incomingCall",g,N),a.on("failed",L=>{console.error("Incoming call failed:",L?.cause),n.value="failed",i.onStatusChange?.("failed"),d("statusChange","failed"),H(g,0,"missed"),o.value=null,k=null,setTimeout(()=>{n.value="disconnected",i.onStatusChange?.("disconnected"),d("statusChange","disconnected")},3e3)}),a.on("ended",()=>{n.value="ended",i.onStatusChange?.("ended"),d("statusChange","ended");const L=C?Math.floor((Date.now()-C)/1e3):0;H(g,L,"completed"),i.onCallEnd?.(g,L,"completed"),d("callEnd",g,L,"completed"),o.value=null,k=null,V&&(clearInterval(V),V=null),setTimeout(()=>{n.value="disconnected",i.onStatusChange?.("disconnected"),d("statusChange","disconnected"),C=null,w.value=0},2e3)}),a.on("confirmed",()=>{n.value="confirmed",i.onStatusChange?.("confirmed"),d("statusChange","confirmed"),C=Date.now(),o.value=null,V=setInterval(()=>{C&&(w.value=Math.floor((Date.now()-C)/1e3))},1e3)})}},p.listeners.add(x),p.isStarted||(p.ua.start(),p.isStarted=!0);const l=localStorage.getItem("tbi-phone-call-history");if(l)try{v.value=JSON.parse(l)}catch(a){console.error("Error loading call history",a)}const t=a=>{const N=a.detail.number;n.value==="disconnected"&&m(N)};window.addEventListener("StartCallEvent",t)}),e.onUnmounted(()=>{V&&clearInterval(V),p&&x&&p.listeners.delete(x)}),(l,t)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(B.cn)("tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2",E.className))},[n.value==="disconnected"?(e.openBlock(),e.createElementBlock("div",Z,[e.createElementVNode("button",{onClick:t[0]||(t[0]=a=>b.value=!0),class:"h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",type:"button"},[...t[5]||(t[5]=[e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.954 8.954 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"})],-1)])]),e.withDirectives(e.createElementVNode("input",{type:"text","onUpdate:modelValue":t[1]||(t[1]=a=>u.value=a),onKeydown:P,placeholder:S.value.placeholder,class:"flex-1 w-full h-8 px-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"},null,40,ee),[[e.vModelText,u.value]]),e.createElementVNode("button",{onClick:t[2]||(t[2]=a=>m(u.value)),disabled:u.value.length<9||!c.value,class:"h-8 w-8 flex items-center justify-center rounded-xl bg-green-500 hover:bg-green-600 disabled:bg-gray-300 disabled:cursor-not-allowed text-white transition-colors",type:"button",title:c.value?"Call":"Connecting..."},[f.value==="connecting"?(e.openBlock(),e.createElementBlock("div",ne)):(e.openBlock(),e.createElementBlock("svg",oe,[...t[6]||(t[6]=[e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},null,-1)])]))],8,te)])):e.createCommentVNode("",!0),n.value==="progress"?(e.openBlock(),e.createElementBlock("div",le,[t[8]||(t[8]=e.createElementVNode("div",{class:"relative"},[e.createElementVNode("svg",{class:"w-12 h-12 text-yellow-500 animate-pulse",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M15.05 5A7 7 0 0 1 19 8.95M15.05 1A11 11 0 0 1 23 8.94m-1 7.98v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})]),e.createElementVNode("div",{class:"absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping"})],-1)),e.createElementVNode("div",ae,[e.createElementVNode("p",se,e.toDisplayString(S.value.calling)+" "+e.toDisplayString(u.value),1),e.createElementVNode("p",re,e.toDisplayString(S.value.waitingResponse),1)]),e.createElementVNode("button",{onClick:y,class:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button"},[t[7]||(t[7]=e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})],-1)),e.createTextVNode(" "+e.toDisplayString(S.value.cancel),1)])])):e.createCommentVNode("",!0),n.value==="ringing"&&o.value?(e.openBlock(),e.createElementBlock("div",ce,[t[11]||(t[11]=e.createElementVNode("div",{class:"relative"},[e.createElementVNode("svg",{class:"w-12 h-12 text-blue-500 animate-bounce",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M15.05 5A7 7 0 0 1 19 8.95M15.05 1A11 11 0 0 1 23 8.94m-1 7.98v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})]),e.createElementVNode("div",{class:"absolute inset-0 rounded-full border-4 border-blue-500/30 animate-ping"})],-1)),e.createElementVNode("div",ie,[e.createElementVNode("p",de,e.toDisplayString(S.value.incomingCall),1),e.createElementVNode("p",ue,e.toDisplayString(o.value.callerNumber),1),o.value.callerName?(e.openBlock(),e.createElementBlock("p",me,e.toDisplayString(o.value.callerName),1)):e.createCommentVNode("",!0)]),e.createElementVNode("div",ve,[e.createElementVNode("button",{onClick:M,class:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button"},[t[9]||(t[9]=e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})],-1)),e.createTextVNode(" "+e.toDisplayString(S.value.reject),1)]),e.createElementVNode("button",{onClick:D,class:"flex items-center gap-2 px-6 py-2 rounded-full bg-green-500 hover:bg-green-600 text-white text-sm font-medium transition-colors",type:"button"},[t[10]||(t[10]=e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"})],-1)),e.createTextVNode(" "+e.toDisplayString(S.value.answer),1)])])])):e.createCommentVNode("",!0),n.value==="confirmed"?(e.openBlock(),e.createElementBlock("div",fe,[t[13]||(t[13]=e.createElementVNode("div",{class:"relative"},[e.createElementVNode("svg",{class:"w-12 h-12 text-green-500",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M20 15.5c-1.25 0-2.45-.2-3.57-.57-.35-.12-.74-.03-1.02.24l-2.2 2.2c-2.83-1.45-5.15-3.76-6.59-6.59l2.2-2.21c.28-.26.36-.65.25-1C8.7 6.45 8.5 5.25 8.5 4c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1 0 9.39 7.61 17 17 17 .55 0 1-.45 1-1v-3.5c0-.55-.45-1-1-1zM19 12h2c0-4.97-4.03-9-9-9v2c3.87 0 7 3.13 7 7zm-4 0h2c0-2.76-2.24-5-5-5v2c1.66 0 3 1.34 3 3z"})]),e.createElementVNode("div",{class:"absolute inset-0 rounded-full bg-green-500/20 animate-pulse"})],-1)),e.createElementVNode("div",ge,[e.createElementVNode("p",pe,e.toDisplayString(u.value),1),e.createElementVNode("p",he,e.toDisplayString(e.unref(B.formatDuration)(w.value)),1)]),e.createElementVNode("button",{onClick:y,class:"flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",type:"button"},[t[12]||(t[12]=e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})],-1)),e.createTextVNode(" "+e.toDisplayString(S.value.hangUp),1)])])):e.createCommentVNode("",!0),n.value==="failed"||n.value==="ended"?(e.openBlock(),e.createElementBlock("div",ye,[(e.openBlock(),e.createElementBlock("svg",{class:e.normalizeClass(e.unref(B.cn)("w-12 h-12",n.value==="failed"?"text-red-500":"text-gray-500")),viewBox:"0 0 24 24",fill:"currentColor"},[n.value==="failed"?(e.openBlock(),e.createElementBlock("path",Ce)):(e.openBlock(),e.createElementBlock("path",Ee))],2)),e.createElementVNode("div",xe,[e.createElementVNode("p",we,e.toDisplayString(J.value.text),1)])])):e.createCommentVNode("",!0),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[b.value?(e.openBlock(),e.createElementBlock("div",be,[e.createElementVNode("div",{class:"fixed inset-0 bg-black/50",onClick:t[3]||(t[3]=a=>b.value=!1)}),e.createElementVNode("div",Se,[e.createElementVNode("div",ke,[e.createElementVNode("div",Ne,[e.createElementVNode("div",null,[e.createElementVNode("h2",Ve,e.toDisplayString(S.value.callHistory),1),e.createElementVNode("p",_e,e.toDisplayString(v.value.length===0?S.value.noCallsRegistered:`${v.value.length} ${S.value.callsRegistered}`),1)]),e.createElementVNode("button",{onClick:t[4]||(t[4]=a=>b.value=!1),class:"h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",type:"button"},[...t[14]||(t[14]=[e.createElementVNode("svg",{class:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})],-1)])])]),e.createElementVNode("div",Be,[v.value.length===0?(e.openBlock(),e.createElementBlock("div",De,[t[15]||(t[15]=e.createElementVNode("svg",{class:"w-12 h-12 mx-auto mb-2 opacity-50",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"})],-1)),e.createElementVNode("p",null,e.toDisplayString(S.value.noCalls),1)])):(e.openBlock(),e.createElementBlock("div",ze,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(v.value,(a,g)=>(e.openBlock(),e.createElementBlock("div",{key:a.id,class:"flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",style:e.normalizeStyle({animationDelay:`${g*30}ms`})},[e.createElementVNode("div",{class:e.normalizeClass(e.unref(B.cn)("w-9 h-9 rounded-full flex items-center justify-center shrink-0",$(a.status)))},[(e.openBlock(),e.createElementBlock("svg",{class:e.normalizeClass(e.unref(B.cn)("w-4 h-4",Q(a.status))),viewBox:"0 0 24 24",fill:"currentColor"},[a.status==="completed"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t[16]||(t[16]=e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},null,-1)),t[17]||(t[17]=e.createElementVNode("path",{d:"M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z"},null,-1))],64)):a.status==="failed"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[t[18]||(t[18]=e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"},null,-1)),t[19]||(t[19]=e.createElementVNode("path",{d:"M19 6.41L17.59 5 15 7.59 12.41 5 11 6.41 13.59 9 11 11.59 12.41 13 15 10.41 17.59 13 19 11.59 16.41 9z"},null,-1))],64)):(e.openBlock(),e.createElementBlock("path",Me))],2))],2),e.createElementVNode("div",Ie,[e.createElementVNode("p",He,e.toDisplayString(a.number),1),e.createElementVNode("div",Ue,[e.createElementVNode("span",null,e.toDisplayString(X(a.timestamp)),1),a.duration>0?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t[20]||(t[20]=e.createElementVNode("span",null,"•",-1)),e.createElementVNode("span",Te,e.toDisplayString(e.unref(B.formatDuration)(a.duration)),1)],64)):e.createCommentVNode("",!0)])]),e.createElementVNode("button",{onClick:N=>O(a),class:"h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",type:"button"},[...t[21]||(t[21]=[e.createElementVNode("svg",{class:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor"},[e.createElementVNode("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"})],-1)])],8,Pe)],4))),128))]))])])])])):e.createCommentVNode("",!0)]))],2))}}),W=Symbol("Phone");let A=null,q=null;function Re(E){return`${E.websocketUrl}|${E.sipUri}|${E.authorizationUser}`}function Le(E){const T=Re(E);if(A&&q===T)return A;if(A&&q!==T){try{A.ua.stop()}catch{}A=null}q=T;const d={sockets:[new B.JsSIP.WebSocketInterface(E.websocketUrl)],uri:E.sipUri,password:E.password,registrar_server:E.registrarServer,display_name:E.displayName,authorization_user:E.authorizationUser,connection_recovery_min_interval:2,connection_recovery_max_interval:30},s=new B.JsSIP.UA(d),I=document.createElement("audio");I.autoplay=!0;const r={ua:s,audio:I,isStarted:!1,listeners:new Set};return s.on("connecting",()=>{r.listeners.forEach(h=>h.onConnecting?.())}),s.on("connected",()=>{r.listeners.forEach(h=>h.onConnected?.())}),s.on("disconnected",()=>{r.listeners.forEach(h=>h.onDisconnected?.())}),s.on("registered",()=>{r.listeners.forEach(h=>h.onRegistered?.())}),s.on("unregistered",()=>{r.listeners.forEach(h=>h.onUnregistered?.())}),s.on("registrationFailed",h=>{r.listeners.forEach(n=>n.onRegistrationFailed?.(h?.cause))}),s.on("newRTCSession",h=>{const n=h.session;if(n.direction==="incoming"){const u=n.remote_identity,v=u?.uri?.user||"Unknown",w=u?.display_name||void 0;r.listeners.forEach(c=>c.onIncomingSession?.(n,v,w)),n.on("peerconnection",()=>{n.connection.addEventListener("addstream",c=>{if(!c.streams?.length)return;const f=document.createElement("audio");f.srcObject=c.streams[0],f.play()}),n.connection.addEventListener("track",c=>{const f=document.createElement("audio");f.srcObject=c.streams[0],f.play()})});return}r.listeners.forEach(u=>u.onNewSession?.(n)),n.connection&&(n.connection.addEventListener("addstream",u=>{if(!u.streams?.length)return;const v=document.createElement("audio");v.srcObject=u.streams[0],v.play()}),n.connection.addEventListener("track",u=>{const v=document.createElement("audio");v.srcObject=u.streams[0],v.play()}))}),A=r,r}function je(E){const{config:T,onCallStart:i,onCallEnd:d,onStatusChange:s,onIncomingCall:I}=E,r=e.ref("disconnected"),h=e.ref(""),n=e.ref([]),u=e.ref(0),v=e.ref(!1),w=e.ref("connecting"),c=e.ref(null);let f=null,b=null,o=null,p=null;const k=y=>{h.value=y},C=(y,D,M)=>{const m={id:Date.now().toString(),number:y,timestamp:Date.now(),duration:D,status:M};n.value=[m,...n.value].slice(0,50),localStorage.setItem("tbi-phone-call-history",JSON.stringify(n.value))},V=()=>{b&&(b.terminate(),b=null),c.value=null},x=()=>{if(!c.value)return;const{session:y,callerNumber:D}=c.value,M={mediaConstraints:{audio:!0,video:!1}};try{y.answer(M),b=y,i?.(D)}catch(m){console.error("Failed to answer call:",m),r.value="failed",s?.("failed"),C(D,0,"missed"),c.value=null,setTimeout(()=>{r.value="disconnected",s?.("disconnected")},3e3)}},S=()=>{if(!c.value)return;const{session:y,callerNumber:D}=c.value;try{y.terminate({status_code:603,reason_phrase:"Decline"})}catch(M){console.error("Failed to reject call:",M)}C(D,0,"missed"),c.value=null,r.value="disconnected",s?.("disconnected")},J=y=>{if(!y.trim()||!f)return;if(!v.value){console.warn("Phone is not ready yet. Please wait for registration.");return}h.value=y,i?.(y);const M={eventHandlers:{progress:()=>{r.value="progress",s?.("progress")},failed:m=>{console.error("Call failed:",m?.cause),r.value="failed",s?.("failed"),C(y,0,"failed"),d?.(y,0,"failed"),b=null,setTimeout(()=>{r.value="disconnected",s?.("disconnected")},3e3)},ended:()=>{r.value="ended",s?.("ended");const m=o?Math.floor((Date.now()-o)/1e3):0;C(y,m,"completed"),d?.(y,m,"completed"),b=null,p&&(clearInterval(p),p=null),setTimeout(()=>{r.value="disconnected",s?.("disconnected"),o=null,u.value=0},2e3)},confirmed:()=>{r.value="confirmed",s?.("confirmed"),o=Date.now(),p=setInterval(()=>{o&&(u.value=Math.floor((Date.now()-o)/1e3))},1e3)}},mediaConstraints:{audio:!0,video:!1}};r.value="progress",s?.("progress");try{b=f.ua.call(y,M)}catch(m){console.error("Failed to start call:",m),r.value="failed",s?.("failed"),C(y,0,"failed"),setTimeout(()=>{r.value="disconnected",s?.("disconnected")},3e3)}};e.onMounted(()=>{f=Le(T),f.ua.isRegistered()?(v.value=!0,w.value="connected"):f.ua.isConnected()&&(w.value="connected");const y={onConnecting:()=>{w.value="connecting"},onConnected:()=>{w.value="connected"},onDisconnected:()=>{w.value="disconnected",v.value=!1},onRegistered:()=>{v.value=!0,w.value="connected"},onUnregistered:()=>{v.value=!1},onRegistrationFailed:m=>{console.error("Registration failed:",m),v.value=!1,w.value="failed"},onNewSession:m=>{b=m},onIncomingSession:(m,P,O)=>{if(b){m.terminate({status_code:486,reason_phrase:"Busy Here"});return}c.value={session:m,callerNumber:P,callerName:O},h.value=P,r.value="ringing",s?.("ringing"),I?.(P,O),m.on("failed",$=>{console.error("Incoming call failed:",$?.cause),r.value="failed",s?.("failed"),C(P,0,"missed"),c.value=null,b=null,setTimeout(()=>{r.value="disconnected",s?.("disconnected")},3e3)}),m.on("ended",()=>{r.value="ended",s?.("ended");const $=o?Math.floor((Date.now()-o)/1e3):0;C(P,$,"completed"),d?.(P,$,"completed"),c.value=null,b=null,p&&(clearInterval(p),p=null),setTimeout(()=>{r.value="disconnected",s?.("disconnected"),o=null,u.value=0},2e3)}),m.on("confirmed",()=>{r.value="confirmed",s?.("confirmed"),o=Date.now(),c.value=null,p=setInterval(()=>{o&&(u.value=Math.floor((Date.now()-o)/1e3))},1e3)})}};f.listeners.add(y),f.isStarted||(f.ua.start(),f.isStarted=!0);const D=localStorage.getItem("tbi-phone-call-history");if(D)try{n.value=JSON.parse(D)}catch(m){console.error("Error loading call history",m)}const M=m=>{const O=m.detail.number;r.value==="disconnected"&&J(O)};window.addEventListener("StartCallEvent",M)}),e.onUnmounted(()=>{p&&clearInterval(p)});const H={status:e.readonly(r),callNumber:h,setCallNumber:k,callHistory:e.readonly(n),currentCallDuration:e.readonly(u),startCall:J,endCall:V,answerCall:x,rejectCall:S,isReady:e.readonly(v),connectionStatus:e.readonly(w),incomingCall:e.readonly(c)};return e.provide(W,H),H}function Oe(){const E=e.inject(W);if(!E)throw new Error("usePhone must be used within a component that has called usePhoneProvider");return E}function $e(E,T={}){const{onCallStart:i,onCallEnd:d,onStatusChange:s,onConnectionChange:I,persistHistory:r=!0,historyKey:h="tbi-phone-call-history"}=T,n=e.ref("disconnected"),u=e.ref(""),v=e.ref([]),w=e.ref(0),c=e.ref(!1),f=e.ref("connecting"),b=e.ref(null);let o=null;e.onMounted(()=>{o=new B.PhoneManager(E,{onStatusChange:x=>{n.value=x,s?.(x)},onConnectionChange:x=>{f.value=x,o&&(c.value=o.state.isReady),I?.(x)},onCallStart:i,onCallEnd:d,onDurationUpdate:x=>{w.value=x},onHistoryUpdate:x=>{v.value=x},onRegistered:()=>{c.value=!0},onUnregistered:()=>{c.value=!1}},{persistHistory:r,historyKey:h}),o.initialize(),n.value=o.state.status,u.value=o.state.callNumber,v.value=o.state.callHistory,c.value=o.state.isReady,f.value=o.state.connectionStatus,b.value=o.ua}),e.onUnmounted(()=>{o&&(o.destroy(),o=null)});const p=x=>{u.value=x,o?.setCallNumber(x)},k=x=>{o?.startCall(x)},C=()=>{o?.endCall()},V=()=>{o?.clearHistory(),v.value=[]};return{status:e.readonly(n),callNumber:u,setCallNumber:p,callHistory:e.readonly(v),clearCallHistory:V,currentCallDuration:e.readonly(w),startCall:k,endCall:C,isReady:e.readonly(c),connectionStatus:e.readonly(f),ua:b}}exports.Phone=G;exports.PhoneKey=W;exports.default=G;exports.usePhone=Oe;exports.usePhoneManager=$e;exports.usePhoneProvider=je;