<ion-view>
  <ion-nav-bar class="bar-royal">
    <ion-nav-back-button>
    </ion-nav-back-button>
    <ion-nav-title>Sell</ion-nav-title>
  </ion-nav-bar>

  <ion-content>

    <div class="box-notification warning" ng-show="network == 'testnet'">
      Testnet wallets only work with Glidera Sandbox Accounts
    </div>

    <div class="box-notification notice" ng-show="limits && !sell.show2faCodeInput && !sell.success">
      <span class="text-light">Daily sell limit</span>:
      {{limits.dailySell|currency:'':2}} {{limits.currency}}
      (remaining {{limits.dailySellRemaining|currency:'':2}} {{limits.currency}})
      <br>
      <span class="text-light">Monthly sell limit</span>:
      {{limits.monthlySell|currency:'':2}} {{limits.currency}}
      (remaining {{limits.monthlySellRemaining|currency:'':2}} {{limits.currency}})
    </div>

    <div class="box-notification m20b" ng-show="limits.transactDisabledPendingFirstTransaction">
      <span class="text-warning">
        This operation was disabled because you have a pending first transaction
      </span>
    </div>

    <div ng-show="!sell.show2faCodeInput && !sell.success">
      <form name="sellPriceForm" ng-if="token"
        ng-submit="sell.get2faCode(token)" novalidate>

        <div class="list card">
          <label class="item item-input item-stacked-label">
            <span class="input-label"><span>Amount in</span> {{showAlternative ? 'USD' : 'BTC'}}</span>
            <input ng-show="!showAlternative"
                   type="number"
                   id="qty" ignore-mouse-wheel
                   name="qty"
                   ng-attr-placeholder="{{'Amount'}}"
                   ng-minlength="0.00000001"
                   ng-maxlength="10000000000"
                   ng-model="qty"
                   autocomplete="off"
                   ng-change="sell.getSellPrice(token, {'qty': qty})">

            <input ng-show="showAlternative"
                   type="number"
                   id="fiat" ignore-mouse-wheel
                   name="fiat"
                   ng-attr-placeholder="{{'Amount'}}"
                   ng-model="fiat"
                   autocomplete="off"
                   ng-change="sell.getSellPrice(token, {'fiat': fiat})">

            <a ng-show="!showAlternative"
               class="postfix"
               on-tap="showAlternative = true; qty = null; sell.sellPrice = null">BTC</a>
            <a ng-show="showAlternative"
               class="postfix"
               on-tap="showAlternative = false; fiat = null; sell.sellPrice = null">USD</a>
          </label>
        </div>

        <wallets ng-if="wallets[0]" wallets="wallets"></wallets>

        <div class="text-center text-gray size-12 m20v" ng-show="!sell.gettingSellPrice && sell.sellPrice.qty">
          Sell
          <span ng-show="qty">{{sell.sellPrice.subtotal|currency:'':2}} {{sell.sellPrice.currency}} in Bitcoin</span>
          <span ng-show="fiat">{{sell.sellPrice.qty}} BTC</span>
          at {{sell.sellPrice.price|currency:'':2}} {{sell.sellPrice.currency}}/BTC

        </div>
        <div class="text-center text-gray size-12 m20b" ng-show="!sell.gettingSellPrice && !sell.sellPrice.qty">
          (Enter the amount to get the exchange rate)
        </div>

        <div class="text-center text-gray size-12 m20b" ng-show="sell.gettingSellPrice">
          ...
        </div>

        <button class="button button-standard button-primary"
                type="submit"
                ng-disabled="limits.transactDisabledPendingFirstTransaction || !sell.sellPrice.qty">
          Continue
        </button>
      </form>
    </div>
    <div ng-show="sell.show2faCodeInput && !sell.success">
      <div class="m10t text-center">
{{sell.sellPrice.qty}} BTC &rarr; {{sell.sellPrice.subtotal|currency:'':2}} {{sell.sellPrice.currency}}
        <p class="m20t">
          A SMS containing a confirmation code was sent to your phone. <br>
          Please, enter the code below
        </p>
        <form name="sellForm"
              ng-submit="sell.createTx(token, permissions, twoFaCode)" novalidate>
          <div class="list card">
            <label class="item item-input">
              <input type="number" ng-model="twoFaCode" placeholder="2FA Code" required ignore-mouse-wheel>
            </label>
          </div>
          <button class="button button-standard button-primary"
                  type="submit"
                  ng-disabled="sellForm.$invalid ">
            Sell
          </button>
        </form>
        <p class="m10t size-12 text-gray padding">
        Bitcoins will be immediately sent from your wallet to Glidera. Fiat will be deposited in your bank account in 4-6 business days.
        </p>
      </div>
    </div>
    <div class="text-center padding" ng-show="sell.success">
      <h1>Sale initiated</h1>
      <p class="text-gray">
      A transfer has been initiated to your bank account and should arrive in 4-6 business days.
      </p>

      <button class="button button-standard button-primary" ui-sref="tabs.buyandsell.glidera">OK</button>
    </div>
  </ion-content>
</ion-view>
