| 1 |
import { r as reactExports, j as jsxRuntimeExports, ax as X, x as ChevronDown, aO as Search, aA as Check } from "./react-vendor-xzSqHjRF.js"; |
| 2 |
import { _ as __, I as Input, o as __$1 } from "./index-CbMRo6lO.js"; |
| 3 |
import { B as Button } from "../../admin/dist/js/app.js"; |
| 4 |
const MultiSelect = ({ |
| 5 |
value, |
| 6 |
onChange, |
| 7 |
options, |
| 8 |
placeholder = __("Select options...", "yatra"), |
| 9 |
searchPlaceholder = __("Search...", "yatra"), |
| 10 |
className = "", |
| 11 |
error = false, |
| 12 |
disabled = false |
| 13 |
}) => { |
| 14 |
const [isOpen, setIsOpen] = reactExports.useState(false); |
| 15 |
const [searchTerm, setSearchTerm] = reactExports.useState(""); |
| 16 |
const containerRef = reactExports.useRef(null); |
| 17 |
const searchInputRef = reactExports.useRef(null); |
| 18 |
const filteredOptions = options.filter( |
| 19 |
(option) => option.label.toLowerCase().includes(searchTerm.toLowerCase()) |
| 20 |
); |
| 21 |
const selectedOptions = options.filter( |
| 22 |
(opt) => value.some((v) => String(v) === String(opt.value)) |
| 23 |
); |
| 24 |
reactExports.useEffect(() => { |
| 25 |
const handleClickOutside = (event) => { |
| 26 |
if (containerRef.current && !containerRef.current.contains(event.target)) { |
| 27 |
setIsOpen(false); |
| 28 |
setSearchTerm(""); |
| 29 |
} |
| 30 |
}; |
| 31 |
if (isOpen) { |
| 32 |
document.addEventListener("mousedown", handleClickOutside); |
| 33 |
setTimeout(() => { |
| 34 |
var _a; |
| 35 |
(_a = searchInputRef.current) == null ? void 0 : _a.focus(); |
| 36 |
}, 100); |
| 37 |
} |
| 38 |
return () => { |
| 39 |
document.removeEventListener("mousedown", handleClickOutside); |
| 40 |
}; |
| 41 |
}, [isOpen]); |
| 42 |
const handleToggle = (optionValue) => { |
| 43 |
const isSelected = value.some((v) => String(v) === String(optionValue)); |
| 44 |
if (isSelected) { |
| 45 |
onChange(value.filter((v) => String(v) !== String(optionValue))); |
| 46 |
} else { |
| 47 |
onChange([...value, optionValue]); |
| 48 |
} |
| 49 |
}; |
| 50 |
const handleRemove = (optionValue, e) => { |
| 51 |
e.stopPropagation(); |
| 52 |
onChange(value.filter((v) => String(v) !== String(optionValue))); |
| 53 |
}; |
| 54 |
const handleClearAll = (e) => { |
| 55 |
e.stopPropagation(); |
| 56 |
onChange([]); |
| 57 |
}; |
| 58 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 59 |
"div", |
| 60 |
{ |
| 61 |
ref: containerRef, |
| 62 |
className: `relative ${className}`, |
| 63 |
style: { zIndex: isOpen ? 9999 : "auto" }, |
| 64 |
children: [ |
| 65 |
/* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 66 |
"div", |
| 67 |
{ |
| 68 |
onClick: () => !disabled && setIsOpen(!isOpen), |
| 69 |
className: `flex min-h-11 w-full rounded-md border-2 ${error ? "border-red-500" : "border-gray-300 dark:border-gray-600"} bg-white dark:bg-gray-800 px-3 py-2 text-base ring-offset-white cursor-pointer focus-within:outline-none focus-within:ring-2 focus-within:ring-blue-500 focus-within:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:ring-offset-gray-900 dark:focus-within:ring-blue-400 transition-colors ${disabled ? "opacity-50 cursor-not-allowed" : ""}`, |
| 70 |
children: [ |
| 71 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1 flex flex-wrap gap-1.5 items-center", children: selectedOptions.length > 0 ? selectedOptions.map((option) => /* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 72 |
"span", |
| 73 |
{ |
| 74 |
className: "inline-flex items-center gap-1 px-2 py-0.5 rounded-md bg-blue-100 dark:bg-blue-900/40 text-blue-800 dark:text-blue-300 text-sm", |
| 75 |
children: [ |
| 76 |
option.label, |
| 77 |
!disabled && /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 78 |
"button", |
| 79 |
{ |
| 80 |
type: "button", |
| 81 |
onClick: (e) => handleRemove(option.value, e), |
| 82 |
className: "hover:bg-blue-200 dark:hover:bg-blue-800 rounded-full p-0.5", |
| 83 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx(X, { className: "w-3 h-3" }) |
| 84 |
} |
| 85 |
) |
| 86 |
] |
| 87 |
}, |
| 88 |
option.value |
| 89 |
)) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-500 dark:text-gray-400", children: placeholder }) }), |
| 90 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1 ml-2", children: [ |
| 91 |
value.length > 0 && !disabled && /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 92 |
"button", |
| 93 |
{ |
| 94 |
type: "button", |
| 95 |
onClick: handleClearAll, |
| 96 |
className: "p-0.5 hover:bg-gray-100 dark:hover:bg-gray-700 rounded", |
| 97 |
"aria-label": __("Clear all", "yatra"), |
| 98 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx(X, { className: "w-4 h-4 text-gray-400" }) |
| 99 |
} |
| 100 |
), |
| 101 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 102 |
ChevronDown, |
| 103 |
{ |
| 104 |
className: `w-4 h-4 text-gray-400 transition-transform ${isOpen ? "rotate-180" : ""}` |
| 105 |
} |
| 106 |
) |
| 107 |
] }) |
| 108 |
] |
| 109 |
} |
| 110 |
), |
| 111 |
isOpen && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "absolute z-[9999] w-full mt-1 bg-white dark:bg-gray-800 border-2 border-gray-300 dark:border-gray-600 rounded-md shadow-lg max-h-72 overflow-visible", children: [ |
| 112 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-2 border-b border-gray-200 dark:border-gray-700", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [ |
| 113 |
/* @__PURE__ */ jsxRuntimeExports.jsx(Search, { className: "absolute left-2.5 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400" }), |
| 114 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 115 |
Input, |
| 116 |
{ |
| 117 |
ref: searchInputRef, |
| 118 |
type: "text", |
| 119 |
placeholder: searchPlaceholder, |
| 120 |
value: searchTerm, |
| 121 |
onChange: (e) => setSearchTerm(e.target.value), |
| 122 |
className: "pl-8 h-9", |
| 123 |
onClick: (e) => e.stopPropagation() |
| 124 |
} |
| 125 |
) |
| 126 |
] }) }), |
| 127 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "max-h-52 overflow-y-auto", children: filteredOptions.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-3 py-3 text-sm text-gray-500 dark:text-gray-400 text-center", children: __("No options found", "yatra") }) : filteredOptions.map((option) => { |
| 128 |
const isSelected = value.some( |
| 129 |
(v) => String(v) === String(option.value) |
| 130 |
); |
| 131 |
return /* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 132 |
"button", |
| 133 |
{ |
| 134 |
type: "button", |
| 135 |
onClick: () => handleToggle(option.value), |
| 136 |
className: `w-full px-3 py-2.5 text-left text-sm flex items-center justify-between hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors ${isSelected ? "bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-400" : "text-gray-900 dark:text-white"}`, |
| 137 |
children: [ |
| 138 |
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: option.label }), |
| 139 |
isSelected && /* @__PURE__ */ jsxRuntimeExports.jsx(Check, { className: "w-4 h-4 text-blue-600 dark:text-blue-400" }) |
| 140 |
] |
| 141 |
}, |
| 142 |
option.value |
| 143 |
); |
| 144 |
}) }), |
| 145 |
value.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-3 py-2 border-t border-gray-200 dark:border-gray-700 text-xs text-gray-500 dark:text-gray-400", children: [ |
| 146 |
value.length, |
| 147 |
" ", |
| 148 |
value.length === 1 ? __("selected", "yatra") : __("selected", "yatra") |
| 149 |
] }) |
| 150 |
] }) |
| 151 |
] |
| 152 |
} |
| 153 |
); |
| 154 |
}; |
| 155 |
const ProBadge = ({ isProActive }) => { |
| 156 |
if (!isProActive) { |
| 157 |
return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gradient-to-r from-purple-500 to-blue-500 text-white", children: "PRO" }); |
| 158 |
} |
| 159 |
return null; |
| 160 |
}; |
| 161 |
const ProFeature = ({ |
| 162 |
title, |
| 163 |
description, |
| 164 |
moduleName, |
| 165 |
pricingUrl, |
| 166 |
isProActive, |
| 167 |
isModuleEnabled, |
| 168 |
children |
| 169 |
}) => { |
| 170 |
const modulesPageUrl = reactExports.useMemo(() => { |
| 171 |
var _a; |
| 172 |
const baseUrl = ((_a = window.yatraAdmin) == null ? void 0 : _a.siteUrl) ? `${window.yatraAdmin.siteUrl}/wp-admin/admin.php?page=yatra` : "/wp-admin/admin.php?page=yatra"; |
| 173 |
return `${baseUrl}&subpage=modules`; |
| 174 |
}, []); |
| 175 |
if (isProActive && isModuleEnabled) { |
| 176 |
return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children }); |
| 177 |
} |
| 178 |
if (isProActive && !isModuleEnabled) { |
| 179 |
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 bg-gradient-to-r from-amber-50 to-orange-50 dark:from-amber-900/20 dark:to-orange-900/20 rounded-lg border border-amber-200 dark:border-amber-800", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-3", children: [ |
| 180 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 181 |
"svg", |
| 182 |
{ |
| 183 |
className: "w-6 h-6 text-amber-500", |
| 184 |
fill: "none", |
| 185 |
stroke: "currentColor", |
| 186 |
viewBox: "0 0 24 24", |
| 187 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 188 |
"path", |
| 189 |
{ |
| 190 |
strokeLinecap: "round", |
| 191 |
strokeLinejoin: "round", |
| 192 |
strokeWidth: 2, |
| 193 |
d: "M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4" |
| 194 |
} |
| 195 |
) |
| 196 |
} |
| 197 |
) }), |
| 198 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [ |
| 199 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("h4", { className: "text-sm font-semibold text-amber-900 dark:text-amber-100", children: [ |
| 200 |
__$1("Please activate", "yatra"), |
| 201 |
" ", |
| 202 |
moduleName |
| 203 |
] }), |
| 204 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-amber-700 dark:text-amber-300 mt-1", children: [ |
| 205 |
__$1("You have Yatra Pro installed. Enable the", "yatra"), |
| 206 |
" ", |
| 207 |
moduleName, |
| 208 |
" ", |
| 209 |
__$1("module to access", "yatra"), |
| 210 |
" ", |
| 211 |
description.toLowerCase(), |
| 212 |
" ", |
| 213 |
__$1("features.", "yatra") |
| 214 |
] }), |
| 215 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 216 |
Button, |
| 217 |
{ |
| 218 |
type: "button", |
| 219 |
onClick: () => window.open(modulesPageUrl, "_blank"), |
| 220 |
className: "mt-3 bg-amber-600 hover:bg-amber-700 text-white", |
| 221 |
children: __$1("Activate Module", "yatra") |
| 222 |
} |
| 223 |
) |
| 224 |
] }) |
| 225 |
] }) }); |
| 226 |
} |
| 227 |
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 bg-gradient-to-r from-purple-50 to-blue-50 dark:from-purple-900/20 dark:to-blue-900/20 border border-purple-200 dark:border-purple-800 rounded-lg", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start gap-3", children: [ |
| 228 |
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 229 |
"svg", |
| 230 |
{ |
| 231 |
className: "w-6 h-6 text-purple-500", |
| 232 |
fill: "none", |
| 233 |
stroke: "currentColor", |
| 234 |
viewBox: "0 0 24 24", |
| 235 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 236 |
"path", |
| 237 |
{ |
| 238 |
strokeLinecap: "round", |
| 239 |
strokeLinejoin: "round", |
| 240 |
strokeWidth: 2, |
| 241 |
d: "M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" |
| 242 |
} |
| 243 |
) |
| 244 |
} |
| 245 |
) }), |
| 246 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [ |
| 247 |
/* @__PURE__ */ jsxRuntimeExports.jsxs("h4", { className: "text-sm font-semibold text-purple-900 dark:text-purple-100", children: [ |
| 248 |
__$1("Upgrade to Pro for", "yatra"), |
| 249 |
" ", |
| 250 |
moduleName |
| 251 |
] }), |
| 252 |
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-purple-700 dark:text-purple-300 mt-1", children: __$1( |
| 253 |
`Get Yatra Pro to access ${description} and unlock all premium features.`, |
| 254 |
"yatra" |
| 255 |
) }), |
| 256 |
/* @__PURE__ */ jsxRuntimeExports.jsxs( |
| 257 |
"a", |
| 258 |
{ |
| 259 |
href: pricingUrl, |
| 260 |
target: "_blank", |
| 261 |
rel: "noopener noreferrer", |
| 262 |
className: "inline-flex items-center gap-2 mt-3 px-4 py-2 bg-gradient-to-r from-purple-600 to-blue-600 text-white rounded-lg text-sm font-medium hover:from-purple-700 hover:to-blue-700 transition-all", |
| 263 |
children: [ |
| 264 |
__$1("Upgrade to Pro", "yatra"), |
| 265 |
/* @__PURE__ */ jsxRuntimeExports.jsx( |
| 266 |
"svg", |
| 267 |
{ |
| 268 |
className: "w-4 h-4", |
| 269 |
fill: "none", |
| 270 |
stroke: "currentColor", |
| 271 |
viewBox: "0 0 24 24", |
| 272 |
children: /* @__PURE__ */ jsxRuntimeExports.jsx( |
| 273 |
"path", |
| 274 |
{ |
| 275 |
strokeLinecap: "round", |
| 276 |
strokeLinejoin: "round", |
| 277 |
strokeWidth: 2, |
| 278 |
d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" |
| 279 |
} |
| 280 |
) |
| 281 |
} |
| 282 |
) |
| 283 |
] |
| 284 |
} |
| 285 |
) |
| 286 |
] }) |
| 287 |
] }) }); |
| 288 |
}; |
| 289 |
export { |
| 290 |
MultiSelect as M, |
| 291 |
ProBadge as P, |
| 292 |
ProFeature as a |
| 293 |
}; |
| 294 |
//# sourceMappingURL=ProFeature-97ewna1x.js.map |
| 295 |
|