Line data Source code
1 : import { computed } from 'vue'
2 : import type { Ref } from 'vue'
3 :
4 : import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
5 : import { getPlanCreditGrant } from '@/platform/billing/subscription/utils/planCreditGrant'
6 : import { deriveCreditsCard } from '@comfyorg/account-core/billing'
7 : import type { PlanRowState } from '@comfyorg/account-core/billing'
8 :
9 5 : export function useBillingCreditsCard(planRow: Ref<PlanRowState>) {
10 5 : const {
11 : balance,
12 : billingStatus,
13 : subscription,
14 : currentTeamCreditStop,
15 : nextCreditRefillAt,
16 : periodCreditGrant
17 : } = useBillingContext()
18 :
19 5 : const planPoolCredits = computed(
20 : () =>
21 : getPlanCreditGrant({
22 : tier: subscription.value?.tier,
23 : duration: subscription.value?.duration,
24 : teamMonthlyCredits: currentTeamCreditStop.value?.credits_monthly
25 : })?.credits ?? null
26 : )
27 :
28 : const state = computed(() =>
29 : deriveCreditsCard({
30 : balance: balance.value,
31 : planKind: planRow.value.kind,
32 : billingStatus: billingStatus.value,
33 : periodCreditGrant: periodCreditGrant.value,
34 : planPoolCredits: planPoolCredits.value,
35 : nextCreditRefillAt: nextCreditRefillAt.value,
36 : endDate: planRow.value.kind === 'ending' ? planRow.value.endsAt : null
37 : })
38 : )
39 :
40 5 : return { state }
41 : }
|