PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.9
Yatra – Travel Booking & Tour Operator Software v3.0.9
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / assets / dist / js / account-page.js

account-page.js in Yatra – Travel Booking & Tour Operator Software 3.0.9, at assets/dist/js/account-page.js

3,449 lines 194.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { j as jsxRuntimeExports, p as Calendar, k as FileText, b as Plane, at as ArrowRight, q as MapPin, I as User, y as ChevronRight, S as Sparkles, h as Package, i as CreditCard, by as LifeBuoy, be as Bell, az as AlertCircle, aD as CheckCircle2, ar as Clock, V as ExternalLink, U as Users, d as Mail, aW as Phone, b4 as Download, r as reactExports, a5 as React, u as useQuery, av as CheckCircle, as as DollarSign, aQ as Eye, t as useQueryClient, aJ as PenSquare, b6 as XCircle, bz as ShieldCheck, bf as Heart, s as LayoutDashboard, bA as LogOut, bv as QueryClient, bw as client, bx as QueryClientProvider } from "./react-vendor-zODANjVp.js";
2 import { f as formatYatraMoney, _ as __, p as parseDate, e as formatDate$1, k as applyCurrencyPosition, s as sprintf, t as toDateValue, a as apiClient, A as API_ENDPOINTS, u as useToast, l as getCountryOptions, i as getCountryName$1, T as ToastProvider, E as ErrorBoundary } from "./index-C2r48y7c.js";
3 function toBrowserLocaleTag(locale) {
4 const raw = String(locale || "").trim();
5 if (!raw) return void 0;
6 return raw.replace(/_/g, "-");
7 }
8 function getAccountLocale() {
9 var _a;
10 if (typeof window === "undefined") return void 0;
11 const raw = (_a = window.yatraAccountPage) == null ? void 0 : _a.locale;
12 return toBrowserLocaleTag(raw);
13 }
14 const formatDate = (value) => {
15 if (!value) {
16 return __("N/A", "yatra");
17 }
18 if (!parseDate(value)) {
19 return __("Invalid date", "yatra");
20 }
21 return formatDate$1(value);
22 };
23 function extractYmd(value) {
24 if (!value) {
25 return null;
26 }
27 const m = String(value).trim().match(/^(\d{4}-\d{2}-\d{2})/);
28 return m ? m[1] : null;
29 }
30 const formatTravelDateRange = (travelDate, endDate) => {
31 const startKey = extractYmd(travelDate);
32 const endKey = extractYmd(endDate);
33 if (!startKey) {
34 return formatDate(travelDate);
35 }
36 if (!endKey || endKey === startKey) {
37 return formatDate(travelDate);
38 }
39 return sprintf(
40 // translators: 1: start date, 2: end date. Joined with an en-dash for travel date ranges.
41 __("%1$s – %2$s", "yatra"),
42 formatDate(travelDate),
43 formatDate(endDate)
44 );
45 };
46 const getStatusLabel = (status) => {
47 const raw = typeof status === "string" ? status.toLowerCase().trim() : "";
48 switch (raw) {
49 case "pending":
50 return __("Pending", "yatra");
51 case "confirmed":
52 return __("Confirmed", "yatra");
53 case "processing":
54 return __("Processing", "yatra");
55 case "completed":
56 return __("Completed", "yatra");
57 case "cancelled":
58 return __("Cancelled", "yatra");
59 case "refunded":
60 return __("Refunded", "yatra");
61 case "failed":
62 return __("Failed", "yatra");
63 case "on_hold":
64 return __("On hold", "yatra");
65 case "paid":
66 return __("Paid", "yatra");
67 case "partial":
68 return __("Partial", "yatra");
69 case "awaiting_response":
70 return __("Awaiting response", "yatra");
71 case "resolved":
72 return __("Resolved", "yatra");
73 case "closed":
74 return __("Closed", "yatra");
75 case "open":
76 return __("Open", "yatra");
77 case "":
78 return __("Pending", "yatra");
79 default:
80 return raw.charAt(0).toUpperCase() + raw.slice(1).replace(/_/g, " ");
81 }
82 };
83 const getBadge = (status) => {
84 const base = "px-2.5 py-0.5 rounded-full text-xs font-medium";
85 if (!status || typeof status !== "string") {
86 return `${base} bg-gray-100 text-gray-800 dark:bg-gray-900/30 dark:text-gray-300`;
87 }
88 switch (status.toLowerCase()) {
89 case "paid":
90 case "confirmed":
91 case "resolved":
92 return `${base} bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300`;
93 case "pending":
94 case "partial":
95 case "awaiting_response":
96 return `${base} bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`;
97 case "failed":
98 case "cancelled":
99 return `${base} bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300`;
100 default:
101 return `${base} bg-yatra-chip-bg text-yatra-primary-darker dark:bg-yatra-surface-dark dark:text-yatra-primary-light`;
102 }
103 };
104 function readPriceConfig() {
105 if (typeof window === "undefined") {
106 return {
107 globalCurrency: "USD",
108 currencyPosition: "before",
109 decimalPlaces: 2,
110 thousandSeparator: ",",
111 decimalSeparator: "."
112 };
113 }
114 const w = window;
115 const a = w.yatraAdmin || {};
116 const p = w.yatraAccountPage || {};
117 return {
118 globalCurrency: a.currency || p.currency || "USD",
119 currencyPosition: a.currencyPosition || a.currency_position || p.currencyPosition || p.currency_position || "before",
120 decimalPlaces: Number(a.decimalPlaces ?? p.decimalPlaces ?? 2) || 2,
121 thousandSeparator: a.thousandSeparator || p.thousandSeparator || ",",
122 decimalSeparator: a.decimalSeparator || p.decimalSeparator || "."
123 };
124 }
125 const formatPrice = (price) => {
126 const {
127 globalCurrency,
128 currencyPosition,
129 decimalPlaces,
130 thousandSeparator,
131 decimalSeparator
132 } = readPriceConfig();
133 if (!price || price === 0) {
134 return __("Contact for pricing", "yatra");
135 }
136 const formattedAmount = new Intl.NumberFormat(getAccountLocale(), {
137 minimumFractionDigits: decimalPlaces,
138 maximumFractionDigits: decimalPlaces
139 }).format(price).replace(/,/g, "TEMP_THOUSAND").replace(/\./g, decimalSeparator).replace(/TEMP_THOUSAND/g, thousandSeparator);
140 const currencySymbol = new Intl.NumberFormat(getAccountLocale(), {
141 style: "currency",
142 currency: globalCurrency
143 }).format(0).replace(/[\d\s.,]/g, "").trim();
144 return applyCurrencyPosition(
145 formattedAmount,
146 currencySymbol,
147 currencyPosition
148 );
149 };
150 const formatPriceForBooking = (price, currency2) => {
151 const cfg = readPriceConfig();
152 const globalCurrency = currency2 || cfg.globalCurrency;
153 const {
154 currencyPosition,
155 decimalPlaces,
156 thousandSeparator,
157 decimalSeparator
158 } = cfg;
159 const currencyToUse = globalCurrency;
160 const numPrice = Number(price) || 0;
161 const formattedAmount = new Intl.NumberFormat(getAccountLocale(), {
162 minimumFractionDigits: decimalPlaces,
163 maximumFractionDigits: decimalPlaces
164 }).format(numPrice).replace(/,/g, "TEMP_THOUSAND").replace(/\./g, decimalSeparator).replace(/TEMP_THOUSAND/g, thousandSeparator);
165 const currencySymbol = new Intl.NumberFormat(getAccountLocale(), {
166 style: "currency",
167 currency: currencyToUse
168 }).format(0).replace(/[\d\s.,]/g, "").trim();
169 return applyCurrencyPosition(
170 formattedAmount,
171 currencySymbol,
172 currencyPosition
173 );
174 };
175 const currency = (value, currencyCode) => {
176 const cfg = readPriceConfig();
177 const code = cfg.globalCurrency || "USD";
178 return formatYatraMoney(Number(value) || 0, code, { zeroAsUnknown: false });
179 };
180 function getYatraAccountPageGlobals() {
181 if (typeof window === "undefined") {
182 return {
183 logoutUrl: "",
184 companyPhone: "",
185 companyName: "",
186 companyEmail: "",
187 locale: ""
188 };
189 }
190 const p = window.yatraAccountPage;
191 const raw = p || {};
192 return {
193 logoutUrl: String(raw.logoutUrl || "").trim(),
194 companyPhone: String(raw.companyPhone || "").trim(),
195 companyName: String(raw.companyName || "").trim(),
196 companyEmail: String(raw.companyEmail || "").trim(),
197 locale: String(raw.locale || "").trim()
198 };
199 }
200 function phoneToTelHref(phone) {
201 const t = String(phone).trim();
202 if (!t) {
203 return "";
204 }
205 const compact = t.replace(/[^\d+]/g, "");
206 return compact ? `tel:${compact}` : `tel:${encodeURIComponent(t)}`;
207 }
208 const Dashboard = ({
209 bookings,
210 payments,
211 displayProfile,
212 stats,
213 notifications,
214 conciergePhone = "",
215 conciergeEmail = "",
216 onSectionChange,
217 onBookingOpen
218 }) => {
219 var _a;
220 const conciergeTel = phoneToTelHref(conciergePhone);
221 const conciergeMail = String(conciergeEmail || "").trim();
222 const upcomingBookings = bookings.filter((b) => toDateValue(b.travel_date) > /* @__PURE__ */ new Date()).length > 0 ? bookings.filter((b) => toDateValue(b.travel_date) > /* @__PURE__ */ new Date()).slice(0, 3) : bookings.filter((b) => toDateValue(b.travel_date) > /* @__PURE__ */ new Date()).slice(0, 3);
223 const recentBookings = bookings.length > 0 ? bookings.slice(0, 2) : [];
224 const pendingPayments = payments.filter((p) => p.status === "pending").length > 0 ? payments.filter((p) => p.status === "pending").slice(0, 2) : [];
225 const displayNotifications = notifications;
226 const enhancedStats = [
227 {
228 ...stats[0],
229 gradient: "from-yatra-primary to-yatra-primary-dark",
230 bgColor: "bg-yatra-soft dark:bg-yatra-surface-dark-muted",
231 iconColor: "text-yatra-primary dark:text-yatra-on-dark"
232 },
233 {
234 ...stats[1],
235 gradient: "from-emerald-500 to-emerald-600",
236 bgColor: "bg-emerald-50 dark:bg-emerald-900/20",
237 iconColor: "text-emerald-600 dark:text-emerald-400"
238 },
239 {
240 ...stats[2],
241 gradient: "from-amber-500 to-amber-600",
242 bgColor: "bg-amber-50 dark:bg-amber-900/20",
243 iconColor: "text-amber-600 dark:text-amber-400"
244 },
245 {
246 ...stats[3],
247 gradient: "from-purple-500 to-purple-600",
248 bgColor: "bg-purple-50 dark:bg-purple-900/20",
249 iconColor: "text-purple-600 dark:text-purple-400"
250 }
251 ];
252 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
253 /* @__PURE__ */ jsxRuntimeExports.jsxs(
254 "div",
255 {
256 className: "yatra-dashboard-welcome relative overflow-hidden rounded-2xl p-8 shadow-xl",
257 style: {
258 background: "linear-gradient(135deg, var(--yatra-primary, #3b82f6) 0%, var(--yatra-primary-dark, #2563eb) 45%, var(--yatra-primary-darker, #1e40af) 100%)",
259 color: "#ffffff"
260 },
261 children: [
262 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative z-10", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between", children: [
263 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
264 /* @__PURE__ */ jsxRuntimeExports.jsx(
265 "h2",
266 {
267 className: "text-lg font-bold mb-2",
268 style: { color: "#ffffff" },
269 children: sprintf(
270 // translators: %s: customer first name (or "Traveler" fallback).
271 __("Welcome back, %s!", "yatra"),
272 ((_a = displayProfile == null ? void 0 : displayProfile.name) == null ? void 0 : _a.split(" ")[0]) || __("Traveler", "yatra")
273 )
274 }
275 ),
276 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm mb-4 text-white/90", children: [
277 __("You have", "yatra"),
278 " ",
279 upcomingBookings.length,
280 " ",
281 upcomingBookings.length === 1 ? __("upcoming adventure", "yatra") : __("upcoming adventures", "yatra"),
282 " ",
283 __("coming up", "yatra")
284 ] }),
285 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap gap-3 mt-4", children: [
286 /* @__PURE__ */ jsxRuntimeExports.jsxs(
287 "div",
288 {
289 role: "button",
290 tabIndex: 0,
291 onClick: () => onSectionChange("bookings"),
292 className: "px-4 py-2 rounded-lg text-sm font-medium transition-all flex items-center gap-2 hover:opacity-90 cursor-pointer",
293 style: {
294 backgroundColor: "rgba(255, 255, 255, 0.2)",
295 color: "#ffffff",
296 backdropFilter: "blur(8px)"
297 },
298 children: [
299 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-4 h-4", style: { color: "#ffffff" } }),
300 __("View Calendar", "yatra")
301 ]
302 }
303 ),
304 /* @__PURE__ */ jsxRuntimeExports.jsxs(
305 "div",
306 {
307 role: "button",
308 tabIndex: 0,
309 onClick: () => onSectionChange("documents"),
310 className: "px-4 py-2 rounded-lg text-sm font-medium transition-all flex items-center gap-2 hover:opacity-90 cursor-pointer",
311 style: {
312 backgroundColor: "rgba(255, 255, 255, 0.2)",
313 color: "#ffffff",
314 backdropFilter: "blur(8px)"
315 },
316 children: [
317 /* @__PURE__ */ jsxRuntimeExports.jsx(FileText, { className: "w-4 h-4", style: { color: "#ffffff" } }),
318 __("My Documents", "yatra")
319 ]
320 }
321 )
322 ] })
323 ] }),
324 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "hidden md:block", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
325 "div",
326 {
327 className: "w-24 h-24 rounded-full flex items-center justify-center",
328 style: {
329 backgroundColor: "rgba(255, 255, 255, 0.1)",
330 backdropFilter: "blur(8px)"
331 },
332 children: /* @__PURE__ */ jsxRuntimeExports.jsx(Plane, { className: "w-12 h-12", style: { color: "#ffffff" } })
333 }
334 ) })
335 ] }) }),
336 /* @__PURE__ */ jsxRuntimeExports.jsx(
337 "div",
338 {
339 className: "absolute top-0 right-0 w-64 h-64 rounded-full -mr-32 -mt-32",
340 style: { backgroundColor: "rgba(255, 255, 255, 0.05)" }
341 }
342 ),
343 /* @__PURE__ */ jsxRuntimeExports.jsx(
344 "div",
345 {
346 className: "absolute bottom-0 left-0 w-48 h-48 rounded-full -ml-24 -mb-24",
347 style: { backgroundColor: "rgba(255, 255, 255, 0.05)" }
348 }
349 )
350 ]
351 }
352 ),
353 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-dashboard-stats grid gap-4 sm:grid-cols-2 lg:grid-cols-4", children: enhancedStats.map((stat) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
354 "div",
355 {
356 className: `yatra-stat-card yatra-stat-card-${stat.label.toLowerCase().replace(/\s+/g, "-")} group relative bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm hover:shadow-md transition-all overflow-hidden`,
357 children: [
358 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-6", children: [
359 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between mb-4", children: [
360 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `p-3 rounded-lg ${stat.bgColor}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(stat.icon, { className: `w-6 h-6 ${stat.iconColor}` }) }),
361 stat.badge && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "inline-flex text-xs px-2 py-1 rounded-full bg-yatra-chip-bg text-yatra-primary-dark dark:bg-yatra-surface-dark dark:text-yatra-primary-light font-medium", children: stat.badge })
362 ] }),
363 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
364 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mb-1", children: stat.label }),
365 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: stat.value })
366 ] })
367 ] }),
368 /* @__PURE__ */ jsxRuntimeExports.jsx(
369 "div",
370 {
371 className: `absolute bottom-0 left-0 right-0 h-1 bg-gradient-to-r ${stat.gradient} opacity-0 group-hover:opacity-100 transition-opacity`
372 }
373 )
374 ]
375 },
376 stat.label
377 )) }),
378 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-6 lg:grid-cols-3", children: [
379 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-dashboard-upcoming-trips lg:col-span-2 bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm overflow-hidden", children: [
380 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-dashboard-upcoming-trips-header p-6 border-b border-gray-100 dark:border-gray-700", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
381 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
382 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-emerald-50 dark:bg-emerald-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-5 h-5 text-emerald-600 dark:text-emerald-400" }) }),
383 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
384 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-semibold text-gray-900 dark:text-white", children: __("Upcoming Trips", "yatra") }),
385 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: __("Your next adventures", "yatra") })
386 ] })
387 ] }),
388 upcomingBookings.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(
389 "div",
390 {
391 role: "button",
392 tabIndex: 0,
393 onClick: () => onSectionChange("bookings"),
394 className: "text-sm text-yatra-primary dark:text-yatra-on-dark hover:text-yatra-primary-dark dark:hover:text-yatra-primary-light font-medium flex items-center gap-1 transition-colors cursor-pointer",
395 children: [
396 __("View all", "yatra"),
397 /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowRight, { className: "w-4 h-4" })
398 ]
399 }
400 )
401 ] }) }),
402 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-6", children: upcomingBookings.length > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: upcomingBookings.map((booking) => {
403 const openBooking = () => {
404 const id = Number(booking.id);
405 if (!id) return;
406 if (onBookingOpen) {
407 onBookingOpen(id);
408 } else {
409 onSectionChange("bookings");
410 }
411 };
412 return /* @__PURE__ */ jsxRuntimeExports.jsx(
413 "div",
414 {
415 role: "button",
416 tabIndex: 0,
417 onClick: openBooking,
418 onKeyDown: (e) => {
419 if (e.key === "Enter" || e.key === " ") {
420 e.preventDefault();
421 openBooking();
422 }
423 },
424 className: "yatra-booking-card yatra-booking-card-upcoming group relative border border-gray-200 dark:border-gray-700 rounded-xl p-5 hover:border-yatra-border-hover dark:hover:border-yatra-border-hover-dark hover:shadow-md transition-all cursor-pointer bg-gradient-to-r from-white to-gray-50/50 dark:from-gray-800 dark:to-gray-800/50",
425 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-4", children: [
426 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-12 h-12 bg-gradient-to-br from-yatra-primary to-yatra-primary-darker rounded-lg flex items-center justify-center shadow-sm", children: /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "w-6 h-6 text-white" }) }) }),
427 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
428 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between gap-2 mb-2", children: [
429 /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "text-sm font-semibold text-gray-900 dark:text-white group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark transition-colors", children: booking.trip_title }),
430 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.booking_status), children: getStatusLabel(booking.booking_status) })
431 ] }),
432 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400 mb-2 flex items-center gap-2", children: [
433 /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "w-4 h-4" }),
434 booking.destination || __("Multiple destinations", "yatra")
435 ] }),
436 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-4 text-xs text-gray-500 dark:text-gray-400", children: [
437 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "flex items-center gap-1", children: [
438 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-3.5 h-3.5" }),
439 formatTravelDateRange(
440 booking.travel_date,
441 booking.end_date
442 )
443 ] }),
444 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "flex items-center gap-1", children: [
445 /* @__PURE__ */ jsxRuntimeExports.jsx(User, { className: "w-3.5 h-3.5" }),
446 (() => {
447 const n = Number(
448 booking.travelers_count ?? booking.travelers ?? 0
449 ) || 0;
450 return n === 1 ? sprintf(__("%d Traveler", "yatra"), n) : sprintf(__("%d Travelers", "yatra"), n);
451 })()
452 ] })
453 ] })
454 ] }),
455 /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "w-5 h-5 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark transition-colors flex-shrink-0" })
456 ] })
457 },
458 booking.id
459 );
460 }) }) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center py-12", children: [
461 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 bg-gray-100 dark:bg-gray-700 rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-8 h-8 text-gray-400" }) }),
462 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 font-medium mb-1", children: __("No upcoming trips", "yatra") }),
463 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __("Start planning your next adventure!", "yatra") })
464 ] }) })
465 ] }),
466 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
467 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-dashboard-quick-actions bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm overflow-hidden", children: [
468 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-dashboard-quick-actions-header p-6 border-b border-gray-100 dark:border-gray-700", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
469 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-purple-50 dark:bg-purple-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Sparkles, { className: "w-5 h-5 text-purple-600 dark:text-purple-400" }) }),
470 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-semibold text-gray-900 dark:text-white", children: __("Quick Actions", "yatra") })
471 ] }) }),
472 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-6 space-y-3", children: [
473 /* @__PURE__ */ jsxRuntimeExports.jsxs(
474 "div",
475 {
476 role: "button",
477 tabIndex: 0,
478 onClick: () => onSectionChange("bookings"),
479 className: "w-full flex items-center justify-between p-4 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-yatra-border-hover dark:hover:border-yatra-border-hover-dark hover:bg-yatra-hover-soft dark:hover:bg-yatra-hover-soft-dark transition-all group cursor-pointer text-sm",
480 children: [
481 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
482 /* @__PURE__ */ jsxRuntimeExports.jsx(Package, { className: "w-5 h-5 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" }),
483 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700 dark:text-gray-300 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark", children: __("View Bookings", "yatra") })
484 ] }),
485 /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "w-4 h-4 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" })
486 ]
487 }
488 ),
489 /* @__PURE__ */ jsxRuntimeExports.jsxs(
490 "div",
491 {
492 role: "button",
493 tabIndex: 0,
494 onClick: () => onSectionChange("payments"),
495 className: "w-full flex items-center justify-between p-4 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-yatra-border-hover dark:hover:border-yatra-border-hover-dark hover:bg-yatra-hover-soft dark:hover:bg-yatra-hover-soft-dark transition-all group cursor-pointer text-sm",
496 children: [
497 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
498 /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-5 h-5 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" }),
499 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700 dark:text-gray-300 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark", children: __("Make Payment", "yatra") })
500 ] }),
501 /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "w-4 h-4 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" })
502 ]
503 }
504 ),
505 /* @__PURE__ */ jsxRuntimeExports.jsxs(
506 "div",
507 {
508 role: "button",
509 tabIndex: 0,
510 onClick: () => onSectionChange("documents"),
511 className: "w-full flex items-center justify-between p-4 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-yatra-border-hover dark:hover:border-yatra-border-hover-dark hover:bg-yatra-hover-soft dark:hover:bg-yatra-hover-soft-dark transition-all group cursor-pointer text-sm",
512 children: [
513 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
514 /* @__PURE__ */ jsxRuntimeExports.jsx(FileText, { className: "w-5 h-5 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" }),
515 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700 dark:text-gray-300 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark", children: __("My Documents", "yatra") })
516 ] }),
517 /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "w-4 h-4 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" })
518 ]
519 }
520 ),
521 conciergeTel ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
522 "a",
523 {
524 href: conciergeTel,
525 className: "w-full flex items-center justify-between p-4 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-yatra-border-hover dark:hover:border-yatra-border-hover-dark hover:bg-yatra-hover-soft dark:hover:bg-yatra-hover-soft-dark transition-all group cursor-pointer text-sm no-underline text-inherit",
526 children: [
527 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
528 /* @__PURE__ */ jsxRuntimeExports.jsx(LifeBuoy, { className: "w-5 h-5 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" }),
529 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700 dark:text-gray-300 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark", children: __("Call us", "yatra") })
530 ] }),
531 /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "w-4 h-4 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" })
532 ]
533 }
534 ) : conciergeMail ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
535 "a",
536 {
537 href: `mailto:${encodeURIComponent(conciergeMail)}`,
538 className: "w-full flex items-center justify-between p-4 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-yatra-border-hover dark:hover:border-yatra-border-hover-dark hover:bg-yatra-hover-soft dark:hover:bg-yatra-hover-soft-dark transition-all group cursor-pointer text-sm no-underline text-inherit",
539 children: [
540 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
541 /* @__PURE__ */ jsxRuntimeExports.jsx(LifeBuoy, { className: "w-5 h-5 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" }),
542 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700 dark:text-gray-300 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark", children: __("Email us", "yatra") })
543 ] }),
544 /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "w-4 h-4 text-gray-400 group-hover:text-yatra-primary dark:group-hover:text-yatra-on-dark" })
545 ]
546 }
547 ) : null
548 ] })
549 ] }),
550 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-dashboard-notifications bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm overflow-hidden", children: [
551 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-dashboard-notifications-header p-6 border-b border-gray-100 dark:border-gray-700", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
552 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-amber-50 dark:bg-amber-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Bell, { className: "w-5 h-5 text-amber-600 dark:text-amber-400" }) }),
553 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
554 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-semibold text-gray-900 dark:text-white", children: __("Notifications", "yatra") }),
555 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: __("Updates & reminders", "yatra") })
556 ] })
557 ] }) }),
558 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-6 space-y-3", children: displayNotifications.length > 0 ? displayNotifications.map((notif) => /* @__PURE__ */ jsxRuntimeExports.jsx(
559 "div",
560 {
561 className: `p-4 rounded-lg border ${notif.type === "warning" ? "bg-amber-50 dark:bg-amber-900/10 border-amber-200 dark:border-amber-800" : "bg-yatra-soft dark:bg-yatra-hover-soft-dark border-yatra-border-subtle dark:border-yatra-border-dark"}`,
562 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-3", children: [
563 notif.type === "warning" ? /* @__PURE__ */ jsxRuntimeExports.jsx(AlertCircle, { className: "w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle2, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark flex-shrink-0 mt-0.5" }),
564 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
565 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "font-semibold text-sm text-gray-900 dark:text-white mb-1", children: notif.title }),
566 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-600 dark:text-gray-400 leading-relaxed", children: notif.message })
567 ] })
568 ] })
569 },
570 notif.id
571 )) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center py-6", children: [
572 /* @__PURE__ */ jsxRuntimeExports.jsx(Bell, { className: "w-8 h-8 text-gray-300 dark:text-gray-600 mx-auto mb-2" }),
573 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __("No new notifications", "yatra") })
574 ] }) })
575 ] })
576 ] })
577 ] }),
578 (recentBookings.length > 0 || pendingPayments.length > 0) && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-dashboard-recent-activity bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm overflow-hidden", children: [
579 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-dashboard-recent-activity-header p-6 border-b border-gray-100 dark:border-gray-700", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
580 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-yatra-soft dark:bg-yatra-surface-dark-muted rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark" }) }),
581 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
582 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-semibold text-gray-900 dark:text-white", children: __("Recent Activity", "yatra") }),
583 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: __("Your latest updates", "yatra") })
584 ] })
585 ] }) }),
586 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
587 recentBookings.map((booking) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
588 "div",
589 {
590 className: "flex items-center gap-4 pb-4 border-b border-gray-100 dark:border-gray-700 last:border-0 last:pb-0",
591 children: [
592 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-10 h-10 bg-yatra-chip-bg dark:bg-yatra-surface-dark rounded-full flex items-center justify-center flex-shrink-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle2, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark" }) }),
593 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
594 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm font-medium text-gray-900 dark:text-white", children: [
595 __("Booking confirmed:", "yatra"),
596 " ",
597 booking.trip_title
598 ] }),
599 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: formatDate(booking.booking_date || booking.created_at) })
600 ] }),
601 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.booking_status), children: getStatusLabel(booking.booking_status) })
602 ]
603 },
604 booking.id
605 )),
606 pendingPayments.map((payment) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
607 "div",
608 {
609 className: "flex items-center gap-4 pb-4 border-b border-gray-100 dark:border-gray-700 last:border-0 last:pb-0",
610 children: [
611 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-10 h-10 bg-amber-100 dark:bg-amber-900/30 rounded-full flex items-center justify-center flex-shrink-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "w-5 h-5 text-amber-600 dark:text-amber-400" }) }),
612 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
613 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm font-medium text-gray-900 dark:text-white", children: [
614 __("Payment pending:", "yatra"),
615 " ",
616 currency(payment.amount)
617 ] }),
618 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: formatDate(payment.date) })
619 ] }),
620 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(payment.status), children: getStatusLabel(payment.status) })
621 ]
622 },
623 payment.id
624 ))
625 ] }) })
626 ] })
627 ] });
628 };
629 function getAccountRestConfig() {
630 var _a, _b, _c, _d;
631 if (typeof window === "undefined") {
632 return { base: "/wp-json/yatra/v1", nonce: "" };
633 }
634 const w = window;
635 const raw = ((_a = w.yatraAccountPage) == null ? void 0 : _a.apiUrl) || ((_b = w.yatraAdmin) == null ? void 0 : _b.apiUrl) || "/wp-json/yatra/v1";
636 const base = String(raw).replace(/\/$/, "");
637 const nonce = ((_c = w.yatraAccountPage) == null ? void 0 : _c.nonce) || ((_d = w.yatraAdmin) == null ? void 0 : _d.nonce) || "";
638 return { base, nonce };
639 }
640 function parseYatraRestSubpath(href) {
641 const origin = typeof window !== "undefined" ? window.location.origin : "http://localhost";
642 try {
643 const u = new URL(href, origin);
644 const rr = u.searchParams.get("rest_route");
645 if (rr) {
646 const decoded = decodeURIComponent(rr.replace(/\+/g, " "));
647 const idx = decoded.indexOf("/yatra/v1");
648 if (idx !== -1) {
649 return decoded.slice(idx + "/yatra/v1".length) || decoded;
650 }
651 return decoded;
652 }
653 const path = u.pathname || "";
654 const marker = "/yatra/v1";
655 const pos = path.indexOf(marker);
656 if (pos !== -1) {
657 return path.slice(pos + marker.length);
658 }
659 } catch {
660 }
661 return "";
662 }
663 function parsePaymentIdFromHref(href) {
664 const sub = parseYatraRestSubpath(href);
665 const m = sub.match(/^\/payment\/(\d+)\/invoice(?:\/?|$)/i);
666 return m ? parseInt(m[1], 10) : null;
667 }
668 function parseBookingDocFromHref(href, kind) {
669 const sub = parseYatraRestSubpath(href);
670 const re = new RegExp(`^/bookings/(\\d+)/${kind}(?:/?|$)`, "i");
671 const m = sub.match(re);
672 return m ? parseInt(m[1], 10) : null;
673 }
674 function buildBookingDocumentUrl(baseRaw, bookingId, kind, mode = "download") {
675 const suffix = `/bookings/${bookingId}/${kind}`;
676 const origin = typeof window !== "undefined" ? window.location.origin : "http://localhost";
677 let u;
678 try {
679 u = new URL(String(baseRaw).trim(), origin);
680 } catch {
681 const b = String(baseRaw).replace(/\/$/, "");
682 const q = mode === "download" ? "?download=1" : "?preview=1";
683 return `${b}${suffix}${q}`;
684 }
685 if (u.searchParams.has("rest_route")) {
686 const route = (u.searchParams.get("rest_route") || "").replace(/\/$/, "");
687 u.searchParams.set("rest_route", `${route}${suffix}`);
688 if (mode === "download") {
689 u.searchParams.set("download", "1");
690 u.searchParams.delete("preview");
691 } else {
692 u.searchParams.set("preview", "1");
693 u.searchParams.delete("download");
694 }
695 return u.toString();
696 }
697 u.pathname = (u.pathname || "").replace(/\/$/, "") + suffix;
698 if (mode === "download") {
699 u.searchParams.set("download", "1");
700 u.searchParams.delete("preview");
701 } else {
702 u.searchParams.set("preview", "1");
703 u.searchParams.delete("download");
704 }
705 return u.toString();
706 }
707 function buildPaymentInvoiceUrl(baseRaw, paymentId, mode) {
708 const suffix = `/payment/${paymentId}/invoice`;
709 const origin = typeof window !== "undefined" ? window.location.origin : "http://localhost";
710 let u;
711 try {
712 u = new URL(String(baseRaw).trim(), origin);
713 } catch {
714 const b = String(baseRaw).replace(/\/$/, "");
715 const q = mode === "download" ? "?download=1" : "?preview=1";
716 return `${b}${suffix}${q}`;
717 }
718 if (u.searchParams.has("rest_route")) {
719 const route = (u.searchParams.get("rest_route") || "").replace(/\/$/, "");
720 u.searchParams.set("rest_route", `${route}${suffix}`);
721 if (mode === "download") {
722 u.searchParams.set("download", "1");
723 u.searchParams.delete("preview");
724 } else {
725 u.searchParams.set("preview", "1");
726 u.searchParams.delete("download");
727 }
728 return u.toString();
729 }
730 u.pathname = (u.pathname || "").replace(/\/$/, "") + suffix;
731 if (mode === "download") {
732 u.searchParams.set("download", "1");
733 u.searchParams.delete("preview");
734 } else {
735 u.searchParams.set("preview", "1");
736 u.searchParams.delete("download");
737 }
738 return u.toString();
739 }
740 async function readFetchErrorMessage(res) {
741 let msg = res.statusText || __("Request failed", "yatra");
742 try {
743 const j = await res.json();
744 if (j == null ? void 0 : j.message) {
745 msg = typeof j.message === "string" ? j.message : msg;
746 }
747 } catch {
748 const t = await res.text().catch(() => "");
749 if (t && t.length < 200) {
750 msg = t;
751 }
752 }
753 return msg;
754 }
755 async function fetchPreviewPdf(url) {
756 const { nonce } = getAccountRestConfig();
757 if (!nonce) {
758 throw new Error(
759 __(
760 "Missing security token. Reload the account page and try again.",
761 "yatra"
762 )
763 );
764 }
765 const res = await fetch(url, {
766 method: "GET",
767 credentials: "include",
768 headers: {
769 "X-WP-Nonce": nonce,
770 Accept: "application/json"
771 }
772 });
773 if (!res.ok) {
774 throw new Error(await readFetchErrorMessage(res));
775 }
776 const data = await res.json();
777 if (!(data == null ? void 0 : data.pdf_data) || typeof data.pdf_data !== "string") {
778 throw new Error(__("Invalid preview response from the server.", "yatra"));
779 }
780 const binary = atob(data.pdf_data);
781 const bytes = new Uint8Array(binary.length);
782 for (let i = 0; i < binary.length; i++) {
783 bytes[i] = binary.charCodeAt(i);
784 }
785 return new Blob([bytes], { type: "application/pdf" });
786 }
787 function openPdfInPreOpenedWindow(blob, preOpened, filename) {
788 const objectUrl = URL.createObjectURL(blob);
789 if (preOpened && !preOpened.closed) {
790 try {
791 preOpened.location.href = objectUrl;
792 window.setTimeout(() => URL.revokeObjectURL(objectUrl), 6e4);
793 return;
794 } catch {
795 try {
796 preOpened.close();
797 } catch {
798 }
799 }
800 }
801 const link = document.createElement("a");
802 link.href = objectUrl;
803 link.target = "_blank";
804 link.rel = "noopener noreferrer";
805 document.body.appendChild(link);
806 link.click();
807 document.body.removeChild(link);
808 window.setTimeout(() => URL.revokeObjectURL(objectUrl), 6e4);
809 }
810 async function downloadBookingBinary(bookingId, kind) {
811 const { base, nonce } = getAccountRestConfig();
812 if (!nonce) {
813 throw new Error(
814 __(
815 "Missing security token. Reload the account page and try again.",
816 "yatra"
817 )
818 );
819 }
820 const url = buildBookingDocumentUrl(base, bookingId, kind, "download");
821 const res = await fetch(url, {
822 method: "GET",
823 credentials: "include",
824 headers: {
825 "X-WP-Nonce": nonce,
826 Accept: "application/pdf, application/octet-stream, */*"
827 }
828 });
829 if (!res.ok) {
830 throw new Error(await readFetchErrorMessage(res));
831 }
832 const blob = await res.blob();
833 const dispo = res.headers.get("Content-Disposition");
834 let filename = `${kind}-${bookingId}.pdf`;
835 if (dispo) {
836 const m = /filename\*?=(?:UTF-8'')?["']?([^";\n]+)/i.exec(dispo);
837 if (m == null ? void 0 : m[1]) {
838 try {
839 filename = decodeURIComponent(m[1].replace(/['"]/g, "").trim());
840 } catch {
841 filename = m[1].replace(/['"]/g, "").trim();
842 }
843 }
844 }
845 const objectUrl = URL.createObjectURL(blob);
846 const link = document.createElement("a");
847 link.href = objectUrl;
848 link.download = filename;
849 document.body.appendChild(link);
850 link.click();
851 document.body.removeChild(link);
852 URL.revokeObjectURL(objectUrl);
853 }
854 async function downloadPaymentInvoiceBinary(paymentId) {
855 const { base, nonce } = getAccountRestConfig();
856 if (!nonce) {
857 throw new Error(
858 __(
859 "Missing security token. Reload the account page and try again.",
860 "yatra"
861 )
862 );
863 }
864 const url = buildPaymentInvoiceUrl(base, paymentId, "download");
865 const res = await fetch(url, {
866 method: "GET",
867 credentials: "include",
868 headers: {
869 "X-WP-Nonce": nonce,
870 Accept: "application/pdf, application/octet-stream, */*"
871 }
872 });
873 if (!res.ok) {
874 throw new Error(await readFetchErrorMessage(res));
875 }
876 const blob = await res.blob();
877 const dispo = res.headers.get("Content-Disposition");
878 let filename = `invoice-${paymentId}.pdf`;
879 if (dispo) {
880 const m = /filename\*?=(?:UTF-8'')?["']?([^";\n]+)/i.exec(dispo);
881 if (m == null ? void 0 : m[1]) {
882 try {
883 filename = decodeURIComponent(m[1].replace(/['"]/g, "").trim());
884 } catch {
885 filename = m[1].replace(/['"]/g, "").trim();
886 }
887 }
888 }
889 const objectUrl = URL.createObjectURL(blob);
890 const link = document.createElement("a");
891 link.href = objectUrl;
892 link.download = filename;
893 document.body.appendChild(link);
894 link.click();
895 document.body.removeChild(link);
896 URL.revokeObjectURL(objectUrl);
897 }
898 const downloadDocument = async (options) => {
899 if (options.documentType === "downloads" && options.fallbackUrl) {
900 window.open(options.fallbackUrl, "_blank", "noopener,noreferrer");
901 return;
902 }
903 if (options.documentType === "invoice") {
904 const pid = options.paymentId ?? parsePaymentIdFromHref(options.fallbackUrl || "");
905 if (pid) {
906 await downloadPaymentInvoiceBinary(pid);
907 return;
908 }
909 }
910 if (options.documentType === "voucher" || options.documentType === "itinerary") {
911 const kind = options.documentType === "voucher" ? "voucher" : "itinerary";
912 const bid = options.bookingId ?? parseBookingDocFromHref(options.fallbackUrl || "", kind);
913 if (bid) {
914 await downloadBookingBinary(bid, kind);
915 return;
916 }
917 }
918 if (options.bookingId && options.documentType === "all") {
919 await downloadBookingBinary(options.bookingId, "voucher");
920 return;
921 }
922 console.error(`No handler for document type: ${options.documentType}`);
923 };
924 const downloadVoucher = (bookingId) => downloadBookingBinary(bookingId, "voucher");
925 const downloadInvoice = (paymentId) => downloadPaymentInvoiceBinary(paymentId);
926 function preOpenPreviewWindow() {
927 if (typeof window === "undefined") return null;
928 try {
929 return window.open("about:blank", "_blank");
930 } catch {
931 return null;
932 }
933 }
934 const previewPaymentInvoice = async (paymentId) => {
935 const preOpened = preOpenPreviewWindow();
936 try {
937 const { base, nonce } = getAccountRestConfig();
938 if (!nonce) {
939 throw new Error(
940 __(
941 "Missing security token. Reload the account page and try again.",
942 "yatra"
943 )
944 );
945 }
946 const url = buildPaymentInvoiceUrl(base, paymentId, "preview");
947 const blob = await fetchPreviewPdf(url);
948 openPdfInPreOpenedWindow(blob, preOpened, `invoice-${paymentId}.pdf`);
949 } catch (e) {
950 if (preOpened && !preOpened.closed) {
951 try {
952 preOpened.close();
953 } catch {
954 }
955 }
956 throw e;
957 }
958 };
959 async function previewTravelDocument(doc) {
960 const preOpened = preOpenPreviewWindow();
961 try {
962 const { base, nonce } = getAccountRestConfig();
963 if (!nonce) {
964 throw new Error(
965 __(
966 "Missing security token. Reload the account page and try again.",
967 "yatra"
968 )
969 );
970 }
971 if (doc.category === "invoice") {
972 const pid = doc.payment_id ?? parsePaymentIdFromHref(doc.url);
973 if (!pid) {
974 throw new Error(__("Could not resolve invoice link.", "yatra"));
975 }
976 const url = buildPaymentInvoiceUrl(base, pid, "preview");
977 const blob = await fetchPreviewPdf(url);
978 openPdfInPreOpenedWindow(blob, preOpened, `invoice-${pid}.pdf`);
979 return;
980 }
981 if (doc.category === "voucher" || doc.category === "itinerary") {
982 const kind = doc.category === "voucher" ? "voucher" : "itinerary";
983 const bid = doc.booking_id ?? parseBookingDocFromHref(doc.url, kind);
984 if (!bid) {
985 throw new Error(__("Could not resolve document link.", "yatra"));
986 }
987 const url = buildBookingDocumentUrl(base, bid, kind, "preview");
988 const blob = await fetchPreviewPdf(url);
989 openPdfInPreOpenedWindow(blob, preOpened, `${kind}-${bid}.pdf`);
990 return;
991 }
992 if (preOpened && !preOpened.closed) {
993 preOpened.location.href = doc.url;
994 } else {
995 window.open(doc.url, "_blank", "noopener,noreferrer");
996 }
997 } catch (e) {
998 if (preOpened && !preOpened.closed) {
999 try {
1000 preOpened.close();
1001 } catch {
1002 }
1003 }
1004 throw e;
1005 }
1006 }
1007 const getCountryName = (code) => {
1008 if (!code || typeof code !== "string") {
1009 return "";
1010 }
1011 const upperCode = code.trim().toUpperCase();
1012 if (upperCode.length !== 2) {
1013 return code;
1014 }
1015 try {
1016 const locale = getYatraAccountPageGlobals().locale;
1017 const tag = locale ? locale.replace(/_/g, "-") : void 0;
1018 const display = new Intl.DisplayNames(tag ? [tag] : void 0, {
1019 type: "region"
1020 });
1021 const name = display.of(upperCode);
1022 return name && name !== upperCode ? name : code;
1023 } catch {
1024 return code;
1025 }
1026 };
1027 let knownFieldLabels = null;
1028 const getKnownFieldLabels = () => {
1029 if (knownFieldLabels === null) {
1030 knownFieldLabels = {
1031 first_name: __("First Name", "yatra"),
1032 last_name: __("Last Name", "yatra"),
1033 full_name: __("Full Name", "yatra"),
1034 name: __("Name", "yatra"),
1035 email: __("Email", "yatra"),
1036 phone: __("Phone", "yatra"),
1037 mobile: __("Mobile", "yatra"),
1038 date_of_birth: __("Date of Birth", "yatra"),
1039 gender: __("Gender", "yatra"),
1040 nationality: __("Nationality", "yatra"),
1041 country: __("Country", "yatra"),
1042 address: __("Address", "yatra"),
1043 city: __("City", "yatra"),
1044 state: __("State", "yatra"),
1045 postal_code: __("Postal Code", "yatra"),
1046 zip_code: __("Zip Code", "yatra"),
1047 passport: __("Passport", "yatra"),
1048 passport_number: __("Passport Number", "yatra"),
1049 passport_expiry: __("Passport Expiry", "yatra"),
1050 dietary_requirements: __("Dietary Requirements", "yatra"),
1051 special_requirements: __("Special Requirements", "yatra"),
1052 relationship: __("Relationship", "yatra"),
1053 company: __("Company", "yatra")
1054 };
1055 }
1056 return knownFieldLabels;
1057 };
1058 const fieldLabel = (fieldId) => {
1059 const known = getKnownFieldLabels();
1060 if (Object.prototype.hasOwnProperty.call(known, fieldId)) {
1061 return known[fieldId];
1062 }
1063 return fieldId.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase());
1064 };
1065 const BookingDetails = ({
1066 booking,
1067 isLoading,
1068 onBack
1069 }) => {
1070 var _a;
1071 if (isLoading) {
1072 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
1073 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1074 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white", children: __("Booking Details", "yatra") }) }),
1075 /* @__PURE__ */ jsxRuntimeExports.jsxs(
1076 "div",
1077 {
1078 role: "button",
1079 tabIndex: 0,
1080 onClick: onBack,
1081 className: "inline-flex items-center gap-2 px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors cursor-pointer",
1082 children: [
1083 /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowRight, { className: "w-4 h-4 rotate-180" }),
1084 __("Back to Bookings", "yatra")
1085 ]
1086 }
1087 )
1088 ] }),
1089 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse space-y-4", children: [
1090 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-3/4" }),
1091 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-1/2" }),
1092 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-2/3" })
1093 ] }) })
1094 ] });
1095 }
1096 if (!booking) {
1097 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
1098 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1099 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white", children: __("Booking Details", "yatra") }) }),
1100 /* @__PURE__ */ jsxRuntimeExports.jsxs(
1101 "div",
1102 {
1103 role: "button",
1104 tabIndex: 0,
1105 onClick: onBack,
1106 className: "inline-flex items-center gap-2 px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors cursor-pointer",
1107 children: [
1108 /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowRight, { className: "w-4 h-4 rotate-180" }),
1109 __("Back to Bookings", "yatra")
1110 ]
1111 }
1112 )
1113 ] }),
1114 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6 text-center text-red-500", children: __("Booking not found or error loading booking", "yatra") })
1115 ] });
1116 }
1117 const normalizeRecord = (value) => {
1118 if (!value) return null;
1119 if (typeof value === "string") {
1120 try {
1121 const parsed = JSON.parse(value);
1122 if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
1123 return parsed;
1124 } catch {
1125 return null;
1126 }
1127 return null;
1128 }
1129 if (typeof value === "object" && !Array.isArray(value)) {
1130 return value;
1131 }
1132 return null;
1133 };
1134 const emergencyContact = normalizeRecord(booking.emergency_contact);
1135 const contactData = normalizeRecord(booking.contact_data);
1136 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
1137 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1138 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1139 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white", children: __("Booking Details", "yatra") }),
1140 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-1", children: __("Complete booking information", "yatra") })
1141 ] }),
1142 /* @__PURE__ */ jsxRuntimeExports.jsxs(
1143 "div",
1144 {
1145 role: "button",
1146 tabIndex: 0,
1147 onClick: onBack,
1148 className: "inline-flex items-center gap-2 px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors cursor-pointer",
1149 children: [
1150 /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowRight, { className: "w-4 h-4 rotate-180" }),
1151 __("Back to Bookings", "yatra")
1152 ]
1153 }
1154 )
1155 ] }),
1156 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 lg:grid-cols-3 gap-6", children: [
1157 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "lg:col-span-2 space-y-6", children: [
1158 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1159 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-between mb-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: __("Booking Overview", "yatra") }) }),
1160 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1161 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1162 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Booking Number", "yatra") }),
1163 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: booking.booking_number || `#${booking.id}` })
1164 ] }),
1165 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1166 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Trip", "yatra") }),
1167 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: booking.trip_title }),
1168 booking.trip_url ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
1169 "a",
1170 {
1171 href: booking.trip_url,
1172 className: "mt-2 inline-flex items-center gap-2 text-sm text-yatra-primary dark:text-yatra-on-dark hover:underline",
1173 children: [
1174 /* @__PURE__ */ jsxRuntimeExports.jsx(ExternalLink, { className: "w-4 h-4" }),
1175 __("View Trip", "yatra")
1176 ]
1177 }
1178 ) : null
1179 ] }),
1180 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1181 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1 flex items-center gap-1", children: [
1182 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-3 h-3" }),
1183 __("Booking Date", "yatra")
1184 ] }),
1185 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatDate(booking.booking_date || booking.created_at) })
1186 ] }),
1187 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1188 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1 flex items-center gap-1", children: [
1189 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-3 h-3" }),
1190 __("Travel Date", "yatra")
1191 ] }),
1192 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatTravelDateRange(booking.travel_date, booking.end_date) })
1193 ] }),
1194 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1195 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1 flex items-center gap-1", children: [
1196 /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "w-3 h-3" }),
1197 __("Number of Travelers", "yatra")
1198 ] }),
1199 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: (() => {
1200 const t = booking.travelers;
1201 const n = Number(
1202 booking.travelers_count ?? (Array.isArray(t) ? t.length : t) ?? 0
1203 ) || 0;
1204 return n === 1 ? sprintf(__("%d Traveler", "yatra"), n) : sprintf(__("%d Travelers", "yatra"), n);
1205 })() })
1206 ] })
1207 ] }),
1208 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-4 pt-4 border-t border-gray-200 dark:border-gray-700", children: [
1209 /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "text-sm font-semibold text-gray-900 dark:text-white mb-3", children: __("Payment Summary", "yatra") }),
1210 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
1211 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
1212 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-600 dark:text-gray-400", children: __("Gross Total", "yatra") }),
1213 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1214 booking.subtotal || booking.total_amount,
1215 booking.currency
1216 ) })
1217 ] }),
1218 typeof booking.taxable_amount === "number" && booking.taxable_amount > 0 && (booking.tax_amount > 0 || ((_a = booking.tax_breakdown) == null ? void 0 : _a.length) > 0) && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm font-medium", children: [
1219 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-600 dark:text-gray-400", children: __("Subtotal (Taxable Amount)", "yatra") }),
1220 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1221 booking.taxable_amount,
1222 booking.currency
1223 ) })
1224 ] }),
1225 booking.discount_amount && booking.discount_amount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
1226 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-600 dark:text-gray-400", children: __("Discount", "yatra") }),
1227 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-green-600 dark:text-green-400", children: [
1228 "-",
1229 formatPriceForBooking(
1230 booking.discount_amount,
1231 booking.currency
1232 )
1233 ] })
1234 ] }),
1235 booking.itinerary_costs && booking.itinerary_costs.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1236 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex justify-between text-sm", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-600 dark:text-gray-400 font-medium", children: __("Itinerary Costs", "yatra") }) }),
1237 booking.itinerary_costs.map((cost, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1238 "div",
1239 {
1240 className: "flex justify-between text-sm ml-4",
1241 children: [
1242 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1243 cost.name,
1244 cost.price_per === "person" && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs text-gray-500 dark:text-gray-500 ml-1", children: [
1245 "(",
1246 __("per person", "yatra"),
1247 ")"
1248 ] }),
1249 cost.price_per === "group" && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs text-gray-500 dark:text-gray-500 ml-1", children: [
1250 "(",
1251 __("per booking", "yatra"),
1252 ")"
1253 ] })
1254 ] }),
1255 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1256 cost.total_cost,
1257 booking.currency
1258 ) })
1259 ]
1260 },
1261 index
1262 ))
1263 ] }),
1264 booking.tax_amount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: (() => {
1265 const taxBreakdown = booking.tax_breakdown;
1266 if (Array.isArray(taxBreakdown) && taxBreakdown.length > 0) {
1267 return taxBreakdown.map((tax, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1268 "div",
1269 {
1270 className: "flex justify-between text-sm",
1271 children: [
1272 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1273 tax.name,
1274 " (",
1275 tax.rate,
1276 "%)"
1277 ] }),
1278 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1279 tax.amount,
1280 booking.currency
1281 ) })
1282 ]
1283 },
1284 index
1285 ));
1286 }
1287 const taxDetails = booking.tax_details;
1288 if (taxDetails) {
1289 try {
1290 const taxes = typeof taxDetails === "string" ? JSON.parse(taxDetails) : taxDetails;
1291 if (Array.isArray(taxes) && taxes.length > 0) {
1292 return taxes.map((tax, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1293 "div",
1294 {
1295 className: "flex justify-between text-sm",
1296 children: [
1297 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1298 tax.name,
1299 " (",
1300 tax.rate,
1301 "%)"
1302 ] }),
1303 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1304 tax.amount,
1305 booking.currency
1306 ) })
1307 ]
1308 },
1309 index
1310 ));
1311 }
1312 } catch (e) {
1313 console.error("Failed to parse tax_details:", e);
1314 }
1315 }
1316 if (booking.tax_amount > 0) {
1317 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
1318 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1319 __("Tax", "yatra"),
1320 " (",
1321 booking.tax_rate,
1322 "%)"
1323 ] }),
1324 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1325 booking.tax_amount,
1326 booking.currency
1327 ) })
1328 ] });
1329 }
1330 return null;
1331 })() }),
1332 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-base font-semibold pt-2 border-t border-gray-200 dark:border-gray-700", children: [
1333 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: __("Net Amount", "yatra") }),
1334 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1335 booking.total_amount,
1336 booking.currency
1337 ) })
1338 ] })
1339 ] })
1340 ] })
1341 ] }),
1342 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1343 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4", children: __("Customer Information", "yatra") }),
1344 (() => {
1345 const leadTraveler = Array.isArray(booking.travelers_data) && booking.travelers_data.length > 0 ? booking.travelers_data[0] : null;
1346 const leadFields = leadTraveler && typeof leadTraveler === "object" ? leadTraveler.fields || leadTraveler : null;
1347 const firstName = booking.contact_first_name || leadFields && leadFields.first_name || "";
1348 const lastName = booking.contact_last_name || leadFields && leadFields.last_name || "";
1349 const fullName = [firstName, lastName].filter(Boolean).join(" ").trim() || booking.customer_name || "";
1350 const email = booking.contact_email || booking.customer_email || leadFields && leadFields.email || "";
1351 const phone = booking.contact_phone || booking.customer_phone || leadFields && leadFields.phone || "";
1352 const country = booking.contact_country || leadFields && leadFields.country || "";
1353 const hasAny = fullName || email || phone || country;
1354 if (!hasAny) {
1355 return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: __("No customer information recorded.", "yatra") });
1356 }
1357 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
1358 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1359 fullName && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium text-gray-900 dark:text-white mb-1", children: fullName }),
1360 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-sm text-gray-600 dark:text-gray-400", children: [
1361 email && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1.5", children: [
1362 /* @__PURE__ */ jsxRuntimeExports.jsx(Mail, { className: "w-4 h-4" }),
1363 /* @__PURE__ */ jsxRuntimeExports.jsx(
1364 "a",
1365 {
1366 href: `mailto:${email}`,
1367 className: "hover:text-yatra-primary dark:hover:text-yatra-on-dark",
1368 children: email
1369 }
1370 )
1371 ] }),
1372 phone && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1.5", children: [
1373 /* @__PURE__ */ jsxRuntimeExports.jsx(Phone, { className: "w-4 h-4" }),
1374 /* @__PURE__ */ jsxRuntimeExports.jsx(
1375 "a",
1376 {
1377 href: `tel:${String(phone).replace(/\s+/g, "")}`,
1378 className: "hover:text-yatra-primary dark:hover:text-yatra-on-dark",
1379 children: phone
1380 }
1381 )
1382 ] }),
1383 country && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: getCountryName(country) })
1384 ] })
1385 ] }),
1386 (() => {
1387 const CORE = [
1388 "first_name",
1389 "last_name",
1390 "email",
1391 "phone",
1392 "country"
1393 ];
1394 const extras = contactData ? Object.entries(contactData).filter(
1395 ([k, v]) => !CORE.includes(k) && v != null && String(v).trim() !== ""
1396 ) : [];
1397 if (extras.length === 0) return null;
1398 return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-2 md:grid-cols-3 gap-3 pt-3 border-t border-gray-100 dark:border-gray-700", children: extras.map(([fieldId, value]) => {
1399 const label = fieldLabel(fieldId);
1400 let displayValue = String(value);
1401 if ((fieldId === "nationality" || fieldId === "country") && typeof value === "string" && value.length === 2) {
1402 displayValue = getCountryName(value);
1403 }
1404 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1405 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mb-0.5", children: label }),
1406 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: displayValue })
1407 ] }, fieldId);
1408 }) });
1409 })()
1410 ] });
1411 })()
1412 ] }),
1413 booking.travelers_data && booking.travelers_data.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1414 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1415 /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "w-5 h-5" }),
1416 __("Travelers Information", "yatra"),
1417 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-sm font-normal text-gray-500 dark:text-gray-400", children: [
1418 "(",
1419 booking.travelers_data.length,
1420 " ",
1421 booking.travelers_data.length === 1 ? __("traveler", "yatra") : __("travelers", "yatra"),
1422 ")"
1423 ] })
1424 ] }),
1425 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: booking.travelers_data.map((traveler, index) => {
1426 const travelerFieldsData = traveler.fields || traveler;
1427 const systemFields = [
1428 "id",
1429 "booking_id",
1430 "traveller_index",
1431 "is_lead",
1432 "created_at",
1433 "updated_at",
1434 "fields"
1435 ];
1436 const travelerEntries = Object.entries(
1437 travelerFieldsData
1438 ).filter(([key, value]) => {
1439 if (systemFields.includes(key)) return false;
1440 if (!value || typeof value === "string" && value.trim() === "")
1441 return false;
1442 if (typeof value === "object" && !Array.isArray(value))
1443 return false;
1444 return true;
1445 });
1446 const firstName = travelerFieldsData.first_name || traveler.first_name || "";
1447 const lastName = travelerFieldsData.last_name || traveler.last_name || "";
1448 return /* @__PURE__ */ jsxRuntimeExports.jsxs(
1449 "div",
1450 {
1451 className: `p-4 rounded-lg ${index === 0 ? "bg-yatra-soft dark:bg-yatra-surface-dark-muted border border-yatra-border-subtle dark:border-yatra-border-dark" : "bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700"}`,
1452 children: [
1453 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
1454 /* @__PURE__ */ jsxRuntimeExports.jsxs("h4", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: [
1455 index === 0 ? __("Lead Traveler", "yatra") : `${__("Traveler", "yatra")} ${index + 1}`,
1456 (firstName || lastName) && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-normal text-gray-500 dark:text-gray-400 ml-2", children: [
1457 "-",
1458 " ",
1459 [firstName, lastName].filter(Boolean).join(" ")
1460 ] })
1461 ] }),
1462 index === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs bg-yatra-chip-bg text-yatra-primary-dark dark:bg-yatra-surface-dark dark:text-yatra-primary-light px-2 py-0.5 rounded", children: __("Primary Contact", "yatra") })
1463 ] }),
1464 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-2 md:grid-cols-3 gap-3", children: travelerEntries.map(([fieldId, fieldValue]) => {
1465 if (fieldId === "first_name" || fieldId === "last_name")
1466 return null;
1467 const label = fieldLabel(fieldId);
1468 let displayValue = String(fieldValue);
1469 if (fieldId.includes("date") || fieldId.includes("expiry")) {
1470 try {
1471 displayValue = formatDate(fieldValue);
1472 } catch {
1473 displayValue = String(fieldValue);
1474 }
1475 }
1476 if ((fieldId === "nationality" || fieldId === "country") && fieldValue && typeof fieldValue === "string" && fieldValue.length === 2) {
1477 displayValue = getCountryName(fieldValue);
1478 }
1479 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1480 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mb-0.5", children: label }),
1481 /* @__PURE__ */ jsxRuntimeExports.jsx(
1482 "div",
1483 {
1484 className: `text-sm text-gray-900 dark:text-white ${fieldId === "passport" ? "font-mono" : ""}`,
1485 children: displayValue
1486 }
1487 )
1488 ] }, fieldId);
1489 }) })
1490 ]
1491 },
1492 index
1493 );
1494 }) })
1495 ] }),
1496 emergencyContact && Object.values(emergencyContact).some(
1497 (v) => v && String(v).trim() !== ""
1498 ) && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1499 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1500 /* @__PURE__ */ jsxRuntimeExports.jsx(AlertCircle, { className: "w-5 h-5" }),
1501 __("Emergency Contact", "yatra")
1502 ] }),
1503 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-3", children: Object.entries(emergencyContact).filter(
1504 ([_, value]) => value && String(value).trim() !== ""
1505 ).map(([fieldId, fieldValue]) => {
1506 const label = fieldLabel(fieldId);
1507 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1508 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mb-0.5", children: label }),
1509 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium text-gray-900 dark:text-white", children: String(fieldValue) })
1510 ] }, fieldId);
1511 }) })
1512 ] }),
1513 booking.notes && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1514 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1515 /* @__PURE__ */ jsxRuntimeExports.jsx(FileText, { className: "w-5 h-5" }),
1516 __("Special Requests", "yatra")
1517 ] }),
1518 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap", children: booking.notes })
1519 ] }),
1520 Array.isArray(booking.downloads) && booking.downloads.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1521 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1522 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-5 h-5" }),
1523 __("Downloads", "yatra")
1524 ] }),
1525 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-3", children: booking.downloads.map((d) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1526 "div",
1527 {
1528 className: "flex items-center justify-between gap-3 p-3 rounded-lg border border-gray-200 dark:border-gray-700",
1529 children: [
1530 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
1531 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium text-gray-900 dark:text-white truncate", children: d.title }),
1532 d.access_label ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mt-1", children: d.access_label }) : null,
1533 d.locked && d.locked_reason ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-amber-700 dark:text-amber-300 mt-1", children: d.locked_reason }) : null
1534 ] }),
1535 d.locked || !d.url ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "inline-flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 text-sm font-medium cursor-not-allowed", children: [
1536 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-4 h-4" }),
1537 __("Not Available", "yatra")
1538 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
1539 "a",
1540 {
1541 href: d.url,
1542 target: "_blank",
1543 rel: "noreferrer",
1544 className: "inline-flex items-center gap-2 px-3 py-2 rounded-lg bg-yatra-primary text-white hover:bg-yatra-primary-dark transition-colors text-sm font-medium",
1545 children: [
1546 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-4 h-4" }),
1547 __("Download", "yatra")
1548 ]
1549 }
1550 )
1551 ]
1552 },
1553 d.id
1554 )) })
1555 ] })
1556 ] }),
1557 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
1558 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1559 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4", children: __("Payment Information", "yatra") }),
1560 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
1561 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1562 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Booking Status", "yatra") }),
1563 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.booking_status), children: getStatusLabel(booking.booking_status) }) })
1564 ] }),
1565 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1566 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Payment Status", "yatra") }),
1567 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.payment_status), children: getStatusLabel(booking.payment_status) }) })
1568 ] }),
1569 booking.payment_method && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1570 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1 flex items-center gap-1", children: [
1571 /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-3 h-3" }),
1572 __("Payment Method", "yatra")
1573 ] }),
1574 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: booking.payment_method })
1575 ] }),
1576 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1577 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Total Amount", "yatra") }),
1578 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: formatPriceForBooking(
1579 booking.total_amount,
1580 booking.currency
1581 ) })
1582 ] }),
1583 booking.amount_paid > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1584 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Amount Paid", "yatra") }),
1585 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatPriceForBooking(
1586 booking.amount_paid,
1587 booking.currency
1588 ) })
1589 ] }),
1590 booking.amount_due > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1591 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Amount Due", "yatra") }),
1592 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-semibold text-amber-600 dark:text-amber-400", children: formatPriceForBooking(
1593 booking.amount_due,
1594 booking.currency
1595 ) })
1596 ] })
1597 ] })
1598 ] }),
1599 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
1600 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4", children: __("Timeline", "yatra") }),
1601 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
1602 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1603 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Created", "yatra") }),
1604 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatDate(booking.created_at || booking.booking_date) })
1605 ] }),
1606 booking.updated_at && booking.updated_at !== booking.created_at && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1607 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Last Updated", "yatra") }),
1608 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatDate(booking.updated_at) })
1609 ] })
1610 ] })
1611 ] })
1612 ] })
1613 ] })
1614 ] });
1615 };
1616 const Bookings = ({
1617 bookings,
1618 conciergePhone = "",
1619 conciergeEmail = "",
1620 onSectionChange,
1621 initialBookingId = null,
1622 onBookingIdConsumed
1623 }) => {
1624 const conciergeTel = phoneToTelHref(conciergePhone);
1625 const conciergeMail = String(conciergeEmail || "").trim();
1626 const [searchTerm, setSearchTerm] = reactExports.useState("");
1627 const [bookingFilter, setBookingFilter] = reactExports.useState("all");
1628 const [selectedBookingId, setSelectedBookingId] = reactExports.useState(
1629 initialBookingId
1630 );
1631 React.useEffect(() => {
1632 if (initialBookingId && initialBookingId !== selectedBookingId) {
1633 setSelectedBookingId(initialBookingId);
1634 onBookingIdConsumed == null ? void 0 : onBookingIdConsumed();
1635 }
1636 }, [initialBookingId]);
1637 const [payLoading, setPayLoading] = reactExports.useState(null);
1638 const {
1639 data: bookingDetailsData,
1640 isPending: isBookingDetailLoading,
1641 isError: isBookingDetailError
1642 } = useQuery({
1643 queryKey: ["booking-details", selectedBookingId],
1644 queryFn: async () => {
1645 if (!selectedBookingId) return null;
1646 const response = await apiClient.get(
1647 API_ENDPOINTS.CUSTOMER_MY_BOOKING(selectedBookingId)
1648 );
1649 const inner = response && typeof response === "object" && "data" in response && response.data && typeof response.data === "object" ? response.data : response;
1650 return inner;
1651 },
1652 enabled: !!selectedBookingId
1653 });
1654 const handleBookingSelect = (bookingId) => {
1655 setSelectedBookingId(bookingId);
1656 };
1657 const handleBackToList = () => {
1658 setSelectedBookingId(null);
1659 };
1660 const handleDownloadClick = async (bookingId) => {
1661 try {
1662 await downloadVoucher(bookingId);
1663 } catch (e) {
1664 const msg = e instanceof Error ? e.message : __("Download failed.", "yatra");
1665 window.alert(msg);
1666 }
1667 };
1668 const startRemainingPaymentSession = async (bookingId) => {
1669 setPayLoading(bookingId);
1670 try {
1671 const response = await apiClient.post(
1672 API_ENDPOINTS.PAYMENT_REMAINING_SESSION,
1673 { booking_id: bookingId }
1674 );
1675 const payload = response && typeof response === "object" && "data" in response && response.data && typeof response.data === "object" ? response.data : response;
1676 const checkoutUrl = payload && typeof payload === "object" && "checkout_url" in payload && typeof payload.checkout_url === "string" ? payload.checkout_url : "";
1677 if (checkoutUrl) {
1678 window.location.href = checkoutUrl;
1679 } else {
1680 window.alert(__("Could not start payment. Please try again.", "yatra"));
1681 }
1682 } catch (error) {
1683 console.error("Error initiating payment:", error);
1684 const msg = error instanceof Error && error.message ? error.message : __("Could not start payment.", "yatra");
1685 window.alert(msg);
1686 } finally {
1687 setPayLoading(null);
1688 }
1689 };
1690 if (selectedBookingId) {
1691 return /* @__PURE__ */ jsxRuntimeExports.jsx(
1692 BookingDetails,
1693 {
1694 booking: isBookingDetailLoading || isBookingDetailError ? null : bookingDetailsData,
1695 isLoading: isBookingDetailLoading,
1696 onBack: handleBackToList
1697 }
1698 );
1699 }
1700 const displayBookings = bookings;
1701 let filteredDisplayBookings = displayBookings;
1702 if (bookingFilter === "upcoming") {
1703 const today = /* @__PURE__ */ new Date();
1704 today.setHours(0, 0, 0, 0);
1705 filteredDisplayBookings = filteredDisplayBookings.filter((b) => {
1706 const travelDate = toDateValue(b.travel_date);
1707 return travelDate >= today;
1708 });
1709 } else if (bookingFilter === "pending") {
1710 filteredDisplayBookings = filteredDisplayBookings.filter(
1711 (b) => b.payment_status === "pending" || b.booking_status === "pending"
1712 );
1713 } else if (bookingFilter === "completed") {
1714 filteredDisplayBookings = filteredDisplayBookings.filter(
1715 (b) => b.booking_status === "completed"
1716 );
1717 }
1718 if (searchTerm.trim()) {
1719 const searchLower = searchTerm.toLowerCase().trim();
1720 filteredDisplayBookings = filteredDisplayBookings.filter(
1721 (b) => b.trip_title && b.trip_title.toLowerCase().includes(searchLower) || b.booking_number && b.booking_number.toLowerCase().includes(searchLower) || b.destination && b.destination.toLowerCase().includes(searchLower) || b.payment_status && b.payment_status.toLowerCase().includes(searchLower) || b.booking_status && b.booking_status.toLowerCase().includes(searchLower)
1722 );
1723 }
1724 const bookingStats = {
1725 total: displayBookings.length,
1726 upcoming: displayBookings.filter(
1727 (b) => toDateValue(b.travel_date) >= /* @__PURE__ */ new Date()
1728 ).length,
1729 pending: displayBookings.filter(
1730 (b) => b.payment_status === "pending" || b.booking_status === "pending"
1731 ).length,
1732 completed: displayBookings.filter((b) => b.booking_status === "completed").length,
1733 totalSpent: displayBookings.reduce((sum, b) => sum + b.total_amount, 0)
1734 };
1735 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-bookings-page space-y-6", children: [
1736 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-bookings-header bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between", children: [
1737 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1738 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-bold text-gray-900 dark:text-white", children: __("Bookings", "yatra") }),
1739 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-2", children: __("Manage and view all your travel bookings", "yatra") })
1740 ] }),
1741 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3 lg:flex-row lg:items-center lg:gap-4", children: [
1742 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1743 "input",
1744 {
1745 placeholder: __("Search bookings...", "yatra"),
1746 value: searchTerm,
1747 onChange: (e) => setSearchTerm(e.target.value),
1748 className: "w-full lg:w-64 pl-4 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-yatra-primary focus:border-transparent"
1749 }
1750 ) }),
1751 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
1752 "select",
1753 {
1754 value: bookingFilter,
1755 onChange: (e) => setBookingFilter(
1756 e.target.value
1757 ),
1758 className: "appearance-none bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg px-4 py-2 pr-4 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-yatra-primary focus:border-transparent cursor-pointer",
1759 children: [
1760 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "all", children: __("All Bookings", "yatra") }),
1761 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "upcoming", children: __("Upcoming", "yatra") }),
1762 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "pending", children: __("Pending", "yatra") }),
1763 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "completed", children: __("Completed", "yatra") })
1764 ]
1765 }
1766 ) })
1767 ] })
1768 ] }) }),
1769 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-nowrap gap-6 overflow-x-auto", children: [
1770 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 bg-white dark:bg-gray-800 rounded-xl p-6 border border-gray-100 dark:border-gray-700 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1771 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1772 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Bookings", "yatra") }),
1773 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: bookingStats.total })
1774 ] }),
1775 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-yatra-soft dark:bg-yatra-surface-dark-muted rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Package, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark" }) })
1776 ] }) }),
1777 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 bg-white dark:bg-gray-800 rounded-xl p-6 border border-gray-100 dark:border-gray-700 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1778 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1779 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Upcoming", "yatra") }),
1780 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-emerald-600 dark:text-emerald-400", children: bookingStats.upcoming })
1781 ] }),
1782 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-emerald-50 dark:bg-emerald-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-5 h-5 text-emerald-600 dark:text-emerald-400" }) })
1783 ] }) }),
1784 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 bg-white dark:bg-gray-800 rounded-xl p-6 border border-gray-100 dark:border-gray-700 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1785 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1786 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Pending", "yatra") }),
1787 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-amber-600 dark:text-amber-400", children: bookingStats.pending })
1788 ] }),
1789 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-amber-50 dark:bg-amber-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "w-5 h-5 text-amber-600 dark:text-amber-400" }) })
1790 ] }) }),
1791 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 bg-white dark:bg-gray-800 rounded-xl p-6 border border-gray-100 dark:border-gray-700 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1792 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1793 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Completed", "yatra") }),
1794 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-600 dark:text-gray-400", children: bookingStats.completed })
1795 ] }),
1796 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-gray-50 dark:bg-gray-700 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle, { className: "w-5 h-5 text-gray-600 dark:text-gray-400" }) })
1797 ] }) }),
1798 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 bg-white dark:bg-gray-800 rounded-xl p-6 border border-gray-100 dark:border-gray-700 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1799 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1800 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Spent", "yatra") }),
1801 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: currency(bookingStats.totalSpent) })
1802 ] }),
1803 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-purple-50 dark:bg-purple-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(DollarSign, { className: "w-5 h-5 text-purple-600 dark:text-purple-400" }) })
1804 ] }) })
1805 ] }),
1806 filteredDisplayBookings.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-12 text-center", children: [
1807 /* @__PURE__ */ jsxRuntimeExports.jsx(Package, { className: "w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-4" }),
1808 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 font-medium mb-1", children: __("No bookings found", "yatra") }),
1809 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __("Try adjusting your filters or check back later.", "yatra") })
1810 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: filteredDisplayBookings.map((booking) => {
1811 const bookingId = Number(booking.id);
1812 const paidNumeric = typeof booking.amount_paid === "number" ? booking.amount_paid : parseFloat(booking.amount_paid || "0");
1813 const totalNumeric = typeof booking.total_amount === "number" ? booking.total_amount : parseFloat(booking.total_amount || "0");
1814 const totalPaid = paidNumeric;
1815 const amountDue = totalNumeric - totalPaid;
1816 const canPayRemaining = amountDue > 0 && booking.payment_status !== "paid";
1817 return /* @__PURE__ */ jsxRuntimeExports.jsx(
1818 "div",
1819 {
1820 className: "group bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm hover:shadow-md transition-all overflow-hidden",
1821 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-6", children: [
1822 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col lg:flex-row lg:items-start lg:justify-between gap-4 mb-4", children: [
1823 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 mb-2", children: [
1824 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 rounded-lg bg-yatra-soft dark:bg-yatra-surface-dark-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Plane, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark" }) }),
1825 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [
1826 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs uppercase tracking-wider text-gray-500 dark:text-gray-400 font-medium mb-1", children: booking.booking_number }),
1827 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-bold text-gray-900 dark:text-white mb-1", children: booking.trip_title }),
1828 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400 flex items-center gap-1", children: [
1829 /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "w-4 h-4 text-gray-600 dark:text-gray-400" }),
1830 booking.destination || __("Multiple destinations", "yatra")
1831 ] })
1832 ] })
1833 ] }) }),
1834 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap gap-2 items-start", children: [
1835 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.booking_status), children: getStatusLabel(booking.booking_status) }),
1836 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.payment_status), children: getStatusLabel(booking.payment_status) })
1837 ] })
1838 ] }),
1839 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-booking-details grid grid-cols-2 md:grid-cols-5 gap-4 p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg mb-4", children: [
1840 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1841 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Travel Date", "yatra") }),
1842 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: formatTravelDateRange(
1843 booking.travel_date,
1844 booking.end_date
1845 ) })
1846 ] }),
1847 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1848 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Travelers", "yatra") }),
1849 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: (() => {
1850 const n = Number(
1851 booking.travelers_count ?? booking.travelers ?? 0
1852 ) || 0;
1853 return n === 1 ? sprintf(__("%d traveler", "yatra"), n) : sprintf(__("%d travelers", "yatra"), n);
1854 })() })
1855 ] }),
1856 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1857 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Amount", "yatra") }),
1858 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: currency(booking.total_amount) })
1859 ] }),
1860 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1861 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Paid / Due", "yatra") }),
1862 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: [
1863 currency(totalPaid ?? 0),
1864 amountDue !== null && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs font-normal text-gray-500 dark:text-gray-400 ml-1", children: [
1865 __("Due:", "yatra"),
1866 " ",
1867 currency(amountDue)
1868 ] })
1869 ] })
1870 ] }),
1871 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1872 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Booked On", "yatra") }),
1873 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: formatDate(booking.booking_date || booking.created_at) })
1874 ] })
1875 ] }),
1876 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-booking-actions flex flex-wrap gap-3", children: [
1877 /* @__PURE__ */ jsxRuntimeExports.jsx(
1878 "div",
1879 {
1880 role: "button",
1881 tabIndex: 0,
1882 onClick: () => handleBookingSelect(bookingId),
1883 className: "yatra-booking-action yatra-booking-action-view inline-flex items-center px-4 py-2 rounded-lg bg-yatra-primary text-white hover:bg-yatra-primary-dark transition-colors text-sm font-medium cursor-pointer",
1884 children: __("View Details", "yatra")
1885 }
1886 ),
1887 /* @__PURE__ */ jsxRuntimeExports.jsx(
1888 "div",
1889 {
1890 role: "button",
1891 tabIndex: 0,
1892 onClick: () => handleDownloadClick(bookingId),
1893 className: "yatra-booking-action yatra-booking-action-download inline-flex items-center px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium cursor-pointer",
1894 children: __("Download Voucher", "yatra")
1895 }
1896 ),
1897 /* @__PURE__ */ jsxRuntimeExports.jsx(
1898 "div",
1899 {
1900 role: "button",
1901 tabIndex: 0,
1902 onClick: () => onSectionChange("payments"),
1903 className: "yatra-booking-action yatra-booking-action-payment inline-flex items-center px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium cursor-pointer",
1904 children: __("Payment", "yatra")
1905 }
1906 ),
1907 canPayRemaining && /* @__PURE__ */ jsxRuntimeExports.jsxs(
1908 "button",
1909 {
1910 type: "button",
1911 onClick: () => bookingId && startRemainingPaymentSession(bookingId),
1912 disabled: payLoading === bookingId,
1913 className: "yatra-booking-action inline-flex items-center px-4 py-2 rounded-lg bg-emerald-600 text-white hover:bg-emerald-700 transition-colors text-sm font-medium disabled:opacity-50",
1914 children: [
1915 payLoading === bookingId ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
1916 "svg",
1917 {
1918 className: "w-4 h-4 animate-spin",
1919 viewBox: "0 0 24 24",
1920 fill: "none",
1921 stroke: "currentColor",
1922 strokeWidth: "2",
1923 children: [
1924 /* @__PURE__ */ jsxRuntimeExports.jsx(
1925 "circle",
1926 {
1927 cx: "12",
1928 cy: "12",
1929 r: "10",
1930 strokeOpacity: "0.25"
1931 }
1932 ),
1933 /* @__PURE__ */ jsxRuntimeExports.jsx("path", { d: "M4 12a8 8 0 0 1 8-8" })
1934 ]
1935 }
1936 ) : null,
1937 __("Pay Remaining Balance", "yatra")
1938 ]
1939 }
1940 ),
1941 conciergeTel ? /* @__PURE__ */ jsxRuntimeExports.jsx(
1942 "a",
1943 {
1944 href: conciergeTel,
1945 className: "yatra-booking-action yatra-booking-action-support inline-flex items-center px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium no-underline",
1946 children: __("Call us", "yatra")
1947 }
1948 ) : conciergeMail ? /* @__PURE__ */ jsxRuntimeExports.jsx(
1949 "a",
1950 {
1951 href: `mailto:${encodeURIComponent(conciergeMail)}`,
1952 className: "yatra-booking-action yatra-booking-action-support inline-flex items-center px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium no-underline",
1953 children: __("Email us", "yatra")
1954 }
1955 ) : null
1956 ] })
1957 ] })
1958 },
1959 booking.id
1960 );
1961 }) })
1962 ] });
1963 };
1964 function paymentTypeLabel(type) {
1965 switch (type) {
1966 case "deposit":
1967 return __("Deposit", "yatra");
1968 case "balance":
1969 return __("Balance", "yatra");
1970 case "installment":
1971 return __("Installment", "yatra");
1972 default:
1973 return type;
1974 }
1975 }
1976 const Payments = ({ payments, onSectionChange }) => {
1977 const displayPayments = payments;
1978 const bookingSummaries = React.useMemo(() => {
1979 const map = /* @__PURE__ */ new Map();
1980 displayPayments.forEach((payment) => {
1981 if (typeof payment.booking_id !== "number") {
1982 return;
1983 }
1984 const total = typeof payment.booking_total_amount === "number" ? payment.booking_total_amount : null;
1985 const dueValue = typeof payment.booking_amount_due === "number" ? payment.booking_amount_due : null;
1986 const paidValue = typeof payment.booking_amount_paid === "number" ? payment.booking_amount_paid : null;
1987 const paid = paidValue ?? (total !== null && dueValue !== null ? total - dueValue : null);
1988 const due = dueValue ?? (total !== null && paid !== null ? total - paid : null);
1989 const existing = map.get(payment.booking_id);
1990 const summary = {
1991 total: total ?? (existing == null ? void 0 : existing.total) ?? 0,
1992 paid: paid ?? (existing == null ? void 0 : existing.paid) ?? 0,
1993 due: due ?? (existing == null ? void 0 : existing.due) ?? 0
1994 };
1995 if (!existing || summary.due < existing.due) {
1996 map.set(payment.booking_id, summary);
1997 }
1998 });
1999 return Array.from(map.values());
2000 }, [displayPayments]);
2001 const paymentStats = React.useMemo(() => {
2002 const totals = bookingSummaries.reduce(
2003 (acc, summary) => {
2004 acc.totalAmount += summary.total;
2005 acc.paidAmount += summary.total - summary.due;
2006 acc.outstanding += summary.due;
2007 if (summary.due > 0) {
2008 acc.pendingBookings += 1;
2009 } else {
2010 acc.paidBookings += 1;
2011 }
2012 return acc;
2013 },
2014 {
2015 totalAmount: 0,
2016 paidAmount: 0,
2017 outstanding: 0,
2018 pendingBookings: 0,
2019 paidBookings: 0
2020 }
2021 );
2022 return {
2023 total: displayPayments.length,
2024 paid: totals.paidBookings,
2025 pending: totals.pendingBookings,
2026 totalPaidAmount: totals.paidAmount,
2027 outstandingAmount: totals.outstanding
2028 };
2029 }, [displayPayments, bookingSummaries]);
2030 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-payments-page space-y-6", children: [
2031 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-payments-header bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2032 /* @__PURE__ */ jsxRuntimeExports.jsxs("h2", { className: "text-lg font-bold text-gray-900 dark:text-white flex items-center gap-3", children: [
2033 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-emerald-50 dark:bg-emerald-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-6 h-6 text-emerald-600 dark:text-emerald-400" }) }),
2034 __("Payments & Invoices", "yatra")
2035 ] }),
2036 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-2", children: __(
2037 "Track deposits, balances, and installment schedules with secure payment links.",
2038 "yatra"
2039 ) })
2040 ] }) }) }),
2041 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-payments-stats grid gap-4 sm:grid-cols-2 lg:grid-cols-4", children: [
2042 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-payment-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
2043 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2044 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Payments", "yatra") }),
2045 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: paymentStats.total })
2046 ] }),
2047 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-yatra-soft dark:bg-yatra-surface-dark-muted rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark" }) })
2048 ] }) }),
2049 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-payment-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
2050 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2051 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Paid", "yatra") }),
2052 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-emerald-600 dark:text-emerald-400", children: paymentStats.paid }),
2053 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-400 dark:text-gray-500", children: currency(paymentStats.totalPaidAmount) })
2054 ] }),
2055 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-emerald-50 dark:bg-emerald-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle, { className: "w-5 h-5 text-emerald-600 dark:text-emerald-400" }) })
2056 ] }) }),
2057 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-payment-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
2058 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2059 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Pending", "yatra") }),
2060 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-amber-600 dark:text-amber-400", children: paymentStats.pending })
2061 ] }),
2062 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-amber-50 dark:bg-amber-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "w-5 h-5 text-amber-600 dark:text-amber-400" }) })
2063 ] }) }),
2064 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-payment-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
2065 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2066 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Outstanding", "yatra") }),
2067 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: currency(paymentStats.outstandingAmount) })
2068 ] }),
2069 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-purple-50 dark:bg-purple-900/20 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(DollarSign, { className: "w-5 h-5 text-purple-600 dark:text-purple-400" }) })
2070 ] }) })
2071 ] }),
2072 displayPayments.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-12 text-center", children: [
2073 /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-4" }),
2074 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 font-medium mb-1", children: __("No payments found", "yatra") }),
2075 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __(
2076 "Payment history will appear here once you make a booking.",
2077 "yatra"
2078 ) })
2079 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: displayPayments.map((payment) => {
2080 const bookingTotal = typeof payment.booking_total_amount === "number" ? payment.booking_total_amount : null;
2081 const bookingPaid = typeof payment.booking_amount_paid === "number" ? payment.booking_amount_paid : null;
2082 const bookingDue = typeof payment.booking_amount_due === "number" ? payment.booking_amount_due : null;
2083 const total = bookingTotal ?? payment.amount;
2084 const paid = bookingPaid ?? (bookingDue !== null && bookingTotal !== null ? bookingTotal - bookingDue : payment.amount);
2085 const dueRaw = bookingDue ?? (bookingTotal !== null ? bookingTotal - paid : total - paid);
2086 const due = Math.max(0, dueRaw || 0);
2087 const canPayRemaining = typeof payment.booking_id === "number" && due > 0.01;
2088 const isPaid = payment.status === "paid" || payment.status === "completed";
2089 const isPending = payment.status === "pending";
2090 return /* @__PURE__ */ jsxRuntimeExports.jsx(
2091 "div",
2092 {
2093 className: "group bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm hover:shadow-md transition-all overflow-hidden",
2094 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-6", children: [
2095 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col lg:flex-row lg:items-start lg:justify-between gap-4 mb-4", children: [
2096 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 mb-2", children: [
2097 /* @__PURE__ */ jsxRuntimeExports.jsx(
2098 "div",
2099 {
2100 className: `p-2 rounded-lg ${payment.status === "paid" ? "bg-emerald-50 dark:bg-emerald-900/20" : payment.status === "pending" ? "bg-amber-50 dark:bg-amber-900/20" : "bg-gray-50 dark:bg-gray-700"}`,
2101 children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2102 CreditCard,
2103 {
2104 className: `w-5 h-5 ${payment.status === "paid" ? "text-emerald-600 dark:text-emerald-400" : payment.status === "pending" ? "text-amber-600 dark:text-amber-400" : "text-gray-400"}`
2105 }
2106 )
2107 }
2108 ),
2109 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [
2110 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs uppercase tracking-wider text-gray-500 dark:text-gray-400 font-medium mb-1", children: payment.reference }),
2111 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-base font-bold text-gray-900 dark:text-white mb-1", children: [
2112 __("Booking", "yatra"),
2113 ": ",
2114 payment.booking_number
2115 ] }),
2116 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400 flex items-center gap-1", children: [
2117 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-4 h-4" }),
2118 formatDate(payment.date)
2119 ] })
2120 ] })
2121 ] }) }),
2122 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap gap-2 items-start", children: [
2123 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(payment.status), children: getStatusLabel(payment.status) }),
2124 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "px-3 py-1 rounded-lg text-xs font-medium bg-yatra-soft dark:bg-yatra-surface-dark-muted text-yatra-primary-dark dark:text-yatra-primary-light capitalize", children: paymentTypeLabel(payment.type) })
2125 ] })
2126 ] }),
2127 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-payment-details grid grid-cols-2 md:grid-cols-3 gap-4 p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg mb-4", children: [
2128 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2129 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center gap-1", children: [
2130 /* @__PURE__ */ jsxRuntimeExports.jsx(DollarSign, { className: "w-3.5 h-3.5" }),
2131 __("Amount", "yatra")
2132 ] }),
2133 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: currency(payment.amount) })
2134 ] }),
2135 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2136 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center gap-1", children: [
2137 /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-3.5 h-3.5" }),
2138 __("Payment Method", "yatra")
2139 ] }),
2140 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: payment.method })
2141 ] }),
2142 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2143 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center gap-1", children: [
2144 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-3.5 h-3.5" }),
2145 __("Payment Date", "yatra")
2146 ] }),
2147 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: formatDate(payment.date) })
2148 ] })
2149 ] }),
2150 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-payment-actions flex flex-wrap gap-3", children: [
2151 isPaid && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2152 "button",
2153 {
2154 type: "button",
2155 onClick: async () => {
2156 try {
2157 await downloadInvoice(payment.id);
2158 } catch (err) {
2159 alert(
2160 err instanceof Error ? err.message : __("Download failed.", "yatra")
2161 );
2162 }
2163 },
2164 className: "yatra-payment-action yatra-payment-action-invoice inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium",
2165 style: { backgroundColor: "#059669", color: "#ffffff" },
2166 children: [
2167 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-4 h-4" }),
2168 __("Download Invoice", "yatra")
2169 ]
2170 }
2171 ),
2172 isPaid && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2173 "button",
2174 {
2175 type: "button",
2176 onClick: async () => {
2177 try {
2178 await previewPaymentInvoice(payment.id);
2179 } catch (err) {
2180 alert(
2181 err instanceof Error ? err.message : __("Could not open receipt.", "yatra")
2182 );
2183 }
2184 },
2185 className: "yatra-payment-action yatra-payment-action-receipt inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium",
2186 style: {
2187 backgroundColor: "var(--yatra-primary-dark, #2563eb)",
2188 color: "#ffffff"
2189 },
2190 children: [
2191 /* @__PURE__ */ jsxRuntimeExports.jsx(FileText, { className: "w-4 h-4" }),
2192 __("View Receipt", "yatra")
2193 ]
2194 }
2195 ),
2196 isPending && !canPayRemaining && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2197 "button",
2198 {
2199 type: "button",
2200 className: "yatra-payment-action inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-amber-600 text-white text-sm font-medium",
2201 children: [
2202 /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "w-4 h-4" }),
2203 __("Pending approval", "yatra")
2204 ]
2205 }
2206 ),
2207 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2208 "button",
2209 {
2210 type: "button",
2211 onClick: () => onSectionChange("bookings"),
2212 className: "yatra-payment-action yatra-payment-action-booking inline-flex items-center gap-2 px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium",
2213 children: [
2214 /* @__PURE__ */ jsxRuntimeExports.jsx(Eye, { className: "w-4 h-4" }),
2215 __("View Booking Details", "yatra")
2216 ]
2217 }
2218 )
2219 ] })
2220 ] })
2221 },
2222 payment.id
2223 );
2224 }) })
2225 ] });
2226 };
2227 function documentCategoryLabel(category) {
2228 switch (category) {
2229 case "itinerary":
2230 return __("Itinerary", "yatra");
2231 case "voucher":
2232 return __("Voucher", "yatra");
2233 case "invoice":
2234 return __("Invoice", "yatra");
2235 case "downloads":
2236 return __("Downloads", "yatra");
2237 default:
2238 return category;
2239 }
2240 }
2241 const Documents = ({ documents }) => {
2242 const [searchTerm, setSearchTerm] = reactExports.useState("");
2243 const [selectedCategory, setSelectedCategory] = reactExports.useState("all");
2244 const displayDocuments = documents;
2245 let filteredDocuments = [...displayDocuments];
2246 if (selectedCategory !== "all") {
2247 filteredDocuments = filteredDocuments.filter(
2248 (d) => d.category === selectedCategory
2249 );
2250 }
2251 if (searchTerm.trim()) {
2252 const searchLower = searchTerm.toLowerCase().trim();
2253 filteredDocuments = filteredDocuments.filter((d) => {
2254 const name = d.name || "";
2255 const tripTitle = d.trip_title || "";
2256 const category = d.category || "";
2257 return name.toLowerCase().includes(searchLower) || tripTitle.toLowerCase().includes(searchLower) || category.toLowerCase().includes(searchLower);
2258 });
2259 }
2260 const documentsByCategory = {
2261 itinerary: filteredDocuments.filter((d) => d.category === "itinerary"),
2262 voucher: filteredDocuments.filter((d) => d.category === "voucher"),
2263 invoice: filteredDocuments.filter((d) => d.category === "invoice"),
2264 downloads: filteredDocuments.filter((d) => d.category === "downloads")
2265 };
2266 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-documents-page space-y-6", children: [
2267 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-documents-header bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between", children: [
2268 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2269 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-bold text-gray-900 dark:text-white", children: __("Travel Documents", "yatra") }),
2270 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-2", children: __(
2271 "Download itineraries, vouchers, invoices, and other documents for each trip.",
2272 "yatra"
2273 ) })
2274 ] }),
2275 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3 lg:flex-row lg:items-center lg:gap-4", children: [
2276 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2277 "input",
2278 {
2279 type: "text",
2280 placeholder: __("Search documents...", "yatra"),
2281 value: searchTerm,
2282 onChange: (e) => setSearchTerm(e.target.value),
2283 className: "w-full lg:w-64 pl-4 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent"
2284 }
2285 ) }),
2286 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
2287 "select",
2288 {
2289 value: selectedCategory,
2290 onChange: (e) => setSelectedCategory(
2291 e.target.value
2292 ),
2293 className: "appearance-none bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg px-4 py-2 pr-4 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent cursor-pointer",
2294 children: [
2295 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "all", children: __("All Documents", "yatra") }),
2296 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "itinerary", children: __("Itineraries", "yatra") }),
2297 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "voucher", children: __("Vouchers", "yatra") }),
2298 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "invoice", children: __("Invoices", "yatra") }),
2299 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "downloads", children: __("Downloads", "yatra") })
2300 ]
2301 }
2302 ) })
2303 ] })
2304 ] }) }),
2305 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-documents-stats flex flex-nowrap gap-6 overflow-x-auto", children: [
2306 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 yatra-document-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-6 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2307 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Itinerary", "yatra") }),
2308 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-yatra-primary dark:text-yatra-on-dark", children: documentsByCategory.itinerary.length })
2309 ] }) }),
2310 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 yatra-document-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-6 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2311 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Voucher", "yatra") }),
2312 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-emerald-600 dark:text-emerald-400", children: documentsByCategory.voucher.length })
2313 ] }) }),
2314 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 yatra-document-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-6 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2315 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Invoice", "yatra") }),
2316 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-purple-600 dark:text-purple-400", children: documentsByCategory.invoice.length })
2317 ] }) }),
2318 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 yatra-document-stat-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-6 min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2319 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Downloads", "yatra") }),
2320 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-amber-600 dark:text-amber-400", children: documentsByCategory.downloads.length })
2321 ] }) })
2322 ] }),
2323 filteredDocuments.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl p-12 text-center", children: [
2324 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 bg-gray-200 dark:bg-gray-700 rounded-full mx-auto mb-4" }),
2325 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 font-medium mb-1", children: __("No documents found", "yatra") }),
2326 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __(
2327 "No documents are available yet. Please check back later.",
2328 "yatra"
2329 ) })
2330 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: filteredDocuments.map((doc) => /* @__PURE__ */ jsxRuntimeExports.jsx(
2331 "div",
2332 {
2333 className: "group bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm hover:shadow-md transition-all overflow-hidden",
2334 children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-start gap-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
2335 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between gap-4 mb-2", children: [
2336 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
2337 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: doc.trip_title }),
2338 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-bold text-gray-900 dark:text-white mb-1 truncate", children: doc.name }),
2339 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: [
2340 __("Updated", "yatra"),
2341 ": ",
2342 formatDate(doc.updated_at)
2343 ] }),
2344 doc.category === "downloads" && /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400 mt-2", children: [
2345 __("Access", "yatra"),
2346 ":",
2347 " ",
2348 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700 dark:text-gray-300", children: doc.access_label || doc.access || "-" }),
2349 doc.locked && doc.locked_reason ? /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "ml-2 text-amber-700 dark:text-amber-300", children: [
2350 "(",
2351 doc.locked_reason,
2352 ")"
2353 ] }) : null
2354 ] })
2355 ] }),
2356 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 flex-shrink-0", children: [
2357 doc.category === "downloads" && doc.access_label && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "px-3 py-1 rounded-lg text-xs font-medium bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300 border border-amber-200 dark:border-amber-800", children: doc.access_label }),
2358 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "px-3 py-1 rounded-lg text-xs font-medium bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 capitalize", children: documentCategoryLabel(doc.category) })
2359 ] })
2360 ] }),
2361 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-document-actions flex flex-wrap gap-3 mt-4", children: [
2362 doc.locked || !doc.url ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2363 "div",
2364 {
2365 className: "inline-flex items-center px-4 py-2 rounded-lg bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors text-sm font-medium cursor-not-allowed",
2366 title: doc.locked_reason || __("Not available", "yatra"),
2367 children: __("Not Available", "yatra")
2368 }
2369 ) : /* @__PURE__ */ jsxRuntimeExports.jsx(
2370 "button",
2371 {
2372 type: "button",
2373 onClick: async () => {
2374 try {
2375 await downloadDocument({
2376 bookingId: doc.booking_id,
2377 paymentId: doc.payment_id,
2378 documentType: doc.category,
2379 fallbackUrl: doc.url
2380 });
2381 } catch (err) {
2382 alert(
2383 err instanceof Error ? err.message : __("Download failed.", "yatra")
2384 );
2385 }
2386 },
2387 className: "yatra-document-action yatra-document-action-download inline-flex items-center px-4 py-2 rounded-lg bg-yatra-primary text-white hover:bg-yatra-primary-dark transition-colors text-sm font-medium",
2388 children: __("Download", "yatra")
2389 }
2390 ),
2391 doc.url ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2392 "button",
2393 {
2394 type: "button",
2395 onClick: async () => {
2396 try {
2397 await previewTravelDocument(doc);
2398 } catch (err) {
2399 alert(
2400 err instanceof Error ? err.message : __("Preview failed.", "yatra")
2401 );
2402 }
2403 },
2404 className: "yatra-document-action yatra-document-action-preview inline-flex items-center px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium",
2405 children: __("Preview", "yatra")
2406 }
2407 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "inline-flex items-center px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-700 text-gray-500 dark:text-gray-500 text-sm font-medium cursor-not-allowed", children: __("Preview", "yatra") })
2408 ] })
2409 ] }) }) })
2410 },
2411 doc.id
2412 )) })
2413 ] });
2414 };
2415 const Profile = ({
2416 profile,
2417 savedTrips,
2418 wishlistEnabled = false
2419 }) => {
2420 const [isEditing, setIsEditing] = reactExports.useState(false);
2421 const [formData, setFormData] = reactExports.useState({
2422 name: "",
2423 email: "",
2424 phone: "",
2425 address: "",
2426 city: "",
2427 country: ""
2428 });
2429 const [isChangingPassword, setIsChangingPassword] = reactExports.useState(false);
2430 const [passwordData, setPasswordData] = reactExports.useState({
2431 currentPassword: "",
2432 newPassword: "",
2433 confirmPassword: ""
2434 });
2435 reactExports.useEffect(() => {
2436 if (profile && !isEditing) {
2437 setFormData({
2438 name: profile.name || "",
2439 email: profile.email || "",
2440 phone: profile.phone || "",
2441 address: profile.address || "",
2442 city: profile.city || "",
2443 country: profile.country || ""
2444 });
2445 }
2446 }, [profile, isEditing]);
2447 const queryClient2 = useQueryClient();
2448 const { showToast } = useToast();
2449 const [isSaving, setIsSaving] = reactExports.useState(false);
2450 const [isSavingPassword, setIsSavingPassword] = reactExports.useState(false);
2451 const handleInputChange = (field, value) => {
2452 setFormData((prev) => ({ ...prev, [field]: value }));
2453 };
2454 const handleSave = async () => {
2455 setIsSaving(true);
2456 try {
2457 const parts = formData.name.trim().split(/\s+/).filter(Boolean);
2458 const firstName = parts.shift() || "";
2459 const lastName = parts.join(" ");
2460 const payload = {
2461 first_name: firstName,
2462 phone: formData.phone,
2463 address: formData.address,
2464 city: formData.city,
2465 country: formData.country
2466 };
2467 if (lastName) {
2468 payload.last_name = lastName;
2469 }
2470 await apiClient.put(API_ENDPOINTS.CUSTOMER_ME, payload);
2471 await queryClient2.invalidateQueries({ queryKey: ["account-profile"] });
2472 showToast(__("Profile updated successfully.", "yatra"), "success");
2473 setIsEditing(false);
2474 } catch (error) {
2475 showToast(
2476 (error == null ? void 0 : error.message) || __("Failed to update profile.", "yatra"),
2477 "error"
2478 );
2479 } finally {
2480 setIsSaving(false);
2481 }
2482 };
2483 const handleChangePassword = async () => {
2484 if (passwordData.newPassword !== passwordData.confirmPassword) {
2485 showToast(__("Passwords do not match.", "yatra"), "error");
2486 return;
2487 }
2488 setIsSavingPassword(true);
2489 try {
2490 await apiClient.post(API_ENDPOINTS.CUSTOMER_CHANGE_PASSWORD, {
2491 current_password: passwordData.currentPassword,
2492 new_password: passwordData.newPassword
2493 });
2494 showToast(__("Password changed successfully.", "yatra"), "success");
2495 setIsChangingPassword(false);
2496 setPasswordData({
2497 currentPassword: "",
2498 newPassword: "",
2499 confirmPassword: ""
2500 });
2501 setTimeout(() => window.location.reload(), 1200);
2502 } catch (error) {
2503 showToast(
2504 (error == null ? void 0 : error.message) || __("Failed to change password.", "yatra"),
2505 "error"
2506 );
2507 } finally {
2508 setIsSavingPassword(false);
2509 }
2510 };
2511 const handleCancel = () => {
2512 setIsEditing(false);
2513 if (profile) {
2514 setFormData({
2515 name: profile.name || "",
2516 email: profile.email || "",
2517 phone: profile.phone || "",
2518 address: profile.address || "",
2519 city: profile.city || "",
2520 country: profile.country || ""
2521 });
2522 }
2523 };
2524 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-page space-y-6", children: [
2525 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-profile-header bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between", children: [
2526 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2527 /* @__PURE__ */ jsxRuntimeExports.jsxs("h2", { className: "text-lg font-bold text-gray-900 dark:text-white flex items-center gap-3", children: [
2528 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 bg-yatra-soft dark:bg-yatra-surface-dark-muted rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(User, { className: "w-6 h-6 text-yatra-primary dark:text-yatra-on-dark" }) }),
2529 __("Profile", "yatra")
2530 ] }),
2531 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-2", children: __(
2532 "Update your contact details, address, and communication preferences.",
2533 "yatra"
2534 ) })
2535 ] }),
2536 !isEditing && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2537 "div",
2538 {
2539 role: "button",
2540 tabIndex: 0,
2541 onClick: () => setIsEditing(true),
2542 className: "yatra-profile-edit-btn inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-yatra-primary text-white hover:bg-yatra-primary-dark transition-colors text-sm font-medium cursor-pointer",
2543 children: [
2544 /* @__PURE__ */ jsxRuntimeExports.jsx(PenSquare, { className: "w-4 h-4" }),
2545 " ",
2546 __("Edit Profile", "yatra")
2547 ]
2548 }
2549 )
2550 ] }) }),
2551 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-profile-card bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-fields space-y-6", children: [
2552 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2553 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2554 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2555 __("Full Name", "yatra"),
2556 " ",
2557 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2558 ] }),
2559 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2560 "input",
2561 {
2562 type: "text",
2563 value: formData.name,
2564 onChange: (e) => handleInputChange("name", e.target.value),
2565 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2566 placeholder: __("Enter your full name", "yatra")
2567 }
2568 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.name || __("Not set", "yatra") })
2569 ] }),
2570 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2571 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("Email Address", "yatra") }),
2572 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.email || __("Not set", "yatra") })
2573 ] }),
2574 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2575 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("Phone Number", "yatra") }),
2576 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2577 "input",
2578 {
2579 type: "tel",
2580 value: formData.phone,
2581 onChange: (e) => handleInputChange("phone", e.target.value),
2582 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2583 placeholder: __("Enter your phone number", "yatra")
2584 }
2585 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.phone || __("Not set", "yatra") })
2586 ] }),
2587 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2588 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("Country", "yatra") }),
2589 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
2590 "select",
2591 {
2592 value: formData.country,
2593 onChange: (e) => handleInputChange("country", e.target.value),
2594 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2595 children: [
2596 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "", children: __("Select your country", "yatra") }),
2597 getCountryOptions().map((c) => /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: c.code, children: c.name }, c.code))
2598 ]
2599 }
2600 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: getCountryName$1(formData.country) || __("Not set", "yatra") })
2601 ] }),
2602 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2603 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("City", "yatra") }),
2604 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2605 "input",
2606 {
2607 type: "text",
2608 value: formData.city,
2609 onChange: (e) => handleInputChange("city", e.target.value),
2610 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2611 placeholder: __("Enter your city", "yatra")
2612 }
2613 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.city || __("Not set", "yatra") })
2614 ] }),
2615 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field md:col-span-2", children: [
2616 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("Address", "yatra") }),
2617 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2618 "textarea",
2619 {
2620 value: formData.address,
2621 onChange: (e) => handleInputChange("address", e.target.value),
2622 rows: 3,
2623 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2624 placeholder: __("Enter your address", "yatra")
2625 }
2626 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.address || __("Not set", "yatra") })
2627 ] })
2628 ] }),
2629 isEditing && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-actions flex flex-wrap gap-3 pt-4 border-t border-gray-200 dark:border-gray-700", children: [
2630 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2631 "button",
2632 {
2633 type: "button",
2634 onClick: handleSave,
2635 disabled: isSaving,
2636 className: "inline-flex items-center gap-2 px-6 py-2 rounded-lg bg-yatra-primary text-white hover:bg-yatra-primary-dark transition-colors text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed",
2637 children: [
2638 /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle, { className: "w-4 h-4" }),
2639 isSaving ? __("Saving…", "yatra") : __("Save Changes", "yatra")
2640 ]
2641 }
2642 ),
2643 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2644 "div",
2645 {
2646 role: "button",
2647 tabIndex: 0,
2648 onClick: handleCancel,
2649 className: "inline-flex items-center gap-2 px-6 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium cursor-pointer",
2650 children: [
2651 /* @__PURE__ */ jsxRuntimeExports.jsx(XCircle, { className: "w-4 h-4" }),
2652 __("Cancel", "yatra")
2653 ]
2654 }
2655 )
2656 ] })
2657 ] }) }),
2658 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-password bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
2659 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-6", children: [
2660 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2661 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-base font-semibold text-gray-900 dark:text-white flex items-center gap-2", children: [
2662 /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldCheck, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark" }),
2663 __("Change Password", "yatra")
2664 ] }),
2665 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-1", children: __("Update your password to keep your account secure.", "yatra") })
2666 ] }),
2667 !isChangingPassword && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2668 "div",
2669 {
2670 role: "button",
2671 tabIndex: 0,
2672 onClick: () => setIsChangingPassword(true),
2673 className: "inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-yatra-primary text-white hover:bg-yatra-primary-dark transition-colors text-sm font-medium cursor-pointer",
2674 children: [
2675 /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4" }),
2676 __("Change Password", "yatra")
2677 ]
2678 }
2679 )
2680 ] }),
2681 isChangingPassword && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
2682 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-password-field", children: [
2683 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2684 __("Current Password", "yatra"),
2685 " ",
2686 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2687 ] }),
2688 /* @__PURE__ */ jsxRuntimeExports.jsx(
2689 "input",
2690 {
2691 type: "password",
2692 value: passwordData.currentPassword,
2693 onChange: (e) => setPasswordData((prev) => ({
2694 ...prev,
2695 currentPassword: e.target.value
2696 })),
2697 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2698 placeholder: __("Enter your current password", "yatra")
2699 }
2700 )
2701 ] }),
2702 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-password-field", children: [
2703 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2704 __("New Password", "yatra"),
2705 " ",
2706 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2707 ] }),
2708 /* @__PURE__ */ jsxRuntimeExports.jsx(
2709 "input",
2710 {
2711 type: "password",
2712 value: passwordData.newPassword,
2713 onChange: (e) => setPasswordData((prev) => ({
2714 ...prev,
2715 newPassword: e.target.value
2716 })),
2717 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2718 placeholder: __("Enter new password", "yatra")
2719 }
2720 )
2721 ] }),
2722 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-password-field", children: [
2723 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2724 __("Confirm New Password", "yatra"),
2725 " ",
2726 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2727 ] }),
2728 /* @__PURE__ */ jsxRuntimeExports.jsx(
2729 "input",
2730 {
2731 type: "password",
2732 value: passwordData.confirmPassword,
2733 onChange: (e) => setPasswordData((prev) => ({
2734 ...prev,
2735 confirmPassword: e.target.value
2736 })),
2737 className: "w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white px-4 py-2 text-sm focus:ring-2 focus:ring-yatra-primary focus:border-transparent",
2738 placeholder: __("Confirm your new password", "yatra")
2739 }
2740 ),
2741 passwordData.newPassword && passwordData.confirmPassword && passwordData.newPassword !== passwordData.confirmPassword && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-red-500 mt-1", children: __("Passwords do not match", "yatra") })
2742 ] }),
2743 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-password-actions flex flex-wrap gap-3 pt-4 border-t border-gray-200 dark:border-gray-700", children: [
2744 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2745 "button",
2746 {
2747 type: "button",
2748 onClick: handleChangePassword,
2749 disabled: isSavingPassword || !passwordData.currentPassword || !passwordData.newPassword || !passwordData.confirmPassword || passwordData.newPassword !== passwordData.confirmPassword,
2750 className: "inline-flex items-center gap-2 px-6 py-2 rounded-lg bg-yatra-primary text-white hover:bg-yatra-primary-dark transition-colors text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed",
2751 children: [
2752 /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle, { className: "w-4 h-4" }),
2753 isSavingPassword ? __("Updating…", "yatra") : __("Update Password", "yatra")
2754 ]
2755 }
2756 ),
2757 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2758 "div",
2759 {
2760 role: "button",
2761 tabIndex: 0,
2762 onClick: () => {
2763 setIsChangingPassword(false);
2764 setPasswordData({
2765 currentPassword: "",
2766 newPassword: "",
2767 confirmPassword: ""
2768 });
2769 },
2770 className: "inline-flex items-center gap-2 px-6 py-2 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors text-sm font-medium cursor-pointer",
2771 children: [
2772 /* @__PURE__ */ jsxRuntimeExports.jsx(XCircle, { className: "w-4 h-4" }),
2773 __("Cancel", "yatra")
2774 ]
2775 }
2776 )
2777 ] })
2778 ] })
2779 ] }),
2780 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-profile-sections grid gap-6 lg:grid-cols-1", children: wishlistEnabled && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-saved-trips bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: [
2781 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-base font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
2782 /* @__PURE__ */ jsxRuntimeExports.jsx(Heart, { className: "w-5 h-5 text-red-600 dark:text-red-400" }),
2783 __("Saved Trips", "yatra")
2784 ] }),
2785 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-saved-trips-list space-y-3", children: savedTrips.length > 0 ? savedTrips.map((trip) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
2786 "div",
2787 {
2788 className: "yatra-saved-trip-item flex items-center justify-between border border-gray-100 dark:border-gray-700 rounded-lg p-4 hover:bg-gray-50 dark:hover:bg-gray-900/40 transition-colors",
2789 children: [
2790 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
2791 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white truncate", children: trip.trip_title || trip.title }),
2792 (trip.location || trip.duration) && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mt-1", children: trip.location || trip.duration })
2793 ] }),
2794 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-right ml-4 flex-shrink-0", children: [
2795 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: __("From", "yatra") }),
2796 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: currency(trip.price_from || trip.price || 0) })
2797 ] })
2798 ]
2799 },
2800 trip.id || trip.trip_id
2801 )) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 text-center py-4", children: __("No saved trips yet", "yatra") }) })
2802 ] }) })
2803 ] });
2804 };
2805 const SavedTrips = ({ savedTrips, isLoading }) => {
2806 const { showToast } = useToast();
2807 const handleRemoveTrip = async (tripId) => {
2808 try {
2809 await apiClient.delete(`/saved-trips/${tripId}`);
2810 window.location.reload();
2811 } catch (error) {
2812 console.error("Error removing trip:", error);
2813 showToast(__("Failed to remove trip from wishlist.", "yatra"), "error");
2814 }
2815 };
2816 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
2817 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2818 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white", children: __("Saved Trips", "yatra") }),
2819 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-1", children: __("Your wishlist of favorite trips", "yatra") })
2820 ] }) }),
2821 isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-trip-grid grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6", children: [1, 2, 3].map((i) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-card", children: [
2822 /* @__PURE__ */ jsxRuntimeExports.jsx(
2823 "div",
2824 {
2825 className: "yatra-trip-image",
2826 style: { backgroundColor: "#f3f4f6", minHeight: "200px" },
2827 children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-pulse bg-gray-200 dark:bg-gray-700 w-full h-full" })
2828 }
2829 ),
2830 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-trip-content p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse space-y-3", children: [
2831 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-3/4" }),
2832 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-1/2" }),
2833 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-2/3" })
2834 ] }) })
2835 ] }, i)) }) : savedTrips.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center py-12", children: [
2836 /* @__PURE__ */ jsxRuntimeExports.jsx(Heart, { className: "w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-4" }),
2837 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-2", children: __("No saved trips yet", "yatra") }),
2838 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 mb-6", children: __(
2839 "Start exploring and save your favorite trips to your wishlist!",
2840 "yatra"
2841 ) }),
2842 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2843 "a",
2844 {
2845 href: "/trip/",
2846 className: "inline-flex items-center gap-2 px-4 py-2 bg-yatra-primary text-white rounded-lg hover:bg-yatra-primary-dark transition-colors",
2847 children: [
2848 /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "w-4 h-4" }),
2849 __("Browse Trips", "yatra")
2850 ]
2851 }
2852 )
2853 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-trip-grid grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6", children: savedTrips.map((trip) => {
2854 var _a, _b;
2855 const tripUrl = trip.permalink || `/trip/${trip.trip_slug || trip.trip_id}`;
2856 const siteBase = typeof window !== "undefined" && (((_a = window.yatraAdmin) == null ? void 0 : _a.siteUrl) || ((_b = window.yatraAccountPage) == null ? void 0 : _b.siteUrl)) || (typeof window !== "undefined" ? window.location.origin : "");
2857 const imageUrl = trip.trip_image || `${siteBase}/wp-content/plugins/yatra/assets/images/trip-placeholder.svg`;
2858 const hasDiscount = trip.discount_percent && trip.discount_percent > 0;
2859 const displayPrice = trip.price !== void 0 && trip.price !== null ? trip.price : trip.sale_price !== void 0 && trip.sale_price !== null && trip.sale_price > 0 ? trip.sale_price : trip.original_price !== void 0 && trip.original_price !== null && trip.original_price > 0 ? trip.original_price : 0;
2860 const originalPrice = trip.original_price;
2861 const avgRating = trip.rating !== void 0 && trip.rating !== null ? trip.rating : trip.average_rating !== void 0 && trip.average_rating !== null ? trip.average_rating : 0;
2862 const reviewCount = trip.reviews !== void 0 && trip.reviews !== null ? trip.reviews : trip.review_count || trip.reviews_count || 0;
2863 return /* @__PURE__ */ jsxRuntimeExports.jsxs(
2864 "div",
2865 {
2866 className: "yatra-trip-card flex h-full flex-col overflow-hidden rounded-xl border border-gray-100 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800",
2867 "data-price": displayPrice,
2868 "data-rating": avgRating,
2869 "data-duration": trip.duration_days || 0,
2870 children: [
2871 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-image", children: [
2872 /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: imageUrl, alt: trip.trip_title }),
2873 hasDiscount && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-discount-badge", children: [
2874 trip.discount_percent,
2875 "% ",
2876 __("OFF", "yatra")
2877 ] }),
2878 /* @__PURE__ */ jsxRuntimeExports.jsx(
2879 "button",
2880 {
2881 className: "yatra-favorite-btn saved is-saved",
2882 title: __("Remove from favorites", "yatra"),
2883 onClick: () => handleRemoveTrip(trip.trip_id),
2884 style: { color: "#ef4444" },
2885 children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2886 "svg",
2887 {
2888 width: "20",
2889 height: "20",
2890 fill: "currentColor",
2891 stroke: "currentColor",
2892 viewBox: "0 0 24 24",
2893 children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2894 "path",
2895 {
2896 strokeLinecap: "round",
2897 strokeLinejoin: "round",
2898 strokeWidth: "2",
2899 d: "M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"
2900 }
2901 )
2902 }
2903 )
2904 }
2905 )
2906 ] }),
2907 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-content flex flex-1 flex-col p-4", children: [
2908 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-meta", children: [
2909 trip.location && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2910 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-location", children: trip.location }),
2911 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-separator", children: "•" })
2912 ] }),
2913 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-duration", children: trip.duration || __("Flexible", "yatra") }),
2914 trip.difficulty && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2915 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-separator", children: "•" }),
2916 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-difficulty", children: trip.difficulty })
2917 ] })
2918 ] }),
2919 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "yatra-trip-title mb-2 text-lg font-semibold leading-snug text-gray-900 dark:text-white", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2920 "a",
2921 {
2922 href: tripUrl,
2923 className: "text-yatra-primary-dark hover:text-yatra-primary-darker hover:underline dark:text-yatra-on-dark dark:hover:text-yatra-primary-light focus-visible:outline focus-visible:ring-2 focus-visible:ring-yatra-primary focus-visible:ring-offset-2 rounded-sm",
2924 children: trip.trip_title
2925 }
2926 ) }),
2927 trip.highlights && trip.highlights.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-trip-highlights", children: trip.highlights.map((highlight, idx) => {
2928 const highlightText = typeof highlight === "string" ? highlight : highlight.text || highlight;
2929 const highlightLink = typeof highlight === "object" && highlight.link ? highlight.link : null;
2930 if (highlightLink) {
2931 return /* @__PURE__ */ jsxRuntimeExports.jsx(
2932 "a",
2933 {
2934 href: highlightLink,
2935 className: "yatra-highlight-badge yatra-highlight-link",
2936 children: highlightText
2937 },
2938 idx
2939 );
2940 }
2941 return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-highlight-badge", children: highlightText }, idx);
2942 }) }),
2943 reviewCount > 0 && avgRating > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-rating", children: [
2944 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-rating-stars", children: [
2945 /* @__PURE__ */ jsxRuntimeExports.jsx(
2946 "svg",
2947 {
2948 width: "16",
2949 height: "16",
2950 fill: "#fbbf24",
2951 viewBox: "0 0 24 24",
2952 "aria-hidden": "true",
2953 children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { d: "M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" })
2954 }
2955 ),
2956 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-rating-value", children: avgRating.toFixed(1) })
2957 ] }),
2958 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-reviews-count", children: reviewCount === 1 ? sprintf(__("(%d review)", "yatra"), reviewCount) : sprintf(__("(%d reviews)", "yatra"), reviewCount) })
2959 ] }),
2960 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-footer mt-auto flex flex-row items-center justify-between gap-4 border-t border-gray-100 pt-4 dark:border-gray-700", children: [
2961 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-price flex min-w-0 flex-col items-start gap-1 text-left", children: [
2962 hasDiscount && originalPrice && originalPrice > displayPrice && !trip.is_traveler_based && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-original-price text-sm text-gray-500 line-through", children: formatPrice(originalPrice) }),
2963 trip.is_traveler_based ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-starting-from text-xs font-normal leading-tight text-gray-500 dark:text-gray-400", children: __("Starting from", "yatra") }) : null,
2964 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-current-price text-xl font-bold leading-none text-yatra-primary tabular-nums dark:text-yatra-on-dark", children: formatPrice(displayPrice) }),
2965 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-price-note text-xs leading-tight text-gray-400 dark:text-gray-500", children: __("Per person", "yatra") })
2966 ] }),
2967 /* @__PURE__ */ jsxRuntimeExports.jsx(
2968 "a",
2969 {
2970 href: tripUrl,
2971 className: "yatra-card-view-btn inline-flex shrink-0 items-center justify-center self-center rounded-lg bg-yatra-primary px-4 py-2 text-sm font-medium text-white no-underline transition-colors hover:bg-yatra-primary-dark",
2972 children: __("View Details", "yatra")
2973 }
2974 )
2975 ] })
2976 ] })
2977 ]
2978 },
2979 trip.id || trip.trip_id
2980 );
2981 }) })
2982 ] });
2983 };
2984 const navigation = [
2985 { id: "dashboard", label: __("Dashboard", "yatra"), icon: LayoutDashboard },
2986 { id: "bookings", label: __("Bookings", "yatra"), icon: Calendar },
2987 { id: "payments", label: __("Payments", "yatra"), icon: CreditCard },
2988 { id: "documents", label: __("Documents", "yatra"), icon: FileText },
2989 { id: "saved-trips", label: __("Saved Trips", "yatra"), icon: Heart },
2990 { id: "profile", label: __("Profile", "yatra"), icon: User }
2991 ];
2992 const AccountPage = () => {
2993 var _a;
2994 const accountShell = reactExports.useMemo(() => getYatraAccountPageGlobals(), []);
2995 const accountNavigation = React.useMemo(() => {
2996 var _a2;
2997 const wl = typeof window !== "undefined" && !!((_a2 = window.yatraAccountPage) == null ? void 0 : _a2.wishlistEnabled);
2998 return navigation.filter((n) => n.id !== "saved-trips" || wl);
2999 }, []);
3000 const [urlKey, setUrlKey] = reactExports.useState(0);
3001 React.useEffect(() => {
3002 const handleLocationChange = () => {
3003 setUrlKey((prev) => prev + 1);
3004 };
3005 window.addEventListener("popstate", handleLocationChange);
3006 const interval = setInterval(() => {
3007 const currentSearch = window.location.search;
3008 if (currentSearch !== window.__lastAccountSearch) {
3009 window.__lastAccountSearch = currentSearch;
3010 handleLocationChange();
3011 }
3012 }, 100);
3013 return () => {
3014 window.removeEventListener("popstate", handleLocationChange);
3015 clearInterval(interval);
3016 };
3017 }, []);
3018 const getSectionFromUrl = () => {
3019 var _a2, _b;
3020 if (typeof window !== "undefined") {
3021 const wl = !!((_a2 = window.yatraAccountPage) == null ? void 0 : _a2.wishlistEnabled);
3022 const params = new URLSearchParams(window.location.search);
3023 const tab = params.get("tab");
3024 if (tab === "saved-trips" && !wl) {
3025 return "dashboard";
3026 }
3027 if (tab && [
3028 "dashboard",
3029 "bookings",
3030 "payments",
3031 "documents",
3032 "profile",
3033 "saved-trips"
3034 ].includes(tab)) {
3035 return tab;
3036 }
3037 const saved = localStorage.getItem("yatra-account-active-section");
3038 const wlSaved = !!((_b = window.yatraAccountPage) == null ? void 0 : _b.wishlistEnabled);
3039 if (saved === "saved-trips" && !wlSaved) {
3040 return "dashboard";
3041 }
3042 if (saved && [
3043 "dashboard",
3044 "bookings",
3045 "payments",
3046 "documents",
3047 "profile",
3048 "saved-trips"
3049 ].includes(saved)) {
3050 return saved;
3051 }
3052 }
3053 return "dashboard";
3054 };
3055 const [section, setSection] = reactExports.useState(getSectionFromUrl);
3056 const [pendingBookingId, setPendingBookingId] = reactExports.useState(null);
3057 React.useEffect(() => {
3058 const newSection = getSectionFromUrl();
3059 setSection(newSection);
3060 }, [urlKey]);
3061 const handleSectionChange = (newSection) => {
3062 setSection(newSection);
3063 if (typeof window !== "undefined") {
3064 const urlParams = new URLSearchParams(window.location.search);
3065 urlParams.set("tab", newSection);
3066 const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
3067 window.history.pushState({}, "", newUrl);
3068 localStorage.setItem("yatra-account-active-section", newSection);
3069 window.dispatchEvent(new PopStateEvent("popstate"));
3070 }
3071 };
3072 const handleBookingOpen = (bookingId) => {
3073 setPendingBookingId(bookingId);
3074 handleSectionChange("bookings");
3075 };
3076 const unwrapArrayResponse = (response) => {
3077 if (!response) return [];
3078 if (typeof response === "object" && response.success === true && Array.isArray(response.data)) {
3079 return response.data;
3080 }
3081 if (typeof response === "object" && response.data && typeof response.data === "object") {
3082 const inner = response.data;
3083 if (inner.success === true && Array.isArray(inner.data)) {
3084 return inner.data;
3085 }
3086 if (Array.isArray(inner)) {
3087 return inner;
3088 }
3089 }
3090 if (Array.isArray(response)) {
3091 return response;
3092 }
3093 if (typeof response === "object" && Array.isArray(response.data)) {
3094 return response.data;
3095 }
3096 return [];
3097 };
3098 const { data: profile, isLoading: isLoadingProfile } = useQuery({
3099 queryKey: ["account-profile"],
3100 queryFn: async () => {
3101 try {
3102 const response = await apiClient.get(API_ENDPOINTS.CUSTOMER_ME);
3103 const raw = response && typeof response === "object" && "data" in response && response.data && typeof response.data === "object" ? response.data : response;
3104 if (!raw || typeof raw !== "object" || !("id" in raw) && !("user_id" in raw) && !("email" in raw)) {
3105 return null;
3106 }
3107 const row = raw;
3108 const fromParts = [row.first_name, row.last_name].filter(Boolean).join(" ").trim();
3109 const name = typeof row.name === "string" && row.name.trim() || fromParts || (typeof row.email === "string" ? row.email.split("@")[0] || "" : "") || "";
3110 return {
3111 ...row,
3112 name,
3113 registered_at: row.registered_at || row.created_at || ""
3114 };
3115 } catch (error) {
3116 console.error("Error fetching profile:", error);
3117 return null;
3118 }
3119 },
3120 refetchOnMount: "always"
3121 });
3122 const displayProfile = profile;
3123 const { data: bookings = [] } = useQuery({
3124 queryKey: ["account-bookings"],
3125 queryFn: async () => {
3126 try {
3127 const response = await apiClient.get(
3128 API_ENDPOINTS.CUSTOMER_MY_BOOKINGS
3129 );
3130 return unwrapArrayResponse(response);
3131 } catch (error) {
3132 console.error("Error fetching bookings:", error);
3133 return [];
3134 }
3135 },
3136 refetchOnMount: "always"
3137 });
3138 const { data: payments = [] } = useQuery({
3139 queryKey: ["account-payments"],
3140 queryFn: async () => {
3141 try {
3142 const response = await apiClient.get(
3143 API_ENDPOINTS.CUSTOMER_MY_PAYMENTS
3144 );
3145 return unwrapArrayResponse(response);
3146 } catch (error) {
3147 console.error("Error fetching payments:", error);
3148 return [];
3149 }
3150 },
3151 refetchOnMount: "always"
3152 });
3153 const { data: documents = [] } = useQuery({
3154 queryKey: ["account-documents"],
3155 queryFn: async () => {
3156 try {
3157 const response = await apiClient.get(
3158 API_ENDPOINTS.CUSTOMER_MY_DOCUMENTS
3159 );
3160 return unwrapArrayResponse(response);
3161 } catch (error) {
3162 console.error("Error fetching documents:", error);
3163 return [];
3164 }
3165 },
3166 refetchOnMount: "always"
3167 });
3168 const notifications = [];
3169 const wishlistEnabled = typeof window !== "undefined" && !!((_a = window.yatraAccountPage) == null ? void 0 : _a.wishlistEnabled);
3170 const { data: savedTripsData, isLoading: isLoadingSavedTrips } = useQuery({
3171 queryKey: ["account-saved-trips"],
3172 enabled: wishlistEnabled,
3173 queryFn: async () => {
3174 try {
3175 const response = await apiClient.get(API_ENDPOINTS.SAVED_TRIPS);
3176 let trips = [];
3177 if (response && typeof response === "object") {
3178 if (response.data && typeof response.data === "object") {
3179 if (response.data.success === true && Array.isArray(response.data.data)) {
3180 trips = response.data.data;
3181 } else if (Array.isArray(response.data.data)) {
3182 trips = response.data.data;
3183 } else if (Array.isArray(response.data)) {
3184 trips = response.data;
3185 }
3186 } else if (response.success === true && Array.isArray(response.data)) {
3187 trips = response.data;
3188 } else if (Array.isArray(response.data)) {
3189 trips = response.data;
3190 } else if (Array.isArray(response)) {
3191 trips = response;
3192 }
3193 }
3194 if (trips.length > 0) {
3195 }
3196 return trips;
3197 } catch (error) {
3198 console.error("Error fetching saved trips:", error);
3199 return [];
3200 }
3201 }
3202 });
3203 const savedTrips = Array.isArray(savedTripsData) ? savedTripsData : [];
3204 const stats = reactExports.useMemo(() => {
3205 const outstanding = payments.filter((p) => p.status === "pending").reduce((sum, payment) => sum + payment.amount, 0);
3206 const upcoming = bookings.filter(
3207 (b) => toDateValue(b.travel_date) > /* @__PURE__ */ new Date()
3208 ).length;
3209 const totalSpent = (displayProfile == null ? void 0 : displayProfile.total_spent) ?? 0;
3210 const totalBookings = bookings.length;
3211 return [
3212 {
3213 label: __("Total Bookings", "yatra"),
3214 value: (displayProfile == null ? void 0 : displayProfile.total_bookings) ?? totalBookings,
3215 icon: Package,
3216 badge: (displayProfile == null ? void 0 : displayProfile.loyalty_tier) || ""
3217 },
3218 {
3219 label: __("Upcoming Trips", "yatra"),
3220 value: upcoming,
3221 icon: Calendar
3222 },
3223 {
3224 label: __("Outstanding Balance", "yatra"),
3225 value: currency(outstanding),
3226 icon: DollarSign
3227 },
3228 {
3229 label: __("Total Spent", "yatra"),
3230 value: currency(totalSpent),
3231 icon: ShieldCheck
3232 }
3233 ];
3234 }, [bookings, payments, displayProfile]);
3235 const renderSection = () => {
3236 switch (section) {
3237 case "dashboard":
3238 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3239 Dashboard,
3240 {
3241 bookings,
3242 payments,
3243 displayProfile: displayProfile || null,
3244 stats,
3245 notifications,
3246 conciergePhone: accountShell.companyPhone,
3247 conciergeEmail: accountShell.companyEmail,
3248 onSectionChange: (section2) => handleSectionChange(section2),
3249 onBookingOpen: handleBookingOpen
3250 }
3251 );
3252 case "bookings":
3253 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3254 Bookings,
3255 {
3256 bookings,
3257 conciergePhone: accountShell.companyPhone,
3258 conciergeEmail: accountShell.companyEmail,
3259 onSectionChange: (section2) => handleSectionChange(section2),
3260 initialBookingId: pendingBookingId,
3261 onBookingIdConsumed: () => setPendingBookingId(null)
3262 }
3263 );
3264 case "payments":
3265 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3266 Payments,
3267 {
3268 payments,
3269 onSectionChange: (section2) => handleSectionChange(section2)
3270 }
3271 );
3272 case "documents":
3273 return /* @__PURE__ */ jsxRuntimeExports.jsx(Documents, { documents });
3274 case "saved-trips":
3275 if (!wishlistEnabled) {
3276 return null;
3277 }
3278 return /* @__PURE__ */ jsxRuntimeExports.jsx(SavedTrips, { savedTrips, isLoading: isLoadingSavedTrips });
3279 case "profile":
3280 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3281 Profile,
3282 {
3283 profile: displayProfile || null,
3284 savedTrips,
3285 wishlistEnabled
3286 }
3287 );
3288 default:
3289 return null;
3290 }
3291 };
3292 return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen bg-gray-50 dark:bg-gray-900 py-10 pb-16 px-4 sm:px-6 lg:px-8", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full max-w-[var(--yatra-container-max-width,80rem)] mx-auto space-y-6 pb-8", children: [
3293 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-800 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between", children: [
3294 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
3295 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: (displayProfile == null ? void 0 : displayProfile.registered_at) ? formatDate(displayProfile.registered_at) : "" }),
3296 /* @__PURE__ */ jsxRuntimeExports.jsxs("h1", { className: "text-xl font-bold text-gray-900 dark:text-white", children: [
3297 __("Hello,", "yatra"),
3298 " ",
3299 (displayProfile == null ? void 0 : displayProfile.name) || __("Guest", "yatra")
3300 ] }),
3301 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: __(
3302 "Manage bookings, payments, and documents – everything for your adventures in one place.",
3303 "yatra"
3304 ) })
3305 ] }),
3306 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-wrap gap-3", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
3307 "div",
3308 {
3309 role: "button",
3310 tabIndex: 0,
3311 onClick: () => {
3312 const url = accountShell.logoutUrl;
3313 if (url) {
3314 window.location.href = url;
3315 }
3316 },
3317 onKeyDown: (e) => {
3318 if (e.key === "Enter" || e.key === " ") {
3319 e.preventDefault();
3320 const url = accountShell.logoutUrl;
3321 if (url) {
3322 window.location.href = url;
3323 }
3324 }
3325 },
3326 className: "inline-flex items-center gap-2 px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-600 cursor-pointer text-sm",
3327 children: [
3328 /* @__PURE__ */ jsxRuntimeExports.jsx(LogOut, { className: "w-4 h-4" }),
3329 " ",
3330 __("Logout", "yatra")
3331 ]
3332 }
3333 ) })
3334 ] }) }),
3335 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-6 lg:flex-row lg:items-start", children: [
3336 /* @__PURE__ */ jsxRuntimeExports.jsxs("aside", { className: "w-full lg:w-64 flex-shrink-0 space-y-4 lg:sticky lg:top-10 self-start bg-transparent", children: [
3337 /* @__PURE__ */ jsxRuntimeExports.jsx("nav", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-800 rounded-xl divide-y divide-gray-100 dark:divide-gray-800", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 space-y-1", children: accountNavigation.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
3338 "div",
3339 {
3340 role: "button",
3341 tabIndex: 0,
3342 onClick: () => handleSectionChange(item.id),
3343 className: `yatra-nav-item yatra-nav-item-${item.id} w-full flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition cursor-pointer ${section === item.id ? "bg-yatra-soft text-yatra-primary-dark dark:bg-yatra-surface-dark dark:text-yatra-primary-light" : "text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-900/40"}`,
3344 children: [
3345 /* @__PURE__ */ jsxRuntimeExports.jsx(item.icon, { className: "w-4 h-4" }),
3346 item.label
3347 ]
3348 },
3349 item.id
3350 )) }) }),
3351 /* @__PURE__ */ jsxRuntimeExports.jsxs(
3352 "div",
3353 {
3354 className: "rounded-xl p-6 text-white space-y-2 shadow-xl",
3355 style: {
3356 backgroundImage: "linear-gradient(to bottom right, var(--yatra-primary-dark, #2563eb), var(--yatra-primary-darker, #1e40af))"
3357 },
3358 children: [
3359 /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldCheck, { className: "w-6 h-6 text-white" }),
3360 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-white", children: __("Need help right away?", "yatra") }),
3361 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "font-semibold text-lg text-white", children: accountShell.companyName || __("Concierge Desk", "yatra") }),
3362 accountShell.companyPhone ? /* @__PURE__ */ jsxRuntimeExports.jsx(
3363 "a",
3364 {
3365 href: phoneToTelHref(accountShell.companyPhone),
3366 className: "text-sm font-medium text-white hover:underline",
3367 children: accountShell.companyPhone
3368 }
3369 ) : accountShell.companyEmail ? /* @__PURE__ */ jsxRuntimeExports.jsx(
3370 "a",
3371 {
3372 href: `mailto:${encodeURIComponent(accountShell.companyEmail)}`,
3373 className: "text-sm font-medium text-white hover:underline break-all",
3374 children: accountShell.companyEmail
3375 }
3376 ) : null
3377 ]
3378 }
3379 )
3380 ] }),
3381 /* @__PURE__ */ jsxRuntimeExports.jsx("section", { className: "flex-1 min-w-0 space-y-6", style: { minWidth: 0 }, children: isLoadingProfile && !profile ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
3382 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded-xl shadow-sm p-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse", children: [
3383 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-6 bg-gray-200 dark:bg-gray-700 rounded w-48 mb-2" }),
3384 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-96" })
3385 ] }) }),
3386 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-nowrap gap-6 overflow-x-auto", children: [1, 2, 3, 4, 5].map((i) => /* @__PURE__ */ jsxRuntimeExports.jsx(
3387 "div",
3388 {
3389 className: "flex-shrink-0 bg-white dark:bg-gray-800 rounded-xl p-6 border border-gray-100 dark:border-gray-700 min-w-0 flex-1",
3390 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse", children: [
3391 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-20 mb-3" }),
3392 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-8 bg-gray-200 dark:bg-gray-700 rounded w-16" })
3393 ] })
3394 },
3395 i
3396 )) }),
3397 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: [1, 2, 3].map((i) => /* @__PURE__ */ jsxRuntimeExports.jsx(
3398 "div",
3399 {
3400 className: "bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-6",
3401 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse", children: [
3402 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-5 bg-gray-200 dark:bg-gray-700 rounded w-64 mb-4" }),
3403 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-full mb-2" }),
3404 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-3/4" })
3405 ] })
3406 },
3407 i
3408 )) })
3409 ] }) : renderSection() })
3410 ] })
3411 ] }) });
3412 };
3413 const queryClient = new QueryClient({
3414 defaultOptions: {
3415 queries: {
3416 refetchOnWindowFocus: false,
3417 retry: 1,
3418 staleTime: 5 * 60 * 1e3
3419 // 5 minutes
3420 }
3421 }
3422 });
3423 const rootElement = document.getElementById("yatra-account-page-root");
3424 if (rootElement) {
3425 rootElement.setAttribute("translate", "no");
3426 rootElement.classList.add("notranslate");
3427 try {
3428 const root = client.createRoot(rootElement);
3429 root.render(
3430 /* @__PURE__ */ jsxRuntimeExports.jsx(React.StrictMode, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ToastProvider, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorBoundary, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(AccountPage, {}) }) }) }) })
3431 );
3432 } catch (error) {
3433 console.error("Error rendering account page:", error);
3434 const wrap = document.createElement("div");
3435 wrap.style.cssText = "padding: 40px; text-align: center;";
3436 const h2 = document.createElement("h2");
3437 h2.textContent = __("Error loading account page", "yatra");
3438 const p = document.createElement("p");
3439 p.textContent = __(
3440 "Please refresh the page or contact support if the problem continues.",
3441 "yatra"
3442 );
3443 wrap.appendChild(h2);
3444 wrap.appendChild(p);
3445 rootElement.replaceChildren(wrap);
3446 }
3447 }
3448 //# sourceMappingURL=account-page.js.map
3449