@tetsuo-ai/marketplace-react 0.1.0

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 (112) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +21 -0
  3. package/README.md +172 -0
  4. package/dist/chunk-5OTKSRHM.js +128 -0
  5. package/dist/chunk-5OTKSRHM.js.map +1 -0
  6. package/dist/chunk-ABS77JB2.js +94 -0
  7. package/dist/chunk-ABS77JB2.js.map +1 -0
  8. package/dist/chunk-GN5DYVN5.js +35 -0
  9. package/dist/chunk-GN5DYVN5.js.map +1 -0
  10. package/dist/chunk-KJMR6OGC.js +1198 -0
  11. package/dist/chunk-KJMR6OGC.js.map +1 -0
  12. package/dist/chunk-YORZNYZZ.js +107 -0
  13. package/dist/chunk-YORZNYZZ.js.map +1 -0
  14. package/dist/components/agenc-components.css +570 -0
  15. package/dist/components/index.cjs +1335 -0
  16. package/dist/components/index.cjs.map +1 -0
  17. package/dist/components/index.d.cts +5 -0
  18. package/dist/components/index.d.ts +5 -0
  19. package/dist/components/index.js +5 -0
  20. package/dist/components/index.js.map +1 -0
  21. package/dist/hooks/index.cjs +493 -0
  22. package/dist/hooks/index.cjs.map +1 -0
  23. package/dist/hooks/index.d.cts +294 -0
  24. package/dist/hooks/index.d.ts +294 -0
  25. package/dist/hooks/index.js +339 -0
  26. package/dist/hooks/index.js.map +1 -0
  27. package/dist/index-BLrlBVj-.d.cts +1129 -0
  28. package/dist/index-CKTYsNPH.d.ts +1129 -0
  29. package/dist/index.cjs +1690 -0
  30. package/dist/index.cjs.map +1 -0
  31. package/dist/index.d.cts +235 -0
  32. package/dist/index.d.ts +235 -0
  33. package/dist/index.js +127 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/signers/index.cjs +166 -0
  36. package/dist/signers/index.cjs.map +1 -0
  37. package/dist/signers/index.d.cts +136 -0
  38. package/dist/signers/index.d.ts +136 -0
  39. package/dist/signers/index.js +4 -0
  40. package/dist/signers/index.js.map +1 -0
  41. package/dist/testing/index.cjs +62 -0
  42. package/dist/testing/index.cjs.map +1 -0
  43. package/dist/testing/index.d.cts +71 -0
  44. package/dist/testing/index.d.ts +71 -0
  45. package/dist/testing/index.js +60 -0
  46. package/dist/testing/index.js.map +1 -0
  47. package/dist/theme/agenc-tailwind-preset.cjs +184 -0
  48. package/dist/theme/agenc-tokens.css +132 -0
  49. package/dist/types-jvISR6bc.d.cts +135 -0
  50. package/dist/types-jvISR6bc.d.ts +135 -0
  51. package/dist/useAgentTrackRecord-BLf1nrbu.d.cts +249 -0
  52. package/dist/useAgentTrackRecord-BLf1nrbu.d.ts +249 -0
  53. package/package.json +139 -0
  54. package/src/components/DisputeBanner.stories.tsx +39 -0
  55. package/src/components/DisputeBanner.tsx +110 -0
  56. package/src/components/HireButton.stories.tsx +72 -0
  57. package/src/components/HireButton.tsx +151 -0
  58. package/src/components/HireCheckoutModal.stories.tsx +107 -0
  59. package/src/components/HireCheckoutModal.tsx +284 -0
  60. package/src/components/ListingCard.stories.tsx +55 -0
  61. package/src/components/ListingCard.tsx +148 -0
  62. package/src/components/ListingGrid.stories.tsx +44 -0
  63. package/src/components/ListingGrid.tsx +137 -0
  64. package/src/components/Modal.tsx +121 -0
  65. package/src/components/PoweredByAgenC.tsx +85 -0
  66. package/src/components/ProviderCard.stories.tsx +61 -0
  67. package/src/components/ProviderCard.tsx +154 -0
  68. package/src/components/ReferrerDisclosure.tsx +67 -0
  69. package/src/components/ReviewPanel.stories.tsx +65 -0
  70. package/src/components/ReviewPanel.tsx +141 -0
  71. package/src/components/TaskTimeline.stories.tsx +43 -0
  72. package/src/components/TaskTimeline.tsx +156 -0
  73. package/src/components/__fixtures__/index.tsx +173 -0
  74. package/src/components/agenc-components.css +570 -0
  75. package/src/components/badges.tsx +115 -0
  76. package/src/components/format.ts +150 -0
  77. package/src/components/index.ts +102 -0
  78. package/src/components/primitives.tsx +236 -0
  79. package/src/components/strings.ts +131 -0
  80. package/src/components/useFocusTrap.ts +122 -0
  81. package/src/hooks/index.ts +90 -0
  82. package/src/hooks/internal.ts +70 -0
  83. package/src/hooks/useAgentTrackRecord.ts +166 -0
  84. package/src/hooks/useDispute.ts +130 -0
  85. package/src/hooks/useHire.ts +198 -0
  86. package/src/hooks/useListing.ts +138 -0
  87. package/src/hooks/useListings.ts +133 -0
  88. package/src/hooks/useReferrerEarnings.ts +134 -0
  89. package/src/hooks/useSubmissionReview.ts +179 -0
  90. package/src/hooks/useTaskStatus.ts +192 -0
  91. package/src/hooks/useWalletSigner.ts +99 -0
  92. package/src/index.ts +170 -0
  93. package/src/provider/AgencProvider.tsx +169 -0
  94. package/src/provider/context.ts +35 -0
  95. package/src/provider/index.ts +17 -0
  96. package/src/provider/network.ts +68 -0
  97. package/src/provider/referrer.ts +97 -0
  98. package/src/signers/README.md +130 -0
  99. package/src/signers/embedded-wallet-mock.ts +158 -0
  100. package/src/signers/embedded-wallet.ts +64 -0
  101. package/src/signers/index.ts +48 -0
  102. package/src/signers/strings.ts +39 -0
  103. package/src/signers/types.ts +158 -0
  104. package/src/signers/wallet-account.ts +128 -0
  105. package/src/signers/wallet-adapter.ts +149 -0
  106. package/src/strings/index.ts +119 -0
  107. package/src/testing/index.ts +24 -0
  108. package/src/theme/agenc-tailwind-preset.cjs +184 -0
  109. package/src/theme/agenc-tokens.css +132 -0
  110. package/src/theme/index.ts +94 -0
  111. package/src/transport/index.ts +164 -0
  112. package/src/types.ts +224 -0
