Skip to content

The agent that grows with you

2.6 KB
Raw Blame
import { Button } from '@/components/ui/button'
import { useI18n } from '@/i18n'
import { ExternalLink } from '@/lib/icons'
import { cn } from '@/lib/utils'

import { LIST_ROW_COLUMNS } from '../primitives'

import { BillingRefusalInline } from './inline-feedback'
import { openExternal } from './open-external'
import { TierArt } from './tier-art'
import type { BillingPlanCardView } from './use-billing-state'
import { useResumeFlow } from './use-subscription-change'

export function CurrentPlanCard({ onViewPlans, plan }: { onViewPlans: () => void; plan: BillingPlanCardView }) {
  const { t } = useI18n()
  const b = t.settings.billing
  const resumeFlow = useResumeFlow()

  return (
    <div className="@container">
      <div className={cn('grid gap-3 py-3 @2xl:items-center', LIST_ROW_COLUMNS)}>
        <div className="flex min-w-0 items-center gap-3">
          <TierArt name={plan.tierName} />
          <div className="min-w-0">
            <div className="flex min-w-0 flex-wrap items-baseline gap-x-2">
              <span className="truncate text-[length:var(--conversation-text-font-size)] font-medium text-foreground">
                {plan.tierName}
              </span>
              {plan.price && (
                <span className="text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)">
                  {b.perMonth(plan.price)}
                </span>
              )}
            </div>
            <div className="mt-1 text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)">
              {plan.caption}
            </div>
          </div>
        </div>
        <div className="flex min-w-0 flex-wrap items-center justify-start gap-2 @2xl:justify-end">
          {plan.action && (
            <Button onClick={plan.action.onSelect ?? onViewPlans} size="sm" type="button" variant="outline">
              {plan.action.label}
            </Button>
          )}
          {/* Scheduled downgrade → chargeless undo (subscription.resume), no confirm. */}
          {plan.pending && (
            <Button disabled={resumeFlow.busy} onClick={() => void resumeFlow.resume()} size="sm" type="button">
              {resumeFlow.busy ? b.plan.undoing : b.plan.undo}
            </Button>
          )}
          {plan.link && (
            <Button onClick={() => plan.link && openExternal(plan.link.url)} size="sm" type="button" variant="outline">
              {plan.link.label}
              <ExternalLink className="size-3.5" />
            </Button>
          )}
        </div>
      </div>
      <BillingRefusalInline refusal={resumeFlow.refusal} />
    </div>
  )
}