{#if loading}
{:else}

{i18n.t("billing.title")}

{#if planAssigned && plan} {planName} · {headerPlanBlurb} {:else} {headerPlanBlurb} {/if}

{#if canManageBilling} {i18n.t("billing.comparePlans")} {#if showPortal} {/if} {:else} {upgradeCta.primaryLabel} {/if} {#if isPlatformAdmin} {/if}
{#if canManageBilling && !purchasesEnabled} {/if} {#if recovery} void manageSubscription() : undefined } /> {:else if freePlan} {:else if outOfCredits || atProductLimit} {:else if lowCredits} {/if} {#if credits}
{i18n.t("billing.currentPlan")}
{planName}

{planBillingLabel}

{formatSkuUsage(credits?.product_count, maxProducts ?? plan?.max_products, plan)}

{#if isContractExpiringSoon && !enterprise && !payg}

{i18n.t("billing.periodEnds", { date: formatContractDate(usage?.cycle_end ?? plan?.next_billing_date) })}

{:else if payg}

{i18n.t("billing.openEndedContract")}

{/if}
{payg ? i18n.t("billing.creditWallet") : i18n.t("billing.creditsRemaining")} {#if enterprise}
{remainingLabel}

{i18n.t("billing.enterpriseCapacity")}

{:else if payg}
{i18n.t("billing.payAsYouGo")}

{i18n.t("billing.paygWallet", { remaining: formatCredits(remaining ?? 0) })}

{:else if freePlan}
{remainingLabel}

{canUseAI ? i18n.t("billing.trialLeftover") : i18n.t("billing.aiLockedFree")}

{:else}
{remainingLabel}

{i18n.t("billing.usedOf", { used: formatCredits(walletUsed), total: formatCredits(usage?.credits_total ?? credits.total_credits) })}

{/if}
{:else}

{i18n.t("billing.noBalanceTitle")}

{i18n.t("billing.noBalanceBody")}

{/if} {#if showQuickUpgrade}

{i18n.t("billing.needCapacity")}

{i18n.t("billing.selfServeUpgrade")} {#if stripe?.configured && !stripe?.mock} {i18n.t("billing.viaStripe")} {/if}.

{#if nextUpgradePlan} {/if} {i18n.t("billing.comparePlans")}
{:else if !canManageBilling && (freePlan || outOfCredits || atProductLimit || lowCredits)}

{i18n.t("billing.needCapacity")}

{upgradeCta.memberHint ?? i18n.t("billing.askAdminPlan")}

{/if} {#if canManageBilling && purchasesEnabled && !enterprise && planAssigned}

{i18n.t("billing.buyCreditPacks")}

{i18n.t("billing.buyCreditPacksHint")}

{#each CREDIT_PACKS as pack (pack.id)}

{i18n.t(pack.nameKey)}

{i18n.t(pack.descriptionKey)}

${pack.priceUSD}

{i18n.t("billing.packCredits", { credits: pack.credits.toLocaleString() })} · {i18n.t("billing.packApproxProducts", { count: pack.aiProducts.toLocaleString() })}

{/each}
{/if}

{i18n.t("billing.usage")}

{i18n.t("billing.productsProcessed", { count: (usage?.products_processed ?? 0).toLocaleString(), range: rangeLabel })} {#if usageLoading} · {i18n.t("billing.updating")} {/if}

{i18n.t("billing.productsByDay")} {#if isPlatformAdmin} {i18n.t("billing.chartAmber", { range: rangeLabel })} {:else} {i18n.t("billing.chartRange", { range: rangeLabel })} {/if} {#if !hasCatalogActivity}

{i18n.t("billing.nothingToChartTitle")}

{i18n.t("billing.nothingToChartBody")}

{:else if dateRangeOption === "all"}
{i18n.t("billing.dailyChartsHint")}
{:else if !hasSeries}

{i18n.t("billing.noNewProducts", { range: rangeLabel })}

{i18n.t("billing.catalogOverall", { count: catalogProductCount.toLocaleString() })}

{:else} {/if} {#if isPlatformAdmin}

{i18n.t("billing.adminStats", { tokens: (usage?.tokens ?? 0).toLocaleString(), jobs: (usage?.jobs_total ?? 0).toLocaleString(), input: (usage?.feeds_input ?? 0).toLocaleString(), export: (usage?.feeds_export ?? 0).toLocaleString() })}

{/if}
{i18n.t("billing.whatUsesCredits")}
    {#each CREDIT_USAGE_ITEMS as item (item.labelKey)}
  • {#if item.burns} {i18n.t("billing.burnsCredits")} {:else} {i18n.t("billing.noCreditCost")} {/if} {i18n.t(item.labelKey)}

    {i18n.t(item.detailKey)}

  • {/each}
{/if} {#if isPlatformAdmin}
{#snippet footer()} {/snippet}
{/if}