<form #form (ngSubmit)="submit()" [appApiAction]="formPromise">
  <div class="content">
    <div class="inner-content" *ngIf="send">
      <div class="box">
        <app-callout *ngIf="disableSend">
          <span>{{ "sendDisabledWarning" | i18n }}</span>
        </app-callout>
        <app-callout type="info" *ngIf="disableHideEmail && !disableSend">
          {{ "sendOptionsPolicyInEffect" | i18n }}
        </app-callout>
      </div>
      <div class="box">
        <h2 class="box-header">
          {{ title }}
        </h2>
        <div class="box-content">
          <div class="box-content-row" appBoxRow>
            <label for="name">{{ "name" | i18n }}</label>
            <input
              id="name"
              type="text"
              name="Name"
              [(ngModel)]="send.name"
              appAutofocus
              [readOnly]="disableSend"
            />
          </div>
          <div class="box-content-row box-content-row-radio" *ngIf="!editMode">
            <label class="radio-header">{{ "whatTypeOfSend" | i18n }}</label>
            <div class="item" *ngFor="let o of typeOptions">
              <input
                type="radio"
                class="radio"
                [(ngModel)]="send.type"
                name="Type_{{ o.value }}"
                id="type_{{ o.value }}"
                [value]="o.value"
                (change)="typeChanged()"
                [checked]="send.type === o.value"
                [disabled]="disableSend"
              />
              <label class="unstyled" for="type_{{ o.value }}">
                {{ o.name }}
              </label>
            </div>
          </div>
          <div class="box-content-row" appBowRow *ngIf="!editMode && send.type === sendType.File">
            <label for="file">{{ "file" | i18n }}</label>
            <input
              type="file"
              id="file"
              class="form-control-file"
              name="file"
              aria-describedby="fileHelp"
              required
              [disabled]="disableSend"
            />
          </div>
          <div class="box-content-row" appBowRow *ngIf="editMode && send.type === sendType.File">
            <label for="file">{{ "file" | i18n }}</label>
            <div class="row-main">{{ send.file.fileName }} ({{ send.file.sizeName }})</div>
          </div>
          <div class="box-content-row" appBoxRow *ngIf="send.type === sendType.Text">
            <label for="text">{{ "text" | i18n }}</label>
            <textarea
              id="text"
              name="text"
              aria-describedby="textHelp"
              [(ngModel)]="send.text.text"
              rows="6"
              [readOnly]="disableSend"
            ></textarea>
          </div>
        </div>
        <div id="fileHelp" class="box-footer" *ngIf="!editMode && send.type === sendType.File">
          {{ "sendFileDesc" | i18n }} {{ "maxFileSize" | i18n }}
        </div>
        <div id="textHelp" class="box-footer" *ngIf="send.type === sendType.Text">
          {{ "sendTextDesc" | i18n }}
        </div>
      </div>
      <div class="box" *ngIf="send.type === sendType.Text">
        <div class="box-content">
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="hideText">{{ "textHiddenByDefault" | i18n }}</label>
            <input
              id="hideText"
              name="hideText"
              type="checkbox"
              [(ngModel)]="send.text.hidden"
              [disabled]="disableSend"
            />
          </div>
        </div>
      </div>
      <div class="box">
        <h2 class="box-header">
          <button
            type="button"
            class="toggle"
            appStopClick
            (click)="toggleOptions()"
            [attr.aria-expanded]="showOptions"
          >
            <i
              class="bwi bwi-lg"
              aria-hidden="true"
              [ngClass]="{ 'bwi-angle-right': !showOptions, 'bwi-angle-down': showOptions }"
            ></i>
            {{ "options" | i18n }}
          </button>
        </h2>
      </div>
      <div [hidden]="!showOptions">
        <app-send-efflux-dates
          [initialDeletionDate]="send.deletionDate"
          [initialExpirationDate]="send.expirationDate"
          [editMode]="editMode"
          [disabled]="disableSend"
          (datesChanged)="setDates($event)"
        >
        </app-send-efflux-dates>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row" appBoxRow>
              <label for="maxAccessCount">{{ "maxAccessCount" | i18n }}</label>
              <input
                id="maxAccessCount"
                type="number"
                name="maxAccessCount"
                aria-describedby="maxAccessCountHelp"
                [(ngModel)]="send.maxAccessCount"
                [readOnly]="disableSend"
              />
            </div>
          </div>
          <div id="maxAccessCountHelp" class="box-footer" *ngIf="!editMode">
            {{ "maxAccessCountDesc" | i18n }}
          </div>
          <div id="maxAccessCountHelp" class="box-footer" *ngIf="editMode">
            <p>{{ "maxAccessCountDesc" | i18n }}</p>
            {{ "currentAccessCount" | i18n }}: <strong>{{ send.accessCount }}</strong>
          </div>
        </div>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row box-content-row-flex" appBoxRow>
              <div class="row-main">
                <label for="password">{{
                  (hasPassword ? "newPassword" : "password") | i18n
                }}</label>
                <input
                  id="password"
                  name="password"
                  aria-describedby="passwordHelp"
                  type="{{ showPassword ? 'text' : 'password' }}"
                  [(ngModel)]="password"
                  [readOnly]="disableSend"
                  appInputVerbatim
                />
              </div>
              <div class="action-buttons">
                <button
                  type="button"
                  class="row-btn"
                  appStopClick
                  appA11yTitle="{{ 'toggleVisibility' | i18n }}"
                  [attr.aria-pressed]="showPassword"
                  (click)="togglePasswordVisible()"
                  [disabled]="disableSend"
                >
                  <i
                    class="bwi bwi-lg"
                    aria-hidden="true"
                    [ngClass]="{ 'bwi-eye': !showPassword, 'bwi-eye-slash': showPassword }"
                  ></i>
                </button>
              </div>
            </div>
          </div>
          <div id="passwordHelp" class="box-footer">
            {{ "sendPasswordDesc" | i18n }}
          </div>
        </div>
        <div class="box">
          <h2 class="box-header">
            <label for="notes">{{ "notes" | i18n }}</label>
          </h2>
          <div class="box-content">
            <div class="box-content-row" appBoxRow>
              <textarea
                id="notes"
                name="notes"
                aria-describedby="notesHelp"
                [(ngModel)]="send.notes"
                rows="6"
                [readOnly]="disableSend"
              ></textarea>
            </div>
          </div>
          <div id="notesHelp" class="box-footer">
            {{ "sendNotesDesc" | i18n }}
          </div>
        </div>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row box-content-row-checkbox" appBoxRow>
              <label for="hideEmail">{{ "hideEmail" | i18n }}</label>
              <input
                id="hideEmail"
                type="checkbox"
                name="HideEmail"
                [(ngModel)]="send.hideEmail"
                [disabled]="(disableHideEmail && !send.hideEmail) || disableSend"
              />
            </div>
          </div>
        </div>
        <div class="box">
          <div class="box-content">
            <div class="box-content-row box-content-row-checkbox" appBoxRow>
              <label for="disabled">{{ "disableSend" | i18n }}</label>
              <input
                id="disabled"
                type="checkbox"
                name="disabled"
                [(ngModel)]="send.disabled"
                [disabled]="disableSend"
              />
            </div>
          </div>
        </div>
      </div>
      <div class="box">
        <h2 class="box-header">
          {{ "share" | i18n }}
        </h2>
        <div class="box-content">
          <div class="box-content-row" appBoxRow *ngIf="editMode">
            <label for="link">{{ "sendLinkLabel" | i18n }}</label>
            <input id="link" name="link" [ngModel]="link" readonly />
          </div>
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="copyLink">{{ "copySendLinkOnSave" | i18n }}</label>
            <input
              id="copyLink"
              name="copyLink"
              [(ngModel)]="copyLink"
              type="checkbox"
              [disabled]="disableSend"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <button
      type="submit"
      class="primary btn-submit"
      appA11yTitle="{{ 'save' | i18n }}"
      [disabled]="form.loading"
      *ngIf="!disableSend"
    >
      <i class="bwi bwi-spinner bwi-spin" title="{{ 'loading' | i18n }}" aria-hidden="true"></i>
      <span><i class="bwi bwi-save-changes bwi-lg bwi-fw" aria-hidden="true"></i></span>
    </button>
    <button type="button" (click)="cancel()" [disabled]="form.loading">
      {{ "cancel" | i18n }}
    </button>
    <div class="right">
      <button
        type="button"
        (click)="copyLinkToClipboard(link)"
        appA11yTitle="{{ 'copySendLinkToClipboard' | i18n }}"
        *ngIf="editMode"
      >
        <i class="bwi bwi-clone bwi-lg bwi-fw" aria-hidden="true"></i>
      </button>
      <button
        #deleteBtn
        type="button"
        (click)="delete()"
        class="danger"
        appA11yTitle="{{ 'delete' | i18n }}"
        *ngIf="editMode"
      >
        <i
          class="bwi bwi-trash bwi-lg bwi-fw"
          [hidden]="$any(deleteBtn).loading"
          aria-hidden="true"
        ></i>
        <i
          class="bwi bwi-spinner bwi-spin bwi-lg bwi-fw"
          [hidden]="!$any(deleteBtn).loading"
          aria-hidden="true"
        ></i>
      </button>
    </div>
  </div>
</form>
