admin-lib-cms 1.2.7 → 1.2.8

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.
package/dist/index.mjs CHANGED
@@ -788,6 +788,8 @@ function EditableReference({
788
788
 
789
789
  // src/admin/AdminApp.tsx
790
790
  import { createElement as createElement2, useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as useState5 } from "react";
791
+ import { ConfigProvider, Modal, TimePicker } from "antd";
792
+ import dayjs from "dayjs";
791
793
  import {
792
794
  FileText,
793
795
  Boxes,
@@ -820,6 +822,67 @@ import {
820
822
  } from "lucide-react";
821
823
  import { CreditCard as CreditCard2, BarChart3 } from "lucide-react";
822
824
  import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
825
+ var TIME_STORAGE_FORMAT = "HH:mm";
826
+ var TIME_DISPLAY_FORMAT = "h:mm A";
827
+ var TIME_PICKER_THEME = {
828
+ token: {
829
+ borderRadius: 12,
830
+ colorBgContainer: "#ffffff",
831
+ colorBorder: "#e2e8f0",
832
+ colorPrimary: "#6366f1",
833
+ colorText: "#1e293b",
834
+ colorTextPlaceholder: "#94a3b8",
835
+ controlHeight: 42,
836
+ controlOutline: "rgba(99, 102, 241, 0.1)",
837
+ fontFamily: "inherit",
838
+ fontSize: 14,
839
+ lineWidth: 1
840
+ },
841
+ components: {
842
+ DatePicker: {
843
+ activeBorderColor: "#6366f1",
844
+ activeShadow: "0 0 0 4px rgba(99, 102, 241, 0.1)",
845
+ hoverBg: "#ffffff",
846
+ hoverBorderColor: "#cbd5e1",
847
+ paddingBlock: 9,
848
+ paddingInline: 14
849
+ }
850
+ }
851
+ };
852
+ function AdminTimeRangePicker(props) {
853
+ return /* @__PURE__ */ jsx5(ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ jsx5(
854
+ TimePicker.RangePicker,
855
+ {
856
+ ...props,
857
+ className: `w-full min-w-0 ${props.className ?? ""}`,
858
+ style: {
859
+ boxShadow: "0 1px 2px rgba(15, 23, 42, 0.08)",
860
+ ...props.style
861
+ }
862
+ }
863
+ ) });
864
+ }
865
+ function AdminTimePicker(props) {
866
+ return /* @__PURE__ */ jsx5(ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ jsx5(
867
+ TimePicker,
868
+ {
869
+ ...props,
870
+ className: `w-full min-w-0 ${props.className ?? ""}`,
871
+ style: {
872
+ boxShadow: "0 1px 2px rgba(15, 23, 42, 0.08)",
873
+ ...props.style
874
+ }
875
+ }
876
+ ) });
877
+ }
878
+ function toDayjsTime(value) {
879
+ const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(String(value ?? ""));
880
+ if (!match) return null;
881
+ return dayjs().hour(Number(match[1])).minute(Number(match[2])).second(0).millisecond(0);
882
+ }
883
+ function toStoredTime(value) {
884
+ return value?.format(TIME_STORAGE_FORMAT) ?? "";
885
+ }
823
886
  async function handleImageFile(file, onUrl, uploadImage) {
824
887
  if (uploadImage) {
825
888
  try {
@@ -834,6 +897,40 @@ async function handleImageFile(file, onUrl, uploadImage) {
834
897
  reader.onload = (ev) => onUrl(ev.target?.result);
835
898
  reader.readAsDataURL(file);
836
899
  }
900
+ function FilePickerButton({
901
+ accept,
902
+ children,
903
+ className,
904
+ multiple = false,
905
+ onFiles
906
+ }) {
907
+ const inputRef = useRef2(null);
908
+ return /* @__PURE__ */ jsxs4(Fragment4, { children: [
909
+ /* @__PURE__ */ jsx5(
910
+ "button",
911
+ {
912
+ type: "button",
913
+ onClick: () => inputRef.current?.click(),
914
+ className,
915
+ children
916
+ }
917
+ ),
918
+ /* @__PURE__ */ jsx5(
919
+ "input",
920
+ {
921
+ ref: inputRef,
922
+ type: "file",
923
+ accept,
924
+ multiple,
925
+ className: "hidden",
926
+ onChange: (event) => {
927
+ onFiles(Array.from(event.currentTarget.files ?? []));
928
+ event.currentTarget.value = "";
929
+ }
930
+ }
931
+ )
932
+ ] });
933
+ }
837
934
  function AdminApp(props) {
838
935
  if (props.projectId) {
839
936
  return /* @__PURE__ */ jsx5(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: /* @__PURE__ */ jsx5(AdminAppContent, { ...props }) });
@@ -848,6 +945,7 @@ function AdminAppContent(props) {
848
945
  const [authenticated, setAuthenticated] = useState5(false);
849
946
  const hideSettings = props.hideSettings ?? ctx.config.hideSettings ?? false;
850
947
  const hideData = props.hideData ?? ctx.config.hideData ?? false;
948
+ const hideGlobals = props.hideGlobals ?? ctx.config.hideGlobals ?? false;
851
949
  const hideConfig = props.hideConfig ?? ctx.config.hideConfig ?? false;
852
950
  const menuLabels = {
853
951
  dashboard: "Dashboard",
@@ -945,7 +1043,7 @@ function AdminAppContent(props) {
945
1043
  children: menuLabels.data
946
1044
  }
947
1045
  ),
948
- !hideConfig && /* @__PURE__ */ jsx5(
1046
+ !hideConfig && !hideGlobals && /* @__PURE__ */ jsx5(
949
1047
  SideItem,
950
1048
  {
951
1049
  active: section === "config",
@@ -973,33 +1071,27 @@ function AdminAppContent(props) {
973
1071
  }
974
1072
  )
975
1073
  ] }),
976
- /* @__PURE__ */ jsxs4("div", { className: "hidden lg:block mt-auto border-t border-slate-200 p-4 bg-slate-50/50", children: [
977
- /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between text-xs text-slate-500 mb-4", children: [
978
- /* @__PURE__ */ jsx5("span", { children: "Storage Adapter" }),
979
- /* @__PURE__ */ jsx5("span", { className: "font-semibold px-2 py-0.5 rounded-full bg-slate-200 text-slate-700", children: ctx.adapter.name })
980
- ] }),
981
- /* @__PURE__ */ jsxs4(
982
- "button",
983
- {
984
- onClick: async () => {
985
- await fetch("/api/admin/auth?action=logout", { method: "POST" });
986
- window.location.href = "/admin/login";
987
- },
988
- className: "flex items-center justify-center gap-2 w-full px-3 py-2 text-sm font-medium text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",
989
- children: [
990
- /* @__PURE__ */ jsx5(LogOut, { className: "w-4 h-4" }),
991
- "Logout"
992
- ]
993
- }
994
- )
995
- ] })
1074
+ /* @__PURE__ */ jsx5("div", { className: "hidden lg:block mt-auto border-t border-slate-200 p-4 bg-slate-50/50", children: /* @__PURE__ */ jsxs4(
1075
+ "button",
1076
+ {
1077
+ onClick: async () => {
1078
+ await fetch("/api/admin/auth?action=logout", { method: "POST" });
1079
+ window.location.href = "/admin/login";
1080
+ },
1081
+ className: "flex items-center justify-center gap-2 w-full px-3 py-2 text-sm font-medium text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",
1082
+ children: [
1083
+ /* @__PURE__ */ jsx5(LogOut, { className: "w-4 h-4" }),
1084
+ "Logout"
1085
+ ]
1086
+ }
1087
+ ) })
996
1088
  ] }),
997
1089
  /* @__PURE__ */ jsxs4("main", { className: "flex-1 overflow-hidden relative flex flex-col", children: [
998
1090
  section === "dashboard" && hasDashboard && (typeof props.dashboard === "function" ? createElement2(props.dashboard) : props.dashboard),
999
1091
  section === "pages" && /* @__PURE__ */ jsx5(PagesSection, {}),
1000
1092
  section === "collections" && /* @__PURE__ */ jsx5(CollectionsSection, {}),
1001
1093
  !hideData && section === "submissions" && /* @__PURE__ */ jsx5(SubmissionsSection, {}),
1002
- !hideConfig && section === "config" && /* @__PURE__ */ jsx5(ConfigSection, {}),
1094
+ !hideConfig && !hideGlobals && section === "config" && /* @__PURE__ */ jsx5(ConfigSection, {}),
1003
1095
  !hideSettings && section === "settings" && /* @__PURE__ */ jsx5(SettingsSection, {}),
1004
1096
  section === "subscription" && /* @__PURE__ */ jsx5(SubscriptionPage, {})
1005
1097
  ] })
