admin-lib-cms 1.2.15 → 1.2.17

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.js CHANGED
@@ -887,8 +887,11 @@ var translations = {
887
887
  saveSignature: "Guardar Firma",
888
888
  selectOption: "-- Selecciona una opci\xF3n --",
889
889
  loadingOptions: "Cargando opciones...",
890
- cantFindClient: "\xBFNo encuentras el cliente?",
891
- createClient: "Crear cliente",
890
+ cantFindOption: "\xBFNo encuentras la opci\xF3n?",
891
+ createNewOption: "Crear nuevo",
892
+ recordCreatedSuccess: "Registro creado y seleccionado exitosamente.",
893
+ cantFindClient: "\xBFNo encuentras la opci\xF3n?",
894
+ createClient: "Crear nuevo",
892
895
  newBtn: "Nuevo",
893
896
  basicDetails: "Datos b\xE1sicos",
894
897
  clientType: "Tipo",
@@ -970,8 +973,11 @@ var translations = {
970
973
  saveSignature: "Save Signature",
971
974
  selectOption: "-- Select an option --",
972
975
  loadingOptions: "Loading options...",
973
- cantFindClient: "Can't find the client?",
974
- createClient: "Create client",
976
+ cantFindOption: "Can't find the option?",
977
+ createNewOption: "Create new",
978
+ recordCreatedSuccess: "Record created and selected successfully.",
979
+ cantFindClient: "Can't find the option?",
980
+ createClient: "Create new",
975
981
  newBtn: "New",
976
982
  basicDetails: "Basic details",
977
983
  clientType: "Type",
@@ -2525,9 +2531,29 @@ function CollectionEditor({ collection }) {
2525
2531
  setLoadingEntries(true);
2526
2532
  ctx.adapter.listEntries(collection.id).then((res) => {
2527
2533
  const sorted = [...res].sort((a, b) => {
2528
- const orderA = Number(a.order) || 0;
2529
- const orderB = Number(b.order) || 0;
2530
- return orderA - orderB;
2534
+ if (collection.defaultSort) {
2535
+ if (typeof collection.defaultSort === "function") {
2536
+ return collection.defaultSort(a, b);
2537
+ }
2538
+ const field = collection.defaultSort.field;
2539
+ const valA = a[field];
2540
+ const valB = b[field];
2541
+ const dir = collection.defaultSort.direction === "desc" ? -1 : 1;
2542
+ if (valA === valB) return 0;
2543
+ if (valA === void 0 || valA === null) return 1;
2544
+ if (valB === void 0 || valB === null) return -1;
2545
+ if (typeof valA === "number" && typeof valB === "number") {
2546
+ return (valA - valB) * dir;
2547
+ }
2548
+ return String(valA).localeCompare(String(valB)) * dir;
2549
+ }
2550
+ const hasOrderField = collection.fields.some((f) => f.id === "order");
2551
+ if (hasOrderField) {
2552
+ const orderA = Number(a.order) || 0;
2553
+ const orderB = Number(b.order) || 0;
2554
+ if (orderA !== orderB) return orderA - orderB;
2555
+ }
2556
+ return 0;
2531
2557
  });
2532
2558
  setEntries(sorted);
2533
2559
  setLoadingEntries(false);
@@ -2591,10 +2617,35 @@ function CollectionEditor({ collection }) {
2591
2617
  let val = String(finalEditing[sourceField] || finalEditing.id || "");
2592
2618
  val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
2593
2619
  finalEditing[f.id] = val;
2620
+ } else if (f.type === "list" || f.multiple) {
2621
+ if (Array.isArray(finalEditing[f.id])) {
2622
+ finalEditing[f.id] = finalEditing[f.id].filter(
2623
+ (item) => item !== void 0 && item !== null && String(item).trim() !== ""
2624
+ );
2625
+ } else if (typeof finalEditing[f.id] === "string" && finalEditing[f.id]) {
2626
+ finalEditing[f.id] = [String(finalEditing[f.id]).trim()];
2627
+ }
2594
2628
  }
2595
2629
  });
2596
- const isClientOrEmployee = collection.id === "clients" || collection.id === "employees";
2597
- const uniqueFields = collection.fields.filter((f) => f.unique || isClientOrEmployee && f.id === "id");
2630
+ for (const f of collection.fields) {
2631
+ if (f.required) {
2632
+ if (isCreatingEntry && f.hideOnCreate) continue;
2633
+ if (f.dependsOn && finalEditing[f.dependsOn.field] !== void 0) {
2634
+ const targetVal = f.dependsOn.value;
2635
+ const currentVal = finalEditing[f.dependsOn.field];
2636
+ const match = Array.isArray(targetVal) ? targetVal.includes(currentVal) : currentVal === targetVal;
2637
+ if (!match) continue;
2638
+ }
2639
+ const rawVal = finalEditing[f.id];
2640
+ const isEmpty = rawVal === void 0 || rawVal === null || typeof rawVal === "string" && rawVal.trim() === "" || Array.isArray(rawVal) && rawVal.length === 0;
2641
+ if (isEmpty) {
2642
+ message.error(`El campo "${f.label || f.id}" es obligatorio.`);
2643
+ setSaving(false);
2644
+ return;
2645
+ }
2646
+ }
2647
+ }
2648
+ const uniqueFields = collection.fields.filter((f) => f.unique);
2598
2649
  for (const f of uniqueFields) {
2599
2650
  const val = String(finalEditing[f.id] || "").trim().toLowerCase();
2600
2651
  if (!val) {
@@ -2627,6 +2678,18 @@ function CollectionEditor({ collection }) {
2627
2678
  await ctx.adapter.putEntry(collection.id, finalEditing);
2628
2679
  message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
2629
2680
  ctx.notifyCollectionChanged();
2681
+ setEntries((prev) => {
2682
+ const next = [...prev];
2683
+ const matchIdx = next.findIndex(
2684
+ (e) => originalId && String(e.id || "").trim().toLowerCase() === String(originalId).trim().toLowerCase() || String(e.id || "").trim().toLowerCase() === String(finalEditing.id || "").trim().toLowerCase()
2685
+ );
2686
+ if (matchIdx >= 0) {
2687
+ next[matchIdx] = { ...next[matchIdx], ...finalEditing };
2688
+ } else {
2689
+ next.unshift(finalEditing);
2690
+ }
2691
+ return next;
2692
+ });
2630
2693
  setEditing(null);
2631
2694
  setOriginalId(null);
2632
2695
  setIsCreatingManual(false);
@@ -2640,6 +2703,9 @@ function CollectionEditor({ collection }) {
2640
2703
  setDeletingId(id);
2641
2704
  try {
2642
2705
  await ctx.adapter.deleteEntry(collection.id, id);
2706
+ setEntries(
2707
+ (prev) => prev.filter((e) => String(e.id || "").trim().toLowerCase() !== String(id).trim().toLowerCase())
2708
+ );
2643
2709
  ctx.notifyCollectionChanged();
2644
2710
  load();
2645
2711
  } finally {
@@ -2707,7 +2773,10 @@ function CollectionEditor({ collection }) {
2707
2773
  {
2708
2774
  size: "large",
2709
2775
  prefix: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Search, { className: "h-4 w-4 text-slate-400" }),
2710
- placeholder: `Buscar por ${collection.searchBy.map((s) => s === "numero" ? "n\xFAmero" : s === "clienteNombre" ? "cliente" : s === "clienteId" ? "identificaci\xF3n" : s === "fecha" ? "fecha" : s).join(", ")}...`,
2776
+ placeholder: `Buscar por ${collection.searchBy.map((s) => {
2777
+ const f = collection.fields.find((field) => field.id === s);
2778
+ return f?.label ? f.label.toLowerCase() : s;
2779
+ }).join(", ")}...`,
2711
2780
  value: search,
2712
2781
  allowClear: true,
2713
2782
  onChange: (e) => {
@@ -2837,7 +2906,7 @@ function CollectionEditor({ collection }) {
2837
2906
  }
2838
2907
  return true;
2839
2908
  }).map((f) => {
2840
- 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";
2909
+ const isFullWidth = f.colSpan === 2 || f.colSpan === 12 || f.multiple || 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";
2841
2910
  const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
2842
2911
  if (isViewingDetail) {
2843
2912
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${colSpanClass}`, children: [
@@ -2847,7 +2916,9 @@ function CollectionEditor({ collection }) {
2847
2916
  record: editing,
2848
2917
  onChange: () => {
2849
2918
  },
2850
- isCreatingEntry: false
2919
+ isCreatingEntry: false,
2920
+ isViewingDetail: true,
2921
+ readOnly: true
2851
2922
  }) : f.type === "signature" ? editing[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl border border-slate-200 bg-white p-3 flex items-center justify-center shadow-sm", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2852
2923
  "img",
2853
2924
  {
@@ -2855,14 +2926,14 @@ function CollectionEditor({ collection }) {
2855
2926
  alt: f.label,
2856
2927
  className: "h-28 w-auto max-w-full object-contain"
2857
2928
  }
2858
- ) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-400 italic py-1", children: "Sin firma registrada" }) : f.type === "list" ? Array.isArray(editing[f.id]) && editing[f.id].length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-1.5 pt-0.5", children: editing[f.id].map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2929
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-400 italic py-1", children: "Sin firma registrada" }) : f.type === "list" || f.multiple ? Array.isArray(editing[f.id]) && editing[f.id].length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-1.5 pt-0.5", children: editing[f.id].map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2859
2930
  "span",
2860
2931
  {
2861
- className: "rounded-full bg-slate-100 text-slate-700 px-3 py-1 text-xs font-medium border border-slate-200",
2932
+ className: "rounded-xl bg-slate-100 text-slate-700 px-3 py-1 text-xs font-medium border border-slate-200",
2862
2933
  children: String(item)
2863
2934
  },
2864
2935
  idx
2865
- )) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-400 italic py-1", children: "Ninguno" }) : f.type === "link" ? Boolean(editing[f.id]) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2936
+ )) }) : typeof editing[f.id] === "string" && editing[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2 text-sm text-slate-800 font-medium", children: String(editing[f.id]) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-400 italic py-1", children: "Ninguno" }) : f.type === "link" ? Boolean(editing[f.id]) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2866
2937
  "a",
2867
2938
  {
2868
2939
  href: String(editing[f.id]),
@@ -2879,14 +2950,19 @@ function CollectionEditor({ collection }) {
2879
2950
  }
2880
2951
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${colSpanClass}`, children: [
2881
2952
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
2882
- f.label,
2953
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
2954
+ f.label,
2955
+ (f.required || f.unique) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-rose-500 ml-1 font-bold", title: "Campo obligatorio", children: "*" })
2956
+ ] }),
2883
2957
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
2884
2958
  ] }),
2885
2959
  f.customRender ? f.customRender({
2886
2960
  value: editing[f.id],
2887
2961
  record: editing,
2888
2962
  onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2889
- isCreatingEntry
2963
+ isCreatingEntry,
2964
+ isViewingDetail: false,
2965
+ readOnly: false
2890
2966
  }) : f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2891
2967
  BranchSettingsEditor,
2892
2968
  {
@@ -3020,21 +3096,8 @@ function CollectionEditor({ collection }) {
3020
3096
  value: editing[f.id],
3021
3097
  onChange: (val) => setEditing({ ...editing, [f.id]: val }),
3022
3098
  onSelectRecord: (rec) => {
3023
- if (f.id === "clienteId" && rec) {
3024
- setEditing((prev) => prev ? {
3025
- ...prev,
3026
- clienteId: rec.id || prev.clienteId,
3027
- clienteNombre: rec.nombre || rec.name || prev.clienteNombre,
3028
- ciudad: rec.ciudad || prev.ciudad,
3029
- direccion: rec.direccion || prev.direccion,
3030
- telefono: rec.telefono || prev.telefono
3031
- } : prev);
3032
- } else if (f.id === "empleadoId" && rec) {
3033
- setEditing((prev) => prev ? {
3034
- ...prev,
3035
- empleadoId: rec.id || prev.empleadoId,
3036
- empleadoNombre: rec.apellido ? `${rec.nombre || rec.name || ""} ${rec.apellido}`.trim() : rec.nombre || rec.name || prev.empleadoNombre
3037
- } : prev);
3099
+ if (f.onSelectRecord) {
3100
+ setEditing((prev) => prev ? { ...prev, ...f.onSelectRecord(rec, prev) } : prev);
3038
3101
  }
3039
3102
  }
3040
3103
  }
@@ -3290,63 +3353,61 @@ function CollectionEditor({ collection }) {
3290
3353
  ]
3291
3354
  }
3292
3355
  )
3293
- ] }) : f.type === "list" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
3294
- (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : []).map((item, idx) => {
3295
- const isFeatures = f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") || f.label.toLowerCase().includes("beneficio");
3296
- const placeholder = isFeatures ? `Caracter\xEDstica o beneficio ${idx + 1}...` : `Entregable o punto clave ${idx + 1}...`;
3297
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2 items-center", children: [
3298
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-mono font-bold text-slate-400 w-6 text-right shrink-0", children: [
3299
- idx + 1,
3300
- "."
3356
+ ] }) : f.type === "list" || f.multiple ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "space-y-3", children: (() => {
3357
+ const currentArr = Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" && editing[f.id] ? [editing[f.id]] : [""];
3358
+ const displayArr = currentArr.length > 0 ? currentArr : [""];
3359
+ const singularLabel = f.label.endsWith("es") ? f.label.slice(0, -2) : f.label.endsWith("s") ? f.label.slice(0, -1) : f.label;
3360
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-2.5", children: [
3361
+ displayArr.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2 items-center", children: [
3362
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-mono font-bold text-slate-400 w-7 text-right shrink-0", children: [
3363
+ "#",
3364
+ idx + 1
3301
3365
  ] }),
3302
3366
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3303
3367
  "input",
3304
3368
  {
3305
3369
  type: "text",
3306
3370
  value: String(item ?? ""),
3307
- placeholder,
3371
+ placeholder: `${singularLabel} #${idx + 1}...`,
3308
3372
  onChange: (e) => {
3309
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
3373
+ const arr = [...displayArr];
3310
3374
  arr[idx] = e.target.value;
3311
3375
  setEditing({ ...editing, [f.id]: arr });
3312
3376
  },
3313
3377
  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"
3314
3378
  }
3315
3379
  ),
