<div class="bottom-10">
  <div ng-show="sambo.isActive()" class="alert alert-info" translate>
    В Автономной охране добавляйте и настраивайте доступы к разделам пользователей только через MyAlarm.
  </div>
</div>

<table class="table">
  <tr ng-show="parts.empty()">
    <td translate>Нет разделов</td>
  </tr>
  <tr ng-show="!parts.empty()">
    <th class="col-md-1" translate translate-comment="(заголовок столбца 'номер раздела')">Номер</th>
    <th class="col-md-4" translate>Шлейфы</th>
    <th class="col-md-6" translate>Взятие и снятие</th>
    <th class="col-md-1"></th>
  </tr>
  <tr ng-repeat="(part_index, part) in parts.all()" ng-if="part.enabled">
    <td>{[ part_index + 1 ]}</td>

    <!-- Шлейфы -->
    <td ng-if="isNordSB()">
      <span ng-repeat="device_id in getRieltaWiredDevicesIDS(part.zones)">
        <span ng-repeat="zone_index in getRieltaWiredDeviceEnableZoneNumbersInPart(device_id, part_index)">
          <p>
            <button type="button" class="close" style="float:none"
                    ng-click="parts.removeZone(part_index, zone_index)"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
            </button>
            {[ verboseNameForZone(zone_index) ]}
          </p>
        </span>
      </span>
      <p ng-repeat="zone_index in part.zones"
         ng-if="isWiredZone(zone_index)"
         ng-show="zones.all()[zone_index].enabled">
        <button type="button" class="close" style="float:none"
                ng-click="parts.removeZone(part_index, zone_index)"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
        </button>
        {[ verboseNameForZone(zone_index) ]}
      </p>
      <div class="btn-group" ng-show="(parts.getUnclaimedZones(part_index) | onlyEnabledZone).length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <translate>Добавить шлейф</translate> <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="device_id in getRieltaWiredDevicesIDS(parts.getUnclaimedZones(part_index))">
            <a ng-repeat="zone_index in getRieltaWiredDeviceEnableZoneNumbersForPart(device_id, part_index)"
               href="#"
               ng-click="addZone(part_index, zone_index, $event)">
               {[ verboseNameForZone(zone_index) ]}
            </a>
          </li>
          <li ng-repeat="zone_index in parts.getUnclaimedZones(part_index) | onlyEnabledZone"
              ng-if="isWiredZone(zone_index)">
            <a href="#" ng-click="addZone(part_index, zone_index, $event)">
                {[ verboseNameForZone(zone_index) ]}
            </a>
          </li>
        </ul>
      </div>
    </td>
    <td ng-if="!isNordSB()">
      <p ng-repeat="zone_index in part.zones"
          ng-show="zones.all()[zone_index].enabled">
        <button type="button" class="close" style="float:none"
                ng-click="parts.removeZone(part_index, zone_index)"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          {[ verboseNameForZone(zone_index) ]}
      </p>
      <div class="btn-group" ng-show="(parts.getUnclaimedZones(part_index) | onlyEnabledZone).length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <translate>Добавить шлейф</translate> <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="zone_index in parts.getUnclaimedZones(part_index) | onlyEnabledZone">
            <a href="#" ng-click="addZone(part_index, zone_index, $event)">
                {[ verboseNameForZone(zone_index) ]}
            </a>
          </li>
        </ul>
      </div>
    </td>

    <!-- Постановка-снятие -->
    <td part-users="part" part-index="part_index">

      <part-user user="user" ng-repeat="(_i, user) in armDisarm.users">
        <button ng-show="!sambo.isActive()" type="button" class="close" style="float:left"
                ng-click="removeUser(part_index, user)">
          <span aria-hidden="true">&times;</span>
          <span class="sr-only" translate>Удалить пользователя</span>
        </button>
      </part-user>

      <!-- Добавление кода -->
      <div class="btn-group" ng-show="!useAltonikaKeypad && armDisarm.unclaimedUsers.length && !sambo.isActive()">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <translate translate-context="(в значении 'код взятия/снятия')">Добавить код</translate> <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="user_index in armDisarm.unclaimedUsers">
            <a href="#" ng-click="addUser(part_index, user_index, $event)"><translate>Пользователь</translate> №{[ user_index + 1 ]}</a>
          </li>
        </ul>
      </div>

      <!-- Добавление ключа или кода Риф-КТМ (Си-Норд) -->
      <div ng-if="hasOneWire && sambo.isActive()" class="btn-group" ng-show="getAllowedUnclaimedKeys(part_index).length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <span ng-if="!useAltonikaKeypad" translate>Добавить ключ</span>
          <span ng-if="useAltonikaKeypad" translate>Добавить код Риф-КТМ (Си-Норд)</span>
          <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="key_index in getAllowedUnclaimedKeys(part_index)">
            <a href="#" ng-click="addKey(part_index, key_index, $event)"><translate>Пользователь</translate> №{[ keys.all()[key_index].user + 1 ]},
                <span ng-if="!useAltonikaKeypad"><translate>ключ</translate>: {[ keys.all()[key_index].id ]}</span>
                <span ng-if="useAltonikaKeypad"><translate>код Риф-КТМ (Си-Норд)</translate>: {[ keys.all()[key_index].id | altonikaReadableCode]}</span>
            </a>
          </li>
        </ul>
      </div>
      <div ng-if="hasOneWire && !sambo.isActive()" class="btn-group" ng-show="parts.getUnclaimedKeys().length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <span ng-if="!useAltonikaKeypad" translate>Добавить ключ</span>
          <span ng-if="useAltonikaKeypad" translate>Добавить код Риф-КТМ (Си-Норд)</span>
          <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="key_index in parts.getUnclaimedKeys()">
            <a href="#" ng-click="addKey(part_index, key_index, $event)"><translate>Пользователь</translate> №{[ keys.all()[key_index].user + 1 ]},
                <span ng-if="!useAltonikaKeypad"><translate>ключ</translate>: {[ keys.all()[key_index].id ]}</span>
                <span ng-if="useAltonikaKeypad"><translate>код Риф-КТМ (Си-Норд)</translate>: {[ keys.all()[key_index].id | altonikaReadableCode]}</span>
            </a>
          </li>
        </ul>
      </div>

      <!-- Добавление брелока -->
      <div ng-if="hasRielta && sambo.isActive()" class="btn-group" ng-show="getAllowedUnclaimedRemotes(part_index).length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <translate>Добавить брелок</translate> <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="devnum in getAllowedUnclaimedRemotes(part_index)">
            <a href="#" ng-click="addRemote(part_index, devnum, $event)">
              <translate>Пользователь</translate> №{[ remotes.all()[devnum].user + 1 ]},
              <translate>брелок</translate> №{[ getRemoteIndex(devnum) + 1 ]}</a>
          </li>
        </ul>
      </div>
      <div ng-if="hasRielta && !sambo.isActive()" class="btn-group" ng-show="parts.getUnclaimedRemotes().length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <translate>Добавить брелок</translate> <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="devnum in parts.getUnclaimedRemotes()">
            <a href="#" ng-click="addRemote(part_index, devnum, $event)">
              <translate>Пользователь</translate> №{[ remotes.all()[devnum].user + 1 ]},
              <translate>брелок</translate> №{[ getRemoteIndex(devnum) + 1 ]}</a>
          </li>
        </ul>
      </div>

      <!-- Добавление брелока CWL -->
      <div ng-if="hasCwl && sambo.isActive()" class="btn-group" ng-show="cwl.getAllowedUnclaimedRemotes(part_index).length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <translate>Добавить брелок</translate> <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="slot in cwl.getAllowedUnclaimedRemotes(part_index)">
            <a href="#" ng-click="addCwlRemoteToPart(slot, part_index, $event)">
              <translate>Пользователь</translate> №{[ cwl.getRemoteConnectedUserIndex(slot) + 1 ]},
              <translate>брелок</translate> №{[ cwl.getRemoteVerboseNumber(slot) ]}</a>
          </li>
        </ul>
      </div>
      <div ng-if="hasCwl && !sambo.isActive()" class="btn-group" ng-show="cwl.getEnabledUnclaimedRemotes().length">
        <button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown">
          <translate>Добавить брелок</translate> <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
          <li ng-repeat="slot in cwl.getEnabledUnclaimedRemotes()">
            <a href="#" ng-click="addCwlRemoteToPart(slot, part_index, $event)">
              <translate>Пользователь</translate> №{[ cwl.getRemoteConnectedUserIndex(slot) + 1 ]},
              <translate>брелок</translate> №{[ cwl.getRemoteVerboseNumber(slot) ]}</a>
          </li>
        </ul>
      </div>
    </td>

    <!-- Удаление раздела -->
    <td>
      <button class="pull-right btn btn-default"
          ng-click="removePart(part_index)">
        <span class="glyphicon glyphicon-trash"></span>
      </button>
    </td>

  </tr>
</table>
<button
    class="btn btn-success"
    ng-click="parts.add()" ng-hide="parts.full()" translate>Добавить раздел</button>
