{% set user = user_dict if not user else user %}
{% set orgs_available = h.organizations_available(permission='manage_group',
  include_dataset_count=True,
  include_member_count=True,
  user=user['id'])
%}
{% set groups_available = h.groups_available(am_member=True,
  include_dataset_count=True,
  include_member_count=True,
  user=user['id'])
%}


<div id="user-info" class="module context-info">
    <section class="module-content">
      {% block secondary_content_inner %}
        {% block user_image %}
        <div class="image">{{ h.user_image(user.id, size=270) }}</div>
        {% endblock %}
        {% block user_heading %}
        <h1 class="heading">{{ user.display_name }}</h1>
        {% endblock %}
        {% block user_about %}
        {% if about_formatted %}
          {{ about_formatted }}
        {% else %}
          <p class="empty">
            {% if is_myself %}
              {% trans %}You have not provided a biography.{% endtrans %}
            {% else %}
              {% trans %}This user has no biography.{% endtrans %}
            {% endif %}
          </p>
        {% endif %}
        {% endblock %}
        {% block user_nums %}
        {% set num_followers = h.follow_count('user', user.id) %}
        <div class="nums">
          <dl>
            <dt>{{ _('Followers') }}</dt>
            <dd>{{ h.SI_number_span(num_followers) }}</dd>
          </dl>
          <dl>
            <dt>{{ h.humanize_entity_type('package', dataset_type, 'facet label') or _('Datasets') }}</dt>
            <dd>{{ h.SI_number_span(user.number_created_packages) }}</dd>
          </dl>
          <dl>
            <dt>{{ h.humanize_entity_type('organization', org_type, 'facet label') or _('Organizations') }}</dt>
            <dd>{{ orgs_available | count }}</dd>
          </dl>
          <dl>
            <dt>{{ h.humanize_entity_type('group', group_type, 'facet label') or _('Groups') }}</dt>
            <dd>{{ groups_available | count }}</dd>
          </dl>
        </div>
        {% endblock %}
        {% if is_myself == false %}
          {% block user_follow %}
          {% if current_user.is_authenticated %}
          {% if error_message %}
             <div class="alert alert-danger">{{ error_message }}</div>
          {% endif %}
          {% snippet 'snippets/follow_button.html', am_following=am_following, obj_type='user', obj_id=user.id %}
         {% endif %}
          {% endblock %}
        {% endif %}
        {% block user_info %}
        <div class="info">
          <dl>
            {% if user.name.startswith('http://') or user.name.startswith('https://') %}
              <dt>{{ _('Open ID') }}</dt>
              <dd>{{ user.name|urlize(25) }}{# Be great if this just showed the domain #}</dd>
            {% else %}
              <dt>{{ _('Username') }}</dt>
              <dd>{{ user.name }}</dd>
            {% endif %}
          </dl>
          {% if is_myself %}
            <dl>
              <dt>{{ _('Email') }} <span class="label label-default" title="{{ _('This means only you can see this') }}">{{ _('Private') }}</span></dt>
              <dd>{{ user.email }}</dd>
            </dl>
          {% endif %}
          <dl>
            <dt>{{ _('Member Since') }}</dt>
            <dd>{{ h.render_datetime(user.created) }}</dd>
          </dl>
          {% if is_sysadmin %}
          <dl>
            <dt>{{_('Last Active') }}</dt>
            <dd>{{ h.time_ago_from_timestamp(user.last_active) }}</dd>
          </dl>
          {% endif %}
          <dl>
            <dt>{{ _('State') }}</dt>
            <dd>{{ _(user.state) }}</dd>
          </dl>
        </div>
        {% endblock %}
      {% endblock %}
    </section>
  </div>
