import templateOnly from '@ember/component/template-only';
import { setComponentTemplate } from '@ember/component';
import { precompileTemplate } from '@ember/template-compilation';
import { array } from '@ember/helper';
import { eq, and, gt } from 'ember-truth-helpers';
import isArray from 'ember-truth-helpers/helpers/is-array';
import argOrDefault from '../helpers/arg-or-default.js';
import EuiCallOut from './eui-call-out.js';

const EuiForm = setComponentTemplate(precompileTemplate(`
  {{#let
    (argOrDefault @invalidCallout "above")
    (if (isArray @error) @error (if @array (array @error)))
    as |invalidCallout errors|
  }}
    {{#if (eq @tagName "form")}}
      <form class="euiForm" ...attributes>
        {{#if
          (and (eq invalidCallout "above") (gt errors.length 0) @isInvalid)
        }}
          <EuiCallOut
            class="euiForm__errors"
            role="alert"
            aria-live="assertive"
            @title={{argOrDefault @errorTitle "Please correct the fields"}}
            @color="danger"
          >
            <:body>
              {{#each errors as |error|}}
                <li class="euiForm__error">
                  {{#if (has-block "error")}}
                    {{!@glint-expect-error}}
                    {{yield error to="error"}}
                  {{else}}
                    {{!@glint-expect-error}}
                    {{error}}
                  {{/if}}
                </li>
              {{/each}}
            </:body>
          </EuiCallOut>
        {{/if}}
        {{#if (has-block "content")}}
          {{yield to="content"}}
        {{else}}
          {{yield}}
        {{/if}}
      </form>
    {{else}}
      <div class="euiForm" ...attributes>
        {{#if
          (and (eq invalidCallout "above") (gt errors.length 0) @isInvalid)
        }}
          <EuiCallOut
            class="euiForm__errors"
            role="alert"
            aria-live="assertive"
            @title={{argOrDefault @errorTitle "Please correct the fields"}}
            @color="danger"
          >
            <:body>
              {{#each errors as |error|}}
                <li class="euiForm__error">
                  {{#if (has-block "error")}}
                    {{!@glint-expect-error}}
                    {{yield error to="error"}}
                  {{else}}
                    {{!@glint-expect-error}}
                    {{error}}
                  {{/if}}
                </li>
              {{/each}}
            </:body>
          </EuiCallOut>
        {{/if}}
        {{#if (has-block "content")}}
          {{yield to="content"}}
        {{else}}
          {{yield}}
        {{/if}}
      </div>
    {{/if}}
  {{/let}}
`, {
  strictMode: true,
  scope: () => ({
    argOrDefault,
    isArray,
    array,
    eq,
    and,
    gt,
    EuiCallOut
  })
}), templateOnly("eui-form", "EuiForm"));

export { EuiForm as default };
//# sourceMappingURL=eui-form.js.map
