|
|
import { Component, Renderer2, OnInit, OnDestroy } from '@angular/core'; |
|
|
import { Router } from '@angular/router'; |
|
|
import { CommonModule } from '@angular/common'; |
|
|
import { RouterModule } from '@angular/router'; |
|
|
import { SignInComponent } from './sign-in/sign-in.component'; |
|
|
import { SignUpComponent } from './sign-up/sign-up.component'; |
|
|
|
|
|
@Component({ |
|
|
selector: 'app-homepage', |
|
|
standalone: true, |
|
|
templateUrl: './homepage.component.html', |
|
|
styleUrls: ['./homepage.component.css'], |
|
|
imports: [CommonModule, RouterModule, SignInComponent, SignUpComponent] |
|
|
}) |
|
|
export class HomepageComponent implements OnInit, OnDestroy { |
|
|
|
|
|
showSignIn = false; |
|
|
showSignUp = false; |
|
|
showTourOverlay = false; |
|
|
|
|
|
|
|
|
selectedNav: string = ''; |
|
|
selectedLanguage = 'en-US'; |
|
|
|
|
|
|
|
|
selectedInfo: string | null = null; |
|
|
showDetails = false; |
|
|
|
|
|
|
|
|
showInfoDialog = false; |
|
|
|
|
|
welcomeText = `Py-Detect is an intelligent lie detection platform designed to analyze human responses and uncover hidden truths. During each session, we also record and analyze body language using video to provide deeper behavioral insights. Whether you're evaluating a suspect, interviewing a student, or conducting sensitive assessments, Py-Detect uses advanced algorithms to ask targeted questions and deliver a truthfulness score—a percentage-based estimate of how likely the person is being honest.`; |
|
|
|
|
|
private authCloseListener = () => { this.closeModal(); }; |
|
|
|
|
|
constructor(private router: Router, private renderer: Renderer2) { } |
|
|
|
|
|
ngOnInit() { |
|
|
this.renderer.addClass(document.body, 'homepage-bg'); |
|
|
|
|
|
const savedLang = localStorage.getItem('pydetect_lang'); |
|
|
if (savedLang) { |
|
|
this.selectedLanguage = savedLang; |
|
|
document.documentElement.lang = savedLang; |
|
|
} |
|
|
|
|
|
window.addEventListener('auth-close', this.authCloseListener as EventListener); |
|
|
} |
|
|
|
|
|
ngOnDestroy() { |
|
|
this.renderer.removeClass(document.body, 'homepage-bg'); |
|
|
window.removeEventListener('auth-close', this.authCloseListener as EventListener); |
|
|
} |
|
|
|
|
|
|
|
|
openSignIn() { this.showSignIn = true; this.showSignUp = false; document.body.classList.add('modal-open'); } |
|
|
openSignUp() { this.showSignUp = true; this.showSignIn = false; document.body.classList.add('modal-open'); } |
|
|
closeModal() { this.showSignIn = this.showSignUp = false; document.body.classList.remove('modal-open'); } |
|
|
|
|
|
|
|
|
handleSignInSuccess() { |
|
|
this.closeModal(); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
openInfoDialog() { this.showInfoDialog = true; } |
|
|
closeInfoDialog() { this.showInfoDialog = false; } |
|
|
|
|
|
|
|
|
toggleInfo(info: string) { |
|
|
this.selectedInfo = (this.selectedInfo === info) ? null : info; |
|
|
} |
|
|
|
|
|
|
|
|
private easeInOutCubic(t: number): number { |
|
|
return t <0.5 ?4 * t * t * t :1 - Math.pow(-2 * t +2,3) /2; |
|
|
} |
|
|
|
|
|
|
|
|
private smoothScrollTo(targetY: number, duration =1800): void { |
|
|
const startY = window.scrollY || window.pageYOffset; |
|
|
const distance = targetY - startY; |
|
|
const startTime = performance.now(); |
|
|
const step = (now: number) => { |
|
|
const elapsed = now - startTime; |
|
|
const progress = Math.min(elapsed / duration,1); |
|
|
const eased = this.easeInOutCubic(progress); |
|
|
window.scrollTo(0, startY + distance * eased); |
|
|
if (progress <1) requestAnimationFrame(step); |
|
|
}; |
|
|
requestAnimationFrame(step); |
|
|
} |
|
|
|
|
|
private getYForElement(el: HTMLElement, headerOffset =80): number { |
|
|
const rect = el.getBoundingClientRect(); |
|
|
const scrollTop = window.scrollY || window.pageYOffset; |
|
|
return rect.top + scrollTop - headerOffset; |
|
|
} |
|
|
|
|
|
|
|
|
public navigateHome(): void { |
|
|
this.selectedNav = 'home'; |
|
|
const performScroll = () => this.smoothScrollTo(0,1800); |
|
|
if (this.router.url === '/' || this.router.url === '') { |
|
|
performScroll(); |
|
|
} else { |
|
|
this.router.navigate(['/']).then(() => setTimeout(performScroll,0)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public scrollToFeatures(event: Event): void { |
|
|
event.preventDefault(); |
|
|
this.selectedNav = 'features'; |
|
|
const el = document.getElementById('features'); |
|
|
if (el) { |
|
|
const y = this.getYForElement(el,80); |
|
|
this.smoothScrollTo(y,1800); |
|
|
} |
|
|
} |
|
|
public scrollToMission(event: Event): void { |
|
|
event.preventDefault(); |
|
|
this.selectedNav = 'mission'; |
|
|
const el = document.getElementById('mission'); |
|
|
if (el) { |
|
|
const y = this.getYForElement(el,80); |
|
|
this.smoothScrollTo(y,1800); |
|
|
} |
|
|
} |
|
|
public scrollToHowToUse(event: Event): void { |
|
|
event.preventDefault(); |
|
|
this.selectedNav = 'how-to-use'; |
|
|
const el = document.getElementById('how-to-use'); |
|
|
if (el) { |
|
|
const y = this.getYForElement(el,80); |
|
|
this.smoothScrollTo(y,1800); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public scrollToHowItWorks(event: Event): void { |
|
|
event.preventDefault(); |
|
|
this.selectedNav = 'how-it-works'; |
|
|
const el = document.getElementById('how-it-works'); |
|
|
if (el) { |
|
|
const y = this.getYForElement(el,80); |
|
|
this.smoothScrollTo(y,1800); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public markSelected(key: string): void { |
|
|
this.selectedNav = key; |
|
|
} |
|
|
|
|
|
|
|
|
public onLanguageChange(lang: string): void { |
|
|
this.selectedLanguage = lang || 'en'; |
|
|
localStorage.setItem('pydetect_lang', this.selectedLanguage); |
|
|
document.documentElement.lang = this.selectedLanguage; |
|
|
} |
|
|
|
|
|
|
|
|
public scrollToSection(ev: Event, id: string) { |
|
|
ev.preventDefault(); |
|
|
this.markSelected(id); |
|
|
const el = document.getElementById(id); |
|
|
if (el) { |
|
|
|
|
|
const y = this.getYForElement(el,80); |
|
|
this.smoothScrollTo(y,1800); |
|
|
} |
|
|
} |
|
|
} |
|
|
|