import{r as o,u as Z,j as e,H as U,L as H,a as k}from"./app-7TQoRINg.js";import{H as L}from"./heading-Bg-7hxYP.js";import{B as j}from"./button-B14hYptM.js";import{C as v,b as y,c as b,d as w,a as S}from"./card-HlYY-FCN.js";import{I as u}from"./input-v8Dzddeo.js";import{L as d}from"./label-CgA_it3S.js";import{P as W}from"./progress-BK9q9DOp.js";import{A as p,a as T,b as h}from"./alert-CUSiPjtj.js";import{d as z,S as G,a as M,c as J,b as _}from"./select-BCAd9Crp.js";import{C as K}from"./checkbox-wEG3odM0.js";import{P as q}from"./page-help-B13kG5V1.js";import{A as Q}from"./app-layout-aQVFjfPM.js";import{d as X}from"./index-DK5ap2Wf.js";import{D as Y,f as B}from"./badge-D3x2GPbI.js";import{Z as ee}from"./zap-DSJtdPct.js";import{C as A}from"./check-hGgFQtIN.js";import{G as O}from"./globe-DokHR5TU.js";import{L as F}from"./loader-circle-BR-UEWuS.js";/* empty css            */import"./chevron-up-yk1TmQNC.js";import"./createLucideIcon-COcR6tBl.js";import"./circle-help-BvSDueQL.js";import"./external-link-wwk4CRPv.js";import"./minus-atjnjdmC.js";import"./app-logo-icon-D-MBezm7.js";import"./house-VYpqVtj8.js";import"./phone-Ba-bFSOe.js";import"./user-cog-BMG7RYTW.js";import"./circle-alert-x4iPpGgH.js";import"./circle-check-wCLPZlSf.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};a.SENTRY_RELEASE={id:"b85bb7b5dc83f935fd7d75fdf93418434f2e0da2"}}catch{}})();try{(function(){var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},c=new a.Error().stack;c&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[c]="80acc2bc-0192-47fb-8d61-fe902504336a",a._sentryDebugIdIdentifier="sentry-dbid-80acc2bc-0192-47fb-8d61-fe902504336a")})()}catch{}const se=[{title:"Dashboard",href:X().url},{title:"Twilio Integration",href:"/settings/twilio"},{title:"BYOC Setup",href:"/byoc/setup"}],re=[{title:"What is BYOC (Bring Your Own Carrier)?",content:"BYOC allows you to route calls through your own 3rd party SIP providers (like Zadarma, VoIP.ms, or any SIP carrier) while still using Twilio's powerful API and platform. This provides massive cost savings - up to 60% cheaper than standard Twilio rates!"},{title:"How It Works",content:`Your Application → Twilio REST API → BYOC Trunk → Your SIP Provider (Zadarma/VoIP.ms) → PSTN

When you make a call through campaigns or AI agents, Twilio automatically routes it through your configured SIP provider at their cheaper rates. You still use the same TwilioService code - no changes needed!`},{title:"Cost Comparison",content:`• Standard Twilio Voice: $0.013/min
• Elastic SIP Trunk (BYOT): $0.0085/min (35% savings)  
• BYOC via Zadarma: ~$0.005/min (62% savings!)
• BYOC via VoIP.ms: ~$0.0049/min (62% savings!)

For 10,000 minutes/month, BYOC can save you $80-$100 compared to standard Twilio!`},{title:"Supported Providers",content:`Pre-configured providers:
• Zadarma - Popular international provider with excellent rates
• VoIP.ms - Canadian/US provider with great reliability
• Custom - Any SIP provider with a SIP URI

You can add multiple providers for failover and load balancing!`},{title:"Compatibility",content:`✅ Campaign Calls - Works perfectly with MakeCampaignCallJob
✅ AI Agent Calls - Full support for AI-powered calls  
✅ Inbound Calls - Route through your SIP provider
✅ Call Recording - Twilio records as normal
✅ Status Callbacks - All webhooks work normally
⚠️ Softphone WebRTC - Cannot use BYOC (Twilio SDK limitation)`},{title:"What You Need",content:`1. Active account with a SIP provider (Zadarma, VoIP.ms, etc.)
2. Your SIP credentials from the provider
3. SIP URI format (we provide templates for popular providers)
4. Twilio account configured in Teleman

