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

@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[],

    subtasks: [''] as string[],
    note: ''  // 新增备注字段
  };

  newTag = '';

  constructor(private modalCtrl: ModalController) {}

  // 新增模态控制器实现
  addTag() {
    if (this.newTag) {
      this.task.tags.push(this.newTag.trim());
      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() {
    if (!this.task.title) {
      return;
    }
    this.modalCtrl.dismiss(this.task);
  }
}
