<section>
  {{#unless isEnabled}}
    <div class="banner bg-warning">
      <div class="banner-icon">
        <span class="icon icon-alert"></span>
      </div>
      <div class="banner-message">
        <p>{{t 'authPage.azuread.header.disabled.label' htmlSafe=true}}</p>
      </div>
    </div>
  {{/unless}}
</section>


{{#accordion-list showExpandAll=false  as |al expandFn|}}

  {{#if isEnabled}}

    {{#accordion-list-item
         detail=(t 'authPage.azuread.configure.help')
         expand=(action expandFn)
         expandAll=al.expandAll
         expandOnInit=true
         expanded=true
         showExpand=false
         title=(t 'authPage.github.authenticated.header.text')
    }}

      <section class="">
        <div class="clearfix">
          <div class="pull-right">
            <button class="btn btn-sm bg-primary" {{action "edit"}}>
              {{t 'generic.edit'}}
            </button>
            <button class="btn btn-sm right-divider-btn bg-error" {{action "disable"}}>
              {{t 'authPage.azuread.enabled.promptDisable'}}
            </button>
          </div>
        </div>
        <hr/>
        <div class="row">
          <div class="col span-12">
            <h3>{{t 'authPage.azuread.enabled.general.header'}}</h3>
            <div>
              <b>{{t 'authPage.azuread.configure.tenantId.label'}}: </b> <span class="text-muted">{{authConfig.tenantId}}</span>
            </div>
            <div>
              <b>{{t 'authPage.azuread.configure.applicationId.label'}}: </b> <span class="text-muted">{{authConfig.applicationId}}</span>
            </div>
            <div>
              <b>{{t 'authPage.azuread.configure.azureADEndpoint.label'}}: </b> <span class="text-muted">{{authConfig.endpoint}}</span>
            </div>
            <div>
              <b>{{t 'authPage.azuread.configure.azureADGraphEndpoint.label'}}: </b> <span class="text-muted">{{authConfig.graphEndpoint}}</span>
            </div>
            <div>
              <b>{{t 'authPage.azuread.configure.azureADTokenEndpoint.label'}}: </b> <span class="text-muted">{{authConfig.tokenEndpoint}}</span>
            </div>
            <div>
              <b>{{t 'authPage.azuread.configure.azureADAuthEndpoint.label'}}: </b> <span class="text-muted">{{authConfig.authEndpoint}}</span>
            </div>
          </div>
        </div>
      </section>

    {{/accordion-list-item}}

  {{/if}}


  {{#if (or (not isEnabled) editing)}}
    {{#accordion-list-item
         classNames="mt-30"
         detail=(t 'authPage.azuread.configure.help')
         expand=(action expandFn)
         expandAll=al.expandAll
         expandOnInit=true
         expanded=true
         showExpand=false
         title=(t 'authPage.azuread.configure.header')
    }}

      <section>
        <form class="form" {{action "test" on="submit"}}>
          <div class="row">
            <p class="text-info">{{t 'authPage.azuread.configure.replyUrl' appName=settings.appName htmlSafe=true}} </p>
            <div class="col span-12">
              <label class="acc-label pb-5 mr-5">Reply URL:</label>
              <code>{{replyUrl}}</code> {{copy-to-clipboard class="ml-5" clipboardText=replyUrl size="md"}}
            </div>
            <div class="col span-6">
              <div class="inline-form">
                <label class="acc-label pb-5" for="tenant-id">{{t 'authPage.azuread.configure.tenantId.label'}}{{field-required}}</label>
                {{input id="tenant-id"  classNames="form-control" type="text" value=authConfig.tenantId placeholder=(t 'authPage.azuread.configure.tenantId.placeholder')}}
                <p class="help-block">{{t 'authPage.azuread.configure.tenantId.help'}}</p>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col span-6">
              <div class="inline-form">
                <label class="acc-label pb-5" for="application-id">{{t 'authPage.azuread.configure.applicationId.label'}}{{field-required}}</label>
                {{input id="application-id" type="text" value=authConfig.applicationId placeholder=(t 'authPage.azuread.configure.applicationId.placeholder') classNames="form-control"}}
              </div>
            </div>
            <div class="col span-6">
              <div class="inline-form">
                <label class="acc-label pb-5" for="application-secret">{{t 'authPage.azuread.configure.applicationSecret.label'}}{{field-required}}</label>
                {{input id="application-secret" type="password" value=authConfig.applicationSecret classNames="form-control"}}
              </div>
            </div>
          </div>
          {{#if authConfig}}
            {{azuread-endpoints isEnabled=isEnabled authConfig=authConfig}}
          {{/if}}
          <div class="row mt-10 text-center">
            <div class="btn-group">
              <button class="btn bg-primary" {{action "test"}}>
                {{#if testing}}
                  <i class="icon icon-spinner icon-spin"></i> {{t 'authPage.azuread.test.post'}}
                {{else}}
                  <i class="icon icon-azuread"></i> {{t 'authPage.azuread.test.pre'}}
                {{/if}}
              </button>
              <button {{action "cancel"}} class="btn bg-transparent">{{t 'saveCancel.cancel'}}</button>
            </div>
          </div>
        </form>
      </section>

    {{/accordion-list-item}}
    {{top-errors errors=errors}}
  {{/if}}

  {{#if isEnabled}}
    {{#accordion-list-item
         classNames="mt-30"
         detail=(t 'siteAccess.helpText' appName=settings.appName htmlSafe=true)
         expand=(action expandFn)
         expandAll=al.expandAll
         expandOnInit=true
         expanded=true
         showExpand=false
         title=(t 'siteAccess.header')
    }}

      {{site-access
          model=authConfig
          principals=model.principals
          collection='siteAccess.organizations'
      }}

    {{/accordion-list-item}}

  {{/if}}

{{/accordion-list}}