import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';
// import { navItems } from './_nav';

@Injectable({
  providedIn: 'root'
})
export class RoleService {
  private EndPoint = 'http://localhost:4000/';
  private datas;
  constructor(
    private http: HttpClient
  ) { }


  getNavDetails(): Observable<any> {
    return this.http.get<any>(this.EndPoint+"nav")
      .pipe(
      catchError(this.handleError('getEmployee', []))
      )
  }

  getNavDetailsLIst():Observable<any> {
     return this.http.get<any>(this.EndPoint+"detailsList")
      .pipe(
      catchError(this.handleError('getEmployee', []))
      )
  }

  addRoleDetailsMaster(details):Observable<any> {
    return this.http.post<any>(this.EndPoint+"addRole", details)
    .pipe(
      catchError(this.handleError('role', []))
    )
  }

  updateRoleDetailsMaster(details):Observable<any> {
    return this.http.put<any>(this.EndPoint+"updateRoleDetails", details)
    .pipe(
      catchError(this.handleError('role', []))
    )
  }

  getRoleDetails(): Observable<any> {
    // return this.http.get<any>(this.EndPoint+"roleDetails")
    return of(this.navItems)
    // .pipe(
    //   catchError(this.handleError('role', []))
    // )
  }

  private handleError<T>(operation = 'operation', result?: T) {
    return (error: any): Observable<T> => {

      console.error(error); // log to console instead
      return of(result as T);
    };
  }

  navItems = {
    "status": true,
    "message": "nav details list created successfully",
    "data": [
        {
            "id": 3,
            "role": "ADMIN",
            "nav": [
                {
                    "id": 1,
                    "order_details": 1,
                    "name": "Dashboard",
                    "url": "/dashboard",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 2,
                    "order_details": 2,
                    "name": "Employee",
                    "url": "/employee",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 3,
                    "order_details": 3,
                    "name": "Base",
                    "url": "/base",
                    "sub_nav": "[1]",
                    "Sub_Nav": "[1]",
                    "isActive": 1
                },
                {
                    "id": 4,
                    "order_details": 4,
                    "name": "Create Role",
                    "url": "/createRole",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 5,
                    "order_details": 5,
                    "name": "Role Details",
                    "url": "/listRole",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                }
            ]
        },
        {
            "id": 15,
            "role": "EMPLOYEE",
            "nav": [
                {
                    "id": 1,
                    "order_details": 1,
                    "name": "Dashboard",
                    "url": "/dashboard",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 3,
                    "order_details": 3,
                    "name": "Base",
                    "url": "/base",
                    "sub_nav": "[1]",
                    "Sub_Nav": "[1]",
                    "isActive": 0
                }
            ]
        },
        {
            "id": 27,
            "role": "EMPLOYEE",
            "nav": [
                {
                    "id": 1,
                    "order_details": 1,
                    "name": "Dashboard",
                    "url": "/dashboard",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 3,
                    "order_details": 3,
                    "name": "Base",
                    "url": "/base",
                    "sub_nav": "[1]",
                    "Sub_Nav": "[1]",
                    "isActive": 0
                }
            ]
        },
        {
            "id": 28,
            "role": "FINANCE",
            "nav": [
                {
                    "id": 1,
                    "order_details": 1,
                    "name": "Dashboard",
                    "url": "/dashboard",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 4,
                    "order_details": 4,
                    "name": "Create Role",
                    "url": "/createRole",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 0
                },
                {
                    "id": 5,
                    "order_details": 5,
                    "name": "Role Details",
                    "url": "/listRole",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 0
                },
                {
                    "id": 2,
                    "order_details": 2,
                    "name": "Employee",
                    "url": "/employee",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                }
            ]
        },
        {
            "id": 29,
            "role": "MANAGER",
            "nav": [
                {
                    "id": 1,
                    "order_details": 1,
                    "name": "Dashboard",
                    "url": "/dashboard",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 2,
                    "order_details": 2,
                    "name": "Employee",
                    "url": "/employee",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 0
                },
                {
                    "id": 3,
                    "order_details": 3,
                    "name": "Base",
                    "url": "/base",
                    "sub_nav": "[1]",
                    "Sub_Nav": "1",
                    "isActive": 0
                },
                {
                    "id": 1,
                    "order_details": 1,
                    "name": "Dashboard",
                    "url": "/dashboard",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                },
                {
                    "id": 4,
                    "order_details": 4,
                    "name": "Create Role",
                    "url": "/createRole",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 0
                },
                {
                    "id": 5,
                    "order_details": 5,
                    "name": "Role Details",
                    "url": "/listRole",
                    "sub_nav": "",
                    "Sub_Nav": "",
                    "isActive": 1
                }
            ]
        }
    ]
}

}
