@dialstack/sdk-react 3.8.0 → 3.9.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.
Files changed (45) hide show
  1. package/dist/ai-agent.cjs +1 -1
  2. package/dist/ai-agent.cjs.map +1 -1
  3. package/dist/ai-agent.mjs +1 -1
  4. package/dist/ai-agent.mjs.map +1 -1
  5. package/dist/call-history.cjs +1 -1
  6. package/dist/call-history.cjs.map +1 -1
  7. package/dist/call-history.mjs +1 -1
  8. package/dist/call-history.mjs.map +1 -1
  9. package/dist/call-logs.cjs +1 -1
  10. package/dist/call-logs.cjs.map +1 -1
  11. package/dist/call-logs.d.cts +4 -0
  12. package/dist/call-logs.d.ts +4 -0
  13. package/dist/call-logs.mjs +1 -1
  14. package/dist/call-logs.mjs.map +1 -1
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +21 -2
  18. package/dist/index.d.ts +21 -2
  19. package/dist/index.mjs +1 -1
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/onboarding.cjs +1 -1
  22. package/dist/onboarding.cjs.map +1 -1
  23. package/dist/onboarding.mjs +1 -1
  24. package/dist/onboarding.mjs.map +1 -1
  25. package/dist/phone-number-ordering.cjs +1 -1
  26. package/dist/phone-number-ordering.cjs.map +1 -1
  27. package/dist/phone-number-ordering.mjs +1 -1
  28. package/dist/phone-number-ordering.mjs.map +1 -1
  29. package/dist/phone-numbers.cjs +1 -1
  30. package/dist/phone-numbers.cjs.map +1 -1
  31. package/dist/phone-numbers.mjs +1 -1
  32. package/dist/phone-numbers.mjs.map +1 -1
  33. package/dist/softphone.cjs +1 -1
  34. package/dist/softphone.cjs.map +1 -1
  35. package/dist/softphone.d.cts +57 -27
  36. package/dist/softphone.d.ts +57 -27
  37. package/dist/softphone.mjs +1 -1
  38. package/dist/softphone.mjs.map +1 -1
  39. package/dist/voicemails.cjs +1 -1
  40. package/dist/voicemails.cjs.map +1 -1
  41. package/dist/voicemails.d.cts +4 -0
  42. package/dist/voicemails.d.ts +4 -0
  43. package/dist/voicemails.mjs +1 -1
  44. package/dist/voicemails.mjs.map +1 -1
  45. package/package.json +3 -3