@@ -0,0 +1,1335 @@
1
+ 'use strict';
2
+
3
+ var marketplaceSdk = require('@tetsuo-ai/marketplace-sdk');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var react = require('react');
6
+ var reactQuery = require('@tanstack/react-query');
7
+
8
+ // src/theme/index.ts
9
+ var AGENC_THEME_CLASS = "agenc";
10
+
11
+ // src/strings/index.ts
12
+ var EN_STRINGS = {
13
+ // Provider / context wiring errors (developer-facing, but routed for parity).
14
+ "provider.missingContext": "useAgencContext must be used within <AgencProvider>.",
15
+ "provider.missingWriteClient": "No write client is configured. Pass config.client, or config.rpcUrl + config.signer, to <AgencProvider> before using a mutating hook.",
16
+ "provider.missingSigner": "No signer is configured on <AgencProvider>. Connect a wallet or pass config.signer.",
17
+ // Referrer config validation (the P6.2 gate surface).
18
+ "referrer.invalidWallet": "Referrer wallet is not a valid base58 Solana address: {wallet}.",
19
+ "referrer.invalidFeeBps": "Referrer feeBps must be an integer between {min} and {max} (basis points); got {feeBps}.",
20
+ "referrer.notLive": "This site earns a referral fee (pending protocol support).",
21
+ "referrer.notLiveReason": "Referral settlement is not yet deployed on this cluster (PLAN.md P6.2). Referrer config is accepted and validated but not injected into hires.",
22
+ // Read transport.
23
+ "transport.noReadSource": "No read source is configured. Pass an indexer baseUrl, an rpc/queryTransport, to <AgencProvider> or createReadTransport().",
24
+ // Generic loading / empty / error states (components extend these).
25
+ "state.loading": "Loading\u2026",
26
+ "state.empty": "Nothing to show yet.",
27
+ "state.error": "Something went wrong.",
28
+ // Hire flow shells (components fill out the rest).
29
+ "hire.cta": "Hire",
30
+ "hire.pending": "Confirming\u2026",
31
+ "hire.funded": "Escrow funded."
32
+ };
33
+ function t(id, vars, options) {
34
+ const catalog = options?.catalog ?? EN_STRINGS;
35
+ const template = catalog[id] ?? id;
36
+ if (vars === void 0) return template;
37
+ return template.replace(/\{(\w+)\}/g, (match, key) => {
38
+ const value = vars[key];
39
+ return value === void 0 ? match : String(value);
40
+ });
41
+ }
42
+
43
+ // src/components/strings.ts
44
+ var EN_COMPONENT_STRINGS = {
45
+ // Shared / cross-component.
46
+ "components.common.loading": "Loading\u2026",
47
+ "components.common.empty": "Nothing to show yet.",
48
+ "components.common.error": "Something went wrong.",
49
+ "components.common.retry": "Retry",
50
+ "components.common.close": "Close",
51
+ "components.common.verified": "Verified",
52
+ "components.common.unverified": "Unverified",
53
+ "components.common.sol": "SOL",
54
+ "components.common.lamports": "lamports",
55
+ // ListingCard.
56
+ "components.listingCard.priceLabel": "Price",
57
+ "components.listingCard.byProvider": "by {provider}",
58
+ "components.listingCard.untitled": "Untitled service",
59
+ "components.listingCard.hires": "{count} hires",
60
+ "components.listingCard.category": "Category",
61
+ // ListingGrid.
62
+ "components.listingGrid.empty": "No listings match your filters yet.",
63
+ "components.listingGrid.loadMore": "Load more",
64
+ "components.listingGrid.error": "Could not load listings.",
65
+ // HireButton / Checkout.
66
+ "components.hire.cta": "Hire",
67
+ "components.hire.ctaPrice": "Hire \u2014 {price}",
68
+ "components.hire.checkoutTitle": "Confirm hire",
69
+ "components.hire.priceLabel": "You pay",
70
+ "components.hire.escrowNote": "Funds are held in protocol escrow and released to the provider only when you accept the result.",
71
+ "components.hire.confirm": "Confirm and fund escrow",
72
+ "components.hire.cancel": "Cancel",
73
+ "components.hire.pending": "Confirming\u2026",
74
+ "components.hire.success": "Escrow funded.",
75
+ "components.hire.successDetail": "Your task is created. Track it below.",
76
+ "components.hire.viewTask": "View task",
77
+ "components.hire.errorTitle": "Hire failed",
78
+ "components.hire.moderationAttested": "Moderation attested",
79
+ "components.hire.moderationPending": "Moderation pending",
80
+ "components.hire.moderationIssues": "Moderation issues found",
81
+ "components.hire.notConnected": "Connect a wallet to hire.",
82
+ // Referrer disclosure (P6.2 gate — never claims a live fee).
83
+ "components.referrer.disclosure": "This site earns a referral fee.",
84
+ "components.referrer.disclosurePending": "This site earns a referral fee (pending protocol support).",
85
+ "components.referrer.feeBps": "{bps} bps",
86
+ // TaskTimeline.
87
+ "components.taskTimeline.title": "Task progress",
88
+ "components.taskTimeline.empty": "No task to track yet.",
89
+ "components.taskTimeline.status.Open": "Open",
90
+ "components.taskTimeline.status.InProgress": "In progress",
91
+ "components.taskTimeline.status.PendingValidation": "Pending review",
92
+ "components.taskTimeline.status.Completed": "Completed",
93
+ "components.taskTimeline.status.Cancelled": "Cancelled",
94
+ "components.taskTimeline.status.Disputed": "Disputed",
95
+ "components.taskTimeline.status.RejectFrozen": "Rejected (frozen)",
96
+ // ReviewPanel.
97
+ "components.review.title": "Review submission",
98
+ "components.review.noSubmission": "Awaiting the worker's submission.",
99
+ "components.review.accept": "Accept and release escrow",
100
+ "components.review.reject": "Reject",
101
+ "components.review.requestChanges": "Request changes",
102
+ "components.review.accepted": "Result accepted. Escrow released.",
103
+ "components.review.rejected": "Result rejected.",
104
+ "components.review.changesRequested": "Changes requested.",
105
+ "components.review.pending": "Submitting\u2026",
106
+ "components.review.errorTitle": "Review action failed",
107
+ // DisputeBanner.
108
+ "components.dispute.title": "This task is in dispute.",
109
+ "components.dispute.body": "A dispute has been opened. A protocol resolver decides the outcome; funds stay in escrow until then.",
110
+ "components.dispute.initiate": "Open a dispute",
111
+ "components.dispute.pending": "Opening dispute\u2026",
112
+ "components.dispute.opened": "Dispute opened.",
113
+ "components.dispute.none": "No open dispute.",
114
+ "components.dispute.errorTitle": "Could not open dispute",
115
+ // ProviderCard.
116
+ "components.provider.title": "Provider",
117
+ "components.provider.completionRate": "Completion rate",
118
+ "components.provider.disputeRate": "Dispute rate",
119
+ "components.provider.completions": "{count} completed",
120
+ "components.provider.disputes": "{count} disputes",
121
+ "components.provider.provisional": "provisional",
122
+ "components.provider.noData": "No track record yet.",
123
+ "components.provider.unavailable": "Track record is unavailable on this read transport.",
124
+ // PoweredByAgenC.
125
+ "components.poweredBy.label": "Powered by AgenC",
126
+ "components.poweredBy.trustLink": "Learn how this works"
127
+ };
128
+ var COMPONENT_CATALOG = {
129
+ ...EN_STRINGS,
130
+ ...EN_COMPONENT_STRINGS
131
+ };
132
+
133
+ // src/components/format.ts
134
+ function tc(id, vars, options) {
135
+ return t(id, vars, { catalog: COMPONENT_CATALOG, ...options });
136
+ }
137
+ var LAMPORTS_PER_SOL = 1000000000n;
138
+ function formatSol(lamports) {
139
+ const negative = lamports < 0n;
140
+ const abs = negative ? -lamports : lamports;
141
+ const whole = abs / LAMPORTS_PER_SOL;
142
+ const frac = abs % LAMPORTS_PER_SOL;
143
+ let out;
144
+ if (frac === 0n) {
145
+ out = whole.toString();
146
+ } else {
147
+ const fracStr = frac.toString().padStart(9, "0").replace(/0+$/, "");
148
+ out = `${whole.toString()}.${fracStr}`;
149
+ }
150
+ return negative ? `-${out}` : out;
151
+ }
152
+ function formatPriceSol(lamports, options) {
153
+ return `${formatSol(lamports)} ${t("components.common.sol", void 0, {
154
+ catalog: COMPONENT_CATALOG,
155
+ ...options
156
+ })}`;
157
+ }
158
+ function truncateAddress(value, head = 4, tail = 4) {
159
+ if (value === null || value === void 0) return "";
160
+ const s = String(value);
161
+ if (s.length <= head + tail + 1) return s;
162
+ return `${s.slice(0, head)}\u2026${s.slice(-tail)}`;
163
+ }
164
+ function decodeListingName(listing) {
165
+ try {
166
+ return marketplaceSdk.values.decodeListingName(Uint8Array.from(listing.name));
167
+ } catch {
168
+ return "";
169
+ }
170
+ }
171
+ function decodeListingCategory(listing) {
172
+ try {
173
+ return marketplaceSdk.values.decodeListingCategory(Uint8Array.from(listing.category));
174
+ } catch {
175
+ return "";
176
+ }
177
+ }
178
+ function decodeListingTags(listing) {
179
+ try {
180
+ return marketplaceSdk.values.decodeListingTags(Uint8Array.from(listing.tags));
181
+ } catch {
182
+ return [];
183
+ }
184
+ }
185
+ function toHex(bytes) {
186
+ let out = "";
187
+ for (let i = 0; i < bytes.length; i++) {
188
+ out += bytes[i].toString(16).padStart(2, "0");
189
+ }
190
+ return out;
191
+ }
192
+ function formatRate(rate, fallback = "\u2014") {
193
+ if (rate === null || Number.isNaN(rate)) return fallback;
194
+ const pct = Math.round(rate * 100);
195
+ return `${pct}%`;
196
+ }
197
+ function cx(...parts) {
198
+ return parts.filter((p) => Boolean(p)).join(" ");
199
+ }
200
+ function elementClass(base, unstyled, extra) {
201
+ if (unstyled) return extra && extra.trim() !== "" ? extra : void 0;
202
+ return cx(base, extra) || void 0;
203
+ }
204
+ function rootClass(base, unstyled, extra) {
205
+ if (unstyled) return extra && extra.trim() !== "" ? extra : void 0;
206
+ return cx(AGENC_THEME_CLASS, base, extra) || void 0;
207
+ }
208
+ var STATE_STRING = {
209
+ loading: "components.common.loading",
210
+ empty: "components.common.empty",
211
+ error: "components.common.error"
212
+ };
213
+ function StateMessage({
214
+ kind,
215
+ message,
216
+ onRetry,
217
+ role,
218
+ unstyled,
219
+ className
220
+ }) {
221
+ const text = message ?? tc(STATE_STRING[kind]);
222
+ const resolvedRole = role ?? (kind === "error" ? "alert" : "status");
223
+ return /* @__PURE__ */ jsxRuntime.jsxs(
224
+ "div",
225
+ {
226
+ className: elementClass(`agenc-state agenc-state--${kind}`, unstyled, className),
227
+ role: resolvedRole,
228
+ "aria-live": kind === "error" ? "assertive" : "polite",
229
+ "aria-busy": kind === "loading" ? true : void 0,
230
+ children: [
231
+ kind === "loading" ? /* @__PURE__ */ jsxRuntime.jsx(Spinner, { unstyled }) : null,
232
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-state__text", children: text }),
233
+ onRetry && kind !== "loading" ? /* @__PURE__ */ jsxRuntime.jsx(Button, { unstyled, variant: "ghost", onClick: onRetry, children: tc("components.common.retry") }) : null
234
+ ]
235
+ }
236
+ );
237
+ }
238
+ function Spinner({ label, unstyled, className }) {
239
+ return /* @__PURE__ */ jsxRuntime.jsx(
240
+ "span",
241
+ {
242
+ className: elementClass("agenc-spinner", unstyled, className),
243
+ role: "status",
244
+ "aria-live": "polite",
245
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-visually-hidden", children: label ?? tc("components.common.loading") })
246
+ }
247
+ );
248
+ }
249
+ function Badge({
250
+ tone = "neutral",
251
+ children,
252
+ label,
253
+ unstyled,
254
+ className
255
+ }) {
256
+ return /* @__PURE__ */ jsxRuntime.jsx(
257
+ "span",
258
+ {
259
+ className: elementClass(
260
+ `agenc-badge agenc-badge--${tone}`,
261
+ unstyled,
262
+ className
263
+ ),
264
+ title: label,
265
+ "aria-label": label,
266
+ children
267
+ }
268
+ );
269
+ }
270
+ function Button({
271
+ variant = "primary",
272
+ loading = false,
273
+ unstyled,
274
+ className,
275
+ children,
276
+ disabled,
277
+ type,
278
+ ...rest
279
+ }) {
280
+ return /* @__PURE__ */ jsxRuntime.jsxs(
281
+ "button",
282
+ {
283
+ type: type ?? "button",
284
+ className: elementClass(
285
+ `agenc-button agenc-button--${variant}`,
286
+ unstyled,
287
+ className
288
+ ),
289
+ disabled: disabled || loading,
290
+ "aria-busy": loading || void 0,
291
+ ...rest,
292
+ children: [
293
+ loading ? /* @__PURE__ */ jsxRuntime.jsx(Spinner, { unstyled }) : null,
294
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-button__label", children })
295
+ ]
296
+ }
297
+ );
298
+ }
299
+ function moderationStateOf(moderation) {
300
+ if (!moderation) return "pending";
301
+ return moderation.metadataValid ? "attested" : "issues";
302
+ }
303
+ var MODERATION_TONE = {
304
+ attested: "success",
305
+ pending: "neutral",
306
+ issues: "warning"
307
+ };
308
+ var MODERATION_STRING = {
309
+ attested: "components.hire.moderationAttested",
310
+ pending: "components.hire.moderationPending",
311
+ // Distinct from `pending` ("Moderation pending") so a buyer can textually
312
+ // tell "we found problems" apart from "we haven't checked", not just by tone.
313
+ issues: "components.hire.moderationIssues"
314
+ };
315
+ function ModerationBadge({
316
+ moderation,
317
+ state,
318
+ unstyled,
319
+ className
320
+ }) {
321
+ const resolved = state ?? moderationStateOf(moderation);
322
+ const label = tc(MODERATION_STRING[resolved]);
323
+ const issues = resolved === "issues" && moderation?.metadataIssues?.length ? moderation.metadataIssues.join("; ") : void 0;
324
+ return /* @__PURE__ */ jsxRuntime.jsx(
325
+ Badge,
326
+ {
327
+ tone: MODERATION_TONE[resolved],
328
+ unstyled,
329
+ className,
330
+ label: issues ?? label,
331
+ children: label
332
+ }
333
+ );
334
+ }
335
+ function VerifiedBadge({
336
+ verified,
337
+ unstyled,
338
+ className
339
+ }) {
340
+ return /* @__PURE__ */ jsxRuntime.jsx(
341
+ Badge,
342
+ {
343
+ tone: verified ? "success" : "neutral",
344
+ unstyled,
345
+ className,
346
+ children: verified ? tc("components.common.verified") : tc("components.common.unverified")
347
+ }
348
+ );
349
+ }
350
+ var FOCUSABLE_SELECTOR = [
351
+ "a[href]",
352
+ "button:not([disabled])",
353
+ "textarea:not([disabled])",
354
+ "input:not([disabled])",
355
+ "select:not([disabled])",
356
+ '[tabindex]:not([tabindex="-1"])'
357
+ ].join(",");
358
+ function focusableWithin(container) {
359
+ return Array.from(
360
+ container.querySelectorAll(FOCUSABLE_SELECTOR)
361
+ ).filter((el) => el.offsetParent !== null || el === document.activeElement);
362
+ }
363
+ function useFocusTrap(containerRef, active, onEscape) {
364
+ react.useEffect(() => {
365
+ if (!active) return;
366
+ const container = containerRef.current;
367
+ if (!container) return;
368
+ const previouslyFocused = document.activeElement instanceof HTMLElement ? document.activeElement : null;
369
+ const initial = focusableWithin(container)[0] ?? container;
370
+ initial.focus();
371
+ function onKeyDown(event) {
372
+ if (event.key === "Escape") {
373
+ event.stopPropagation();
374
+ onEscape?.();
375
+ return;
376
+ }
377
+ if (event.key !== "Tab") return;
378
+ const focusable = focusableWithin(container);
379
+ if (focusable.length === 0) {
380
+ event.preventDefault();
381
+ container.focus();
382
+ return;
383
+ }
384
+ const first = focusable[0];
385
+ const last = focusable[focusable.length - 1];
386
+ const activeEl = document.activeElement;
387
+ if (event.shiftKey) {
388
+ if (activeEl === first || activeEl === container) {
389
+ event.preventDefault();
390
+ last.focus();
391
+ }
392
+ } else if (activeEl === last) {
393
+ event.preventDefault();
394
+ first.focus();
395
+ }
396
+ }
397
+ function onFocusIn(event) {
398
+ const target = event.target;
399
+ if (!(target instanceof Node)) return;
400
+ if (container.contains(target)) return;
401
+ event.stopPropagation();
402
+ const focusable = focusableWithin(container);
403
+ (focusable[0] ?? container).focus();
404
+ }
405
+ container.addEventListener("keydown", onKeyDown);
406
+ document.addEventListener("focusin", onFocusIn);
407
+ return () => {
408
+ container.removeEventListener("keydown", onKeyDown);
409
+ document.removeEventListener("focusin", onFocusIn);
410
+ previouslyFocused?.focus();
411
+ };
412
+ }, [containerRef, active, onEscape]);
413
+ }
414
+ function Modal({
415
+ open,
416
+ onClose,
417
+ title,
418
+ children,
419
+ footer,
420
+ disableEscapeClose = false,
421
+ disableOverlayClose = false,
422
+ hideCloseButton = false,
423
+ closeLabel,
424
+ unstyled,
425
+ className
426
+ }) {
427
+ const dialogRef = react.useRef(null);
428
+ const titleId = react.useId();
429
+ const bodyId = react.useId();
430
+ useFocusTrap(dialogRef, open, () => {
431
+ if (!disableEscapeClose) onClose();
432
+ });
433
+ if (!open) return null;
434
+ const overlayClass = rootClass("agenc-modal", unstyled, className);
435
+ return /* @__PURE__ */ jsxRuntime.jsx(
436
+ "div",
437
+ {
438
+ className: overlayClass,
439
+ onMouseDown: (event) => {
440
+ if (disableOverlayClose) return;
441
+ if (event.target === event.currentTarget) onClose();
442
+ },
443
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
444
+ "div",
445
+ {
446
+ className: unstyled ? void 0 : "agenc-modal__dialog",
447
+ ref: dialogRef,
448
+ role: "dialog",
449
+ "aria-modal": "true",
450
+ "aria-labelledby": titleId,
451
+ "aria-describedby": bodyId,
452
+ tabIndex: -1,
453
+ children: [
454
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: unstyled ? void 0 : "agenc-modal__header", children: [
455
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { id: titleId, className: unstyled ? void 0 : "agenc-modal__title", children: title }),
456
+ hideCloseButton ? null : /* @__PURE__ */ jsxRuntime.jsx(
457
+ "button",
458
+ {
459
+ type: "button",
460
+ className: unstyled ? void 0 : "agenc-modal__close",
461
+ "aria-label": closeLabel ?? tc("components.common.close"),
462
+ onClick: onClose,
463
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: "\xD7" })
464
+ }
465
+ )
466
+ ] }),
467
+ /* @__PURE__ */ jsxRuntime.jsx("div", { id: bodyId, className: unstyled ? void 0 : "agenc-modal__body", children }),
468
+ footer ? /* @__PURE__ */ jsxRuntime.jsx("footer", { className: unstyled ? void 0 : "agenc-modal__footer", children: footer }) : null
469
+ ]
470
+ }
471
+ )
472
+ }
473
+ );
474
+ }
475
+ function ListingCard({
476
+ listing,
477
+ moderation,
478
+ onHire,
479
+ onSelect,
480
+ hidePrice = false,
481
+ unstyled,
482
+ className
483
+ }) {
484
+ const { account } = listing;
485
+ const name = decodeListingName(account) || tc("components.listingCard.untitled");
486
+ const category = decodeListingCategory(account);
487
+ const price = formatPriceSol(account.price);
488
+ const provider = truncateAddress(account.providerAgent);
489
+ const hires = account.totalHires;
490
+ const cardClass = rootClass("agenc-listing-card", unstyled, className);
491
+ const selectable = Boolean(onSelect);
492
+ const heading = /* @__PURE__ */ jsxRuntime.jsx("h3", { className: unstyled ? void 0 : "agenc-listing-card__title", children: name });
493
+ return /* @__PURE__ */ jsxRuntime.jsxs(
494
+ "article",
495
+ {
496
+ className: cardClass,
497
+ "aria-label": name,
498
+ children: [
499
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: unstyled ? void 0 : "agenc-listing-card__header", children: [
500
+ selectable ? /* @__PURE__ */ jsxRuntime.jsx(
501
+ "button",
502
+ {
503
+ type: "button",
504
+ className: unstyled ? void 0 : "agenc-listing-card__title-button",
505
+ onClick: () => onSelect?.(listing),
506
+ children: heading
507
+ }
508
+ ) : heading,
509
+ /* @__PURE__ */ jsxRuntime.jsx(ModerationBadge, { moderation, unstyled })
510
+ ] }),
511
+ /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: unstyled ? void 0 : "agenc-listing-card__meta", children: [
512
+ category ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-listing-card__meta-row", children: [
513
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: tc("components.listingCard.category") }),
514
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { children: /* @__PURE__ */ jsxRuntime.jsx(Badge, { tone: "info", unstyled, children: category }) })
515
+ ] }) : null,
516
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-listing-card__meta-row", children: [
517
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: tc("components.listingCard.byProvider", { provider }) }),
518
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { children: tc("components.listingCard.hires", { count: String(hires) }) })
519
+ ] })
520
+ ] }),
521
+ /* @__PURE__ */ jsxRuntime.jsxs("footer", { className: unstyled ? void 0 : "agenc-listing-card__footer", children: [
522
+ hidePrice ? null : /* @__PURE__ */ jsxRuntime.jsxs("p", { className: unstyled ? void 0 : "agenc-listing-card__price", children: [
523
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-listing-card__price-label", children: tc("components.listingCard.priceLabel") }),
524
+ " ",
525
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-listing-card__price-value", children: price })
526
+ ] }),
527
+ onHire ? /* @__PURE__ */ jsxRuntime.jsx(
528
+ Button,
529
+ {
530
+ unstyled,
531
+ variant: "primary",
532
+ onClick: () => onHire(listing),
533
+ children: tc("components.hire.cta")
534
+ }
535
+ ) : null
536
+ ] })
537
+ ]
538
+ }
539
+ );
540
+ }
541
+ function ListingGrid({
542
+ listings,
543
+ isLoading = false,
544
+ error = null,
545
+ hasMore = false,
546
+ onLoadMore,
547
+ onRetry,
548
+ onHire,
549
+ onSelect,
550
+ moderationByPda,
551
+ emptyMessage,
552
+ unstyled,
553
+ className
554
+ }) {
555
+ const gridClass = rootClass("agenc-listing-grid", unstyled, className);
556
+ if (error) {
557
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: gridClass, children: /* @__PURE__ */ jsxRuntime.jsx(
558
+ StateMessage,
559
+ {
560
+ kind: "error",
561
+ message: tc("components.listingGrid.error"),
562
+ onRetry,
563
+ unstyled
564
+ }
565
+ ) });
566
+ }
567
+ if (isLoading && listings.length === 0) {
568
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: gridClass, children: /* @__PURE__ */ jsxRuntime.jsx(StateMessage, { kind: "loading", unstyled }) });
569
+ }
570
+ if (listings.length === 0) {
571
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: gridClass, children: /* @__PURE__ */ jsxRuntime.jsx(
572
+ StateMessage,
573
+ {
574
+ kind: "empty",
575
+ message: emptyMessage ?? tc("components.listingGrid.empty"),
576
+ unstyled
577
+ }
578
+ ) });
579
+ }
580
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: gridClass, children: [
581
+ /* @__PURE__ */ jsxRuntime.jsx(
582
+ "ul",
583
+ {
584
+ className: unstyled ? void 0 : "agenc-listing-grid__list",
585
+ children: listings.map((listing) => /* @__PURE__ */ jsxRuntime.jsx(
586
+ "li",
587
+ {
588
+ className: unstyled ? void 0 : "agenc-listing-grid__item",
589
+ children: /* @__PURE__ */ jsxRuntime.jsx(
590
+ ListingCard,
591
+ {
592
+ listing,
593
+ moderation: moderationByPda?.[String(listing.address)] ?? null,
594
+ onHire,
595
+ onSelect,
596
+ unstyled
597
+ }
598
+ )
599
+ },
600
+ String(listing.address)
601
+ ))
602
+ }
603
+ ),
604
+ hasMore && onLoadMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: unstyled ? void 0 : "agenc-listing-grid__more", children: /* @__PURE__ */ jsxRuntime.jsx(
605
+ "button",
606
+ {
607
+ type: "button",
608
+ className: unstyled ? void 0 : "agenc-button agenc-button--secondary",
609
+ onClick: onLoadMore,
610
+ children: tc("components.listingGrid.loadMore")
611
+ }
612
+ ) }) : null
613
+ ] });
614
+ }
615
+ var AgencContext = react.createContext(null);
616
+ AgencContext.displayName = "AgencContext";
617
+ function useAgencContext() {
618
+ const ctx = react.useContext(AgencContext);
619
+ if (ctx === null) {
620
+ throw new Error(t("provider.missingContext"));
621
+ }
622
+ return ctx;
623
+ }
624
+
625
+ // src/hooks/internal.ts
626
+ function requireClient(client) {
627
+ if (client === null) {
628
+ throw new Error(t("provider.missingWriteClient"));
629
+ }
630
+ return client;
631
+ }
632
+
633
+ // src/hooks/useHire.ts
634
+ function useHire() {
635
+ const ctx = useAgencContext();
636
+ const mutation = reactQuery.useMutation({
637
+ mutationFn: async (input) => {
638
+ const client = requireClient(ctx.client);
639
+ const capability = ctx.resolveReferrerCapability();
640
+ const referrerInjected = capability.live && ctx.referrer !== null;
641
+ const creator = input.creator ?? client.signer;
642
+ let signature;
643
+ if (input.humanless === true) {
644
+ const ix = await marketplaceSdk.facade.hireFromListingHumanless({
645
+ ...input,
646
+ creator
647
+ // NOTE: P6.2 referrer fields would spread here under capability.live.
648
+ });
649
+ ({ signature } = await client.send([ix]));
650
+ } else {
651
+ const authority = input.authority ?? client.signer;
652
+ const result = await client.hireFromListing({
653
+ ...input,
654
+ authority,
655
+ creator
656
+ // NOTE: P6.2 referrer fields would spread here under capability.live.
657
+ });
658
+ signature = result.signature;
659
+ }
660
+ const [taskPda] = await marketplaceSdk.findTaskPda({
661
+ creator: typeof creator === "object" && creator !== null && "address" in creator ? creator.address : creator,
662
+ taskId: input.taskId
663
+ });
664
+ return { signature, taskPda, referrerInjected };
665
+ }
666
+ });
667
+ const hire = react.useCallback(
668
+ (input) => mutation.mutateAsync(input),
669
+ [mutation]
670
+ );
671
+ const status = react.useMemo(() => {
672
+ if (mutation.isPending) return "pending";
673
+ if (mutation.isError) return "error";
674
+ if (mutation.isSuccess) return "success";
675
+ return "idle";
676
+ }, [mutation.isPending, mutation.isError, mutation.isSuccess]);
677
+ return {
678
+ hire,
679
+ status,
680
+ taskPda: mutation.data?.taskPda ?? null,
681
+ signature: mutation.data?.signature ?? null,
682
+ error: mutation.error ?? null,
683
+ isPending: mutation.isPending,
684
+ reset: mutation.reset
685
+ };
686
+ }
687
+ function useWalletSigner(options) {
688
+ const ctx = useAgencContext();
689
+ const adapter = options?.adapter;
690
+ const signer = ctx.signer ?? null;
691
+ const connected = adapter !== void 0 ? adapter.connected ?? adapter.signer !== null : ctx.signer !== null;
692
+ const connect = react.useCallback(() => {
693
+ return void 0;
694
+ }, [adapter]);
695
+ return { signer, connected, connect };
696
+ }
697
+ function ReferrerDisclosure({
698
+ referrer,
699
+ live = false,
700
+ showFee = true,
701
+ unstyled,
702
+ className
703
+ }) {
704
+ const text = live ? tc("components.referrer.disclosure") : tc("components.referrer.disclosurePending");
705
+ return /* @__PURE__ */ jsxRuntime.jsxs(
706
+ "p",
707
+ {
708
+ className: unstyled ? className : cx("agenc-referrer-disclosure", className),
709
+ role: "note",
710
+ children: [
711
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: text }),
712
+ showFee ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: unstyled ? void 0 : "agenc-referrer-disclosure__fee", children: [
713
+ " ",
714
+ tc("components.referrer.feeBps", { bps: String(referrer.feeBps) })
715
+ ] }) : null
716
+ ]
717
+ }
718
+ );
719
+ }
720
+ function HireCheckoutModal({
721
+ open,
722
+ onClose,
723
+ listing,
724
+ onConfirm,
725
+ status = "idle",
726
+ error = null,
727
+ taskPda = null,
728
+ onViewTask,
729
+ moderation,
730
+ referrer,
731
+ referrerLive = false,
732
+ connected = true,
733
+ unstyled,
734
+ className
735
+ }) {
736
+ const pending = status === "pending";
737
+ const success = status === "success";
738
+ const price = formatPriceSol(listing.account.price);
739
+ const [submitting, setSubmitting] = react.useState(false);
740
+ const submittingRef = react.useRef(false);
741
+ react.useEffect(() => {
742
+ if (!open || !pending) {
743
+ submittingRef.current = false;
744
+ setSubmitting(false);
745
+ }
746
+ }, [open, pending]);
747
+ const handleConfirm = react.useCallback(() => {
748
+ if (submittingRef.current) return;
749
+ submittingRef.current = true;
750
+ setSubmitting(true);
751
+ let result;
752
+ try {
753
+ result = onConfirm();
754
+ } catch {
755
+ submittingRef.current = false;
756
+ setSubmitting(false);
757
+ return;
758
+ }
759
+ if (result && typeof result.then === "function") {
760
+ void result.finally(() => {
761
+ submittingRef.current = false;
762
+ setSubmitting(false);
763
+ });
764
+ }
765
+ }, [onConfirm]);
766
+ const confirmDisabled = !connected || pending || submitting;
767
+ const lockClose = pending || submitting;
768
+ const footer = success ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
769
+ taskPda && onViewTask ? /* @__PURE__ */ jsxRuntime.jsx(
770
+ Button,
771
+ {
772
+ unstyled,
773
+ variant: "primary",
774
+ onClick: () => onViewTask(taskPda),
775
+ children: tc("components.hire.viewTask")
776
+ }
777
+ ) : null,
778
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { unstyled, variant: "secondary", onClick: onClose, children: tc("components.common.close") })
779
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
780
+ /* @__PURE__ */ jsxRuntime.jsx(
781
+ Button,
782
+ {
783
+ unstyled,
784
+ variant: "secondary",
785
+ onClick: onClose,
786
+ disabled: pending || submitting,
787
+ children: tc("components.hire.cancel")
788
+ }
789
+ ),
790
+ /* @__PURE__ */ jsxRuntime.jsx(
791
+ Button,
792
+ {
793
+ unstyled,
794
+ variant: "primary",
795
+ loading: pending || submitting,
796
+ disabled: confirmDisabled,
797
+ onClick: handleConfirm,
798
+ children: pending || submitting ? tc("components.hire.pending") : tc("components.hire.confirm")
799
+ }
800
+ )
801
+ ] });
802
+ return /* @__PURE__ */ jsxRuntime.jsx(
803
+ Modal,
804
+ {
805
+ open,
806
+ onClose,
807
+ title: tc("components.hire.checkoutTitle"),
808
+ footer,
809
+ disableEscapeClose: lockClose,
810
+ disableOverlayClose: lockClose,
811
+ hideCloseButton: lockClose,
812
+ unstyled,
813
+ className,
814
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-checkout", children: [
815
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-checkout__row", children: [
816
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-checkout__price-label", children: tc("components.hire.priceLabel") }),
817
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-checkout__price", children: price })
818
+ ] }),
819
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: unstyled ? void 0 : "agenc-checkout__moderation", children: /* @__PURE__ */ jsxRuntime.jsx(ModerationBadge, { moderation, unstyled }) }),
820
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: unstyled ? void 0 : "agenc-checkout__escrow-note", children: tc("components.hire.escrowNote") }),
821
+ referrer ? /* @__PURE__ */ jsxRuntime.jsx(
822
+ ReferrerDisclosure,
823
+ {
824
+ referrer,
825
+ live: referrerLive,
826
+ unstyled
827
+ }
828
+ ) : null,
829
+ /* @__PURE__ */ jsxRuntime.jsxs(
830
+ "div",
831
+ {
832
+ className: unstyled ? void 0 : "agenc-checkout__status",
833
+ role: "status",
834
+ "aria-live": "polite",
835
+ children: [
836
+ pending ? tc("components.hire.pending") : null,
837
+ success ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
838
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: tc("components.hire.success") }),
839
+ " ",
840
+ tc("components.hire.successDetail")
841
+ ] }) : null
842
+ ]
843
+ }
844
+ ),
845
+ error ? /* @__PURE__ */ jsxRuntime.jsxs(
846
+ "div",
847
+ {
848
+ className: unstyled ? void 0 : "agenc-checkout__error",
849
+ role: "alert",
850
+ "aria-live": "assertive",
851
+ children: [
852
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: tc("components.hire.errorTitle") }),
853
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: error.message })
854
+ ]
855
+ }
856
+ ) : null,
857
+ !connected && !success ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: unstyled ? void 0 : "agenc-checkout__hint", children: tc("components.hire.notConnected") }) : null
858
+ ] })
859
+ }
860
+ );
861
+ }
862
+ function HireButton({
863
+ listing,
864
+ buildHireInput,
865
+ onHired,
866
+ onViewTask,
867
+ showPriceInLabel = true,
868
+ label,
869
+ unstyled,
870
+ className
871
+ }) {
872
+ const ctx = useAgencContext();
873
+ const { hire, status, error, taskPda, reset } = useHire();
874
+ const { connected } = useWalletSigner();
875
+ const [open, setOpen] = react.useState(false);
876
+ const inFlightRef = react.useRef(false);
877
+ const capability = ctx.resolveReferrerCapability();
878
+ const close = react.useCallback(() => {
879
+ setOpen(false);
880
+ inFlightRef.current = false;
881
+ reset();
882
+ }, [reset]);
883
+ const confirm = react.useCallback(async () => {
884
+ if (inFlightRef.current) return;
885
+ inFlightRef.current = true;
886
+ try {
887
+ const input = buildHireInput(listing);
888
+ const result = await hire(input);
889
+ onHired?.(result.taskPda);
890
+ } finally {
891
+ inFlightRef.current = false;
892
+ }
893
+ }, [buildHireInput, hire, listing, onHired]);
894
+ const buttonLabel = label ?? (showPriceInLabel ? tc("components.hire.ctaPrice", {
895
+ price: formatPriceSol(listing.account.price)
896
+ }) : tc("components.hire.cta"));
897
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
898
+ /* @__PURE__ */ jsxRuntime.jsx(
899
+ Button,
900
+ {
901
+ unstyled,
902
+ className,
903
+ variant: "primary",
904
+ onClick: () => setOpen(true),
905
+ children: buttonLabel
906
+ }
907
+ ),
908
+ /* @__PURE__ */ jsxRuntime.jsx(
909
+ HireCheckoutModal,
910
+ {
911
+ open,
912
+ onClose: close,
913
+ listing,
914
+ onConfirm: confirm,
915
+ status,
916
+ error,
917
+ taskPda,
918
+ onViewTask,
919
+ referrer: ctx.referrer,
920
+ referrerLive: capability.live,
921
+ connected,
922
+ unstyled
923
+ }
924
+ )
925
+ ] });
926
+ }
927
+ var HAPPY_PATH = [
928
+ { status: marketplaceSdk.TaskStatus.Open, stringId: "components.taskTimeline.status.Open" },
929
+ {
930
+ status: marketplaceSdk.TaskStatus.InProgress,
931
+ stringId: "components.taskTimeline.status.InProgress"
932
+ },
933
+ {
934
+ status: marketplaceSdk.TaskStatus.PendingValidation,
935
+ stringId: "components.taskTimeline.status.PendingValidation"
936
+ },
937
+ {
938
+ status: marketplaceSdk.TaskStatus.Completed,
939
+ stringId: "components.taskTimeline.status.Completed"
940
+ }
941
+ ];
942
+ var OFF_PATH = {
943
+ [marketplaceSdk.TaskStatus.Cancelled]: {
944
+ stringId: "components.taskTimeline.status.Cancelled",
945
+ tone: "cancelled"
946
+ },
947
+ [marketplaceSdk.TaskStatus.Disputed]: {
948
+ stringId: "components.taskTimeline.status.Disputed",
949
+ tone: "disputed"
950
+ },
951
+ [marketplaceSdk.TaskStatus.RejectFrozen]: {
952
+ stringId: "components.taskTimeline.status.RejectFrozen",
953
+ tone: "rejected"
954
+ }
955
+ };
956
+ function happyIndex(status) {
957
+ return HAPPY_PATH.findIndex((s) => s.status === status);
958
+ }
959
+ function TaskTimeline({
960
+ status,
961
+ isLoading = false,
962
+ error = null,
963
+ onRetry,
964
+ unstyled,
965
+ className
966
+ }) {
967
+ const timelineClass = rootClass("agenc-timeline", unstyled, className);
968
+ if (error) {
969
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: timelineClass, children: /* @__PURE__ */ jsxRuntime.jsx(StateMessage, { kind: "error", onRetry, unstyled }) });
970
+ }
971
+ if (isLoading && status === null) {
972
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: timelineClass, children: /* @__PURE__ */ jsxRuntime.jsx(StateMessage, { kind: "loading", unstyled }) });
973
+ }
974
+ if (status === null) {
975
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: timelineClass, children: /* @__PURE__ */ jsxRuntime.jsx(
976
+ StateMessage,
977
+ {
978
+ kind: "empty",
979
+ message: tc("components.taskTimeline.empty"),
980
+ unstyled
981
+ }
982
+ ) });
983
+ }
984
+ const offPath = OFF_PATH[status];
985
+ const currentIndex = offPath ? -1 : happyIndex(status);
986
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: timelineClass, "aria-label": tc("components.taskTimeline.title"), children: [
987
+ /* @__PURE__ */ jsxRuntime.jsx("ol", { className: unstyled ? void 0 : "agenc-timeline__list", children: HAPPY_PATH.map((stage, index) => {
988
+ const done = currentIndex > index;
989
+ const current = currentIndex === index;
990
+ const state = done ? "done" : current ? "current" : "upcoming";
991
+ return /* @__PURE__ */ jsxRuntime.jsxs(
992
+ "li",
993
+ {
994
+ className: unstyled ? void 0 : cx("agenc-timeline__step", `agenc-timeline__step--${state}`),
995
+ "aria-current": current ? "step" : void 0,
996
+ children: [
997
+ /* @__PURE__ */ jsxRuntime.jsx(
998
+ "span",
999
+ {
1000
+ className: unstyled ? void 0 : "agenc-timeline__marker",
1001
+ "aria-hidden": "true"
1002
+ }
1003
+ ),
1004
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-timeline__label", children: tc(stage.stringId) })
1005
+ ]
1006
+ },
1007
+ stage.status
1008
+ );
1009
+ }) }),
1010
+ offPath ? /* @__PURE__ */ jsxRuntime.jsx(
1011
+ "p",
1012
+ {
1013
+ className: unstyled ? void 0 : cx(
1014
+ "agenc-timeline__terminal",
1015
+ `agenc-timeline__terminal--${offPath.tone}`
1016
+ ),
1017
+ role: "status",
1018
+ children: tc(offPath.stringId)
1019
+ }
1020
+ ) : null
1021
+ ] });
1022
+ }
1023
+ var SUCCESS_STRING = {
1024
+ accept: "components.review.accepted",
1025
+ reject: "components.review.rejected",
1026
+ requestChanges: "components.review.changesRequested"
1027
+ };
1028
+ function ReviewPanel({
1029
+ hasSubmission = false,
1030
+ onAccept,
1031
+ onReject,
1032
+ onRequestChanges,
1033
+ status = "idle",
1034
+ error = null,
1035
+ settledAction,
1036
+ unstyled,
1037
+ className
1038
+ }) {
1039
+ const panelClass = rootClass("agenc-review", unstyled, className);
1040
+ const pending = status === "pending";
1041
+ const success = status === "success";
1042
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1043
+ "section",
1044
+ {
1045
+ className: panelClass,
1046
+ "aria-label": tc("components.review.title"),
1047
+ children: [
1048
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { className: unstyled ? void 0 : "agenc-review__title", children: tc("components.review.title") }),
1049
+ !hasSubmission ? /* @__PURE__ */ jsxRuntime.jsx(
1050
+ StateMessage,
1051
+ {
1052
+ kind: "empty",
1053
+ message: tc("components.review.noSubmission"),
1054
+ unstyled
1055
+ }
1056
+ ) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-review__actions", children: [
1057
+ /* @__PURE__ */ jsxRuntime.jsx(
1058
+ Button,
1059
+ {
1060
+ unstyled,
1061
+ variant: "primary",
1062
+ loading: pending,
1063
+ disabled: pending || !onAccept,
1064
+ onClick: onAccept,
1065
+ children: tc("components.review.accept")
1066
+ }
1067
+ ),
1068
+ /* @__PURE__ */ jsxRuntime.jsx(
1069
+ Button,
1070
+ {
1071
+ unstyled,
1072
+ variant: "secondary",
1073
+ disabled: pending || !onRequestChanges,
1074
+ onClick: onRequestChanges,
1075
+ children: tc("components.review.requestChanges")
1076
+ }
1077
+ ),
1078
+ /* @__PURE__ */ jsxRuntime.jsx(
1079
+ Button,
1080
+ {
1081
+ unstyled,
1082
+ variant: "danger",
1083
+ disabled: pending || !onReject,
1084
+ onClick: onReject,
1085
+ children: tc("components.review.reject")
1086
+ }
1087
+ )
1088
+ ] }),
1089
+ /* @__PURE__ */ jsxRuntime.jsxs(
1090
+ "div",
1091
+ {
1092
+ className: unstyled ? void 0 : "agenc-review__status",
1093
+ role: "status",
1094
+ "aria-live": "polite",
1095
+ children: [
1096
+ pending ? tc("components.review.pending") : null,
1097
+ success && settledAction ? tc(SUCCESS_STRING[settledAction]) : null
1098
+ ]
1099
+ }
1100
+ ),
1101
+ error ? /* @__PURE__ */ jsxRuntime.jsxs(
1102
+ "div",
1103
+ {
1104
+ className: unstyled ? void 0 : "agenc-review__error",
1105
+ role: "alert",
1106
+ "aria-live": "assertive",
1107
+ children: [
1108
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: tc("components.review.errorTitle") }),
1109
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: error.message })
1110
+ ]
1111
+ }
1112
+ ) : null
1113
+ ]
1114
+ }
1115
+ );
1116
+ }
1117
+ function DisputeBanner({
1118
+ disputeOpen = false,
1119
+ onInitiate,
1120
+ status = "idle",
1121
+ error = null,
1122
+ unstyled,
1123
+ className
1124
+ }) {
1125
+ const bannerClass = rootClass(
1126
+ cx(
1127
+ "agenc-dispute",
1128
+ disputeOpen ? "agenc-dispute--open" : "agenc-dispute--none"
1129
+ ),
1130
+ unstyled,
1131
+ className
1132
+ );
1133
+ const pending = status === "pending";
1134
+ const opened = status === "success";
1135
+ if (disputeOpen) {
1136
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: bannerClass, role: "alert", children: [
1137
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { className: unstyled ? void 0 : "agenc-dispute__title", children: tc("components.dispute.title") }),
1138
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: unstyled ? void 0 : "agenc-dispute__body", children: tc("components.dispute.body") })
1139
+ ] });
1140
+ }
1141
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: bannerClass, role: "region", "aria-label": tc("components.dispute.none"), children: [
1142
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: unstyled ? void 0 : "agenc-dispute__none", children: tc("components.dispute.none") }),
1143
+ onInitiate ? /* @__PURE__ */ jsxRuntime.jsx(
1144
+ Button,
1145
+ {
1146
+ unstyled,
1147
+ variant: "secondary",
1148
+ loading: pending,
1149
+ disabled: pending,
1150
+ onClick: onInitiate,
1151
+ children: pending ? tc("components.dispute.pending") : tc("components.dispute.initiate")
1152
+ }
1153
+ ) : null,
1154
+ /* @__PURE__ */ jsxRuntime.jsx(
1155
+ "div",
1156
+ {
1157
+ className: unstyled ? void 0 : "agenc-dispute__status",
1158
+ role: "status",
1159
+ "aria-live": "polite",
1160
+ children: opened ? tc("components.dispute.opened") : null
1161
+ }
1162
+ ),
1163
+ error ? /* @__PURE__ */ jsxRuntime.jsxs(
1164
+ "div",
1165
+ {
1166
+ className: unstyled ? void 0 : "agenc-dispute__error",
1167
+ role: "alert",
1168
+ "aria-live": "assertive",
1169
+ children: [
1170
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: tc("components.dispute.errorTitle") }),
1171
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: error.message })
1172
+ ]
1173
+ }
1174
+ ) : null
1175
+ ] });
1176
+ }
1177
+ function ProviderCard({
1178
+ agent,
1179
+ trackRecord,
1180
+ verified = false,
1181
+ isLoading = false,
1182
+ error = null,
1183
+ onRetry,
1184
+ unstyled,
1185
+ className
1186
+ }) {
1187
+ const cardClass = rootClass("agenc-provider", unstyled, className);
1188
+ const header = /* @__PURE__ */ jsxRuntime.jsxs("header", { className: unstyled ? void 0 : "agenc-provider__header", children: [
1189
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-provider__id", children: [
1190
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-provider__label", children: tc("components.provider.title") }),
1191
+ agent ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-provider__pda", children: truncateAddress(agent) }) : null
1192
+ ] }),
1193
+ /* @__PURE__ */ jsxRuntime.jsx(VerifiedBadge, { verified, unstyled })
1194
+ ] });
1195
+ if (error) {
1196
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cardClass, "aria-label": tc("components.provider.title"), children: [
1197
+ header,
1198
+ /* @__PURE__ */ jsxRuntime.jsx(
1199
+ StateMessage,
1200
+ {
1201
+ kind: "error",
1202
+ message: tc("components.provider.unavailable"),
1203
+ onRetry,
1204
+ unstyled
1205
+ }
1206
+ )
1207
+ ] });
1208
+ }
1209
+ if (isLoading && trackRecord === null) {
1210
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cardClass, "aria-label": tc("components.provider.title"), children: [
1211
+ header,
1212
+ /* @__PURE__ */ jsxRuntime.jsx(StateMessage, { kind: "loading", unstyled })
1213
+ ] });
1214
+ }
1215
+ if (trackRecord === null) {
1216
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cardClass, "aria-label": tc("components.provider.title"), children: [
1217
+ header,
1218
+ /* @__PURE__ */ jsxRuntime.jsx(
1219
+ StateMessage,
1220
+ {
1221
+ kind: "empty",
1222
+ message: tc("components.provider.noData"),
1223
+ unstyled
1224
+ }
1225
+ )
1226
+ ] });
1227
+ }
1228
+ const provisional = trackRecord.partial;
1229
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cardClass, "aria-label": tc("components.provider.title"), children: [
1230
+ header,
1231
+ /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: unstyled ? void 0 : "agenc-provider__stats", children: [
1232
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-provider__stat", children: [
1233
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: tc("components.provider.completionRate") }),
1234
+ /* @__PURE__ */ jsxRuntime.jsxs("dd", { children: [
1235
+ formatRate(trackRecord.completionRate),
1236
+ provisional ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: unstyled ? void 0 : "agenc-provider__provisional", children: [
1237
+ " ",
1238
+ "(",
1239
+ tc("components.provider.provisional"),
1240
+ ")"
1241
+ ] }) : null
1242
+ ] })
1243
+ ] }),
1244
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-provider__stat", children: [
1245
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: tc("components.provider.disputeRate") }),
1246
+ /* @__PURE__ */ jsxRuntime.jsxs("dd", { children: [
1247
+ formatRate(trackRecord.disputeRate),
1248
+ provisional ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: unstyled ? void 0 : "agenc-provider__provisional", children: [
1249
+ " ",
1250
+ "(",
1251
+ tc("components.provider.provisional"),
1252
+ ")"
1253
+ ] }) : null
1254
+ ] })
1255
+ ] }),
1256
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: unstyled ? void 0 : "agenc-provider__stat", children: [
1257
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { children: tc("components.provider.completions", {
1258
+ count: String(trackRecord.completions)
1259
+ }) }),
1260
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { children: tc("components.provider.disputes", {
1261
+ count: String(trackRecord.disputesLost)
1262
+ }) })
1263
+ ] })
1264
+ ] })
1265
+ ] });
1266
+ }
1267
+ var DEFAULT_TRUST_HREF = "https://agenc.tech/trust";
1268
+ var SAFE_HREF_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
1269
+ function safeHref(href) {
1270
+ try {
1271
+ const url = new URL(href, DEFAULT_TRUST_HREF);
1272
+ return SAFE_HREF_SCHEMES.has(url.protocol) ? href : DEFAULT_TRUST_HREF;
1273
+ } catch {
1274
+ return DEFAULT_TRUST_HREF;
1275
+ }
1276
+ }
1277
+ function PoweredByAgenC({
1278
+ href = DEFAULT_TRUST_HREF,
1279
+ newTab = true,
1280
+ label,
1281
+ unstyled,
1282
+ className
1283
+ }) {
1284
+ const linkClass = rootClass("agenc-powered-by", unstyled, className);
1285
+ return /* @__PURE__ */ jsxRuntime.jsx(
1286
+ "a",
1287
+ {
1288
+ className: linkClass,
1289
+ href: safeHref(href),
1290
+ target: newTab ? "_blank" : void 0,
1291
+ rel: newTab ? "noopener noreferrer" : void 0,
1292
+ "aria-label": `${label ?? tc("components.poweredBy.label")} \u2014 ${tc(
1293
+ "components.poweredBy.trustLink"
1294
+ )}`,
1295
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: unstyled ? void 0 : "agenc-powered-by__label", children: label ?? tc("components.poweredBy.label") })
1296
+ }
1297
+ );
1298
+ }
1299
+
1300
+ exports.Badge = Badge;
1301
+ exports.Button = Button;
1302
+ exports.COMPONENT_CATALOG = COMPONENT_CATALOG;
1303
+ exports.DEFAULT_TRUST_HREF = DEFAULT_TRUST_HREF;
1304
+ exports.DisputeBanner = DisputeBanner;
1305
+ exports.EN_COMPONENT_STRINGS = EN_COMPONENT_STRINGS;
1306
+ exports.HireButton = HireButton;
1307
+ exports.HireCheckoutModal = HireCheckoutModal;
1308
+ exports.ListingCard = ListingCard;
1309
+ exports.ListingGrid = ListingGrid;
1310
+ exports.Modal = Modal;
1311
+ exports.ModerationBadge = ModerationBadge;
1312
+ exports.PoweredByAgenC = PoweredByAgenC;
1313
+ exports.ProviderCard = ProviderCard;
1314
+ exports.ReferrerDisclosure = ReferrerDisclosure;
1315
+ exports.ReviewPanel = ReviewPanel;
1316
+ exports.Spinner = Spinner;
1317
+ exports.StateMessage = StateMessage;
1318
+ exports.TaskTimeline = TaskTimeline;
1319
+ exports.VerifiedBadge = VerifiedBadge;
1320
+ exports.cx = cx;
1321
+ exports.decodeListingCategory = decodeListingCategory;
1322
+ exports.decodeListingName = decodeListingName;
1323
+ exports.decodeListingTags = decodeListingTags;
1324
+ exports.elementClass = elementClass;
1325
+ exports.formatPriceSol = formatPriceSol;
1326
+ exports.formatRate = formatRate;
1327
+ exports.formatSol = formatSol;
1328
+ exports.moderationStateOf = moderationStateOf;
1329
+ exports.rootClass = rootClass;
1330
+ exports.tc = tc;
1331
+ exports.toHex = toHex;
1332
+ exports.truncateAddress = truncateAddress;
1333
+ exports.useFocusTrap = useFocusTrap;
1334
+ //# sourceMappingURL=index.cjs.map
1335
+ //# sourceMappingURL=index.cjs.map