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

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

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

  //get roles list 
  getSectionsList(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 
    deleteSection(sectionsIds) {
      console.log(sectionsIds);
      return this.http.post(this.authService.pathApi + '/delete_department' , {'departments_id' : sectionsIds});
    };

    //get section data
    getDataSection(sectionId:number) {
      return this.http.get( this.authService.pathApi + '/get_department/' + sectionId);
    }

    //add section
    addSection(formData) {
      const data = formData.value;
      return this.http.post(this.authService.pathApi + '/add_department' , data);
    }
  

    editSection(dataSectionEdit, EditSectionId) {
      const newData = dataSectionEdit.value;
      newData.id = EditSectionId;
      console.log('new data', newData);
      return this.http.post(this.authService.pathApi + '/edit_department' , newData);
    }

    //get adminstartion 
    getAdinstration() {
      return this.http.get(this.authService.pathApi + '/adminstrations_list');
    }


}