@@ -2141,8 +2233,22 @@ function CollectionEditor({ collection }) {
2141
2233
  collection.fields.forEach((f) => {
2142
2234
  if (f.id === "order") {
2143
2235
  base[f.id] = entries.length;
2236
+ } else if (f.type === "time-range") {
2237
+ if (f.startField) base[f.startField] = "";
2238
+ if (f.endField) base[f.endField] = "";
2144
2239
  } else if (f.defaultValue !== void 0) {
2145
2240
  base[f.id] = f.defaultValue;
2241
+ } else if (f.type === "branch-settings") {
2242
+ base[f.id] = {
2243
+ allBranches: true,
2244
+ branches: [],
2245
+ useBranchPricing: false,
2246
+ priceBranches: [],
2247
+ prices: {},
2248
+ useBranchDiscounts: false,
2249
+ discountBranches: [],
2250
+ discounts: {}
2251
+ };
2146
2252
  } else if (f.multiple) {
2147
2253
  base[f.id] = [];
2148
2254
  } else {
@@ -2157,7 +2263,9 @@ function CollectionEditor({ collection }) {
2157
2263
  try {
2158
2264
  const finalEditing = { ...editing };
2159
2265
  collection.fields.forEach((f) => {
2160
- if (f.type === "slug" && !finalEditing[f.id]) {
2266
+ if (f.type === "time-range") {
2267
+ delete finalEditing[f.id];
2268
+ } else if (f.type === "slug" && !finalEditing[f.id]) {
2161
2269
  const sourceField = f.source || "title";
2162
2270
  let val = String(finalEditing[sourceField] || finalEditing.id || "");
2163
2271
  val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
@@ -2218,6 +2326,7 @@ function CollectionEditor({ collection }) {
2218
2326
  setDragOverIdx(null);
2219
2327
  };
2220
2328
  const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 5);
2329
+ const isCreatingEntry = editing ? !entries.some((entry) => entry.id === editing.id) : false;
2221
2330
  return /* @__PURE__ */ jsxs4("div", { className: "mx-auto max-w-5xl", children: [
2222
2331
  /* @__PURE__ */ jsxs4("div", { className: "mb-8 flex items-center justify-between", children: [
2223
2332
  /* @__PURE__ */ jsxs4("div", { children: [
@@ -2280,266 +2389,298 @@ function CollectionEditor({ collection }) {
2280
2389
  ] }, f);
2281
2390
  })
2282
2391
  ] }),
2283
- editing && /* @__PURE__ */ jsxs4("div", { className: "mb-8 rounded-2xl border border-indigo-100 bg-white p-6 shadow-xl shadow-indigo-100/50 animate-in fade-in slide-in-from-top-4", children: [
2284
- /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 mb-6", children: [
2285
- /* @__PURE__ */ jsx5("div", { className: "w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600", children: /* @__PURE__ */ jsx5(Pencil, { className: "w-4 h-4" }) }),
2286
- /* @__PURE__ */ jsx5("h3", { className: "text-lg font-bold text-slate-900", children: "Edit Entry" })
2287
- ] }),
2288
- /* @__PURE__ */ jsx5("div", { className: "grid gap-5 md:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order" && !f.hidden).map((f) => /* @__PURE__ */ jsxs4("label", { className: `block ${f.type === "richtext" ? "md:col-span-2" : ""}`, children: [
2289
- /* @__PURE__ */ jsxs4("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
2290
- f.label,
2291
- /* @__PURE__ */ jsx5("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
2392
+ /* @__PURE__ */ jsx5(
2393
+ Modal,
2394
+ {
2395
+ open: Boolean(editing),
2396
+ title: /* @__PURE__ */ jsxs4("span", { className: "flex items-center gap-2 text-slate-900", children: [
2397
+ isCreatingEntry ? /* @__PURE__ */ jsx5(Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ jsx5(Pencil, { className: "h-4 w-4 text-indigo-600" }),
2398
+ isCreatingEntry ? "Create Entry" : "Edit Entry"
2292
2399
  ] }),
2293
- f.type === "boolean" ? /* @__PURE__ */ jsx5("div", { className: "mt-1 h-10 flex items-center", children: /* @__PURE__ */ jsx5(
2294
- "input",
2295
- {
2296
- type: "checkbox",
2297
- checked: !!editing[f.id],
2298
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.checked }),
2299
- className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
2300
- }
2301
- ) }) : f.type === "number" ? /* @__PURE__ */ jsx5(
2302
- FormattedNumberInput,
2303
- {
2304
- value: editing[f.id],
2305
- onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2306
- isPrice: f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.toLowerCase().includes("valor") || f.label.includes("$")
2307
- }
2308
- ) : f.type === "richtext" ? /* @__PURE__ */ jsx5(
2309
- "textarea",
2310
- {
2311
- value: String(editing[f.id] ?? ""),
2312
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2313
- rows: 4,
2314
- className: "w-full rounded-xl border border-slate-200 px-4 py-3 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all font-mono text-xs"
2315
- }
2316
- ) : f.type === "icon" ? /* @__PURE__ */ jsx5(
2317
- SearchableSelect,
2318
- {
2319
- value: String(editing[f.id] ?? ""),
2320
- onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2321
- options: f.options || [],
2322
- placeholder: `Search ${f.label.toLowerCase()}...`,
2323
- iconMap: ctx.iconMap
2324
- }
2325
- ) : f.type === "slug" ? /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
2326
- /* @__PURE__ */ jsx5(
2327
- "input",
2328
- {
2329
- type: "text",
2330
- value: String(editing[f.id] ?? ""),
2331
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2332
- className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
2333
- }
2334
- ),
2335
- /* @__PURE__ */ jsx5(
2336
- "button",
2337
- {
2338
- type: "button",
2339
- onClick: () => {
2340
- const sourceField = f.source || "title";
2341
- let val = String(editing[sourceField] || editing.id || "");
2342
- val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
2343
- setEditing({ ...editing, [f.id]: val });
2344
- },
2345
- className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
2346
- children: "Generate"
2347
- }
2348
- )
2349
- ] }) : f.type === "reference" || f.type === "select" && f.collection ? /* @__PURE__ */ jsx5(
2350
- ReferenceSelect,
2351
- {
2352
- collectionId: f.collection,
2353
- displayField: f.displayField,
2354
- valueField: f.valueField,
2355
- fallbackOptions: f.options,
2356
- multiple: f.multiple,
2357
- max: f.max,
2358
- value: editing[f.id],
2359
- onChange: (val) => setEditing({ ...editing, [f.id]: val })
2400
+ onCancel: () => {
2401
+ if (!saving) setEditing(null);
2402
+ },
2403
+ footer: null,
2404
+ centered: true,
2405
+ width: "min(900px, calc(100vw - 32px))",
2406
+ mask: { blur: true },
2407
+ keyboard: !saving,
2408
+ closable: !saving,
2409
+ styles: {
2410
+ body: {
2411
+ maxHeight: "calc(100dvh - 180px)",
2412
+ display: "flex",
2413
+ flexDirection: "column",
2414
+ overflow: "hidden",
2415
+ padding: 0
2416
+ },
2417
+ mask: {
2418
+ backgroundColor: "rgba(15, 23, 42, 0.82)",
2419
+ backdropFilter: "blur(8px)"
2360
2420
  }
2361
- ) : f.type === "select" ? /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
2362
- /* @__PURE__ */ jsxs4(
2363
- "select",
2364
- {
2365
- value: String(editing[f.id] ?? ""),
2366
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2367
- className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all bg-white appearance-none pr-10 cursor-pointer text-slate-800",
2368
- children: [
2369
- /* @__PURE__ */ jsx5("option", { value: "", children: "-- Selecciona una opci\xF3n --" }),
2370
- f.options?.map((opt) => {
2371
- const val = typeof opt === "string" ? opt : opt.value;
2372
- const lab = typeof opt === "string" ? opt : opt.label;
2373
- return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
2374
- })
2375
- ]
2376
- }
2377
- ),
2378
- /* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
2379
- ] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2380
- /* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
2381
- const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
2382
- return /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
2383
- isVideo ? /* @__PURE__ */ jsx5("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ jsx5("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
2384
- /* @__PURE__ */ jsx5(
2385
- "button",
2386
- {
2387
- type: "button",
2388
- onClick: () => {
2389
- const arr = [...editing[f.id] || []];
2390
- arr.splice(i, 1);
2391
- setEditing({ ...editing, [f.id]: arr });
2392
- },
2393
- className: "absolute top-2 right-2 bg-red-500/80 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500",
2394
- children: /* @__PURE__ */ jsx5(X, { className: "w-3 h-3" })
2395
- }
2396
- )
2397
- ] }, i);
2398
- }) }),
2399
- (!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
2400
- /* @__PURE__ */ jsx5(
2421
+ },
2422
+ children: editing && /* @__PURE__ */ jsxs4("div", { className: "flex max-h-[calc(100dvh-180px)] min-h-0 flex-col", children: [
2423
+ /* @__PURE__ */ jsx5("div", { className: "min-h-0 flex-1 overflow-y-auto px-6 py-5", children: /* @__PURE__ */ jsx5("div", { className: "grid grid-cols-1 gap-5 lg:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order" && !f.hidden).map((f) => /* @__PURE__ */ jsxs4("div", { className: `block ${f.type === "richtext" || f.type === "branch-settings" || f.type === "time-range" ? "lg:col-span-2" : ""}`, children: [
2424
+ /* @__PURE__ */ jsxs4("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
2425
+ f.label,
2426
+ /* @__PURE__ */ jsx5("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
2427
+ ] }),
2428
+ f.type === "branch-settings" ? /* @__PURE__ */ jsx5(
2429
+ BranchSettingsEditor,
2430
+ {
2431
+ collectionId: f.collection || "",
2432
+ value: editing[f.id],
2433
+ globalPrice: Number(editing.price) || 0,
2434
+ globalDiscount: Number(editing.discountPercent) || 0,
2435
+ onChange: (val) => setEditing({ ...editing, [f.id]: val })
2436
+ }
2437
+ ) : f.type === "boolean" ? /* @__PURE__ */ jsx5("div", { className: "mt-1 h-10 flex items-center", children: /* @__PURE__ */ jsx5(
2401
2438
  "input",
2402
2439
  {
2403
- type: "url",
2404
- placeholder: "Add media URL and press Enter...",
2405
- onKeyDown: (e) => {
2406
- if (e.key === "Enter" && e.currentTarget.value) {
2407
- e.preventDefault();
2408
- const arr = [...editing[f.id] || [], e.currentTarget.value];
2409
- setEditing({ ...editing, [f.id]: arr });
2410
- e.currentTarget.value = "";
2411
- }
2412
- },
2413
- className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2440
+ type: "checkbox",
2441
+ checked: !!editing[f.id],
2442
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.checked }),
2443
+ className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
2414
2444
  }
2415
- ),
2416
- /* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
2417
- "Upload",
2445
+ ) }) : f.type === "number" ? /* @__PURE__ */ jsx5(
2446
+ FormattedNumberInput,
2447
+ {
2448
+ value: editing[f.id],
2449
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2450
+ isPrice: f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.toLowerCase().includes("valor") || f.label.includes("$"),
2451
+ isPercent: f.id.toLowerCase().includes("discount") || f.id.toLowerCase().includes("descuento") || f.label.toLowerCase().includes("descuento")
2452
+ }
2453
+ ) : f.type === "time-range" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-1.5", children: [
2418
2454
  /* @__PURE__ */ jsx5(
2419
- "input",
2455
+ AdminTimeRangePicker,
2420
2456
  {
2421
- type: "file",
2422
- accept: "image/*,video/*",
2423
- multiple: true,
2424
- className: "hidden",
2425
- onChange: (e) => {
2426
- const files = Array.from(e.target.files || []);
2427
- files.forEach((file) => {
2428
- void handleImageFile(
2429
- file,
2430
- (url) => {
2431
- setEditing((prev) => {
2432
- if (!prev) return prev;
2433
- const current = prev[f.id] || [];
2434
- if (f.max && current.length >= f.max) return prev;
2435
- return { ...prev, [f.id]: [...current, url] };
2436
- });
2437
- },
2438
- ctx.uploadImage
2439
- );
2440
- });
2441
- }
2457
+ value: [
2458
+ toDayjsTime(f.startField ? editing[f.startField] : ""),
2459
+ toDayjsTime(f.endField ? editing[f.endField] : "")
2460
+ ],
2461
+ onChange: (times) => setEditing(
2462
+ (current) => current ? {
2463
+ ...current,
2464
+ ...f.startField ? { [f.startField]: toStoredTime(times?.[0]) } : {},
2465
+ ...f.endField ? { [f.endField]: toStoredTime(times?.[1]) } : {}
2466
+ } : current
2467
+ ),
2468
+ allowEmpty: [true, true],
2469
+ className: "w-full",
2470
+ format: TIME_DISPLAY_FORMAT,
2471
+ order: false,
2472
+ placeholder: ["Hora de inicio", "Hora de cierre"],
2473
+ use12Hours: true
2442
2474
  }
2443
- )
2444
- ] })
2445
- ] })
2446
- ] }) : /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2447
- /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
2448
- /* @__PURE__ */ jsx5(
2449
- "input",
2475
+ ),
2476
+ /* @__PURE__ */ jsx5("p", { className: "text-xs text-slate-500", children: "Selecciona inicio y cierre en un mismo control. Usa AM/PM; si el cierre es anterior al inicio, el horario cruza medianoche. Deja ambos vac\xEDos para mantenerlo siempre disponible." })
2477
+ ] }) : f.type === "time" ? /* @__PURE__ */ jsx5(
2478
+ AdminTimePicker,
2479
+ {
2480
+ value: toDayjsTime(editing[f.id]),
2481
+ onChange: (time) => setEditing({ ...editing, [f.id]: toStoredTime(time) }),
2482
+ className: "w-full",
2483
+ format: TIME_DISPLAY_FORMAT,
2484
+ use12Hours: true
2485
+ }
2486
+ ) : f.type === "richtext" ? /* @__PURE__ */ jsx5(
2487
+ "textarea",
2450
2488
  {
2451
- type: "url",
2452
2489
  value: String(editing[f.id] ?? ""),
2453
2490
  onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2454
- placeholder: "https://...",
2455
- className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2491
+ rows: 4,
2492
+ className: "w-full rounded-xl border border-slate-200 px-4 py-3 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all font-mono text-xs"
2456
2493
  }
2457
- ),
2458
- /* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
2459
- "Upload",
2494
+ ) : f.type === "icon" ? /* @__PURE__ */ jsx5(
2495
+ SearchableSelect,
2496
+ {
2497
+ value: String(editing[f.id] ?? ""),
2498
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2499
+ options: f.options || [],
2500
+ placeholder: `Search ${f.label.toLowerCase()}...`,
2501
+ iconMap: ctx.iconMap
2502
+ }
2503
+ ) : f.type === "slug" ? /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
2460
2504
  /* @__PURE__ */ jsx5(
2461
2505
  "input",
2462
2506
  {
2463
- type: "file",
2464
- accept: "image/*,video/*",
2465
- className: "hidden",
2466
- onChange: (e) => {
2467
- const file = e.target.files?.[0];
2468
- if (file) {
2469
- void handleImageFile(
2470
- file,
2471
- (url) => setEditing({ ...editing, [f.id]: url }),
2472
- ctx.uploadImage
2473
- );
2507
+ type: "text",
2508
+ value: String(editing[f.id] ?? ""),
2509
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2510
+ className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
2511
+ }
2512
+ ),
2513
+ /* @__PURE__ */ jsx5(
2514
+ "button",
2515
+ {
2516
+ type: "button",
2517
+ onClick: () => {
2518
+ const sourceField = f.source || "title";
2519
+ let val = String(editing[sourceField] || editing.id || "");
2520
+ val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
2521
+ setEditing({ ...editing, [f.id]: val });
2522
+ },
2523
+ className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
2524
+ children: "Generate"
2525
+ }
2526
+ )
2527
+ ] }) : f.type === "reference" || f.type === "select" && f.collection ? /* @__PURE__ */ jsx5(
2528
+ ReferenceSelect,
2529
+ {
2530
+ collectionId: f.collection,
2531
+ displayField: f.displayField,
2532
+ valueField: f.valueField,
2533
+ fallbackOptions: f.options,
2534
+ multiple: f.multiple,
2535
+ searchable: f.searchable,
2536
+ max: f.max,
2537
+ value: editing[f.id],
2538
+ onChange: (val) => setEditing({ ...editing, [f.id]: val })
2539
+ }
2540
+ ) : f.type === "select" ? /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
2541
+ /* @__PURE__ */ jsxs4(
2542
+ "select",
2543
+ {
2544
+ value: String(editing[f.id] ?? ""),
2545
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2546
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all bg-white appearance-none pr-10 cursor-pointer text-slate-800",
2547
+ children: [
2548
+ /* @__PURE__ */ jsx5("option", { value: "", children: "-- Selecciona una opci\xF3n --" }),
2549
+ f.options?.map((opt) => {
2550
+ const val = typeof opt === "string" ? opt : opt.value;
2551
+ const lab = typeof opt === "string" ? opt : opt.label;
2552
+ return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
2553
+ })
2554
+ ]
2555
+ }
2556
+ ),
2557
+ /* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
2558
+ ] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2559
+ /* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
2560
+ const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
2561
+ return /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
2562
+ isVideo ? /* @__PURE__ */ jsx5("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ jsx5("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
2563
+ /* @__PURE__ */ jsx5(
2564
+ "button",
2565
+ {
2566
+ type: "button",
2567
+ onClick: () => {
2568
+ const arr = [...editing[f.id] || []];
2569
+ arr.splice(i, 1);
2570
+ setEditing({ ...editing, [f.id]: arr });
2571
+ },
2572
+ className: "absolute top-2 right-2 bg-red-500/80 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500",
2573
+ children: /* @__PURE__ */ jsx5(X, { className: "w-3 h-3" })
2474
2574
  }
2575
+ )
2576
+ ] }, i);
2577
+ }) }),
2578
+ (!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
2579
+ /* @__PURE__ */ jsx5(
2580
+ "input",
2581
+ {
2582
+ type: "url",
2583
+ placeholder: "Add media URL and press Enter...",
2584
+ onKeyDown: (e) => {
2585
+ if (e.key === "Enter" && e.currentTarget.value) {
2586
+ e.preventDefault();
2587
+ const arr = [...editing[f.id] || [], e.currentTarget.value];
2588
+ setEditing({ ...editing, [f.id]: arr });
2589
+ e.currentTarget.value = "";
2590
+ }
2591
+ },
2592
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2593
+ }
2594
+ ),
2595
+ /* @__PURE__ */ jsx5(
2596
+ FilePickerButton,
2597
+ {
2598
+ accept: "image/*,video/*",
2599
+ multiple: true,
2600
+ className: "flex-shrink-0 cursor-pointer rounded-xl border border-slate-200 bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-200",
2601
+ onFiles: (files) => {
2602
+ files.forEach((file) => {
2603
+ void handleImageFile(
2604
+ file,
2605
+ (url) => {
2606
+ setEditing((prev) => {
2607
+ if (!prev) return prev;
2608
+ const current = prev[f.id] || [];
2609
+ if (f.max && current.length >= f.max) {
2610
+ return prev;
2611
+ }
2612
+ return { ...prev, [f.id]: [...current, url] };
2613
+ });
2614
+ },
2615
+ ctx.uploadImage
2616
+ );
2617
+ });
2618
+ },
2619
+ children: "Upload"
2620
+ }
2621
+ )
2622
+ ] })
2623
+ ] }) : /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2624
+ /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
2625
+ /* @__PURE__ */ jsx5(
2626
+ "input",
2627
+ {
2628
+ type: "url",
2629
+ value: String(editing[f.id] ?? ""),
2630
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2631
+ placeholder: "https://...",
2632
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2475
2633
  }
2634
+ ),
2635
+ /* @__PURE__ */ jsx5(
2636
+ FilePickerButton,
2637
+ {
2638
+ accept: "image/*,video/*",
2639
+ className: "flex-shrink-0 cursor-pointer rounded-xl border border-slate-200 bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-200",
2640
+ onFiles: (files) => {
2641
+ const file = files[0];
2642
+ if (file) {
2643
+ void handleImageFile(
2644
+ file,
2645
+ (url) => setEditing(
2646
+ (current) => current ? { ...current, [f.id]: url } : current
2647
+ ),
2648
+ ctx.uploadImage
2649
+ );
2650
+ }
2651
+ },
2652
+ children: "Upload"
2653
+ }
2654
+ )
2655
+ ] }),
2656
+ editing[f.id] ? /* @__PURE__ */ jsx5("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(editing[f.id]).match(/\.(mp4|webm|mov|ogg)$/i) || String(editing[f.id]).includes("video") ? /* @__PURE__ */ jsx5(
2657
+ "video",
2658
+ {
2659
+ src: String(editing[f.id]),
2660
+ controls: true,
2661
+ className: "w-full h-auto max-h-48 object-contain rounded-lg"
2476
2662
  }
2477
- )
2478
- ] })
2479
- ] }),
2480
- editing[f.id] ? /* @__PURE__ */ jsx5("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(editing[f.id]).match(/\.(mp4|webm|mov|ogg)$/i) || String(editing[f.id]).includes("video") ? /* @__PURE__ */ jsx5(
2481
- "video",
2482
- {
2483
- src: String(editing[f.id]),
2484
- controls: true,
2485
- className: "w-full h-auto max-h-48 object-contain rounded-lg"
2486
- }
2487
- ) : /* @__PURE__ */ jsx5(
2488
- "img",
2489
- {
2490
- src: String(editing[f.id]),
2491
- alt: "",
2492
- className: "w-full h-auto max-h-48 object-contain rounded-lg"
2493
- }
2494
- ) }) : null
2495
- ] }) : f.type === "password" ? /* @__PURE__ */ jsx5(
2496
- PasswordField,
2497
- {
2498
- value: String(editing[f.id] ?? ""),
2499
- onChange: (val) => setEditing({ ...editing, [f.id]: val })
2500
- }
2501
- ) : f.type === "color" && !f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-3", children: [
2502
- /* @__PURE__ */ jsx5(
2503
- "input",
2504
- {
2505
- type: "color",
2506
- value: String(editing[f.id] ?? "#000000").startsWith("#") && String(editing[f.id] ?? "").length === 7 ? String(editing[f.id]) : "#000000",
2507
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2508
- className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
2509
- }
2510
- ),
2511
- /* @__PURE__ */ jsx5(
2512
- "input",
2513
- {
2514
- type: "text",
2515
- value: String(editing[f.id] ?? ""),
2516
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2517
- placeholder: "#000000",
2518
- className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2519
- }
2520
- ),
2521
- /* @__PURE__ */ jsx5(
2522
- "div",
2523
- {
2524
- className: "w-8 h-8 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
2525
- style: { backgroundColor: String(editing[f.id] ?? "#000000") }
2526
- }
2527
- )
2528
- ] }) : f.type === "color" && f.multiple || f.type === "list" && f.id === "colors" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2529
- (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : []).map((item, idx) => {
2530
- const colorVal = String(item ?? "").trim();
2531
- const validHex = colorVal.startsWith("#") && (colorVal.length === 4 || colorVal.length === 7) ? colorVal : "#000000";
2532
- return /* @__PURE__ */ jsxs4("div", { className: "flex gap-2 items-center", children: [
2663
+ ) : /* @__PURE__ */ jsx5(
2664
+ "img",
2665
+ {
2666
+ src: String(editing[f.id]),
2667
+ alt: "",
2668
+ className: "w-full h-auto max-h-48 object-contain rounded-lg"
2669
+ }
2670
+ ) }) : null
2671
+ ] }) : f.type === "password" ? /* @__PURE__ */ jsx5(
2672
+ PasswordField,
2673
+ {
2674
+ value: String(editing[f.id] ?? ""),
2675
+ onChange: (val) => setEditing({ ...editing, [f.id]: val })
2676
+ }
2677
+ ) : f.type === "color" && !f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-3", children: [
2533
2678
  /* @__PURE__ */ jsx5(
2534
2679
  "input",
2535
2680
  {
2536
2681
  type: "color",
2537
- value: validHex.length === 7 ? validHex : "#000000",
2538
- onChange: (e) => {
2539
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
2540
- arr[idx] = e.target.value;
2541
- setEditing({ ...editing, [f.id]: arr });
2542
- },
2682
+ value: String(editing[f.id] ?? "#000000").startsWith("#") && String(editing[f.id] ?? "").length === 7 ? String(editing[f.id]) : "#000000",
2683
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2543
2684
  className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
2544
2685
  }
2545
2686
  ),
