@fluid-app/portal-sdk 0.1.803 → 0.1.805

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 (37) hide show
  1. package/dist/{FluidProvider-CbezJu7k.cjs → FluidProvider-BMoMyErE.cjs} +43 -1
  2. package/dist/{FluidProvider-CbezJu7k.cjs.map → FluidProvider-BMoMyErE.cjs.map} +1 -1
  3. package/dist/{FluidProvider-BUgLvMU0.mjs → FluidProvider-Dq5eM99i.mjs} +43 -1
  4. package/dist/{FluidProvider-BUgLvMU0.mjs.map → FluidProvider-Dq5eM99i.mjs.map} +1 -1
  5. package/dist/{MessagingScreen-CaR23V-j.mjs → MessagingScreen-BNfYvLRt.mjs} +2 -2
  6. package/dist/{MessagingScreen-CaR23V-j.mjs.map → MessagingScreen-BNfYvLRt.mjs.map} +1 -1
  7. package/dist/{MessagingScreen-D2xdPEC1.cjs → MessagingScreen-B_WZonYP.cjs} +2 -2
  8. package/dist/{MessagingScreen-D2xdPEC1.cjs.map → MessagingScreen-B_WZonYP.cjs.map} +1 -1
  9. package/dist/{MessagingScreen-BY_DfqH_.mjs → MessagingScreen-C8M7VgKE.mjs} +2 -2
  10. package/dist/{MessagingScreen-cBMjM-MN.cjs → MessagingScreen-DaqZenAk.cjs} +2 -2
  11. package/dist/{OrdersScreen-DZSH0C_x.mjs → OrdersScreen-BKSwZdTS.mjs} +2 -2
  12. package/dist/{OrdersScreen-Luerich7.cjs → OrdersScreen-BM6064zb.cjs} +2 -2
  13. package/dist/{OrdersScreen-DQyPk86D.cjs → OrdersScreen-Dh6cKvoD.cjs} +2 -2
  14. package/dist/{OrdersScreen-DQyPk86D.cjs.map → OrdersScreen-Dh6cKvoD.cjs.map} +1 -1
  15. package/dist/{OrdersScreen-d4iYw6dH.mjs → OrdersScreen-K1aCPtYb.mjs} +2 -2
  16. package/dist/{OrdersScreen-d4iYw6dH.mjs.map → OrdersScreen-K1aCPtYb.mjs.map} +1 -1
  17. package/dist/{ProfileScreen-C1OTbsAH.cjs → ProfileScreen-CkCm1BTd.cjs} +3 -3
  18. package/dist/{ProfileScreen-UiYKJI4W.cjs → ProfileScreen-Cp6uetRK.cjs} +2 -2
  19. package/dist/{ProfileScreen-UiYKJI4W.cjs.map → ProfileScreen-Cp6uetRK.cjs.map} +1 -1
  20. package/dist/{ProfileScreen-BoAweM-N.mjs → ProfileScreen-DNlnG12U.mjs} +2 -2
  21. package/dist/{ProfileScreen-BoAweM-N.mjs.map → ProfileScreen-DNlnG12U.mjs.map} +1 -1
  22. package/dist/{ProfileScreen-fDEfMhHF.mjs → ProfileScreen-PW4MqHpr.mjs} +3 -3
  23. package/dist/{SubscriptionsScreen-Bq9rz8_l.cjs → SubscriptionsScreen-0YpZDxbJ.cjs} +459 -101
  24. package/dist/SubscriptionsScreen-0YpZDxbJ.cjs.map +1 -0
  25. package/dist/{SubscriptionsScreen-BVNRW8Mc.cjs → SubscriptionsScreen-BvfbO0Ph.cjs} +3 -3
  26. package/dist/{SubscriptionsScreen-DTNR_sKF.mjs → SubscriptionsScreen-ChH6JtYD.mjs} +3 -3
  27. package/dist/{SubscriptionsScreen-DrW_5UWh.mjs → SubscriptionsScreen-Dzfs1Tj4.mjs} +460 -102
  28. package/dist/SubscriptionsScreen-Dzfs1Tj4.mjs.map +1 -0
  29. package/dist/index.cjs +14 -14
  30. package/dist/index.mjs +14 -14
  31. package/dist/{use-portal-card-add-3ds-flow-7sMchA1Y.mjs → use-portal-card-add-3ds-flow-BfVoevu3.mjs} +2 -2
  32. package/dist/{use-portal-card-add-3ds-flow-7sMchA1Y.mjs.map → use-portal-card-add-3ds-flow-BfVoevu3.mjs.map} +1 -1
  33. package/dist/{use-portal-card-add-3ds-flow-CKQr5F5Q.cjs → use-portal-card-add-3ds-flow-oy_eyeQA.cjs} +2 -2
  34. package/dist/{use-portal-card-add-3ds-flow-CKQr5F5Q.cjs.map → use-portal-card-add-3ds-flow-oy_eyeQA.cjs.map} +1 -1
  35. package/package.json +2 -2
  36. package/dist/SubscriptionsScreen-Bq9rz8_l.cjs.map +0 -1
  37. package/dist/SubscriptionsScreen-DrW_5UWh.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
