1import{d as R,u as k,b as p,j as e}from"./vendor-query-DPZO-Gta.js";import{b as G,j as O,r as b,L as x}from"./vendor-react-BomFe3BT.js";import{k as u,z as c,b as U}from"./index-BLzMsaFd.js";import"./vendor-charts-DodUWJ0z.js";function D(){var L,A,M;const{id:n,botId:o}=G(),i=R();let r=null;try{r=O()}catch{}const K=!!(r!=null&&r.business)||!!o,{data:j}=k({queryKey:["business-bots",n],queryFn:async()=>(await U.getBots(n)).data,enabled:!!n&&!!(r!=null&&r.business)&&!o}),a=o||(r!=null&&r.business?(L=j==null?void 0:j[0])==null?void 0:L.id:n),[Q,h]=b.useState(!1),[C,T]=b.useState(""),[_,z]=b.useState("local"),[$,B]=b.useState(""),[d,y]=b.useState(null),{data:v,isLoading:E}=k({queryKey:["chatbot-phone-numbers",a],queryFn:async()=>{console.log("[VoicebotPhoneNumbersPage] Fetching chatbot phone numbers for:",a);const s=await u.getForChatbot(a);return console.log("[VoicebotPhoneNumbersPage] Chatbot phone numbers response:",s.data),s.data},enabled:!!a}),{data:N}=k({queryKey:["phone-numbers"],queryFn:async()=>{console.log("[VoicebotPhoneNumbersPage] Fetching all phone numbers...");const s=await u.list();return console.log("[VoicebotPhoneNumbersPage] All phone numbers response:",s.data),s.data},staleTime:0}),m=p({mutationFn:s=>u.search({country_code:"US",area_code:s.areaCode||void 0,number_type:s.numberType,contains:s.contains||void 0,limit:20}),onSuccess:s=>{s.data.success===!1&&s.data.error&&c.error(s.data.error)},onError:()=>{c.error("Failed to search phone numbers")}}),f=p({mutationFn:s=>u.purchase({phone_number:s}),onSuccess:async()=>{var l;await i.invalidateQueries({queryKey:["phone-numbers"]}),await i.invalidateQueries({queryKey:["chatbot-phone-numbers",a]}),c.success("Phone number purchased! Now attaching to voicebot...");const t=(l=(await u.list()).data.phone_numbers)==null?void 0:l.find(V=>V.phone_number===d&&!V.chatbot_id);t&&w.mutate({phoneNumberId:t.id,chatbotId:a}),h(!1),y(null),m.reset()},onError:s=>{var t,l;c.error(((l=(t=s==null?void 0:s.response)==null?void 0:t.data)==null?void 0:l.error)||"Failed to purchase phone number")}}),w=p({mutationFn:({phoneNumberId:s,chatbotId:t})=>u.attach(s,{chatbot_id:t}),onSuccess:async()=>{await Promise.all([i.invalidateQueries({queryKey:["phone-numbers"]}),i.invalidateQueries({queryKey:["chatbot-phone-numbers",a]}),i.invalidateQueries({queryKey:["voice-settings",a]})]),c.success("Phone number attached to voicebot")},onError:s=>{var t,l;c.error(((l=(t=s==null?void 0:s.response)==null?void 0:t.data)==null?void 0:l.error)||"Failed to attach phone number")}}),S=p({mutationFn:s=>u.detach(s),onSuccess:async()=>{await Promise.all([i.invalidateQueries({queryKey:["phone-numbers"]}),i.invalidateQueries({queryKey:["chatbot-phone-numbers",a]}),i.invalidateQueries({queryKey:["voice-settings",a]})]),c.success("Phone number detached")},onError:()=>{c.error("Failed to detach phone number")}}),q=(v==null?void 0:v.phone_numbers)||[],F=((N==null?void 0:N.phone_numbers)||[]).filter(s=>!s.chatbot_id),P=((M=(A=m.data)==null?void 0:A.data)==null?void 0:M.phone_numbers)||[],g=s=>{const t=s.replace(/\D/g,"");return t.length===11&&t.startsWith("1")?`+1 (${t.slice(1,4)}) ${t.slice(4,7)}-${t.slice(7)}`:s},I=()=>{m.mutate({areaCode:C,numberType:_,contains:$})},W=()=>{d&&f.mutate(d)};return E?e.jsx("div",{className:"text-center py-12 text-gray-500",children:"Loading..."}):e.jsxs("div",{children:[K&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Voicebot Configuration"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Manage phone numbers for your voicebot"}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-gray-200",children:[e.jsx(x,{to:`/business/${n}/bots/voicebot/${o}/settings`,className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-900 border-b-2 border-transparent hover:border-gray-300",children:"Voice"}),e.jsx(x,{to:`/business/${n}/bots/voicebot/${o}/phone-numbers`,className:"px-4 py-2 text-sm font-medium text-primary-600 border-b-2 border-primary-500",children:"Phone Numbers"}),e.jsx(x,{to:`/business/${n}/bots/voicebot/${o}/documents`,className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-900 border-b-2 border-transparent hover:border-gray-300",children:"Knowledge Base"}),e.jsx(x,{to:`/business/${n}/bots/voicebot/${o}/ai-settings`,className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-900 border-b-2 border-transparent hover:border-gray-300",children:"AI Settings"}),e.jsx(x,{to:`/business/${n}/bots/voicebot/${o}/playground`,className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-900 border-b-2 border-transparent hover:border-gray-300",children:"Playground"})]})]}),e.jsxs("div",{className:"card mb-6",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Assigned Phone Numbers"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Phone numbers that ring this voicebot"})]}),e.jsx("button",{onClick:()=>h(!0),className:"btn btn-primary",children:"Add Phone Number"})]}),q.length>0?e.jsx("div",{className:"divide-y divide-gray-200",children:q.map(s=>e.jsxs("div",{className:"px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 bg-purple-100 rounded-lg flex items-center justify-center",children:e.jsx("svg",{className:"w-5 h-5 text-purple-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042
111.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900",children:g(s.phone_number)}),e.jsxs("p",{className:"text-sm text-gray-500",children:[s.locality&&s.region?`${s.locality}, ${s.region}`:s.number_type,s.monthly_cost&&` ⢠$${s.monthly_cost}/mo`]})]})]}),e.jsx("button",{onClick:()=>S.mutate(s.id),disabled:S.isPending,className:"text-sm text-red-600 hover:text-red-700",children:"Remove"})]},s.id))}):e.jsxs("div",{className:"px-6 py-12 text-center",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx("svg",{className:"w-6 h-6 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"})})}),e.jsx("h4",{className:"text-gray-900 font-medium mb-1",children:"No phone numbers assigned"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Add a phone number to receive calls on this voicebot"}),e.jsx("button",{onClick:()=>h(!0),className:"btn btn-primary",children:"Add Phone Number"})]})]}),F.length>0&&e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Available Numbers"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Phone numbers you own that aren't assigned to any bot"})]}),e.jsx("div",{className:"divide-y divide-gray-200",children:F.map(s=>e.jsxs("div",{className:"px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 bg-gray-100 rounded-lg flex items-center justify-center",children:e.jsx("svg",{className:"w-5 h-5 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900",children:g(s.phone_number)}),e.jsx("p",{className:"text-sm text-gray-500",children:s.locality&&s.region?`${s.locality}, ${s.region}`:s.number_type})]})]}),e.jsx("button",{onClick:()=>w.mutate({phoneNumberId:s.id,chatbotId:a}),disabled:w.isPending,className:"btn btn-secondary text-sm",children:"Assign to Voicebot"})]},s.id))})]}),Q&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-xl p-6 w-full max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:"Get a Phone Number"}),e.jsx("button",{onClick:()=>{h(!1),y(null),m.reset()},className:"text-gray-400 hover:text-gray-600",children:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Number Type"}),e.jsxs("select",{value:_,onChange:s=>z(s.target.value),className:"input w-full",children:[e.jsx("option",{value:"local",children:"Local"}),e.jsx("option",{value:"toll_free",children:"Toll-Free"}),e.jsx("option",{value:"mobile",children:"Mobile"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Area Code"}),e.jsx("input",{type:"text",value:C,onChange:s=>T(s.target.value),placeholder:"e.g. 415",className:"input w-full",maxLength:3})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Contains"}),e.jsx("input",{type:"text",value:$,onChange:s=>B(s.target.value),placeholder:"e.g. 1234",className:"input w-full"})]})]}),e.jsx("button",{onClick:I,disabled:m.isPending,className:"btn btn-primary w-full",children:m.isPending?"Searching...":"Search Available Numbers"})]}),P.length>0&&e.jsx("div",{className:"border rounded-lg divide-y max-h-64 overflow-y-auto",children:P.map(s=>e.jsxs("label",{className:`flex items-center justify-between px-4 py-3 cursor-pointer hover:bg-gray-50 ${d===s.phone_number?"bg-primary-50":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"radio",name:"phone_number",checked:d===s.phone_number,onChange:()=>y(s.phone_number),className:"text-primary-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900",children:g(s.phone_number)}),e.jsx("p",{className:"text-sm text-gray-500",children:s.locality&&s.region?`${s.locality}, ${s.region}`:s.number_type})]})]}),s.monthly_cost&&e.jsxs("span",{className:"text-sm text-gray-600",children:["$",s.monthly_cost,"/mo"]})]},s.phone_number))}),m.isSuccess&&P.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500",children:"No numbers found matching your criteria. Try different search options."}),d&&e.jsxs("div",{className:"mt-6 pt-4 border-t flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>{h(!1),y(null)},className:"btn btn-secondary",children:"Cancel"}),e.jsx("button",{onClick:W,disabled:f.isPending,className:"btn btn-primary",children:f.isPending?"Purchasing...":`Purchase ${g(d)}`})]})]})})]})}export{D as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.