admin-lib-cms 1.2.16 → 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,18 +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;
2594
- } else if (f.type === "list") {
2620
+ } else if (f.type === "list" || f.multiple) {
2595
2621
  if (Array.isArray(finalEditing[f.id])) {
2596
2622
  finalEditing[f.id] = finalEditing[f.id].filter(
2597
2623
  (item) => item !== void 0 && item !== null && String(item).trim() !== ""
2598
2624
  );
2599
- } else if (typeof finalEditing[f.id] === "string") {
2600
- finalEditing[f.id] = String(finalEditing[f.id]).split("\n").map((s) => s.trim()).filter(Boolean);
2625
+ } else if (typeof finalEditing[f.id] === "string" && finalEditing[f.id]) {
2626
+ finalEditing[f.id] = [String(finalEditing[f.id]).trim()];
2601
2627
  }
2602
2628
  }
2603
2629
  });
2604
- const isClientOrEmployee = collection.id === "clients" || collection.id === "employees";
2605
- 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);
2606
2649
  for (const f of uniqueFields) {
2607
2650
  const val = String(finalEditing[f.id] || "").trim().toLowerCase();
2608
2651
  if (!val) {
@@ -2635,6 +2678,18 @@ function CollectionEditor({ collection }) {
2635
2678
  await ctx.adapter.putEntry(collection.id, finalEditing);
2636
2679
  message.success(originalId ? "Guardado correctamente" : "Creado correctamente");
2637
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
+ });
2638
2693
  setEditing(null);
2639
2694
  setOriginalId(null);
2640
2695
  setIsCreatingManual(false);
@@ -2648,6 +2703,9 @@ function CollectionEditor({ collection }) {
2648
2703
  setDeletingId(id);
2649
2704
  try {
2650
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
+ );
2651
2709
  ctx.notifyCollectionChanged();
2652
2710
  load();
2653
2711
  } finally {
@@ -2715,7 +2773,10 @@ function CollectionEditor({ collection }) {
2715
2773
  {
2716
2774
  size: "large",
2717
2775
  prefix: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Search, { className: "h-4 w-4 text-slate-400" }),
2718
- 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(", ")}...`,
2719
2780
  value: search,
2720
2781
  allowClear: true,
2721
2782
  onChange: (e) => {
@@ -2845,7 +2906,7 @@ function CollectionEditor({ collection }) {
2845
2906
  }
2846
2907
  return true;
2847
2908
  }).map((f) => {
2848
- 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";
2849
2910
  const colSpanClass = isFullWidth ? "lg:col-span-2 col-span-1" : "col-span-1";
2850
2911
  if (isViewingDetail) {
2851
2912
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${colSpanClass}`, children: [
@@ -2855,7 +2916,9 @@ function CollectionEditor({ collection }) {
2855
2916
  record: editing,
2856
2917
  onChange: () => {
2857
2918
  },
2858
- isCreatingEntry: false
2919
+ isCreatingEntry: false,
2920
+ isViewingDetail: true,
2921
+ readOnly: true
2859
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)(
2860
2923
  "img",
2861
2924
  {
@@ -2863,14 +2926,14 @@ function CollectionEditor({ collection }) {
2863
2926
  alt: f.label,
2864
2927
  className: "h-28 w-auto max-w-full object-contain"
2865
2928
  }
2866
- ) }) : /* @__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)(
2867
2930
  "span",
2868
2931
  {
2869
- 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",
2870
2933
  children: String(item)
2871
2934
  },
2872
2935
  idx
2873
- )) }) : /* @__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)(
2874
2937
  "a",
2875
2938
  {
2876
2939
  href: String(editing[f.id]),
@@ -2887,14 +2950,19 @@ function CollectionEditor({ collection }) {
2887
2950
  }
2888
2951
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${colSpanClass}`, children: [
2889
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: [
2890
- 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
+ ] }),
2891
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 })
2892
2958
  ] }),
2893
2959
  f.customRender ? f.customRender({
2894
2960
  value: editing[f.id],
2895
2961
  record: editing,
2896
2962
  onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2897
- isCreatingEntry
2963
+ isCreatingEntry,
2964
+ isViewingDetail: false,
2965
+ readOnly: false
2898
2966
  }) : f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2899
2967
  BranchSettingsEditor,
2900
2968
  {
@@ -3028,21 +3096,8 @@ function CollectionEditor({ collection }) {
3028
3096
  value: editing[f.id],
3029
3097
  onChange: (val) => setEditing({ ...editing, [f.id]: val }),
3030
3098
  onSelectRecord: (rec) => {
3031
- if (f.id === "clienteId" && rec) {
3032
- setEditing((prev) => prev ? {
3033
- ...prev,
3034
- clienteId: rec.id || prev.clienteId,
3035
- clienteNombre: rec.nombre || rec.name || prev.clienteNombre,
3036
- ciudad: rec.ciudad || prev.ciudad,
3037
- direccion: rec.direccion || prev.direccion,
3038
- telefono: rec.telefono || prev.telefono
3039
- } : prev);
3040
- } else if (f.id === "empleadoId" && rec) {
3041
- setEditing((prev) => prev ? {
3042
- ...prev,
3043
- empleadoId: rec.id || prev.empleadoId,
3044
- empleadoNombre: rec.apellido ? `${rec.nombre || rec.name || ""} ${rec.apellido}`.trim() : rec.nombre || rec.name || prev.empleadoNombre
3045
- } : prev);
3099
+ if (f.onSelectRecord) {
3100
+ setEditing((prev) => prev ? { ...prev, ...f.onSelectRecord(rec, prev) } : prev);
3046
3101
  }
3047
3102
  }
3048
3103
  }
@@ -3298,63 +3353,61 @@ function CollectionEditor({ collection }) {
3298
3353
  ]
3299
3354
  }
3300
3355
  )
3301
- ] }) : f.type === "list" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
3302
- (Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : []).map((item, idx) => {
3303
- const isFeatures = f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") || f.label.toLowerCase().includes("beneficio");
3304
- const placeholder = isFeatures ? `Caracter\xEDstica o beneficio ${idx + 1}...` : `Entregable o punto clave ${idx + 1}...`;
3305
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2 items-center", children: [
3306
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-mono font-bold text-slate-400 w-6 text-right shrink-0", children: [
3307
- idx + 1,
3308
- "."
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
3309
3365
  ] }),
3310
3366
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3311
3367
  "input",
3312
3368
  {
3313
3369
  type: "text",
3314
3370
  value: String(item ?? ""),
3315
- placeholder,
3371
+ placeholder: `${singularLabel} #${idx + 1}...`,
3316
3372
  onChange: (e) => {
3317
- 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];
3318
3374
  arr[idx] = e.target.value;
3319
3375
  setEditing({ ...editing, [f.id]: arr });
3320
3376
  },
3321
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"
3322
3378
  }
3323
3379
  ),
3324
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3380
+ displayArr.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3325
3381
  "button",
3326
3382
  {
3327
3383
  type: "button",
3328
3384
  onClick: () => {
3329
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
3330
- arr.splice(idx, 1);
3331
- setEditing({ ...editing, [f.id]: arr });
3385
+ const arr = displayArr.filter((_, i) => i !== idx);
3386
+ setEditing({ ...editing, [f.id]: arr.length > 0 ? arr : [""] });
3332
3387
  },
3333
- 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",
3334
3389
  title: "Eliminar elemento",
3335
3390
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
3336
3391
  }
3337
3392
  )
3338
- ] }, idx);
3339
- }),
3340
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3341
- "button",
3342
- {
3343
- type: "button",
3344
- onClick: () => {
3345
- let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
3346
- arr.push("");
3347
- setEditing({ ...editing, [f.id]: arr });
3348
- },
3349
- 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",
3350
- children: [
3351
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
3352
- " ",
3353
- f.id === "features" || f.label.toLowerCase().includes("caracter\xEDstica") ? "Agregar caracter\xEDstica uno a uno" : "Agregar entregable / punto uno a uno"
3354
- ]
3355
- }
3356
- )
3357
- ] }) : 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: [
3358
3411
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3359
3412
  import_antd.Input,
3360
3413
  {
@@ -3401,7 +3454,7 @@ function CollectionEditor({ collection }) {
3401
3454
  }
3402
3455
  },
3403
3456
  onBlur: (e) => {
3404
- const isUniqueField = f.unique || (collection.id === "clients" || collection.id === "employees") && f.id === "id";
3457
+ const isUniqueField = Boolean(f.unique);
3405
3458
  if (isUniqueField) {
3406
3459
  const val = (e.target.value || "").trim().toLowerCase();
3407
3460
  if (val) {
@@ -3536,7 +3589,30 @@ function CollectionEditor({ collection }) {
3536
3589
  onDragEnd,
3537
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" : ""}`,
3538
3591
  children: [
3539
- 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: [
3540
3616
  "$ ",
3541
3617
  Number(e[f.id]).toLocaleString("es-CO")
3542
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)(
@@ -3553,18 +3629,22 @@ function CollectionEditor({ collection }) {
3553
3629
  }
3554
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)),
3555
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: [
3556
- collection.enableDetailView && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3632
+ (collection.enableDetailView || collection.onViewRecord) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3557
3633
  "button",
3558
3634
  {
3559
3635
  onClick: () => {
3636
+ if (collection.onViewRecord) {
3637
+ collection.onViewRecord(e);
3638
+ return;
3639
+ }
3560
3640
  setIsCreatingManual(false);
3561
3641
  setIsViewingDetail(true);
3562
3642
  setOriginalId(String(e.id || ""));
3563
3643
  setDuplicateErrors({});
3564
3644
  setEditing({ ...e });
3565
3645
  },
3566
- className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
3567
- 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",
3568
3648
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Eye, { className: "h-4 w-4" })
3569
3649
  }
3570
3650
  ),
@@ -5158,9 +5238,9 @@ function ReferenceSelect({
5158
5238
  displayField = "name",
5159
5239
  valueField = "name",
5160
5240
  fallbackOptions,
5161
- multiple = false,
5241
+ multiple: _multiple = false,
5162
5242
  searchable = false,
5163
- max,
5243
+ max: _max,
5164
5244
  value,
5165
5245
  onChange,
5166
5246
  onSelectRecord
@@ -5170,45 +5250,46 @@ function ReferenceSelect({
5170
5250
  const { message } = import_antd.App.useApp();
5171
5251
  const [options, setOptions] = (0, import_react5.useState)([]);
5172
5252
  const [loading, setLoading] = (0, import_react5.useState)(true);
5173
- const [clientModalOpen, setClientModalOpen] = (0, import_react5.useState)(false);
5174
- const [creatingClient, setCreatingClient] = (0, import_react5.useState)(false);
5175
- const [clientError, setClientError] = (0, import_react5.useState)("");
5176
- const [newClient, setNewClient] = (0, import_react5.useState)({
5177
- tipo: "Persona",
5178
- tipoDocumento: "C\xE9dula de ciudadan\xEDa",
5179
- id: "",
5180
- sucursal: "",
5181
- nombre: "",
5182
- email: "",
5183
- telefono: "",
5184
- ciudad: "",
5185
- direccion: ""
5186
- });
5187
- const handleSaveClient = async () => {
5188
- setClientError("");
5189
- if (!newClient.id.trim()) {
5190
- setClientError(t.idRequired);
5191
- return;
5192
- }
5193
- if (!newClient.nombre.trim()) {
5194
- setClientError(t.nameRequired);
5195
- return;
5196
- }
5197
- const cleanId = newClient.id.trim().toLowerCase();
5198
- const isDuplicate = options.some((opt) => String(opt.value || "").trim().toLowerCase() === cleanId);
5199
- if (isDuplicate) {
5200
- setClientError("Ya existe un cliente con este NIT o C\xE9dula. No se pueden repetir.");
5201
- 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
+ }
5202
5273
  }
5203
- setCreatingClient(true);
5274
+ setSaving(true);
5204
5275
  try {
5205
- const entry = {
5206
- ...newClient,
5207
- id: newClient.id.trim(),
5208
- nombre: newClient.nombre.trim()
5276
+ const entryToSave = {
5277
+ id: String(newRecord.id || Date.now()).trim(),
5278
+ ...newRecord
5209
5279
  };
5210
- await ctx.adapter.putEntry("clients", entry);
5211
- 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);
5212
5293
  const fromCollection = (res || []).map((r) => {
5213
5294
  const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
5214
5295
  const fullName = r.apellido ? `${r.nombre || r.name || ""} ${r.apellido}`.trim() : "";
@@ -5220,27 +5301,18 @@ function ReferenceSelect({
5220
5301
  };
5221
5302
  });
5222
5303
  setOptions(fromCollection);
5223
- onChange(entry.id);
5304
+ const selectedVal = valueField && entryToSave[valueField] !== void 0 ? String(entryToSave[valueField]) : entryToSave.id;
5305
+ onChange(selectedVal);
5224
5306
  if (onSelectRecord) {
5225
- onSelectRecord(entry);
5307
+ onSelectRecord(entryToSave);
5226
5308
  }
5227
- setClientModalOpen(false);
5228
- setNewClient({
5229
- tipo: "Persona",
5230
- tipoDocumento: "C\xE9dula de ciudadan\xEDa",
5231
- id: "",
5232
- sucursal: "",
5233
- nombre: "",
5234
- email: "",
5235
- telefono: "",
5236
- ciudad: "",
5237
- direccion: ""
5238
- });
5239
- message.success(t.clientCreatedSuccess);
5309
+ setModalOpen(false);
5310
+ setNewRecord({});
5311
+ message.success(t.recordCreatedSuccess || "Registro creado y seleccionado exitosamente.");
5240
5312
  } catch (err) {
5241
- setClientError(err?.message || "Error al crear cliente.");
5313
+ setFormError(err?.message || "Error al crear registro.");
5242
5314
  } finally {
5243
- setCreatingClient(false);
5315
+ setSaving(false);
5244
5316
  }
5245
5317
  };
5246
5318
  (0, import_react5.useEffect)(() => {
@@ -5265,41 +5337,24 @@ function ReferenceSelect({
5265
5337
  });
5266
5338
  setOptions(fromCollection);
5267
5339
  setLoading(false);
5268
- }).catch(() => {
5269
- 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
+ }
5270
5345
  setLoading(false);
5271
5346
  });
5272
- }, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter, ctx.collectionChangedAt]);
5273
- if (multiple) {
5274
- const selectedList = Array.isArray(value) ? value.map(String) : typeof value === "string" && value.trim() ? value.split(",").map((s) => s.trim()).filter(Boolean) : [];
5275
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5276
- import_antd.Select,
5277
- {
5278
- size: "large",
5279
- mode: "multiple",
5280
- loading,
5281
- showSearch: searchable,
5282
- placeholder: "Seleccionar opciones...",
5283
- filterOption: (input, option) => {
5284
- if (!input) return true;
5285
- const q = input.toLowerCase();
5286
- const label = String(option?.label ?? "").toLowerCase();
5287
- const val = String(option?.value ?? "").toLowerCase();
5288
- return label.includes(q) || val.includes(q);
5289
- },
5290
- maxCount: max,
5291
- value: selectedList,
5292
- onChange,
5293
- options,
5294
- className: "w-full"
5295
- }
5296
- );
5297
- }
5298
- const singleVal = value !== void 0 && value !== null && value !== "" ? String(value) : void 0;
5299
- const displayOptions = [...options];
5300
- if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
5301
- displayOptions.unshift({ value: singleVal, label: singleVal });
5302
- }
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);
5303
5358
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
5304
5359
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
5305
5360
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex-1", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -5328,8 +5383,8 @@ function ReferenceSelect({
5328
5383
  options: displayOptions,
5329
5384
  dropdownRender: (menu) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5330
5385
  menu,
5331
- 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: [
5332
- /* @__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?" }),
5333
5388
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5334
5389
  import_antd.Button,
5335
5390
  {
@@ -5337,11 +5392,18 @@ function ReferenceSelect({
5337
5392
  size: "small",
5338
5393
  icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
5339
5394
  onClick: () => {
5340
- setClientError("");
5341
- 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);
5342
5404
  },
5343
5405
  className: "bg-blue-600 hover:bg-blue-700 text-xs font-semibold rounded-lg shadow-sm",
5344
- children: t.createClient
5406
+ children: t.createNewOption || `Crear ${targetCol.name}`
5345
5407
  }
5346
5408
  )
5347
5409
  ] })
@@ -5349,192 +5411,191 @@ function ReferenceSelect({
5349
5411
  className: "w-full"
5350
5412
  }
5351
5413
  ) }),
5352
- collectionId === "clients" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5414
+ canQuickCreate && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5353
5415
  import_antd.Button,
5354
5416
  {
5355
5417
  type: "primary",
5356
5418
  size: "large",
5357
5419
  icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-4 h-4" }),
5358
5420
  onClick: () => {
5359
- setClientError("");
5360
- 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);
5361
5430
  },
5362
5431
  className: "bg-blue-600 hover:bg-blue-700 font-bold rounded-xl shrink-0 h-10 px-4 text-xs uppercase tracking-wider",
5363
- children: t.newBtn
5432
+ children: targetCol.submitLabel || t.newBtn
5364
5433
  }
5365
5434
  )
5366
5435
  ] }),
5367
- collectionId === "clients" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5436
+ canQuickCreate && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5368
5437
  import_antd.Modal,
5369
5438
  {
5370
- open: clientModalOpen,
5371
- title: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xl font-bold text-slate-900 font-display", children: t.basicDetails }),
5372
- 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),
5373
5442
  centered: true,
5374
5443
  width: 650,
5375
5444
  footer: null,
5376
5445
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "pt-2 space-y-4", children: [
5377
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5378
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5379
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientType }),
5380
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5381
- import_antd.Select,
5382
- {
5383
- size: "large",
5384
- value: newClient.tipo,
5385
- onChange: (val) => {
5386
- setNewClient((prev) => ({
5387
- ...prev,
5388
- tipo: val,
5389
- tipoDocumento: val === "Empresa" ? "Nit" : "C\xE9dula de ciudadan\xEDa"
5390
- }));
5391
- },
5392
- options: [
5393
- { label: "Persona", value: "Persona" },
5394
- { label: "Empresa", value: "Empresa" }
5395
- ],
5396
- className: "w-full"
5397
- }
5398
- )
5399
- ] }),
5400
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5401
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientDocType }),
5402
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5403
- import_antd.Select,
5404
- {
5405
- size: "large",
5406
- value: newClient.tipoDocumento,
5407
- onChange: (val) => setNewClient((prev) => ({ ...prev, tipoDocumento: val })),
5408
- options: newClient.tipo === "Persona" ? [
5409
- { label: "C\xE9dula de ciudadan\xEDa", value: "C\xE9dula de ciudadan\xEDa" },
5410
- { label: "C\xE9dula de extranjer\xEDa", value: "C\xE9dula de extranjer\xEDa" },
5411
- { label: "Pasaporte", value: "Pasaporte" }
5412
- ] : [{ label: "Nit", value: "Nit" }],
5413
- className: "w-full"
5414
- }
5415
- )
5416
- ] })
5417
- ] }),
5418
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5419
- /* @__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: [
5420
5558
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
5421
- t.clientIdentification,
5422
- " *"
5559
+ f.label,
5560
+ " ",
5561
+ f.unique ? "*" : ""
5423
5562
  ] }),
5424
5563
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5425
5564
  import_antd.Input,
5426
5565
  {
5427
5566
  size: "large",
5428
- status: clientError && clientError.includes("identificaci\xF3n") ? "error" : void 0,
5429
- placeholder: t.clientIdentification,
5430
- value: newClient.id,
5567
+ value: newRecord[f.id] || "",
5568
+ placeholder: f.label,
5431
5569
  onChange: (e) => {
5432
- setNewClient((prev) => ({ ...prev, id: e.target.value }));
5433
- if (clientError) setClientError("");
5570
+ setNewRecord((prev) => ({ ...prev, [f.id]: e.target.value }));
5571
+ if (formError) setFormError("");
5434
5572
  },
5435
5573
  onBlur: (e) => {
5436
- const clean = (e.target.value || "").trim().toLowerCase();
5437
- if (clean) {
5438
- const dup = options.find((opt) => String(opt.value || "").trim().toLowerCase() === clean);
5439
- if (dup) {
5440
- setClientError(`Ya existe un cliente con esta identificaci\xF3n (\xAB${dup.label || clean}\xBB).`);
5441
- 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
+ }
5442
5582
  }
5443
5583
  }
5444
5584
  }
5445
5585
  }
5446
5586
  )
5447
- ] }),
5448
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5449
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientBranch }),
5450
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5451
- import_antd.Input,
5452
- {
5453
- size: "large",
5454
- placeholder: t.clientBranch,
5455
- value: newClient.sucursal,
5456
- onChange: (e) => setNewClient((prev) => ({ ...prev, sucursal: e.target.value }))
5457
- }
5458
- )
5459
- ] })
5460
- ] }),
5461
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5462
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5463
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: [
5464
- t.clientName,
5465
- " *"
5466
- ] }),
5467
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5468
- import_antd.Input,
5469
- {
5470
- size: "large",
5471
- placeholder: t.clientName,
5472
- value: newClient.nombre,
5473
- onChange: (e) => setNewClient((prev) => ({ ...prev, nombre: e.target.value }))
5474
- }
5475
- )
5476
- ] }),
5477
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5478
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientEmail }),
5479
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5480
- import_antd.Input,
5481
- {
5482
- size: "large",
5483
- placeholder: t.clientEmail,
5484
- value: newClient.email,
5485
- onChange: (e) => setNewClient((prev) => ({ ...prev, email: e.target.value }))
5486
- }
5487
- )
5488
- ] })
5489
- ] }),
5490
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3", children: [
5491
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5492
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientPhone }),
5493
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5494
- import_antd.Input,
5495
- {
5496
- size: "large",
5497
- placeholder: t.clientPhone,
5498
- value: newClient.telefono,
5499
- onChange: (e) => setNewClient((prev) => ({ ...prev, telefono: e.target.value }))
5500
- }
5501
- )
5502
- ] }),
5503
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5504
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientCity }),
5505
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5506
- import_antd.Input,
5507
- {
5508
- size: "large",
5509
- placeholder: t.clientCity,
5510
- value: newClient.ciudad,
5511
- onChange: (e) => setNewClient((prev) => ({ ...prev, ciudad: e.target.value }))
5512
- }
5513
- )
5514
- ] })
5515
- ] }),
5516
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
5517
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-xs font-bold text-slate-700 mb-1", children: t.clientAddress }),
5518
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5519
- import_antd.Input,
5520
- {
5521
- size: "large",
5522
- placeholder: t.clientAddress,
5523
- value: newClient.direccion,
5524
- onChange: (e) => setNewClient((prev) => ({ ...prev, direccion: e.target.value }))
5525
- }
5526
- )
5527
- ] }),
5528
- 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 }),
5529
5590
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5530
5591
  import_antd.Button,
5531
5592
  {
5532
5593
  type: "primary",
5533
5594
  size: "large",
5534
- loading: creatingClient,
5535
- onClick: handleSaveClient,
5595
+ loading: saving,
5596
+ onClick: handleSaveRecord,
5536
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",
5537
- children: t.create.toUpperCase()
5598
+ children: (targetCol.submitLabel || t.create).toUpperCase()
5538
5599
  }
5539
5600
  )
5540
5601
  ] })