script(id='partials/options.settings.html', type="text/ng-template")
  ul.options-menu
    li(ng-class="{ active: $state.includes('options.settings.settings') }")
      a(ui-sref='options.settings.settings')
        =env.t('settings')
    li(ng-class="{ active: $state.includes('options.settings.api') }")
      a(ui-sref='options.settings.api')
        =env.t('API')
    li(ng-class="{ active: $state.includes('options.settings.export') }")
      a(ui-sref='options.settings.export')
        =env.t('dataExport')
    li(ng-class="{ active: $state.includes('options.settings.coupon') }")
      a(ui-sref='options.settings.coupon')
        | Coupon
    li(ng-class="{ active: $state.includes('options.settings.subscription') }")
      a(ui-sref='options.settings.subscription')=env.t('subscription')

  .tab-content
    .tab-pane.active
      div(ui-view)

script(type='text/ng-template', id='partials/options.settings.settings.html')
  .container-fluid
    .row
      .personal-options.col-md-6
        .panel.panel-default
          .panel-heading
            =env.t('settings')
          .panel-body

            .form-horizontal
              h5=env.t('language')
              select.form-control(ng-model='language.code', ng-options='lang.code as lang.name for lang in avalaibleLanguages', ng-change='changeLanguage()')
              small 
                !=env.t('americanEnglishGovern')
                br
                strong
                  !=env.t('helpWithTranslation')
                  
            .form-horizontal
              h5=env.t('dateFormat')
              select.form-control(ng-model='user.preferences.dateFormat', ng-options='DF for DF in availableFormats', ng-change='set({"preferences.dateFormat": user.preferences.dateFormat})')                  
            .checkbox
              label
                input(type='checkbox', ng-click='hideHeader() ', ng-checked='user.preferences.hideHeader!==true')
                span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('showHeaderPop'))=env.t('showHeader')
            .checkbox
              label
                input(type='checkbox', ng-click='toggleStickyHeader()', ng-checked='user.preferences.stickyHeader!==false', ng-disabled="user.preferences.hideHeader!==false")
                span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('stickyHeaderPop'))=env.t('stickyHeader')
            .checkbox
              label
                input(type='checkbox', ng-model='user.preferences.newTaskEdit', ng-change='set({"preferences.newTaskEdit": user.preferences.newTaskEdit?true: false})')
                span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('newTaskEditPop'))=env.t('newTaskEdit')
            .checkbox
              label
                input(type='checkbox', ng-model='user.preferences.tagsCollapsed', ng-change='set({"preferences.tagsCollapsed": user.preferences.tagsCollapsed?true: false})')
                span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('startCollapsedPop'))=env.t('startCollapsed')
            .checkbox
              label
                input(type='checkbox', ng-model='user.preferences.advancedCollapsed', ng-change='set({"preferences.advancedCollapsed": user.preferences.advancedCollapsed?true: false})')
                span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('startAdvCollapsedPop'))=env.t('startAdvCollapsed')
            .checkbox
              label
                input(type='checkbox', ng-model='user.preferences.dailyDueDefaultView', ng-change='set({"preferences.dailyDueDefaultView": user.preferences.dailyDueDefaultView?true: false})')
                span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('dailyDueDefaultViewPop'))=env.t('dailyDueDefaultView')
            button.btn.btn-default(ng-click='showTour()', popover-placement='right', popover-trigger='mouseenter', popover=env.t('restartTour'))= env.t('showTour')
            button.btn.btn-default(ng-click='showBailey()', popover-trigger='mouseenter', popover-placement='right', popover=env.t('showBaileyPop'))= env.t('showBailey')
            button.btn.btn-default(ng-click='openRestoreModal()', popover-trigger='mouseenter', popover-placement='right', popover=env.t('fixValPop'))= env.t('fixVal')
            button.btn.btn-default(ng-click="openModal('invite-friends', {controller:'GroupsCtrl'})") Invite Friends
            button.btn.btn-default(ng-if='user.preferences.disableClasses==true', ng-click='user.ops.changeClass({})', popover-trigger='mouseenter', popover-placement='right', popover=env.t('enableClassPop'))= env.t('enableClass')
            button.btn.btn-default(ng-if='!user.preferences.disableClasses && user.flags.classSelected', ng-click='showClassesTour()', popover-trigger='mouseenter', popover-placement='right', popover=env.t('classTourPop'))= env.t('showClass')

            div.alert.alert-warning(style='padding:2px;margin-top:7px')
              h5.hint(popover=env.t('clockInfo'), popover-trigger='mouseenter')=env.t('customDayStart')
              .form-group
                .input-group
                  input.form-control(type='number', min='0', max='23', ng-model='user.preferences.dayStart', ng-change='saveDayStart()')
                  span.input-group-addon= ':00 (' + env.t('24HrClock') + ')'
              small
                  =env.t('subWarning1')
                  |&nbsp;
                  a(href='https://github.com/HabitRPG/habitrpg/issues/1057' target='_blank')=env.t('subWarning2')
                  |&nbsp;
                  =env.t('subWarning3')

        .panel.panel-default
          .panel-heading
            span Registration
          .panel-body
            p(ng-if='user.auth.facebook.id') Registered with Facebook
            div(ng-if='user.auth.local.username')
              p Username: {{user.auth.local.username}}
              p Email: {{user.auth.local.email}}
              hr
              h5=env.t('changeUsername')
              form(ng-submit='changeUsername(changeUser)', ng-show='user.auth.local')
                .form-group
                  input.form-control(type='text', placeholder=env.t('newUsername'), ng-model='changeUser.newUsername', required)
                .form-group
                  input.form-control(type='password', placeholder=env.t('password'), ng-model='changeUser.password', required)
                input.btn.btn-default(type='submit', value=env.t('submit'))
              h5=env.t('changePass')
              form(ng-submit='changePassword(changePass)', ng-show='user.auth.local')
                .form-group
                  input.form-control(type='password', placeholder=env.t('oldPass'), ng-model='changePass.oldPassword', required)
                .form-group
                  input.form-control(type='password', placeholder=env.t('newPass'), ng-model='changePass.newPassword', required)
                .form-group
                  input.form-control(type='password', placeholder=env.t('confirmPass'), ng-model='changePass.confirmNewPassword', required)
                input.btn.btn-default(type='submit', value=env.t('submit'))


        .panel.panel-default
          .panel-heading
            span=env.t('dangerZone')
          .panel-body
            a.btn.btn-danger(ng-click='openModal("reset", {controller:"SettingsCtrl"})', popover-trigger='mouseenter', popover-placement='right', popover=env.t('resetAccPop'))= env.t('resetAccount')
            a.btn.btn-danger(ng-click='openModal("delete", {controller:"SettingsCtrl"})', popover-trigger='mouseenter', popover=env.t('deleteAccPop'))= env.t('deleteAccount')

