{{#d-modal-body title=(if invite.id "user.invited.invite.edit_title" "user.invited.invite.new_title")}}
  <form>
    <div class="input-group invite-link">
      <label for="invite-link">{{i18n "user.invited.invite.instructions"}}</label>
      <div class="invite-input-with-button">
        {{input
          name="invite-link"
          class="invite-link"
          value=invite.link
          readonly=true
        }}
        {{copy-button selector="input.invite-link" copied=(action "copied")}}
      </div>
    </div>

    <p>{{expiresAtLabel}}</p>

    <div class="input-group invite-type">
      {{input type="checkbox" id="invite-type" checked=limitToEmail click=(action "toggleLimitToEmail")}}
      <label for="invite-type">{{i18n "user.invited.invite.restrict_email"}}</label>

      {{#if isEmail}}
        <div class="invite-input-with-button">
          {{input
            id="invite-email"
            value=buffered.email
            placeholderKey="topic.invite_reply.email_placeholder"
          }}
          {{#if capabilities.hasContactPicker}}
            {{d-button
              icon="address-book"
              action=(action "searchContact")
              class="btn-primary open-contact-picker"
            }}
          {{/if}}
        </div>
      {{/if}}
    </div>

    {{#if isLink}}
      <div class="input-group invite-max-redemptions">
        <label for="invite-max-redemptions">{{i18n "user.invited.invite.max_redemptions_allowed"}}</label>
        {{input
          id="invite-max-redemptions"
          type="number"
          value=buffered.max_redemptions_allowed
          min="1"
          max=maxRedemptionsAllowedLimit
        }}
      </div>
    {{/if}}

    {{#if isEmail}}
      {{#if showAdvanced}}
        <div class="input-group invite-custom-message">
          <label for="invite-message">{{i18n "user.invited.invite.custom_message"}}</label>
          {{textarea id="invite-message" value=buffered.custom_message}}
        </div>
      {{/if}}
    {{/if}}

    {{#if showAdvanced}}
      {{#if currentUser.staff}}
        <div class="input-group invite-to-topic">
          {{choose-topic
            selectedTopicId=buffered.topicId
            topicTitle=buffered.topicTitle
            additionalFilters="status:public"
            label="user.invited.invite.invite_to_topic"
          }}
        </div>
      {{else if buffered.topicTitle}}
        <div class="input-group">
          <label for="invite-topic">{{i18n "user.invited.invite.invite_to_topic"}}</label>
          {{input
            name="invite-topic"
            class="invite-topic"
            value=buffered.topicTitle
            readonly=true
          }}
        </div>
      {{/if}}
    {{/if}}

    {{#if showAdvanced}}
      {{#if canInviteToGroup}}
        <div class="input-group invite-to-groups">
          <label>{{i18n "user.invited.invite.add_to_groups"}}</label>
          {{group-chooser
            content=allGroups
            value=buffered.groupIds
            labelProperty="name"
            onChange=(action (mut buffered.groupIds))
          }}
        </div>
      {{/if}}
    {{/if}}

    {{#if showAdvanced}}
      {{#if currentUser.staff}}
        <div class="input-group invite-expires-at">
          {{future-date-input
            displayLabel=(i18n "user.invited.invite.expires_at")
            includeDateTime=true
            includeMidFuture=true
            clearable=true
            onChangeInput=(action (mut buffered.expires_at))
          }}
        </div>
      {{/if}}
    {{/if}}
  </form>
{{/d-modal-body}}

<div class="modal-footer">
  {{d-button
    icon="link"
    label="user.invited.invite.save_invite"
    class="btn-primary save-invite"
    action=(action "saveInvite")
    disabled=disabled
  }}

  {{#if isEmail}}
    {{d-button
      icon="envelope"
      label=(if invite.emailed "user.invited.reinvite" "user.invited.invite.send_invite_email")
      class="btn-primary send-invite"
      action=(action "saveInvite" true)
      disabled=disabled
    }}
  {{/if}}

  {{#if hasAdvanced}}
    {{d-button
      action=(action "toggleAdvanced")
      class="btn-default show-advanced"
      icon="cog"
      title=(if showAdvanced "user.invited.invite.hide_advanced" "user.invited.invite.show_advanced")
    }}
  {{/if}}
</div>
