import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { NgxSpinnerService } from 'ngx-spinner';
import { ToastrService } from 'ngx-toastr';
import { AuthServiceService } from './auth-service.service';

@Injectable({
  providedIn: 'root'
})


export class DashboardService {

  constructor(private http: HttpClient, 
    private toastr: ToastrService, 
    private authService: AuthServiceService,
    private spinner: NgxSpinnerService) { }

     //get hospitals list 
     getListData(pageId: number, currentPage: number, dataTableNumber: number){
      this.spinner.show();
      console.log(this.authService.pathApi +'/page_list/' + pageId + '/' + currentPage + '/' + dataTableNumber + '/all');
      return this.http.get(this.authService.pathApi +'/page_list/' + pageId + '/' + currentPage + '/' + dataTableNumber + '/all');
    }
  
     //get data user from searchBar 
     getDataUSerSearchBar(data, pageId, pagenationNumber, dataTableNumber) {
      console.log('url', this.authService.pathApi + '/page_list' + '/' + pageId + '/' + pagenationNumber + '/' + dataTableNumber + '/all/' + data);
       return this.http.get(this.authService.pathApi + '/page_list' + '/' + pageId + '/' + pagenationNumber + '/' + dataTableNumber + '/all/' + data);
    }
  
    //addEvent
    addItem(data, addType) {

      if(addType == 'advertisiment'){
        return this.http.post(this.authService.pathApi + '/add_main_ad' , data);
      }
    }
  
    //edit event
    editItem(dataEdit,editId,editPageName){
      const editData = dataEdit;
      editData.id = editId;

      if(editPageName == 'advertisiment') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_main_ad', editData);
      }
    }
  
    //get event data
    getItemData(pageId: number, typeGetData:string) {
      console.log('wwwwwwwwwwwwwwwwwwwwwwwwwwww', pageId);
      if(typeGetData == 'advertisiment') {
        return this.http.get(this.authService.pathApi + '/get_main_ad/' + pageId);
      }
    }
  
    //delete event 
    deleteItem(dataIds, pageId) {
      
      console.log(dataIds);

      if(pageId == 24) {
        return this.http.post(this.authService.pathApi + '/delete_main_ads' , {'ads_id' : dataIds});
      }
      
      
    };


}
