import{r as a,u as R,j as e,H as Y,L as H,a as U}from"./app-7TQoRINg.js";import{H as B}from"./heading-Bg-7hxYP.js";import{B as u}from"./button-B14hYptM.js";import{C as g,b as j,c as y,d as b,a as w}from"./card-HlYY-FCN.js";import{I as O}from"./input-v8Dzddeo.js";import{L as V}from"./label-CgA_it3S.js";import{P as $}from"./progress-BK9q9DOp.js";import{A as m,b as h,a as z}from"./alert-CUSiPjtj.js";import{P as M}from"./page-help-B13kG5V1.js";import{A as q}from"./app-layout-aQVFjfPM.js";import{d as K}from"./index-DK5ap2Wf.js";import{d as G,N as J,f as _}from"./badge-D3x2GPbI.js";import{C as i}from"./check-hGgFQtIN.js";import{L as A}from"./loader-circle-BR-UEWuS.js";import{P as Q}from"./phone-Ba-bFSOe.js";/* empty css            */import"./circle-help-BvSDueQL.js";import"./createLucideIcon-COcR6tBl.js";import"./external-link-wwk4CRPv.js";import"./checkbox-wEG3odM0.js";import"./minus-atjnjdmC.js";import"./app-logo-icon-D-MBezm7.js";import"./house-VYpqVtj8.js";import"./user-cog-BMG7RYTW.js";import"./circle-alert-x4iPpGgH.js";import"./circle-check-wCLPZlSf.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"b85bb7b5dc83f935fd7d75fdf93418434f2e0da2"}}catch{}})();try{(function(){var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},l=new t.Error().stack;l&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[l]="3e5eea32-1b1f-4ddc-8957-b449b40a7865",t._sentryDebugIdIdentifier="sentry-dbid-3e5eea32-1b1f-4ddc-8957-b449b40a7865")})()}catch{}const X=[{title:"Dashboard",href:K().url},{title:"Twilio Integration",href:"/settings/twilio"},{title:"SIP Trunk Setup",href:"/sip-trunk/setup"}],Z=[{title:"What is SIP Trunk Setup?",content:"This wizard connects your Twilio account to Teleman using SIP Trunking technology. It automatically configures your trunk, imports phone numbers, sets up webhooks, and runs health tests - all in about 60 seconds."},{title:"What You Need",content:`• Twilio Account SID (starts with "AC"): Find it in your Twilio Console dashboard
• Auth Token: Located in your Twilio Console under Account Info
• Active Twilio account with phone numbers
• The setup is completely automatic - just provide credentials and we handle the rest`},{title:"Setup Process (7 Steps)",content:`1. Validate Credentials: We verify your Twilio Account SID and Auth Token
2. Create Trunk: Your SIP trunk is created in Twilio with optimal settings
3. Origination URLs: Configure inbound call routing to Teleman
4. Import Numbers: All your Twilio phone numbers are automatically imported
5. Configure Numbers: Numbers are linked to your trunk for call routing
6. Set Webhooks: Voice URLs configured for seamless call handling
7. Health Tests: 5 comprehensive tests ensure everything works perfectly`},{title:"Benefits of BYOT (Bring Your Own Trunk)",content:`• Cost Savings: Save 35% on per-minute calling rates compared to standard Twilio pricing
• No Per-Number Fees: Eliminate monthly charges for each phone number
• Full Control: Keep complete ownership of your Twilio account and numbers
• Universal Usage: Use for softphone calls, campaigns, and AI agents
• Real-time Monitoring: Built-in health checks and call statistics`},{title:"Troubleshooting",content:`Common Issues:
• Invalid Credentials: Double-check your Account SID starts with "AC" and Auth Token is correct
• API Access: Ensure your Twilio account has API access enabled
• Number Compatibility: Voice-enabled numbers are required (SMS-only numbers won't work)
• Stuck Setup: If setup hangs over 2 minutes, click "Start Over" and try again
• Connection Failed: Check your internet connection and Twilio account status`},{title:"What Happens During Setup?",content:`Real-Time Progress: Watch as each step completes with live status updates
Automatic Configuration: All Twilio settings are optimized automatically
Error Handling: If any step fails, you'll see a clear error message and can retry
Success Confirmation: Upon completion, view your trunk dashboard with statistics
No Manual Work: Everything is handled automatically - no technical knowledge needed`}];function Te({user:t,twilioConfigured:l,twilioAccountSid:D}){const[n,x]=a.useState("credentials"),[N,v]=a.useState(0),[E,k]=a.useState(""),[o,d]=a.useState(null),[c,S]=a.useState(null),[p,T]=a.useState(null),{data:I,setData:F,processing:f,errors:C}=R({friendly_name:`${t.name}'s SIP Trunk`});a.useEffect(()=>{if(n==="setup"&&p){const r=setInterval(async()=>{try{const s=await window.axios.get(`/sip-trunk/${p}/setup-status`);v(s.data.setup_progress||0),k(s.data.setup_step||""),s.data.is_setup_complete&&(clearInterval(r),setTimeout(()=>{x("success")},1e3)),s.data.setup_error&&(clearInterval(r),d(s.data.setup_error))}catch(s){console.error("Failed to fetch setup status:",s)}},2e3);return()=>clearInterval(r)}},[n,p]);const W=async r=>{r.preventDefault(),d(null);try{const s=await window.axios.post("/sip-trunk/setup",I);s.data.success?(S(s.data),T(s.data.trunk.id),x("setup")):d(s.data.message||"Failed to setup SIP trunk")}catch(s){d(s.response?.data?.message||"Failed to setup SIP trunk. Please check your credentials and try again.")}},L=()=>{x("credentials"),v(0),k(""),d(null),S(null),T(null)},P=()=>{U.visit("/sip-trunk")};return e.jsxs(q,{breadcrumbs:X,children:[e.jsx(Y,{title:"SIP Trunk Setup"}),e.jsxs("div",{className:"mx-auto max-w-3xl space-y-6 p-4 md:p-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(B,{title:"SIP Trunk Setup Wizard"}),e.jsx(M,{title:"SIP Trunk Setup Help",sections:Z,documentationUrl:"/docs/documentation.html#sip-trunk"})]}),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==="credentials"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:e.jsx(G,{className:"h-6 w-6"})}),e.jsx("span",{className:"mt-2 text-sm font-medium",children:"Credentials"})]}),e.jsx("div",{className:"h-px w-16 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(J,{className:"h-6 w-6"})}),e.jsx("span",{className:"mt-2 text-sm font-medium",children:"Setup"})]}),e.jsx("div",{className:"h-px w-16 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(i,{className:"h-6 w-6"})}),e.jsx("span",{className:"mt-2 text-sm font-medium",children:"Complete"})]})]}),n==="credentials"&&e.jsxs(g,{children:[e.jsxs(j,{children:[e.jsx(y,{children:"Connect Your Twilio SIP Trunk"}),e.jsx(b,{children:"We'll automatically configure your SIP trunk, import your phone numbers, and test the connection."})]}),e.jsx(w,{children:l?e.jsxs("form",{onSubmit:W,className:"space-y-6",children:[o&&e.jsx(m,{variant:"destructive",children:e.jsx(h,{children:o})}),e.jsxs(m,{className:"border-l-4 border-primary bg-muted/50",children:[e.jsx(i,{className:"h-4 w-4"}),e.jsx(z,{children:"Ready to Configure SIP Trunk"}),e.jsxs(h,{className:"text-sm text-muted-foreground leading-relaxed",children:["Your Twilio account"," ",e.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-xs font-mono",children:D})," ","is connected. Complete the form below to set up your SIP Trunk."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"friendly_name",children:"Friendly Name (Optional)"}),e.jsx(O,{id:"friendly_name",type:"text",value:I.friendly_name,onChange:r=>F("friendly_name",r.target.value),placeholder:"e.g., Production SIP Trunk",disabled:f}),C.friendly_name&&e.jsx("p",{className:"text-sm text-destructive",children:C.friendly_name})]}),e.jsxs("div",{className:"rounded-lg bg-muted p-4",children:[e.jsx("h4",{className:"mb-2 font-semibold text-sm",children:"What happens next?"}),e.jsxs("ul",{className:"space-y-1 text-sm text-muted-foreground",children:[e.jsx("li",{children:"• Validate your Twilio credentials"}),e.jsx("li",{children:"• Create a SIP trunk in your account"}),e.jsx("li",{children:"• Configure inbound call routing"}),e.jsx("li",{children:"• Configure outbound authentication"}),e.jsx("li",{children:"• Import all your phone numbers"}),e.jsx("li",{children:"• Test the connection end-to-end"})]})]}),e.jsx("div",{className:"flex gap-4",children:e.jsx(u,{type:"submit",disabled:f,className:"w-full",children:f?e.jsxs(e.Fragment,{children:[e.jsx(A,{className:"mr-2 h-4 w-4 animate-spin"}),"Starting Setup..."]}):"Start Automatic Setup"})})]}):e.jsxs("div",{className:"relative overflow-hidden rounded-xl border bg-muted/50 p-8 shadow-sm",children:[e.jsx("div",{className:"absolute -right-16 -top-16 h-48 w-48 rounded-full bg-muted/30 blur-3xl"}),e.jsx("div",{className:"absolute -bottom-12 -left-12 h-40 w-40 rounded-full bg-muted/30 blur-3xl"}),e.jsxs("div",{className:"relative space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center rounded-2xl bg-primary shadow-lg",children:e.jsx(_,{className:"h-7 w-7 text-primary-foreground"})}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("h3",{className:"text-xl font-bold",children:"Twilio Configuration Required"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect your Twilio account to get started"})]})]}),e.jsx("div",{className:"rounded-lg border bg-card p-4 shadow-sm",children:e.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:"Before you can set up your SIP Trunk, you need to configure your Twilio account credentials. This is a quick one-time setup that takes less than a minute."})}),e.jsxs(H,{href:"/settings/twilio",className:"group inline-flex w-full items-center justify-center gap-3 rounded-xl bg-primary px-8 py-4 text-base font-semibold text-primary-foreground shadow-lg transition-all duration-200 hover:scale-[1.02] hover:bg-primary/90 hover:shadow-xl focus:outline-none focus:ring-4 focus:ring-ring active:scale-[0.98]",children:[e.jsx(_,{className:"h-5 w-5 transition-transform group-hover:rotate-90"}),"Configure Twilio Settings"]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-secondary px-3 py-1.5 text-xs font-medium text-secondary-foreground shadow-sm",children:[e.jsx(i,{className:"h-3.5 w-3.5"}),"One-time setup"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-secondary px-3 py-1.5 text-xs font-medium text-secondary-foreground shadow-sm",children:[e.jsx(i,{className:"h-3.5 w-3.5"}),"Takes less than 1 minute"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-secondary px-3 py-1.5 text-xs font-medium text-secondary-foreground shadow-sm",children:[e.jsx(i,{className:"h-3.5 w-3.5"}),"Secure connection"]})]})]})]})})]}),n==="setup"&&e.jsxs(g,{children:[e.jsxs(j,{children:[e.jsx(y,{children:"Setting Up Your SIP Trunk"}),e.jsx(b,{children:"Please wait while we configure your SIP trunk automatically. This should take about 60 seconds."})]}),e.jsxs(w,{className:"space-y-6",children:[o?e.jsx(m,{variant:"destructive",children:e.jsxs(h,{children:[e.jsx("p",{className:"mb-2 font-semibold",children:"Setup Failed"}),e.jsx("p",{children:o})]})}):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:E||"Initializing..."}),e.jsxs("span",{className:"text-muted-foreground",children:[N,"%"]})]}),e.jsx($,{value:N,className:"h-2"})]}),e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(A,{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:"We're configuring everything automatically in the background."})]})]}),o&&e.jsxs("div",{className:"flex gap-4",children:[e.jsx(u,{onClick:L,variant:"outline",className:"w-full",children:"Try Again"}),e.jsx(u,{onClick:P,variant:"secondary",className:"w-full",children:"View Dashboard"})]})]})]}),n==="success"&&c&&e.jsxs(g,{children:[e.jsx(j,{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(i,{className:"h-8 w-8 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx(y,{children:"SIP Trunk Connected Successfully!"}),e.jsx(b,{children:"Your trunk is ready to make and receive calls."})]})]})}),e.jsxs(w,{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsx("h4",{className:"mb-4 font-semibold",children:"Trunk Details"}),e.jsxs("dl",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Trunk Name:"}),e.jsx("dd",{className:"font-medium",children:c.trunk?.friendly_name})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Domain:"}),e.jsx("dd",{className:"font-mono text-xs",children:c.trunk?.trunk_domain_name})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Phone Numbers:"}),e.jsxs("dd",{className:"font-medium",children:[c.trunk?.phone_numbers_count," imported"]})]})]})]}),e.jsxs(m,{children:[e.jsx(Q,{className:"h-4 w-4"}),e.jsxs(h,{children:[e.jsx("p",{className:"mb-2 font-semibold",children:"What's Next?"}),e.jsxs("ul",{className:"space-y-1 text-sm",children:[e.jsx("li",{children:"• Your phone numbers are now connected to the trunk"}),e.jsx("li",{children:"• You can make calls at reduced rates ($0.0085/min)"}),e.jsx("li",{children:"• Inbound calls will route to your softphone or campaigns"}),e.jsx("li",{children:"• Monitor trunk health and statistics in the dashboard"})]})]})]}),e.jsx("div",{className:"flex gap-4",children:e.jsx(u,{onClick:P,className:"w-full",children:"View Trunk Dashboard"})})]})]})]})]})}export{Te as default};
//# sourceMappingURL=SetupWizard-DfhK9XmT.js.map
