% layout 'admin';
% title 'Organisations';
% content_for javascript => begin
% end
% if ( my $error = flash 'error' ) {
  <div class="alert alert-danger" role="alert">
    <strong>Error!</strong> <%= $error %>
  </div>
% } elsif ( my $success = flash 'success' ) {
  <div class="alert alert-success" role="alert">
    <strong>Success!</strong> <%= $success %>
  </div>
% }
<div class="row mb-3">
  <div class="col">
    <div class="card">
      <h3 class="card-header">
        Organisations
        <a href="<%= url_for . '/add' %>" class="btn btn-success" style="float: right" target="_blank">Add Organisation</a>
      </h3>
      <div class="list-group list-group-flush">
        % for my $org_result ($orgs_rs->all) {
        <a href="<%= url_for . '/' . $org_result->id %>" class="list-group-item list-group-item-action d-flex justify-content-between" target="_blank">
          <div>
            %= $org_result->name
          </div>
          <div>
            % if ( $org_result->pending ) {
            <span class="badge badge-warning">Unvalidated</span>
            % }
            % if ( defined $org_result->user ) {
            <span class="badge badge-info">User</span>
            % }
            % if ( !defined $org_result->is_local ) {
            <span class="badge badge-danger">Locality Not Set</span>
            % } elsif ( $org_result->is_local ) {
            <span class="badge badge-success">Local Org</span>
            % } else {
            <span class="badge badge-secondary">Non Local Org</span>
            % }
            % if ( !defined $org_result->is_fair ) {
            <span class="badge badge-danger">Fair Trading Status Not Set</span>
            % } elsif ( $org_result->is_fair ) {
            <span class="badge badge-success">Fairly Trading Org</span>
            % } else {
            <span class="badge badge-secondary">Non Fairly Trading Org</span>
            % }
          </div>
        </a>
        % }
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col">
      %= bootstrap_pagination( $c->param('page') || 1, $orgs_rs->pager->last_page, { class => 'justify-content-center' } );
  </div>
</div>
