admin-lib-cms 1.2.17 → 1.2.18

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
@@ -829,9 +829,224 @@ function EditableReference({
829
829
  var import_react5 = __toESM(require("react"));
830
830
  var import_react_dom = require("react-dom");
831
831
  var import_antd = require("antd");
832
- var import_dayjs = __toESM(require("dayjs"));
832
+ var import_dayjs2 = __toESM(require("dayjs"));
833
833
  var import_lucide_react2 = require("lucide-react");
834
834
 
835
+ // src/admin/excel.ts
836
+ var XLSX = __toESM(require("xlsx"));
837
+ var import_dayjs = __toESM(require("dayjs"));
838
+ function filterEntriesByDateRange(entries, fieldId, startDate, endDate) {
839
+ if (!startDate && !endDate) return entries;
840
+ const startDayjs = startDate ? (0, import_dayjs.default)(startDate).startOf("day") : null;
841
+ const endDayjs = endDate ? (0, import_dayjs.default)(endDate).endOf("day") : null;
842
+ return entries.filter((e) => {
843
+ const val = e[fieldId];
844
+ if (!val) return false;
845
+ const d = (0, import_dayjs.default)(String(val));
846
+ if (!d.isValid()) return false;
847
+ if (startDayjs && d.isBefore(startDayjs)) return false;
848
+ if (endDayjs && d.isAfter(endDayjs)) return false;
849
+ return true;
850
+ });
851
+ }
852
+ function findExistingEntry(item, existingEntries, collection) {
853
+ if (item.id && !item.id.startsWith("item_")) {
854
+ const cleanId = String(item.id).trim().toLowerCase();
855
+ const matchById = existingEntries.find(
856
+ (e) => e.id && String(e.id).trim().toLowerCase() === cleanId || e._id && String(e._id).trim().toLowerCase() === cleanId
857
+ );
858
+ if (matchById) return matchById;
859
+ }
860
+ const uniqueFieldIds = [];
861
+ (collection.fields || []).forEach((f) => {
862
+ if (f.unique && !uniqueFieldIds.includes(f.id)) {
863
+ uniqueFieldIds.push(f.id);
864
+ }
865
+ });
866
+ (collection.uniqueFields || []).forEach((uf) => {
867
+ if (!uniqueFieldIds.includes(uf)) {
868
+ uniqueFieldIds.push(uf);
869
+ }
870
+ });
871
+ for (const ufId of uniqueFieldIds) {
872
+ const itemVal = item[ufId];
873
+ if (itemVal !== void 0 && itemVal !== null && String(itemVal).trim() !== "") {
874
+ const cleanVal = String(itemVal).trim().toLowerCase();
875
+ const match = existingEntries.find((e) => {
876
+ const eVal = e[ufId];
877
+ return eVal !== void 0 && eVal !== null && String(eVal).trim().toLowerCase() === cleanVal;
878
+ });
879
+ if (match) return match;
880
+ }
881
+ }
882
+ return null;
883
+ }
884
+ function formatValueForExport(val, field) {
885
+ if (val === void 0 || val === null) return "";
886
+ if (typeof val === "number" || typeof val === "boolean") return val;
887
+ if (Array.isArray(val)) {
888
+ return val.map((item) => typeof item === "object" && item !== null ? JSON.stringify(item) : String(item)).join(", ");
889
+ }
890
+ if (typeof val === "object") {
891
+ try {
892
+ return JSON.stringify(val);
893
+ } catch {
894
+ return String(val);
895
+ }
896
+ }
897
+ return String(val);
898
+ }
899
+ function exportCollectionToExcel(collection, entries, fileNamePrefix) {
900
+ const columns = [
901
+ { key: "id", label: "ID" }
902
+ ];
903
+ (collection.fields || []).forEach((f) => {
904
+ columns.push({
905
+ key: f.id,
906
+ label: f.label || f.id,
907
+ field: f
908
+ });
909
+ });
910
+ const rows = entries.map((entry) => {
911
+ const rowObj = {};
912
+ columns.forEach((col) => {
913
+ const rawVal = entry[col.key];
914
+ rowObj[col.label] = formatValueForExport(rawVal, col.field);
915
+ });
916
+ return rowObj;
917
+ });
918
+ const worksheet = XLSX.utils.json_to_sheet(rows);
919
+ const colWidths = columns.map((col) => {
920
+ let maxLen = col.label.length;
921
+ for (let i = 0; i < Math.min(rows.length, 100); i++) {
922
+ const cellVal = String(rows[i]?.[col.label] ?? "");
923
+ if (cellVal.length > maxLen) {
924
+ maxLen = Math.min(cellVal.length, 45);
925
+ }
926
+ }
927
+ return { wch: Math.max(maxLen + 3, 12) };
928
+ });
929
+ worksheet["!cols"] = colWidths;
930
+ const workbook = XLSX.utils.book_new();
931
+ const safeSheetName = (collection.name || collection.id).replace(/[\\/?*[\]:]/g, "").slice(0, 31) || "Datos";
932
+ XLSX.utils.book_append_sheet(workbook, worksheet, safeSheetName);
933
+ const dateStr = (0, import_dayjs.default)().format("YYYY-MM-DD");
934
+ const baseName = fileNamePrefix || (collection.name || collection.id).toLowerCase().replace(/[^a-z0-9_-]+/g, "_");
935
+ const fileName = `${baseName}_${dateStr}.xlsx`;
936
+ XLSX.writeFile(workbook, fileName);
937
+ }
938
+ async function parseExcelForCollection(file, collection, existingEntries = []) {
939
+ const data = await file.arrayBuffer();
940
+ const workbook = XLSX.read(data, { type: "array" });
941
+ const firstSheetName = workbook.SheetNames[0];
942
+ if (!firstSheetName) {
943
+ throw new Error("El archivo no contiene ninguna hoja de c\xE1lculo.");
944
+ }
945
+ const worksheet = workbook.Sheets[firstSheetName];
946
+ const rawRows = XLSX.utils.sheet_to_json(worksheet, { defval: "" });
947
+ if (!rawRows.length) {
948
+ return {
949
+ records: [],
950
+ totalRows: 0,
951
+ matchedFields: [],
952
+ unmatchedHeaders: [],
953
+ samplePreview: [],
954
+ errors: ["El archivo no contiene filas con datos."]
955
+ };
956
+ }
957
+ const headers = Object.keys(rawRows[0] || {});
958
+ const matchedFields = [];
959
+ const unmatchedHeaders = [];
960
+ const headerToFieldMap = /* @__PURE__ */ new Map();
961
+ headers.forEach((header) => {
962
+ const cleanHeader = header.trim().toLowerCase();
963
+ if (cleanHeader === "id" || cleanHeader === "_id" || cleanHeader === "identificador") {
964
+ headerToFieldMap.set(header, "id");
965
+ matchedFields.push({ label: header, fieldId: "id" });
966
+ return;
967
+ }
968
+ const matched = (collection.fields || []).find((f) => {
969
+ const fieldLabel = (f.label || "").trim().toLowerCase();
970
+ const fieldId = f.id.trim().toLowerCase();
971
+ return fieldLabel === cleanHeader || fieldId === cleanHeader;
972
+ });
973
+ if (matched) {
974
+ headerToFieldMap.set(header, matched);
975
+ matchedFields.push({ label: header, fieldId: matched.id });
976
+ } else {
977
+ unmatchedHeaders.push(header);
978
+ }
979
+ });
980
+ const records = [];
981
+ const errors = [];
982
+ rawRows.forEach((row, idx) => {
983
+ const entry = { id: "" };
984
+ (collection.fields || []).forEach((f) => {
985
+ if (f.defaultValue !== void 0) {
986
+ entry[f.id] = f.defaultValue;
987
+ }
988
+ });
989
+ headers.forEach((header) => {
990
+ const mapping = headerToFieldMap.get(header);
991
+ const rawVal = row[header];
992
+ if (rawVal === void 0 || rawVal === "") return;
993
+ if (mapping === "id") {
994
+ entry.id = String(rawVal).trim();
995
+ return;
996
+ }
997
+ if (!mapping) return;
998
+ const field = mapping;
999
+ if (field.type === "number") {
1000
+ const num = Number(String(rawVal).replace(/[^0-9.-]/g, ""));
1001
+ entry[field.id] = isNaN(num) ? rawVal : num;
1002
+ } else if (field.type === "boolean") {
1003
+ const str = String(rawVal).trim().toLowerCase();
1004
+ entry[field.id] = str === "true" || str === "si" || str === "s\xED" || str === "yes" || str === "1" || str === "verdadero";
1005
+ } else if (field.multiple || field.type === "list") {
1006
+ if (typeof rawVal === "string") {
1007
+ entry[field.id] = rawVal.split(/[,;\n]/).map((s) => s.trim()).filter(Boolean);
1008
+ } else if (Array.isArray(rawVal)) {
1009
+ entry[field.id] = rawVal;
1010
+ } else {
1011
+ entry[field.id] = [String(rawVal)];
1012
+ }
1013
+ } else if (typeof rawVal === "string" && (rawVal.startsWith("{") || rawVal.startsWith("["))) {
1014
+ try {
1015
+ entry[field.id] = JSON.parse(rawVal);
1016
+ } catch {
1017
+ entry[field.id] = rawVal;
1018
+ }
1019
+ } else {
1020
+ entry[field.id] = rawVal;
1021
+ }
1022
+ });
1023
+ if (!entry.id) {
1024
+ entry.id = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `item_${Date.now()}_${idx}`;
1025
+ }
1026
+ records.push(entry);
1027
+ });
1028
+ let existingCount = 0;
1029
+ let newCount = 0;
1030
+ records.forEach((rec) => {
1031
+ const existing = findExistingEntry(rec, existingEntries, collection);
1032
+ if (existing) {
1033
+ existingCount++;
1034
+ } else {
1035
+ newCount++;
1036
+ }
1037
+ });
1038
+ return {
1039
+ records,
1040
+ totalRows: records.length,
1041
+ matchedFields,
1042
+ unmatchedHeaders,
1043
+ samplePreview: records.slice(0, 5),
1044
+ existingRecordsCount: existingCount,
1045
+ newRecordsCount: newCount,
1046
+ errors
1047
+ };
1048
+ }
1049
+
835
1050
  // src/admin/i18n.ts
836
1051
  var translations = {
837
1052
  es: {
@@ -916,6 +1131,29 @@ var translations = {
916
1131
  submissions: "Mensajes y Formularios",
917
1132
  noSubmissions: "No hay env\xEDos registrados",
918
1133
  exportCsv: "Exportar CSV",
1134
+ exportExcel: "Exportar Excel",
1135
+ importExcel: "Importar Excel",
1136
+ exportSuccess: "Archivo Excel exportado con \xE9xito.",
1137
+ importSuccess: "registros procesados exitosamente.",
1138
+ exportModalTitle: "Exportar a Excel",
1139
+ exportAllRecords: "Todos los registros",
1140
+ exportFilterByDate: "Filtrar por rango de fechas",
1141
+ exportDateFieldLabel: "Campo de fecha",
1142
+ exportDateRangeLabel: "Rango de fechas",
1143
+ exportDownloadBtn: "Descargar Excel",
1144
+ exportNoRecordsInRange: "No se encontraron registros en el rango seleccionado.",
1145
+ importModalTitle: "Importar datos desde Excel / CSV",
1146
+ importModalDesc: "Carga un archivo .xlsx, .xls o .csv para agregar o actualizar registros autom\xE1ticamente.",
1147
+ importDropzone: "Haz clic o arrastra un archivo Excel aqu\xED",
1148
+ importDropzoneSub: "Formatos compatibles: .xlsx, .xls, .csv. La primera fila debe contener los encabezados.",
1149
+ importPreviewTitle: "Vista previa de importaci\xF3n",
1150
+ importConfirmBtn: "Importar registros",
1151
+ importOverwritesWarning: "Tratamiento de registros ya existentes:",
1152
+ importingProgress: "Importando registros...",
1153
+ importExistingOmit: "Omitir existentes (no volver a crear ni duplicar)",
1154
+ importExistingUpdate: "Actualizar existentes con datos del archivo",
1155
+ importExistingDetected: "ya existentes",
1156
+ importNewDetected: "nuevos a crear",
919
1157
  markRead: "Marcar como le\xEDdo",
920
1158
  settingsTitle: "Ajustes del sitio",
921
1159
  entries: "registros"
@@ -1002,6 +1240,29 @@ var translations = {
1002
1240
  submissions: "Form Submissions",
1003
1241
  noSubmissions: "No submissions yet",
1004
1242
  exportCsv: "Export CSV",
1243
+ exportExcel: "Export Excel",
1244
+ importExcel: "Import Excel",
1245
+ exportSuccess: "Excel file exported successfully.",
1246
+ importSuccess: "records processed successfully.",
1247
+ exportModalTitle: "Export to Excel",
1248
+ exportAllRecords: "All records",
1249
+ exportFilterByDate: "Filter by date range",
1250
+ exportDateFieldLabel: "Date field",
1251
+ exportDateRangeLabel: "Date range",
1252
+ exportDownloadBtn: "Download Excel",
1253
+ exportNoRecordsInRange: "No records found in the selected date range.",
1254
+ importModalTitle: "Import data from Excel / CSV",
1255
+ importModalDesc: "Upload a .xlsx, .xls or .csv file to automatically create or update records.",
1256
+ importDropzone: "Click or drag an Excel file here",
1257
+ importDropzoneSub: "Supported formats: .xlsx, .xls, .csv. The first row must contain column headers.",
1258
+ importPreviewTitle: "Import Preview",
1259
+ importConfirmBtn: "Import records",
1260
+ importOverwritesWarning: "Handling of existing records:",
1261
+ importingProgress: "Importing records...",
1262
+ importExistingOmit: "Skip existing (do not recreate or duplicate)",
1263
+ importExistingUpdate: "Update existing with file data",
1264
+ importExistingDetected: "existing records",
1265
+ importNewDetected: "new to create",
1005
1266
  markRead: "Mark as read",
1006
1267
  settingsTitle: "Site Settings",
1007
1268
  entries: "entries"
@@ -1072,13 +1333,13 @@ function toDayjsTime(value) {
1072
1333
  const isPm = match12[3].toLowerCase().startsWith("p");
1073
1334
  if (isPm && h < 12) h += 12;
1074
1335
  if (!isPm && h === 12) h = 0;
1075
- return (0, import_dayjs.default)().hour(h).minute(m).second(0).millisecond(0);
1336
+ return (0, import_dayjs2.default)().hour(h).minute(m).second(0).millisecond(0);
1076
1337
  }
1077
1338
  const match24 = /^([01]?\d|2[0-3]):([0-5]\d)$/.exec(str);
1078
1339
  if (match24) {
1079
- return (0, import_dayjs.default)().hour(Number(match24[1])).minute(Number(match24[2])).second(0).millisecond(0);
1340
+ return (0, import_dayjs2.default)().hour(Number(match24[1])).minute(Number(match24[2])).second(0).millisecond(0);
1080
1341
  }
1081
- const parsed = (0, import_dayjs.default)(str, ["h:mm a", "h:mm A", "hh:mm a", "hh:mm A", "HH:mm"]);
1342
+ const parsed = (0, import_dayjs2.default)(str, ["h:mm a", "h:mm A", "hh:mm a", "hh:mm A", "HH:mm"]);
1082
1343
  return parsed.isValid() ? parsed : null;
1083
1344
  }
1084
1345
  function toStoredTime(value) {
@@ -2458,37 +2719,37 @@ function CollectionsSection() {
2458
2719
  });
2459
2720
  }, [ctx.adapter, colIds, ctx.collectionChangedAt]);
2460
2721
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-col md:flex-row h-full bg-slate-50", children: [
2461
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-4", children: [
2462
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
2463
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("ul", { className: "flex overflow-x-auto gap-2 pb-2 md:block md:space-x-0 md:space-y-1 md:pb-0 md:overflow-visible", children: [
2722
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-2 sm:p-3 md:p-4", children: [
2723
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "hidden md:block mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
2724
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("ul", { className: "flex items-center md:items-stretch overflow-x-auto gap-1.5 p-1 md:p-0 md:block md:space-x-0 md:space-y-1 md:overflow-visible", children: [
2464
2725
  collections.map((c, idx) => {
2465
2726
  if (c.isSeparator) {
2466
2727
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2467
2728
  "li",
2468
2729
  {
2469
- className: "my-3 border-t border-slate-200/80 pt-2 px-1 list-none",
2470
- children: c.name && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[10px] font-bold uppercase tracking-wider text-slate-400", children: c.name })
2730
+ className: "self-center shrink-0 h-6 w-px bg-slate-200 mx-1 md:h-auto md:w-auto md:mx-0 md:my-3 md:border-t md:border-slate-200/80 md:pt-2 md:px-1 list-none",
2731
+ children: c.name && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hidden md:block text-[10px] font-bold uppercase tracking-wider text-slate-400", children: c.name })
2471
2732
  },
2472
2733
  c.id || `sep-${idx}`
2473
2734
  );
2474
2735
  }
2475
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "shrink-0 min-w-[140px] md:w-full md:min-w-0", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2736
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "shrink-0 md:w-full md:min-w-0", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2476
2737
  "button",
2477
2738
  {
2478
2739
  onClick: () => setSelected(c),
2479
- className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selected?.id === c.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
2740
+ className: `rounded-xl px-3.5 py-2 md:w-full md:px-3 md:py-2.5 text-left text-xs md:text-sm transition-all duration-200 ${selected?.id === c.id ? "bg-white border border-slate-200/90 shadow-2xs font-semibold" : "text-slate-600 hover:text-slate-900 hover:bg-slate-100/70 border border-transparent"}`,
2480
2741
  children: [
2481
2742
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2482
2743
  "div",
2483
2744
  {
2484
- className: selected?.id === c.id ? "text-slate-900" : "text-slate-700",
2745
+ className: selected?.id === c.id ? "text-slate-900 font-bold" : "text-slate-700 font-medium",
2485
2746
  children: c.name
2486
2747
  }
2487
2748
  ),
2488
2749
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2489
2750
  "div",
2490
2751
  {
2491
- className: `text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-500" : "text-slate-400"}`,
2752
+ className: `text-[10px] md:text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-600 font-medium" : "text-slate-400"}`,
2492
2753
  children: [
2493
2754
  counts[c.id] ?? 0,
2494
2755
  " items"
@@ -2502,7 +2763,7 @@ function CollectionsSection() {
2502
2763
  collections.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200", children: "No collections registered." })
2503
2764
  ] })
2504
2765
  ] }),
2505
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex-1 overflow-auto p-4 md:p-8 relative", children: [
2766
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex-1 overflow-auto p-2 sm:p-4 md:p-8 relative", children: [
2506
2767
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "absolute inset-0 bg-grid-slate-100 [mask-image:linear-gradient(0deg,white,rgba(255,255,255,0.6))] -z-10 pointer-events-none" }),
2507
2768
  selected ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CollectionEditor, { collection: selected }, selected.id) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "grid h-full place-items-center text-sm text-slate-500", children: "Select a collection to manage its entries." })
2508
2769
  ] })
