@cedros/login-react 0.0.29 → 0.0.30

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 (175) hide show
  1. package/README.md +2 -0
  2. package/dist/{AdminDepositList-CyT4VBH8.js → AdminDepositList-BUm_ZcAW.js} +1 -1
  3. package/dist/{AdminDepositList-CyT4VBH8.js.map → AdminDepositList-BUm_ZcAW.js.map} +1 -1
  4. package/dist/{AdminDepositList-b2AXtLg0.cjs → AdminDepositList-B_z6x3j5.cjs} +1 -1
  5. package/dist/{AdminDepositList-b2AXtLg0.cjs.map → AdminDepositList-B_z6x3j5.cjs.map} +1 -1
  6. package/dist/{AdminWithdrawalHistory-DL9zbu2b.cjs → AdminWithdrawalHistory-B2EY2ZmH.cjs} +1 -1
  7. package/dist/{AdminWithdrawalHistory-DL9zbu2b.cjs.map → AdminWithdrawalHistory-B2EY2ZmH.cjs.map} +1 -1
  8. package/dist/{AdminWithdrawalHistory-Cud-yuWy.js → AdminWithdrawalHistory-C76bkbjX.js} +1 -1
  9. package/dist/{AdminWithdrawalHistory-Cud-yuWy.js.map → AdminWithdrawalHistory-C76bkbjX.js.map} +1 -1
  10. package/dist/{AuthenticationSettings-D6GvSw3g.cjs → AuthenticationSettings-C-aYDXNH.cjs} +1 -1
  11. package/dist/{AuthenticationSettings-D6GvSw3g.cjs.map → AuthenticationSettings-C-aYDXNH.cjs.map} +1 -1
  12. package/dist/AuthenticationSettings-CoTic-d_.cjs +1 -0
  13. package/dist/AuthenticationSettings-CoTic-d_.cjs.map +1 -0
  14. package/dist/{AuthenticationSettings-rb4Fksw5.js → AuthenticationSettings-CsPbxwP7.js} +1 -1
  15. package/dist/{AuthenticationSettings-rb4Fksw5.js.map → AuthenticationSettings-CsPbxwP7.js.map} +1 -1
  16. package/dist/AuthenticationSettings-DIVk0OP8.js +712 -0
  17. package/dist/AuthenticationSettings-DIVk0OP8.js.map +1 -0
  18. package/dist/AutosaveStatus-DGNI4lXn.cjs +1 -0
  19. package/dist/AutosaveStatus-DGNI4lXn.cjs.map +1 -0
  20. package/dist/{AutosaveStatus-vkJxtuEw.js → AutosaveStatus-f-jw25Ay.js} +141 -93
  21. package/dist/AutosaveStatus-f-jw25Ay.js.map +1 -0
  22. package/dist/{CreditSystemSettings-ChA_lbef.cjs → CreditSystemSettings-BNkvsgsk.cjs} +1 -1
  23. package/dist/{CreditSystemSettings-ChA_lbef.cjs.map → CreditSystemSettings-BNkvsgsk.cjs.map} +1 -1
  24. package/dist/{CreditSystemSettings-DsRipb2R.js → CreditSystemSettings-C6ed3yp7.js} +1 -1
  25. package/dist/{CreditSystemSettings-DsRipb2R.js.map → CreditSystemSettings-C6ed3yp7.js.map} +1 -1
  26. package/dist/{CreditSystemSettings-r3gnGjiU.cjs → CreditSystemSettings-DM9ep1TF.cjs} +1 -1
  27. package/dist/{CreditSystemSettings-r3gnGjiU.cjs.map → CreditSystemSettings-DM9ep1TF.cjs.map} +1 -1
  28. package/dist/{CreditSystemSettings-a31pqSYS.js → CreditSystemSettings-uinhzoha.js} +1 -1
  29. package/dist/{CreditSystemSettings-a31pqSYS.js.map → CreditSystemSettings-uinhzoha.js.map} +1 -1
  30. package/dist/{DepositsSection-DD9MKUFt.js → DepositsSection-Bb4ISzvE.js} +1 -1
  31. package/dist/{DepositsSection-DD9MKUFt.js.map → DepositsSection-Bb4ISzvE.js.map} +1 -1
  32. package/dist/{DepositsSection-BkKUS4vk.cjs → DepositsSection-uQUdGeVb.cjs} +1 -1
  33. package/dist/{DepositsSection-BkKUS4vk.cjs.map → DepositsSection-uQUdGeVb.cjs.map} +1 -1
  34. package/dist/EmailRegisterForm-B_TiJkD6.cjs +1 -0
  35. package/dist/EmailRegisterForm-B_TiJkD6.cjs.map +1 -0
  36. package/dist/EmailRegisterForm-CCEuQA-w.js +773 -0
  37. package/dist/EmailRegisterForm-CCEuQA-w.js.map +1 -0
  38. package/dist/{EmailSettings-BVJ4vz0Y.js → EmailSettings-BAuQtEfM.js} +1 -1
  39. package/dist/{EmailSettings-BVJ4vz0Y.js.map → EmailSettings-BAuQtEfM.js.map} +1 -1
  40. package/dist/{EmailSettings-Dg2SAiHj.cjs → EmailSettings-BC0f1PCI.cjs} +1 -1
  41. package/dist/{EmailSettings-Dg2SAiHj.cjs.map → EmailSettings-BC0f1PCI.cjs.map} +1 -1
  42. package/dist/{EmailSettings-CM5l8qqK.cjs → EmailSettings-BF5EiPl9.cjs} +1 -1
  43. package/dist/{EmailSettings-CM5l8qqK.cjs.map → EmailSettings-BF5EiPl9.cjs.map} +1 -1
  44. package/dist/{EmailSettings-xtVl4kXD.js → EmailSettings-BKuXy8sc.js} +1 -1
  45. package/dist/{EmailSettings-xtVl4kXD.js.map → EmailSettings-BKuXy8sc.js.map} +1 -1
  46. package/dist/{EmbeddedWalletSettings-Bmx8x21f.cjs → EmbeddedWalletSettings-BRjt2PAj.cjs} +1 -1
  47. package/dist/{EmbeddedWalletSettings-Bmx8x21f.cjs.map → EmbeddedWalletSettings-BRjt2PAj.cjs.map} +1 -1
  48. package/dist/{EmbeddedWalletSettings-BuDgqv-K.js → EmbeddedWalletSettings-C27X9He2.js} +1 -1
  49. package/dist/{EmbeddedWalletSettings-BuDgqv-K.js.map → EmbeddedWalletSettings-C27X9He2.js.map} +1 -1
  50. package/dist/{EmbeddedWalletSettings-BXN9VbNJ.cjs → EmbeddedWalletSettings-CJY39UZN.cjs} +1 -1
  51. package/dist/{EmbeddedWalletSettings-BXN9VbNJ.cjs.map → EmbeddedWalletSettings-CJY39UZN.cjs.map} +1 -1
  52. package/dist/{EmbeddedWalletSettings-DY5iJhS0.js → EmbeddedWalletSettings-Dmi-EQ7W.js} +1 -1
  53. package/dist/{EmbeddedWalletSettings-DY5iJhS0.js.map → EmbeddedWalletSettings-Dmi-EQ7W.js.map} +1 -1
  54. package/dist/GoogleLoginButton-CjBO3Rf1.cjs +1 -0
  55. package/dist/GoogleLoginButton-CjBO3Rf1.cjs.map +1 -0
  56. package/dist/{GoogleLoginButton-B6qnNMZp.js → GoogleLoginButton-DEbiQngr.js} +51 -51
  57. package/dist/GoogleLoginButton-DEbiQngr.js.map +1 -0
  58. package/dist/LoadingSpinner-6vml-zwr.js.map +1 -1
  59. package/dist/LoadingSpinner-d6sSxgQN.cjs.map +1 -1
  60. package/dist/{PermissionsSection-BPbE-hNx.cjs → PermissionsSection-DEMVp7X3.cjs} +1 -1
  61. package/dist/PermissionsSection-DEMVp7X3.cjs.map +1 -0
  62. package/dist/{PermissionsSection-CighC1p6.js → PermissionsSection-DNzOL1xW.js} +27 -25
  63. package/dist/PermissionsSection-DNzOL1xW.js.map +1 -0
  64. package/dist/{ServerSettings-BAstMKHS.js → ServerSettings-BT9weFPz.js} +1 -1
  65. package/dist/{ServerSettings-BAstMKHS.js.map → ServerSettings-BT9weFPz.js.map} +1 -1
  66. package/dist/{ServerSettings-LIIP5TPz.cjs → ServerSettings-CKfiLfXi.cjs} +1 -1
  67. package/dist/{ServerSettings-LIIP5TPz.cjs.map → ServerSettings-CKfiLfXi.cjs.map} +1 -1
  68. package/dist/{ServerSettings-9Q091f3o.js → ServerSettings-CZfBdMxG.js} +1 -1
  69. package/dist/{ServerSettings-9Q091f3o.js.map → ServerSettings-CZfBdMxG.js.map} +1 -1
  70. package/dist/{ServerSettings-PH7T8JKI.cjs → ServerSettings-rHrVN8O8.cjs} +1 -1
  71. package/dist/{ServerSettings-PH7T8JKI.cjs.map → ServerSettings-rHrVN8O8.cjs.map} +1 -1
  72. package/dist/SolanaLoginButton-DAV3r4oB.cjs +1 -0
  73. package/dist/SolanaLoginButton-DAV3r4oB.cjs.map +1 -0
  74. package/dist/{mobileWalletAdapter-Cm_AUXhg.js → SolanaLoginButton-DFOoLqoj.js} +75 -74
  75. package/dist/SolanaLoginButton-DFOoLqoj.js.map +1 -0
  76. package/dist/{TeamSection-BIECkp7g.js → TeamSection-CoMXyFtz.js} +2 -2
  77. package/dist/{TeamSection-BIECkp7g.js.map → TeamSection-CoMXyFtz.js.map} +1 -1
  78. package/dist/{TeamSection-BOH9pv_E.cjs → TeamSection-DopbZClq.cjs} +1 -1
  79. package/dist/{TeamSection-BOH9pv_E.cjs.map → TeamSection-DopbZClq.cjs.map} +1 -1
  80. package/dist/{UsersSection-t-zm0jZW.js → UsersSection--PAE1XRh.js} +1 -1
  81. package/dist/{UsersSection-t-zm0jZW.js.map → UsersSection--PAE1XRh.js.map} +1 -1
  82. package/dist/{UsersSection-e6q7FHzx.cjs → UsersSection-C7aRNkK2.cjs} +1 -1
  83. package/dist/{UsersSection-e6q7FHzx.cjs.map → UsersSection-C7aRNkK2.cjs.map} +1 -1
  84. package/dist/{WebhookSettings-D0F8ESlB.js → WebhookSettings-Bgld6D_T.js} +1 -1
  85. package/dist/{WebhookSettings-D0F8ESlB.js.map → WebhookSettings-Bgld6D_T.js.map} +1 -1
  86. package/dist/{WebhookSettings-2p9abGm5.cjs → WebhookSettings-DXjnq-c7.cjs} +1 -1
  87. package/dist/{WebhookSettings-2p9abGm5.cjs.map → WebhookSettings-DXjnq-c7.cjs.map} +1 -1
  88. package/dist/{WebhookSettings-CdFM7_V-.cjs → WebhookSettings-DnLk97Mr.cjs} +1 -1
  89. package/dist/{WebhookSettings-CdFM7_V-.cjs.map → WebhookSettings-DnLk97Mr.cjs.map} +1 -1
  90. package/dist/{WebhookSettings-CXMBju7N.js → WebhookSettings-ufiGTmbG.js} +1 -1
  91. package/dist/{WebhookSettings-CXMBju7N.js.map → WebhookSettings-ufiGTmbG.js.map} +1 -1
  92. package/dist/{WithdrawalsSection-yRDTVFsb.js → WithdrawalsSection-BN-FjTEV.js} +1 -1
  93. package/dist/{WithdrawalsSection-yRDTVFsb.js.map → WithdrawalsSection-BN-FjTEV.js.map} +1 -1
  94. package/dist/{WithdrawalsSection-sljIyeaz.cjs → WithdrawalsSection-BhuCwFat.cjs} +1 -1
  95. package/dist/{WithdrawalsSection-sljIyeaz.cjs.map → WithdrawalsSection-BhuCwFat.cjs.map} +1 -1
  96. package/dist/admin-only.cjs +1 -1
  97. package/dist/admin-only.js +1 -1
  98. package/dist/email-only.cjs +1 -1
  99. package/dist/email-only.d.ts +17 -1
  100. package/dist/email-only.js +3 -3
  101. package/dist/google-only.cjs +1 -1
  102. package/dist/google-only.d.ts +16 -0
  103. package/dist/google-only.js +3 -3
  104. package/dist/index.cjs +12 -12
  105. package/dist/index.cjs.map +1 -1
  106. package/dist/index.d.ts +246 -10
  107. package/dist/index.js +3384 -2508
  108. package/dist/index.js.map +1 -1
  109. package/dist/login-react.css +1 -1
  110. package/dist/{plugin-DbkijwEV.js → plugin-BbExid4E.js} +1 -1
  111. package/dist/{plugin-DbkijwEV.js.map → plugin-BbExid4E.js.map} +1 -1
  112. package/dist/{plugin-PU2vAozn.cjs → plugin-Xca67fp7.cjs} +1 -1
  113. package/dist/{plugin-PU2vAozn.cjs.map → plugin-Xca67fp7.cjs.map} +1 -1
  114. package/dist/{shamir-CiBczzDN.cjs → shamir-DBpHm7WN.cjs} +1 -1
  115. package/dist/{shamir-CiBczzDN.cjs.map → shamir-DBpHm7WN.cjs.map} +1 -1
  116. package/dist/{shamir-OAB2zD9Y.js → shamir-R8ddesFt.js} +1 -1
  117. package/dist/{shamir-OAB2zD9Y.js.map → shamir-R8ddesFt.js.map} +1 -1
  118. package/dist/{silentWalletEnroll-FqXS7Rvh.js → silentWalletEnroll-Dp1GTeNr.js} +3 -3
  119. package/dist/{silentWalletEnroll-FqXS7Rvh.js.map → silentWalletEnroll-Dp1GTeNr.js.map} +1 -1
  120. package/dist/{silentWalletEnroll-wnkcB9HP.cjs → silentWalletEnroll-HPvsbd2J.cjs} +1 -1
  121. package/dist/{silentWalletEnroll-wnkcB9HP.cjs.map → silentWalletEnroll-HPvsbd2J.cjs.map} +1 -1
  122. package/dist/solana-only.cjs +1 -1
  123. package/dist/solana-only.d.ts +16 -0
  124. package/dist/solana-only.js +3 -3
  125. package/dist/{useAdminDeposits-BTSyeAfg.js → useAdminDeposits-C76B2Q_8.js} +1 -1
  126. package/dist/{useAdminDeposits-BTSyeAfg.js.map → useAdminDeposits-C76B2Q_8.js.map} +1 -1
  127. package/dist/{useAdminDeposits-BkkCwHWp.cjs → useAdminDeposits-CpLd68oP.cjs} +1 -1
  128. package/dist/{useAdminDeposits-BkkCwHWp.cjs.map → useAdminDeposits-CpLd68oP.cjs.map} +1 -1
  129. package/dist/{useAuth-m5Hf89v8.js → useAuth-CVLv2oKA.js} +547 -545
  130. package/dist/useAuth-CVLv2oKA.js.map +1 -0
  131. package/dist/useAuth-XZaciuLg.cjs +1 -0
  132. package/dist/useAuth-XZaciuLg.cjs.map +1 -0
  133. package/dist/useCedrosLogin-CFfID-0i.js +228 -0
  134. package/dist/useCedrosLogin-CFfID-0i.js.map +1 -0
  135. package/dist/useCedrosLogin-DtJorrE7.cjs +1 -0
  136. package/dist/useCedrosLogin-DtJorrE7.cjs.map +1 -0
  137. package/dist/{useOrgs-C3pzMA9h.js → useOrgs-C90KT9KP.js} +1 -1
  138. package/dist/{useOrgs-C3pzMA9h.js.map → useOrgs-C90KT9KP.js.map} +1 -1
  139. package/dist/{useOrgs-DDVRCaVi.cjs → useOrgs-CNqfn-fk.cjs} +1 -1
  140. package/dist/{useOrgs-DDVRCaVi.cjs.map → useOrgs-CNqfn-fk.cjs.map} +1 -1
  141. package/dist/{useSystemSettings-DRrreszl.cjs → useSystemSettings-B2jY51ob.cjs} +1 -1
  142. package/dist/{useSystemSettings-DRrreszl.cjs.map → useSystemSettings-B2jY51ob.cjs.map} +1 -1
  143. package/dist/{useSystemSettings-DBlAMjFi.js → useSystemSettings-rgskaDqP.js} +1 -1
  144. package/dist/{useSystemSettings-DBlAMjFi.js.map → useSystemSettings-rgskaDqP.js.map} +1 -1
  145. package/dist/{useUsersStatsSummary-NjEFvWuz.js → useUsersStatsSummary-5DJwzntC.js} +2 -2
  146. package/dist/{useUsersStatsSummary-NjEFvWuz.js.map → useUsersStatsSummary-5DJwzntC.js.map} +1 -1
  147. package/dist/{useUsersStatsSummary-8qY7iP4G.cjs → useUsersStatsSummary-DgKaUIfs.cjs} +1 -1
  148. package/dist/{useUsersStatsSummary-8qY7iP4G.cjs.map → useUsersStatsSummary-DgKaUIfs.cjs.map} +1 -1
  149. package/package.json +1 -1
  150. package/dist/AuthenticationSettings-C9f5MKgj.cjs +0 -1
  151. package/dist/AuthenticationSettings-C9f5MKgj.cjs.map +0 -1
  152. package/dist/AuthenticationSettings-DC64o_J6.js +0 -525
  153. package/dist/AuthenticationSettings-DC64o_J6.js.map +0 -1
  154. package/dist/AutosaveStatus-BFj5GIab.cjs +0 -1
  155. package/dist/AutosaveStatus-BFj5GIab.cjs.map +0 -1
  156. package/dist/AutosaveStatus-vkJxtuEw.js.map +0 -1
  157. package/dist/EmailRegisterForm-B1DB-bqe.cjs +0 -1
  158. package/dist/EmailRegisterForm-B1DB-bqe.cjs.map +0 -1
  159. package/dist/EmailRegisterForm-BAX_uBIt.js +0 -927
  160. package/dist/EmailRegisterForm-BAX_uBIt.js.map +0 -1
  161. package/dist/GoogleLoginButton-B6qnNMZp.js.map +0 -1
  162. package/dist/GoogleLoginButton-D7CoMXLq.cjs +0 -1
  163. package/dist/GoogleLoginButton-D7CoMXLq.cjs.map +0 -1
  164. package/dist/PermissionsSection-BPbE-hNx.cjs.map +0 -1
  165. package/dist/PermissionsSection-CighC1p6.js.map +0 -1
  166. package/dist/mobileWalletAdapter-B6ELaZp1.cjs +0 -1
  167. package/dist/mobileWalletAdapter-B6ELaZp1.cjs.map +0 -1
  168. package/dist/mobileWalletAdapter-Cm_AUXhg.js.map +0 -1
  169. package/dist/useAuth-X6Ds6WW4.cjs +0 -1
  170. package/dist/useAuth-X6Ds6WW4.cjs.map +0 -1
  171. package/dist/useAuth-m5Hf89v8.js.map +0 -1
  172. package/dist/useCedrosLogin-C9MrcZvh.cjs +0 -1
  173. package/dist/useCedrosLogin-C9MrcZvh.cjs.map +0 -1
  174. package/dist/useCedrosLogin-_94MmGGq.js +0 -216
  175. package/dist/useCedrosLogin-_94MmGGq.js.map +0 -1
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),n=require("react"),v=require("./useCedrosLogin-C9MrcZvh.cjs"),be=require("./useSystemSettings-DRrreszl.cjs");class pe{client;constructor(t,r,a,b){this.client=new v.ApiClient({baseUrl:t,timeoutMs:r,retryAttempts:a,getAccessToken:b})}async listUsers(t){try{const r=new URLSearchParams;t?.limit&&r.set("limit",String(t.limit)),t?.offset&&r.set("offset",String(t.offset));const a=r.toString(),b=`/admin/users${a?`?${a}`:""}`;return await this.client.get(b)}catch(r){throw v.handleApiError(r,"Failed to list users")}}async getUser(t){try{return await this.client.get(`/admin/users/${t}`)}catch(r){throw v.handleApiError(r,"Failed to get user")}}async setSystemAdmin(t,r){try{await this.client.patch(`/admin/users/${t}/system-admin`,{isAdmin:r})}catch(a){throw v.handleApiError(a,"Failed to update system admin status")}}async updateUser(t,r){try{return await this.client.patch(`/admin/users/${t}`,r)}catch(a){throw v.handleApiError(a,"Failed to update user")}}async deleteUser(t){try{await this.client.delete(`/admin/users/${t}`)}catch(r){throw v.handleApiError(r,"Failed to delete user")}}async forcePasswordReset(t){try{await this.client.post(`/admin/users/${t}/force-password-reset`,{})}catch(r){throw v.handleApiError(r,"Failed to send password reset email")}}async adjustCredits(t,r){try{await this.client.post(`/admin/users/${t}/credits`,r)}catch(a){throw v.handleApiError(a,"Failed to adjust credits")}}async getUserDeposits(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/deposits${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user deposits")}}async getUserCredits(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/credits${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user credits")}}async getUserWithdrawalHistory(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/withdrawal-history${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user withdrawal history")}}async getUserChats(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/chats${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user chat history")}}async getStats(){try{return await this.client.get("/admin/users/stats")}catch(t){throw v.handleApiError(t,"Failed to get user stats")}}}function V(){const{config:s,_internal:t}=v.useCedrosLogin(),[r,a]=n.useState([]),[b,p]=n.useState(0),[j,l]=n.useState(!1),[u,h]=n.useState(null),[A,D]=n.useState({}),f=n.useMemo(()=>new pe(s.serverUrl,s.requestTimeout,s.retryAttempts,t?.getAccessToken),[s.serverUrl,s.requestTimeout,s.retryAttempts,t]),T=n.useCallback(async d=>{l(!0),h(null),D(d||{});try{const i=await f.listUsers(d);return a(i.users),p(i.total),i}catch(i){const o=i instanceof Error?i:new Error("Failed to list users");throw h(o),o}finally{l(!1)}},[f]),y=n.useCallback(async d=>{l(!0),h(null);try{return await f.getUser(d)}catch(i){const o=i instanceof Error?i:new Error("Failed to get user");throw h(o),o}finally{l(!1)}},[f]),c=n.useCallback(async(d,i)=>{l(!0),h(null);try{await f.setSystemAdmin(d,i),a(o=>o.map(g=>g.id===d?{...g,isSystemAdmin:i}:g))}catch(o){const g=o instanceof Error?o:new Error("Failed to update admin status");throw h(g),g}finally{l(!1)}},[f]),N=n.useCallback(async(d,i)=>{l(!0),h(null);try{const o=await f.updateUser(d,i);return a(g=>g.map(R=>R.id===d?o:R)),o}catch(o){const g=o instanceof Error?o:new Error("Failed to update user");throw h(g),g}finally{l(!1)}},[f]),w=n.useCallback(async d=>{l(!0),h(null);try{await f.deleteUser(d),a(i=>i.filter(o=>o.id!==d)),p(i=>i-1)}catch(i){const o=i instanceof Error?i:new Error("Failed to delete user");throw h(o),o}finally{l(!1)}},[f]),S=n.useCallback(async d=>{l(!0),h(null);try{await f.forcePasswordReset(d)}catch(i){const o=i instanceof Error?i:new Error("Failed to send password reset");throw h(o),o}finally{l(!1)}},[f]),k=n.useCallback(async(d,i,o)=>{l(!0),h(null);try{await f.adjustCredits(d,{amount:i,reason:o})}catch(g){const R=g instanceof Error?g:new Error("Failed to adjust credits");throw h(R),R}finally{l(!1)}},[f]),F=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserDeposits(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user deposits");throw h(g),g}finally{l(!1)}},[f]),$=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserCredits(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user credits");throw h(g),g}finally{l(!1)}},[f]),L=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserWithdrawalHistory(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user withdrawal history");throw h(g),g}finally{l(!1)}},[f]),C=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserChats(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user chat history");throw h(g),g}finally{l(!1)}},[f]),U=n.useCallback(async()=>{l(!0),h(null);try{return await f.getStats()}catch(d){const i=d instanceof Error?d:new Error("Failed to get user stats");throw h(i),i}finally{l(!1)}},[f]),P=n.useCallback(async()=>{await T(A)},[T,A]),m=n.useCallback(()=>{h(null)},[]);return{users:r,total:b,isLoading:j,error:u,listUsers:T,getUser:y,setSystemAdmin:c,updateUser:N,deleteUser:w,forcePasswordReset:S,adjustCredits:k,getUserDeposits:F,getUserCredits:$,getUserWithdrawalHistory:L,getUserChats:C,getStats:U,refresh:P,clearError:m}}function z(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function ge(s){return s.length<=12?s:`${s.slice(0,6)}...${s.slice(-4)}`}function xe(s){return s==null?"-":(s/1e9).toFixed(4)}function je({pageSize:s=20,refreshInterval:t=0,currentUserId:r,className:a="",onLoad:b,onUserClick:p}){const{users:j,total:l,isLoading:u,error:h,listUsers:A,clearError:D}=V(),[f,T]=n.useState(0),[y,c]=n.useState(null),[N,w]=n.useState("createdAt"),[S,k]=n.useState("desc"),F=m=>{N===m?k(S==="asc"?"desc":"asc"):(w(m),k("desc"))},$=n.useMemo(()=>[...j].sort((m,d)=>{let i,o;switch(N){case"name":i=(m.name||m.email||"").toLowerCase(),o=(d.name||d.email||"").toLowerCase();break;case"createdAt":i=new Date(m.createdAt).getTime(),o=new Date(d.createdAt).getTime();break;case"lastLoginAt":i=m.lastLoginAt?new Date(m.lastLoginAt).getTime():0,o=d.lastLoginAt?new Date(d.lastLoginAt).getTime():0;break;case"balanceLamports":i=m.balanceLamports??0,o=d.balanceLamports??0;break;default:return 0}return i<o?S==="asc"?-1:1:i>o?S==="asc"?1:-1:0}),[j,N,S]),L=n.useCallback(async()=>{try{const m=await A({limit:s,offset:f});b?.(m),c(null)}catch(m){c(m instanceof Error?m.message:"Failed to load users")}},[s,f,A,b]);n.useEffect(()=>{T(0)},[s]),n.useEffect(()=>{L()},[L]),n.useEffect(()=>{if(t<=0)return;const m=setInterval(L,t);return()=>clearInterval(m)},[t,L]);const C=Math.ceil(l/s),U=Math.floor(f/s)+1,P=m=>{const d=(m-1)*s;T(Math.max(0,Math.min(d,Math.max(0,l-1))))};return y||h?e.jsxs("div",{className:`cedros-admin-user-list cedros-admin-user-list-error ${a}`,children:[e.jsx("p",{className:"cedros-admin-error",children:y||h?.message}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline",onClick:()=>{D(),c(null),L()},children:"Retry"})]}):u&&j.length===0?e.jsxs("div",{className:`cedros-admin-user-list cedros-admin-user-list-loading ${a}`,children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{className:"cedros-admin-loading-text",children:"Loading users..."})]}):e.jsxs("div",{className:`cedros-admin-user-list ${a}`,children:[e.jsxs("div",{className:"cedros-admin-user-list-header",children:[e.jsx("h4",{className:"cedros-admin-user-list-title",children:"All Users"}),e.jsxs("div",{className:"cedros-admin-user-list-actions",children:[e.jsxs("span",{className:"cedros-admin-queue-count",children:[l," user",l!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__stats-bar-refresh",onClick:L,disabled:u,title:"Refresh list","aria-label":"Refresh list",children:u?"...":"↻"})]})]}),j.length===0?e.jsx("div",{className:"cedros-admin-empty",children:e.jsx("p",{className:"cedros-admin-empty-message",children:"No users found."})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-user-table",children:[e.jsxs("div",{className:"cedros-admin-user-thead",children:[e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="name"?"cedros-admin-sort-active":""}`,onClick:()=>F("name"),"aria-label":"Sort by user",children:["User"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="name"?S==="asc"?"↑":"↓":"↕"})]})}),e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="createdAt"?"cedros-admin-sort-active":""}`,onClick:()=>F("createdAt"),"aria-label":"Sort by registered date",children:["Registered"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="createdAt"?S==="asc"?"↑":"↓":"↕"})]})}),e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="lastLoginAt"?"cedros-admin-sort-active":""}`,onClick:()=>F("lastLoginAt"),"aria-label":"Sort by last login",children:["Last Login"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="lastLoginAt"?S==="asc"?"↑":"↓":"↕"})]})}),e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="balanceLamports"?"cedros-admin-sort-active":""}`,onClick:()=>F("balanceLamports"),"aria-label":"Sort by balance",children:["Balance"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="balanceLamports"?S==="asc"?"↑":"↓":"↕"})]})})]}),$.map(m=>{const d=m.id===r;return e.jsxs("div",{className:`cedros-admin-user-row ${d?"cedros-admin-user-row-current":""}`,onClick:()=>p?.(m),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),p?.(m))},role:p?"button":void 0,tabIndex:p?0:void 0,children:[e.jsxs("div",{className:"cedros-admin-user-td cedros-admin-user-info",children:[e.jsx("div",{className:"cedros-admin-user-avatar",children:m.picture?e.jsx("img",{src:m.picture,alt:m.name||m.email||"User",className:"cedros-admin-user-avatar-img",referrerPolicy:"no-referrer"}):e.jsx("span",{className:"cedros-admin-user-avatar-placeholder",children:(m.name?.[0]||m.email?.[0]||"?").toUpperCase()})}),e.jsxs("div",{className:"cedros-admin-user-details",children:[e.jsxs("span",{className:"cedros-admin-user-name",children:[m.name||"Unknown",d&&e.jsx("span",{className:"cedros-admin-user-you",children:"(you)"})]}),e.jsx("span",{className:"cedros-admin-user-email",title:m.email,children:m.email||ge(m.id)})]})]}),e.jsx("div",{className:"cedros-admin-user-td",children:z(m.createdAt)}),e.jsx("div",{className:"cedros-admin-user-td",children:m.lastLoginAt?z(m.lastLoginAt):"-"}),e.jsx("div",{className:"cedros-admin-user-td",children:xe(m.balanceLamports)})]},m.id)})]}),C>1&&e.jsxs("div",{className:"cedros-admin-pagination",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>P(U-1),disabled:U<=1,children:"Previous"}),e.jsxs("span",{className:"cedros-admin-page-info",children:["Page ",U," of ",C," (",l," total)"]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>P(U+1),disabled:U>=C,children:"Next"})]})]})]})}function ee(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Q(s){return new Date(s).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ye(s){return s==null?"—":`${(s/1e9).toFixed(4)} SOL`}function B(s){return s==null?"—":(s/1e9).toFixed(4)}function Ne(s){return{DEPOSIT:"Deposit",SPEND:"Spend",ADJUSTMENT:"Adjustment",REFUND:"Refund"}[s.toUpperCase()]||s}function we(s,t){return t?{deposit:"Credit deposit",purchase:"Purchase",api_call:"API usage",subscription:"Subscription",refund:"Refund",bonus:"Bonus credit",promo:"Promotional credit",correction:"Balance correction"}[t.toLowerCase()]||t:{DEPOSIT:"Credit added",SPEND:"Credit used",ADJUSTMENT:"Manual adjustment",REFUND:"Credit refunded"}[s.toUpperCase()]||"—"}function ve({userId:s,onBack:t,currentUserId:r,onEditUser:a,onAdjustCredits:b,cedrosPayEnabled:p=!1,className:j=""}){const{isLoading:l,getUser:u,getUserDeposits:h,getUserCredits:A,getUserChats:D,deleteUser:f,forcePasswordReset:T,clearError:y}=V(),[c,N]=n.useState(null),[w,S]=n.useState(null),[k,F]=n.useState(null),[$,L]=n.useState(null),[C,U]=n.useState("deposits"),[P,m]=n.useState(null),[d,i]=n.useState(null),[o,g]=n.useState(null),[R,H]=n.useState(null),[O,_]=n.useState(!1),[W,se]=n.useState(0),[G,te]=n.useState(0),[J,ae]=n.useState(0),E=10,I=n.useCallback(async()=>{try{const x=await u(s);N(x),m(null)}catch(x){m(x instanceof Error?x.message:"Failed to load user")}},[s,u]),K=n.useCallback(async()=>{try{const M=await h(s,{limit:E,offset:W});F(M),g(null)}catch(x){g(x instanceof Error?x.message:"Failed to load deposits")}},[s,h,W]),q=n.useCallback(async()=>{try{const M=await A(s,{limit:E,offset:G});S(M),i(null)}catch(x){i(x instanceof Error?x.message:"Failed to load credits")}},[s,A,G]),Y=n.useCallback(async()=>{if(p)try{const M=await D(s,{limit:E,offset:J});L(M),H(null)}catch(x){H(x instanceof Error?x.message:"Failed to load chat history")}},[s,D,J,p]);n.useEffect(()=>{I(),K(),q(),p&&Y()},[I,K,q,Y,p]);const re=async()=>{if(!c)return;if(c.id===r){alert("You cannot delete your own account");return}if(c.isSystemAdmin){alert("Cannot delete a system admin. Remove admin status first.");return}if(window.confirm(`Are you sure you want to delete ${c.name||c.email||"this user"}? This action cannot be undone.`)){_(!0);try{await f(c.id),t()}catch{}finally{_(!1)}}},ne=async()=>{if(!c?.email){alert("User has no email address");return}if(window.confirm(`Send a password reset email to ${c.email}?`)){_(!0);try{await T(c.id),alert("Password reset email sent")}catch{}finally{_(!1)}}},ie=k?Math.ceil(k.total/E):0,oe=Math.floor(W/E)+1,ce=w?Math.ceil(w.totalTransactions/E):0,de=Math.floor(G/E)+1,le=x=>{se((x-1)*E)},me=x=>{te((x-1)*E)},ue=$?Math.ceil($.total/E):0,he=Math.floor(J/E)+1,fe=x=>{ae((x-1)*E)};if(P)return e.jsxs("div",{className:`cedros-admin-user-detail cedros-admin-user-detail-error ${j}`,children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:t,children:"Back"}),e.jsx("p",{className:"cedros-admin-error",children:P}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline",onClick:()=>{y(),m(null),I()},children:"Retry"})]});if(l&&!c)return e.jsxs("div",{className:`cedros-admin-user-detail cedros-admin-user-detail-loading ${j}`,children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{className:"cedros-admin-loading-text",children:"Loading user..."})]});if(!c)return e.jsxs("div",{className:`cedros-admin-user-detail ${j}`,children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:t,children:"Back"}),e.jsx("p",{className:"cedros-admin-empty-message",children:"User not found."})]});const Z=c.id===r;return e.jsxs("div",{className:`cedros-admin-user-detail ${j}`,children:[e.jsxs("div",{className:"cedros-admin-user-detail-header",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm cedros-admin-back-btn",onClick:t,children:"Back to Users"}),e.jsxs("div",{className:"cedros-admin-user-detail-actions",children:[a&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>a(c),disabled:O,children:"Edit"}),c.email&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:ne,disabled:O,children:"Reset Password"}),b&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>b(c),disabled:O,children:"Adjust Credits"}),!Z&&!c.isSystemAdmin&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm cedros-admin-btn-danger",onClick:re,disabled:O,children:"Delete"})]})]}),e.jsxs("div",{className:"cedros-admin-user-detail-info",children:[e.jsx("div",{className:"cedros-admin-user-detail-avatar",children:c.picture?e.jsx("img",{src:c.picture,alt:c.name||c.email||"User",className:"cedros-admin-user-detail-avatar-img",referrerPolicy:"no-referrer"}):e.jsx("span",{className:"cedros-admin-user-detail-avatar-placeholder",children:(c.name?.[0]||c.email?.[0]||"?").toUpperCase()})}),e.jsxs("div",{className:"cedros-admin-user-detail-meta",children:[e.jsxs("h2",{className:"cedros-admin-user-detail-name",children:[c.name||"Unknown",Z&&e.jsx("span",{className:"cedros-admin-user-you",children:"(you)"})]}),e.jsxs("p",{className:"cedros-admin-user-detail-email",children:[c.email||"No email",c.emailVerified&&e.jsx("span",{className:"cedros-admin-verified-badge",title:"Email verified",children:"Verified"})]}),c.isSystemAdmin&&e.jsx("div",{className:"cedros-admin-user-detail-badges",children:e.jsx("span",{className:"cedros-admin-admin-badge cedros-admin-admin-badge-yes",children:"System Admin"})}),e.jsxs("div",{className:"cedros-admin-user-detail-methods",children:[e.jsx("span",{className:"cedros-admin-user-detail-methods-label",children:"Auth Methods:"}),c.authMethods.length>0?c.authMethods.map(x=>e.jsx("span",{className:`cedros-admin-auth-badge cedros-admin-auth-badge-${x}`,children:x},x)):e.jsx("span",{className:"cedros-admin-auth-badge cedros-admin-auth-badge-none",children:"none"})]}),e.jsxs("p",{className:"cedros-admin-user-detail-dates",children:["Registered: ",ee(c.createdAt)," | Updated: ",ee(c.updatedAt)]})]})]}),d?e.jsxs("div",{className:"cedros-admin-stats-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:d}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>{i(null),q()},children:"Retry"})]}):w?e.jsxs("div",{className:"cedros-admin-user-detail-stats",children:[e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Credit Balance"}),e.jsx("span",{className:"cedros-admin-stat-value",children:B(w.stats.currentBalanceLamports)})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Total Credited"}),e.jsx("span",{className:"cedros-admin-stat-value",children:B(w.stats.totalDepositedLamports)})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Total Spent"}),e.jsx("span",{className:"cedros-admin-stat-value",children:B(w.stats.totalSpentLamports)})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Deposits"}),e.jsx("span",{className:"cedros-admin-stat-value",children:w.stats.depositCount})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Transactions"}),e.jsx("span",{className:"cedros-admin-stat-value",children:w.stats.spendCount})]})]}):e.jsxs("div",{className:"cedros-admin-stats-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading credit stats..."})]}),e.jsxs("div",{className:"cedros-admin-user-detail-tabs",children:[e.jsxs("button",{type:"button",className:`cedros-admin-tab ${C==="deposits"?"cedros-admin-tab-active":""}`,onClick:()=>U("deposits"),children:["Deposits (",k?.total??0,")"]}),e.jsxs("button",{type:"button",className:`cedros-admin-tab ${C==="transactions"?"cedros-admin-tab-active":""}`,onClick:()=>U("transactions"),children:["Credits (",w?.totalTransactions??0,")"]}),p&&e.jsxs("button",{type:"button",className:`cedros-admin-tab ${C==="chats"?"cedros-admin-tab-active":""}`,onClick:()=>U("chats"),children:["Chats (",$?.total??0,")"]})]}),e.jsxs("div",{className:"cedros-admin-user-detail-content",children:[C==="deposits"&&e.jsx(Se,{deposits:k?.deposits??[],total:k?.total??0,currentPage:oe,totalPages:ie,onPageChange:le,isLoading:l,error:o,onRetry:()=>{g(null),K()}}),C==="transactions"&&e.jsx(Ce,{transactions:w?.transactions??[],total:w?.totalTransactions??0,currentPage:de,totalPages:ce,onPageChange:me,error:d,onRetry:()=>{i(null),q()},isLoading:l}),C==="chats"&&p&&e.jsx(Ee,{sessions:$?.sessions??[],total:$?.total??0,currentPage:he,totalPages:ue,onPageChange:fe,error:R,onRetry:()=>{H(null),Y()},isLoading:l})]})]})}function Se({deposits:s,total:t,currentPage:r,totalPages:a,onPageChange:b,isLoading:p,error:j,onRetry:l}){return j?e.jsxs("div",{className:"cedros-admin-tab-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:j}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:l,children:"Retry"})]}):p&&s.length===0?e.jsxs("div",{className:"cedros-admin-tab-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading deposits..."})]}):t===0?e.jsx("div",{className:"cedros-admin-empty-message",children:"No deposits found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-list-table",children:[e.jsxs("div",{className:"cedros-admin-list-thead",children:[e.jsx("div",{className:"cedros-admin-list-th",children:"Date"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Amount"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Status"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Transaction"})]}),s.map(u=>e.jsxs("div",{className:"cedros-admin-list-row",children:[e.jsx("div",{className:"cedros-admin-list-td",children:Q(u.createdAt)}),e.jsx("div",{className:"cedros-admin-list-td",children:ye(u.amountLamports)}),e.jsx("div",{className:"cedros-admin-list-td",children:e.jsx("span",{className:`cedros-admin-status-badge cedros-admin-status-${u.status}`,children:u.status})}),e.jsx("div",{className:"cedros-admin-list-td cedros-admin-list-td-actions",children:u.txSignature?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"cedros-admin-list-td-mono",title:u.txSignature,children:[u.txSignature.slice(0,8),"..."]}),e.jsx("a",{href:`https://orbmarkets.io/tx/${u.txSignature}`,target:"_blank",rel:"noopener noreferrer",className:"cedros-admin-icon-link",title:"View on Orbmarkets","aria-label":"View transaction on Orbmarkets",children:"↗"})]}):e.jsx("span",{className:"cedros-admin-list-td-muted",children:"—"})})]},u.id))]}),a>1&&e.jsx(X,{currentPage:r,totalPages:a,total:t,onPageChange:b})]})}function Ce({transactions:s,total:t,currentPage:r,totalPages:a,onPageChange:b,isLoading:p,error:j,onRetry:l}){return j?e.jsxs("div",{className:"cedros-admin-tab-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:j}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:l,children:"Retry"})]}):p&&s.length===0?e.jsxs("div",{className:"cedros-admin-tab-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading transactions..."})]}):t===0?e.jsx("div",{className:"cedros-admin-empty-message",children:"No credit transactions found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-list-table",children:[e.jsxs("div",{className:"cedros-admin-list-thead",children:[e.jsx("div",{className:"cedros-admin-list-th",children:"Date"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Type"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Description"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Amount"})]}),s.map(u=>e.jsxs("div",{className:"cedros-admin-list-row",children:[e.jsx("div",{className:"cedros-admin-list-td",children:Q(u.createdAt)}),e.jsx("div",{className:"cedros-admin-list-td",children:e.jsx("span",{className:`cedros-admin-tx-type cedros-admin-tx-type-${u.txType.toLowerCase()}`,children:Ne(u.txType)})}),e.jsx("div",{className:"cedros-admin-list-td",children:we(u.txType,u.referenceType)}),e.jsxs("div",{className:`cedros-admin-list-td ${u.amountLamports>=0?"cedros-admin-amount-positive":"cedros-admin-amount-negative"}`,children:[u.amountLamports>=0?"+":"",B(u.amountLamports)]})]},u.id))]}),a>1&&e.jsx(X,{currentPage:r,totalPages:a,total:t,onPageChange:b})]})}function Ee({sessions:s,total:t,currentPage:r,totalPages:a,onPageChange:b,isLoading:p,error:j,onRetry:l}){return j?e.jsxs("div",{className:"cedros-admin-tab-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:j}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:l,children:"Retry"})]}):p&&s.length===0?e.jsxs("div",{className:"cedros-admin-tab-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading chat history..."})]}):t===0?e.jsx("div",{className:"cedros-admin-empty-message",children:"No chat sessions found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-list-table",children:[e.jsxs("div",{className:"cedros-admin-list-thead",children:[e.jsx("div",{className:"cedros-admin-list-th",children:"Date"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Session"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Messages"})]}),s.map(u=>e.jsxs("div",{className:"cedros-admin-list-row",children:[e.jsx("div",{className:"cedros-admin-list-td",children:Q(u.createdAt)}),e.jsx("div",{className:"cedros-admin-list-td",children:u.title||`Chat ${u.id.slice(0,8)}...`}),e.jsx("div",{className:"cedros-admin-list-td",children:u.messageCount})]},u.id))]}),a>1&&e.jsx(X,{currentPage:r,totalPages:a,total:t,onPageChange:b})]})}function X({currentPage:s,totalPages:t,total:r,onPageChange:a}){return e.jsxs("div",{className:"cedros-admin-pagination",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>a(s-1),disabled:s<=1,children:"Previous"}),e.jsxs("span",{className:"cedros-admin-page-info",children:["Page ",s," of ",t," (",r," total)"]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>a(s+1),disabled:s>=t,children:"Next"})]})}const Ue=["email","google","apple","solana","webauthn","sso"],Ae={email:"Email Users",google:"Google Users",apple:"Apple Users",solana:"Solana Users",webauthn:"Passkey Users",sso:"SSO Provider Users"},ke={email:"auth_email_enabled",google:"auth_google_enabled",apple:"auth_apple_enabled",solana:"auth_solana_enabled",webauthn:"auth_webauthn_enabled",sso:"feature_sso"};function Le(){const{getStats:s}=V(),{fetchSettings:t,getValue:r}=be.useSystemSettings(),[a,b]=n.useState(null),[p,j]=n.useState(!1),[l,u]=n.useState(null),[h,A]=n.useState(!1);n.useEffect(()=>{h||(t(),A(!0))},[t,h]);const D=n.useCallback(y=>{const c=r(y);return c===void 0?!1:c==="true"||c==="1"},[r]),f=n.useCallback(async()=>{j(!0),u(null);try{const y=await s();b(y)}catch(y){u(y instanceof Error?y.message:"Failed to load user stats")}finally{j(!1)}},[s]);return n.useEffect(()=>{f()},[f]),{statsItems:n.useMemo(()=>{const y=[{label:"Total Users",value:a?.total??"—"}];return Ue.forEach(c=>{D(ke[c])&&y.push({label:Ae[c],value:a?.authMethodCounts[c]??0})}),y},[a,D]),isLoading:p,error:l,refresh:f}}exports.AdminUserDetail=ve;exports.AdminUserList=je;exports.useAdminUsers=V;exports.useUsersStatsSummary=Le;
1
+ "use strict";const e=require("react/jsx-runtime"),n=require("react"),v=require("./useCedrosLogin-DtJorrE7.cjs"),be=require("./useSystemSettings-B2jY51ob.cjs");class pe{client;constructor(t,r,a,b){this.client=new v.ApiClient({baseUrl:t,timeoutMs:r,retryAttempts:a,getAccessToken:b})}async listUsers(t){try{const r=new URLSearchParams;t?.limit&&r.set("limit",String(t.limit)),t?.offset&&r.set("offset",String(t.offset));const a=r.toString(),b=`/admin/users${a?`?${a}`:""}`;return await this.client.get(b)}catch(r){throw v.handleApiError(r,"Failed to list users")}}async getUser(t){try{return await this.client.get(`/admin/users/${t}`)}catch(r){throw v.handleApiError(r,"Failed to get user")}}async setSystemAdmin(t,r){try{await this.client.patch(`/admin/users/${t}/system-admin`,{isAdmin:r})}catch(a){throw v.handleApiError(a,"Failed to update system admin status")}}async updateUser(t,r){try{return await this.client.patch(`/admin/users/${t}`,r)}catch(a){throw v.handleApiError(a,"Failed to update user")}}async deleteUser(t){try{await this.client.delete(`/admin/users/${t}`)}catch(r){throw v.handleApiError(r,"Failed to delete user")}}async forcePasswordReset(t){try{await this.client.post(`/admin/users/${t}/force-password-reset`,{})}catch(r){throw v.handleApiError(r,"Failed to send password reset email")}}async adjustCredits(t,r){try{await this.client.post(`/admin/users/${t}/credits`,r)}catch(a){throw v.handleApiError(a,"Failed to adjust credits")}}async getUserDeposits(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/deposits${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user deposits")}}async getUserCredits(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/credits${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user credits")}}async getUserWithdrawalHistory(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/withdrawal-history${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user withdrawal history")}}async getUserChats(t,r){try{const a=new URLSearchParams;r?.limit&&a.set("limit",String(r.limit)),r?.offset&&a.set("offset",String(r.offset));const b=a.toString(),p=`/admin/users/${t}/chats${b?`?${b}`:""}`;return await this.client.get(p)}catch(a){throw v.handleApiError(a,"Failed to get user chat history")}}async getStats(){try{return await this.client.get("/admin/users/stats")}catch(t){throw v.handleApiError(t,"Failed to get user stats")}}}function V(){const{config:s,_internal:t}=v.useCedrosLogin(),[r,a]=n.useState([]),[b,p]=n.useState(0),[j,l]=n.useState(!1),[u,h]=n.useState(null),[A,D]=n.useState({}),f=n.useMemo(()=>new pe(s.serverUrl,s.requestTimeout,s.retryAttempts,t?.getAccessToken),[s.serverUrl,s.requestTimeout,s.retryAttempts,t]),T=n.useCallback(async d=>{l(!0),h(null),D(d||{});try{const i=await f.listUsers(d);return a(i.users),p(i.total),i}catch(i){const o=i instanceof Error?i:new Error("Failed to list users");throw h(o),o}finally{l(!1)}},[f]),y=n.useCallback(async d=>{l(!0),h(null);try{return await f.getUser(d)}catch(i){const o=i instanceof Error?i:new Error("Failed to get user");throw h(o),o}finally{l(!1)}},[f]),c=n.useCallback(async(d,i)=>{l(!0),h(null);try{await f.setSystemAdmin(d,i),a(o=>o.map(g=>g.id===d?{...g,isSystemAdmin:i}:g))}catch(o){const g=o instanceof Error?o:new Error("Failed to update admin status");throw h(g),g}finally{l(!1)}},[f]),N=n.useCallback(async(d,i)=>{l(!0),h(null);try{const o=await f.updateUser(d,i);return a(g=>g.map(R=>R.id===d?o:R)),o}catch(o){const g=o instanceof Error?o:new Error("Failed to update user");throw h(g),g}finally{l(!1)}},[f]),w=n.useCallback(async d=>{l(!0),h(null);try{await f.deleteUser(d),a(i=>i.filter(o=>o.id!==d)),p(i=>i-1)}catch(i){const o=i instanceof Error?i:new Error("Failed to delete user");throw h(o),o}finally{l(!1)}},[f]),S=n.useCallback(async d=>{l(!0),h(null);try{await f.forcePasswordReset(d)}catch(i){const o=i instanceof Error?i:new Error("Failed to send password reset");throw h(o),o}finally{l(!1)}},[f]),k=n.useCallback(async(d,i,o)=>{l(!0),h(null);try{await f.adjustCredits(d,{amount:i,reason:o})}catch(g){const R=g instanceof Error?g:new Error("Failed to adjust credits");throw h(R),R}finally{l(!1)}},[f]),F=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserDeposits(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user deposits");throw h(g),g}finally{l(!1)}},[f]),$=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserCredits(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user credits");throw h(g),g}finally{l(!1)}},[f]),L=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserWithdrawalHistory(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user withdrawal history");throw h(g),g}finally{l(!1)}},[f]),C=n.useCallback(async(d,i)=>{l(!0),h(null);try{return await f.getUserChats(d,i)}catch(o){const g=o instanceof Error?o:new Error("Failed to get user chat history");throw h(g),g}finally{l(!1)}},[f]),U=n.useCallback(async()=>{l(!0),h(null);try{return await f.getStats()}catch(d){const i=d instanceof Error?d:new Error("Failed to get user stats");throw h(i),i}finally{l(!1)}},[f]),P=n.useCallback(async()=>{await T(A)},[T,A]),m=n.useCallback(()=>{h(null)},[]);return{users:r,total:b,isLoading:j,error:u,listUsers:T,getUser:y,setSystemAdmin:c,updateUser:N,deleteUser:w,forcePasswordReset:S,adjustCredits:k,getUserDeposits:F,getUserCredits:$,getUserWithdrawalHistory:L,getUserChats:C,getStats:U,refresh:P,clearError:m}}function z(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function ge(s){return s.length<=12?s:`${s.slice(0,6)}...${s.slice(-4)}`}function xe(s){return s==null?"-":(s/1e9).toFixed(4)}function je({pageSize:s=20,refreshInterval:t=0,currentUserId:r,className:a="",onLoad:b,onUserClick:p}){const{users:j,total:l,isLoading:u,error:h,listUsers:A,clearError:D}=V(),[f,T]=n.useState(0),[y,c]=n.useState(null),[N,w]=n.useState("createdAt"),[S,k]=n.useState("desc"),F=m=>{N===m?k(S==="asc"?"desc":"asc"):(w(m),k("desc"))},$=n.useMemo(()=>[...j].sort((m,d)=>{let i,o;switch(N){case"name":i=(m.name||m.email||"").toLowerCase(),o=(d.name||d.email||"").toLowerCase();break;case"createdAt":i=new Date(m.createdAt).getTime(),o=new Date(d.createdAt).getTime();break;case"lastLoginAt":i=m.lastLoginAt?new Date(m.lastLoginAt).getTime():0,o=d.lastLoginAt?new Date(d.lastLoginAt).getTime():0;break;case"balanceLamports":i=m.balanceLamports??0,o=d.balanceLamports??0;break;default:return 0}return i<o?S==="asc"?-1:1:i>o?S==="asc"?1:-1:0}),[j,N,S]),L=n.useCallback(async()=>{try{const m=await A({limit:s,offset:f});b?.(m),c(null)}catch(m){c(m instanceof Error?m.message:"Failed to load users")}},[s,f,A,b]);n.useEffect(()=>{T(0)},[s]),n.useEffect(()=>{L()},[L]),n.useEffect(()=>{if(t<=0)return;const m=setInterval(L,t);return()=>clearInterval(m)},[t,L]);const C=Math.ceil(l/s),U=Math.floor(f/s)+1,P=m=>{const d=(m-1)*s;T(Math.max(0,Math.min(d,Math.max(0,l-1))))};return y||h?e.jsxs("div",{className:`cedros-admin-user-list cedros-admin-user-list-error ${a}`,children:[e.jsx("p",{className:"cedros-admin-error",children:y||h?.message}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline",onClick:()=>{D(),c(null),L()},children:"Retry"})]}):u&&j.length===0?e.jsxs("div",{className:`cedros-admin-user-list cedros-admin-user-list-loading ${a}`,children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{className:"cedros-admin-loading-text",children:"Loading users..."})]}):e.jsxs("div",{className:`cedros-admin-user-list ${a}`,children:[e.jsxs("div",{className:"cedros-admin-user-list-header",children:[e.jsx("h4",{className:"cedros-admin-user-list-title",children:"All Users"}),e.jsxs("div",{className:"cedros-admin-user-list-actions",children:[e.jsxs("span",{className:"cedros-admin-queue-count",children:[l," user",l!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__stats-bar-refresh",onClick:L,disabled:u,title:"Refresh list","aria-label":"Refresh list",children:u?"...":"↻"})]})]}),j.length===0?e.jsx("div",{className:"cedros-admin-empty",children:e.jsx("p",{className:"cedros-admin-empty-message",children:"No users found."})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-user-table",children:[e.jsxs("div",{className:"cedros-admin-user-thead",children:[e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="name"?"cedros-admin-sort-active":""}`,onClick:()=>F("name"),"aria-label":"Sort by user",children:["User"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="name"?S==="asc"?"↑":"↓":"↕"})]})}),e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="createdAt"?"cedros-admin-sort-active":""}`,onClick:()=>F("createdAt"),"aria-label":"Sort by registered date",children:["Registered"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="createdAt"?S==="asc"?"↑":"↓":"↕"})]})}),e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="lastLoginAt"?"cedros-admin-sort-active":""}`,onClick:()=>F("lastLoginAt"),"aria-label":"Sort by last login",children:["Last Login"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="lastLoginAt"?S==="asc"?"↑":"↓":"↕"})]})}),e.jsx("div",{className:"cedros-admin-user-th",children:e.jsxs("button",{type:"button",className:`cedros-admin-sort-button ${N==="balanceLamports"?"cedros-admin-sort-active":""}`,onClick:()=>F("balanceLamports"),"aria-label":"Sort by balance",children:["Balance"," ",e.jsx("span",{className:"cedros-admin-sort-icon",children:N==="balanceLamports"?S==="asc"?"↑":"↓":"↕"})]})})]}),$.map(m=>{const d=m.id===r;return e.jsxs("div",{className:`cedros-admin-user-row ${d?"cedros-admin-user-row-current":""}`,onClick:()=>p?.(m),onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),p?.(m))},role:p?"button":void 0,tabIndex:p?0:void 0,children:[e.jsxs("div",{className:"cedros-admin-user-td cedros-admin-user-info",children:[e.jsx("div",{className:"cedros-admin-user-avatar",children:m.picture?e.jsx("img",{src:m.picture,alt:m.name||m.email||"User",className:"cedros-admin-user-avatar-img",referrerPolicy:"no-referrer"}):e.jsx("span",{className:"cedros-admin-user-avatar-placeholder",children:(m.name?.[0]||m.email?.[0]||"?").toUpperCase()})}),e.jsxs("div",{className:"cedros-admin-user-details",children:[e.jsxs("span",{className:"cedros-admin-user-name",children:[m.name||"Unknown",d&&e.jsx("span",{className:"cedros-admin-user-you",children:"(you)"})]}),e.jsx("span",{className:"cedros-admin-user-email",title:m.email,children:m.email||ge(m.id)})]})]}),e.jsx("div",{className:"cedros-admin-user-td",children:z(m.createdAt)}),e.jsx("div",{className:"cedros-admin-user-td",children:m.lastLoginAt?z(m.lastLoginAt):"-"}),e.jsx("div",{className:"cedros-admin-user-td",children:xe(m.balanceLamports)})]},m.id)})]}),C>1&&e.jsxs("div",{className:"cedros-admin-pagination",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>P(U-1),disabled:U<=1,children:"Previous"}),e.jsxs("span",{className:"cedros-admin-page-info",children:["Page ",U," of ",C," (",l," total)"]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>P(U+1),disabled:U>=C,children:"Next"})]})]})]})}function ee(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Q(s){return new Date(s).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ye(s){return s==null?"—":`${(s/1e9).toFixed(4)} SOL`}function B(s){return s==null?"—":(s/1e9).toFixed(4)}function Ne(s){return{DEPOSIT:"Deposit",SPEND:"Spend",ADJUSTMENT:"Adjustment",REFUND:"Refund"}[s.toUpperCase()]||s}function we(s,t){return t?{deposit:"Credit deposit",purchase:"Purchase",api_call:"API usage",subscription:"Subscription",refund:"Refund",bonus:"Bonus credit",promo:"Promotional credit",correction:"Balance correction"}[t.toLowerCase()]||t:{DEPOSIT:"Credit added",SPEND:"Credit used",ADJUSTMENT:"Manual adjustment",REFUND:"Credit refunded"}[s.toUpperCase()]||"—"}function ve({userId:s,onBack:t,currentUserId:r,onEditUser:a,onAdjustCredits:b,cedrosPayEnabled:p=!1,className:j=""}){const{isLoading:l,getUser:u,getUserDeposits:h,getUserCredits:A,getUserChats:D,deleteUser:f,forcePasswordReset:T,clearError:y}=V(),[c,N]=n.useState(null),[w,S]=n.useState(null),[k,F]=n.useState(null),[$,L]=n.useState(null),[C,U]=n.useState("deposits"),[P,m]=n.useState(null),[d,i]=n.useState(null),[o,g]=n.useState(null),[R,H]=n.useState(null),[O,_]=n.useState(!1),[W,se]=n.useState(0),[G,te]=n.useState(0),[J,ae]=n.useState(0),E=10,I=n.useCallback(async()=>{try{const x=await u(s);N(x),m(null)}catch(x){m(x instanceof Error?x.message:"Failed to load user")}},[s,u]),K=n.useCallback(async()=>{try{const M=await h(s,{limit:E,offset:W});F(M),g(null)}catch(x){g(x instanceof Error?x.message:"Failed to load deposits")}},[s,h,W]),q=n.useCallback(async()=>{try{const M=await A(s,{limit:E,offset:G});S(M),i(null)}catch(x){i(x instanceof Error?x.message:"Failed to load credits")}},[s,A,G]),Y=n.useCallback(async()=>{if(p)try{const M=await D(s,{limit:E,offset:J});L(M),H(null)}catch(x){H(x instanceof Error?x.message:"Failed to load chat history")}},[s,D,J,p]);n.useEffect(()=>{I(),K(),q(),p&&Y()},[I,K,q,Y,p]);const re=async()=>{if(!c)return;if(c.id===r){alert("You cannot delete your own account");return}if(c.isSystemAdmin){alert("Cannot delete a system admin. Remove admin status first.");return}if(window.confirm(`Are you sure you want to delete ${c.name||c.email||"this user"}? This action cannot be undone.`)){_(!0);try{await f(c.id),t()}catch{}finally{_(!1)}}},ne=async()=>{if(!c?.email){alert("User has no email address");return}if(window.confirm(`Send a password reset email to ${c.email}?`)){_(!0);try{await T(c.id),alert("Password reset email sent")}catch{}finally{_(!1)}}},ie=k?Math.ceil(k.total/E):0,oe=Math.floor(W/E)+1,ce=w?Math.ceil(w.totalTransactions/E):0,de=Math.floor(G/E)+1,le=x=>{se((x-1)*E)},me=x=>{te((x-1)*E)},ue=$?Math.ceil($.total/E):0,he=Math.floor(J/E)+1,fe=x=>{ae((x-1)*E)};if(P)return e.jsxs("div",{className:`cedros-admin-user-detail cedros-admin-user-detail-error ${j}`,children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:t,children:"Back"}),e.jsx("p",{className:"cedros-admin-error",children:P}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline",onClick:()=>{y(),m(null),I()},children:"Retry"})]});if(l&&!c)return e.jsxs("div",{className:`cedros-admin-user-detail cedros-admin-user-detail-loading ${j}`,children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{className:"cedros-admin-loading-text",children:"Loading user..."})]});if(!c)return e.jsxs("div",{className:`cedros-admin-user-detail ${j}`,children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:t,children:"Back"}),e.jsx("p",{className:"cedros-admin-empty-message",children:"User not found."})]});const Z=c.id===r;return e.jsxs("div",{className:`cedros-admin-user-detail ${j}`,children:[e.jsxs("div",{className:"cedros-admin-user-detail-header",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm cedros-admin-back-btn",onClick:t,children:"Back to Users"}),e.jsxs("div",{className:"cedros-admin-user-detail-actions",children:[a&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>a(c),disabled:O,children:"Edit"}),c.email&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:ne,disabled:O,children:"Reset Password"}),b&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>b(c),disabled:O,children:"Adjust Credits"}),!Z&&!c.isSystemAdmin&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm cedros-admin-btn-danger",onClick:re,disabled:O,children:"Delete"})]})]}),e.jsxs("div",{className:"cedros-admin-user-detail-info",children:[e.jsx("div",{className:"cedros-admin-user-detail-avatar",children:c.picture?e.jsx("img",{src:c.picture,alt:c.name||c.email||"User",className:"cedros-admin-user-detail-avatar-img",referrerPolicy:"no-referrer"}):e.jsx("span",{className:"cedros-admin-user-detail-avatar-placeholder",children:(c.name?.[0]||c.email?.[0]||"?").toUpperCase()})}),e.jsxs("div",{className:"cedros-admin-user-detail-meta",children:[e.jsxs("h2",{className:"cedros-admin-user-detail-name",children:[c.name||"Unknown",Z&&e.jsx("span",{className:"cedros-admin-user-you",children:"(you)"})]}),e.jsxs("p",{className:"cedros-admin-user-detail-email",children:[c.email||"No email",c.emailVerified&&e.jsx("span",{className:"cedros-admin-verified-badge",title:"Email verified",children:"Verified"})]}),c.isSystemAdmin&&e.jsx("div",{className:"cedros-admin-user-detail-badges",children:e.jsx("span",{className:"cedros-admin-admin-badge cedros-admin-admin-badge-yes",children:"System Admin"})}),e.jsxs("div",{className:"cedros-admin-user-detail-methods",children:[e.jsx("span",{className:"cedros-admin-user-detail-methods-label",children:"Auth Methods:"}),c.authMethods.length>0?c.authMethods.map(x=>e.jsx("span",{className:`cedros-admin-auth-badge cedros-admin-auth-badge-${x}`,children:x},x)):e.jsx("span",{className:"cedros-admin-auth-badge cedros-admin-auth-badge-none",children:"none"})]}),e.jsxs("p",{className:"cedros-admin-user-detail-dates",children:["Registered: ",ee(c.createdAt)," | Updated: ",ee(c.updatedAt)]})]})]}),d?e.jsxs("div",{className:"cedros-admin-stats-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:d}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>{i(null),q()},children:"Retry"})]}):w?e.jsxs("div",{className:"cedros-admin-user-detail-stats",children:[e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Credit Balance"}),e.jsx("span",{className:"cedros-admin-stat-value",children:B(w.stats.currentBalanceLamports)})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Total Credited"}),e.jsx("span",{className:"cedros-admin-stat-value",children:B(w.stats.totalDepositedLamports)})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Total Spent"}),e.jsx("span",{className:"cedros-admin-stat-value",children:B(w.stats.totalSpentLamports)})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Deposits"}),e.jsx("span",{className:"cedros-admin-stat-value",children:w.stats.depositCount})]}),e.jsxs("div",{className:"cedros-admin-stat-card",children:[e.jsx("span",{className:"cedros-admin-stat-label",children:"Transactions"}),e.jsx("span",{className:"cedros-admin-stat-value",children:w.stats.spendCount})]})]}):e.jsxs("div",{className:"cedros-admin-stats-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading credit stats..."})]}),e.jsxs("div",{className:"cedros-admin-user-detail-tabs",children:[e.jsxs("button",{type:"button",className:`cedros-admin-tab ${C==="deposits"?"cedros-admin-tab-active":""}`,onClick:()=>U("deposits"),children:["Deposits (",k?.total??0,")"]}),e.jsxs("button",{type:"button",className:`cedros-admin-tab ${C==="transactions"?"cedros-admin-tab-active":""}`,onClick:()=>U("transactions"),children:["Credits (",w?.totalTransactions??0,")"]}),p&&e.jsxs("button",{type:"button",className:`cedros-admin-tab ${C==="chats"?"cedros-admin-tab-active":""}`,onClick:()=>U("chats"),children:["Chats (",$?.total??0,")"]})]}),e.jsxs("div",{className:"cedros-admin-user-detail-content",children:[C==="deposits"&&e.jsx(Se,{deposits:k?.deposits??[],total:k?.total??0,currentPage:oe,totalPages:ie,onPageChange:le,isLoading:l,error:o,onRetry:()=>{g(null),K()}}),C==="transactions"&&e.jsx(Ce,{transactions:w?.transactions??[],total:w?.totalTransactions??0,currentPage:de,totalPages:ce,onPageChange:me,error:d,onRetry:()=>{i(null),q()},isLoading:l}),C==="chats"&&p&&e.jsx(Ee,{sessions:$?.sessions??[],total:$?.total??0,currentPage:he,totalPages:ue,onPageChange:fe,error:R,onRetry:()=>{H(null),Y()},isLoading:l})]})]})}function Se({deposits:s,total:t,currentPage:r,totalPages:a,onPageChange:b,isLoading:p,error:j,onRetry:l}){return j?e.jsxs("div",{className:"cedros-admin-tab-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:j}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:l,children:"Retry"})]}):p&&s.length===0?e.jsxs("div",{className:"cedros-admin-tab-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading deposits..."})]}):t===0?e.jsx("div",{className:"cedros-admin-empty-message",children:"No deposits found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-list-table",children:[e.jsxs("div",{className:"cedros-admin-list-thead",children:[e.jsx("div",{className:"cedros-admin-list-th",children:"Date"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Amount"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Status"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Transaction"})]}),s.map(u=>e.jsxs("div",{className:"cedros-admin-list-row",children:[e.jsx("div",{className:"cedros-admin-list-td",children:Q(u.createdAt)}),e.jsx("div",{className:"cedros-admin-list-td",children:ye(u.amountLamports)}),e.jsx("div",{className:"cedros-admin-list-td",children:e.jsx("span",{className:`cedros-admin-status-badge cedros-admin-status-${u.status}`,children:u.status})}),e.jsx("div",{className:"cedros-admin-list-td cedros-admin-list-td-actions",children:u.txSignature?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"cedros-admin-list-td-mono",title:u.txSignature,children:[u.txSignature.slice(0,8),"..."]}),e.jsx("a",{href:`https://orbmarkets.io/tx/${u.txSignature}`,target:"_blank",rel:"noopener noreferrer",className:"cedros-admin-icon-link",title:"View on Orbmarkets","aria-label":"View transaction on Orbmarkets",children:"↗"})]}):e.jsx("span",{className:"cedros-admin-list-td-muted",children:"—"})})]},u.id))]}),a>1&&e.jsx(X,{currentPage:r,totalPages:a,total:t,onPageChange:b})]})}function Ce({transactions:s,total:t,currentPage:r,totalPages:a,onPageChange:b,isLoading:p,error:j,onRetry:l}){return j?e.jsxs("div",{className:"cedros-admin-tab-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:j}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:l,children:"Retry"})]}):p&&s.length===0?e.jsxs("div",{className:"cedros-admin-tab-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading transactions..."})]}):t===0?e.jsx("div",{className:"cedros-admin-empty-message",children:"No credit transactions found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-list-table",children:[e.jsxs("div",{className:"cedros-admin-list-thead",children:[e.jsx("div",{className:"cedros-admin-list-th",children:"Date"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Type"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Description"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Amount"})]}),s.map(u=>e.jsxs("div",{className:"cedros-admin-list-row",children:[e.jsx("div",{className:"cedros-admin-list-td",children:Q(u.createdAt)}),e.jsx("div",{className:"cedros-admin-list-td",children:e.jsx("span",{className:`cedros-admin-tx-type cedros-admin-tx-type-${u.txType.toLowerCase()}`,children:Ne(u.txType)})}),e.jsx("div",{className:"cedros-admin-list-td",children:we(u.txType,u.referenceType)}),e.jsxs("div",{className:`cedros-admin-list-td ${u.amountLamports>=0?"cedros-admin-amount-positive":"cedros-admin-amount-negative"}`,children:[u.amountLamports>=0?"+":"",B(u.amountLamports)]})]},u.id))]}),a>1&&e.jsx(X,{currentPage:r,totalPages:a,total:t,onPageChange:b})]})}function Ee({sessions:s,total:t,currentPage:r,totalPages:a,onPageChange:b,isLoading:p,error:j,onRetry:l}){return j?e.jsxs("div",{className:"cedros-admin-tab-error",children:[e.jsx("p",{className:"cedros-admin-error-inline",children:j}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:l,children:"Retry"})]}):p&&s.length===0?e.jsxs("div",{className:"cedros-admin-tab-loading",children:[e.jsx("span",{className:"cedros-admin-loading-indicator"}),e.jsx("span",{children:"Loading chat history..."})]}):t===0?e.jsx("div",{className:"cedros-admin-empty-message",children:"No chat sessions found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin-list-table",children:[e.jsxs("div",{className:"cedros-admin-list-thead",children:[e.jsx("div",{className:"cedros-admin-list-th",children:"Date"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Session"}),e.jsx("div",{className:"cedros-admin-list-th",children:"Messages"})]}),s.map(u=>e.jsxs("div",{className:"cedros-admin-list-row",children:[e.jsx("div",{className:"cedros-admin-list-td",children:Q(u.createdAt)}),e.jsx("div",{className:"cedros-admin-list-td",children:u.title||`Chat ${u.id.slice(0,8)}...`}),e.jsx("div",{className:"cedros-admin-list-td",children:u.messageCount})]},u.id))]}),a>1&&e.jsx(X,{currentPage:r,totalPages:a,total:t,onPageChange:b})]})}function X({currentPage:s,totalPages:t,total:r,onPageChange:a}){return e.jsxs("div",{className:"cedros-admin-pagination",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>a(s-1),disabled:s<=1,children:"Previous"}),e.jsxs("span",{className:"cedros-admin-page-info",children:["Page ",s," of ",t," (",r," total)"]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:()=>a(s+1),disabled:s>=t,children:"Next"})]})}const Ue=["email","google","apple","solana","webauthn","sso"],Ae={email:"Email Users",google:"Google Users",apple:"Apple Users",solana:"Solana Users",webauthn:"Passkey Users",sso:"SSO Provider Users"},ke={email:"auth_email_enabled",google:"auth_google_enabled",apple:"auth_apple_enabled",solana:"auth_solana_enabled",webauthn:"auth_webauthn_enabled",sso:"feature_sso"};function Le(){const{getStats:s}=V(),{fetchSettings:t,getValue:r}=be.useSystemSettings(),[a,b]=n.useState(null),[p,j]=n.useState(!1),[l,u]=n.useState(null),[h,A]=n.useState(!1);n.useEffect(()=>{h||(t(),A(!0))},[t,h]);const D=n.useCallback(y=>{const c=r(y);return c===void 0?!1:c==="true"||c==="1"},[r]),f=n.useCallback(async()=>{j(!0),u(null);try{const y=await s();b(y)}catch(y){u(y instanceof Error?y.message:"Failed to load user stats")}finally{j(!1)}},[s]);return n.useEffect(()=>{f()},[f]),{statsItems:n.useMemo(()=>{const y=[{label:"Total Users",value:a?.total??"—"}];return Ue.forEach(c=>{D(ke[c])&&y.push({label:Ae[c],value:a?.authMethodCounts[c]??0})}),y},[a,D]),isLoading:p,error:l,refresh:f}}exports.AdminUserDetail=ve;exports.AdminUserList=je;exports.useAdminUsers=V;exports.useUsersStatsSummary=Le;