PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.14.1
Yatra – Travel Booking & Tour Operator Software v3.0.14.1
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 / AvailabilityForm-BOtuwB57.js

AvailabilityForm-BOtuwB57.js in Yatra – Travel Booking & Tour Operator Software 3.0.14.1, at assets/dist/js/AvailabilityForm-BOtuwB57.js

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