<section class="header clearfix">
  <div class="pull-left">
    <h2>
      {{t "namespacesPage.addNamespace"}}
    </h2>
  </div>
</section>

{{form-name-description
  model=model.namespace
}}
{{#if nameExists}}
  <p class="text-error text-small mt-0 mb-0">
    {{t "editStack.name.error"}}
  </p>
{{/if}}

<div class="row">
  {{#unless from}}
    <div class="col span-6">
      <label class="pt-20 pb-5 acc-label" for="input-project-select">
        {{t "editStack.project.label"}}
      </label>
      {{new-select
        id="input-project-select"
        classNames="form-control"
        optionValuePath="id"
        optionLabelPath="displayName"
        content=allProjects
        value=model.namespace.projectId
        prompt="editStack.project.prompt"
        localizedPrompt=true
      }}
    </div>
  {{/unless}}
  {{#if scope.currentCluster.istioEnabled}}
    <div class="col span-6">
      <label class="pt-20 pb-5 acc-label">
        {{t "editStack.autoInject.label"}}
      </label>
      <div class="mt-5">
        {{#if istioInjection}}
          <div class="btn-group no-inline-space">
            <div class="btn btn-link btn-sm bg-success">
              {{t "generic.enabled"}}
            </div>
            <div class="btn btn-link btn-sm bg-default" {{action "toggleAutoInject"}}>
              {{t 'generic.disable'}}
            </div>
          </div>
        {{else}}
          <div class="btn-group no-inline-space">
            <div class="btn btn-link btn-sm bg-default" {{action "toggleAutoInject"}}>
              {{t 'generic.enable'}}
            </div>
            <div class="btn btn-link btn-sm bg-primary">
              {{t 'generic.disabled'}}
            </div>
          </div>
        {{/if}}
      </div>
    </div>
  {{/if}}
</div>

<div class="row mt-20">
  {{#accordion-list showExpandAll=false as | al expandFn | }}
    {{#if (and primaryResource.project.resourceQuota (not switchingProject))}}
      {{#accordion-list-item
         title=(t "editStack.resourceQuota.title")
         detail=(t "editStack.resourceQuota.detail")
         expandAll=al.expandAll
         expand=(action expandFn)
         expandOnInit=true
      }}
        {{namespace-resource-quota
          editing=(or editing isNew)
          isNew=true
          expanded=expanded
          limit=primaryResource.resourceQuota.limit
          projectLimit=projectLimit
          usedLimit=projectUsedLimit
          nsDefaultQuota=nsDefaultQuota
          changed=(action "updateNsQuota")
        }}
      {{/accordion-list-item}}
    {{/if}}

    {{#accordion-list-item
       title=(t "projectsPage.containerDefaultLimit.title")
       detail=(t "projectsPage.containerDefaultLimit.detail")
       expandAll=al.expandAll
       expand=(action expandFn)
       expandOnInit=true
    }}
      {{container-default-limit
        editing=(or editing isNew)
        expanded=expanded
        limit=primaryResource.project.containerDefaultResourceLimit
        changed=(action "updateContainerDefault")
      }}
    {{/accordion-list-item}}

    {{form-labels-annotations
      classNames="accordion-wrapper"
      expandAll=al.expandAll
      expandFn=expandFn
      initialLabels=primaryResource.labels
      model=primaryResource
      editing=(or editing isNew)
      setLabels=(action "setLabels")
    }}
  {{/accordion-list}}
</div>

{{top-errors errors=errors}}
{{save-cancel
  editing=false
  save=(action "save")
  cancel=(action "cancel")
}}