3316
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3380
+ displayArr.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3317
3381
  "button",
3318
3382
  {
3319
3383
  type: "button",
3320
3384
  onClick: () => {
3321
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
3322
- arr.splice(idx, 1);
3323
- setEditing({ ...editing, [f.id]: arr });
3385
+ const arr = displayArr.filter((_, i) => i !== idx);
3386
+ setEditing({ ...editing, [f.id]: arr.length > 0 ? arr : [""] });
3324
3387
  },
3325
- className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer",
3388
+ className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors cursor-pointer shrink-0",
3326
3389
  title: "Eliminar elemento",
3327
3390
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
3328
3391
  }
3329
3392
  )
3330
- ] }, idx);
3331
- }),
3332
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3333
- "button",
3334
- {
3335
- type: "button",
3336
- onClick: () => {
3337
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
3338
- arr.push("");
3339
- setEditing({ ...editing, [f.id]: arr });
3340
- },
3341
- 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",
3342
- children: [
3343
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
3344
- " ",
3345
- f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") ? "Agregar caracter\xEDstica uno a uno" : "Agregar entregable / punto uno a uno"
3346
- ]
3347
- }
3348
- )
3349
- ] }) : f.type === "link" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2 items-center", children: [
3393
+ ] }, idx)),
3394
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3395
+ "button",
3396
+ {
3397
+ type: "button",
3398
+ onClick: () => {
3399
+ setEditing({ ...editing, [f.id]: [...displayArr, ""] });
3400
+ },
3401
+ 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",
3402
+ children: [
3403
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
3404
+ " Agregar ",
3405
+ singularLabel.toLowerCase()
3406
+ ]
3407
+ }
3408
+ )
3409
+ ] });
3410
+ })() }) : f.type === "link" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2 items-center", children: [
3350
3411
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3351
3412
  import_antd.Input,
