@saasicat/ui-vue 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +47 -0
  3. package/dist/index.cjs +3776 -0
  4. package/dist/index.d.cts +2395 -0
  5. package/dist/index.d.ts +2395 -0
  6. package/dist/index.js +3659 -0
  7. package/dist/testing-e2e/admin-pages-suite.cjs +134 -0
  8. package/dist/testing-e2e/admin-pages-suite.d.cts +37 -0
  9. package/dist/testing-e2e/admin-pages-suite.d.ts +37 -0
  10. package/dist/testing-e2e/admin-pages-suite.js +109 -0
  11. package/package.json +87 -0
  12. package/src/action-registry.ts +110 -0
  13. package/src/batch-column-fetcher.ts +152 -0
  14. package/src/boot-loader.ts +60 -0
  15. package/src/components/BundleVersionPublishDialog.vue +359 -0
  16. package/src/components/BusinessTypeVersionEditorDialog.vue +417 -0
  17. package/src/components/BusinessTypeVersionPublishDialog.vue +258 -0
  18. package/src/components/FeatureGate.vue +56 -0
  19. package/src/components/KpiCard.vue +53 -0
  20. package/src/components/KvBlock.vue +36 -0
  21. package/src/components/MarketingPromotionsTab.vue +861 -0
  22. package/src/components/MfaPromptDialog.vue +104 -0
  23. package/src/components/TenantActionConfirmDialog.vue +252 -0
  24. package/src/components/VersionDiffPreview.vue +150 -0
  25. package/src/components/bundle-editor/BundleCreatePanel.vue +681 -0
  26. package/src/components/bundle-editor/BundleFeaturesEditor.vue +215 -0
  27. package/src/components/bundle-editor/BundlePlanCompatPicker.vue +316 -0
  28. package/src/components/bundle-editor/BundleQuotasEditor.vue +219 -0
  29. package/src/components/bundle-editor/BundleStatusBanner.vue +189 -0
  30. package/src/components/bundle-editor/BundleVersionInlineEditor.vue +659 -0
  31. package/src/components/bundle-editor/BundleVersionStrip.vue +207 -0
  32. package/src/components/bundle-editor/bundle-version-status.ts +164 -0
  33. package/src/components/bundle-editor/catalog-i18n.ts +85 -0
  34. package/src/components/dialogs/PilotCreateDialog.vue +780 -0
  35. package/src/components/dialogs/PilotEditDialog.vue +548 -0
  36. package/src/components/dialogs/PromoCodeCreateDialog.vue +737 -0
  37. package/src/components/dialogs/PromoCodeEditDialog.vue +859 -0
  38. package/src/components/dialogs/types.ts +126 -0
  39. package/src/components/plan/PlanCycleToggle.vue +99 -0
  40. package/src/components/plan/PlanGrid.vue +211 -0
  41. package/src/components/plan/PriceSummary.vue +293 -0
  42. package/src/components/plan/PromoCodeInput.vue +192 -0
  43. package/src/components/plan/PublicBundleGrid.vue +287 -0
  44. package/src/components/plan-cockpit/PlanCockpit.vue +993 -0
  45. package/src/components/plan-cockpit/PlanCockpitAuditLog.vue +65 -0
  46. package/src/components/plan-cockpit/PlanCockpitDiffPanel.vue +91 -0
  47. package/src/components/plan-cockpit/PlanCockpitHeader.vue +98 -0
  48. package/src/components/plan-cockpit/PlanCockpitImpactPanel.vue +99 -0
  49. package/src/components/plan-cockpit/PlanCockpitKpis.vue +57 -0
  50. package/src/components/plan-cockpit/PlanCockpitVersions.vue +226 -0
  51. package/src/components/plan-cockpit/types.ts +72 -0
  52. package/src/components/plan-create-dialog/PlanCreateDialog.vue +508 -0
  53. package/src/components/plan-detail/PlanAuditLog.vue +59 -0
  54. package/src/components/plan-detail/PlanDetail.vue +1195 -0
  55. package/src/components/plan-detail/PlanDetailHeader.vue +185 -0
  56. package/src/components/plan-detail/PlanDetailKpis.vue +57 -0
  57. package/src/components/plan-detail/PlanTerminateDialog.vue +76 -0
  58. package/src/components/plan-detail/PlanVersionDiffPanel.vue +149 -0
  59. package/src/components/plan-detail/PlanVersionsPanel.vue +255 -0
  60. package/src/components/plan-detail/types.ts +59 -0
  61. package/src/components/plan-list/PlanList.vue +1067 -0
  62. package/src/components/plan-matrix/PlanMatrix.vue +1113 -0
  63. package/src/components/plan-review/PlanReview.vue +742 -0
  64. package/src/components/plan-version-editor/PlanCatalogPreview.vue +184 -0
  65. package/src/components/plan-version-editor/PlanComponentPool.vue +272 -0
  66. package/src/components/plan-version-editor/PlanVersionBasket.vue +281 -0
  67. package/src/components/plan-version-editor/PlanVersionDiffDialog.vue +84 -0
  68. package/src/components/plan-version-editor/PlanVersionEditor.vue +1728 -0
  69. package/src/components/plan-version-editor/PlanVersionEditorHeader.vue +94 -0
  70. package/src/components/plan-version-editor/types.ts +96 -0
  71. package/src/components/wizard-stepper/WizardStepper.vue +107 -0
  72. package/src/create-admin-routes.ts +68 -0
  73. package/src/create-super-admin-app.ts +345 -0
  74. package/src/entitlement-provider.ts +36 -0
  75. package/src/feature-router-guard.ts +77 -0
  76. package/src/http-json.ts +62 -0
  77. package/src/index.ts +98 -0
  78. package/src/manifest-loader.ts +139 -0
  79. package/src/manifest-store-factory.ts +114 -0
  80. package/src/nav-builder.ts +274 -0
  81. package/src/pages-standard/AdminLayout.vue +411 -0
  82. package/src/pages-standard/AdminManifestErrorPage.vue +79 -0
  83. package/src/pages-standard/AuditPage.vue +223 -0
  84. package/src/pages-standard/BundlesPage.vue +910 -0
  85. package/src/pages-standard/BusinessTypesPage.vue +662 -0
  86. package/src/pages-standard/DashboardPage.vue +595 -0
  87. package/src/pages-standard/DiscoveryPage.vue +663 -0
  88. package/src/pages-standard/EmailHistoryPage.vue +576 -0
  89. package/src/pages-standard/MarketingCatalogPage.vue +1771 -0
  90. package/src/pages-standard/PilotsPage.vue +577 -0
  91. package/src/pages-standard/PlanVersionsPage.vue +216 -0
  92. package/src/pages-standard/PlansPage.vue +1222 -0
  93. package/src/pages-standard/PlatformEmailPage.vue +434 -0
  94. package/src/pages-standard/PromoCodeDetailPage.vue +331 -0
  95. package/src/pages-standard/PromoCodesPage.vue +589 -0
  96. package/src/pages-standard/SubscriptionsPage.vue +159 -0
  97. package/src/pages-standard/SuperAdminLoginPage.vue +299 -0
  98. package/src/pages-standard/SuperAdminSetupWizard.vue +405 -0
  99. package/src/pages-standard/TenantDetailPage.vue +432 -0
  100. package/src/pages-standard/TenantsPage.vue +732 -0
  101. package/src/pages-standard/UsersPage.vue +504 -0
  102. package/src/pages-standard/bundles-page/BundleAccordionList.vue +116 -0
  103. package/src/pages-standard/bundles-page/BundleDetailPanel.vue +193 -0
  104. package/src/pages-standard/bundles-page/BundlesFilterBar.vue +48 -0
  105. package/src/pages-standard/bundles-page/BundlesHeader.vue +67 -0
  106. package/src/pages-standard/bundles-page/BundlesKpis.vue +39 -0
  107. package/src/pages-standard/bundles-page/types.ts +15 -0
  108. package/src/pages-standard/discovery-page/CatalogEntryTransPanel.vue +246 -0
  109. package/src/pages-standard/discovery-page/DiscoveryCapList.vue +171 -0
  110. package/src/pages-standard/discovery-page/DiscoveryFeatureCard.vue +410 -0
  111. package/src/pages-standard/discovery-page/DiscoveryHeader.vue +31 -0
  112. package/src/pages-standard/discovery-page/DiscoveryKpis.vue +47 -0
  113. package/src/pages-standard/discovery-page/DiscoveryMetaBanner.vue +26 -0
  114. package/src/pages-standard/discovery-page/DiscoveryQuotaCard.vue +247 -0
  115. package/src/pages-standard/discovery-page/DiscoveryStatusControl.vue +73 -0
  116. package/src/pages-standard/discovery-page/discovery-ui.ts +166 -0
  117. package/src/pages-standard/email-history.types.ts +48 -0
  118. package/src/pages-standard/marketing-catalog/MarketingCatalogAdmin.vue +448 -0
  119. package/src/pages-standard/marketing-catalog/MarketingCatalogHeader.vue +93 -0
  120. package/src/pages-standard/marketing-catalog/MarketingCatalogPreview.vue +138 -0
  121. package/src/pages-standard/marketing-catalog/MarketingCatalogToolbar.vue +58 -0
  122. package/src/pages-standard/marketing-catalog/types.ts +43 -0
  123. package/src/pages-standard/plan-versions/PlanDiffCard.vue +132 -0
  124. package/src/pages-standard/plan-versions/PlanVersionHeader.vue +293 -0
  125. package/src/pages-standard/plan-versions/PlanVersionStatusBadge.vue +48 -0
  126. package/src/pages-standard/plan-versions/PlanVersionsAudit.vue +307 -0
  127. package/src/pages-standard/plan-versions/PlanVersionsDiff.vue +269 -0
  128. package/src/pages-standard/plan-versions/PlanVersionsKpi.vue +65 -0
  129. package/src/pages-standard/plan-versions/PlanVersionsList.vue +292 -0
  130. package/src/pages-standard/plan-versions/PlanVersionsMatrix.vue +261 -0
  131. package/src/pages-standard/plan-versions/PlanVersionsTimeline.vue +300 -0
  132. package/src/pages-standard/plan-versions/VersionDiffPreview.vue +167 -0
  133. package/src/pages-standard/plan-versions/format.ts +53 -0
  134. package/src/pages-standard/plan-versions/types.ts +33 -0
  135. package/src/pages-standard/plans-page/PlanArchiveDialog.vue +50 -0
  136. package/src/pages-standard/plans-page/PlanBundleOverview.vue +147 -0
  137. package/src/pages-standard/plans-page/PlanDiscardDraftDialog.vue +46 -0
  138. package/src/pages-standard/plans-page/PlanPublishDialog.vue +106 -0
  139. package/src/pages-standard/plans-page/PlansPageToast.vue +69 -0
  140. package/src/pages-standard/plans-page/types.ts +18 -0
  141. package/src/pages-standard/platform-email.types.ts +41 -0
  142. package/src/pages-standard/sa-theme.css +223 -0
  143. package/src/pages-standard/tenants/StatusPill.vue +62 -0
  144. package/src/pages-standard/tenants/format.ts +38 -0
  145. package/src/pages-tenant/LimitsRow.vue +67 -0
  146. package/src/pages-tenant/MySubscriptionBundlesPage.vue +604 -0
  147. package/src/pages-tenant/OnboardingConfigurator.vue +417 -0
  148. package/src/pages-tenant/PackageSnapshotPanel.vue +241 -0
  149. package/src/pages-tenant/PendingVersionBanner.vue +126 -0
  150. package/src/pages-tenant/PlanChangeWizard.vue +630 -0
  151. package/src/pages-tenant/TenantPlanSection.vue +729 -0
  152. package/src/pages-tenant/UsageBar.vue +107 -0
  153. package/src/pages-tenant/default-i18n.ts +280 -0
  154. package/src/pages-tenant/tenant-plan-section/BundlePreviewDialog.vue +304 -0
  155. package/src/pages-tenant/tenant-plan-section/TenantBundleStore.vue +323 -0
  156. package/src/pages-tenant/tenant-plan-section/TenantFeatureMatrix.vue +122 -0
  157. package/src/pages-tenant/tenant-plan-section/TenantPlanCardHeader.vue +67 -0
  158. package/src/pages-tenant/tenant-plan-section/TenantUsageGrid.vue +31 -0
  159. package/src/plan-versions-catalog.ts +368 -0
  160. package/src/platform-loaders.ts +68 -0
  161. package/src/project-page-host.ts +108 -0
  162. package/src/testing-e2e/admin-pages-suite.ts +187 -0
  163. package/src/types.ts +58 -0
  164. package/src/use-actions.ts +25 -0
  165. package/src/use-api-list.ts +151 -0
  166. package/src/use-audit-entries.ts +48 -0
  167. package/src/use-batch-columns.ts +59 -0
  168. package/src/use-bulk-publish.ts +150 -0
  169. package/src/use-bundle-versions-map.ts +112 -0
  170. package/src/use-bundles.ts +297 -0
  171. package/src/use-business-types.ts +269 -0
  172. package/src/use-catalog-entries.ts +243 -0
  173. package/src/use-discovery.ts +158 -0
  174. package/src/use-entitlement.ts +87 -0
  175. package/src/use-live-plan-versions.ts +126 -0
  176. package/src/use-manifest.ts +57 -0
  177. package/src/use-marketing-projections.ts +160 -0
  178. package/src/use-nav.ts +33 -0
  179. package/src/use-plan-editor.ts +162 -0
  180. package/src/use-plan-versions.ts +83 -0
  181. package/src/use-plans.ts +375 -0
  182. package/src/use-platform-tenant-actions.ts +286 -0
  183. package/src/use-promotions.ts +126 -0
  184. package/src/use-public-boot.ts +40 -0
  185. package/src/use-subscription-draft.ts +355 -0
  186. package/src/use-super-admin-context.ts +93 -0
  187. package/src/use-tenant-action-flow.ts +238 -0
  188. package/src/use-tenant-billing-catalog.ts +160 -0
  189. package/src/use-tenant-billing.ts +453 -0
  190. package/src/use-tenant-manifest.ts +94 -0
  191. package/src/use-tenant-subscription-bundles.ts +148 -0
  192. package/src/use-tenants.ts +61 -0
  193. package/src/version.ts +10 -0
