{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
}}

<Route
  @name={{this.routeName}}
as |route|>
  <DataLoader @src={{
    uri '/${partition}/${nspace}/${dc}/role/${id}'
      (hash
        partition=route.params.partition
        nspace=route.params.nspace
        dc=route.params.dc
        id=(or route.params.id '')
      )
    }}
  as |loader|>

    <BlockSlot @name="error">
      {{#if (eq loader.error.status '401')}}
        <Consul::Acl::Disabled />
      {{else}}
        <AppError
          @error={{loader.error}}
          @login={{route.model.app.login.open}}
        />
      {{/if}}
    </BlockSlot>

    <BlockSlot @name="loaded">
{{#let

  route.params.dc
  route.params.partition
  route.params.nspace

  loader.data
  loader.data.isNew
as |dc partition nspace item create|}}
  <AppView
    @login={{route.model.app.login.open}}
    >
      <BlockSlot @name="breadcrumbs">
          <ol>
              <li><a data-test-back href={{href-to 'dc.acls.roles'}}>All Roles</a></li>
          </ol>
      </BlockSlot>
      <BlockSlot @name="header">
          <h1>
    {{#if create }}
              <route.Title @title="New Role" />
    {{else}}
              <route.Title @title="Edit Role" />
    {{/if}}
          </h1>
      </BlockSlot>
      <BlockSlot @name="content">
  {{#if (not create) }}
        <div class="definition-table">
            <dl>
              <dt>Role ID</dt>
              <dd>
                <CopyableCode
                  @value={{item.ID}}
                  @name="Role ID"
                />
              </dd>
            </dl>
        </div>
  {{/if}}
        <Consul::Role::Form
          @form={{this.form}}
          @item={{item}}
          @dc={{dc}}
          @nspace={{nspace}}
          @partition={{partition}}
          @create={{create}}
          @id={{route.params.id}}
          @items={{this.items}}
          @onCreate={{fn this.onCreate item}}
          @onUpdate={{fn this.onUpdate item}}
          @onCancel={{fn this.onCancel item}}
          @onDelete={{fn this.onDelete item}}
          @onItemsChange={{action (mut this.items) value="data"}}
        />
      </BlockSlot>
  </AppView>
{{/let}}
    </BlockSlot>
  </DataLoader>
</Route>