import{r as m,j as e,H as I,a as o,t as r}from"./app-BeNY_zSm.js";import{H as P}from"./heading-CT-LucMJ.js";import{B as i}from"./button-Dge8PO59.js";import{C as g,a as y,b as A,c as H,d as F}from"./card-DG7I-_3R.js";import{P as j,A as l,R as b,B as E}from"./index-Bdohy6kp.js";import{P as $}from"./page-help-DTCPMpQ7.js";import{g as L,c as R,A as B,a as z,b as U,d as M,e as V,f as W}from"./alert-dialog-Bc-MUtyi.js";import{A as Y}from"./app-layout-DgG7GJrd.js";import{d as q}from"./index-6bh5m_Va.js";import{P as w}from"./phone-BwMlHUyB.js";import{T as G}from"./trash-2-CkyRKENG.js";/* empty css            */import"./createLucideIcon-VdTyGa1S.js";import"./circle-help-BK6Ftcl-.js";import"./external-link-B9pahLkG.js";import"./checkbox-CP6n_Jsi.js";import"./check-ApYQKYPd.js";import"./minus-DZw6Ijz4.js";import"./app-logo-icon-vDeU-Cqe.js";import"./house-DocrF1YH.js";import"./user-cog-CmNZBMeK.js";import"./alert-CxSnbwwr.js";import"./circle-alert-DR8wP1n1.js";import"./input-C0y5Yptz.js";import"./label-GwfI79i1.js";import"./circle-check-Cbr55h3A.js";import"./loader-circle-B3vU0DzH.js";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};n.SENTRY_RELEASE={id:"d90f819d28d132ee9ad7641cbed0d6343dd98ccf"}}catch{}})();try{(function(){var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},a=new n.Error().stack;a&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[a]="139443d8-fc40-493c-bd19-cff576f2e130",n._sentryDebugIdIdentifier="sentry-dbid-139443d8-fc40-493c-bd19-cff576f2e130")})()}catch{}const O=[{title:"Dashboard",href:q().url},{title:"Twilio Integration",href:"/settings/twilio"},{title:"SIP Trunk",href:"/sip-trunk"}],J=[{title:"What is SIP Trunk?",content:"SIP Trunking is a cost-effective way to make and receive calls through the internet. By connecting your Twilio account via SIP Trunk, you can significantly reduce call costs while maintaining full control of your phone numbers."},{title:"Cost Savings Explained",content:`Standard Twilio Pricing:
• $0.013 per minute for calls
• $1.00 per month per phone number

SIP Trunk Pricing:
• $0.0085 per minute (35% savings)
• $0 per month per phone number
• Same call quality and reliability

Example: With 50 numbers and 50,000 minutes/month, you save $275/month ($3,300/year)`},{title:"How to Get Started",content:`1. Click "Connect SIP Trunk" button
2. Enter your Twilio Account SID and Auth Token (found in Twilio Console)
3. Wait 60 seconds for automatic setup
4. View your dashboard and start making calls

The setup process is fully automatic - we create the trunk, import numbers, configure webhooks, and run health tests.`},{title:"Trunk Management Actions",content:`View: See detailed statistics, phone numbers, and health history
Sync: Manually sync phone numbers from Twilio (useful after adding new numbers)
Health Check: Run comprehensive tests to verify trunk functionality
Disconnect: Remove trunk connection (can reconnect anytime)`},{title:"Health Status Indicators",content:`Healthy (Green): All systems operational, trunk ready for calls
Degraded (Yellow): Some issues detected, calls may work but investigate recommended
Down (Red): Critical issues, immediate attention required

Health checks run automatically every 6 hours and test: API connectivity, trunk configuration, phone numbers, inbound routing, and outbound calling.`},{title:"Usage Statistics",content:`Each trunk card shows:
• Total calls made through this trunk
• Total minutes used
• Number of phone numbers connected
• Last call timestamp
• Last health check timestamp

These stats help you monitor usage and ensure optimal performance.`}];function ve({trunks:n,hasTrunk:a}){const[u,h]=m.useState(null),[p,x]=m.useState(null),[c,d]=m.useState({open:!1,trunkId:null,trunkName:""}),f=()=>{o.visit("/sip-trunk/setup")},N=s=>{o.visit(`/sip-trunk/${s}`)},v=async s=>{h(s);try{(await window.axios.post(`/sip-trunk/${s}/sync`)).data.success&&(r.success("Phone numbers synced successfully"),o.reload({preserveScroll:!0}))}catch(t){console.error("Failed to sync:",t),r.error(t.response?.data?.message||"Failed to sync phone numbers")}finally{h(null)}},k=async s=>{x(s);try{(await window.axios.post(`/sip-trunk/${s}/health`)).data.success&&(r.success("Health check completed successfully"),o.reload({preserveScroll:!0}))}catch(t){console.error("Failed to check health:",t),r.error(t.response?.data?.message||"Failed to perform health check")}finally{x(null)}},S=(s,t)=>{d({open:!0,trunkId:s,trunkName:t})},C=async()=>{if(c.trunkId)try{await window.axios.delete(`/sip-trunk/${c.trunkId}`),r.success("SIP Trunk disconnected successfully"),d({open:!1,trunkId:null,trunkName:""}),o.reload()}catch(s){console.error("Failed to disconnect:",s),r.error(s.response?.data?.message||"Failed to disconnect trunk")}},T=s=>{const t={active:"success",setting_up:"warning",error:"destructive",suspended:"default"};return e.jsx(E,{variant:t[s]||"default",children:s.replace("_"," ").toUpperCase()})},_=s=>{const t={healthy:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300",degraded:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300",down:"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300"};return e.jsx("span",{className:`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${t[s]||""}`,children:s.toUpperCase()})},D=s=>s?new Date(s).toLocaleString():"Never";return e.jsxs(Y,{breadcrumbs:O,children:[e.jsx(I,{title:"SIP Trunk"}),e.jsxs("div",{className:"space-y-6 p-4 md:p-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(P,{title:"SIP Trunk Management"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{title:"SIP Trunk Help",sections:J,documentationUrl:"/docs/documentation.html#sip-trunk"}),!a&&e.jsxs(i,{onClick:f,children:[e.jsx(j,{className:"mr-2 h-4 w-4"}),"Connect SIP Trunk Here"]})]})]}),a?e.jsx("div",{className:"grid gap-6",children:n.map(s=>e.jsxs(g,{children:[e.jsx(A,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(H,{children:s.friendly_name}),e.jsx(F,{className:"mt-1 font-mono text-xs",children:s.trunk_domain_name})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[T(s.status),_(s.health_status)]})]})}),e.jsxs(y,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(w,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Phone Numbers"})]}),e.jsx("p",{className:"mt-2 text-2xl font-bold",children:s.phone_numbers_count})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(l,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Total Calls"})]}),e.jsx("p",{className:"mt-2 text-2xl font-bold",children:s.total_calls_count.toLocaleString()})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(l,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Minutes Used"})]}),e.jsx("p",{className:"mt-2 text-2xl font-bold",children:typeof s.total_minutes_used=="string"?s.total_minutes_used:s.total_minutes_used.toFixed(2)})]}),e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(l,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Last Call"})]}),e.jsx("p",{className:"mt-2 text-sm font-medium",children:s.last_call_at?new Date(s.last_call_at).toLocaleDateString():"N/A"})]})]}),s.last_health_check_at&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Last health check: ",D(s.last_health_check_at)]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(i,{onClick:()=>N(s.id),size:"sm",children:"View Details"}),e.jsx(i,{onClick:()=>v(s.id),variant:"outline",size:"sm",disabled:u===s.id,children:u===s.id?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"mr-2 h-4 w-4 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"mr-2 h-4 w-4"}),"Sync Numbers"]})}),e.jsx(i,{onClick:()=>k(s.id),variant:"outline",size:"sm",disabled:p===s.id,children:p===s.id?e.jsxs(e.Fragment,{children:[e.jsx(l,{className:"mr-2 h-4 w-4 animate-spin"}),"Checking..."]}):e.jsxs(e.Fragment,{children:[e.jsx(l,{className:"mr-2 h-4 w-4"}),"Health Check"]})}),e.jsxs(i,{onClick:()=>S(s.id,s.friendly_name),variant:"destructive",size:"sm",children:[e.jsx(G,{className:"mr-2 h-4 w-4"}),"Disconnect"]})]})]})]},s.id))}):e.jsx(g,{children:e.jsxs(y,{className:"relative overflow-hidden p-12 text-center",children:[e.jsx("div",{className:"absolute -right-20 -top-20 h-64 w-64 rounded-full bg-muted/30 blur-3xl"}),e.jsx("div",{className:"absolute -bottom-20 -left-20 h-56 w-56 rounded-full bg-muted/30 blur-3xl"}),e.jsxs("div",{className:"relative space-y-6",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded-3xl bg-primary shadow-xl",children:e.jsx(w,{className:"h-10 w-10 text-primary-foreground"})})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-2xl font-bold",children:"No SIP Trunk Connected"}),e.jsx("p",{className:"mx-auto max-w-md text-sm leading-relaxed text-muted-foreground",children:"Connect your SIP Trunk Here."})]}),e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-3",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-secondary px-4 py-2 text-xs font-medium text-secondary-foreground shadow-sm",children:[e.jsx(l,{className:"h-3.5 w-3.5"}),"Setup in 60 Seconds"]})}),e.jsx("div",{className:"pt-2",children:e.jsxs(i,{onClick:f,size:"lg",className:"group h-14 rounded-xl px-12 text-base font-semibold shadow-lg transition-all duration-200 hover:scale-[1.02] hover:shadow-xl",children:[e.jsx(j,{className:"mr-2 h-5 w-5 transition-transform group-hover:rotate-90"}),"Connect Your SIP Trunk"]})})]})]})})]}),e.jsx(L,{open:c.open,onOpenChange:s=>!s&&d({open:!1,trunkId:null,trunkName:""}),children:e.jsxs(R,{children:[e.jsxs(B,{children:[e.jsx(z,{children:"Disconnect SIP Trunk?"}),e.jsxs(U,{children:['Are you sure you want to disconnect "',c.trunkName,'"? This will remove the trunk connection, but you can reconnect it later if needed.']})]}),e.jsxs(M,{children:[e.jsx(V,{onClick:()=>d({open:!1,trunkId:null,trunkName:""}),children:"Cancel"}),e.jsx(W,{onClick:C,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Disconnect"})]})]})})]})}export{ve as default};
//# sourceMappingURL=Index-CUuesWRn.js.map
