import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { IonInput, IonButton, IonChip, IonIcon, IonLabel } from '@ionic/angular/standalone';

@Component({
  selector: 'edit-tag',
  templateUrl: './edit-tag.component.html',
  styleUrls: ['./edit-tag.component.scss'],
  standalone: true,
  imports: [IonInput, IonButton, IonChip, IonIcon, IonLabel],
})
export class EditTagComponent implements OnInit {
  @Output() onTagAdd = new EventEmitter<string>();

  user_tag: string[] = [];
  textResult: string = "";

  userInput(ev: any) {
    this.textResult = ev.detail.value;
  }

  Add_tags() {
    if (this.textResult.trim()) {
      this.user_tag.push(this.textResult.trim());
      this.onTagAdd.emit(this.textResult.trim());
      this.textResult = "";
    }
  }

  Delete_tag(tag: string) {
    const index = this.user_tag.indexOf(tag);
    if (index > -1) {
      this.user_tag.splice(index, 1);
    }
  }

  constructor() { }

  ngOnInit() { }
}
