PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.8
Yatra – Travel Booking & Tour Operator Software v3.0.8
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.8, at assets/dist/js/account-page.js

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