1import{k as o,j as e}from"./vendor-Dfxs0MA2.js";import{d as w}from"./SellerConsole-DjgxrZyx.js";import{u as S,s as a,t as y}from"./index-CIKckvOq.js";function C({onClose:d}){S();const l=w(),[r,s]=o.useState({twilio_number:"",personal_number:"",voice_enabled:!0,greeting_es:"",greeting_en:""}),[u,b]=o.useState([]),[f,v]=o.useState(!0),[g,p]=o.useState(!1);o.useEffect(()=>{(async()=>{if(!a)return;const{data:t}=await a.auth.getUser();if(!t.user)return;const[n,c]=await Promise.all([a.from("phone_numbers").select("*").eq("user_id",t.user.id).maybeSingle(),a.from("phone_calls").select("id, from_number, caller_name, vehicle_interest, ai_decision, ai_urgency, transcript, created_at").eq("user_id",t.user.id).order("created_at",{ascending:!1}).limit(20)]);n.data&&s(n.data),b(c.data??[]),v(!1)})()},[]);function m(t){const n=t.replace(/\D/g,"");return n.length===10?"+1"+n:n.length===11&&n.startsWith("1")||n.length>0&&!t.startsWith("+")?"+"+n:t.trim()}async function _(){var c,h;if(!a)return;const t=m(r.twilio_number),n=m(r.personal_number);if(!/^\+[1-9]\d{6,14}$/.test(t)){l.push("error","Twilio number must be in E.164 format (e.g. +18774015407)");return}if(!/^\+[1-9]\d{6,14}$/.test(n)){l.push("error","Personal cell must be in E.164 format");return}p(!0);try{const{data:i}=await a.auth.getUser();if(!i.user)throw new Error("not signed in");const j={user_id:i.user.id,twilio_number:t,personal_number:n,voice_enabled:r.voice_enabled,greeting_es:((c=r.greeting_es)==null?void 0:c.trim())||null,greeting_en:((h=r.greeting_en)==null?void 0:h.trim())||null},{error:x}=await a.from("phone_numbers").upsert(j,{onConflict:"user_id"});if(x)throw x;l.push("success","â Phone receptionist configured")}catch(i){l.push("error",i instanceof Error?i.message:"Could not save")}finally{p(!1)}}return e.jsx("div",{className:"mask",onClick:d,children:e.jsxs("div",{className:"modal-card",style:{maxWidth:560,maxHeight:"90vh",overflowY:"auto"},onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:4},children:[e.jsx("h2",{className:"modal-h",children:"AI Phone Receptionist"}),e.jsx("button",{onClick:d,style:{background:"transparent",border:"none",color:"var(--text-tertiary)",fontSize:22},children:"Ã"})]}),e.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",marginBottom:14},children:'Cuando un cliente llama, AI contesta bilingüe, captura intent y solo te reenvÃa las llamadas serias con un "whisper" que te dice quién llama y por qué.'}),f?e.jsx("div",{style:{padding:40,textAlign:"center",color:"var(--text-tertiary)"},children:y("common.loading")||"Loadingâ¦"}):e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"lbl",children:"Twilio number (E.164)"}),e.jsx("input",{className:"inp",type:"tel",placeholder:"+18774015407",value:r.twilio_number,onChange:t=>s({...r,twilio_number:t.target.value})}),e.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginTop:-6,marginBottom:10},children:"The Twilio number you bought. Customers call this."}),e.jsx("label",{className:"lbl",children:"Your personal cell (E.164)"}),e.jsx("input",{className:"inp",type:"tel",placeholder:"+15551234567",value:r.personal_number,onChange:t=>s({...r,personal_number:t.target.value})}),e.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginTop:-6,marginBottom:10},children:"Where serious calls get forwarded. Never shown to the customer."}),e.jsx("label",{className:"lbl",style:{marginTop:10},children:"Spanish greeting (optional)"}),e.jsx("textarea",{className:"inp",rows:2,placeholder:"Hola, soy el asistente de [tu nombre] en [dealer]. ¿Buscas info de un carro o quieres hablar directo conmigo?",value:r.greeting_es??"",onChange:t=>s({...r,greeting_es:t.target.value})}),e.jsx("label",{className:"lbl",children:"English greeting (optional)"}),e.jsx("textarea",{className:"inp",rows:2,placeholder:"Hi, this is [your name]'s assistant at [dealer]. Looking for car info or want to speak with me directly?",value:r.greeting_en??"",onChange:t=>s({...r,greeting_en:t.target.value})}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,marginTop:14,padding:"10px 12px",background:"rgba(0,0,0,.02)",borderRadius:10},children:[e.jsx("input",{type:"checkbox",checked:r.voice_enabled,onChange:t=>s({...r,voice_enabled:t.target.checked})}),e.jsxs("span",{children:[e.jsx("strong",{children:"Voice enabled"})," â AI answers. Uncheck to ring your personal cell directly."]})]}),e.jsxs("div",{style:{background:"rgba(245, 158, 11, .08)",border:"1px solid rgba(245, 158, 11, .25)",color:"#78350f",padding:"12px 14px",borderRadius:10,fontSize:12,marginTop:14,lineHeight:1.5},children:[e.jsx("strong",{children:"In Twilio Console, configure your number's Voice webhook:"}),e.jsxs("div",{style:{fontFamily:"ui-monospace, monospace",marginTop:4,fontSize:11,wordBreak:"break-all"},children:["URL: https://www.auttiv.com/api/voice/incoming",e.jsx("br",{}),"Method: POST"]}),e.jsxs("div",{style:{marginTop:6},children:["Also: in Supabase Dashboard â Edge Functions Secrets, add ",e.jsx("code",{style:{fontSize:11},children:"TWILIO_AUTH_TOKEN"})," = your Twilio Auth Token (signs every request so attackers can't fake calls)."]})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:18},children:[e.jsx("button",{type:"button",onClick:d,className:"cta-ghost",style:{flex:1},children:y("common.cancel")}),e.jsx("button",{type:"button",onClick:_,disabled:g,className:"cta-btn",style:{flex:2},children:g?"Savingâ¦":"Save configuration â"})]}),e.jsxs("div",{style:{marginTop:26},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,letterSpacing:2,textTransform:"uppercase",color:"var(--text-tertiary)",marginBottom:8},children:"Recent calls"}),u.length===0?e.jsx("div",{style:{fontSize:12,color:"var(--text-tertiary)",padding:14,textAlign:"center",background:"rgba(0,0,0,.02)",borderRadius:10},children:"No calls yet. They'll show up here as customers call your Twilio number."}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:u.map(t=>e.jsxs("div",{style:{background:"rgba(0,0,0,.02)",border:"1px solid var(--border-subtle)",borderRadius:10,padding:"10px 12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:12},children:[e.jsx("strong",{children:t.caller_name||t.from_number||"Unknown"}),e.jsx("span",{style:{color:"var(--text-tertiary)",fontSize:11}
1,children:new Date(t.created_at).toLocaleString()})]}),e.jsxs("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:[t.ai_decision==="FORWARD"&&e.jsx("span",{style:{color:"#16a34a"},children:"Forwarded"}),t.ai_decision==="MESSAGE"&&e.jsx("span",{style:{color:"#2563eb"},children:"Message taken"}),t.ai_decision==="HANGUP_SPAM"&&e.jsx("span",{style:{color:"#dc2626"},children:"Spam blocked"}),t.ai_urgency&&e.jsxs("span",{style:{marginLeft:8,color:"var(--text-tertiary)"},children:["· ",t.ai_urgency," urgency"]}),t.vehicle_interest&&e.jsxs("span",{style:{marginLeft:8},children:["· ",t.vehicle_interest]})]}),t.transcript&&e.jsxs("div",{style:{fontSize:11,color:"var(--text-tertiary)",fontStyle:"italic",marginTop:4},children:['"',t.transcript,'"']})]},t.id))})]})]})]})})}export{C 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.