<div>
  <div class="active-profile-titles section-header">
    <div class="active-profile-filter">
      <div class="section-filter">
        <input type="text" class="search-query" placeholder="Filter..." ng-model="searchFilter">
        <i class="icon-remove clickable" title="Clear filter" ng-click="searchFilter = ''"></i>
      </div>
    </div>

    <div class="section-controls">
      <!--a href="" title="Create a new container" ng-click="createContainer()">
        <i class="icon-plus"></i> Container
      </a-->
      <a href="" ng-click="editRequirements.dialogOpen(null)"
         title="Configure the minimum number of required instances for each profile. If you are on OpenShift or using an Auto Scaler they are then created automatically; otherwise click on the count button to manually provision required containers">
        <i class="icon-resize-vertical"></i>
        Target
      </a>
    </div>

  </div>
  <div class="active-profile-count-title" title="The actual number of instances of each profile that are currently running">
    Count
  </div>
  <div class="active-profile-list" ng-repeat="profile in activeProfiles" ng-show="profileMatchesFilter(profile)">
    <div class="expandable" model="profile">
      <div class="active-profile-row">
        <div class="title active-profile-expander">
          <i class="expandable-indicator" ng-show="profile.count"></i>
        </div>
        <div class="title active-profile-icon">
          <i class="icon-book"></i>
        </div>
        <div class="title active-profile-name">
          <span class="contained c-max" title="{{profile.id}} / {{profile.versionId}}" ng-click="showProfile(profile)">
            <!--<a href="" ng-click="showProfile(profile)">{{profile.id}}</a> / {{profile.versionId}} -->
            {{profile.id}} / {{profile.versionId}}
          </span>
        </div>
        <div class="active-profile-count"
             title="Current number of instances of this profile. Click to create more containers">
          <span class="badge {{profile.requireStyle}}" >
            {{profile.count}}
          </span>
          <a href="" ng-click="createRequiredContainers(profile)" hawtio-show object-name="{{managerMBean}}" method-name="createContainers" mode="remove">
            <i class="icon-plus clickable" title="Create more containers of this profile" ></i>
          </a>
        </div>

        <div class="active-profile-requirements">
          <span ng-show="profile.requirements.minimumInstances" class="badge"
                title="The minimum number of required instances of this profile. If you use OpenShift or run an Auto Scaler then this many instances will be created automatically.">
            {{profile.requirements.minimumInstances}}
          </span>
          <a ng-click="editRequirements.dialogOpen(profile)" ng-show="profile.requirements.minimumInstances"
             hawtio-show object-name="{{managerMBean}}" method-name="requirementsJson" mode="remove">
            <i class="icon-plus clickable" title="Edit requirements"></i>
          </a>
        </div>

      </div>
      <div class="expandable-body">
        <div ng-repeat="container in containersForProfileAndVersion(profile.id, profile.versionId)"
              ng-show="containerMatchesFilter(container)"
              ng-include="'app/fabric/html/containerItem.html'"> 
        </div>
      </div>
    </div>
  </div>

  <script type="text/ng-template" id="addProfileRequirement">
    <div>
      <div class="modal-header">
        <h4>Add New Profile Requirements
        </h4>
      </div>
      <div class="modal-body">
        <div fabric-profile-selector="editRequirements.selectedProfiles" no-links="true"
             version-id="editRequirements.versionId"
             excluded-profiles="editRequirements.excludeProfiles"></div>
      </div>
      <div class="modal-footer">
        <button class="btn btn-success" ng-disabled="editRequirements.selectedProfiles.length == 0"
                ng-click="editRequirements.addProfileRequirementApply()"
                title="Adds the selected profiles as new requirements">
          <i class="icon-plus"></i> Add
        </button>
        <button class="btn btn-primary" ng-click="editRequirements.addProfileRequirementHide()"
                title="Closes this profile selection panel">Cancel
        </button>
      </div>
    </div>
  </script>


  <script type="text/ng-template" id="addDependentProfile">
    <div>
      <div class="modal-header">
        <h4>Add Dependencies to Profile: <b>{{editRequirements.addDependentProfileDialogProfile}}</b>
        </h4>
      </div>
      <div class="modal-body">
        <div fabric-profile-selector="editRequirements.selectedDependentProfiles" no-links="true"
             version-id="editRequirements.versionId"
             excluded-profiles="editRequirements.excludeDependentProfiles"></div>
      </div>
      <div class="modal-footer">
        <button class="btn btn-success" ng-disabled="editRequirements.selectedDependentProfiles.length == 0"
                ng-click="editRequirements.addDependentProfileDialogApply()"
                title="Add the selected profiles as dependencies of this profile requirement">
          <i class="icon-plus"></i> Add
        </button>
        <button class="btn btn-primary" ng-click="editRequirements.addDependentProfileDialogHide()"
                title="Closes this profile selection panel">Cancel
        </button>
      </div>
    </div>
  </script>


  <script type="text/ng-template" id="addProfileRequirements">
    <div>
      <form name="requirementsForm" class="form-inline no-bottom-margin">
        <div class="modal-header">
          <h4>Edit Requirements
            <button class="btn pull-right requirement-profile-add"
                    ng-click="editRequirements.addProfileRequirementOpen()"
                    title="Add requirements for a new profile which does not currently have any containers running"><i
                    class="icon-plus"></i> Profile
            </button>
          </h4>
        </div>
        <div class="modal-body">
          <table>
            <thead>
            <th>Profile</th>
            <th title="Minimum number of instances which should be running">Minimum</th>
            <th title="Maximum number of instances">Maximum</th>
            <th title="Profiles which must be provisioned first before this profile">Dependent Profiles</th>
            </thead>
            <tbody>
            <tr ng-repeat="requirement in editRequirements.entity.profileRequirements">
              <td class="property-name">
                <i class="red clickable icon-remove" title="Removes this dependent profile"
                   ng-click="editRequirements.entity.profileRequirements.remove(requirement)"></i>
                {{requirement.profile}}
              </td>
              <td>
                <input name="minimumInstances" type="number" ng-model="requirement.minimumInstances" ng-required="false"
                       class="input-small" min="0">
              </td>
              <td>
                <input name="maximumInstances" type="number" ng-model="requirement.maximumInstances" ng-required="false"
                       class="input-small" min="0">
              </td>
              <td>
                <div ng-repeat="dependentProfile in requirement.dependentProfiles">
                  <i class="red clickable icon-remove" title="Removes this dependent profile"
                     ng-click="requirement.dependentProfiles.remove(dependentProfile)"></i>
                  <span class="dependent-profile">{{dependentProfile}}</span>
                </div>
                <i class="clickable icon-edit green"
                   ng-click="editRequirements.addDependentProfileDialogOpen(requirement)"
                   title="Add new dependent profiles to this profile"></i>
              </td>
            </tr>
            </tbody>
          </table>
        </div>
        <div class="modal-footer">
          <input class="btn btn-success" ng-disabled="!requirementsForm.$valid"
                 ng-click="updateRequirements(editRequirements.entity)" type="button" value="Update">
          <input class="btn-warning cancel" ng-click="editRequirements.dialog.close()" type="button" value="Cancel">
        </div>
      </form>
    </div>

  </script>

  <div modal="editRequirements.dialog.show">
    <div compile="currentPage"></div>
  </div>

  <div ng-include="'app/fabric/html/connectToContainerDialog.html'"></div>
</div>
