import { Component, OnInit } from '@angular/core';
import { FmodeChatCompletion } from 'fmode-ng';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-page-exercise-result',
  templateUrl: './page-exercise-result.component.html',
  styleUrls: ['./page-exercise-result.component.scss'],
})
export class PageExerciseResultComponent implements OnInit {
  userPrompt: string = '飞码产品LOGO，独角兽头部形象，极简风格，棱角分明，线条勾勒，蓝色紫色搭配。';
  userData: any;  // 用于存储传递的数据
  responseMsg: string = '';

  constructor(private router: Router, private activatedRoute: ActivatedRoute) {}

  ngOnInit(): void {
    // 获取路由状态中的用户数据
    if (history.state && history.state.userData) {
      this.userData = history.state.userData;
    }
  }

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

  sendMessage() {
    console.log('create');
    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;
    });
  }
}
