@devtravelcode/widget-native 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/LICENSE +18 -0
  2. package/dist/App.d.ts +10 -0
  3. package/dist/App.js +192 -0
  4. package/dist/TravelHubWidget.d.ts +12 -0
  5. package/dist/TravelHubWidget.js +58 -0
  6. package/dist/components/ErrorBoundary.d.ts +18 -0
  7. package/dist/components/ErrorBoundary.js +63 -0
  8. package/dist/components/ui/Modal.d.ts +11 -0
  9. package/dist/components/ui/Modal.js +66 -0
  10. package/dist/components/ui/Skeleton.d.ts +8 -0
  11. package/dist/components/ui/Skeleton.js +33 -0
  12. package/dist/components/ui/badge.d.ts +11 -0
  13. package/dist/components/ui/badge.js +54 -0
  14. package/dist/components/ui/button.d.ts +14 -0
  15. package/dist/components/ui/button.js +101 -0
  16. package/dist/components/ui/card.d.ts +16 -0
  17. package/dist/components/ui/card.js +51 -0
  18. package/dist/components/ui/input.d.ts +8 -0
  19. package/dist/components/ui/input.js +61 -0
  20. package/dist/components/ui/label.d.ts +8 -0
  21. package/dist/components/ui/label.js +17 -0
  22. package/dist/context/WidgetContext.d.ts +29 -0
  23. package/dist/context/WidgetContext.js +64 -0
  24. package/dist/icons/CarIcon.d.ts +4 -0
  25. package/dist/icons/CarIcon.js +3 -0
  26. package/dist/icons/CloseIcon.d.ts +7 -0
  27. package/dist/icons/CloseIcon.js +3 -0
  28. package/dist/icons/FlightIcon.d.ts +4 -0
  29. package/dist/icons/FlightIcon.js +3 -0
  30. package/dist/icons/HotelIcon.d.ts +4 -0
  31. package/dist/icons/HotelIcon.js +3 -0
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +1 -0
  34. package/dist/lib/utils.d.ts +2 -0
  35. package/dist/lib/utils.js +3 -0
  36. package/dist/locales/widgetTranslations.d.ts +1 -0
  37. package/dist/locales/widgetTranslations.js +732 -0
  38. package/dist/modules/hooks/useAirportSearch.d.ts +21 -0
  39. package/dist/modules/hooks/useAirportSearch.js +48 -0
  40. package/dist/modules/hooks/useCarOffers.d.ts +7 -0
  41. package/dist/modules/hooks/useCarOffers.js +47 -0
  42. package/dist/modules/hooks/useCountriesByCodes.d.ts +4 -0
  43. package/dist/modules/hooks/useCountriesByCodes.js +60 -0
  44. package/dist/modules/hooks/useCountriesSearch.d.ts +11 -0
  45. package/dist/modules/hooks/useCountriesSearch.js +55 -0
  46. package/dist/modules/hooks/useDefaultHotelLocation.d.ts +7 -0
  47. package/dist/modules/hooks/useDefaultHotelLocation.js +44 -0
  48. package/dist/modules/hooks/useDetectNationality.d.ts +1 -0
  49. package/dist/modules/hooks/useDetectNationality.js +20 -0
  50. package/dist/modules/hooks/useFlightSearch.d.ts +20 -0
  51. package/dist/modules/hooks/useFlightSearch.js +243 -0
  52. package/dist/modules/hooks/useHotelDetails.d.ts +7 -0
  53. package/dist/modules/hooks/useHotelDetails.js +80 -0
  54. package/dist/modules/hooks/useHotelLocations.d.ts +5 -0
  55. package/dist/modules/hooks/useHotelLocations.js +42 -0
  56. package/dist/modules/hooks/useHotelMapData.d.ts +12 -0
  57. package/dist/modules/hooks/useHotelMapData.js +78 -0
  58. package/dist/modules/hooks/useHotelOffers.d.ts +11 -0
  59. package/dist/modules/hooks/useHotelOffers.js +122 -0
  60. package/dist/modules/hooks/useHotelSearchSSE.d.ts +18 -0
  61. package/dist/modules/hooks/useHotelSearchSSE.js +411 -0
  62. package/dist/modules/hooks/useSearchExpiration.d.ts +6 -0
  63. package/dist/modules/hooks/useSearchExpiration.js +35 -0
  64. package/dist/modules/hooks/useTranslationsHub.d.ts +5 -0
  65. package/dist/modules/hooks/useTranslationsHub.js +48 -0
  66. package/dist/modules/navbar/Navbar.d.ts +8 -0
  67. package/dist/modules/navbar/Navbar.js +69 -0
  68. package/dist/modules/search-form/AgeSelector.d.ts +9 -0
  69. package/dist/modules/search-form/AgeSelector.js +109 -0
  70. package/dist/modules/search-form/CustomSelect.d.ts +14 -0
  71. package/dist/modules/search-form/CustomSelect.js +94 -0
  72. package/dist/modules/search-form/FiltersSkeleton.d.ts +6 -0
  73. package/dist/modules/search-form/FiltersSkeleton.js +35 -0
  74. package/dist/modules/search-form/NationalityInput.d.ts +18 -0
  75. package/dist/modules/search-form/NationalityInput.js +172 -0
  76. package/dist/modules/search-form/Pagination.d.ts +8 -0
  77. package/dist/modules/search-form/Pagination.js +84 -0
  78. package/dist/modules/search-form/SearchExpiredPopup.d.ts +10 -0
  79. package/dist/modules/search-form/SearchExpiredPopup.js +91 -0
  80. package/dist/modules/search-form/SkeletonWidget.d.ts +2 -0
  81. package/dist/modules/search-form/SkeletonWidget.js +33 -0
  82. package/dist/modules/search-form/TimePicker.d.ts +9 -0
  83. package/dist/modules/search-form/TimePicker.js +182 -0
  84. package/dist/modules/search-form/cars/CarEmptyState.d.ts +6 -0
  85. package/dist/modules/search-form/cars/CarEmptyState.js +42 -0
  86. package/dist/modules/search-form/cars/CarFiltersSkeleton.d.ts +6 -0
  87. package/dist/modules/search-form/cars/CarFiltersSkeleton.js +35 -0
  88. package/dist/modules/search-form/cars/CarOffersList.d.ts +43 -0
  89. package/dist/modules/search-form/cars/CarOffersList.js +214 -0
  90. package/dist/modules/search-form/cars/CarResults.d.ts +25 -0
  91. package/dist/modules/search-form/cars/CarResults.js +116 -0
  92. package/dist/modules/search-form/cars/CarSearchForm.d.ts +19 -0
  93. package/dist/modules/search-form/cars/CarSearchForm.js +173 -0
  94. package/dist/modules/search-form/cars/CarSkeleton.d.ts +6 -0
  95. package/dist/modules/search-form/cars/CarSkeleton.js +46 -0
  96. package/dist/modules/search-form/cars/CarTopOffersSlider.d.ts +20 -0
  97. package/dist/modules/search-form/cars/CarTopOffersSlider.js +100 -0
  98. package/dist/modules/search-form/cars/car-filters/CarFilters.d.ts +8 -0
  99. package/dist/modules/search-form/cars/car-filters/CarFilters.js +318 -0
  100. package/dist/modules/search-form/cars/car-filters/FilterSection.d.ts +9 -0
  101. package/dist/modules/search-form/cars/car-filters/FilterSection.js +30 -0
  102. package/dist/modules/search-form/cars/car-filters/index.d.ts +6 -0
  103. package/dist/modules/search-form/cars/car-filters/index.js +3 -0
  104. package/dist/modules/search-form/cars/car-filters/useCarFilters.d.ts +24 -0
  105. package/dist/modules/search-form/cars/car-filters/useCarFilters.js +121 -0
  106. package/dist/modules/search-form/flight/AirlinesSelector.d.ts +8 -0
  107. package/dist/modules/search-form/flight/AirlinesSelector.js +235 -0
  108. package/dist/modules/search-form/flight/CabinClassSelector.d.ts +9 -0
  109. package/dist/modules/search-form/flight/CabinClassSelector.js +63 -0
  110. package/dist/modules/search-form/flight/DatePicker.d.ts +12 -0
  111. package/dist/modules/search-form/flight/DatePicker.js +536 -0
  112. package/dist/modules/search-form/flight/FlightSearchForm.d.ts +18 -0
  113. package/dist/modules/search-form/flight/FlightSearchForm.js +147 -0
  114. package/dist/modules/search-form/flight/LocationInput.d.ts +11 -0
  115. package/dist/modules/search-form/flight/LocationInput.js +294 -0
  116. package/dist/modules/search-form/flight/PassengersPicker.d.ts +16 -0
  117. package/dist/modules/search-form/flight/PassengersPicker.js +203 -0
  118. package/dist/modules/search-form/flight/SwitchLocationBtn.d.ts +9 -0
  119. package/dist/modules/search-form/flight/SwitchLocationBtn.js +48 -0
  120. package/dist/modules/search-form/flight/flight-filters/FiltersContent.d.ts +21 -0
  121. package/dist/modules/search-form/flight/flight-filters/FiltersContent.js +145 -0
  122. package/dist/modules/search-form/flight/flight-filters/FlightFiltersDynamic.d.ts +11 -0
  123. package/dist/modules/search-form/flight/flight-filters/FlightFiltersDynamic.js +213 -0
  124. package/dist/modules/search-form/flight/flight-filters/RangeBlock.d.ts +22 -0
  125. package/dist/modules/search-form/flight/flight-filters/RangeBlock.js +164 -0
  126. package/dist/modules/search-form/flight/flight-filters/index.d.ts +1 -0
  127. package/dist/modules/search-form/flight/flight-filters/index.js +1 -0
  128. package/dist/modules/search-form/flight/flight-results/FlightAdditionalInfo.d.ts +16 -0
  129. package/dist/modules/search-form/flight/flight-results/FlightAdditionalInfo.js +229 -0
  130. package/dist/modules/search-form/flight/flight-results/FlightBaggageToggle.d.ts +15 -0
  131. package/dist/modules/search-form/flight/flight-results/FlightBaggageToggle.js +110 -0
  132. package/dist/modules/search-form/flight/flight-results/FlightCard.d.ts +14 -0
  133. package/dist/modules/search-form/flight/flight-results/FlightCard.js +436 -0
  134. package/dist/modules/search-form/flight/flight-results/FlightInfo.d.ts +12 -0
  135. package/dist/modules/search-form/flight/flight-results/FlightInfo.js +48 -0
  136. package/dist/modules/search-form/flight/flight-results/FlightPriceBlock.d.ts +11 -0
  137. package/dist/modules/search-form/flight/flight-results/FlightPriceBlock.js +36 -0
  138. package/dist/modules/search-form/flight/flight-results/FlightResults.d.ts +22 -0
  139. package/dist/modules/search-form/flight/flight-results/FlightResults.js +109 -0
  140. package/dist/modules/search-form/flight/flight-results/FlightSegments.d.ts +40 -0
  141. package/dist/modules/search-form/flight/flight-results/FlightSegments.js +162 -0
  142. package/dist/modules/search-form/flight/flight-results/FlightsSkeleton.d.ts +6 -0
  143. package/dist/modules/search-form/flight/flight-results/FlightsSkeleton.js +52 -0
  144. package/dist/modules/search-form/flight/flight-results/ProvidersLoader.d.ts +9 -0
  145. package/dist/modules/search-form/flight/flight-results/ProvidersLoader.js +242 -0
  146. package/dist/modules/search-form/hotel/DatePicker.d.ts +1 -0
  147. package/dist/modules/search-form/hotel/DatePicker.js +1 -0
  148. package/dist/modules/search-form/hotel/GuestSelector.d.ts +13 -0
  149. package/dist/modules/search-form/hotel/GuestSelector.js +272 -0
  150. package/dist/modules/search-form/hotel/GuestSelectorMobilePopup.d.ts +2 -0
  151. package/dist/modules/search-form/hotel/GuestSelectorMobilePopup.js +1 -0
  152. package/dist/modules/search-form/hotel/HotelLocation.d.ts +17 -0
  153. package/dist/modules/search-form/hotel/HotelLocation.js +178 -0
  154. package/dist/modules/search-form/hotel/HotelLocationMobilePopup.d.ts +2 -0
  155. package/dist/modules/search-form/hotel/HotelLocationMobilePopup.js +1 -0
  156. package/dist/modules/search-form/hotel/HotelResults.d.ts +21 -0
  157. package/dist/modules/search-form/hotel/HotelResults.js +333 -0
  158. package/dist/modules/search-form/hotel/HotelSearchForm.d.ts +13 -0
  159. package/dist/modules/search-form/hotel/HotelSearchForm.js +130 -0
  160. package/dist/modules/search-form/hotel/HotelsSkeleton.d.ts +6 -0
  161. package/dist/modules/search-form/hotel/HotelsSkeleton.js +40 -0
  162. package/dist/modules/search-form/hotel/PassengersPicker.d.ts +2 -0
  163. package/dist/modules/search-form/hotel/PassengersPicker.js +1 -0
  164. package/dist/modules/search-form/hotel/components/HotelCard.d.ts +11 -0
  165. package/dist/modules/search-form/hotel/components/HotelCard.js +180 -0
  166. package/dist/modules/search-form/hotel/components/HotelEmptyState.d.ts +6 -0
  167. package/dist/modules/search-form/hotel/components/HotelEmptyState.js +34 -0
  168. package/dist/modules/search-form/hotel/components/HotelGallery.d.ts +6 -0
  169. package/dist/modules/search-form/hotel/components/HotelGallery.js +77 -0
  170. package/dist/modules/search-form/hotel/components/HotelList.d.ts +9 -0
  171. package/dist/modules/search-form/hotel/components/HotelList.js +12 -0
  172. package/dist/modules/search-form/hotel/components/HotelMap.d.ts +26 -0
  173. package/dist/modules/search-form/hotel/components/HotelMap.js +707 -0
  174. package/dist/modules/search-form/hotel/components/HotelPin.d.ts +7 -0
  175. package/dist/modules/search-form/hotel/components/HotelPin.js +1 -0
  176. package/dist/modules/search-form/hotel/hotel-filters/HotelFilters.d.ts +29 -0
  177. package/dist/modules/search-form/hotel/hotel-filters/HotelFilters.js +339 -0
  178. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersBar.d.ts +3 -0
  179. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersBar.js +2 -0
  180. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersContent.d.ts +2 -0
  181. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersContent.js +1 -0
  182. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersDynamic.d.ts +2 -0
  183. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersDynamic.js +1 -0
  184. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersMobilePopup.d.ts +2 -0
  185. package/dist/modules/search-form/hotel/hotel-filters/HotelFiltersMobilePopup.js +1 -0
  186. package/dist/modules/search-form/hotel/hotel-filters/RangeBlock.d.ts +1 -0
  187. package/dist/modules/search-form/hotel/hotel-filters/RangeBlock.js +1 -0
  188. package/dist/modules/search-form/hotel/hotel-filters/index.d.ts +1 -0
  189. package/dist/modules/search-form/hotel/hotel-filters/index.js +1 -0
  190. package/dist/modules/tabs/FlightsTab.d.ts +1 -0
  191. package/dist/modules/tabs/FlightsTab.js +1 -0
  192. package/dist/modules/tabs/HotelsTab.d.ts +1 -0
  193. package/dist/modules/tabs/HotelsTab.js +1 -0
  194. package/dist/store/index.d.ts +22 -0
  195. package/dist/store/index.js +19 -0
  196. package/dist/theme/colors.d.ts +56 -0
  197. package/dist/theme/colors.js +56 -0
  198. package/dist/theme/formStyles.d.ts +76 -0
  199. package/dist/theme/formStyles.js +78 -0
  200. package/dist/utils/applyWidgetColors.d.ts +1 -0
  201. package/dist/utils/applyWidgetColors.js +2 -0
  202. package/dist/utils/dateTime.d.ts +2 -0
  203. package/dist/utils/dateTime.js +23 -0
  204. package/dist/utils/fetchSSE.d.ts +23 -0
  205. package/dist/utils/fetchSSE.js +104 -0
  206. package/dist/utils/getToken.d.ts +3 -0
  207. package/dist/utils/getToken.js +12 -0
  208. package/package.json +64 -0
