<popup-page>
  <popup-header
    slot="header"
    [pageTitle]="headerText"
    showBackButton
    [backAction]="onBackClick.bind(this)"
  ></popup-header>

  @if (disabledSendConfig()) {
    <bit-callout type="info" [title]="disabledSendConfig().title | i18n">
      <div>{{ disabledSendConfig().message | i18n }}</div>
      @if (disabledSendConfig().showMakeCopyButton) {
        <button class="tw-mt-4" type="button" bitButton buttonType="primary" (click)="makeCopy()">
          {{ "makeACopy" | i18n }}
        </button>
      }
    </bit-callout>
  }

  <tools-send-form
    formId="sendForm"
    [config]="config"
    (onSendCreated)="onSendCreated($event)"
    (onSendUpdated)="onSendUpdated($event)"
    (openPasswordGenerator)="openGenerator()"
    [editing]="editing()"
    [submitBtn]="submitBtn()"
  >
  </tools-send-form>

  <popup-footer slot="footer">
    <!-- Send is disabled -->
    @if (disabledSendConfig()) {
      <!-- User is allowed to make a copy of the Send -->
      @if (disabledSendConfig().showMakeCopyButton) {
        <button type="button" bitButton buttonType="primary" (click)="makeCopy()">
          {{ "makeACopy" | i18n }}
        </button>
      } @else {
        <button type="button" bitButton buttonType="danger" (click)="deleteSend()">
          {{ "delete" | i18n }}
        </button>
      }
      <!-- Send is enabled -->
    } @else {
      <!-- Send is actively being edited -->
      @if (editing()) {
        <button bitButton type="submit" form="sendForm" buttonType="primary" #submitBtn>
          {{ "save" | i18n }}
        </button>
        <button bitButton type="button" buttonType="secondary" (click)="onCancelClick()">
          {{ "cancel" | i18n }}
        </button>
      } @else {
        <button bitButton type="button" buttonType="secondary" (click)="editSend()">
          {{ "edit" | i18n }}
        </button>
      }
    }
    @if (
      disabledSendConfig()?.showMakeCopyButton || (!disabledSendConfig() && config?.mode !== "add")
    ) {
      <button
        class="tw-ml-auto"
        type="button"
        buttonType="dangerGhost"
        slot="end"
        bitIconButton="bwi-trash"
        [bitAction]="deleteSend"
        label="{{ 'delete' | i18n }}"
      ></button>
    }
  </popup-footer>
</popup-page>
