import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
  ionicStandaloneModules,
  LoadingController,
  ToastController,
} from '../../../modules/ionic-standalone.modules';
import { LiveService } from '../../../services/live.service';
import * as Parse from 'parse';

@Component({
  selector: 'app-appraise',
  templateUrl: './appraise.component.html',
  styleUrls: ['./appraise.component.scss'],
  standalone: true,
  imports: [...ionicStandaloneModules, CommonModule],
})
export class AppraiseComponent implements OnInit {
  active: string = 'negativeTags';
  negativeTags: Array<string> = [
    '没礼貌',
    '不好看',
    '不专业',
    '态度差',
    '声音难听',
    '内容无聊',
    '互动少',
    '妆容差',
    '发型乱',
    '背景杂乱',
    '动作僵硬',
    '表情不自然',
    '内容重复',
    '没有创意',
    '不幽默',
  ];
  positiveTags: Array<string> = [
    '很礼貌',
    '很好看',
    '很专业',
    '态度好',
    '声音好听',
    '内容有趣',
    '互动多',
    '妆容精致',
    '发型时尚',
    '背景整洁',
    '动作自然',
    '表情生动',
    '内容新颖',
    '有创意',
    '很幽默',
  ];
  list: Array<string> = this.positiveTags;
  checkTags = new Set();
  constructor(
    private toastController: ToastController,
    private loadingCtrl: LoadingController,
    public liveService: LiveService
  ) {}

  ngOnInit() {}
  segmentChanged(e: any) {
    let { value } = e.detail;
    // this.active = value;
    console.log(value);
    this.list = this[value]
    this.checkTags = new Set();
  }
  async onCheck(tag:string){
    if(this.checkTags.has(tag)){
      this.checkTags.delete(tag)
    }else{
      if(this.checkTags.size >= 3){
        const toast = await this.toastController.create({
          message: '不超过3项',
          color: 'danger',
          duration: 1000,
        });
        toast.present();
        return;
      }
      this.checkTags.add(tag)
    }
  }
  confirm() {
    this.onComment()
  }

  async onComment() {
    const loading = await this.loadingCtrl.create({
      message: '加载中',
    });
    loading.present();
    if(this.checkTags.size > 3 || this.checkTags.size == 0){
      loading.dismiss();
      const toast = await this.toastController.create({
        message: this.checkTags.size == 0 ? '至少选择一项' : '不超过3项',
        color: 'danger',
        duration: 1000,
      });
      toast.present();
      return;
    }
    let obj = Parse.Object.extend('DramaPostLog');
    let postLog = new obj();
    postLog.set('room', {
      __type: 'Pointer',
      className: 'Room',
      objectId: this.liveService.room?.id,
    });
    postLog.set('company', {
      __type: 'Pointer',
      className: 'Company',
      objectId: this.liveService?.company,
    });
    postLog.set('user', {
      __type: 'Pointer',
      className: '_User',
      objectId: Parse.User.current()?.id,
    });
    postLog.set('type', 'comment');
    // postLog.set('credit', star)
    postLog.set('tags',Array.from(this.checkTags))
    postLog.set('isVerify', true)
    await postLog.save();
    loading.dismiss();
    this.liveService.isOpenEvaluate = false;
    this.checkTags = new Set();
  }
}
