import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HeaderComponent } from '../../components/header/header.component';
import { SortingTabsComponent } from '../../components/sorting-tabs/sorting-tabs.component';
import { StatsSectionComponent } from '../../components/stats-section/stats-section.component';
import { MenuCardComponent } from '../../components/menu-card/menu-card.component';
import { BottomNavComponent } from '../../components/bottom-nav/bottom-nav.component';
import { MenuService } from '../../services/menu.service';
import { CultureService } from '../../services/culture.service';
import { MenuItem } from '../../models/menu-item.model';
import { CultureInfo } from '../../models/culture-info.model';
import { ChartDirective } from '../../shared/chart/chart.directive';

@Component({
  selector: 'app-discover',
  standalone: true,
  imports: [
    CommonModule,
    HeaderComponent,
    SortingTabsComponent,
    StatsSectionComponent,
    MenuCardComponent,
    BottomNavComponent,
    ChartDirective
  ],
  templateUrl: './discover.component.html',
  styleUrls: ['./discover.component.scss']
})
export class DiscoverComponent implements OnInit {
  menuItems: MenuItem[] = [];
  activeSort: string = 'recommend';
  showCultureModal = false;
  currentCulture?: CultureInfo;
  
  constructor(
    private menuService: MenuService,
    private cultureService: CultureService
  ) {}
  
  ngOnInit(): void {
    this.loadMenuItems();
  }
  
  loadMenuItems(): void {
    this.menuItems = this.menuService.getMenuItems(this.activeSort);
  }
  
  onSortChange(sortType: string): void {
    this.activeSort = sortType;
    this.loadMenuItems();
  }
  
  onViewCulture(item: MenuItem): void {
    this.currentCulture = this.cultureService.getCultureInfo(item.id);
    this.showCultureModal = true;
  }
  
  onAddToCart(item: MenuItem): void {
    // 这里可以添加购物车逻辑
    console.log('Added to cart:', item);
  }
  
  closeModal(): void {
    this.showCultureModal = false;
  }
}