<ion-view id="coinbase" hide-tabs>
  <ion-nav-bar class="bar-royal">
    <ion-nav-back-button>
    </ion-nav-back-button>
    <ion-nav-title>Sell bitcoin</ion-nav-title>
  </ion-nav-bar>

  <ion-content class="add-bottom-for-cta">
    <!-- SELL -->
    <div class="list" ng-if="sellRequestInfo">

      <div class="item head">
        <div class="sending-label">
          <img src="img/sell-bitcoin.svg" alt="sell bitcoin" width="35" class="item-img-sell">
          <span>Selling</span>
        </div>
        <div class="amount-label">
          <div class="amount">{{amountUnitStr}}</div>
          <div class="alternative" ng-if="sellPrice">
            <span ng-show="isFiat">{{sellRequestInfo.amount.amount}} {{sellRequestInfo.amount.currency}}</span> 
            @ ${{sellPrice.amount}} per BTC
          </div>
        </div>
      </div> 

      <div class="info">

        <div class="item item-icon-right" ng-click="showWalletSelector()">
          <div class="label">From</div>
          <div class="wallet">
            <i class="icon big-icon-svg">
              <img src="img/icon-wallet.svg" ng-class="{'wallet-background-color-default': !wallet.color}" ng-style="{'background-color': wallet.color}" class="bg">
            </i>
            {{wallet ? wallet.name : '...'}}
          </div>
          <i class="icon bp-arrow-right"></i>
        </div>

        <label class="item item-input item-select">
          <div class="input-label">
            Deposit into
          </div>
          <select ng-model="selectedPaymentMethodId.value"
                  ng-options="item.id as item.name for item in paymentMethods"
                  ng-change="sellRequest()">
          </select>
        </label>

        <div class="item item-divider">
          At what percentage lower price would you accept to sell?
        </div>
        <label class="item item-input item-select" ng-if="priceSensitivity">
          <div class="input-label">Price Sensitivity</div>
          <select
                ng-model="selectedPriceSensitivity.data"
                ng-options="item as item.name for item in priceSensitivity track by item.value">
          </select>
        </label>
        <div class="item size-12" ng-if="selectedPriceSensitivity">
          <div class="m10b">
            Coinbase has not yet implemented an immediate method to sell bitcoin from a wallet. To make this sale, funds
            will be sent to your Coinbase account, and sold when Coinbase accepts the transaction (usually one
            hour).
          </div>
          <div class="label" ng-if="sellRequestInfo">Estimated sale value: 
            <strong>
            {{sellRequestInfo.total.amount | currency : '' : 2}} 
            {{sellRequestInfo.total.currency}}
            </strong>
          </div>
          <div class="label" ng-if="sellRequestInfo">Still sell if price fall until: 
            <strong>
            {{(sellRequestInfo.total.amount - 
            (selectedPriceSensitivity.data.value / 100) * sellRequestInfo.total.amount) | currency : '' : 2}} 
            {{sellRequestInfo.total.currency}}
            </strong>
          </div>
        </div>

        <div class="item item-divider">
          Transaction details
        </div>
        <div class="item">
          Amount
          <span class="item-note">
            {{sellRequestInfo.subtotal.amount}} {{sellRequestInfo.subtotal.currency}}
          </span>
        </div>
        <div class="item" ng-repeat="fee in sellRequestInfo.fees">
          <span class="capitalized">
            {{fee.type}} fee
          </span>
          <span class="item-note">
            <span ng-if="fee.amount.amount != '0.00'">-</span>
            {{fee.amount.amount}} {{fee.amount.currency}}
          </span>
        </div>
        <div class="item">
          Total to receive
          <span class="item-note total-amount">
            {{sellRequestInfo.total.amount}} {{sellRequestInfo.total.currency}}
          </span>
        </div>
      </div>
    </div>

  </ion-content>

  <click-to-accept
    ng-disabled="!selectedPaymentMethodId.value || !sellRequestInfo || !wallet"
    ng-click="sellConfirm()"
    ng-if="!isCordova && sellRequestInfo"
    click-send-status="sendStatus"
    has-wallet-chosen="wallet"
    insufficient-funds="!selectedPaymentMethodId.value"
    no-matching-wallet="!sellRequestInfo">
    Confirm sale
  </click-to-accept>
  <slide-to-accept
    ng-disabled="!selectedPaymentMethodId.value || !sellRequestInfo || !wallet"
    ng-if="isCordova && sellRequestInfo"
    slide-on-confirm="sellConfirm()"
    slide-send-status="sendStatus"
    has-wallet-chosen="wallet"
    insufficient-funds="!selectedPaymentMethodId.value"
    no-matching-wallet="!sellRequestInfo">
    Slide to sell
  </slide-to-accept>
  <slide-to-accept-success
    slide-success-show="sendStatus === 'success'"
    slide-success-on-confirm="goBackHome()"
    slide-success-hide-on-confirm="true">
    <span>Funds sent to Coinbase Account</span>
    <div class="m10 size-14">
      The transaction is not yet confirmed, and will show as "Pending" in your Activity. The bitcoin sale will be completed automatically once it is confirmed by Coinbase.
    </div>
  </slide-to-accept-success>

  <wallet-selector
    wallet-selector-title="walletSelectorTitle"
    wallet-selector-wallets="wallets"
    wallet-selector-selected-wallet="wallet"
    wallet-selector-show="showWallets"
    wallet-selector-on-select="onWalletSelect">
  </wallet-selector>
</ion-view>
