import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import { PublicationsService } from 'src/app/services/publications.service';
import { ToastService } from 'src/app/services/toast.service';
import { ThemeService } from 'src/app/services/theme.service'

@Component({
  selector: 'app-actions-options',
  templateUrl: './actions-options.page.html',
  styleUrls: ['./actions-options.page.scss'],
})
export class ActionsOptionsPage implements OnInit {

  id:string;
  
  constructor(
    private modalController: ModalController,
    private navParams: NavParams,
    private publicationsService: PublicationsService,
    private toastService: ToastService,
    public ThemeService: ThemeService
  ) { 
    this.id = this.navParams.get('id');
  }

  ngOnInit() {
  }

  close () {
    this.modalController.dismiss();
  }

  editAction(){
    this.modalController.dismiss('edit');
  }

  async deleteAction() {

    const loader = this.toastService.loading();

    try {
      await this.publicationsService.DeletePresidentialAction(this.id).toPromise();
      this.toastService.successMessage()
      this.modalController.dismiss('delete');

    } catch(e) {
      this.toastService.badRequest()
    }
    finally {
      loader.remove()
    }

    
  }

}
