@contractspec/example.saas-boilerplate 3.8.9 → 3.8.11

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 (156) hide show
  1. package/.turbo/turbo-build.log +155 -155
  2. package/CHANGELOG.md +34 -0
  3. package/dist/billing/billing.entity.js +1 -113
  4. package/dist/billing/billing.enum.js +1 -19
  5. package/dist/billing/billing.event.js +1 -90
  6. package/dist/billing/billing.handler.js +1 -148
  7. package/dist/billing/billing.operations.js +1 -278
  8. package/dist/billing/billing.presentation.js +1 -55
  9. package/dist/billing/billing.schema.js +1 -121
  10. package/dist/billing/index.js +1 -691
  11. package/dist/browser/billing/billing.entity.js +1 -113
  12. package/dist/browser/billing/billing.enum.js +1 -19
  13. package/dist/browser/billing/billing.event.js +1 -90
  14. package/dist/browser/billing/billing.handler.js +1 -148
  15. package/dist/browser/billing/billing.operations.js +1 -278
  16. package/dist/browser/billing/billing.presentation.js +1 -55
  17. package/dist/browser/billing/billing.schema.js +1 -121
  18. package/dist/browser/billing/index.js +1 -691
  19. package/dist/browser/dashboard/dashboard.presentation.js +1 -55
  20. package/dist/browser/dashboard/index.js +1 -55
  21. package/dist/browser/docs/index.js +5 -49
  22. package/dist/browser/docs/saas-boilerplate.docblock.js +5 -49
  23. package/dist/browser/example.js +1 -39
  24. package/dist/browser/handlers/index.js +2 -358
  25. package/dist/browser/handlers/saas.handlers.js +2 -134
  26. package/dist/browser/index.js +9 -3591
  27. package/dist/browser/presentations/index.js +1 -299
  28. package/dist/browser/project/index.js +1 -793
  29. package/dist/browser/project/project.entity.js +1 -77
  30. package/dist/browser/project/project.enum.js +1 -18
  31. package/dist/browser/project/project.event.js +1 -103
  32. package/dist/browser/project/project.handler.js +1 -178
  33. package/dist/browser/project/project.operations.js +1 -372
  34. package/dist/browser/project/project.presentation.js +1 -180
  35. package/dist/browser/project/project.schema.js +1 -134
  36. package/dist/browser/saas-boilerplate.feature.js +1 -304
  37. package/dist/browser/seeders/index.js +2 -20
  38. package/dist/browser/settings/index.js +1 -75
  39. package/dist/browser/settings/settings.entity.js +1 -74
  40. package/dist/browser/settings/settings.enum.js +1 -11
  41. package/dist/browser/shared/mock-data.js +1 -104
  42. package/dist/browser/tests/operations.test-spec.js +1 -112
  43. package/dist/browser/ui/SaasDashboard.js +1 -1239
  44. package/dist/browser/ui/SaasDashboard.visualizations.js +1 -249
  45. package/dist/browser/ui/SaasProjectList.js +1 -162
  46. package/dist/browser/ui/SaasSettingsPanel.js +1 -145
  47. package/dist/browser/ui/hooks/index.js +1 -159
  48. package/dist/browser/ui/hooks/useProjectList.js +1 -66
  49. package/dist/browser/ui/hooks/useProjectMutations.js +1 -91
  50. package/dist/browser/ui/index.js +5 -2077
  51. package/dist/browser/ui/modals/CreateProjectModal.js +1 -153
  52. package/dist/browser/ui/modals/ProjectActionsModal.js +1 -335
  53. package/dist/browser/ui/modals/index.js +1 -487
  54. package/dist/browser/ui/overlays/demo-overlays.js +1 -61
  55. package/dist/browser/ui/overlays/index.js +1 -61
  56. package/dist/browser/ui/renderers/index.js +5 -901
  57. package/dist/browser/ui/renderers/project-list.markdown.js +5 -725
  58. package/dist/browser/ui/renderers/project-list.renderer.js +1 -177
  59. package/dist/browser/visualizations/catalog.js +1 -155
  60. package/dist/browser/visualizations/index.js +1 -217
  61. package/dist/browser/visualizations/selectors.js +1 -210
  62. package/dist/dashboard/dashboard.presentation.js +1 -55
  63. package/dist/dashboard/index.js +1 -55
  64. package/dist/docs/index.js +5 -49
  65. package/dist/docs/saas-boilerplate.docblock.js +5 -49
  66. package/dist/example.js +1 -39
  67. package/dist/handlers/index.js +2 -358
  68. package/dist/handlers/saas.handlers.js +2 -134
  69. package/dist/index.js +9 -3591
  70. package/dist/node/billing/billing.entity.js +1 -113
  71. package/dist/node/billing/billing.enum.js +1 -19
  72. package/dist/node/billing/billing.event.js +1 -90
  73. package/dist/node/billing/billing.handler.js +1 -148
  74. package/dist/node/billing/billing.operations.js +1 -278
  75. package/dist/node/billing/billing.presentation.js +1 -55
  76. package/dist/node/billing/billing.schema.js +1 -121
  77. package/dist/node/billing/index.js +1 -691
  78. package/dist/node/dashboard/dashboard.presentation.js +1 -55
  79. package/dist/node/dashboard/index.js +1 -55
  80. package/dist/node/docs/index.js +5 -49
  81. package/dist/node/docs/saas-boilerplate.docblock.js +5 -49
  82. package/dist/node/example.js +1 -39
  83. package/dist/node/handlers/index.js +2 -358
  84. package/dist/node/handlers/saas.handlers.js +2 -134
  85. package/dist/node/index.js +9 -3591
  86. package/dist/node/presentations/index.js +1 -299
  87. package/dist/node/project/index.js +1 -793
  88. package/dist/node/project/project.entity.js +1 -77
  89. package/dist/node/project/project.enum.js +1 -18
  90. package/dist/node/project/project.event.js +1 -103
  91. package/dist/node/project/project.handler.js +1 -178
  92. package/dist/node/project/project.operations.js +1 -372
  93. package/dist/node/project/project.presentation.js +1 -180
  94. package/dist/node/project/project.schema.js +1 -134
  95. package/dist/node/saas-boilerplate.feature.js +1 -304
  96. package/dist/node/seeders/index.js +2 -20
  97. package/dist/node/settings/index.js +1 -75
  98. package/dist/node/settings/settings.entity.js +1 -74
  99. package/dist/node/settings/settings.enum.js +1 -11
  100. package/dist/node/shared/mock-data.js +1 -104
  101. package/dist/node/tests/operations.test-spec.js +1 -112
  102. package/dist/node/ui/SaasDashboard.js +1 -1239
  103. package/dist/node/ui/SaasDashboard.visualizations.js +1 -249
  104. package/dist/node/ui/SaasProjectList.js +1 -162
  105. package/dist/node/ui/SaasSettingsPanel.js +1 -145
  106. package/dist/node/ui/hooks/index.js +1 -159
  107. package/dist/node/ui/hooks/useProjectList.js +1 -66
  108. package/dist/node/ui/hooks/useProjectMutations.js +1 -91
  109. package/dist/node/ui/index.js +5 -2077
  110. package/dist/node/ui/modals/CreateProjectModal.js +1 -153
  111. package/dist/node/ui/modals/ProjectActionsModal.js +1 -335
  112. package/dist/node/ui/modals/index.js +1 -487
  113. package/dist/node/ui/overlays/demo-overlays.js +1 -61
  114. package/dist/node/ui/overlays/index.js +1 -61
  115. package/dist/node/ui/renderers/index.js +5 -901
  116. package/dist/node/ui/renderers/project-list.markdown.js +5 -725
  117. package/dist/node/ui/renderers/project-list.renderer.js +1 -177
  118. package/dist/node/visualizations/catalog.js +1 -155
  119. package/dist/node/visualizations/index.js +1 -217
  120. package/dist/node/visualizations/selectors.js +1 -210
  121. package/dist/presentations/index.js +1 -299
  122. package/dist/project/index.js +1 -793
  123. package/dist/project/project.entity.js +1 -77
  124. package/dist/project/project.enum.js +1 -18
  125. package/dist/project/project.event.js +1 -103
  126. package/dist/project/project.handler.js +1 -178
  127. package/dist/project/project.operations.js +1 -372
  128. package/dist/project/project.presentation.js +1 -180
  129. package/dist/project/project.schema.js +1 -134
  130. package/dist/saas-boilerplate.feature.js +1 -304
  131. package/dist/seeders/index.js +2 -20
  132. package/dist/settings/index.js +1 -75
  133. package/dist/settings/settings.entity.js +1 -74
  134. package/dist/settings/settings.enum.js +1 -11
  135. package/dist/shared/mock-data.js +1 -104
  136. package/dist/tests/operations.test-spec.js +1 -112
  137. package/dist/ui/SaasDashboard.js +1 -1239
  138. package/dist/ui/SaasDashboard.visualizations.js +1 -249
  139. package/dist/ui/SaasProjectList.js +1 -162
  140. package/dist/ui/SaasSettingsPanel.js +1 -145
  141. package/dist/ui/hooks/index.js +1 -159
  142. package/dist/ui/hooks/useProjectList.js +1 -66
  143. package/dist/ui/hooks/useProjectMutations.js +1 -91
  144. package/dist/ui/index.js +5 -2077
  145. package/dist/ui/modals/CreateProjectModal.js +1 -153
  146. package/dist/ui/modals/ProjectActionsModal.js +1 -335
  147. package/dist/ui/modals/index.js +1 -487
  148. package/dist/ui/overlays/demo-overlays.js +1 -61
  149. package/dist/ui/overlays/index.js +1 -61
  150. package/dist/ui/renderers/index.js +5 -901
  151. package/dist/ui/renderers/project-list.markdown.js +5 -725
  152. package/dist/ui/renderers/project-list.renderer.js +1 -177
  153. package/dist/visualizations/catalog.js +1 -155
  154. package/dist/visualizations/index.js +1 -217
  155. package/dist/visualizations/selectors.js +1 -210
  156. package/package.json +12 -12
package/dist/ui/index.js CHANGED
@@ -1,2078 +1,6 @@
1
1
  // @bun
