@dialstack/sdk-react 3.3.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-agent.cjs +1 -1
- package/dist/ai-agent.mjs +1 -1
- package/dist/call-history.cjs +1 -1
- package/dist/call-history.mjs +1 -1
- package/dist/call-logs.cjs +1 -1
- package/dist/call-logs.mjs +1 -1
- package/dist/dial-plan.cjs +1 -1
- package/dist/dial-plan.cjs.map +1 -1
- package/dist/dial-plan.mjs +1 -1
- package/dist/dial-plan.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/phone-number-ordering.cjs +1 -1
- package/dist/phone-number-ordering.mjs +1 -1
- package/dist/phone-numbers.cjs +1 -1
- package/dist/phone-numbers.mjs +1 -1
- package/dist/softphone.cjs +1 -1
- package/dist/softphone.cjs.map +1 -1
- package/dist/softphone.d.cts +0 -12
- package/dist/softphone.d.ts +0 -12
- package/dist/softphone.mjs +1 -1
- package/dist/softphone.mjs.map +1 -1
- package/dist/voicemails.cjs +1 -1
- package/dist/voicemails.mjs +1 -1
- package/package.json +4 -4
package/dist/softphone.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{useRef as n,useEffect as t,useState as a,useReducer as r,useMemo as l,useCallback as s,createContext as c,useContext as o,useId as i}from"react";import{DialStackPhone as d,supportsConference as u,LocalConference as p,createPaginatedList as m,storage as g}from"@dialstack/sdk-webrtc";import{parsePhoneNumber as f}from"libphonenumber-js";import{defaultLocale as h}from"@dialstack/sdk-js/pure";import{DialstackComponentsContext as v}from"@dialstack/sdk-react";function b(e){const a=n(e);return t(()=>{a.current=e},[e]),a}function y(e){const{autoConnect:n=!0,onError:r,existingPhone:l}=e,[s,c]=a(null!=l?l:null),[o,i]=a(l?l.isConnected?"connected":l.isConnecting||n?"connecting":"idle":n&&e.token?"connecting":"idle"),u=b({onError:r}),p=b(e.emergencyAddressId),m=b(e.iceServers),g=b(e.storage),f=b(e.ringback),h=b(e.createSignalingSocket),v=b(e.onAppResume),y=b(e.onTokenExpiring),{token:x,apiBaseUrl:E,signalingBaseUrl:w,autoReconnect:C}=e;t(()=>{if(l){let e=!1;const t=n=>()=>{e||n()},a=t(()=>i("connected")),r=t(()=>i("reconnecting")),s=t(()=>i("disconnected")),c=n=>{var t,a;e||(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&i("error"))};return l.on("connected",a),l.on("reconnected",a),l.on("reconnecting",r),l.on("disconnected",s),l.on("error",c),!n||l.isConnected||l.isConnecting||l.connect().catch(n=>{var t,a,r,l;if(e)return;const s=n;null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:null!==(r=null==s?void 0:s.code)&&void 0!==r?r:"internal_error",message:null!==(l=null==s?void 0:s.message)&&void 0!==l?l:String(n)}),i("error")}),()=>{e=!0,l.off("connected",a),l.off("reconnected",a),l.off("reconnecting",r),l.off("disconnected",s),l.off("error",c)}}if(!x)return;let e=!1;const t=(a={token:x,apiBaseUrl:E,signalingBaseUrl:w,emergencyAddressId:p.current,iceServers:m.current,storage:g.current,ringback:f.current,createSignalingSocket:h.current,onAppResume:v.current,autoReconnect:C,onTokenExpiring:y.current?()=>{const e=y.current;return e?e():Promise.reject(new Error("onTokenExpiring not set"))}:void 0},new d(a));var a;c(t);const r=n=>()=>{e||n()};return t.on("connected",r(()=>i("connected"))),t.on("reconnected",r(()=>i("connected"))),t.on("reconnecting",r(()=>i("reconnecting"))),t.on("disconnected",r(()=>i("disconnected"))),t.on("error",n=>{var t,a;e||(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&i("error"))}),n&&(i("connecting"),t.connect().catch(n=>{var t,a,r,l;"transport_closed"!==(null==n?void 0:n.code)&&(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:null!==(r=null==n?void 0:n.code)&&void 0!==r?r:"internal_error",message:null!==(l=null==n?void 0:n.message)&&void 0!==l?l:String(n)}),e||i("error"))})),()=>{e=!0,t.disconnect(),c(null),i("idle")}},[l,x,E,w,C,n,u,p,m,g,f,h,v,y]);const k=!l||"idle"!==o&&"connecting"!==o?o:l.isConnected?"connected":l.isConnecting?"connecting":o;return{phone:null!=l?l:s,connection:k}}function x(e,n,t,a){return new(t||(t=Promise))(function(r,l){function s(e){try{o(a.next(e))}catch(e){l(e)}}function c(e){try{o(a.throw(e))}catch(e){l(e)}}function o(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(s,c)}o((a=a.apply(e,n||[])).next())})}function E(e){return"inbound"===e.direction&&("ringing"===e.state||"trying"===e.state)}function w(e){return!!e&&(Array.isArray(e)?e.some(E):E(e))}function C(e){return e.isConnected}function k(e){return e?E(e)?"incoming":"in-call":"dial"}function $(e){return"inbound"===e.direction?e.from:e.to}function N(e){return"inbound"===e.direction?e.fromName:null}function A(e){const n=Math.max(0,Math.floor(e));return`${Math.floor(n/60)}:${(n%60).toString().padStart(2,"0")}`}function S(e,n="US"){if(!e)return"";try{const t=f(e,n);if(t){return"US"===t.country||"1"===t.countryCallingCode?t.formatNational():t.formatInternational()}}catch(e){}return e}"function"==typeof SuppressedError&&SuppressedError;const I=/[^+*#0-9A-Da-d]/g,T="US";function z(e){return e.replace(I,"").slice(0,32).toUpperCase()}function O(e,n="US"){const t=z(e);if(!t)return"";if(!/[*#]/.test(t)&&/^\+?[0-9]+$/.test(t))try{const e=f(t,n);if(null==e?void 0:e.isValid())return e.number}catch(e){}return t}const D={code:"invalid_message",message:"Enter a valid phone number, extension, or feature code"};function M(e,n,{silentWhenEmpty:t=!1}={}){const a=O(e,T);return a||(t&&!e.trim()||null==n||n(Object.assign({},D)),"")}function j(e){switch(e){case"trying":return"stateTrying";case"ringing":return"stateRinging";case"active":return"stateActive";case"held":return"stateHeld";default:return"stateEnded"}}const P=new Set(["auth_failed","auth_expired","session_limit","session_revoked","going_away","idle_timeout","slow_consumer","transport_closed","ice_fetch_failed"]);function _(e){return"mic_permission_denied"===e?"micPermissionError":P.has(e)?"connectionError":"callError"}const B={calls:[],conferenceAudio:null};function H(e,n){const t=function(e,n){var t,a;switch(n.type){case"active":{const t=e.calls.find(e=>e.call===n.call),a=e.calls.filter(e=>e.call!==n.call).map(e=>Object.assign(Object.assign({},e),{active:!1})),r=t?Object.assign(Object.assign({},t),{active:!0}):{call:n.call,active:!0,transferPeer:null,transferRole:null,merged:!1};return Object.assign(Object.assign({},e),{calls:[...a,r]})}case"incomingAdded":return e.calls.some(e=>e.call===n.call)?e:Object.assign(Object.assign({},e),{calls:[...e.calls,{call:n.call,active:!1,transferPeer:null,transferRole:null,merged:!1}]});case"answered":case"switchActive":return e.calls.some(e=>e.call===n.call)?Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"answeredInPlace":return e.calls.find(e=>e.call===n.call)?e.calls.some(e=>e.active)?e:Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"consultStarted":{const r=null!==(a=null===(t=e.calls.find(e=>e.active))||void 0===t?void 0:t.call)&&void 0!==a?a:null,l=e.calls.filter(e=>e.call!==r).map(e=>Object.assign(Object.assign({},e),{active:!1})),s=r?[{call:r,active:!1,transferPeer:n.call,transferRole:"original",merged:!1}]:[];return Object.assign(Object.assign({},e),{calls:[...l,...s,{call:n.call,active:!0,transferPeer:r,transferRole:"consult",merged:!1}]})}case"cancelConsult":{const n=e.calls.find(e=>"consult"===e.transferRole),t=e.calls.find(e=>"original"===e.transferRole);if(!n||!t)return e;const a=e.calls.filter(e=>e.call!==n.call&&e.call!==t.call);return Object.assign(Object.assign({},e),{calls:[...a,{call:t.call,active:!0,transferPeer:null,transferRole:null,merged:!1}]})}case"callEnded":{const t=e.calls.find(e=>e.call===n.call);if(!t)return e;let a=e.calls.filter(e=>e.call!==n.call);return t.transferPeer&&(a=a.map(e=>e.call===t.transferPeer?{call:e.call,active:!0,transferPeer:null,transferRole:null,merged:!1}:e)),Object.assign(Object.assign({},e),{calls:a})}case"merged":{const[t]=n.calls;if(!t)return e;const a=new Set(n.calls);return Object.assign(Object.assign({},e),{conferenceAudio:n.audio,calls:e.calls.map(e=>a.has(e.call)?Object.assign(Object.assign({},e),{merged:!0,active:e.call===t}):Object.assign(Object.assign({},e),{active:!1}))})}case"unmerged":return e.calls.some(e=>e.merged)?Object.assign(Object.assign({},e),{conferenceAudio:null,calls:e.calls.map(e=>e.merged?Object.assign(Object.assign({},e),{merged:!1}):e)}):e;case"reset":return 0===e.calls.length?e:B}}(e,n);if(t===e)return e;const a=function(e){const n=e.filter(e=>e.active).length;if(0===n){const n=[...e].reverse().find(e=>!E(e.call));return n?e.map(e=>e.call===n.call?Object.assign(Object.assign({},e),{active:!0}):e):e}if(1===n)return e;let t=!1;return[...e].reverse().map(e=>e.active?t?Object.assign(Object.assign({},e),{active:!1}):(t=!0,e):e).reverse()}(t.calls);return a===t.calls?t:Object.assign(Object.assign({},t),{calls:a})}function R(e,n={}){const{onError:t}=n,[,r]=a(0),l=s(()=>r(e=>e+1),[]),c=s((e,n)=>{var a,r;const l=e;null==t||t({code:null!==(a=null==l?void 0:l.code)&&void 0!==a?a:n,message:null!==(r=null==l?void 0:l.message)&&void 0!==r?r:String(e)})},[t]),o=s(e=>function(e,n,t){return{answer:()=>{if(e)try{e.answer()}catch(e){n(e,"call_failed")}},reject:()=>{if(e)try{e.reject()}catch(e){n(e,"call_failed")}},hangup:()=>{if(e)try{e.hangup()}catch(e){n(e,"call_failed")}},toggleMute:()=>{if(e)try{e.isMuted?e.unmute():e.mute(),t()}catch(e){n(e,"call_failed")}},toggleHold:()=>{if(e)try{"held"===e.state?e.resume():e.hold()}catch(e){n(e,"call_failed")}},sendDtmf:t=>{if(t&&e)try{e.sendDtmf(t)}catch(e){n(e,"call_failed")}}}}(e,c,l),[c,l]),{answer:i,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g}=o(e);return{answer:i,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g,transfer:s(n=>{if(!e)return!1;const a=M(n,t,{silentWhenEmpty:!0});if(!a)return!1;try{return e.transfer(a),!0}catch(e){return c(e,"call_failed"),!1}},[e,c,t]),callActionsFor:o}}function L(e,n=500){const[,r]=a(0),l=null!=e&&C(e);return t(()=>{if(!l)return;const e=setInterval(()=>r(e=>e+1),n);return()=>clearInterval(e)},[l,n]),A(e?e.duration:0)}const U="Timed out confirming your location. Please try again.";function V(e,n){let t=!1;return new Promise((a,r)=>{const l=setTimeout(()=>{t=!0,r(new Error(U))},8e3);e.then(()=>{clearTimeout(l),t?n(null):a()},e=>{clearTimeout(l);const a=e instanceof Error?e:new Error(U);t?n(a):r(a)})})}function F(e){const[n,t]=a(null);return{lastError:n,handleError:s(n=>{t(n),null==e||e(n)},[e]),clearError:s(()=>t(null),[])}}function W(e){return{onType:s(n=>e(z(n)),[e]),onPasteText:s(n=>e(O(n,T)),[e])}}const K={maxWidth:420,actionButtonSize:68,controlButtonSize:60,keyGap:14,radius:14},q={background:"#ffffff",surface:"rgba(0, 0, 0, 0.04)",surfaceActive:"rgba(0, 0, 0, 0.09)",text:"#1a1a1a",textSecondary:"rgba(0, 0, 0, 0.55)",border:"rgba(0, 0, 0, 0.1)",accent:"#6772e5",success:"#30a46c",danger:"#e5484d",warning:"#f5a623",onAccent:"#ffffff"},G={background:"#1a1a1a",surface:"rgba(255, 255, 255, 0.06)",surfaceActive:"rgba(255, 255, 255, 0.12)",text:"#ffffff",textSecondary:"rgba(255, 255, 255, 0.6)",border:"rgba(255, 255, 255, 0.12)",accent:"#828bf0",success:"#3dd68c",danger:"#ff6369",warning:"#f5a623",onAccent:"#ffffff"},Y=[{digit:"1",letters:""},{digit:"2",letters:"ABC"},{digit:"3",letters:"DEF"},{digit:"4",letters:"GHI"},{digit:"5",letters:"JKL"},{digit:"6",letters:"MNO"},{digit:"7",letters:"PQRS"},{digit:"8",letters:"TUV"},{digit:"9",letters:"WXYZ"},{digit:"*",letters:""},{digit:"0",letters:"+"},{digit:"#",letters:""}];function J(e){var n,t,a,r,l,s,c,o,i,d;const u="dark"===(null==e?void 0:e.theme)?G:q;const p=null!==(n=null==e?void 0:e.variables)&&void 0!==n?n:{};return{background:null!==(t=p.colorBackground)&&void 0!==t?t:u.background,surface:null!==(a=p.colorSurfaceSubtle)&&void 0!==a?a:u.surface,surfaceActive:u.surfaceActive,text:null!==(r=p.colorText)&&void 0!==r?r:u.text,textSecondary:null!==(l=p.colorTextSecondary)&&void 0!==l?l:u.textSecondary,border:null!==(s=p.colorBorder)&&void 0!==s?s:u.border,accent:null!==(c=p.colorPrimary)&&void 0!==c?c:u.accent,success:null!==(o=p.colorSuccess)&&void 0!==o?o:u.success,danger:null!==(i=p.colorDanger)&&void 0!==i?i:u.danger,warning:null!==(d=p.colorWarning)&&void 0!==d?d:u.warning,onAccent:u.onAccent}}const Q=c(null),X=()=>Promise.reject(new Error("Phone not connected")),Z={listEmergencyAddresses:()=>m(X(),X),setEmergencyAddress:X,presentedEmergencyAddressId:null,clearEmergencyAddressRegisteredIp:X,reconnectWithEmergency:X};function ee({token:c,existingPhone:o,apiBaseUrl:i,onTokenExpiring:d,iceServers:m,storage:g,ringback:f,createSignalingSocket:v,onAppResume:C,emergencyAddressId:k,autoConnect:$=!0,appearance:N,locale:A=h,defaultCountry:I="US",onConnectionStateChange:z,onIncomingCall:D,onCallStarted:j,onCallEnded:P,onError:_,placeOutbound:U,extra:W,children:K}){var q,G;const{lastError:Y,handleError:X,clearError:ee}=F(_),ne=`${null!==(q=null==N?void 0:N.theme)&&void 0!==q?q:""}|${JSON.stringify(null!==(G=null==N?void 0:N.variables)&&void 0!==G?G:{})}`,te=l(()=>J(N),[ne]),ae=e=>A.softphone[e],re=e=>S(e,I),{phone:le,connection:se}=y({existingPhone:o,token:c,apiBaseUrl:i,onTokenExpiring:d,iceServers:m,storage:g,ringback:f,createSignalingSocket:v,onAppResume:C,emergencyAddressId:k,autoConnect:$,onError:X}),{calls:ce,activeCall:oe,incomingCalls:ie,heldCalls:de,answerCall:ue,switchToCall:pe,placeCall:me,consultCall:ge,transferOriginal:fe,startAttendedTransfer:he,completeAttendedTransfer:ve,cancelAttendedTransfer:be,mergedCalls:ye,isMerged:xe,conferenceAudio:Ee,canMerge:we,mergeCalls:Ce,splitMerge:ke,hangupConference:$e,holdConference:Ne}=function(e,c,o={}){var i,d,m,g,f,h;const{onIncomingCall:v,onCallStarted:y,onCallActivated:w,onCallEnded:C,onError:k,placeOutbound:$}=o,[N,A]=r(H,B),[S,I]=a(e);S!==e&&(I(e),N.calls.length>0&&A({type:"reset"}));const{calls:z,conferenceAudio:D}=N,j=null!==(i=z.find(e=>e.active))&&void 0!==i?i:null,P=null!==(d=null==j?void 0:j.call)&&void 0!==d?d:null,_=l(()=>z.filter(e=>!e.active&&E(e.call)).map(e=>e.call),[z]),R=l(()=>z.filter(e=>!e.active&&!E(e.call)).map(e=>e.call),[z]),L=null!==(g=null===(m=z.find(e=>"consult"===e.transferRole))||void 0===m?void 0:m.call)&&void 0!==g?g:null,U=null!==(h=null===(f=z.find(e=>"original"===e.transferRole))||void 0===f?void 0:f.call)&&void 0!==h?h:null,V=l(()=>z.filter(e=>e.merged).map(e=>e.call),[z]),F=V.length>0,W=b(e),K=b(c),[,q]=a(0),G=s(()=>q(e=>e+1),[]),Y=n(null);Y.current=P;const J=b(L),Q=n(null),X=b(z),Z=b(U),ee=n(!0);t(()=>(ee.current=!0,()=>{ee.current=!1}),[]);const ne=b({onIncomingCall:v,onCallStarted:y,onCallActivated:w,onCallEnded:C,onError:k,placeOutbound:$}),te=n(new Map),ae=n(new WeakSet),re=s(e=>{const n=te.current.get(e);n&&(n(),te.current.delete(e))},[]),le=s(e=>{re(e);const n=()=>{G()},t=()=>{var n,t,a,r;"inbound"===e.direction&&(ae.current.add(e),null===(t=(n=ne.current).onCallStarted)||void 0===t||t.call(n,{direction:"inbound",peer:e.from})),null===(r=(a=ne.current).onCallActivated)||void 0===r||r.call(a,e),A({type:"answeredInPlace",call:e}),G()},a=n=>{var t,a;ae.current.has(e)&&(ae.current.delete(e),null===(a=(t=ne.current).onCallEnded)||void 0===a||a.call(t,{reason:n}));const r=Q.current;(null==r?void 0:r.has(e))&&(r.remove(e),r.calls.length<2&&(r.dispose(),Q.current=null,A({type:"unmerged"}))),A({type:"callEnded",call:e}),re(e)};e.on("trying",n),e.on("ringing",n),e.on("answered",t),e.on("held",n),e.on("resumed",n),e.on("ended",a),te.current.set(e,()=>{e.off("trying",n),e.off("ringing",n),e.off("answered",t),e.off("held",n),e.off("resumed",n),e.off("ended",a)})},[G,re,ne]),se=s(e=>x(this,void 0,void 0,function*(){var n,t,a,r,l,s,c,o,i,d,u,p;const m=W.current,g=M(e,ne.current.onError);if(!g)return;if(!m||"connected"!==K.current)return void(null===(t=(n=ne.current).onError)||void 0===t||t.call(n,{code:"transport_closed",message:"The softphone is not connected"}));if(te.current.size>=4)return void(null===(r=(a=ne.current).onError)||void 0===r||r.call(a,{code:"rate_limited",message:"Too many active calls"}));const f=Y.current;try{null==f||f.hold();const e=yield null!==(c=null===(s=(l=ne.current).placeOutbound)||void 0===s?void 0:s.call(l,g))&&void 0!==c?c:m.call(g);A({type:"active",call:e}),ae.current.add(e),null===(i=(o=ne.current).onCallStarted)||void 0===i||i.call(o,{direction:"outbound",peer:e.to}),le(e)}catch(e){if(f&&"ended"!==f.state)try{f.resume()}catch(e){}const n=e;null===(u=(d=ne.current).onError)||void 0===u||u.call(d,{code:null!==(p=n.code)&&void 0!==p?p:"call_failed",message:n.message})}}),[le,K,ne,W]),ce=s((e,n)=>{var t,a,r;const l=Y.current;try{null==l||l.hold(),e(),A(n)}catch(e){if(l&&"ended"!==l.state)try{l.resume()}catch(e){}const n=e;null===(a=(t=ne.current).onError)||void 0===a||a.call(t,{code:null!==(r=n.code)&&void 0!==r?r:"call_failed",message:n.message})}},[ne]),oe=s(e=>{Y.current!==e&&ce(()=>e.resume(),{type:"switchActive",call:e})},[ce]),ie=s(e=>{ce(()=>e.answer(),{type:"answered",call:e})},[ce]),de=s(()=>{var e,n,t;if(Q.current)return;const a=X.current;if(2!==a.length)return;if(!a.every(e=>e.call.isConnected)||!u())return;const r=a.map(e=>e.call);if(X.current.some(e=>null!==e.transferRole))return;const l=[];for(const e of r)if("held"===e.state)try{e.resume(),l.push(e)}catch(e){}try{const e=p.merge(r,r[0].localMediaStream,e=>{var n,t,a;return null===(t=(n=ne.current).onError)||void 0===t?void 0:t.call(n,{code:null!==(a=e.code)&&void 0!==a?a:"call_failed",message:e.message})});Q.current=e,A({type:"merged",calls:r,audio:e.localMediaStream}),G()}catch(a){for(const e of l)try{e.holdAfterResume()}catch(e){}const r=a;null===(n=(e=ne.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[X,Q,ne,G]),ue=s(()=>{const e=Q.current;if(e){e.dispose(),Q.current=null;for(const e of X.current)if(e.merged&&!e.active)try{e.call.hold()}catch(e){}A({type:"unmerged"}),G()}},[X,Q,G]),pe=s(e=>{var n,t,a;const r=Q.current;if(r){for(const l of r.calls)try{l.setConferenceHold(e)}catch(e){const r=e;null===(t=(n=ne.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}G()}},[Q,ne,G]),me=s(()=>{var e,n,t;const a=Q.current;if(!a)return;const r=a.calls;a.dispose(),Q.current=null,A({type:"unmerged"});for(const a of r)try{a.hangup()}catch(a){const r=a;null===(n=(e=ne.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[Q,ne]),ge=s(e=>x(this,void 0,void 0,function*(){var n,t,a;const r=Y.current,l=W.current,s=O(e,T);if(r&&!J.current&&s&&!Q.current)try{const e=yield r.attendedTransfer(s);if(!ee.current)return;if("ended"===r.state||W.current!==l)return void e.hangup();A({type:"consultStarted",call:e}),le(e)}catch(e){const r=e;null===(t=(n=ne.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}}),[le,J,ne,W]),fe=s(()=>{var e,n,t;const a=Z.current,r=J.current;if(a&&r&&r.isConnected)try{a.completeTransfer()}catch(a){const r=a;null===(n=(e=ne.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[J,ne,Z]),he=s(()=>{const e=J.current,n=Z.current;e&&(e.hangup(),re(e),"held"===(null==n?void 0:n.state)&&n.resume(),A({type:"cancelConsult"}))},[re,J,Z]);t(()=>{var n;if(!e)return;let t=!1;const a=te.current,r=(e,n)=>{var a,r,l;if(t)return;const s=null===(a=null==n?void 0:n.notifyHost)||void 0===a||a;Q.current||te.current.size>=4?e.reject("busy"):(A({type:"incomingAdded",call:e}),s&&(ae.current.add(e),null===(l=(r=ne.current).onIncomingCall)||void 0===l||l.call(r,{callId:e.id,from:e.from,fromName:e.fromName})),le(e))};e.on("incoming",r);for(const t of null!==(n=e.activeCalls)&&void 0!==n?n:[])te.current.has(t)||"inbound"===t.direction&&(r(t,{notifyHost:!t.isConnected}),t.isConnected&&(ae.current.add(t),A({type:"answeredInPlace",call:t})));return()=>{t=!0,e.off("incoming",r);const n=Q.current;n&&(n.dispose(),Q.current=null);for(const e of a.values())e();a.clear(),A({type:"reset"})}},[e,le,ne]);const ve=!F&&2===z.length&&z.every(e=>e.call.isConnected)&&!z.some(e=>null!==e.transferRole)&&u();return{calls:z,activeCall:P,incomingCalls:_,switchToCall:oe,answerCall:ie,placeCall:se,consultCall:L,heldCalls:R,transferOriginal:U,startAttendedTransfer:ge,completeAttendedTransfer:fe,cancelAttendedTransfer:he,mergedCalls:V,isMerged:F,conferenceAudio:D,canMerge:ve,mergeCalls:de,splitMerge:ue,hangupConference:me,holdConference:pe}}(le,se,{onIncomingCall:D,onCallStarted:j,onCallEnded:P,onError:X,placeOutbound:U}),Ae=function(e,r){const{disabled:l,connection:c,identityKey:o,liveCallCount:i=0}=r,[d,u]=a(!l),[p,m]=a(!1),[g,f]=a(!1),[h,v]=a([]),[y,E]=a(!1),w=b(y),[C,k]=a(null),$=b(e),N=n(!1),A=n(0),S=n(o);t(()=>{S.current!==o&&(S.current=o,N.current=!1,m(!1),f(!1),v([]),k(null),u(!l))},[o,l]);const I=s(()=>{f(!0),m(!1)},[]);t(()=>{if(l)return;if("connected"!==c)return void("disconnected"!==c&&"error"!==c||u(!1));let e=!1;return(()=>{x(this,void 0,void 0,function*(){var n,t;try{const a=$.current,r=(yield a.listEmergencyAddresses()).data;if(e)return;v(r);const l=a.presentedEmergencyAddressId,s=null!==(t=null!==(n=r.find(e=>e.id===l))&&void 0!==n?n:r[0])&&void 0!==t?t:null;if(!s)return void m(!1);if(i>0)return void u(!1);if(N.current||g)w.current||(m(!g),g||k(null));else{if(N.current=!0,null==l||l!==s.id||null==s.registered_ip)return void(yield V(a.reconnectWithEmergency(s.id),()=>{}).catch(()=>{}));m(!0),w.current||k(null)}}catch(n){e||m(!1)}finally{e||u(!1)}})})(),()=>{e=!0}},[l,c,g,$,w,i]);const T=s((e,n)=>x(this,void 0,void 0,function*(){const t=++A.current,a=n=>function(e){return"transport_closed"===(null==e?void 0:e.code)}(n)?"Connection interrupted. Please try again.":n instanceof Error?n.message:e,r=e=>{A.current===t&&k(e?a(e):null)};E(!0),k(null),f(!1),N.current=!0;try{const e=yield n(),t=$.current.reconnectWithEmergency(e);yield V(t,r)}catch(e){throw k(a(e)),e}finally{E(!1)}}),[$]);return{loading:d,bound:p,savedAddresses:h,submitting:y,error:C,onNetworkChanged:I,confirm:s(e=>T("Failed to confirm emergency address",()=>x(this,void 0,void 0,function*(){return yield $.current.clearEmergencyAddressRegisteredIp(e),e})),[T,$]),create:s(e=>T("Failed to save emergency address",()=>x(this,void 0,void 0,function*(){return(yield $.current.setEmergencyAddress(e)).id})),[T,$])}}(null!=le?le:Z,{disabled:!!k,connection:se,identityKey:c,liveCallCount:ce.length});t(()=>{if(!le)return;const e=Ae.onNetworkChanged;return le.on("network.changed",e),()=>le.off("network.changed",e)},[le,Ae.onNetworkChanged]);const Se=R(oe,{onError:X}),Ie=function(e,n=!0){const[r,l]=a(null);n||"addcall"!==r||l(null);const c=s(e=>{l(n=>n===e?null:e)},[]),o=s(()=>c("keypad"),[c]),i=s(()=>c("transfer"),[c]),d=s(()=>c("devices"),[c]),u=s(()=>c("addcall"),[c]),p=s(()=>l(e=>"transfer"===e?null:e),[]),m=s(()=>l(e=>"addcall"===e?null:e),[]);return t(()=>{l(null)},[e]),{showKeypad:"keypad"===r,showTransfer:"transfer"===r,showDevices:"devices"===r,showAddCall:"addcall"===r,toggleKeypad:o,toggleTransfer:i,toggleDevices:d,toggleAddCall:u,closeTransfer:p,closeAddCall:m}}(oe,ce.length<4),Te=L(oe),ze=l(()=>ce.map(e=>e.call),[ce]),Oe=w(ie),De=n(se);t(()=>{null==z||z({state:se}),"connected"===se&&"connected"!==De.current&&ee(),De.current=se},[se,z,ee]);const Me=l(()=>Object.assign({connection:se,webrtcPhone:le,calls:ze,activeCall:oe,incomingCalls:ie,incomingRinging:Oe,heldCalls:de,answerCall:ue,switchToCall:pe,actions:Se,overlays:Ie,duration:Te,consultCall:ge,transferOriginal:fe,startAttendedTransfer:he,completeAttendedTransfer:ve,cancelAttendedTransfer:be,placeCall:me,mergedCalls:ye,isMerged:xe,conferenceAudio:Ee,canMerge:we,mergeCalls:Ce,splitMerge:ke,hangupConference:$e,holdConference:Ne,emergency:Ae,emergencyManagedByHost:!!k,lastError:Y,clearError:ee,t:ae,displayNumber:re,palette:te},W),[se,le,ze,oe,ie,Oe,de,ue,pe,Se,Ie,Te,ge,fe,he,ve,be,me,ye,xe,Ee,we,Ce,ke,$e,Ne,Ae,k,Y,ee,te,A,I,W]);return e.createElement(Q.Provider,{value:Me},K)}function ne(){const e=o(Q);if(!e)throw new Error("Could not find softphone context; wrap your softphone UI in a <SoftphoneProvider>.");return e}const te="dialstack.softphone.input_device_id",ae="dialstack.softphone.output_device_id",re=c(null),le=e=>e.filter(e=>""!==e.deviceId).map(e=>({deviceId:e.deviceId,label:e.label})),se=({children:n})=>{var r,l,c;const{webrtcPhone:o,activeCall:i}=ne(),[d]=a(()=>"undefined"!=typeof HTMLMediaElement&&"function"==typeof HTMLMediaElement.prototype.setSinkId),[u]=a(()=>{var e;return"undefined"!=typeof navigator&&"function"==typeof(null===(e=navigator.mediaDevices)||void 0===e?void 0:e.enumerateDevices)}),[p,m]=a([]),[f,h]=a([]),[v,b]=a(!1),[y,E]=a(!1),[,w]=a(0),C=i?null!==(l=null!==(r=i.effectiveAudioInputDeviceId)&&void 0!==r?r:null==o?void 0:o.audioInputDeviceId)&&void 0!==l?l:null:null!==(c=null==o?void 0:o.audioInputDeviceId)&&void 0!==c?c:g.getItem(te),[k,$]=a(()=>g.getItem(ae));t(()=>{if(!u)return;let e=!1;const n=()=>x(void 0,void 0,void 0,function*(){let n;try{n=yield navigator.mediaDevices.enumerateDevices()}catch(e){return}if(e)return;const t=n.filter(e=>"audioinput"===e.kind),a=n.filter(e=>"audiooutput"===e.kind);b(t.length>0&&t.every(e=>""===e.label)),m(le(t)),h(d?le(a):[])});n();const t=()=>{n()};return navigator.mediaDevices.addEventListener("devicechange",t),()=>{e=!0,navigator.mediaDevices.removeEventListener("devicechange",t)}},[u,d,i]),t(()=>{o&&k&&o.setAudioOutputDevice(k)},[o,k]),t(()=>{const e=g.getItem(te);o&&e&&!o.audioInputDeviceId&&o.seedAudioInputDevice(e)},[o]),t(()=>{if(!i)return;const e=()=>E(!0),n=()=>w(e=>e+1);return i.on("audioInputLost",e),i.on("audioInputChanged",n),()=>{i.off("audioInputLost",e),i.off("audioInputChanged",n),E(!1)}},[i]);const N=s(e=>{const n=()=>w(e=>e+1);null==o||o.setAudioInputDevice(e).then(()=>{E(!1),e?g.setItem(te,e):g.removeItem(te),n()},n)},[o]),A=s(e=>{$(e),e?g.setItem(ae,e):g.removeItem(ae),null==o||o.setAudioOutputDevice(e)},[o]),S={inputs:p,outputs:f,inputDeviceId:C,outputDeviceId:k,selectInputDevice:N,selectOutputDevice:A,outputSelectionSupported:d,enumerationSupported:u,labelsHidden:v,inputLost:y};return e.createElement(re.Provider,{value:S},n)};function ce(){const e=o(re);return e||{inputs:[],outputs:[],inputDeviceId:null,outputDeviceId:null,selectInputDevice:()=>{},selectOutputDevice:()=>{},outputSelectionSupported:!1,enumerationSupported:!1,labelsHidden:!1,inputLost:!1}}const oe=[440,480];class ie{constructor(){this.ctx=null,this.gain=null,this.oscillators=[],this.cadenceTimer=null,this.started=!1,this.nextCadenceTime=0,this.sinkId=null}get isPlaying(){return this.started}setSinkId(e){this.sinkId=e;const n=this.ctx;n&&"function"==typeof n.setSinkId&&Promise.resolve(n.setSinkId(null!=e?e:"")).catch(()=>{})}start(){if(this.started)return;const e=function(){var e,n;const t=globalThis;return null!==(n=null!==(e=t.AudioContext)&&void 0!==e?e:t.webkitAudioContext)&&void 0!==n?n:null}();if(!e)return;let n;try{n=new e(this.sinkId?{sinkId:this.sinkId}:void 0)}catch(t){this.sinkId=null;try{n=new e}catch(e){return}}this.ctx=n,"suspended"===n.state&&"function"==typeof n.resume&&Promise.resolve(n.resume()).catch(()=>{});try{const e=n.createGain();e.gain.value=0,e.connect(n.destination),this.gain=e;for(const t of oe){const a=n.createOscillator();a.frequency.value=t,a.connect(e),a.start(),this.oscillators.push(a)}this.nextCadenceTime=n.currentTime,this.scheduleCadenceAhead(),this.cadenceTimer=setInterval(()=>this.scheduleCadenceAhead(),6e3),this.started=!0}catch(e){this.teardown()}}stop(){this.started&&(this.started=!1,this.teardown())}teardown(){this.cadenceTimer&&(clearInterval(this.cadenceTimer),this.cadenceTimer=null);for(const e of this.oscillators)try{e.stop(),e.disconnect()}catch(e){}if(this.oscillators=[],this.gain){try{this.gain.disconnect()}catch(e){}this.gain=null}const e=this.ctx;this.ctx=null,e&&"function"==typeof e.close&&Promise.resolve(e.close()).catch(()=>{})}scheduleCadenceAhead(){const e=this.ctx,n=this.gain;if(!e||!n)return;for(;this.nextCadenceTime+6<=e.currentTime;)this.nextCadenceTime+=6;const t=e.currentTime+12;for(;this.nextCadenceTime<t;)n.gain.setValueAtTime(.14,this.nextCadenceTime),n.gain.setValueAtTime(0,this.nextCadenceTime+2),this.nextCadenceTime+=6}}const de=Q,ue=({existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:s,iceServers:c,emergencyAddressId:d,autoConnect:u=!0,appearance:p,locale:m=h,formatting:g,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:y,onCallEnded:x,onError:E,children:w})=>{var C,k,$;const N=`ds-softphone-${i().replace(/[:]/g,"")}`,A=l(()=>({scope:N}),[N]),S=o(v),[I,T]=a(()=>null==S?void 0:S.dialstack.getAppearance()),z=null!=p?p:I,O=`${null!==(C=null==z?void 0:z.theme)&&void 0!==C?C:""}|${JSON.stringify(null!==(k=null==z?void 0:z.variables)&&void 0!==k?k:{})}`,D=null!==($=null==g?void 0:g.defaultCountry)&&void 0!==$?$:"US",M=l(()=>function(e,n="ds-softphone"){const t=K;return`\n .${n} {\n --dsd-bg: ${e.background};\n --dsd-surface: ${e.surface};\n --dsd-surface-active: ${e.surfaceActive};\n --dsd-text: ${e.text};\n --dsd-text-secondary: ${e.textSecondary};\n --dsd-border: ${e.border};\n --dsd-accent: ${e.accent};\n --dsd-success: ${e.success};\n --dsd-danger: ${e.danger};\n --dsd-warning: ${e.warning};\n --dsd-on-accent: ${e.onAccent};\n font-family: var(--ds-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);\n background: var(--dsd-bg);\n color: var(--dsd-text);\n width: 100%;\n max-width: ${t.maxWidth}px;\n margin: 0 auto;\n border-radius: ${t.radius}px;\n padding: clamp(12px, 4vw, 24px);\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n .${n} * { box-sizing: border-box; }\n /* Every exported piece (DialPad, OngoingCall, IncomingCall, IncomingStack,\n IncomingCallCard, EmergencyBanner) self-wraps in its own \`.ds-softphone\`\n so it renders correctly standalone — a host can drop any one of them under\n the provider without hand-supplying scoped wrappers. When one such piece is\n composed INSIDE another (e.g. IncomingStack renders IncomingCallCards, or\n <Softphone> stacks several screens), the inner \`.ds-softphone\` would\n otherwise paint a second card box. Collapse any nested wrapper so only the\n outermost is the padded card. */\n .${n} .ds-softphone { padding: 0; background: none; max-width: none; margin: 0; }\n .${n} .ds-screen { display: flex; flex-direction: column; gap: clamp(12px, 3vw, 20px); }\n\n .${n} .ds-chip {\n align-self: center;\n font-size: 12px;\n font-weight: 600;\n padding: 4px 12px;\n border-radius: 999px;\n letter-spacing: 0.02em;\n }\n .${n} .ds-chip-spacer { visibility: hidden; }\n .${n} .ds-chip-pending { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-off { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-error { background: color-mix(in srgb, var(--dsd-danger) 16%, transparent); color: var(--dsd-danger); }\n .${n} .ds-call-error {\n display: flex;\n align-items: center;\n gap: 8px;\n max-width: 100%;\n text-align: left;\n }\n .${n} .ds-call-error-dismiss {\n border: none;\n background: transparent;\n color: inherit;\n cursor: pointer;\n font-size: 12px;\n line-height: 1;\n padding: 0;\n }\n\n /* The number must center on the keypad's axis. The backspace flanks the input\n on the right, so an equal-width invisible spacer flanks it on the left — the\n input then centers between two 40px flanks and reads as truly centered (a\n lone backspace would optically pull the number left even when the box math\n centers). */\n .${n} .ds-display { display: flex; align-items: center; min-height: 56px; gap: 8px; }\n .${n} .ds-display-spacer { width: 40px; flex: none; }\n .${n} .ds-destination {\n flex: 1; min-width: 0;\n font-size: clamp(24px, 7vw, 32px);\n font-weight: 500;\n text-align: center;\n border: none; outline: none; background: transparent;\n color: var(--dsd-text);\n letter-spacing: 0.02em;\n }\n .${n} .ds-destination::placeholder { color: var(--dsd-text-secondary); opacity: 0.7; }\n .${n} .ds-backspace {\n flex: none;\n border: none; background: transparent; cursor: pointer;\n font-size: 22px; color: var(--dsd-text-secondary);\n width: 40px; height: 40px; border-radius: 999px;\n }\n .${n} .ds-backspace:hover { background: var(--dsd-surface); color: var(--dsd-text); }\n\n .${n} .ds-keypad {\n display: grid; grid-template-columns: repeat(3, 1fr);\n gap: ${t.keyGap}px;\n justify-items: center;\n }\n .${n} .ds-key {\n display: flex; flex-direction: column; align-items: center; justify-content: center;\n width: 100%; aspect-ratio: 1 / 1; max-width: 84px;\n border: none; border-radius: 999px;\n background: var(--dsd-surface); color: var(--dsd-text);\n cursor: pointer; gap: 2px;\n transition: background-color 0.12s ease, transform 0.06s ease;\n -webkit-tap-highlight-color: transparent;\n user-select: none;\n }\n .${n} .ds-key:hover { background: var(--dsd-surface-active); }\n .${n} .ds-key:active { transform: scale(0.94); }\n .${n} .ds-key-digit { font-size: clamp(22px, 6vw, 28px); font-weight: 500; line-height: 1; }\n .${n} .ds-key-letters {\n font-size: 10px; font-weight: 600; letter-spacing: 0.12em;\n color: var(--dsd-text-secondary); min-height: 12px;\n }\n .${n} .ds-keypad-dtmf .ds-key { aspect-ratio: auto; padding: 10px 0; max-width: 72px; }\n\n .${n} .ds-actions { display: flex; justify-content: center; gap: clamp(24px, 12vw, 72px); }\n .${n} .ds-actions-incoming { justify-content: space-evenly; }\n .${n} .ds-action {\n width: ${t.actionButtonSize}px; height: ${t.actionButtonSize}px;\n border: none; border-radius: 999px; cursor: pointer;\n display: flex; align-items: center; justify-content: center;\n color: var(--dsd-on-accent);\n transition: transform 0.06s ease, filter 0.12s ease;\n -webkit-tap-highlight-color: transparent;\n }\n .${n} .ds-action svg { width: 46%; height: 46%; }\n .${n} .ds-action:active { transform: scale(0.92); }\n .${n} .ds-action:disabled { opacity: 0.4; cursor: not-allowed; }\n .${n} .ds-call, .${n} .ds-answer { background: var(--dsd-success); }\n .${n} .ds-hangup, .${n} .ds-decline { background: var(--dsd-danger); }\n .${n} .ds-call:not(:disabled):hover, .${n} .ds-answer:hover,\n .${n} .ds-hangup:hover, .${n} .ds-decline:hover { filter: brightness(1.06); }\n\n .${n} .ds-peer { text-align: center; display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-peer-name { font-size: clamp(22px, 6vw, 28px); font-weight: 600; word-break: break-word; }\n .${n} .ds-peer-number { font-size: 15px; color: var(--dsd-text-secondary); }\n .${n} .ds-callstate { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 6px; }\n .${n} .ds-callstate-text { font-size: 14px; color: var(--dsd-text-secondary); }\n .${n} .ds-duration { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 500; }\n\n .${n} .ds-incoming-label {\n text-align: center; font-size: 13px; font-weight: 600;\n letter-spacing: 0.08em; text-transform: uppercase; color: var(--dsd-text-secondary);\n }\n .${n} .ds-incoming-pulse {\n width: 12px; height: 12px; border-radius: 999px; margin: 4px auto;\n background: var(--dsd-success);\n box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 60%, transparent);\n animation: ds-pulse 1.6s infinite;\n }\n @keyframes ds-pulse {\n 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 50%, transparent); }\n 70% { box-shadow: 0 0 0 16px transparent; }\n 100% { box-shadow: 0 0 0 0 transparent; }\n }\n\n .${n} .ds-controls {\n display: flex; flex-wrap: wrap; justify-content: center;\n gap: 8px 20px;\n max-width: ${3*(t.controlButtonSize+12)+40}px;\n margin: 0 auto;\n }\n .${n} .ds-controls > * { flex: 0 0 ${t.controlButtonSize+12}px; }\n .${n} .ds-control {\n display: flex; flex-direction: column; align-items: center; gap: 6px;\n border: none; background: transparent; cursor: pointer;\n color: var(--dsd-text); font-family: inherit;\n }\n .${n} .ds-control-glyph {\n width: ${t.controlButtonSize}px; height: ${t.controlButtonSize}px;\n border-radius: 999px; background: var(--dsd-surface);\n display: flex; align-items: center; justify-content: center;\n transition: background-color 0.12s ease;\n }\n .${n} .ds-control-glyph svg { width: 42%; height: 42%; }\n .${n} .ds-control:hover:not(:disabled) .ds-control-glyph { background: var(--dsd-surface-active); }\n .${n} .ds-control-on .ds-control-glyph { background: var(--dsd-accent); color: var(--dsd-on-accent); }\n .${n} .ds-control-label { font-size: 12px; color: var(--dsd-text-secondary); }\n .${n} .ds-control-on .ds-control-label { color: var(--dsd-text); }\n .${n} .ds-control:disabled { cursor: not-allowed; opacity: 0.4; }\n\n .${n} .ds-dtmf { display: flex; flex-direction: column; gap: 10px; }\n .${n} .ds-dtmf-readout {\n text-align: center; font-size: 22px; min-height: 28px;\n font-variant-numeric: tabular-nums; letter-spacing: 0.08em;\n }\n .${n} .ds-transfer { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-transfer-input {\n flex: 1; min-width: 0; padding: 12px 14px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 16px; outline: none;\n }\n .${n} .ds-transfer-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-transfer-actions { display: flex; gap: 8px; }\n .${n} .ds-transfer-send {\n flex: 1; border: none; border-radius: ${t.radius}px; padding: 12px 18px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-transfer-send:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-transfer-send-secondary {\n background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} .ds-devices {\n display: flex; flex-direction: column; gap: 10px;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+40}px; margin: 0 auto;\n }\n .${n} .ds-device-row { display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-device-label { font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-select {\n width: 100%; padding: 10px 12px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text);\n font-size: 14px; font-family: inherit; outline: none;\n }\n .${n} .ds-device-select:focus { border-color: var(--dsd-accent); }\n .${n} .ds-device-select:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-device-hint { margin: 0; font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-alert { font-size: 12px; color: var(--dsd-danger); }\n\n /* Attended-transfer banner (layered over the normal in-call view): the other\n transfer leg as a switch card + the Cancel/Complete actions. */\n .${n} .ds-transfer-banner { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-consult-held { opacity: 0.7; }\n .${n} .ds-consult-actions { display: flex; gap: 8px; }\n .${n} .ds-consult-actions .ds-e911-btn { flex: 1; }\n\n /* Multi-call + transfer: switchable held-call cards. Clickable (button reset)\n to switch focus to that call; the cursor + hover signal it's actionable. */\n .${n} .ds-held-calls { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-held-call {\n display: block; width: 100%; cursor: pointer; text-align: center;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n padding: 12px 14px;\n background: var(--dsd-surface); color: var(--dsd-text);\n font-family: inherit;\n }\n .${n} .ds-held-call:hover { opacity: 1; border-color: var(--dsd-accent); }\n /* A conference is ONE conversation with two people. The participants sit in a\n single bordered block under one heading and one timer, so they read as\n joined rather than as an active call with another stacked above it. */\n .${n} .ds-conference-parties {\n display: flex; flex-direction: column; align-items: center; gap: 2px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n padding: 10px 14px; margin: 6px 0;\n background: var(--dsd-surface);\n }\n\n /* Multi-call: composite layout — the in-call screen with the ringing\n call-waiting card(s) as a compact banner ABOVE it. The banner is in normal\n flow (not absolutely positioned) so it reserves its own space and never\n overlaps the in-call peer/controls below. (Idle inbound is a dedicated\n screen, not this banner.) */\n .${n}.ds-softphone-layout {\n display: flex; flex-direction: column; gap: 12px;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-softphone-layout > .ds-softphone { padding: 0; background: none; }\n .${n} .ds-incoming-overlay { flex: none; }\n\n /* Batteries-included dial screen: the E911 banner above the dial pad, each in\n its own scope wrapper. This outer wrapper is the single padded card; the\n inner dial pad's own .ds-softphone must not add a second card box. The\n banner (a direct .ds-e911 child) carries its own spacing. */\n .${n}.ds-dial-screen {\n display: flex; flex-direction: column;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-dial-screen > .ds-softphone { padding: 0; background: none; }\n .${n} .ds-incoming-stack { display: flex; flex-direction: column; gap: 8px; }\n\n /* One ringing call's card. Full-size inside the dedicated incoming screen;\n the compact variant (stacked / call-waiting overlay) shrinks it and puts\n the answer/decline buttons inline so it takes less space. */\n .${n} .ds-incoming-card {\n display: flex; flex-direction: column; gap: clamp(12px, 3vw, 20px);\n align-items: center; text-align: center;\n }\n .${n} .ds-incoming-card-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n .${n} .ds-incoming-card-compact {\n flex-direction: row; gap: 12px; align-items: center; text-align: left;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-surface); box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);\n }\n .${n} .ds-incoming-card-compact .ds-incoming-card-info { flex: 1; min-width: 0; }\n .${n} .ds-incoming-card-compact .ds-incoming-label { font-size: 11px; }\n /* Shrink the peer name/number in a compact card — otherwise they inherit the\n full-screen in-call sizes (clamp up to 28px) and overflow the small overlay\n card, colliding with the call behind it. Truncate rather than wrap. */\n .${n} .ds-incoming-card-compact .ds-peer-name {\n font-size: 15px; font-weight: 600; line-height: 1.2;\n white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-peer-number {\n font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-actions-incoming { margin: 0; gap: 8px; flex: none; }\n .${n} .ds-incoming-card-compact .ds-action { width: 44px; height: 44px; }\n\n /* EmergencyBanner's self-wrap is only a scope carrier — never its own card\n box. The visible chrome is the .ds-e911 prompt inside; the wrapper stays\n transparent/paddingless in every context (standalone or composed), and its\n trailing margin comes from .ds-e911 itself. */\n .${n}.ds-e911-root { padding: 0; background: none; max-width: none; margin: 0; }\n .${n} .ds-e911 {\n margin-bottom: 12px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n overflow: hidden; background: var(--dsd-surface);\n }\n .${n} .ds-e911-toggle {\n display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;\n padding: 10px 12px; border: none; cursor: pointer;\n background: color-mix(in srgb, var(--dsd-warning) 18%, transparent);\n color: color-mix(in srgb, var(--dsd-warning) 60%, var(--dsd-text));\n font-family: inherit; font-size: 13px;\n font-weight: 600; text-align: center;\n }\n .${n} .ds-e911-toggle svg { width: 16px; height: 16px; flex: none; }\n .${n} .ds-e911-label { flex: 0 1 auto; text-align: center; }\n .${n} .ds-e911-chevron { transition: transform 0.15s ease; }\n .${n} .ds-e911-open .ds-e911-chevron { transform: rotate(180deg); }\n .${n} .ds-e911-body {\n display: flex; flex-direction: column; gap: 8px;\n padding: 12px; border-top: 1px solid var(--dsd-border);\n }\n .${n} .ds-e911-hint { font-size: 12px; color: var(--dsd-text-secondary); margin: 0; }\n /* Saved-address choice buttons ("Are you here?") */\n .${n} .ds-e911-choice {\n display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); cursor: pointer;\n font-family: inherit; font-size: 13px;\n }\n .${n} .ds-e911-choice:hover { border-color: var(--dsd-accent); }\n .${n} .ds-e911-choice svg { width: 14px; height: 14px; flex: none; color: var(--dsd-success); }\n .${n} .ds-e911-choice-addr { flex: 1; min-width: 0; }\n .${n} .ds-e911-choice-cta { font-size: 12px; font-weight: 600; color: var(--dsd-accent); }\n .${n} .ds-e911-row { display: flex; gap: 8px; }\n .${n} .ds-e911-field { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }\n .${n} .ds-e911-field-sm { flex: none; width: 88px; }\n .${n} .ds-e911-field label { font-size: 11px; color: var(--dsd-text-secondary); }\n .${n} .ds-e911-input {\n padding: 8px 10px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 14px; outline: none;\n font-family: inherit; width: 100%;\n }\n .${n} .ds-e911-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-e911-error { font-size: 12px; color: var(--dsd-danger); margin: 0; }\n .${n} .ds-e911-actions { display: flex; gap: 8px; }\n .${n} .ds-e911-btn {\n flex: 1; border: none; border-radius: 8px; padding: 10px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-e911-btn:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-e911-btn-secondary {\n flex: none; background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} button:focus-visible, .${n} input:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px color-mix(in srgb, var(--dsd-accent) 45%, transparent);\n }\n `}(J(z),N),[O,N]);return e.createElement(ee,{existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:s,iceServers:c,emergencyAddressId:d,autoConnect:u,appearance:z,locale:m,defaultCountry:D,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:y,onCallEnded:x,onError:E,extra:A},S&&e.createElement(ge,{dialstack:S.dialstack,onChange:T}),e.createElement("style",null,M),e.createElement(se,null,w,e.createElement(pe,null),e.createElement(me,{onError:E})))},pe=()=>{const{incomingRinging:e}=fe(),{outputDeviceId:a}=ce(),r=n(null);return null===r.current&&(r.current=new ie),t(()=>{var e;null===(e=r.current)||void 0===e||e.setSinkId(a)},[a]),t(()=>{const n=r.current;if(n)return e?n.start():n.stop(),()=>n.stop()},[e]),null},me=({onError:a})=>{const{activeCall:r,conferenceAudio:l}=fe(),{outputDeviceId:s}=ce(),c=n(null);return t(()=>{const e=c.current;e&&"function"==typeof e.setSinkId&&e.setSinkId(null!=s?s:"").catch(()=>{})},[s,r]),t(()=>{const e=c.current;if(!e)return;if(!r)return void(e.srcObject=null);e.srcObject=null!=l?l:r.remoteMediaStream;const n=r;let t=!1;const s=n=>{e.play().then(()=>{t=!0},e=>{const r=null==e?void 0:e.name;n&&!t&&"AbortError"!==r&&(null==a||a({code:"audio_playback_blocked",message:"Could not play call audio — tap the call to enable sound."}))})};s("active"===n.state);const o=()=>s(!0);return n.on("answered",o),()=>{n.off("answered",o)}},[r,l,a]),e.createElement("audio",{ref:c,autoPlay:!0})},ge=({dialstack:e,onChange:n})=>{const r=function(e){const[n,r]=a(()=>e.getAppearance());return t(()=>{if("undefined"==typeof document)return;const n=document.createElement("div"),t=e=>{const n=e.detail;r(null==n?void 0:n.appearance)};return n.addEventListener("dialstack-appearance-update",t),e.addAppearanceTarget(n),()=>{e.removeAppearanceTarget(n),n.removeEventListener("dialstack-appearance-update",t)}},[e]),n}(e);return t(()=>{n(r)},[r,n]),null},fe=()=>ne(),he=()=>{const{activeCall:e,actions:n}=fe();return{activeCall:e,actions:n}},ve=()=>{const{incomingCalls:e}=fe();return function(e){var n;return null!==(n=e.find(E))&&void 0!==n?n:null}(e)},be={phone:{path:"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"},hangup:{path:"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",transform:"rotate(135 12 12)"},mic:{path:"M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11h-2z"},micOff:{path:"M19 11h-1.7a5.6 5.6 0 0 1-.34 1.6l1.22 1.22A7 7 0 0 0 19 11zM4.27 3 3 4.27 9 10.27V11a3 3 0 0 0 4.42 2.65l1.05 1.05A4.96 4.96 0 0 1 12 16a5 5 0 0 1-5-5H5a7 7 0 0 0 6 6.92V21h2v-3.08c.5-.07.98-.2 1.43-.39L19.73 21 21 19.73 4.27 3zM15 5a3 3 0 0 0-6-.09l6 6V5z"},pause:{path:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"},keypad:{path:"M5 3a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 10a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 17a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4z"},transfer:{path:"M16 1l4 4-4 4V6H9V4h7V1zM8 23l-4-4 4-4v3h7v2H8v3z"},location:{path:"M12 2a7 7 0 0 0-7 7c0 5.25 7 13 7 13s7-7.75 7-13a7 7 0 0 0-7-7zm0 9.5A2.5 2.5 0 1 1 12 6.5a2.5 2.5 0 0 1 0 5z"},chevronDown:{path:"M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z"},speaker:{path:"M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 7.97v8.05A4.47 4.47 0 0 0 16.5 12zM14 2.23v2.06a7.5 7.5 0 0 1 0 15.42v2.06a9.5 9.5 0 0 0 0-19.54z"},addCall:{path:"M15 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zM6 8V5H4v3H1v2h3v3h2v-3h3V8H6z"},merge:{path:"M17 20.41 18.41 19 15 15.59 13.59 17 17 20.41zM7.5 8H11v5.59L5.59 19 7 20.41l6-6V8h3.5L12 3.5 7.5 8z"}},ye=({glyph:n})=>e.createElement("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},e.createElement("path",{d:n.path,transform:n.transform})),xe=()=>{const{lastError:n,clearError:t,t:a}=fe();return n?e.createElement("div",{className:"ds-chip ds-chip-error ds-call-error",role:"alert"},e.createElement("span",null,a(_(n.code))),e.createElement("button",{type:"button",className:"ds-call-error-dismiss","aria-label":a("dismiss"),onClick:t},"✕")):null},Ee=({autoFocusDestination:r=!1})=>{const{connection:l,placeCall:s,emergency:c,t:o,scope:i}=fe(),[d,u]=a(""),{onType:p,onPasteText:m}=W(u),g=n(null);t(()=>{var e;r&&(null===(e=g.current)||void 0===e||e.focus())},[r]);const f=function(e,n,t){return"connected"===e&&n.length>0&&!t}(l,d,c.submitting);return e.createElement("div",{className:`${i} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-dial"},e.createElement(we,null),e.createElement(xe,null),e.createElement("div",{className:"ds-display"},d.length>0&&e.createElement("span",{className:"ds-display-spacer","aria-hidden":"true"}),e.createElement("input",{ref:g,className:"ds-destination",type:"tel",inputMode:"tel",value:d,placeholder:o("destinationPlaceholder"),"aria-label":o("destinationPlaceholder"),autoComplete:"off",onChange:e=>p(e.target.value),onPaste:e=>{e.preventDefault(),m(e.clipboardData.getData("text"))},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),f&&s(d))}}),d.length>0&&e.createElement("button",{type:"button",className:"ds-backspace","aria-label":o("backspace"),onClick:()=>u(e=>e.slice(0,-1))},"⌫")),e.createElement("div",{className:"ds-keypad",role:"group","aria-label":o("title")},Y.map(({digit:n,letters:t})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":`${n}${t?" "+t:""}`,onClick:()=>u(e=>e+n)},e.createElement("span",{className:"ds-key-digit"},n),e.createElement("span",{className:"ds-key-letters"},t||" ")))),e.createElement("div",{className:"ds-actions"},e.createElement("button",{type:"button",className:"ds-action ds-call","aria-label":o("call"),disabled:!f,onClick:()=>{s(d)}},e.createElement(ye,{glyph:be.phone})))))},we=()=>{const{connection:n,t:t}=fe();switch(n){case"connecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("connecting"));case"reconnecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("reconnecting"));case"disconnected":return e.createElement("div",{className:"ds-chip ds-chip-off",role:"status"},t("disconnected"));case"error":return e.createElement("div",{className:"ds-chip ds-chip-error",role:"status"},t("connectionError"));default:return e.createElement("div",{className:"ds-chip ds-chip-spacer","aria-hidden":"true"})}},Ce={alabama:"AL",alaska:"AK",arizona:"AZ",arkansas:"AR",california:"CA",colorado:"CO",connecticut:"CT",delaware:"DE","district of columbia":"DC",florida:"FL",georgia:"GA",hawaii:"HI",idaho:"ID",illinois:"IL",indiana:"IN",iowa:"IA",kansas:"KS",kentucky:"KY",louisiana:"LA",maine:"ME",maryland:"MD",massachusetts:"MA",michigan:"MI",minnesota:"MN",mississippi:"MS",missouri:"MO",montana:"MT",nebraska:"NE",nevada:"NV","new hampshire":"NH","new jersey":"NJ","new mexico":"NM","new york":"NY","north carolina":"NC","north dakota":"ND",ohio:"OH",oklahoma:"OK",oregon:"OR",pennsylvania:"PA","rhode island":"RI","south carolina":"SC","south dakota":"SD",tennessee:"TN",texas:"TX",utah:"UT",vermont:"VT",virginia:"VA",washington:"WA","west virginia":"WV",wisconsin:"WI",wyoming:"WY","puerto rico":"PR",guam:"GU","u.s. virgin islands":"VI","american samoa":"AS","northern mariana islands":"MP",alberta:"AB","british columbia":"BC",manitoba:"MB","new brunswick":"NB","newfoundland and labrador":"NL","nova scotia":"NS","northwest territories":"NT",nunavut:"NU",ontario:"ON","prince edward island":"PE",quebec:"QC",saskatchewan:"SK",yukon:"YT"};function ke(e){const n=e.trim(),t=Ce[n.toLowerCase()];return t||(/^[a-z]{2}$/i.test(n)?n.toUpperCase():n)}const $e={address_number:"",street:"",unit:"",city:"",state:"",postal_code:""},Ne=()=>{const{emergency:n,emergencyManagedByHost:t,activeCall:r,t:l,scope:s}=fe(),[c,o]=a(!1),[i,d]=a(!1),[u,p]=a($e);if(t||n.loading||n.bound||r)return null;const m=e=>n=>p(t=>Object.assign(Object.assign({},t),{[e]:n.target.value}));return e.createElement("div",{className:`${s} ds-softphone ds-e911-root`},e.createElement("div",{className:"ds-e911 "+(c?"ds-e911-open":"")},e.createElement("button",{type:"button",className:"ds-e911-toggle","aria-expanded":c,onClick:()=>o(e=>!e)},e.createElement("span",null,e.createElement(ye,{glyph:be.location})),e.createElement("span",{className:"ds-e911-label"},l("emergencyPrompt")),e.createElement("span",{className:"ds-e911-chevron"},e.createElement(ye,{glyph:be.chevronDown}))),c&&e.createElement("div",{className:"ds-e911-body"},e.createElement("p",{className:"ds-e911-hint"},l("emergencyHint")),!i&&n.savedAddresses.map(t=>e.createElement("button",{key:t.id,type:"button",className:"ds-e911-choice",disabled:n.submitting,onClick:()=>{return e=t.id,void n.confirm(e).then(()=>o(!1)).catch(()=>{});var e}},e.createElement(ye,{glyph:be.location}),e.createElement("span",{className:"ds-e911-choice-addr"},[t.address.address_number,t.address.street,t.address.city,t.address.state,t.address.postal_code].filter(Boolean).join(" ")),e.createElement("span",{className:"ds-e911-choice-cta"},l("emergencyConfirm")))),!i&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>d(!0)},l("emergencyNewLocation")),i&&e.createElement("form",{className:"ds-e911-body",style:{padding:0,borderTop:"none"},onSubmit:e=>{e.preventDefault(),n.create(Object.assign(Object.assign({},u),{state:ke(u.state),unit:u.unit||void 0})).then(()=>{o(!1),d(!1)}).catch(()=>{})}},e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${s}-ea-num`},l("emergencyNumber")),e.createElement("input",{id:`${s}-ea-num`,className:"ds-e911-input",value:u.address_number,onChange:m("address_number")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-street`},l("emergencyStreet")),e.createElement("input",{id:`${s}-ea-street`,className:"ds-e911-input",value:u.street,onChange:m("street"),required:!0}))),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-unit`},l("emergencyUnit")),e.createElement("input",{id:`${s}-ea-unit`,className:"ds-e911-input",value:u.unit,onChange:m("unit")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-city`},l("emergencyCity")),e.createElement("input",{id:`${s}-ea-city`,className:"ds-e911-input",value:u.city,onChange:m("city"),required:!0})),e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${s}-ea-state`},l("emergencyState")),e.createElement("input",{id:`${s}-ea-state`,className:"ds-e911-input",value:u.state,onChange:m("state"),required:!0})),e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${s}-ea-zip`},l("emergencyPostalCode")),e.createElement("input",{id:`${s}-ea-zip`,className:"ds-e911-input",value:u.postal_code,onChange:m("postal_code"),required:!0}))),n.error&&e.createElement("p",{className:"ds-e911-error"},n.error),e.createElement("div",{className:"ds-e911-actions"},n.savedAddresses.length>0&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>d(!1)},l("emergencyBack")),e.createElement("button",{type:"submit",className:"ds-e911-btn",disabled:n.submitting},n.submitting?l("emergencySaving"):l("emergencySave")))))))},Ae=({call:n,compact:t=!1})=>{const{answerCall:a,actions:r,t:l,displayNumber:s}=fe(),c=$(n),o=N(n)||s(c)||l("unknownCaller");return e.createElement("div",{className:"ds-incoming-card "+(t?"ds-incoming-card-compact":"")},e.createElement("div",{className:"ds-incoming-card-info"},e.createElement("div",{className:"ds-incoming-label"},l("incomingCall")),e.createElement("div",{className:"ds-peer-name"},o),N(n)&&e.createElement("div",{className:"ds-peer-number"},s(c))),e.createElement("div",{className:"ds-actions ds-actions-incoming"},e.createElement("button",{type:"button",className:"ds-action ds-decline","aria-label":l("decline"),onClick:()=>r.callActionsFor(n).reject()},e.createElement(ye,{glyph:be.hangup})),e.createElement("button",{type:"button",className:"ds-action ds-answer","aria-label":l("answer"),onClick:()=>a(n)},e.createElement(ye,{glyph:be.phone}))))},Se=()=>{const{incomingCalls:n,scope:t}=fe(),a=n[0];return a?e.createElement("div",{className:`${t} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incoming"},e.createElement(Ae,{call:a}))):null},Ie=({compact:n})=>{const{incomingCalls:t,scope:a}=fe();if(0===t.length)return null;const r=null!=n?n:t.length>1;return e.createElement("div",{className:`${a} ds-softphone`},e.createElement("div",{className:"ds-incoming-stack"},t.map(n=>e.createElement(Ae,{key:n.id,call:n,compact:r}))))},Te=({label:n,glyph:t,on:a=!1,disabled:r=!1,onClick:l})=>e.createElement("button",{type:"button",className:"ds-control "+(a?"ds-control-on":""),"aria-pressed":a,"aria-label":n,disabled:r,onClick:l},e.createElement("span",{className:"ds-control-glyph"},e.createElement(ye,{glyph:t})),e.createElement("span",{className:"ds-control-label"},n)),ze=()=>{const{t:n}=fe(),{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:l,selectInputDevice:s,selectOutputDevice:c,outputSelectionSupported:o,enumerationSupported:i,labelsHidden:d,inputLost:u}=ce();return e.createElement("div",{className:"ds-devices",role:"group"},u&&e.createElement("div",{className:"ds-device-alert",role:"alert"},n("audioMicrophoneLost")),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},n("audioMicrophone")),e.createElement("select",{className:"ds-device-select","aria-label":n("audioMicrophone"),value:null!=r?r:"",onChange:e=>s(e.target.value||null)},e.createElement("option",{value:""},n("audioSystemDefault")),t.map(t=>e.createElement("option",{key:t.deviceId,value:t.deviceId},t.label||n("audioUnnamedDevice"))))),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},n("audioSpeaker")),e.createElement("select",{className:"ds-device-select","aria-label":n("audioSpeaker"),value:null!=l?l:"",disabled:!o,onChange:e=>c(e.target.value||null)},e.createElement("option",{value:""},n("audioSystemDefault")),a.map(t=>e.createElement("option",{key:t.deviceId,value:t.deviceId},t.label||n("audioUnnamedDevice"))))),!i&&e.createElement("p",{className:"ds-device-hint"},n("audioDevicesUnsupported")),!o&&e.createElement("p",{className:"ds-device-hint"},n("audioSpeakerUnsupported")),d&&e.createElement("p",{className:"ds-device-hint"},n("audioLabelsHidden")))},Oe=()=>{var n;const{activeCall:r,actions:l,overlays:s,duration:c,consultCall:o,transferOriginal:i,heldCalls:d,incomingCalls:u,switchToCall:p,startAttendedTransfer:m,completeAttendedTransfer:g,cancelAttendedTransfer:f,placeCall:h,calls:v,mergedCalls:b,isMerged:y,canMerge:x,mergeCalls:E,splitMerge:w,hangupConference:k,holdConference:A,t:S,displayNumber:I,scope:T}=fe(),{showKeypad:z,showTransfer:O,showDevices:D,showAddCall:M}=s,[P,_]=a(""),[B,H]=a(""),[R,L]=a(""),{onType:U,onPasteText:V}=W(H),{onType:F,onPasteText:K}=W(L),q=null!==(n=null==r?void 0:r.id)&&void 0!==n?n:null;if(t(()=>{_(""),H(""),L("")},[q]),!r)return null;const G=$(r),J=N(r),Q=C(r),X=J||I(G)||S("unknownCaller"),Z=r.canSendDtmf,ee=null!==o&&null!==i,ne=ee&&(r===o||r===i),te=ne?r===o?i:o:null,ae=ne&&null!==o&&o.isConnected,re=d.filter(e=>e!==te&&!b.includes(e)),le=d.length+u.length,se=!ee&&!y&&0===le,ce=y&&b.some(e=>"held"===e.state),oe=v.length<4,ie=oe?R:"";return e.createElement("div",{className:`${T} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incall"},ne&&te&&e.createElement("div",{className:"ds-transfer-banner"},(()=>{const n=$(te),t=N(te)||I(n)||S("unknownCaller");return e.createElement("button",{type:"button",className:"ds-held-call ds-consult-held","aria-label":`${S("switchToCall")}: ${t}`,onClick:()=>p(te)},e.createElement("div",{className:"ds-peer-name"},t),e.createElement("div",{className:"ds-callstate-text"},S("transferOriginalOnHold")))})(),e.createElement("div",{className:"ds-consult-actions"},e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:f},S("cancel")),e.createElement("button",{type:"button",className:"ds-e911-btn",disabled:!ae,onClick:g},S("transferComplete")))),re.length>0&&e.createElement("div",{className:"ds-held-calls",role:"group","aria-label":S("heldCallsLabel")},re.map(n=>{const t=$(n),a=N(n)||I(t)||S("unknownCaller");return e.createElement("button",{type:"button",key:n.id,className:"ds-held-call ds-consult-held","aria-label":`${S("switchToCall")}: ${a}`,onClick:()=>p(n)},e.createElement("div",{className:"ds-peer-name"},a),e.createElement("div",{className:"ds-callstate-text"},S("heldCallsLabel")))})),y?e.createElement("div",{className:"ds-peer ds-peer-conference"},e.createElement("div",{className:"ds-callstate-text"},S("conferenceLabel")),e.createElement("div",{className:"ds-conference-parties"},b.map(n=>e.createElement("div",{key:n.id,className:"ds-peer-name"},N(n)||I($(n))||S("unknownCaller")))),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-duration"},c))):e.createElement("div",{className:"ds-peer"},e.createElement("div",{className:"ds-peer-name"},X),J&&e.createElement("div",{className:"ds-peer-number"},I(G)),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-callstate-text"},S(j(r.state))),"active"===r.state&&e.createElement("span",{className:"ds-duration"},c))),e.createElement(xe,null),Q&&z&&Z&&e.createElement("div",{className:"ds-dtmf"},e.createElement("div",{className:"ds-dtmf-readout"},P||" "),e.createElement("div",{className:"ds-keypad ds-keypad-dtmf",role:"group","aria-label":S("keypad")},Y.map(({digit:n})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":n,onClick:()=>(e=>{l.sendDtmf(e),_(n=>n+e)})(n)},e.createElement("span",{className:"ds-key-digit"},n))))),Q&&O&&se&&e.createElement("div",{className:"ds-transfer"},e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:B,placeholder:S("transferPlaceholder"),"aria-label":S("transferPlaceholder"),autoComplete:"off",onChange:e=>U(e.target.value),onPaste:e=>{e.preventDefault(),V(e.clipboardData.getData("text"))}}),e.createElement("div",{className:"ds-transfer-actions"},e.createElement("button",{type:"button",className:"ds-transfer-send ds-transfer-send-secondary",disabled:!B.trim(),onClick:()=>{l.transfer(B)&&(H(""),s.closeTransfer())}},S("transferNow")),e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!B.trim(),onClick:()=>{m(B)}},S("transferConsult")))),Q&&M&&oe&&e.createElement("div",{className:"ds-transfer ds-addcall"},e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:ie,placeholder:S("addCallPlaceholder"),"aria-label":S("addCallPlaceholder"),autoComplete:"off",onChange:e=>F(e.target.value),onPaste:e=>{e.preventDefault(),K(e.clipboardData.getData("text"))}}),e.createElement("div",{className:"ds-transfer-actions"},e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!ie.trim(),onClick:()=>{const e=ie.trim();e&&(h(e),L(""),s.closeAddCall())}},S("addCallSend")))),Q&&D&&e.createElement(ze,null),Q&&e.createElement("div",{className:"ds-controls",role:"group"},e.createElement(Te,{label:r.isMuted?S("unmute"):S("mute"),glyph:r.isMuted?be.micOff:be.mic,on:r.isMuted,onClick:l.toggleMute}),e.createElement(Te,{label:ce||"held"===r.state?S("resume"):S("hold"),glyph:be.pause,on:ce||"held"===r.state,onClick:y?()=>A(!ce):l.toggleHold}),Z&&e.createElement(Te,{label:S("keypad"),glyph:be.keypad,on:z,onClick:s.toggleKeypad}),e.createElement(Te,{label:S("addCall"),glyph:be.addCall,on:M,disabled:!oe||y,onClick:s.toggleAddCall}),x||y?e.createElement(Te,{label:S(y?"split":"merge"),glyph:be.merge,on:y,onClick:y?w:E}):e.createElement(Te,{label:S("transfer"),glyph:be.transfer,on:O,disabled:!se,onClick:s.toggleTransfer}),e.createElement(Te,{label:S("audioDevices"),glyph:be.speaker,on:D,onClick:s.toggleDevices})),e.createElement("div",{className:"ds-actions"},e.createElement("button",{type:"button",className:"ds-action ds-hangup","aria-label":S("hangUp"),onClick:y?k:l.hangup},e.createElement(ye,{glyph:be.hangup})))))},De=({autoFocusDestination:n})=>{const{calls:t,activeCall:a,scope:r}=fe(),l=function(e,n=null){const t=e.filter(e=>e!==n&&E(e)),a=e.some(e=>e===n||!E(e));return{base:a?"in-call":"dial",incoming:t,overlay:a&&t.length>0,compact:a?t.length>0:t.length>1}}(t,a);if("dial"===l.base&&l.incoming.length>0)return 1===l.incoming.length?e.createElement(Se,null):e.createElement(Ie,{compact:l.compact});const s="in-call"===l.base?e.createElement(Oe,null):e.createElement(Me,{autoFocusDestination:n});return 0===l.incoming.length?s:e.createElement("div",{className:`${r} ds-softphone-layout`},e.createElement("div",{className:"ds-incoming-overlay"},e.createElement(Ie,{compact:l.compact})),s)},Me=({autoFocusDestination:n})=>{const{scope:t}=fe();return e.createElement("div",{className:`${t} ds-dial-screen`},e.createElement(Ne,null),e.createElement(Ee,{autoFocusDestination:n}))},je=({autoFocusDestination:n})=>{if(null===o(de))throw new Error("<Softphone> must be rendered inside a <SoftphoneProvider>. The provider owns the connection and the token. See https://docs.dialstack.ai/sdk/react.");return e.createElement(De,{autoFocusDestination:n})};export{T as DIAL_COUNTRY,Ee as DialPad,Ne as EmergencyBanner,Se as IncomingCall,Ie as IncomingStack,Oe as OngoingCall,je as Softphone,ue as SoftphoneProvider,N as callPeerName,$ as callPeerNumber,j as callStateLabelKey,_ as errorMessageKey,A as formatCallDuration,S as formatDisplayNumber,C as isCallActive,E as isIncomingRinging,O as sanitizeDestination,k as selectScreen,w as shouldRingIncoming,z as stripToDialString,he as useActiveCall,R as useCallActions,L as useCallDuration,W as useDialInput,ve as useIncomingCall,F as useLastError,fe as useSoftphone};
|
|
1
|
+
import e,{useRef as n,useEffect as t,useState as a,useReducer as r,useMemo as l,useCallback as o,createContext as s,useContext as c,useId as i}from"react";import{DialStackPhone as d,supportsConference as u,LocalConference as m,createPaginatedList as p,storage as g}from"@dialstack/sdk-webrtc";import{parsePhoneNumber as f}from"libphonenumber-js";import{defaultLocale as h}from"@dialstack/sdk-js/pure";import{DialstackComponentsContext as v}from"@dialstack/sdk-react";function b(e){const a=n(e);return t(()=>{a.current=e},[e]),a}function x(e){const{autoConnect:n=!0,onError:r,existingPhone:l}=e,[o,s]=a(null!=l?l:null),[c,i]=a(l?l.isConnected?"connected":l.isConnecting||n?"connecting":"idle":n&&e.token?"connecting":"idle"),u=b({onError:r}),m=b(e.emergencyAddressId),p=b(e.iceServers),g=b(e.storage),f=b(e.ringback),h=b(e.createSignalingSocket),v=b(e.onAppResume),x=b(e.onTokenExpiring),{token:y,apiBaseUrl:E,signalingBaseUrl:C,autoReconnect:k}=e;t(()=>{if(l){let e=!1;const t=n=>()=>{e||n()},a=t(()=>i("connected")),r=t(()=>i("reconnecting")),o=t(()=>i("disconnected")),s=n=>{var t,a;e||(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&i("error"))};return l.on("connected",a),l.on("reconnected",a),l.on("reconnecting",r),l.on("disconnected",o),l.on("error",s),!n||l.isConnected||l.isConnecting||l.connect().catch(n=>{var t,a,r,l;if(e)return;const o=n;null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:null!==(r=null==o?void 0:o.code)&&void 0!==r?r:"internal_error",message:null!==(l=null==o?void 0:o.message)&&void 0!==l?l:String(n)}),i("error")}),()=>{e=!0,l.off("connected",a),l.off("reconnected",a),l.off("reconnecting",r),l.off("disconnected",o),l.off("error",s)}}if(!y)return;let e=!1;const t=(a={token:y,apiBaseUrl:E,signalingBaseUrl:C,emergencyAddressId:m.current,iceServers:p.current,storage:g.current,ringback:f.current,createSignalingSocket:h.current,onAppResume:v.current,autoReconnect:k,onTokenExpiring:x.current?()=>{const e=x.current;return e?e():Promise.reject(new Error("onTokenExpiring not set"))}:void 0},new d(a));var a;s(t);const r=n=>()=>{e||n()};return t.on("connected",r(()=>i("connected"))),t.on("reconnected",r(()=>i("connected"))),t.on("reconnecting",r(()=>i("reconnecting"))),t.on("disconnected",r(()=>i("disconnected"))),t.on("error",n=>{var t,a;e||(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&i("error"))}),n&&(i("connecting"),t.connect().catch(n=>{var t,a,r,l;"transport_closed"!==(null==n?void 0:n.code)&&(null===(a=(t=u.current).onError)||void 0===a||a.call(t,{code:null!==(r=null==n?void 0:n.code)&&void 0!==r?r:"internal_error",message:null!==(l=null==n?void 0:n.message)&&void 0!==l?l:String(n)}),e||i("error"))})),()=>{e=!0,t.disconnect(),s(null),i("idle")}},[l,y,E,C,k,n,u,m,p,g,f,h,v,x]);const w=!l||"idle"!==c&&"connecting"!==c?c:l.isConnected?"connected":l.isConnecting?"connecting":c;return{phone:null!=l?l:o,connection:w}}function y(e,n,t,a){return new(t||(t=Promise))(function(r,l){function o(e){try{c(a.next(e))}catch(e){l(e)}}function s(e){try{c(a.throw(e))}catch(e){l(e)}}function c(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(o,s)}c((a=a.apply(e,n||[])).next())})}function E(e){return"inbound"===e.direction&&("ringing"===e.state||"trying"===e.state)}function C(e){return!!e&&(Array.isArray(e)?e.some(E):E(e))}function k(e){return e.isConnected}function w(e){return e?E(e)?"incoming":"in-call":"dial"}function $(e){return"inbound"===e.direction?e.from:e.to}function N(e){return"inbound"===e.direction?e.fromName:null}function S(e){const n=Math.max(0,Math.floor(e));return`${Math.floor(n/60)}:${(n%60).toString().padStart(2,"0")}`}function A(e,n="US"){if(!e)return"";try{const t=f(e,n);if(t){return"US"===t.country||"1"===t.countryCallingCode?t.formatNational():t.formatInternational()}}catch(e){}return e}"function"==typeof SuppressedError&&SuppressedError;const T=/[^+*#0-9A-Da-d]/g,I="US";function D(e){return e.replace(T,"").slice(0,32).toUpperCase()}function z(e,n="US"){const t=D(e);if(!t)return"";if(!/[*#]/.test(t)&&/^\+?[0-9]+$/.test(t))try{const e=f(t,n);if(null==e?void 0:e.isValid())return e.number}catch(e){}return t}const M={code:"invalid_message",message:"Enter a valid phone number, extension, or feature code"};function O(e,n,{silentWhenEmpty:t=!1}={}){const a=z(e,I);return a||(t&&!e.trim()||null==n||n(Object.assign({},M)),"")}function j(e){switch(e){case"trying":return"stateTrying";case"ringing":return"stateRinging";case"active":return"stateActive";case"held":return"stateHeld";default:return"stateEnded"}}const P=new Set(["auth_failed","auth_expired","session_limit","session_revoked","going_away","idle_timeout","slow_consumer","transport_closed","ice_fetch_failed","token_refresh_failed"]);function _(e){return"mic_permission_denied"===e?"micPermissionError":P.has(e)?"connectionError":"callError"}const H={calls:[],conferenceAudio:null};function L(e,n){const t=function(e,n){var t,a;switch(n.type){case"active":{const t=e.calls.find(e=>e.call===n.call),a=e.calls.filter(e=>e.call!==n.call).map(e=>Object.assign(Object.assign({},e),{active:!1})),r=t?Object.assign(Object.assign({},t),{active:!0}):{call:n.call,active:!0,transferPeer:null,transferRole:null,merged:!1};return Object.assign(Object.assign({},e),{calls:[...a,r]})}case"incomingAdded":return e.calls.some(e=>e.call===n.call)?e:Object.assign(Object.assign({},e),{calls:[...e.calls,{call:n.call,active:!1,transferPeer:null,transferRole:null,merged:!1}]});case"answered":case"switchActive":return e.calls.some(e=>e.call===n.call)?Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"answeredInPlace":return e.calls.find(e=>e.call===n.call)?e.calls.some(e=>e.active)?e:Object.assign(Object.assign({},e),{calls:e.calls.map(e=>Object.assign(Object.assign({},e),{active:e.call===n.call}))}):e;case"consultStarted":{const r=null!==(a=null===(t=e.calls.find(e=>e.active))||void 0===t?void 0:t.call)&&void 0!==a?a:null,l=e.calls.filter(e=>e.call!==r).map(e=>Object.assign(Object.assign({},e),{active:!1})),o=r?[{call:r,active:!1,transferPeer:n.call,transferRole:"original",merged:!1}]:[];return Object.assign(Object.assign({},e),{calls:[...l,...o,{call:n.call,active:!0,transferPeer:r,transferRole:"consult",merged:!1}]})}case"cancelConsult":{const n=e.calls.find(e=>"consult"===e.transferRole),t=e.calls.find(e=>"original"===e.transferRole);if(!n||!t)return e;const a=e.calls.filter(e=>e.call!==n.call&&e.call!==t.call);return Object.assign(Object.assign({},e),{calls:[...a,{call:t.call,active:!0,transferPeer:null,transferRole:null,merged:!1}]})}case"callEnded":{const t=e.calls.find(e=>e.call===n.call);if(!t)return e;let a=e.calls.filter(e=>e.call!==n.call);return t.transferPeer&&(a=a.map(e=>e.call===t.transferPeer?{call:e.call,active:!0,transferPeer:null,transferRole:null,merged:!1}:e)),Object.assign(Object.assign({},e),{calls:a})}case"merged":{const[t]=n.calls;if(!t)return e;const a=new Set(n.calls);return Object.assign(Object.assign({},e),{conferenceAudio:n.audio,calls:e.calls.map(e=>a.has(e.call)?Object.assign(Object.assign({},e),{merged:!0,active:e.call===t}):Object.assign(Object.assign({},e),{active:!1}))})}case"unmerged":return e.calls.some(e=>e.merged)?Object.assign(Object.assign({},e),{conferenceAudio:null,calls:e.calls.map(e=>e.merged?Object.assign(Object.assign({},e),{merged:!1}):e)}):e;case"reset":return 0===e.calls.length?e:H}}(e,n);if(t===e)return e;const a=function(e){const n=e.filter(e=>e.active).length;if(0===n){const n=[...e].reverse().find(e=>!E(e.call));return n?e.map(e=>e.call===n.call?Object.assign(Object.assign({},e),{active:!0}):e):e}if(1===n)return e;let t=!1;return[...e].reverse().map(e=>e.active?t?Object.assign(Object.assign({},e),{active:!1}):(t=!0,e):e).reverse()}(t.calls);return a===t.calls?t:Object.assign(Object.assign({},t),{calls:a})}function B(e,n={}){const{onError:t}=n,[,r]=a(0),l=o(()=>r(e=>e+1),[]),s=o((e,n)=>{var a,r;const l=e;null==t||t({code:null!==(a=null==l?void 0:l.code)&&void 0!==a?a:n,message:null!==(r=null==l?void 0:l.message)&&void 0!==r?r:String(e)})},[t]),c=o(e=>function(e,n,t){return{answer:()=>{if(e)try{e.answer()}catch(e){n(e,"call_failed")}},reject:()=>{if(e)try{e.reject()}catch(e){n(e,"call_failed")}},hangup:()=>{if(e)try{e.hangup()}catch(e){n(e,"call_failed")}},toggleMute:()=>{if(e)try{e.isMuted?e.unmute():e.mute(),t()}catch(e){n(e,"call_failed")}},toggleHold:()=>{if(e)try{"held"===e.state?e.resume():e.hold()}catch(e){n(e,"call_failed")}},sendDtmf:t=>{if(t&&e)try{e.sendDtmf(t)}catch(e){n(e,"call_failed")}}}}(e,s,l),[s,l]),{answer:i,reject:d,hangup:u,toggleMute:m,toggleHold:p,sendDtmf:g}=c(e);return{answer:i,reject:d,hangup:u,toggleMute:m,toggleHold:p,sendDtmf:g,transfer:o(n=>{if(!e)return!1;const a=O(n,t,{silentWhenEmpty:!0});if(!a)return!1;try{return e.transfer(a),!0}catch(e){return s(e,"call_failed"),!1}},[e,s,t]),callActionsFor:c}}function R(e,n=500){const[,r]=a(0),l=null!=e&&k(e);return t(()=>{if(!l)return;const e=setInterval(()=>r(e=>e+1),n);return()=>clearInterval(e)},[l,n]),S(e?e.duration:0)}const U="Timed out confirming your location. Please try again.";function V(e,n){let t=!1;return new Promise((a,r)=>{const l=setTimeout(()=>{t=!0,r(new Error(U))},8e3);e.then(()=>{clearTimeout(l),t?n(null):a()},e=>{clearTimeout(l);const a=e instanceof Error?e:new Error(U);t?n(a):r(a)})})}function F(e){const[n,t]=a(null);return{lastError:n,handleError:o(n=>{t(n),null==e||e(n)},[e]),clearError:o(()=>t(null),[])}}function W(e){return{onType:o(n=>e(D(n)),[e]),onPasteText:o(n=>e(z(n,I)),[e])}}const K={maxWidth:420,actionButtonSize:68,controlButtonSize:60,keyGap:14,keyMaxSize:84,radius:14},G={background:"#ffffff",surface:"rgba(0, 0, 0, 0.04)",surfaceActive:"rgba(0, 0, 0, 0.09)",text:"#1a1a1a",textSecondary:"rgba(0, 0, 0, 0.55)",border:"rgba(0, 0, 0, 0.1)",accent:"#6772e5",success:"#30a46c",danger:"#e5484d",warning:"#f5a623",onAccent:"#ffffff"},q={background:"#1a1a1a",surface:"rgba(255, 255, 255, 0.06)",surfaceActive:"rgba(255, 255, 255, 0.12)",text:"#ffffff",textSecondary:"rgba(255, 255, 255, 0.6)",border:"rgba(255, 255, 255, 0.12)",accent:"#828bf0",success:"#3dd68c",danger:"#ff6369",warning:"#f5a623",onAccent:"#ffffff"},Y=[{digit:"1",letters:""},{digit:"2",letters:"ABC"},{digit:"3",letters:"DEF"},{digit:"4",letters:"GHI"},{digit:"5",letters:"JKL"},{digit:"6",letters:"MNO"},{digit:"7",letters:"PQRS"},{digit:"8",letters:"TUV"},{digit:"9",letters:"WXYZ"},{digit:"*",letters:""},{digit:"0",letters:"+"},{digit:"#",letters:""}];function J(e){var n,t,a,r,l,o,s,c,i,d;const u="dark"===(null==e?void 0:e.theme)?q:G;const m=null!==(n=null==e?void 0:e.variables)&&void 0!==n?n:{};return{background:null!==(t=m.colorBackground)&&void 0!==t?t:u.background,surface:null!==(a=m.colorSurfaceSubtle)&&void 0!==a?a:u.surface,surfaceActive:u.surfaceActive,text:null!==(r=m.colorText)&&void 0!==r?r:u.text,textSecondary:null!==(l=m.colorTextSecondary)&&void 0!==l?l:u.textSecondary,border:null!==(o=m.colorBorder)&&void 0!==o?o:u.border,accent:null!==(s=m.colorPrimary)&&void 0!==s?s:u.accent,success:null!==(c=m.colorSuccess)&&void 0!==c?c:u.success,danger:null!==(i=m.colorDanger)&&void 0!==i?i:u.danger,warning:null!==(d=m.colorWarning)&&void 0!==d?d:u.warning,onAccent:u.onAccent}}const Q=s(null),X=()=>Promise.reject(new Error("Phone not connected")),Z={listEmergencyAddresses:()=>p(X(),X),setEmergencyAddress:X,presentedEmergencyAddressId:null,clearEmergencyAddressRegisteredIp:X,reconnectWithEmergency:X};function ee({token:s,existingPhone:c,apiBaseUrl:i,onTokenExpiring:d,iceServers:p,storage:g,ringback:f,createSignalingSocket:v,onAppResume:k,emergencyAddressId:w,autoConnect:$=!0,appearance:N,locale:S=h,defaultCountry:T="US",onConnectionStateChange:D,onIncomingCall:M,onCallStarted:j,onCallEnded:P,onError:_,placeOutbound:U,answerIncoming:W,extra:K,children:G}){var q,Y;const{lastError:X,handleError:ee,clearError:ne}=F(_),te=`${null!==(q=null==N?void 0:N.theme)&&void 0!==q?q:""}|${JSON.stringify(null!==(Y=null==N?void 0:N.variables)&&void 0!==Y?Y:{})}`,ae=l(()=>J(N),[te]),re=e=>S.softphone[e],le=e=>A(e,T),{phone:oe,connection:se}=x({existingPhone:c,token:s,apiBaseUrl:i,onTokenExpiring:d,iceServers:p,storage:g,ringback:f,createSignalingSocket:v,onAppResume:k,emergencyAddressId:w,autoConnect:$,onError:ee}),{calls:ce,activeCall:ie,incomingCalls:de,heldCalls:ue,answerCall:me,switchToCall:pe,placeCall:ge,consultCall:fe,transferOriginal:he,startAttendedTransfer:ve,completeAttendedTransfer:be,cancelAttendedTransfer:xe,mergedCalls:ye,isMerged:Ee,conferenceAudio:Ce,canMerge:ke,mergeCalls:we,splitMerge:$e,hangupConference:Ne,holdConference:Se}=function(e,s,c={}){var i,d,p,g,f,h;const{onIncomingCall:v,onCallStarted:x,onCallActivated:C,onCallEnded:k,onError:w,placeOutbound:$,answerIncoming:N}=c,[S,A]=r(L,H),[T,D]=a(e);T!==e&&(D(e),S.calls.length>0&&A({type:"reset"}));const{calls:M,conferenceAudio:j}=S,P=null!==(i=M.find(e=>e.active))&&void 0!==i?i:null,_=null!==(d=null==P?void 0:P.call)&&void 0!==d?d:null,B=l(()=>M.filter(e=>!e.active&&E(e.call)).map(e=>e.call),[M]),R=l(()=>M.filter(e=>!e.active&&!E(e.call)).map(e=>e.call),[M]),U=null!==(g=null===(p=M.find(e=>"consult"===e.transferRole))||void 0===p?void 0:p.call)&&void 0!==g?g:null,V=null!==(h=null===(f=M.find(e=>"original"===e.transferRole))||void 0===f?void 0:f.call)&&void 0!==h?h:null,F=l(()=>M.filter(e=>e.merged).map(e=>e.call),[M]),W=F.length>0,K=b(e),G=b(s),[,q]=a(0),Y=o(()=>q(e=>e+1),[]),J=n(null);J.current=_;const Q=b(U),X=n(null),Z=b(M),ee=b(V),ne=n(!0);t(()=>(ne.current=!0,()=>{ne.current=!1}),[]);const te=b({onIncomingCall:v,onCallStarted:x,onCallActivated:C,onCallEnded:k,onError:w,placeOutbound:$,answerIncoming:N}),ae=n(new Map),re=n(new WeakSet),le=o(e=>{const n=ae.current.get(e);n&&(n(),ae.current.delete(e))},[]),oe=o(e=>{le(e);const n=()=>{Y()},t=()=>{var n,t,a,r;"inbound"===e.direction&&(re.current.add(e),null===(t=(n=te.current).onCallStarted)||void 0===t||t.call(n,{direction:"inbound",peer:e.from})),null===(r=(a=te.current).onCallActivated)||void 0===r||r.call(a,e),A({type:"answeredInPlace",call:e}),Y()},a=n=>{var t,a;re.current.has(e)&&(re.current.delete(e),null===(a=(t=te.current).onCallEnded)||void 0===a||a.call(t,{reason:n}));const r=X.current;(null==r?void 0:r.has(e))&&(r.remove(e),r.calls.length<2&&(r.dispose(),X.current=null,A({type:"unmerged"}))),A({type:"callEnded",call:e}),le(e)};e.on("trying",n),e.on("ringing",n),e.on("answered",t),e.on("held",n),e.on("resumed",n),e.on("ended",a),ae.current.set(e,()=>{e.off("trying",n),e.off("ringing",n),e.off("answered",t),e.off("held",n),e.off("resumed",n),e.off("ended",a)})},[Y,le,te]),se=o(e=>y(this,void 0,void 0,function*(){var n,t,a,r,l,o,s,c,i,d,u,m;const p=K.current,g=O(e,te.current.onError);if(!g)return;if(!p||"connected"!==G.current)return void(null===(t=(n=te.current).onError)||void 0===t||t.call(n,{code:"transport_closed",message:"The softphone is not connected"}));if(ae.current.size>=4)return void(null===(r=(a=te.current).onError)||void 0===r||r.call(a,{code:"rate_limited",message:"Too many active calls"}));const f=J.current;try{null==f||f.hold();const e=yield null!==(s=null===(o=(l=te.current).placeOutbound)||void 0===o?void 0:o.call(l,g))&&void 0!==s?s:p.call(g);A({type:"active",call:e}),re.current.add(e),null===(i=(c=te.current).onCallStarted)||void 0===i||i.call(c,{direction:"outbound",peer:e.to}),oe(e)}catch(e){if(f&&"ended"!==f.state)try{f.resume()}catch(e){}const n=e;null===(u=(d=te.current).onError)||void 0===u||u.call(d,{code:null!==(m=n.code)&&void 0!==m?m:"call_failed",message:n.message})}}),[oe,G,te,K]),ce=o((e,n)=>{var t,a,r;const l=J.current;try{null==l||l.hold(),e(),A(n)}catch(e){if(l&&"ended"!==l.state)try{l.resume()}catch(e){}const n=e;null===(a=(t=te.current).onError)||void 0===a||a.call(t,{code:null!==(r=n.code)&&void 0!==r?r:"call_failed",message:n.message})}},[te]),ie=o(e=>{J.current!==e&&ce(()=>e.resume(),{type:"switchActive",call:e})},[ce]),de=o(e=>{ce(()=>te.current.answerIncoming?te.current.answerIncoming(e):e.answer(),{type:"answered",call:e})},[ce]),ue=o(()=>{var e,n,t;if(X.current)return;const a=Z.current;if(2!==a.length)return;if(!a.every(e=>e.call.isConnected)||!u())return;const r=a.map(e=>e.call);if(Z.current.some(e=>null!==e.transferRole))return;const l=[];for(const e of r)if("held"===e.state)try{e.resume(),l.push(e)}catch(e){}try{const e=m.merge(r,r[0].localMediaStream,e=>{var n,t,a;return null===(t=(n=te.current).onError)||void 0===t?void 0:t.call(n,{code:null!==(a=e.code)&&void 0!==a?a:"call_failed",message:e.message})});X.current=e,A({type:"merged",calls:r,audio:e.localMediaStream}),Y()}catch(a){for(const e of l)try{e.holdAfterResume()}catch(e){}const r=a;null===(n=(e=te.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[Z,X,te,Y]),me=o(()=>{const e=X.current;if(e){e.dispose(),X.current=null;for(const e of Z.current)if(e.merged&&!e.active)try{e.call.hold()}catch(e){}A({type:"unmerged"}),Y()}},[Z,X,Y]),pe=o(e=>{var n,t,a;const r=X.current;if(r){for(const l of r.calls)try{l.setConferenceHold(e)}catch(e){const r=e;null===(t=(n=te.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}Y()}},[X,te,Y]),ge=o(()=>{var e,n,t;const a=X.current;if(!a)return;const r=a.calls;a.dispose(),X.current=null,A({type:"unmerged"});for(const a of r)try{a.hangup()}catch(a){const r=a;null===(n=(e=te.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[X,te]),fe=o(e=>y(this,void 0,void 0,function*(){var n,t,a;const r=J.current,l=K.current,o=z(e,I);if(r&&!Q.current&&o&&!X.current)try{const e=yield r.attendedTransfer(o);if(!ne.current)return;if("ended"===r.state||K.current!==l)return void e.hangup();A({type:"consultStarted",call:e}),oe(e)}catch(e){const r=e;null===(t=(n=te.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}}),[oe,Q,te,K]),he=o(()=>{var e,n,t;const a=ee.current,r=Q.current;if(a&&r&&r.isConnected)try{a.completeTransfer()}catch(a){const r=a;null===(n=(e=te.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[Q,te,ee]),ve=o(()=>{const e=Q.current,n=ee.current;e&&(e.hangup(),le(e),"held"===(null==n?void 0:n.state)&&n.resume(),A({type:"cancelConsult"}))},[le,Q,ee]);t(()=>{var n;if(!e)return;let t=!1;const a=ae.current,r=(e,n)=>{var a,r,l;if(t)return;const o=null===(a=null==n?void 0:n.notifyHost)||void 0===a||a;X.current||ae.current.size>=4?e.reject("busy"):(A({type:"incomingAdded",call:e}),o&&(re.current.add(e),null===(l=(r=te.current).onIncomingCall)||void 0===l||l.call(r,{callId:e.id,from:e.from,fromName:e.fromName})),oe(e))};e.on("incoming",r);for(const t of null!==(n=e.activeCalls)&&void 0!==n?n:[])ae.current.has(t)||"inbound"===t.direction&&(r(t,{notifyHost:!t.isConnected}),t.isConnected&&(re.current.add(t),A({type:"answeredInPlace",call:t})));return()=>{t=!0,e.off("incoming",r);const n=X.current;n&&(n.dispose(),X.current=null);for(const e of a.values())e();a.clear(),A({type:"reset"})}},[e,oe,te]);const be=!W&&2===M.length&&M.every(e=>e.call.isConnected)&&!M.some(e=>null!==e.transferRole)&&u();return{calls:M,activeCall:_,incomingCalls:B,switchToCall:ie,answerCall:de,placeCall:se,consultCall:U,heldCalls:R,transferOriginal:V,startAttendedTransfer:fe,completeAttendedTransfer:he,cancelAttendedTransfer:ve,mergedCalls:F,isMerged:W,conferenceAudio:j,canMerge:be,mergeCalls:ue,splitMerge:me,hangupConference:ge,holdConference:pe}}(oe,se,{onIncomingCall:M,onCallStarted:j,onCallEnded:P,onError:ee,placeOutbound:U,answerIncoming:W}),Ae=function(e,r){const{disabled:l,connection:s,identityKey:c,liveCallCount:i=0}=r,[d,u]=a(!l),[m,p]=a(!1),[g,f]=a(!1),[h,v]=a([]),[x,E]=a(!1),C=b(x),[k,w]=a(null),$=b(e),N=n(!1),S=n(0),A=n(c);t(()=>{A.current!==c&&(A.current=c,N.current=!1,p(!1),f(!1),v([]),w(null),u(!l))},[c,l]);const T=o(()=>{f(!0),p(!1)},[]);t(()=>{if(l)return;if("connected"!==s)return void("disconnected"!==s&&"error"!==s||u(!1));let e=!1;return(()=>{y(this,void 0,void 0,function*(){var n,t;try{const a=$.current,r=(yield a.listEmergencyAddresses()).data;if(e)return;v(r);const l=a.presentedEmergencyAddressId,o=null!==(t=null!==(n=r.find(e=>e.id===l))&&void 0!==n?n:r[0])&&void 0!==t?t:null;if(!o)return void p(!1);if(i>0)return void u(!1);if(N.current||g)C.current||(p(!g),g||w(null));else{if(N.current=!0,null==l||l!==o.id||null==o.registered_ip)return void(yield V(a.reconnectWithEmergency(o.id),()=>{}).catch(()=>{}));p(!0),C.current||w(null)}}catch(n){e||p(!1)}finally{e||u(!1)}})})(),()=>{e=!0}},[l,s,g,$,C,i]);const I=o((e,n)=>y(this,void 0,void 0,function*(){const t=++S.current,a=n=>function(e){return"transport_closed"===(null==e?void 0:e.code)}(n)?"Connection interrupted. Please try again.":n instanceof Error?n.message:e,r=e=>{S.current===t&&w(e?a(e):null)};E(!0),w(null),f(!1),N.current=!0;try{const e=yield n(),t=$.current.reconnectWithEmergency(e);yield V(t,r)}catch(e){throw w(a(e)),e}finally{E(!1)}}),[$]);return{loading:d,bound:m,savedAddresses:h,submitting:x,error:k,onNetworkChanged:T,confirm:o(e=>I("Failed to confirm emergency address",()=>y(this,void 0,void 0,function*(){return yield $.current.clearEmergencyAddressRegisteredIp(e),e})),[I,$]),create:o(e=>I("Failed to save emergency address",()=>y(this,void 0,void 0,function*(){return(yield $.current.setEmergencyAddress(e)).id})),[I,$])}}(null!=oe?oe:Z,{disabled:!!w,connection:se,identityKey:s,liveCallCount:ce.length});t(()=>{if(!oe)return;const e=Ae.onNetworkChanged;return oe.on("network.changed",e),()=>oe.off("network.changed",e)},[oe,Ae.onNetworkChanged]);const Te=B(ie,{onError:ee}),Ie=function(e,n=!0){const[r,l]=a(null);n||"addcall"!==r||l(null);const s=o(e=>{l(n=>n===e?null:e)},[]),c=o(()=>s("keypad"),[s]),i=o(()=>s("transfer"),[s]),d=o(()=>s("devices"),[s]),u=o(()=>s("addcall"),[s]),m=o(()=>l(e=>"transfer"===e?null:e),[]),p=o(()=>l(e=>"addcall"===e?null:e),[]);return t(()=>{l(null)},[e]),{showKeypad:"keypad"===r,showTransfer:"transfer"===r,showDevices:"devices"===r,showAddCall:"addcall"===r,toggleKeypad:c,toggleTransfer:i,toggleDevices:d,toggleAddCall:u,closeTransfer:m,closeAddCall:p}}(ie,ce.length<4),De=R(ie),ze=l(()=>ce.map(e=>e.call),[ce]),Me=C(de),Oe=n(se);t(()=>{null==D||D({state:se}),"connected"===se&&"connected"!==Oe.current&&ne(),Oe.current=se},[se,D,ne]);const je=l(()=>Object.assign({connection:se,webrtcPhone:oe,calls:ze,activeCall:ie,incomingCalls:de,incomingRinging:Me,heldCalls:ue,answerCall:me,switchToCall:pe,actions:Te,overlays:Ie,duration:De,consultCall:fe,transferOriginal:he,startAttendedTransfer:ve,completeAttendedTransfer:be,cancelAttendedTransfer:xe,placeCall:ge,mergedCalls:ye,isMerged:Ee,conferenceAudio:Ce,canMerge:ke,mergeCalls:we,splitMerge:$e,hangupConference:Ne,holdConference:Se,emergency:Ae,emergencyManagedByHost:!!w,lastError:X,clearError:ne,t:re,displayNumber:le,palette:ae},K),[se,oe,ze,ie,de,Me,ue,me,pe,Te,Ie,De,fe,he,ve,be,xe,ge,ye,Ee,Ce,ke,we,$e,Ne,Se,Ae,w,X,ne,ae,S,T,K]);return e.createElement(Q.Provider,{value:je},G)}function ne(){const e=c(Q);if(!e)throw new Error("Could not find softphone context; wrap your softphone UI in a <SoftphoneProvider>.");return e}const te="dialstack.softphone.input_device_id",ae="dialstack.softphone.output_device_id",re=s(null),le=e=>e.filter(e=>""!==e.deviceId).map(e=>({deviceId:e.deviceId,label:e.label})),oe=({children:n})=>{var r,l,s;const{webrtcPhone:c,activeCall:i}=ne(),[d]=a(()=>"undefined"!=typeof HTMLMediaElement&&"function"==typeof HTMLMediaElement.prototype.setSinkId),[u]=a(()=>{var e;return"undefined"!=typeof navigator&&"function"==typeof(null===(e=navigator.mediaDevices)||void 0===e?void 0:e.enumerateDevices)}),[m,p]=a([]),[f,h]=a([]),[v,b]=a(!1),[x,E]=a(!1),[,C]=a(0),k=i?null!==(l=null!==(r=i.effectiveAudioInputDeviceId)&&void 0!==r?r:null==c?void 0:c.audioInputDeviceId)&&void 0!==l?l:null:null!==(s=null==c?void 0:c.audioInputDeviceId)&&void 0!==s?s:g.getItem(te),[w,$]=a(()=>g.getItem(ae));t(()=>{if(!u)return;let e=!1;const n=()=>y(void 0,void 0,void 0,function*(){let n;try{n=yield navigator.mediaDevices.enumerateDevices()}catch(e){return}if(e)return;const t=n.filter(e=>"audioinput"===e.kind),a=n.filter(e=>"audiooutput"===e.kind);b(t.length>0&&t.every(e=>""===e.label)),p(le(t)),h(d?le(a):[])});n();const t=()=>{n()};return navigator.mediaDevices.addEventListener("devicechange",t),()=>{e=!0,navigator.mediaDevices.removeEventListener("devicechange",t)}},[u,d,i]),t(()=>{c&&w&&c.setAudioOutputDevice(w)},[c,w]),t(()=>{const e=g.getItem(te);c&&e&&!c.audioInputDeviceId&&c.seedAudioInputDevice(e)},[c]),t(()=>{if(!i)return;const e=()=>E(!0),n=()=>C(e=>e+1);return i.on("audioInputLost",e),i.on("audioInputChanged",n),()=>{i.off("audioInputLost",e),i.off("audioInputChanged",n),E(!1)}},[i]);const N=o(e=>{const n=()=>C(e=>e+1);null==c||c.setAudioInputDevice(e).then(()=>{E(!1),e?g.setItem(te,e):g.removeItem(te),n()},n)},[c]),S=o(e=>{$(e),e?g.setItem(ae,e):g.removeItem(ae),null==c||c.setAudioOutputDevice(e)},[c]),A={inputs:m,outputs:f,inputDeviceId:k,outputDeviceId:w,selectInputDevice:N,selectOutputDevice:S,outputSelectionSupported:d,enumerationSupported:u,labelsHidden:v,inputLost:x};return e.createElement(re.Provider,{value:A},n)};function se(){const e=c(re);return e||{inputs:[],outputs:[],inputDeviceId:null,outputDeviceId:null,selectInputDevice:()=>{},selectOutputDevice:()=>{},outputSelectionSupported:!1,enumerationSupported:!1,labelsHidden:!1,inputLost:!1}}const ce=[440,480];class ie{constructor(){this.ctx=null,this.gain=null,this.oscillators=[],this.cadenceTimer=null,this.started=!1,this.nextCadenceTime=0,this.sinkId=null}get isPlaying(){return this.started}setSinkId(e){this.sinkId=e;const n=this.ctx;n&&"function"==typeof n.setSinkId&&Promise.resolve(n.setSinkId(null!=e?e:"")).catch(()=>{})}start(){if(this.started)return;const e=function(){var e,n;const t=globalThis;return null!==(n=null!==(e=t.AudioContext)&&void 0!==e?e:t.webkitAudioContext)&&void 0!==n?n:null}();if(!e)return;let n;try{n=new e(this.sinkId?{sinkId:this.sinkId}:void 0)}catch(t){this.sinkId=null;try{n=new e}catch(e){return}}this.ctx=n,"suspended"===n.state&&"function"==typeof n.resume&&Promise.resolve(n.resume()).catch(()=>{});try{const e=n.createGain();e.gain.value=0,e.connect(n.destination),this.gain=e;for(const t of ce){const a=n.createOscillator();a.frequency.value=t,a.connect(e),a.start(),this.oscillators.push(a)}this.nextCadenceTime=n.currentTime,this.scheduleCadenceAhead(),this.cadenceTimer=setInterval(()=>this.scheduleCadenceAhead(),6e3),this.started=!0}catch(e){this.teardown()}}stop(){this.started&&(this.started=!1,this.teardown())}teardown(){this.cadenceTimer&&(clearInterval(this.cadenceTimer),this.cadenceTimer=null);for(const e of this.oscillators)try{e.stop(),e.disconnect()}catch(e){}if(this.oscillators=[],this.gain){try{this.gain.disconnect()}catch(e){}this.gain=null}const e=this.ctx;this.ctx=null,e&&"function"==typeof e.close&&Promise.resolve(e.close()).catch(()=>{})}scheduleCadenceAhead(){const e=this.ctx,n=this.gain;if(!e||!n)return;for(;this.nextCadenceTime+6<=e.currentTime;)this.nextCadenceTime+=6;const t=e.currentTime+12;for(;this.nextCadenceTime<t;)n.gain.setValueAtTime(.14,this.nextCadenceTime),n.gain.setValueAtTime(0,this.nextCadenceTime+2),this.nextCadenceTime+=6}}const de=Q,ue=({existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:o,iceServers:s,emergencyAddressId:d,autoConnect:u=!0,appearance:m,locale:p=h,formatting:g,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:x,onCallEnded:y,onError:E,children:C})=>{var k,w,$;const N=`ds-softphone-${i().replace(/[:]/g,"")}`,S=l(()=>({scope:N}),[N]),A=c(v),[T,I]=a(()=>null==A?void 0:A.dialstack.getAppearance()),D=null!=m?m:T,z=`${null!==(k=null==D?void 0:D.theme)&&void 0!==k?k:""}|${JSON.stringify(null!==(w=null==D?void 0:D.variables)&&void 0!==w?w:{})}`,M=null!==($=null==g?void 0:g.defaultCountry)&&void 0!==$?$:"US",O=l(()=>function(e,n="ds-softphone"){const t=K;return`\n .${n} {\n --dsd-bg: ${e.background};\n --dsd-surface: ${e.surface};\n --dsd-surface-active: ${e.surfaceActive};\n --dsd-text: ${e.text};\n --dsd-text-secondary: ${e.textSecondary};\n --dsd-border: ${e.border};\n --dsd-accent: ${e.accent};\n --dsd-success: ${e.success};\n --dsd-danger: ${e.danger};\n --dsd-warning: ${e.warning};\n --dsd-on-accent: ${e.onAccent};\n font-family: var(--ds-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);\n background: var(--dsd-bg);\n color: var(--dsd-text);\n width: 100%;\n min-width: 0;\n height: var(--ds-softphone-height, 100%);\n min-height: 0;\n max-width: ${t.maxWidth}px;\n margin: 0 auto;\n border-radius: ${t.radius}px;\n padding: clamp(12px, 4vw, 24px);\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n }\n .${n} * { box-sizing: border-box; }\n .${n} .ds-softphone {\n padding: 0; background: none; max-width: none; margin: 0;\n min-width: 0; flex: 1;\n height: auto; min-height: 0;\n }\n .${n} .ds-screen {\n display: flex; flex: 1; flex-direction: column;\n min-height: 0;\n gap: clamp(12px, 3vw, 20px);\n overflow-y: auto;\n scrollbar-gutter: stable both-edges;\n }\n .${n} .ds-screen > *:not(.ds-actions) { flex-shrink: 0; }\n .${n} .ds-screen > .ds-actions {\n position: sticky; bottom: 0;\n background: var(--dsd-bg);\n padding-bottom: 2px;\n }\n\n .${n} .ds-screen-dial { position: relative; padding-top: 26px; }\n\n .${n} .ds-chip {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n width: fit-content;\n margin-inline: auto;\n font-size: 12px;\n font-weight: 600;\n padding: 4px 12px;\n border-radius: 999px;\n letter-spacing: 0.02em;\n }\n .${n} .ds-chip-spacer { visibility: hidden; position: absolute; }\n .${n} .ds-chip-pending { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-off { background: var(--dsd-surface); color: var(--dsd-text-secondary); }\n .${n} .ds-chip-error { background: color-mix(in srgb, var(--dsd-danger) 16%, transparent); color: var(--dsd-danger); }\n .${n} .ds-call-error {\n display: flex;\n align-items: center;\n gap: 8px;\n max-width: 100%;\n text-align: left;\n position: static;\n align-self: stretch;\n }\n .${n} .ds-call-error-dismiss {\n border: none;\n background: transparent;\n color: inherit;\n cursor: pointer;\n font-size: 12px;\n line-height: 1;\n padding: 0;\n }\n\n .${n} .ds-display { display: flex; align-items: center; min-height: 56px; gap: 8px; }\n .${n} .ds-display-spacer { width: 40px; flex: none; }\n .${n} .ds-destination {\n flex: 1; min-width: 0;\n font-size: clamp(22px, 6vw, 28px);\n font-weight: 600;\n font-family: inherit;\n text-align: center;\n border: none; outline: none; background: transparent;\n color: var(--dsd-text);\n }\n .${n} .ds-destination::placeholder { color: var(--dsd-text-secondary); opacity: 0.7; }\n .${n} .ds-backspace {\n flex: none;\n border: none; background: transparent; cursor: pointer;\n font-size: 22px; color: var(--dsd-text-secondary);\n width: 40px; height: 40px; border-radius: 999px;\n }\n .${n} .ds-backspace:hover { background: var(--dsd-surface); color: var(--dsd-text); }\n\n .${n} .ds-keypad {\n display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));\n gap: ${t.keyGap}px;\n justify-items: center;\n max-width: min(${3*t.keyMaxSize+2*t.keyGap}px, 100%);\n width: 100%; margin: 0 auto;\n flex: 1 1 auto; min-height: 0;\n align-content: center;\n }\n .${n} .ds-key {\n display: flex; flex-direction: column; align-items: center; justify-content: center;\n aspect-ratio: 1 / 1; width: 100%; max-width: ${t.keyMaxSize}px;\n height: auto;\n border: none; border-radius: 999px;\n background: var(--dsd-surface); color: var(--dsd-text);\n cursor: pointer; gap: 2px;\n transition: background-color 0.12s ease, transform 0.06s ease;\n -webkit-tap-highlight-color: transparent;\n user-select: none;\n }\n .${n} .ds-key:hover { background: var(--dsd-surface-active); }\n .${n} .ds-key:active { transform: scale(0.94); }\n .${n} .ds-key-digit { font-size: clamp(22px, 6vw, 28px); font-weight: 500; line-height: 1; }\n .${n} .ds-key-letters {\n font-size: 10px; font-weight: 600; letter-spacing: 0.12em;\n color: var(--dsd-text-secondary); min-height: 12px;\n }\n .${n} .ds-keypad-dtmf .ds-key { aspect-ratio: auto; padding: 10px 0; max-width: 72px; }\n\n .${n} .ds-actions {\n display: flex; justify-content: center; gap: clamp(24px, 12vw, 72px);\n margin-top: auto; padding-top: clamp(8px, 2vw, 16px);\n flex: 0 0 auto;\n }\n .${n} .ds-actions-incoming { justify-content: space-evenly; }\n .${n} .ds-action {\n width: ${t.actionButtonSize}px; height: ${t.actionButtonSize}px;\n border: none; border-radius: 999px; cursor: pointer;\n display: flex; align-items: center; justify-content: center;\n color: var(--dsd-on-accent);\n transition: transform 0.06s ease, filter 0.12s ease;\n -webkit-tap-highlight-color: transparent;\n }\n .${n} .ds-action svg { width: 46%; height: 46%; }\n .${n} .ds-action:active { transform: scale(0.92); }\n .${n} .ds-action:disabled { opacity: 0.4; cursor: not-allowed; }\n .${n} .ds-call, .${n} .ds-answer { background: var(--dsd-success); }\n .${n} .ds-hangup, .${n} .ds-decline { background: var(--dsd-danger); }\n .${n} .ds-call:not(:disabled):hover, .${n} .ds-answer:hover,\n .${n} .ds-hangup:hover, .${n} .ds-decline:hover { filter: brightness(1.06); }\n\n .${n} .ds-peer {\n flex: 1 1 auto;\n min-height: min-content;\n justify-content: center;\n }\n .${n} .ds-display {\n flex: 0 1 auto; min-height: 0;\n justify-content: center;\n }\n .${n} .ds-controls { flex: 0 1 auto; min-height: 0; }\n .${n} .ds-controls-slot { visibility: hidden; pointer-events: none; }\n .${n} .ds-peer { text-align: center; display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-peer-name { font-size: clamp(22px, 6vw, 28px); font-weight: 600; word-break: break-word; }\n .${n} .ds-peer-number { font-size: 15px; color: var(--dsd-text-secondary); }\n .${n} .ds-callstate { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 6px; }\n .${n} .ds-callstate-text { font-size: 14px; color: var(--dsd-text-secondary); }\n .${n} .ds-duration { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 500; }\n\n .${n} .ds-incoming-label {\n text-align: center; font-size: 13px; font-weight: 600;\n letter-spacing: 0.08em; text-transform: uppercase; color: var(--dsd-text-secondary);\n }\n .${n} .ds-incoming-pulse {\n width: 12px; height: 12px; border-radius: 999px; margin: 4px auto;\n background: var(--dsd-success);\n box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 60%, transparent);\n animation: ds-pulse 1.6s infinite;\n }\n @keyframes ds-pulse {\n 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dsd-success) 50%, transparent); }\n 70% { box-shadow: 0 0 0 16px transparent; }\n 100% { box-shadow: 0 0 0 0 transparent; }\n }\n\n .${n} .ds-controls {\n display: flex; flex-wrap: wrap; justify-content: center;\n gap: 8px 20px;\n max-width: ${3*(t.controlButtonSize+12)+40}px;\n align-content: flex-end;\n margin: 0 auto;\n }\n .${n} .ds-controls > * { flex: 0 0 ${t.controlButtonSize+12}px; }\n .${n} .ds-control {\n display: flex; flex-direction: column; align-items: center; gap: 6px;\n border: none; background: transparent; cursor: pointer;\n color: var(--dsd-text); font-family: inherit;\n }\n .${n} .ds-control-glyph {\n width: ${t.controlButtonSize}px; height: ${t.controlButtonSize}px;\n border-radius: 999px; background: var(--dsd-surface);\n display: flex; align-items: center; justify-content: center;\n transition: background-color 0.12s ease;\n }\n .${n} .ds-control-glyph svg { width: 42%; height: 42%; }\n .${n} .ds-control:hover:not(:disabled) .ds-control-glyph { background: var(--dsd-surface-active); }\n .${n} .ds-control-on .ds-control-glyph { background: var(--dsd-accent); color: var(--dsd-on-accent); }\n .${n} .ds-control-label { font-size: 12px; color: var(--dsd-text-secondary); }\n .${n} .ds-control-on .ds-control-label { color: var(--dsd-text); }\n .${n} .ds-control:disabled { cursor: not-allowed; opacity: 0.4; }\n\n .${n} .ds-dtmf {\n display: flex; flex-direction: column; gap: 10px;\n flex: 1; min-height: 0; justify-content: center;\n }\n .${n} .ds-screen-incall:has(.ds-dtmf) > .ds-peer { flex: 0 0 auto; }\n .${n} .ds-screen-incall:has(.ds-transfer) > .ds-peer { flex: 1 1 auto; }\n .${n} .ds-keypad-dtmf {\n flex: 1; min-height: 0;\n grid-auto-rows: minmax(0, ${t.keyMaxSize}px);\n align-content: center;\n }\n .${n} .ds-keypad-dtmf .ds-key {\n aspect-ratio: 1 / 1; width: auto; height: 100%;\n max-height: ${t.keyMaxSize}px; max-width: 100%; padding: 0;\n }\n .${n} .ds-keypad-close { background: var(--dsd-surface); color: var(--dsd-text); }\n .${n} .ds-keypad-close:hover { filter: brightness(0.96); }\n .${n} .ds-dtmf-readout {\n text-align: center; font-size: 22px; min-height: 28px;\n font-variant-numeric: tabular-nums; letter-spacing: 0.08em;\n }\n .${n} .ds-transfer {\n display: flex; flex-direction: column; gap: 8px;\n flex: 0 0 auto; min-height: min-content; justify-content: center;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+40}px; margin: 0 auto;\n }\n .${n} .ds-transfer-input {\n flex: 0 0 auto; min-width: 0; padding: 12px 14px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 16px; outline: none;\n }\n .${n} .ds-transfer-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-transfer-actions { display: flex; gap: 8px; }\n .${n} .ds-transfer-send {\n flex: 1; border: none; border-radius: ${t.radius}px; padding: 12px 18px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-transfer-send:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-transfer-send-secondary {\n background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} .ds-devices {\n display: flex; flex-direction: column; gap: 10px;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+40}px; margin: 0 auto;\n }\n .${n} .ds-device-row { display: flex; flex-direction: column; gap: 4px; }\n .${n} .ds-device-label { font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-select {\n width: 100%; padding: 10px 12px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-bg); color: var(--dsd-text);\n font-size: 14px; font-family: inherit; outline: none;\n }\n .${n} .ds-device-select:focus { border-color: var(--dsd-accent); }\n .${n} .ds-device-select:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-device-hint { margin: 0; font-size: 12px; color: var(--dsd-text-muted); }\n .${n} .ds-device-alert { font-size: 12px; color: var(--dsd-danger); }\n\n .${n} .ds-transfer-banner { display: flex; flex-direction: column; gap: 8px; }\n .${n} .ds-consult-held { opacity: 0.7; }\n .${n} .ds-consult-actions { display: flex; gap: 8px; }\n .${n} .ds-consult-actions .ds-e911-btn { flex: 1; }\n\n .${n} .ds-held-calls {\n display: flex; flex-direction: column; gap: 8px;\n flex: 0 1 auto; min-height: 0; overflow: auto;\n }\n .${n} .ds-held-call {\n display: block; width: 100%; cursor: pointer; text-align: center;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n padding: 12px 14px;\n background: var(--dsd-surface); color: var(--dsd-text);\n font-family: inherit;\n }\n .${n} .ds-held-call:hover { opacity: 1; border-color: var(--dsd-accent); }\n .${n} .ds-conference-parties {\n display: flex; flex-direction: column; align-items: center; gap: 2px;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n padding: 10px 14px; margin: 6px 0;\n background: var(--dsd-surface);\n }\n\n .${n}.ds-softphone-layout {\n display: flex; flex-direction: column; gap: 12px;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-softphone-layout > .ds-softphone { padding: 0; background: none; }\n .${n} .ds-incoming-overlay { flex: none; }\n\n .${n}.ds-dial-screen {\n display: flex; flex: 1; flex-direction: column;\n padding: clamp(12px, 4vw, 24px); background: var(--dsd-bg);\n }\n .${n} .ds-dial-screen > .ds-softphone { display: flex; min-height: 0; }\n .${n} .ds-incoming-stack { display: flex; flex-direction: column; gap: 8px; }\n\n .${n} .ds-incoming-card {\n display: flex; flex: 1; flex-direction: column;\n min-height: 0;\n gap: clamp(12px, 3vw, 20px);\n align-items: stretch; text-align: center;\n }\n .${n} .ds-incoming-card-info { min-width: 0; min-height: min-content; }\n .${n} .ds-incoming-card-compact {\n flex-direction: row; gap: 12px; align-items: center; text-align: left;\n min-height: 0; flex: none;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-surface); box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);\n }\n .${n} .ds-incoming-card-compact .ds-incoming-card-info {\n flex: 1 1 auto; min-width: 0; min-height: 0; justify-content: center;\n }\n .${n} .ds-incoming-card-compact .ds-incoming-label { font-size: 11px; }\n .${n} .ds-incoming-card-compact .ds-callstate { margin-top: 0; }\n .${n} .ds-incoming-card-compact .ds-duration { display: none; }\n .${n} .ds-incoming-card-compact .ds-peer-name {\n font-size: 15px; font-weight: 600; line-height: 1.2;\n white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-peer-number {\n font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .${n} .ds-incoming-card-compact .ds-actions-incoming { margin: 0; gap: 8px; flex: none; }\n .${n} .ds-incoming-card-compact .ds-action { width: 44px; height: 44px; }\n\n .${n}.ds-e911-root {\n padding: 0; background: none; max-width: none; margin: 0;\n flex: 0 0 auto; height: auto; min-height: 0;\n }\n .${n} .ds-e911 {\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n overflow: hidden; background: var(--dsd-surface);\n }\n .${n} .ds-e911-open {\n position: relative; overflow: visible; z-index: 3;\n }\n .${n} .ds-e911-open > .ds-e911-toggle {\n border-radius: ${t.radius}px ${t.radius}px 0 0;\n }\n .${n} .ds-e911-open > .ds-e911-body {\n position: absolute; top: 100%; left: 0; right: 0; z-index: 3;\n background: color-mix(in srgb, var(--dsd-text) 6%, var(--dsd-bg));\n border: 1px solid var(--dsd-border); border-top: none;\n border-radius: 0 0 ${t.radius}px ${t.radius}px;\n box-shadow: 0 6px 16px rgb(0 0 0 / 0.28), 0 1px 3px rgb(0 0 0 / 0.22);\n }\n .${n} .ds-e911-toggle {\n display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;\n padding: 10px 12px; border: none; cursor: pointer;\n background: color-mix(in srgb, var(--dsd-warning) 18%, transparent);\n color: color-mix(in srgb, var(--dsd-warning) 60%, var(--dsd-text));\n font-family: inherit; font-size: 13px;\n font-weight: 600; text-align: center;\n }\n .${n} .ds-e911-toggle svg { width: 16px; height: 16px; flex: none; }\n .${n} .ds-e911-label { flex: 0 1 auto; text-align: center; }\n .${n} .ds-e911-chevron { transition: transform 0.15s ease; }\n .${n} .ds-e911-open .ds-e911-chevron { transform: rotate(180deg); }\n .${n} .ds-e911-body {\n display: flex; flex-direction: column; gap: 8px;\n padding: 12px; border-top: 1px solid var(--dsd-border);\n }\n .${n} .ds-e911-hint { font-size: 12px; color: var(--dsd-text-secondary); margin: 0; }\n .${n} .ds-e911-choice {\n display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;\n padding: 10px 12px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); cursor: pointer;\n font-family: inherit; font-size: 13px;\n }\n .${n} .ds-e911-choice:hover { border-color: var(--dsd-accent); }\n .${n} .ds-e911-choice svg { width: 14px; height: 14px; flex: none; color: var(--dsd-success); }\n .${n} .ds-e911-choice-addr { flex: 1; min-width: 0; }\n .${n} .ds-e911-choice-cta { font-size: 12px; font-weight: 600; color: var(--dsd-accent); }\n .${n} .ds-e911-row { display: flex; gap: 8px; }\n .${n} .ds-e911-field { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }\n .${n} .ds-e911-field-sm { flex: none; width: 88px; }\n .${n} .ds-e911-field label { font-size: 11px; color: var(--dsd-text-secondary); }\n .${n} .ds-e911-input {\n padding: 8px 10px; border: 1px solid var(--dsd-border); border-radius: 8px;\n background: var(--dsd-bg); color: var(--dsd-text); font-size: 14px; outline: none;\n font-family: inherit; width: 100%;\n }\n .${n} .ds-e911-input:focus { border-color: var(--dsd-accent); }\n .${n} .ds-e911-error { font-size: 12px; color: var(--dsd-danger); margin: 0; }\n .${n} .ds-e911-actions { display: flex; gap: 8px; }\n .${n} .ds-e911-btn {\n flex: 1; border: none; border-radius: 8px; padding: 10px;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-weight: 600; cursor: pointer; font-family: inherit; font-size: 14px;\n }\n .${n} .ds-e911-btn:disabled { opacity: 0.5; cursor: not-allowed; }\n .${n} .ds-e911-btn-secondary {\n flex: none; background: var(--dsd-surface); color: var(--dsd-text);\n }\n\n .${n} button:focus-visible, .${n} input:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px color-mix(in srgb, var(--dsd-accent) 45%, transparent);\n }\n `}(J(D),N),[z,N]);return e.createElement(ee,{existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:o,iceServers:s,emergencyAddressId:d,autoConnect:u,appearance:D,locale:p,defaultCountry:M,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:x,onCallEnded:y,onError:E,extra:S},A&&e.createElement(ge,{dialstack:A.dialstack,onChange:I}),e.createElement("style",null,O),e.createElement(oe,null,C,e.createElement(me,null),e.createElement(pe,{onError:E})))},me=()=>{const{incomingRinging:e}=fe(),{outputDeviceId:a}=se(),r=n(null);return null===r.current&&(r.current=new ie),t(()=>{var e;null===(e=r.current)||void 0===e||e.setSinkId(a)},[a]),t(()=>{const n=r.current;if(n)return e?n.start():n.stop(),()=>n.stop()},[e]),null},pe=({onError:a})=>{const{activeCall:r,conferenceAudio:l}=fe(),{outputDeviceId:o}=se(),s=n(null);return t(()=>{const e=s.current;e&&"function"==typeof e.setSinkId&&e.setSinkId(null!=o?o:"").catch(()=>{})},[o,r]),t(()=>{const e=s.current;if(!e)return;if(!r)return void(e.srcObject=null);e.srcObject=null!=l?l:r.remoteMediaStream;const n=r;let t=!1;const o=n=>{e.play().then(()=>{t=!0},e=>{const r=null==e?void 0:e.name;n&&!t&&"AbortError"!==r&&(null==a||a({code:"audio_playback_blocked",message:"Could not play call audio — tap the call to enable sound."}))})};o("active"===n.state);const c=()=>o(!0);return n.on("answered",c),()=>{n.off("answered",c)}},[r,l,a]),e.createElement("audio",{ref:s,autoPlay:!0})},ge=({dialstack:e,onChange:n})=>{const r=function(e){const[n,r]=a(()=>e.getAppearance());return t(()=>{if("undefined"==typeof document)return;const n=document.createElement("div"),t=e=>{const n=e.detail;r(null==n?void 0:n.appearance)};return n.addEventListener("dialstack-appearance-update",t),e.addAppearanceTarget(n),()=>{e.removeAppearanceTarget(n),n.removeEventListener("dialstack-appearance-update",t)}},[e]),n}(e);return t(()=>{n(r)},[r,n]),null},fe=()=>ne(),he=()=>{const{activeCall:e,actions:n}=fe();return{activeCall:e,actions:n}},ve=()=>{const{incomingCalls:e}=fe();return function(e){var n;return null!==(n=e.find(E))&&void 0!==n?n:null}(e)},be={phone:{path:"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"},hangup:{path:"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",transform:"rotate(135 12 12)"},mic:{path:"M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11h-2z"},micOff:{path:"M19 11h-1.7a5.6 5.6 0 0 1-.34 1.6l1.22 1.22A7 7 0 0 0 19 11zM4.27 3 3 4.27 9 10.27V11a3 3 0 0 0 4.42 2.65l1.05 1.05A4.96 4.96 0 0 1 12 16a5 5 0 0 1-5-5H5a7 7 0 0 0 6 6.92V21h2v-3.08c.5-.07.98-.2 1.43-.39L19.73 21 21 19.73 4.27 3zM15 5a3 3 0 0 0-6-.09l6 6V5z"},pause:{path:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"},keypad:{path:"M5 3a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 10a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 17a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4z"},transfer:{path:"M16 1l4 4-4 4V6H9V4h7V1zM8 23l-4-4 4-4v3h7v2H8v3z"},location:{path:"M12 2a7 7 0 0 0-7 7c0 5.25 7 13 7 13s7-7.75 7-13a7 7 0 0 0-7-7zm0 9.5A2.5 2.5 0 1 1 12 6.5a2.5 2.5 0 0 1 0 5z"},chevronDown:{path:"M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z"},speaker:{path:"M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 7.97v8.05A4.47 4.47 0 0 0 16.5 12zM14 2.23v2.06a7.5 7.5 0 0 1 0 15.42v2.06a9.5 9.5 0 0 0 0-19.54z"},addCall:{path:"M15 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zM6 8V5H4v3H1v2h3v3h2v-3h3V8H6z"},merge:{path:"M17 20.41 18.41 19 15 15.59 13.59 17 17 20.41zM7.5 8H11v5.59L5.59 19 7 20.41l6-6V8h3.5L12 3.5 7.5 8z"},close:{path:"M19 6.41 17.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 12 19 6.41z"}},xe=({glyph:n})=>e.createElement("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},e.createElement("path",{d:n.path,transform:n.transform})),ye=({error:n,onDismiss:t,t:a})=>n?e.createElement("div",{className:"ds-chip ds-chip-error ds-call-error",role:"alert"},e.createElement("span",null,a(_(n.code))),e.createElement("button",{type:"button",className:"ds-call-error-dismiss","aria-label":a("dismiss"),onClick:t},"✕")):null,Ee="ds-softphone",Ce=({connection:n,destination:t,onDestinationChange:a,onDestinationPaste:r,canCall:l,onCall:o,destinationRef:s,error:c=null,onDismissError:i=()=>{},scope:d=Ee,t:u})=>e.createElement("div",{className:`${d} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-dial"},e.createElement(ke,{connection:n,t:u}),e.createElement(ye,{error:c,onDismiss:i,t:u}),e.createElement("div",{className:"ds-display"},t.length>0&&e.createElement("span",{className:"ds-display-spacer","aria-hidden":"true"}),e.createElement("input",{ref:s,className:"ds-destination",type:"tel",inputMode:"tel",value:t,placeholder:u("destinationPlaceholder"),"aria-label":u("destinationPlaceholder"),autoComplete:"off",onChange:e=>a(e.target.value),onPaste:e=>{e.preventDefault(),r(e.clipboardData.getData("text"))},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),l&&o())}}),t.length>0&&e.createElement("button",{type:"button",className:"ds-backspace","aria-label":u("backspace"),onClick:()=>a(t.slice(0,-1))},"⌫")),e.createElement("div",{className:"ds-keypad",role:"group","aria-label":u("title")},Y.map(({digit:n,letters:r})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":`${n}${r?" "+r:""}`,onClick:()=>a(t+n)},e.createElement("span",{className:"ds-key-digit"},n),e.createElement("span",{className:"ds-key-letters"},r||" ")))),e.createElement("div",{className:"ds-actions"},e.createElement("button",{type:"button",className:"ds-action ds-call","aria-label":u("call"),disabled:!l,onClick:o},e.createElement(xe,{glyph:be.phone}))))),ke=({connection:n,t:t})=>{switch(n){case"connecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("connecting"));case"reconnecting":return e.createElement("div",{className:"ds-chip ds-chip-pending",role:"status"},t("reconnecting"));case"disconnected":return e.createElement("div",{className:"ds-chip ds-chip-off",role:"status"},t("disconnected"));case"error":return e.createElement("div",{className:"ds-chip ds-chip-error",role:"status"},t("connectionError"));default:return e.createElement("div",{className:"ds-chip ds-chip-spacer","aria-hidden":"true"})}},we=({autoFocusDestination:r=!1})=>{const{connection:l,placeCall:o,emergency:s,lastError:c,clearError:i,t:d,scope:u}=fe(),[m,p]=a(""),{onType:g,onPasteText:f}=W(p),h=n(null);t(()=>{var e;r&&(null===(e=h.current)||void 0===e||e.focus())},[r]);const v=function(e,n,t){return"connected"===e&&n.length>0&&!t}(l,m,s.submitting);return e.createElement(Ce,{connection:l,destination:m,onDestinationChange:g,onDestinationPaste:f,canCall:v,onCall:()=>{o(m)},destinationRef:h,error:c,onDismissError:i,scope:u,t:d})},$e={alabama:"AL",alaska:"AK",arizona:"AZ",arkansas:"AR",california:"CA",colorado:"CO",connecticut:"CT",delaware:"DE","district of columbia":"DC",florida:"FL",georgia:"GA",hawaii:"HI",idaho:"ID",illinois:"IL",indiana:"IN",iowa:"IA",kansas:"KS",kentucky:"KY",louisiana:"LA",maine:"ME",maryland:"MD",massachusetts:"MA",michigan:"MI",minnesota:"MN",mississippi:"MS",missouri:"MO",montana:"MT",nebraska:"NE",nevada:"NV","new hampshire":"NH","new jersey":"NJ","new mexico":"NM","new york":"NY","north carolina":"NC","north dakota":"ND",ohio:"OH",oklahoma:"OK",oregon:"OR",pennsylvania:"PA","rhode island":"RI","south carolina":"SC","south dakota":"SD",tennessee:"TN",texas:"TX",utah:"UT",vermont:"VT",virginia:"VA",washington:"WA","west virginia":"WV",wisconsin:"WI",wyoming:"WY","puerto rico":"PR",guam:"GU","u.s. virgin islands":"VI","american samoa":"AS","northern mariana islands":"MP",alberta:"AB","british columbia":"BC",manitoba:"MB","new brunswick":"NB","newfoundland and labrador":"NL","nova scotia":"NS","northwest territories":"NT",nunavut:"NU",ontario:"ON","prince edward island":"PE",quebec:"QC",saskatchewan:"SK",yukon:"YT"};function Ne(e){const n=e.trim(),t=$e[n.toLowerCase()];return t||(/^[a-z]{2}$/i.test(n)?n.toUpperCase():n)}const Se={address_number:"",street:"",unit:"",city:"",state:"",postal_code:""},Ae=({savedAddresses:n,submitting:t,error:r,onConfirm:l,onCreate:o,defaultExpanded:s=!1,defaultAddingNew:c=!1,scope:i=Ee,t:d})=>{const[u,m]=a(s),[p,g]=a(c),[f,h]=a(Se),v=e=>n=>h(t=>Object.assign(Object.assign({},t),{[e]:n.target.value}));return e.createElement("div",{className:`${i} ds-softphone ds-e911-root`},e.createElement("div",{className:"ds-e911 "+(u?"ds-e911-open":"")},e.createElement("button",{type:"button",className:"ds-e911-toggle","aria-expanded":u,onClick:()=>m(e=>!e)},e.createElement("span",null,e.createElement(xe,{glyph:be.location})),e.createElement("span",{className:"ds-e911-label"},d("emergencyPrompt")),e.createElement("span",{className:"ds-e911-chevron"},e.createElement(xe,{glyph:be.chevronDown}))),u&&e.createElement("div",{className:"ds-e911-body"},e.createElement("p",{className:"ds-e911-hint"},d("emergencyHint")),!p&&n.map(n=>e.createElement("button",{key:n.id,type:"button",className:"ds-e911-choice",disabled:t,onClick:()=>{return e=n.id,void l(e).then(()=>m(!1)).catch(()=>{});var e}},e.createElement(xe,{glyph:be.location}),e.createElement("span",{className:"ds-e911-choice-addr"},[n.address.address_number,n.address.street,n.address.city,n.address.state,n.address.postal_code].filter(Boolean).join(" ")),e.createElement("span",{className:"ds-e911-choice-cta"},d("emergencyConfirm")))),!p&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>g(!0)},d("emergencyNewLocation")),p&&e.createElement("form",{className:"ds-e911-body",style:{padding:0,borderTop:"none"},onSubmit:e=>{e.preventDefault(),o(Object.assign(Object.assign({},f),{state:Ne(f.state),unit:f.unit||void 0})).then(()=>{m(!1),g(!1)}).catch(()=>{})}},e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${i}-ea-num`},d("emergencyNumber")),e.createElement("input",{id:`${i}-ea-num`,className:"ds-e911-input",value:f.address_number,onChange:v("address_number")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${i}-ea-street`},d("emergencyStreet")),e.createElement("input",{id:`${i}-ea-street`,className:"ds-e911-input",value:f.street,onChange:v("street"),required:!0}))),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${i}-ea-unit`},d("emergencyUnit")),e.createElement("input",{id:`${i}-ea-unit`,className:"ds-e911-input",value:f.unit,onChange:v("unit")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${i}-ea-city`},d("emergencyCity")),e.createElement("input",{id:`${i}-ea-city`,className:"ds-e911-input",value:f.city,onChange:v("city"),required:!0})),e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${i}-ea-state`},d("emergencyState")),e.createElement("input",{id:`${i}-ea-state`,className:"ds-e911-input",value:f.state,onChange:v("state"),required:!0})),e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${i}-ea-zip`},d("emergencyPostalCode")),e.createElement("input",{id:`${i}-ea-zip`,className:"ds-e911-input",value:f.postal_code,onChange:v("postal_code"),required:!0}))),r&&e.createElement("p",{className:"ds-e911-error"},r),e.createElement("div",{className:"ds-e911-actions"},n.length>0&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>g(!1)},d("emergencyBack")),e.createElement("button",{type:"submit",className:"ds-e911-btn",disabled:t},d(t?"emergencySaving":"emergencySave")))))))},Te=()=>{const{emergency:n,emergencyManagedByHost:t,activeCall:a,t:r,scope:l}=fe();return t||n.loading||n.bound||a?null:e.createElement(Ae,{savedAddresses:n.savedAddresses,submitting:n.submitting,error:n.error,onConfirm:n.confirm,onCreate:n.create,scope:l,t:r})},Ie=()=>e.createElement("div",{className:"ds-controls ds-controls-slot","aria-hidden":"true"},Array.from({length:6},(n,t)=>e.createElement("span",{key:t,className:"ds-control"},e.createElement("span",{className:"ds-control-glyph"}),e.createElement("span",{className:"ds-control-label"}," ")))),De=({name:n,number:t=null,compact:a=!1,onAnswer:r,onDecline:l,t:o})=>e.createElement("div",{className:"ds-incoming-card "+(a?"ds-incoming-card-compact":"")},e.createElement("div",{className:"ds-peer ds-incoming-card-info"},e.createElement("div",{className:"ds-peer-name"},n),t&&e.createElement("div",{className:"ds-peer-number"},t),e.createElement("div",{className:"ds-callstate"},e.createElement("div",{className:"ds-incoming-label"},o("incomingCall")),e.createElement("span",{className:"ds-duration","aria-hidden":"true"}," "))),!a&&e.createElement(Ie,null),e.createElement("div",{className:"ds-actions ds-actions-incoming"},e.createElement("button",{type:"button",className:"ds-action ds-decline","aria-label":o("decline"),onClick:l},e.createElement(xe,{glyph:be.hangup})),e.createElement("button",{type:"button",className:"ds-action ds-answer","aria-label":o("answer"),onClick:r},e.createElement(xe,{glyph:be.phone})))),ze=({call:n,compact:t=!1})=>{const{answerCall:a,actions:r,t:l,displayNumber:o}=fe(),s=$(n),c=N(n);return e.createElement(De,{name:c||o(s)||l("unknownCaller"),number:c?o(s):null,compact:t,onAnswer:()=>a(n),onDecline:()=>r.callActionsFor(n).reject(),t:l})},Me=()=>{const{incomingCalls:n,scope:t}=fe(),a=n[0];return a?e.createElement("div",{className:`${t} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incoming"},e.createElement(ze,{call:a}))):null},Oe=({compact:n})=>{const{incomingCalls:t,scope:a}=fe();if(0===t.length)return null;const r=null!=n?n:t.length>1;return e.createElement("div",{className:`${a} ds-softphone`},e.createElement("div",{className:"ds-incoming-stack"},t.map(n=>e.createElement(ze,{key:n.id,call:n,compact:r}))))},je=({inputs:n,outputs:t,inputDeviceId:a,outputDeviceId:r,onSelectInput:l,onSelectOutput:o,outputSelectionSupported:s,enumerationSupported:c,labelsHidden:i,inputLost:d,t:u})=>e.createElement("div",{className:"ds-devices",role:"group"},d&&e.createElement("div",{className:"ds-device-alert",role:"alert"},u("audioMicrophoneLost")),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},u("audioMicrophone")),e.createElement("select",{className:"ds-device-select","aria-label":u("audioMicrophone"),value:null!=a?a:"",onChange:e=>l(e.target.value||null)},e.createElement("option",{value:""},u("audioSystemDefault")),n.map(n=>e.createElement("option",{key:n.deviceId,value:n.deviceId},n.label||u("audioUnnamedDevice"))))),e.createElement("label",{className:"ds-device-row"},e.createElement("span",{className:"ds-device-label"},u("audioSpeaker")),e.createElement("select",{className:"ds-device-select","aria-label":u("audioSpeaker"),value:null!=r?r:"",disabled:!s,onChange:e=>o(e.target.value||null)},e.createElement("option",{value:""},u("audioSystemDefault")),t.map(n=>e.createElement("option",{key:n.deviceId,value:n.deviceId},n.label||u("audioUnnamedDevice"))))),!c&&e.createElement("p",{className:"ds-device-hint"},u("audioDevicesUnsupported")),!s&&e.createElement("p",{className:"ds-device-hint"},u("audioSpeakerUnsupported")),i&&e.createElement("p",{className:"ds-device-hint"},u("audioLabelsHidden"))),Pe=()=>{const{t:n}=fe(),{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:l,selectInputDevice:o,selectOutputDevice:s,outputSelectionSupported:c,enumerationSupported:i,labelsHidden:d,inputLost:u}=se();return e.createElement(je,{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:l,onSelectInput:o,onSelectOutput:s,outputSelectionSupported:c,enumerationSupported:i,labelsHidden:d,inputLost:u,t:n})},_e=({label:n,glyph:t,on:a=!1,disabled:r=!1,onClick:l})=>e.createElement("button",{type:"button",className:"ds-control "+(a?"ds-control-on":""),"aria-pressed":a,"aria-label":n,disabled:r,onClick:l},e.createElement("span",{className:"ds-control-glyph"},e.createElement(xe,{glyph:t})),e.createElement("span",{className:"ds-control-label"},n)),He=({peer:n,stateLabel:t,duration:a,showDuration:r,isActive:l,isMuted:o,isHeld:s,isMerged:c,conferenceParties:i,conferenceLabel:d,transferOther:u,canCompleteTransfer:m,onSwitchToTransferOther:p,onCancelTransfer:g,onCompleteTransfer:f,switchableHeld:h,onSwitchToCall:v,error:b=null,onDismissError:x=()=>{},overlay:y,canSendDtmf:E,dtmfEntered:C,onSendDtmf:k,transferTo:w,onTransferToChange:$,onTransferToPaste:N,onBlindTransfer:S,onConsultTransfer:A,addCallTo:T,onAddCallToChange:I,onAddCallToPaste:D,onSubmitAddCall:z,devicesPanel:M=null,canStartTransfer:O,canAddCall:j,canMerge:P,onToggleMute:_,onToggleHold:H,onToggleOverlay:L,onMergeOrSplit:B,onHangup:R,scope:U=Ee,t:V})=>{const F=l&&"keypad"===y&&E;return e.createElement("div",{className:`${U} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incall "+(l?"ds-screen-active":"ds-screen-outgoing")},u&&e.createElement("div",{className:"ds-transfer-banner"},e.createElement("button",{type:"button",className:"ds-held-call ds-consult-held","aria-label":`${V("switchToCall")}: ${u.name}`,onClick:p},e.createElement("div",{className:"ds-peer-name"},u.name),e.createElement("div",{className:"ds-callstate-text"},V("transferOriginalOnHold"))),e.createElement("div",{className:"ds-consult-actions"},e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:g},V("cancel")),e.createElement("button",{type:"button",className:"ds-e911-btn",disabled:!m,onClick:f},V("transferComplete")))),h.length>0&&e.createElement("div",{className:"ds-held-calls",role:"group","aria-label":V("heldCallsLabel")},h.map(n=>e.createElement("button",{type:"button",key:n.id,className:"ds-held-call ds-consult-held","aria-label":`${V("switchToCall")}: ${n.name}`,onClick:()=>v(n.id)},e.createElement("div",{className:"ds-peer-name"},n.name),e.createElement("div",{className:"ds-callstate-text"},V("heldCallsLabel"))))),c?e.createElement("div",{className:"ds-peer ds-peer-conference"},e.createElement("div",{className:"ds-callstate-text"},d),e.createElement("div",{className:"ds-conference-parties"},i.map(n=>e.createElement("div",{key:n.id,className:"ds-peer-name"},n.name))),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-duration"},a))):e.createElement("div",{className:"ds-peer"},e.createElement("div",{className:"ds-peer-name"},n.name),n.number&&e.createElement("div",{className:"ds-peer-number"},n.number),e.createElement("div",{className:"ds-callstate"},F?e.createElement("span",{className:"ds-dtmf-readout"},C||" "):e.createElement("span",{className:"ds-callstate-text"},t),!F&&e.createElement("span",{className:"ds-duration","aria-hidden":!r},r?a:" "))),e.createElement(ye,{error:b,onDismiss:x,t:V}),l&&"keypad"===y&&E&&e.createElement("div",{className:"ds-dtmf"},e.createElement("div",{className:"ds-keypad ds-keypad-dtmf",role:"group","aria-label":V("keypad")},Y.map(({digit:n})=>e.createElement("button",{type:"button",key:n,className:"ds-key","aria-label":n,onClick:()=>k(n)},e.createElement("span",{className:"ds-key-digit"},n))))),l&&"transfer"===y&&O&&e.createElement("div",{className:"ds-transfer"},e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:w,placeholder:V("transferPlaceholder"),"aria-label":V("transferPlaceholder"),autoComplete:"off",onChange:e=>$(e.target.value),onPaste:e=>{e.preventDefault(),N(e.clipboardData.getData("text"))}}),e.createElement("div",{className:"ds-transfer-actions"},e.createElement("button",{type:"button",className:"ds-transfer-send ds-transfer-send-secondary",disabled:!w.trim(),onClick:S},V("transferNow")),e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!w.trim(),onClick:A},V("transferConsult")))),l&&"addcall"===y&&j&&e.createElement("div",{className:"ds-transfer ds-addcall"},e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:T,placeholder:V("addCallPlaceholder"),"aria-label":V("addCallPlaceholder"),autoComplete:"off",onChange:e=>I(e.target.value),onPaste:e=>{e.preventDefault(),D(e.clipboardData.getData("text"))}}),e.createElement("div",{className:"ds-transfer-actions"},e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!T.trim(),onClick:z},V("addCallSend")))),l&&"devices"===y&&M,!l&&e.createElement(Ie,null),l&&!F&&e.createElement("div",{className:"ds-controls",role:"group"},e.createElement(_e,{label:V(o?"unmute":"mute"),glyph:o?be.micOff:be.mic,on:o,onClick:_}),e.createElement(_e,{label:V(s?"resume":"hold"),glyph:be.pause,on:s,onClick:H}),E&&e.createElement(_e,{label:V("keypad"),glyph:be.keypad,on:"keypad"===y,onClick:()=>L("keypad")}),e.createElement(_e,{label:V("addCall"),glyph:be.addCall,on:"addcall"===y,disabled:!j||c,onClick:()=>L("addcall")}),P||c?e.createElement(_e,{label:V(c?"split":"merge"),glyph:be.merge,on:c,onClick:B}):e.createElement(_e,{label:V("transfer"),glyph:be.transfer,on:"transfer"===y,disabled:!O,onClick:()=>L("transfer")}),e.createElement(_e,{label:V("audioDevices"),glyph:be.speaker,on:"devices"===y,onClick:()=>L("devices")})),e.createElement("div",{className:"ds-actions"},F?e.createElement("button",{type:"button",className:"ds-action ds-keypad-close","aria-label":V("keypad"),onClick:()=>L("keypad")},e.createElement(xe,{glyph:be.close})):e.createElement("button",{type:"button",className:"ds-action ds-hangup","aria-label":V("hangUp"),onClick:R},e.createElement(xe,{glyph:be.hangup})))))},Le=()=>{var n;const{activeCall:r,actions:l,overlays:o,duration:s,consultCall:c,transferOriginal:i,heldCalls:d,incomingCalls:u,switchToCall:m,startAttendedTransfer:p,completeAttendedTransfer:g,cancelAttendedTransfer:f,placeCall:h,calls:v,mergedCalls:b,isMerged:x,canMerge:y,mergeCalls:E,splitMerge:C,hangupConference:w,holdConference:S,t:A,displayNumber:T,scope:I,lastError:D,clearError:z}=fe(),{showKeypad:M,showTransfer:O,showDevices:P,showAddCall:_}=o,[H,L]=a(""),[B,R]=a(""),[U,V]=a(""),{onType:F,onPasteText:K}=W(R),{onType:G,onPasteText:q}=W(V),Y=null!==(n=null==r?void 0:r.id)&&void 0!==n?n:null;if(t(()=>{L(""),R(""),V("")},[Y]),!r)return null;const J=$(r),Q=N(r),X=k(r),Z=Q||T(J)||A("unknownCaller"),ee=r.canSendDtmf,ne=null!==c&&null!==i,te=ne&&(r===c||r===i),ae=te?r===c?i:c:null,re=te&&null!==c&&c.isConnected,le=d.filter(e=>e!==ae&&!b.includes(e)),oe=d.length+u.length,se=!ne&&!x&&0===oe,ce=x&&b.some(e=>"held"===e.state),ie=v.length<4,de=ie?U:"",ue=e=>{const n=N(e),t=$(e);return{id:e.id,name:n||T(t)||A("unknownCaller"),number:n?T(t):null}},me=M?"keypad":O?"transfer":P?"devices":_?"addcall":null;return e.createElement(He,{peer:{id:r.id,name:Z,number:Q?T(J):null},stateLabel:A(j(r.state)),duration:s,showDuration:"active"===r.state,isActive:X,isMuted:r.isMuted,isHeld:ce||"held"===r.state,isMerged:x,conferenceParties:b.map(ue),conferenceLabel:A("conferenceLabel"),transferOther:te&&ae?ue(ae):null,canCompleteTransfer:re,onSwitchToTransferOther:()=>ae&&m(ae),onCancelTransfer:f,onCompleteTransfer:g,switchableHeld:le.map(ue),onSwitchToCall:e=>{const n=le.find(n=>n.id===e);n&&m(n)},error:D,onDismissError:z,overlay:me,canSendDtmf:ee,dtmfEntered:H,onSendDtmf:e=>{l.sendDtmf(e),L(n=>n+e)},transferTo:B,onTransferToChange:F,onTransferToPaste:K,onBlindTransfer:()=>{l.transfer(B)&&(R(""),o.closeTransfer())},onConsultTransfer:()=>{p(B)},addCallTo:de,onAddCallToChange:G,onAddCallToPaste:q,onSubmitAddCall:()=>{const e=de.trim();e&&(h(e),V(""),o.closeAddCall())},devicesPanel:e.createElement(Pe,null),canStartTransfer:se,canAddCall:ie,canMerge:y,onToggleMute:l.toggleMute,onToggleHold:x?()=>S(!ce):l.toggleHold,onToggleOverlay:e=>{"keypad"===e?o.toggleKeypad():"transfer"===e?o.toggleTransfer():"devices"===e?o.toggleDevices():o.toggleAddCall()},onMergeOrSplit:x?C:E,onHangup:x?w:l.hangup,scope:I,t:A})},Be=({autoFocusDestination:n})=>{const{calls:t,activeCall:a,scope:r}=fe(),l=function(e,n=null){const t=e.filter(e=>e!==n&&E(e)),a=e.some(e=>e===n||!E(e));return{base:a?"in-call":"dial",incoming:t,overlay:a&&t.length>0,compact:a?t.length>0:t.length>1}}(t,a);if("dial"===l.base&&l.incoming.length>0)return 1===l.incoming.length?e.createElement(Me,null):e.createElement(Oe,{compact:l.compact});const o="in-call"===l.base?e.createElement(Le,null):e.createElement(Re,{autoFocusDestination:n});return 0===l.incoming.length?o:e.createElement("div",{className:`${r} ds-softphone-layout`},e.createElement("div",{className:"ds-incoming-overlay"},e.createElement(Oe,{compact:l.compact})),o)},Re=({autoFocusDestination:n})=>{const{scope:t}=fe();return e.createElement("div",{className:`${t} ds-dial-screen`},e.createElement(Te,null),e.createElement(we,{autoFocusDestination:n}))},Ue=({autoFocusDestination:n})=>{if(null===c(de))throw new Error("<Softphone> must be rendered inside a <SoftphoneProvider>. The provider owns the connection and the token. See https://docs.dialstack.ai/sdk/react.");return e.createElement(Be,{autoFocusDestination:n})};export{I as DIAL_COUNTRY,we as DialPad,Te as EmergencyBanner,Me as IncomingCall,Oe as IncomingStack,Le as OngoingCall,Ue as Softphone,ue as SoftphoneProvider,N as callPeerName,$ as callPeerNumber,j as callStateLabelKey,_ as errorMessageKey,S as formatCallDuration,A as formatDisplayNumber,k as isCallActive,E as isIncomingRinging,z as sanitizeDestination,w as selectScreen,C as shouldRingIncoming,D as stripToDialString,he as useActiveCall,B as useCallActions,R as useCallDuration,W as useDialInput,ve as useIncomingCall,F as useLastError,fe as useSoftphone};
|
|
2
2
|
//# sourceMappingURL=softphone.mjs.map
|