1import{c as le,b as ve,q as he,a3 as je,r as d,j as e,B as q,s as v,K as be,M as Ne,af as we,ag as Ce,ah as ke,a9 as L}from"./index-DwmCyvIn.js";import{S as te,a as ae,b as oe,c as se,d as ne}from"./select-4GVnKBQv.js";import{D as pe,a as fe,c as _e,d as ge,f as ye,e as Se}from"./dialog-B1S6etBk.js";import{E as $}from"./EditableCell-BtI9TfGG.js";import{I as ee}from"./input-CmUnNnnD.js";import{L as D}from"./label-7L10LABd.js";import{T as De}from"./textarea-awHddNqV.js";import{C as Ae}from"./checkbox-Bcy8SSAA.js";import{u as Me,A as Pe}from"./useAvailability-BsASYTAe.js";import{a as de}from"./addDays-KM2RQqIm.js";import{d as ie}from"./differenceInDays-Oo8GD58e.js";import{f as T}from"./format-D--iGIR9.js";import{e as Fe}from"./calendarEvents-Dd1sb3-Q.js";import{C as Ee}from"./ClientTierBadge-BHttM6lg.js";import{u as Be}from"./useEmailLogs-BMdLCFxf.js";import{B as Le}from"./badge-DbnDKnYF.js";import{c as $e,d as qe,b as me}from"./bookingFinance-CzwMcJZY.js";import{P as Te}from"./plus-DxAflexx.js";import"./index-BdQq_4o_.js";import"./index-C-D7eFvJ.js";import"./index-CVx7nn7T.js";import"./popover-Dh3pQdP5.js";import"./startOfMonth-CqRI3ATb.js";import"./loader-circle-XjoJAR5T.js";import"./et-DIQHajBV.js";import"./isWithinInterval-CfEcPx4A.js";import"./star-FTLuhlWE.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 Ge=le("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Ue=le("ArrowUpDown",[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Oe=le("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Ve=le("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]),Ie=[{value:"pending",label:"Pending"},{value:"confirmed",label:"Confirmed"},{value:"delayed",label:"Delayed"},{value:"cancelled",label:"Cancelled"},{value:"completed",label:"Completed"}],Re=[{value:"et",label:"Eesti"},{value:"en",label:"English"},{value:"fi",label:"Suomi"}],ze=({open:y,onOpenChange:F})=>{const{toast:h}=ve(),{data:f}=he(),r=je(),{availability:G,loading:re,isDateAvailable:M,findFirstAvailableDate:ce}=Me((f==null?void 0:f.id)||null),[R,w]=d.useState(!1),[u,P]=d.useState(),[_,C]=d.useState(),[z,E]=d.useState("2"),[B,U]=d.useState(""),[O,k]=d.useState(""),[j,Q]=d.useState(""),[V,W]=d.useState(""),[I,A]=d.useState("manual"),[Y,H]=d.useState("pending"),[J,t]=d.useState("et"),[s,a]=d.useState(""),[n,i]=d.useState(!0),o=d.useMemo(()=>{if(!u)return null;let l=de(u,1);const x=365;for(let K=0;K<x;K++){if(!M(l))return l;l=de(l,1)}return null},[u,M]),m=()=>{P(void 0),C(void 0),E("2"),U(""),k(""),Q(""),W(""),A("manual"),H("confirmed"),t("et"),a(""),i(!0)},g=l=>{!u||u&&_?(P(l),C(void 0)):l>u?C(l):(P(l),C(void 0))},c=()=>{if(!u||!_)return!1;const l=Fe({start:u,end:de(_,-1)});for(const x of l)if(!M(x))return h({title:"Error",description:`Date ${T(x,"dd.MM.yyyy")} is not available`,variant:"destructive"}),!1;return!0},S=async l=>{if(l.preventDefault(),!(f!=null&&f.id)){h({title:"Error",description:"Property not found",variant:"destructive"});return}if(!u||!_||!B||!j||!V){h({title:"Error",description:"Please fill all required fields",variant:"destructive"});return}if(!c())return;w(!0);const x=T(u,"yyyy-MM-dd"),K=T(_,"yyyy-MM-dd");try{const{data:p,error:ue}=await v.from("bookings").insert({property_id:f.id,check_in_date:x,check_out_date:K,num_guests:parseInt(z)||2,guest_name:B.trim(),guest_email:j.trim().toLowerCase(),guest_phone:O.trim()||null,total_price:parseFloat(V),status:Y,source:I,notes:s.trim()||null}).select("id").single();if(ue)throw ue;if(p!=null&&p.id&&j)try{const{data:N}=await v.rpc("find_or_create_client",{_email:j.trim().toLowerCase(),_name:B.trim(),_phone:O.trim()||null});if(N){const{data:Z}=await v.rpc("generate_booking_code",{_client_id:N,_source:I});await v.from("bookings").update({client_id:N,booking_code:Z||null}).eq("id",p.id)}}catch(N){console.error("Client linking error (non-fatal):",N)}if(p!=null&&p.id&&!j.trim().toLowerCase().endsWith("@airbnb.invali
21d")&&v.functions.invoke("sync-google-contact",{body:{bookingId:p.id}}).catch(N=>console.error("[GOOGLE_CONTACT_SYNC] Manual booking auto-sync failed:",N)),n&&j&&(p!=null&&p.id))try{const N=I==="stripe"?"stripe":I==="invoice"?"invoice":"lhv",{error:Z}=await v.functions.invoke("send-booking-email",{body:{bookingId:p.id,guestEmail:j.trim().toLowerCase(),guestName:B.trim(),checkIn:x,checkOut:K,numGuests:parseInt(z)||2,totalPrice:parseFloat(V),paymentMethod:N,language:J}});Z?(console.error("Email sending error:",Z),h({title:"Warning",description:"Booking created, but email sending failed",variant:"destructive"})):h({title:"Confirmation email sent"})}catch(N){console.error("Email function error:",N)}r.invalidateQueries({queryKey:["bookings"]}),r.invalidateQueries({queryKey:["payments"]}),h({title:"Booking created"}),m(),F(!1)}catch(p){console.error("Create booking error:",p),h({title:"Error",description:p.message||"Booking creation failed",variant:"destructive"})}finally{w(!1)}},b=u&&_?ie(_,u):0,X=ce();return e.jsx(pe,{open:y,onOpenChange:F,children:e.jsxs(fe,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(_e,{children:e.jsx(ge,{children:"Add new booking"})}),e.jsxs("form",{onSubmit:S,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:"Dates *"}),e.jsx("div",{className:"border rounded-lg p-4 bg-muted/30",children:e.jsx(Pe,{availability:G,checkIn:u,checkOut:_,onDateSelect:g,isLoading:re,maxCheckoutDate:o,firstAvailableDate:X,minStay:(f==null?void 0:f.min_stay)||2,allowSameDayBooking:!0})}),u&&_&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:[T(u,"dd.MM.yyyy")," - ",T(_,"dd.MM.yyyy")," (",b," nights)"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{htmlFor:"numGuests",children:"Guests"}),e.jsxs(te,{value:z,onValueChange:E,children:[e.jsx(ae,{children:e.jsx(oe,{})}),e.jsx(se,{children:[1,2,3,4].map(l=>e.jsx(ne,{value:String(l),children:l},l))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{htmlFor:"guestName",children:"Name *"}),e.jsx(ee,{id:"guestName",value:B,onChange:l=>U(l.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{htmlFor:"guestPhone",children:"Phone"}),e.jsx(ee,{id:"guestPhone",type:"tel",value:O,onChange:l=>k(l.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{htmlFor:"guestEmail",children:"Email *"}),e.jsx(ee,{id:"guestEmail",type:"email",value:j,onChange:l=>Q(l.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{htmlFor:"totalPrice",children:"Amount (â¬) *"}),e.jsx(ee,{id:"totalPrice",type:"number",onFocus:l=>l.target.select(),step:"0.01",value:V,onChange:l=>W(l.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:"Status"}),e.jsxs(te,{value:Y,onValueChange:H,children:[e.jsx(ae,{children:e.jsx(oe,{})}),e.jsx(se,{children:Ie.map(l=>e.jsx(ne,{value:l.value,children:l.label},l.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:"Email language"}),e.jsxs(te,{value:J,onValueChange:t,children:[e.jsx(ae,{children:e.jsx(oe,{})}),e.jsx(se,{children:Re.map(l=>e.jsx(ne,{value:l.value,children:l.label},l.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{htmlFor:"notes",children:"Notes"}),e.jsx(De,{id:"notes",value:s,onChange:l=>a(l.target.value),rows:2})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ae,{id:"sendEmail",checked:n,onCheckedChange:l=>i(l===!0)}),e.jsx(D,{htmlFor:"sendEmail",className:"cursor-pointer",children:"Send confirmation email"})]}),e.jsxs(ye,{children:[e.jsx(q,{type:"button",variant:"outline",onClick:()=>F(!1),children:"Cancel"}),e.jsx(q,{type:"submit",disabled:R||!u||!_,children:R?"Saving...":"Save"})]})]})]})})},He={manual:"Manual",stripe:"Stripe",invoice:"Invoice",bank:"Bank",ical:"iCal",lhv:"LHV"},xe=[{value:"pending",label:"Pending"},{value:"confirmed",label:"Confirmed"},{value:"delayed",label:"Delayed"},{value:"cancelled",label:"Cancelled"},{value:"completed",label:"Completed"}],Ke=y=>{switch(y){case"confirmed":return"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200";
21case"pending":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200";case"delayed":return"bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200";case"cancelled":return"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200";case"completed":return"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200";default:return"bg-muted text-muted-foreground"}},Qe=y=>He[y||"manual"]||y||"Manual",We=(y,F)=>{const h=F?"0d":"1f";switch(y){case"booking_com":return{backgroundColor:`#003580${h}`};case"airbnb":return{backgroundColor:`#FF5A5F${h}`};default:return{backgroundColor:`#F6920A${h}`}}},Nt=()=>{const{data:y,isLoading:F}=be(),{data:h}=Ne(),{data:f}=Be(),{data:r}=he(),G=we(),re=Ce(),M=ke(),[ce,R]=d.useState(!1),[w,u]=d.useState(null),[P,_]=d.useState("upcoming"),[C,z]=d.useState("all"),[E,B]=d.useState("check_in_date"),[U,O]=d.useState("asc"),k=d.useMemo(()=>{if(!y)return[];const t=(r==null?void 0:r.bc_payment_due_days)??1,s={bc_commission_pct:r==null?void 0:r.bc_commission_pct,ab_commission_pct:r==null?void 0:r.ab_commission_pct,stripe_fee_pct:r==null?void 0:r.stripe_fee_pct,stripe_fee_fixed:r==null?void 0:r.stripe_fee_fixed,lhv_fee_pct:r==null?void 0:r.lhv_fee_pct,lhv_fee_fixed:r==null?void 0:r.lhv_fee_fixed};return y.map(a=>{const n=$e(a,h,t),i=qe(a,h,s,t),o=Number(a.total_price)||0,g=(a.source||"").toLowerCase()==="booking_com"?me(o,{source:"booking_com"},s):me(o,{payment_method:a.source},s);return{...a,paidAmount:n,feeAmount:i,netPaid:n-i,netTotal:o-g}})},[y,h,r]),j=d.useMemo(()=>{const t=new Date;t.setHours(0,0,0,0);let s=k;P==="upcoming"?s=s.filter(i=>new Date(i.check_out_date)>=t):P==="past"&&(s=s.filter(i=>new Date(i.check_out_date)<t)),C!=="all"&&(s=s.filter(i=>{const o=i.source||"manual";return C==="booking_com"?o==="booking_com":C==="airbnb"?o==="airbnb":o!=="booking_com"&&o!=="airbnb"}));const a=U==="asc"?1:-1,n=i=>{var o,m,g,c;switch(E){case"check_in_date":return new Date(i.check_in_date).getTime();case"client":return((o=i.clients)==null?void 0:o.client_code)||"";case"guest_name":return((m=i.guest_name)==null?void 0:m.toLowerCase())||"";case"guest_phone":return((g=i.guest_phone)==null?void 0:g.toLowerCase())||"";case"guest_email":return((c=i.guest_email)==null?void 0:c.toLowerCase())||"";case"total_price":return Number(i.total_price);case"paid":return i.paidAmount;case"remaining":return Number(i.total_price)-i.paidAmount;case"final_payment_due":return i.final_payment_due?new Date(i.final_payment_due).getTime():0;case"source":return i.source||"";case"status":return i.status;default:return 0}};return[...s].sort((i,o)=>{const m=n(i),g=n(o);return m<g?-1*a:m>g?1*a:0})},[k,P,C,E,U]),Q=t=>{E===t?O(s=>s==="asc"?"desc":"asc"):(B(t),O("asc"))},V=t=>{const s=t.paidAmount;if(s<=0)return 0;const a=Number(t.total_price),n=Math.max(0,s-a),i=ie(new Date(t.check_in_date),new Date),o=(r==null?void 0:r.cancellation_free_days)??21,m=(r==null?void 0:r.cancellation_cutoff_days)??4;return i>=o?s:i>=m?Math.max(0,s-a*.5):n},W=(t,s)=>{{const a=k.find(n=>n.id===t);if(!a)return;if(a.paidAmount>0){const n=V(a);u({bookingId:t,paidAmount:a.paidAmount,totalPrice:Number(a.total_price),refundAmount:n,checkIn:a.check_in_date});return}G.mutate({id:t,status:"cancelled",remaining_amount:0,refund_amount:0}),M.mutate({booking_id:t,field_name:"status",old_value:a.status,new_value:"cancelled",guest_name:a.guest_name});return}},I=async()=>{if(!w)return;const{bookingId:t,refundAmount:s}=w,a=k.find(i=>i.id===t);if(!a)return;const n=s>0?-s:0;if(G.mutate({id:t,status:"cancelled",remaining_amount:n,refund_amount:s}),M.mutate({booking_id:t,field_name:"status",old_value:a.status,new_value:"cancelled",guest_name:a.guest_name,extra_context:{refund_amount:s,paid_amount:a.paidAmount,total_price:Number(a.total_price)}}),a.guest_email)try{await v.functions.invoke("send-booking-email",{body:{bookingId:a.id,guestEmail:a.guest_email,guestName:a.guest_name,checkIn:a.check_in_date,checkOut:a.check_out_date,numGuests:a.num_guests,totalPrice:a.total_price,paymentMethod:"cancellation",language:a.language||"en",depositAmount:a.paidAmount,finalPaymentDue:a.final_payment_due,cancellationCutoffDays:(r==null?void 0:r.cancellation_cutoff_days)??4,refundAmount:s}})}catch(i){console.error("Failed to send cancellation email:",i)}u(null)},A=async(t,s,a)=>{const n=k.find(b=>b.id===t);if(!n)return;
21if(s==="status"&&a==="cancelled"){W(t);return}const i=String(n[s]??""),o={id:t};s==="total_price"||s==="num_guests"?o[s]=parseFloat(a)||0:o[s]=a||null;let m=n.remaining_amount??0;if(s==="total_price"){const b=Number(n.deposit_amount)||0,X=parseFloat(a)||0;m=Math.max(0,X-b),o.remaining_amount=m}G.mutate(o);const c=["total_price","status"].includes(s)?{before:{total_price:Number(n.total_price),deposit_amount:Number(n.deposit_amount)||0,remaining_amount:Number(n.remaining_amount)||0},after:{total_price:s==="total_price"?parseFloat(a)||0:Number(n.total_price),deposit_amount:Number(n.deposit_amount)||0,remaining_amount:s==="total_price"?m:Number(n.remaining_amount)||0}}:void 0;if(M.mutate({booking_id:t,field_name:s,old_value:i,new_value:a,guest_name:n.guest_name,extra_context:c}),i!==(a||"")&&((s==="notes"||s==="guest_phone")&&L.info("iCal feed updated â calendar apps refresh on next sync"),s==="guest_phone"||s==="guest_email")){const b=s==="guest_phone"?"phone":"email",l=s==="guest_email"&&(x=>/@(guest\.booking\.com|.*\.?booking\.com|relay\.airbnb\.com|airbnb\.com|expediapartnercentral\.com|expedia\.com)$/i.test(x||""))(i);if(n.client_id)try{l?await v.from("clients").update({[b]:a||null}).eq("id",n.client_id):await v.from("clients").update({[b]:a||null}).eq("id",n.client_id).eq(b,i),l&&a&&await v.from("bookings").update({guest_email:a}).eq("client_id",n.client_id).eq("guest_email",i).neq("id",t)}catch(x){console.error("Client propagation failed:",x)}try{const{error:x}=await v.functions.invoke("sync-google-contact",{body:{bookingId:t,oldPhone:s==="guest_phone"?i:void 0,oldEmail:s==="guest_email"?i:void 0}});x?(console.error("Google Contact auto-sync failed:",x),L.error("Google Contacts sync failed")):L.success("Google Contacts updated")}catch(x){console.error("Google Contact auto-sync error:",x)}}},Y=async t=>{if(k.find(a=>a.id===t))try{L.info("Syncing contact...");const{data:a,error:n}=await v.functions.invoke("sync-google-contact",{body:{bookingId:t}});n?(L.error("Contact sync failed"),console.error("Google Contact sync failed:",n)):(L.success("Contact synced!"),console.log("Google Contact synced for booking",t))}catch(a){L.error("Contact sync failed"),console.error("Google Contact sync failed:",a)}},H=t=>(f==null?void 0:f.some(s=>s.booking_id===t&&s.email_type==="google_contact_sync"&&s.status==="sent"))??!1,J=(t,s)=>{const a=parseFloat(s)||0,n=k.find(o=>o.id===t),i=(n==null?void 0:n.paidAmount)??0;if(re.mutate({bookingId:t,amount:a}),n){const o=Number(n.total_price)-a;G.mutate({id:t,deposit_amount:a,remaining_amount:o}),M.mutate({booking_id:t,field_name:"deposit_amount",old_value:String(i),new_value:String(a),guest_name:n.guest_name,extra_context:{before:{total_price:Number(n.total_price),deposit_amount:i,remaining_amount:Number(n.remaining_amount)||0},after:{total_price:Number(n.total_price),deposit_amount:a,remaining_amount:o}}})}};return F?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-8 bg-muted rounded w-48"}),e.jsx("div",{className:"h-64 bg-muted rounded"})]})}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"p-3 border-b bg-background flex-shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("div",{className:"flex items-center gap-1",children:["upcoming","past","all"].map(t=>e.jsx(q,{size:"sm",variant:P===t?"default":"outline",className:"h-7 text-xs px-2.5 capitalize",onClick:()=>_(t),children:t==="upcoming"?"Upcoming":t==="past"?"Past":"All"},t))}),e.jsx("div",{className:"h-5 w-px bg-border"}),e.jsx("div",{className:"flex items-center gap-1",children:[{key:"all",label:"All sources"},{key:"ssda",label:"SSDA"},{key:"booking_com",label:"Booking.com"},{key:"airbnb",label:"Airbnb"}].map(t=>e.jsx(q,{size:"sm",variant:C===t.key?"default":"outline",className:"h-7 text-xs px-2.5",onClick:()=>z(t.key),children:t.label},t.key))})]}),e.jsxs(q,{size:"sm",className:"h-8 text-sm",onClick:()=>R(!0),children:[e.jsx(Te,{className:"h-4 w-4 mr-1"}),"Add"]})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-background z-10 border-b",children:e.jsx("tr",{children:[{key:"check_in_date",label:"Check-in"},{key:"client",label:"Client"},{key:"guest_name",label:"Name"},{key:"guest_phone",label:"Phone"},{key:"guest_email",label:"Email"},{key:"total_price",label:"Amount"},{key:"paid",label:"Paid"},{key:"remaining",label:"Rem."},{key:"final_payment_due",label:"Due date"},{key:"notes",label:"Notes",sortable:!1},{key:"status",label:"Status"}].map(t=>e.jsx("th",{className:"whitespace-nowrap py-1.5 px-1.5 text-left text-xs font-medium text-muted-foreground",children:t.sortable===!1?t.label:e.jsxs("button",{type:"button",onClick:()=>Q(t.key),className:"inline-flex items-center gap-1 hover:text-foreground transition-colors",children:[t.label,E===t.key?U==="asc"?e.jsx(Oe,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}):e.jsx(Ue,{className:"h-3 w-3 opacity-30"})]})},t.key))})}),e.jsx("tbody",{children:j.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:11,className:"text-center text-muted-foreground py-6 text-sm",children:"No bookings"})}):j.map(t=>{var i,o,m,g;const s=ie(new Date(t.check_out_date),new Date(t.check_in_date)),a=`${T(new Date(t.check_in_date),"dd.MM.yy")} ${s}n/${t.num_guests}p`,n=new Date(t.check_out_date)<new Date(new Date().setHours(0,0,0,0));return e.jsxs("tr",{className:`border-b hover:bg-muted/50 ${n?"text-muted-foreground":""} ${t.status==="cancelled"?"line-through opacity-60":""}`,style:We(t.source,n),children:[e.jsx("td",{className:"whitespace-nowrap py-0 px-1 text-xs font-medium",children:a}),e.jsx("td",{className:"py-0 px-1",children:e.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:((i=t.clients)==null?void 0:i.client_code)||"-"})}),e.jsx("td",{className:"py-0 px-1",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx($,{value:t.guest_name,onSave:c=>A(t.id,"guest_name",c)}),e.jsx(Ee,{tier:(o=t.clients)==null?void 0:o.tier,tierChangedAt:(m=t.clients)==null?void 0:m.tier_changed_at})]})}),e.jsx("td",{className:"py-0 px-1",children:e.jsx($,{value:t.guest_phone,onSave:c=>A(t.id,"guest_phone",c),placeholder:"-"})}),e.jsx("td",{className:"py-0 px-1 max-w-[160px]",children:e.jsx($,{value:t.guest_email,onSave:c=>A(t.id,"guest_email",c),truncate:"max-w-[160px]"})}),e.jsxs("td",{className:"py-0 px-1",children:[e.jsx($,{value:t.total_price,onSave:c=>A(t.id,"total_price",c),type:"number",onFocus:c=>c.target.select(),currency:!0}),t.feeAmount>0&&t.netTotal!==Number(t.total_price)&&e.jsxs("div",{className:"text-[10px] text-muted-foreground leading-tight",children:["netto â¬",Math.round(t.netTotal)]})]}),e.jsxs("td",{className:"py-0 px-1",children:[e.jsx($,{value:t.paidAmount,onSave:c=>J(t.id,c),type:"number",onFocus:c=>c.target.select(),currency:!0}),t.feeAmount>0&&t.paidAmount>0&&e.jsxs("div",{className:"text-[10px] text-muted-foreground leading-tight",children:["netto â¬",Math.round(t.netPaid)]})]}),e.jsx("td",{className:"py-0 px-1",children:(()=>{const c=t.status==="cancelled",S=c?t.remaining_amount??0:Number(t.total_price)-t.paidAmount;if(c&&S<0)return e.jsxs("span",{className:"text-xs text-blue-600 font-medium",title:"Refund pending",children:["-â¬",Math.round(Math.abs(S))]});if(c&&S===0)return e.jsx("span",{className:"text-xs text-muted-foreground",children:"0â¬"});const b=S<0?"text-blue-600 font-medium":S>0?"text-orange-600 font-medium":"text-muted-foreground";return e.jsx("span",{className:`text-xs ${b}`,children:S!==0?`â¬${Math.round(Math.abs(S))}`:"0â¬"})})()}),e.jsx("td",{className:"py-0 px-1 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx($,{value:t.final_payment_due||"",onSave:c=>
21A(t.id,"final_payment_due",c),type:"date",placeholder:"-",displayValue:t.final_payment_due?e.jsx("span",{className:"text-xs font-medium",children:T(new Date(t.final_payment_due),"dd.MM.yy")}):void 0}),t.reminder_sent_at&&e.jsx("span",{className:"text-green-600 text-xs",children:"â"})]})}),e.jsx("td",{className:"py-0 px-1 max-w-[140px]",children:e.jsx($,{value:t.notes,onSave:c=>A(t.id,"notes",c),type:"textarea",placeholder:"-",truncate:"max-w-[140px]"})}),e.jsx("td",{className:"py-0 px-1",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(te,{value:t.status,onValueChange:c=>A(t.id,"status",c),children:[e.jsx(ae,{className:"w-24 h-6 text-xs border-0 p-0",children:e.jsx(Le,{className:Ke(t.status),title:Qe(t.source),children:((g=xe.find(c=>c.value===t.status))==null?void 0:g.label)||t.status})}),e.jsx(se,{children:xe.map(c=>e.jsx(ne,{value:c.value,children:c.label},c.value))})]}),t.paidAmount>=Number(t.total_price)&&Number(t.total_price)>0&&e.jsx("button",{onClick:()=>Y(t.id),title:H(t.id)?"Contact synced":"Sync contact",className:`p-0.5 rounded hover:bg-muted ${H(t.id)?"text-green-600":"text-muted-foreground"}`,children:e.jsx(Ve,{className:"h-3.5 w-3.5"})})]})})]},t.id)})})]})}),e.jsx(ze,{open:ce,onOpenChange:R}),e.jsx(pe,{open:!!w,onOpenChange:t=>!t&&u(null),children:e.jsxs(fe,{className:"max-w-sm",children:[e.jsxs(_e,{children:[e.jsx(ge,{children:"Cancel Booking"}),e.jsx(Se,{children:"The booking will be cancelled and the guest will be notified."})]}),w&&(()=>{const t=ie(new Date(w.checkIn),new Date),s=(r==null?void 0:r.cancellation_free_days)??21,a=(r==null?void 0:r.cancellation_cutoff_days)??4;let n="";return t>=s?n=`Free cancellation (${t} days before arrival ⥠${s})`:t>=a?n=`50% penalty (${t} days before arrival, cutoff ${a} days)`:n=`Non-refundable (${t} days before arrival < ${a} day cutoff)`,e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Paid:"}),e.jsxs("span",{className:"font-medium",children:["â¬",Math.round(w.paidAmount)]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Rule:"}),e.jsx("span",{className:"text-xs text-right max-w-[200px]",children:n})]}),e.jsxs("div",{className:"flex justify-between border-t pt-2",children:[e.jsx("span",{className:"text-muted-foreground font-medium",children:"Refund:"}),e.jsxs("span",{className:"font-bold text-blue-600",children:["â¬",Math.round(w.refundAmount)]})]})]})})(),e.jsxs(ye,{className:"gap-2",children:[e.jsx(q,{variant:"outline",size:"sm",onClick:()=>u(null),children:"Cancel"}),e.jsx(q,{variant:"destructive",size:"sm",onClick:I,children:"Confirm Cancellation"})]})]})})]})};export{Nt 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.