@@ -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 o,useContext as i,useId as c}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,ClientInfo as v}from"@dialstack/sdk-js/pure";import{DialstackComponentsContext as x}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,o]=a(null!=l?l:null),[i,c]=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),x=b(e.client),y=b(e.onTokenExpiring),{token:E,apiBaseUrl:w,signalingBaseUrl:k,autoReconnect:C}=e;t(()=>{var e;if(l){let e=!1;const t=n=>()=>{e||n()},a=t(()=>c("connected")),r=t(()=>c("reconnecting")),s=t(()=>c("disconnected")),o=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&&c("error"))};return l.on("connected",a),l.on("reconnected",a),l.on("reconnecting",r),l.on("disconnected",s),l.on("error",o),!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)}),c("error")}),()=>{e=!0,l.off("connected",a),l.off("reconnected",a),l.off("reconnecting",r),l.off("disconnected",s),l.off("error",o)}}if(!E)return;let t=!1;const a=(r={token:E,apiBaseUrl:w,signalingBaseUrl:k,emergencyAddressId:p.current,iceServers:m.current,storage:g.current,ringback:f.current,createSignalingSocket:h.current,onAppResume:v.current,client:null===(e=x.current)||void 0===e?void 0:e.call(x),autoReconnect:C,onTokenExpiring:y.current?()=>{const e=y.current;return e?e():Promise.reject(new Error("onTokenExpiring not set"))}:void 0},new d(r));var r;o(a);const s=e=>()=>{t||e()};return a.on("connected",s(()=>c("connected"))),a.on("reconnected",s(()=>c("connected"))),a.on("reconnecting",s(()=>c("reconnecting"))),a.on("disconnected",s(()=>c("disconnected"))),a.on("error",e=>{var n,a;t||(null===(a=(n=u.current).onError)||void 0===a||a.call(n,{code:e.code,message:e.message}),e.fatal&&c("error"))}),n&&(c("connecting"),a.connect().catch(e=>{var n,a,r,l;"transport_closed"!==(null==e?void 0:e.code)&&(null===(a=(n=u.current).onError)||void 0===a||a.call(n,{code:null!==(r=null==e?void 0:e.code)&&void 0!==r?r:"internal_error",message:null!==(l=null==e?void 0:e.message)&&void 0!==l?l:String(e)}),t||c("error"))})),()=>{t=!0,a.disconnect(),o(null),c("idle")}},[l,E,w,k,C,n,u,p,m,g,f,h,v,y]);const $=!l||"idle"!==i&&"connecting"!==i?i:l.isConnected?"connected":l.isConnecting?"connecting":i;return{phone:null!=l?l:s,connection:$}}function E(e,n,t,a){return new(t||(t=Promise))(function(r,l){function s(e){try{i(a.next(e))}catch(e){l(e)}}function o(e){try{i(a.throw(e))}catch(e){l(e)}}function i(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(s,o)}i((a=a.apply(e,n||[])).next())})}function w(e){return"inbound"===e.direction&&("ringing"===e.state||"trying"===e.state)}function k(e){return!!e&&(Array.isArray(e)?e.some(w):w(e))}function C(e){return e.isConnected}function $(e){return e?w(e)?"incoming":"in-call":"dial"}function N(e,n,t,a){const r=t(S(e)),l=(null==n?void 0:n.name)||T(e)||r||a;return{name:l,number:l!==r&&r?r:null,avatar:null==n?void 0:n.avatar}}"function"==typeof SuppressedError&&SuppressedError;function S(e){return"inbound"===e.direction?e.from:e.to}function T(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 z(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}const I=/[^+*#0-9A-Da-d]/g,D="US";function M(e){return e.replace(I,"").slice(0,32).toUpperCase()}function O(e,n="US"){const t=M(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 P={code:"invalid_message",message:"Enter a valid phone number, extension, or feature code"};function j(e,n,{silentWhenEmpty:t=!1}={}){const a=O(e,D);return a||(t&&!e.trim()||null==n||n(Object.assign({},P)),"")}function _(e){switch(e){case"trying":return"stateTrying";case"ringing":return"stateRinging";case"active":return"stateActive";case"held":return"stateHeld";default:return"stateEnded"}}const H=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 L(e){return"mic_permission_denied"===e?"micPermissionError":H.has(e)?"connectionError":"callError"}const R={calls:[],conferenceAudio:null};function B(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:R}}(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=>!w(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 V(e,n={}){const{onError:t}=n,[,r]=a(0),l=s(()=>r(e=>e+1),[]),o=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]),i=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,o,l),[o,l]),{answer:c,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g}=i(e);return{answer:c,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:g,transfer:s(n=>{if(!e)return!1;const a=j(n,t,{silentWhenEmpty:!0});if(!a)return!1;try{return e.transfer(a),!0}catch(e){return o(e,"call_failed"),!1}},[e,o,t]),callActionsFor:i}}function U(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 F="Timed out confirming your location. Please try again.";function W(e,n){let t=!1;return new Promise((a,r)=>{const l=setTimeout(()=>{t=!0,r(new Error(F))},8e3);e.then(()=>{clearTimeout(l),t?n(null):a()},e=>{clearTimeout(l);const a=e instanceof Error?e:new Error(F);t?n(a):r(a)})})}function K(e){const[n,t]=a(null);return{lastError:n,handleError:s(n=>{t(n),null==e||e(n)},[e]),clearError:s(()=>t(null),[])}}function q(e){var n,t;if(!e)return null;const a=e=>"string"==typeof e&&e.trim()?e.trim():void 0,r=a(null===(n=e.avatar)||void 0===n?void 0:n.initials),l=a(null===(t=e.avatar)||void 0===t?void 0:t.uri),s={name:a(e.name),avatar:r||l?{initials:r,uri:l}:void 0};return s.name||s.avatar?s:null}function G(e){return{onType:s(n=>e(M(n)),[e]),onPasteText:s(n=>e(O(n,D)),[e])}}function Y(){const[e,n]=a(""),[t,r]=a(null);return{value:e,picked:t,onType:s(e=>{r(null),n(M(e))},[]),onPasteText:s(e=>{r(null),n(O(e,D))},[]),pick:s(e=>{r(e),n(O(e.destination,D))},[]),clear:s(()=>{r(null),n("")},[])}}const J={maxWidth:420,actionButtonSize:68,controlButtonSize:60,keyGap:14,keyMaxSize:84,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"},X={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"},Z=[{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 ee(e){var n,t,a,r,l,s,o,i,c,d;const u="dark"===(null==e?void 0:e.theme)?X: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!==(o=p.colorPrimary)&&void 0!==o?o:u.accent,success:null!==(i=p.colorSuccess)&&void 0!==i?i:u.success,danger:null!==(c=p.colorDanger)&&void 0!==c?c:u.danger,warning:null!==(d=p.colorWarning)&&void 0!==d?d:u.warning,onAccent:u.onAccent}}const ne=o(null),te=[],ae=()=>Promise.reject(new Error("Phone not connected")),re={listEmergencyAddresses:()=>m(ae(),ae),setEmergencyAddress:ae,presentedEmergencyAddressId:null,clearEmergencyAddressRegisteredIp:ae,reconnectWithEmergency:ae};function le({token:o,existingPhone:i,apiBaseUrl:c,onTokenExpiring:d,iceServers:m,storage:g,ringback:f,createSignalingSocket:v,client:x,onAppResume:C,emergencyAddressId:$,autoConnect:N=!0,appearance:S,locale:T=h,defaultCountry:A="US",onConnectionStateChange:I,onIncomingCall:M,onCallStarted:P,onCallEnded:_,onError:H,resolvePeer:L,layoutVariant:F="auto",directory:G=te,placeOutbound:Y,answerIncoming:J,extra:Q,children:X}){var Z,ae;const{lastError:le,handleError:se,clearError:oe}=K(H),ie=`${null!==(Z=null==S?void 0:S.theme)&&void 0!==Z?Z:""}|${JSON.stringify(null!==(ae=null==S?void 0:S.variables)&&void 0!==ae?ae:{})}`,ce=l(()=>ee(S),[ie]),de=e=>T.softphone[e],ue=e=>z(e,A),{phone:pe,connection:me}=y({existingPhone:i,token:o,apiBaseUrl:c,onTokenExpiring:d,iceServers:m,storage:g,ringback:f,createSignalingSocket:v,client:x,onAppResume:C,emergencyAddressId:$,autoConnect:N,onError:se}),{calls:ge,activeCall:fe,incomingCalls:he,heldCalls:ve,answerCall:xe,switchToCall:be,placeCall:ye,consultCall:Ee,transferOriginal:we,startAttendedTransfer:ke,completeAttendedTransfer:Ce,cancelAttendedTransfer:$e,mergedCalls:Ne,isMerged:Se,conferenceAudio:Te,canMerge:Ae,mergeCalls:ze,splitMerge:Ie,hangupConference:De,holdConference:Me}=function(e,o,i={}){var c,d,m,g,f,h;const{onIncomingCall:v,onCallStarted:x,onCallActivated:y,onCallEnded:k,onError:C,placeOutbound:$,answerIncoming:N}=i,[S,T]=r(B,R),[A,z]=a(e);A!==e&&(z(e),S.calls.length>0&&T({type:"reset"}));const{calls:I,conferenceAudio:M}=S,P=null!==(c=I.find(e=>e.active))&&void 0!==c?c:null,_=null!==(d=null==P?void 0:P.call)&&void 0!==d?d:null,H=l(()=>I.filter(e=>!e.active&&w(e.call)).map(e=>e.call),[I]),L=l(()=>I.filter(e=>!e.active&&!w(e.call)).map(e=>e.call),[I]),V=null!==(g=null===(m=I.find(e=>"consult"===e.transferRole))||void 0===m?void 0:m.call)&&void 0!==g?g:null,U=null!==(h=null===(f=I.find(e=>"original"===e.transferRole))||void 0===f?void 0:f.call)&&void 0!==h?h:null,F=l(()=>I.filter(e=>e.merged).map(e=>e.call),[I]),W=F.length>0,K=b(e),q=b(o),[,G]=a(0),Y=s(()=>G(e=>e+1),[]),J=n(null);J.current=_;const Q=b(V),X=n(null),Z=b(I),ee=b(U),ne=n(!0);t(()=>(ne.current=!0,()=>{ne.current=!1}),[]);const te=b({onIncomingCall:v,onCallStarted:x,onCallActivated:y,onCallEnded:k,onError:C,placeOutbound:$,answerIncoming:N}),ae=n(new Map),re=n(new WeakSet),le=s(e=>{const n=ae.current.get(e);n&&(n(),ae.current.delete(e))},[]),se=s(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),T({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,T({type:"unmerged"}))),T({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]),oe=s(e=>E(this,void 0,void 0,function*(){var n,t,a,r,l,s,o,i,c,d,u,p;const m=K.current,g=j(e,te.current.onError);if(!g)return;if(!m||"connected"!==q.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!==(o=null===(s=(l=te.current).placeOutbound)||void 0===s?void 0:s.call(l,g))&&void 0!==o?o:m.call(g);T({type:"active",call:e}),re.current.add(e),null===(c=(i=te.current).onCallStarted)||void 0===c||c.call(i,{direction:"outbound",peer:e.to}),se(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!==(p=n.code)&&void 0!==p?p:"call_failed",message:n.message})}}),[se,q,te,K]),ie=s((e,n)=>{var t,a,r;const l=J.current;try{null==l||l.hold(),e(),T(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]),ce=s(e=>{J.current!==e&&ie(()=>e.resume(),{type:"switchActive",call:e})},[ie]),de=s(e=>{ie(()=>te.current.answerIncoming?te.current.answerIncoming(e):e.answer(),{type:"answered",call:e})},[ie]),ue=s(()=>{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=p.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,T({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]),pe=s(()=>{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){}T({type:"unmerged"}),Y()}},[Z,X,Y]),me=s(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=s(()=>{var e,n,t;const a=X.current;if(!a)return;const r=a.calls;a.dispose(),X.current=null,T({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=s(e=>E(this,void 0,void 0,function*(){var n,t,a;const r=J.current,l=K.current,s=O(e,D);if(r&&!Q.current&&s&&!X.current)try{const e=yield r.attendedTransfer(s);if(!ne.current)return;if("ended"===r.state||K.current!==l)return void e.hangup();T({type:"consultStarted",call:e}),se(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})}}),[se,Q,te,K]),he=s(()=>{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=s(()=>{const e=Q.current,n=ee.current;e&&(e.hangup(),le(e),"held"===(null==n?void 0:n.state)&&n.resume(),T({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 s=null===(a=null==n?void 0:n.notifyHost)||void 0===a||a;X.current||ae.current.size>=4?e.reject("busy"):(T({type:"incomingAdded",call:e}),s&&(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})),se(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),T({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(),T({type:"reset"})}},[e,se,te]);const xe=!W&&2===I.length&&I.every(e=>e.call.isConnected)&&!I.some(e=>null!==e.transferRole)&&u();return{calls:I,activeCall:_,incomingCalls:H,switchToCall:ce,answerCall:de,placeCall:oe,consultCall:V,heldCalls:L,transferOriginal:U,startAttendedTransfer:fe,completeAttendedTransfer:he,cancelAttendedTransfer:ve,mergedCalls:F,isMerged:W,conferenceAudio:M,canMerge:xe,mergeCalls:ue,splitMerge:pe,hangupConference:ge,holdConference:me}}(pe,me,{onIncomingCall:M,onCallStarted:P,onCallEnded:_,onError:se,placeOutbound:Y,answerIncoming:J}),Oe=function(e,r){const{disabled:l,connection:o,identityKey:i,liveCallCount:c=0}=r,[d,u]=a(!l),[p,m]=a(!1),[g,f]=a(!1),[h,v]=a([]),[x,y]=a(!1),w=b(x),[k,C]=a(null),$=b(e),N=n(!1),S=n(0),T=n(i);t(()=>{T.current!==i&&(T.current=i,N.current=!1,m(!1),f(!1),v([]),C(null),u(!l))},[i,l]);const A=s(()=>{f(!0),m(!1)},[]);t(()=>{if(l)return;if("connected"!==o)return void("disconnected"!==o&&"error"!==o||u(!1));let e=!1;return(()=>{E(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(c>0)return void u(!1);if(N.current||g)w.current||(m(!g),g||C(null));else{if(N.current=!0,null==l||l!==s.id||null==s.registered_ip)return void(yield W(a.reconnectWithEmergency(s.id),()=>{}).catch(()=>{}));m(!0),w.current||C(null)}}catch(n){e||m(!1)}finally{e||u(!1)}})})(),()=>{e=!0}},[l,o,g,$,w,c]);const z=s((e,n)=>E(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&&C(e?a(e):null)};y(!0),C(null),f(!1),N.current=!0;try{const e=yield n(),t=$.current.reconnectWithEmergency(e);yield W(t,r)}catch(e){throw C(a(e)),e}finally{y(!1)}}),[$]);return{loading:d,bound:p,savedAddresses:h,submitting:x,error:k,onNetworkChanged:A,confirm:s(e=>z("Failed to confirm emergency address",()=>E(this,void 0,void 0,function*(){return yield $.current.clearEmergencyAddressRegisteredIp(e),e})),[z,$]),create:s(e=>z("Failed to save emergency address",()=>E(this,void 0,void 0,function*(){return(yield $.current.setEmergencyAddress(e)).id})),[z,$])}}(null!=pe?pe:re,{disabled:!!$,connection:me,identityKey:o,liveCallCount:ge.length});t(()=>{if(!pe)return;const e=Oe.onNetworkChanged;return pe.on("network.changed",e),()=>pe.off("network.changed",e)},[pe,Oe.onNetworkChanged]);const Pe=V(fe,{onError:se}),je=function(e,n=!0){const[r,l]=a(null);n||"addcall"!==r||l(null);const o=s(e=>{l(n=>n===e?null:e)},[]),i=s(()=>o("keypad"),[o]),c=s(()=>o("transfer"),[o]),d=s(()=>o("devices"),[o]),u=s(()=>o("addcall"),[o]),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:i,toggleTransfer:c,toggleDevices:d,toggleAddCall:u,closeTransfer:p,closeAddCall:m}}(fe,ge.length<4),_e=U(fe),He=l(()=>ge.map(e=>e.call),[ge]),Le=function(e,r){const l=n(new Map),o=n(new Map),[i,c]=a(0);return t(()=>{var n;if(!e)return void((l.current.size>0||o.current.size>0)&&(l.current.clear(),o.current.clear(),c(e=>e+1)));const t=new Set(r.map(e=>e.id));for(const e of[...l.current.keys()])t.has(e)||l.current.delete(e);for(const e of[...o.current.keys()])t.has(e)||o.current.delete(e);for(const t of r)(null===(n=l.current.get(t.id))||void 0===n?void 0:n.from)!==e&&o.current.get(t.id)!==e&&(o.current.set(t.id,e),Promise.resolve().then(()=>e(t)).then(q,()=>null).then(n=>{var a,r;if(o.current.get(t.id)!==e)return;o.current.delete(t.id);const s=null!==(r=null===(a=l.current.get(t.id))||void 0===a?void 0:a.info)&&void 0!==r?r:null;l.current.set(t.id,{info:n,from:e}),(n||s)&&c(e=>e+1)}))},[r,e]),s(e=>{var n,t;return e&&null!==(t=null===(n=l.current.get(e.id))||void 0===n?void 0:n.info)&&void 0!==t?t:null},[i])}(L,He),Re=k(he),Be=n(me);t(()=>{null==I||I({state:me}),"connected"===me&&"connected"!==Be.current&&oe(),Be.current=me},[me,I,oe]);const Ve=l(()=>Object.assign({connection:me,webrtcPhone:pe,calls:He,activeCall:fe,incomingCalls:he,incomingRinging:Re,heldCalls:ve,answerCall:xe,switchToCall:be,actions:Pe,overlays:je,duration:_e,consultCall:Ee,transferOriginal:we,startAttendedTransfer:ke,completeAttendedTransfer:Ce,cancelAttendedTransfer:$e,placeCall:ye,mergedCalls:Ne,isMerged:Se,conferenceAudio:Te,canMerge:Ae,mergeCalls:ze,splitMerge:Ie,hangupConference:De,holdConference:Me,emergency:Oe,emergencyManagedByHost:!!$,lastError:le,clearError:oe,t:de,displayNumber:ue,palette:ce,peerInfo:Le,layoutVariant:F,directory:G},Q),[me,pe,He,fe,he,Re,ve,xe,be,Pe,je,_e,Ee,we,ke,Ce,$e,ye,Ne,Se,Te,Ae,ze,Ie,De,Me,Oe,$,le,oe,ce,Le,F,G,T,A,Q]);return e.createElement(ne.Provider,{value:Ve},X)}function se(){const e=i(ne);if(!e)throw new Error("Could not find softphone context; wrap your softphone UI in a <SoftphoneProvider>.");return e}const oe="dialstack.softphone.input_device_id",ie="dialstack.softphone.output_device_id",ce=o(null),de=e=>e.filter(e=>""!==e.deviceId).map(e=>({deviceId:e.deviceId,label:e.label})),ue=({children:n})=>{var r,l,o;const{webrtcPhone:i,activeCall:c}=se(),[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,x]=a(!1),[b,y]=a(!1),[,w]=a(0),k=c?null!==(l=null!==(r=c.effectiveAudioInputDeviceId)&&void 0!==r?r:null==i?void 0:i.audioInputDeviceId)&&void 0!==l?l:null:null!==(o=null==i?void 0:i.audioInputDeviceId)&&void 0!==o?o:g.getItem(oe),[C,$]=a(()=>g.getItem(ie));t(()=>{if(!u)return;let e=!1;const n=()=>E(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);x(t.length>0&&t.every(e=>""===e.label)),m(de(t)),h(d?de(a):[])});n();const t=()=>{n()};return navigator.mediaDevices.addEventListener("devicechange",t),()=>{e=!0,navigator.mediaDevices.removeEventListener("devicechange",t)}},[u,d,c]),t(()=>{i&&C&&i.setAudioOutputDevice(C)},[i,C]),t(()=>{const e=g.getItem(oe);i&&e&&!i.audioInputDeviceId&&i.seedAudioInputDevice(e)},[i]),t(()=>{if(!c)return;const e=()=>y(!0),n=()=>w(e=>e+1);return c.on("audioInputLost",e),c.on("audioInputChanged",n),()=>{c.off("audioInputLost",e),c.off("audioInputChanged",n),y(!1)}},[c]);const N=s(e=>{const n=()=>w(e=>e+1);null==i||i.setAudioInputDevice(e).then(()=>{y(!1),e?g.setItem(oe,e):g.removeItem(oe),n()},n)},[i]),S=s(e=>{$(e),e?g.setItem(ie,e):g.removeItem(ie),null==i||i.setAudioOutputDevice(e)},[i]),T={inputs:p,outputs:f,inputDeviceId:k,outputDeviceId:C,selectInputDevice:N,selectOutputDevice:S,outputSelectionSupported:d,enumerationSupported:u,labelsHidden:v,inputLost:b};return e.createElement(ce.Provider,{value:T},n)};function pe(){const e=i(ce);return e||{inputs:[],outputs:[],inputDeviceId:null,outputDeviceId:null,selectInputDevice:()=>{},selectOutputDevice:()=>{},outputSelectionSupported:!1,enumerationSupported:!1,labelsHidden:!1,inputLost:!1}}const me=[440,480];class ge{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 me){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 fe=ne,he=({existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:s,iceServers:o,emergencyAddressId:d,autoConnect:u=!0,appearance:p,locale:m=h,formatting:g,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:y,onCallEnded:E,onError:w,resolvePeer:k,layoutVariant:C,directory:$,appInfo:N,children:S})=>{var T,A,z,I;const D=`ds-softphone-${c().replace(/[:]/g,"")}`,M=l(()=>({scope:D}),[D]),O=i(x),[P,j]=a(()=>null==O?void 0:O.dialstack.getAppearance()),_=null!=p?p:P,H=null==O?void 0:O.dialstack;null===(T=null==H?void 0:H.registerClientComponent)||void 0===T||T.call(H,"sdk-react","softphone");const L=`${null!==(A=null==_?void 0:_.theme)&&void 0!==A?A:""}|${JSON.stringify(null!==(z=null==_?void 0:_.variables)&&void 0!==z?z:{})}`,R=null!==(I=null==g?void 0:g.defaultCountry)&&void 0!==I?I:"US",B=l(()=>function(e,n="ds-softphone"){const t=J;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 /* The large avatar shrinks first when the screen runs out of height\n (flex-shrink well above its siblings'). It is a size container, so its\n content never holds the peer block open, and below a legible size the\n disc hides rather than turning into a dot. */\n .${n} .ds-peer-avatar {\n flex: 0 100 64px; min-height: 0; max-height: 64px; width: 64px;\n align-self: center; margin-bottom: 4px;\n container-type: size; display: flex; align-items: center; justify-content: center;\n }\n .${n} .ds-peer-avatar-disc {\n height: 100%; aspect-ratio: 1; border-radius: 999px; overflow: hidden;\n display: flex; align-items: center; justify-content: center;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-size: 34cqh; font-weight: 600;\n }\n .${n} .ds-peer-avatar-disc img { width: 100%; height: 100%; object-fit: cover; }\n @container (max-height: 39px) {\n .${n} .ds-peer-avatar-disc { display: none; }\n }\n .${n} .ds-peer-avatar-sm { flex: none; width: 32px; height: 32px; margin: 0; }\n .${n} .ds-peer-avatar-sm .ds-peer-avatar-disc { font-size: 13px; }\n .${n} .ds-peer-row { display: flex; align-items: center; justify-content: center; gap: 10px; }\n .${n} .ds-peer-row-text { min-width: 0; text-align: left; }\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 12px;\n max-width: ${3*(t.controlButtonSize+12)+24}px;\n align-content: flex-end;\n margin: 0 auto;\n }\n /* Three to a row: the column gap is sized so a row of three fits the\n narrowest host (inside the scrollbar gutters) instead of wrapping to two. */\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 /* The in-call peer may give up height (its avatar first) before the screen\n has to scroll; the other children stay rigid. */\n .${n} .ds-screen-incall > .ds-peer { flex-shrink: 1; min-height: 0; }\n .${n} .ds-screen-incoming > .ds-incoming-card:not(.ds-incoming-card-compact) {\n flex-shrink: 1; min-height: 0;\n }\n .${n} .ds-incoming-card:not(.ds-incoming-card-compact) > .ds-incoming-card-info {\n min-height: 0;\n }\n /* The invisible controls placeholder (it lines the answer buttons up with\n the in-call screen) gives up its height before the caller does. */\n .${n} .ds-incoming-card > .ds-controls-slot { flex-shrink: 1000; }\n .${n} .ds-screen-incall:has(.ds-dtmf) > .ds-peer { flex: 0 0 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-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 /* The transfer / add-call screen: it fills the in-call screen above hang\n up, and only the directory list flexes (and scrolls). */\n .${n} .ds-dial-panel {\n display: flex; flex-direction: column; gap: 10px;\n flex: 1 1 auto; min-height: 0;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+24}px; margin: 0 auto;\n }\n .${n} .ds-screen > .ds-dial-panel { flex-shrink: 1; }\n .${n} .ds-dial-panel > * { flex: none; }\n /* Same spot in both modes, just above hang up. */\n .${n} .ds-dial-panel > .ds-transfer-actions { margin-top: auto; }\n /* Sits with the buttons, so it moves down with them. */\n .${n} .ds-dial-panel > .ds-dial-panel-target { margin-top: auto; }\n .${n} .ds-dial-panel > .ds-dial-panel-target + .ds-transfer-actions { margin-top: 0; }\n /* With just the field, the auto margins split the spare height a third\n above, two thirds below: within reach in a tall host instead of pinned\n to the top. The list stays anchored to the top (so the header doesn't\n move as a search shortens it) and grows to its content, scrolling only\n once it reaches the buttons. */\n .${n} .ds-dial-panel-main {\n display: flex; flex-direction: column; gap: 10px; margin-block: auto;\n }\n .${n} .ds-dial-panel-main > * { flex: none; }\n .${n} .ds-dial-panel > .ds-dial-panel-main-list {\n flex: 0 1 auto; min-height: 0; margin-block: 0;\n }\n .${n} .ds-dial-panel-header { display: flex; align-items: flex-start; gap: 8px; }\n .${n} .ds-dial-panel-heading { flex: 1; min-width: 0; }\n .${n} .ds-dial-panel-title { font-size: 18px; font-weight: 600; }\n .${n} .ds-dial-panel-peer {\n font-size: 13px; color: var(--dsd-text-secondary);\n overflow: hidden; text-overflow: ellipsis; white-space: nowrap;\n }\n .${n} .ds-dial-panel-close {\n flex: none; width: 36px; height: 36px; padding: 8px;\n border: none; border-radius: 50%; cursor: pointer;\n background: var(--dsd-surface); color: var(--dsd-text);\n }\n .${n} .ds-dial-panel-close:hover { background: var(--dsd-surface-active); }\n .${n} .ds-dial-panel-close svg { width: 100%; height: 100%; display: block; }\n .${n} .ds-dial-panel-mode {\n align-self: center; border: none; background: none; padding: 4px 8px;\n color: var(--dsd-accent); font-family: inherit; font-size: 14px; font-weight: 500;\n cursor: pointer;\n }\n .${n} .ds-dial-panel-mode:hover { text-decoration: underline; }\n .${n} .ds-dial-panel-target {\n font-size: 13px; color: var(--dsd-text-secondary); text-align: center;\n overflow: hidden; text-overflow: ellipsis; white-space: nowrap;\n }\n .${n} .ds-dial-panel-main > .ds-directory {\n display: flex; flex-direction: column; gap: 8px; flex: 0 1 auto; min-height: 0;\n }\n .${n} .ds-directory-search { flex: none; }\n .${n} .ds-directory-options {\n display: flex; flex-direction: column; gap: 4px;\n flex: 0 1 auto; min-height: 0; overflow-y: auto;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-surface); padding: 4px;\n }\n .${n} .ds-directory-group {\n padding: 6px 10px 2px; font-size: 11px; font-weight: 600;\n text-transform: uppercase; letter-spacing: 0.04em; color: var(--dsd-text-secondary);\n }\n .${n} .ds-directory-option {\n display: flex; flex-direction: column; align-items: flex-start; gap: 2px;\n width: 100%; padding: 8px 10px; text-align: left; cursor: pointer;\n border: 1px solid transparent; border-radius: ${Math.max(t.radius-4,4)}px;\n background: none; color: var(--dsd-text); font-family: inherit;\n }\n .${n} .ds-directory-option:hover { background: var(--dsd-surface-active); }\n .${n} .ds-directory-option[aria-pressed='true'] {\n border-color: var(--dsd-accent);\n background: color-mix(in srgb, var(--dsd-accent) 12%, transparent);\n }\n .${n} .ds-directory-option-title {\n display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;\n }\n .${n} .ds-directory-option-label { font-size: 14px; font-weight: 500; }\n .${n} .ds-directory-tag {\n padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 500;\n /* Not surface-active: that is the row's hover fill, which would swallow\n the chip under the pointer. */\n background: var(--dsd-bg); color: var(--dsd-text-secondary);\n }\n .${n} .ds-directory-option-detail { font-size: 12px; color: var(--dsd-text-secondary); }\n .${n} .ds-directory-empty {\n padding: 10px; font-size: 13px; text-align: center; color: var(--dsd-text-secondary);\n }\n\n .${n} .ds-devices {\n display: flex; flex-direction: column; gap: 10px;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+24}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} .ds-conference-party {\n display: flex; align-items: center; gap: 10px; align-self: stretch; min-width: 0;\n }\n .${n} .ds-conference-party-name {\n min-width: 0; font-size: 17px; font-weight: 600;\n white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\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 /* Compact size tier for small hosts (narrower than 300px or shorter than\n 480px; set by useRoomyHost). Everything steps down together so the\n screens fit instead of clipping; a host smaller still scrolls. */\n .ds-host-small.${n}, .ds-host-small > .${n} { padding: 12px; }\n .ds-host-small .ds-screen { gap: 8px; }\n .ds-host-small .ds-screen-dial { padding-top: 18px; }\n .ds-host-small .ds-display { min-height: 36px; }\n .ds-host-small .ds-destination, .ds-host-small .ds-peer-name { font-size: 20px; }\n .ds-host-small .ds-peer-number { font-size: 13px; }\n .ds-host-small .ds-callstate { margin-top: 2px; }\n .ds-host-small .ds-callstate-text { font-size: 12px; }\n .ds-host-small .ds-duration { font-size: 15px; }\n .ds-host-small .ds-keypad { gap: 6px; max-width: min(156px, 100%); }\n .ds-host-small .ds-key { max-width: 48px; }\n .ds-host-small .ds-key-digit { font-size: 18px; }\n .ds-host-small .ds-key-letters { font-size: 8px; min-height: 9px; }\n .ds-host-small .ds-actions { gap: 32px; padding-top: 4px; }\n .ds-host-small .ds-action { width: 48px; height: 48px; }\n .ds-host-small .ds-controls { gap: 4px 8px; max-width: 184px; }\n .ds-host-small .ds-controls > * { flex-basis: 56px; }\n .ds-host-small .ds-control { gap: 3px; }\n .ds-host-small .ds-control-glyph { width: 42px; height: 42px; }\n .ds-host-small .ds-control-label { font-size: 10px; }\n .ds-host-small .ds-held-call { padding: 8px 10px; }\n .ds-host-small .ds-held-call .ds-peer-name { font-size: 15px; }\n .ds-host-small .ds-held-calls { gap: 4px; }\n .ds-host-small .ds-chip { font-size: 10px; padding: 2px 8px; }\n .ds-host-small .ds-e911-toggle { padding: 6px 8px; font-size: 11px; gap: 6px; }\n .ds-host-small .ds-transfer-input { padding: 6px 10px; font-size: 14px; }\n .ds-host-small .ds-dial-panel, .ds-host-small .ds-dial-panel-main { gap: 6px; }\n .ds-host-small .ds-dial-panel-title { font-size: 15px; }\n .ds-host-small .ds-dial-panel-close { width: 30px; height: 30px; padding: 7px; }\n .ds-host-small .ds-dial-panel-mode { font-size: 12px; padding: 2px 6px; }\n .ds-host-small .ds-directory-option { padding: 5px 8px; }\n .ds-host-small .ds-directory-option-label { font-size: 13px; }\n .ds-host-small .ds-directory-tag { font-size: 10px; padding: 0 6px; }\n .ds-host-small .ds-transfer-actions, .ds-host-small .ds-consult-actions { gap: 6px; }\n .ds-host-small .ds-transfer-send, .ds-host-small .ds-e911-btn { padding: 7px 8px; font-size: 12px; }\n .ds-host-small .ds-incoming-card-compact { padding: 8px 10px; gap: 8px; }\n .ds-host-small .ds-incoming-card-compact .ds-peer-name { font-size: 13px; }\n .ds-host-small .ds-incoming-card-compact .ds-action { width: 36px; height: 36px; }\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 `}(ee(_),D),[L,D]);return e.createElement(le,{existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:s,iceServers:o,emergencyAddressId:d,autoConnect:u,client:()=>{var e;return(null===(e=null==H?void 0:H.clientHeader)||void 0===e?void 0:e.call(H))||v.forComponent("sdk-react","3.8.0","softphone",N)},appearance:_,locale:m,defaultCountry:R,onConnectionStateChange:f,onIncomingCall:b,onCallStarted:y,onCallEnded:E,onError:w,resolvePeer:k,layoutVariant:C,directory:$,extra:M},O&&e.createElement(be,{dialstack:O.dialstack,onChange:j}),e.createElement("style",null,B),e.createElement(ue,null,S,e.createElement(ve,null),e.createElement(xe,{onError:w})))},ve=()=>{const{incomingRinging:e}=ye(),{outputDeviceId:a}=pe(),r=n(null);return null===r.current&&(r.current=new ge),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},xe=({onError:a})=>{const{activeCall:r,conferenceAudio:l}=ye(),{outputDeviceId:s}=pe(),o=n(null);return t(()=>{const e=o.current;e&&"function"==typeof e.setSinkId&&e.setSinkId(null!=s?s:"").catch(()=>{})},[s,r]),t(()=>{const e=o.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 i=()=>s(!0);return n.on("answered",i),()=>{n.off("answered",i)}},[r,l,a]),e.createElement("audio",{ref:o,autoPlay:!0})},be=({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},ye=()=>se(),Ee=()=>{const{activeCall:e,actions:n}=ye();return{activeCall:e,actions:n}},we=()=>{const{incomingCalls:e}=ye();return function(e){var n;return null!==(n=e.find(w))&&void 0!==n?n:null}(e)},ke={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"}},Ce=({glyph:n})=>e.createElement("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},e.createElement("path",{d:n.path,transform:n.transform})),$e=({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(L(n.code))),e.createElement("button",{type:"button",className:"ds-call-error-dismiss","aria-label":a("dismiss"),onClick:t},"✕")):null,Ne="ds-softphone",Se=o(null);function Te(e,n,r){var l,s;const o=null!==(s=null===(l=i(ne))||void 0===l?void 0:l.layoutVariant)&&void 0!==s?s:"auto",[c,d]=a("compact"!==o);return t(()=>{const t=n?e():null;if(!t||"undefined"==typeof ResizeObserver)return;const a=new ResizeObserver(()=>{const{width:e,height:n}=t.getBoundingClientRect(),a=function(e,n){return"compact"!==e&&("full"===e||n)}(o,e>=300&&n>=480);t.classList.toggle("ds-host-small",!a),d(a)});return a.observe(t),()=>{a.disconnect(),t.classList.remove("ds-host-small")}},[o,n,r]),c}function Ae(){const e=n(null),t=i(Se),a=Te(()=>{var n,t,a,r;let l=null!==(t=null===(n=e.current)||void 0===n?void 0:n.closest(".ds-softphone"))&&void 0!==t?t:e.current;for(let e=null===(a=null==l?void 0:l.parentElement)||void 0===a?void 0:a.closest(".ds-softphone");e;e=null===(r=e.parentElement)||void 0===r?void 0:r.closest(".ds-softphone"))l=e;return l},null===t);return{ref:e,roomy:null!=t?t:a}}const ze=({connection:n,destination:t,onDestinationChange:a,onDestinationPaste:r,canCall:l,onCall:s,destinationRef:o,error:i=null,onDismissError:c=()=>{},scope:d=Ne,t:u})=>{const{ref:p}=Ae();return e.createElement("div",{ref:p,className:`${d} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-dial"},e.createElement(Ie,{connection:n,t:u}),e.createElement($e,{error:i,onDismiss:c,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:o,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&&s())}}),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")},Z.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:s},e.createElement(Ce,{glyph:ke.phone})))))},Ie=({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"})}},De=({autoFocusDestination:r=!1})=>{const{connection:l,placeCall:s,emergency:o,lastError:i,clearError:c,t:d,scope:u}=ye(),[p,m]=a(""),{onType:g,onPasteText:f}=G(m),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,p,o.submitting);return e.createElement(ze,{connection:l,destination:p,onDestinationChange:g,onDestinationPaste:f,canCall:v,onCall:()=>{s(p)},destinationRef:h,error:i,onDismissError:c,scope:u,t:d})},Me={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 Oe(e){const n=e.trim(),t=Me[n.toLowerCase()];return t||(/^[a-z]{2}$/i.test(n)?n.toUpperCase():n)}const Pe={address_number:"",street:"",unit:"",city:"",state:"",postal_code:""},je=({savedAddresses:n,submitting:t,error:r,onConfirm:l,onCreate:s,defaultExpanded:o=!1,defaultAddingNew:i=!1,scope:c=Ne,t:d})=>{const[u,p]=a(o),[m,g]=a(i),[f,h]=a(Pe),v=e=>n=>h(t=>Object.assign(Object.assign({},t),{[e]:n.target.value}));return e.createElement("div",{className:`${c} 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:()=>p(e=>!e)},e.createElement("span",null,e.createElement(Ce,{glyph:ke.location})),e.createElement("span",{className:"ds-e911-label"},d("emergencyPrompt")),e.createElement("span",{className:"ds-e911-chevron"},e.createElement(Ce,{glyph:ke.chevronDown}))),u&&e.createElement("div",{className:"ds-e911-body"},e.createElement("p",{className:"ds-e911-hint"},d("emergencyHint")),!m&&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(()=>p(!1)).catch(()=>{});var e}},e.createElement(Ce,{glyph:ke.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")))),!m&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>g(!0)},d("emergencyNewLocation")),m&&e.createElement("form",{className:"ds-e911-body",style:{padding:0,borderTop:"none"},onSubmit:e=>{e.preventDefault(),s(Object.assign(Object.assign({},f),{state:Oe(f.state),unit:f.unit||void 0})).then(()=>{p(!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:`${c}-ea-num`},d("emergencyNumber")),e.createElement("input",{id:`${c}-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:`${c}-ea-street`},d("emergencyStreet")),e.createElement("input",{id:`${c}-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:`${c}-ea-unit`},d("emergencyUnit")),e.createElement("input",{id:`${c}-ea-unit`,className:"ds-e911-input",value:f.unit,onChange:v("unit")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${c}-ea-city`},d("emergencyCity")),e.createElement("input",{id:`${c}-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:`${c}-ea-state`},d("emergencyState")),e.createElement("input",{id:`${c}-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:`${c}-ea-zip`},d("emergencyPostalCode")),e.createElement("input",{id:`${c}-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")))))))},_e=()=>{const{emergency:n,emergencyManagedByHost:t,activeCall:a,t:r,scope:l}=ye();return t||n.loading||n.bound||a?null:e.createElement(je,{savedAddresses:n.savedAddresses,submitting:n.submitting,error:n.error,onConfirm:n.confirm,onCreate:n.create,scope:l,t:r})},He=()=>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"}," ")))),Le=({avatar:n,size:t="lg"})=>{const[r,l]=a(null);if(!n)return null;const s=n.uri&&n.uri!==r?n.uri:null;return s||n.initials?e.createElement("div",{className:"sm"===t?"ds-peer-avatar-sm":"ds-peer-avatar","aria-hidden":"true"},e.createElement("div",{className:"ds-peer-avatar-disc"},s?e.createElement("img",{src:s,alt:"",onError:()=>l(s)}):e.createElement("span",null,n.initials))):null},Re=({avatar:n,children:t})=>n?e.createElement("div",{className:"ds-peer-row"},e.createElement(Le,{avatar:n,size:"sm"}),e.createElement("div",{className:"ds-peer-row-text"},t)):e.createElement(e.Fragment,null,t),Be=({name:n,number:t=null,avatar:a,compact:r=!1,onAnswer:l,onDecline:s,t:o})=>{const{ref:i,roomy:c}=Ae();return e.createElement("div",{ref:i,className:"ds-incoming-card "+(r?"ds-incoming-card-compact":"")},e.createElement("div",{className:"ds-peer ds-incoming-card-info"},!r&&c&&e.createElement(Le,{avatar:a}),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"}," "))),!r&&e.createElement(He,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:s},e.createElement(Ce,{glyph:ke.hangup})),e.createElement("button",{type:"button",className:"ds-action ds-answer","aria-label":o("answer"),onClick:l},e.createElement(Ce,{glyph:ke.phone}))))},Ve=({call:n,compact:t=!1})=>{const{answerCall:a,actions:r,t:l,displayNumber:s,peerInfo:o}=ye(),{name:i,number:c,avatar:d}=N(n,o(n),s,l("unknownCaller"));return e.createElement(Be,{name:i,number:c,avatar:d,compact:t,onAnswer:()=>a(n),onDecline:()=>r.callActionsFor(n).reject(),t:l})},Ue=()=>{const{incomingCalls:n,scope:t}=ye(),a=n[0];return a?e.createElement("div",{className:`${t} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incoming"},e.createElement(Ve,{call:a}))):null},Fe=({compact:n})=>{const{incomingCalls:t,scope:a}=ye();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(Ve,{key:n.id,call:n,compact:r}))))},We=({inputs:n,outputs:t,inputDeviceId:a,outputDeviceId:r,onSelectInput:l,onSelectOutput:s,outputSelectionSupported:o,enumerationSupported:i,labelsHidden:c,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:!o,onChange:e=>s(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"))))),!i&&e.createElement("p",{className:"ds-device-hint"},u("audioDevicesUnsupported")),!o&&e.createElement("p",{className:"ds-device-hint"},u("audioSpeakerUnsupported")),c&&e.createElement("p",{className:"ds-device-hint"},u("audioLabelsHidden"))),Ke=()=>{const{t:n}=ye(),{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:l,selectInputDevice:s,selectOutputDevice:o,outputSelectionSupported:i,enumerationSupported:c,labelsHidden:d,inputLost:u}=pe();return e.createElement(We,{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:l,onSelectInput:s,onSelectOutput:o,outputSelectionSupported:i,enumerationSupported:c,labelsHidden:d,inputLost:u,t:n})},qe=({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(Ce,{glyph:t})),e.createElement("span",{className:"ds-control-label"},n)),Ge=({destinations:n,isSelected:t,onPick:r,t:l})=>{const[s,o]=a(""),i=c(),d=function(e,n){var t;const a=n.trim().toLowerCase(),r=/^[\d\s()+.-]+$/.test(a)?a.replace(/\D/g,""):"",l=e=>{var n;return!a||[e.label,e.description,e.group,e.destination,...null!==(n=e.tags)&&void 0!==n?n:[]].some(e=>"string"==typeof e&&e.toLowerCase().includes(a))||r.length>=2&&e.destination.replace(/\D/g,"").includes(r)},s=[],o=new Map;for(const n of e){if(!l(n))continue;const e=null===(t=n.group)||void 0===t?void 0:t.trim();if(!e){s.push(n);continue}let a=o.get(e);a||o.set(e,a=[]),a.push(n)}const i=[];s.length&&i.push({group:void 0,destinations:s});for(const[e,n]of o)i.push({group:e,destinations:n});return i}(n,s);return e.createElement("div",{className:"ds-directory"},e.createElement("input",{className:"ds-transfer-input ds-directory-search",type:"search",value:s,placeholder:l("directorySearchPlaceholder"),"aria-label":l("directorySearchPlaceholder"),"aria-controls":i,autoComplete:"off",onChange:e=>o(e.target.value)}),e.createElement("div",{id:i,className:"ds-directory-options","aria-label":l("directoryLabel")},0===d.length&&e.createElement("div",{className:"ds-directory-empty"},l("directoryNoMatches")),d.map(({group:n,destinations:a})=>e.createElement("div",{key:null!=n?n:"",role:"group","aria-label":n},n&&e.createElement("div",{className:"ds-directory-group","aria-hidden":"true"},n),a.map(n=>e.createElement("button",{type:"button",key:n.id,className:"ds-directory-option","aria-pressed":t(n),onClick:()=>r(n)},e.createElement("span",{className:"ds-directory-option-title"},e.createElement("span",{className:"ds-directory-option-label"},n.label),function(e){var n;return(null!==(n=e.tags)&&void 0!==n?n:[]).map(e=>e.trim()).filter(Boolean)}(n).map((n,t)=>e.createElement("span",{key:`${n}|${t}`,className:"ds-directory-tag"},n))),e.createElement("span",{className:"ds-directory-option-detail"},n.description||n.destination)))))))},Ye=({title:n,peerName:t,directory:r,picked:l,onPick:s,value:o,placeholder:i,onChange:c,onPaste:d,actions:u,onClose:p,t:m})=>{const[g,f]=a(!1),h=r.length>0,v=g||!h;return e.createElement("div",{className:"ds-dial-panel"},e.createElement("div",{className:"ds-dial-panel-main"+(v?"":" ds-dial-panel-main-list")},e.createElement("div",{className:"ds-dial-panel-header"},e.createElement("div",{className:"ds-dial-panel-heading"},e.createElement("div",{className:"ds-dial-panel-title"},n),e.createElement("div",{className:"ds-dial-panel-peer"},t)),e.createElement("button",{type:"button",className:"ds-dial-panel-close","aria-label":m("cancel"),onClick:p},e.createElement(Ce,{glyph:ke.close}))),v?e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:o,placeholder:i,"aria-label":i,autoComplete:"off",autoFocus:!0,onChange:e=>c(e.target.value),onPaste:e=>{e.preventDefault(),d(e.clipboardData.getData("text"))}}):e.createElement(Ge,{destinations:r,isSelected:e=>e.id===(null==l?void 0:l.id),onPick:s,t:m}),h&&e.createElement("button",{type:"button",className:"ds-dial-panel-mode",onClick:()=>f(!g)},m(g?"chooseFromDirectory":"enterNumber"))),!v&&o.trim()&&e.createElement("div",{className:"ds-dial-panel-target"},m("dialTarget"),": ",l?`${l.label} · ${o}`:o),e.createElement("div",{className:"ds-transfer-actions"},u))},Je=[],Qe=({peer:n,stateLabel:t,duration:a,showDuration:r,isActive:l,isMuted:s,isHeld:o,isMerged:i,conferenceParties:c,conferenceLabel:d,transferOther:u,canCompleteTransfer:p,onSwitchToTransferOther:m,onCancelTransfer:g,onCompleteTransfer:f,switchableHeld:h,onSwitchToCall:v,error:x=null,onDismissError:b=()=>{},overlay:y,canSendDtmf:E,dtmfEntered:w,onSendDtmf:k,transferTo:C,onTransferToChange:$,onTransferToPaste:N,directory:S=Je,onPickTransferContact:T=()=>{},pickedTransferContact:A=null,onPickAddCallContact:z=()=>{},pickedAddCallContact:I=null,onBlindTransfer:D,onConsultTransfer:M,addCallTo:O,onAddCallToChange:P,onAddCallToPaste:j,onSubmitAddCall:_,devicesPanel:H=null,canStartTransfer:L,canAddCall:R,canMerge:B,onToggleMute:V,onToggleHold:U,onToggleOverlay:F,onMergeOrSplit:W,onHangup:K,scope:q=Ne,t:G})=>{const Y=l&&"keypad"===y&&E,J=l&&"transfer"===y&&L,Q=l&&"addcall"===y&&R,X=J||Q,{ref:ee,roomy:ne}=Ae();return e.createElement("div",{ref:ee,className:`${q} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incall "+(l?"ds-screen-active":"ds-screen-outgoing")},u&&!X&&e.createElement("div",{className:"ds-transfer-banner"},e.createElement("button",{type:"button",className:"ds-held-call ds-consult-held","aria-label":`${G("switchToCall")}: ${u.name}`,onClick:m},e.createElement(Re,{avatar:u.avatar},e.createElement("div",{className:"ds-peer-name"},u.name),e.createElement("div",{className:"ds-callstate-text"},G("transferOriginalOnHold")))),e.createElement("div",{className:"ds-consult-actions"},e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:g},G("cancel")),e.createElement("button",{type:"button",className:"ds-e911-btn",disabled:!p,onClick:f},G("transferComplete")))),h.length>0&&!X&&e.createElement("div",{className:"ds-held-calls",role:"group","aria-label":G("heldCallsLabel")},h.map(n=>e.createElement("button",{type:"button",key:n.id,className:"ds-held-call ds-consult-held","aria-label":`${G("switchToCall")}: ${n.name}`,onClick:()=>v(n.id)},e.createElement(Re,{avatar:n.avatar},e.createElement("div",{className:"ds-peer-name"},n.name),e.createElement("div",{className:"ds-callstate-text"},G("heldCallsLabel")))))),X?null:i?e.createElement("div",{className:"ds-peer ds-peer-conference"},e.createElement("div",{className:"ds-callstate-text"},d),e.createElement("div",{className:"ds-conference-parties"},c.map(n=>e.createElement("div",{key:n.id,className:"ds-conference-party"},e.createElement(Le,{avatar:n.avatar,size:"sm"}),e.createElement("div",{className:"ds-conference-party-name"},n.name)))),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-duration"},a))):e.createElement("div",{className:"ds-peer"},ne&&!Y&&e.createElement(Le,{avatar:n.avatar}),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"},Y?e.createElement("span",{className:"ds-dtmf-readout"},w||" "):e.createElement("span",{className:"ds-callstate-text"},t),!Y&&e.createElement("span",{className:"ds-duration","aria-hidden":!r},r?a:" "))),e.createElement($e,{error:x,onDismiss:b,t:G}),l&&"keypad"===y&&E&&e.createElement("div",{className:"ds-dtmf"},e.createElement("div",{className:"ds-keypad ds-keypad-dtmf",role:"group","aria-label":G("keypad")},Z.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))))),J&&e.createElement(Ye,{title:G("transfer"),peerName:n.name,directory:S,picked:A,onPick:T,value:C,placeholder:G("transferPlaceholder"),onChange:$,onPaste:N,actions:e.createElement(e.Fragment,null,e.createElement("button",{type:"button",className:"ds-transfer-send ds-transfer-send-secondary",disabled:!C.trim(),onClick:D},G("transferNow")),e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!C.trim(),onClick:M},G("transferConsult"))),onClose:()=>F("transfer"),t:G}),Q&&e.createElement(Ye,{title:G("addCall"),peerName:n.name,directory:S,picked:I,onPick:z,value:O,placeholder:G("addCallPlaceholder"),onChange:P,onPaste:j,actions:e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!O.trim(),onClick:_},G("addCallSend")),onClose:()=>F("addcall"),t:G}),l&&"devices"===y&&H,!l&&e.createElement(He,null),l&&!Y&&!X&&e.createElement("div",{className:"ds-controls",role:"group"},e.createElement(qe,{label:G(s?"unmute":"mute"),glyph:s?ke.micOff:ke.mic,on:s,onClick:V}),e.createElement(qe,{label:G(o?"resume":"hold"),glyph:ke.pause,on:o,onClick:U}),E&&e.createElement(qe,{label:G("keypad"),glyph:ke.keypad,on:"keypad"===y,onClick:()=>F("keypad")}),e.createElement(qe,{label:G("addCall"),glyph:ke.addCall,on:"addcall"===y,disabled:!R||i,onClick:()=>F("addcall")}),B||i?e.createElement(qe,{label:G(i?"split":"merge"),glyph:ke.merge,on:i,onClick:W}):e.createElement(qe,{label:G("transfer"),glyph:ke.transfer,on:"transfer"===y,disabled:!L,onClick:()=>F("transfer")}),e.createElement(qe,{label:G("audioDevices"),glyph:ke.speaker,on:"devices"===y,onClick:()=>F("devices")})),e.createElement("div",{className:"ds-actions"},Y?e.createElement("button",{type:"button",className:"ds-action ds-keypad-close","aria-label":G("keypad"),onClick:()=>F("keypad")},e.createElement(Ce,{glyph:ke.close})):e.createElement("button",{type:"button",className:"ds-action ds-hangup","aria-label":G("hangUp"),onClick:K},e.createElement(Ce,{glyph:ke.hangup})))))},Xe=()=>{var n;const{activeCall:r,actions:l,overlays:s,duration:o,consultCall:i,transferOriginal:c,heldCalls:d,incomingCalls:u,switchToCall:p,startAttendedTransfer:m,completeAttendedTransfer:g,cancelAttendedTransfer:f,placeCall:h,calls:v,mergedCalls:x,isMerged:b,canMerge:y,mergeCalls:E,splitMerge:w,hangupConference:k,holdConference:$,t:S,displayNumber:T,peerInfo:A,scope:z,lastError:I,clearError:D,directory:M}=ye(),{showKeypad:O,showTransfer:P,showDevices:j,showAddCall:H}=s,[L,R]=a(""),B=Y(),V=Y(),U=B.value,F=V.value,{clear:W}=B,{clear:K}=V,q=null!==(n=null==r?void 0:r.id)&&void 0!==n?n:null;if(t(()=>{R(""),W(),K()},[q,W,K]),!r)return null;const G=C(r),J=r.canSendDtmf,Q=null!==i&&null!==c,X=Q&&(r===i||r===c),Z=X?r===i?c:i:null,ee=X&&null!==i&&i.isConnected,ne=d.filter(e=>e!==Z&&!x.includes(e)),te=d.length+u.length,ae=!Q&&!b&&0===te,re=b&&x.some(e=>"held"===e.state),le=v.length<4,se=le?F:"",oe=e=>Object.assign({id:e.id},N(e,A(e),T,S("unknownCaller"))),ie=O?"keypad":P?"transfer":j?"devices":H?"addcall":null;return e.createElement(Qe,{peer:oe(r),stateLabel:S(_(r.state)),duration:o,showDuration:"active"===r.state,isActive:G,isMuted:r.isMuted,isHeld:re||"held"===r.state,isMerged:b,conferenceParties:x.map(oe),conferenceLabel:S("conferenceLabel"),transferOther:X&&Z?oe(Z):null,canCompleteTransfer:ee,onSwitchToTransferOther:()=>Z&&p(Z),onCancelTransfer:f,onCompleteTransfer:g,switchableHeld:ne.map(oe),onSwitchToCall:e=>{const n=ne.find(n=>n.id===e);n&&p(n)},error:I,onDismissError:D,overlay:ie,canSendDtmf:J,dtmfEntered:L,onSendDtmf:e=>{l.sendDtmf(e),R(n=>n+e)},transferTo:U,onTransferToChange:B.onType,onTransferToPaste:B.onPasteText,directory:M,onPickTransferContact:B.pick,pickedTransferContact:B.picked,onPickAddCallContact:V.pick,pickedAddCallContact:le?V.picked:null,onBlindTransfer:()=>{l.transfer(U)&&(W(),s.closeTransfer())},onConsultTransfer:()=>{m(U)},addCallTo:se,onAddCallToChange:V.onType,onAddCallToPaste:V.onPasteText,onSubmitAddCall:()=>{const e=se.trim();e&&(h(e),K(),s.closeAddCall())},devicesPanel:e.createElement(Ke,null),canStartTransfer:ae,canAddCall:le,canMerge:y,onToggleMute:l.toggleMute,onToggleHold:b?()=>$(!re):l.toggleHold,onToggleOverlay:e=>{e===ie&&"transfer"===e&&W(),e===ie&&"addcall"===e&&K(),"keypad"===e?s.toggleKeypad():"transfer"===e?s.toggleTransfer():"devices"===e?s.toggleDevices():s.toggleAddCall()},onMergeOrSplit:b?w:E,onHangup:b?k:l.hangup,scope:z,t:S})},Ze=({autoFocusDestination:n})=>{const{calls:t,activeCall:a,scope:r}=ye(),l=function(e,n=null){const t=e.filter(e=>e!==n&&w(e)),a=e.some(e=>e===n||!w(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(Ue,null):e.createElement(Fe,{compact:l.compact});const s="in-call"===l.base?e.createElement(Xe,null):e.createElement(en,{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(Fe,{compact:l.compact})),s)},en=({autoFocusDestination:n})=>{const{scope:t}=ye();return e.createElement("div",{className:`${t} ds-dial-screen`},e.createElement(_e,null),e.createElement(De,{autoFocusDestination:n}))},nn=({autoFocusDestination:n})=>{if(null===i(fe))throw new Error("<Softphone> must be rendered inside a <SoftphoneProvider>. The provider owns the connection and the token. See https://docs.dialstack.ai/sdks/components/softphone.");return e.createElement(tn,{autoFocusDestination:n})},tn=({autoFocusDestination:n})=>{const{ref:t,roomy:r}=function(){const[e,n]=a(null);return{ref:n,roomy:Te(()=>null==e?void 0:e.parentElement,!0,e)}}();return e.createElement(Se.Provider,{value:r},e.createElement("span",{ref:t,hidden:!0}),e.createElement(Ze,{autoFocusDestination:n}))};export{D as DIAL_COUNTRY,De as DialPad,_e as EmergencyBanner,Ue as IncomingCall,Fe as IncomingStack,Xe as OngoingCall,nn as Softphone,he as SoftphoneProvider,T as callPeerName,S as callPeerNumber,_ as callStateLabelKey,L as errorMessageKey,A as formatCallDuration,z as formatDisplayNumber,C as isCallActive,w as isIncomingRinging,O as sanitizeDestination,$ as selectScreen,k as shouldRingIncoming,M as stripToDialString,Ee as useActiveCall,V as useCallActions,U as useCallDuration,G as useDialInput,we as useIncomingCall,K as useLastError,ye as useSoftphone};
1
+ import e,{useRef as n,useEffect as t,useState as a,useReducer as r,useMemo as s,useCallback as o,createContext as l,useContext as i,useId as c,useLayoutEffect as d}from"react";import{DialStackPhone as u,supportsConference as p,LocalConference as m,createPaginatedList as h,storage as g}from"@dialstack/sdk-webrtc";import{parsePhoneNumber as f}from"libphonenumber-js";import{defaultLocale as v,ClientInfo as x}from"@dialstack/sdk-js/pure";import{DialstackComponentsContext as y}from"@dialstack/sdk-react";function b(e){const a=n(e);return t(()=>{a.current=e},[e]),a}function w(e){const{autoConnect:n=!0,onError:r,existingPhone:s}=e,[o,l]=a(null!=s?s:null),[i,c]=a(s?s.isConnected?"connected":s.isConnecting||n?"connecting":"idle":n&&e.token?"connecting":"idle"),d=b({onError:r}),p=b(e.emergencyAddressId),m=b(e.iceServers),h=b(e.storage),g=b(e.ringback),f=b(e.createSignalingSocket),v=b(e.onAppResume),x=b(e.client),y=b(e.onTokenExpiring),{token:w,apiBaseUrl:k,signalingBaseUrl:E,autoReconnect:C}=e;t(()=>{var e;if(s){let e=!1;const t=n=>()=>{e||n()},a=t(()=>c("connected")),r=t(()=>c("reconnecting")),o=t(()=>c("disconnected")),l=n=>{var t,a;e||(null===(a=(t=d.current).onError)||void 0===a||a.call(t,{code:n.code,message:n.message}),n.fatal&&c("error"))};return s.on("connected",a),s.on("reconnected",a),s.on("reconnecting",r),s.on("disconnected",o),s.on("error",l),!n||s.isConnected||s.isConnecting||s.connect().catch(n=>{var t,a,r,s;if(e)return;const o=n;null===(a=(t=d.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!==(s=null==o?void 0:o.message)&&void 0!==s?s:String(n)}),c("error")}),()=>{e=!0,s.off("connected",a),s.off("reconnected",a),s.off("reconnecting",r),s.off("disconnected",o),s.off("error",l)}}if(!w)return;let t=!1;const a=(r={token:w,apiBaseUrl:k,signalingBaseUrl:E,emergencyAddressId:p.current,iceServers:m.current,storage:h.current,ringback:g.current,createSignalingSocket:f.current,onAppResume:v.current,client:null===(e=x.current)||void 0===e?void 0:e.call(x),autoReconnect:C,onTokenExpiring:y.current?()=>{const e=y.current;return e?e():Promise.reject(new Error("onTokenExpiring not set"))}:void 0},new u(r));var r;l(a);const o=e=>()=>{t||e()};return a.on("connected",o(()=>c("connected"))),a.on("reconnected",o(()=>c("connected"))),a.on("reconnecting",o(()=>c("reconnecting"))),a.on("disconnected",o(()=>c("disconnected"))),a.on("error",e=>{var n,a;t||(null===(a=(n=d.current).onError)||void 0===a||a.call(n,{code:e.code,message:e.message}),e.fatal&&c("error"))}),n&&(c("connecting"),a.connect().catch(e=>{var n,a,r,s;"transport_closed"!==(null==e?void 0:e.code)&&(null===(a=(n=d.current).onError)||void 0===a||a.call(n,{code:null!==(r=null==e?void 0:e.code)&&void 0!==r?r:"internal_error",message:null!==(s=null==e?void 0:e.message)&&void 0!==s?s:String(e)}),t||c("error"))})),()=>{t=!0,a.disconnect(),l(null),c("idle")}},[s,w,k,E,C,n,d,p,m,h,g,f,v,y]);const $=!s||"idle"!==i&&"connecting"!==i?i:s.isConnected?"connected":s.isConnecting?"connecting":i;return{phone:null!=s?s:o,connection:$}}function k(e,n,t,a){return new(t||(t=Promise))(function(r,s){function o(e){try{i(a.next(e))}catch(e){s(e)}}function l(e){try{i(a.throw(e))}catch(e){s(e)}}function i(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(o,l)}i((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 $(e){return e.isConnected}function N(e,n,t){return"connected"===e&&n.length>0&&!t}function T(e,n){const{allowed:t=!0,placeCall:a,pick:r,onCalled:s}=n;r(e),t&&N(n.connection,e.destination,n.emergencySubmitting)&&(a(e.destination),null==s||s())}function S(e){return e?E(e)?"incoming":"in-call":"dial"}function z(e,n,t,a){const r=t(A(e)),s=(null==n?void 0:n.name)||D(e)||r||a;return{name:s,number:s!==r&&r?r:null,avatar:null==n?void 0:n.avatar}}"function"==typeof SuppressedError&&SuppressedError;function A(e){return"inbound"===e.direction?e.from:e.to}function D(e){return"inbound"===e.direction?e.fromName:null}function I(e){const n=Math.max(0,Math.floor(e));return`${Math.floor(n/60)}:${(n%60).toString().padStart(2,"0")}`}function M(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}const O=/[^+*#0-9A-Da-d]/g,P="US";function j(e){return e.replace(O,"").slice(0,32).toUpperCase()}function L(e,n="US"){const t=j(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 H={code:"invalid_message",message:"Enter a valid phone number, extension, or feature code"};function _(e,n,{silentWhenEmpty:t=!1}={}){const a=L(e,P);return a||(t&&!e.trim()||null==n||n(Object.assign({},H)),"")}function B(e){switch(e){case"trying":return"stateTrying";case"ringing":return"stateRinging";case"active":return"stateActive";case"held":return"stateHeld";default:return"stateEnded"}}const R=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 F(e){return"mic_permission_denied"===e?"micPermissionError":R.has(e)?"connectionError":"callError"}function V(e,n){if(!n)return null;const t=e.find(e=>e.id===n.id);return t&&t.presence!==n.presence?Object.assign(Object.assign({},n),{presence:t.presence}):n}function U(e){switch(e){case"available":return"presenceAvailable";case"on_call":return"presenceOnCall";case"dnd":return"presenceDoNotDisturb";case"away":return"presenceAway";default:return"presenceOffline"}}function W(e){switch(e){case"available":return"success";case"on_call":return"warning";case"dnd":return"danger";default:return"muted"}}function K(e,n){return n&&"offline"!==e?"dnd":e}function q(e=500,n=()=>Date.now()){const t=new Map;return(a,r)=>{const s=n(),o=t.get(a);if(!(void 0!==o&&s-o<e))return t.set(a,s),r()}}const G=new WeakMap;function Y(e){let n=G.get(e);return n||G.set(e,n=q()),n}const J={calls:[],conferenceAudio:null};function Q(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,s=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:[...s,...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:J}}(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})}const X=e=>L(e,P)||e;function Z(e,n={}){const{onError:t}=n,[,r]=a(0),s=o(()=>r(e=>e+1),[]),l=o((e,n)=>{var a,r;const s=e;null==t||t({code:null!==(a=null==s?void 0:s.code)&&void 0!==a?a:n,message:null!==(r=null==s?void 0:s.message)&&void 0!==r?r:String(e)})},[t]),i=o(e=>function(e,n,t){const a=(t,a)=>()=>{e&&Y(e)(t,()=>{try{a(e)}catch(e){n(e,"call_failed")}})};return{answer:a("answer",e=>e.answer()),reject:a("reject",e=>e.reject()),hangup:a("hangup",e=>e.hangup()),toggleMute:a("mute",e=>{e.isMuted?e.unmute():e.mute(),t()}),toggleHold:a("hold",e=>{"held"===e.state?e.resume():e.hold()}),sendDtmf:t=>{if(t&&e)try{e.sendDtmf(t)}catch(e){n(e,"call_failed")}}}}(e,l,s),[l,s]),{answer:c,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:h}=i(e);return{answer:c,reject:d,hangup:u,toggleMute:p,toggleHold:m,sendDtmf:h,transfer:o(n=>{if(!e)return!1;const a=_(n,t,{silentWhenEmpty:!0});if(!a)return!1;let r=!1;return Y(e)("transfer",()=>{try{e.transfer(a),r=!0}catch(e){l(e,"call_failed")}}),r},[e,l,t]),callActionsFor:i}}function ee(e,n=500){const[,r]=a(0),s=null!=e&&$(e);return t(()=>{if(!s)return;const e=setInterval(()=>r(e=>e+1),n);return()=>clearInterval(e)},[s,n]),I(e?e.duration:0)}const ne="Timed out confirming your location. Please try again.";function te(e,n){let t=!1;return new Promise((a,r)=>{const s=setTimeout(()=>{t=!0,r(new Error(ne))},8e3);e.then(()=>{clearTimeout(s),t?n(null):a()},e=>{clearTimeout(s);const a=e instanceof Error?e:new Error(ne);t?n(a):r(a)})})}function ae(e){const[n,t]=a(null);return{lastError:n,handleError:o(n=>{t(n),null==e||e(n)},[e]),clearError:o(()=>t(null),[])}}function re(e){var n,t;if(!e)return null;const a=e=>"string"==typeof e&&e.trim()?e.trim():void 0,r=a(null===(n=e.avatar)||void 0===n?void 0:n.initials),s=a(null===(t=e.avatar)||void 0===t?void 0:t.uri),o={name:a(e.name),avatar:r||s?{initials:r,uri:s}:void 0};return o.name||o.avatar?o:null}const se=[];function oe(e,n){const[t,r]=a(""),s=function(e,n,t){var a;const r=n.trim().toLowerCase(),s=/^[\d\s()+.-]+$/.test(r)?r.replace(/\D/g,""):"",o=e=>{var n;return!r||[e.label,e.description,e.group,e.destination,...null!==(n=e.tags)&&void 0!==n?n:[]].some(e=>"string"==typeof e&&e.toLowerCase().includes(r))||!!e.presence&&(null==t?void 0:t(e.presence).toLowerCase())===r||s.length>=2&&e.destination.replace(/\D/g,"").includes(s)},l=[],i=new Map;for(const n of e){if(!o(n))continue;const e=null===(a=n.group)||void 0===a?void 0:a.trim();if(!e){l.push(n);continue}let t=i.get(e);t||i.set(e,t=[]),t.push(n)}const c=[];l.length&&c.push({group:void 0,destinations:l});for(const[e,n]of i)c.push({group:e,destinations:n});return c}(e,t,e=>n(U(e)));return{query:t,setQuery:r,groups:s}}function le(e){return{onType:o(n=>e(j(n)),[e]),onPasteText:o(n=>e(L(n,P)),[e])}}function ie(){const[e,n]=a(""),[t,r]=a(null);return{value:e,picked:t,onType:o(e=>{r(null),n(j(e))},[]),onPasteText:o(e=>{r(null),n(L(e,P))},[]),pick:o(e=>{r(e),n(L(e.destination,P))},[]),clear:o(()=>{r(null),n("")},[])}}const ce={maxWidth:420,actionButtonSize:68,controlButtonSize:60,keyGap:14,keyMaxSize:84,radius:14},de={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"},ue={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"},pe=[{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 me(e){var n,t,a,r,s,o,l,i,c,d;const u="dark"===(null==e?void 0:e.theme)?ue:de;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!==(s=p.colorTextSecondary)&&void 0!==s?s:u.textSecondary,border:null!==(o=p.colorBorder)&&void 0!==o?o:u.border,accent:null!==(l=p.colorPrimary)&&void 0!==l?l:u.accent,success:null!==(i=p.colorSuccess)&&void 0!==i?i:u.success,danger:null!==(c=p.colorDanger)&&void 0!==c?c:u.danger,warning:null!==(d=p.colorWarning)&&void 0!==d?d:u.warning,onAccent:u.onAccent}}const he=l(null),ge=[],fe=()=>Promise.reject(new Error("Phone not connected")),ve={listEmergencyAddresses:()=>h(fe(),fe),setEmergencyAddress:fe,presentedEmergencyAddressId:null,clearEmergencyAddressRegisteredIp:fe,reconnectWithEmergency:fe};function xe({token:l,existingPhone:i,apiBaseUrl:c,onTokenExpiring:d,iceServers:u,storage:h,ringback:g,createSignalingSocket:f,client:x,onAppResume:y,emergencyAddressId:$,autoConnect:N=!0,appearance:T,locale:S=v,defaultCountry:z="US",onConnectionStateChange:A,onIncomingCall:D,onCallStarted:I,onCallEnded:O,onError:j,resolvePeer:H,layoutVariant:B="auto",directory:R,accountDirectory:F,placeOutbound:V,answerIncoming:U,extra:W,children:G}){var ne,oe;const{lastError:le,handleError:ie,clearError:ce}=ae(j),de=`${null!==(ne=null==T?void 0:T.theme)&&void 0!==ne?ne:""}|${JSON.stringify(null!==(oe=null==T?void 0:T.variables)&&void 0!==oe?oe:{})}`,ue=s(()=>me(T),[de]),pe=e=>S.softphone[e],fe=e=>M(e,z),{phone:xe,connection:ye}=w({existingPhone:i,token:l,apiBaseUrl:c,onTokenExpiring:d,iceServers:u,storage:h,ringback:g,createSignalingSocket:f,client:x,onAppResume:y,emergencyAddressId:$,autoConnect:N,onError:ie}),{calls:be,activeCall:we,incomingCalls:ke,heldCalls:Ee,answerCall:Ce,switchToCall:$e,placeCall:Ne,consultCall:Te,transferOriginal:Se,startAttendedTransfer:ze,completeAttendedTransfer:Ae,cancelAttendedTransfer:De,mergedCalls:Ie,isMerged:Me,conferenceAudio:Oe,canMerge:Pe,mergeCalls:je,splitMerge:Le,hangupConference:He,holdConference:_e}=function(e,l,i={}){var c,d,u,h,g,f;const{onIncomingCall:v,onCallStarted:x,onCallActivated:y,onCallEnded:w,onError:C,placeOutbound:$,answerIncoming:N}=i,[T,S]=r(Q,J),[z,A]=a(e);z!==e&&(A(e),T.calls.length>0&&S({type:"reset"}));const{calls:D,conferenceAudio:I}=T,M=null!==(c=D.find(e=>e.active))&&void 0!==c?c:null,O=null!==(d=null==M?void 0:M.call)&&void 0!==d?d:null,j=s(()=>D.filter(e=>!e.active&&E(e.call)).map(e=>e.call),[D]),H=s(()=>D.filter(e=>!e.active&&!E(e.call)).map(e=>e.call),[D]),B=null!==(h=null===(u=D.find(e=>"consult"===e.transferRole))||void 0===u?void 0:u.call)&&void 0!==h?h:null,R=null!==(f=null===(g=D.find(e=>"original"===e.transferRole))||void 0===g?void 0:g.call)&&void 0!==f?f:null,F=s(()=>D.filter(e=>e.merged).map(e=>e.call),[D]),V=F.length>0,U=b(e),W=b(l),[,K]=a(0),G=o(()=>K(e=>e+1),[]),Z=n(null);Z.current=O;const ee=b(B),ne=n(null),te=b(D),ae=b(R),re=n(!0);t(()=>(re.current=!0,()=>{re.current=!1}),[]);const se=b({onIncomingCall:v,onCallStarted:x,onCallActivated:y,onCallEnded:w,onError:C,placeOutbound:$,answerIncoming:N}),oe=n(new Map),le=n(new WeakSet),[ie]=a(()=>q()),ce=o(e=>{const n=oe.current.get(e);n&&(n(),oe.current.delete(e))},[]),de=o(e=>{ce(e);const n=()=>{G()},t=()=>{var n,t,a,r;"inbound"===e.direction&&(le.current.add(e),null===(t=(n=se.current).onCallStarted)||void 0===t||t.call(n,{direction:"inbound",peer:e.from})),null===(r=(a=se.current).onCallActivated)||void 0===r||r.call(a,e),S({type:"answeredInPlace",call:e}),G()},a=n=>{var t,a;le.current.has(e)&&(le.current.delete(e),null===(a=(t=se.current).onCallEnded)||void 0===a||a.call(t,{reason:n}));const r=ne.current;(null==r?void 0:r.has(e))&&(r.remove(e),r.calls.length<2&&(r.dispose(),ne.current=null,S({type:"unmerged"}))),S({type:"callEnded",call:e}),ce(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),oe.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,ce,se]),ue=o(e=>k(this,void 0,void 0,function*(){var n,t,a,r,s,o,l,i,c,d,u,p;const m=U.current,h=_(e,se.current.onError);if(!h)return;if(!m||"connected"!==W.current)return void(null===(t=(n=se.current).onError)||void 0===t||t.call(n,{code:"transport_closed",message:"The softphone is not connected"}));if(oe.current.size>=4)return void(null===(r=(a=se.current).onError)||void 0===r||r.call(a,{code:"rate_limited",message:"Too many active calls"}));const g=Z.current;try{null==g||g.hold();const e=yield null!==(l=null===(o=(s=se.current).placeOutbound)||void 0===o?void 0:o.call(s,h))&&void 0!==l?l:m.call(h);S({type:"active",call:e}),le.current.add(e),null===(c=(i=se.current).onCallStarted)||void 0===c||c.call(i,{direction:"outbound",peer:e.to}),de(e)}catch(e){if(g&&"ended"!==g.state)try{g.resume()}catch(e){}const n=e;null===(u=(d=se.current).onError)||void 0===u||u.call(d,{code:null!==(p=n.code)&&void 0!==p?p:"call_failed",message:n.message})}}),[de,W,se,U]),pe=o(e=>{var n;return null!==(n=ie(`placeCall:${X(e)}`,()=>ue(e)))&&void 0!==n?n:Promise.resolve()},[ie,ue]),me=o((e,n)=>{var t,a,r;const s=Z.current;try{null==s||s.hold(),e(),S(n)}catch(e){if(s&&"ended"!==s.state)try{s.resume()}catch(e){}const n=e;null===(a=(t=se.current).onError)||void 0===a||a.call(t,{code:null!==(r=n.code)&&void 0!==r?r:"call_failed",message:n.message})}},[se]),he=o(e=>{Z.current!==e&&Y(e)("switch",()=>me(()=>e.resume(),{type:"switchActive",call:e}))},[me]),ge=o(e=>{Y(e)("answer",()=>me(()=>se.current.answerIncoming?se.current.answerIncoming(e):e.answer(),{type:"answered",call:e}))},[me,se]),fe=o(()=>{var e,n,t;if(ne.current)return;const a=te.current;if(2!==a.length)return;if(!a.every(e=>e.call.isConnected)||!p())return;const r=a.map(e=>e.call);if(te.current.some(e=>null!==e.transferRole))return;const s=[];for(const e of r)if("held"===e.state)try{e.resume(),s.push(e)}catch(e){}try{const e=m.merge(r,r[0].localMediaStream,e=>{var n,t,a;return null===(t=(n=se.current).onError)||void 0===t?void 0:t.call(n,{code:null!==(a=e.code)&&void 0!==a?a:"call_failed",message:e.message})});ne.current=e,S({type:"merged",calls:r,audio:e.localMediaStream}),G()}catch(a){for(const e of s)try{e.holdAfterResume()}catch(e){}const r=a;null===(n=(e=se.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[te,ne,se,G]),ve=o(()=>{const e=ne.current;if(e){e.dispose(),ne.current=null;for(const e of te.current)if(e.merged&&!e.active)try{e.call.hold()}catch(e){}S({type:"unmerged"}),G()}},[te,ne,G]),xe=o(()=>ie("merge",fe),[ie,fe]),ye=o(()=>ie("merge",ve),[ie,ve]),be=o(e=>ie("conferenceHold",()=>{var n,t,a;const r=ne.current;if(r){for(const s of r.calls)try{s.setConferenceHold(e)}catch(e){const r=e;null===(t=(n=se.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}G()}}),[ne,se,G,ie]),we=o(()=>{var e,n,t;const a=ne.current;if(!a)return;const r=a.calls;a.dispose(),ne.current=null,S({type:"unmerged"});for(const a of r)try{a.hangup()}catch(a){const r=a;null===(n=(e=se.current).onError)||void 0===n||n.call(e,{code:null!==(t=r.code)&&void 0!==t?t:"call_failed",message:r.message})}},[ne,se]),ke=o(e=>k(this,void 0,void 0,function*(){var n,t,a;const r=Z.current,s=U.current,o=L(e,P);if(r&&!ee.current&&o&&!ne.current)try{const e=yield r.attendedTransfer(o);if(!re.current)return;if("ended"===r.state||U.current!==s)return void e.hangup();S({type:"consultStarted",call:e}),de(e)}catch(e){const r=e;null===(t=(n=se.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}}),[de,ee,se,U]),Ee=o(e=>{var n;return null!==(n=ie(`consult:${X(e)}`,()=>ke(e)))&&void 0!==n?n:Promise.resolve()},[ie,ke]),Ce=o(()=>{const e=ae.current,n=ee.current;e&&n&&n.isConnected&&ie("finishTransfer",()=>{var n,t,a;try{e.completeTransfer()}catch(e){const r=e;null===(t=(n=se.current).onError)||void 0===t||t.call(n,{code:null!==(a=r.code)&&void 0!==a?a:"call_failed",message:r.message})}})},[ee,se,ae,ie]),$e=o(()=>{const e=ee.current,n=ae.current;e&&ie("finishTransfer",()=>{e.hangup(),ce(e),"held"===(null==n?void 0:n.state)&&n.resume(),S({type:"cancelConsult"})})},[ce,ee,ae,ie]);t(()=>{var n;if(!e)return;let t=!1;const a=oe.current,r=(e,n)=>{var a,r,s;if(t)return;const o=null===(a=null==n?void 0:n.notifyHost)||void 0===a||a;ne.current||oe.current.size>=4?e.reject("busy"):(S({type:"incomingAdded",call:e}),o&&(le.current.add(e),null===(s=(r=se.current).onIncomingCall)||void 0===s||s.call(r,{callId:e.id,from:e.from,fromName:e.fromName})),de(e))};e.on("incoming",r);for(const t of null!==(n=e.activeCalls)&&void 0!==n?n:[])oe.current.has(t)||"inbound"===t.direction&&(r(t,{notifyHost:!t.isConnected}),t.isConnected&&(le.current.add(t),S({type:"answeredInPlace",call:t})));return()=>{t=!0,e.off("incoming",r);const n=ne.current;n&&(n.dispose(),ne.current=null);for(const e of a.values())e();a.clear(),S({type:"reset"})}},[e,de,se]);const Ne=!V&&2===D.length&&D.every(e=>e.call.isConnected)&&!D.some(e=>null!==e.transferRole)&&p();return{calls:D,activeCall:O,incomingCalls:j,switchToCall:he,answerCall:ge,placeCall:pe,consultCall:B,heldCalls:H,transferOriginal:R,startAttendedTransfer:Ee,completeAttendedTransfer:Ce,cancelAttendedTransfer:$e,mergedCalls:F,isMerged:V,conferenceAudio:I,canMerge:Ne,mergeCalls:xe,splitMerge:ye,hangupConference:we,holdConference:be}}(xe,ye,{onIncomingCall:D,onCallStarted:I,onCallEnded:O,onError:ie,placeOutbound:V,answerIncoming:U}),Be=function(e,r){const{disabled:s,connection:l,identityKey:i,liveCallCount:c=0}=r,[d,u]=a(!s),[p,m]=a(!1),[h,g]=a(!1),[f,v]=a([]),[x,y]=a(!1),w=b(x),[E,C]=a(null),$=b(e),N=n(!1),T=n(0),S=n(i);t(()=>{S.current!==i&&(S.current=i,N.current=!1,m(!1),g(!1),v([]),C(null),u(!s))},[i,s]);const z=o(()=>{g(!0),m(!1)},[]);t(()=>{if(s)return;if("connected"!==l)return void("disconnected"!==l&&"error"!==l||u(!1));let e=!1;return(()=>{k(this,void 0,void 0,function*(){var n,t;try{const a=$.current,r=(yield a.listEmergencyAddresses()).data;if(e)return;v(r);const s=a.presentedEmergencyAddressId,o=null!==(t=null!==(n=r.find(e=>e.id===s))&&void 0!==n?n:r[0])&&void 0!==t?t:null;if(!o)return void m(!1);if(c>0)return void u(!1);if(N.current||h)w.current||(m(!h),h||C(null));else{if(N.current=!0,null==s||s!==o.id||null==o.registered_ip)return void(yield te(a.reconnectWithEmergency(o.id),()=>{}).catch(()=>{}));m(!0),w.current||C(null)}}catch(n){e||m(!1)}finally{e||u(!1)}})})(),()=>{e=!0}},[s,l,h,$,w,c]);const A=o((e,n)=>k(this,void 0,void 0,function*(){const t=++T.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=>{T.current===t&&C(e?a(e):null)};y(!0),C(null),g(!1),N.current=!0;try{const e=yield n(),t=$.current.reconnectWithEmergency(e);yield te(t,r)}catch(e){throw C(a(e)),e}finally{y(!1)}}),[$]);return{loading:d,bound:p,savedAddresses:f,submitting:x,error:E,onNetworkChanged:z,confirm:o(e=>A("Failed to confirm emergency address",()=>k(this,void 0,void 0,function*(){return yield $.current.clearEmergencyAddressRegisteredIp(e),e})),[A,$]),create:o(e=>A("Failed to save emergency address",()=>k(this,void 0,void 0,function*(){return(yield $.current.setEmergencyAddress(e)).id})),[A,$])}}(null!=xe?xe:ve,{disabled:!!$,connection:ye,identityKey:l,liveCallCount:be.length});t(()=>{if(!xe)return;const e=Be.onNetworkChanged;return xe.on("network.changed",e),()=>xe.off("network.changed",e)},[xe,Be.onNetworkChanged]);const Re=Z(we,{onError:ie}),Fe=function(e,n=!0){const[r,s]=a(null);n||"addcall"!==r||s(null);const l=o(e=>{s(n=>n===e?null:e)},[]),i=o(()=>l("keypad"),[l]),c=o(()=>l("transfer"),[l]),d=o(()=>l("devices"),[l]),u=o(()=>l("addcall"),[l]),p=o(()=>s(e=>"transfer"===e?null:e),[]),m=o(()=>s(e=>"addcall"===e?null:e),[]);return t(()=>{s(null)},[e]),{showKeypad:"keypad"===r,showTransfer:"transfer"===r,showDevices:"devices"===r,showAddCall:"addcall"===r,toggleKeypad:i,toggleTransfer:c,toggleDevices:d,toggleAddCall:u,closeTransfer:p,closeAddCall:m}}(we,be.length<4),Ve=ee(we),Ue=s(()=>be.map(e=>e.call),[be]),We=function(e,r){const s=n(new Map),l=n(new Map),[i,c]=a(0);return t(()=>{var n;if(!e)return void((s.current.size>0||l.current.size>0)&&(s.current.clear(),l.current.clear(),c(e=>e+1)));const t=new Set(r.map(e=>e.id));for(const e of[...s.current.keys()])t.has(e)||s.current.delete(e);for(const e of[...l.current.keys()])t.has(e)||l.current.delete(e);for(const t of r)(null===(n=s.current.get(t.id))||void 0===n?void 0:n.from)!==e&&l.current.get(t.id)!==e&&(l.current.set(t.id,e),Promise.resolve().then(()=>e(t)).then(re,()=>null).then(n=>{var a,r;if(l.current.get(t.id)!==e)return;l.current.delete(t.id);const o=null!==(r=null===(a=s.current.get(t.id))||void 0===a?void 0:a.info)&&void 0!==r?r:null;s.current.set(t.id,{info:n,from:e}),(n||o)&&c(e=>e+1)}))},[r,e]),o(e=>{var n,t;return e&&null!==(t=null===(n=s.current.get(e.id))||void 0===n?void 0:n.info)&&void 0!==t?t:null},[i])}(H,Ue),Ke=null!=R?R:ge,qe=function(e,r,o){const[l,i]=a([]),[c,d]=a({}),u="connected"===r,p=o&&!!e,m=n([]);return t(()=>()=>{i([]),m.current=[]},[e]),t(()=>{if(!p||!e)return;let n=new Set;const t=e=>{const t=e.filter(e=>n.has(e.userId));0!==t.length&&d(e=>{const n=Object.assign({},e);for(const e of t)n[e.userId]=K(e.status,e.doNotDisturb);return n})},a=e=>t(e),r=e=>t([e]);e.on("presenceList",a),e.on("presenceUpdate",r);let s,o=!1;const l=(n,t)=>{if(!o)try{e.subscribePresence(n)}catch(e){if(t>=3)return;s=setTimeout(()=>l(n,t+1),1e3*Math.pow(2,t))}};let c=0;const h=e=>{if("presence_unavailable"!==e.code||0===n.size)return;if(c>=3)return;clearTimeout(s);const t=[...n];s=setTimeout(()=>l(t,0),1e3*Math.pow(2,c++))};return e.on("error",h),u&&e.listDirectory().then(e=>{if(o)return;i(e);const t=e.filter(e=>e.extensionNumbers.length>0).slice(0,100).map(e=>e.user);n=new Set(t),m.current=t,t.length>0&&l(t,0)}).catch(()=>{o||0===m.current.length||(n=new Set(m.current),l(m.current,0))}),()=>{o=!0,clearTimeout(s),e.off("presenceList",a),e.off("presenceUpdate",r),e.off("error",h),d({})}},[e,p,u]),s(()=>p?function(e,n){const t=[];for(const a of e){const e=a.extensionNumbers[0];if(!e)continue;const r={id:a.user,label:a.displayName||e,destination:e},s=n[a.user];s&&(r.presence=s),t.push(r)}return t}(l,c):se,[p,l,c])}(xe,ye,null!=F?F:void 0===R),Ge=s(()=>function(e,n){if(0===e.length)return n;if(0===n.length)return e;const t=new Map(n.map(e=>[e.id,e]));return[...e.map(e=>{const n=t.get(e.id);return n?(t.delete(e.id),n.presence||!e.presence?n:Object.assign(Object.assign({},n),{presence:e.presence})):e}),...n.filter(e=>t.has(e.id))]}(qe,Ke),[qe,Ke]),Ye=C(ke),Je=n(ye);t(()=>{null==A||A({state:ye}),"connected"===ye&&"connected"!==Je.current&&ce(),Je.current=ye},[ye,A,ce]);const Qe=s(()=>Object.assign({connection:ye,webrtcPhone:xe,calls:Ue,activeCall:we,incomingCalls:ke,incomingRinging:Ye,heldCalls:Ee,answerCall:Ce,switchToCall:$e,actions:Re,overlays:Fe,duration:Ve,consultCall:Te,transferOriginal:Se,startAttendedTransfer:ze,completeAttendedTransfer:Ae,cancelAttendedTransfer:De,placeCall:Ne,mergedCalls:Ie,isMerged:Me,conferenceAudio:Oe,canMerge:Pe,mergeCalls:je,splitMerge:Le,hangupConference:He,holdConference:_e,emergency:Be,emergencyManagedByHost:!!$,lastError:le,clearError:ce,t:pe,displayNumber:fe,palette:ue,peerInfo:We,layoutVariant:B,directory:Ge},W),[ye,xe,Ue,we,ke,Ye,Ee,Ce,$e,Re,Fe,Ve,Te,Se,ze,Ae,De,Ne,Ie,Me,Oe,Pe,je,Le,He,_e,Be,$,le,ce,ue,We,B,Ge,S,z,W]);return e.createElement(he.Provider,{value:Qe},G)}function ye(){const e=i(he);if(!e)throw new Error("Could not find softphone context; wrap your softphone UI in a <SoftphoneProvider>.");return e}const be="dialstack.softphone.input_device_id",we="dialstack.softphone.output_device_id",ke=l(null),Ee=e=>e.filter(e=>""!==e.deviceId).map(e=>({deviceId:e.deviceId,label:e.label})),Ce=({children:n})=>{var r,s,l;const{webrtcPhone:i,activeCall:c}=ye(),[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([]),[h,f]=a([]),[v,x]=a(!1),[y,b]=a(!1),[,w]=a(0),E=c?null!==(s=null!==(r=c.effectiveAudioInputDeviceId)&&void 0!==r?r:null==i?void 0:i.audioInputDeviceId)&&void 0!==s?s:null:null!==(l=null==i?void 0:i.audioInputDeviceId)&&void 0!==l?l:g.getItem(be),[C,$]=a(()=>g.getItem(we));t(()=>{if(!u)return;let e=!1;const n=()=>k(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);x(t.length>0&&t.every(e=>""===e.label)),m(Ee(t)),f(d?Ee(a):[])});n();const t=()=>{n()};return navigator.mediaDevices.addEventListener("devicechange",t),()=>{e=!0,navigator.mediaDevices.removeEventListener("devicechange",t)}},[u,d,c]),t(()=>{i&&C&&i.setAudioOutputDevice(C)},[i,C]),t(()=>{const e=g.getItem(be);i&&e&&!i.audioInputDeviceId&&i.seedAudioInputDevice(e)},[i]),t(()=>{if(!c)return;const e=()=>b(!0),n=()=>w(e=>e+1);return c.on("audioInputLost",e),c.on("audioInputChanged",n),()=>{c.off("audioInputLost",e),c.off("audioInputChanged",n),b(!1)}},[c]);const N=o(e=>{const n=()=>w(e=>e+1);null==i||i.setAudioInputDevice(e).then(()=>{b(!1),e?g.setItem(be,e):g.removeItem(be),n()},n)},[i]),T=o(e=>{$(e),e?g.setItem(we,e):g.removeItem(we),null==i||i.setAudioOutputDevice(e)},[i]),S={inputs:p,outputs:h,inputDeviceId:E,outputDeviceId:C,selectInputDevice:N,selectOutputDevice:T,outputSelectionSupported:d,enumerationSupported:u,labelsHidden:v,inputLost:y};return e.createElement(ke.Provider,{value:S},n)};function $e(){const e=i(ke);return e||{inputs:[],outputs:[],inputDeviceId:null,outputDeviceId:null,selectInputDevice:()=>{},selectOutputDevice:()=>{},outputSelectionSupported:!1,enumerationSupported:!1,labelsHidden:!1,inputLost:!1}}const Ne=[440,480];class Te{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 Ne){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 Se=he,ze=({existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:o,iceServers:l,emergencyAddressId:d,autoConnect:u=!0,appearance:p,locale:m=v,formatting:h,onConnectionStateChange:g,onIncomingCall:f,onCallStarted:b,onCallEnded:w,onError:k,resolvePeer:E,layoutVariant:C,directory:$,accountDirectory:N,appInfo:T,children:S})=>{var z,A,D,I;const M=`ds-softphone-${c().replace(/[:]/g,"")}`,O=s(()=>({scope:M}),[M]),P=i(y),[j,L]=a(()=>null==P?void 0:P.dialstack.getAppearance()),H=null!=p?p:j,_=null==P?void 0:P.dialstack;null===(z=null==_?void 0:_.registerClientComponent)||void 0===z||z.call(_,"sdk-react","softphone");const B=`${null!==(A=null==H?void 0:H.theme)&&void 0!==A?A:""}|${JSON.stringify(null!==(D=null==H?void 0:H.variables)&&void 0!==D?D:{})}`,R=null!==(I=null==h?void 0:h.defaultCountry)&&void 0!==I?I:"US",F=s(()=>function(e,n="ds-softphone"){const t=ce,a=32,r=22;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-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 /* The dial pad's keys fit its height as well as its width: whatever sits\n above them (the E911 banner, the directory matches) can take room\n without pushing the last row under Call or the first over the number.\n The keypad is a size container; the keys are one centred 3x4 block whose\n key size is the largest that fits it, and whose gaps scale with the keys,\n so a smaller keypad keeps the same proportions instead of spreading out.\n The dial pad and the in-call keypad share it, so they look the same.\n The same rule holds in every size tier: a narrow host gets keys as large\n as its width allows rather than a fixed compact size. Its basis is the\n full-size keypad, which is what it takes in a host sized by its content;\n a fixed host shrinks it. */\n .${n} .ds-keypad {\n --ds-key-max: ${t.keyMaxSize}px; --ds-key-ratio: ${t.keyGap/t.keyMaxSize};\n container-type: size;\n display: flex; align-items: center; justify-content: center;\n width: 100%; margin: 0 auto; min-height: 0;\n flex: 1 1 calc(var(--ds-key-max) * (4 + 3 * var(--ds-key-ratio)));\n max-width: min(calc(var(--ds-key-max) * (3 + 2 * var(--ds-key-ratio))), 100%);\n }\n .${n} .ds-keypad-keys {\n --ds-key: min(\n var(--ds-key-max),\n 100cqw / (3 + 2 * var(--ds-key-ratio)),\n 100cqh / (4 + 3 * var(--ds-key-ratio))\n );\n display: grid; grid-template-columns: repeat(3, var(--ds-key));\n gap: calc(var(--ds-key) * var(--ds-key-ratio));\n }\n .${n} .ds-keypad-keys .ds-key {\n width: var(--ds-key); height: var(--ds-key); max-width: none; aspect-ratio: auto;\n }\n .${n} .ds-keypad-keys .ds-key-digit {\n font-size: min(28px, calc(var(--ds-key) * 0.34));\n }\n .${n} .ds-keypad-keys .ds-key-letters {\n font-size: min(10px, calc(var(--ds-key) * 0.13));\n min-height: min(12px, calc(var(--ds-key) * 0.15));\n }\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 /* With a side button, the row takes the keypad's three columns, so it\n can't overflow a narrow host and the buttons line up under the keys. */\n .${n} .ds-actions:has(.ds-action-side) {\n display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));\n justify-items: center; gap: ${t.keyGap}px;\n width: 100%; max-width: min(${3*t.keyMaxSize+2*t.keyGap}px, 100%); margin-inline: auto;\n }\n /* A small round button beside Call; the empty one on the other side\n keeps Call centred. */\n .${n} .ds-action-side {\n flex: none; align-self: center; width: 44px; height: 44px; padding: 11px;\n border: none; border-radius: 999px; cursor: pointer;\n background: var(--dsd-surface); color: var(--dsd-text);\n }\n .${n} span.ds-action-side { visibility: hidden; }\n .${n} .ds-action-side:hover { background: var(--dsd-surface-active); }\n .${n} .ds-action-side svg { width: 100%; height: 100%; display: block; }\n /* One row, fixed height whether or not anything matches, scrolling\n sideways when the matches don't fit. */\n /* The row's height includes the scrollbar's, so it doesn't grow (or\n squeeze the chips) when there are enough matches to scroll. */\n .${n} .ds-dial-matches {\n display: flex; align-items: flex-start; gap: 6px; flex: none;\n height: ${a+14}px;\n overflow-x: auto; overflow-y: hidden;\n /* The scrollbar's room already spaces the chips from the number; the\n section gap on top of it left them looking detached. */\n margin-bottom: -8px;\n }\n /* Styled, so WebKit shows it all the time rather than only mid-scroll:\n a mouse user otherwise has no sign the row scrolls. Chrome drops these\n styles when the standard scrollbar-* properties are set, so those are\n only for browsers without them. */\n @supports not selector(::-webkit-scrollbar) {\n .${n} .ds-dial-matches {\n scrollbar-width: thin; scrollbar-color: var(--dsd-border) transparent;\n }\n }\n .${n} .ds-dial-matches::-webkit-scrollbar { height: 6px; }\n .${n} .ds-dial-matches::-webkit-scrollbar-track { background: transparent; }\n .${n} .ds-dial-matches::-webkit-scrollbar-thumb {\n background: var(--dsd-border); border-radius: 999px;\n }\n /* Centred when they fit. Auto margins, not justify-content: centring that\n way would push overflowing chips past the scrollable start. */\n .${n} .ds-dial-match:first-child { margin-left: auto; }\n .${n} .ds-dial-match:last-child { margin-right: auto; }\n .${n} .ds-dial-match {\n flex: none; display: inline-flex; align-items: center; gap: 6px;\n height: ${a}px; padding: 0 10px; border-radius: ${Math.max(t.radius-4,4)}px; cursor: pointer;\n border: 1px solid var(--dsd-border); background: var(--dsd-surface);\n color: var(--dsd-text); font-family: inherit; font-size: 13px; white-space: nowrap;\n }\n .${n} .ds-dial-match:hover { background: var(--dsd-surface-active); }\n .${n} .ds-dial-match[aria-pressed='true'] {\n border-color: var(--dsd-accent);\n background: color-mix(in srgb, var(--dsd-accent) 12%, transparent);\n }\n .${n} .ds-dial-match .ds-directory-option-label { font-size: 13px; }\n /* The contact a transfer / add-call panel will act on, in place of the\n field or list it was picked from. */\n .${n} .ds-dial-pick {\n align-self: flex-start; display: flex; align-items: center; gap: 10px;\n max-width: 100%; padding: 8px 8px 8px 10px;\n border-radius: ${Math.max(t.radius-4,4)}px;\n border: 1px solid var(--dsd-accent);\n background: color-mix(in srgb, var(--dsd-accent) 12%, transparent);\n color: var(--dsd-text);\n }\n .${n} .ds-dial-pick-contact {\n display: flex; flex-direction: column; gap: 2px; min-width: 0;\n }\n .${n} .ds-dial-pick-clear {\n flex: none; width: 24px; height: 24px; padding: 5px; margin-left: 2px;\n border: none; border-radius: 50%; cursor: pointer;\n background: var(--dsd-surface); color: var(--dsd-text-secondary);\n }\n .${n} .ds-dial-pick-clear:hover { background: var(--dsd-surface-active); color: var(--dsd-text); }\n .${n} .ds-dial-pick-clear svg { width: 100%; height: 100%; display: block; }\n .${n} .ds-action {\n flex: none; 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 /* As tall as the backspace, so the first digit (which brings it in)\n doesn't push the keypad down. */\n flex: 0 1 auto; min-height: 40px;\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 /* The large avatar shrinks first when the screen runs out of height\n (flex-shrink well above its siblings'). It is a size container, so its\n content never holds the peer block open, and below a legible size the\n disc hides rather than turning into a dot. */\n .${n} .ds-peer-avatar {\n flex: 0 100 64px; min-height: 0; max-height: 64px; width: 64px;\n align-self: center; margin-bottom: 4px;\n container-type: size; display: flex; align-items: center; justify-content: center;\n }\n .${n} .ds-peer-avatar-disc {\n height: 100%; aspect-ratio: 1; border-radius: 999px; overflow: hidden;\n display: flex; align-items: center; justify-content: center;\n background: var(--dsd-accent); color: var(--dsd-on-accent);\n font-size: 34cqh; font-weight: 600;\n }\n .${n} .ds-peer-avatar-disc img { width: 100%; height: 100%; object-fit: cover; }\n @container (max-height: 39px) {\n .${n} .ds-peer-avatar-disc { display: none; }\n }\n .${n} .ds-peer-avatar-sm { flex: none; width: 32px; height: 32px; margin: 0; }\n .${n} .ds-peer-avatar-sm .ds-peer-avatar-disc { font-size: 13px; }\n .${n} .ds-peer-row { display: flex; align-items: center; justify-content: center; gap: 10px; }\n .${n} .ds-peer-row-text { min-width: 0; text-align: left; }\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 12px;\n max-width: ${3*(t.controlButtonSize+12)+24}px;\n align-content: flex-end;\n margin: 0 auto;\n }\n /* Three to a row: the column gap is sized so a row of three fits the\n narrowest host (inside the scrollbar gutters) instead of wrapping to two. */\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 /* The in-call peer may give up height (its avatar first) before the screen\n has to scroll; the other children stay rigid. */\n .${n} .ds-screen-incall > .ds-peer { flex-shrink: 1; min-height: 0; }\n .${n} .ds-screen-incoming > .ds-incoming-card:not(.ds-incoming-card-compact) {\n flex-shrink: 1; min-height: 0;\n }\n .${n} .ds-incoming-card:not(.ds-incoming-card-compact) > .ds-incoming-card-info {\n min-height: 0;\n }\n /* The invisible controls placeholder (it lines the answer buttons up with\n the in-call screen) gives up its height before the caller does. */\n .${n} .ds-incoming-card > .ds-controls-slot { flex-shrink: 1000; }\n .${n} .ds-screen-incall:has(.ds-dtmf) > .ds-peer { flex: 0 0 auto; }\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-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 /* The transfer / add-call screen: it fills the in-call screen above hang\n up, and only the directory list flexes (and scrolls). */\n .${n} .ds-dial-panel {\n display: flex; flex-direction: column; gap: 10px;\n flex: 1 1 auto; min-height: 0;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+24}px; margin: 0 auto;\n }\n .${n} .ds-screen > .ds-dial-panel { flex-shrink: 1; }\n .${n} .ds-dial-panel > * { flex: none; }\n /* Same spot in both modes, just above hang up. */\n .${n} .ds-dial-panel > .ds-transfer-actions { margin-top: auto; }\n /* Sits with the buttons, so it moves down with them. */\n .${n} .ds-dial-panel > .ds-dial-panel-target { margin-top: auto; }\n .${n} .ds-dial-panel > .ds-dial-panel-target + .ds-transfer-actions { margin-top: 0; }\n /* With just the field, the auto margins split the spare height a third\n above, two thirds below: within reach in a tall host instead of pinned\n to the top. The list stays anchored to the top (so the header doesn't\n move as a search shortens it) and grows to its content, scrolling only\n once it reaches the buttons. */\n .${n} .ds-dial-panel-main {\n display: flex; flex-direction: column; gap: 10px; margin-block: auto;\n }\n .${n} .ds-dial-panel-main > * { flex: none; }\n .${n} .ds-dial-panel > .ds-dial-panel-main-list {\n flex: 0 1 auto; min-height: 0; margin-block: 0;\n }\n .${n} .ds-dial-panel-header { display: flex; align-items: flex-start; gap: 8px; }\n .${n} .ds-dial-panel-label {\n font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;\n color: var(--dsd-text-secondary); margin-bottom: -4px;\n }\n .${n} .ds-dial-panel-heading { flex: 1; min-width: 0; }\n .${n} .ds-dial-panel-title { font-size: 18px; font-weight: 600; }\n .${n} .ds-dial-panel-peer {\n font-size: 13px; color: var(--dsd-text-secondary);\n overflow: hidden; text-overflow: ellipsis; white-space: nowrap;\n }\n .${n} .ds-dial-panel-close {\n flex: none; width: 36px; height: 36px; padding: 8px;\n border: none; border-radius: 50%; cursor: pointer;\n background: var(--dsd-surface); color: var(--dsd-text);\n }\n .${n} .ds-dial-panel-close:hover { background: var(--dsd-surface-active); }\n .${n} .ds-dial-panel-close svg { width: 100%; height: 100%; display: block; }\n .${n} .ds-dial-panel-target {\n font-size: 13px; color: var(--dsd-text-secondary); text-align: center;\n overflow: hidden; text-overflow: ellipsis; white-space: nowrap;\n }\n /* The dial pad's number, keypad and their matches, or the list in their\n place: one box, so the list can hold the height they had. */\n .${n} .ds-screen > .ds-dial-body {\n display: flex; flex-direction: column; gap: inherit;\n flex: 1 1 auto; min-height: 0;\n }\n /* The dial pad's list takes the keypad's place and height. */\n .${n} .ds-dial-body > .ds-dial-directory {\n display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+24}px; margin: 0 auto;\n }\n .${n} .ds-dial-directory > .ds-directory {\n display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-height: 0;\n }\n .${n} .ds-dial-panel-main > .ds-directory {\n display: flex; flex-direction: column; gap: 8px; flex: 0 1 auto; min-height: 0;\n }\n .${n} .ds-directory-search { flex: none; position: relative; display: flex; }\n .${n} .ds-directory-search-input { flex: 1 1 auto; padding-left: 38px; padding-right: 38px; }\n /* Ours is drawn the same in every browser and on native. */\n .${n} .ds-directory-search-input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }\n .${n} .ds-directory-search-icon {\n position: absolute; left: 12px; top: 50%; transform: translateY(-50%);\n width: 18px; height: 18px; color: var(--dsd-text-secondary); pointer-events: none;\n }\n .${n} .ds-directory-search-icon svg,\n .${n} .ds-directory-search-clear svg { width: 100%; height: 100%; display: block; }\n .${n} .ds-directory-search-clear {\n position: absolute; right: 8px; top: 50%; transform: translateY(-50%);\n width: 24px; height: 24px; padding: 5px; border: none; border-radius: 50%; cursor: pointer;\n background: var(--dsd-surface); color: var(--dsd-text-secondary);\n }\n .${n} .ds-directory-search-clear:hover { background: var(--dsd-surface-active); color: var(--dsd-text); }\n .${n} .ds-directory-options {\n display: flex; flex-direction: column; gap: 4px;\n flex: 0 1 auto; min-height: 0; overflow-y: auto;\n border: 1px solid var(--dsd-border); border-radius: ${t.radius}px;\n background: var(--dsd-surface); padding: 4px;\n }\n .${n} .ds-directory-group {\n padding: 6px 10px 2px; font-size: 11px; font-weight: 600;\n text-transform: uppercase; letter-spacing: 0.04em; color: var(--dsd-text-secondary);\n }\n .${n} .ds-directory-option {\n display: flex; flex-direction: column; align-items: flex-start; gap: 2px;\n width: 100%; padding: 8px 10px; text-align: left; cursor: pointer;\n border: 1px solid transparent; border-radius: ${Math.max(t.radius-4,4)}px;\n background: none; color: var(--dsd-text); font-family: inherit;\n }\n .${n} .ds-directory-option:hover { background: var(--dsd-surface-active); }\n .${n} .ds-directory-option[aria-pressed='true'] {\n border-color: var(--dsd-accent);\n background: color-mix(in srgb, var(--dsd-accent) 12%, transparent);\n }\n .${n} .ds-directory-option-title {\n display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;\n }\n .${n} .ds-directory-option-label { font-size: 14px; font-weight: 500; }\n .${n} .ds-directory-tag {\n padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 500;\n /* Not surface-active: that is the row's hover fill, which would swallow\n the chip under the pointer. */\n background: var(--dsd-bg); color: var(--dsd-text-secondary);\n }\n .${n} .ds-directory-option-detail { font-size: 12px; color: var(--dsd-text-secondary); }\n .${n} .ds-directory-presence {\n flex: none; display: inline-flex; width: 12px; height: 12px; border-radius: 50%;\n color: var(--dsd-bg); background: var(--dsd-text-secondary);\n }\n .${n} .ds-directory-presence svg { width: 100%; height: 100%; display: block; }\n .${n} .ds-directory-presence[data-tone='success'] { background: var(--dsd-success); }\n .${n} .ds-directory-presence[data-tone='warning'] { background: var(--dsd-warning); }\n .${n} .ds-directory-presence[data-tone='danger'] { background: var(--dsd-danger); }\n .${n} .ds-directory-presence[data-presence='offline'] {\n background: none; color: var(--dsd-text-secondary);\n box-shadow: inset 0 0 0 1.5px var(--dsd-text-secondary);\n }\n .${n} .ds-directory-empty {\n padding: 10px; font-size: 13px; text-align: center; color: var(--dsd-text-secondary);\n }\n\n .${n} .ds-devices {\n display: flex; flex-direction: column; gap: 10px;\n width: 100%; max-width: ${3*(t.controlButtonSize+12)+24}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} .ds-conference-party {\n display: flex; align-items: center; gap: 10px; align-self: stretch; min-width: 0;\n }\n .${n} .ds-conference-party-name {\n min-width: 0; font-size: 17px; font-weight: 600;\n white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\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 /* Compact size tier for small hosts (narrower than 300px or shorter than\n 480px; set by useRoomyHost). Everything steps down together so the\n screens fit instead of clipping; a host smaller still scrolls. */\n /* The host's own padding, once: a host that is itself a softphone section\n (a stand-alone view) mustn't pad its sections again. */\n .ds-host-small.${n}, .ds-host-small:not(.${n}) > .${n} { padding: 12px; }\n .ds-host-small .ds-screen { gap: 8px; }\n .ds-host-small .ds-screen-dial { padding-top: 18px; }\n .ds-host-small .ds-display { min-height: 32px; }\n .ds-host-small .ds-display-spacer { width: 32px; }\n .ds-host-small .ds-backspace { width: 32px; height: 32px; font-size: 18px; }\n .ds-host-small .ds-destination, .ds-host-small .ds-peer-name { font-size: 20px; }\n .ds-host-small .ds-peer-number { font-size: 13px; }\n .ds-host-small .ds-callstate { margin-top: 2px; }\n .ds-host-small .ds-callstate-text { font-size: 12px; }\n .ds-host-small .ds-duration { font-size: 15px; }\n .ds-host-small .ds-actions:has(.ds-action-side) { gap: 6px; max-width: min(156px, 100%); }\n .ds-host-small .ds-key { max-width: 48px; }\n .ds-host-small .ds-key-digit { font-size: 18px; }\n .ds-host-small .ds-key-letters { font-size: 8px; min-height: 9px; }\n .ds-host-small .ds-actions { gap: 32px; padding-top: 4px; }\n .ds-host-small .ds-action { width: 48px; height: 48px; }\n .ds-host-small .ds-action-side { width: 36px; height: 36px; padding: 9px; }\n .ds-host-small .ds-dial-matches { height: ${r+14}px; gap: 4px; }\n .ds-host-small .ds-dial-match { height: ${r}px; font-size: 11px; padding: 0 7px; gap: 4px; }\n .ds-host-small .ds-dial-match .ds-directory-option-label { font-size: 11px; }\n .ds-host-small .ds-dial-match .ds-directory-option-detail { font-size: 11px; }\n .ds-host-small .ds-controls { gap: 4px 8px; max-width: 184px; }\n .ds-host-small .ds-controls > * { flex-basis: 56px; }\n .ds-host-small .ds-control { gap: 3px; }\n .ds-host-small .ds-control-glyph { width: 42px; height: 42px; }\n .ds-host-small .ds-control-label { font-size: 10px; }\n .ds-host-small .ds-held-call { padding: 8px 10px; }\n .ds-host-small .ds-held-call .ds-peer-name { font-size: 15px; }\n .ds-host-small .ds-held-calls { gap: 4px; }\n .ds-host-small .ds-chip { font-size: 10px; padding: 2px 8px; }\n .ds-host-small .ds-e911-toggle { padding: 6px 8px; font-size: 11px; gap: 6px; }\n /* One line in a small host: the keypad needs the height more. */\n .ds-host-small .ds-e911-label {\n min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n }\n .ds-host-small .ds-transfer-input { padding: 6px 10px; font-size: 14px; }\n .ds-host-small .ds-directory-search-input { padding-left: 30px; padding-right: 30px; }\n .ds-host-small .ds-directory-search-icon { left: 9px; width: 15px; height: 15px; }\n .ds-host-small .ds-directory-search-clear { right: 5px; width: 20px; height: 20px; padding: 4px; }\n .ds-host-small .ds-dial-panel, .ds-host-small .ds-dial-panel-main { gap: 6px; }\n .ds-host-small .ds-dial-panel-title { font-size: 15px; }\n .ds-host-small .ds-dial-panel-close { width: 30px; height: 30px; padding: 7px; }\n .ds-host-small .ds-directory-option { padding: 5px 8px; }\n .ds-host-small .ds-directory-option-label { font-size: 13px; }\n .ds-host-small .ds-directory-tag { font-size: 10px; padding: 0 6px; }\n .ds-host-small .ds-transfer-actions, .ds-host-small .ds-consult-actions { gap: 6px; }\n .ds-host-small .ds-transfer-send, .ds-host-small .ds-e911-btn { padding: 7px 8px; font-size: 12px; }\n .ds-host-small .ds-incoming-card-compact { padding: 8px 10px; gap: 8px; }\n .ds-host-small .ds-incoming-card-compact .ds-peer-name { font-size: 13px; }\n .ds-host-small .ds-incoming-card-compact .ds-action { width: 36px; height: 36px; }\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 `}(me(H),M),[B,M]);return e.createElement(xe,{existingPhone:n,token:t,apiBaseUrl:r,onTokenExpiring:o,iceServers:l,emergencyAddressId:d,autoConnect:u,client:()=>{var e;return(null===(e=null==_?void 0:_.clientHeader)||void 0===e?void 0:e.call(_))||x.forComponent("sdk-react","3.9.0","softphone",T)},appearance:H,locale:m,defaultCountry:R,onConnectionStateChange:g,onIncomingCall:f,onCallStarted:b,onCallEnded:w,onError:k,resolvePeer:E,layoutVariant:C,directory:$,accountDirectory:N,extra:O},P&&e.createElement(Ie,{dialstack:P.dialstack,onChange:L}),e.createElement("style",null,F),e.createElement(Ce,null,S,e.createElement(Ae,null),e.createElement(De,{onError:k})))},Ae=()=>{const{incomingRinging:e}=Me(),{outputDeviceId:a}=$e(),r=n(null);return null===r.current&&(r.current=new Te),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},De=({onError:a})=>{const{activeCall:r,conferenceAudio:s}=Me(),{outputDeviceId:o}=$e(),l=n(null);return t(()=>{const e=l.current;e&&"function"==typeof e.setSinkId&&e.setSinkId(null!=o?o:"").catch(()=>{})},[o,r]),t(()=>{const e=l.current;if(!e)return;if(!r)return void(e.srcObject=null);e.srcObject=null!=s?s: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 i=()=>o(!0);return n.on("answered",i),()=>{n.off("answered",i)}},[r,s,a]),e.createElement("audio",{ref:l,autoPlay:!0})},Ie=({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},Me=()=>ye(),Oe=()=>{const{activeCall:e,actions:n}=Me();return{activeCall:e,actions:n}},Pe=()=>{const{incomingCalls:e}=Me();return function(e){var n;return null!==(n=e.find(E))&&void 0!==n?n:null}(e)},je={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"},contacts:{path:"M20 0H4v2h16V0zM4 24h16v-2H4v2zM20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm-8 2.75c1.24 0 2.25 1.01 2.25 2.25s-1.01 2.25-2.25 2.25S9.75 10.24 9.75 9 10.76 6.75 12 6.75zM17 17H7v-1.5c0-1.67 3.33-2.5 5-2.5s5 .83 5 2.5V17z"},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"},search:{path:"M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"},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"}},Le={dnd:{path:"M6 10.5h12v3H6z"},away:{path:"M11 6.5h2v5.1l3.6 2.1-1 1.7L11 12.7z"}},He=({glyph:n})=>e.createElement("svg",{viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},e.createElement("path",{d:n.path,transform:n.transform})),_e=({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(F(n.code))),e.createElement("button",{type:"button",className:"ds-call-error-dismiss","aria-label":a("dismiss"),onClick:t},"✕")):null,Be="ds-softphone",Re=l(null),Fe="undefined"==typeof window?t:d;function Ve(e,n,t){var r,s;const o=null!==(s=null===(r=i(he))||void 0===r?void 0:r.layoutVariant)&&void 0!==s?s:"auto",[l,c]=a("compact"!==o);return Fe(()=>{const t=n?e():null;if(!t||"undefined"==typeof ResizeObserver)return;const a=()=>{const{width:e,height:n}=t.getBoundingClientRect(),a=function(e,n){return"compact"!==e&&("full"===e||n)}(o,e>=300&&n>=480);t.classList.toggle("ds-host-small",!a),c(a)};a();const r=new ResizeObserver(a);return r.observe(t),()=>{r.disconnect(),t.classList.remove("ds-host-small")}},[o,n,t]),l}function Ue(){const e=n(null),t=i(Re),a=Ve(()=>{var n,t,a,r;let s=null!==(t=null===(n=e.current)||void 0===n?void 0:n.closest(".ds-softphone"))&&void 0!==t?t:e.current;for(let e=null===(a=null==s?void 0:s.parentElement)||void 0===a?void 0:a.closest(".ds-softphone");e;e=null===(r=e.parentElement)||void 0===r?void 0:r.closest(".ds-softphone"))s=e;return s},null===t);return{ref:e,roomy:null!=t?t:a}}const We=({presence:n})=>{const t=Le[n];return e.createElement("span",{className:"ds-directory-presence","data-presence":n,"data-tone":W(n),"aria-hidden":"true"},t&&e.createElement(He,{glyph:t}))},Ke=({entry:n,t:t,inline:a=!1})=>{const r=e.createElement(e.Fragment,null,n.presence&&e.createElement(We,{presence:n.presence}),e.createElement("span",{className:"ds-directory-option-label"},n.label),function(e){var n;return(null!==(n=e.tags)&&void 0!==n?n:[]).map(e=>e.trim()).filter(Boolean)}(n).map((n,t)=>e.createElement("span",{key:`${n}|${t}`,className:"ds-directory-tag"},n))),s=e.createElement("span",{className:"ds-directory-option-detail"},function(e,n,t){const a=n?e.destination:e.description||e.destination;return e.presence?`${a} · ${t(U(e.presence))}`:a}(n,a,t));return a?e.createElement(e.Fragment,null,r,s):e.createElement(e.Fragment,null,e.createElement("span",{className:"ds-directory-option-title"},r),s)},qe=({destinations:t,isSelected:a,onPick:r,t:s})=>{const{query:o,setQuery:l,groups:i}=oe(t,s),d=c(),u=n(null);return e.createElement("div",{className:"ds-directory"},e.createElement("div",{className:"ds-directory-search"},e.createElement("span",{className:"ds-directory-search-icon","aria-hidden":"true"},e.createElement(He,{glyph:je.search})),e.createElement("input",{ref:u,className:"ds-transfer-input ds-directory-search-input",type:"search",value:o,placeholder:s("directorySearchPlaceholder"),"aria-label":s("directorySearchPlaceholder"),"aria-controls":d,autoComplete:"off",onChange:e=>l(e.target.value)}),o&&e.createElement("button",{type:"button",className:"ds-directory-search-clear","aria-label":s("directoryClearSearch"),onClick:()=>{var e;l(""),null===(e=u.current)||void 0===e||e.focus()}},e.createElement(He,{glyph:je.close}))),e.createElement("div",{id:d,className:"ds-directory-options","aria-label":s("directoryLabel")},0===i.length&&e.createElement("div",{className:"ds-directory-empty"},s("directoryNoMatches")),i.map(({group:n,destinations:t})=>e.createElement("div",{key:null!=n?n:"",role:"group","aria-label":n},n&&e.createElement("div",{className:"ds-directory-group","aria-hidden":"true"},n),t.map(n=>e.createElement("button",{type:"button",key:n.id,className:"ds-directory-option","aria-pressed":a(n),onClick:()=>r(n)},e.createElement(Ke,{entry:n,t:s})))))))},Ge=({label:n,onKey:t,keyLabel:a=({digit:e,letters:n})=>`${e}${n?" "+n:""}`})=>e.createElement("div",{className:"ds-keypad",role:"group","aria-label":n},e.createElement("div",{className:"ds-keypad-keys"},pe.map(n=>e.createElement("button",{type:"button",key:n.digit,className:"ds-key","aria-label":a(n),onClick:()=>t(n.digit)},e.createElement("span",{className:"ds-key-digit"},n.digit),e.createElement("span",{className:"ds-key-letters"},n.letters||" "))))),Ye=({directory:n,value:t,picked:a,onPick:r,t:s})=>{const o=V(n,a);return e.createElement("div",{className:"ds-dial-matches",role:"group","aria-label":s("directoryMatches")},(o?[o]:function(e,n){const t=n.trim();if(!t)return[];if(t.length<2)return e.filter(e=>e.destination===t);const a=t.replace(/\D/g,"");return e.filter(e=>e.destination.includes(t)||a.length>0&&e.destination.replace(/\D/g,"").includes(a))}(n,t)).map(n=>e.createElement("button",{type:"button",key:n.id,className:"ds-dial-match","aria-pressed":n.id===(null==a?void 0:a.id),onClick:()=>r(n)},e.createElement(Ke,{entry:n,t:s,inline:!0}))))},Je=[],Qe=({connection:t,destination:r,onDestinationChange:s,onDestinationPaste:o,canCall:l,onCall:i,destinationRef:c,error:d=null,onDismissError:u=()=>{},directory:p=Je,picked:m=null,onPick:h=()=>{},scope:g=Be,t:f})=>{const{ref:v}=Ue(),x=p.length>0,y=n(null),b=function(e,n){const[t,r]=a(!1);t&&!e&&r(!1);const s=t&&e,[o,l]=a(void 0);return{showList:s,toggleList:e=>{s||l(e||void 0),r(!t)},pickAndClose:e=>{n(e),r(!1)},listMinHeight:o}}(x,h),{showList:w,pickAndClose:k,listMinHeight:E}=b;return e.createElement("div",{ref:v,className:`${g} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-dial"},e.createElement(Xe,{connection:t,t:f}),e.createElement(_e,{error:d,onDismiss:u,t:f}),w?e.createElement("div",{className:"ds-dial-body",style:{minHeight:E}},e.createElement("div",{className:"ds-dial-directory"},e.createElement(qe,{destinations:p,isSelected:e=>e.id===(null==m?void 0:m.id),onPick:k,t:f})),r&&e.createElement("div",{className:"ds-dial-panel-target"},f("dialTarget"),": ",m?`${m.label} · ${r}`:r)):e.createElement("div",{className:"ds-dial-body",ref:y},x&&e.createElement(Ye,{directory:p,value:r,picked:m,onPick:h,t:f}),e.createElement("div",{className:"ds-display"},r.length>0&&e.createElement("span",{className:"ds-display-spacer","aria-hidden":"true"}),e.createElement("input",{ref:c,className:"ds-destination",type:"tel",inputMode:"tel",value:r,placeholder:f("destinationPlaceholder"),"aria-label":f("destinationPlaceholder"),autoComplete:"off",onChange:e=>s(e.target.value),onPaste:e=>{e.preventDefault(),o(e.clipboardData.getData("text"))},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),l&&i())}}),r.length>0&&e.createElement("button",{type:"button",className:"ds-backspace","aria-label":f("backspace"),onClick:()=>s(r.slice(0,-1))},"⌫")),e.createElement(Ge,{label:f("title"),onKey:e=>s(r+e)})),e.createElement("div",{className:"ds-actions"},x&&e.createElement("button",{type:"button",className:"ds-action-side","aria-label":f(w?"enterNumber":"chooseFromDirectory"),onClick:()=>{var e;return b.toggleList(null===(e=y.current)||void 0===e?void 0:e.offsetHeight)}},e.createElement(He,{glyph:w?je.keypad:je.contacts})),e.createElement("button",{type:"button",className:"ds-action ds-call","aria-label":f("call"),disabled:!l,onClick:i},e.createElement(He,{glyph:je.phone})),x&&e.createElement("span",{className:"ds-action-side","aria-hidden":"true"}))))},Xe=({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"})}},Ze=({autoFocusDestination:a=!1})=>{const{connection:r,placeCall:s,emergency:o,lastError:l,clearError:i,t:c,scope:d,directory:u}=Me(),{value:p,picked:m,onType:h,onPasteText:g,pick:f}=ie(),v=n(null);t(()=>{var e;a&&(null===(e=v.current)||void 0===e||e.focus())},[a]);const x=N(r,p,o.submitting);return e.createElement(Qe,{connection:r,destination:p,onDestinationChange:h,onDestinationPaste:g,canCall:x,onCall:()=>{s(p)},destinationRef:v,error:l,onDismissError:i,directory:u,picked:m,onPick:e=>T(e,{connection:r,emergencySubmitting:o.submitting,placeCall:s,pick:f}),scope:d,t:c})},en={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 nn(e){const n=e.trim(),t=en[n.toLowerCase()];return t||(/^[a-z]{2}$/i.test(n)?n.toUpperCase():n)}const tn={address_number:"",street:"",unit:"",city:"",state:"",postal_code:""},an=({savedAddresses:n,submitting:t,error:r,onConfirm:s,onCreate:o,defaultExpanded:l=!1,defaultAddingNew:i=!1,scope:c=Be,t:d})=>{const[u,p]=a(l),[m,h]=a(i),[g,f]=a(tn),v=e=>n=>f(t=>Object.assign(Object.assign({},t),{[e]:n.target.value}));return e.createElement("div",{className:`${c} 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:()=>p(e=>!e)},e.createElement("span",null,e.createElement(He,{glyph:je.location})),e.createElement("span",{className:"ds-e911-label"},d("emergencyPrompt")),e.createElement("span",{className:"ds-e911-chevron"},e.createElement(He,{glyph:je.chevronDown}))),u&&e.createElement("div",{className:"ds-e911-body"},e.createElement("p",{className:"ds-e911-hint"},d("emergencyHint")),!m&&n.map(n=>e.createElement("button",{key:n.id,type:"button",className:"ds-e911-choice",disabled:t,onClick:()=>{return e=n.id,void s(e).then(()=>p(!1)).catch(()=>{});var e}},e.createElement(He,{glyph:je.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")))),!m&&e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:()=>h(!0)},d("emergencyNewLocation")),m&&e.createElement("form",{className:"ds-e911-body",style:{padding:0,borderTop:"none"},onSubmit:e=>{e.preventDefault(),o(Object.assign(Object.assign({},g),{state:nn(g.state),unit:g.unit||void 0})).then(()=>{p(!1),h(!1)}).catch(()=>{})}},e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${c}-ea-num`},d("emergencyNumber")),e.createElement("input",{id:`${c}-ea-num`,className:"ds-e911-input",value:g.address_number,onChange:v("address_number")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${c}-ea-street`},d("emergencyStreet")),e.createElement("input",{id:`${c}-ea-street`,className:"ds-e911-input",value:g.street,onChange:v("street"),required:!0}))),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${c}-ea-unit`},d("emergencyUnit")),e.createElement("input",{id:`${c}-ea-unit`,className:"ds-e911-input",value:g.unit,onChange:v("unit")})),e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${c}-ea-city`},d("emergencyCity")),e.createElement("input",{id:`${c}-ea-city`,className:"ds-e911-input",value:g.city,onChange:v("city"),required:!0})),e.createElement("div",{className:"ds-e911-row"},e.createElement("div",{className:"ds-e911-field"},e.createElement("label",{htmlFor:`${c}-ea-state`},d("emergencyState")),e.createElement("input",{id:`${c}-ea-state`,className:"ds-e911-input",value:g.state,onChange:v("state"),required:!0})),e.createElement("div",{className:"ds-e911-field ds-e911-field-sm"},e.createElement("label",{htmlFor:`${c}-ea-zip`},d("emergencyPostalCode")),e.createElement("input",{id:`${c}-ea-zip`,className:"ds-e911-input",value:g.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:()=>h(!1)},d("emergencyBack")),e.createElement("button",{type:"submit",className:"ds-e911-btn",disabled:t},d(t?"emergencySaving":"emergencySave")))))))},rn=()=>{const{emergency:n,emergencyManagedByHost:t,activeCall:a,t:r,scope:s}=Me();return t||n.loading||n.bound||a?null:e.createElement(an,{savedAddresses:n.savedAddresses,submitting:n.submitting,error:n.error,onConfirm:n.confirm,onCreate:n.create,scope:s,t:r})},sn=()=>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"}," ")))),on=({avatar:n,size:t="lg"})=>{const[r,s]=a(null);if(!n)return null;const o=n.uri&&n.uri!==r?n.uri:null;return o||n.initials?e.createElement("div",{className:"sm"===t?"ds-peer-avatar-sm":"ds-peer-avatar","aria-hidden":"true"},e.createElement("div",{className:"ds-peer-avatar-disc"},o?e.createElement("img",{src:o,alt:"",onError:()=>s(o)}):e.createElement("span",null,n.initials))):null},ln=({avatar:n,children:t})=>n?e.createElement("div",{className:"ds-peer-row"},e.createElement(on,{avatar:n,size:"sm"}),e.createElement("div",{className:"ds-peer-row-text"},t)):e.createElement(e.Fragment,null,t),cn=({name:n,number:t=null,avatar:a,compact:r=!1,onAnswer:s,onDecline:o,t:l})=>{const{ref:i,roomy:c}=Ue();return e.createElement("div",{ref:i,className:"ds-incoming-card "+(r?"ds-incoming-card-compact":"")},e.createElement("div",{className:"ds-peer ds-incoming-card-info"},!r&&c&&e.createElement(on,{avatar:a}),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"},l("incomingCall")),e.createElement("span",{className:"ds-duration","aria-hidden":"true"}," "))),!r&&e.createElement(sn,null),e.createElement("div",{className:"ds-actions ds-actions-incoming"},e.createElement("button",{type:"button",className:"ds-action ds-decline","aria-label":l("decline"),onClick:o},e.createElement(He,{glyph:je.hangup})),e.createElement("button",{type:"button",className:"ds-action ds-answer","aria-label":l("answer"),onClick:s},e.createElement(He,{glyph:je.phone}))))},dn=({call:n,compact:t=!1})=>{const{answerCall:a,actions:r,t:s,displayNumber:o,peerInfo:l}=Me(),{name:i,number:c,avatar:d}=z(n,l(n),o,s("unknownCaller"));return e.createElement(cn,{name:i,number:c,avatar:d,compact:t,onAnswer:()=>a(n),onDecline:()=>r.callActionsFor(n).reject(),t:s})},un=()=>{const{incomingCalls:n,scope:t}=Me(),a=n[0];return a?e.createElement("div",{className:`${t} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incoming"},e.createElement(dn,{call:a}))):null},pn=({compact:n})=>{const{incomingCalls:t,scope:a}=Me();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(dn,{key:n.id,call:n,compact:r}))))},mn=({inputs:n,outputs:t,inputDeviceId:a,outputDeviceId:r,onSelectInput:s,onSelectOutput:o,outputSelectionSupported:l,enumerationSupported:i,labelsHidden:c,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=>s(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:!l,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"))))),!i&&e.createElement("p",{className:"ds-device-hint"},u("audioDevicesUnsupported")),!l&&e.createElement("p",{className:"ds-device-hint"},u("audioSpeakerUnsupported")),c&&e.createElement("p",{className:"ds-device-hint"},u("audioLabelsHidden"))),hn=()=>{const{t:n}=Me(),{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:s,selectInputDevice:o,selectOutputDevice:l,outputSelectionSupported:i,enumerationSupported:c,labelsHidden:d,inputLost:u}=$e();return e.createElement(mn,{inputs:t,outputs:a,inputDeviceId:r,outputDeviceId:s,onSelectInput:o,onSelectOutput:l,outputSelectionSupported:i,enumerationSupported:c,labelsHidden:d,inputLost:u,t:n})},gn=({label:n,glyph:t,on:a=!1,disabled:r=!1,onClick:s})=>e.createElement("button",{type:"button",className:"ds-control "+(a?"ds-control-on":""),"aria-pressed":a,"aria-label":n,disabled:r,onClick:s},e.createElement("span",{className:"ds-control-glyph"},e.createElement(He,{glyph:t})),e.createElement("span",{className:"ds-control-label"},n)),fn=({entry:n,onClear:t,t:a})=>e.createElement("div",{className:"ds-dial-pick"},e.createElement("div",{className:"ds-dial-pick-contact"},e.createElement(Ke,{entry:n,t:a})),e.createElement("button",{type:"button",className:"ds-dial-pick-clear","aria-label":a("directoryClearPick"),onClick:t},e.createElement(He,{glyph:je.close}))),vn=({title:n,peerName:t,directory:r,picked:s,onPick:o,onClearPick:l=()=>{},value:i,targetLabel:c,placeholder:d,onChange:u,onPaste:p,actions:m,onClose:h,t:g})=>{const{hasDirectory:f,pickedNow:v,showField:x,showList:y,showTarget:b,toggleDialing:w}=function(e,n,t){const[r,s]=a(!1),o=e.length>0,l=r||!o,i=!n&&!l;return{hasDirectory:o,pickedNow:V(e,n),showField:l,showList:i,showTarget:i&&!!t.trim(),toggleDialing:()=>s(!r)}}(r,s,i);return e.createElement("div",{className:"ds-dial-panel"},e.createElement("div",{className:"ds-dial-panel-main"+(y?" ds-dial-panel-main-list":"")},e.createElement("div",{className:"ds-dial-panel-header"},e.createElement("div",{className:"ds-dial-panel-heading"},e.createElement("div",{className:"ds-dial-panel-title"},n),e.createElement("div",{className:"ds-dial-panel-peer"},t)),f&&!s&&e.createElement("button",{type:"button",className:"ds-dial-panel-close","aria-label":g(x?"chooseFromDirectory":"enterNumber"),onClick:w},e.createElement(He,{glyph:x?je.contacts:je.keypad})),e.createElement("button",{type:"button",className:"ds-dial-panel-close","aria-label":g("cancel"),onClick:h},e.createElement(He,{glyph:je.close}))),!y&&e.createElement("div",{className:"ds-dial-panel-label"},c),v?e.createElement(fn,{entry:v,onClear:l,t:g}):e.createElement(e.Fragment,null,x&&f&&e.createElement(Ye,{directory:r,value:i,picked:null,onPick:o,t:g}),x?e.createElement("input",{className:"ds-transfer-input",type:"tel",inputMode:"tel",value:i,placeholder:d,"aria-label":d,autoComplete:"off",autoFocus:!0,onChange:e=>u(e.target.value),onPaste:e=>{e.preventDefault(),p(e.clipboardData.getData("text"))}}):e.createElement(qe,{destinations:r,isSelected:()=>!1,onPick:o,t:g}))),b&&e.createElement("div",{className:"ds-dial-panel-target"},g("dialTarget"),": ",i),e.createElement("div",{className:"ds-transfer-actions"},m))},xn=[],yn=({peer:n,stateLabel:t,duration:a,showDuration:r,isActive:s,isMuted:o,isHeld:l,isMerged:i,conferenceParties:c,conferenceLabel:d,transferOther:u,canCompleteTransfer:p,onSwitchToTransferOther:m,onCancelTransfer:h,onCompleteTransfer:g,switchableHeld:f,onSwitchToCall:v,error:x=null,onDismissError:y=()=>{},overlay:b,canSendDtmf:w,dtmfEntered:k,onSendDtmf:E,transferTo:C,onTransferToChange:$,onTransferToPaste:N,directory:T=xn,onPickTransferContact:S=()=>{},pickedTransferContact:z=null,onClearTransferContact:A=()=>{},onPickAddCallContact:D=()=>{},pickedAddCallContact:I=null,onClearAddCallContact:M=()=>{},onBlindTransfer:O,onConsultTransfer:P,addCallTo:j,onAddCallToChange:L,onAddCallToPaste:H,onSubmitAddCall:_,devicesPanel:B=null,canStartTransfer:R,canAddCall:F,canMerge:V,onToggleMute:U,onToggleHold:W,onToggleOverlay:K,onMergeOrSplit:q,onHangup:G,scope:Y=Be,t:J})=>{const Q=s&&"keypad"===b&&w,X=s&&"transfer"===b&&R,Z=s&&"addcall"===b&&F,ee=X||Z,{ref:ne,roomy:te}=Ue();return e.createElement("div",{ref:ne,className:`${Y} ds-softphone`},e.createElement("div",{className:"ds-screen ds-screen-incall "+(s?"ds-screen-active":"ds-screen-outgoing")},u&&!ee&&e.createElement("div",{className:"ds-transfer-banner"},e.createElement("button",{type:"button",className:"ds-held-call ds-consult-held","aria-label":`${J("switchToCall")}: ${u.name}`,onClick:m},e.createElement(ln,{avatar:u.avatar},e.createElement("div",{className:"ds-peer-name"},u.name),e.createElement("div",{className:"ds-callstate-text"},J("transferOriginalOnHold")))),e.createElement("div",{className:"ds-consult-actions"},e.createElement("button",{type:"button",className:"ds-e911-btn ds-e911-btn-secondary",onClick:h},J("cancel")),e.createElement("button",{type:"button",className:"ds-e911-btn",disabled:!p,onClick:g},J("transferComplete")))),f.length>0&&!ee&&e.createElement("div",{className:"ds-held-calls",role:"group","aria-label":J("heldCallsLabel")},f.map(n=>e.createElement("button",{type:"button",key:n.id,className:"ds-held-call ds-consult-held","aria-label":`${J("switchToCall")}: ${n.name}`,onClick:()=>v(n.id)},e.createElement(ln,{avatar:n.avatar},e.createElement("div",{className:"ds-peer-name"},n.name),e.createElement("div",{className:"ds-callstate-text"},J("heldCallsLabel")))))),ee?null:i?e.createElement("div",{className:"ds-peer ds-peer-conference"},e.createElement("div",{className:"ds-callstate-text"},d),e.createElement("div",{className:"ds-conference-parties"},c.map(n=>e.createElement("div",{key:n.id,className:"ds-conference-party"},e.createElement(on,{avatar:n.avatar,size:"sm"}),e.createElement("div",{className:"ds-conference-party-name"},n.name)))),e.createElement("div",{className:"ds-callstate"},e.createElement("span",{className:"ds-duration"},a))):e.createElement("div",{className:"ds-peer"},te&&!Q&&e.createElement(on,{avatar:n.avatar}),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"},Q?e.createElement("span",{className:"ds-dtmf-readout"},k||" "):e.createElement("span",{className:"ds-callstate-text"},t),!Q&&e.createElement("span",{className:"ds-duration","aria-hidden":!r},r?a:" "))),e.createElement(_e,{error:x,onDismiss:y,t:J}),s&&"keypad"===b&&w&&e.createElement("div",{className:"ds-dtmf"},e.createElement(Ge,{label:J("keypad"),onKey:E,keyLabel:({digit:e})=>e})),X&&e.createElement(vn,{title:J("transfer"),targetLabel:J("transferToLabel"),peerName:n.name,directory:T,picked:z,onPick:S,onClearPick:A,value:C,placeholder:J("transferPlaceholder"),onChange:$,onPaste:N,actions:e.createElement(e.Fragment,null,e.createElement("button",{type:"button",className:"ds-transfer-send ds-transfer-send-secondary",disabled:!C.trim(),onClick:O},J("transferNow")),e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!C.trim(),onClick:P},J("transferConsult"))),onClose:()=>K("transfer"),t:J}),Z&&e.createElement(vn,{title:J("addCall"),targetLabel:J("addCallToLabel"),peerName:n.name,directory:T,picked:I,onPick:D,onClearPick:M,value:j,placeholder:J("addCallPlaceholder"),onChange:L,onPaste:H,actions:e.createElement("button",{type:"button",className:"ds-transfer-send",disabled:!j.trim(),onClick:_},J("addCallSend")),onClose:()=>K("addcall"),t:J}),s&&"devices"===b&&B,!s&&e.createElement(sn,null),s&&!Q&&!ee&&e.createElement("div",{className:"ds-controls",role:"group"},e.createElement(gn,{label:J(o?"unmute":"mute"),glyph:o?je.micOff:je.mic,on:o,onClick:U}),e.createElement(gn,{label:J(l?"resume":"hold"),glyph:je.pause,on:l,onClick:W}),w&&e.createElement(gn,{label:J("keypad"),glyph:je.keypad,on:"keypad"===b,onClick:()=>K("keypad")}),e.createElement(gn,{label:J("addCall"),glyph:je.addCall,on:"addcall"===b,disabled:!F||i,onClick:()=>K("addcall")}),V||i?e.createElement(gn,{label:J(i?"split":"merge"),glyph:je.merge,on:i,onClick:q}):e.createElement(gn,{label:J("transfer"),glyph:je.transfer,on:"transfer"===b,disabled:!R,onClick:()=>K("transfer")}),e.createElement(gn,{label:J("audioDevices"),glyph:je.speaker,on:"devices"===b,onClick:()=>K("devices")})),e.createElement("div",{className:"ds-actions"},Q?e.createElement("button",{type:"button",className:"ds-action ds-keypad-close","aria-label":J("keypad"),onClick:()=>K("keypad")},e.createElement(He,{glyph:je.close})):e.createElement("button",{type:"button",className:"ds-action ds-hangup","aria-label":J("hangUp"),onClick:G},e.createElement(He,{glyph:je.hangup})))))},bn=()=>{var n;const{activeCall:r,actions:s,overlays:o,duration:l,consultCall:i,transferOriginal:c,heldCalls:d,incomingCalls:u,switchToCall:p,startAttendedTransfer:m,completeAttendedTransfer:h,cancelAttendedTransfer:g,placeCall:f,calls:v,mergedCalls:x,isMerged:y,canMerge:b,mergeCalls:w,splitMerge:k,hangupConference:E,holdConference:C,t:N,displayNumber:S,peerInfo:A,scope:D,lastError:I,clearError:M,directory:O,connection:P,emergency:j}=Me(),{showKeypad:L,showTransfer:H,showDevices:_,showAddCall:R}=o,[F,V]=a(""),U=ie(),W=ie(),K=U.value,q=W.value,{clear:G}=U,{clear:Y}=W,J=null!==(n=null==r?void 0:r.id)&&void 0!==n?n:null;if(t(()=>{V(""),G(),Y()},[J,G,Y]),!r)return null;const Q=$(r),X=r.canSendDtmf,Z=null!==i&&null!==c,ee=Z&&(r===i||r===c),ne=ee?r===i?c:i:null,te=ee&&null!==i&&i.isConnected,ae=d.filter(e=>e!==ne&&!x.includes(e)),re=d.length+u.length,se=!Z&&!y&&0===re,oe=y&&x.some(e=>"held"===e.state),le=v.length<4,ce=le?q:"",de=e=>Object.assign({id:e.id},z(e,A(e),S,N("unknownCaller"))),ue=L?"keypad":H?"transfer":_?"devices":R?"addcall":null;return e.createElement(yn,{peer:de(r),stateLabel:N(B(r.state)),duration:l,showDuration:"active"===r.state,isActive:Q,isMuted:r.isMuted,isHeld:oe||"held"===r.state,isMerged:y,conferenceParties:x.map(de),conferenceLabel:N("conferenceLabel"),transferOther:ee&&ne?de(ne):null,canCompleteTransfer:te,onSwitchToTransferOther:()=>ne&&p(ne),onCancelTransfer:g,onCompleteTransfer:h,switchableHeld:ae.map(de),onSwitchToCall:e=>{const n=ae.find(n=>n.id===e);n&&p(n)},error:I,onDismissError:M,overlay:ue,canSendDtmf:X,dtmfEntered:F,onSendDtmf:e=>{s.sendDtmf(e),V(n=>n+e)},transferTo:K,onTransferToChange:U.onType,onTransferToPaste:U.onPasteText,directory:O,onPickTransferContact:U.pick,pickedTransferContact:U.picked,onClearTransferContact:G,onPickAddCallContact:e=>T(e,{connection:P,emergencySubmitting:j.submitting,allowed:le,placeCall:f,pick:W.pick,onCalled:()=>{Y(),o.closeAddCall()}}),pickedAddCallContact:le?W.picked:null,onClearAddCallContact:Y,onBlindTransfer:()=>{s.transfer(K)&&(G(),o.closeTransfer())},onConsultTransfer:()=>{m(K)},addCallTo:ce,onAddCallToChange:W.onType,onAddCallToPaste:W.onPasteText,onSubmitAddCall:()=>{const e=ce.trim();e&&(f(e),Y(),o.closeAddCall())},devicesPanel:e.createElement(hn,null),canStartTransfer:se,canAddCall:le,canMerge:b,onToggleMute:s.toggleMute,onToggleHold:y?()=>C(!oe):s.toggleHold,onToggleOverlay:e=>{e===ue&&"transfer"===e&&G(),e===ue&&"addcall"===e&&Y(),"keypad"===e?o.toggleKeypad():"transfer"===e?o.toggleTransfer():"devices"===e?o.toggleDevices():o.toggleAddCall()},onMergeOrSplit:y?k:w,onHangup:y?E:s.hangup,scope:D,t:N})},wn=({autoFocusDestination:n})=>{const{calls:t,activeCall:a,scope:r}=Me(),s=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"===s.base&&s.incoming.length>0)return 1===s.incoming.length?e.createElement(un,null):e.createElement(pn,{compact:s.compact});const o="in-call"===s.base?e.createElement(bn,null):e.createElement(kn,{autoFocusDestination:n});return 0===s.incoming.length?o:e.createElement("div",{className:`${r} ds-softphone-layout`},e.createElement("div",{className:"ds-incoming-overlay"},e.createElement(pn,{compact:s.compact})),o)},kn=({autoFocusDestination:n})=>{const{scope:t}=Me();return e.createElement("div",{className:`${t} ds-dial-screen`},e.createElement(rn,null),e.createElement(Ze,{autoFocusDestination:n}))},En=({autoFocusDestination:n})=>{if(null===i(Se))throw new Error("<Softphone> must be rendered inside a <SoftphoneProvider>. The provider owns the connection and the token. See https://docs.dialstack.ai/sdks/components/softphone.");return e.createElement(Cn,{autoFocusDestination:n})},Cn=({autoFocusDestination:n})=>{const{ref:t,roomy:r}=function(){const[e,n]=a(null);return{ref:n,roomy:Ve(()=>null==e?void 0:e.parentElement,!0,e)}}();return e.createElement(Re.Provider,{value:r},e.createElement("span",{ref:t,hidden:!0}),e.createElement(wn,{autoFocusDestination:n}))};export{P as DIAL_COUNTRY,Ze as DialPad,rn as EmergencyBanner,un as IncomingCall,pn as IncomingStack,bn as OngoingCall,En as Softphone,ze as SoftphoneProvider,D as callPeerName,A as callPeerNumber,B as callStateLabelKey,F as errorMessageKey,I as formatCallDuration,M as formatDisplayNumber,$ as isCallActive,E as isIncomingRinging,L as sanitizeDestination,S as selectScreen,C as shouldRingIncoming,j as stripToDialString,Oe as useActiveCall,Z as useCallActions,ee as useCallDuration,le as useDialInput,Pe as useIncomingCall,ae as useLastError,Me as useSoftphone};
2
2
  //# sourceMappingURL=softphone.mjs.map