import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material';
import { Title } from '@angular/platform-browser';
import { ApiService } from 'app/api.service';
import { AngularEditorConfig } from '@kolkov/angular-editor';

@Component({
  selector: 'app-configuration',
  templateUrl: './configuration.component.html',
  styleUrls: ['./configuration.component.scss']
})
export class ConfigurationComponent implements OnInit {

  public last_terms:string = '';
  editorConfig: AngularEditorConfig = {
    editable: true,
    spellcheck: true,
    height: '25rem',
    minHeight: '5rem',
    placeholder: 'Enter text here...',
    translate: 'no',
    //uploadUrl: 'v1/images', // if needed
    customClasses: [ // optional
      {
        name: "quote",
        class: "quote",
      },
      {
        name: 'redText',
        class: 'redText'
      },
      {
        name: "titleText",
        class: "titleText",
        tag: "h1",
      },
    ]
  };
  
  constructor(private title: Title, public dialog: MatDialog, public apiService: ApiService) {
    this.title.setTitle("Green App - Configuración");
    this.apiService.getTerms().subscribe((data:any)=>{
      this.last_terms = data.data.content;
    });

  }

  sendToApp() {
    let confirm = this.apiService.confirm("Confirme acción","Enviara actualización a todos los usuarios");
    let xdata = { content: this.last_terms };
    confirm.then((data:any) => {
      if (data.dismiss=="cancel") { }
      else if (data.value) {
        this.apiService.sendToApp(xdata).subscribe((data:any)=>{
          if (data.res == "OK") {
            this.apiService.showOk("Procesado","Solicitud realizada");
          } else {
            this.apiService.showError("Error",data.msg);
          }
        });
      }
    })
  }

  save() {
    
  }

  ngOnInit() {
  }

}
