<ion-view class="settings">
  <ion-nav-bar class="bar-royal">
    <ion-nav-title>{{'Create Personal Wallet' | translate}}</ion-nav-title>
    <ion-nav-back-button>
    </ion-nav-back-button>
  </ion-nav-bar>

  <ion-content ng-controller="createController" ng-init="init(1);">
    <form name="setupForm" ng-submit="create(setupForm)" novalidate>
      <div class="list settings-list settings-input-group">
        <label class="item item-input item-stacked-label">
          <span class="input-label" translate>Wallet name</span>
          <input type="text"
          placeholder="{{'Family vacation funds'|translate}}"
          ng-model="formData.walletName"
          ng-required="true"
          ng-focus="formFocus('wallet-name')"
          ng-blur="formFocus(false)">
        </label>

        <div class="item item-divider"></div>

        <a class="item" ng-click="showAdvChange()">
          <span translate ng-show="!showAdv">Show advanced options</span>
          <span translate ng-show="showAdv">Hide advanced options</span>
        </a>

        <div ng-show="showAdv">
          <label class="item item-input item-stacked-label">
            <span class="input-label">Wallet Service URL</span>
            <input type="text" ng-model="formData.bwsurl" placeholder="https://bws.bitpay.com/bws/api">
          </label>

          <label class="item item-input item-select">
            <div class="input-label" translate>
              Wallet Key
            </div>
            <select class="m10t" ng-model="seedSource" ng-options="seed as seed.label for seed in seedOptions"></select>
          </label>

          <label class="item item-input item-stacked-label" ng-show="seedSource.id == 'trezor' || seedSource.id == 'ledger'">
            <span class="input-label" translate>Account Number</span>
            <input type="number" ng-model="formData.account" ignore-mouse-wheel>
          </label>

          <label class="item item-input item-stacked-label" ng-show="seedSource.id == 'set'">
            <span class="input-label" translate>Wallet Recovery Phrase</span>
            <input placeholder="{{'Enter the recovery phrase (BIP39)'|translate}}"
            autocapitalize="off"
            type="text"
            ng-model="formData.privateKey">
          </label>

          <ion-toggle ng-model="encrypt" toggle-class="toggle-positive" ng-change="resizeView()" ng-show="seedSource.id == 'new' || seedSource.id == 'set'">
            <span translate>Encrypt with a Password</span>
          </ion-toggle>

          <label class="item item-input item-stacked-label" ng-show="seedSource.id == 'new' && encrypt">
            <span class="input-label" translate>Add a Password</span>
            <input type="text"
            placeholder="{{'Add an optional password to secure the recovery phrase'|translate}}"
            autocapitalize="off"
            ng-model="formData.createPassphrase">
          </label>

          <label class="item item-input item-stacked-label" ng-show="seedSource.id == 'set' && encrypt">
            <span class="input-label" translate>Add a Password</span>
            <input type="text"
            placeholder="{{'The recovery phrase could require a password to be imported'|translate}}"
            autocapitalize="off"
            ng-model="formData.passphrase">
          </label>

          <div class="text-center box-notification error" ng-show="(seedSource.id =='new' || seedSource.id =='set') && encrypt">
            <strong translate>This password cannot be recovered. If the password is lost, funds can only be recovered with a valid backup.</strong>
          </div>

          <ion-checkbox ng-model="formData.passwordSaved" class="checkbox-positive" ng-show="encrypt">
            <span class="toggle-label" translate>I have written it down</span>
          </ion-checkbox>

          <label class="item item-input item-stacked-label" ng-show="seedSource.id == 'set'">
            <span class="input-label" translate>Derivation Path</span>
            <input type="text"
            placeholder="{{'BIP32 path for address derivation'|translate}}"
            ng-model="formData.derivationPath">
          </label>

          <ion-toggle ng-show="seedSource.id == 'new'" ng-model="formData.testnetEnabled" toggle-class="toggle-positive">
            <span translate>Testnet</span>
          </ion-toggle>

          <ion-toggle ng-model="formData.singleAddressEnabled" toggle-class="toggle-positive">
            <span translate>Single Address Wallet</span>
            <small translate>For audit purposes</small>
          </ion-toggle>

        </div> <!-- advanced -->
      </div> <!-- list -->

      <button type="submit" class="button button-standard button-primary"
        ng-disabled="setupForm.$invalid || ((encrypt && !formData.passwordSaved) || encrypt && ((seedSource.id == 'new' && !formData.createPassphrase) || (seedSource.id == 'set' && !formData.passphrase)))">
        <span translate>Create new wallet</span>
      </button>
    </form>
  </ion-content>
</ion-view>