@@ -0,0 +1,116 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useMemo } from "react";
3
+ import { View, Text, FlatList, ActivityIndicator, StyleSheet, } from "react-native";
4
+ import CarsSkeleton from "./CarSkeleton";
5
+ import CarFiltersSkeleton from "./CarFiltersSkeleton";
6
+ import CarEmptyState from "./CarEmptyState";
7
+ import CarTopOffersSlider from "./CarTopOffersSlider";
8
+ import { CarFilters } from "./car-filters/CarFilters";
9
+ import CarOffersList from "./CarOffersList";
10
+ import Pagination from "../Pagination";
11
+ import { Colors, Spacing, FontSize } from "../../../theme/colors";
12
+ const CarResults = ({ offers, filteredOffers, paginatedOffers, loading, error, isFiltering, hasAppliedFilters, onFilterChange, onFiltersApplied, days, searchParams, translations, hasCarSearched, lang, currency, currentPage, totalPages, onPageChange, isPageLoading, headerComponent, }) => {
13
+ const hasResults = offers.length > 0;
14
+ const hasFilteredResults = filteredOffers.length > 0;
15
+ const filtersAreActive = filteredOffers.length !== offers.length || hasAppliedFilters;
16
+ const displayCount = filtersAreActive
17
+ ? filteredOffers.length
18
+ : offers.length;
19
+ const resultCountText = useMemo(() => {
20
+ const label = translations["results_found"] || "Found";
21
+ const unit = lang === "ru"
22
+ ? displayCount === 1
23
+ ? "machine"
24
+ : displayCount < 5
25
+ ? "cars"
26
+ : "cars"
27
+ : displayCount === 1
28
+ ? "car"
29
+ : "cars";
30
+ return `${label} ${displayCount} ${unit}`;
31
+ }, [displayCount, translations, lang]);
32
+ const handleCategorySelect = useCallback((category) => {
33
+ onFiltersApplied?.();
34
+ }, [onFiltersApplied]);
35
+ if (!hasCarSearched) {
36
+ return (_jsx(View, { style: styles.container, children: headerComponent }));
37
+ }
38
+ if (loading && !isFiltering) {
39
+ return (_jsxs(View, { style: styles.container, children: [headerComponent, _jsx(CarFiltersSkeleton, { translations: translations }), _jsx(CarsSkeleton, { translations: translations })] }));
40
+ }
41
+ if (isFiltering) {
42
+ return (_jsxs(View, { style: styles.container, children: [headerComponent, _jsxs(View, { style: styles.filteringContainer, children: [_jsx(ActivityIndicator, { size: "large", color: Colors.primary }), _jsx(Text, { style: styles.filteringText, children: translations["loading"] || "Loading..." })] })] }));
43
+ }
44
+ if (error && !loading) {
45
+ return (_jsxs(View, { style: styles.container, children: [headerComponent, _jsxs(View, { style: styles.errorContainer, children: [_jsx(Text, { style: styles.errorTitle, children: translations["car_search_error_title"] || "Search error" }), _jsx(Text, { style: styles.errorText, children: translations["car_search_error_hint"] || "Something went wrong. Please try again." })] })] }));
46
+ }
47
+ if (!loading && !hasResults && !filtersAreActive) {
48
+ return (_jsxs(View, { style: styles.container, children: [headerComponent, _jsx(CarEmptyState, { translations: translations })] }));
49
+ }
50
+ const renderHeader = () => (_jsxs(View, { children: [headerComponent, _jsx(CarTopOffersSlider, { offers: offers, translations: translations, onCategorySelect: handleCategorySelect }), hasCarSearched && !loading ? (_jsx(Text, { style: styles.resultCount, children: resultCountText })) : null, _jsx(CarFilters, { offers: offers, onFilterChange: onFilterChange, onFiltersApplied: onFiltersApplied, translations: translations }), filtersAreActive && !hasFilteredResults ? (_jsx(CarEmptyState, { translations: translations })) : null] }));
51
+ const renderFooter = () => {
52
+ if (totalPages <= 1)
53
+ return null;
54
+ return (_jsx(View, { style: styles.paginationWrapper, children: _jsx(Pagination, { currentPage: currentPage, totalPages: totalPages, onPageChange: onPageChange }) }));
55
+ };
56
+ return (_jsxs(View, { style: styles.container, children: [(isPageLoading || isFiltering) && (_jsxs(View, { style: styles.overlayLoader, children: [_jsx(ActivityIndicator, { size: "large", color: Colors.primary }), _jsx(Text, { style: styles.filteringText, children: translations["loading"] || "Loading..." })] })), hasFilteredResults ? (_jsx(FlatList, { data: [{ key: "content" }], renderItem: () => (_jsx(CarOffersList, { offers: paginatedOffers, days: days, searchParams: searchParams, translations: translations, lang: lang })), keyExtractor: (item) => item.key, ListHeaderComponent: renderHeader(), ListFooterComponent: renderFooter(), showsVerticalScrollIndicator: false, contentContainerStyle: styles.listContent })) : (_jsx(FlatList, { data: [], renderItem: null, ListHeaderComponent: renderHeader(), showsVerticalScrollIndicator: false, contentContainerStyle: styles.listContent }))] }));
57
+ };
58
+ const styles = StyleSheet.create({
59
+ container: {
60
+ flex: 1,
61
+ position: "relative",
62
+ },
63
+ listContent: {
64
+ paddingBottom: Spacing.lg,
65
+ },
66
+ filteringContainer: {
67
+ flex: 1,
68
+ justifyContent: "center",
69
+ alignItems: "center",
70
+ padding: Spacing.xxl,
71
+ },
72
+ filteringText: {
73
+ marginTop: Spacing.sm,
74
+ fontSize: FontSize.md,
75
+ color: Colors.textSecondary,
76
+ },
77
+ resultCount: {
78
+ fontSize: FontSize.md,
79
+ color: Colors.textSecondary,
80
+ fontWeight: "500",
81
+ paddingHorizontal: Spacing.lg,
82
+ paddingVertical: Spacing.sm,
83
+ },
84
+ paginationWrapper: {
85
+ paddingVertical: Spacing.lg,
86
+ alignItems: "center",
87
+ },
88
+ errorContainer: {
89
+ padding: Spacing.xxl,
90
+ alignItems: "center",
91
+ },
92
+ errorTitle: {
93
+ fontSize: FontSize.xl,
94
+ fontWeight: "600",
95
+ color: Colors.error,
96
+ marginBottom: Spacing.sm,
97
+ textAlign: "center",
98
+ },
99
+ errorText: {
100
+ fontSize: FontSize.md,
101
+ color: Colors.textSecondary,
102
+ textAlign: "center",
103
+ },
104
+ overlayLoader: {
105
+ position: "absolute",
106
+ top: 0,
107
+ left: 0,
108
+ right: 0,
109
+ bottom: 0,
110
+ backgroundColor: "rgba(255,255,255,0.7)",
111
+ zIndex: 10,
112
+ justifyContent: "center",
113
+ alignItems: "center",
114
+ },
115
+ });
116
+ export default CarResults;
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { useSearchExpiration } from "../../hooks/useSearchExpiration";
3
+ type CarSearchFormProps = {
4
+ startSearch?: (params: any) => Promise<any>;
5
+ loading?: boolean;
6
+ error?: string | null;
7
+ onDaysChange?: (days: number) => void;
8
+ onSearchParamsChange?: (params: {
9
+ country: string;
10
+ nationality: string;
11
+ age: number;
12
+ }) => void;
13
+ translations: Record<string, string>;
14
+ isPreview: boolean;
15
+ expiration?: ReturnType<typeof useSearchExpiration>;
16
+ hasSearched?: boolean;
17
+ };
18
+ declare const CarSearchForm: React.FC<CarSearchFormProps>;
19
+ export default CarSearchForm;
@@ -0,0 +1,173 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { View, Text, TouchableOpacity, Switch, ScrollView, ActivityIndicator, StyleSheet, } from "react-native";
4
+ import { format, addDays, differenceInCalendarDays, parseISO } from "date-fns";
5
+ import LocationInput from "../flight/LocationInput";
6
+ import DatePicker from "../flight/DatePicker";
7
+ import NationalityInput from "../NationalityInput";
8
+ import AgeSelector from "../AgeSelector";
9
+ import TimePicker from "../TimePicker";
10
+ import { useWidget } from "../../../context/WidgetContext";
11
+ import SearchExpiredPopup from "../../search-form/SearchExpiredPopup";
12
+ import { useSearchExpiration } from "../../hooks/useSearchExpiration";
13
+ import { useDetectNationality } from "../../hooks/useDetectNationality";
14
+ import { Colors, Spacing, FontSize } from "../../../theme/colors";
15
+ import { formStyles } from "../../../theme/formStyles";
16
+ const CarSearchForm = ({ startSearch, loading = false, error = null, onDaysChange, onSearchParamsChange, translations, isPreview, expiration, hasSearched = false, }) => {
17
+ const { lang, currency, config, colors } = useWidget();
18
+ const today = new Date();
19
+ const defaultPickupDate = format(addDays(today, 3), "yyyy-MM-dd");
20
+ const defaultDropoffDate = format(addDays(today, 7), "yyyy-MM-dd");
21
+ const [pickupLocation, setPickupLocation] = useState("");
22
+ const [dropoffLocation, setDropoffLocation] = useState("");
23
+ const [dates, setDates] = useState([
24
+ defaultPickupDate,
25
+ defaultDropoffDate,
26
+ ]);
27
+ const [times, setTimes] = useState(["12:00", "12:00"]);
28
+ const [driverAge, setDriverAge] = useState("30-65");
29
+ const [nationality, setNationality] = useState("");
30
+ const [sameLocation, setSameLocation] = useState(true);
31
+ const [formErrors, setFormErrors] = useState({
32
+ pickupLocation: "",
33
+ dropoffLocation: "",
34
+ date: "",
35
+ nationality: "",
36
+ timePickup: "",
37
+ timeDropoff: "",
38
+ });
39
+ const detectedNationality = useDetectNationality();
40
+ useEffect(() => {
41
+ if (!nationality && detectedNationality) {
42
+ setNationality(detectedNationality);
43
+ }
44
+ }, [detectedNationality]);
45
+ const defaultExpiration = useSearchExpiration(30);
46
+ const { isExpired: isCarSearchExpired, startTimer, ignore: closeCarSearchPopup, } = expiration || defaultExpiration;
47
+ const refreshCarSearch = () => {
48
+ startTimer();
49
+ closeCarSearchPopup();
50
+ handleSearchClick();
51
+ };
52
+ useEffect(() => {
53
+ if (config?.defaults?.cars) {
54
+ const pickup = config.defaults.cars.from || "WAW";
55
+ setPickupLocation(pickup);
56
+ setDropoffLocation(pickup);
57
+ setSameLocation(true);
58
+ }
59
+ }, [config]);
60
+ const resolveDriverAge = (ageValue) => {
61
+ if (ageValue === "30-65")
62
+ return 30;
63
+ if (ageValue === "80+")
64
+ return 80;
65
+ return parseInt(ageValue, 10);
66
+ };
67
+ const days = dates[0] && dates[1]
68
+ ? Math.max(1, differenceInCalendarDays(parseISO(dates[1]), parseISO(dates[0])))
69
+ : 1;
70
+ useEffect(() => {
71
+ onDaysChange?.(days);
72
+ }, [days, onDaysChange]);
73
+ const handleSearchClick = async () => {
74
+ if (isPreview)
75
+ return;
76
+ startTimer();
77
+ const errors = {
78
+ pickupLocation: !pickupLocation
79
+ ? translations["car_form_error_pickup"] || "Enter pickup location"
80
+ : "",
81
+ dropoffLocation: !sameLocation && !dropoffLocation
82
+ ? translations["car_form_error_dropoff"] || "Enter drop-off location"
83
+ : "",
84
+ date: !dates[0]
85
+ ? translations["car_form_error_date"] || "Select rental dates"
86
+ : "",
87
+ nationality: !nationality
88
+ ? translations["car_form_error_nationality"] || "Select nationality"
89
+ : "",
90
+ timePickup: !times[0]
91
+ ? translations["car_form_error_time_pickup"] || "Select pickup time"
92
+ : "",
93
+ timeDropoff: !times[1]
94
+ ? translations["car_form_error_time_dropoff"] || "Select drop-off time"
95
+ : "",
96
+ };
97
+ setFormErrors(errors);
98
+ if (Object.values(errors).some((e) => e))
99
+ return;
100
+ const payload = {
101
+ currency: currency,
102
+ driver: {
103
+ age: resolveDriverAge(driverAge),
104
+ residence: nationality,
105
+ },
106
+ pickup_at: `${dates[0]}T${times[0]}:00`,
107
+ dropoff_at: `${dates[1]}T${times[1]}:00`,
108
+ pickup_location: { iata: pickupLocation },
109
+ dropoff_location: {
110
+ iata: sameLocation ? pickupLocation : dropoffLocation,
111
+ },
112
+ };
113
+ onSearchParamsChange?.({
114
+ country: "France",
115
+ nationality,
116
+ age: resolveDriverAge(driverAge),
117
+ });
118
+ await startSearch?.(payload);
119
+ };
120
+ return (_jsxs(ScrollView, { style: styles.container, showsVerticalScrollIndicator: false, keyboardShouldPersistTaps: "handled", children: [_jsxs(View, { style: [
121
+ formStyles.formCard,
122
+ { backgroundColor: colors?.form || Colors.surface },
123
+ ], children: [_jsxs(View, { style: styles.sameLocationRow, children: [_jsx(Switch, { value: sameLocation, disabled: true, trackColor: {
124
+ false: Colors.border,
125
+ true: Colors.primaryLight,
126
+ }, thumbColor: sameLocation ? Colors.primary : Colors.textTertiary }), _jsx(Text, { style: styles.sameLocationLabel, children: translations["car_form_same_location"] ||
127
+ "Return to same location" })] }), _jsxs(View, { children: [_jsx(DatePicker, { value: dates, onChange: (val) => {
128
+ setDates(val);
129
+ if (formErrors.date)
130
+ setFormErrors((p) => ({ ...p, date: "" }));
131
+ }, lang: lang, translations: translations, mode: "car" }), formErrors.date ? (_jsx(Text, { style: formStyles.errorText, children: formErrors.date })) : null] }), _jsxs(View, { children: [_jsx(TimePicker, { value: times, onChange: (val) => {
132
+ setTimes(val);
133
+ if (formErrors.timePickup || formErrors.timeDropoff)
134
+ setFormErrors((p) => ({
135
+ ...p,
136
+ timePickup: "",
137
+ timeDropoff: "",
138
+ }));
139
+ }, lang: "ru", translations: translations }), formErrors.timePickup ? (_jsx(Text, { style: formStyles.errorText, children: formErrors.timePickup })) : null, formErrors.timeDropoff ? (_jsx(Text, { style: formStyles.errorText, children: formErrors.timeDropoff })) : null] }), _jsxs(View, { children: [_jsx(LocationInput, { label: translations["car_form_pickup_location"] || "Pickup location", value: pickupLocation, onChange: (val) => {
140
+ setPickupLocation(val);
141
+ if (formErrors.pickupLocation)
142
+ setFormErrors((p) => ({ ...p, pickupLocation: "" }));
143
+ }, lang: lang, translations: translations }), formErrors.pickupLocation ? (_jsx(Text, { style: formStyles.errorText, children: formErrors.pickupLocation })) : null] }), !sameLocation ? (_jsxs(View, { children: [_jsx(LocationInput, { label: translations["car_form_dropoff_location"] ||
144
+ "Drop-off location", value: dropoffLocation, onChange: (val) => {
145
+ setDropoffLocation(val);
146
+ if (formErrors.dropoffLocation)
147
+ setFormErrors((p) => ({ ...p, dropoffLocation: "" }));
148
+ }, lang: lang, translations: translations }), formErrors.dropoffLocation ? (_jsx(Text, { style: formStyles.errorText, children: formErrors.dropoffLocation })) : null] })) : null, _jsxs(View, { children: [_jsx(NationalityInput, { label: translations["car_form_nationality"] || "Nationality", value: nationality, onChange: (val) => {
149
+ setNationality(val);
150
+ if (formErrors.nationality)
151
+ setFormErrors((p) => ({ ...p, nationality: "" }));
152
+ }, translations: translations, defaultNationality: detectedNationality, defaultNationalities: config?.nationalities || null, lang: lang }), formErrors.nationality ? (_jsx(Text, { style: formStyles.errorText, children: formErrors.nationality })) : null] }), _jsx(AgeSelector, { label: translations["car_form_driver_age"] || "Driver age", value: driverAge, onChange: setDriverAge, translations: translations }), _jsx(TouchableOpacity, { style: [
153
+ formStyles.searchButton,
154
+ { backgroundColor: colors?.primary || Colors.primary },
155
+ loading && formStyles.searchButtonDisabled,
156
+ ], onPress: handleSearchClick, disabled: loading, activeOpacity: 0.8, children: loading ? (_jsxs(View, { style: formStyles.searchButtonContent, children: [_jsx(ActivityIndicator, { size: "small", color: Colors.textOnPrimary }), _jsx(Text, { style: formStyles.searchButtonText, children: translations["car_form_searching"] || "Searching..." })] })) : (_jsx(Text, { style: formStyles.searchButtonText, children: translations["car_form_search"] || "Search cars" })) }), error ? _jsx(Text, { style: formStyles.searchError, children: error }) : null] }), !isPreview && hasSearched && (_jsx(SearchExpiredPopup, { isOpen: isCarSearchExpired, onRefresh: refreshCarSearch, onClose: closeCarSearchPopup, translations: translations, type: "car" }))] }));
157
+ };
158
+ const styles = StyleSheet.create({
159
+ container: {
160
+ flex: 1,
161
+ },
162
+ sameLocationRow: {
163
+ flexDirection: "row",
164
+ alignItems: "center",
165
+ gap: Spacing.sm,
166
+ },
167
+ sameLocationLabel: {
168
+ fontSize: FontSize.md,
169
+ color: Colors.text,
170
+ fontWeight: "500",
171
+ },
172
+ });
173
+ export default CarSearchForm;
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ type CarsSkeletonProps = {
3
+ translations: Record<string, string>;
4
+ };
5
+ declare const CarsSkeleton: React.FC<CarsSkeletonProps>;
6
+ export default CarsSkeleton;
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { View, StyleSheet } from "react-native";
3
+ import { Skeleton } from "../../../components/ui/Skeleton";
4
+ import { Colors, Spacing, BorderRadius } from "../../../theme/colors";
5
+ const CarsSkeleton = () => {
6
+ return (_jsx(View, { style: styles.container, children: [1, 2, 3, 4].map((i) => (_jsxs(View, { style: styles.card, children: [_jsxs(View, { style: styles.cardRow, children: [_jsx(View, { style: styles.imageCol, children: _jsx(Skeleton, { width: "100%", height: 100, borderRadius: BorderRadius.md }) }), _jsxs(View, { style: styles.contentCol, children: [_jsx(Skeleton, { width: 80, height: 12 }), _jsx(Skeleton, { width: "90%", height: 18, style: { marginTop: Spacing.sm } }), _jsxs(View, { style: styles.featuresRow, children: [_jsx(Skeleton, { width: 50, height: 14 }), _jsx(Skeleton, { width: 50, height: 14 }), _jsx(Skeleton, { width: 70, height: 14 })] }), _jsx(Skeleton, { width: "70%", height: 12, style: { marginTop: Spacing.sm } })] })] }), _jsxs(View, { style: styles.priceRow, children: [_jsx(Skeleton, { width: 100, height: 12 }), _jsx(Skeleton, { width: 80, height: 22 }), _jsx(Skeleton, { width: "100%", height: 42, borderRadius: BorderRadius.md, style: { marginTop: Spacing.sm } })] })] }, i))) }));
7
+ };
8
+ const styles = StyleSheet.create({
9
+ container: {
10
+ paddingHorizontal: Spacing.lg,
11
+ },
12
+ card: {
13
+ backgroundColor: Colors.surface,
14
+ borderRadius: BorderRadius.lg,
15
+ padding: Spacing.lg,
16
+ marginBottom: Spacing.md,
17
+ shadowColor: Colors.black,
18
+ shadowOffset: { width: 0, height: 2 },
19
+ shadowOpacity: 0.05,
20
+ shadowRadius: 4,
21
+ elevation: 2,
22
+ },
23
+ cardRow: {
24
+ flexDirection: "row",
25
+ gap: Spacing.md,
26
+ },
27
+ imageCol: {
28
+ width: 120,
29
+ },
30
+ contentCol: {
31
+ flex: 1,
32
+ },
33
+ featuresRow: {
34
+ flexDirection: "row",
35
+ gap: Spacing.sm,
36
+ marginTop: Spacing.sm,
37
+ },
38
+ priceRow: {
39
+ borderTopWidth: 1,
40
+ borderTopColor: Colors.borderLight,
41
+ paddingTop: Spacing.md,
42
+ marginTop: Spacing.lg,
43
+ alignItems: "center",
44
+ },
45
+ });
46
+ export default CarsSkeleton;
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ type CarOffer = {
3
+ offer_id: string;
4
+ car?: {
5
+ name?: string;
6
+ image?: string;
7
+ category?: string;
8
+ };
9
+ price?: {
10
+ total?: number;
11
+ currency?: string;
12
+ };
13
+ };
14
+ type Props = {
15
+ offers: CarOffer[];
16
+ onCategorySelect?: (category: string | null) => void;
17
+ translations?: Record<string, string>;
18
+ };
19
+ declare const CarTopOffersSlider: React.FC<Props>;
20
+ export default CarTopOffersSlider;
@@ -0,0 +1,100 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState, useCallback } from "react";
3
+ import { View, Text, TouchableOpacity, FlatList, Image, StyleSheet, Dimensions, } from "react-native";
4
+ import { useWidget } from "../../../context/WidgetContext";
5
+ import { Colors, Spacing, FontSize, BorderRadius } from "../../../theme/colors";
6
+ const SCREEN_WIDTH = Dimensions.get("window").width;
7
+ const CARD_WIDTH = SCREEN_WIDTH * 0.38;
8
+ const CARD_SPACING = Spacing.sm;
9
+ const CURRENCY_SIGNS = {
10
+ USD: "$",
11
+ EUR: "\u20AC",
12
+ GBP: "\u00A3",
13
+ CHF: "\u20A3",
14
+ };
15
+ const CarTopOffersSlider = ({ offers, onCategorySelect, translations = {}, }) => {
16
+ const { currency } = useWidget();
17
+ const [activeCategory, setActiveCategory] = useState(null);
18
+ const currencySign = CURRENCY_SIGNS[currency] || currency;
19
+ const bestByCategory = useMemo(() => {
20
+ const map = new Map();
21
+ offers.forEach((offer) => {
22
+ const rawCat = offer.car?.category?.toLowerCase();
23
+ if (!rawCat || rawCat === "other")
24
+ return;
25
+ const existing = map.get(rawCat);
26
+ if (!existing ||
27
+ (offer.price?.total || 0) < (existing.price?.total || Infinity)) {
28
+ map.set(rawCat, offer);
29
+ }
30
+ });
31
+ return Array.from(map.entries());
32
+ }, [offers]);
33
+ const handlePress = useCallback((cat) => {
34
+ const newCategory = activeCategory === cat ? null : cat;
35
+ setActiveCategory(newCategory);
36
+ onCategorySelect?.(newCategory);
37
+ }, [activeCategory, onCategorySelect]);
38
+ const renderItem = useCallback(({ item }) => {
39
+ const [category, offer] = item;
40
+ const cat = category.toLowerCase();
41
+ const car = offer.car || {};
42
+ const price = offer.price || {};
43
+ const isActive = activeCategory === cat;
44
+ return (_jsxs(TouchableOpacity, { style: [styles.card, isActive && styles.cardActive], onPress: () => handlePress(cat), activeOpacity: 0.8, children: [_jsx(Image, { source: { uri: car.image || undefined }, style: styles.cardImage, resizeMode: "contain" }), _jsxs(View, { style: styles.cardContent, children: [_jsx(Text, { style: styles.cardTitle, numberOfLines: 1, children: (translations[`car_category_${cat}`] ||
45
+ translations[cat] ||
46
+ cat).toUpperCase() }), _jsxs(Text, { style: styles.cardPrice, children: [currencySign, (price.total || 0).toFixed(2)] })] })] }));
47
+ }, [activeCategory, handlePress, currencySign, translations]);
48
+ const keyExtractor = useCallback((item) => item[0], []);
49
+ if (bestByCategory.length === 0)
50
+ return null;
51
+ return (_jsx(View, { style: styles.container, children: _jsx(FlatList, { data: bestByCategory, renderItem: renderItem, keyExtractor: keyExtractor, horizontal: true, showsHorizontalScrollIndicator: false, snapToInterval: CARD_WIDTH + CARD_SPACING, decelerationRate: "fast", contentContainerStyle: styles.listContent }) }));
52
+ };
53
+ const styles = StyleSheet.create({
54
+ container: {
55
+ marginVertical: Spacing.md,
56
+ },
57
+ listContent: {
58
+ paddingHorizontal: Spacing.lg,
59
+ gap: CARD_SPACING,
60
+ },
61
+ card: {
62
+ width: CARD_WIDTH,
63
+ backgroundColor: Colors.surface,
64
+ borderRadius: BorderRadius.lg,
65
+ overflow: "hidden",
66
+ borderWidth: 1,
67
+ borderColor: Colors.border,
68
+ shadowColor: Colors.black,
69
+ shadowOffset: { width: 0, height: 2 },
70
+ shadowOpacity: 0.05,
71
+ shadowRadius: 4,
72
+ elevation: 2,
73
+ },
74
+ cardActive: {
75
+ borderColor: Colors.primary,
76
+ backgroundColor: Colors.primaryLight,
77
+ },
78
+ cardImage: {
79
+ width: "100%",
80
+ height: 80,
81
+ backgroundColor: Colors.surfaceSecondary,
82
+ },
83
+ cardContent: {
84
+ padding: Spacing.sm,
85
+ alignItems: "center",
86
+ },
87
+ cardTitle: {
88
+ fontSize: FontSize.xs,
89
+ fontWeight: "600",
90
+ color: Colors.text,
91
+ marginBottom: Spacing.xs,
92
+ letterSpacing: 0.5,
93
+ },
94
+ cardPrice: {
95
+ fontSize: FontSize.md,
96
+ fontWeight: "700",
97
+ color: Colors.primary,
98
+ },
99
+ });
100
+ export default CarTopOffersSlider;
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ export type CarFiltersProps = {
3
+ offers: any[];
4
+ onFilterChange?: (filtered: any[]) => void;
5
+ onFiltersApplied?: () => void;
6
+ translations: Record<string, string>;
7
+ };
8
+ export declare const CarFilters: React.FC<CarFiltersProps>;