import {Component, inject, OnInit} from '@angular/core'
import {LabelService} from '../services/label.service'
import {TaskService} from '../services/task.service'
import {ILabel} from '../../models/ILabel'

@Component({
  selector: 'app-tasks-by-label',
  templateUrl: './tasks-by-label.page.html',
  styleUrls: ['./tasks-by-label.page.scss'],
})
export class TasksByLabelPage implements OnInit {
  fabIsVisible = true

  labelService = inject(LabelService)
  taskService = inject(TaskService)

  labels: ILabel[] = this.labelService.labels

  // Indicates whether the labels corresponding with a specific index are expanded.
  expanded = Array(this.labels.length).fill(false)

  constructor() { }

  ngOnInit() {
  }

  /**
   * A handler that ensures that the floating action button is hidden when the
   * user scrolls through the task list.
   */
  logScrollStart(): void {
    this.fabIsVisible = false
  }

  /**
   * A handler that shows the FAB after scrolling has stopped and 1.5 seconds
   * have passed.
   */
  logScrollEnd(): void {
    setTimeout(() => this.fabIsVisible = true, 1500)
  }
}
