PageSourceSearch

https://evisas.io/assets/SustainabilityTab-D-NMtShe.js

js evisas.io collected 2026-10-04 02:57:22 UTC 90,964 bytes, 772 lines download raw bytes

1import{r as y,R as Q,j as e}from"./vendor-react-CuUun9aL.js";import{C as _,a as F,e as P,c as B}from"./card-khC1k9a2.js";import{s as ie,B as O,J as U}from"./index-CffYHF1C.js";import{T as ve,a as be,b as R,c as L}from"./tabs-tAXZLwp9.js";import{u as Be}from"./vendor-query-Ch735aT_.js";import{D as $e}from"./DateRangeFilter-DuXBFvsO.js";import{T as ne,a as le,b as V,c as C,d as oe,e as w}from"./table-Bf8kae7D.js";import{I as M}from"./input-Ccd_OHYE.js";import{B as Y}from"./badge-tBo3c1at.js";import{U as I,B as q,ai as re,i as ce,a$ as X,aN as Z,F as je,aO as Fe,bI as Pe,aA as Ne,aP as ye,b9 as Oe,X as _e,_ as we,aL as Ce,M as ae,a1 as xe,R as Se,ad as ze,G as ue,L as Ue,ao as Ee,ah as ee,P as Ie,b as ge,T as pe}from"./vendor-icons-9tdgZqZ8.js";import{D as Re,a as Le,b as Ve,c as Me}from"./dialog-C-hTN1bv.js";import{C as Ye}from"./companyProfileService-BgTvD9cH.js";import{L as se}from"./label-BaKeqYGc.js";import{T as qe}from"./textarea-CHbjQrep.js";import{S as Te,a as Ae,b as ke,c as De,d as K}from"./select-BaOXAfxm.js";import{D as G,a as He}from"./DataSourceIndicator-CnUso5xz.js";import{s as We}from"./supplierVisaPricingService-BScd2IUA.js";import{S as he}from"./skeleton-CsY_my8R.js";import{f as te}from"./currency-CifnWf-V.js";import{u as Ge}from"./vendor-router-CIKCSSKp.js";import{T as Xe}from"./TechLoader-Cf6kryw6.js";import"./vendor-supabase-V01cKGWO.js";import"./vendor-radix-DHc79Ej6.js";import"./calendar-Bb432Ybw.js";import"./vendor-date-BqJAPjTW.js";import"./popover-Bf6khzEE.js";import"./supabaseProxy-B-2nsjjj.js";const Je=(i,o,a={})=>{const{enabled:r=!0,refetchOnMount:x=!1}=a;return Be({queryKey:["sustainability-data",i,o],queryFn:async()=>{const t={p_start_date:i||null,p_end_date:o||null},[d,c,h,l]=await Promise.all([ie.rpc("get_customer_profitability_data",t),ie.rpc("get_supplier_profit_data",t),ie.rpc("get_visa_profit_by_country",t),ie.rpc("get_agent_discount_summary",t)]);if(d.error)throw console.error("Error fetching customer profitability data:",d.error),d.error;if(c.error)throw console.error("Error fetching supplier profit data:",c.error),c.error;if(h.error)throw console.error("Error fetching visa country data:",h.error),h.error;if(l.error)throw console.error("Error fetching agent discount data:",l.error),l.error;const u=d.data,p=c.data,S=h.data,b=l.data;let A={total_revenue:0,total_cost:0,net_profit:0,profit_margin:0,total_applications:0,avg_profit_per_application:0};if(u&&u.length>0){const s=u.reduce((N,E)=>({revenue:N.revenue+(Number(E.revenue)||0),cost:N.cost+(Number(E.cost)||0),applications:N.applications+(Number(E.total_applications)||0)}),{revenue:0,cost:0,applications:0});A={total_revenue:s.revenue,total_cost:s.cost,net_profit:s.revenue-s.cost,profit_margin:s.revenue>0?(s.revenue-s.cost)/s.revenue*100:0,total_applications:s.applications,avg_profit_per_application:s.applications>0?(s.revenue-s.cost)/s.applications:0}}const j=(u==null?void 0:u.map(s=>({user_id:s.user_id,customer_name:s.customer_name||"Unknown Customer",customer_type:s.customer_type||"Individual (B2C)",total_applications:Number(s.total_applications)||0,total_passengers:Number(s.total_passengers)||0,revenue:Number(s.revenue)||0,cost:Number(s.cost)||0,profit:Number(s.profit)||0,profit_percentage:Number(s.profit_percentage)||0,avg_profit_per_application:Number(s.avg_profit_per_application)||0,partner_id:s.partner_id||null})))||[],m=(S==null?void 0:S.map(s=>{var N;return{country:s.country,country_code:((N=s.country)==null?void 0:N.toLowerCase().replace(/\s+/g,"_"))||"",total_applications:Number(s.applications)||0,total_revenue:Number(s.revenue)||0,total_cost:Number(s.cost)||0,net_profit:Number(s.profit)||0,profit_percentage:Number(s.profit_percentage)||0,avg_profit_per_application:Number(s.applications)>0?Number(s.profit)/Number(s.applications):0}}))||[],v=(b==null?void 0:b.map(s=>(console.log("Processing agent discount data:",s),{agent_id:s.partner_id||"",agent_name:s.partner_name||"Unknown Partner",total_applications:Number(s.total_applications)||0,unique_customers:Number(s.unique_customers)||0,discount_given:Number(s.discount_given)||0,profit_left_after_discount:Number(s.profit_left_after_discount)||0,avg_discount_per_application:Number(s.avg_discount_per_application)||0})))||[];console.log("Processed agent discount data:",v);const k={customerProfitability:j,supplierProfit:p||[],overallProfitSummary:A,visaProfitByCountry:m,agentDiscountSummary:v,smartOfferCandidates:j.filter(s=>{const N=s.customer_type.includes("B2B")||s.customer_type.includes("Business"),E=s.total_applications>=(N?3:2),T=s.profit>(N?500:100);return E||T})};return console.log("Final sustainability data result:",k),k},enabled:r,refetchOnMount:x,refetchOnWindowFocus:!1,staleTime:r?0:1/0,gcTime:10*60*1e3})},Ke=({data:i,isLoading:o})=>{const[a,r]=y.useState(""),[x,t]=y.useState("profit"),[d,c]=y.useState("desc"),[h,l]=y.useState("all"),u=Q.useMemo(()=>{let s=i.filter(N=>{const E=N.customer_name.toLowerCase().includes(a.toLowerCase()),T=h==="all"||h==="b2b"&&N.customer_type.includes("B2B")||h==="b2c"&&N.customer_type.includes("B2C");return E&&T});return s.sort((N,E)=>{const T=N[x],H=E[x];if(typeof T=="string"&&typeof H=="string")return d==="asc"?T.localeCompare(H):H.localeCompare(T);const J=Number(T),n=Number(H);return d==="asc"?J-n:n-J}),s},[i,a,x,d,h]),p=s=>{x===s?c(d==="asc"?"desc":"asc"):(t(s),c("desc"))},S=s=>new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:2,maximumFractionDigits:2}).format(s),b=s=>s.includes("B2B")?q:re,A=s=>{const N=s.includes("B2B");return e.jsxs(Y,{variant:N?"default":"secondary",className:"flex items-center gap-1",children:[Q.createElement(b(s),{className:"h-3 w-3"}),N?"B2B":"B2C"]})},j=i.filter(s=>s.customer_type.includes("B2B")),m=i.filter(s=>s.customer_type.includes("B2C")),v=j.reduce((s,N)=>s+N.revenue,0),k=m.reduce((s,N)=>s+N.revenue,0);return o?e.jsxs(_,{children:[e.jsx(F,{children:e.jsx(P,{children:"Customer Profitability Analysis"})}),e.jsx(B,{children:e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((s,N)=>e.jsx("div",{className:"h-12 bg-gray-100 animate-pulse rounded"},N))})})]}):e.jsxs(_,{children:[e.jsxs(F,{children:[e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5"}),"Customer Profitability Analysis"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mt-4",children:[e.jsxs("div",{className:"bg-blue-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-sm text-blue-600",children:"B2B Customers"})]}),e.jsxs("div",{className:"text-lg font-bold text-blue-700",children:[j.length," customers"]}),e.jsxs("div",{className:"text-sm text-blue-600",children:[S(v)," revenue"]})]}),e.jsxs("div",{className:"bg-green-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-sm text-green-600",children:"B2C Customers"})]}),e.jsxs("div",{className:"text-lg font-bold text-green-700",children:[m.length," customers"]}),e.jsxs("div",{className:"text-sm text-green-600",children:[S(k)," revenue"]})]}),e.jsxs("div",{className:"bg-purple-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"text-sm text-purple-600",children:"Total Passengers"})]}),e.jsx("div",{className:"text-lg font-bold text-purple-700",children:i.reduce((s,N)=>s+N.total_passengers,0)}),e.jsx("div",{className:"text-sm text-purple-600",children:"Across all applications"})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 justify-between",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(M,{placeholder:"Search customers...",value:a,onChange:s=>r(s.target.value),className:"pl-10"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1 text-sm rounded ${h==="all"?"bg-blue-500 text-white":"bg-gray-200"}`,children:"All"}),e.jsx("button",{onClick:()=>l("b2b"),className:`px-3 py-1 text-sm rounded ${h==="b2b"?"bg-blue-500 text-white":"bg-gray-200"}`,children:"B2B"}),e.jsx("button",{onClick:()=>l("b2c"),className:`px-3 py-1 text-sm rounded ${h==="b2c"?"bg-blue-500 text-white":"bg-gray-200"}`,children:"B2C"})]})]})]}),e.jsx(B,{children:e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs(ne,{children:[e.jsx(le,{children:e.jsxs(V,{children:[e.jsx(C,{onClick:()=>p("customer_name"),className:"cursor-pointer hover:bg-gray-50",children:"Customer Name"}),e.jsx(C,{children:"Type"}),e.jsx(C,{onClick:()=>p("total_applications"),className:"cursor-pointer hover:bg-gray-50",children:"Applications"}),e.jsx(C,{onClick:()=>p("total_passengers"),className:"cursor-pointer hover:bg-gray-50",children:"Passengers"}),e.jsx(C,{onClick:()=>p("revenue"),className:"cursor-pointer hover:bg-gray-50",children:"Revenue"}),e.jsx(C,{onClick:()=>p("cost"),className:"cursor-pointer hover:bg-gray-50",children:"Cost"}),e.jsx(C,{onClick:()=>p("profit"),className:"cursor-pointer hover:bg-gray-50",children:"Profit"}),e.jsx(C,{onClick:()=>p("profit_percentage"),className:"cursor-pointer hover:bg-gray-50",children:"Profit %"}),e.jsx(C,{onClick:()=>p("avg_profit_per_application"),className:"cursor-pointer hover:bg-gray-50",children:"Avg Profit/App"})]})}),e.jsx(oe,{children:u.map(s=>e.jsxs(V,{children:[e.jsx(w,{className:"font-medium",children:s.customer_name}),e.jsx(w,{children:A(s.customer_type)}),e.jsx(w,{children:s.total_applications}),e.jsx(w,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(I,{className:"h-4 w-4 text-gray-400"}),s.total_passengers]})}),e.jsx(w,{children:S(s.revenue)}),e.jsx(w,{className:"text-muted-foreground",children:S(s.cost)}),e.jsx(w,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[s.profit>=0?e.jsx(X,{className:"h-4 w-4 text-green-500"}):e.jsx(Z,{className:"h-4 w-4 text-red-500"}),e.jsx("span",{className:s.profit>=0?"text-green-600":"text-red-600",children:S(s.profit)})]})}),e.jsx(w,{children:e.jsxs("span",{className:s.profit_percentage>=0?"text-green-600":"text-red-600",children:[s.profit_percentage.toFixed(1),"%"]})}),e.jsx(w,{children:S(s.avg_profit_per_application)})]}
1,s.user_id))})]}),u.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500",children:"No customer data found"}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Revenue includes wallet + gateway + processing fees per the split-payment rule. Excludes draft & cancelled applications."})]})})]})},Qe=({data:i,isLoading:o})=>{const[a,r]=y.useState(""),[x,t]=y.useState("net_profit"),[d,c]=y.useState("desc"),h=Q.useMemo(()=>{let p=i.filter(S=>S.supplier_name.toLowerCase().includes(a.toLowerCase()));return p.sort((S,b)=>{const A=S[x],j=b[x];if(typeof A=="string"&&typeof j=="string")return d==="asc"?A.localeCompare(j):j.localeCompare(A);const m=Number(A),v=Number(j);return d==="asc"?m-v:v-m}),p},[i,a,x,d]),l=p=>{x===p?c(d==="asc"?"desc":"asc"):(t(p),c("desc"))},u=p=>new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0,maximumFractionDigits:0}).format(p);return o?e.jsxs(_,{children:[e.jsx(F,{children:e.jsx(P,{children:"Supplier Profit Analysis"})}),e.jsx(B,{children:e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((p,S)=>e.jsx("div",{className:"h-12 bg-gray-100 animate-pulse rounded"},S))})})]}):e.jsxs(_,{children:[e.jsxs(F,{children:[e.jsx(P,{children:"Supplier Profit Analysis"}),e.jsxs("div",{className:"relative",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(M,{placeholder:"Search suppliers...",value:a,onChange:p=>r(p.target.value),className:"pl-10"})]})]}),e.jsx(B,{children:e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs(ne,{children:[e.jsx(le,{children:e.jsxs(V,{children:[e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("supplier_name"),children:"Supplier Name"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("total_applications"),children:"Applications"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("total_buy_cost"),children:"Total Buy Cost"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("total_sell_price"),children:"Total Sell Price"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("net_profit"),children:"Net Profit"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("profit_percentage"),children:"Profit %"})]})}),e.jsx(oe,{children:h.map(p=>e.jsxs(V,{children:[e.jsx(w,{className:"font-medium",children:p.supplier_name}),e.jsx(w,{children:p.total_applications}),e.jsx(w,{children:u(p.total_buy_cost)}),e.jsx(w,{children:u(p.total_sell_price)}),e.jsx(w,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[p.net_profit>=0?e.jsx(X,{className:"h-4 w-4 text-green-500"}):e.jsx(Z,{className:"h-4 w-4 text-red-500"}),e.jsx("span",{className:p.net_profit>=0?"text-green-600":"text-red-600",children:u(p.net_profit)})]})}),e.jsx(w,{children:e.jsxs("span",{className:p.profit_percentage>=0?"text-green-600":"text-red-600",children:[p.profit_percentage.toFixed(1),"%"]})})]},p.supplier_id))})]}),h.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500",children:"No supplier data found"})]})})]})},Ze=({data:i,isLoading:o})=>{const a=t=>new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0,maximumFractionDigits:0}).format(t),r=t=>new Intl.NumberFormat().format(t),x=[{title:"Total Applications",value:r(i.total_applications),icon:je,color:"text-blue-600",bgColor:"bg-blue-100",subtitle:"Visa applications processed"},{title:"Unique Customers",value:r(i.unique_customers),icon:I,color:"text-purple-600",bgColor:"bg-purple-100",subtitle:"Individual & business customers"},{title:"Total Revenue",value:a(i.revenue),icon:Fe,color:"text-green-600",bgColor:"bg-green-100",subtitle:"From all customer segments"},{title:"Total Cost",value:a(i.cost),icon:Pe,color:"text-orange-600",bgColor:"bg-orange-100",subtitle:"Supplier and operational costs"},{title:"Net Profit",value:a(i.net_profit),icon:X,color:i.net_profit>=0?"text-green-600":"text-red-600",bgColor:i.net_profit>=0?"bg-green-100":"bg-red-100",subtitle:`${(i.net_profit/i.revenue*100||0).toFixed(1)}% profit margin`},{title:"Avg Revenue/Customer",value:a(i.avg_revenue_per_customer),icon:Ne,color:"text-indigo-600",bgColor:"bg-indigo-100",subtitle:"Customer lifetime value"}];return o?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-6 gap-4",children:[...Array(6)].map((t,d)=>e.jsx(_,{className:"animate-pulse",children:e.jsx(B,{className:"p-6",children:e.jsx("div",{className:"h-20 bg-gray-100 rounded"})})},d))}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-6 gap-4",children:x.map((t,d)=>{const c=t.icon;return e.jsx(_,{className:"hover:shadow-md transition-shadow",children:e.jsx(B,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${t.bgColor}`,children:e.jsx(c,{className:`h-5 w-5 ${t.color}`})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:t.title}),e.jsx("p",{className:`text-xl font-bold ${t.color}`,children:t.value}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:t.subtitle})]})]})})})},d)})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mt-6",children:[e.jsx(_,{className:"bg-blue-50",children:e.jsxs(B,{className:"p-4",children:[e.jsx("h4",{className:"font-medium text-blue-800 mb-2",children:"Customer Efficiency"}),e.jsxs("p",{className:"text-sm text-blue-700",children:[i.unique_customers>0?(i.total_applications/i.unique_customers).toFixed(1):"0"," applications per customer"]})]})}),e.jsx(_,{className:"bg-green-50",children:e.jsxs(B,{className:"p-4",children:[e.jsx("h4",{className:"font-medium text-green-800 mb-2",children:"Profit Per Application"}),e.jsxs("p",{className:"text-sm text-green-700",children:[a(i.avg_profit_per_application)," average profit"]})]})}),e.jsx(_,{className:"bg-purple-50",children:e.jsxs(B,{className:"p-4",children:[e.jsx("h4",{className:"font-medium text-purple-800 mb-2",children:"Total Passengers"}),e.jsxs("p",{className:"text-sm text-purple-700",children:[r(i.total_passengers||i.total_applications)," passengers"]}
1),e.jsx("p",{className:"text-xs text-purple-600 mt-1",children:"Across all applications"})]})}),e.jsx(_,{className:"bg-orange-50",children:e.jsxs(B,{className:"p-4",children:[e.jsx("h4",{className:"font-medium text-orange-800 mb-2",children:"Customer Acquisition"}),e.jsx("p",{className:"text-sm text-orange-700",children:"Focus on expanding customer base and retention"})]})})]})]})},es=({data:i,isLoading:o})=>{const[a,r]=y.useState(""),[x,t]=y.useState("profit"),[d,c]=y.useState("desc"),h=Q.useMemo(()=>{let b=i.filter(A=>A.country.toLowerCase().includes(a.toLowerCase()));return b.sort((A,j)=>{const m=A[x],v=j[x];if(typeof m=="string"&&typeof v=="string")return d==="asc"?m.localeCompare(v):v.localeCompare(m);const k=Number(m),s=Number(v);return d==="asc"?k-s:s-k}),b},[i,a,x,d]),l=b=>{x===b?c(d==="asc"?"desc":"asc"):(t(b),c("desc"))},u=b=>new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0,maximumFractionDigits:0}).format(b),p=()=>{const b=["Country","Applications","Revenue","Cost","Profit","Profit %"],A=h.map(s=>[s.country,s.applications.toString(),s.revenue.toString(),s.cost.toString(),s.profit.toString(),s.profit_percentage.toFixed(2)]),j=[b,...A].map(s=>s.join(",")).join(`
2`),m=new Blob([j],{type:"text/csv"}),v=window.URL.createObjectURL(m),k=document.createElement("a");k.href=v,k.download="visa-profit-by-country.csv",k.click(),window.URL.revokeObjectURL(v),U.success("Export completed successfully!")},S=()=>{U.success("PDF export functionality will be implemented!")};return o?e.jsxs(_,{children:[e.jsx(F,{children:e.jsx(P,{children:"Visa Profit by Country"})}),e.jsx(B,{children:e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((b,A)=>e.jsx("div",{className:"h-12 bg-gray-100 animate-pulse rounded"},A))})})]}):e.jsxs(_,{children:[e.jsxs(F,{children:[e.jsx(P,{children:"Visa Profit by Country"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 justify-between",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(M,{placeholder:"Search countries...",value:a,onChange:b=>r(b.target.value),className:"pl-10"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(O,{variant:"outline",size:"sm",onClick:p,children:[e.jsx(ye,{className:"h-4 w-4 mr-1"}),"CSV"]}),e.jsxs(O,{variant:"outline",size:"sm",onClick:S,children:[e.jsx(je,{className:"h-4 w-4 mr-1"}),"PDF"]})]})]})]}),e.jsx(B,{children:e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs(ne,{children:[e.jsx(le,{children:e.jsxs(V,{children:[e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("country"),children:"Country"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("applications"),children:"Applications"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("revenue"),children:"Revenue"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("cost"),children:"Cost"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("profit"),children:"Profit"}),e.jsx(C,{className:"cursor-pointer hover:bg-gray-50",onClick:()=>l("profit_percentage"),children:"Profit %"})]})}),e.jsx(oe,{children:h.map(b=>e.jsxs(V,{children:[e.jsx(w,{className:"font-medium",children:b.country}),e.jsx(w,{children:b.applications}),e.jsx(w,{children:u(b.revenue)}),e.jsx(w,{children:u(b.cost)}),e.jsx(w,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[b.profit>=0?e.jsx(X,{className:"h-4 w-4 text-green-500"}):e.jsx(Z,{className:"h-4 w-4 text-red-500"}),e.jsx("span",{className:b.profit>=0?"text-green-600":"text-red-600",children:u(b.profit)})]})}),e.jsx(w,{children:e.jsxs("span",{className:b.profit_percentage>=0?"text-green-600":"text-red-600",children:[b.profit_percentage.toFixed(1),"%"]})})]},b.country))})]}),h.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500",children:"No country data found"})]})})]})},ss=({data:i,isLoading:o})=>{const[a,r]=y.useState(""),[x,t]=y.useState("discount_given"),[d,c]=y.useState("desc"),h=Q.useMemo(()=>
2{if(!i||i.length===0)return[];let m=i.filter(v=>v.agent_name&&v.agent_name.toLowerCase().includes(a.toLowerCase()));return m.sort((v,k)=>{const s=v[x],N=k[x];if(typeof s=="string"&&typeof N=="string")return d==="asc"?s.localeCompare(N):N.localeCompare(s);const E=Number(s)||0,T=Number(N)||0;return d==="asc"?E-T:T-E}),m},[i,a,x,d]),l=m=>{x===m?c(d==="asc"?"desc":"asc"):(t(m),c("desc"))},u=m=>new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0,maximumFractionDigits:0}).format(m||0),p=i||[],S=p.reduce((m,v)=>m+(Number(v.discount_given)||0),0),b=p.reduce((m,v)=>m+(Number(v.profit_left_after_discount)||0),0),A=p.reduce((m,v)=>m+(Number(v.total_applications)||0),0),j=p.reduce((m,v)=>m+(Number(v.unique_customers)||0),0);return o?e.jsxs(_,{children:[e.jsx(F,{children:e.jsx(P,{children:"Business Partner Discount Summary"})}),e.jsx(B,{children:e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((m,v)=>e.jsx("div",{className:"h-12 bg-gray-100 animate-pulse rounded"},v))})})]}):e.jsxs(_,{children:[e.jsxs(F,{children:[e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5"}),"Business Partner Discount Summary"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mt-4",children:[e.jsxs("div",{className:"bg-red-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4 text-red-500"}),e.jsx("span",{className:"text-sm text-red-600",children:"Total Discounts Given"})]}),e.jsx("div",{className:"text-lg font-bold text-red-700",children:u(S)}),e.jsxs("div",{className:"text-xs text-red-600",children:["Across ",A," applications"]})]}),e.jsxs("div",{className:"bg-green-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4 text-green-500 rotate-180"}),e.jsx("span",{className:"text-sm text-green-600",children:"Profit After Discounts"})]}),e.jsx("div",{className:"text-lg font-bold text-green-700",children:u(b)}),e.jsx("div",{className:"text-xs text-green-600",children:"Net profit retained"})]}),e.jsxs("div",{className:"bg-blue-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-sm text-blue-600",children:"Active Partners"})]}),e.jsx("div",{className:"text-lg font-bold text-blue-700",children:p.length}),e.jsx("div",{className:"text-xs text-blue-600",children:"Business partners"})]}),e.jsxs("div",{className:"bg-purple-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"text-sm text-purple-600",children:"Unique Customers"})]}),e.jsx("div",{className:"text-lg font-bold text-purple-700",children:j}),e.jsx("div",{className:"text-xs text-purple-600",children:"Served by partners"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(M,{placeholder:"Search business partners...",value:a,onChange:m=>r(m.target.value),className:"pl-10"})]})]}),e.jsx(B,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ne,{children:[e.jsx(le,{children:e.jsxs(V,{children:[e.jsx(C,{onClick:()=>l("agent_name"),className:"cursor-pointer hover:bg-gray-50",children:"Partner Name"}),e.jsx(C,{onClick:()=>l("total_applications"),className:"cursor-pointer hover:bg-gray-50",children:"Applications"}),e.jsx(C,{onClick:()=>l("unique_customers"),className:"cursor-pointer hover:bg-gray-50",children:"Unique Customers"}),e.jsx(C,{onClick:()=>l("discount_given"),className:"cursor-pointer hover:bg-gray-50",children:"Discount Given"}),e.jsx(C,{onClick:()=>l("profit_left_after_discount"),className:"cursor-pointer hover:bg-gray-50",children:"Profit Retained"}),e.jsx(C,{onClick:()=>l("avg_discount_per_application"),className:"cursor-pointer hover:bg-gray-50",children:"Avg Discount/App"}),e.jsx(C,{children:"Discount Impact"})]})}),e.jsx(oe,{children:h.length>0?h.map(m=>{const v=(Number(m.profit_left_after_discount)||0)+(Number(m.discount_given)||0),k=v>0?(Number(m.discount_given)||0)/v*100:0,s=(Number(m.unique_customers)||0)>0?(Number(m.total_applications)||0)/(Number(m.unique_customers)||0):0;return e.jsxs(V,{children:[e.jsx(w,{className:"font-medium",children:e.jsxs("div",{children:[e.jsx("div",{children:m.agent_name}),e.jsxs("div",{className:"text-xs text-gray-500",children:["ID: ",m.agent_id]})]})}),e.jsx(w,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Oe,{className:"h-4 w-4 text-gray-400"}),Number(m.total_applications)||0]})}),e.jsx(w,{children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(I,{className:"h-4 w-4 text-gray-400"}),Number(m.unique_customers)||0]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[s.toFixed(1)," apps/customer"]})]})}),e.jsx(w,{children:e.jsx("span",{className:"text-red-600 font-medium",children:u(Number(m.discount_given)||0)})}),e.jsx(w,{children:e.jsx("span",{className:"text-green-600 font-medium",children:u(Number(m.profit_left_after_discount)||0)})}),e.jsx(w,{children:e.jsx("span",{className:"text-orange-600",children:u(Number(m.avg_discount_per_application)||0)})}),e.jsx(w,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 bg-gray-200 rounded-full h-2",children:e.jsx("div",{className:"bg-red-500 h-2 rounded-full",style:{width:`${Math.min(k,100)}%`}})}),e.jsxs("span",{className:"text-sm text-gray-600 min-w-[3rem]",children:[k.toFixed(1),"%"]})]})})]},m.agent_id)}):e.jsx(V,{children:e.jsx(w,{colSpan:7,className:"text-center py-8 text-gray-500",children:"No business partner discount data found"})})})]})})})]})},ts=({initialValue:i,maxAmount:o,onSave:a,className:r=""})=>{const[x,t]=y.useState(!1),[d,c]=y.useState(i),h=()=>{const u=d.match(/(\d+(?:\.\d+)?)/),p=u?parseFloat(u[1]):0;if(p>o){U.error(`Offer amount cannot exceed AED ${o} (service charge limit)`);return}if(p<=0){U.error("Offer amount must be greater than 0");return}a(d),t(!1),U.success("Offer updated successfully")},l=()=>{c(i),t(!1)};return x?e.jsxs("div",{className:`flex items-center gap-2 ${r}`,children:[e.jsx(M,{value:d,onChange:u=>c(u.target.value),className:"flex-1 text-sm",placeholder:"Enter offer details..."}),e.jsx(O,{size:"sm",variant:"outline",onClick:h,children:e.jsx(_e,{className:"h-3 w-3"})}),e.jsx(O,{size:"sm",variant:"outline",onClick:l,children:e.jsx(we,{className:"h-3 w-3"})})]}):e.jsxs("div",{className:`flex items-center gap-2 ${r}`,children:[e.jsx("span",{className:"flex-1 text-sm",children:d}),e.jsx(O,{size:"sm",variant:"ghost",onClick:()=>t(!0),className:"h-6 w-6 p-0",children:e.jsx(Ce,{className:"h-3 w-3"})})]})},as=({initialValue:i,onSave:o,className:a=""})=>{const[r,x]=y.useState(!1),[t,d]=y.useState(i.toString()),c=()=>{const l=parseInt(t);if(isNaN(l)||l<=0){U.error("Application count must be a positive number");return}if(l>100){U.error("Application count cannot exceed 100");return}o(l),x(!1),U.success("Application count updated successfully")},h=()=>{d(i.toString()),x(!1)};return r?e.jsxs("div",{className:`flex items-center gap-2 ${a}
2`,children:[e.jsx(M,{type:"number",value:t,onChange:l=>d(l.target.value),className:"w-20 text-sm",min:"1",max:"100"}),e.jsx(O,{size:"sm",variant:"outline",onClick:c,children:e.jsx(_e,{className:"h-3 w-3"})}),e.jsx(O,{size:"sm",variant:"outline",onClick:h,children:e.jsx(we,{className:"h-3 w-3"})})]}):e.jsxs("div",{className:`flex items-center gap-2 ${a}`,children:[e.jsx("span",{className:"text-sm font-medium",children:i}),e.jsx(O,{size:"sm",variant:"ghost",onClick:()=>x(!0),className:"h-6 w-6 p-0",children:e.jsx(Ce,{className:"h-3 w-3"})})]})},is=({subject:i,setSubject:o,offerText:a,setOfferText:r,applicationCount:x,validUntil:t,setValidUntil:d,emailTemplate:c,onTemplateChange:h,customer:l})=>(l.customer_type.includes("B2B"),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(_,{children:[e.jsx(F,{children:e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-5 w-5"}),"Email Composition"]})}),e.jsxs(B,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(se,{htmlFor:"subject",children:"Email Subject"}),e.jsx(M,{id:"subject",value:i,onChange:u=>o(u.target.value),placeholder:"Enter email subject...",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(se,{htmlFor:"template",children:"Email Template"}),e.jsxs(Te,{value:c,onValueChange:h,children:[e.jsx(Ae,{className:"mt-1",children:e.jsx(ke,{})}),e.jsxs(De,{children:[e.jsx(K,{value:"b2b",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"B2B Partner Template"]})}),e.jsx(K,{value:"b2c",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4"}),"B2C Customer Template"]})}),e.jsx(K,{value:"promotional",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4"}),"Promotional Template"]})})]})]})]}),e.jsxs("div",{children:[e.jsx(se,{htmlFor:"offerText",children:"Offer Details"}),e.jsx(qe,{id:"offerText",value:a,onChange:u=>r(u.target.value),placeholder:"Enter offer details...",rows:3,className:"mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(se,{htmlFor:"applicationCount",children:"Application Count"}),e.jsx(M,{id:"applicationCount",type:"number",value:x,readOnly:!0,className:"mt-1 bg-gray-50"})]}),e.jsxs("div",{children:[e.jsx(se,{htmlFor:"validUntil",children:"Valid Until"}),e.jsx(M,{id:"validUntil",type:"date",value:t,onChange:u=>d(u.target.value),className:"mt-1"})]})]})]})]}),e.jsxs(_,{children:[e.jsx(F,{children:e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5"}),"Customer Information"]})}),e.jsx(B,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Customer Name:"}),e.jsx("div",{className:"font-medium",children:l.customer_name})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Customer Type:"}),e.jsx("div",{className:"font-medium",children:l.customer_type})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Total Applications:"}),e.jsx("div",{className:"font-medium",children:l.total_applications})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Total Profit:"}),e.jsx("div",{className:"font-medium text-green-600",children:new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0}).format(l.profit)})]})]})})]})]})),rs=({emailHtml:i,onRefreshPreview:o})=>e.jsxs(_,{className:"h-full",children:[e.jsx(F,{children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-5 w-5"}),"Email Preview"]}),e.jsxs(O,{onClick:o,size:"sm",variant:"outline",children:[e.jsx(Se,{className:"h-4 w-4 mr-2"}),"Refresh Preview"]})]})}),e.jsx(B,{children:e.jsx("div",{className:"border rounded-lg bg-white max-h-[600px] overflow-y-auto",children:i?e.jsx("div",{dangerouslySetInnerHTML:{__html:i}}):e.jsxs("div",{className:"p-8 text-center text-gray-500",children:[e.jsx(xe,{className:"h-12 w-12 mx-auto mb-3 text-gray-300"}),e.jsx("p",{children:"Email preview will appear here"}),e.jsx("p",{className:"text-sm",children:"Configure your offer details to see the preview"})]})})})]}
2),ns=({customer:i,emailTemplate:o,onTemplateChange:a,companyProfile:r})=>{const x=i.customer_type.includes("B2B");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(_,{children:[e.jsx(F,{children:e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-5 w-5"}),"Email Template Settings"]})}),e.jsxs(B,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Template Type"}),e.jsxs(Te,{value:o,onValueChange:a,children:[e.jsx(Ae,{className:"mt-1",children:e.jsx(ke,{})}),e.jsxs(De,{children:[e.jsx(K,{value:"b2b",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"B2B Partner Template"]})}),e.jsx(K,{value:"b2c",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4"}),"B2C Customer Template"]})}),e.jsx(K,{value:"promotional",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4"}),"Promotional Template"]})})]})]})]}),e.jsxs("div",{className:"bg-blue-50 p-4 rounded-lg",children:[e.jsx("h4",{className:"font-medium text-blue-800 mb-2",children:"Template Features"}),e.jsxs("div",{className:"space-y-2 text-sm text-blue-700",children:[o==="b2b"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"• Professional business-focused design"}),e.jsx("div",{children:"• Partnership benefits highlighted"}),e.jsx("div",{children:"• Volume discount emphasis"}),e.jsx("div",{children:"• Business relationship terminology"})]}),o==="b2c"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"• Consumer-friendly design"}),e.jsx("div",{children:"• Family and travel focus"}),e.jsx("div",{children:"• Personal savings emphasis"}),e.jsx("div",{children:"• Friendly customer language"})]}),o==="promotional"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"• Eye-catching promotional design"}),e.jsx("div",{children:"• Urgency and scarcity elements"}),e.jsx("div",{children:"• Bold call-to-action"}),e.jsx("div",{children:"• Marketing campaign style"})]})]})]})]})]}),e.jsxs(_,{children:[e.jsx(F,{children:e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5"}),"Company Branding"]})}),e.jsx(B,{children:r?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[r.logo_url&&e.jsx("img",{src:r.logo_url,alt:"Company Logo",className:"h-12 w-12 object-contain"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:r.company_name}),e.jsx("div",{className:"text-sm text-gray-600",children:r.email})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Phone:"}),e.jsx("div",{children:r.phone||"Not set"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Website:"}),e.jsx("div",{children:r.website||"Not set"})]})]}),r.address&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Address:"}),e.jsx("div",{children:r.address})]})]}):e.jsxs("div",{className:"text-center py-6 text-gray-500",children:[e.jsx(ue,{className:"h-8 w-8 mx-auto mb-2 text-gray-300"}),e.jsx("p",{children:"No company profile configured"}),e.jsx("p",{className:"text-sm",children:"Set up company profile for branded emails"})]})})]}),e.jsxs(_,{children:[e.jsx(F,{children:e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5"}),"Customer Analysis"]})}),e.jsx(B,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Customer Segment:"}),e.jsx(Y,{variant:x?"default":"secondary",children:x?"Business Partner":"Individual Customer"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Recommended Template:"}),e.jsx(Y,{variant:"outline",children:x?"B2B Partner":"B2C Customer"})]}),e.jsxs("div",{className:"bg-green-50 p-3 rounded-lg text-sm",children:[e.jsx("div",{className:"text-green-800 font-medium mb-1",children:"Personalization Applied:"}),e.jsxs("div",{className:"text-green-700",children:["• Customer name and type recognition",e.jsx("br",{}),"• Booking history integration",e.jsx("br",{}),"• Profit-based offer calculation",e.jsx("br",{}),"• Relationship status consideration"]})]})]})})]})]})},fe={generate(i){var u;const{customer:o,offerText:a,applicationCount:r,validUntil:x,companyProfile:t}=i,d=((u=a.match(/(\d+(?:\.\d+)?)\s*AED/))==null?void 0:u[1])||"50",c=(t==null?void 0:t.company_name)||"eVisas.io",h=(t==null?void 0:t.logo_url)||"",l=new Date(x).toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"});return`
3<!DOCTYPE html>
4<html lang="en">
5<head>
6    <meta charset="UTF-8">
7    <meta name="viewport" content="width=device-width, initial-scale=1.0">
8    <title>Exclusive Partner Offer</title>
9    <style>
10        * { margin: 0; padding: 0; box-sizing: border-box; }
11        body { 
12            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
13            line-height: 1.6; 
14            color: #333; 
15            background-color: #f8fafc;
16        }
17        .container { max-width: 600px; margin: 0 auto; background: white; }
18        .header { 
19            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); 
20            color: white; 
21            padding: 30px 20px; 
22            text-align: center; 
23        }
24        .logo { height: 60px; margin-bottom: 20px; }
25        .main-content { padding: 40px 30px; }
26        .offer-banner { 
27            background: linear-gradient(135deg, #10b981 0%, #059669 100%); 
28            color: white; 
29            padding: 25px; 
30            border-radius: 12px; 
31            text-align: center; 
32            margin: 30px 0; 
33            box-shadow: 0 8px 25px rgba(16, 185, 129, 0.3);
34        }
35        .discount-amount { 
36            font-size: 48px; 
37            font-weight: bold; 
38            margin: 10px 0; 
39            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
40        }
41        .partner-badge { 
42            background: #fbbf24; 
43            color: #92400e; 
44            padding: 8px 16px; 
45            border-radius: 20px; 
46            font-weight: bold; 
47            display: inline-block; 
48            margin: 20px 0;
49        }
50        .stats-grid { 
51            display: grid; 
52            grid-template-columns: repeat(2, 1fr); 
53            gap: 20px; 
54            margin: 30px 0; 
55        }
56        .stat-card { 
57            background: #f1f5f9; 
58            padding: 20px; 
59            border-radius: 8px; 
60            text-align: center; 
61            border-left: 4px solid #3b82f6;
62        }
63        .stat-number { font-size: 28px; font-weight: bold; color: #1e40af; }
64        .stat-label { font-size: 14px; color: #64748b; margin-top: 5px; }
65        .cta-button { 
66            background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%); 
67            color: white; 
68            padding: 18px 40px; 
69            border: none; 
70            border-radius: 8px; 
71            font-size: 18px; 
72            font-weight: bold; 
73            cursor: pointer; 
74            text-decoration: none; 
75            display: inline-block; 
76            margin: 20px 0; 
77            box-shadow: 0 4px 15px rgba(220, 38, 38, 0.3);
78            transition: transform 0.2s ease;
79        }
80        .cta-button:hover { transform: translateY(-2px); }
81        .urgency-banner { 
82            background: #fef3c7; 
83            border: 2px solid #f59e0b; 
84            color: #92400e; 
85            padding: 15px; 
86            border-radius: 8px; 
87            text-align: center; 
88            margin: 20px 0; 
89            font-weight: bold;
90        }
91        .benefits-list { 
92            background: #f0f9ff; 
93            padding: 25px; 
94            border-radius: 8px; 
95            margin: 20px 0; 
96            border-left: 4px solid #0ea5e9;
97        }
98        .benefits-list ul { list-style: none; }
99        .benefits-list li { 
100            padding: 8px 0; 
101            position: relative; 
102            padding-left: 25px;
103        }
104        .benefits-list li:before { 
105            content: '✓'; 
106            position: absolute; 
107            left: 0; 
108            color: #10b981; 
109            font-weight: bold; 
110            font-size: 16px;
111        }
112        .footer { 
113            background: #1f2937; 
114            color: #d1d5db; 
115            padding: 30px; 
116            text-align: center; 
117            font-size: 14px; 
118        }
119        .social-links { margin: 20px 0; }
120        .social-links a { 
121            color: #60a5fa; 
122            text-decoration: none; 
123            margin: 0 10px; 
124        }
125        @media (max-width: 600px) {
126            .stats-grid { grid-template-columns: 1fr; }
127            .discount-amount { font-size: 36px; }
128            .main-content { padding: 20px 15px; }
129        }
130    </style>
131</head>
132<body>
133    <div class="container">
134        <div class="header">
135            <img src="https://evisas.io/__l5e/assets-v1/2b052bed-a708-4eb2-8c6a-5e3f5a742cf5/sun-palm-trip.gif" alt="Exclusive offer" width="140" height="140" style="display:inline-block;width:140px;height:140px;max-width:140px;border:0;margin-bottom:16px;" />
136            ${h?`<img src="${h}" alt="${c}" class="logo">`:""}
137            <h1>Exclusive Partner Offer</h1>
138            <p>Specially crafted for our valued business partner</p>
139        </div>
140
141        <div class="main-content">
142            <div class="partner-badge">🏆 PREMIUM BUSINESS PARTNER</div>
143            
144            <h2>Dear ${o.customer_name},</h2>
145            
146            <p>As one of our most valued business partners, we're excited to present you with an exclusive offer designed to maximize your savings and streamline your visa application process.</p>
147
148            <div class="offer-banner">
149                <h3>EXCLUSIVE PARTNER DISCOUNT</h3>
150                <div class="discount-amount">${d} AED OFF</div>
151                <p>On your next ${r} visa applications</p>
152            </div>
153
154            <div class="urgency-banner">
155                ⏰ Limited Time Offer - Valid until ${l}
156            </div>
157
158            <div class="stats-grid">
159                <div class="stat-card">
160                    <div class="stat-number">${o.total_applications}</div>
161                    <div class="stat-label">Total Applications</div>
162                </div>
163                <div class="stat-card">
164                    <div class="stat-number">${new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0}).format(o.profit)}</div>
165                    <div class="stat-label">Partnership Value</div>
166                </div>
167            </div>
168
169            <div class="benefits-list">
170                <h3>🎯 Your Partner Benefits Include:</h3>
171                <ul>
172                    <li>Priority processing for all applications</li>
173                    <li>Dedicated partner support team</li>
174                    <li>Bulk application discounts</li>
175                    <li>Expedited document verification</li>
176                    <li>Custom reporting and analytics</li>
177                    <li>Flexible payment terms</li>
178                </ul>
179            </div>
180
181            <div style="text-align: center;">
182                <a href="#" class="cta-button">CLAIM YOUR PARTNER DISCOUNT</a>
183            </div>
184
185            <p><strong>How to redeem:</strong></p>
186            <ol style="margin: 20px 0; padding-left: 20px;">
187                <li>Contact your dedicated partner representative</li>
188                <li>Mention offer code: <strong>PARTNER${d}</strong></li>
189                <li>Submit your next ${r} applications</li>
190                <li>Enjoy immediate savings of ${d} AED</li>
191            </ol>
192
193            <p>This exclusive offer reflects our appreciation for your continued partnership and trust in ${c}. We look forward to serving your visa application needs with even greater value.</p>
194
195            <p>Best regards,<br>
196            <strong>The ${c} Partnership Team</strong></p>
197        </div>
198
199        <div class="footer">
200            <p><strong>${c}</strong></p>
201            ${t!=null&&t.address?`<p>${t.address}</p>`:""}
202            ${t!=null&&t.phone?`<p>Phone: ${t.phone}</p>`:""}
203            ${t!=null&&t.email?`<p>Email: ${t.email}</p>`:""}
204            ${t!=null&&t.website?`<p>Website: ${t.website}</p>`:""}
205            
206            <div class="social-links">
207                <a href="#">Privacy Policy</a> | 
208                <a href="#">Terms of Service</a> | 
209                <a href="#">Partner Portal</a>
210            </div>
211            
212            <p style="font-size: 12px; margin-top: 20px; color: #9ca3af;">
213                This offer is exclusively for ${o.customer_name} and expires on ${l}. 
214                Cannot be combined with other offers. Terms and conditions apply.
215            </p>
216        </div>
217    </div>
218</body>
219</html>`}},ls={generate(i){var u;const{customer:o,offerText:a,applicationCount:r,validUntil:x,companyProfile:t}=i,d=((u=a.match(/(\d+(?:\.\d+)?)\s*AED/))==null?void 0:u[1])||"50",c=(t==null?void 0:t.company_name)||"eVisas.io",h=(t==null?void 0:t.logo_url)||"",l=new Date(x).toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"});return`
220<!DOCTYPE html>
221<html lang="en">
222<head>
223    <meta charset="UTF-8">
224    <meta name="viewport" content="width=device-width, initial-scale=1.0">
225    <title>Special Travel Savings</title>
226    <style>
227        * { margin: 0; padding: 0; box-sizing: border-box; }
228        body { 
229            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
230            line-height: 1.6; 
231            color: #333; 
232            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
233        }
234        .container { max-width: 600px; margin: 20px auto; background: white; border-radius: 15px; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.1); }
235        .header { 
236            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); 
237            color: white; 
238            padding: 40px 30px; 
239            text-align: center; 
240            position: relative;
241        }
242        .header::before {
243            content: '';
244            position: absolute;
245            top: 0;
246            left: 0;
247            right: 0;
248            bottom: 0;
249            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 20"><defs><pattern id="plane" x="0" y="0" width="100" height="20" patternUnits="userSpaceOnUse"><text x="10" y="15" style="font-size:12px;fill:rgba(255,255,255,0.1)">✈</text></pattern></defs><rect width="100" height="20" fill="url(%23plane)"/></svg>') repeat;
250            opacity: 0.1;
251        }
252        .logo { height: 50px; margin-bottom: 15px; position: relative; z-index: 1; }
253        .main-content { padding: 40px 30px; }
254        .travel-banner { 
255            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%); 
256            color: white; 
257            padding: 30px; 
258            border-radius: 15px; 
259            text-align: center; 
260            margin: 30px 0; 
261            position: relative;
262            overflow: hidden;
263        }
264        .travel-banner::before {
265            content: '✈️';
266            position: absolute;
267            top: -10px;
268            right: -10px;
269            font-size: 100px;
270            opacity: 0.1;
271        }
272        .discount-amount { 
273            font-size: 54px; 
274            font-weight: bold; 
275            margin: 15px 0; 
276            text-shadow: 2px 2px 8px rgba(0,0,0,0.3);
277            position: relative;
278            z-index: 1;
279        }
280        .family-badge { 
281            background: #10b981; 
282            color: white; 
283            padding: 10px 20px; 
284            border-radius: 25px; 
285            font-weight: bold; 
286            display: inline-block; 
287            margin: 20px 0;
288        }
289        .savings-highlight { 
290            background: #fef3c7; 
291            border: 2px solid #f59e0b; 
292            color: #92400e; 
293            padding: 20px; 
294            border-radius: 12px; 
295            text-align: center; 
296            margin: 25px 0; 
297            font-weight: bold;
298        }
299        .travel-stats { 
300            display: grid; 
301            grid-template-columns: repeat(2, 1fr); 
302            gap: 20px; 
303            margin: 30px 0; 
304        }
305        .stat-card { 
306            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%); 
307            padding: 25px; 
308            border-radius: 15px; 
309            text-align: center;
310        }
311        .stat-number { font-size: 32px; font-weight: bold; color: #374151; }
312        .stat-label { font-size: 14px; color: #6b7280; margin-top: 8px; }
313        .cta-button { 
314            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%); 
315            color: white; 
316            padding: 20px 45px; 
317            border: none; 
318            border-radius: 50px; 
319            font-size: 18px; 
320            font-weight: bold; 
321            cursor: pointer; 
322            text-decoration: none; 
323            display: inline-block; 
324            margin: 25px 0; 
325            box-shadow: 0 8px 20px rgba(238, 90, 82, 0.3);
326            transition: all 0.3s ease;
327        }
328        .cta-button:hover { transform: translateY(-3px); box-shadow: 0 12px 25px rgba(238, 90, 82, 0.4); }
329        .travel-benefits { 
330            background: linear-gradient(135deg, #e0f2fe 0%, #f3e5f5 100%); 
331            padding: 30px; 
332            border-radius: 15px; 
333            margin: 25px 0;
334        }
335        .travel-benefits ul { list-style: none; }
336        .travel-benefits li { 
337            padding: 10px 0; 
338            position: relative; 
339            padding-left: 35px;
340            font-size: 16px;
341        }
342        .travel-benefits li:before { 
343            content: '🌟'; 
344            position: absolute; 
345            left: 0; 
346            font-size: 18px;
347        }
348        .family-section {
349            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
350            padding: 25px;
351            border-radius: 15px;
352            margin: 25px 0;
353            text-align: center;
354        }
355        .footer { 
356            background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%); 
357            color: #ecf0f1; 
358            padding: 40px 30px; 
359            text-align: center; 
360            font-size: 14px; 
361        }
362        .social-links { margin: 25px 0; }
363        .social-links a { 
364            color: #74b9ff; 
365            text-decoration: none; 
366            margin: 0 15px; 
367            font-weight: 500;
368        }
369        @media (max-width: 600px) {
370            .travel-stats { grid-template-columns: 1fr; }
371            .discount-amount { font-size: 42px; }
372            .main-content { padding: 25px 20px; }
373        }
374    </style>
375</head>
376<body>
377    <div class="container">
378        <div class="header">
379            <img src="https://evisas.io/__l5e/assets-v1/2b052bed-a708-4eb2-8c6a-5e3f5a742cf5/sun-palm-trip.gif" alt="Your next trip awaits" width="140" height="140" style="display:inline-block;width:140px;height:140px;max-width:140px;border:0;margin-bottom:16px;position:relative;z-index:1;" />
380            ${h?`<img src="${h}" alt="${c}" class="logo">`:""}
381            <h1>🎉 Special Travel Savings Just for You!</h1>
382            <p>Your next adventure awaits with incredible savings</p>
383        </div>
384
385        <div class="main-content">
386            <div class="family-badge">🏠 VALUED CUSTOMER</div>
387            
388            <h2>Hello ${o.customer_name}!</h2>
389            
390            <p>We've noticed your love for travel and wanted to reward your loyalty with an exclusive discount that will make your next journey even more exciting!</p>
391
392            <div class="travel-banner">
393                <h3>🎯 YOUR EXCLUSIVE TRAVEL DISCOUNT</h3>
394                <div class="discount-amount">${d} AED OFF</div>
395                <p>On your next ${r} visa application${r>1?"s":""}</p>
396            </div>
397
398            <div class="savings-highlight">
399                ⏰ Limited Time Offer - Save big until ${l}!
400            </div>
401
402            <div class="travel-stats">
403                <div class="stat-card">
404                    <div class="stat-number">${o.total_applications}</div>
405                    <div class="stat-label">Trips Planned</div>
406                </div>
407                <div class="stat-card">
408                    <div class="stat-number">${o.total_passengers}</div>
409                    <div class="stat-label">Travelers Served</div>
410                </div>
411            </div>
412
413            <div class="family-section">
414                <h3>🏆 Why You're Special to Us</h3>
415                <p>Your ${o.total_applications} successful applications show your trust in ${c}. This exclusive discount is our way of saying thank you for choosing us for your travel needs!</p>
416            </div>
417
418            <div class="travel-benefits">
419                <h3>✨ What Makes This Offer Amazing:</h3>
420                <ul>
421                    <li>Instant savings on your favorite destinations</li>
422                    <li>Perfect for family vacations and business trips</li>
423                    <li>Easy online application process</li>
424                    <li>Fast processing with premium support</li>
425                    <li>No hidden fees or complicated terms</li>
426                    <li>Valid for all visa types and destinations</li>
427                </ul>
428            </div>
429
430            <div style="text-align: center;">
431                <a href="#" class="cta-button">🚀 CLAIM MY DISCOUNT NOW</a>
432            </div>
433
434            <div style="background: #f8fafc; padding: 20px; border-radius: 10px; margin: 20px 0;">
435                <p><strong>🎫 How to use your discount:</strong></p>
436                <ol style="margin: 15px 0; padding-left: 25px; line-height: 1.8;">
437                    <li>Visit our website or contact our friendly team</li>
438                    <li>Use promo code: <strong style="background: #fee2e2; padding: 4px 8px; border-radius: 4px;">SAVE${d}</strong></li>
439                    <li>Complete your ${r} application${r>1?"s":""}</li>
440                    <li>Enjoy your instant ${d} AED savings!</li>
441                </ol>
442            </div>
443
444            <p>Thank you for being a valued ${c} customer. We're here to make your travel dreams come true with the best service and amazing savings!</p>
445
446            <p>Happy travels! ✈️<br>
447            <strong>Your Friends at ${c}</strong></p>
448        </div>
449
450        <div class="footer">
451            <p><strong>${c}</strong> - Your Trusted Travel Partner</p>
452            ${t!=null&&t.address?`<p>📍 ${t.address}</p>`:""}
453            ${t!=null&&t.phone?`<p>📞 ${t.phone}</p>`:""}
454            ${t!=null&&t.email?`<p>✉️ ${t.email}</p>`:""}
455            ${t!=null&&t.website?`<p>🌐 ${t.website}</p>`:""}
456            
457            <div class="social-links">
458                <a href="#">Privacy Policy</a> | 
459                <a href="#">Customer Support</a> | 
460                <a href="#">Travel Tips</a>
461            </div>
462            
463            <p style="font-size: 12px; margin-top: 25px; color: #bdc3c7;">
464                This exclusive offer is for ${o.customer_name} and expires ${l}. 
465                Cannot be combined with other promotions. Terms apply.
466            </p>
467        </div>
468    </div>
469</body>
470</html>`}},os={generate(i){var u;const{customer:o,offerText:a,applicationCount:r,validUntil:x,companyProfile:t}=i,d=((u=a.match(/(\d+(?:\.\d+)?)\s*AED/))==null?void 0:u[1])||"50",c=(t==null?void 0:t.company_name)||"eVisas.io",h=(t==null?void 0:t.logo_url)||"",l=new Date(x).toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"});return`
471<!DOCTYPE html>
472<html lang="en">
473<head>
474    <meta charset="UTF-8">
475    <meta name="viewport" content="width=device-width, initial-scale=1.0">
476    <title>Flash Sale - Limited Time Only!</title>
477    <style>
478        * { margin: 0; padding: 0; box-sizing: border-box; }
479        body { 
480            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
481            line-height: 1.6; 
482            color: #333; 
483            background: linear-gradient(45deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%);
484        }
485        .container { max-width: 600px; margin: 10px auto; background: white; border-radius: 20px; overflow: hidden; box-shadow: 0 25px 50px rgba(0,0,0,0.15); }
486        .flash-header { 
487            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
488            color: white; 
489            padding: 20px; 
490            text-align: center; 
491            position: relative;
492            overflow: hidden;
493        }
494        .flash-header::before {
495            content: '';
496            position: absolute;
497            top: 0;
498            left: -100%;
499            width: 100%;
500            height: 100%;
501            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
502            animation: flash 2s infinite;
503        }
504        @keyframes flash {
505            0% { left: -100%; }
506            100% { left: 100%; }
507        }
508        .urgency-banner {
509            background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
510            color: white;
511            padding: 15px;
512            text-align: center;
513            font-weight: bold;
514            font-size: 18px;
515            animation: pulse 1.5s infinite;
516        }
517        @keyframes pulse {
518            0%, 100% { transform: scale(1); }
519            50% { transform: scale(1.02); }
520        }
521        .logo { height: 45px; margin-bottom: 10px; position: relative; z-index: 1; }
522        .main-content { padding: 40px 30px; }
523        .mega-offer { 
524            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%); 
525            border: 3px solid #ff6b6b;
526            padding: 40px; 
527            border-radius: 20px; 
528            text-align: center; 
529            margin: 30px 0; 
530            position: relative;
531            overflow: hidden;
532        }
533        .mega-offer::before {
534            content: '🔥';
535            position: absolute;
536            top: 10px;
537            right: 10px;
538            font-size: 40px;
539            animation: bounce 1s infinite;
540        }
541        @keyframes bounce {
542            0%, 100% { transform: translateY(0); }
543            50% { transform: translateY(-10px); }
544        }
545        .discount-mega { 
546            font-size: 64px; 
547            font-weight: bold; 
548            margin: 20px 0; 
549            color: #ff416c;
550            text-shadow: 3px 3px 6px rgba(0,0,0,0.3);
551        }
552        .timer-section {
553            background: #1f2937;
554            color: white;
555            padding: 25px;
556            border-radius: 15px;
557            text-align: center;
558            margin: 25px 0;
559        }
560        .timer-grid {
561            display: grid;
562            grid-template-columns: repeat(4, 1fr);
563            gap: 15px;
564            margin-top: 20px;
565        }
566        .timer-unit {
567            background: #374151;
568            padding: 15px;
569            border-radius: 10px;
570        }
571        .timer-number {
572            font-size: 24px;
573            font-weight: bold;
574            color: #f59e0b;
575        }
576        .timer-label {
577            font-size: 12px;
578            color: #d1d5db;
579        }
580        .scarcity-alert {
581            background: linear-gradient(135deg, #fee2e2 0%, #fca5a5 100%);
582            border: 2px solid #dc2626;
583            color: #7f1d1d;
584            padding: 20px;
585            border-radius: 12px;
586            text-align: center;
587            margin: 20px 0;
588            font-weight: bold;
589            animation: shake 0.5s ease-in-out infinite alternate;
590        }
591        @keyframes shake {
592            from { transform: translateX(-2px); }
593            to { transform: translateX(2px); }
594        }
595        .mega-cta { 
596            background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%); 
597            color: white; 
598            padding: 25px 50px; 
599            border: none; 
600            border-radius: 50px; 
601            font-size: 22px; 
602            font-weight: bold; 
603            cursor: pointer; 
604            text-decoration: none; 
605            display: inline-block; 
606            margin: 30px 0; 
607            box-shadow: 0 10px 30px rgba(255, 65, 108, 0.4);
608            animation: glow 2s ease-in-out infinite alternate;
609        }
610        @keyframes glow {
611            from { box-shadow: 0 10px 30px rgba(255, 65, 108, 0.4); }
612            to { box-shadow: 0 15px 40px rgba(255, 65, 108, 0.6); }
613        }
614        .social-proof {
615            background: #f0fdf4;
616            border-left: 4px solid #10b981;
617            padding: 20px;
618            margin: 25px 0;
619            border-radius: 8px;
620        }
621        .testimonial-grid {
622            display: grid;
623            grid-template-columns: repeat(3, 1fr);
624            gap: 15px;
625            margin: 20px 0;
626        }
627        .testimonial-card {
628            background: #f8fafc;
629            padding: 15px;
630            border-radius: 10px;
631            text-align: center;
632            border: 1px solid #e2e8f0;
633        }
634        .star-rating {
635            color: #fbbf24;
636            font-size: 18px;
637            margin-bottom: 8px;
638        }
639        .footer { 
640            background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%); 
641            color: #e2e8f0; 
642            padding: 30px; 
643            text-align: center; 
644            font-size: 14px; 
645        }
646        @media (max-width: 600px) {
647            .timer-grid { grid-template-columns: repeat(2, 1fr); }
648            .testimonial-grid { grid-template-columns: 1fr; }
649            .discount-mega { font-size: 48px; }
650            .main-content { padding: 25px 20px; }
651        }
652    </style>
653</head>
654<body>
655    <div class="container">
656        <div class="urgency-banner">
657            🚨 FLASH SALE ALERT - LIMITED TIME ONLY! 🚨
658        </div>
659        
660        <div class="flash-header">
661            <img src="https://evisas.io/__l5e/assets-v1/2b052bed-a708-4eb2-8c6a-5e3f5a742cf5/sun-palm-trip.gif" alt="Flash sale" width="140" height="140" style="display:inline-block;width:140px;height:140px;max-width:140px;border:0;margin-bottom:16px;position:relative;z-index:1;" />
662            ${h?`<img src="${h}" alt="${c}" class="logo">`:""}
663            <h1>⚡ MEGA FLASH SALE ⚡</h1>
664            <p>The biggest discount of the year!</p>
665        </div>
666
667        <div class="main-content">
668            <h2>🎯 ${o.customer_name}, This Deal Won't Last!</h2>
669            
670            <div class="scarcity-alert">
671                ⚠️ ONLY 48 HOURS LEFT - Don't Miss Out! ⚠️
672            </div>
673
674            <div class="mega-offer">
675                <h3>🔥 MASSIVE SAVINGS EXPLOSION!</h3>
676                <div class="discount-mega">${d} AED OFF</div>
677                <p style="font-size: 20px; font-weight: bold;">On ${r} visa applications</p>
678                <p style="margin-top: 15px; font-size: 16px;">This is our BIGGEST discount ever!</p>
679            </div>
680
681            <div class="timer-section">
682                <h3>⏰ Offer Expires In:</h3>
683                <div class="timer-grid">
684                    <div class="timer-unit">
685                        <div class="timer-number">
68502</div>
686                        <div class="timer-label">DAYS</div>
687                    </div>
688                    <div class="timer-unit">
689                        <div class="timer-number">14</div>
690                        <div class="timer-label">HOURS</div>
691                    </div>
692                    <div class="timer-unit">
693                        <div class="timer-number">35</div>
694                        <div class="timer-label">MINUTES</div>
695                    </div>
696                    <div class="timer-unit">
697                        <div class="timer-number">42</div>
698                        <div class="timer-label">SECONDS</div>
699                    </div>
700                </div>
701                <p style="margin-top: 15px; color: #fbbf24;">Expires: ${l}</p>
702            </div>
703
704            <div class="social-proof">
705                <h3>🌟 Join 10,000+ Happy Travelers!</h3>
706                <p>"I saved hundreds with ${c}! The process was so easy and fast!" - Sarah M.</p>
707            </div>
708
709            <div class="testimonial-grid">
710                <div class="testimonial-card">
711                    <div class="star-rating">⭐⭐⭐⭐⭐</div>
712                    <p>"Amazing service!"</p>
713                    <small>- Ahmed K.</small>
714                </div>
715                <div class="testimonial-card">
716                    <div class="star-rating">⭐⭐⭐⭐⭐</div>
717                    <p>"Super fast!"</p>
718                    <small>- Maria L.</small>
719                </div>
720                <div class="testimonial-card">
721                    <div class="star-rating">⭐⭐⭐⭐⭐</div>
722                    <p>"Best prices!"</p>
723                    <small>- John D.</small>
724                </div>
725            </div>
726
727            <div style="text-align: center;">
728                <a href="#" class="mega-cta">🚀 GRAB THIS DEAL NOW!</a>
729            </div>
730
731            <div style="background: #fef3c7; border: 2px solid #f59e0b; padding: 20px; border-radius: 10px; margin: 20px 0; text-align: center;">
732                <h4 style="color: #92400e; margin-bottom: 10px;">🎫 Your VIP Promo Code:</h4>
733                <div style="background: white; padding: 15px; border-radius: 8px; font-size: 24px; font-weight: bold; color: #dc2626; letter-spacing: 2px;">
734                    FLASH${d}
735                </div>
736                <p style="margin-top: 10px; color: #92400e; font-weight: bold;">Use this code to unlock your ${d} AED savings!</p>
737            </div>
738
739            <div style="background: linear-gradient(135deg, #ddd6fe 0%, #fae8ff 100%); padding: 25px; border-radius: 15px; margin: 25px 0;">
740                <h3>🎁 BONUS: What You Get FREE:</h3>
741                <ul style="list-style: none; margin: 15px 0;">
742                    <li style="padding: 5px 0;">✅ Priority processing (Worth 50 AED)</li>
743                    <li style="padding: 5px 0;">✅ 24/7 premium support (Worth 30 AED)</li>
744                    <li style="padding: 5px 0;">✅ Express document verification (Worth 40 AED)</li>
745                    <li style="padding: 5px 0;">✅ SMS updates & tracking (Worth 20 AED)</li>
746                </ul>
747                <p style="font-weight: bold; color: #7c3aed;">Total FREE bonus value: 140 AED!</p>
748            </div>
749
750            <p style="font-size: 18px; text-align: center; margin: 20px 0; color: #dc2626; font-weight: bold;">
751                ⚡ Don't let this incredible deal slip away! ⚡
752            </p>
753
754            <p>This is a limited-time flash sale exclusively for our valued customers. Act fast before this amazing opportunity expires!</p>
755
756            <p>Ready to save big? 💰<br>
757            <strong>The ${c} Flash Sale Team</strong></p>
758        </div>
759
760        <div class="footer">
761            <p><strong>${c}</strong> - Your Travel Deal Specialists</p>
762            ${t!=null&&t.address?`<p>${t.address}</p>`:""}
763            ${t!=null&&t.phone?`<p>Phone: ${t.phone}</p>`:""}
764            ${t!=null&&t.email?`<p>Email: ${t.email}</p>`:""}
765            
766            <p style="font-size: 12px; margin-top: 20px; color: #a0aec0;">
767                Flash sale ends ${l}. Limited quantity. Terms apply. Cannot be combined with other offers.
768            </p>
769        </div>
770    </div>
771</body>
772</html>`}};class cs{generateSubject(o,a,r){const x=a.match(/(\d+)\s*AED/),t=x?x[1]:"50";return r?`🎯 Exclusive Partner Offer: ${t} AED Off Your Next Applications - ${o.customer_name}`:`✈️ Special Visa Discount: Save ${t} AED on Your Next Application!`}generateEmailHtml(o){const{template:a}=o;switch(a){case"b2b":return fe.generate(o);case"b2c":return ls.generate(o);case"promotional":return os.generate(o);default:return fe.generate(o)}}extractDiscountAmount(o){const a=o.match(/(\d+(?:\.\d+)?)\s*AED/);return a?a[1]:"50"}formatCurrency(o){return new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0,maximumFractionDigits:0}
772).format(o)}}const me=new cs,ds=({open:i,onOpenChange:o,customer:a,offerText:r,applicationCount:x})=>{const[t,d]=y.useState(""),[c,h]=y.useState(""),[l,u]=y.useState("b2b"),[p,S]=y.useState(!1),[b,A]=y.useState(null),[j,m]=y.useState(r),[v,k]=y.useState("");y.useEffect(()=>{if(i){s(),N();const g=new Date;g.setDate(g.getDate()+30),k(g.toISOString().split("T")[0])}},[i,a,r,x]),y.useEffect(()=>{console.log("Dialog received offer text:",r),m(r)},[r]);const s=async()=>{try{const g=await Ye.getCompanyProfile();A(g)}catch(g){console.error("Error loading company profile:",g)}},N=()=>{const g=a.customer_type.includes("B2B"),f=g?"b2b":"b2c";u(f);const $=me.generateSubject(a,r,g);d($),E(f)},E=g=>{console.log("Generating email preview with offer text:",j);const f={customer:a,offerText:j,applicationCount:x,validUntil:v,companyProfile:b,template:g},$=me.generateEmailHtml(f);h($)},T=g=>{u(g),E(g)},H=g=>{console.log("Offer text changed to:",g),m(g);const f=a.customer_type.includes("B2B"),$=me.generateSubject(a,g,f);d($),E(l)},J=async()=>{if(!t.trim()||!c.trim()){U.error("Please provide both subject and email content");return}S(!0);try{await new Promise(g=>setTimeout(g,2e3)),console.log("Sending offer email:",{to:a.customer_name,subject:t,html:c,offerDetails:{customer:a.customer_name,offer:j,applicationCount:x,validUntil:v}}),U.success(`Smart offer email sent successfully to ${a.customer_name}!`),o(!1)}catch(g){console.error("Error sending email:",g),U.error("Failed to send email")}finally{S(!1)}},n=g=>{switch(g){case"b2b":return"bg-blue-600";case"b2c":return"bg-green-600";case"promotional":return"bg-purple-600";default:return"bg-gray-600"}};return e.jsx(Re,{open:i,onOpenChange:o,children:e.jsxs(Le,{className:"max-w-6xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Ve,{children:e.jsxs(Me,{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-5 w-5"}),"Smart Offer Email to ",a.customer_name,e.jsxs(Y,{className:`${n(l)} text-white`,children:[l.toUpperCase()," TEMPLATE"]})]})}),e.jsxs(ve,{defaultValue:"compose",className:"w-full",children:[e.jsxs(be,{className:"grid w-full grid-cols-3",children:[e.jsx(R,{value:"compose",children:"Compose"}),e.jsx(R,{value:"preview",children:"Preview"}),e.jsx(R,{value:"settings",children:"Settings"})]}),e.jsx(L,{value:"compose",className:"space-y-4",children:e.jsx(is,{subject:t,setSubject:d,offerText:j,setOfferText:H,applicationCount:x,validUntil:v,setValidUntil:k,emailTemplate:l,onTemplateChange:T,customer:a})}),e.jsx(L,{value:"preview",className:"space-y-4",children:e.jsx(rs,{emailHtml:c,onRefreshPreview:()=>E(l)})}),e.jsx(L,{value:"settings",className:"space-y-4",children:e.jsx(ns,{customer:a,emailTemplate:l,onTemplateChange:T,companyProfile:b})})]}),e.jsxs("div",{className:"flex justify-between items-center pt-4",children:[e.jsxs("div",{className:"text-sm text-gray-600",children:["Offer Email for ",a.customer_type," customer"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsx(O,{onClick:J,disabled:p,className:"bg-blue-600 hover:bg-blue-700",children:p?e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"h-4 w-4 mr-2 animate-spin"}),"Sending Offer..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{className:"h-4 w-4 mr-2"}),"Send Offer Email"]})})]})]})]})})},ps=({smartOfferCandidates:i,isLoading:o})=>{const[a,r]=y.useState([]),[x,t]=y.useState(!1),[d,c]=y.useState(null),[h,l]=y.useState(""),[u,p]=y.useState(0),S=(n,g,f)=>{const $=g||j(n,f);U.success(`Smart offer sent to ${n.customer_name}!`),console.log("Sending offer:",$)},b=(n,g,f)=>{const $=k(n.user_id),D=($==null?void 0:$.offer)||g||j(n,f),z=($==null?void 0:$.applicationCount)||f||(n.customer_type.includes("B2B")?Math.min(n.total_applications+2,10):Math.min(n.total_applications+1,5));console.log("Email Preview - Using offer text:",D),console.log("Email Preview - Using app count:",z),c(n),l(D),p(z),t(!0)},A=n=>50,j=(n,g)=>{const f=n.customer_type.includes("B2B"),$=A(),D=Math.min($,100),z=g||(f?Math.min(n.total_applications+2,10):Math.min(n.total_applications+1,5));return f?n.total_applications>=20?`High-volume partner: ${Math.min(75,D)} AED off next ${z} applications`:n.total_applications>=10?`Loyal partner: ${Math.min(50,D)} AED off next ${z} applications`:n.profit>1e3?`Premium partner: ${Math.min(100,D)} AED off next ${z} applications`:`Business offer: ${Math.min(40,D)} AED off next ${z} applications`:n.total_applications>=10?`Frequent traveler: ${Math.min(30,D)} AED off next ${z}
772 family visas`:n.total_passengers>=5?`Large family discount: ${Math.min(25,D)} AED off next ${z} group booking`:n.profit>300?`Valued customer: ${Math.min(20,D)} AED off next ${z} visas`:`Welcome back: ${Math.min(15,D)} AED off next ${z} visa application`},m=(n,g)=>{console.log("Updating custom offer for customer:",n,"New offer:",g),r(f=>f.find(D=>D.customerId===n)?f.map(D=>D.customerId===n?{...D,offer:g}:D):[...f,{customerId:n,offer:g,applicationCount:2}])},v=(n,g)=>{console.log("Updating application count for customer:",n,"New count:",g),r(f=>f.find(D=>D.customerId===n)?f.map(D=>D.customerId===n?{...D,applicationCount:g}:D):[...f,{customerId:n,offer:"",applicationCount:g}])},k=n=>a.find(g=>g.customerId===n),s=n=>{const g=n.customer_type.includes("B2B");return g&&n.total_applications>=15?"high-volume":n.profit>(g?1e3:300)?"high-profit":n.total_applications>=(g?5:3)?"loyal":"premium"},N=n=>{switch(n){case"high-volume":return"bg-blue-100 text-blue-800";case"high-profit":return"bg-green-100 text-green-800";case"loyal":return"bg-purple-100 text-purple-800";case"premium":return"bg-yellow-100 text-yellow-800";default:return"bg-gray-100 text-gray-800"}},E=n=>{switch(n){case"high-volume":return I;case"high-profit":return X;case"loyal":return ee;case"premium":return q;default:return ee}},T=n=>new Intl.NumberFormat("en-AE",{style:"currency",currency:"AED",minimumFractionDigits:0,maximumFractionDigits:0}).format(n),H=i.filter(n=>n.customer_type.includes("B2B")),J=i.filter(n=>n.customer_type.includes("B2C"));return o?e.jsxs(_,{children:[e.jsx(F,{children:e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-5 w-5"}),"Smart Customer Offers"]})}),e.jsx(B,{children:e.jsx("div",{className:"space-y-4",children:[...Array(3)].map((n,g)=>e.jsx("div",{className:"h-20 bg-gray-100 animate-pulse rounded"},g))})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(_,{children:[e.jsxs(F,{children:[e.jsxs(P,{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-5 w-5"}),"Smart Customer Offers"]}),e.jsx("p",{className:"text-sm text-gray-600",children:"AI-generated offers for high-value customers based on their booking behavior"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mt-4",children:[e.jsxs("div",{className:"bg-blue-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-sm text-blue-600",children:"B2B Offer Candidates"})]}),e.jsx("div",{className:"text-lg font-bold text-blue-700",children:H.length})]}),e.jsxs("div",{className:"bg-green-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-sm text-green-600",children:"B2C Offer Candidates"})]}),e.jsx("div",{className:"text-lg font-bold text-green-700",children:J.length})]}),e.jsxs("div",{className:"bg-purple-50 p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"text-sm text-purple-600",children:"Potential Revenue Impact"})]}),e.jsx("div",{className:"text-lg font-bold text-purple-700",children:T(i.reduce((n,g)=>n+g.profit*.1,0))})]})]})]}),e.jsx(B,{children:i.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-500",children:[e.jsx(ee,{className:"h-12 w-12 mx-auto mb-3 text-gray-300"}),e.jsx("p",{children:"No smart offer candidates found"}),e.jsx("p",{className:"text-sm",children:"Need more customer data to generate targeted offers"})]}):e.jsx("div",{className:"space-y-4",children:i.slice(0,10).map(n=>{const g=s(n),f=k(n.user_id),$=A(),D=(f==null?void 0:f.offer)||j(n,f==null?void 0:f.applicationCount),z=E(g),W=n.customer_type.includes("B2B");return e.jsx("div",{className:"border rounded-lg p-4 hover:bg-gray-50 transition-colors",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h4",{className:"font-medium",children:n.customer_name}),e.jsxs(Y,{variant:W?"default":"secondary",className:"flex items-center gap-1",children:[W?e.jsx(q,{className:"h-3 w-3"}):e.jsx(re,{className:"h-3 w-3"}),W?"B2B Partner":"B2C Customer"]}),e.jsxs(Y,{className:N(g),children:[e.jsx(z,{className:"h-3 w-3 mr-1"}),g.replace("-"," ")]})]}
772),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4 text-sm text-gray-600 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500",children:"Applications:"}),e.jsx(as,{initialValue:(f==null?void 0:f.applicationCount)||n.total_applications,onSave:de=>v(n.user_id,de)})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-gray-500 flex items-center gap-1",children:[e.jsx(Ie,{className:"h-3 w-3"}),"Passengers:"]}),e.jsx("div",{className:"font-medium",children:n.total_passengers})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Total Profit:"}),e.jsx("div",{className:"font-medium text-green-600",children:T(n.profit)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Profit %:"}),e.jsxs("div",{className:"font-medium",children:[n.profit_percentage.toFixed(1),"%"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Avg/App:"}),e.jsx("div",{className:"font-medium",children:T(n.avg_profit_per_application)})]})]}),e.jsxs("div",{className:`p-3 rounded-md ${W?"bg-blue-50":"bg-green-50"}`,children:[e.jsxs("p",{className:`text-sm font-medium ${W?"text-blue-800":"text-green-800"} mb-2`,children:["💡 Suggested ",W?"Partner":"Customer"," Offer:"]}),e.jsx(ts,{initialValue:D,maxAmount:$,onSave:de=>m(n.user_id,de),className:`${W?"text-blue-700":"text-green-700"}`}),e.jsxs("p",{className:"text-xs text-gray-600 mt-1",children:["Max discount: ",T($)," (service charge limit)"]}),n.partner_id&&e.jsxs("p",{className:"text-xs text-gray-600 mt-1",children:["Partner ID: ",n.partner_id]})]})]}),e.jsxs("div",{className:"ml-4 flex flex-col gap-2",children:[e.jsxs(O,{onClick:()=>b(n,f==null?void 0:f.offer,f==null?void 0:f.applicationCount),size:"sm",variant:"outline",className:"flex items-center gap-1",children:[e.jsx(ae,{className:"h-4 w-4"}),"Email Preview"]}),e.jsxs(O,{onClick:()=>S(n,f==null?void 0:f.offer,f==null?void 0:f.applicationCount),size:"sm",className:"flex items-center gap-1",variant:W?"default":"secondary",children:[e.jsx(Ee,{className:"h-4 w-4"}),"Send Offer"]})]})]})},n.user_id)})})})]}),d&&e.jsx(ds,{open:x,onOpenChange:t,customer:d,offerText:h,applicationCount:u})]})},ms=({startDate:i,endDate:o})=>{const a=Ge(),[r,x]=y.useState(null),[t,d]=y.useState(!0),c=u=>{const p=new URLSearchParams;p.set("filter",u),i&&p.set("startDate",i),o&&p.set("endDate",o),a(`/admin/analytics/supplier-pricing-details?${p.toString()}`)};y.useEffect(()=>{h()},[i,o]);const h=async()=>{d(!0);try{const u=await We.getPricingAnalysis(i,o);x(u)}catch(u){console.error("Error loading supplier analysis:",u)}finally{d(!1)}};if(t)return e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{className:"h-32 w-full"}),e.jsx(he,{className:"h-32 w-full"})]});if(!r)return e.jsx(_,{className:"p-6",children:e.jsx("p",{className:"text-center text-muted-foreground",children:"No data available"})});const l=r.applications_with_supplier>0?r.optimal_selections/r.applications_with_supplier*100:0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Supplier Selection Analysis"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Overview of supplier pricing optimization"})]}),e.jsxs(O,{onClick:h,disabled:t,variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(Se,{className:`h-4 w-4 ${t?"animate-spin":""}`}),"Refresh"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(_,{className:"p-4 cursor-pointer hover:shadow-lg transition-shadow",onClick:()=>c("all"),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Applications"}),e.jsx("p",{className:"text-2xl font-bold",children:r.total_applications})]}),e.jsx(ge,{className:"h-8 w-8 text-blue-500"})]})}),e.jsx(_,{className:"p-4 cursor-pointer hover:shadow-lg transition-shadow",onClick:()=>c("optimal"),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Optimal Selections"}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:r.optimal_selections}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[l.toFixed(1),"%"]})]}),e.jsx(Z,{className:"h-8 w-8 text-green-500"})]})}),e.jsx(_,{className:"p-4 cursor-pointer hover:shadow-lg transition-shadow",onClick:()=>c("overpaid"),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Overpayments"}),e.jsx("p",{className:"text-2xl font-bold text-red-600",children:r.suboptimal_selections}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Avg +",r.avg_overpayment_percentage.toFixed(1),"%"]})]}),e.jsx(X,{className:"h-8 w-8 text-red-500"})]})}),e.jsx(_,{className:"p-4 cursor-pointer hover:shadow-lg transition-shadow",onClick:()=>c("overpaid"),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Potential Savings"}),e.jsx("p",{className:"text-2xl font-bold text-orange-600",children:te(r.total_potential_savings)})]}),e.jsx(pe,{className:"h-8 w-8 text-orange-500"})]})})]}),e.jsxs(_,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Decision Insights"}),e.jsxs("div",{className:"space-y-3",children:[r.total_potential_savings>0&&e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-orange-50 rounded-lg border border-orange-200 cursor-pointer hover:shadow-lg transition-shadow",onClick:()=>c("overpaid"),children:[e.jsx(pe,{className:"h-5 w-5 text-orange-600 mt-0.5"}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium text-orange-900",children:["You could have saved ",te(r.total_potential_savings)," in this period"]}),e.jsxs("p",{className:"text-sm text-orange-700 mt-1",children:[r.suboptimal_selections," applications were assigned to more expensive suppliers than the best available option."]}),e.jsx("p",{className:"text-xs text-orange-600 mt-2 font-medium",children:"Click to view detailed comparison →"})]})]}),l>=80&&e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-green-50 rounded-lg border border-green-200",children:[e.jsx(ge,{className:"h-5 w-5 text-green-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-green-900",children:"Excellent cost optimization!"}),e.jsxs("p",{className:"text-sm text-green-700 mt-1",children:["You're choosing the best-priced suppliers ",l.toFixed(0),"% of the time."]})]})]}),l<50&&e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-red-50 rounded-lg border border-red-200 cursor-pointer hover:shadow-lg transition-shadow",onClick:()=>c("overpaid"),children:[e.jsx(pe,{className:"h-5 w-5 text-red-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-red-900",children:"High overpayment rate detected"}),e.jsx("p",{className:"text-sm text-red-700 mt-1",children:"Over half of your supplier assignments resulted in overpayments."}),e.jsx("p",{className:"text-xs text-red-600 mt-2 font-medium",children:"Click to view detailed comparison →"})]})]})]})]}),e.jsxs(_,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Cost Comparison"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center p-4 bg-gray-50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Actual Supplier Cost"}),e.jsx("p",{className:"text-xl font-bold",children:te(r.total_supplier_cost)})]}),e.jsx(Y,{variant:"outline",children:"Paid"})]}),e.jsxs("div",{className:"flex justify-between items-center p-4 bg-green-50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Best Available Cost"}),e.jsx("p",{className:"text-xl font-bold text-green-600",children:te(r.total_best_available_cost)})]}),e.jsx(Y,{className:"bg-green-100 text-green-800",children:"Optimal"})]}),r.total_potential_savings>0&&e.jsxs("div",{className:"flex justify-between items-center p-4 bg-red-50 rounded-lg border-2 border-red-200",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Overspending"}),e.jsxs("p",{className:"text-xl font-bold text-red-600",children:["+",te(r.total_potential_savings)]})]}),e.jsx(Y,{className:"bg-red-100 text-red-800",children:"Could Save"})]})]})]})]})},Rs=()=>{const[i,o]=y.useState({}),{data:a,isLoading:r,error:x,refetch:t}=Je(i.startDate,i.endDate),d=(a==null?void 0:a.supplierProfit)||[],c=(a==null?void 0:a.customerProfitability)||[],h=(a==null?void 0:a.visaProfitByCountry)||[];a!=null&&a.overallProfitSummary;const l=(a==null?void 0:a.agentDiscountSummary)||[],u=(a==null?void 0:a.smartOfferCandidates)||[],p=Q.useMemo(()=>
772{if(!c||c.length===0)return{total_applications:0,unique_customers:0,revenue:0,cost:0,net_profit:0,avg_profit_per_application:0,avg_revenue_per_customer:0};const j=c.reduce((E,T)=>E+T.total_applications,0),m=c.length,v=c.reduce((E,T)=>E+T.revenue,0),k=c.reduce((E,T)=>E+T.cost,0),s=v-k,N=c.reduce((E,T)=>E+T.total_passengers,0);return{total_applications:j,unique_customers:m,revenue:v,cost:k,net_profit:s,avg_profit_per_application:j>0?s/j:0,avg_revenue_per_customer:m>0?v/m:0,total_passengers:N}},[c]),S={...p,total_applications:p.total_applications,unique_customers:p.unique_customers,revenue:p.revenue,cost:p.cost,net_profit:p.net_profit,avg_profit_per_application:p.avg_profit_per_application,avg_revenue_per_customer:p.avg_revenue_per_customer},b=h.map(j=>({...j,applications:j.total_applications,unique_customers:0,revenue:j.total_revenue,cost:j.total_cost,profit:j.net_profit})),A=j=>{o(j)};return x?(console.error("Error loading sustainability data:",x),e.jsx(_,{children:e.jsx(B,{className:"p-6",children:e.jsxs("div",{className:"text-center text-red-600",children:[e.jsx("p",{children:"Error loading sustainability data"}),e.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"Please try refreshing the page"})]})})})):r&&!a?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Sustainability Analytics"}),e.jsx("p",{className:"text-gray-600",children:"Business profitability and sustainability insights"})]}),e.jsx(Xe,{title:"Sustainability Analytics",onRetry:()=>t(),stages:[{label:"Customers",detail:"Reading customer profitability…"}
772,{label:"Suppliers",detail:"Reading supplier profit…"},{label:"Countries",detail:"Reading visa profit by country…"},{label:"Discounts",detail:"Reading agent discounts…"}]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Sustainability Analytics"}),e.jsx("p",{className:"text-gray-600",children:"Business profitability and sustainability insights"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{source:"real",lastUpdated:new Date,className:"mr-4"}),e.jsx($e,{onDateChange:A}),e.jsxs(O,{variant:"outline",size:"sm",children:[e.jsx(ye,{className:"h-4 w-4 mr-2"}),"Export Report"]})]})]}),e.jsx(He,{}),e.jsx(Ze,{data:S,isLoading:r}),e.jsxs(ve,{defaultValue:"customer-profitability",className:"w-full",children:[e.jsxs(be,{className:"grid w-full grid-cols-6",children:[e.jsx(R,{value:"customer-profitability",children:"Customer Profitability"}),e.jsx(R,{value:"supplier-profit",children:"Supplier Profit"}),e.jsx(R,{value:"supplier-selection",children:"Supplier Selection"}),e.jsx(R,{value:"visa-countries",children:"Visa by Country"}),e.jsx(R,{value:"agent-discounts",children:"Agent Discounts"}),e.jsx(R,{value:"smart-offers",children:"Smart Offers"})]}),e.jsxs(L,{value:"customer-profitability",className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{source:"real"})}),e.jsx(Ke,{data:c,isLoading:r})]}),e.jsxs(L,{value:"supplier-profit",className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{source:"real"})}),e.jsx(Qe,{data:d,isLoading:r})]}),e.jsxs(L,{value:"supplier-selection",className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{source:"real"})}),e.jsx(ms,{startDate:i.startDate,endDate:i.endDate})]}),e.jsxs(L,{value:"visa-countries",className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{source:"real"})}),e.jsx(es,{data:b,isLoading:r})]}),e.jsxs(L,{value:"agent-discounts",className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{source:"real"})}),e.jsx(ss,{data:l,isLoading:r})]}),e.jsxs(L,{value:"smart-offers",className:"space-y-4",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{source:"real"})}),e.jsx(ps,{smartOfferCandidates:u,isLoading:r})]})]})]})};export{Rs as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.