admin-lib-cms 1.2.10 → 1.2.11

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
@@ -22,9 +22,21 @@ import {
22
22
  } from "./chunk-4KJKAYIC.mjs";
23
23
 
24
24
  // src/admin/AdminApp.tsx
25
- import { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
25
+ import React, { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
26
26
  import { createPortal } from "react-dom";
27
- import { ConfigProvider, Modal, TimePicker } from "antd";
27
+ import {
28
+ ConfigProvider,
29
+ Modal,
30
+ TimePicker,
31
+ DatePicker,
32
+ Input,
33
+ InputNumber,
34
+ Select,
35
+ Switch,
36
+ Button,
37
+ Image,
38
+ message
39
+ } from "antd";
28
40
  import dayjs from "dayjs";
29
41
  import {
30
42
  FileText,
@@ -56,8 +68,191 @@ import {
56
68
  Check,
57
69
  GripVertical
58
70
  } from "lucide-react";
71
+
72
+ // src/admin/i18n.ts
73
+ var translations = {
74
+ es: {
75
+ menuDashboard: "Dashboard",
76
+ menuPages: "P\xE1ginas",
77
+ menuCollections: "Colecciones",
78
+ menuData: "Datos",
79
+ menuConfig: "Configuraci\xF3n",
80
+ menuSettings: "Ajustes",
81
+ menuSubscription: "Suscripci\xF3n",
82
+ liveEditor: "Editor en vivo",
83
+ viewSite: "Ver sitio",
84
+ signOut: "Cerrar sesi\xF3n",
85
+ signedInAs: "Conectado como",
86
+ saving: "Guardando...",
87
+ saved: "Guardado",
88
+ saveChanges: "Guardar cambios",
89
+ discardChanges: "Descartar",
90
+ unsavedChanges: "Cambios sin guardar",
91
+ desktop: "Escritorio",
92
+ tablet: "Tableta",
93
+ mobile: "M\xF3vil",
94
+ search: "Buscar...",
95
+ filterBy: "Filtrar por...",
96
+ all: "Todos",
97
+ actions: "Acciones",
98
+ edit: "Editar",
99
+ delete: "Eliminar",
100
+ cancel: "Cancelar",
101
+ save: "Guardar",
102
+ create: "Crear",
103
+ newEntry: "Nuevo",
104
+ createNew: "Crear nuevo",
105
+ confirmDeleteTitle: "\xBFEliminar este registro?",
106
+ confirmDeleteText: "Esta acci\xF3n no se puede deshacer.",
107
+ deleteSuccess: "Registro eliminado exitosamente.",
108
+ saveSuccess: "Registro guardado exitosamente.",
109
+ noRecords: "No hay registros disponibles.",
110
+ recordsFound: "registros encontrados",
111
+ back: "Volver",
112
+ apply: "Aplicar",
113
+ close: "Cerrar",
114
+ signatureRegistered: "Firma registrada",
115
+ viewLarger: "Click en la firma para verla en pantalla grande",
116
+ previewMask: "Ver m\xE1s grande",
117
+ addSignature: "AGREGAR FIRMA",
118
+ replaceSignature: "REEMPLAZAR FIRMA",
119
+ uploadImage: "SUBIR IMAGEN",
120
+ uploadNewImage: "SUBIR NUEVA IMAGEN",
121
+ signOnScreen: "Firmar en pantalla",
122
+ signInstructions: "Dibuja la firma en el recuadro usando el dedo o el mouse:",
123
+ clear: "Limpiar",
124
+ saveSignature: "Guardar Firma",
125
+ selectOption: "-- Selecciona una opci\xF3n --",
126
+ loadingOptions: "Cargando opciones...",
127
+ cantFindClient: "\xBFNo encuentras el cliente?",
128
+ createClient: "Crear cliente",
129
+ newBtn: "Nuevo",
130
+ basicDetails: "Datos b\xE1sicos",
131
+ clientType: "Tipo",
132
+ clientDocType: "Tipo de documento",
133
+ clientIdentification: "Identificaci\xF3n",
134
+ clientBranch: "Sucursal o sede",
135
+ clientName: "Nombre",
136
+ clientEmail: "Email",
137
+ clientPhone: "Tel\xE9fono",
138
+ clientCity: "Ciudad",
139
+ clientAddress: "direcci\xF3n",
140
+ clientCreatedSuccess: "Cliente creado y seleccionado exitosamente.",
141
+ idRequired: "La identificaci\xF3n es obligatoria.",
142
+ nameRequired: "El nombre es obligatorio.",
143
+ signInTitle: "Iniciar sesi\xF3n",
144
+ signInSubtitle: "Ingresa tus credenciales para acceder al panel",
145
+ emailLabel: "Correo electr\xF3nico",
146
+ passwordLabel: "Contrase\xF1a",
147
+ signInButton: "Iniciar sesi\xF3n",
148
+ invalidCredentials: "Credenciales inv\xE1lidas",
149
+ loggingIn: "Iniciando sesi\xF3n...",
150
+ submissions: "Mensajes y Formularios",
151
+ noSubmissions: "No hay env\xEDos registrados",
152
+ exportCsv: "Exportar CSV",
153
+ markRead: "Marcar como le\xEDdo",
154
+ settingsTitle: "Ajustes del sitio",
155
+ entries: "registros"
156
+ },
157
+ en: {
158
+ menuDashboard: "Dashboard",
159
+ menuPages: "Pages",
160
+ menuCollections: "Collections",
161
+ menuData: "Data",
162
+ menuConfig: "Settings",
163
+ menuSettings: "Preferences",
164
+ menuSubscription: "Subscription",
165
+ liveEditor: "Live Editor",
166
+ viewSite: "View site",
167
+ signOut: "Sign out",
168
+ signedInAs: "Signed in as",
169
+ saving: "Saving...",
170
+ saved: "Saved",
171
+ saveChanges: "Save changes",
172
+ discardChanges: "Discard",
173
+ unsavedChanges: "Unsaved changes",
174
+ desktop: "Desktop",
175
+ tablet: "Tablet",
176
+ mobile: "Mobile",
177
+ search: "Search...",
178
+ filterBy: "Filter by...",
179
+ all: "All",
180
+ actions: "Actions",
181
+ edit: "Edit",
182
+ delete: "Delete",
183
+ cancel: "Cancel",
184
+ save: "Save",
185
+ create: "Create",
186
+ newEntry: "New",
187
+ createNew: "Create new",
188
+ confirmDeleteTitle: "Delete this record?",
189
+ confirmDeleteText: "This action cannot be undone.",
190
+ deleteSuccess: "Record deleted successfully.",
191
+ saveSuccess: "Record saved successfully.",
192
+ noRecords: "No records found.",
193
+ recordsFound: "records found",
194
+ back: "Back",
195
+ apply: "Apply",
196
+ close: "Close",
197
+ signatureRegistered: "Signature registered",
198
+ viewLarger: "Click signature to view full size",
199
+ previewMask: "View larger",
200
+ addSignature: "ADD SIGNATURE",
201
+ replaceSignature: "REPLACE SIGNATURE",
202
+ uploadImage: "UPLOAD IMAGE",
203
+ uploadNewImage: "UPLOAD NEW IMAGE",
204
+ signOnScreen: "Sign on screen",
205
+ signInstructions: "Draw signature in the box using finger or mouse:",
206
+ clear: "Clear",
207
+ saveSignature: "Save Signature",
208
+ selectOption: "-- Select an option --",
209
+ loadingOptions: "Loading options...",
210
+ cantFindClient: "Can't find the client?",
211
+ createClient: "Create client",
212
+ newBtn: "New",
213
+ basicDetails: "Basic details",
214
+ clientType: "Type",
215
+ clientDocType: "Document type",
216
+ clientIdentification: "Identification",
217
+ clientBranch: "Branch or site",
218
+ clientName: "Name",
219
+ clientEmail: "Email",
220
+ clientPhone: "Phone",
221
+ clientCity: "City",
222
+ clientAddress: "Address",
223
+ clientCreatedSuccess: "Client created and selected successfully.",
224
+ idRequired: "Identification is required.",
225
+ nameRequired: "Name is required.",
226
+ signInTitle: "Sign In",
227
+ signInSubtitle: "Enter your credentials to access the panel",
228
+ emailLabel: "Email address",
229
+ passwordLabel: "Password",
230
+ signInButton: "Sign In",
231
+ invalidCredentials: "Invalid credentials",
232
+ loggingIn: "Signing in...",
233
+ submissions: "Form Submissions",
234
+ noSubmissions: "No submissions yet",
235
+ exportCsv: "Export CSV",
236
+ markRead: "Mark as read",
237
+ settingsTitle: "Site Settings",
238
+ entries: "entries"
239
+ }
240
+ };
241
+ function getAdminTranslations(locale) {
242
+ const norm = String(locale || "").trim().toLowerCase();
243
+ if (norm === "es" || norm.startsWith("es-")) {
244
+ return translations.es;
245
+ }
246
+ return translations.en;
247
+ }
248
+
249
+ // src/admin/AdminApp.tsx
59
250
  import { CreditCard, BarChart3 } from "lucide-react";
60
251
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
252
+ var AdminI18nContext = React.createContext(getAdminTranslations("en"));
253
+ function useAdminI18n() {
254
+ return React.useContext(AdminI18nContext);
255
+ }
61
256
  var TIME_STORAGE_FORMAT = "HH:mm";
62
257
  var TIME_DISPLAY_FORMAT = "h:mm A";
63
258
  var TIME_PICKER_THEME = {
@@ -98,23 +293,24 @@ function AdminTimeRangePicker(props) {
98
293
  }
99
294
  ) });
100
295
  }
101
- function AdminTimePicker(props) {
102
- return /* @__PURE__ */ jsx(ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ jsx(
103
- TimePicker,
104
- {
105
- ...props,
106
- className: `w-full min-w-0 ${props.className ?? ""}`,
107
- style: {
108
- boxShadow: "0 1px 2px rgba(15, 23, 42, 0.08)",
109
- ...props.style
110
- }
111
- }
112
- ) });
113
- }
114
296
  function toDayjsTime(value) {
115
- const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(String(value ?? ""));
116
- if (!match) return null;
117
- return dayjs().hour(Number(match[1])).minute(Number(match[2])).second(0).millisecond(0);
297
+ const str = String(value ?? "").trim();
298
+ if (!str) return null;
299
+ const match12 = /^(\d{1,2}):(\d{2})\s*([ap]\.?m\.?)$/i.exec(str);
300
+ if (match12) {
301
+ let h = Number(match12[1]);
302
+ const m = Number(match12[2]);
303
+ const isPm = match12[3].toLowerCase().startsWith("p");
304
+ if (isPm && h < 12) h += 12;
305
+ if (!isPm && h === 12) h = 0;
306
+ return dayjs().hour(h).minute(m).second(0).millisecond(0);
307
+ }
308
+ const match24 = /^([01]?\d|2[0-3]):([0-5]\d)$/.exec(str);
309
+ if (match24) {
310
+ return dayjs().hour(Number(match24[1])).minute(Number(match24[2])).second(0).millisecond(0);
311
+ }
312
+ const parsed = dayjs(str, ["h:mm a", "h:mm A", "hh:mm a", "hh:mm A", "HH:mm"]);
313
+ return parsed.isValid() ? parsed : null;
118
314
  }
