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 + pageId);
      if(pageId == 40) {
        return this.http.get(this.authService.pathApi +'/page_list/1' + '/' + currentPage + '/' + dataTableNumber + '/all');
      } else {
        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);
      if(pageId == 40) {
        return this.http.get(this.authService.pathApi + '/page_list' + '/' + pageId + '/' + pagenationNumber + '/' + dataTableNumber + '/1/' + data);
      } else {
        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);
      } else if(addType == 'internalHospital') {
        return this.http.post(this.authService.pathApi + '/add_hospitals_centers' , data);
      } else if(addType == 'externalHospital') {
        return this.http.post(this.authService.pathApi + '/add_hospitals_centers_ex' , data);
      } else if(addType == 'internalManagement') {
        return this.http.post(this.authService.pathApi + '/add_management' , data);
      } else if(addType == 'externalManagement') {
        return this.http.post(this.authService.pathApi + '/add_management_ex' , data);
      } else if(addType == 'internalMainMenu') {
        return this.http.post(this.authService.pathApi + '/add_menu' , data);
      } else if(addType == 'externalMainMenu') {
        return this.http.post(this.authService.pathApi + '/add_external_menu' , data);
      } else if(addType == 'internalServiceExternalPage') {
        return this.http.post(this.authService.pathApi + '/add_external_service' , data);
      } else if(addType == 'externalServiceExternalPage') {
        return this.http.post(this.authService.pathApi + '/add_external_service_ex' , data);
      } else if(addType == 'internalNews') {
        return this.http.post(this.authService.pathApi + '/add_report' , data);
      } else if(addType == 'externalNews') {
        return this.http.post(this.authService.pathApi + '/add_report_ex' , data);
      } else if(addType == 'internalFooter') {
        return this.http.post(this.authService.pathApi + '/add_footer' , data);
      } else if(addType == 'externalFooter') {
        return this.http.post(this.authService.pathApi + '/add_footer_ex' , data);
      } else if(addType == 'barEvent') {
        return this.http.post(this.authService.pathApi + '/add_event_bar', data);
      } else if(addType == 'visitingTime') {
        return this.http.post(this.authService.pathApi + '/add_visiting_time', data);
      } else if(addType == 'eventCalendar') {
        return this.http.post(this.authService.pathApi + '/add_event_calendar', data);
      } else if(addType == 'externalAchievement') {
        return this.http.post(this.authService.pathApi + "/add_external_achievement", data);
      } else if(addType == 'statistic') {
        return this.http.post(this.authService.pathApi + "/add_statistic", data);
      } else if(addType == 'advertising') {
        return this.http.post(this.authService.pathApi + "/add_advertising_service", data);
      } else if(addType == 'supervisor') {
        return this.http.post(this.authService.pathApi + "/asign_supervisor_to_department", data);
      } else if(addType == 'absorpation') {
        return this.http.post(this.authService.pathApi + "/add_absorpation_plan", data);
      } else if(addType == 'request') {
        return this.http.post(this.authService.pathApi + "/add_request", data);
      } else if(addType == 'trainee') {
        return this.http.post(this.authService.pathApi + "/add_user", data);
      } else if(addType == 'traineeRequest') {
        return this.http.post(this.authService.pathApi + "/add_request", data);
      } else if(addType == 'vehicle') {
        return this.http.post(this.authService.pathApi + '/add_vehicle_type', data);
      } else if(addType == 'modelVehicle') {
        return this.http.post(this.authService.pathApi + '/add_vehicle_model', data);
      } else if(addType == 'registerVehicle') {
        return this.http.post(this.authService.pathApi + '/add_vehicle_data', data);
      }
    }

    //edit event
    editItem(editId,dataEdit,editPageName){
      const editData = dataEdit;
      console.log(editId);
      console.log(editPageName);
      editData['id'] = editId;
      console.log(dataEdit);

      if(editPageName == 'advertisiment') {
        return this.http.post(this.authService.pathApi + '/edit_main_ad', editData);
      } else if(editPageName == 'internalHospital') {
        return this.http.post(this.authService.pathApi + '/edit_hospitals_centers', editData);
      } else if(editPageName == 'externalHospital') {
        return this.http.post(this.authService.pathApi + '/edit_hospitals_centers_ex', editData);
      } else if(editPageName == 'internalManagement') {
        return this.http.post(this.authService.pathApi + '/edit_management' , dataEdit);
      } else if(editPageName == 'externalManagement') {
        return this.http.post(this.authService.pathApi + '/edit_management_ex' , dataEdit);
      } else if(editPageName == 'internalMenu') {
        return this.http.post(this.authService.pathApi + '/edit_menu' , dataEdit);
      } else if(editPageName == 'externalMenu') {
        return this.http.post(this.authService.pathApi + '/edit_external_menu' , dataEdit);
      } else if(editPageName == 'internalServiceExternalPage') {
        return this.http.post(this.authService.pathApi + '/edit_external_service' , dataEdit);
      } else if(editPageName == 'externalServiceExternalPage') {
        return this.http.post(this.authService.pathApi + '/edit_external_service_ex' , dataEdit);
      } else if(editPageName == 'internalNew') {
        return this.http.post(this.authService.pathApi + '/edit_report' , dataEdit);
      } else if(editPageName == 'externalNew') {
        return this.http.post(this.authService.pathApi + '/edit_report_ex' , dataEdit);
      } else if(editPageName == 'internalFooter') {
        return this.http.post(this.authService.pathApi + '/edit_footer', dataEdit);
      } else if(editPageName == 'externalFooter') {
        return this.http.post(this.authService.pathApi + '/edit_footer_ex', dataEdit);
      }else if(editPageName == 'barEvent') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_event_bar', editData);
      } else if(editPageName == 'contactUs') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_contact_us', editData);
      } else if(editPageName == 'visitingTime') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_visiting_time', editData);
      } else if(editPageName == 'eventCalendar') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_event_calendar', editData);
      } else if(editPageName == 'externalAchievement') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_external_achievement', editData);
      } else if(editPageName == 'statistic') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_statistic', editData);
      } else if(editPageName == 'advertising') {
        console.log(editData);
        return this.http.post(this.authService.pathApi + '/edit_advertising_service', editData);
      } else if(editPageName == 'absorpation') {
        return this.http.post(this.authService.pathApi + '/edit_absorpation_plan', editData);
      } else if(editPageName == 'trainee') {
        return this.http.post(this.authService.pathApi + '/edit_user', editData);
      } else if(editPageName == 'request') {
        return this.http.post(this.authService.pathApi + '/edit_request', editData);
      } else if(editPageName == 'vehicle') {
        return this.http.post(this.authService.pathApi + '/edit_vehicle_type', editData);
      } else if(editPageName == 'vehicelModel') {
        return this.http.post(this.authService.pathApi + '/edit_vehicle_model', editData);
      } else if(editPageName == 'registerVehicle') {
        return this.http.post(this.authService.pathApi + '/edit_vehicle_data', editData);
      }
    }

    //get item data
    getItemData(pageId: number, typeGetData:string) {
      console.log('wwwwwwwwwwwwwwwwwwwwwwwwwwww', pageId);
      if(typeGetData == 'advertisiment') {
        return this.http.get(this.authService.pathApi + '/get_main_ad/' + pageId);
      } else if(typeGetData == 'hospital') {
        return this.http.get(this.authService.pathApi + '/get_hospitals_centers/' + pageId);
      } else if(typeGetData == 'managament') {
        return this.http.get(this.authService.pathApi + '/get_management/' + pageId);
      } else if(typeGetData == 'mainMenu') {
        return this.http.get(this.authService.pathApi + '/get_menu/' + pageId);
      } else if(typeGetData == 'externalService') {
        return this.http.get(this.authService.pathApi + '/get_external_service/' + pageId);
      } else if(typeGetData == 'news') {
        return this.http.get(this.authService.pathApi + '/get_report/' + pageId);
      } else if(typeGetData == 'footer') {
        return this.http.get(this.authService.pathApi + '/get_footer/' + pageId);
      }else if(typeGetData == 'barEvent') {
        return this.http.get(this.authService.pathApi + '/get_event_bar/' + pageId);
      } else if(typeGetData == 'contactUs') {
        return this.http.get(this.authService.pathApi + '/get_contact_us/' + pageId);
      } else if(typeGetData == 'visitingTime') {
        return this.http.get(this.authService.pathApi + '/get_visiting_time/' + pageId);
      } else if(typeGetData == 'eventCalendar') {
        return this.http.get(this.authService.pathApi + '/get_event_calendar/' + pageId);
      } else if(typeGetData == 'externalAchievement') {
        return this.http.get(this.authService.pathApi + '/get_external_achievement/' + pageId);
      } else if(typeGetData == 'statistic') {
        return this.http.get(this.authService.pathApi + '/get_statistic/' + pageId);
      } else if(typeGetData == 'advertising') {
        return this.http.get(this.authService.pathApi + '/get_advertising_service/' + pageId);
      } else if(typeGetData == 'supervisor') {
        return this.http.get(this.authService.pathApi + '/get_department/' + pageId);
      } else if(typeGetData == 'absorpation') {
        return this.http.get(this.authService.pathApi + '/get_absorpation_plan/' + pageId);
      } else if(typeGetData == 'trainee') {
        return this.http.get(this.authService.pathApi + '/get_user/' + pageId);
      } else if(typeGetData == 'traineeRequest') {
        return this.http.get(this.authService.pathApi + '/get_request/' + pageId);
      } else if(typeGetData == 'sectionReviewTrainee') {
        return this.http.get(this.authService.pathApi + '/get_request/' + pageId);
      } else if(typeGetData == 'vehicle') {
        return this.http.get(this.authService.pathApi + '/get_vehicle_type/' + pageId);
      } else if(typeGetData == 'vehicleModel') {
        return this.http.get(this.authService.pathApi + '/get_vehicle_model/' + pageId);
      } else if(typeGetData == 'registerVehicle') {
        return this.http.get(this.authService.pathApi + '/get_vehicle_data/' + pageId);
      }
  }

    //delete event
    deleteItem(dataIds, pageId) {

      console.log(dataIds);
      console.log(pageId);

      if(pageId == 24) {
        return this.http.post(this.authService.pathApi + '/delete_main_ads' , {'ads_id' : dataIds});
      } else if(pageId == 10) {
        return this.http.post(this.authService.pathApi + '/delete_managements' , {'managements_id' : dataIds});
      } else if(pageId == 31) {
        return this.http.post(this.authService.pathApi + '/delete_managements_ex' , {'managements_id' : dataIds});
      } else if(pageId == 6) {
        return this.http.post(this.authService.pathApi + '/delete_hospitals_centers' , {'hospitals_centers_id' : dataIds});
      } else if(pageId == 30) {
        return this.http.post(this.authService.pathApi + '/delete_hospitals_centers_ex' , {'hospitals_centers_id' : dataIds});
      } else if(pageId == 17) {
        return this.http.post(this.authService.pathApi + '/delete_menus' , {'menus_id' : dataIds});
      } else if(pageId == 18) {
        return this.http.post(this.authService.pathApi + '/delete_external_menus' , {'menus_id' : dataIds});
      } else if(pageId == 19) {
        return this.http.post(this.authService.pathApi + '/delete_external_services_ex' , {'external_services_id' : dataIds});
      } else if(pageId == 7) {
        return this.http.post(this.authService.pathApi + '/delete_external_services' , {'external_services_id' : dataIds});
      } else if(pageId == 20) {
        return this.http.post(this.authService.pathApi + '/delete_reports_ex' , {'reports_id' : dataIds});
      } else if(pageId == 13) {
        return this.http.post(this.authService.pathApi + '/delete_reports' , {'reports_id' : dataIds});
      } else if(pageId == 16) {
        return this.http.post(this.authService.pathApi + '/delete_footers' , {'footers_id' : dataIds});
      } else if(pageId == 29) {
        return this.http.post(this.authService.pathApi + '/delete_footers_ex' , {'footers_id' : dataIds});
      } else if (pageId == 21){
        return this.http.post(this.authService.pathApi + '/delete_event_bars' , {'event_bars_id' : dataIds});
      } else if (pageId == 23){
        return this.http.post(this.authService.pathApi + '/delete_visiting_times' , {'visiting_times_id' : dataIds});
      } else if (pageId == 25){
        return this.http.post(this.authService.pathApi + '/delete_event_calendars' , {'event_calendars_id' : dataIds});
      } else if (pageId == 27){
        return this.http.post(this.authService.pathApi + '/delete_external_achievements' , {'external_achievements_id' : dataIds});
      } else if (pageId == 26){
        return this.http.post(this.authService.pathApi + '/delete_statistics' , {'statistics_id' : dataIds});
      } else if (pageId == 22){
        return this.http.post(this.authService.pathApi + '/delete_advertising_services' , {'advertising_services_id' : dataIds});
      } else if(pageId == 33) {
        return this.http.post(this.authService.pathApi + '/un_asign_supervisor_to_department', {'departments_id' : dataIds})
      } else if(pageId == 34) {
        return this.http.post(this.authService.pathApi + '/delete_absorpation_plans', {'absorpation_plans_id' : dataIds});
      } else if(pageId == 40) {
        return this.http.post(this.authService.pathApi + '/delete_user', {'users_id' : dataIds});
      } else if(pageId == 43) {
        return this.http.post(this.authService.pathApi + '/delete_vehicle_type', {'types_id' : dataIds});
      } else if(pageId == 44) {
        return this.http.post(this.authService.pathApi + '/delete_vehicle_model', {'models_id' : dataIds});
      } else if(pageId == 45) {
        return this.http.post(this.authService.pathApi + '/delete_vehicle_data', {'datas_id' : dataIds});
      }

    };



}
