import { Component } from '@angular/core';
import { HeaderComponent } from '../header/header.component';
import { Route } from '@angular/router';

@Component({
  selector: 'app-contest',
  standalone: true,
  imports: [HeaderComponent, ],
  templateUrl: './contest.component.html',
  styleUrl: './contest.component.css'
})
export class ContestComponent {
  days: number = 0;
  hours: number = 0;
  minutes: number = 0;
  seconds: number = 0;
  private countdownInterval: any;
  constructor(){
    
  }

  targetDate: Date = new Date('2025-12-31T23:59:59');

  ngOnInit(): void {
    this.startCountdown();
  }
scrollToSection(sectionId: string) {
  const element = document.getElementById(sectionId);
  if (element) {
    element.scrollIntoView({ behavior: 'smooth', block: 'start' });
  }
}
  ngOnDestroy(): void {
    if (this.countdownInterval) {
      clearInterval(this.countdownInterval);
    }
  }

  startCountdown() {
    this.countdownInterval = setInterval(() => {
      const now = new Date().getTime();
      const distance = this.targetDate.getTime() - now;

      if (distance < 0) {
        clearInterval(this.countdownInterval);
        this.days = this.hours = this.minutes = this.seconds = 0;
        return;
      }

      this.days = Math.floor(distance / (1000 * 60 * 60 * 24));
      this.hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      this.minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
      this.seconds = Math.floor((distance % (1000 * 60)) / 1000);
    }, 1000);
  }
createnew(){
window.location.href = '/new'; 
}
}