119
315
  function toStoredTime(value) {
120
316
  return value?.format(TIME_STORAGE_FORMAT) ?? "";
@@ -175,6 +371,8 @@ function AdminApp(props) {
175
371
  }
176
372
  function AdminAppContent(props) {
177
373
  const ctx = useCmsContext();
374
+ const rawLocale = props.locale ?? props.lang ?? ctx.config.locale ?? ctx.config.lang ?? "en";
375
+ const t = useMemo(() => getAdminTranslations(rawLocale), [rawLocale]);
178
376
  const hasDashboard = Boolean(props.dashboard);
179
377
  const [section, setSection] = useState(hasDashboard ? "dashboard" : "pages");
180
378
  const [authChecking, setAuthChecking] = useState(true);
@@ -184,13 +382,13 @@ function AdminAppContent(props) {
184
382
  const hideGlobals = props.hideGlobals ?? ctx.config.hideGlobals ?? false;
185
383
  const hideConfig = props.hideConfig ?? ctx.config.hideConfig ?? false;
186
384
  const menuLabels = {
187
- dashboard: "Dashboard",
188
- pages: "P\xE1ginas",
189
- collections: "Colecciones",
190
- data: "Datos",
191
- config: "Configuraci\xF3n",
192
- settings: "Ajustes",
193
- subscription: "Suscripci\xF3n",
385
+ dashboard: t.menuDashboard,
386
+ pages: t.menuPages,
387
+ collections: t.menuCollections,
388
+ data: t.menuData,
389
+ config: t.menuConfig,
390
+ settings: t.menuSettings,
391
+ subscription: t.menuSubscription,
194
392
  ...ctx.config.menuLabels,
195
393
  ...props.menuLabels
196
394
  };
@@ -226,7 +424,7 @@ function AdminAppContent(props) {
226
424
  if (!isSubscriptionActive) {
227
425
  return /* @__PURE__ */ jsx("div", { className: "flex flex-col lg:flex-row h-screen w-full overflow-hidden bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900", children: /* @__PURE__ */ jsx(SubscriptionPage, {}) });
228
426
  }
229
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col h-screen w-full bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900 overflow-hidden", children: [
427
+ return /* @__PURE__ */ jsx(AdminI18nContext.Provider, { value: t, children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col h-screen w-full bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900 overflow-hidden", children: [
230
428
  daysOverdue > 0 && daysOverdue <= 15 && /* @__PURE__ */ jsx("div", { className: "bg-amber-400 text-amber-950 px-4 py-2.5 text-center text-sm font-semibold shadow-sm z-50", children: "Your account has an overdue balance. Please update your payment." }),
231
429
  daysOverdue > 15 && daysOverdue < 30 && /* @__PURE__ */ jsx("div", { className: "bg-rose-600 text-white px-4 py-2.5 text-center text-sm font-bold shadow-sm z-50", children: "Attention: If you do not settle your balance, your account will be suspended soon." }),
232
430
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col lg:flex-row flex-1 overflow-hidden relative", children: [
@@ -242,81 +440,155 @@ function AdminAppContent(props) {
242
440
  ] }),
243
441
  /* @__PURE__ */ jsx("div", { className: "truncate font-bold text-lg text-slate-900", children: ctx.config.siteName ?? "Site Administration" })
244
442
  ] }),
245
- /* @__PURE__ */ jsxs("nav", { className: "flex flex-row lg:flex-col overflow-x-auto lg:overflow-visible space-x-2 lg:space-x-0 lg:space-y-1.5 p-3 lg:p-4 text-sm font-medium hide-scrollbar", children: [
246
- hasDashboard && /* @__PURE__ */ jsx(
247
- SideItem,
248
- {
249
- active: section === "dashboard",
250
- onClick: () => setSection("dashboard"),
251
- icon: /* @__PURE__ */ jsx(BarChart3, { className: "h-4 w-4 shrink-0" }),
252
- children: menuLabels.dashboard
253
- }
254
- ),
255
- props.customSections?.map((cs) => /* @__PURE__ */ jsx(
256
- SideItem,
257
- {
258
- active: section === cs.id,
259
- onClick: () => setSection(cs.id),
260
- icon: cs.icon || /* @__PURE__ */ jsx(Boxes, { className: "h-4 w-4 shrink-0" }),
261
- children: cs.label
262
- },
263
- cs.id
264
- )),
265
- /* @__PURE__ */ jsx(
266
- SideItem,
267
- {
268
- active: section === "pages",
269
- onClick: () => setSection("pages"),
270
- icon: /* @__PURE__ */ jsx(FileText, { className: "h-4 w-4 shrink-0" }),
271
- children: menuLabels.pages
272
- }
273
- ),
274
- /* @__PURE__ */ jsx(
275
- SideItem,
276
- {
277
- active: section === "collections",
278
- onClick: () => setSection("collections"),
279
- icon: /* @__PURE__ */ jsx(Boxes, { className: "h-4 w-4 shrink-0" }),
280
- children: menuLabels.collections
281
- }
282
- ),
283
- !hideData && /* @__PURE__ */ jsx(
284
- SideItem,
285
- {
286
- active: section === "submissions",
287
- onClick: () => setSection("submissions"),
288
- icon: /* @__PURE__ */ jsx(Inbox, { className: "h-4 w-4 shrink-0" }),
289
- children: menuLabels.data
290
- }
291
- ),
292
- !hideConfig && !hideGlobals && /* @__PURE__ */ jsx(
293
- SideItem,
294
- {
295
- active: section === "config",
296
- onClick: () => setSection("config"),
297
- icon: /* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-4 w-4 shrink-0" }),
298
- children: menuLabels.config
299
- }
300
- ),
301
- !hideSettings && /* @__PURE__ */ jsx(
302
- SideItem,
303
- {
304
- active: section === "settings",
305
- onClick: () => setSection("settings"),
306
- icon: /* @__PURE__ */ jsx(SettingsIcon, { className: "h-4 w-4 shrink-0" }),
307
- children: menuLabels.settings
308
- }
309
- ),
310
- subscriptionCtx && /* @__PURE__ */ jsx(
311
- SideItem,
312
- {
313
- active: section === "subscription",
314
- onClick: () => setSection("subscription"),
315
- icon: /* @__PURE__ */ jsx(CreditCard, { className: "h-4 w-4 shrink-0" }),
316
- children: menuLabels.subscription
317
- }
318
- )
319
- ] }),
443
+ /* @__PURE__ */ jsx("nav", { className: "flex flex-row lg:flex-col overflow-x-auto lg:overflow-visible space-x-2 lg:space-x-0 lg:space-y-1.5 p-3 lg:p-4 text-sm font-medium hide-scrollbar", children: (() => {
444
+ const navItemsMap = /* @__PURE__ */ new Map();
445
+ if (hasDashboard) {
446
+ navItemsMap.set(
447
+ "dashboard",
448
+ /* @__PURE__ */ jsx(
449
+ SideItem,
450
+ {
451
+ active: section === "dashboard",
452
+ onClick: () => setSection("dashboard"),
453
+ icon: /* @__PURE__ */ jsx(BarChart3, { className: "h-4 w-4 shrink-0" }),
454
+ children: menuLabels.dashboard
455
+ },
456
+ "dashboard"
457
+ )
458
+ );
459
+ }
460
+ navItemsMap.set(
461
+ "pages",
462
+ /* @__PURE__ */ jsx(
463
+ SideItem,
464
+ {
465
+ active: section === "pages",
466
+ onClick: () => setSection("pages"),
467
+ icon: /* @__PURE__ */ jsx(FileText, { className: "h-4 w-4 shrink-0" }),
468
+ children: menuLabels.pages
469
+ },
470
+ "pages"
471
+ )
472
+ );
473
+ navItemsMap.set(
474
+ "collections",
475
+ /* @__PURE__ */ jsx(
476
+ SideItem,
477
+ {
478
+ active: section === "collections",
479
+ onClick: () => setSection("collections"),
480
+ icon: /* @__PURE__ */ jsx(Boxes, { className: "h-4 w-4 shrink-0" }),
481
+ children: menuLabels.collections
482
+ },
483
+ "collections"
484
+ )
485
+ );
486
+ props.customSections?.forEach((cs) => {
487
+ navItemsMap.set(
488
+ cs.id,
489
+ /* @__PURE__ */ jsx(
490
+ SideItem,
491
+ {
492
+ active: section === cs.id,
493
+ onClick: () => setSection(cs.id),
494
+ icon: cs.icon || /* @__PURE__ */ jsx(Boxes, { className: "h-4 w-4 shrink-0" }),
495
+ children: cs.label
496
+ },
497
+ cs.id
498
+ )
499
+ );
500
+ });
501
+ if (!hideData) {
502
+ navItemsMap.set(
503
+ "submissions",
504
+ /* @__PURE__ */ jsx(
505
+ SideItem,
506
+ {
507
+ active: section === "submissions",
508
+ onClick: () => setSection("submissions"),
509
+ icon: /* @__PURE__ */ jsx(Inbox, { className: "h-4 w-4 shrink-0" }),
510
+ children: menuLabels.data
511
+ },
512
+ "submissions"
513
+ )
514
+ );
515
+ }
516
+ if (!hideConfig && !hideGlobals) {
517
+ navItemsMap.set(
518
+ "config",
519
+ /* @__PURE__ */ jsx(
520
+ SideItem,
521
+ {
522
+ active: section === "config",
523
+ onClick: () => setSection("config"),
524
+ icon: /* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-4 w-4 shrink-0" }),
525
+ children: menuLabels.config
526
+ },
527
+ "config"
528
+ )
529
+ );
530
+ }
531
+ if (!hideSettings) {
532
+ navItemsMap.set(
533
+ "settings",
534
+ /* @__PURE__ */ jsx(
535
+ SideItem,
536
+ {
537
+ active: section === "settings",
538
+ onClick: () => setSection("settings"),
539
+ icon: /* @__PURE__ */ jsx(SettingsIcon, { className: "h-4 w-4 shrink-0" }),
540
+ children: menuLabels.settings
541
+ },
542
+ "settings"
543
+ )
544
+ );
545
+ }
546
+ if (subscriptionCtx) {
547
+ navItemsMap.set(
548
+ "subscription",
549
+ /* @__PURE__ */ jsx(
550
+ SideItem,
551
+ {
552
+ active: section === "subscription",
553
+ onClick: () => setSection("subscription"),
554
+ icon: /* @__PURE__ */ jsx(CreditCard, { className: "h-4 w-4 shrink-0" }),
555
+ children: menuLabels.subscription
556
+ },
557
+ "subscription"
558
+ )
559
+ );
560
+ }
561
+ const orderedKeys = [];
562
+ if (props.menuOrder && Array.isArray(props.menuOrder) && props.menuOrder.length > 0) {
563
+ props.menuOrder.forEach((k) => {
564
+ if (navItemsMap.has(k) && !orderedKeys.includes(k)) {
565
+ orderedKeys.push(k);
566
+ }
567
+ });
568
+ navItemsMap.forEach((_, k) => {
569
+ if (!orderedKeys.includes(k)) {
570
+ orderedKeys.push(k);
571
+ }
572
+ });
573
+ } else {
574
+ const topCustom = (props.customSections || []).filter((cs) => cs.position === "top").map((cs) => cs.id);
575
+ const bottomCustom = (props.customSections || []).filter((cs) => cs.position === "bottom" || cs.position === "after-collections").map((cs) => cs.id);
576
+ const otherCustom = (props.customSections || []).filter(
577
+ (cs) => cs.position !== "top" && cs.position !== "bottom" && cs.position !== "after-collections"
578
+ ).map((cs) => cs.id);
579
+ if (hasDashboard) orderedKeys.push("dashboard");
580
+ topCustom.forEach((k) => orderedKeys.push(k));
581
+ orderedKeys.push("pages");
582
+ orderedKeys.push("collections");
583
+ otherCustom.forEach((k) => orderedKeys.push(k));
584
+ bottomCustom.forEach((k) => orderedKeys.push(k));
585
+ if (!hideData) orderedKeys.push("submissions");
586
+ if (!hideConfig && !hideGlobals) orderedKeys.push("config");
587
+ if (!hideSettings) orderedKeys.push("settings");
588
+ if (subscriptionCtx) orderedKeys.push("subscription");
589
+ }
590
+ return orderedKeys.map((k) => navItemsMap.get(k));
591
+ })() }),
320
592
  /* @__PURE__ */ jsx("div", { className: "hidden lg:block mt-auto border-t border-slate-200 p-4 bg-slate-50/50", children: /* @__PURE__ */ jsxs(
321
593
  "button",
322
594
  {
@@ -327,7 +599,7 @@ function AdminAppContent(props) {
327
599
  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",
328
600
  children: [
329
601
  /* @__PURE__ */ jsx(LogOut, { className: "w-4 h-4" }),
330
- "Logout"
602
+ t.signOut
331
603
  ]
332
604
  }
333
605
  ) })
@@ -345,7 +617,7 @@ function AdminAppContent(props) {
345
617
  )
346
618
  ] })
347
619
  ] })
348
- ] });
620
+ ] }) });
349
621
  }
