import{V as ye,r as c,q as Xe,t as Yr,c as K,v as T,aW as Qr,bf as Hr,j as e,n as Gr,X as Dr,aG as fr,av as Jr,a1 as Zr,au as Wr,aX as kr,e as er,a9 as rr,aY as Xr,aO as eo,aP as ro,ac as Ke,ae as Be,af as Qe,ax as He,ag as Je,aR as Ze,$ as B,a0 as Er,a4 as ue,a5 as be,a6 as de,a7 as Se,a8 as I,aT as We,B as v,aB as oo,aV as Ir,bg as io,bh as so,bi as lo,C as ze,W as vr,Y as Or,I as ve,i as z,R as no,a_ as Oe,S as to,f as ce,d as Ce,M as ao,bj as Ve,aa as mo,E as co,ad as uo,aM as bo,bk as So,bl as po,N as pe}from"./index-Ef5HIHwv.js";import{A as yo,s as ho,I as xo,E as go}from"./EmailLivePreview-BVCmMA0B.js";import{T as No}from"./textarea-DI4Rh5ZE.js";import{C as Do}from"./checkbox-BVivpJ34.js";import{E as fo}from"./EmailComposePanel-CJQwBVRG.js";import{S as Cr}from"./star-BJeP7_T0.js";import{P as Vr}from"./paperclip-D8gnDdf4.js";import{D as Eo}from"./index-5CRimzhx.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const vo=ye("Archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ae=ye("FileBadge2",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m14 12.5 1 5.5-3-1-3 1 1-5.5",key:"14xlky"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Oo=ye("Mountain",[["path",{d:"m8 3 4 8 5-5 5 15H2L8 3z",key:"otkl63"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ar=ye("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Lr=ye("Unlink",[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]),Co=/\{\{\s*([\w.]+)\s*\}\}/g;function Pr(o,i){return o?o.replace(Co,(g,h)=>{const t=h.trim();if(t in i){const x=i[t];return x==null?"":String(x)}const d=t.split(".");let N=i;for(const x of d)if(N&&typeof N=="object"&&x in N)N=N[x];else{N=void 0;break}return N==null?`{{${t}}}`:String(N)}):""}function Vo(o,i){var t;const g=((o==null?void 0:o.from_name)||"").trim().split(/\s+/)[0]||"",h=((t=o==null?void 0:o.parsed_data)==null?void 0:t.extracted)||{};return{customer_name:(o==null?void 0:o.from_name)||"",customer_first_name:g,customer_email:(o==null?void 0:o.from_email)||"",booking_ref:(o==null?void 0:o.booking_code)||(i==null?void 0:i.code)||"",company_name:"",departure_date:"",destination:"",total_amount:"",currency:"",passenger_count:"",supplier_name:(o==null?void 0:o.supplier_name)||h.supplier_name||"",supplier_ref:h.supplier_ref||h.supplier_reference||"",hcn_number:h.hcn||h.hcn_number||"",eticket_id:h.eticket||h.eticket_id||"",tour_confirmation_number:h.tour_confirmation||"",transfer_confirmation_number:h.transfer_confirmation||"",check_in_date:"",check_out_date:"",request_number:h.request_number||""}}const Ao=/^[A-Za-z0-9][A-Za-z0-9_/\-.]{2,30}[A-Za-z0-9]$/;function Lo(o,i={}){const{pattern:g=Ao,minLength:h=4,maxLength:t=32,skipInEditableContext:d=!0}=i,[N,x]=c.useState(null),n=c.useRef(null),u=c.useCallback(()=>{if(!o.current){x(null);return}const b=window.getSelection();if(!b||b.isCollapsed||b.rangeCount===0){x(null);return}if(d){const M=document.activeElement;if(M&&(M.tagName==="INPUT"||M.tagName==="TEXTAREA"||M.isContentEditable)){x(null);return}}const y=b.getRangeAt(0),O=y.commonAncestorContainer;if(!o.current.contains(O.nodeType===Node.TEXT_NODE?O.parentElement:O)){x(null);return}const Y=b.toString(),q=Y.replace(/\s+/g," ").trim();if(!q||/[\r\n]/.test(Y)){x(null);return}if(q.length<h||q.length>t){x(null);return}if(!g.test(q)){x(null);return}const C=y.getBoundingClientRect();if(!C||C.width===0&&C.height===0){x(null);return}x({text:q,rect:C})},[o,g,h,t,d]);return c.useEffect(()=>{const b=()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(u,80)};document.addEventListener("selectionchange",b);const y=()=>u();return window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{document.removeEventListener("selectionchange",b),window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y),n.current&&clearTimeout(n.current)}},[u]),N}const Po={hotel:Wr,flight:Zr,transfer:Jr,tour:Oo,visa:Ae,insurance:Ae,service:Ae};function jo({selection:o,bookingCode:i,customerEmail:g,customerName:h,onAssigned:t,onDismiss:d}){var M;const{toast:N}=Xe(),x=Yr(),[n,u]=c.useState(!1),b=c.useRef(null),y=K({queryKey:["booking-confirmation-numbers",i],queryFn:()=>Xr(i),enabled:!!i,staleTime:3e4,refetchOnWindowFocus:!1}),O=c.useMemo(()=>{var f,A;const S=((f=y.data)==null?void 0:f.result)||[],D=[];for(const j of S)if(j.kind==="hotel"){const J=((A=j.rooms.find(oe=>oe.hcn))==null?void 0:A.hcn)||"";D.push({product:j,field:"hcn",fieldLabel:"HCN",currentValue:J})}else j.kind==="flight"?D.push({product:j,field:"pnr",fieldLabel:"PNR",currentValue:j.pnr}):D.push({product:j,field:"confirmation_number",fieldLabel:"Confirmation #",currentValue:j.confirmation_number});return D},[y.data]),U=T({mutationFn:async S=>{const D=S.product.kind==="hotel"?{product_id:S.product.product_id,kind:"hotel",rooms:S.product.rooms.length>0?S.product.rooms.map(f=>({index:f.index,hcn:o.text})):[{index:0,hcn:o.text}]}:S.product.kind==="flight"?{product_id:S.product.product_id,kind:"flight",pnr:o.text}:{product_id:S.product.product_id,kind:S.product.kind,confirmation_number:o.text};return Qr(i,[D],`Assigned from selection in email — value "${o.text}"`)},onSuccess:(S,D)=>{var A;x.invalidateQueries({queryKey:["booking-confirmation-numbers",i]}),x.invalidateQueries({queryKey:["easygds","booking-products"]}),x.invalidateQueries({queryKey:["easygds","booking-pnrs"]});const f=S.failed||[];if(f.length>0){N({variant:"destructive",title:"Assign failed",description:f[0].error||"EasyGDS rejected the change."});return}u(!1),d==null||d();try{(A=window.getSelection())==null||A.removeAllRanges()}catch{}N({title:`${D.fieldLabel} assigned`,description:`"${o.text}" → ${D.product.title}`}),t==null||t({kind:D.product.kind,value:o.text,productTitle:D.product.title})},onError:S=>{N({variant:"destructive",title:"Assign failed",description:S.message})}});c.useEffect(()=>{const S=D=>{var f;if(D.key==="Escape"){u(!1),d==null||d();try{(f=window.getSelection())==null||f.removeAllRanges()}catch{}}};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[d]),c.useEffect(()=>{const S=D=>{n&&b.current&&!b.current.contains(D.target)&&u(!1)};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[n]);const Y=o.rect.top-48,q=Y<8,C={position:"fixed",left:Math.max(8,o.rect.left),top:q?o.rect.bottom+8:Y,zIndex:60};return Hr.createPortal(e.jsxDEV("div",{ref:b,style:C,className:"select-none",children:n?e.jsxDEV("div",{className:"bg-white border rounded-lg shadow-2xl w-[320px] overflow-hidden",children:[e.jsxDEV("div",{className:"px-3 py-2 border-b bg-gray-50 flex items-center justify-between gap-2",children:[e.jsxDEV("div",{className:"text-xs font-semibold truncate",children:["Assign ",e.jsxDEV("span",{className:"font-mono",children:o.text.length>16?o.text.slice(0,14)+"…":o.text},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:227,columnNumber:22},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:226,columnNumber:13},this),e.jsxDEV("button",{type:"button",onClick:()=>u(!1),className:"text-gray-400 hover:text-gray-700","aria-label":"Close menu",children:e.jsxDEV(Dr,{className:"h-3.5 w-3.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:235,columnNumber:15},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:229,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:225,columnNumber:11},this),i?y.isLoading?e.jsxDEV("div",{className:"px-3 py-4 text-xs text-muted-foreground flex items-center gap-2",children:[e.jsxDEV(fr,{className:"h-3 w-3 animate-spin"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:246,columnNumber:15},this)," Loading products…"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:245,columnNumber:13},this):y.isError?e.jsxDEV("div",{className:"px-3 py-4 text-xs text-red-700 bg-red-50",children:["Failed to load: ",(M=y.error)==null?void 0:M.message]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:249,columnNumber:13},this):O.length===0?e.jsxDEV("div",{className:"px-3 py-4 text-xs text-muted-foreground",children:"No services on this booking."},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:253,columnNumber:13},this):e.jsxDEV("ul",{className:"max-h-[320px] overflow-y-auto divide-y",children:O.map(S=>{const D=Po[S.product.kind]||Ae,f=!!S.currentValue&&S.currentValue!==o.text,A=S.currentValue===o.text;return e.jsxDEV("li",{children:e.jsxDEV("button",{type:"button",disabled:A||U.isPending,onClick:()=>U.mutate(S),className:"w-full text-left px-3 py-2.5 flex items-start gap-2 hover:bg-orange-50 disabled:opacity-50 disabled:bg-gray-50 disabled:cursor-not-allowed",children:[e.jsxDEV(D,{className:"h-4 w-4 mt-0.5 shrink-0 text-orange-600"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:270,columnNumber:23},this),e.jsxDEV("div",{className:"flex-1 min-w-0",children:[e.jsxDEV("div",{className:"text-xs font-semibold uppercase tracking-wide text-gray-700",children:S.fieldLabel},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:272,columnNumber:25},this),e.jsxDEV("div",{className:"text-sm truncate",children:S.product.title},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:275,columnNumber:25},this),e.jsxDEV("div",{className:"text-[11px] mt-0.5",children:A?e.jsxDEV("span",{className:"text-green-700 inline-flex items-center gap-1",children:[e.jsxDEV(kr,{className:"h-3 w-3"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:279,columnNumber:31},this)," Already set to this value"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:278,columnNumber:29},this):f?e.jsxDEV("span",{className:"text-amber-700 inline-flex items-center gap-1",children:[e.jsxDEV(er,{className:"h-3 w-3"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:283,columnNumber:31},this),"Replaces ",e.jsxDEV("span",{className:"font-mono",children:S.currentValue},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:284,columnNumber:40},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:282,columnNumber:29},this):e.jsxDEV("span",{className:"text-muted-foreground",children:"Currently empty — will be set"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:287,columnNumber:29},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:276,columnNumber:25},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:271,columnNumber:23},this),U.isPending&&U.variables===S?e.jsxDEV(fr,{className:"h-4 w-4 animate-spin text-orange-600 mt-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:292,columnNumber:27},this):e.jsxDEV(rr,{className:"h-4 w-4 text-gray-300 mt-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:293,columnNumber:27},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:264,columnNumber:21},this)},`${S.product.product_id}-${S.field}`,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:263,columnNumber:19},this)})},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:257,columnNumber:13},this):e.jsxDEV("div",{className:"px-3 py-4 text-xs text-amber-900 bg-amber-50",children:["Email isn't linked to a booking yet. Use ",e.jsxDEV("strong",{children:"Link to booking"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:242,columnNumber:56},this)," first."]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:241,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:224,columnNumber:9},this):e.jsxDEV("button",{type:"button",onClick:()=>u(!0),className:"group inline-flex items-center gap-1.5 rounded-full bg-gray-900 text-white text-xs font-medium pl-3 pr-2 py-1.5 shadow-lg hover:bg-gray-800 transition-colors",children:[e.jsxDEV("span",{children:["Assign ",e.jsxDEV("span",{className:"font-mono bg-white/15 px-1.5 py-0.5 rounded",children:o.text.length>20?o.text.slice(0,18)+"…":o.text},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:211,columnNumber:24},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:211,columnNumber:11},this),e.jsxDEV(Gr,{className:"h-3 w-3 transition-transform group-hover:translate-x-0.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:212,columnNumber:11},this),e.jsxDEV("span",{role:"button","aria-label":"Dismiss",onClick:S=>{var D;S.stopPropagation(),d==null||d();try{(D=window.getSelection())==null||D.removeAllRanges()}catch{}},className:"ml-1 text-white/60 hover:text-white p-0.5 rounded",children:e.jsxDEV(Dr,{className:"h-3 w-3"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:219,columnNumber:13},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:213,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:206,columnNumber:9},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/selection-assist/EmailSelectionToolbar.tsx",lineNumber:203,columnNumber:5},this),document.body)}function Uo({open:o,onOpenChange:i,bookingId:g,bookingCode:h,customerEmail:t,customerName:d,onSent:N}){var le;const{toast:x}=Xe(),[n,u]=c.useState(1),[b,y]=c.useState(null),[O,U]=c.useState([]),[Y,q]=c.useState(""),[C,M]=c.useState(""),[S,D]=c.useState(""),[f,A]=c.useState(""),[j,J]=c.useState(""),[oe,X]=c.useState([]);c.useEffect(()=>{o&&(u(1),y(null),U([]),q(""),M(t||""),D(""),A(""),J(""),X([]))},[o,g,t]);const ie=K({queryKey:["email-templates","voucher"],queryFn:()=>Ir({template_type:"voucher"}),enabled:o,staleTime:6e4}),w=(ie.data||[]).filter(a=>a.is_active),ee=K({queryKey:["booking-vouchers",h],queryFn:()=>io(h),enabled:o&&!!h,staleTime:6e4}),L=((le=ee.data)==null?void 0:le.result)||[];c.useEffect(()=>{o&&(w.length>0&&!b&&y(w[0].id),L.length>0&&O.length===0&&U(L.map(a=>a.product_index)))},[o,w,L,b,O.length]);const $=c.useMemo(()=>w.find(a=>a.id===b)||null,[w,b]),Q=T({mutationFn:async()=>{if(!b)throw new Error("Pick a template first");const a=O.length>0?O:void 0;return eo(b,{booking_code:h,product_indexes:a,notes:Y||void 0})},onSuccess:a=>{A(a.subject),J(a.body_html),X(a.missing_placeholders||[]),u(2)},onError:a=>{x({title:"Failed to render template",description:a.message,variant:"destructive"})}}),F=T({mutationFn:async()=>{const a=C.split(/[,;\s]+/).map(V=>V.trim()).filter(Boolean);if(a.length===0)throw new Error("Add at least one recipient");const Z=S.split(/[,;\s]+/).map(V=>V.trim()).filter(Boolean),re=L.filter(V=>O.includes(V.product_index)).map(V=>({filename:V.filename,url:V.pdf_url,content_type:"application/pdf"}));return ro({to:a,cc:Z,subject:f,body_html:j,booking_id:g,booking_code:h,template_id:b||void 0,category:"customer",attachments:re})},onSuccess:()=>{x({title:"Voucher sent",description:"Email logged on the booking thread with attachments."}),N==null||N(),i(!1)},onError:a=>{x({title:"Send failed",description:a.message,variant:"destructive"})}}),Le=n===1?"Step 1 of 2 — Pick template & vouchers":"Step 2 of 2 — Review & send",E=O.length,se=L.filter(a=>O.includes(a.product_index)).map(a=>({filename:a.filename,content_type:"application/pdf",url:a.pdf_url})),Pe=(a,Z)=>{U(re=>{const V=new Set(re);return Z?V.add(a):V.delete(a),Array.from(V).sort((m,je)=>m-je)})};return e.jsxDEV(Ke,{open:o,onOpenChange:a=>{F.isPending||i(a)},children:e.jsxDEV(Be,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxDEV(Qe,{children:e.jsxDEV("div",{className:"flex items-start gap-3",children:[e.jsxDEV(He,{className:"h-5 w-5 mt-0.5 text-orange-500"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:184,columnNumber:13},this),e.jsxDEV("div",{children:[e.jsxDEV(Je,{children:["Send Voucher — ",h]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:186,columnNumber:15},this),e.jsxDEV(Ze,{className:"mt-1",children:Le},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:187,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:185,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:183,columnNumber:11},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:182,columnNumber:9},this),e.jsxDEV("div",{className:"min-h-[280px]",children:[n===1&&e.jsxDEV("div",{className:"space-y-4",children:[e.jsxDEV("div",{className:"space-y-2",children:[e.jsxDEV(B,{children:"Cover-email template"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:197,columnNumber:17},this),ie.isLoading?e.jsxDEV(Er,{className:"h-9 w-full"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:199,columnNumber:19},this):w.length===0?e.jsxDEV("div",{className:"rounded border border-dashed p-4 text-sm text-muted-foreground",children:'No voucher templates configured. A default is seeded on first server boot — try restarting the backend, or add one in Settings → Templates with type "voucher".'},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:201,columnNumber:19},this):e.jsxDEV(ue,{value:b||"",onValueChange:y,children:[e.jsxDEV(be,{children:e.jsxDEV(de,{placeholder:"Pick a template…"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:207,columnNumber:36},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:207,columnNumber:21},this),e.jsxDEV(Se,{children:w.map(a=>e.jsxDEV(I,{value:a.id,children:a.name},a.id,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:210,columnNumber:25},this))},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:208,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:206,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:196,columnNumber:15},this),$&&e.jsxDEV("div",{className:"space-y-1",children:[e.jsxDEV(B,{className:"text-xs text-muted-foreground",children:"Subject preview"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:219,columnNumber:19},this),e.jsxDEV("div",{className:"text-sm font-medium",children:$.subject},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:220,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:218,columnNumber:17},this),e.jsxDEV("div",{className:"space-y-2",children:[e.jsxDEV(B,{children:"Voucher PDFs to attach"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:226,columnNumber:17},this),ee.isLoading?e.jsxDEV(Er,{className:"h-20 w-full"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:228,columnNumber:19},this):L.length===0?e.jsxDEV("div",{className:"rounded border border-dashed p-4 text-sm text-muted-foreground flex items-start gap-2",children:[e.jsxDEV(er,{className:"h-4 w-4 mt-0.5 shrink-0"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:231,columnNumber:21},this),e.jsxDEV("span",{children:["No voucher PDFs available for this booking yet. A voucher URL becomes available once the product is confirmed by the supplier (look for the ",e.jsxDEV("strong",{children:"Voucher"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:234,columnNumber:74},this)," button on each product row)."]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:232,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:230,columnNumber:19},this):e.jsxDEV("div",{className:"space-y-1.5",children:L.map(a=>e.jsxDEV("label",{className:"flex items-start gap-3 p-3 rounded-md border hover:bg-accent/30 cursor-pointer",children:[e.jsxDEV(Do,{checked:O.includes(a.product_index),onCheckedChange:Z=>Pe(a.product_index,!!Z),className:"mt-0.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:245,columnNumber:25},this),e.jsxDEV(He,{className:"h-4 w-4 mt-0.5 text-muted-foreground"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:250,columnNumber:25},this),e.jsxDEV("div",{className:"flex-1 min-w-0",children:[e.jsxDEV("div",{className:"flex items-center gap-2",children:[e.jsxDEV("span",{className:"text-xs px-1.5 py-0.5 rounded bg-muted font-mono uppercase",children:a.product_type},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:253,columnNumber:29},this),e.jsxDEV("span",{className:"text-sm font-medium truncate",children:a.filename},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:254,columnNumber:29},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:252,columnNumber:27},this),a.reference&&e.jsxDEV("div",{className:"text-xs text-muted-foreground mt-0.5 font-mono",children:["Ref: ",a.reference]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:257,columnNumber:29},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:251,columnNumber:25},this)]},a.product_index,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:241,columnNumber:23},this))},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:239,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:225,columnNumber:15},this),e.jsxDEV("div",{className:"space-y-2",children:[e.jsxDEV(B,{htmlFor:"vc-notes",children:["Additional notes ",e.jsxDEV("span",{className:"text-muted-foreground text-xs",children:"(optional)"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:268,columnNumber:60},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:268,columnNumber:17},this),e.jsxDEV(No,{id:"vc-notes",value:Y,onChange:a=>q(a.target.value),rows:2,placeholder:"Anything to add to the cover email (e.g. check-in instructions)…"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:269,columnNumber:17},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:267,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:194,columnNumber:13},this),n===2&&e.jsxDEV(fo,{contextHeader:e.jsxDEV("div",{className:"text-xs text-muted-foreground",children:["Sending ",e.jsxDEV("strong",{children:($==null?void 0:$.name)||"voucher email"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:284,columnNumber:27},this)," to ",e.jsxDEV("strong",{children:d||t||"customer"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:284,columnNumber:91},this),E>0&&e.jsxDEV(e.Fragment,{children:[" · ",E," PDF attachment",E===1?"":"s"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:285,columnNumber:39},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:283,columnNumber:17},this),toStr:C,setToStr:M,ccStr:S,setCcStr:D,subject:f,setSubject:A,bodyHtml:j,setBodyHtml:J,missingPlaceholders:oe,attachments:se,ccPlaceholder:"agent@example.com",bookingCode:h},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:281,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:192,columnNumber:9},this),e.jsxDEV(We,{className:"flex flex-row justify-between sm:justify-between",children:[e.jsxDEV("div",{children:n===2&&e.jsxDEV(v,{variant:"ghost",onClick:()=>u(1),disabled:Q.isPending||F.isPending,children:[e.jsxDEV(oo,{className:"h-4 w-4 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:304,columnNumber:17},this)," Back"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:303,columnNumber:15},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:301,columnNumber:11},this),e.jsxDEV("div",{className:"flex gap-2",children:[e.jsxDEV(v,{variant:"outline",onClick:()=>i(!1),disabled:F.isPending,children:"Cancel"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:309,columnNumber:13},this),n===1&&e.jsxDEV(v,{onClick:()=>Q.mutate(),disabled:!b||Q.isPending,title:b?void 0:"Pick a template first",children:[Q.isPending?"Rendering…":"Compose"," ",e.jsxDEV(yo,{className:"h-4 w-4 ml-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:318,columnNumber:66},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:313,columnNumber:15},this),n===2&&e.jsxDEV(v,{onClick:()=>F.mutate(),disabled:F.isPending||!C.trim()||!f.trim(),children:[e.jsxDEV(rr,{className:"h-4 w-4 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:323,columnNumber:17},this)," ",F.isPending?"Sending…":"Send"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:322,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:308,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:300,columnNumber:9},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:181,columnNumber:7},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/bookings/SendVoucherDialog.tsx",lineNumber:180,columnNumber:5},this)}function Yo(o){return o?o.replace(/^(?:\s*(?:re|fw|fwd)\s*:\s*)+/i,"").trim().toLowerCase():""}function Go(o){const i=new Map,g=n=>{let u=n;for(;i.get(u)&&i.get(u)!==u;)u=i.get(u);let b=n;for(;i.get(b)&&i.get(b)!==u;){const y=i.get(b);i.set(b,u),b=y}return u},h=(n,u)=>{const b=g(n),y=g(u);b!==y&&i.set(b,y)},t=n=>{i.has(n)||i.set(n,n)};for(const n of o){const u=n.message_id||`row:${n.id}`;if(t(u),n.in_reply_to&&(t(n.in_reply_to),h(u,n.in_reply_to)),n.references_chain)for(const b of n.references_chain.split(/\s+/).filter(Boolean))t(b),h(u,b)}const d=new Map;for(const n of o){const u=n.message_id||`row:${n.id}`,b=g(u),y=Yo(n.subject),O=`${b}||${y}`,U=d.get(O);U?U.push(n):d.set(O,[n])}const N=[],x=n=>{const u=or(n);return u?u.getTime():0};for(const[n,u]of d){u.sort((y,O)=>x(y.received_at)-x(O.received_at));const b=u[u.length-1];N.push({thread_id:n,messages:u,latest:b,has_unread:u.some(y=>!y.is_read),has_unlinked:u.some(y=>!y.booking_id&&!y.booking_code)})}return N.sort((n,u)=>x(u.latest.received_at)-x(n.latest.received_at)),N}async function k(o,i){const g=localStorage.getItem("platform_token"),t=await(await fetch(o,{headers:{"Content-Type":"application/json",...g?{Authorization:`Bearer ${g}`}:{}},...i})).json();if(t.error)throw new Error(t.error.message||t.error);return t.data}const jr={customer:{label:"Customer",color:"bg-blue-100 text-blue-800 border-blue-200"},supplier:{label:"Supplier",color:"bg-violet-100 text-violet-800 border-violet-200"},internal:{label:"Internal",color:"bg-gray-100 text-gray-700 border-gray-200"},unknown:{label:"Unknown",color:"bg-amber-100 text-amber-800 border-amber-200"}};function or(o){if(!o)return null;if(o instanceof Date)return isNaN(o.getTime())?null:o;let i=String(o).trim();if(!i)return null;/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?(\.\d+)?$/.test(i)?i=i.replace(" ","T")+"Z":/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?$/.test(i)&&(i+="Z");const g=new Date(i);return isNaN(g.getTime())?null:g}function ko(o){const i=or(o);if(!i)return"";const g=new Date;return i.getFullYear()===g.getFullYear()&&i.getMonth()===g.getMonth()&&i.getDate()===g.getDate()?pe(i,"HH:mm"):Math.abs(g.getTime()-i.getTime())<24*60*60*1e3?pe(i,"HH:mm"):i.getFullYear()===g.getFullYear()?pe(i,"dd MMM"):pe(i,"dd MMM yyyy")}function Ur(o){const i=or(o);return i?pe(i,"dd MMM yyyy HH:mm"):""}function Fo({bookingCodeFilter:o,hideStats:i=!1,participant:g,onParticipantChange:h}){var yr,hr,xr;const{toast:t}=Xe(),d=Yr(),[N,x]=c.useState(""),[n,u]=c.useState("all"),[b,y]=c.useState(!1),[O,U]=c.useState("all"),Y=g??O,q=r=>{h?h(r):U(r)},[C,M]=c.useState("inbox"),[S,D]=c.useState("all"),[f,A]=c.useState(null),[j,J]=c.useState(null),[oe,X]=c.useState(new Set),ie=c.useRef(null),w=Lo(ie),ee=c.useMemo(()=>{var p,P;if(!w)return null;const r=window.getSelection();if(!r||r.rangeCount===0)return null;let s=r.getRangeAt(0).startContainer;for(;s&&s.nodeType!==Node.ELEMENT_NODE;)s=s.parentNode;let l=s;for(;l&&!((p=l.dataset)!=null&&p.bookingCode);)l=l.parentElement;return((P=l==null?void 0:l.dataset)==null?void 0:P.bookingCode)||null},[w]),[L,$]=c.useState(null),[Q,F]=c.useState(!1),Le=r=>{X(s=>{const l=new Set(s);return l.has(r)?l.delete(r):l.add(r),l})};c.useEffect(()=>{if(!j){X(new Set);return}f&&X(new Set([f]))},[j]);const{data:E}=K({queryKey:["emails-stats"],queryFn:()=>k("/rest/v1/emails/stats"),refetchInterval:3e4,enabled:!i}),{data:se=[],refetch:Pe,isFetching:le}=K({queryKey:["emails",n,b,N,o,S,Y,C],queryFn:async()=>{const r=new URLSearchParams;return o&&r.set("booking_code",o),!o&&n!=="all"&&r.set("category",n),b&&r.set("unlinked","true"),S!=="all"&&r.set("inbox_id",S),C==="archived"?r.set("archived","true"):C==="all"&&r.set("archived","all"),N.trim()&&r.set("q",N.trim()),o&&Y&&Y!=="all"&&r.set("participant",Y),r.set("limit","200"),k(`/rest/v1/emails?${r.toString()}`)},refetchInterval:3e4}),{data:a=[]}=K({queryKey:["email-inboxes-summary"],queryFn:()=>k("/api/email-inboxes"),staleTime:6e4}),Z=async()=>{const r=a.filter(p=>p.is_active);if(!r.length){t({title:"No active inbox",description:"Add one in Settings → Inbox and enable it.",variant:"destructive"});return}let s=0,l=0;for(const p of r)try{const P=await k(`/api/email-inboxes/${p.id}/poll`,{method:"POST",body:JSON.stringify({})});s+=P.ingested||0}catch(P){l++,t({variant:"destructive",title:`Poll failed: ${p.name}`,description:P.message})}t({title:"Poll complete",description:`${s} new email(s) · ${l} error(s)`}),d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["emails-stats"]}),Pe()},re=T({mutationFn:async()=>k("/rest/v1/emails/reclassify-all?only=unknown",{method:"POST",body:JSON.stringify({})}),onSuccess:r=>{t({title:"Re-classified",description:`${r.processed} email(s) scanned · ${r.updated} updated.`}),d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["emails-stats"]})},onError:r=>t({variant:"destructive",title:"Re-classify failed",description:r.message})}),V=T({mutationFn:async()=>k("/rest/v1/emails/rethread",{method:"POST",body:JSON.stringify({})}),onSuccess:r=>{t({title:"Threads rebuilt",description:`${r.updated} / ${r.total} emails re-grouped.`}),d.invalidateQueries({queryKey:["emails"]})},onError:r=>t({variant:"destructive",title:"Re-thread failed",description:r.message})}),{data:m}=K({queryKey:["email-detail",f],queryFn:()=>k(`/rest/v1/emails/${f}`),enabled:!!f}),{data:je=[]}=K({queryKey:["email-thread",f],queryFn:()=>k(`/rest/v1/emails/${f}/thread`),enabled:!!f,staleTime:3e4}),he=je,Ue=T({mutationFn:async r=>k(`/rest/v1/emails/${r.id}`,{method:"PATCH",body:JSON.stringify(r.flags)}),onSuccess:(r,s)=>{d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["email-detail",s.id]}),d.invalidateQueries({queryKey:["emails-stats"]})}}),ir=T({mutationFn:async r=>k(`/rest/v1/emails/${r}/reclassify`,{method:"POST",body:JSON.stringify({})}),onSuccess:(r,s)=>{t({title:"Re-classified",description:"Email re-matched against current supplier rules."}),d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["email-detail",s]})},onError:r=>t({variant:"destructive",title:"Failed",description:r.message})}),sr=T({mutationFn:async r=>so(r),onSuccess:(r,s)=>{t({title:"Linked from AI suggestion",description:"Email is now attached to the booking."}),d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["email-detail",s]}),d.invalidateQueries({queryKey:["emails-stats"]})},onError:r=>t({variant:"destructive",title:"Confirm failed",description:r.message})}),lr=T({mutationFn:async r=>lo(r),onSuccess:(r,s)=>{d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["email-detail",s]})},onError:r=>t({variant:"destructive",title:"Dismiss failed",description:r.message})}),qr=T({mutationFn:async r=>k(`/rest/v1/emails/${r.id}/unlink`,{method:"POST",body:JSON.stringify(r.type?{type:r.type}:{})}),onSuccess:(r,s)=>{t({title:"Unlinked"}),d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["email-detail",s.id]})}}),[Mr,xe]=c.useState(!1),[Ye,nr]=c.useState(""),[tr,ar]=c.useState(""),[mr,Ge]=c.useState(""),[ke,ge]=c.useState(""),[Ne,wr]=c.useState(""),[R,_r]=c.useState(null),[Ie,cr]=c.useState(!0),[ur,qe]=c.useState(""),{data:Me=[]}=K({queryKey:["email-templates","reply-picker"],queryFn:()=>Ir({active_only:!0}),staleTime:6e4}),Tr=r=>{if(qe(r),!r||!m)return;const s=Me.find(p=>p.id===r);if(!s)return;const l=Vo(m);Ge(Pr(s.subject,l)),ge(Pr(s.body,l))},we=r=>r.replace(/[<>&]/g,s=>({"<":"&lt;",">":"&gt;","&":"&amp;"})[s]),Rr=r=>{if(!r)return"";const s=r.split(`
`),l=[];let p=!1;for(const P of s){const H=P.startsWith(">");H&&!p&&(l.push('<blockquote style="border-left:3px solid #cbd5e1;padding-left:12px;color:#475569;margin:8px 0">'),p=!0),!H&&p&&(l.push("</blockquote>"),p=!1);const G=H?P.replace(/^>\s?/,""):P;l.push(G.trim()===""?"<br>":`<p style="margin:0 0 8px">${we(G)}</p>`)}return p&&l.push("</blockquote>"),l.join(`
`)},br=r=>{nr(r.from_email||""),ar((r.cc_emails||[]).join(", ")),Ge(r.subject&&!/^re:/i.test(r.subject)?`Re: ${r.subject}`:r.subject||""),ge("<p><br></p>");const s=Ur(r.received_at),l=r.from_name||r.from_email||"the sender",p=Array.isArray(r.to_emails)?r.to_emails.join(", "):"";wr(r.body_html||Rr(r.body_text||"")),_r({from:l,date:s,to:p}),cr(!0),qe(""),xe(!0)},$r=()=>{const r=[];R!=null&&R.date&&r.push(`On ${we(R.date)}`),R!=null&&R.from&&r.push(we(R.from));const s=r.length?`<p style="color:#475569;font-size:13px;margin:16px 0 8px">${r.join(", ")} wrote:</p>`:"",l=Ie&&Ne?`<hr style="border:none;border-top:1px solid #e2e8f0;margin:16px 0"/>${s}<div style="border-left:3px solid #cbd5e1;padding-left:12px;color:#334155">${Ne}</div>`:"";return`${ke}${l}`},_e=T({mutationFn:async r=>{const s=Ye.split(",").map(p=>p.trim()).filter(Boolean),l=tr.split(",").map(p=>p.trim()).filter(Boolean);return k("/rest/v1/emails/send",{method:"POST",body:JSON.stringify({to:s,cc:l,subject:mr,body_html:$r(),reply_to_email_id:r.emailId})})},onSuccess:()=>{t({title:"Reply sent",description:"It will show up in the thread."}),xe(!1),ge(""),d.invalidateQueries({queryKey:["emails"]})},onError:r=>t({variant:"destructive",title:"Send failed",description:r.message})}),[dr,Te]=c.useState(!1),[ne,Sr]=c.useState(""),{data:pr=[]}=K({queryKey:["link-booking-search",ne],enabled:dr&&ne.trim().length>=3,queryFn:async()=>{var p;const r=localStorage.getItem("platform_token"),l=await(await fetch(`/api/easygds/bookings?per_page=10&search_text=${encodeURIComponent(ne)}`,{headers:{Authorization:`Bearer ${r}`}})).json();return((p=l.data)==null?void 0:p.result)||l.data||[]}}),Fr=T({mutationFn:async r=>k(`/rest/v1/emails/${r.emailId}/link`,{method:"POST",body:JSON.stringify({booking_id:r.booking_id,booking_code:r.booking_code,category:"customer"})}),onSuccess:(r,s)=>{t({title:"Linked to booking",description:s.booking_code}),d.invalidateQueries({queryKey:["emails"]}),d.invalidateQueries({queryKey:["email-detail",s.emailId]}),Te(!1),Sr("")},onError:r=>t({variant:"destructive",title:"Link failed",description:r.message})}),W=(r,s,l)=>e.jsxDEV(ze,{children:e.jsxDEV(Ce,{className:"p-3",children:[e.jsxDEV("div",{className:`text-2xl font-bold ${l}`,children:s??"—"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:675,columnNumber:9},this),e.jsxDEV("div",{className:"text-xs text-gray-600",children:r},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:676,columnNumber:9},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:674,columnNumber:7},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:673,columnNumber:5},this);return e.jsxDEV("div",{className:"space-y-4",children:[!i&&e.jsxDEV("div",{className:"grid grid-cols-2 md:grid-cols-7 gap-2",children:[W("Total",E==null?void 0:E.total,"text-gray-900"),W("Today",E==null?void 0:E.today,"text-blue-700"),W("Unread",E==null?void 0:E.unread,"text-amber-700"),W("Unlinked",E==null?void 0:E.unlinked,"text-red-700"),W("Customer",(yr=E==null?void 0:E.by_category)==null?void 0:yr.customer,"text-blue-700"),W("Supplier",(hr=E==null?void 0:E.by_category)==null?void 0:hr.supplier,"text-violet-700"),W("Unknown",(xr=E==null?void 0:E.by_category)==null?void 0:xr.unknown,"text-amber-700")]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:685,columnNumber:9},this),e.jsxDEV("div",{className:"grid grid-cols-12 gap-4 h-[calc(100vh-340px)] min-h-[540px]",children:[e.jsxDEV(ze,{className:"col-span-12 md:col-span-5 flex flex-col",children:[e.jsxDEV(vr,{className:"p-3 shrink-0 space-y-2 border-b",children:[e.jsxDEV(Or,{className:"text-sm flex items-center gap-2",children:[e.jsxDEV(ve,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:702,columnNumber:15},this)," Inbox",e.jsxDEV(z,{variant:"outline",className:"text-[10px] ml-auto",children:se.length},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:703,columnNumber:15},this),!i&&e.jsxDEV(e.Fragment,{children:[e.jsxDEV(v,{size:"sm",variant:"outline",onClick:Z,disabled:le,children:[e.jsxDEV(no,{className:`h-3 w-3 mr-1 ${le?"animate-spin":""}`},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:707,columnNumber:21},this)," Poll"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:706,columnNumber:19},this),e.jsxDEV(v,{size:"sm",variant:"outline",onClick:()=>re.mutate(),disabled:re.isPending,title:"Re-run supplier + extraction rules on all unknown emails",children:[e.jsxDEV(Oe,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:711,columnNumber:21},this)," Re-classify"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:709,columnNumber:19},this),e.jsxDEV(v,{size:"sm",variant:"outline",onClick:()=>V.mutate(),disabled:V.isPending,title:"Recompute conversation grouping on every email (one-shot, idempotent)",children:[e.jsxDEV(ve,{className:`h-3 w-3 mr-1 ${V.isPending?"animate-pulse":""}`},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:715,columnNumber:21},this),V.isPending?"Re-threading…":"Re-thread"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:713,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:705,columnNumber:17},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:701,columnNumber:13},this),e.jsxDEV("div",{className:"relative",children:[e.jsxDEV(to,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-gray-400"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:722,columnNumber:15},this),e.jsxDEV(ce,{className:"pl-7 h-8 text-sm",placeholder:"Search subject / sender…",value:N,onChange:r=>x(r.target.value)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:723,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:721,columnNumber:13},this),e.jsxDEV("div",{className:"flex items-center gap-2 flex-wrap",children:[o&&e.jsxDEV("div",{className:"inline-flex rounded-md border bg-background p-0.5 text-xs",role:"tablist",children:["all","supplier","customer"].map(r=>e.jsxDEV("button",{type:"button",onClick:()=>q(r),className:`px-2 py-1 rounded ${Y===r?"bg-orange-500 text-white":"text-muted-foreground hover:bg-accent"}`,children:r==="all"?"All":r==="supplier"?"Supplier":"Customer"},r,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:733,columnNumber:21},this))},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:731,columnNumber:17},this),!o&&e.jsxDEV(ue,{value:n,onValueChange:u,children:[e.jsxDEV(be,{className:"h-7 text-xs w-32",children:e.jsxDEV(de,{},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:751,columnNumber:63},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:751,columnNumber:19},this),e.jsxDEV(Se,{children:[e.jsxDEV(I,{value:"all",children:"All categories"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:753,columnNumber:21},this),e.jsxDEV(I,{value:"customer",children:"Customer"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:754,columnNumber:21},this),e.jsxDEV(I,{value:"supplier",children:"Supplier"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:755,columnNumber:21},this),e.jsxDEV(I,{value:"internal",children:"Internal"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:756,columnNumber:21},this),e.jsxDEV(I,{value:"unknown",children:"Unknown"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:757,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:752,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:750,columnNumber:17},this),!o&&e.jsxDEV(ue,{value:C,onValueChange:r=>M(r),children:[e.jsxDEV(be,{className:"h-7 text-xs w-28",children:e.jsxDEV(de,{},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:767,columnNumber:63},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:767,columnNumber:19},this),e.jsxDEV(Se,{children:[e.jsxDEV(I,{value:"inbox",children:"Inbox"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:769,columnNumber:21},this),e.jsxDEV(I,{value:"archived",children:"Archived"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:770,columnNumber:21},this),e.jsxDEV(I,{value:"all",children:"All"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:771,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:768,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:766,columnNumber:17},this),a.length>1&&e.jsxDEV(ue,{value:S,onValueChange:D,children:[e.jsxDEV(be,{className:"h-7 text-xs w-40",children:e.jsxDEV(de,{placeholder:"All inboxes"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:783,columnNumber:21},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:782,columnNumber:19},this),e.jsxDEV(Se,{children:[e.jsxDEV(I,{value:"all",children:["All inboxes (",a.length,")"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:786,columnNumber:21},this),a.map(r=>e.jsxDEV(I,{value:r.id,children:[r.name,r.is_active?"":" (inactive)"]},r.id,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:788,columnNumber:23},this)),e.jsxDEV(I,{value:"unknown",children:"— Legacy / no inbox"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:792,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:785,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:781,columnNumber:17},this),e.jsxDEV("label",{className:"flex items-center gap-1 text-xs",children:[e.jsxDEV("input",{type:"checkbox",checked:b,onChange:r=>y(r.target.checked)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:797,columnNumber:17},this),e.jsxDEV(Lr,{className:"h-3 w-3"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:798,columnNumber:17},this)," Unlinked only"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:796,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:725,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:700,columnNumber:11},this),e.jsxDEV(Ce,{className:"p-0 flex-1 overflow-y-auto",children:[se.length===0&&e.jsxDEV("div",{className:"p-6 text-center text-sm text-muted-foreground",children:[e.jsxDEV(ao,{className:"h-8 w-8 mx-auto mb-2 opacity-50"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:805,columnNumber:17},this),e.jsxDEV("p",{children:"No emails yet."},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:806,columnNumber:17},this),e.jsxDEV("p",{className:"text-xs mt-1",children:["Make sure you have an ",e.jsxDEV("strong",{children:"active inbox"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:808,columnNumber:41},this)," in Settings → Inbox, or click ",e.jsxDEV("strong",{children:"Poll"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:809,columnNumber:28},this)," to trigger one manually."]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:807,columnNumber:17},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:804,columnNumber:15},this),(()=>{const r=Go(se);return e.jsxDEV("ul",{className:"divide-y",children:r.map(s=>{const l=s.latest,p=jr[l.category]||jr.unknown,P=s.thread_id===j,H=s.messages.length;return e.jsxDEV("li",{className:`p-2.5 cursor-pointer ${P?"bg-blue-50 border-l-4 border-blue-500":"hover:bg-gray-50"} ${s.has_unread?"font-medium":""}`,onClick:()=>{J(s.thread_id),A(l.id);for(const G of s.messages)G.is_read||Ue.mutate({id:G.id,flags:{is_read:!0}})},children:[e.jsxDEV("div",{className:"flex items-start gap-2",children:[e.jsxDEV(z,{variant:"outline",className:`text-[9px] ${p.color}`,children:p.label},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:837,columnNumber:27},this),H>1&&e.jsxDEV(z,{variant:"outline",className:"text-[9px] bg-slate-100 text-slate-700 border-slate-300",children:[H," messages"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:839,columnNumber:29},this),l.booking_code&&e.jsxDEV(z,{variant:"outline",className:"text-[9px] bg-emerald-50 text-emerald-800 border-emerald-200",children:[e.jsxDEV(Ve,{className:"h-2.5 w-2.5 mr-0.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:845,columnNumber:31},this),l.booking_code]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:844,columnNumber:29},this),l.inbox_name&&e.jsxDEV(z,{variant:"outline",className:"text-[9px] bg-indigo-50 text-indigo-700 border-indigo-200",title:`Fetched from ${l.inbox_name}`,children:[e.jsxDEV(ve,{className:"h-2.5 w-2.5 mr-0.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:857,columnNumber:31},this),l.inbox_name]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:855,columnNumber:29},this),!!l.is_starred&&e.jsxDEV(Cr,{className:"h-3 w-3 text-amber-500 fill-amber-400"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:860,columnNumber:51},this),e.jsxDEV("span",{className:"text-[10px] text-muted-foreground ml-auto",children:ko(l.received_at)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:861,columnNumber:27},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:836,columnNumber:25},this),e.jsxDEV("div",{className:"text-sm truncate mt-0.5",children:l.subject||"(no subject)"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:865,columnNumber:25},this),e.jsxDEV("div",{className:"text-xs text-muted-foreground truncate",children:(()=>{const G=Array.from(new Set(s.messages.map(te=>te.from_name||te.from_email).filter(Boolean)));return G.length===1?G[0]:G.length>1?`${G[0]} · ${G.length} participants`:"(unknown sender)"})()},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:866,columnNumber:25},this),l.snippet&&e.jsxDEV("div",{className:"text-[10px] text-gray-400 truncate mt-0.5 font-normal",children:l.snippet},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:879,columnNumber:44},this)]},s.thread_id,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:826,columnNumber:23},this)})},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:819,columnNumber:17},this)})()]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:802,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:699,columnNumber:9},this),e.jsxDEV(ze,{className:"col-span-12 md:col-span-7 flex flex-col",children:m?e.jsxDEV(e.Fragment,{children:[e.jsxDEV(vr,{className:"p-3 shrink-0 border-b space-y-2",children:[e.jsxDEV(Or,{className:"text-base pr-2 flex items-center gap-2",children:[e.jsxDEV("span",{className:"flex-1 truncate",children:m.subject||"(no subject)"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:901,columnNumber:19},this),he.length>1&&e.jsxDEV(z,{variant:"outline",className:"text-[10px] bg-slate-100 text-slate-700 border-slate-300 shrink-0",children:[e.jsxDEV(ve,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:904,columnNumber:23},this)," ",he.length," messages"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:903,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:900,columnNumber:17},this),e.jsxDEV("div",{className:"flex items-center gap-1 flex-wrap",children:[m.supplier_id&&e.jsxDEV(z,{variant:"outline",className:"text-[10px] bg-violet-50 text-violet-800 border-violet-200",children:[e.jsxDEV(mo,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:912,columnNumber:23},this)," ",m.supplier_id]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:911,columnNumber:21},this),m.booking_code?e.jsxDEV("a",{href:`/bookings/${m.booking_code}`,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] bg-emerald-50 text-emerald-800 border border-emerald-200 px-1.5 py-0.5 rounded hover:bg-emerald-100",children:[e.jsxDEV(Ve,{className:"h-3 w-3"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:918,columnNumber:23},this)," ",m.booking_code," ",e.jsxDEV(co,{className:"h-2.5 w-2.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:918,columnNumber:77},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:916,columnNumber:21},this):e.jsxDEV(z,{variant:"outline",className:"text-[10px] bg-amber-50 text-amber-800 border-amber-200",children:[e.jsxDEV(er,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:922,columnNumber:23},this)," Unlinked"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:921,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:909,columnNumber:17},this),e.jsxDEV("div",{className:"flex items-center gap-1 flex-wrap pt-1",children:[e.jsxDEV(v,{size:"sm",onClick:()=>br(m),children:[e.jsxDEV(Ar,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:930,columnNumber:21},this)," Reply"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:929,columnNumber:19},this),e.jsxDEV(Ke,{open:dr,onOpenChange:Te,children:[e.jsxDEV(uo,{asChild:!0,children:e.jsxDEV(v,{size:"sm",variant:"outline",children:[e.jsxDEV(Ve,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:935,columnNumber:25},this)," Link to booking"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:934,columnNumber:23},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:933,columnNumber:21},this),e.jsxDEV(Be,{className:"max-w-lg",children:[e.jsxDEV(Qe,{children:[e.jsxDEV(Je,{children:"Link email to a booking"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:940,columnNumber:25},this),e.jsxDEV(Ze,{children:"Search by booking code, passenger name, or email — pick from the matches below."},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:941,columnNumber:25},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:939,columnNumber:23},this),e.jsxDEV("div",{className:"space-y-2",children:[e.jsxDEV(ce,{autoFocus:!0,placeholder:"e.g. DEMOS202302200 or contact email…",value:ne,onChange:r=>Sr(r.target.value)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:944,columnNumber:25},this),e.jsxDEV("div",{className:"max-h-80 overflow-y-auto border rounded",children:ne.trim().length<3?e.jsxDEV("p",{className:"text-xs text-muted-foreground p-3",children:"Type at least 3 characters to search."},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:948,columnNumber:29},this):pr.length===0?e.jsxDEV("p",{className:"text-xs text-muted-foreground p-3",children:"No bookings match."},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:950,columnNumber:29},this):e.jsxDEV("ul",{className:"divide-y",children:pr.map(r=>{var s,l,p;return e.jsxDEV("li",{className:"p-2 flex items-center gap-2 hover:bg-gray-50",children:[e.jsxDEV("div",{className:"flex-1 min-w-0",children:[e.jsxDEV("div",{className:"text-sm font-medium",children:r.code},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:956,columnNumber:37},this),e.jsxDEV("div",{className:"text-[10px] text-muted-foreground truncate",children:[(s=r.contact)==null?void 0:s.first_name," ",(l=r.contact)==null?void 0:l.last_name," · ",(p=r.contact)==null?void 0:p.email]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:957,columnNumber:37},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:955,columnNumber:35},this),e.jsxDEV(v,{size:"sm",onClick:()=>Fr.mutate({emailId:m.id,booking_id:r.id,booking_code:r.code}),children:"Link"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:961,columnNumber:35},this)]},r.id,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:954,columnNumber:33},this)})},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:952,columnNumber:29},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:946,columnNumber:25},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:943,columnNumber:23},this),e.jsxDEV(We,{children:e.jsxDEV(v,{variant:"outline",onClick:()=>Te(!1),children:"Cancel"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:971,columnNumber:25},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:970,columnNumber:23},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:938,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:932,columnNumber:19},this),m.booking_id&&e.jsxDEV(v,{size:"sm",variant:"outline",onClick:()=>qr.mutate({id:m.id,type:"booking"}),children:[e.jsxDEV(Lr,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:978,columnNumber:23},this)," Unlink booking"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:977,columnNumber:21},this),e.jsxDEV(v,{size:"sm",variant:"outline",onClick:()=>ir.mutate(m.id),disabled:ir.isPending,children:[e.jsxDEV(Oe,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:983,columnNumber:21},this)," Re-classify"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:982,columnNumber:19},this),e.jsxDEV(v,{size:"sm",variant:"ghost",onClick:()=>Ue.mutate({id:m.id,flags:{is_starred:!m.is_starred}}),children:e.jsxDEV(Cr,{className:`h-3.5 w-3.5 ${m.is_starred?"fill-amber-400 text-amber-500":"text-gray-400"}`},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:987,columnNumber:21},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:986,columnNumber:19},this),e.jsxDEV(v,{size:"sm",variant:"ghost",title:m.is_archived?"Unarchive (move back to inbox)":"Archive (hide from inbox)",onClick:()=>{const r=!m.is_archived;Ue.mutate({id:m.id,flags:{is_archived:r}},{onSuccess:()=>{t({title:r?"Email archived":"Email restored",description:r?'Hidden from the Inbox view. Switch the dropdown to "Archived" to find it.':"Moved back to the Inbox."}),(r&&C==="inbox"||!r&&C==="archived")&&A(null)},onError:s=>t({variant:"destructive",title:"Archive failed",description:s.message})})},children:e.jsxDEV(vo,{className:`h-3.5 w-3.5 ${m.is_archived?"text-orange-500":""}`},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1021,columnNumber:21},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:990,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:928,columnNumber:17},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:899,columnNumber:15},this),e.jsxDEV(Ce,{ref:ie,className:"p-3 flex-1 overflow-y-auto space-y-2 bg-slate-50",children:he.map((r,s)=>{const l=s===he.length-1,p=oe.has(r.id),P=r.direction==="outbound",H=Ur(r.received_at),G=r.from_name||r.from_email||"Unknown sender",te=r.body_html?{__html:ho(r.body_html)}:null,Re=Array.isArray(r.attachments)?r.attachments:[],De=r.parsed_data;return e.jsxDEV("div",{className:`rounded-lg border bg-white shadow-sm ${l?"ring-1 ring-blue-200":""}`,children:[e.jsxDEV("button",{type:"button",onClick:()=>Le(r.id),className:"w-full flex items-start gap-2 p-3 text-left hover:bg-slate-50 rounded-t-lg",children:[p?e.jsxDEV(bo,{className:"h-4 w-4 text-slate-400 mt-0.5 shrink-0"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1054,columnNumber:29},this):e.jsxDEV(Gr,{className:"h-4 w-4 text-slate-400 mt-0.5 shrink-0"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1055,columnNumber:29},this),e.jsxDEV("div",{className:`h-7 w-7 rounded-full shrink-0 flex items-center justify-center text-xs font-semibold ${P?"bg-blue-100 text-blue-700":"bg-slate-100 text-slate-700"}`,children:G.charAt(0).toUpperCase()},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1056,columnNumber:25},this),e.jsxDEV("div",{className:"flex-1 min-w-0",children:[e.jsxDEV("div",{className:"flex items-center gap-2",children:[e.jsxDEV("span",{className:"text-sm font-medium truncate",children:G},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1063,columnNumber:29},this),P&&e.jsxDEV(z,{variant:"outline",className:"text-[9px] bg-blue-50 text-blue-700 border-blue-200",children:"Sent"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1065,columnNumber:31},this),r.booking_code&&e.jsxDEV(z,{variant:"outline",className:"text-[9px] bg-emerald-50 text-emerald-800 border-emerald-200",children:[e.jsxDEV(Ve,{className:"h-2.5 w-2.5 mr-0.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1071,columnNumber:33},this),r.booking_code]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1070,columnNumber:31},this),e.jsxDEV("span",{className:"text-[11px] text-muted-foreground ml-auto shrink-0",children:H},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1074,columnNumber:29},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1062,columnNumber:27},this),!p&&r.snippet&&e.jsxDEV("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:r.snippet},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1079,columnNumber:29},this),p&&e.jsxDEV("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:[P?"to":"from"," ",r.from_email||"",r.to_emails&&Array.isArray(r.to_emails)&&r.to_emails.length>0&&e.jsxDEV(e.Fragment,{children:[" · to ",r.to_emails.join(", ")]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1085,columnNumber:33},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1082,columnNumber:29},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1061,columnNumber:25},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1048,columnNumber:23},this),p&&e.jsxDEV("div",{className:"px-3 pb-3 space-y-3 border-t",children:[De&&typeof De=="object"&&Object.keys(De).length>0&&e.jsxDEV("div",{className:"pt-3 text-[10px] text-muted-foreground flex items-center gap-2 flex-wrap",children:[e.jsxDEV(So,{className:"h-3 w-3 text-emerald-600"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1098,columnNumber:31},this)," Extracted:",Object.entries(De).map(([_,fe])=>e.jsxDEV("span",{children:[e.jsxDEV("code",{className:"font-mono bg-gray-100 px-1 rounded",children:_},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1101,columnNumber:35},this),": ",e.jsxDEV("strong",{children:fe},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1102,columnNumber:37},this)]},_,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1100,columnNumber:33},this))]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1097,columnNumber:29},this),Re.length>0&&e.jsxDEV("div",{className:"border rounded-md p-2 space-y-1 bg-slate-50",children:[e.jsxDEV("div",{className:"text-xs font-medium text-gray-600 flex items-center gap-1",children:[e.jsxDEV(Vr,{className:"h-3 w-3"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1112,columnNumber:33},this)," ",Re.length," attachment(s)"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1111,columnNumber:31},this),e.jsxDEV("ul",{className:"divide-y divide-gray-200",children:Re.map(_=>{const fe=(_.mime_type||"").startsWith("image/"),gr=(_.mime_type||"")==="application/pdf",zr=fe?xo:gr?He:Vr,Nr=_.size_bytes?(Number(_.size_bytes)/1024).toFixed(1)+" KB":"",Ee=localStorage.getItem("platform_token"),Kr=async()=>{const ae=await fetch(`/rest/v1/email-attachments/${_.id}/download`,{headers:Ee?{Authorization:`Bearer ${Ee}`}:{}});if(!ae.ok){t({variant:"destructive",title:"Download failed"});return}const $e=await ae.blob(),me=URL.createObjectURL($e),Fe=document.createElement("a");Fe.href=me,Fe.download=_.filename||"attachment",Fe.click(),setTimeout(()=>URL.revokeObjectURL(me),1e3)},Br=async()=>{const ae=await fetch(`/rest/v1/email-attachments/${_.id}/download`,{headers:Ee?{Authorization:`Bearer ${Ee}`}:{}});if(!ae.ok){t({variant:"destructive",title:"Preview failed"});return}const $e=await ae.blob(),me=URL.createObjectURL($e);window.open(me,"_blank"),setTimeout(()=>URL.revokeObjectURL(me),3e4)};return e.jsxDEV("li",{className:"flex items-center gap-2 py-1.5 text-xs",children:[e.jsxDEV(zr,{className:"h-3.5 w-3.5 text-gray-500 shrink-0"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1146,columnNumber:39},this),e.jsxDEV("span",{className:"flex-1 truncate",children:_.filename},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1147,columnNumber:39},this),Nr&&e.jsxDEV("span",{className:"text-[10px] text-gray-400",children:Nr},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1148,columnNumber:46},this),(fe||gr)&&e.jsxDEV(v,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:Br,children:"Preview"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1150,columnNumber:41},this),e.jsxDEV(v,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:Kr,children:[e.jsxDEV(Eo,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1155,columnNumber:41},this)," Download"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1154,columnNumber:39},this)]},_.id,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1145,columnNumber:37},this)})},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1114,columnNumber:31},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1110,columnNumber:29},this),r.ai_suggested_booking_code&&!r.booking_code&&e.jsxDEV("div",{className:"mb-3 rounded-lg border border-purple-200 bg-purple-50 px-3 py-2 flex items-start gap-2",children:[e.jsxDEV(Oe,{className:"h-4 w-4 text-purple-600 mt-0.5 shrink-0"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1172,columnNumber:31},this),e.jsxDEV("div",{className:"flex-1 min-w-0",children:[e.jsxDEV("div",{className:"text-xs font-semibold text-purple-900",children:["AI suggests linking to ",e.jsxDEV("span",{className:"font-mono",children:r.ai_suggested_booking_code},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1175,columnNumber:58},this),r.ai_confidence!=null&&e.jsxDEV("span",{className:"ml-2 text-purple-700 font-normal",children:["(",Math.round(Number(r.ai_confidence)*100),"% confident)"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1177,columnNumber:37},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1174,columnNumber:33},this),r.ai_reason&&e.jsxDEV("div",{className:"text-[11px] text-purple-800 mt-0.5",children:r.ai_reason},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1183,columnNumber:35},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1173,columnNumber:31},this),e.jsxDEV("div",{className:"flex gap-1 shrink-0",children:[e.jsxDEV(v,{size:"sm",className:"h-7 px-2 bg-purple-600 hover:bg-purple-700 text-white text-xs",disabled:sr.isPending,onClick:()=>sr.mutate(r.id),children:"Confirm link"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1189,columnNumber:33},this),e.jsxDEV(v,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs text-purple-700 hover:bg-purple-100",disabled:lr.isPending,onClick:()=>lr.mutate(r.id),children:"Dismiss"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1197,columnNumber:33},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1188,columnNumber:31},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1171,columnNumber:29},this),Number(r.ai_classified)===1&&r.booking_code&&r.ai_confidence!=null&&Number(r.ai_confidence)>=.85&&e.jsxDEV("div",{className:"mb-2 inline-flex items-center gap-1.5 rounded-full bg-purple-100 text-purple-800 text-[10px] font-medium px-2 py-0.5",children:[e.jsxDEV(Oe,{className:"h-2.5 w-2.5"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1217,columnNumber:31},this),"AI auto-linked · ",Math.round(Number(r.ai_confidence)*100),"% confident"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1216,columnNumber:29},this),te?e.jsxDEV("div",{"data-booking-code":r.booking_code||"","data-message-id":r.id,className:"prose prose-sm max-w-none",dangerouslySetInnerHTML:te},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1228,columnNumber:29},this):r.body_text?e.jsxDEV("pre",{"data-booking-code":r.booking_code||"","data-message-id":r.id,className:"whitespace-pre-wrap text-sm font-mono",children:r.body_text},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1235,columnNumber:29},this):e.jsxDEV("div",{className:"text-xs text-muted-foreground italic",children:"Loading message…"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1241,columnNumber:29},this),e.jsxDEV("div",{className:"flex items-center gap-2 pt-1",children:e.jsxDEV(v,{size:"sm",variant:"outline",onClick:()=>br(r),children:[e.jsxDEV(Ar,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1249,columnNumber:31},this)," Reply to this"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1248,columnNumber:29},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1247,columnNumber:27},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1094,columnNumber:25},this)]},r.id,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1046,columnNumber:21},this)})},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1026,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:898,columnNumber:13},this):e.jsxDEV(Ce,{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Select an email on the left."},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:894,columnNumber:13},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:892,columnNumber:9},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:697,columnNumber:7},this),e.jsxDEV(Ke,{open:Mr,onOpenChange:xe,children:e.jsxDEV(Be,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxDEV(Qe,{children:[e.jsxDEV(Je,{children:"Reply"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1268,columnNumber:13},this),e.jsxDEV(Ze,{children:"Sends via the default SMTP account (Settings → SMTP). The reply is threaded via the original Message-ID so it appears in-thread for the recipient."},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1269,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1267,columnNumber:11},this),e.jsxDEV("div",{className:"space-y-2",children:[Me.length>0&&e.jsxDEV("div",{children:[e.jsxDEV(B,{className:"text-xs",children:"Template"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1277,columnNumber:17},this),e.jsxDEV("div",{className:"flex gap-2 items-center",children:[e.jsxDEV(ue,{value:ur,onValueChange:Tr,children:[e.jsxDEV(be,{className:"flex-1",children:e.jsxDEV(de,{placeholder:"Start from a template…"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1281,columnNumber:23},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1280,columnNumber:21},this),e.jsxDEV(Se,{children:Me.map(r=>e.jsxDEV(I,{value:r.id,children:e.jsxDEV("span",{className:"inline-flex items-center gap-2",children:[e.jsxDEV("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:r.template_type},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1287,columnNumber:29},this),e.jsxDEV("span",{children:r.name},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1288,columnNumber:29},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1286,columnNumber:27},this)},r.id,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1285,columnNumber:25},this))},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1283,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1279,columnNumber:19},this),ur&&e.jsxDEV(v,{variant:"ghost",size:"sm",className:"text-xs",onClick:()=>qe(""),children:"Clear"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1295,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1278,columnNumber:17},this),e.jsxDEV("p",{className:"text-[10px] text-muted-foreground mt-1",children:["Variables like ",e.jsxDEV("code",{className:"bg-gray-100 px-1 rounded",children:"{{customer_name}}"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1302,columnNumber:34},this),", ",e.jsxDEV("code",{className:"bg-gray-100 px-1 rounded",children:"{{booking_ref}}"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1302,columnNumber:107},this)," are filled from this email. Unknown placeholders stay visible so you can spot them."]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1301,columnNumber:17},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1276,columnNumber:15},this),e.jsxDEV("div",{children:[e.jsxDEV(B,{htmlFor:"rply-to",className:"text-xs",children:"To"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1307,columnNumber:15},this),e.jsxDEV(ce,{id:"rply-to",value:Ye,onChange:r=>nr(r.target.value),placeholder:"recipient@domain.com, another@domain.com"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1308,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1306,columnNumber:13},this),e.jsxDEV("div",{children:[e.jsxDEV(B,{htmlFor:"rply-cc",className:"text-xs",children:"Cc (optional)"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1312,columnNumber:15},this),e.jsxDEV(ce,{id:"rply-cc",value:tr,onChange:r=>ar(r.target.value)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1313,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1311,columnNumber:13},this),e.jsxDEV("div",{children:[e.jsxDEV(B,{htmlFor:"rply-subj",className:"text-xs",children:"Subject"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1316,columnNumber:15},this),e.jsxDEV(ce,{id:"rply-subj",value:mr,onChange:r=>Ge(r.target.value)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1317,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1315,columnNumber:13},this),e.jsxDEV("div",{children:[e.jsxDEV(B,{htmlFor:"rply-body",className:"text-xs",children:"Message"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1320,columnNumber:15},this),e.jsxDEV("div",{className:"mt-1",children:e.jsxDEV(go,{value:ke,onChange:ge,minHeight:280,compact:!0,placeholder:"Type your reply…"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1322,columnNumber:17},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1321,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1319,columnNumber:13},this),Ne&&e.jsxDEV("div",{className:"rounded-md border bg-slate-50",children:[e.jsxDEV("div",{className:"flex items-center justify-between px-3 py-2 border-b",children:[e.jsxDEV("div",{className:"flex items-center gap-2 text-xs text-slate-700",children:[e.jsxDEV("input",{id:"include-original",type:"checkbox",className:"h-3.5 w-3.5",checked:Ie,onChange:r=>cr(r.target.checked)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1339,columnNumber:21},this),e.jsxDEV("label",{htmlFor:"include-original",className:"cursor-pointer select-none",children:"Include original message in reply"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1346,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1338,columnNumber:19},this),R&&e.jsxDEV("span",{className:"text-[11px] text-slate-500",children:["From ",R.from||"sender"," · ",R.date]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1351,columnNumber:21},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1337,columnNumber:17},this),Ie&&e.jsxDEV("iframe",{sandbox:"",title:"Original message preview",srcDoc:`<!doctype html><html><head><meta charset="utf-8"><base target="_blank"><style>body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;font-size:14px;color:#0f172a;margin:12px;line-height:1.5}img{max-width:100%;height:auto}a{color:#2563eb}</style></head><body>${Ne}</body></html>`,style:{width:"100%",height:"320px",border:"0",background:"white"}},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1357,columnNumber:19},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1336,columnNumber:15},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1274,columnNumber:11},this),e.jsxDEV(We,{children:[e.jsxDEV(v,{variant:"outline",onClick:()=>xe(!1),children:"Cancel"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1371,columnNumber:13},this),e.jsxDEV(v,{onClick:()=>m&&_e.mutate({emailId:m.id}),disabled:_e.isPending||!Ye.trim()||!ke.replace(/<p>\s*<br\s*\/?>\s*<\/p>/g,"").replace(/<[^>]+>/g,"").trim(),children:[e.jsxDEV(rr,{className:"h-3 w-3 mr-1"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1382,columnNumber:15},this),_e.isPending?"Sending…":"Send reply"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1372,columnNumber:13},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1370,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1266,columnNumber:9},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1265,columnNumber:7},this),w&&e.jsxDEV(jo,{selection:w,bookingCode:ee,customerEmail:(m==null?void 0:m.direction)==="outbound"?Array.isArray(m==null?void 0:m.to_emails)?m.to_emails[0]:null:(m==null?void 0:m.from_email)||null,customerName:(m==null?void 0:m.from_name)||null,onAssigned:r=>{if(r.kind!=="hotel"||!ee||!(m!=null&&m.booking_id))return;const s=m.direction==="outbound"?Array.isArray(m.to_emails)?m.to_emails[0]:null:m.from_email||null;$({bookingId:m.booking_id,bookingCode:ee,customerEmail:s,customerName:m.from_name||null})}},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1394,columnNumber:9},this),L&&!Q&&e.jsxDEV("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-50 bg-emerald-600 text-white rounded-full shadow-2xl px-4 py-2.5 flex items-center gap-3 text-sm animate-in fade-in slide-in-from-bottom-4 duration-300",children:[e.jsxDEV(kr,{className:"h-4 w-4 shrink-0"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1432,columnNumber:11},this),e.jsxDEV("span",{className:"whitespace-nowrap",children:["HCN assigned — send voucher to ",e.jsxDEV("strong",{children:L.customerName||L.customerEmail||"customer"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1434,columnNumber:44},this),"?"]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1433,columnNumber:11},this),e.jsxDEV(v,{size:"sm",variant:"secondary",className:"h-7 px-3 bg-white text-emerald-700 hover:bg-emerald-50 ml-1",onClick:()=>F(!0),children:"Send voucher"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1436,columnNumber:11},this),e.jsxDEV("button",{type:"button",onClick:()=>$(null),className:"text-white/70 hover:text-white p-1","aria-label":"Dismiss",children:e.jsxDEV(po,{className:"h-4 w-4"},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1450,columnNumber:13},this)},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1444,columnNumber:11},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1431,columnNumber:9},this),L&&Q&&e.jsxDEV(Uo,{open:Q,onOpenChange:r=>{F(r),r||$(null)},bookingId:L.bookingId,bookingCode:L.bookingCode,customerEmail:L.customerEmail,customerName:L.customerName,onSent:()=>{F(!1),$(null)}},void 0,!1,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:1459,columnNumber:9},this)]},void 0,!0,{fileName:"/Users/abanoubhelmy/Library/CloudStorage/OneDrive-Personal/EASYGDS/Operation System/trip-glide-control/src/components/emails/MySqlEmailInbox.tsx",lineNumber:682,columnNumber:5},this)}export{Ae as F,Fo as M,Uo as S,Oo as a};
