{% extends "portfolios/base.html" %}

{% from "components/pagination.html" import Pagination %}
{% from "components/text_input.html" import TextInput %}
{% from 'components/save_button.html' import SaveButton %}

{% block portfolio_content %}

  <div v-cloak class="portfolio-admin portfolio-content">

    <div class="panel">
      <div class="panel__content">

        {% if user_can(permissions.EDIT_PORTFOLIO_NAME) %}
          <base-form inline-template>
            <form method="POST" action="{{ url_for('portfolios.edit', portfolio_id=portfolio.id) }}" autocomplete="false">
              {{ portfolio_form.csrf_token }}
              <div class='form-row'>
                <div class='form-col form-col--half'>
                  {{ TextInput(portfolio_form.name, validation="portfolioName", optional=False) }}
                </div>
                <div class='edit-portfolio-name action-group'>
                  {{ SaveButton(text='Save', additional_classes='usa-button-big') }}
                </div>
              </div>
            </form>
          </base-form>
        {% else %}
          <div>
            <div class='admin-title'>
              {{ "portfolios.admin.portfolio_name" | translate }}
            </div>
          </div>

          <div>
            <div class='admin-content'>
              {{ portfolio.name }}
            </div>
          </div>
        {% endif %}

        <div class='defense-row'>
          <div>
            <div class='admin-title'>{{ "forms.task_order.defense_component_label" | translate }}</div>
            {% if portfolio.defense_component %}
              <div class='admin-content'>{{ portfolio.defense_component }}</div>
            {% else %}
              <div class='admin-content'>{{ "fragments.portfolio_admin.none" | translate }}</div>
            {% endif %}
          </div>
        </div>
      </div>
    </div>

    {% if user_can(permissions.VIEW_PORTFOLIO_POC) %}
      {% include "portfolios/fragments/primary_point_of_contact.html" %}
    {% endif %}

    {% if user_can(permissions.ARCHIVE_PORTFOLIO) %}
      {% include "portfolios/fragments/delete_portfolio.html" %}
    {% endif %}

    {% if user_can(permissions.VIEW_PORTFOLIO_USERS) %}
      {% include "portfolios/fragments/portfolio_members.html" %}
    {% endif %}
    
    {% if user_can(permissions.VIEW_PORTFOLIO_ACTIVITY_LOG) and config.get("USE_AUDIT_LOG", False) %}
      {% include "fragments/audit_events_log.html" %}
      {{ Pagination(audit_events, url_for('portfolios.admin', portfolio_id=portfolio.id)) }}
    {% endif %}
  </div>
{% endblock %}
