
<div class="topbar-container"
  ng-include="'views/includes/topbar.html'"
  ng-init="showPreferences = true" ng-show="!index.noFocusedWallet">
</div>

<div ng-controller="walletHomeController as home">
  <div class="row columns m30tp" ng-show="index.noFocusedWallet">
    <div class="text-center size-12 text-warning m20b">
      <i class="fi-alert"></i> <span translate>You do not have any wallet</span>
    </div>
    <button class="button black round expand" href ui-sref="add" translate>Create</button>
  </div>

 <div class="onGoingProcess" ng-show="index.updating">
     <div class="onGoingProcess-content" ng-style="{'background-color':index.backgroundColor}">
      <div class="spinner">
        <div class="rect1"></div>
        <div class="rect2"></div>
        <div class="rect3"></div>
        <div class="rect4"></div>
        <div class="rect5"></div>
      </div>
       <span translate>Updating Wallet...</span>
     </div>
  </div>

  <div class="oh" ng-show="!index.noFocusedWallet">

    <!--

    WalletHome

    -->

    <div id="walletHome" class="walletHome tab-view tab-in">
      <ion-content on-release="index.allowPullToRefresh = true;"
        on-drag-right="index.allowRefresher()" delegate-handle="my-handle" overflow-scroll="true">
        <ion-refresher
          ng-if="index.allowPullToRefresh && index.isCordova"
          pulling-icon="ion-ios-refresh"
          spinner="ios-small"
          on-refresh="index.updateAll({triggerTxUpdate: true})">
        </ion-refresher>
        <div class="oh pr">
          <div ng-style="{'background-color':index.backgroundColor}" class="amount">
            <div ng-if="!index.notAuthorized && !index.updating">
              <div class="m15t" ng-show="index.updateError" ng-click='index.updateAll({triggerTxUpdate: true})'>
                <span class="size-12 db m10b">{{index.updateError|translate}}</span>
                <button class="outline white tiny round" translate>Tap to retry</button>
              </div>

              <div ng-show="index.walletScanStatus == 'error'" ng-click='index.retryScan()'>
                <span translate>Scan status finished with error</span>
                <br><span translate>Tap to retry</span>
              </div>

              <div ng-click='index.updateAll({triggerTxUpdate: true})'  ng-show="!index.updateError && index.walletScanStatus != 'error' && !index.shouldHideBalance" on-hold="index.onHold()">
                <strong class="size-36">{{index.totalBalanceStr}}</strong>
                <div class="size-14" ng-if="index.totalBalanceAlternative">{{index.totalBalanceAlternative}} {{index.alternativeIsoCode}}</div>
                <div class="size-14" ng-if="index.pendingAmount">
                  <span translate>Pending Confirmation</span>: {{index.pendingAmountStr}}
                </div>
              </div>

              <div ng-show="!index.updateError && index.walletScanStatus != 'error' && index.shouldHideBalance" on-hold="index.onHold()">
                <strong class="size-24" translate>[Balance Hidden]</strong>
                <div class="size-14" translate>
                  Tap and hold to show
                </div>
              </div>
            </div>
           <div ng-if="index.updating">
               <div class="size-36">
                 <strong>...</strong>
               </div>
             </div>
          </div> <!-- amount -->

          <div class="wallet-info">
            <span ng-include="'views/includes/walletInfo.html'"></span>
          </div>
          <div class="camera-icon" ng-show="index.isComplete">
            <qr-scanner on-scan="home.onQrCodeScanned(data)"></qr-scanner>
          </div>
        </div> <!-- oh -->

        <div class="p60b">
          <div class="oh pr m20t" ng-show="index.incorrectDerivation">
            <div class="text-center text-warning">
              <i class="fi-alert"></i>
              <span translate>
                WARNING: Key derivation is not working on this device/wallet. Actions cannot be performed on this wallet.
              </span>
            </div>
          </div>
          <div class="oh pr m20t" ng-show="index.notAuthorized && !index.updating">
            <div class="text-center text-warning">
              <i class="fi-alert"></i>
              <span translate>
                WARNING: Wallet not registered
              </span>
            </div>
            <div class="text-center text-gray m15r m15l" translate>
              This wallet is not registered at the given Bitcore Wallet Service (BWS). You can recreate it from the local information.
            </div>
            <div class="text-center m10t ">
              <span class="button outline round dark-gray tiny"
                ng-click="index.recreate()">
                <span translate>Recreate</span>
              </span>
            </div>
          </div>

          <div class="release size-12" ng-show="newRelease" ng-click="$root.openExternalLink('https://github.com/bitpay/copay/releases/latest')">
            <span>{{newRelease}}</span><i class="icon-arrow-right3 right size-18"></i>
          </div>

          <div ng-if="index.txps[0]">
            <h4 ng-show="index.requiresMultipleSignatures" class="title m0" translate>Payment Proposals</h4>
            <h4 ng-show="!index.requiresMultipleSignatures" class="title m0" translate>Unsent transactions</h4>
            <div ng-repeat="tx in index.txps">
              <div ng-include="index.txTemplateUrl"></div>
            </div>

            <div class="text-gray text-center size-12 p10t"
              ng-show="index.lockedBalanceSat">
              <span translate>Total Locked Balance</span>:
              <b>{{index.lockedBalanceStr}} </b>
              <span> {{index.lockedBalanceAlternative}}
                {{index.alternativeIsoCode}} </span>
            </div>
          </div>

          <!-- Activity -->

          <h4 class="title" ng-click="index.startSearch(); openSearchModal()" ng-show="!index.notAuthorized">
            <span translate>Activity</span>
            <i class="dib m5l size-16 pointer fi-magnifying-glass"></i>
          </h4>

          <div class="oh pr m20t text-gray size-12 text-center"
            ng-show="!index.loadingWallet && !index.txHistory[0] && !index.updatingTxHistory && !index.txHistoryError && !index.updateError && !index.notAuthorized"
            translate>No transactions yet
          </div>

          <div class="oh pr" ng-show="(index.txHistory[0] || index.txProgress > 5) && !index.notAuthorized">

            <div ng-show="index.updatingTxHistory && index.txProgress > 5">
              <div  class="row p20 text-center">
                <div class="columns large-12 medium-12 small-12 m10b">
                  <ion-spinner class="spinner-dark" icon="lines"></ion-spinner>
                </div>
                <div class="size-12 text-gray m20t">
                  <div translate>{{index.txProgress}} transactions downloaded</div>
                  <div translate>Updating transaction history. Please stand by.</div>
                </div>
              </div>
            </div>

            <div ng-if="index.txHistory[0] &&  index.updatingTxHistory && index.newTx" class="row collapse last-transactions-content animated fadeInDown">
              <div class="large-6 medium-6 small-6 columns size-14">
                <div class="m10r left">
                  <img src="img/icon-new.svg" width="40">
                </div>
                <div class="m10t" style="background:#eee; width: 8em; margin-left: 52px; line-height:0.6em">
                  <span>&nbsp;</span>
                </div>
                <div style="margin-top:5px; background:#eee; width: 6em; margin-left: 52px; line-height:0.6em">
                  <span>&nbsp;</span>
                </div>
              </div>
            </div>

            <div ng-repeat="btx in index.txHistory track by btx.txid"
              ng-click="home.openTxModal(btx)"
              class="row collapse last-transactions-content">
              <div class="large-6 medium-6 small-6 columns size-14">
                <div class="m10r left">
                  <img src="img/icon-receive-history.svg" alt="sync" width="40" ng-show="btx.action == 'received'">
                  <img src="img/icon-sent-history.svg" alt="sync" width="40" ng-show="btx.action == 'sent'">
                  <img src="img/icon-moved.svg" alt="sync" width="40" ng-show="btx.action == 'moved'">
                </div>
                <div class="m10t">
                  <span ng-show="btx.action == 'received'">
                    <span class="ellipsis">
                      <span ng-if="btx.note.body">{{btx.note.body}}</span>
                      <span ng-if="!btx.note.body" translate> Received</span>
                    </span>
                  </span>
                  <span ng-show="btx.action == 'sent'">
                    <span class="ellipsis">
                      <span ng-if="btx.message">{{btx.message}}</span>
                      <span ng-if="!btx.message && btx.note.body">{{btx.note.body}}</span>
                      <span ng-if="!btx.message && !btx.note.body && index.addressbook[btx.addressTo]">{{index.addressbook[btx.addressTo]}}</span>
                      <span ng-if="!btx.message && !btx.note.body && !index.addressbook[btx.addressTo]" translate> Sent</span>
                    </span>
                  </span>
                  <span ng-show="btx.action == 'moved'">
                    <span class="ellipsis">
                      <span ng-if="btx.note.body">{{btx.note.body}}</span>
                      <span ng-if="!btx.note.body" translate>Moved</span>
                    </span>

                  </span>
                  <span class="label tu warning radius" ng-show="btx.action == 'invalid'" translate>Invalid</span>
                </div>
              </div>

              <div class="large-5 medium-5 small-5 columns text-right" >
                <span class="size-16"  ng-class="{'text-bold': btx.recent}">
                  <span ng-if="btx.action == 'received'">+</span>
                  <span ng-if="btx.action == 'sent'">-</span>
                  <span  class="size-12" ng-if="btx.action == 'invalid'" translate>
                  (possible double spend)
                  </span>
                  <span  ng-if="btx.action != 'invalid'">
                  {{btx.amountStr}}
                  </span>
                </span>
                <div class="size-12 text-gray">
                  <time ng-if="btx.time">{{btx.time * 1000 | amTimeAgo}}</time>
                  <span translate class="text-warning"
                    ng-show="!btx.time && (!btx.confirmations || btx.confirmations == 0)">
                    Unconfirmed
                  </span>
                </div>
              </div>
              <div class="large-1 medium-1 small-1 columns text-right m10t">
                <i class="icon-arrow-right3 size-18"></i>
              </div>
            </div>

            <div class="row m20t text-center" ng-show="index.historyRendering && !index.ching">
              <div class="columns large-12 medium-12 small-12">
                <ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
              </div>
            </div>

            <ion-infinite-scroll
              ng-if="index.historyShowMore"
              on-infinite="index.showMore()"
              distance="1%">
            </ion-infinite-scroll>
          </div>
        </div>

      </ion-content>
      <div class="extra-margin-bottom"></div>
    </div> <!-- END WalletHome -->

    <!--

    receive

    -->
    <div id="receive" class="receive tab-view">

      <div ng-show="index.needsBackup" class="p60t columns text-center">
        <div class="circle-icon">
          <i class="fi-alert size-48"></i>
        </div>
        <h5 translate>Backup Needed</h5>
        <p class="text-gray m20b columns" translate>
          Before receiving funds, you must backup your wallet. If this device is lost, it is impossible to access your funds without a backup.
        </p>
        <button class="m20t button black expand round" href ui-sref="backup" ng-style="{'background-color':index.backgroundColor}" >
          <span translate>Backup now</span>
        </button>
      </div>
      <div ng-show="!index.needsBackup">
        <div class="box-notification m20t" ng-show="home.addrError">
          <span class="text-warning">
            {{home.addrError|translate}}
          </span>
        </div>
        <div class="row">
          <!-- Address-->
          <div class="large-12 columns">
            <h2 class="text-center m10t" translate>My Bitcoin address</h2>
            <div class="text-center" ng-click="home.copyToClipboard(home.addr, $event)" ng-show="home.addr || home.generatingAddress">
              <qrcode size="220" data="bitcoin:{{home.addr}}"></qrcode>
              <div ng-show="home.generatingAddress" style="position:relative; top:-226px; height:0px">
                <div style="height:220px; width:220px; margin:auto; background: white">
                  <ion-spinner class="spinner-stable" icon="lines" style="margin-top: 85px"></ion-spinner>
                </div>
              </div>
              <div class="m10t" >
                <h4 ng-class="{'enable_text_select': !index.isCordova}" class="size-12">
                  {{home.generatingAddress ? '...' : home.addr}}
                </h4>
              </div>
            </div>
          </div>
        </div>
        <div class="row m20t">
          <div class="small-12 columns" ng-show="index.isCordova && home.addr">
            <button class="button outline light-gray small round expand"
              on-tap="home.shareAddress(home.addr)"
              ng-disabled="home.generatingAddress">
              <span translate>Share address</span>
            </button>
          </div>
          <div class="small-12 columns" ng-show="home.addr">
            <button class="button expand small round m10b" ng-click="openAmountModal(home.addr)"
              ng-style="{'background-color':index.backgroundColor}"
              ng-disabled="home.generatingAddress">
              <span translate>Request a specific amount</span>
            </button>
          </div>
        </div>
        <div class="row m10t" ng-show="home.addr">
          <div class="large-12 columns">
            <div class="line-t size-10 text-gray m10b p10t" ng-show="!index.isSingleAddress">
              <span translate> Share this wallet address to receive payments. To protect your privacy, new addresses are generated automatically once you use them.</span>
                <a ng-show="!home.generatingAddress" ng-click="home.setAddress(true)" translate>Generate new address</a>
            </div>
            <div class="line-t size-10 text-gray m10b p10t" ng-show="index.isSingleAddress">
              <span translate> Share this wallet address to receive payments</span>.
            </div>
          </div>
        </div>
      </div>
      <div class="extra-margin-bottom"></div>
    </div> <!-- END Receive -->


    <!--

    send

    -->
    <div id="send" class="send tab-view">
      <div class="pr p25b">
        <h4 class="title m0" ng-show="!index.updating">
          <available-balance ng-show="!index.shouldHideBalance"></available-balance>
          <span
            ng-show="home.lockedCurrentFeePerKb || home.lockAmount"
            class="text-gray" translate>Send Max</span>
          <a
            ng-show="index.availableBalanceSat > 0 && !home.lockedCurrentFeePerKb  && !home.lockAmount"
            ng-click="home.sendMax(index.availableBalanceSat)"
             translate>Send Max
          </a>
          <div ng-show="!home.paymentExpired && home._paypro">
            <span translate>Payment expires</span>
            <time> {{home.remainingTimeStr}}</time>
          </div>
        </h4>
        <div class="camera-icon" ng-show="index.isComplete">
          <qr-scanner on-scan="home.onQrCodeScanned(data)"></qr-scanner>
        </div>
      </div>
      <div class="box-notification m20t" ng-show="home.error" ng-click="home.resetError()">
        <span class="text-warning">
          {{home.error|translate}}
        </span>
      </div>
      <div class="row m20t">
        <div class="large-12 large-centered columns">
          <form name="sendForm"   novalidate>

            <div ng-hide="home._paypro">
              <div class="row collapse">
                <label for="address" class="left" >
                  <span translate>To</span>
                </label>
                <span ng-hide="sendForm.address.$pristine">
                  <span class="has-error right size-12" ng-show="sendForm.address.$invalid && _address">
                    <i class="icon-close-circle size-14"></i>
                    <span class="vm" translate>Not valid</span>
                  </span>
                  <small class="right text-primary" ng-show="!sendForm.address.$invalid">
                    <i class="icon-checkmark-circle size-14"></i>
                  </small>
                </span>
              </div>

              <div class="input">
                <input ng-show="sendForm.address.$invalid" class="m0" type="text" id="address" name="address" ng-disabled=" home.lockAddress" ng-attr-placeholder="{{'Bitcoin address'|translate}}" ng-model="_address" valid-address required ng-focus="home.formFocus('address')" ng-blur="home.formFocus(false)">
                <div class="addressbook-input" ng-show="!sendForm.address.$invalid && _address">
                  {{index.addressbook[_address] || _address}}
                </div>
                <a class="postfix size-12 m0 text-gray"
                ng-style="{'color':index.backgroundColor}"
                ng-click="home.openAddressbookModal(index.otherWallets, _address)">
                  <i class="icon-wallet text-bold size-18"></i>
                </a>
              </div>
            </div>
            <div ng-show="home._paypro">
              <div class="row collapse" ng-click="home.openPPModal(home._paypro)">

                <label for="domain">
                  <span translate>Payment to</span>
                </label>

                <div class="input block">
                  <input class="p45li" type="text" id="domain" name="domain" ng-model="home._paypro.domain" ng-disabled="1">
                  <i ng-show="home._paypro.verified && home._paypro.caTrusted" class="fi-lock color-greeni"></i>
                  <i ng-show="!home._paypro.caTrusted" class="fi-unlock color-yellowi"></i>
                </div>
              </div>
            </div>

            <div class="row">
              <div class="large-12 medium-12 columns">
                <div class="right" ng-hide="sendForm.amount.$pristine && !sendForm.amount.$modelValue ">
                  <span class="has-error right size-12" ng-show="sendForm.amount.$invalid">
                    <i class="icon-close-circle size-14"></i>
                    <span clas="vm" translate>Not valid</span>
                  </span>
                  <small class="text-primary right" ng-show="!sendForm.amount.$invalid && !sendForm.alternative.$invalid">
                    <i class="icon-checkmark-circle size-14"></i>
                  </small>
                </div>
                <div>
                  <label for="amount">
                    <span translate>Amount</span><span ng-show="showAlternative"> [{{home.alternativeIsoCode}}]</span>
                  </label>
                  <div class="input">
                    <div ng-if="index.isCordova">
                      <input
                        type="number"
                        ng-readonly="!home.lockAmount"
                        ng-show="!showAlternative"
                        id="amount"
                        ng-disabled="home.lockAmount"
                        name="amount"
                        ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}"
                        ng-model="_amount"
                        valid-amount
                        required
                        autocomplete="off"
                        ng-click="openInputAmountModal()"
                        ignore-mouse-wheel>
                      <input
                        type="number"
                        ng-readonly="!home.lockAmount"
                        ng-show="showAlternative"
                        id="alternative"
                        ng-disabled="!home.isRateAvailable || home.lockAmount"
                        name="alternative"
                        ng-attr-placeholder="{{'Amount in'|translate}} {{ home.alternativeName }}"
                        ng-model="_alternative"
                        required
                        autocomplete="off"
                        ng-click="openInputAmountModal()"
                        ignore-mouse-wheel>
                    </div>
                    <div ng-if="!index.isCordova">
                      <input
                        type="number"
                        ng-show="!showAlternative"
                        id="amount"
                        ng-disabled="home.lockAmount"
                        name="amount"
                        ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}"
                        ng-model="_amount"
                        valid-amount
                        required
                        autocomplete="off"
                        ignore-mouse-wheel>
                      <input
                        type="number"
                        ng-show="showAlternative"
                        id="alternative"
                        ng-disabled="!home.isRateAvailable || home.lockAmount"
                        name="alternative"
                        ng-attr-placeholder="{{'Amount in'|translate}} {{ home.alternativeName }}"
                        ng-model="_alternative"
                        required
                        autocomplete="off"
                        ignore-mouse-wheel>
                    </div>
                    <a class="postfix button" ng-show="!showAlternative" ng-style="{'background-color':index.backgroundColor}" ng-click="showAlternative = !showAlternative">{{home.unitName}}</a>
                    <a class="postfix button black" ng-show="showAlternative" ng-click="showAlternative = !showAlternative">{{home.alternativeIsoCode}}</a>
                  </div>
                </div>
              </div>
            </div>
            <div class="row" ng-hide="home.hideNote">
              <div class="large-12 columns">
                <label for="comment"><span translate>Description</span>
                  <small translate ng-hide="!sendForm.comment.$pristine">optional</small>
                  <small translate class="has-error" ng-show="sendForm.comment.$invalid && !sendForm.comment.$pristine">too long!</small>
                </label>
                <div class="input">
                  <textarea id="comment" name="comment"
                    ng-maxlength="500" ng-model="_comment" ng-focus="home.formFocus('msg')"
                    ng-blur="home.formFocus(false)"></textarea>
                </div>
              </div>
            </div>

            <div class="row">
              <div class="large-6 medium-6 small-6 columns" ng-show="(home._paypro || home.lockAddress ||
                home.lockAmount || !sendForm.amount.$pristine)">
                <a ng-click="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a>
              </div>
              <div class="columns" ng-class="{'small-6 medium-6 large-6':(home._paypro || home.lockAddress ||
                home.lockAmount  || !sendForm.amount.$pristine)}">
                <button class="button black round expand" ng-disabled="sendForm.$invalid || home.paymentExpired || index.updating"
                  ng-style="{'background-color':index.backgroundColor}" ng-click="home.submitForm()" translate>
                  Send
                </button>
              </div>

            </div>
          </form>
        </div>
      </div>
      <div class="extra-margin-bottom"></div>
    </div> <!-- END Send -->

    <div id="{{view.id}}" class="{{view.class}} tab-view" ng-repeat="view in index.addonViews" ng-include="view.template">
    </div>

  </div>
</div>
<div class="extra-margin-bottom"></div>
<div class="bottom-bar row collapse p0i">
    <div>
        <div class="row collapse p0i">
            <div class="medium-4 small-4 columns text-center bottombar-item">
                <a href="#/tabs/home" >
                    <span class="size-10 tu">
                      tabs
                    </span>
                </a>             
            </div>
        </div>
    </div>
</div>
