import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { IonButton, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonChip, IonIcon, IonInput, IonItem, IonLabel, IonList, IonRadio, IonRadioGroup, IonSelect, IonSelectOption, IonTextarea } from '@ionic/angular/standalone';


interface WordEntry{
  name :string // 名称
  type:"人物"|"道具"|"场景" // 类型
  important:"重要"|"不重要" //  重要程度
  desc:string // 词条简介
  tags?:Array<string> // 别名标签
  newTag?:string
}


/**
 * 词条编辑组件
 */
@Component({
  selector: 'comp-word-entry',
  templateUrl: './comp-word-entry.component.html',
  styleUrls: ['./comp-word-entry.component.scss'],
  standalone: true,
  imports:[
    IonCard,IonCardHeader,IonCardContent,IonCardTitle,IonCardSubtitle,
    IonList,IonItem,IonLabel,IonIcon,IonSelect,IonSelectOption,
    IonInput,IonTextarea,
    IonButton,
    IonRadio,IonRadioGroup,IonChip
  ]
})
export class CompWordEntryComponent  implements OnInit {

  @Input()
  entryList:Array<WordEntry> = []

  @Output()
  entryListChange:EventEmitter<Array<WordEntry>> = new EventEmitter<Array<WordEntry>>()

  onIonChange(entry:any,key:string,ev:any){
    entry[key] = ev.detail.value;
  }

  constructor() { }

  ngOnInit() {}

  addEntry(){
    this.entryList.push({
      name:"",
      type:"人物",
      important:"重要",
      desc:"简介"
    })
    this.entryListChange.emit(this.entryList)
  }
  deleteEntry(idx:number){
    this.entryList.splice(idx,1);
    this.entryListChange.emit(this.entryList)

  }
  // 标签条件
  newTag:string = ""
  addTag(entry:any){
    if(!entry.tags) entry.tags = []
    if(!entry.newTag) return
    entry.tags.push(entry.newTag)
    entry.newTag = ""
  }


}
