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