3352
3413
  {
@@ -3393,7 +3454,7 @@ function CollectionEditor({ collection }) {
3393
3454
  }
3394
3455
  },
3395
3456
  onBlur: (e) => {
3396
- const isUniqueField = f.unique || (collection.id === "clients" || collection.id === "employees") && f.id === "id";
3457
+ const isUniqueField = Boolean(f.unique);
3397
3458
  if (isUniqueField) {
3398
3459
  const val = (e.target.value || "").trim().toLowerCase();
3399
3460
  if (val) {
@@ -3528,7 +3589,30 @@ function CollectionEditor({ collection }) {
3528
3589
  onDragEnd,
3529
3590
  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" : ""}`,
3530
3591
  children: [
3531
- visibleFields.map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.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-slate-100 text-slate-700 border border-slate-200" : String(e[f.id]) === "Vencido" || String(e[f.id]).toLowerCase().includes("vencid") ? "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__ */ (0, import_jsx_runtime5.jsx)("span", { className: "font-medium text-slate-800", children: String(e.clienteNombre) }) : e.empleadoNombre && f.id === "empleadoId" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "font-medium text-slate-800", children: String(e.empleadoNombre) }) : /* @__PURE__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.jsx)(import_antd.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__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "font-semibold text-slate-800", children: [
3592
+ visibleFields.map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.renderCell ? f.renderCell(e[f.id], e) : f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.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-slate-100 text-slate-700 border border-slate-200" : String(e[f.id]) === "Vencido" || String(e[f.id]).toLowerCase().includes("vencid") ? "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] ? f.onCellClick ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3593
+ "button",
3594
+ {
3595
+ type: "button",
3596
+ onClick: () => f.onCellClick(e[f.id], e),
3597
+ className: "font-medium text-indigo-600 hover:text-indigo-800 hover:underline cursor-pointer text-left truncate block max-w-full",
3598
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple })
3599
+ }
3600
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : (f.type === "list" || f.multiple) && e[f.id] ? Array.isArray(e[f.id]) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-1", children: [
3601
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "truncate", children: String(e[f.id][0] || "") }),
3602
+ e[f.id].length > 1 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "inline-flex items-center px-1.5 py-0.2 rounded text-[10px] font-bold bg-indigo-50 text-indigo-700 border border-indigo-100 shrink-0", children: [
3603
+ "+",
3604
+ e[f.id].length - 1,
3605
+ " m\xE1s"
3606
+ ] })
3607
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: String(e[f.id]) }) : f.onCellClick ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3608
+ "button",
3609
+ {
3610
+ type: "button",
3611
+ onClick: () => f.onCellClick(e[f.id], e),
3612
+ className: "font-medium text-indigo-600 hover:text-indigo-800 hover:underline cursor-pointer text-left truncate block w-full",
3613
+ children: String(e[f.id] ?? "")
3614
+ }
3615
+ ) : f.type === "signature" && e[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd.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__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "font-semibold text-slate-800", children: [
3532
3616
  "$ ",
3533
3617
  Number(e[f.id]).toLocaleString("es-CO")
3534
3618
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.jsxs)(
@@ -3545,18 +3629,22 @@ function CollectionEditor({ collection }) {
3545
3629
  }
3546
3630
  ) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? formatTo12Hour(e[f.id]) || String(e[f.id] ?? "") : String(e[f.id] ?? "") }, f.id)),
3547
3631
  /* @__PURE__ */ (0, import_jsx_runtime5.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__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-end gap-1.5", children: [
3548
- collection.enableDetailView && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3632
+ (collection.enableDetailView || collection.onViewRecord) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3549
3633
  "button",
3550
3634
  {
3551
3635
  onClick: () => {
3636
+ if (collection.onViewRecord) {
3637
+ collection.onViewRecord(e);
3638
+ return;
3639
+ }
3552
3640
  setIsCreatingManual(false);
3553
3641
  setIsViewingDetail(true);
3554
3642
  setOriginalId(String(e.id || ""));
3555
3643
  setDuplicateErrors({});
3556
3644
  setEditing({ ...e });
3557
3645
  },
3558
- className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
3559
- title: "Ver detalle",
3646
+ className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors cursor-pointer",
3647
+ title: collection.viewRecordTitle || "Ver detalle",
3560
3648
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Eye, { className: "h-4 w-4" })
3561
3649
  }
3562
3650
  ),
@@ -5150,9 +5238,9 @@ function ReferenceSelect({
5150
5238
  displayField = "name",
5151
5239
  valueField = "name",
5152
5240
  fallbackOptions,
5153
- multiple = false,
5241
+ multiple: _multiple = false,
5154
5242
  searchable = false,
5155
- max,
5243
+ max: _max,
5156
5244
  value,
5157
5245
  onChange,
5158
5246
  onSelectRecord
@@ -5162,45 +5250,46 @@ function ReferenceSelect({
5162
5250
  const { message } = import_antd.App.useApp();
5163
5251
  const [options, setOptions] = (0, import_react5.useState)([]);
5164
5252
  const [loading, setLoading] = (0, import_react5.useState)(true);
5165
- const [clientModalOpen, setClientModalOpen] = (0, import_react5.useState)(false);
5166
- const [creatingClient, setCreatingClient] = (0, import_react5.useState)(false);
5167
- const [clientError, setClientError] = (0, import_react5.useState)("");
5168
- const [newClient, setNewClient] = (0, import_react5.useState)({
5169
- tipo: "Persona",
5170
- tipoDocumento: "C\xE9dula de ciudadan\xEDa",
5171
- id: "",
5172
- sucursal: "",
5173
- nombre: "",
5174
- email: "",
5175
- telefono: "",
5176
- ciudad: "",
5177
- direccion: ""
5178
- });
5179
- const handleSaveClient = async () => {
5180
- setClientError("");
5181
- if (!newClient.id.trim()) {
5182
- setClientError(t.idRequired);
5183
- return;
5184
- }
5185
- if (!newClient.nombre.trim()) {
5186
- setClientError(t.nameRequired);
5187
- return;
5188
- }
5189
- const cleanId = newClient.id.trim().toLowerCase();
5190
- const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
5191
- if (isDuplicate) {
5192
- setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
5193
- return;
5253
+ const [modalOpen, setModalOpen] = (0, import_react5.useState)(false);
5254
+ const [saving, setSaving] = (0, import_react5.useState)(false);
5255
+ const [formError, setFormError] = (0, import_react5.useState)("");
5256
+ const [newRecord, setNewRecord] = (0, import_react5.useState)({});
5257
+ const targetCol = ctx.config.collections?.find((c) => c.id === collectionId);
5258
+ const handleSaveRecord = async () => {
5259
+ setFormError("");
5260
+ if (!targetCol) return;
5261
+ const uniqueFields = targetCol.fields.filter((f) => f.unique || f.id === "id" && !f.hideOnCreate);
5262
+ for (const uf of uniqueFields) {
5263
+ const val = String(newRecord[uf.id] || "").trim();
5264
+ if (!val) {
5265
+ setFormError(`El campo "${uf.label || uf.id}" es obligatorio.`);
5266
+ return;
5267
+ }
5268
+ const isDup = options.some((opt) => String(opt.value || "").trim().toLowerCase() === val.toLowerCase());
5269
+ if (isDup) {
5270
+ setFormError(`Ya existe un registro con este ${uf.label.toLowerCase()} (\xAB${val}\xBB).`);
5271
+ return;
5272
+ }
5194
5273
  }
5195
- setCreatingClient(true);
5274
+ setSaving(true);
5196
5275
  try {
5197
- const entry = {
5198
- ...newClient,
5199
- id: newClient.id.trim(),
5200
- nombre: newClient.nombre.trim()
5276
+ const entryToSave = {
5277
+ id: String(newRecord.id || Date.now()).trim(),
5278
+ ...newRecord
5201
5279
  };
5202
- await ctx.adapter.putEntry("clients", entry);
5203
- const res = await ctx.adapter.listEntries("clients");
5280
+ targetCol.fields.forEach((f) => {
5281
+ if (f.type === "list" || f.multiple) {
5282
+ if (Array.isArray(entryToSave[f.id])) {
5283
+ entryToSave[f.id] = entryToSave[f.id].filter(
5284
+ (item) => item !== void 0 && item !== null && String(item).trim() !== ""
5285
+ );
5286
+ } else if (typeof entryToSave[f.id] === "string" && entryToSave[f.id]) {
5287
+ entryToSave[f.id] = [String(entryToSave[f.id]).trim()];
5288
+ }
5289
+ }
5290
+ });
5291
+ await ctx.adapter.putEntry(collectionId, entryToSave);
5292
+ const res = await ctx.adapter.listEntries(collectionId);
5204
5293
  const fromCollection = (res || []).map((r) => {
5205
5294
  const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
5206
5295
  const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
@@ -5212,27 +5301,18 @@ function ReferenceSelect({
5212
5301
  };
5213
5302
  });
5214
5303
  setOptions(fromCollection);
5215
- onChange(entry.id);
5304
+ const selectedVal = valueField && entryToSave[valueField] !== void 0 ? String(entryToSave[valueField]) : entryToSave.id;
5305
+ onChange(selectedVal);
5216
5306
  if (onSelectRecord) {
5217
- onSelectRecord(entry);
5307
+ onSelectRecord(entryToSave);
5218
5308
  }
5219
- setClientModalOpen(false);
5220
- setNewClient({
5221
- tipo: "Persona",
5222
- tipoDocumento: "C\xE9dula de ciudadan\xEDa",
5223
- id: "",
5224
- sucursal: "",
5225
- nombre: "",
5226
- email: "",
5227
- telefono: "",
5228
- ciudad: "",
5229
- direccion: ""
5230
- });
5231
- message.success(t.clientCreatedSuccess);
5309
+ setModalOpen(false);
5310
+ setNewRecord({});
5311
+ message.success(t.recordCreatedSuccess || "Registro creado y seleccionado exitosamente.");
5232
5312
  } catch (err) {
5233
- setClientError(err?.message || "Error al crear cliente.");
5313
+ setFormError(err?.message || "Error al crear registro.");
5234
5314
  } finally {
5235
- setCreatingClient(false);
5315
+ setSaving(false);
5236
5316
  }
5237
5317
  };
5238
5318
  (0, import_react5.useEffect)(() => {
@@ -5257,41 +5337,24 @@ function ReferenceSelect({
5257
5337
  });
5258
5338
  setOptions(fromCollection);
5259
5339
  setLoading(false);
5260
- }).catch(() => {
5261
- setOptions([]);
5340
+ }).catch((err) => {
5341
+ console.error(`Failed to load reference entries for ${collectionId}:`, err);
5342
+ if (fallbackOptions && fallbackOptions.length > 0) {
5343
+ setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
5344
+ }
5262
5345
  setLoading(false);
5263
5346
  });
5264
- }, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter, ctx.collectionChangedAt]);
5265
- if (multiple) {
5266
- const selectedList = Array.isArray(value) ? value.map(String) : typeof value === "string" && value.trim() ? value.split(",").map((s) => s.trim()).filter(Boolean) : [];
5267
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5268
- import_antd.Select,
5269
- {
5270
- size: "large",
5271
- mode: "multiple",
5272
- loading,
5273
- showSearch: searchable,
5274
- placeholder: "Seleccionar opciones...",
5275
- filterOption: (input, option) => {
5276
- if (!input) return true;
5277
- const q = input.toLowerCase();
5278
- const label = String(option?.label ?? "").toLowerCase();
5279
- const val = String(option?.value ?? "").toLowerCase();
5280
- return label.includes(q) || val.includes(q);
5281
- },
5282
- maxCount: max,
5283
- value: selectedList,
5284
- onChange,
5285
- options,
5286
- className: "w-full"
5287
- }
5288
- );
5289
- }
5290
- const singleVal = value !== void 0 && value !== null && value !== "" ? String(value) : void 0;
5291
- const displayOptions = [...options];
5292
- if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
5293
- displayOptions.unshift({ value: singleVal, label: singleVal });
5294
- }
5347
+ }, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter]);
5348
+ const rawVal = Array.isArray(value) ? value : value !== void 0 && value !== null && value !== "" ? [value] : [];
5349
+ const singleVal = rawVal[0] !== void 0 ? String(rawVal[0]) : void 0;
5350
+ const displayOptions = (0, import_react5.useMemo)(() => {
5351
+ const list = [...options];
5352
+ if (singleVal && !list.some((o) => o.value === singleVal)) {
5353
+ list.unshift({ value: singleVal, label: `${singleVal} (actual)` });
5354
+ }
5355
+ return list;
5356
+ }, [options, singleVal]);
5357
+ const canQuickCreate = Boolean(targetCol && targetCol.enableQuickCreate !== false);
5295
5358
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
5296
5359
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
5297
5360
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex-1", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -5320,8 +5383,8 @@ function ReferenceSelect({
5320
5383
  options: displayOptions,
5321
5384
  dropdownRender: (menu) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5322
5385
  menu,
5323
- collectionId === "clients" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-2 border-t border-slate-100 flex items-center justify-between bg-slate-50", children: [
5324
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs text-slate-500 font-medium", children: t.cantFindClient }),
5386
+ canQuickCreate && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-2 border-t border-slate-100 flex items-center justify-between bg-slate-50", children: [
5387
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs text-slate-500 font-medium", children: t.cantFindOption || "\xBFNo encuentras la opci\xF3n?" }),
5325
5388
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5326
5389
  import_antd.Button,
5327
5390
  {
@@ -5329,11 +5392,18 @@ function ReferenceSelect({
5329
5392
  size: "small",
5330
5393
  icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
5331
5394
  onClick: () => {
5332
- setClientError("");
5333
- setClientModalOpen(true);
5395
+ setFormError("");
5396
+ const init = {};
5397
+ targetCol.fields.forEach((f) => {
5398
+ if (f.defaultValue !== void 0) init[f.id] = f.defaultValue;
5399
+ else if (f.type === "list" || f.multiple) init[f.id] = [""];
5400
+ else init[f.id] = "";
5401
+ });
5402
+ setNewRecord(init);
5403
+ setModalOpen(true);
5334
5404
  },
5335
5405
  className: "bg-blue-600 hover:bg-blue-700 text-xs font-semibold rounded-lg shadow-sm",
5336
- children: t.createClient
5406
+ children: t.createNewOption || `Crear ${targetCol.name}`
5337
5407
  }
5338
5408
  )
5339
5409
  ] })
