@tbox.cn/app-module-parking 0.2.0 → 0.9.3

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.
Files changed (71) hide show
  1. package/AGENTS.md +16 -0
  2. package/README.md +58 -11
  3. package/dist/chunk-KEUD5YHH.js +1087 -0
  4. package/dist/chunk-QHLX6WXM.js +2667 -0
  5. package/dist/client/index.d.ts +17 -3
  6. package/dist/client/index.js +4 -2
  7. package/dist/index.d.ts +4 -3
  8. package/dist/index.js +14 -4
  9. package/dist/parking-2S2UPCOF.css +1306 -0
  10. package/dist/parking-guide-hero-pea-v2-X2O44LPQ.jpg +0 -0
  11. package/dist/server/index.d.ts +1216 -72
  12. package/dist/server/index.js +11 -3
  13. package/package.json +24 -16
  14. package/skills/parking/SKILL.md +165 -0
  15. package/skills/parking/references/payment-safety.md +25 -0
  16. package/src/client/assets/parking-guide-hero-pea-v2.jpg +0 -0
  17. package/src/client/assets/parking-guide-hero.jpg +0 -0
  18. package/src/client/assets.d.ts +5 -0
  19. package/src/client/cards/index.ts +8 -0
  20. package/src/client/cards/parking-info/index.tsx +41 -0
  21. package/src/client/cards/parking-payment/benefit-selection.ts +79 -0
  22. package/src/client/cards/parking-payment/index.tsx +442 -0
  23. package/src/client/cards/parking-payment-records/index.tsx +259 -0
  24. package/src/client/cards/parking-payment-result/index.tsx +83 -0
  25. package/src/client/cards/parking-vehicle-management/PlateKeyboard.tsx +106 -0
  26. package/src/client/cards/parking-vehicle-management/index.tsx +344 -0
  27. package/src/client/cards/parking-vehicle-management/plate-keyboard.ts +113 -0
  28. package/src/client/cards/view.ts +83 -0
  29. package/src/client/index.ts +19 -4
  30. package/src/client/styles/parking.css +1306 -0
  31. package/src/client/types/css.d.ts +2 -0
  32. package/src/server/actions.ts +975 -0
  33. package/src/server/cards/index.ts +14 -0
  34. package/src/server/cards/parking-info/meta.ts +19 -0
  35. package/src/server/cards/parking-info/samples.ts +50 -0
  36. package/src/server/cards/parking-payment/meta.ts +29 -0
  37. package/src/server/cards/parking-payment/samples.ts +311 -0
  38. package/src/server/cards/parking-payment-records/meta.ts +32 -0
  39. package/src/server/cards/parking-payment-records/samples.ts +86 -0
  40. package/src/server/cards/parking-payment-result/meta.ts +21 -0
  41. package/src/server/cards/parking-payment-result/samples.ts +84 -0
  42. package/src/server/cards/parking-vehicle-management/meta.ts +20 -0
  43. package/src/server/cards/parking-vehicle-management/samples.ts +73 -0
  44. package/src/server/domain.ts +279 -0
  45. package/src/server/handler.ts +47 -16
  46. package/src/server/index.ts +97 -17
  47. package/src/server/intent-context.ts +14 -0
  48. package/src/server/ports.ts +59 -0
  49. package/src/server/service.ts +474 -45
  50. package/src/server/tools.ts +846 -0
  51. package/tbox.module.json +107 -0
  52. package/tests/benefit-selection.test.ts +70 -0
  53. package/tests/cards-render.test.tsx +643 -0
  54. package/tests/dispatcher-flow.test.ts +256 -0
  55. package/tests/payment-flow.test.ts +420 -0
  56. package/tests/plate-keyboard.test.ts +158 -0
  57. package/tests/ports-resolve.test.ts +113 -0
  58. package/tests/pretool-parking-fee.test.ts +104 -0
  59. package/tests/samples.test.ts +44 -0
  60. package/tests/skills.test.ts +37 -0
  61. package/tests/tools-gate.test.ts +237 -0
  62. package/tests/tools-membership.test.ts +91 -0
  63. package/tests/view.test.ts +61 -0
  64. package/tsup.config.ts +9 -1
  65. package/dist/chunk-BYD3C6NE.js +0 -140
  66. package/dist/chunk-QQLBZY6D.js +0 -55
  67. package/src/client/cards/parking-fee/index.tsx +0 -59
  68. package/src/server/cards/parking-fee/meta.ts +0 -26
  69. package/src/server/tool.ts +0 -36
  70. package/tbox.component.json +0 -20
  71. package/tests/service.test.ts +0 -49
