{"ast":null,"code":"import { HttpHeaders } from '@angular/common/http';\nimport { environment } from './environments/environment';\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"./services/auth.service\";\nimport * as i2 from \"./services/client.service\";\nimport * as i3 from \"./services/user.service\";\nimport * as i4 from \"@angular/router\";\nimport * as i5 from \"@angular/common/http\";\nimport * as i6 from \"@angular/common\";\nimport * as i7 from \"@angular/forms\";\nfunction AppComponent_nav_0_li_2_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"li\")(1, \"a\", 7);\n    i0.ɵɵtext(2, \"Home\");\n    i0.ɵɵelementEnd()();\n  }\n}\nfunction AppComponent_nav_0_li_3_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"li\")(1, \"a\", 8);\n    i0.ɵɵtext(2, \"Ajuste de P\\u00E1tio\");\n    i0.ɵɵelementEnd()();\n  }\n}\nfunction AppComponent_nav_0_li_4_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"li\")(1, \"a\", 9);\n    i0.ɵɵtext(2, \"Mensagens\");\n    i0.ɵɵelementEnd()();\n  }\n}\nfunction AppComponent_nav_0_li_5_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"li\")(1, \"a\", 10);\n    i0.ɵɵtext(2, \"Relat\\u00F3rio\");\n    i0.ɵɵelementEnd()();\n  }\n}\nfunction AppComponent_nav_0_li_6_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"li\")(1, \"a\", 11);\n    i0.ɵɵtext(2, \"Cadastro\");\n    i0.ɵɵelementEnd()();\n  }\n}\nfunction AppComponent_nav_0_option_12_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"option\", 12);\n    i0.ɵɵtext(1);\n    i0.ɵɵelementEnd();\n  }\n  if (rf & 2) {\n    const cliente_r3 = ctx.$implicit;\n    i0.ɵɵproperty(\"value\", cliente_r3.id);\n    i0.ɵɵadvance();\n    i0.ɵɵtextInterpolate(cliente_r3.name || \"Sem Nome\");\n  }\n}\nfunction AppComponent_nav_0_Template(rf, ctx) {\n  if (rf & 1) {\n    const _r1 = i0.ɵɵgetCurrentView();\n    i0.ɵɵelementStart(0, \"nav\")(1, \"ul\");\n    i0.ɵɵtemplate(2, AppComponent_nav_0_li_2_Template, 3, 0, \"li\", 0)(3, AppComponent_nav_0_li_3_Template, 3, 0, \"li\", 0)(4, AppComponent_nav_0_li_4_Template, 3, 0, \"li\", 0)(5, AppComponent_nav_0_li_5_Template, 3, 0, \"li\", 0)(6, AppComponent_nav_0_li_6_Template, 3, 0, \"li\", 0);\n    i0.ɵɵelementEnd();\n    i0.ɵɵelementStart(7, \"div\", 1)(8, \"div\", 2)(9, \"label\", 3);\n    i0.ɵɵtext(10, \"Selecionar Cliente:\");\n    i0.ɵɵelementEnd();\n    i0.ɵɵelementStart(11, \"select\", 4);\n    i0.ɵɵtwoWayListener(\"ngModelChange\", function AppComponent_nav_0_Template_select_ngModelChange_11_listener($event) {\n      i0.ɵɵrestoreView(_r1);\n      const ctx_r1 = i0.ɵɵnextContext();\n      i0.ɵɵtwoWayBindingSet(ctx_r1.selectedClient, $event) || (ctx_r1.selectedClient = $event);\n      return i0.ɵɵresetView($event);\n    });\n    i0.ɵɵlistener(\"change\", function AppComponent_nav_0_Template_select_change_11_listener() {\n      i0.ɵɵrestoreView(_r1);\n      const ctx_r1 = i0.ɵɵnextContext();\n      return i0.ɵɵresetView(ctx_r1.onClientChange(ctx_r1.selectedClient));\n    });\n    i0.ɵɵtemplate(12, AppComponent_nav_0_option_12_Template, 2, 2, \"option\", 5);\n    i0.ɵɵelementEnd()();\n    i0.ɵɵelementStart(13, \"button\", 6);\n    i0.ɵɵlistener(\"click\", function AppComponent_nav_0_Template_button_click_13_listener() {\n      i0.ɵɵrestoreView(_r1);\n      const ctx_r1 = i0.ɵɵnextContext();\n      return i0.ɵɵresetView(ctx_r1.logout());\n    });\n    i0.ɵɵtext(14, \"Logout\");\n    i0.ɵɵelementEnd()()();\n  }\n  if (rf & 2) {\n    const ctx_r1 = i0.ɵɵnextContext();\n    i0.ɵɵadvance(2);\n    i0.ɵɵproperty(\"ngIf\", ctx_r1.authService.hasFunctionality(\"TELA HOME\"));\n    i0.ɵɵadvance();\n    i0.ɵɵproperty(\"ngIf\", ctx_r1.authService.hasFunctionality(\"TELA AJUSTE DE PATIO\"));\n    i0.ɵɵadvance();\n    i0.ɵɵproperty(\"ngIf\", ctx_r1.authService.hasFunctionality(\"TELA DE MENSAGENS\"));\n    i0.ɵɵadvance();\n    i0.ɵɵproperty(\"ngIf\", ctx_r1.authService.hasFunctionality(\"TELA RELATORIOS\"));\n    i0.ɵɵadvance();\n    i0.ɵɵproperty(\"ngIf\", ctx_r1.authService.hasFunctionality(\"TELA DE CADASTRO\"));\n    i0.ɵɵadvance(5);\n    i0.ɵɵtwoWayProperty(\"ngModel\", ctx_r1.selectedClient);\n    i0.ɵɵadvance();\n    i0.ɵɵproperty(\"ngForOf\", ctx_r1.clients);\n  }\n}\nexport let AppComponent = /*#__PURE__*/(() => {\n  class AppComponent {\n    constructor(authService, clientService, userService, router, cdRef,\n    // 👈 novo\n    http) {\n      this.authService = authService;\n      this.clientService = clientService;\n      this.userService = userService;\n      this.router = router;\n      this.cdRef = cdRef;\n      this.http = http;\n      this.title = 'RF ContaVagas';\n      this.selectedClient = '';\n      this.clients = [];\n      this.userName = '';\n      this.userRole = '';\n      this.grounds = [];\n      this.clientId_adjustment = 0;\n    }\n    ngOnInit() {\n      this.clientService.selectedClient$.subscribe(clientId => {\n        this.selectedClient = clientId;\n        this.cdRef.detectChanges(); // 👈 força a atualização segura\n      });\n    }\n    loadClients() {\n      const userId = this.userService.getUserId();\n      const apiUrl = environment.apiUrlBackEnd;\n      const url = `${apiUrl}/api/users/${userId}/access`;\n      this.http.get(url).subscribe(data => {\n        if (data.parkingAccess && data.parkingAccess.length > 0) {\n          const firstParkingAccess = data.parkingAccess[0];\n          this.userName = `Nome: ${firstParkingAccess.nome}`;\n          this.userRole = `Cargo: ${firstParkingAccess.cargo}`;\n          this.userService.setUserAccessData(data); // ✔ salva o objeto completo retornado da API\n          this.clients = data.parkingAccess.map(parking => ({\n            id: parking.id,\n            name: parking.parkingName\n          }));\n          if (this.clients.length) {\n            this.selectedClient = this.clients[0].id.toString();\n            this.clientService.setSelectedClient(this.clients[0].id);\n            this.getParkingData(this.clients[0].id);\n          }\n        }\n      }, error => {\n        console.error('Erro ao buscar dados de acesso do usuário', error);\n      });\n    }\n    getParkingData(clientId) {\n      const apiUrl = environment.apiUrlBackEndExternaCache + `/v1/spark-customers/ground/{\"id_customer\":${clientId},\"id_park\":1}`;\n      const headers = new HttpHeaders().set('device', 'manager');\n      this.http.get(apiUrl, {\n        headers\n      }).subscribe(data => {\n        this.grounds = data;\n        if (this.grounds.length > 0) {\n          this.selectedGround = this.grounds[0];\n        }\n      }, error => {\n        console.error('Erro ao buscar dados dos grounds', error);\n      });\n      this.clientId_adjustment = clientId;\n    }\n    onClientChange(clientId) {\n      this.selectedClient = clientId;\n      const numericClientId = +clientId;\n      this.clientService.updateSelectedClient(clientId);\n      this.getParkingData(numericClientId);\n      this.updateUserAccessForClient(numericClientId); // ✅ nova chamada para atualizar menus\n    }\n    updateUserAccessForClient(clientId) {\n      const userId = this.userService.getUserId();\n      const apiUrl = environment.apiUrlBackEnd;\n      const url = `${apiUrl}/api/users/${userId}/access`;\n      this.http.get(url).subscribe(data => {\n        const selectedAccess = data.parkingAccess.find(p => p.id === clientId);\n        if (selectedAccess) {\n          this.userService.setUserAccessData({\n            ...data,\n            parkingAccess: [selectedAccess]\n          });\n        } else {\n          this.userService.setUserAccessData({\n            ...data,\n            parkingAccess: []\n          });\n        }\n      }, error => {\n        console.error('Erro ao atualizar funcionalidades do usuário para o cliente selecionado', error);\n      });\n    }\n    logout() {\n      this.authService.setLoggedOut();\n      this.router.navigate(['/login']);\n    }\n    static #_ = this.ɵfac = function AppComponent_Factory(t) {\n      return new (t || AppComponent)(i0.ɵɵdirectiveInject(i1.AuthService), i0.ɵɵdirectiveInject(i2.ClientService), i0.ɵɵdirectiveInject(i3.UserService), i0.ɵɵdirectiveInject(i4.Router), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i5.HttpClient));\n    };\n    static #_2 = this.ɵcmp = /*@__PURE__*/i0.ɵɵdefineComponent({\n      type: AppComponent,\n      selectors: [[\"app-root\"]],\n      decls: 2,\n      vars: 1,\n      consts: [[4, \"ngIf\"], [1, \"navbar-actions\"], [1, \"client-selection\"], [\"for\", \"clienteSelect\"], [\"id\", \"clienteSelect\", 3, \"ngModelChange\", \"change\", \"ngModel\"], [3, \"value\", 4, \"ngFor\", \"ngForOf\"], [1, \"logout-btn\", 3, \"click\"], [\"routerLink\", \"/home\"], [\"routerLink\", \"/ajuste-patio\"], [\"routerLink\", \"/configuracao-mensagens\"], [\"routerLink\", \"/relatorio\"], [\"routerLink\", \"/cadastro\"], [3, \"value\"]],\n      template: function AppComponent_Template(rf, ctx) {\n        if (rf & 1) {\n          i0.ɵɵtemplate(0, AppComponent_nav_0_Template, 15, 7, \"nav\", 0);\n          i0.ɵɵelement(1, \"router-outlet\");\n        }\n        if (rf & 2) {\n          i0.ɵɵproperty(\"ngIf\", ctx.authService.isLoggedIn());\n        }\n      },\n      dependencies: [i6.NgForOf, i6.NgIf, i4.RouterOutlet, i4.RouterLink, i7.NgSelectOption, i7.ɵNgSelectMultipleOption, i7.SelectControlValueAccessor, i7.NgControlStatus, i7.NgModel],\n      styles: [\"nav[_ngcontent-%COMP%]{display:flex;justify-content:space-between;align-items:center;background-color:#2c3e50;color:#fff;padding:10px 20px}nav[_ngcontent-%COMP%]   ul[_ngcontent-%COMP%]{list-style:none;display:flex;gap:20px;margin:0;padding:0}nav[_ngcontent-%COMP%]   ul[_ngcontent-%COMP%]   li[_ngcontent-%COMP%]   a[_ngcontent-%COMP%]{color:#fff;text-decoration:none;font-weight:500}.navbar-actions[_ngcontent-%COMP%]{display:flex;align-items:center;gap:12px}.client-selection[_ngcontent-%COMP%]   label[_ngcontent-%COMP%]{margin-right:6px;font-weight:500}.client-selection[_ngcontent-%COMP%]   select[_ngcontent-%COMP%]{padding:6px 10px;border-radius:4px;border:none;font-size:14px}.logout-btn[_ngcontent-%COMP%]{background-color:transparent;border:1px solid white;color:#fff;padding:6px 12px;border-radius:4px;cursor:pointer;font-weight:500;transition:background-color .3s}.logout-btn[_ngcontent-%COMP%]:hover{background-color:#34495e}\"]\n    });\n  }\n  return AppComponent;\n})();","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}