1import{q as ue,r as s,a as Z,Z as xe,aj as X,b0 as he,aq as be,j as e,cB as ge,ap as fe}from"./index-XBRHUmHx.js";import{l as ve,g as ye,u as ke,f as je,a as we}from"./composer-CBd7tp6g.js";import{u as ee,g as Ne,s as C,a as Se,b as ze}from"./sms-o1l4pzi2.js";import{C as Ce}from"./ComposerToolbar-GXbtJ8do.js";function Te(h){const o=(h||"").trim(),l=o.replace(/\D/g,"");return l?o.startsWith("+")?l.length>=8?"+"+l:null:l.length===10?"+1"+l:l.length===11&&l.startsWith("1")?"+"+l:null:null}const ne=h=>{var o;return(o=h.friendlyName)!=null&&o.trim()?`${h.friendlyName.trim()} · ${h.phoneNumber}`:h.phoneNumber||""};function Ie({prefill:h,onClose:o}){var V;const[,l]=ue(),[f,T]=s.useState(h||""),[c,L]=s.useState(null),[d,w]=s.useState(""),[P,te]=s.useState(!0),[D,U]=s.useState(!1),[R,$]=s.useState(!1),[q,v]=s.useState(null),O=s.useRef(null),E=s.useRef(null),[se,re]=s.useState([]),[F,oe]=s.useState({email:"",text:""}),[Y,ae]=s.useState([]),[y,B]=s.useState(null),[p,K]=s.useState(""),[b,ie]=s.useState(null),[A,le]=s.useState(null),[k,ce]=s.useState(null);s.useEffect(()=>{var n;(n=E.current)==null||n.focus()},[]),s.useEffect(()=>{const n=t=>{t.key==="Escape"&&o()};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[o]),s.useEffect(()=>{ve().then(re).catch(()=>{}),ye().then(oe).catch(()=>{}),Z("/api/leads",{on401:"throw"}).then(n=>ae((Array.isArray(n)?n:[]).filter(t=>((t==null?void 0:t.phone)||"").trim()).map(t=>({name:[t.firstName,t.lastName].filter(Boolean).join(" ").trim()||t.company||t.phone,phone:t.phone})))).catch(()=>{}),xe().then(async n=>{B(n);const t=n.filter(u=>u.phoneNumber&&X(u.capabilities).sms);let r=null;t.some(u=>ee(u.phoneNumber))&&(r=await Ne(),le(r));const i=t.filter(u=>C(u.phoneNumber,r)),m=i.find(u=>u.isPrimary)||i[0]||t.find(u=>u.isPrimary)||t[0];m!=null&&m.phoneNumber&&K(m.phoneNumber)}).catch(()=>B([])),he().then(n=>ie(n.find(t=>t.resource==="sms")??null)).catch(()=>{}),be().then(ce).catch(()=>{})},[]);const x=s.useMemo(()=>(y||[]).filter(n=>n.phoneNumber&&X(n.capabilities).sms),[y]),W=y===null,N=!W&&(y||[]).length===0,M=!W&&!N&&x.length===0,S=b&&b.limit!=null?b.remaining??b.limit-b.used:null,I=S!=null&&S<=0,j=k?!k.smsAvailable:!1,de=j||N||M||I,z=f.trim().toLowerCase(),G=s.useMemo(()=>{if(c||!z)return[];const n=z.replace(/\D/g,""),t=new Set;return Y.filter(r=>r.name.toLowerCase().includes(z)||n&&r.phone.replace(/\D/g,"").includes(n)).filter(r=>{const i=r.phone.replace(/\D/g,"");return t.has(i)?!1:(t.add(i),!0)}).slice(0,6)},[Y,z,c]),g=Te(f),_=ke({name:c==null?void 0:c.name,phone:g||f.trim()}),a=s.useMemo(()=>Se(d),[d]),H=s.useMemo(()=>{const n=ze(d,a);return d.trim()&&p.startsWith("+1")&&n.push({level:"info",text:"US numbers must be 10DLC-registered or carriers block the text outright â check your registration if messages donât arrive."}),n},[d,a,p]),J=!!g&&!!d.trim()&&!R&&!de;function pe(n){const t=O.current;if(!t){w(m=>(m?m.replace(/\s*$/,"")+` 2 3`:"")+n);return}const r=t.selectionStart??t.value.length,i=t.selectionEnd??t.value.length;w(t.value.slice(0,r)+n+t.value.slice(i)),requestAnimationFrame(()=>{try{t.focus();const m=r+n.length;t.setSelectionRange(m,m)}catch{}})}async function me(n){const t=d.trim();if(!(!t||D)){U(!0),v(null);try{const r=await we(t,"sms",n);r&&r!==t?w(r):v("AI polish left the text unchanged â the AI service may be unavailable right now.")}catch(r){v(/403|not available|compliance/i.test((r==null?void 0:r.message)||"")?"AI polish isnât available on your plan.":"Couldnât polish â try again.")}finally{U(!1)}}}async function Q(){if(!J||!g)return;const n=d.trim(),t=P&&F.text.trim()?`${n} 4 5${F.text.trim()}`:n;$(!0),v(null);try{await Z("/api/messages",{method:"POST",on401:"throw",body:JSON.stringify({phoneNumber:g,content:t,...p?{fromNumber:p}:{}})}),ge(g,t);try{window.dispatchEvent(new CustomEvent(fe,{detail:{phone:g,text:t}}))}catch{}o(),window.location.pathname!=="/inbox"&&l("/inbox")}catch(r){const i=(r==null?void 0:r.message)||"";v(/403|access/i.test(i)?"Texting isnât enabled on your plan â upgrade to send texts.":/402|credit/i.test(i)?"International texts need credit on your account â top up under Billing.":/404|no number|not found
5/i.test(i)?"No text-capable number on your account â buy one under Numbers first.":i||"Couldnât send.")}finally{$(!1)}}return e.jsxs("div",{className:"cmp-modal-scrim",onClick:o,children:[e.jsxs("div",{className:"card pad cmp-modal nt-modal",onClick:n=>n.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"New text",children:[e.jsxs("div",{className:"nt-head",children:[e.jsx("b",{children:"New text"}),e.jsx("button",{type:"button",className:"nt-x",onClick:o,"aria-label":"Close",children:"â"})]}),j&&e.jsx("div",{className:"nt-block",children:k.smsEnabled===!1?e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"Texting is paused on your account."}),e.jsxs("span",{children:["SMS is under compliance review â inbound still works, and sends resume once it clears. ",e.jsx("a",{href:"/settings/messaging",onClick:o,children:"Messaging settings"})]})]}):k.state==="trialing"?e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"Texting starts with a paid plan."}),e.jsxs("span",{children:["Your trial covers inbound â the AI answering calls and web callbacks. Outbound calls and texts unlock when you upgrade. ",e.jsx("a",{href:"/plan",onClick:o,children:"See plans"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("b",{children:["Texting isnât included in your ",k.planName," plan."]}),e.jsxs("span",{children:["Inbound still works â your AI answers and everything lands in the Inbox. Sending a text needs a paid plan. ",e.jsx("a",{href:"/plan",onClick:o,children:"See plans"})]})]})}),!j&&N&&e.jsxs("div",{className:"nt-block",children:[e.jsx("b",{children:"You donât have a phone number yet."}),e.jsxs("span",{children:["Texts are sent from one of your own numbers. ",e.jsx("a",{href:"/numbers",onClick:o,children:"Get a number"})," to start texting."]})]}),!j&&M&&e.jsxs("div",{className:"nt-block",children:[e.jsx("b",{children:"None of your numbers can send texts."}),e.jsxs("span",{children:[x.length===0&&(y||[]).length===1?"Your number is voice-only â texting is a separate capability on the number itself.":"Your numbers are voice-only â texting is a separate capability on the number itself."," ",e.jsx("a",{href:"/numbers",onClick:o,children:"Add an SMS-capable number"}),"."]})]}),!j&&I&&!M&&!N&&e.jsxs("div",{className:"nt-block",children:[e.jsxs("b",{children:["Youâve used all ",(V=b==null?void 0:b.limit)==null?void 0:V.toLocaleString()," texts included this month."]}),e.jsxs("span",{children:["Sending resumes next cycle. ",e.jsx("a",{href:"/settings/billing",onClick:o,children:"Upgrade or add credit"})," to keep texting now."]})]}),e.jsx("label",{className:"nt-lbl",htmlFor:"nt-to",children:"To"}),e.jsxs("div",{className:"nt-to",children:[c?e.jsxs("span",{className:"nt-picked",children:[e.jsxs("span",{className:"nt-picked-txt",children:[e.jsx("b",{children:c.name}),c.name!==c.phone&&e.jsx("span",{children:c.phone})]}),e.jsx("button",{type:"button",onClick:()=>{L(null),T(""),requestAnimationFrame(()=>{var n;return(n=E.current)==null?void 0:n.focus()})},"aria-label":"Change recipient",children:"â"})]}):e.jsx("input",{id:"nt-to",ref:E,value:f,onChange:n=>T(n.target.value),placeholder:"Name or phone number, e.g. +1 415 555 0134",autoComplete:"off"}),G.length>0&&e.jsx("div",{className:"nt-sugg",children:G.map(n=>e.jsx("button",{type:"button",className:"nt-sugg-item",onClick:()=>{L(n),T(n.phone)},children:e.jsxs("span",{children:[e.jsx("b",{children:n.name}),n.name!==n.phone&&e.jsx("i",{children:n.phone})]})},n.phone))})]}),e.jsx("div",{className:"nt-hint",children:f.trim()?g?e.jsxs(e.Fragment,{children:["Sends to ",e.jsx("b",{children:g})]}):e.jsx("span",{style:{color:"var(--crit)"},children:"That doesnât look like a phone number â add the country code, e.g. +44â¦"}):"Include the country code for numbers outside the US and Canada."}),x.length>1?e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"nt-lbl",htmlFor:"nt-from",children:"From"}),e.jsx("select",{id:"nt-from",className:"nt-from",value:p,onChange:n=>K(n.target.value),children:x.map(n=>e.jsxs("option",{value:n.phoneNumber||"",children:[ne(n),n.isPrimary?" (primary)":""]},n.phoneNumber||""))}),e.jsx("div",{className:"nt-hint",children:"The recipient sees this number, and their reply comes back to it."})]}):x.length===1?e.jsxs("div",{className:"nt-from-one",children:["From ",e.jsx("b",{children:ne(x[0])})]}):null,x.length>0&&p&&!C(p,A)&&e.jsx("div",{className:"nt-block",children:ee(p)==="tollfree"?e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"This toll-free number isnât verified for texting yet."}),e.jsxs("span",{children:["US carriers block texts from unverified toll-free numbers. Contact support to verify it",x.some(n=>n.phoneNumber!==p&&C(n.phoneNumber,A))?", or pick another number above":"","."]})]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"This US number isnât registered for texting yet."}),e.jsxs("span",{children:["US carriers filter texts from unregistered senders (10DLC). ",e.jsx("a",{href:"/settings/messaging",onClick:o,children:"Register your business"}),x.some(n=>n.phoneNumber!==p&&C(n.phoneNumber,A))?", or pick another number above":""," â delivery isnât reliable until itâs approved."]})]})}),e.jsx("label",{className:"nt-lbl",htmlFor:"nt-msg",children:"Message"}),e.jsx(Ce,{channel:"sms",templates:se,onInsert:n=>pe(je(n,_)),ctx:_,hasSig:!!F.text.trim(),useSig:P,onToggleSig:()=>te(n=>
5!n),onPolish:me,polishing:D,canPolish:!!d.trim()}),e.jsx("textarea",{id:"nt-msg",ref:O,className:"nt-ta",value:d,onChange:n=>w(n.target.value),rows:4,placeholder:"Write your textâ¦",onKeyDown:n=>{(n.metaKey||n.ctrlKey)&&n.key==="Enter"&&Q()}}),e.jsxs("div",{className:"nt-count",children:[e.jsxs("span",{className:a.segments>1?"warn":"",children:[a.chars," character",a.chars===1?"":"s",a.segments>0&&e.jsxs(e.Fragment,{children:[" · ",a.segments," segment",a.segments===1?"":"s"]}),a.segments>0&&e.jsxs(e.Fragment,{children:[" · ",a.encoding]})]}),a.segments>0&&e.jsxs("span",{className:"nt-count-rem",children:[a.remaining," left in this segment"]})]}),H.length>0&&e.jsx("ul",{className:"nt-hints",children:H.map((n,t)=>e.jsx("li",{className:n.level,children:n.text},t))}),e.jsxs("div",{className:"nt-foot",children:[e.jsx("span",{className:"nt-err",children:q?e.jsx("b",{style:{color:"var(--crit)"},children:q}):S!=null&&!I?`Sends a real SMS · ${S.toLocaleString()} left this month.`:"Sends a real SMS from your number."}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{type:"button",className:"pill",onClick:o,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn",disabled:!J,onClick:Q,children:R?"Sendingâ¦":"Send text"})]})]})]}),e.jsx("style",{children:` 6 .nt-modal{max-width:540px} 7 .nt-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px} 8 .nt-head b{font-size:15px} 9 .nt-x{border:0;background:none;color:var(--muted);font-size:14px;cursor:pointer;padding:4px 6px;border-radius:8px} 10 .nt-x:hover{background:var(--line-2);color:var(--ink)} 11 .nt-lbl{display:block;font-size:11.5px;font-weight:650;color:var(--muted);margin:0 0 5px;text-transform:uppercase;letter-spacing:.03em} 12 .nt-block{border:1px solid color-mix(in srgb,var(--warn) 34%,var(--panel));background:color-mix(in srgb,var(--warn) 10%,var(--panel));border-radius:10px;padding:10px 12px;margin-bottom:14px;display:flex;flex-direction:column;gap:3px} 13 .nt-block b{font-size:13px} 14 .nt-block span{font-size:12.5px;color:var(--muted)} 15 .nt-block a{color:var(--accent-ink);font-weight:600} 16 .nt-to{position:relative;margin-bottom:6px} 17 .nt-to input{width:100%;box-sizing:border-box;border:1px solid var(--line);border-radius:10px;background:var(--panel);color:var(--ink);font-family:inherit;font-size:14px;padding:10px 12px;outline:none} 18 .nt-to input:focus{border-color:var(--accent-ink)} 19 .nt-picked{display:flex;align-items:center;gap:9px;border:1px solid var(--line);border-radius:10px;padding:7px 8px 7px 12px;background:var(--panel)} 20 .nt-picked-txt{display:flex;flex-direction:column;min-width:0;flex:1} 21 .nt-picked-txt b{font-size:13.5px} 22 .nt-picked-txt span{font-size:11.5px;color:var(--muted)} 23 .nt-picked button{border:0;background:none;color:var(--muted);cursor:pointer;font-size:12px;padding:4px 6px;border-radius:8px} 24 .nt-picked button:hover{background:var(--line-2);color:var(--ink)} 25 .nt-sugg{position:absolute;left:0;right:0;top:calc(100% + 4px);background:var(--panel);border:1px solid var(--line);border-radius:10px;box-shadow:0 10px 26px rgba(0,0,0,.14);z-index:2;overflow:hidden} 26 .nt-sugg-item{display:flex;align-items:center;gap:9px;width:100%;border:0;background:none;text-align:left;padding:8px 12px;cursor:pointer;font-family:inherit;color:var(--ink)} 27 .nt-sugg-item:hover{background:var(--line-2)} 28 .nt-sugg-item b{font-size:13px;display:block} 29 .nt-sugg-item i{font-size:11.5px;color:var(--muted);font-style:normal} 30 .nt-hint{font-size:11.5px;color:var(--faint);margin-bottom:14px} 31 .nt-from{width:100%;box-sizing:border-box;border:1px solid var(--line);border-radius:10px;background:var(--panel);color:var(--ink);font-family:inherit;font-size:13.5px;padding:9px 11px;margin-bottom:6px} 32 .nt-from-one{font-size:12.5px;color:var(--muted);margin-bottom:14px} 33 .nt-from-one b{color:var(--ink-2);font-weight:600} 34 .nt-ta{width:100%;box-sizing:border-box;border:1px solid var(--line);border-radius:12px;background:var(--panel);color:var(--ink);font-family:inherit;font-size:14px;line-height:1.5;padding:11px 13px;resize:vertical;min-height:92px;outline:none} 35 .nt-ta:focus{border-color:var(--accent-ink)} 36 .nt-count{display:flex;justify-content:space-between;gap:10px;font-size:11.5px;color:var(--faint);margin-top:6px} 37 .nt-count .warn{color:var(--warn)} 38 .nt-count-rem{white-space:nowrap} 39 .nt-hints{list-style:none;margin:9px 0 0;padding:0;display:flex;flex-direction:column;gap:6px} 40 .nt-hints li{font-size:11.5px;line-height:1.45;color:var(--muted);padding-left:18px;position:relative} 41 .nt-hints li::before{position:absolute;
41left:0;top:0} 42 .nt-hints li.warn::before{content:"â ";color:var(--warn)} 43 .nt-hints li.info::before{content:""} 44 .nt-foot{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:14px;flex-wrap:wrap} 45 .nt-err{font-size:11.5px;color:var(--faint);flex:1;min-width:150px} 46 /* Composer toolbar â the Inbox page owns these, but this modal opens on 47 any route, so it carries its own copy. */ 48 .nt-modal .ibx-tools{display:flex;gap:7px;flex-wrap:wrap;margin-bottom:8px} 49 .nt-modal .ibx-tool{position:relative} 50 .nt-modal .ibx-tool-scrim{position:fixed;inset:0;z-index:1} 51 .nt-modal .ibx-tool-btn{border:1px solid var(--line);background:var(--panel);color:var(--muted);border-radius:999px;padding:5px 11px;font-size:11.5px;font-weight:600;cursor:pointer;font-family:inherit} 52 .nt-modal .ibx-tool-btn:hover:not(:disabled){background:var(--line-2);color:var(--ink-2)} 53 .nt-modal .ibx-tool-btn:disabled{opacity:.5;cursor:not-allowed} 54 .nt-modal .ibx-tool-btn.sig.on{background:var(--accent-soft);color:var(--accent-ink);border-color:color-mix(in srgb,var(--accent) 30%,var(--panel))} 55 .nt-modal .ibx-pop{position:absolute;top:calc(100% + 5px);left:0;z-index:2;min-width:230px;max-width:300px;max-height:240px;overflow:auto;background:var(--panel);border:1px solid var(--line);border-radius:10px;box-shadow:0 10px 26px rgba(0,0,0,.14);padding:4px} 56 .nt-modal .ibx-pop-item{display:block;width:100%;text-align:left;border:0;background:none;padding:7px 9px;border-radius:8px;cursor:pointer;font-family:inherit;color:var(--ink)} 57 .nt-modal .ibx-pop-item:hover{background:var(--line-2)} 58 .nt-modal .ibx-pop-item b{display:block;font-size:12.5px} 59 .nt-modal .ibx-pop-item span{display:block;font-size:11px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap} 60 .nt-modal .ibx-pop-empty{padding:10px;font-size:12px;color:var(--muted);text-align:center} 61 .nt-modal .ibx-pop-empty span{font-size:11px;color:var(--faint)} 62 `})]})}export{Ie as default,Te as toE164};
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.