{% extends "profile.html" %}

{% block title %}
<title>{{user.canonical_name}}'s projects</title>
{% endblock %}

{% block sidebar %}
{% if current_user and user.id == current_user.id %}
<a
  class="btn btn-primary btn-block"
  href="{{url_for("projects.create_GET")}}"
>Create a new project {{icon("caret-right")}}</a>
{% endif %}
{% endblock %}

{% block content %}
{% if projects or search %}
<form action="{{url_for("users.projects_GET", owner=user.canonical_name)}}">
  <input
    name="search"
    type="text"
    placeholder="Search {{user.canonical_name}}'s projects"
    class="form-control {% if search_error %}is-invalid{% endif %}"
    value="{{search or ""}}" />
  {% if search_error %}
    <div class="invalid-feedback">{{ search_error }}</div>
  {% endif %}
</form>
{% endif %}

<div class="event-list">
  {% if search and not projects %}
  <div class="alert alert-warning">
    No projects found for "{{search}}".
  </div>
  {% elif not projects %}
  <div class="alert alert-info">
    This user does not have any projects.
  </div>
  {% endif %}

  {% for project in projects %}
  <div class="event">
    <h4>
      {% if project.visibility.value != 'PUBLIC' %}
      <small class="text-muted pull-right">{{project.visibility.value.lower()}}</small>
      {% endif %}
      <a href="{{url_for("projects.summary_GET",
        owner=project.owner.canonical_name,
        project_name=project.name)}}">{{project.name}}</a>
    </h4>
    <p>{{project.description}}</p>
    {% if project.tags %}
    <div class="tags">
    {% for tag in project.tags %}
      <a href="{{url_for("public.project_index", search="#"+tag)}}"
         class="tag" rel="nofollow">#{{tag}}</a>
    {% endfor %}
    </div>
    {% endif %}
  </div>
  {% endfor %}
</div>
{{pagination()}}
{% endblock %}