350
622
  function SideItem({
351
623
  active,
@@ -454,6 +726,7 @@ function PagesSection() {
454
726
  }
455
727
  function PageEditor({ page, showList, onToggleList }) {
456
728
  const ctx = useCmsContext();
729
+ const t = useAdminI18n();
457
730
  const iframeRef = useRef(null);
458
731
  const [registered, setRegistered] = useState([]);
459
732
  const [selectedId, setSelectedId] = useState(null);
@@ -547,7 +820,7 @@ function PageEditor({ page, showList, onToggleList }) {
547
820
  className: "inline-flex items-center gap-1.5 rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-50 hover:text-slate-900 disabled:opacity-50 transition-colors bg-white shadow-sm shrink-0",
548
821
  children: [
549
822
  /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" }),
550
- "Discard"
823
+ t.discardChanges
551
824
  ]
552
825
  }
553
826
  ),
@@ -559,7 +832,7 @@ function PageEditor({ page, showList, onToggleList }) {
559
832
  className: "inline-flex items-center gap-1.5 rounded-lg bg-indigo-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-indigo-700 disabled:opacity-50 transition-colors shadow-sm shrink-0",
560
833
  children: [
561
834
  /* @__PURE__ */ jsx(Boxes, { className: "h-3.5 w-3.5" }),
562
- "Save"
835
+ t.save
563
836
  ]
564
837
  }
565
838
  )
@@ -1392,13 +1665,18 @@ function CollectionsSection() {
1392
1665
  collections.find((c) => !c.isSeparator) ?? null
1393
1666
  );
1394
1667
  const [counts, setCounts] = useState({});
1668
+ const colIds = useMemo(
1669
+ () => (ctx.config.collections ?? []).filter((c) => !c.isSeparator).map((c) => c.id).join(","),
1670
+ [ctx.config.collections]
1671
+ );
1395
1672
  useEffect(() => {
1396
- collections.filter((c) => !c.isSeparator).forEach((c) => {
1673
+ const list = ctx.config.collections ?? [];
1674
+ list.filter((c) => !c.isSeparator).forEach((c) => {
1397
1675
  ctx.adapter.listEntries(c.id).then((entries) => {
1398
- setCounts((prev) => ({ ...prev, [c.id]: entries.length }));
1676
+ setCounts((prev) => prev[c.id] === entries.length ? prev : { ...prev, [c.id]: entries.length });
1399
1677
  });
1400
1678
  });
1401
- }, [ctx.adapter, collections]);
1679
+ }, [ctx.adapter, colIds, ctx.collectionChangedAt]);
1402
1680
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col md:flex-row h-full bg-slate-50", children: [
1403
1681
  /* @__PURE__ */ jsxs("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-4", children: [
1404
1682
  /* @__PURE__ */ jsx("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
@@ -1408,7 +1686,8 @@ function CollectionsSection() {
1408
1686
  return /* @__PURE__ */ jsx(
1409
1687
  "li",
1410
1688
  {
1411
- className: "my-2 border-t border-slate-200/80"
1689
+ className: "my-3 border-t border-slate-200/80 pt-2 px-1 list-none",
1690
+ children: c.name && /* @__PURE__ */ jsx("span", { className: "text-[10px] font-bold uppercase tracking-wider text-slate-400", children: c.name })
1412
1691
  },
1413
1692
  c.id || `sep-${idx}`
1414
1693
  );
@@ -1451,6 +1730,7 @@ function CollectionsSection() {
1451
1730
  }
1452
1731
  function CollectionEditor({ collection }) {
1453
1732
  const ctx = useCmsContext();
1733
+ const t = useAdminI18n();
1454
1734
  const [entries, setEntries] = useState([]);
1455
1735
  const [editing, setEditing] = useState(null);
1456
1736
  const [saving, setSaving] = useState(false);
@@ -1512,6 +1792,16 @@ function CollectionEditor({ collection }) {
1512
1792
  try {
1513
1793
  const finalEditing = { ...editing };
1514
1794
  collection.fields.forEach((f) => {
1795
+ if (f.autoIncrement && isCreatingEntry && (!finalEditing[f.id] || Number(finalEditing[f.id]) === 0)) {
1796
+ const maxVal = entries.reduce(
1797
+ (max, e) => Math.max(max, Number(e[f.id]) || 0),
1798
+ 0
1799
+ );
1800
+ finalEditing[f.id] = maxVal > 0 ? maxVal + 1 : 1;
1801
+ }
1802
+ if (f.id === "estado" && !finalEditing[f.id]) {
1803
+ finalEditing[f.id] = "Nueva";
1804
+ }
1515
1805
  if (f.type === "time-range") {
1516
1806
  delete finalEditing[f.id];
1517
1807
  } else if (f.type === "slug" && !finalEditing[f.id]) {
@@ -1575,7 +1865,7 @@ function CollectionEditor({ collection }) {
1575
1865
  setDraggedIdx(null);
1576
1866
  setDragOverIdx(null);
1577
1867
  };
1578
- const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 5);
1868
+ const visibleFields = collection.tableFields?.length ? collection.tableFields.map((tf) => collection.fields.find((f) => f.id === tf)).filter(Boolean) : collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 6);
1579
1869
  const isCreatingEntry = editing ? !entries.some((entry) => entry.id === editing.id) : false;
1580
1870
  return /* @__PURE__ */ jsxs("div", { className: "mx-auto max-w-5xl", children: [
1581
1871
  /* @__PURE__ */ jsxs("div", { className: "mb-8 flex items-center justify-between", children: [
@@ -1583,69 +1873,110 @@ function CollectionEditor({ collection }) {
1583
1873
  /* @__PURE__ */ jsx("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight", children: collection.name }),
1584
1874
  collection.description && /* @__PURE__ */ jsx("p", { className: "text-sm text-slate-500 mt-1", children: collection.description })
1585
1875
  ] }),
1586
- /* @__PURE__ */ jsxs(
1587
- "button",
1876
+ /* @__PURE__ */ jsx(
1877
+ Button,
1588
1878
  {
1879
+ type: "primary",
1880
+ size: "large",
1881
+ icon: /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
1589
1882
  onClick: startNew,
1590
- className: "inline-flex items-center gap-2 rounded-xl bg-indigo-600 px-4 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-indigo-700 hover:shadow transition-all",
1591
- children: [
1592
- /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
1593
- " New Entry"
1594
- ]
1883
+ className: "rounded-xl font-bold shadow-sm",
1884
+ children: t.newEntry
1595
1885
  }
1596
1886
  )
1597
1887
  ] }),
1598
1888
  !editing && (collection.searchBy?.length || collection.filterBy?.length) && /* @__PURE__ */ jsxs("div", { className: "mb-6 flex flex-wrap gap-4 items-center p-4 bg-white rounded-2xl border border-slate-200 shadow-sm animate-in fade-in slide-in-from-top-2", children: [
1599
- collection.searchBy?.length ? /* @__PURE__ */ jsxs("div", { className: "relative flex-1 min-w-[200px]", children: [
1600
- /* @__PURE__ */ jsx(Search, { className: "absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" }),
1601
- /* @__PURE__ */ jsx(
1602
- "input",
1603
- {
1604
- type: "text",
1605
- placeholder: `Search by ${collection.searchBy.join(", ")}...`,
1606
- value: search,
1607
- onChange: (e) => {
1608
- setSearch(e.target.value);
1609
- setPage(1);
1610
- },
1611
- className: "w-full rounded-xl border border-slate-200 bg-slate-50 py-2.5 pl-10 pr-4 text-sm focus:border-indigo-500 focus:bg-white focus:ring-4 focus:ring-indigo-500/10 outline-none transition-all"
1612
- }
1613
- )
1614
- ] }) : null,
1889
+ collection.searchBy?.length ? /* @__PURE__ */ jsx("div", { className: "relative flex-1 min-w-[220px]", children: /* @__PURE__ */ jsx(
1890
+ Input,
1891
+ {
1892
+ size: "large",
1893
+ prefix: /* @__PURE__ */ jsx(Search, { className: "h-4 w-4 text-slate-400" }),
1894
+ placeholder: `Buscar por ${collection.searchBy.map((s) => s === "numero" ? "n\xFAmero" : s === "clienteNombre" ? "cliente" : s === "clienteId" ? "identificaci\xF3n" : s === "fecha" ? "fecha" : s).join(", ")}...`,
1895
+ value: search,
1896
+ allowClear: true,
1897
+ onChange: (e) => {
1898
+ setSearch(e.target.value);
1899
+ setPage(1);
1900
+ },
1901
+ className: "rounded-xl"
1902
+ }
1903
+ ) }) : null,
1615
1904
  collection.filterBy?.map((f) => {
1616
1905
  const fieldDef = collection.fields.find((cf) => cf.id === f);
1617
- const uniqueVals = Array.from(new Set(entries.map((e) => String(e[f] || "")))).filter(Boolean);
1618
- if (!fieldDef || uniqueVals.length === 0) return null;
1619
- return /* @__PURE__ */ jsxs("div", { className: "min-w-[150px] relative", children: [
1620
- /* @__PURE__ */ jsxs(
1621
- "select",
1906
+ if (!fieldDef) return null;
1907
+ if (fieldDef.type === "date") {
1908
+ const dateVal = filters[f] ? dayjs(filters[f], ["YYYY/MM/DD", "YYYY-MM-DD", "YYYY-M-D"]).isValid() ? dayjs(filters[f], ["YYYY/MM/DD", "YYYY-MM-DD", "YYYY-M-D"]) : null : null;
1909
+ return /* @__PURE__ */ jsx("div", { className: "min-w-[180px]", children: /* @__PURE__ */ jsx(
1910
+ DatePicker,
1622
1911
  {
1623
- value: filters[f] || "",
1624
- onChange: (e) => {
1625
- setFilters((prev) => ({ ...prev, [f]: e.target.value }));
1912
+ size: "large",
1913
+ format: "YYYY/MM/DD",
1914
+ placeholder: `Filtrar por ${fieldDef.label}`,
1915
+ allowClear: true,
1916
+ value: dateVal,
1917
+ onChange: (_, dateStr) => {
1918
+ const val = Array.isArray(dateStr) ? dateStr[0] : dateStr;
1919
+ setFilters((prev) => ({ ...prev, [f]: val || "" }));
1626
1920
  setPage(1);
1627
1921
  },
1628
- className: "w-full rounded-xl border border-slate-200 bg-slate-50 py-2.5 px-4 pr-10 text-sm focus:border-indigo-500 focus:bg-white focus:ring-4 focus:ring-indigo-500/10 outline-none transition-all appearance-none",
1629
- children: [
1630
- /* @__PURE__ */ jsxs("option", { value: "", children: [
1631
- "All ",
1632
- fieldDef.label
1633
- ] }),
1634
- uniqueVals.map((v) => /* @__PURE__ */ jsx("option", { value: v, children: v }, v))
1635
- ]
1922
+ className: "w-full rounded-xl"
1636
1923
  }
1637
- ),
1638
- /* @__PURE__ */ jsx(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
1639
- ] }, f);
1924
+ ) }, f);
1925
+ }
1926
+ const predefinedOptions = (fieldDef.options || []).map(
1927
+ (opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
1928
+ );
1929
+ const entryVals = Array.from(new Set(entries.map((e) => String(e[f] || "")))).filter(Boolean);
1930
+ const combinedOptions = [...predefinedOptions];
1931
+ for (const ev of entryVals) {
1932
+ if (!combinedOptions.some((o) => o.value === ev)) {
1933
+ combinedOptions.push({ value: ev, label: ev });
1934
+ }
1935
+ }
1936
+ return /* @__PURE__ */ jsx("div", { className: "min-w-[170px]", children: /* @__PURE__ */ jsx(
1937
+ Select,
1938
+ {
1939
+ size: "large",
1940
+ value: filters[f] || void 0,
1941
+ placeholder: `Filtrar por ${fieldDef.label}`,
1942
+ allowClear: true,
1943
+ onChange: (v) => {
1944
+ setFilters((prev) => ({ ...prev, [f]: v || "" }));
1945
+ setPage(1);
1946
+ },
1947
+ options: combinedOptions,
1948
+ className: "w-full"
1949
+ }
1950
+ ) }, f);
1640
1951
  })
1641
1952
  ] }),
1642
1953
  /* @__PURE__ */ jsx(
1643
1954
  Modal,
1644
1955
  {
1645
1956
  open: Boolean(editing),
1646
- title: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-slate-900", children: [
1647
- isCreatingEntry ? /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4 text-indigo-600" }),
1648
- isCreatingEntry ? "Create Entry" : "Edit Entry"
1957
+ title: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between pr-8", children: [
1958
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-slate-900 font-bold", children: [
1959
+ isCreatingEntry ? /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4 text-indigo-600" }),
1960
+ isCreatingEntry ? collection.createTitle || `Nueva ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}` : `Editar ${collection.name.endsWith("s") ? collection.name.slice(0, -1) : collection.name}`
1961
+ ] }),
1962
+ !isCreatingEntry && editing && editing.estado !== void 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1963
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-slate-400 font-medium", children: "Estado:" }),
1964
+ /* @__PURE__ */ jsx(
1965
+ Select,
1966
+ {
1967
+ size: "middle",
1968
+ value: String(editing.estado || "Nueva"),
1969
+ onChange: (val) => setEditing({ ...editing, estado: val }),
1970
+ options: [
1971
+ { value: "Nueva", label: "Nueva" },
1972
+ { value: "Proceso", label: "Proceso" },
1973
+ { value: "Terminado", label: "Terminado" },
1974
+ { value: "Cancelado", label: "Cancelado" }
1975
+ ],
1976
+ className: "w-32"
1977
+ }
1978
+ )
1979
+ ] })
1649
1980
  ] }),
1650
1981
  onCancel: () => {
1651
1982
  if (!saving) setEditing(null);
@@ -1669,463 +2000,556 @@ function CollectionEditor({ collection }) {
1669
2000
  backdropFilter: "blur(8px)"
1670
2001
  }
1671
2002
  },
1672
- children: editing && /* @__PURE__ */ jsxs("div", { className: "flex max-h-[calc(100dvh-180px)] min-h-0 flex-col", children: [
1673
- /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1 overflow-y-auto px-6 py-5", children: /* @__PURE__ */ jsx("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__ */ jsxs("div", { className: `block ${f.type === "richtext" || f.type === "textarea" || f.type === "list" || f.type === "branch-settings" || f.type === "time-range" ? "lg:col-span-2" : ""}`, children: [
1674
- /* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
1675
- f.label,
1676
- /* @__PURE__ */ jsx("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
1677
- ] }),
1678
- f.type === "branch-settings" ? /* @__PURE__ */ jsx(
1679
- BranchSettingsEditor,
1680
- {
1681
- collectionId: f.collection || "",
1682
- value: editing[f.id],
1683
- globalPrice: Number(editing.price) || 0,
1684
- globalDiscount: Number(editing.discountPercent) || 0,
1685
- onChange: (val) => setEditing({ ...editing, [f.id]: val })
2003
+ children: editing && /* @__PURE__ */ jsx(ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ jsxs("div", { className: "flex max-h-[calc(100dvh-180px)] min-h-0 flex-col", children: [
2004
+ /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1 overflow-y-auto px-6 py-5", children: /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-5 lg:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order" && !f.hidden).filter((f) => {
2005
+ if (f.id === "estado" && !isCreatingEntry) return false;
2006
+ if (isCreatingEntry && f.hideOnCreate) return false;
2007
+ if (f.dependsOn) {
2008
+ const targetVal = editing[f.dependsOn.field];
2009
+ if (Array.isArray(f.dependsOn.value)) {
2010
+ if (!f.dependsOn.value.includes(targetVal)) return false;
2011
+ } else if (targetVal !== f.dependsOn.value) {
2012
+ return false;
1686
2013
  }
1687
- ) : f.type === "boolean" ? /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-3", children: [
1688
- /* @__PURE__ */ jsxs("label", { className: "relative inline-flex items-center cursor-pointer select-none", children: [
2014
+ }
2015
+ return true;
2016
+ }).map((f) => {
2017
+ const isFullWidth = f.colSpan === 2 || f.colSpan === 12 || f.type === "signature" || f.type === "date" || f.type === "datetime" || f.type === "richtext" || f.type === "textarea" || f.type === "list" || f.type === "branch-settings" || f.type === "time-range";
2018
+ const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
2019
+ return /* @__PURE__ */ jsxs("div", { className: `block ${colSpanClass}`, children: [
2020
+ /* @__PURE__ */ jsxs("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
2021
+ f.label,
2022
+ /* @__PURE__ */ jsx("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
2023
+ ] }),
2024
+ f.type === "branch-settings" ? /* @__PURE__ */ jsx(
2025
+ BranchSettingsEditor,
2026
+ {
2027
+ collectionId: f.collection || "",
2028
+ value: editing[f.id],
2029
+ globalPrice: Number(editing.price) || 0,
2030
+ globalDiscount: Number(editing.discountPercent) || 0,
2031
+ onChange: (val) => setEditing({ ...editing, [f.id]: val })
2032
+ }
2033
+ ) : f.type === "boolean" ? /* @__PURE__ */ jsxs("div", { className: "mt-1 flex items-center gap-3", children: [
1689
2034
  /* @__PURE__ */ jsx(
1690
- "input",
2035
+ Switch,
1691
2036
  {
1692
- type: "checkbox",
1693
2037
  checked: !!editing[f.id],
1694
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.checked }),
1695
- className: "sr-only peer"
2038
+ onChange: (checked) => setEditing({ ...editing, [f.id]: checked })
1696
2039
  }
1697
2040
  ),
1698
- /* @__PURE__ */ jsx("div", { className: "w-11 h-6 bg-slate-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-slate-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600" })
1699
- ] }),
1700
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-slate-700", children: editing[f.id] ? "Activado / S\xED" : "Desactivado / No" })
1701
- ] }) : f.type === "number" ? /* @__PURE__ */ jsx(
1702
- FormattedNumberInput,
1703
- {
1704
- value: editing[f.id],
1705
- onChange: (val) => setEditing({ ...editing, [f.id]: val }),
1706
- isPrice: f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.toLowerCase().includes("valor") || f.label.includes("$"),
1707
- isPercent: f.id.toLowerCase().includes("discount") || f.id.toLowerCase().includes("descuento") || f.label.toLowerCase().includes("descuento")
1708
- }
1709
- ) : f.type === "time-range" ? /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
1710
- /* @__PURE__ */ jsx(
1711
- AdminTimeRangePicker,
2041
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-slate-700", children: editing[f.id] ? "Activado / S\xED" : "Desactivado / No" })
2042
+ ] }) : f.type === "number" ? /* @__PURE__ */ jsx(
2043
+ InputNumber,
1712
2044
  {
1713
- value: [
1714
- toDayjsTime(f.startField ? editing[f.startField] : ""),
1715
- toDayjsTime(f.endField ? editing[f.endField] : "")
1716
- ],
1717
- onChange: (times) => setEditing(
1718
- (current) => current ? {
1719
- ...current,
1720
- ...f.startField ? { [f.startField]: toStoredTime(times?.[0]) } : {},
1721
- ...f.endField ? { [f.endField]: toStoredTime(times?.[1]) } : {}
1722
- } : current
1723
- ),
1724
- allowEmpty: [true, true],
1725
- className: "w-full",
1726
- format: TIME_DISPLAY_FORMAT,
1727
- order: false,
1728
- placeholder: ["Hora de inicio", "Hora de cierre"],
1729
- use12Hours: true
2045
+ size: "large",
2046
+ value: editing[f.id] !== void 0 && editing[f.id] !== null && editing[f.id] !== "" ? Number(editing[f.id]) : void 0,
2047
+ readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
2048
+ disabled: f.readOnly,
2049
+ onChange: (val) => setEditing({ ...editing, [f.id]: val ?? 0 }),
2050
+ className: "w-full rounded-xl",
2051
+ placeholder: "0"
1730
2052
  }
1731
- ),
1732
- /* @__PURE__ */ jsx("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." })
1733
- ] }) : f.type === "time" ? /* @__PURE__ */ jsx(
1734
- AdminTimePicker,
1735
- {
1736
- value: toDayjsTime(editing[f.id]),
1737
- onChange: (time) => setEditing({ ...editing, [f.id]: toStoredTime(time) }),
1738
- className: "w-full",
1739
- format: TIME_DISPLAY_FORMAT,
1740
- use12Hours: true
1741
- }
1742
- ) : f.type === "richtext" || f.type === "textarea" ? /* @__PURE__ */ jsx(
1743
- "textarea",
1744
- {
1745
- value: String(editing[f.id] ?? ""),
1746
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1747
- rows: 4,
1748
- placeholder: `Escribe ${f.label.toLowerCase()}...`,
1749
- 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-sans text-slate-800"
1750
- }
1751
- ) : f.type === "icon" ? /* @__PURE__ */ jsx(
1752
- SearchableSelect,
1753
- {
1754
- value: String(editing[f.id] ?? ""),
1755
- onChange: (val) => setEditing({ ...editing, [f.id]: val }),
1756
- options: f.options?.length ? f.options : ctx.iconMap ? Object.keys(ctx.iconMap) : [],
1757
- placeholder: `Buscar icono ${f.label.toLowerCase()}...`,
1758
- iconMap: ctx.iconMap
1759
- }
1760
- ) : f.type === "slug" ? /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1761
- /* @__PURE__ */ jsx(
1762
- "input",
2053
+ ) : f.type === "date" || f.type === "datetime" ? /* @__PURE__ */ jsx(
2054
+ DatePicker,
1763
2055
  {
1764
- type: "text",
1765
- value: String(editing[f.id] ?? ""),
1766
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1767
- 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"
2056
+ size: "large",
2057
+ value: editing[f.id] ? dayjs(String(editing[f.id])).isValid() ? dayjs(String(editing[f.id])) : null : null,
2058
+ onChange: (date, dateString) => setEditing({ ...editing, [f.id]: (Array.isArray(dateString) ? dateString[0] : dateString) || (date ? date.format("YYYY/MM/DD") : "") }),
2059
+ format: "YYYY/MM/DD",
2060
+ placeholder: `Seleccionar ${f.label.toLowerCase()}...`,
2061
+ className: "w-full rounded-xl"
1768
2062
  }
1769
- ),
1770
- /* @__PURE__ */ jsx(
1771
- "button",
2063
+ ) : f.type === "time-range" ? /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
2064
+ /* @__PURE__ */ jsx(
2065
+ AdminTimeRangePicker,
2066
+ {
2067
+ value: [
2068
+ toDayjsTime(f.startField ? editing[f.startField] : ""),
2069
+ toDayjsTime(f.endField ? editing[f.endField] : "")
2070
+ ],
2071
+ onChange: (times) => setEditing(
2072
+ (current) => current ? {
2073
+ ...current,
2074
+ ...f.startField ? { [f.startField]: toStoredTime(times?.[0]) } : {},
2075
+ ...f.endField ? { [f.endField]: toStoredTime(times?.[1]) } : {}
2076
+ } : current
2077
+ ),
2078
+ allowEmpty: [true, true],
2079
+ className: "w-full",
2080
+ format: "h:mm a",
2081
+ order: false,
2082
+ placeholder: ["Hora de inicio", "Hora de cierre"],
2083
+ use12Hours: true
2084
+ }
2085
+ ),
2086
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-500", children: "Selecciona inicio y cierre en un mismo control. Usa AM/PM. Deja ambos vac\xEDos para mantenerlo siempre disponible." })
2087
+ ] }) : f.type === "time" ? /* @__PURE__ */ jsx(
2088
+ TimePicker,
1772
2089
  {
1773
- type: "button",
1774
- onClick: () => {
1775
- const sourceField = f.source || "title";
1776
- let val = String(editing[sourceField] || editing.id || "");
1777
- val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
1778
- setEditing({ ...editing, [f.id]: val });
1779
- },
1780
- 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",
1781
- children: "Generate"
2090
+ size: "large",
2091
+ use12Hours: true,
2092
+ format: "h:mm a",
2093
+ value: toDayjsTime(editing[f.id]),
2094
+ onChange: (time, timeString) => setEditing({
2095
+ ...editing,
2096
+ [f.id]: (Array.isArray(timeString) ? timeString[0] : timeString) || (time ? time.format("h:mm a") : "")
2097
+ }),
2098
+ placeholder: `Seleccionar ${f.label.toLowerCase()}...`,
2099
+ className: "w-full rounded-xl"
1782
2100
  }
1783
- )
1784
- ] }) : f.type === "reference" || f.type === "select" && f.collection ? /* @__PURE__ */ jsx(
1785
- ReferenceSelect,
1786
- {
1787
- collectionId: f.collection,
1788
- displayField: f.displayField,
1789
- valueField: f.valueField,
1790
- fallbackOptions: f.options,
1791
- multiple: f.multiple,
1792
- searchable: f.searchable,
1793
- max: f.max,
1794
- value: editing[f.id],
1795
- onChange: (val) => setEditing({ ...editing, [f.id]: val })
1796
- }
1797
- ) : f.type === "select" ? /* @__PURE__ */ jsxs("div", { className: "relative", children: [
1798
- /* @__PURE__ */ jsxs(
1799
- "select",
2101
+ ) : f.type === "richtext" || f.type === "textarea" ? /* @__PURE__ */ jsx(
2102
+ Input.TextArea,
1800
2103
  {
2104
+ size: "large",
1801
2105
  value: String(editing[f.id] ?? ""),
1802
2106
  onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1803
- 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",
1804
- children: [
1805
- /* @__PURE__ */ jsx("option", { value: "", children: "-- Selecciona una opci\xF3n --" }),
1806
- f.options?.map((opt) => {
1807
- const val = typeof opt === "string" ? opt : opt.value;
1808
- const lab = typeof opt === "string" ? opt : opt.label;
1809
- return /* @__PURE__ */ jsx("option", { value: val, children: lab }, val);
1810
- })
1811
- ]
2107
+ rows: 4,
2108
+ placeholder: `Escribe ${f.label.toLowerCase()}...`,
2109
+ className: "w-full rounded-xl font-sans"
1812
2110
  }
1813
- ),
1814
- /* @__PURE__ */ jsx(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
1815
- ] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1816
- /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
1817
- const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
1818
- return /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
1819
- isVideo ? /* @__PURE__ */ jsx("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ jsx("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
1820
- /* @__PURE__ */ jsx(
1821
- "button",
1822
- {
1823
- type: "button",
1824
- onClick: () => {
1825
- const arr = [...editing[f.id] || []];
1826
- arr.splice(i, 1);
1827
- setEditing({ ...editing, [f.id]: arr });
1828
- },
1829
- 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",
1830
- children: /* @__PURE__ */ jsx(X, { className: "w-3 h-3" })
1831
- }
1832
- )
1833
- ] }, i);
1834
- }) }),
1835
- (!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1836
- /* @__PURE__ */ jsx(
1837
- "input",
1838
- {
1839
- type: "url",
1840
- placeholder: "Add media URL and press Enter...",
1841
- onKeyDown: (e) => {
1842
- if (e.key === "Enter" && e.currentTarget.value) {
1843
- e.preventDefault();
1844
- const arr = [...editing[f.id] || [], e.currentTarget.value];
1845
- setEditing({ ...editing, [f.id]: arr });
1846
- e.currentTarget.value = "";
1847
- }
1848
- },
1849
- 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"
1850
- }
1851
- ),
1852
- /* @__PURE__ */ jsx(
1853
- FilePickerButton,
1854
- {
1855
- accept: "image/*,video/*",
1856
- multiple: true,
1857
- 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",
1858
- onFiles: (files) => {
1859
- files.forEach((file) => {
1860
- void handleImageFile(
1861
- file,
1862
- (url) => {
1863
- setEditing((prev) => {
1864
- if (!prev) return prev;
1865
- const current = prev[f.id] || [];
1866
- if (f.max && current.length >= f.max) {
1867
- return prev;
1868
- }
1869
- return { ...prev, [f.id]: [...current, url] };
1870
- });
1871
- },
1872
- ctx.uploadImage
1873
- );
1874
- });
1875
- },
1876
- children: "Upload"
1877
- }
1878
- )
1879
- ] })
1880
- ] }) : /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1881
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
2111
+ ) : f.type === "icon" ? /* @__PURE__ */ jsx(
2112
+ SearchableSelect,
2113
+ {
2114
+ value: String(editing[f.id] ?? ""),
2115
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2116
+ options: f.options?.length ? f.options : ctx.iconMap ? Object.keys(ctx.iconMap) : [],
2117
+ placeholder: `Buscar icono ${f.label.toLowerCase()}...`,
2118
+ iconMap: ctx.iconMap
2119
+ }
2120
+ ) : f.type === "slug" ? /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1882
2121
  /* @__PURE__ */ jsx(
1883
- "input",
2122
+ Input,
1884
2123
  {
1885
- type: "url",
2124
+ size: "large",
1886
2125
  value: String(editing[f.id] ?? ""),
1887
2126
  onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1888
- placeholder: "https://...",
1889
- 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"
2127
+ className: "flex-1 rounded-xl"
1890
2128
  }
1891
2129
  ),
