| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | module AdminHelper |
| 4 | # Colored pill for a subscription plan. |
| 5 | def admin_plan_badge(plan) |
| 6 | plan = plan.to_s |
| 7 | classes = |
| 8 | case plan |
| 9 | when "team" then "bg-purple-500/15 text-purple-300" |
| 10 | when "pro" then "bg-brand-500/15 text-brand-300" |
| 11 | else "bg-surface-600 text-gray-300" |
| 12 | end |
| 13 | content_tag(:span, plan.presence&.capitalize || "Free", |
| 14 | class: "inline-flex items-center rounded px-2 py-0.5 text-xs font-medium #{classes}") |
| 15 | end |
| 16 | |
| 17 | # Colored pill for a subscription status. |
| 18 | def admin_status_badge(status) |
| 19 | status = status.to_s |
| 20 | classes = |
| 21 | case status |
| 22 | when "active" then "bg-green-500/15 text-green-300" |
| 23 | when "trialing" then "bg-blue-500/15 text-blue-300" |
| 24 | when "past_due", "incomplete" then "bg-amber-500/15 text-amber-300" |
| 25 | when "canceled" then "bg-red-500/15 text-red-300" |
| 26 | else "bg-surface-600 text-gray-300" |
| 27 | end |
| 28 | content_tag(:span, status.tr("_", " ").presence&.capitalize || "—", |
| 29 | class: "inline-flex items-center rounded px-2 py-0.5 text-xs font-medium #{classes}") |
| 30 | end |
| 31 | |
| 32 | # Compact USD, e.g. 1234 -> "$1,234". |
| 33 | def admin_usd(amount) |
| 34 | "$#{number_with_delimiter(amount.to_i)}" |
| 35 | end |
| 36 | end |