@@ -2547,135 +2688,172 @@ function CollectionEditor({ collection }) {
2547
2688
  "input",
2548
2689
  {
2549
2690
  type: "text",
2550
- value: colorVal,
2551
- onChange: (e) => {
2552
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
2553
- arr[idx] = e.target.value;
2554
- setEditing({ ...editing, [f.id]: arr });
2555
- },
2556
- placeholder: "#1c2a44",
2557
- className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2691
+ value: String(editing[f.id] ?? ""),
2692
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2693
+ placeholder: "#000000",
2694
+ className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2558
2695
  }
2559
2696
  ),
2560
2697
  /* @__PURE__ */ jsx5(
2561
2698
  "div",
2562
2699
  {
2563
- className: "w-7 h-7 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
2564
- style: { backgroundColor: colorVal || "#000000" }
2700
+ className: "w-8 h-8 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
2701
+ style: { backgroundColor: String(editing[f.id] ?? "#000000") }
2565
2702
  }
2566
- ),
2567
- /* @__PURE__ */ jsx5(
2703
+ )
2704
+ ] }) : f.type === "color" && f.multiple || f.type === "list" && f.id === "colors" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2705
+ (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : []).map((item, idx) => {
2706
+ const colorVal = String(item ?? "").trim();
2707
+ const validHex = colorVal.startsWith("#") && (colorVal.length === 4 || colorVal.length === 7) ? colorVal : "#000000";
2708
+ return /* @__PURE__ */ jsxs4("div", { className: "flex gap-2 items-center", children: [
2709
+ /* @__PURE__ */ jsx5(
2710
+ "input",
2711
+ {
2712
+ type: "color",
2713
+ value: validHex.length === 7 ? validHex : "#000000",
2714
+ onChange: (e) => {
2715
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
2716
+ arr[idx] = e.target.value;
2717
+ setEditing({ ...editing, [f.id]: arr });
2718
+ },
2719
+ className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
2720
+ }
2721
+ ),
2722
+ /* @__PURE__ */ jsx5(
2723
+ "input",
2724
+ {
2725
+ type: "text",
2726
+ value: colorVal,
2727
+ onChange: (e) => {
2728
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
2729
+ arr[idx] = e.target.value;
2730
+ setEditing({ ...editing, [f.id]: arr });
2731
+ },
2732
+ placeholder: "#1c2a44",
2733
+ className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2734
+ }
2735
+ ),
2736
+ /* @__PURE__ */ jsx5(
2737
+ "div",
2738
+ {
2739
+ className: "w-7 h-7 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
2740
+ style: { backgroundColor: colorVal || "#000000" }
2741
+ }
2742
+ ),
2743
+ /* @__PURE__ */ jsx5(
2744
+ "button",
2745
+ {
2746
+ type: "button",
2747
+ onClick: () => {
2748
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
2749
+ arr.splice(idx, 1);
2750
+ setEditing({ ...editing, [f.id]: arr });
2751
+ },
2752
+ className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
2753
+ children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
2754
+ }
2755
+ )
2756
+ ] }, idx);
2757
+ }),
2758
+ /* @__PURE__ */ jsxs4(
2568
2759
  "button",
2569
2760
  {
2570
2761
  type: "button",
2571
2762
  onClick: () => {
2572
2763
  let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
2573
- arr.splice(idx, 1);
2764
+ arr.push("#000000");
2574
2765
  setEditing({ ...editing, [f.id]: arr });
2575
2766
  },
2576
- className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
2577
- children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
2767
+ className: "inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-indigo-600 bg-indigo-50 hover:bg-indigo-100 rounded-lg border border-indigo-100 transition-colors",
2768
+ children: [
2769
+ /* @__PURE__ */ jsx5(Plus, { className: "w-3.5 h-3.5" }),
2770
+ " Add Color"
2771
+ ]
2578
2772
  }
2579
2773
  )
