@atlashub/smartstack 3.21.0 → 3.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/dist/chunks/{AgentSkillsPage-7si3Ng8e.js → AgentSkillsPage-BWQSCYl-.js} +2 -2
  2. package/dist/chunks/{AgentSkillsPage-7si3Ng8e.js.map → AgentSkillsPage-BWQSCYl-.js.map} +1 -1
  3. package/dist/chunks/{AgentSkillsPage-D0cD1QdM.js → AgentSkillsPage-IQcMnBaD.js} +2 -2
  4. package/dist/chunks/{AgentSkillsPage-D0cD1QdM.js.map → AgentSkillsPage-IQcMnBaD.js.map} +1 -1
  5. package/dist/chunks/{AgentWorkloadPage-H_7ze33H.js → AgentWorkloadPage-DqrjkvWL.js} +2 -2
  6. package/dist/chunks/{AgentWorkloadPage-H_7ze33H.js.map → AgentWorkloadPage-DqrjkvWL.js.map} +1 -1
  7. package/dist/chunks/{AgentWorkloadPage-D4d86cdV.js → AgentWorkloadPage-w-HiyFYP.js} +2 -2
  8. package/dist/chunks/{AgentWorkloadPage-D4d86cdV.js.map → AgentWorkloadPage-w-HiyFYP.js.map} +1 -1
  9. package/dist/chunks/{ApiCatalogDetailPage-2ktkRrCb.js → ApiCatalogDetailPage-D3L8Yf4G.js} +3 -3
  10. package/dist/chunks/{ApiCatalogDetailPage-2ktkRrCb.js.map → ApiCatalogDetailPage-D3L8Yf4G.js.map} +1 -1
  11. package/dist/chunks/{ApiCatalogDetailPage-BQ53xuwD.js → ApiCatalogDetailPage-MPT3Kz6H.js} +2 -2
  12. package/dist/chunks/{ApiCatalogDetailPage-BQ53xuwD.js.map → ApiCatalogDetailPage-MPT3Kz6H.js.map} +1 -1
  13. package/dist/chunks/{ApiCatalogPage-BEqTDJz8.js → ApiCatalogPage-D4Hg3uiS.js} +2 -2
  14. package/dist/chunks/{ApiCatalogPage-BEqTDJz8.js.map → ApiCatalogPage-D4Hg3uiS.js.map} +1 -1
  15. package/dist/chunks/{ApiCatalogPage-BBkWSLI8.js → ApiCatalogPage-DRg5Cz0r.js} +2 -2
  16. package/dist/chunks/{ApiCatalogPage-BBkWSLI8.js.map → ApiCatalogPage-DRg5Cz0r.js.map} +1 -1
  17. package/dist/chunks/{ApplicationDetailPage-BYJ2YMPq.js → ApplicationDetailPage-Caizuyn2.js} +2 -2
  18. package/dist/chunks/{ApplicationDetailPage-BYJ2YMPq.js.map → ApplicationDetailPage-Caizuyn2.js.map} +1 -1
  19. package/dist/chunks/{ApplicationDetailPage-D8-bf1as.js → ApplicationDetailPage-CuCW6aMB.js} +4 -4
  20. package/dist/chunks/{ApplicationDetailPage-D8-bf1as.js.map → ApplicationDetailPage-CuCW6aMB.js.map} +1 -1
  21. package/dist/chunks/{ApplicationsDashboardPage-BBlLms2r.js → ApplicationsDashboardPage-B2MW8-Kc.js} +2 -2
  22. package/dist/chunks/{ApplicationsDashboardPage-BBlLms2r.js.map → ApplicationsDashboardPage-B2MW8-Kc.js.map} +1 -1
  23. package/dist/chunks/{ApplicationsDashboardPage-DTWZxJJM.js → ApplicationsDashboardPage-BDIjFIYZ.js} +3 -3
  24. package/dist/chunks/{ApplicationsDashboardPage-DTWZxJJM.js.map → ApplicationsDashboardPage-BDIjFIYZ.js.map} +1 -1
  25. package/dist/chunks/{ApplicationsGridPage-BQaMsK1K.js → ApplicationsGridPage-DV-FihKj.js} +2 -2
  26. package/dist/chunks/{ApplicationsGridPage-BQaMsK1K.js.map → ApplicationsGridPage-DV-FihKj.js.map} +1 -1
  27. package/dist/chunks/{ApplicationsGridPage-DbVcvezt.js → ApplicationsGridPage-DXsTfXPI.js} +2 -2
  28. package/dist/chunks/{ApplicationsGridPage-DbVcvezt.js.map → ApplicationsGridPage-DXsTfXPI.js.map} +1 -1
  29. package/dist/chunks/{ApplicationsListPage-DYKM2Yeo.js → ApplicationsListPage--CGkyBuJ.js} +2 -2
  30. package/dist/chunks/{ApplicationsListPage-DYKM2Yeo.js.map → ApplicationsListPage--CGkyBuJ.js.map} +1 -1
  31. package/dist/chunks/{ApplicationsListPage-C91v2rZt.js → ApplicationsListPage-JUX823bh.js} +2 -2
  32. package/dist/chunks/{ApplicationsListPage-C91v2rZt.js.map → ApplicationsListPage-JUX823bh.js.map} +1 -1
  33. package/dist/chunks/{ApplicationsPage-BCbgotIx.js → ApplicationsPage-6zgFye6w.js} +2 -2
  34. package/dist/chunks/{ApplicationsPage-BCbgotIx.js.map → ApplicationsPage-6zgFye6w.js.map} +1 -1
  35. package/dist/chunks/{ApplicationsPage-CW3-Hjlu.js → ApplicationsPage-CQPuuiO6.js} +4 -4
  36. package/dist/chunks/{ApplicationsPage-CW3-Hjlu.js.map → ApplicationsPage-CQPuuiO6.js.map} +1 -1
  37. package/dist/chunks/{AssignmentRulesPage-D8vfGDBN.js → AssignmentRulesPage-CFffeEbo.js} +2 -2
  38. package/dist/chunks/{AssignmentRulesPage-D8vfGDBN.js.map → AssignmentRulesPage-CFffeEbo.js.map} +1 -1
  39. package/dist/chunks/{AssignmentRulesPage-CxktlEMB.js → AssignmentRulesPage-D78UeUId.js} +2 -2
  40. package/dist/chunks/{AssignmentRulesPage-CxktlEMB.js.map → AssignmentRulesPage-D78UeUId.js.map} +1 -1
  41. package/dist/chunks/{AssignmentsPage-DmfBYQAD.js → AssignmentsPage-Cww2ifZF.js} +2 -2
  42. package/dist/chunks/{AssignmentsPage-DmfBYQAD.js.map → AssignmentsPage-Cww2ifZF.js.map} +1 -1
  43. package/dist/chunks/{AssignmentsPage-sRCCBmRc.js → AssignmentsPage-DE_QS2LO.js} +2 -2
  44. package/dist/chunks/{AssignmentsPage-sRCCBmRc.js.map → AssignmentsPage-DE_QS2LO.js.map} +1 -1
  45. package/dist/chunks/{AuthCallbackPage-C7XiZxKb.js → AuthCallbackPage-CA2nO6DG.js} +2 -2
  46. package/dist/chunks/{AuthCallbackPage-C7XiZxKb.js.map → AuthCallbackPage-CA2nO6DG.js.map} +1 -1
  47. package/dist/chunks/{AuthCallbackPage-BCe_bwJM.js → AuthCallbackPage-CDUAoX-N.js} +2 -2
  48. package/dist/chunks/{AuthCallbackPage-BCe_bwJM.js.map → AuthCallbackPage-CDUAoX-N.js.map} +1 -1
  49. package/dist/chunks/{ConfirmEmailPage-BUfGSqxF.js → ConfirmEmailPage-BqsILAYH.js} +2 -2
  50. package/dist/chunks/{ConfirmEmailPage-BUfGSqxF.js.map → ConfirmEmailPage-BqsILAYH.js.map} +1 -1
  51. package/dist/chunks/{ConfirmEmailPage-Buj4x-rx.js → ConfirmEmailPage-INeHCuMB.js} +2 -2
  52. package/dist/chunks/{ConfirmEmailPage-Buj4x-rx.js.map → ConfirmEmailPage-INeHCuMB.js.map} +1 -1
  53. package/dist/chunks/{CreateSupportTicketPage-CKDX_HQm.js → CreateSupportTicketPage-BWeuV2aU.js} +2 -2
  54. package/dist/chunks/{CreateSupportTicketPage-CKDX_HQm.js.map → CreateSupportTicketPage-BWeuV2aU.js.map} +1 -1
  55. package/dist/chunks/{CreateSupportTicketPage-0LgY-_pu.js → CreateSupportTicketPage-OBwF4v7b.js} +2 -2
  56. package/dist/chunks/{CreateSupportTicketPage-0LgY-_pu.js.map → CreateSupportTicketPage-OBwF4v7b.js.map} +1 -1
  57. package/dist/chunks/{DashboardPage-CUZ80NGV.js → DashboardPage-CKHqWrdS.js} +3 -3
  58. package/dist/chunks/{DashboardPage-CUZ80NGV.js.map → DashboardPage-CKHqWrdS.js.map} +1 -1
  59. package/dist/chunks/{DashboardPage-CaNOAstg.js → DashboardPage-COmc9b__.js} +3 -3
  60. package/dist/chunks/{DashboardPage-CaNOAstg.js.map → DashboardPage-COmc9b__.js.map} +1 -1
  61. package/dist/chunks/{DashboardPage-B48_rQFi.js → DashboardPage-CfKZHiSj.js} +2 -2
  62. package/dist/chunks/{DashboardPage-B48_rQFi.js.map → DashboardPage-CfKZHiSj.js.map} +1 -1
  63. package/dist/chunks/{DashboardPage-CUZV1J9t.js → DashboardPage-CwEZZ3jx.js} +2 -2
  64. package/dist/chunks/{DashboardPage-CUZV1J9t.js.map → DashboardPage-CwEZZ3jx.js.map} +1 -1
  65. package/dist/chunks/{EscalationConfigPage-CdzAbnGy.js → EscalationConfigPage--7lgZ0kJ.js} +2 -2
  66. package/dist/chunks/{EscalationConfigPage-CdzAbnGy.js.map → EscalationConfigPage--7lgZ0kJ.js.map} +1 -1
  67. package/dist/chunks/{EscalationConfigPage-CYGIl_e6.js → EscalationConfigPage-DPyiBcqV.js} +2 -2
  68. package/dist/chunks/{EscalationConfigPage-CYGIl_e6.js.map → EscalationConfigPage-DPyiBcqV.js.map} +1 -1
  69. package/dist/chunks/{ForceChangePasswordPage-lRpkwcX7.js → ForceChangePasswordPage-BE-6umub.js} +2 -2
  70. package/dist/chunks/{ForceChangePasswordPage-lRpkwcX7.js.map → ForceChangePasswordPage-BE-6umub.js.map} +1 -1
  71. package/dist/chunks/{ForceChangePasswordPage-CvmYAV3r.js → ForceChangePasswordPage-CnsYoWmV.js} +2 -2
  72. package/dist/chunks/{ForceChangePasswordPage-CvmYAV3r.js.map → ForceChangePasswordPage-CnsYoWmV.js.map} +1 -1
  73. package/dist/chunks/{ForgotPasswordPage-0u49E4Pw.js → ForgotPasswordPage-CSq4DnFF.js} +2 -2
  74. package/dist/chunks/{ForgotPasswordPage-0u49E4Pw.js.map → ForgotPasswordPage-CSq4DnFF.js.map} +1 -1
  75. package/dist/chunks/{ForgotPasswordPage-CxQUqKOm.js → ForgotPasswordPage-DZLVolAC.js} +2 -2
  76. package/dist/chunks/{ForgotPasswordPage-CxQUqKOm.js.map → ForgotPasswordPage-DZLVolAC.js.map} +1 -1
  77. package/dist/chunks/{GroupDetailPage-DFBvVO1S.js → GroupDetailPage-Bf9Wb_2j.js} +5 -5
  78. package/dist/chunks/{GroupDetailPage-DFBvVO1S.js.map → GroupDetailPage-Bf9Wb_2j.js.map} +1 -1
  79. package/dist/chunks/{GroupDetailPage-B2FkKrGG.js → GroupDetailPage-R-hf3rJ7.js} +2 -2
  80. package/dist/chunks/{GroupDetailPage-B2FkKrGG.js.map → GroupDetailPage-R-hf3rJ7.js.map} +1 -1
  81. package/dist/chunks/{MyAccessRequestsPage-C9IX4c0K.js → MyAccessRequestsPage-BIisvWM6.js} +2 -2
  82. package/dist/chunks/{MyAccessRequestsPage-C9IX4c0K.js.map → MyAccessRequestsPage-BIisvWM6.js.map} +1 -1
  83. package/dist/chunks/{MyAccessRequestsPage-D6pVULNM.js → MyAccessRequestsPage-BLSV7Tbx.js} +2 -2
  84. package/dist/chunks/{MyAccessRequestsPage-D6pVULNM.js.map → MyAccessRequestsPage-BLSV7Tbx.js.map} +1 -1
  85. package/dist/chunks/{MyTenantsPage-BEcYYdGR.js → MyTenantsPage-D-7k9CP1.js} +3 -3
  86. package/dist/chunks/{MyTenantsPage-BEcYYdGR.js.map → MyTenantsPage-D-7k9CP1.js.map} +1 -1
  87. package/dist/chunks/{MyTenantsPage-D9f85zjF.js → MyTenantsPage-DqGW6aDt.js} +2 -2
  88. package/dist/chunks/{MyTenantsPage-D9f85zjF.js.map → MyTenantsPage-DqGW6aDt.js.map} +1 -1
  89. package/dist/chunks/{MyTicketsPage-DJR8h6y1.js → MyTicketsPage--DgDsnZA.js} +2 -2
  90. package/dist/chunks/{MyTicketsPage-DJR8h6y1.js.map → MyTicketsPage--DgDsnZA.js.map} +1 -1
  91. package/dist/chunks/{MyTicketsPage-DiOUExKJ.js → MyTicketsPage-CqJ3Aqob.js} +2 -2
  92. package/dist/chunks/{MyTicketsPage-DiOUExKJ.js.map → MyTicketsPage-CqJ3Aqob.js.map} +1 -1
  93. package/dist/chunks/{NavigationAppsPage-CeHbxfZw.js → NavigationAppsPage-Bebis_RT.js} +2 -2
  94. package/dist/chunks/{NavigationAppsPage-CeHbxfZw.js.map → NavigationAppsPage-Bebis_RT.js.map} +1 -1
  95. package/dist/chunks/{NavigationAppsPage-If7tmCFY.js → NavigationAppsPage-THNPOAjv.js} +2 -2
  96. package/dist/chunks/{NavigationAppsPage-If7tmCFY.js.map → NavigationAppsPage-THNPOAjv.js.map} +1 -1
  97. package/dist/chunks/{NotificationsPage-C29Lln5o.js → NotificationsPage-CAbNW_Cn.js} +2 -2
  98. package/dist/chunks/{NotificationsPage-C29Lln5o.js.map → NotificationsPage-CAbNW_Cn.js.map} +1 -1
  99. package/dist/chunks/{NotificationsPage-BiaLRb0s.js → NotificationsPage-DxwizUhL.js} +2 -2
  100. package/dist/chunks/{NotificationsPage-BiaLRb0s.js.map → NotificationsPage-DxwizUhL.js.map} +1 -1
  101. package/dist/chunks/{OnboardingWizardPage-DQrBKNBq.js → OnboardingWizardPage-C6HlbJ3K.js} +2 -2
  102. package/dist/chunks/{OnboardingWizardPage-DQrBKNBq.js.map → OnboardingWizardPage-C6HlbJ3K.js.map} +1 -1
  103. package/dist/chunks/{OnboardingWizardPage-BQah4cI8.js → OnboardingWizardPage-CyC2zONO.js} +2 -2
  104. package/dist/chunks/{OnboardingWizardPage-BQah4cI8.js.map → OnboardingWizardPage-CyC2zONO.js.map} +1 -1
  105. package/dist/chunks/{PermissionDetailPage-Ckjdjvf9.js → PermissionDetailPage-BDHiNgky.js} +2 -2
  106. package/dist/chunks/{PermissionDetailPage-Ckjdjvf9.js.map → PermissionDetailPage-BDHiNgky.js.map} +1 -1
  107. package/dist/chunks/{PermissionDetailPage-Dh8v7mGj.js → PermissionDetailPage-C5K17ydY.js} +2 -2
  108. package/dist/chunks/{PermissionDetailPage-Dh8v7mGj.js.map → PermissionDetailPage-C5K17ydY.js.map} +1 -1
  109. package/dist/chunks/{PermissionsPage-l0PnY-EE.js → PermissionsPage-COI5LJPo.js} +2 -2
  110. package/dist/chunks/{PermissionsPage-l0PnY-EE.js.map → PermissionsPage-COI5LJPo.js.map} +1 -1
  111. package/dist/chunks/{PermissionsPage-DLy9U3P3.js → PermissionsPage-CkOwH2_d.js} +2 -2
  112. package/dist/chunks/{PermissionsPage-DLy9U3P3.js.map → PermissionsPage-CkOwH2_d.js.map} +1 -1
  113. package/dist/chunks/{PortalDashboardPage-DFBx38-x.js → PortalDashboardPage-CoEC4CmC.js} +2 -2
  114. package/dist/chunks/{PortalDashboardPage-DFBx38-x.js.map → PortalDashboardPage-CoEC4CmC.js.map} +1 -1
  115. package/dist/chunks/{PortalDashboardPage-rQYhrX0q.js → PortalDashboardPage-DrYymEf-.js} +2 -2
  116. package/dist/chunks/{PortalDashboardPage-rQYhrX0q.js.map → PortalDashboardPage-DrYymEf-.js.map} +1 -1
  117. package/dist/chunks/{PreferencesPage-BBu8yZQB.js → PreferencesPage-CJRaU3ba.js} +2 -2
  118. package/dist/chunks/{PreferencesPage-BBu8yZQB.js.map → PreferencesPage-CJRaU3ba.js.map} +1 -1
  119. package/dist/chunks/{PreferencesPage-B81MsNV1.js → PreferencesPage-Cqr9mAab.js} +2 -2
  120. package/dist/chunks/{PreferencesPage-B81MsNV1.js.map → PreferencesPage-Cqr9mAab.js.map} +1 -1
  121. package/dist/chunks/{ProfilePage-DDrl10zj.js → ProfilePage-BZVpg6-l.js} +2 -2
  122. package/dist/chunks/{ProfilePage-DDrl10zj.js.map → ProfilePage-BZVpg6-l.js.map} +1 -1
  123. package/dist/chunks/{ProfilePage-DPoXwdnc.js → ProfilePage-Cu_FITeL.js} +2 -2
  124. package/dist/chunks/{ProfilePage-DPoXwdnc.js.map → ProfilePage-Cu_FITeL.js.map} +1 -1
  125. package/dist/chunks/{ReferencesManagementPage-eFsKjIEK.js → ReferencesManagementPage-DUlVk9Ps.js} +3 -3
  126. package/dist/chunks/{ReferencesManagementPage-eFsKjIEK.js.map → ReferencesManagementPage-DUlVk9Ps.js.map} +1 -1
  127. package/dist/chunks/{ReferencesManagementPage-DhVsuElE.js → ReferencesManagementPage-ZCuYtqd7.js} +2 -2
  128. package/dist/chunks/{ReferencesManagementPage-DhVsuElE.js.map → ReferencesManagementPage-ZCuYtqd7.js.map} +1 -1
  129. package/dist/chunks/{RegisterPage-CiQib3-6.js → RegisterPage-C4xmVwh9.js} +2 -2
  130. package/dist/chunks/{RegisterPage-CiQib3-6.js.map → RegisterPage-C4xmVwh9.js.map} +1 -1
  131. package/dist/chunks/{RegisterPage-bXCcJD88.js → RegisterPage-DGyzoIHT.js} +2 -2
  132. package/dist/chunks/{RegisterPage-bXCcJD88.js.map → RegisterPage-DGyzoIHT.js.map} +1 -1
  133. package/dist/chunks/{ResetPasswordPage-Dqiahhnj.js → ResetPasswordPage-DqDD6VPR.js} +2 -2
  134. package/dist/chunks/{ResetPasswordPage-Dqiahhnj.js.map → ResetPasswordPage-DqDD6VPR.js.map} +1 -1
  135. package/dist/chunks/{ResetPasswordPage-CubPG3yv.js → ResetPasswordPage-Glu-aeqv.js} +2 -2
  136. package/dist/chunks/{ResetPasswordPage-CubPG3yv.js.map → ResetPasswordPage-Glu-aeqv.js.map} +1 -1
  137. package/dist/chunks/{ResolutionModal-Bg7XZmR1.js → ResolutionModal-CxjANAOP.js} +2 -2
  138. package/dist/chunks/{ResolutionModal-Bg7XZmR1.js.map → ResolutionModal-CxjANAOP.js.map} +1 -1
  139. package/dist/chunks/{ResolutionModal-DqRk_T0n.js → ResolutionModal-Duat18qV.js} +2 -2
  140. package/dist/chunks/{ResolutionModal-DqRk_T0n.js.map → ResolutionModal-Duat18qV.js.map} +1 -1
  141. package/dist/chunks/{RoleDetailPage-Blau6_4c.js → RoleDetailPage-BQffUSnt.js} +3 -3
  142. package/dist/chunks/{RoleDetailPage-Blau6_4c.js.map → RoleDetailPage-BQffUSnt.js.map} +1 -1
  143. package/dist/chunks/{RoleDetailPage-CiRVxxIP.js → RoleDetailPage-JTm5lD1_.js} +2 -2
  144. package/dist/chunks/{RoleDetailPage-CiRVxxIP.js.map → RoleDetailPage-JTm5lD1_.js.map} +1 -1
  145. package/dist/chunks/{RolesPage-Pm-RN3lP.js → RolesPage-B9rRzciI.js} +2 -2
  146. package/dist/chunks/{RolesPage-Pm-RN3lP.js.map → RolesPage-B9rRzciI.js.map} +1 -1
  147. package/dist/chunks/{RolesPage-Cb8joqdJ.js → RolesPage-BN8_zMOC.js} +2 -2
  148. package/dist/chunks/{RolesPage-Cb8joqdJ.js.map → RolesPage-BN8_zMOC.js.map} +1 -1
  149. package/dist/chunks/{SlaConfigPage-B86McKM6.js → SlaConfigPage-B7kZNig4.js} +2 -2
  150. package/dist/chunks/{SlaConfigPage-B86McKM6.js.map → SlaConfigPage-B7kZNig4.js.map} +1 -1
  151. package/dist/chunks/{SlaConfigPage-BY7gvYU6.js → SlaConfigPage-okvZfA_K.js} +2 -2
  152. package/dist/chunks/{SlaConfigPage-BY7gvYU6.js.map → SlaConfigPage-okvZfA_K.js.map} +1 -1
  153. package/dist/chunks/{SupportPermissionsPage-BYxcLMSd.js → SupportPermissionsPage-DGAPqJbl.js} +2 -2
  154. package/dist/chunks/{SupportPermissionsPage-BYxcLMSd.js.map → SupportPermissionsPage-DGAPqJbl.js.map} +1 -1
  155. package/dist/chunks/{SupportPermissionsPage-MXqXNJIZ.js → SupportPermissionsPage-Dg_wLOme.js} +2 -2
  156. package/dist/chunks/{SupportPermissionsPage-MXqXNJIZ.js.map → SupportPermissionsPage-Dg_wLOme.js.map} +1 -1
  157. package/dist/chunks/{TemplatesPage-BDguJ401.js → TemplatesPage-DT9fhlAU.js} +2 -2
  158. package/dist/chunks/{TemplatesPage-BDguJ401.js.map → TemplatesPage-DT9fhlAU.js.map} +1 -1
  159. package/dist/chunks/{TemplatesPage-DdnGgioU.js → TemplatesPage-DiEk538p.js} +2 -2
  160. package/dist/chunks/{TemplatesPage-DdnGgioU.js.map → TemplatesPage-DiEk538p.js.map} +1 -1
  161. package/dist/chunks/{TenantCard-ffwWsgFQ.js → TenantCard-BbSYk9_Z.js} +2 -2
  162. package/dist/chunks/{TenantCard-ffwWsgFQ.js.map → TenantCard-BbSYk9_Z.js.map} +1 -1
  163. package/dist/chunks/{TenantCard-CUjb6og9.js → TenantCard-CEkiKxcZ.js} +2 -2
  164. package/dist/chunks/{TenantCard-CUjb6og9.js.map → TenantCard-CEkiKxcZ.js.map} +1 -1
  165. package/dist/chunks/{TenantScopeSelector-Dz7i1I43.js → TenantScopeSelector-BWfYxvEa.js} +2 -2
  166. package/dist/chunks/{TenantScopeSelector-Dz7i1I43.js.map → TenantScopeSelector-BWfYxvEa.js.map} +1 -1
  167. package/dist/chunks/{TenantScopeSelector-Cym_Zyps.js → TenantScopeSelector-D-BKgQPV.js} +2 -2
  168. package/dist/chunks/{TenantScopeSelector-Cym_Zyps.js.map → TenantScopeSelector-D-BKgQPV.js.map} +1 -1
  169. package/dist/chunks/{TicketDetailPage-GOh9GX7E.js → TicketDetailPage-C1mNS9Up.js} +2 -2
  170. package/dist/chunks/{TicketDetailPage-GOh9GX7E.js.map → TicketDetailPage-C1mNS9Up.js.map} +1 -1
  171. package/dist/chunks/{TicketDetailPage-Du8WMyqf.js → TicketDetailPage-ieVDRh42.js} +2 -2
  172. package/dist/chunks/{TicketDetailPage-Du8WMyqf.js.map → TicketDetailPage-ieVDRh42.js.map} +1 -1
  173. package/dist/chunks/{TicketsPage-Bqd6moQy.js → TicketsPage-CnuWsnIW.js} +2 -2
  174. package/dist/chunks/{TicketsPage-Bqd6moQy.js.map → TicketsPage-CnuWsnIW.js.map} +1 -1
  175. package/dist/chunks/{TicketsPage-WdU4Bb7M.js → TicketsPage-jjyY15_D.js} +2 -2
  176. package/dist/chunks/{TicketsPage-WdU4Bb7M.js.map → TicketsPage-jjyY15_D.js.map} +1 -1
  177. package/dist/chunks/{UserCreateTicketPage-Cm1emgwR.js → UserCreateTicketPage-B8Tvf-ag.js} +2 -2
  178. package/dist/chunks/{UserCreateTicketPage-Cm1emgwR.js.map → UserCreateTicketPage-B8Tvf-ag.js.map} +1 -1
  179. package/dist/chunks/{UserCreateTicketPage-BPw-5Y_D.js → UserCreateTicketPage-DnOsDlfO.js} +2 -2
  180. package/dist/chunks/{UserCreateTicketPage-BPw-5Y_D.js.map → UserCreateTicketPage-DnOsDlfO.js.map} +1 -1
  181. package/dist/chunks/{UserDashboardPage-BP5WeXPS.js → UserDashboardPage-BrtkJ-NB.js} +2 -2
  182. package/dist/chunks/{UserDashboardPage-BP5WeXPS.js.map → UserDashboardPage-BrtkJ-NB.js.map} +1 -1
  183. package/dist/chunks/{UserDashboardPage-B53C8fUq.js → UserDashboardPage-KLB5CQP5.js} +2 -2
  184. package/dist/chunks/{UserDashboardPage-B53C8fUq.js.map → UserDashboardPage-KLB5CQP5.js.map} +1 -1
  185. package/dist/chunks/{UserDetailPage-B110bmGX.js → UserDetailPage-U7smBQoF.js} +5 -5
  186. package/dist/chunks/{UserDetailPage-B110bmGX.js.map → UserDetailPage-U7smBQoF.js.map} +1 -1
  187. package/dist/chunks/{UserDetailPage-CV2VCE46.js → UserDetailPage-_J6lcKAU.js} +2 -2
  188. package/dist/chunks/{UserDetailPage-CV2VCE46.js.map → UserDetailPage-_J6lcKAU.js.map} +1 -1
  189. package/dist/chunks/{UserTicketDetailPage-CCNJON1V.js → UserTicketDetailPage-CWoYQgH-.js} +2 -2
  190. package/dist/chunks/{UserTicketDetailPage-CCNJON1V.js.map → UserTicketDetailPage-CWoYQgH-.js.map} +1 -1
  191. package/dist/chunks/{UserTicketDetailPage-V0mLXrox.js → UserTicketDetailPage-DkufSlvZ.js} +2 -2
  192. package/dist/chunks/{UserTicketDetailPage-V0mLXrox.js.map → UserTicketDetailPage-DkufSlvZ.js.map} +1 -1
  193. package/dist/chunks/{UsersGroupsPage-CmdaU-z-.js → UsersGroupsPage-C38s2-Rq.js} +3 -3
  194. package/dist/chunks/{UsersGroupsPage-CmdaU-z-.js.map → UsersGroupsPage-C38s2-Rq.js.map} +1 -1
  195. package/dist/chunks/{UsersGroupsPage-BgfAMgEP.js → UsersGroupsPage-Dq3rAteo.js} +2 -2
  196. package/dist/chunks/{UsersGroupsPage-BgfAMgEP.js.map → UsersGroupsPage-Dq3rAteo.js.map} +1 -1
  197. package/dist/chunks/{UsersPage-Bg7033pp.js → UsersPage-B5C5KEUR.js} +2 -2
  198. package/dist/chunks/{UsersPage-Bg7033pp.js.map → UsersPage-B5C5KEUR.js.map} +1 -1
  199. package/dist/chunks/{UsersPage-TYAfwPY1.js → UsersPage-CXC9Hvq6.js} +2 -2
  200. package/dist/chunks/{UsersPage-TYAfwPY1.js.map → UsersPage-CXC9Hvq6.js.map} +1 -1
  201. package/dist/chunks/{accessRequestsApi-DZeDvzwv.js → accessRequestsApi-B-4TJ5_U.js} +2 -2
  202. package/dist/chunks/{accessRequestsApi-DZeDvzwv.js.map → accessRequestsApi-B-4TJ5_U.js.map} +1 -1
  203. package/dist/chunks/{accessRequestsApi-ZXFPCid2.js → accessRequestsApi-DZSfThpd.js} +2 -2
  204. package/dist/chunks/{accessRequestsApi-ZXFPCid2.js.map → accessRequestsApi-DZSfThpd.js.map} +1 -1
  205. package/dist/chunks/{aiApi-CsH8DXgs.js → aiApi-B20Teu2v.js} +2 -2
  206. package/dist/chunks/{aiApi-CsH8DXgs.js.map → aiApi-B20Teu2v.js.map} +1 -1
  207. package/dist/chunks/{aiApi-CVPzFTXa.js → aiApi-DMGz-RPM.js} +2 -2
  208. package/dist/chunks/{aiApi-CVPzFTXa.js.map → aiApi-DMGz-RPM.js.map} +1 -1
  209. package/dist/chunks/{applicationAnalyticsApi-B8AhFYLr.js → applicationAnalyticsApi-Bwa75Fzd.js} +2 -2
  210. package/dist/chunks/{applicationAnalyticsApi-B8AhFYLr.js.map → applicationAnalyticsApi-Bwa75Fzd.js.map} +1 -1
  211. package/dist/chunks/{applicationAnalyticsApi-Ce_1qOk-.js → applicationAnalyticsApi-CLBqRPfN.js} +2 -2
  212. package/dist/chunks/{applicationAnalyticsApi-Ce_1qOk-.js.map → applicationAnalyticsApi-CLBqRPfN.js.map} +1 -1
  213. package/dist/chunks/{groupsApi-BgCk2fsp.js → groupsApi-QzXI-5xu.js} +2 -2
  214. package/dist/chunks/{groupsApi-BgCk2fsp.js.map → groupsApi-QzXI-5xu.js.map} +1 -1
  215. package/dist/chunks/{groupsApi-BIbG665N.js → groupsApi-hB9kSWEd.js} +2 -2
  216. package/dist/chunks/{groupsApi-BIbG665N.js.map → groupsApi-hB9kSWEd.js.map} +1 -1
  217. package/dist/chunks/{index-Cb3LotuT.js → index--NGcBYUu.js} +3 -3
  218. package/dist/chunks/{index-Cb3LotuT.js.map → index--NGcBYUu.js.map} +1 -1
  219. package/dist/chunks/{index-C33zcyF4.js → index--aPwOFjF.js} +2 -2
  220. package/dist/chunks/{index-C33zcyF4.js.map → index--aPwOFjF.js.map} +1 -1
  221. package/dist/chunks/{index-sMr9qND_.js → index-0VrOtwP0.js} +2 -2
  222. package/dist/chunks/{index-sMr9qND_.js.map → index-0VrOtwP0.js.map} +1 -1
  223. package/dist/chunks/{index-DDKetfKq.js → index-37U271aw.js} +2 -2
  224. package/dist/chunks/{index-DDKetfKq.js.map → index-37U271aw.js.map} +1 -1
  225. package/dist/chunks/{index-B9fS7ir6.js → index-B7qZTuQ-.js} +2 -2
  226. package/dist/chunks/{index-B9fS7ir6.js.map → index-B7qZTuQ-.js.map} +1 -1
  227. package/dist/chunks/{index-CdjBY7L8.js → index-Bedzmqr-.js} +2 -2
  228. package/dist/chunks/{index-CdjBY7L8.js.map → index-Bedzmqr-.js.map} +1 -1
  229. package/dist/chunks/{index-CHG_O1fS.js → index-Betxo5g5.js} +2 -2
  230. package/dist/chunks/{index-CHG_O1fS.js.map → index-Betxo5g5.js.map} +1 -1
  231. package/dist/chunks/{index-jiGu-H8x.js → index-BmaJz475.js} +2 -2
  232. package/dist/chunks/{index-jiGu-H8x.js.map → index-BmaJz475.js.map} +1 -1
  233. package/dist/chunks/{index-C53JoVNk.js → index-Buhqag3v.js} +2 -2
  234. package/dist/chunks/{index-C53JoVNk.js.map → index-Buhqag3v.js.map} +1 -1
  235. package/dist/chunks/{index-DO0Rw7hX.js → index-C3VxlfKq.js} +2 -2
  236. package/dist/chunks/{index-DO0Rw7hX.js.map → index-C3VxlfKq.js.map} +1 -1
  237. package/dist/chunks/{index-CSQ60fpG.js → index-CgpRo8Oe.js} +2 -2
  238. package/dist/chunks/{index-CSQ60fpG.js.map → index-CgpRo8Oe.js.map} +1 -1
  239. package/dist/chunks/{index-B-e-ELsf.js → index-DOY0w8Iu.js} +8 -8
  240. package/dist/chunks/{index-B-e-ELsf.js.map → index-DOY0w8Iu.js.map} +1 -1
  241. package/dist/chunks/{index-D2REDIRX.js → index-DwuvIOrQ.js} +2 -2
  242. package/dist/chunks/{index-D2REDIRX.js.map → index-DwuvIOrQ.js.map} +1 -1
  243. package/dist/chunks/{index-DCcl7Qof.js → index-DzedSLdI.js} +2 -2
  244. package/dist/chunks/{index-DCcl7Qof.js.map → index-DzedSLdI.js.map} +1 -1
  245. package/dist/chunks/{index-2wUhd9Lu.js → index-IgLVXPg8.js} +10 -10
  246. package/dist/chunks/index-IgLVXPg8.js.map +1 -0
  247. package/dist/chunks/{index-CwSaRXXg.js → index-lpIzhufD.js} +1916 -1900
  248. package/dist/chunks/index-lpIzhufD.js.map +1 -0
  249. package/dist/chunks/{index-Cuwn2q-f.js → index-mLUKwbGl.js} +4 -4
  250. package/dist/chunks/{index-Cuwn2q-f.js.map → index-mLUKwbGl.js.map} +1 -1
  251. package/dist/chunks/{index-B0mk2tNY.js → index-tO6MMIFB.js} +2 -2
  252. package/dist/chunks/{index-B0mk2tNY.js.map → index-tO6MMIFB.js.map} +1 -1
  253. package/dist/chunks/{tenantIconMap-BpNANQ5s.js → tenantIconMap-BQD9byc8.js} +2 -2
  254. package/dist/chunks/{tenantIconMap-BpNANQ5s.js.map → tenantIconMap-BQD9byc8.js.map} +1 -1
  255. package/dist/chunks/{tenantIconMap-DtdUgvJO.js → tenantIconMap-CTMuSt18.js} +2 -2
  256. package/dist/chunks/{tenantIconMap-DtdUgvJO.js.map → tenantIconMap-CTMuSt18.js.map} +1 -1
  257. package/dist/chunks/{ticketingApi-Bu4rKwLl.js → ticketingApi-BNIdox5t.js} +2 -2
  258. package/dist/chunks/{ticketingApi-Bu4rKwLl.js.map → ticketingApi-BNIdox5t.js.map} +1 -1
  259. package/dist/chunks/{ticketingApi-r4Avm9iS.js → ticketingApi-J0vC_t7r.js} +2 -2
  260. package/dist/chunks/{ticketingApi-r4Avm9iS.js.map → ticketingApi-J0vC_t7r.js.map} +1 -1
  261. package/dist/chunks/{useAccessRequests-B9bF4swg.js → useAccessRequests-DCNNLnxk.js} +3 -3
  262. package/dist/chunks/{useAccessRequests-B9bF4swg.js.map → useAccessRequests-DCNNLnxk.js.map} +1 -1
  263. package/dist/chunks/{useAccessRequests-JyPUX3Om.js → useAccessRequests-DT7X4FAK.js} +2 -2
  264. package/dist/chunks/{useAccessRequests-JyPUX3Om.js.map → useAccessRequests-DT7X4FAK.js.map} +1 -1
  265. package/dist/chunks/{useUserAccessRequests-DjPQenC2.js → useUserAccessRequests-BYbmG4c7.js} +2 -2
  266. package/dist/chunks/{useUserAccessRequests-DjPQenC2.js.map → useUserAccessRequests-BYbmG4c7.js.map} +1 -1
  267. package/dist/chunks/{useUserAccessRequests-BB6FHW14.js → useUserAccessRequests-CylKxRN6.js} +2 -2
  268. package/dist/chunks/{useUserAccessRequests-BB6FHW14.js.map → useUserAccessRequests-CylKxRN6.js.map} +1 -1
  269. package/dist/hooks/useCollapsibleState.d.ts +5 -2
  270. package/dist/hooks/useCollapsibleState.d.ts.map +1 -1
  271. package/dist/i18n/config.d.ts +1 -0
  272. package/dist/i18n/config.d.ts.map +1 -1
  273. package/dist/main.d.ts +0 -1
  274. package/dist/main.d.ts.map +1 -1
  275. package/dist/smartstack.cjs +1 -1
  276. package/dist/smartstack.js +1 -1
  277. package/dist/utils/permissions.d.ts.map +1 -1
  278. package/package.json +1 -1
  279. package/dist/chunks/index-2wUhd9Lu.js.map +0 -1
  280. package/dist/chunks/index-CwSaRXXg.js.map +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),Y=require("react-i18next"),t=require("lucide-react"),G=require("recharts"),J=require("./index-2wUhd9Lu.js"),E=require("./aiApi-CsH8DXgs.js"),De=require("./ConfirmModal-CYWRiVoD.js"),ke=require("./useTabNavigation-BVtbCTd5.js"),Z=require("react-router-dom"),ee=["#3b82f6","#8b5cf6","#22c55e","#f59e0b","#ef4444","#06b6d4","#ec4899","#14b8a6"],Pe={blue:"bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",green:"bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",yellow:"bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",red:"bg-[var(--error-bg)] text-[var(--error-text)] border-[var(--error-border)]",neutral:"bg-[var(--bg-secondary)] text-[var(--text-primary)] border-[var(--border-color)]"};function Fe(){const{t:s}=Y.useTranslation(["ai"]),[l,i]=r.useState(!0),[a,d]=r.useState(!1),[g,b]=r.useState(30),[f,y]=r.useState(""),[x,p]=r.useState(null),[k,T]=r.useState([]),[L,j]=r.useState([]),[P,u]=r.useState([]),[A,F]=r.useState(null),h=r.useCallback(async()=>{try{F(null);const m=f||void 0,[D,K,w,q]=await Promise.all([E.aiApi.dashboard.getOverview(g),E.aiApi.dashboard.getByProvider(),E.aiApi.dashboard.getByModel(void 0,void 0,m),E.aiApi.dashboard.getDailyCosts(g,m)]);p(D??null),T(K??[]),j(w??[]),u(q??[])}catch(m){console.error("Failed to load AI dashboard data:",m);const D=m;D.statusCode===401?F(s("dashboard.errors.sessionExpired")):D.statusCode===403?F(s("dashboard.errors.forbidden")):F(s("dashboard.errors.loadFailed"))}finally{i(!1),d(!1)}},[g,f,s]);r.useEffect(()=>{h()},[h]);const c=()=>{d(!0),h()},n=m=>{const D=Math.abs(m),w=D===0||D>=.01?2:D>=1e-4?4:6;return new Intl.NumberFormat("fr-FR",{style:"currency",currency:"USD",minimumFractionDigits:w,maximumFractionDigits:w}).format(m)},N=m=>new Intl.NumberFormat("fr-FR").format(m),o=r.useMemo(()=>{const m=new Map,D=new Set;for(const K of P){D.add(K.providerName),m.has(K.date)||m.set(K.date,{date:K.date});const w=m.get(K.date);w[K.providerName]=(w[K.providerName]??0)+K.totalCost}return{data:Array.from(m.values()).sort((K,w)=>String(K.date).localeCompare(String(w.date))),providers:Array.from(D)}},[P]),_=r.useMemo(()=>{const m=new Map;for(const D of P){const K=m.get(D.date);K?(K.requests+=D.requestCount,K.success+=D.successCount,K.errors+=D.errorCount):m.set(D.date,{date:D.date,requests:D.requestCount,success:D.successCount,errors:D.errorCount})}return Array.from(m.values()).sort((D,K)=>D.date.localeCompare(K.date)).map(D=>({...D,successRate:D.requests>0?D.success/D.requests*100:0}))},[P]),C=r.useMemo(()=>(x?.providerBreakdown??[]).map((m,D)=>({name:m.providerName,value:Number(m.totalCost),color:ee[D%ee.length]})),[x]),v=r.useMemo(()=>[...L].sort((m,D)=>D.totalCost-m.totalCost).slice(0,8).map(m=>({name:m.modelName.length>20?m.modelName.slice(0,18)+"...":m.modelName,fullName:m.modelName,tokens:m.totalTokens,cost:Number(m.totalCost),requests:m.requestCount,latency:Math.round(m.avgLatencyMs)})),[L]),O=r.useMemo(()=>{const m=P.reduce((K,w)=>K+w.totalInputTokens,0),D=P.reduce((K,w)=>K+w.totalOutputTokens,0);return m===0&&D===0?[]:[{name:s("dashboard.charts.inputTokens"),value:m,color:"#3b82f6"},{name:s("dashboard.charts.outputTokens"),value:D,color:"#8b5cf6"}]},[P,s]),W=r.useMemo(()=>{if(o.data.length<2)return null;const m=Math.floor(o.data.length/2),D=o.data.slice(0,m),K=o.data.slice(m),w=M=>M.reduce((S,I)=>{let R=0;for(const[V,U]of Object.entries(I))V!=="date"&&typeof U=="number"&&(R+=U);return S+R},0),q=w(D),B=w(K);return q===0?null:(B-q)/q*100},[o]);return l?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-500)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("ai.dashboard","Dashboard")}]}),A&&e.jsxs("div",{className:"bg-[var(--error-bg)] border border-[var(--error-border)] rounded-[var(--radius-card)] p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-[var(--error-text)] flex-shrink-0"}),e.jsx("p",{className:"flex-1 text-[var(--error-text)] font-medium",children:A}),e.jsx("button",{onClick:c,className:"text-[var(--error-text)] hover:opacity-80",children:e.jsx(t.RefreshCw,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Brain,{className:"w-6 h-6"}),s("dashboard.title")]}),e.jsx("p",{className:"text-[var(--text-secondary)] mt-1",children:s("dashboard.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("select",{value:f,onChange:m=>y(m.target.value),className:"input",children:[e.jsx("option",{value:"",children:s("dashboard.allProviders")}),k.map(m=>e.jsx("option",{value:m.providerId,children:m.providerName},m.providerId))]}),e.jsxs("select",{value:g,onChange:m=>b(Number(m.target.value)),className:"input",children:[e.jsx("option",{value:7,children:s("dashboard.period.7days")}),e.jsx("option",{value:30,children:s("dashboard.period.30days")}),e.jsx("option",{value:90,children:s("dashboard.period.90days")})]}),e.jsxs("button",{onClick:c,disabled:a,className:"btn btn-secondary flex items-center gap-2",children:[e.jsx(t.RefreshCw,{className:`w-4 h-4 ${a?"animate-spin":""}`}),s("dashboard.refresh")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:[e.jsx(re,{title:s("dashboard.kpis.totalCost"),value:n(x?.totalCost??0),icon:e.jsx(t.DollarSign,{className:"w-5 h-5"}),color:"green",trend:W}),e.jsx(re,{title:s("dashboard.kpis.totalTokens"),value:N(x?.totalTokens??0),icon:e.jsx(t.Zap,{className:"w-5 h-5"}),color:"blue"}),e.jsx(re,{title:s("dashboard.kpis.totalRequests"),value:N(x?.totalRequests??0),icon:e.jsx(t.Activity,{className:"w-5 h-5"}),color:"neutral"}),e.jsx(re,{title:s("dashboard.kpis.successRate"),value:`${(x?.successRate??0).toFixed(1)}%`,icon:e.jsx(t.CheckCircle,{className:"w-5 h-5"}),color:(()=>{const m=x?.successRate??0;return m>=95?"green":m>=80?"yellow":"red"})()}),e.jsx(re,{title:s("dashboard.kpis.avgLatency"),value:`${(x?.avgLatencyMs??0).toFixed(0)} ms`,icon:e.jsx(t.Clock,{className:"w-5 h-5"}),color:(()=>{const m=x?.avgLatencyMs??0;return m<=1e3?"green":m<=3e3?"yellow":"red"})()}),e.jsx(re,{title:s("dashboard.kpis.activeProviders"),value:`${x?.activeProviders??0} / ${x?.totalProviders??0}`,icon:e.jsx(t.Server,{className:"w-5 h-5"}),color:"blue"})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.DollarSign,{className:"w-5 h-5"}),s("dashboard.charts.dailyCosts")]}),o.data.length>0?e.jsx(G.ResponsiveContainer,{width:"100%",height:280,children:e.jsxs(G.AreaChart,{data:o.data,margin:{top:5,right:20,bottom:5,left:10},children:[e.jsx("defs",{children:o.providers.map((m,D)=>e.jsxs("linearGradient",{id:`grad-${D}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:ee[D%ee.length],stopOpacity:.4}),e.jsx("stop",{offset:"95%",stopColor:ee[D%ee.length],stopOpacity:.05})]},m))}),e.jsx(G.CartesianGrid,{strokeDasharray:"3 3",stroke:"var(--border-color)"}),e.jsx(G.XAxis,{dataKey:"date",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>m.slice(5)}),e.jsx(G.YAxis,{tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>`$${m}`}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:m=>[n(m??0),void 0],labelFormatter:m=>String(m)}),e.jsx(G.Legend,{}),o.providers.map((m,D)=>e.jsx(G.Area,{type:"monotone",dataKey:m,stackId:"1",stroke:ee[D%ee.length],fill:`url(#grad-${D})`,strokeWidth:2},m))]})}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.DollarSign,{className:"w-5 h-5"}),s("dashboard.charts.costByProvider")]}),C.length>0?e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(G.ResponsiveContainer,{width:"50%",height:220,children:e.jsxs(G.PieChart,{children:[e.jsx(G.Pie,{data:C,cx:"50%",cy:"50%",innerRadius:55,outerRadius:90,paddingAngle:2,dataKey:"value",children:C.map((m,D)=>e.jsx(G.Cell,{fill:m.color},`${m.name}-${D}`))}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:m=>[n(m??0),void 0]})]})}),e.jsx("div",{className:"flex-1 space-y-2",children:C.map(m=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:m.color}}),e.jsx("span",{className:"flex-1 truncate text-[var(--text-primary)]",children:m.name}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:n(m.value)})]},m.name))})]}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Zap,{className:"w-5 h-5"}),s("dashboard.charts.tokenDistribution")]}),O.length>0?e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(G.ResponsiveContainer,{width:"50%",height:220,children:e.jsxs(G.PieChart,{children:[e.jsx(G.Pie,{data:O,cx:"50%",cy:"50%",innerRadius:55,outerRadius:90,paddingAngle:2,dataKey:"value",children:O.map((m,D)=>e.jsx(G.Cell,{fill:m.color},`${m.name}-${D}`))}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:m=>[N(m??0),void 0]})]})}),e.jsx("div",{className:"flex-1 space-y-3",children:O.map(m=>{const D=O.reduce((w,q)=>w+q.value,0),K=D>0?(m.value/D*100).toFixed(1):"0";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:m.color}}),e.jsx("span",{className:"flex-1 text-[var(--text-primary)]",children:m.name}),e.jsxs("span",{className:"font-medium text-[var(--text-primary)]",children:[K,"%"]})]}),e.jsxs("p",{className:"text-xs text-[var(--text-secondary)] ml-5",children:[N(m.value)," tokens"]})]},m.name)})})]}):e.jsx(le,{message:s("dashboard.charts.noData")})]})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Activity,{className:"w-5 h-5"}),s("dashboard.charts.usageByModel")]}),v.length>0?e.jsx(G.ResponsiveContainer,{width:"100%",height:Math.max(200,v.length*44),children:e.jsxs(G.BarChart,{data:v,layout:"vertical",margin:{top:5,right:30,bottom:5,left:120},children:[e.jsx(G.CartesianGrid,{strokeDasharray:"3 3",stroke:"var(--border-color)",horizontal:!1}),e.jsx(G.XAxis,{type:"number",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>N(m)}),e.jsx(G.YAxis,{type:"category",dataKey:"name",tick:{fontSize:11,fill:"var(--text-primary)"},width:115}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:(m,D)=>{const K=m??0;return D==="tokens"?[N(K),"Tokens"]:D==="cost"?[n(K),s("dashboard.charts.costLabel")]:[K,D??""]},labelFormatter:(m,D)=>D?.[0]?.payload?.fullName??String(m)}),e.jsx(G.Legend,{}),e.jsx(G.Bar,{dataKey:"tokens",name:"Tokens",fill:"#3b82f6",radius:[0,4,4,0]})]})}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Activity,{className:"w-5 h-5"}),s("dashboard.charts.requestsAndSuccess")]}),_.length>0?e.jsx(G.ResponsiveContainer,{width:"100%",height:260,children:e.jsxs(G.ComposedChart,{data:_,margin:{top:5,right:20,bottom:5,left:10},children:[e.jsx(G.CartesianGrid,{strokeDasharray:"3 3",stroke:"var(--border-color)"}),e.jsx(G.XAxis,{dataKey:"date",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>m.slice(5)}),e.jsx(G.YAxis,{yAxisId:"left",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>N(m)}),e.jsx(G.YAxis,{yAxisId:"right",orientation:"right",domain:[0,100],tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>`${m}%`}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:(m,D)=>{const K=m??0;return D==="successRate"?[`${K.toFixed(1)}%`,s("dashboard.kpis.successRate")]:D==="errors"?[N(K),s("dashboard.charts.errors")]:[N(K),s("dashboard.charts.requests")]}}),e.jsx(G.Legend,{}),e.jsx(G.Bar,{yAxisId:"left",dataKey:"success",name:s("dashboard.charts.successRequests"),stackId:"req",fill:"#22c55e"}),e.jsx(G.Bar,{yAxisId:"left",dataKey:"errors",name:s("dashboard.charts.errors"),stackId:"req",fill:"#ef4444",radius:[4,4,0,0]}),e.jsx(G.Line,{yAxisId:"right",type:"monotone",dataKey:"successRate",name:s("dashboard.kpis.successRate"),stroke:"#f59e0b",strokeWidth:2,dot:!1})]})}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),L.length>0&&e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Clock,{className:"w-5 h-5"}),s("dashboard.charts.modelPerformance")]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[var(--border-color)] bg-[var(--bg-secondary)]",children:[e.jsx("th",{className:"text-left p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.model")}),e.jsx("th",{className:"text-left p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.provider")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.kpis.totalTokens")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.kpis.totalCost")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.requests")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.kpis.avgLatency")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.costPerRequest")})]})}),e.jsx("tbody",{children:[...L].sort((m,D)=>D.totalCost-m.totalCost).map(m=>e.jsxs("tr",{className:"border-b border-[var(--border-color)] hover:bg-[var(--bg-hover)]",children:[e.jsx("td",{className:"p-3 font-mono text-[var(--text-primary)]",children:m.modelName}),e.jsx("td",{className:"p-3 text-[var(--text-secondary)]",children:m.providerCode}),e.jsx("td",{className:"p-3 text-right font-mono",children:N(m.totalTokens)}),e.jsx("td",{className:"p-3 text-right font-medium",children:n(m.totalCost)}),e.jsx("td",{className:"p-3 text-right",children:N(m.requestCount)}),e.jsxs("td",{className:"p-3 text-right",children:[Math.round(m.avgLatencyMs)," ms"]}),e.jsx("td",{className:"p-3 text-right text-[var(--text-secondary)]",children:m.requestCount>0?n(m.totalCost/m.requestCount):"—"})]},`${m.providerId}-${m.modelName}`))})]})})]})]})}function re({title:s,value:l,icon:i,color:a,trend:d}){return e.jsxs("div",{className:`card p-4 border ${Pe[a]}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium opacity-80",children:s}),i]}),e.jsx("div",{className:"text-2xl font-bold",children:l}),d!=null&&e.jsxs("div",{className:`flex items-center gap-1 mt-1 text-xs font-medium ${d>0?"text-red-500":"text-green-500"}`,children:[d>0?e.jsx(t.TrendingUp,{className:"w-3 h-3"}):e.jsx(t.TrendingDown,{className:"w-3 h-3"}),e.jsxs("span",{children:[Math.abs(d).toFixed(1),"%"]})]})]})}function le({message:s}){return e.jsx("div",{className:"flex items-center justify-center py-12 text-[var(--text-secondary)]",children:s})}const ie=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(s);function we({logoUrl:s,providerCode:l,size:i="md"}){const[a,d]=r.useState(!1),g={sm:{size:"w-8 h-8 text-sm",img:"w-8 h-8"},md:{size:"w-10 h-10 text-base",img:"w-10 h-10"},lg:{size:"w-12 h-12 text-lg",img:"w-12 h-12"}};return!s||a?e.jsx("div",{className:`${g[i].size} bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] rounded-lg flex items-center justify-center font-bold text-[var(--color-accent-600)]`,children:l.charAt(0).toUpperCase()}):e.jsx("img",{src:s,alt:l,className:`${g[i].img} rounded-lg object-contain`,onError:()=>d(!0)})}function $e({t:s}){return e.jsxs("div",{className:"card p-12 text-center",children:[e.jsx(t.Layers,{className:"w-16 h-16 mx-auto mb-4 text-[var(--text-secondary)] opacity-50"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:s("settings.profiles.noInstances")}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("settings.profiles.subtitle")})]})}function Le({t:s}){return e.jsxs("div",{className:"card p-12 text-center",children:[e.jsx(t.Layers,{className:"w-16 h-16 mx-auto mb-4 text-[var(--text-secondary)] opacity-50"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("settings.profiles.actions.viewDetails")})]})}const Me=s=>s?"bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)]":"bg-[var(--bg-secondary)] text-[var(--text-secondary)] border border-[var(--border-color)]",Ee=(s,l)=>l(s?"settings.profiles.status.active":"settings.profiles.status.inactive");function Be({isActive:s,isOverBudget:l,t:i}){return e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Me(s)}`,children:Ee(s,i)}),l&&e.jsxs("span",{className:"px-2 py-0.5 rounded text-xs font-medium bg-[var(--error-bg)] text-[var(--error-text)] border border-[var(--error-border)] flex items-center gap-1",children:[e.jsx(t.AlertCircle,{className:"w-3 h-3"}),i("settings.profiles.usage.overBudget")]})]})}function Ie(s,l){return s?"border-[var(--color-accent-500)] shadow-[0_0_0_1px_var(--color-accent-500)]":l?"border-[var(--success-border)]":"border-[var(--border-color)]"}function he({type:s,hasKey:l,onSave:i,placeholder:a,providerKeyUrl:d,t:g}){const[b,f]=r.useState(!1),[y,x]=r.useState(""),[p,k]=r.useState(!1),[T,L]=r.useState(!1),j=s==="api",P=j?t.KeyRound:t.ShieldCheck,u=async()=>{if(y.trim()){k(!0);try{await i(y),x(""),L(!1),f(!1)}catch{}finally{k(!1)}}},A=()=>{x(""),L(!1),f(!1)};return e.jsxs("div",{className:`relative rounded-[var(--radius-card)] border overflow-hidden transition-all ${Ie(b,l)}`,children:[e.jsxs("div",{className:`px-4 py-3 flex items-center justify-between ${l?"bg-[var(--success-bg)]":"bg-[var(--bg-secondary)]"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center ${l?"bg-[var(--success-dot)] text-white":"bg-[var(--bg-tertiary)] text-[var(--text-secondary)]"}`,children:e.jsx(P,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[var(--text-primary)]",children:g(j?"settings.profiles.fields.apiKey":"settings.profiles.fields.adminKey")}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:g(l?"settings.profiles.status.hasApiKey":"settings.profiles.status.noApiKey")})]})]}),l&&!b&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)]",children:[e.jsx(t.CheckCircle,{className:"w-3 h-3"}),g("settings.profiles.status.active")]})]}),e.jsxs("div",{className:"px-4 py-3 bg-[var(--bg-primary)]",children:[d&&e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-xs text-[var(--color-accent-600)] hover:text-[var(--color-accent-700)] mb-3 transition-colors",children:[e.jsx(t.ExternalLink,{className:"w-3 h-3"}),g("settings.profiles.fields.getKeyFromProvider")]}),b?e.jsx(Re,{showValue:T,onShowValueChange:L,value:y,onValueChange:x,placeholder:a,saving:p,onCancel:A,onSave:u,hasKey:l,isApi:j,t:g}):e.jsx(Ke,{hasKey:l,onEdit:()=>f(!0),isApi:j,t:g})]})]})}function Oe({budget:s,usage:l,isOver:i,t:a,budgetPeriodType:d,nextResetDate:g}){if(s==null)return e.jsxs("div",{className:"flex-1 p-6 bg-[var(--bg-primary)] flex flex-col items-center justify-center",children:[e.jsx(t.DollarSign,{className:"w-10 h-10 text-[var(--text-tertiary)] opacity-30 mb-2"}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] italic",children:a("common:notSet","—")})]});const b=50,f=2*Math.PI*b,y=Math.min(100,l/s*100),x=f-f*y/100,p=i?"var(--error-dot)":y>80?"var(--warning-dot)":"var(--success-dot)";return e.jsxs("div",{className:"flex-1 p-4 bg-[var(--bg-primary)] flex flex-col items-center justify-center",children:[e.jsxs("div",{className:"relative",style:{width:120,height:120},children:[e.jsxs("svg",{viewBox:"0 0 120 120",className:"w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"60",cy:"60",r:b,fill:"none",stroke:"var(--bg-tertiary)",strokeWidth:"9",strokeLinecap:"round"}),e.jsx("circle",{cx:"60",cy:"60",r:b,fill:"none",stroke:p,strokeWidth:"9",strokeLinecap:"round",strokeDasharray:f,strokeDashoffset:x,className:"transition-all duration-700 ease-out"})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsxs("span",{className:`text-xl font-bold ${i?"text-[var(--error-text)]":"text-[var(--text-primary)]"}`,children:[Math.round(y),"%"]}),e.jsx("span",{className:"text-[10px] text-[var(--text-secondary)] uppercase tracking-wider",children:a("settings.profiles.usage.used","used")})]})]}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.currentPeriod")}),e.jsx("span",{className:`font-semibold ${i?"text-[var(--error-text)]":"text-[var(--text-primary)]"}`,children:ie(l)})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.fields.budgetLimit")}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:ie(s)})]}),e.jsx("div",{className:"h-px bg-[var(--border-color)]"}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.remaining","Remaining")}),e.jsxs("span",{className:`font-semibold ${i?"text-[var(--error-text)]":"text-[var(--success-text)]"}`,children:[i?"- ":"",ie(Math.abs(s-l))]})]}),d&&d!=="Fixed"&&g?e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.nextReset")}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:new Date(g).toLocaleDateString()})]}):d==="Fixed"||!d?e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.nextReset")}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:a("settings.profiles.usage.noAutoReset")})]}):null]})]})}function Re({showValue:s,onShowValueChange:l,value:i,onValueChange:a,placeholder:d,saving:g,onCancel:b,onSave:f,hasKey:y,isApi:x,t:p}){return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:s?"text":"password",value:i,onChange:k=>a(k.target.value),placeholder:d,className:"input w-full pr-10 font-mono text-sm",autoFocus:!0,onKeyDown:k=>{k.key==="Enter"&&i.trim()&&f(),k.key==="Escape"&&b()}}),e.jsx("button",{type:"button",onClick:()=>l(!s),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 rounded-md text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)] transition-colors",tabIndex:-1,children:s?e.jsx(t.EyeOff,{className:"w-4 h-4"}):e.jsx(t.Eye,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:b,disabled:g,className:"btn btn-ghost btn-sm",children:p("common:cancel")}),e.jsxs("button",{onClick:f,disabled:!i.trim()||g,className:"btn btn-primary btn-sm disabled:opacity-50 disabled:cursor-not-allowed",children:[g&&e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}),p(y?"settings.profiles.actions.changeKey":"common:save")]})]})]})}function Ke({hasKey:s,onEdit:l,isApi:i,t:a}){return e.jsx("button",{onClick:l,className:"w-full group flex items-center justify-between py-1 text-left",children:s?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-sm text-[var(--text-tertiary)] tracking-widest",children:"•".repeat(24)}),e.jsx("span",{className:"text-xs font-medium text-[var(--color-accent-600)] group-hover:text-[var(--color-accent-700)] transition-colors",children:a("settings.profiles.actions.changeKey")})]}):e.jsxs("span",{className:"flex items-center gap-2 text-sm text-[var(--text-secondary)] group-hover:text-[var(--color-accent-600)] transition-colors",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),a(i?"settings.profiles.actions.setApiKey":"settings.profiles.actions.setAdminKey")]})})}function qe({instance:s,isSelected:l,onSelect:i,t:a}){return e.jsxs("button",{onClick:()=>i(s.id),className:`w-full text-left p-4 rounded-lg border transition-all ${l?"border-[var(--color-accent-500)] bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 shadow-sm":"border-[var(--border-color)] bg-[var(--bg-primary)] hover:border-[var(--color-accent-300)] hover:shadow-sm"}`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(we,{logoUrl:s.providerLogoUrl,providerCode:s.providerCode,size:"sm"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:s.name}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:s.providerName})]})]}),e.jsx(Be,{isActive:s.isActive,isOverBudget:s.isOverBudget,t:a})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-xs text-[var(--text-secondary)]",children:[s.department&&e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--bg-secondary)] px-2 py-1 rounded",children:[e.jsx(t.Building2,{className:"w-3 h-3"}),s.department]}),s.hasApiKey&&e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--success-bg)] text-[var(--success-text)] px-2 py-1 rounded",children:[e.jsx(t.Key,{className:"w-3 h-3"}),"API"]}),s.isAllTenants?e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--success-bg)] text-[var(--success-text)] px-2 py-1 rounded",children:[e.jsx(t.Globe,{className:"w-3 h-3"}),a("settings.profiles.allTenants")]}):e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--bg-secondary)] px-2 py-1 rounded",children:[e.jsx(t.Building2,{className:"w-3 h-3"}),a("settings.profiles.tenantCount",{count:s.tenantCount})]})]}),s.budgetLimit&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.budget")}),e.jsxs("span",{className:s.isOverBudget?"text-[var(--error-text)]":"",children:[ie(s.currentPeriodUsage)," / ",ie(s.budgetLimit)]})]}),e.jsx("div",{className:"h-1.5 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${s.isOverBudget?"bg-[var(--error-dot)]":"bg-[var(--color-accent-500)]"}`,style:{width:`${Math.min(100,s.currentPeriodUsage/s.budgetLimit*100)}%`}})})]})]})}function ue({placeholder:s,onSearch:l,onSelect:i,onClose:a}){const[d,g]=r.useState(""),[b,f]=r.useState([]),[y,x]=r.useState(!1),[p,k]=r.useState(null);r.useEffect(()=>{if(d.length<2){f([]);return}const L=setTimeout(async()=>{x(!0);try{const j=await l(d);f(j)}catch{f([])}finally{x(!1)}},300);return()=>clearTimeout(L)},[d,l]);const T=async L=>{k(L);try{await i(L),a()}catch{}finally{k(null)}};return e.jsxs("div",{className:"p-3 border-t border-[var(--border-color)] bg-[var(--bg-primary)]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(t.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("input",{type:"text",value:d,onChange:L=>g(L.target.value),placeholder:s,className:"w-full pl-9 pr-8 py-2 text-sm border border-[var(--border-color)] bg-[var(--bg-card)] text-[var(--text-primary)] rounded-[var(--radius-input)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",autoFocus:!0}),e.jsx("button",{onClick:a,className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(t.X,{className:"w-4 h-4"})})]}),y&&e.jsx("div",{className:"flex items-center justify-center py-3",children:e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin text-[var(--color-accent-500)]"})}),!y&&b.length>0&&e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto space-y-1",children:b.map(L=>e.jsxs("button",{onClick:()=>T(L.id),disabled:p===L.id,className:"w-full flex items-center gap-2.5 p-2 rounded-md text-left hover:bg-[var(--bg-hover)] transition-colors disabled:opacity-50",children:[L.icon||e.jsx("div",{className:"w-7 h-7 rounded-md bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] flex items-center justify-center flex-shrink-0",children:e.jsx(t.Building2,{className:"w-3.5 h-3.5 text-[var(--color-accent-600)]"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--text-primary)] truncate",children:L.label}),L.sublabel&&e.jsx("div",{className:"text-xs text-[var(--text-secondary)] truncate",children:L.sublabel})]}),p===L.id&&e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin text-[var(--color-accent-500)]"})]},L.id))}),!y&&d.length>=2&&b.length===0&&e.jsx("p",{className:"text-xs text-[var(--text-secondary)] text-center py-3",children:d.length>=2?"No results found":""})]})}function Ve({instances:s,selectedInstance:l,onSelectInstance:i,onToggleActive:a,onDelete:d,onUpdate:g,models:b,onSetApiKey:f,onSetAdminKey:y,providerApiKeyUrl:x,providerAdminApiKeyUrl:p,onAddTenant:k,onRemoveTenant:T,onSetAllTenants:L,onAddPrompt:j,onRemovePrompt:P}){const{t:u}=Y.useTranslation("ai"),[A,F]=r.useState(!1),[h,c]=r.useState({name:""}),[n,N]=r.useState(!1),[o,_]=r.useState(!1),[C,v]=r.useState(!1),[O,W]=r.useState(!1),m=r.useCallback(()=>{l&&(c({name:l.name,description:l.description||"",systemContext:l.systemContext||"",department:l.department||"",costCenter:l.costCenter||"",defaultModel:l.defaultModel||"",maxTokensPerRequest:l.maxTokensPerRequest||void 0,budgetLimit:l.budgetLimit||void 0,budgetPeriodType:l.budgetPeriodType||void 0,budgetPeriodStart:l.budgetPeriodStart||void 0}),F(!0))},[l]),D=r.useCallback(()=>{F(!1),c({name:""})},[]),K=r.useCallback(async()=>{if(h.name.trim()){N(!0);try{await g(h),F(!1)}catch{}finally{N(!1)}}},[h,g]),w=r.useCallback(async M=>{const S=await J.adminApi.tenants.getAll({search:M,pageSize:10}),I=new Set(l?.tenants?.map(R=>R.tenantId)||[]);return S.items.filter(R=>!I.has(R.id)).map(R=>({id:R.id,label:R.name,sublabel:R.slug||void 0}))},[l]),q=r.useCallback(async M=>{const{aiApi:S}=await Promise.resolve().then(()=>require("./aiApi-CsH8DXgs.js")),I=await S.skills.getAll(),R=new Set(l?.skills?.map(V=>V.skillId)||[]);return I.filter(V=>!R.has(V.id)&&(V.name.toLowerCase().includes(M.toLowerCase())||V.code.toLowerCase().includes(M.toLowerCase()))).slice(0,10).map(V=>({id:V.id,label:V.name,sublabel:`${V.code} (v${V.version})`}))},[l]);r.useEffect(()=>{F(!1)},[l?.id]);const B=r.useCallback(async()=>{if(l){W(!0);try{await L(!l.isAllTenants)}catch{}finally{W(!1)}}},[l,L]);return s.length===0?e.jsx($e,{t:u}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"lg:col-span-1 space-y-3",children:s.map(M=>e.jsx(qe,{instance:M,isSelected:l?.id===M.id,onSelect:i,t:u},M.id))}),e.jsx("div",{className:"lg:col-span-2",children:l?e.jsxs("div",{className:"card p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(we,{logoUrl:l.providerLogoUrl,providerCode:l.providerCode,size:"lg"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-semibold",children:A?u("settings.profiles.editTitle"):l.name}),e.jsxs("p",{className:"text-sm text-[var(--text-secondary)]",children:[l.providerName," -"," ",e.jsx("code",{className:"text-xs",children:l.code})]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:A?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:D,disabled:n,className:"btn btn-secondary btn-sm",children:[e.jsx(t.X,{className:"w-4 h-4"}),u("common:cancel")]}),e.jsxs("button",{onClick:K,disabled:!h.name.trim()||n,className:"btn btn-primary btn-sm disabled:opacity-50 disabled:cursor-not-allowed",children:[n?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsx(t.Save,{className:"w-4 h-4"}),u("common:save")]})]}):e.jsxs(e.Fragment,{children:[l.providerDocumentationUrl&&e.jsxs("a",{href:l.providerDocumentationUrl,target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm",children:[e.jsx(t.BookOpen,{className:"w-4 h-4"}),u("settings.profiles.metadata.docs")]}),e.jsxs("button",{onClick:m,className:"btn btn-secondary btn-sm",children:[e.jsx(t.Pencil,{className:"w-4 h-4"}),u("settings.profiles.actions.edit")]}),e.jsx("button",{onClick:()=>a(l.id),className:`btn btn-sm ${l.isActive?"btn-secondary":"btn-primary"}`,title:u("settings.profiles.actions.toggleActive"),children:l.isActive?e.jsx(t.XCircle,{className:"w-4 h-4"}):e.jsx(t.CheckCircle,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>d(l.id),className:"btn btn-sm text-[var(--error-text)] hover:bg-[var(--error-bg)]",title:u("settings.profiles.actions.delete"),children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})})]}),A?e.jsxs("div",{className:"space-y-4 bg-[var(--bg-secondary)] rounded-lg p-5 border border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.name")}),e.jsx("input",{type:"text",value:h.name,onChange:M=>c({...h,name:M.target.value}),placeholder:u("settings.profiles.fields.namePlaceholder"),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.description")}),e.jsx("input",{type:"text",value:h.description||"",onChange:M=>c({...h,description:M.target.value||void 0}),placeholder:u("settings.profiles.fields.descriptionPlaceholder"),className:"input w-full"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.department")}),e.jsx("input",{type:"text",value:h.department||"",onChange:M=>c({...h,department:M.target.value||void 0}),placeholder:u("settings.profiles.fields.departmentPlaceholder"),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.costCenter")}),e.jsx("input",{type:"text",value:h.costCenter||"",onChange:M=>c({...h,costCenter:M.target.value||void 0}),placeholder:u("settings.profiles.fields.costCenterPlaceholder"),className:"input w-full"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.defaultModel")}),e.jsx("p",{className:"text-xs text-[var(--text-muted)] mb-2",children:u("settings.profiles.fields.modelFamilyDescription")}),(()=>{const M=b.filter(U=>U.providerId===l.providerId&&U.modelFamily),S=new Map;M.forEach(U=>{const H=U.modelFamily;S.has(H)||S.set(H,[]),S.get(H).push(U)}),S.forEach(U=>U.sort((H,Q)=>{const $=H.deprecationDate?new Date(H.deprecationDate).getTime():0;return(Q.deprecationDate?new Date(Q.deprecationDate).getTime():0)-$||(H.inputCostPerMillionTokens>Q.inputCostPerMillionTokens?-1:1)}));const I=h.defaultModel??"",R=S.has(I),V=!R&&!!I;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("select",{value:R?I:V?"__pinned__":"",onChange:U=>{const H=U.target.value;H!=="__pinned__"&&c({...h,defaultModel:H||void 0})},className:"input w-full",children:[e.jsx("option",{value:"",children:u("settings.profiles.fields.defaultModelPlaceholder")}),Array.from(S.entries()).map(([U,H])=>{const Q=H[0],$=Math.min(...H.map(X=>X.inputCostPerMillionTokens)),z=Math.max(...H.map(X=>X.outputCostPerMillionTokens));return e.jsxs("option",{value:U,children:[U.charAt(0).toUpperCase()+U.slice(1)," — ",u("settings.profiles.fields.latestVersion",{modelName:Q.name})," ($",$,"/$",z," ",u("settings.models.perMillionTokens"),") — ",u("settings.profiles.fields.familyModels",{count:H.length})]},U)}),V&&e.jsxs("option",{value:"__pinned__",disabled:!0,children:["✦ ",u("settings.profiles.fields.pinVersion"),": ",b.find(U=>U.code===I)?.name??I]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{type:"button",onClick:()=>{if(V){const H=b.find(Q=>Q.code===I)?.modelFamily;c({...h,defaultModel:H||void 0})}else if(R){const U=S.get(I);U&&U.length>0&&c({...h,defaultModel:U[0].code})}},className:`flex items-center gap-1.5 text-xs px-2 py-1 rounded transition-colors ${V?"bg-[var(--warning-bg)] text-[var(--warning-text)] border border-[var(--warning-border)]":"bg-[var(--bg-secondary)] text-[var(--text-muted)] border border-[var(--border-color)] hover:border-[var(--text-muted)]"}`,disabled:!I,children:[V?e.jsx(t.Pin,{className:"w-3 h-3"}):e.jsx(t.PinOff,{className:"w-3 h-3"}),V?u("settings.profiles.fields.pinVersion"):u("settings.profiles.fields.latestVersion",{modelName:""}).replace(": ","")]})}),V&&e.jsx("select",{value:I,onChange:U=>c({...h,defaultModel:U.target.value||void 0}),className:"input w-full",children:b.filter(U=>U.providerId===l.providerId).map(U=>e.jsxs("option",{value:U.code,children:[U.name," ",U.modelFamily?`(${U.modelFamily})`:""]},U.id))})]})})()]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.maxTokensPerRequest")}),e.jsx("input",{type:"number",value:h.maxTokensPerRequest??"",onChange:M=>c({...h,maxTokensPerRequest:M.target.value?Number(M.target.value):void 0}),placeholder:u("settings.profiles.fields.maxTokensPerRequestPlaceholder","e.g. 4096"),className:"input w-full",min:0})]})]}),e.jsxs("div",{className:"md:w-1/2",children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.budgetLimit")}),e.jsx("input",{type:"number",value:h.budgetLimit??"",onChange:M=>c({...h,budgetLimit:M.target.value?Number(M.target.value):void 0}),placeholder:u("settings.profiles.fields.budgetLimitPlaceholder","e.g. 100.00"),className:"input w-full",min:0,step:.01})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.budgetPeriodType")}),e.jsxs("select",{value:h.budgetPeriodType||"",onChange:M=>c({...h,budgetPeriodType:M.target.value||void 0}),className:"input w-full",children:[e.jsx("option",{value:"",children:"Select period type"}),e.jsx("option",{value:"Monthly",children:"Monthly"}),e.jsx("option",{value:"Quarterly",children:"Quarterly"}),e.jsx("option",{value:"Annual",children:"Annual"}),e.jsx("option",{value:"Fixed",children:"Fixed"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.budgetPeriodStart")}),e.jsx("input",{type:"date",value:h.budgetPeriodStart||"",onChange:M=>c({...h,budgetPeriodStart:M.target.value||void 0}),className:"input w-full"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.systemContext")}),e.jsx("textarea",{value:h.systemContext||"",onChange:M=>c({...h,systemContext:M.target.value||void 0}),placeholder:u("settings.profiles.fields.systemContextPlaceholder","Enter system instructions..."),className:"input w-full font-mono text-sm min-h-[120px] resize-y",rows:5})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[var(--text-secondary)]",children:l.description||e.jsx("span",{className:"italic",children:u("common:notSet","—")})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-5 gap-4",children:[e.jsxs("div",{className:"lg:col-span-3 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--text-secondary)] mb-1",children:[e.jsx(t.Building2,{className:"w-3 h-3"}),u("settings.profiles.fields.department")]}),e.jsx("div",{className:"font-medium",children:l.department||e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--text-secondary)] mb-1",children:[e.jsx(t.DollarSign,{className:"w-3 h-3"}),u("settings.profiles.fields.costCenter")]}),e.jsx("div",{className:"font-medium",children:l.costCenter||e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mb-1",children:u("settings.profiles.fields.defaultModel")}),e.jsx("div",{className:"font-medium font-mono text-sm",children:l.defaultModel||e.jsx("span",{className:"text-[var(--text-tertiary)] font-sans",children:"—"})})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mb-1",children:u("settings.profiles.fields.maxTokensPerRequest")}),e.jsx("div",{className:"font-medium",children:l.maxTokensPerRequest?l.maxTokensPerRequest.toLocaleString():e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})})]})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsx("h4",{className:"font-medium mb-1.5 text-sm",children:u("settings.profiles.fields.systemContext")}),l.systemContext?e.jsx("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg text-sm font-mono whitespace-pre-wrap overflow-y-auto flex-1",children:l.systemContext}):e.jsx("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg text-sm text-[var(--text-tertiary)] italic flex-1 flex items-center justify-center",children:"—"})]})]}),e.jsxs("div",{className:`lg:col-span-2 rounded-[var(--radius-card)] border overflow-hidden flex flex-col ${l.isOverBudget?"border-[var(--error-border)]":"border-[var(--border-color)]"}`,children:[e.jsxs("div",{className:`px-4 py-2.5 flex items-center gap-2 text-sm font-medium ${l.isOverBudget?"bg-[var(--error-bg)] text-[var(--error-text)]":"bg-[var(--bg-secondary)] text-[var(--text-primary)]"}`,children:[e.jsx(t.DollarSign,{className:"w-4 h-4"}),u("settings.profiles.usage.budget"),l.isOverBudget&&e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-xs font-medium",children:[e.jsx(t.AlertCircle,{className:"w-3.5 h-3.5"}),u("settings.profiles.usage.overBudget")]})]}),e.jsx(Oe,{budget:l.budgetLimit,usage:l.currentPeriodUsage,isOver:l.isOverBudget,t:u,budgetPeriodType:l.budgetPeriodType,nextResetDate:l.nextResetDate})]})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"font-medium mb-3 flex items-center gap-2",children:[e.jsx(t.Key,{className:"w-4 h-4"}),u("settings.profiles.fields.apiKeys")]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(he,{type:"api",hasKey:l.hasApiKey,onSave:f,placeholder:u("settings.profiles.fields.apiKeyPlaceholder"),providerKeyUrl:x,t:u}),e.jsx(he,{type:"admin",hasKey:l.hasAdminKey,onSave:y,placeholder:u("settings.profiles.fields.adminKeyPlaceholder"),providerKeyUrl:p,t:u})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[e.jsx(t.Building2,{className:"w-4 h-4 text-[var(--color-accent-500)]"}),u("settings.profiles.tenantAccess")]})}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)]",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[var(--text-primary)]",children:u("settings.profiles.allTenants")}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)] mt-0.5",children:u("settings.profiles.allTenantsDescription")})]}),e.jsxs("button",{onClick:B,disabled:O,className:"flex-shrink-0 transition-colors",title:u("settings.profiles.allTenants"),children:[O&&e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-500)]"}),!O&&l.isAllTenants&&e.jsx(t.ToggleRight,{className:"w-10 h-10 text-[var(--success-dot)]"}),!O&&!l.isAllTenants&&e.jsx(t.ToggleLeft,{className:"w-10 h-10 text-[var(--text-tertiary)]"})]})]}),!l.isAllTenants&&e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-[var(--radius-card)] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-[var(--bg-tertiary)]",children:[e.jsxs("h5",{className:"text-sm font-medium text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Building2,{className:"w-4 h-4 text-[var(--color-accent-500)]"}),u("settings.profiles.tenantCount",{count:l.tenants?.length??0})]}),e.jsx("button",{onClick:()=>_(!o),className:"p-1.5 rounded-md hover:bg-[var(--bg-primary)] text-[var(--color-accent-500)] transition-colors",title:u("settings.profiles.addTenant"),children:e.jsx(t.Plus,{className:"w-4 h-4"})})]}),o&&e.jsx(ue,{placeholder:u("settings.profiles.addTenant"),onSearch:w,onSelect:async M=>{await k(M)},onClose:()=>_(!1)}),e.jsx("div",{className:"p-3",children:(l.tenants?.length??0)>0?e.jsx("div",{className:"space-y-2",children:l.tenants.map(M=>e.jsxs("div",{className:"group flex items-center gap-3 p-2.5 rounded-lg bg-[var(--bg-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] flex items-center justify-center flex-shrink-0",children:e.jsx(t.Building2,{className:"w-4 h-4 text-[var(--color-accent-600)]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:M.tenantName}),M.tenantSlug&&e.jsx("div",{className:"text-xs text-[var(--text-secondary)] truncate",children:M.tenantSlug})]}),e.jsx("button",{onClick:()=>T(M.tenantId),className:"p-1.5 rounded-md text-[var(--text-secondary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] opacity-0 group-hover:opacity-100 transition-all",title:u("settings.profiles.removeTenant"),children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]},M.id))}):e.jsxs("div",{className:"text-center py-4",children:[e.jsx(t.Building2,{className:"w-7 h-7 mx-auto text-[var(--text-tertiary)] mb-1.5"}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:u("settings.profiles.noTenants")})]})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[e.jsx(t.BookOpen,{className:"w-4 h-4 text-[var(--color-accent-500)]"}),u("settings.profiles.prompts.title")]}),e.jsx("button",{onClick:()=>v(!C),className:"p-1.5 rounded-md hover:bg-[var(--bg-tertiary)] text-[var(--color-accent-500)] transition-colors",title:u("settings.profiles.prompts.addPrompt"),children:e.jsx(t.Plus,{className:"w-4 h-4"})})]}),C&&e.jsx(ue,{placeholder:u("settings.profiles.prompts.addPrompt"),onSearch:q,onSelect:async M=>{await j(M)},onClose:()=>v(!1)}),e.jsx("div",{className:"bg-[var(--bg-secondary)] rounded-lg overflow-hidden",children:e.jsx("div",{className:"p-3 min-h-[100px]",children:l?.skills&&l.skills.length>0?e.jsx("div",{className:"space-y-2",children:l.skills.map(M=>e.jsxs("div",{className:"group flex items-center gap-3 p-2.5 rounded-lg bg-[var(--bg-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] flex items-center justify-center flex-shrink-0",children:e.jsx(t.BookOpen,{className:"w-4 h-4 text-[var(--color-accent-600)]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:M.skillName}),e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] truncate",children:[M.skillCode," ",e.jsxs("span",{className:"text-xs opacity-75",children:["v",M.skillVersion]})]})]}),e.jsx("span",{className:"text-xs px-2 py-1 rounded bg-[var(--bg-secondary)] text-[var(--text-secondary)] whitespace-nowrap",children:M.skillStatus}),e.jsx("button",{onClick:()=>P(M.skillId),className:"p-1.5 rounded-md text-[var(--text-secondary)] hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 opacity-0 group-hover:opacity-100 transition-all",children:e.jsx(t.Trash2,{className:"w-3.5 h-3.5"})})]},M.id))}):e.jsx("p",{className:"text-sm text-[var(--text-secondary)] text-center py-6",children:u("settings.profiles.prompts.noPrompts")})})})]}),e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] flex items-center gap-4 pt-4 border-t border-[var(--border-color)]",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(t.Clock,{className:"w-3 h-3"}),u("settings.profiles.metadata.created"),": ",new Date(l.createdAt).toLocaleDateString(),l.createdBy&&` ${u("settings.profiles.metadata.by")} ${l.createdBy}`]}),l.updatedAt&&e.jsxs("span",{children:[u("settings.profiles.metadata.updated"),":"," ",new Date(l.updatedAt).toLocaleDateString(),l.updatedBy&&` ${u("settings.profiles.metadata.by")} ${l.updatedBy}`]})]})]}):e.jsx(Le,{t:u})})]})}function Ue({providers:s}){const{t:l}=Y.useTranslation("ai");return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-[var(--text-secondary)]",children:l("settings.providers.subtitle")}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:s.map(i=>e.jsx(J.ProviderCard,{name:i.name,code:i.code,description:i.description||"",modelCount:i.modelCount,color:"var(--color-accent-500)",websiteUrl:i.websiteUrl??void 0,docsUrl:i.documentationUrl??void 0,apiKeyUrl:i.apiKeyUrl??void 0,adminApiKeyUrl:i.adminApiKeyUrl??void 0,hasAdminKey:i.supportsAdminApi,badgeIcon:i.supportsAdminApi?t.Shield:void 0,badgeTooltip:i.supportsAdminApi?l("settings.providers.adminApiSupported"):void 0,labels:{websiteLabel:l("settings.providers.officialSite"),docsLabel:l("settings.providers.apiDocumentation"),apiKeyLabel:l("settings.providers.getApiKey"),adminApiKeyLabel:l("settings.providers.getAdminApiKey"),modelsLabel:l("settings.providers.models")}},i.id))})]})}const ne=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(s),ce=[{key:"supportsVision",icon:t.Eye,color:"text-blue-700 dark:text-blue-400",bgLight:"bg-blue-100",bgDark:"dark:bg-blue-900/30"},{key:"supportsImageGeneration",icon:t.ImagePlus,color:"text-pink-700 dark:text-pink-400",bgLight:"bg-pink-100",bgDark:"dark:bg-pink-900/30"},{key:"supportsAudioInput",icon:t.Mic,color:"text-amber-700 dark:text-amber-400",bgLight:"bg-amber-100",bgDark:"dark:bg-amber-900/30"},{key:"supportsAudioOutput",icon:t.Volume2,color:"text-orange-700 dark:text-orange-400",bgLight:"bg-orange-100",bgDark:"dark:bg-orange-900/30"},{key:"supportsFunctionCalling",icon:t.Zap,color:"text-purple-700 dark:text-purple-400",bgLight:"bg-purple-100",bgDark:"dark:bg-purple-900/30"},{key:"supportsStreaming",icon:t.Radio,color:"text-green-700 dark:text-green-400",bgLight:"bg-green-100",bgDark:"dark:bg-green-900/30"},{key:"supportsCodeExecution",icon:t.Terminal,color:"text-cyan-700 dark:text-cyan-400",bgLight:"bg-cyan-100",bgDark:"dark:bg-cyan-900/30"}],pe=s=>s?.charAt(0).toUpperCase()||"M",ze=(s,l)=>s.isDeprecated?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 rounded text-xs",children:[e.jsx(t.AlertOctagon,{className:"w-3 h-3"}),l("settings.models.deprecated")]}):s.isActive?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded text-xs",children:[e.jsx(t.CheckCircle,{className:"w-3 h-3"}),l("settings.models.statusActive")]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-gray-100 dark:bg-gray-900/30 text-gray-700 dark:text-gray-400 rounded text-xs",children:[e.jsx(t.XCircle,{className:"w-3 h-3"}),l("settings.models.statusInactive")]});function Ge({models:s,providers:l,filter:i,onFilterChange:a}){const{t:d}=Y.useTranslation("ai"),g=["TextGeneration","Embedding","ImageGeneration","AudioGeneration","VideoGeneration"],[b,f]=r.useState(1),[y,x]=r.useState("grid"),[p,k]=r.useState(new Set),[T,L]=r.useState("or"),j=y==="grid"?12:10,P=s.filter(c=>{if(p.size===0)return!0;const n=Array.from(p);return T==="or"?n.some(N=>c[N]):n.every(N=>c[N])}),u=Math.ceil(P.length/j),A=P.slice((b-1)*j,b*j);r.useEffect(()=>{f(1)},[i,p,T,y]);const F=c=>{k(n=>{const N=new Set(n);return N.has(c)?N.delete(c):N.add(c),N})},h=()=>{k(new Set)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-[var(--text-secondary)]",children:d("settings.models.subtitle")}),e.jsxs("div",{className:"flex items-center gap-1 p-1 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("button",{onClick:()=>x("grid"),className:`p-2 rounded transition-colors ${y==="grid"?"bg-[var(--bg-primary)] shadow-sm":"hover:bg-[var(--bg-tertiary)]"}`,title:d("settings.models.viewGrid"),children:e.jsx(t.LayoutGrid,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>x("table"),className:`p-2 rounded transition-colors ${y==="table"?"bg-[var(--bg-primary)] shadow-sm":"hover:bg-[var(--bg-tertiary)]"}`,title:d("settings.models.viewTable"),children:e.jsx(t.List,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("settings.models.category")}),e.jsxs("select",{value:i.category||"",onChange:c=>a({...i,category:c.target.value||void 0}),className:"input min-w-[150px]",children:[e.jsx("option",{value:"",children:d("prompts.allCategories")}),g.map(c=>e.jsx("option",{value:c,children:d(`settings.models.categories.${c}`)},c))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("settings.profiles.fields.provider")}),e.jsxs("select",{value:i.providerId||"",onChange:c=>a({...i,providerId:c.target.value||void 0}),className:"input min-w-[150px]",children:[e.jsx("option",{value:"",children:d("dashboard.allProviders")}),l.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]})]}),e.jsxs("div",{className:"card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Filter,{className:"w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("span",{className:"text-sm font-medium",children:d("settings.models.filterByCapabilities")}),p.size>0&&e.jsx("span",{className:"px-2 py-0.5 bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] text-[var(--color-accent-600)] text-xs rounded-full",children:p.size})]}),e.jsx("div",{className:"flex items-center gap-2",children:p.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 p-1 bg-[var(--bg-secondary)] rounded-lg text-xs",children:[e.jsx("button",{onClick:()=>L("or"),className:`px-2 py-1 rounded transition-colors ${T==="or"?"bg-[var(--bg-primary)] shadow-sm font-medium":"hover:bg-[var(--bg-tertiary)]"}`,children:d("settings.models.filterOr")}),e.jsx("button",{onClick:()=>L("and"),className:`px-2 py-1 rounded transition-colors ${T==="and"?"bg-[var(--bg-primary)] shadow-sm font-medium":"hover:bg-[var(--bg-tertiary)]"}`,children:d("settings.models.filterAnd")})]}),e.jsx("button",{onClick:h,className:"text-xs text-[var(--text-secondary)] hover:text-[var(--text-primary)] underline",children:d("common:clear")})]})})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:ce.map(({key:c,icon:n,color:N,bgLight:o,bgDark:_})=>{const C=p.has(c);return e.jsxs("button",{onClick:()=>F(c),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-medium transition-all ${o} ${_} ${N} ${C?"ring-2 ring-offset-1 ring-current shadow-sm":"opacity-60 hover:opacity-100"}`,children:[e.jsx(n,{className:"w-3.5 h-3.5"}),d(`settings.models.${c}`)]},c)})}),p.size>0&&e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:T==="or"?d("settings.models.filterOrDescription",{count:P.length}):d("settings.models.filterAndDescription",{count:P.length})})]}),P.length===0&&e.jsxs("div",{className:"card p-12 text-center",children:[e.jsx(t.Cpu,{className:"w-16 h-16 mx-auto mb-4 text-[var(--text-secondary)] opacity-50"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:d("settings.models.noModels")}),p.size>0&&e.jsx("button",{onClick:h,className:"btn btn-secondary mt-2",children:d("settings.models.clearFilters")})]}),P.length>0&&y==="grid"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:A.map(c=>e.jsxs("div",{className:`bg-[var(--bg-card)] border-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)] rounded-[var(--radius-card)] overflow-hidden transition-all hover:shadow-lg hover:-translate-y-0.5 hover:border-[var(--color-accent-400)] ${c.isDeprecated?"opacity-60":""}`,children:[e.jsx("div",{className:"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 p-4 border-b-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-[var(--color-accent-500)] rounded-lg flex items-center justify-center text-white font-bold shadow-lg",children:pe(c.providerCode)}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--text-primary)]",children:c.name}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:c.providerName})]})]}),c.isDeprecated&&e.jsx("span",{className:"px-2 py-0.5 bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 rounded text-xs flex items-center gap-1",children:e.jsx(t.AlertOctagon,{className:"w-3 h-3"})})]})}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"px-2 py-1 bg-[var(--bg-secondary)] rounded text-xs font-medium",children:d(`settings.models.categories.${c.category}`)}),e.jsx("code",{className:"text-xs text-[var(--text-tertiary)] font-mono",children:c.code})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-lg p-3 text-center",children:[e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] mb-1 flex items-center justify-center gap-1",children:[e.jsx(t.ArrowDownUp,{className:"w-3 h-3"}),d("settings.models.inputCost")]}),e.jsx("div",{className:"font-mono font-bold text-lg",children:ne(c.inputCostPerMillionTokens)}),e.jsx("div",{className:"text-[10px] text-[var(--text-tertiary)]",children:d("settings.models.perMillionTokens")})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-lg p-3 text-center",children:[e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] mb-1 flex items-center justify-center gap-1",children:[e.jsx(t.ArrowUpDown,{className:"w-3 h-3"}),d("settings.models.outputCost")]}),e.jsx("div",{className:"font-mono font-bold text-lg",children:ne(c.outputCostPerMillionTokens)}),e.jsx("div",{className:"text-[10px] text-[var(--text-tertiary)]",children:d("settings.models.perMillionTokens")})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-[var(--text-secondary)] flex items-center gap-1",children:[e.jsx(t.Brain,{className:"w-4 h-4"}),d("settings.models.contextWindow")]}),e.jsx("span",{className:"font-mono font-medium",children:c.contextWindow>=1e6?`${(c.contextWindow/1e6).toFixed(1)}M`:`${(c.contextWindow/1e3).toFixed(0)}K`})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[ce.map(({key:n,icon:N,color:o,bgLight:_,bgDark:C})=>c[n]&&e.jsx("span",{className:`p-1.5 ${_} ${C} ${o} rounded-md`,title:d(`settings.models.${n}`),children:e.jsx(N,{className:"w-3.5 h-3.5"})},n)),!ce.some(({key:n})=>c[n])&&e.jsx("span",{className:"text-xs text-[var(--text-tertiary)] italic",children:d("settings.models.noCapabilities")})]})]})]},c.id))}),P.length>0&&y!=="grid"&&e.jsx("div",{className:"card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-[var(--bg-secondary)] border-b border-[var(--border-color)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-4 font-medium text-sm",children:d("settings.models.model")}),e.jsx("th",{className:"text-left p-4 font-medium text-sm",children:d("settings.models.category")}),e.jsxs("th",{className:"text-right p-4 font-medium text-sm",children:[d("settings.models.inputCost")," $/M"]}),e.jsxs("th",{className:"text-right p-4 font-medium text-sm",children:[d("settings.models.outputCost")," $/M"]}),e.jsx("th",{className:"text-right p-4 font-medium text-sm",children:d("settings.models.contextWindow")}),e.jsx("th",{className:"text-center p-4 font-medium text-sm",children:d("settings.models.capabilities")}),e.jsx("th",{className:"text-center p-4 font-medium text-sm",children:d("settings.models.status")})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border-color)]",children:A.map(c=>e.jsxs("tr",{className:`hover:bg-[var(--bg-secondary)]/50 ${c.isDeprecated?"opacity-60":""}`,children:[e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-[var(--color-accent-500)] rounded flex items-center justify-center text-xs font-bold text-white",children:pe(c.providerCode)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:c.name}),e.jsx("code",{className:"text-xs text-[var(--text-secondary)]",children:c.code})]})]})}),e.jsx("td",{className:"p-4",children:e.jsx("span",{className:"px-2 py-1 bg-[var(--bg-secondary)] rounded text-sm",children:d(`settings.models.categories.${c.category}`)})}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("span",{className:"font-mono font-medium",children:ne(c.inputCostPerMillionTokens)})}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("span",{className:"font-mono font-medium",children:ne(c.outputCostPerMillionTokens)})}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("div",{className:"font-mono text-sm",children:c.contextWindow>=1e6?`${(c.contextWindow/1e6).toFixed(1)}M`:`${(c.contextWindow/1e3).toFixed(0)}K`})}),e.jsx("td",{className:"p-4",children:e.jsx("div",{className:"flex items-center justify-center gap-1 flex-wrap",children:ce.map(({key:n,icon:N,color:o,bgLight:_,bgDark:C})=>c[n]&&e.jsx("span",{className:`p-1 ${_} ${C} ${o} rounded`,title:d(`settings.models.${n}`),children:e.jsx(N,{className:"w-3.5 h-3.5"})},n))})}),e.jsx("td",{className:"p-4 text-center",children:ze(c,d)})]},c.id))})]})})}),u>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:d("common.showingOf",{from:(b-1)*j+1,to:Math.min(b*j,P.length),total:P.length})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>f(c=>Math.max(1,c-1)),disabled:b===1,className:"btn btn-sm btn-secondary disabled:opacity-50",children:d("common.previous")}),e.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:Math.min(u,5)},(c,n)=>{let N;return u<=5||b<=3?N=n+1:b>=u-2?N=u-4+n:N=b-2+n,e.jsx("button",{onClick:()=>f(N),className:`w-8 h-8 rounded text-sm font-medium ${b===N?"bg-[var(--color-accent-500)] text-white":"hover:bg-[var(--bg-secondary)]"}`,children:N},N)})}),e.jsx("button",{onClick:()=>f(c=>Math.min(u,c+1)),disabled:b===u,className:"btn btn-sm btn-secondary disabled:opacity-50",children:d("common.next")})]})]})]})}function _e(){const[s,l]=r.useState([]),[i,a]=r.useState(null),[d,g]=r.useState(!1),[b,f]=r.useState(null),y=r.useCallback(async()=>{g(!0),f(null);try{const h=await E.aiApi.instances.getAll();l(h??[])}catch(h){const c=h instanceof Error?h.message:"Failed to load instances";f(c),console.error("Failed to load instances:",h)}finally{g(!1)}},[]),x=r.useCallback(async h=>{f(null);try{const c=await E.aiApi.instances.getById(h);a(c??null)}catch(c){const n=c instanceof Error?c.message:"Failed to load instance details";f(n),console.error("Failed to load instance details:",c)}},[]),p=r.useCallback(async()=>{i&&await x(i.id)},[i,x]),k=r.useCallback(async h=>{f(null);try{const c=await E.aiApi.instances.create(h);return await y(),c??null}catch(c){const n=c instanceof Error?c.message:"Failed to create instance";return f(n),console.error("Failed to create instance:",c),null}},[y]),T=r.useCallback(async(h,c)=>{f(null);try{const n=await E.aiApi.instances.update(h,c);return await y(),i?.id===h&&a(n??null),n??null}catch(n){const N=n instanceof Error?n.message:"Failed to update instance";return f(N),console.error("Failed to update instance:",n),null}},[y,i?.id]),L=r.useCallback(async h=>{f(null);try{await E.aiApi.instances.delete(h),await y(),i?.id===h&&a(null)}catch(c){const n=c instanceof Error?c.message:"Failed to delete instance";f(n),console.error("Failed to delete instance:",c)}},[y,i?.id]),j=r.useCallback(async h=>{f(null);try{await E.aiApi.instances.toggleActive(h),await y(),i?.id===h&&await x(h)}catch(c){const n=c instanceof Error?c.message:"Failed to toggle instance";f(n),console.error("Failed to toggle instance:",c)}},[y,i?.id,x]),P=r.useCallback(async(h,c)=>{f(null);try{const n={value:c};await E.aiApi.instances.setApiKey(h,n),i?.id===h&&await x(h)}catch(n){const N=n instanceof Error?n.message:"Failed to set API key";f(N),console.error("Failed to set API key:",n)}},[i?.id,x]),u=r.useCallback(async(h,c)=>{f(null);try{const n={value:c};await E.aiApi.instances.setAdminKey(h,n),i?.id===h&&await x(h)}catch(n){const N=n instanceof Error?n.message:"Failed to set admin key";f(N),console.error("Failed to set admin key:",n)}},[i?.id,x]),A=r.useCallback(h=>{a(h),f(null)},[]),F=r.useCallback(()=>{f(null)},[]);return{instances:s,selectedInstance:i,loading:d,error:b,loadInstances:y,loadInstanceDetail:x,refreshInstance:p,createInstance:k,updateInstance:T,deleteInstance:L,toggleInstanceActive:j,setApiKey:P,setAdminKey:u,selectInstance:A,clearError:F}}function We(){const[s,l]=r.useState([]),[i,a]=r.useState(!1),[d,g]=r.useState(null),b=r.useCallback(x=>{g(x)},[]),f=r.useCallback(async()=>{a(!0),b(null);try{const x=await E.aiApi.settings.getProviders();l(x??[])}catch(x){const p=x instanceof Error?x.message:"Failed to load providers";b(p),console.error("Failed to load providers:",x)}finally{a(!1)}},[b]),y=r.useCallback(()=>{b(null)},[b]);return{providers:s,loading:i,error:d,loadProviders:f,clearError:y}}function Xe(){const[s,l]=r.useState([]),[i,a]=r.useState({}),[d,g]=r.useState(!1),[b,f]=r.useState(null),y=r.useCallback(j=>{f(j)},[]),x=r.useCallback(async(j,P)=>{g(!0),y(null);try{const u=await E.aiApi.settings.getModels(j,P);l(u??[])}catch(u){const A=u instanceof Error?u.message:"Failed to load models";y(A),console.error("Failed to load models:",u)}finally{g(!1)}},[y]),p=r.useCallback(async j=>{a(j),await x(j.category,j.providerId)},[x]),k=r.useCallback(async()=>{a({}),await x()},[x]),T=r.useCallback(()=>{y(null)},[y]),L=r.useMemo(()=>{let j=s;return i.providerId&&(j=j.filter(P=>P.providerId===i.providerId)),i.category&&(j=j.filter(P=>P.category===i.category)),j},[s,i]);return{models:s,filteredModels:L,modelFilter:i,loading:d,error:b,loadModels:x,setModelFilter:p,clearFilters:k,clearError:T}}function Je(){const[s,l]=r.useState([]),[i,a]=r.useState(!1),d=r.useCallback(()=>a(!0),[]),g=r.useCallback(()=>a(!1),[]),b=r.useCallback(async(x,p)=>{try{await E.aiApi.instances.addTenant(x,{tenantId:p})}catch(k){throw console.error("Failed to add tenant:",k),k}},[]),f=r.useCallback(async(x,p)=>{try{await E.aiApi.instances.removeTenant(x,p),l(k=>k.filter(T=>T.tenantId!==p))}catch(k){throw console.error("Failed to remove tenant:",k),k}},[]),y=r.useCallback(x=>{x&&l(x)},[]);return{tenants:s,showAddTenantModal:i,openAddTenantModal:d,closeAddTenantModal:g,addTenant:b,removeTenant:f,loadAccessData:y}}const He=["profiles","providers","models"];function Ye(){const{t:s}=Y.useTranslation(["ai"]),{activeTab:l,setActiveTab:i}=ke.useTabNavigation("profiles",He),a=_e(),d=We(),g=Xe(),b=Je(),[f,y]=r.useState(!1),[x,p]=r.useState({name:"",code:"",providerId:""}),[k,T]=r.useState(!1),[L,j]=r.useState({show:!1,instanceId:null});r.useEffect(()=>{(async()=>await Promise.all([a.loadInstances(),d.loadProviders(),g.loadModels()]))()},[]),r.useEffect(()=>{if(a.selectedInstance){const{tenants:o}=a.selectedInstance;b.loadAccessData(o)}},[a.selectedInstance]);const P=async o=>{await a.loadInstanceDetail(o)},u=o=>{j({show:!0,instanceId:o})},A=async()=>{L.instanceId&&(await a.deleteInstance(L.instanceId),j({show:!1,instanceId:null}))},F=async o=>{await a.toggleInstanceActive(o)},h=async()=>{try{await a.createInstance(x)&&(y(!1),p({name:"",code:"",providerId:""}))}catch(o){console.error("Failed to create instance:",o)}},c=async o=>{a.selectedInstance&&await a.updateInstance(a.selectedInstance.id,o)},n=async()=>{if(x.providerId){T(!0);try{const o=await E.aiApi.instances.generateCode(x.providerId);p({...x,code:o.code})}catch(o){console.error("Failed to generate code:",o)}finally{T(!1)}}};return(a.loading||d.loading||g.loading)&&!a.instances.length?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-600)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("settings.title","Settings")}]}),a.error&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:a.error})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Settings,{className:"w-6 h-6"}),s("settings.title")]}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] mt-1",children:s("settings.description")})]})}),l==="profiles"&&e.jsxs("button",{onClick:()=>{p({name:"",code:"",providerId:""}),y(!0)},className:"btn btn-primary",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("settings.profiles.createButton")]})]}),e.jsx("div",{className:"border-b border-[var(--border-color)]",children:e.jsx("div",{className:"flex gap-8",children:["profiles","providers","models"].map(o=>e.jsx("button",{onClick:()=>i(o),className:`pb-4 px-1 border-b-2 transition-colors ${l===o?"border-[var(--color-accent-600)] text-[var(--text-primary)] font-medium":"border-transparent text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,children:s(`settings.tabs.${o}`)},o))})}),e.jsxs("div",{children:[l==="profiles"&&e.jsx(Ve,{instances:a.instances,selectedInstance:a.selectedInstance,onSelectInstance:P,onToggleActive:F,onDelete:u,onUpdate:c,models:g.models,onSetApiKey:async o=>{a.selectedInstance&&await a.setApiKey(a.selectedInstance.id,o)},onSetAdminKey:async o=>{a.selectedInstance&&await a.setAdminKey(a.selectedInstance.id,o)},providerApiKeyUrl:d.providers.find(o=>o.id===a.selectedInstance?.providerId)?.apiKeyUrl,providerAdminApiKeyUrl:d.providers.find(o=>o.id===a.selectedInstance?.providerId)?.adminApiKeyUrl,onAddTenant:async o=>{a.selectedInstance&&(await b.addTenant(a.selectedInstance.id,o),await a.loadInstanceDetail(a.selectedInstance.id))},onRemoveTenant:async o=>{a.selectedInstance&&(await b.removeTenant(a.selectedInstance.id,o),await a.loadInstanceDetail(a.selectedInstance.id))},onSetAllTenants:async o=>{a.selectedInstance&&(await E.aiApi.instances.setAllTenants(a.selectedInstance.id,{isAllTenants:o}),await a.loadInstanceDetail(a.selectedInstance.id))},onAddPrompt:async o=>{a.selectedInstance&&(await E.aiApi.instances.addSkill(a.selectedInstance.id,{skillId:o}),await a.loadInstanceDetail(a.selectedInstance.id))},onRemovePrompt:async o=>{a.selectedInstance&&(await E.aiApi.instances.removeSkill(a.selectedInstance.id,o),await a.loadInstanceDetail(a.selectedInstance.id))}}),l==="providers"&&e.jsx(Ue,{providers:d.providers}),l==="models"&&e.jsx(Ge,{models:g.filteredModels,providers:d.providers,filter:g.modelFilter,onFilterChange:o=>g.setModelFilter(o)})]}),f&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",role:"dialog","aria-modal":"true",onKeyDown:o=>{o.key==="Escape"&&y(!1)},children:e.jsxs("div",{className:"bg-[var(--bg-primary)] rounded-lg shadow-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-[var(--border-color)]",children:[e.jsx("h2",{className:"text-xl font-bold",children:s("settings.profiles.createTitle")}),e.jsx("button",{onClick:()=>y(!1),className:"text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(t.X,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("settings.profiles.fields.name")}),e.jsx("input",{type:"text",value:x.name,onChange:o=>p({...x,name:o.target.value}),placeholder:s("settings.profiles.fields.namePlaceholder"),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("settings.profiles.fields.provider")}),e.jsxs("select",{value:x.providerId,onChange:o=>p({...x,providerId:o.target.value,defaultModel:void 0}),className:"input w-full",children:[e.jsx("option",{value:"",children:s("settings.profiles.fields.selectProvider")}),d.providers.map(o=>e.jsx("option",{value:o.id,children:o.name},o.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("settings.profiles.fields.defaultModel")}),e.jsxs("select",{value:x.defaultModel||"",onChange:o=>p({...x,defaultModel:o.target.value||void 0}),className:"input w-full",disabled:!x.providerId,children:[e.jsx("option",{value:"",children:s("settings.profiles.fields.defaultModelPlaceholder")}),g.models.filter(o=>o.providerId===x.providerId).map(o=>e.jsx("option",{value:o.code,children:o.name},o.id))]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",children:[s("settings.profiles.fields.code"),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] ml-2",children:["(",s("settings.profiles.fields.autoGenerated"),")"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:k?"...":x.code||"",readOnly:!0,className:"input w-full bg-[var(--bg-secondary)] font-mono text-sm",placeholder:s("settings.profiles.fields.codePlaceholder")}),e.jsx("button",{onClick:n,disabled:!x.providerId||k,className:"btn btn-secondary btn-sm",children:k?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):s("settings.profiles.fields.generate")})]})]})]}),e.jsxs("div",{className:"flex gap-3 justify-end p-6 border-t border-[var(--border-color)]",children:[e.jsx("button",{onClick:()=>y(!1),className:"btn btn-secondary",children:s("common:cancel")}),e.jsx("button",{onClick:h,disabled:!x.name.trim()||!x.providerId,className:"btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed",children:s("common:save")})]})]})}),e.jsx(De.ConfirmModal,{isOpen:L.show,title:s("settings.profiles.actions.delete"),message:s("settings.profiles.confirmDelete"),variant:"danger",confirmLabel:s("common:delete"),onConfirm:A,onCancel:()=>j({show:!1,instanceId:null})})]})}function Ce({prompt:s,onClose:l}){const{t:i}=Y.useTranslation(["ai"]),[a,d]=r.useState({}),[g,b]=r.useState([]),[f,y]=r.useState([]),[x,p]=r.useState(""),[k,T]=r.useState(""),[L,j]=r.useState(!1),[P,u]=r.useState(null),[A,F]=r.useState(null),[h,c]=r.useState(!1),[n,N]=r.useState(!1);r.useEffect(()=>{const v={};s.variables.forEach(O=>{v[O]=""}),d(v)},[s.variables]),r.useEffect(()=>{(async()=>{try{const W=(await E.aiApi.settings.getProviders()??[]).filter(m=>m.isActive);b(W)}catch(O){console.error("Failed to load providers:",O)}})()},[]),r.useEffect(()=>{(async()=>{if(!x){y([]);return}try{const W=(await E.aiApi.settings.getModels(void 0,x)??[]).filter(m=>m.isActive&&!m.isDeprecated);y(W),W.length>0&&T(W[0].id)}catch(O){console.error("Failed to load models:",O)}})()},[x]);const o=async()=>{j(!0),F(null),u(null);try{const v=await E.aiApi.skills.execute(s.id,{variables:Object.keys(a).length>0?a:void 0,providerId:x||void 0,modelId:k||void 0});v&&(u(v),!v.success&&v.error&&F(v.error))}catch(v){console.error("Failed to execute prompt:",v);const O=v instanceof Error?v.message:"Une erreur est survenue";F(O)}finally{j(!1)}},_=async()=>{P?.response&&(await navigator.clipboard.writeText(P.response),N(!0),setTimeout(()=>N(!1),2e3))},C=()=>s.blocks.sort((v,O)=>v.displayOrder-O.displayOrder).filter(v=>v.isEnabled).map(v=>{let O=v.content;return Object.entries(a).forEach(([W,m])=>{O=O.replace(new RegExp(`\\{${W}\\}`,"g"),m||`{${W}}`)}),`# ${v.label}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),Y=require("react-i18next"),t=require("lucide-react"),G=require("recharts"),J=require("./index-IgLVXPg8.js"),E=require("./aiApi-B20Teu2v.js"),De=require("./ConfirmModal-CYWRiVoD.js"),ke=require("./useTabNavigation-BVtbCTd5.js"),Z=require("react-router-dom"),ee=["#3b82f6","#8b5cf6","#22c55e","#f59e0b","#ef4444","#06b6d4","#ec4899","#14b8a6"],Pe={blue:"bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",green:"bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",yellow:"bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",red:"bg-[var(--error-bg)] text-[var(--error-text)] border-[var(--error-border)]",neutral:"bg-[var(--bg-secondary)] text-[var(--text-primary)] border-[var(--border-color)]"};function Fe(){const{t:s}=Y.useTranslation(["ai"]),[l,i]=r.useState(!0),[a,d]=r.useState(!1),[g,b]=r.useState(30),[f,y]=r.useState(""),[x,p]=r.useState(null),[k,T]=r.useState([]),[L,j]=r.useState([]),[P,u]=r.useState([]),[A,F]=r.useState(null),h=r.useCallback(async()=>{try{F(null);const m=f||void 0,[D,K,w,q]=await Promise.all([E.aiApi.dashboard.getOverview(g),E.aiApi.dashboard.getByProvider(),E.aiApi.dashboard.getByModel(void 0,void 0,m),E.aiApi.dashboard.getDailyCosts(g,m)]);p(D??null),T(K??[]),j(w??[]),u(q??[])}catch(m){console.error("Failed to load AI dashboard data:",m);const D=m;D.statusCode===401?F(s("dashboard.errors.sessionExpired")):D.statusCode===403?F(s("dashboard.errors.forbidden")):F(s("dashboard.errors.loadFailed"))}finally{i(!1),d(!1)}},[g,f,s]);r.useEffect(()=>{h()},[h]);const c=()=>{d(!0),h()},n=m=>{const D=Math.abs(m),w=D===0||D>=.01?2:D>=1e-4?4:6;return new Intl.NumberFormat("fr-FR",{style:"currency",currency:"USD",minimumFractionDigits:w,maximumFractionDigits:w}).format(m)},N=m=>new Intl.NumberFormat("fr-FR").format(m),o=r.useMemo(()=>{const m=new Map,D=new Set;for(const K of P){D.add(K.providerName),m.has(K.date)||m.set(K.date,{date:K.date});const w=m.get(K.date);w[K.providerName]=(w[K.providerName]??0)+K.totalCost}return{data:Array.from(m.values()).sort((K,w)=>String(K.date).localeCompare(String(w.date))),providers:Array.from(D)}},[P]),_=r.useMemo(()=>{const m=new Map;for(const D of P){const K=m.get(D.date);K?(K.requests+=D.requestCount,K.success+=D.successCount,K.errors+=D.errorCount):m.set(D.date,{date:D.date,requests:D.requestCount,success:D.successCount,errors:D.errorCount})}return Array.from(m.values()).sort((D,K)=>D.date.localeCompare(K.date)).map(D=>({...D,successRate:D.requests>0?D.success/D.requests*100:0}))},[P]),C=r.useMemo(()=>(x?.providerBreakdown??[]).map((m,D)=>({name:m.providerName,value:Number(m.totalCost),color:ee[D%ee.length]})),[x]),v=r.useMemo(()=>[...L].sort((m,D)=>D.totalCost-m.totalCost).slice(0,8).map(m=>({name:m.modelName.length>20?m.modelName.slice(0,18)+"...":m.modelName,fullName:m.modelName,tokens:m.totalTokens,cost:Number(m.totalCost),requests:m.requestCount,latency:Math.round(m.avgLatencyMs)})),[L]),O=r.useMemo(()=>{const m=P.reduce((K,w)=>K+w.totalInputTokens,0),D=P.reduce((K,w)=>K+w.totalOutputTokens,0);return m===0&&D===0?[]:[{name:s("dashboard.charts.inputTokens"),value:m,color:"#3b82f6"},{name:s("dashboard.charts.outputTokens"),value:D,color:"#8b5cf6"}]},[P,s]),W=r.useMemo(()=>{if(o.data.length<2)return null;const m=Math.floor(o.data.length/2),D=o.data.slice(0,m),K=o.data.slice(m),w=M=>M.reduce((S,I)=>{let R=0;for(const[V,U]of Object.entries(I))V!=="date"&&typeof U=="number"&&(R+=U);return S+R},0),q=w(D),B=w(K);return q===0?null:(B-q)/q*100},[o]);return l?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-500)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("ai.dashboard","Dashboard")}]}),A&&e.jsxs("div",{className:"bg-[var(--error-bg)] border border-[var(--error-border)] rounded-[var(--radius-card)] p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-[var(--error-text)] flex-shrink-0"}),e.jsx("p",{className:"flex-1 text-[var(--error-text)] font-medium",children:A}),e.jsx("button",{onClick:c,className:"text-[var(--error-text)] hover:opacity-80",children:e.jsx(t.RefreshCw,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Brain,{className:"w-6 h-6"}),s("dashboard.title")]}),e.jsx("p",{className:"text-[var(--text-secondary)] mt-1",children:s("dashboard.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("select",{value:f,onChange:m=>y(m.target.value),className:"input",children:[e.jsx("option",{value:"",children:s("dashboard.allProviders")}),k.map(m=>e.jsx("option",{value:m.providerId,children:m.providerName},m.providerId))]}),e.jsxs("select",{value:g,onChange:m=>b(Number(m.target.value)),className:"input",children:[e.jsx("option",{value:7,children:s("dashboard.period.7days")}),e.jsx("option",{value:30,children:s("dashboard.period.30days")}),e.jsx("option",{value:90,children:s("dashboard.period.90days")})]}),e.jsxs("button",{onClick:c,disabled:a,className:"btn btn-secondary flex items-center gap-2",children:[e.jsx(t.RefreshCw,{className:`w-4 h-4 ${a?"animate-spin":""}`}),s("dashboard.refresh")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:[e.jsx(re,{title:s("dashboard.kpis.totalCost"),value:n(x?.totalCost??0),icon:e.jsx(t.DollarSign,{className:"w-5 h-5"}),color:"green",trend:W}),e.jsx(re,{title:s("dashboard.kpis.totalTokens"),value:N(x?.totalTokens??0),icon:e.jsx(t.Zap,{className:"w-5 h-5"}),color:"blue"}),e.jsx(re,{title:s("dashboard.kpis.totalRequests"),value:N(x?.totalRequests??0),icon:e.jsx(t.Activity,{className:"w-5 h-5"}),color:"neutral"}),e.jsx(re,{title:s("dashboard.kpis.successRate"),value:`${(x?.successRate??0).toFixed(1)}%`,icon:e.jsx(t.CheckCircle,{className:"w-5 h-5"}),color:(()=>{const m=x?.successRate??0;return m>=95?"green":m>=80?"yellow":"red"})()}),e.jsx(re,{title:s("dashboard.kpis.avgLatency"),value:`${(x?.avgLatencyMs??0).toFixed(0)} ms`,icon:e.jsx(t.Clock,{className:"w-5 h-5"}),color:(()=>{const m=x?.avgLatencyMs??0;return m<=1e3?"green":m<=3e3?"yellow":"red"})()}),e.jsx(re,{title:s("dashboard.kpis.activeProviders"),value:`${x?.activeProviders??0} / ${x?.totalProviders??0}`,icon:e.jsx(t.Server,{className:"w-5 h-5"}),color:"blue"})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.DollarSign,{className:"w-5 h-5"}),s("dashboard.charts.dailyCosts")]}),o.data.length>0?e.jsx(G.ResponsiveContainer,{width:"100%",height:280,children:e.jsxs(G.AreaChart,{data:o.data,margin:{top:5,right:20,bottom:5,left:10},children:[e.jsx("defs",{children:o.providers.map((m,D)=>e.jsxs("linearGradient",{id:`grad-${D}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:ee[D%ee.length],stopOpacity:.4}),e.jsx("stop",{offset:"95%",stopColor:ee[D%ee.length],stopOpacity:.05})]},m))}),e.jsx(G.CartesianGrid,{strokeDasharray:"3 3",stroke:"var(--border-color)"}),e.jsx(G.XAxis,{dataKey:"date",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>m.slice(5)}),e.jsx(G.YAxis,{tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>`$${m}`}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:m=>[n(m??0),void 0],labelFormatter:m=>String(m)}),e.jsx(G.Legend,{}),o.providers.map((m,D)=>e.jsx(G.Area,{type:"monotone",dataKey:m,stackId:"1",stroke:ee[D%ee.length],fill:`url(#grad-${D})`,strokeWidth:2},m))]})}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.DollarSign,{className:"w-5 h-5"}),s("dashboard.charts.costByProvider")]}),C.length>0?e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(G.ResponsiveContainer,{width:"50%",height:220,children:e.jsxs(G.PieChart,{children:[e.jsx(G.Pie,{data:C,cx:"50%",cy:"50%",innerRadius:55,outerRadius:90,paddingAngle:2,dataKey:"value",children:C.map((m,D)=>e.jsx(G.Cell,{fill:m.color},`${m.name}-${D}`))}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:m=>[n(m??0),void 0]})]})}),e.jsx("div",{className:"flex-1 space-y-2",children:C.map(m=>e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:m.color}}),e.jsx("span",{className:"flex-1 truncate text-[var(--text-primary)]",children:m.name}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:n(m.value)})]},m.name))})]}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Zap,{className:"w-5 h-5"}),s("dashboard.charts.tokenDistribution")]}),O.length>0?e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(G.ResponsiveContainer,{width:"50%",height:220,children:e.jsxs(G.PieChart,{children:[e.jsx(G.Pie,{data:O,cx:"50%",cy:"50%",innerRadius:55,outerRadius:90,paddingAngle:2,dataKey:"value",children:O.map((m,D)=>e.jsx(G.Cell,{fill:m.color},`${m.name}-${D}`))}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:m=>[N(m??0),void 0]})]})}),e.jsx("div",{className:"flex-1 space-y-3",children:O.map(m=>{const D=O.reduce((w,q)=>w+q.value,0),K=D>0?(m.value/D*100).toFixed(1):"0";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:m.color}}),e.jsx("span",{className:"flex-1 text-[var(--text-primary)]",children:m.name}),e.jsxs("span",{className:"font-medium text-[var(--text-primary)]",children:[K,"%"]})]}),e.jsxs("p",{className:"text-xs text-[var(--text-secondary)] ml-5",children:[N(m.value)," tokens"]})]},m.name)})})]}):e.jsx(le,{message:s("dashboard.charts.noData")})]})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Activity,{className:"w-5 h-5"}),s("dashboard.charts.usageByModel")]}),v.length>0?e.jsx(G.ResponsiveContainer,{width:"100%",height:Math.max(200,v.length*44),children:e.jsxs(G.BarChart,{data:v,layout:"vertical",margin:{top:5,right:30,bottom:5,left:120},children:[e.jsx(G.CartesianGrid,{strokeDasharray:"3 3",stroke:"var(--border-color)",horizontal:!1}),e.jsx(G.XAxis,{type:"number",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>N(m)}),e.jsx(G.YAxis,{type:"category",dataKey:"name",tick:{fontSize:11,fill:"var(--text-primary)"},width:115}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:(m,D)=>{const K=m??0;return D==="tokens"?[N(K),"Tokens"]:D==="cost"?[n(K),s("dashboard.charts.costLabel")]:[K,D??""]},labelFormatter:(m,D)=>D?.[0]?.payload?.fullName??String(m)}),e.jsx(G.Legend,{}),e.jsx(G.Bar,{dataKey:"tokens",name:"Tokens",fill:"#3b82f6",radius:[0,4,4,0]})]})}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Activity,{className:"w-5 h-5"}),s("dashboard.charts.requestsAndSuccess")]}),_.length>0?e.jsx(G.ResponsiveContainer,{width:"100%",height:260,children:e.jsxs(G.ComposedChart,{data:_,margin:{top:5,right:20,bottom:5,left:10},children:[e.jsx(G.CartesianGrid,{strokeDasharray:"3 3",stroke:"var(--border-color)"}),e.jsx(G.XAxis,{dataKey:"date",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>m.slice(5)}),e.jsx(G.YAxis,{yAxisId:"left",tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>N(m)}),e.jsx(G.YAxis,{yAxisId:"right",orientation:"right",domain:[0,100],tick:{fontSize:11,fill:"var(--text-secondary)"},tickFormatter:m=>`${m}%`}),e.jsx(G.Tooltip,{contentStyle:{backgroundColor:"var(--bg-card)",border:"1px solid var(--border-color)",borderRadius:"8px",color:"var(--text-primary)"},formatter:(m,D)=>{const K=m??0;return D==="successRate"?[`${K.toFixed(1)}%`,s("dashboard.kpis.successRate")]:D==="errors"?[N(K),s("dashboard.charts.errors")]:[N(K),s("dashboard.charts.requests")]}}),e.jsx(G.Legend,{}),e.jsx(G.Bar,{yAxisId:"left",dataKey:"success",name:s("dashboard.charts.successRequests"),stackId:"req",fill:"#22c55e"}),e.jsx(G.Bar,{yAxisId:"left",dataKey:"errors",name:s("dashboard.charts.errors"),stackId:"req",fill:"#ef4444",radius:[4,4,0,0]}),e.jsx(G.Line,{yAxisId:"right",type:"monotone",dataKey:"successRate",name:s("dashboard.kpis.successRate"),stroke:"#f59e0b",strokeWidth:2,dot:!1})]})}):e.jsx(le,{message:s("dashboard.charts.noData")})]}),L.length>0&&e.jsxs("div",{className:"card p-5 border border-[var(--border-color)]",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(t.Clock,{className:"w-5 h-5"}),s("dashboard.charts.modelPerformance")]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[var(--border-color)] bg-[var(--bg-secondary)]",children:[e.jsx("th",{className:"text-left p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.model")}),e.jsx("th",{className:"text-left p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.provider")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.kpis.totalTokens")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.kpis.totalCost")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.requests")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.kpis.avgLatency")}),e.jsx("th",{className:"text-right p-3 font-medium text-[var(--text-secondary)]",children:s("dashboard.charts.costPerRequest")})]})}),e.jsx("tbody",{children:[...L].sort((m,D)=>D.totalCost-m.totalCost).map(m=>e.jsxs("tr",{className:"border-b border-[var(--border-color)] hover:bg-[var(--bg-hover)]",children:[e.jsx("td",{className:"p-3 font-mono text-[var(--text-primary)]",children:m.modelName}),e.jsx("td",{className:"p-3 text-[var(--text-secondary)]",children:m.providerCode}),e.jsx("td",{className:"p-3 text-right font-mono",children:N(m.totalTokens)}),e.jsx("td",{className:"p-3 text-right font-medium",children:n(m.totalCost)}),e.jsx("td",{className:"p-3 text-right",children:N(m.requestCount)}),e.jsxs("td",{className:"p-3 text-right",children:[Math.round(m.avgLatencyMs)," ms"]}),e.jsx("td",{className:"p-3 text-right text-[var(--text-secondary)]",children:m.requestCount>0?n(m.totalCost/m.requestCount):"—"})]},`${m.providerId}-${m.modelName}`))})]})})]})]})}function re({title:s,value:l,icon:i,color:a,trend:d}){return e.jsxs("div",{className:`card p-4 border ${Pe[a]}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium opacity-80",children:s}),i]}),e.jsx("div",{className:"text-2xl font-bold",children:l}),d!=null&&e.jsxs("div",{className:`flex items-center gap-1 mt-1 text-xs font-medium ${d>0?"text-red-500":"text-green-500"}`,children:[d>0?e.jsx(t.TrendingUp,{className:"w-3 h-3"}):e.jsx(t.TrendingDown,{className:"w-3 h-3"}),e.jsxs("span",{children:[Math.abs(d).toFixed(1),"%"]})]})]})}function le({message:s}){return e.jsx("div",{className:"flex items-center justify-center py-12 text-[var(--text-secondary)]",children:s})}const ie=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(s);function we({logoUrl:s,providerCode:l,size:i="md"}){const[a,d]=r.useState(!1),g={sm:{size:"w-8 h-8 text-sm",img:"w-8 h-8"},md:{size:"w-10 h-10 text-base",img:"w-10 h-10"},lg:{size:"w-12 h-12 text-lg",img:"w-12 h-12"}};return!s||a?e.jsx("div",{className:`${g[i].size} bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] rounded-lg flex items-center justify-center font-bold text-[var(--color-accent-600)]`,children:l.charAt(0).toUpperCase()}):e.jsx("img",{src:s,alt:l,className:`${g[i].img} rounded-lg object-contain`,onError:()=>d(!0)})}function $e({t:s}){return e.jsxs("div",{className:"card p-12 text-center",children:[e.jsx(t.Layers,{className:"w-16 h-16 mx-auto mb-4 text-[var(--text-secondary)] opacity-50"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:s("settings.profiles.noInstances")}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("settings.profiles.subtitle")})]})}function Le({t:s}){return e.jsxs("div",{className:"card p-12 text-center",children:[e.jsx(t.Layers,{className:"w-16 h-16 mx-auto mb-4 text-[var(--text-secondary)] opacity-50"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("settings.profiles.actions.viewDetails")})]})}const Me=s=>s?"bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)]":"bg-[var(--bg-secondary)] text-[var(--text-secondary)] border border-[var(--border-color)]",Ee=(s,l)=>l(s?"settings.profiles.status.active":"settings.profiles.status.inactive");function Be({isActive:s,isOverBudget:l,t:i}){return e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${Me(s)}`,children:Ee(s,i)}),l&&e.jsxs("span",{className:"px-2 py-0.5 rounded text-xs font-medium bg-[var(--error-bg)] text-[var(--error-text)] border border-[var(--error-border)] flex items-center gap-1",children:[e.jsx(t.AlertCircle,{className:"w-3 h-3"}),i("settings.profiles.usage.overBudget")]})]})}function Ie(s,l){return s?"border-[var(--color-accent-500)] shadow-[0_0_0_1px_var(--color-accent-500)]":l?"border-[var(--success-border)]":"border-[var(--border-color)]"}function he({type:s,hasKey:l,onSave:i,placeholder:a,providerKeyUrl:d,t:g}){const[b,f]=r.useState(!1),[y,x]=r.useState(""),[p,k]=r.useState(!1),[T,L]=r.useState(!1),j=s==="api",P=j?t.KeyRound:t.ShieldCheck,u=async()=>{if(y.trim()){k(!0);try{await i(y),x(""),L(!1),f(!1)}catch{}finally{k(!1)}}},A=()=>{x(""),L(!1),f(!1)};return e.jsxs("div",{className:`relative rounded-[var(--radius-card)] border overflow-hidden transition-all ${Ie(b,l)}`,children:[e.jsxs("div",{className:`px-4 py-3 flex items-center justify-between ${l?"bg-[var(--success-bg)]":"bg-[var(--bg-secondary)]"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center ${l?"bg-[var(--success-dot)] text-white":"bg-[var(--bg-tertiary)] text-[var(--text-secondary)]"}`,children:e.jsx(P,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[var(--text-primary)]",children:g(j?"settings.profiles.fields.apiKey":"settings.profiles.fields.adminKey")}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:g(l?"settings.profiles.status.hasApiKey":"settings.profiles.status.noApiKey")})]})]}),l&&!b&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)]",children:[e.jsx(t.CheckCircle,{className:"w-3 h-3"}),g("settings.profiles.status.active")]})]}),e.jsxs("div",{className:"px-4 py-3 bg-[var(--bg-primary)]",children:[d&&e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-xs text-[var(--color-accent-600)] hover:text-[var(--color-accent-700)] mb-3 transition-colors",children:[e.jsx(t.ExternalLink,{className:"w-3 h-3"}),g("settings.profiles.fields.getKeyFromProvider")]}),b?e.jsx(Re,{showValue:T,onShowValueChange:L,value:y,onValueChange:x,placeholder:a,saving:p,onCancel:A,onSave:u,hasKey:l,isApi:j,t:g}):e.jsx(Ke,{hasKey:l,onEdit:()=>f(!0),isApi:j,t:g})]})]})}function Oe({budget:s,usage:l,isOver:i,t:a,budgetPeriodType:d,nextResetDate:g}){if(s==null)return e.jsxs("div",{className:"flex-1 p-6 bg-[var(--bg-primary)] flex flex-col items-center justify-center",children:[e.jsx(t.DollarSign,{className:"w-10 h-10 text-[var(--text-tertiary)] opacity-30 mb-2"}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] italic",children:a("common:notSet","—")})]});const b=50,f=2*Math.PI*b,y=Math.min(100,l/s*100),x=f-f*y/100,p=i?"var(--error-dot)":y>80?"var(--warning-dot)":"var(--success-dot)";return e.jsxs("div",{className:"flex-1 p-4 bg-[var(--bg-primary)] flex flex-col items-center justify-center",children:[e.jsxs("div",{className:"relative",style:{width:120,height:120},children:[e.jsxs("svg",{viewBox:"0 0 120 120",className:"w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"60",cy:"60",r:b,fill:"none",stroke:"var(--bg-tertiary)",strokeWidth:"9",strokeLinecap:"round"}),e.jsx("circle",{cx:"60",cy:"60",r:b,fill:"none",stroke:p,strokeWidth:"9",strokeLinecap:"round",strokeDasharray:f,strokeDashoffset:x,className:"transition-all duration-700 ease-out"})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsxs("span",{className:`text-xl font-bold ${i?"text-[var(--error-text)]":"text-[var(--text-primary)]"}`,children:[Math.round(y),"%"]}),e.jsx("span",{className:"text-[10px] text-[var(--text-secondary)] uppercase tracking-wider",children:a("settings.profiles.usage.used","used")})]})]}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.currentPeriod")}),e.jsx("span",{className:`font-semibold ${i?"text-[var(--error-text)]":"text-[var(--text-primary)]"}`,children:ie(l)})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.fields.budgetLimit")}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:ie(s)})]}),e.jsx("div",{className:"h-px bg-[var(--border-color)]"}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.remaining","Remaining")}),e.jsxs("span",{className:`font-semibold ${i?"text-[var(--error-text)]":"text-[var(--success-text)]"}`,children:[i?"- ":"",ie(Math.abs(s-l))]})]}),d&&d!=="Fixed"&&g?e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.nextReset")}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:new Date(g).toLocaleDateString()})]}):d==="Fixed"||!d?e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.nextReset")}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:a("settings.profiles.usage.noAutoReset")})]}):null]})]})}function Re({showValue:s,onShowValueChange:l,value:i,onValueChange:a,placeholder:d,saving:g,onCancel:b,onSave:f,hasKey:y,isApi:x,t:p}){return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:s?"text":"password",value:i,onChange:k=>a(k.target.value),placeholder:d,className:"input w-full pr-10 font-mono text-sm",autoFocus:!0,onKeyDown:k=>{k.key==="Enter"&&i.trim()&&f(),k.key==="Escape"&&b()}}),e.jsx("button",{type:"button",onClick:()=>l(!s),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 rounded-md text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)] transition-colors",tabIndex:-1,children:s?e.jsx(t.EyeOff,{className:"w-4 h-4"}):e.jsx(t.Eye,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:b,disabled:g,className:"btn btn-ghost btn-sm",children:p("common:cancel")}),e.jsxs("button",{onClick:f,disabled:!i.trim()||g,className:"btn btn-primary btn-sm disabled:opacity-50 disabled:cursor-not-allowed",children:[g&&e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}),p(y?"settings.profiles.actions.changeKey":"common:save")]})]})]})}function Ke({hasKey:s,onEdit:l,isApi:i,t:a}){return e.jsx("button",{onClick:l,className:"w-full group flex items-center justify-between py-1 text-left",children:s?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-sm text-[var(--text-tertiary)] tracking-widest",children:"•".repeat(24)}),e.jsx("span",{className:"text-xs font-medium text-[var(--color-accent-600)] group-hover:text-[var(--color-accent-700)] transition-colors",children:a("settings.profiles.actions.changeKey")})]}):e.jsxs("span",{className:"flex items-center gap-2 text-sm text-[var(--text-secondary)] group-hover:text-[var(--color-accent-600)] transition-colors",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),a(i?"settings.profiles.actions.setApiKey":"settings.profiles.actions.setAdminKey")]})})}function qe({instance:s,isSelected:l,onSelect:i,t:a}){return e.jsxs("button",{onClick:()=>i(s.id),className:`w-full text-left p-4 rounded-lg border transition-all ${l?"border-[var(--color-accent-500)] bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 shadow-sm":"border-[var(--border-color)] bg-[var(--bg-primary)] hover:border-[var(--color-accent-300)] hover:shadow-sm"}`,children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(we,{logoUrl:s.providerLogoUrl,providerCode:s.providerCode,size:"sm"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:s.name}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:s.providerName})]})]}),e.jsx(Be,{isActive:s.isActive,isOverBudget:s.isOverBudget,t:a})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-xs text-[var(--text-secondary)]",children:[s.department&&e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--bg-secondary)] px-2 py-1 rounded",children:[e.jsx(t.Building2,{className:"w-3 h-3"}),s.department]}),s.hasApiKey&&e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--success-bg)] text-[var(--success-text)] px-2 py-1 rounded",children:[e.jsx(t.Key,{className:"w-3 h-3"}),"API"]}),s.isAllTenants?e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--success-bg)] text-[var(--success-text)] px-2 py-1 rounded",children:[e.jsx(t.Globe,{className:"w-3 h-3"}),a("settings.profiles.allTenants")]}):e.jsxs("span",{className:"flex items-center gap-1 bg-[var(--bg-secondary)] px-2 py-1 rounded",children:[e.jsx(t.Building2,{className:"w-3 h-3"}),a("settings.profiles.tenantCount",{count:s.tenantCount})]})]}),s.budgetLimit&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-[var(--text-secondary)]",children:a("settings.profiles.usage.budget")}),e.jsxs("span",{className:s.isOverBudget?"text-[var(--error-text)]":"",children:[ie(s.currentPeriodUsage)," / ",ie(s.budgetLimit)]})]}),e.jsx("div",{className:"h-1.5 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${s.isOverBudget?"bg-[var(--error-dot)]":"bg-[var(--color-accent-500)]"}`,style:{width:`${Math.min(100,s.currentPeriodUsage/s.budgetLimit*100)}%`}})})]})]})}function ue({placeholder:s,onSearch:l,onSelect:i,onClose:a}){const[d,g]=r.useState(""),[b,f]=r.useState([]),[y,x]=r.useState(!1),[p,k]=r.useState(null);r.useEffect(()=>{if(d.length<2){f([]);return}const L=setTimeout(async()=>{x(!0);try{const j=await l(d);f(j)}catch{f([])}finally{x(!1)}},300);return()=>clearTimeout(L)},[d,l]);const T=async L=>{k(L);try{await i(L),a()}catch{}finally{k(null)}};return e.jsxs("div",{className:"p-3 border-t border-[var(--border-color)] bg-[var(--bg-primary)]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(t.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("input",{type:"text",value:d,onChange:L=>g(L.target.value),placeholder:s,className:"w-full pl-9 pr-8 py-2 text-sm border border-[var(--border-color)] bg-[var(--bg-card)] text-[var(--text-primary)] rounded-[var(--radius-input)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",autoFocus:!0}),e.jsx("button",{onClick:a,className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(t.X,{className:"w-4 h-4"})})]}),y&&e.jsx("div",{className:"flex items-center justify-center py-3",children:e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin text-[var(--color-accent-500)]"})}),!y&&b.length>0&&e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto space-y-1",children:b.map(L=>e.jsxs("button",{onClick:()=>T(L.id),disabled:p===L.id,className:"w-full flex items-center gap-2.5 p-2 rounded-md text-left hover:bg-[var(--bg-hover)] transition-colors disabled:opacity-50",children:[L.icon||e.jsx("div",{className:"w-7 h-7 rounded-md bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] flex items-center justify-center flex-shrink-0",children:e.jsx(t.Building2,{className:"w-3.5 h-3.5 text-[var(--color-accent-600)]"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--text-primary)] truncate",children:L.label}),L.sublabel&&e.jsx("div",{className:"text-xs text-[var(--text-secondary)] truncate",children:L.sublabel})]}),p===L.id&&e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin text-[var(--color-accent-500)]"})]},L.id))}),!y&&d.length>=2&&b.length===0&&e.jsx("p",{className:"text-xs text-[var(--text-secondary)] text-center py-3",children:d.length>=2?"No results found":""})]})}function Ve({instances:s,selectedInstance:l,onSelectInstance:i,onToggleActive:a,onDelete:d,onUpdate:g,models:b,onSetApiKey:f,onSetAdminKey:y,providerApiKeyUrl:x,providerAdminApiKeyUrl:p,onAddTenant:k,onRemoveTenant:T,onSetAllTenants:L,onAddPrompt:j,onRemovePrompt:P}){const{t:u}=Y.useTranslation("ai"),[A,F]=r.useState(!1),[h,c]=r.useState({name:""}),[n,N]=r.useState(!1),[o,_]=r.useState(!1),[C,v]=r.useState(!1),[O,W]=r.useState(!1),m=r.useCallback(()=>{l&&(c({name:l.name,description:l.description||"",systemContext:l.systemContext||"",department:l.department||"",costCenter:l.costCenter||"",defaultModel:l.defaultModel||"",maxTokensPerRequest:l.maxTokensPerRequest||void 0,budgetLimit:l.budgetLimit||void 0,budgetPeriodType:l.budgetPeriodType||void 0,budgetPeriodStart:l.budgetPeriodStart||void 0}),F(!0))},[l]),D=r.useCallback(()=>{F(!1),c({name:""})},[]),K=r.useCallback(async()=>{if(h.name.trim()){N(!0);try{await g(h),F(!1)}catch{}finally{N(!1)}}},[h,g]),w=r.useCallback(async M=>{const S=await J.adminApi.tenants.getAll({search:M,pageSize:10}),I=new Set(l?.tenants?.map(R=>R.tenantId)||[]);return S.items.filter(R=>!I.has(R.id)).map(R=>({id:R.id,label:R.name,sublabel:R.slug||void 0}))},[l]),q=r.useCallback(async M=>{const{aiApi:S}=await Promise.resolve().then(()=>require("./aiApi-B20Teu2v.js")),I=await S.skills.getAll(),R=new Set(l?.skills?.map(V=>V.skillId)||[]);return I.filter(V=>!R.has(V.id)&&(V.name.toLowerCase().includes(M.toLowerCase())||V.code.toLowerCase().includes(M.toLowerCase()))).slice(0,10).map(V=>({id:V.id,label:V.name,sublabel:`${V.code} (v${V.version})`}))},[l]);r.useEffect(()=>{F(!1)},[l?.id]);const B=r.useCallback(async()=>{if(l){W(!0);try{await L(!l.isAllTenants)}catch{}finally{W(!1)}}},[l,L]);return s.length===0?e.jsx($e,{t:u}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"lg:col-span-1 space-y-3",children:s.map(M=>e.jsx(qe,{instance:M,isSelected:l?.id===M.id,onSelect:i,t:u},M.id))}),e.jsx("div",{className:"lg:col-span-2",children:l?e.jsxs("div",{className:"card p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(we,{logoUrl:l.providerLogoUrl,providerCode:l.providerCode,size:"lg"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-semibold",children:A?u("settings.profiles.editTitle"):l.name}),e.jsxs("p",{className:"text-sm text-[var(--text-secondary)]",children:[l.providerName," -"," ",e.jsx("code",{className:"text-xs",children:l.code})]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:A?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:D,disabled:n,className:"btn btn-secondary btn-sm",children:[e.jsx(t.X,{className:"w-4 h-4"}),u("common:cancel")]}),e.jsxs("button",{onClick:K,disabled:!h.name.trim()||n,className:"btn btn-primary btn-sm disabled:opacity-50 disabled:cursor-not-allowed",children:[n?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsx(t.Save,{className:"w-4 h-4"}),u("common:save")]})]}):e.jsxs(e.Fragment,{children:[l.providerDocumentationUrl&&e.jsxs("a",{href:l.providerDocumentationUrl,target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm",children:[e.jsx(t.BookOpen,{className:"w-4 h-4"}),u("settings.profiles.metadata.docs")]}),e.jsxs("button",{onClick:m,className:"btn btn-secondary btn-sm",children:[e.jsx(t.Pencil,{className:"w-4 h-4"}),u("settings.profiles.actions.edit")]}),e.jsx("button",{onClick:()=>a(l.id),className:`btn btn-sm ${l.isActive?"btn-secondary":"btn-primary"}`,title:u("settings.profiles.actions.toggleActive"),children:l.isActive?e.jsx(t.XCircle,{className:"w-4 h-4"}):e.jsx(t.CheckCircle,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>d(l.id),className:"btn btn-sm text-[var(--error-text)] hover:bg-[var(--error-bg)]",title:u("settings.profiles.actions.delete"),children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})})]}),A?e.jsxs("div",{className:"space-y-4 bg-[var(--bg-secondary)] rounded-lg p-5 border border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.name")}),e.jsx("input",{type:"text",value:h.name,onChange:M=>c({...h,name:M.target.value}),placeholder:u("settings.profiles.fields.namePlaceholder"),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.description")}),e.jsx("input",{type:"text",value:h.description||"",onChange:M=>c({...h,description:M.target.value||void 0}),placeholder:u("settings.profiles.fields.descriptionPlaceholder"),className:"input w-full"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.department")}),e.jsx("input",{type:"text",value:h.department||"",onChange:M=>c({...h,department:M.target.value||void 0}),placeholder:u("settings.profiles.fields.departmentPlaceholder"),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.costCenter")}),e.jsx("input",{type:"text",value:h.costCenter||"",onChange:M=>c({...h,costCenter:M.target.value||void 0}),placeholder:u("settings.profiles.fields.costCenterPlaceholder"),className:"input w-full"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.defaultModel")}),e.jsx("p",{className:"text-xs text-[var(--text-muted)] mb-2",children:u("settings.profiles.fields.modelFamilyDescription")}),(()=>{const M=b.filter(U=>U.providerId===l.providerId&&U.modelFamily),S=new Map;M.forEach(U=>{const H=U.modelFamily;S.has(H)||S.set(H,[]),S.get(H).push(U)}),S.forEach(U=>U.sort((H,Q)=>{const $=H.deprecationDate?new Date(H.deprecationDate).getTime():0;return(Q.deprecationDate?new Date(Q.deprecationDate).getTime():0)-$||(H.inputCostPerMillionTokens>Q.inputCostPerMillionTokens?-1:1)}));const I=h.defaultModel??"",R=S.has(I),V=!R&&!!I;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("select",{value:R?I:V?"__pinned__":"",onChange:U=>{const H=U.target.value;H!=="__pinned__"&&c({...h,defaultModel:H||void 0})},className:"input w-full",children:[e.jsx("option",{value:"",children:u("settings.profiles.fields.defaultModelPlaceholder")}),Array.from(S.entries()).map(([U,H])=>{const Q=H[0],$=Math.min(...H.map(X=>X.inputCostPerMillionTokens)),z=Math.max(...H.map(X=>X.outputCostPerMillionTokens));return e.jsxs("option",{value:U,children:[U.charAt(0).toUpperCase()+U.slice(1)," — ",u("settings.profiles.fields.latestVersion",{modelName:Q.name})," ($",$,"/$",z," ",u("settings.models.perMillionTokens"),") — ",u("settings.profiles.fields.familyModels",{count:H.length})]},U)}),V&&e.jsxs("option",{value:"__pinned__",disabled:!0,children:["✦ ",u("settings.profiles.fields.pinVersion"),": ",b.find(U=>U.code===I)?.name??I]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{type:"button",onClick:()=>{if(V){const H=b.find(Q=>Q.code===I)?.modelFamily;c({...h,defaultModel:H||void 0})}else if(R){const U=S.get(I);U&&U.length>0&&c({...h,defaultModel:U[0].code})}},className:`flex items-center gap-1.5 text-xs px-2 py-1 rounded transition-colors ${V?"bg-[var(--warning-bg)] text-[var(--warning-text)] border border-[var(--warning-border)]":"bg-[var(--bg-secondary)] text-[var(--text-muted)] border border-[var(--border-color)] hover:border-[var(--text-muted)]"}`,disabled:!I,children:[V?e.jsx(t.Pin,{className:"w-3 h-3"}):e.jsx(t.PinOff,{className:"w-3 h-3"}),V?u("settings.profiles.fields.pinVersion"):u("settings.profiles.fields.latestVersion",{modelName:""}).replace(": ","")]})}),V&&e.jsx("select",{value:I,onChange:U=>c({...h,defaultModel:U.target.value||void 0}),className:"input w-full",children:b.filter(U=>U.providerId===l.providerId).map(U=>e.jsxs("option",{value:U.code,children:[U.name," ",U.modelFamily?`(${U.modelFamily})`:""]},U.id))})]})})()]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.maxTokensPerRequest")}),e.jsx("input",{type:"number",value:h.maxTokensPerRequest??"",onChange:M=>c({...h,maxTokensPerRequest:M.target.value?Number(M.target.value):void 0}),placeholder:u("settings.profiles.fields.maxTokensPerRequestPlaceholder","e.g. 4096"),className:"input w-full",min:0})]})]}),e.jsxs("div",{className:"md:w-1/2",children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.budgetLimit")}),e.jsx("input",{type:"number",value:h.budgetLimit??"",onChange:M=>c({...h,budgetLimit:M.target.value?Number(M.target.value):void 0}),placeholder:u("settings.profiles.fields.budgetLimitPlaceholder","e.g. 100.00"),className:"input w-full",min:0,step:.01})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.budgetPeriodType")}),e.jsxs("select",{value:h.budgetPeriodType||"",onChange:M=>c({...h,budgetPeriodType:M.target.value||void 0}),className:"input w-full",children:[e.jsx("option",{value:"",children:"Select period type"}),e.jsx("option",{value:"Monthly",children:"Monthly"}),e.jsx("option",{value:"Quarterly",children:"Quarterly"}),e.jsx("option",{value:"Annual",children:"Annual"}),e.jsx("option",{value:"Fixed",children:"Fixed"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.budgetPeriodStart")}),e.jsx("input",{type:"date",value:h.budgetPeriodStart||"",onChange:M=>c({...h,budgetPeriodStart:M.target.value||void 0}),className:"input w-full"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-primary)] mb-1",children:u("settings.profiles.fields.systemContext")}),e.jsx("textarea",{value:h.systemContext||"",onChange:M=>c({...h,systemContext:M.target.value||void 0}),placeholder:u("settings.profiles.fields.systemContextPlaceholder","Enter system instructions..."),className:"input w-full font-mono text-sm min-h-[120px] resize-y",rows:5})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[var(--text-secondary)]",children:l.description||e.jsx("span",{className:"italic",children:u("common:notSet","—")})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-5 gap-4",children:[e.jsxs("div",{className:"lg:col-span-3 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--text-secondary)] mb-1",children:[e.jsx(t.Building2,{className:"w-3 h-3"}),u("settings.profiles.fields.department")]}),e.jsx("div",{className:"font-medium",children:l.department||e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--text-secondary)] mb-1",children:[e.jsx(t.DollarSign,{className:"w-3 h-3"}),u("settings.profiles.fields.costCenter")]}),e.jsx("div",{className:"font-medium",children:l.costCenter||e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mb-1",children:u("settings.profiles.fields.defaultModel")}),e.jsx("div",{className:"font-medium font-mono text-sm",children:l.defaultModel||e.jsx("span",{className:"text-[var(--text-tertiary)] font-sans",children:"—"})})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg",children:[e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mb-1",children:u("settings.profiles.fields.maxTokensPerRequest")}),e.jsx("div",{className:"font-medium",children:l.maxTokensPerRequest?l.maxTokensPerRequest.toLocaleString():e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})})]})]}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsx("h4",{className:"font-medium mb-1.5 text-sm",children:u("settings.profiles.fields.systemContext")}),l.systemContext?e.jsx("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg text-sm font-mono whitespace-pre-wrap overflow-y-auto flex-1",children:l.systemContext}):e.jsx("div",{className:"bg-[var(--bg-secondary)] p-3 rounded-lg text-sm text-[var(--text-tertiary)] italic flex-1 flex items-center justify-center",children:"—"})]})]}),e.jsxs("div",{className:`lg:col-span-2 rounded-[var(--radius-card)] border overflow-hidden flex flex-col ${l.isOverBudget?"border-[var(--error-border)]":"border-[var(--border-color)]"}`,children:[e.jsxs("div",{className:`px-4 py-2.5 flex items-center gap-2 text-sm font-medium ${l.isOverBudget?"bg-[var(--error-bg)] text-[var(--error-text)]":"bg-[var(--bg-secondary)] text-[var(--text-primary)]"}`,children:[e.jsx(t.DollarSign,{className:"w-4 h-4"}),u("settings.profiles.usage.budget"),l.isOverBudget&&e.jsxs("span",{className:"ml-auto flex items-center gap-1 text-xs font-medium",children:[e.jsx(t.AlertCircle,{className:"w-3.5 h-3.5"}),u("settings.profiles.usage.overBudget")]})]}),e.jsx(Oe,{budget:l.budgetLimit,usage:l.currentPeriodUsage,isOver:l.isOverBudget,t:u,budgetPeriodType:l.budgetPeriodType,nextResetDate:l.nextResetDate})]})]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"font-medium mb-3 flex items-center gap-2",children:[e.jsx(t.Key,{className:"w-4 h-4"}),u("settings.profiles.fields.apiKeys")]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(he,{type:"api",hasKey:l.hasApiKey,onSave:f,placeholder:u("settings.profiles.fields.apiKeyPlaceholder"),providerKeyUrl:x,t:u}),e.jsx(he,{type:"admin",hasKey:l.hasAdminKey,onSave:y,placeholder:u("settings.profiles.fields.adminKeyPlaceholder"),providerKeyUrl:p,t:u})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[e.jsx(t.Building2,{className:"w-4 h-4 text-[var(--color-accent-500)]"}),u("settings.profiles.tenantAccess")]})}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)]",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-[var(--text-primary)]",children:u("settings.profiles.allTenants")}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)] mt-0.5",children:u("settings.profiles.allTenantsDescription")})]}),e.jsxs("button",{onClick:B,disabled:O,className:"flex-shrink-0 transition-colors",title:u("settings.profiles.allTenants"),children:[O&&e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-500)]"}),!O&&l.isAllTenants&&e.jsx(t.ToggleRight,{className:"w-10 h-10 text-[var(--success-dot)]"}),!O&&!l.isAllTenants&&e.jsx(t.ToggleLeft,{className:"w-10 h-10 text-[var(--text-tertiary)]"})]})]}),!l.isAllTenants&&e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-[var(--radius-card)] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-[var(--bg-tertiary)]",children:[e.jsxs("h5",{className:"text-sm font-medium text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Building2,{className:"w-4 h-4 text-[var(--color-accent-500)]"}),u("settings.profiles.tenantCount",{count:l.tenants?.length??0})]}),e.jsx("button",{onClick:()=>_(!o),className:"p-1.5 rounded-md hover:bg-[var(--bg-primary)] text-[var(--color-accent-500)] transition-colors",title:u("settings.profiles.addTenant"),children:e.jsx(t.Plus,{className:"w-4 h-4"})})]}),o&&e.jsx(ue,{placeholder:u("settings.profiles.addTenant"),onSearch:w,onSelect:async M=>{await k(M)},onClose:()=>_(!1)}),e.jsx("div",{className:"p-3",children:(l.tenants?.length??0)>0?e.jsx("div",{className:"space-y-2",children:l.tenants.map(M=>e.jsxs("div",{className:"group flex items-center gap-3 p-2.5 rounded-lg bg-[var(--bg-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] flex items-center justify-center flex-shrink-0",children:e.jsx(t.Building2,{className:"w-4 h-4 text-[var(--color-accent-600)]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:M.tenantName}),M.tenantSlug&&e.jsx("div",{className:"text-xs text-[var(--text-secondary)] truncate",children:M.tenantSlug})]}),e.jsx("button",{onClick:()=>T(M.tenantId),className:"p-1.5 rounded-md text-[var(--text-secondary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] opacity-0 group-hover:opacity-100 transition-all",title:u("settings.profiles.removeTenant"),children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]},M.id))}):e.jsxs("div",{className:"text-center py-4",children:[e.jsx(t.Building2,{className:"w-7 h-7 mx-auto text-[var(--text-tertiary)] mb-1.5"}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:u("settings.profiles.noTenants")})]})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[e.jsx(t.BookOpen,{className:"w-4 h-4 text-[var(--color-accent-500)]"}),u("settings.profiles.prompts.title")]}),e.jsx("button",{onClick:()=>v(!C),className:"p-1.5 rounded-md hover:bg-[var(--bg-tertiary)] text-[var(--color-accent-500)] transition-colors",title:u("settings.profiles.prompts.addPrompt"),children:e.jsx(t.Plus,{className:"w-4 h-4"})})]}),C&&e.jsx(ue,{placeholder:u("settings.profiles.prompts.addPrompt"),onSearch:q,onSelect:async M=>{await j(M)},onClose:()=>v(!1)}),e.jsx("div",{className:"bg-[var(--bg-secondary)] rounded-lg overflow-hidden",children:e.jsx("div",{className:"p-3 min-h-[100px]",children:l?.skills&&l.skills.length>0?e.jsx("div",{className:"space-y-2",children:l.skills.map(M=>e.jsxs("div",{className:"group flex items-center gap-3 p-2.5 rounded-lg bg-[var(--bg-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] flex items-center justify-center flex-shrink-0",children:e.jsx(t.BookOpen,{className:"w-4 h-4 text-[var(--color-accent-600)]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:M.skillName}),e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] truncate",children:[M.skillCode," ",e.jsxs("span",{className:"text-xs opacity-75",children:["v",M.skillVersion]})]})]}),e.jsx("span",{className:"text-xs px-2 py-1 rounded bg-[var(--bg-secondary)] text-[var(--text-secondary)] whitespace-nowrap",children:M.skillStatus}),e.jsx("button",{onClick:()=>P(M.skillId),className:"p-1.5 rounded-md text-[var(--text-secondary)] hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 opacity-0 group-hover:opacity-100 transition-all",children:e.jsx(t.Trash2,{className:"w-3.5 h-3.5"})})]},M.id))}):e.jsx("p",{className:"text-sm text-[var(--text-secondary)] text-center py-6",children:u("settings.profiles.prompts.noPrompts")})})})]}),e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] flex items-center gap-4 pt-4 border-t border-[var(--border-color)]",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(t.Clock,{className:"w-3 h-3"}),u("settings.profiles.metadata.created"),": ",new Date(l.createdAt).toLocaleDateString(),l.createdBy&&` ${u("settings.profiles.metadata.by")} ${l.createdBy}`]}),l.updatedAt&&e.jsxs("span",{children:[u("settings.profiles.metadata.updated"),":"," ",new Date(l.updatedAt).toLocaleDateString(),l.updatedBy&&` ${u("settings.profiles.metadata.by")} ${l.updatedBy}`]})]})]}):e.jsx(Le,{t:u})})]})}function Ue({providers:s}){const{t:l}=Y.useTranslation("ai");return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-[var(--text-secondary)]",children:l("settings.providers.subtitle")}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:s.map(i=>e.jsx(J.ProviderCard,{name:i.name,code:i.code,description:i.description||"",modelCount:i.modelCount,color:"var(--color-accent-500)",websiteUrl:i.websiteUrl??void 0,docsUrl:i.documentationUrl??void 0,apiKeyUrl:i.apiKeyUrl??void 0,adminApiKeyUrl:i.adminApiKeyUrl??void 0,hasAdminKey:i.supportsAdminApi,badgeIcon:i.supportsAdminApi?t.Shield:void 0,badgeTooltip:i.supportsAdminApi?l("settings.providers.adminApiSupported"):void 0,labels:{websiteLabel:l("settings.providers.officialSite"),docsLabel:l("settings.providers.apiDocumentation"),apiKeyLabel:l("settings.providers.getApiKey"),adminApiKeyLabel:l("settings.providers.getAdminApiKey"),modelsLabel:l("settings.providers.models")}},i.id))})]})}const ne=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(s),ce=[{key:"supportsVision",icon:t.Eye,color:"text-blue-700 dark:text-blue-400",bgLight:"bg-blue-100",bgDark:"dark:bg-blue-900/30"},{key:"supportsImageGeneration",icon:t.ImagePlus,color:"text-pink-700 dark:text-pink-400",bgLight:"bg-pink-100",bgDark:"dark:bg-pink-900/30"},{key:"supportsAudioInput",icon:t.Mic,color:"text-amber-700 dark:text-amber-400",bgLight:"bg-amber-100",bgDark:"dark:bg-amber-900/30"},{key:"supportsAudioOutput",icon:t.Volume2,color:"text-orange-700 dark:text-orange-400",bgLight:"bg-orange-100",bgDark:"dark:bg-orange-900/30"},{key:"supportsFunctionCalling",icon:t.Zap,color:"text-purple-700 dark:text-purple-400",bgLight:"bg-purple-100",bgDark:"dark:bg-purple-900/30"},{key:"supportsStreaming",icon:t.Radio,color:"text-green-700 dark:text-green-400",bgLight:"bg-green-100",bgDark:"dark:bg-green-900/30"},{key:"supportsCodeExecution",icon:t.Terminal,color:"text-cyan-700 dark:text-cyan-400",bgLight:"bg-cyan-100",bgDark:"dark:bg-cyan-900/30"}],pe=s=>s?.charAt(0).toUpperCase()||"M",ze=(s,l)=>s.isDeprecated?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 rounded text-xs",children:[e.jsx(t.AlertOctagon,{className:"w-3 h-3"}),l("settings.models.deprecated")]}):s.isActive?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded text-xs",children:[e.jsx(t.CheckCircle,{className:"w-3 h-3"}),l("settings.models.statusActive")]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-gray-100 dark:bg-gray-900/30 text-gray-700 dark:text-gray-400 rounded text-xs",children:[e.jsx(t.XCircle,{className:"w-3 h-3"}),l("settings.models.statusInactive")]});function Ge({models:s,providers:l,filter:i,onFilterChange:a}){const{t:d}=Y.useTranslation("ai"),g=["TextGeneration","Embedding","ImageGeneration","AudioGeneration","VideoGeneration"],[b,f]=r.useState(1),[y,x]=r.useState("grid"),[p,k]=r.useState(new Set),[T,L]=r.useState("or"),j=y==="grid"?12:10,P=s.filter(c=>{if(p.size===0)return!0;const n=Array.from(p);return T==="or"?n.some(N=>c[N]):n.every(N=>c[N])}),u=Math.ceil(P.length/j),A=P.slice((b-1)*j,b*j);r.useEffect(()=>{f(1)},[i,p,T,y]);const F=c=>{k(n=>{const N=new Set(n);return N.has(c)?N.delete(c):N.add(c),N})},h=()=>{k(new Set)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-[var(--text-secondary)]",children:d("settings.models.subtitle")}),e.jsxs("div",{className:"flex items-center gap-1 p-1 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("button",{onClick:()=>x("grid"),className:`p-2 rounded transition-colors ${y==="grid"?"bg-[var(--bg-primary)] shadow-sm":"hover:bg-[var(--bg-tertiary)]"}`,title:d("settings.models.viewGrid"),children:e.jsx(t.LayoutGrid,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>x("table"),className:`p-2 rounded transition-colors ${y==="table"?"bg-[var(--bg-primary)] shadow-sm":"hover:bg-[var(--bg-tertiary)]"}`,title:d("settings.models.viewTable"),children:e.jsx(t.List,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("settings.models.category")}),e.jsxs("select",{value:i.category||"",onChange:c=>a({...i,category:c.target.value||void 0}),className:"input min-w-[150px]",children:[e.jsx("option",{value:"",children:d("prompts.allCategories")}),g.map(c=>e.jsx("option",{value:c,children:d(`settings.models.categories.${c}`)},c))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("settings.profiles.fields.provider")}),e.jsxs("select",{value:i.providerId||"",onChange:c=>a({...i,providerId:c.target.value||void 0}),className:"input min-w-[150px]",children:[e.jsx("option",{value:"",children:d("dashboard.allProviders")}),l.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]})]}),e.jsxs("div",{className:"card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Filter,{className:"w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("span",{className:"text-sm font-medium",children:d("settings.models.filterByCapabilities")}),p.size>0&&e.jsx("span",{className:"px-2 py-0.5 bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] text-[var(--color-accent-600)] text-xs rounded-full",children:p.size})]}),e.jsx("div",{className:"flex items-center gap-2",children:p.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 p-1 bg-[var(--bg-secondary)] rounded-lg text-xs",children:[e.jsx("button",{onClick:()=>L("or"),className:`px-2 py-1 rounded transition-colors ${T==="or"?"bg-[var(--bg-primary)] shadow-sm font-medium":"hover:bg-[var(--bg-tertiary)]"}`,children:d("settings.models.filterOr")}),e.jsx("button",{onClick:()=>L("and"),className:`px-2 py-1 rounded transition-colors ${T==="and"?"bg-[var(--bg-primary)] shadow-sm font-medium":"hover:bg-[var(--bg-tertiary)]"}`,children:d("settings.models.filterAnd")})]}),e.jsx("button",{onClick:h,className:"text-xs text-[var(--text-secondary)] hover:text-[var(--text-primary)] underline",children:d("common:clear")})]})})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:ce.map(({key:c,icon:n,color:N,bgLight:o,bgDark:_})=>{const C=p.has(c);return e.jsxs("button",{onClick:()=>F(c),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-medium transition-all ${o} ${_} ${N} ${C?"ring-2 ring-offset-1 ring-current shadow-sm":"opacity-60 hover:opacity-100"}`,children:[e.jsx(n,{className:"w-3.5 h-3.5"}),d(`settings.models.${c}`)]},c)})}),p.size>0&&e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:T==="or"?d("settings.models.filterOrDescription",{count:P.length}):d("settings.models.filterAndDescription",{count:P.length})})]}),P.length===0&&e.jsxs("div",{className:"card p-12 text-center",children:[e.jsx(t.Cpu,{className:"w-16 h-16 mx-auto mb-4 text-[var(--text-secondary)] opacity-50"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:d("settings.models.noModels")}),p.size>0&&e.jsx("button",{onClick:h,className:"btn btn-secondary mt-2",children:d("settings.models.clearFilters")})]}),P.length>0&&y==="grid"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:A.map(c=>e.jsxs("div",{className:`bg-[var(--bg-card)] border-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)] rounded-[var(--radius-card)] overflow-hidden transition-all hover:shadow-lg hover:-translate-y-0.5 hover:border-[var(--color-accent-400)] ${c.isDeprecated?"opacity-60":""}`,children:[e.jsx("div",{className:"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 p-4 border-b-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-[var(--color-accent-500)] rounded-lg flex items-center justify-center text-white font-bold shadow-lg",children:pe(c.providerCode)}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--text-primary)]",children:c.name}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)]",children:c.providerName})]})]}),c.isDeprecated&&e.jsx("span",{className:"px-2 py-0.5 bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400 rounded text-xs flex items-center gap-1",children:e.jsx(t.AlertOctagon,{className:"w-3 h-3"})})]})}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"px-2 py-1 bg-[var(--bg-secondary)] rounded text-xs font-medium",children:d(`settings.models.categories.${c.category}`)}),e.jsx("code",{className:"text-xs text-[var(--text-tertiary)] font-mono",children:c.code})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-lg p-3 text-center",children:[e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] mb-1 flex items-center justify-center gap-1",children:[e.jsx(t.ArrowDownUp,{className:"w-3 h-3"}),d("settings.models.inputCost")]}),e.jsx("div",{className:"font-mono font-bold text-lg",children:ne(c.inputCostPerMillionTokens)}),e.jsx("div",{className:"text-[10px] text-[var(--text-tertiary)]",children:d("settings.models.perMillionTokens")})]}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-lg p-3 text-center",children:[e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] mb-1 flex items-center justify-center gap-1",children:[e.jsx(t.ArrowUpDown,{className:"w-3 h-3"}),d("settings.models.outputCost")]}),e.jsx("div",{className:"font-mono font-bold text-lg",children:ne(c.outputCostPerMillionTokens)}),e.jsx("div",{className:"text-[10px] text-[var(--text-tertiary)]",children:d("settings.models.perMillionTokens")})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-[var(--text-secondary)] flex items-center gap-1",children:[e.jsx(t.Brain,{className:"w-4 h-4"}),d("settings.models.contextWindow")]}),e.jsx("span",{className:"font-mono font-medium",children:c.contextWindow>=1e6?`${(c.contextWindow/1e6).toFixed(1)}M`:`${(c.contextWindow/1e3).toFixed(0)}K`})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[ce.map(({key:n,icon:N,color:o,bgLight:_,bgDark:C})=>c[n]&&e.jsx("span",{className:`p-1.5 ${_} ${C} ${o} rounded-md`,title:d(`settings.models.${n}`),children:e.jsx(N,{className:"w-3.5 h-3.5"})},n)),!ce.some(({key:n})=>c[n])&&e.jsx("span",{className:"text-xs text-[var(--text-tertiary)] italic",children:d("settings.models.noCapabilities")})]})]})]},c.id))}),P.length>0&&y!=="grid"&&e.jsx("div",{className:"card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-[var(--bg-secondary)] border-b border-[var(--border-color)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-4 font-medium text-sm",children:d("settings.models.model")}),e.jsx("th",{className:"text-left p-4 font-medium text-sm",children:d("settings.models.category")}),e.jsxs("th",{className:"text-right p-4 font-medium text-sm",children:[d("settings.models.inputCost")," $/M"]}),e.jsxs("th",{className:"text-right p-4 font-medium text-sm",children:[d("settings.models.outputCost")," $/M"]}),e.jsx("th",{className:"text-right p-4 font-medium text-sm",children:d("settings.models.contextWindow")}),e.jsx("th",{className:"text-center p-4 font-medium text-sm",children:d("settings.models.capabilities")}),e.jsx("th",{className:"text-center p-4 font-medium text-sm",children:d("settings.models.status")})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border-color)]",children:A.map(c=>e.jsxs("tr",{className:`hover:bg-[var(--bg-secondary)]/50 ${c.isDeprecated?"opacity-60":""}`,children:[e.jsx("td",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-[var(--color-accent-500)] rounded flex items-center justify-center text-xs font-bold text-white",children:pe(c.providerCode)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:c.name}),e.jsx("code",{className:"text-xs text-[var(--text-secondary)]",children:c.code})]})]})}),e.jsx("td",{className:"p-4",children:e.jsx("span",{className:"px-2 py-1 bg-[var(--bg-secondary)] rounded text-sm",children:d(`settings.models.categories.${c.category}`)})}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("span",{className:"font-mono font-medium",children:ne(c.inputCostPerMillionTokens)})}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("span",{className:"font-mono font-medium",children:ne(c.outputCostPerMillionTokens)})}),e.jsx("td",{className:"p-4 text-right",children:e.jsx("div",{className:"font-mono text-sm",children:c.contextWindow>=1e6?`${(c.contextWindow/1e6).toFixed(1)}M`:`${(c.contextWindow/1e3).toFixed(0)}K`})}),e.jsx("td",{className:"p-4",children:e.jsx("div",{className:"flex items-center justify-center gap-1 flex-wrap",children:ce.map(({key:n,icon:N,color:o,bgLight:_,bgDark:C})=>c[n]&&e.jsx("span",{className:`p-1 ${_} ${C} ${o} rounded`,title:d(`settings.models.${n}`),children:e.jsx(N,{className:"w-3.5 h-3.5"})},n))})}),e.jsx("td",{className:"p-4 text-center",children:ze(c,d)})]},c.id))})]})})}),u>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:d("common.showingOf",{from:(b-1)*j+1,to:Math.min(b*j,P.length),total:P.length})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>f(c=>Math.max(1,c-1)),disabled:b===1,className:"btn btn-sm btn-secondary disabled:opacity-50",children:d("common.previous")}),e.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:Math.min(u,5)},(c,n)=>{let N;return u<=5||b<=3?N=n+1:b>=u-2?N=u-4+n:N=b-2+n,e.jsx("button",{onClick:()=>f(N),className:`w-8 h-8 rounded text-sm font-medium ${b===N?"bg-[var(--color-accent-500)] text-white":"hover:bg-[var(--bg-secondary)]"}`,children:N},N)})}),e.jsx("button",{onClick:()=>f(c=>Math.min(u,c+1)),disabled:b===u,className:"btn btn-sm btn-secondary disabled:opacity-50",children:d("common.next")})]})]})]})}function _e(){const[s,l]=r.useState([]),[i,a]=r.useState(null),[d,g]=r.useState(!1),[b,f]=r.useState(null),y=r.useCallback(async()=>{g(!0),f(null);try{const h=await E.aiApi.instances.getAll();l(h??[])}catch(h){const c=h instanceof Error?h.message:"Failed to load instances";f(c),console.error("Failed to load instances:",h)}finally{g(!1)}},[]),x=r.useCallback(async h=>{f(null);try{const c=await E.aiApi.instances.getById(h);a(c??null)}catch(c){const n=c instanceof Error?c.message:"Failed to load instance details";f(n),console.error("Failed to load instance details:",c)}},[]),p=r.useCallback(async()=>{i&&await x(i.id)},[i,x]),k=r.useCallback(async h=>{f(null);try{const c=await E.aiApi.instances.create(h);return await y(),c??null}catch(c){const n=c instanceof Error?c.message:"Failed to create instance";return f(n),console.error("Failed to create instance:",c),null}},[y]),T=r.useCallback(async(h,c)=>{f(null);try{const n=await E.aiApi.instances.update(h,c);return await y(),i?.id===h&&a(n??null),n??null}catch(n){const N=n instanceof Error?n.message:"Failed to update instance";return f(N),console.error("Failed to update instance:",n),null}},[y,i?.id]),L=r.useCallback(async h=>{f(null);try{await E.aiApi.instances.delete(h),await y(),i?.id===h&&a(null)}catch(c){const n=c instanceof Error?c.message:"Failed to delete instance";f(n),console.error("Failed to delete instance:",c)}},[y,i?.id]),j=r.useCallback(async h=>{f(null);try{await E.aiApi.instances.toggleActive(h),await y(),i?.id===h&&await x(h)}catch(c){const n=c instanceof Error?c.message:"Failed to toggle instance";f(n),console.error("Failed to toggle instance:",c)}},[y,i?.id,x]),P=r.useCallback(async(h,c)=>{f(null);try{const n={value:c};await E.aiApi.instances.setApiKey(h,n),i?.id===h&&await x(h)}catch(n){const N=n instanceof Error?n.message:"Failed to set API key";f(N),console.error("Failed to set API key:",n)}},[i?.id,x]),u=r.useCallback(async(h,c)=>{f(null);try{const n={value:c};await E.aiApi.instances.setAdminKey(h,n),i?.id===h&&await x(h)}catch(n){const N=n instanceof Error?n.message:"Failed to set admin key";f(N),console.error("Failed to set admin key:",n)}},[i?.id,x]),A=r.useCallback(h=>{a(h),f(null)},[]),F=r.useCallback(()=>{f(null)},[]);return{instances:s,selectedInstance:i,loading:d,error:b,loadInstances:y,loadInstanceDetail:x,refreshInstance:p,createInstance:k,updateInstance:T,deleteInstance:L,toggleInstanceActive:j,setApiKey:P,setAdminKey:u,selectInstance:A,clearError:F}}function We(){const[s,l]=r.useState([]),[i,a]=r.useState(!1),[d,g]=r.useState(null),b=r.useCallback(x=>{g(x)},[]),f=r.useCallback(async()=>{a(!0),b(null);try{const x=await E.aiApi.settings.getProviders();l(x??[])}catch(x){const p=x instanceof Error?x.message:"Failed to load providers";b(p),console.error("Failed to load providers:",x)}finally{a(!1)}},[b]),y=r.useCallback(()=>{b(null)},[b]);return{providers:s,loading:i,error:d,loadProviders:f,clearError:y}}function Xe(){const[s,l]=r.useState([]),[i,a]=r.useState({}),[d,g]=r.useState(!1),[b,f]=r.useState(null),y=r.useCallback(j=>{f(j)},[]),x=r.useCallback(async(j,P)=>{g(!0),y(null);try{const u=await E.aiApi.settings.getModels(j,P);l(u??[])}catch(u){const A=u instanceof Error?u.message:"Failed to load models";y(A),console.error("Failed to load models:",u)}finally{g(!1)}},[y]),p=r.useCallback(async j=>{a(j),await x(j.category,j.providerId)},[x]),k=r.useCallback(async()=>{a({}),await x()},[x]),T=r.useCallback(()=>{y(null)},[y]),L=r.useMemo(()=>{let j=s;return i.providerId&&(j=j.filter(P=>P.providerId===i.providerId)),i.category&&(j=j.filter(P=>P.category===i.category)),j},[s,i]);return{models:s,filteredModels:L,modelFilter:i,loading:d,error:b,loadModels:x,setModelFilter:p,clearFilters:k,clearError:T}}function Je(){const[s,l]=r.useState([]),[i,a]=r.useState(!1),d=r.useCallback(()=>a(!0),[]),g=r.useCallback(()=>a(!1),[]),b=r.useCallback(async(x,p)=>{try{await E.aiApi.instances.addTenant(x,{tenantId:p})}catch(k){throw console.error("Failed to add tenant:",k),k}},[]),f=r.useCallback(async(x,p)=>{try{await E.aiApi.instances.removeTenant(x,p),l(k=>k.filter(T=>T.tenantId!==p))}catch(k){throw console.error("Failed to remove tenant:",k),k}},[]),y=r.useCallback(x=>{x&&l(x)},[]);return{tenants:s,showAddTenantModal:i,openAddTenantModal:d,closeAddTenantModal:g,addTenant:b,removeTenant:f,loadAccessData:y}}const He=["profiles","providers","models"];function Ye(){const{t:s}=Y.useTranslation(["ai"]),{activeTab:l,setActiveTab:i}=ke.useTabNavigation("profiles",He),a=_e(),d=We(),g=Xe(),b=Je(),[f,y]=r.useState(!1),[x,p]=r.useState({name:"",code:"",providerId:""}),[k,T]=r.useState(!1),[L,j]=r.useState({show:!1,instanceId:null});r.useEffect(()=>{(async()=>await Promise.all([a.loadInstances(),d.loadProviders(),g.loadModels()]))()},[]),r.useEffect(()=>{if(a.selectedInstance){const{tenants:o}=a.selectedInstance;b.loadAccessData(o)}},[a.selectedInstance]);const P=async o=>{await a.loadInstanceDetail(o)},u=o=>{j({show:!0,instanceId:o})},A=async()=>{L.instanceId&&(await a.deleteInstance(L.instanceId),j({show:!1,instanceId:null}))},F=async o=>{await a.toggleInstanceActive(o)},h=async()=>{try{await a.createInstance(x)&&(y(!1),p({name:"",code:"",providerId:""}))}catch(o){console.error("Failed to create instance:",o)}},c=async o=>{a.selectedInstance&&await a.updateInstance(a.selectedInstance.id,o)},n=async()=>{if(x.providerId){T(!0);try{const o=await E.aiApi.instances.generateCode(x.providerId);p({...x,code:o.code})}catch(o){console.error("Failed to generate code:",o)}finally{T(!1)}}};return(a.loading||d.loading||g.loading)&&!a.instances.length?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-600)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("settings.title","Settings")}]}),a.error&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:a.error})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Settings,{className:"w-6 h-6"}),s("settings.title")]}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] mt-1",children:s("settings.description")})]})}),l==="profiles"&&e.jsxs("button",{onClick:()=>{p({name:"",code:"",providerId:""}),y(!0)},className:"btn btn-primary",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("settings.profiles.createButton")]})]}),e.jsx("div",{className:"border-b border-[var(--border-color)]",children:e.jsx("div",{className:"flex gap-8",children:["profiles","providers","models"].map(o=>e.jsx("button",{onClick:()=>i(o),className:`pb-4 px-1 border-b-2 transition-colors ${l===o?"border-[var(--color-accent-600)] text-[var(--text-primary)] font-medium":"border-transparent text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,children:s(`settings.tabs.${o}`)},o))})}),e.jsxs("div",{children:[l==="profiles"&&e.jsx(Ve,{instances:a.instances,selectedInstance:a.selectedInstance,onSelectInstance:P,onToggleActive:F,onDelete:u,onUpdate:c,models:g.models,onSetApiKey:async o=>{a.selectedInstance&&await a.setApiKey(a.selectedInstance.id,o)},onSetAdminKey:async o=>{a.selectedInstance&&await a.setAdminKey(a.selectedInstance.id,o)},providerApiKeyUrl:d.providers.find(o=>o.id===a.selectedInstance?.providerId)?.apiKeyUrl,providerAdminApiKeyUrl:d.providers.find(o=>o.id===a.selectedInstance?.providerId)?.adminApiKeyUrl,onAddTenant:async o=>{a.selectedInstance&&(await b.addTenant(a.selectedInstance.id,o),await a.loadInstanceDetail(a.selectedInstance.id))},onRemoveTenant:async o=>{a.selectedInstance&&(await b.removeTenant(a.selectedInstance.id,o),await a.loadInstanceDetail(a.selectedInstance.id))},onSetAllTenants:async o=>{a.selectedInstance&&(await E.aiApi.instances.setAllTenants(a.selectedInstance.id,{isAllTenants:o}),await a.loadInstanceDetail(a.selectedInstance.id))},onAddPrompt:async o=>{a.selectedInstance&&(await E.aiApi.instances.addSkill(a.selectedInstance.id,{skillId:o}),await a.loadInstanceDetail(a.selectedInstance.id))},onRemovePrompt:async o=>{a.selectedInstance&&(await E.aiApi.instances.removeSkill(a.selectedInstance.id,o),await a.loadInstanceDetail(a.selectedInstance.id))}}),l==="providers"&&e.jsx(Ue,{providers:d.providers}),l==="models"&&e.jsx(Ge,{models:g.filteredModels,providers:d.providers,filter:g.modelFilter,onFilterChange:o=>g.setModelFilter(o)})]}),f&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",role:"dialog","aria-modal":"true",onKeyDown:o=>{o.key==="Escape"&&y(!1)},children:e.jsxs("div",{className:"bg-[var(--bg-primary)] rounded-lg shadow-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-[var(--border-color)]",children:[e.jsx("h2",{className:"text-xl font-bold",children:s("settings.profiles.createTitle")}),e.jsx("button",{onClick:()=>y(!1),className:"text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(t.X,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("settings.profiles.fields.name")}),e.jsx("input",{type:"text",value:x.name,onChange:o=>p({...x,name:o.target.value}),placeholder:s("settings.profiles.fields.namePlaceholder"),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("settings.profiles.fields.provider")}),e.jsxs("select",{value:x.providerId,onChange:o=>p({...x,providerId:o.target.value,defaultModel:void 0}),className:"input w-full",children:[e.jsx("option",{value:"",children:s("settings.profiles.fields.selectProvider")}),d.providers.map(o=>e.jsx("option",{value:o.id,children:o.name},o.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("settings.profiles.fields.defaultModel")}),e.jsxs("select",{value:x.defaultModel||"",onChange:o=>p({...x,defaultModel:o.target.value||void 0}),className:"input w-full",disabled:!x.providerId,children:[e.jsx("option",{value:"",children:s("settings.profiles.fields.defaultModelPlaceholder")}),g.models.filter(o=>o.providerId===x.providerId).map(o=>e.jsx("option",{value:o.code,children:o.name},o.id))]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",children:[s("settings.profiles.fields.code"),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] ml-2",children:["(",s("settings.profiles.fields.autoGenerated"),")"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:k?"...":x.code||"",readOnly:!0,className:"input w-full bg-[var(--bg-secondary)] font-mono text-sm",placeholder:s("settings.profiles.fields.codePlaceholder")}),e.jsx("button",{onClick:n,disabled:!x.providerId||k,className:"btn btn-secondary btn-sm",children:k?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):s("settings.profiles.fields.generate")})]})]})]}),e.jsxs("div",{className:"flex gap-3 justify-end p-6 border-t border-[var(--border-color)]",children:[e.jsx("button",{onClick:()=>y(!1),className:"btn btn-secondary",children:s("common:cancel")}),e.jsx("button",{onClick:h,disabled:!x.name.trim()||!x.providerId,className:"btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed",children:s("common:save")})]})]})}),e.jsx(De.ConfirmModal,{isOpen:L.show,title:s("settings.profiles.actions.delete"),message:s("settings.profiles.confirmDelete"),variant:"danger",confirmLabel:s("common:delete"),onConfirm:A,onCancel:()=>j({show:!1,instanceId:null})})]})}function Ce({prompt:s,onClose:l}){const{t:i}=Y.useTranslation(["ai"]),[a,d]=r.useState({}),[g,b]=r.useState([]),[f,y]=r.useState([]),[x,p]=r.useState(""),[k,T]=r.useState(""),[L,j]=r.useState(!1),[P,u]=r.useState(null),[A,F]=r.useState(null),[h,c]=r.useState(!1),[n,N]=r.useState(!1);r.useEffect(()=>{const v={};s.variables.forEach(O=>{v[O]=""}),d(v)},[s.variables]),r.useEffect(()=>{(async()=>{try{const W=(await E.aiApi.settings.getProviders()??[]).filter(m=>m.isActive);b(W)}catch(O){console.error("Failed to load providers:",O)}})()},[]),r.useEffect(()=>{(async()=>{if(!x){y([]);return}try{const W=(await E.aiApi.settings.getModels(void 0,x)??[]).filter(m=>m.isActive&&!m.isDeprecated);y(W),W.length>0&&T(W[0].id)}catch(O){console.error("Failed to load models:",O)}})()},[x]);const o=async()=>{j(!0),F(null),u(null);try{const v=await E.aiApi.skills.execute(s.id,{variables:Object.keys(a).length>0?a:void 0,providerId:x||void 0,modelId:k||void 0});v&&(u(v),!v.success&&v.error&&F(v.error))}catch(v){console.error("Failed to execute prompt:",v);const O=v instanceof Error?v.message:"Une erreur est survenue";F(O)}finally{j(!1)}},_=async()=>{P?.response&&(await navigator.clipboard.writeText(P.response),N(!0),setTimeout(()=>N(!1),2e3))},C=()=>s.blocks.sort((v,O)=>v.displayOrder-O.displayOrder).filter(v=>v.isEnabled).map(v=>{let O=v.content;return Object.entries(a).forEach(([W,m])=>{O=O.replace(new RegExp(`\\{${W}\\}`,"g"),m||`{${W}}`)}),`# ${v.label}
2
2
  ${O}`}).join(`
3
3
 
4
4
  `);return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-[var(--bg-primary)] rounded-lg shadow-xl w-full max-w-4xl p-6 max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(t.Play,{className:"w-5 h-5 text-[var(--color-primary-600)]"}),i("skills.test.title")]}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:s.name})]}),e.jsx("button",{onClick:l,className:"text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(t.X,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-4",children:[s.variables.length>0&&e.jsxs("div",{className:"p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:i("skills.test.variables")}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:s.variables.map(v=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-[var(--text-secondary)] mb-1 font-mono",children:`{${v}}`}),e.jsx("input",{type:"text",value:a[v]||"",onChange:O=>d({...a,[v]:O.target.value}),className:"input w-full text-sm",placeholder:i("skills.test.enterValue")})]},v))})]}),e.jsxs("div",{className:"p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:i("skills.test.configuration")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-[var(--text-secondary)] mb-1",children:i("skills.test.provider")}),e.jsxs("select",{value:x,onChange:v=>{p(v.target.value),T("")},className:"input w-full text-sm",children:[e.jsx("option",{value:"",children:i("skills.test.defaultProvider")}),g.map(v=>e.jsx("option",{value:v.id,children:v.name},v.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-[var(--text-secondary)] mb-1",children:i("skills.test.model")}),e.jsxs("select",{value:k,onChange:v=>T(v.target.value),className:"input w-full text-sm",disabled:!x,children:[e.jsx("option",{value:"",children:i("skills.test.defaultModel")}),f.map(v=>e.jsx("option",{value:v.id,children:v.name},v.id))]})]})]})]}),e.jsxs("div",{className:"p-4 border border-[var(--border-color)] rounded-lg",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:i("skills.test.promptPreview")}),e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs bg-[var(--bg-secondary)] p-3 rounded max-h-40 overflow-y-auto",children:C()||i("skills.test.noContent")})]}),e.jsx("div",{className:"flex justify-center",children:e.jsxs("button",{onClick:o,disabled:L,className:"btn btn-primary flex items-center gap-2 px-8",children:[L?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsx(t.Play,{className:"w-4 h-4"}),i(L?"skills.test.executing":"skills.test.execute")]})}),A&&e.jsxs("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-800 dark:text-red-200",children:[e.jsx(t.XCircle,{className:"w-5 h-5 flex-shrink-0"}),e.jsx("span",{className:"font-medium",children:i("skills.test.error")})]}),e.jsx("p",{className:"mt-2 text-sm text-red-700 dark:text-red-300",children:A})]}),P?.success&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-800 dark:text-green-200",children:[e.jsx(t.CheckCircle,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium",children:i("skills.test.success")})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-green-700 dark:text-green-300",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(t.Clock,{className:"w-4 h-4"}),P.latencyMs,"ms"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(t.Coins,{className:"w-4 h-4"}),P.totalTokens," tokens"]})]})]}),e.jsxs("div",{className:"p-4 border border-[var(--border-color)] rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:i("skills.test.response")}),e.jsxs("button",{onClick:_,className:"btn btn-secondary btn-sm flex items-center gap-1",children:[n?e.jsx(t.Check,{className:"w-3 h-3"}):e.jsx(t.Copy,{className:"w-3 h-3"}),i(n?"skills.test.copied":"skills.test.copy")]})]}),e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm bg-[var(--bg-secondary)] p-3 rounded max-h-60 overflow-y-auto",children:P.response})]}),e.jsxs("button",{onClick:()=>c(!h),className:"w-full flex items-center justify-center gap-2 text-sm text-[var(--text-secondary)] hover:text-[var(--text-primary)] py-2",children:[h?e.jsx(t.ChevronUp,{className:"w-4 h-4"}):e.jsx(t.ChevronDown,{className:"w-4 h-4"}),i("skills.test.debugInfo")]}),h&&e.jsx("div",{className:"p-4 bg-[var(--bg-secondary)] rounded-lg",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-secondary)]",children:[i("skills.test.inputTokens"),":"]}),e.jsx("span",{className:"ml-2 font-mono",children:P.inputTokens})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-secondary)]",children:[i("skills.test.outputTokens"),":"]}),e.jsx("span",{className:"ml-2 font-mono",children:P.outputTokens})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-secondary)]",children:[i("skills.test.totalTokens"),":"]}),e.jsx("span",{className:"ml-2 font-mono",children:P.totalTokens})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-secondary)]",children:[i("skills.test.latency"),":"]}),e.jsxs("span",{className:"ml-2 font-mono",children:[P.latencyMs,"ms"]})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-secondary)]",children:[i("skills.test.modelUsed"),":"]}),e.jsx("span",{className:"ml-2 font-mono",children:P.modelName})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-secondary)]",children:[i("skills.test.promptId"),":"]}),e.jsx("span",{className:"ml-2 font-mono text-xs",children:P.skillId})]})]})})]})]}),e.jsx("div",{className:"flex justify-end gap-2 pt-4 mt-4 border-t border-[var(--border-color)]",children:e.jsx("button",{onClick:l,className:"btn btn-secondary",children:i("common.close")})})]})})}const ge={Draft:"inactive",Active:"active",Deprecated:"warning"};function Se(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),{currentTenant:i,isGlobalView:a}=J.useTenant(),[d,g]=r.useState([]),[b,f]=r.useState(!0),[y,x]=r.useState(null),[p,k]=r.useState(""),[T,L]=r.useState(""),[j,P]=r.useState(""),[u,A]=r.useState("table"),[F,h]=r.useState(1),c=20,n=r.useCallback(async()=>{try{x(null),f(!0);const w={};p&&(w.search=p),T&&(w.category=T),j&&(w.status=j);const q=await E.aiApi.skills.getAll(w);g(q??[])}catch(w){console.error("Failed to load prompts:",w),x(s("skills.messages.loadFailed"))}finally{f(!1)}},[p,T,j,s,i?.id,a]);r.useEffect(()=>{n()},[n]);const N=async(w,q)=>{if(q.stopPropagation(),!!confirm(s("skills.confirmDelete")))try{await E.aiApi.skills.delete(w.id),await n()}catch(B){console.error("Failed to delete prompt:",B)}},o=async(w,q)=>{q.stopPropagation();try{const B=await E.aiApi.skills.clone(w.id);await n(),B&&l(`/administration/ai/skills/${B.id}/edit`)}catch(B){console.error("Failed to clone prompt:",B)}},_=async(w,q)=>{q.stopPropagation();try{await E.aiApi.skills.activate(w.id),await n()}catch(B){console.error("Failed to activate prompt:",B)}},C=async(w,q)=>{q.stopPropagation();try{await E.aiApi.skills.deprecate(w.id),await n()}catch(B){console.error("Failed to deprecate prompt:",B)}},v=Array.from(new Set(d.map(w=>w.tags).filter(w=>!!w))),O=d,W=(F-1)*c,m=O.slice(W,W+c),D=()=>e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-[var(--bg-secondary)] border-b border-[var(--border-color)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)]"})}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("skills.list.columns.name")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("skills.list.columns.category")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("skills.list.columns.version")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("skills.list.columns.blocks")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("skills.list.columns.status")}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("skills.list.columns.actions")})]})}),e.jsxs("tbody",{className:"divide-y divide-[var(--border-color)]",children:[b&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-12 text-center",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin mx-auto text-[var(--color-primary-600)]"})})}),!b&&m.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-12 text-center text-[var(--text-secondary)]",children:s("skills.list.noSkills")})}),!b&&m.length>0&&m.map(w=>e.jsxs("tr",{className:"group hover:bg-[var(--bg-hover)] transition-all cursor-pointer",onClick:()=>l(`/administration/ai/skills/${w.id}`),children:[e.jsx("td",{className:"px-4 py-3",onClick:q=>q.stopPropagation(),children:e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)]"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.FileText,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("div",{children:e.jsx("p",{className:"font-medium text-[var(--text-primary)]",children:w.name})})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[e.jsx(t.Tag,{className:"w-3 h-3"}),w.tags||"-"]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"text-sm text-[var(--text-secondary)]",children:["v",w.version]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-sm text-[var(--text-secondary)]",children:[e.jsx(t.Blocks,{className:"w-3.5 h-3.5"}),w.blockCount]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(J.StatusBadge,{status:ge[w.status]||"inactive",label:s(`skills.status.${w.status}`)})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:q=>q.stopPropagation(),children:[e.jsx("button",{onClick:()=>l(`/administration/ai/skills/${w.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("skills.actions.view"),children:e.jsx(t.Eye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>l(`/administration/ai/skills/${w.id}/edit`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)] transition-all",title:s("skills.actions.edit"),children:e.jsx(t.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:q=>o(w,q),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)] transition-all",title:s("skills.actions.clone"),children:e.jsx(t.Copy,{className:"w-4 h-4"})}),w.status==="Draft"&&e.jsx("button",{onClick:q=>_(w,q),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--success-text)] hover:bg-[var(--success-bg)] transition-all",title:s("skills.actions.activate"),children:e.jsx(t.CheckCircle,{className:"w-4 h-4"})}),w.status==="Active"&&e.jsx("button",{onClick:q=>C(w,q),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--warning-text)] hover:bg-[var(--warning-bg)] transition-all",title:s("skills.actions.deprecate"),children:e.jsx(t.XCircle,{className:"w-4 h-4"})}),e.jsx("button",{onClick:q=>N(w,q),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",title:s("skills.actions.delete"),children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})})]},w.id))]})]})}),K=()=>e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[b&&e.jsx("div",{className:"col-span-full flex items-center justify-center py-16",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-500)]"})}),!b&&m.length===0&&e.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg bg-[var(--color-accent-50)] flex items-center justify-center mb-3",children:e.jsx(t.FileText,{className:"w-8 h-8 text-[var(--color-accent-500)]"})}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s("skills.list.noSkills")})]}),!b&&m.length>0&&m.map(w=>e.jsxs("button",{onClick:()=>l(`/administration/ai/skills/${w.id}`),className:"bg-[var(--bg-card)] border-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)] rounded-[var(--radius-card)] overflow-hidden transition-all hover:shadow-lg hover:border-[var(--color-accent-400)] cursor-pointer flex flex-col text-left",children:[e.jsx("div",{className:"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 p-4 border-b border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-[var(--color-accent-500)] flex items-center justify-center shadow-lg",children:e.jsx(t.FileText,{className:"w-5 h-5 text-white"})}),e.jsx("div",{children:e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] truncate",children:w.name})})]}),e.jsx(J.StatusBadge,{status:ge[w.status]||"inactive",label:s(`skills.status.${w.status}`),size:"sm"})]})}),e.jsxs("div",{className:"p-4 flex flex-col flex-1",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[e.jsx(t.Tag,{className:"w-3 h-3"}),w.tags||"-"]}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[e.jsx(t.Blocks,{className:"w-3 h-3"}),w.blockCount," blocs"]}),e.jsxs("span",{className:"px-2 py-1 rounded-full text-xs bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:["v",w.version]})]}),e.jsx("div",{className:"flex-1 min-h-4"}),e.jsxs("div",{className:"flex items-center justify-end gap-1 mt-3 pt-3 border-t border-[var(--border-color)]",onClick:q=>q.stopPropagation(),children:[e.jsx("button",{onClick:()=>l(`/administration/ai/skills/${w.id}/edit`),className:"p-1.5 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--color-accent-600)] hover:bg-[var(--color-accent-50)] transition-all",title:s("skills.actions.edit"),children:e.jsx(t.Edit2,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:q=>o(w,q),className:"p-1.5 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--color-accent-600)] hover:bg-[var(--color-accent-50)] transition-all",title:s("skills.actions.clone"),children:e.jsx(t.Copy,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:q=>N(w,q),className:"p-1.5 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",title:s("skills.actions.delete"),children:e.jsx(t.Trash2,{className:"w-3.5 h-3.5"})})]})]})]},w.id))]});return e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("skills.title")}]}),y&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:y})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.FileText,{className:"w-6 h-6"}),s("skills.title")]}),e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)] mt-1",children:[d.length," ",s("skills.list.skillsCount")]})]}),e.jsxs("button",{onClick:()=>l("/administration/ai/skills/create"),className:"btn btn-primary",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("skills.createSkill")]})]}),e.jsx("div",{className:"card p-4",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 flex-1",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(t.Search,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("input",{type:"text",value:p,onChange:w=>k(w.target.value),placeholder:s("skills.search"),className:"input pl-10 w-full"})]}),e.jsxs("select",{value:T,onChange:w=>L(w.target.value),className:"input",children:[e.jsx("option",{value:"",children:s("skills.allCategories")}),v.map(w=>e.jsx("option",{value:w,children:w},w))]}),e.jsxs("select",{value:j,onChange:w=>P(w.target.value),className:"input",children:[e.jsx("option",{value:"",children:s("skills.allStatuses")}),e.jsx("option",{value:"Draft",children:s("skills.status.Draft")}),e.jsx("option",{value:"Active",children:s("skills.status.Active")}),e.jsx("option",{value:"Deprecated",children:s("skills.status.Deprecated")})]})]}),e.jsx(J.ViewToggle,{viewMode:u,onChange:A,showKanban:!1,tableLabel:s("skills.list.tableView"),cardsLabel:s("skills.list.cardsView")})]})}),u==="table"&&D(),u==="cards"&&K(),!b&&O.length>c&&e.jsx(J.Pagination,{page:F,totalPages:Math.ceil(O.length/c),totalCount:O.length,pageSize:c,onPageChange:h,itemLabel:"skills"})]})}const ve={System:"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-400 border-purple-200 dark:border-purple-800",Context:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400 border-blue-200 dark:border-blue-800",Task:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400 border-green-200 dark:border-green-800",Output:"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-400 border-orange-200 dark:border-orange-800",Examples:"bg-cyan-100 text-cyan-800 dark:bg-cyan-900/30 dark:text-cyan-400 border-cyan-200 dark:border-cyan-800",Validation:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400 border-red-200 dark:border-red-800"},Ze={Draft:"inactive",Active:"active",Deprecated:"warning"};function Qe(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),{id:i}=Z.useParams(),[a,d]=r.useState(null),[g,b]=r.useState(!0),[f,y]=r.useState(null),[x,p]=r.useState(!1),[k,T]=r.useState(!1),[L,j]=r.useState({}),P=r.useCallback(async()=>{if(i)try{y(null),b(!0);const n=await E.aiApi.skills.getById(i);if(d(n??null),n?.variables){const N={};n.variables.forEach(o=>{N[o]=""}),j(N)}}catch(n){console.error("Failed to load skill:",n),y(s("skills.messages.loadFailed"))}finally{b(!1)}},[i,s]);r.useEffect(()=>{P()},[P]);const u=async()=>{if(!(!a||!confirm(s("skills.confirmDelete",{name:a.name}))))try{await E.aiApi.skills.delete(a.id),l("/administration/ai/skills")}catch(n){console.error("Failed to delete skill:",n)}},A=async()=>{if(a)try{const n=await E.aiApi.skills.clone(a.id);n&&l(`/administration/ai/skills/${n.id}/edit`)}catch(n){console.error("Failed to clone skill:",n)}},F=async()=>{if(a)try{await E.aiApi.skills.activate(a.id),await P()}catch(n){console.error("Failed to activate skill:",n)}},h=async()=>{if(a)try{await E.aiApi.skills.deprecate(a.id),await P()}catch(n){console.error("Failed to deprecate skill:",n)}},c=()=>a?a.blocks.sort((n,N)=>n.displayOrder-N.displayOrder).filter(n=>n.isEnabled).map(n=>{let N=n.content;return Object.entries(L).forEach(([o,_])=>{N=N.replace(new RegExp(`\\{${o}\\}`,"g"),_||`{${o}}`)}),`## ${n.label}
@@ -8,4 +8,4 @@ ${N}`}).join(`
8
8
  ${z}`}).join(`
9
9
 
10
10
  `);return d?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("skills.title"),href:"/administration/ai/skills"},{label:a?s("common:create"):u?.name||"Edit"}]}),y&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:y})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>l(a?"/administration/ai/skills":`/administration/ai/skills/${i}`),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("common.back")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!a&&u&&e.jsxs("button",{onClick:()=>O(!0),className:"btn btn-secondary flex items-center gap-2",children:[e.jsx(t.Play,{className:"w-4 h-4"}),s("skills.test.title")]}),e.jsxs("button",{onClick:I,disabled:b||!p||!j,className:"btn btn-primary flex items-center gap-2",children:[b?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsx(t.Save,{className:"w-4 h-4"}),s("common.save")]})]})]}),e.jsxs("div",{className:"flex items-center gap-4 mb-2",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gradient-to-br from-violet-500 to-purple-500 flex items-center justify-center shadow-lg",children:e.jsx(t.FileText,{className:"w-6 h-6 text-white"})}),e.jsx("div",{className:"flex-1",children:e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s(a?"skills.createSkill":"skills.builder.editTitle")})}),e.jsxs("button",{onClick:()=>K(!D),className:`btn btn-secondary flex items-center gap-2 ${D?"bg-[var(--bg-secondary)]":""}`,children:[e.jsx(t.Settings,{className:"w-4 h-4"}),s("skills.builder.settings")]})]}),D&&e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"font-semibold mb-4",children:s("skills.builder.skillInfo")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",children:[s("skills.list.columns.name")," *"]}),e.jsx("input",{type:"text",value:p,onChange:$=>k($.target.value),className:"input w-full",required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",children:[s("skills.list.columns.category")," *"]}),e.jsx("input",{type:"text",value:j,onChange:$=>P($.target.value),className:"input w-full",required:!0})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("skills.detail.description")}),e.jsx("textarea",{value:T,onChange:$=>L($.target.value),className:"input w-full",rows:2})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-5 gap-6",children:[e.jsxs("div",{className:"lg:col-span-3 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Blocks,{className:"w-5 h-5"}),s("skills.blocks.title")," (",F.length,")"]}),e.jsxs("button",{onClick:()=>o(!0),className:"btn btn-primary btn-sm flex items-center gap-1",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("skills.blocks.addBlock")]})]}),F.length>0?e.jsx("div",{className:"space-y-3",children:F.map(($,z)=>e.jsx(as,{block:$,index:z,isFirst:z===0,isLast:z===F.length-1,isEditing:_===$.id,onEdit:()=>C($.id),onCancelEdit:()=>C(null),onSave:X=>V($.id,X),onDelete:()=>U($.id),onMoveUp:()=>H($.id,"up"),onMoveDown:()=>H($.id,"down"),t:s},$.id))}):e.jsxs("div",{className:"card p-8 text-center border-2 border-dashed border-[var(--border-color)]",children:[e.jsx(t.Blocks,{className:"w-12 h-12 mx-auto mb-4 text-[var(--text-tertiary)]"}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:s("skills.blocks.noBlocks")}),e.jsxs("button",{onClick:()=>o(!0),className:"btn btn-primary",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("skills.blocks.addFirstBlock")]})]})]}),e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"card p-6 sticky top-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Eye,{className:"w-5 h-5"}),s("skills.editor.preview")]})}),S.length>0&&e.jsxs("div",{className:"mb-4 p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:s("skills.test.variables")}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:S.map($=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-[var(--text-tertiary)] mb-1",children:`{${$}}`}),e.jsx("input",{type:"text",value:W[$]||"",onChange:z=>m({...W,[$]:z.target.value}),className:"input w-full text-sm",placeholder:s("skills.test.enterValue")})]},$))})]}),e.jsx("div",{className:"border border-[var(--border-color)] rounded-lg p-4 bg-[var(--bg-secondary)] max-h-[500px] overflow-y-auto",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm text-[var(--text-primary)]",children:Q()||s("skills.blocks.noBlocks")})})]})})]}),N&&e.jsx(rs,{definitions:c,existingBlocksCount:F.length,onClose:()=>o(!1),onAdd:R,t:s}),v&&u&&e.jsx(Ce,{prompt:u,onClose:()=>O(!1)})]})}function as({block:s,index:l,isFirst:i,isLast:a,isEditing:d,onEdit:g,onCancelEdit:b,onSave:f,onDelete:y,onMoveUp:x,onMoveDown:p,t:k}){const[T,L]=r.useState(s.label??""),[j,P]=r.useState(s.content),[u,A]=r.useState(s.blockType),[F,h]=r.useState(s.isEnabled);r.useEffect(()=>{L(s.label||""),P(s.content),A(s.blockType),h(s.isEnabled)},[s]);const c=()=>{f({label:T||void 0,content:j,isEnabled:F})};return d?e.jsx("div",{className:`card border-l-4 ${be[u]} p-4`,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:k("skills.editor.title")}),e.jsx("input",{type:"text",value:T,onChange:n=>L(n.target.value),className:"input w-full"})]}),e.jsxs("div",{className:"w-40",children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:k("skills.blocks.type")}),e.jsx("select",{value:u,onChange:n=>A(n.target.value),className:"input w-full",children:Ae.map(n=>e.jsx("option",{value:n,children:k(`skills.blocks.types.${n}`)},n))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:k("skills.editor.content")}),e.jsx("textarea",{value:j,onChange:n=>P(n.target.value),className:"input w-full font-mono text-sm",rows:6}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] mt-1",children:k("skills.editor.variableFormat")})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:F,onChange:n=>h(n.target.checked),className:"rounded"}),k("skills.blocks.active")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:b,className:"btn btn-secondary btn-sm",children:k("common.cancel")}),e.jsx("button",{onClick:c,className:"btn btn-primary btn-sm",children:k("common.save")})]})]})]})}):e.jsx("button",{type:"button",className:`card border-l-4 ${be[s.blockType]} p-4 cursor-pointer hover:shadow-md transition-shadow text-left w-full ${s.isEnabled?"":"opacity-60"}`,onClick:g,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("button",{onClick:n=>{n.stopPropagation(),x()},disabled:i,className:"p-1 rounded hover:bg-[var(--bg-secondary)] disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(t.ChevronUp,{className:"w-4 h-4"})}),e.jsx(t.GripVertical,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("button",{onClick:n=>{n.stopPropagation(),p()},disabled:a,className:"p-1 rounded hover:bg-[var(--bg-secondary)] disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(t.ChevronDown,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-[var(--bg-secondary)] flex items-center justify-center text-xs font-medium",children:l+1}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-medium ${ss[s.blockType]}`,children:k(`skills.blocks.types.${s.blockType}`)}),e.jsx("span",{className:"font-medium truncate",children:s.label}),!s.isEnabled&&e.jsx("span",{className:"text-xs text-orange-600 bg-orange-100 dark:bg-orange-900/30 px-2 py-0.5 rounded",children:k("skills.blocks.inactive")})]}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] line-clamp-2 font-mono",children:s.content}),(s.variables?.length??0)>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:s.variables.map(n=>e.jsx("span",{className:"text-xs font-mono bg-[var(--bg-secondary)] px-1.5 py-0.5 rounded",children:`{${n}}`},n))})]}),e.jsx("button",{onClick:n=>{n.stopPropagation(),y()},className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})})}function rs({definitions:s,existingBlocksCount:l,onClose:i,onAdd:a,t:d}){const[g,b]=r.useState("custom"),[f,y]=r.useState(""),[x,p]=r.useState("Task"),[k,T]=r.useState(""),[L,j]=r.useState(""),P=async A=>{if(y(A),A)try{const F=await E.aiApi.blockDefinitions.getById(A);F&&(p(F.blockType),T(F.defaultTitle||""),j(F.defaultContent||""))}catch(F){console.error("Failed to load definition:",F)}},u=A=>{A.preventDefault(),a({blockDefinitionId:g==="definition"&&f?f:void 0,blockType:x,label:k,content:L,displayOrder:l+1})};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-[var(--bg-primary)] rounded-lg shadow-xl w-full max-w-lg p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:d("skills.blocks.addBlock")}),e.jsx("button",{onClick:i,className:"text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:e.jsx(t.X,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx("button",{type:"button",onClick:()=>b("custom"),className:`flex-1 py-2 px-4 rounded-lg border transition-colors ${g==="custom"?"border-[var(--color-primary-500)] bg-[var(--color-primary-50)] dark:bg-[var(--color-primary-900)]/20":"border-[var(--border-color)] hover:bg-[var(--bg-secondary)]"}`,children:d("skills.blocks.custom")}),e.jsx("button",{type:"button",onClick:()=>b("definition"),className:`flex-1 py-2 px-4 rounded-lg border transition-colors ${g==="definition"?"border-[var(--color-primary-500)] bg-[var(--color-primary-50)] dark:bg-[var(--color-primary-900)]/20":"border-[var(--border-color)] hover:bg-[var(--bg-secondary)]"}`,children:d("skills.blocks.fromDefinition")})]}),e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[g==="definition"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("skills.definitions.title")}),e.jsxs("select",{value:f,onChange:A=>P(A.target.value),className:"input w-full",children:[e.jsx("option",{value:"",children:d("skills.definitions.selectDefinition")}),s.map(A=>e.jsxs("option",{value:A.id,children:[A.name," (",d(`skills.blocks.types.${A.blockType}`),")"]},A.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("skills.blocks.type")}),e.jsx("select",{value:x,onChange:A=>p(A.target.value),className:"input w-full",children:Ae.map(A=>e.jsx("option",{value:A,children:d(`skills.blocks.types.${A}`)},A))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("skills.editor.title")}),e.jsx("input",{type:"text",value:k,onChange:A=>T(A.target.value),className:"input w-full",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:d("skills.editor.content")}),e.jsx("textarea",{value:L,onChange:A=>j(A.target.value),className:"input w-full font-mono text-sm",rows:6,required:!0}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] mt-1",children:d("skills.editor.variableFormat")})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx("button",{type:"button",onClick:i,className:"btn btn-secondary",children:d("common.cancel")}),e.jsx("button",{type:"submit",className:"btn btn-primary",children:d("common.create")})]})]})]})})}const oe={System:e.jsx(t.Shield,{className:"w-4 h-4"}),Context:e.jsx(t.FileText,{className:"w-4 h-4"}),Task:e.jsx(t.Target,{className:"w-4 h-4"}),Output:e.jsx(t.MessageSquare,{className:"w-4 h-4"}),Examples:e.jsx(t.ListChecks,{className:"w-4 h-4"}),Validation:e.jsx(t.Sparkles,{className:"w-4 h-4"})},fe={System:"from-red-500 to-rose-500",Context:"from-blue-500 to-cyan-500",Task:"from-amber-500 to-orange-500",Output:"from-green-500 to-emerald-500",Examples:"from-purple-500 to-violet-500",Validation:"from-pink-500 to-fuchsia-500"};function ls(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),[i,a]=r.useState([]),[d,g]=r.useState(!0),[b,f]=r.useState(null),[y,x]=r.useState(""),[p,k]=r.useState(""),[T,L]=r.useState("table"),[j,P]=r.useState(1),u=20,A=r.useCallback(async()=>{try{f(null),g(!0);const C={};y&&(C.search=y),p&&(C.blockType=p);const v=await E.aiApi.blockDefinitions.getAll(C);a(v??[])}catch(C){console.error("Failed to load block definitions:",C),f(s("definitions.messages.loadFailed"))}finally{g(!1)}},[y,p,s]);r.useEffect(()=>{A()},[A]);const F=async(C,v)=>{if(v.stopPropagation(),C.isSystem){alert(s("definitions.cannotDeleteSystem"));return}if(C.usageCount>0){alert(s("definitions.messages.cannotDeleteInUse",{count:C.usageCount}));return}if(confirm(s("definitions.confirmDelete",{name:C.name})))try{await E.aiApi.blockDefinitions.delete(C.id),await A()}catch(O){console.error("Failed to delete definition:",O)}},h=i.filter(C=>!(y&&!C.name.toLowerCase().includes(y.toLowerCase())||p&&C.blockType!==p)),c=(j-1)*u,n=h.slice(c,c+u),N=["System","Context","Task","Output","Examples","Validation"],o=()=>e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-[var(--bg-secondary)] border-b border-[var(--border-color)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("definitions.columns.name")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("definitions.columns.type")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("definitions.columns.description")}),e.jsx("th",{className:"px-4 py-3 text-center text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("definitions.columns.scope")}),e.jsx("th",{className:"px-4 py-3 text-center text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("definitions.columns.usage")}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("definitions.columns.actions")})]})}),e.jsxs("tbody",{className:"divide-y divide-[var(--border-color)]",children:[d&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-12 text-center",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin mx-auto text-[var(--color-primary-600)]"})})}),!d&&n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-12 text-center text-[var(--text-secondary)]",children:s("definitions.noDefinitions")})}),!d&&n.length>0&&n.map(C=>e.jsxs("tr",{className:"group hover:bg-[var(--bg-hover)] transition-all cursor-pointer",onClick:()=>l(`/administration/ai/skills/blocks/${C.id}`),children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg bg-gradient-to-br ${fe[C.blockType]||"from-gray-500 to-slate-500"} flex items-center justify-center text-white`,children:oe[C.blockType]||e.jsx(t.Blocks,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-[var(--text-primary)]",children:C.name}),C.isSystem&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-[var(--text-tertiary)]",children:[e.jsx(t.Lock,{className:"w-3 h-3"}),s("definitions.systemBadge")]})]})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[oe[C.blockType],s(`definitions.blockTypes.${C.blockType}`)]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("p",{className:"text-sm text-[var(--text-secondary)] truncate max-w-xs",children:C.description||"-"})}),e.jsx("td",{className:"px-4 py-3 text-center",children:C.isGlobal?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-[var(--success-text)]",children:[e.jsx(t.Globe,{className:"w-3.5 h-3.5"}),s("definitions.scope.global")]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-[var(--text-tertiary)]",children:[e.jsx(t.Lock,{className:"w-3.5 h-3.5"}),s("definitions.scope.restricted")]})}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx(J.StatusBadge,{status:C.usageCount>0?"active":"inactive",label:`${C.usageCount}`,size:"sm"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:v=>v.stopPropagation(),children:[e.jsx("button",{onClick:()=>l(`/administration/ai/skills/blocks/${C.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("definitions.actions.view"),children:e.jsx(t.Eye,{className:"w-4 h-4"})}),!C.isSystem&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>l(`/administration/ai/skills/blocks/${C.id}/edit`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)] transition-all",title:s("definitions.actions.edit"),children:e.jsx(t.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:v=>F(C,v),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",title:s("definitions.actions.delete"),disabled:C.usageCount>0,children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})]})})]},C.id))]})]})}),_=()=>e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[d&&e.jsx("div",{className:"col-span-full flex items-center justify-center py-16",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}),!d&&n.length===0&&e.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg bg-[var(--bg-secondary)] flex items-center justify-center mb-3",children:e.jsx(t.Blocks,{className:"w-8 h-8 text-[var(--text-tertiary)]"})}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s("definitions.noDefinitions")})]}),!d&&n.length>0&&n.map(C=>e.jsxs("button",{onClick:()=>l(`/administration/ai/skills/blocks/${C.id}`),className:"bg-[var(--bg-card)] border-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)] rounded-[var(--radius-card)] overflow-hidden transition-all hover:shadow-lg hover:border-[var(--color-accent-400)] cursor-pointer flex flex-col text-left",children:[e.jsx("div",{className:"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 p-4 border-b border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-lg bg-gradient-to-br ${fe[C.blockType]||"from-gray-500 to-slate-500"} flex items-center justify-center text-white shadow-lg`,children:oe[C.blockType]||e.jsx(t.Blocks,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--text-primary)] truncate",children:C.name}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-[var(--text-tertiary)]",children:[oe[C.blockType],s(`definitions.blockTypes.${C.blockType}`)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[C.isSystem&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-400",children:[e.jsx(t.Lock,{className:"w-3 h-3"}),s("definitions.systemBadge")]}),C.isGlobal?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",children:[e.jsx(t.Globe,{className:"w-3 h-3"}),s("definitions.scope.global")]}):e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400",children:e.jsx(t.Lock,{className:"w-3 h-3"})})]})]})}),e.jsxs("div",{className:"p-4 flex flex-col flex-1",children:[C.description&&e.jsx("p",{className:"text-sm text-[var(--text-secondary)] line-clamp-2 mb-3",children:C.description}),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-[var(--text-tertiary)] mb-3",children:e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-md bg-[var(--bg-secondary)]",children:s("definitions.usedIn",{count:C.usageCount})})}),e.jsxs("div",{className:"flex items-center justify-end gap-1 pt-3 border-t border-[var(--border-color)]",onClick:v=>v.stopPropagation(),children:[e.jsx("button",{onClick:()=>l(`/administration/ai/skills/blocks/${C.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("definitions.actions.view"),children:e.jsx(t.Eye,{className:"w-4 h-4"})}),!C.isSystem&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>l(`/administration/ai/skills/blocks/${C.id}/edit`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)] transition-all",title:s("definitions.actions.edit"),children:e.jsx(t.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:v=>F(C,v),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",title:s("definitions.actions.delete"),disabled:C.usageCount>0,children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})]})]})]},C.id))]});return e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("skills.title"),href:"/administration/ai/skills"},{label:s("definitions.title")}]}),b&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:b})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Blocks,{className:"w-6 h-6"}),s("definitions.title")]}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] mt-1",children:s("definitions.subtitle")})]}),e.jsxs("button",{onClick:()=>l("/administration/ai/skills/blocks/create"),className:"btn btn-primary",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("definitions.createDefinition")]})]}),e.jsx("div",{className:"card p-4",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 flex-1",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(t.Search,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("input",{type:"text",value:y,onChange:C=>x(C.target.value),placeholder:s("definitions.search"),className:"input pl-10 w-full"})]}),e.jsxs("select",{value:p,onChange:C=>k(C.target.value),className:"input",children:[e.jsx("option",{value:"",children:s("definitions.allTypes")}),N.map(C=>e.jsx("option",{value:C,children:s(`definitions.blockTypes.${C}`)},C))]})]}),e.jsx(J.ViewToggle,{viewMode:T,onChange:L,showKanban:!1,tableLabel:s("definitions.tableView"),cardsLabel:s("definitions.cardsView")})]})}),T==="table"&&o(),T==="cards"&&_(),!d&&h.length>u&&e.jsx(J.Pagination,{page:j,totalPages:Math.ceil(h.length/u),totalCount:h.length,pageSize:u,onPageChange:P,itemLabel:s("definitions.definitionsCount")})]})}const je={System:e.jsx(t.Shield,{className:"w-5 h-5"}),Context:e.jsx(t.FileText,{className:"w-5 h-5"}),Task:e.jsx(t.Target,{className:"w-5 h-5"}),Output:e.jsx(t.MessageSquare,{className:"w-5 h-5"}),Examples:e.jsx(t.ListChecks,{className:"w-5 h-5"}),Validation:e.jsx(t.Sparkles,{className:"w-5 h-5"})},is={System:"from-red-500 to-rose-500",Context:"from-blue-500 to-cyan-500",Task:"from-amber-500 to-orange-500",Output:"from-green-500 to-emerald-500",Examples:"from-purple-500 to-violet-500",Validation:"from-pink-500 to-fuchsia-500"};function ns(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),{id:i}=Z.useParams(),[a,d]=r.useState(null),[g,b]=r.useState(!0),[f,y]=r.useState(null);r.useEffect(()=>{(async()=>{if(i)try{y(null),b(!0);const k=await E.aiApi.blockDefinitions.getById(i);d(k)}catch(k){console.error("Failed to load block definition:",k),y(s("definitions.messages.loadFailed"))}finally{b(!1)}})()},[i,s]);const x=async()=>{if(a){if(a.isSystem){alert(s("definitions.cannotDeleteSystem"));return}if(confirm(s("definitions.confirmDelete",{name:a.name})))try{await E.aiApi.blockDefinitions.delete(a.id),l("/administration/ai/skills/blocks")}catch(p){console.error("Failed to delete definition:",p)}}};return g?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}):f||!a?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("button",{onClick:()=>l("/administration/ai/skills/blocks"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("definitions.backToList")]}),e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-6 text-center",children:[e.jsx(t.AlertTriangle,{className:"w-12 h-12 text-red-600 dark:text-red-400 mx-auto mb-3"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium",children:f||s("definitions.detail.notFound")})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("skills.title"),href:"/administration/ai/skills"},{label:s("definitions.title"),href:"/administration/ai/skills/blocks"},{label:a?.name||"Detail"}]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>l("/administration/ai/skills/blocks"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("definitions.backToList")]}),!a.isSystem&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>l(`/administration/ai/skills/blocks/${a.id}/edit`),className:"btn btn-secondary",children:[e.jsx(t.Edit2,{className:"w-4 h-4"}),s("common.edit")]}),e.jsxs("button",{onClick:x,className:"btn btn-danger",children:[e.jsx(t.Trash2,{className:"w-4 h-4"}),s("common.delete")]})]})]}),e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-start gap-6 mb-6",children:[e.jsx("div",{className:`w-16 h-16 rounded-xl bg-gradient-to-br ${is[a.blockType]||"from-gray-500 to-slate-500"} flex items-center justify-center text-white shadow-lg`,children:je[a.blockType]||e.jsx(t.Blocks,{className:"w-8 h-8"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:a.name}),a.isSystem&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-[var(--bg-secondary)] text-[var(--text-tertiary)]",children:[e.jsx(t.Lock,{className:"w-3 h-3"}),s("definitions.systemBadge")]}),a.isGlobal?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300",children:[e.jsx(t.Globe,{className:"w-3 h-3"}),s("definitions.scope.global")]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-[var(--bg-secondary)] text-[var(--text-tertiary)]",children:[e.jsx(t.Lock,{className:"w-3 h-3"}),s("definitions.scope.restricted")]})]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-sm font-medium bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[je[a.blockType],s(`definitions.blockTypes.${a.blockType}`)]})]})]}),a.description&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2",children:s("definitions.columns.description")}),e.jsx("p",{className:"text-[var(--text-primary)]",children:a.description})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6 pb-6 border-b border-[var(--border-color)]",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx(t.Code,{className:"w-5 h-5 text-[var(--text-tertiary)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-[var(--text-tertiary)]",children:s("definitions.fields.code")}),e.jsx("p",{className:"font-mono text-sm text-[var(--text-primary)]",children:a.code})]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx(t.Hash,{className:"w-5 h-5 text-[var(--text-tertiary)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-[var(--text-tertiary)]",children:s("definitions.fields.usageCount")}),e.jsx("p",{className:"font-semibold text-[var(--text-primary)]",children:a.usageCount??0})]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx(t.Calendar,{className:"w-5 h-5 text-[var(--text-tertiary)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-[var(--text-tertiary)]",children:s("skills.detail.createdAt")}),e.jsx("p",{className:"text-sm text-[var(--text-primary)]",children:a.createdAt?new Date(a.createdAt).toLocaleDateString():"-"})]})]}),e.jsx("div",{className:"flex items-center gap-3 p-3 bg-[var(--bg-secondary)] rounded-lg",children:a.isActive?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500"}),e.jsx("span",{className:"text-sm text-[var(--text-primary)]",children:s("skills.blocks.active")})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-gray-400"}),e.jsx("span",{className:"text-sm text-[var(--text-secondary)]",children:s("skills.blocks.inactive")})]})})]}),a.defaultTitle&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2",children:s("definitions.fields.defaultTitle")}),e.jsx("p",{className:"text-[var(--text-primary)] font-medium",children:a.defaultTitle})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2",children:s("definitions.fields.defaultContent")}),e.jsx("div",{className:"bg-[var(--bg-secondary)] rounded-lg p-4 font-mono text-sm whitespace-pre-wrap text-[var(--text-primary)] border border-[var(--border-color)]",children:a.defaultContent||s("common.noData")})]}),(a.variables?.length??0)>0&&e.jsxs("div",{className:"mt-6 pt-6 border-t border-[var(--border-color)]",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:s("skills.detail.variables")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.variables.map(p=>e.jsx("span",{className:"inline-flex items-center px-3 py-1.5 rounded-full text-xs font-mono bg-[var(--accent-bg)] text-[var(--accent-text)] border border-[var(--accent-border)]",children:`{${p}}`},p))})]})]})]})}const cs={System:e.jsx(t.Shield,{className:"w-4 h-4"}),Context:e.jsx(t.FileText,{className:"w-4 h-4"}),Task:e.jsx(t.Target,{className:"w-4 h-4"}),Output:e.jsx(t.MessageSquare,{className:"w-4 h-4"}),Examples:e.jsx(t.ListChecks,{className:"w-4 h-4"}),Validation:e.jsx(t.Sparkles,{className:"w-4 h-4"})},os=["System","Context","Task","Output","Examples","Validation"];function ds(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),{id:i}=Z.useParams(),a=!!i,[d,g]=r.useState(a),[b,f]=r.useState(!1),[y,x]=r.useState(null),[p,k]=r.useState(null),[T,L]=r.useState(!1),[j,P]=r.useState({code:"",name:"",description:"",blockType:"System",defaultTitle:"",defaultContent:"",isGlobal:!0});r.useEffect(()=>{if(!a)return;(async()=>{try{x(null),g(!0);const c=await E.aiApi.blockDefinitions.getById(i);k(c),P({code:c.code||"",name:c.name||"",description:c.description||"",blockType:c.blockType||"System",defaultTitle:c.defaultTitle||"",defaultContent:c.defaultContent||"",isGlobal:c.isGlobal??!0})}catch(c){console.error("Failed to load definition:",c),x(s("definitions.messages.loadFailed"))}finally{g(!1)}})()},[i,a,s]);const u=(h,c)=>{P(n=>({...n,[h]:c}))},A=async h=>{if(h.preventDefault(),!j.name.trim()||!j.defaultContent.trim()){x(s("definitions.errors.requiredFields"));return}try{x(null),f(!0),a?await E.aiApi.blockDefinitions.update(i,{name:j.name,description:j.description||void 0,defaultTitle:j.defaultTitle||void 0,defaultContent:j.defaultContent}):await E.aiApi.blockDefinitions.create({name:j.name,blockType:j.blockType,description:j.description||void 0,defaultTitle:j.defaultTitle||void 0,defaultContent:j.defaultContent}),l("/administration/ai/skills/blocks")}catch(c){console.error("Failed to save definition:",c),x(s("definitions.messages.saveFailed"))}finally{f(!1)}},F=(j.defaultContent.match(/\{([^}]+)\}/g)||[]).map(h=>h.replace(/[{}]/g,""));return d?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}):a&&p?.isSystem?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("button",{onClick:()=>l("/administration/ai/skills/blocks"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("definitions.backToList")]}),e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-6 text-center",children:[e.jsx(t.Lock,{className:"w-12 h-12 text-amber-600 dark:text-amber-400 mx-auto mb-3"}),e.jsx("p",{className:"text-amber-800 dark:text-amber-200 font-medium",children:s("definitions.cannotEditSystem")})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("skills.title"),href:"/administration/ai/skills"},{label:s("definitions.title"),href:"/administration/ai/skills/blocks"},{label:a?p?.name||"Edit":s("common:create")}]}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("button",{onClick:()=>l("/administration/ai/skills/blocks"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("definitions.backToList")]})}),y&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:y})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gradient-to-br from-violet-500 to-purple-500 flex items-center justify-center text-white shadow-lg",children:e.jsx(t.Blocks,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s(a?"definitions.edit.title":"definitions.create.title")}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)]",children:s("definitions.edit.subtitle")})]})]}),e.jsxs("form",{onSubmit:A,className:"grid grid-cols-1 lg:grid-cols-5 gap-6",children:[e.jsxs("div",{className:"lg:col-span-3 space-y-6",children:[e.jsxs("div",{className:"card p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--text-primary)] mb-4",children:s("definitions.edit.basicInfo")}),e.jsxs("div",{className:"space-y-4",children:[!a&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:[s("definitions.fields.code")," *"]}),e.jsx("input",{type:"text",value:j.code,onChange:h=>u("code",h.target.value),placeholder:"my-block-definition",className:"input w-full font-mono"}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] mt-1",children:s("definitions.fields.codeHelp")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:[s("definitions.fields.name")," *"]}),e.jsx("input",{type:"text",value:j.name,onChange:h=>u("name",h.target.value),placeholder:s("definitions.fields.namePlaceholder"),className:"input w-full",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("definitions.fields.description")}),e.jsx("textarea",{value:j.description,onChange:h=>u("description",h.target.value),placeholder:s("definitions.fields.descriptionPlaceholder"),rows:2,className:"input w-full resize-none"})]}),!a&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:[s("definitions.columns.type")," *"]}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:os.map(h=>e.jsxs("button",{type:"button",onClick:()=>u("blockType",h),className:`p-3 rounded-lg border-2 transition-all flex flex-col items-center gap-2 ${j.blockType===h?"border-[var(--color-primary-500)] bg-[var(--accent-bg)]":"border-[var(--border-color)] hover:border-[var(--color-primary-300)]"}`,children:[e.jsx("span",{className:j.blockType===h?"text-[var(--color-primary-600)]":"text-[var(--text-tertiary)]",children:cs[h]}),e.jsx("span",{className:"text-xs font-medium",children:s(`definitions.blockTypes.${h}`)})]},h))})]}),e.jsx("div",{className:"flex items-center gap-3 pt-2",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:j.isGlobal,onChange:h=>u("isGlobal",h.target.checked),className:"w-4 h-4 rounded border-[var(--border-color)]"}),e.jsx(t.Globe,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("span",{className:"text-sm text-[var(--text-primary)]",children:s("definitions.fields.isGlobal")})]})})]})]}),e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--text-primary)]",children:s("definitions.edit.content")}),e.jsxs("button",{type:"button",onClick:()=>L(!T),className:"btn btn-secondary btn-sm",children:[e.jsx(t.Eye,{className:"w-4 h-4"}),s(T?"definitions.edit.hidePreview":"definitions.edit.showPreview")]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("definitions.fields.defaultTitle")}),e.jsx("input",{type:"text",value:j.defaultTitle,onChange:h=>u("defaultTitle",h.target.value),placeholder:s("definitions.fields.defaultTitlePlaceholder"),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:[s("definitions.fields.defaultContent")," *"]}),e.jsx("textarea",{value:j.defaultContent,onChange:h=>u("defaultContent",h.target.value),placeholder:s("definitions.fields.defaultContentPlaceholder"),rows:12,className:"input w-full font-mono text-sm resize-none",required:!0}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] mt-1",children:s("definitions.fields.variablesHelp")})]})]})]})]}),e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[F.length>0&&e.jsxs("div",{className:"card p-6",children:[e.jsxs("h3",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:[s("skills.detail.variables")," (",F.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:F.map(h=>e.jsx("span",{className:"inline-flex items-center px-3 py-1.5 rounded-full text-xs font-mono bg-[var(--accent-bg)] text-[var(--accent-text)] border border-[var(--accent-border)]",children:`{${h}}`},h))})]}),T&&e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:s("skills.editor.preview")}),e.jsx("div",{className:"bg-[var(--bg-secondary)] rounded-lg p-4 font-mono text-sm whitespace-pre-wrap text-[var(--text-primary)] border border-[var(--border-color)] max-h-96 overflow-y-auto",children:j.defaultContent||s("common.noData")})]}),e.jsxs("div",{className:"card p-6 bg-[var(--bg-secondary)]",children:[e.jsx("h3",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:s("definitions.edit.tips")}),e.jsxs("ul",{className:"space-y-2 text-sm text-[var(--text-tertiary)]",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[var(--color-primary-500)]",children:"•"}),s("definitions.edit.tip1")]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[var(--color-primary-500)]",children:"•"}),s("definitions.edit.tip2")]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-[var(--color-primary-500)]",children:"•"}),s("definitions.edit.tip3")]})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{type:"button",onClick:()=>l("/administration/ai/skills/blocks"),className:"btn btn-secondary flex-1",children:s("common.cancel")}),e.jsx("button",{type:"submit",disabled:b,className:"btn btn-primary flex-1",children:b?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(t.Save,{className:"w-4 h-4"}),s("common.save")]})})]})]})]})]})}const xs={blue:"bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",green:"bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",yellow:"bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",red:"bg-[var(--error-bg)] text-[var(--error-text)] border-[var(--error-border)]",neutral:"bg-[var(--bg-secondary)] text-[var(--text-primary)] border-[var(--border-color)]"},de=r.memo(function({title:l,value:i,icon:a,color:d}){return e.jsxs("div",{className:`card p-4 border ${xs[d]}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium opacity-80",children:l}),a]}),e.jsx("div",{className:"text-2xl font-bold",children:i})]})});function ms(){const{t:s}=Y.useTranslation(["ai"]),[l,i]=r.useState(!0),[a,d]=r.useState(!1),[g,b]=r.useState(null),[f,y]=r.useState(30),[x,p]=r.useState([]),[k,T]=r.useState(null),[L,j]=r.useState([]),[P,u]=r.useState(!1),[A,F]=r.useState("totalCost"),[h,c]=r.useState("desc"),n=r.useCallback(B=>{const M=new Date,S=new Date;return S.setDate(S.getDate()-B),{startDate:S.toISOString().split("T")[0],endDate:M.toISOString()}},[]),N=r.useCallback(async()=>{try{b(null);const{startDate:B,endDate:M}=n(f),S=await E.aiApi.usage.getByInstance(B,M);p(S??[])}catch(B){console.error("Failed to load AI usage data:",B),b(s("ai:common.error","Failed to load data"))}finally{i(!1),d(!1)}},[f,n,s]);r.useEffect(()=>{N()},[N]);const o=r.useCallback(()=>{d(!0),N()},[N]),_=r.useCallback(async B=>{try{u(!0);const{startDate:M,endDate:S}=n(f),I=await E.aiApi.usage.getInstanceEvents(B,M,S,100);j(I??[])}catch{j([])}finally{u(!1)}},[f,n]),C=r.useCallback(B=>{k===B?(T(null),j([])):(T(B),_(B))},[k,_]),v=r.useCallback(B=>{A===B?c(M=>M==="asc"?"desc":"asc"):(F(B),c("desc"))},[A]),O=r.useMemo(()=>[...x].sort((B,M)=>{const S=B[A],I=M[A];if(S==null&&I==null)return 0;if(S==null)return 1;if(I==null)return-1;const R=typeof S=="string"?S.localeCompare(I):S-I;return h==="asc"?R:-R}),[x,A,h]),W=r.useMemo(()=>{const B=x.length,M=x.reduce((R,V)=>R+V.totalCost,0),S=x.reduce((R,V)=>R+V.requestCount,0),I=x.reduce((R,V)=>R+V.totalTokens,0);return{activeProfiles:B,totalCost:M,totalRequests:S,totalTokens:I}},[x]),m=B=>{const M=Math.abs(B),I=M===0||M>=.01?2:M>=1e-4?4:6;return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:I,maximumFractionDigits:I}).format(B)},D=B=>new Intl.NumberFormat("en-US").format(B),K=B=>`${Math.round(B)} ms`,w=B=>B.requestCount===0?"—":`${(B.successCount/B.requestCount*100).toFixed(1)}%`,q=B=>B?new Date(B).toLocaleString():"—";return l?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-500)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s("ai:monitoring.title")}),e.jsx("p",{className:"text-[var(--text-secondary)] mt-1",children:s("ai:monitoring.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("select",{value:f,onChange:B=>y(Number(B.target.value)),className:"px-3 py-2 border border-[var(--border-color)] bg-[var(--bg-card)] text-[var(--text-primary)] rounded-[var(--radius-input)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",children:[e.jsx("option",{value:7,children:s("ai:monitoring.period.7days")}),e.jsx("option",{value:30,children:s("ai:monitoring.period.30days")}),e.jsx("option",{value:90,children:s("ai:monitoring.period.90days")})]}),e.jsxs("button",{onClick:o,disabled:a,className:"px-4 py-2 text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] rounded-[var(--radius-button)] flex items-center gap-2",children:[e.jsx(t.RefreshCw,{className:`w-4 h-4 ${a?"animate-spin":""}`}),s("ai:monitoring.refresh")]})]})]}),g&&e.jsxs("div",{className:"p-4 bg-[var(--error-bg)] border border-[var(--error-border)] rounded-[var(--radius-card)]",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(t.AlertCircle,{className:"h-5 w-5 text-[var(--error-text)]"}),e.jsx("span",{className:"ml-2 text-[var(--error-text)]",children:g})]}),e.jsx("button",{onClick:o,className:"mt-2 text-sm text-[var(--error-text)] hover:opacity-80 underline",children:s("ai:monitoring.refresh")})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(de,{title:s("ai:monitoring.kpis.totalProfiles"),value:W.activeProfiles,icon:e.jsx(t.Users,{className:"w-5 h-5"}),color:"blue"}),e.jsx(de,{title:s("ai:monitoring.kpis.totalCost"),value:m(W.totalCost),icon:e.jsx(t.DollarSign,{className:"w-5 h-5"}),color:"green"}),e.jsx(de,{title:s("ai:monitoring.kpis.totalRequests"),value:D(W.totalRequests),icon:e.jsx(t.Activity,{className:"w-5 h-5"}),color:"yellow"}),e.jsx(de,{title:s("ai:monitoring.kpis.totalTokens"),value:D(W.totalTokens),icon:e.jsx(t.Zap,{className:"w-5 h-5"}),color:"neutral"})]}),x.length===0?e.jsx("div",{className:"text-center py-12 text-[var(--text-secondary)]",children:s("ai:monitoring.empty")}):e.jsx("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)] overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[var(--border-color)] bg-[var(--bg-secondary)]",children:[e.jsx("th",{className:"w-8 p-3"}),e.jsx(ae,{field:"instanceName",label:s("ai:monitoring.table.instance"),sortField:A,sortDirection:h,onSort:v}),e.jsx(ae,{field:"providerName",label:s("ai:monitoring.table.provider"),sortField:A,sortDirection:h,onSort:v}),e.jsx("th",{className:"text-left p-3 text-sm font-medium text-[var(--text-secondary)]",children:s("ai:monitoring.table.department")}),e.jsx("th",{className:"text-left p-3 text-sm font-medium text-[var(--text-secondary)]",children:s("ai:monitoring.table.costCenter")}),e.jsx(ae,{field:"totalTokens",label:s("ai:monitoring.table.totalTokens"),sortField:A,sortDirection:h,onSort:v,align:"right"}),e.jsx(ae,{field:"totalCost",label:s("ai:monitoring.table.totalCost"),sortField:A,sortDirection:h,onSort:v,align:"right"}),e.jsx(ae,{field:"requestCount",label:s("ai:monitoring.table.requests"),sortField:A,sortDirection:h,onSort:v,align:"right"}),e.jsx("th",{className:"text-right p-3 text-sm font-medium text-[var(--text-secondary)]",children:s("ai:monitoring.table.successRate")}),e.jsx(ae,{field:"avgLatencyMs",label:s("ai:monitoring.table.avgLatency"),sortField:A,sortDirection:h,onSort:v,align:"right"}),e.jsx(ae,{field:"lastUsedAt",label:s("ai:monitoring.table.lastUsed"),sortField:A,sortDirection:h,onSort:v})]})}),e.jsx("tbody",{children:O.map(B=>e.jsx(hs,{item:B,isExpanded:k===B.instanceId,onToggle:C,events:k===B.instanceId?L:[],eventsLoading:k===B.instanceId&&P,formatCurrency:m,formatNumber:D,formatLatency:K,formatSuccessRate:w,formatDate:q},B.instanceId))})]})})})]})}const ae=r.memo(function({field:l,label:i,sortField:a,sortDirection:d,onSort:g,align:b="left"}){const f=a===l;return e.jsx("th",{className:`p-3 text-sm font-medium text-[var(--text-secondary)] cursor-pointer hover:text-[var(--text-primary)] select-none ${b==="right"?"text-right":"text-left"}`,onClick:()=>g(l),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[i,f&&e.jsx("span",{className:"text-[var(--color-accent-500)]",children:d==="asc"?"↑":"↓"})]})})}),hs=r.memo(function({item:l,isExpanded:i,onToggle:a,events:d,eventsLoading:g,formatCurrency:b,formatNumber:f,formatLatency:y,formatSuccessRate:x,formatDate:p}){const{t:k}=Y.useTranslation(["ai"]);return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"border-b border-[var(--border-color)] hover:bg-[var(--bg-hover)] cursor-pointer",onClick:()=>a(l.instanceId),children:[e.jsx("td",{className:"p-3 text-center",children:i?e.jsx(t.ChevronDown,{className:"w-4 h-4 text-[var(--text-secondary)]"}):e.jsx(t.ChevronRight,{className:"w-4 h-4 text-[var(--text-secondary)]"})}),e.jsx("td",{className:"p-3 font-medium text-[var(--text-primary)]",children:l.instanceName}),e.jsx("td",{className:"p-3 text-[var(--text-secondary)]",children:l.providerName}),e.jsx("td",{className:"p-3 text-[var(--text-secondary)]",children:l.department??"—"}),e.jsx("td",{className:"p-3 text-[var(--text-secondary)]",children:l.costCenter??"—"}),e.jsx("td",{className:"p-3 text-right font-mono text-sm",children:f(l.totalTokens)}),e.jsx("td",{className:"p-3 text-right font-medium",children:b(l.totalCost)}),e.jsx("td",{className:"p-3 text-right",children:f(l.requestCount)}),e.jsx("td",{className:"p-3 text-right",children:x(l)}),e.jsx("td",{className:"p-3 text-right text-sm",children:y(l.avgLatencyMs)}),e.jsx("td",{className:"p-3 text-sm text-[var(--text-secondary)]",children:p(l.lastUsedAt)})]}),i&&e.jsx("tr",{children:e.jsx("td",{colSpan:11,className:"p-0",children:e.jsxs("div",{className:"bg-[var(--bg-secondary)] border-t border-[var(--border-color)] p-4",children:[e.jsx("h4",{className:"text-sm font-semibold text-[var(--text-primary)] mb-3",children:k("ai:monitoring.detail.title",{name:l.instanceName})}),g&&e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(t.Loader2,{className:"w-5 h-5 animate-spin text-[var(--color-accent-500)]"})}),!g&&d.length===0&&e.jsx("div",{className:"text-center py-4 text-[var(--text-secondary)] text-sm",children:k("ai:monitoring.detail.noEvents")}),!g&&d.length>0&&e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[var(--border-color)]",children:[e.jsx("th",{className:"text-left p-2 font-medium text-[var(--text-secondary)]",children:k("ai:monitoring.detail.timestamp")}),e.jsx("th",{className:"text-left p-2 font-medium text-[var(--text-secondary)]",children:k("ai:monitoring.detail.model")}),e.jsx("th",{className:"text-left p-2 font-medium text-[var(--text-secondary)]",children:k("ai:monitoring.detail.feature")}),e.jsx("th",{className:"text-right p-2 font-medium text-[var(--text-secondary)]",children:k("ai:monitoring.detail.tokens")}),e.jsx("th",{className:"text-right p-2 font-medium text-[var(--text-secondary)]",children:k("ai:monitoring.detail.cost")}),e.jsx("th",{className:"text-right p-2 font-medium text-[var(--text-secondary)]",children:k("ai:monitoring.detail.latency")}),e.jsx("th",{className:"text-center p-2 font-medium text-[var(--text-secondary)]",children:k("ai:monitoring.detail.status")})]})}),e.jsx("tbody",{children:d.map(T=>e.jsxs("tr",{className:"border-b border-[var(--border-color)] last:border-0",children:[e.jsx("td",{className:"p-2 text-[var(--text-secondary)]",children:new Date(T.timestamp).toLocaleString()}),e.jsx("td",{className:"p-2 font-mono",children:T.modelName}),e.jsx("td",{className:"p-2 text-[var(--text-secondary)]",children:T.featureName??"—"}),e.jsx("td",{className:"p-2 text-right font-mono",children:e.jsx("span",{title:`In: ${f(T.inputTokens)} / Out: ${f(T.outputTokens)}`,children:f(T.totalTokens)})}),e.jsx("td",{className:"p-2 text-right",children:b(T.costAmount)}),e.jsxs("td",{className:"p-2 text-right",children:[T.latencyMs," ms"]}),e.jsx("td",{className:"p-2 text-center",children:T.statusCode>=200&&T.statusCode<300?e.jsx(t.CheckCircle,{className:"w-4 h-4 text-[var(--success-text)] inline"}):e.jsx("span",{title:T.errorMessage??"",children:e.jsx(t.XCircle,{className:"w-4 h-4 text-[var(--error-text)] inline"})})})]},T.id))})]})})]})})})]})});function us(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),{currentTenant:i,isGlobalView:a}=J.useTenant(),[d,g]=r.useState([]),[b,f]=r.useState(!0),[y,x]=r.useState(null),[p,k]=r.useState(""),[T,L]=r.useState(""),[j,P]=r.useState("table"),[u,A]=r.useState(1),F=20,h=r.useCallback(async()=>{try{x(null),f(!0);const v=await E.aiApi.agents.getAll();g(v??[])}catch(v){console.error("Failed to load agents:",v),x(s("agents.messages.loadFailed"))}finally{f(!1)}},[s,i?.id,a]);r.useEffect(()=>{h()},[h]);const c=async(v,O)=>{if(O.stopPropagation(),!!confirm(s("agents.confirmDelete")))try{await E.aiApi.agents.delete(v.id),await h()}catch(W){console.error("Failed to delete agent:",W)}},n=d.filter(v=>{const O=!p||v.name.toLowerCase().includes(p.toLowerCase())||v.agentCode.toLowerCase().includes(p.toLowerCase()),W=!T||T==="active"&&v.isActive||T==="inactive"&&!v.isActive;return O&&W}),N=(u-1)*F,o=n.slice(N,N+F),_=()=>e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-[var(--bg-secondary)] border-b border-[var(--border-color)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("agents.columns.name")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("agents.columns.code")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("agents.columns.steps")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("agents.columns.maxParallelism")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("agents.columns.timeout")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("agents.columns.status")}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",children:s("agents.columns.actions")})]})}),e.jsxs("tbody",{className:"divide-y divide-[var(--border-color)]",children:[b&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-12 text-center",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin mx-auto text-[var(--color-primary-600)]"})})}),!b&&o.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-12 text-center text-[var(--text-secondary)]",children:s("agents.noAgents")})}),!b&&o.length>0&&o.map(v=>e.jsxs("tr",{className:"group hover:bg-[var(--bg-hover)] transition-all cursor-pointer",onClick:()=>l(`/administration/ai/agents/${v.id}`),children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Bot,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-[var(--text-primary)]",children:v.name}),v.description&&e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] truncate max-w-[300px]",children:v.description})]})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"font-mono text-sm text-[var(--text-secondary)]",children:v.agentCode})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-sm text-[var(--text-secondary)]",children:[e.jsx(t.Workflow,{className:"w-3.5 h-3.5"}),v.stepCount]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"text-sm text-[var(--text-secondary)]",children:v.maxParallelism})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"text-sm text-[var(--text-secondary)]",children:[v.timeoutSeconds,"s"]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(J.StatusBadge,{status:v.isActive?"active":"inactive",label:s(`agents.status.${v.isActive?"active":"inactive"}`)})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:O=>O.stopPropagation(),children:[e.jsx("button",{onClick:()=>l(`/administration/ai/agents/${v.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("agents.actions.view"),children:e.jsx(t.Eye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>l(`/administration/ai/agents/${v.id}/edit`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)] transition-all",title:s("agents.actions.edit"),children:e.jsx(t.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:O=>c(v,O),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",title:s("agents.actions.delete"),children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})})]},v.id))]})]})}),C=()=>e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[b&&e.jsx("div",{className:"col-span-full flex items-center justify-center py-16",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-accent-500)]"})}),!b&&o.length===0&&e.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg bg-[var(--color-accent-50)] flex items-center justify-center mb-3",children:e.jsx(t.Bot,{className:"w-8 h-8 text-[var(--color-accent-500)]"})}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s("agents.noAgents")})]}),!b&&o.length>0&&o.map(v=>e.jsxs("button",{onClick:()=>l(`/administration/ai/agents/${v.id}`),className:"bg-[var(--bg-card)] border-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)] rounded-[var(--radius-card)] overflow-hidden transition-all hover:shadow-lg hover:border-[var(--color-accent-400)] cursor-pointer flex flex-col text-left",children:[e.jsx("div",{className:"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 p-4 border-b border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-[var(--color-accent-500)] flex items-center justify-center shadow-lg",children:e.jsx(t.Bot,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] truncate",children:v.name}),e.jsx("p",{className:"text-xs font-mono text-[var(--text-tertiary)]",children:v.agentCode})]})]}),e.jsx(J.StatusBadge,{status:v.isActive?"active":"inactive",label:s(`agents.status.${v.isActive?"active":"inactive"}`),size:"sm"})]})}),e.jsxs("div",{className:"p-4 flex flex-col flex-1",children:[v.description&&e.jsx("p",{className:"text-sm text-[var(--text-secondary)] line-clamp-2 mb-3",children:v.description}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[e.jsx(t.Workflow,{className:"w-3 h-3"}),v.stepCount," ",s("agents.columns.steps").toLowerCase()]}),e.jsxs("span",{className:"px-2 py-1 rounded-full text-xs bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[s("agents.columns.maxParallelism"),": ",v.maxParallelism]}),e.jsxs("span",{className:"px-2 py-1 rounded-full text-xs bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:[v.timeoutSeconds,"s"]})]}),e.jsx("div",{className:"flex-1 min-h-4"}),e.jsxs("div",{className:"flex items-center justify-end gap-1 mt-3 pt-3 border-t border-[var(--border-color)]",onClick:O=>O.stopPropagation(),children:[e.jsx("button",{onClick:()=>l(`/administration/ai/agents/${v.id}/edit`),className:"p-1.5 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--color-accent-600)] hover:bg-[var(--color-accent-50)] transition-all",title:s("agents.actions.edit"),children:e.jsx(t.Edit2,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:O=>c(v,O),className:"p-1.5 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",title:s("agents.actions.delete"),children:e.jsx(t.Trash2,{className:"w-3.5 h-3.5"})})]})]})]},v.id))]});return e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("agents.title")}]}),y&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:y})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Bot,{className:"w-6 h-6"}),s("agents.title")]}),e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)] mt-1",children:[d.length," ",s("agents.agentsCount")]})]}),e.jsxs("button",{onClick:()=>l("/administration/ai/agents/create"),className:"btn btn-primary",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("agents.createAgent")]})]}),e.jsx("div",{className:"card p-4",children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 flex-1",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(t.Search,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("input",{type:"text",value:p,onChange:v=>k(v.target.value),placeholder:s("agents.search"),className:"input pl-10 w-full"})]}),e.jsxs("select",{value:T,onChange:v=>L(v.target.value),className:"input",children:[e.jsx("option",{value:"",children:s("agents.allStatuses")}),e.jsx("option",{value:"active",children:s("agents.status.active")}),e.jsx("option",{value:"inactive",children:s("agents.status.inactive")})]})]}),e.jsx(J.ViewToggle,{viewMode:j,onChange:P,showKanban:!1})]})}),j==="table"&&_(),j==="cards"&&C(),!b&&n.length>F&&e.jsx(J.Pagination,{page:u,totalPages:Math.ceil(n.length/F),totalCount:n.length,pageSize:F,onPageChange:A,itemLabel:s("agents.agentsCount")})]})}const ye=["steps","executions"],Ne={0:"inactive",1:"active",2:"active",3:"warning",4:"warning",5:"inactive"};function ps(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),{id:i}=Z.useParams(),{activeTab:a,setActiveTab:d}=ke.useTabNavigation("steps",ye),[g,b]=r.useState(null),[f,y]=r.useState(!0),[x,p]=r.useState(null),[k,T]=r.useState([]),[L,j]=r.useState(!1),[P,u]=r.useState(null),A=r.useCallback(async()=>{if(i)try{p(null),y(!0);const o=await E.aiApi.agents.getById(i);b(o??null)}catch(o){console.error("Failed to load agent:",o),p(s("agents.messages.loadFailed"))}finally{y(!1)}},[i,s]),F=r.useCallback(async()=>{if(i)try{j(!0);const o=await E.aiApi.agents.getExecutions(i);T(o??[])}catch(o){console.error("Failed to load executions:",o)}finally{j(!1)}},[i]);r.useEffect(()=>{A()},[A]),r.useEffect(()=>{a==="executions"&&F()},[a,F]);const h=async()=>{if(!(!g||!confirm(s("agents.confirmDelete"))))try{await E.aiApi.agents.delete(g.id),l("/administration/ai/agents")}catch(o){console.error("Failed to delete agent:",o)}},c=async o=>{try{const _=await E.aiApi.agents.getExecutionDetail(o);u(_??null)}catch(_){console.error("Failed to load execution detail:",_)}},n=o=>o<1e3?`${o}ms`:`${(o/1e3).toFixed(1)}s`,N=o=>`$${o.toFixed(4)}`;return f?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}):x||!g?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("button",{onClick:()=>l("/administration/ai/agents"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("agents.backToList")]}),e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:x||s("common.noData")})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("agents.title"),href:"/administration/ai/agents"},{label:g.name}]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>l("/administration/ai/agents"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("agents.backToList")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>l(`/administration/ai/agents/${g.id}/edit`),className:"btn btn-secondary flex items-center gap-2",children:[e.jsx(t.Edit2,{className:"w-4 h-4"}),s("agents.actions.edit")]}),e.jsx("button",{onClick:h,className:"btn btn-danger flex items-center gap-2",children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"card p-6",children:[e.jsxs("div",{className:"flex items-start gap-4 mb-6",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-gradient-to-br from-indigo-500 to-blue-500 flex items-center justify-center shadow-lg",children:e.jsx(t.Bot,{className:"w-7 h-7 text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:g.name}),e.jsx(J.StatusBadge,{status:g.isActive?"active":"inactive",label:s(`agents.status.${g.isActive?"active":"inactive"}`)})]}),e.jsx("p",{className:"font-mono text-sm text-[var(--text-tertiary)]",children:g.agentCode}),g.description&&e.jsx("p",{className:"text-[var(--text-secondary)] mt-2",children:g.description})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--text-tertiary)] mb-1",children:[e.jsx(t.Workflow,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs",children:s("agents.columns.steps")})]}),e.jsx("p",{className:"font-medium text-[var(--text-primary)]",children:g.steps.length})]}),e.jsxs("div",{className:"p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--text-tertiary)] mb-1",children:[e.jsx(t.Layers,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs",children:s("agents.columns.maxParallelism")})]}),e.jsx("p",{className:"font-medium text-[var(--text-primary)]",children:g.maxParallelism})]}),e.jsxs("div",{className:"p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--text-tertiary)] mb-1",children:[e.jsx(t.Clock,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs",children:s("agents.columns.timeout")})]}),e.jsxs("p",{className:"font-medium text-[var(--text-primary)]",children:[g.timeoutSeconds,"s"]})]}),e.jsxs("div",{className:"p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--text-tertiary)] mb-1",children:[e.jsx(t.User,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs",children:s("agents.detail.createdBy")})]}),e.jsx("p",{className:"font-medium text-[var(--text-primary)]",children:g.createdBy||"System"})]})]})]}),e.jsx("div",{className:"border-b border-[var(--border-color)]",children:e.jsx("nav",{className:"flex gap-4",children:ye.map(o=>e.jsx("button",{onClick:()=>d(o),className:`pb-3 px-1 text-sm font-medium border-b-2 transition-colors ${a===o?"border-[var(--color-primary-600)] text-[var(--color-primary-600)]":"border-transparent text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,children:s(`agents.detail.${o}`)},o))})}),a==="steps"&&e.jsx("div",{className:"space-y-3",children:g.steps.length>0?g.steps.map(o=>e.jsx("div",{className:`card p-4 border-l-4 ${o.isActive?"border-l-blue-500 bg-blue-50/30 dark:bg-blue-900/10":"border-l-gray-300 opacity-60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"w-8 h-8 rounded-full bg-[var(--bg-secondary)] flex items-center justify-center text-sm font-bold",children:o.stepOrder}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:o.name}),o.continueOnFailure&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-[var(--warning-bg)] text-[var(--warning-text)]",children:s("agents.detail.continueOnFailure")}),!o.isActive&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-orange-100 text-orange-600 dark:bg-orange-900/30",children:s("agents.status.inactive")})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-2 text-sm text-[var(--text-secondary)]",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-tertiary)]",children:[s("agents.detail.stepSkill"),": "]}),e.jsx("span",{className:"font-mono",children:o.skill?o.skill.name:o.skillId})]}),o.outputStateKey&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-tertiary)]",children:[s("agents.detail.stepOutputKey"),": "]}),e.jsx("span",{className:"font-mono",children:o.outputStateKey})]}),o.inputMappingJson&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-[var(--text-tertiary)]",children:[s("agents.detail.stepInputMapping"),": "]}),e.jsx("span",{className:"font-mono text-xs",children:o.inputMappingJson})]})]})]})]})},o.id)):e.jsxs("div",{className:"card p-8 text-center border-2 border-dashed border-[var(--border-color)]",children:[e.jsx(t.Workflow,{className:"w-12 h-12 mx-auto mb-4 text-[var(--text-tertiary)]"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("agents.detail.noSteps")})]})}),a==="executions"&&e.jsxs("div",{className:"space-y-4",children:[L&&e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}),!L&&k.length===0&&e.jsxs("div",{className:"card p-8 text-center border-2 border-dashed border-[var(--border-color)]",children:[e.jsx(t.Play,{className:"w-12 h-12 mx-auto mb-4 text-[var(--text-tertiary)]"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("agents.executions.noExecutions")})]}),!L&&k.length>0&&e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-[var(--bg-secondary)] border-b border-[var(--border-color)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase",children:s("agents.executions.columns.status")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase",children:s("agents.executions.columns.startedAt")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase",children:s("agents.executions.columns.steps")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase",children:s("agents.executions.columns.tokens")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase",children:s("agents.executions.columns.cost")}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase",children:s("agents.executions.columns.duration")}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-[var(--text-secondary)] uppercase",children:s("agents.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border-color)]",children:k.map(o=>e.jsx(gs,{execution:o,t:s,formatDuration:n,formatCost:N,selectedExecution:P,onViewDetail:c},o.id))})]})})]}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:e.jsx("div",{className:"lg:col-span-3",children:e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"font-semibold text-[var(--text-primary)] mb-4",children:s("agents.detail.info")}),e.jsxs("dl",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--text-secondary)]",children:s("agents.detail.createdAt")}),e.jsx("dd",{className:"text-[var(--text-primary)]",children:g.createdAt?new Date(g.createdAt).toLocaleDateString():"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--text-secondary)]",children:s("agents.detail.createdBy")}),e.jsx("dd",{className:"text-[var(--text-primary)]",children:g.createdBy||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--text-secondary)]",children:s("agents.detail.updatedAt")}),e.jsx("dd",{className:"text-[var(--text-primary)]",children:g.updatedAt?new Date(g.updatedAt).toLocaleDateString():"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[var(--text-secondary)]",children:s("agents.detail.updatedBy")}),e.jsx("dd",{className:"text-[var(--text-primary)]",children:g.updatedBy||"-"})]})]})]})})})]})}function gs({execution:s,t:l,formatDuration:i,formatCost:a,selectedExecution:d,onViewDetail:g}){const[b,f]=r.useState(!1),y=d?.id===s.id,x=async()=>{!b&&!y&&await g(s.id),f(!b)};return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:"hover:bg-[var(--bg-hover)] transition-all cursor-pointer",onClick:x,children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[b?e.jsx(t.ChevronDown,{className:"w-4 h-4"}):e.jsx(t.ChevronRight,{className:"w-4 h-4"}),e.jsx(J.StatusBadge,{status:Ne[s.status]||"inactive",label:l(`agents.executions.status.${s.status}`)})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-[var(--text-secondary)]",children:new Date(s.startedAt).toLocaleString()}),e.jsxs("td",{className:"px-4 py-3 text-sm text-[var(--text-secondary)]",children:[s.executedSteps,"/",s.totalSteps]}),e.jsx("td",{className:"px-4 py-3 text-sm text-[var(--text-secondary)]",children:(s.totalInputTokens+s.totalOutputTokens).toLocaleString()}),e.jsx("td",{className:"px-4 py-3 text-sm text-[var(--text-secondary)]",children:a(s.totalCost)}),e.jsx("td",{className:"px-4 py-3 text-sm text-[var(--text-secondary)]",children:i(s.totalExecutionTimeMs)}),e.jsx("td",{className:"px-4 py-3 text-right",children:s.errorMessage&&e.jsx("div",{title:s.errorMessage,children:e.jsx(t.AlertCircle,{className:"w-4 h-4 text-[var(--error-text)] inline-block"})})})]}),b&&y&&d&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-4 bg-[var(--bg-secondary)]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium text-sm",children:l("agents.executions.stepDetail")}),d.stepExecutions.map(p=>e.jsxs("div",{className:"flex items-center gap-4 p-3 bg-[var(--bg-primary)] rounded-lg border border-[var(--border-color)]",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-[var(--bg-secondary)] flex items-center justify-center text-xs font-bold",children:p.stepOrder}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:p.stepName}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] font-mono",children:p.skillCode})]}),e.jsx(J.StatusBadge,{status:Ne[p.status]||"inactive",label:l(`agents.executions.status.${p.status}`),size:"sm"}),e.jsxs("div",{className:"text-xs text-[var(--text-secondary)] flex items-center gap-3",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(t.Timer,{className:"w-3 h-3"}),i(p.executionTimeMs)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(t.Coins,{className:"w-3 h-3"}),a(p.cost)]}),e.jsxs("span",{children:[(p.inputTokens+p.outputTokens).toLocaleString()," tokens"]})]}),p.errorMessage&&e.jsx("span",{className:"text-xs text-[var(--error-text)] max-w-[200px] truncate",title:p.errorMessage,children:p.errorMessage})]},p.id))]})})})]})}function vs(){const{t:s}=Y.useTranslation("ai"),l=Z.useNavigate(),{id:i}=Z.useParams(),a=!i||i==="create",[d,g]=r.useState(!a),[b,f]=r.useState(!1),[y,x]=r.useState(null),[p,k]=r.useState(null),[T,L]=r.useState(""),[j,P]=r.useState(""),[u,A]=r.useState(""),[F,h]=r.useState(5),[c,n]=r.useState(120),[N,o]=r.useState([]),[_,C]=r.useState(!0),[v,O]=r.useState([]),W=r.useCallback(async()=>{if(!a)try{x(null),g(!0);const S=await E.aiApi.agents.getById(i);S&&(k(S),L(S.agentCode),P(S.name),A(S.description||""),h(S.maxParallelism),n(S.timeoutSeconds),o(S.steps.sort((I,R)=>I.stepOrder-R.stepOrder).map(I=>({tempId:I.id,id:I.id,skillId:I.skillId,name:I.name,stepOrder:I.stepOrder,inputMappingJson:I.inputMappingJson||"",outputStateKey:I.outputStateKey||"",continueOnFailure:I.continueOnFailure}))))}catch(S){console.error("Failed to load agent:",S),x(s("agents.messages.loadFailed"))}finally{g(!1)}},[i,a,s]),m=r.useCallback(async()=>{try{const S=await E.aiApi.skills.getAll({status:"Active"});O(S??[])}catch(S){console.error("Failed to load skills:",S)}},[]);r.useEffect(()=>{W(),m()},[W,m]);const D=async()=>{try{if(f(!0),x(null),a){const S=await E.aiApi.agents.create({agentCode:T,name:j,moduleId:"c3d4e5f6-7a8b-9c0d-1e2f-3a4b5c6d7e8f",description:u||void 0,maxParallelism:F,timeoutSeconds:c});if(S){if(N.length>0){const I=N.map((R,V)=>({skillId:R.skillId,name:R.name,stepOrder:V+1,inputMappingJson:R.inputMappingJson||void 0,outputStateKey:R.outputStateKey||void 0,continueOnFailure:R.continueOnFailure}));await E.aiApi.agents.update(S.id,{name:j,description:u||void 0,maxParallelism:F,timeoutSeconds:c,steps:I})}l(`/administration/ai/agents/${S.id}`)}}else{const S=N.map((I,R)=>({id:I.id,skillId:I.skillId,name:I.name,stepOrder:R+1,inputMappingJson:I.inputMappingJson||void 0,outputStateKey:I.outputStateKey||void 0,continueOnFailure:I.continueOnFailure}));await E.aiApi.agents.update(i,{name:j,description:u||void 0,maxParallelism:F,timeoutSeconds:c,steps:S}),l(`/administration/ai/agents/${i}`)}}catch(S){console.error("Failed to save agent:",S),x(s("agents.messages.saveFailed"))}finally{f(!1)}},K=()=>{const S={tempId:`temp-${Date.now()}`,skillId:"",name:"",stepOrder:N.length+1,inputMappingJson:"",outputStateKey:"",continueOnFailure:!1};o([...N,S])},w=S=>{o(N.filter(I=>I.tempId!==S))},q=(S,I,R)=>{o(N.map(V=>V.tempId===S?{...V,[I]:R}:V))},B=(S,I)=>{const R=N.findIndex(H=>H.tempId===S);if(R===-1||I==="up"&&R===0||I==="down"&&R===N.length-1)return;const V=[...N],U=I==="up"?R-1:R+1;[V[R],V[U]]=[V[U],V[R]],o(V.map((H,Q)=>({...H,stepOrder:Q+1})))},M=j.trim()&&(a?T.trim():!0);return d?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(t.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(J.Breadcrumb,{items:[{label:s("breadcrumb.administration"),href:"/administration"},{label:s("header.title"),href:"/administration/ai"},{label:s("agents.title"),href:"/administration/ai/agents"},{label:a?s("agents.edit.create"):p?.name||s("agents.edit.title")}]}),y&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(t.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium flex-1",children:y})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>l(a?"/administration/ai/agents":`/administration/ai/agents/${i}`),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)]",children:[e.jsx(t.ArrowLeft,{className:"w-4 h-4"}),s("common.back")]}),e.jsxs("button",{onClick:D,disabled:b||!M,className:"btn btn-primary flex items-center gap-2",children:[b?e.jsx(t.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsx(t.Save,{className:"w-4 h-4"}),s("common.save")]})]}),e.jsxs("div",{className:"flex items-center gap-4 mb-2",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gradient-to-br from-indigo-500 to-blue-500 flex items-center justify-center shadow-lg",children:e.jsx(t.Bot,{className:"w-6 h-6 text-white"})}),e.jsx("div",{className:"flex-1",children:e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s(a?"agents.edit.create":"agents.edit.title")})}),e.jsxs("button",{onClick:()=>C(!_),className:`btn btn-secondary flex items-center gap-2 ${_?"bg-[var(--bg-secondary)]":""}`,children:[e.jsx(t.Settings,{className:"w-4 h-4"}),s("agents.edit.agentInfo")]})]}),_&&e.jsxs("div",{className:"card p-6",children:[e.jsx("h3",{className:"font-semibold mb-4",children:s("agents.edit.agentInfo")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",children:[s("agents.fields.agentCode")," *"]}),e.jsx("input",{type:"text",value:T,onChange:S=>L(S.target.value),className:"input w-full font-mono",placeholder:s("agents.fields.agentCodePlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",children:[s("agents.fields.name")," *"]}),e.jsx("input",{type:"text",value:j,onChange:S=>P(S.target.value),className:"input w-full",placeholder:s("agents.fields.namePlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("agents.fields.maxParallelism")}),e.jsx("input",{type:"number",value:F,onChange:S=>h(Math.min(20,Math.max(1,parseInt(S.target.value)||1))),className:"input w-full",min:1,max:20})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("agents.fields.timeoutSeconds")}),e.jsx("input",{type:"number",value:c,onChange:S=>n(Math.min(600,Math.max(10,parseInt(S.target.value)||10))),className:"input w-full",min:10,max:600})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:s("agents.fields.description")}),e.jsx("textarea",{value:u,onChange:S=>A(S.target.value),className:"input w-full",rows:2,placeholder:s("agents.fields.descriptionPlaceholder")})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-semibold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(t.Workflow,{className:"w-5 h-5"}),s("agents.edit.stepsBuilder")," (",N.length,")"]}),e.jsxs("button",{onClick:K,className:"btn btn-primary btn-sm flex items-center gap-1",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("agents.edit.addStep")]})]}),N.length>0?e.jsx("div",{className:"space-y-3",children:N.map((S,I)=>e.jsx(bs,{step:S,index:I,isFirst:I===0,isLast:I===N.length-1,skills:v,onChange:(R,V)=>q(S.tempId,R,V),onDelete:()=>w(S.tempId),onMoveUp:()=>B(S.tempId,"up"),onMoveDown:()=>B(S.tempId,"down"),t:s},S.tempId))}):e.jsxs("div",{className:"card p-8 text-center border-2 border-dashed border-[var(--border-color)]",children:[e.jsx(t.Workflow,{className:"w-12 h-12 mx-auto mb-4 text-[var(--text-tertiary)]"}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:s("agents.edit.addFirstStep")}),e.jsxs("button",{onClick:K,className:"btn btn-primary",children:[e.jsx(t.Plus,{className:"w-4 h-4"}),s("agents.edit.addStep")]})]})]})]})}function bs({step:s,index:l,isFirst:i,isLast:a,skills:d,onChange:g,onDelete:b,onMoveUp:f,onMoveDown:y,t:x}){return e.jsx("div",{className:"card border-l-4 border-l-blue-500 bg-blue-50/30 dark:bg-blue-900/10 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex flex-col items-center gap-1 pt-2",children:[e.jsx("button",{onClick:f,disabled:i,className:"p-1 rounded hover:bg-[var(--bg-secondary)] disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(t.ChevronUp,{className:"w-4 h-4"})}),e.jsx("span",{className:"w-8 h-8 rounded-full bg-[var(--bg-secondary)] flex items-center justify-center text-sm font-bold",children:l+1}),e.jsx("button",{onClick:y,disabled:a,className:"p-1 rounded hover:bg-[var(--bg-secondary)] disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(t.ChevronDown,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium mb-1",children:[x("agents.fields.stepName")," *"]}),e.jsx("input",{type:"text",value:s.name,onChange:p=>g("name",p.target.value),className:"input w-full",placeholder:x("agents.fields.stepNamePlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium mb-1",children:[x("agents.fields.skill")," *"]}),e.jsxs("select",{value:s.skillId,onChange:p=>g("skillId",p.target.value),className:"input w-full",children:[e.jsx("option",{value:"",children:x("agents.fields.selectSkill")}),d.map(p=>e.jsxs("option",{value:p.id,children:[p.name," (",p.code,")"]},p.id))]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:x("agents.fields.outputStateKey")}),e.jsx("input",{type:"text",value:s.outputStateKey,onChange:p=>g("outputStateKey",p.target.value),className:"input w-full font-mono",placeholder:x("agents.fields.outputStateKeyPlaceholder")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium mb-1",children:x("agents.fields.inputMapping")}),e.jsx("input",{type:"text",value:s.inputMappingJson,onChange:p=>g("inputMappingJson",p.target.value),className:"input w-full font-mono text-sm",placeholder:x("agents.fields.inputMappingPlaceholder")})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:s.continueOnFailure,onChange:p=>g("continueOnFailure",p.target.checked),className:"rounded"}),x("agents.fields.continueOnFailure")]})]}),e.jsx("button",{onClick:b,className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-all",title:x("agents.edit.removeStep"),children:e.jsx(t.Trash2,{className:"w-4 h-4"})})]})})}exports.AiAgentDetailPage=ps;exports.AiAgentEditPage=vs;exports.AiAgentsPage=us;exports.AiBlockDefinitionDetailPage=ns;exports.AiBlockDefinitionEditPage=ds;exports.AiBlockDefinitionsListPage=ls;exports.AiDashboardPage=Fe;exports.AiMonitoringPage=ms;exports.AiPromptsListPage=Se;exports.AiSettingsPage=Ye;exports.AiSkillsDetailPage=Qe;exports.AiSkillsEditPage=ts;exports.AiSkillsListPage=Se;
11
- //# sourceMappingURL=index-CSQ60fpG.js.map
11
+ //# sourceMappingURL=index-CgpRo8Oe.js.map