1import{a as w,j as e}from"./trpc-vendor-Bta84Nsh.js";import{t as o,B as d,L as n,I as c}from"./index-_3-B0itT.js";import{t as r,n as k,aA as S,cH as j,ap as T,K as M,as as B,av as C,aY as A,g as $,b as z,f as E}from"./ui-vendor-NEZNvIbV.js";import"./react-vendor-DpXpH6G7.js";const V=[{v:1,label:"Mo"},{v:2,label:"Di"},{v:3,label:"Mi"},{v:4,label:"Do"},{v:5,label:"Fr"},{v:6,label:"Sa"},{v:0,label:"So"}],D={pending:"Offen",confirmed:"Bestätigt",completed:"Erledigt",cancelled:"Storniert",no_show:"No-Show"},F={pending:"bg-zinc-500/20 text-zinc-300",confirmed:"bg-green-500/20 text-green-400",completed:"bg-blue-500/20 text-blue-400",cancelled:"bg-red-500/20 text-red-400",no_show:"bg-orange-500/20 text-orange-400"};function P(){const m=o.useUtils(),{data:u=[]}=o.agencyVisits.listSlots.useQuery({daysAhead:90}),{data:h=[]}=o.agencyVisits.listBookings.useQuery(),[a,i]=w.useState({dateFrom:"",dateTo:"",weekdays:[2],timeFrom:"10:00",timeTo:"18:00",durationMinutes:120,region:""}),p=o.agencyVisits.generateSlots.useMutation({onSuccess:t=>{r.success(`${t.created} Slot(s) angelegt${t.skipped?` (${t.skipped} übersprungen)`:""}`),m.agencyVisits.listSlots.invalidate()},onError:t=>r.error(t.message)}),N=o.agencyVisits.deleteSlot.useMutation({onSuccess:()=>{r.success("Slot gelöscht"),m.agencyVisits.listSlots.invalidate()},onError:t=>r.error(t.message)}),l=o.agencyVisits.updateBookingStatus.useMutation({onSuccess:()=>{r.success("Status aktualisiert"),m.agencyVisits.listBookings.invalidate(),m.agencyVisits.listSlots.invalidate()},onError:t=>r.error(t.message)}),f=t=>{i(s=>({...s,weekdays:s.weekdays.includes(t)?s.weekdays.filter(x=>x!==t):[...s.weekdays,t].sort()}))},v=()=>{if(!a.dateFrom||!a.dateTo)return r.error("Datumsbereich angeben");if(a.weekdays.length===0)return r.error("Mindestens 1 Wochentag wählen");p.mutate({dateFrom:a.dateFrom,dateTo:a.dateTo,weekdays:a.weekdays,timeFrom:a.timeFrom,timeTo:a.timeTo,durationMinutes:a.durationMinutes,region:a.region.trim()||void 0})},g=t=>new Date(Number(t)).toLocaleString("de-DE",{weekday:"short",day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",timeZone:"Europe/Berlin"}),y=typeof window<"u"?`${window.location.origin}/moremembers/vor-ort`:"/moremembers/vor-ort";return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(k,{className:"w-6 h-6 text-yellow-400"})," Vor-Ort-Termine"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Slots fuer Agentur-Verkaufsbesuche bei Studio-Inhabern."})]}),e.jsxs(d,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(y),r.success("Link kopiert")},children:[e.jsx(S,{className:"w-3.5 h-3.5 mr-1.5"})," Buchungs-Link kopieren"]})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{className:"w-4 h-4 text-yellow-400"}),e.jsx("p",{className:"text-sm font-semibold",children:"Slots generieren (Bulk-Regel)"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-1",children:'Beispiel: "Jeden Dienstag von 10â18 Uhr je 2h-Slots" â Server erzeugt alle einzelnen Slots im Datumsbereich.'}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Von Datum"}),e.jsx(c,{type:"date",value:a.dateFrom,onChange:t=>i(s=>({...s,dateFrom:t.target.value})),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Bis Datum"}),e.jsx(c,{type:"date",value:a.dateTo,onChange:t=>i(s=>({...s,dateTo:t.target.value})),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Uhrzeit von"}),e.jsx(c,{type:"time",value:a.timeFrom,onChange:t=>i(s=>({...s,timeFrom:t.target.value})),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Uhrzeit bis"}),e.jsx(c,{type:"time",value:a.timeTo,onChange:t=>i(s=>({...s,timeTo:t.target.value})),className:"mt-1"})]})]}),e.jsxs("div",{children:[e.jsx(n,{className:"text-xs mb-2 block",children:"Wochentage"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:V.map(t=>{const s=a.weekdays.includes(t.v);return e.jsx("button",{type:"button",onClick:()=>f(t.v),className:`w-12 h-9 rounded-md text-sm font-medium transition-colors ${s?"bg-yellow-400 text-black border-yellow-400":"bg-muted/30 text-muted-foreground border border-border hover:bg-muted/50"}`,children:t.label},t.v)})})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3 items-end",children:[e.jsxs("div",{children:[e.jsx(n,{className:"text-xs",children:"Slot-Dauer (Minuten)"}),e.jsx(c,{type:"number",min:30,max:480,step:15,value:a.durationMinutes,onChange:t=>i(s=>({...s,durationMinutes:parseInt(t.target.value)||120})),className:"mt-1"})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(n,{className:"text-xs",children:"Region (optional)"}),e.jsx(c,{value:a.region,onChange:t=>i(s=>({...s,region:t.target.value})),placeholder:"z.B. NRW oder PLZ 30000-39999",className:"mt-1"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"ð¡ Bedenke Anfahrtszeiten â bei langer Strecke max. 1 Termin/Tag einplanen."}),e.jsxs(d,{onClick:v,disabled:p.isPending,className:"gap-1 bg-yellow-400 text-black hover:bg-yellow-500",children:[e.jsx(j,{className:"w-4 h-4"})," Slots generieren"]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"bg-muted/30 px-4 py-3 text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Zukünftige Slots (",u.length,")"]}),u.length===0?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Keine Slots im Vorausschau-Zeitraum (90 Tage)."}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Termin"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Dauer"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Region"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Aktion"})]})}),e.jsx("tbody",{children:u.map(t=>{const s=!!t.bookedBy;return e.jsxs("tr",{className:"border-b border-border last:border-0 hover:bg-muted/10",children:[e.jsx("td",{className:"px-4 py-3",children:g(t.startsAt)}),e.jsxs("td",{className:"px-4 py-3 text-muted-foreground",children:[t.durationMinutes," Min"]}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:t.regi
1on||"â"}),e.jsx("td",{className:"px-4 py-3",children:s?e.jsx("span",{className:"text-green-400 text-xs font-medium",children:"Gebucht"}):t.isBlocked?e.jsx("span",{className:"text-orange-400 text-xs font-medium",children:"Blockiert"}):e.jsx("span",{className:"text-blue-400 text-xs font-medium",children:"Frei"})}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx(d,{size:"sm",variant:"ghost",disabled:s,title:s?"Buchung erst stornieren":"Slot löschen",onClick:()=>{window.confirm(`Slot "${g(t.startsAt)}" löschen?`)&&N.mutate({id:t.id})},className:"text-xs h-7 text-red-400 hover:bg-red-500/10 disabled:opacity-30",children:e.jsx(T,{className:"w-3 h-3"})})})]},t.id)})})]})]}),e.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"bg-muted/30 px-4 py-3 text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Eingegangene Buchungen (",h.length,")"]}),h.length===0?e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"Noch keine Buchungen."}):e.jsx("div",{className:"divide-y divide-border",children:h.map(t=>{const s=t.booking,x=t.slot,b=`${s.street}${s.houseNumber?" "+s.houseNumber:""}, ${s.zipCode} ${s.city}`;return e.jsxs("div",{className:"p-4 hover:bg-muted/10",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold",children:s.studioName}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.firstName," ",s.lastName,s.studioMembers?` · ca. ${s.studioMembers} Mitglieder`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-2 text-xs text-muted-foreground",children:[e.jsxs("a",{href:`mailto:${s.email}`,className:"flex items-center gap-1 hover:text-foreground",children:[e.jsx(M,{className:"w-3 h-3"}),s.email]}),e.jsxs("a",{href:`tel:${s.phone}`,className:"flex items-center gap-1 hover:text-foreground",children:[e.jsx(B,{className:"w-3 h-3"}),s.phone]}),e.jsxs("a",{href:`https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(b)}`,target:"_blank",rel:"noopener",className:"flex items-center gap-1 text-blue-400 hover:text-blue-300",children:[e.jsx(C,{className:"w-3 h-3"}),b," ",e.jsx(A,{className:"w-3 h-3"})]})]}),s.notes&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2 bg-muted/30 rounded p-2 whitespace-pre-wrap",children:s.notes})]}),e.jsxs("div",{className:"text-right shrink-0 space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:x?g(Number(x.startsAt)):"â"}),e.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full ${F[s.status]??"bg-muted text-muted-foreground"}`,children:D[s.status]??s.status})]})]}),s.status!=="cancelled"&&s.status!=="completed"&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border",children:[e.jsxs(d,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",disabled:l.isPending,onClick:()=>l.mutate({bookingId:s.id,status:"completed"}),children:[e.jsx($,{className:"w-3 h-3"})," Erledigt"]}),e.jsxs(d,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1 text-orange-400",disabled:l.isPending,onClick:()=>l.mutate({bookingId:s.id,status:"no_show"}),children:[e.jsx(z,{className:"w-3 h-3"})," No-Show"]}),e.jsxs(d,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1 text-red-400",disabled:l.isPending,onClick:()=>{window.confirm("Buchung stornieren? Slot wird wieder freigegeben.")&&l.mutate({bookingId:s.id,status:"cancelled"})},children:[e.jsx(E,{className:"w-3 h-3"})," Stornieren"]})]})]},s.id)})})]})]})}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.