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

@Component({
  selector: 'app-edit-tag',
  templateUrl: './edit-tag.component.html',
  styleUrls: ['./edit-tag.component.scss'],
  standalone: true,
  imports:[
    IonInput,IonButton,IonChip,IonLabel
    
  ]
})
export class EditTagComponent  implements OnInit {

  /**
   * 用户输入
   */
  userInput:string = "";
  onInput(ev:any){
    this.userInput = ev.detail.value;
  }

  /**
   * 标签列表
   */
  tags:Array<string> = [];
  addTag(){
    // 如果标签为空，则不添加
    if(this.userInput==""){
      return;
    }
    this.tags.push(this.userInput);
    this.userInput = "";
    this.onTagChange.emit(this.tags);
    console.log("传入的标签：",this.tags);
  }

  removeTag(tag:string){
    // this.tags = this.tags.filter((item)=>item!=tag);
    let idx = this.tags.findIndex((item)=>item==tag);
    this.tags.splice(idx,1);
  }

  @Output()
  onTagChange:EventEmitter<Array<string>> = new EventEmitter<Array<string>>();
  
  constructor() { }

  ngOnInit() {}

}