@@ -2518,6 +2779,16 @@ function CollectionEditor({ collection }) {
2518
2779
  const [duplicateErrors, setDuplicateErrors] = (0, import_react5.useState)({});
2519
2780
  const [isCreatingManual, setIsCreatingManual] = (0, import_react5.useState)(false);
2520
2781
  const [isViewingDetail, setIsViewingDetail] = (0, import_react5.useState)(false);
2782
+ const [customViewingRecord, setCustomViewingRecord] = (0, import_react5.useState)(null);
2783
+ const [isCustomEditing, setIsCustomEditing] = (0, import_react5.useState)(false);
2784
+ const [customActiveView, setCustomActiveView] = (0, import_react5.useState)(null);
2785
+ const [isCustomCreating, setIsCustomCreating] = (0, import_react5.useState)(false);
2786
+ (0, import_react5.useEffect)(() => {
2787
+ setCustomViewingRecord(null);
2788
+ setIsCustomEditing(false);
2789
+ setCustomActiveView(null);
2790
+ setIsCustomCreating(false);
2791
+ }, [collection.id]);
2521
2792
  const [saving, setSaving] = (0, import_react5.useState)(false);
2522
2793
  const [deletingId, setDeletingId] = (0, import_react5.useState)(null);
2523
2794
  const [loadingEntries, setLoadingEntries] = (0, import_react5.useState)(true);
@@ -2527,6 +2798,47 @@ function CollectionEditor({ collection }) {
2527
2798
  const [filters, setFilters] = (0, import_react5.useState)({});
2528
2799
  const [page, setPage] = (0, import_react5.useState)(1);
2529
2800
  const itemsPerPage = 10;
2801
+ const dateFields = (0, import_react5.useMemo)(() => {
2802
+ const list = [];
2803
+ (collection.fields || []).forEach((f) => {
2804
+ if (f.type === "date" || f.type === "datetime" || f.id === "fecha" || f.id.toLowerCase().includes("fecha") || f.id.toLowerCase().includes("date")) {
2805
+ list.push({ id: f.id, label: f.label || f.id });
2806
+ }
2807
+ });
2808
+ const hasCreatedAt = entries.some((e) => e._createdAt);
2809
+ if (hasCreatedAt && !list.some((f) => f.id === "_createdAt")) {
2810
+ list.push({ id: "_createdAt", label: "Fecha de creaci\xF3n (_createdAt)" });
2811
+ }
2812
+ return list;
2813
+ }, [collection.fields, entries]);
2814
+ const [isExportModalOpen, setIsExportModalOpen] = (0, import_react5.useState)(false);
2815
+ const [exportMode, setExportMode] = (0, import_react5.useState)("all");
2816
+ const [exportDateField, setExportDateField] = (0, import_react5.useState)("");
2817
+ const [exportDateRange, setExportDateRange] = (0, import_react5.useState)(null);
2818
+ (0, import_react5.useEffect)(() => {
2819
+ if (dateFields.length > 0 && !exportDateField) {
2820
+ setExportDateField(dateFields[0].id);
2821
+ }
2822
+ }, [dateFields, exportDateField]);
2823
+ const exportTargetEntries = (0, import_react5.useMemo)(() => {
2824
+ if (exportMode === "all" || !exportDateField || !exportDateRange || !exportDateRange[0] || !exportDateRange[1]) {
2825
+ return entries;
2826
+ }
2827
+ return filterEntriesByDateRange(
2828
+ entries,
2829
+ exportDateField,
2830
+ exportDateRange[0].format("YYYY-MM-DD"),
2831
+ exportDateRange[1].format("YYYY-MM-DD")
2832
+ );
2833
+ }, [entries, exportMode, exportDateField, exportDateRange]);
2834
+ const [isImportModalOpen, setIsImportModalOpen] = (0, import_react5.useState)(false);
2835
+ const [importFile, setImportFile] = (0, import_react5.useState)(null);
2836
+ const [importResult, setImportResult] = (0, import_react5.useState)(null);
2837
+ const [isParsingImport, setIsParsingImport] = (0, import_react5.useState)(false);
2838
+ const [isImporting, setIsImporting] = (0, import_react5.useState)(false);
2839
+ const [importExistingAction, setImportExistingAction] = (0, import_react5.useState)("omit");
2840
+ const [importProgress, setImportProgress] = (0, import_react5.useState)({ current: 0, total: 0 });
2841
+ const fileInputRef = (0, import_react5.useRef)(null);
2530
2842
  const load = (0, import_react5.useCallback)(() => {
2531
2843
  setLoadingEntries(true);
2532
2844
  ctx.adapter.listEntries(collection.id).then((res) => {
@@ -2562,7 +2874,111 @@ function CollectionEditor({ collection }) {
2562
2874
  (0, import_react5.useEffect)(() => {
2563
2875
  load();
2564
2876
  }, [load]);
2877
+ const handleOpenExportModal = () => {
2878
+ if (dateFields.length === 0) {
2879
+ try {
2880
+ exportCollectionToExcel(collection, entries);
2881
+ message.success(t.exportSuccess);
2882
+ } catch (err) {
2883
+ console.error("Error exportando a Excel:", err);
2884
+ message.error("No se pudo exportar a Excel.");
2885
+ }
2886
+ return;
2887
+ }
2888
+ setIsExportModalOpen(true);
2889
+ };
2890
+ const handleConfirmExport = () => {
2891
+ try {
2892
+ let suffix = "";
2893
+ if (exportMode === "byDate" && exportDateRange?.[0] && exportDateRange?.[1]) {
2894
+ suffix = `${(collection.name || collection.id).toLowerCase()}_${exportDateRange[0].format("YYYYMMDD")}_al_${exportDateRange[1].format("YYYYMMDD")}`;
2895
+ }
2896
+ exportCollectionToExcel(collection, exportTargetEntries, suffix);
2897
+ message.success(t.exportSuccess);
2898
+ setIsExportModalOpen(false);
2899
+ } catch (err) {
2900
+ console.error("Error exportando a Excel:", err);
2901
+ message.error("No se pudo exportar a Excel.");
2902
+ }
2903
+ };
2904
+ const handleProcessImportFile = async (file) => {
2905
+ setIsParsingImport(true);
2906
+ setImportFile(file);
2907
+ try {
2908
+ const res = await parseExcelForCollection(file, collection, entries);
2909
+ setImportResult(res);
2910
+ if (res.errors.length > 0) {
2911
+ message.warning(res.errors[0]);
2912
+ }
2913
+ } catch (err) {
2914
+ console.error("Error parseando archivo Excel:", err);
2915
+ message.error(err?.message || "Error al leer el archivo Excel.");
2916
+ setImportResult(null);
2917
+ setImportFile(null);
2918
+ } finally {
2919
+ setIsParsingImport(false);
2920
+ }
2921
+ };
2922
+ const handleExecuteImport = async () => {
2923
+ if (!importResult || !importResult.records.length) return;
2924
+ setIsImporting(true);
2925
+ const total = importResult.records.length;
2926
+ setImportProgress({ current: 0, total });
2927
+ try {
2928
+ let createdCount = 0;
2929
+ let updatedCount = 0;
2930
+ let omittedCount = 0;
2931
+ for (let i = 0; i < total; i++) {
2932
+ const item = { ...importResult.records[i] };
2933
+ const existing = findExistingEntry(item, entries, collection);
2934
+ if (existing) {
2935
+ if (importExistingAction === "omit") {
2936
+ omittedCount++;
2937
+ } else {
2938
+ const merged = { ...existing, ...item, id: existing.id };
2939
+ if (existing._id) merged._id = existing._id;
2940
+ await ctx.adapter.putEntry(collection.id, merged);
2941
+ updatedCount++;
2942
+ }
2943
+ } else {
2944
+ await ctx.adapter.putEntry(collection.id, item);
2945
+ createdCount++;
2946
+ }
2947
+ setImportProgress({ current: i + 1, total });
2948
+ }
2949
+ if (createdCount > 0 && omittedCount > 0) {
2950
+ message.success(
2951
+ `Se importaron ${createdCount} registros nuevos. Se omitieron ${omittedCount} registros ya existentes.`
2952
+ );
2953
+ } else if (createdCount > 0 && updatedCount > 0) {
2954
+ message.success(
2955
+ `Se crearon ${createdCount} registros y se actualizaron ${updatedCount} existentes.`
2956
+ );
2957
+ } else if (createdCount > 0) {
2958
+ message.success(`Se importaron ${createdCount} registros exitosamente.`);
2959
+ } else if (omittedCount > 0) {
2960
+ message.info(
2961
+ `Los ${omittedCount} registros ya se encontraban creados. No se duplic\xF3 ning\xFAn dato.`
2962
+ );
2963
+ } else if (updatedCount > 0) {
2964
+ message.success(`Se actualizaron ${updatedCount} registros existentes.`);
2965
+ }
2966
+ load();
2967
+ setIsImportModalOpen(false);
2968
+ setImportResult(null);
2969
+ setImportFile(null);
2970
+ } catch (err) {
2971
+ console.error("Error importando registros:", err);
2972
+ message.error("Ocurri\xF3 un error al guardar los registros importados.");
2973
+ } finally {
2974
+ setIsImporting(false);
2975
+ }
2976
+ };
2565
2977
  const startNew = () => {
2978
+ if (collection.customCreateView) {
2979
+ setIsCustomCreating(true);
2980
+ return;
2981
+ }
2566
2982
  setIsCreatingManual(true);
2567
2983
  setOriginalId(null);
2568
2984
  setDuplicateErrors({});
@@ -2749,23 +3165,80 @@ function CollectionEditor({ collection }) {
2749
3165
  };
2750
3166
  const visibleFields = collection.tableFields?.length ? collection.tableFields.map((tf) => collection.fields.find((f) => f.id === tf)).filter(Boolean) : collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 6);
2751
3167
  const isCreatingEntry = isCreatingManual || (editing ? !entries.some((entry) => entry.id && entry.id === editing.id || entry._id && entry._id === (editing._id || editing.id)) : false);
3168
+ if (isCustomCreating && collection.customCreateView) {
3169
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "w-full", children: collection.customCreateView({
3170
+ onBack: () => setIsCustomCreating(false),
3171
+ reload: () => {
3172
+ load();
3173
+ }
3174
+ }) });
3175
+ }
3176
+ if (customActiveView) {
3177
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "w-full", children: customActiveView({
3178
+ onBack: () => setCustomActiveView(null),
3179
+ reload: () => {
3180
+ load();
3181
+ }
3182
+ }) });
3183
+ }
3184
+ if (customViewingRecord && (collection.customDetailView || collection.renderCustomDetail || collection.customEditView)) {
3185
+ const renderFn = isCustomEditing && collection.customEditView ? collection.customEditView : collection.customDetailView || collection.renderCustomDetail;
3186
+ if (renderFn) {
3187
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "w-full", children: renderFn({
3188
+ record: customViewingRecord,
3189
+ isEditing: isCustomEditing,
3190
+ onBack: () => {
3191
+ setCustomViewingRecord(null);
3192
+ setIsCustomEditing(false);
3193
+ },
3194
+ reload: () => {
3195
+ load();
3196
+ }
3197
+ }) });
3198
+ }
3199
+ }
2752
3200
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mx-auto max-w-5xl", children: [
2753
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-8 flex items-center justify-between", children: [
3201
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-8 flex flex-col sm:flex-row sm:items-center justify-between gap-4", children: [
2754
3202
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
2755
3203
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight", children: collection.name }),
2756
3204
  collection.description && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-sm text-slate-500 mt-1", children: collection.description })
2757
3205
  ] }),