2
- // src/shared/mock-data.ts
3
- var MOCK_PROJECTS = [
4
- {
5
- id: "proj-1",
6
- name: "Marketing Website",
7
- description: "Main company website redesign project",
8
- slug: "marketing-website",
9
- organizationId: "demo-org",
10
- createdBy: "user-1",
11
- status: "ACTIVE",
12
- isPublic: false,
13
- tags: ["marketing", "website", "redesign"],
14
- createdAt: new Date("2024-01-15T10:00:00Z"),
15
- updatedAt: new Date("2024-03-20T14:30:00Z")
16
- },
17
- {
18
- id: "proj-2",
19
- name: "Mobile App v2",
20
- description: "Next generation mobile application",
21
- slug: "mobile-app-v2",
22
- organizationId: "demo-org",
23
- createdBy: "user-2",
24
- status: "ACTIVE",
25
- isPublic: false,
26
- tags: ["mobile", "app", "v2"],
27
- createdAt: new Date("2024-02-01T09:00:00Z"),
28
- updatedAt: new Date("2024-04-05T11:15:00Z")
29
- },
30
- {
31
- id: "proj-3",
32
- name: "API Integration",
33
- description: "Third-party API integration project",
34
- slug: "api-integration",
35
- organizationId: "demo-org",
36
- createdBy: "user-1",
37
- status: "DRAFT",
38
- isPublic: false,
39
- tags: ["api", "integration"],
40
- createdAt: new Date("2024-03-10T08:00:00Z"),
41
- updatedAt: new Date("2024-03-10T08:00:00Z")
42
- },
43
- {
44
- id: "proj-4",
45
- name: "Analytics Dashboard",
46
- description: "Internal analytics and reporting dashboard",
47
- slug: "analytics-dashboard",
48
- organizationId: "demo-org",
49
- createdBy: "user-3",
50
- status: "ARCHIVED",
51
- isPublic: true,
52
- tags: ["analytics", "dashboard", "reporting"],
53
- createdAt: new Date("2023-10-01T12:00:00Z"),
54
- updatedAt: new Date("2024-02-28T16:45:00Z")
55
- }
56
- ];
57
- var MOCK_SUBSCRIPTION = {
58
- id: "sub-1",
59
- organizationId: "demo-org",
60
- planId: "pro",
61
- planName: "Professional",
62
- status: "ACTIVE",
63
- currentPeriodStart: new Date("2024-04-01T00:00:00Z"),
64
- currentPeriodEnd: new Date("2024-05-01T00:00:00Z"),
65
- limits: {
66
- projects: 25,
67
- users: 10,
68
- storage: 50,
69
- apiCalls: 1e5
70
- },
71
- usage: {
72
- projects: 4,
73
- users: 5,
74
- storage: 12.5,
75
- apiCalls: 45230
76
- }
77
- };
78
- var MOCK_USAGE_SUMMARY = {
79
- organizationId: "demo-org",
80
- period: "current_month",
81
- apiCalls: {
82
- total: 45230,
83
- limit: 1e5,
84
- percentUsed: 45.23
85
- },
86
- storage: {
87
- totalGb: 12.5,
88
- limitGb: 50,
89
- percentUsed: 25
90
- },
91
- activeProjects: 4,
92
- activeUsers: 5,
93
- breakdown: [
94
- { date: "2024-04-01", apiCalls: 3200, storageGb: 12.1 },
95
- { date: "2024-04-02", apiCalls: 2800, storageGb: 12.2 },
96
- { date: "2024-04-03", apiCalls: 4100, storageGb: 12.3 },
97
- { date: "2024-04-04", apiCalls: 3600, storageGb: 12.4 },
98
- { date: "2024-04-05", apiCalls: 3800, storageGb: 12.5 }
99
- ]
100
- };
101
-
102
- // src/billing/billing.handler.ts
103
- async function mockGetSubscriptionHandler() {
104
- return MOCK_SUBSCRIPTION;
105
- }
106
- async function mockGetUsageSummaryHandler(input) {
107
- return {
108
- ...MOCK_USAGE_SUMMARY,
109
- period: input.period ?? "current_month"
110
- };
111
- }
112
- async function mockRecordUsageHandler(input) {
113
- const currentUsage = MOCK_USAGE_SUMMARY.apiCalls.total;
114
- const newTotal = currentUsage + input.quantity;
115
- return {
116
- recorded: true,
117
- newTotal
118
- };
119
- }
120
- async function mockCheckFeatureAccessHandler(input) {
121
- const { feature } = input;
122
- const featureMap = {
123
- custom_domains: {
124
- allowed: true
125
- },
126
- api_access: {
127
- allowed: true,
128
- currentUsage: MOCK_USAGE_SUMMARY.apiCalls.total,
129
- limit: MOCK_USAGE_SUMMARY.apiCalls.limit
130
- },
131
- advanced_analytics: {
132
- allowed: false,
133
- reason: "FEATURE_NOT_INCLUDED"
134
- },
135
- unlimited_projects: {
136
- allowed: false,
137
- reason: "PLAN_LIMIT",
138
- currentUsage: MOCK_SUBSCRIPTION.usage.projects,
139
- limit: MOCK_SUBSCRIPTION.limits.projects
140
- }
141
- };
142
- return featureMap[feature] ?? { allowed: true };
143
- }
144
-
145
- // src/project/project.handler.ts
146
- async function mockListProjectsHandler(input) {
147
- const { status, search, limit = 20, offset = 0 } = input;
148
- let filtered = [...MOCK_PROJECTS];
149
- if (status && status !== "all") {
150
- filtered = filtered.filter((p) => p.status === status);
151
- }
152
- if (search) {
153
- const q = search.toLowerCase();
154
- filtered = filtered.filter((p) => p.name.toLowerCase().includes(q) || p.description?.toLowerCase().includes(q) || p.tags.some((t) => t.toLowerCase().includes(q)));
155
- }
156
- filtered.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
157
- const total = filtered.length;
158
- const projects = filtered.slice(offset, offset + limit);
159
- return {
160
- projects,
161
- total
162
- };
163
- }
164
- async function mockGetProjectHandler(input) {
165
- const project = MOCK_PROJECTS.find((p) => p.id === input.projectId);
166
- if (!project) {
167
- throw new Error("NOT_FOUND");
168
- }
169
- return project;
170
- }
171
- async function mockCreateProjectHandler(input, context) {
172
- if (input.slug) {
173
- const exists = MOCK_PROJECTS.some((p) => p.slug === input.slug);
174
- if (exists) {
175
- throw new Error("SLUG_EXISTS");
176
- }
177
- }
178
- const now = new Date;
179
- return {
180
- id: `proj-${Date.now()}`,
181
- name: input.name,
182
- description: input.description,
183
- slug: input.slug ?? input.name.toLowerCase().replace(/\s+/g, "-"),
184
- organizationId: context.organizationId,
185
- createdBy: context.userId,
186
- status: "DRAFT",
187
- isPublic: input.isPublic ?? false,
188
- tags: input.tags ?? [],
189
- createdAt: now,
190
- updatedAt: now
191
- };
192
- }
193
- async function mockUpdateProjectHandler(input) {
194
- const project = MOCK_PROJECTS.find((p) => p.id === input.projectId);
195
- if (!project) {
196
- throw new Error("NOT_FOUND");
197
- }
198
- return {
199
- ...project,
200
- name: input.name ?? project.name,
201
- description: input.description ?? project.description,
202
- slug: input.slug ?? project.slug,
203
- isPublic: input.isPublic ?? project.isPublic,
204
- tags: input.tags ?? project.tags,
205
- status: input.status ?? project.status,
206
- updatedAt: new Date
207
- };
208
- }
209
- async function mockDeleteProjectHandler(input) {
210
- const project = MOCK_PROJECTS.find((p) => p.id === input.projectId);
211
- if (!project) {
212
- throw new Error("NOT_FOUND");
213
- }
214
- return { success: true };
215
- }
216
-
217
- // src/handlers/saas.handlers.ts
218
- import { web } from "@contractspec/lib.runtime-sandbox";
219
- var { generateId } = web;
220
- function rowToProject(row) {
221
- return {
222
- id: row.id,
223
- projectId: row.projectId,
224
- organizationId: row.organizationId,
225
- name: row.name,
226
- description: row.description ?? undefined,
227
- status: row.status,
228
- tier: row.tier,
229
- createdAt: new Date(row.createdAt),
230
- updatedAt: new Date(row.updatedAt)
231
- };
232
- }
233
- function rowToSubscription(row) {
234
- return {
235
- id: row.id,
236
- projectId: row.projectId,
237
- organizationId: row.organizationId,
238
- plan: row.plan,
239
- status: row.status,
240
- billingCycle: row.billingCycle,
241
- currentPeriodStart: new Date(row.currentPeriodStart),
242
- currentPeriodEnd: new Date(row.currentPeriodEnd),
243
- cancelAtPeriodEnd: Boolean(row.cancelAtPeriodEnd)
244
- };
245
- }
246
- function createSaasHandlers(db) {
247
- async function listProjects(input) {
248
- const {
249
- projectId,
250
- organizationId,
251
- status,
252
- search,
253
- limit = 20,
254
- offset = 0
255
- } = input;
256
- let whereClause = "WHERE projectId = ?";
257
- const params = [projectId];
258
- if (organizationId) {
259
- whereClause += " AND organizationId = ?";
260
- params.push(organizationId);
261
- }
262
- if (status && status !== "all") {
263
- whereClause += " AND status = ?";
264
- params.push(status);
265
- }
266
- if (search) {
267
- whereClause += " AND (name LIKE ? OR description LIKE ?)";
268
- params.push(`%${search}%`, `%${search}%`);
269
- }
270
- const countResult = (await db.query(`SELECT COUNT(*) as count FROM saas_project ${whereClause}`, params)).rows;
271
- const total = countResult[0]?.count ?? 0;
272
- const rows = (await db.query(`SELECT * FROM saas_project ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
273
- return {
274
- items: rows.map(rowToProject),
275
- total,
276
- hasMore: offset + rows.length < total
277
- };
278
- }
279
- async function getProject(id) {
280
- const rows = (await db.query(`SELECT * FROM saas_project WHERE id = ?`, [id])).rows;
281
- return rows[0] ? rowToProject(rows[0]) : null;
282
- }
283
- async function createProject(input, context) {
284
- const id = generateId("proj");
285
- const now = new Date().toISOString();
286
- await db.execute(`INSERT INTO saas_project (id, projectId, organizationId, name, description, status, tier, createdAt, updatedAt)
287
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
288
- id,
289
- context.projectId,
290
- context.organizationId,
291
- input.name,
292
- input.description ?? null,
293
- "DRAFT",
294
- input.tier ?? "FREE",
295
- now,
296
- now
297
- ]);
298
- const rows = (await db.query(`SELECT * FROM saas_project WHERE id = ?`, [id])).rows;
299
- return rowToProject(rows[0]);
300
- }
301
- async function updateProject(input) {
302
- const now = new Date().toISOString();
303
- const updates = ["updatedAt = ?"];
304
- const params = [now];
305
- if (input.name !== undefined) {
306
- updates.push("name = ?");
307
- params.push(input.name);
308
- }
309
- if (input.description !== undefined) {
310
- updates.push("description = ?");
311
- params.push(input.description);
312
- }
313
- if (input.status !== undefined) {
314
- updates.push("status = ?");
315
- params.push(input.status);
316
- }
317
- params.push(input.id);
318
- await db.execute(`UPDATE saas_project SET ${updates.join(", ")} WHERE id = ?`, params);
319
- const rows = (await db.query(`SELECT * FROM saas_project WHERE id = ?`, [input.id])).rows;
320
- if (!rows[0]) {
321
- throw new Error("NOT_FOUND");
322
- }
323
- return rowToProject(rows[0]);
324
- }
325
- async function deleteProject(id) {
326
- await db.execute(`DELETE FROM saas_project WHERE id = ?`, [id]);
327
- }
328
- async function getSubscription(input) {
329
- let query = `SELECT * FROM saas_subscription WHERE projectId = ?`;
330
- const params = [input.projectId];
331
- if (input.organizationId) {
332
- query += " AND organizationId = ?";
333
- params.push(input.organizationId);
334
- }
335
- query += " LIMIT 1";
336
- const rows = (await db.query(query, params)).rows;
337
- return rows[0] ? rowToSubscription(rows[0]) : null;
338
- }
339
- return {
340
- listProjects,
341
- getProject,
342
- createProject,
343
- updateProject,
344
- deleteProject,
345
- getSubscription
346
- };
347
- }
348
- // src/visualizations/catalog.ts
349
- import {
350
- defineVisualization,
351
- VisualizationRegistry
352
- } from "@contractspec/lib.contracts-spec/visualizations";
353
- var PROJECT_LIST_REF = {
354
- key: "saas.project.list",
355
- version: "1.0.0"
356
- };
357
- var META = {
358
- version: "1.0.0",
359
- domain: "saas",
360
- stability: "experimental",
361
- owners: ["@example.saas-boilerplate"],
362
- tags: ["saas", "visualization", "projects"]
363
- };
364
- var SaasProjectUsageVisualization = defineVisualization({
365
- meta: {
366
- ...META,
367
- key: "saas-boilerplate.visualization.project-usage",
368
- title: "Project Capacity",
369
- description: "Current project count against the current plan limit.",
370
- goal: "Show usage against the active plan allowance.",
371
- context: "SaaS account overview."
372
- },
373
- source: { primary: PROJECT_LIST_REF, resultPath: "data" },
374
- visualization: {
375
- kind: "metric",
376
- measure: "totalProjects",
377
- comparisonMeasure: "projectLimit",
378
- measures: [
379
- {
380
- key: "totalProjects",
381
- label: "Projects",
382
- dataPath: "totalProjects",
383
- format: "number"
384
- },
385
- {
386
- key: "projectLimit",
387
- label: "Plan Limit",
388
- dataPath: "projectLimit",
389
- format: "number"
390
- }
391
- ],
392
- table: { caption: "Current project count and plan limit." }
393
- }
394
- });
395
- var SaasProjectStatusVisualization = defineVisualization({
396
- meta: {
397
- ...META,
398
- key: "saas-boilerplate.visualization.project-status",
399
- title: "Project Status",
400
- description: "Distribution of project states.",
401
- goal: "Show the mix of active, draft, and archived projects.",
402
- context: "Project portfolio overview."
403
- },
404
- source: { primary: PROJECT_LIST_REF, resultPath: "data" },
405
- visualization: {
406
- kind: "pie",
407
- nameDimension: "status",
408
- valueMeasure: "projects",
409
- dimensions: [
410
- { key: "status", label: "Status", dataPath: "status", type: "category" }
411
- ],
412
- measures: [
413
- {
414
- key: "projects",
415
- label: "Projects",
416
- dataPath: "projects",
417
- format: "number"
418
- }
419
- ],
420
- table: { caption: "Project counts by status." }
421
- }
422
- });
423
- var SaasProjectTierVisualization = defineVisualization({
424
- meta: {
425
- ...META,
426
- key: "saas-boilerplate.visualization.project-tiers",
427
- title: "Tier Comparison",
428
- description: "Distribution of projects across tiers.",
429
- goal: "Compare how the current portfolio is distributed by tier.",
430
- context: "Plan and packaging overview."
431
- },
432
- source: { primary: PROJECT_LIST_REF, resultPath: "data" },
433
- visualization: {
434
- kind: "cartesian",
435
- variant: "bar",
436
- xDimension: "tier",
437
- yMeasures: ["projects"],
438
- dimensions: [
439
- { key: "tier", label: "Tier", dataPath: "tier", type: "category" }
440
- ],
441
- measures: [
442
- {
443
- key: "projects",
444
- label: "Projects",
445
- dataPath: "projects",
446
- format: "number",
447
- color: "#1d4ed8"
448
- }
449
- ],
450
- table: { caption: "Project counts by tier." }
451
- }
452
- });
453
- var SaasProjectActivityVisualization = defineVisualization({
454
- meta: {
455
- ...META,
456
- key: "saas-boilerplate.visualization.project-activity",
457
- title: "Recent Project Activity",
458
- description: "Daily project creation activity.",
459
- goal: "Show recent project activity over time.",
460
- context: "Project portfolio trend view."
461
- },
462
- source: { primary: PROJECT_LIST_REF, resultPath: "data" },
463
- visualization: {
464
- kind: "cartesian",
465
- variant: "line",
466
- xDimension: "day",
467
- yMeasures: ["projects"],
468
- dimensions: [{ key: "day", label: "Day", dataPath: "day", type: "time" }],
469
- measures: [
470
- {
471
- key: "projects",
472
- label: "Projects",
473
- dataPath: "projects",
474
- format: "number",
475
- color: "#0f766e"
476
- }
477
- ],
478
- table: { caption: "Daily project creation counts." }
479
- }
480
- });
481
- var SaasVisualizationSpecs = [
482
- SaasProjectUsageVisualization,
483
- SaasProjectStatusVisualization,
484
- SaasProjectTierVisualization,
485
- SaasProjectActivityVisualization
486
- ];
487
- var SaasVisualizationRegistry = new VisualizationRegistry([
488
- ...SaasVisualizationSpecs
489
- ]);
490
- var SaasVisualizationRefs = SaasVisualizationSpecs.map((spec) => ({
491
- key: spec.meta.key,
492
- version: spec.meta.version
493
- }));
494
-
495
- // src/visualizations/selectors.ts
496
- function toDayKey(value) {
497
- const date = value instanceof Date ? value : new Date(value);
498
- return date.toISOString().slice(0, 10);
499
- }
500
- function createSaasVisualizationItems(projects, projectLimit = 10) {
501
- const statusCounts = new Map;
502
- const tierCounts = new Map;
503
- const activityCounts = new Map;
504
- for (const project of projects) {
505
- statusCounts.set(project.status, (statusCounts.get(project.status) ?? 0) + 1);
506
- tierCounts.set(project.tier, (tierCounts.get(project.tier) ?? 0) + 1);
507
- const day = toDayKey(project.createdAt);
508
- activityCounts.set(day, (activityCounts.get(day) ?? 0) + 1);
509
- }
510
- return [
511
- {
512
- key: "saas-capacity",
513
- spec: SaasProjectUsageVisualization,
514
- data: { data: [{ totalProjects: projects.length, projectLimit }] },
515
- title: "Project Capacity",
516
- description: "Current project count compared to the active limit.",
517
- height: 220
518
- },
519
- {
520
- key: "saas-status",
521
- spec: SaasProjectStatusVisualization,
522
- data: {
523
- data: Array.from(statusCounts.entries()).map(([status, count]) => ({
524
- status,
525
- projects: count
526
- }))
527
- },
528
- title: "Project Status",
529
- description: "Status mix across the current project portfolio.",
530
- height: 260
531
- },
532
- {
533
- key: "saas-tier",
534
- spec: SaasProjectTierVisualization,
535
- data: {
536
- data: Array.from(tierCounts.entries()).map(([tier, count]) => ({
537
- tier,
538
- projects: count
539
- }))
540
- },
541
- title: "Tier Comparison",
542
- description: "How projects are distributed across tiers."
543
- },
544
- {
545
- key: "saas-activity",
546
- spec: SaasProjectActivityVisualization,
547
- data: {
548
- data: Array.from(activityCounts.entries()).sort(([left], [right]) => left.localeCompare(right)).map(([day, count]) => ({ day, projects: count }))
549
- },
550
- title: "Recent Project Activity",
551
- description: "Daily project creation activity."
552
- }
553
- ];
554
- }
555
- // src/ui/hooks/useProjectList.ts
556
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
557
- import { useCallback, useEffect, useMemo, useState } from "react";
558
- function useProjectList(options = {}) {
559
- const { handlers, projectId } = useTemplateRuntime();
560
- const { saas: saas2 } = handlers;
561
- const [data, setData] = useState(null);
562
- const [subscription, setSubscription] = useState(null);
563
- const [loading, setLoading] = useState(true);
564
- const [error, setError] = useState(null);
565
- const [page, setPage] = useState(1);
566
- const fetchData = useCallback(async () => {
567
- setLoading(true);
568
- setError(null);
569
- try {
570
- const [projectsResult, subscriptionResult] = await Promise.all([
571
- saas2.listProjects({
572
- projectId,
573
- status: options.status === "all" ? undefined : options.status,
574
- search: options.search,
575
- limit: options.limit ?? 20,
576
- offset: (page - 1) * (options.limit ?? 20)
577
- }),
578
- saas2.getSubscription({ projectId })
579
- ]);
580
- setData({
581
- items: projectsResult.items,
582
- total: projectsResult.total
583
- });
584
- setSubscription(subscriptionResult);
585
- } catch (err) {
586
- setError(err instanceof Error ? err : new Error("Unknown error"));
587
- } finally {
588
- setLoading(false);
589
- }
590
- }, [saas2, projectId, options.status, options.search, options.limit, page]);
591
- useEffect(() => {
592
- fetchData();
593
- }, [fetchData]);
594
- const stats = useMemo(() => {
595
- if (!data)
596
- return null;
597
- const items = data.items;
598
- return {
599
- total: data.total,
600
- activeCount: items.filter((p) => p.status === "ACTIVE").length,
601
- draftCount: items.filter((p) => p.status === "DRAFT").length,
602
- projectLimit: 10,
603
- usagePercent: Math.min(data.total / 10 * 100, 100)
604
- };
605
- }, [data]);
606
- return {
607
- data,
608
- subscription,
609
- loading,
610
- error,
611
- stats,
612
- page,
613
- refetch: fetchData,
614
- nextPage: () => setPage((p) => p + 1),
615
- prevPage: () => page > 1 && setPage((p) => p - 1)
616
- };
617
- }
618
-
619
- // src/ui/hooks/useProjectMutations.ts
620
- import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
621
- import { useCallback as useCallback2, useState as useState2 } from "react";
622
- function useProjectMutations(options = {}) {
623
- const { handlers, projectId } = useTemplateRuntime2();
624
- const { saas: saas2 } = handlers;
625
- const [createState, setCreateState] = useState2({
626
- loading: false,
627
- error: null,
628
- data: null
629
- });
630
- const [updateState, setUpdateState] = useState2({
631
- loading: false,
632
- error: null,
633
- data: null
634
- });
635
- const [deleteState, setDeleteState] = useState2({
636
- loading: false,
637
- error: null,
638
- data: null
639
- });
640
- const createProject = useCallback2(async (input) => {
641
- setCreateState({ loading: true, error: null, data: null });
642
- try {
643
- const result = await saas2.createProject(input, {
644
- projectId,
645
- organizationId: "demo-org"
646
- });
647
- setCreateState({ loading: false, error: null, data: result });
648
- options.onSuccess?.();
649
- return result;
650
- } catch (err) {
651
- const error = err instanceof Error ? err : new Error("Failed to create project");
652
- setCreateState({ loading: false, error, data: null });
653
- options.onError?.(error);
654
- return null;
655
- }
656
- }, [saas2, projectId, options]);
657
- const updateProject = useCallback2(async (input) => {
658
- setUpdateState({ loading: true, error: null, data: null });
659
- try {
660
- const result = await saas2.updateProject(input);
661
- setUpdateState({ loading: false, error: null, data: result });
662
- options.onSuccess?.();
663
- return result;
664
- } catch (err) {
665
- const error = err instanceof Error ? err : new Error("Failed to update project");
666
- setUpdateState({ loading: false, error, data: null });
667
- options.onError?.(error);
668
- return null;
669
- }
670
- }, [saas2, options]);
671
- const deleteProject = useCallback2(async (id) => {
672
- setDeleteState({ loading: true, error: null, data: null });
673
- try {
674
- await saas2.deleteProject(id);
675
- setDeleteState({
676
- loading: false,
677
- error: null,
678
- data: { success: true }
679
- });
680
- options.onSuccess?.();
681
- return true;
682
- } catch (err) {
683
- const error = err instanceof Error ? err : new Error("Failed to delete project");
684
- setDeleteState({ loading: false, error, data: null });
685
- options.onError?.(error);
686
- return false;
687
- }
688
- }, [saas2, options]);
689
- const archiveProject = useCallback2(async (id) => {
690
- return updateProject({ id, status: "ARCHIVED" });
691
- }, [updateProject]);
692
- const activateProject = useCallback2(async (id) => {
693
- return updateProject({ id, status: "ACTIVE" });
694
- }, [updateProject]);
695
- return {
696
- createProject,
697
- updateProject,
698
- deleteProject,
699
- archiveProject,
700
- activateProject,
701
- createState,
702
- updateState,
703
- deleteState,
704
- isLoading: createState.loading || updateState.loading || deleteState.loading
705
- };
706
- }
707
-
708
- // src/ui/hooks/index.ts
709
- "use client";
710
-
711
- // src/ui/modals/CreateProjectModal.tsx
712
- import { Button, Input } from "@contractspec/lib.design-system";
713
- import { useState as useState3 } from "react";
714
- import { jsxDEV } from "react/jsx-dev-runtime";
715
- "use client";
716
- var TIERS = [
717
- { value: "FREE", label: "Free" },
718
- { value: "PRO", label: "Pro" },
719
- { value: "ENTERPRISE", label: "Enterprise" }
720
- ];
721
- function CreateProjectModal({
722
- isOpen,
723
- onClose,
724
- onSubmit,
725
- isLoading = false
726
- }) {
727
- const [name, setName] = useState3("");
728
- const [description, setDescription] = useState3("");
729
- const [tier, setTier] = useState3("FREE");
730
- const [error, setError] = useState3(null);
731
- const handleSubmit = async (e) => {
732
- e.preventDefault();
733
- setError(null);
734
- if (!name.trim()) {
735
- setError("Project name is required");
736
- return;
737
- }
738
- try {
739
- await onSubmit({
740
- name: name.trim(),
741
- description: description.trim() || undefined,
742
- tier
743
- });
744
- setName("");
745
- setDescription("");
746
- setTier("FREE");
747
- onClose();
748
- } catch (err) {
749
- setError(err instanceof Error ? err.message : "Failed to create project");
750
- }
751
- };
752
- if (!isOpen)
753
- return null;
754
- return /* @__PURE__ */ jsxDEV("div", {
755
- className: "fixed inset-0 z-50 flex items-center justify-center",
756
- children: [
757
- /* @__PURE__ */ jsxDEV("div", {
758
- className: "absolute inset-0 bg-background/80 backdrop-blur-sm",
759
- onClick: onClose,
760
- role: "button",
761
- tabIndex: 0,
762
- onKeyDown: (e) => {
763
- if (e.key === "Enter" || e.key === " ")
764
- onClose();
765
- },
766
- "aria-label": "Close modal"
767
- }, undefined, false, undefined, this),
768
- /* @__PURE__ */ jsxDEV("div", {
769
- className: "relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",
770
- children: [
771
- /* @__PURE__ */ jsxDEV("h2", {
772
- className: "mb-4 font-semibold text-xl",
773
- children: "Create New Project"
774
- }, undefined, false, undefined, this),
775
- /* @__PURE__ */ jsxDEV("form", {
776
- onSubmit: handleSubmit,
777
- className: "space-y-4",
778
- children: [
779
- /* @__PURE__ */ jsxDEV("div", {
780
- children: [
781
- /* @__PURE__ */ jsxDEV("label", {
782
- htmlFor: "project-name",
783
- className: "mb-1 block font-medium text-muted-foreground text-sm",
784
- children: "Project Name *"
785
- }, undefined, false, undefined, this),
786
- /* @__PURE__ */ jsxDEV(Input, {
787
- id: "project-name",
788
- value: name,
789
- onChange: (e) => setName(e.target.value),
790
- placeholder: "e.g., My Awesome Project",
791
- disabled: isLoading
792
- }, undefined, false, undefined, this)
793
- ]
794
- }, undefined, true, undefined, this),
795
- /* @__PURE__ */ jsxDEV("div", {
796
- children: [
797
- /* @__PURE__ */ jsxDEV("label", {
798
- htmlFor: "project-description",
799
- className: "mb-1 block font-medium text-muted-foreground text-sm",
800
- children: "Description"
801
- }, undefined, false, undefined, this),
802
- /* @__PURE__ */ jsxDEV("textarea", {
803
- id: "project-description",
804
- value: description,
805
- onChange: (e) => setDescription(e.target.value),
806
- placeholder: "Describe what this project is about...",
807
- rows: 3,
808
- disabled: isLoading,
809
- 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 disabled:opacity-50"
810
- }, undefined, false, undefined, this)
811
- ]
812
- }, undefined, true, undefined, this),
813
- /* @__PURE__ */ jsxDEV("div", {
814
- children: [
815
- /* @__PURE__ */ jsxDEV("label", {
816
- htmlFor: "project-tier",
817
- className: "mb-1 block font-medium text-muted-foreground text-sm",
818
- children: "Tier"
819
- }, undefined, false, undefined, this),
820
- /* @__PURE__ */ jsxDEV("select", {
821
- id: "project-tier",
822
- value: tier,
823
- onChange: (e) => setTier(e.target.value),
824
- disabled: isLoading,
825
- 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",
826
- children: TIERS.map((t) => /* @__PURE__ */ jsxDEV("option", {
827
- value: t.value,
828
- children: t.label
829
- }, t.value, false, undefined, this))
830
- }, undefined, false, undefined, this)
831
- ]
832
- }, undefined, true, undefined, this),
833
- error && /* @__PURE__ */ jsxDEV("div", {
834
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
835
- children: error
836
- }, undefined, false, undefined, this),
837
- /* @__PURE__ */ jsxDEV("div", {
838
- className: "flex justify-end gap-3 pt-2",
839
- children: [
840
- /* @__PURE__ */ jsxDEV(Button, {
841
- type: "button",
842
- variant: "ghost",
843
- onPress: onClose,
844
- disabled: isLoading,
845
- children: "Cancel"
846
- }, undefined, false, undefined, this),
847
- /* @__PURE__ */ jsxDEV(Button, {
848
- type: "submit",
849
- disabled: isLoading,
850
- children: isLoading ? "Creating..." : "Create Project"
851
- }, undefined, false, undefined, this)
852
- ]
853
- }, undefined, true, undefined, this)
854
- ]
855
- }, undefined, true, undefined, this)
856
- ]
857
- }, undefined, true, undefined, this)
858
- ]
859
- }, undefined, true, undefined, this);
860
- }
861
-
862
- // src/ui/modals/ProjectActionsModal.tsx
863
- import { Button as Button2, Input as Input2 } from "@contractspec/lib.design-system";
864
- import { useEffect as useEffect2, useState as useState4 } from "react";
865
- import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
866
- "use client";
867
- function ProjectActionsModal({
868
- isOpen,
869
- project,
870
- onClose,
871
- onUpdate,
872
- onArchive,
873
- onActivate,
874
- onDelete,
875
- isLoading = false
876
- }) {
877
- const [mode, setMode] = useState4("menu");
878
- const [name, setName] = useState4("");
879
- const [description, setDescription] = useState4("");
880
- const [error, setError] = useState4(null);
881
- const resetForm = () => {
882
- setMode("menu");
883
- setError(null);
884
- if (project) {
885
- setName(project.name);
886
- setDescription(project.description ?? "");
887
- }
888
- };
889
- const handleClose = () => {
890
- resetForm();
891
- onClose();
892
- };
893
- useEffect2(() => {
894
- if (project) {
895
- setName(project.name);
896
- setDescription(project.description ?? "");
897
- }
898
- }, [project]);
899
- const handleEdit = async () => {
900
- if (!project)
901
- return;
902
- setError(null);
903
- if (!name.trim()) {
904
- setError("Project name is required");
905
- return;
906
- }
907
- try {
908
- await onUpdate({
909
- id: project.id,
910
- name: name.trim(),
911
- description: description.trim() || undefined
912
- });
913
- handleClose();
914
- } catch (err) {
915
- setError(err instanceof Error ? err.message : "Failed to update project");
916
- }
917
- };
918
- const handleArchive = async () => {
919
- if (!project)
920
- return;
921
- setError(null);
922
- try {
923
- await onArchive(project.id);
924
- handleClose();
925
- } catch (err) {
926
- setError(err instanceof Error ? err.message : "Failed to archive project");
927
- }
928
- };
929
- const handleActivate = async () => {
930
- if (!project)
931
- return;
932
- setError(null);
933
- try {
934
- await onActivate(project.id);
935
- handleClose();
936
- } catch (err) {
937
- setError(err instanceof Error ? err.message : "Failed to activate project");
938
- }
939
- };
940
- const handleDelete = async () => {
941
- if (!project)
942
- return;
943
- setError(null);
944
- try {
945
- await onDelete(project.id);
946
- handleClose();
947
- } catch (err) {
948
- setError(err instanceof Error ? err.message : "Failed to delete project");
949
- }
950
- };
951
- if (!isOpen || !project)
952
- return null;
953
- return /* @__PURE__ */ jsxDEV2("div", {
954
- className: "fixed inset-0 z-50 flex items-center justify-center",
955
- children: [
956
- /* @__PURE__ */ jsxDEV2("div", {
957
- className: "absolute inset-0 bg-background/80 backdrop-blur-sm",
958
- onClick: handleClose,
959
- role: "button",
960
- tabIndex: 0,
961
- onKeyDown: (e) => {
962
- if (e.key === "Enter" || e.key === " ")
963
- handleClose();
964
- },
965
- "aria-label": "Close modal"
966
- }, undefined, false, undefined, this),
967
- /* @__PURE__ */ jsxDEV2("div", {
968
- className: "relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",
969
- children: [
970
- /* @__PURE__ */ jsxDEV2("div", {
971
- className: "mb-4 border-border border-b pb-4",
972
- children: [
973
- /* @__PURE__ */ jsxDEV2("h2", {
974
- className: "font-semibold text-xl",
975
- children: project.name
976
- }, undefined, false, undefined, this),
977
- /* @__PURE__ */ jsxDEV2("p", {
978
- className: "text-muted-foreground text-sm",
979
- children: [
980
- project.tier,
981
- " \xB7 ",
982
- project.status
983
- ]
984
- }, undefined, true, undefined, this)
985
- ]
986
- }, undefined, true, undefined, this),
987
- mode === "menu" && /* @__PURE__ */ jsxDEV2("div", {
988
- className: "space-y-3",
989
- children: [
990
- /* @__PURE__ */ jsxDEV2(Button2, {
991
- className: "w-full justify-start",
992
- variant: "ghost",
993
- onPress: () => setMode("edit"),
994
- children: [
995
- /* @__PURE__ */ jsxDEV2("span", {
996
- className: "mr-2",
997
- children: "\u270F\uFE0F"
998
- }, undefined, false, undefined, this),
999
- " Edit Project"
1000
- ]
1001
- }, undefined, true, undefined, this),
1002
- project.status === "ACTIVE" || project.status === "DRAFT" ? /* @__PURE__ */ jsxDEV2(Button2, {
1003
- className: "w-full justify-start",
1004
- variant: "ghost",
1005
- onPress: () => setMode("archive"),
1006
- children: [
1007
- /* @__PURE__ */ jsxDEV2("span", {
1008
- className: "mr-2",
1009
- children: "\uD83D\uDCE6"
1010
- }, undefined, false, undefined, this),
1011
- " Archive Project"
1012
- ]
1013
- }, undefined, true, undefined, this) : project.status === "ARCHIVED" ? /* @__PURE__ */ jsxDEV2(Button2, {
1014
- className: "w-full justify-start",
1015
- variant: "ghost",
1016
- onPress: handleActivate,
1017
- disabled: isLoading,
1018
- children: [
1019
- /* @__PURE__ */ jsxDEV2("span", {
1020
- className: "mr-2",
1021
- children: "\uD83D\uDD04"
1022
- }, undefined, false, undefined, this),
1023
- " Restore Project"
1024
- ]
1025
- }, undefined, true, undefined, this) : null,
1026
- /* @__PURE__ */ jsxDEV2(Button2, {
1027
- className: "w-full justify-start text-red-500 hover:text-red-600",
1028
- variant: "ghost",
1029
- onPress: () => setMode("delete"),
1030
- children: [
1031
- /* @__PURE__ */ jsxDEV2("span", {
1032
- className: "mr-2",
1033
- children: "\uD83D\uDDD1\uFE0F"
1034
- }, undefined, false, undefined, this),
1035
- " Delete Project"
1036
- ]
1037
- }, undefined, true, undefined, this),
1038
- /* @__PURE__ */ jsxDEV2("div", {
1039
- className: "border-border border-t pt-3",
1040
- children: /* @__PURE__ */ jsxDEV2(Button2, {
1041
- className: "w-full",
1042
- variant: "outline",
1043
- onPress: handleClose,
1044
- children: "Close"
1045
- }, undefined, false, undefined, this)
1046
- }, undefined, false, undefined, this)
1047
- ]
1048
- }, undefined, true, undefined, this),
1049
- mode === "edit" && /* @__PURE__ */ jsxDEV2("div", {
1050
- className: "space-y-4",
1051
- children: [
1052
- /* @__PURE__ */ jsxDEV2("div", {
1053
- children: [
1054
- /* @__PURE__ */ jsxDEV2("label", {
1055
- htmlFor: "edit-name",
1056
- className: "mb-1 block font-medium text-muted-foreground text-sm",
1057
- children: "Project Name *"
1058
- }, undefined, false, undefined, this),
1059
- /* @__PURE__ */ jsxDEV2(Input2, {
1060
- id: "edit-name",
1061
- value: name,
1062
- onChange: (e) => setName(e.target.value),
1063
- disabled: isLoading
1064
- }, undefined, false, undefined, this)
1065
- ]
1066
- }, undefined, true, undefined, this),
1067
- /* @__PURE__ */ jsxDEV2("div", {
1068
- children: [
1069
- /* @__PURE__ */ jsxDEV2("label", {
1070
- htmlFor: "edit-description",
1071
- className: "mb-1 block font-medium text-muted-foreground text-sm",
1072
- children: "Description"
1073
- }, undefined, false, undefined, this),
1074
- /* @__PURE__ */ jsxDEV2("textarea", {
1075
- id: "edit-description",
1076
- value: description,
1077
- onChange: (e) => setDescription(e.target.value),
1078
- rows: 3,
1079
- disabled: isLoading,
1080
- 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 disabled:opacity-50"
1081
- }, undefined, false, undefined, this)
1082
- ]
1083
- }, undefined, true, undefined, this),
1084
- error && /* @__PURE__ */ jsxDEV2("div", {
1085
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
1086
- children: error
1087
- }, undefined, false, undefined, this),
1088
- /* @__PURE__ */ jsxDEV2("div", {
1089
- className: "flex justify-end gap-3 pt-2",
1090
- children: [
1091
- /* @__PURE__ */ jsxDEV2(Button2, {
1092
- variant: "ghost",
1093
- onPress: () => setMode("menu"),
1094
- disabled: isLoading,
1095
- children: "Back"
1096
- }, undefined, false, undefined, this),
1097
- /* @__PURE__ */ jsxDEV2(Button2, {
1098
- onPress: handleEdit,
1099
- disabled: isLoading,
1100
- children: isLoading ? "Saving..." : "Save Changes"
1101
- }, undefined, false, undefined, this)
1102
- ]
1103
- }, undefined, true, undefined, this)
1104
- ]
1105
- }, undefined, true, undefined, this),
1106
- mode === "archive" && /* @__PURE__ */ jsxDEV2("div", {
1107
- className: "space-y-4",
1108
- children: [
1109
- /* @__PURE__ */ jsxDEV2("p", {
1110
- className: "text-muted-foreground",
1111
- children: [
1112
- "Are you sure you want to archive",
1113
- " ",
1114
- /* @__PURE__ */ jsxDEV2("span", {
1115
- className: "font-medium text-foreground",
1116
- children: project.name
1117
- }, undefined, false, undefined, this),
1118
- "?"
1119
- ]
1120
- }, undefined, true, undefined, this),
1121
- /* @__PURE__ */ jsxDEV2("p", {
1122
- className: "text-muted-foreground text-sm",
1123
- children: "Archived projects can be restored later."
1124
- }, undefined, false, undefined, this),
1125
- error && /* @__PURE__ */ jsxDEV2("div", {
1126
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
1127
- children: error
1128
- }, undefined, false, undefined, this),
1129
- /* @__PURE__ */ jsxDEV2("div", {
1130
- className: "flex justify-end gap-3 pt-2",
1131
- children: [
1132
- /* @__PURE__ */ jsxDEV2(Button2, {
1133
- variant: "ghost",
1134
- onPress: () => setMode("menu"),
1135
- disabled: isLoading,
1136
- children: "Cancel"
1137
- }, undefined, false, undefined, this),
1138
- /* @__PURE__ */ jsxDEV2(Button2, {
1139
- onPress: handleArchive,
1140
- disabled: isLoading,
1141
- children: isLoading ? "Archiving..." : "\uD83D\uDCE6 Archive"
1142
- }, undefined, false, undefined, this)
1143
- ]
1144
- }, undefined, true, undefined, this)
1145
- ]
1146
- }, undefined, true, undefined, this),
1147
- mode === "delete" && /* @__PURE__ */ jsxDEV2("div", {
1148
- className: "space-y-4",
1149
- children: [
1150
- /* @__PURE__ */ jsxDEV2("p", {
1151
- className: "text-muted-foreground",
1152
- children: [
1153
- "Are you sure you want to delete",
1154
- " ",
1155
- /* @__PURE__ */ jsxDEV2("span", {
1156
- className: "font-medium text-foreground",
1157
- children: project.name
1158
- }, undefined, false, undefined, this),
1159
- "?"
1160
- ]
1161
- }, undefined, true, undefined, this),
1162
- /* @__PURE__ */ jsxDEV2("p", {
1163
- className: "text-destructive text-sm",
1164
- children: "This action cannot be undone."
1165
- }, undefined, false, undefined, this),
1166
- error && /* @__PURE__ */ jsxDEV2("div", {
1167
- className: "rounded-md bg-destructive/10 p-3 text-destructive text-sm",
1168
- children: error
1169
- }, undefined, false, undefined, this),
1170
- /* @__PURE__ */ jsxDEV2("div", {
1171
- className: "flex justify-end gap-3 pt-2",
1172
- children: [
1173
- /* @__PURE__ */ jsxDEV2(Button2, {
1174
- variant: "ghost",
1175
- onPress: () => setMode("menu"),
1176
- disabled: isLoading,
1177
- children: "Cancel"
1178
- }, undefined, false, undefined, this),
1179
- /* @__PURE__ */ jsxDEV2(Button2, {
1180
- variant: "destructive",
1181
- onPress: handleDelete,
1182
- disabled: isLoading,
1183
- children: isLoading ? "Deleting..." : "\uD83D\uDDD1\uFE0F Delete"
1184
- }, undefined, false, undefined, this)
1185
- ]
1186
- }, undefined, true, undefined, this)
1187
- ]
1188
- }, undefined, true, undefined, this)
1189
- ]
1190
- }, undefined, true, undefined, this)
1191
- ]
1192
- }, undefined, true, undefined, this);
1193
- }
1194
- // src/ui/overlays/demo-overlays.ts
1195
- var saasFreeUserOverlay = {
1196
- overlayId: "saas-boilerplate.free-tier",
1197
- version: "1.0.0",
1198
- description: "Shows limitations for free tier users",
1199
- appliesTo: {
1200
- feature: "saas-boilerplate",
1201
- tier: "free"
1202
- },
1203
- modifications: [
1204
- {
1205
- type: "setLimit",
1206
- field: "projects",
1207
- max: 3,
1208
- message: "Upgrade to create more projects"
1209
- },
1210
- { type: "hideField", field: "advancedSettings", reason: "Pro feature" },
1211
- {
1212
- type: "addBadge",
1213
- position: "header",
1214
- label: "Free Plan",
1215
- variant: "default"
1216
- }
1217
- ]
1218
- };
1219
- var saasDemoOverlay = {
1220
- overlayId: "saas-boilerplate.demo-user",
1221
- version: "1.0.0",
1222
- description: "Demo mode for SaaS boilerplate",
1223
- appliesTo: {
1224
- feature: "saas-boilerplate",
1225
- role: "demo"
1226
- },
1227
- modifications: [
1228
- {
1229
- type: "hideField",
1230
- field: "billingSection",
1231
- reason: "Demo users cannot access billing"
1232
- },
1233
- {
1234
- type: "hideField",
1235
- field: "deleteAccount",
1236
- reason: "Not available in demo"
1237
- },
1238
- {
1239
- type: "addBadge",
1240
- position: "header",
1241
- label: "Demo Mode",
1242
- variant: "warning"
1243
- }
1244
- ]
1245
- };
1246
- var saasOverlays = [
1247
- saasFreeUserOverlay,
1248
- saasDemoOverlay
1249
- ];
1250
- // src/ui/renderers/project-list.markdown.ts
1251
- var PROJECT_TIERS = [
1252
- "FREE",
1253
- "PRO",
1254
- "ENTERPRISE"
1255
- ];
1256
- function toVisualizationProject(project, index) {
1257
- return {
1258
- status: project.status === "DELETED" ? "ARCHIVED" : project.status,
1259
- tier: PROJECT_TIERS[index % PROJECT_TIERS.length] ?? "FREE",
1260
- createdAt: project.createdAt
1261
- };
1262
- }
1263
- var projectListMarkdownRenderer = {
1264
- target: "markdown",
1265
- render: async (desc, _ctx) => {
1266
- if (desc.source.type !== "component" || desc.source.componentKey !== "ProjectListView") {
1267
- throw new Error("projectListMarkdownRenderer: not ProjectListView");
1268
- }
1269
- const data = await mockListProjectsHandler({
1270
- limit: 20,
1271
- offset: 0
1272
- });
1273
- const items = data.projects ?? [];
1274
- const lines = [
1275
- "# Projects",
1276
- "",
1277
- `**Total**: ${data.total} projects`,
1278
- ""
1279
- ];
1280
- if (items.length === 0) {
1281
- lines.push("_No projects found._");
1282
- } else {
1283
- lines.push("| Status | Project | Description |");
1284
- lines.push("|--------|---------|-------------|");
1285
- for (const project of items) {
1286
- const status = project.status === "ACTIVE" ? "\u2705" : project.status === "ARCHIVED" ? "\uD83D\uDCE6" : "\u23F8\uFE0F";
1287
- lines.push(`| ${status} | **${project.name}** | ${project.description ?? "-"} |`);
1288
- }
1289
- }
1290
- return {
1291
- mimeType: "text/markdown",
1292
- body: lines.join(`
1293
- `)
1294
- };
1295
- }
1296
- };
1297
- var saasDashboardMarkdownRenderer = {
1298
- target: "markdown",
1299
- render: async (desc, _ctx) => {
1300
- if (desc.source.type !== "component" || desc.source.componentKey !== "SaasDashboard") {
1301
- throw new Error("saasDashboardMarkdownRenderer: not SaasDashboard");
1302
- }
1303
- const [projectsData, subscription] = await Promise.all([
1304
- mockListProjectsHandler({ limit: 50 }),
1305
- mockGetSubscriptionHandler()
1306
- ]);
1307
- const projects = projectsData.projects ?? [];
1308
- const activeProjects = projects.filter((p) => p.status === "ACTIVE").length;
1309
- const archivedProjects = projects.filter((p) => p.status === "ARCHIVED").length;
1310
- const visualizations = createSaasVisualizationItems(projects.map(toVisualizationProject), 10);
1311
- const lines = [
1312
- "# SaaS Dashboard",
1313
- "",
1314
- "> Organization overview and usage summary",
1315
- "",
1316
- "## Summary",
1317
- "",
1318
- "| Metric | Value |",
1319
- "|--------|-------|",
1320
- `| Total Projects | ${projectsData.total} |`,
1321
- `| Active Projects | ${activeProjects} |`,
1322
- `| Archived Projects | ${archivedProjects} |`,
1323
- `| Subscription Plan | ${subscription.planName} |`,
1324
- `| Subscription Status | ${subscription.status} |`,
1325
- ""
1326
- ];
1327
- lines.push("## Visualization Overview");
1328
- lines.push("");
1329
- for (const item of visualizations) {
1330
- lines.push(`- **${item.title}** via \`${item.spec.meta.key}\``);
1331
- }
1332
- lines.push("");
1333
- lines.push("## Projects");
1334
- lines.push("");
1335
- if (projects.length === 0) {
1336
- lines.push("_No projects yet._");
1337
- } else {
1338
- lines.push("| Status | Project | Description |");
1339
- lines.push("|--------|---------|-------------|");
1340
- for (const project of projects.slice(0, 10)) {
1341
- const status = project.status === "ACTIVE" ? "\u2705" : project.status === "ARCHIVED" ? "\uD83D\uDCE6" : "\u23F8\uFE0F";
1342
- lines.push(`| ${status} | **${project.name}** | ${project.description ?? "-"} |`);
1343
- }
1344
- if (projects.length > 10) {
1345
- lines.push(`| ... | ... | _${projectsData.total - 10} more projects_ |`);
1346
- }
1347
- }
1348
- lines.push("");
1349
- lines.push("## Subscription");
1350
- lines.push("");
1351
- lines.push(`- **Plan**: ${subscription.planName}`);
1352
- lines.push(`- **Status**: ${subscription.status}`);
1353
- if (subscription.currentPeriodEnd) {
1354
- lines.push(`- **Period End**: ${new Date(subscription.currentPeriodEnd).toLocaleDateString()}`);
1355
- }
1356
- return {
1357
- mimeType: "text/markdown",
1358
- body: lines.join(`
1359
- `)
1360
- };
1361
- }
1362
- };
1363
- var saasBillingMarkdownRenderer = {
1364
- target: "markdown",
1365
- render: async (desc, _ctx) => {
1366
- if (desc.source.type !== "component" || desc.source.componentKey !== "SubscriptionView") {
1367
- throw new Error("saasBillingMarkdownRenderer: not SubscriptionView");
1368
- }
1369
- const subscription = await mockGetSubscriptionHandler();
1370
- const lines = [
1371
- "# Billing & Subscription",
1372
- "",
1373
- "> Current subscription details and billing information",
1374
- "",
1375
- "## Subscription Details",
1376
- "",
1377
- "| Property | Value |",
1378
- "|----------|-------|",
1379
- `| Plan | ${subscription.planName} |`,
1380
- `| Status | ${subscription.status} |`,
1381
- `| ID | ${subscription.id} |`,
1382
- `| Period Start | ${new Date(subscription.currentPeriodStart).toLocaleDateString()} |`,
1383
- `| Period End | ${new Date(subscription.currentPeriodEnd).toLocaleDateString()} |`
1384
- ];
1385
- lines.push("");
1386
- lines.push("## Plan Limits");
1387
- lines.push("");
1388
- lines.push(`- **Projects**: ${subscription.limits.projects}`);
1389
- lines.push(`- **Users**: ${subscription.limits.users}`);
1390
- lines.push("");
1391
- lines.push("## Plan Features");
1392
- lines.push("");
1393
- if (subscription.planName.toLowerCase().includes("free")) {
1394
- lines.push("- \u2705 Up to 3 projects");
1395
- lines.push("- \u2705 Basic support");
1396
- lines.push("- \u274C Priority support");
1397
- lines.push("- \u274C Advanced analytics");
1398
- } else if (subscription.planName.toLowerCase().includes("pro")) {
1399
- lines.push("- \u2705 Unlimited projects");
1400
- lines.push("- \u2705 Priority support");
1401
- lines.push("- \u2705 Advanced analytics");
1402
- lines.push("- \u274C Custom integrations");
1403
- } else {
1404
- lines.push("- \u2705 Unlimited projects");
1405
- lines.push("- \u2705 Priority support");
1406
- lines.push("- \u2705 Advanced analytics");
1407
- lines.push("- \u2705 Custom integrations");
1408
- lines.push("- \u2705 Dedicated support");
1409
- }
1410
- return {
1411
- mimeType: "text/markdown",
1412
- body: lines.join(`
1413
- `)
1414
- };
1415
- }
1416
- };
1417
-
1418
- // src/ui/SaasProjectList.tsx
1419
- import {
1420
- Button as Button3,
1421
- EmptyState,
1422
- EntityCard,
1423
- ErrorState,
1424
- LoaderBlock,
1425
- StatCard,
1426
- StatCardGroup,
1427
- StatusChip
1428
- } from "@contractspec/lib.design-system";
1429
- import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
1430
- "use client";
1431
- function getStatusTone(status) {
1432
- switch (status) {
1433
- case "ACTIVE":
1434
- return "success";
1435
- case "DRAFT":
1436
- return "neutral";
1437
- case "ARCHIVED":
1438
- return "danger";
1439
- default:
1440
- return "neutral";
1441
- }
1442
- }
1443
- function SaasProjectList({
1444
- onProjectClick,
1445
- onCreateProject
1446
- }) {
1447
- const { data, loading, error, stats, refetch } = useProjectList();
1448
- if (loading && !data) {
1449
- return /* @__PURE__ */ jsxDEV3(LoaderBlock, {
1450
- label: "Loading projects..."
1451
- }, undefined, false, undefined, this);
1452
- }
1453
- if (error) {
1454
- return /* @__PURE__ */ jsxDEV3(ErrorState, {
1455
- title: "Failed to load projects",
1456
- description: error.message,
1457
- onRetry: refetch,
1458
- retryLabel: "Retry"
1459
- }, undefined, false, undefined, this);
1460
- }
1461
- if (!data?.items.length) {
1462
- return /* @__PURE__ */ jsxDEV3(EmptyState, {
1463
- title: "No projects found",
1464
- description: "Create your first project to get started.",
1465
- primaryAction: onCreateProject ? /* @__PURE__ */ jsxDEV3(Button3, {
1466
- onPress: onCreateProject,
1467
- children: "Create Project"
1468
- }, undefined, false, undefined, this) : undefined
1469
- }, undefined, false, undefined, this);
1470
- }
1471
- return /* @__PURE__ */ jsxDEV3("div", {
1472
- className: "space-y-6",
1473
- children: [
1474
- stats && /* @__PURE__ */ jsxDEV3(StatCardGroup, {
1475
- children: [
1476
- /* @__PURE__ */ jsxDEV3(StatCard, {
1477
- label: "Total Projects",
1478
- value: stats.total.toString()
1479
- }, undefined, false, undefined, this),
1480
- /* @__PURE__ */ jsxDEV3(StatCard, {
1481
- label: "Active",
1482
- value: stats.activeCount.toString()
1483
- }, undefined, false, undefined, this),
1484
- /* @__PURE__ */ jsxDEV3(StatCard, {
1485
- label: "Draft",
1486
- value: stats.draftCount.toString()
1487
- }, undefined, false, undefined, this)
1488
- ]
1489
- }, undefined, true, undefined, this),
1490
- /* @__PURE__ */ jsxDEV3("div", {
1491
- className: "grid gap-4 md:grid-cols-2 lg:grid-cols-3",
1492
- children: data.items.map((project) => /* @__PURE__ */ jsxDEV3(EntityCard, {
1493
- cardTitle: project.name,
1494
- cardSubtitle: project.tier,
1495
- meta: /* @__PURE__ */ jsxDEV3("p", {
1496
- className: "text-muted-foreground text-sm",
1497
- children: project.description
1498
- }, undefined, false, undefined, this),
1499
- chips: /* @__PURE__ */ jsxDEV3(StatusChip, {
1500
- tone: getStatusTone(project.status),
1501
- label: project.status
1502
- }, undefined, false, undefined, this),
1503
- footer: /* @__PURE__ */ jsxDEV3("span", {
1504
- className: "text-muted-foreground text-xs",
1505
- children: project.updatedAt.toLocaleDateString()
1506
- }, undefined, false, undefined, this),
1507
- onClick: onProjectClick ? () => onProjectClick(project.id) : undefined
1508
- }, project.id, false, undefined, this))
1509
- }, undefined, false, undefined, this)
1510
- ]
1511
- }, undefined, true, undefined, this);
1512
- }
1513
-
1514
- // src/ui/renderers/project-list.renderer.tsx
1515
- import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
1516
- var projectListReactRenderer = {
1517
- target: "react",
1518
- render: async (desc, _ctx) => {
1519
- if (desc.source.type !== "component") {
1520
- throw new Error("Invalid source type");
1521
- }
1522
- if (desc.source.componentKey !== "SaasProjectListView") {
1523
- throw new Error(`Unknown component: ${desc.source.componentKey}`);
1524
- }
1525
- return /* @__PURE__ */ jsxDEV4(SaasProjectList, {}, undefined, false, undefined, this);
1526
- }
1527
- };
1528
- // src/ui/SaasDashboard.visualizations.tsx
1529
- import {
1530
- VisualizationCard,
1531
- VisualizationGrid
1532
- } from "@contractspec/lib.design-system";
1533
- import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
1534
- "use client";
1535
- function SaasVisualizationOverview({
1536
- projects,
1537
- projectLimit
1538
- }) {
1539
- const items = createSaasVisualizationItems(projects, projectLimit);
1540
- return /* @__PURE__ */ jsxDEV5("section", {
1541
- className: "space-y-3",
1542
- children: [
1543
- /* @__PURE__ */ jsxDEV5("div", {
1544
- children: [
1545
- /* @__PURE__ */ jsxDEV5("h3", {
1546
- className: "font-semibold text-lg",
1547
- children: "Portfolio Visualizations"
1548
- }, undefined, false, undefined, this),
1549
- /* @__PURE__ */ jsxDEV5("p", {
1550
- className: "text-muted-foreground text-sm",
1551
- children: "Contract-backed charts for project mix, capacity, and activity."
1552
- }, undefined, false, undefined, this)
1553
- ]
1554
- }, undefined, true, undefined, this),
1555
- /* @__PURE__ */ jsxDEV5(VisualizationGrid, {
1556
- children: items.map((item) => /* @__PURE__ */ jsxDEV5(VisualizationCard, {
1557
- data: item.data,
1558
- description: item.description,
1559
- height: item.height,
1560
- spec: item.spec,
1561
- title: item.title
1562
- }, item.key, false, undefined, this))
1563
- }, undefined, false, undefined, this)
1564
- ]
1565
- }, undefined, true, undefined, this);
1566
- }
1567
-
1568
- // src/ui/SaasDashboard.tsx
1569
- import {
1570
- Button as Button4,
1571
- EmptyState as EmptyState2,
1572
- EntityCard as EntityCard2,
1573
- ErrorState as ErrorState2,
1574
- LoaderBlock as LoaderBlock2,
1575
- StatCard as StatCard2,
1576
- StatCardGroup as StatCardGroup2,
1577
- StatusChip as StatusChip2
1578
- } from "@contractspec/lib.design-system";
1579
- import { useCallback as useCallback3, useState as useState5 } from "react";
1580
- import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
1581
- "use client";
1582
- function getStatusTone2(status) {
1583
- switch (status) {
1584
- case "ACTIVE":
1585
- return "success";
1586
- case "DRAFT":
1587
- return "neutral";
1588
- case "ARCHIVED":
1589
- return "warning";
1590
- default:
1591
- return "neutral";
1592
- }
1593
- }
1594
- function SaasDashboard() {
1595
- const [activeTab, setActiveTab] = useState5("projects");
1596
- const [isCreateModalOpen, setIsCreateModalOpen] = useState5(false);
1597
- const [selectedProject, setSelectedProject] = useState5(null);
1598
- const [isProjectActionsOpen, setIsProjectActionsOpen] = useState5(false);
1599
- const { data, subscription, loading, error, stats, refetch } = useProjectList();
1600
- const mutations = useProjectMutations({
1601
- onSuccess: () => {
1602
- refetch();
1603
- }
1604
- });
1605
- const handleProjectClick = useCallback3((project) => {
1606
- setSelectedProject(project);
1607
- setIsProjectActionsOpen(true);
1608
- }, []);
1609
- const tabs = [
1610
- { id: "projects", label: "Projects", icon: "\uD83D\uDCC1" },
1611
- { id: "billing", label: "Billing", icon: "\uD83D\uDCB3" },
1612
- { id: "settings", label: "Settings", icon: "\u2699\uFE0F" }
1613
- ];
1614
- if (loading && !data) {
1615
- return /* @__PURE__ */ jsxDEV6(LoaderBlock2, {
1616
- label: "Loading dashboard..."
1617
- }, undefined, false, undefined, this);
1618
- }
1619
- if (error) {
1620
- return /* @__PURE__ */ jsxDEV6(ErrorState2, {
1621
- title: "Failed to load dashboard",
1622
- description: error.message,
1623
- onRetry: refetch,
1624
- retryLabel: "Retry"
1625
- }, undefined, false, undefined, this);
1626
- }
1627
- return /* @__PURE__ */ jsxDEV6("div", {
1628
- className: "space-y-6",
1629
- children: [
1630
- /* @__PURE__ */ jsxDEV6("div", {
1631
- className: "flex items-center justify-between",
1632
- children: [
1633
- /* @__PURE__ */ jsxDEV6("h2", {
1634
- className: "font-bold text-2xl",
1635
- children: "SaaS Dashboard"
1636
- }, undefined, false, undefined, this),
1637
- activeTab === "projects" && /* @__PURE__ */ jsxDEV6(Button4, {
1638
- onPress: () => setIsCreateModalOpen(true),
1639
- children: [
1640
- /* @__PURE__ */ jsxDEV6("span", {
1641
- className: "mr-2",
1642
- children: "+"
1643
- }, undefined, false, undefined, this),
1644
- " New Project"
1645
- ]
1646
- }, undefined, true, undefined, this)
1647
- ]
1648
- }, undefined, true, undefined, this),
1649
- stats && subscription && /* @__PURE__ */ jsxDEV6(StatCardGroup2, {
1650
- children: [
1651
- /* @__PURE__ */ jsxDEV6(StatCard2, {
1652
- label: "Projects",
1653
- value: stats.total.toString()
1654
- }, undefined, false, undefined, this),
1655
- /* @__PURE__ */ jsxDEV6(StatCard2, {
1656
- label: "Active",
1657
- value: stats.activeCount.toString()
1658
- }, undefined, false, undefined, this),
1659
- /* @__PURE__ */ jsxDEV6(StatCard2, {
1660
- label: "Draft",
1661
- value: stats.draftCount.toString()
1662
- }, undefined, false, undefined, this),
1663
- /* @__PURE__ */ jsxDEV6(StatCard2, {
1664
- label: "Plan",
1665
- value: subscription.plan,
1666
- hint: subscription.status
1667
- }, undefined, false, undefined, this)
1668
- ]
1669
- }, undefined, true, undefined, this),
1670
- data && stats && /* @__PURE__ */ jsxDEV6(SaasVisualizationOverview, {
1671
- projectLimit: stats.projectLimit,
1672
- projects: data.items
1673
- }, undefined, false, undefined, this),
1674
- /* @__PURE__ */ jsxDEV6("nav", {
1675
- className: "flex gap-1 rounded-lg bg-muted p-1",
1676
- role: "tablist",
1677
- children: tabs.map((tab) => /* @__PURE__ */ jsxDEV6("button", {
1678
- type: "button",
1679
- role: "tab",
1680
- "aria-selected": activeTab === tab.id,
1681
- onClick: () => setActiveTab(tab.id),
1682
- className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 font-medium text-sm transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
1683
- children: [
1684
- /* @__PURE__ */ jsxDEV6("span", {
1685
- children: tab.icon
1686
- }, undefined, false, undefined, this),
1687
- tab.label
1688
- ]
1689
- }, tab.id, true, undefined, this))
1690
- }, undefined, false, undefined, this),
1691
- /* @__PURE__ */ jsxDEV6("div", {
1692
- className: "min-h-[400px]",
1693
- role: "tabpanel",
1694
- children: [
1695
- activeTab === "projects" && /* @__PURE__ */ jsxDEV6(ProjectsTab, {
1696
- data,
1697
- onProjectClick: handleProjectClick
1698
- }, undefined, false, undefined, this),
1699
- activeTab === "billing" && /* @__PURE__ */ jsxDEV6(BillingTab, {
1700
- subscription
1701
- }, undefined, false, undefined, this),
1702
- activeTab === "settings" && /* @__PURE__ */ jsxDEV6(SettingsTab, {}, undefined, false, undefined, this)
1703
- ]
1704
- }, undefined, true, undefined, this),
1705
- /* @__PURE__ */ jsxDEV6(CreateProjectModal, {
1706
- isOpen: isCreateModalOpen,
1707
- onClose: () => setIsCreateModalOpen(false),
1708
- onSubmit: async (input) => {
1709
- await mutations.createProject(input);
1710
- },
1711
- isLoading: mutations.createState.loading
1712
- }, undefined, false, undefined, this),
1713
- /* @__PURE__ */ jsxDEV6(ProjectActionsModal, {
1714
- isOpen: isProjectActionsOpen,
1715
- project: selectedProject,
1716
- onClose: () => {
1717
- setIsProjectActionsOpen(false);
1718
- setSelectedProject(null);
1719
- },
1720
- onUpdate: async (input) => {
1721
- await mutations.updateProject(input);
1722
- },
1723
- onArchive: async (projectId) => {
1724
- await mutations.archiveProject(projectId);
1725
- },
1726
- onActivate: async (projectId) => {
1727
- await mutations.activateProject(projectId);
1728
- },
1729
- onDelete: async (projectId) => {
1730
- await mutations.deleteProject(projectId);
1731
- },
1732
- isLoading: mutations.isLoading
1733
- }, undefined, false, undefined, this)
1734
- ]
1735
- }, undefined, true, undefined, this);
1736
- }
1737
- function ProjectsTab({ data, onProjectClick }) {
1738
- if (!data?.items.length) {
1739
- return /* @__PURE__ */ jsxDEV6(EmptyState2, {
1740
- title: "No projects yet",
1741
- description: "Create your first project to get started."
1742
- }, undefined, false, undefined, this);
1743
- }
1744
- return /* @__PURE__ */ jsxDEV6("div", {
1745
- className: "space-y-4",
1746
- children: /* @__PURE__ */ jsxDEV6("div", {
1747
- className: "grid gap-4 md:grid-cols-2 lg:grid-cols-3",
1748
- children: data.items.map((project) => /* @__PURE__ */ jsxDEV6(EntityCard2, {
1749
- cardTitle: project.name,
1750
- cardSubtitle: project.tier,
1751
- meta: /* @__PURE__ */ jsxDEV6("p", {
1752
- className: "text-muted-foreground text-sm",
1753
- children: project.description
1754
- }, undefined, false, undefined, this),
1755
- chips: /* @__PURE__ */ jsxDEV6(StatusChip2, {
1756
- tone: getStatusTone2(project.status),
1757
- label: project.status
1758
- }, undefined, false, undefined, this),
1759
- footer: /* @__PURE__ */ jsxDEV6("div", {
1760
- className: "flex w-full items-center justify-between",
1761
- children: [
1762
- /* @__PURE__ */ jsxDEV6("span", {
1763
- className: "text-muted-foreground text-xs",
1764
- children: project.updatedAt.toLocaleDateString()
1765
- }, undefined, false, undefined, this),
1766
- /* @__PURE__ */ jsxDEV6(Button4, {
1767
- variant: "ghost",
1768
- size: "sm",
1769
- onPress: () => onProjectClick?.(project),
1770
- children: "Actions"
1771
- }, undefined, false, undefined, this)
1772
- ]
1773
- }, undefined, true, undefined, this)
1774
- }, project.id, false, undefined, this))
1775
- }, undefined, false, undefined, this)
1776
- }, undefined, false, undefined, this);
1777
- }
1778
- function BillingTab({ subscription }) {
1779
- if (!subscription)
1780
- return null;
1781
- return /* @__PURE__ */ jsxDEV6("div", {
1782
- className: "space-y-6",
1783
- children: [
1784
- /* @__PURE__ */ jsxDEV6("div", {
1785
- className: "rounded-xl border border-border bg-card p-6",
1786
- children: [
1787
- /* @__PURE__ */ jsxDEV6("div", {
1788
- className: "flex items-start justify-between",
1789
- children: [
1790
- /* @__PURE__ */ jsxDEV6("div", {
1791
- children: [
1792
- /* @__PURE__ */ jsxDEV6("h3", {
1793
- className: "font-semibold text-lg",
1794
- children: [
1795
- subscription.plan,
1796
- " Plan"
1797
- ]
1798
- }, undefined, true, undefined, this),
1799
- /* @__PURE__ */ jsxDEV6("p", {
1800
- className: "text-muted-foreground text-sm",
1801
- children: [
1802
- "Current period:",
1803
- " ",
1804
- subscription.currentPeriodStart.toLocaleDateString(),
1805
- " -",
1806
- " ",
1807
- subscription.currentPeriodEnd.toLocaleDateString()
1808
- ]
1809
- }, undefined, true, undefined, this),
1810
- /* @__PURE__ */ jsxDEV6("p", {
1811
- className: "text-muted-foreground text-sm",
1812
- children: [
1813
- "Billing cycle: ",
1814
- subscription.billingCycle
1815
- ]
1816
- }, undefined, true, undefined, this)
1817
- ]
1818
- }, undefined, true, undefined, this),
1819
- /* @__PURE__ */ jsxDEV6(StatusChip2, {
1820
- tone: "success",
1821
- label: subscription.status
1822
- }, undefined, false, undefined, this)
1823
- ]
1824
- }, undefined, true, undefined, this),
1825
- /* @__PURE__ */ jsxDEV6("div", {
1826
- className: "mt-4 flex gap-3",
1827
- children: [
1828
- /* @__PURE__ */ jsxDEV6(Button4, {
1829
- variant: "outline",
1830
- onPress: () => alert("Upgrade clicked!"),
1831
- children: "Upgrade Plan"
1832
- }, undefined, false, undefined, this),
1833
- /* @__PURE__ */ jsxDEV6(Button4, {
1834
- variant: "ghost",
1835
- onPress: () => alert("Manage Billing clicked!"),
1836
- children: "Manage Billing"
1837
- }, undefined, false, undefined, this)
1838
- ]
1839
- }, undefined, true, undefined, this)
1840
- ]
1841
- }, undefined, true, undefined, this),
1842
- subscription.cancelAtPeriodEnd && /* @__PURE__ */ jsxDEV6("div", {
1843
- className: "rounded-xl border border-border bg-destructive/10 p-4 text-destructive",
1844
- children: /* @__PURE__ */ jsxDEV6("p", {
1845
- className: "font-medium text-sm",
1846
- children: "\u26A0\uFE0F Your subscription will be cancelled at the end of the current period."
1847
- }, undefined, false, undefined, this)
1848
- }, undefined, false, undefined, this)
1849
- ]
1850
- }, undefined, true, undefined, this);
1851
- }
1852
- function SettingsTab() {
1853
- return /* @__PURE__ */ jsxDEV6("div", {
1854
- className: "space-y-6",
1855
- children: /* @__PURE__ */ jsxDEV6("div", {
1856
- className: "rounded-xl border border-border bg-card p-6",
1857
- children: [
1858
- /* @__PURE__ */ jsxDEV6("h3", {
1859
- className: "mb-4 font-semibold text-lg",
1860
- children: "Organization Settings"
1861
- }, undefined, false, undefined, this),
1862
- /* @__PURE__ */ jsxDEV6("div", {
1863
- className: "space-y-4",
1864
- children: [
1865
- /* @__PURE__ */ jsxDEV6("div", {
1866
- children: [
1867
- /* @__PURE__ */ jsxDEV6("label", {
1868
- htmlFor: "org-name",
1869
- className: "font-medium text-sm",
1870
- children: "Organization Name"
1871
- }, undefined, false, undefined, this),
1872
- /* @__PURE__ */ jsxDEV6("input", {
1873
- id: "org-name",
1874
- type: "text",
1875
- defaultValue: "Demo Organization",
1876
- className: "mt-1 block w-full rounded-md border border-input bg-background px-3 py-2"
1877
- }, undefined, false, undefined, this)
1878
- ]
1879
- }, undefined, true, undefined, this),
1880
- /* @__PURE__ */ jsxDEV6("div", {
1881
- children: [
1882
- /* @__PURE__ */ jsxDEV6("label", {
1883
- htmlFor: "timezone",
1884
- className: "font-medium text-sm",
1885
- children: "Default Timezone"
1886
- }, undefined, false, undefined, this),
1887
- /* @__PURE__ */ jsxDEV6("select", {
1888
- id: "timezone",
1889
- className: "mt-1 block w-full rounded-md border border-input bg-background px-3 py-2",
1890
- children: [
1891
- /* @__PURE__ */ jsxDEV6("option", {
1892
- children: "UTC"
1893
- }, undefined, false, undefined, this),
1894
- /* @__PURE__ */ jsxDEV6("option", {
1895
- children: "America/New_York"
1896
- }, undefined, false, undefined, this),
1897
- /* @__PURE__ */ jsxDEV6("option", {
1898
- children: "Europe/London"
1899
- }, undefined, false, undefined, this),
1900
- /* @__PURE__ */ jsxDEV6("option", {
1901
- children: "Asia/Tokyo"
1902
- }, undefined, false, undefined, this)
1903
- ]
1904
- }, undefined, true, undefined, this)
1905
- ]
1906
- }, undefined, true, undefined, this),
1907
- /* @__PURE__ */ jsxDEV6("div", {
1908
- className: "pt-2",
1909
- children: /* @__PURE__ */ jsxDEV6(Button4, {
1910
- onPress: () => alert("Settings saved!"),
1911
- children: "Save Settings"
1912
- }, undefined, false, undefined, this)
1913
- }, undefined, false, undefined, this)
1914
- ]
1915
- }, undefined, true, undefined, this)
1916
- ]
1917
- }, undefined, true, undefined, this)
1918
- }, undefined, false, undefined, this);
1919
- }
1920
-
1921
- // src/ui/SaasSettingsPanel.tsx
1922
- import { Button as Button5 } from "@contractspec/lib.design-system";
1923
- import { useState as useState6 } from "react";
1924
- import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
1925
- "use client";
1926
- function SaasSettingsPanel() {
1927
- const [orgName, setOrgName] = useState6("Demo Organization");
1928
- const [timezone, setTimezone] = useState6("UTC");
1929
- return /* @__PURE__ */ jsxDEV7("div", {
1930
- className: "space-y-6",
1931
- children: [
1932
- /* @__PURE__ */ jsxDEV7("div", {
1933
- className: "rounded-xl border border-border bg-card p-6",
1934
- children: [
1935
- /* @__PURE__ */ jsxDEV7("h3", {
1936
- className: "mb-4 font-semibold text-lg",
1937
- children: "Organization Settings"
1938
- }, undefined, false, undefined, this),
1939
- /* @__PURE__ */ jsxDEV7("div", {
1940
- className: "space-y-4",
1941
- children: [
1942
- /* @__PURE__ */ jsxDEV7("div", {
1943
- children: [
1944
- /* @__PURE__ */ jsxDEV7("label", {
1945
- htmlFor: "setting-org-name",
1946
- className: "block font-medium text-sm",
1947
- children: "Organization Name"
1948
- }, undefined, false, undefined, this),
1949
- /* @__PURE__ */ jsxDEV7("input", {
1950
- id: "setting-org-name",
1951
- type: "text",
1952
- value: orgName,
1953
- onChange: (e) => setOrgName(e.target.value),
1954
- className: "mt-1 block w-full rounded-md border border-input bg-background px-3 py-2"
1955
- }, undefined, false, undefined, this)
1956
- ]
1957
- }, undefined, true, undefined, this),
1958
- /* @__PURE__ */ jsxDEV7("div", {
1959
- children: [
1960
- /* @__PURE__ */ jsxDEV7("label", {
1961
- htmlFor: "setting-timezone",
1962
- className: "block font-medium text-sm",
1963
- children: "Default Timezone"
1964
- }, undefined, false, undefined, this),
1965
- /* @__PURE__ */ jsxDEV7("select", {
1966
- id: "setting-timezone",
1967
- value: timezone,
1968
- onChange: (e) => setTimezone(e.target.value),
1969
- className: "mt-1 block w-full rounded-md border border-input bg-background px-3 py-2",
1970
- children: [
1971
- /* @__PURE__ */ jsxDEV7("option", {
1972
- value: "UTC",
1973
- children: "UTC"
1974
- }, undefined, false, undefined, this),
1975
- /* @__PURE__ */ jsxDEV7("option", {
1976
- value: "America/New_York",
1977
- children: "America/New_York"
1978
- }, undefined, false, undefined, this),
1979
- /* @__PURE__ */ jsxDEV7("option", {
1980
- value: "Europe/London",
1981
- children: "Europe/London"
1982
- }, undefined, false, undefined, this),
1983
- /* @__PURE__ */ jsxDEV7("option", {
1984
- value: "Asia/Tokyo",
1985
- children: "Asia/Tokyo"
1986
- }, undefined, false, undefined, this)
1987
- ]
1988
- }, undefined, true, undefined, this)
1989
- ]
1990
- }, undefined, true, undefined, this)
1991
- ]
1992
- }, undefined, true, undefined, this),
1993
- /* @__PURE__ */ jsxDEV7("div", {
1994
- className: "mt-6",
1995
- children: /* @__PURE__ */ jsxDEV7(Button5, {
1996
- variant: "default",
1997
- children: "Save Changes"
1998
- }, undefined, false, undefined, this)
1999
- }, undefined, false, undefined, this)
2000
- ]
2001
- }, undefined, true, undefined, this),
2002
- /* @__PURE__ */ jsxDEV7("div", {
2003
- className: "rounded-xl border border-border bg-card p-6",
2004
- children: [
2005
- /* @__PURE__ */ jsxDEV7("h3", {
2006
- className: "mb-4 font-semibold text-lg",
2007
- children: "Notifications"
2008
- }, undefined, false, undefined, this),
2009
- /* @__PURE__ */ jsxDEV7("div", {
2010
- className: "space-y-3",
2011
- children: [
2012
- { label: "Email notifications", defaultChecked: true },
2013
- { label: "Usage alerts", defaultChecked: true },
2014
- { label: "Weekly digest", defaultChecked: false }
2015
- ].map((item) => /* @__PURE__ */ jsxDEV7("label", {
2016
- className: "flex items-center gap-3",
2017
- children: [
2018
- /* @__PURE__ */ jsxDEV7("input", {
2019
- type: "checkbox",
2020
- defaultChecked: item.defaultChecked,
2021
- className: "h-4 w-4 rounded border-input"
2022
- }, undefined, false, undefined, this),
2023
- /* @__PURE__ */ jsxDEV7("span", {
2024
- className: "text-sm",
2025
- children: item.label
2026
- }, undefined, false, undefined, this)
2027
- ]
2028
- }, item.label, true, undefined, this))
2029
- }, undefined, false, undefined, this)
2030
- ]
2031
- }, undefined, true, undefined, this),
2032
- /* @__PURE__ */ jsxDEV7("div", {
2033
- className: "rounded-xl border border-red-200 bg-red-50 p-6 dark:border-red-900 dark:bg-red-950/20",
2034
- children: [
2035
- /* @__PURE__ */ jsxDEV7("h3", {
2036
- className: "mb-2 font-semibold text-lg text-red-700 dark:text-red-400",
2037
- children: "Danger Zone"
2038
- }, undefined, false, undefined, this),
2039
- /* @__PURE__ */ jsxDEV7("p", {
2040
- className: "mb-4 text-red-600 text-sm dark:text-red-300",
2041
- children: "These actions are irreversible. Please proceed with caution."
2042
- }, undefined, false, undefined, this),
2043
- /* @__PURE__ */ jsxDEV7("div", {
2044
- className: "flex gap-3",
2045
- children: [
2046
- /* @__PURE__ */ jsxDEV7(Button5, {
2047
- variant: "secondary",
2048
- size: "sm",
2049
- children: "Export Data"
2050
- }, undefined, false, undefined, this),
2051
- /* @__PURE__ */ jsxDEV7(Button5, {
2052
- variant: "secondary",
2053
- size: "sm",
2054
- children: "Delete Organization"
2055
- }, undefined, false, undefined, this)
2056
- ]
2057
- }, undefined, true, undefined, this)
2058
- ]
2059
- }, undefined, true, undefined, this)
2060
- ]
2061
- }, undefined, true, undefined, this);
2062
- }
2063
- export {
2064
- useProjectMutations,
2065
- useProjectList,
2066
- saasOverlays,
2067
- saasFreeUserOverlay,
2068
- saasDemoOverlay,
2069
- saasDashboardMarkdownRenderer,
2070
- saasBillingMarkdownRenderer,
2071
- projectListReactRenderer,
2072
- projectListMarkdownRenderer,
2073
- SaasSettingsPanel,
2074
- SaasProjectList,
2075
- SaasDashboard,
2076
- ProjectActionsModal,
2077
- CreateProjectModal
2078
- };
2
+ var M=[{id:"proj-1",name:"Marketing Website",description:"Main company website redesign project",slug:"marketing-website",organizationId:"demo-org",createdBy:"user-1",status:"ACTIVE",isPublic:!1,tags:["marketing","website","redesign"],createdAt:new Date("2024-01-15T10:00:00Z"),updatedAt:new Date("2024-03-20T14:30:00Z")},{id:"proj-2",name:"Mobile App v2",description:"Next generation mobile application",slug:"mobile-app-v2",organizationId:"demo-org",createdBy:"user-2",status:"ACTIVE",isPublic:!1,tags:["mobile","app","v2"],createdAt:new Date("2024-02-01T09:00:00Z"),updatedAt:new Date("2024-04-05T11:15:00Z")},{id:"proj-3",name:"API Integration",description:"Third-party API integration project",slug:"api-integration",organizationId:"demo-org",createdBy:"user-1",status:"DRAFT",isPublic:!1,tags:["api","integration"],createdAt:new Date("2024-03-10T08:00:00Z"),updatedAt:new Date("2024-03-10T08:00:00Z")},{id:"proj-4",name:"Analytics Dashboard",description:"Internal analytics and reporting dashboard",slug:"analytics-dashboard",organizationId:"demo-org",createdBy:"user-3",status:"ARCHIVED",isPublic:!0,tags:["analytics","dashboard","reporting"],createdAt:new Date("2023-10-01T12:00:00Z"),updatedAt:new Date("2024-02-28T16:45:00Z")}],T={id:"sub-1",organizationId:"demo-org",planId:"pro",planName:"Professional",status:"ACTIVE",currentPeriodStart:new Date("2024-04-01T00:00:00Z"),currentPeriodEnd:new Date("2024-05-01T00:00:00Z"),limits:{projects:25,users:10,storage:50,apiCalls:1e5},usage:{projects:4,users:5,storage:12.5,apiCalls:45230}},L={organizationId:"demo-org",period:"current_month",apiCalls:{total:45230,limit:1e5,percentUsed:45.23},storage:{totalGb:12.5,limitGb:50,percentUsed:25},activeProjects:4,activeUsers:5,breakdown:[{date:"2024-04-01",apiCalls:3200,storageGb:12.1},{date:"2024-04-02",apiCalls:2800,storageGb:12.2},{date:"2024-04-03",apiCalls:4100,storageGb:12.3},{date:"2024-04-04",apiCalls:3600,storageGb:12.4},{date:"2024-04-05",apiCalls:3800,storageGb:12.5}]};async function C(){return T}async function RH(H){return{...L,period:H.period??"current_month"}}async function yH(H){return{recorded:!0,newTotal:L.apiCalls.total+H.quantity}}async function zH(H){let{feature:$}=H;return{custom_domains:{allowed:!0},api_access:{allowed:!0,currentUsage:L.apiCalls.total,limit:L.apiCalls.limit},advanced_analytics:{allowed:!1,reason:"FEATURE_NOT_INCLUDED"},unlimited_projects:{allowed:!1,reason:"PLAN_LIMIT",currentUsage:T.usage.projects,limit:T.limits.projects}}[$]??{allowed:!0}}async function S(H){let{status:$,search:W,limit:Q=20,offset:Y=0}=H,q=[...M];if($&&$!=="all")q=q.filter((Z)=>Z.status===$);if(W){let Z=W.toLowerCase();q=q.filter((G)=>G.name.toLowerCase().includes(Z)||G.description?.toLowerCase().includes(Z)||G.tags.some((J)=>J.toLowerCase().includes(Z)))}q.sort((Z,G)=>G.updatedAt.getTime()-Z.updatedAt.getTime());let N=q.length;return{projects:q.slice(Y,Y+Q),total:N}}async function _H(H){let $=M.find((W)=>W.id===H.projectId);if(!$)throw Error("NOT_FOUND");return $}async function DH(H,$){if(H.slug){if(M.some((Y)=>Y.slug===H.slug))throw Error("SLUG_EXISTS")}let W=new Date;return{id:`proj-${Date.now()}`,name:H.name,description:H.description,slug:H.slug??H.name.toLowerCase().replace(/\s+/g,"-"),organizationId:$.organizationId,createdBy:$.userId,status:"DRAFT",isPublic:H.isPublic??!1,tags:H.tags??[],createdAt:W,updatedAt:W}}async function BH(H){let $=M.find((W)=>W.id===H.projectId);if(!$)throw Error("NOT_FOUND");return{...$,name:H.name??$.name,description:H.description??$.description,slug:H.slug??$.slug,isPublic:H.isPublic??$.isPublic,tags:H.tags??$.tags,status:H.status??$.status,updatedAt:new Date}}async function AH(H){if(!M.find((W)=>W.id===H.projectId))throw Error("NOT_FOUND");return{success:!0}}import{web as vH}from"@contractspec/lib.runtime-sandbox";var{generateId:IH}=vH;function x(H){return{id:H.id,projectId:H.projectId,organizationId:H.organizationId,name:H.name,description:H.description??void 0,status:H.status,tier:H.tier,createdAt:new Date(H.createdAt),updatedAt:new Date(H.updatedAt)}}function OH(H){return{id:H.id,projectId:H.projectId,organizationId:H.organizationId,plan:H.plan,status:H.status,billingCycle:H.billingCycle,currentPeriodStart:new Date(H.currentPeriodStart),currentPeriodEnd:new Date(H.currentPeriodEnd),cancelAtPeriodEnd:Boolean(H.cancelAtPeriodEnd)}}function y3(H){async function $(X){let{projectId:Z,organizationId:G,status:J,search:R,limit:z=20,offset:V=0}=X,U="WHERE projectId = ?",k=[Z];if(G)U+=" AND organizationId = ?",k.push(G);if(J&&J!=="all")U+=" AND status = ?",k.push(J);if(R)U+=" AND (name LIKE ? OR description LIKE ?)",k.push(`%${R}%`,`%${R}%`);let F=(await H.query(`SELECT COUNT(*) as count FROM saas_project ${U}`,k)).rows[0]?.count??0,b=(await H.query(`SELECT * FROM saas_project ${U} ORDER BY createdAt DESC LIMIT ? OFFSET ?`,[...k,z,V])).rows;return{items:b.map(x),total:F,hasMore:V+b.length<F}}async function W(X){let Z=(await H.query("SELECT * FROM saas_project WHERE id = ?",[X])).rows;return Z[0]?x(Z[0]):null}async function Q(X,Z){let G=IH("proj"),J=new Date().toISOString();await H.execute(`INSERT INTO saas_project (id, projectId, organizationId, name, description, status, tier, createdAt, updatedAt)
3
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,[G,Z.projectId,Z.organizationId,X.name,X.description??null,"DRAFT",X.tier??"FREE",J,J]);let R=(await H.query("SELECT * FROM saas_project WHERE id = ?",[G])).rows;return x(R[0])}async function Y(X){let Z=new Date().toISOString(),G=["updatedAt = ?"],J=[Z];if(X.name!==void 0)G.push("name = ?"),J.push(X.name);if(X.description!==void 0)G.push("description = ?"),J.push(X.description);if(X.status!==void 0)G.push("status = ?"),J.push(X.status);J.push(X.id),await H.execute(`UPDATE saas_project SET ${G.join(", ")} WHERE id = ?`,J);let R=(await H.query("SELECT * FROM saas_project WHERE id = ?",[X.id])).rows;if(!R[0])throw Error("NOT_FOUND");return x(R[0])}async function q(X){await H.execute("DELETE FROM saas_project WHERE id = ?",[X])}async function N(X){let Z="SELECT * FROM saas_subscription WHERE projectId = ?",G=[X.projectId];if(X.organizationId)Z+=" AND organizationId = ?",G.push(X.organizationId);Z+=" LIMIT 1";let J=(await H.query(Z,G)).rows;return J[0]?OH(J[0]):null}return{listProjects:$,getProject:W,createProject:Q,updateProject:Y,deleteProject:q,getSubscription:N}}import{defineVisualization as l,VisualizationRegistry as hH}from"@contractspec/lib.contracts-spec/visualizations";var d={key:"saas.project.list",version:"1.0.0"},u={version:"1.0.0",domain:"saas",stability:"experimental",owners:["@example.saas-boilerplate"],tags:["saas","visualization","projects"]},i=l({meta:{...u,key:"saas-boilerplate.visualization.project-usage",title:"Project Capacity",description:"Current project count against the current plan limit.",goal:"Show usage against the active plan allowance.",context:"SaaS account overview."},source:{primary:d,resultPath:"data"},visualization:{kind:"metric",measure:"totalProjects",comparisonMeasure:"projectLimit",measures:[{key:"totalProjects",label:"Projects",dataPath:"totalProjects",format:"number"},{key:"projectLimit",label:"Plan Limit",dataPath:"projectLimit",format:"number"}],table:{caption:"Current project count and plan limit."}}}),o=l({meta:{...u,key:"saas-boilerplate.visualization.project-status",title:"Project Status",description:"Distribution of project states.",goal:"Show the mix of active, draft, and archived projects.",context:"Project portfolio overview."},source:{primary:d,resultPath:"data"},visualization:{kind:"pie",nameDimension:"status",valueMeasure:"projects",dimensions:[{key:"status",label:"Status",dataPath:"status",type:"category"}],measures:[{key:"projects",label:"Projects",dataPath:"projects",format:"number"}],table:{caption:"Project counts by status."}}}),e=l({meta:{...u,key:"saas-boilerplate.visualization.project-tiers",title:"Tier Comparison",description:"Distribution of projects across tiers.",goal:"Compare how the current portfolio is distributed by tier.",context:"Plan and packaging overview."},source:{primary:d,resultPath:"data"},visualization:{kind:"cartesian",variant:"bar",xDimension:"tier",yMeasures:["projects"],dimensions:[{key:"tier",label:"Tier",dataPath:"tier",type:"category"}],measures:[{key:"projects",label:"Projects",dataPath:"projects",format:"number",color:"#1d4ed8"}],table:{caption:"Project counts by tier."}}}),s=l({meta:{...u,key:"saas-boilerplate.visualization.project-activity",title:"Recent Project Activity",description:"Daily project creation activity.",goal:"Show recent project activity over time.",context:"Project portfolio trend view."},source:{primary:d,resultPath:"data"},visualization:{kind:"cartesian",variant:"line",xDimension:"day",yMeasures:["projects"],dimensions:[{key:"day",label:"Day",dataPath:"day",type:"time"}],measures:[{key:"projects",label:"Projects",dataPath:"projects",format:"number",color:"#0f766e"}],table:{caption:"Daily project creation counts."}}}),ZH=[i,o,e,s],I3=new hH([...ZH]),O3=ZH.map((H)=>({key:H.meta.key,version:H.meta.version}));function LH(H){return(H instanceof Date?H:new Date(H)).toISOString().slice(0,10)}function c(H,$=10){let W=new Map,Q=new Map,Y=new Map;for(let q of H){W.set(q.status,(W.get(q.status)??0)+1),Q.set(q.tier,(Q.get(q.tier)??0)+1);let N=LH(q.createdAt);Y.set(N,(Y.get(N)??0)+1)}return[{key:"saas-capacity",spec:i,data:{data:[{totalProjects:H.length,projectLimit:$}]},title:"Project Capacity",description:"Current project count compared to the active limit.",height:220},{key:"saas-status",spec:o,data:{data:Array.from(W.entries()).map(([q,N])=>({status:q,projects:N}))},title:"Project Status",description:"Status mix across the current project portfolio.",height:260},{key:"saas-tier",spec:e,data:{data:Array.from(Q.entries()).map(([q,N])=>({tier:q,projects:N}))},title:"Tier Comparison",description:"How projects are distributed across tiers."},{key:"saas-activity",spec:s,data:{data:Array.from(Y.entries()).sort(([q],[N])=>q.localeCompare(N)).map(([q,N])=>({day:q,projects:N}))},title:"Recent Project Activity",description:"Daily project creation activity."}]}import{useTemplateRuntime as MH}from"@contractspec/lib.example-shared-ui";import{useCallback as EH,useEffect as TH,useMemo as mH,useState as m}from"react";function w(H={}){let{handlers:$,projectId:W}=MH(),{saas:Q}=$,[Y,q]=m(null),[N,X]=m(null),[Z,G]=m(!0),[J,R]=m(null),[z,V]=m(1),U=EH(async()=>{G(!0),R(null);try{let[K,F]=await Promise.all([Q.listProjects({projectId:W,status:H.status==="all"?void 0:H.status,search:H.search,limit:H.limit??20,offset:(z-1)*(H.limit??20)}),Q.getSubscription({projectId:W})]);q({items:K.items,total:K.total}),X(F)}catch(K){R(K instanceof Error?K:Error("Unknown error"))}finally{G(!1)}},[Q,W,H.status,H.search,H.limit,z]);TH(()=>{U()},[U]);let k=mH(()=>{if(!Y)return null;let K=Y.items;return{total:Y.total,activeCount:K.filter((F)=>F.status==="ACTIVE").length,draftCount:K.filter((F)=>F.status==="DRAFT").length,projectLimit:10,usagePercent:Math.min(Y.total/10*100,100)}},[Y]);return{data:Y,subscription:N,loading:Z,error:J,stats:k,page:z,refetch:U,nextPage:()=>V((K)=>K+1),prevPage:()=>z>1&&V((K)=>K-1)}}import{useTemplateRuntime as wH}from"@contractspec/lib.example-shared-ui";import{useCallback as g,useState as t}from"react";function HH(H={}){let{handlers:$,projectId:W}=wH(),{saas:Q}=$,[Y,q]=t({loading:!1,error:null,data:null}),[N,X]=t({loading:!1,error:null,data:null}),[Z,G]=t({loading:!1,error:null,data:null}),J=g(async(k)=>{q({loading:!0,error:null,data:null});try{let K=await Q.createProject(k,{projectId:W,organizationId:"demo-org"});return q({loading:!1,error:null,data:K}),H.onSuccess?.(),K}catch(K){let F=K instanceof Error?K:Error("Failed to create project");return q({loading:!1,error:F,data:null}),H.onError?.(F),null}},[Q,W,H]),R=g(async(k)=>{X({loading:!0,error:null,data:null});try{let K=await Q.updateProject(k);return X({loading:!1,error:null,data:K}),H.onSuccess?.(),K}catch(K){let F=K instanceof Error?K:Error("Failed to update project");return X({loading:!1,error:F,data:null}),H.onError?.(F),null}},[Q,H]),z=g(async(k)=>{G({loading:!0,error:null,data:null});try{return await Q.deleteProject(k),G({loading:!1,error:null,data:{success:!0}}),H.onSuccess?.(),!0}catch(K){let F=K instanceof Error?K:Error("Failed to delete project");return G({loading:!1,error:F,data:null}),H.onError?.(F),!1}},[Q,H]),V=g(async(k)=>{return R({id:k,status:"ARCHIVED"})},[R]),U=g(async(k)=>{return R({id:k,status:"ACTIVE"})},[R]);return{createProject:J,updateProject:R,deleteProject:z,archiveProject:V,activateProject:U,createState:Y,updateState:N,deleteState:Z,isLoading:Y.loading||N.loading||Z.loading}}import{Button as GH,Input as gH}from"@contractspec/lib.design-system";import{useState as p}from"react";import{jsx as v,jsxs as E}from"react/jsx-runtime";var PH=[{value:"FREE",label:"Free"},{value:"PRO",label:"Pro"},{value:"ENTERPRISE",label:"Enterprise"}];function $H({isOpen:H,onClose:$,onSubmit:W,isLoading:Q=!1}){let[Y,q]=p(""),[N,X]=p(""),[Z,G]=p("FREE"),[J,R]=p(null),z=async(V)=>{if(V.preventDefault(),R(null),!Y.trim()){R("Project name is required");return}try{await W({name:Y.trim(),description:N.trim()||void 0,tier:Z}),q(""),X(""),G("FREE"),$()}catch(U){R(U instanceof Error?U.message:"Failed to create project")}};if(!H)return null;return E("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[v("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm",onClick:$,role:"button",tabIndex:0,onKeyDown:(V)=>{if(V.key==="Enter"||V.key===" ")$()},"aria-label":"Close modal"}),E("div",{className:"relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",children:[v("h2",{className:"mb-4 font-semibold text-xl",children:"Create New Project"}),E("form",{onSubmit:z,className:"space-y-4",children:[E("div",{children:[v("label",{htmlFor:"project-name",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Project Name *"}),v(gH,{id:"project-name",value:Y,onChange:(V)=>q(V.target.value),placeholder:"e.g., My Awesome Project",disabled:Q})]}),E("div",{children:[v("label",{htmlFor:"project-description",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Description"}),v("textarea",{id:"project-description",value:N,onChange:(V)=>X(V.target.value),placeholder:"Describe what this project is about...",rows:3,disabled:Q,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 disabled:opacity-50"})]}),E("div",{children:[v("label",{htmlFor:"project-tier",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Tier"}),v("select",{id:"project-tier",value:Z,onChange:(V)=>G(V.target.value),disabled:Q,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:PH.map((V)=>v("option",{value:V.value,children:V.label},V.value))})]}),J&&v("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:J}),E("div",{className:"flex justify-end gap-3 pt-2",children:[v(GH,{type:"button",variant:"ghost",onPress:$,disabled:Q,children:"Cancel"}),v(GH,{type:"submit",disabled:Q,children:Q?"Creating...":"Create Project"})]})]})]})]})}import{Button as O,Input as bH}from"@contractspec/lib.design-system";import{useEffect as CH,useState as j}from"react";import{jsx as y,jsxs as D}from"react/jsx-runtime";function QH({isOpen:H,project:$,onClose:W,onUpdate:Q,onArchive:Y,onActivate:q,onDelete:N,isLoading:X=!1}){let[Z,G]=j("menu"),[J,R]=j(""),[z,V]=j(""),[U,k]=j(null),K=()=>{if(G("menu"),k(null),$)R($.name),V($.description??"")},F=()=>{K(),W()};CH(()=>{if($)R($.name),V($.description??"")},[$]);let b=async()=>{if(!$)return;if(k(null),!J.trim()){k("Project name is required");return}try{await Q({id:$.id,name:J.trim(),description:z.trim()||void 0}),F()}catch(B){k(B instanceof Error?B.message:"Failed to update project")}},kH=async()=>{if(!$)return;k(null);try{await Y($.id),F()}catch(B){k(B instanceof Error?B.message:"Failed to archive project")}},VH=async()=>{if(!$)return;k(null);try{await q($.id),F()}catch(B){k(B instanceof Error?B.message:"Failed to activate project")}},UH=async()=>{if(!$)return;k(null);try{await N($.id),F()}catch(B){k(B instanceof Error?B.message:"Failed to delete project")}};if(!H||!$)return null;return D("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[y("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm",onClick:F,role:"button",tabIndex:0,onKeyDown:(B)=>{if(B.key==="Enter"||B.key===" ")F()},"aria-label":"Close modal"}),D("div",{className:"relative z-10 w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl",children:[D("div",{className:"mb-4 border-border border-b pb-4",children:[y("h2",{className:"font-semibold text-xl",children:$.name}),D("p",{className:"text-muted-foreground text-sm",children:[$.tier," \xB7 ",$.status]})]}),Z==="menu"&&D("div",{className:"space-y-3",children:[D(O,{className:"w-full justify-start",variant:"ghost",onPress:()=>G("edit"),children:[y("span",{className:"mr-2",children:"\u270F\uFE0F"})," Edit Project"]}),$.status==="ACTIVE"||$.status==="DRAFT"?D(O,{className:"w-full justify-start",variant:"ghost",onPress:()=>G("archive"),children:[y("span",{className:"mr-2",children:"\uD83D\uDCE6"})," Archive Project"]}):$.status==="ARCHIVED"?D(O,{className:"w-full justify-start",variant:"ghost",onPress:VH,disabled:X,children:[y("span",{className:"mr-2",children:"\uD83D\uDD04"})," Restore Project"]}):null,D(O,{className:"w-full justify-start text-red-500 hover:text-red-600",variant:"ghost",onPress:()=>G("delete"),children:[y("span",{className:"mr-2",children:"\uD83D\uDDD1\uFE0F"})," Delete Project"]}),y("div",{className:"border-border border-t pt-3",children:y(O,{className:"w-full",variant:"outline",onPress:F,children:"Close"})})]}),Z==="edit"&&D("div",{className:"space-y-4",children:[D("div",{children:[y("label",{htmlFor:"edit-name",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Project Name *"}),y(bH,{id:"edit-name",value:J,onChange:(B)=>R(B.target.value),disabled:X})]}),D("div",{children:[y("label",{htmlFor:"edit-description",className:"mb-1 block font-medium text-muted-foreground text-sm",children:"Description"}),y("textarea",{id:"edit-description",value:z,onChange:(B)=>V(B.target.value),rows:3,disabled:X,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 disabled:opacity-50"})]}),U&&y("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:U}),D("div",{className:"flex justify-end gap-3 pt-2",children:[y(O,{variant:"ghost",onPress:()=>G("menu"),disabled:X,children:"Back"}),y(O,{onPress:b,disabled:X,children:X?"Saving...":"Save Changes"})]})]}),Z==="archive"&&D("div",{className:"space-y-4",children:[D("p",{className:"text-muted-foreground",children:["Are you sure you want to archive"," ",y("span",{className:"font-medium text-foreground",children:$.name}),"?"]}),y("p",{className:"text-muted-foreground text-sm",children:"Archived projects can be restored later."}),U&&y("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:U}),D("div",{className:"flex justify-end gap-3 pt-2",children:[y(O,{variant:"ghost",onPress:()=>G("menu"),disabled:X,children:"Cancel"}),y(O,{onPress:kH,disabled:X,children:X?"Archiving...":"\uD83D\uDCE6 Archive"})]})]}),Z==="delete"&&D("div",{className:"space-y-4",children:[D("p",{className:"text-muted-foreground",children:["Are you sure you want to delete"," ",y("span",{className:"font-medium text-foreground",children:$.name}),"?"]}),y("p",{className:"text-destructive text-sm",children:"This action cannot be undone."}),U&&y("div",{className:"rounded-md bg-destructive/10 p-3 text-destructive text-sm",children:U}),D("div",{className:"flex justify-end gap-3 pt-2",children:[y(O,{variant:"ghost",onPress:()=>G("menu"),disabled:X,children:"Cancel"}),y(O,{variant:"destructive",onPress:UH,disabled:X,children:X?"Deleting...":"\uD83D\uDDD1\uFE0F Delete"})]})]})]})]})}var SH={overlayId:"saas-boilerplate.free-tier",version:"1.0.0",description:"Shows limitations for free tier users",appliesTo:{feature:"saas-boilerplate",tier:"free"},modifications:[{type:"setLimit",field:"projects",max:3,message:"Upgrade to create more projects"},{type:"hideField",field:"advancedSettings",reason:"Pro feature"},{type:"addBadge",position:"header",label:"Free Plan",variant:"default"}]},xH={overlayId:"saas-boilerplate.demo-user",version:"1.0.0",description:"Demo mode for SaaS boilerplate",appliesTo:{feature:"saas-boilerplate",role:"demo"},modifications:[{type:"hideField",field:"billingSection",reason:"Demo users cannot access billing"},{type:"hideField",field:"deleteAccount",reason:"Not available in demo"},{type:"addBadge",position:"header",label:"Demo Mode",variant:"warning"}]},t3=[SH,xH];var YH=["FREE","PRO","ENTERPRISE"];function lH(H,$){return{status:H.status==="DELETED"?"ARCHIVED":H.status,tier:YH[$%YH.length]??"FREE",createdAt:H.createdAt}}var dH={target:"markdown",render:async(H,$)=>{if(H.source.type!=="component"||H.source.componentKey!=="ProjectListView")throw Error("projectListMarkdownRenderer: not ProjectListView");let W=await S({limit:20,offset:0}),Q=W.projects??[],Y=["# Projects","",`**Total**: ${W.total} projects`,""];if(Q.length===0)Y.push("_No projects found._");else{Y.push("| Status | Project | Description |"),Y.push("|--------|---------|-------------|");for(let q of Q){let N=q.status==="ACTIVE"?"\u2705":q.status==="ARCHIVED"?"\uD83D\uDCE6":"\u23F8\uFE0F";Y.push(`| ${N} | **${q.name}** | ${q.description??"-"} |`)}}return{mimeType:"text/markdown",body:Y.join(`
4
+ `)}}},uH={target:"markdown",render:async(H,$)=>{if(H.source.type!=="component"||H.source.componentKey!=="SaasDashboard")throw Error("saasDashboardMarkdownRenderer: not SaasDashboard");let[W,Q]=await Promise.all([S({limit:50}),C()]),Y=W.projects??[],q=Y.filter((G)=>G.status==="ACTIVE").length,N=Y.filter((G)=>G.status==="ARCHIVED").length,X=c(Y.map(lH),10),Z=["# SaaS Dashboard","","> Organization overview and usage summary","","## Summary","","| Metric | Value |","|--------|-------|",`| Total Projects | ${W.total} |`,`| Active Projects | ${q} |`,`| Archived Projects | ${N} |`,`| Subscription Plan | ${Q.planName} |`,`| Subscription Status | ${Q.status} |`,""];Z.push("## Visualization Overview"),Z.push("");for(let G of X)Z.push(`- **${G.title}** via \`${G.spec.meta.key}\``);if(Z.push(""),Z.push("## Projects"),Z.push(""),Y.length===0)Z.push("_No projects yet._");else{Z.push("| Status | Project | Description |"),Z.push("|--------|---------|-------------|");for(let G of Y.slice(0,10)){let J=G.status==="ACTIVE"?"\u2705":G.status==="ARCHIVED"?"\uD83D\uDCE6":"\u23F8\uFE0F";Z.push(`| ${J} | **${G.name}** | ${G.description??"-"} |`)}if(Y.length>10)Z.push(`| ... | ... | _${W.total-10} more projects_ |`)}if(Z.push(""),Z.push("## Subscription"),Z.push(""),Z.push(`- **Plan**: ${Q.planName}`),Z.push(`- **Status**: ${Q.status}`),Q.currentPeriodEnd)Z.push(`- **Period End**: ${new Date(Q.currentPeriodEnd).toLocaleDateString()}`);return{mimeType:"text/markdown",body:Z.join(`
5
+ `)}}},cH={target:"markdown",render:async(H,$)=>{if(H.source.type!=="component"||H.source.componentKey!=="SubscriptionView")throw Error("saasBillingMarkdownRenderer: not SubscriptionView");let W=await C(),Q=["# Billing & Subscription","","> Current subscription details and billing information","","## Subscription Details","","| Property | Value |","|----------|-------|",`| Plan | ${W.planName} |`,`| Status | ${W.status} |`,`| ID | ${W.id} |`,`| Period Start | ${new Date(W.currentPeriodStart).toLocaleDateString()} |`,`| Period End | ${new Date(W.currentPeriodEnd).toLocaleDateString()} |`];if(Q.push(""),Q.push("## Plan Limits"),Q.push(""),Q.push(`- **Projects**: ${W.limits.projects}`),Q.push(`- **Users**: ${W.limits.users}`),Q.push(""),Q.push("## Plan Features"),Q.push(""),W.planName.toLowerCase().includes("free"))Q.push("- \u2705 Up to 3 projects"),Q.push("- \u2705 Basic support"),Q.push("- \u274C Priority support"),Q.push("- \u274C Advanced analytics");else if(W.planName.toLowerCase().includes("pro"))Q.push("- \u2705 Unlimited projects"),Q.push("- \u2705 Priority support"),Q.push("- \u2705 Advanced analytics"),Q.push("- \u274C Custom integrations");else Q.push("- \u2705 Unlimited projects"),Q.push("- \u2705 Priority support"),Q.push("- \u2705 Advanced analytics"),Q.push("- \u2705 Custom integrations"),Q.push("- \u2705 Dedicated support");return{mimeType:"text/markdown",body:Q.join(`
6
+ `)}}};import{Button as pH,EmptyState as jH,EntityCard as nH,ErrorState as rH,LoaderBlock as aH,StatCard as WH,StatCardGroup as iH,StatusChip as oH}from"@contractspec/lib.design-system";import{jsx as I,jsxs as qH}from"react/jsx-runtime";function eH(H){switch(H){case"ACTIVE":return"success";case"DRAFT":return"neutral";case"ARCHIVED":return"danger";default:return"neutral"}}function FH({onProjectClick:H,onCreateProject:$}){let{data:W,loading:Q,error:Y,stats:q,refetch:N}=w();if(Q&&!W)return I(aH,{label:"Loading projects..."});if(Y)return I(rH,{title:"Failed to load projects",description:Y.message,onRetry:N,retryLabel:"Retry"});if(!W?.items.length)return I(jH,{title:"No projects found",description:"Create your first project to get started.",primaryAction:$?I(pH,{onPress:$,children:"Create Project"}):void 0});return qH("div",{className:"space-y-6",children:[q&&qH(iH,{children:[I(WH,{label:"Total Projects",value:q.total.toString()}),I(WH,{label:"Active",value:q.activeCount.toString()}),I(WH,{label:"Draft",value:q.draftCount.toString()})]}),I("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:W.items.map((X)=>I(nH,{cardTitle:X.name,cardSubtitle:X.tier,meta:I("p",{className:"text-muted-foreground text-sm",children:X.description}),chips:I(oH,{tone:eH(X.status),label:X.status}),footer:I("span",{className:"text-muted-foreground text-xs",children:X.updatedAt.toLocaleDateString()}),onClick:H?()=>H(X.id):void 0},X.id))})]})}import{jsx as tH}from"react/jsx-runtime";var sH={target:"react",render:async(H,$)=>{if(H.source.type!=="component")throw Error("Invalid source type");if(H.source.componentKey!=="SaasProjectListView")throw Error(`Unknown component: ${H.source.componentKey}`);return tH(FH,{})}};import{VisualizationCard as H3,VisualizationGrid as $3}from"@contractspec/lib.design-system";import{jsx as n,jsxs as fH}from"react/jsx-runtime";function NH({projects:H,projectLimit:$}){let W=c(H,$);return fH("section",{className:"space-y-3",children:[fH("div",{children:[n("h3",{className:"font-semibold text-lg",children:"Portfolio Visualizations"}),n("p",{className:"text-muted-foreground text-sm",children:"Contract-backed charts for project mix, capacity, and activity."})]}),n($3,{children:W.map((Q)=>n(H3,{data:Q.data,description:Q.description,height:Q.height,spec:Q.spec,title:Q.title},Q.key))})]})}import{Button as P,EmptyState as Q3,EntityCard as W3,ErrorState as X3,LoaderBlock as Z3,StatCard as r,StatCardGroup as G3,StatusChip as JH}from"@contractspec/lib.design-system";import{useCallback as Y3,useState as a}from"react";import{jsx as f,jsxs as _}from"react/jsx-runtime";function q3(H){switch(H){case"ACTIVE":return"success";case"DRAFT":return"neutral";case"ARCHIVED":return"warning";default:return"neutral"}}function h$(){let[H,$]=a("projects"),[W,Q]=a(!1),[Y,q]=a(null),[N,X]=a(!1),{data:Z,subscription:G,loading:J,error:R,stats:z,refetch:V}=w(),U=HH({onSuccess:()=>{V()}}),k=Y3((F)=>{q(F),X(!0)},[]),K=[{id:"projects",label:"Projects",icon:"\uD83D\uDCC1"},{id:"billing",label:"Billing",icon:"\uD83D\uDCB3"},{id:"settings",label:"Settings",icon:"\u2699\uFE0F"}];if(J&&!Z)return f(Z3,{label:"Loading dashboard..."});if(R)return f(X3,{title:"Failed to load dashboard",description:R.message,onRetry:V,retryLabel:"Retry"});return _("div",{className:"space-y-6",children:[_("div",{className:"flex items-center justify-between",children:[f("h2",{className:"font-bold text-2xl",children:"SaaS Dashboard"}),H==="projects"&&_(P,{onPress:()=>Q(!0),children:[f("span",{className:"mr-2",children:"+"})," New Project"]})]}),z&&G&&_(G3,{children:[f(r,{label:"Projects",value:z.total.toString()}),f(r,{label:"Active",value:z.activeCount.toString()}),f(r,{label:"Draft",value:z.draftCount.toString()}),f(r,{label:"Plan",value:G.plan,hint:G.status})]}),Z&&z&&f(NH,{projectLimit:z.projectLimit,projects:Z.items}),f("nav",{className:"flex gap-1 rounded-lg bg-muted p-1",role:"tablist",children:K.map((F)=>_("button",{type:"button",role:"tab","aria-selected":H===F.id,onClick:()=>$(F.id),className:`flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 font-medium text-sm transition-colors ${H===F.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[f("span",{children:F.icon}),F.label]},F.id))}),_("div",{className:"min-h-[400px]",role:"tabpanel",children:[H==="projects"&&f(F3,{data:Z,onProjectClick:k}),H==="billing"&&f(f3,{subscription:G}),H==="settings"&&f(N3,{})]}),f($H,{isOpen:W,onClose:()=>Q(!1),onSubmit:async(F)=>{await U.createProject(F)},isLoading:U.createState.loading}),f(QH,{isOpen:N,project:Y,onClose:()=>{X(!1),q(null)},onUpdate:async(F)=>{await U.updateProject(F)},onArchive:async(F)=>{await U.archiveProject(F)},onActivate:async(F)=>{await U.activateProject(F)},onDelete:async(F)=>{await U.deleteProject(F)},isLoading:U.isLoading})]})}function F3({data:H,onProjectClick:$}){if(!H?.items.length)return f(Q3,{title:"No projects yet",description:"Create your first project to get started."});return f("div",{className:"space-y-4",children:f("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:H.items.map((W)=>f(W3,{cardTitle:W.name,cardSubtitle:W.tier,meta:f("p",{className:"text-muted-foreground text-sm",children:W.description}),chips:f(JH,{tone:q3(W.status),label:W.status}),footer:_("div",{className:"flex w-full items-center justify-between",children:[f("span",{className:"text-muted-foreground text-xs",children:W.updatedAt.toLocaleDateString()}),f(P,{variant:"ghost",size:"sm",onPress:()=>$?.(W),children:"Actions"})]})},W.id))})})}function f3({subscription:H}){if(!H)return null;return _("div",{className:"space-y-6",children:[_("div",{className:"rounded-xl border border-border bg-card p-6",children:[_("div",{className:"flex items-start justify-between",children:[_("div",{children:[_("h3",{className:"font-semibold text-lg",children:[H.plan," Plan"]}),_("p",{className:"text-muted-foreground text-sm",children:["Current period:"," ",H.currentPeriodStart.toLocaleDateString()," -"," ",H.currentPeriodEnd.toLocaleDateString()]}),_("p",{className:"text-muted-foreground text-sm",children:["Billing cycle: ",H.billingCycle]})]}),f(JH,{tone:"success",label:H.status})]}),_("div",{className:"mt-4 flex gap-3",children:[f(P,{variant:"outline",onPress:()=>alert("Upgrade clicked!"),children:"Upgrade Plan"}),f(P,{variant:"ghost",onPress:()=>alert("Manage Billing clicked!"),children:"Manage Billing"})]})]}),H.cancelAtPeriodEnd&&f("div",{className:"rounded-xl border border-border bg-destructive/10 p-4 text-destructive",children:f("p",{className:"font-medium text-sm",children:"\u26A0\uFE0F Your subscription will be cancelled at the end of the current period."})})]})}function N3(){return f("div",{className:"space-y-6",children:_("div",{className:"rounded-xl border border-border bg-card p-6",children:[f("h3",{className:"mb-4 font-semibold text-lg",children:"Organization Settings"}),_("div",{className:"space-y-4",children:[_("div",{children:[f("label",{htmlFor:"org-name",className:"font-medium text-sm",children:"Organization Name"}),f("input",{id:"org-name",type:"text",defaultValue:"Demo Organization",className:"mt-1 block w-full rounded-md border border-input bg-background px-3 py-2"})]}),_("div",{children:[f("label",{htmlFor:"timezone",className:"font-medium text-sm",children:"Default Timezone"}),_("select",{id:"timezone",className:"mt-1 block w-full rounded-md border border-input bg-background px-3 py-2",children:[f("option",{children:"UTC"}),f("option",{children:"America/New_York"}),f("option",{children:"Europe/London"}),f("option",{children:"Asia/Tokyo"})]})]}),f("div",{className:"pt-2",children:f(P,{onPress:()=>alert("Settings saved!"),children:"Save Settings"})})]})]})})}import{Button as XH}from"@contractspec/lib.design-system";import{useState as KH}from"react";import{jsx as A,jsxs as h}from"react/jsx-runtime";function m$(){let[H,$]=KH("Demo Organization"),[W,Q]=KH("UTC");return h("div",{className:"space-y-6",children:[h("div",{className:"rounded-xl border border-border bg-card p-6",children:[A("h3",{className:"mb-4 font-semibold text-lg",children:"Organization Settings"}),h("div",{className:"space-y-4",children:[h("div",{children:[A("label",{htmlFor:"setting-org-name",className:"block font-medium text-sm",children:"Organization Name"}),A("input",{id:"setting-org-name",type:"text",value:H,onChange:(Y)=>$(Y.target.value),className:"mt-1 block w-full rounded-md border border-input bg-background px-3 py-2"})]}),h("div",{children:[A("label",{htmlFor:"setting-timezone",className:"block font-medium text-sm",children:"Default Timezone"}),h("select",{id:"setting-timezone",value:W,onChange:(Y)=>Q(Y.target.value),className:"mt-1 block w-full rounded-md border border-input bg-background px-3 py-2",children:[A("option",{value:"UTC",children:"UTC"}),A("option",{value:"America/New_York",children:"America/New_York"}),A("option",{value:"Europe/London",children:"Europe/London"}),A("option",{value:"Asia/Tokyo",children:"Asia/Tokyo"})]})]})]}),A("div",{className:"mt-6",children:A(XH,{variant:"default",children:"Save Changes"})})]}),h("div",{className:"rounded-xl border border-border bg-card p-6",children:[A("h3",{className:"mb-4 font-semibold text-lg",children:"Notifications"}),A("div",{className:"space-y-3",children:[{label:"Email notifications",defaultChecked:!0},{label:"Usage alerts",defaultChecked:!0},{label:"Weekly digest",defaultChecked:!1}].map((Y)=>h("label",{className:"flex items-center gap-3",children:[A("input",{type:"checkbox",defaultChecked:Y.defaultChecked,className:"h-4 w-4 rounded border-input"}),A("span",{className:"text-sm",children:Y.label})]},Y.label))})]}),h("div",{className:"rounded-xl border border-red-200 bg-red-50 p-6 dark:border-red-900 dark:bg-red-950/20",children:[A("h3",{className:"mb-2 font-semibold text-lg text-red-700 dark:text-red-400",children:"Danger Zone"}),A("p",{className:"mb-4 text-red-600 text-sm dark:text-red-300",children:"These actions are irreversible. Please proceed with caution."}),h("div",{className:"flex gap-3",children:[A(XH,{variant:"secondary",size:"sm",children:"Export Data"}),A(XH,{variant:"secondary",size:"sm",children:"Delete Organization"})]})]})]})}export{HH as useProjectMutations,w as useProjectList,t3 as saasOverlays,SH as saasFreeUserOverlay,xH as saasDemoOverlay,uH as saasDashboardMarkdownRenderer,cH as saasBillingMarkdownRenderer,sH as projectListReactRenderer,dH as projectListMarkdownRenderer,m$ as SaasSettingsPanel,FH as SaasProjectList,h$ as SaasDashboard,QH as ProjectActionsModal,$H as CreateProjectModal};