<PageHeader as |p|>
  <p.levelLeft>
    <h1 class="title is-3">
      Hash Data
    </h1>
  </p.levelLeft>
</PageHeader>

{{#if sum}}
  <div class="box is-sideless is-fullwidth is-marginless">
    <div class="field">
      <label for="sum" class="is-input">Sum</label>
      <div class="control">
        <textarea readonly class="textarea" id="sum" data-test-tools-input="sum">{{sum}}</textarea>
      </div>
    </div>
  </div>
  <div class="field is-grouped box is-fullwidth is-bottomless">
    <div class="control">
      {{#copy-button
        clipboardText=sum
        class="button is-primary"
        buttonType="button"
        success=(action (set-flash-message 'Hashed data copied!'))
      }}
      Copy
      {{/copy-button}}
    </div>
    <div class="control">
      <button {{action 'onClear'}} type="button" class="button" data-test-tools-back=true>
        Back
      </button>
    </div>
  </div>
{{else}}
  <div class="box is-sideless is-fullwidth is-marginless">
    {{message-error errors=errors}}
    <div class="field">
      <label for="input" class="is-label">
        Input
      </label>
      <div class="control">
        {{textarea id="input" name="input" value=input class="textarea" data-test-tools-input="hash-input"}}
        {{b64-toggle value=input isInput=false data-test-tools-b64-toggle="input"}}
      </div>
    </div>
    <div class="field is-horizontal">
      <div class="field-body">
        <div class="field">
          <label for="algorithm" class="is-label">Algorithm</label>
          <div class="control is-expanded">
            <div class="select is-fullwidth">
              <select
                name="algorithm"
                id="algorithm"
                onchange={{action (mut algorithm) value="target.value"}}
              >
                {{#each (sha2-digest-sizes) as |algo|}}
                  <option selected={{if algorithm (eq algorithm algo)}} value={{algo}}>
                    {{algo}}
                  </option>
                {{/each}}
              </select>
            </div>
          </div>
        </div>
        <div class="field">
          <label for="format" class="is-label"> Output format </label>
          <div class="control is-expanded">
            <div class="select is-fullwidth">
              <select
                 name="format"
                 id="format"
                 onchange={{action (mut format) value="target.value"}}
              >
                {{#each (reduce-to-array 'base64' 'hex') as |formatOption|}}
                  <option selected={{if format (eq format formatOption)}} value={{formatOption}}>
                    {{formatOption}}
                  </option>
                {{/each}}
              </select>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="field is-grouped box is-fullwidth is-bottomless">
    <div class="control">
      <button
         type="sumbit"
         class="button is-primary"
         data-test-tools-submit="true"
         >
         Hash
      </button>
    </div>
  </div>
{{/if}}
