import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import * as Parse from 'parse';


interface Item {
  name: string;
  imgUrl:string;
  price: number;
  sales: number;
  choice:number;
 detailId: string;
}

@Component({
  selector: 'app-page-cart',
  templateUrl: './page-cart.component.html',
  styleUrls: ['./page-cart.component.scss']
})
export class PageCartComponent implements OnInit {
  items: Item[] = [];
  currentContent: string = 'cart-one';

  constructor(private router: Router) {}

  ngOnInit() {
    this.getData();
  }

  getData() {
    (Parse as any).serverURL = 'https://web2023.fmode.cn/parse';
    Parse.initialize('dev');

    let query: Parse.Query;
    if (this.currentContent === 'cart-one') {
      query = new Parse.Query('LcmCartOne');
    } else if (this.currentContent === 'cart-two') {
      query = new Parse.Query('LcmCartTwo');
    } else if (this.currentContent === 'cart-three') {
      query = new Parse.Query('LcmCartThree');
    } else {
      return; // 如果没有匹配的模块，退出方法
    }

    query.find()
      .then((results) => {
        this.items = results.map((result) => ({
          imgUrl:result.get('imgUrl'),
          name: result.get('name'),
          price: result.get('price'),
          sales: result.get('sales'),
          choice:result.get('choice'),
         detailId: result.get('detailId')
        }));
        console.log(this.items);
      })
      .catch((error) => {
        console.error('Error retrieving data from Parse:', error);
      });
  }

  showContent(content: string) {
    this.currentContent = content;
    this.getData();
  }
  handleInput(event: any) {
    // 处理输入事件的逻辑
  }
}