@@ -0,0 +1,630 @@
1
+ <template>
2
+ <q-dialog v-model="model" persistent>
3
+ <q-card class="sp-wizard">
4
+ <q-card-section class="sp-wizard__head">
5
+ <div>
6
+ <div class="sp-wizard__title">{{ i18n.title }}</div>
7
+ <div class="sp-wizard__sub">
8
+ {{ i18n.currentLabel }}: {{ currentPlanName }} ({{ currentCycleLabel }})
9
+ </div>
10
+ </div>
11
+ <q-btn flat round dense icon="close" :aria-label="i18n.close" @click="close" />
12
+ </q-card-section>
13
+
14
+ <q-stepper
15
+ v-model="step"
16
+ animated
17
+ flat
18
+ keep-alive
19
+ active-color="primary"
20
+ class="sp-wizard__stepper"
21
+ >
22
+ <!-- Step 1: Plan + Cycle -->
23
+ <q-step :name="1" :title="i18n.stepChoose" icon="grade" :done="step > 1">
24
+ <p class="sp-wizard__intro">{{ i18n.stepChooseIntro }}</p>
25
+
26
+ <PlanCycleToggle
27
+ :model-value="targetCycle"
28
+ :i18n="cycleI18n"
29
+ class="q-mb-md"
30
+ @update:model-value="targetCycle = $event"
31
+ />
32
+
33
+ <PlanGrid
34
+ :model-value="targetPlan"
35
+ :plans="plans"
36
+ :cycle="targetCycle"
37
+ :catalog-quota-keys="catalogQuotaKeys"
38
+ :current-plan-id="currentPlanId"
39
+ :format-currency="formatCurrency"
40
+ :format-quota-value="formatQuotaValueResolved"
41
+ :quota-label="quotaLabel"
42
+ :i18n="planGridI18n"
43
+ @update:model-value="targetPlan = $event"
44
+ />
45
+
46
+ <q-stepper-navigation>
47
+ <q-btn
48
+ color="primary"
49
+ :label="i18n.next"
50
+ :disable="!targetPlan || !canAdvanceFromStep1"
51
+ unelevated
52
+ @click="goToPreview"
53
+ />
54
+ </q-stepper-navigation>
55
+ </q-step>
56
+
57
+ <!-- Step 2: Preview -->
58
+ <q-step :name="2" :title="i18n.stepPreview" icon="preview" :done="step > 2">
59
+ <div v-if="previewLoading" class="sp-wizard__loading">
60
+ <q-spinner size="32px" />
61
+ <span>{{ i18n.previewLoading }}</span>
62
+ </div>
63
+
64
+ <div v-else-if="previewError" class="sp-wizard__error">
65
+ {{ previewError }}
66
+ </div>
67
+
68
+ <template v-else-if="preview">
69
+ <div class="sp-wizard__type">
70
+ <q-badge
71
+ :color="changeTypeColor"
72
+ :label="changeTypeLabel"
73
+ class="q-mr-sm"
74
+ />
75
+ <span v-if="preview.effectiveAt && !preview.isImmediate">
76
+ {{ i18n.effectiveAtLabel }}: {{ formatDate(preview.effectiveAt) }}
77
+ </span>
78
+ <span v-else-if="preview.isImmediate">
79
+ {{ i18n.effectiveImmediate }}
80
+ </span>
81
+ </div>
82
+
83
+ <div v-if="preview.proration" class="sp-wizard__proration">
84
+ <h4>{{ i18n.prorationTitle }}</h4>
85
+ <p>
86
+ {{ i18n.prorationLine }}
87
+ <strong>{{
88
+ formatCurrency(preview.proration.prorataDeltaNet)
89
+ }}</strong>
90
+ ({{ preview.proration.daysRemainingInPeriod }} /
91
+ {{ preview.proration.daysInPeriod }} {{ i18n.prorationDays }})
92
+ </p>
93
+ </div>
94
+
95
+ <h4 class="q-mt-lg">{{ i18n.limitsTitle }}</h4>
96
+ <table class="sp-wizard__limits">
97
+ <thead>
98
+ <tr>
99
+ <th></th>
100
+ <th>{{ i18n.limitsUsed }}</th>
101
+ <th>{{ i18n.limitsCurrent }}</th>
102
+ <th>{{ i18n.limitsTarget }}</th>
103
+ </tr>
104
+ </thead>
105
+ <tbody>
106
+ <LimitsRow
107
+ v-for="(row, key) in preview.limitsCheck"
108
+ :key="key"
109
+ :label="quotaLabel(String(key))"
110
+ :row="row"
111
+ :fractional="isFractionalQuotaSafe(String(key))"
112
+ />
113
+ </tbody>
114
+ </table>
115
+
116
+ <div v-if="preview.featuresGained.length > 0" class="sp-wizard__feat">
117
+ <h4>{{ i18n.featuresGained }}</h4>
118
+ <ul>
119
+ <li v-for="f in preview.featuresGained" :key="f">
120
+ {{ featureLabel(f) }}
121
+ </li>
122
+ </ul>
123
+ </div>
124
+
125
+ <div
126
+ v-if="preview.featuresLost.length > 0"
127
+ class="sp-wizard__feat sp-wizard__feat--warn"
128
+ >
129
+ <h4>{{ i18n.featuresLost }}</h4>
130
+ <ul>
131
+ <li v-for="f in preview.featuresLost" :key="f">
132
+ {{ featureLabel(f) }}
133
+ </li>
134
+ </ul>
135
+ </div>
136
+
137
+ <div v-if="preview.blockers.length > 0" class="sp-wizard__blockers">
138
+ <h4>{{ i18n.blockersTitle }}</h4>
139
+ <ul>
140
+ <li v-for="b in preview.blockers" :key="b.code">{{ b.message }}</li>
141
+ </ul>
142
+ </div>
143
+
144
+ <div v-if="preview.warnings.length > 0" class="sp-wizard__warnings">
145
+ <ul>
146
+ <li v-for="w in preview.warnings" :key="w.code">{{ w.message }}</li>
147
+ </ul>
148
+ </div>
149
+ </template>
150
+
151
+ <q-stepper-navigation>
152
+ <q-btn flat :label="i18n.back" @click="step = 1" />
153
+ <q-btn
154
+ color="primary"
155
+ :label="i18n.next"
156
+ unelevated
157
+ class="q-ml-sm"
158
+ :disable="!canAdvanceFromPreview"
159
+ @click="step = 3"
160
+ />
161
+ </q-stepper-navigation>
162
+ </q-step>
163
+
164
+ <!-- Step 3: Confirm -->
165
+ <q-step :name="3" :title="i18n.stepConfirm" icon="check_circle">
166
+ <p>
167
+ <strong>{{ targetPlanName }}</strong>
168
+ ({{ targetCycle === 'YEARLY' ? i18n.cycleYearly : i18n.cycleMonthly }})
169
+ </p>
170
+ <p v-if="preview?.isImmediate" class="sp-wizard__confirm-line">
171
+ {{ i18n.confirmImmediate }}
172
+ </p>
173
+ <p v-else-if="preview?.effectiveAt" class="sp-wizard__confirm-line">
174
+ {{ i18n.confirmScheduled }} {{ formatDate(preview.effectiveAt) }}.
175
+ </p>
176
+
177
+ <!-- #17: Price summary — prorated now + regular from the next period.
178
+ During a trial nothing is charged → only a note + next price. -->
179
+ <div v-if="preview" class="sp-wizard__price-summary">
180
+ <h4>{{ i18n.confirmPriceTitle }}</h4>
181
+ <div v-if="isTrial" class="sp-wizard__price-note">
182
+ {{ i18n.confirmTrialNote }}
183
+ </div>
184
+ <div v-else-if="preview.proration" class="sp-wizard__price-row">
185
+ <span>{{ i18n.confirmProratedNow }}</span>
186
+ <strong>{{ formatCurrency(preview.proration.prorataDeltaNet) }}</strong>
187
+ </div>
188
+ <div class="sp-wizard__price-row">
189
+ <span>{{ recurringFromLabel }}</span>
190
+ <strong>
191
+ {{ formatCurrency(recurringPriceNet) }} {{ recurringCycleLabel }}
192
+ </strong>
193
+ </div>
194
+ </div>
195
+
196
+ <div v-if="submitError" class="sp-wizard__error q-mt-md">
197
+ {{ submitError }}
198
+ </div>
199
+
200
+ <q-stepper-navigation>
201
+ <q-btn flat :label="i18n.back" @click="step = 2" />
202
+ <q-btn
203
+ color="primary"
204
+ :label="submitting ? i18n.confirmInProgress : i18n.confirmAction"
205
+ unelevated
206
+ class="q-ml-sm"
207
+ :loading="submitting"
208
+ :disable="submitting"
209
+ @click="submit"
210
+ />
211
+ </q-stepper-navigation>
212
+ </q-step>
213
+ </q-stepper>
214
+ </q-card>
215
+ </q-dialog>
216
+ </template>
217
+
218
+ <script setup lang="ts">
219
+ import { computed, ref, watch } from 'vue';
220
+ import LimitsRow from './LimitsRow.vue';
221
+ import PlanCycleToggle from '../components/plan/PlanCycleToggle.vue';
222
+ import PlanGrid from '../components/plan/PlanGrid.vue';
223
+ import type { BillingCycleStr, PlanChangePreviewShape } from '../use-tenant-billing.js';
224
+ import type { CatalogPlan } from '../use-tenant-billing-catalog.js';
225
+
226
+ // PlanChangeWizard — 3-step dialog for plan changes.
227
+ //
228
+ // Input: list of bookable plans from the catalog + current plan/cycle.
229
+ // Logic: step 1 local selection, step 2 calls `previewPlanChange` and shows
230
+ // the limits check + proration + feature diff + blockers, step 3 calls `changePlan`.
231
+ // Data-driven via the passed `catalogQuotaKeys[]` — no hard-coded trinity.
232
+
233
+ interface I18nStrings {
234
+ title: string;
235
+ close: string;
236
+ currentLabel: string;
237
+ cycleMonthly: string;
238
+ cycleYearly: string;
239
+ badgeCurrent: string;
240
+ badgePopular: string;
241
+ priceUnitMonthly: string;
242
+ priceOnRequest: string;
243
+ stepChoose: string;
244
+ stepChooseIntro: string;
245
+ stepPreview: string;
246
+ stepConfirm: string;
247
+ next: string;
248
+ back: string;
249
+ previewLoading: string;
250
+ effectiveAtLabel: string;
251
+ effectiveImmediate: string;
252
+ prorationTitle: string;
253
+ prorationLine: string;
254
+ prorationDays: string;
255
+ limitsTitle: string;
256
+ limitsUsed: string;
257
+ limitsCurrent: string;
258
+ limitsTarget: string;
259
+ featuresGained: string;
260
+ featuresLost: string;
261
+ blockersTitle: string;
262
+ confirmImmediate: string;
263
+ confirmScheduled: string;
264
+ confirmAction: string;
265
+ confirmInProgress: string;
266
+ confirmPriceTitle: string;
267
+ confirmProratedNow: string;
268
+ confirmRecurringNext: string;
269
+ confirmRecurringFrom: string;
270
+ perCycleMonthly: string;
271
+ perCycleYearly: string;
272
+ confirmTrialNote: string;
273
+ confirmRecurringTrialEnd: string;
274
+ changeTypeUpgrade: string;
275
+ changeTypeDowngrade: string;
276
+ changeTypeCycle: string;
277
+ changeTypeNoop: string;
278
+ }
279
+
280
+ interface Props {
281
+ modelValue: boolean;
282
+ plans: CatalogPlan[];
283
+ currentPlanId: string;
284
+ currentPlanName: string;
285
+ currentCycle: BillingCycleStr;
286
+ /** Subscription status (e.g. 'TRIAL'/'ACTIVE') — for the trial note in confirm. */
287
+ currentStatus?: string;
288
+ /** Trial-end ISO, if status is TRIAL — for "regular from the end of the trial". */
289
+ trialEndsAt?: string | null;
290
+ /** Catalog quota keys in declared order. */
291
+ catalogQuotaKeys: string[];
292
+ /** Consumer hooks. */
293
+ formatCurrency: (n: number) => string;
294
+ formatDate: (iso: string) => string;
295
+ /**
296
+ * Optional: combined label-+-value ("200 Mitglieder"). No longer used
297
+ * internally since step 1 was switched to `<PlanGrid>` with `quotaLabel` +
298
+ * `formatQuotaValue` (P10.2.1). Kept in the prop list for backward-
299
+ * compatibility reasons — consumers that configured it earlier keep working
300
+ * without any code change.
301
+ */
302
+ formatQuotaLabel?: (key: string, value: number) => string;
303
+ /**
304
+ * Plain value per quota key, e.g. "200" or "10 GB" (for PlanGrid).
305
+ * Optional — default: takes `value.toLocaleString('de-DE')`, appends a
306
+ * `GB` suffix for `storage` keys, replaces -1 with ∞.
307
+ */
308
+ formatQuotaValue?: (key: string, value: number) => string;
309
+ quotaLabel: (key: string) => string;
310
+ featureLabel: (key: string) => string;
311
+ isFractionalQuota?: (key: string) => boolean;
312
+ /** Preview caller (passed through from the consumer composable). */
313
+ previewPlanChange: (plan: string, cycle: BillingCycleStr) => Promise<PlanChangePreviewShape>;
314
+ changePlan: (plan: string, cycle: BillingCycleStr, immediate: boolean) => Promise<void>;
315
+ i18n: I18nStrings;
316
+ }
317
+
318
+ const props = defineProps<Props>();
319
+ const emit = defineEmits<{
320
+ 'update:modelValue': [boolean];
321
+ submitted: [];
322
+ }>();
323
+
324
+ const model = computed({
325
+ get: () => props.modelValue,
326
+ set: (v) => emit('update:modelValue', v),
327
+ });
328
+
329
+ const step = ref(1);
330
+ const targetPlan = ref<string | null>(null);
331
+ const targetCycle = ref<BillingCycleStr>(props.currentCycle);
332
+
333
+ const preview = ref<PlanChangePreviewShape | null>(null);
334
+ const previewLoading = ref(false);
335
+ const previewError = ref<string | null>(null);
336
+
337
+ const submitting = ref(false);
338
+ const submitError = ref<string | null>(null);
339
+
340
+ const currentCycleLabel = computed(() =>
341
+ props.currentCycle === 'YEARLY' ? props.i18n.cycleYearly : props.i18n.cycleMonthly,
342
+ );
343
+
344
+ const targetPlanName = computed(() => {
345
+ if (!targetPlan.value) return '';
346
+ return props.plans.find((p) => p.id === targetPlan.value)?.name ?? targetPlan.value;
347
+ });
348
+
349
+ const canAdvanceFromStep1 = computed(() => {
350
+ if (!targetPlan.value) return false;
351
+ return targetPlan.value !== props.currentPlanId || targetCycle.value !== props.currentCycle;
352
+ });
353
+
354
+ // #17 — price summary in the confirm step: regular price from the next period
355
+ // (in the selected cycle) + possibly the prorated amount due for the current period.
356
+ const recurringPriceNet = computed<number>(() => {
357
+ const t = preview.value?.target.plan;
358
+ if (!t) return 0;
359
+ return (targetCycle.value === 'YEARLY' ? t.yearlyNet : t.monthlyNet) ?? 0;
360
+ });
361
+
362
+ const recurringCycleLabel = computed(() =>
363
+ targetCycle.value === 'YEARLY' ? props.i18n.perCycleYearly : props.i18n.perCycleMonthly,
364
+ );
365
+
366
+ const isTrial = computed(() => props.currentStatus === 'TRIAL');
367
+
368
+ const recurringFromLabel = computed(() => {
369
+ // Trial: nothing due during the trial → regular only from the end of the trial.
370
+ // Prefers the projected NEW trial end (carry-over), otherwise the current one.
371
+ if (isTrial.value) {
372
+ const end =
373
+ preview.value?.projectedTrialEndsAt ??
374
+ props.trialEndsAt ??
375
+ preview.value?.effectiveAt ??
376
+ null;
377
+ return end
378
+ ? `${props.i18n.confirmRecurringTrialEnd} (${props.formatDate(end)})`
379
+ : props.i18n.confirmRecurringTrialEnd;
380
+ }
381
+ // Immediately effective (upgrade without trial): regular from the next period.
382
+ if (preview.value?.proration) return props.i18n.confirmRecurringNext;
383
+ // Scheduled (downgrade/cycle): regular from the effective date.
384
+ if (preview.value?.effectiveAt) {
385
+ return `${props.i18n.confirmRecurringFrom} ${props.formatDate(preview.value.effectiveAt)}`;
386
+ }
387
+ return props.i18n.confirmRecurringNext;
388
+ });
389
+
390
+ const canAdvanceFromPreview = computed(
391
+ () => !!preview.value && preview.value.blockers.length === 0,
392
+ );
393
+
394
+ const changeTypeLabel = computed(() => {
395
+ if (!preview.value) return '';
396
+ switch (preview.value.changeType) {
397
+ case 'UPGRADE':
398
+ return props.i18n.changeTypeUpgrade;
399
+ case 'DOWNGRADE':
400
+ return props.i18n.changeTypeDowngrade;
401
+ case 'CYCLE_CHANGE':
402
+ return props.i18n.changeTypeCycle;
403
+ default:
404
+ return props.i18n.changeTypeNoop;
405
+ }
406
+ });
407
+
408
+ const changeTypeColor = computed(() => {
409
+ if (!preview.value) return 'grey';
410
+ switch (preview.value.changeType) {
411
+ case 'UPGRADE':
412
+ return 'positive';
413
+ case 'DOWNGRADE':
414
+ return 'negative';
415
+ case 'CYCLE_CHANGE':
416
+ return 'info';
417
+ default:
418
+ return 'grey';
419
+ }
420
+ });
421
+
422
+ function isFractionalQuotaSafe(key: string): boolean {
423
+ return props.isFractionalQuota?.(key) ?? key.toLowerCase().includes('storage');
424
+ }
425
+
426
+ function formatQuotaValueResolved(key: string, value: number | null | undefined): string {
427
+ if (props.formatQuotaValue) return props.formatQuotaValue(key, value as number);
428
+ // Plans may omit individual quota keys; the default renderer must
429
+ // cope with `undefined` instead of crashing (.toLocaleString).
430
+ if (value === null || value === undefined || Number.isNaN(value)) return '–';
431
+ if (value < 0) return '∞';
432
+ if (key.toLowerCase().includes('storage')) return `${value} GB`;
433
+ return value.toLocaleString('de-DE');
434
+ }
435
+
436
+ const cycleI18n = computed(() => ({
437
+ ariaLabel: props.i18n.cycleMonthly + ' / ' + props.i18n.cycleYearly,
438
+ monthly: props.i18n.cycleMonthly,
439
+ yearly: props.i18n.cycleYearly,
440
+ }));
441
+
442
+ const planGridI18n = computed(() => ({
443
+ popular: props.i18n.badgePopular,
444
+ current: props.i18n.badgeCurrent,
445
+ perMonth: props.i18n.priceUnitMonthly,
446
+ perYear: props.i18n.priceUnitMonthly,
447
+ priceOnRequest: props.i18n.priceOnRequest,
448
+ }));
449
+
450
+ async function goToPreview() {
451
+ if (!targetPlan.value) return;
452
+ step.value = 2;
453
+ previewLoading.value = true;
454
+ previewError.value = null;
455
+ try {
456
+ preview.value = await props.previewPlanChange(targetPlan.value, targetCycle.value);
457
+ } catch (err) {
458
+ preview.value = null;
459
+ previewError.value = err instanceof Error ? err.message : String(err);
460
+ } finally {
461
+ previewLoading.value = false;
462
+ }
463
+ }
464
+
465
+ async function submit() {
466
+ if (!targetPlan.value || !preview.value) return;
467
+ submitting.value = true;
468
+ submitError.value = null;
469
+ try {
470
+ await props.changePlan(targetPlan.value, targetCycle.value, preview.value.isImmediate);
471
+ emit('submitted');
472
+ close();
473
+ } catch (err) {
474
+ submitError.value = err instanceof Error ? err.message : String(err);
475
+ } finally {
476
+ submitting.value = false;
477
+ }
478
+ }
479
+
480
+ function close() {
481
+ model.value = false;
482
+ // Reset state so the next open starts fresh.
483
+ setTimeout(() => {
484
+ step.value = 1;
485
+ targetPlan.value = null;
486
+ targetCycle.value = props.currentCycle;
487
+ preview.value = null;
488
+ previewError.value = null;
489
+ submitError.value = null;
490
+ }, 200);
491
+ }
492
+
493
+ watch(
494
+ () => props.modelValue,
495
+ (v) => {
496
+ if (v) {
497
+ targetCycle.value = props.currentCycle;
498
+ }
499
+ },
500
+ );
501
+ </script>
502
+
503
+ <style scoped>
504
+ .sp-wizard {
505
+ width: min(900px, 95vw);
506
+ max-height: 90vh;
507
+ }
508
+ /* CSS vars for light + dark mode */
509
+ .sp-wizard {
510
+ --sp-wiz-border: rgba(0, 0, 0, 0.08);
511
+ --sp-wiz-text-strong: rgba(0, 0, 0, 0.87);
512
+ --sp-wiz-text-muted: rgba(0, 0, 0, 0.6);
513
+ --sp-wiz-text-faint: rgba(0, 0, 0, 0.55);
514
+ --sp-wiz-border-soft: rgba(0, 0, 0, 0.1);
515
+ }
516
+ :global(.body--dark) .sp-wizard {
517
+ --sp-wiz-border: rgba(255, 255, 255, 0.12);
518
+ --sp-wiz-text-strong: rgba(255, 255, 255, 0.92);
519
+ --sp-wiz-text-muted: rgba(255, 255, 255, 0.7);
520
+ --sp-wiz-text-faint: rgba(255, 255, 255, 0.6);
521
+ --sp-wiz-border-soft: rgba(255, 255, 255, 0.18);
522
+ }
523
+ .sp-wizard__head {
524
+ display: flex;
525
+ justify-content: space-between;
526
+ align-items: flex-start;
527
+ border-bottom: 1px solid var(--sp-wiz-border);
528
+ }
529
+ .sp-wizard__title {
530
+ font-size: 18px;
531
+ font-weight: 600;
532
+ color: var(--sp-wiz-text-strong);
533
+ }
534
+ .sp-wizard__sub {
535
+ color: var(--sp-wiz-text-muted);
536
+ font-size: 13px;
537
+ }
538
+ .sp-wizard__intro {
539
+ color: var(--sp-wiz-text-muted);
540
+ margin-bottom: 16px;
541
+ }
542
+ .sp-wizard__loading {
543
+ display: flex;
544
+ gap: 12px;
545
+ align-items: center;
546
+ padding: 24px 0;
547
+ }
548
+ .sp-wizard__error {
549
+ color: var(--q-negative, #c10015);
550
+ background: rgba(193, 0, 21, 0.08);
551
+ padding: 12px;
552
+ border-radius: 4px;
553
+ }
554
+ .sp-wizard__type {
555
+ margin-bottom: 12px;
556
+ }
557
+ .sp-wizard__proration {
558
+ background: rgba(25, 118, 210, 0.06);
559
+ padding: 12px 14px;
560
+ border-radius: 4px;
561
+ margin-top: 12px;
562
+ }
563
+ .sp-wizard__proration h4 {
564
+ margin: 0 0 6px;
565
+ font-size: 14px;
566
+ }
567
+ .sp-wizard__proration p {
568
+ margin: 0;
569
+ }
570
+ .sp-wizard__limits {
571
+ width: 100%;
572
+ border-collapse: collapse;
573
+ margin-top: 4px;
574
+ }
575
+ .sp-wizard__limits thead th {
576
+ padding: 6px 12px;
577
+ text-align: left;
578
+ font-size: 12px;
579
+ color: var(--sp-wiz-text-faint);
580
+ text-transform: uppercase;
581
+ border-bottom: 1px solid var(--sp-wiz-border-soft);
582
+ }
583
+ .sp-wizard__feat,
584
+ .sp-wizard__blockers,
585
+ .sp-wizard__warnings {
586
+ margin-top: 16px;
587
+ }
588
+ .sp-wizard__feat h4,
589
+ .sp-wizard__blockers h4 {
590
+ margin: 0 0 6px;
591
+ font-size: 14px;
592
+ }
593
+ .sp-wizard__feat--warn {
594
+ color: rgba(193, 0, 21, 0.8);
595
+ }
596
+ .sp-wizard__blockers {
597
+ color: var(--q-negative, #c10015);
598
+ background: rgba(193, 0, 21, 0.06);
599
+ padding: 12px 14px;
600
+ border-radius: 4px;
601
+ }
602
+ .sp-wizard__warnings {
603
+ color: var(--q-warning, #c87b00);
604
+ font-size: 13px;
605
+ }
606
+ .sp-wizard__confirm-line {
607
+ color: var(--sp-wiz-text-muted);
608
+ }
609
+ .sp-wizard__price-summary {
610
+ margin-top: 16px;
611
+ background: rgba(25, 118, 210, 0.06);
612
+ padding: 12px 14px;
613
+ border-radius: 4px;
614
+ }
615
+ .sp-wizard__price-summary h4 {
616
+ margin: 0 0 8px;
617
+ font-size: 14px;
618
+ }
619
+ .sp-wizard__price-row {
620
+ display: flex;
621
+ justify-content: space-between;
622
+ align-items: baseline;
623
+ gap: 16px;
624
+ padding: 2px 0;
625
+ }
626
+ .sp-wizard__price-note {
627
+ color: var(--sp-wiz-text-muted);
628
+ padding: 2px 0 6px;
629
+ }
630
+ </style>