1892
2130
  /* @__PURE__ */ jsx(
1893
- FilePickerButton,
2131
+ Button,
1894
2132
  {
1895
- accept: "image/*,video/*",
1896
- 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",
1897
- onFiles: (files) => {
1898
- const file = files[0];
1899
- if (file) {
1900
- void handleImageFile(
1901
- file,
1902
- (url) => setEditing(
1903
- (current) => current ? { ...current, [f.id]: url } : current
1904
- ),
1905
- ctx.uploadImage
1906
- );
1907
- }
2133
+ size: "large",
2134
+ onClick: () => {
2135
+ const sourceField = f.source || "title";
2136
+ let val = String(editing[sourceField] || editing.id || "");
2137
+ val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
2138
+ setEditing({ ...editing, [f.id]: val });
1908
2139
  },
1909
- children: "Upload"
2140
+ className: "rounded-xl font-semibold",
2141
+ children: "Generate"
1910
2142
  }
1911
2143
  )
1912
- ] }),
1913
- editing[f.id] ? /* @__PURE__ */ jsx("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__ */ jsx(
1914
- "video",
1915
- {
1916
- src: String(editing[f.id]),
1917
- controls: true,
1918
- className: "w-full h-auto max-h-48 object-contain rounded-lg"
1919
- }
1920
- ) : /* @__PURE__ */ jsx(
1921
- "img",
1922
- {
1923
- src: String(editing[f.id]),
1924
- alt: "",
1925
- className: "w-full h-auto max-h-48 object-contain rounded-lg"
1926
- }
1927
- ) }) : null
1928
- ] }) : f.type === "password" ? /* @__PURE__ */ jsx(
1929
- PasswordField,
1930
- {
1931
- value: String(editing[f.id] ?? ""),
1932
- onChange: (val) => setEditing({ ...editing, [f.id]: val })
1933
- }
1934
- ) : f.type === "color" && !f.multiple ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
1935
- /* @__PURE__ */ jsx(
1936
- "input",
1937
- {
1938
- type: "color",
1939
- value: String(editing[f.id] ?? "#000000").startsWith("#") && String(editing[f.id] ?? "").length === 7 ? String(editing[f.id]) : "#000000",
1940
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1941
- className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
1942
- }
1943
- ),
1944
- /* @__PURE__ */ jsx(
1945
- "input",
1946
- {
1947
- type: "text",
1948
- value: String(editing[f.id] ?? ""),
1949
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1950
- placeholder: "#000000",
1951
- 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"
1952
- }
1953
- ),
1954
- /* @__PURE__ */ jsx(
1955
- "div",
2144
+ ] }) : f.type === "reference" || f.type === "select" && f.collection ? /* @__PURE__ */ jsx(
2145
+ ReferenceSelect,
1956
2146
  {
1957
- className: "w-8 h-8 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
1958
- style: { backgroundColor: String(editing[f.id] ?? "#000000") }
2147
+ collectionId: f.collection,
2148
+ displayField: f.displayField,
2149
+ valueField: f.valueField,
2150
+ fallbackOptions: f.options,
2151
+ multiple: f.multiple,
2152
+ searchable: f.searchable,
2153
+ max: f.max,
2154
+ value: editing[f.id],
2155
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2156
+ onSelectRecord: (rec) => {
2157
+ if (f.id === "clienteId" && rec) {
2158
+ setEditing((prev) => prev ? {
2159
+ ...prev,
2160
+ clienteId: rec.id || prev.clienteId,
2161
+ clienteNombre: rec.nombre || rec.name || prev.clienteNombre,
2162
+ ciudad: rec.ciudad || prev.ciudad,
2163
+ direccion: rec.direccion || prev.direccion,
2164
+ telefono: rec.telefono || prev.telefono
2165
+ } : prev);
2166
+ } else if (f.id === "empleadoId" && rec) {
2167
+ setEditing((prev) => prev ? {
2168
+ ...prev,
2169
+ empleadoId: rec.id || prev.empleadoId,
2170
+ empleadoNombre: rec.apellido ? `${rec.nombre || rec.name || ""} ${rec.apellido}`.trim() : rec.nombre || rec.name || prev.empleadoNombre
2171
+ } : prev);
2172
+ }
2173
+ }
1959
2174
  }
1960
- )
1961
- ] }) : f.type === "color" && f.multiple || f.type === "list" && f.id === "colors" ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1962
- (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) => {
1963
- const colorVal = String(item ?? "").trim();
1964
- const validHex = colorVal.startsWith("#") && (colorVal.length === 4 || colorVal.length === 7) ? colorVal : "#000000";
1965
- return /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
2175
+ ) : f.type === "select" ? (() => {
2176
+ const dynamicOptions = f.optionsMap && f.dependsOnField ? f.optionsMap[String(editing[f.dependsOnField] || "")] || f.options || [] : f.options || [];
2177
+ return /* @__PURE__ */ jsx(
2178
+ Select,
2179
+ {
2180
+ size: "large",
2181
+ value: editing[f.id] ? String(editing[f.id]) : void 0,
2182
+ placeholder: f.label,
2183
+ allowClear: true,
2184
+ onChange: (val) => {
2185
+ const next = { ...editing, [f.id]: val || "" };
2186
+ collection.fields.forEach((otherField) => {
2187
+ if (otherField.dependsOnField === f.id && otherField.optionsMap) {
2188
+ const newOpts = otherField.optionsMap[String(val || "")];
2189
+ if (newOpts && newOpts.length > 0) {
2190
+ const firstVal = typeof newOpts[0] === "string" ? newOpts[0] : newOpts[0].value;
2191
+ next[otherField.id] = firstVal;
2192
+ }
2193
+ }
2194
+ });
2195
+ setEditing(next);
2196
+ },
2197
+ options: dynamicOptions.map((opt) => ({
2198
+ label: typeof opt === "string" ? opt : opt.label,
2199
+ value: typeof opt === "string" ? opt : opt.value
2200
+ })),
2201
+ className: "w-full"
2202
+ }
2203
+ );
2204
+ })() : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2205
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
2206
+ const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
2207
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
2208
+ isVideo ? /* @__PURE__ */ jsx("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ jsx("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
2209
+ /* @__PURE__ */ jsx(
2210
+ "button",
2211
+ {
2212
+ type: "button",
2213
+ onClick: () => {
2214
+ const arr = [...editing[f.id] || []];
2215
+ arr.splice(i, 1);
2216
+ setEditing({ ...editing, [f.id]: arr });
2217
+ },
2218
+ 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",
2219
+ children: /* @__PURE__ */ jsx(X, { className: "w-3 h-3" })
2220
+ }
2221
+ )
2222
+ ] }, i);
2223
+ }) }),
2224
+ (!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1966
2225
  /* @__PURE__ */ jsx(
1967
2226
  "input",
1968
2227
  {
1969
- type: "color",
1970
- value: validHex.length === 7 ? validHex : "#000000",
1971
- onChange: (e) => {
1972
- 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) : [];
1973
- arr[idx] = e.target.value;
1974
- setEditing({ ...editing, [f.id]: arr });
1975
- },
1976
- className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
1977
- }
1978
- ),
1979
- /* @__PURE__ */ jsx(
1980
- "input",
1981
- {
1982
- type: "text",
1983
- value: colorVal,
1984
- onChange: (e) => {
1985
- 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) : [];
1986
- arr[idx] = e.target.value;
1987
- setEditing({ ...editing, [f.id]: arr });
2228
+ type: "url",
2229
+ placeholder: "Add media URL and press Enter...",
2230
+ onKeyDown: (e) => {
2231
+ if (e.key === "Enter" && e.currentTarget.value) {
2232
+ e.preventDefault();
2233
+ const arr = [...editing[f.id] || [], e.currentTarget.value];
2234
+ setEditing({ ...editing, [f.id]: arr });
2235
+ e.currentTarget.value = "";
2236
+ }
1988
2237
  },
1989
- placeholder: "#1c2a44",
1990
- 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"
2238
+ 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"
1991
2239
  }
1992
2240
  ),
