import { Component, OnInit, OnDestroy } from '@angular/core';
import { IonicModule } from '@ionic/angular';

@Component({
  selector: 'app-discount-banner',
  templateUrl: './discount-banner.component.html',
  styleUrls: ['./discount-banner.component.scss'],
  standalone: true,
  imports: [IonicModule],
})
export class DiscountBannerComponent implements OnInit, OnDestroy {
  countdown: string = '';
  private countdownInterval: any;
  ngOnInit() {
    const endTime = new Date('2025-01-01T00:00:00');
    this.countdownInterval = setInterval(() => {
      const now = new Date();
      const diff = endTime.getTime() - now.getTime();
      const days = Math.floor(diff / (1000 * 60 * 60 * 24));
      const hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
      const minutes = Math.floor((diff / (1000 * 60)) % 60);
      const seconds = Math.floor((diff / 1000) % 60);
      this.countdown = `${days}天 ${hours}小时 ${minutes}分 ${seconds}秒`;
    }, 1000);
  }

  ngOnDestroy() {
    if (this.countdownInterval) {
      clearInterval(this.countdownInterval);
    }
  }
}
