<div class="container paper-page admin-page">
  <div class="paper-crumbs">Admin &nbsp;/&nbsp; <span class="here">Conferences</span></div>
  <h1 class="paper-page-title">Conferences</h1>

  <nav class="admin-nav">
    <a href="/admin/"><i class="fas fa-tachometer-alt"></i> Overview</a>
    <a href="/admin/repositories"><i class="fas fa-code-branch"></i> Repositories</a>
    <a href="/admin/users"><i class="fas fa-users"></i> Users</a>
    <a href="/admin/conferences" class="active"><i class="fas fa-chalkboard-teacher"></i> Conferences</a>
    <a href="/admin/queues"><i class="fas fa-tasks"></i> Queues</a>
    <a href="/admin/errors"><i class="fas fa-bug"></i> Errors</a>
  </nav>

  <div class="admin-summary">
    <span class="summary-total">{{total >= 0 ? (total | number) : '…'}}</span>
    <span class="summary-pill ok" ng-class="{active: query.ready}" ng-click="query.ready = !query.ready; query.page = 1" title="Toggle ready filter">Ready <span class="count">{{statusCountFor('ready') | number}}</span></span>
    <span class="summary-pill warn" ng-class="{active: query.preparing}" ng-click="query.preparing = !query.preparing; query.page = 1" title="Toggle preparing filter">Preparing <span class="count">{{statusCountFor('preparing') | number}}</span></span>
    <span class="summary-pill error" ng-class="{active: query.error}" ng-click="query.error = !query.error; query.page = 1" title="Toggle errored filter">Errored <span class="count">{{statusCountFor('error') | number}}</span></span>
    <span class="summary-pill" ng-class="{active: query.expired}" ng-click="query.expired = !query.expired; query.page = 1" title="Toggle expired filter">Expired <span class="count">{{statusCountFor('expired') | number}}</span></span>
    <span class="summary-pill" ng-class="{active: query.removed}" ng-click="query.removed = !query.removed; query.page = 1" title="Toggle removed filter">Removed <span class="count">{{statusCountFor('removed') | number}}</span></span>
  </div>

  <div class="alert alert-danger" ng-if="fetchError" style="margin: 8px 0;">
    <i class="fas fa-exclamation-triangle"></i> {{fetchError}}
  </div>

  <form class="w-100 admin-filter-toolbar" aria-label="Conferences" accept-charset="UTF-8">
    <div class="admin-filter-row">
      <div class="search-wrap">
        <input type="search" class="form-control" placeholder="Search conferences…" autocomplete="off" ng-model="query.search" />
        <span class="admin-search-hint" ng-if="!query.search">/</span>
      </div>
      <span class="admin-filter-spacer"></span>
      <button class="btn btn-sm" type="button" ng-click="exportCsv()"><i class="fas fa-file-csv"></i> Export</button>
      <span class="admin-filter-inline" aria-label="Pagination">
        <button class="btn btn-sm" type="button" ng-click="query.page = Math.max(1, query.page - 1)" ng-disabled="query.page <= 1"><i class="fas fa-chevron-left"></i></button>
        <span style="font-family: var(--font-mono); font-size: 12px; color: var(--ink-muted);">{{query.page}}/{{totalPage || 1}}</span>
        <button class="btn btn-sm" type="button" ng-click="query.page = Math.min(totalPage, query.page + 1)" ng-disabled="query.page >= totalPage"><i class="fas fa-chevron-right"></i></button>
      </span>
    </div>

    <div class="admin-filter-row" ng-if="chips.length">
      <div class="admin-active-chips">
        <span class="admin-active-chip" ng-repeat="chip in chips track by chip.key">
          <span class="key">{{chip.label}}</span>
          <span>{{chip.value}}</span>
          <button type="button" ng-click="clearFilter(chip.key)"><i class="fas fa-times"></i></button>
        </span>
      </div>
    </div>
  </form>

  <div class="paper-table paper-table-conferences w-100" role="table" aria-label="Conferences">
    <div class="paper-table-head" role="row">
      <div role="columnheader"><span class="sortable" ng-class="{active: query.sort == 'name'}" ng-click="sortBy('name')">Conference <i class="fas" ng-class="sortIcon('name')"></i></span></div>
      <div role="columnheader"><span class="sortable" ng-class="{active: query.sort == 'status'}" ng-click="sortBy('status')">Status <i class="fas" ng-class="sortIcon('status')"></i></span></div>
      <div role="columnheader" class="num">Repos</div>
      <div role="columnheader"><span class="sortable" ng-class="{active: query.sort == 'startDate'}" ng-click="sortBy('startDate')">Window <i class="fas" ng-class="sortIcon('startDate')"></i></span></div>
      <div role="columnheader" aria-label="Actions"></div>
    </div>
    <div
      class="paper-table-row"
      role="row"
      ng-repeat="conference in conferences as filteredConferences"
    >
      <div class="cell-anon" role="cell">
        <span class="type-badge type-repo">Conf</span>
        <div class="anon-text">
          <a class="repo-name" ng-href="/conference/{{conference.conferenceID}}" ng-bind="conference.name"></a>
          <div class="anon-sub">
            <span>{{conference.conferenceID}}</span>&nbsp;&middot;&nbsp;<span>{{conference.price || 0 | number}} &euro;</span>
          </div>
        </div>
      </div>
      <div class="cell-status" role="cell">
        <span class="status-dot" ng-class="{'status-removed': conference.status == 'removed' || conference.status == 'expired', 'status-ready': conference.status == 'ready', 'status-error': conference.status == 'error', 'status-preparing': conference.status == 'preparing'}"></span>
        <span ng-bind="conference.status | title"></span>
      </div>
      <div class="cell-views num" role="cell">
        <a ng-href="/admin/?conference={{conference.conferenceID}}" ng-bind="::conference.repositories.length || 0 | number" title="Show repositories in this conference"></a>
      </div>
      <div class="cell-expires" role="cell">{{conference.startDate | date}} &ndash; {{conference.endDate | date}}</div>
      <div class="cell-actions" role="cell">
        <div class="dropdown">
          <button class="btn btn-icon-dots" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" aria-label="Actions">
            <i class="fas fa-ellipsis-h" aria-hidden="true"></i>
          </button>
          <div class="dropdown-menu dropdown-menu-right">
            <a class="dropdown-item" href="/conference/{{conference.conferenceID}}/edit"><i class="far fa-edit"></i> Edit</a>
            <a class="dropdown-item" href="/conference/{{conference.conferenceID}}/"><i class="fa fa-eye"></i> View</a>
            <a class="dropdown-item" href="/admin/?conference={{conference.conferenceID}}"><i class="fas fa-code-branch"></i> View repositories</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item text-danger" href="#" ng-show="conference.status != 'removed'" ng-click="removeConference(conference)"><i class="fas fa-trash-alt"></i> Remove</a>
          </div>
        </div>
      </div>
    </div>
    <div class="paper-table-empty" ng-if="filteredConferences.length == 0">
      <i class="fas fa-inbox"></i>
      <span>No conferences match the current filters.</span>
    </div>
  </div>

  <div class="admin-toolbar" style="justify-content: space-between; border-bottom: none;">
    <span style="font-size: 12px; color: var(--ink-muted);">{{total | number}} results</span>
    <div class="pagination-compact" ng-if="totalPage > 1">
      <button class="btn btn-sm" ng-click="query.page = Math.max(1, query.page - 1)" ng-disabled="query.page <= 1"><i class="fas fa-chevron-left"></i> Previous</button>
      <input type="number" class="form-control form-control-sm" ng-model="query.page" min="1" max="{{totalPage}}" style="width: 56px;" />
      <span>of {{totalPage}}</span>
      <button class="btn btn-sm" ng-click="query.page = Math.min(totalPage, query.page + 1)" ng-disabled="query.page >= totalPage">Next <i class="fas fa-chevron-right"></i></button>
    </div>
    <span class="admin-filter-inline">
      <label>Per page</label>
      <select class="form-control form-control-sm" ng-model="query.limit"><option value="10">10</option><option value="25">25</option><option value="50">50</option><option value="100">100</option><option value="250">250</option></select>
    </span>
  </div>
</div>