2580
- ] }, idx);
2581
- }),
2582
- /* @__PURE__ */ jsxs4(
2583
- "button",
2584
- {
2585
- type: "button",
2586
- onClick: () => {
2587
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
2588
- arr.push("#000000");
2589
- setEditing({ ...editing, [f.id]: arr });
2590
- },
2591
- className: "inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-indigo-600 bg-indigo-50 hover:bg-indigo-100 rounded-lg border border-indigo-100 transition-colors",
2592
- children: [
2593
- /* @__PURE__ */ jsx5(Plus, { className: "w-3.5 h-3.5" }),
2594
- " Add Color"
2595
- ]
2596
- }
2597
- )
2598
- ] }) : f.type === "list" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2599
- (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : []).map((item, idx) => /* @__PURE__ */ jsxs4("div", { className: "flex gap-2 items-center", children: [
2600
- /* @__PURE__ */ jsx5(
2774
+ ] }) : f.type === "list" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2775
+ (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : []).map((item, idx) => /* @__PURE__ */ jsxs4("div", { className: "flex gap-2 items-center", children: [
2776
+ /* @__PURE__ */ jsx5(
2777
+ "input",
2778
+ {
2779
+ type: "text",
2780
+ value: String(item ?? ""),
2781
+ onChange: (e) => {
2782
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2783
+ arr[idx] = e.target.value;
2784
+ setEditing({ ...editing, [f.id]: arr });
2785
+ },
2786
+ className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2787
+ }
2788
+ ),
2789
+ /* @__PURE__ */ jsx5(
2790
+ "button",
2791
+ {
2792
+ type: "button",
2793
+ onClick: () => {
2794
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2795
+ arr.splice(idx, 1);
2796
+ setEditing({ ...editing, [f.id]: arr });
2797
+ },
2798
+ className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
2799
+ children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
2800
+ }
2801
+ )
2802
+ ] }, idx)),
2803
+ /* @__PURE__ */ jsxs4(
2804
+ "button",
2805
+ {
2806
+ type: "button",
2807
+ onClick: () => {
2808
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2809
+ arr.push("");
2810
+ setEditing({ ...editing, [f.id]: arr });
2811
+ },
2812
+ className: "inline-flex items-center gap-1.5 px-3 py-2 bg-indigo-50 hover:bg-indigo-100 text-indigo-700 text-xs font-semibold rounded-xl transition-colors",
2813
+ children: [
2814
+ /* @__PURE__ */ jsx5(Plus, { className: "w-3.5 h-3.5" }),
2815
+ " Add Item"
2816
+ ]
2817
+ }
2818
+ )
2819
+ ] }) : /* @__PURE__ */ jsx5(
2601
2820
  "input",
2602
2821
  {
2603
- type: "text",
2604
- value: String(item ?? ""),
2605
- onChange: (e) => {
2606
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2607
- arr[idx] = e.target.value;
2608
- setEditing({ ...editing, [f.id]: arr });
2609
- },
2610
- className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
2822
+ value: String(editing[f.id] ?? ""),
2823
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2824
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
2825
+ }
2826
+ )
2827
+ ] }, f.id)) }) }),
2828
+ /* @__PURE__ */ jsxs4("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
2829
+ /* @__PURE__ */ jsx5(
2830
+ "button",
2831
+ {
2832
+ onClick: () => setEditing(null),
2833
+ disabled: saving,
2834
+ className: "rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-600 hover:bg-slate-100 transition-colors disabled:opacity-50",
2835
+ children: "Cancel"
2611
2836
  }
2612
2837
  ),
2613
2838
  /* @__PURE__ */ jsx5(
2614
2839
  "button",
2615
2840
  {
2616
- type: "button",
2617
- onClick: () => {
2618
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2619
- arr.splice(idx, 1);
2620
- setEditing({ ...editing, [f.id]: arr });
2621
- },
2622
- className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
2623
- children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
2841
+ onClick: save,
2842
+ disabled: saving,
2843
+ className: "inline-flex items-center gap-2 rounded-xl bg-slate-900 px-6 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-slate-800 hover:shadow transition-all disabled:opacity-60",
2844
+ children: saving ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
2845
+ /* @__PURE__ */ jsxs4("svg", { className: "animate-spin h-4 w-4 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
2846
+ /* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2847
+ /* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
2848
+ ] }),
2849
+ "Saving..."
2850
+ ] }) : "Save Entry"
2624
2851
  }
2625
2852
  )
2626
- ] }, idx)),
2627
- /* @__PURE__ */ jsxs4(
2628
- "button",
2629
- {
2630
- type: "button",
2631
- onClick: () => {
2632
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2633
- arr.push("");
2634
- setEditing({ ...editing, [f.id]: arr });
2635
- },
2636
- className: "inline-flex items-center gap-1.5 px-3 py-2 bg-indigo-50 hover:bg-indigo-100 text-indigo-700 text-xs font-semibold rounded-xl transition-colors",
2637
- children: [
2638
- /* @__PURE__ */ jsx5(Plus, { className: "w-3.5 h-3.5" }),
2639
- " Add Item"
2640
- ]
2641
- }
2642
- )
2643
- ] }) : /* @__PURE__ */ jsx5(
2644
- "input",
2645
- {
2646
- value: String(editing[f.id] ?? ""),
2647
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2648
- className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
2649
- }
2650
- )
2651
- ] }, f.id)) }),
2652
- /* @__PURE__ */ jsxs4("div", { className: "mt-8 flex justify-end gap-3 pt-5 border-t border-slate-100", children: [
2653
- /* @__PURE__ */ jsx5(
2654
- "button",
2655
- {
2656
- onClick: () => setEditing(null),
2657
- disabled: saving,
2658
- className: "rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-600 hover:bg-slate-100 transition-colors disabled:opacity-50",
2659
- children: "Cancel"
2660
- }
2661
- ),
2662
- /* @__PURE__ */ jsx5(
2663
- "button",
2664
- {
2665
- onClick: save,
2666
- disabled: saving,
2667
- className: "inline-flex items-center gap-2 rounded-xl bg-slate-900 px-6 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-slate-800 hover:shadow transition-all disabled:opacity-60",
2668
- children: saving ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
2669
- /* @__PURE__ */ jsxs4("svg", { className: "animate-spin h-4 w-4 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
2670
- /* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2671
- /* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
2672
- ] }),
2673
- "Saving..."
2674
- ] }) : "Save Entry"
2675
- }
2676
- )
2677
- ] })
2678
- ] }),
2853
+ ] })
2854
+ ] })
2855
+ }
2856
+ ),
2679
2857
  /* @__PURE__ */ jsx5("div", { className: "overflow-x-auto rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ jsxs4("table", { className: "w-full text-sm text-left", children: [
2680
2858
  /* @__PURE__ */ jsx5("thead", { className: "bg-slate-50/80 border-b border-slate-200", children: /* @__PURE__ */ jsxs4("tr", { children: [
2681
2859
  visibleFields.map((f) => /* @__PURE__ */ jsx5("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: f.label }, f.id)),
@@ -2713,7 +2891,7 @@ function CollectionEditor({ collection }) {
2713
2891
  onDragEnd,
2714
2892
  className: `hover:bg-slate-50/50 transition-colors group cursor-grab active:cursor-grabbing ${deletingId === e.id ? "opacity-50" : ""} ${dragOverIdx === idx ? "border-t-2 border-t-indigo-500" : ""}`,
2715
2893
  children: [
2716
- visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx5("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ? /* @__PURE__ */ jsx5(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : f.id === "status" && e[f.id] ? /* @__PURE__ */ jsx5("span", { className: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold ${String(e[f.id]).includes("Entregado") ? "bg-emerald-100 text-emerald-800 border border-emerald-300" : String(e[f.id]).includes("Preparaci\xF3n") ? "bg-amber-100 text-amber-800 border border-amber-300" : String(e[f.id]).includes("Camino") ? "bg-blue-100 text-blue-800 border border-blue-300" : String(e[f.id]).includes("Confirmado") ? "bg-indigo-100 text-indigo-800 border border-indigo-300" : String(e[f.id]).includes("Cancelado") ? "bg-rose-100 text-rose-800 border border-rose-300" : "bg-amber-50 text-amber-800 border border-amber-200"}`, children: String(e[f.id]) }) : f.type === "number" && e[f.id] !== void 0 && e[f.id] !== null && String(e[f.id]) !== "" ? f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.includes("$") || f.id.toLowerCase().includes("amount") || f.id.toLowerCase().includes("total") ? /* @__PURE__ */ jsxs4("span", { className: "font-semibold text-slate-800", children: [
2894
+ visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "branch-settings" ? /* @__PURE__ */ jsx5(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx5("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ? /* @__PURE__ */ jsx5(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : f.id === "status" && e[f.id] ? /* @__PURE__ */ jsx5("span", { className: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold ${String(e[f.id]).includes("Entregado") ? "bg-emerald-100 text-emerald-800 border border-emerald-300" : String(e[f.id]).includes("Preparaci\xF3n") ? "bg-amber-100 text-amber-800 border border-amber-300" : String(e[f.id]).includes("Camino") ? "bg-blue-100 text-blue-800 border border-blue-300" : String(e[f.id]).includes("Confirmado") ? "bg-indigo-100 text-indigo-800 border border-indigo-300" : String(e[f.id]).includes("Cancelado") ? "bg-rose-100 text-rose-800 border border-rose-300" : "bg-amber-50 text-amber-800 border border-amber-200"}`, children: String(e[f.id]) }) : f.type === "number" && e[f.id] !== void 0 && e[f.id] !== null && String(e[f.id]) !== "" ? f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.includes("$") || f.id.toLowerCase().includes("amount") || f.id.toLowerCase().includes("total") ? /* @__PURE__ */ jsxs4("span", { className: "font-semibold text-slate-800", children: [
2717
2895
  "$ ",
2718
2896
  Number(e[f.id]).toLocaleString("es-CO")
2719
2897
  ] }) : /* @__PURE__ */ jsx5("span", { children: Number(e[f.id]).toLocaleString("es-CO") }) : String(e[f.id] ?? "") }, f.id)),
@@ -3133,7 +3311,6 @@ function SettingsSection() {
3133
3311
  /* @__PURE__ */ jsx5("div", { className: "px-6 py-4 border-b border-slate-100 bg-slate-50/50", children: /* @__PURE__ */ jsx5("h3", { className: "font-bold text-slate-800", children: "Configuration Snapshot" }) }),
3134
3312
  /* @__PURE__ */ jsxs4("dl", { className: "divide-y divide-slate-100 text-sm", children: [
3135
3313
  /* @__PURE__ */ jsx5(Row, { label: "Site Name", value: ctx.config.siteName ?? "\u2014" }),
3136
- /* @__PURE__ */ jsx5(Row, { label: "Active Storage Adapter", value: ctx.adapter.name, highlight: true }),
3137
3314
  /* @__PURE__ */ jsx5(Row, { label: "Registered Pages", value: String(ctx.config.pages.length) }),
3138
3315
  /* @__PURE__ */ jsx5(
3139
3316
  Row,
@@ -3366,8 +3543,11 @@ function FormattedNumberInput({
3366
3543
  value,
3367
3544
  onChange,
3368
3545
  isPrice = false,
3546
+ isPercent = false,
3547
+ allowEmpty = false,
3369
3548
  placeholder = "0",
3370
- className = ""
3549
+ className = "",
3550
+ containerClassName = "w-full"
3371
3551
  }) {
3372
3552
  const formatWithDots = (num) => {
3373
3553
  if (num === void 0 || num === null || num === "") return "";
@@ -3384,34 +3564,661 @@ function FormattedNumberInput({
3384
3564
  const cleanDigits = rawText.replace(/\D/g, "");
3385
3565
  if (!cleanDigits) {
3386
3566
  setDisplayVal("");
3387
- onChange(0);
3567
+ onChange(allowEmpty ? null : 0);
3568
+ return;
3569
+ }
3570
+ const parsed = Number(cleanDigits);
3571
+ if (isPercent && parsed > 100) {
3572
+ setDisplayVal("100");
3573
+ onChange(100);
3388
3574
  return;
3389
3575
  }
3390
- const formatted = cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
3576
+ const formatted = isPercent ? cleanDigits : cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
3391
3577
  setDisplayVal(formatted);
3392
- onChange(Number(cleanDigits));
3578
+ onChange(parsed);
3393
3579
  };
3394
- return /* @__PURE__ */ jsxs4("div", { className: "relative flex items-center w-full", children: [
3580
+ return /* @__PURE__ */ jsxs4("div", { className: `relative flex items-center ${containerClassName}`, children: [
3395
3581
  isPrice && /* @__PURE__ */ jsx5("span", { className: "absolute left-3.5 text-sm font-bold text-slate-400 pointer-events-none select-none", children: "$" }),
3582
+ isPercent && /* @__PURE__ */ jsx5("span", { className: "absolute right-3.5 text-sm font-bold text-slate-400 pointer-events-none select-none", children: "%" }),
3396
3583
  /* @__PURE__ */ jsx5(
3397
3584
  "input",
3398
3585
  {
3399
3586
  type: "text",
3400
3587
  inputMode: "numeric",
3588
+ pattern: "[0-9.]*",
3589
+ autoComplete: "off",
3401
3590
  value: displayVal,
3402
3591
  onChange: handleChange,
3403
3592
  placeholder,
3404
- className: `w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-800 shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all ${isPrice ? "pl-8" : ""} ${className}`
3593
+ "aria-valuemin": isPercent ? 0 : void 0,
3594
+ "aria-valuemax": isPercent ? 100 : void 0,
3595
+ className: `w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-800 shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all ${isPrice ? "pl-8" : ""} ${isPercent ? "pr-8" : ""} ${className}`
3405
3596
  }
3406
3597
  )
3407
3598
  ] });
3408
3599
  }
3600
+ function BranchSettingsEditor({
3601
+ collectionId,
3602
+ value,
3603
+ globalPrice,
3604
+ globalDiscount,
3605
+ onChange
3606
+ }) {
3607
+ const ctx = useCmsContext();
3608
+ const [branches, setBranches] = useState5([]);
3609
+ const [loading, setLoading] = useState5(true);
3610
+ const [loadError, setLoadError] = useState5("");
3611
+ const settings = value && typeof value === "object" ? value : {};
3612
+ const selectedBranches = Array.isArray(settings.branches) ? settings.branches.map(String) : [];
3613
+ const prices = settings.prices && typeof settings.prices === "object" ? settings.prices : {};
3614
+ const selectedPriceBranches = [
3615
+ .../* @__PURE__ */ new Set([
3616
+ ...Array.isArray(settings.priceBranches) ? settings.priceBranches.map(String) : [],
3617
+ ...Object.keys(prices)
3618
+ ])
3619
+ ];
3620
+ const discounts = settings.discounts && typeof settings.discounts === "object" ? settings.discounts : {};
3621
+ const selectedDiscountBranches = [
3622
+ .../* @__PURE__ */ new Set([
3623
+ ...Array.isArray(settings.discountBranches) ? settings.discountBranches.map(String) : [],
3624
+ ...Object.keys(discounts)
3625
+ ])
3626
+ ];
3627
+ const branchAvailability = settings.branchAvailability && typeof settings.branchAvailability === "object" ? settings.branchAvailability : {};
3628
+ const selectedAvailabilityBranches = Object.keys(branchAvailability);
3629
+ const allBranches = settings.allBranches !== false;
3630
+ const useBranchPricing = settings.useBranchPricing === true;
3631
+ const useBranchDiscounts = settings.useBranchDiscounts === true;
3632
+ useEffect4(() => {
3633
+ let active = true;
3634
+ setLoading(true);
3635
+ setLoadError("");
3636
+ ctx.adapter.listEntries(collectionId).then((entries) => {
3637
+ if (active) setBranches(entries);
3638
+ }).catch((error) => {
3639
+ console.error("Could not load branches for product settings:", error);
3640
+ if (active) setLoadError("No se pudieron cargar las sedes.");
3641
+ }).finally(() => {
3642
+ if (active) setLoading(false);
3643
+ });
3644
+ return () => {
3645
+ active = false;
3646
+ };
3647
+ }, [collectionId, ctx.adapter]);
3648
+ const getBranchName = (branch) => String(branch.name || branch.id);
3649
+ const updateSettings = (patch) => {
3650
+ onChange({
3651
+ allBranches,
3652
+ branches: selectedBranches,
3653
+ useBranchPricing,
3654
+ priceBranches: selectedPriceBranches,
3655
+ prices: { ...prices },
3656
+ useBranchDiscounts,
3657
+ discountBranches: selectedDiscountBranches,
3658
+ discounts: { ...discounts },
3659
+ branchAvailability: { ...branchAvailability },
3660
+ ...patch
3661
+ });
3662
+ };
3663
+ const updateBranchAvailability = (name, start, end) => {
3664
+ updateSettings({
3665
+ branchAvailability: {
3666
+ ...branchAvailability,
3667
+ [name]: {
3668
+ start: toStoredTime(start),
3669
+ end: toStoredTime(end)
3670
+ }
3671
+ }
3672
+ });
3673
+ };
3674
+ const updateBranchPrice = (name, value2) => {
3675
+ const nextPrices = { ...prices };
3676
+ if (value2.trim() === "") {
3677
+ delete nextPrices[name];
3678
+ } else {
3679
+ const parsed = Number(value2);
3680
+ if (Number.isFinite(parsed) && parsed >= 0) nextPrices[name] = parsed;
3681
+ }
3682
+ updateSettings({ prices: nextPrices });
3683
+ };
3684
+ const updateBranchDiscount = (name, value2) => {
3685
+ const nextDiscounts = { ...discounts };
3686
+ if (value2.trim() === "") {
3687
+ delete nextDiscounts[name];
3688
+ } else {
3689
+ const parsed = Number(value2);
3690
+ if (Number.isFinite(parsed) && parsed >= 0 && parsed <= 100) {
3691
+ nextDiscounts[name] = parsed;
3692
+ }
3693
+ }
3694
+ updateSettings({ discounts: nextDiscounts });
3695
+ };
3696
+ return /* @__PURE__ */ jsxs4("div", { className: "space-y-4 rounded-xl border border-slate-200 bg-slate-50/50 p-4", children: [
3697
+ /* @__PURE__ */ jsxs4("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
3698
+ /* @__PURE__ */ jsx5(
3699
+ "input",
3700
+ {
3701
+ type: "checkbox",
3702
+ checked: allBranches,
3703
+ onChange: (event) => updateSettings({ allBranches: event.target.checked }),
3704
+ className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
3705
+ }
3706
+ ),
3707
+ /* @__PURE__ */ jsxs4("span", { children: [
3708
+ /* @__PURE__ */ jsx5("span", { className: "block font-semibold", children: "Disponible en todas las sedes" }),
3709
+ /* @__PURE__ */ jsx5("span", { className: "mt-0.5 block text-xs text-slate-500", children: "Desactiva esta opci\xF3n para elegir una o varias sedes." })
3710
+ ] })
3711
+ ] }),
3712
+ !allBranches && /* @__PURE__ */ jsx5(
3713
+ SearchableMultiSelect,
3714
+ {
3715
+ options: branches.map((branch) => ({
3716
+ value: getBranchName(branch),
3717
+ label: getBranchName(branch)
3718
+ })),
3719
+ value: selectedBranches,
3720
+ onChange: (next) => updateSettings({ branches: next }),
3721
+ loading,
3722
+ error: loadError,
3723
+ placeholder: "Seleccionar sedes...",
3724
+ searchPlaceholder: "Buscar sede...",
3725
+ emptyMessage: "No hay sedes registradas todav\xEDa."
3726
+ }
3727
+ ),
3728
+ /* @__PURE__ */ jsxs4("div", { className: "border-t border-slate-200 pt-4", children: [
3729
+ /* @__PURE__ */ jsx5("p", { className: "text-sm font-semibold text-slate-700", children: "Horario diferente por sede (opcional)" }),
3730
+ /* @__PURE__ */ jsx5("p", { className: "mt-1 text-xs text-slate-500", children: "Deja ambas horas vac\xEDas para heredar el horario general. Si defines una hora, el horario de esa sede reemplaza por completo al general." }),
3731
+ /* @__PURE__ */ jsx5("div", { className: "mt-3", children: /* @__PURE__ */ jsx5(
3732
+ SearchableMultiSelect,
3733
+ {
3734
+ options: branches.map((branch) => ({
3735
+ value: getBranchName(branch),
3736
+ label: getBranchName(branch)
3737
+ })),
3738
+ value: selectedAvailabilityBranches,
3739
+ onChange: (next) => {
3740
+ const nextSchedules = Object.fromEntries(
3741
+ next.map((name) => [
3742
+ name,
3743
+ branchAvailability[name] ?? { start: "", end: "" }
3744
+ ])
3745
+ );
3746
+ updateSettings({ branchAvailability: nextSchedules });
3747
+ },
3748
+ loading,
3749
+ error: loadError,
3750
+ placeholder: "Buscar sedes para configurar su horario...",
3751
+ searchPlaceholder: "Buscar sede...",
3752
+ emptyMessage: "No hay sedes registradas todav\xEDa."
3753
+ }
3754
+ ) }),
3755
+ /* @__PURE__ */ jsx5("div", { className: "mt-3 space-y-2", children: branches.filter(
3756
+ (branch) => selectedAvailabilityBranches.includes(getBranchName(branch))
3757
+ ).map((branch) => {
3758
+ const name = getBranchName(branch);
3759
+ const schedule = branchAvailability[name] ?? {};
3760
+ return /* @__PURE__ */ jsxs4(
3761
+ "div",
3762
+ {
3763
+ className: "space-y-3 rounded-lg border border-slate-200 bg-white p-3",
3764
+ children: [
3765
+ /* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
3766
+ /* @__PURE__ */ jsx5("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
3767
+ /* @__PURE__ */ jsx5(
3768
+ "button",
3769
+ {
3770
+ type: "button",
3771
+ onClick: () => {
3772
+ const nextSchedules = { ...branchAvailability };
3773
+ delete nextSchedules[name];
3774
+ updateSettings({ branchAvailability: nextSchedules });
3775
+ },
3776
+ "aria-label": `Quitar horario de ${name}`,
3777
+ title: `Quitar horario de ${name}`,
3778
+ className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
3779
+ children: /* @__PURE__ */ jsx5(X, { className: "h-4 w-4" })
3780
+ }
3781
+ )
3782
+ ] }),
3783
+ /* @__PURE__ */ jsx5(
3784
+ AdminTimeRangePicker,
3785
+ {
3786
+ value: [
3787
+ toDayjsTime(schedule.start),
3788
+ toDayjsTime(schedule.end)
3789
+ ],
3790
+ onChange: (times) => updateBranchAvailability(
3791
+ name,
3792
+ times?.[0] ?? null,
3793
+ times?.[1] ?? null
3794
+ ),
3795
+ allowEmpty: [true, true],
3796
+ className: "w-full",
3797
+ format: TIME_DISPLAY_FORMAT,
3798
+ order: false,
3799
+ placeholder: ["Hora de inicio", "Hora de cierre"],
3800
+ use12Hours: true
3801
+ }
3802
+ )
3803
+ ]
3804
+ },
3805
+ branch.id
3806
+ );
3807
+ }) })
3808
+ ] }),
3809
+ /* @__PURE__ */ jsxs4("div", { className: "border-t border-slate-200 pt-4", children: [
3810
+ /* @__PURE__ */ jsxs4("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
3811
+ /* @__PURE__ */ jsx5(
3812
+ "input",
3813
+ {
3814
+ type: "checkbox",
3815
+ checked: useBranchPricing,
3816
+ onChange: (event) => updateSettings({ useBranchPricing: event.target.checked }),
3817
+ className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
3818
+ }
3819
+ ),
3820
+ /* @__PURE__ */ jsxs4("span", { children: [
3821
+ /* @__PURE__ */ jsx5("span", { className: "block font-semibold", children: "Usar precio diferente por sede" }),
3822
+ /* @__PURE__ */ jsx5("span", { className: "mt-0.5 block text-xs text-slate-500", children: "El precio global se usa como base; deja una sede vac\xEDa para conservarlo." })
3823
+ ] })
3824
+ ] }),
3825
+ useBranchPricing && /* @__PURE__ */ jsx5("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ jsx5("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir precios." }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
3826
+ /* @__PURE__ */ jsxs4("p", { className: "text-xs text-slate-500", children: [
3827
+ "Precio global actual: $",
3828
+ globalPrice.toLocaleString("es-CO")
3829
+ ] }),
3830
+ /* @__PURE__ */ jsx5(
3831
+ SearchableMultiSelect,
3832
+ {
3833
+ options: branches.map((branch) => ({
3834
+ value: getBranchName(branch),
3835
+ label: getBranchName(branch)
3836
+ })),
3837
+ value: selectedPriceBranches,
3838
+ onChange: (next) => {
3839
+ const removed = selectedPriceBranches.filter(
3840
+ (name) => !next.includes(name)
3841
+ );
3842
+ const nextPrices = { ...prices };
3843
+ removed.forEach((name) => delete nextPrices[name]);
3844
+ updateSettings({
3845
+ priceBranches: next,
3846
+ prices: nextPrices
3847
+ });
3848
+ },
3849
+ loading,
3850
+ error: loadError,
3851
+ placeholder: "Buscar y agregar sedes...",
3852
+ searchPlaceholder: "Buscar sede...",
3853
+ emptyMessage: "No hay sedes registradas todav\xEDa."
3854
+ }
3855
+ ),
3856
+ branches.filter(
3857
+ (branch) => selectedPriceBranches.includes(getBranchName(branch))
3858
+ ).map((branch) => {
3859
+ const name = getBranchName(branch);
3860
+ return /* @__PURE__ */ jsxs4(
3861
+ "div",
3862
+ {
3863
+ className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
3864
+ children: [
3865
+ /* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
3866
+ /* @__PURE__ */ jsx5("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
3867
+ /* @__PURE__ */ jsx5(
3868
+ "button",
3869
+ {
3870
+ type: "button",
3871
+ onClick: () => {
3872
+ const nextPrices = { ...prices };
3873
+ delete nextPrices[name];
3874
+ updateSettings({
3875
+ priceBranches: selectedPriceBranches.filter(
3876
+ (selected) => selected !== name
3877
+ ),
3878
+ prices: nextPrices
3879
+ });
3880
+ },
3881
+ "aria-label": `Quitar ${name} de precios por sede`,
3882
+ title: `Quitar ${name}`,
3883
+ className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
3884
+ children: /* @__PURE__ */ jsx5(X, { className: "h-4 w-4" })
3885
+ }
3886
+ )
3887
+ ] }),
3888
+ /* @__PURE__ */ jsxs4("label", { className: "block w-full", children: [
3889
+ /* @__PURE__ */ jsxs4("span", { className: "sr-only", children: [
3890
+ "Precio para ",
3891
+ name
3892
+ ] }),
3893
+ /* @__PURE__ */ jsx5(
3894
+ FormattedNumberInput,
3895
+ {
3896
+ value: prices[name] ?? "",
3897
+ onChange: (price) => updateBranchPrice(
3898
+ name,
3899
+ price === null ? "" : String(price)
3900
+ ),
3901
+ isPrice: true,
3902
+ allowEmpty: true,
3903
+ placeholder: String(globalPrice),
3904
+ className: "bg-white text-right",
3905
+ containerClassName: "w-full"
3906
+ }
3907
+ )
3908
+ ] })
3909
+ ]
3910
+ },
3911
+ branch.id
3912
+ );
3913
+ })
3914
+ ] }) })
3915
+ ] }),
3916
+ /* @__PURE__ */ jsxs4("div", { className: "border-t border-slate-200 pt-4", children: [
3917
+ /* @__PURE__ */ jsxs4("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
3918
+ /* @__PURE__ */ jsx5(
3919
+ "input",
3920
+ {
3921
+ type: "checkbox",
3922
+ checked: useBranchDiscounts,
3923
+ onChange: (event) => updateSettings({ useBranchDiscounts: event.target.checked }),
3924
+ className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
3925
+ }
3926
+ ),
3927
+ /* @__PURE__ */ jsxs4("span", { children: [
3928
+ /* @__PURE__ */ jsx5("span", { className: "block font-semibold", children: "Usar descuento diferente por sede" }),
3929
+ /* @__PURE__ */ jsx5("span", { className: "mt-0.5 block text-xs text-slate-500", children: "El descuento global aplica como base; una sede vac\xEDa hereda ese porcentaje." })
3930
+ ] })
3931
+ ] }),
3932
+ useBranchDiscounts && /* @__PURE__ */ jsx5("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ jsx5("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir descuentos." }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
3933
+ /* @__PURE__ */ jsxs4("p", { className: "text-xs text-slate-500", children: [
3934
+ "Descuento global actual: ",
3935
+ globalDiscount,
3936
+ "%"
3937
+ ] }),
3938
+ /* @__PURE__ */ jsx5(
3939
+ SearchableMultiSelect,
3940
+ {
3941
+ options: branches.map((branch) => ({
3942
+ value: getBranchName(branch),
3943
+ label: getBranchName(branch)
3944
+ })),
3945
+ value: selectedDiscountBranches,
3946
+ onChange: (next) => {
3947
+ const removed = selectedDiscountBranches.filter(
3948
+ (name) => !next.includes(name)
3949
+ );
3950
+ const nextDiscounts = { ...discounts };
3951
+ removed.forEach((name) => delete nextDiscounts[name]);
3952
+ updateSettings({
3953
+ discountBranches: next,
3954
+ discounts: nextDiscounts
3955
+ });
3956
+ },
3957
+ loading,
3958
+ error: loadError,
3959
+ placeholder: "Buscar y agregar sedes...",
3960
+ searchPlaceholder: "Buscar sede...",
3961
+ emptyMessage: "No hay sedes registradas todav\xEDa."
3962
+ }
3963
+ ),
3964
+ branches.filter(
3965
+ (branch) => selectedDiscountBranches.includes(getBranchName(branch))
3966
+ ).map((branch) => {
3967
+ const name = getBranchName(branch);
3968
+ return /* @__PURE__ */ jsxs4(
3969
+ "div",
3970
+ {
3971
+ className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
3972
+ children: [
3973
+ /* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
3974
+ /* @__PURE__ */ jsx5("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
3975
+ /* @__PURE__ */ jsx5(
3976
+ "button",
3977
+ {
3978
+ type: "button",
3979
+ onClick: () => {
3980
+ const nextDiscounts = { ...discounts };
3981
+ delete nextDiscounts[name];
3982
+ updateSettings({
3983
+ discountBranches: selectedDiscountBranches.filter(
3984
+ (selected) => selected !== name
3985
+ ),
3986
+ discounts: nextDiscounts
3987
+ });
3988
+ },
3989
+ "aria-label": `Quitar descuento de ${name}`,
3990
+ title: `Quitar ${name}`,
3991
+ className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
3992
+ children: /* @__PURE__ */ jsx5(X, { className: "h-4 w-4" })
3993
+ }
3994
+ )
3995
+ ] }),
3996
+ /* @__PURE__ */ jsxs4("label", { className: "block w-full", children: [
3997
+ /* @__PURE__ */ jsxs4("span", { className: "sr-only", children: [
3998
+ "Descuento para ",
3999
+ name
4000
+ ] }),
4001
+ /* @__PURE__ */ jsx5(
4002
+ FormattedNumberInput,
4003
+ {
4004
+ value: discounts[name] ?? "",
4005
+ onChange: (discount) => updateBranchDiscount(
4006
+ name,
4007
+ discount === null ? "" : String(discount)
4008
+ ),
4009
+ isPercent: true,
4010
+ allowEmpty: true,
4011
+ placeholder: String(globalDiscount),
4012
+ className: "bg-white text-right",
4013
+ containerClassName: "w-full"
4014
+ }
4015
+ )
4016
+ ] })
4017
+ ]
4018
+ },
4019
+ branch.id
4020
+ );
4021
+ })
4022
+ ] }) })
4023
+ ] })
4024
+ ] });
4025
+ }
4026
+ function BranchSettingsSummary({ value }) {
4027
+ if (!value || typeof value !== "object") return /* @__PURE__ */ jsx5("span", { children: "Todas las sedes" });
4028
+ const settings = value;
4029
+ const names = Array.isArray(settings.branches) ? settings.branches : [];
4030
+ const locationSummary = settings.allBranches === false ? names.length > 0 ? names.join(", ") : "Sin sedes" : "Todas las sedes";
4031
+ const pricingSummary = settings.useBranchPricing ? " \xB7 Precio por sede" : " \xB7 Precio global";
4032
+ return /* @__PURE__ */ jsx5("span", { children: locationSummary + pricingSummary });
4033
+ }
4034
+ function SearchableMultiSelect({
4035
+ options,
4036
+ value,
4037
+ onChange,
4038
+ placeholder,
4039
+ searchable = true,
4040
+ searchPlaceholder = "Buscar...",
4041
+ emptyMessage = "No hay opciones registradas todav\xEDa.",
4042
+ loading = false,
4043
+ error,
4044
+ max
4045
+ }) {
4046
+ const [open, setOpen] = useState5(false);
4047
+ const [search, setSearch] = useState5("");
4048
+ const rootRef = useRef2(null);
4049
+ useEffect4(() => {
4050
+ if (!open) return;
4051
+ const handlePointerDown = (event) => {
4052
+ if (event.target instanceof Node && !rootRef.current?.contains(event.target)) {
4053
+ setOpen(false);
4054
+ }
4055
+ };
4056
+ const handleKeyDown = (event) => {
4057
+ if (event.key === "Escape") setOpen(false);
4058
+ };
4059
+ document.addEventListener("pointerdown", handlePointerDown);
4060
+ document.addEventListener("keydown", handleKeyDown);
4061
+ return () => {
4062
+ document.removeEventListener("pointerdown", handlePointerDown);
4063
+ document.removeEventListener("keydown", handleKeyDown);
4064
+ };
4065
+ }, [open]);
4066
+ const normalize = (text) => text.toLocaleLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
4067
+ const normalizedSearch = searchable ? normalize(search.trim()) : "";
4068
+ const visibleOptions = options.filter(
4069
+ (option) => normalize(option.label).includes(normalizedSearch)
4070
+ );
4071
+ const selectedOptions = value.map(
4072
+ (selected) => options.find((option) => option.value === selected) || {
4073
+ value: selected,
4074
+ label: selected
4075
+ }
4076
+ ).filter(Boolean);
4077
+ const toggleOption = (optionValue) => {
4078
+ if (value.includes(optionValue)) {
4079
+ onChange(value.filter((selected) => selected !== optionValue));
4080
+ return;
4081
+ }
4082
+ if (!max || value.length < max) {
4083
+ onChange([...value, optionValue]);
4084
+ }
4085
+ };
4086
+ const toggleVisibleOptions = () => {
4087
+ const visibleValues = visibleOptions.map((option) => option.value);
4088
+ const hasUnselected = visibleValues.some(
4089
+ (optionValue) => !value.includes(optionValue)
4090
+ );
4091
+ if (hasUnselected) {
4092
+ const merged = [.../* @__PURE__ */ new Set([...value, ...visibleValues])];
4093
+ onChange(max ? merged.slice(0, max) : merged);
4094
+ } else {
4095
+ onChange(value.filter((selected) => !visibleValues.includes(selected)));
4096
+ }
4097
+ };
4098
+ return /* @__PURE__ */ jsxs4("div", { ref: rootRef, className: "relative", children: [
4099
+ /* @__PURE__ */ jsxs4(
4100
+ "button",
4101
+ {
4102
+ type: "button",
4103
+ "aria-haspopup": "listbox",
4104
+ "aria-expanded": open,
4105
+ onClick: () => setOpen((isOpen) => !isOpen),
4106
+ className: "flex min-h-11 w-full items-center justify-between gap-3 rounded-xl border border-slate-200 bg-white px-3 py-2.5 text-left text-sm shadow-sm transition-colors hover:border-slate-300 focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10",
4107
+ children: [
4108
+ /* @__PURE__ */ jsx5("span", { className: "flex min-w-0 flex-1 flex-wrap items-center gap-1.5", children: selectedOptions.length === 0 ? /* @__PURE__ */ jsx5("span", { className: "text-slate-400", children: placeholder }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
4109
+ selectedOptions.slice(0, 2).map((option) => /* @__PURE__ */ jsx5(
4110
+ "span",
4111
+ {
4112
+ className: "max-w-full truncate rounded-md bg-indigo-50 px-2 py-1 text-xs font-medium text-indigo-700",
4113
+ children: option.label
4114
+ },
4115
+ option.value
4116
+ )),
4117
+ selectedOptions.length > 2 && /* @__PURE__ */ jsxs4("span", { className: "rounded-md bg-slate-100 px-2 py-1 text-xs font-semibold text-slate-600", children: [
4118
+ "+",
4119
+ selectedOptions.length - 2
4120
+ ] })
4121
+ ] }) }),
4122
+ /* @__PURE__ */ jsxs4("span", { className: "flex shrink-0 items-center gap-2 text-xs text-slate-400", children: [
4123
+ selectedOptions.length > 0 && /* @__PURE__ */ jsxs4("span", { children: [
4124
+ selectedOptions.length,
4125
+ " seleccionada",
4126
+ selectedOptions.length === 1 ? "" : "s"
4127
+ ] }),
4128
+ /* @__PURE__ */ jsx5(
4129
+ ChevronDown,
4130
+ {
4131
+ className: `h-4 w-4 transition-transform ${open ? "rotate-180" : ""}`
4132
+ }
4133
+ )
4134
+ ] })
4135
+ ]
4136
+ }
4137
+ ),
4138
+ open && /* @__PURE__ */ jsxs4("div", { className: "absolute left-0 right-0 top-full z-[70] mt-1 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-xl", children: [
4139
+ /* @__PURE__ */ jsxs4("div", { className: "space-y-2 border-b border-slate-100 p-3", children: [
4140
+ searchable && /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
4141
+ /* @__PURE__ */ jsx5(Search, { className: "pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400" }),
4142
+ /* @__PURE__ */ jsx5(
4143
+ "input",
4144
+ {
4145
+ type: "search",
4146
+ autoFocus: true,
4147
+ value: search,
4148
+ onChange: (event) => setSearch(event.target.value),
4149
+ placeholder: searchPlaceholder,
4150
+ className: "w-full rounded-lg border border-slate-200 bg-white py-2 pl-9 pr-3 text-sm outline-none focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10"
4151
+ }
4152
+ )
4153
+ ] }),
4154
+ /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between gap-2 text-xs", children: [
4155
+ /* @__PURE__ */ jsxs4("span", { className: "font-medium text-slate-500", children: [
4156
+ value.length,
4157
+ " seleccionada",
4158
+ value.length === 1 ? "" : "s",
4159
+ max ? ` \xB7 m\xE1ximo ${max}` : ""
4160
+ ] }),
4161
+ /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
4162
+ /* @__PURE__ */ jsx5(
4163
+ "button",
4164
+ {
4165
+ type: "button",
4166
+ disabled: visibleOptions.length === 0 || loading || !!error,
4167
+ onClick: toggleVisibleOptions,
4168
+ className: "font-semibold text-indigo-600 hover:text-indigo-800 disabled:cursor-not-allowed disabled:text-slate-300",
4169
+ children: visibleOptions.length > 0 && visibleOptions.every((option) => value.includes(option.value)) ? searchable ? "Quitar visibles" : "Quitar todas" : searchable ? "Seleccionar visibles" : "Seleccionar todas"
4170
+ }
4171
+ ),
4172
+ /* @__PURE__ */ jsx5("span", { className: "text-slate-300", children: "\xB7" }),
4173
+ /* @__PURE__ */ jsx5(
4174
+ "button",
4175
+ {
4176
+ type: "button",
4177
+ disabled: value.length === 0,
4178
+ onClick: () => onChange([]),
4179
+ className: "font-semibold text-slate-500 hover:text-slate-700 disabled:cursor-not-allowed disabled:text-slate-300",
4180
+ children: "Limpiar"
4181
+ }
4182
+ )
4183
+ ] })
4184
+ ] })
4185
+ ] }),
4186
+ /* @__PURE__ */ jsx5("div", { role: "listbox", "aria-multiselectable": "true", className: "max-h-56 overflow-y-auto p-2", children: loading ? /* @__PURE__ */ jsx5("p", { className: "py-4 text-center text-xs text-slate-400", children: "Cargando opciones..." }) : error ? /* @__PURE__ */ jsx5("p", { role: "alert", className: "py-4 text-center text-xs text-red-600", children: error }) : visibleOptions.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "py-4 text-center text-xs text-slate-400", children: options.length === 0 ? emptyMessage : "No hay resultados para la b\xFAsqueda." }) : /* @__PURE__ */ jsx5("div", { className: "space-y-1", children: visibleOptions.map((option) => {
4187
+ const isSelected = value.includes(option.value);
4188
+ const isAtMax = !!max && value.length >= max && !isSelected;
4189
+ return /* @__PURE__ */ jsxs4(
4190
+ "button",
4191
+ {
4192
+ type: "button",
4193
+ role: "option",
4194
+ "aria-selected": isSelected,
4195
+ disabled: isAtMax,
4196
+ onClick: () => toggleOption(option.value),
4197
+ className: `flex w-full items-center gap-2.5 rounded-lg px-3 py-2.5 text-left text-sm transition-colors ${isSelected ? "bg-indigo-50 font-semibold text-indigo-900" : "text-slate-700 hover:bg-slate-50"} disabled:cursor-not-allowed disabled:opacity-50`,
4198
+ children: [
4199
+ /* @__PURE__ */ jsx5(
4200
+ "span",
4201
+ {
4202
+ className: `flex h-4 w-4 shrink-0 items-center justify-center rounded border ${isSelected ? "border-indigo-600 bg-indigo-600 text-white" : "border-slate-300 bg-white"}`,
4203
+ children: isSelected && /* @__PURE__ */ jsx5(Check, { className: "h-3 w-3" })
4204
+ }
4205
+ ),
4206
+ /* @__PURE__ */ jsx5("span", { className: "truncate", children: option.label })
4207
+ ]
4208
+ },
4209
+ option.value
4210
+ );
4211
+ }) }) })
4212
+ ] })
4213
+ ] });
4214
+ }
3409
4215
  function ReferenceSelect({
3410
4216
  collectionId,
3411
4217
  displayField = "name",
3412
4218
  valueField = "name",
3413
4219
  fallbackOptions,
3414
4220
  multiple = false,
4221
+ searchable = false,
3415
4222
  max,
3416
4223
  value,
3417
4224
  onChange
@@ -3454,73 +4261,20 @@ function ReferenceSelect({
3454
4261
  }, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter]);
3455
4262
  if (multiple) {
3456
4263
  const selectedList = Array.isArray(value) ? value.map(String) : typeof value === "string" && value.trim() ? value.split(",").map((s) => s.trim()).filter(Boolean) : [];
3457
- const toggle = (optVal) => {
3458
- if (selectedList.includes(optVal)) {
3459
- onChange(selectedList.filter((s) => s !== optVal));
3460
- } else {
3461
- if (max && selectedList.length >= max) return;
3462
- onChange([...selectedList, optVal]);
4264
+ return /* @__PURE__ */ jsx5(
4265
+ SearchableMultiSelect,
4266
+ {
4267
+ options,
4268
+ value: selectedList,
4269
+ onChange,
4270
+ loading,
4271
+ searchable,
4272
+ placeholder: "Seleccionar opciones...",
4273
+ searchPlaceholder: `Buscar ${collectionId === "sauces" ? "salsa" : collectionId === "extras" ? "adicional" : "opci\xF3n"}...`,
4274
+ emptyMessage: "No hay opciones registradas todav\xEDa.",
4275
+ max
3463
4276
  }
3464
- };
3465
- const selectAll = () => {
3466
- onChange(options.map((o) => o.value));
3467
- };
3468
- const clearAll = () => {
3469
- onChange([]);
3470
- };
3471
- return /* @__PURE__ */ jsxs4("div", { className: "space-y-2.5 rounded-xl border border-slate-200 bg-slate-50/50 p-3", children: [
3472
- /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between text-xs text-slate-500 font-medium pb-1.5 border-b border-slate-200/60", children: [
3473
- /* @__PURE__ */ jsxs4("span", { className: "font-semibold text-slate-700", children: [
3474
- selectedList.length,
3475
- " seleccionada",
3476
- selectedList.length === 1 ? "" : "s",
3477
- max ? ` (m\xE1x. ${max})` : ""
3478
- ] }),
3479
- /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
3480
- /* @__PURE__ */ jsx5(
3481
- "button",
3482
- {
3483
- type: "button",
3484
- onClick: selectAll,
3485
- className: "text-[11px] font-semibold text-indigo-600 hover:text-indigo-800 transition-colors cursor-pointer",
3486
- children: "Seleccionar todas"
3487
- }
3488
- ),
3489
- /* @__PURE__ */ jsx5("span", { className: "text-slate-300", children: "\u2022" }),
3490
- /* @__PURE__ */ jsx5(
3491
- "button",
3492
- {
3493
- type: "button",
3494
- onClick: clearAll,
3495
- className: "text-[11px] font-semibold text-slate-400 hover:text-slate-600 transition-colors cursor-pointer",
3496
- children: "Limpiar"
3497
- }
3498
- )
3499
- ] })
3500
- ] }),
3501
- loading ? /* @__PURE__ */ jsx5("div", { className: "text-xs text-slate-400 py-3 text-center", children: "Cargando opciones..." }) : options.length === 0 ? /* @__PURE__ */ jsx5("div", { className: "text-xs text-slate-400 py-3 text-center", children: "No hay opciones registradas todav\xEDa." }) : /* @__PURE__ */ jsx5("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-2 max-h-52 overflow-y-auto pr-1", children: options.map((o) => {
3502
- const isChecked = selectedList.includes(o.value);
3503
- return /* @__PURE__ */ jsxs4(
3504
- "label",
3505
- {
3506
- className: `flex items-center gap-2.5 p-2 rounded-lg border text-xs font-medium cursor-pointer transition-all ${isChecked ? "bg-indigo-50/70 border-indigo-200 text-indigo-950 font-semibold shadow-xs" : "bg-white border-slate-200 text-slate-700 hover:border-slate-300"}`,
3507
- children: [
3508
- /* @__PURE__ */ jsx5(
3509
- "input",
3510
- {
3511
- type: "checkbox",
3512
- checked: isChecked,
3513
- onChange: () => toggle(o.value),
3514
- className: "w-4 h-4 rounded text-indigo-600 border-slate-300 focus:ring-indigo-500"
3515
- }
3516
- ),
3517
- /* @__PURE__ */ jsx5("span", { className: "truncate", children: o.label })
3518
- ]
3519
- },
3520
- o.value
3521
- );
3522
- }) })
3523
- ] });
4277
+ );
3524
4278
  }
3525
4279
  const singleVal = String(value ?? "");
3526
4280
  const displayOptions = [...options];