@@ -0,0 +1,1087 @@
1
+ // src/client/index.ts
2
+ import "./parking-2S2UPCOF.css";
3
+
4
+ // src/client/cards/parking-payment/index.tsx
5
+ import { useEffect, useState } from "react";
6
+ import { Car, Check, CheckCircle, Clock, CurrencyCircleDollar, ShieldCheck, Sparkle } from "@phosphor-icons/react";
7
+ import { callCapability, markSelfRendering, sendCardAction } from "@tbox.cn/app-sdk/client";
8
+
9
+ // src/client/assets/parking-guide-hero-pea-v2.jpg
10
+ var parking_guide_hero_pea_v2_default = "./parking-guide-hero-pea-v2-X2O44LPQ.jpg";
11
+
12
+ // src/client/cards/parking-payment/benefit-selection.ts
13
+ function conflicts(a, b) {
14
+ const aBlocksB = !!(b.kind && a.exclusiveWithKinds?.includes(b.kind));
15
+ const bBlocksA = !!(a.kind && b.exclusiveWithKinds?.includes(a.kind));
16
+ return aBlocksB || bBlocksA;
17
+ }
18
+ function resolveBenefitSelection(benefits, current, target, checked) {
19
+ if (!checked) {
20
+ return { selected: current.filter((ref) => ref !== target), dropped: [] };
21
+ }
22
+ const targetBenefit = benefits.find((b) => b.benefitRef === target);
23
+ if (!targetBenefit) return { selected: current, dropped: [] };
24
+ const dropped = [];
25
+ const kept = current.filter((ref) => {
26
+ if (ref === target) return false;
27
+ const other = benefits.find((b) => b.benefitRef === ref);
28
+ if (other && conflicts(targetBenefit, other)) {
29
+ dropped.push(other);
30
+ return false;
31
+ }
32
+ return true;
33
+ });
34
+ return { selected: [...kept, target], dropped };
35
+ }
36
+ function describeDropped(dropped) {
37
+ if (dropped.length === 0) return "";
38
+ const names = dropped.map((b) => b.title).join("\u3001");
39
+ return `\u5DF2\u53D6\u6D88\u300C${names}\u300D\u2014\u2014\u8BE5\u4F18\u60E0\u4E0D\u53EF\u4E0E\u672C\u6B21\u6240\u9009\u53E0\u52A0`;
40
+ }
41
+ function selectableRefsOf(benefits) {
42
+ return (benefits ?? []).filter((b) => b.autoSelected).map((b) => b.benefitRef);
43
+ }
44
+
45
+ // src/client/cards/parking-payment/index.tsx
46
+ import { jsx, jsxs } from "react/jsx-runtime";
47
+ var VEHICLE_MANAGE_QUERY = "\u67E5\u770B\u6211\u7684\u7ED1\u5B9A\u8F66\u8F86";
48
+ var REPRICE_TIMEOUT_MS = 8e3;
49
+ var NAV_PAY_TIMEOUT = 5 * 60 * 1e3;
50
+ function formatDiscountText(value) {
51
+ const text = value?.trim();
52
+ if (!text || !/\d/.test(text)) return text;
53
+ if (/^[-−]/.test(text)) return `-${text.slice(1).trimStart()}`;
54
+ const currencyNegative = text.match(/^([¥¥$])\s*[-−]\s*(.+)$/);
55
+ if (currencyNegative) return `-${currencyNegative[1]}${currencyNegative[2]}`;
56
+ return `-${text}`;
57
+ }
58
+ function ParkingPaymentCard(props) {
59
+ const { data, cardId, isHistory, actionTokens } = props;
60
+ const [submitting, setSubmitting] = useState(false);
61
+ const [payOpening, setPayOpening] = useState(false);
62
+ const [optimisticSettlement, setOptimisticSettlement] = useState();
63
+ const confirmToken = actionTokens?.["parking.confirm-payment"];
64
+ const onPayResult = (r) => {
65
+ const ps = r?.payStatus;
66
+ if (ps === "success") setOptimisticSettlement({ state: "paid", text: "\u5DF2\u5B8C\u6210\u652F\u4ED8\uFF0C\u8BF7\u572830\u5206\u949F\u5185\u79BB\u573A" });
67
+ else if (ps === "cancelled") setOptimisticSettlement({ state: "failed", text: "\u652F\u4ED8\u5DF2\u53D6\u6D88" });
68
+ else if (ps === "fail") setOptimisticSettlement({ state: "failed", text: "\u652F\u4ED8\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u53D1\u8D77\u5BF9\u8BDD\u8FDB\u884C\u91CD\u8BD5" });
69
+ else if (ps === "unpaid" && r?.message) {
70
+ sendCardAction(cardId, { type: "toast", content: r.message, tone: "info" });
71
+ }
72
+ };
73
+ const callForPay = (apiName, params) => {
74
+ if (isHistory || payOpening) return;
75
+ setPayOpening(true);
76
+ callCapability(apiName, params, NAV_PAY_TIMEOUT).then((r) => onPayResult(r)).catch((err) => {
77
+ const e = err;
78
+ if (e?.code !== "BRIDGE_UNAVAILABLE" && e?.code !== "REQUEST_REPLACED") {
79
+ sendCardAction(cardId, {
80
+ type: "toast",
81
+ content: e?.errorMessage || "\u6253\u5F00\u7F34\u8D39\u9875\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",
82
+ tone: "error"
83
+ });
84
+ }
85
+ }).finally(() => setPayOpening(false));
86
+ };
87
+ const submit = (benefitRefs) => {
88
+ if (isHistory || submitting || payOpening) return;
89
+ const handoff = data.payHandoff;
90
+ if (handoff?.kind === "pay" && handoff.orderInfo) {
91
+ callForPay("openParkingPay", {
92
+ ...handoff.parkingStoreId ? { parkingStoreId: handoff.parkingStoreId } : {},
93
+ orderInfo: handoff.orderInfo
94
+ });
95
+ return;
96
+ }
97
+ if (handoff?.kind === "unpaid" && handoff.orderNo) {
98
+ callForPay("openParkingUnpaidOrder", { orderNo: handoff.orderNo });
99
+ return;
100
+ }
101
+ if (!confirmToken) return;
102
+ setSubmitting(true);
103
+ sendCardAction(
104
+ cardId,
105
+ { type: "moduleAction", actionId: "parking.confirm-payment", contextToken: confirmToken },
106
+ { quoteRef: data.quoteRef, revision: String(data.revision), benefitRefs }
107
+ );
108
+ };
109
+ const isAutoApplied = (benefit) => benefit.kind === "discount" && benefit.autoSelected === true;
110
+ const allSelectable = data.selectableBenefits ?? [];
111
+ const selectable = allSelectable.filter((benefit) => !isAutoApplied(benefit));
112
+ const repriceToken = actionTokens?.["parking.reprice"];
113
+ const [selectedRefs, setSelectedRefs] = useState(
114
+ () => selectableRefsOf(selectable)
115
+ );
116
+ const [repricing, setRepricing] = useState(false);
117
+ const [dropNotice, setDropNotice] = useState("");
118
+ useEffect(() => {
119
+ setRepricing(false);
120
+ setSelectedRefs(selectableRefsOf((data.selectableBenefits ?? []).filter((b) => !isAutoApplied(b))));
121
+ }, [data.revision]);
122
+ useEffect(() => {
123
+ if (!repricing) return void 0;
124
+ const timer = setTimeout(() => setRepricing(false), REPRICE_TIMEOUT_MS);
125
+ return () => clearTimeout(timer);
126
+ }, [repricing]);
127
+ const alwaysOnRefs = [
128
+ ...allSelectable.filter(isAutoApplied).map((b) => b.benefitRef),
129
+ ...(data.appliedBenefits ?? []).filter((a) => !allSelectable.some((b) => b.benefitRef === a.benefitRef)).map((a) => a.benefitRef)
130
+ ];
131
+ const withAlwaysOn = (refs) => [.../* @__PURE__ */ new Set([...alwaysOnRefs, ...refs])];
132
+ const toggleBenefit = (benefitRef, checked) => {
133
+ if (isHistory || repricing || !repriceToken) return;
134
+ const { selected, dropped } = resolveBenefitSelection(selectable, selectedRefs, benefitRef, checked);
135
+ setSelectedRefs([...selected]);
136
+ setDropNotice(describeDropped(dropped));
137
+ setRepricing(true);
138
+ sendCardAction(
139
+ cardId,
140
+ { type: "moduleAction", actionId: "parking.reprice", contextToken: repriceToken },
141
+ { quoteRef: data.quoteRef, revision: String(data.revision), benefitRefs: withAlwaysOn(selected) }
142
+ );
143
+ };
144
+ const payableAmount = Number.parseFloat((data.payableText || "").replace(/[^\d.]/g, ""));
145
+ const isFreeOfCharge = Number.isFinite(payableAmount) && payableAmount === 0;
146
+ const settlement = data.settlement ?? optimisticSettlement;
147
+ const submitDisabled = isHistory || !confirmToken || submitting || payOpening || isFreeOfCharge || settlement !== void 0 || repricing;
148
+ const submitTitle = settlement ? settlement.text : payOpening ? "\u6B63\u5728\u6253\u5F00\u652F\u4ED8\u9875\u2026" : !confirmToken ? "\u652F\u4ED8\u6388\u6743\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u67E5\u8BE2\u505C\u8F66\u8D39" : submitting ? "\u652F\u4ED8\u5904\u7406\u4E2D\u2026" : void 0;
149
+ const appliedBenefits = data.appliedBenefits ?? [];
150
+ const discountText = formatDiscountText(data.discountText);
151
+ const autoAppliedBenefits = appliedBenefits.filter(
152
+ (a) => !selectable.some((b) => b.benefitRef === a.benefitRef)
153
+ );
154
+ const membership = data.membership;
155
+ const submitBenefitRefs = appliedBenefits.map((benefit) => benefit.benefitRef);
156
+ const payButtonText = data.payableText ? `\u652F\u4ED8 ${data.payableText}` : "\u6309\u5B9E\u65F6\u91D1\u989D\u652F\u4ED8";
157
+ const promptMembership = () => {
158
+ if (isHistory) return;
159
+ sendCardAction(cardId, { type: "sendMessage", value: "\u6211\u8981\u5165\u4F1A", visible: true });
160
+ };
161
+ const parkingMeta = [
162
+ data.entryAtText ? `\u5165\u573A ${data.entryAtText}` : void 0,
163
+ data.durationText ? `\u5DF2\u505C ${data.durationText}` : void 0
164
+ ].filter(Boolean).join(" \xB7 ");
165
+ return /* @__PURE__ */ jsxs("section", { className: "parking-payment", children: [
166
+ /* @__PURE__ */ jsxs("header", { className: "parking-payment__hero", children: [
167
+ /* @__PURE__ */ jsx(
168
+ "img",
169
+ {
170
+ className: "parking-payment__hero-image",
171
+ src: parking_guide_hero_pea_v2_default,
172
+ alt: "",
173
+ "aria-hidden": "true"
174
+ }
175
+ ),
176
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__hero-content", children: [
177
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__hero-eyebrow", children: [
178
+ /* @__PURE__ */ jsx("span", { children: "\u5546\u573A\u505C\u8F66\u670D\u52A1" }),
179
+ isHistory && /* @__PURE__ */ jsx("span", { className: "parking-payment__status", children: "\u5386\u53F2\u62A5\u4EF7" })
180
+ ] }),
181
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__hero-main", children: [
182
+ /* @__PURE__ */ jsx("strong", { children: data.plateNo }),
183
+ /* @__PURE__ */ jsx("span", { children: parkingMeta || "\u505C\u8F66\u8D39\u7528\u4EE5\u5546\u573A\u7CFB\u7EDF\u5B9E\u65F6\u7ED3\u679C\u4E3A\u51C6" })
184
+ ] }),
185
+ /* @__PURE__ */ jsx("div", { className: "parking-payment__hero-actions", children: /* @__PURE__ */ jsxs(
186
+ "button",
187
+ {
188
+ type: "button",
189
+ className: "parking-payment__hero-action",
190
+ disabled: isHistory,
191
+ onClick: () => sendCardAction(cardId, { type: "sendMessage", value: VEHICLE_MANAGE_QUERY }),
192
+ children: [
193
+ /* @__PURE__ */ jsx(Car, { size: 16, weight: "fill" }),
194
+ "\u8F66\u8F86\u7BA1\u7406"
195
+ ]
196
+ }
197
+ ) })
198
+ ] })
199
+ ] }),
200
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__summary", children: [
201
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__summary-item", children: [
202
+ /* @__PURE__ */ jsx("small", { children: "\u5DF2\u505C\u65F6\u957F" }),
203
+ /* @__PURE__ */ jsx("strong", { children: data.durationText ?? "\u2014" })
204
+ ] }),
205
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__summary-item parking-payment__summary-item--benefit", children: [
206
+ /* @__PURE__ */ jsx("small", { children: "\u4F18\u60E0\u51CF\u514D" }),
207
+ /* @__PURE__ */ jsx("strong", { children: discountText ?? "\u2014" })
208
+ ] }),
209
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__summary-item parking-payment__summary-item--amount", children: [
210
+ /* @__PURE__ */ jsx("small", { children: "\u5F53\u524D\u5E94\u4ED8" }),
211
+ /* @__PURE__ */ jsx("strong", { children: data.payableText })
212
+ ] })
213
+ ] }),
214
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__body", children: [
215
+ /* @__PURE__ */ jsxs("section", { className: "parking-payment__billing", children: [
216
+ /* @__PURE__ */ jsx("header", { className: "parking-payment__billing-head", children: /* @__PURE__ */ jsxs("div", { children: [
217
+ /* @__PURE__ */ jsx("span", { className: "parking-payment__billing-icon", children: /* @__PURE__ */ jsx(CurrencyCircleDollar, { weight: "duotone", size: 18 }) }),
218
+ /* @__PURE__ */ jsx("h4", { children: "\u505C\u8F66\u8D39\u7528" })
219
+ ] }) }),
220
+ /* @__PURE__ */ jsxs("dl", { className: "parking-payment__fees", children: [
221
+ data.feeItems.map((f) => /* @__PURE__ */ jsxs("div", { className: "parking-payment__fee", children: [
222
+ /* @__PURE__ */ jsx("dt", { children: f.name }),
223
+ /* @__PURE__ */ jsx("dd", { children: f.amountText })
224
+ ] }, f.name)),
225
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__fee", children: [
226
+ /* @__PURE__ */ jsx("dt", { children: "\u505C\u8F66\u603B\u8D39\u7528" }),
227
+ /* @__PURE__ */ jsx("dd", { children: data.totalText })
228
+ ] }),
229
+ autoAppliedBenefits.map((benefit) => /* @__PURE__ */ jsxs("div", { className: "parking-payment__fee parking-payment__fee--discount", children: [
230
+ /* @__PURE__ */ jsx("dt", { children: benefit.title }),
231
+ /* @__PURE__ */ jsx("dd", { children: formatDiscountText(benefit.discountText) ?? "\u5DF2\u751F\u6548" })
232
+ ] }, benefit.benefitRef)),
233
+ discountText && /* @__PURE__ */ jsxs("div", { className: "parking-payment__fee parking-payment__fee--discount", children: [
234
+ /* @__PURE__ */ jsx("dt", { children: "\u4F18\u60E0\u51CF\u514D" }),
235
+ /* @__PURE__ */ jsx("dd", { children: discountText })
236
+ ] })
237
+ ] }),
238
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__billing-total", children: [
239
+ /* @__PURE__ */ jsx("strong", { children: "\u5F53\u524D\u5E94\u4ED8" }),
240
+ /* @__PURE__ */ jsx("b", { children: data.payableText })
241
+ ] })
242
+ ] }),
243
+ selectable.length > 0 && !isFreeOfCharge && /* @__PURE__ */ jsxs("section", { className: "parking-payment__benefit-picker", "aria-label": "\u505C\u8F66\u4F18\u60E0\u9009\u62E9", children: [
244
+ /* @__PURE__ */ jsxs("div", { className: "parking-payment__benefit-picker-head", children: [
245
+ /* @__PURE__ */ jsx("h4", { children: "\u4F18\u60E0" }),
246
+ repricing && /* @__PURE__ */ jsx("span", { className: "parking-payment__benefit-repricing", children: "\u91CD\u7B97\u4E2D\u2026" })
247
+ ] }),
248
+ /* @__PURE__ */ jsx("ul", { className: "parking-payment__benefit-options", children: selectable.map((benefit) => {
249
+ const checked = selectedRefs.includes(benefit.benefitRef);
250
+ const applied = appliedBenefits.find((a) => a.benefitRef === benefit.benefitRef);
251
+ const amountText = formatDiscountText(applied?.discountText ?? benefit.discountText);
252
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
253
+ "label",
254
+ {
255
+ className: `parking-payment__benefit-option${checked ? " parking-payment__benefit-option--on" : ""}`,
256
+ children: [
257
+ /* @__PURE__ */ jsx(
258
+ "input",
259
+ {
260
+ type: "checkbox",
261
+ checked,
262
+ disabled: isHistory || repricing || !repriceToken,
263
+ onChange: (e) => toggleBenefit(benefit.benefitRef, e.target.checked)
264
+ }
265
+ ),
266
+ /* @__PURE__ */ jsx("span", { className: "parking-payment__benefit-check", "aria-hidden": "true", children: /* @__PURE__ */ jsx(Check, { size: 14, weight: "bold" }) }),
267
+ /* @__PURE__ */ jsx("span", { className: "parking-payment__benefit-option-copy", children: /* @__PURE__ */ jsx("strong", { children: benefit.title }) }),
268
+ amountText && /* @__PURE__ */ jsx("span", { className: "parking-payment__benefit-amount", children: amountText })
269
+ ]
270
+ }
271
+ ) }, benefit.benefitRef);
272
+ }) }),
273
+ dropNotice && /* @__PURE__ */ jsx("p", { className: "parking-payment__benefit-notice", children: dropNotice })
274
+ ] }),
275
+ (membership?.state === "not_enrolled" || membership?.state === "unauthenticated") && /* @__PURE__ */ jsxs("div", { className: "parking-payment__member-guide", children: [
276
+ /* @__PURE__ */ jsx("span", { className: "parking-payment__member-guide-icon", children: /* @__PURE__ */ jsx(Sparkle, { weight: "fill", size: 20 }) }),
277
+ /* @__PURE__ */ jsxs("div", { children: [
278
+ /* @__PURE__ */ jsx("strong", { children: membership.state === "not_enrolled" ? "\u5165\u4F1A\u540E\u53EF\u4F7F\u7528\u4F1A\u5458\u505C\u8F66\u6743\u76CA" : "\u767B\u5F55\u540E\u67E5\u770B\u4F1A\u5458\u505C\u8F66\u6743\u76CA" }),
279
+ /* @__PURE__ */ jsx("small", { children: "\u6743\u76CA\u4EE5\u5546\u573A\u4F1A\u5458\u4E0E\u505C\u8F66\u7CFB\u7EDF\u5B9E\u65F6\u7ED3\u679C\u4E3A\u51C6" })
280
+ ] }),
281
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: isHistory, onClick: promptMembership, children: membership.state === "not_enrolled" ? "\u7ACB\u5373\u5165\u4F1A" : "\u53BB\u767B\u5F55" })
282
+ ] }),
283
+ /* @__PURE__ */ jsx("div", { className: "parking-payment__actions", children: /* @__PURE__ */ jsxs(
284
+ "button",
285
+ {
286
+ type: "button",
287
+ className: "parking-payment__action parking-payment__action--primary",
288
+ disabled: submitDisabled,
289
+ title: submitTitle,
290
+ onClick: () => submit(submitBenefitRefs),
291
+ children: [
292
+ !isFreeOfCharge && !settlement && !repricing && !payOpening && /* @__PURE__ */ jsx(CurrencyCircleDollar, { weight: "fill", size: 18 }),
293
+ settlement ? settlement.state === "paid" ? "\u5DF2\u5B8C\u6210\u652F\u4ED8" : settlement.state === "failed" ? "\u652F\u4ED8\u672A\u5B8C\u6210" : "\u652F\u4ED8\u5904\u7406\u4E2D" : submitting ? "\u652F\u4ED8\u5904\u7406\u4E2D\u2026" : payOpening ? "\u6B63\u5728\u6253\u5F00\u652F\u4ED8\u9875\u2026" : repricing ? "\u4F18\u60E0\u91CD\u7B97\u4E2D\u2026" : isFreeOfCharge ? "\u65E0\u9700\u652F\u4ED8\u505C\u8F66\u8D39\u7528" : payButtonText
294
+ ]
295
+ }
296
+ ) }),
297
+ settlement && /* @__PURE__ */ jsxs("p", { className: `parking-payment__settlement parking-payment__settlement--${settlement.state}`, children: [
298
+ settlement.state === "paid" ? /* @__PURE__ */ jsx(CheckCircle, { size: 16, weight: "fill" }) : /* @__PURE__ */ jsx(Clock, { size: 16, weight: "fill" }),
299
+ settlement.text
300
+ ] }),
301
+ !confirmToken && !isHistory && !settlement && /* @__PURE__ */ jsx("p", { className: "parking-payment__token-expired", children: "\u652F\u4ED8\u6388\u6743\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u67E5\u8BE2\u505C\u8F66\u8D39\u540E\u518D\u652F\u4ED8" }),
302
+ data.caveats.length > 0 && /* @__PURE__ */ jsxs("footer", { className: "parking-payment__foot", children: [
303
+ /* @__PURE__ */ jsx(ShieldCheck, { size: 14 }),
304
+ data.caveats.join("\uFF1B")
305
+ ] })
306
+ ] })
307
+ ] });
308
+ }
309
+ var parking_payment_default = markSelfRendering(ParkingPaymentCard);
310
+
311
+ // src/client/cards/parking-payment-result/index.tsx
312
+ import { CheckCircle as CheckCircle2, Clock as Clock2, WarningCircle } from "@phosphor-icons/react";
313
+ import { sendCardAction as sendCardAction2, markSelfRendering as markSelfRendering2 } from "@tbox.cn/app-sdk/client";
314
+
315
+ // src/client/cards/view.ts
316
+ import { PARKING_PLATE_PATTERN } from "@tbox.cn/app-contracts-mall";
317
+ function recordStatusText(status, statusText) {
318
+ if (statusText) return statusText;
319
+ switch (status) {
320
+ case "PAID":
321
+ return "\u5DF2\u652F\u4ED8";
322
+ case "REFUNDED":
323
+ return "\u5DF2\u9000\u6B3E";
324
+ case "CLOSED":
325
+ return "\u4EA4\u6613\u5173\u95ED";
326
+ default:
327
+ return "\u5904\u7406\u4E2D";
328
+ }
329
+ }
330
+ function recordStatusClass(status) {
331
+ switch (status) {
332
+ case "PAID":
333
+ return "parking-records__status--paid";
334
+ case "REFUNDED":
335
+ return "parking-records__status--refunded";
336
+ case "CLOSED":
337
+ return "parking-records__status--closed";
338
+ default:
339
+ return "parking-records__status--unknown";
340
+ }
341
+ }
342
+ function plateValid(plate) {
343
+ return PARKING_PLATE_PATTERN.test(plate.trim().toUpperCase());
344
+ }
345
+ function plateParts(plate) {
346
+ const p = plate.trim();
347
+ if (p.length <= 2) return [p, ""];
348
+ return [p.slice(0, 2), p.slice(2)];
349
+ }
350
+ var PLATE_CELL_COUNT = 8;
351
+ function plateCells(plate) {
352
+ const p = plate.trim().toUpperCase();
353
+ return Array.from({ length: PLATE_CELL_COUNT }, (_, i) => p[i] ?? "");
354
+ }
355
+ function normalizePlateInput(raw) {
356
+ return raw.replace(/\s/g, "").toUpperCase().slice(0, PLATE_CELL_COUNT);
357
+ }
358
+ function paymentResultText(status) {
359
+ switch (status) {
360
+ case "PAID":
361
+ return "\u652F\u4ED8\u6210\u529F";
362
+ case "CANCELLED":
363
+ return "\u5DF2\u53D6\u6D88";
364
+ default:
365
+ return "\u786E\u8BA4\u4E2D";
366
+ }
367
+ }
368
+ function paymentResultClass(status) {
369
+ switch (status) {
370
+ case "PAID":
371
+ return "parking-result--paid";
372
+ case "CANCELLED":
373
+ return "parking-result--cancelled";
374
+ default:
375
+ return "parking-result--unknown";
376
+ }
377
+ }
378
+
379
+ // src/client/cards/parking-payment-result/index.tsx
380
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
381
+ var ICONS = { paid: CheckCircle2, cancelled: WarningCircle, unknown: Clock2 };
382
+ function ParkingPaymentResultCard(props) {
383
+ const { data, cardId, isHistory, actionTokens } = props;
384
+ const cls = paymentResultClass(data.status);
385
+ const Icon = ICONS[cls === "parking-result--paid" ? "paid" : cls === "parking-result--cancelled" ? "cancelled" : "unknown"];
386
+ const token = actionTokens?.["parking.refresh-payment"];
387
+ return /* @__PURE__ */ jsxs2("section", { className: `parking-result ${cls}`, children: [
388
+ /* @__PURE__ */ jsxs2("header", { className: "parking-result__head", children: [
389
+ /* @__PURE__ */ jsx2("span", { className: "parking-result__icon", children: /* @__PURE__ */ jsx2(Icon, { size: 30, weight: "fill" }) }),
390
+ /* @__PURE__ */ jsxs2("div", { className: "parking-result__heading", children: [
391
+ /* @__PURE__ */ jsx2("h4", { children: paymentResultText(data.status) }),
392
+ /* @__PURE__ */ jsx2("small", { children: data.message })
393
+ ] })
394
+ ] }),
395
+ data.amountText && /* @__PURE__ */ jsxs2("div", { className: "parking-result__amount-row", children: [
396
+ /* @__PURE__ */ jsx2("b", { className: "parking-result__amount", children: data.amountText }),
397
+ /* @__PURE__ */ jsx2("span", { children: data.status === "PAID" ? "\u5DF2\u652F\u4ED8" : data.status === "CANCELLED" ? "\u672A\u652F\u4ED8" : "\u5F85\u786E\u8BA4" })
398
+ ] }),
399
+ data.leaveNotice && /* @__PURE__ */ jsxs2("p", { className: "parking-result__leave", children: [
400
+ /* @__PURE__ */ jsx2(Clock2, { size: 16, weight: "fill" }),
401
+ data.leaveNotice
402
+ ] }),
403
+ data.details && data.details.length > 0 && /* @__PURE__ */ jsx2("dl", { className: "parking-result__details", children: data.details.map((d) => /* @__PURE__ */ jsxs2("div", { children: [
404
+ /* @__PURE__ */ jsx2("dt", { children: d.label }),
405
+ /* @__PURE__ */ jsx2("dd", { children: d.value })
406
+ ] }, d.label)) }),
407
+ data.retryable && data.paymentRef && !isHistory && /* @__PURE__ */ jsx2(
408
+ "button",
409
+ {
410
+ type: "button",
411
+ className: "parking-result__refresh",
412
+ disabled: !token,
413
+ onClick: () => {
414
+ if (!token || isHistory) return;
415
+ sendCardAction2(
416
+ cardId,
417
+ { type: "moduleAction", actionId: "parking.refresh-payment", contextToken: token },
418
+ { paymentRef: data.paymentRef }
419
+ );
420
+ },
421
+ children: "\u5237\u65B0\u652F\u4ED8\u72B6\u6001"
422
+ }
423
+ )
424
+ ] });
425
+ }
426
+ var parking_payment_result_default = markSelfRendering2(ParkingPaymentResultCard);
427
+
428
+ // src/client/cards/parking-payment-records/index.tsx
429
+ import { useEffect as useEffect2, useId, useRef, useState as useState2 } from "react";
430
+ import { createPortal } from "react-dom";
431
+ import { CaretDown, Receipt, X } from "@phosphor-icons/react";
432
+ import { markSelfRendering as markSelfRendering3, sendCardAction as sendCardAction3 } from "@tbox.cn/app-sdk/client";
433
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
434
+ var PAGE_SIZE = 5;
435
+ function RecordDetailSheet(props) {
436
+ const { open, record, isHistory, cardId, invoiceToken, onClose } = props;
437
+ const panelRef = useRef(null);
438
+ const closeButtonRef = useRef(null);
439
+ const titleId = useId();
440
+ useEffect2(() => {
441
+ if (!open || !record) return;
442
+ const previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
443
+ const previousOverflow = document.body.style.overflow;
444
+ document.body.style.overflow = "hidden";
445
+ closeButtonRef.current?.focus();
446
+ const onKeyDown = (event) => {
447
+ if (event.key === "Escape") onCloseRef.current();
448
+ };
449
+ const onCloseRef = { current: onClose };
450
+ document.addEventListener("keydown", onKeyDown);
451
+ return () => {
452
+ document.removeEventListener("keydown", onKeyDown);
453
+ document.body.style.overflow = previousOverflow;
454
+ previousFocus?.focus();
455
+ };
456
+ }, [open]);
457
+ if (!open || !record || typeof document === "undefined") return null;
458
+ const act = (actionId, recordRef, token) => {
459
+ if (!token || !cardId || isHistory) return;
460
+ sendCardAction3(
461
+ cardId,
462
+ { type: "moduleAction", actionId, contextToken: token },
463
+ { recordRef: String(recordRef) }
464
+ );
465
+ };
466
+ return createPortal(
467
+ /* @__PURE__ */ jsxs3("div", { className: "parking-sheet", role: "presentation", children: [
468
+ /* @__PURE__ */ jsx3("div", { className: "parking-sheet__mask", "aria-hidden": "true", onClick: onClose }),
469
+ /* @__PURE__ */ jsxs3(
470
+ "section",
471
+ {
472
+ ref: panelRef,
473
+ className: "parking-sheet__panel",
474
+ role: "dialog",
475
+ "aria-modal": "true",
476
+ "aria-labelledby": titleId,
477
+ children: [
478
+ /* @__PURE__ */ jsxs3("header", { className: "parking-sheet__header", children: [
479
+ /* @__PURE__ */ jsx3("h2", { id: titleId, children: "\u8BA2\u5355\u8BE6\u60C5" }),
480
+ /* @__PURE__ */ jsx3(
481
+ "button",
482
+ {
483
+ ref: closeButtonRef,
484
+ type: "button",
485
+ className: "parking-sheet__close",
486
+ "aria-label": "\u5173\u95ED\u8BA2\u5355\u8BE6\u60C5",
487
+ onClick: onClose,
488
+ children: /* @__PURE__ */ jsx3(X, { size: 20, weight: "bold" })
489
+ }
490
+ )
491
+ ] }),
492
+ /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__body", children: [
493
+ /* @__PURE__ */ jsx3("div", { className: "parking-sheet__plate", children: /* @__PURE__ */ jsxs3("span", { className: "parking-plate", children: [
494
+ /* @__PURE__ */ jsx3("b", { children: plateParts(record.plateNo)[0] }),
495
+ /* @__PURE__ */ jsx3("span", { children: plateParts(record.plateNo)[1] })
496
+ ] }) }),
497
+ /* @__PURE__ */ jsxs3("dl", { className: "parking-sheet__facts", children: [
498
+ /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
499
+ /* @__PURE__ */ jsx3("dt", { children: "\u8BA2\u5355\u53F7" }),
500
+ /* @__PURE__ */ jsx3("dd", { children: record.recordRef })
501
+ ] }),
502
+ /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
503
+ /* @__PURE__ */ jsx3("dt", { children: "\u91D1\u989D" }),
504
+ /* @__PURE__ */ jsx3("dd", { children: record.amountText })
505
+ ] }),
506
+ /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
507
+ /* @__PURE__ */ jsx3("dt", { children: "\u72B6\u6001" }),
508
+ /* @__PURE__ */ jsx3("dd", { className: recordStatusClass(record.status), children: recordStatusText(record.status, record.statusText) })
509
+ ] }),
510
+ record.paidAtText && /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
511
+ /* @__PURE__ */ jsx3("dt", { children: "\u652F\u4ED8\u65F6\u95F4" }),
512
+ /* @__PURE__ */ jsx3("dd", { children: record.paidAtText })
513
+ ] }),
514
+ record.plazaName && /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
515
+ /* @__PURE__ */ jsx3("dt", { children: "\u5E7F\u573A" }),
516
+ /* @__PURE__ */ jsx3("dd", { children: record.plazaName })
517
+ ] }),
518
+ record.parkName && /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
519
+ /* @__PURE__ */ jsx3("dt", { children: "\u505C\u8F66\u573A" }),
520
+ /* @__PURE__ */ jsx3("dd", { children: record.parkName })
521
+ ] }),
522
+ record.entryAtText && /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
523
+ /* @__PURE__ */ jsx3("dt", { children: "\u5165\u573A\u65F6\u95F4" }),
524
+ /* @__PURE__ */ jsx3("dd", { children: record.entryAtText })
525
+ ] }),
526
+ record.exitAtText && /* @__PURE__ */ jsxs3("div", { className: "parking-sheet__fact-row", children: [
527
+ /* @__PURE__ */ jsx3("dt", { children: "\u51FA\u573A\u65F6\u95F4" }),
528
+ /* @__PURE__ */ jsx3("dd", { children: record.exitAtText })
529
+ ] })
530
+ ] }),
531
+ !isHistory && record.invoiceEligible && !record.invoiceIssued && invoiceToken && /* @__PURE__ */ jsxs3(
532
+ "button",
533
+ {
534
+ type: "button",
535
+ className: "parking-sheet__invoice-btn",
536
+ "data-action-id": "parking.apply-invoice",
537
+ onClick: () => act("parking.apply-invoice", record.recordRef, invoiceToken),
538
+ children: [
539
+ /* @__PURE__ */ jsx3(Receipt, { size: 16 }),
540
+ "\u7533\u8BF7\u5F00\u7968"
541
+ ]
542
+ }
543
+ ),
544
+ !isHistory && record.invoiceIssued && /* @__PURE__ */ jsx3("span", { className: "parking-sheet__invoiced", children: "\u5DF2\u7533\u8BF7\u5F00\u7968" })
545
+ ] })
546
+ ]
547
+ }
548
+ )
549
+ ] }),
550
+ document.body
551
+ );
552
+ }
553
+ function ParkingPaymentRecordsCard(props) {
554
+ const { data, cardId = "", isHistory = false, actionTokens } = props;
555
+ const [expanded, setExpanded] = useState2(false);
556
+ const [selectedRecord, setSelectedRecord] = useState2(null);
557
+ const collapsible = data.items.length > PAGE_SIZE;
558
+ const showAll = isHistory || expanded;
559
+ const visible = collapsible && !showAll ? data.items.slice(0, PAGE_SIZE) : data.items;
560
+ const invoiceToken = actionTokens?.["parking.apply-invoice"];
561
+ return /* @__PURE__ */ jsxs3("section", { className: "parking-records", children: [
562
+ /* @__PURE__ */ jsxs3("header", { className: "parking-records__head", children: [
563
+ /* @__PURE__ */ jsxs3("div", { className: "parking-records__heading", children: [
564
+ /* @__PURE__ */ jsx3("span", { className: "parking-records__head-icon", children: /* @__PURE__ */ jsx3(Receipt, { weight: "duotone", size: 24 }) }),
565
+ /* @__PURE__ */ jsxs3("div", { children: [
566
+ /* @__PURE__ */ jsx3("h4", { children: "\u7F34\u8D39\u8BB0\u5F55" }),
567
+ /* @__PURE__ */ jsx3("p", { children: "\u8FD1 6 \u4E2A\u6708\u505C\u8F66\u7F34\u8D39\u660E\u7EC6" })
568
+ ] })
569
+ ] }),
570
+ /* @__PURE__ */ jsxs3("span", { children: [
571
+ "\u5171 ",
572
+ data.total,
573
+ " \u6761"
574
+ ] })
575
+ ] }),
576
+ visible.length === 0 ? /* @__PURE__ */ jsx3("div", { className: "parking-records__empty", children: "\u6682\u65E0\u7F34\u8D39\u8BB0\u5F55" }) : /* @__PURE__ */ jsx3("ul", { className: "parking-records__list", children: visible.map((r) => /* @__PURE__ */ jsxs3(
577
+ "li",
578
+ {
579
+ className: "parking-records__row",
580
+ role: isHistory ? void 0 : "button",
581
+ tabIndex: isHistory ? void 0 : 0,
582
+ onClick: isHistory ? void 0 : () => setSelectedRecord(r),
583
+ onKeyDown: isHistory ? void 0 : (e) => {
584
+ if (e.key === "Enter" || e.key === " ") {
585
+ e.preventDefault();
586
+ setSelectedRecord(r);
587
+ }
588
+ },
589
+ children: [
590
+ /* @__PURE__ */ jsxs3("div", { className: "parking-records__main", children: [
591
+ /* @__PURE__ */ jsxs3("span", { className: "parking-records__plate parking-plate", children: [
592
+ /* @__PURE__ */ jsx3("b", { children: plateParts(r.plateNo)[0] }),
593
+ /* @__PURE__ */ jsx3("span", { children: plateParts(r.plateNo)[1] })
594
+ ] }),
595
+ /* @__PURE__ */ jsxs3("small", { children: [
596
+ r.paidAtText,
597
+ r.parkName ? ` \xB7 ${r.parkName}` : ""
598
+ ] })
599
+ ] }),
600
+ /* @__PURE__ */ jsxs3("div", { className: "parking-records__amount", children: [
601
+ /* @__PURE__ */ jsx3("strong", { children: r.amountText }),
602
+ /* @__PURE__ */ jsx3("em", { className: recordStatusClass(r.status), children: recordStatusText(r.status, r.statusText) })
603
+ ] })
604
+ ]
605
+ },
606
+ r.recordRef
607
+ )) }),
608
+ collapsible && !isHistory && /* @__PURE__ */ jsxs3(
609
+ "button",
610
+ {
611
+ type: "button",
612
+ className: "parking-records__more",
613
+ "aria-expanded": expanded,
614
+ onClick: () => setExpanded((v) => !v),
615
+ children: [
616
+ /* @__PURE__ */ jsx3(CaretDown, { size: 14, "data-rotated": expanded || void 0 }),
617
+ expanded ? "\u6536\u8D77" : `\u67E5\u770B\u5168\u90E8 ${data.items.length} \u6761`
618
+ ]
619
+ }
620
+ ),
621
+ data.caveats.length > 0 && /* @__PURE__ */ jsx3("p", { className: "parking-records__caveats", children: data.caveats.join("\uFF1B") }),
622
+ data.message && /* @__PURE__ */ jsx3("p", { className: "parking-records__message", children: data.message }),
623
+ /* @__PURE__ */ jsx3(
624
+ RecordDetailSheet,
625
+ {
626
+ open: !!selectedRecord,
627
+ record: selectedRecord,
628
+ isHistory,
629
+ cardId,
630
+ invoiceToken,
631
+ onClose: () => setSelectedRecord(null)
632
+ }
633
+ )
634
+ ] });
635
+ }
636
+ var parking_payment_records_default = markSelfRendering3(ParkingPaymentRecordsCard);
637
+
638
+ // src/client/cards/parking-vehicle-management/index.tsx
639
+ import { Fragment, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
640
+ import { Car as Car2, Plus, SealCheck, TrashSimple } from "@phosphor-icons/react";
641
+ import { markSelfRendering as markSelfRendering4, sendCardAction as sendCardAction4 } from "@tbox.cn/app-sdk/client";
642
+ import { TBOX_NOTICE_EVENT_NAME } from "@tbox.cn/app-contracts";
643
+
644
+ // src/client/cards/parking-vehicle-management/plate-keyboard.ts
645
+ var PLATE_PROVINCES = "\u4EAC\u6D25\u6CAA\u6E1D\u5180\u8C6B\u4E91\u8FBD\u9ED1\u6E58\u7696\u9C81\u65B0\u82CF\u6D59\u8D63\u9102\u6842\u7518\u664B\u8499\u9655\u5409\u95FD\u8D35\u7CA4\u9752\u85CF\u5DDD\u5B81\u743C".split("");
646
+ var PLATE_DIGITS = "0123456789".split("");
647
+ var PLATE_LETTERS = "ABCDEFGHJKLMNPQRSTUVWXYZ".split("");
648
+ var PLATE_SPECIAL_LAST = "\u6302\u5B66\u8B66\u6E2F\u6FB3".split("");
649
+ function initialPlateInputState() {
650
+ return { plate: "", panel: "province", cursor: 0 };
651
+ }
652
+ var FIRST_CHAR_SET = /* @__PURE__ */ new Set([
653
+ ...PLATE_PROVINCES,
654
+ ...PLATE_LETTERS,
655
+ ...PLATE_DIGITS,
656
+ ...PLATE_SPECIAL_LAST
657
+ ]);
658
+ var LETTER_SET = new Set(PLATE_LETTERS);
659
+ var DIGIT_SET = new Set(PLATE_DIGITS);
660
+ var SPECIAL_SET = new Set(PLATE_SPECIAL_LAST);
661
+ var isAlnum = (key) => LETTER_SET.has(key) || DIGIT_SET.has(key);
662
+ var MAX_LENGTH = PLATE_CELL_COUNT;
663
+ function panelForPosition(cursor) {
664
+ return cursor === 0 ? "province" : "alnum";
665
+ }
666
+ function isKeyDisabled(state, key) {
667
+ const { cursor } = state;
668
+ if (key === "\u53F0") return true;
669
+ if (cursor >= MAX_LENGTH) return true;
670
+ if (cursor === 0) return !FIRST_CHAR_SET.has(key);
671
+ if (cursor === 1) return !LETTER_SET.has(key);
672
+ if (cursor >= PLATE_CELL_COUNT - 2) {
673
+ return !(isAlnum(key) || SPECIAL_SET.has(key));
674
+ }
675
+ return !isAlnum(key);
676
+ }
677
+ function pressKey(state, key) {
678
+ if (isKeyDisabled(state, key)) return state;
679
+ const { plate, cursor } = state;
680
+ const nextPlate = plate.slice(0, cursor) + key + plate.slice(cursor + 1);
681
+ const nextCursor = Math.min(cursor + 1, MAX_LENGTH);
682
+ return { ...state, plate: nextPlate, cursor: nextCursor, panel: panelForPosition(nextCursor) };
683
+ }
684
+ function pressBackspace(state) {
685
+ const { plate, cursor } = state;
686
+ if (cursor <= 0) return state;
687
+ const nextPlate = plate.slice(0, cursor - 1) + plate.slice(cursor);
688
+ const nextCursor = cursor - 1;
689
+ return { ...state, plate: nextPlate, cursor: nextCursor, panel: panelForPosition(nextCursor) };
690
+ }
691
+ function clickCell(state, index) {
692
+ const cursor = index < state.plate.length ? index : state.plate.length;
693
+ return { ...state, cursor, panel: panelForPosition(cursor) };
694
+ }
695
+ function setPlateFromExternal(raw) {
696
+ const plate = normalizePlateInput(raw);
697
+ return { plate, panel: panelForPosition(plate.length), cursor: plate.length };
698
+ }
699
+ function switchPanel(state, panel) {
700
+ return { ...state, panel };
701
+ }
702
+
703
+ // src/client/cards/parking-vehicle-management/PlateKeyboard.tsx
704
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
705
+ function PlateKeyboard(props) {
706
+ const { state, onKey, onBackspace, onSwitchPanel, onDone } = props;
707
+ const charKey = (key) => /* @__PURE__ */ jsx4(
708
+ "button",
709
+ {
710
+ type: "button",
711
+ className: "parking-kb__key",
712
+ "data-kb-key": key,
713
+ disabled: isKeyDisabled(state, key),
714
+ title: key === "\u53F0" ? "\u6682\u4E0D\u652F\u6301\u53F0\u6E7E\u5730\u533A\u8F66\u724C" : void 0,
715
+ onClick: () => onKey(key),
716
+ children: key
717
+ },
718
+ key
719
+ );
720
+ if (state.panel === "province") {
721
+ return /* @__PURE__ */ jsxs4("div", { className: "parking-kb", role: "group", "aria-label": "\u8F66\u724C\u7701\u4EFD\u952E\u76D8", children: [
722
+ PLATE_PROVINCES.map(charKey),
723
+ /* @__PURE__ */ jsx4(
724
+ "button",
725
+ {
726
+ type: "button",
727
+ className: "parking-kb__key parking-kb__key--fn parking-kb__key--span2",
728
+ "data-kb-action": "letters",
729
+ onClick: () => onSwitchPanel("alnum"),
730
+ children: "\u5B57\u6BCD"
731
+ }
732
+ ),
733
+ /* @__PURE__ */ jsx4(
734
+ "button",
735
+ {
736
+ type: "button",
737
+ className: "parking-kb__key parking-kb__key--fn parking-kb__key--span3",
738
+ "data-kb-action": "backspace",
739
+ "aria-label": "\u9000\u683C",
740
+ onClick: onBackspace,
741
+ children: "\u232B"
742
+ }
743
+ ),
744
+ /* @__PURE__ */ jsx4(
745
+ "button",
746
+ {
747
+ type: "button",
748
+ className: "parking-kb__key parking-kb__key--done parking-kb__key--span4",
749
+ "data-kb-action": "done",
750
+ onClick: onDone,
751
+ children: "\u5B8C\u6210"
752
+ }
753
+ )
754
+ ] });
755
+ }
756
+ return /* @__PURE__ */ jsxs4("div", { className: "parking-kb", role: "group", "aria-label": "\u8F66\u724C\u5B57\u6BCD\u6570\u5B57\u952E\u76D8", children: [
757
+ PLATE_DIGITS.map(charKey),
758
+ PLATE_LETTERS.slice(0, 10).map(charKey),
759
+ PLATE_LETTERS.slice(10, 20).map(charKey),
760
+ [...PLATE_LETTERS.slice(20), ...PLATE_SPECIAL_LAST, "\u53F0"].map(charKey),
761
+ /* @__PURE__ */ jsx4(
762
+ "button",
763
+ {
764
+ type: "button",
765
+ className: "parking-kb__key parking-kb__key--fn parking-kb__key--span3",
766
+ "data-kb-action": "province",
767
+ onClick: () => onSwitchPanel("province"),
768
+ children: "\u7701\u4EFD"
769
+ }
770
+ ),
771
+ /* @__PURE__ */ jsx4(
772
+ "button",
773
+ {
774
+ type: "button",
775
+ className: "parking-kb__key parking-kb__key--fn parking-kb__key--span3",
776
+ "data-kb-action": "backspace",
777
+ "aria-label": "\u9000\u683C",
778
+ onClick: onBackspace,
779
+ children: "\u232B"
780
+ }
781
+ ),
782
+ /* @__PURE__ */ jsx4(
783
+ "button",
784
+ {
785
+ type: "button",
786
+ className: "parking-kb__key parking-kb__key--done parking-kb__key--span4",
787
+ "data-kb-action": "done",
788
+ onClick: onDone,
789
+ children: "\u5B8C\u6210"
790
+ }
791
+ )
792
+ ] });
793
+ }
794
+
795
+ // src/client/cards/parking-vehicle-management/index.tsx
796
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
797
+ var MAX_BOUND_VEHICLES = 3;
798
+ function ParkingVehicleManagementCard(props) {
799
+ const { data, cardId, isHistory, actionTokens } = props;
800
+ const [plate, setPlate] = useState3("");
801
+ const [plateFocused, setPlateFocused] = useState3(false);
802
+ const [kb, setKb] = useState3(initialPlateInputState);
803
+ const [kbOpen, setKbOpen] = useState3(false);
804
+ const [composing, setComposing] = useState3(false);
805
+ const plateInputRef = useRef2(null);
806
+ const [bindingAction, setBindingAction] = useState3(null);
807
+ const [unbindingRefs, setUnbindingRefs] = useState3(/* @__PURE__ */ new Set());
808
+ const bindToken = actionTokens?.["parking.bind-vehicle"];
809
+ const unbindToken = actionTokens?.["parking.unbind-vehicle"];
810
+ const valid = plateValid(plate);
811
+ const isBindingPending = bindingAction !== null;
812
+ const boundLimit = data.bound.length >= MAX_BOUND_VEHICLES;
813
+ useEffect3(() => {
814
+ setBindingAction(null);
815
+ setUnbindingRefs(/* @__PURE__ */ new Set());
816
+ setComposing(false);
817
+ setPlate("");
818
+ setKb(initialPlateInputState());
819
+ setKbOpen(false);
820
+ }, [actionTokens]);
821
+ useEffect3(() => {
822
+ const onNotice = (e) => {
823
+ const n = e.detail;
824
+ if (n?.surfaceId && n.surfaceId !== cardId) return;
825
+ setBindingAction(null);
826
+ setUnbindingRefs(/* @__PURE__ */ new Set());
827
+ };
828
+ window.addEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
829
+ return () => window.removeEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
830
+ }, [cardId]);
831
+ const isEmpty = data.bound.length === 0;
832
+ useEffect3(() => {
833
+ if (isEmpty && !isHistory) {
834
+ requestAnimationFrame(() => openH5Keyboard());
835
+ }
836
+ }, []);
837
+ const applyKb = (next) => {
838
+ setKb(next);
839
+ setPlate(next.plate);
840
+ };
841
+ const openH5Keyboard = () => {
842
+ setKb((prev) => prev.plate === plate ? prev : setPlateFromExternal(plate));
843
+ setKbOpen(true);
844
+ };
845
+ const handleCellsClick = (i) => {
846
+ if (isHistory) return;
847
+ if (kbOpen) {
848
+ applyKb(clickCell(kb, i));
849
+ return;
850
+ }
851
+ openH5Keyboard();
852
+ };
853
+ const handlePlateInputFocus = () => {
854
+ openH5Keyboard();
855
+ };
856
+ const cells = plateCells(plate);
857
+ const activeCell = kbOpen ? kb.cursor : plateFocused ? Math.min(plate.length, PLATE_CELL_COUNT - 1) : -1;
858
+ const renderPlateField = () => /* @__PURE__ */ jsxs5("div", { className: "parking-vm__plate-field", children: [
859
+ /* @__PURE__ */ jsx5("span", { className: "parking-vm__plate-label", children: "\u8F66\u724C" }),
860
+ /* @__PURE__ */ jsxs5("div", { className: "parking-vm__plate-cells", children: [
861
+ /* @__PURE__ */ jsx5(
862
+ "input",
863
+ {
864
+ ref: plateInputRef,
865
+ className: "parking-vm__plate-native",
866
+ value: plate,
867
+ maxLength: PLATE_CELL_COUNT,
868
+ autoCapitalize: "characters",
869
+ autoCorrect: "off",
870
+ autoComplete: "off",
871
+ spellCheck: false,
872
+ inputMode: "text",
873
+ "aria-label": "\u8F66\u724C\u53F7",
874
+ onChange: (e) => {
875
+ const next = normalizePlateInput(e.target.value);
876
+ setPlate(next);
877
+ setKb(setPlateFromExternal(next));
878
+ },
879
+ onFocus: () => {
880
+ setPlateFocused(true);
881
+ void handlePlateInputFocus();
882
+ },
883
+ onBlur: () => setPlateFocused(false)
884
+ }
885
+ ),
886
+ cells.map((ch, i) => {
887
+ const active = (kbOpen || plateFocused) && i === activeCell;
888
+ return /* @__PURE__ */ jsxs5(Fragment, { children: [
889
+ i === 2 && /* @__PURE__ */ jsx5("i", { className: "parking-vm__plate-dot", "aria-hidden": "true" }),
890
+ /* @__PURE__ */ jsx5(
891
+ "span",
892
+ {
893
+ className: [
894
+ "parking-vm__plate-cell",
895
+ active ? "parking-vm__plate-cell--active" : ""
896
+ ].filter(Boolean).join(" "),
897
+ onClick: () => handleCellsClick(i),
898
+ children: ch
899
+ }
900
+ )
901
+ ] }, i);
902
+ })
903
+ ] })
904
+ ] });
905
+ const act = (actionId, token) => {
906
+ if (!token || !valid || isHistory || isBindingPending) return;
907
+ setBindingAction("bind");
908
+ sendCardAction4(
909
+ cardId,
910
+ { type: "moduleAction", actionId, contextToken: token },
911
+ { plateNo: plate }
912
+ );
913
+ };
914
+ const vehicleAction = (actionId, vehicleRef, token) => {
915
+ if (!token || isHistory || unbindingRefs.has(vehicleRef)) return;
916
+ setUnbindingRefs((prev) => /* @__PURE__ */ new Set([...prev, vehicleRef]));
917
+ sendCardAction4(
918
+ cardId,
919
+ { type: "moduleAction", actionId, contextToken: token },
920
+ { vehicleRef }
921
+ );
922
+ };
923
+ const showCompose = isEmpty || composing;
924
+ const canCancel = !isEmpty;
925
+ const showEnrollGuide = data.membership?.state === "not_enrolled" && !isHistory;
926
+ return /* @__PURE__ */ jsxs5("section", { className: `parking-vm${showCompose ? " parking-vm--composing" : ""}`, children: [
927
+ /* @__PURE__ */ jsxs5("header", { className: "parking-vm__head", children: [
928
+ /* @__PURE__ */ jsx5("span", { className: "parking-vm__head-icon", children: /* @__PURE__ */ jsx5(Car2, { weight: "duotone", size: 24 }) }),
929
+ /* @__PURE__ */ jsxs5("div", { className: "parking-vm__heading", children: [
930
+ /* @__PURE__ */ jsx5("h4", { children: showCompose ? "\u6DFB\u52A0\u8F66\u8F86" : "\u6211\u7684\u8F66\u8F86" }),
931
+ /* @__PURE__ */ jsx5("p", { children: "\u8F66\u8F86\u7528\u4E8E\u7F34\u8D39\u4E0E\u6743\u76CA\u6298\u6263" })
932
+ ] }),
933
+ showCompose ? canCancel && /* @__PURE__ */ jsx5(
934
+ "button",
935
+ {
936
+ type: "button",
937
+ className: "parking-vm__head-btn",
938
+ onClick: () => {
939
+ setComposing(false);
940
+ setPlate("");
941
+ setKb(initialPlateInputState());
942
+ setKbOpen(false);
943
+ setBindingAction(null);
944
+ },
945
+ children: "\u53D6\u6D88"
946
+ }
947
+ ) : !isHistory && /* @__PURE__ */ jsxs5(
948
+ "button",
949
+ {
950
+ type: "button",
951
+ className: "parking-vm__head-btn parking-vm__head-btn--add",
952
+ disabled: !bindToken || boundLimit,
953
+ title: boundLimit ? "\u6700\u591A\u7ED1\u5B9A 3 \u8F86\u8F66" : void 0,
954
+ onClick: () => {
955
+ setComposing(true);
956
+ requestAnimationFrame(() => {
957
+ openH5Keyboard();
958
+ });
959
+ },
960
+ children: [
961
+ /* @__PURE__ */ jsx5(Plus, { size: 14, weight: "bold" }),
962
+ "\u6DFB\u52A0\u8F66\u8F86"
963
+ ]
964
+ }
965
+ )
966
+ ] }),
967
+ showCompose ? /* @__PURE__ */ jsxs5(Fragment2, { children: [
968
+ renderPlateField(),
969
+ kbOpen && !isHistory && /* @__PURE__ */ jsx5(
970
+ PlateKeyboard,
971
+ {
972
+ state: kb,
973
+ onKey: (key) => applyKb(pressKey(kb, key)),
974
+ onBackspace: () => applyKb(pressBackspace(kb)),
975
+ onSwitchPanel: (panel) => setKb(switchPanel(kb, panel)),
976
+ onDone: () => setKbOpen(false)
977
+ }
978
+ ),
979
+ /* @__PURE__ */ jsxs5(
980
+ "button",
981
+ {
982
+ type: "button",
983
+ className: `parking-vm__primary-btn parking-payment__action parking-payment__action--primary${bindingAction === "bind" ? " parking-vm__btn--loading" : ""}`,
984
+ disabled: isBindingPending || isHistory || !bindToken || !valid,
985
+ onClick: () => act("parking.bind-vehicle", bindToken),
986
+ children: [
987
+ bindingAction === "bind" && /* @__PURE__ */ jsx5("span", { className: "parking-vm__spinner", "aria-hidden": "true" }),
988
+ bindingAction === "bind" ? "\u7ED1\u5B9A\u4E2D\u2026" : "\u786E\u8BA4\u7ED1\u5B9A"
989
+ ]
990
+ }
991
+ )
992
+ ] }) : /* @__PURE__ */ jsxs5(Fragment2, { children: [
993
+ isEmpty ? /* @__PURE__ */ jsx5("p", { className: "parking-vm__empty", children: "\u8FD8\u6CA1\u6709\u7ED1\u5B9A\u8F66\u8F86" }) : /* @__PURE__ */ jsx5("ul", { className: "parking-vm__bound", children: data.bound.map((v) => {
994
+ const isUnbinding = unbindingRefs.has(v.vehicleRef);
995
+ const [prefix, rest] = plateParts(v.plateNo);
996
+ return /* @__PURE__ */ jsxs5("li", { className: "parking-vm__vehicle", children: [
997
+ /* @__PURE__ */ jsx5("span", { className: "parking-vm__vehicle-icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx5(Car2, { size: 19, weight: "fill" }) }),
998
+ /* @__PURE__ */ jsxs5("span", { className: "parking-vm__vehicle-copy", children: [
999
+ /* @__PURE__ */ jsxs5("span", { className: "parking-plate", children: [
1000
+ /* @__PURE__ */ jsx5("b", { children: prefix }),
1001
+ rest && /* @__PURE__ */ jsx5("i", { className: "parking-plate__sep", "aria-hidden": "true", children: "\xB7" }),
1002
+ /* @__PURE__ */ jsx5("span", { children: rest })
1003
+ ] }),
1004
+ v.parked === true && /* @__PURE__ */ jsx5("em", { className: "parking-vm__vehicle-state", children: "\u5DF2\u5165\u573A" })
1005
+ ] }),
1006
+ /* @__PURE__ */ jsx5("div", { className: "parking-vm__vehicle-actions", children: /* @__PURE__ */ jsx5(
1007
+ "button",
1008
+ {
1009
+ type: "button",
1010
+ "data-action-id": "parking.unbind-vehicle",
1011
+ disabled: isHistory || isUnbinding || !unbindToken,
1012
+ className: isUnbinding ? "parking-vm__btn--loading" : "",
1013
+ onClick: () => vehicleAction("parking.unbind-vehicle", v.vehicleRef, unbindToken),
1014
+ title: "\u5220\u9664\u8F66\u8F86",
1015
+ "aria-label": `\u5220\u9664\u8F66\u724C ${v.plateNo}`,
1016
+ children: isUnbinding ? /* @__PURE__ */ jsx5("span", { className: "parking-vm__spinner", "aria-hidden": "true" }) : /* @__PURE__ */ jsx5(TrashSimple, { size: 16, weight: "fill" })
1017
+ }
1018
+ ) })
1019
+ ] }, v.vehicleRef);
1020
+ }) }),
1021
+ showEnrollGuide && /* @__PURE__ */ jsxs5("div", { className: "parking-vm__enroll", children: [
1022
+ /* @__PURE__ */ jsx5("span", { className: "parking-vm__enroll-icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx5(SealCheck, { size: 22, weight: "fill" }) }),
1023
+ /* @__PURE__ */ jsxs5("div", { className: "parking-vm__enroll-copy", children: [
1024
+ /* @__PURE__ */ jsx5("strong", { children: "\u5165\u4F1A\u4EAB\u505C\u8F66\u6743\u76CA" }),
1025
+ /* @__PURE__ */ jsx5("small", { children: "\u79EF\u5206\u53EF\u62B5\u6263\u505C\u8F66\u8D39\uFF0C\u4F1A\u5458\u53E6\u4EAB\u6298\u6263" })
1026
+ ] }),
1027
+ /* @__PURE__ */ jsx5(
1028
+ "button",
1029
+ {
1030
+ type: "button",
1031
+ className: "parking-vm__enroll-btn",
1032
+ onClick: () => sendCardAction4(cardId, { type: "sendMessage", value: "\u6211\u8981\u5165\u4F1A", visible: true }),
1033
+ children: "\u7ACB\u5373\u5165\u4F1A"
1034
+ }
1035
+ )
1036
+ ] })
1037
+ ] })
1038
+ ] });
1039
+ }
1040
+ var parking_vehicle_management_default = markSelfRendering4(ParkingVehicleManagementCard);
1041
+
1042
+ // src/client/cards/parking-info/index.tsx
1043
+ import { Coins, Info, MapPin } from "@phosphor-icons/react";
1044
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1045
+ var KIND_META = {
1046
+ chargeRules: { subtitle: "\u5546\u573A\u505C\u8F66\u8BA1\u8D39\u6807\u51C6", Icon: Coins },
1047
+ benefitPolicy: { subtitle: "\u4F1A\u5458\u53EF\u4EAB\u7684\u505C\u8F66\u4F18\u60E0", Icon: Info },
1048
+ vehicleLocation: { subtitle: "\u6309\u697C\u5C42\u4E0E\u533A\u57DF\u6307\u5F15\u53D6\u8F66", Icon: MapPin }
1049
+ };
1050
+ function ParkingInfoCard(props) {
1051
+ const { data } = props;
1052
+ const { subtitle, Icon } = KIND_META[data.kind];
1053
+ return /* @__PURE__ */ jsxs6("section", { className: "parking-info", children: [
1054
+ /* @__PURE__ */ jsxs6("header", { className: "parking-info__head", children: [
1055
+ /* @__PURE__ */ jsx6("span", { className: "parking-info__head-icon", children: /* @__PURE__ */ jsx6(Icon, { weight: "duotone", size: 24 }) }),
1056
+ /* @__PURE__ */ jsxs6("div", { className: "parking-info__heading", children: [
1057
+ /* @__PURE__ */ jsx6("h4", { children: data.title }),
1058
+ /* @__PURE__ */ jsx6("p", { children: subtitle })
1059
+ ] })
1060
+ ] }),
1061
+ /* @__PURE__ */ jsx6("dl", { className: "parking-info__entries", children: data.entries.map((e) => /* @__PURE__ */ jsxs6("div", { className: "parking-info__entry", children: [
1062
+ /* @__PURE__ */ jsx6("dt", { children: e.label }),
1063
+ /* @__PURE__ */ jsx6("dd", { children: e.value })
1064
+ ] }, e.label)) })
1065
+ ] });
1066
+ }
1067
+ var parking_info_default = ParkingInfoCard;
1068
+
1069
+ // src/client/index.ts
1070
+ var cards = {
1071
+ "parking-payment": parking_payment_default,
1072
+ "parking-payment-result": parking_payment_result_default,
1073
+ "parking-payment-records": parking_payment_records_default,
1074
+ "parking-vehicle-management": parking_vehicle_management_default,
1075
+ "parking-info": parking_info_default
1076
+ };
1077
+ var clientModule = {
1078
+ cards,
1079
+ register(ctx) {
1080
+ ctx.cards.registerMap(cards);
1081
+ }
1082
+ };
1083
+
1084
+ export {
1085
+ cards,
1086
+ clientModule
1087
+ };