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

3,386 lines 191.4 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, bx 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, aJ as PenSquare, b6 as XCircle, by as ShieldCheck, bf as Heart, s as LayoutDashboard, bz as LogOut, bu as QueryClient, bv as client, bw as QueryClientProvider } from "./react-vendor-CqkbFEvK.js";
2 import { f as formatYatraMoney, _ as __, e as applyCurrencyPosition, s as sprintf, h as _n, a as apiClient, A as API_ENDPOINTS, u as useToast, T as ToastProvider } from "./index-DRAt5dnR.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 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
1111 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
1112 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1113 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white", children: __("Booking Details", "yatra") }),
1114 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-1", children: __("Complete booking information", "yatra") })
1115 ] }),
1116 /* @__PURE__ */ jsxRuntimeExports.jsxs(
1117 "div",
1118 {
1119 role: "button",
1120 tabIndex: 0,
1121 onClick: onBack,
1122 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",
1123 children: [
1124 /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowRight, { className: "w-4 h-4 rotate-180" }),
1125 __("Back to Bookings", "yatra")
1126 ]
1127 }
1128 )
1129 ] }),
1130 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 lg:grid-cols-3 gap-6", children: [
1131 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "lg:col-span-2 space-y-6", children: [
1132 /* @__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: [
1133 /* @__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") }) }),
1134 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1135 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1136 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Booking Number", "yatra") }),
1137 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: booking.booking_number || `#${booking.id}` })
1138 ] }),
1139 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1140 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Trip", "yatra") }),
1141 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: booking.trip_title }),
1142 booking.trip_url ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
1143 "a",
1144 {
1145 href: booking.trip_url,
1146 className: "mt-2 inline-flex items-center gap-2 text-sm text-yatra-primary dark:text-yatra-on-dark hover:underline",
1147 children: [
1148 /* @__PURE__ */ jsxRuntimeExports.jsx(ExternalLink, { className: "w-4 h-4" }),
1149 __("View Trip", "yatra")
1150 ]
1151 }
1152 ) : null
1153 ] }),
1154 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1155 /* @__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: [
1156 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-3 h-3" }),
1157 __("Booking Date", "yatra")
1158 ] }),
1159 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatDate(booking.booking_date || booking.created_at) })
1160 ] }),
1161 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1162 /* @__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: [
1163 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-3 h-3" }),
1164 __("Travel Date", "yatra")
1165 ] }),
1166 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatTravelDateRange(booking.travel_date, booking.end_date) })
1167 ] }),
1168 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1169 /* @__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: [
1170 /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "w-3 h-3" }),
1171 __("Number of Travelers", "yatra")
1172 ] }),
1173 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: (() => {
1174 const t = booking.travelers;
1175 const n = Number(
1176 booking.travelers_count ?? (Array.isArray(t) ? t.length : t) ?? 0
1177 ) || 0;
1178 return sprintf(
1179 // translators: %d: number of travelers on this booking
1180 _n("%d Traveler", "%d Travelers", n),
1181 n
1182 );
1183 })() })
1184 ] })
1185 ] }),
1186 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-4 pt-4 border-t border-gray-200 dark:border-gray-700", children: [
1187 /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "text-sm font-semibold text-gray-900 dark:text-white mb-3", children: __("Payment Summary", "yatra") }),
1188 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
1189 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
1190 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-600 dark:text-gray-400", children: __("Gross Total", "yatra") }),
1191 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1192 booking.subtotal || booking.total_amount,
1193 booking.currency
1194 ) })
1195 ] }),
1196 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: [
1197 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-600 dark:text-gray-400", children: __("Subtotal (Taxable Amount)", "yatra") }),
1198 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1199 booking.taxable_amount,
1200 booking.currency
1201 ) })
1202 ] }),
1203 booking.discount_amount && booking.discount_amount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
1204 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-600 dark:text-gray-400", children: __("Discount", "yatra") }),
1205 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-green-600 dark:text-green-400", children: [
1206 "-",
1207 formatPriceForBooking(
1208 booking.discount_amount,
1209 booking.currency
1210 )
1211 ] })
1212 ] }),
1213 booking.itinerary_costs && booking.itinerary_costs.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1214 /* @__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") }) }),
1215 booking.itinerary_costs.map((cost, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1216 "div",
1217 {
1218 className: "flex justify-between text-sm ml-4",
1219 children: [
1220 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1221 cost.name,
1222 cost.price_per === "person" && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs text-gray-500 dark:text-gray-500 ml-1", children: [
1223 "(",
1224 __("per person", "yatra"),
1225 ")"
1226 ] }),
1227 cost.price_per === "group" && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs text-gray-500 dark:text-gray-500 ml-1", children: [
1228 "(",
1229 __("per booking", "yatra"),
1230 ")"
1231 ] })
1232 ] }),
1233 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1234 cost.total_cost,
1235 booking.currency
1236 ) })
1237 ]
1238 },
1239 index
1240 ))
1241 ] }),
1242 booking.tax_amount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: (() => {
1243 const taxBreakdown = booking.tax_breakdown;
1244 if (Array.isArray(taxBreakdown) && taxBreakdown.length > 0) {
1245 return taxBreakdown.map((tax, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1246 "div",
1247 {
1248 className: "flex justify-between text-sm",
1249 children: [
1250 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1251 tax.name,
1252 " (",
1253 tax.rate,
1254 "%)"
1255 ] }),
1256 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1257 tax.amount,
1258 booking.currency
1259 ) })
1260 ]
1261 },
1262 index
1263 ));
1264 }
1265 const taxDetails = booking.tax_details;
1266 if (taxDetails) {
1267 try {
1268 const taxes = typeof taxDetails === "string" ? JSON.parse(taxDetails) : taxDetails;
1269 if (Array.isArray(taxes) && taxes.length > 0) {
1270 return taxes.map((tax, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1271 "div",
1272 {
1273 className: "flex justify-between text-sm",
1274 children: [
1275 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1276 tax.name,
1277 " (",
1278 tax.rate,
1279 "%)"
1280 ] }),
1281 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1282 tax.amount,
1283 booking.currency
1284 ) })
1285 ]
1286 },
1287 index
1288 ));
1289 }
1290 } catch (e) {
1291 console.error("Failed to parse tax_details:", e);
1292 }
1293 }
1294 if (booking.tax_amount > 0) {
1295 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-sm", children: [
1296 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-600 dark:text-gray-400", children: [
1297 __("Tax", "yatra"),
1298 " (",
1299 booking.tax_rate,
1300 "%)"
1301 ] }),
1302 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1303 booking.tax_amount,
1304 booking.currency
1305 ) })
1306 ] });
1307 }
1308 return null;
1309 })() }),
1310 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between text-base font-semibold pt-2 border-t border-gray-200 dark:border-gray-700", children: [
1311 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: __("Net Amount", "yatra") }),
1312 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-900 dark:text-white", children: formatPriceForBooking(
1313 booking.total_amount,
1314 booking.currency
1315 ) })
1316 ] })
1317 ] })
1318 ] })
1319 ] }),
1320 /* @__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: [
1321 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4", children: __("Customer Information", "yatra") }),
1322 (() => {
1323 const leadTraveler = Array.isArray(booking.travelers_data) && booking.travelers_data.length > 0 ? booking.travelers_data[0] : null;
1324 const leadFields = leadTraveler && typeof leadTraveler === "object" ? leadTraveler.fields || leadTraveler : null;
1325 const firstName = booking.contact_first_name || leadFields && leadFields.first_name || "";
1326 const lastName = booking.contact_last_name || leadFields && leadFields.last_name || "";
1327 const fullName = [firstName, lastName].filter(Boolean).join(" ").trim() || booking.customer_name || "";
1328 const email = booking.contact_email || booking.customer_email || leadFields && leadFields.email || "";
1329 const phone = booking.contact_phone || booking.customer_phone || leadFields && leadFields.phone || "";
1330 const country = booking.contact_country || leadFields && leadFields.country || "";
1331 const hasAny = fullName || email || phone || country;
1332 if (!hasAny) {
1333 return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: __("No customer information recorded.", "yatra") });
1334 }
1335 return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-3", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1336 fullName && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium text-gray-900 dark:text-white mb-1", children: fullName }),
1337 /* @__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: [
1338 email && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1.5", children: [
1339 /* @__PURE__ */ jsxRuntimeExports.jsx(Mail, { className: "w-4 h-4" }),
1340 /* @__PURE__ */ jsxRuntimeExports.jsx(
1341 "a",
1342 {
1343 href: `mailto:${email}`,
1344 className: "hover:text-yatra-primary dark:hover:text-yatra-on-dark",
1345 children: email
1346 }
1347 )
1348 ] }),
1349 phone && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1.5", children: [
1350 /* @__PURE__ */ jsxRuntimeExports.jsx(Phone, { className: "w-4 h-4" }),
1351 /* @__PURE__ */ jsxRuntimeExports.jsx(
1352 "a",
1353 {
1354 href: `tel:${String(phone).replace(/\s+/g, "")}`,
1355 className: "hover:text-yatra-primary dark:hover:text-yatra-on-dark",
1356 children: phone
1357 }
1358 )
1359 ] }),
1360 country && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: country })
1361 ] })
1362 ] }) });
1363 })()
1364 ] }),
1365 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: [
1366 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1367 /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "w-5 h-5" }),
1368 __("Travelers Information", "yatra"),
1369 /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-sm font-normal text-gray-500 dark:text-gray-400", children: [
1370 "(",
1371 booking.travelers_data.length,
1372 " ",
1373 booking.travelers_data.length === 1 ? __("traveler", "yatra") : __("travelers", "yatra"),
1374 ")"
1375 ] })
1376 ] }),
1377 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: booking.travelers_data.map((traveler, index) => {
1378 const travelerFieldsData = traveler.fields || traveler;
1379 const systemFields = [
1380 "id",
1381 "booking_id",
1382 "traveller_index",
1383 "is_lead",
1384 "created_at",
1385 "updated_at",
1386 "fields"
1387 ];
1388 const travelerEntries = Object.entries(
1389 travelerFieldsData
1390 ).filter(([key, value]) => {
1391 if (systemFields.includes(key)) return false;
1392 if (!value || typeof value === "string" && value.trim() === "")
1393 return false;
1394 if (typeof value === "object" && !Array.isArray(value))
1395 return false;
1396 return true;
1397 });
1398 const firstName = travelerFieldsData.first_name || traveler.first_name || "";
1399 const lastName = travelerFieldsData.last_name || traveler.last_name || "";
1400 return /* @__PURE__ */ jsxRuntimeExports.jsxs(
1401 "div",
1402 {
1403 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"}`,
1404 children: [
1405 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
1406 /* @__PURE__ */ jsxRuntimeExports.jsxs("h4", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: [
1407 index === 0 ? __("Lead Traveler", "yatra") : `${__("Traveler", "yatra")} ${index + 1}`,
1408 (firstName || lastName) && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-normal text-gray-500 dark:text-gray-400 ml-2", children: [
1409 "-",
1410 " ",
1411 [firstName, lastName].filter(Boolean).join(" ")
1412 ] })
1413 ] }),
1414 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") })
1415 ] }),
1416 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-2 md:grid-cols-3 gap-3", children: travelerEntries.map(([fieldId, fieldValue]) => {
1417 if (fieldId === "first_name" || fieldId === "last_name")
1418 return null;
1419 const label = fieldId.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase());
1420 let displayValue = String(fieldValue);
1421 if (fieldId.includes("date") || fieldId.includes("expiry")) {
1422 try {
1423 displayValue = formatDate(fieldValue);
1424 } catch {
1425 displayValue = String(fieldValue);
1426 }
1427 }
1428 if ((fieldId === "nationality" || fieldId === "country") && fieldValue && typeof fieldValue === "string" && fieldValue.length === 2) {
1429 displayValue = getCountryName(fieldValue);
1430 }
1431 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1432 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mb-0.5", children: label }),
1433 /* @__PURE__ */ jsxRuntimeExports.jsx(
1434 "div",
1435 {
1436 className: `text-sm text-gray-900 dark:text-white ${fieldId === "passport" ? "font-mono" : ""}`,
1437 children: displayValue
1438 }
1439 )
1440 ] }, fieldId);
1441 }) })
1442 ]
1443 },
1444 index
1445 );
1446 }) })
1447 ] }),
1448 emergencyContact && Object.values(emergencyContact).some(
1449 (v) => v && String(v).trim() !== ""
1450 ) && /* @__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: [
1451 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1452 /* @__PURE__ */ jsxRuntimeExports.jsx(AlertCircle, { className: "w-5 h-5" }),
1453 __("Emergency Contact", "yatra")
1454 ] }),
1455 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-3", children: Object.entries(emergencyContact).filter(
1456 ([_, value]) => value && String(value).trim() !== ""
1457 ).map(([fieldId, fieldValue]) => {
1458 const label = fieldId.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase());
1459 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1460 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mb-0.5", children: label }),
1461 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium text-gray-900 dark:text-white", children: String(fieldValue) })
1462 ] }, fieldId);
1463 }) })
1464 ] }),
1465 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: [
1466 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1467 /* @__PURE__ */ jsxRuntimeExports.jsx(FileText, { className: "w-5 h-5" }),
1468 __("Special Requests", "yatra")
1469 ] }),
1470 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap", children: booking.notes })
1471 ] }),
1472 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: [
1473 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
1474 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-5 h-5" }),
1475 __("Downloads", "yatra")
1476 ] }),
1477 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-3", children: booking.downloads.map((d) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
1478 "div",
1479 {
1480 className: "flex items-center justify-between gap-3 p-3 rounded-lg border border-gray-200 dark:border-gray-700",
1481 children: [
1482 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
1483 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium text-gray-900 dark:text-white truncate", children: d.title }),
1484 d.access_label ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mt-1", children: d.access_label }) : null,
1485 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
1486 ] }),
1487 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: [
1488 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-4 h-4" }),
1489 __("Not Available", "yatra")
1490 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
1491 "a",
1492 {
1493 href: d.url,
1494 target: "_blank",
1495 rel: "noreferrer",
1496 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",
1497 children: [
1498 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-4 h-4" }),
1499 __("Download", "yatra")
1500 ]
1501 }
1502 )
1503 ]
1504 },
1505 d.id
1506 )) })
1507 ] })
1508 ] }),
1509 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
1510 /* @__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: [
1511 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4", children: __("Payment Information", "yatra") }),
1512 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
1513 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1514 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Booking Status", "yatra") }),
1515 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.booking_status), children: getStatusLabel(booking.booking_status) }) })
1516 ] }),
1517 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1518 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Payment Status", "yatra") }),
1519 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.payment_status), children: getStatusLabel(booking.payment_status) }) })
1520 ] }),
1521 booking.payment_method && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1522 /* @__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: [
1523 /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-3 h-3" }),
1524 __("Payment Method", "yatra")
1525 ] }),
1526 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: booking.payment_method })
1527 ] }),
1528 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1529 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Total Amount", "yatra") }),
1530 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: formatPriceForBooking(
1531 booking.total_amount,
1532 booking.currency
1533 ) })
1534 ] }),
1535 booking.amount_paid > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1536 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Amount Paid", "yatra") }),
1537 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatPriceForBooking(
1538 booking.amount_paid,
1539 booking.currency
1540 ) })
1541 ] }),
1542 booking.amount_due > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1543 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Amount Due", "yatra") }),
1544 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-semibold text-amber-600 dark:text-amber-400", children: formatPriceForBooking(
1545 booking.amount_due,
1546 booking.currency
1547 ) })
1548 ] })
1549 ] })
1550 ] }),
1551 /* @__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: [
1552 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4", children: __("Timeline", "yatra") }),
1553 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
1554 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1555 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Created", "yatra") }),
1556 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatDate(booking.created_at || booking.booking_date) })
1557 ] }),
1558 booking.updated_at && booking.updated_at !== booking.created_at && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1559 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1", children: __("Last Updated", "yatra") }),
1560 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-900 dark:text-white", children: formatDate(booking.updated_at) })
1561 ] })
1562 ] })
1563 ] })
1564 ] })
1565 ] })
1566 ] });
1567 };
1568 const Bookings = ({
1569 bookings,
1570 conciergePhone = "",
1571 conciergeEmail = "",
1572 onSectionChange,
1573 initialBookingId = null,
1574 onBookingIdConsumed
1575 }) => {
1576 const conciergeTel = phoneToTelHref(conciergePhone);
1577 const conciergeMail = String(conciergeEmail || "").trim();
1578 const [searchTerm, setSearchTerm] = reactExports.useState("");
1579 const [bookingFilter, setBookingFilter] = reactExports.useState("all");
1580 const [selectedBookingId, setSelectedBookingId] = reactExports.useState(
1581 initialBookingId
1582 );
1583 React.useEffect(() => {
1584 if (initialBookingId && initialBookingId !== selectedBookingId) {
1585 setSelectedBookingId(initialBookingId);
1586 onBookingIdConsumed == null ? void 0 : onBookingIdConsumed();
1587 }
1588 }, [initialBookingId]);
1589 const [payLoading, setPayLoading] = reactExports.useState(null);
1590 const {
1591 data: bookingDetailsData,
1592 isPending: isBookingDetailLoading,
1593 isError: isBookingDetailError
1594 } = useQuery({
1595 queryKey: ["booking-details", selectedBookingId],
1596 queryFn: async () => {
1597 if (!selectedBookingId) return null;
1598 const response = await apiClient.get(
1599 API_ENDPOINTS.CUSTOMER_MY_BOOKING(selectedBookingId)
1600 );
1601 const inner = response && typeof response === "object" && "data" in response && response.data && typeof response.data === "object" ? response.data : response;
1602 return inner;
1603 },
1604 enabled: !!selectedBookingId
1605 });
1606 const handleBookingSelect = (bookingId) => {
1607 setSelectedBookingId(bookingId);
1608 };
1609 const handleBackToList = () => {
1610 setSelectedBookingId(null);
1611 };
1612 const handleDownloadClick = async (bookingId) => {
1613 try {
1614 await downloadVoucher(bookingId);
1615 } catch (e) {
1616 const msg = e instanceof Error ? e.message : __("Download failed.", "yatra");
1617 window.alert(msg);
1618 }
1619 };
1620 const startRemainingPaymentSession = async (bookingId) => {
1621 setPayLoading(bookingId);
1622 try {
1623 const response = await apiClient.post(
1624 API_ENDPOINTS.PAYMENT_REMAINING_SESSION,
1625 { booking_id: bookingId }
1626 );
1627 const payload = response && typeof response === "object" && "data" in response && response.data && typeof response.data === "object" ? response.data : response;
1628 const checkoutUrl = payload && typeof payload === "object" && "checkout_url" in payload && typeof payload.checkout_url === "string" ? payload.checkout_url : "";
1629 if (checkoutUrl) {
1630 window.location.href = checkoutUrl;
1631 } else {
1632 window.alert(__("Could not start payment. Please try again.", "yatra"));
1633 }
1634 } catch (error) {
1635 console.error("Error initiating payment:", error);
1636 const msg = error instanceof Error && error.message ? error.message : __("Could not start payment.", "yatra");
1637 window.alert(msg);
1638 } finally {
1639 setPayLoading(null);
1640 }
1641 };
1642 if (selectedBookingId) {
1643 return /* @__PURE__ */ jsxRuntimeExports.jsx(
1644 BookingDetails,
1645 {
1646 booking: isBookingDetailLoading || isBookingDetailError ? null : bookingDetailsData,
1647 isLoading: isBookingDetailLoading,
1648 onBack: handleBackToList
1649 }
1650 );
1651 }
1652 const displayBookings = bookings;
1653 let filteredDisplayBookings = displayBookings;
1654 if (bookingFilter === "upcoming") {
1655 const today = /* @__PURE__ */ new Date();
1656 today.setHours(0, 0, 0, 0);
1657 filteredDisplayBookings = filteredDisplayBookings.filter((b) => {
1658 const travelDate = new Date(b.travel_date);
1659 return travelDate >= today;
1660 });
1661 } else if (bookingFilter === "pending") {
1662 filteredDisplayBookings = filteredDisplayBookings.filter(
1663 (b) => b.payment_status === "pending" || b.booking_status === "pending"
1664 );
1665 } else if (bookingFilter === "completed") {
1666 filteredDisplayBookings = filteredDisplayBookings.filter(
1667 (b) => b.booking_status === "completed"
1668 );
1669 }
1670 if (searchTerm.trim()) {
1671 const searchLower = searchTerm.toLowerCase().trim();
1672 filteredDisplayBookings = filteredDisplayBookings.filter(
1673 (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)
1674 );
1675 }
1676 const bookingStats = {
1677 total: displayBookings.length,
1678 upcoming: displayBookings.filter(
1679 (b) => new Date(b.travel_date) >= /* @__PURE__ */ new Date()
1680 ).length,
1681 pending: displayBookings.filter(
1682 (b) => b.payment_status === "pending" || b.booking_status === "pending"
1683 ).length,
1684 completed: displayBookings.filter((b) => b.booking_status === "completed").length,
1685 totalSpent: displayBookings.reduce((sum, b) => sum + b.total_amount, 0)
1686 };
1687 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-bookings-page space-y-6", children: [
1688 /* @__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: [
1689 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1690 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-bold text-gray-900 dark:text-white", children: __("Bookings", "yatra") }),
1691 /* @__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") })
1692 ] }),
1693 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3 lg:flex-row lg:items-center lg:gap-4", children: [
1694 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1695 "input",
1696 {
1697 placeholder: __("Search bookings...", "yatra"),
1698 value: searchTerm,
1699 onChange: (e) => setSearchTerm(e.target.value),
1700 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"
1701 }
1702 ) }),
1703 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
1704 "select",
1705 {
1706 value: bookingFilter,
1707 onChange: (e) => setBookingFilter(
1708 e.target.value
1709 ),
1710 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",
1711 children: [
1712 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "all", children: __("All Bookings", "yatra") }),
1713 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "upcoming", children: __("Upcoming", "yatra") }),
1714 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "pending", children: __("Pending", "yatra") }),
1715 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "completed", children: __("Completed", "yatra") })
1716 ]
1717 }
1718 ) })
1719 ] })
1720 ] }) }),
1721 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-nowrap gap-6 overflow-x-auto", children: [
1722 /* @__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: [
1723 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1724 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Bookings", "yatra") }),
1725 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: bookingStats.total })
1726 ] }),
1727 /* @__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" }) })
1728 ] }) }),
1729 /* @__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: [
1730 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1731 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Upcoming", "yatra") }),
1732 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-emerald-600 dark:text-emerald-400", children: bookingStats.upcoming })
1733 ] }),
1734 /* @__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" }) })
1735 ] }) }),
1736 /* @__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: [
1737 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1738 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Pending", "yatra") }),
1739 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-amber-600 dark:text-amber-400", children: bookingStats.pending })
1740 ] }),
1741 /* @__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" }) })
1742 ] }) }),
1743 /* @__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: [
1744 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1745 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Completed", "yatra") }),
1746 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-600 dark:text-gray-400", children: bookingStats.completed })
1747 ] }),
1748 /* @__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" }) })
1749 ] }) }),
1750 /* @__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: [
1751 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1752 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Spent", "yatra") }),
1753 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: currency(bookingStats.totalSpent) })
1754 ] }),
1755 /* @__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" }) })
1756 ] }) })
1757 ] }),
1758 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: [
1759 /* @__PURE__ */ jsxRuntimeExports.jsx(Package, { className: "w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-4" }),
1760 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 font-medium mb-1", children: __("No bookings found", "yatra") }),
1761 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __("Try adjusting your filters or check back later.", "yatra") })
1762 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: filteredDisplayBookings.map((booking) => {
1763 const bookingId = Number(booking.id);
1764 const isUpcoming = new Date(booking.travel_date) > /* @__PURE__ */ new Date();
1765 const isCompleted = booking.booking_status === "completed";
1766 const paidNumeric = typeof booking.amount_paid === "number" ? booking.amount_paid : parseFloat(booking.amount_paid || "0");
1767 const totalNumeric = typeof booking.total_amount === "number" ? booking.total_amount : parseFloat(booking.total_amount || "0");
1768 const totalPaid = paidNumeric;
1769 const amountDue = totalNumeric - totalPaid;
1770 const canPayRemaining = amountDue > 0 && booking.payment_status !== "paid";
1771 return /* @__PURE__ */ jsxRuntimeExports.jsx(
1772 "div",
1773 {
1774 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",
1775 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-6", children: [
1776 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col lg:flex-row lg:items-start lg:justify-between gap-4 mb-4", children: [
1777 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 mb-2", children: [
1778 /* @__PURE__ */ jsxRuntimeExports.jsx(
1779 "div",
1780 {
1781 className: `p-2 rounded-lg ${isUpcoming ? "bg-emerald-50 dark:bg-emerald-900/20" : isCompleted ? "bg-gray-50 dark:bg-gray-700" : "bg-amber-50 dark:bg-amber-900/20"}`,
1782 children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1783 MapPin,
1784 {
1785 className: `w-5 h-5 ${isUpcoming ? "text-emerald-600 dark:text-emerald-400" : isCompleted ? "text-gray-400" : "text-amber-600 dark:text-amber-400"}`
1786 }
1787 )
1788 }
1789 ),
1790 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [
1791 /* @__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 }),
1792 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-bold text-gray-900 dark:text-white mb-1", children: booking.trip_title }),
1793 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400 flex items-center gap-1", children: [
1794 /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "w-4 h-4 text-gray-600 dark:text-gray-400" }),
1795 booking.destination || __("Multiple destinations", "yatra")
1796 ] })
1797 ] })
1798 ] }) }),
1799 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap gap-2 items-start", children: [
1800 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.booking_status), children: getStatusLabel(booking.booking_status) }),
1801 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(booking.payment_status), children: getStatusLabel(booking.payment_status) })
1802 ] })
1803 ] }),
1804 /* @__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: [
1805 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1806 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Travel Date", "yatra") }),
1807 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: formatTravelDateRange(
1808 booking.travel_date,
1809 booking.end_date
1810 ) })
1811 ] }),
1812 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1813 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Travelers", "yatra") }),
1814 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: (() => {
1815 const n = Number(
1816 booking.travelers_count ?? booking.travelers ?? 0
1817 ) || 0;
1818 return sprintf(
1819 // translators: %d: number of travelers on this booking.
1820 _n("%d traveler", "%d travelers", n),
1821 n
1822 );
1823 })() })
1824 ] }),
1825 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1826 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Amount", "yatra") }),
1827 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: currency(booking.total_amount) })
1828 ] }),
1829 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1830 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Paid / Due", "yatra") }),
1831 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: [
1832 currency(totalPaid ?? 0),
1833 amountDue !== null && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs font-normal text-gray-500 dark:text-gray-400 ml-1", children: [
1834 __("Due:", "yatra"),
1835 " ",
1836 currency(amountDue)
1837 ] })
1838 ] })
1839 ] }),
1840 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1841 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Booked On", "yatra") }),
1842 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: formatDate(booking.booking_date || booking.created_at) })
1843 ] })
1844 ] }),
1845 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-booking-actions flex flex-wrap gap-3", children: [
1846 /* @__PURE__ */ jsxRuntimeExports.jsx(
1847 "div",
1848 {
1849 role: "button",
1850 tabIndex: 0,
1851 onClick: () => handleBookingSelect(bookingId),
1852 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",
1853 children: __("View Details", "yatra")
1854 }
1855 ),
1856 /* @__PURE__ */ jsxRuntimeExports.jsx(
1857 "div",
1858 {
1859 role: "button",
1860 tabIndex: 0,
1861 onClick: () => handleDownloadClick(bookingId),
1862 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",
1863 children: __("Download Voucher", "yatra")
1864 }
1865 ),
1866 /* @__PURE__ */ jsxRuntimeExports.jsx(
1867 "div",
1868 {
1869 role: "button",
1870 tabIndex: 0,
1871 onClick: () => onSectionChange("payments"),
1872 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",
1873 children: __("Payment", "yatra")
1874 }
1875 ),
1876 canPayRemaining && /* @__PURE__ */ jsxRuntimeExports.jsxs(
1877 "button",
1878 {
1879 type: "button",
1880 onClick: () => bookingId && startRemainingPaymentSession(bookingId),
1881 disabled: payLoading === bookingId,
1882 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",
1883 children: [
1884 payLoading === bookingId ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
1885 "svg",
1886 {
1887 className: "w-4 h-4 animate-spin",
1888 viewBox: "0 0 24 24",
1889 fill: "none",
1890 stroke: "currentColor",
1891 strokeWidth: "2",
1892 children: [
1893 /* @__PURE__ */ jsxRuntimeExports.jsx(
1894 "circle",
1895 {
1896 cx: "12",
1897 cy: "12",
1898 r: "10",
1899 strokeOpacity: "0.25"
1900 }
1901 ),
1902 /* @__PURE__ */ jsxRuntimeExports.jsx("path", { d: "M4 12a8 8 0 0 1 8-8" })
1903 ]
1904 }
1905 ) : null,
1906 __("Pay Remaining Balance", "yatra")
1907 ]
1908 }
1909 ),
1910 conciergeTel ? /* @__PURE__ */ jsxRuntimeExports.jsx(
1911 "a",
1912 {
1913 href: conciergeTel,
1914 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",
1915 children: __("Call us", "yatra")
1916 }
1917 ) : conciergeMail ? /* @__PURE__ */ jsxRuntimeExports.jsx(
1918 "a",
1919 {
1920 href: `mailto:${encodeURIComponent(conciergeMail)}`,
1921 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",
1922 children: __("Email us", "yatra")
1923 }
1924 ) : null
1925 ] })
1926 ] })
1927 },
1928 booking.id
1929 );
1930 }) })
1931 ] });
1932 };
1933 function paymentTypeLabel(type) {
1934 switch (type) {
1935 case "deposit":
1936 return __("Deposit", "yatra");
1937 case "balance":
1938 return __("Balance", "yatra");
1939 case "installment":
1940 return __("Installment", "yatra");
1941 default:
1942 return type;
1943 }
1944 }
1945 const Payments = ({ payments, onSectionChange }) => {
1946 const displayPayments = payments;
1947 const bookingSummaries = React.useMemo(() => {
1948 const map = /* @__PURE__ */ new Map();
1949 displayPayments.forEach((payment) => {
1950 if (typeof payment.booking_id !== "number") {
1951 return;
1952 }
1953 const total = typeof payment.booking_total_amount === "number" ? payment.booking_total_amount : null;
1954 const dueValue = typeof payment.booking_amount_due === "number" ? payment.booking_amount_due : null;
1955 const paidValue = typeof payment.booking_amount_paid === "number" ? payment.booking_amount_paid : null;
1956 const paid = paidValue ?? (total !== null && dueValue !== null ? total - dueValue : null);
1957 const due = dueValue ?? (total !== null && paid !== null ? total - paid : null);
1958 const existing = map.get(payment.booking_id);
1959 const summary = {
1960 total: total ?? (existing == null ? void 0 : existing.total) ?? 0,
1961 paid: paid ?? (existing == null ? void 0 : existing.paid) ?? 0,
1962 due: due ?? (existing == null ? void 0 : existing.due) ?? 0
1963 };
1964 if (!existing || summary.due < existing.due) {
1965 map.set(payment.booking_id, summary);
1966 }
1967 });
1968 return Array.from(map.values());
1969 }, [displayPayments]);
1970 const paymentStats = React.useMemo(() => {
1971 const totals = bookingSummaries.reduce(
1972 (acc, summary) => {
1973 acc.totalAmount += summary.total;
1974 acc.paidAmount += summary.total - summary.due;
1975 acc.outstanding += summary.due;
1976 if (summary.due > 0) {
1977 acc.pendingBookings += 1;
1978 } else {
1979 acc.paidBookings += 1;
1980 }
1981 return acc;
1982 },
1983 {
1984 totalAmount: 0,
1985 paidAmount: 0,
1986 outstanding: 0,
1987 pendingBookings: 0,
1988 paidBookings: 0
1989 }
1990 );
1991 return {
1992 total: displayPayments.length,
1993 paid: totals.paidBookings,
1994 pending: totals.pendingBookings,
1995 totalPaidAmount: totals.paidAmount,
1996 outstandingAmount: totals.outstanding
1997 };
1998 }, [displayPayments, bookingSummaries]);
1999 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-payments-page space-y-6", children: [
2000 /* @__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: [
2001 /* @__PURE__ */ jsxRuntimeExports.jsxs("h2", { className: "text-lg font-bold text-gray-900 dark:text-white flex items-center gap-3", children: [
2002 /* @__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" }) }),
2003 __("Payments & Invoices", "yatra")
2004 ] }),
2005 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-2", children: __(
2006 "Track deposits, balances, and installment schedules with secure payment links.",
2007 "yatra"
2008 ) })
2009 ] }) }) }),
2010 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-payments-stats grid gap-4 sm:grid-cols-2 lg:grid-cols-4", children: [
2011 /* @__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: [
2012 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2013 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Total Payments", "yatra") }),
2014 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: paymentStats.total })
2015 ] }),
2016 /* @__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" }) })
2017 ] }) }),
2018 /* @__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: [
2019 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2020 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Paid", "yatra") }),
2021 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-emerald-600 dark:text-emerald-400", children: paymentStats.paid }),
2022 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-400 dark:text-gray-500", children: currency(paymentStats.totalPaidAmount) })
2023 ] }),
2024 /* @__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" }) })
2025 ] }) }),
2026 /* @__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: [
2027 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2028 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Pending", "yatra") }),
2029 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-amber-600 dark:text-amber-400", children: paymentStats.pending })
2030 ] }),
2031 /* @__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" }) })
2032 ] }) }),
2033 /* @__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: [
2034 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2035 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Outstanding", "yatra") }),
2036 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-gray-900 dark:text-white", children: currency(paymentStats.outstandingAmount) })
2037 ] }),
2038 /* @__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" }) })
2039 ] }) })
2040 ] }),
2041 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: [
2042 /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-4" }),
2043 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 font-medium mb-1", children: __("No payments found", "yatra") }),
2044 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __(
2045 "Payment history will appear here once you make a booking.",
2046 "yatra"
2047 ) })
2048 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: displayPayments.map((payment) => {
2049 const bookingTotal = typeof payment.booking_total_amount === "number" ? payment.booking_total_amount : null;
2050 const bookingPaid = typeof payment.booking_amount_paid === "number" ? payment.booking_amount_paid : null;
2051 const bookingDue = typeof payment.booking_amount_due === "number" ? payment.booking_amount_due : null;
2052 const total = bookingTotal ?? payment.amount;
2053 const paid = bookingPaid ?? (bookingDue !== null && bookingTotal !== null ? bookingTotal - bookingDue : payment.amount);
2054 const dueRaw = bookingDue ?? (bookingTotal !== null ? bookingTotal - paid : total - paid);
2055 const due = Math.max(0, dueRaw || 0);
2056 const canPayRemaining = typeof payment.booking_id === "number" && due > 0.01;
2057 const isPaid = payment.status === "paid" || payment.status === "completed";
2058 const isPending = payment.status === "pending";
2059 return /* @__PURE__ */ jsxRuntimeExports.jsx(
2060 "div",
2061 {
2062 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",
2063 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-6", children: [
2064 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col lg:flex-row lg:items-start lg:justify-between gap-4 mb-4", children: [
2065 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 mb-2", children: [
2066 /* @__PURE__ */ jsxRuntimeExports.jsx(
2067 "div",
2068 {
2069 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"}`,
2070 children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2071 CreditCard,
2072 {
2073 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"}`
2074 }
2075 )
2076 }
2077 ),
2078 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [
2079 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs uppercase tracking-wider text-gray-500 dark:text-gray-400 font-medium mb-1", children: payment.reference }),
2080 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-base font-bold text-gray-900 dark:text-white mb-1", children: [
2081 __("Booking", "yatra"),
2082 ": ",
2083 payment.booking_number
2084 ] }),
2085 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400 flex items-center gap-1", children: [
2086 /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "w-4 h-4" }),
2087 formatDate(payment.date)
2088 ] })
2089 ] })
2090 ] }) }),
2091 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap gap-2 items-start", children: [
2092 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: getBadge(payment.status), children: getStatusLabel(payment.status) }),
2093 /* @__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) })
2094 ] })
2095 ] }),
2096 /* @__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: [
2097 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2098 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center gap-1", children: [
2099 /* @__PURE__ */ jsxRuntimeExports.jsx(DollarSign, { className: "w-3.5 h-3.5" }),
2100 __("Amount", "yatra")
2101 ] }),
2102 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: currency(payment.amount) })
2103 ] }),
2104 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2105 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center gap-1", children: [
2106 /* @__PURE__ */ jsxRuntimeExports.jsx(CreditCard, { className: "w-3.5 h-3.5" }),
2107 __("Payment Method", "yatra")
2108 ] }),
2109 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: payment.method })
2110 ] }),
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(Calendar, { className: "w-3.5 h-3.5" }),
2114 __("Payment Date", "yatra")
2115 ] }),
2116 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: formatDate(payment.date) })
2117 ] })
2118 ] }),
2119 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-payment-actions flex flex-wrap gap-3", children: [
2120 isPaid && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2121 "button",
2122 {
2123 type: "button",
2124 onClick: async () => {
2125 try {
2126 await downloadInvoice(payment.id);
2127 } catch (err) {
2128 alert(
2129 err instanceof Error ? err.message : __("Download failed.", "yatra")
2130 );
2131 }
2132 },
2133 className: "yatra-payment-action yatra-payment-action-invoice inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium",
2134 style: { backgroundColor: "#059669", color: "#ffffff" },
2135 children: [
2136 /* @__PURE__ */ jsxRuntimeExports.jsx(Download, { className: "w-4 h-4" }),
2137 __("Download Invoice", "yatra")
2138 ]
2139 }
2140 ),
2141 isPaid && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2142 "button",
2143 {
2144 type: "button",
2145 onClick: async () => {
2146 try {
2147 await previewPaymentInvoice(payment.id);
2148 } catch (err) {
2149 alert(
2150 err instanceof Error ? err.message : __("Could not open receipt.", "yatra")
2151 );
2152 }
2153 },
2154 className: "yatra-payment-action yatra-payment-action-receipt inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium",
2155 style: {
2156 backgroundColor: "var(--yatra-primary-dark, #2563eb)",
2157 color: "#ffffff"
2158 },
2159 children: [
2160 /* @__PURE__ */ jsxRuntimeExports.jsx(FileText, { className: "w-4 h-4" }),
2161 __("View Receipt", "yatra")
2162 ]
2163 }
2164 ),
2165 isPending && !canPayRemaining && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2166 "button",
2167 {
2168 type: "button",
2169 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",
2170 children: [
2171 /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "w-4 h-4" }),
2172 __("Pending approval", "yatra")
2173 ]
2174 }
2175 ),
2176 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2177 "button",
2178 {
2179 type: "button",
2180 onClick: () => onSectionChange("bookings"),
2181 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",
2182 children: [
2183 /* @__PURE__ */ jsxRuntimeExports.jsx(Eye, { className: "w-4 h-4" }),
2184 __("View Booking Details", "yatra")
2185 ]
2186 }
2187 )
2188 ] })
2189 ] })
2190 },
2191 payment.id
2192 );
2193 }) })
2194 ] });
2195 };
2196 function documentCategoryLabel(category) {
2197 switch (category) {
2198 case "itinerary":
2199 return __("Itinerary", "yatra");
2200 case "voucher":
2201 return __("Voucher", "yatra");
2202 case "invoice":
2203 return __("Invoice", "yatra");
2204 case "downloads":
2205 return __("Downloads", "yatra");
2206 default:
2207 return category;
2208 }
2209 }
2210 const Documents = ({ documents }) => {
2211 const [searchTerm, setSearchTerm] = reactExports.useState("");
2212 const [selectedCategory, setSelectedCategory] = reactExports.useState("all");
2213 const displayDocuments = documents;
2214 let filteredDocuments = [...displayDocuments];
2215 if (selectedCategory !== "all") {
2216 filteredDocuments = filteredDocuments.filter(
2217 (d) => d.category === selectedCategory
2218 );
2219 }
2220 if (searchTerm.trim()) {
2221 const searchLower = searchTerm.toLowerCase().trim();
2222 filteredDocuments = filteredDocuments.filter((d) => {
2223 const name = d.name || "";
2224 const tripTitle = d.trip_title || "";
2225 const category = d.category || "";
2226 return name.toLowerCase().includes(searchLower) || tripTitle.toLowerCase().includes(searchLower) || category.toLowerCase().includes(searchLower);
2227 });
2228 }
2229 const documentsByCategory = {
2230 itinerary: filteredDocuments.filter((d) => d.category === "itinerary"),
2231 voucher: filteredDocuments.filter((d) => d.category === "voucher"),
2232 invoice: filteredDocuments.filter((d) => d.category === "invoice"),
2233 downloads: filteredDocuments.filter((d) => d.category === "downloads")
2234 };
2235 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-documents-page space-y-6", children: [
2236 /* @__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: [
2237 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2238 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-bold text-gray-900 dark:text-white", children: __("Travel Documents", "yatra") }),
2239 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-2", children: __(
2240 "Download itineraries, vouchers, invoices, and other documents for each trip.",
2241 "yatra"
2242 ) })
2243 ] }),
2244 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-3 lg:flex-row lg:items-center lg:gap-4", children: [
2245 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2246 "input",
2247 {
2248 type: "text",
2249 placeholder: __("Search documents...", "yatra"),
2250 value: searchTerm,
2251 onChange: (e) => setSearchTerm(e.target.value),
2252 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"
2253 }
2254 ) }),
2255 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
2256 "select",
2257 {
2258 value: selectedCategory,
2259 onChange: (e) => setSelectedCategory(
2260 e.target.value
2261 ),
2262 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",
2263 children: [
2264 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "all", children: __("All Documents", "yatra") }),
2265 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "itinerary", children: __("Itineraries", "yatra") }),
2266 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "voucher", children: __("Vouchers", "yatra") }),
2267 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "invoice", children: __("Invoices", "yatra") }),
2268 /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "downloads", children: __("Downloads", "yatra") })
2269 ]
2270 }
2271 ) })
2272 ] })
2273 ] }) }),
2274 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-documents-stats flex flex-nowrap gap-6 overflow-x-auto", children: [
2275 /* @__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: [
2276 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Itinerary", "yatra") }),
2277 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-yatra-primary dark:text-yatra-on-dark", children: documentsByCategory.itinerary.length })
2278 ] }) }),
2279 /* @__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: [
2280 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Voucher", "yatra") }),
2281 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-emerald-600 dark:text-emerald-400", children: documentsByCategory.voucher.length })
2282 ] }) }),
2283 /* @__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: [
2284 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Invoice", "yatra") }),
2285 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-purple-600 dark:text-purple-400", children: documentsByCategory.invoice.length })
2286 ] }) }),
2287 /* @__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: [
2288 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: __("Downloads", "yatra") }),
2289 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xl font-bold text-amber-600 dark:text-amber-400", children: documentsByCategory.downloads.length })
2290 ] }) })
2291 ] }),
2292 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: [
2293 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 bg-gray-200 dark:bg-gray-700 rounded-full mx-auto mb-4" }),
2294 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 font-medium mb-1", children: __("No documents found", "yatra") }),
2295 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-400 dark:text-gray-500", children: __(
2296 "No documents are available yet. Please check back later.",
2297 "yatra"
2298 ) })
2299 ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: filteredDocuments.map((doc) => /* @__PURE__ */ jsxRuntimeExports.jsx(
2300 "div",
2301 {
2302 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",
2303 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: [
2304 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between gap-4 mb-2", children: [
2305 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
2306 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-1", children: doc.trip_title }),
2307 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-base font-bold text-gray-900 dark:text-white mb-1 truncate", children: doc.name }),
2308 /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: [
2309 __("Updated", "yatra"),
2310 ": ",
2311 formatDate(doc.updated_at)
2312 ] }),
2313 doc.category === "downloads" && /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 dark:text-gray-400 mt-2", children: [
2314 __("Access", "yatra"),
2315 ":",
2316 " ",
2317 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700 dark:text-gray-300", children: doc.access_label || doc.access || "-" }),
2318 doc.locked && doc.locked_reason ? /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "ml-2 text-amber-700 dark:text-amber-300", children: [
2319 "(",
2320 doc.locked_reason,
2321 ")"
2322 ] }) : null
2323 ] })
2324 ] }),
2325 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 flex-shrink-0", children: [
2326 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 }),
2327 /* @__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) })
2328 ] })
2329 ] }),
2330 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-document-actions flex flex-wrap gap-3 mt-4", children: [
2331 doc.locked || !doc.url ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2332 "div",
2333 {
2334 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",
2335 title: doc.locked_reason || __("Not available", "yatra"),
2336 children: __("Not Available", "yatra")
2337 }
2338 ) : /* @__PURE__ */ jsxRuntimeExports.jsx(
2339 "button",
2340 {
2341 type: "button",
2342 onClick: async () => {
2343 try {
2344 await downloadDocument({
2345 bookingId: doc.booking_id,
2346 paymentId: doc.payment_id,
2347 documentType: doc.category,
2348 fallbackUrl: doc.url
2349 });
2350 } catch (err) {
2351 alert(
2352 err instanceof Error ? err.message : __("Download failed.", "yatra")
2353 );
2354 }
2355 },
2356 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",
2357 children: __("Download", "yatra")
2358 }
2359 ),
2360 doc.url ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2361 "button",
2362 {
2363 type: "button",
2364 onClick: async () => {
2365 try {
2366 await previewTravelDocument(doc);
2367 } catch (err) {
2368 alert(
2369 err instanceof Error ? err.message : __("Preview failed.", "yatra")
2370 );
2371 }
2372 },
2373 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",
2374 children: __("Preview", "yatra")
2375 }
2376 ) : /* @__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") })
2377 ] })
2378 ] }) }) })
2379 },
2380 doc.id
2381 )) })
2382 ] });
2383 };
2384 const Profile = ({
2385 profile,
2386 savedTrips,
2387 wishlistEnabled = false
2388 }) => {
2389 const [isEditing, setIsEditing] = reactExports.useState(false);
2390 const [formData, setFormData] = reactExports.useState({
2391 name: "",
2392 email: "",
2393 phone: "",
2394 address: "",
2395 city: "",
2396 country: ""
2397 });
2398 const [isChangingPassword, setIsChangingPassword] = reactExports.useState(false);
2399 const [passwordData, setPasswordData] = reactExports.useState({
2400 currentPassword: "",
2401 newPassword: "",
2402 confirmPassword: ""
2403 });
2404 reactExports.useEffect(() => {
2405 if (profile && !isEditing) {
2406 setFormData({
2407 name: profile.name || "",
2408 email: profile.email || "",
2409 phone: profile.phone || "",
2410 address: profile.address || "",
2411 city: profile.city || "",
2412 country: profile.country || ""
2413 });
2414 }
2415 }, [profile, isEditing]);
2416 const handleInputChange = (field, value) => {
2417 setFormData((prev) => ({ ...prev, [field]: value }));
2418 };
2419 const handleSave = () => {
2420 setIsEditing(false);
2421 };
2422 const handleCancel = () => {
2423 setIsEditing(false);
2424 if (profile) {
2425 setFormData({
2426 name: profile.name || "",
2427 email: profile.email || "",
2428 phone: profile.phone || "",
2429 address: profile.address || "",
2430 city: profile.city || "",
2431 country: profile.country || ""
2432 });
2433 }
2434 };
2435 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-page space-y-6", children: [
2436 /* @__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: [
2437 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2438 /* @__PURE__ */ jsxRuntimeExports.jsxs("h2", { className: "text-lg font-bold text-gray-900 dark:text-white flex items-center gap-3", children: [
2439 /* @__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" }) }),
2440 __("Profile", "yatra")
2441 ] }),
2442 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-2", children: __(
2443 "Update your contact details, address, and communication preferences.",
2444 "yatra"
2445 ) })
2446 ] }),
2447 !isEditing && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2448 "div",
2449 {
2450 role: "button",
2451 tabIndex: 0,
2452 onClick: () => setIsEditing(true),
2453 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",
2454 children: [
2455 /* @__PURE__ */ jsxRuntimeExports.jsx(PenSquare, { className: "w-4 h-4" }),
2456 " ",
2457 __("Edit Profile", "yatra")
2458 ]
2459 }
2460 )
2461 ] }) }),
2462 /* @__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: [
2463 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2464 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2465 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2466 __("Full Name", "yatra"),
2467 " ",
2468 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2469 ] }),
2470 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2471 "input",
2472 {
2473 type: "text",
2474 value: formData.name,
2475 onChange: (e) => handleInputChange("name", e.target.value),
2476 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",
2477 placeholder: __("Enter your full name", "yatra")
2478 }
2479 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.name || __("Not set", "yatra") })
2480 ] }),
2481 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2482 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2483 __("Email Address", "yatra"),
2484 " ",
2485 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2486 ] }),
2487 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2488 "input",
2489 {
2490 type: "email",
2491 value: formData.email,
2492 onChange: (e) => handleInputChange("email", e.target.value),
2493 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",
2494 placeholder: __("Enter your email address", "yatra")
2495 }
2496 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.email || __("Not set", "yatra") })
2497 ] }),
2498 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2499 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("Phone Number", "yatra") }),
2500 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2501 "input",
2502 {
2503 type: "tel",
2504 value: formData.phone,
2505 onChange: (e) => handleInputChange("phone", e.target.value),
2506 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",
2507 placeholder: __("Enter your phone number", "yatra")
2508 }
2509 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.phone || __("Not set", "yatra") })
2510 ] }),
2511 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2512 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("City", "yatra") }),
2513 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2514 "input",
2515 {
2516 type: "text",
2517 value: formData.city,
2518 onChange: (e) => handleInputChange("city", e.target.value),
2519 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",
2520 placeholder: __("Enter your city", "yatra")
2521 }
2522 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.city || __("Not set", "yatra") })
2523 ] }),
2524 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field md:col-span-2", children: [
2525 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("Address", "yatra") }),
2526 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2527 "textarea",
2528 {
2529 value: formData.address,
2530 onChange: (e) => handleInputChange("address", e.target.value),
2531 rows: 3,
2532 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",
2533 placeholder: __("Enter your address", "yatra")
2534 }
2535 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.address || __("Not set", "yatra") })
2536 ] }),
2537 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-profile-field", children: [
2538 /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: __("Country", "yatra") }),
2539 isEditing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2540 "input",
2541 {
2542 type: "text",
2543 value: formData.country,
2544 onChange: (e) => handleInputChange("country", e.target.value),
2545 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",
2546 placeholder: __("Enter your country", "yatra")
2547 }
2548 ) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white py-2", children: formData.country || __("Not set", "yatra") })
2549 ] })
2550 ] }),
2551 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: [
2552 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2553 "button",
2554 {
2555 type: "button",
2556 onClick: handleSave,
2557 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",
2558 children: [
2559 /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle, { className: "w-4 h-4" }),
2560 __("Save Changes", "yatra")
2561 ]
2562 }
2563 ),
2564 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2565 "div",
2566 {
2567 role: "button",
2568 tabIndex: 0,
2569 onClick: handleCancel,
2570 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",
2571 children: [
2572 /* @__PURE__ */ jsxRuntimeExports.jsx(XCircle, { className: "w-4 h-4" }),
2573 __("Cancel", "yatra")
2574 ]
2575 }
2576 )
2577 ] })
2578 ] }) }),
2579 /* @__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: [
2580 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-6", children: [
2581 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2582 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-base font-semibold text-gray-900 dark:text-white flex items-center gap-2", children: [
2583 /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldCheck, { className: "w-5 h-5 text-yatra-primary dark:text-yatra-on-dark" }),
2584 __("Change Password", "yatra")
2585 ] }),
2586 /* @__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") })
2587 ] }),
2588 !isChangingPassword && /* @__PURE__ */ jsxRuntimeExports.jsxs(
2589 "div",
2590 {
2591 role: "button",
2592 tabIndex: 0,
2593 onClick: () => setIsChangingPassword(true),
2594 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",
2595 children: [
2596 /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4" }),
2597 __("Change Password", "yatra")
2598 ]
2599 }
2600 )
2601 ] }),
2602 isChangingPassword && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
2603 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-password-field", children: [
2604 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2605 __("Current Password", "yatra"),
2606 " ",
2607 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2608 ] }),
2609 /* @__PURE__ */ jsxRuntimeExports.jsx(
2610 "input",
2611 {
2612 type: "password",
2613 value: passwordData.currentPassword,
2614 onChange: (e) => setPasswordData((prev) => ({
2615 ...prev,
2616 currentPassword: e.target.value
2617 })),
2618 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",
2619 placeholder: __("Enter your current password", "yatra")
2620 }
2621 )
2622 ] }),
2623 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-password-field", children: [
2624 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2625 __("New Password", "yatra"),
2626 " ",
2627 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2628 ] }),
2629 /* @__PURE__ */ jsxRuntimeExports.jsx(
2630 "input",
2631 {
2632 type: "password",
2633 value: passwordData.newPassword,
2634 onChange: (e) => setPasswordData((prev) => ({
2635 ...prev,
2636 newPassword: e.target.value
2637 })),
2638 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",
2639 placeholder: __("Enter new password", "yatra")
2640 }
2641 )
2642 ] }),
2643 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-password-field", children: [
2644 /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [
2645 __("Confirm New Password", "yatra"),
2646 " ",
2647 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" })
2648 ] }),
2649 /* @__PURE__ */ jsxRuntimeExports.jsx(
2650 "input",
2651 {
2652 type: "password",
2653 value: passwordData.confirmPassword,
2654 onChange: (e) => setPasswordData((prev) => ({
2655 ...prev,
2656 confirmPassword: e.target.value
2657 })),
2658 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",
2659 placeholder: __("Confirm your new password", "yatra")
2660 }
2661 ),
2662 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") })
2663 ] }),
2664 /* @__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: [
2665 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2666 "button",
2667 {
2668 type: "button",
2669 onClick: () => {
2670 if (passwordData.newPassword !== passwordData.confirmPassword) {
2671 return;
2672 }
2673 setIsChangingPassword(false);
2674 setPasswordData({
2675 currentPassword: "",
2676 newPassword: "",
2677 confirmPassword: ""
2678 });
2679 },
2680 disabled: !passwordData.currentPassword || !passwordData.newPassword || !passwordData.confirmPassword || passwordData.newPassword !== passwordData.confirmPassword,
2681 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",
2682 children: [
2683 /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle, { className: "w-4 h-4" }),
2684 __("Update Password", "yatra")
2685 ]
2686 }
2687 ),
2688 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2689 "div",
2690 {
2691 role: "button",
2692 tabIndex: 0,
2693 onClick: () => {
2694 setIsChangingPassword(false);
2695 setPasswordData({
2696 currentPassword: "",
2697 newPassword: "",
2698 confirmPassword: ""
2699 });
2700 },
2701 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",
2702 children: [
2703 /* @__PURE__ */ jsxRuntimeExports.jsx(XCircle, { className: "w-4 h-4" }),
2704 __("Cancel", "yatra")
2705 ]
2706 }
2707 )
2708 ] })
2709 ] })
2710 ] }),
2711 /* @__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: [
2712 /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-base font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2", children: [
2713 /* @__PURE__ */ jsxRuntimeExports.jsx(Heart, { className: "w-5 h-5 text-red-600 dark:text-red-400" }),
2714 __("Saved Trips", "yatra")
2715 ] }),
2716 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-saved-trips-list space-y-3", children: savedTrips.length > 0 ? savedTrips.map((trip) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
2717 "div",
2718 {
2719 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",
2720 children: [
2721 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
2722 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white truncate", children: trip.trip_title || trip.title }),
2723 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mt-1", children: formatDate(trip.next_departure) })
2724 ] }),
2725 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-right ml-4 flex-shrink-0", children: [
2726 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: __("From", "yatra") }),
2727 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: currency(trip.price_from || trip.price || 0) })
2728 ] })
2729 ]
2730 },
2731 trip.id || trip.trip_id
2732 )) : /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 text-center py-4", children: __("No saved trips yet", "yatra") }) })
2733 ] }) })
2734 ] });
2735 };
2736 const SavedTrips = ({ savedTrips, isLoading }) => {
2737 const { showToast } = useToast();
2738 const handleRemoveTrip = async (tripId) => {
2739 try {
2740 await apiClient.delete(`/saved-trips/${tripId}`);
2741 window.location.reload();
2742 } catch (error) {
2743 console.error("Error removing trip:", error);
2744 showToast(__("Failed to remove trip from wishlist.", "yatra"), "error");
2745 }
2746 };
2747 return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
2748 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2749 /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white", children: __("Saved Trips", "yatra") }),
2750 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400 mt-1", children: __("Your wishlist of favorite trips", "yatra") })
2751 ] }) }),
2752 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: [
2753 /* @__PURE__ */ jsxRuntimeExports.jsx(
2754 "div",
2755 {
2756 className: "yatra-trip-image",
2757 style: { backgroundColor: "#f3f4f6", minHeight: "200px" },
2758 children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-pulse bg-gray-200 dark:bg-gray-700 w-full h-full" })
2759 }
2760 ),
2761 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-trip-content p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse space-y-3", children: [
2762 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-3/4" }),
2763 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-1/2" }),
2764 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-2/3" })
2765 ] }) })
2766 ] }, i)) }) : savedTrips.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center py-12", children: [
2767 /* @__PURE__ */ jsxRuntimeExports.jsx(Heart, { className: "w-16 h-16 text-gray-300 dark:text-gray-600 mx-auto mb-4" }),
2768 /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-2", children: __("No saved trips yet", "yatra") }),
2769 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500 dark:text-gray-400 mb-6", children: __(
2770 "Start exploring and save your favorite trips to your wishlist!",
2771 "yatra"
2772 ) }),
2773 /* @__PURE__ */ jsxRuntimeExports.jsxs(
2774 "a",
2775 {
2776 href: "/trip/",
2777 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",
2778 children: [
2779 /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "w-4 h-4" }),
2780 __("Browse Trips", "yatra")
2781 ]
2782 }
2783 )
2784 ] }) : /* @__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) => {
2785 var _a, _b;
2786 const tripUrl = trip.permalink || `/trip/${trip.trip_slug || trip.trip_id}`;
2787 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 : "");
2788 const imageUrl = trip.trip_image || `${siteBase}/wp-content/plugins/yatra/assets/images/trip-placeholder.svg`;
2789 const hasDiscount = trip.discount_percent && trip.discount_percent > 0;
2790 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;
2791 const originalPrice = trip.original_price;
2792 const avgRating = trip.rating !== void 0 && trip.rating !== null ? trip.rating : trip.average_rating !== void 0 && trip.average_rating !== null ? trip.average_rating : 0;
2793 const reviewCount = trip.reviews !== void 0 && trip.reviews !== null ? trip.reviews : trip.review_count || trip.reviews_count || 0;
2794 return /* @__PURE__ */ jsxRuntimeExports.jsxs(
2795 "div",
2796 {
2797 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",
2798 "data-price": displayPrice,
2799 "data-rating": avgRating,
2800 "data-duration": trip.duration_days || 0,
2801 children: [
2802 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-image", children: [
2803 /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: imageUrl, alt: trip.trip_title }),
2804 hasDiscount && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-discount-badge", children: [
2805 trip.discount_percent,
2806 "% ",
2807 __("OFF", "yatra")
2808 ] }),
2809 /* @__PURE__ */ jsxRuntimeExports.jsx(
2810 "button",
2811 {
2812 className: "yatra-favorite-btn saved is-saved",
2813 title: __("Remove from favorites", "yatra"),
2814 onClick: () => handleRemoveTrip(trip.trip_id),
2815 style: { color: "#ef4444" },
2816 children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2817 "svg",
2818 {
2819 width: "20",
2820 height: "20",
2821 fill: "currentColor",
2822 stroke: "currentColor",
2823 viewBox: "0 0 24 24",
2824 children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2825 "path",
2826 {
2827 strokeLinecap: "round",
2828 strokeLinejoin: "round",
2829 strokeWidth: "2",
2830 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"
2831 }
2832 )
2833 }
2834 )
2835 }
2836 )
2837 ] }),
2838 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-content flex flex-1 flex-col p-4", children: [
2839 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-meta", children: [
2840 trip.location && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2841 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-location", children: trip.location }),
2842 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-separator", children: "•" })
2843 ] }),
2844 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-duration", children: trip.duration || __("Flexible", "yatra") }),
2845 trip.difficulty && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
2846 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-separator", children: "•" }),
2847 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-trip-difficulty", children: trip.difficulty })
2848 ] })
2849 ] }),
2850 /* @__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(
2851 "a",
2852 {
2853 href: tripUrl,
2854 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",
2855 children: trip.trip_title
2856 }
2857 ) }),
2858 trip.highlights && trip.highlights.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-trip-highlights", children: trip.highlights.map((highlight, idx) => {
2859 const highlightText = typeof highlight === "string" ? highlight : highlight.text || highlight;
2860 const highlightLink = typeof highlight === "object" && highlight.link ? highlight.link : null;
2861 if (highlightLink) {
2862 return /* @__PURE__ */ jsxRuntimeExports.jsx(
2863 "a",
2864 {
2865 href: highlightLink,
2866 className: "yatra-highlight-badge yatra-highlight-link",
2867 children: highlightText
2868 },
2869 idx
2870 );
2871 }
2872 return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-highlight-badge", children: highlightText }, idx);
2873 }) }),
2874 reviewCount > 0 && avgRating > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-rating", children: [
2875 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-rating-stars", children: [
2876 /* @__PURE__ */ jsxRuntimeExports.jsx(
2877 "svg",
2878 {
2879 width: "16",
2880 height: "16",
2881 fill: "#fbbf24",
2882 viewBox: "0 0 24 24",
2883 "aria-hidden": "true",
2884 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" })
2885 }
2886 ),
2887 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-rating-value", children: avgRating.toFixed(1) })
2888 ] }),
2889 /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "yatra-reviews-count", children: sprintf(
2890 // translators: %d: number of reviews for the trip
2891 _n(
2892 "(%d review)",
2893 "(%d reviews)",
2894 reviewCount
2895 ),
2896 reviewCount
2897 ) })
2898 ] }),
2899 /* @__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: [
2900 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "yatra-trip-price flex min-w-0 flex-col items-start gap-1 text-left", children: [
2901 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) }),
2902 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,
2903 /* @__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) }),
2904 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "yatra-price-note text-xs leading-tight text-gray-400 dark:text-gray-500", children: __("Per person", "yatra") })
2905 ] }),
2906 /* @__PURE__ */ jsxRuntimeExports.jsx(
2907 "a",
2908 {
2909 href: tripUrl,
2910 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",
2911 children: __("View Details", "yatra")
2912 }
2913 )
2914 ] })
2915 ] })
2916 ]
2917 },
2918 trip.id || trip.trip_id
2919 );
2920 }) })
2921 ] });
2922 };
2923 const navigation = [
2924 { id: "dashboard", label: __("Dashboard", "yatra"), icon: LayoutDashboard },
2925 { id: "bookings", label: __("Bookings", "yatra"), icon: Calendar },
2926 { id: "payments", label: __("Payments", "yatra"), icon: CreditCard },
2927 { id: "documents", label: __("Documents", "yatra"), icon: FileText },
2928 { id: "saved-trips", label: __("Saved Trips", "yatra"), icon: Heart },
2929 { id: "profile", label: __("Profile", "yatra"), icon: User }
2930 ];
2931 const AccountPage = () => {
2932 var _a;
2933 const accountShell = reactExports.useMemo(() => getYatraAccountPageGlobals(), []);
2934 const accountNavigation = React.useMemo(() => {
2935 var _a2;
2936 const wl = typeof window !== "undefined" && !!((_a2 = window.yatraAccountPage) == null ? void 0 : _a2.wishlistEnabled);
2937 return navigation.filter((n) => n.id !== "saved-trips" || wl);
2938 }, []);
2939 const [urlKey, setUrlKey] = reactExports.useState(0);
2940 React.useEffect(() => {
2941 const handleLocationChange = () => {
2942 setUrlKey((prev) => prev + 1);
2943 };
2944 window.addEventListener("popstate", handleLocationChange);
2945 const interval = setInterval(() => {
2946 const currentSearch = window.location.search;
2947 if (currentSearch !== window.__lastAccountSearch) {
2948 window.__lastAccountSearch = currentSearch;
2949 handleLocationChange();
2950 }
2951 }, 100);
2952 return () => {
2953 window.removeEventListener("popstate", handleLocationChange);
2954 clearInterval(interval);
2955 };
2956 }, []);
2957 const getSectionFromUrl = () => {
2958 var _a2, _b;
2959 if (typeof window !== "undefined") {
2960 const wl = !!((_a2 = window.yatraAccountPage) == null ? void 0 : _a2.wishlistEnabled);
2961 const params = new URLSearchParams(window.location.search);
2962 const tab = params.get("tab");
2963 if (tab === "saved-trips" && !wl) {
2964 return "dashboard";
2965 }
2966 if (tab && [
2967 "dashboard",
2968 "bookings",
2969 "payments",
2970 "documents",
2971 "profile",
2972 "saved-trips"
2973 ].includes(tab)) {
2974 return tab;
2975 }
2976 const saved = localStorage.getItem("yatra-account-active-section");
2977 const wlSaved = !!((_b = window.yatraAccountPage) == null ? void 0 : _b.wishlistEnabled);
2978 if (saved === "saved-trips" && !wlSaved) {
2979 return "dashboard";
2980 }
2981 if (saved && [
2982 "dashboard",
2983 "bookings",
2984 "payments",
2985 "documents",
2986 "profile",
2987 "saved-trips"
2988 ].includes(saved)) {
2989 return saved;
2990 }
2991 }
2992 return "dashboard";
2993 };
2994 const [section, setSection] = reactExports.useState(getSectionFromUrl);
2995 const [pendingBookingId, setPendingBookingId] = reactExports.useState(null);
2996 React.useEffect(() => {
2997 const newSection = getSectionFromUrl();
2998 setSection(newSection);
2999 }, [urlKey]);
3000 const handleSectionChange = (newSection) => {
3001 setSection(newSection);
3002 if (typeof window !== "undefined") {
3003 const urlParams = new URLSearchParams(window.location.search);
3004 urlParams.set("tab", newSection);
3005 const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
3006 window.history.pushState({}, "", newUrl);
3007 localStorage.setItem("yatra-account-active-section", newSection);
3008 window.dispatchEvent(new PopStateEvent("popstate"));
3009 }
3010 };
3011 const handleBookingOpen = (bookingId) => {
3012 setPendingBookingId(bookingId);
3013 handleSectionChange("bookings");
3014 };
3015 const unwrapArrayResponse = (response) => {
3016 if (!response) return [];
3017 if (typeof response === "object" && response.success === true && Array.isArray(response.data)) {
3018 return response.data;
3019 }
3020 if (typeof response === "object" && response.data && typeof response.data === "object") {
3021 const inner = response.data;
3022 if (inner.success === true && Array.isArray(inner.data)) {
3023 return inner.data;
3024 }
3025 if (Array.isArray(inner)) {
3026 return inner;
3027 }
3028 }
3029 if (Array.isArray(response)) {
3030 return response;
3031 }
3032 if (typeof response === "object" && Array.isArray(response.data)) {
3033 return response.data;
3034 }
3035 return [];
3036 };
3037 const { data: profile, isLoading: isLoadingProfile } = useQuery({
3038 queryKey: ["account-profile"],
3039 queryFn: async () => {
3040 try {
3041 const response = await apiClient.get(API_ENDPOINTS.CUSTOMER_ME);
3042 const raw = response && typeof response === "object" && "data" in response && response.data && typeof response.data === "object" ? response.data : response;
3043 if (!raw || typeof raw !== "object" || !("id" in raw) && !("user_id" in raw) && !("email" in raw)) {
3044 return null;
3045 }
3046 const row = raw;
3047 const fromParts = [row.first_name, row.last_name].filter(Boolean).join(" ").trim();
3048 const name = typeof row.name === "string" && row.name.trim() || fromParts || (typeof row.email === "string" ? row.email.split("@")[0] || "" : "") || "";
3049 return {
3050 ...row,
3051 name,
3052 registered_at: row.registered_at || row.created_at || ""
3053 };
3054 } catch (error) {
3055 console.error("Error fetching profile:", error);
3056 return null;
3057 }
3058 },
3059 refetchOnMount: "always"
3060 });
3061 const displayProfile = profile;
3062 const { data: bookings = [] } = useQuery({
3063 queryKey: ["account-bookings"],
3064 queryFn: async () => {
3065 try {
3066 const response = await apiClient.get(
3067 API_ENDPOINTS.CUSTOMER_MY_BOOKINGS
3068 );
3069 return unwrapArrayResponse(response);
3070 } catch (error) {
3071 console.error("Error fetching bookings:", error);
3072 return [];
3073 }
3074 },
3075 refetchOnMount: "always"
3076 });
3077 const { data: payments = [] } = useQuery({
3078 queryKey: ["account-payments"],
3079 queryFn: async () => {
3080 try {
3081 const response = await apiClient.get(
3082 API_ENDPOINTS.CUSTOMER_MY_PAYMENTS
3083 );
3084 return unwrapArrayResponse(response);
3085 } catch (error) {
3086 console.error("Error fetching payments:", error);
3087 return [];
3088 }
3089 },
3090 refetchOnMount: "always"
3091 });
3092 const { data: documents = [] } = useQuery({
3093 queryKey: ["account-documents"],
3094 queryFn: async () => {
3095 try {
3096 const response = await apiClient.get(
3097 API_ENDPOINTS.CUSTOMER_MY_DOCUMENTS
3098 );
3099 return unwrapArrayResponse(response);
3100 } catch (error) {
3101 console.error("Error fetching documents:", error);
3102 return [];
3103 }
3104 },
3105 refetchOnMount: "always"
3106 });
3107 const notifications = [];
3108 const wishlistEnabled = typeof window !== "undefined" && !!((_a = window.yatraAccountPage) == null ? void 0 : _a.wishlistEnabled);
3109 const { data: savedTripsData, isLoading: isLoadingSavedTrips } = useQuery({
3110 queryKey: ["account-saved-trips"],
3111 enabled: wishlistEnabled,
3112 queryFn: async () => {
3113 try {
3114 const response = await apiClient.get(API_ENDPOINTS.SAVED_TRIPS);
3115 let trips = [];
3116 if (response && typeof response === "object") {
3117 if (response.data && typeof response.data === "object") {
3118 if (response.data.success === true && Array.isArray(response.data.data)) {
3119 trips = response.data.data;
3120 } else if (Array.isArray(response.data.data)) {
3121 trips = response.data.data;
3122 } else if (Array.isArray(response.data)) {
3123 trips = response.data;
3124 }
3125 } else if (response.success === true && Array.isArray(response.data)) {
3126 trips = response.data;
3127 } else if (Array.isArray(response.data)) {
3128 trips = response.data;
3129 } else if (Array.isArray(response)) {
3130 trips = response;
3131 }
3132 }
3133 if (trips.length > 0) {
3134 }
3135 return trips;
3136 } catch (error) {
3137 console.error("Error fetching saved trips:", error);
3138 return [];
3139 }
3140 }
3141 });
3142 const savedTrips = Array.isArray(savedTripsData) ? savedTripsData : [];
3143 const stats = reactExports.useMemo(() => {
3144 const outstanding = payments.filter((p) => p.status === "pending").reduce((sum, payment) => sum + payment.amount, 0);
3145 const upcoming = bookings.filter(
3146 (b) => new Date(b.travel_date) > /* @__PURE__ */ new Date()
3147 ).length;
3148 const totalSpent = (displayProfile == null ? void 0 : displayProfile.total_spent) ?? 0;
3149 const totalBookings = bookings.length;
3150 return [
3151 {
3152 label: __("Total Bookings", "yatra"),
3153 value: (displayProfile == null ? void 0 : displayProfile.total_bookings) ?? totalBookings,
3154 icon: Package,
3155 badge: (displayProfile == null ? void 0 : displayProfile.loyalty_tier) || ""
3156 },
3157 {
3158 label: __("Upcoming Trips", "yatra"),
3159 value: upcoming,
3160 icon: Calendar
3161 },
3162 {
3163 label: __("Outstanding Balance", "yatra"),
3164 value: currency(outstanding),
3165 icon: DollarSign
3166 },
3167 {
3168 label: __("Total Spent", "yatra"),
3169 value: currency(totalSpent),
3170 icon: ShieldCheck
3171 }
3172 ];
3173 }, [bookings, payments, displayProfile]);
3174 const renderSection = () => {
3175 switch (section) {
3176 case "dashboard":
3177 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3178 Dashboard,
3179 {
3180 bookings,
3181 payments,
3182 displayProfile: displayProfile || null,
3183 stats,
3184 notifications,
3185 conciergePhone: accountShell.companyPhone,
3186 conciergeEmail: accountShell.companyEmail,
3187 onSectionChange: (section2) => handleSectionChange(section2),
3188 onBookingOpen: handleBookingOpen
3189 }
3190 );
3191 case "bookings":
3192 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3193 Bookings,
3194 {
3195 bookings,
3196 conciergePhone: accountShell.companyPhone,
3197 conciergeEmail: accountShell.companyEmail,
3198 onSectionChange: (section2) => handleSectionChange(section2),
3199 initialBookingId: pendingBookingId,
3200 onBookingIdConsumed: () => setPendingBookingId(null)
3201 }
3202 );
3203 case "payments":
3204 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3205 Payments,
3206 {
3207 payments,
3208 onSectionChange: (section2) => handleSectionChange(section2)
3209 }
3210 );
3211 case "documents":
3212 return /* @__PURE__ */ jsxRuntimeExports.jsx(Documents, { documents });
3213 case "saved-trips":
3214 if (!wishlistEnabled) {
3215 return null;
3216 }
3217 return /* @__PURE__ */ jsxRuntimeExports.jsx(SavedTrips, { savedTrips, isLoading: isLoadingSavedTrips });
3218 case "profile":
3219 return /* @__PURE__ */ jsxRuntimeExports.jsx(
3220 Profile,
3221 {
3222 profile: displayProfile || null,
3223 savedTrips,
3224 wishlistEnabled
3225 }
3226 );
3227 default:
3228 return null;
3229 }
3230 };
3231 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: [
3232 /* @__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: [
3233 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
3234 /* @__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) : "" }),
3235 /* @__PURE__ */ jsxRuntimeExports.jsxs("h1", { className: "text-xl font-bold text-gray-900 dark:text-white", children: [
3236 __("Hello,", "yatra"),
3237 " ",
3238 (displayProfile == null ? void 0 : displayProfile.name) || __("Guest", "yatra")
3239 ] }),
3240 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: __(
3241 "Manage bookings, payments, and documents – everything for your adventures in one place.",
3242 "yatra"
3243 ) })
3244 ] }),
3245 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-wrap gap-3", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
3246 "div",
3247 {
3248 role: "button",
3249 tabIndex: 0,
3250 onClick: () => {
3251 const url = accountShell.logoutUrl;
3252 if (url) {
3253 window.location.href = url;
3254 }
3255 },
3256 onKeyDown: (e) => {
3257 if (e.key === "Enter" || e.key === " ") {
3258 e.preventDefault();
3259 const url = accountShell.logoutUrl;
3260 if (url) {
3261 window.location.href = url;
3262 }
3263 }
3264 },
3265 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",
3266 children: [
3267 /* @__PURE__ */ jsxRuntimeExports.jsx(LogOut, { className: "w-4 h-4" }),
3268 " ",
3269 __("Logout", "yatra")
3270 ]
3271 }
3272 ) })
3273 ] }) }),
3274 /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col gap-6 lg:flex-row lg:items-start", children: [
3275 /* @__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: [
3276 /* @__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(
3277 "div",
3278 {
3279 role: "button",
3280 tabIndex: 0,
3281 onClick: () => handleSectionChange(item.id),
3282 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"}`,
3283 children: [
3284 /* @__PURE__ */ jsxRuntimeExports.jsx(item.icon, { className: "w-4 h-4" }),
3285 item.label
3286 ]
3287 },
3288 item.id
3289 )) }) }),
3290 /* @__PURE__ */ jsxRuntimeExports.jsxs(
3291 "div",
3292 {
3293 className: "rounded-xl p-6 text-white space-y-2 shadow-xl",
3294 style: {
3295 backgroundImage: "linear-gradient(to bottom right, var(--yatra-primary-dark, #2563eb), var(--yatra-primary-darker, #1e40af))"
3296 },
3297 children: [
3298 /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldCheck, { className: "w-6 h-6 text-white" }),
3299 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-white", children: __("Need help right away?", "yatra") }),
3300 /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "font-semibold text-lg text-white", children: accountShell.companyName || __("Concierge Desk", "yatra") }),
3301 accountShell.companyPhone ? /* @__PURE__ */ jsxRuntimeExports.jsx(
3302 "a",
3303 {
3304 href: phoneToTelHref(accountShell.companyPhone),
3305 className: "text-sm font-medium text-white hover:underline",
3306 children: accountShell.companyPhone
3307 }
3308 ) : accountShell.companyEmail ? /* @__PURE__ */ jsxRuntimeExports.jsx(
3309 "a",
3310 {
3311 href: `mailto:${encodeURIComponent(accountShell.companyEmail)}`,
3312 className: "text-sm font-medium text-white hover:underline break-all",
3313 children: accountShell.companyEmail
3314 }
3315 ) : null
3316 ]
3317 }
3318 )
3319 ] }),
3320 /* @__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: [
3321 /* @__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: [
3322 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-6 bg-gray-200 dark:bg-gray-700 rounded w-48 mb-2" }),
3323 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-96" })
3324 ] }) }),
3325 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex flex-nowrap gap-6 overflow-x-auto", children: [1, 2, 3, 4, 5].map((i) => /* @__PURE__ */ jsxRuntimeExports.jsx(
3326 "div",
3327 {
3328 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",
3329 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse", children: [
3330 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-20 mb-3" }),
3331 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-8 bg-gray-200 dark:bg-gray-700 rounded w-16" })
3332 ] })
3333 },
3334 i
3335 )) }),
3336 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: [1, 2, 3].map((i) => /* @__PURE__ */ jsxRuntimeExports.jsx(
3337 "div",
3338 {
3339 className: "bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-6",
3340 children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "animate-pulse", children: [
3341 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-5 bg-gray-200 dark:bg-gray-700 rounded w-64 mb-4" }),
3342 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-full mb-2" }),
3343 /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-3/4" })
3344 ] })
3345 },
3346 i
3347 )) })
3348 ] }) : renderSection() })
3349 ] })
3350 ] }) });
3351 };
3352 const queryClient = new QueryClient({
3353 defaultOptions: {
3354 queries: {
3355 refetchOnWindowFocus: false,
3356 retry: 1,
3357 staleTime: 5 * 60 * 1e3
3358 // 5 minutes
3359 }
3360 }
3361 });
3362 const rootElement = document.getElementById("yatra-account-page-root");
3363 if (rootElement) {
3364 try {
3365 const root = client.createRoot(rootElement);
3366 root.render(
3367 /* @__PURE__ */ jsxRuntimeExports.jsx(React.StrictMode, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ToastProvider, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(AccountPage, {}) }) }) })
3368 );
3369 } catch (error) {
3370 console.error("Error rendering account page:", error);
3371 const wrap = document.createElement("div");
3372 wrap.style.cssText = "padding: 40px; text-align: center;";
3373 const h2 = document.createElement("h2");
3374 h2.textContent = __("Error loading account page", "yatra");
3375 const p = document.createElement("p");
3376 p.textContent = __(
3377 "Please refresh the page or contact support if the problem continues.",
3378 "yatra"
3379 );
3380 wrap.appendChild(h2);
3381 wrap.appendChild(p);
3382 rootElement.replaceChildren(wrap);
3383 }
3384 }
3385 //# sourceMappingURL=account-page.js.map
3386