@@ -5341,192 +5411,191 @@ function ReferenceSelect({
5341
5411
  className: "w-full"
5342
5412
  }
5343
5413
  ) }),
5344
- collectionId === "clients" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5414
+ canQuickCreate && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5345
5415
  import_antd.Button,
5346
5416
  {
5347
5417
  type: "primary",
5348
5418
  size: "large",
5349
5419
  icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-4 h-4" }),
5350
5420
  onClick: () => {
5351
- setClientError("");
5352
- setClientModalOpen(true);
5421
+ setFormError("");
5422
+ const init = {};
5423
+ targetCol.fields.forEach((f) => {
5424
+ if (f.defaultValue !== void 0) init[f.id] = f.defaultValue;
5425
+ else if (f.type === "list" || f.multiple) init[f.id] = [""];
5426
+ else init[f.id] = "";
5427
+ });
5428
+ setNewRecord(init);
5429
+ setModalOpen(true);
5353
5430
  },
5354
5431
  className: "bg-blue-600 hover:bg-blue-700 font-bold rounded-xl shrink-0 h-10 px-4 text-xs uppercase tracking-wider",
5355
- children: t.newBtn
5432
+ children: targetCol.submitLabel || t.newBtn
5356
5433
  }
5357
5434
  )
5358
5435
  ] }),
