PageSourceSearch

https://skyprio.com/assets/AdminPhoneOrderEditorPage-BnP-T3LJ.js

js skyprio.com collected 2026-10-03 02:39:54 UTC 45,510 bytes, 1 lines download raw bytes

1import{k as ta,i as ia,J as na,r as f,a as _e,s as U,j as e,L as Te,B as y,$ as o,ak as Ee,al as Oe,am as Me,an as ze,ao as be,I as u,be as Ue,T as la,R as Ke,p as da,G as Ne,Q as oa,aY as ca,aV as K}from"./index-DwO-Othf.js";import{B as ue}from"./badge-D_Bz-WFU.js";import{A as ke,b as ma,a as Ae}from"./alert-ClcFXRwV.js";import{A as ua,I as Ve}from"./AirlineSearchInput-D79sMIVL.js";import{s as Qe}from"./timeUtils-DL2-HR8m.js";import{g as k,a as E,b as ga,c as He,f as Z,d as ge,p as Fe,r as xa}from"./flightLegPreview-DxJhj6Tb.js";import{A as ha}from"./arrow-left-dI89F-W2.js";import{T as Se}from"./triangle-alert-DBO2yYAS.js";import{C as pa}from"./calendar-clock-Crdsj0PD.js";import{T as xe}from"./trash-2-DjePVYeT.js";import{B as va}from"./briefcase-DcNqLkh4.js";import{P as ja}from"./package-plus-Ck1ItRA2.js";import{P as _a}from"./percent-ZFc1f3aF.js";import{R as ba}from"./receipt-text-Bg8-lkmF.js";import{H as Na}from"./history-DhWXMGXj.js";import{S as Ge}from"./save-Crwj5G4F.js";const fa={transportation:["transport","transfer","chauffeur","car service","limousine","ground"],flowers:["flower","bouquet","greeting gift","roses"],lounge:["lounge"],porter:["porter","baggage handler"]},ye=p=>(p||"").toLowerCase().trim(),fe=p=>{const m=ye(p);if(!m)return null;for(const[P,S]of Object.entries(fa))if(S.some(H=>m.includes(H)))return P;return null},ya=(p,m)=>m.find(P=>ye(P.category||"")===p||fe(P.name)===p),Pa=p=>{const m=[],{charges:P=[],reductions:S=[],addons:H=[],availableAddons:he=[],baseServiceTotal:le=0,additionalPassengerTotal:w=0,luggageTotal:ee=0,addonsTotal:C=0}=p,G=P.reduce((i,b)=>i+Math.abs(Number(b.amount)||0),0),$=S.reduce((i,b)=>i+Math.abs(Number(b.amount)||0),0),ae=le+w+ee+C+G,R=+(le+w).toFixed(2);P.forEach((i,b)=>{const A=(i.label||"").trim(),Pe=Number(i.amount)||0;A||m.push({level:"error",code:"charge_no_label",lineIndex:b,message:`Charge line ${b+1} needs a name shown to the customer.`}),Pe<=0&&m.push({level:"error",code:"charge_no_amount",lineIndex:b,message:`“${A||`Line ${b+1}`}” needs an amount greater than 0.`});const N=fe(A);N&&(H.some(T=>fe(T.name)===N||ye(T.category||"")===N)?m.push({level:"error",code:"duplicate_service",lineIndex:b,message:`“${A}” duplicates the ${N} add-on already on this order. Edit the add-on price instead.`}):ya(N,he)&&m.push({level:"warning",code:"should_map_to_addon",lineIndex:b,message:`This airport has a catalogue “${N}” service — add it under Extra services so the address and category appear on the order, receipt and ops notification.`}),N==="transportation"&&!(i.note||"").trim()&&m.push({level:"warning",code:"transport_missing_address",lineIndex:b,message:"Transportation lines should include the pickup / drop-off address in the detail field."}))});const de=new Map;return P.forEach((i,b)=>{const A=ye(i.label);A&&(de.has(A)?m.push({level:"warning",code:"duplicate_label",lineIndex:b,message:`“${i.label}” appears twice — merge the lines to avoid double billing.`}):de.set(A,b))}),S.forEach((i,b)=>{const A=Number(i.amount)||0;(i.label||"").trim()||m.push({level:"error",code:"reduction_no_label",lineIndex:b,message:`Reduction line ${b+1} needs a name shown to the customer.`}),A<=0&&m.push({level:"error",code:"reduction_no_amount",lineIndex:b,message:`Reduction “${i.label||b+1}” needs an amount greater than 0.`}),fe(i.label)&&A>0&&m.push({level:"warning",code:"service_as_reduction",lineIndex:b,message:`“${i.label}” looks like a service, not a discount. Remove the add-on instead of discounting it.`})}),$>ae?m.push({level:"error",code:"reduction_exceeds_total",message:`Reductions (${$.toFixed(2)}) exceed the order value (${ae.toFixed(2)}).`}):R>0&&$>+(ae-R).toFixed(2)&&m.push({level:"warning",code:"reduction_hits_base_service",message:`Reductions eat into the required base service (${R.toFixed(2)}). Confirm this is an approved discount.`}),H.forEach(i=>{(Number(i.quantity)||0)<=0&&m.push({level:"error",code:"addon_qty",message:`“${i.name}” must have a quantity of at least 1.`}),(Number(i.price)||0)<0&&m.push({level:"error",code:"addon_price",message:`“${i.name}” cannot have a negative price.`})}),le<=0&&m.push({level:"error",code:"no_base_service",message:"Base service price cannot be zero — airport services are billed on top of the base service, never instead of it."}),m},Ie=4,V=(p="",m=0)=>({id:`${Date.now()}-${Math.random().toString(36).slice(2,7)}`,label:p,amount:m,note:""}),ne=(p,m="USD")=>`${m} ${Number(p||0).toFixed(2)}`,Q=({icon:p,title:m,description:P,children:S})=>e.jsxs("section",{className:"rounded-2xl border bg-card shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"flex items-start gap-3 border-b bg-muted/30 px-4 py-3",children:[e.jsx("div",{className:"mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-primary text-primary-foreground",children:e.jsx(p,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm font-semibold leading-tight",children:m}),P&&e.jsx("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:P})]})]}),e.jsx("div",{className:"p-4",children:S})]}),O=({label:p,value:m,currency:P="USD"})=>e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsx("span",{children:p}),e.jsxs("span",{className:m<0?"text-emerald-600":"",children:[m<0?"-":"",P," ",Math.abs(m).toFixed(2)]})]});function Ma(){const{id:p}=ta(),m=ia(),P=na(),[S,H]=f.useState(!1),[he,le]=f.useState(""),[w,ee]=f.useState([]),[C,G]=f.useState([]),[$,ae]=f.useState(0),[R,de]=f.useState(0),[i,b]=f.useState(null),[A,Pe]=f.useState(!1),[N,q]=f.useState([]),[T,M]=f.useState([]),[g,z]=f.useState({serviceType:"arrival",serviceDate:"",serviceTime:"",isTimeConfirmed:!0,specialRequests:"",airportId:"",airportIATA:"",airportName:""}),[I,oe]=f.useState([]),[c,Ce]=f.useState({basePrice:0,additionalPassengerFee:0,includedPasse
1ngers:1,usePricePerPax:!1,pricePerPax:0,pricePerBag:0,freeAllowancePerAdult:2,processingFeePercentage:Ie,discount:0,discountLabel:"Discount",extraCharge:0,extraChargeLabel:"Additional charge",totalOverride:""}),L=(a,r)=>Ce(s=>({...s,[a]:r})),{data:h,isLoading:Ye}=_e({queryKey:["admin-order-editor",p],queryFn:async()=>{const{data:a,error:r}=await U.from("admin_orders").select("*").eq("id",p).maybeSingle();if(r)throw r;return a},enabled:!!p}),l=(h==null?void 0:h.booking_data)||{},Je=f.useMemo(()=>{if(!(h!=null&&h.payment_session_id))return!1;const a=new Date(h.payment_started_at||h.updated_at).getTime();return Date.now()-a<10*60*1e3},[h]),se=g.airportId||(l==null?void 0:l.airportId)||"",{data:$e=[]}=_e({queryKey:["admin-order-editor-airports"],queryFn:async()=>{const{data:a}=await U.from("airports").select("id, iata_code, airport_name, city, country").eq("is_active",!0).order("airport_name");return a||[]}});f.useEffect(()=>{se&&(async()=>{const{data:a}=await U.from("airports").select("base_price, price_per_pax, use_price_per_pax, additional_passenger_fee, extra_bag_price, currency, included_passengers").eq("id",se).maybeSingle();a&&b(a)})()},[se]),f.useEffect(()=>{var n,v,j,D,W,X;if(!h||A)return;ee(l.passengers?[...l.passengers]:[]),G(l.addons?[...l.addons]:[]),ae(((n=l.luggage)==null?void 0:n.extraBags)||0),de(Number(h.admin_fee)||0),z({serviceType:String(l.serviceType||"arrival").toLowerCase(),serviceDate:k(l.serviceDate),serviceTime:E(l.serviceTime)||String(l.serviceTime||"").slice(0,5),isTimeConfirmed:l.isTimeConfirmed!==!1,specialRequests:String(l.specialRequests||""),airportId:String(l.airportId||""),airportIATA:String(l.airportIATA||""),airportName:String(l.airportName||"")}),oe((l.flights||[]).map((x,B)=>({...x,_key:`${B}-${Math.random().toString(36).slice(2,7)}`,flight_date:k(x.flight_date)||k(x.departure_time),arrival_date:k(x.arrival_date)||k(x.arrival_time),departure_time:E(x.departure_time),arrival_time:E(x.arrival_time),sequence_order:x.sequence_order??B+1})));const a=l.pricingOverrides||{};Ce({basePrice:Number(a.basePrice??(i==null?void 0:i.base_price)??((v=l.priceBreakdown)==null?void 0:v.baseServiceTotal)??0),additionalPassengerFee:Number(a.additionalPassengerFee??(i==null?void 0:i.additional_passenger_fee)??50),includedPassengers:Math.max(1,Number(a.includedPassengers??(i==null?void 0:i.included_passengers)??1)),usePricePerPax:!!(a.usePricePerPax??(i==null?void 0:i.use_price_per_pax)??!1),pricePerPax:Number(a.pricePerPax??(i==null?void 0:i.price_per_pax)??0),pricePerBag:Number(a.pricePerBag??(i==null?void 0:i.extra_bag_price)??((j=l.luggage)==null?void 0:j.pricePerBag)??15),freeAllowancePerAdult:Number(a.freeAllowancePerAdult??2),processingFeePercentage:Number(a.processingFeePercentage??((D=l.priceBreakdown)==null?void 0:D.processingFeePercentage)??Ie),discount:Number(a.discount??0),discountLabel:String(a.discountLabel??"Discount"),extraCharge:Number(a.extraCharge??0),extraChargeLabel:String(a.extraChargeLabel??"Additional charge"),totalOverride:a.totalOverride!=null?String(a.totalOverride):""});const r=a.charges||((W=l.priceBreakdown)==null?void 0:W.customCharges)||[],s=a.reductions||((X=l.priceBreakdown)==null?void 0:X.customReductions)||[];if(r.length||s.length)q(r.map(x=>({...V(),...x,amount:Number(x.amount)||0}))),M(s.map(x=>({...V(),...x,amount:Number(x.amount)||0})));else{const x=Number(a.extraCharge??0),B=Number(a.discount??0);q(x?[V(String(a.extraChargeLabel||"Additional charge"),x)]:[]),M(B?[V(String(a.discountLabel||"Discount"),B)]:[])}(i||l.pricingOverrides)&&Pe(!0)},[h,i]);const{data:ce=[]}=_e({queryKey:["admin-order-editor-addons",se],queryFn:async()=>{const{data:a}=await U.from("add_ons").select("id, name, price, category").eq("airport_id",se).eq("is_active",!0).order("name");return a||[]},enabled:!!se}),{data:we=[]}=_e({queryKey:["admin-order-audit",p],queryFn:async()=>{const{data:a}=await U.from("admin_order_audit_log").select("*").eq("admin_order_id",p).order("created_at",{ascending:!1});return a||[]},enabled:!!p}),t=f.useMemo(()=>{var Le;const a=w.filter(_=>(_.passenger_type||"adult")!=="child").length||1,r=a*(Number(c.freeAllowancePerAdult)||0),s=r+$,n=Number(c.pricePerBag)||0,v=$*n;let j=0,D=0;if(c.usePricePerPax)j=(Number(c.pricePerPax)||0)*a;else{j=Number(c.basePrice)||0;
1const _=Math.max(1,Number(c.includedPassengers)||1);D=Math.max(0,a-_)*(Number(c.additionalPassengerFee)||0)}const W=C.reduce((_,ie)=>_+(Number(ie.price)||0)*(Number(ie.quantity)||0),0),X=N.filter(_=>(_.label||"").trim()!==""||Number(_.amount)).map(_=>({..._,label:(_.label||"Additional charge").trim(),amount:+(Number(_.amount)||0).toFixed(2)})),x=T.filter(_=>(_.label||"").trim()!==""||Number(_.amount)).map(_=>({..._,label:(_.label||"Discount").trim(),amount:Math.abs(+(Number(_.amount)||0).toFixed(2))})),B=+X.reduce((_,ie)=>_+ie.amount,0).toFixed(2),je=+x.reduce((_,ie)=>_+ie.amount,0).toFixed(2),re=Math.max(0,+(j+D+v+W+B-je).toFixed(2)),d=Number(c.processingFeePercentage)||0,te=+(re*(d/100)).toFixed(2),ra=+(re+te).toFixed(2);return{baseServiceTotal:j,additionalPassengerTotal:D,luggageTotal:v,addonsTotal:W,discount:je,extraCharge:B,cleanCharges:X,cleanReductions:x,subtotal:re,processingFee:te,processingFeePercentage:d,total:ra,currency:(i==null?void 0:i.currency)||((Le=l==null?void 0:l.priceBreakdown)==null?void 0:Le.currency)||"USD",totalBags:s,freeAllowance:r,pricePerBag:n,paidPassengerCount:a}},[i,w,C,$,l,c,N,T]),Be=f.useMemo(()=>Pa({charges:N,reductions:T,addons:C,availableAddons:ce||[],baseServiceTotal:t.baseServiceTotal,additionalPassengerTotal:t.additionalPassengerTotal,luggageTotal:t.luggageTotal,addonsTotal:t.addonsTotal,currency:t.currency}),[N,T,C,ce,t]),pe=Be.filter(a=>a.level==="error"),Re=Be.filter(a=>a.level==="warning"),ve=String(c.totalOverride).trim()!==""&&!isNaN(Number(c.totalOverride)),qe=+(t.total+(Number(R)||0)).toFixed(2),Y=ve?+Number(c.totalOverride).toFixed(2):qe,We=()=>ee([...w,{first_name:"",last_name:"",passenger_type:"adult",is_primary:!1}]),Xe=a=>{var r;if((r=w[a])!=null&&r.is_primary||a===0){K.error("Cannot remove primary passenger");return}ee(w.filter((s,n)=>n!==a))},me=(a,r,s)=>{const n=[...w];n[a]={...n[a],[r]:s},ee(n)},Ze=a=>{const r=ce.find(s=>s.id===a);if(r){if(C.some(s=>s.id===a)){K.info("Add-on already in order — increase quantity instead");return}G([...C,{id:r.id,name:r.name,price:Number(r.price),quantity:1}])}},F=(a,r)=>oe(s=>s.map(n=>n._key===a?{...n,...r}:n)),ea=()=>oe(a=>[...a,{_key:`${Date.now()}-${Math.random().toString(36).slice(2,7)}`,flight_number:"",flight_date:g.serviceDate||"",arrival_date:"",departure_time:"",arrival_time:"",airline_code:"",airline_name:"",airline_logo_url:null,origin_airport_code:"",origin_airport_name:"",destination_airport_code:"",destination_airport_name:"",terminal:"",gate:"",is_service_leg:a.length===0,sequence_order:a.length+1}]),aa=a=>oe(r=>r.map(s=>({...s,is_service_leg:s._key===a}))),J=f.useMemo(()=>I.find(a=>a.is_service_leg)||I[0]||null,[I]),sa=()=>{if(!J)return;const a=g.serviceType!=="departure",r=a?k(J.arrival_date)||k(J.flight_date):k(J.flight_date),s=a?E(J.arrival_time):E(J.departure_time);if(!r&&!s){K.info("Add the leg date and time first");return}z(n=>({...n,serviceDate:r||n.serviceDate,serviceTime:s||n.serviceTime})),K.success("Service date & time taken from the service leg")},De=async()=>{var a,r,s,n;if(h){if(w.some(v=>{var j,D;return!((j=v.first_name)!=null&&j.trim())||!((D=v.last_name)!=null&&D.trim())})){K.error("All passengers need a first and last name");return}if(pe.length>0){K.error(pe[0].message);return}H(!0);try{const v=w.map((d,te)=>({...d,is_primary:te===0})),j=v[0],W=Qe(I).map((d,te)=>({flight_number:(d.flight_number||"").trim().toUpperCase()||null,flight_date:k(d.flight_date)||null,arrival_date:k(d.arrival_date)||null,flight_type:d.flight_type||(g.serviceType==="departure"?"departure":"arrival"),airline_code:(d.airline_code||"").trim().toUpperCase()||null,airline_name:d.airline_name||null,airline_logo_url:d.airline_code?He(d.airline_code):d.airline_logo_url||null,origin_airport_code:(d.origin_airport_code||"").trim().toUpperCase()||null,origin_airport_name:d.origin_airport_name||null,destination_airport_code:(d.destination_airport_code||"").trim().toUpperCase()||null,destination_airport_name:d.destination_airport_name||null,departure_time:E(d.departure_time)||null,departure_timezone:d.departure_timezone||null,arrival_time:E(d.arrival_time)||null,arrival_timezone:d.arrival_timezone||null,duration_minutes:xa(d),duration_manual:!!d.duration_manual&&Number(d.duration_minutes)>0,duration_hidden:!!d.duration_hidden,terminal:(d.terminal||"").trim()||null,gate:(d.gate||"").trim()||null,sequence_order:te+1,is_service_leg:!!d.is_service_leg}
1)),X={...l,serviceType:g.serviceType,serviceDate:g.serviceDate||null,serviceTime:g.serviceTime||null,isTimeConfirmed:g.isTimeConfirmed,specialRequests:g.specialRequests||null,airportId:g.airportId||l.airportId||null,airportIATA:g.airportIATA||l.airportIATA||null,airportName:g.airportName||l.airportName||null,flights:W,passengers:v,addons:C,luggage:{totalBags:t.totalBags,freeAllowance:t.freeAllowance,extraBags:$,pricePerBag:t.pricePerBag,luggageTotal:t.luggageTotal},priceBreakdown:{...l.priceBreakdown||{},baseServiceTotal:t.baseServiceTotal,usePricePerPax:c.usePricePerPax,includedPassengers:Math.max(1,Number(c.includedPassengers)||1),additionalPassengerTotal:t.additionalPassengerTotal,additionalPassengerFee:Number(c.additionalPassengerFee)||0,luggageTotal:t.luggageTotal,addonsTotal:t.addonsTotal,customCharges:t.cleanCharges,customReductions:t.cleanReductions,discount:t.discount,discountAmount:t.discount,discountLabel:t.cleanReductions.length===1?t.cleanReductions[0].label:t.cleanReductions.length>1?"Discounts":"Discount",extraCharge:t.extraCharge,extraCh
1argeLabel:t.cleanCharges.length===1?t.cleanCharges[0].label:t.cleanCharges.length>1?"Additional charges":"Additional charge",subtotal:t.subtotal,processingFee:t.processingFee,processingFeePercentage:t.processingFeePercentage,total:t.total,totalOverride:ve?Number(c.totalOverride):null,currency:t.currency},pricingOverrides:{basePrice:Number(c.basePrice)||0,additionalPassengerFee:Number(c.additionalPassengerFee)||0,includedPassengers:Math.max(1,Number(c.includedPassengers)||1),usePricePerPax:c.usePricePerPax,pricePerPax:Number(c.pricePerPax)||0,pricePerBag:Number(c.pricePerBag)||0,freeAllowancePerAdult:Number(c.freeAllowancePerAdult)||0,processingFeePercentage:Number(c.processingFeePercentage)||0,charges:t.cleanCharges,reductions:t.cleanReductions,discount:t.discount,extraCharge:t.extraCharge,totalOverride:ve?Number(c.totalOverride):null}},{data:x}=await U.auth.getUser(),B=((a=x==null?void 0:x.user)==null?void 0:a.id)||null,je=((r=x==null?void 0:x.user)==null?void 0:r.email)||null,{error:re}=await U.from("admin_orders").update({booking_data:X,original_total:t.total,final_total:Y,admin_fee:Number(R)||0,customer_name:`${(j==null?void 0:j.first_name)||""} ${(j==null?void 0:j.last_name)||""}`.trim()||h.customer_name,customer_email:(j==null?void 0:j.email)||h.customer_email,customer_phone:(j==null?void 0:j.phone)||h.customer_phone,payment_session_id:null,last_edited_at:new Date().toISOString(),last_edited_by:B}).eq("id",h.id);if(re)throw re;await U.from("admin_order_audit_log").insert({admin_order_id:h.id,changed_by:B,changed_by_email:je,change_type:"edit",changes:{before:{passengers:((s=l.passengers)==null?void 0:s.length)||0,extraBags:((n=l.luggage)==null?void 0:n.extraBags)||0,addons:(l.addons||[]).map(d=>`${d.name}×${d.quantity}`),adminFee:Number(h.admin_fee)||0,finalTotal:Number(h.final_total)||0,serviceType:l.serviceType||null,serviceDate:l.serviceDate||null,serviceTime:l.serviceTime||null,airport:l.airportIATA||l.airportName||null,flights:(l.flights||[]).map(d=>`${d.flight_number||"?"} ${k(d.flight_date)}`)},after:{passengers:w.length,extraBags:$,addons:C.map(d=>`${d.name}×${d.quantity}`),adminFee:Number(R)||0,finalTotal:Y,serviceType:g.serviceType,serviceDate:g.serviceDate||null,serviceTime:g.serviceTime||null,airport:g.airportIATA||g.airportName||null,flights:I.map(d=>`${d.flight_number||"?"} ${k(d.flight_date)}`)}},notes:he||null}),K.success("Order updated",{description:`New total: ${ne(Y,t.currency)}`}),P.invalidateQueries({queryKey:["admin-orders"]}),P.invalidateQueries({queryKey:["admin-order-editor",p]}),P.invalidateQueries({queryKey:["admin-order-audit",p]})}catch(v){console.error("Edit order error:",v),K.error("Failed to update order",{description:v.message})}finally{H(!1)}}};return Ye?e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center",children:e.jsx(Te,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):h?e.jsxs("div",{className:"min-h-screen bg-muted/20 pb-40 lg:pb-10",children:[e.jsx("header",{className:"sticky top-0 z-20 border-b bg-background/95 backdrop-blur",children:e.jsxs("div",{className:"mx-auto flex max-w-6xl items-center gap-3 px-4 py-3",children:[e.jsx(y,{variant:"ghost",size:"icon",onClick:()=>m(-1),"aria-label":"Back",children:e.jsx(ha,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h1",{className:"truncate text-base font-semibold sm:text-lg",children:["Edit phone order ",h.order_reference]}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[h.customer_name," · ",l.serviceType||"Airport service"," · ",l.airportIATA||l.airportName||"—"]})]}),e.jsx(ue,{variant:"outline",className:"hidden shrink-0 capitalize sm:inline-flex",children:h.status})]})}),e.jsxs("main",{className:"mx-auto grid max-w-6xl gap-5 px-4 py-5 lg:grid-cols-[1.2fr_0.8fr]",children:[e.jsxs("div",{className:"space-y-5",children:[Je&&e.jsxs(ke,{children:[e.jsx(Se,{className:"h-4 w-4"}),e.jsx(ma,{children:"Customer may be on the payment page"}),e.jsx(Ae,{children:"Saving invalidates the active checkout session — they will need to refresh and pay the new total."})]}),e.jsx(Q,{icon:pa,title:"Service details",description:"Drives the service date, time and airport shown on the shared review-and-pay link.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Service type"}),e.jsxs(Ee,{value:g.serviceType,onValueChange:a=>z({...g,serviceType:a}),children:[e.jsx(Oe,{className:"mt-1",children:e.jsx(Me,{})}),e.jsxs(ze,{children:[e.jsx(be,{value:"arrival",children:"Arrival"}),e.jsx(be,{value:"departure",children:"Departure"}),e.jsx(be,{value:"transit",children:"Transit"})]})]})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Service date"}),e.jsx(u,{className:"mt-1",type:"date",value:g.serviceDate,onChange:a=>z({...g,serviceDate:a.target.value})})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Service time"}),e.jsx(u,{className:"mt-1",type:"time",value:g.serviceTime,onChange:a=>z({...g,serviceTime:a.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Service airport"}),e.jsxs(Ee,{value:g.airportId,onValueChange:a=>{const r=$e.find(s=>
1s.id===a);z({...g,airportId:a,airportIATA:(r==null?void 0:r.iata_code)||"",airportName:(r==null?void 0:r.airport_name)||""})},children:[e.jsx(Oe,{className:"mt-1",children:e.jsx(Me,{placeholder:g.airportName||"Select service airport"})}),e.jsx(ze,{className:"max-h-72",children:$e.map(a=>e.jsxs(be,{value:a.id,children:[a.iata_code," — ",a.airport_name,a.city?` · ${a.city}`:""]},a.id))})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Changing the airport reloads its pricing defaults and available extra services."})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ue,{checked:g.isTimeConfirmed,onCheckedChange:a=>z({...g,isTimeConfirmed:!!a})}),"Service time confirmed (uncheck to show “TBC” to the client)"]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Special requests"}),e.jsx(la,{className:"mt-1",rows:2,value:g.specialRequests,onChange:a=>z({...g,specialRequests:a.target.value})})]}),J&&e.jsxs(y,{size:"sm",variant:"outline",className:"gap-1",onClick:sa,children:[e.jsx(Ke,{className:"h-3.5 w-3.5"})," Use time from service leg"]})]})}),e.jsx(Q,{icon:da,title:`Flight itinerary (${I.length})`,description:"Exactly what the client sees in the flight preview on the shared order page.",children:e.jsxs("div",{className:"space-y-4",children:[I.length>0&&e.jsxs("div",{className:"space-y-2 rounded-xl border border-primary/30 bg-primary/5 p-3",children:[e.jsx("p",{className:"text-xs font-semibold",children:"Live preview — as it appears on the order page, confirmation & receipt"}),Qe(I).map((a,r)=>{const s=ga(a);return e.jsxs("div",{className:"rounded-lg border bg-background p-3 text-sm",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"font-medium",children:["Leg ",r+1," ",a.is_service_leg&&e.jsx(ue,{variant:"secondary",className:"ml-1",children:"Service leg"})]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[s.airline," ",s.flightNo&&`· ${s.flightNo}`]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Departs"}),e.jsx("div",{children:s.depAirport}),e.jsx("div",{className:"font-mono text-xs",children:s.depLine})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Arrives ",s.crossesMidnight&&e.jsx("span",{className:"text-amber-600",children:"(next day)"})]}),e.jsx("div",{children:s.arrAirport}),e.jsx("div",{className:"font-mono text-xs",children:s.arrLine})]})]}),e.jsxs("div",{className:"mt-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Duration: "}),a.duration_hidden?e.jsx("span",{className:"font-medium",children:"hidden — the client sees no duration"}):s.durationLabel?e.jsx("span",{className:"font-medium",children:s.durationLabel}):e.jsx("span",{className:"text-amber-600",children:"not shown — needs departure & arrival date + time"})]})]},`prev-${a._key}`)})]}),I.length===0&&e.jsx("p",{className:"rounded-xl bg-muted/30 p-4 text-sm text-muted-foreground",children:"No flight legs — the client will see the order without a flight preview."}),I.map((a,r)=>e.jsxs("div",{className:"rounded-xl border bg-muted/20 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs(ue,{variant:a.is_service_leg?"default":"secondary",className:"text-xs",children:["Leg ",r+1,a.is_service_leg?" · Service leg":""]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(y,{size:"sm",variant:"ghost",className:"text-xs",disabled:a.is_service_leg,onClick:()=>aa(a._key),children:"Use as service leg"}),e.jsxs(y,{size:"sm",variant:"ghost",className:"gap-1 text-destructive",onClick:()=>oe(I.filter(s=>s._key!==a._key)),children:[e.jsx(xe,{className:"h-3.5 w-3.5"})," Remove"]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Flight number"}),e.jsx(u,{className:"mt-1",value:a.flight_number||"",onChange:s=>F(a._key,{flight_number:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Airline"}),e.jsx(ua,{className:"mt-1",code:a.airline_code||"",name:a.airline_name||"",onChange:({code:s,name:n})=>F(a._key,{airline_code:s,airline_name:n,airline_logo_url:s?He(s):a.airline_logo_url}),placeholder:"Search airline…"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"From airport"}),e.jsx(Ve,{className:"mt-1",iata:a.origin_airport_code||"",name:a.origin_airport_name||"",onChange:({i
1ata:s,name:n})=>F(a._key,{origin_airport_code:s,origin_airport_name:n}),placeholder:"Search departure airport…"})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"To airport"}),e.jsx(Ve,{className:"mt-1",iata:a.destination_airport_code||"",name:a.destination_airport_name||"",onChange:({iata:s,name:n})=>F(a._key,{destination_airport_code:s,destination_airport_name:n}),placeholder:"Search arrival airport…"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Departure date"}),e.jsx(u,{className:"mt-1",type:"date",value:k(a.flight_date),onChange:s=>F(a._key,{flight_date:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Departure time"}),e.jsx(u,{className:"mt-1",type:"time",value:E(a.departure_time),onChange:s=>F(a._key,{departure_time:s.target.value})})]}),e.jsxs("div",{children:[e.jsxs(o,{className:"text-xs text-muted-foreground",children:["Arrival date ",e.jsx("span",{className:"opacity-70",children:"(if different)"})]}),e.jsx(u,{className:"mt-1",type:"date",value:k(a.arrival_date),onChange:s=>F(a._key,{arrival_date:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Arrival time"}),e.jsx(u,{className:"mt-1",type:"time",value:E(a.arrival_time),onChange:s=>F(a._key,{arrival_time:s.target.value})})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Terminal"}),e.jsx(u,{className:"mt-1",value:a.terminal||"",onChange:s=>F(a._key,{terminal:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Gate"}),e.jsx(u,{className:"mt-1",value:a.gate||"",onChange:s=>F(a._key,{gate:s.target.value})})]})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border bg-background px-3 py-2 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!a.duration_hidden,onChange:s=>F(a._key,{duration_hidden:!s.target.checked})}),e.jsx("span",{className:"font-medium",children:"Show flight duration to the client"})]}),a.duration_hidden&&e.jsx("p",{className:"text-muted-foreground",children:"Duration is hidden on the itinerary, service order sheet, confirmation, receipt and share message."}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Computed duration: "}),Z(ge(a))?e.jsx("span",{className:"font-medium",children:Z(ge(a))}):e.jsx("span",{className:"text-amber-600",children:"— enter departure and arrival date + time"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!a.duration_manual,onChange:s=>F(a._key,{duration_manual:s.target.checked,duration_minutes:s.target.checked?Number(a.duration_minutes)||ge(a)||null:ge(a),_durationInput:s.target.checked?a._durationInput??Z(Number(a.duration_minutes)||ge(a)):""})}),e.jsx("span",{children:"Enter the duration manually"})]}),a.duration_manual&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{className:"h-8 w-40",placeholder:"7h 30m",value:a._durationInput??Z(a.duration_minutes),onChange:s=>F(a._key,{_durationInput:s.target.value,duration_minutes:Fe(s.target.value)})}),e.jsx("span",{className:"text-muted-foreground",children:Fe(a._durationInput??Z(a.duration_minutes))?`Client sees: ${Z(Fe(a._durationInput??Z(a.duration_minutes)))}`:"Use “7h 30m”, “7:30” or minutes (450)"})]})]})]},a._key)),e.jsxs(y,{variant:"outline",className:"gap-1",onClick:ea,children:[e.jsx(Ne,{className:"h-3.5 w-3.5"})," Add flight leg"]}),g.serviceType==="transit"&&I.length<2&&e.jsx("p",{className:"text-xs text-amber-600",children:"Transit service usually has 2 flight legs (inbound + onward). Add the second leg above."})]})}),e.jsxs(Q,{icon:oa,title:`Passengers (${w.length})`,description:"Children are free and receive no baggage allowance.",children:[e.jsx("div",{className:"mb-3 flex justify-end",children:e.jsxs(y,{size:"sm",variant:"outline",onClick:We,className:"gap-1",children:[e.jsx(Ne,{className:"h-3.5 w-3.5"})," Add passenger"]})}),e.jsx("div",{className:"space-y-3",children:w.map((a,r)=>
1e.jsxs("div",{className:"rounded-xl border bg-muted/20 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx(ue,{variant:r===0?"default":"secondary",className:"text-xs",children:r===0?"Primary passenger":`Passenger ${r+1}`}),r>0&&e.jsxs(y,{size:"sm",variant:"ghost",className:"h-8 gap-1 text-destructive",onClick:()=>Xe(r),children:[e.jsx(xe,{className:"h-3.5 w-3.5"})," Remove"]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"First name"}),e.jsx(u,{value:a.first_name,onChange:s=>me(r,"first_name",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Last name"}),e.jsx(u,{value:a.last_name,onChange:s=>me(r,"last_name",s.target.value)})]}),r===0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Email"}),e.jsx(u,{value:a.email||"",onChange:s=>me(r,"email",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Phone"}),e.jsx(u,{value:a.phone||"",onChange:s=>me(r,"phone",s.target.value)})]})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Passenger type"}),e.jsxs("select",{value:a.passenger_type||"adult",onChange:s=>me(r,"passenger_type",s.target.value),className:"mt-1 h-10 w-full rounded-md border bg-background px-3 text-sm",children:[e.jsx("option",{value:"adult",children:"Adult"}),e.jsx("option",{value:"child",children:"Child (free)"})]})]})]})]},r))})]}),e.jsx(Q,{icon:va,title:"Baggage",description:"Free allowance is calculated from adult passengers.",children:e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Free allowance"}),e.jsx(u,{value:t.freeAllowance,disabled:!0})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Extra bags"}),e.jsx(u,{type:"number",min:0,value:$,onChange:a=>ae(Math.max(0,parseInt(a.target.value||"0",10)))})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Price / bag"}),e.jsx(u,{type:"number",step:"0.01",min:0,value:c.pricePerBag,onChange:a=>L("pricePerBag",parseFloat(a.target.value)||0)})]})]})}),e.jsx(Q,{icon:ja,title:"Extra services",description:"Transportation, flowers or any add-on available at this airport.",children:e.jsxs("div",{className:"space-y-3",children:[C.length===0&&e.jsx("p",{className:"rounded-xl bg-muted/30 p-4 text-sm text-muted-foreground",children:"No add-ons selected."}),C.map(a=>e.jsxs("div",{className:"grid gap-3 rounded-xl border bg-muted/20 p-3 sm:grid-cols-[1fr_6rem_auto] sm:items-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.name}),e.jsx(u,{type:"number",step:"0.01",min:0,className:"mt-1 h-8",value:a.price,onChange:r=>G(C.map(s=>s.id===a.id?{...s,price:parseFloat(r.target.value)||0}:s))})]}),e.jsx(u,{type:"number",min:0,className:"h-9",value:a.quantity,onChange:r=>{const s=Math.max(0,parseInt(r.target.value||"0",10));G(C.map(n=>n.id===a.id?{...n,quantity:s}:n))}}),e.jsxs(y,{size:"sm",variant:"ghost",className:"justify-start gap-1 text-destructive sm:justify-center",onClick:()=>G(C.filter(r=>r.id!==a.id)),children:[e.jsx(xe,{className:"h-3.5 w-3.5"})," Remove"]})]},a.id)),ce.length>0&&e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Add a service"}),e.jsxs("select",{className:"mt-1 h-11 w-full rounded-md border bg-background px-3 text-sm",value:"",onChange:a=>a.target.value&&Ze(a.target.value),children:[e.jsx("option",{value:"",children:"Select an add-on"}),ce.filter(a=>!C.some(r=>r.id===a.id)).map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",ne(Number(a.price),t.currency),")"]},a.id))]})]})]})}),e.jsx(Q,{icon:_a,title:"Pricing overrides",description:"These values apply to this order only — airport defaults stay untouched.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ue,{checked:c.usePricePerPax,onCheckedChange:a=>L("usePricePerPax",!!a)}),"Price per passenger model"]}),e.jsxs(y,{size:"sm",variant:"ghost",className:"gap-1 text-xs",disabled:!i,onClick:()=>{q([]),M([]),Ce(a=>({...a,basePrice:Number(i==null?void 0:i.base_price)||0,additionalPassengerFee:Number(i==null?void 0:i.additional_passenger_fee)||0,includedPasse
1ngers:Math.max(1,Number(i==null?void 0:i.included_passengers)||1),usePricePerPax:!!(i!=null&&i.use_price_per_pax),pricePerPax:Number(i==null?void 0:i.price_per_pax)||0,pricePerBag:Number(i==null?void 0:i.extra_bag_price)||0,processingFeePercentage:Ie,discount:0,extraCharge:0,totalOverride:""}))},children:[e.jsx(Ke,{className:"h-3.5 w-3.5"})," Reset to airport defaults"]})]}),c.usePricePerPax?e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Price per passenger"}),e.jsx(u,{type:"number",step:"0.01",min:0,value:c.pricePerPax,onChange:a=>L("pricePerPax",parseFloat(a.target.value)||0)})]}):e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Base price"}),e.jsx(u,{type:"number",step:"0.01",min:0,value:c.basePrice,onChange:a=>L("basePrice",parseFloat(a.target.value)||0)})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Passengers included"}),e.jsx(u,{type:"number",min:1,value:c.includedPassengers,onChange:a=>L("includedPassengers",Math.max(1,parseInt(a.target.value||"1",10)))})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Additional passenger fee"}),e.jsx(u,{type:"number",step:"0.01",min:0,value:c.additionalPassengerFee,onChange:a=>L("additionalPassengerFee",parseFloat(a.target.value)||0)})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Free bags / adult"}),e.jsx(u,{type:"number",min:0,value:c.freeAllowancePerAdult,onChange:a=>L("freeAllowancePerAdult",parseInt(a.target.value||"0",10))})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Processing fee %"}),e.jsx(u,{type:"number",step:"0.01",min:0,value:c.processingFeePercentage,onChange:a=>L("processingFeePercentage",parseFloat(a.target.value)||0)})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Admin fee"}),e.jsx(u,{type:"number",step:"0.01",min:0,value:R,onChange:a=>de(parseFloat(a.target.value)||0)})]})]}),(pe.length>0||Re.length>0)&&e.jsxs("div",{className:"space-y-2",children:[pe.map((a,r)=>e.jsxs(ke,{variant:"destructive",children:[e.jsx(Se,{className:"h-4 w-4"}),e.jsx(Ae,{className:"text-xs",children:a.message})]},`err-${r}`)),Re.map((a,r)=>e.jsxs(ke,{className:"border-amber-300 bg-amber-50 text-amber-900 dark:bg-amber-950/30",children:[e.jsx(Se,{className:"h-4 w-4"}),e.jsx(Ae,{className:"text-xs",children:a.message})]},`warn-${r}`))]}),e.jsxs("div",{className:"rounded-xl border bg-muted/20 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-sm font-semibold",children:"Additional charges"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Any extra service or fee — name it yourself (e.g. “Transportation — pickup at 12 Rue de Rivoli”)."})]}),e.jsxs(y,{size:"sm",variant:"outline",className:"shrink-0 gap-1",onClick:()=>q([...N,V()]),children:[e.jsx(Ne,{className:"h-3.5 w-3.5"})," Add"]})]}),N.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No extra charges."}),N.map((a,r)=>e.jsxs("div",{className:"rounded-lg border bg-background p-3 space-y-2",children:[e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[1fr_8rem_auto] sm:items-end",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Name shown to customer"}),e.jsx(u,{value:a.label,placeholder:"e.g. Transportation",onChange:s=>q(N.map((n,v)=>v===r?{...n,label:s.target.value}:n))})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Amount"}),e.jsx(u,{type:"number",step:"0.01",value:a.amount,onChange:s=>q(N.map((n,v)=>v===r?{...n,amount:parseFloat(s.target.value)||0}:n))})]}),e.jsxs(y,{size:"sm",variant:"ghost",className:"gap-1 text-destructive",onClick:()=>q(N.filter((s,n)=>n!==r)),children:[e.jsx(xe,{className:"h-3.5 w-3.5"})," Remove"]})]}),e.jsx(u,{className:"h-9",placeholder:"Optional detail (pickup point, notes…)",value:a.note||"",onChange:s=>q(N.map((n,v)=>v===r?{...n,note:s.target.value}:n))})]},a.id)),e.jsx("div",{className:"flex flex-wrap gap-2",children:["Transportation","Flower greeting","Late booking fee","Extra agent"].map(a=>e.jsxs(y,{size:"sm",variant:"secondary",className:"text-xs",onClick:()=>q([...N,V(a,0)]),children:["+ ",a]},a))})]}),e.jsxs("div",{className:"rounded-xl border bg-muted/20 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-sm font-semibold",children:"Reductions"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Discounts, goodwill gestures, waived fees — one line each."})]}),e.jsxs(y,{size:"sm",variant:"outline",className:"shrink-0 gap-1",onClick:()=>M([...T,V("Discount")]),children:[e.jsx(Ne,{className:"h-3.5 w-3.5"})," Add"]})]}),T.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No reductions."}),T.map((a,r)=>
1e.jsxs("div",{className:"grid gap-2 rounded-lg border bg-background p-3 sm:grid-cols-[1fr_8rem_auto] sm:items-end",children:[e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Name shown to customer"}),e.jsx(u,{value:a.label,placeholder:"e.g. Loyalty discount",onChange:s=>M(T.map((n,v)=>v===r?{...n,label:s.target.value}:n))})]}),e.jsxs("div",{children:[e.jsx(o,{className:"text-xs text-muted-foreground",children:"Amount off"}),e.jsx(u,{type:"number",step:"0.01",min:0,value:a.amount,onChange:s=>M(T.map((n,v)=>v===r?{...n,amount:parseFloat(s.target.value)||0}:n))})]}),e.jsxs(y,{size:"sm",variant:"ghost",className:"gap-1 text-destructive",onClick:()=>M(T.filter((s,n)=>n!==r)),children:[e.jsx(xe,{className:"h-3.5 w-3.5"})," Remove"]})]},a.id)),e.jsx("div",{className:"flex flex-wrap gap-2",children:[5,10,15,20,50].map(a=>e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>{const r=t.baseServiceTotal+t.additionalPassengerTotal+t.luggageTotal+t.addonsTotal+t.extraCharge;M([...T,V(`${a}% discount`,+(r*a/100).toFixed(2))])},children:["-",a,"%"]},a))})]}),e.jsxs("div",{className:"rounded-xl border border-dashed p-3 space-y-2",children:[e.jsx(o,{className:"text-sm font-semibold",children:"Force final total"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Overrides every calculation above. Leave empty to use the calculated total."}),e.jsx(u,{type:"number",step:"0.01",min:0,placeholder:`Calculated: ${qe.toFixed(2)}`,value:c.totalOverride,onChange:a=>L("totalOverride",a.target.value)}),ve&&e.jsxs("p",{className:"text-xs text-destructive",children:["Manual total active — customer will be charged ",ne(Y,t.currency)]})]})]})}),e.jsx(Q,{icon:ba,title:"Reason for change",description:"Stored in the order audit history.",children:e.jsx(u,{placeholder:"e.g. Added complimentary passenger",value:he,onChange:a=>le(a.target.value)})}),e.jsx(Q,{icon:Na,title:`Edit history (${we.length})`,children:we.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:"No edits recorded yet"}):e.jsx("div",{className:"space-y-3",children:we.map(a=>e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-3",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx(ue,{variant:"outline",className:"text-xs capitalize",children:a.change_type}),e.jsx("span",{className:"text-xs text-muted-foreground",children:ca(new Date(a.created_at),"MMM d, yyyy HH:mm")})]}),a.changed_by_email&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["By: ",a.changed_by_email]}),a.notes&&e.jsxs("p",{className:"mt-1 text-sm italic",children:['"',a.notes,'"']})]},a.id))})})]}),e.jsx("aside",{className:"hidden lg:block",children:e.jsxs("div",{className:"sticky top-20 space-y-4 rounded-2xl border bg-card p-4 shadow-sm",children:[e.jsx("h2",{className:"text-sm font-semibold",children:"Live booking summary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{label:`Base service${c.usePricePerPax?` × ${t.paidPassengerCount}`:""}`,value:t.baseServiceTotal,currency:t.currency}),t.additionalPassengerTotal>0&&e.jsx(O,{label:"Additional passengers",value:t.additionalPassengerTotal,currency:t.currency}),t.luggageTotal>0&&e.jsx(O,{label:`Extra bags (${$})`,value:t.luggageTotal,currency:t.currency}),t.addonsTotal>0&&e.jsx(O,{label:"Extra services",value:t.addonsTotal,currency:t.currency}),t.cleanCharges.map(a=>e.jsx(O,{label:a.label,value:a.amount,currency:t.currency},a.id)),t.cleanReductions.map(a=>e.jsx(O,{label:a.label,value:-a.amount,currency:t.currency},a.id)),e.jsx("div",{className:"my-2 border-t"}),e.jsx(O,{label:"Subtotal",value:t.subtotal,currency:t.currency}),e.jsx(O,{label:`Processing fee (${t.processingFeePercentage}%)`,value:t.processingFee,currency:t.currency}),R>0&&e.jsx(O,{label:"Admin fee",value:R,currency:t.currency})]}),e.jsxs("div",{className:"flex items-baseline justify-between border-t pt-3",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Final total"}),e.jsxs("div",{className:"text-right leading-tight",children:[e.jsx("div",{className:"text-xl font-bold",children:ne(Y,t.currency)}),Number(h.final_total)!==Y&&e.jsx("div",{className:"text-[11px] text-muted-foreground line-through",children:ne(Number(h.final_total)||0,t.currency)})]})]}),e.jsxs(y,{className:"w-full gap-2",onClick:De,disabled:S,children:[S?e.jsx(Te,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"})," Save changes"]})]})})]}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-30 border-t bg-background/95 px-4 pb-[calc(env(safe-area-inset-bottom)+0.75rem)] pt-3 backdrop-blur lg:hidden",children:[e.jsxs("div",{className:"mb-2 flex items-baseline justify-between",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Final total"}),e.jsx("span",{className:"text-lg font-bold",children:ne(Y,t.currency)})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"outline",className:"flex-1",onClick:()=>m(-1),disabled:S,children:"Cancel"}),e.jsxs(y,{className:"flex-1 gap-2",onClick:De,disabled:S,children:[S?e.jsx(Te,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"})," Save"]})]})]})]}):e.jsxs("div",{className:"mx-auto max-w-lg px-4 py-16 text-center",children:[e.jsx("h1",{className:"text-lg font-semibold",children:"Order not found"}),e.jsx(y,{variant:"outline",className:"mt-4",onClick:()=>m("/admin"),children:"Back to dashboard"})]})}
1export{Ma 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.