Setup takes about 90 seconds and is completely automatic!`}];function Oe({user:a,twilioConfigured:c,twilioAccountSid:te,providerDefaults:C}){const[n,N]=o.useState("config"),[I,$]=o.useState(0),[D,E]=o.useState(""),[m,x]=o.useState(null),[g,R]=o.useState(null),{data:r,setData:i,processing:l,errors:f}=Z({friendly_name:`${a.name}'s BYOC Trunk`,provider_type:"zadarma",sip_uri:"",sip_username:"",sip_password:"",cost_per_minute:"0.005",priority:1,weight:100,add_backup:!0});o.useEffect(()=>{const s=C[r.provider_type];s&&s.sip_uri_template&&((!r.sip_uri||r.sip_uri.includes("{username}"))&&i("sip_uri",s.sip_uri_template),s.default_cost_per_minute&&i("cost_per_minute",s.default_cost_per_minute.toString()))},[r.provider_type]),o.useEffect(()=>{if(n==="setup"&&g){const s=setInterval(async()=>{try{const t=await window.axios.get(`/byoc/${g}/setup-status`);$(t.data.setup_progress||0),E(t.data.setup_step||""),t.data.is_setup_complete&&(clearInterval(s),setTimeout(()=>N("success"),1e3)),t.data.setup_error&&(clearInterval(s),x(t.data.setup_error))}catch(t){console.error("Failed to fetch setup status:",t)}},2e3);return()=>clearInterval(s)}},[n,g]);const V=async s=>{s.preventDefault(),x(null);try{const t=await window.axios.post("/byoc/setup",r);t.data.success?(R(t.data.trunk.id),N("setup")):x(t.data.message||"Failed to setup BYOC trunk")}catch(t){x(t.response?.data?.message||"Failed to setup BYOC trunk. Please check your configuration and try again.")}},P=C[r.provider_type];return e.jsxs(Q,{breadcrumbs:se,children:[e.jsx(U,{title:"BYOC Trunk Setup"}),e.jsxs("div",{className:"mx-auto max-w-4xl space-y-6 p-4 md:p-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(L,{title:"BYOC Trunk Setup"}),e.jsx(q,{title:"BYOC Setup Help",sections:re,documentationUrl:"/docs/documentation.html#byoc"})]}),e.jsxs(p,{className:"border-l-4 border-green-500 bg-green-50 dark:bg-green-950",children:[e.jsx(Y,{className:"h-5 w-5 text-green-600"}),e.jsx(T,{className:"text-green-900 dark:text-green-100",children:"Save Up To 62% on Call Costs!"}),e.jsx(h,{className:"text-green-800 dark:text-green-200",children:"Route calls through your own SIP provider (Zadarma, VoIP.ms, etc.) and pay as low as $0.005/min instead of Twilio's $0.013/min standard rate."})]}),e.jsxs("div",{className:"flex items-center justify-center space-x-4",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:`flex h-12 w-12 items-center justify-center rounded-full ${n==="config"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:e.jsx(B,{className:"h-6 w-6"})}),e.jsx("span",{className:"mt-2 text-sm font-medium",children:"Configure"})]}),e.jsx("div",{className:"h-px w-20 bg-muted"}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:`flex h-12 w-12 items-center justify-center rounded-full ${n==="setup"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:e.jsx(ee,{className:"h-6 w-6"})}),e.jsx("span",{className:"mt-2 text-sm font-medium",children:"Setup"})]}),e.jsx("div",{className:"h-px w-20 bg-muted"}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:`flex h-12 w-12 items-center justify-center rounded-full ${n==="success"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:e.jsx(A,{className:"h-6 w-6"})}),e.jsx("span",{className:"mt-2 text-sm font-medium",children:"Complete"})]})]}),n==="config"&&e.jsxs(v,{children:[e.jsxs(y,{children:[e.jsx(b,{children:"Configure Your SIP Provider"}),e.jsx(w,{children:"Connect Zadarma, VoIP.ms, or any SIP provider to save on call costs"})]}),e.jsx(S,{children:c?e.jsxs("form",{onSubmit:V,className:"space-y-6",children:[m&&e.jsx(p,{variant:"destructive",children:e.jsx(h,{children:m})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"friendly_name",children:"Trunk Name"}),e.jsx(u,{id:"friendly_name",value:r.friendly_name,onChange:s=>i("friendly_name",s.target.value),placeholder:"e.g., Zadarma Production Trunk",disabled:l}),f.friendly_name&&e.jsx("p",{className:"text-sm text-destructive",children:f.friendly_name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"provider_type",children:"SIP Provider"}),e.jsxs(z,{value:r.provider_type,onValueChange:s=>i("provider_type",s),children:[e.jsx(G,{children:e.jsx(M,{})}),e.jsxs(J,{children:[e.jsx(_,{value:"zadarma",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{className:"h-4 w-4"}),"Zadarma (~$0.005/min)"]})}),e.jsx(_,{value:"voipms",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{className:"h-4 w-4"}),"VoIP.ms (~$0.0049/min)"]})}),e.jsx(_,{value:"custom",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-4 w-4"}),"Custom SIP Provider"]})})]})]}),P?.notes&&e.jsx("p",{className:"text-xs text-muted-foreground",children:P.notes})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"sip_username",children:"SIP Username"}),e.jsx(u,{id:"sip_username",value:r.sip_username,onChange:s=>i("sip_username",s.target.value),placeholder:"Your SIP username",disabled:l})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"sip_password",children:"SIP Password"}),e.jsx(u,{id:"sip_password",type:"password",value:r.sip_password,onChange:s=>i("sip_password",s.target.value),placeholder:"Your SIP password",disabled:l})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"sip_uri",children:"SIP URI"}),e.jsx(u,{id:"sip_uri",value:r.sip_uri,onChange:s=>i("sip_uri",s.target.value),placeholder:"sip:username@provider.com",disabled:l}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Replace ","{username}"," with your actual username"]}),f.sip_uri&&e.jsx("p",{className:"text-sm text-destructive",children:f.sip_uri})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"cost_per_minute",children:"Cost Per Minute (USD)"}),e.jsx(u,{id:"cost_per_minute",type:"number",step:"0.0001",value:r.cost_per_minute,onChange:s=>i("cost_per_minute",s.target.value),placeholder:"0.005",disabled:l}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"For cost tracking and statistics"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(K,{id:"add_backup",checked:r.add_backup,onCheckedChange:s=>i("add_backup",!!s)}),e.jsx(d,{htmlFor:"add_backup",className:"text-sm font-normal",children:"Add Twilio as backup provider (recommended)"})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-4",children:[e.jsx("h4",{className:"mb-2 text-sm font-semibold",children:"What happens next?"}),e.jsxs("ul",{className:"space-y-1 text-xs text-muted-foreground",children:[e.jsx("li",{children:"• Create connection policy for routing"}),e.jsx("li",{children:"• Add your SIP provider as primary target"}),e.jsx("li",{children:"• Configure Twilio backup (if selected)"}),e.jsx("li",{children:"• Create BYOC trunk and test connection"}),e.jsx("li",{children:"• Your campaigns will automatically use cheaper rates!"})]})]}),e.jsx(j,{type:"submit",disabled:l,className:"w-full",children:l?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"mr-2 h-4 w-4 animate-spin"}),"Starting Setup..."]}):"Setup BYOC Trunk"})]}):e.jsx(p,{variant:"destructive",children:e.jsxs(h,{children:["Please configure your Twilio account first."," ",e.jsx(H,{href:"/settings/twilio",className:"underline",children:"Go to Twilio Settings"})]})})})]}),n==="setup"&&e.jsxs(v,{children:[e.jsxs(y,{children:[e.jsx(b,{children:"Setting Up Your BYOC Trunk"}),e.jsx(w,{children:"Configuring connection to your SIP provider..."})]}),e.jsxs(S,{className:"space-y-6",children:[m?e.jsx(p,{variant:"destructive",children:e.jsxs(h,{children:[e.jsx("p",{className:"mb-2 font-semibold",children:"Setup Failed"}),e.jsx("p",{children:m})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium",children:D||"Initializing..."}),e.jsxs("span",{className:"text-muted-foreground",children:[I,"%"]})]}),e.jsx(W,{value:I,className:"h-2"})]}),e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(F,{className:"h-12 w-12 animate-spin text-primary"})}),e.jsxs("div",{className:"space-y-2 text-center text-sm text-muted-foreground",children:[e.jsx("p",{children:"Do not close or refresh this page."}),e.jsx("p",{children:"Setting up connection policy and routing..."})]})]}),m&&e.jsx(j,{onClick:()=>k.visit("/byoc/setup"),className:"w-full",children:"Try Again"})]})]}),n==="success"&&e.jsxs(v,{children:[e.jsx(y,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-green-100 dark:bg-green-900",children:e.jsx(A,{className:"h-8 w-8 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx(b,{children:"BYOC Trunk Connected!"}),e.jsx(w,{children:"Your calls will now route through your SIP provider"})]})]})}),e.jsxs(S,{className:"space-y-6",children:[e.jsxs(p,{className:"border-l-4 border-green-500",children:[e.jsx(Y,{className:"h-4 w-4 text-green-600"}),e.jsx(T,{children:"Start Saving on Every Call"}),e.jsx(h,{children:e.jsxs("ul",{className:"mt-2 space-y-1 text-sm",children:[e.jsx("li",{children:"• Campaign calls now use your provider's rates"}),e.jsx("li",{children:"• AI agent calls automatically routed"}),e.jsx("li",{children:"• Twilio backup active for reliability"}),e.jsx("li",{children:"• Track savings in the dashboard"})]})})]}),e.jsx("div",{className:"flex gap-4",children:e.jsx(j,{onClick:()=>k.visit("/byoc"),className:"w-full",children:"View BYOC Dashboard"})})]})]})]})]})}export{Oe as default};
//# sourceMappingURL=SetupWizard-5S1L6TVY.js.map
