@if (tasks$ | async; as tasks) {
  <h1 mat-dialog-title>
    <mat-icon class="dialog-header-icon">notifications</mat-icon>
    <span>{{ T.F.TASK.D_REMINDER_VIEW.TASK_REMINDERS | translate }}</span>
  </h1>
  <mat-dialog-content>
    @if (hasDeadlineTasks(tasks)) {
      <h3 class="section-heading">
        <mat-icon>flag</mat-icon>
        {{ T.F.TASK.D_REMINDER_VIEW.DEADLINE_SECTION | translate }}
      </h3>
      <div
        class="tasks"
        [@standardList]="tasks.length"
      >
        @for (task of tasks; track trackById($index, task)) {
          @if (task.isDeadlineReminder) {
            <ng-container
              *ngTemplateOutlet="taskRow; context: { $implicit: task }"
            ></ng-container>
          }
        }
      </div>
    }
    @if (hasScheduleTasks(tasks)) {
      <h3 class="section-heading">
        <mat-icon>alarm</mat-icon>
        {{ T.F.TASK.D_REMINDER_VIEW.DUE_SECTION | translate }}
      </h3>
      <div
        class="tasks"
        [@standardList]="tasks.length"
      >
        @for (task of tasks; track trackById($index, task)) {
          @if (!task.isDeadlineReminder) {
            <ng-container
              *ngTemplateOutlet="taskRow; context: { $implicit: task }"
            ></ng-container>
          }
        }
      </div>
    }
  </mat-dialog-content>
  <mat-dialog-actions align="end">
    <div class="footer-wrapper">
      @if (isMultiple) {
        <div class="bulk-actions-header">
          {{ T.F.TASK.D_REMINDER_VIEW.OR_DIRECTLY_FOR_ALL | translate }}
        </div>
      }
      <div class="wrap-buttons">
        <split-button
          [disabled]="isDisableControls"
          [menu]="footerMenu"
          [mainLabel]="T.F.TASK.D_REMINDER_VIEW.SNOOZE_FOR | translate: { m: 10 }"
          [triggerLabel]="T.F.TASK.D_REMINDER_VIEW.MORE_ACTIONS"
          (mainClick)="snoozeAll(10)"
        >
          <mat-icon>snooze</mat-icon>
          {{ T.F.TASK.D_REMINDER_VIEW.SNOOZE_FOR_SHORT | translate: { m: 10 } }}
        </split-button>
        @if (!isMultiple) {
          <button
            class="done-btn"
            (click)="markSingleAsDone()"
            [disabled]="isDisableControls"
            [matTooltip]="T.F.TASK.D_REMINDER_VIEW.MARK_AS_DONE | translate"
            [attr.aria-label]="T.F.TASK.D_REMINDER_VIEW.MARK_AS_DONE | translate"
            color="primary"
            mat-stroked-button
            matTooltipShowDelay="0"
            type="button"
          >
            <mat-icon>check</mat-icon>
          </button>
        }
        @if (isMultiple || isAllDeadline) {
          <button
            (click)="addAllToToday()"
            [disabled]="isDisableControls"
            color="primary"
            mat-flat-button
            type="button"
          >
            <mat-icon>wb_sunny</mat-icon>
            {{
              (isAllDeadline
                ? T.F.TASK.D_REMINDER_VIEW.ADD_TO_TODAY
                : T.F.TASK.D_REMINDER_VIEW.KEEP_IN_TODAY
              ) | translate
            }}
          </button>
        } @else {
          <button
            (click)="play()"
            [disabled]="isDisableControls"
            color="primary"
            mat-flat-button
            type="button"
          >
            <mat-icon>play_arrow</mat-icon>
            {{ T.F.TASK.D_REMINDER_VIEW.START | translate }}
          </button>
        }
      </div>
    </div>
  </mat-dialog-actions>
  <mat-menu #footerMenu="matMenu">
    <button
      (click)="snoozeAll(30)"
      [disabled]="isDisableControls"
      mat-menu-item
    >
      <mat-icon>snooze</mat-icon>
      {{ T.G.MINUTES | translate: { m: 30 } }}
    </button>
    <button
      (click)="snoozeAll(60)"
      [disabled]="isDisableControls"
      mat-menu-item
    >
      <mat-icon>snooze</mat-icon>
      {{ T.G.MINUTES | translate: { m: 60 } }}
    </button>
    <button
      (click)="rescheduleAllUntilTomorrow()"
      [disabled]="isDisableControls"
      mat-menu-item
    >
      <mat-icon>today</mat-icon>
      {{ T.F.TASK.D_REMINDER_VIEW.RESCHEDULE_UNTIL_TOMORROW | translate }}
    </button>
    @if (!isMultiple) {
      <button
        (click)="editReminder(tasks[0], true)"
        mat-menu-item
      >
        <mat-icon>edit</mat-icon>
        {{ T.F.TASK.D_REMINDER_VIEW.RESCHEDULE_EDIT | translate }}
      </button>
    }
    <mat-divider></mat-divider>
    @if (isMultiple) {
      <button
        (click)="markAllAsDone()"
        [disabled]="isDisableControls"
        mat-menu-item
      >
        <mat-icon>done_all</mat-icon>
        {{ T.F.TASK.D_REMINDER_VIEW.COMPLETE | translate }}
      </button>
    } @else if (isAllDeadline) {
      <button
        (click)="play()"
        [disabled]="isDisableControls"
        mat-menu-item
      >
        <mat-icon>play_arrow</mat-icon>
        {{ T.F.TASK.D_REMINDER_VIEW.START | translate }}
      </button>
    }
    @if (!isMultiple && !isAllDeadline && !(isSingleOnToday$ | async)) {
      <button
        (click)="addAllToToday()"
        [disabled]="isDisableControls"
        mat-menu-item
      >
        <mat-icon>wb_sunny</mat-icon>
        {{ T.F.TASK.D_REMINDER_VIEW.ADD_TO_TODAY | translate }}
      </button>
    }
    <button
      (click)="dismissAll()"
      [disabled]="isDisableControls"
      mat-menu-item
    >
      <mat-icon>{{ isAllDeadline ? 'alarm_off' : 'event_busy' }}</mat-icon>
      {{
        (isAllDeadline
          ? isMultiple
            ? T.F.TASK.D_REMINDER_VIEW.CLEAR_ALL_REMINDERS
            : T.F.TASK.D_REMINDER_VIEW.CLEAR_REMINDER
          : isMultiple
            ? T.F.TASK.D_REMINDER_VIEW.UNSCHEDULE_ALL
            : T.F.TASK.D_REMINDER_VIEW.UNSCHEDULE
        ) | translate
      }}
    </button>
    <button
      (click)="dismissAllRemindersOnly()"
      [disabled]="isDisableControls"
      mat-menu-item
    >
      <mat-icon>alarm_off</mat-icon>
      {{
        (isMultiple
          ? T.F.TASK.D_REMINDER_VIEW.DISMISS_ALL_REMINDERS_KEEP_TODAY
          : T.F.TASK.D_REMINDER_VIEW.DISMISS_REMINDER_KEEP_TODAY
        ) | translate
      }}
    </button>
    @if (!isMultiple) {
      <mat-divider></mat-divider>
      <button
        (click)="deleteTask(tasks[0])"
        [disabled]="isDisableControls"
        mat-menu-item
      >
        <mat-icon>delete</mat-icon>
        {{ T.F.TASK.D_REMINDER_VIEW.DELETE | translate }}
      </button>
    }
  </mat-menu>

  <ng-template
    #taskRow
    let-task
  >
    <div
      class="task"
      [attr.data-id]="task.id"
    >
      <div class="title-wrapper">
        <div
          class="due-for"
          [class.emphasized]="(task.dueWithTime || 0) < overdueThreshold"
        >
          @if (task.isDeadlineReminder && task.deadlineWithTime) {
            {{ task.deadlineWithTime | localeDate: 'short' : undefined : locale() }}
          } @else if (task.isDeadlineReminder && task.deadlineDay) {
            {{ task.deadlineDay | localDateStr: '' }}
          } @else {
            {{ task.dueWithTime | localeDate: 'short' : undefined : locale() }}
          }
        </div>
        @if (shouldShowDeadlineScheduleHint(task)) {
          <div class="schedule-hint">
            <mat-icon>event</mat-icon>
            <span>
              {{ T.F.TASK.D_REMINDER_VIEW.SCHEDULED_FOR | translate }}
              @if (task.dueWithTime) {
                {{ task.dueWithTime | localeDate: 'short' : undefined : locale() }}
              } @else {
                {{ task.dueDay | localDateStr: '' }}
              }
            </span>
          </div>
        }
        <div class="title">{{ task.title }}</div>
        <tag-list
          [isShowProjectTagAlways]="true"
          [task]="task"
        ></tag-list>
      </div>
      @if (isMultiple) {
        <div class="actions">
          <button
            (click)="markTaskAsDone(task)"
            [matTooltip]="T.F.TASK.D_REMINDER_VIEW.MARK_AS_DONE | translate"
            [attr.aria-label]="T.F.TASK.D_REMINDER_VIEW.MARK_AS_DONE | translate"
            matTooltipShowDelay="0"
            color=""
            mat-icon-button
            type="button"
          >
            <mat-icon>check</mat-icon>
          </button>
          <button
            [disabled]="
              !task.isDeadlineReminder &&
              !(task.projectId || task.parentId || task.tagIds.length > 0)
            "
            (click)="dismiss(task)"
            [matTooltip]="
              (task.isDeadlineReminder
                ? T.F.TASK.D_REMINDER_VIEW.CLEAR_REMINDER
                : T.F.TASK.D_REMINDER_VIEW.UNSCHEDULE
              ) | translate
            "
            [attr.aria-label]="
              (task.isDeadlineReminder
                ? T.F.TASK.D_REMINDER_VIEW.CLEAR_REMINDER
                : T.F.TASK.D_REMINDER_VIEW.UNSCHEDULE
              ) | translate
            "
            matTooltipShowDelay="0"
            class="hide-xs"
            color=""
            mat-icon-button
            type="button"
          >
            <mat-icon>{{
              task.isDeadlineReminder ? 'alarm_off' : 'event_busy'
            }}</mat-icon>
          </button>
          <button
            (dblclick)="snooze(task, 10)"
            [matMenuTriggerFor]="snoozeMenu"
            [matTooltip]="T.F.TASK.D_REMINDER_VIEW.SNOOZE | translate"
            [attr.aria-label]="T.F.TASK.D_REMINDER_VIEW.SNOOZE | translate"
            matTooltipShowDelay="0"
            color=""
            mat-icon-button
            type="button"
          >
            <mat-icon>snooze</mat-icon>
          </button>
          <button
            (click)="addToToday(task)"
            [matTooltip]="
              ((todayTaskIds$ | async)?.includes(task.id) &&
              (task.dueWithTime || 0) < overdueThreshold
                ? T.F.TASK.D_REMINDER_VIEW.DROP_TIME_KEEP_TODAY
                : T.F.TASK.D_REMINDER_VIEW.SCHEDULE_FOR_TODAY
              ) | translate
            "
            [attr.aria-label]="
              ((todayTaskIds$ | async)?.includes(task.id) &&
              (task.dueWithTime || 0) < overdueThreshold
                ? T.F.TASK.D_REMINDER_VIEW.DROP_TIME_KEEP_TODAY
                : T.F.TASK.D_REMINDER_VIEW.SCHEDULE_FOR_TODAY
              ) | translate
            "
            matTooltipShowDelay="0"
            color=""
            mat-icon-button
            type="button"
          >
            <mat-icon>wb_sunny</mat-icon>
          </button>
          <mat-menu #snoozeMenu="matMenu">
            <button
              (click)="snooze(task, 10)"
              mat-menu-item
            >
              <mat-icon>snooze</mat-icon>
              {{ T.G.MINUTES | translate: { m: 10 } }}
            </button>
            <button
              (click)="snooze(task, 30)"
              mat-menu-item
            >
              <mat-icon>snooze</mat-icon>
              {{ T.G.MINUTES | translate: { m: 30 } }}
            </button>
            <button
              (click)="snooze(task, 60)"
              mat-menu-item
            >
              <mat-icon>snooze</mat-icon>
              {{ T.G.MINUTES | translate: { m: 60 } }}
            </button>
            <button
              (click)="planForTomorrow(task)"
              [disabled]="isDisableControls"
              mat-menu-item
            >
              <mat-icon>today</mat-icon>
              {{ T.F.TASK.D_REMINDER_VIEW.RESCHEDULE_UNTIL_TOMORROW | translate }}
            </button>
            <button
              [disabled]="
                !task.isDeadlineReminder &&
                !(task.projectId || task.parentId || task.tagIds.length > 0)
              "
              (click)="dismiss(task)"
              mat-menu-item
            >
              <mat-icon>{{
                task.isDeadlineReminder ? 'alarm_off' : 'event_busy'
              }}</mat-icon>
              {{
                (task.isDeadlineReminder
                  ? T.F.TASK.D_REMINDER_VIEW.CLEAR_REMINDER
                  : T.F.TASK.D_REMINDER_VIEW.UNSCHEDULE
                ) | translate
              }}
            </button>
            <button
              (click)="dismissReminderOnly(task)"
              mat-menu-item
            >
              <mat-icon>alarm_off</mat-icon>
              {{ T.F.TASK.D_REMINDER_VIEW.DISMISS_REMINDER_KEEP_TODAY | translate }}
            </button>
            <button
              (click)="editReminder(task)"
              mat-menu-item
            >
              <mat-icon>edit</mat-icon>
              {{ T.G.EDIT | translate }}
            </button>
          </mat-menu>
        </div>
      }
    </div>
  </ng-template>
}
