import { Injectable } from '@angular/core';
import { AnimationController, ModalController, ToastController } from '@ionic/angular';
import { BadRequestPage } from '../shared/popover/bad-request/bad-request.page';
import { SuccessMessagePage } from '../shared/popover/success-message/success-message.page';
@Injectable({
providedIn: 'root'
})
export class ToastService {
constructor(
public toastController: ToastController,
private animationController: AnimationController,
private modalController: ModalController,
) { }
ngOnInit() {
}
async presentToast(infoMessage: string) {
const toast = await this.toastController.create({
message: infoMessage,
duration: 2000
});
toast.present();
}
async successMessage(message?: any, callback?) {
let notification = document.createElement('div')
notification.className = 'notification'
notification.innerHTML = `
`
document.body.append(notification)
notification.querySelector('.text').innerHTML = message || 'Processo efetuado'
setTimeout(()=>{
if (callback) {
callback()
}
notification.style.right = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
}
async badRequest(message?: string, callback?) {
let notification = document.createElement('div')
notification.className = 'notification'
notification.innerHTML = `
`
notification.style.animationName = 'notification-top'
document.body.append(notification)
notification.querySelector('.text').innerHTML = message || 'Processo não efetuado'
setTimeout(()=>{
if (callback) {
callback()
}
notification.style.right = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
}
async notificationMessage(message?: any, callback?: any,data?: any) {
let notification = document.createElement('div')
notification.className = 'notificationPush'
notification.innerHTML = `
`
let funcx = ()=>{
callback(data);
document.body.removeEventListener('click', funcx);
notification.remove();
}
document.body.append(notification)
document.body.addEventListener('click', funcx);
notification.querySelector('.text').innerHTML = message || 'Processo efetuado'
setTimeout(()=>{
notification.style.top = "-100%"
setTimeout(()=>{
notification.remove()
},1000)
},6000)
}
loading() : HTMLDivElement {
let loader: HTMLDivElement = document.createElement('div')
loader.innerHTML = `
`
document.body.append(loader)
loader.addEventListener('click', ()=>{
// loader.remove()
})
return loader
}
}