import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';

@Component({
  selector: 'app-art-detail',
  templateUrl: './art-detail.component.html',
  styleUrls: ['./art-detail.component.scss'],
  standalone: true,
  imports: [IonicModule, CommonModule]
})
export class ArtDetailComponent implements OnInit {
  artId: string = '';
  artwork: any = null;

  constructor(
    private route: ActivatedRoute,
    private router: Router
  ) {
    // 获取路由传递的数据
    const navigation = this.router.getCurrentNavigation();
    if (navigation?.extras.state) {
      this.artwork = navigation.extras.state['artwork'];
    }
  }

  ngOnInit() {
    this.artId = this.route.snapshot.paramMap.get('id') || '';
    if (!this.artwork) {
      this.loadArtwork();
    }
  }

  loadArtwork() {
    // 如果没有通过路由获取到数据，则加载默认数据
    this.artwork = {
      id: this.artId,
      image: '../../assets/img/xingkong.png',
      title: '梵高-星空高清画作',
      description: '致敬梵高 #艺术品 #星空',
      avatarUrl: '../../assets/img/book1.png',
      userName: '星空艺术家',
      date: '12-01',
      likes: 1687,
      category: 'art'
    };
  }

  // 添加点赞功能
  toggleLike() {
    if (this.artwork) {
      this.artwork.isLiked = !this.artwork.isLiked;
      this.artwork.likes += this.artwork.isLiked ? 1 : -1;
    }
  }

  // 添加分享功能
  shareArtwork() {
    // 实现分享逻辑
    console.log('Sharing artwork:', this.artwork.title);
  }
}
