import { Component, OnInit } from '@angular/core';
import {NavController} from "@ionic/angular";
import {Router} from "@angular/router";
import { SessionDataProviderService } from 'src/app/store/session-data-provider.service';
import { BlogDataService } from 'src/app/store/blog-data.service';
import { WrenchService } from 'src/app/services/wrench.service';

@Component({
  selector: 'app-allblog',
  templateUrl: './allblog.page.html',
  styleUrls: ['./allblog.page.scss'],
})
export class AllblogPage implements OnInit {
  tabs = 'about';


  constructor(
      private router: Router,
      private navctr: NavController,
      public sessionDataProviderService: SessionDataProviderService,
      private wrenchService: WrenchService,
      public blogDataService: BlogDataService
  ) {
  }

  ngOnInit() {
    this.getBlogData([]);
  }

  onBack() {
    this.navctr.back();
  }

  blogResult:any;
  blogData:any;
  getBlogData(blogReq=[]){
    this.wrenchService.getBlogData(blogReq).subscribe(
        blogResult => {
          this.blogResult = blogResult;
          console.log("BLOG RETURN->", this.blogResult);
          this.blogData = this.blogResult.blogdata;
          // debugger;
          this.blogDataService.setBlogData(this.blogResult.blogdata);
        }
    );
  }
  onMentor() {
    this.router.navigate(['mentor']);
  }

  blogDetails(item) {
    var pageToNavigate = 'blogdetail';
    this.router.navigate([pageToNavigate],{state: item} );
  }

  onEnroll() {
    this.router.navigate(['enroll']);
  }
}
