<div class="bottom-10">
  <div ng-show="!desktopMode" class="alert alert-warning" translate>
    Указанные настройки применятся только при подключённом сетевом адаптере.
  </div>
</div>

<div class="bottom-10">
  <div ng-show="!desktopMode" class="alert alert-danger" translate>
    Внимание! При записи некорректных сетевых настроек прибор перестанет передавать события и облачные сервисы будут недоступны. Внимательно проверьте настройки перед записью.
  </div>
</div>

<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title ng-binding" translate>Сетевой адаптер</h3>
  </div>
  <div class="panel-body">
    <form role="form" class="form-horizontal" name="NetworkAdapterForm">
      <!-- Adapter type dropdown -->
      <div class="form-group">
        <label class="control-label col-sm-3" translate>Тип сетевого адаптера</label>
        <div class="col-sm-3">
          <select class="form-control"
                  ng-model="adapters().spi_adapter_type"
                  ng-disabled="!isWifiAvailable()"
                  ng-options="option.value as option.label for option in adapterTypeOptions"
                  ng-change="onAdapterTypeChange(NetworkAdapterForm)">
          </select>
        </div>
      </div>

      <!-- Firmware warning when WiFi is not available -->
      <div class="form-group" ng-show="!isWifiAvailable()">
        <div class="col-sm-offset-3 col-sm-9">
          <div class="alert alert-info" translate>
            Использование адаптера WiFi поддерживается только приборами с прошивкой версии 20.51 или выше
          </div>
        </div>
      </div>

      <!-- ======================== -->
      <!-- Ethernet settings block  -->
      <!-- ======================== -->
      <div ng-if="showEthernetSettings()">
        <hr>
        <div class="form-group"
             ng-class="NetworkAdapterForm.eth_mac_addr.$invalid?'has-error':''"
             ng-if="showControlsForMAC()">
          <label class="control-label col-sm-3" translate>MAC-адрес</label>
          <div class="col-sm-3">
            <input type="text" class="form-control col-sm-3"
                   name="eth_mac_addr"
                   required
                   ng-model="getEthernetModel().mac"
                   mac
                   mac-zero-bit
                   ng-trim="false"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="formGuard(NetworkAdapterForm)">
          </div>
          <div class="col-sm-1">
            <button class="btn btn-default" type="button"
                    ng-click="generateEthernetMac(NetworkAdapterForm)">
              <span class="glyphicon glyphicon-refresh"></span>
            </button>
          </div>
          <div class="col-sm-5">
            <div ng-show="NetworkAdapterForm.eth_mac_addr.$error.mac" class="help-block ng-hide" translate>
                  Неверный формат (Пример: 00:11:22:AB:CD:EF)
            </div>
            <div ng-show="NetworkAdapterForm.eth_mac_addr.$error.macZeroBit" class="help-block ng-hide" translate>
                  Второй символ некорректный. Допустимые значения: 0, 2, 4, 6, 8, A, C, E.
            </div>
          </div>
        </div>
        <dev class="form-inline col-md-offset-3 col-md-7">
          <div class="form-group checkbox">
            <label>
              <input type="checkbox" ng-model="ethernet().dhcp_enabled"
                     ng-change="whenEthernetDHCPChanged(NetworkAdapterForm)"
                     ng-true-value="1" ng-false-value="0">
              <translate>Получать настройки по DHCP</translate>
            </label>
          </div>
        </dev>
        <div class="form-group" ng-class="NetworkAdapterForm.eth_ip_addr.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Локальный IP-адрес</label>
          <div class="col-sm-3">
            <input type="text" class="form-control col-sm-3"
                   name="eth_ip_addr"
                   ng-model="getEthernetSettings().ip_addr"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-disabled="ethernet().dhcp_enabled"
                   ng-change="setEthernetSettings(); formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.eth_ip_addr.$error.ip" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>
        <div class="form-group" ng-class="NetworkAdapterForm.eth_ip_mask.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Маска подсети</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="eth_ip_mask"
                   ng-model="getEthernetSettings().ip_mask"
                   subnetmask
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-disabled="ethernet().dhcp_enabled"
                   ng-change="setEthernetSettings(); formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.eth_ip_mask.$error.subnetmask" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 255.255.255.0)
          </div>
        </div>
        <div class="form-group" ng-class="NetworkAdapterForm.eth_ip_gateway.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>IP-адрес шлюза</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="eth_ip_gateway"
                   ng-model="getEthernetSettings().ip_gateway"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-disabled="ethernet().dhcp_enabled"
                   ng-change="setEthernetSettings(); formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.eth_ip_gateway.$error.ip" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>
        <div class="form-group" ng-class="NetworkAdapterForm.eth_dns1.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Основной DNS</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="eth_dns1"
                   ng-model="ethernet().dns1"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.eth_dns1.$error.ip" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>
        <div class="form-group" ng-class="NetworkAdapterForm.eth_dns2.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Вторичный DNS</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="eth_dns2"
                   ng-model="ethernet().dns2"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.eth_dns2.$invalid" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>
      </div>

      <!-- =================== -->
      <!-- WiFi settings block -->
      <!-- =================== -->
      <div ng-if="showWifiSettings()">
        <hr>
        <!-- WiFi SSID -->
        <div class="form-group" ng-class="NetworkAdapterForm.wifi_ssid.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Имя сети</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="wifi_ssid"
                   ng-model="wifi().wifi_ssid"
                   required
                   wifi-ssid
                   ng-trim="false"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.wifi_ssid.$error.required" class="help-block ng-hide col-sm-5" translate>
            Имя сети не может быть пустым
          </div>
          <div ng-show="NetworkAdapterForm.wifi_ssid.$error.wifiSsid" class="help-block ng-hide col-sm-5" translate>
            Имя сети должно содержать не более 32 ASCII символов
          </div>
        </div>

        <!-- WiFi Password -->
        <div class="form-group" ng-class="NetworkAdapterForm.wifi_password.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Пароль</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="wifi_password"
                   ng-model="wifi().wifi_password"
                   wifi-password
                   ng-trim="false"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.wifi_password.$error.wifiPasswordLength" class="help-block ng-hide col-sm-5" translate>
            Пароль должен содержать не более 63 символов
          </div>
          <div ng-show="NetworkAdapterForm.wifi_password.$error.wifiPasswordChars && !NetworkAdapterForm.wifi_password.$error.wifiPasswordLength" class="help-block ng-hide col-sm-5" translate>
            Пароль должен состоять из латинских букв, цифр и стандартных знаков
          </div>
        </div>

        <hr>

        <!-- WiFi MAC -->
        <div class="form-group"
             ng-class="NetworkAdapterForm.wifi_mac.$invalid?'has-error':''"
             ng-if="showControlsForMAC()">
          <label class="control-label col-sm-3" translate>MAC</label>
          <div class="col-sm-3">
            <input type="text" class="form-control col-sm-3"
                   name="wifi_mac"
                   ng-model="wifi().wifi_mac"
                   mac-optional
                   ng-trim="false"
                   placeholder="По умолчанию..."
                   masquerade="{from: '00:00:00:00:00:00', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="formGuard(NetworkAdapterForm)">
          </div>
          <div class="col-sm-1">
            <button class="btn btn-default" type="button"
                    ng-click="generateWifiMac(NetworkAdapterForm)">
              <span class="glyphicon glyphicon-refresh"></span>
            </button>
          </div>
          <div class="col-sm-5">
            <div ng-show="NetworkAdapterForm.wifi_mac.$error.macOptional" class="help-block ng-hide" translate>
                  Неверный формат (Пример: 00:11:22:AB:CD:EF)
            </div>
          </div>
        </div>

        <hr>

        <!-- WiFi DHCP -->
        <dev class="form-inline col-md-offset-3 col-md-7">
          <div class="form-group checkbox">
            <label>
              <input type="checkbox" ng-model="wifi().wifi_dhcp_enabled"
                     ng-change="whenWifiDHCPChanged(NetworkAdapterForm)"
                     ng-true-value="1" ng-false-value="0">
              <translate>Получать настройки по DHCP</translate>
            </label>
          </div>
        </dev>

        <!-- WiFi IP Address -->
        <div class="form-group" ng-class="NetworkAdapterForm.wifi_ip_addr.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Локальный IP-адрес</label>
          <div class="col-sm-3">
            <input type="text" class="form-control col-sm-3"
                   name="wifi_ip_addr"
                   ng-model="getWifiSettings().wifi_ip_addr"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-disabled="wifi().wifi_dhcp_enabled"
                   ng-change="setWifiSettings(); formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.wifi_ip_addr.$error.ip" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>

        <!-- WiFi Subnet Mask -->
        <div class="form-group" ng-class="NetworkAdapterForm.wifi_ip_mask.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Маска подсети</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="wifi_ip_mask"
                   ng-model="getWifiSettings().wifi_ip_mask"
                   subnetmask
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-disabled="wifi().wifi_dhcp_enabled"
                   ng-change="setWifiSettings(); formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.wifi_ip_mask.$error.subnetmask" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 255.255.255.0)
          </div>
        </div>

        <!-- WiFi Gateway -->
        <div class="form-group" ng-class="NetworkAdapterForm.wifi_ip_gateway.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>IP-адрес шлюза</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="wifi_ip_gateway"
                   ng-model="getWifiSettings().wifi_ip_gateway"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-disabled="wifi().wifi_dhcp_enabled"
                   ng-change="setWifiSettings(); formGuard(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.wifi_ip_gateway.$error.ip" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>

        <!-- WiFi Primary DNS -->
        <div class="form-group" ng-class="NetworkAdapterForm.wifi_dns1.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Основной DNS</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="wifi_dns1"
                   ng-model="wifi().wifi_dns1"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="onWifiDns1Change(NetworkAdapterForm)">
          </div>
          <div ng-show="NetworkAdapterForm.wifi_dns1.$error.ip" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>

        <!-- WiFi Secondary DNS -->
        <div class="form-group" ng-class="NetworkAdapterForm.wifi_dns2.$invalid?'has-error':''">
          <label class="control-label col-sm-3" translate>Вторичный DNS</label>
          <div class="col-sm-3">
            <input type="text" class="form-control"
                   name="wifi_dns2"
                   ng-model="wifi().wifi_dns2"
                   ip
                   ng-trim="false"
                   masquerade="{from: '0.0.0.0', to: ''}"
                   ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0 } }"
                   ng-change="formGuard(NetworkAdapterForm)"
                   ng-disabled="isWifiDns1Empty()">
          </div>
          <div ng-show="NetworkAdapterForm.wifi_dns2.$invalid" class="help-block ng-hide col-sm-5" translate>
            Неверный формат (Пример: 192.168.0.1)
          </div>
        </div>
      </div>

    </form>
  </div>
</div>
