1import{k as a,j as t}from"./vendor-Dfxs0MA2.js";import{u as E,s as l,t as n}from"./index-5f6L9I3c.js";function P({onClose:i,onSaved:N}){E();const[d,S]=a.useState([]),[r,u]=a.useState(""),[p,w]=a.useState(()=>{const e=new Date;e.setDate(e.getDate()+1),e.setHours(11,0,0,0);const s=o=>String(o).padStart(2,"0");return`${e.getFullYear()}-${s(e.getMonth()+1)}-${s(e.getDate())}T${s(e.getHours())}:${s(e.getMinutes())}`}),[h,_]=a.useState("test_drive"),[m,C]=a.useState(30),[x,k]=a.useState(""),[g,D]=a.useState(""),[v,j]=a.useState(!1),[f,y]=a.useState(null);a.useEffect(()=>{(async()=>{if(!l)return;const{data:e}=await l.auth.getUser();if(!e.user)return;const{data:s}=await l.from("prospects").select("*").eq("user_id",e.user.id).order("created_at",{ascending:!1}).limit(200);S(s||[]),s&&s.length>0&&u(s[0].id)})()},[]);const c=d.find(e=>e.id===r)||null,b=(c==null?void 0:c.washout_no_show_count)||0;async function A(e){if(e.preventDefault(),!!l){y(null),j(!0);try{const{data:s}=await l.auth.getUser();if(!s.user)throw new Error("Not signed in");const{error:o}=await l.from("appointments").insert({user_id:s.user.id,prospect_id:r||null,scheduled_at:new Date(p).toISOString(),duration_minutes:m,type:h,location:x.trim()||null,notes:g.trim()||null,status:"pending"});if(o)throw o;N()}catch(s){y(s instanceof Error?s.message:"Could not save")}finally{j(!1)}}}return t.jsx("div",{className:"mask",onClick:i,children:t.jsxs("div",{className:"modal-card",onClick:e=>e.stopPropagation(),children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:6},children:[t.jsx("h2",{className:"modal-h",children:"Book appointment"}),t.jsx("button",{onClick:i,style:{background:"transparent",border:"none",color:"var(--text-tertiary)",fontSize:22},children:"Ã"})]}),f&&t.jsx("div",{className:"err",children:f}),t.jsxs("form",{onSubmit:A,children:[t.jsx("label",{className:"lbl",children:"Lead"}),t.jsxs("select",{className:"inp",value:r,onChange:e=>u(e.target.value),children:[t.jsx("option",{value:"",children:"â No lead yet â"}),d.map(e=>t.jsxs("option",{value:e.id,children:[e.name,e.vehicle?` · ${e.vehicle}`:"",(e.washout_no_show_count||0)>0?" â ï¸":""]},e.id))]}),b>0&&t.jsx("div",{style:{marginBottom:10,fontSize:13,color:"var(--text-tertiary)"},children:n("appointments.washoutWarningNote",{count:String(b)})}),t.jsx("label",{className:"lbl",children:"When *"}),t.jsx("input",{className:"inp",type:"datetime-local",value:p,onChange:e=>w(e.target.value),required:!0}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[t.jsxs("div",{children:[t.jsx("label",{className:"lbl",children:"Type"}),t.jsxs("select",{className:"inp",value:h,onChange:e=>_(e.target.value),children:[t.jsx("option",{value:"test_drive",children:"Test drive"}),t.jsx("option",{value:"sit_down",children:"Sit-down meeting"}),t.jsx("option",{value:"delivery",children:"Delivery"}),t.jsx("option",{value:"phone_call",children:"Phone call"}),t.jsx("option",{value:"other",children:"Other"})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"lbl",children:n("addAppt.duration")}),t.jsx("input",{className:"inp",type:"number",min:15,step:15,value:m,onChange:e=>C(parseInt(e.target.value))})]})]}),t.jsx("label",{className:"lbl",children:n("addAppt.location")}),t.jsx("input",{className:"inp",value:x,onChange:e=>k(e.target.value),placeholder:n("addAppt.locationPlaceholder")}),t.jsx("label",{className:"lbl",children:n("addAppt.notes")}),t.jsx("textarea",{className:"inp",style:{minHeight:60,resize:"vertical"},value:g,onChange:e=>D(e.target.value),placeholder:n("addAppt.notesPlaceholder")}),t.jsxs("div",{style:{display:"flex",gap:8,marginTop:20},children:[t.jsx("button",{type:"button",onClick:i,className:"cta-ghost",style:{flex:1},children:n("common.cancel")}),t.jsx("button",{type:"submit",disabled:v,className:"cta-btn",style:{flex:2},children:v?n("common.saving"):n("addAppt.bookCta")})]})]})]})})}export{P 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.