1993
2241
  /* @__PURE__ */ jsx(
1994
- "div",
2242
+ FilePickerButton,
1995
2243
  {
1996
- className: "w-7 h-7 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
1997
- style: { backgroundColor: colorVal || "#000000" }
1998
- }
1999
- ),
2000
- /* @__PURE__ */ jsx(
2001
- "button",
2002
- {
2003
- type: "button",
2004
- onClick: () => {
2005
- 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) : [];
2006
- arr.splice(idx, 1);
2007
- setEditing({ ...editing, [f.id]: arr });
2244
+ accept: "image/*,video/*",
2245
+ multiple: true,
2246
+ 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",
2247
+ onFiles: (files) => {
2248
+ files.forEach((file) => {
2249
+ void handleImageFile(
2250
+ file,
2251
+ (url) => {
2252
+ setEditing((prev) => {
2253
+ if (!prev) return prev;
2254
+ const current = prev[f.id] || [];
2255
+ if (f.max && current.length >= f.max) {
2256
+ return prev;
2257
+ }
2258
+ return { ...prev, [f.id]: [...current, url] };
2259
+ });
2260
+ },
2261
+ ctx.uploadImage
2262
+ );
2263
+ });
2008
2264
  },
2009
- className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
2010
- children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
2265
+ children: "Upload"
2011
2266
  }
2012
2267
  )
2013
- ] }, idx);
2014
- }),
2015
- /* @__PURE__ */ jsxs(
2016
- "button",
2017
- {
2018
- type: "button",
2019
- onClick: () => {
2020
- 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) : [];
2021
- arr.push("#000000");
2022
- setEditing({ ...editing, [f.id]: arr });
2023
- },
2024
- 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",
2025
- children: [
2026
- /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
2027
- " Add Color"
2028
- ]
2029
- }
2030
- )
2031
- ] }) : f.type === "list" ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2032
- (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : []).map((item, idx) => {
2033
- const isFeatures = f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") || f.label.toLowerCase().includes("beneficio");
2034
- const placeholder = isFeatures ? `Caracter\xEDstica o beneficio ${idx + 1}...` : `Entregable o punto clave ${idx + 1}...`;
2035
- return /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
2036
- /* @__PURE__ */ jsxs("span", { className: "text-xs font-mono font-bold text-slate-400 w-6 text-right shrink-0", children: [
2037
- idx + 1,
2038
- "."
2039
- ] }),
2268
+ ] })
2269
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2270
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
2040
2271
  /* @__PURE__ */ jsx(
2041
2272
  "input",
2042
2273
  {
2043
- type: "text",
2044
- value: String(item ?? ""),
2045
- placeholder,
2046
- onChange: (e) => {
2047
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2048
- arr[idx] = e.target.value;
2049
- setEditing({ ...editing, [f.id]: arr });
2050
- },
2051
- className: "flex-1 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 bg-white"
2274
+ type: "url",
2275
+ value: String(editing[f.id] ?? ""),
2276
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2277
+ placeholder: "https://...",
2278
+ 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"
2052
2279
  }
2053
2280
  ),
