import { Component } from '@angular/core';
import { IonicModule, ModalController } from '@ionic/angular';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

@Component({
  selector: 'app-task-modal',
  templateUrl: './task-modal.component.html',
  styleUrls: ['./task-modal.component.scss'],
  standalone: true,
  imports: [IonicModule, CommonModule, FormsModule]
})
export class TaskModalComponent {
  task = {
    title: '',
    tags: [] as string[],
    dueDate: new Date().toISOString(),
    subtasks: [''] as string[]
  };

  newTag = '';

  constructor(private modalCtrl: ModalController) {}

  addTag() {
    if (this.newTag) {
      this.task.tags.push(this.newTag);
      this.newTag = '';
    }
  }

  removeTag(index: number) {
    this.task.tags.splice(index, 1);
  }

  addSubtask() {
    this.task.subtasks.push('');
  }

  removeSubtask(index: number) {
    this.task.subtasks.splice(index, 1);
  }

  cancel() {
    this.modalCtrl.dismiss();
  }

  confirm() {
    this.modalCtrl.dismiss(this.task);
  }
}
