import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {ToastType} from '../../services/toasts.service';

@Component({
  selector: 'app-toast',
  standalone: false,
  templateUrl: './toast.component.html',
  styleUrl: './toast.component.css'
})
export class ToastComponent implements OnInit{
    @Input() type!: ToastType
    @Input() message!: string
    @Input() action?: {label: string, onAction: () => void}

    @ViewChild("toastDiv") toastDiv!: ElementRef<HTMLDivElement>

    ngOnInit() {
        setTimeout(() => {
            this.hide();
        }, 3000)
    }

    hide() {
        console.log(this.toastDiv, typeof this.toastDiv)
        this.toastDiv.nativeElement.classList.add('hide')
    }

    getColor() {
        switch (this.type) {
            case ToastType.ERROR: return "red";
            case ToastType.INFO: return "";
            case ToastType.WARNING: return "yellow";
        }
    }

    protected readonly ToastType = ToastType;
}