1
  require("./chunk-9hOWP6kD.cjs");
2
2
  require("./build-widget-registry-CR5qbb2G.cjs");
3
3
  require("./ContactsTranslationBridge-FyqcnCwN.cjs");
4
- require("./FluidProvider-CbezJu7k.cjs");
4
+ require("./FluidProvider-BMoMyErE.cjs");
5
5
  require("./ScreenRenderer-CLT0DgZh.cjs");
6
6
  require("./account-api-context-BAC-rNdx.cjs");
7
7
  require("./use-optional-store-DiiiefyO.cjs");
@@ -69,7 +69,7 @@ require("./translation-adapter-DFTj_Ydf.cjs");
69
69
  require("./translation-adapter-BhsWM9YE.cjs");
70
70
  require("./sidebar-BnZL8dM6.cjs");
71
71
  require("./ScreenHeaderContext-fJKG4BUl.cjs");
72
- require("./use-portal-card-add-3ds-flow-CKQr5F5Q.cjs");
73
- const require_SubscriptionsScreen = require("./SubscriptionsScreen-Bq9rz8_l.cjs");
72
+ require("./use-portal-card-add-3ds-flow-oy_eyeQA.cjs");
73
+ const require_SubscriptionsScreen = require("./SubscriptionsScreen-0YpZDxbJ.cjs");
74
74
  exports.SubscriptionsScreen = require_SubscriptionsScreen.SubscriptionsScreen;
75
75
  exports.subscriptionsScreenPropertySchema = require_SubscriptionsScreen.subscriptionsScreenPropertySchema;
@@ -1,7 +1,7 @@
1
1
  import "./src-8ihOpuAU.mjs";
2
2
  import "./build-widget-registry-mTHeMMXC.mjs";
3
3
  import "./ContactsTranslationBridge-D3J4a-56.mjs";
4
- import "./FluidProvider-BUgLvMU0.mjs";
4
+ import "./FluidProvider-Dq5eM99i.mjs";
5
5
  import "./ScreenRenderer-DJnHvFb-.mjs";
6
6
  import "./account-api-context-DCEDXtbM.mjs";
7
7
  import "./use-optional-store-D6XsdB-j.mjs";
@@ -68,6 +68,6 @@ import "./translation-adapter-D4UNUw8I.mjs";
68
68
  import "./translation-adapter-BGwgAecf.mjs";
69
69
  import "./sidebar-BqTwYEfE.mjs";
70
70
  import "./ScreenHeaderContext-D7jhJX8j.mjs";
71
- import "./use-portal-card-add-3ds-flow-7sMchA1Y.mjs";
72
- import { n as subscriptionsScreenPropertySchema, t as SubscriptionsScreen } from "./SubscriptionsScreen-DrW_5UWh.mjs";
71
+ import "./use-portal-card-add-3ds-flow-BfVoevu3.mjs";
72
+ import { n as subscriptionsScreenPropertySchema, t as SubscriptionsScreen } from "./SubscriptionsScreen-Dzfs1Tj4.mjs";
73
73
  export { SubscriptionsScreen, subscriptionsScreenPropertySchema };
@@ -1,8 +1,8 @@
1
- import { Bt as BreadcrumbList, C as SheetTitle, D as SelectItem, E as SelectContent, G as DropdownMenuContent, H as Label, Ht as BreadcrumbSeparator, It as Calendar$1, K as DropdownMenuItem, Lt as Breadcrumb, N as Input, O as SelectTrigger, Rt as BreadcrumbItem, T as Select, U as DropdownMenu, Ut as Badge, Vt as BreadcrumbPage, _ as Skeleton, an as PortalContainerProvider, at as DialogFooter, d as Switch, dt as Popover, et as DropdownMenuTrigger, ft as PopoverContent, it as DialogDescription, k as SelectValue, lt as DialogTitle, m as fluidToast, ot as DialogHeader, pt as PopoverTrigger, qt as Button, rt as DialogContent, sn as cn$1, tt as Dialog, v as Sheet, y as SheetContent, zt as BreadcrumbLink } from "./src-8ihOpuAU.mjs";
1
+ import { Bt as BreadcrumbList, C as SheetTitle, D as SelectItem, E as SelectContent, G as DropdownMenuContent, H as Label, Ht as BreadcrumbSeparator, It as Calendar$1, K as DropdownMenuItem, Lt as Breadcrumb, N as Input, O as SelectTrigger, Rt as BreadcrumbItem, T as Select, U as DropdownMenu, Ut as Badge, Vt as BreadcrumbPage, _ as Skeleton, an as PortalContainerProvider, at as DialogFooter, d as Switch, dt as Popover, et as DropdownMenuTrigger, ft as PopoverContent, it as DialogDescription, k as SelectValue, lt as DialogTitle, m as fluidToast, o as Textarea, ot as DialogHeader, pt as PopoverTrigger, qt as Button, rt as DialogContent, sn as cn$1, tt as Dialog, v as Sheet, y as SheetContent, zt as BreadcrumbLink } from "./src-8ihOpuAU.mjs";
2
2
  import { B as getPaymentBrandName, Et as usePayApi, F as paymentDescriptorLabel, L as resolvePaymentMethodDisplay, P as normalizePaymentDescriptor, V as normalizeCardBrand, j as isCardPaymentDescriptor } from "./build-widget-registry-mTHeMMXC.mjs";
