@contractspec/example.crm-pipeline 3.7.17 → 3.7.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/.turbo/turbo-build.log +135 -135
  2. package/CHANGELOG.md +20 -0
  3. package/dist/browser/crm-pipeline.feature.js +1 -82
  4. package/dist/browser/deal/deal.enum.js +1 -18
  5. package/dist/browser/deal/deal.operation.js +1 -396
  6. package/dist/browser/deal/deal.schema.js +1 -141
  7. package/dist/browser/deal/deal.test-spec.js +1 -58
  8. package/dist/browser/deal/index.js +1 -408
  9. package/dist/browser/docs/crm-pipeline.docblock.js +5 -49
  10. package/dist/browser/docs/index.js +5 -49
  11. package/dist/browser/entities/company.entity.js +1 -52
  12. package/dist/browser/entities/contact.entity.js +1 -66
  13. package/dist/browser/entities/deal.entity.js +1 -107
  14. package/dist/browser/entities/index.js +1 -343
  15. package/dist/browser/entities/task.entity.js +1 -99
  16. package/dist/browser/events/contact.event.js +1 -31
  17. package/dist/browser/events/deal.event.js +1 -101
  18. package/dist/browser/events/index.js +1 -158
  19. package/dist/browser/events/task.event.js +1 -28
  20. package/dist/browser/example.js +1 -39
  21. package/dist/browser/handlers/crm.handlers.js +2 -171
  22. package/dist/browser/handlers/deal.handlers.js +1 -293
  23. package/dist/browser/handlers/index.js +2 -467
  24. package/dist/browser/handlers/mock-data.js +1 -165
  25. package/dist/browser/index.js +8 -3461
  26. package/dist/browser/operations/index.js +1 -407
  27. package/dist/browser/presentations/dashboard.presentation.js +1 -55
  28. package/dist/browser/presentations/index.js +1 -290
  29. package/dist/browser/presentations/pipeline.presentation.js +1 -236
  30. package/dist/browser/seeders/index.js +1 -22
  31. package/dist/browser/ui/CrmDashboard.js +1 -1547
  32. package/dist/browser/ui/CrmDealCard.js +1 -50
  33. package/dist/browser/ui/CrmPipelineBoard.js +1 -160
  34. package/dist/browser/ui/hooks/index.js +1 -197
  35. package/dist/browser/ui/hooks/useDealList.js +1 -95
  36. package/dist/browser/ui/hooks/useDealMutations.js +1 -100
  37. package/dist/browser/ui/index.js +4 -2205
  38. package/dist/browser/ui/modals/CreateDealModal.js +1 -211
  39. package/dist/browser/ui/modals/DealActionsModal.js +1 -428
  40. package/dist/browser/ui/modals/index.js +1 -638
  41. package/dist/browser/ui/overlays/demo-overlays.js +1 -55
  42. package/dist/browser/ui/overlays/index.js +1 -55
  43. package/dist/browser/ui/renderers/index.js +4 -849
  44. package/dist/browser/ui/renderers/pipeline.markdown.js +4 -575
  45. package/dist/browser/ui/renderers/pipeline.renderer.js +1 -275
  46. package/dist/browser/ui/tables/DealListTab.js +1 -390
  47. package/dist/crm-pipeline.feature.js +1 -82
  48. package/dist/deal/deal.enum.js +1 -18
  49. package/dist/deal/deal.operation.js +1 -396
  50. package/dist/deal/deal.schema.js +1 -141
  51. package/dist/deal/deal.test-spec.js +1 -58
  52. package/dist/deal/index.js +1 -408
  53. package/dist/docs/crm-pipeline.docblock.js +5 -49
  54. package/dist/docs/index.js +5 -49
  55. package/dist/entities/company.entity.js +1 -52
  56. package/dist/entities/contact.entity.js +1 -66
  57. package/dist/entities/deal.entity.js +1 -107
  58. package/dist/entities/index.js +1 -343
  59. package/dist/entities/task.entity.js +1 -99
  60. package/dist/events/contact.event.js +1 -31
  61. package/dist/events/deal.event.js +1 -101
  62. package/dist/events/index.js +1 -158
  63. package/dist/events/task.event.js +1 -28
  64. package/dist/example.js +1 -39
  65. package/dist/handlers/crm.handlers.js +2 -171
  66. package/dist/handlers/deal.handlers.js +1 -293
  67. package/dist/handlers/index.js +2 -467
  68. package/dist/handlers/mock-data.js +1 -165
  69. package/dist/index.js +8 -3461
  70. package/dist/node/crm-pipeline.feature.js +1 -82
  71. package/dist/node/deal/deal.enum.js +1 -18
  72. package/dist/node/deal/deal.operation.js +1 -396
  73. package/dist/node/deal/deal.schema.js +1 -141
  74. package/dist/node/deal/deal.test-spec.js +1 -58
  75. package/dist/node/deal/index.js +1 -408
  76. package/dist/node/docs/crm-pipeline.docblock.js +5 -49
  77. package/dist/node/docs/index.js +5 -49
  78. package/dist/node/entities/company.entity.js +1 -52
  79. package/dist/node/entities/contact.entity.js +1 -66
  80. package/dist/node/entities/deal.entity.js +1 -107
  81. package/dist/node/entities/index.js +1 -343
  82. package/dist/node/entities/task.entity.js +1 -99
  83. package/dist/node/events/contact.event.js +1 -31
  84. package/dist/node/events/deal.event.js +1 -101
  85. package/dist/node/events/index.js +1 -158
  86. package/dist/node/events/task.event.js +1 -28
  87. package/dist/node/example.js +1 -39
  88. package/dist/node/handlers/crm.handlers.js +2 -171
  89. package/dist/node/handlers/deal.handlers.js +1 -293
  90. package/dist/node/handlers/index.js +2 -467
  91. package/dist/node/handlers/mock-data.js +1 -165
  92. package/dist/node/index.js +8 -3461
  93. package/dist/node/operations/index.js +1 -407
  94. package/dist/node/presentations/dashboard.presentation.js +1 -55
  95. package/dist/node/presentations/index.js +1 -290
  96. package/dist/node/presentations/pipeline.presentation.js +1 -236
  97. package/dist/node/seeders/index.js +1 -22
  98. package/dist/node/ui/CrmDashboard.js +1 -1547
  99. package/dist/node/ui/CrmDealCard.js +1 -50
  100. package/dist/node/ui/CrmPipelineBoard.js +1 -160
  101. package/dist/node/ui/hooks/index.js +1 -197
  102. package/dist/node/ui/hooks/useDealList.js +1 -95
  103. package/dist/node/ui/hooks/useDealMutations.js +1 -100
  104. package/dist/node/ui/index.js +4 -2205
  105. package/dist/node/ui/modals/CreateDealModal.js +1 -211
  106. package/dist/node/ui/modals/DealActionsModal.js +1 -428
  107. package/dist/node/ui/modals/index.js +1 -638
  108. package/dist/node/ui/overlays/demo-overlays.js +1 -55
  109. package/dist/node/ui/overlays/index.js +1 -55
  110. package/dist/node/ui/renderers/index.js +4 -849
  111. package/dist/node/ui/renderers/pipeline.markdown.js +4 -575
  112. package/dist/node/ui/renderers/pipeline.renderer.js +1 -275
  113. package/dist/node/ui/tables/DealListTab.js +1 -390
  114. package/dist/operations/index.js +1 -407
  115. package/dist/presentations/dashboard.presentation.js +1 -55
  116. package/dist/presentations/index.js +1 -290
  117. package/dist/presentations/pipeline.presentation.js +1 -236
  118. package/dist/seeders/index.js +1 -22
  119. package/dist/ui/CrmDashboard.js +1 -1547
  120. package/dist/ui/CrmDealCard.js +1 -50
  121. package/dist/ui/CrmPipelineBoard.js +1 -160
  122. package/dist/ui/hooks/index.js +1 -197
  123. package/dist/ui/hooks/useDealList.js +1 -95
  124. package/dist/ui/hooks/useDealMutations.js +1 -100
  125. package/dist/ui/index.js +4 -2205
  126. package/dist/ui/modals/CreateDealModal.js +1 -211
  127. package/dist/ui/modals/DealActionsModal.js +1 -428
  128. package/dist/ui/modals/index.js +1 -638
  129. package/dist/ui/overlays/demo-overlays.js +1 -55
  130. package/dist/ui/overlays/index.js +1 -55
  131. package/dist/ui/renderers/index.js +4 -849
  132. package/dist/ui/renderers/pipeline.markdown.js +4 -575
  133. package/dist/ui/renderers/pipeline.renderer.js +1 -275
  134. package/dist/ui/tables/DealListTab.js +1 -390
  135. package/package.json +13 -13
@@ -1,1548 +1,2 @@
1
1
  // @bun
