import { Component, OnInit } from '@angular/core';
import { AnimationController, ModalController, NavParams } from '@ionic/angular';
import { SearchList } from 'src/app/models/search-document';
import { SearchPage } from 'src/app/pages/search/search.page';
import { ThemeService } from 'src/app/services/theme.service'

@Component({
  selector: 'app-add-note',
  templateUrl: './add-note.page.html',
  styleUrls: ['./add-note.page.scss'],
})
export class AddNotePage implements OnInit {
  note: string = '';
  documents: SearchList[] = [];
  loadedAttachments:any;
  hideThisFeature: boolean = true;

  constructor(
    private modalController: ModalController,
    private animationController: AnimationController,
    private navParams: NavParams,
    public ThemeService: ThemeService
  ) {
    this.note = '';
    this.hideThisFeature = this.navParams.get('showAttachmentBtn');
   }

  ngOnInit() {
    console.log( this.navParams);

    console.log(this.hideThisFeature);

  }

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

  save() {
    let body = {
      "note":this.note,
      "documents":this.documents,
    }
    this.modalController.dismiss(body);
  }

  async getDoc() {

    const modal = await this.modalController.create({
      component: SearchPage,
      cssClass: 'modal-width-100-width-background modal',
      componentProps: {
        type: 'AccoesPresidenciais & ArquivoDespachoElect',
        showSearchInput: true,
        select: true
      }
    });
    await modal.present();
      modal.onDidDismiss().then((res)=>{
        if(res){
          const data = res.data;
          this.documents.push(data.selected);
        }
    });

  }

  removeAttachment(index: number){

    this.documents = this.documents.filter( (e, i) =>  index != i);
  }


}
