//-/////////////////////////////////////////////////////////////////////////////
//-                                                                           //
//-               This file is part of the Buildbotics firmware.              //
//-                                                                           //
//-      Copyright (c) 2015 - 2021, Buildbotics LLC, All rights reserved.     //
//-                                                                           //
//-       This Source describes Open Hardware and is licensed under the       //
//-                               CERN-OHL-S v2.                              //
//-                                                                           //
//-       You may redistribute and modify this Source and make products       //
//-  using it under the terms of the CERN-OHL-S v2 (https:/cern.ch/cern-ohl). //
//-         This Source is distributed WITHOUT ANY EXPRESS OR IMPLIED         //
//-  WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS //
//-   FOR A PARTICULAR PURPOSE. Please see the CERN-OHL-S v2 for applicable   //
//-                                conditions.                                //
//-                                                                           //
//-              Source location: https://github.com/buildbotics              //
//-                                                                           //
//-    As per CERN-OHL-S v2 section 4, should You produce hardware based on   //
//-  these sources, You must maintain the Source Location clearly visible on  //
//-  the external case of the CNC Controller or other product you make using  //
//-                                this Source.                               //
//-                                                                           //
//-              For more information, email info@buildbotics.com             //
//-                                                                           //
//-/////////////////////////////////////////////////////////////////////////////

script#settings-network-template(type="text/x-template")
  #settings-network
    h1 Network Configuration
    em(v-if="!authorized") Login to make changes.

    h2 Hostname
    .pure-form.pure-form-aligned
      .pure-control-group
        label(for="hostname") Hostname
        input(name="hostname", v-model="hostname", @keyup.enter="set_hostname")
        bbutton(primary, :disabled="!$root.authorized", @click="set_hostname",
          text="Set")

    dialog(v-ref:hostname-set, header="Hostname Set")
      div(slot="body")
        p Hostname was successfuly set to #[strong {{hostname}}].
        p Rebooting to apply changes.
        p Redirecting to new hostname in {{redirectTimeout}} seconds.
      div(slot="footer")

    h2 WiFi
    .wifi-device(v-for="net in state.network", v-if="net.type == 'wifi'")
      table.pure-table.pure-table-striped
        tr
          th Device
          td {{net.usb ? 'USB' : 'Internal'}} WiFi
        tr
          th State
          td {{net.state}}
        tr
          th SSID
          td {{net.ssid}}
        tr
          th Addresses
          td: span(v-for="ip in net.ipv4") {{ip + ' '}}

        tr
          th Actions
          td.actions
            bbutton(primary, :disabled="!authorized", @click="connect(net)",
              icon="link", text="Connect")
            bbutton(v-if="false", primary, :disabled="!authorized",
              @click="hotspot(net)", icon="wifi", text="Hotspot")
            bbutton(primary, :disabled="!authorized", @click="disconnect(net)",
              icon="times", text="Disconnect")

    .pure-form.pure-form-aligned(v-if="false")
      .pure-control-group
        label(for="wifi_region") WiFi Region
        select(name="wifi_region", v-model="wifi_region",
          title="Set WiFi regulatory region.")
          option(v-for="region in wifi_regions", :value="region[0]")
            | {{region[1]}}
        bbutton(primary, @click="set_region", text="Set")

    p.
      WARNING: WiFi may be unreliable in an electrically noisy environment
      such as a machine shop.

    wifi-connect(v-ref:connect)
    wifi-hotspot(v-ref:hotspot)

    dialog(v-ref:wifi-password, header="Enter WiFi password", icon="question",
       width="400px", buttons="Cancel Ok")

      div(slot="body")
        .pure-form.pure-form-aligned
          .pure-control-group
            label(for="wifi_pass") Password
            input.password(name="wifi_pass", v-model="wifi_pass",
              autocomplete="current-password")
