File size: 1,077 Bytes
88211d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
defmodule PlausibleWeb.AuthView do
  use Plausible
  use PlausibleWeb, :view
  alias Plausible.Billing.Plans

  def subscription_quota(subscription, options \\ [])

  def subscription_quota(nil, _options), do: "Free trial"

  def subscription_quota(subscription, options) do
    pageview_limit = Plausible.Teams.Billing.monthly_pageview_limit(subscription)

    quota =
      if pageview_limit == :unlimited do
        "unlimited"
      else
        PlausibleWeb.StatsView.large_number_format(pageview_limit)
      end

    if Keyword.get(options, :format) == :long do
      "#{quota} pageviews"
    else
      quota
    end
  end

  def subscription_interval(subscription) do
    Plans.subscription_interval(subscription)
  end

  def delimit_integer(number) do
    Integer.to_charlist(number)
    |> :lists.reverse()
    |> delimit_integer([])
    |> String.Chars.to_string()
  end

  defp delimit_integer([a, b, c, d | tail], acc) do
    delimit_integer([d | tail], [",", c, b, a | acc])
  end

  defp delimit_integer(list, acc) do
    :lists.reverse(list) ++ acc
  end
end