marketmyna 0.2.0__py3-none-any.whl

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 (344) hide show
  1. marketmyna/__init__.py +14 -0
  2. marketmyna/agent/__init__.py +8 -0
  3. marketmyna/agent/agents.py +543 -0
  4. marketmyna/agent/context.py +69 -0
  5. marketmyna/agent/dashboard.py +55 -0
  6. marketmyna/agent/orchestrator.py +153 -0
  7. marketmyna/agent/sentiment.py +150 -0
  8. marketmyna/agent/skills.py +119 -0
  9. marketmyna/ai/__init__.py +1 -0
  10. marketmyna/ai/portfolio_optimizer.py +330 -0
  11. marketmyna/analysis/__init__.py +6 -0
  12. marketmyna/analysis/fundamental.py +329 -0
  13. marketmyna/analysis/sip_optimizer.py +81 -0
  14. marketmyna/analysis/technical.py +321 -0
  15. marketmyna/api/__init__.py +1 -0
  16. marketmyna/api/app.py +209 -0
  17. marketmyna/api/deps.py +63 -0
  18. marketmyna/api/middlewares/__init__.py +0 -0
  19. marketmyna/api/middlewares/auth.py +116 -0
  20. marketmyna/api/middlewares/csrf.py +66 -0
  21. marketmyna/api/middlewares/error_handler.py +38 -0
  22. marketmyna/api/middlewares/slashes.py +27 -0
  23. marketmyna/api/v1/__init__.py +0 -0
  24. marketmyna/api/v1/endpoints/__init__.py +0 -0
  25. marketmyna/api/v1/endpoints/account.py +166 -0
  26. marketmyna/api/v1/endpoints/agent.py +114 -0
  27. marketmyna/api/v1/endpoints/bot.py +38 -0
  28. marketmyna/api/v1/endpoints/calendar.py +269 -0
  29. marketmyna/api/v1/endpoints/data_sources.py +174 -0
  30. marketmyna/api/v1/endpoints/health.py +10 -0
  31. marketmyna/api/v1/endpoints/listings.py +564 -0
  32. marketmyna/api/v1/endpoints/macro.py +163 -0
  33. marketmyna/api/v1/endpoints/portfolio.py +530 -0
  34. marketmyna/api/v1/endpoints/push.py +119 -0
  35. marketmyna/api/v1/endpoints/reports.py +49 -0
  36. marketmyna/api/v1/endpoints/scheduler.py +219 -0
  37. marketmyna/api/v1/endpoints/stocks.py +400 -0
  38. marketmyna/api/v1/endpoints/system_config.py +157 -0
  39. marketmyna/api/v1/endpoints/thesis.py +112 -0
  40. marketmyna/api/v1/endpoints/trade.py +709 -0
  41. marketmyna/api/v1/endpoints/updates.py +394 -0
  42. marketmyna/api/v1/endpoints/watchlists.py +179 -0
  43. marketmyna/api/v1/router.py +43 -0
  44. marketmyna/bot/__init__.py +14 -0
  45. marketmyna/bot/commands/__init__.py +0 -0
  46. marketmyna/bot/commands/analyze.py +40 -0
  47. marketmyna/bot/commands/ask.py +51 -0
  48. marketmyna/bot/commands/base.py +35 -0
  49. marketmyna/bot/commands/batch.py +53 -0
  50. marketmyna/bot/commands/common.py +84 -0
  51. marketmyna/bot/commands/help.py +43 -0
  52. marketmyna/bot/commands/markets.py +153 -0
  53. marketmyna/bot/commands/portfolio.py +145 -0
  54. marketmyna/bot/commands/research.py +323 -0
  55. marketmyna/bot/commands/status.py +48 -0
  56. marketmyna/bot/commands/trade.py +176 -0
  57. marketmyna/bot/dispatcher.py +95 -0
  58. marketmyna/bot/formatting.py +25 -0
  59. marketmyna/bot/models.py +27 -0
  60. marketmyna/bot/registry.py +50 -0
  61. marketmyna/bot/telegram_listener.py +227 -0
  62. marketmyna/cli/__init__.py +1 -0
  63. marketmyna/cli/scheduled_run.py +292 -0
  64. marketmyna/core/__init__.py +6 -0
  65. marketmyna/core/compliance.py +53 -0
  66. marketmyna/core/config.py +377 -0
  67. marketmyna/core/constants.py +69 -0
  68. marketmyna/core/home.py +22 -0
  69. marketmyna/core/numbers.py +28 -0
  70. marketmyna/core/secret_store.py +104 -0
  71. marketmyna/core/tenant.py +130 -0
  72. marketmyna/data/__init__.py +8 -0
  73. marketmyna/data/base.py +36 -0
  74. marketmyna/data/categories.py +272 -0
  75. marketmyna/data/china.py +360 -0
  76. marketmyna/data/crypto.py +200 -0
  77. marketmyna/data/ecb_fx.py +131 -0
  78. marketmyna/data/extra_sources.py +569 -0
  79. marketmyna/data/india.py +241 -0
  80. marketmyna/data/india_filings.py +343 -0
  81. marketmyna/data/listings.py +1314 -0
  82. marketmyna/data/mutual_funds.py +34 -0
  83. marketmyna/data/news.py +98 -0
  84. marketmyna/data/news_search.py +346 -0
  85. marketmyna/data/nse_deals.py +138 -0
  86. marketmyna/data/resilience.py +173 -0
  87. marketmyna/data/sec_facts.py +252 -0
  88. marketmyna/data/shariah.py +283 -0
  89. marketmyna/data/social/__init__.py +9 -0
  90. marketmyna/data/social/base.py +100 -0
  91. marketmyna/data/social/browser.py +92 -0
  92. marketmyna/data/social/hackernews.py +53 -0
  93. marketmyna/data/social/reddit.py +397 -0
  94. marketmyna/data/social/stocktwits.py +63 -0
  95. marketmyna/data/social/valuepickr.py +53 -0
  96. marketmyna/data/stocks.py +197 -0
  97. marketmyna/data/yahoo_price.py +48 -0
  98. marketmyna/launcher.py +71 -0
  99. marketmyna/llm/__init__.py +33 -0
  100. marketmyna/llm/backend_factory.py +51 -0
  101. marketmyna/llm/backend_registry.py +19 -0
  102. marketmyna/llm/channels.py +447 -0
  103. marketmyna/llm/json_reply.py +63 -0
  104. marketmyna/llm/litellm_backend.py +197 -0
  105. marketmyna/llm/model_catalog.py +166 -0
  106. marketmyna/llm/model_health.py +193 -0
  107. marketmyna/llm/protocol.py +111 -0
  108. marketmyna/llm/providers.py +128 -0
  109. marketmyna/llm/store.py +128 -0
  110. marketmyna/notifiers/__init__.py +35 -0
  111. marketmyna/notifiers/apprise_sender.py +43 -0
  112. marketmyna/notifiers/astrbot.py +47 -0
  113. marketmyna/notifiers/bark.py +24 -0
  114. marketmyna/notifiers/base.py +80 -0
  115. marketmyna/notifiers/dingtalk.py +54 -0
  116. marketmyna/notifiers/discord.py +39 -0
  117. marketmyna/notifiers/dispatcher.py +153 -0
  118. marketmyna/notifiers/email.py +99 -0
  119. marketmyna/notifiers/feishu.py +57 -0
  120. marketmyna/notifiers/googlechat.py +24 -0
  121. marketmyna/notifiers/gotify.py +36 -0
  122. marketmyna/notifiers/matrix.py +28 -0
  123. marketmyna/notifiers/ntfy.py +36 -0
  124. marketmyna/notifiers/pushbullet.py +24 -0
  125. marketmyna/notifiers/pushover.py +41 -0
  126. marketmyna/notifiers/pushplus.py +41 -0
  127. marketmyna/notifiers/serverchan3.py +40 -0
  128. marketmyna/notifiers/settings_schema.py +119 -0
  129. marketmyna/notifiers/signal_messenger.py +25 -0
  130. marketmyna/notifiers/slack.py +36 -0
  131. marketmyna/notifiers/teams.py +37 -0
  132. marketmyna/notifiers/telegram.py +81 -0
  133. marketmyna/notifiers/twilio.py +33 -0
  134. marketmyna/notifiers/webhook.py +44 -0
  135. marketmyna/notifiers/webpush.py +222 -0
  136. marketmyna/notifiers/wechat.py +40 -0
  137. marketmyna/notifiers/whatsapp.py +27 -0
  138. marketmyna/portfolio/__init__.py +6 -0
  139. marketmyna/portfolio/analytics.py +336 -0
  140. marketmyna/portfolio/manager.py +383 -0
  141. marketmyna/portfolio/models.py +155 -0
  142. marketmyna/portfolio/optimizers.py +88 -0
  143. marketmyna/portfolio/review.py +411 -0
  144. marketmyna/services/__init__.py +1 -0
  145. marketmyna/services/accounts.py +278 -0
  146. marketmyna/services/ai_access.py +94 -0
  147. marketmyna/services/analysis_run.py +491 -0
  148. marketmyna/services/big_trades.py +335 -0
  149. marketmyna/services/brokers/__init__.py +0 -0
  150. marketmyna/services/brokers/angel.py +271 -0
  151. marketmyna/services/brokers/finnhub.py +209 -0
  152. marketmyna/services/byok_detect.py +196 -0
  153. marketmyna/services/calendar.py +748 -0
  154. marketmyna/services/central_banks.py +202 -0
  155. marketmyna/services/commodities.py +134 -0
  156. marketmyna/services/compare.py +307 -0
  157. marketmyna/services/cot.py +148 -0
  158. marketmyna/services/country_macro.py +135 -0
  159. marketmyna/services/crude_sensitivity.py +239 -0
  160. marketmyna/services/crypto_mood.py +135 -0
  161. marketmyna/services/crypto_screens.py +226 -0
  162. marketmyna/services/data_export.py +91 -0
  163. marketmyna/services/dcf.py +220 -0
  164. marketmyna/services/dcf_model.py +194 -0
  165. marketmyna/services/delivery.py +142 -0
  166. marketmyna/services/discovery.py +146 -0
  167. marketmyna/services/dividends.py +95 -0
  168. marketmyna/services/earnings.py +305 -0
  169. marketmyna/services/econ_calendar.py +495 -0
  170. marketmyna/services/eia_stocks.py +115 -0
  171. marketmyna/services/estimates.py +109 -0
  172. marketmyna/services/etf.py +236 -0
  173. marketmyna/services/etf_rotation.py +193 -0
  174. marketmyna/services/etf_screens.py +196 -0
  175. marketmyna/services/financials.py +639 -0
  176. marketmyna/services/fund_ai.py +181 -0
  177. marketmyna/services/fund_analytics.py +371 -0
  178. marketmyna/services/fund_cost.py +147 -0
  179. marketmyna/services/fund_holdings.py +664 -0
  180. marketmyna/services/fund_peers.py +247 -0
  181. marketmyna/services/fund_rotation.py +206 -0
  182. marketmyna/services/fund_style.py +179 -0
  183. marketmyna/services/funds.py +70 -0
  184. marketmyna/services/hot_stocks.py +358 -0
  185. marketmyna/services/india_flows.py +263 -0
  186. marketmyna/services/india_rates.py +258 -0
  187. marketmyna/services/investor_lenses.py +271 -0
  188. marketmyna/services/leadership.py +165 -0
  189. marketmyna/services/live_market.py +497 -0
  190. marketmyna/services/live_quotes.py +295 -0
  191. marketmyna/services/macro.py +182 -0
  192. marketmyna/services/market_calendar.py +399 -0
  193. marketmyna/services/market_mood.py +168 -0
  194. marketmyna/services/market_valuation.py +231 -0
  195. marketmyna/services/mf_holdings.py +199 -0
  196. marketmyna/services/mf_insights.py +132 -0
  197. marketmyna/services/mf_lumpsum.py +587 -0
  198. marketmyna/services/mf_portfolio_ai.py +195 -0
  199. marketmyna/services/nse_events.py +98 -0
  200. marketmyna/services/overview.py +366 -0
  201. marketmyna/services/ownership.py +143 -0
  202. marketmyna/services/quality_scores.py +199 -0
  203. marketmyna/services/rates.py +335 -0
  204. marketmyna/services/reconcile.py +343 -0
  205. marketmyna/services/report.py +584 -0
  206. marketmyna/services/report_i18n.py +678 -0
  207. marketmyna/services/rotation.py +224 -0
  208. marketmyna/services/runtime_scheduler.py +548 -0
  209. marketmyna/services/schedule_config.py +251 -0
  210. marketmyna/services/schedule_time.py +39 -0
  211. marketmyna/services/screens.py +398 -0
  212. marketmyna/services/sec_mdna.py +173 -0
  213. marketmyna/services/shariah.py +246 -0
  214. marketmyna/services/sip.py +148 -0
  215. marketmyna/services/sip_days.py +362 -0
  216. marketmyna/services/smart_file.py +595 -0
  217. marketmyna/services/smart_pdf.py +425 -0
  218. marketmyna/services/smart_report.py +370 -0
  219. marketmyna/services/social_sentiment.py +511 -0
  220. marketmyna/services/thesis.py +328 -0
  221. marketmyna/services/translate.py +146 -0
  222. marketmyna/services/valuation.py +173 -0
  223. marketmyna/services/worker_pool.py +149 -0
  224. marketmyna/services/world_markets.py +208 -0
  225. marketmyna/storage.py +722 -0
  226. marketmyna/strategies/README.md +51 -0
  227. marketmyna/strategies/bottom_volume.yaml +49 -0
  228. marketmyna/strategies/box_oscillation.yaml +69 -0
  229. marketmyna/strategies/bull_trend.yaml +49 -0
  230. marketmyna/strategies/chan_theory.yaml +58 -0
  231. marketmyna/strategies/dragon_head.yaml +44 -0
  232. marketmyna/strategies/emotion_cycle.yaml +79 -0
  233. marketmyna/strategies/event_driven.yaml +54 -0
  234. marketmyna/strategies/expectation_repricing.yaml +54 -0
  235. marketmyna/strategies/growth_quality.yaml +54 -0
  236. marketmyna/strategies/hot_theme.yaml +54 -0
  237. marketmyna/strategies/ma_golden_cross.yaml +46 -0
  238. marketmyna/strategies/one_yang_three_yin.yaml +37 -0
  239. marketmyna/strategies/shrink_pullback.yaml +46 -0
  240. marketmyna/strategies/volume_breakout.yaml +47 -0
  241. marketmyna/strategies/wave_theory.yaml +64 -0
  242. marketmyna/trading/__init__.py +2 -0
  243. marketmyna/trading/alerts.py +356 -0
  244. marketmyna/trading/backtest.py +317 -0
  245. marketmyna/trading/charges.py +82 -0
  246. marketmyna/trading/chart.py +197 -0
  247. marketmyna/trading/indicators.py +303 -0
  248. marketmyna/trading/journal.py +74 -0
  249. marketmyna/trading/knn.py +164 -0
  250. marketmyna/trading/lots.py +109 -0
  251. marketmyna/trading/market_hours.py +66 -0
  252. marketmyna/trading/options.py +554 -0
  253. marketmyna/trading/pairs.py +94 -0
  254. marketmyna/trading/risk.py +170 -0
  255. marketmyna/trading/scanner.py +500 -0
  256. marketmyna/trading/volatility.py +163 -0
  257. marketmyna/utils/__init__.py +1 -0
  258. marketmyna/utils/deadline.py +36 -0
  259. marketmyna/utils/log_redact.py +52 -0
  260. marketmyna/utils/yahoo_gate.py +183 -0
  261. marketmyna/utils/yf_lock.py +12 -0
  262. marketmyna/web/apple-touch-icon.png +0 -0
  263. marketmyna/web/assets/Account-CA9NFDKO.js +1 -0
  264. marketmyna/web/assets/Analyze-uM0srB_U.js +7 -0
  265. marketmyna/web/assets/AreaChart-2i67V6Jf.js +1 -0
  266. marketmyna/web/assets/BarChart-_yngarVl.js +3 -0
  267. marketmyna/web/assets/Bot-E4gpf1qZ.js +1 -0
  268. marketmyna/web/assets/CandleChart-CioqTqMV.js +1 -0
  269. marketmyna/web/assets/Compare-D6_2CPl4.js +1 -0
  270. marketmyna/web/assets/ExportMenu-DaZ1xVmW.js +1 -0
  271. marketmyna/web/assets/LineChart-BaOkD1Ta.js +57 -0
  272. marketmyna/web/assets/Markets-BMw_M1sJ.js +1 -0
  273. marketmyna/web/assets/Portfolio-DQEdHVc2.js +1 -0
  274. marketmyna/web/assets/ReportView-BzhdcqSh.js +1 -0
  275. marketmyna/web/assets/Scheduler-I9PDKxTd.js +1 -0
  276. marketmyna/web/assets/Settings-DpXfHolW.js +3 -0
  277. marketmyna/web/assets/SipDays-C9q3bNSx.js +1 -0
  278. marketmyna/web/assets/SymbolSearch-CBOVPEk1.js +1 -0
  279. marketmyna/web/assets/Trade-_CM7HC4H.js +2 -0
  280. marketmyna/web/assets/TradeChart-ZjsycacC.js +1 -0
  281. marketmyna/web/assets/WatchButton-ComYW56_.js +1 -0
  282. marketmyna/web/assets/Watchlist-DAjLb0jd.js +1 -0
  283. marketmyna/web/assets/app-BP1o7WZS.js +1 -0
  284. marketmyna/web/assets/app-BkIUKdld.js +1 -0
  285. marketmyna/web/assets/app-CKeSYhEt.js +1 -0
  286. marketmyna/web/assets/app-CN1OERYX.js +1 -0
  287. marketmyna/web/assets/app-DIQllha5.js +1 -0
  288. marketmyna/web/assets/app-DeiAW0tX.js +1 -0
  289. marketmyna/web/assets/br-Cu5YU29T.svg +45 -0
  290. marketmyna/web/assets/browser-CR-ks2Fp.js +19 -0
  291. marketmyna/web/assets/browser-D5K_K_gj.js +1 -0
  292. marketmyna/web/assets/common-0wvpAVpd.js +1 -0
  293. marketmyna/web/assets/common-3ghy53Us.js +1 -0
  294. marketmyna/web/assets/common-Bib2unjX.js +1 -0
  295. marketmyna/web/assets/common-BvSJP0w_.js +1 -0
  296. marketmyna/web/assets/common-CSfyC0Sp.js +1 -0
  297. marketmyna/web/assets/common-C_t-iZPf.js +1 -0
  298. marketmyna/web/assets/compare-DMcsx70H.js +1 -0
  299. marketmyna/web/assets/es-d5m8M5h8.svg +544 -0
  300. marketmyna/web/assets/exporter-DiMg2O5d.js +3 -0
  301. marketmyna/web/assets/files-CpgiZRbN.js +1 -0
  302. marketmyna/web/assets/format-d8InM0Zw.js +9 -0
  303. marketmyna/web/assets/html2canvas-Bw0OShmD.js +5 -0
  304. marketmyna/web/assets/index-CKAnq-Or.js +12 -0
  305. marketmyna/web/assets/index-D4U8E6LH.css +2 -0
  306. marketmyna/web/assets/index.es-iBEw7jOv.js +5 -0
  307. marketmyna/web/assets/ir-cCIgaNf6.svg +219 -0
  308. marketmyna/web/assets/jspdf.es.min-C4285IdL.js +79 -0
  309. marketmyna/web/assets/jspdf.plugin.autotable-2eOJeXl-.js +2 -0
  310. marketmyna/web/assets/lightweight-charts.production-BF2noug5.js +1 -0
  311. marketmyna/web/assets/listings-BefgXpb1.js +1 -0
  312. marketmyna/web/assets/liveQuotes-CtSmCUFA.js +1 -0
  313. marketmyna/web/assets/markets-BI4AhI9W.js +1 -0
  314. marketmyna/web/assets/markets-BUHUdYpT.js +1 -0
  315. marketmyna/web/assets/markets-BqvN1Bvf.js +1 -0
  316. marketmyna/web/assets/markets-DPO40TTe.js +1 -0
  317. marketmyna/web/assets/markets-bsiPo-Tk.js +1 -0
  318. marketmyna/web/assets/markets-ff1e792u.js +1 -0
  319. marketmyna/web/assets/montecarlo-BsNlH2qe.js +1 -0
  320. marketmyna/web/assets/options-BYAZnwzW.js +1 -0
  321. marketmyna/web/assets/preload-helper-BLdHbfdN.js +1 -0
  322. marketmyna/web/assets/purify.es-Dqk5qvad.js +3 -0
  323. marketmyna/web/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  324. marketmyna/web/assets/sa-Dh79zbT9.svg +25 -0
  325. marketmyna/web/assets/toast-DDradTZw.js +1 -0
  326. marketmyna/web/assets/trade-fndw1Ql3.js +1 -0
  327. marketmyna/web/assets/ui-gsFb8B2m.js +1 -0
  328. marketmyna/web/assets/watchlists-B6YqwUIk.js +1 -0
  329. marketmyna/web/brand/logo-mark.webp +0 -0
  330. marketmyna/web/favicon.png +0 -0
  331. marketmyna/web/icon-192.png +0 -0
  332. marketmyna/web/icon-512.png +0 -0
  333. marketmyna/web/index.html +34 -0
  334. marketmyna/web/manifest.webmanifest +28 -0
  335. marketmyna/web/robots.txt +2 -0
  336. marketmyna/web/sw.js +40 -0
  337. marketmyna/web/theme-init.js +37 -0
  338. marketmyna-0.2.0.dist-info/METADATA +345 -0
  339. marketmyna-0.2.0.dist-info/RECORD +344 -0
  340. marketmyna-0.2.0.dist-info/WHEEL +5 -0
  341. marketmyna-0.2.0.dist-info/entry_points.txt +2 -0
  342. marketmyna-0.2.0.dist-info/licenses/LICENSE +202 -0
  343. marketmyna-0.2.0.dist-info/licenses/NOTICE +22 -0
  344. marketmyna-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{b as t,c as n,d as r,f as i,i as a,l as o,n as s,o as c,p as l,s as u,t as d}from"./format-d8InM0Zw.js";import{t as f}from"./toast-DDradTZw.js";import{C as p,D as m,O as h,_ as g,b as _,f as v,g as y,i as b,l as x,m as S,p as C,r as w,s as T,t as E,y as ee}from"./ui-gsFb8B2m.js";import{M as te,O as D,j as O,k as ne,n as re,t as k}from"./index-CKAnq-Or.js";import{o as A,t as j}from"./AreaChart-2i67V6Jf.js";import{R as M,a as N,i as ie,pt as P,r as F,t as I,u as ae,yt as L}from"./LineChart-BaOkD1Ta.js";import{n as oe,r as se,t as ce}from"./BarChart-_yngarVl.js";import{a as R,c as le,i as ue,n as de,o as fe,r as pe,s as me,t as he}from"./WatchButton-ComYW56_.js";import{_ as ge,f as _e,g as ve,i as ye,n as be,r as xe,t as Se,v as Ce,x as we}from"./listings-BefgXpb1.js";import{a as Te,n as Ee}from"./options-BYAZnwzW.js";import{t as z}from"./compare-DMcsx70H.js";import{i as B,t as De}from"./SipDays-C9q3bNSx.js";import{t as Oe}from"./ExportMenu-DaZ1xVmW.js";import{n as ke,r as Ae,t as je}from"./liveQuotes-CtSmCUFA.js";var V=e(t(),1),Me=`marketmyna.english-names`,Ne=`marketmyna:english-names`,H=/[㐀-鿿]/,Pe=e=>!!e&&H.test(e);function Fe(){try{return localStorage.getItem(Me)===`1`}catch{return!1}}function Ie(e){try{localStorage.setItem(Me,e?`1`:`0`)}catch{}window.dispatchEvent(new Event(Ne))}function Le(){return(0,V.useSyncExternalStore)(e=>(window.addEventListener(Ne,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(Ne,e),window.removeEventListener(`storage`,e)}),Fe,()=>!1)}var Re=new Map,ze=new Map;function Be(e,t,n=[]){let r=Le(),[,i]=(0,V.useState)(0),a=r?t.filter(t=>Pe(t.name)&&!Re.has(`${e}:${t.symbol}`)):[],o=r?[...new Set(n.filter(e=>Pe(e)&&!ze.has(e)))]:[],s=a.map(e=>e.symbol).join(`,`)+`|`+o.join(`|`);return(0,V.useEffect)(()=>{if(!a.length&&!o.length)return;let t=!0;return h.post(`/translate`,{market:e,names:a.map(e=>({symbol:e.symbol,name:e.name})),texts:o},{timeout:9e4}).then(({data:n})=>{for(let[t,r]of Object.entries(n.names))Re.set(`${e}:${t}`,r);for(let[e,t]of Object.entries(n.texts))ze.set(e,t);t&&i(e=>e+1)}).catch(()=>void 0),()=>{t=!1}},[e,s]),{on:r,loading:a.length+o.length>0,name:(t,n)=>r&&Pe(n)&&Re.get(`${e}:${t}`)||n||t,text:e=>r&&e&&ze.get(e)||e||``}}var U=l();function Ve({loading:e=!1,className:t}){let n=Le();return(0,U.jsxs)(`button`,{type:`button`,onClick:()=>Ie(!n),title:n?`Showing English names - click for the original Chinese`:`Show Chinese names in English`,className:m(`inline-flex shrink-0 items-center gap-1.5 rounded-md border px-2 py-1 text-xs whitespace-nowrap`,n?`border-accent bg-accent/10 text-fg`:`border-line text-muted hover:border-line-strong hover:text-fg`,t),children:[e&&n?(0,U.jsx)(_,{className:`h-3 w-3 text-accent`}):(0,U.jsx)(`span`,{"aria-hidden":!0,children:n?`EN`:`中`}),`English names`]})}var He=(0,V.createContext)(!0),W=e=>t=>t.live?.open?e:3e5,G=6e5;function K(e,t,n){let r=(0,V.useContext)(He),[i,a]=(0,V.useState)(null),[o,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(null),[d,f]=(0,V.useState)(0),[p,m]=(0,V.useState)(0),h=(0,V.useRef)(e);h.current=e;let g=(0,V.useRef)(n);g.current=n;let _=(0,V.useRef)(0);return(0,V.useEffect)(()=>{let e=new AbortController;return a(null),c(null),u(null),h.current(e.signal).then(e=>{a(e),u(Date.now())}).catch(t=>{e.signal.aborted||c(s(t))}),()=>e.abort()},[...t,p]),(0,V.useEffect)(()=>{if(!r||i==null||l==null)return;let e=g.current,t=typeof e==`function`?e(i):e,n=new AbortController,o,s=async()=>{if(document.visibilityState!==`visible`)o=setTimeout(s,2e3);else{_.current=Date.now();try{let e=await h.current(n.signal);if(n.signal.aborted)return;a(e),u(Date.now()),c(null)}catch{}n.signal.aborted||f(e=>e+1)}};return o=setTimeout(s,Math.max(0,Math.max(l,_.current)+t-Date.now())),()=>{clearTimeout(o),n.abort()}},[r,i==null,l,d]),{data:i,error:o,at:l,reload:()=>m(e=>e+1)}}function Ue(e){let t=(0,V.useRef)({}),[n,r]=(0,V.useState)({}),i=JSON.stringify(e);return(0,V.useEffect)(()=>{let n=Date.now(),i={};for(let[r,a]of Object.entries(e)){if(a==null)continue;let e=t.current[r];e!=null&&e!==a&&(i[r]={dir:a>e?`up`:`down`,until:n+1200}),t.current[r]=a}Object.keys(i).length&&r(e=>({...e,...i}))},[i]),e=>{let t=n[e];return t&&t.until>Date.now()?`flash-${t.dir}`:``}}function We(e){return e<5?`just now`:e<90?`${Math.round(e)}s ago`:e<5400?`${Math.round(e/60)} min ago`:`${Math.round(e/3600)} h ago`}function q({live:e,at:t,daily:n,ticking:r}){let[i,a]=(0,V.useState)(()=>Date.now());if((0,V.useEffect)(()=>{let t=window.setInterval(()=>a(Date.now()),e?.open?1e3:15e3);return()=>window.clearInterval(t)},[e?.open]),!e||!e.live)return!n||t==null?null:(0,U.jsxs)(`span`,{className:`text-[11px] text-faint`,children:[n,` · checked `,We((i-t)/1e3)]});let o=e.age_seconds!=null&&t!=null?e.age_seconds+(i-t)/1e3:null,s=r??o;return(0,U.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted`,title:`${e.source} · ${e.covered.toLocaleString()} priced live`,children:[(0,U.jsxs)(`span`,{className:m(`inline-flex items-center gap-1 font-medium`,e.open?`text-up`:`text-muted`),children:[(0,U.jsx)(`span`,{className:m(`h-1.5 w-1.5 rounded-full`,e.open?`animate-pulse bg-up`:`bg-faint`)}),e.open?`Live`:`Market closed`]}),(0,U.jsx)(`span`,{children:e.open?`prices updated ${s==null?`…`:We(s)}`:`last session's prices`}),e.error&&(0,U.jsxs)(`span`,{className:`text-warn`,children:[`· `,e.error]})]})}var Ge=[{value:`1`,label:`Latest day`},{value:`7`,label:`7 days`}],Ke={us:[`Reading the latest insider filings (Form 4)…`,`Keeping open-market buys and sells…`,`Sorting by dollar value…`],china_a:[`Fetching Shanghai and Shenzhen block trades…`,`Sorting by deal size…`],hong_kong:[`Fetching southbound Stock Connect flows…`,`Sorting by net amount…`],crypto:[`Reading big-trader positioning from crypto futures…`,`Comparing open interest over the week…`]},qe=e=>e.includes(`buy`)||e===`premium`?`text-up`:e.includes(`sell`)||e===`discount`?`text-down`:`text-muted`;function Je({data:e}){let[t,n]=(0,V.useState)(!1),r=e.deals??[],i=r.slice(0,t?200:20),a=Be(e.market,i,i.map(e=>e.client));return r.length?(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`ul`,{className:`divide-y divide-line text-sm`,children:i.map((t,n)=>(0,U.jsxs)(`li`,{className:`flex items-start justify-between gap-3 py-1.5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`truncate`,children:[(0,U.jsx)(D,{to:`/analyze?symbol=${encodeURIComponent(t.symbol)}&market=${e.market}`,className:`me-2 font-mono hover:text-accent-fg`,children:t.symbol}),(0,U.jsx)(`span`,{className:`text-muted`,title:t.name_local??t.name??void 0,children:a.name(t.symbol,t.name)})]}),(0,U.jsxs)(`div`,{className:`truncate text-[12px] text-faint`,title:t.client??void 0,children:[t.date,` · `,a.text(t.client),t.remarks?` · ${t.remarks}`:``]})]}),(0,U.jsxs)(`div`,{className:`shrink-0 text-end`,children:[(0,U.jsx)(`div`,{className:m(`text-xs font-medium uppercase`,qe(t.side)),children:t.side}),(0,U.jsxs)(`div`,{className:`tabular text-[12px] text-faint`,children:[t.qty!=null&&t.price!=null?`${d(t.qty)} @ ${c(t.price)} · `:``,t.value==null?``:`${e.currency}${d(t.value)}`]})]})]},n))}),r.length>20&&(0,U.jsx)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`mt-1 text-xs text-accent-fg hover:underline`,children:t?`Show fewer`:`Show all ${r.length}`})]}):(0,U.jsx)(`p`,{className:`text-sm text-muted`,children:`No trades in this window.`})}function Ye({rows:e}){return(0,U.jsx)(`div`,{className:`overflow-x-auto`,children:(0,U.jsxs)(`table`,{className:`tabular w-full min-w-[36rem] text-sm`,children:[(0,U.jsx)(`thead`,{className:`text-xs text-muted`,children:(0,U.jsxs)(`tr`,{className:`border-b border-line`,children:[(0,U.jsx)(`th`,{className:`py-2 text-start font-medium`,children:`Coin`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-start font-medium`,children:`Top traders long`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`L/S ratio`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Open interest`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`OI 1d`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`OI 7d`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Taker buy/sell`})]})}),(0,U.jsx)(`tbody`,{className:`divide-y divide-line`,children:e.map(e=>(0,U.jsxs)(`tr`,{children:[(0,U.jsx)(`td`,{className:`py-2`,children:(0,U.jsx)(D,{to:`/analyze?symbol=${e.coin}-USD&market=crypto`,className:`font-mono text-xs font-medium hover:text-accent-fg`,children:e.coin})}),(0,U.jsx)(`td`,{className:`px-2 py-2`,children:(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`div`,{className:`flex h-1.5 w-24 overflow-hidden rounded-full bg-down/60`,children:(0,U.jsx)(`div`,{className:`bg-up`,style:{width:`${e.top_long_pct}%`}})}),(0,U.jsxs)(`span`,{className:`text-xs`,children:[c(e.top_long_pct,0),`%`]})]})}),(0,U.jsxs)(`td`,{className:`px-2 py-2 text-end`,children:[c(e.top_ratio,2),(0,U.jsx)(`span`,{className:m(`ms-1 text-[12px]`,i(e.top_ratio_change)),children:e.top_ratio_change>0?`▲`:e.top_ratio_change<0?`▼`:``})]}),(0,U.jsxs)(`td`,{className:`px-2 py-2 text-end`,children:[`$`,d(e.open_interest)]}),(0,U.jsx)(`td`,{className:m(`px-2 py-2 text-end`,i(e.oi_change_1d)),children:u(e.oi_change_1d,1)}),(0,U.jsx)(`td`,{className:m(`px-2 py-2 text-end`,i(e.oi_change_7d)),children:u(e.oi_change_7d,1)}),(0,U.jsx)(`td`,{className:m(`px-2 py-2 text-end`,e.taker_ratio==null?``:e.taker_ratio>=1?`text-up`:`text-down`),children:c(e.taker_ratio,2)})]},e.coin))})]})})}function J({market:e}){let[t,n]=(0,V.useState)(`1`),r=e===`china_a`||e===`hong_kong`,{data:i,error:a,at:o}=K(n=>be(e,r?Number(t):1,n),[e,t,r],G);return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-5 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:i?.title??`Big trades`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:i?.subtitle??`Large trades and positioning by big investors`}),(0,U.jsx)(q,{at:o,daily:`Checked for new trades every 10 min`})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e===`china_a`&&(0,U.jsx)(Ve,{}),r&&(0,U.jsx)(y,{size:`sm`,value:t,onChange:n,options:Ge})]})]}),(0,U.jsxs)(`div`,{className:`space-y-2 px-5 pb-4`,children:[a&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:a}),!i&&!a&&(0,U.jsx)(B,{className:`min-h-56`,steps:Ke[e]??[`Loading…`]}),i&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(S,{children:i.positions?(0,U.jsx)(Ye,{rows:i.positions}):(0,U.jsx)(Je,{data:i})}),(0,U.jsx)(`p`,{className:`text-[12px] text-faint`,children:i.note})]})]})]})}async function Xe(e){return(await h.get(`/macro`,{signal:e})).data}async function Ze(e){return(await h.get(`/macro/commodities`,{signal:e})).data}async function Qe(e){return(await h.get(`/macro/cot`,{signal:e})).data}async function $e(e){return(await h.get(`/macro/eia`,{signal:e})).data}async function et(e){return(await h.get(`/macro/yield-curve`,{signal:e})).data}async function tt(e){return(await h.get(`/macro/india`,{signal:e,timeout:6e4})).data}async function nt(e=`india`,t){return(await h.get(`/macro/crude-sensitivity`,{params:{market:e},signal:t,timeout:9e4})).data}async function rt(e,t){return(await h.get(`/macro/rates`,{params:{market:e},signal:t,timeout:9e4})).data}async function it(e){return(await h.get(`/macro/world`,{signal:e})).data}async function at(e){return(await h.get(`/macro/valuation`,{signal:e})).data}async function ot(e,t){return(await h.get(`/macro/countries`,{params:{codes:e.join(`,`)},signal:t})).data}async function st(e){return(await h.get(`/macro/central-banks`,{signal:e})).data}async function ct(e){return(await h.get(`/macro/india-flows`,{signal:e})).data}async function lt(e,t){return(await h.get(`/macro/mood`,{params:{market:e},signal:t})).data}var ut=8;function dt(e){return e==null?`—`:c(e,Number.isInteger(Math.round(e*1e3)/10)?2:3)}function ft(e){return e.changed_between?`${e.direction===`cut`?`Cut`:`Raised`} from ${dt(e.previous)}% after ${e.changed_between[0]}`:!e.last_change||e.previous==null?`No change in 2 years`:`${e.direction===`cut`?`Cut`:`Raised`} from ${dt(e.previous)}% on ${e.last_change}`}function pt(){let[e,t]=(0,V.useState)(null),[n,i]=(0,V.useState)(null),[a,o]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1);(0,V.useEffect)(()=>{let e=new AbortController;return st(e.signal).then(e=>{t(e.rows),i({stale:e.stale,source:e.source})}).catch(t=>!e.signal.aborted&&o(s(t))),()=>e.abort()},[]);let d=e?l?e:e.slice(0,ut):[],f=e=>Date.now()-new Date(e).getTime()>5184e6;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Central bank rates`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Policy rate, last move, change over a year and the rate after inflation`})]}),(0,U.jsxs)(`div`,{className:`space-y-3 px-5 pb-4`,children:[a&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:a}),!e&&!a&&(0,U.jsx)(B,{className:`min-h-40`,steps:[`Fetching policy rates…`]}),e&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`overflow-x-auto`,children:(0,U.jsxs)(`table`,{className:`w-full min-w-[600px] text-sm`,children:[(0,U.jsx)(`thead`,{children:(0,U.jsxs)(`tr`,{className:`text-start text-xs text-muted`,children:[(0,U.jsx)(`th`,{className:`py-1 pe-3 font-medium`,children:`Economy`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:`Rate`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 font-medium`,children:`Last move`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:`1y change`}),(0,U.jsx)(`th`,{className:`py-1 text-end font-medium`,title:`Policy rate minus the IMF's inflation projection for this year`,children:`Real rate`})]})}),(0,U.jsx)(`tbody`,{children:d.map(e=>(0,U.jsxs)(`tr`,{className:`border-t border-line`,children:[(0,U.jsxs)(`td`,{className:`py-1.5 pe-3`,title:e.bank,children:[e.name,(0,U.jsxs)(`div`,{className:`text-[11px] text-faint`,children:[e.bank,f(e.as_of)&&` · data to ${e.as_of}`]})]}),(0,U.jsxs)(`td`,{className:`tabular py-1.5 pe-3 text-end font-semibold`,children:[dt(e.rate),`%`]}),(0,U.jsx)(`td`,{className:`py-1.5 pe-3 text-xs ${e.direction===`cut`?`text-up`:e.direction===`hike`?`text-down`:`text-muted`}`,children:ft(e)}),(0,U.jsx)(`td`,{className:`tabular py-1.5 pe-3 text-end`,children:e.change_1y==null?`—`:`${r(e.change_1y,2)} pts`}),(0,U.jsx)(`td`,{className:`tabular py-1.5 text-end`,title:e.inflation==null?void 0:`IMF inflation ${c(e.inflation,1)}%`,children:e.real_rate==null?`—`:`${r(e.real_rate,2)}%`})]},e.area))})]})}),e.length>ut&&(0,U.jsx)(`button`,{type:`button`,className:`text-xs text-muted underline hover:text-fg`,onClick:()=>u(e=>!e),children:l?`Show fewer`:`Show all ${e.length}`}),n&&(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Source: `,n.source,n.stale?` (saved copy: the BIS did not answer)`:``,`. Cuts are shown green and hikes red as a convention, not a judgement.`]})]})]})]})}function mt({values:e,up:t}){let n=t?`var(--color-up)`:`var(--color-down)`;return(0,U.jsx)(`div`,{className:`h-10 w-16 shrink-0 sm:w-20`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(j,{data:e.map(e=>({v:e})),margin:{top:2,right:0,bottom:2,left:0},children:[(0,U.jsx)(F,{hide:!0,domain:[`auto`,`auto`]}),(0,U.jsx)(se,{type:`monotone`,dataKey:`v`,stroke:n,strokeWidth:1.5,fill:n,fillOpacity:.12,isAnimationActive:!1})]})})})}var ht=[{key:`india`,label:`In rupees`},{key:`metals`,label:`Metals`},{key:`energy`,label:`Energy`},{key:`agri`,label:`Grains`}];function gt(e){return e.unit.startsWith(`₹`)?e.price.toLocaleString(`en-IN`,{style:`currency`,currency:`INR`,maximumFractionDigits:0}):c(e.price,e.price<20?3:2)}function _t({market:e}){let{data:t,error:n,at:r}=K(e=>Ze(e),[],W(6e4)),i=t?.items??null,a=Ue(Object.fromEntries((i??[]).map(e=>[e.key,e.price]))),[o,s]=(0,V.useState)(null),[c,l]=(0,V.useState)(null);(0,V.useEffect)(()=>{if(!i||o)return;let e=new AbortController;return Qe(e.signal).then(s).catch(()=>!e.signal.aborted&&s({items:[],as_of:null,source:``})),()=>e.abort()},[i,o]),(0,V.useEffect)(()=>{if(!i||c)return;let e=new AbortController;return $e(e.signal).then(l).catch(()=>!e.signal.aborted&&l({items:[],week_ending:null,source:``})),()=>e.abort()},[i,c]);let u=e===`india`?ht:[...ht.slice(1),ht[0]];return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 px-5 py-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Commodities`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Gold, silver, oil, gas, copper and grains (front-month futures)`}),t&&(0,U.jsx)(q,{live:t.live,at:r})]})}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[n&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:n}),!i&&!n&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Fetching metal prices…`,`Fetching energy prices…`,`Converting to rupees…`]}),i&&i.length===0&&(0,U.jsx)(`p`,{className:`text-sm text-muted`,children:`Commodity prices are unavailable right now.`}),i&&u.map(e=>{let t=i.filter(t=>t.group===e.key);return t.length?(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:e.label}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:t.map(e=>(0,U.jsx)(vt,{c:e,flash:a(e.key)},e.key))})]},e.key):null}),i&&i.length>0&&(0,U.jsx)(`p`,{className:`text-[12px] text-faint`,children:`Source: futures prices from our market data feed, delayed. Rupee prices are international prices converted at the day's USD/INR, before import duty and GST, so MCX and jeweller prices run higher.`}),i&&i.length>0&&(0,U.jsx)(bt,{cot:o}),i&&i.length>0&&(0,U.jsx)(St,{eia:c})]})]})}function vt({c:e,flash:t}){let n=e.spark.length<2||e.spark[e.spark.length-1]>=e.spark[0];return(0,U.jsxs)(`div`,{className:m(`rounded-lg bg-canvas px-3 py-2`,t),title:e.note,children:[(0,U.jsxs)(`div`,{className:`flex justify-between gap-2 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`truncate`,children:e.label}),(0,U.jsx)(`span`,{className:`shrink-0 text-faint`,children:e.unit})]}),(0,U.jsxs)(`div`,{className:`flex items-end justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`tabular text-lg font-semibold`,children:gt(e)}),(0,U.jsxs)(`div`,{className:`tabular whitespace-nowrap text-[11px] text-faint`,children:[`1d `,(0,U.jsx)(`span`,{className:i(e.change_1d),children:u(e.change_1d,1)}),` · 1y`,` `,(0,U.jsx)(`span`,{className:i(e.change_1y),children:u(e.change_1y,1)})]})]}),(0,U.jsx)(mt,{values:e.spark,up:n})]})]})}function yt(e){return(e>0?`+`:e<0?`−`:``)+Math.abs(e).toLocaleString(`en-US`)}function bt({cot:e}){return e?e.items.length?(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-baseline justify-between gap-x-3 text-xs`,children:[(0,U.jsx)(`span`,{className:`font-medium text-muted`,children:`Fund positioning (CFTC)`}),(0,U.jsxs)(`span`,{className:`text-faint`,children:[`Positions as of `,e.as_of]})]}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:e.items.map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsxs)(`div`,{className:`flex justify-between gap-2 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`truncate`,children:e.label}),(0,U.jsx)(`span`,{className:`shrink-0 text-faint`,children:e.net_pct_oi==null?``:`${e.net_pct_oi}% of OI`})]}),(0,U.jsxs)(`div`,{className:`tabular text-sm font-semibold`,title:`Managed money (hedge funds, CTAs) long minus short, in contracts`,children:[yt(e.managed_money_net),` `,(0,U.jsx)(`span`,{className:`text-[11px] font-normal text-faint`,children:`net contracts`})]}),(0,U.jsxs)(`div`,{className:`tabular text-[11px] text-faint`,children:[`1w `,(0,U.jsx)(`span`,{className:i(e.net_change_1w),children:e.net_change_1w==null?`—`:yt(e.net_change_1w)}),` · `,`producers `,yt(e.producer_net)]}),e.index_3y!=null&&(0,U.jsxs)(`div`,{className:`mt-1.5`,title:`3-year position index ${e.index_3y} (0 = most short, 100 = most long in 3 years)`,children:[(0,U.jsx)(`div`,{className:`relative h-1.5 rounded-full bg-line`,children:(0,U.jsx)(`div`,{className:`absolute top-1/2 h-3 w-1 -translate-x-1/2 -translate-y-1/2 rounded-sm bg-fg`,style:{left:`${e.index_3y}%`}})}),(0,U.jsxs)(`div`,{className:`mt-1 text-[11px] text-muted`,children:[e.reading,` (`,e.index_3y,`/100)`]})]})]},e.key))}),(0,U.jsxs)(`p`,{className:`mt-2 text-[12px] text-faint`,children:[`Source: `,e.source,`. Shows how positions stand, not where prices will go. Brent is not covered (it trades on ICE Europe).`]})]}):(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Fund positioning (CFTC) is unavailable right now.`}):(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Loading fund positioning…`})}function xt(e,t){return(e>0?`+`:e<0?`−`:``)+Math.abs(e).toFixed(t)}function St({eia:e}){return e?e.items.length?(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-baseline justify-between gap-x-3 text-xs`,children:[(0,U.jsx)(`span`,{className:`font-medium text-muted`,children:`US oil inventories (EIA)`}),(0,U.jsxs)(`span`,{className:`text-faint`,children:[`Week ending `,e.week_ending]})]}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:e.items.map(e=>{let t=e.unit===`%`;return(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,title:e.note,children:[(0,U.jsxs)(`div`,{className:`flex justify-between gap-2 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`truncate`,children:e.label}),(0,U.jsx)(`span`,{className:`shrink-0 text-faint`,children:t?`% of capacity`:`million bbl`})]}),(0,U.jsxs)(`div`,{className:`tabular text-lg font-semibold`,children:[e.value.toFixed(1),t?`%`:``]}),(0,U.jsxs)(`div`,{className:`tabular text-[11px] text-faint`,children:[`1w `,xt(e.change_1w,t?1:2),t?` pts`:``,e.vs_avg_5y!=null&&(0,U.jsxs)(U.Fragment,{children:[` · `,`vs 5-yr avg `,xt(e.vs_avg_5y,1),t?` pts`:`%`]})]})]},e.key)})}),(0,U.jsxs)(`p`,{className:`mt-2 text-[12px] text-faint`,children:[`Source: `,e.source,`. The 5-year average is for the same week of the year, since stocks rise and fall with the seasons.`]})]}):(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`US oil inventories (EIA) are unavailable right now.`}):(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Loading US oil inventories…`})}var Ct=`marketmyna.countries`,wt=[`IND`,`USA`,`CHN`,`JPN`,`DEU`,`GBR`,`FRA`,`KOR`,`IDN`,`BRA`,`SAU`,`ARE`,`AUS`,`CAN`];function Tt(){try{let e=JSON.parse(localStorage.getItem(Ct)||`null`);return Array.isArray(e)&&e.length?e.slice(0,30):wt}catch{return wt}}function Et(e,t){return typeof e==`number`?t===`US$ bn`?e>=1e3?`${c(e/1e3,2)} tn`:`${c(e,0)} bn`:t===`US$`?c(e,0):c(e,1):`—`}function Dt(){let[e,t]=(0,V.useState)(Tt),[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(null),[o,c]=(0,V.useState)(1);(0,V.useEffect)(()=>{try{localStorage.setItem(Ct,JSON.stringify(e))}catch{}let t=new AbortController;return a(null),ot(e,t.signal).then(r).catch(e=>!t.signal.aborted&&a(s(e))),()=>t.abort()},[e]);let l=n?.years[o],u=n&&l!=null&&l>=n.projection_from;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Countries`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Growth, inflation, debt and deficits from the IMF, for any country`})]}),(0,U.jsxs)(`div`,{className:`space-y-3 px-5 pb-4`,children:[i&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:i}),!n&&!i&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Fetching IMF outlook…`,`Lining up countries…`]}),n&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`div`,{className:`flex overflow-hidden rounded-lg border border-line text-xs`,children:n.years.map((e,t)=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>c(t),className:`px-3 py-1.5 ${t===o?`bg-accent-soft font-medium text-fg`:`text-muted hover:text-fg`}`,children:[e,e>=n.projection_from?` projected`:``]},e))}),(0,U.jsxs)(`select`,{"aria-label":`Add a country`,className:`min-w-0 max-w-full rounded-lg border border-line bg-canvas px-2 py-1.5 text-xs`,value:``,onChange:e=>e.target.value&&t(t=>[...t.filter(t=>t!==e.target.value),e.target.value].slice(0,30)),children:[(0,U.jsx)(`option`,{value:``,children:`Add a country…`}),n.countries.filter(t=>!e.includes(t.code)).map(e=>(0,U.jsx)(`option`,{value:e.code,children:e.name},e.code))]}),e.join()!==wt.join()&&(0,U.jsx)(`button`,{type:`button`,className:`text-xs text-muted underline hover:text-fg`,onClick:()=>t(wt),children:`Reset list`})]}),(0,U.jsx)(`div`,{className:`overflow-x-auto`,children:(0,U.jsxs)(`table`,{className:`w-full min-w-[720px] text-sm`,children:[(0,U.jsx)(`thead`,{children:(0,U.jsxs)(`tr`,{className:`text-start text-xs text-muted`,children:[(0,U.jsx)(`th`,{className:`py-1 pe-3 font-medium`,children:`Country`}),n.indicators.map(e=>(0,U.jsxs)(`th`,{className:`py-1 pe-3 text-end font-medium`,title:e.note,children:[e.label,(0,U.jsx)(`div`,{className:`text-[10px] font-normal text-faint`,children:e.unit})]},e.key)),(0,U.jsx)(`th`,{})]})}),(0,U.jsx)(`tbody`,{children:n.rows.map(e=>(0,U.jsxs)(`tr`,{className:`border-t border-line`,children:[(0,U.jsxs)(`td`,{className:`py-1.5 pe-3`,title:e.fiscal_year??void 0,children:[e.name,e.fiscal_year&&(0,U.jsx)(`span`,{className:`text-faint`,children:`*`})]}),n.indicators.map(t=>{let r=e[t.key],i=r?.[o],a=[`NGDP_RPCH`,`GGXCNL_NGDP`,`BCA_NGDPD`].includes(t.key)&&typeof i==`number`&&i<0;return(0,U.jsx)(`td`,{className:`tabular py-1.5 pe-3 text-end ${a?`text-down`:``}`,title:n.years.map((e,n)=>`${e}: ${Et(r?.[n],t.unit)}`).join(` · `),children:Et(i,t.unit)},t.key)}),(0,U.jsx)(`td`,{className:`py-1.5 text-end`,children:(0,U.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.name}`,className:`px-1 text-faint hover:text-fg`,onClick:()=>t(t=>t.filter(t=>t!==e.code)),children:`×`})})]},e.code))})]})}),(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Source: `,n.source,`, updated `,n.as_of,n.stale?` (saved copy: the IMF did not answer)`:``,`. `,u?`${l} figures are IMF projections, not results. `:``,n.rows.some(e=>e.fiscal_year)&&`* India: April-March fiscal years. `,`Hover a figure for the three years.`]})]})]})]})}var Ot=.5;function kt({beta:e,significant:t}){let n=Math.min(Math.abs(e)/Ot,1)*50;return(0,U.jsxs)(`span`,{className:`relative block h-2.5 w-full rounded-full bg-raised`,children:[(0,U.jsx)(`span`,{className:`absolute top-0 left-1/2 h-2.5 w-px bg-line-strong`}),(0,U.jsx)(`span`,{className:m(`absolute top-0 h-2.5 rounded-full`,e>=0?`bg-up`:`bg-down`,!t&&`opacity-35`),style:e>=0?{left:`50%`,width:`${n}%`}:{right:`50%`,width:`${n}%`}})]})}var At={india:`Indian`,us:`US`,hong_kong:`Hong Kong`,china_a:`China A-share`};function jt({market:e=`india`}={}){let t=e===`all`?`india`:e,{data:n,error:r,at:a}=K(e=>nt(t,e),[t],G);return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 px-5 py-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Oil sensitivity`}),(0,U.jsxs)(`p`,{className:`text-xs text-muted`,children:[`Which `,At[t]??``,` stocks gain or lose when crude moves, beyond the market's own swing`]}),(0,U.jsx)(q,{at:a,daily:`Weekly moves over two years, refreshed daily`})]})}),(0,U.jsxs)(`div`,{className:`space-y-5 px-5 pb-4`,children:[r&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:r}),!n&&!r&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Loading two years of weekly prices…`,t===`us`?`Lining up WTI crude…`:`Converting crude to local currency…`,`Separating the oil effect from the market's swing…`,`Grouping stocks by how crude hits them…`]}),n?.error&&(0,U.jsx)(`p`,{className:`text-sm text-muted`,children:n.error}),n&&n.groups.length>0&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-6 gap-y-1 text-sm`,children:[(0,U.jsxs)(`span`,{children:[n.crude_label,` `,(0,U.jsxs)(`span`,{className:`tabular font-semibold`,children:[n.currency,c(n.crude,0),`/bbl`]})]}),(0,U.jsxs)(`span`,{className:`text-muted`,children:[`1 month `,(0,U.jsx)(`span`,{className:m(`tabular`,i(n.crude_change_1m)),children:u(n.crude_change_1m,1)})]}),(0,U.jsxs)(`span`,{className:`text-muted`,children:[`1 year `,(0,U.jsx)(`span`,{className:m(`tabular`,i(n.crude_change_1y)),children:u(n.crude_change_1y,1)})]})]}),(0,U.jsx)(S,{className:`space-y-4 pe-1`,maxHeight:`62rem`,children:n.groups.map(e=>(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-baseline justify-between gap-x-3`,children:[(0,U.jsx)(`span`,{className:`text-xs font-medium`,children:e.name}),(0,U.jsx)(`span`,{className:`text-xs text-faint`,children:e.why})]}),(0,U.jsx)(`div`,{className:`divide-y divide-line rounded-lg bg-canvas px-3`,children:e.stocks.map(e=>(0,U.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_5rem_3.5rem] items-center gap-3 py-2 text-sm sm:grid-cols-[12rem_minmax(0,1fr)_4rem_7rem]`,children:[(0,U.jsxs)(D,{to:`/analyze?symbol=${e.symbol}&market=${t}`,className:`min-w-0 truncate hover:text-accent-fg`,title:e.name,children:[(0,U.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.symbol}),` `,(0,U.jsx)(`span`,{className:`hidden text-xs text-muted sm:inline`,children:e.name})]}),(0,U.jsx)(`span`,{title:`Crude beta ${c(e.beta_crude,2)} (t ${c(e.t_crude,1)}${e.significant?``:`, not significant`})`,children:(0,U.jsx)(kt,{beta:e.beta_crude,significant:e.significant})}),(0,U.jsxs)(`span`,{className:m(`tabular text-end text-xs`,e.significant?`text-fg`:`text-faint`),children:[e.beta_crude>0?`+`:``,c(e.beta_crude,2)]}),(0,U.jsx)(`span`,{className:`tabular hidden text-end text-xs sm:inline`,title:`Crude's move last month times this stock's crude beta, market held flat`,children:e.crude_implied_1m==null?`—`:(0,U.jsx)(`span`,{className:i(e.crude_implied_1m),children:u(e.crude_implied_1m,1)})})]},e.symbol))})]},e.name))}),(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Crude beta: % move in the stock for a 1% move in `,n.crude_label,`, after removing what the `,n.index_name,` explains. -0.2 means a 10% oil jump has gone with about 2% underperformance. Faded bars are not statistically significant (|t| < 2). Right column: what last month's oil move alone implies. `,n.method,` Past relationships; not investment advice.`]})]})]})]})}var Mt=[{value:`1`,label:`Latest day`},{value:`7`,label:`7 days`},{value:`30`,label:`30 days`}];function Nt(){let[e,t]=(0,V.useState)(`1`),{data:n,error:r,at:i}=K(()=>A(Number(e)),[e],G);return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-5 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Big trades (NSE bulk & block deals)`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Which funds, promoters and big investors bought or sold large blocks`}),(0,U.jsx)(q,{at:i,daily:`New deals each trading evening`})]}),(0,U.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,U.jsx)(y,{size:`sm`,value:e,onChange:t,options:Mt})})]}),(0,U.jsxs)(`div`,{className:`px-5 pb-4`,children:[r&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:r}),!n&&!r&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Fetching the latest bulk and block deals…`,`Matching deals to companies…`,`Sorting by deal size…`]}),n&&(0,U.jsx)(S,{children:(0,U.jsx)(le,{deals:n,showSymbol:!0})})]})]})}var Pt=[{value:`category`,label:`Categories`},{value:`amc`,label:`Fund houses`}],Ft=15,It=[`us`,`hong_kong`,`china_a`],Lt={lagging:0,weakening:1,improving:2,leading:3};function Rt({market:e=`india`}={}){let t=It.includes(e),[n,r]=(0,V.useState)(`category`),[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(null),[l,d]=(0,V.useState)(null),[f,p]=(0,V.useState)(e);f!==e&&(p(e),c(null),o(null));let{data:h,error:g,at:_}=K(r=>t?ye(e,s,r):_e(n,a,r),[t,e,s,n,a],t?W(6e4):G),v=me(h?.benchmark.name??(t?`market`:`Nifty 500`)),b=Ue(Object.fromEntries((h?.items??[]).map(e=>[e.name,Lt[e.quadrant]]))),x=h?.items??[],C=x.slice(0,Math.max(Ft,x.length)),w=(0,V.useMemo)(()=>{let e={leading:0,improving:0,weakening:0,lagging:0};for(let t of x)e[t.quadrant]+=1;return e},[x]);return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-5 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:a?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`button`,{type:`button`,onClick:()=>o(null),className:`me-2 text-accent-fg hover:underline`,children:[`← `,n===`amc`?`All fund houses`:`All categories`]}),a]}):t?`ETF rotation`:`Mutual fund rotation`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:t?h?`${h.group} ETFs vs the ${h.benchmark.name}, weekly to ${h.as_of}.`:`Which sector, theme, style and country ETFs are leading, weakening, lagging or improving`:h?`Equity funds (Direct, Growth) vs the ${h.benchmark.name}, weekly to ${h.as_of}. ${a?`Each fund on its own.`:`Click a row to see its funds.`}`:`Which fund categories and fund houses are leading, weakening, lagging or improving`}),h&&(0,U.jsx)(q,{live:h.live,at:_,daily:t?void 0:`Fund NAVs update once a day`})]}),t?h?.groups&&h.groups.length>1&&(0,U.jsx)(y,{size:`sm`,options:h.groups.map(e=>({value:e,label:e})),value:h.group??h.groups[0],onChange:e=>c(e)}):!a&&(0,U.jsx)(y,{size:`sm`,options:Pt,value:n,onChange:e=>r(e)})]}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[g&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:g}),!h&&!g&&(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(B,{className:`min-h-56`,steps:t?[`Loading two years of ETF prices…`,`Comparing each ETF with its home market…`,`Placing ETFs on the rotation chart…`]:[`Reading weekly NAVs for a few hundred funds…`,`Building baskets by category…`,`Comparing each basket with the Nifty 500…`,`Placing groups on the rotation chart…`]}),!t&&(0,U.jsx)(`p`,{className:`text-xs text-faint`,children:`Reading weekly NAVs for a few hundred funds; the first load can take half a minute.`})]}),h&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`flex flex-wrap gap-2 text-xs`,children:Object.keys(v).map(e=>(0,U.jsxs)(`span`,{className:m(`rounded-full border border-line px-2.5 py-0.5`,v[e].className),title:v[e].note,children:[v[e].label,` · `,w[e]]},e))}),(0,U.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,U.jsx)(fe,{series:C,focus:l}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(S,{maxHeight:`30rem`,children:(0,U.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,U.jsxs)(`colgroup`,{children:[(0,U.jsx)(`col`,{}),(0,U.jsx)(`col`,{className:`w-24`}),(0,U.jsx)(`col`,{className:`w-16`})]}),(0,U.jsx)(`thead`,{className:`sticky top-0 bg-surface text-xs text-muted`,children:(0,U.jsxs)(`tr`,{children:[(0,U.jsx)(`th`,{className:`py-1 text-start font-medium`,children:t?`ETF`:a?`Fund`:n===`amc`?`Fund house`:`Category`}),(0,U.jsx)(`th`,{className:`py-1 text-start font-medium`,children:`Phase`}),(0,U.jsx)(`th`,{className:`py-1 text-end font-medium`,children:`4 weeks`})]})}),(0,U.jsx)(`tbody`,{className:`divide-y divide-line`,children:x.map((n,r)=>(0,U.jsxs)(`tr`,{onMouseEnter:()=>d(n.name),onMouseLeave:()=>d(null),onClick:()=>!t&&!a&&o(n.name),title:t?n.code:a?`${n.amc??``} · ${n.category??``}`:`Basket of ${n.funds} of ${n.total_funds} funds · click to see each fund`,className:m(`hover:bg-raised`,!t&&!a&&`cursor-pointer`),children:[(0,U.jsxs)(`td`,{className:`truncate py-1.5 pe-2`,title:n.name,children:[(0,U.jsx)(`span`,{className:`me-2 inline-block h-2 w-2 rounded-full`,style:{backgroundColor:R[r%R.length]}}),t&&n.symbol?(0,U.jsxs)(D,{to:`/analyze?symbol=${encodeURIComponent(n.symbol)}&market=${e}`,className:`hover:text-accent-fg`,children:[(0,U.jsx)(`span`,{className:`font-mono text-xs text-muted`,children:n.code}),` `,n.name]}):a&&n.code?(0,U.jsx)(D,{to:`/?market=india&type=mf&q=${encodeURIComponent(n.name)}`,className:`hover:text-accent-fg`,children:n.name}):n.name]}),(0,U.jsx)(`td`,{className:m(`rounded py-1.5 pe-2 text-xs`,v[n.quadrant].className,b(n.name)),title:v[n.quadrant].note,children:v[n.quadrant].label}),(0,U.jsx)(`td`,{className:m(`tabular py-1.5 text-end`,i(n.return_4w)),children:u(n.return_4w,1)})]},n.code??n.name))})]})}),(0,U.jsxs)(`p`,{className:`mt-2 text-xs text-faint`,children:[`Right = stronger than the `,h.benchmark.name,`, up = strength rising; `,t?`ETFs`:`funds`,` usually cycle clockwise: improving → leading → weakening → lagging.`,` `,t?`Click an ETF to analyse it.`:a?`Click a fund to find it in the list.`:`Groups are equal-weighted baskets of their longest-running funds.`,` Past relative performance; not a recommendation.`]})]})]})]})]})]})}var zt=`marketmyna.hot.board`,Bt=[],Vt={trader:{title:`Hot for trading`,loading:[`Ranking today’s biggest moves…`,`Measuring trading activity…`,`Checking 52-week highs and lows…`]},investor:{title:`Trending for investors`,loading:[`Reading fundamentals for the largest stocks…`,`Comparing valuations within each sector…`,`Matching quality with where price sits in its range…`,`Checking what mutual funds added…`]}};function Ht(e){try{return localStorage.getItem(`${zt}.${e}`)}catch{return null}}function Ut({market:e,area:t}){let[n,r]=(0,V.useState)(()=>Ht(t)),{data:i,error:a,at:s,reload:c}=K(n=>ve(e,t,n),[e,t],W(t===`trader`?15e3:3e4));function l(e){r(e);try{localStorage.setItem(`${zt}.${t}`,e)}catch{}}let u=Vt[t],d=i?.boards.find(e=>e.key===n)??i?.boards[0],f=(0,V.useContext)(He),p=je(d?.rows??Bt,f);return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-5 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:u.title}),i&&(0,U.jsxs)(`p`,{className:`text-xs text-muted`,children:[i.universe,t===`investor`&&i.as_of?` · fundamentals ${o(i.as_of)}`:``,t===`trader`&&!i.live?.live&&i.as_of?` · prices ${o(i.as_of)}`:``,` · facts, not advice`]}),i&&(0,U.jsx)(q,{live:i.live,at:s,ticking:p.status.updated})]}),t===`trader`&&i&&(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:`refresh`,onClick:c,children:`Refresh`})]}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[a&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:a}),!i&&!a&&(0,U.jsx)(B,{className:`min-h-56`,steps:u.loading}),i&&d&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,role:`tablist`,children:i.boards.map(e=>(0,U.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":e.key===d.key,onClick:()=>l(e.key),className:m(`inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-1 text-xs font-medium transition-colors`,e.key===d.key?t===`investor`?`border-up/40 bg-up-soft text-up`:`border-accent/40 bg-accent-soft text-accent-fg`:`border-line text-muted hover:border-faint hover:text-fg`),children:[e.title,(0,U.jsx)(`span`,{className:m(`tabular rounded px-1 text-[11px]`,e.rows.length?`bg-canvas`:`text-faint`),children:e.rows.length})]},e.key))}),(0,U.jsx)(`p`,{className:`text-xs text-faint`,children:d.description}),(0,U.jsx)(Wt,{board:d,rows:p.rows,flash:p.flash})]})]})]})}function Wt({board:e,rows:t,flash:r}){return t.length===0?(0,U.jsx)(`p`,{className:`py-6 text-center text-sm text-muted`,children:e.note??`Nothing on this board right now.`}):(0,U.jsx)(S,{className:`pe-1`,children:(0,U.jsx)(`table`,{className:`w-full text-sm`,children:(0,U.jsx)(`tbody`,{className:`divide-y divide-line`,children:t.map(e=>(0,U.jsxs)(`tr`,{children:[(0,U.jsxs)(`td`,{className:`w-full max-w-0 py-2 pe-3`,children:[(0,U.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,U.jsx)(D,{to:Se(e),className:`font-mono text-sm hover:text-accent-fg`,children:e.symbol}),(0,U.jsx)(`span`,{className:`truncate text-[12px] text-faint`,children:e.name})]}),(0,U.jsx)(`div`,{className:`truncate text-xs text-muted`,children:e.why})]}),(0,U.jsx)(`td`,{className:`tabular hidden whitespace-nowrap py-2 pe-3 text-end text-xs text-faint md:table-cell`,children:e.sector}),(0,U.jsx)(`td`,{className:m(`tabular whitespace-nowrap py-2 pe-3 text-end`,r(e)),children:n(e.price,e.currency)}),(0,U.jsx)(`td`,{className:m(`tabular py-2 text-end`,i(e.change_percent)),children:u(e.change_percent)})]},e.symbol))})})})}var Gt={background:`var(--color-raised)`,border:`1px solid var(--color-line-strong)`,borderRadius:8,fontSize:12},Kt=e=>e==null?`—`:`${e>0?`+`:e<0?`−`:``}₹${Math.abs(e).toLocaleString(`en-IN`,{maximumFractionDigits:0})} cr`,qt=e=>`${e>0?`+`:e<0?`−`:``}${Math.abs(e).toLocaleString(`en-IN`)}`,Jt=e=>new Date(e+`T00:00:00`).toLocaleDateString(void 0,{day:`numeric`,month:`short`});function Yt(){let{data:e,error:t,at:n}=K(e=>ct(e),[],G),r=e?.cash,a=e?.positioning;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`FII / DII flows`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Foreign and domestic institutions' buying and selling, and who is long or short the index`}),(0,U.jsx)(q,{at:n,daily:`New figures each trading evening`})]}),(0,U.jsxs)(`div`,{className:`space-y-5 px-5 pb-4`,children:[t&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:t}),!e&&!t&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Fetching NSE cash flows…`,`Reading participant open interest…`]}),r?.latest&&(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,U.jsxs)(`span`,{className:`text-xs font-medium text-muted`,children:[`Cash market · `,Jt(r.latest.date)]}),r.stale&&(0,U.jsx)(`span`,{className:`text-xs text-warn`,children:r.stale})]}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`fii`,`dii`].map(e=>{let t=r.latest?.[e];return(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`text-xs text-muted`,children:e===`fii`?`Foreign institutions (FII / FPI)`:`Domestic institutions (DII)`}),(0,U.jsx)(`div`,{className:m(`tabular text-lg font-semibold`,i(t?.net)),children:Kt(t?.net)}),(0,U.jsxs)(`div`,{className:`tabular text-[11px] text-faint`,children:[`bought ₹`,t?.buy?.toLocaleString(`en-IN`,{maximumFractionDigits:0})??`—`,` cr · sold ₹`,t?.sell?.toLocaleString(`en-IN`,{maximumFractionDigits:0})??`—`,` cr`]}),(0,U.jsxs)(`div`,{className:`tabular mt-1 text-[11px] text-muted`,children:[r.five_day.sessions>1&&(0,U.jsxs)(U.Fragment,{children:[`last `,r.five_day.sessions,` sessions `,(0,U.jsx)(`span`,{className:i(r.five_day[e]),children:Kt(r.five_day[e])}),` ·`,` `]}),`month so far `,(0,U.jsx)(`span`,{className:i(r.month_to_date[e]),children:Kt(r.month_to_date[e])}),r.month_to_date.sessions>0&&` (${r.month_to_date.sessions} session${r.month_to_date.sessions>1?`s`:``})`]})]},e)})}),r.series.length>1?(0,U.jsx)(`div`,{className:`h-44 rounded-lg bg-canvas p-2`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(ce,{data:r.series,margin:{top:4,right:4,bottom:0,left:0},children:[(0,U.jsx)(ae,{stroke:`var(--color-line)`,vertical:!1}),(0,U.jsx)(ie,{dataKey:`date`,tickFormatter:Jt,tick:{fill:`var(--color-faint)`,fontSize:10},axisLine:!1,tickLine:!1,minTickGap:16}),(0,U.jsx)(F,{orientation:`right`,width:64,tickFormatter:e=>`${Math.round(e).toLocaleString(`en-IN`)}`,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1}),(0,U.jsx)(M,{contentStyle:Gt,labelFormatter:e=>Jt(String(e)),formatter:(e,t)=>[Kt(Number(e)),t===`fii`?`FII`:`DII`]}),(0,U.jsx)(oe,{dataKey:`fii`,fill:`var(--color-accent)`}),(0,U.jsx)(oe,{dataKey:`dii`,fill:`var(--color-warn)`})]})})}):(0,U.jsx)(`p`,{className:`text-[12px] text-faint`,children:`NSE publishes only the latest session; the daily history here starts from the first saved day and grows each session.`})]}),a&&(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,U.jsxs)(`span`,{className:`text-xs font-medium text-muted`,children:[`Index derivatives positioning · `,Jt(a.date)]}),(0,U.jsxs)(`span`,{className:`text-xs text-faint`,children:[`open contracts, last `,a.sessions,` sessions`]})]}),(0,U.jsx)(Xt,{p:a}),(0,U.jsx)(`div`,{className:`overflow-x-auto`,children:(0,U.jsxs)(`table`,{className:`w-full min-w-[520px] text-sm`,children:[(0,U.jsx)(`thead`,{children:(0,U.jsxs)(`tr`,{className:`text-start text-xs text-muted`,children:[(0,U.jsx)(`th`,{className:`py-1 pe-3 font-medium`,children:`Participant`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:`Index futures long`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:`Net futures`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,title:`Calls bought + puts sold, minus puts bought + calls sold`,children:`Net index options`}),(0,U.jsx)(`th`,{className:`py-1 text-end font-medium`,children:`Change in net futures`})]})}),(0,U.jsx)(`tbody`,{children:[`FII`,`DII`,`Client`,`Pro`].map(e=>{let t=a.groups[e];if(!t)return null;let n=a.previous?.[e],r=n?t.index_futures_net-n.index_futures_net:null;return(0,U.jsxs)(`tr`,{className:`border-t border-line`,children:[(0,U.jsx)(`td`,{className:`py-1.5 pe-3`,children:e===`Client`?`Retail & others (client)`:e===`Pro`?`Brokers (pro)`:e}),(0,U.jsx)(`td`,{className:`tabular py-1.5 pe-3 text-end`,children:t.index_futures_long_pct==null?`—`:`${t.index_futures_long_pct}%`}),(0,U.jsx)(`td`,{className:m(`tabular py-1.5 pe-3 text-end`,i(t.index_futures_net)),children:qt(t.index_futures_net)}),(0,U.jsx)(`td`,{className:m(`tabular py-1.5 pe-3 text-end`,i(t.index_options_net)),children:qt(t.index_options_net)}),(0,U.jsx)(`td`,{className:m(`tabular py-1.5 text-end`,i(r)),children:r==null?`—`:qt(r)})]},e)})})]})})]}),e&&(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Source: `,e.source,`. Cash figures are NSE's provisional numbers for the session. Positioning counts open contracts; every long has a short on the other side, so one group's long is another's short. Shows how positions stand, not where the market will go.`]})]})]})}function Xt({p:e}){let t=e.groups.FII,n=t?.index_futures_long_pct,[r,i]=e.fii_long_pct_range??[0,100];return(0,U.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(0,2fr)]`,children:[(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`text-xs text-muted`,children:`FII index futures held long`}),(0,U.jsx)(`div`,{className:`tabular text-2xl font-semibold`,children:n==null?`—`:`${n}%`}),(0,U.jsx)(`div`,{className:`mt-1 text-[11px] text-faint`,children:t&&`${t.index_futures_long.toLocaleString(`en-IN`)} long · ${t.index_futures_short.toLocaleString(`en-IN`)} short`}),(0,U.jsxs)(`div`,{className:`mt-1 text-[11px] text-muted`,children:[e.sessions,`-session range `,r,`%–`,i,`%.`,` `,n!=null&&(n<30?`Heavily short.`:n>70?`Heavily long.`:`Neither side dominant.`)]})]}),(0,U.jsx)(`div`,{className:`h-32 rounded-lg bg-canvas p-2`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(I,{data:e.fii_long_pct_series,margin:{top:4,right:4,bottom:0,left:0},children:[(0,U.jsx)(ie,{dataKey:`date`,tickFormatter:Jt,tick:{fill:`var(--color-faint)`,fontSize:10},axisLine:!1,tickLine:!1,minTickGap:24}),(0,U.jsx)(F,{orientation:`right`,width:40,domain:[e=>Math.max(0,Math.floor(e-2)),e=>Math.min(100,Math.ceil(e+2))],allowDecimals:!1,tickFormatter:e=>`${e}%`,tick:{fill:`var(--color-faint)`,fontSize:10},axisLine:!1,tickLine:!1}),(0,U.jsx)(M,{contentStyle:Gt,labelFormatter:e=>Jt(String(e)),formatter:e=>[`${e}%`,`FII long share`]}),(0,U.jsx)(N,{type:`monotone`,dataKey:`pct`,stroke:`var(--color-accent)`,dot:!1,strokeWidth:1.8})]})})})]})}var Zt=e=>e==null?`—`:e.toLocaleString(`en-IN`,{style:`currency`,currency:`INR`,maximumFractionDigits:0});function Qt(){let{data:e,error:t,at:n}=K(e=>tt(e),[],G),r=t!=null,i=K(e=>Ze(e),[],W(6e4)),a=i.data?.items??[];return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 px-5 py-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`India rates & bullion`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`RBI policy rates, the government bond curve, and IBJA gold / silver prices`}),i.data?.live?.live?(0,U.jsx)(q,{live:i.data.live,at:i.at}):(0,U.jsx)(q,{at:n,daily:`Rates and IBJA prices update once a day`})]})}),(0,U.jsxs)(`div`,{className:`space-y-6 px-5 pb-4`,children:[r&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:`India rates are unavailable right now.`}),!e&&!r&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Reading RBI policy rates…`,`Building the government bond curve…`,`Fetching IBJA gold and silver prices…`]}),e&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(en,{rbi:e.rbi}),(0,U.jsx)(tn,{ibja:e.ibja,intl:a})]})]})]})}function $t({error:e}){return e?(0,U.jsx)(`p`,{className:`rounded-md bg-warn-soft px-3 py-2 text-xs text-warn`,children:e}):null}function en({rbi:e}){if(!e.policy)return(0,U.jsx)($t,{error:e.error});let t=e.fx?.find(e=>e.pair===`USD/INR`);return(0,U.jsxs)(`div`,{className:`space-y-4`,children:[(0,U.jsx)($t,{error:e.stale?e.error:void 0}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:`RBI policy`}),(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4 xl:grid-cols-7`,children:[e.policy.map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,title:e.note,children:[(0,U.jsx)(`div`,{className:`truncate text-xs text-muted`,children:e.label}),(0,U.jsx)(`div`,{className:`tabular text-lg font-semibold`,children:e.value==null?`—`:`${c(e.value)}%`})]},e.key)),e.call_rate&&(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,title:`Overnight interbank borrowing; sits inside the SDF-MSF corridor`,children:[(0,U.jsx)(`div`,{className:`truncate text-xs text-muted`,children:`Call money`}),(0,U.jsxs)(`div`,{className:`tabular whitespace-nowrap text-lg font-semibold xl:text-base xl:leading-7`,children:[c(e.call_rate.low),`–`,c(e.call_rate.high),`%`]})]})]})]}),e.curve&&e.curve.length>2&&(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`text-xs font-medium text-muted`,children:[`India government yield curve`,e.gsec_as_of?` · ${e.gsec_as_of}`:``]}),(()=>{let t=e.curve[0],n=e.curve.reduce((e,t)=>Math.abs(t.years-10)<Math.abs(e.years-10)?t:e).yield-t.yield;return(0,U.jsxs)(`span`,{className:`text-xs text-muted`,children:[`~10Y − `,t.label,`: `,(0,U.jsxs)(`span`,{className:`tabular text-fg`,children:[n>0?`+`:``,c(n),` pts`]})]})})()]}),(0,U.jsx)(`div`,{className:`h-52 rounded-lg bg-canvas p-2`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(I,{data:e.curve,margin:{top:8,right:16,bottom:0,left:0},children:[(0,U.jsx)(ae,{stroke:`var(--color-line)`,vertical:!1}),(0,U.jsx)(ie,{dataKey:`label`,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1,interval:0}),(0,U.jsx)(F,{width:40,domain:[`auto`,`auto`],tickFormatter:e=>`${c(e,1)}%`,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1}),(0,U.jsx)(M,{contentStyle:{background:`var(--color-raised)`,border:`1px solid var(--color-line-strong)`,borderRadius:8,fontSize:12},formatter:e=>[`${c(Number(e),2)}%`,`Yield`],labelFormatter:e=>String(e).endsWith(`D`)?`${String(e).slice(0,-1)}-day T-bill`:`G-sec maturing ${e}`}),(0,U.jsx)(N,{dataKey:`yield`,stroke:`var(--color-accent)`,strokeWidth:2,dot:{r:2.5},isAnimationActive:!1})]})})}),(0,U.jsx)(`p`,{className:`mt-1.5 text-[12px] text-faint`,children:`T-bills: cut-off at the last auction. Bonds: RBI's benchmark G-secs, labelled by maturity year. A steeper curve means the market expects higher rates or inflation later.`})]}),(t||e.lending?.length)&&(0,U.jsxs)(`div`,{className:`grid gap-x-8 gap-y-1 text-xs sm:grid-cols-2`,children:[e.fx?.slice(0,4).map(e=>(0,U.jsxs)(`div`,{className:`flex justify-between border-b border-line py-1`,children:[(0,U.jsxs)(`span`,{className:`text-muted`,children:[e.per>1?`${e.per} `:``,e.pair,` (FBIL)`]}),(0,U.jsxs)(`span`,{className:`tabular`,children:[`₹`,c(e.value,2)]})]},e.pair)),e.lending?.map(e=>(0,U.jsxs)(`div`,{className:`flex justify-between border-b border-line py-1`,children:[(0,U.jsx)(`span`,{className:`text-muted`,children:e.label}),(0,U.jsx)(`span`,{className:`tabular`,children:e.value})]},e.label))]}),(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Source: Reserve Bank of India (rbi.org.in)`,e.fx_as_of?`; FX as at ${e.fx_as_of}`:``,`.`]})]})}function tn({ibja:e,intl:t}){if(!e.items)return(0,U.jsx)($t,{error:e.error});let n={gold_999:t.find(e=>e.key===`GC=F:INR`),silver_999:t.find(e=>e.key===`SI=F:INR`)},r=e.items.filter(e=>[`gold_999`,`gold_916`,`silver_999`].includes(e.key));return(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsx)($t,{error:e.stale?e.error:void 0}),(0,U.jsxs)(`div`,{className:`text-xs font-medium text-muted`,children:[`Bullion in India (IBJA)`,e.as_of?` · ${e.as_of}`:``]}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:r.map(t=>{let r=e.history?.[t.key]??[],a=n[t.key],o=a?(t.latest/a.price-1)*100:null;return(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsxs)(`div`,{className:`flex justify-between gap-2 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`truncate`,children:t.label}),(0,U.jsxs)(`span`,{className:`shrink-0 text-faint`,children:[t.unit,` · `,t.session]})]}),(0,U.jsxs)(`div`,{className:`flex items-end justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`tabular text-lg font-semibold`,children:Zt(t.latest)}),t.change_pct!=null&&(0,U.jsxs)(`div`,{className:`tabular whitespace-nowrap text-[11px] text-faint`,children:[`vs yesterday `,(0,U.jsx)(`span`,{className:i(t.change_pct),children:u(t.change_pct,2)})]}),o!=null&&(0,U.jsxs)(`div`,{className:`tabular whitespace-nowrap text-[11px] text-faint`,title:`International price in rupees: ${Zt(a.price)}`,children:[o>=0?`+`:``,c(o,1),`% over international`]})]}),r.length>5&&(0,U.jsx)(`div`,{className:`h-10 w-16 shrink-0 sm:w-20`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(j,{data:r,margin:{top:2,right:0,bottom:2,left:0},children:[(0,U.jsx)(F,{hide:!0,domain:[`auto`,`auto`]}),(0,U.jsx)(se,{type:`monotone`,dataKey:`value`,stroke:`var(--color-accent)`,strokeWidth:1.5,fill:`var(--color-accent)`,fillOpacity:.12,isAnimationActive:!1})]})})})]})]},t.key)})}),(0,U.jsx)(`p`,{className:`text-[12px] text-faint`,children:`Source: India Bullion and Jewellers Association (ibjarates.com), before 3% GST and making charges. The premium over the international price is mostly import duty and local demand. MCX futures are not shown: MCX blocks automated access.`})]})}var nn={normal:{text:`Normal (upward sloping)`,className:`bg-up-soft text-up`},flat:{text:`Flat`,className:`bg-warn-soft text-warn`},inverted:{text:`Inverted`,className:`bg-down-soft text-down`}};function rn(){let[e,t]=(0,V.useState)(null),[n,r]=(0,V.useState)(!1);if((0,V.useEffect)(()=>{let e=new AbortController;return et(e.signal).then(t).catch(()=>!e.signal.aborted&&r(!0)),()=>e.abort()},[]),n||e&&!e.points.length)return null;let i=e?.shape?nn[e.shape.label]:null;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`text-xs font-medium text-muted`,children:[`US Treasury yield curve`,e?.as_of?` · ${e.as_of}`:``]}),i&&e?.shape&&(0,U.jsxs)(`span`,{className:m(`rounded-md px-2 py-0.5 text-xs`,i.className),children:[i.text,` · 10Y − 3M `,e.shape.spread_10y_3m>0?`+`:``,c(e.shape.spread_10y_3m),` pts`]})]}),(0,U.jsx)(`div`,{className:`h-56 rounded-lg bg-canvas p-2`,children:e?(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(I,{data:e.points,margin:{top:8,right:16,bottom:0,left:0},children:[(0,U.jsx)(ae,{stroke:`var(--color-line)`,vertical:!1}),(0,U.jsx)(ie,{dataKey:`tenor`,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1,interval:0,minTickGap:0}),(0,U.jsx)(F,{domain:[`auto`,`auto`],width:40,tickFormatter:e=>`${c(e,1)}%`,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1}),(0,U.jsx)(M,{contentStyle:{background:`var(--color-raised)`,border:`1px solid var(--color-line-strong)`,borderRadius:8,fontSize:12},formatter:e=>`${c(Number(e))}%`}),(0,U.jsx)(P,{wrapperStyle:{fontSize:11}}),(0,U.jsx)(N,{name:`Now`,dataKey:`now`,stroke:`var(--color-accent)`,strokeWidth:2,dot:{r:2},isAnimationActive:!1}),(0,U.jsx)(N,{name:`1 month ago`,dataKey:`month_ago`,stroke:`var(--color-muted)`,strokeWidth:1.25,strokeDasharray:`4 3`,dot:!1,isAnimationActive:!1}),(0,U.jsx)(N,{name:`1 year ago`,dataKey:`year_ago`,stroke:`var(--color-faint)`,strokeWidth:1.25,strokeDasharray:`1 3`,dot:!1,isAnimationActive:!1})]})}):(0,U.jsx)(ee,{className:`h-full w-full`})}),(0,U.jsx)(`p`,{className:`mt-1.5 text-[12px] text-faint`,children:`Short-term yields follow the central bank; long-term ones price growth and inflation. A curve that turns inverted (short above long) has preceded most US recessions. No free daily curve exists for India.`})]})}var an=[{key:`india`,label:`India`},{key:`us`,label:`United States`},{key:`global`,label:`Global`}];function on(e,t,n=!1){if(t==null)return`—`;let r=c(t,2),i=n&&t>0?`+`:``;return e.unit===`%`||e.unit===`pts`?`${i}${r}${e.unit===`%`?`%`:``}`:`${i}${e.unit}${r}`}function sn(){let{data:e,error:t,at:n}=K(e=>Xe(e),[],G);return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 px-5 py-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Macro backdrop`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Rates, inflation, rupee and oil: the forces that move the whole market`}),(0,U.jsx)(q,{at:n,daily:`Daily and monthly series`})]})}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[t&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:t}),!e&&!t&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Fetching India indicators…`,`Fetching US indicators…`,`Fetching global indicators…`]}),e&&(0,U.jsxs)(U.Fragment,{children:[e.signals.us_curve_inverted&&(0,U.jsx)(`p`,{className:`rounded-md bg-warn-soft px-3 py-2 text-xs text-warn`,children:`The US yield curve is inverted (2-year above 10-year), a pattern that has preceded most US recessions.`}),an.map(t=>{let n=e.series.filter(e=>e.group===t.key);return n.length?(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:t.label}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:n.map(e=>(0,U.jsx)(cn,{s:e},e.id))})]},t.key):null}),(0,U.jsx)(rn,{}),(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Source: `,e.source,`. Monthly series lag by a few weeks.`,e.failed.length?` Unavailable now: ${e.failed.join(`, `)}.`:``]})]})]})]})}function cn({s:e}){return(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,title:e.note,children:[(0,U.jsx)(`div`,{className:`truncate text-xs text-muted`,children:e.label}),(0,U.jsxs)(`div`,{className:`flex items-end justify-between gap-2`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`tabular text-lg font-semibold`,children:on(e,e.value)}),(0,U.jsxs)(`div`,{className:`tabular text-[11px] text-faint`,children:[`1y `,(0,U.jsx)(`span`,{className:`text-fg`,children:on(e,e.change_1y,!0)})]}),(0,U.jsxs)(`div`,{className:`text-[11px] text-faint`,children:[`as of `,e.date]})]}),(0,U.jsx)(`div`,{className:`h-10 w-24 shrink-0`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(j,{data:e.spark,margin:{top:2,right:0,bottom:2,left:0},children:[(0,U.jsx)(F,{hide:!0,domain:[`auto`,`auto`]}),(0,U.jsx)(se,{type:`monotone`,dataKey:`value`,stroke:`var(--color-accent)`,strokeWidth:1.5,fill:`var(--color-accent)`,fillOpacity:.12,isAnimationActive:!1})]})})})]})]})}var ln=[{to:25,label:`Extreme fear`},{to:45,label:`Fear`},{to:55,label:`Neutral`},{to:75,label:`Greed`},{to:100,label:`Extreme greed`}];function un({score:e,big:t=!1}){return(0,U.jsxs)(`div`,{className:t?`relative h-3`:`relative h-1.5`,children:[(0,U.jsx)(`div`,{className:`absolute inset-0 overflow-hidden rounded-full`,style:{background:`linear-gradient(90deg, var(--color-down), var(--color-warn) 50%, var(--color-up))`,opacity:.35}}),(0,U.jsx)(`div`,{className:m(`absolute -translate-x-1/2 rounded-full bg-fg transition-[left] duration-700`,t?`-top-1 h-5 w-1.5`:`-top-0.5 h-2.5 w-1`),style:{left:`${e}%`}})]})}function dn({market:e}){let{data:t,error:n,at:r}=K(t=>lt(e,t),[e],W(3e4)),i=Ue(Object.fromEntries([[`score`,t?.score],...(t?.readings??[]).map(e=>[e.key,Math.round(e.score)])]));return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Market mood`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`How broad the buying or selling is, from fear (0) to greed (100)`}),t&&(0,U.jsx)(q,{live:t.live,at:r})]}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[n&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:n}),!t&&!n&&(0,U.jsx)(B,{className:`min-h-56`,steps:e===`crypto`?[`Loading six months of prices for the most-traded coins…`,`Counting moving averages and highs…`,`Reading funding rates…`]:[`Loading a year of prices for the largest stocks…`,`Counting moving averages and highs…`,`Reading the volatility index…`]}),t&&t.score!=null&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-4 py-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,U.jsx)(`span`,{className:m(`tabular rounded text-3xl font-semibold`,i(`score`)),children:Math.round(t.score)}),(0,U.jsx)(`span`,{className:`text-base font-medium`,children:t.label})]}),(0,U.jsxs)(`span`,{className:`text-xs text-faint`,children:[`average of `,t.readings.length,` readings`]})]}),(0,U.jsxs)(`div`,{className:`mt-3`,children:[(0,U.jsx)(un,{score:t.score,big:!0}),(0,U.jsx)(`div`,{className:`mt-1.5 hidden justify-between text-[11px] text-faint sm:flex`,children:ln.map(e=>(0,U.jsx)(`span`,{children:e.label},e.label))})]})]}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:t.readings.map(e=>(0,U.jsxs)(`div`,{className:`rounded-lg border border-line px-3 py-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-xs`,children:[(0,U.jsx)(`span`,{className:`text-muted`,children:e.label}),(0,U.jsx)(`span`,{className:m(`tabular shrink-0 rounded font-semibold`,i(e.key)),children:Math.round(e.score)})]}),(0,U.jsx)(`div`,{className:`tabular mb-1.5 text-[12px]`,children:e.value}),(0,U.jsx)(un,{score:e.score}),(0,U.jsx)(`div`,{className:`mt-1 text-[11px] text-faint`,children:e.label_text})]},e.key))}),(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Universe: `,t.universe,`; momentum uses the `,t.index,`. Each reading is scaled 0-100 and the gauge is their plain average. Source:`,` `,t.source,`. A description of how the market is behaving now, not a forecast or advice.`]})]})]})]})}var fn=[{value:`gainers`,label:`Gainers`},{value:`losers`,label:`Losers`},{value:`active`,label:`Most active`},{value:`near_high`,label:`Near 52w high`},{value:`near_low`,label:`Near 52w low`}],pn=[{value:`100`,label:`Top 100`},{value:`500`,label:`Top 500`},{value:`2000`,label:`Top 2000`}];function mn({market:e,onCategory:t}){let[n,r]=(0,V.useState)(`500`),[a,s]=(0,V.useState)(`gainers`),{data:l,error:d,at:f}=K(t=>xe(e,Number(n),t),[e,n],W(15e3)),p=e===`crypto`?`by volume`:`by market cap`,h=(0,V.useContext)(He),g=(0,V.useMemo)(()=>(l?l[a]:[]).map(t=>({...t,market:e})),[l,a,e]),_=je(g,h),v=_.rows,b=Ue(Object.fromEntries([...(l?.indices??[]).map(e=>[`i:${e.name}`,e.price])]));return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 px-5 py-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Market pulse`}),l&&(0,U.jsxs)(`p`,{className:`text-xs text-muted`,children:[`Leaders among the `,l.universe.toLocaleString(),` largest `,p,l.live?.live?l.live.open?` on live prices`:``:l.as_of?` · prices ${o(l.as_of)}`:``]}),l&&(0,U.jsx)(q,{live:l.live,at:f,ticking:_.status.updated})]})}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[d&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:d}),!l&&!d&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Fetching index levels…`,`Counting advancing and declining stocks…`,`Ranking gainers and losers…`,`Weighing sectors by market cap…`]}),l&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-3`,children:[l.indices.map(e=>(0,U.jsxs)(`div`,{className:`min-w-[140px] rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`text-xs text-muted`,children:e.name}),(0,U.jsx)(`div`,{className:m(`tabular rounded text-sm font-semibold`,b(`i:${e.name}`)),children:c(e.price)}),(0,U.jsx)(`div`,{className:m(`tabular text-xs`,i(e.change_percent)),children:u(e.change_percent)})]},e.name)),(0,U.jsx)(hn,{breadth:l.breadth})]}),(0,U.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 space-y-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(y,{size:`sm`,value:a,onChange:e=>s(e),options:fn}),(0,U.jsx)(y,{size:`sm`,value:n,onChange:r,options:pn})]}),v.length>0&&(0,U.jsxs)(`div`,{className:`text-xs text-faint`,children:[v.length,` `,v.length===1?`stock`:`stocks`,` among the top `,Number(n).toLocaleString(),v.length>10?` · scroll for more`:``]}),(0,U.jsx)(gn,{rows:v,market:e,board:a,flash:_.flash})]}),l.sectors.length>0&&(0,U.jsx)(_n,{sectors:l.sectors,market:e,onCategory:t})]})]})]})]})}function hn({breadth:e}){let{advancers:t,decliners:n,unchanged:r,total:i}=e;if(!i)return null;let a=e=>`${e/i*100}%`;return(0,U.jsxs)(`div`,{className:`min-w-[220px] flex-1 rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsxs)(`div`,{className:`flex justify-between text-xs text-muted`,children:[(0,U.jsxs)(`span`,{children:[`Breadth · `,i.toLocaleString(),` stocks`]}),(0,U.jsxs)(`span`,{className:`tabular`,children:[(0,U.jsxs)(`span`,{className:`text-up`,children:[t.toLocaleString(),` up`]}),` · `,(0,U.jsxs)(`span`,{className:`text-down`,children:[n.toLocaleString(),` down`]})]})]}),(0,U.jsxs)(`div`,{className:`mt-2 flex h-2 overflow-hidden rounded-full bg-raised`,title:`${r} unchanged`,children:[(0,U.jsx)(`div`,{className:`bg-up`,style:{width:a(t)}}),(0,U.jsx)(`div`,{className:`bg-line-strong`,style:{width:a(r)}}),(0,U.jsx)(`div`,{className:`bg-down`,style:{width:a(n)}})]})]})}function gn({rows:e,market:t,board:r,flash:a}){if(e.length===0)return(0,U.jsx)(`p`,{className:`py-6 text-center text-sm text-muted`,children:r.startsWith(`near`)?`No 52-week range data for this market, or nothing near it today.`:`Nothing to show.`});let o=r===`active`,s=r===`near_high`?`high_52w`:r===`near_low`?`low_52w`:null;return(0,U.jsx)(S,{className:`pe-1`,children:(0,U.jsx)(`table`,{className:`w-full text-sm`,children:(0,U.jsx)(`tbody`,{className:`divide-y divide-line`,children:e.map(e=>(0,U.jsxs)(`tr`,{children:[(0,U.jsxs)(`td`,{className:`w-full max-w-0 py-1.5 pe-2`,children:[(0,U.jsx)(D,{to:Se({symbol:e.symbol,market:t}),className:`font-mono text-sm hover:text-accent-fg`,children:e.symbol}),(0,U.jsx)(`div`,{className:`truncate text-[12px] text-faint`,children:e.name})]}),(0,U.jsx)(`td`,{className:m(`tabular whitespace-nowrap py-1.5 pe-2 text-end`,a({...e,market:t})),children:n(e.price,e.currency)}),(0,U.jsx)(`td`,{className:m(`tabular py-1.5 pe-2 text-end`,i(e.change_percent)),children:u(e.change_percent)}),(0,U.jsx)(`td`,{className:`tabular hidden whitespace-nowrap py-1.5 text-end text-xs text-muted sm:table-cell`,children:o?`${d(e.traded_value)} traded`:s&&e[s]&&e.price?`${u((e.price/e[s]-1)*100,1)} vs ${r===`near_high`?`high`:`low`}`:e.market_cap?`cap ${d(e.market_cap)}`:``})]},e.symbol))})})})}function _n({sectors:e,market:t,onCategory:n}){let[r,a]=(0,V.useState)(null);(0,V.useEffect)(()=>a(null),[t]);let o=Math.max(.5,...e.map(e=>Math.abs(e.change_percent??0))),s=e.find(e=>e.sector===r);return(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:`Sectors (cap-weighted day change) · click to pin`}),(0,U.jsx)(S,{className:`pe-1`,children:(0,U.jsx)(`ul`,{className:`space-y-1`,children:e.map(e=>{let t=e.change_percent??0,n=r===e.sector;return(0,U.jsx)(`li`,{children:(0,U.jsxs)(`button`,{type:`button`,"aria-pressed":n,onClick:()=>a(n?null:e.sector),className:m(`grid w-full grid-cols-[minmax(0,9rem)_minmax(0,1fr)_4rem] items-center gap-2 rounded px-1 py-0.5 text-start text-xs transition-colors focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-accent`,n?`bg-accent-soft font-medium shadow-[inset_3px_0_0_var(--color-accent)]`:`hover:bg-raised`),title:n?`Click again to unpin`:`Click to pin · ${e.count} stocks · ${e.advancers} up / ${e.decliners} down${e.leader?` · best ${e.leader.symbol} ${u(e.leader.change_percent,1)}`:``}${e.laggard?` · worst ${e.laggard.symbol} ${u(e.laggard.change_percent,1)}`:``}`,children:[(0,U.jsx)(`span`,{className:m(`truncate`,n&&`ps-1.5`),children:e.sector}),(0,U.jsx)(`span`,{className:`relative h-2 rounded-full bg-raised`,children:(0,U.jsx)(`span`,{className:m(`absolute top-0 h-2 rounded-full`,t>=0?`left-1/2 bg-up`:`right-1/2 bg-down`),style:{width:`${Math.abs(t)/o*50}%`}})}),(0,U.jsx)(`span`,{className:m(`tabular text-end`,i(t)),children:u(e.change_percent)})]})},e.sector)})})}),s&&(0,U.jsxs)(`div`,{className:`mt-3 rounded-lg border border-accent/40 bg-accent-soft px-3 py-2.5`,children:[(0,U.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2 text-xs`,children:[(0,U.jsxs)(`span`,{className:`min-w-0 truncate font-medium text-fg`,children:[s.sector,` · `,(0,U.jsx)(`span`,{className:i(s.change_percent),children:u(s.change_percent)}),(0,U.jsxs)(`span`,{className:`font-normal text-muted`,children:[` · `,s.advancers,` up / `,s.decliners,` down of `,s.count]})]}),(0,U.jsxs)(`span`,{className:`flex shrink-0 gap-3`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>n(s.sector),className:`text-accent-fg hover:text-fg`,children:`Filter list`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>a(null),className:`text-muted hover:text-fg`,children:`Unpin`})]})]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:(s.members??[]).map(e=>(0,U.jsxs)(D,{to:Se({symbol:e.symbol,market:t}),className:`rounded-md border border-line bg-surface px-2 py-0.5 font-mono text-xs hover:border-accent hover:text-accent-fg`,children:[e.symbol,` `,(0,U.jsx)(`span`,{className:m(`tabular`,i(e.change_percent)),children:u(e.change_percent,1)})]},e.symbol))})]})]})}function vn({market:e}){let{data:t,error:n,at:r}=K(e=>at(e),[],G),i=t&&t.india.indices.length>0?(0,U.jsx)(Cn,{data:t}):null,a=t&&t.us.series.length>0?(0,U.jsx)(bn,{data:t}):null;return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Market valuation`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`How the whole market is priced today, against its own history`}),(0,U.jsx)(q,{at:r,daily:`Valuations update once a day`})]}),(0,U.jsxs)(`div`,{className:`space-y-5 px-5 pb-4`,children:[n&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:n}),!t&&!n&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Reading S&P 500 history…`,`Reading Nifty valuations…`]}),e===`india`||e===`all`?(0,U.jsxs)(U.Fragment,{children:[i,a]}):(0,U.jsxs)(U.Fragment,{children:[a,i]}),t&&(0,U.jsx)(`p`,{className:`text-[12px] text-faint`,children:`A percentile says where today's reading sits in the record (90th = higher than 90% of past months). It describes the past; it is not a forecast.`})]})]})}function yn({value:e}){return e==null?null:(0,U.jsx)(`div`,{className:`mt-1 h-1.5 rounded-full bg-line`,title:`${e}th percentile`,children:(0,U.jsx)(`div`,{className:`h-1.5 rounded-full bg-accent`,style:{width:`${Math.max(2,e)}%`}})})}function bn({data:e}){return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:`S&P 500 (US)`}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:e.us.series.map(e=>(0,U.jsx)(xn,{s:e},e.key))}),(0,U.jsxs)(`p`,{className:`mt-2 text-[12px] text-faint`,children:[`Source: `,e.us.source,`. Values marked ~ are estimates for the current month.`,e.us.failed.length>0&&` Unavailable now: ${e.us.failed.join(`, `)}.`]})]})}function xn({s:e}){let t=e.key.includes(`yield`)?`%`:``;return(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,title:e.note,children:[(0,U.jsxs)(`div`,{className:`flex justify-between gap-2 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`truncate`,children:e.label}),(0,U.jsxs)(`span`,{className:`shrink-0 text-faint`,children:[e.stale?`saved copy · `:``,e.date]})]}),(0,U.jsxs)(`div`,{className:`flex items-end justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`tabular text-lg font-semibold`,children:[e.estimated?`~`:``,c(e.value,2),t]}),(0,U.jsxs)(`div`,{className:`tabular text-[11px] text-faint`,children:[e.percentile_all!=null&&`${Math.round(e.percentile_all)}th pct since ${e.since.slice(0,4)}`,e.percentile_1990!=null&&` · ${Math.round(e.percentile_1990)}th since 1990`]}),(0,U.jsx)(yn,{value:e.percentile_all}),(0,U.jsxs)(`div`,{className:`tabular mt-1 text-[11px] text-faint`,children:[`Median `,c(e.median_all,1),t,` all-time · `,c(e.median_1990,1),t,` since 1990`]})]}),(0,U.jsx)(`div`,{className:`h-12 w-20 shrink-0 sm:w-24`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(j,{data:e.spark,margin:{top:2,right:0,bottom:2,left:0},children:[(0,U.jsx)(F,{hide:!0,domain:[`auto`,`auto`]}),(0,U.jsx)(se,{type:`monotone`,dataKey:`value`,stroke:`var(--color-accent)`,strokeWidth:1.5,fill:`var(--color-accent)`,fillOpacity:.12,isAnimationActive:!1})]})})})]})]})}function Sn(e){return e.toLowerCase().replace(/\b[a-z]/g,e=>e.toUpperCase())}function Cn({data:e}){let t=e.india.indices,n=t.length>0&&t[0].pe_percentile==null;return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:`Nifty indices (India)`}),(0,U.jsx)(`div`,{className:`overflow-x-auto`,children:(0,U.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,U.jsx)(`thead`,{children:(0,U.jsxs)(`tr`,{className:`text-start text-xs text-muted`,children:[(0,U.jsx)(`th`,{className:`py-1 pe-3 font-medium`,children:`Index`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:`P/E`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:`P/B`}),(0,U.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:`Yield`}),(0,U.jsx)(`th`,{className:`py-1 text-end font-medium`,children:`P/E 1y ago`})]})}),(0,U.jsx)(`tbody`,{children:t.map(e=>(0,U.jsxs)(`tr`,{className:`border-t border-line`,children:[(0,U.jsx)(`td`,{className:`py-1.5 pe-3`,children:Sn(e.index)}),(0,U.jsxs)(`td`,{className:`tabular py-1.5 pe-3 text-end`,children:[c(e.pe,2),e.pe_percentile!=null&&(0,U.jsxs)(`span`,{className:`text-[11px] text-faint`,children:[` · `,Math.round(e.pe_percentile),`th`]})]}),(0,U.jsx)(`td`,{className:`tabular py-1.5 pe-3 text-end`,children:c(e.pb,2)}),(0,U.jsx)(`td`,{className:`tabular py-1.5 pe-3 text-end`,children:e.dy==null?`—`:`${c(e.dy,2)}%`}),(0,U.jsx)(`td`,{className:`tabular py-1.5 text-end text-muted`,children:e.pe_year_ago==null?`—`:c(e.pe_year_ago,2)})]},e.index))})]})}),(0,U.jsxs)(`p`,{className:`mt-2 text-[12px] text-faint`,children:[`Source: `,e.india.source,e.india.stale?` (NSE did not answer; showing the last saved day)`:``,`.`,n&&` Percentiles appear once a year of daily history has been saved (${t[0].history_days} day${t[0].history_days===1?``:`s`} so far).`]})]})}var wn={us:`Fed and money-market rates, Treasury yields, and gold / silver in dollars`,hong_kong:`HKMA base rate, HIBOR, the HK dollar peg, and gold / silver in HK dollars`,china_a:`Interbank rates, the yuan, and gold / silver in yuan`,crypto:`Perpetual funding rates (crypto's cost of leverage) and Bitcoin priced in gold`},Tn={us:[`Reading official Fed and Treasury rates…`,`Fetching gold and silver futures…`],hong_kong:[`Reading HKMA base rate and HIBOR…`,`Checking the HK dollar peg…`,`Pricing gold per tael…`],china_a:[`Reading interbank rates…`,`Converting gold to yuan…`],crypto:[`Reading perpetual funding rates…`,`Pricing Bitcoin in gold…`]};function En(e,t){if(t==null)return null;let n=e.change_kind===`pct`?`${t>0?`+`:``}${c(t,1)}%`:`${t>0?`+`:``}${c(t,2)}`;return(0,U.jsx)(`span`,{className:m(`tabular`,t>0?`text-up`:t<0?`text-down`:`text-muted`),children:n})}function Dn(e){if(e.unit===`%`||e.unit===`% / yr`)return`${c(e.value,e.unit===`%`?2:1)}%`;if(e.unit===`pts`)return`${e.value>0?`+`:``}${c(e.value,2)}`;if(e.unit===`x`||e.unit===`oz`)return`${c(e.value,1)}${e.unit===`x`?`×`:` oz`}`;let t=Math.abs(e.value)>=1e3?0:Math.abs(e.value)>=20?2:4;return`${e.unit}${e.value.toLocaleString(void 0,{maximumFractionDigits:t})}`}function On({i:e}){let t=e.spark.map((e,t)=>({idx:t,v:e}));return(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2.5`,title:e.note||void 0,children:[(0,U.jsx)(`div`,{className:`truncate text-xs text-muted`,children:e.label}),(0,U.jsxs)(`div`,{className:`flex items-end justify-between gap-2`,children:[(0,U.jsx)(`div`,{className:m(`tabular text-lg font-semibold`,e.tone===`up`&&`text-up`,e.tone===`down`&&`text-down`),children:Dn(e)}),t.length>4&&(0,U.jsx)(`div`,{className:`h-7 w-20 shrink-0`,children:(0,U.jsx)(L,{width:`100%`,height:`100%`,children:(0,U.jsxs)(I,{data:t,children:[(0,U.jsx)(F,{hide:!0,domain:[`dataMin`,`dataMax`]}),(0,U.jsx)(N,{dataKey:`v`,stroke:`var(--color-accent)`,strokeWidth:1.5,dot:!1,isAnimationActive:!1})]})})})]}),(e.change_1m!=null||e.change_1y!=null)&&(0,U.jsxs)(`div`,{className:`mt-0.5 flex gap-3 text-[12px] text-faint`,children:[e.change_1m!=null&&(0,U.jsxs)(`span`,{children:[`1m `,En(e,e.change_1m)]}),e.change_1y!=null&&(0,U.jsxs)(`span`,{children:[`1y `,En(e,e.change_1y)]})]}),e.note&&(0,U.jsx)(`div`,{className:`mt-1 line-clamp-2 text-[12px] text-faint`,children:e.note})]})}function kn({market:e}){let{data:t,error:n,at:r}=K(t=>rt(e,t),[e],G);return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:t?.title??`Rates & bullion`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:wn[e]??``}),(0,U.jsx)(q,{at:r,daily:`Rates daily, prices hourly`})]}),(0,U.jsxs)(`div`,{className:`space-y-6 px-5 pb-4`,children:[n&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:n}),!t&&!n&&(0,U.jsx)(B,{className:`min-h-56`,steps:Tn[e]??[`Loading rates…`]}),t?.errors.map(e=>(0,U.jsx)(`p`,{className:`rounded-md bg-warn-soft px-3 py-2 text-xs text-warn`,children:e},e)),t?.sections.map(e=>(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-baseline justify-between gap-2`,children:[(0,U.jsx)(`span`,{className:`text-xs font-medium text-muted`,children:e.title}),e.source&&(0,U.jsx)(`span`,{className:`text-[12px] text-faint`,children:e.source})]}),(0,U.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:e.items.map(e=>(0,U.jsx)(On,{i:e},e.label))}),e.note&&(0,U.jsx)(`p`,{className:`mt-2 text-[12px] text-faint`,children:e.note})]},e.title))]})]})}async function An(e=`india`,t=`stock`){return(await h.get(`/screens`,{params:{market:e,asset:t}})).data}async function jn(e,t,n=`stock`){return(await h.get(`/screens/${e}`,{params:{market:t,asset:n},timeout:12e4})).data}async function Mn(){return(await h.get(`/screens/metrics`)).data}async function Nn(e,t){return(await h.post(`/screens/custom`,{...e,market:t},{timeout:12e4})).data}var Pn=`mm.customScreen`,Fn=12,In={rules:[{field:`roe`,op:`>`,value:15},{field:`pe`,op:`between`,value:0,value2:25},{field:`debt_equity`,op:`<`,value:1}],sectors:[],sort:`roe`,descending:!0,columns:[],large_only:!1},Ln=[{value:`>`,label:`above`},{value:`<`,label:`below`},{value:`between`,label:`between`},{value:`top`,label:`in the top %`},{value:`bottom`,label:`in the bottom %`},{value:`below_sector`,label:`below sector median`},{value:`above_sector`,label:`above sector median`}],Rn=`h-8 rounded-lg border border-line bg-canvas px-2 text-xs text-fg focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent-soft`;function zn(){try{let e=JSON.parse(localStorage.getItem(Pn)??`null`);if(e&&Array.isArray(e.rules)&&e.rules.length)return{...In,...e}}catch{}return In}function Bn(e){try{localStorage.setItem(Pn,JSON.stringify(e))}catch{}}var Vn=e=>e.rules.map(e=>({field:e.field,op:e.op,value:e.value==null?``:String(e.value),value2:e.value2==null?``:String(e.value2)})),Hn=e=>e.trim()===``||!Number.isFinite(Number(e))?null:Number(e);function Un({groups:e,value:t,onChange:n,className:r}){return(0,U.jsx)(`select`,{value:t,onChange:e=>n(e.target.value),className:m(Rn,r),"aria-label":`Metric`,children:e.map(e=>(0,U.jsx)(`optgroup`,{label:e.group,children:e.metrics.map(e=>(0,U.jsx)(`option`,{value:e.key,title:e.hint,children:e.label},e.key))},e.group))})}function Wn({spec:e,sectors:t,running:n,onRun:r}){let[i,a]=(0,V.useState)([]),[o,s]=(0,V.useState)(()=>Vn(e)),[c,l]=(0,V.useState)(e.sectors),[u,d]=(0,V.useState)(e.sort??``),[f,p]=(0,V.useState)(e.descending),[h,g]=(0,V.useState)(e.columns),[_,y]=(0,V.useState)(e.large_only),[b,S]=(0,V.useState)(null);(0,V.useEffect)(()=>{Mn().then(a).catch(()=>void 0)},[]);let C=e=>i.flatMap(e=>e.metrics).find(t=>t.key===e)?.label??e,T=e=>i.flatMap(e=>e.metrics).find(t=>t.key===e)?.hint;function E(e,t){s(n=>n.map((n,r)=>r===e?{...n,...t}:n))}function ee(){let e=[];for(let t of o){let n=Hn(t.value),r=t.op===`below_sector`||t.op===`above_sector`;if(n==null&&!r)return S(`${C(t.field)}: enter a number`);if(t.op===`between`&&Hn(t.value2)==null)return S(`${C(t.field)}: enter both ends of the range`);if((t.op===`top`||t.op===`bottom`)&&!(n>0&&n<=100))return S(`${C(t.field)}: pick a percent from 1 to 100`);e.push({field:t.field,op:t.op,value:n,...t.op===`between`?{value2:Hn(t.value2)}:{}})}if(!e.length)return S(`Add at least one rule`);S(null);let t={rules:e,sectors:c,sort:u||e[0].field,descending:f,columns:h,large_only:_};Bn(t),r(t)}let te=[...new Set([...o.map(e=>e.field),...h,`market_cap`,`price`])],D=[...new Set([...t,...c])].sort();return(0,U.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-line bg-canvas/40 p-3`,children:[(0,U.jsxs)(`div`,{className:`space-y-2`,children:[o.map((e,t)=>{let n=e.op===`below_sector`||e.op===`above_sector`,r=e.op===`top`||e.op===`bottom`;return(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i.length?(0,U.jsx)(Un,{groups:i,value:e.field,onChange:e=>E(t,{field:e}),className:`w-44`}):(0,U.jsx)(`span`,{className:m(Rn,`inline-flex w-44 items-center text-muted`),children:e.field}),(0,U.jsx)(`select`,{value:e.op,onChange:e=>E(t,{op:e.target.value}),className:m(Rn,`w-40`),"aria-label":`Operator`,children:Ln.map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value))}),n&&(0,U.jsx)(`span`,{className:`text-xs text-faint`,children:`×`}),(0,U.jsx)(v,{value:e.value,onChange:e=>E(t,{value:e.target.value}),onKeyDown:e=>e.key===`Enter`&&ee(),placeholder:n?`1`:r?`10`:`Value`,inputMode:`decimal`,className:`h-8 w-20 text-xs`,"aria-label":`Value`}),e.op===`between`&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`text-xs text-faint`,children:`and`}),(0,U.jsx)(v,{value:e.value2,onChange:e=>E(t,{value2:e.target.value}),onKeyDown:e=>e.key===`Enter`&&ee(),placeholder:`Value`,inputMode:`decimal`,className:`h-8 w-20 text-xs`,"aria-label":`Upper value`})]}),r&&(0,U.jsx)(`span`,{className:`text-xs text-faint`,children:`%`}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>s(e=>e.filter((e,n)=>n!==t)),className:`rounded p-1 text-faint hover:text-down`,"aria-label":`Remove rule`,title:`Remove rule`,children:(0,U.jsx)(x,{name:`x`,className:`h-3.5 w-3.5`})}),T(e.field)&&(0,U.jsx)(`span`,{className:`hidden text-[11px] text-faint lg:inline`,children:T(e.field)})]},t)}),o.length<Fn&&(0,U.jsx)(`button`,{type:`button`,onClick:()=>s(e=>[...e,{field:`pe`,op:`<`,value:``,value2:``}]),className:`inline-flex items-center gap-1 text-xs text-accent-fg hover:underline`,children:`+ Add rule`})]}),D.length>0&&(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsxs)(`div`,{className:`text-xs font-medium text-muted`,children:[`Sectors `,(0,U.jsx)(`span`,{className:`font-normal text-faint`,children:c.length?`${c.length} picked`:`all`})]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:D.map(e=>(0,U.jsx)(`button`,{type:`button`,"aria-pressed":c.includes(e),onClick:()=>l(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:m(`rounded-full border px-2.5 py-0.5 text-[11px]`,c.includes(e)?`border-accent bg-accent-soft text-fg`:`border-line text-muted hover:border-line-strong hover:text-fg`),children:e},e))})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-xs`,children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-muted`,children:[`Sort by`,(0,U.jsx)(`select`,{value:u||o[0]?.field||``,onChange:e=>d(e.target.value),className:Rn,children:te.map(e=>(0,U.jsx)(`option`,{value:e,children:C(e)},e))}),(0,U.jsxs)(`select`,{value:f?`desc`:`asc`,onChange:e=>p(e.target.value===`desc`),className:Rn,"aria-label":`Sort order`,children:[(0,U.jsx)(`option`,{value:`desc`,children:`high first`}),(0,U.jsx)(`option`,{value:`asc`,children:`low first`})]})]}),(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-muted`,children:[`Show also`,i.length>0&&(0,U.jsx)(Un,{groups:[{group:``,metrics:[{key:``,label:`add a column…`,hint:``}]},...i],value:``,onChange:e=>e&&!h.includes(e)&&g(t=>[...t,e])})]}),h.map(e=>(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-line px-2 py-0.5 text-[11px] text-muted`,children:[C(e),(0,U.jsx)(`button`,{type:`button`,onClick:()=>g(t=>t.filter(t=>t!==e)),"aria-label":`Remove ${C(e)} column`,className:`hover:text-down`,children:(0,U.jsx)(x,{name:`x`,className:`h-3 w-3`})})]},e)),(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-muted`,children:[(0,U.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>y(e.target.checked),className:`h-3.5 w-3.5 accent-[var(--color-accent)]`}),`Largest 100 only`]})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,U.jsx)(w,{size:`sm`,icon:`filter`,loading:n,onClick:ee,children:`Run screen`}),b&&(0,U.jsx)(`span`,{className:`text-xs text-down`,children:b}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>{s(Vn(In)),l([]),d(In.sort??``),p(!0),g([]),y(!1),S(null)},className:`text-xs text-muted hover:text-fg`,children:`Reset`})]})]})}function Gn(e,t){if(e===`sector`)return t||`—`;let n=t;return e===`pe_vs_sector`||e===`pb_vs_sector`?n==null?`—`:`${c(n,1)}×`:e===`volume`?d(n):e===`analysts`?c(n,0):c(n,e===`debt_equity`||e===`pb`?2:1)}var Kn=[],qn=[`pe`,`pb`,`ps`,`pe_vs_sector`,`pb_vs_sector`,`peg`,`market_cap`],Jn=[`dividend_yield`,`earnings_yield`,`fcf_yield`],Yn={open:!0,live:!0,updated:null,age_seconds:null,refresh_seconds:1,covered:0,source:`Live prices`,error:null};function Xn(e,t){let n=t&&e.price?e.price/t:1;if(n===1)return e;let r={...e};for(let t of qn)typeof e[t]==`number`&&(r[t]=e[t]*n);for(let t of Jn)typeof e[t]==`number`&&(r[t]=e[t]/n);for(let t of[`from_high`,`from_low`])typeof e[t]==`number`&&(r[t]=((1+e[t]/100)*n-1)*100);return typeof e.target_upside==`number`&&(r.target_upside=((1+e.target_upside/100)/n-1)*100),r}var Zn=(e,t)=>e===`crypto`?`volume_leaders`:t===`etf`?`most_traded`:`undervalued_large`,Qn=`custom`,$n=[`india`,`us`,`hong_kong`,`china_a`],er=[{value:`stock`,label:`Stocks`},{value:`etf`,label:`ETFs`}];function tr({market:e}){let t=e===`crypto`,[r,a]=(0,V.useState)(`stock`),o=r===`etf`&&$n.includes(e),s=o?`etf`:`stock`,c=t||o,[l,f]=(0,V.useState)([]),[p,h]=(0,V.useState)(()=>Zn(e,s)),[g,v]=(0,V.useState)(`${e}:${s}`),[b,C]=(0,V.useState)([]);g!==`${e}:${s}`&&(v(`${e}:${s}`),f([]),h(Zn(e,s)),C([]));let[w,T]=(0,V.useState)(zn),[E,ee]=(0,V.useState)(0),te=`${JSON.stringify(w)}#${E}`,{data:O,error:ne,at:re}=K(()=>p===Qn?Nn(w,e).then(e=>(C(e.sectors),e)):jn(p,e,s),[p,e,s,p===Qn?te:``],3e5),k=!O&&!ne,A=(0,V.useContext)(He),j=je(O?.results??Kn,A),M=(0,V.useMemo)(()=>{let e=new Map((O?.results??[]).map(e=>[e.symbol,e.price]));return j.rows.map(t=>Xn(t,e.get(t.symbol)))},[j.rows,O]);(0,V.useEffect)(()=>{l.length||An(e,s).then(f).catch(()=>void 0)},[l.length,e,s]);let N=Be(e,O?.results??[]),ie=p===Qn?`your screen`:l.find(e=>e.key===p)?.title??`this screen`,P=M.slice(0,5).map(t=>({symbol:t.symbol,market:e}));return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-5 py-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Ready-made screens`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:t?`Momentum, strength vs Bitcoin, oversold and breakout picks from the most-traded coins`:o?`Liquidity, returns, strength vs the index and volatility picks from the market's main ETFs`:`Value, growth, dividend and quality picks from the market's largest companies`}),O&&(0,U.jsx)(q,{live:j.status.updated==null?null:{...Yn,open:Object.values(j.status.markets).some(e=>e.open)},at:re,ticking:j.status.updated,daily:`Re-checked every 5 min`})]}),$n.includes(e)&&(0,U.jsx)(y,{options:er,value:s,onChange:e=>a(e),size:`sm`})]}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[(0,U.jsxs)(`div`,{className:`no-scrollbar -mx-5 flex gap-2 overflow-x-auto px-5 sm:mx-0 sm:flex-wrap sm:px-0`,children:[(l.length?l:[{key:Zn(e,s),title:c?`Most traded`:`Low-multiple large caps`}]).map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>h(e.key),title:e.description,className:m(`shrink-0 whitespace-nowrap rounded-full border px-3 py-1 text-xs`,p===e.key?`border-accent bg-accent/10 text-fg`:`border-line text-muted hover:border-line-strong hover:text-fg`),children:[k&&p===e.key&&(0,U.jsx)(_,{className:`me-1.5 inline-block h-3 w-3 align-[-2px] text-accent`}),e.title]},e.key)),!c&&(0,U.jsxs)(`button`,{type:`button`,onClick:()=>h(Qn),title:`Pick your own metrics, values, sectors and columns`,className:m(`inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded-full border px-3 py-1 text-xs`,p===Qn?`border-accent bg-accent/10 text-fg`:`border-dashed border-line text-muted hover:border-line-strong hover:text-fg`),children:[k&&p===Qn?(0,U.jsx)(_,{className:`h-3 w-3 text-accent`}):(0,U.jsx)(x,{name:`filter`,className:`h-3 w-3`}),`Build your own`]})]}),p===Qn&&(0,U.jsx)(Wn,{spec:w,sectors:b,running:k,onRun:e=>{T(e),ee(e=>e+1)}},e),ne&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:ne}),(k||!O)&&!ne&&(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(B,{className:`min-h-56`,steps:[t?`Loading six months of coin prices…`:o?`Loading a year of ETF prices…`:`Loading the largest companies…`,`Applying the rules for ${ie.toLowerCase()}…`,`Collecting the matches…`]},p),!O&&(0,U.jsx)(`p`,{className:`text-xs text-faint`,children:t?`First run checks the 100 most-traded coins.`:o?`First run checks about 120 of the main and most-traded ETFs.`:`First run checks the 200 largest companies; this can take half a minute.`})]}),O&&!k&&(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsxs)(`p`,{className:`text-xs text-muted`,children:[(0,U.jsxs)(`span`,{className:`font-medium text-fg`,children:[O.description,`.`]}),` `,O.rules.join(` · `)]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e===`china_a`&&(0,U.jsx)(Ve,{loading:N.loading}),(0,U.jsx)(Oe,{title:`Screen ${O.title} ${e}`,subtitle:O.rules.join(` | `),tables:()=>[{title:O.title,columns:[{key:`symbol`,label:`Symbol`},{key:`name`,label:`Name`},{key:`sector`,label:`Sector`},t?{key:`volume`,label:`24h volume`,kind:`money`}:o?{key:`volume`,label:`Avg daily turnover`,kind:`money`}:{key:`market_cap`,label:`Market cap`,kind:`money`},{key:`price`,label:`Price`,kind:`number`},...O.columns.map(e=>({key:e.key,label:e.label,kind:e.key===`sector`?void 0:`number`}))],rows:M,note:`${O.description}. Rules: ${O.rules.join(`; `)}. ${O.universe}. ${t?`Prices from crypto exchange data.`:o?`Daily prices from the market data feed.`:`Fundamentals from the market data feed.`}`}]}),P.length>=2&&(0,U.jsxs)(D,{to:z(P),className:`inline-flex items-center gap-1.5 rounded-md border border-line px-2.5 py-1 text-xs text-muted hover:border-line-strong hover:text-fg`,children:[(0,U.jsx)(x,{name:`compare`,className:`h-3.5 w-3.5`}),` Compare top `,P.length]})]})]}),p===`expensive_sector`&&(0,U.jsxs)(`details`,{className:`rounded-lg bg-canvas px-3 py-2 text-xs text-muted`,children:[(0,U.jsx)(`summary`,{className:`cursor-pointer font-medium text-fg`,children:`How to read this`}),(0,U.jsxs)(`ul`,{className:`mt-2 list-disc space-y-1 ps-4`,children:[(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`b`,{className:`text-fg`,children:`P/E`}),`: share price ÷ yearly profit per share. A P/E of 120 means you pay ₹120 for every ₹1 the company earns in a year.`]}),(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`b`,{className:`text-fg`,children:`Sector P/E`}),`: the middle P/E among the largest companies in the same sector, since each industry normally trades at its own level. `,(0,U.jsx)(`b`,{className:`text-fg`,children:`P/E × sector`}),` = how many times that level this stock costs. Listed when above 1.5×.`]}),(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`b`,{className:`text-fg`,children:`PEG`}),`: P/E ÷ profit growth %. Around 1 means price and growth match; above 2 the price runs well ahead of growth. Listed only when PEG is above 2 or profits are shrinking, so fast growers that earn their price are left out.`]}),(0,U.jsxs)(`li`,{children:[(0,U.jsx)(`b`,{className:`text-fg`,children:`EPS growth %`}),` compares the latest quarter with the same quarter a year earlier (reported figures), so one unusual quarter can make it jump.`]}),(0,U.jsx)(`li`,{children:`Expensive is not the same as "will fall": markets sometimes pay more for a strong brand, a monopoly or future plans. Use it as a question to research, not a verdict.`})]})]}),M.length===0?(0,U.jsxs)(`p`,{className:`py-4 text-center text-sm text-muted`,children:[o?`No ETF`:t?`No coin`:`No company`,` passes every rule right now.`]}):(0,U.jsx)(S,{className:`overflow-x-auto`,children:(0,U.jsxs)(`table`,{className:`tabular w-full min-w-[40rem] text-sm`,children:[(0,U.jsx)(`thead`,{className:`text-xs text-muted`,children:(0,U.jsxs)(`tr`,{className:`border-b border-line`,children:[(0,U.jsx)(`th`,{className:`py-2 text-start font-medium`,children:o?`ETF`:t?`Coin`:`Company`}),!c&&(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Mkt cap`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Price`}),(0,U.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Day`}),O.columns.map(e=>(0,U.jsx)(`th`,{className:m(`px-2 py-2 font-medium`,e.key===`sector`?`text-start`:`text-end`),children:e.label},e.key))]})}),(0,U.jsx)(`tbody`,{className:`divide-y divide-line`,children:M.map(t=>(0,U.jsxs)(`tr`,{children:[(0,U.jsx)(`td`,{className:`max-w-[14rem] py-2`,children:(0,U.jsxs)(D,{to:`/analyze?symbol=${encodeURIComponent(t.symbol)}&market=${e}`,className:`block truncate hover:text-accent-fg`,title:t.name??t.symbol,children:[(0,U.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:t.symbol}),` `,(0,U.jsx)(`span`,{className:`text-xs text-muted`,children:N.name(t.symbol,t.name)})]})}),!c&&(0,U.jsx)(`td`,{className:`px-2 py-2 text-end`,children:d(t.market_cap)}),(0,U.jsx)(`td`,{className:m(`whitespace-nowrap px-2 py-2 text-end`,j.flash(t)),children:n(t.price,t.currency)}),(0,U.jsx)(`td`,{className:m(`px-2 py-2 text-end`,i(t.change_percent)),children:u(t.change_percent)}),O.columns.map(e=>(0,U.jsx)(`td`,{className:m(`px-2 py-2`,e.key===`sector`?`max-w-[9rem] truncate text-start text-xs text-muted`:`text-end`),children:Gn(e.key,t[e.key])},e.key))]},t.symbol))})]})}),(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[O.universe,`; `,O.scanned,` had data.`,` `,t?`Daily prices from crypto exchange data.`:o?`Daily prices from the market data feed; returns are price only, before dividends.`:`Fundamentals from the market data feed, latest reported.`,` `,`A starting point for research, not a recommendation.`]})]})]})]})}var nr=me(`index`),rr={lagging:0,weakening:1,improving:2,leading:3};function ir({market:e}){let[t,n]=(0,V.useState)(null),[r,a]=(0,V.useState)(null),o=t??r;(0,V.useEffect)(()=>a(null),[e]);let{data:s,error:c,at:l}=K(t=>Ce(e,t),[e],W(3e4)),d=Ue(Object.fromEntries((s?.sectors??[]).map(e=>[e.sector,rr[e.quadrant]])));return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`flex items-center justify-between gap-3 px-5 py-3`,children:(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Sector rotation`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:s?`${e===`crypto`?`Coin groups`:`Sectors`} vs ${s.benchmark.name}, weekly to ${s.as_of}${s.live?.live?` (this week on live prices)`:``} · click a sector to pin its ${s.sectors[0]?.tail.length??0}-week trail`:`Which sectors are gaining or losing strength against the index`}),s&&(0,U.jsx)(q,{live:s.live,at:l})]})}),(0,U.jsxs)(`div`,{className:`px-5 pb-4`,children:[c&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:c}),!s&&!c&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Loading weekly prices for sector baskets…`,`Comparing each sector with the index…`,`Placing sectors on the rotation chart…`]}),s&&(0,U.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[(0,U.jsx)(fe,{series:s.sectors.map(e=>({name:e.sector,tail:e.tail})),focus:o}),(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(S,{maxHeight:`36rem`,children:(0,U.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,U.jsxs)(`colgroup`,{children:[(0,U.jsx)(`col`,{}),(0,U.jsx)(`col`,{className:`w-28`}),(0,U.jsx)(`col`,{className:`w-20`})]}),(0,U.jsx)(`thead`,{className:`text-xs text-muted`,children:(0,U.jsxs)(`tr`,{children:[(0,U.jsx)(`th`,{className:`py-1 pe-4 ps-2 text-start font-medium`,children:`Sector`}),(0,U.jsx)(`th`,{className:`px-3 py-1 text-start font-medium`,children:`Phase`}),(0,U.jsx)(`th`,{className:`py-1 pe-2 ps-3 text-end font-medium`,children:`4 weeks`})]})}),(0,U.jsx)(`tbody`,{className:`divide-y divide-line`,children:s.sectors.map((e,t)=>{let o=r===e.sector,s=()=>a(o?null:e.sector);return(0,U.jsxs)(`tr`,{tabIndex:0,"aria-selected":o,onClick:s,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s())},onMouseEnter:()=>n(e.sector),onMouseLeave:()=>n(null),title:o?`Click again to unpin`:`Click to pin · basket: ${e.members.join(`, `)}`,className:m(`cursor-pointer transition-colors focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-accent`,o?`bg-accent-soft font-medium shadow-[inset_3px_0_0_var(--color-accent)]`:`hover:bg-raised`),children:[(0,U.jsxs)(`td`,{className:`truncate py-1.5 pe-4 ps-2`,children:[(0,U.jsx)(`span`,{className:m(`me-2 inline-block rounded-full align-middle`,o?`h-2.5 w-2.5 ring-2 ring-fg/40`:`h-2 w-2`),style:{backgroundColor:R[t%R.length]}}),e.sector]}),(0,U.jsx)(`td`,{className:m(`truncate rounded px-3 py-1.5 text-xs`,nr[e.quadrant].className,d(e.sector)),title:nr[e.quadrant].note,children:nr[e.quadrant].label}),(0,U.jsx)(`td`,{className:m(`tabular py-1.5 pe-2 ps-3 text-end`,i(e.return_4w)),children:u(e.return_4w,1)})]},e.sector)})})]})}),(()=>{let t=s.sectors.find(e=>e.sector===r);return t?(0,U.jsxs)(`div`,{className:`mt-3 rounded-lg border border-accent/40 bg-accent-soft px-3 py-2.5`,children:[(0,U.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2 text-xs`,children:[(0,U.jsxs)(`span`,{className:`font-medium text-fg`,children:[t.sector,` · `,(0,U.jsx)(`span`,{className:nr[t.quadrant].className,children:nr[t.quadrant].label})]}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>a(null),className:`text-muted hover:text-fg`,children:`Unpin`})]}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.members.map(t=>(0,U.jsx)(D,{to:`/analyze?symbol=${encodeURIComponent(t)}&market=${e}`,className:`rounded-md border border-line bg-surface px-2 py-0.5 font-mono text-xs hover:border-accent hover:text-accent-fg`,children:t},t))})]}):null})(),(0,U.jsx)(`p`,{className:`mt-2 text-xs text-faint`,children:`Right = stronger than the index, up = strength rising. Sectors usually cycle clockwise: improving → leading → weakening → lagging. Each sector is a cap-weighted basket of its largest stocks; click a row to pin its trail and see its stocks.`})]})]})]})]})}var ar=[{key:`asia`,label:`Asia-Pacific`},{key:`europe`,label:`Europe`},{key:`americas`,label:`Americas`},{key:`fx`,label:`Currencies`},{key:`yields`,label:`US Treasury yields`},{key:`volatility`,label:`Volatility`}];function or(e,t){return e.change_unit===`points`?r(t,2):u(t,1)}function sr(e){return e.group===`yields`?`${c(e.price,2)}%`:e.group===`fx`?c(e.price,e.price<10?4:2):c(e.price,2)}function cr(){let{data:e,error:t,at:n}=K(e=>it(e),[],W(6e4)),r=Ue(Object.fromEntries((e?.items??[]).map(e=>[e.key,e.price])));return(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,U.jsx)(`h2`,{className:`text-sm font-semibold`,children:`World markets`}),(0,U.jsx)(`p`,{className:`text-xs text-muted`,children:`Major indices by region, currencies, US yields and fear gauges`}),e&&(0,U.jsx)(q,{live:e.live,at:n})]}),(0,U.jsxs)(`div`,{className:`space-y-4 px-5 pb-4`,children:[t&&(0,U.jsx)(`p`,{className:`text-sm text-down`,children:t}),!e&&!t&&(0,U.jsx)(B,{className:`min-h-56`,steps:[`Fetching world indices…`,`Fetching currencies and yields…`,`Reading fear gauges…`]}),e&&(0,U.jsx)(lr,{data:e}),e&&ar.map(t=>{let n=e.items.filter(e=>e.group===t.key);return n.length?(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:t.label}),(0,U.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:n.map(e=>(0,U.jsx)(ur,{item:e,flash:r(e.key)},e.key))})]},t.key):null}),e&&(0,U.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Source: `,e.source,`.`,` `,e.live?.live?`Latest prices refresh every minute and can lag up to 15 min; 1-day changes are against the previous close.`:`Daily closes, delayed; each market's last close is in its own time zone.`,e.failed.length>0&&` Unavailable now: ${e.failed.join(`, `)}.`]})]})]})}function lr({data:e}){let t=e.vix_term,n=e.crypto_mood;return!t&&!n?null:(0,U.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[t&&(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsx)(`div`,{className:`text-xs text-muted`,children:`VIX term structure`}),(0,U.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,U.jsx)(`span`,{className:`text-lg font-semibold ${t.shape===`backwardation`?`text-down`:`text-up`}`,children:t.shape===`backwardation`?`Backwardation`:`Contango`}),(0,U.jsxs)(`span`,{className:`tabular text-xs text-faint`,children:[`VIX `,c(t.vix,2),` / 3-month `,c(t.vix3m,2),` = `,c(t.ratio,2)]})]}),(0,U.jsx)(`p`,{className:`text-[12px] text-muted`,children:t.note})]}),n&&(0,U.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,children:[(0,U.jsxs)(`div`,{className:`flex justify-between text-xs text-muted`,children:[(0,U.jsx)(`span`,{children:`Crypto fear & greed`}),(0,U.jsx)(`span`,{className:`text-faint`,children:`0 fear · 100 greed`})]}),(0,U.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,U.jsx)(`span`,{className:`tabular text-lg font-semibold`,children:n.value}),(0,U.jsx)(`span`,{className:`text-sm`,children:n.label})]}),(0,U.jsx)(`div`,{className:`mt-1 h-1.5 rounded-full bg-line`,children:(0,U.jsx)(`div`,{className:`h-1.5 rounded-full bg-accent`,style:{width:`${n.value}%`}})}),(0,U.jsxs)(`p`,{className:`tabular mt-1 text-[12px] text-faint`,children:[n.week_ago!=null&&`Week ago ${n.week_ago}`,n.month_ago!=null&&` · month ago ${n.month_ago}`]})]})]})}function ur({item:e,flash:t}){let n=e.spark,r=n.length<2||n[n.length-1]>=n[0];return(0,U.jsxs)(`div`,{className:m(`rounded-lg bg-canvas px-3 py-2`,t),title:`${e.note} · as of ${e.as_of}`,children:[(0,U.jsxs)(`div`,{className:`flex justify-between gap-2 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`truncate`,children:e.label}),(0,U.jsx)(`span`,{className:`shrink-0 truncate text-faint`,children:e.group===`fx`||e.group===`yields`?``:e.note})]}),(0,U.jsxs)(`div`,{className:`flex items-end justify-between gap-2`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsx)(`div`,{className:`tabular text-lg font-semibold`,children:sr(e)}),(0,U.jsxs)(`div`,{className:`tabular whitespace-nowrap text-[11px] text-faint`,children:[`1d `,(0,U.jsx)(`span`,{className:i(e.change_1d),children:or(e,e.change_1d)}),` · 1y`,` `,(0,U.jsx)(`span`,{className:i(e.change_1y),children:or(e,e.change_1y)})]})]}),(0,U.jsx)(mt,{values:n,up:r})]})]})}var Y=[`india`,`all`],dr=[`stocks`,`markets`,`economy`],fr=[{id:`hot_trade`,group:`stocks`,section:`trader`,icon:`radar`,except:[`all`],render:e=>(0,U.jsx)(Ut,{market:e,area:`trader`})},{id:`hot_invest`,group:`stocks`,section:`investor`,icon:`star`,except:[`all`],render:e=>(0,U.jsx)(Ut,{market:e,area:`investor`})},{id:`pulse`,group:`stocks`,icon:`analyze`,except:[`all`],render:(e,t)=>(0,U.jsx)(mn,{market:e,onCategory:t})},{id:`rotation`,group:`stocks`,section:`investor`,icon:`refresh`,markets:[`india`,`us`,`china_a`,`hong_kong`,`crypto`],render:e=>(0,U.jsx)(ir,{market:e})},{id:`funds`,group:`stocks`,section:`investor`,icon:`portfolio`,markets:[...Y,`us`,`hong_kong`,`china_a`],render:e=>Y.includes(e)?(0,U.jsx)(Rt,{}):(0,U.jsx)(Rt,{market:e})},{id:`deals`,group:`stocks`,section:`trader`,icon:`portfolio`,markets:[`india`,`us`,`china_a`,`hong_kong`,`crypto`],render:e=>e===`india`?(0,U.jsx)(Nt,{}):(0,U.jsx)(J,{market:e})},{id:`screens`,group:`stocks`,section:`investor`,icon:`filter`,markets:[`india`,`us`,`hong_kong`,`china_a`,`crypto`],render:e=>(0,U.jsx)(tr,{market:e})},{id:`rates`,group:`economy`,section:`investor`,icon:`grid`,markets:[...Y,`us`,`hong_kong`,`china_a`,`crypto`],render:e=>Y.includes(e)?(0,U.jsx)(Qt,{}):(0,U.jsx)(kn,{market:e})},{id:`mood`,group:`markets`,icon:`radar`,markets:[`india`,`us`,`hong_kong`,`china_a`,`crypto`],render:e=>(0,U.jsx)(dn,{market:e})},{id:`flows`,group:`markets`,icon:`compare`,markets:Y,render:()=>(0,U.jsx)(Yt,{})},{id:`world`,group:`markets`,icon:`globe`,render:()=>(0,U.jsx)(cr,{})},{id:`valuation`,group:`markets`,section:`investor`,icon:`sort`,markets:[...Y,`us`],render:e=>(0,U.jsx)(vn,{market:e})},{id:`macro`,group:`economy`,section:`investor`,icon:`globe`,render:()=>(0,U.jsx)(sn,{})},{id:`countries`,group:`economy`,section:`investor`,icon:`globe`,render:()=>(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Dt,{}),(0,U.jsx)(pt,{})]})},{id:`commodities`,group:`markets`,icon:`candles`,render:e=>(0,U.jsx)(_t,{market:e})},{id:`oil`,group:`markets`,section:`investor`,icon:`compare`,markets:[...Y,`us`,`hong_kong`,`china_a`],render:e=>(0,U.jsx)(jt,{market:Y.includes(e)?`india`:e})}];function pr(e,t){return fr.filter(n=>(!n.markets||n.markets.includes(e))&&!n.except?.includes(e)&&k(t,n.section))}function mr({market:e,view:t,onView:n,onCategory:r,list:i}){let{t:a}=te(`markets`),o=pr(e,re()),s=o.some(e=>e.id===t)?t:`list`,[c,l]=(0,V.useState)([]);(0,V.useEffect)(()=>{s!==`list`&&!c.includes(s)&&l(e=>[...e,s])},[s,c]),(0,V.useEffect)(()=>l([]),[e]);function u(e){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(ue,{rail:e,selected:s===`list`,icon:`grid`,label:a(`insights.list`),onClick:()=>n(`list`)}),dr.map(t=>{let r=o.filter(e=>e.group===t);return r.length?(0,U.jsx)(pe,{rail:e,label:a(`insights.groups.${t}`),children:r.map(t=>(0,U.jsx)(ue,{rail:e,selected:t.id===s,icon:t.icon,label:a(`insights.tabs.${t.id}.label`),onClick:()=>n(t.id)},t.id))},t):null})]})}return(0,U.jsxs)(de,{label:a(`insights.title`),nav:u,children:[(0,U.jsx)(`div`,{hidden:s!==`list`,children:i}),o.filter(e=>c.includes(e.id)||e.id===s).map(t=>(0,U.jsx)(`div`,{hidden:t.id!==s,children:(0,U.jsx)(b,{className:`overflow-hidden`,children:(0,U.jsx)(He.Provider,{value:t.id===s,children:t.render(e,r)})})},`${e}:${t.id}`))]})}var hr=[`cat`,`cap`,`sh`,`sip`,`pmin`,`pmax`,`chg`,`w52`,`vol`,`cmin`,`cmax`,`mcmin`,`mcmax`,`vmax`,`mk`],gr=[{max:50},{min:50,max:100},{min:100,max:500},{min:500,max:1e3},{min:1e3,max:5e3},{min:5e3}],_r=[{value:`mega`,inr:`≥ $200B`,usd:`≥ $200B`},{value:`large`,inr:`≥ ₹20,000 Cr`,usd:`$10B – 200B`},{value:`mid`,inr:`₹5,000 – 20,000 Cr`,usd:`$2B – 10B`},{value:`small`,inr:`₹500 – 5,000 Cr`,usd:`$300M – 2B`},{value:`micro`,inr:`< ₹500 Cr`,usd:`< $300M`}],vr={gainers:{min:1e-4},losers:{max:-1e-4},up5:{min:5},down5:{max:-5}},yr=[`high`,`low`],br=[`halal`,`doubtful`,`haram`,`unknown`],xr=[`consistent`,`no_edge`,`negligible`,`short`],Sr={1e4:`≥ 10K`,1e5:`≥ 100K`,1e6:`≥ 1M`};function Cr(e,t,n){let r=e=>`${n}${e.toLocaleString(`en-US`)}`;return t.min==null?e(`filters.price.under`,{n:r(t.max)}):t.max==null?e(`filters.price.above`,{n:r(t.min)}):`${r(t.min)} – ${r(t.max)}`}function X(e){return e?e.split(`,`).filter(Boolean):[]}function Z(e){if(e==null||e===``)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function wr(e){let t=vr[e.get(`chg`)],n=e.get(`w52`);return{category:X(e.get(`cat`)).join(`,`)||void 0,cap:X(e.get(`cap`)).join(`,`)||void 0,shariah:X(e.get(`sh`)).join(`,`)||void 0,sip_edge:X(e.get(`sip`)).join(`,`)||void 0,price_min:Z(e.get(`pmin`)),price_max:Z(e.get(`pmax`)),change_min:Z(e.get(`cmin`))??t?.min,change_max:Z(e.get(`cmax`))??t?.max,near_high:n===`high`?5:void 0,near_low:n===`low`?5:void 0,min_volume:Z(e.get(`vol`)),max_volume:Z(e.get(`vmax`)),min_cap:Z(e.get(`mcmin`)),max_cap:Z(e.get(`mcmax`)),markets:X(e.get(`mk`)).join(`,`)||void 0}}function Tr(e){let t=X(e.get(`cat`)).length+X(e.get(`cap`)).length+X(e.get(`sh`)).length+X(e.get(`sip`)).length;(e.get(`pmin`)||e.get(`pmax`))&&(t+=1);for(let n of[`chg`,`w52`,`vol`])e.get(n)&&(t+=1);return(e.get(`cmin`)||e.get(`cmax`))&&(t+=1),(e.get(`mcmin`)||e.get(`mcmax`))&&(t+=1),e.get(`vmax`)&&(t+=1),t+=X(e.get(`mk`)).length,t}function Q({active:e,onClick:t,children:n,title:r}){return(0,U.jsx)(`button`,{type:`button`,onClick:t,title:r,"aria-pressed":e,className:m(`rounded-full border px-3 py-1 text-xs font-medium transition-colors`,e?`border-accent bg-accent-soft text-fg`:`border-line text-muted hover:border-line-strong hover:text-fg`),children:n})}function $({label:e,hint:t,children:n}){return(0,U.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[120px_minmax(0,1fr)] sm:gap-4`,children:[(0,U.jsxs)(`div`,{className:`pt-1`,children:[(0,U.jsx)(`div`,{className:`text-xs font-medium text-muted`,children:e}),t&&(0,U.jsx)(`div`,{className:`text-xs text-faint`,children:t})]}),(0,U.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:n})]})}function Er({params:e,update:t,categories:n,isFunds:r,currency:i,showCap:a=!0,shariahCounts:o,showShariah:s=!0,showSip:c=!1}){let{t:l}=te(`markets`),u=X(e.get(`cat`)),d=X(e.get(`cap`)),f=X(e.get(`sh`)),p=X(e.get(`sip`)),m=e.get(`pmin`)??``,h=e.get(`pmax`)??``,g=i===`INR`?`₹`:i===`USD`?`$`:``,[_,y]=(0,V.useState)(m),[b,S]=(0,V.useState)(h);(0,V.useEffect)(()=>y(m),[m]),(0,V.useEffect)(()=>S(h),[h]);function C(e,n,r){let i=n.includes(r)?n.filter(e=>e!==r):[...n,r];t({[e]:i.join(`,`)||null})}function w(){let e=e=>e.trim()===``||!Number.isFinite(Number(e))?null:String(Number(e));t({pmin:e(_),pmax:e(b)})}let T=[...n];for(let e of u)T.some(t=>t.value===e)||T.push({value:e,count:0});return(0,U.jsxs)(`div`,{className:`space-y-4 border-t border-line bg-canvas/40 px-5 py-4`,children:[(0,U.jsxs)($,{label:l(r?`filters.fundType`:`filters.category`),hint:l(`filters.pickAny`),children:[T.length===0&&(0,U.jsx)(`span`,{className:`text-xs text-faint`,children:l(`filters.noCategories`)}),T.map(e=>(0,U.jsxs)(Q,{active:u.includes(e.value),onClick:()=>C(`cat`,u,e.value),children:[e.value,` `,(0,U.jsx)(`span`,{className:`text-faint`,children:e.count.toLocaleString()})]},e.value))]}),s&&(0,U.jsx)($,{label:l(`filters.ethical`),hint:l(`filters.ethicalHint`),children:br.map(e=>(0,U.jsxs)(Q,{active:f.includes(e),onClick:()=>C(`sh`,f,e),title:l(`filters.shariah.${e}Hint`),children:[l(`filters.shariah.${e}`),` `,(0,U.jsx)(`span`,{className:`text-faint`,children:(o?.[e]??0).toLocaleString()})]},e))}),c&&(0,U.jsx)($,{label:l(`filters.sip`),hint:l(`filters.sipHint`),children:xr.map(e=>(0,U.jsx)(Q,{active:p.includes(e),onClick:()=>C(`sip`,p,e),title:l(`filters.sipEdge.${e}Hint`),children:l(`filters.sipEdge.${e}`)},e))}),(0,U.jsxs)($,{label:l(r?`filters.nav`:`filters.price.label`),hint:g?l(`filters.price.in`,{symbol:g}):l(`filters.price.eachCurrency`),children:[gr.map(e=>{let n=m===(e.min==null?``:String(e.min))&&h===(e.max==null?``:String(e.max));return(0,U.jsx)(Q,{active:n,onClick:()=>t(n?{pmin:null,pmax:null}:{pmin:e.min==null?null:String(e.min),pmax:e.max==null?null:String(e.max)}),children:Cr(l,e,g)},`${e.min}-${e.max}`)}),(0,U.jsxs)(`span`,{className:`ms-1 flex items-center gap-1.5`,children:[(0,U.jsx)(v,{value:_,onChange:e=>y(e.target.value),onBlur:w,onKeyDown:e=>e.key===`Enter`&&w(),placeholder:l(`filters.min`),inputMode:`decimal`,className:`h-7 w-20 text-xs`,"aria-label":l(`filters.minPrice`)}),(0,U.jsx)(`span`,{className:`text-faint`,children:`–`}),(0,U.jsx)(v,{value:b,onChange:e=>S(e.target.value),onBlur:w,onKeyDown:e=>e.key===`Enter`&&w(),placeholder:l(`filters.max`),inputMode:`decimal`,className:`h-7 w-20 text-xs`,"aria-label":l(`filters.maxPrice`)})]})]}),!r&&(0,U.jsxs)(U.Fragment,{children:[a&&(0,U.jsx)($,{label:l(`filters.marketCap`),children:_r.filter(e=>e.value!==`mega`||i!==`INR`).map(e=>(0,U.jsxs)(Q,{active:d.includes(e.value),onClick:()=>C(`cap`,d,e.value),title:i===`INR`?e.inr:i===`USD`?e.usd:`${e.inr} · ${e.usd}`,children:[l(`filters.cap.${e.value}`),(0,U.jsx)(`span`,{className:`ms-1 text-faint`,children:i===`INR`?e.inr:e.usd})]},e.value))}),(0,U.jsx)($,{label:l(`filters.today`),children:Object.keys(vr).map(n=>(0,U.jsx)(Q,{active:e.get(`chg`)===n,onClick:()=>t({chg:e.get(`chg`)===n?null:n}),children:l(`filters.change.${n}`)},n))}),(0,U.jsx)($,{label:l(`filters.w52.label`),children:yr.map(n=>(0,U.jsx)(Q,{active:e.get(`w52`)===n,onClick:()=>t({w52:e.get(`w52`)===n?null:n}),title:l(`filters.w52.${n}Hint`),children:l(`filters.w52.${n}`)},n))}),(0,U.jsx)($,{label:l(`filters.volume`),hint:l(`filters.volumeHint`),children:Object.entries(Sr).map(([n,r])=>(0,U.jsx)(Q,{active:e.get(`vol`)===n,onClick:()=>t({vol:e.get(`vol`)===n?null:n}),children:r},n))})]}),Tr(e)>0&&(0,U.jsx)(`div`,{className:`flex justify-end`,children:(0,U.jsxs)(`button`,{type:`button`,onClick:()=>t(Object.fromEntries(hr.map(e=>[e,null]))),className:`inline-flex items-center gap-1 text-xs text-muted hover:text-fg`,children:[(0,U.jsx)(x,{name:`x`,className:`h-3 w-3`}),` `,l(`filters.clearAll`)]})})]})}function Dr(e){let t=e.trim().toLowerCase().replace(/[,\s₹$¥]/g,``).replace(/hk\$?/,``);if(!t)return;let n=t.match(/^(-?\d*\.?\d+(?:e-?\d+)?)(k|m|b|bn|t|cr|l|lakh|crore)?$/);if(!n)return;let r=Number(n[1])*(n[2]?{k:1e3,m:1e6,b:1e9,bn:1e9,t:0xe8d4a51000,cr:1e7,crore:1e7,l:1e5,lakh:1e5}[n[2]]:1);return Number.isFinite(r)?r:void 0}function Or({active:e,align:t=`left`,label:n,sortable:r,sorted:i,onSort:a,children:o}){let[s,c]=(0,V.useState)(!1),l=(0,V.useRef)(null);return(0,V.useEffect)(()=>{if(!s)return;let e=e=>!l.current?.contains(e.target)&&c(!1),t=e=>e.key===`Escape`&&c(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[s]),(0,U.jsxs)(`span`,{ref:l,className:`relative inline-flex`,onClick:e=>e.stopPropagation(),children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-label":`Filter ${n}`,"aria-expanded":s,title:e?`${n}: filtered`:`Filter ${n}`,className:m(`rounded p-0.5 transition-colors`,e?`bg-accent-soft text-accent-fg`:`text-faint opacity-60 hover:bg-raised hover:text-fg hover:opacity-100`,s&&`bg-raised text-fg opacity-100`),children:(0,U.jsx)(x,{name:`filter`,className:`h-3 w-3`})}),s&&(0,U.jsxs)(`div`,{className:m(`absolute top-full z-30 mt-1 w-64 rounded-lg border border-line-strong bg-surface p-3 text-start text-sm font-normal normal-case text-fg shadow-card`,t===`right`?`end-0`:`start-0`),children:[r&&a&&(0,U.jsx)(`div`,{className:`mb-2 space-y-0.5 border-b border-line pb-2`,children:[`asc`,`desc`].map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>{a(e),c(!1)},className:m(`flex w-full items-center gap-2 rounded px-2 py-1 text-xs hover:bg-raised`,i===e?`text-accent-fg`:`text-fg`),children:[(0,U.jsx)(x,{name:`sort`,className:`h-3.5 w-3.5`}),e===`asc`?`Sort ascending (A → Z, low → high)`:`Sort descending (Z → A, high → low)`]},e))}),o(()=>c(!1))]})]})}function kr({onClear:e,onApply:t,canApply:n=!0}){return(0,U.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,U.jsx)(w,{size:`sm`,variant:`ghost`,onClick:e,children:`Clear`}),(0,U.jsx)(w,{size:`sm`,onClick:t,disabled:!n,children:`OK`})]})}function Ar({options:e,selected:t,onApply:n,close:r}){let[i,a]=(0,V.useState)(``),[o,s]=(0,V.useState)(()=>new Set(t.length?t:e.map(e=>e.value))),c=(0,V.useMemo)(()=>e.filter(e=>(e.label??e.value).toLowerCase().includes(i.trim().toLowerCase())),[e,i]),l=c.length>0&&c.every(e=>o.has(e.value));function u(){let e=new Set(o);for(let t of c)l?e.delete(t.value):e.add(t.value);s(e)}function d(){n(e.every(e=>o.has(e.value))?[]:e.filter(e=>o.has(e.value)).map(e=>e.value)),r()}return(0,U.jsxs)(`div`,{children:[e.length>8&&(0,U.jsx)(v,{value:i,onChange:e=>a(e.target.value),placeholder:`Search`,className:`mb-2 h-8 text-xs`,autoFocus:!0}),(0,U.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 border-b border-line px-1 py-1 text-xs font-medium`,children:[(0,U.jsx)(`input`,{type:`checkbox`,checked:l,onChange:u,className:`accent-[var(--color-accent)]`}),i?`Select all results`:`Select all`]}),(0,U.jsxs)(`div`,{className:`max-h-56 overflow-y-auto py-1`,children:[c.map(e=>(0,U.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 text-xs hover:bg-raised`,children:[(0,U.jsx)(`input`,{type:`checkbox`,checked:o.has(e.value),onChange:()=>{let t=new Set(o);t.has(e.value)?t.delete(e.value):t.add(e.value),s(t)},className:`accent-[var(--color-accent)]`}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label??e.value}),e.count!=null&&(0,U.jsx)(`span`,{className:`tabular text-faint`,children:e.count.toLocaleString()})]},e.value)),!c.length&&(0,U.jsx)(`p`,{className:`px-1 py-2 text-xs text-faint`,children:`No matches`})]}),(0,U.jsx)(kr,{onClear:()=>{n([]),r()},onApply:d,canApply:o.size>0})]})}function jr({min:e,max:t,onApply:n,close:r,unit:i,hint:a,presets:o=[],extra:s}){let[c,l]=(0,V.useState)(e??``),[u,d]=(0,V.useState)(t??``),f=Dr(c),p=Dr(u),h=c.trim()!==``&&f===void 0||u.trim()!==``&&p===void 0;return(0,U.jsxs)(`div`,{children:[s,o.length>0&&(0,U.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1`,children:o.map(e=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>{n(e.min,e.max),r()},className:`rounded-full border border-line px-2 py-0.5 text-xs text-muted hover:border-line-strong hover:text-fg`,children:e.label},e.label))}),(0,U.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,U.jsxs)(`label`,{className:`text-xs text-muted`,children:[`Min`,i?` (${i})`:``,(0,U.jsx)(v,{value:c,onChange:e=>l(e.target.value),placeholder:`any`,className:`mt-1 h-8 text-xs`,autoFocus:!0})]}),(0,U.jsxs)(`label`,{className:`text-xs text-muted`,children:[`Max`,i?` (${i})`:``,(0,U.jsx)(v,{value:u,onChange:e=>d(e.target.value),placeholder:`any`,className:`mt-1 h-8 text-xs`})]})]}),(0,U.jsx)(`p`,{className:m(`mt-1.5 text-[11px]`,h?`text-down`:`text-faint`),children:h?`Use numbers like 500, 2.5k, 10M, 3B or 50cr`:a??`Shorthand works: 500k, 10M, 3B, 50cr, 2L`}),(0,U.jsx)(kr,{onClear:()=>{n(void 0,void 0),r()},onApply:()=>{n(f,p),r()},canApply:!h})]})}function Mr({options:e,value:t,onApply:n,close:r}){return(0,U.jsx)(`div`,{className:`space-y-0.5`,children:e.map(e=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>{n(e.value),r()},title:e.hint,className:m(`flex w-full items-center gap-2 rounded px-2 py-1 text-xs hover:bg-raised`,t===e.value&&`text-accent-fg`),children:[(0,U.jsx)(`span`,{className:m(`h-2 w-2 rounded-full border`,t===e.value?`border-accent bg-accent`:`border-line-strong`)}),e.label]},e.value))})}function Nr({value:e,onApply:t,close:n}){let[r,i]=(0,V.useState)(e);return(0,U.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t(r.trim()),n()},children:[(0,U.jsxs)(`label`,{className:`text-xs text-muted`,children:[`Name or symbol contains`,(0,U.jsx)(v,{value:r,onChange:e=>i(e.target.value),className:`mt-1 h-8 text-xs`,autoFocus:!0})]}),(0,U.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,U.jsx)(w,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>{t(``),n()},children:`Clear`}),(0,U.jsx)(w,{size:`sm`,type:`submit`,children:`OK`})]})]})}var Pr=[`india`,`us`,`china_a`,`hong_kong`,`crypto`,`all`],Fr={india:[`all`,`stock`,`etf`,`mf`],us:[`all`,`stock`,`etf`],china_a:[`all`,`stock`,`etf`],hong_kong:[`all`,`stock`,`etf`],crypto:[`crypto`],all:[`all`,`stock`,`etf`,`mf`,`crypto`]},Ir={halal:`bg-up-soft text-up`,doubtful:`bg-warn-soft text-warn`,haram:`bg-down-soft text-down`,unknown:`bg-raised text-muted`},Lr=50,Rr=Object.fromEntries(hr.map(e=>[e,null]));function zr(e,t){return e===`crypto`||t===`crypto`?`volume`:t===`mf`||t===`etf`?`name`:`market_cap`}var Br=5e3,Vr=`mm_halal_only`;function Hr(){try{return localStorage.getItem(Vr)===`1`}catch{return!1}}function Ur(e){try{e?localStorage.setItem(Vr,`1`):localStorage.removeItem(Vr)}catch{}}var Wr=[`india`,`us`,`hong_kong`];function Gr(){let{t:e}=te(`markets`),[t,r]=O(),c=ne(),l=t.get(`market`)??`india`,h=Fr[l]??[`all`],_=h.find(e=>e===t.get(`type`))??h[0],S=t.get(`q`)??``,D=t.get(`sector`)??``,re=t.get(`plan`)??``,k=t.get(`option`)??``,A=t.get(`sort`)??zr(l,_),j=t.get(`order`)??(A===`name`||A===`symbol`?`asc`:`desc`),M=Math.max(0,Number(t.get(`page`)??0)||0),N=t.get(`view`)??`list`,ie=hr.map(e=>t.get(e)??``).join(`|`),P=Tr(t),F=!!t.get(`sh`),I=(t.get(`sh`)??``)===`halal`,ae=l!==`crypto`;function L(e){Ur(e),z({sh:e?`halal`:null})}(0,V.useEffect)(()=>{!t.get(`sh`)&&ae&&Hr()&&z({sh:`halal`})},[]);let[oe,se]=(0,V.useState)(S);function ce(){se(``),z({q:null,sector:null,plan:null,option:null,...Rr})}let[R,le]=(0,V.useState)(null),[ue,de]=(0,V.useState)(!0),[fe,pe]=(0,V.useState)(null),[me,_e]=(0,V.useState)(!1),[ve,ye]=(0,V.useState)(0),[be,xe]=(0,V.useState)(()=>Tr(t)>0||!!t.get(`sector`)),Ce=(0,V.useRef)(t);Ce.current=t;function z(e,t=!1){let n=new URLSearchParams(Ce.current);for(let[t,r]of Object.entries(e))r==null||r===``?n.delete(t):n.set(t,r);t||n.delete(`page`),Ce.current=n,r(n,{replace:!0})}(0,V.useEffect)(()=>{if(oe===S)return;let e=setTimeout(()=>z({q:oe.trim()||null}),250);return()=>clearTimeout(e)},[oe]),(0,V.useEffect)(()=>{let e=new AbortController;return de(!0),pe(null),ge({market:l,type:_,q:S,sector:D,plan:re,option:k,sort:A,order:j,offset:M*Lr,limit:Lr,...wr(new URLSearchParams(t))},e.signal).then(le).catch(t=>{e.signal.aborted||pe(s(t))}).finally(()=>{e.signal.aborted||de(!1)}),()=>e.abort()},[l,_,S,D,re,k,A,j,M,ve,ie]);async function B(){_e(!0);try{let t=(await we(l)).filter(e=>e.error);t.length?f.error(`${t.map(e=>e.source).join(`, `)}: ${t[0].error}`):f.success(e(`refreshed`)),ye(e=>e+1)}catch(e){f.error(s(e))}finally{_e(!1)}}function Me(e){c(Se(e))}function Ne(e){z(A===e?{sort:e,order:j===`asc`?`desc`:`asc`}:{sort:e,order:[`name`,`symbol`,`sector`,`category`].includes(e)?`asc`:`desc`})}let H=_===`mf`,Fe=je(R?.rows??[],!H),Ie=l===`all`,Le=H||_===`etf`&&Wr.includes(l),Re=[{key:`name`,label:e(`col.name`),align:`left`,sortable:!0},...Ie?[{key:`market`,label:e(`col.market`),align:`left`}]:[],{key:`category`,label:e(`col.category`),align:`left`,sortable:!0,className:`hidden md:table-cell`},{key:`price`,label:e(H?`col.nav`:`col.price`),sortable:!0},...Le?[{key:`sip_day`,label:e(`col.sipDay`),className:`hidden sm:table-cell`}]:[],...H?[{key:`nav_date`,label:e(`col.navDate`),className:`hidden sm:table-cell`}]:[{key:`change_percent`,label:e(`col.change`),sortable:!0},{key:`market_cap`,label:e(`col.marketCap`),sortable:!0,className:`hidden sm:table-cell`},{key:`volume`,label:e(`col.volume`),sortable:!0,className:`hidden lg:table-cell`},{key:`range`,label:e(`col.range`),className:`hidden xl:table-cell`}]],ze=Be(l===`all`?`china_a`:l,Fe.rows.filter(e=>e.market===`china_a`)),He=Fe.rows.some(e=>Pe(e.name));function W(n){let r=e=>(t.get(e)??``).split(`,`).filter(Boolean),i=(e,t)=>(n,r)=>z({[e]:n==null?null:String(n),[t]:r==null?null:String(r)}),a=(e,t)=>(0,U.jsx)(Or,{label:n.label,active:e,align:n.align===`left`?`left`:`right`,sortable:n.sortable,sorted:A===n.key?j:null,onSort:e=>z({sort:n.key,order:e}),children:t}),o=l===`india`?`₹`:l===`us`||l===`crypto`?`$`:l===`hong_kong`?`HK$`:l===`china_a`?`¥`:void 0;switch(n.key){case`name`:return a(!!S,e=>(0,U.jsx)(Nr,{value:S,close:e,onApply:e=>{se(e),z({q:e||null})}}));case`market`:return a(r(`mk`).length>0,e=>(0,U.jsx)(Ar,{close:e,selected:r(`mk`),options:Object.entries(R?.facets.markets??{}).map(([e,t])=>({value:e,label:K(e),count:t})),onApply:e=>z({mk:e.join(`,`)||null})}));case`category`:return a(r(`cat`).length>0,e=>(0,U.jsx)(Ar,{close:e,selected:r(`cat`),options:(R?.facets.categories??[]).map(e=>({value:e.value,count:e.count})),onApply:e=>z({cat:e.join(`,`)||null})}));case`price`:return a(!!(t.get(`pmin`)||t.get(`pmax`)),e=>(0,U.jsx)(jr,{close:e,unit:o,min:t.get(`pmin`),max:t.get(`pmax`),onApply:i(`pmin`,`pmax`)}));case`change_percent`:return a(!!(t.get(`cmin`)||t.get(`cmax`)||t.get(`chg`)),n=>(0,U.jsx)(jr,{close:n,unit:`%`,hint:e(`filter.changeHint`),min:t.get(`cmin`),max:t.get(`cmax`),presets:[{label:e(`filters.change.gainers`),min:1e-4},{label:e(`filters.change.losers`),max:-1e-4},{label:e(`filters.change.up5`),min:5},{label:e(`filters.change.down5`),max:-5}],onApply:(e,t)=>z({chg:null,cmin:e==null?null:String(e),cmax:t==null?null:String(t)})}));case`market_cap`:{let n=r(`cap`);return a(!!(t.get(`mcmin`)||t.get(`mcmax`)||n.length),r=>(0,U.jsx)(jr,{close:r,unit:o,hint:e(l===`india`?`filter.capHintIndia`:`filter.capHint`),min:t.get(`mcmin`),max:t.get(`mcmax`),onApply:i(`mcmin`,`mcmax`),extra:(0,U.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-1`,children:_r.filter(e=>e.value!==`mega`||l!==`india`).map(t=>(0,U.jsx)(`button`,{type:`button`,title:l===`india`?t.inr:t.usd,onClick:()=>{z({cap:(n.includes(t.value)?n.filter(e=>e!==t.value):[...n,t.value]).join(`,`)||null})},className:m(`rounded-full border px-2 py-0.5 text-xs`,n.includes(t.value)?`border-accent bg-accent-soft text-fg`:`border-line text-muted hover:text-fg`),children:e(`filters.cap.${t.value}`)},t.value))})}))}case`volume`:return a(!!(t.get(`vol`)||t.get(`vmax`)),n=>(0,U.jsx)(jr,{close:n,hint:e(`filter.volumeHint`),min:t.get(`vol`),max:t.get(`vmax`),presets:[{label:`≥ 100K`,min:1e5},{label:`≥ 1M`,min:1e6},{label:`≥ 10M`,min:1e7}],onApply:i(`vol`,`vmax`)}));case`range`:return a(!!t.get(`w52`),n=>(0,U.jsx)(Mr,{close:n,value:t.get(`w52`)??``,options:[{value:``,label:e(`filter.any`)},...yr.map(t=>({value:t,label:e(`filters.w52.${t}`),hint:e(`filters.w52.${t}Hint`)}))],onApply:e=>z({w52:e||null})}));default:return null}}let G=e=>z({market:e,type:null,sector:null,sort:null,order:null,plan:null,option:null,...Rr}),K=t=>Pr.includes(t)?e(`marketTabs.${t}.label`):Te(Ee,t),Ue=Pr.map(t=>({value:t,label:e(`marketTabs.${t}.label`),hint:e(`marketTabs.${t}.hint`)})),We=h.map(t=>{let n=t===`all`?void 0:R?.facets.types[t],r=e(`types.${t}`);return{value:t,label:n==null?r:`${r} · ${n.toLocaleString()}`}}),q=[{value:``,label:e(H?`allSubCategories`:`allIndustries`)},...(R?.facets.sectors??[]).map(e=>({value:e.value,label:`${e.value} (${e.count})`}))];D&&!q.some(e=>e.value===D)&&q.push({value:D,label:D});let Ge=R?.sources??[],Ke=Ge.filter(e=>e.error&&!e.count),qe=Ge.filter(e=>e.error&&e.count);async function Je(){let n={market:l,type:_,q:S,sector:D,plan:re,option:k,sort:A,order:j,...wr(new URLSearchParams(t))},r=[];for(let e=0;e<Math.min(J,Br);e+=500){let t=await ge({...n,offset:e,limit:500});if(r.push(...t.rows),t.rows.length<500)break}let i=_===`mf`;return[{title:i?`Mutual funds`:`Listings`,columns:[{key:`symbol`,label:i?`Scheme code`:`Symbol`},{key:`name`,label:`Name`},{key:`market`,label:`Market`},{key:`type`,label:`Type`},{key:i?`amc`:`sector`,label:i?`AMC`:`Sector`},{key:`category`,label:`Category`},{key:`price`,label:i?`NAV`:`Price`,kind:`number`},{key:`change_percent`,label:`Change %`,kind:`pct`},{key:`volume`,label:`Volume`,kind:`number`,digits:0},{key:`market_cap`,label:`Market cap`,kind:`money`},{key:`high_52w`,label:`52w high`,kind:`number`},{key:`low_52w`,label:`52w low`,kind:`number`},{key:`currency`,label:`Currency`},{key:`shariah`,label:`Ethical`}],rows:r,note:J>Br?e(`exportNote`,{first:Br.toLocaleString(),total:J.toLocaleString()}):void 0}]}let Ye=Ge.map(e=>e.fetched_at).filter(Boolean).sort()[0],J=R?.total??0,Xe=Math.max(1,Math.ceil(J/Lr));return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(C,{title:e(`title`),description:R?(0,U.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,U.jsxs)(`span`,{children:[e(`listings`,{count:J,n:J.toLocaleString()}),Ye?` · ${e(`dataUpdated`,{ago:o(Ye)})}`:``]}),!H&&R.rows.length>0&&(0,U.jsx)(ke,{status:Fe.status})]}):e(`intro`),actions:(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Oe,{title:`MarketMyna ${l} listings`,subtitle:S?e(`searchSubtitle`,{q:S}):void 0,tables:Je,disabled:!J}),(0,U.jsx)(w,{variant:`secondary`,size:`sm`,icon:`refresh`,loading:me,onClick:B,children:e(`refresh`)})]})}),(0,U.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,U.jsx)(y,{options:Ue,value:l,onChange:G,showHint:!0}),(He||l===`china_a`)&&(0,U.jsx)(Ve,{loading:ze.loading,className:`mt-1`})]}),ae&&(0,U.jsx)(`div`,{className:m(`rounded-lg border px-3 py-2 transition-colors`,I?`border-up/30 bg-up-soft`:`border-line bg-surface`),title:e(I?`ethical.onDescription`:`ethical.offDescription`),children:(0,U.jsx)(p,{checked:I,onChange:L,label:(0,U.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(x,{name:`check`,className:`h-4 w-4 text-up`}),e(`ethical.only`),I&&R&&(0,U.jsx)(`span`,{className:`rounded-md bg-up/15 px-1.5 text-xs font-semibold text-up`,children:e(`ethical.count`,{count:J,n:J.toLocaleString()})})]})})})]}),(0,U.jsx)(mr,{market:l,view:N,onView:e=>z({view:e===`list`?null:e},!0),onCategory:e=>z({cat:e,type:l===`crypto`?null:`stock`,view:null}),list:(0,U.jsxs)(b,{id:`listings`,className:`scroll-mt-6`,children:[(0,U.jsx)(`div`,{className:`space-y-4 p-5`,children:(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[h.length>1&&(0,U.jsx)(y,{options:We,value:_,size:`sm`,onChange:e=>z({type:e===`all`?null:e,sector:null,sort:null,order:null,plan:null,option:null,...Rr})}),(0,U.jsxs)(`div`,{className:`relative min-w-56 flex-1`,children:[(0,U.jsx)(x,{name:`search`,className:`pointer-events-none absolute top-1/2 start-3 h-4 w-4 -translate-y-1/2 text-faint`}),(0,U.jsx)(v,{value:oe,onChange:e=>se(e.target.value),placeholder:e(H?`searchFunds`:`searchStocks`),className:`ps-9`,spellCheck:!1})]}),(0,U.jsx)(g,{options:q,value:D,onChange:e=>z({sector:e.target.value||null}),className:`w-auto max-w-64`}),(0,U.jsxs)(w,{variant:P?`primary`:`secondary`,icon:`filter`,onClick:()=>xe(e=>!e),"aria-expanded":be,children:[e(`filtersButton`),P?` · ${P}`:``]}),(P>0||S||D||re||k)&&(0,U.jsx)(w,{variant:`ghost`,icon:`x`,onClick:ce,title:e(`clearTitle`),children:e(`clear`)}),H&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(g,{options:[{value:``,label:e(`plan.both`)},{value:`Direct`,label:e(`plan.direct`)},{value:`Regular`,label:e(`plan.regular`)}],value:re,onChange:e=>z({plan:e.target.value||null}),className:`w-auto`}),(0,U.jsx)(g,{options:[{value:``,label:e(`option.any`)},{value:`Growth`,label:e(`option.growth`)},{value:`IDCW`,label:`IDCW`}],value:k,onChange:e=>z({option:e.target.value||null}),className:`w-auto`})]})]})}),be&&(0,U.jsx)(Er,{params:t,update:z,categories:R?.facets.categories??[],isFunds:H,showCap:l!==`crypto`,showShariah:l!==`crypto`,shariahCounts:R?.facets.shariah,showSip:_===`mf`||_===`etf`&&Wr.includes(l),currency:l===`india`?`INR`:l===`us`||l===`crypto`?`USD`:null}),Ke.map(t=>(0,U.jsx)(`div`,{className:`px-5 pb-4`,children:(0,U.jsx)(E,{tone:`warn`,title:e(`unavailable`,{market:K(t.market)}),children:t.error})},t.source)),qe.map(t=>(0,U.jsx)(`div`,{className:`px-5 pb-4`,children:(0,U.jsxs)(E,{tone:`accent`,title:e(`partial`,{market:K(t.market)}),children:[t.error,`. `,e(`retrying`)]})},t.source)),fe&&(0,U.jsx)(`div`,{className:`px-5 pb-4`,children:(0,U.jsx)(E,{title:e(`loadError`),children:fe})}),(0,U.jsxs)(`div`,{className:`overflow-x-auto border-t border-line`,children:[(0,U.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,U.jsx)(`thead`,{children:(0,U.jsxs)(`tr`,{className:`border-b border-line text-xs text-muted`,children:[(0,U.jsx)(`th`,{className:`w-8 px-1 py-2.5`,"aria-label":e(`col.watch`)}),(0,U.jsx)(`th`,{className:`w-12 px-3 py-2.5 text-end font-medium`,children:`#`}),Re.map(e=>(0,U.jsx)(`th`,{className:m(`px-3 py-2.5 font-medium whitespace-nowrap`,e.align===`left`?`text-start`:`text-end`,e.className),children:(0,U.jsxs)(`span`,{className:m(`inline-flex items-center gap-1`,e.align!==`left`&&`flex-row-reverse`),children:[e.sortable?(0,U.jsxs)(`button`,{type:`button`,onClick:()=>Ne(e.key),className:m(`inline-flex items-center gap-1 hover:text-fg`,A===e.key&&`text-fg`),children:[e.label,(0,U.jsx)(`span`,{className:`text-[12px]`,children:A===e.key?j===`asc`?`▲`:`▼`:``})]}):e.label,W(e)]})},e.key))]})}),(0,U.jsx)(`tbody`,{className:m(`divide-y divide-line`,ue&&R&&`opacity-60`),children:ue&&!R?Array.from({length:12},(e,t)=>(0,U.jsx)(`tr`,{children:(0,U.jsx)(`td`,{colSpan:Re.length+2,className:`px-3 py-2.5`,children:(0,U.jsx)(ee,{className:`h-5 w-full`})})},t)):Fe.rows.map((t,r)=>(0,U.jsxs)(`tr`,{onClick:()=>Me(t),className:`cursor-pointer hover:bg-raised/50`,children:[(0,U.jsx)(`td`,{className:`px-1 py-2.5 text-center`,children:(0,U.jsx)(he,{item:{symbol:t.symbol,market:t.market,type:t.type,name:t.name}})}),(0,U.jsx)(`td`,{className:`tabular px-3 py-2.5 text-end text-xs text-faint`,children:M*Lr+r+1}),(0,U.jsxs)(`td`,{className:`max-w-md px-3 py-2.5`,children:[(0,U.jsx)(`div`,{className:`truncate font-medium`,title:t.name,children:ze.name(t.symbol,t.name)}),(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`font-mono`,children:t.symbol}),t.exchange&&(0,U.jsxs)(`span`,{className:`text-faint`,children:[`· `,t.exchange]}),t.name_local&&t.name_local!==t.name&&(0,U.jsxs)(`span`,{className:`truncate text-faint`,children:[`· `,t.name_local]}),ze.on&&Pe(t.name)&&ze.name(t.symbol,t.name)!==t.name&&(0,U.jsxs)(`span`,{className:`truncate text-faint`,children:[`· `,t.name]}),_===`all`&&t.type!==`stock`&&(0,U.jsx)(`span`,{className:`rounded bg-raised px-1 text-[12px] uppercase`,children:t.type===`mf`?e(`fund`):t.type}),t.shariah&&(t.shariah===`halal`||F)&&(0,U.jsx)(`span`,{className:m(`rounded px-1 text-[12px] font-medium`,Ir[t.shariah]),title:t.shariah_reason,children:e(`badge.${t.shariah}`)})]})]}),Ie&&(0,U.jsx)(`td`,{className:`px-3 py-2.5 text-xs text-muted`,children:K(t.market)}),(0,U.jsxs)(`td`,{className:`hidden max-w-52 px-3 py-2.5 md:table-cell`,children:[(0,U.jsxs)(`div`,{className:`truncate text-xs`,title:t.category_inferred?e(`categoryGuessed`):void 0,children:[t.category??`—`,t.category_inferred&&t.type===`stock`&&(0,U.jsx)(`span`,{className:`text-faint`,children:`*`})]}),t.sector&&t.sector!==t.category&&(0,U.jsx)(`div`,{className:`truncate text-xs text-faint`,title:t.sector,children:t.sector})]}),(0,U.jsx)(`td`,{className:m(`tabular px-3 py-2.5 text-end`,Fe.flash(t)),children:n(t.price,t.currency)}),Le&&(0,U.jsx)(`td`,{className:`hidden px-3 py-2.5 text-end sm:table-cell`,children:(0,U.jsx)(De,{day:t.sip_day,edge:t.sip_edge,spread:t.sip_spread})}),H?(0,U.jsx)(`td`,{className:`tabular hidden px-3 py-2.5 text-end text-xs text-muted sm:table-cell`,children:t.nav_date??`—`}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`td`,{className:m(`tabular px-3 py-2.5 text-end`,i(t.change_percent)),children:u(t.change_percent)}),(0,U.jsx)(`td`,{className:`tabular hidden px-3 py-2.5 text-end sm:table-cell`,children:a(t.market_cap,t.currency)}),(0,U.jsx)(`td`,{className:`tabular hidden px-3 py-2.5 text-end text-muted lg:table-cell`,children:d(t.volume)}),(0,U.jsx)(`td`,{className:`hidden px-3 py-2.5 xl:table-cell`,children:(0,U.jsx)(Ae,{low:t.low_52w,high:t.high_52w,value:t.price})})]})]},`${t.market}:${t.type}:${t.symbol}`))})]}),!ue&&R&&R.rows.length===0&&(0,U.jsx)(T,{icon:`search`,title:e(`empty.title`),description:Ke.length?e(`empty.noData`):e(`empty.tryAgain`)})]}),J>Lr&&(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-line px-5 py-3 text-xs text-muted`,children:[(0,U.jsx)(`span`,{className:`tabular`,children:e(`pager.range`,{from:(M*Lr+1).toLocaleString(),to:Math.min(J,(M+1)*Lr).toLocaleString(),total:J.toLocaleString()})}),(0,U.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,U.jsx)(w,{variant:`ghost`,size:`sm`,disabled:M===0,onClick:()=>z({page:null},!0),children:e(`pager.first`)}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,disabled:M===0,onClick:()=>z({page:String(M-1)},!0),children:e(`pager.prev`)}),(0,U.jsx)(`span`,{className:`tabular px-2`,children:e(`pager.page`,{page:M+1,pages:Xe.toLocaleString()})}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,disabled:M>=Xe-1,onClick:()=>z({page:String(M+1)},!0),children:e(`pager.next`)})]})]})]})})]})}export{Gr as default};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{a as t,b as n,d as r,f as i,n as a,o,p as s,s as c,t as l}from"./format-d8InM0Zw.js";import{t as u}from"./toast-DDradTZw.js";import{D as d,O as f,_ as p,a as m,c as h,f as g,g as _,i as v,l as y,n as b,o as x,p as S,r as C,s as w,t as T,x as E,y as D}from"./ui-gsFb8B2m.js";import{n as O}from"./files-CpgiZRbN.js";import{O as k,j as A,k as j}from"./index-CKAnq-Or.js";import{R as M,a as N,i as P,pt as F,r as I,t as L,u as R,yt as z}from"./LineChart-BaOkD1Ta.js";import{r as B}from"./BarChart-_yngarVl.js";import{a as V,i as ee,n as H,o as te,r as U,t as W}from"./montecarlo-BsNlH2qe.js";import{n as ne,t as re}from"./options-BYAZnwzW.js";import{i as ie,r as ae}from"./SipDays-C9q3bNSx.js";import{t as oe}from"./SymbolSearch-CBOVPEk1.js";import{t as se}from"./ExportMenu-DaZ1xVmW.js";var G=e(n(),1);async function ce(){return(await f.get(`/portfolio`)).data}async function le(e){return(await f.get(`/portfolio/${encodeURIComponent(e)}`)).data}async function ue(e,t=`USD`,n=`stocks`){return(await f.post(`/portfolio`,{name:e,currency:t,kind:n})).data}async function de(e,t){return(await f.post(`/portfolio/${encodeURIComponent(e)}/transactions`,t)).data}async function fe(e,t){return(await f.get(`/funds/${encodeURIComponent(e)}/nav`,{params:{on:t}})).data}async function pe(e,t){return(await f.patch(`/portfolio/${encodeURIComponent(e)}`,{name:t})).data}async function me(e){await f.delete(`/portfolio/${encodeURIComponent(e)}`)}async function he(e,t){return(await f.delete(`/portfolio/${encodeURIComponent(e)}/transactions/${t}`)).data}async function ge(e){return(await f.get(`/portfolio/${encodeURIComponent(e)}/analytics`)).data}async function _e(e,t){return(await f.post(`/portfolio/cas/parse`,{file_b64:e,password:t},{timeout:12e4})).data}async function ve(e,t){return(await f.post(`/portfolio/${encodeURIComponent(e)}/import-funds`,{holdings:t})).data}async function ye(e){return(await f.get(`/portfolio/${encodeURIComponent(e)}/fund-insights`)).data}async function be(e){return(await f.get(`/portfolio/${encodeURIComponent(e)}/funds`,{timeout:12e4})).data}async function xe(e,t){return(await f.post(`/portfolio/${encodeURIComponent(e)}/funds/${encodeURIComponent(t)}/ai-review`,null,{timeout:12e4})).data}async function Se(e){return(await f.get(`/portfolio/${encodeURIComponent(e)}/dip-alerts`)).data}async function Ce(e,t){return(await f.put(`/portfolio/${encodeURIComponent(e)}/dip-alerts`,t)).data}async function we(e){return(await f.post(`/portfolio/${encodeURIComponent(e)}/dip-alerts/test`,null,{timeout:9e4})).data}async function Te(e){return(await f.get(`/portfolio/${encodeURIComponent(e)}/review`,{timeout:12e4})).data}async function Ee(e,t){return(await f.put(`/portfolio/${encodeURIComponent(e)}/review/limits`,t)).data}async function De(e){return(await f.post(`/portfolio/${encodeURIComponent(e)}/review/ai`,null,{timeout:12e4})).data}async function Oe(e,t,n,r){return(await f.post(`/portfolio/${encodeURIComponent(e)}/reconcile`,{filename:t,file_b64:n,password:r},{timeout:12e4})).data}async function ke(e,t){return(await f.post(`/portfolio/${encodeURIComponent(e)}/reconcile/apply`,{fixes:t})).data}async function Ae(e,t=!1){return(await f.post(`/portfolio/${encodeURIComponent(e)}/funds/ai-review`,null,{params:{refresh:t},timeout:26e4})).data}var K=s(),q=(e,t=1)=>e==null?`—`:c(e*100,t),J=(e,t=1)=>e==null?`—`:`${o(e*100,t)}%`;function Y(e,t){if(e==null||!Number.isFinite(e))return`—`;try{return e.toLocaleString(t===`INR`?`en-IN`:void 0,{style:`currency`,currency:t,maximumFractionDigits:0})}catch{return`${Math.round(e).toLocaleString()} ${t}`}}var je=[{value:`risk`,label:`Risk by holding`},{value:`correlation`,label:`Correlation`},{value:`stress`,label:`Stress test`},{value:`projection`,label:`Projection & goal`}];function Me({portfolio:e,currency:n,version:r}){let[s,c]=(0,G.useState)(null),[l,u]=(0,G.useState)(null),[d,f]=(0,G.useState)(!1),[p,h]=(0,G.useState)(`risk`);async function g(){f(!0),u(null);try{c(await ge(e))}catch(e){c(null),u(a(e))}finally{f(!1)}}(0,G.useEffect)(()=>{g()},[e,r]);let y=s?.metrics;return(0,K.jsxs)(v,{id:`section-analytics`,section:`Risk & analytics`,children:[(0,K.jsx)(x,{title:`Risk & analytics`,icon:`analyze`,description:s?`Today's mix replayed over ${s.days} trading days to ${s.as_of}, vs ${s.benchmark.name}`:`Return, risk and diversification of the current holdings over the last year`,actions:(0,K.jsx)(C,{variant:`ghost`,icon:`refresh`,loading:d,onClick:g,children:`Recalculate`})}),(0,K.jsxs)(m,{className:`space-y-5`,children:[l&&(0,K.jsx)(T,{tone:`warn`,title:`Analytics unavailable`,children:l}),!s&&!l&&(0,K.jsx)(D,{className:`h-48 w-full`}),s&&y&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 sm:grid-cols-4 lg:grid-cols-8`,children:[(0,K.jsx)(E,{label:`Annual return`,value:(0,K.jsx)(`span`,{className:i(y.annual_return),children:q(y.annual_return)}),sub:y.benchmark_return==null?void 0:`index ${q(y.benchmark_return)}`}),(0,K.jsx)(E,{label:`Volatility`,value:J(y.volatility),sub:`annualised`}),(0,K.jsx)(E,{label:`Sharpe`,value:o(y.sharpe),sub:`rf ${J(s.risk_free)}`}),(0,K.jsx)(E,{label:`Sortino`,value:o(y.sortino),sub:`downside only`}),(0,K.jsx)(E,{label:`Max drawdown`,value:(0,K.jsx)(`span`,{className:`text-down`,children:q(y.max_drawdown)})}),(0,K.jsx)(E,{label:`Beta`,value:o(y.beta),sub:s.benchmark.name}),(0,K.jsx)(E,{label:`1-day VaR 95%`,value:t(y.var_95_value,n),sub:J(y.var_95,2)}),(0,K.jsx)(E,{label:`Expected shortfall`,value:t(y.cvar_95_value,n),sub:J(y.cvar_95,2)})]}),y.tracking_error!=null&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 rounded-lg bg-canvas px-3 py-2.5 sm:grid-cols-4`,children:[(0,K.jsx)(E,{label:`Tracking error`,value:J(y.tracking_error),sub:`vs ${s.benchmark.name}, a year`}),(0,K.jsx)(E,{label:`Information ratio`,value:o(y.information_ratio),sub:`extra return per unit of tracking error`}),(0,K.jsx)(E,{label:`Up capture`,value:J(y.up_capture,0),sub:`of the index's rises`}),(0,K.jsx)(E,{label:`Down capture`,value:J(y.down_capture,0),sub:`of the index's falls`})]}),s.warnings.length>0&&(0,K.jsx)(`ul`,{className:`space-y-1 text-xs text-warn`,children:s.warnings.map(e=>(0,K.jsxs)(`li`,{children:[`• `,e]},e))}),s.curve.length>1&&(0,K.jsx)(`div`,{className:`h-56`,children:(0,K.jsx)(z,{width:`100%`,height:`100%`,children:(0,K.jsxs)(L,{data:s.curve,margin:{top:5,right:8,bottom:0,left:0},children:[(0,K.jsx)(R,{stroke:`var(--color-line)`,vertical:!1}),(0,K.jsx)(P,{dataKey:`time`,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1,minTickGap:40,tickFormatter:e=>new Date(e).toLocaleDateString(void 0,{month:`short`,year:`2-digit`})}),(0,K.jsx)(I,{domain:[`auto`,`auto`],width:40,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1}),(0,K.jsx)(M,{contentStyle:{background:`var(--color-raised)`,border:`1px solid var(--color-line-strong)`,borderRadius:8,fontSize:12},formatter:(e,t)=>[o(Number(e),1),t===`portfolio`?`Portfolio`:s.benchmark.name]}),(0,K.jsx)(F,{formatter:e=>e===`portfolio`?`Portfolio (start = 100)`:s.benchmark.name,wrapperStyle:{fontSize:12}}),(0,K.jsx)(N,{type:`monotone`,dataKey:`portfolio`,stroke:`var(--color-accent)`,strokeWidth:1.75,dot:!1}),(0,K.jsx)(N,{type:`monotone`,dataKey:`benchmark`,stroke:`var(--color-faint)`,strokeWidth:1.25,strokeDasharray:`4 3`,dot:!1})]})})}),(0,K.jsx)(_,{value:p,onChange:e=>h(e),options:je}),p===`risk`&&(0,K.jsx)(Ne,{data:s}),p===`correlation`&&(0,K.jsx)(Pe,{data:s}),p===`stress`&&(0,K.jsx)(Fe,{data:s,currency:n}),p===`projection`&&(0,K.jsx)(Ie,{data:s,currency:n})]})]})]})}function Ne({data:e}){return(0,K.jsxs)(`div`,{className:`overflow-x-auto`,children:[(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-xs text-muted`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`py-1.5 pe-2 text-start font-medium`,children:`Symbol`}),(0,K.jsx)(`th`,{className:`py-1.5 pe-2 text-end font-medium`,children:`Weight`}),(0,K.jsx)(`th`,{className:`py-1.5 pe-2 text-end font-medium`,title:`Share of total portfolio volatility`,children:`Risk share`}),(0,K.jsx)(`th`,{className:`py-1.5 pe-2 text-end font-medium`,children:`Return`}),(0,K.jsx)(`th`,{className:`py-1.5 pe-2 text-end font-medium`,children:`Volatility`}),(0,K.jsx)(`th`,{className:`py-1.5 pe-2 text-end font-medium`,children:`Max DD`}),(0,K.jsx)(`th`,{className:`py-1.5 text-end font-medium`,children:`Beta`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:e.holdings.map(e=>{let t=(e.risk_contribution??0)>e.weight*1.3;return(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`td`,{className:`py-1.5 pe-2 font-mono`,children:e.symbol}),(0,K.jsx)(`td`,{className:`tabular py-1.5 pe-2 text-end`,children:J(e.weight)}),(0,K.jsx)(`td`,{className:d(`tabular py-1.5 pe-2 text-end`,t&&`font-semibold text-warn`),children:J(e.risk_contribution)}),(0,K.jsx)(`td`,{className:d(`tabular py-1.5 pe-2 text-end`,i(e.annual_return)),children:q(e.annual_return)}),(0,K.jsx)(`td`,{className:`tabular py-1.5 pe-2 text-end`,children:J(e.volatility)}),(0,K.jsx)(`td`,{className:`tabular py-1.5 pe-2 text-end text-down`,children:q(e.max_drawdown)}),(0,K.jsx)(`td`,{className:`tabular py-1.5 text-end`,children:o(e.beta)})]},e.symbol)})})]}),(0,K.jsx)(`p`,{className:`mt-2 text-xs text-faint`,children:`Risk share above weight (highlighted) means the holding adds more volatility than its size suggests.`})]})}function Pe({data:e}){let{symbols:t,matrix:n}=e.correlation;return t.length<2?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`Needs at least two holdings.`}):(0,K.jsxs)(`div`,{className:`overflow-x-auto`,children:[(0,K.jsxs)(`table`,{className:`text-xs`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{}),t.map(e=>(0,K.jsx)(`th`,{className:`px-1.5 py-1 font-mono font-medium text-muted`,children:e},e))]})}),(0,K.jsx)(`tbody`,{children:t.map((e,t)=>(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`py-1 pe-2 text-start font-mono font-medium text-muted`,children:e}),n[t].map((e,t)=>{let n=e??0;return(0,K.jsx)(`td`,{className:`tabular px-1.5 py-1 text-center`,style:{backgroundColor:`color-mix(in srgb, ${n>=0?`var(--color-accent)`:`var(--color-down)`} ${Math.round(Math.abs(n)*55)}%, transparent)`},children:e==null?`—`:e.toFixed(2)},t)})]},e))})]}),(0,K.jsx)(`p`,{className:`mt-2 text-xs text-faint`,children:`Daily-return correlation. Near 1 = move together (little diversification); near 0 or negative = diversify well.`})]})}function Fe({data:e,currency:t}){let n=e.stress??[];return n.length?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`text-start text-xs text-muted`,children:[(0,K.jsx)(`th`,{className:`py-1 pe-3 font-medium`,children:`Scenario`}),(0,K.jsx)(`th`,{className:`py-1 pe-3 text-end font-medium`,children:e.benchmark.name}),(0,K.jsx)(`th`,{className:`py-1 text-end font-medium`,children:`This portfolio (est.)`})]})}),(0,K.jsx)(`tbody`,{children:n.map(n=>(0,K.jsxs)(`tr`,{className:`border-t border-line`,children:[(0,K.jsxs)(`td`,{className:`py-1.5 pe-3`,children:[n.label,n.from&&(0,K.jsxs)(`div`,{className:`text-[11px] text-faint`,children:[n.from,` to `,n.to]})]}),(0,K.jsx)(`td`,{className:`tabular py-1.5 pe-3 text-end text-down`,children:q(n.index_move)}),(0,K.jsxs)(`td`,{className:`tabular py-1.5 text-end text-down`,children:[q(n.portfolio_move),(0,K.jsx)(`div`,{className:`text-[11px]`,children:Y(n.portfolio_move*e.total_value,t)})]})]},n.label))})]})}),(0,K.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Past falls are the `,e.benchmark.name,`'s own peak-to-trough moves in each window; the portfolio estimate moves each holding by its beta (1 when unknown) times the index. Real losses differ: stocks fall unevenly and correlations rise in a crash.`]})]}):(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No stress scenarios for this portfolio.`})}function Ie({data:e,currency:t}){let n=e.projection,[r,i]=(0,G.useState)({years:`10`,monthly:`0`,goal:String(Math.round(e.total_value*2)),ret:((n?.expected_return??.08)*100).toFixed(1),vol:((n?.volatility??.16)*100).toFixed(1)}),a={years:Math.min(40,Math.max(1,Math.round(Number(r.years)||0))),monthly:Math.max(0,Number(r.monthly)||0),goal:Math.max(0,Number(r.goal)||0),ret:(Number(r.ret)||0)/100,vol:Math.max(.01,(Number(r.vol)||0)/100)},o={start:e.total_value,years:a.years,expectedReturn:a.ret,volatility:a.vol},s=(0,G.useMemo)(()=>U({...o,monthly:a.monthly}),[e.total_value,a.years,a.monthly,a.ret,a.vol]),c=a.goal?W(s.finals,a.goal):null,u=(0,G.useMemo)(()=>a.goal?H(o,a.goal,.8):null,[e.total_value,a.years,a.goal,a.ret,a.vol]),d=s.bands[s.bands.length-1],f=s.bands.map(e=>({...e,band:[e.p10,e.p90]})),p=(e,t,n)=>(0,K.jsxs)(`label`,{className:`block min-w-0`,children:[(0,K.jsx)(`span`,{className:`mb-1 block text-xs font-medium text-muted`,children:t}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(g,{type:`number`,inputMode:`decimal`,value:r[e],onChange:t=>i({...r,[e]:t.target.value}),className:`w-full`,"aria-label":t}),n&&(0,K.jsx)(`span`,{className:`text-sm text-muted`,children:n})]})]});return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-5`,children:[p(`years`,`Years`),p(`monthly`,`Added each month`),p(`goal`,`Goal`),p(`ret`,`Expected return`,`%`),p(`vol`,`Volatility`,`%`)]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,K.jsx)(E,{label:`Middle outcome in ${a.years} years`,value:Y(d.p50,t),sub:`put in ${Y(d.invested,t)}`}),(0,K.jsx)(E,{label:`Bad case (1 in 10)`,value:Y(d.p10,t),sub:`10th percentile`}),(0,K.jsx)(E,{label:`Chance of reaching the goal`,value:c==null?`—`:`${Math.round(c*100)}%`,sub:`goal ${Y(a.goal,t)}`}),(0,K.jsx)(E,{label:`Monthly amount for an 80% chance`,value:u==null?`—`:Y(u,t),sub:u===0?`already on track without adding`:`at these return and volatility figures`})]}),(0,K.jsx)(`div`,{className:`h-60`,children:(0,K.jsx)(z,{width:`100%`,height:`100%`,children:(0,K.jsxs)(te,{data:f,margin:{top:5,right:8,bottom:0,left:0},children:[(0,K.jsx)(R,{stroke:`var(--color-line)`,vertical:!1}),(0,K.jsx)(P,{dataKey:`year`,tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1,tickFormatter:e=>`${e}y`}),(0,K.jsx)(I,{width:56,tickFormatter:e=>l(e),tick:{fill:`var(--color-faint)`,fontSize:11},axisLine:!1,tickLine:!1}),(0,K.jsx)(M,{contentStyle:{background:`var(--color-raised)`,border:`1px solid var(--color-line-strong)`,borderRadius:8,fontSize:12},labelFormatter:e=>`Year ${e}`,formatter:(e,n)=>Array.isArray(e)?[`${Y(Number(e[0]),t)} – ${Y(Number(e[1]),t)}`,`1 in 10 to 9 in 10`]:[Y(Number(e),t),n===`p50`?`Middle outcome`:`Money put in`]}),(0,K.jsx)(B,{type:`monotone`,dataKey:`band`,stroke:`none`,fill:`var(--color-accent)`,fillOpacity:.15}),(0,K.jsx)(N,{type:`monotone`,dataKey:`p50`,stroke:`var(--color-accent)`,strokeWidth:2,dot:!1}),(0,K.jsx)(N,{type:`monotone`,dataKey:`invested`,stroke:`var(--color-faint)`,strokeDasharray:`4 3`,dot:!1})]})})}),(0,K.jsx)(`p`,{className:`text-[12px] text-faint`,children:`2,000 simulated paths with monthly returns drawn at your expected return and volatility (defaults: a long-run assumption for this market and this portfolio's own volatility over the past year), contributions added each month, no taxes or costs. Shaded: the middle 80% of outcomes. A projection of your inputs, not a forecast or advice.`})]})}var Le={high:{label:`Act on this`,tone:`down`,dot:`bg-down`},medium:{label:`Worth a look`,tone:`warn`,dot:`bg-warn`},low:{label:`Minor`,tone:`neutral`,dot:`bg-faint`}},Re={"section-holdings":`Holdings`,"section-analytics":`Risk & analytics`,"section-funds":`Mutual funds`,"section-fund-health":`Fund health check`,"section-transactions":`Transactions`},ze=[{key:`max_holding`,label:`Max per holding`,hint:`Flag any single holding above this share`,suffix:`%`},{key:`max_sector`,label:`Max per sector`,hint:`Flag a sector above this share of stocks`,suffix:`%`},{key:`max_cash`,label:`Max cash`,hint:`Flag idle cash above this share`,suffix:`%`},{key:`loss_review`,label:`Review losses at`,hint:`Flag holdings this far below cost`,suffix:`% down`},{key:`min_holdings`,label:`Min holdings`,hint:`Flag a stock-only portfolio with fewer`,suffix:`stocks`}],Be=4;function Ve({portfolio:e,version:t}){let[n,r]=(0,G.useState)(null),[i,o]=(0,G.useState)(null),[s,c]=(0,G.useState)(!1),[l,u]=(0,G.useState)(0),[f,p]=(0,G.useState)(!1),[h,g]=(0,G.useState)(!1),[_,S]=(0,G.useState)({});(0,G.useEffect)(()=>{let t=!1;return o(null),c(!0),Te(e).then(e=>!t&&r(e)).catch(e=>!t&&o(a(e))).finally(()=>!t&&c(!1)),()=>{t=!0}},[e,t,l]),(0,G.useEffect)(()=>S({}),[e,t]);let w=()=>{S({loading:!0}),De(e).then(e=>S({data:e})).catch(e=>S({error:a(e)}))},E=n?.findings??[],O=f?E:E.slice(0,Be),k=n?.grade===`Good`?`text-up`:n?.grade===`Fair`?`text-warn`:`text-down`;return(0,K.jsxs)(v,{id:`section-review`,section:`Portfolio review`,children:[(0,K.jsx)(x,{title:`Portfolio review`,icon:`shield`,description:`What could be changed, why it matters and how - checked against your own limits`,actions:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(C,{variant:`ghost`,size:`sm`,icon:`settings`,onClick:()=>g(e=>!e),disabled:!n,children:`Your limits`}),(0,K.jsx)(C,{variant:`ghost`,size:`sm`,icon:`refresh`,loading:s&&!!n,onClick:()=>u(e=>e+1),children:`Recheck`})]})}),(0,K.jsx)(m,{className:`space-y-5`,children:i?(0,K.jsx)(`p`,{className:`text-sm text-down`,children:i}):n?n.score==null?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:n.summary}):(0,K.jsxs)(K.Fragment,{children:[h&&(0,K.jsx)(We,{portfolio:e,limits:n.limits,onSaved:()=>{g(!1),u(e=>e+1)},onCancel:()=>g(!1)}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-8 gap-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-xs text-faint`,children:`Score`}),(0,K.jsxs)(`div`,{className:`tabular text-2xl font-semibold`,children:[n.score,(0,K.jsx)(`span`,{className:`text-sm text-faint`,children:`/100`}),` `,(0,K.jsx)(`span`,{className:d(`text-sm`,k),children:n.grade})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-xs text-faint`,children:`Found`}),(0,K.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1.5`,children:[[`high`,`medium`,`low`].map(e=>{let t=E.filter(t=>t.severity===e).length;return t?(0,K.jsxs)(b,{tone:Le[e].tone,children:[t,` `,Le[e].label]},e):null}),!E.length&&(0,K.jsx)(`span`,{className:`text-sm text-up`,children:n.summary})]})]})]}),(0,K.jsx)(C,{size:`sm`,variant:`secondary`,icon:`cpu`,loading:_.loading,onClick:w,children:_.loading?`Reviewing…`:`AI analyst summary`})]}),_.error&&(0,K.jsx)(T,{title:`AI summary failed`,onDismiss:()=>S({}),children:_.error}),_.data&&(0,K.jsx)(Ue,{ai:_.data,onClose:()=>S({})}),E.length>0&&(0,K.jsx)(`ol`,{className:`space-y-3`,children:O.map((e,t)=>(0,K.jsx)(He,{finding:e,index:t+1},e.id))}),E.length>Be&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`text-xs font-medium text-accent-fg hover:text-fg`,children:f?`Show fewer`:`Show ${E.length-Be} more`}),n.good.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-muted`,children:`What's working`}),(0,K.jsx)(`ul`,{className:`space-y-1`,children:n.good.map(e=>(0,K.jsxs)(`li`,{className:`flex items-start gap-2 text-sm`,children:[(0,K.jsx)(y,{name:`check`,className:`mt-0.5 h-4 w-4 shrink-0 text-up`}),(0,K.jsx)(`span`,{children:e})]},e))})]}),(0,K.jsx)(`p`,{className:`text-[12px] text-faint`,children:`Facts and general options checked against your own limits. Not investment advice; consider your goals and a registered adviser for decisions.`})]}):(0,K.jsx)(D,{className:`h-40 w-full`})})]})}function He({finding:e,index:t}){let n=Le[e.severity];return(0,K.jsxs)(`li`,{className:`rounded-lg border border-line bg-canvas`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-3 px-4 pt-3`,children:[(0,K.jsx)(`span`,{className:`tabular mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-raised text-[11px] font-semibold text-muted`,children:t}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-semibold`,children:e.title}),(0,K.jsx)(b,{tone:n.tone,children:n.label}),e.rule&&(0,K.jsx)(`span`,{className:`text-xs text-faint`,children:e.rule})]}),(0,K.jsx)(`p`,{className:`mt-1 text-sm`,children:e.fact})]})]}),(0,K.jsxs)(`div`,{className:`grid gap-3 px-4 py-3 ps-12 md:grid-cols-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted`,children:`Why it matters`}),(0,K.jsx)(`p`,{className:`text-sm text-fg/80`,children:e.why})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`mb-1 text-xs font-medium text-muted`,children:`What you can change`}),(0,K.jsx)(`ul`,{className:`space-y-1`,children:e.levers.map(e=>(0,K.jsxs)(`li`,{className:`flex gap-2 text-sm text-fg/90`,children:[(0,K.jsx)(`span`,{className:d(`mt-2 h-1.5 w-1.5 shrink-0 rounded-full`,n.dot)}),(0,K.jsx)(`span`,{children:e})]},e))})]})]}),Re[e.section]&&(0,K.jsx)(`div`,{className:`border-t border-line px-4 py-2 ps-12`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>document.getElementById(e.section)?.scrollIntoView({behavior:`smooth`,block:`start`}),className:`text-xs text-muted hover:text-accent-fg`,children:[`See the numbers in `,Re[e.section],` →`]})})]})}function Ue({ai:e,onClose:t}){return(0,K.jsxs)(`div`,{className:`rounded-lg border border-accent/40 bg-accent-soft px-4 py-3`,children:[(0,K.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs font-semibold text-accent-fg`,children:`AI analyst summary`}),(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`text-muted hover:text-fg`,"aria-label":`Close`,children:(0,K.jsx)(y,{name:`x`})})]}),(0,K.jsx)(`p`,{className:`text-sm`,children:e.summary}),e.priorities.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`mt-3 mb-1 text-xs font-medium text-muted`,children:`Look into first`}),(0,K.jsx)(`ol`,{className:`list-decimal space-y-1 ps-5 text-sm`,children:e.priorities.map(e=>(0,K.jsx)(`li`,{children:e},e))})]}),e.keep&&(0,K.jsxs)(`p`,{className:`mt-3 text-sm`,children:[(0,K.jsx)(`span`,{className:`font-medium text-up`,children:`Fine as it is: `}),e.keep]})]})}function We({portfolio:e,limits:t,onSaved:n,onCancel:r}){let[i,o]=(0,G.useState)(()=>Object.fromEntries(ze.map(e=>[e.key,String(t[e.key])]))),[s,c]=(0,G.useState)(!1),[l,d]=(0,G.useState)(null);return(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),c(!0),d(null),Ee(e,Object.fromEntries(ze.map(e=>[e.key,Number(i[e.key])]))).then(()=>{u.success(`Limits saved`),n()}).catch(e=>d(a(e))).finally(()=>c(!1))},className:`space-y-3 rounded-lg border border-line bg-canvas p-4`,children:[(0,K.jsx)(`div`,{className:`text-xs text-muted`,children:`The review checks your portfolio against these. Set them to match how you invest.`}),(0,K.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-5`,children:ze.map(e=>(0,K.jsx)(h,{label:e.label,hint:`${e.hint} (${e.suffix})`,children:(0,K.jsx)(g,{type:`number`,min:`0`,step:`any`,value:i[e.key],onChange:t=>o(n=>({...n,[e.key]:t.target.value})),className:`w-full`})},e.key))}),l&&(0,K.jsx)(`p`,{className:`text-sm text-down`,children:l}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(C,{type:`submit`,size:`sm`,loading:s,children:`Save limits`}),(0,K.jsx)(C,{type:`button`,size:`sm`,variant:`ghost`,onClick:r,children:`Cancel`})]})]})}var Ge=10485760;function X(e){return e==null||!Number.isFinite(e)?`—`:e.toLocaleString(`en-IN`,{style:`currency`,currency:`INR`,maximumFractionDigits:0})}function Ke({portfolio:e,currency:t,onCancel:n,onImported:r}){let[i,s]=(0,G.useState)(null),[c,l]=(0,G.useState)(``),[f,p]=(0,G.useState)(!1),[_,y]=(0,G.useState)(!1),[b,S]=(0,G.useState)(null),[w,T]=(0,G.useState)(new Set),[E,D]=(0,G.useState)(null);async function k(){if(i){if(i.size>Ge)return D(`File is larger than 10 MB.`);p(!0),D(null);try{let e=await _e(await O(i),c);S(e),T(new Set(e.holdings.map(e=>e.amfi)))}catch(e){D(a(e))}finally{p(!1)}}}async function A(){if(b){y(!0);try{let t=await ve(e,b.holdings.filter(e=>w.has(e.amfi)).map(({amfi:e,scheme:t,units:n,nav:r,cost:i,date:a})=>({amfi:e,scheme:t,units:n,nav:r,cost:i,date:a})));u.success(t.applied?`Updated ${t.applied} fund${t.applied===1?``:`s`}${t.unchanged?`, ${t.unchanged} already in sync`:``}`:`Everything already in sync`),r(t.portfolio)}catch(e){u.error(a(e))}finally{y(!1)}}}let j=e=>T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,K.jsxs)(v,{className:`mb-6`,children:[(0,K.jsx)(x,{title:`Import mutual funds from CAS`,description:`Your Consolidated Account Statement (CAS) PDF, the one your mutual fund registrar emails you or lets you download.`,icon:`plus`}),(0,K.jsxs)(m,{className:`space-y-4`,children:[b?(0,K.jsxs)(K.Fragment,{children:[t!==`INR`&&(0,K.jsxs)(`p`,{className:`rounded-lg bg-warn-soft px-3 py-2 text-xs text-warn`,children:[`This portfolio is in `,t,`; fund values are in INR and will be mixed without conversion.`]}),b.holdings.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No fund holdings found in this statement.`}):(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`tabular w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-xs text-muted`,children:(0,K.jsxs)(`tr`,{className:`border-b border-line`,children:[(0,K.jsx)(`th`,{className:`w-8 py-2`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-start font-medium`,children:`Scheme`}),(0,K.jsx)(`th`,{className:`hidden px-2 py-2 text-end font-medium sm:table-cell`,children:`Units`}),(0,K.jsx)(`th`,{className:`hidden px-2 py-2 text-end font-medium sm:table-cell`,children:`Cost`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Value`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:b.holdings.map(e=>(0,K.jsxs)(`tr`,{className:d(!w.has(e.amfi)&&`opacity-50`),children:[(0,K.jsx)(`td`,{className:`py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 accent-[var(--color-accent)]`,checked:w.has(e.amfi),onChange:()=>j(e.amfi),"aria-label":`Import ${e.scheme}`})}),(0,K.jsxs)(`td`,{className:`max-w-[11rem] px-2 py-2 sm:max-w-72`,children:[(0,K.jsx)(`div`,{className:`truncate`,title:e.scheme,children:e.scheme}),(0,K.jsxs)(`div`,{className:`text-xs text-faint`,children:[e.amc,` · `,e.amfi,e.folios>1?` · ${e.folios} folios`:``,e.units<=0?` · fully redeemed`:``]}),e.units>0&&(0,K.jsxs)(`div`,{className:`text-xs text-muted sm:hidden`,children:[o(e.units,3),` units · cost `,X(e.cost)]})]}),(0,K.jsx)(`td`,{className:`hidden px-2 py-2 text-end sm:table-cell`,children:o(e.units,3)}),(0,K.jsx)(`td`,{className:`hidden px-2 py-2 text-end text-muted sm:table-cell`,children:X(e.cost)}),(0,K.jsx)(`td`,{className:`px-2 py-2 text-end`,children:X(e.value)})]},e.amfi))})]})}),b.skipped.length>0&&(0,K.jsxs)(`p`,{className:`text-xs text-faint`,children:[`Skipped: `,b.skipped.map(e=>`${e.scheme} (${e.reason})`).join(`; `)]}),(0,K.jsx)(`p`,{className:`text-xs text-faint`,children:`Units are synced: funds already in this portfolio only get the difference added or sold, so you can re-import each month. Funds without a cost in the statement are recorded at the statement NAV, so their gain starts at zero.`}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-muted`,children:[`Statement total `,(0,K.jsx)(`span`,{className:`tabular font-semibold text-fg`,children:X(b.total_value)}),b.statement_to?` as of ${b.statement_to}`:``]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(C,{variant:`ghost`,onClick:()=>(S(null),D(null)),children:`Back`}),(0,K.jsxs)(C,{icon:`check`,loading:_,disabled:w.size===0,onClick:A,children:[`Import `,w.size,` fund`,w.size===1?``:`s`]})]})]})]}):(0,K.jsxs)(`form`,{className:`grid gap-3 sm:grid-cols-[minmax(0,1fr)_200px_auto] sm:items-end`,onSubmit:e=>{e.preventDefault(),k()},children:[(0,K.jsx)(h,{label:`Statement PDF`,children:(0,K.jsx)(g,{type:`file`,accept:`application/pdf,.pdf`,className:`py-1.5`,onChange:e=>s(e.target.files?.[0]??null)})}),(0,K.jsx)(h,{label:`PDF password`,children:(0,K.jsx)(g,{type:`password`,autoComplete:`off`,placeholder:`Usually your PAN`,value:c,onChange:e=>l(e.target.value)})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(C,{type:`button`,variant:`ghost`,onClick:n,children:`Cancel`}),(0,K.jsx)(C,{type:`submit`,loading:f,disabled:!i,children:`Read statement`})]})]}),E&&(0,K.jsx)(`p`,{className:`text-sm text-down`,children:E}),(0,K.jsx)(`p`,{className:`text-xs text-faint`,children:`The file and password are read in memory and not stored.`})]})]})}var qe=10485760,Je={split:`Split / bonus`,not_in_app:`Only on statement`,not_in_statement:`Only in MarketMyna`,short:`Statement has more`,excess:`MarketMyna has more`},Z=e=>o(e,e!=null&&Number.isInteger(e)?0:4),Ye={buy:`Add buy`,sell:`Add sell`,split:`Add split / bonus`};function Xe({portfolio:e,onCancel:t,onApplied:n}){let[r,i]=(0,G.useState)(null),[s,c]=(0,G.useState)(``),[l,f]=(0,G.useState)(!1),[p,_]=(0,G.useState)(!1),[y,b]=(0,G.useState)(null),[S,w]=(0,G.useState)({}),E=!!r&&r.name.toLowerCase().endsWith(`.pdf`),D=(e,t)=>`${e.symbol}:${t}`;async function k(){if(r){if(r.size>qe)u.error(`That file is over 10 MB`);else{f(!0);try{let t=await Oe(e,r.name,await O(r),s);b(t);let n={};for(let e of t.breaks)e.fixes.forEach((t,r)=>{let i=t.type===`split`?`0`:t.price>0?String(Math.round(t.price*100)/100):``;n[D(e,r)]={on:!t.needs_price,price:i}});w(n)}catch(e){u.error(a(e))}finally{f(!1)}}}}async function A(){if(!y)return;let t=y.breaks.flatMap(e=>e.fixes.map((t,n)=>({b:e,f:t,c:S[D(e,n)]})).filter(({c:e})=>e?.on).map(({b:e,f:t,c:n})=>({symbol:e.symbol,market:e.market,type:t.type,quantity:t.quantity,price:t.type===`split`?0:Number(n.price),date:t.date,notes:t.notes})));if(t.length){if(t.some(e=>e.type!==`split`&&!(e.price>0)))u.error(`Enter a price for every ticked buy or sell`);else{_(!0);try{let r=await ke(e,t);r.errors.length&&u.error(r.errors.join(`; `)),r.applied&&u.success(`Added ${r.applied} entr${r.applied===1?`y`:`ies`}`),n(r.portfolio)}catch(e){u.error(a(e))}finally{_(!1)}}}}let j=Object.values(S).filter(e=>e.on).length;return(0,K.jsxs)(v,{className:`mb-6`,id:`section-reconcile`,section:`Reconcile`,children:[(0,K.jsx)(x,{title:`Reconcile with a statement`,icon:`check`,description:`Compare this portfolio with the holdings export from your broker's website or app (CSV or Excel), or, for mutual funds, your Consolidated Account Statement (CAS) PDF. The file is read in memory and never stored.`}),(0,K.jsxs)(m,{className:`space-y-5`,children:[(0,K.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[minmax(0,1fr)_minmax(0,14rem)_auto] sm:items-end`,children:[(0,K.jsx)(h,{label:`Statement file`,children:(0,K.jsx)(g,{type:`file`,accept:`.csv,.xlsx,.xls,.pdf`,onChange:e=>(i(e.target.files?.[0]??null),b(null))})}),E&&(0,K.jsx)(h,{label:`CAS password`,hint:`Usually your PAN in capitals`,children:(0,K.jsx)(g,{type:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`off`})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(C,{icon:`search`,loading:l,disabled:!r,onClick:k,children:`Check`}),(0,K.jsx)(C,{variant:`ghost`,onClick:t,children:`Close`})]})]}),y&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-sm`,children:[(0,K.jsxs)(`span`,{className:`rounded-md bg-up-soft px-2 py-1 text-up`,children:[y.matches.length,` match`]}),(0,K.jsxs)(`span`,{className:d(`rounded-md px-2 py-1`,y.breaks.length?`bg-down-soft text-down`:`bg-raised text-muted`),children:[y.breaks.length,` mismatch`,y.breaks.length===1?``:`es`]}),y.cost_differences.length>0&&(0,K.jsxs)(`span`,{className:`rounded-md bg-raised px-2 py-1 text-muted`,children:[y.cost_differences.length,` cost difference`,y.cost_differences.length===1?``:`s`]}),(0,K.jsxs)(`span`,{className:`px-1 py-1 text-xs text-faint`,children:[y.rows_read,` lines read from the `,y.kind===`cas`?`CAS (mutual funds only)`:`broker statement (Indian stocks and ETFs only)`]})]}),y.ledger.length>0&&(0,K.jsx)(T,{tone:`warn`,title:`Your holdings and transaction history disagree`,children:y.ledger.map(e=>(0,K.jsxs)(`div`,{children:[e.symbol?`${e.symbol}: `:``,e.issue,e.stored!=null&&` (holding ${Z(e.stored)}, history ${Z(e.from_history)})`]},`${e.symbol}`))}),y.unresolved.length>0&&(0,K.jsxs)(T,{tone:`warn`,title:`${y.unresolved.length} statement line${y.unresolved.length===1?``:`s`} not recognised`,children:[y.unresolved.map(e=>`${e.name||e.symbol}${e.isin?` (${e.isin})`:``}: ${Z(e.quantity)}`).join(` · `),`. Add these by hand if you hold them.`]}),y.breaks.length===0?(0,K.jsx)(`p`,{className:`rounded-lg bg-up-soft px-4 py-3 text-sm text-up`,children:`Everything on the statement agrees with this portfolio.`}):(0,K.jsxs)(`div`,{className:`space-y-3`,children:[y.breaks.map(e=>(0,K.jsxs)(`div`,{className:`rounded-lg border border-line p-3`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`font-mono text-sm font-semibold`,children:e.symbol}),e.name&&(0,K.jsx)(`span`,{className:`ms-2 text-xs text-muted`,children:e.name}),(0,K.jsx)(`span`,{className:`ms-2 rounded bg-raised px-1.5 py-0.5 text-[11px] text-muted`,children:Je[e.kind]})]}),(0,K.jsxs)(`div`,{className:`tabular text-xs text-muted`,children:[`Statement `,Z(e.statement_qty),` · MarketMyna `,Z(e.app_qty)]})]}),(0,K.jsx)(`p`,{className:`mt-1 text-xs text-muted`,children:e.cause}),(0,K.jsx)(`div`,{className:`mt-2 space-y-1.5`,children:e.fixes.map((t,n)=>{let r=S[D(e,n)]??{on:!1,price:``};return(0,K.jsxs)(`label`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`accent-accent`,checked:r.on,onChange:t=>w(i=>({...i,[D(e,n)]:{...r,on:t.target.checked}}))}),(0,K.jsxs)(`span`,{children:[Ye[t.type],`: `,t.type===`split`?`${o(t.quantity,2)} shares per old share`:Z(t.quantity),` on `,t.date]}),t.type!==`split`&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted`,children:`at`}),(0,K.jsx)(g,{type:`number`,min:`0`,step:`any`,className:`h-8 w-28`,value:r.price,onChange:t=>w(i=>({...i,[D(e,n)]:{...r,price:t.target.value}}))}),t.needs_price&&(0,K.jsx)(`span`,{className:`text-xs text-warn`,children:`check the price`})]})]},n)})})]},e.symbol)),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,K.jsxs)(C,{icon:`check`,loading:p,disabled:!j,onClick:A,children:[`Add `,j,` ticked entr`,j===1?`y`:`ies`]}),(0,K.jsx)(`span`,{className:`text-xs text-faint`,children:`Nothing changes until you add them. Each becomes a normal transaction you can delete later.`})]})]}),y.cost_differences.length>0&&(0,K.jsxs)(`details`,{className:`text-xs text-muted`,children:[(0,K.jsxs)(`summary`,{className:`cursor-pointer`,children:[`Average cost differs on `,y.cost_differences.length,` matched holding`,y.cost_differences.length===1?``:`s`,` (information only)`]}),(0,K.jsx)(`ul`,{className:`mt-2 space-y-1`,children:y.cost_differences.map(e=>(0,K.jsxs)(`li`,{className:`tabular`,children:[(0,K.jsx)(`span`,{className:`font-mono`,children:e.symbol}),`: statement `,o(e.statement_avg,2),`, MarketMyna `,o(e.app_avg,2)]},e.symbol))}),(0,K.jsx)(`p`,{className:`mt-1`,children:y.cost_differences[0].cause})]})]})]})]})}var Q=[`#6d8cff`,`#34d399`,`#fbbf24`,`#f472b6`,`#22d3ee`,`#a78bfa`,`#fb923c`,`#94a3b8`];function Ze({portfolio:e,version:t}){let[n,r]=(0,G.useState)(null),[i,s]=(0,G.useState)(null);(0,G.useEffect)(()=>{let t=!1;return s(null),ye(e).then(e=>!t&&r(e)).catch(e=>!t&&s(a(e))),()=>{t=!0}},[e,t]);let c=n?.grade===`Good`?`text-up`:n?.grade===`Fair`?`text-warn`:`text-down`;return(0,K.jsxs)(v,{id:`section-fund-health`,section:`Fund health check`,children:[(0,K.jsx)(x,{title:`Mutual fund health check`,description:`Mix, duplicate categories and funds that move together`,icon:`portfolio`}),(0,K.jsx)(m,{className:`space-y-5`,children:i?(0,K.jsx)(`p`,{className:`text-sm text-down`,children:i}):n?n.funds===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No mutual funds in this portfolio.`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-8 gap-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-xs text-faint`,children:`Score`}),(0,K.jsxs)(`div`,{className:`tabular text-2xl font-semibold`,children:[n.score,(0,K.jsx)(`span`,{className:`text-sm text-faint`,children:`/100`}),` `,(0,K.jsx)(`span`,{className:d(`text-sm`,c),children:n.grade})]})]}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`mb-1.5 text-xs text-faint`,children:`Asset mix`}),(0,K.jsx)(`div`,{className:`flex h-2.5 overflow-hidden rounded-full`,children:n.asset_classes.map((e,t)=>(0,K.jsx)(`div`,{title:`${e.name} ${o(e.weight*100,1)}%`,style:{width:`${e.weight*100}%`,background:Q[t%Q.length]}},e.name))}),(0,K.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted`,children:n.asset_classes.map((e,t)=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`h-2 w-2 rounded-sm`,style:{background:Q[t%Q.length]}}),e.name,` `,(0,K.jsxs)(`span`,{className:`tabular`,children:[o(e.weight*100,0),`%`]})]},e.name))})]})]}),n.issues.length>0?(0,K.jsx)(`ul`,{className:`space-y-2`,children:n.issues.map(e=>(0,K.jsx)(`li`,{className:`rounded-lg bg-canvas px-3 py-2 text-sm`,children:e},e))}):(0,K.jsx)(`p`,{className:`rounded-lg bg-up-soft px-3 py-2 text-sm text-up`,children:`No overlap or cost issues found.`}),(0,K.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-muted`,children:`By category`}),(0,K.jsx)(`table`,{className:`tabular w-full text-sm`,children:(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:n.categories.map(e=>(0,K.jsxs)(`tr`,{children:[(0,K.jsxs)(`td`,{className:`py-1.5`,children:[e.name,e.count>1&&(0,K.jsxs)(`span`,{className:`text-warn`,children:[` ×`,e.count]})]}),(0,K.jsxs)(`td`,{className:`py-1.5 text-end`,children:[o(e.weight*100,1),`%`]})]},e.name))})})]}),n.similar_pairs.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-muted`,children:`Funds that move together (1y daily NAV)`}),(0,K.jsx)(`table`,{className:`tabular w-full text-sm`,children:(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:n.similar_pairs.map(e=>(0,K.jsxs)(`tr`,{children:[(0,K.jsxs)(`td`,{className:`py-1.5`,children:[e.a_name,` `,(0,K.jsx)(`span`,{className:`text-faint`,children:`&`}),` `,e.b_name]}),(0,K.jsx)(`td`,{className:d(`py-1.5 text-end`,e.correlation>=.95&&`text-warn`),children:o(e.correlation)})]},`${e.a}-${e.b}`))})})]})]}),(0,K.jsxs)(`p`,{className:`text-xs text-faint`,children:[n.method,` Not investment advice.`]})]}):(0,K.jsx)(D,{className:`h-32 w-full`})})]})}var Qe=[{key:`mix`,label:`Asset mix`},{key:`overlap`,label:`Overlap`},{key:`concentration`,label:`Concentration`},{key:`risk`,label:`Risk`}];function $e({portfolio:e,version:t}){let[n,r]=(0,G.useState)(null),[i,s]=(0,G.useState)(null),[c,l]=(0,G.useState)(!1),[u,d]=(0,G.useState)(`${e}|${t}`);u!==`${e}|${t}`&&(d(`${e}|${t}`),r(null),s(null));let f=(t=!1)=>{l(!0),s(null),Ae(e,t).then(r).catch(e=>s(a(e))).finally(()=>l(!1))};return(0,K.jsxs)(v,{id:`section-fund-ai`,section:`AI portfolio review`,children:[(0,K.jsx)(x,{title:(0,K.jsx)(`span`,{className:`flex items-center gap-2`,children:`AI portfolio review`}),description:`The AI reads your funds' mix, overlap, the stocks and sectors underneath, and each fund's role`,icon:`cpu`,actions:n?(0,K.jsx)(C,{variant:`ghost`,size:`sm`,icon:`refresh`,loading:c,onClick:()=>f(!0),children:`Refresh`}):(0,K.jsx)(C,{size:`sm`,icon:`cpu`,loading:c,onClick:()=>f(),children:c?`Reading your funds…`:`Run AI review`})}),(0,K.jsxs)(m,{className:`space-y-5`,children:[i&&(0,K.jsx)(`p`,{className:`text-xs text-down`,children:i}),!n&&!i&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:c?`Reading every fund’s holdings and asking the AI. With many funds this can take a minute or two.`:`Run it for a plain-language read of how your fund portfolio is built.`}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-sm leading-relaxed`,children:n.summary}),(n.strengths.length>0||n.concerns.length>0)&&(0,K.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,K.jsx)(ee,{title:`Strengths`,tone:`text-up`,items:n.strengths}),(0,K.jsx)(ee,{title:`Watch out for`,tone:`text-warn`,items:n.concerns})]}),Qe.some(e=>n.sections[e.key])&&(0,K.jsx)(`dl`,{className:`divide-y divide-line rounded-lg bg-canvas px-4`,children:Qe.filter(e=>n.sections[e.key]).map(e=>(0,K.jsxs)(`div`,{className:`grid gap-1 py-2.5 sm:grid-cols-[9rem_minmax(0,1fr)] sm:gap-4`,children:[(0,K.jsx)(`dt`,{className:`text-xs font-medium text-muted`,children:e.label}),(0,K.jsx)(`dd`,{className:`text-sm`,children:n.sections[e.key]})]},e.key))}),n.look_through?.top_sectors_of_portfolio?.length?(0,K.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,K.jsx)(et,{title:`Biggest sectors across your funds`,items:n.look_through.top_sectors_of_portfolio}),(0,K.jsx)(et,{title:`Biggest stocks across your funds`,items:n.look_through.top_stocks_of_portfolio??[]}),n.look_through.covered_pct!=null&&n.look_through.covered_pct<95&&(0,K.jsxs)(`p`,{className:`text-[12px] text-faint sm:col-span-2`,children:[`Holdings were available for funds making up `,o(n.look_through.covered_pct,0),`% of the portfolio.`]})]}):n.look_through?.covered_pct!=null&&(0,K.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Stocks and sectors across your funds are left out: holdings are known for only `,o(n.look_through.covered_pct,0),`% of the portfolio.`]}),n.funds.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`mb-1.5 text-xs font-semibold text-muted`,children:`Each fund's role`}),(0,K.jsx)(`ul`,{className:`divide-y divide-line`,children:n.funds.map(e=>(0,K.jsxs)(`li`,{className:`grid gap-1 py-2 sm:grid-cols-[minmax(0,16rem)_minmax(0,1fr)] sm:gap-4`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`truncate text-sm font-medium`,title:e.name??e.code,children:e.name??e.code}),e.weight_pct!=null&&(0,K.jsxs)(`div`,{className:`text-xs text-faint`,children:[o(e.weight_pct,1),`% of the portfolio`]})]}),(0,K.jsx)(`p`,{className:`text-sm text-fg/90`,children:e.note})]},e.code))})]}),(0,K.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`AI-generated from past data on `,n.generated_at,`; it can be wrong.`,` An explanation of your portfolio, not a recommendation.`]})]})]})]})}function et({title:e,items:t}){return t.length?(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`mb-1.5 text-xs font-medium text-muted`,children:e}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,K.jsx)(`span`,{className:`rounded-md bg-canvas px-2 py-1 text-xs text-muted ring-1 ring-line ring-inset`,children:e},e))})]}):null}var $=e=>e==null?`—`:`₹${e.toLocaleString(`en-IN`,{maximumFractionDigits:0})}`;function tt(e){let t=e.lumpsum;return t.status!==`ok`||!t.level?null:{text:`Dip check: ${t.met} of ${t.total}`,className:`bg-raised text-fg`}}function nt({portfolio:e,version:t}){let[n,r]=(0,G.useState)(null),[i,s]=(0,G.useState)(null),[l,f]=(0,G.useState)(null),[p,h]=(0,G.useState)(null);(0,G.useEffect)(()=>{Se(e).then(h,()=>h(null))},[e]);async function g(t){let n=p;p&&h({...p,...t});try{h(await Ce(e,t))}catch(e){h(n),u.error(a(e))}}return(0,G.useEffect)(()=>{let t=!1;return r(null),s(null),be(e).then(e=>!t&&r(e),e=>!t&&s(a(e))),()=>{t=!0}},[e,t]),(0,K.jsxs)(v,{id:`section-funds`,section:`Mutual funds`,children:[(0,K.jsx)(x,{title:`Mutual fund portfolio`,icon:`portfolio`,description:`Returns, best SIP day and a dip check for the funds you hold`}),(0,K.jsxs)(m,{className:`space-y-5`,children:[i&&(0,K.jsx)(`p`,{className:`text-sm text-down`,children:i}),!n&&!i&&(0,K.jsx)(ie,{className:`min-h-48`,steps:[`Reading each fund’s full NAV history…`,`Working out your returns (XIRR)…`,`Checking each fund’s dip against its own past…`]}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[[`Invested`,$(n.total.invested)],[`Value now`,$(n.total.value)],[`Gain`,$(n.total.gain)],[`Your return (XIRR)`,n.total.xirr_pct==null?`—`:`${o(n.total.xirr_pct,1)}% a year`]].map(([e,t])=>(0,K.jsxs)(`div`,{className:`rounded-lg bg-canvas px-3 py-2`,children:[(0,K.jsx)(`div`,{className:`text-xs text-muted`,children:e}),(0,K.jsx)(`div`,{className:`tabular text-base font-semibold`,children:t})]},e))}),p&&(0,K.jsx)(at,{portfolio:e,rules:p,onChange:g}),(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`tabular w-full min-w-[46rem] text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-xs text-muted`,children:(0,K.jsxs)(`tr`,{className:`border-b border-line`,children:[(0,K.jsx)(`th`,{className:`py-2 text-start font-medium`,children:`Fund`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Value`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`Gain`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,children:`XIRR`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,title:`How far the NAV is below its highest NAV`,children:`Below high`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-start font-medium`,children:`Dip check`}),(0,K.jsx)(`th`,{className:`px-2 py-2 text-end font-medium`,title:`Historically best SIP day`,children:`SIP day`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:n.funds.map(t=>{let n=tt(t),r=l===t.code;return(0,K.jsxs)(G.Fragment,{children:[(0,K.jsxs)(`tr`,{className:d(`cursor-pointer hover:bg-raised`,r&&`bg-raised`),onClick:()=>f(r?null:t.code),children:[(0,K.jsxs)(`td`,{className:`max-w-[18rem] py-2 pe-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(y,{name:`chevron`,className:d(`h-3.5 w-3.5 shrink-0 text-faint transition-transform`,r&&`rotate-90`)}),(0,K.jsx)(`span`,{className:`truncate font-medium`,title:t.name,children:t.name})]}),(0,K.jsx)(`div`,{className:`truncate ps-5 text-xs text-faint`,children:t.category})]}),(0,K.jsx)(`td`,{className:`px-2 py-2 text-end`,children:$(t.value)}),(0,K.jsx)(`td`,{className:d(`px-2 py-2 text-end`,t.gain>=0?`text-up`:`text-down`),children:c(t.gain_pct,1)}),(0,K.jsx)(`td`,{className:`px-2 py-2 text-end`,children:t.xirr_pct==null?`—`:`${o(t.xirr_pct,1)}%`}),(0,K.jsx)(`td`,{className:`px-2 py-2 text-end`,children:t.lumpsum.below_high==null?`—`:`${o(-t.lumpsum.below_high*100,1)}%`}),(0,K.jsx)(`td`,{className:`px-2 py-2`,children:n?(0,K.jsx)(`span`,{className:d(`whitespace-nowrap rounded-md px-2 py-0.5 text-xs font-medium`,n.className),children:n.text}):(0,K.jsx)(`span`,{className:`text-xs text-faint`,children:t.asset_class===`Debt`?`Debt fund`:`—`})}),(0,K.jsx)(`td`,{className:`px-2 py-2 text-end`,children:t.best_sip_day?ae(t.best_sip_day):`—`})]}),r&&(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:7,className:`bg-canvas px-4 py-3`,children:(0,K.jsx)(rt,{f:t,portfolio:e,rules:p,onRules:g})})})]},t.code)})})]})}),(0,K.jsxs)(`p`,{className:`text-[12px] text-faint`,children:[`Click a fund for the details. Each condition compares today with the fund’s own last 10 years of NAVs, not a fixed rule. XIRR uses your recorded buys and sells.`,` `,`Facts about past behaviour, not investment advice.`]})]})]})]})}function rt({f:e,portfolio:t,rules:n,onRules:r}){let i=e.lumpsum,[s,c]=(0,G.useState)(null),[l,u]=(0,G.useState)(null),[f,p]=(0,G.useState)(!1);async function m(){p(!0),u(null);try{c(await xe(t,e.code))}catch(e){u(a(e))}finally{p(!1)}}return i.status===`ok`?(0,K.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,K.jsx)(`ul`,{className:`space-y-1.5`,children:i.conditions?.map(e=>(0,K.jsxs)(`li`,{className:`flex gap-2`,children:[(0,K.jsx)(`span`,{className:d(`font-semibold`,e.pass?`text-up`:`text-faint`),children:e.pass?`✓`:`✗`}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`span`,{className:`font-medium`,children:e.label}),` `,(0,K.jsxs)(`span`,{className:`text-muted`,children:[`— `,e.detail]})]})]},e.key))}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-1 text-xs text-muted`,children:[i.turning!=null&&(0,K.jsx)(`span`,{children:i.turning?`↗ NAV has started rising again (last 10 days)`:`No upturn yet in the last 10 days`}),i.recovery_days!=null&&(0,K.jsxs)(`span`,{children:[`Past dips this deep took about `,Math.round(i.recovery_days/21),` months to get back to the high`]}),i.rsi!=null&&(0,K.jsxs)(`span`,{children:[`RSI `,o(i.rsi,0)]}),(0,K.jsxs)(`span`,{children:[`NAV as of `,i.as_of]})]}),n&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-t border-line pt-3 text-xs`,children:[(0,K.jsxs)(`span`,{className:`text-muted`,children:[`% alerts for this fund`,i.below_52w_high!=null&&` (now ${o(-i.below_52w_high*100,1)}% below its 52-week high)`,`:`]}),(0,K.jsx)(it,{choices:n.choices,selected:n.overrides[e.code]??n.levels,onChange:t=>r({levels:n.levels,overrides:{...n.overrides,[e.code]:t}})}),e.code in n.overrides?(0,K.jsx)(`button`,{type:`button`,className:`text-muted underline hover:text-fg`,onClick:()=>{let{[e.code]:t,...i}=n.overrides;r({levels:n.levels,overrides:i})},children:`Use portfolio setting`}):(0,K.jsx)(`span`,{className:`text-faint`,children:`same as the portfolio`})]}),(0,K.jsxs)(`div`,{className:`border-t border-line pt-3`,children:[!s&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,K.jsx)(C,{size:`sm`,variant:`secondary`,icon:`cpu`,loading:f,onClick:m,children:`AI review`}),(0,K.jsx)(`span`,{className:`text-xs text-faint`,children:`Asks your AI model to explain this dip in plain words.`})]}),l&&(0,K.jsx)(`p`,{className:`mt-2 text-xs text-down`,children:l}),s&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:`AI review`}),(0,K.jsx)(`p`,{className:`text-sm`,children:s.summary}),s.reasons.length>0&&(0,K.jsx)(`ul`,{className:`list-disc space-y-0.5 ps-5 text-xs text-muted`,children:s.reasons.map(e=>(0,K.jsx)(`li`,{children:e},e))}),s.risk&&(0,K.jsxs)(`p`,{className:`text-xs text-warn`,children:[`Risk: `,s.risk]})]})]})]}):(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:i.reason})}function it({choices:e,selected:t,onChange:n}){return(0,K.jsx)(`span`,{className:`inline-flex flex-wrap gap-1.5`,children:e.map(e=>{let r=t.includes(e);return(0,K.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>n(r?t.filter(t=>t!==e):[...t,e].sort((e,t)=>e-t)),className:d(`rounded-full border px-2.5 py-0.5 text-xs font-medium transition-colors`,r?`border-accent bg-accent-soft text-fg`:`border-line text-muted hover:border-line-strong hover:text-fg`),children:[e,`%`]},e)})})}function at({portfolio:e,rules:t,onChange:n}){let[r,i]=(0,G.useState)(!1);async function o(){i(!0);try{let t=await we(e);u.success(`Test alert sent for ${t.fund}`)}catch(e){u.error(a(e))}finally{i(!1)}}let s=Object.keys(t.overrides).length;return(0,K.jsxs)(`div`,{className:`rounded-lg border border-line px-4 py-3`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium`,children:`Dip alerts`}),(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Alert me when a fund falls this far below its 52-week high. Pick one or more; each level alerts once per dip and re-arms when the fund gets back near its high.`})]}),(0,K.jsx)(C,{size:`sm`,variant:`secondary`,icon:`send`,loading:r,onClick:o,children:`Send test alert`})]}),(0,K.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(it,{choices:t.choices,selected:t.levels,onChange:e=>n({levels:e,overrides:t.overrides})}),(0,K.jsxs)(`span`,{className:`text-xs text-faint`,children:[t.levels.length?`for every fund in this portfolio`:`off`,s>0&&` · ${s} fund${s>1?`s`:``} set separately`]})]})]})}var ot=[...ne,{value:`mf`,label:`Mutual fund`}],st=[{value:`buy`,label:`Buy`},{value:`sell`,label:`Sell`},{value:`dividend`,label:`Dividend`},{value:`split`,label:`Split / bonus`}],ct=[`#6d8cff`,`#34d399`,`#fbbf24`,`#f472b6`,`#22d3ee`,`#a78bfa`,`#fb923c`,`#94a3b8`];function lt(){let[e,t]=(0,G.useState)(null),[n,r]=(0,G.useState)(null),[i,o]=(0,G.useState)(null),s=i&&i.name===n?i:null,c=s?Object.values(s.holdings).map(e=>`${e.symbol}:${e.quantity}`).join(`,`):``,l=!!s&&Object.values(s.holdings).some(e=>e.market?.toLowerCase()===`mf`),f=(0,G.useRef)(0),[p,m]=(0,G.useState)(!1),[h,g]=(0,G.useState)(!1),[_,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),[T,E]=(0,G.useState)(0),O=(0,G.useRef)(null),[k,j]=A(),M=(0,G.useMemo)(()=>{let e=k.get(`add`);return e?{symbol:e,market:k.get(`market`)??`us`,price:k.get(`price`)??``}:null},[k]),N=(0,G.useCallback)(()=>j({},{replace:!0}),[j]),P=(0,G.useCallback)(async e=>{try{let n=await ce();t(n),r(t=>e??t??n[0]??null)}catch(e){t([]),u.error(a(e))}},[]),F=(0,G.useCallback)(async e=>{let t=++f.current;m(!0);try{let n=await le(e);t===f.current&&o(n)}catch(e){if(t!==f.current)return;o(null),u.error(a(e))}finally{t===f.current&&m(!1)}},[]);return(0,G.useEffect)(()=>{P()},[P]),(0,G.useEffect)(()=>{n&&F(n)},[n,F]),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(S,{title:`Portfolio`,description:`Holdings, live valuation and transaction entry.`,actions:(0,K.jsxs)(K.Fragment,{children:[n&&s&&(0,K.jsx)(se,{title:`Portfolio ${n}`,subtitle:`Currency ${s.currency}`,tables:()=>vt(s)}),n&&(0,K.jsx)(C,{variant:`secondary`,icon:`refresh`,loading:p,onClick:()=>F(n),children:`Refresh prices`}),(0,K.jsx)(C,{icon:`plus`,onClick:()=>g(!0),children:`New portfolio`})]})}),h&&(0,K.jsx)(ut,{existing:e??[],onCancel:()=>g(!1),onCreated:e=>{g(!1),P(e)}}),e==null?(0,K.jsx)(D,{className:`h-40 w-full`}):e.length===0?!h&&(0,K.jsx)(v,{children:(0,K.jsx)(w,{icon:`portfolio`,title:`No portfolios yet`,description:M?`Create a portfolio first, then ${M.symbol} is ready to record.`:`Create your own portfolio, then record buys and sells to track value and unrealized P/L.`,action:(0,K.jsx)(C,{icon:`plus`,onClick:()=>g(!0),children:`New portfolio`})})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`mb-5 flex gap-1 overflow-x-auto border-b border-line`,children:e.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>r(e),className:d(`-mb-px shrink-0 border-b-2 px-3 py-2 text-sm font-medium`,e===n?`border-accent text-fg`:`border-transparent text-muted hover:text-fg`),children:e},e))}),n&&(0,K.jsx)(mt,{name:n,existing:e,onRenamed:(e,t)=>{o(t),P(e)},onImport:()=>y(e=>!e),onReconcile:()=>x(e=>!e),onAddFund:()=>{E(e=>e+1),setTimeout(()=>document.getElementById(`tx-form`)?.scrollIntoView({behavior:`smooth`,block:`center`}),50)},onDeleted:()=>{o(null),r(null),P()}},n),_&&n&&s&&(0,K.jsx)(Ke,{portfolio:n,currency:s.currency,onCancel:()=>y(!1),onImported:e=>{o(e),y(!1)}},n),b&&n&&(0,K.jsx)(Xe,{portfolio:n,onCancel:()=>x(!1),onApplied:e=>o(e)},n),s&&n?(0,K.jsxs)(`div`,{className:`flex flex-col gap-6 xl:grid xl:grid-cols-[minmax(0,1fr)_340px]`,children:[(0,K.jsxs)(`div`,{ref:O,className:`contents xl:block xl:min-w-0 xl:space-y-6`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[(0,K.jsx)(dt,{summary:s}),(0,K.jsx)(pt,{summary:s}),Object.keys(s.holdings).length>0&&(0,K.jsx)(Ve,{portfolio:n,version:`${c}|${s.cash_balance}`})]}),(0,K.jsxs)(`div`,{className:`order-2 min-w-0 space-y-6 xl:order-none`,children:[Object.keys(s.holdings).length>0&&(0,K.jsx)(Me,{portfolio:n,currency:s.currency,version:c}),l&&(0,K.jsx)(nt,{portfolio:n,version:c}),l&&(0,K.jsx)(Ze,{portfolio:n,version:c}),l&&(0,K.jsx)($e,{portfolio:n,version:c}),(0,K.jsx)(ht,{summary:s,onChanged:o})]})]}),(0,K.jsx)(`aside`,{className:`order-1 min-w-0 xl:order-none`,children:(0,K.jsxs)(`div`,{className:`z-10 flex flex-col gap-6 xl:sticky xl:top-8 xl:max-h-[calc(100vh-4rem)] [@media(max-height:800px)]:static [@media(max-height:800px)]:max-h-none`,children:[Object.keys(s.holdings).length>0&&(0,K.jsx)(`div`,{className:`hidden min-h-36 flex-col xl:flex`,children:(0,K.jsx)(V,{root:O,fill:!0},n)}),(0,K.jsx)(_t,{portfolio:n,prefill:M,fundMode:T>0,onSaved:e=>{o(e),M&&N()}},M?`${n}:${M.symbol}`:`${n}:${T}`)]})})]}):(0,K.jsx)(D,{className:`h-64 w-full`})]})]})}function ut({existing:e,onCancel:t,onCreated:n}){let[r,i]=(0,G.useState)(``),[o,s]=(0,G.useState)(`USD`),[c,l]=(0,G.useState)(`stocks`),[d,f]=(0,G.useState)(!1),m=r.trim(),_=e.includes(m);async function y(){if(m&&!_){f(!0);try{await ue(m,o,c),u.success(`Portfolio “${m}” created`),n(m)}catch(e){u.error(a(e))}finally{f(!1)}}}return(0,K.jsx)(v,{className:`mb-6`,children:(0,K.jsxs)(`form`,{className:`grid items-end gap-4 p-5 sm:grid-cols-[minmax(0,1fr)_160px_140px_auto]`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,K.jsx)(h,{label:`Portfolio name`,children:(0,K.jsx)(g,{value:r,onChange:e=>i(e.target.value),placeholder:`e.g. Ravi - Long term`,maxLength:60,autoFocus:!0,"aria-describedby":`portfolio-name-hint`})}),(0,K.jsx)(`p`,{id:`portfolio-name-hint`,className:`-mt-2 text-xs text-faint sm:order-last sm:col-span-4`,children:_?(0,K.jsx)(`span`,{className:`text-down`,children:`Name already exists`}):`Put your name in it so others know it is yours. Free includes one stocks and one mutual fund portfolio.`}),(0,K.jsx)(h,{label:`Holds`,children:(0,K.jsx)(p,{options:[{value:`stocks`,label:`Stocks`},{value:`funds`,label:`Mutual funds`}],value:c,onChange:e=>l(e.target.value)})}),(0,K.jsx)(h,{label:`Base currency`,children:(0,K.jsx)(p,{options:re.map(e=>({value:e,label:e})),value:o,onChange:e=>s(e.target.value)})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(C,{variant:`ghost`,onClick:t,children:`Cancel`}),(0,K.jsx)(C,{type:`submit`,loading:d,disabled:!m||_,children:`Create`})]})]})})}function dt({summary:e}){let n=e.currency;return(0,K.jsx)(v,{id:`section-summary`,section:`Summary`,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-6 p-5 md:grid-cols-5`,children:[(0,K.jsx)(E,{label:`Total value`,value:t(e.total_value,n)}),(0,K.jsx)(E,{label:`Market value`,value:t(e.total_market_value,n)}),(0,K.jsx)(E,{label:`Cost basis`,value:t(e.total_cost_basis,n)}),(0,K.jsx)(E,{label:`Unrealized P/L`,value:(0,K.jsx)(`span`,{className:i(e.total_unrealized_gain),children:r(e.total_unrealized_gain)}),sub:c(e.total_unrealized_gain_percent),subClassName:i(e.total_unrealized_gain)}),(0,K.jsx)(E,{label:`Cash`,value:t(e.cash_balance,n)})]})})}function ft(e){let t=encodeURIComponent(e.symbol);return e.market?.toLowerCase()===`mf`?`/analyze?view=funds&symbol=${t}&market=india`:`/analyze?symbol=${t}&market=${encodeURIComponent((e.market||`us`).toLowerCase())}`}function pt({summary:e}){let t=j(),[n,a]=(0,G.useState)({key:`market_value`,dir:-1}),s=(0,G.useMemo)(()=>{let t=e.total_market_value||0;return Object.values(e.holdings).map(e=>({...e,weight:t?(e.market_value??0)/t*100:0})).sort((e,t)=>{let r=e[n.key]??0,i=t[n.key]??0;return(typeof r==`string`?r.localeCompare(String(i)):Number(r)-Number(i))*n.dir})},[e,n]);function l(e,t,r=`right`){let i=n.key===e;return(0,K.jsx)(`th`,{className:d(`px-3 py-2.5 font-medium`,r===`right`?`text-end`:`text-start`),children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a({key:e,dir:i?n.dir===1?-1:1:-1}),className:d(`inline-flex items-center gap-1 hover:text-fg`,i&&`text-fg`),children:[t,i&&(0,K.jsx)(`span`,{className:`text-[12px]`,children:n.dir===1?`▲`:`▼`})]})})}return(0,K.jsxs)(v,{id:`section-holdings`,section:`Holdings`,className:`min-w-0`,children:[(0,K.jsx)(x,{title:`Holdings`,description:`${s.length} position${s.length===1?``:`s`}`}),s.length===0?(0,K.jsx)(w,{icon:`portfolio`,title:`No holdings`,description:`Record a Buy transaction to open a position.`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex h-2 overflow-hidden rounded-none`,children:s.map((e,t)=>(0,K.jsx)(`div`,{title:`${e.name??e.symbol} ${o(e.weight,1)}%`,style:{width:`${e.weight}%`,background:ct[t%ct.length]}},e.symbol))}),(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`tabular w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-xs text-muted`,children:(0,K.jsxs)(`tr`,{className:`border-b border-line`,children:[l(`symbol`,`Symbol`,`left`),(0,K.jsx)(`th`,{className:`px-3 py-2.5 text-end font-medium`,children:`Qty`}),(0,K.jsx)(`th`,{className:`px-3 py-2.5 text-end font-medium`,children:`Avg cost`}),(0,K.jsx)(`th`,{className:`px-3 py-2.5 text-end font-medium`,children:`Price`}),l(`market_value`,`Value`),l(`weight`,`Weight`),l(`unrealized_gain`,`P/L`),l(`unrealized_gain_percent`,`P/L %`)]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:s.map((e,n)=>(0,K.jsxs)(`tr`,{className:`cursor-pointer hover:bg-raised/40`,title:`Open in Analyze`,onClick:n=>{n.target.closest(`a`)||t(ft(e))},children:[(0,K.jsx)(`td`,{className:`px-3 py-2.5`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`h-2 w-2 rounded-sm`,style:{background:ct[n%ct.length]}}),e.market?.toLowerCase()===`mf`?(0,K.jsxs)(k,{to:ft(e),className:`group min-w-0`,title:`${e.name??e.symbol} · AMFI ${e.symbol} · open the fund analysis`,children:[(0,K.jsx)(`span`,{className:`block max-w-56 truncate font-medium group-hover:text-accent-fg`,children:e.name??e.symbol}),(0,K.jsx)(`span`,{className:`block text-xs text-faint`,children:e.category?.replace(/ Scheme - /,` · `)||`Mutual fund`})]}):(0,K.jsx)(k,{to:ft(e),className:`font-mono font-medium hover:text-accent-fg`,title:`Open in Analyze`,children:e.symbol})]})}),(0,K.jsx)(`td`,{className:`px-3 py-2.5 text-end`,children:o(e.quantity,e.quantity%1?4:0)}),(0,K.jsx)(`td`,{className:`px-3 py-2.5 text-end text-muted`,children:o(e.avg_cost)}),(0,K.jsx)(`td`,{className:`px-3 py-2.5 text-end`,children:o(e.current_price)}),(0,K.jsx)(`td`,{className:`px-3 py-2.5 text-end`,children:o(e.market_value)}),(0,K.jsxs)(`td`,{className:`px-3 py-2.5 text-end text-muted`,children:[o(e.weight,1),`%`]}),(0,K.jsx)(`td`,{className:d(`px-3 py-2.5 text-end`,i(e.unrealized_gain)),children:r(e.unrealized_gain)}),(0,K.jsx)(`td`,{className:d(`px-3 py-2.5 text-end`,i(e.unrealized_gain_percent)),children:c(e.unrealized_gain_percent)})]},e.symbol))})]})})]})]})}function mt({name:e,existing:t,onRenamed:n,onDeleted:r,onImport:i,onReconcile:o,onAddFund:s}){let[c,l]=(0,G.useState)(!1),[d,f]=(0,G.useState)(e),[p,m]=(0,G.useState)(!1),[h,_]=(0,G.useState)(!1),v=d.trim(),y=v!==e&&t.includes(v);async function b(){if(!v||y||v===e)return l(!1);_(!0);try{let t=await pe(e,v);u.success(`Renamed to “${v}”`),l(!1),n(v,t)}catch(e){u.error(a(e))}finally{_(!1)}}async function x(){_(!0);try{await me(e),u.success(`Portfolio “${e}” deleted`),r()}catch(e){u.error(a(e))}finally{_(!1)}}return(0,K.jsx)(`div`,{className:`mb-5 flex flex-wrap items-center gap-2`,children:c?(0,K.jsxs)(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,K.jsx)(g,{value:d,onChange:e=>f(e.target.value),maxLength:60,className:`h-8 w-64`,autoFocus:!0}),(0,K.jsx)(C,{type:`submit`,size:`sm`,loading:h,disabled:!v||y,children:`Save`}),(0,K.jsx)(C,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>(l(!1),f(e)),children:`Cancel`}),y&&(0,K.jsx)(`span`,{className:`text-xs text-down`,children:`Name already exists`})]}):p?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`text-sm text-down`,children:[`Delete “`,e,`” with all its holdings and transactions? This can't be undone.`]}),(0,K.jsx)(C,{size:`sm`,variant:`danger`,icon:`trash`,loading:h,onClick:x,children:`Yes, delete`}),(0,K.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>m(!1),children:`Keep it`})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(C,{size:`sm`,variant:`ghost`,icon:`pencil`,onClick:()=>l(!0),children:`Rename`}),(0,K.jsx)(C,{size:`sm`,variant:`ghost`,icon:`trash`,onClick:()=>m(!0),children:`Delete portfolio`}),(0,K.jsx)(C,{size:`sm`,variant:`ghost`,icon:`plus`,onClick:s,children:`Add mutual fund manually`}),(0,K.jsx)(C,{size:`sm`,variant:`ghost`,icon:`plus`,onClick:i,children:`Import mutual funds (CAS)`}),(0,K.jsx)(C,{size:`sm`,variant:`ghost`,icon:`check`,onClick:o,children:`Reconcile with statement`})]})})}function ht({summary:e,onChanged:t}){let[n,r]=(0,G.useState)(null),[i,s]=(0,G.useState)(!1),c=[...e.transactions??[]].reverse();async function l(n){s(!0);try{t(await he(e.name,n)),u.success(`Transaction removed - holdings recalculated`),r(null)}catch(e){u.error(a(e))}finally{s(!1)}}return(0,K.jsxs)(v,{id:`section-transactions`,section:`Transactions`,children:[(0,K.jsx)(x,{title:`Transactions`,description:`Entered something wrong? Delete it and the holdings are recalculated.`}),c.length===0?(0,K.jsx)(w,{icon:`portfolio`,title:`No transactions yet`,description:`Record a Buy to start.`}):(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-y border-line text-xs text-muted`,children:[(0,K.jsx)(`th`,{className:`px-5 py-2 text-start font-medium`,children:`Date`}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-start font-medium`,children:`Type`}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-start font-medium`,children:`Symbol`}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-end font-medium`,children:`Qty`}),(0,K.jsx)(`th`,{className:`px-3 py-2 text-end font-medium`,children:`Price`}),(0,K.jsx)(`th`,{className:`hidden px-3 py-2 text-end font-medium sm:table-cell`,children:`Total`}),(0,K.jsx)(`th`,{className:`hidden px-3 py-2 text-start font-medium md:table-cell`,children:`Notes`}),(0,K.jsx)(`th`,{className:`px-5 py-2`,"aria-label":`Actions`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:c.map(e=>(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`td`,{className:`tabular px-5 py-2.5 text-muted`,children:e.date?e.date.slice(0,10):`—`}),(0,K.jsx)(`td`,{className:d(`px-3 py-2.5 font-medium uppercase`,e.transaction_type===`buy`?`text-up`:e.transaction_type===`sell`?`text-down`:`text-muted`),children:e.transaction_type}),(0,K.jsx)(`td`,{className:`px-3 py-2.5 font-mono`,children:e.symbol}),(0,K.jsx)(`td`,{className:`tabular px-3 py-2.5 text-end`,children:o(e.quantity,0)}),(0,K.jsx)(`td`,{className:`tabular px-3 py-2.5 text-end`,children:o(e.price)}),(0,K.jsx)(`td`,{className:`tabular hidden px-3 py-2.5 text-end sm:table-cell`,children:o(e.total)}),(0,K.jsx)(`td`,{className:`hidden max-w-48 truncate px-3 py-2.5 text-muted md:table-cell`,title:e.notes,children:e.notes||`—`}),(0,K.jsx)(`td`,{className:`px-5 py-2.5 text-end whitespace-nowrap`,children:n===e.index?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,K.jsx)(C,{size:`sm`,variant:`danger`,loading:i,onClick:()=>l(e.index),children:`Delete`}),(0,K.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>r(null),children:`Cancel`})]}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>r(e.index),className:`rounded-md p-1.5 text-faint hover:bg-raised hover:text-down`,"aria-label":`Delete ${e.transaction_type} ${e.symbol}`,title:`Delete`,children:(0,K.jsx)(y,{name:`trash`})})})]},e.index))})]})})]})}function gt(){return new Date().toISOString().slice(0,10)}function _t({portfolio:e,prefill:t,fundMode:n=!1,onSaved:r}){let[i,s]=(0,G.useState)(`buy`),[c,l]=(0,G.useState)(t?.symbol??``),[d,f]=(0,G.useState)(t?.market??(n?`mf`:`us`)),[y,b]=(0,G.useState)(``),[S,w]=(0,G.useState)(t?.price??``),[T,E]=(0,G.useState)(``),[D,O]=(0,G.useState)(gt),[k,A]=(0,G.useState)(``),[j,M]=(0,G.useState)(!1),[N,P]=(0,G.useState)(``),[F,I]=(0,G.useState)(null),L=Number(y),R=Number(S),z=Number(T||0),B=i===`split`,V=c.trim()!==``&&L>0&&R>=0&&(S!==``||B)&&z>=0,ee=!V||i===`split`?null:i===`buy`?L*R+z:L*R-z,H=d===`mf`,te=i===`dividend`?`Amount per share`:H?`NAV`:`Price`,U=H&&(i===`buy`||i===`sell`),W=/^\d+$/.test(c.trim())?c.trim():``;(0,G.useEffect)(()=>{if(!U||!W||!D){I(null);return}let e=!1;return I(`loading`),fe(W,D).then(t=>{e||(w(String(t.nav)),I({date:t.nav_date}))}).catch(()=>!e&&I(`missing`)),()=>{e=!0}},[U,W,D]),(0,G.useEffect)(()=>{let e=Number(N),t=Number(S);if(!U||N===``||!(e>0)||!(t>0))return;let n=i===`buy`?e*.99995:e;b(String(Math.floor(n/t*1e3)/1e3))},[N,S,i,U]);async function ne(){if(V){M(!0);try{r(await de(e,{symbol:c.trim().toUpperCase(),transaction_type:i,quantity:L,price:R,fees:z,notes:k.trim(),market:d.toUpperCase(),date:D?new Date(`${D}T12:00:00`).toISOString():void 0})),u.success(`${i.toUpperCase()} ${L} ${c.trim().toUpperCase()} recorded`),l(``),b(``),w(``),E(``),A(``),P(``)}catch(e){u.error(a(e))}finally{M(!1)}}}return(0,K.jsxs)(v,{id:`tx-form`,className:`h-fit`,children:[(0,K.jsx)(x,{title:d===`mf`?`Add a mutual fund`:`Record transaction`,description:d===`mf`?`Into ${e} · units and NAV are on your fund statement or app`:`Into ${e}`,icon:`plus`}),(0,K.jsx)(m,{children:(0,K.jsxs)(`form`,{className:`space-y-4`,onSubmit:e=>{e.preventDefault(),ne()},children:[(0,K.jsx)(_,{options:st,value:i,onChange:e=>s(e),size:`sm`}),(0,K.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_120px] gap-3`,children:[(0,K.jsx)(h,{label:`Symbol`,children:(0,K.jsx)(oe,{value:c,onChange:l,onSelect:e=>{l(e.symbol),f(e.type===`mf`?`mf`:e.market)},type:d===`mf`?`mf`:`all`,autoFocus:n,placeholder:d===`mf`?`Search a fund, e.g. Parag Parikh Flexi Cap Direct`:`Search a stock, ETF or mutual fund`})}),(0,K.jsx)(h,{label:`Market`,children:(0,K.jsx)(p,{options:ot,value:d,onChange:e=>f(e.target.value)})})]}),U&&(0,K.jsx)(h,{label:i===`buy`?`Amount invested (₹)`:`Amount received (₹)`,hint:`Optional. Units are worked out from this and the NAV. Or type the units yourself below.`,children:(0,K.jsx)(g,{type:`number`,min:`0`,step:`any`,value:N,onChange:e=>P(e.target.value),placeholder:`e.g. 5000`})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsx)(h,{label:B?`Shares now per 1 old share`:H?`Units`:`Quantity`,hint:B?`5 for a 1:5 split, 2 for a 1:1 bonus`:U?N?`From the amount and NAV`:`On your statement or fund app`:void 0,children:(0,K.jsx)(g,{type:`number`,min:`0`,step:`any`,value:y,onChange:e=>{b(e.target.value),P(``)},placeholder:`0`})}),!B&&(0,K.jsx)(h,{label:te,hint:U?F===`loading`?`Looking up NAV…`:F===`missing`?`NAV not found, type it in`:F?`Official NAV of ${F.date}`:`Pick the fund and date first`:void 0,children:(0,K.jsx)(g,{type:`number`,min:`0`,step:`any`,value:S,onChange:e=>w(e.target.value),placeholder:`0.00`})}),!B&&(0,K.jsx)(h,{label:`Fees`,children:(0,K.jsx)(g,{type:`number`,min:`0`,step:`any`,value:T,onChange:e=>E(e.target.value),placeholder:`0.00`})}),(0,K.jsx)(h,{label:`Trade date`,children:(0,K.jsx)(g,{type:`date`,value:D,max:gt(),onChange:e=>O(e.target.value)})})]}),(0,K.jsx)(h,{label:`Notes`,hint:`Optional`,children:(0,K.jsx)(g,{value:k,onChange:e=>A(e.target.value),placeholder:`Reason, broker, lot…`})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg bg-canvas px-3 py-2.5 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-muted`,children:i===`buy`?`Total cost`:i===`split`?`Cash impact`:`Net proceeds`}),(0,K.jsx)(`span`,{className:`tabular font-semibold`,children:o(ee)})]}),(0,K.jsxs)(C,{type:`submit`,icon:`check`,className:`w-full`,loading:j,disabled:!V,children:[`Record `,i]})]})})]})}function vt(e){let t=e.total_market_value||0,n=Object.values(e.holdings).map(e=>({...e,display:e.market?.toLowerCase()===`mf`?e.name??e.symbol:e.symbol,weight:t?(e.market_value??0)/t*100:null}));return[{title:`Summary`,columns:[{key:`label`,label:`Item`},{key:`value`,label:`Value`,kind:`number`}],rows:[{label:`Market value`,value:e.total_market_value},{label:`Cost basis`,value:e.total_cost_basis},{label:`Unrealized P/L`,value:e.total_unrealized_gain},{label:`Unrealized P/L %`,value:e.total_unrealized_gain_percent},{label:`Cash`,value:e.cash_balance},{label:`Total value`,value:e.total_value}]},{title:`Holdings`,columns:[{key:`display`,label:`Holding`},{key:`symbol`,label:`Symbol / AMFI code`},{key:`market`,label:`Market`},{key:`category`,label:`Category`},{key:`quantity`,label:`Quantity`,kind:`number`,digits:4},{key:`avg_cost`,label:`Avg cost`,kind:`number`},{key:`current_price`,label:`Price`,kind:`number`},{key:`market_value`,label:`Value`,kind:`number`},{key:`weight`,label:`Weight %`,kind:`pct`},{key:`cost_basis`,label:`Cost`,kind:`number`},{key:`unrealized_gain`,label:`P/L`,kind:`number`},{key:`unrealized_gain_percent`,label:`P/L %`,kind:`pct`}],rows:n},{title:`Transactions`,columns:[{key:`date`,label:`Date`,kind:`date`},{key:`transaction_type`,label:`Type`},{key:`symbol`,label:`Symbol`},{key:`market`,label:`Market`},{key:`quantity`,label:`Quantity`,kind:`number`,digits:4},{key:`price`,label:`Price`,kind:`number`},{key:`fees`,label:`Fees`,kind:`number`},{key:`total`,label:`Total`,kind:`number`},{key:`notes`,label:`Notes`}],rows:e.transactions??[]}]}export{lt as default};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{b as t,c as n,n as r,o as i,p as a,s as o,u as s}from"./format-d8InM0Zw.js";import{D as c,f as l,g as u,i as d,n as f,p,r as m,t as h,y as g}from"./ui-gsFb8B2m.js";import{A as _,O as v,c as y}from"./index-CKAnq-Or.js";import{t as b}from"./listings-BefgXpb1.js";import{t as x}from"./exporter-DiMg2O5d.js";var S=e(t(),1),C=a(),w={india:`INR`,us:`USD`,china_a:`CNY`,hong_kong:`HKD`,crypto:`USD`},T=[{value:`all`,label:`All`},{value:`positive`,label:`Bullish`},{value:`mixed`,label:`Neutral`},{value:`negative`,label:`Bearish`}],E={positive:`▲ Bullish`,mixed:`◆ Neutral`,negative:`▼ Bearish`},D={positive:`up`,mixed:`warn`,negative:`down`};function O(e){return e.reading??`mixed`}function k(e){return e.price==null||e.normal_low==null||e.normal_high==null||e.normal_high<=e.normal_low?null:(e.price-e.normal_low)/(e.normal_high-e.normal_low)*100}function A(e,t){switch(t){case`symbol`:return e.symbol;case`change_percent`:return e.change_percent??-1/0;case`rsi`:return e.rsi??-1/0;case`band`:return k(e)??-1/0;default:return e.attention??-1/0}}var j=[`symbol`,`name`,`market`,`price`,`change_percent`,`reading`,`pe`,`normal_low`,`normal_high`,`week_low`,`week_high`,`rsi`,`trend`,`ai_summary`,`reasons`];function M(){let{token:e=``}=_(),[t,n]=(0,S.useState)(null),[i,a]=(0,S.useState)(null),[o,v]=(0,S.useState)(`all`),[b,w]=(0,S.useState)(``),[D,k]=(0,S.useState)({key:`attention`,desc:!0});(0,S.useEffect)(()=>{n(null),a(null),y(e).then(n).catch(e=>a(r(e)))},[e]);let M=(0,S.useMemo)(()=>(t?.rows??[]).filter(e=>!e.error),[t]),P=(0,S.useMemo)(()=>(t?.rows??[]).filter(e=>e.error),[t]),F=(0,S.useMemo)(()=>{let e={};return M.forEach(t=>e[O(t)]=(e[O(t)]??0)+1),e},[M]),I=(0,S.useMemo)(()=>{let e=b.trim().toLowerCase();return[...M.filter(t=>(o===`all`||O(t)===o)&&(!e||t.symbol.toLowerCase().includes(e)||(t.name??``).toLowerCase().includes(e)))].sort((e,t)=>{let n=A(e,D.key),r=A(t,D.key),i=typeof n==`string`?n.localeCompare(String(r)):n-r;return D.desc?-i:i})},[M,o,b,D]);function L(){t&&x(`csv`,`marketmyna-report`,[{title:`Smart report`,columns:j.map(e=>({key:e,label:e})),rows:t.rows}])}if(i)return(0,C.jsx)(h,{title:`Report not available`,children:i});if(!t)return(0,C.jsx)(g,{className:`h-96 w-full`});let R=(e,t,n=`right`)=>(0,C.jsx)(`th`,{className:c(`px-3 py-2 font-medium whitespace-nowrap`,n===`right`?`text-end`:`text-start`),children:(0,C.jsxs)(`button`,{type:`button`,className:c(`hover:text-fg`,D.key===e&&`text-fg`),onClick:()=>k(t=>({key:e,desc:t.key===e?!t.desc:e!==`symbol`})),children:[t,D.key===e?D.desc?` ↓`:` ↑`:``]})});return(0,C.jsxs)(`div`,{children:[(0,C.jsx)(p,{title:t.title,description:(0,C.jsxs)(C.Fragment,{children:[t.created_at&&s(t.created_at).toLocaleString(),` · `,M.length,` stocks analysed`,P.length>0&&`, ${P.length} unavailable`,`. Computed from market data, not investment advice.`]}),actions:(0,C.jsx)(m,{variant:`secondary`,size:`sm`,onClick:L,children:`Download CSV`})}),(0,C.jsx)(`div`,{className:`mb-4`,children:(0,C.jsx)(h,{tone:`accent`,title:`How to read this report`,children:`This report describes what the market data shows. It is not a recommendation to buy, sell or hold any stock. "Bullish" or "bearish" means most of the indicators we track (trend, momentum, where the price sits in its range, valuation) lean that way today; they can change quickly and are often wrong. Do your own research or speak to a SEBI-registered adviser before you invest.`})}),(0,C.jsx)(`div`,{className:`mb-4 grid grid-cols-3 gap-px overflow-hidden rounded-xl border border-line bg-line`,children:[`positive`,`mixed`,`negative`].map(e=>(0,C.jsxs)(`button`,{type:`button`,onClick:()=>v(o===e?`all`:e),className:c(`bg-surface px-4 py-3 text-start hover:bg-raised`,o===e&&`bg-raised`),children:[(0,C.jsx)(`div`,{className:`text-xs font-medium text-muted capitalize`,children:E[e]}),(0,C.jsx)(`div`,{className:c(`tabular text-lg font-semibold`,e===`positive`?`text-up`:e===`negative`?`text-down`:``),children:F[e]??0})]},e))}),(0,C.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-3`,children:[(0,C.jsx)(u,{options:T,value:o,onChange:v,size:`sm`}),(0,C.jsx)(l,{value:b,onChange:e=>w(e.target.value),placeholder:`Filter by symbol or name`,className:`w-full sm:w-64`})]}),(0,C.jsx)(d,{className:`overflow-hidden`,children:(0,C.jsx)(`div`,{className:`overflow-x-auto`,children:(0,C.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,C.jsx)(`thead`,{className:`border-b border-line text-xs text-muted`,children:(0,C.jsxs)(`tr`,{children:[R(`symbol`,`Stock`,`left`),(0,C.jsx)(`th`,{className:`px-3 py-2 text-start font-medium`,children:`Indicators`}),R(`change_percent`,`Price`),R(`band`,`Normal range`),(0,C.jsx)(`th`,{className:`px-3 py-2 text-end font-medium`,children:`P/E`}),(0,C.jsx)(`th`,{className:`px-3 py-2 text-end font-medium whitespace-nowrap`,children:`1-week range`}),R(`rsi`,`RSI`),R(`attention`,`What stands out`,`left`)]})}),(0,C.jsxs)(`tbody`,{className:`divide-y divide-line`,children:[I.map(e=>(0,C.jsx)(N,{row:e},`${e.market}:${e.symbol}`)),I.length===0&&(0,C.jsx)(`tr`,{children:(0,C.jsx)(`td`,{colSpan:8,className:`px-3 py-8 text-center text-xs text-muted`,children:`No stocks match.`})})]})]})})}),P.length>0&&(0,C.jsxs)(`details`,{className:`mt-4 rounded-lg border border-line px-3 py-2 text-xs text-muted`,children:[(0,C.jsxs)(`summary`,{className:`cursor-pointer`,children:[P.length,` stocks could not be analysed`]}),(0,C.jsx)(`ul`,{className:`mt-2 space-y-1`,children:P.map(e=>(0,C.jsxs)(`li`,{children:[(0,C.jsx)(`span`,{className:`font-mono text-fg`,children:e.symbol}),`: `,e.error]},e.symbol))})]}),(0,C.jsxs)(`div`,{className:`mt-6 grid gap-3 text-xs text-muted sm:grid-cols-2`,children:[(0,C.jsxs)(`p`,{children:[(0,C.jsx)(`b`,{className:`text-fg`,children:`Normal range`}),`: the 20-day Bollinger band, where the price usually trades. The bar shows where today's price sits in it; above the top is stretched, below the bottom is washed out.`]}),(0,C.jsxs)(`p`,{children:[(0,C.jsx)(`b`,{className:`text-fg`,children:`1-week range`}),`: where about two weeks in three end, from the last 60 days of volatility. A range, not a target.`]}),(0,C.jsxs)(`p`,{children:[(0,C.jsx)(`b`,{className:`text-fg`,children:`Indicators`}),`: how most of trend, momentum (RSI), where the price sits in its range and valuation lean today. It describes the data; it is not a buy, sell or hold call. Stocks marked`,` `,(0,C.jsx)(f,{tone:`accent`,children:`AI`}),` have an AI summary of their figures.`]})]})]})}function N({row:e}){let t=w[e.market],r=k(e),a=e.reading??`mixed`;return(0,C.jsxs)(`tr`,{className:`align-top hover:bg-raised/50`,children:[(0,C.jsxs)(`td`,{className:`px-3 py-2`,children:[(0,C.jsx)(v,{to:b(e),className:`font-mono font-medium hover:underline`,children:e.symbol}),e.name&&(0,C.jsx)(`div`,{className:`max-w-44 truncate text-xs text-muted`,children:e.name})]}),(0,C.jsxs)(`td`,{className:`px-3 py-2 whitespace-nowrap`,children:[(0,C.jsx)(f,{tone:D[a],children:E[a]}),e.ai&&(0,C.jsx)(`span`,{className:`ms-1`,children:(0,C.jsx)(f,{tone:`accent`,children:`AI`})})]}),(0,C.jsxs)(`td`,{className:`tabular px-3 py-2 text-end whitespace-nowrap`,children:[(0,C.jsx)(`div`,{children:n(e.price,t)}),(0,C.jsx)(`div`,{className:c(`text-xs`,(e.change_percent??0)>=0?`text-up`:`text-down`),children:o(e.change_percent)})]}),(0,C.jsxs)(`td`,{className:`tabular px-3 py-2 text-end whitespace-nowrap`,children:[(0,C.jsxs)(`div`,{className:`text-xs`,children:[n(e.normal_low,t),` – `,n(e.normal_high,t)]}),r!=null&&(0,C.jsx)(`div`,{className:`relative mt-1 ms-auto h-1.5 w-24 rounded-full bg-line`,title:`${i(r,0)}% of the range`,children:(0,C.jsx)(`span`,{className:c(`absolute top-1/2 h-2.5 w-1 -translate-y-1/2 rounded-full`,r>100?`bg-down`:r<0?`bg-up`:`bg-fg`),style:{left:`${Math.max(0,Math.min(100,r))}%`}})})]}),(0,C.jsx)(`td`,{className:`tabular px-3 py-2 text-end text-xs whitespace-nowrap`,children:e.pe==null?`—`:i(e.pe,1)}),(0,C.jsxs)(`td`,{className:`tabular px-3 py-2 text-end text-xs whitespace-nowrap`,children:[n(e.week_low,t),` – `,n(e.week_high,t)]}),(0,C.jsxs)(`td`,{className:`tabular px-3 py-2 text-end whitespace-nowrap`,children:[(0,C.jsx)(`div`,{className:c((e.rsi??50)>70&&`text-down`,(e.rsi??50)<30&&`text-up`),children:i(e.rsi,0)}),(0,C.jsx)(`div`,{className:`text-xs text-muted`,children:e.trend})]}),(0,C.jsx)(`td`,{className:`max-w-72 px-3 py-2 text-xs text-muted`,children:e.ai_summary||(e.reasons?.length?e.reasons.join(`, `):`—`)})]})}export{M as default};