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

{% block title %} Dashboard {% endblock %}

<!-- Element injected in the BODY element -->
{% block body_class %} sidebar-mini {% endblock body_class %}

<!-- Specific Page CSS goes HERE  -->
{% block stylesheets %}

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/static/assets/css/adminlte.min.css">

{% endblock stylesheets %}

{% block content %}

  <div class="content-wrapper">

    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Dashboard</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/index">Home</a></li>
              <li class="breadcrumb-item active">Dashboard</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        <div class="row">
          <div class="col-lg-2">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                <h3>{{ installations|length }}</h3>
                <p>GitHub Organizations</p>
              </div>
              <div class="icon">
                <i class="fas fa-sitemap"></i>
              </div>
              <a href="/admin/organizations" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-2">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                <h3>{{ open_pull_request_count }}</h3>
                <p>Open Pull Requests</p>
              </div>
              <div class="icon">
                <i class="fas fa-code-pull-request"></i>
              </div>
              <a href="/admin/pullrequests" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-2">
            <!-- small box -->
            <div class="small-box bg-success">
              <div class="inner">
                <h3>{{ merged_pull_request_count }}</h3>
                <p>Merged Pull Requests</p>
              </div>
              <div class="icon">
                <i class="fas fa-code-merge"></i>
              </div>
              <a href="/admin/pullrequests" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-2">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                <h3>{{ total_repository_count }}</h3>
                <p>Total Repository Count</p>
              </div>
              <div class="icon">
                <i class="fab fa-github"></i>
              </div>
<!--              <a href="/statistics" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>-->
            </div>
          </div>
          <!-- ./col -->
        </div>
        <!-- ./row -->

        <div class="row">
          {% for installation in installations %}
          {% set github_id = installation.github_id %}
          {% set project_name = installation.project_name %}
          {% set installation_status = installation.installation_status %}
          <div class="col-md-3">
            <div class="card">
              {% if installation_status|status == 'success' %}
              <a class="text-reset" href="/projects/{{ project_name }}">
                <div class="card-header bg-{{ installation_status|status }}">
                  <h3 class="card-title">{{ project_name }}</h3>
                  <div class="float-right">
                    <i class="fas fa-arrow-circle-right"></i>
                  </div>
                </div>
              </a>
              {% else %}
              <a class="text-reset" href="#">
                <div class="card-header bg-{{ installation_status|status }}">
                  <h3 class="card-title">{{ project_name }}</h3>
                </div>
              </a>
              {% endif %}
              <div class="card-body">
                <a href="https://github.com/{{ github_id }}"><i class="fab fa-github"></i> &nbsp; {{ github_id }}</a>
              </div>
              <div class="card-footer p-0">
                {% if installation_status|status == 'success' %}
                <ul class="nav flex-column">
                  {% if configurations[github_id] %}
                  {% set config = configurations[github_id].config %}
                  <li class="nav-item">
                    <a href="/projects/{{ project_name }}#settings" class="nav-link">
                      {% set two_factor_enabled = config.settings.two_factor_requirement %}
                      2FA enforced <span class="float-right badge bg-{{ 'success' if two_factor_enabled == true else 'danger' }}">{{ two_factor_enabled }}</span>
                    </a>
                  </li>
                  <li class="nav-item">
                    <a href="/projects/{{ project_name }}#workflow-settings" class="nav-link tab-link">
                      {% set default_workflow_permissions = config.settings.workflows.default_workflow_permissions %}
                      Default workflow permissions <span class="float-right badge bg-{{ 'success' if default_workflow_permissions == 'read' else 'danger' }}">{{ default_workflow_permissions }}</span>
                    </a>
                  </li>
                  <li class="nav-item">
                    <a href="/projects/{{ project_name }}#repositories" class="nav-link">
                      Repositories <span class="float-right badge bg-primary">{{ config.repositories|length }}</span>
                    </a>
                  </li>
                  {% endif %}
                </ul>
                {% endif %}
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          {% endfor %}
          <!-- /.col -->
        </div>
        <!-- /.row -->

      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->

  </div>

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}

  <!-- jQuery -->
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
  <!-- jQuery UI -->
  <script src="https://cdn.jsdelivr.net/npm/jquery-ui@1.12.1/ui/widget.min.js"></script>
  <!-- Bootstrap 4 -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
  <!-- AdminLTE App -->
  <script src="/static/assets/js/adminlte.js"></script>

{% endblock javascripts %}
