{{#each (get @model this.fieldGroups) as |fieldGroup|}}
  {{#each-in fieldGroup as |group fields|}}
    {{#if (or (not @renderGroup) (and @renderGroup (eq group @renderGroup)))}}
      {{#if (eq group "default")}}
        {{#each fields as |attr|}}
          {{! SHOW ALL FIELDS IF CREATING A NEW MODEL }}
          {{#if (or (eq @mode "create") @model.isNew)}}
            <FormField
              data-test-field
              @attr={{attr}}
              @mode={{@mode}}
              @model={{@model}}
              @onChange={{@onChange}}
              @onKeyUp={{@onKeyUp}}
              @modelValidations={{@modelValidations}}
              @showHelpText={{@showHelpText}}
            />
          {{else}}
            {{! OTHERWISE WE'RE EDITING }}
            {{#if (or (eq attr.name "name") (attr.options.editDisabled))}}
              <ReadonlyFormField @attr={{attr}} @value={{get @model attr.name}} />
            {{else}}
              <FormField
                data-test-field
                @attr={{attr}}
                @mode={{@mode}}
                @model={{@model}}
                @onChange={{@onChange}}
                @onKeyUp={{@onKeyUp}}
                @modelValidations={{@modelValidations}}
                @showHelpText={{@showHelpText}}
              />
            {{/if}}
          {{/if}}
        {{/each}}
      {{else}}
        <ToggleButton
          @isOpen={{eq this.showGroup group}}
          @openLabel={{concat "Hide " group}}
          @closedLabel={{group}}
          @onClick={{fn this.toggleGroup group}}
          class="is-block"
          data-test-toggle-group={{group}}
        />
        {{#if (eq this.showGroup group)}}
          <div class="box is-marginless">
            {{#each fields as |attr|}}
              {{! SHOW ALL FIELDS IF CREATING A NEW MODEL }}
              {{#if (or (eq @mode "create") @model.isNew)}}
                <FormField
                  data-test-field
                  @attr={{attr}}
                  @mode={{@mode}}
                  @model={{@model}}
                  @onChange={{@onChange}}
                  @onKeyUp={{@onKeyUp}}
                  @modelValidations={{@modelValidations}}
                  @showHelpText={{@showHelpText}}
                />
              {{else}}
                {{! OTHERWISE WE'RE EDITING }}
                {{#if (or (eq attr.name "name") (eq attr.options.editDisabled true))}}
                  <ReadonlyFormField @attr={{attr}} @value={{get @model attr.name}} />
                {{else}}
                  <FormField
                    data-test-field
                    @attr={{attr}}
                    @mode={{@mode}}
                    @model={{@model}}
                    @onChange={{@onChange}}
                    @onKeyUp={{@onKeyUp}}
                    @modelValidations={{@modelValidations}}
                    @showHelpText={{@showHelpText}}
                  />
                {{/if}}
              {{/if}}
            {{/each}}
          </div>
        {{/if}}
      {{/if}}
    {{/if}}
  {{/each-in}}
{{/each}}