script(type='text/ng-template', id='partials/options.settings.coupon.html')
  .container-fluid
    .row
      .col-md-6
        h2 Coupon
        form.form-inline(role='form',ng-submit='enterCoupon(_couponCode)')
          input.form-control(type='text', ng-model='_couponCode', placeholder='Enter Coupon Code')
          button.btn.btn-primary(type='submit') Submit
        div
          small We sometimes have events and give out coupon codes for special gear. (eg, those who stop by our Wondercon booth)
        div(ng-if='user.contributor.sudo')
          hr
          h4 Generate Codes
          form.form(role='form',ng-submit='generateCodes(_codes)',ng-init='_codes={}')
            .form-group
              input.form-control(type='text',ng-model='_codes.event',placeholder="Event code (eg, 'wondercon')")
            .form-group
              input.form-control(type='number',ng-model='_codes.count',placeholder="Number of codes to generate (eg, 250)")
            .form-group
              button.btn.btn-primary(type='submit') Generate
              a.btn.btn-default(href='/api/v2/coupons?_id={{user._id}}&apiToken={{user.apiToken}}') Get Codes



script(type='text/ng-template', id='partials/options.settings.api.html')
  .container-fluid
    .row
      .col-md-6
        h2=env.t('API')
        small=env.t('APIText')
        h6=env.t('userId')
        pre.prettyprint {{user.id}}
        h6=env.t('APIToken')
        pre.prettyprint {{user.apiToken}}
        h6=env.t('qrCode')
        img(src='https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=%7B%22address%22%3A%22https%3A%2F%2Fhabitrpg.com%22%2C%22user%22%3A%22{{user.id}}%22%2C%22key%22%3A%22{{user.apiToken}}%22%7D&choe=UTF-8&chld=L', alt='qrcode')

        hr

        h2 Webhooks
        table.table.table-striped
          thead(ng-if='hasWebhooks')
            tr
              th Enabled
              th Webhook URL
              th
          tbody
            tr(ng-repeat="webhook in user.preferences.webhooks | toArray:true | orderBy:'sort'")
              td
                input(type='checkbox', ng-model='webhook.enabled', ng-change='saveWebhook(webhook.$key,webhook)')
              td
                input.form-control(type='url', ng-model='webhook.url', ng-change='webhook._editing=true', ui-keyup="{13:'saveWebhook(webhook.$key,webhook)'}")
              td
                span.pull-left(ng-show='webhook._editing') *
                a.checklist-icons(ng-click='deleteWebhook(webhook.$key)')
                  span.glyphicon.glyphicon-trash(tooltip=env.t('delete'))
            tr
              td(colspan=2)
                form.form-horizontal(ng-submit='addWebhook(_newWebhook.url)')
                  .form-group.col-sm-10
                    input.form-control(type='url', ng-model='_newWebhook.url', placeholder='Webhook URL')
                  .col-sm-2
                    button.btn.btn-sm.btn-primary(type='submit') Add