2
- // src/ui/CrmDealCard.tsx
3
- import { jsxDEV } from "react/jsx-dev-runtime";
4
- "use client";
5
- function formatCurrency(value, currency) {
6
- return new Intl.NumberFormat("en-US", {
7
- style: "currency",
8
- currency,
9
- minimumFractionDigits: 0,
10
- maximumFractionDigits: 0
11
- }).format(value);
12
- }
13
- function CrmDealCard({ deal, onClick }) {
14
- const daysUntilClose = deal.expectedCloseDate ? Math.ceil((deal.expectedCloseDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)) : null;
15
- return /* @__PURE__ */ jsxDEV("div", {
16
- onClick,
17
- className: "cursor-pointer rounded-lg border border-border bg-card p-3 shadow-sm transition-shadow hover:shadow-md",
18
- role: "button",
19
- tabIndex: 0,
20
- onKeyDown: (e) => {
21
- if (e.key === "Enter" || e.key === " ")
22
- onClick?.();
23
- },
24
- children: [
25
- /* @__PURE__ */ jsxDEV("h4", {
26
- className: "font-medium leading-snug",
27
- children: deal.name
28
- }, undefined, false, undefined, this),
29
- /* @__PURE__ */ jsxDEV("div", {
30
- className: "mt-2 font-semibold text-lg text-primary",
31
- children: formatCurrency(deal.value, deal.currency)
32
- }, undefined, false, undefined, this),
33
- /* @__PURE__ */ jsxDEV("div", {
34
- className: "mt-3 flex items-center justify-between text-muted-foreground text-xs",
35
- children: [
36
- daysUntilClose !== null && /* @__PURE__ */ jsxDEV("span", {
37
- className: daysUntilClose < 0 ? "text-red-500" : daysUntilClose <= 7 ? "text-yellow-600 dark:text-yellow-500" : "",
38
- children: daysUntilClose < 0 ? `${Math.abs(daysUntilClose)}d overdue` : daysUntilClose === 0 ? "Due today" : `${daysUntilClose}d left`
39
- }, undefined, false, undefined, this),
40
- /* @__PURE__ */ jsxDEV("span", {
41
- className: `rounded px-1.5 py-0.5 font-medium text-xs ${deal.status === "WON" ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" : deal.status === "LOST" ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400" : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,
42
- children: deal.status
43
- }, undefined, false, undefined, this)
44
- ]
45
- }, undefined, true, undefined, this)
46
- ]
47
- }, undefined, true, undefined, this);
48
- }
49
-
50
- // src/ui/CrmPipelineBoard.tsx
51
- import { useState } from "react";
52
- import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
53
- "use client";
54
- function formatCurrency2(value) {
55
- if (value >= 1e6)
56
- return `$${(value / 1e6).toFixed(1)}M`;
57
- if (value >= 1000)
58
- return `$${(value / 1000).toFixed(0)}K`;
59
- return `$${value}`;
60
- }
61
- function CrmPipelineBoard({
62
- dealsByStage,
63
- stages,
64
- onDealClick,
65
- onDealMove
66
- }) {
67
- const [quickMoveOpen, setQuickMoveOpen] = useState(null);
68
- const sortedStages = [...stages].sort((a, b) => a.position - b.position);
69
- const handleQuickMove = (dealId, toStageId) => {
70
- onDealMove?.(dealId, toStageId);
71
- setQuickMoveOpen(null);
72
- };
73
- return /* @__PURE__ */ jsxDEV2("div", {
74
- className: "flex gap-4 overflow-x-auto pb-4",
75
- children: sortedStages.map((stage) => {
76
- const deals = dealsByStage[stage.id] ?? [];
77
- const stageValue = deals.reduce((sum, d) => sum + d.value, 0);
78
- return /* @__PURE__ */ jsxDEV2("div", {
79
- className: "flex w-72 flex-shrink-0 flex-col rounded-lg bg-muted/30",
80
- children: [
81
- /* @__PURE__ */ jsxDEV2("div", {
82
- className: "flex items-center justify-between border-border border-b px-3 py-2",
83
- children: [
84
- /* @__PURE__ */ jsxDEV2("div", {
85
- children: [
86
- /* @__PURE__ */ jsxDEV2("h3", {
87
- className: "font-medium",
88
- children: stage.name
89
- }, undefined, false, undefined, this),
90
- /* @__PURE__ */ jsxDEV2("p", {
91
- className: "text-muted-foreground text-xs",
92
- children: [
93
- deals.length,
94
- " deals \xB7 ",
95
- formatCurrency2(stageValue)
96
- ]
97
- }, undefined, true, undefined, this)
98
- ]
99
- }, undefined, true, undefined, this),
100
- /* @__PURE__ */ jsxDEV2("span", {
101
- className: "flex h-6 w-6 items-center justify-center rounded-full bg-muted font-medium text-xs",
102
- children: deals.length
103
- }, undefined, false, undefined, this)
104
- ]
105
- }, undefined, true, undefined, this),
106
- /* @__PURE__ */ jsxDEV2("div", {
107
- className: "flex flex-1 flex-col gap-2 p-2",
108
- children: deals.length === 0 ? /* @__PURE__ */ jsxDEV2("div", {
109
- className: "flex h-24 items-center justify-center rounded-md border-2 border-muted-foreground/20 border-dashed text-muted-foreground text-xs",
110
- children: "No deals"
111
- }, undefined, false, undefined, this) : deals.map((deal) => /* @__PURE__ */ jsxDEV2("div", {
112
- className: "group relative",
113
- children: [
114
- /* @__PURE__ */ jsxDEV2(CrmDealCard, {
115
- deal,
116
- onClick: () => onDealClick?.(deal.id)
117
- }, undefined, false, undefined, this),
118
- deal.status === "OPEN" && onDealMove && /* @__PURE__ */ jsxDEV2("div", {
119
- className: "absolute top-1 right-1 opacity-0 transition-opacity group-hover:opacity-100",
120
- children: [
121
- /* @__PURE__ */ jsxDEV2("button", {
122
- type: "button",
123
- onClick: (e) => {
124
- e.stopPropagation();
125
- setQuickMoveOpen(quickMoveOpen === deal.id ? null : deal.id);
126
- },
127
- className: "flex h-6 w-6 items-center justify-center rounded border border-border bg-background text-xs shadow-sm hover:bg-muted",
128
- title: "Quick move",
129
- children: "\u27A1\uFE0F"
130
- }, undefined, false, undefined, this),
131
- quickMoveOpen === deal.id && /* @__PURE__ */ jsxDEV2("div", {
132
- className: "absolute top-7 right-0 z-20 min-w-[140px] rounded-lg border border-border bg-card py-1 shadow-lg",
133
- children: [
134
- /* @__PURE__ */ jsxDEV2("p", {
135
- className: "px-3 py-1 font-medium text-muted-foreground text-xs",
136
- children: "Move to:"
137
- }, undefined, false, undefined, this),
138
- sortedStages.filter((s) => s.id !== deal.stageId).map((s) => /* @__PURE__ */ jsxDEV2("button", {
139
- type: "button",
140
- onClick: (e) => {
141
- e.stopPropagation();
142
- handleQuickMove(deal.id, s.id);
143
- },
144
- className: "w-full px-3 py-1.5 text-left text-sm hover:bg-muted",
145
- children: s.name
146
- }, s.id, false, undefined, this))
147
- ]
148
- }, undefined, true, undefined, this)
149
- ]
150
- }, undefined, true, undefined, this)
151
- ]
152
- }, deal.id, true, undefined, this))
153
- }, undefined, false, undefined, this)
154
- ]
155
- }, stage.id, true, undefined, this);
156
- })
157
- }, undefined, false, undefined, this);
158
- }
159
-
160
- // src/ui/hooks/useDealList.ts
161
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
162
- import { useCallback, useEffect, useMemo, useState as useState2 } from "react";
163
- "use client";
164
- function useDealList(options = {}) {
165
- const { handlers, projectId } = useTemplateRuntime();
166
- const { crm } = handlers;
167
- const [data, setData] = useState2(null);
168
- const [dealsByStage, setDealsByStage] = useState2({});
169
- const [stages, setStages] = useState2([]);
170
- const [loading, setLoading] = useState2(true);
171
- const [error, setError] = useState2(null);
172
- const [internalPage, setInternalPage] = useState2(0);
173
- const pipelineId = options.pipelineId ?? "pipeline-1";
174
- const pageIndex = options.pageIndex ?? internalPage;
175
- const pageSize = options.pageSize ?? options.limit ?? 50;
176
- const [sort] = options.sorting ?? [];
177
- const sortBy = sort?.id;
178
- const sortDirection = sort ? sort.desc ? "desc" : "asc" : undefined;
179
- const fetchData = useCallback(async () => {
180
- setLoading(true);
181
- setError(null);
182
- try {
183
- const [dealsResult, stageDealsResult, stagesResult] = await Promise.all([
184
- crm.listDeals({
185
- projectId,
186
- pipelineId,
187
- stageId: options.stageId,
188
- status: options.status === "all" ? undefined : options.status,
189
- search: options.search,
190
- limit: pageSize,
191
- offset: pageIndex * pageSize,
192
- sortBy: sortBy === "name" || sortBy === "value" || sortBy === "status" || sortBy === "expectedCloseDate" || sortBy === "updatedAt" ? sortBy : undefined,
193
- sortDirection
194
- }),
195
- crm.getDealsByStage({ projectId, pipelineId }),
196
- crm.getPipelineStages({ pipelineId })
197
- ]);
198
- setData(dealsResult);
199
- setDealsByStage(stageDealsResult);
200
- setStages(stagesResult);
201
- } catch (err) {
202
- setError(err instanceof Error ? err : new Error("Unknown error"));
203
- } finally {
204
- setLoading(false);
205
- }
206
- }, [
207
- crm,
208
- projectId,
209
- pipelineId,
210
- options.stageId,
211
- options.status,
212
- options.search,
213
- pageIndex,
214
- pageSize,
215
- sortBy,
216
- sortDirection
217
- ]);
218
- useEffect(() => {
219
- fetchData();
220
- }, [fetchData]);
221
- const stats = useMemo(() => {
222
- if (!data)
223
- return null;
224
- const open = data.deals.filter((d) => d.status === "OPEN");
225
- const won = data.deals.filter((d) => d.status === "WON");
226
- const lost = data.deals.filter((d) => d.status === "LOST");
227
- return {
228
- total: data.total,
229
- totalValue: data.totalValue,
230
- openCount: open.length,
231
- openValue: open.reduce((sum, d) => sum + d.value, 0),
232
- wonCount: won.length,
233
- wonValue: won.reduce((sum, d) => sum + d.value, 0),
234
- lostCount: lost.length
235
- };
236
- }, [data]);
237
- return {
238
- data,
239
- dealsByStage,
240
- stages,
241
- loading,
242
- error,
243
- stats,
244
- page: pageIndex + 1,
245
- pageIndex,
246
- pageSize,
247
- refetch: fetchData,
248
- nextPage: options.pageIndex === undefined ? () => setInternalPage((page) => page + 1) : undefined,
249
- prevPage: options.pageIndex === undefined ? () => pageIndex > 0 && setInternalPage((page) => page - 1) : undefined
250
- };
251
- }
252
-
253
- // src/ui/hooks/useDealMutations.ts
254
- import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
255
- import { useCallback as useCallback2, useState as useState3 } from "react";
256
- function useDealMutations(options = {}) {
257
- const { handlers, projectId } = useTemplateRuntime2();
258
- const { crm } = handlers;
259
- const [createState, setCreateState] = useState3({
260
- loading: false,
261
- error: null,
262
- data: null
263
- });
264
- const [moveState, setMoveState] = useState3({
265
- loading: false,
266
- error: null,
267
- data: null
268
- });
269
- const [winState, setWinState] = useState3({
270
- loading: false,
271
- error: null,
272
- data: null
273
- });
274
- const [loseState, setLoseState] = useState3({
275
- loading: false,
276
- error: null,
277
- data: null
278
- });
279
- const createDeal = useCallback2(async (input) => {
280
- setCreateState({ loading: true, error: null, data: null });
281
- try {
282
- const result = await crm.createDeal(input, {
283
- projectId,
284
- ownerId: "user-1"
285
- });
286
- setCreateState({ loading: false, error: null, data: result });
287
- options.onSuccess?.();
288
- return result;
289
- } catch (err) {
290
- const error = err instanceof Error ? err : new Error("Failed to create deal");
291
- setCreateState({ loading: false, error, data: null });
292
- options.onError?.(error);
293
- return null;
294
- }
295
- }, [crm, projectId, options]);
296
- const moveDeal = useCallback2(async (input) => {
297
- setMoveState({ loading: true, error: null, data: null });
298
- try {
299
- const result = await crm.moveDeal(input);
300
- setMoveState({ loading: false, error: null, data: result });
301
- options.onSuccess?.();
302
- return result;
303
- } catch (err) {
304
- const error = err instanceof Error ? err : new Error("Failed to move deal");
305
- setMoveState({ loading: false, error, data: null });
306
- options.onError?.(error);
307
- return null;
308
- }
309
- }, [crm, options]);
310
- const winDeal = useCallback2(async (input) => {
311
- setWinState({ loading: true, error: null, data: null });
312
- try {
313
- const result = await crm.winDeal(input);
314
- setWinState({ loading: false, error: null, data: result });
315
- options.onSuccess?.();
316
- return result;
317
- } catch (err) {
318
- const error = err instanceof Error ? err : new Error("Failed to mark deal as won");
319
- setWinState({ loading: false, error, data: null });
320
- options.onError?.(error);
321
- return null;
322
- }
323
- }, [crm, options]);
324
- const loseDeal = useCallback2(async (input) => {
325
- setLoseState({ loading: true, error: null, data: null });
326
- try {
327
- const result = await crm.loseDeal(input);
328
- setLoseState({ loading: false, error: null, data: result });
329
- options.onSuccess?.();
330
- return result;
331
- } catch (err) {
332
- const error = err instanceof Error ? err : new Error("Failed to mark deal as lost");
333
- setLoseState({ loading: false, error, data: null });
334
- options.onError?.(error);
335
- return null;
336
- }
337
- }, [crm, options]);
338
- return {
339
- createDeal,
340
- moveDeal,
341
- winDeal,
342
- loseDeal,
343
- createState,
344
- moveState,
345
- winState,
346
- loseState,
347
- isLoading: createState.loading || moveState.loading || winState.loading || loseState.loading
348
- };
349
- }
350
-
351
- // src/ui/modals/CreateDealModal.tsx
352
- import { Button, Input } from "@contractspec/lib.design-system";
353
- import { useState as useState4 } from "react";
354
- import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
355
- "use client";
356
- var CURRENCIES = ["USD", "EUR", "GBP", "CAD"];
357
- var DEFAULT_PIPELINE_ID = "pipeline-1";
358
- function CreateDealModal({
359
- isOpen,
360
- onClose,
361
- onSubmit,
362
- stages,
363
- isLoading = false
364
- }) {
365
- const [name, setName] = useState4("");
366
- const [value, setValue] = useState4("");
367
- const [currency, setCurrency] = useState4("USD");
368
- const [stageId, setStageId] = useState4(stages[0]?.id ?? "");
369
- const [expectedCloseDate, setExpectedCloseDate] = useState4("");
370
- const [error, setError] = useState4(null);
371
- const handleSubmit = async (e) => {
372
- e.preventDefault();
373
- setError(null);
374
- if (!name.trim()) {
375
- setError("Deal name is required");
376
- return;
377
- }
378
- const numericValue = parseFloat(value);
379
- if (isNaN(numericValue) || numericValue <= 0) {
380
- setError("Value must be a positive number");
381
- return;
382
- }
383
- if (!stageId) {
384
- setError("Please select a pipeline stage");
385
- return;
386
- }
387
- try {
388
- await onSubmit({
389
- name: name.trim(),
390
- value: numericValue,
391
- currency,
392
- pipelineId: DEFAULT_PIPELINE_ID,
393
- stageId,
394
- expectedCloseDate: expectedCloseDate ? new Date(expectedCloseDate) : undefined
395
- });
396
- setName("");
397
- setValue("");
398
- setCurrency("USD");
399
- setStageId(stages[0]?.id ?? "");
400
- setExpectedCloseDate("");
401
- onClose();
402
- } catch (err) {
403
- setError(err instanceof Error ? err.message : "Failed to create deal");
404
- }
405
- };
406
- if (!isOpen)
407
- return null;
408
- return /* @__PURE__ */ jsxDEV3("div", {
409
- className: "fixed inset-0 z-50 flex items-center justify-center",
410
- children: [
411
- /* @__PURE__ */ jsxDEV3("div", {
412
- className: "absolute inset-0 bg-background/80 backdrop-blur-sm",
413
- onClick: onClose,
414
- role: "button",
415
- tabIndex: 0,
416
- onKeyDown: (e) => {
417
- if (e.key === "Enter" || e.key === " ")
418
- onClose();
419
- },
420
- "aria-label": "Close modal"
421
- }, undefined, false, undefined, this),
422
- /* @__PURE__ */ jsxDEV3("div", {
423
- className: "relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",
424
- children: [
425
- /* @__PURE__ */ jsxDEV3("h2", {
426
- className: "mb-4 font-semibold text-xl",
427
- children: "Create New Deal"
428
- }, undefined, false, undefined, this),
429
- /* @__PURE__ */ jsxDEV3("form", {
430
- onSubmit: handleSubmit,
431
- className: "space-y-4",
432
- children: [
433
- /* @__PURE__ */ jsxDEV3("div", {
434
- children: [
435
- /* @__PURE__ */ jsxDEV3("label", {
436
- htmlFor: "deal-name",
437
- className: "mb-1 block font-medium text-muted-foreground text-sm",
438
- children: "Deal Name *"
439
- }, undefined, false, undefined, this),
440
- /* @__PURE__ */ jsxDEV3(Input, {
441
- id: "deal-name",
442
- value: name,
443
- onChange: (e) => setName(e.target.value),
444
- placeholder: "e.g., Enterprise License - Acme Corp",
445
- disabled: isLoading
446
- }, undefined, false, undefined, this)
447
- ]
448
- }, undefined, true, undefined, this),
449
- /* @__PURE__ */ jsxDEV3("div", {
450
- className: "flex gap-3",
451
- children: [
452
- /* @__PURE__ */ jsxDEV3("div", {
453
- className: "flex-1",
454
- children: [
455
- /* @__PURE__ */ jsxDEV3("label", {
456
- htmlFor: "deal-value",
457
- className: "mb-1 block font-medium text-muted-foreground text-sm",
458
- children: "Value *"
459
- }, undefined, false, undefined, this),
460
- /* @__PURE__ */ jsxDEV3(Input, {
461
- id: "deal-value",
462
- type: "number",
463
- min: "0",
464
- step: "0.01",
465
- value,
466
- onChange: (e) => setValue(e.target.value),
467
- placeholder: "50000",
468
- disabled: isLoading
469
- }, undefined, false, undefined, this)
470
- ]
471
- }, undefined, true, undefined, this),
472
- /* @__PURE__ */ jsxDEV3("div", {
473
- className: "w-24",
474
- children: [
475
- /* @__PURE__ */ jsxDEV3("label", {
476
- htmlFor: "deal-currency",
477
- className: "mb-1 block font-medium text-muted-foreground text-sm",
478
- children: "Currency"
479
- }, undefined, false, undefined, this),
480
- /* @__PURE__ */ jsxDEV3("select", {
481
- id: "deal-currency",
482
- value: currency,
483
- onChange: (e) => setCurrency(e.target.value),
484
- disabled: isLoading,
485
- className: "h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50",
486
- children: CURRENCIES.map((c) => /* @__PURE__ */ jsxDEV3("option", {
487
- value: c,
488
- children: c
489
- }, c, false, undefined, this))
490
- }, undefined, false, undefined, this)
491
- ]
492
- }, undefined, true, undefined, this)
493
- ]
494
- }, undefined, true, undefined, this),
495
- /* @__PURE__ */ jsxDEV3("div", {
496
- children: [
497
- /* @__PURE__ */ jsxDEV3("label", {
498
- htmlFor: "deal-stage",
499
- className: "mb-1 block font-medium text-muted-foreground text-sm",
500
- children: "Pipeline Stage *"
501
- }, undefined, false, undefined, this),
502
- /* @__PURE__ */ jsxDEV3("select", {
503
- id: "deal-stage",
504
- value: stageId,
505
- onChange: (e) => setStageId(e.target.value),
506
- disabled: isLoading,
507
- className: "h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50",
508
- children: stages.map((stage) => /* @__PURE__ */ jsxDEV3("option", {
509
- value: stage.id,
510
- children: stage.name
511
- }, stage.id, false, undefined, this))
512
- }, undefined, false, undefined, this)
513
- ]
514
- }, undefined, true, undefined, this),
515
- /* @__PURE__ */ jsxDEV3("div", {
516
- children: [
517
- /* @__PURE__ */ jsxDEV3("label", {
518
- htmlFor: "deal-close-date",
519
- className: "mb-1 block font-medium text-muted-foreground text-sm",
520
- children: "Expected Close Date"
521
- }, undefined, false, undefined, this),
522
- /* @__PURE__ */ jsxDEV3(Input, {
523
- id: "deal-close-date",
524
- type: "date",
525
- value: expectedCloseDate,
526
- onChange: (e) => setExpectedCloseDate(e.target.value),
527
- disabled: isLoading
528
- }, undefined, false, undefined, this)
529
- ]
530
- }, undefined, true, undefined, this),
531
- error && /* @__PURE__ */ jsxDEV3("div", {
532
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
533
- children: error
534
- }, undefined, false, undefined, this),
535
- /* @__PURE__ */ jsxDEV3("div", {
536
- className: "flex justify-end gap-3 pt-2",
537
- children: [
538
- /* @__PURE__ */ jsxDEV3(Button, {
539
- type: "button",
540
- variant: "ghost",
541
- onPress: onClose,
542
- disabled: isLoading,
543
- children: "Cancel"
544
- }, undefined, false, undefined, this),
545
- /* @__PURE__ */ jsxDEV3(Button, {
546
- type: "submit",
547
- disabled: isLoading,
548
- children: isLoading ? "Creating..." : "Create Deal"
549
- }, undefined, false, undefined, this)
550
- ]
551
- }, undefined, true, undefined, this)
552
- ]
553
- }, undefined, true, undefined, this)
554
- ]
555
- }, undefined, true, undefined, this)
556
- ]
557
- }, undefined, true, undefined, this);
558
- }
559
-
560
- // src/ui/modals/DealActionsModal.tsx
561
- import { Button as Button2 } from "@contractspec/lib.design-system";
562
- import { useState as useState5 } from "react";
563
- import { jsxDEV as jsxDEV4, Fragment } from "react/jsx-dev-runtime";
564
- "use client";
565
- function formatCurrency3(value, currency) {
566
- return new Intl.NumberFormat("en-US", {
567
- style: "currency",
568
- currency,
569
- minimumFractionDigits: 0,
570
- maximumFractionDigits: 0
571
- }).format(value);
572
- }
573
- function DealActionsModal({
574
- isOpen,
575
- deal,
576
- stages,
577
- onClose,
578
- onWin,
579
- onLose,
580
- onMove,
581
- isLoading = false
582
- }) {
583
- const [mode, setMode] = useState5("menu");
584
- const [wonSource, setWonSource] = useState5("");
585
- const [lostReason, setLostReason] = useState5("");
586
- const [notes, setNotes] = useState5("");
587
- const [selectedStageId, setSelectedStageId] = useState5("");
588
- const [error, setError] = useState5(null);
589
- const resetForm = () => {
590
- setMode("menu");
591
- setWonSource("");
592
- setLostReason("");
593
- setNotes("");
594
- setSelectedStageId("");
595
- setError(null);
596
- };
597
- const handleClose = () => {
598
- resetForm();
599
- onClose();
600
- };
601
- const handleWin = async () => {
602
- if (!deal)
603
- return;
604
- setError(null);
605
- try {
606
- await onWin({
607
- dealId: deal.id,
608
- wonSource: wonSource.trim() || undefined,
609
- notes: notes.trim() || undefined
610
- });
611
- handleClose();
612
- } catch (err) {
613
- setError(err instanceof Error ? err.message : "Failed to mark deal as won");
614
- }
615
- };
616
- const handleLose = async () => {
617
- if (!deal)
618
- return;
619
- setError(null);
620
- if (!lostReason.trim()) {
621
- setError("Please provide a reason for losing the deal");
622
- return;
623
- }
624
- try {
625
- await onLose({
626
- dealId: deal.id,
627
- lostReason: lostReason.trim(),
628
- notes: notes.trim() || undefined
629
- });
630
- handleClose();
631
- } catch (err) {
632
- setError(err instanceof Error ? err.message : "Failed to mark deal as lost");
633
- }
634
- };
635
- const handleMove = async () => {
636
- if (!deal)
637
- return;
638
- setError(null);
639
- if (!selectedStageId) {
640
- setError("Please select a stage");
641
- return;
642
- }
643
- if (selectedStageId === deal.stageId) {
644
- setError("Deal is already in this stage");
645
- return;
646
- }
647
- try {
648
- await onMove({
649
- dealId: deal.id,
650
- stageId: selectedStageId
651
- });
652
- handleClose();
653
- } catch (err) {
654
- setError(err instanceof Error ? err.message : "Failed to move deal");
655
- }
656
- };
657
- if (!isOpen || !deal)
658
- return null;
659
- return /* @__PURE__ */ jsxDEV4("div", {
660
- className: "fixed inset-0 z-50 flex items-center justify-center",
661
- children: [
662
- /* @__PURE__ */ jsxDEV4("div", {
663
- className: "absolute inset-0 bg-background/80 backdrop-blur-sm",
664
- onClick: handleClose,
665
- role: "button",
666
- tabIndex: 0,
667
- onKeyDown: (e) => {
668
- if (e.key === "Enter" || e.key === " ")
669
- handleClose();
670
- },
671
- "aria-label": "Close modal"
672
- }, undefined, false, undefined, this),
673
- /* @__PURE__ */ jsxDEV4("div", {
674
- className: "relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",
675
- children: [
676
- /* @__PURE__ */ jsxDEV4("div", {
677
- className: "mb-4 border-border border-b pb-4",
678
- children: [
679
- /* @__PURE__ */ jsxDEV4("h2", {
680
- className: "font-semibold text-xl",
681
- children: deal.name
682
- }, undefined, false, undefined, this),
683
- /* @__PURE__ */ jsxDEV4("p", {
684
- className: "font-medium text-lg text-primary",
685
- children: formatCurrency3(deal.value, deal.currency)
686
- }, undefined, false, undefined, this),
687
- /* @__PURE__ */ jsxDEV4("span", {
688
- className: `mt-2 inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${deal.status === "WON" ? "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400" : deal.status === "LOST" ? "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400" : "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,
689
- children: deal.status
690
- }, undefined, false, undefined, this)
691
- ]
692
- }, undefined, true, undefined, this),
693
- mode === "menu" && /* @__PURE__ */ jsxDEV4("div", {
694
- className: "space-y-3",
695
- children: [
696
- deal.status === "OPEN" && /* @__PURE__ */ jsxDEV4(Fragment, {
697
- children: [
698
- /* @__PURE__ */ jsxDEV4(Button2, {
699
- className: "w-full justify-start",
700
- variant: "ghost",
701
- onPress: () => setMode("win"),
702
- children: [
703
- /* @__PURE__ */ jsxDEV4("span", {
704
- className: "mr-2",
705
- children: "\uD83C\uDFC6"
706
- }, undefined, false, undefined, this),
707
- " Mark as Won"
708
- ]
709
- }, undefined, true, undefined, this),
710
- /* @__PURE__ */ jsxDEV4(Button2, {
711
- className: "w-full justify-start",
712
- variant: "ghost",
713
- onPress: () => setMode("lose"),
714
- children: [
715
- /* @__PURE__ */ jsxDEV4("span", {
716
- className: "mr-2",
717
- children: "\u274C"
718
- }, undefined, false, undefined, this),
719
- " Mark as Lost"
720
- ]
721
- }, undefined, true, undefined, this),
722
- /* @__PURE__ */ jsxDEV4(Button2, {
723
- className: "w-full justify-start",
724
- variant: "ghost",
725
- onPress: () => {
726
- setSelectedStageId(deal.stageId);
727
- setMode("move");
728
- },
729
- children: [
730
- /* @__PURE__ */ jsxDEV4("span", {
731
- className: "mr-2",
732
- children: "\u27A1\uFE0F"
733
- }, undefined, false, undefined, this),
734
- " Move to Stage"
735
- ]
736
- }, undefined, true, undefined, this)
737
- ]
738
- }, undefined, true, undefined, this),
739
- deal.status !== "OPEN" && /* @__PURE__ */ jsxDEV4("p", {
740
- className: "py-4 text-center text-muted-foreground",
741
- children: [
742
- "This deal is already ",
743
- deal.status.toLowerCase(),
744
- ". No actions available."
745
- ]
746
- }, undefined, true, undefined, this),
747
- /* @__PURE__ */ jsxDEV4("div", {
748
- className: "border-border border-t pt-3",
749
- children: /* @__PURE__ */ jsxDEV4(Button2, {
750
- className: "w-full",
751
- variant: "outline",
752
- onPress: handleClose,
753
- children: "Close"
754
- }, undefined, false, undefined, this)
755
- }, undefined, false, undefined, this)
756
- ]
757
- }, undefined, true, undefined, this),
758
- mode === "win" && /* @__PURE__ */ jsxDEV4("div", {
759
- className: "space-y-4",
760
- children: [
761
- /* @__PURE__ */ jsxDEV4("div", {
762
- children: [
763
- /* @__PURE__ */ jsxDEV4("label", {
764
- htmlFor: "won-source",
765
- className: "mb-1 block font-medium text-muted-foreground text-sm",
766
- children: "How did you win this deal?"
767
- }, undefined, false, undefined, this),
768
- /* @__PURE__ */ jsxDEV4("select", {
769
- id: "won-source",
770
- value: wonSource,
771
- onChange: (e) => setWonSource(e.target.value),
772
- className: "h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring",
773
- children: [
774
- /* @__PURE__ */ jsxDEV4("option", {
775
- value: "",
776
- children: "Select a source..."
777
- }, undefined, false, undefined, this),
778
- /* @__PURE__ */ jsxDEV4("option", {
779
- value: "referral",
780
- children: "Referral"
781
- }, undefined, false, undefined, this),
782
- /* @__PURE__ */ jsxDEV4("option", {
783
- value: "cold_outreach",
784
- children: "Cold Outreach"
785
- }, undefined, false, undefined, this),
786
- /* @__PURE__ */ jsxDEV4("option", {
787
- value: "inbound",
788
- children: "Inbound Lead"
789
- }, undefined, false, undefined, this),
790
- /* @__PURE__ */ jsxDEV4("option", {
791
- value: "upsell",
792
- children: "Upsell"
793
- }, undefined, false, undefined, this),
794
- /* @__PURE__ */ jsxDEV4("option", {
795
- value: "other",
796
- children: "Other"
797
- }, undefined, false, undefined, this)
798
- ]
799
- }, undefined, true, undefined, this)
800
- ]
801
- }, undefined, true, undefined, this),
802
- /* @__PURE__ */ jsxDEV4("div", {
803
- children: [
804
- /* @__PURE__ */ jsxDEV4("label", {
805
- htmlFor: "win-notes",
806
- className: "mb-1 block font-medium text-muted-foreground text-sm",
807
- children: "Notes (optional)"
808
- }, undefined, false, undefined, this),
809
- /* @__PURE__ */ jsxDEV4("textarea", {
810
- id: "win-notes",
811
- value: notes,
812
- onChange: (e) => setNotes(e.target.value),
813
- placeholder: "Any additional notes about the win...",
814
- rows: 3,
815
- className: "w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"
816
- }, undefined, false, undefined, this)
817
- ]
818
- }, undefined, true, undefined, this),
819
- error && /* @__PURE__ */ jsxDEV4("div", {
820
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
821
- children: error
822
- }, undefined, false, undefined, this),
823
- /* @__PURE__ */ jsxDEV4("div", {
824
- className: "flex justify-end gap-3 pt-2",
825
- children: [
826
- /* @__PURE__ */ jsxDEV4(Button2, {
827
- variant: "ghost",
828
- onPress: () => setMode("menu"),
829
- disabled: isLoading,
830
- children: "Back"
831
- }, undefined, false, undefined, this),
832
- /* @__PURE__ */ jsxDEV4(Button2, {
833
- onPress: handleWin,
834
- disabled: isLoading,
835
- children: isLoading ? "Processing..." : "\uD83C\uDFC6 Confirm Win"
836
- }, undefined, false, undefined, this)
837
- ]
838
- }, undefined, true, undefined, this)
839
- ]
840
- }, undefined, true, undefined, this),
841
- mode === "lose" && /* @__PURE__ */ jsxDEV4("div", {
842
- className: "space-y-4",
843
- children: [
844
- /* @__PURE__ */ jsxDEV4("div", {
845
- children: [
846
- /* @__PURE__ */ jsxDEV4("label", {
847
- htmlFor: "lost-reason",
848
- className: "mb-1 block font-medium text-muted-foreground text-sm",
849
- children: "Why was this deal lost? *"
850
- }, undefined, false, undefined, this),
851
- /* @__PURE__ */ jsxDEV4("select", {
852
- id: "lost-reason",
853
- value: lostReason,
854
- onChange: (e) => setLostReason(e.target.value),
855
- className: "h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring",
856
- children: [
857
- /* @__PURE__ */ jsxDEV4("option", {
858
- value: "",
859
- children: "Select a reason..."
860
- }, undefined, false, undefined, this),
861
- /* @__PURE__ */ jsxDEV4("option", {
862
- value: "price",
863
- children: "Price too high"
864
- }, undefined, false, undefined, this),
865
- /* @__PURE__ */ jsxDEV4("option", {
866
- value: "competitor",
867
- children: "Lost to competitor"
868
- }, undefined, false, undefined, this),
869
- /* @__PURE__ */ jsxDEV4("option", {
870
- value: "no_budget",
871
- children: "No budget"
872
- }, undefined, false, undefined, this),
873
- /* @__PURE__ */ jsxDEV4("option", {
874
- value: "no_decision",
875
- children: "No decision made"
876
- }, undefined, false, undefined, this),
877
- /* @__PURE__ */ jsxDEV4("option", {
878
- value: "timing",
879
- children: "Bad timing"
880
- }, undefined, false, undefined, this),
881
- /* @__PURE__ */ jsxDEV4("option", {
882
- value: "product_fit",
883
- children: "Product not a fit"
884
- }, undefined, false, undefined, this),
885
- /* @__PURE__ */ jsxDEV4("option", {
886
- value: "other",
887
- children: "Other"
888
- }, undefined, false, undefined, this)
889
- ]
890
- }, undefined, true, undefined, this)
891
- ]
892
- }, undefined, true, undefined, this),
893
- /* @__PURE__ */ jsxDEV4("div", {
894
- children: [
895
- /* @__PURE__ */ jsxDEV4("label", {
896
- htmlFor: "lose-notes",
897
- className: "mb-1 block font-medium text-muted-foreground text-sm",
898
- children: "Notes (optional)"
899
- }, undefined, false, undefined, this),
900
- /* @__PURE__ */ jsxDEV4("textarea", {
901
- id: "lose-notes",
902
- value: notes,
903
- onChange: (e) => setNotes(e.target.value),
904
- placeholder: "Any additional details...",
905
- rows: 3,
906
- className: "w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"
907
- }, undefined, false, undefined, this)
908
- ]
909
- }, undefined, true, undefined, this),
910
- error && /* @__PURE__ */ jsxDEV4("div", {
911
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
912
- children: error
913
- }, undefined, false, undefined, this),
914
- /* @__PURE__ */ jsxDEV4("div", {
915
- className: "flex justify-end gap-3 pt-2",
916
- children: [
917
- /* @__PURE__ */ jsxDEV4(Button2, {
918
- variant: "ghost",
919
- onPress: () => setMode("menu"),
920
- disabled: isLoading,
921
- children: "Back"
922
- }, undefined, false, undefined, this),
923
- /* @__PURE__ */ jsxDEV4(Button2, {
924
- variant: "destructive",
925
- onPress: handleLose,
926
- disabled: isLoading,
927
- children: isLoading ? "Processing..." : "\u274C Confirm Loss"
928
- }, undefined, false, undefined, this)
929
- ]
930
- }, undefined, true, undefined, this)
931
- ]
932
- }, undefined, true, undefined, this),
933
- mode === "move" && /* @__PURE__ */ jsxDEV4("div", {
934
- className: "space-y-4",
935
- children: [
936
- /* @__PURE__ */ jsxDEV4("div", {
937
- children: [
938
- /* @__PURE__ */ jsxDEV4("label", {
939
- htmlFor: "move-stage",
940
- className: "mb-1 block font-medium text-muted-foreground text-sm",
941
- children: "Move to Stage"
942
- }, undefined, false, undefined, this),
943
- /* @__PURE__ */ jsxDEV4("select", {
944
- id: "move-stage",
945
- value: selectedStageId,
946
- onChange: (e) => setSelectedStageId(e.target.value),
947
- className: "h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring",
948
- children: stages.map((stage) => /* @__PURE__ */ jsxDEV4("option", {
949
- value: stage.id,
950
- children: [
951
- stage.name,
952
- stage.id === deal.stageId ? " (current)" : ""
953
- ]
954
- }, stage.id, true, undefined, this))
955
- }, undefined, false, undefined, this)
956
- ]
957
- }, undefined, true, undefined, this),
958
- error && /* @__PURE__ */ jsxDEV4("div", {
959
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
960
- children: error
961
- }, undefined, false, undefined, this),
962
- /* @__PURE__ */ jsxDEV4("div", {
963
- className: "flex justify-end gap-3 pt-2",
964
- children: [
965
- /* @__PURE__ */ jsxDEV4(Button2, {
966
- variant: "ghost",
967
- onPress: () => setMode("menu"),
968
- disabled: isLoading,
969
- children: "Back"
970
- }, undefined, false, undefined, this),
971
- /* @__PURE__ */ jsxDEV4(Button2, {
972
- onPress: handleMove,
973
- disabled: isLoading,
974
- children: isLoading ? "Moving..." : "\u27A1\uFE0F Move Deal"
975
- }, undefined, false, undefined, this)
976
- ]
977
- }, undefined, true, undefined, this)
978
- ]
979
- }, undefined, true, undefined, this)
980
- ]
981
- }, undefined, true, undefined, this)
982
- ]
983
- }, undefined, true, undefined, this);
984
- }
985
-
986
- // src/ui/tables/DealListTab.tsx
987
- import {
988
- Button as Button3,
989
- DataTable,
990
- LoaderBlock
991
- } from "@contractspec/lib.design-system";
992
- import { useContractTable } from "@contractspec/lib.presentation-runtime-react";
993
- import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
994
- import { HStack, VStack } from "@contractspec/lib.ui-kit-web/ui/stack";
995
- import { Text } from "@contractspec/lib.ui-kit-web/ui/text";
996
- import * as React from "react";
997
- import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
998
- "use client";
999
- function formatCurrency4(value, currency = "USD") {
1000
- return new Intl.NumberFormat("en-US", {
1001
- style: "currency",
1002
- currency,
1003
- minimumFractionDigits: 0,
1004
- maximumFractionDigits: 0
1005
- }).format(value);
1006
- }
1007
- function statusVariant(status) {
1008
- switch (status) {
1009
- case "WON":
1010
- return "default";
1011
- case "LOST":
1012
- return "destructive";
1013
- case "STALE":
1014
- return "outline";
1015
- default:
1016
- return "secondary";
1017
- }
1018
- }
1019
- function DealListDataTable({
1020
- deals,
1021
- totalItems,
1022
- pageIndex,
1023
- pageSize,
1024
- sorting,
1025
- loading,
1026
- onSortingChange,
1027
- onPaginationChange,
1028
- onDealClick
1029
- }) {
1030
- const controller = useContractTable({
1031
- data: deals,
1032
- columns: [
1033
- {
1034
- id: "deal",
1035
- header: "Deal",
1036
- label: "Deal",
1037
- accessor: (deal) => deal.name,
1038
- cell: ({ item }) => /* @__PURE__ */ jsxDEV5(VStack, {
1039
- gap: "xs",
1040
- children: [
1041
- /* @__PURE__ */ jsxDEV5(Text, {
1042
- className: "font-medium text-sm",
1043
- children: item.name
1044
- }, undefined, false, undefined, this),
1045
- /* @__PURE__ */ jsxDEV5(Text, {
1046
- className: "text-muted-foreground text-xs",
1047
- children: item.companyId ?? "Unassigned company"
1048
- }, undefined, false, undefined, this)
1049
- ]
1050
- }, undefined, true, undefined, this),
1051
- size: 240,
1052
- minSize: 180,
1053
- canSort: true,
1054
- canPin: true,
1055
- canResize: true
1056
- },
1057
- {
1058
- id: "value",
1059
- header: "Value",
1060
- label: "Value",
1061
- accessorKey: "value",
1062
- cell: ({ item }) => formatCurrency4(item.value, item.currency),
1063
- align: "right",
1064
- size: 140,
1065
- canSort: true,
1066
- canResize: true
1067
- },
1068
- {
1069
- id: "status",
1070
- header: "Status",
1071
- label: "Status",
1072
- accessorKey: "status",
1073
- cell: ({ value }) => /* @__PURE__ */ jsxDEV5(Badge, {
1074
- variant: statusVariant(value),
1075
- children: String(value)
1076
- }, undefined, false, undefined, this),
1077
- size: 130,
1078
- canSort: true,
1079
- canHide: true,
1080
- canPin: true,
1081
- canResize: true
1082
- },
1083
- {
1084
- id: "expectedCloseDate",
1085
- header: "Expected Close",
1086
- label: "Expected Close",
1087
- accessor: (deal) => deal.expectedCloseDate?.toISOString() ?? "",
1088
- cell: ({ item }) => item.expectedCloseDate?.toLocaleDateString() ?? "Not scheduled",
1089
- size: 170,
1090
- canSort: true,
1091
- canHide: true,
1092
- canResize: true
1093
- },
1094
- {
1095
- id: "updatedAt",
1096
- header: "Updated",
1097
- label: "Updated",
1098
- accessor: (deal) => deal.updatedAt.toISOString(),
1099
- cell: ({ item }) => item.updatedAt.toLocaleDateString(),
1100
- size: 140,
1101
- canSort: true,
1102
- canHide: true,
1103
- canResize: true
1104
- },
1105
- {
1106
- id: "actions",
1107
- header: "Actions",
1108
- label: "Actions",
1109
- accessor: (deal) => deal.id,
1110
- cell: ({ item }) => /* @__PURE__ */ jsxDEV5(Button3, {
1111
- variant: "ghost",
1112
- size: "sm",
1113
- onPress: () => onDealClick?.(item.id),
1114
- children: "Actions"
1115
- }, undefined, false, undefined, this),
1116
- size: 120,
1117
- canSort: false,
1118
- canHide: false,
1119
- canPin: false,
1120
- canResize: false
1121
- }
1122
- ],
1123
- executionMode: "server",
1124
- selectionMode: "multiple",
1125
- totalItems,
1126
- state: {
1127
- sorting,
1128
- pagination: {
1129
- pageIndex,
1130
- pageSize
1131
- }
1132
- },
1133
- onSortingChange,
1134
- onPaginationChange,
1135
- initialState: {
1136
- columnVisibility: { updatedAt: false },
1137
- columnPinning: { left: ["deal", "status"], right: [] }
1138
- },
1139
- renderExpandedContent: (deal) => /* @__PURE__ */ jsxDEV5(VStack, {
1140
- gap: "sm",
1141
- className: "py-2",
1142
- children: [
1143
- /* @__PURE__ */ jsxDEV5(HStack, {
1144
- justify: "between",
1145
- children: [
1146
- /* @__PURE__ */ jsxDEV5(Text, {
1147
- className: "font-medium text-sm",
1148
- children: "Owner"
1149
- }, undefined, false, undefined, this),
1150
- /* @__PURE__ */ jsxDEV5(Text, {
1151
- className: "text-muted-foreground text-sm",
1152
- children: deal.ownerId
1153
- }, undefined, false, undefined, this)
1154
- ]
1155
- }, undefined, true, undefined, this),
1156
- /* @__PURE__ */ jsxDEV5(HStack, {
1157
- justify: "between",
1158
- children: [
1159
- /* @__PURE__ */ jsxDEV5(Text, {
1160
- className: "font-medium text-sm",
1161
- children: "Contact"
1162
- }, undefined, false, undefined, this),
1163
- /* @__PURE__ */ jsxDEV5(Text, {
1164
- className: "text-muted-foreground text-sm",
1165
- children: deal.contactId ?? "No linked contact"
1166
- }, undefined, false, undefined, this)
1167
- ]
1168
- }, undefined, true, undefined, this),
1169
- deal.wonSource ? /* @__PURE__ */ jsxDEV5(HStack, {
1170
- justify: "between",
1171
- children: [
1172
- /* @__PURE__ */ jsxDEV5(Text, {
1173
- className: "font-medium text-sm",
1174
- children: "Won Source"
1175
- }, undefined, false, undefined, this),
1176
- /* @__PURE__ */ jsxDEV5(Text, {
1177
- className: "text-muted-foreground text-sm",
1178
- children: deal.wonSource
1179
- }, undefined, false, undefined, this)
1180
- ]
1181
- }, undefined, true, undefined, this) : null,
1182
- deal.lostReason ? /* @__PURE__ */ jsxDEV5(HStack, {
1183
- justify: "between",
1184
- children: [
1185
- /* @__PURE__ */ jsxDEV5(Text, {
1186
- className: "font-medium text-sm",
1187
- children: "Lost Reason"
1188
- }, undefined, false, undefined, this),
1189
- /* @__PURE__ */ jsxDEV5(Text, {
1190
- className: "text-muted-foreground text-sm",
1191
- children: deal.lostReason
1192
- }, undefined, false, undefined, this)
1193
- ]
1194
- }, undefined, true, undefined, this) : null,
1195
- deal.notes ? /* @__PURE__ */ jsxDEV5(VStack, {
1196
- gap: "xs",
1197
- children: [
1198
- /* @__PURE__ */ jsxDEV5(Text, {
1199
- className: "font-medium text-sm",
1200
- children: "Notes"
1201
- }, undefined, false, undefined, this),
1202
- /* @__PURE__ */ jsxDEV5(Text, {
1203
- className: "text-muted-foreground text-sm",
1204
- children: deal.notes
1205
- }, undefined, false, undefined, this)
1206
- ]
1207
- }, undefined, true, undefined, this) : null
1208
- ]
1209
- }, undefined, true, undefined, this),
1210
- getCanExpand: () => true
1211
- });
1212
- return /* @__PURE__ */ jsxDEV5(DataTable, {
1213
- controller,
1214
- title: "All Deals",
1215
- description: "Server-mode table using the shared ContractSpec controller.",
1216
- loading,
1217
- toolbar: /* @__PURE__ */ jsxDEV5(HStack, {
1218
- gap: "sm",
1219
- className: "flex-wrap",
1220
- children: [
1221
- /* @__PURE__ */ jsxDEV5(Text, {
1222
- className: "text-muted-foreground text-sm",
1223
- children: [
1224
- "Selected ",
1225
- controller.selectedRowIds.length
1226
- ]
1227
- }, undefined, true, undefined, this),
1228
- /* @__PURE__ */ jsxDEV5(Text, {
1229
- className: "text-muted-foreground text-sm",
1230
- children: [
1231
- totalItems,
1232
- " total deals"
1233
- ]
1234
- }, undefined, true, undefined, this)
1235
- ]
1236
- }, undefined, true, undefined, this),
1237
- footer: `Page ${controller.pageIndex + 1} of ${controller.pageCount}`,
1238
- emptyState: /* @__PURE__ */ jsxDEV5("div", {
1239
- className: "rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",
1240
- children: "No deals found"
1241
- }, undefined, false, undefined, this)
1242
- }, undefined, false, undefined, this);
1243
- }
1244
- function DealListTab({
1245
- onDealClick
1246
- }) {
1247
- const [sorting, setSorting] = React.useState([
1248
- { id: "value", desc: true }
1249
- ]);
1250
- const [pagination, setPagination] = React.useState({
1251
- pageIndex: 0,
1252
- pageSize: 3
1253
- });
1254
- const { data, loading } = useDealList({
1255
- pageIndex: pagination.pageIndex,
1256
- pageSize: pagination.pageSize,
1257
- sorting
1258
- });
1259
- if (loading && !data) {
1260
- return /* @__PURE__ */ jsxDEV5(LoaderBlock, {
1261
- label: "Loading deals..."
1262
- }, undefined, false, undefined, this);
1263
- }
1264
- return /* @__PURE__ */ jsxDEV5(DealListDataTable, {
1265
- deals: data?.deals ?? [],
1266
- totalItems: data?.total ?? 0,
1267
- pageIndex: pagination.pageIndex,
1268
- pageSize: pagination.pageSize,
1269
- sorting,
1270
- loading,
1271
- onSortingChange: (nextSorting) => {
1272
- setSorting(nextSorting);
1273
- setPagination((current) => ({ ...current, pageIndex: 0 }));
1274
- },
1275
- onPaginationChange: setPagination,
1276
- onDealClick
1277
- }, undefined, false, undefined, this);
1278
- }
1279
-
1280
- // src/ui/CrmDashboard.tsx
1281
- import {
1282
- Button as Button4,
1283
- ErrorState,
1284
- LoaderBlock as LoaderBlock2,
1285
- StatCard,
1286
- StatCardGroup
1287
- } from "@contractspec/lib.design-system";
1288
- import {
1289
- Tabs,
1290
- TabsContent,
1291
- TabsList,
1292
- TabsTrigger
1293
- } from "@contractspec/lib.ui-kit-web/ui/tabs";
1294
- import { useCallback as useCallback3, useState as useState7 } from "react";
1295
- import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
1296
- "use client";
1297
- function formatCurrency5(value, currency = "USD") {
1298
- return new Intl.NumberFormat("en-US", {
1299
- style: "currency",
1300
- currency,
1301
- minimumFractionDigits: 0,
1302
- maximumFractionDigits: 0
1303
- }).format(value);
1304
- }
1305
- function CrmDashboard() {
1306
- const [isCreateModalOpen, setIsCreateModalOpen] = useState7(false);
1307
- const [selectedDeal, setSelectedDeal] = useState7(null);
1308
- const [isDealActionsOpen, setIsDealActionsOpen] = useState7(false);
1309
- const { data, dealsByStage, stages, loading, error, stats, refetch } = useDealList();
1310
- const mutations = useDealMutations({
1311
- onSuccess: () => {
1312
- refetch();
1313
- }
1314
- });
1315
- const handleDealClick = useCallback3((dealId) => {
1316
- const deal = dealsByStage ? Object.values(dealsByStage).flat().find((d) => d.id === dealId) : null;
1317
- if (deal) {
1318
- setSelectedDeal(deal);
1319
- setIsDealActionsOpen(true);
1320
- }
1321
- }, [dealsByStage]);
1322
- const handleDealMove = useCallback3(async (dealId, toStageId) => {
1323
- await mutations.moveDeal({ dealId, stageId: toStageId });
1324
- }, [mutations]);
1325
- if (loading && !data) {
1326
- return /* @__PURE__ */ jsxDEV6(LoaderBlock2, {
1327
- label: "Loading CRM..."
1328
- }, undefined, false, undefined, this);
1329
- }
1330
- if (error) {
1331
- return /* @__PURE__ */ jsxDEV6(ErrorState, {
1332
- title: "Failed to load CRM",
1333
- description: error.message,
1334
- onRetry: refetch,
1335
- retryLabel: "Retry"
1336
- }, undefined, false, undefined, this);
1337
- }
1338
- return /* @__PURE__ */ jsxDEV6("div", {
1339
- className: "space-y-6",
1340
- children: [
1341
- /* @__PURE__ */ jsxDEV6("div", {
1342
- className: "flex items-center justify-between",
1343
- children: [
1344
- /* @__PURE__ */ jsxDEV6("h2", {
1345
- className: "font-bold text-2xl",
1346
- children: "CRM Pipeline"
1347
- }, undefined, false, undefined, this),
1348
- /* @__PURE__ */ jsxDEV6(Button4, {
1349
- onClick: () => setIsCreateModalOpen(true),
1350
- children: [
1351
- /* @__PURE__ */ jsxDEV6("span", {
1352
- className: "mr-2",
1353
- children: "+"
1354
- }, undefined, false, undefined, this),
1355
- " Create Deal"
1356
- ]
1357
- }, undefined, true, undefined, this)
1358
- ]
1359
- }, undefined, true, undefined, this),
1360
- stats && /* @__PURE__ */ jsxDEV6(StatCardGroup, {
1361
- children: [
1362
- /* @__PURE__ */ jsxDEV6(StatCard, {
1363
- label: "Total Pipeline",
1364
- value: formatCurrency5(stats.totalValue),
1365
- hint: `${stats.total} deals`
1366
- }, undefined, false, undefined, this),
1367
- /* @__PURE__ */ jsxDEV6(StatCard, {
1368
- label: "Open Deals",
1369
- value: formatCurrency5(stats.openValue),
1370
- hint: `${stats.openCount} active`
1371
- }, undefined, false, undefined, this),
1372
- /* @__PURE__ */ jsxDEV6(StatCard, {
1373
- label: "Won",
1374
- value: formatCurrency5(stats.wonValue),
1375
- hint: `${stats.wonCount} closed`
1376
- }, undefined, false, undefined, this),
1377
- /* @__PURE__ */ jsxDEV6(StatCard, {
1378
- label: "Lost",
1379
- value: stats.lostCount,
1380
- hint: "deals lost"
1381
- }, undefined, false, undefined, this)
1382
- ]
1383
- }, undefined, true, undefined, this),
1384
- /* @__PURE__ */ jsxDEV6(Tabs, {
1385
- defaultValue: "pipeline",
1386
- className: "w-full",
1387
- children: [
1388
- /* @__PURE__ */ jsxDEV6(TabsList, {
1389
- children: [
1390
- /* @__PURE__ */ jsxDEV6(TabsTrigger, {
1391
- value: "pipeline",
1392
- children: [
1393
- /* @__PURE__ */ jsxDEV6("span", {
1394
- className: "mr-2",
1395
- children: "\uD83D\uDCCA"
1396
- }, undefined, false, undefined, this),
1397
- "Pipeline"
1398
- ]
1399
- }, undefined, true, undefined, this),
1400
- /* @__PURE__ */ jsxDEV6(TabsTrigger, {
1401
- value: "list",
1402
- children: [
1403
- /* @__PURE__ */ jsxDEV6("span", {
1404
- className: "mr-2",
1405
- children: "\uD83D\uDCCB"
1406
- }, undefined, false, undefined, this),
1407
- "All Deals"
1408
- ]
1409
- }, undefined, true, undefined, this),
1410
- /* @__PURE__ */ jsxDEV6(TabsTrigger, {
1411
- value: "metrics",
1412
- children: [
1413
- /* @__PURE__ */ jsxDEV6("span", {
1414
- className: "mr-2",
1415
- children: "\uD83D\uDCC8"
1416
- }, undefined, false, undefined, this),
1417
- "Metrics"
1418
- ]
1419
- }, undefined, true, undefined, this)
1420
- ]
1421
- }, undefined, true, undefined, this),
1422
- /* @__PURE__ */ jsxDEV6(TabsContent, {
1423
- value: "pipeline",
1424
- className: "min-h-[400px]",
1425
- children: /* @__PURE__ */ jsxDEV6(CrmPipelineBoard, {
1426
- dealsByStage,
1427
- stages,
1428
- onDealClick: handleDealClick,
1429
- onDealMove: handleDealMove
1430
- }, undefined, false, undefined, this)
1431
- }, undefined, false, undefined, this),
1432
- /* @__PURE__ */ jsxDEV6(TabsContent, {
1433
- value: "list",
1434
- className: "min-h-[400px]",
1435
- children: /* @__PURE__ */ jsxDEV6(DealListTab, {
1436
- onDealClick: handleDealClick
1437
- }, undefined, false, undefined, this)
1438
- }, undefined, false, undefined, this),
1439
- /* @__PURE__ */ jsxDEV6(TabsContent, {
1440
- value: "metrics",
1441
- className: "min-h-[400px]",
1442
- children: /* @__PURE__ */ jsxDEV6(MetricsTab, {
1443
- stats
1444
- }, undefined, false, undefined, this)
1445
- }, undefined, false, undefined, this)
1446
- ]
1447
- }, undefined, true, undefined, this),
1448
- /* @__PURE__ */ jsxDEV6(CreateDealModal, {
1449
- isOpen: isCreateModalOpen,
1450
- onClose: () => setIsCreateModalOpen(false),
1451
- onSubmit: async (input) => {
1452
- await mutations.createDeal(input);
1453
- },
1454
- stages,
1455
- isLoading: mutations.createState.loading
1456
- }, undefined, false, undefined, this),
1457
- /* @__PURE__ */ jsxDEV6(DealActionsModal, {
1458
- isOpen: isDealActionsOpen,
1459
- deal: selectedDeal,
1460
- stages,
1461
- onClose: () => {
1462
- setIsDealActionsOpen(false);
1463
- setSelectedDeal(null);
1464
- },
1465
- onWin: async (input) => {
1466
- await mutations.winDeal(input);
1467
- },
1468
- onLose: async (input) => {
1469
- await mutations.loseDeal(input);
1470
- },
1471
- onMove: async (input) => {
1472
- await mutations.moveDeal(input);
1473
- refetch();
1474
- },
1475
- isLoading: mutations.isLoading
1476
- }, undefined, false, undefined, this)
1477
- ]
1478
- }, undefined, true, undefined, this);
1479
- }
1480
- function MetricsTab({
1481
- stats
1482
- }) {
1483
- if (!stats)
1484
- return null;
1485
- return /* @__PURE__ */ jsxDEV6("div", {
1486
- className: "space-y-6",
1487
- children: /* @__PURE__ */ jsxDEV6("div", {
1488
- className: "rounded-xl border border-border bg-card p-6",
1489
- children: [
1490
- /* @__PURE__ */ jsxDEV6("h3", {
1491
- className: "mb-4 font-semibold text-lg",
1492
- children: "Pipeline Overview"
1493
- }, undefined, false, undefined, this),
1494
- /* @__PURE__ */ jsxDEV6("dl", {
1495
- className: "grid gap-4 sm:grid-cols-3",
1496
- children: [
1497
- /* @__PURE__ */ jsxDEV6("div", {
1498
- children: [
1499
- /* @__PURE__ */ jsxDEV6("dt", {
1500
- className: "text-muted-foreground text-sm",
1501
- children: "Win Rate"
1502
- }, undefined, false, undefined, this),
1503
- /* @__PURE__ */ jsxDEV6("dd", {
1504
- className: "font-semibold text-2xl",
1505
- children: [
1506
- stats.total > 0 ? (stats.wonCount / stats.total * 100).toFixed(0) : 0,
1507
- "%"
1508
- ]
1509
- }, undefined, true, undefined, this)
1510
- ]
1511
- }, undefined, true, undefined, this),
1512
- /* @__PURE__ */ jsxDEV6("div", {
1513
- children: [
1514
- /* @__PURE__ */ jsxDEV6("dt", {
1515
- className: "text-muted-foreground text-sm",
1516
- children: "Avg Deal Size"
1517
- }, undefined, false, undefined, this),
1518
- /* @__PURE__ */ jsxDEV6("dd", {
1519
- className: "font-semibold text-2xl",
1520
- children: formatCurrency5(stats.total > 0 ? stats.totalValue / stats.total : 0)
1521
- }, undefined, false, undefined, this)
1522
- ]
1523
- }, undefined, true, undefined, this),
1524
- /* @__PURE__ */ jsxDEV6("div", {
1525
- children: [
1526
- /* @__PURE__ */ jsxDEV6("dt", {
1527
- className: "text-muted-foreground text-sm",
1528
- children: "Conversion"
1529
- }, undefined, false, undefined, this),
1530
- /* @__PURE__ */ jsxDEV6("dd", {
1531
- className: "font-semibold text-2xl",
1532
- children: [
1533
- stats.wonCount,
1534
- " / ",
1535
- stats.total
1536
- ]
1537
- }, undefined, true, undefined, this)
1538
- ]
1539
- }, undefined, true, undefined, this)
1540
- ]
1541
- }, undefined, true, undefined, this)
1542
- ]
1543
- }, undefined, true, undefined, this)
1544
- }, undefined, false, undefined, this);
1545
- }
1546
- export {
1547
- CrmDashboard
1548
- };
2
+ import{jsx as u,jsxs as YJ}from"react/jsx-runtime";function AJ(J,K){return new Intl.NumberFormat("en-US",{style:"currency",currency:K,minimumFractionDigits:0,maximumFractionDigits:0}).format(J)}function ZJ({deal:J,onClick:K}){let N=J.expectedCloseDate?Math.ceil((J.expectedCloseDate.getTime()-Date.now())/86400000):null;return YJ("div",{onClick:K,className:"cursor-pointer rounded-lg border border-border bg-card p-3 shadow-sm transition-shadow hover:shadow-md",role:"button",tabIndex:0,onKeyDown:(G)=>{if(G.key==="Enter"||G.key===" ")K?.()},children:[u("h4",{className:"font-medium leading-snug",children:J.name}),u("div",{className:"mt-2 font-semibold text-lg text-primary",children:AJ(J.value,J.currency)}),YJ("div",{className:"mt-3 flex items-center justify-between text-muted-foreground text-xs",children:[N!==null&&u("span",{className:N<0?"text-red-500":N<=7?"text-yellow-600 dark:text-yellow-500":"",children:N<0?`${Math.abs(N)}d overdue`:N===0?"Due today":`${N}d left`}),u("span",{className:`rounded px-1.5 py-0.5 font-medium text-xs ${J.status==="WON"?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":J.status==="LOST"?"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400":"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,children:J.status})]})]})}import{useState as HJ}from"react";import{jsx as C,jsxs as m}from"react/jsx-runtime";function NJ(J){if(J>=1e6)return`$${(J/1e6).toFixed(1)}M`;if(J>=1000)return`$${(J/1000).toFixed(0)}K`;return`$${J}`}function $J({dealsByStage:J,stages:K,onDealClick:N,onDealMove:G}){let[z,P]=HJ(null),O=[...K].sort((H,Q)=>H.position-Q.position),A=(H,Q)=>{G?.(H,Q),P(null)};return C("div",{className:"flex gap-4 overflow-x-auto pb-4",children:O.map((H)=>{let Q=J[H.id]??[],Y=Q.reduce((_,W)=>_+W.value,0);return m("div",{className:"flex w-72 flex-shrink-0 flex-col rounded-lg bg-muted/30",children:[m("div",{className:"flex items-center justify-between border-border border-b px-3 py-2",children:[m("div",{children:[C("h3",{className:"font-medium",children:H.name}),m("p",{className:"text-muted-foreground text-xs",children:[Q.length," deals \xB7 ",NJ(Y)]})]}),C("span",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-muted font-medium text-xs",children:Q.length})]}),C("div",{className:"flex flex-1 flex-col gap-2 p-2",children:Q.length===0?C("div",{className:"flex h-24 items-center justify-center rounded-md border-2 border-muted-foreground/20 border-dashed text-muted-foreground text-xs",children:"No deals"}):Q.map((_)=>m("div",{className:"group relative",children:[C(ZJ,{deal:_,onClick:()=>N?.(_.id)}),_.status==="OPEN"&&G&&m("div",{className:"absolute top-1 right-1 opacity-0 transition-opacity group-hover:opacity-100",children:[C("button",{type:"button",onClick:(W)=>{W.stopPropagation(),P(z===_.id?null:_.id)},className:"flex h-6 w-6 items-center justify-center rounded border border-border bg-background text-xs shadow-sm hover:bg-muted",title:"Quick move",children:"\u27A1\uFE0F"}),z===_.id&&m("div",{className:"absolute top-7 right-0 z-20 min-w-[140px] rounded-lg border border-border bg-card py-1 shadow-lg",children:[C("p",{className:"px-3 py-1 font-medium text-muted-foreground text-xs",children:"Move to:"}),O.filter((W)=>W.id!==_.stageId).map((W)=>C("button",{type:"button",onClick:(V)=>{V.stopPropagation(),A(_.id,W.id)},className:"w-full px-3 py-1.5 text-left text-sm hover:bg-muted",children:W.name},W.id))]})]})]},_.id))})]},H.id)})})}import{useTemplateRuntime as UJ}from"@contractspec/lib.example-shared-ui";import{useCallback as WJ,useEffect as PJ,useMemo as wJ,useState as S}from"react";function x(J={}){let{handlers:K,projectId:N}=UJ(),{crm:G}=K,[z,P]=S(null),[O,A]=S({}),[H,Q]=S([]),[Y,_]=S(!0),[W,V]=S(null),[T,b]=S(0),q=J.pipelineId??"pipeline-1",Z=J.pageIndex??T,X=J.pageSize??J.limit??50,[R]=J.sorting??[],k=R?.id,L=R?R.desc?"desc":"asc":void 0,c=WJ(async()=>{_(!0),V(null);try{let[M,F,o]=await Promise.all([G.listDeals({projectId:N,pipelineId:q,stageId:J.stageId,status:J.status==="all"?void 0:J.status,search:J.search,limit:X,offset:Z*X,sortBy:k==="name"||k==="value"||k==="status"||k==="expectedCloseDate"||k==="updatedAt"?k:void 0,sortDirection:L}),G.getDealsByStage({projectId:N,pipelineId:q}),G.getPipelineStages({pipelineId:q})]);P(M),A(F),Q(o)}catch(M){V(M instanceof Error?M:Error("Unknown error"))}finally{_(!1)}},[G,N,q,J.stageId,J.status,J.search,Z,X,k,L]);PJ(()=>{c()},[c]);let n=wJ(()=>{if(!z)return null;let M=z.deals.filter((D)=>D.status==="OPEN"),F=z.deals.filter((D)=>D.status==="WON"),o=z.deals.filter((D)=>D.status==="LOST");return{total:z.total,totalValue:z.totalValue,openCount:M.length,openValue:M.reduce((D,a)=>D+a.value,0),wonCount:F.length,wonValue:F.reduce((D,a)=>D+a.value,0),lostCount:o.length}},[z]);return{data:z,dealsByStage:O,stages:H,loading:Y,error:W,stats:n,page:Z+1,pageIndex:Z,pageSize:X,refetch:c,nextPage:J.pageIndex===void 0?()=>b((M)=>M+1):void 0,prevPage:J.pageIndex===void 0?()=>Z>0&&b((M)=>M-1):void 0}}import{useTemplateRuntime as VJ}from"@contractspec/lib.example-shared-ui";import{useCallback as i,useState as d}from"react";function GJ(J={}){let{handlers:K,projectId:N}=VJ(),{crm:G}=K,[z,P]=d({loading:!1,error:null,data:null}),[O,A]=d({loading:!1,error:null,data:null}),[H,Q]=d({loading:!1,error:null,data:null}),[Y,_]=d({loading:!1,error:null,data:null}),W=i(async(q)=>{P({loading:!0,error:null,data:null});try{let Z=await G.createDeal(q,{projectId:N,ownerId:"user-1"});return P({loading:!1,error:null,data:Z}),J.onSuccess?.(),Z}catch(Z){let X=Z instanceof Error?Z:Error("Failed to create deal");return P({loading:!1,error:X,data:null}),J.onError?.(X),null}},[G,N,J]),V=i(async(q)=>{A({loading:!0,error:null,data:null});try{let Z=await G.moveDeal(q);return A({loading:!1,error:null,data:Z}),J.onSuccess?.(),Z}catch(Z){let X=Z instanceof Error?Z:Error("Failed to move deal");return A({loading:!1,error:X,data:null}),J.onError?.(X),null}},[G,J]),T=i(async(q)=>{Q({loading:!0,error:null,data:null});try{let Z=await G.winDeal(q);return Q({loading:!1,error:null,data:Z}),J.onSuccess?.(),Z}catch(Z){let X=Z instanceof Error?Z:Error("Failed to mark deal as won");return Q({loading:!1,error:X,data:null}),J.onError?.(X),null}},[G,J]),b=i(async(q)=>{_({loading:!0,error:null,data:null});try{let Z=await G.loseDeal(q);return _({loading:!1,error:null,data:Z}),J.onSuccess?.(),Z}catch(Z){let X=Z instanceof Error?Z:Error("Failed to mark deal as lost");return _({loading:!1,error:X,data:null}),J.onError?.(X),null}},[G,J]);return{createDeal:W,moveDeal:V,winDeal:T,loseDeal:b,createState:z,moveState:O,winState:H,loseState:Y,isLoading:z.loading||O.loading||H.loading||Y.loading}}import{Button as _J,Input as t}from"@contractspec/lib.design-system";import{useState as p}from"react";import{jsx as E,jsxs as v}from"react/jsx-runtime";var OJ=["USD","EUR","GBP","CAD"],RJ="pipeline-1";function qJ({isOpen:J,onClose:K,onSubmit:N,stages:G,isLoading:z=!1}){let[P,O]=p(""),[A,H]=p(""),[Q,Y]=p("USD"),[_,W]=p(G[0]?.id??""),[V,T]=p(""),[b,q]=p(null),Z=async(X)=>{if(X.preventDefault(),q(null),!P.trim()){q("Deal name is required");return}let R=parseFloat(A);if(isNaN(R)||R<=0){q("Value must be a positive number");return}if(!_){q("Please select a pipeline stage");return}try{await N({name:P.trim(),value:R,currency:Q,pipelineId:RJ,stageId:_,expectedCloseDate:V?new Date(V):void 0}),O(""),H(""),Y("USD"),W(G[0]?.id??""),T(""),K()}catch(k){q(k instanceof Error?k.message:"Failed to create deal")}};if(!J)return null;return v("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[E("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm",onClick:K,role:"button",tabIndex:0,onKeyDown:(X)=>{if(X.key==="Enter"||X.key===" ")K()},"aria-label":"Close modal"}),v("div",{className:"relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",children:[E("h2",{className:"mb-4 font-semibold text-xl",children:"Create New Deal"}),v("form",{onSubmit:Z,className:"space-y-4",children:[v("div",{children:[E("label",{htmlFor:"deal-name",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Deal Name *"}),E(t,{id:"deal-name",value:P,onChange:(X)=>O(X.target.value),placeholder:"e.g., Enterprise License - Acme Corp",disabled:z})]}),v("div",{className:"flex gap-3",children:[v("div",{className:"flex-1",children:[E("label",{htmlFor:"deal-value",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Value *"}),E(t,{id:"deal-value",type:"number",min:"0",step:"0.01",value:A,onChange:(X)=>H(X.target.value),placeholder:"50000",disabled:z})]}),v("div",{className:"w-24",children:[E("label",{htmlFor:"deal-currency",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Currency"}),E("select",{id:"deal-currency",value:Q,onChange:(X)=>Y(X.target.value),disabled:z,className:"h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50",children:OJ.map((X)=>E("option",{value:X,children:X},X))})]})]}),v("div",{children:[E("label",{htmlFor:"deal-stage",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Pipeline Stage *"}),E("select",{id:"deal-stage",value:_,onChange:(X)=>W(X.target.value),disabled:z,className:"h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50",children:G.map((X)=>E("option",{value:X.id,children:X.name},X.id))})]}),v("div",{children:[E("label",{htmlFor:"deal-close-date",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Expected Close Date"}),E(t,{id:"deal-close-date",type:"date",value:V,onChange:(X)=>T(X.target.value),disabled:z})]}),b&&E("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:b}),v("div",{className:"flex justify-end gap-3 pt-2",children:[E(_J,{type:"button",variant:"ghost",onPress:K,disabled:z,children:"Cancel"}),E(_J,{type:"submit",disabled:z,children:z?"Creating...":"Create Deal"})]})]})]})]})}import{Button as y}from"@contractspec/lib.design-system";import{useState as g}from"react";import{jsx as $,jsxs as w,Fragment as EJ}from"react/jsx-runtime";function fJ(J,K){return new Intl.NumberFormat("en-US",{style:"currency",currency:K,minimumFractionDigits:0,maximumFractionDigits:0}).format(J)}function QJ({isOpen:J,deal:K,stages:N,onClose:G,onWin:z,onLose:P,onMove:O,isLoading:A=!1}){let[H,Q]=g("menu"),[Y,_]=g(""),[W,V]=g(""),[T,b]=g(""),[q,Z]=g(""),[X,R]=g(null),k=()=>{Q("menu"),_(""),V(""),b(""),Z(""),R(null)},L=()=>{k(),G()},c=async()=>{if(!K)return;R(null);try{await z({dealId:K.id,wonSource:Y.trim()||void 0,notes:T.trim()||void 0}),L()}catch(F){R(F instanceof Error?F.message:"Failed to mark deal as won")}},n=async()=>{if(!K)return;if(R(null),!W.trim()){R("Please provide a reason for losing the deal");return}try{await P({dealId:K.id,lostReason:W.trim(),notes:T.trim()||void 0}),L()}catch(F){R(F instanceof Error?F.message:"Failed to mark deal as lost")}},M=async()=>{if(!K)return;if(R(null),!q){R("Please select a stage");return}if(q===K.stageId){R("Deal is already in this stage");return}try{await O({dealId:K.id,stageId:q}),L()}catch(F){R(F instanceof Error?F.message:"Failed to move deal")}};if(!J||!K)return null;return w("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[$("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm",onClick:L,role:"button",tabIndex:0,onKeyDown:(F)=>{if(F.key==="Enter"||F.key===" ")L()},"aria-label":"Close modal"}),w("div",{className:"relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",children:[w("div",{className:"mb-4 border-border border-b pb-4",children:[$("h2",{className:"font-semibold text-xl",children:K.name}),$("p",{className:"font-medium text-lg text-primary",children:fJ(K.value,K.currency)}),$("span",{className:`mt-2 inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${K.status==="WON"?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":K.status==="LOST"?"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400":"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}`,children:K.status})]}),H==="menu"&&w("div",{className:"space-y-3",children:[K.status==="OPEN"&&w(EJ,{children:[w(y,{className:"w-full justify-start",variant:"ghost",onPress:()=>Q("win"),children:[$("span",{className:"mr-2",children:"\uD83C\uDFC6"})," Mark as Won"]}),w(y,{className:"w-full justify-start",variant:"ghost",onPress:()=>Q("lose"),children:[$("span",{className:"mr-2",children:"\u274C"})," Mark as Lost"]}),w(y,{className:"w-full justify-start",variant:"ghost",onPress:()=>{Z(K.stageId),Q("move")},children:[$("span",{className:"mr-2",children:"\u27A1\uFE0F"})," Move to Stage"]})]}),K.status!=="OPEN"&&w("p",{className:"py-4 text-center text-muted-foreground",children:["This deal is already ",K.status.toLowerCase(),". No actions available."]}),$("div",{className:"border-border border-t pt-3",children:$(y,{className:"w-full",variant:"outline",onPress:L,children:"Close"})})]}),H==="win"&&w("div",{className:"space-y-4",children:[w("div",{children:[$("label",{htmlFor:"won-source",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"How did you win this deal?"}),w("select",{id:"won-source",value:Y,onChange:(F)=>_(F.target.value),className:"h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring",children:[$("option",{value:"",children:"Select a source..."}),$("option",{value:"referral",children:"Referral"}),$("option",{value:"cold_outreach",children:"Cold Outreach"}),$("option",{value:"inbound",children:"Inbound Lead"}),$("option",{value:"upsell",children:"Upsell"}),$("option",{value:"other",children:"Other"})]})]}),w("div",{children:[$("label",{htmlFor:"win-notes",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Notes (optional)"}),$("textarea",{id:"win-notes",value:T,onChange:(F)=>b(F.target.value),placeholder:"Any additional notes about the win...",rows:3,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"})]}),X&&$("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:X}),w("div",{className:"flex justify-end gap-3 pt-2",children:[$(y,{variant:"ghost",onPress:()=>Q("menu"),disabled:A,children:"Back"}),$(y,{onPress:c,disabled:A,children:A?"Processing...":"\uD83C\uDFC6 Confirm Win"})]})]}),H==="lose"&&w("div",{className:"space-y-4",children:[w("div",{children:[$("label",{htmlFor:"lost-reason",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Why was this deal lost? *"}),w("select",{id:"lost-reason",value:W,onChange:(F)=>V(F.target.value),className:"h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring",children:[$("option",{value:"",children:"Select a reason..."}),$("option",{value:"price",children:"Price too high"}),$("option",{value:"competitor",children:"Lost to competitor"}),$("option",{value:"no_budget",children:"No budget"}),$("option",{value:"no_decision",children:"No decision made"}),$("option",{value:"timing",children:"Bad timing"}),$("option",{value:"product_fit",children:"Product not a fit"}),$("option",{value:"other",children:"Other"})]})]}),w("div",{children:[$("label",{htmlFor:"lose-notes",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Notes (optional)"}),$("textarea",{id:"lose-notes",value:T,onChange:(F)=>b(F.target.value),placeholder:"Any additional details...",rows:3,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"})]}),X&&$("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:X}),w("div",{className:"flex justify-end gap-3 pt-2",children:[$(y,{variant:"ghost",onPress:()=>Q("menu"),disabled:A,children:"Back"}),$(y,{variant:"destructive",onPress:n,disabled:A,children:A?"Processing...":"\u274C Confirm Loss"})]})]}),H==="move"&&w("div",{className:"space-y-4",children:[w("div",{children:[$("label",{htmlFor:"move-stage",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Move to Stage"}),$("select",{id:"move-stage",value:q,onChange:(F)=>Z(F.target.value),className:"h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring",children:N.map((F)=>w("option",{value:F.id,children:[F.name,F.id===K.stageId?" (current)":""]},F.id))})]}),X&&$("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:X}),w("div",{className:"flex justify-end gap-3 pt-2",children:[$(y,{variant:"ghost",onPress:()=>Q("menu"),disabled:A,children:"Back"}),$(y,{onPress:M,disabled:A,children:A?"Moving...":"\u27A1\uFE0F Move Deal"})]})]})]})]})}import{Button as hJ,DataTable as TJ,LoaderBlock as BJ}from"@contractspec/lib.design-system";import{useContractTable as bJ}from"@contractspec/lib.presentation-runtime-react";import{Badge as MJ}from"@contractspec/lib.ui-kit-web/ui/badge";import{HStack as j,VStack as s}from"@contractspec/lib.ui-kit-web/ui/stack";import{Text as B}from"@contractspec/lib.ui-kit-web/ui/text";import*as e from"react";import{jsx as f,jsxs as I}from"react/jsx-runtime";function kJ(J,K="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:K,minimumFractionDigits:0,maximumFractionDigits:0}).format(J)}function vJ(J){switch(J){case"WON":return"default";case"LOST":return"destructive";case"STALE":return"outline";default:return"secondary"}}function yJ({deals:J,totalItems:K,pageIndex:N,pageSize:G,sorting:z,loading:P,onSortingChange:O,onPaginationChange:A,onDealClick:H}){let Q=bJ({data:J,columns:[{id:"deal",header:"Deal",label:"Deal",accessor:(Y)=>Y.name,cell:({item:Y})=>I(s,{gap:"xs",children:[f(B,{className:"font-medium text-sm",children:Y.name}),f(B,{className:"text-muted-foreground text-xs",children:Y.companyId??"Unassigned company"})]}),size:240,minSize:180,canSort:!0,canPin:!0,canResize:!0},{id:"value",header:"Value",label:"Value",accessorKey:"value",cell:({item:Y})=>kJ(Y.value,Y.currency),align:"right",size:140,canSort:!0,canResize:!0},{id:"status",header:"Status",label:"Status",accessorKey:"status",cell:({value:Y})=>f(MJ,{variant:vJ(Y),children:String(Y)}),size:130,canSort:!0,canHide:!0,canPin:!0,canResize:!0},{id:"expectedCloseDate",header:"Expected Close",label:"Expected Close",accessor:(Y)=>Y.expectedCloseDate?.toISOString()??"",cell:({item:Y})=>Y.expectedCloseDate?.toLocaleDateString()??"Not scheduled",size:170,canSort:!0,canHide:!0,canResize:!0},{id:"updatedAt",header:"Updated",label:"Updated",accessor:(Y)=>Y.updatedAt.toISOString(),cell:({item:Y})=>Y.updatedAt.toLocaleDateString(),size:140,canSort:!0,canHide:!0,canResize:!0},{id:"actions",header:"Actions",label:"Actions",accessor:(Y)=>Y.id,cell:({item:Y})=>f(hJ,{variant:"ghost",size:"sm",onPress:()=>H?.(Y.id),children:"Actions"}),size:120,canSort:!1,canHide:!1,canPin:!1,canResize:!1}],executionMode:"server",selectionMode:"multiple",totalItems:K,state:{sorting:z,pagination:{pageIndex:N,pageSize:G}},onSortingChange:O,onPaginationChange:A,initialState:{columnVisibility:{updatedAt:!1},columnPinning:{left:["deal","status"],right:[]}},renderExpandedContent:(Y)=>I(s,{gap:"sm",className:"py-2",children:[I(j,{justify:"between",children:[f(B,{className:"font-medium text-sm",children:"Owner"}),f(B,{className:"text-muted-foreground text-sm",children:Y.ownerId})]}),I(j,{justify:"between",children:[f(B,{className:"font-medium text-sm",children:"Contact"}),f(B,{className:"text-muted-foreground text-sm",children:Y.contactId??"No linked contact"})]}),Y.wonSource?I(j,{justify:"between",children:[f(B,{className:"font-medium text-sm",children:"Won Source"}),f(B,{className:"text-muted-foreground text-sm",children:Y.wonSource})]}):null,Y.lostReason?I(j,{justify:"between",children:[f(B,{className:"font-medium text-sm",children:"Lost Reason"}),f(B,{className:"text-muted-foreground text-sm",children:Y.lostReason})]}):null,Y.notes?I(s,{gap:"xs",children:[f(B,{className:"font-medium text-sm",children:"Notes"}),f(B,{className:"text-muted-foreground text-sm",children:Y.notes})]}):null]}),getCanExpand:()=>!0});return f(TJ,{controller:Q,title:"All Deals",description:"Server-mode table using the shared ContractSpec controller.",loading:P,toolbar:I(j,{gap:"sm",className:"flex-wrap",children:[I(B,{className:"text-muted-foreground text-sm",children:["Selected ",Q.selectedRowIds.length]}),I(B,{className:"text-muted-foreground text-sm",children:[K," total deals"]})]}),footer:`Page ${Q.pageIndex+1} of ${Q.pageCount}`,emptyState:f("div",{className:"rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",children:"No deals found"})})}function zJ({onDealClick:J}){let[K,N]=e.useState([{id:"value",desc:!0}]),[G,z]=e.useState({pageIndex:0,pageSize:3}),{data:P,loading:O}=x({pageIndex:G.pageIndex,pageSize:G.pageSize,sorting:K});if(O&&!P)return f(BJ,{label:"Loading deals..."});return f(yJ,{deals:P?.deals??[],totalItems:P?.total??0,pageIndex:G.pageIndex,pageSize:G.pageSize,sorting:K,loading:O,onSortingChange:(A)=>{N(A),z((H)=>({...H,pageIndex:0}))},onPaginationChange:z,onDealClick:J})}import{Button as IJ,ErrorState as LJ,LoaderBlock as DJ,StatCard as r,StatCardGroup as CJ}from"@contractspec/lib.design-system";import{Tabs as mJ,TabsContent as JJ,TabsList as SJ,TabsTrigger as KJ}from"@contractspec/lib.ui-kit-web/ui/tabs";import{useCallback as FJ,useState as XJ}from"react";import{jsx as U,jsxs as h}from"react/jsx-runtime";function l(J,K="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:K,minimumFractionDigits:0,maximumFractionDigits:0}).format(J)}function fK(){let[J,K]=XJ(!1),[N,G]=XJ(null),[z,P]=XJ(!1),{data:O,dealsByStage:A,stages:H,loading:Q,error:Y,stats:_,refetch:W}=x(),V=GJ({onSuccess:()=>{W()}}),T=FJ((q)=>{let Z=A?Object.values(A).flat().find((X)=>X.id===q):null;if(Z)G(Z),P(!0)},[A]),b=FJ(async(q,Z)=>{await V.moveDeal({dealId:q,stageId:Z})},[V]);if(Q&&!O)return U(DJ,{label:"Loading CRM..."});if(Y)return U(LJ,{title:"Failed to load CRM",description:Y.message,onRetry:W,retryLabel:"Retry"});return h("div",{className:"space-y-6",children:[h("div",{className:"flex items-center justify-between",children:[U("h2",{className:"font-bold text-2xl",children:"CRM Pipeline"}),h(IJ,{onClick:()=>K(!0),children:[U("span",{className:"mr-2",children:"+"})," Create Deal"]})]}),_&&h(CJ,{children:[U(r,{label:"Total Pipeline",value:l(_.totalValue),hint:`${_.total} deals`}),U(r,{label:"Open Deals",value:l(_.openValue),hint:`${_.openCount} active`}),U(r,{label:"Won",value:l(_.wonValue),hint:`${_.wonCount} closed`}),U(r,{label:"Lost",value:_.lostCount,hint:"deals lost"})]}),h(mJ,{defaultValue:"pipeline",className:"w-full",children:[h(SJ,{children:[h(KJ,{value:"pipeline",children:[U("span",{className:"mr-2",children:"\uD83D\uDCCA"}),"Pipeline"]}),h(KJ,{value:"list",children:[U("span",{className:"mr-2",children:"\uD83D\uDCCB"}),"All Deals"]}),h(KJ,{value:"metrics",children:[U("span",{className:"mr-2",children:"\uD83D\uDCC8"}),"Metrics"]})]}),U(JJ,{value:"pipeline",className:"min-h-[400px]",children:U($J,{dealsByStage:A,stages:H,onDealClick:T,onDealMove:b})}),U(JJ,{value:"list",className:"min-h-[400px]",children:U(zJ,{onDealClick:T})}),U(JJ,{value:"metrics",className:"min-h-[400px]",children:U(pJ,{stats:_})})]}),U(qJ,{isOpen:J,onClose:()=>K(!1),onSubmit:async(q)=>{await V.createDeal(q)},stages:H,isLoading:V.createState.loading}),U(QJ,{isOpen:z,deal:N,stages:H,onClose:()=>{P(!1),G(null)},onWin:async(q)=>{await V.winDeal(q)},onLose:async(q)=>{await V.loseDeal(q)},onMove:async(q)=>{await V.moveDeal(q),W()},isLoading:V.isLoading})]})}function pJ({stats:J}){if(!J)return null;return U("div",{className:"space-y-6",children:h("div",{className:"rounded-xl border border-border bg-card p-6",children:[U("h3",{className:"mb-4 font-semibold text-lg",children:"Pipeline Overview"}),h("dl",{className:"grid gap-4 sm:grid-cols-3",children:[h("div",{children:[U("dt",{className:"text-muted-foreground text-sm",children:"Win Rate"}),h("dd",{className:"font-semibold text-2xl",children:[J.total>0?(J.wonCount/J.total*100).toFixed(0):0,"%"]})]}),h("div",{children:[U("dt",{className:"text-muted-foreground text-sm",children:"Avg Deal Size"}),U("dd",{className:"font-semibold text-2xl",children:l(J.total>0?J.totalValue/J.total:0)})]}),h("div",{children:[U("dt",{className:"text-muted-foreground text-sm",children:"Conversion"}),h("dd",{className:"font-semibold text-2xl",children:[J.wonCount," / ",J.total]})]})]})]})})}export{fK as CrmDashboard};