1import{j as e,r as i,d as Ut}from"./react-vendor-C4ZgFeHq.js";import{u as Pe,a as Et,c as Bt}from"./query-BgwNLuJi.js";import{c as Qt,am as He,G as p,an as P,E as ct,L as d,ao as Y,ap as k,aq as ee,ar as te,as as M,I as j,at as vt,aj as Le,a as f,a8 as Oe,a9 as Re,aa as Ge,ab as Ve,a7 as $t,a6 as Zt,C as Wt,b as Jt,i as Ue,a3 as yt,au as _t,al as Ie,j as Xt,l as Yt,v as kt,w as es,D as Nt,av as ts}from"./index-Ceacv5mq.js";import{T as ss,a as as,b as wt,c as St}from"./tabs-BUHuPk5x.js";import{l as me}from"./audit-BDO4qXS3.js";import{p as H}from"./parseISO-C40aaM3_.js";import{a as ns,f as Tt}from"./createdVia-BBjbCQSK.js";import{A as qe,s as rs,t as bt,f as is,v as ls,g as ds}from"./bookingPricing-TmKstKWP.js";import{T as zt}from"./triangle-alert-BvbBHhRF.js";import{l as lt}from"./bookingLabels-Wa40z2IZ.js";import{s as cs,e as us,a as ms,i as os}from"./startOfMonth-DyM8rjwf.js";import{U as hs}from"./upload-BP2tZvvC.js";import{E as Ct}from"./external-link-DDEkpUHb.js";import{E as xs}from"./eye-CcsMKmch.js";import{s as fs}from"./subMonths-C3ocaslY.js";import{F as ps}from"./file-text-BgLUNbJe.js";import"./radix-Bg-Cwxu9.js";import"./supabase-CLp0XeNR.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const js=Qt("Paperclip",[["path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48",key:"1u3ebp"}]]);function gs(n,t){const u=He(n.start),a=He(n.end);let h=+u>+a;const g=h?+u:+a,N=h?a:u;N.setHours(0,0,0,0);let w=1;const B=[];for(;+N<=g;)B.push(He(N)),N.setDate(N.getDate()+w),N.setHours(0,0,0,0);return h?B.reverse():B}function vs(n){return He(n).getDay()}async function oe(n){var t,u;try{const{data:a}=await p.auth.getUser(),h=((t=a==null?void 0:a.user)==null?void 0:t.email)??((u=a==null?void 0:a.user)==null?void 0:u.id)??null,{error:g}=await p.from("booking_events").insert({booking_id:n.bookingId,event_type:n.eventType,via:"manual",agent_name:null,actor:h,note:n.note??null});g&&console.error("booking event log failed",g.message)}catch(a){console.error("booking event log failed",a)}}const ys={create:"Angelegt",update:"Geändert",cancel:"Storniert"},_s=n=>!n||n==="agent"?null:n.startsWith("agent:")?n.slice(6):n;function Ns({bookingId:n}){const{data:t,isLoading:u}=Pe({queryKey:["admin","booking-events",n],queryFn:async()=>{const{data:a,error:h}=await p.from("booking_events").select("*").eq("booking_id",n).order("created_at",{ascending:!0});if(h)throw h;return a??[]}});return e.jsxs("div",{className:"border rounded-lg p-3 space-y-2 text-sm",children:[e.jsx("p",{className:"font-semibold text-muted-foreground",children:"Historie"}),u&&e.jsx("p",{className:"text-muted-foreground",children:"Lädtâ¦"}),!u&&(t??[]).length===0&&e.jsx("p",{className:"text-muted-foreground",children:"Keine Einträge vorhanden."}),e.jsx("ol",{className:"space-y-2",children:(t??[]).map(a=>{const h=_s(a.actor),g=a.via==="ki_agent"?`KI-Agentin ${a.agent_name||"Elena Event"}`:"manuell";return e.jsxs("li",{className:"border-l-2 border-muted pl-3",children:[e.jsxs("p",{className:"font-medium",children:[ys[a.event_type]??a.event_type," · ",e.jsx("span",{className:a.via==="ki_agent"?"text-primary":"text-muted-foreground",children:g})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[P(H(a.created_at),"dd.MM.yyyy HH:mm"),h?` · ausgelöst von ${h}`:""]}),a.note&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.note})]},a.id)})})]})}const ws=["fullday","halfday_morning","halfday_afternoon","evening","two_hour"],Z=n=>String(n).padStart(2,"0"),Ke=n=>{if(!n)return"";const t=new Date(n);return Number.isNaN(t.getTime())?"":`${t.getFullYear()}-${Z(t.getMonth()+1)}-${Z(t.getDate())}`},Mt=n=>{if(!n)return"";const t=new Date(n);return Number.isNaN(t.getTime())?"":`${Z(t.getHours())}:${Z(t.getMinutes())}`},Ss=n=>n.trim()===""?null:Number(n);function Ft({mode:n,booking:t,rooms:u,labels:a,allBookings:h,onCancel:g,onSaved:N}){var jt;const{toast:w}=ct(),[B,T]=i.useState(!1),L=i.useMemo(()=>Ke(new Date().toISOString()),[]),[S,se]=i.useState((t==null?void 0:t.room_id)??((jt=u[0])==null?void 0:jt.id)??""),[x,O]=i.useState((t==null?void 0:t.slot_type)||"fullday"),[F,A]=i.useState(Ke(t==null?void 0:t.requested_start)||L),[z,he]=i.useState(Ke(t==null?void 0:t.requested_end)||Ke(t==null?void 0:t.requested_start)||L),[_,Ne]=i.useState(Mt(t==null?void 0:t.requested_start)||qe.fullday.start),[I,W]=i.useState(Mt(t==null?void 0:t.requested_end)||qe.fullday.end),[xe,R]=i.useState((t==null?void 0:t.is_full_day)??!0),[fe,q]=i.useState((t==null?void 0:t.first_name)??""),[ae,we]=i.useState((t==null?void 0:t.last_name)??""),[U,Se]=i.useState((t==null?void 0:t.email)??""),[be,Ce]=i.useState((t==null?void 0:t.company)??""),[Me,Qe]=i.useState((t==null?void 0:t.phone)??""),[Fe,Ze]=i.useState((t==null?void 0:t.street)??""),[pe,We]=i.useState((t==null?void 0:t.postal_code)??""),[je,De]=i.useState((t==null?void 0:t.city)??""),[ge,Ee]=i.useState((t==null?void 0:t.country)??""),[ve,s]=i.useState((t==null?void 0:t.event_type)??""),[l,o]=i.useState((t==null?void 0:t.expected_guests)!=null?String(t.expected_guests):""),[m,b]=i.useState((t==null?void 0:t.setup_notes)??""),[C,ne]=i.useState((t==null?void 0:t.notes)??""),[J,At]=i.useState((t==null?void 0:t.admin_note)??""),[X,It]=i.useState((t==null?void 0:t.status)??"confirmed"),[Je,qt]=i.useState((t==null?void 0:t.label_id)??"none"),[ut,Kt]=i.useState((t==null?void 0:t.language)??"de"),[Be,Pt]=i.useState((t==null?void 0:t.membership_number_used)??""),[Q,Ht]=i.useState((t==null?void 0:t.voucher_code_used)??""),[D,Xe]=i.useState(null),[mt,ot]=i.useState(!1),[ht,ye]=i.useState(n==="edit"),[Ye,ke]=i.useState((t==null?void 0:t.base_price)!=null?String(t.base_price):"0"),[et,tt]=i.useState((t==null?void 0:t.member_discount_amount)!=null?String(t.member_discount_amount):"0"),[$e,Te]=i.useState((t==null?void 0:t.voucher_discount_amount)!=null?String(t.voucher_discount_amount):"0"),[st,ze]=i.useState((t==null?void 0:t.final_price)!=null?String(t.final_price):"0"),[at,Lt]=i.useState(!1),nt=i.useMemo(()=>{var E;const r=[...u];return t!=null&&t.room_id&&!r.some(y=>y.id===t.room_id)&&r.push({id:t.room_id,name_de:((E=t.rooms)==null?void 0:E.name_de)??"Inaktiver Raum"}),r},[u,t]),xt=i.useMemo(()=>nt.find(r=>r.id===S),[nt,S]),ft=i.useRef(!0);i.useEffect(()=>{if(ft.current){ft.current=!1;return}if(x==="two_hour"){const[E,y]=(_||"09:00").split(":").map(Number),c=new Date;c.setHours(E+2,y,0,0),W(`${Z(c.getHours())}:${Z(c.getMinutes())}`),R(!1);return}const r=qe[x];Ne(r.start),W(r.end),R(x==="fullday")},[x]);const pt=i.useRef(!0);i.useEffect(()=>{if(pt.current){pt.current=!1;return}if(x!=="two_hour")return;const[r,E]=(_||"09:00").split(":").map(Number);if(Number.isNaN(r))return;const y=new Date;y.setHours(r+2,E||0,0,0),W(`${Z(y.getHours())}:${Z(y.getMinutes())}`)},[_,x]),i.useEffect(()=>{F&&(!z||new Date(`${z}T00:00:00`)<new Date(`${F}T00:00:00`))&&he(F)},[F]);const G=i.useMemo(()=>rs({room:xt,slot:x,isMember:Be.trim().length>0}),[xt,x,Be]);i.useEffect(()=>{ht||(ke(String(G.basePrice)),tt(String(G.memberDiscount)),Te(String(G.voucherDiscount)),ze(String(G.finalPrice)))},[G,ht]);const re=bt(F,_),ie=bt(z||F,I),rt=i.useMemo(()=>!S||!re||!ie?[]:X!=="pending"&&X!=="confirmed"?[]:is(h??[],{roomId:S,start:re,end:ie,excludeId:(t==null?void 0:t.id)??null}
6),[h,S,re,ie,t==null?void 0:t.id,X]),it=Number(st)||0,Ot=()=>{ke(String(G.basePrice)),tt(String(G.memberDiscount)),Te(String(G.voucherDiscount)),ze(String(G.finalPrice))},Rt=async()=>{const r=Q.trim();if(!r){Xe(null);return}ot(!0);try{const{data:E,error:y}=await p.functions.invoke("booking-validate",{body:{action:"validate_voucher",code:r}});if(y)throw y;const c=E;if(Xe(c),!(c!=null&&c.valid)){w({title:"Gutschein nicht einlösbar",description:(c==null?void 0:c.reason)==="expired"?"Der Gutschein ist abgelaufen.":(c==null?void 0:c.reason)==="not_yet_valid"?"Der Gutschein ist noch nicht gültig.":(c==null?void 0:c.reason)==="fully_redeemed"?"Der Gutschein ist bereits vollständig eingelöst.":"Dieser Code existiert nicht oder ist inaktiv.",variant:"destructive"});return}const _e=Number(Ye)||0,le=Math.max(_e-(Number(et)||0),0),de=Number(c.discount_value)||0,gt=c.type==="percent"?_e*de/100:de,v=Math.max(Math.min(Math.round(gt*100)/100,le),0);ye(!0),Te(String(v)),ze(String(Math.max(Math.round((le-v)*100)/100,0))),w({title:"Gutschein gültig",description:c.type==="percent"?`${de} % Rabatt â ${v.toFixed(2)} ⬠werden abgezogen.`:c.type==="credit"?`Restguthaben ${de.toFixed(2)} ⬠â ${v.toFixed(2)} ⬠werden abgezogen.`:`Festbetrag ${de.toFixed(2)} ⬠â ${v.toFixed(2)} ⬠werden abgezogen.`})}catch(E){w({title:"Prüfung fehlgeschlagen",description:E.message,variant:"destructive"})}finally{ot(!1)}},Gt=()=>S?!fe.trim()||!ae.trim()?"Bitte Vor- und Nachnamen angeben.":/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(U.trim())?!re||!ie?"Bitte Datum und Uhrzeit vollständig angeben.":new Date(ie)<=new Date(re)?"Das Ende muss nach dem Beginn liegen.":Q.trim()&&(Number($e)||0)>0&&!(D!=null&&D.valid)?"Bitte den Gutscheincode zuerst über âPrüfenâ bestätigen â nur dann wird er vom Guthaben abgezogen.":null:"Bitte eine gültige E-Mail-Adresse angeben.":"Bitte einen Raum auswählen.",Vt=async()=>{var E;const r=Gt();if(r){w({title:"Eingabe unvollständig",description:r,variant:"destructive"});return}T(!0);try{const y={room_id:S,status:X,requested_start:re,requested_end:ie,is_full_day:xe,slot_type:x,first_name:fe.trim(),last_name:ae.trim(),email:U.trim(),company:be.trim()||null,phone:Me.trim()||null,street:Fe.trim()||null,postal_code:pe.trim()||null,city:je.trim()||null,country:ge.trim()||null,event_type:ve.trim()||null,expected_guests:Ss(l),setup_notes:m.trim()||null,notes:C.trim()||null,admin_note:J.trim()||null,language:ut,label_id:Je==="none"?null:Je,membership_number_used:Be.trim()||null,voucher_code_used:Q.trim()||null,base_price:Number(Ye)||0,member_discount_amount:Number(et)||0,voucher_discount_amount:Number($e)||0,final_price:Number(st)||0,currency:(t==null?void 0:t.currency)??"EUR"};let c=t==null?void 0:t.id,_e=!1;if(n==="create"){const{data:v}=await p.auth.getUser();y.created_via=ns("manual"),y.created_by=((E=v==null?void 0:v.user)==null?void 0:E.email)??"admin";let $=null;try{const{data:V,error:Ae}=await p.functions.invoke("lookup-user-by-email",{body:{email:U.trim()}});if(Ae)throw Ae;$=(V==null?void 0:V.userId)??null}catch(V){console.error("Kundenkonto-Zuordnung fehlgeschlagen:",V)}y.user_id=$,_e=!!$;const{data:K,error:ce}=await p.from("bookings").insert(y).select("id").single();if(ce)throw ce;c=K.id,me({action:"create",table:"bookings",recordId:c,diff:y}),await oe({bookingId:c,eventType:"update",note:`Direktbuchung im Backend angelegt (${X})${$?" â Kundenkonto zugeordnet":" â ohne Kundenkonto"}`})}else{const v={};Object.entries(y).forEach(([K,ce])=>{const V=t==null?void 0:t[K],Ae=typeof ce=="number"?Number(V??0):V===void 0?null:V;String(Ae??"")!==String(ce??"")&&(v[K]=ce)});const{error:$}=await p.from("bookings").update(y).eq("id",t.id);if($)throw $;me({action:"update",table:"bookings",recordId:t.id,diff:v}),await oe({bookingId:t.id,eventType:"update",note:Object.keys(v).length>0?`Buchung bearbeitet: ${Object.keys(v).join(", ")}`:"Buchung gespeichert (keine Ãnderung)"})}const le=Number($e)||0;if(c&&(D!=null&&D.valid)&&(D!=null&&D.id)&&le>0){const{data:v,error:$}=await p.functions.invoke("booking-validate",{body:{action:"admin_redeem_voucher",booking_id:c,voucher_code:Q.trim(),customer_email:U.trim(),reserved:le}}),K=v;
6$||K&&K.ok===!1?w({title:"Gutschein nicht verbucht",description:(K==null?void 0:K.reason)==="already_redeemed"?"Für diese Buchung ist bereits eine Einlösung gespeichert.":($==null?void 0:$.message)??"Der Rabatt steht in der Buchung, das Gutscheinguthaben wurde aber nicht reduziert.",variant:"destructive"}):await oe({bookingId:c,eventType:"update",note:`Gutschein ${Q.trim()} eingelöst: ${le.toFixed(2)} â¬`})}at&&c&&(p.functions.invoke("booking-status-changed",{body:{booking_id:c,new_status:X,admin_message:J||""}}).catch(v=>console.error("Notification error:",v)),p.functions.invoke("sync-booking-hubspot",{body:{booking_id:c}}).catch(v=>console.error("HubSpot sync error:",v)),n==="create"&&p.functions.invoke("send-booking-confirmation",{body:{booking_id:c}}).catch(v=>console.error("Confirmation email error:",v))),w({title:n==="create"?"Buchung angelegt":"Buchung gespeichert",description:(at?"Der Kunde wird per E-Mail informiert.":"Es wurde keine E-Mail versendet.")+(n==="create"?_e?" Die Buchung wurde dem bestehenden Kundenkonto zugeordnet.":" Kein Kundenkonto zu dieser E-Mail-Adresse gefunden â Buchung ohne Kontozuordnung gespeichert.":"")}),N()}catch(y){w({title:"Fehler",description:Tt(y,"de"),variant:"destructive"})}finally{T(!1)}};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground",children:"Raum & Zeitraum"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-room",children:"Raum"}),e.jsxs(Y,{value:S,onValueChange:se,children:[e.jsx(k,{id:"bf-room",children:e.jsx(ee,{placeholder:"Raum wählen"})}),e.jsx(te,{children:nt.map(r=>e.jsx(M,{value:r.id,children:r.name_de},r.id))})]})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-slot",children:"Zeitfenster"}),e.jsxs(Y,{value:x,onValueChange:r=>O(r),children:[e.jsx(k,{id:"bf-slot",children:e.jsx(ee,{})}),e.jsx(te,{children:ws.map(r=>e.jsx(M,{value:r,children:qe[r].label},r))})]})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-date",children:"Datum"}),e.jsx(j,{id:"bf-date",type:"date",value:F,onChange:r=>A(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-enddate",children:"Enddatum"}),e.jsx(j,{id:"bf-enddate",type:"date",value:z,onChange:r=>he(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-start",children:"Beginn"}),e.jsx(j,{id:"bf-start",type:"time",value:_,onChange:r=>Ne(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-end",children:"Ende"}),e.jsx(j,{id:"bf-end",type:"time",value:I,onChange:r=>W(r.target.value)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vt,{id:"bf-fullday",checked:xe,onCheckedChange:r=>R(r===!0)}),e.jsx(d,{htmlFor:"bf-fullday",className:"font-normal",children:"Ganztägig"})]}),rt.length>0&&e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm",children:[e.jsx(zt,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-destructive",children:"Zeitraum bereits belegt"}),e.jsx("ul",{className:"mt-1 space-y-0.5 text-muted-foreground",children:rt.slice(0,3).map(r=>e.jsxs("li",{children:[r.first_name," ",r.last_name," · ",new Date(r.requested_start).toLocaleString("de-DE")," â ",new Date(r.requested_end).toLocaleString("de-DE")]},r.id))}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Speichern ist erst möglich, wenn der Zeitraum frei ist oder die andere Buchung storniert wurde."})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground",children:"Kontaktdaten"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-first",children:"Vorname"}),e.jsx(j,{id:"bf-first",value:fe,onChange:r=>q(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-last",children:"Nachname"}),e.jsx(j,{id:"bf-last",value:ae,onChange:r=>we(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-email",children:"E-Mail"}),e.jsx(j,{id:"bf-email",type:"email",value:U,onChange:r=>Se(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-phone",children:"Telefon"}),e.jsx(j,{id:"bf-phone",value:Me,onChange:r=>Qe(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-company",children:"Firma"}),e.jsx(j,{id:"bf-company",value:be,onChange:r=>Ce(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-street",children:"StraÃe"}
6),e.jsx(j,{id:"bf-street",value:Fe,onChange:r=>Ze(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-zip",children:"PLZ"}),e.jsx(j,{id:"bf-zip",value:pe,onChange:r=>We(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-city",children:"Ort"}),e.jsx(j,{id:"bf-city",value:je,onChange:r=>De(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-country",children:"Land"}),e.jsx(j,{id:"bf-country",value:ge,onChange:r=>Ee(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-lang",children:"Sprache"}),e.jsxs(Y,{value:ut,onValueChange:Kt,children:[e.jsx(k,{id:"bf-lang",children:e.jsx(ee,{})}),e.jsxs(te,{children:[e.jsx(M,{value:"de",children:"Deutsch"}),e.jsx(M,{value:"en",children:"Englisch"})]})]})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground",children:"Veranstaltung"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-event",children:"Veranstaltungsart"}),e.jsx(j,{id:"bf-event",value:ve,onChange:r=>s(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-guests",children:"Personenzahl"}),e.jsx(j,{id:"bf-guests",type:"number",min:0,value:l,onChange:r=>o(r.target.value)})]})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-setup",children:"Aufbau-/Setup-Hinweise"}),e.jsx(Le,{id:"bf-setup",value:m,onChange:r=>
6b(r.target.value),className:"min-h-[60px]"})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-notes",children:"Anmerkungen des Kunden"}),e.jsx(Le,{id:"bf-notes",value:C,onChange:r=>ne(r.target.value),className:"min-h-[60px]"})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground",children:"Status & Markierung"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-status",children:"Status"}),e.jsxs(Y,{value:X,onValueChange:It,children:[e.jsx(k,{id:"bf-status",children:e.jsx(ee,{})}),e.jsxs(te,{children:[e.jsx(M,{value:"pending",children:"Angefragt"}),e.jsx(M,{value:"confirmed",children:"Bestätigt"}),e.jsx(M,{value:"cancelled",children:"Storniert"}),e.jsx(M,{value:"rejected",children:"Abgelehnt"})]})]})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-label",children:"Interne Markierung"}),e.jsxs(Y,{value:Je,onValueChange:qt,children:[e.jsx(k,{id:"bf-label",children:e.jsx(ee,{placeholder:"Keine Markierung"})}),e.jsxs(te,{children:[e.jsx(M,{value:"none",children:"Keine Markierung"}),a.filter(r=>r.active||r.id===(t==null?void 0:t.label_id)).map(r=>e.jsx(M,{value:r.id,children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:r.color}}),r.name]})},r.id))]})]})]})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-adminnote",children:"Interne Admin-Notiz"}),e.jsx(Le,{id:"bf-adminnote",value:J,onChange:r=>
6At(r.target.value),className:"min-h-[60px]"})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground",children:"Preise (netto)"}),e.jsx(f,{type:"button",variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:Ot,children:"Vorschlag übernehmen"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-member",children:"Mitgliedsnummer"}),e.jsx(j,{id:"bf-member",value:Be,onChange:r=>Pt(r.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-voucher",children:"Gutscheincode"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{id:"bf-voucher",value:Q,onChange:r=>{Ht(r.target.value),Xe(null)}}),e.jsx(f,{type:"button",variant:"outline",onClick:Rt,disabled:mt||!Q.trim(),children:mt?"Prüfeâ¦":"Prüfen"})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:D!=null&&D.valid?`Geprüft: ${D.label??Q} â wird beim Speichern vom Guthaben abgezogen.`:"Erst âPrüfenâ â danach wird der Rabatt automatisch berechnet und beim Speichern verbucht."})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-base",children:"Grundpreis"}),e.jsx(j,{id:"bf-base",type:"number",step:"0.01",value:Ye,onChange:r=>{ye(!0),ke(r.target.value)}})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-memberdisc",children:"Mitglieder-Rabatt"}),e.jsx(j,{id:"bf-memberdisc",type:"number",step:"0.01",value:et,onChange:r=>{ye(!0),tt(r.target.value)}})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-vouchdisc",children:"Gutschein-Rabatt"}),e.jsx(j,{id:"bf-vouchdisc",type:"number",step:"0.01",value:$e,onChange:r=>{ye(!0),Te(r.target.value)}})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-final",children:"Endpreis (netto)"}),e.jsx(j,{id:"bf-final",type:"number",step:"0.01",value:st,onChange:r=>{ye(!0),ze(r.target.value)}})]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Netto ",it.toFixed(2)," ⬠· zzgl. 19 % MwSt. ",ls(it).toFixed(2)," ⬠·"," ",e.jsxs("span",{className:"font-medium text-foreground",children:["Brutto ",ds(it).toFixed(2)," â¬"]})]})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-md border p-3",children:[e.jsx(vt,{id:"bf-notify",checked:at,onCheckedChange:r=>Lt(r===!0)}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"bf-notify",className:"font-normal",children:n==="create"?"Bestätigungsmail an Kunden senden":"Kunden über Ãnderung informieren"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"StandardmäÃig wird keine E-Mail versendet â die Buchung bleibt rein intern."})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(f,{variant:"outline",onClick:g,disabled:B,children:"Abbrechen"}),e.jsx(f,{onClick:Vt,disabled:B||rt.length>0,children:B?"Speichernâ¦":n==="create"?"Buchung anlegen":"Ãnderungen speichern"})]})]})}const dt="LÃSCHEN";function bs(n){return n.trim()===dt}function Cs({booking:n,onOpenChange:t,onDeleted:u}){var se;const[a,h]=i.useState(""),[g,N]=i.useState(!1),{toast:w}=ct(),B=Et(),T=()=>{h(""),N(!1),t(!1)},L=Bt({mutationFn:async()=>{var A;const x=n.id;if(g&&!n.is_imported)try{await p.functions.invoke("booking-status-changed",{body:{booking_id:x,new_status:"cancelled",admin_message:""}})}catch(z){console.error("Storno-Mail fehlgeschlagen",z)}const O=Array.isArray(n.attachments)?n.attachments:[];if(O.length>0){const{error:z}=await p.storage.from("booking-attachments").remove(O);z&&console.error("Anhänge löschen fehlgeschlagen",z.message)}const{error:F}=await p.from("bookings").delete().eq("id",x);if(F)throw new Error(Tt(F));me({action:"delete",table:"bookings",recordId:x,diff:{room_id:n.room_id,room:((A=n.rooms)==null?void 0:A.name_de)??null,requested_start:n.requested_start,requested_end:n.requested_end,status:n.status,first_name:n.first_name,last_name:n.last_name,email:n.email,final_price:n.final_price,currency:n.currency,notified_customer:g&&!n.is_imported}})},onSuccess:()=>{B.invalidateQueries({queryKey:["admin","bookings"]}),w({title:"Buchung gelöscht"}),T(),u==null||u()},onError:x=>w({title:"Fehler",description:x.message,variant:"destructive"})}),S=bs(a)&&!L.isPending;return e.jsx(Oe,{open:!!n,onOpenChange:x=>{x||T()},children:e.jsxs(Re,{className:"max-w-md",children:[e.jsx(Ge,{children:e.jsxs(Ve,{className:"flex items-center gap-2",children:[e.jsx(zt,{className:"h-5 w-5 text-destructive"})," Buchung endgültig löschen"]})}),n&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-md border p-3 text-sm space-y-1",children:[e.jsx("p",{className:"font-medium",children:((se=n.rooms)==null?void 0:se.name_de)??"Raum unbekannt"}),e.jsxs("p",{className:"text-muted-foreground",children:[P(H(n.requested_start),"dd.MM.yyyy HH:mm")," â"," ",P(H(n.requested_end),"HH:mm")]}),e.jsxs("p",{children:[n.first_name," ",n.last_name,n.company?` · ${n.company}`:""]}),n.final_price!=null&&e.jsxs("p",{className:"text-muted-foreground",children:[Number(n.final_price).toFixed(2)," ",n.currency||"EUR"," netto"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Die Buchung wird ",e.jsx("strong",{children:"unwiderruflich"})," gelöscht â inklusive Historie, E-Mail-Protokoll, Gutschein-Einlösung und Anhängen. Der Zeitraum wird sofort wieder frei. Wenn der Termin nur abgesagt werden soll, nutze stattdessen den Status âStorniertâ."]}),e.jsxs("div",{children:[e.jsxs(d,{children:["Zum Bestätigen ",e.jsx("strong",{children:dt})," eintippen"]}),e.jsx(j,{value:a,onChange:x=>h(x.target.value),placeholder:dt,autoComplete:"off"})]}),!n.is_imported&&e.jsxs("label",{className:"flex items-start gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:g,onChange:x=>N(x.target.checked),className:"mt-1"}),e.jsx("span",{children:"Kunden über die Stornierung informieren"})]}),e.jsxs("div",{className:"flex gap-2 justify-end pt-2 border-t",children:[e.jsx(f,{variant:"outline",onClick:T,disabled:L.isPending,children:"Abbrechen"}),e.jsxs(f,{variant:"destructive",disabled:!S,onClick:()=>L.mutate(),children:[e.jsx($t,{className:"h-4 w-4 mr-1"}),L.isPending?"Wird gelöschtâ¦":"Endgültig löschen"]})]})]})]})})}const ue={pending:{label:"Ausstehend",variant:"secondary"},confirmed:{label:"Bestätigt",variant:"default",className:"bg-green-600 hover:bg-green-700 text-white border-green-600"},rejected:{label:"Abgelehnt",variant:"destructive"},cancelled:{label:"Storniert",variant:"outline"}},Ms=n=>/\.(jpe?g|png|webp|gif)$/i.test(n),Dt=n=>!n||n==="agent"?null:n.startsWith("agent:")?n.slice(6):n,Fs=n=>{if((n==null?void 0:n.created_via)!=="ki_agent"){const a=Dt(n==null?void 0:n.created_by);return a?`${a} (manuell)`:"Manuell"}const t=n.agent_name||"Elena Event",u=Dt(n.created_by);return u?`KI-Agentin ${t} (ausgelöst von ${u})`:`KI-Agentin ${t}`},Ds=({booking:n})=>(n==null?void 0:n.created_via)==="ki_agent"?e.jsxs(Ue,{variant:"outline",className:"border-primary text-primary",children:["KI-Agentin: ",n.agent_name||"Elena Event"]}):null,Es=n=>(n.split("/").pop()||n).replace(/^\d{10,}_/,"");function Bs({path:n}){const[t,u]=i.useState(null),a=Es(n);return i.useEffect(()=>{let h=!1;return p.storage.from("booking-attachments").createSignedUrl(n,3600).then(({data:g,error:N})=>{h||u(N?null:(g==null?void 0:g.signedUrl)??null)}),()=>{h=!0}},[n]),e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-md bg-muted/50",children:[Ms(a)&&t?e.jsx("img",{width:48,height:48,src:t,alt:a,className:"h-12 w-12 object-cover rounded border"}):e.jsx(ps,{className:"h-8 w-8 text-muted-foreground shrink-0"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:a}),t?e.jsx("a",{href:kt(t,a),download:es(a,n),target:"_blank",rel:"noopener noreferrer",className:"shrink-0",children:e.jsx(f,{variant:"ghost",size:"icon",title:"Herunterladen / Ansehen",children:e.jsx(Nt,{className:"h-4 w-4"})})}):e.jsx(f,{variant:"ghost",size:"icon",disabled:!0,title:"Lädtâ¦",children:e.jsx(Nt,{className:"h-4 w-4 opacity-40"})})]})}function Js(){var je,De,ge,Ee,ve;const n=Ut(),{toast:t}=ct(),u=Et(),[a,h]=i.useState(null),[g,N]=i.useState(""),[w,B]=i.useState(new Date),[T,L]=i.useState("all"),[S,se]=i.useState("all"),[x,O]=i.useState(!1),[F,A]=i.useState(null),[z,he]=i.useState(null),{data:_,isLoading:Ne}=Pe({queryKey:["admin","bookings"],queryFn:async()=>{const l=[];for(let o=0;;o++){const{data:m,error:b}=await p.from("bookings").select("*, rooms!bookings_room_id_fkey(name_de)").order("created_at",{ascending:!1}).range(o*1e3,o*1e3+1e3-1);if(b)throw b;if(l.push(...m??[]),!m||m.length<1e3)break}return l}}),{data:I}=Pe({queryKey:["admin","booking_labels"],queryFn:async()=>{const{data:s,error:l}=await p.from("booking_labels").select("*").order("sort_order");if(l)throw l;return s??[]}}),{data:W}=Pe({queryKey:["admin","rooms","tariffs"],queryFn:async()=>{const{data:s,error:l}=await p.from("rooms").select("id,name_de,active,price_amount,halfday_morning_price,halfday_afternoon_price,evening_price,two_hour_price,two_hour_enabled,sort_order").eq("active",!0).order("sort_order");if(l)throw l;return s??[]}}),xe=()=>
6{O(!1),A(null),u.invalidateQueries({queryKey:["admin","bookings"]})},R=i.useMemo(()=>{const s={};return(I??[]).forEach(l=>{s[l.id]=l}),s},[I]),fe=async(s,l)=>{var b;u.setQueryData(["admin","bookings"],C=>C==null?void 0:C.map(ne=>ne.id===s.id?{...ne,label_id:l}:ne)),h(C=>C&&C.id===s.id?{...C,label_id:l}:C);const{error:o}=await p.from("bookings").update({label_id:l}).eq("id",s.id);if(o){t({title:"Fehler",description:o.message,variant:"destructive"}),u.invalidateQueries({queryKey:["admin","bookings"]});return}const m=l?((b=R[l])==null?void 0:b.name)??"Markierung":"keine";me({action:"update",table:"bookings",recordId:s.id,diff:{label_id:l}}),oe({bookingId:s.id,eventType:"update",note:`Interne Markierung: ${m}`}),t({title:"Markierung gespeichert"})},q=Bt({mutationFn:async({id:s,status:l,note:o})=>{const m={status:l};o!==void 0&&(m.admin_note=o);const{error:b}=await p.from("bookings").update(m).eq("id",s);if(b)throw b;me({action:"booking_status_change",table:"bookings",recordId:s,diff:{status:l,admin_note:o??null}}),await oe({bookingId:s,eventType:l==="cancelled"?"cancel":"update",note:`Status: ${l}${o?` · Notiz: ${o}`:""}`});const{data:C}=await p.from("bookings").select("is_imported").eq("id",s).maybeSingle();!((C==null?void 0:C.is_imported)===!0)&&(l==="confirmed"||l==="rejected"||l==="cancelled")&&(p.functions.invoke("booking-status-changed",{body:{booking_id:s,new_status:l,admin_message:o||""}}).catch(J=>console.error("Notification error:",J)),p.functions.invoke("sync-booking-hubspot",{body:{booking_id:s}}).catch(J=>console.error("HubSpot sync error:",J)))},onSuccess:()=>{u.invalidateQueries({queryKey:["admin","bookings"]}),h(null),t({title:"Status aktualisiert"})},onError:s=>t({title:"Fehler",description:s.message,variant:"destructive"})}),ae=s=>{q.mutate({id:s,status:"confirmed",note:g||void 0})},we=s=>{q.mutate({id:s,status:"rejected",note:g||void 0})},U=s=>{confirm("Buchung wirklich stornieren?")&&q.mutate({id:s,status:"cancelled",note:g||void 0})},Se=i.useMemo(()=>_?_.filter(s=>T!=="all"&&s.status!==T?!1:S==="none"?!s.label_id:!(S!=="all"&&s.label_id!==S)):[],[_,T,S]),be=i.useMemo(()=>{if(!_)return{all:0,pending:0,confirmed:0,rejected:0,cancelled:0};const s={all:_.length,pending:0,confirmed:0,rejected:0,cancelled:0};return _.forEach(l=>{s[l.status]!==void 0&&s[l.status]++}),s},[_]),Ce=cs(w),Me=us(w),Qe=gs({start:Ce,end:Me}),Fe=(vs(Ce)+6)%7,Ze=s=>_?_.filter(l=>{const o=H(l.requested_start),m=H(l.requested_end);return s>=new Date(o.toDateString())&&s<=new Date(m.toDateString())}):[],pe=s=>{h(s),N(s.admin_note||"")},We=["Mo","Di","Mi","Do","Fr","Sa","So"];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold font-heading",children:"Buchungen verwalten"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(f,{onClick:()=>O(!0),children:[e.jsx(Zt,{className:"mr-2 h-4 w-4"})," Buchung anlegen"]}),e.jsxs(f,{variant:"outline",onClick:()=>n("/admin/booking-import"),children:[e.jsx(hs,{className:"mr-2 h-4 w-4"})," Import"]})]})]}),e.jsxs(ss,{defaultValue:"calendar",children:[e.jsxs(as,{className:"mb-4",children:[e.jsx(wt,{value:"list",children:"Liste"}),e.jsx(wt,{value:"calendar",children:"Kalender"})]}),e.jsxs(St,{value:"list",children:[e.jsx("div",{className:"flex flex-wrap gap-2 mb-4",children:["all","pending","confirmed","rejected","cancelled"].map(s=>e.jsxs(f,{variant:T===s?"default":"outline",size:"sm",onClick:()=>L(s),children:[s==="all"?"Alle":ue[s].label," (",be[s],")"]},s))}),e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(d,{htmlFor:"label-filter",className:"text-sm text-muted-foreground",children:"Markierung"}),e.jsxs(Y,{value:S,onValueChange:se,children:[e.jsx(k,{id:"label-filter",className:"w-[240px]",children:e.jsx(ee,{placeholder:"Alle Markierungen"})}),e.jsxs(te,{children:[e.jsx(M,{value:"all",children:"Alle Markierungen"}),e.jsx(M,{value:"none",children:"Ohne Markierung"}),(I??[]).map(s=>e.jsx(M,{value:s.id,children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:s.color}}),s.name]})},s.id))]})]})]}),Ne?e.jsx("p",{className:"text-muted-foreground",children:"Ladenâ¦"}):e.jsxs("div",{className:"space-y-2",children:[Se.map(s=>{var o;const l=ue[s.status]??ue.pending;return e.jsx(Wt,{children:e.jsxs(Jt,{className:"p-4 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("p",{className:"font-semibold truncate",children:[s.first_name," ",s.last_name,s.company&&e.jsxs("span",{className:"text-muted-foreground font-normal",children:[" · ",s.company]})]}),e.jsx(Ue,{variant:l.variant,className:l.className,children:l.label}),s.label_id&&R[s.label_id]&&e.jsx(Ue,{variant:"outline",style:lt(R[s.label_id].color),children:R[s.label_id].name}),e.jsx(Ds,{booking:s})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[((o=s.rooms)==null?void 0:o.name_de)??"Raum"," · ",P(H(s.requested_start),"dd.MM.yyyy HH:mm")," â ",P(H(s.requested_end),"dd.MM.yyyy HH:mm"),s.asana_task_id&&e.jsxs("a",{href:`https://app.asana.com/0/0/${s.asana_task_id}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-0.5 ml-2 text-primary hover:underline",title:"In Asana öffnen",children:[e.jsx(Ct,{className:"h-3 w-3"})," Asana"]})]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx(f,{variant:"ghost",size:"icon",title:"Details",onClick:()=>pe(s),children:e.jsx(xs,{className:"h-4 w-4"})}),e.jsx(f,{variant:"ghost",size:"icon",title:"Bearbeiten",onClick:()=>A(s),children:e.jsx(yt,{className:"h-4 w-4"})}),s.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx(f,{variant:"ghost",size:"icon",title:"Bestätigen",onClick:()=>ae(s.id),children:e.jsx(_t,{className:"h-4 w-4 text-green-600"})}),e.jsx(f,{variant:"ghost",size:"icon",title:"Ablehnen",onClick:()=>we(s.id),children:e.jsx(Ie,{className:"h-4 w-4 text-destructive"})})]}),s.status==="confirmed"&&e.jsx(f,{variant:"ghost",size:"icon",title:"Stornieren",onClick:()=>U(s.id),children:e.jsx(Ie,{className:"h-4 w-4 text-destructive"})})]})]})},s.id)}),Se.length===0&&e.jsx("p",{className:"text-muted-foreground text-center py-8",children:"Keine Buchungen vorhanden."})]})]}),e.jsxs(St,{value:"calendar",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(f,{variant:"ghost",size:"icon",onClick:()=>B(s=>fs(s,1)),children:e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx("h2",{className:"text-lg font-semibold",children:P(w,"MMMM yyyy",{locale:ts})}),e.jsx(f,{variant:"ghost",size:"icon",onClick:()=>B(s=>ms(s,1)),children:e.jsx(Yt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-px bg-border rounded-lg overflow-hidden",children:[We.map(s=>e.jsx("div",{className:"bg-muted p-2 text-center text-xs font-medium text-muted-foreground",children:s},s)),Array.from({length:Fe}).map((s,l)=>e.jsx("div",{className:"bg-background p-2 min-h-[80px]"},`empty-${l}`)),Qe.map(s=>{const l=Ze(s),o=os(s,new Date);return e.jsxs("div",{className:`bg-background p-1 min-h-[80px] ${o?"ring-2 ring-primary ring-inset":""}`,children:[e.jsx("div",{className:"text-xs text-right mb-1",children:P(s,"d")}),e.jsx("div",{className:"space-y-0.5 max-h-[160px] overflow-y-auto",children:l.map(m=>{const b=m.label_id?R[m.label_id]:void 0;return e.jsxs("button",{title:b?`Markierung: ${b.name}`:void 0,className:`w-full text-left text-[10px] leading-tight px-1 py-0.5 rounded truncate cursor-pointer ${b?"":m.status==="confirmed"?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300":m.status==="pending"?"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300":m.status==="rejected"?"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300":"bg-muted text-muted-foreground"}`,style:b?lt(b.color):void 0,onClick:()=>pe(m),children:[m.created_via==="ki_agent"&&e.jsx("span",{title:"KI-Agentin: Elena Event",children:"KI · "}),m.company?m.company:`${m.first_name} ${m.last_name}`]},m.id)})})]},s.toISOString())})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Markierungen:"}),(I??[]).filter(s=>s.active).map(s=>e.jsx("span",{className:"px-2 py-0.5 rounded border",style:lt(s.color),children:s.name},s.id)),e.jsx(f,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:()=>n("/admin/booking-labels"),children:"Markierungen verwalten"})]})]})]}),e.jsx(Oe,{open:!!a,onOpenChange:s=>!s&&h(null),children:e.jsxs(Re,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[e.jsx(Ge,{children:e.jsx(Ve,{children:"Buchungsdetails"})}),a&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>{const s=a;h(null),A(s)},children:[e.jsx(yt,{className:"h-4 w-4 mr-1"})," Buchung bearbeiten"]}),e.jsxs(f,{variant:"destructive",size:"sm",onClick:()=>{const s=a;h(null),he(s)},children:[e.jsx($t,{className:"h-4 w-4 mr-1"})," Buchung löschen"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Name"}),e.jsxs("p",{className:"font-medium",children:[a.first_name," ",a.last_name]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Firma"}),e.jsx("p",{className:"font-medium",children:a.company||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"E-Mail"}),e.jsx("p",{className:"font-medium",children:a.email})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Telefon"}),e.jsx("p",{className:"font-medium",children:a.phone||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Raum"}),e.jsx("p",{className:"font-medium",children:((je=a.rooms)==null?void 0:je.name_de)??"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Status"}),e.jsx("p",{children:e.jsx(Ue,{variant:((De=ue[a.status])==null?void 0:De.variant)??"secondary",className:(ge=ue[a.status])==null?void 0:ge.className,children:((Ee=ue[a.status])==null?void 0:Ee.label)??a.status})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Von"}),e.jsx("p",{className:"font-medium",children:P(H(a.requested_start),"dd.MM.yyyy HH:mm")}
6)]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Bis"}),e.jsx("p",{className:"font-medium",children:P(H(a.requested_end),"dd.MM.yyyy HH:mm")})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Ganztägig"}),e.jsx("p",{className:"font-medium",children:a.is_full_day?"Ja":"Nein"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Angelegt durch"}),e.jsx("p",{className:"font-medium",children:Fs(a)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Gäste"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(j,{type:"number",min:0,className:"w-24 h-8",value:a.expected_guests??"",onChange:s=>{const l=s.target.value===""?null:Number(s.target.value);u.setQueryData(["admin","bookings"],o=>o==null?void 0:o.map(m=>m.id===a.id?{...m,expected_guests:l}:m))},onBlur:async s=>{const l=s.target.value===""?null:Number(s.target.value),{error:o}=await p.from("bookings").update({expected_guests:l}).eq("id",a.id);o?(t({title:"Fehler",description:o.message,variant:"destructive"}),u.invalidateQueries({queryKey:["admin","bookings"]})):(me({action:"update",table:"bookings",recordId:a.id,diff:{expected_guests:l}}),oe({bookingId:a.id,eventType:"update",note:`Gästezahl geändert auf ${l??"â"}`}),t({title:"Gästezahl aktualisiert"}))}})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Veranstaltungsart"}),e.jsx("p",{className:"font-medium",children:a.event_type||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Sprache"}),e.jsx("p",{className:"font-medium",children:(ve=a.language)==null?void 0:ve.toUpperCase()})]})]}),(a.base_price!=null||a.final_price!=null)&&e.jsxs("div",{className:"border rounded-lg p-3 space-y-1 text-sm",children:[e.jsx("p",{className:"font-semibold text-muted-foreground mb-2",children:"Preisinformationen"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Grundpreis"}),e.jsx("p",{className:"font-medium",children:a.base_price!=null?`${Number(a.base_price).toFixed(2)} ${a.currency||"EUR"}`:"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Zeitfenster"}),e.jsx("p",{className:"font-medium",children:a.slot_type||"â"})]}),(a.voucher_discount_amount>0||a.voucher_code_used)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Gutschein"}),e.jsxs("p",{className:"font-medium",children:[a.voucher_code_used||"â"," ",a.voucher_discount_amount>0?`(â${Number(a.voucher_discount_amount).toFixed(2)} ${a.currency||"EUR"})`:""]})]}),(a.member_discount_amount>0||a.membership_number_used)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Mitgliederrabatt"}),e.jsxs("p",{className:"font-medium",children:[a.membership_number_used||"â"," ",a.member_discount_amount>0?`(â${Number(a.member_discount_amount).toFixed(2)} ${a.currency||"EUR"})`:""]})]}),e.jsxs("div",{className:"col-span-2 border-t pt-2 mt-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Endpreis"}),e.jsx("p",{className:"font-semibold text-lg",children:a.final_price!=null?`${Number(a.final_price).toFixed(2)} ${a.currency||"EUR"}`:"â"})]})]})]}),a.attachments&&a.attachments.length>0&&e.jsxs("div",{className:"border rounded-lg p-3 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold text-muted-foreground",children:[e.jsx(js,{className:"h-4 w-4"}),"Anhänge (",a.attachments.length,")"]}),e.jsx("div",{className:"space-y-2",children:a.attachments.map((s,l)=>e.jsx(Bs,{path:s},`${s}-${l}`))})]}),a.notes&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Anmerkungen"}),e.jsx("p",{children:a.notes})]}),a.extras&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Extras"}),e.jsx("p",{children:a.extras})]}),a.setup_notes&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Setup-Hinweise"}),e.jsx("p",{children:a.setup_notes})]}),e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Adresse"}),e.jsx("p",{children:[a.street,a.postal_code,a.city,a.country].filter(
6Boolean).join(", ")||"â"})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"booking-label",children:"Interne Markierung"}),e.jsxs(Y,{value:a.label_id??"none",onValueChange:s=>fe(a,s==="none"?null:s),children:[e.jsx(k,{id:"booking-label",children:e.jsx(ee,{placeholder:"Keine Markierung"})}),e.jsxs(te,{children:[e.jsx(M,{value:"none",children:"Keine Markierung"}),(I??[]).filter(s=>s.active||s.id===a.label_id).map(s=>e.jsx(M,{value:s.id,children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:s.color}}),s.name]})},s.id))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Nur intern sichtbar â ändert weder Status noch Verfügbarkeit."})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Admin-Notiz"}),e.jsx(Le,{value:g,onChange:s=>N(s.target.value),placeholder:"Interne Notiz zur Buchungâ¦",className:"min-h-[60px]"})]}),a.status==="pending"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(f,{className:"bg-green-600 hover:bg-green-700 text-white",onClick:()=>ae(a.id),disabled:q.isPending,children:[e.jsx(_t,{className:"h-4 w-4 mr-1"})," Bestätigen"]}),e.jsxs(f,{variant:"destructive",onClick:()=>we(a.id),disabled:q.isPending,children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Ablehnen"]})]}),a.status==="confirmed"&&e.jsxs(f,{variant:"destructive",onClick:()=>U(a.id),disabled:q.isPending,children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," Stornieren"]}),a.status!=="pending"&&e.jsx(f,{variant:"outline",size:"sm",onClick:()=>q.mutate({id:a.id,status:a.status,note:g}),disabled:q.isPending,children:"Notiz speichern"}),a.asana_task_id&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Asana"}),e.jsx("p",{children:e.jsxs("a",{href:`https://app.asana.com/0/0/${a.asana_task_id}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline",children:[e.jsx(Ct,{className:"h-3 w-3"})," Aufgabe in Asana öffnen"]})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Erstellt: ",P(H(a.created_at),"dd.MM.yyyy HH:mm")]}),e.jsx(Ns,{bookingId:a.id})]})]})}),e.jsx(Oe,{open:x,onOpenChange:s=>!s&&O(!1),children:e.jsxs(Re,{className:"max-w-2xl max-h-[88vh] overflow-y-auto",children:[e.jsx(Ge,{children:e.jsx(Ve,{children:"Direktbuchung anlegen"})}),x&&e.jsx(Ft,{mode:"create",rooms:W??[],labels:I??[],allBookings:_??[],onCancel:()=>O(!1),onSaved:xe})]})}),e.jsx(Oe,{open:!!F,onOpenChange:s=>!s&&A(null),children:e.jsxs(Re,{className:"max-w-2xl max-h-[88vh] overflow-y-auto",children:[e.jsx(Ge,{children:e.jsx(Ve,{children:"Buchung bearbeiten"})}),F&&e.jsx(Ft,{mode:"edit",booking:F,rooms:W??[],labels:I??[],allBookings:_??[],onCancel:()=>A(null),onSaved:xe})]})}),e.jsx(Cs,{booking:z,onOpenChange:s=>{s||he(null)}})]})}export{Js 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.