import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';  // 引入 IonicModule
import { IonTextarea } from '@ionic/angular/standalone';  // 引入 IonicModule
import { ExploreContainerComponent } from '../explore-container/explore-container.component';
import { FmodeChatCompletion, MarkdownPreviewModule } from 'fmode-ng';

@Component({
  selector: 'app-tab3',
  templateUrl: 'tab3.page.html',
  styleUrls: ['tab3.page.scss'],
  standalone: true,
  imports: [
    ExploreContainerComponent,
    IonicModule, // 引入 IonicModule
    MarkdownPreviewModule,
  ],
})
export class Tab3Page {
  xiguan: string = "";
  jikou: string = "";
  userPrompt: string = "";
  responseMsg: any = "";
  isComplete: boolean = false;

  constructor() {}

  ngOnInit() {}

  xiguanInput(ev: any) {
    this.xiguan = ev.detail.value;
  }

  jikouInput(ev: any) {
    this.jikou = ev.detail.value;
  }

  promptInput(ev: any) {
    this.userPrompt = ev.detail.value;
  }

  sendMessage() {
    console.log("create");

    let PromptTemplate = `
    你是一名专业的饮食营养规划师，拥有丰富的营养学背景和实践经验。你的工作是为不同需求的人群提供个性化的饮食规划，帮助他们实现健康目标，如减肥、增肌、健康维护或疾病管理。
    你可以根据用户的需求为客户设计量身定制具体的饮食方案。
    当前来咨询用户的饮食习惯是${this.xiguan},用户的饮食偏好是${this.jikou}需求描述是${this.userPrompt}`;

    let completion = new FmodeChatCompletion([
      { role: "system", content: "" },
      { role: "user", content: this.userPrompt }
    ]);

    completion.sendCompletion().subscribe((message: any) => {
      console.log(message.content);
      this.responseMsg = message.content;
      if (message?.complete) {
        this.isComplete = true;
      }
    });
  }
}