import { Component, OnInit } from '@angular/core';
import { IonButton, IonContent, IonHeader, IonInput, IonTitle, IonToolbar } from '@ionic/angular/standalone';
import { IonTextarea } from '@ionic/angular/standalone';
import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';

@Component({
  selector: 'app-interest-test',
  templateUrl: './interest-test.component.html',
  styleUrls: ['./interest-test.component.scss'],
  standalone: true,
  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
    IonTextarea, IonInput, MarkdownPreviewModule
  ],
})
export class InterestTestComponent implements OnInit {
  ngOnInit(): void {

  }
  constructor() { }
  // 用户输入提示词
  department: string = "请给出学习方向，例如：绘画"
  departmentInput(ev: any) {
    this.department = ev.detail.value;
  }
  // 用户输入提示词
  userPrompt: string = "请具体描述您想要学习/感兴趣的内容"
  promptInput(ev: any) {
    this.userPrompt = ev.detail.value;
  }
  // 属性：组件内用于展示消息内容的变量
  responseMsg: any = ""
  // 方法：实例化completion对象，传入消息数组，并订阅生成的可观察对象。
  isComplete: boolean = false;
  sendMessage() {
    console.log("开始制定学习计划")
    let PromptTemplate = `
    您作为一名专业的${this.department}兴趣规划师，请根据用户的描述，分点给出初步的实现方案并给出一些建议，
    以下是用户的描述${this.userPrompt}
    `
    let completion = new FmodeChatCompletion([
      { role: "system", content: "" },
      { role: "user", content: PromptTemplate }
    ])
    completion.sendCompletion().subscribe((message: any) => {
      // 打印消息体
      console.log(message.content)
      // 赋值消息内容给组件内属性
      this.responseMsg = message.content
      if (message?.complete) (
        this.isComplete = true
      )
    })
  }
  makeMindMap() {
    console.log("开始生成思维导图")
  }
}
