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

@Injectable({
  providedIn: 'root'
})
export class DepartmentService {

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

      //get roles list 
  getDeparmentsList(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);
  }

  //delete user 
  deleteDepart(departsIds) {
    console.log(departsIds);
    return this.http.post(this.authService.pathApi + '/delete_adminstration' , {'adminstrations_id' : departsIds});
  };

  addDepartment(formData) {
    const data = formData.value;
    return this.http.post(this.authService.pathApi + '/add_adminstration' , data);
  }

  getDataAdmin(idAdmin:number) {
    return this.http.get( this.authService.pathApi + '/get_adminstration/' + idAdmin);
  }

  editAdmin(dataDepartEdit, EditDepartId) {
    const newData = dataDepartEdit.value;
    newData.id = EditDepartId;
    console.log('new data', newData);
    return this.http.post(this.authService.pathApi + '/edit_adminstration' , newData);
  }
      
}
