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('site')
    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.promo') }")
      a(ui-sref='options.settings.promo')
        =env.t('promoCode')
    li(ng-class="{ active: $state.includes('options.settings.subscription') }")
      a(ui-sref='options.settings.subscription')=env.t('subscription')
    li(ng-class="{ active: $state.includes('options.settings.notifications') }")
      a(ui-sref='options.settings.notifications')=env.t('notifications')

  .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 availableLanguages', ng-change='changeLanguage()')
              small
                !=env.t('americanEnglishGovern')
                br
                strong
                  !=env.t('helpWithTranslation')

            hr

            .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})')

            hr

            .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')
            .checkbox(ng-if='party.memberCount === 1')
              label
                input(type='checkbox', ng-model='user.preferences.displayInviteToPartyWhenPartyIs1', ng-change='set({"preferences.displayInviteToPartyWhenPartyIs1": user.preferences.displayInviteToPartyWhenPartyIs1 ? true : false})')
                span.hint(popover-trigger='mouseenter', popover-placement='right', popover=env.t('displayInviteToPartyWhenPartyIs1'))=env.t('displayInviteToPartyWhenPartyIs1')
            .checkbox
              label=env.t('suppressLevelUpModal')
                input(type='checkbox', ng-model='user.preferences.suppressModals.levelUp', ng-change='set({"preferences.suppressModals.levelUp": user.preferences.suppressModals.levelUp?true: false})')
            .checkbox
              label=env.t('suppressHatchPetModal')
                input(type='checkbox', ng-model='user.preferences.suppressModals.hatchPet', ng-change='set({"preferences.suppressModals.hatchPet": user.preferences.suppressModals.hatchPet?true: false})')
            .checkbox
              label=env.t('suppressRaisePetModal')
                input(type='checkbox', ng-model='user.preferences.suppressModals.raisePet', ng-change='set({"preferences.suppressModals.raisePet": user.preferences.suppressModals.raisePet?true: false})')
            .checkbox
              label=env.t('suppressStreakModal')
                input(type='checkbox', ng-model='user.preferences.suppressModals.streak', ng-change='set({"preferences.suppressModals.streak": user.preferences.suppressModals.streak?true: false})')

            hr

            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-if='user.preferences.disableClasses==true', ng-click='User.changeClass({})', popover-trigger='mouseenter', popover-placement='right', popover=env.t('enableClassPop'))= env.t('enableClass')

            hr

            h5=env.t('customDayStart')
            alert.alert-warning=env.t('customDayStartInfo1')

            .form-horizontal
              .form-group
                .col-sm-7
                  select.form-control(ng-model='dayStart')
                    - var number = 0
                    while number < 24
                      - var value = number
                      - var meridian = number < 12 ? 'AM' : 'PM'
                      - var hour = number++ % 12
                      option(value=value) #{hour ? hour : 12}:00 #{meridian}

                .col-sm-5
                  br.visible-xs
                  button.btn.btn-block.btn-primary(ng-click='openDayStartModal(dayStart)',
                    ng-disabled='dayStart == user.preferences.dayStart')
                    =env.t('saveCustomDayStart')

            hr

            h5=env.t('timezone')
            .form-horizontal
              .form-group
                .col-sm-12
                  p!=env.t('timezoneUTC', {utc: "{{ user.preferences.timezoneOffset | timezoneOffsetToUtc }}"})
                  br
                  p!=env.t('timezoneInfo')

      .personal-options.col-md-6
        .panel.panel-default
          .panel-heading
            span=env.t('registration')
          .panel-body
            div(ng-if='user.auth.facebook.id')
              button.btn.btn-primary(disabled='disabled', ng-if='!user.auth.local.username')=env.t('registeredWithFb')
              button.btn.btn-danger(ng-click='http("delete", "/api/v3/user/auth/social/facebook", null, "detachedFacebook")', ng-if='user.auth.local.username')=env.t('detachFacebook')
              hr
              div(ng-if='!user.auth.local.username')
                p=env.t('addLocalAuth')
                form(ng-submit='http("post", "/api/v3/user/auth/local/register", localAuth, "addedLocalAuth")', ng-init='localAuth={}', name='localAuth', novalidate)
                  //-.alert.alert-danger(ng-messages='changeUsername.$error && changeUsername.submitted')=env.t('fillAll')
                  .form-group
                    input.form-control(type='text', placeholder=env.t('username'), ng-model='localAuth.username', required)
                  .form-group
                    input.form-control(type='text', placeholder=env.t('email'), ng-model='localAuth.email', required)
                  .form-group
                    input.form-control(type='password', placeholder=env.t('password'), ng-model='localAuth.password', required)
                  .form-group
                    input.form-control(type='password', placeholder=env.t('confirmPass'), ng-model='localAuth.confirmPassword', required)
                  input.btn.btn-default(type='submit', ng-disabled='localAuth.$invalid', value=env.t('submit'))

            div(ng-if='user.auth.local.username')
              p=env.t('username')
                |: {{user.auth.local.username}}
              p
                small.muted
                    =env.t('loginNameDescription1')
                    |&nbsp;
                    a(href='/#/options/profile/profile')=env.t('loginNameDescription2')
                    |&nbsp;
                    =env.t('loginNameDescription3')
              p=env.t('email')
                |: {{user.auth.local.email}}
              hr

              h5=env.t('changeUsername')
              form(ng-submit='changeUser("username", usernameUpdates)', ng-init='usernameUpdates={}', ng-show='user.auth.local', name='changeUsername', novalidate)
                //-.alert.alert-danger(ng-messages='changeUsername.$error && changeUsername.submitted')=env.t('fillAll')
                .form-group
                  input.form-control(type='text', placeholder=env.t('newUsername'), ng-model='usernameUpdates.username', required)
                .form-group
                  input.form-control(type='password', placeholder=env.t('password'), ng-model='usernameUpdates.password', required)
                input.btn.btn-default(type='submit', ng-disabled='changeUsername.$invalid', value=env.t('submit'))

              h5=env.t('changeEmail')
              form(ng-submit='changeUser("email", emailUpdates)', ng-show='user.auth.local', name='changeEmail', novalidate)
                .form-group
                  input.form-control(type='text', placeholder=env.t('newEmail'), ng-model='emailUpdates.newEmail', required)
                .form-group
                  input.form-control(type='password', placeholder=env.t('password'), ng-model='emailUpdates.password', required)
                input.btn.btn-default(type='submit', ng-disabled='changeEmail.$invalid', value=env.t('submit'))

              h5=env.t('changePass')
              form(ng-submit='changeUser("password", passwordUpdates)', ng-show='user.auth.local', name='changePassword', novalidate)
                .form-group
                  input.form-control(type='password', placeholder=env.t('oldPass'), ng-model='passwordUpdates.password', required)
                .form-group
                  input.form-control(type='password', placeholder=env.t('newPass'), ng-model='passwordUpdates.newPassword', required)
                .form-group
                  input.form-control(type='password', placeholder=env.t('confirmPass'), ng-model='passwordUpdates.confirmPassword', required)
                input.btn.btn-default(type='submit', ng-disabled='changePassword.$invalid', 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.promo.html')
  .container-fluid
    .row
      .col-md-6
        h2=env.t('promoCode')
        form.form-inline(role='form',ng-submit='enterCoupon(_couponCode)')
          input.form-control(type='text', ng-model='_couponCode', placeholder=env.t('promoPlaceholder'))
          button.btn.btn-primary(type='submit')= env.t('submit')
        div
          small= env.t('couponText')
        div(ng-if='user.contributor.sudo')
          hr
          h4=env.t('generateCodes')
          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')=env.t('generate')
              a.btn.btn-default(href='/api/v3/coupons?_id={{user._id}}&apiToken={{User.settings.auth.apiToken}}')=env.t('getCodes')

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.settings.auth.apiToken}}
        h6=env.t('qrCode')
        img.img-rendering-auto(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.settings.auth.apiToken}}%22%7D&choe=UTF-8&chld=L', alt='qrcode')
        br
        h3=env.t('thirdPartyApps')
        ul
          li
            a(target='_blank' href='https://www.beeminder.com/habitica')=env.t('beeminder')
            br
            =env.t('beeminderDesc')
          li
            a(target='_blank' href='https://chrome.google.com/webstore/detail/habitrpg-chat-client/hidkdfgonpoaiannijofifhjidbnilbb')=env.t('chromeChatExtension')
            br
            =env.t('chromeChatExtensionDesc')
          li
            a(target='_blank' ng-href='http://data.habitrpg.com?uuid={{user._id}}')=env.t('dataTool')
            br
            =env.t('dataToolDesc')
          li
            !=env.t('otherExtensions')
            br
            =env.t('otherDesc')

        hr

        h2=env.t('webhooks')
        table.table.table-striped
          thead(ng-if='hasWebhooks')
            tr
              th=env.t('enabled')
              th=env.t('webhookURL')
              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=env.t('webhookURL'))
                  .col-sm-2
                    button.btn.btn-sm.btn-primary(type='submit')=env.t('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()
  ul
    li
      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"')=env.t('buyGemsGoldCap', {amount: '{{gemGoldCap(_subscription) | min }}'})
    li
      span.hint(popover=env.t('retainHistoryText'),popover-trigger='mouseenter',popover-placement='right')=env.t('retainHistory')
    li
      span.hint(popover=env.t('doubleDropsText'),popover-trigger='mouseenter',popover-placement='right')=env.t('doubleDrops')
    li
      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=env.t('mysticHourglass', {amount: '+{{numberOfMysticHourglasses(_subscription)}}'})
        .small.muted=env.t('mysticHourglassText')
    li
      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.notifications.html', type="text/ng-template")
  .container-fluid
    .row
      .personal-options.col-md-6
        .panel.panel-default
          .panel-heading
            =env.t('emailNotifications')
          .panel-body

            each notification in ['newPM', 'wonChallenge', 'giftedGems', 'giftedSubscription', 'invitedParty', 'invitedGuild', 'kickedGroup', 'questStarted', 'invitedQuest', 'importantAnnouncements', 'weeklyRecaps']
              -var preference = 'user.preferences.emailNotifications.' + notification
              -var unsubscribeFromAll = 'user.preferences.emailNotifications.unsubscribeFromAll'

              .checkbox: label
                input(type='checkbox', ng-model='#{preference}',
                  ng-disabled='#{unsubscribeFromAll} === true',
                  ng-checked='#{unsubscribeFromAll} === false && #{preference} === true',
                  ng-change='set({"preferences.emailNotifications.#{notification}": #{preference} ? true: false})')
                span=env.t(notification)

            hr

            .checkbox
              label
                input(type='checkbox', ng-model='user.preferences.emailNotifications.unsubscribeFromAll', ng-change='set({"preferences.emailNotifications.unsubscribeFromAll": user.preferences.emailNotifications.unsubscribeFromAll ? true: false})')
                span=env.t('unsubscribeAllEmails')

            small=env.t('unsubscribeAllEmailsText')

script(id='partials/options.settings.subscription.html',type='text/ng-template')
  //-h2=env.t('individualSub')
  .container-fluid(ng-init='_subscription={key:"basic_earned"}')
    h3= env.t('benefits')
    .row
      .col-md-6
        +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
            span.noninteractive-button.btn-danger=env.t('canceledSubscription')
            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')=env.t('purchasedPlanId', {price: '{{Content.subscriptionBlocks[user.purchased.plan.planId].price}}', months: '{{Content.subscriptionBlocks[user.purchased.plan.planId].months}}', plan: '{{user.purchased.plan.paymentMethod}}'})
          tr(ng-if='user.purchased.plan.extraMonths'): td
            span.glyphicon.glyphicon-credit-card
            | &nbsp;#{env.t('purchasedPlanExtraMonths', {months: '{{user.purchased.plan.extraMonths | number:2}}'})}
          tr(ng-if='user.purchased.plan.consecutive.count || user.purchased.plan.consecutive.offset'): td
            span.glyphicon.glyphicon-forward
            | &nbsp;#{env.t('consecutiveSubscription')}
            ul.list-unstyled
              li #{env.t('consecutiveMonths')} {{user.purchased.plan.consecutive.count + user.purchased.plan.consecutive.offset}}
              li #{env.t('gemCapExtra')} {{user.purchased.plan.consecutive.gemCapExtra}}
              li #{env.t('mysticHourglasses')} {{user.purchased.plan.consecutive.trinkets}}
        div(ng-if='!user.purchased.plan.customerId || (user.purchased.plan.customerId && user.purchased.plan.dateTerminated)')
          h4(ng-if='(user.purchased.plan.customerId && user.purchased.plan.dateTerminated)')= env.t("resubscribe")
          .form-group.reduce-top-margin
            .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')
                  span.label.label-success.line-through
                    | ${{:: block.original }}
                  =env.t('subscriptionRateText', {price:'{{::block.price}}', months: '{{::block.months}}'})
                span(ng-hide='block.original')
                  =env.t('subscriptionRateText', {price: '{{::block.price}}', months: '{{block.months}}'})

          .form-inline
            .form-group
              input.form-control(type='text', ng-model='_subscription.coupon', placeholder= env.t('couponPlaceholder'))
            .form-group
              button.pull-right.btn.btn-small(type='button',ng-click='applyCoupon(_subscription.coupon)')= env.t("apply")

        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')

      .container-fluid.slight-vertical-padding(ng-if='!user.purchased.plan.customerId || (user.purchased.plan.customerId && user.purchased.plan.dateTerminated)')
        small.muted=env.t('subscribeUsing')
        .row.text-center
          .col-xs-4
            a.purchase.btn.btn-primary(ng-click='Payments.showStripe({subscription:_subscription.key, coupon:_subscription.coupon})', ng-disabled='!_subscription.key')= env.t('card')
          .col-xs-4
            a.purchase(href='/paypal/subscribe?_id={{user._id}}&apiToken={{User.settings.auth.apiToken}}&sub={{_subscription.key}}{{_subscription.coupon ? "&coupon="+_subscription.coupon : ""}}', ng-disabled='!_subscription.key')
              img(src='https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-small.png',alt=env.t('paypal'))
          .col-xs-4
            a.purchase(ng-click="Payments.amazonPayments.init({type: 'subscription', subscription:_subscription.key, coupon:_subscription.coupon})")
              img(src='https://payments.amazon.com/gp/cba/button',alt=env.t('amazonPayments'))
