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

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

  }
  userPrompt: string = "请输入项目的简要内容"
  promptInput(ev: any) {
    this.userPrompt = ev.detail.value;
  }
  imagineWork: ImagineWork | undefined
  images: Array<string> = []
  constructor(
  ) {
    // 示例任务，自己生成图片后请存储新的ID
    this.imagineWork = new ImagineWork("lpJGiFwWeA");
    this.imagineWork.fetchTask().then(work => {
      this.images = this.imagineWork?.images || [];
    })
  }

  PictureDescResult = ``
  async createImage() {
    this.imagineWork = new ImagineWork();
    let PromptTemplate = `
    您是一名专业的logo设计师，请您根据项目的内容，将其描述的内容等用最简短的语言表达，
    项目内容如下：
    ${this.userPrompt}
    `
    let completion = new FmodeChatCompletion([
      { role: "system", content: "" },
      { role: "user", content: PromptTemplate }
    ])
    completion.sendCompletion().subscribe((message: any) => {
      // 打印消息体
      console.log(message.content)
      // 赋值消息内容给组件内属性
      this.PictureDescResult = message.content
      if (message?.complete) {
        let PicturePrompt = `${this.PictureDescResult}\n根据描述的内容生成一张与项目名称“AI艺速”相关的logo图片，画面包含元素：画笔，ai字母，风。风格简约大气，画面以彩色为主色调且不带任何文字(画面越简单越好)`
        let options: DalleOptions = { prompt: PicturePrompt }
        this.imagineWork?.draw(options).subscribe(work => {
          console.log("imagineWork", work?.toJSON())
          console.log("images", work?.get("images"))
          if (work?.get("images")?.length) {
            this.images = work?.get("images");
          }
        })
      }
    })
  }

}

// # "AI艺速"项目策划书
// 项目设想

//   - 行业：兴趣教育与技能培训领域
//     - 用户：对各类新鲜事物抱有三分钟热度、渴望快速入门体验的广大人群
//       - 功能：通过程序依据用户感兴趣的内容提供相应的浅显教学步骤及基础指导。
