<nz-card nzType="inner">
  <nz-alert
    *ngIf="success"
    nzBanner
    nzMessage="Flag submitted"
    nzType="success"
    nzCloseable
    (nzOnClose)="onSuccessBannerClose()"></nz-alert>
  <nz-alert
    *ngIf="errorMessages.length > 0"
    nzType="error"
    nzShowIcon
    [nzDescription]="errorContents"
    nzMessage="Error Adding Flag">
  </nz-alert>
  <ng-template #errorContents>
    <ul>
      <li *ngFor="let error of errorMessages">{{ error }}</li>
    </ul>
  </ng-template>
  <form
    nz-form
    (ngSubmit)="submitFlag()"
    nzLayout="vertical">
    <cvc-comment-input-form [(comment)]="comment"></cvc-comment-input-form>
    <nz-spin
      nzTip="Submitting"
      [nzSpinning]="loading">
      <nz-form-item>
        <nz-form-control>
          <ng-container *ngrxLet="viewer$ as viewer">
            <cvc-form-buttons>
              <ng-container *ngIf="viewer.signedIn; else notSignedIn">
                <ng-template *ngTemplateOutlet="submitButton"></ng-template>
              </ng-container>
              <ng-template #notSignedIn>
                <span
                  nz-tooltip
                  nzTooltipTitle="Must be signed in to flag entity.">
                  <ng-template *ngTemplateOutlet="submitButton"></ng-template>
                </span>
              </ng-template>
              <ng-template #submitButton>
                <button
                  type="submit"
                  nz-button
                  cvcOrgSelectorBtn
                  nzType="primary"
                  nzSize="small"
                  [disabled]="!(comment !== undefined && comment.length >= 10) || !viewer.signedIn"
                  nz-tooltip
                  [nzTooltipTrigger]="selectedOrg ? 'hover' : null"
                  [nzTooltipTitle]="'For ' + selectedOrg?.name">
                  Flag {{ flaggable.entityType | enumToTitle }}
                </button>
              </ng-template>
            </cvc-form-buttons>
          </ng-container>
        </nz-form-control>
      </nz-form-item>
    </nz-spin>
  </form>
</nz-card>
