<div ng-if="service.ServicePreferences" id="service-placement-preferences">
  <rd-widget>
    <rd-widget-header icon="list" title-text="Placement preferences">
      <div class="nopadding" authorization="DockerServiceUpdate">
        <a class="btn btn-secondary btn-sm pull-right" ng-click="isUpdating || addPlacementPreference(service)" ng-disabled="isUpdating">
          <pr-icon icon="'plus'"></pr-icon> placement preference
        </a>
      </div>
    </rd-widget-header>
    <rd-widget-body ng-if="service.ServicePreferences.length === 0">
      <p>There are no placement preferences for this service.</p>
    </rd-widget-body>
    <rd-widget-body ng-if="service.ServicePreferences.length > 0" classes="no-padding">
      <table class="table">
        <thead>
          <tr>
            <th>Strategy</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="preference in service.ServicePreferences">
            <td>
              <div class="input-group input-group-sm">
                <input
                  type="text"
                  data-cy="placement-preference-strategy-input-{{ $index }}"
                  class="form-control"
                  ng-model="preference.strategy"
                  placeholder="e.g. node.role"
                  ng-change="updatePlacementPreference(service, preference)"
                  ng-disabled="isUpdating"
                  disable-authorization="DockerServiceUpdate"
                />
              </div>
            </td>
            <td>
              <div class="input-group input-group-sm">
                <input
                  type="text"
                  data-cy="placement-preference-value-input-{{ $index }}"
                  class="form-control"
                  ng-model="preference.value"
                  placeholder="e.g. manager"
                  ng-change="updatePlacementPreference(service, preference)"
                  ng-disabled="isUpdating"
                  disable-authorization="DockerServiceUpdate"
                />
                <span class="input-group-btn" authorization="DockerServiceUpdate">
                  <button class="btn btn-dangerlight" type="button" ng-click="removePlacementPreference(service, $index)" ng-disabled="isUpdating">
                    <pr-icon icon="'trash-2'" size="'md'"></pr-icon>
                  </button>
                </span>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </rd-widget-body>
    <rd-widget-footer authorization="DockerServiceUpdate">
      <div class="btn-toolbar" role="toolbar">
        <div class="btn-group" role="group">
          <button type="button" class="btn btn-primary btn-sm" ng-disabled="!hasChanges(service, ['ServicePreferences'])" ng-click="updateService(service)">Apply changes</button>
          <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <pr-icon icon="'chevron-down'"></pr-icon>
          </button>
          <ul class="dropdown-menu">
            <li><a ng-click="cancelChanges(service, ['ServicePreferences'])">Reset changes</a></li>
            <li><a ng-click="cancelChanges(service)">Reset all changes</a></li>
          </ul>
        </div>
      </div>
    </rd-widget-footer>
  </rd-widget>
</div>
