1import{k as t,j as e}from"./vendor-Dfxs0MA2.js";import{u as A,t as s,s as c}from"./index-CIKckvOq.js";function $({onClose:d,onSaved:N}){A();const[h,S]=t.useState(""),[p,C]=t.useState(""),[x,k]=t.useState(""),[g,w]=t.useState(""),[n,E]=t.useState("en"),[b,L]=t.useState(""),[f,r]=t.useState(!1),[v,i]=t.useState(null);async function z(a){var y;if(a.preventDefault(),!!c){r(!0),i(null);try{const{data:o}=await c.auth.getUser(),u=(y=o.user)==null?void 0:y.id;if(!u)throw new Error("Not signed in");const l=p.trim();if(l){const{data:j}=await c.from("prospects").select("id").eq("user_id",u).eq("phone",l).limit(1);if(j&&j.length>0){i(`A lead with phone ${l} already exists. Open it from the Leads tab.`),r(!1);return}}const{error:m}=await c.from("prospects").insert({user_id:u,name:h.trim(),phone:l||null,email:x.trim()||null,vehicle:g.trim()||null,language:n,notes:b.trim()||null,stage:"nuevo",source:"manual"});if(m){if(m.code==="23505"){i(`A lead with phone ${l} already exists.`),r(!1);return}throw m}N()}catch(o){i(o instanceof Error?o.message:"Could not save")}finally{r(!1)}}}return e.jsx("div",{className:"mask",onClick:d,children:e.jsxs("div",{className:"modal-card",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:6},children:[e.jsx("h2",{className:"modal-h",children:s("addLead.title")}),e.jsx("button",{onClick:d,style:{background:"transparent",border:"none",color:"var(--text-tertiary)",fontSize:22},children:"Ã"})]}),e.jsx("p",{className:"modal-sub",children:s("addLead.subtitle")}),v&&e.jsx("div",{className:"err",children:v}),e.jsxs("form",{onSubmit:z,children:[e.jsx("label",{className:"lbl",children:"Name *"}),e.jsx("input",{className:"inp",value:h,onChange:a=>S(a.target.value),required:!0,placeholder:"Maria Rodriguez"}),e.jsx("label",{className:"lbl",children:s("common.phone")}),e.jsx("input",{className:"inp",type:"tel",value:p,onChange:a=>C(a.target.value),placeholder:"(512) 555-0143"}),e.jsx("label",{className:"lbl",children:s("common.email")}),e.jsx("input",{className:"inp",type:"email",value:x,onChange:a=>k(a.target.value),placeholder:"[email protected]"}),e.jsx("label",{className:"lbl",children:s("common.vehicleOfInterest")}),e.jsx("input",{className:"inp",value:g,onChange:a=>w(a.target.value),placeholder:"2024 Toyota RAV4"}),e.jsx("label",{className:"lbl",children:s("common.language")}),e.jsx("div",{style:{display:"flex",gap:6},children:["en","es"].map(a=>e.jsx("button",{type:"button",onClick:()=>E(a),style:{flex:1,padding:"10px 14px",borderRadius:10,background:n===a?"var(--primary-soft)":"var(--tint-1)",border:`1px solid ${n===a?"var(--primary)":"var(--border-default)"}`,color:n===a?"var(--primary)":"var(--text-secondary)",fontWeight:600,fontSize:13},children:a==="en"?"English":"Spanish"},a))}),e.jsx("label",{className:"lbl",children:s("common.notes")}),e.jsx("textarea",{className:"inp",style:{minHeight:70,resize:"vertical"},value:b,onChange:a=>L(a.target.value),placeholder:"What did they say?"}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[e.jsx("button",{type:"button",onClick:d,className:"cta-ghost",style:{flex:1},children:s("common.cancel")}),e.jsx("button",{type:"submit",disabled:f,className:"cta-btn",style:{flex:2},children:f?"Savingâ¦":"Save lead â"})]})]})]})})}export{$ 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.