<ion-view id="coinbase">
  <ion-nav-bar class="bar-royal">
    <ion-nav-back-button>
    </ion-nav-back-button>
    <ion-nav-title>Coinbase</ion-nav-title>
  </ion-nav-bar>
  <ion-nav-buttons side="secondary">
    <button class="button button-clear button-small ng-hide" ng-show="!accessToken" ng-click="coinbase.toggleOauthForm()">
      <span ng-hide="showOauthForm">Enter Code</span>
      <span ng-show="showOauthForm">Restart</span>
    </button>
  </ion-nav-buttons>
  <ion-content scroll="false" class="ng-hide" ng-show="!accessToken">
    <div class="integration-onboarding">
      <div class="integration-onboarding-logo">
        <img src="img/coinbase-logo.png">
      </div>
      <div class="integration-onboarding-description" ng-hide="showOauthForm">Coinbase's exchange service is available in 33 countries, and can take 3-5 days to buy or sell bitcoin.</div>
      <div class="integration-onboarding-description" ng-show="showOauthForm">If you have trouble, contact Coinbase support for direct assistance.</div>
      <div class="integration-onboarding-cta" ng-show="!showOauthForm">
        <button class="button button-standard button-primary" ng-click="coinbase.openAuthenticateWindow()">Connect Coinbase Account</button>
        <button class="button button-standard button-secondary" ng-click="coinbase.openSignupWindow()">Sign Up for Coinbase</button>
      </div>

      <div ng-show="showOauthForm" class="integration-onboarding-oauthform">
        <form name="oauthCodeForm" ng-submit="coinbase.submitOauthCode(code)" novalidate>
          <div class="list">
            <label class="item item-input item-floating-label">
              <span class="input-label">OAuth Code</span>
              <input type="text"
                     ng-model="code"
                     placeholder="{{'Enter OAuth Code'}}" required>
            </label>
          </div>
          <input
            class="button button-standard button-primary"
            type="submit" value="Connect Coinbase Account" ng-disabled="oauthCodeForm.$invalid">
          <button type="button" class="button button-standard button-secondary" ng-click="coinbase.openSupportWindow()">Coinbase Support &rarr;</button>
        </form>
      </div>
    </div>
  </ion-content>

  <ion-content class="ng-hide" ng-show="accessToken">

  <div>

    <div class="m20t text-center" ng-click="updateTransactions()">
      <img src="img/coinbase-logo.png" width="200">
    </div>

    <div class="list card">
      <a class="item item-icon-right"
         href ui-sref="tabs.buyandsell.coinbase.amount({nextStep: 'tabs.buyandsell.coinbase.buy', currency: currency})">
        <img src="img/buy-bitcoin.svg" alt="buy bitcoin" width="30" class="item-img-buy" style="vertical-align:
        text-bottom;">
        Buy Bitcoin
        <span class="item-note">
          <ion-spinner class="spinner-dark recent" icon="crescent" ng-show="!buyPrice"></ion-spinner>
          <span ng-show="buyPrice">{{buyPrice.amount|currency:'$':2}} {{buyPrice.currency}}/BTC</span>
        </span>
        <i class="icon bp-arrow-right"></i>
      </a>
      <a class="item item-icon-right"
         href ui-sref="tabs.buyandsell.coinbase.amount({nextStep: 'tabs.buyandsell.coinbase.sell', currency: currency})" no-low-fee>
        <img src="img/sell-bitcoin.svg" alt="sell bitcoin" width="30" class="item-img-sell" style="vertical-align:
        text-bottom;">
        Sell Bitcoin
        <span class="item-note">
          <ion-spinner class="spinner-dark recent" icon="crescent" ng-show="!sellPrice"></ion-spinner>
          <span ng-show="sellPrice">{{sellPrice.amount|currency:'$':2}} {{sellPrice.currency}}/BTC</span>
        </span>
        <i class="icon bp-arrow-right"></i>
      </a>
    </div>

    <div class="list card">
      <div class="item item-heading" ng-click="updateTransactions()">
        Activity
      </div>
      <a class="item"
         ng-if="pendingTransactions.data && !error"
         ng-repeat="(id, tx) in pendingTransactions.data | orderObjectBy:'updated_at':true track by $index"
         ng-click="coinbase.openTxModal(tx)">

        <span class="item-note">
          <div class="assertive" ng-show="tx.error || tx.status == 'error'">
            Error
          </div>
          <div ng-show="!tx.error">
            <div ng-show="tx.status == 'completed'">
              <time ng-if="tx.created_at">{{tx.created_at | amTimeAgo}}</time>
            </div>
            <div ng-show="tx.status == 'pending'">
              <span ng-if="tx.status == 'pending'">Pending</span>
            </div>
          </div>
        </span>

        <img class="left m10r" src="img/bought-pending.svg" alt="bought" width="24" ng-show="(tx.type == 'buy' || (tx.to && tx.type == 'send')) && tx.status != 'completed'">
        <img class="left m10r" src="img/bought.svg" alt="bought" width="30" ng-show="(tx.type == 'buy' || (tx.to && tx.type == 'send')) && tx.status == 'completed'">
        <img class="left m10r" src="img/sold-pending.svg" alt="sold" width="24" ng-show="tx.from && tx.type == 'send'">
        <img class="left m10r" src="img/sold.svg" alt="sold" width="30" ng-show="!tx.from && tx.type == 'sell' && tx.status == 'completed'">

        <h2>
          <span ng-show="tx.type == 'sell' && tx.status == 'completed'">Sold</span>
          <span ng-show="tx.type == 'send' && tx.to && tx.status == 'completed'">Bought</span>
        </h2>
        <p>
          <span ng-if="tx.type == 'sell' || (tx.type == 'send' && tx.from)">-</span>{{tx.amount.amount.replace('-','')}}
          {{tx.amount.currency}}
        </p>
      </a>
    </div>

  </div>
  </ion-content>
</ion-view>