3
3
  import { i as toApiErrorBody, r as isApiError } from "./fetch-client-BRi4Z3Zz.mjs";
4
4
  import { i as useFluidContext } from "./ContactsTranslationBridge-D3J4a-56.mjs";
5
- import { c as createSubscriptionsTranslationAdapter, l as subscriptionsDomain } from "./FluidProvider-BUgLvMU0.mjs";
5
+ import { c as createSubscriptionsTranslationAdapter, l as subscriptionsDomain } from "./FluidProvider-Dq5eM99i.mjs";
6
6
  import { i as useOptionalStore } from "./use-optional-store-D6XsdB-j.mjs";
7
7
  import { r as useCountriesApi } from "./Combobox-vfx4KKN_.mjs";
8
8
  import { T as usePortalTenantClient, at as subscriptionsList, ct as subscriptionsResume, dt as subscriptionsSkip, et as subscriptionBundlesCreate, ft as subscriptionsUpdate, it as subscriptionsFailedCycleWaiverPreview, lt as subscriptionsRetry, nt as subscriptionsCancel, ot as subscriptionsPause, rt as subscriptionsFailedCycleWaiverCreate, st as subscriptionsReactivate, tt as subscriptionBundlesList, ut as subscriptionsShow } from "./prop-types-BKixw4TR.mjs";
@@ -16,7 +16,7 @@ import { n as useAppNavigation } from "./AppNavigationContext-BnYj4Pjp.mjs";
16
16
  import { t as useStore } from "./use-store-jLETls7H.mjs";
17
17
  import { p as useSidebar, r as SidebarContext } from "./sidebar-BqTwYEfE.mjs";
18
18
  import { n as ScreenHeaderBreadcrumbs } from "./ScreenHeaderContext-D7jhJX8j.mjs";
19
- import { _ as ProfileTranslationBridge, a as getBrowserInfo, c as EditPaymentMethodDialog, d as getCardDisplayName, f as getCardExpiry, g as EllipsesDropdown, h as ConfirmActionDialog, i as isThreeDsRequiredCreate, l as FluidPayCoreProvider, n as createFluidPayApiAdapter, o as CreditCardFormDialog, p as getPaymentMethodLogoBrand, r as mapToFluidPayPaymentMethod, s as AddressFormDialog, t as usePortalCardAdd3DSFlow, u as PaymentIcon, v as useProfileTranslation } from "./use-portal-card-add-3ds-flow-7sMchA1Y.mjs";
19
+ import { _ as ProfileTranslationBridge, a as getBrowserInfo, c as EditPaymentMethodDialog, d as getCardDisplayName, f as getCardExpiry, g as EllipsesDropdown, h as ConfirmActionDialog, i as isThreeDsRequiredCreate, l as FluidPayCoreProvider, n as createFluidPayApiAdapter, o as CreditCardFormDialog, p as getPaymentMethodLogoBrand, r as mapToFluidPayPaymentMethod, s as AddressFormDialog, t as usePortalCardAdd3DSFlow, u as PaymentIcon, v as useProfileTranslation } from "./use-portal-card-add-3ds-flow-BfVoevu3.mjs";
20
20
  import { C as millisecondsInMinute, S as millisecondsInHour, _ as getDefaultOptions$1, a as warnOrThrowProtectedError, b as toDate, c as getWeekYear, g as startOfWeek, h as startOfISOWeek, i as isProtectedWeekYearToken, l as getISOWeek, m as getTimezoneOffsetInMilliseconds, n as format, o as longFormatters, r as isProtectedDayOfYearToken, s as getWeek, t as isAfter, u as enUS, v as addMonths, w as millisecondsInSecond, x as constructFrom, y as addDays } from "./isAfter-D9nJj9TD.mjs";
21
21
  import { createContext, use, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
22
22
  import { useInfiniteQuery, useIsFetching, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
@@ -5581,104 +5581,6 @@ function SubscriptionsListScreen(props) {
5581
5581
  });
5582
5582
  }
5583
5583
  //#endregion
