| 1 |
import { j as jsxRuntimeExports, v as useQueryClient, r as reactExports, u as useQuery, w as useMutation, aA as AlertCircle, D as ArrowLeft, s as MapPin, aE as CheckCircle2, E as Loader2, ax as Plus, ay as X, aW as Save } from "./react-vendor-CithbthY.js"; |
| 2 |
import { C as Card, f as CardHeader, d as CardContent, A as Alert, P as PageHeader, B as Button, g as CardTitle, h as CardDescription, D as DatePicker, T as TimePicker, H as HelpText, L as LocationPicker, S as Select, a8 as useNavigate } from "../../admin/dist/js/app.js"; |
| 3 |
import { u as useToast, _ as __, t as toDateValue, I as Input, s as sprintf, a as apiClient } from "./index-Dec_weLB.js"; |
| 4 |
const AvailabilityFormSkeleton = () => { |
| 5 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [ |
| 6 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-pulse", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-4", children: [ |
| 7 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 8 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-8 bg-gray-200 dark:bg-gray-700 rounded w-56 mb-2" }), |
| 9 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-80" }) |
| 10 |
] }), |
| 11 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded w-24" }) |
| 12 |
] }) }), |
| 13 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6 animate-pulse", children: [ |
| 14 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { children: [ |
| 15 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardHeader, { children: [ |
| 16 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-6 bg-gray-200 dark:bg-gray-700 rounded w-36 mb-2" }), |
| 17 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-72" }) |
| 18 |
] }), |
| 19 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardContent, { className: "space-y-4", children: [ |
| 20 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [ |
| 21 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 22 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-32" }), |
| 23 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }) |
| 24 |
] }), |
| 25 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 26 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-28" }), |
| 27 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }) |
| 28 |
] }) |
| 29 |
] }), |
| 30 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [ |
| 31 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 32 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-28" }), |
| 33 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }), |
| 34 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-3 bg-gray-200 dark:bg-gray-700 rounded w-52" }) |
| 35 |
] }), |
| 36 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 37 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-24" }), |
| 38 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }), |
| 39 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-3 bg-gray-200 dark:bg-gray-700 rounded w-52" }) |
| 40 |
] }) |
| 41 |
] }) |
| 42 |
] }) |
| 43 |
] }), |
| 44 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { children: [ |
| 45 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardHeader, { children: [ |
| 46 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-6 bg-gray-200 dark:bg-gray-700 rounded w-44 mb-2" }), |
| 47 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-96" }) |
| 48 |
] }), |
| 49 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardContent, { className: "space-y-4", children: [ |
| 50 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 bg-gray-100 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [ |
| 51 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-9 w-9 bg-gray-200 dark:bg-gray-700 rounded-full" }), |
| 52 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [ |
| 53 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-36 mb-2" }), |
| 54 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-3 bg-gray-200 dark:bg-gray-700 rounded w-80" }) |
| 55 |
] }) |
| 56 |
] }) }), |
| 57 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [ |
| 58 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 59 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-28" }), |
| 60 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }) |
| 61 |
] }), |
| 62 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 63 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-40" }), |
| 64 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }) |
| 65 |
] }) |
| 66 |
] }), |
| 67 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-6 pt-6 border-t border-gray-200 dark:border-gray-700", children: [ |
| 68 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-5 bg-gray-200 dark:bg-gray-700 rounded w-44 mb-4" }), |
| 69 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-4", children: [ |
| 70 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 71 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-28" }), |
| 72 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }), |
| 73 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-3 bg-gray-200 dark:bg-gray-700 rounded w-56" }) |
| 74 |
] }), |
| 75 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 76 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-28" }), |
| 77 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }), |
| 78 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-3 bg-gray-200 dark:bg-gray-700 rounded w-44" }) |
| 79 |
] }), |
| 80 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 81 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-32" }), |
| 82 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }), |
| 83 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-3 bg-gray-200 dark:bg-gray-700 rounded w-64" }) |
| 84 |
] }) |
| 85 |
] }) |
| 86 |
] }), |
| 87 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-6 pt-6 border-t border-gray-200 dark:border-gray-700", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-4", children: [ |
| 88 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-5 bg-gray-200 dark:bg-gray-700 rounded w-24" }), |
| 89 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [ |
| 90 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 w-4 bg-gray-200 dark:bg-gray-700 rounded" }), |
| 91 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-44" }) |
| 92 |
] }) |
| 93 |
] }) }), |
| 94 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-4", children: [ |
| 95 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-4 bg-gray-200 dark:bg-gray-700 rounded w-14 mb-2" }), |
| 96 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded" }) |
| 97 |
] }) |
| 98 |
] }) |
| 99 |
] }), |
| 100 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-end gap-4", children: [ |
| 101 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded w-24" }), |
| 102 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-10 bg-gray-200 dark:bg-gray-700 rounded w-36" }) |
| 103 |
] }) |
| 104 |
] }) |
| 105 |
] }); |
| 106 |
}; |
| 107 |
function coordFromApi(v) { |
| 108 |
if (v == null || v === "") return ""; |
| 109 |
return String(v); |
| 110 |
} |
| 111 |
const AvailabilityForm = () => { |
| 112 |
var _a; |
| 113 |
const { navigate } = useNavigate(); |
| 114 |
const queryClient = useQueryClient(); |
| 115 |
const { showToast } = useToast(); |
| 116 |
const urlParams = new URLSearchParams(window.location.search); |
| 117 |
const tripIdFromUrl = urlParams.get("trip_id") ? parseInt(urlParams.get("trip_id")) : null; |
| 118 |
const availabilityId = urlParams.get("action") === "create" ? null : urlParams.get("id") || null; |
| 119 |
const isEditMode = !!availabilityId; |
| 120 |
const [tripId, setTripId] = reactExports.useState(tripIdFromUrl); |
| 121 |
const [formData, setFormData] = reactExports.useState({ |
| 122 |
departure_date: "", |
| 123 |
departure_time: "", |
| 124 |
arrival_date: "", |
| 125 |
arrival_time: "", |
| 126 |
total_seats: "", |
| 127 |
booked_seats: "0", |
| 128 |
seats_remaining: "", |
| 129 |
pricing_type: "regular", |
| 130 |
original_price: "", |
| 131 |
discounted_price: "", |
| 132 |
price_types: [], |
| 133 |
status: "available", |
| 134 |
is_blocked: false, |
| 135 |
block_reason: "", |
| 136 |
alert_threshold: "5", |
| 137 |
from_location: "", |
| 138 |
to_location: "", |
| 139 |
from_latitude: "", |
| 140 |
from_longitude: "", |
| 141 |
to_latitude: "", |
| 142 |
to_longitude: "" |
| 143 |
}); |
| 144 |
const [errors, setErrors] = reactExports.useState({}); |
| 145 |
const [showCategorySelector, setShowCategorySelector] = reactExports.useState(false); |
| 146 |
const { data: tripData } = useQuery({ |
| 147 |
queryKey: ["trip", tripId], |
| 148 |
queryFn: async () => { |
| 149 |
if (!tripId) return null; |
| 150 |
const response = await apiClient.get(`/trips/${tripId}`); |
| 151 |
const data = (response == null ? void 0 : response.data) || response; |
| 152 |
return data; |
| 153 |
}, |
| 154 |
enabled: !!tripId |
| 155 |
}); |
| 156 |
const isSingleDayTrip = (tripData == null ? void 0 : tripData.trip_type) === "single_day"; |
| 157 |
const hasTimeSlots = isSingleDayTrip && !!(tripData == null ? void 0 : tripData.has_default_time_slots); |
| 158 |
const tripMaxTravelers = (() => { |
| 159 |
const raw = Number((tripData == null ? void 0 : tripData.max_travelers) ?? 0); |
| 160 |
return Number.isFinite(raw) && raw > 0 ? raw : 0; |
| 161 |
})(); |
| 162 |
const { data: categoriesData, isLoading: isLoadingCategories } = useQuery({ |
| 163 |
queryKey: ["traveler-categories"], |
| 164 |
queryFn: async () => { |
| 165 |
const response = await apiClient.get("/traveler-categories"); |
| 166 |
const categories = (response == null ? void 0 : response.data) || response || []; |
| 167 |
return { |
| 168 |
categories: Array.isArray(categories) ? categories : [] |
| 169 |
}; |
| 170 |
} |
| 171 |
}); |
| 172 |
const activeCategories = ((_a = categoriesData == null ? void 0 : categoriesData.categories) == null ? void 0 : _a.filter( |
| 173 |
(cat) => cat.status === "active" || cat.status === "publish" |
| 174 |
)) || []; |
| 175 |
const { data: availabilityData, isLoading: isLoadingAvailability } = useQuery( |
| 176 |
{ |
| 177 |
queryKey: ["availability", availabilityId], |
| 178 |
queryFn: async () => { |
| 179 |
if (!availabilityId) return null; |
| 180 |
const response = await apiClient.get(`/availability/${availabilityId}`); |
| 181 |
return (response == null ? void 0 : response.data) || response; |
| 182 |
}, |
| 183 |
enabled: isEditMode && !!availabilityId |
| 184 |
} |
| 185 |
); |
| 186 |
reactExports.useEffect(() => { |
| 187 |
if (availabilityData && availabilityData.trip_id && !tripId) { |
| 188 |
setTripId(availabilityData.trip_id); |
| 189 |
} |
| 190 |
}, [availabilityData, tripId]); |
| 191 |
reactExports.useEffect(() => { |
| 192 |
if (tripData && !isEditMode) { |
| 193 |
const rawPriceTypes = tripData.price_types; |
| 194 |
const hasTravelerPricing = Array.isArray(rawPriceTypes) ? rawPriceTypes.length > 0 : false; |
| 195 |
const effectivePricingType = hasTravelerPricing ? "traveler_based" : tripData.pricing_type || "regular"; |
| 196 |
setFormData((prev) => ({ |
| 197 |
...prev, |
| 198 |
// Only seeds an untouched field — never overwrites a typed value if |
| 199 |
// the trip query refetches. |
| 200 |
total_seats: prev.total_seats || (tripMaxTravelers > 0 ? String(tripMaxTravelers) : prev.total_seats), |
| 201 |
from_location: tripData.starting_location || "", |
| 202 |
to_location: tripData.ending_location || "", |
| 203 |
from_latitude: coordFromApi(tripData.starting_latitude), |
| 204 |
from_longitude: coordFromApi(tripData.starting_longitude), |
| 205 |
to_latitude: coordFromApi(tripData.ending_latitude), |
| 206 |
to_longitude: coordFromApi(tripData.ending_longitude), |
| 207 |
// Default pricing type based on trip's pricing type |
| 208 |
pricing_type: effectivePricingType |
| 209 |
})); |
| 210 |
} |
| 211 |
}, [tripData, isEditMode, tripMaxTravelers]); |
| 212 |
reactExports.useEffect(() => { |
| 213 |
var _a2, _b, _c; |
| 214 |
if (availabilityData) { |
| 215 |
const totalSeats = availabilityData.total_seats || availabilityData.seats_total || 0; |
| 216 |
const availableSeats = availabilityData.available_seats || availabilityData.seats_available || 0; |
| 217 |
const bookedSeats = totalSeats - availableSeats; |
| 218 |
const rawTripPriceTypes = tripData == null ? void 0 : tripData.price_types; |
| 219 |
const tripHasTravelerPricing = Array.isArray(rawTripPriceTypes) ? rawTripPriceTypes.length > 0 : false; |
| 220 |
const pricingType = tripHasTravelerPricing ? "traveler_based" : (tripData == null ? void 0 : tripData.pricing_type) || availabilityData.pricing_type || "regular"; |
| 221 |
setFormData({ |
| 222 |
departure_date: availabilityData.departure_date || "", |
| 223 |
departure_time: availabilityData.departure_time || "", |
| 224 |
arrival_date: availabilityData.arrival_date || availabilityData.departure_date || "", |
| 225 |
arrival_time: availabilityData.arrival_time || "", |
| 226 |
total_seats: totalSeats.toString(), |
| 227 |
booked_seats: bookedSeats.toString(), |
| 228 |
seats_remaining: availableSeats > 10 ? "10+" : availableSeats.toString(), |
| 229 |
pricing_type: pricingType, |
| 230 |
original_price: ((_a2 = availabilityData.original_price) == null ? void 0 : _a2.toString()) || "", |
| 231 |
discounted_price: ((_b = availabilityData.discounted_price) == null ? void 0 : _b.toString()) || "", |
| 232 |
price_types: availabilityData.price_types || [], |
| 233 |
status: availabilityData.status || (availabilityData.is_blocked ? "blocked" : "available"), |
| 234 |
is_blocked: availabilityData.is_blocked || availabilityData.status === "blocked" || false, |
| 235 |
block_reason: availabilityData.block_reason || "", |
| 236 |
alert_threshold: ((_c = availabilityData.alert_threshold) == null ? void 0 : _c.toString()) || "5", |
| 237 |
from_location: availabilityData.from_location || (tripData == null ? void 0 : tripData.starting_location) || "", |
| 238 |
to_location: availabilityData.to_location || (tripData == null ? void 0 : tripData.ending_location) || "", |
| 239 |
from_latitude: coordFromApi(availabilityData.from_latitude) || coordFromApi(tripData == null ? void 0 : tripData.starting_latitude), |
| 240 |
from_longitude: coordFromApi(availabilityData.from_longitude) || coordFromApi(tripData == null ? void 0 : tripData.starting_longitude), |
| 241 |
to_latitude: coordFromApi(availabilityData.to_latitude) || coordFromApi(tripData == null ? void 0 : tripData.ending_latitude), |
| 242 |
to_longitude: coordFromApi(availabilityData.to_longitude) || coordFromApi(tripData == null ? void 0 : tripData.ending_longitude) |
| 243 |
}); |
| 244 |
} |
| 245 |
}, [availabilityData, tripData]); |
| 246 |
const handleFieldChange = (field, value) => { |
| 247 |
setFormData((prev) => ({ |
| 248 |
...prev, |
| 249 |
[field]: value |
| 250 |
})); |
| 251 |
if (errors[field]) { |
| 252 |
setErrors((prev) => { |
| 253 |
const newErrors = { ...prev }; |
| 254 |
delete newErrors[field]; |
| 255 |
return newErrors; |
| 256 |
}); |
| 257 |
} |
| 258 |
}; |
| 259 |
const handlePriceTypeAdd = (categoryId) => { |
| 260 |
if (formData.price_types.some((pt) => pt.category_id === categoryId)) { |
| 261 |
return; |
| 262 |
} |
| 263 |
const category = activeCategories.find((cat) => cat.id === categoryId); |
| 264 |
setFormData((prev) => ({ |
| 265 |
...prev, |
| 266 |
price_types: [ |
| 267 |
...prev.price_types, |
| 268 |
{ |
| 269 |
category_id: categoryId, |
| 270 |
category_label: (category == null ? void 0 : category.label) || "", |
| 271 |
original_price: "", |
| 272 |
discounted_price: "" |
| 273 |
} |
| 274 |
] |
| 275 |
})); |
| 276 |
}; |
| 277 |
const handlePriceTypeRemove = (categoryId) => { |
| 278 |
setFormData((prev) => ({ |
| 279 |
...prev, |
| 280 |
price_types: prev.price_types.filter( |
| 281 |
(pt) => pt.category_id !== categoryId |
| 282 |
) |
| 283 |
})); |
| 284 |
}; |
| 285 |
const handlePriceTypeChange = (categoryId, field, value) => { |
| 286 |
setFormData((prev) => ({ |
| 287 |
...prev, |
| 288 |
price_types: prev.price_types.map( |
| 289 |
(pt) => pt.category_id === categoryId ? { ...pt, [field]: value } : pt |
| 290 |
) |
| 291 |
})); |
| 292 |
}; |
| 293 |
const validateForm = () => { |
| 294 |
const newErrors = {}; |
| 295 |
if (!formData.departure_date) { |
| 296 |
newErrors.departure_date = __("Departure date is required", "yatra"); |
| 297 |
} |
| 298 |
if (!formData.arrival_date) { |
| 299 |
newErrors.arrival_date = __("Arrival date is required", "yatra"); |
| 300 |
} |
| 301 |
const isSingleDay = isSingleDayTrip; |
| 302 |
if (isSingleDay) { |
| 303 |
if (formData.departure_date && formData.arrival_date && formData.departure_date !== formData.arrival_date) { |
| 304 |
newErrors.arrival_date = __( |
| 305 |
"For single day trips, departure and arrival must be on the same date", |
| 306 |
"yatra" |
| 307 |
); |
| 308 |
} |
| 309 |
if (hasTimeSlots && !formData.departure_time) { |
| 310 |
newErrors.departure_time = __( |
| 311 |
"Departure time is required when the trip has multiple time slots", |
| 312 |
"yatra" |
| 313 |
); |
| 314 |
} |
| 315 |
if (formData.departure_time && formData.arrival_time && formData.departure_date === formData.arrival_date) { |
| 316 |
const [depHour, depMin] = formData.departure_time.split(":").map(Number); |
| 317 |
const [arrHour, arrMin] = formData.arrival_time.split(":").map(Number); |
| 318 |
const depMinutes = depHour * 60 + depMin; |
| 319 |
const arrMinutes = arrHour * 60 + arrMin; |
| 320 |
if (arrMinutes <= depMinutes) { |
| 321 |
newErrors.arrival_time = __( |
| 322 |
"Arrival time must be after departure time", |
| 323 |
"yatra" |
| 324 |
); |
| 325 |
} |
| 326 |
} |
| 327 |
} else { |
| 328 |
if (formData.departure_date && formData.arrival_date) { |
| 329 |
const departure = new Date(formData.departure_date); |
| 330 |
const arrival = new Date(formData.arrival_date); |
| 331 |
if (arrival <= departure) { |
| 332 |
newErrors.arrival_date = __( |
| 333 |
"Arrival date must be after departure date", |
| 334 |
"yatra" |
| 335 |
); |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
if (!formData.total_seats || parseInt(formData.total_seats) <= 0) { |
| 340 |
newErrors.total_seats = __( |
| 341 |
"Total capacity is required and must be greater than 0", |
| 342 |
"yatra" |
| 343 |
); |
| 344 |
} |
| 345 |
if (isEditMode && formData.booked_seats) { |
| 346 |
const total = parseInt(formData.total_seats) || 0; |
| 347 |
const booked = parseInt(formData.booked_seats) || 0; |
| 348 |
if (booked > total) { |
| 349 |
newErrors.booked_seats = __( |
| 350 |
"Booked seats cannot exceed total capacity", |
| 351 |
"yatra" |
| 352 |
); |
| 353 |
} |
| 354 |
} |
| 355 |
if (formData.pricing_type === "regular") { |
| 356 |
if (formData.original_price && parseFloat(formData.original_price) <= 0) { |
| 357 |
newErrors.original_price = __( |
| 358 |
"Original price must be greater than 0", |
| 359 |
"yatra" |
| 360 |
); |
| 361 |
} |
| 362 |
if (formData.discounted_price && formData.original_price && parseFloat(formData.discounted_price) >= parseFloat(formData.original_price)) { |
| 363 |
newErrors.discounted_price = __( |
| 364 |
"Discounted price must be less than original price", |
| 365 |
"yatra" |
| 366 |
); |
| 367 |
} |
| 368 |
} else { |
| 369 |
if (formData.price_types.length > 0) { |
| 370 |
formData.price_types.forEach((priceType, index) => { |
| 371 |
if (priceType.original_price && (isNaN(parseFloat(priceType.original_price)) || parseFloat(priceType.original_price) < 0)) { |
| 372 |
newErrors[`price_type_${index}_original`] = __( |
| 373 |
"Original price must be a valid number", |
| 374 |
"yatra" |
| 375 |
); |
| 376 |
} |
| 377 |
if (priceType.discounted_price && (isNaN(parseFloat(priceType.discounted_price)) || parseFloat(priceType.discounted_price) < 0)) { |
| 378 |
newErrors[`price_type_${index}_discounted`] = __( |
| 379 |
"Discounted price must be a valid number", |
| 380 |
"yatra" |
| 381 |
); |
| 382 |
} |
| 383 |
if (priceType.discounted_price && priceType.original_price && parseFloat(priceType.discounted_price) >= parseFloat(priceType.original_price)) { |
| 384 |
newErrors[`price_type_${index}_discounted`] = __( |
| 385 |
"Discounted price must be less than original price", |
| 386 |
"yatra" |
| 387 |
); |
| 388 |
} |
| 389 |
}); |
| 390 |
} |
| 391 |
} |
| 392 |
setErrors(newErrors); |
| 393 |
return Object.keys(newErrors).length === 0; |
| 394 |
}; |
| 395 |
const saveMutation = useMutation({ |
| 396 |
mutationFn: async (data) => { |
| 397 |
var _a2, _b, _c, _d; |
| 398 |
const totalSeats = data.total_seats ? parseInt(data.total_seats) : 0; |
| 399 |
const bookedSeats = isEditMode && data.booked_seats ? parseInt(data.booked_seats) : 0; |
| 400 |
const availableSeats = totalSeats - bookedSeats; |
| 401 |
const payload = { |
| 402 |
trip_id: tripId, |
| 403 |
departure_date: data.departure_date, |
| 404 |
departure_time: (tripData == null ? void 0 : tripData.trip_type) === "single_day" ? data.departure_time || null : null, |
| 405 |
arrival_date: data.arrival_date || null, |
| 406 |
arrival_time: (tripData == null ? void 0 : tripData.trip_type) === "single_day" ? data.arrival_time || null : null, |
| 407 |
seats_total: totalSeats, |
| 408 |
seats_available: availableSeats, |
| 409 |
seats_reserved: 0, |
| 410 |
seats_waitlist: 0, |
| 411 |
pricing_type: data.pricing_type, |
| 412 |
original_price: data.pricing_type === "regular" && data.original_price ? parseFloat(data.original_price) : null, |
| 413 |
discounted_price: data.pricing_type === "regular" && data.discounted_price ? parseFloat(data.discounted_price) : null, |
| 414 |
price_types: data.pricing_type === "traveler_based" ? data.price_types : null, |
| 415 |
status: data.is_blocked ? "blocked" : data.status, |
| 416 |
from_location: data.from_location || null, |
| 417 |
to_location: data.to_location || null, |
| 418 |
from_latitude: ((_a2 = data.from_latitude) == null ? void 0 : _a2.trim()) || null, |
| 419 |
from_longitude: ((_b = data.from_longitude) == null ? void 0 : _b.trim()) || null, |
| 420 |
to_latitude: ((_c = data.to_latitude) == null ? void 0 : _c.trim()) || null, |
| 421 |
to_longitude: ((_d = data.to_longitude) == null ? void 0 : _d.trim()) || null, |
| 422 |
special_notes: null, |
| 423 |
cutoff_hours: 24, |
| 424 |
alert_threshold: data.alert_threshold ? parseInt(data.alert_threshold) : null, |
| 425 |
is_blocked: data.is_blocked, |
| 426 |
block_reason: data.is_blocked ? data.block_reason || null : null |
| 427 |
}; |
| 428 |
if (isEditMode && availabilityId) { |
| 429 |
const response = await apiClient.put( |
| 430 |
`/availability/${availabilityId}`, |
| 431 |
payload |
| 432 |
); |
| 433 |
return (response == null ? void 0 : response.data) || response; |
| 434 |
} else { |
| 435 |
const response = await apiClient.post("/availability", payload); |
| 436 |
return (response == null ? void 0 : response.data) || response; |
| 437 |
} |
| 438 |
}, |
| 439 |
onSuccess: () => { |
| 440 |
queryClient.invalidateQueries({ queryKey: ["availability"] }); |
| 441 |
queryClient.invalidateQueries({ queryKey: ["trips"] }); |
| 442 |
navigate({ |
| 443 |
subpage: "trips", |
| 444 |
tab: "availability", |
| 445 |
trip_id: tripId == null ? void 0 : tripId.toString() |
| 446 |
}); |
| 447 |
setTimeout(() => { |
| 448 |
showToast( |
| 449 |
isEditMode ? __("Availability date updated successfully", "yatra") : __("Availability date created successfully", "yatra"), |
| 450 |
"success", |
| 451 |
3e3 |
| 452 |
// Shorter duration |
| 453 |
); |
| 454 |
}, 100); |
| 455 |
}, |
| 456 |
onError: (error) => { |
| 457 |
var _a2; |
| 458 |
const errorMessage = (error == null ? void 0 : error.message) || ((_a2 = error == null ? void 0 : error.data) == null ? void 0 : _a2.message) || __("An error occurred while saving", "yatra"); |
| 459 |
showToast(errorMessage, "error"); |
| 460 |
setErrors({ |
| 461 |
submit: errorMessage |
| 462 |
}); |
| 463 |
} |
| 464 |
}); |
| 465 |
const handleSubmit = (e) => { |
| 466 |
e.preventDefault(); |
| 467 |
if (!validateForm()) { |
| 468 |
return; |
| 469 |
} |
| 470 |
saveMutation.mutate(formData); |
| 471 |
}; |
| 472 |
const getCurrencySymbol = (currency) => { |
| 473 |
const symbols = { |
| 474 |
USD: "$", |
| 475 |
EUR: "€", |
| 476 |
GBP: "£", |
| 477 |
INR: "₹" |
| 478 |
}; |
| 479 |
return symbols[currency] || currency; |
| 480 |
}; |
| 481 |
if (isEditMode && !tripId && isLoadingAvailability) { |
| 482 |
return /* @__PURE__ */ jsxRuntimeExports.jsx(AvailabilityFormSkeleton, {}); |
| 483 |
} |
| 484 |
if (!tripId) { |
| 485 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs(Alert, { variant: "error", children: [ |
| 486 |
/* @__PURE__ */ jsxRuntimeExports.jsx(AlertCircle, { className: "w-4 h-4" }), |
| 487 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 488 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "font-medium", children: __("Trip ID Required", "yatra") }), |
| 489 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm", children: __("Please select a trip first.", "yatra") }) |
| 490 |
] }) |
| 491 |
] }); |
| 492 |
} |
| 493 |
if (isLoadingAvailability || isEditMode && !availabilityData) { |
| 494 |
return /* @__PURE__ */ jsxRuntimeExports.jsx(AvailabilityFormSkeleton, {}); |
| 495 |
} |
| 496 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [ |
| 497 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 498 |
PageHeader, |
| 499 |
{ |
| 500 |
title: isEditMode ? __("Edit Availability Date", "yatra") : __("Add Availability Date", "yatra"), |
| 501 |
description: tripData ? `${isEditMode ? __("Edit", "yatra") : __("Add")} availability date for ${tripData.title} (Trip ID: ${tripId})` : __("Add a new availability date for this trip", "yatra"), |
| 502 |
actions: tripId ? /* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 503 |
Button, |
| 504 |
{ |
| 505 |
variant: "outline", |
| 506 |
onClick: () => navigate({ |
| 507 |
subpage: "trips", |
| 508 |
tab: "availability", |
| 509 |
trip_id: tripId.toString() |
| 510 |
}), |
| 511 |
children: [ |
| 512 |
/* @__PURE__ */ jsxRuntimeExports.jsx(ArrowLeft, { className: "w-4 h-4 mr-2" }), |
| 513 |
__("Back", "yatra") |
| 514 |
] |
| 515 |
} |
| 516 |
) : null |
| 517 |
} |
| 518 |
), |
| 519 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: handleSubmit, className: "space-y-6", children: [ |
| 520 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { children: [ |
| 521 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardHeader, { children: [ |
| 522 |
/* @__PURE__ */ jsxRuntimeExports.jsx(CardTitle, { children: __("Date Information", "yatra") }), |
| 523 |
/* @__PURE__ */ jsxRuntimeExports.jsx(CardDescription, { children: __( |
| 524 |
"Set the departure and arrival dates for this availability", |
| 525 |
"yatra" |
| 526 |
) }) |
| 527 |
] }), |
| 528 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardContent, { className: "space-y-4", children: [ |
| 529 |
(tripData == null ? void 0 : tripData.trip_type) === "single_day" ? ( |
| 530 |
// Single Day Trip - Show date and time pickers |
| 531 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [ |
| 532 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 533 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 534 |
__("Date", "yatra"), |
| 535 |
" ", |
| 536 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" }) |
| 537 |
] }), |
| 538 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 539 |
DatePicker, |
| 540 |
{ |
| 541 |
value: formData.departure_date, |
| 542 |
onChange: (value) => { |
| 543 |
handleFieldChange("departure_date", value); |
| 544 |
handleFieldChange("arrival_date", value); |
| 545 |
}, |
| 546 |
placeholder: __("Select date", "yatra"), |
| 547 |
error: !!errors.departure_date |
| 548 |
} |
| 549 |
), |
| 550 |
errors.departure_date && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.departure_date }) |
| 551 |
] }), |
| 552 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [ |
| 553 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 554 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 555 |
__("Departure Time", "yatra"), |
| 556 |
" ", |
| 557 |
hasTimeSlots ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" }) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-400 font-normal", children: __("(optional)", "yatra") }) |
| 558 |
] }), |
| 559 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 560 |
TimePicker, |
| 561 |
{ |
| 562 |
value: formData.departure_time, |
| 563 |
onChange: (value) => handleFieldChange("departure_time", value), |
| 564 |
placeholder: __("Select departure time", "yatra"), |
| 565 |
error: !!errors.departure_time |
| 566 |
} |
| 567 |
), |
| 568 |
errors.departure_time && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.departure_time }) |
| 569 |
] }), |
| 570 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 571 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 572 |
__("Arrival Time", "yatra"), |
| 573 |
" ", |
| 574 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-400 font-normal", children: __("(optional)", "yatra") }) |
| 575 |
] }), |
| 576 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 577 |
TimePicker, |
| 578 |
{ |
| 579 |
value: formData.arrival_time, |
| 580 |
onChange: (value) => handleFieldChange("arrival_time", value), |
| 581 |
placeholder: __("Select arrival time", "yatra"), |
| 582 |
error: !!errors.arrival_time |
| 583 |
} |
| 584 |
), |
| 585 |
errors.arrival_time && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.arrival_time }) |
| 586 |
] }) |
| 587 |
] }) |
| 588 |
] }) |
| 589 |
) : ( |
| 590 |
// Multi-Day Trip - Show date pickers only |
| 591 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [ |
| 592 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 593 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 594 |
__("Departure Date", "yatra"), |
| 595 |
" ", |
| 596 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" }) |
| 597 |
] }), |
| 598 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 599 |
DatePicker, |
| 600 |
{ |
| 601 |
value: formData.departure_date, |
| 602 |
onChange: (value) => handleFieldChange("departure_date", value), |
| 603 |
placeholder: __("Select departure date", "yatra"), |
| 604 |
error: !!errors.departure_date |
| 605 |
} |
| 606 |
), |
| 607 |
errors.departure_date && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.departure_date }) |
| 608 |
] }), |
| 609 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 610 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 611 |
__("Arrival Date", "yatra"), |
| 612 |
" ", |
| 613 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" }) |
| 614 |
] }), |
| 615 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 616 |
DatePicker, |
| 617 |
{ |
| 618 |
value: formData.arrival_date, |
| 619 |
onChange: (value) => handleFieldChange("arrival_date", value), |
| 620 |
minDate: formData.departure_date ? toDateValue(formData.departure_date) : void 0, |
| 621 |
placeholder: __("Select arrival date", "yatra"), |
| 622 |
error: !!errors.arrival_date |
| 623 |
} |
| 624 |
), |
| 625 |
errors.arrival_date && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.arrival_date }), |
| 626 |
(tripData == null ? void 0 : tripData.duration_days) && formData.departure_date && formData.arrival_date && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-1.5", children: (() => { |
| 627 |
const departure = new Date(formData.departure_date); |
| 628 |
const arrival = new Date(formData.arrival_date); |
| 629 |
const selectedDays = Math.round( |
| 630 |
(arrival.getTime() - departure.getTime()) / (1e3 * 60 * 60 * 24) |
| 631 |
) + 1; |
| 632 |
const expectedDays = tripData.duration_days; |
| 633 |
const diff = selectedDays - expectedDays; |
| 634 |
if (diff === 0) { |
| 635 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-green-600 dark:text-green-400", children: [ |
| 636 |
__("Duration matches trip duration", "yatra"), |
| 637 |
" ", |
| 638 |
"(", |
| 639 |
selectedDays, |
| 640 |
" ", |
| 641 |
__("days", "yatra"), |
| 642 |
")" |
| 643 |
] }); |
| 644 |
} else if (diff < 0) { |
| 645 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-amber-600 dark:text-amber-400", children: [ |
| 646 |
__("Shorter than trip duration", "yatra"), |
| 647 |
":", |
| 648 |
" ", |
| 649 |
selectedDays, |
| 650 |
" ", |
| 651 |
__("days", "yatra"), |
| 652 |
" (", |
| 653 |
Math.abs(diff), |
| 654 |
" ", |
| 655 |
__("days shorter", "yatra"), |
| 656 |
" ", |
| 657 |
"than expected ", |
| 658 |
expectedDays, |
| 659 |
" ", |
| 660 |
__("days", "yatra"), |
| 661 |
")" |
| 662 |
] }); |
| 663 |
} else { |
| 664 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-amber-600 dark:text-amber-400", children: [ |
| 665 |
__("Longer than trip duration", "yatra"), |
| 666 |
":", |
| 667 |
" ", |
| 668 |
selectedDays, |
| 669 |
" ", |
| 670 |
__("days", "yatra"), |
| 671 |
" (", |
| 672 |
diff, |
| 673 |
" ", |
| 674 |
__("days longer", "yatra"), |
| 675 |
" than expected", |
| 676 |
" ", |
| 677 |
expectedDays, |
| 678 |
" ", |
| 679 |
__("days", "yatra"), |
| 680 |
")" |
| 681 |
] }); |
| 682 |
} |
| 683 |
})() }), |
| 684 |
(tripData == null ? void 0 : tripData.duration_days) && !formData.arrival_date && /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 685 |
HelpText, |
| 686 |
{ |
| 687 |
text: `${__("Trip duration", "yatra")}: ${tripData.duration_days} ${tripData.duration_days === 1 ? __("day", "yatra") : __("days", "yatra")}${tripData.duration_nights ? ` (${tripData.duration_nights} ${tripData.duration_nights === 1 ? __("night", "yatra") : __("nights", "yatra")})` : ""}`, |
| 688 |
className: "mt-1" |
| 689 |
} |
| 690 |
) |
| 691 |
] }) |
| 692 |
] }) |
| 693 |
), |
| 694 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-8 pt-2", children: [ |
| 695 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [ |
| 696 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 p-4 bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-900/20 dark:to-indigo-900/20 rounded-xl border border-blue-200 dark:border-blue-800", children: [ |
| 697 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-10 h-10 bg-gradient-to-br from-blue-500 to-blue-600 rounded-xl flex items-center justify-center shadow-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "w-5 h-5 text-white" }) }), |
| 698 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [ |
| 699 |
/* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "text-base font-semibold text-blue-900 dark:text-blue-100", children: __("Starting Point", "yatra") }), |
| 700 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-blue-700 dark:text-blue-300", children: __("Where the journey begins", "yatra") }) |
| 701 |
] }), |
| 702 |
formData.from_latitude && formData.from_longitude && /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 703 |
"div", |
| 704 |
{ |
| 705 |
className: "w-2 h-2 bg-blue-500 rounded-full", |
| 706 |
title: __("Coordinates set", "yatra") |
| 707 |
} |
| 708 |
) |
| 709 |
] }), |
| 710 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 711 |
/* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "text-sm font-medium text-gray-700 dark:text-gray-300", children: __("From location (departure)", "yatra") }), |
| 712 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 713 |
LocationPicker, |
| 714 |
{ |
| 715 |
value: { |
| 716 |
name: formData.from_location, |
| 717 |
latitude: formData.from_latitude, |
| 718 |
longitude: formData.from_longitude |
| 719 |
}, |
| 720 |
onChange: (loc) => { |
| 721 |
setFormData((prev) => ({ |
| 722 |
...prev, |
| 723 |
from_location: loc.name, |
| 724 |
from_latitude: loc.latitude, |
| 725 |
from_longitude: loc.longitude |
| 726 |
})); |
| 727 |
}, |
| 728 |
label: "", |
| 729 |
placeholder: __("Search for starting location...", "yatra"), |
| 730 |
helpText: "", |
| 731 |
required: false, |
| 732 |
defaultMapCenter: formData.from_latitude && formData.from_longitude ? [ |
| 733 |
parseFloat(formData.from_latitude), |
| 734 |
parseFloat(formData.from_longitude) |
| 735 |
] : (tripData == null ? void 0 : tripData.starting_latitude) && (tripData == null ? void 0 : tripData.starting_longitude) ? [ |
| 736 |
parseFloat(String(tripData.starting_latitude)), |
| 737 |
parseFloat(String(tripData.starting_longitude)) |
| 738 |
] : [20, 0], |
| 739 |
defaultZoom: formData.from_latitude && formData.from_longitude ? 13 : (tripData == null ? void 0 : tripData.starting_latitude) && (tripData == null ? void 0 : tripData.starting_longitude) ? 13 : 2, |
| 740 |
mapHeight: "300px", |
| 741 |
showMapButton: false, |
| 742 |
searchLimit: 8, |
| 743 |
__, |
| 744 |
className: "", |
| 745 |
mapClassName: "rounded-lg", |
| 746 |
showManualCoordinateFields: true |
| 747 |
} |
| 748 |
), |
| 749 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 750 |
HelpText, |
| 751 |
{ |
| 752 |
text: __( |
| 753 |
"Overrides trip starting location for this date only. Coordinates power maps and distance features.", |
| 754 |
"yatra" |
| 755 |
) |
| 756 |
} |
| 757 |
) |
| 758 |
] }) |
| 759 |
] }), |
| 760 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [ |
| 761 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 p-4 bg-gradient-to-r from-green-50 to-emerald-50 dark:from-green-900/20 dark:to-emerald-900/20 rounded-xl border border-green-200 dark:border-green-800", children: [ |
| 762 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-10 h-10 bg-gradient-to-br from-green-500 to-green-600 rounded-xl flex items-center justify-center shadow-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CheckCircle2, { className: "w-5 h-5 text-white" }) }), |
| 763 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [ |
| 764 |
/* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "text-base font-semibold text-green-900 dark:text-green-100", children: __("Ending Point", "yatra") }), |
| 765 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-green-700 dark:text-green-300", children: __("Where the journey concludes", "yatra") }) |
| 766 |
] }), |
| 767 |
formData.to_latitude && formData.to_longitude && /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 768 |
"div", |
| 769 |
{ |
| 770 |
className: "w-2 h-2 bg-green-500 rounded-full", |
| 771 |
title: __("Coordinates set", "yatra") |
| 772 |
} |
| 773 |
) |
| 774 |
] }), |
| 775 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [ |
| 776 |
/* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "text-sm font-medium text-gray-700 dark:text-gray-300", children: __("To location (destination)", "yatra") }), |
| 777 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 778 |
LocationPicker, |
| 779 |
{ |
| 780 |
value: { |
| 781 |
name: formData.to_location, |
| 782 |
latitude: formData.to_latitude, |
| 783 |
longitude: formData.to_longitude |
| 784 |
}, |
| 785 |
onChange: (loc) => { |
| 786 |
setFormData((prev) => ({ |
| 787 |
...prev, |
| 788 |
to_location: loc.name, |
| 789 |
to_latitude: loc.latitude, |
| 790 |
to_longitude: loc.longitude |
| 791 |
})); |
| 792 |
}, |
| 793 |
label: "", |
| 794 |
placeholder: __("Search for ending location...", "yatra"), |
| 795 |
helpText: "", |
| 796 |
required: false, |
| 797 |
defaultMapCenter: formData.to_latitude && formData.to_longitude ? [ |
| 798 |
parseFloat(formData.to_latitude), |
| 799 |
parseFloat(formData.to_longitude) |
| 800 |
] : (tripData == null ? void 0 : tripData.ending_latitude) && (tripData == null ? void 0 : tripData.ending_longitude) ? [ |
| 801 |
parseFloat(String(tripData.ending_latitude)), |
| 802 |
parseFloat(String(tripData.ending_longitude)) |
| 803 |
] : formData.from_latitude && formData.from_longitude ? [ |
| 804 |
parseFloat(formData.from_latitude), |
| 805 |
parseFloat(formData.from_longitude) |
| 806 |
] : (tripData == null ? void 0 : tripData.starting_latitude) && (tripData == null ? void 0 : tripData.starting_longitude) ? [ |
| 807 |
parseFloat( |
| 808 |
String(tripData.starting_latitude) |
| 809 |
), |
| 810 |
parseFloat( |
| 811 |
String(tripData.starting_longitude) |
| 812 |
) |
| 813 |
] : [20, 0], |
| 814 |
defaultZoom: formData.to_latitude && formData.to_longitude ? 13 : (tripData == null ? void 0 : tripData.ending_latitude) && (tripData == null ? void 0 : tripData.ending_longitude) ? 13 : formData.from_latitude && formData.from_longitude ? 13 : (tripData == null ? void 0 : tripData.starting_latitude) && (tripData == null ? void 0 : tripData.starting_longitude) ? 13 : 2, |
| 815 |
mapHeight: "300px", |
| 816 |
showMapButton: false, |
| 817 |
searchLimit: 8, |
| 818 |
__, |
| 819 |
className: "", |
| 820 |
mapClassName: "rounded-lg", |
| 821 |
showManualCoordinateFields: true |
| 822 |
} |
| 823 |
), |
| 824 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 825 |
HelpText, |
| 826 |
{ |
| 827 |
text: __( |
| 828 |
"Overrides trip ending location for this date only.", |
| 829 |
"yatra" |
| 830 |
) |
| 831 |
} |
| 832 |
) |
| 833 |
] }) |
| 834 |
] }) |
| 835 |
] }) |
| 836 |
] }) |
| 837 |
] }), |
| 838 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { children: [ |
| 839 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardHeader, { children: [ |
| 840 |
/* @__PURE__ */ jsxRuntimeExports.jsx(CardTitle, { children: __("Pricing & Availability", "yatra") }), |
| 841 |
/* @__PURE__ */ jsxRuntimeExports.jsx(CardDescription, { children: __( |
| 842 |
"Set pricing for traveler categories and seat availability for this date", |
| 843 |
"yatra" |
| 844 |
) }) |
| 845 |
] }), |
| 846 |
/* @__PURE__ */ jsxRuntimeExports.jsxs(CardContent, { className: "space-y-4", children: [ |
| 847 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg mb-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-3", children: [ |
| 848 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 rounded-full bg-amber-100 dark:bg-amber-900/30", children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 849 |
"svg", |
| 850 |
{ |
| 851 |
className: "w-5 h-5 text-amber-600 dark:text-amber-400", |
| 852 |
fill: "none", |
| 853 |
stroke: "currentColor", |
| 854 |
viewBox: "0 0 24 24", |
| 855 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 856 |
"path", |
| 857 |
{ |
| 858 |
strokeLinecap: "round", |
| 859 |
strokeLinejoin: "round", |
| 860 |
strokeWidth: 2, |
| 861 |
d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" |
| 862 |
} |
| 863 |
) |
| 864 |
} |
| 865 |
) }), |
| 866 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [ |
| 867 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white mb-1", children: __("Pricing Override (Optional)", "yatra") }), |
| 868 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-600 dark:text-gray-400", children: __( |
| 869 |
"Leave pricing fields empty to use the trip's default pricing. Fill them in only if you want to override the default pricing for this specific date.", |
| 870 |
"yatra" |
| 871 |
) }) |
| 872 |
] }) |
| 873 |
] }) }), |
| 874 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [ |
| 875 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 876 |
"div", |
| 877 |
{ |
| 878 |
className: `p-2 rounded-full ${formData.pricing_type === "traveler_based" ? "bg-green-100 dark:bg-green-900/30" : "bg-blue-100 dark:bg-blue-900/30"}`, |
| 879 |
children: formData.pricing_type === "traveler_based" ? /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 880 |
"svg", |
| 881 |
{ |
| 882 |
className: "w-5 h-5 text-green-600 dark:text-green-400", |
| 883 |
fill: "none", |
| 884 |
stroke: "currentColor", |
| 885 |
viewBox: "0 0 24 24", |
| 886 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 887 |
"path", |
| 888 |
{ |
| 889 |
strokeLinecap: "round", |
| 890 |
strokeLinejoin: "round", |
| 891 |
strokeWidth: 2, |
| 892 |
d: "M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" |
| 893 |
} |
| 894 |
) |
| 895 |
} |
| 896 |
) : /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 897 |
"svg", |
| 898 |
{ |
| 899 |
className: "w-5 h-5 text-blue-600 dark:text-blue-400", |
| 900 |
fill: "none", |
| 901 |
stroke: "currentColor", |
| 902 |
viewBox: "0 0 24 24", |
| 903 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 904 |
"path", |
| 905 |
{ |
| 906 |
strokeLinecap: "round", |
| 907 |
strokeLinejoin: "round", |
| 908 |
strokeWidth: 2, |
| 909 |
d: "M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" |
| 910 |
} |
| 911 |
) |
| 912 |
} |
| 913 |
) |
| 914 |
} |
| 915 |
), |
| 916 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 917 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-medium text-gray-900 dark:text-white", children: formData.pricing_type === "traveler_based" ? __("Traveler-Based Pricing", "yatra") : __("Regular Pricing", "yatra") }), |
| 918 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-600 dark:text-gray-400", children: formData.pricing_type === "traveler_based" ? __( |
| 919 |
"This trip uses traveler category pricing. Set prices for each category below.", |
| 920 |
"yatra" |
| 921 |
) : __( |
| 922 |
"This trip uses regular pricing. Set a single price for all travelers below.", |
| 923 |
"yatra" |
| 924 |
) }) |
| 925 |
] }) |
| 926 |
] }) }), |
| 927 |
formData.pricing_type === "regular" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [ |
| 928 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 929 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 930 |
__("Original Price", "yatra"), |
| 931 |
" ", |
| 932 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-400 text-xs", children: [ |
| 933 |
"(", |
| 934 |
__("Optional", "yatra"), |
| 935 |
")" |
| 936 |
] }) |
| 937 |
] }), |
| 938 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [ |
| 939 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-500 text-sm", children: getCurrencySymbol((tripData == null ? void 0 : tripData.currency) || "USD") }), |
| 940 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 941 |
Input, |
| 942 |
{ |
| 943 |
type: "number", |
| 944 |
step: "0.01", |
| 945 |
min: "0", |
| 946 |
value: formData.original_price, |
| 947 |
onChange: (e) => handleFieldChange("original_price", e.target.value), |
| 948 |
placeholder: "0.00", |
| 949 |
className: `pl-7 ${errors.original_price ? "border-red-500" : ""}` |
| 950 |
} |
| 951 |
) |
| 952 |
] }), |
| 953 |
errors.original_price && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.original_price }), |
| 954 |
!formData.original_price && tripData && /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "mt-1 text-xs text-blue-600 dark:text-blue-400", children: [ |
| 955 |
__("Using trip default", "yatra"), |
| 956 |
":", |
| 957 |
" ", |
| 958 |
getCurrencySymbol((tripData == null ? void 0 : tripData.currency) || "USD"), |
| 959 |
tripData.original_price || "0.00" |
| 960 |
] }) |
| 961 |
] }), |
| 962 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 963 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 964 |
__("Discounted Price", "yatra"), |
| 965 |
" (", |
| 966 |
__("Optional", "yatra"), |
| 967 |
")" |
| 968 |
] }), |
| 969 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [ |
| 970 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-500 text-sm", children: getCurrencySymbol((tripData == null ? void 0 : tripData.currency) || "USD") }), |
| 971 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 972 |
Input, |
| 973 |
{ |
| 974 |
type: "number", |
| 975 |
step: "0.01", |
| 976 |
min: "0", |
| 977 |
value: formData.discounted_price, |
| 978 |
onChange: (e) => handleFieldChange("discounted_price", e.target.value), |
| 979 |
placeholder: "0.00", |
| 980 |
className: `pl-7 ${errors.discounted_price ? "border-red-500" : ""}` |
| 981 |
} |
| 982 |
) |
| 983 |
] }), |
| 984 |
errors.discounted_price && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.discounted_price }) |
| 985 |
] }) |
| 986 |
] }) }), |
| 987 |
formData.pricing_type === "traveler_based" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [ |
| 988 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 989 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: [ |
| 990 |
__("Traveler Category Pricing", "yatra"), |
| 991 |
" ", |
| 992 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-400 text-xs", children: [ |
| 993 |
"(", |
| 994 |
__("Optional", "yatra"), |
| 995 |
")" |
| 996 |
] }) |
| 997 |
] }), |
| 998 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 dark:text-gray-400 mb-4", children: __( |
| 999 |
"Add pricing to override trip default pricing for specific traveler categories. Leave empty to use trip default pricing.", |
| 1000 |
"yatra" |
| 1001 |
) }) |
| 1002 |
] }), |
| 1003 |
isLoadingCategories ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center py-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader2, { className: "w-6 h-6 animate-spin text-gray-400" }) }) : activeCategories.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-6 border border-gray-200 dark:border-gray-700 rounded-lg text-center", children: [ |
| 1004 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400 mb-3", children: __("No active traveler categories found.", "yatra") }), |
| 1005 |
/* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 1006 |
Button, |
| 1007 |
{ |
| 1008 |
type: "button", |
| 1009 |
variant: "outline", |
| 1010 |
onClick: () => window.location.href = "?subpage=traveler-categories&action=create", |
| 1011 |
className: "flex items-center gap-2 mx-auto", |
| 1012 |
children: [ |
| 1013 |
/* @__PURE__ */ jsxRuntimeExports.jsx(Plus, { className: "w-4 h-4" }), |
| 1014 |
__("Create Category", "yatra") |
| 1015 |
] |
| 1016 |
} |
| 1017 |
) |
| 1018 |
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [ |
| 1019 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [ |
| 1020 |
/* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 1021 |
Button, |
| 1022 |
{ |
| 1023 |
type: "button", |
| 1024 |
variant: "outline", |
| 1025 |
onClick: () => setShowCategorySelector(!showCategorySelector), |
| 1026 |
className: "flex items-center gap-2", |
| 1027 |
disabled: activeCategories.filter( |
| 1028 |
(cat) => !formData.price_types.some( |
| 1029 |
(pt) => pt.category_id === cat.id |
| 1030 |
) |
| 1031 |
).length === 0, |
| 1032 |
children: [ |
| 1033 |
/* @__PURE__ */ jsxRuntimeExports.jsx(Plus, { className: "w-4 h-4" }), |
| 1034 |
__("Add Pricing", "yatra") |
| 1035 |
] |
| 1036 |
} |
| 1037 |
), |
| 1038 |
showCategorySelector && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [ |
| 1039 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1040 |
"div", |
| 1041 |
{ |
| 1042 |
className: "fixed inset-0 z-10", |
| 1043 |
onClick: () => setShowCategorySelector(false) |
| 1044 |
} |
| 1045 |
), |
| 1046 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute top-full left-0 mt-2 w-full max-w-md bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-20 max-h-96 overflow-y-auto", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-2", children: [ |
| 1047 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-medium text-gray-700 dark:text-gray-300 px-3 py-2 mb-1", children: __( |
| 1048 |
"Select a category to add pricing", |
| 1049 |
"yatra" |
| 1050 |
) }), |
| 1051 |
activeCategories.filter( |
| 1052 |
(cat) => !formData.price_types.some( |
| 1053 |
(pt) => pt.category_id === cat.id |
| 1054 |
) |
| 1055 |
).length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-3 py-4 text-sm text-gray-500 dark:text-gray-400 text-center", children: __( |
| 1056 |
"All categories have pricing added", |
| 1057 |
"yatra" |
| 1058 |
) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-1", children: activeCategories.filter( |
| 1059 |
(cat) => !formData.price_types.some( |
| 1060 |
(pt) => pt.category_id === cat.id |
| 1061 |
) |
| 1062 |
).map((category) => { |
| 1063 |
const ageRange = category.age_min !== void 0 || category.age_max !== void 0 ? category.age_min !== void 0 && category.age_max !== void 0 ? `${category.age_min}-${category.age_max} ${__("years", "yatra")}` : category.age_min !== void 0 ? `${category.age_min}+ ${__("years", "yatra")}` : category.age_max !== void 0 ? `${__("Under", "yatra")} ${category.age_max} ${__("years", "yatra")}` : "" : null; |
| 1064 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 1065 |
"button", |
| 1066 |
{ |
| 1067 |
type: "button", |
| 1068 |
onClick: () => { |
| 1069 |
handlePriceTypeAdd(category.id); |
| 1070 |
setShowCategorySelector(false); |
| 1071 |
}, |
| 1072 |
className: "w-full text-left px-3 py-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors", |
| 1073 |
children: [ |
| 1074 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-medium text-sm text-gray-900 dark:text-white", children: [ |
| 1075 |
category.label, |
| 1076 |
ageRange && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "ml-2 text-xs font-normal text-gray-500 dark:text-gray-400", children: [ |
| 1077 |
"(", |
| 1078 |
ageRange, |
| 1079 |
")" |
| 1080 |
] }) |
| 1081 |
] }), |
| 1082 |
category.description && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400 mt-0.5", children: category.description }) |
| 1083 |
] |
| 1084 |
}, |
| 1085 |
category.id |
| 1086 |
); |
| 1087 |
}) }) |
| 1088 |
] }) }) |
| 1089 |
] }) |
| 1090 |
] }), |
| 1091 |
formData.price_types.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-3", children: formData.price_types.map((priceType, index) => { |
| 1092 |
const category = activeCategories.find( |
| 1093 |
(cat) => cat.id === priceType.category_id |
| 1094 |
); |
| 1095 |
if (!category) return null; |
| 1096 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 1097 |
"div", |
| 1098 |
{ |
| 1099 |
className: "p-4 border border-blue-300 dark:border-blue-700 bg-blue-50 dark:bg-blue-900/20 rounded-lg", |
| 1100 |
children: [ |
| 1101 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between mb-3", children: [ |
| 1102 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [ |
| 1103 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center gap-2 mb-1", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("h4", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: [ |
| 1104 |
category.label, |
| 1105 |
(category.age_min !== void 0 || category.age_max !== void 0) && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "ml-2 text-xs font-normal text-gray-500 dark:text-gray-400", children: [ |
| 1106 |
"(", |
| 1107 |
category.age_min !== void 0 && category.age_max !== void 0 ? `${category.age_min}-${category.age_max} ${__("years", "yatra")}` : category.age_min !== void 0 ? `${category.age_min}+ ${__("years", "yatra")}` : category.age_max !== void 0 ? `${__("Under", "yatra")} ${category.age_max} ${__("years", "yatra")}` : "", |
| 1108 |
")" |
| 1109 |
] }) |
| 1110 |
] }) }), |
| 1111 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-600 dark:text-gray-400", children: category.description }) |
| 1112 |
] }), |
| 1113 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1114 |
"button", |
| 1115 |
{ |
| 1116 |
type: "button", |
| 1117 |
onClick: () => handlePriceTypeRemove(category.id), |
| 1118 |
className: "p-1 text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors", |
| 1119 |
title: __("Remove Pricing", "yatra"), |
| 1120 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx(X, { className: "w-4 h-4" }) |
| 1121 |
} |
| 1122 |
) |
| 1123 |
] }), |
| 1124 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-3", children: [ |
| 1125 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 1126 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 1127 |
__("Original Price", "yatra"), |
| 1128 |
" ", |
| 1129 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-400 text-xs", children: [ |
| 1130 |
"(", |
| 1131 |
__("Optional", "yatra"), |
| 1132 |
")" |
| 1133 |
] }) |
| 1134 |
] }), |
| 1135 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [ |
| 1136 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-500 text-sm", children: getCurrencySymbol( |
| 1137 |
(tripData == null ? void 0 : tripData.currency) || "USD" |
| 1138 |
) }), |
| 1139 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1140 |
Input, |
| 1141 |
{ |
| 1142 |
type: "number", |
| 1143 |
step: "0.01", |
| 1144 |
min: "0", |
| 1145 |
value: priceType.original_price, |
| 1146 |
onChange: (e) => handlePriceTypeChange( |
| 1147 |
category.id, |
| 1148 |
"original_price", |
| 1149 |
e.target.value |
| 1150 |
), |
| 1151 |
placeholder: "0.00", |
| 1152 |
className: `pl-7 ${errors[`price_type_${index}_original`] ? "border-red-500" : ""}` |
| 1153 |
} |
| 1154 |
) |
| 1155 |
] }), |
| 1156 |
errors[`price_type_${index}_original`] && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600 dark:text-red-400", children: errors[`price_type_${index}_original`] }) |
| 1157 |
] }), |
| 1158 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 1159 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 1160 |
__("Discounted Price", "yatra"), |
| 1161 |
" (", |
| 1162 |
__("Optional", "yatra"), |
| 1163 |
")" |
| 1164 |
] }), |
| 1165 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [ |
| 1166 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-500 text-sm", children: getCurrencySymbol( |
| 1167 |
(tripData == null ? void 0 : tripData.currency) || "USD" |
| 1168 |
) }), |
| 1169 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1170 |
Input, |
| 1171 |
{ |
| 1172 |
type: "number", |
| 1173 |
step: "0.01", |
| 1174 |
min: "0", |
| 1175 |
value: priceType.discounted_price, |
| 1176 |
onChange: (e) => handlePriceTypeChange( |
| 1177 |
category.id, |
| 1178 |
"discounted_price", |
| 1179 |
e.target.value |
| 1180 |
), |
| 1181 |
placeholder: "0.00", |
| 1182 |
className: `pl-7 ${errors[`price_type_${index}_discounted`] ? "border-red-500" : ""}` |
| 1183 |
} |
| 1184 |
) |
| 1185 |
] }), |
| 1186 |
errors[`price_type_${index}_discounted`] && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600 dark:text-red-400", children: errors[`price_type_${index}_discounted`] }) |
| 1187 |
] }) |
| 1188 |
] }) |
| 1189 |
] |
| 1190 |
}, |
| 1191 |
priceType.category_id |
| 1192 |
); |
| 1193 |
}) }), |
| 1194 |
errors.price_types && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-red-600 dark:text-red-400", children: errors.price_types }) |
| 1195 |
] }) |
| 1196 |
] }), |
| 1197 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-6 pt-6 border-t border-gray-200 dark:border-gray-700", children: [ |
| 1198 |
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-semibold text-gray-900 dark:text-white mb-4", children: __("Inventory Management", "yatra") }), |
| 1199 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-4", children: [ |
| 1200 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 1201 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: [ |
| 1202 |
__("Total Capacity", "yatra"), |
| 1203 |
" ", |
| 1204 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-500", children: "*" }) |
| 1205 |
] }), |
| 1206 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1207 |
Input, |
| 1208 |
{ |
| 1209 |
type: "number", |
| 1210 |
min: "1", |
| 1211 |
value: formData.total_seats, |
| 1212 |
onChange: (e) => handleFieldChange("total_seats", e.target.value), |
| 1213 |
placeholder: "20", |
| 1214 |
className: errors.total_seats ? "border-red-500" : "" |
| 1215 |
} |
| 1216 |
), |
| 1217 |
errors.total_seats && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-1 text-xs text-red-600", children: errors.total_seats }), |
| 1218 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1219 |
HelpText, |
| 1220 |
{ |
| 1221 |
text: tripMaxTravelers > 0 ? sprintf( |
| 1222 |
/* translators: %d: the trip's max travellers. */ |
| 1223 |
__( |
| 1224 |
"Seats for this date. Pre-filled from the trip's max travellers (%d) — change it for this date if it differs.", |
| 1225 |
"yatra" |
| 1226 |
), |
| 1227 |
tripMaxTravelers |
| 1228 |
) : __( |
| 1229 |
"Maximum number of seats available for this date", |
| 1230 |
"yatra" |
| 1231 |
), |
| 1232 |
className: "mt-1" |
| 1233 |
} |
| 1234 |
) |
| 1235 |
] }), |
| 1236 |
isEditMode && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 1237 |
/* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: __("Booked Seats", "yatra") }), |
| 1238 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1239 |
Input, |
| 1240 |
{ |
| 1241 |
type: "number", |
| 1242 |
min: "0", |
| 1243 |
value: formData.booked_seats, |
| 1244 |
readOnly: true, |
| 1245 |
className: "bg-gray-50 dark:bg-gray-800 cursor-not-allowed" |
| 1246 |
} |
| 1247 |
), |
| 1248 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1249 |
HelpText, |
| 1250 |
{ |
| 1251 |
text: __("Currently booked seats (read-only)", "yatra"), |
| 1252 |
className: "mt-1" |
| 1253 |
} |
| 1254 |
) |
| 1255 |
] }), |
| 1256 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 1257 |
/* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: __("Alert Threshold", "yatra") }), |
| 1258 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1259 |
Input, |
| 1260 |
{ |
| 1261 |
type: "number", |
| 1262 |
min: "1", |
| 1263 |
value: formData.alert_threshold, |
| 1264 |
onChange: (e) => handleFieldChange("alert_threshold", e.target.value), |
| 1265 |
placeholder: "5" |
| 1266 |
} |
| 1267 |
), |
| 1268 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1269 |
HelpText, |
| 1270 |
{ |
| 1271 |
text: __( |
| 1272 |
"Alert when available seats drop below this number", |
| 1273 |
"yatra" |
| 1274 |
), |
| 1275 |
className: "mt-1" |
| 1276 |
} |
| 1277 |
) |
| 1278 |
] }) |
| 1279 |
] }) |
| 1280 |
] }), |
| 1281 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-6 pt-6 border-t border-gray-200 dark:border-gray-700", children: [ |
| 1282 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-4", children: [ |
| 1283 |
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: __("Block Date", "yatra") }), |
| 1284 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [ |
| 1285 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1286 |
"input", |
| 1287 |
{ |
| 1288 |
type: "checkbox", |
| 1289 |
checked: formData.is_blocked, |
| 1290 |
onChange: (e) => { |
| 1291 |
handleFieldChange("is_blocked", e.target.checked); |
| 1292 |
if (e.target.checked) { |
| 1293 |
handleFieldChange("status", "blocked"); |
| 1294 |
} else { |
| 1295 |
handleFieldChange("status", "available"); |
| 1296 |
} |
| 1297 |
}, |
| 1298 |
className: "w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" |
| 1299 |
} |
| 1300 |
), |
| 1301 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-700 dark:text-gray-300", children: __("Block this date from bookings", "yatra") }) |
| 1302 |
] }) |
| 1303 |
] }), |
| 1304 |
formData.is_blocked && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [ |
| 1305 |
/* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: __("Block Reason", "yatra") }), |
| 1306 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1307 |
Input, |
| 1308 |
{ |
| 1309 |
type: "text", |
| 1310 |
maxLength: 255, |
| 1311 |
value: formData.block_reason, |
| 1312 |
onChange: (e) => handleFieldChange("block_reason", e.target.value), |
| 1313 |
placeholder: __( |
| 1314 |
"e.g., Maintenance, Holiday, Special Event", |
| 1315 |
"yatra" |
| 1316 |
) |
| 1317 |
} |
| 1318 |
), |
| 1319 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1320 |
HelpText, |
| 1321 |
{ |
| 1322 |
text: __( |
| 1323 |
"Reason for blocking this date (optional but recommended)", |
| 1324 |
"yatra" |
| 1325 |
), |
| 1326 |
className: "mt-1" |
| 1327 |
} |
| 1328 |
) |
| 1329 |
] }) |
| 1330 |
] }), |
| 1331 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-4", children: [ |
| 1332 |
/* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5", children: __("Status", "yatra") }), |
| 1333 |
/* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 1334 |
Select, |
| 1335 |
{ |
| 1336 |
value: formData.status, |
| 1337 |
onChange: (e) => { |
| 1338 |
handleFieldChange("status", e.target.value); |
| 1339 |
if (e.target.value === "blocked") { |
| 1340 |
handleFieldChange("is_blocked", true); |
| 1341 |
} else if (formData.is_blocked && e.target.value !== "blocked") { |
| 1342 |
handleFieldChange("is_blocked", false); |
| 1343 |
} |
| 1344 |
}, |
| 1345 |
disabled: formData.is_blocked, |
| 1346 |
children: [ |
| 1347 |
/* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "available", children: __("Available", "yatra") }), |
| 1348 |
/* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "limited", children: __("Limited", "yatra") }), |
| 1349 |
/* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "sold_out", children: __("Sold Out", "yatra") }), |
| 1350 |
/* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "closed", children: __("Closed", "yatra") }), |
| 1351 |
/* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "blocked", children: __("Blocked", "yatra") }) |
| 1352 |
] |
| 1353 |
} |
| 1354 |
), |
| 1355 |
formData.is_blocked && /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1356 |
HelpText, |
| 1357 |
{ |
| 1358 |
text: __( |
| 1359 |
'Status is automatically set to "Blocked" when date is blocked', |
| 1360 |
"yatra" |
| 1361 |
), |
| 1362 |
className: "mt-1" |
| 1363 |
} |
| 1364 |
) |
| 1365 |
] }) |
| 1366 |
] }) |
| 1367 |
] }), |
| 1368 |
errors.submit && /* @__PURE__ */ jsxRuntimeExports.jsxs(Alert, { variant: "error", children: [ |
| 1369 |
/* @__PURE__ */ jsxRuntimeExports.jsx(AlertCircle, { className: "w-4 h-4" }), |
| 1370 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: errors.submit }) |
| 1371 |
] }), |
| 1372 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-end gap-4", children: [ |
| 1373 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 1374 |
Button, |
| 1375 |
{ |
| 1376 |
type: "button", |
| 1377 |
variant: "outline", |
| 1378 |
onClick: () => { |
| 1379 |
if (tripId) { |
| 1380 |
navigate({ |
| 1381 |
subpage: "trips", |
| 1382 |
tab: "availability", |
| 1383 |
trip_id: tripId.toString() |
| 1384 |
}); |
| 1385 |
} else { |
| 1386 |
navigate({ subpage: "trips", tab: "availability" }); |
| 1387 |
} |
| 1388 |
}, |
| 1389 |
children: __("Cancel", "yatra") |
| 1390 |
} |
| 1391 |
), |
| 1392 |
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", disabled: saveMutation.isPending, children: saveMutation.isPending ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [ |
| 1393 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "inline-block animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2" }), |
| 1394 |
__("Saving...", "yatra") |
| 1395 |
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [ |
| 1396 |
/* @__PURE__ */ jsxRuntimeExports.jsx(Save, { className: "w-4 h-4 mr-2" }), |
| 1397 |
__("Save Availability", "yatra") |
| 1398 |
] }) }) |
| 1399 |
] }) |
| 1400 |
] }) |
| 1401 |
] }); |
| 1402 |
}; |
| 1403 |
export { |
| 1404 |
AvailabilityForm as default |
| 1405 |
}; |
| 1406 |
//# sourceMappingURL=AvailabilityForm-D4S_wB_o.js.map |
| 1407 |
|