2054
2281
  /* @__PURE__ */ jsx(
2055
- "button",
2282
+ FilePickerButton,
2056
2283
  {
2057
- type: "button",
2058
- onClick: () => {
2059
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2060
- arr.splice(idx, 1);
2061
- setEditing({ ...editing, [f.id]: arr });
2284
+ accept: "image/*,video/*",
2285
+ 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",
2286
+ onFiles: (files) => {
2287
+ const file = files[0];
2288
+ if (file) {
2289
+ void handleImageFile(
2290
+ file,
2291
+ (url) => setEditing(
2292
+ (current) => current ? { ...current, [f.id]: url } : current
2293
+ ),
2294
+ ctx.uploadImage
2295
+ );
2296
+ }
2062
2297
  },
2063
- className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer",
2064
- title: "Eliminar elemento",
2065
- children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
2298
+ children: "Upload"
2066
2299
  }
2067
2300
  )
2068
- ] }, idx);
2069
- }),
2070
- /* @__PURE__ */ jsxs(
2071
- "button",
2301
+ ] }),
2302
+ editing[f.id] ? /* @__PURE__ */ jsx("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__ */ jsx(
2303
+ "video",
2304
+ {
2305
+ src: String(editing[f.id]),
2306
+ controls: true,
2307
+ className: "w-full h-auto max-h-48 object-contain rounded-lg"
2308
+ }
2309
+ ) : /* @__PURE__ */ jsx(
2310
+ "img",
2311
+ {
2312
+ src: String(editing[f.id]),
2313
+ alt: "",
2314
+ className: "w-full h-auto max-h-48 object-contain rounded-lg"
2315
+ }
2316
+ ) }) : null
2317
+ ] }) : f.type === "password" ? /* @__PURE__ */ jsx(
2318
+ PasswordField,
2072
2319
  {
2073
- type: "button",
2074
- onClick: () => {
2075
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2076
- arr.push("");
2077
- setEditing({ ...editing, [f.id]: arr });
2078
- },
2079
- className: "inline-flex items-center gap-1.5 px-3.5 py-2 bg-indigo-50 hover:bg-indigo-100 text-indigo-700 text-xs font-bold rounded-xl border border-indigo-100 transition-colors cursor-pointer",
2080
- children: [
2081
- /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
2082
- " ",
2083
- f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") ? "Agregar caracter\xEDstica uno a uno" : "Agregar entregable / punto uno a uno"
2084
- ]
2320
+ value: String(editing[f.id] ?? ""),
2321
+ onChange: (val) => setEditing({ ...editing, [f.id]: val })
2322
+ }
2323
+ ) : f.type === "signature" ? /* @__PURE__ */ jsx(
2324
+ SignatureInput,
2325
+ {
2326
+ value: editing[f.id],
2327
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2328
+ label: f.label
2329
+ }
2330
+ ) : f.type === "color" && !f.multiple ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2331
+ /* @__PURE__ */ jsx(
2332
+ "input",
2333
+ {
2334
+ type: "color",
2335
+ value: String(editing[f.id] ?? "#000000").startsWith("#") && String(editing[f.id] ?? "").length === 7 ? String(editing[f.id]) : "#000000",
2336
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2337
+ className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
2338
+ }
2339
+ ),
2340
+ /* @__PURE__ */ jsx(
2341
+ "input",
2342
+ {
2343
+ type: "text",
2344
+ value: String(editing[f.id] ?? ""),
2345
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2346
+ placeholder: "#000000",
2347
+ 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"
2348
+ }
2349
+ ),
2350
+ /* @__PURE__ */ jsx(
2351
+ "div",
2352
+ {
2353
+ className: "w-8 h-8 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
2354
+ style: { backgroundColor: String(editing[f.id] ?? "#000000") }
2355
+ }
2356
+ )
2357
+ ] }) : f.type === "color" && f.multiple || f.type === "list" && f.id === "colors" ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2358
+ (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) => {
2359
+ const colorVal = String(item ?? "").trim();
2360
+ const validHex = colorVal.startsWith("#") && (colorVal.length === 4 || colorVal.length === 7) ? colorVal : "#000000";
2361
+ return /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
2362
+ /* @__PURE__ */ jsx(
2363
+ "input",
2364
+ {
2365
+ type: "color",
2366
+ value: validHex.length === 7 ? validHex : "#000000",
2367
+ onChange: (e) => {
2368
+ 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) : [];
2369
+ arr[idx] = e.target.value;
2370
+ setEditing({ ...editing, [f.id]: arr });
2371
+ },
2372
+ className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
2373
+ }
2374
+ ),
2375
+ /* @__PURE__ */ jsx(
2376
+ "input",
2377
+ {
2378
+ type: "text",
2379
+ value: colorVal,
2380
+ onChange: (e) => {
2381
+ 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) : [];
2382
+ arr[idx] = e.target.value;
2383
+ setEditing({ ...editing, [f.id]: arr });
2384
+ },
2385
+ placeholder: "#1c2a44",
2386
+ 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"
2387
+ }
2388
+ ),
2389
+ /* @__PURE__ */ jsx(
2390
+ "div",
2391
+ {
2392
+ className: "w-7 h-7 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
2393
+ style: { backgroundColor: colorVal || "#000000" }
2394
+ }
2395
+ ),
2396
+ /* @__PURE__ */ jsx(
2397
+ "button",
2398
+ {
2399
+ type: "button",
2400
+ onClick: () => {
2401
+ 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) : [];
2402
+ arr.splice(idx, 1);
2403
+ setEditing({ ...editing, [f.id]: arr });
2404
+ },
2405
+ className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
2406
+ children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
2407
+ }
2408
+ )
2409
+ ] }, idx);
2410
+ }),
2411
+ /* @__PURE__ */ jsxs(
2412
+ "button",
2413
+ {
2414
+ type: "button",
2415
+ onClick: () => {
2416
+ 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) : [];
2417
+ arr.push("#000000");
2418
+ setEditing({ ...editing, [f.id]: arr });
2419
+ },
2420
+ 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",
2421
+ children: [
2422
+ /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
2423
+ " Add Color"
2424
+ ]
2425
+ }
2426
+ )
2427
+ ] }) : f.type === "list" ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2428
+ (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : []).map((item, idx) => {
2429
+ const isFeatures = f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") || f.label.toLowerCase().includes("beneficio");
2430
+ const placeholder = isFeatures ? `Caracter\xEDstica o beneficio ${idx + 1}...` : `Entregable o punto clave ${idx + 1}...`;
2431
+ return /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
2432
+ /* @__PURE__ */ jsxs("span", { className: "text-xs font-mono font-bold text-slate-400 w-6 text-right shrink-0", children: [
2433
+ idx + 1,
2434
+ "."
2435
+ ] }),
2436
+ /* @__PURE__ */ jsx(
2437
+ "input",
2438
+ {
2439
+ type: "text",
2440
+ value: String(item ?? ""),
2441
+ placeholder,
2442
+ onChange: (e) => {
2443
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2444
+ arr[idx] = e.target.value;
2445
+ setEditing({ ...editing, [f.id]: arr });
2446
+ },
2447
+ className: "flex-1 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 bg-white"
2448
+ }
2449
+ ),
2450
+ /* @__PURE__ */ jsx(
2451
+ "button",
2452
+ {
2453
+ type: "button",
2454
+ onClick: () => {
2455
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2456
+ arr.splice(idx, 1);
2457
+ setEditing({ ...editing, [f.id]: arr });
2458
+ },
2459
+ className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer",
2460
+ title: "Eliminar elemento",
2461
+ children: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" })
2462
+ }
2463
+ )
2464
+ ] }, idx);
2465
+ }),
2466
+ /* @__PURE__ */ jsxs(
2467
+ "button",
2468
+ {
2469
+ type: "button",
2470
+ onClick: () => {
2471
+ let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
2472
+ arr.push("");
2473
+ setEditing({ ...editing, [f.id]: arr });
2474
+ },
2475
+ className: "inline-flex items-center gap-1.5 px-3.5 py-2 bg-indigo-50 hover:bg-indigo-100 text-indigo-700 text-xs font-bold rounded-xl border border-indigo-100 transition-colors cursor-pointer",
2476
+ children: [
2477
+ /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
2478
+ " ",
2479
+ f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") ? "Agregar caracter\xEDstica uno a uno" : "Agregar entregable / punto uno a uno"
2480
+ ]
2481
+ }
2482
+ )
2483
+ ] }) : f.type === "link" ? /* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center", children: [
2484
+ /* @__PURE__ */ jsx(
2485
+ Input,
2486
+ {
2487
+ size: "large",
2488
+ value: String(editing[f.id] ?? ""),
2489
+ readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
2490
+ disabled: f.readOnly,
2491
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2492
+ placeholder: f.label,
2493
+ className: "flex-1 rounded-xl"
2494
+ }
2495
+ ),
2496
+ Boolean(editing[f.id]) && String(editing[f.id]).startsWith("http") ? /* @__PURE__ */ jsxs(
2497
+ "a",
2498
+ {
2499
+ href: String(editing[f.id]),
2500
+ target: "_blank",
2501
+ rel: "noopener noreferrer",
2502
+ className: "inline-flex items-center gap-1.5 px-3 py-2 bg-blue-50 text-blue-600 hover:bg-blue-100 rounded-xl text-xs font-bold border border-blue-200 transition-colors shrink-0",
2503
+ children: [
2504
+ /* @__PURE__ */ jsx(ExternalLink, { className: "w-3.5 h-3.5" }),
2505
+ String(editing[f.id]).includes("maps") ? "Ver en Mapa" : "Abrir"
2506
+ ]
2507
+ }
2508
+ ) : null
2509
+ ] }) : /* @__PURE__ */ jsx(
2510
+ Input,
2511
+ {
2512
+ size: "large",
2513
+ value: String(editing[f.id] ?? ""),
2514
+ readOnly: f.readOnly || f.autoIncrement && !isCreatingEntry,
2515
+ disabled: f.readOnly,
2516
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2517
+ placeholder: f.label,
2518
+ className: "w-full rounded-xl"
2085
2519
  }
2086
2520
  )
2087
- ] }) : /* @__PURE__ */ jsx(
2088
- "input",
2089
- {
2090
- value: String(editing[f.id] ?? ""),
2091
- onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2092
- 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"
2093
- }
2094
- )
2095
- ] }, f.id)) }) }),
2521
+ ] }, f.id);
2522
+ }) }) }),
2096
2523
  /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
2097
2524
  /* @__PURE__ */ jsx(
2098
- "button",
2525
+ Button,
2099
2526
  {
2527
+ size: "large",
2100
2528
  onClick: () => setEditing(null),
2101
2529
  disabled: saving,
2102
- className: "rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-600 hover:bg-slate-100 transition-colors disabled:opacity-50",
2103
- children: "Cancel"
2530
+ className: "rounded-xl font-medium",
2531
+ children: t.cancel
2104
2532
  }
2105
2533
  ),
2106
2534
  /* @__PURE__ */ jsx(
2107
- "button",
2535
+ Button,
2108
2536
  {
2537
+ size: "large",
2538
+ type: "primary",
2109
2539
  onClick: save,
2110
- disabled: saving,
2111
- 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",
2112
- children: saving ? /* @__PURE__ */ jsxs(Fragment, { children: [
2113
- /* @__PURE__ */ jsxs("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: [
2114
- /* @__PURE__ */ jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2115
- /* @__PURE__ */ jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
2116
- ] }),
2117
- "Saving..."
2118
- ] }) : "Save Entry"
2540
+ loading: saving,
2541
+ className: "min-w-[140px] rounded-xl font-bold shadow-sm bg-blue-600 hover:bg-blue-700",
2542
+ children: collection.submitLabel || (isCreatingEntry ? t.create.toUpperCase() : t.save.toUpperCase())
2119
2543
  }
2120
2544
  )
2121
2545
  ] })
2122
- ] })
2546
+ ] }) })
2123
2547
  }
2124
2548
  ),
2125
2549
  /* @__PURE__ */ jsx("div", { className: "overflow-x-auto rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm text-left", children: [
2126
2550
  /* @__PURE__ */ jsx("thead", { className: "bg-slate-50/80 border-b border-slate-200", children: /* @__PURE__ */ jsxs("tr", { children: [
2127
2551
  visibleFields.map((f) => /* @__PURE__ */ jsx("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: f.label }, f.id)),
2128
- /* @__PURE__ */ jsx("th", { className: "px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase tracking-wider sticky right-0 bg-slate-50 border-l border-slate-200 z-10", children: "Actions" })
2552
+ /* @__PURE__ */ jsx("th", { className: "px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase tracking-wider sticky right-0 bg-slate-50 border-l border-slate-200 z-10", children: t.actions })
2129
2553
  ] }) }),
2130
2554
  /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-slate-100", children: loadingEntries ? (
2131
2555
  // Loading skeleton rows
@@ -2137,13 +2561,29 @@ function CollectionEditor({ collection }) {
2137
2561
  (() => {
2138
2562
  let res = entries;
2139
2563
  if (search && collection.searchBy?.length) {
2140
- const q = search.toLowerCase();
2141
- res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
2564
+ const q = search.toLowerCase().trim();
2565
+ res = res.filter((e) => {
2566
+ return collection.searchBy.some((field) => {
2567
+ const val = String(e[field] ?? "").toLowerCase();
2568
+ if (!val) return false;
2569
+ if (val.includes(q)) return true;
2570
+ const normVal = val.replace(/-/g, "/");
2571
+ const normQ = q.replace(/-/g, "/");
2572
+ return normVal.includes(normQ);
2573
+ });
2574
+ });
2142
2575
  }
2143
2576
  if (Object.keys(filters).length > 0) {
2144
2577
  res = res.filter((e) => {
2145
2578
  for (const [k, v] of Object.entries(filters)) {
2146
- if (v && String(e[k] || "") !== v) return false;
2579
+ if (!v) continue;
2580
+ const entryVal = String(e[k] ?? "").trim();
2581
+ const filterVal = String(v).trim();
2582
+ const normEntry = entryVal.replace(/-/g, "/");
2583
+ const normFilter = filterVal.replace(/-/g, "/");
2584
+ if (normEntry !== normFilter && !normEntry.includes(normFilter)) {
2585
+ return false;
2586
+ }
2147
2587
  }
2148
2588
  return true;
2149
2589
  });
@@ -2159,10 +2599,22 @@ function CollectionEditor({ collection }) {
2159
2599
  onDragEnd,
2160
2600
  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" : ""}`,
2161
2601
  children: [
2162
- visibleFields.map((f) => /* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "branch-settings" ? /* @__PURE__ */ jsx(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx("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__ */ jsx("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__ */ jsx("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__ */ jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx("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__ */ jsx(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : f.id === "status" && e[f.id] ? /* @__PURE__ */ jsx("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__ */ jsxs("span", { className: "font-semibold text-slate-800", children: [
2602
+ visibleFields.map((f) => /* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "branch-settings" ? /* @__PURE__ */ jsx(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx("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__ */ jsx("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__ */ jsx("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__ */ jsx("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx("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.id === "status" || f.id === "estado") && e[f.id] ? /* @__PURE__ */ jsx("span", { className: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold ${String(e[f.id]) === "Terminado" || String(e[f.id]) === "Terminada" || String(e[f.id]).includes("Entregado") ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : String(e[f.id]) === "Proceso" || String(e[f.id]).includes("Preparaci\xF3n") ? "bg-amber-50 text-amber-700 border border-amber-200" : String(e[f.id]) === "Cancelado" || String(e[f.id]).includes("Cancelado") ? "bg-rose-50 text-rose-700 border border-rose-200" : "bg-blue-50 text-blue-700 border border-blue-200"}`, children: String(e[f.id]) }) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ? e.clienteNombre && f.id === "clienteId" ? /* @__PURE__ */ jsx("span", { className: "font-medium text-slate-800", children: String(e.clienteNombre) }) : e.empleadoNombre && f.id === "empleadoId" ? /* @__PURE__ */ jsx("span", { className: "font-medium text-slate-800", children: String(e.empleadoNombre) }) : /* @__PURE__ */ jsx(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : f.type === "signature" && e[f.id] ? /* @__PURE__ */ jsx(Image, { src: String(e[f.id]), alt: "Firma", className: "h-7 max-w-[80px] object-contain rounded bg-white border border-slate-200 p-0.5 inline-block shadow-xs cursor-pointer", preview: { mask: "Ver" } }) : 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__ */ jsxs("span", { className: "font-semibold text-slate-800", children: [
2163
2603
  "$ ",
2164
2604
  Number(e[f.id]).toLocaleString("es-CO")
2165
- ] }) : /* @__PURE__ */ jsx("span", { children: Number(e[f.id]).toLocaleString("es-CO") }) : String(e[f.id] ?? "") }, f.id)),
2605
+ ] }) : /* @__PURE__ */ jsx("span", { children: Number(e[f.id]).toLocaleString("es-CO") }) : f.type === "link" || typeof e[f.id] === "string" && String(e[f.id]).startsWith("http") ? /* @__PURE__ */ jsxs(
2606
+ "a",
2607
+ {
2608
+ href: String(e[f.id]),
2609
+ target: "_blank",
2610
+ rel: "noopener noreferrer",
2611
+ className: "inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800 underline font-medium",
2612
+ children: [
2613
+ /* @__PURE__ */ jsx(ExternalLink, { className: "w-3 h-3" }),
2614
+ String(e[f.id]).includes("maps") ? "Ver mapa" : "Abrir"
2615
+ ]
2616
+ }
2617
+ ) : String(e[f.id] ?? "") }, f.id)),
2166
2618
  /* @__PURE__ */ jsx("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2", children: [
2167
2619
  /* @__PURE__ */ jsx("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ jsx("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "w-4 h-4", children: /* @__PURE__ */ jsx("path", { d: "M5.5 3C6.32843 3 7 3.67157 7 4.5C7 5.32843 6.32843 6 5.5 6C4.67157 6 4 5.32843 4 4.5C4 3.67157 4.67157 3 5.5 3ZM9.5 3C10.3284 3 11 3.67157 11 4.5C11 5.32843 10.3284 6 9.5 6C8.67157 6 8 5.32843 8 4.5C8 3.67157 8.67157 3 9.5 3ZM5.5 7.5C6.32843 7.5 7 8.17157 7 9C7 9.82843 6.32843 10.5 5.5 10.5C4.67157 10.5 4 9.82843 4 9C4 8.17157 4.67157 7.5 5.5 7.5ZM9.5 7.5C10.3284 7.5 11 8.17157 11 9C11 9.82843 10.3284 10.5 9.5 10.5C8.67157 10.5 8 9.82843 8 9C8 8.17157 8.67157 7.5 9.5 7.5ZM5.5 12C6.32843 12 7 12.6716 7 13.5C7 14.3284 6.32843 15 5.5 15C4.67157 15 4 14.3284 4 13.5C4 12.6716 4.67157 12 5.5 12ZM9.5 12C10.3284 12 11 12.6716 11 13.5C11 14.3284 10.3284 15 9.5 15C8.67157 15 8 14.3284 8 13.5C8 12.6716 8.67157 12 9.5 12Z", fill: "currentColor", fillRule: "evenodd", clipRule: "evenodd" }) }) }),
2168
2620
  /* @__PURE__ */ jsx(
@@ -2170,7 +2622,7 @@ function CollectionEditor({ collection }) {
2170
2622
  {
2171
2623
  onClick: () => setEditing(e),
2172
2624
  className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
2173
- title: "Edit",
2625
+ title: t.edit,
2174
2626
  children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" })
2175
2627
  }
2176
2628
  ),
@@ -2180,7 +2632,7 @@ function CollectionEditor({ collection }) {
2180
2632
  onClick: () => remove(e.id),
2181
2633
  disabled: deletingId === e.id,
2182
2634
  className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
2183
- title: "Delete",
2635
+ title: t.delete,
2184
2636
  children: deletingId === e.id ? /* @__PURE__ */ jsxs("svg", { className: "animate-spin h-4 w-4", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
2185
2637
  /* @__PURE__ */ jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2186
2638
  /* @__PURE__ */ jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
@@ -2200,7 +2652,7 @@ function CollectionEditor({ collection }) {
2200
2652
  className: "px-6 py-12 text-center text-slate-500",
2201
2653
  children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center", children: [
2202
2654
  /* @__PURE__ */ jsx(Boxes, { className: "h-10 w-10 text-slate-300 mb-3" }),
2203
- /* @__PURE__ */ jsx("p", { children: 'No entries yet. Click "New Entry" to create one.' })
2655
+ /* @__PURE__ */ jsx("p", { children: t.noRecords })
2204
2656
  ] })
2205
2657
  }
2206
2658
  ) })
@@ -2221,7 +2673,7 @@ function CollectionEditor({ collection }) {
2221
2673
  return true;
2222
2674
  });
2223
2675
  }
2224
- return `${res.length} item${res.length !== 1 ? "s" : ""}`;
2676
+ return `${res.length} ${t.entries}`;
2225
2677
  })() }),
2226
2678
  (() => {
2227
2679
  let res = entries;
@@ -2871,6 +3323,197 @@ function PasswordField({ value, onChange }) {
2871
3323
  )
2872
3324
  ] });
