<link rel="import" href="chrome://resources/html/polymer.html">

<link rel="import" href="chrome://resources/cr_components/chromeos/network/mojo_interface_provider.html">
<link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_network_listener_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="chrome://resources/cr_elements/cr_scrollable_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/cr_searchable_drop_down/cr_searchable_drop_down.html">
<link rel="import" href="chrome://resources/cr_elements/shared_style_css.html">
<link rel="import" href="chrome://resources/html/chromeos/onc_mojo.html">
<link rel="import" href="../i18n_setup.html">
<link rel="import" href="cups_add_printer_dialog_elements.html">
<link rel="import" href="cups_printer_dialog_util.html">
<link rel="import" href="cups_printer_shared_css.html">
<link rel="import" href="cups_printers_browser_proxy.html">

<dom-module id="settings-cups-edit-printer-dialog">
  <template>
    <style include="cr-shared-style cups-printer-shared"></style>
    <add-printer-dialog>
      <div slot="dialog-title">$i18n{editPrinterDialogTitle}
        <div id="general-error-container" hidden="[[!errorText_]]">
          <div id="general-error">
            <iron-icon id="general-error-icon" icon="cr:warning"></iron-icon>
            <div id="general-error-message">
              [[errorText_]]
            </div>
          </div>
        </div>
      </div>
      <div slot="dialog-body" scrollable>
        <div class="settings-box first two-line">
          <cr-input class="printer-name-input" autofocus
              id="printerName"
              value="{{pendingPrinter_.printerName}}"
              on-input="onPrinterInfoChange_"
              label="$i18n{printerName}"
              maxlength=64>
          </cr-input>
        </div>
        <div class="settings-box two-line">
          <cr-input label="$i18n{printerAddress}"
              id="printerAddress"
              on-input="onPrinterInfoChange_"
              value="{{pendingPrinter_.printerAddress}}"
              disabled="[[!networkProtocolActive_]]"
              maxlength=63
              readonly="[[!isOnline_]]">
          </cr-input>
        </div>
        <div class="settings-box two-line">
          <div class="start">
            <div id="printerProtocol" class="cr-form-field-label">
              $i18n{printerProtocol}
            </div>
            <div class="secondary">
              <select class="md-select" aria-labelledby="printerProtocol"
                  value="[[pendingPrinter_.printerProtocol]]"
                  on-change="onProtocolChange_"
                  disabled="[[!protocolSelectEnabled(isOnline_,
                      networkProtocolActive_)]]">
                <option value="ipp" disabled="[[!networkProtocolActive_]]">
                  $i18n{printerProtocolIpp}
                </option>
                <option value="ipps" disabled="[[!networkProtocolActive_]]">
                  $i18n{printerProtocolIpps}
                </option>
                <option value="http" disabled="[[!networkProtocolActive_]]">
                  $i18n{printerProtocolHttp}
                </option>
                <option value="https" disabled="[[!networkProtocolActive_]]">
                  $i18n{printerProtocolHttps}
                </option>
                <option value="socket" disabled="[[!networkProtocolActive_]]">
                  $i18n{printerProtocolAppSocket}
                </option>
                <option value="lpd" disabled="[[!networkProtocolActive_]]">
                  $i18n{printerProtocolLpd}
                </option>
                <option value="usb" disabled="[[networkProtocolActive_]]">
                  $i18n{printerProtocolUsb}
                </option>
                <option value="ippusb" disabled="[[networkProtocolActive_]]">
                  $i18n{printerProtocolIppUsb}
                </option>
              </select>
            </div>
          </div>
        </div>
        <div class="settings-box two-line">
          <cr-input id="printerQueue" label="$i18n{printerQueue}"
              value="{{pendingPrinter_.printerQueue}}"
              on-input="onPrinterInfoChange_"
              maxlength=64
              disabled="[[!networkProtocolActive_]]"
              readonly="[[!isOnline_]]">
          </cr-input>
        </div>
        <div class="settings-box two-line">
          <cr-input label="$i18n{printerURI}" readonly
              value="[[getPrinterURI_(pendingPrinter_)]]">
          </cr-input>
        </div>
        <div class="settings-box two-line">
          <cr-searchable-drop-down items="[[manufacturerList]]"
              id="printerPPDManufacturer"
              label="$i18n{printerManufacturer}"
              value="{{pendingPrinter_.ppdManufacturer}}"
              readonly="[[!isOnline_]]">
          </cr-searchable-drop-down>
        </div>
        <div class="settings-box two-line">
          <cr-searchable-drop-down items="[[modelList]]"
              id="printerPPDModel"
              label="$i18n{printerModel}"
              value="{{pendingPrinter_.ppdModel}}"
              readonly="[[!isOnline_]]">
          </cr-searchable-drop-down>
        </div>
        <div id="ppdLabel" class="cr-form-field-label">
          <span>$i18n{selectDriver}</span>
          <a href="$i18n{printingCUPSPrintPpdLearnMoreUrl}" target="_blank">
              $i18n{learnMore}
          </a>
        </div>
        <div class="settings-box two-line">
          <cr-input class="browse-file-input" readonly tabindex="-1"
              value="[[userPPD_]]" aria-labelledby="ppdLabel"
              error-message="$i18n{selectDriverErrorMessage}"
              invalid="[[invalidPPD_]]">
          </cr-input>
          <cr-button class="browse-button" on-click="onBrowseFile_"
          disabled="[[!isOnline_]]">
            $i18n{selectDriverButtonText}
          </cr-button>
        </div>
        <div class="eula" id="eulaUrl" hidden="[[!eulaUrl_]]">
          <a href="[[eulaUrl_]]" target="_blank">$i18n{printerEulaNotice}</a>
        </div>
      </div>
      <div slot="dialog-buttons">
        <cr-button class="cancel-button" on-click="onCancelTap_">
          $i18n{cancel}
        </cr-button>
        <cr-button class="action-button" on-click="onSaveTap_"
            disabled="[[!canSavePrinter_(pendingPrinter_.*,
                printerInfoChanged_, isOnline_)]]">
          $i18n{editPrinterButtonText}
        </cr-button>
      </div>
    </add-printer-dialog>
  </template>
  <script src="cups_edit_printer_dialog.js"></script>
</dom-module>