2758
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2759
- import_antd.Button,
2760
- {
2761
- type: "primary",
2762
- size: "large",
2763
- icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "h-4 w-4" }),
2764
- onClick: startNew,
2765
- className: "rounded-xl font-bold shadow-sm",
2766
- children: t.newEntry
2767
- }
2768
- )
3206
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-wrap items-center gap-2", children: [
3207
+ !collection.disableExport && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3208
+ import_antd.Button,
3209
+ {
3210
+ size: "large",
3211
+ icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileDown, { className: "h-4 w-4 text-emerald-600" }),
3212
+ onClick: handleOpenExportModal,
3213
+ disabled: loadingEntries || entries.length === 0,
3214
+ className: "rounded-xl font-medium border-slate-200 hover:border-emerald-500 hover:text-emerald-600 shadow-sm",
3215
+ title: "Descargar registros en formato Excel (soporta filtro por fechas)",
3216
+ children: t.exportExcel
3217
+ }
3218
+ ),
3219
+ !collection.disableImport && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3220
+ import_antd.Button,
3221
+ {
3222
+ size: "large",
3223
+ icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileUp, { className: "h-4 w-4 text-sky-600" }),
3224
+ onClick: () => setIsImportModalOpen(true),
3225
+ className: "rounded-xl font-medium border-slate-200 hover:border-sky-500 hover:text-sky-600 shadow-sm",
3226
+ title: "Cargar registros desde un archivo Excel o CSV",
3227
+ children: t.importExcel
3228
+ }
3229
+ ),
3230
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3231
+ import_antd.Button,
3232
+ {
3233
+ type: "primary",
3234
+ size: "large",
3235
+ icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "h-4 w-4" }),
3236
+ onClick: startNew,
3237
+ className: "rounded-xl font-bold shadow-sm",
3238
+ children: t.newEntry
3239
+ }
3240
+ )
3241
+ ] })
2769
3242
  ] }),
