import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import Swiper from 'swiper';
import { NavController } from '@ionic/angular'; // 导入 NavController

@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss']
})
export class Tab2Page implements OnInit {

  @ViewChild("slide1Comp") slide1Comp: ElementRef | undefined;

  constructor(private navCtrl: NavController) {} // 注入 NavController

  ngOnInit(): void {
    // 延迟500毫秒加载
    setTimeout(() => {
      this.initSwiper();
    }, 500);
  }

  // 初始化轮播图
  slide1: Swiper | undefined;
  initSwiper() {
    console.log(this.slide1Comp);
    this.slide1 = new Swiper(this.slide1Comp?.nativeElement, {
      loop: true,
      autoplay: {
        delay: 5000,
      },
      mousewheel: {
        forceToAxis: true,
      },
      pagination: {
        el: ".swiper-pagination",
        clickable: true
      },
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      }
    });
  }

  slideNext() {
    this.slide1?.slideNext();
  }

  slidePrev() {
    this.slide1?.slidePrev();
  }

  itemTags = [
    { category: '动物', relatedInfo: '猫是一种常见的宠物。' },
    { category: '植物', relatedInfo: '仙人掌是一种耐旱的植物。' },
  ];

  userInfo = {
    username: '张三',
    avatar: 'assets/images/avatar.png',
    phoneNumber: '13800138000',
  };

  imageCategories = [
    { name: '植物大全', link: 'https://tian.nju.edu.cn/plantae/bje/list.psp' },
    { name: '动物大全', link: 'https://www.aidongwu.net/#google_vignette' },
    { name: '品牌大全', link: 'https://wenku.baidu.com/view/f13a853231126edb6f1a1036.html?fr=aladdin664466&ind=1&aigcsid=0&qtype=0&lcid=1&queryKey=%E5%93%81%E7%89%8C%E5%A4%A7%E5%85%A8&_wkts_=1720441872550&bdQuery=%E5%93%81%E7%89%8C%E5%A4%A7%E5%85%A8' },
    { name: '文化大全', link: 'http://ichpc.org.cn/case/case3/' },
    { name: '科技大全', link: 'http://www.kepu.gov.cn/index.html' },
  ];

  productImages = [
    { platform: '京东', link: 'https://www.jd.com/?cu=true&utm_source=baidu-pinzhuan&utm_medium=cpc&utm_campaign=t_288551095_baidupinzhuan&utm_term=0f3d30c8dba7459bb52f2eb5eba8ac7d_0_5f995b18e5f944fda94e86e5f7efd14d', image: 'assets/images/product1.jpg', status: '已生成' },
    { platform: '淘宝', link: 'https://item.taobao.com/123456789.html', image: 'assets/images/product2.jpg', status: '待生成' },
  ];

  filteredQuestions = [
    { text: "1" },
    { text: "1" },
    { text: "1" },
    { text: "1" },
  ];

  openLink(link: string) {
    window.open(link, '_blank'); // 在新标签页打开链接
  }
}