2873
3325
  }
3326
+ function SignatureInput({
3327
+ value,
3328
+ onChange,
3329
+ label
3330
+ }) {
3331
+ const t = useAdminI18n();
3332
+ const [modalOpen, setModalOpen] = useState(false);
3333
+ const canvasRef = useRef(null);
3334
+ const isDrawingRef = useRef(false);
3335
+ const fileInputRef = useRef(null);
3336
+ const sigVal = typeof value === "string" ? value : "";
3337
+ const displayLabel = label || t.signatureRegistered;
3338
+ const startDrawing = (e) => {
3339
+ const canvas = canvasRef.current;
3340
+ if (!canvas) return;
3341
+ const ctx = canvas.getContext("2d");
3342
+ if (!ctx) return;
3343
+ isDrawingRef.current = true;
3344
+ const rect = canvas.getBoundingClientRect();
3345
+ const x = "touches" in e ? e.touches[0].clientX - rect.left : e.clientX - rect.left;
3346
+ const y = "touches" in e ? e.touches[0].clientY - rect.top : e.clientY - rect.top;
3347
+ ctx.beginPath();
3348
+ ctx.moveTo(x, y);
3349
+ };
3350
+ const draw = (e) => {
3351
+ if (!isDrawingRef.current) return;
3352
+ const canvas = canvasRef.current;
3353
+ if (!canvas) return;
3354
+ const ctx = canvas.getContext("2d");
3355
+ if (!ctx) return;
3356
+ const rect = canvas.getBoundingClientRect();
3357
+ const x = "touches" in e ? e.touches[0].clientX - rect.left : e.clientX - rect.left;
3358
+ const y = "touches" in e ? e.touches[0].clientY - rect.top : e.clientY - rect.top;
3359
+ ctx.lineTo(x, y);
3360
+ ctx.stroke();
3361
+ };
3362
+ const stopDrawing = () => {
3363
+ isDrawingRef.current = false;
3364
+ };
3365
+ const clearCanvas = () => {
3366
+ const canvas = canvasRef.current;
3367
+ if (!canvas) return;
3368
+ const ctx = canvas.getContext("2d");
3369
+ if (!ctx) return;
3370
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
3371
+ };
3372
+ const saveDrawnSignature = () => {
3373
+ const canvas = canvasRef.current;
3374
+ if (!canvas) return;
3375
+ const dataUrl = canvas.toDataURL("image/png");
3376
+ onChange(dataUrl);
3377
+ setModalOpen(false);
3378
+ };
3379
+ const handleFileUpload = (e) => {
3380
+ const file = e.target.files?.[0];
3381
+ if (!file) return;
3382
+ const reader = new FileReader();
3383
+ reader.onload = (evt) => {
3384
+ if (typeof evt.target?.result === "string") {
3385
+ onChange(evt.target.result);
3386
+ }
3387
+ };
3388
+ reader.readAsDataURL(file);
3389
+ e.target.value = "";
3390
+ };
3391
+ useEffect(() => {
3392
+ if (modalOpen) {
3393
+ setTimeout(() => {
3394
+ const canvas = canvasRef.current;
3395
+ if (!canvas) return;
3396
+ const ctx = canvas.getContext("2d");
3397
+ if (ctx) {
3398
+ ctx.strokeStyle = "#0f172a";
3399
+ ctx.lineWidth = 2.5;
3400
+ ctx.lineCap = "round";
3401
+ ctx.lineJoin = "round";
3402
+ }
3403
+ }, 50);
3404
+ }
3405
+ }, [modalOpen]);
3406
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
3407
+ sigVal ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-3 rounded-xl border border-slate-200 bg-slate-50/70", children: [
3408
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
3409
+ /* @__PURE__ */ jsx(
3410
+ Image,
3411
+ {
3412
+ src: sigVal,
3413
+ alt: displayLabel,
3414
+ className: "h-16 max-w-[220px] object-contain rounded bg-white p-1 border border-slate-200 shadow-sm cursor-pointer hover:border-blue-500",
3415
+ preview: {
3416
+ mask: /* @__PURE__ */ jsx("span", { className: "text-xs font-semibold", children: t.previewMask })
3417
+ }
3418
+ }
3419
+ ),
3420
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
3421
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-emerald-700 bg-emerald-50 border border-emerald-200 px-2.5 py-0.5 rounded-full w-fit", children: t.signatureRegistered }),
3422
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] text-slate-500", children: t.viewLarger })
3423
+ ] })
3424
+ ] }),
3425
+ /* @__PURE__ */ jsx(
3426
+ Button,
3427
+ {
3428
+ danger: true,
3429
+ type: "text",
3430
+ icon: /* @__PURE__ */ jsx(Trash2, { className: "w-4 h-4" }),
3431
+ onClick: () => onChange(""),
3432
+ className: "hover:bg-red-50 text-red-600 font-medium",
3433
+ children: t.delete
3434
+ }
3435
+ )
3436
+ ] }) : null,
3437
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
3438
+ /* @__PURE__ */ jsx(
3439
+ Button,
3440
+ {
3441
+ type: "primary",
3442
+ size: "large",
3443
+ onClick: () => {
3444
+ clearCanvas();
3445
+ setModalOpen(true);
3446
+ },
3447
+ className: "w-full bg-blue-600 hover:bg-blue-700 font-bold uppercase rounded-xl h-11 text-xs tracking-wider shadow-sm",
3448
+ children: sigVal ? t.replaceSignature : t.addSignature
3449
+ }
3450
+ ),
3451
+ /* @__PURE__ */ jsx(
3452
+ Button,
3453
+ {
3454
+ type: "primary",
3455
+ size: "large",
3456
+ onClick: () => fileInputRef.current?.click(),
3457
+ className: "w-full bg-blue-600 hover:bg-blue-700 font-bold uppercase rounded-xl h-11 text-xs tracking-wider shadow-sm",
3458
+ children: sigVal ? t.uploadNewImage : t.uploadImage
3459
+ }
3460
+ ),
3461
+ /* @__PURE__ */ jsx(
3462
+ "input",
3463
+ {
3464
+ type: "file",
3465
+ ref: fileInputRef,
3466
+ accept: "image/*",
3467
+ onChange: handleFileUpload,
3468
+ className: "hidden"
3469
+ }
3470
+ )
3471
+ ] }),
3472
+ /* @__PURE__ */ jsx(
3473
+ Modal,
3474
+ {
3475
+ open: modalOpen,
3476
+ title: /* @__PURE__ */ jsx("span", { className: "font-bold text-slate-800", children: t.signOnScreen }),
3477
+ onCancel: () => setModalOpen(false),
3478
+ centered: true,
3479
+ width: 560,
3480
+ footer: [
3481
+ /* @__PURE__ */ jsx(Button, { onClick: clearCanvas, className: "rounded-xl font-medium", children: t.clear }, "clear"),
3482
+ /* @__PURE__ */ jsx(Button, { onClick: () => setModalOpen(false), className: "rounded-xl font-medium", children: t.cancel }, "cancel"),
3483
+ /* @__PURE__ */ jsx(
3484
+ Button,
3485
+ {
3486
+ type: "primary",
3487
+ onClick: saveDrawnSignature,
3488
+ className: "bg-blue-600 hover:bg-blue-700 font-bold rounded-xl",
3489
+ children: t.saveSignature
3490
+ },
3491
+ "save"
3492
+ )
3493
+ ],
3494
+ children: /* @__PURE__ */ jsxs("div", { className: "py-2 space-y-2", children: [
3495
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-slate-500", children: t.signInstructions }),
3496
+ /* @__PURE__ */ jsx("div", { className: "border-2 border-dashed border-slate-300 rounded-2xl bg-white overflow-hidden touch-none", children: /* @__PURE__ */ jsx(
3497
+ "canvas",
3498
+ {
3499
+ ref: canvasRef,
3500
+ width: 500,
3501
+ height: 220,
3502
+ onMouseDown: startDrawing,
3503
+ onMouseMove: draw,
3504
+ onMouseUp: stopDrawing,
3505
+ onMouseLeave: stopDrawing,
3506
+ onTouchStart: startDrawing,
3507
+ onTouchMove: draw,
3508
+ onTouchEnd: stopDrawing,
3509
+ className: "w-full h-[220px] cursor-crosshair block"
3510
+ }
3511
+ ) })
3512
+ ] })
3513
+ }
3514
+ )
3515
+ ] });
3516
+ }
2874
3517
  function FormattedNumberInput({
2875
3518
  value,
2876
3519
  onChange,
@@ -3553,11 +4196,80 @@ function ReferenceSelect({
3553
4196
  searchable = false,
3554
4197
  max,
3555
4198
  value,
3556
- onChange
4199
+ onChange,
4200
+ onSelectRecord
3557
4201
  }) {
3558
4202
  const ctx = useCmsContext();
4203
+ const t = useAdminI18n();
3559
4204
  const [options, setOptions] = useState([]);
3560
4205
  const [loading, setLoading] = useState(true);
4206
+ const [clientModalOpen, setClientModalOpen] = useState(false);
4207
+ const [creatingClient, setCreatingClient] = useState(false);
4208
+ const [clientError, setClientError] = useState("");
4209
+ const [newClient, setNewClient] = useState({
4210
+ tipo: "Persona",
4211
+ tipoDocumento: "C\xE9dula de ciudadan\xEDa",
4212
+ id: "",
4213
+ sucursal: "",
4214
+ nombre: "",
4215
+ email: "",
4216
+ telefono: "",
4217
+ ciudad: "",
4218
+ direccion: ""
4219
+ });
4220
+ const handleSaveClient = async () => {
4221
+ setClientError("");
4222
+ if (!newClient.id.trim()) {
4223
+ setClientError(t.idRequired);
4224
+ return;
4225
+ }
4226
+ if (!newClient.nombre.trim()) {
4227
+ setClientError(t.nameRequired);
4228
+ return;
4229
+ }
4230
+ setCreatingClient(true);
4231
+ try {
4232
+ const entry = {
4233
+ ...newClient,
4234
+ id: newClient.id.trim(),
4235
+ nombre: newClient.nombre.trim()
4236
+ };
4237
+ await ctx.adapter.putEntry("clients", entry);
4238
+ const res = await ctx.adapter.listEntries("clients");
4239
+ const fromCollection = (res || []).map((r) => {
4240
+ const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
4241
+ const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
4242
+ const lab = fullName || String(r[displayField] || r.name || r.id);
4243
+ return {
4244
+ value: val,
4245
+ label: val && val !== lab ? `${lab} (${val})` : lab,
4246
+ raw: r
4247
+ };
4248
+ });
4249
+ setOptions(fromCollection);
4250
+ onChange(entry.id);
4251
+ if (onSelectRecord) {
4252
+ onSelectRecord(entry);
4253
+ }
4254
+ setClientModalOpen(false);
4255
+ setNewClient({
4256
+ tipo: "Persona",
4257
+ tipoDocumento: "C\xE9dula de ciudadan\xEDa",
4258
+ id: "",
4259
+ sucursal: "",
4260
+ nombre: "",
4261
+ email: "",
4262
+ telefono: "",
4263
+ ciudad: "",
4264
+ direccion: ""
4265
+ });
4266
+ message.success(t.clientCreatedSuccess);
4267
+ } catch (err) {
4268
+ setClientError(err?.message || "Error al crear cliente.");
4269
+ } finally {
4270
+ setCreatingClient(false);
4271
+ }
4272
+ };
3561
4273
  useEffect(() => {
3562
4274
  if (!collectionId) {
3563
4275
  if (fallbackOptions && fallbackOptions.length > 0) {
@@ -3568,65 +4280,279 @@ function ReferenceSelect({
3568
4280
  }
3569
4281
  setLoading(true);
3570
4282
  ctx.adapter.listEntries(collectionId).then((res) => {
3571
- const fromCollection = res.map((r) => {
4283
+ const fromCollection = (res || []).map((r) => {
3572
4284
  const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
3573
- const lab = String(r[displayField] || r.name || r.id);
3574
- return { value: val, label: lab };
4285
+ const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
4286
+ const lab = fullName || String(r[displayField] || r.name || r.id);
4287
+ return {
4288
+ value: val,
4289
+ label: val && val !== lab ? `${lab} (${val})` : lab,
4290
+ raw: r
4291
+ };
3575
4292
  });
3576
- const fallbackList = (fallbackOptions || []).map(
3577
- (opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
3578
- );
3579
- const combined = [...fromCollection];
3580
- for (const fb of fallbackList) {
3581
- if (!combined.some((c) => c.value === fb.value || c.label === fb.label)) {
3582
- combined.push(fb);
3583
- }
3584
- }
3585
- setOptions(combined);
4293
+ setOptions(fromCollection);
3586
4294
  setLoading(false);
3587
4295
  }).catch(() => {
3588
- if (fallbackOptions && fallbackOptions.length > 0) {
3589
- setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
3590
- }
4296
+ setOptions([]);
3591
4297
  setLoading(false);
3592
4298
  });
3593
- }, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter]);
4299
+ }, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter, ctx.collectionChangedAt]);
3594
4300
  if (multiple) {
3595
4301
  const selectedList = Array.isArray(value) ? value.map(String) : typeof value === "string" && value.trim() ? value.split(",").map((s) => s.trim()).filter(Boolean) : [];
3596
4302
  return /* @__PURE__ */ jsx(
3597
- SearchableMultiSelect,
4303
+ Select,
3598
4304
  {
3599
- options,
3600
- value: selectedList,
3601
- onChange,
4305
+ size: "large",
4306
+ mode: "multiple",
3602
4307
  loading,
3603
- searchable,
4308
+ showSearch: searchable,
3604
4309
  placeholder: "Seleccionar opciones...",
3605
- searchPlaceholder: `Buscar ${collectionId === "sauces" ? "salsa" : collectionId === "extras" ? "adicional" : "opci\xF3n"}...`,
3606
- emptyMessage: "No hay opciones registradas todav\xEDa.",
3607
- max
4310
+ filterOption: (input, option) => {
4311
+ if (!input) return true;
4312
+ const q = input.toLowerCase();
4313
+ const label = String(option?.label ?? "").toLowerCase();
4314
+ const val = String(option?.value ?? "").toLowerCase();
4315
+ return label.includes(q) || val.includes(q);
4316
+ },
4317
+ maxCount: max,
4318
+ value: selectedList,
4319
+ onChange,
4320
+ options,
4321
+ className: "w-full"
3608
4322
  }
3609
4323
  );
3610
4324
  }
3611
- const singleVal = String(value ?? "");
4325
+ const singleVal = value !== void 0 && value !== null && value !== "" ? String(value) : void 0;
3612
4326
  const displayOptions = [...options];
3613
4327
  if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
3614
4328
  displayOptions.unshift({ value: singleVal, label: singleVal });
3615
4329
  }
3616
- return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
3617
- /* @__PURE__ */ jsxs(
3618
- "select",
4330
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4331
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
4332
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
4333
+ Select,
4334
+ {
4335
+ size: "large",
4336
+ loading,
4337
+ showSearch: searchable,
4338
+ placeholder: loading ? t.loadingOptions : t.selectOption,
4339
+ allowClear: true,
4340
+ filterOption: (input, option) => {
4341
+ if (!input) return true;
4342
+ const q = input.toLowerCase();
4343
+ const label = String(option?.label ?? "").toLowerCase();
4344
+ const val = String(option?.value ?? "").toLowerCase();
4345
+ return label.includes(q) || val.includes(q);
4346
+ },
4347
+ value: singleVal,
4348
+ onChange: (v) => {
4349
+ onChange(v || "");
4350
+ if (onSelectRecord) {
4351
+ const found = options.find((o) => o.value === v);
4352
+ if (found?.raw) onSelectRecord(found.raw);
4353
+ }
4354
+ },
4355
+ options: displayOptions,
4356
+ dropdownRender: (menu) => /* @__PURE__ */ jsxs("div", { children: [
4357
+ menu,
4358
+ collectionId === "clients" && /* @__PURE__ */ jsxs("div", { className: "p-2 border-t border-slate-100 flex items-center justify-between bg-slate-50", children: [
4359
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-slate-500 font-medium", children: t.cantFindClient }),
4360
+ /* @__PURE__ */ jsx(
4361
+ Button,
4362
+ {
4363
+ type: "primary",
4364
+ size: "small",
4365
+ icon: /* @__PURE__ */ jsx(Plus, { className: "w-3.5 h-3.5" }),
4366
+ onClick: () => {
4367
+ setClientError("");
4368
+ setClientModalOpen(true);
4369
+ },
4370
+ className: "bg-blue-600 hover:bg-blue-700 text-xs font-semibold rounded-lg shadow-sm",
4371
+ children: t.createClient
4372
+ }
4373
+ )
4374
+ ] })
4375
+ ] }),
4376
+ className: "w-full"
4377
+ }
4378
+ ) }),
4379
+ collectionId === "clients" && /* @__PURE__ */ jsx(
4380
+ Button,
4381
+ {
4382
+ type: "primary",
4383
+ size: "large",
4384
+ icon: /* @__PURE__ */ jsx(Plus, { className: "w-4 h-4" }),
4385
+ onClick: () => {
4386
+ setClientError("");
4387
+ setClientModalOpen(true);
4388
+ },
4389
+ className: "bg-blue-600 hover:bg-blue-700 font-bold rounded-xl shrink-0 h-10 px-4 text-xs uppercase tracking-wider",
4390
+ children: t.newBtn
4391
+ }
4392
+ )
4393
+ ] }),
4394
+ collectionId === "clients" && /* @__PURE__ */ jsx(
4395
+ Modal,
3619
4396
  {
3620
- value: singleVal,
3621
- onChange: (e) => onChange(e.target.value),
3622
- 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",
3623
- children: [
3624
- /* @__PURE__ */ jsx("option", { value: "", children: loading ? "Cargando opciones..." : "-- Selecciona una opci\xF3n --" }),
3625
- displayOptions.map((o, idx) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, `${o.value}-${idx}`))
3626
- ]
4397
+ open: clientModalOpen,
4398
+ title: /* @__PURE__ */ jsx("span", { className: "text-xl font-bold text-slate-900 font-display", children: t.basicDetails }),
4399
+ onCancel: () => setClientModalOpen(false),
4400
+ centered: true,
4401
+ width: 650,
4402
+ footer: null,
4403
+ children: /* @__PURE__ */ jsxs("div", { className: "pt-2 space-y-4", children: [
4404
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
4405
+ /* @__PURE__ */ jsxs("div", { children: [
4406
+ /* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientType }),
4407
+ /* @__PURE__ */ jsx(
4408
+ Select,
4409
+ {
4410
+ size: "large",
4411
+ value: newClient.tipo,
4412
+ onChange: (val) => {
4413
+ setNewClient((prev) => ({
4414
+ ...prev,
4415
+ tipo: val,
4416
+ tipoDocumento: val === "Empresa" ? "Nit" : "C\xE9dula de ciudadan\xEDa"
4417
+ }));
4418
+ },
4419
+ options: [
4420
+ { label: "Persona", value: "Persona" },
4421
+ { label: "Empresa", value: "Empresa" }
4422
+ ],
4423
+ className: "w-full"
4424
+ }
4425
+ )
4426
+ ] }),
4427
+ /* @__PURE__ */ jsxs("div", { children: [
4428
+ /* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientDocType }),
4429
+ /* @__PURE__ */ jsx(
4430
+ Select,
4431
+ {
4432
+ size: "large",
4433
+ value: newClient.tipoDocumento,
4434
+ onChange: (val) => setNewClient((prev) => ({ ...prev, tipoDocumento: val })),
4435
+ options: newClient.tipo === "Persona" ? [
4436
+ { label: "C\xE9dula de ciudadan\xEDa", value: "C\xE9dula de ciudadan\xEDa" },
4437
+ { label: "C\xE9dula de extranjer\xEDa", value: "C\xE9dula de extranjer\xEDa" },
4438
+ { label: "Pasaporte", value: "Pasaporte" }
4439
+ ] : [{ label: "Nit", value: "Nit" }],
4440
+ className: "w-full"
4441
+ }
4442
+ )
4443
+ ] })
4444
+ ] }),
4445
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
4446
+ /* @__PURE__ */ jsxs("div", { children: [
4447
+ /* @__PURE__ */ jsxs("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
4448
+ t.clientIdentification,
4449
+ " *"
4450
+ ] }),
4451
+ /* @__PURE__ */ jsx(
4452
+ Input,
4453
+ {
4454
+ size: "large",
4455
+ placeholder: t.clientIdentification,
4456
+ value: newClient.id,
4457
+ onChange: (e) => setNewClient((prev) => ({ ...prev, id: e.target.value }))
4458
+ }
4459
+ )
4460
+ ] }),
4461
+ /* @__PURE__ */ jsxs("div", { children: [
4462
+ /* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientBranch }),
4463
+ /* @__PURE__ */ jsx(
4464
+ Input,
4465
+ {
4466
+ size: "large",
4467
+ placeholder: t.clientBranch,
4468
+ value: newClient.sucursal,
4469
+ onChange: (e) => setNewClient((prev) => ({ ...prev, sucursal: e.target.value }))
4470
+ }
4471
+ )
4472
+ ] })
4473
+ ] }),
4474
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
4475
+ /* @__PURE__ */ jsxs("div", { children: [
4476
+ /* @__PURE__ */ jsxs("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
4477
+ t.clientName,
4478
+ " *"
4479
+ ] }),
4480
+ /* @__PURE__ */ jsx(
4481
+ Input,
4482
+ {
4483
+ size: "large",
4484
+ placeholder: t.clientName,
4485
+ value: newClient.nombre,
4486
+ onChange: (e) => setNewClient((prev) => ({ ...prev, nombre: e.target.value }))
4487
+ }
4488
+ )
4489
+ ] }),
4490
+ /* @__PURE__ */ jsxs("div", { children: [
4491
+ /* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientEmail }),
4492
+ /* @__PURE__ */ jsx(
4493
+ Input,
4494
+ {
4495
+ size: "large",
4496
+ placeholder: t.clientEmail,
4497
+ value: newClient.email,
4498
+ onChange: (e) => setNewClient((prev) => ({ ...prev, email: e.target.value }))
4499
+ }
4500
+ )
4501
+ ] })
4502
+ ] }),
4503
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
4504
+ /* @__PURE__ */ jsxs("div", { children: [
4505
+ /* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientPhone }),
4506
+ /* @__PURE__ */ jsx(
4507
+ Input,
4508
+ {
4509
+ size: "large",
4510
+ placeholder: t.clientPhone,
4511
+ value: newClient.telefono,
4512
+ onChange: (e) => setNewClient((prev) => ({ ...prev, telefono: e.target.value }))
4513
+ }
4514
+ )
4515
+ ] }),
4516
+ /* @__PURE__ */ jsxs("div", { children: [
4517
+ /* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientCity }),
4518
+ /* @__PURE__ */ jsx(
4519
+ Input,
4520
+ {
4521
+ size: "large",
4522
+ placeholder: t.clientCity,
4523
+ value: newClient.ciudad,
4524
+ onChange: (e) => setNewClient((prev) => ({ ...prev, ciudad: e.target.value }))
4525
+ }
4526
+ )
4527
+ ] })
4528
+ ] }),
4529
+ /* @__PURE__ */ jsxs("div", { children: [
4530
+ /* @__PURE__ */ jsx("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientAddress }),
4531
+ /* @__PURE__ */ jsx(
4532
+ Input,
4533
+ {
4534
+ size: "large",
4535
+ placeholder: t.clientAddress,
4536
+ value: newClient.direccion,
4537
+ onChange: (e) => setNewClient((prev) => ({ ...prev, direccion: e.target.value }))
4538
+ }
4539
+ )
4540
+ ] }),
4541
+ clientError && /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold text-red-600 bg-red-50 p-2.5 rounded-lg border border-red-200", children: clientError }),
4542
+ /* @__PURE__ */ jsx(
4543
+ Button,
4544
+ {
4545
+ type: "primary",
4546
+ size: "large",
4547
+ loading: creatingClient,
4548
+ onClick: handleSaveClient,
4549
+ className: "w-full bg-blue-600 hover:bg-blue-700 font-bold uppercase rounded-xl h-11 text-xs tracking-wider shadow-sm mt-2",
4550
+ children: t.create.toUpperCase()
4551
+ }
4552
+ )
4553
+ ] })
3627
4554
  }
3628
- ),
3629
- /* @__PURE__ */ jsx(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
4555
+ )
3630
4556
  ] });
3631
4557
  }
3632
4558
  function ReferenceTableCell({