5359
- collectionId === "clients" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5436
+ canQuickCreate && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5360
5437
  import_antd.Modal,
5361
5438
  {
5362
- open: clientModalOpen,
5363
- title: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xl font-bold text-slate-900 font-display", children: t.basicDetails }),
5364
- onCancel: () => setClientModalOpen(false),
5439
+ open: modalOpen,
5440
+ title: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xl font-bold text-slate-900 font-display", children: targetCol.createTitle || `${t.newBtn} ${targetCol.name}` }),
5441
+ onCancel: () => setModalOpen(false),
5365
5442
  centered: true,
5366
5443
  width: 650,
5367
5444
  footer: null,
5368
5445
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "pt-2 space-y-4", children: [
5369
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5370
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5371
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientType }),
5372
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5373
- import_antd.Select,
5374
- {
5375
- size: "large",
5376
- value: newClient.tipo,
5377
- onChange: (val) => {
5378
- setNewClient((prev) => ({
5379
- ...prev,
5380
- tipo: val,
5381
- tipoDocumento: val === "Empresa" ? "Nit" : "C\xE9dula de ciudadan\xEDa"
5382
- }));
5383
- },
5384
- options: [
5385
- { label: "Persona", value: "Persona" },
5386
- { label: "Empresa", value: "Empresa" }
5387
- ],
5388
- className: "w-full"
5389
- }
5390
- )
5391
- ] }),
5392
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5393
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientDocType }),
5394
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5395
- import_antd.Select,
5396
- {
5397
- size: "large",
5398
- value: newClient.tipoDocumento,
5399
- onChange: (val) => setNewClient((prev) => ({ ...prev, tipoDocumento: val })),
5400
- options: newClient.tipo === "Persona" ? [
5401
- { label: "C\xE9dula de ciudadan\xEDa", value: "C\xE9dula de ciudadan\xEDa" },
5402
- { label: "C\xE9dula de extranjer\xEDa", value: "C\xE9dula de extranjer\xEDa" },
5403
- { label: "Pasaporte", value: "Pasaporte" }
5404
- ] : [{ label: "Nit", value: "Nit" }],
5405
- className: "w-full"
5406
- }
5407
- )
5408
- ] })
5409
- ] }),
5410
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5411
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5446
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: targetCol.fields.filter((f) => !f.hideOnCreate && !f.readOnly && f.type !== "signature").map((f) => {
5447
+ if (f.dependsOn && newRecord[f.dependsOn.field] !== void 0) {
5448
+ const targetVal = f.dependsOn.value;
5449
+ const currentVal = newRecord[f.dependsOn.field];
5450
+ const match = Array.isArray(targetVal) ? targetVal.includes(currentVal) : currentVal === targetVal;
5451
+ if (!match) return null;
5452
+ }
5453
+ const isFullWidth = f.colSpan === 2 || f.colSpan === 12 || f.multiple || f.type === "list" || f.type === "textarea";
5454
+ const colSpanClass = isFullWidth ? "col-span-1 sm:col-span-2" : "col-span-1";
5455
+ if (f.type === "list" || f.multiple) {
5456
+ const currentList = Array.isArray(newRecord[f.id]) ? newRecord[f.id] : newRecord[f.id] ? [String(newRecord[f.id])] : [""];
5457
+ const singularLabel = f.label.endsWith("es") ? f.label.slice(0, -2) : f.label.endsWith("s") ? f.label.slice(0, -1) : f.label;
5458
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: colSpanClass, children: [
5459
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: f.label }),
5460
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-2", children: [
5461
+ currentList.map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
5462
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-mono font-bold text-slate-400 w-6 text-right shrink-0", children: [
5463
+ "#",
5464
+ idx + 1
5465
+ ] }),
5466
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5467
+ import_antd.Input,
5468
+ {
5469
+ size: "large",
5470
+ value: item,
5471
+ placeholder: `${singularLabel} #${idx + 1}...`,
5472
+ onChange: (e) => {
5473
+ const updated = [...currentList];
5474
+ updated[idx] = e.target.value;
5475
+ setNewRecord((prev) => ({ ...prev, [f.id]: updated }));
5476
+ }
5477
+ }
5478
+ ),
5479
+ currentList.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5480
+ "button",
5481
+ {
5482
+ type: "button",
5483
+ onClick: () => {
5484
+ const updated = currentList.filter((_, i) => i !== idx);
5485
+ setNewRecord((prev) => ({
5486
+ ...prev,
5487
+ [f.id]: updated.length > 0 ? updated : [""]
5488
+ }));
5489
+ },
5490
+ className: "p-2 text-rose-500 hover:text-rose-700 hover:bg-rose-50 rounded-lg cursor-pointer shrink-0",
5491
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "size-4" })
5492
+ }
5493
+ )
5494
+ ] }, idx)),
5495
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
5496
+ import_antd.Button,
5497
+ {
5498
+ type: "dashed",
5499
+ size: "small",
5500
+ icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "size-3.5" }),
5501
+ onClick: () => setNewRecord((prev) => ({
5502
+ ...prev,
5503
+ [f.id]: [...currentList, ""]
5504
+ })),
5505
+ className: "w-full text-xs font-semibold",
5506
+ children: [
5507
+ "+ Agregar ",
5508
+ singularLabel.toLowerCase()
5509
+ ]
5510
+ }
5511
+ )
5512
+ ] })
5513
+ ] }, f.id);
5514
+ }
5515
+ if (f.type === "select") {
5516
+ const opts = f.optionsMap && f.dependsOnField ? f.optionsMap[String(newRecord[f.dependsOnField] || "")] || f.options || [] : f.options || [];
5517
+ const formattedOpts = opts.map((o) => typeof o === "string" ? { label: o, value: o } : o);
5518
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: colSpanClass, children: [
5519
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: f.label }),
5520
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5521
+ import_antd.Select,
5522
+ {
5523
+ size: "large",
5524
+ value: newRecord[f.id] || void 0,
5525
+ onChange: (val) => {
5526
+ setNewRecord((prev) => {
5527
+ const next = { ...prev, [f.id]: val };
5528
+ targetCol.fields.forEach((dep) => {
5529
+ if (dep.dependsOnField === f.id && dep.optionsMap) {
5530
+ const nextOpts = dep.optionsMap[val] || dep.options || [];
5531
+ const firstVal = typeof nextOpts[0] === "string" ? nextOpts[0] : nextOpts[0]?.value;
5532
+ next[dep.id] = firstVal || "";
5533
+ }
5534
+ });
5535
+ return next;
5536
+ });
5537
+ },
5538
+ options: formattedOpts,
5539
+ className: "w-full"
5540
+ }
5541
+ )
5542
+ ] }, f.id);
5543
+ }
5544
+ if (f.type === "textarea") {
5545
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: colSpanClass, children: [
5546
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: f.label }),
5547
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5548
+ import_antd.Input.TextArea,
5549
+ {
5550
+ rows: 3,
5551
+ value: newRecord[f.id] || "",
5552
+ onChange: (e) => setNewRecord((prev) => ({ ...prev, [f.id]: e.target.value }))
5553
+ }
5554
+ )
5555
+ ] }, f.id);
5556
+ }
5557
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: colSpanClass, children: [
5412
5558
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
5413
- t.clientIdentification,
5414
- " *"
5559
+ f.label,
5560
+ " ",
5561
+ f.unique ? "*" : ""
5415
5562
  ] }),