script(id='partials/options.settings.export.html', type="text/ng-template")
  .container-fluid
    .row
      .col-md-6
        h2=env.t('dataExport')
        small=env.t('saveData')
        h4=env.t('habitHistory')
        =env.t('exportHistory')
        a(href="/export/history.csv")= ' ' + env.t('csv')
        h4=env.t('userData')
        =env.t('exportUserData')
        a(href="/export/userdata.xml")= ' ' + env.t('xml') + ' '
        a(href="/export/userdata.json")= env.t('json')

mixin subPerks()
  table.table.table-striped
    tr
      td
        span.hint(popover=env.t('disableAdsText'),popover-trigger='mouseenter',popover-placement='right')=env.t('disableAds')
    tr
      td
        span.hint(popover=env.t('buyGemsGoldText', {gemCost: "{{Shared.planGemLimits.convRate}}", gemLimit: "{{Shared.planGemLimits.convCap}}"}),popover-trigger='mouseenter',popover-placement='right') #{env.t('buyGemsGold')}&nbsp;
        span.badge.badge-success(ng-show='_subscription.key!="basic_earned"') Cap raised to {{ [25 + user.purchased.plan.consecutive.gemCapExtra + Math.floor(Content.subscriptionBlocks[_subscription.key].months/3*5), 50]  | min }}
    tr
      td
        span.hint(popover=env.t('retainHistoryText'),popover-trigger='mouseenter',popover-placement='right')=env.t('retainHistory')
    tr
      td
        span.hint(popover=env.t('doubleDropsText'),popover-trigger='mouseenter',popover-placement='right')=env.t('doubleDrops')
    tr
      td
        span.hint(popover=env.t('mysteryItemText'),popover-trigger='mouseenter',popover-placement='right') #{env.t('mysteryItem')}&nbsp;
        div(ng-show='_subscription.key!="basic_earned"')
          .badge.badge-success +{{Math.floor(Content.subscriptionBlocks[_subscription.key].months/3)}} Mystic Hourglass
          .small.muted Mystic Hourglasses allow purchasing a previous month's Mystery Item set.
    tr
      td
        span.hint(popover=env.t('supportDevsText'),popover-trigger='mouseenter',popover-placement='right')=env.t('supportDevs')