5584
- //#region ../../subscriptions/ui/src/components/cancel-subscription-dialog.tsx
5585
- const PAUSE_MONTH_OPTIONS = [
5586
- 1,
5587
- 2,
5588
- 3
5589
- ];
5590
- function CancelSubscriptionDialog({ open, onOpenChange, onConfirm, onPauseInstead, errorMessage, isPending: isPendingProp = false, presentation = "dialog" }) {
5591
- const { t } = useSubscriptionsTranslation();
5592
- const [isConfirming, setIsConfirming] = useState(false);
5593
- const isPending = isConfirming || isPendingProp;
5594
- const [selectedMonths, setSelectedMonths] = useState(null);
5595
- useEffect(() => {
5596
- if (!open) setSelectedMonths(null);
5597
- }, [open]);
5598
- const handleConfirm = async () => {
5599
- const result = onConfirm();
5600
- if (!(result instanceof Promise)) {
5601
- onOpenChange(false);
5602
- return;
5603
- }
5604
- setIsConfirming(true);
5605
- try {
5606
- await result;
5607
- onOpenChange(false);
5608
- } catch (error) {
5609
- console.error("CancelSubscriptionDialog: action rejected", error);
5610
- } finally {
5611
- setIsConfirming(false);
5612
- }
5613
- };
5614
- const handlePause = () => {
5615
- if (!selectedMonths) return;
5616
- onPauseInstead(selectedMonths);
5617
- };
5618
- return /* @__PURE__ */ jsxs(ResponsiveDialog, {
5619
- open,
5620
- onOpenChange: (v) => !isPending && onOpenChange(v),
5621
- title: t("cancel_dialog_title"),
5622
- description: t("cancel_dialog_description"),
5623
- role: "alertdialog",
5624
- presentation,
5625
- children: [
5626
- /* @__PURE__ */ jsxs("div", {
5627
- className: "border-border space-y-2 rounded-md border p-3",
5628
- children: [
5629
- /* @__PURE__ */ jsx("p", {
5630
- className: "text-foreground text-sm font-medium",
5631
- children: t("cancel_dialog_pause_question")
5632
- }),
5633
- /* @__PURE__ */ jsx(Label, {
5634
- htmlFor: "cancel-pause-months",
5635
- className: "text-foreground text-sm font-semibold",
5636
- children: t("pause_for")
5637
- }),
5638
- /* @__PURE__ */ jsxs(Select, {
5639
- value: selectedMonths ? String(selectedMonths) : void 0,
5640
- onValueChange: (value) => setSelectedMonths(value ? Number(value) : null),
5641
- disabled: isPending,
5642
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
5643
- id: "cancel-pause-months",
5644
- className: "w-full",
5645
- children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("select_duration") })
5646
- }), /* @__PURE__ */ jsx(SelectContent, { children: PAUSE_MONTH_OPTIONS.map((months) => /* @__PURE__ */ jsx(SelectItem, {
5647
- value: String(months),
5648
- children: months === 1 ? t("month_singular", { count: String(months) }) : t("month_plural", { count: String(months) })
5649
- }, months)) })]
5650
- }),
5651
- /* @__PURE__ */ jsx(Button, {
5652
- variant: "outline",
5653
- onClick: handlePause,
5654
- disabled: isPending || !selectedMonths,
5655
- className: "w-full",
5656
- children: t("cancel_dialog_pause_button")
5657
- })
5658
- ]
5659
- }),
5660
- errorMessage && /* @__PURE__ */ jsx("p", {
5661
- className: "text-destructive text-left text-sm",
5662
- children: errorMessage
5663
- }),
5664
- /* @__PURE__ */ jsxs(DialogFooter, {
5665
- className: "flex-col gap-2 sm:flex-row sm:justify-end",
5666
- children: [/* @__PURE__ */ jsx(Button, {
5667
- variant: "secondary",
5668
- onClick: () => onOpenChange(false),
5669
- disabled: isPending,
5670
- children: t("cancel_dialog_cancel_button")
5671
- }), /* @__PURE__ */ jsx(Button, {
5672
- variant: "destructive",
5673
- onClick: handleConfirm,
5674
- disabled: isPending,
5675
- children: isPending ? t("loading_ellipsis") : t("cancel_dialog_confirm_button")
5676
- })]
5677
- })
5678
- ]
5679
- });
5680
- }
5681
- //#endregion
5682
5584
  //#region ../../subscriptions/ui/src/lib/format.ts
5683
5585
  /** Used when a payload carries no currency, or one Intl does not know. */
5684
5586
  const FALLBACK_CURRENCY = "USD";
@@ -5929,6 +5831,462 @@ function formatMediumDate(date, locale = "en-US") {
5929
5831
  }).format(date);
5930
5832
  }
5931
5833
  }