2770
3243
  !editing && (collection.searchBy?.length || collection.filterBy?.length) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-6 flex flex-wrap gap-4 items-center p-4 bg-white rounded-2xl border border-slate-200 shadow-sm animate-in fade-in slide-in-from-top-2", children: [
2771
3244
  collection.searchBy?.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "relative flex-1 min-w-[220px]", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -2790,7 +3263,7 @@ function CollectionEditor({ collection }) {
2790
3263
  const fieldDef = collection.fields.find((cf) => cf.id === f);
2791
3264
  if (!fieldDef) return null;
2792
3265
  if (fieldDef.type === "date") {
2793
- const dateVal = filters[f] ? (0, import_dayjs.default)(filters[f], ["YYYY/MM/DD", "YYYY-MM-DD", "YYYY-M-D"]).isValid() ? (0, import_dayjs.default)(filters[f], ["YYYY/MM/DD", "YYYY-MM-DD", "YYYY-M-D"]) : null : null;
3266
+ const dateVal = filters[f] ? (0, import_dayjs2.default)(filters[f], ["YYYY/MM/DD", "YYYY-MM-DD", "YYYY-M-D"]).isValid() ? (0, import_dayjs2.default)(filters[f], ["YYYY/MM/DD", "YYYY-MM-DD", "YYYY-M-D"]) : null : null;
2794
3267
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "min-w-[180px]", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2795
3268
  import_antd.DatePicker,
2796
3269
  {
@@ -2945,7 +3418,7 @@ function CollectionEditor({ collection }) {
2945
3418
  String(editing[f.id]).includes("maps") ? "Ver en Google Maps" : String(editing[f.id])
2946
3419
  ]
2947
3420
  }
2948
- ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs text-slate-400 py-1 block", children: "\u2014" }) : f.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2.5 text-sm text-slate-800 whitespace-pre-line leading-relaxed", children: String(editing[f.id] || "\u2014") }) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? /* @__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: formatTo12Hour(editing[f.id]) || String(editing[f.id] ?? "\u2014") }) : /* @__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] ?? "\u2014") })
3421
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs text-slate-400 py-1 block", children: "\u2014" }) : f.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-xl bg-slate-50 border border-slate-200 px-3.5 py-2.5 text-sm text-slate-800 whitespace-pre-line leading-relaxed", children: String(editing[f.id] || "\u2014") }) : f.type === "time" || f.id.toLowerCase().includes("hora") || f.id === "inicioServicio" || f.id === "finServicio" ? /* @__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: formatTo12Hour(editing[f.id]) || String(editing[f.id] ?? "\u2014") }) : f.renderCell ? /* @__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: f.renderCell(editing[f.id], editing) }) : /* @__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] ?? "\u2014") })
2949
3422
  ] }, f.id);
2950
3423
  }
2951
3424
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${colSpanClass}`, children: [
@@ -2996,7 +3469,7 @@ function CollectionEditor({ collection }) {
2996
3469
  import_antd.DatePicker,
2997
3470
  {
2998
3471
  size: "large",
2999
- value: editing[f.id] ? (0, import_dayjs.default)(String(editing[f.id])).isValid() ? (0, import_dayjs.default)(String(editing[f.id])) : null : null,
3472
+ value: editing[f.id] ? (0, import_dayjs2.default)(String(editing[f.id])).isValid() ? (0, import_dayjs2.default)(String(editing[f.id])) : null : null,
3000
3473
  onChange: (date, dateString) => setEditing({ ...editing, [f.id]: (Array.isArray(dateString) ? dateString[0] : dateString) || (date ? date.format("YYYY/MM/DD") : "") }),
3001
3474
  format: "YYYY/MM/DD",
3002
3475
  placeholder: `Seleccionar ${f.label.toLowerCase()}...`,
@@ -3536,6 +4009,304 @@ function CollectionEditor({ collection }) {
3536
4009
  ] }) })
3537
4010
  }
3538
4011
  ),
4012
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4013
+ import_antd.Modal,
4014
+ {
4015
+ open: isExportModalOpen,
4016
+ title: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2 text-slate-900 font-bold text-lg", children: [
4017
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileDown, { className: "h-5 w-5 text-emerald-600" }),
4018
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
4019
+ t.exportModalTitle,
4020
+ " - ",
4021
+ collection.name
4022
+ ] })
4023
+ ] }),
4024
+ onCancel: () => setIsExportModalOpen(false),
4025
+ footer: null,
4026
+ centered: true,
4027
+ width: "min(560px, calc(100vw - 32px))",
4028
+ mask: { blur: true },
4029
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "py-2 space-y-4", children: [
4030
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-500", children: "Descarga los registros en formato Excel estructurado (.xlsx)." }),
4031
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4032
+ import_antd.Segmented,
4033
+ {
4034
+ size: "large",
4035
+ block: true,
4036
+ value: exportMode,
4037
+ onChange: (val) => setExportMode(val),
4038
+ options: [
4039
+ { label: `${t.exportAllRecords} (${entries.length})`, value: "all" },
4040
+ { label: t.exportFilterByDate, value: "byDate" }
4041
+ ]
4042
+ }
4043
+ ),
4044
+ exportMode === "byDate" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-4 bg-slate-50 border border-slate-200 rounded-xl space-y-3 animate-in fade-in", children: [
4045
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-1", children: [
4046
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "text-xs font-semibold text-slate-600", children: [
4047
+ t.exportDateRangeLabel,
4048
+ ":"
4049
+ ] }),
4050
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4051
+ import_antd.DatePicker.RangePicker,
4052
+ {
4053
+ size: "large",
4054
+ className: "w-full rounded-xl",
4055
+ value: exportDateRange,
4056
+ onChange: (dates) => setExportDateRange(dates),
4057
+ presets: [
4058
+ { label: "Hoy", value: [(0, import_dayjs2.default)().startOf("day"), (0, import_dayjs2.default)().endOf("day")] },
4059
+ { label: "Esta semana", value: [(0, import_dayjs2.default)().startOf("week"), (0, import_dayjs2.default)().endOf("week")] },
4060
+ { label: "Este mes", value: [(0, import_dayjs2.default)().startOf("month"), (0, import_dayjs2.default)().endOf("month")] },
4061
+ { label: "\xDAltimos 30 d\xEDas", value: [(0, import_dayjs2.default)().subtract(30, "day"), (0, import_dayjs2.default)()] },
4062
+ { label: "Este a\xF1o", value: [(0, import_dayjs2.default)().startOf("year"), (0, import_dayjs2.default)().endOf("year")] }
4063
+ ]
4064
+ }
4065
+ )
4066
+ ] }),
4067
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "pt-1 flex items-center justify-between text-xs", children: [
4068
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-slate-500 font-medium", children: "Registros coincidentes:" }),
4069
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4070
+ "span",
4071
+ {
4072
+ className: `font-bold ${exportTargetEntries.length > 0 ? "text-emerald-600" : "text-amber-600"}`,
4073
+ children: [
4074
+ exportTargetEntries.length,
4075
+ " de ",
4076
+ entries.length,
4077
+ " registros"
4078
+ ]
4079
+ }
4080
+ )
4081
+ ] })
4082
+ ] }),
4083
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex justify-end gap-2 pt-2", children: [
4084
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd.Button, { size: "large", onClick: () => setIsExportModalOpen(false), children: t.cancel }),
4085
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4086
+ import_antd.Button,
4087
+ {
4088
+ type: "primary",
4089
+ size: "large",
4090
+ icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileDown, { className: "h-4 w-4" }),
4091
+ onClick: handleConfirmExport,
4092
+ disabled: exportTargetEntries.length === 0,
4093
+ className: "rounded-xl font-bold bg-emerald-600 hover:bg-emerald-500",
4094
+ children: [
4095
+ t.exportDownloadBtn,
4096
+ " (",
4097
+ exportTargetEntries.length,
4098
+ ")"
4099
+ ]
4100
+ }
4101
+ )
4102
+ ] })
4103
+ ] })
4104
+ }
4105
+ ),
4106
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4107
+ import_antd.Modal,
4108
+ {
4109
+ open: isImportModalOpen,
4110
+ title: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2 text-slate-900 font-bold text-lg", children: [
4111
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileSpreadsheet, { className: "h-5 w-5 text-emerald-600" }),
4112
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
4113
+ t.importModalTitle,
4114
+ " - ",
4115
+ collection.name
4116
+ ] })
4117
+ ] }),
4118
+ onCancel: () => {
4119
+ if (!isImporting) {
4120
+ setIsImportModalOpen(false);
4121
+ setImportResult(null);
4122
+ setImportFile(null);
4123
+ }
4124
+ },
4125
+ footer: null,
4126
+ centered: true,
4127
+ width: "min(800px, calc(100vw - 32px))",
4128
+ mask: { blur: true },
4129
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "py-2 space-y-4", children: [
4130
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-500", children: t.importModalDesc }),
4131
+ !importResult ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4132
+ "div",
4133
+ {
4134
+ onDragOver: (e) => {
4135
+ e.preventDefault();
4136
+ e.stopPropagation();
4137
+ },
4138
+ onDrop: (e) => {
4139
+ e.preventDefault();
4140
+ e.stopPropagation();
4141
+ const file = e.dataTransfer.files?.[0];
4142
+ if (file) handleProcessImportFile(file);
4143
+ },
4144
+ onClick: () => fileInputRef.current?.click(),
4145
+ className: "border-2 border-dashed border-slate-300 hover:border-emerald-500 rounded-2xl p-8 text-center cursor-pointer bg-slate-50 hover:bg-emerald-50/30 transition-all flex flex-col items-center justify-center gap-3",
4146
+ children: [
4147
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4148
+ "input",
4149
+ {
4150
+ ref: fileInputRef,
4151
+ type: "file",
4152
+ accept: ".xlsx,.xls,.csv",
4153
+ className: "hidden",
4154
+ onChange: (e) => {
4155
+ const file = e.target.files?.[0];
4156
+ if (file) handleProcessImportFile(file);
4157
+ }
4158
+ }
4159
+ ),
4160
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "size-14 rounded-full bg-emerald-100 flex items-center justify-center text-emerald-600 shadow-sm", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileSpreadsheet, { className: "size-7" }) }),
4161
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
4162
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "font-semibold text-sm text-slate-700", children: t.importDropzone }),
4163
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-400 mt-1", children: t.importDropzoneSub })
4164
+ ] }),
4165
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd.Button, { size: "middle", loading: isParsingImport, className: "mt-2 rounded-lg font-medium", children: isParsingImport ? "Leyendo archivo..." : "Seleccionar archivo" })
4166
+ ]
4167
+ }
4168
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4", children: [
4169
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between p-3.5 bg-emerald-50/60 border border-emerald-200 rounded-xl", children: [
4170
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-3", children: [
4171
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "size-9 rounded-lg bg-emerald-100 text-emerald-700 flex items-center justify-center font-bold", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileSpreadsheet, { className: "size-5" }) }),
4172
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
4173
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-sm font-bold text-slate-900", children: importFile?.name }),
4174
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "text-xs text-emerald-700 font-medium", children: [
4175
+ importResult.totalRows,
4176
+ " registros encontrados en el archivo"
4177
+ ] })
4178
+ ] })
4179
+ ] }),
4180
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4181
+ import_antd.Button,
4182
+ {
4183
+ size: "small",
4184
+ onClick: () => {
4185
+ setImportResult(null);
4186
+ setImportFile(null);
4187
+ },
4188
+ disabled: isImporting,
4189
+ children: "Cambiar archivo"
4190
+ }
4191
+ )
4192
+ ] }),
4193
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-wrap items-center gap-2 p-3 bg-slate-50 border border-slate-200 rounded-xl", children: [
4194
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs font-semibold text-slate-700", children: "Estado de los registros:" }),
4195
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd.Tag, { color: "green", className: "text-xs font-medium", children: [
4196
+ "\u2713 ",
4197
+ importResult.newRecordsCount,
4198
+ " ",
4199
+ t.importNewDetected
4200
+ ] }),
4201
+ importResult.existingRecordsCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd.Tag, { color: "gold", className: "text-xs font-medium", children: [
4202
+ "\u2139\uFE0F ",
4203
+ importResult.existingRecordsCount,
4204
+ " ",
4205
+ t.importExistingDetected
4206
+ ] })
4207
+ ] }),
4208
+ importResult.existingRecordsCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-3.5 bg-slate-50/90 rounded-xl border border-slate-200 space-y-2", children: [
4209
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs font-bold text-slate-700 block", children: t.importOverwritesWarning }),
4210
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4211
+ import_antd.Radio.Group,
4212
+ {
4213
+ value: importExistingAction,
4214
+ onChange: (e) => setImportExistingAction(e.target.value),
4215
+ disabled: isImporting,
4216
+ className: "flex flex-col gap-2.5",
4217
+ children: [
4218
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd.Radio, { value: "omit", className: "text-xs text-slate-700", children: [
4219
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "font-semibold text-emerald-700 block", children: t.importExistingOmit }),
4220
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[11px] text-slate-500 block", children: "Si ya existe por ID o campo \xFAnico, no se vuelve a crear ni duplicar en la base de datos." })
4221
+ ] }),
4222
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd.Radio, { value: "update", className: "text-xs text-slate-700", children: [
4223
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "font-semibold text-sky-700 block", children: t.importExistingUpdate }),
4224
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[11px] text-slate-500 block", children: "Actualiza los campos de los registros ya existentes con los datos del archivo." })
4225
+ ] })
4226
+ ]
4227
+ }
4228
+ )
4229
+ ] }),
4230
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
4231
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-bold text-slate-600 uppercase tracking-wider block mb-1.5", children: [
4232
+ "Campos reconocidos (",
4233
+ importResult.matchedFields.length,
4234
+ "):"
4235
+ ] }),
4236
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-wrap gap-1.5", children: [
4237
+ importResult.matchedFields.map((m, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd.Tag, { color: "green", className: "text-xs py-0.5", children: [
4238
+ "\u2713 ",
4239
+ m.label
4240
+ ] }, idx)),
4241
+ importResult.unmatchedHeaders.map((u, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd.Tag, { color: "orange", className: "text-xs py-0.5", children: [
4242
+ "\u26A0\uFE0F ",
4243
+ u,
4244
+ " (omitido)"
4245
+ ] }, idx))
4246
+ ] })
4247
+ ] }),
4248
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
4249
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-bold text-slate-600 uppercase tracking-wider block mb-1.5", children: [
4250
+ t.importPreviewTitle,
4251
+ " (",
4252
+ Math.min(5, importResult.samplePreview.length),
4253
+ " de ",
4254
+ importResult.totalRows,
4255
+ "):"
4256
+ ] }),
4257
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "overflow-x-auto border border-slate-200 rounded-xl max-h-48 text-xs", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("table", { className: "w-full text-left", children: [
4258
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("thead", { className: "bg-slate-100/80 text-slate-700 font-semibold border-b border-slate-200", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { children: importResult.matchedFields.slice(0, 6).map((m, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("th", { className: "p-2 whitespace-nowrap", children: m.label }, idx)) }) }),
4259
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tbody", { className: "divide-y divide-slate-100", children: importResult.samplePreview.map((row, rIdx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { className: "hover:bg-slate-50/60", children: importResult.matchedFields.slice(0, 6).map((m, cIdx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "p-2 whitespace-nowrap max-w-[160px] truncate text-slate-600", children: String(row[m.fieldId] ?? "") }, cIdx)) }, rIdx)) })
4260
+ ] }) })
4261
+ ] }),
4262
+ isImporting && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-1", children: [
4263
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex justify-between text-xs text-slate-600 font-medium", children: [
4264
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: t.importingProgress }),
4265
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
4266
+ importProgress.current,
4267
+ " / ",
4268
+ importProgress.total
4269
+ ] })
4270
+ ] }),
4271
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4272
+ import_antd.Progress,
4273
+ {
4274
+ percent: Math.round(importProgress.current / (importProgress.total || 1) * 100),
4275
+ status: "active"
4276
+ }
4277
+ )
4278
+ ] }),
4279
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex justify-end gap-2 pt-2", children: [
4280
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4281
+ import_antd.Button,
4282
+ {
4283
+ size: "large",
4284
+ onClick: () => setIsImportModalOpen(false),
4285
+ disabled: isImporting,
4286
+ children: t.cancel
4287
+ }
4288
+ ),
4289
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4290
+ import_antd.Button,
4291
+ {
4292
+ type: "primary",
4293
+ size: "large",
4294
+ loading: isImporting,
4295
+ onClick: handleExecuteImport,
4296
+ className: "rounded-xl font-bold bg-emerald-600 hover:bg-emerald-500",
4297
+ children: [
4298
+ t.importConfirmBtn,
4299
+ " (",
4300
+ importExistingAction === "omit" && importResult.existingRecordsCount > 0 ? importResult.newRecordsCount : importResult.totalRows,
4301
+ ")"
4302
+ ]
4303
+ }
4304
+ )
4305
+ ] })
4306
+ ] })
4307
+ ] })
4308
+ }
4309
+ ),
3539
4310
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "overflow-x-auto rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("table", { className: "w-full text-sm text-left", children: [
3540
4311
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("thead", { className: "bg-slate-50/80 border-b border-slate-200", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("tr", { children: [
3541
4312
  visibleFields.map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: f.label }, f.id)),
@@ -3629,10 +4400,52 @@ function CollectionEditor({ collection }) {
3629
4400
  }
3630
4401
  ) : 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)),
3631
4402
  /* @__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: [
3632
- (collection.enableDetailView || collection.onViewRecord) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4403
+ collection.customRowActions && collection.customRowActions({
4404
+ record: e,
4405
+ openDetail: () => {
4406
+ if (collection.customDetailView || collection.renderCustomDetail) {
4407
+ setCustomViewingRecord(e);
4408
+ setIsCustomEditing(false);
4409
+ return;
4410
+ }
4411
+ if (collection.onViewRecord) {
4412
+ collection.onViewRecord(e);
4413
+ return;
4414
+ }
4415
+ setIsCreatingManual(false);
4416
+ setIsViewingDetail(true);
4417
+ setOriginalId(String(e.id || ""));
4418
+ setDuplicateErrors({});
4419
+ setEditing({ ...e });
4420
+ },
4421
+ openEdit: () => {
4422
+ if (collection.customEditView) {
4423
+ setCustomViewingRecord(e);
4424
+ setIsCustomEditing(true);
4425
+ return;
4426
+ }
4427
+ setIsCreatingManual(false);
4428
+ setIsViewingDetail(false);
4429
+ setOriginalId(String(e.id || ""));
4430
+ setDuplicateErrors({});
4431
+ setEditing({ ...e });
4432
+ },
4433
+ openCustomView: (renderFn) => {
4434
+ setCustomActiveView(() => renderFn);
4435
+ },
4436
+ reload: () => {
4437
+ load();
4438
+ }
4439
+ }),
4440
+ (collection.enableDetailView || collection.onViewRecord || collection.customDetailView || collection.renderCustomDetail) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3633
4441
  "button",
3634
4442
  {
3635
4443
  onClick: () => {
4444
+ if (collection.customDetailView || collection.renderCustomDetail) {
4445
+ setCustomViewingRecord(e);
4446
+ setIsCustomEditing(false);
4447
+ return;
4448
+ }
3636
4449
  if (collection.onViewRecord) {
3637
4450
  collection.onViewRecord(e);
3638
4451
  return;
@@ -3661,6 +4474,11 @@ function CollectionEditor({ collection }) {
3661
4474
  "button",
3662
4475
  {
3663
4476
  onClick: () => {
4477
+ if (collection.customEditView) {
4478
+ setCustomViewingRecord(e);
4479
+ setIsCustomEditing(true);
4480
+ return;
4481
+ }
3664
4482
  setIsCreatingManual(false);
3665
4483
  setIsViewingDetail(false);
3666
4484
  setOriginalId(String(e.id || ""));
@@ -3672,7 +4490,7 @@ function CollectionEditor({ collection }) {
3672
4490
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4" })
3673
4491
  }
3674
4492
  ),
3675
- !collection.disableDelete && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4493
+ !collection.disableDelete && !collection.hideDelete && (!collection.canDelete || collection.canDelete(e)) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
3676
4494
  "button",
3677
4495
  {
3678
4496
  onClick: () => remove(e.id),