5416
5563
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5417
5564
  import_antd.Input,
5418
5565
  {
5419
5566
  size: "large",
5420
- status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
5421
- placeholder: t.clientIdentification,
5422
- value: newClient.id,
5567
+ value: newRecord[f.id] || "",
5568
+ placeholder: f.label,
5423
5569
  onChange: (e) => {
5424
- setNewClient((prev) => ({ ...prev, id: e.target.value }));
5425
- if (clientError) setClientError("");
5570
+ setNewRecord((prev) => ({ ...prev, [f.id]: e.target.value }));
5571
+ if (formError) setFormError("");
5426
5572
  },
5427
5573
  onBlur: (e) => {
5428
- const clean = (e.target.value || "").trim().toLowerCase();
5429
- if (clean) {
5430
- const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
5431
- if (dup) {
5432
- setClientError(`Ya existe un cliente con esta identificaci\xF3n (\xAB${dup.label || clean}\xBB).`);
5433
- message.warning(`\u26A0\uFE0F Ya existe un cliente con esta identificaci\xF3n: ${clean}.`);
5574
+ if (f.unique) {
5575
+ const clean = (e.target.value || "").trim().toLowerCase();
5576
+ if (clean) {
5577
+ const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
5578
+ if (dup) {
5579
+ setFormError(`Ya existe un registro con este ${f.label.toLowerCase()} (\xAB${dup.label || clean}\xBB).`);
5580
+ message.warning(`\u26A0\uFE0F Ya existe un registro con este ${f.label.toLowerCase()}: ${clean}.`);
5581
+ }
5434
5582
  }
5435
5583
  }
5436
5584
  }
5437
5585
  }
5438
5586
  )
5439
- ] }),
5440
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5441
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientBranch }),
5442
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5443
- import_antd.Input,
5444
- {
5445
- size: "large",
5446
- placeholder: t.clientBranch,
5447
- value: newClient.sucursal,
5448
- onChange: (e) => setNewClient((prev) => ({ ...prev, sucursal: e.target.value }))
5449
- }
5450
- )
5451
- ] })
5452
- ] }),
5453
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5454
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5455
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
5456
- t.clientName,
5457
- " *"
5458
- ] }),
5459
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5460
- import_antd.Input,
5461
- {
5462
- size: "large",
5463
- placeholder: t.clientName,
5464
- value: newClient.nombre,
5465
- onChange: (e) => setNewClient((prev) => ({ ...prev, nombre: e.target.value }))
5466
- }
5467
- )
5468
- ] }),
5469
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5470
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientEmail }),
5471
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5472
- import_antd.Input,
5473
- {
5474
- size: "large",
5475
- placeholder: t.clientEmail,
5476
- value: newClient.email,
5477
- onChange: (e) => setNewClient((prev) => ({ ...prev, email: e.target.value }))
5478
- }
5479
- )
5480
- ] })
5481
- ] }),
5482
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5483
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5484
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientPhone }),
5485
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5486
- import_antd.Input,
5487
- {
5488
- size: "large",
5489
- placeholder: t.clientPhone,
5490
- value: newClient.telefono,
5491
- onChange: (e) => setNewClient((prev) => ({ ...prev, telefono: e.target.value }))
5492
- }
5493
- )
5494
- ] }),
5495
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5496
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientCity }),
5497
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5498
- import_antd.Input,
5499
- {
5500
- size: "large",
5501
- placeholder: t.clientCity,
5502
- value: newClient.ciudad,
5503
- onChange: (e) => setNewClient((prev) => ({ ...prev, ciudad: e.target.value }))
5504
- }
5505
- )
5506
- ] })
5507
- ] }),
5508
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5509
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientAddress }),
5510
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5511
- import_antd.Input,
5512
- {
5513
- size: "large",
5514
- placeholder: t.clientAddress,
5515
- value: newClient.direccion,
5516
- onChange: (e) => setNewClient((prev) => ({ ...prev, direccion: e.target.value }))
5517
- }
5518
- )
5519
- ] }),
5520
- clientError && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs font-semibold text-red-600 bg-red-50 p-2.5 rounded-lg border border-red-200", children: clientError }),
5587
+ ] }, f.id);
5588
+ }) }),
5589
+ formError && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs font-semibold text-red-600 bg-red-50 p-2.5 rounded-lg border border-red-200", children: formError }),
5521
5590
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5522
5591
  import_antd.Button,
5523
5592
  {
5524
5593
  type: "primary",
5525
5594
  size: "large",
5526
- loading: creatingClient,
5527
- onClick: handleSaveClient,
5595
+ loading: saving,
5596
+ onClick: handleSaveRecord,
5528
5597
  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",
5529
- children: t.create.toUpperCase()
5598
+ children: (targetCol.submitLabel || t.create).toUpperCase()
5530
5599
  }
5531
5600
  )
5532
5601
  ] })