{% extends 'layouts/app.html' %}

{% block title %}Account settings{% endblock %}

{% block body %}
  <div class="container">
    <div class="row">
      <div class="col-md-5">
        <h2>Settings</h2>
        <h5 class="text-muted">{{ current_user.email }}</h5>
        <div class="list-group">
          <a href="{{ url_for('user.update_credentials') }}"
             class="list-group-item list-group-item-action">
            Update email and password
          </a>
          <a href="{{ url_for('user.update_locale') }}"
             class="list-group-item list-group-item-action">
            Update language
          </a>
          {% if current_user.username %}
            <span class="list-group-item text-muted">
              Your username is
              <strong>{{ current_user.username }}</strong>
            </span>
          {% else %}
            <a href="{{ url_for('user.welcome') }}"
               class="list-group-item list-group-item-action">
              Pick a username
            </a>
          {% endif %}
        </div>
        <h2 class="mt-5">Betting</h2>
        <h5 class="text-warning">
          You have <strong>{{ current_user.coins }}</strong> coins
        </h5>
        <div class="list-group">
          <a href="{{ url_for('bet.history') }}"
             class="list-group-item list-group-item-action">
            Betting history
          </a>
        </div>
        <a href="{{ url_for('billing.purchase_coins') }}"
           class="btn btn-primary mt-3">Buy more coins</a>
      </div>
      <div class="col-md-5 offset-md-2">
        {% if current_user.subscription %}
          <h2>
            {{ current_user.subscription.plan | title }}
            subscription
          </h2>
          <h5 class="text-muted">
            {{ current_user.credit_card.brand }}
            {{ current_user.credit_card.last4 }}
            ({{ current_user.credit_card.exp_date.strftime('%m/%Y') }})
          </h5>

          <div class="list-group">
            <a class="list-group-item list-group-item-action"
               href="{{ url_for('billing.update_payment_method') }}">
              Update payment info
            </a>
            <a class="list-group-item list-group-item-action"
               href="{{ url_for('billing.billing_details') }}">
              Billing details
            </a>
            <a class="list-group-item list-group-item-action"
               href="{{ url_for('billing.update') }}">
              Change plan
            </a>
            <a class="list-group-item list-group-item-action"
               href="{{ url_for('billing.cancel') }}">
              <span class="text-muted">Cancel subscription</span>
            </a>
          </div>
        {% else %}
          <h2>Subscribe today</h2>
          <h5 class="text-muted">Hey buddy, why aren't you subscribed?</h5>
          <p>
            Now that you've created an account, wouldn't it be unbelievably
            amazing to unlock everything by becoming a subscriber today?
          </p>
          <a href="{{ url_for('billing.pricing') }}" class="btn btn-primary">
            Learn more
          </a>
          {% if current_user.invoices %}
            <h2 class="mt-5 mb-4">Previous subscription info</h2>
            <div class="list-group">
              <a class="list-group-item list-group-item-action"
                 href="{{ url_for('billing.billing_details') }}">
                Billing details
              </a>
            </div>
          {% endif %}
        {% endif %}
      </div>
    </div>
  </div>
{% endblock %}
