import { Component } from '@angular/core';
import { Router } from '@angular/router';

interface Message {
  text: string;
  isUser: boolean;
  avatar: string;
}

@Component({
  selector: 'app-page-ai',
  templateUrl: './page-ai.component.html',
  styleUrls: ['./page-ai.component.scss']
})
export class PageAiComponent {

  messages: Message[] = [];
  userInput: string = '';

  
  // 在组件的属性中添加一个变量
  showNextAISpeechInput: boolean = false;
  hideToggleButton: boolean = false;
  nextAISpeech: string = '';

  // 添加一个方法来切换输入框的显示状态
  toggleNextAISpeechInput() {
    this.showNextAISpeechInput = !this.showNextAISpeechInput;
    this.hideToggleButton = true;
  }

  // 添加一个方法来设置AI接下来说的话
  setNextAISpeech() {
    // 设置AI接下来说的话为用户输入的内容
    this.nextAISpeech = this.nextAISpeech.trim();
    // 隐藏输入框
    this.showNextAISpeechInput = false;
    //显示控制ai
    this.hideToggleButton = false;
  }

  sendMessage() {
    const userMessage: Message = {
      text: this.userInput,
      isUser: true,
      avatar: '../../assets/images/slide2 .jpg'
    };

    this.messages.push(userMessage);
    this.userInput = '';

    if (this.nextAISpeech) {
      const aiMessage: Message = {
        text: this.nextAISpeech,
        isUser: false,
        avatar: '../../assets/images/AI.png'
      };
      this.messages.push(aiMessage);
      this.nextAISpeech = ''; // 清空 nextAISpeech 变量
      this.showNextAISpeechInput = false; // 隐藏输入框
    } else {
      // 没有设置 AI 接下来说的话时，正常生成 AI 的回复
      // 模拟 AI 回复消息
        setTimeout(() => {
          const aiMessage: Message = {
            text: '好的，祝您生活愉快，再见。',
            isUser: false,
            avatar: '../../assets/images/AI.png'
          };
          this.messages.push(aiMessage);
        }, 500);
      }

        // 隐藏输入框
    this.showNextAISpeechInput = false;
    //显示控制ai
    this.hideToggleButton = false;
    }



    constructor(private router: Router) { }

    ngOnInit(): void {
    }
  
    goToNextPage() {
      this.router.navigate(['/aigc']);
    }
}

 


