PageSourceSearch

https://agentoai.dk/assets/PublicBooking-C3mZGFqk.js

js agentoai.dk collected 2026-10-02 01:53:08 UTC 9,817 bytes, 2 lines download raw bytes

1import{r as o,j as e}from"./framer-motion-CQxuJa5n.js";import{n as Z,s as _,p as Q,C as L,i as M,f as X,g as ee,w as te,B as m,j as A,I as U}from"./index-CSx7K-7R.js";import{C as se}from"./clock-x2s7C7KC.js";import{C as ae}from"./circle-check-B_lwCfqV.js";import{D as ne}from"./download-B29izdwZ.js";import{E as V}from"./external-link-VZCHNZAP.js";import{P as re}from"./phone-DfeYL_-y.js";import"./recharts-CFjfazL9.js";const oe=()=>{const a=[];for(let t=8;t<=17;t++)for(let r=0;r<60&&!(t===17&&r>0);r+=30){const l=`${String(t).padStart(2,"0")}:${String(r).padStart(2,"0")}`;a.push({time:l,label:`Kl. ${l}`})}return a},le=()=>{const a=[],t=new Date;for(let r=0;r<14;r++){const l=new Date(t);l.setDate(t.getDate()+r),l.getDay()!==0&&l.getDay()!==6&&a.push(l)}return a},T=a=>{const t=["Søndag","Mandag","Tirsdag","Onsdag","Torsdag","Fredag","Lørdag"],r=["jan","feb","mar","apr","maj","jun","jul","aug","sep","okt","nov","dec"];return`${t[a.getDay()]} ${a.getDate()}. ${r[a.getMonth()]}`},ie=a=>a.toISOString().split("T")[0];function P(a,t,r,l){const c=new Date(`${a}T${t}:00`),n=new Date(c);n.setMinutes(n.getMinutes()+30);const h=b=>b.toISOString().replace(/[-:]/g,"").replace(/\.\d{3}/,"");return["BEGIN:VCALENDAR","VERSION:2.0","PRODID:-//Booking//DA","BEGIN:VEVENT",`DTSTART:${h(c)}`,`DTEND:${h(n)}`,`SUMMARY:${l||"Aftale"} - ${r}`,"END:VEVENT","END:VCALENDAR"].join(`\r
2`)}function ce(a,t,r,l){const c=new Date(`${a}T${t}:00`),n=new Date(c);n.setMinutes(n.getMinutes()+30);const h=b=>b.toISOString().replace(/[-:]/g,"").replace(/\.\d{3}/,"");return`https://calendar.google.com/calendar/render?action=TEMPLATE&text=${encodeURIComponent(`${l||"Aftale"} - ${r}`)}&dates=${h(c)}/${h(n)}`}function de(a,t,r,l){const c=new Date(`${a}T${t}:00`),n=new Date(c);return n.setMinutes(n.getMinutes()+30),`https://outlook.live.com/calendar/0/action/compose?subject=${encodeURIComponent(`${l||"Aftale"} - ${r}`)}&startdt=${c.toISOString()}&enddt=${n.toISOString()}`}function ke(){const{token:a}=Z(),[t,r]=o.useState(null),[l,c]=o.useState(""),[n,h]=o.useState(null),[b,v]=o.useState(!0),[E,S]=o.useState(null),[x,j]=o.useState("date"),[u,K]=o.useState(null),[g,q]=o.useState(null),[C,B]=o.useState(""),[D,G]=o.useState(""),[I,O]=o.useState(!1),[y,z]=o.useState(""),[N,F]=o.useState(""),J=o.useMemo(()=>oe(),[]),W=o.useMemo(()=>le(),[]);o.useEffect(()=>{a&&(async()=>{v(!0);const{data:s,error:p}=await _.from("booking_sessions").select("*").eq("token",a).maybeSingle();if(p||!s){S("Booking-linket er ugyldigt eller udløbet."),v(!1);return}if(new Date(s.expires_at)<new Date){S("Booking-linket er udløbet."),v(!1);return}s.status==="booked"&&j("done"),r(s),B(s.caller_name||"");const{data:d}=await _.from("voice_agents").select("name, user_id").eq("id",s.agent_id).single();if(d){c(d.name);const{data:f}=await _.from("partner_tenants").select("partner_user_id").eq("agent_id",s.agent_id).maybeSingle();if(f?.partner_user_id){const{data:w}=await _.from("partner_whitelabel_config").select("logo_url, company_name, primary_color").eq("partner_user_id",f.partner_user_id).maybeSingle();w&&h(w)}}v(!1)})()},[a]);const i=n?.primary_color||"hsl(var(--primary))",k=n?.company_name||l,Y=async()=>{if(!t||!u||!g)return;O(!0),S(null);const s=ie(u);try{const p=await fetch("https://lhplkrosdckrjrfeaoan.supabase.co/functions/v1/create-voice-booking",{method:"POST",headers:{"Content-Type":"application/json",apikey:"sb_publishable_VaRxlTJflLmIKI_3fWbMkA_ON9YaoZt"},body:JSON.stringify({agent_id:t.agent_id,booking_session_token:a,customer_name:C||t.caller_name||"Kunde",customer_phone:t.caller_phone,customer_email:D||void 0,booking_date:s,booking_time:g,notes:t.service_type?`Service: ${t.service_type}`:void 0})}),d=await p.json();if(!p.ok||!d.success)throw new Error(d.error||"Booking fejlede");await _.from("booking_sessions").update({status:"booked",booking_id:d.bookingId||d.id,caller_name:C||t.caller_name,caller_email:D||void 0}).eq("id",t.id),z(s),F(g),j("done"),setTimeout(()=>{const f=P(s,g,k,t?.service_type||""),w=new Blob([f],{type:"text/calendar"}),R=URL.createObjectURL(w),$=document.createElement("a");$.href=R,$.download="booking.ics",$.click(),URL.revokeObjectURL(R)},500)}catch(p){console.error("Booking error:",p),S(p?.message||"Kunne ikke oprette booking. Prøv igen.")}finally{O(!1)}},H=()=>
2{const s=P(y,N,k,t?.service_type||""),p=new Blob([s],{type:"text/calendar"}),d=URL.createObjectURL(p),f=document.createElement("a");f.href=d,f.download="booking.ics",f.click(),URL.revokeObjectURL(d)};return b?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(Q,{className:"h-8 w-8 animate-spin text-primary"})}):E&&x!=="done"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsx(L,{className:"w-full max-w-md",children:e.jsx(M,{className:"pt-6 text-center",children:e.jsx("p",{className:"text-destructive",children:E})})})}):e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs(L,{className:"w-full max-w-lg overflow-hidden",children:[n&&e.jsxs("div",{className:"p-4 flex items-center justify-center gap-3",style:{backgroundColor:`${i}10`},children:[n.logo_url&&e.jsx("img",{src:n.logo_url,alt:n.company_name||"",className:"h-8 object-contain"}),!n.logo_url&&n.company_name&&e.jsx("span",{className:"font-bold text-lg",style:{color:i},children:n.company_name})]}),e.jsxs(X,{className:"text-center",children:[e.jsxs(ee,{className:"text-xl flex items-center justify-center gap-2",children:[e.jsx(te,{className:"h-5 w-5",style:{color:i}}),x==="done"?"Booking bekræftet!":`Book tid hos ${k}`]}),t?.service_type&&x!=="done"&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Service: ",t.service_type]}),t?.timeframe&&x!=="done"&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Ønsket: ",t.timeframe]})]}),e.jsxs(M,{children:[x==="date"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm font-medium",children:"Vælg en dag:"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:W.map(s=>e.jsx(m,{variant:u?.toDateString()===s.toDateString()?"default":"outline",className:"justify-start text-left text-sm h-auto py-3",onClick:()=>K(s),style:u?.toDateString()===s.toDateString()?{backgroundColor:i}:{},children:T(s)},s.toISOString()))}),e.jsx(m,{className:"w-full mt-4",disabled:!u,onClick:()=>j("time"),style:{backgroundColor:i},children:"Vælg tidspunkt →"})]}),x==="time"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>j("date"),children:"← Tilbage"}),e.jsxs("p",{className:"text-sm font-medium flex items-center gap-1",children:[e.jsx(se,{className:"h-4 w-4"}),"Vælg tidspunkt for ",u&&T(u),":"]}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:J.map(s=>e.jsx(m,{variant:g===s.time?"default":"outline",size:"sm",onClick:()=>q(s.time),style:g===s.time?{backgroundColor:i}:{},children:s.label},s.time))}),e.jsx(m,{className:"w-full mt-4",disabled:!g,onClick:()=>j("confirm"),style:{backgroundColor:i},children:"Bekræft →"})]}),x==="confirm"&&u&&g&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>j("time"),children:"← Tilbage"}),e.jsxs("div",{className:"rounded-lg p-4 space-y-2",style:{backgroundColor:`${i}08`},children:[e.jsx("p",{className:"font-medium",children:"Din booking:"}),e.jsxs("p",{className:"text-sm",children:["📅 ",T(u)]}),e.jsxs("p",{className:"text-sm",children:["🕐 Kl. ",g]}),t?.service_type&&e.jsxs("p",{className:"text-sm",children:["📋 ",t.service_type]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:"name",children:"Navn"}),e.jsx(U,{id:"name",value:C,onChange:s=>B(s.target.value),placeholder:"Dit navn"})]}),e.jsxs("div",{children:[e.jsx(A,{htmlFor:"email",children:"Email (valgfrit)"}),e.jsx(U,{id:"email",type:"email",value:D,onChange:s=>G(s.target.value),placeholder:"[email protected]"})]})]}),e.jsx(m,{className:"w-full",onClick:Y,disabled:I||!C,style:{backgroundColor:i},children:I?"Booker...":"✅ Bekræft booking"})]}),x==="done"&&e.jsxs("div",{className:"space-y-5 text-center",children:[e.jsx(ae,{className:"h-14 w-14 mx-auto",style:{color:i}}),e.jsx("p",{className:"text-xl font-semibold",children:"Din tid er booket! 🎉"}),y&&N&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl p-5 space-y-2 border",style:{backgroundColor:`${i}08`,borderColor:`${i}30`},children:[e.jsxs("p",{className:"text-base font-medium",children:["📅 ",y]}),e.jsxs("p",{className:"text-base font-medium",children:["🕐 Kl. ",N]}),t?.service_type&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["📋 ",t.service_type]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm font-medium",children:"Tilføj til din kalender:"}),e.jsxs(m,{className:"w-full text-base py-6 font-semibold",size:"lg",onClick:H,style:{backgroundColor:i},children:[e.jsx(ne,{className:"h-5 w-5 mr-2"}),"📲 Gem i kalender"]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(m,{variant:"outline",className:"flex-1 text-sm py-3",asChild:!0,children:e.jsxs("a",{href:ce(y,N,k,t?.service_type||""),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(V,{className:"h-3 w-3 mr-1"})," Google Calendar"]})}),e.jsx(m,{variant:"outline",className:"flex-1 text-sm py-3",asChild:!0,children:e.jsxs("a",{href:de(y,N,k,t?.service_type||""),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(V,{className:"h-3 w-3 mr-1"})," Outlook"]})})]})]})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center justify-center gap-1",children:[e.jsx(re,{className:"h-3 w-3"})," Booket via ",k]})})]})]})]})})}export{ke 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.