5834
+ /** "1 month" or "N months" in the subscriptions dictionary. */
5835
+ function monthsLabel(t, months) {
5836
+ return months === 1 ? t("month_singular", { count: "1" }) : t("month_plural", { count: String(months) });
5837
+ }
5838
+ //#endregion
5839
+ //#region ../../subscriptions/core/src/cancellation-sessions-api.ts
5840
+ var CancellationSessionError = class extends Error {
5841
+ failure;
5842
+ constructor(failure, message) {
5843
+ super(message);
5844
+ this.name = "CancellationSessionError";
5845
+ this.failure = failure;
5846
+ }
5847
+ };
5848
+ //#endregion
5849
+ //#region ../../subscriptions/ui/src/components/cancel-flow.tsx
5850
+ function useCancelFlow(open, binding) {
5851
+ const { t } = useSubscriptionsTranslation();
5852
+ const [step, setStep] = useState({ kind: "plain" });
5853
+ const [error, setError] = useState(null);
5854
+ const [busy, setBusy] = useState(false);
5855
+ const generation = useRef(0);
5856
+ const bindingRef = useRef(binding);
5857
+ bindingRef.current = binding;
5858
+ const openSession = async (current, run) => {
5859
+ try {
5860
+ const session = await current.api.openSession(current.subscriptionToken);
5861
+ if (run === generation.current) setStep({
5862
+ kind: "reason",
5863
+ session
5864
+ });
5865
+ } catch {
5866
+ if (run === generation.current) setStep({ kind: "plain" });
5867
+ }
5868
+ };
5869
+ const enabled = binding !== void 0;
5870
+ const subscriptionToken = binding?.subscriptionToken;
5871
+ const api = binding?.api;
5872
+ useEffect(() => {
5873
+ generation.current += 1;
5874
+ setError(null);
5875
+ setBusy(false);
5876
+ const current = bindingRef.current;
5877
+ if (!open || !current) {
5878
+ setStep({ kind: "plain" });
5879
+ return;
5880
+ }
5881
+ setStep({ kind: "opening" });
5882
+ openSession(current, generation.current);
5883
+ }, [
5884
+ open,
5885
+ enabled,
5886
+ subscriptionToken,
5887
+ api
5888
+ ]);
5889
+ const recover = async (cause) => {
5890
+ const current = bindingRef.current;
5891
+ if (!current) return;
5892
+ if (!(cause instanceof CancellationSessionError)) {
5893
+ setError(t("cancel_flow_error"));
5894
+ return;
5895
+ }
5896
+ if (cause.failure === "unavailable") {
5897
+ setStep({ kind: "plain" });
5898
+ setError(t("cancel_flow_error"));
5899
+ return;
5900
+ }
5901
+ current.onChanged({ kind: "stale" });
5902
+ if (cause.failure === "refused") {
5903
+ setError(t("cancel_flow_refused"));
5904
+ return;
5905
+ }
5906
+ setError(t("cancel_flow_session_restarted"));
5907
+ await openSession(current, generation.current);
5908
+ };
5909
+ const sessionOf = (value) => value.kind === "reason" || value.kind === "offers" ? value.session : null;
5910
+ const withSession = async (fallback, work) => {
5911
+ const current = bindingRef.current;
5912
+ const session = sessionOf(step);
5913
+ if (!current || !session) return fallback;
5914
+ setBusy(true);
5915
+ setError(null);
5916
+ try {
5917
+ return await work(current, session);
5918
+ } catch (cause) {
5919
+ await recover(cause);
5920
+ return fallback;
5921
+ } finally {
5922
+ setBusy(false);
5923
+ }
5924
+ };
5925
+ return {
5926
+ step,
5927
+ error,
5928
+ busy,
5929
+ giveReason: (choice) => withSession(void 0, async (current, session) => {
5930
+ setStep({
5931
+ kind: "offers",
5932
+ session: await current.api.giveReason(current.subscriptionToken, session.id, choice)
5933
+ });
5934
+ }),
5935
+ accept: (offer, variantId) => withSession(false, async (current, session) => {
5936
+ await current.api.acceptOffer(current.subscriptionToken, session.id, {
5937
+ offerId: offer.offerId,
5938
+ variantId
5939
+ });
5940
+ current.onChanged({
5941
+ kind: "saved",
5942
+ notice: t("cancel_flow_saved")
5943
+ });
5944
+ return true;
5945
+ }),
5946
+ cancel: (choice) => withSession("failed", async (current, session) => {
5947
+ const reason = step.kind === "reason" ? choice : void 0;
5948
+ try {
5949
+ await current.api.cancel(current.subscriptionToken, session.id, reason);
5950
+ } catch (cause) {
5951
+ if (reason && cause instanceof CancellationSessionError && cause.failure === "refused") return "plain";
5952
+ throw cause;
5953
+ }
5954
+ current.onChanged({ kind: "cancelled" });
5955
+ return "cancelled";
5956
+ })
5957
+ };
5958
+ }
5959
+ function parseLocalDate(isoDate) {
5960
+ const [year, month, day] = isoDate.slice(0, 10).split("-").map(Number);
5961
+ return new Date(year ?? 0, (month ?? 1) - 1, day ?? 1);
5962
+ }
5963
+ function OfferCard({ offer, disabled, onAccept }) {
5964
+ const { t, locale } = useSubscriptionsTranslation();
5965
+ const [variantId, setVariantId] = useState(null);
5966
+ const terms = offer.terms;
5967
+ const months = Number(terms.months);
5968
+ const title = {
5969
+ skip_next: () => t("cancel_offer_skip_next"),
5970
+ delay: () => t("cancel_offer_delay", { days: String(terms.days) }),
5971
+ change_frequency: () => t("cancel_offer_change_frequency"),
5972
+ swap: () => t("cancel_offer_swap"),
5973
+ pause: () => t("cancel_offer_pause", { duration: monthsLabel(t, months) }),
5974
+ discount: () => terms.duration === "repeating" ? t("cancel_offer_discount_repeating", {
5975
+ percentage: String(terms.percentage),
5976
+ cycles: String(terms.duration_cycles)
5977
+ }) : t("cancel_offer_discount_once", { percentage: String(terms.percentage) }),
5978
+ contact_support: () => t("cancel_offer_contact_support")
5979
+ }[offer.type]();
5980
+ const preview = offer.preview;
5981
+ const date = preview?.nextBillDate ? formatLongDate(parseLocalDate(preview.nextBillDate), locale) : null;
5982
+ const previewText = date && preview?.nextOrderTotal ? t("cancel_offer_preview_total", {
5983
+ date,
5984
+ total: formatCurrency(Number(preview.nextOrderTotal), preview.currency, locale)
5985
+ }) : date ? t("cancel_offer_preview_date", { date }) : null;
5986
+ const supportUrl = typeof terms.url === "string" ? terms.url : null;
5987
+ const needsVariant = offer.type === "swap";
5988
+ return /* @__PURE__ */ jsxs("li", {
5989
+ className: "border-border space-y-2 rounded-md border p-3",
5990
+ children: [
5991
+ /* @__PURE__ */ jsx("p", {
5992
+ className: "text-foreground text-sm font-medium",
5993
+ children: title
5994
+ }),
5995
+ previewText && /* @__PURE__ */ jsx("p", {
5996
+ className: "text-muted-foreground text-sm",
5997
+ children: previewText
5998
+ }),
5999
+ needsVariant && /* @__PURE__ */ jsxs("div", {
6000
+ className: "space-y-1",
6001
+ children: [/* @__PURE__ */ jsx(Label, {
6002
+ htmlFor: `swap-${offer.offerId}`,
6003
+ className: "text-sm",
6004
+ children: t("cancel_offer_swap_label")
6005
+ }), /* @__PURE__ */ jsxs(Select, {
6006
+ value: variantId ? String(variantId) : "",
6007
+ onValueChange: (value) => setVariantId(Number(value)),
6008
+ disabled,
6009
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
6010
+ id: `swap-${offer.offerId}`,
6011
+ className: "w-full",
6012
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("cancel_offer_swap_label") })
6013
+ }), /* @__PURE__ */ jsx(SelectContent, { children: offer.variantOptions.map((option) => /* @__PURE__ */ jsx(SelectItem, {
6014
+ value: String(option.variantId),
6015
+ children: option.title ?? String(option.variantId)
6016
+ }, option.variantId)) })]
6017
+ })]
6018
+ }),
6019
+ offer.saves ? /* @__PURE__ */ jsx(Button, {
6020
+ variant: "outline",
6021
+ className: "w-full",
6022
+ disabled: disabled || needsVariant && variantId === null,
6023
+ onClick: () => onAccept(variantId ?? void 0),
6024
+ children: t("cancel_offer_accept_button")
6025
+ }) : supportUrl && /* @__PURE__ */ jsx(Button, {
6026
+ variant: "outline",
6027
+ className: "w-full",
6028
+ asChild: true,
6029
+ children: /* @__PURE__ */ jsx("a", {
6030
+ href: supportUrl,
6031
+ target: "_blank",
6032
+ rel: "noopener noreferrer",
6033
+ children: t("cancel_offer_contact_button")
6034
+ })
6035
+ })
6036
+ ]
6037
+ });
6038
+ }
6039
+ /** The offer screen. At most one per session; it may hold no offers. */
6040
+ function CancelOffers({ session, disabled, onAccept }) {
6041
+ const { t } = useSubscriptionsTranslation();
6042
+ if (session.offers.length === 0) return /* @__PURE__ */ jsx("p", {
6043
+ className: "text-foreground text-sm",
6044
+ children: t("cancel_flow_no_offers_description")
6045
+ });
6046
+ return /* @__PURE__ */ jsxs("div", {
6047
+ className: "space-y-2",
6048
+ children: [/* @__PURE__ */ jsx("p", {
6049
+ className: "text-foreground text-sm",
6050
+ children: t("cancel_flow_offers_description")
6051
+ }), /* @__PURE__ */ jsx("ul", {
6052
+ className: "space-y-2",
6053
+ children: session.offers.map((offer) => /* @__PURE__ */ jsx(OfferCard, {
6054
+ offer,
6055
+ disabled,
6056
+ onAccept: (variantId) => onAccept(offer, variantId)
6057
+ }, offer.offerId))
6058
+ })]
6059
+ });
6060
+ }
6061
+ //#endregion
6062
+ //#region ../../subscriptions/ui/src/components/cancel-reason-picker.tsx
6063
+ const REASON_TEXT_LIMIT = 500;
6064
+ const DICTIONARY_LABELS = {
6065
+ too_expensive: "cancel_reason_too_expensive",
6066
+ too_much_product: "cancel_reason_too_much_product",
6067
+ too_frequent: "cancel_reason_too_frequent",
6068
+ not_seeing_results: "cancel_reason_not_seeing_results",
6069
+ did_not_like_product: "cancel_reason_did_not_like_product",
6070
+ switching_brand: "cancel_reason_switching_brand",
6071
+ shipping_or_delivery_issue: "cancel_reason_shipping_or_delivery_issue",
6072
+ taking_a_break: "cancel_reason_taking_a_break",
6073
+ moving_or_life_change: "cancel_reason_moving_or_life_change",
6074
+ other: "cancel_reason_other"
6075
+ };
6076
+ const emptyCancelReason = {
6077
+ code: null,
6078
+ text: ""
6079
+ };
6080
+ /** The draft as the server takes it, or undefined when no reason is chosen. */
6081
+ function cancelReasonChoice(draft) {
6082
+ if (!draft.code) return void 0;
6083
+ const text = draft.code === "other" ? draft.text.trim() : "";
6084
+ return text ? {
6085
+ reasonCode: draft.code,
6086
+ reasonText: text
6087
+ } : { reasonCode: draft.code };
6088
+ }
6089
+ function CancelReasonPicker({ reasons, value, onChange, disabled }) {
6090
+ const { t, locale } = useSubscriptionsTranslation();
6091
+ const labelFor = (reason) => {
6092
+ const merchantLabel = reason.labels[locale] ?? reason.labels[locale.split(/[-_]/)[0] ?? ""];
6093
+ if (merchantLabel) return merchantLabel;
6094
+ const key = DICTIONARY_LABELS[reason.code];
6095
+ return key ? t(key) : reason.code;
6096
+ };
6097
+ return /* @__PURE__ */ jsxs("div", {
6098
+ className: "space-y-2",
6099
+ children: [
6100
+ /* @__PURE__ */ jsx(Label, {
6101
+ htmlFor: "cancel-reason",
6102
+ className: "text-foreground text-sm font-semibold",
6103
+ children: t("cancel_dialog_reason_label")
6104
+ }),
6105
+ /* @__PURE__ */ jsxs(Select, {
6106
+ value: value.code ?? "",
6107
+ onValueChange: (code) => onChange({
6108
+ ...value,
6109
+ code
6110
+ }),
6111
+ disabled,
6112
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
6113
+ id: "cancel-reason",
6114
+ className: "w-full",
6115
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("cancel_dialog_reason_placeholder") })
6116
+ }), /* @__PURE__ */ jsx(SelectContent, { children: reasons.map((reason) => /* @__PURE__ */ jsx(SelectItem, {
6117
+ value: reason.code,
6118
+ children: labelFor(reason)
6119
+ }, reason.code)) })]
6120
+ }),
6121
+ value.code === "other" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Label, {
6122
+ htmlFor: "cancel-reason-text",
6123
+ className: "text-sm",
6124
+ children: t("cancel_dialog_reason_text_label")
6125
+ }), /* @__PURE__ */ jsx(Textarea, {
6126
+ id: "cancel-reason-text",
6127
+ value: value.text,
6128
+ maxLength: REASON_TEXT_LIMIT,
6129
+ onChange: (event) => onChange({
6130
+ ...value,
6131
+ text: event.target.value
6132
+ }),
6133
+ disabled
6134
+ })] })
6135
+ ]
6136
+ });
6137
+ }
6138
+ //#endregion
6139
+ //#region ../../subscriptions/ui/src/components/cancel-subscription-dialog.tsx
6140
+ const PAUSE_MONTH_OPTIONS = [
6141
+ 1,
6142
+ 2,
6143
+ 3
6144
+ ];
6145
+ function CancelSubscriptionDialog({ open, onOpenChange, onConfirm, onPauseInstead, errorMessage, isPending: isPendingProp = false, presentation = "dialog", reasons = [], cancelFlow }) {
6146
+ const { t } = useSubscriptionsTranslation();
6147
+ const flow = useCancelFlow(open, cancelFlow);
6148
+ const [isConfirming, setIsConfirming] = useState(false);
6149
+ const isPending = isConfirming || isPendingProp || flow.busy;
6150
+ const [selectedMonths, setSelectedMonths] = useState(null);
6151
+ const [reason, setReason] = useState(emptyCancelReason);
6152
+ useEffect(() => {
6153
+ if (open) return;
6154
+ setSelectedMonths(null);
6155
+ setReason(emptyCancelReason);
6156
+ }, [open]);
6157
+ const { step } = flow;
6158
+ const inSession = step.kind === "reason" || step.kind === "offers";
6159
+ const confirmPlain = async () => {
6160
+ const result = onConfirm(cancelReasonChoice(reason));
6161
+ if (!(result instanceof Promise)) {
6162
+ onOpenChange(false);
6163
+ return;
6164
+ }
6165
+ setIsConfirming(true);
6166
+ try {
6167
+ await result;
6168
+ onOpenChange(false);
6169
+ } catch (error) {
6170
+ console.error("CancelSubscriptionDialog: action rejected", error);
6171
+ } finally {
6172
+ setIsConfirming(false);
6173
+ }
6174
+ };
6175
+ const handleCancel = async () => {
6176
+ if (!inSession) return confirmPlain();
6177
+ const outcome = await flow.cancel(cancelReasonChoice(reason));
6178
+ if (outcome === "plain") return confirmPlain();
6179
+ if (outcome === "cancelled") onOpenChange(false);
6180
+ };
6181
+ const handleContinue = () => {
6182
+ const choice = cancelReasonChoice(reason);
6183
+ if (choice) flow.giveReason(choice);
6184
+ };
6185
+ const handlePause = () => {
6186
+ if (!selectedMonths) return;
6187
+ onPauseInstead(selectedMonths);
6188
+ };
6189
+ const shownError = flow.error ?? errorMessage;
6190
+ return /* @__PURE__ */ jsxs(ResponsiveDialog, {
6191
+ open,
6192
+ onOpenChange: (v) => !isPending && onOpenChange(v),
6193
+ title: t("cancel_dialog_title"),
6194
+ description: step.kind === "reason" ? t("cancel_flow_reason_description") : t("cancel_dialog_description"),
6195
+ role: "alertdialog",
6196
+ presentation,
6197
+ children: [
6198
+ /* @__PURE__ */ jsxs("div", {
6199
+ "data-cancel-step": step.kind,
6200
+ className: "space-y-4",
6201
+ children: [
6202
+ step.kind === "plain" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
6203
+ className: "border-border space-y-2 rounded-md border p-3",
6204
+ children: [
6205
+ /* @__PURE__ */ jsx("p", {
6206
+ className: "text-foreground text-sm font-medium",
6207
+ children: t("cancel_dialog_pause_question")
6208
+ }),
6209
+ /* @__PURE__ */ jsx(Label, {
6210
+ htmlFor: "cancel-pause-months",
6211
+ className: "text-foreground text-sm font-semibold",
6212
+ children: t("pause_for")
6213
+ }),
6214
+ /* @__PURE__ */ jsxs(Select, {
6215
+ value: selectedMonths ? String(selectedMonths) : void 0,
6216
+ onValueChange: (value) => setSelectedMonths(value ? Number(value) : null),
6217
+ disabled: isPending,
6218
+ children: [/* @__PURE__ */ jsx(SelectTrigger, {
6219
+ id: "cancel-pause-months",
6220
+ className: "w-full",
6221
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("select_duration") })
6222
+ }), /* @__PURE__ */ jsx(SelectContent, { children: PAUSE_MONTH_OPTIONS.map((months) => /* @__PURE__ */ jsx(SelectItem, {
6223
+ value: String(months),
6224
+ children: monthsLabel(t, months)
6225
+ }, months)) })]
6226
+ }),
6227
+ /* @__PURE__ */ jsx(Button, {
6228
+ variant: "outline",
6229
+ onClick: handlePause,
6230
+ disabled: isPending || !selectedMonths,
6231
+ className: "w-full",
6232
+ children: t("cancel_dialog_pause_button")
6233
+ })
6234
+ ]
6235
+ }), reasons.length > 0 && /* @__PURE__ */ jsx(CancelReasonPicker, {
6236
+ reasons,
6237
+ value: reason,
6238
+ onChange: setReason,
6239
+ disabled: isPending
6240
+ })] }),
6241
+ step.kind === "opening" && /* @__PURE__ */ jsx("p", {
6242
+ className: "text-muted-foreground text-sm",
6243
+ children: t("loading_ellipsis")
6244
+ }),
6245
+ step.kind === "reason" && /* @__PURE__ */ jsx(CancelReasonPicker, {
6246
+ reasons: step.session.reasons,
6247
+ value: reason,
6248
+ onChange: setReason,
6249
+ disabled: isPending
6250
+ }),
6251
+ step.kind === "offers" && /* @__PURE__ */ jsx(CancelOffers, {
6252
+ session: step.session,
6253
+ disabled: isPending,
6254
+ onAccept: async (offer, variantId) => {
6255
+ if (await flow.accept(offer, variantId)) onOpenChange(false);
6256
+ }
6257
+ })
6258
+ ]
6259
+ }),
6260
+ shownError && /* @__PURE__ */ jsx("p", {
6261
+ className: "text-destructive text-left text-sm",
6262
+ children: shownError
6263
+ }),
6264
+ /* @__PURE__ */ jsxs(DialogFooter, {
6265
+ className: "flex-col gap-2 sm:flex-row sm:justify-end",
6266
+ children: [
6267
+ /* @__PURE__ */ jsx(Button, {
6268
+ variant: "secondary",
6269
+ onClick: () => onOpenChange(false),
6270
+ disabled: isPending,
6271
+ children: cancelFlow ? t("cancel_flow_keep_button") : t("cancel_dialog_cancel_button")
6272
+ }),
6273
+ step.kind === "reason" && /* @__PURE__ */ jsx(Button, {
6274
+ variant: "outline",
6275
+ onClick: handleContinue,
6276
+ disabled: isPending || !reason.code,
6277
+ children: t("cancel_flow_continue_button")
6278
+ }),
6279
+ /* @__PURE__ */ jsx(Button, {
6280
+ variant: "destructive",
6281
+ onClick: () => void handleCancel(),
6282
+ disabled: isPending,
6283
+ children: isPending ? t("loading_ellipsis") : t("cancel_dialog_confirm_button")
6284
+ })
6285
+ ]
6286
+ })
6287
+ ]
6288
+ });
6289
+ }
5932
6290
  //#endregion
5933
6291
  //#region ../../subscriptions/ui/src/components/pause-subscription-dialog.tsx
5934
6292
  function PauseSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, errorMessage, currentNextBillDate, billingInterval = 1, billingIntervalUnit = "month", presentation = "dialog" }) {
@@ -9574,4 +9932,4 @@ const subscriptionsScreenPropertySchema = {
9574
9932
  //#endregion
9575
9933
  export { subscriptionsScreenPropertySchema as n, SubscriptionsScreen as t };
9576
9934
 
9577
- //# sourceMappingURL=SubscriptionsScreen-DrW_5UWh.mjs.map
9935
+ //# sourceMappingURL=SubscriptionsScreen-Dzfs1Tj4.mjs.map