import { Component, Input } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ButtonComponent, ContainerComponent } from 'ui-essentials'; import { CTASectionConfig } from '../../interfaces/conversion.interfaces'; @Component({ selector: 'ui-cta-section', standalone: true, imports: [ CommonModule, ButtonComponent, ContainerComponent, ], template: `
{{ getTimeRemaining().days }} Days
{{ getTimeRemaining().hours }} Hours
{{ getTimeRemaining().minutes }} Minutes
{{ config.urgency.text }} Only {{ config.urgency.remaining }} left!

{{ config.title }}

{{ config.description }}

{{ config.ctaPrimary.text }} {{ config.ctaSecondary.text }}
`, styleUrls: ['./cta-section.component.scss'] }) export class CTASectionComponent { @Input() config!: CTASectionConfig; getTimeRemaining(): { days: number; hours: number; minutes: number; seconds: number } { if (!this.config.urgency?.endDate) { return { days: 0, hours: 0, minutes: 0, seconds: 0 }; } const now = new Date().getTime(); const end = this.config.urgency.endDate.getTime(); const difference = end - now; if (difference > 0) { return { days: Math.floor(difference / (1000 * 60 * 60 * 24)), hours: Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)), minutes: Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60)), seconds: Math.floor((difference % (1000 * 60)) / 1000) }; } return { days: 0, hours: 0, minutes: 0, seconds: 0 }; } }