{{#if inviteModel.error}}
  <div class="alert alert-error">
    {{html-safe errorMessage}}
  </div>
{{/if}}

<div class="body">
  {{#if inviteModel.finished}}
    {{#if inviteModel.inviteLink}}
      {{generated-invite-link link=inviteModel.inviteLink email=emailOrUsername}}
    {{else}}
      <div class="success-message">
        {{html-safe successMessage}}
      </div>
    {{/if}}
  {{else}}
    <div class="invite-user-control">
      <label class="instructions">{{inviteInstructions}}</label>
      <div class="invite-user-input-wrapper">
        {{#if allowExistingMembers}}
          {{user-selector
            fullWidthWrap=true
            single=true
            allowAny=true
            excludeCurrentUser=true
            includeMessageableGroups=isPM
            hasGroups=hasGroups
            usernames=emailOrUsername
            placeholderKey=placeholderKey
            allowEmails=true
            class="invite-user-input"
            autocomplete="discourse"
            value=emailOrUsername
          }}
        {{else}}
          {{text-field
            class="email-or-username-input"
            value=emailOrUsername
            placeholderKey="topic.invite_reply.email_placeholder"}}
        {{/if}}
        {{#if showContactPicker}}
          {{d-button
            icon="address-book"
            action=(action "searchContact")
            class="btn-primary open-contact-picker"
          }}
        {{/if}}
      </div>
    </div>

    {{#if showGroups}}
      <div class="group-access-control">
        <label class="instructions {{showGroupsClass}}">
          {{i18n "topic.automatically_add_to_groups"}}
        </label>
        {{group-selector
          fullWidthWrap=true
          groupFinder=groupFinder
          groupNames=inviteModel.groupNames
          placeholderKey="topic.invite_private.group_name"}}
      </div>
    {{/if}}

    {{#if showCustomMessage}}
      <div class="show-custom-message-control">
        <label class="instructions">
          {{discourse-linked-text
            class="optional"
            action=(action "showCustomMessageBox")
            text="invite.custom_message"}}
        </label>
        {{#if hasCustomMessage}}
          {{textarea value=customMessage placeholder=customMessagePlaceholder}}
        {{/if}}
      </div>
    {{/if}}
  {{/if}}
</div>

<div class="footer">
  {{#if inviteModel.finished}}
    {{d-button
      class="btn-primary"
      action=(route-action "closeModal")
      label="close"}}
  {{else}}
    {{d-button
      icon=inviteIcon
      action=(action "createInvite")
      class="btn-primary send-invite"
      disabled=disabled
      label=buttonTitle}}
    {{#if showCopyInviteButton}}
      {{d-button
        icon="link"
        action=(action "generateInvitelink")
        class="btn-primary generate-invite-link"
        disabled=disabledCopyLink
        label="user.invited.generate_link"}}
    {{/if}}
  {{/if}}
</div>
