import { Component, OnInit } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { Swiper } from 'swiper';
import { ConnectTaskService } from '../../../services/connectTask.service';
import * as Parse from 'parse';
import {
  AlertController,
  LoadingController,
} from '../../ionic-standalone.modules';
import { AiChatService } from '../../../services/aichart.service';
import { Router } from '@angular/router';
@Component({
  selector: 'app-live-review',
  templateUrl: './live-review.component.html',
  styleUrls: ['./live-review.component.scss'],
  standalone: true,
  imports: [IonicModule],
})
export class LiveReviewComponent implements OnInit {
  roomList: Array<any> = [];
  constructor(
    private router: Router,
    private aiServ: AiChatService,
    private loadingCtrl: LoadingController,
    private connectTask: ConnectTaskService,
  ) { }

  ngOnInit() {
    this.refresh()
  }
  async refresh() {
    const loading = await this.loadingCtrl.create({
      message: '正在加载',
    });
    loading.present();
    await this.getRoom();
    setTimeout(() => {
      this.initSwiperTimeEvent();
      loading.dismiss();
    }, 100);
  }
  async getRoom() {
    let uid = Parse.User.current()?.id;
    const userList = Array.from(this.connectTask.onlineUserList);
    let data = await this.aiServ.getRooms({
      uid: uid,
      users: userList,
      sex:'女'
    });
    this.roomList = data;

  }
  initSwiperTimeEvent() {
    // 初始化轮播图
    let swiper = new Swiper('.poster', {
      loop: false, // 循环模式选项
      observer: false, //修改swiper自己或子元素时，自动初始化swiper
      observeParents: true, //修改swiper的父元素时，自动初始化swiper
      // autoplay: {
      //   delay: 3000,
      // },
      direction: 'vertical',
    });
    swiper.on('slideChange', function (event: any) {
      // console.log(event);
    });
  }

  toUrl(user:string){
    this.router.navigate(['/user/profile/',user])
  }
}
