<section class="header clearfix">
  <h1>
    {{t "editPipelineConfig.header"}}
  </h1>
</section>

{{steps/step-scm
  errors=errors
  pipeline=pipeline
  pipelineId=model.pipeline.id
  accounts=model.accounts
}}

{{#if (or pipeline.loading pipeline.branches.length)}}
  <hr class="mt-30 mb-30" />

  <div class="row">
    {{#if pipeline.loading}}
      <section class="row">
        <div class="text-center">
          <i class="icon icon-spinner icon-spin icon-3x"></i>
        </div>
      </section>
    {{else if pipeline.url}}
      <div class="row mb-20">
        <div class="col span-3">
          <label class="acc-label pb-5">
            {{t "generic.branch"}}
          </label>
          {{#searchable-select
             optionLabelPath="branch"
             optionValuePath="branch"
             value=selectedBranch
             customLabel=true
             content=pipeline.branches as |item|
          }}
            <div class="{{item.stateColor}}">
              {{item.branch}}
            </div>
          {{/searchable-select}}
        </div>
      </div>
      <div class="row mb-10">
        <label class="acc-label pb-5">
          {{t "newPipeline.steps.label"}}
        </label>
        <section class="pipeline-container">
          {{#if selectedConfig.stages.length}}
            {{pipeline-stages
              projectDockerCredentials=model.projectDockerCredentials
              pipeline=pipeline
              selectedConfig=selectedConfig
              accounts=model.accounts
              model=model
              editable=true
              editMode="new"
              saved=saved
            }}
          {{else}}
            <div class="banner bg-warning">
              <div class="banner-icon">
                <span class="icon icon-info"></span>
              </div>
              <div class="banner-message">
                <p>{{t "newPipelineStep.stepType.scm.noYaml" htmlSafe=true}}</p>
              </div>
            </div>
            <button class="btn bg-transparent" {{action "enableBranch"}}>
              <i class="icon icon-edit"/>
              {{t "newPipelineStep.stepType.enableBranch"}}
            </button>
          {{/if}}
        </section>
      </div>

      <div class="row mb-10">
        {{pipeline-notifier
          config=selectedNotification
          notificationEnabled=notificationEnabled
        }}
      </div>

      {{#if showAdvanced}}
        {{#advanced-section}}
          {{pipeline-condition
            type="pipeline"
            branchOnly=true
            config=when
          }}
          <div class="acc-label pb-5 pt-10">
            {{t "editPipelineConfig.timeout.label"}}
          </div>
          <div class="row">
            <div class="box col span-6">
              <div class="input-group">
                {{input-integer
                  classNames="form-control"
                  value=selectedConfig.timeout
                }}
                <span class="input-group-addon bg-default">
                  {{t "generic.minutes"}}
                </span>
              </div>
              <p class="help-block">
                {{t "editPipelineConfig.timeout.helpText"}}
              </p>
            </div>
          </div>
        {{/advanced-section}}
      {{/if}}
    {{/if}}
  </div>
{{else if (and (not pipeline.loading) (not pipeline.branches.length))}}
  {{#banner-message color="bg-warning"}}
    <p>{{t "generic.noBranch"}}</p>
  {{/banner-message}}
{{/if}}

<hr class="mt-30 mb-30" />

{{top-errors errors=errors}}

<div class="text-center pipeline-wrap-header-button">
  {{save-cancel
    class="pipeline-save-cancel"
    saveDisabled=(or pipeline.loading (not pipeline.branches.length))
    createLabel="generic.done"
    save=(action "save")
    cancel=(action "cancel")
  }}
</div>