script(id='partials/feature-matrix-check.html',type='text/ng-template')
  span.task-checker.action-yesno
    input.focusable(type='checkbox', checked)
    label

script(id='partials/options.settings.subscription.html',type='text/ng-template')
  //-h2=env.t('individualSub')
  .container-fluid(ng-init='_subscription={key:"basic_earned"}')
    .row
      .col-md-6
        h3 Benefits
        +subPerks()

      .col-md-6
        table.table.alert.alert-info(ng-if='user.purchased.plan.customerId')
          tr(ng-if='user.purchased.plan.dateTerminated'): td.alert.alert-warning
            i.glyphicon.glyphicon-time
            |  #{env.t('subCanceled')} <strong>{{moment(user.purchased.plan.dateTerminated).format('MM/DD/YYYY')}}</strong>
          tr(ng-if='!user.purchased.plan.dateTerminated'): td
            h4=env.t('subscribed')
            p(ng-if='user.purchased.plan.planId') Recurring ${{Content.subscriptionBlocks[user.purchased.plan.planId].price}} each {{Content.subscriptionBlocks[user.purchased.plan.planId].months}} Month(s) ({{user.purchased.plan.paymentMethod}})
          tr(ng-if='user.purchased.plan.extraMonths'): td
            span.glyphicon.glyphicon-credit-card
            |  You have {{user.purchased.plan.extraMonths | number:2}} months of subscription credit.
          tr(ng-if='user.purchased.plan.consecutive.count || user.purchased.plan.consecutive.offset'): td
            span.glyphicon.glyphicon-forward
            | &nbsp;Consecutive Subscription
            ul.list-unstyled
              li Consecutive Months: {{user.purchased.plan.consecutive.count + user.purchased.plan.consecutive.offset}}
              li Gem Cap Extra: {{user.purchased.plan.consecutive.gemCapExtra}}
              li Mystic Hourglasses: {{user.purchased.plan.consecutive.trinkets}}
        div(ng-if='!user.purchased.plan.customerId || (user.purchased.plan.customerId && user.purchased.plan.dateTerminated)')
          .form-group
            .radio(ng-repeat='block in Content.subscriptionBlocks | toArray | omit:"discount==true" | orderBy:"months"')
              label
                input(type="radio", name="subRadio", ng-value="block.key", ng-model='_subscription.key')
                span(ng-show='block.original')
                  | Recurring <span class='line-through'>${{block.original}}</span> <span class='label label-success'>${{block.price}}</span> each {{block.months}} Month(s)
                span(ng-hide='block.original')
                  | Recurring ${{block.price}} each {{block.months}} Month(s)

          .form-inline
            .form-group
              input.form-control(type='text', ng-model='_subscription.coupon', placeholder='Promo Code')
            .form-group
              button.btn.btn-small(type='button',ng-click='applyCoupon(_subscription.coupon)') Apply

          h3(ng-if='(user.purchased.plan.customerId && user.purchased.plan.dateTerminated)') Resubscribe
          a.btn.btn-primary(ng-click='Payments.showStripe({subscription:_subscription.key, coupon:_subscription.coupon})', ng-disabled='!_subscription.key') Card
          a.btn.btn-warning(href='/paypal/subscribe?_id={{user._id}}&apiToken={{user.apiToken}}&sub={{_subscription.key}}{{_subscription.coupon ? "&coupon="+_subscription.coupon : ""}}', ng-disabled='!_subscription.key') PayPal
        div(ng-if='user.purchased.plan.customerId')
          .btn.btn-primary(ng-if='!user.purchased.plan.dateTerminated && user.purchased.plan.paymentMethod=="Stripe"', ng-click='Payments.showStripeEdit()')=env.t('subUpdateCard')
          .btn.btn-sm.btn-danger(ng-if='!user.purchased.plan.dateTerminated', ng-click='Payments.cancelSubscription()')=env.t('cancelSub')
