import { Component } from '@angular/core';
import { AlertController } from '@ionic/angular';

@Component({
  selector: 'app-bounty-store',
  templateUrl: 'bounty-store.page.html',
  styleUrls: ['bounty-store.page.scss']
})
export class BountyStorePage {

  currentBounty: number = 100;
  totalSpent: number = 50;

  constructor(private alertController: AlertController) {}

  async openPopup(activity: string) {
    const alert = await this.alertController.create({
      header: '消费详情',
      inputs: [
        {
          name: 'amount',
          type: 'number',
          placeholder: '消费金额（元）'
        },
        {
          name: 'note',
          type: 'text',
          placeholder: '备注信息'
        }
      ],
      buttons: [
        {
          text: '取消',
          role: 'cancel'
        },
        {
          text: '确认',
          handler: (data: any) => {
            // 处理确认消费的逻辑，更新赏金余额和消费记录
            const amount = parseFloat(data.amount);
            if (!isNaN(amount) && amount > 0) {
              this.currentBounty -= amount;
              this.totalSpent += amount;
            }
          }
        }
      ]
    });

    await alert.present();
  }

}