tokentracker-cli 1.3.5 → 1.3.6
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.
- package/dashboard/dist/assets/{AchievementBadge-Dazs3pEa.js → AchievementBadge-CHDt55IP.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-LWnxZvmw.js → AchievementsPage-DpbRHmb8.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-BLqczmU9.js → AchievementsSection-Ck5CiX4P.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-B_n4aj2S.js → BadgeDetailModal-BVPqlh0X.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-KDWI_YcZ.js → BotAnimated-CVsv6kxT.js} +1 -1
- package/dashboard/dist/assets/{Card-BYoxd4OC.js → Card-C9FjyAwh.js} +1 -1
- package/dashboard/dist/assets/{CloudCheckoutPage-BR2_B03P.js → CloudCheckoutPage-ChkjId9l.js} +1 -1
- package/dashboard/dist/assets/{CloudPage-DL5RkJKK.js → CloudPage-D1nrt3MG.js} +1 -1
- package/dashboard/dist/assets/{CloudUsageExport-C_DqZKo1.js → CloudUsageExport-jXdoiD0e.js} +1 -1
- package/dashboard/dist/assets/{CommandPalette-DkCaIQI4.js → CommandPalette-DFnEeZzc.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-pX9OePi4.js → CommunityStatsModal-CZDS8gPA.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-tkgZwz4u.js → ConfirmModal-DRhgBoGE.js} +1 -1
- package/dashboard/dist/assets/{Controls-MTUhGWy8.js → Controls-BmT6-x_L.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-SOx-A7lH.js → DashboardPage-DfwwXZBo.js} +1 -1
- package/dashboard/dist/assets/{DateRangePopover-B-BMOm3O.js → DateRangePopover-DuqNLatr.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-DSK9lm7v.js → DevicePage-BtI0bWyg.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-uVUNu4rg.js → DialogClose-DjnC3P4V.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-yy_QHg7O.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-B-VifiA3.js → DialogTitle-B9NNSz5p.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-B6lrj4uo.js → FadeIn-fsVQmJGa.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-Cx5zOhXa.js → HeaderGithubStar-Cg-f1iZc.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-DY1ENf69.js → HoverTooltip-DRIRlzXH.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-D6TEq64d.js → IpCheckPage-DaAubaJQ.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-OdZUfq--.js → LandingPage-DjBGIjHk.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardPage-DCK5xcAt.js → LeaderboardPage-BkCXqhz7.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProBadge-CBXJ1u_m.js → LeaderboardProBadge-Ds-wiWcN.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfileModal-Ccdzb7QK.js → LeaderboardProfileModal-X_rfSQT5.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-CFXlZ0fL.js → LeaderboardProfilePage-rpl1Ozwj.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-5krjm-g9.js → LimitsPage-BUvDBmgD.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-Rk1B8PaZ.js → LocalOnlyNotice-LBH1DBrs.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-DTTIm8vk.js → LoginCard-B0vRJEcg.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-BNcDdjfr.js → LoginModal-DdzgP43f.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-CQgXP7Ee.js → LoginPage-B4VCQxzn.js} +1 -1
- package/dashboard/dist/assets/{PetPage-Cw_kAPRs.js → PetPage-Cmf6aXc9.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-NYiGE8A2.js → PopoverPopup-BzfELnIC.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-Bp7iFJ_m.js → ProviderIcon-ClHXNkQ0.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-Cf9kAWDW.js → ResetPasswordPage-BeUpNt_6.js} +1 -1
- package/dashboard/dist/assets/{Select-kIcvQFAo.js → Select-BHEXdYHu.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-BpIsAg3b.js → SelectItemText-aaQK_QIt.js} +1 -1
- package/dashboard/dist/assets/{SelfHostPage-Ch2vvSwI.js → SelfHostPage-ClNhKnlP.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-hoYBvGbu.js → ServiceStatusPage-Byd_s6FS.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-BzRB6q-Z.js → SessionsPage-u3_b4PO7.js} +2 -2
- package/dashboard/dist/assets/{SettingsPage-DRl2uX-i.js → SettingsPage-DweCAbsy.js} +2 -2
- package/dashboard/dist/assets/{SkillsPage-CkqThTZL.js → SkillsPage-Bb-PVfux.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-eLG-UIZY.js → TokenGalaxy-CubA3PXu.js} +1 -1
- package/dashboard/dist/assets/{TooltipPopup-bnMJyilQ.js → TooltipPopup-DMliWhoK.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-X7-aGzIv.js → TrendMonitor-as8idaOy.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-CGznIzrW.js → WidgetsPage-DDPR4v0R.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-p31-uUoF.js → WrappedPage-zZzgYz6s.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-2g_4s3ot.js → __vite-browser-external-DWN9Fb-H.js} +2 -2
- package/dashboard/dist/assets/{agent-logos-2TVT3fIE.js → agent-logos-CoNhCm9-.js} +1 -1
- package/dashboard/dist/assets/{arrow-left-DL0hAp_7.js → arrow-left-C5hDp7fc.js} +1 -1
- package/dashboard/dist/assets/{arrow-right-DFCpnV_9.js → arrow-right-DEvMmSiA.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-DLvfE0Wu.js → arrow-up-right-DxY0neJ4.js} +1 -1
- package/dashboard/dist/assets/{calendar-days-B0aDoKSG.js → calendar-days-bzh7-lab.js} +1 -1
- package/dashboard/dist/assets/{check-C_cfrxiz.js → check-CSZvcC3X.js} +1 -1
- package/dashboard/dist/assets/{chevron-down-Ck8ml43e.js → chevron-down-CsiGcG0G.js} +1 -1
- package/dashboard/dist/assets/{cloud-checkout-PYnwNfdH.js → cloud-checkout-z_eDVwm6.js} +1 -1
- package/dashboard/dist/assets/{composite-INW-ELWX.js → composite-Cq0CmNAv.js} +1 -1
- package/dashboard/dist/assets/{download-B7uokeIo.js → download-DqLpubIF.js} +1 -1
- package/dashboard/dist/assets/{external-link-CI3crg4K.js → external-link-B8E8tbB3.js} +1 -1
- package/dashboard/dist/assets/{flame-DCzvFKV1.js → flame-CrJDlnro.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-CSTEYK2m.js → format-tokens-DPIGGOlt.js} +1 -1
- package/dashboard/dist/assets/{gift-dEHDFMc6.js → gift-CCp4Hh50.js} +1 -1
- package/dashboard/dist/assets/{host-mode-r2SW9Mdv.js → host-mode-xzpMLcwP.js} +1 -1
- package/dashboard/dist/assets/{icons-q-3zvEkh.js → icons-CbB9Y-eV.js} +1 -1
- package/dashboard/dist/assets/{index-CyHYj9XI.js → index-BiK5-tQp.js} +1 -1
- package/dashboard/dist/assets/{index-BV7qwUw4.js → index-DX7nYrHb.js} +1 -1
- package/dashboard/dist/assets/{index-BbrsgHf4.js → index-zuC7FU-t.js} +1 -1
- package/dashboard/dist/assets/{info-BBdY9hV4.js → info-B3NKYwWG.js} +1 -1
- package/dashboard/dist/assets/{link-2-CLPePfXs.js → link-2-BRc8d8M9.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-ETrjzfmn.js → loader-circle-Cm5Nsgp-.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-DHqnp2ol.js → modifiers.esm-CYLYBECB.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-D1kdzrdb.js → monitor-smartphone--IZ4D84F.js} +1 -1
- package/dashboard/dist/assets/{play-Cxp-ronD.js → play-CUrMOLtq.js} +1 -1
- package/dashboard/dist/assets/{plus-4n94VzDK.js → plus-0hrCDl4r.js} +1 -1
- package/dashboard/dist/assets/{provider-display-CRlbeO7t.js → provider-display-CNK0FN3Q.js} +1 -1
- package/dashboard/dist/assets/{react-DlHjGQFN.js → react-CCNSVHEA.js} +1 -1
- package/dashboard/dist/assets/{safePolygon-CVZ27a2_.js → safePolygon-DsolkMUX.js} +1 -1
- package/dashboard/dist/assets/{search-BDPr56_h.js → search-DYmYb9xY.js} +1 -1
- package/dashboard/dist/assets/{server-Bm7fHvVa.js → server-CYcqzdSW.js} +1 -1
- package/dashboard/dist/assets/{shield-check-DtT8ACzI.js → shield-check-5zABLIr6.js} +1 -1
- package/dashboard/dist/assets/{skills-api-Dc1-2qu6.js → skills-api-CD-ojBGj.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-B-qN-Xk2.js → sortable.esm-BCn2Ms6R.js} +1 -1
- package/dashboard/dist/assets/{store-gHeBU8dQ.js → store-B22kwLs0.js} +1 -1
- package/dashboard/dist/assets/{terminal-D4VZbvhg.js → terminal-CTv-oTU2.js} +1 -1
- package/dashboard/dist/assets/{trash-BZtLAFQy.js → trash-C5MAh3GO.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-BdqndrbB.js → use-community-stats-BrgrxUD2.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-DhGg1cDS.js → use-latest-request-guard-B1_rbvgH.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-D3HOcRFv.js → use-limits-display-prefs-BOk5f-HM.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-BniKwA_n.js → use-native-settings-B2gc_m9W.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-b09H7EHq.js → use-ordered-list-N3sGpJ0u.js} +1 -1
- package/dashboard/dist/assets/{use-pet-settings-CPZdlq_e.js → use-pet-settings-sWFXgR3m.js} +2 -2
- package/dashboard/dist/assets/use-reduced-motion-C3MBYVqm.js +1 -0
- package/dashboard/dist/assets/{use-transform-CIdxjmI8.js → use-transform-BsaLmw46.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-eJlU65yY.js → use-usage-limits-wL7v-S0r.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-CM22CmAq.js → useCurrency-CbCnjf-N.js} +1 -1
- package/dashboard/dist/assets/{usePositioner-B3l2ulTw.js → usePositioner-MepYlL0A.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-D7nzgxKw.js → useTokenFormat-Bq-rwuKa.js} +1 -1
- package/dashboard/dist/assets/{zap-Daxct1WV.js → zap-1ah5e11g.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dashboard/dist/ip-check.html +1 -1
- package/dashboard/dist/leaderboard.html +1 -1
- package/dashboard/dist/share.html +1 -1
- package/package.json +1 -1
- package/src/cli.js +1 -1
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/rollout.js +49 -16
- package/src/lib/session-analytics.js +546 -52
- package/src/lib/session-performance.js +24 -1
- package/dashboard/dist/assets/DialogDescription-DBqGGWNj.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-D1gcKJUo.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-
|
|
2
|
-
import{o as W,j as e,c as a,y as B,a as mt,r as l,cm as gt,cn as pt,co as ht,cp as ft,a7 as X,cq as we,bu as xt,cr as bt,bt as Ne,cs as de,aP as $e,ct as yt,cu as vt,ag as ze,u as Fe,V as fe,x as jt,B as R,a8 as G,cv as kt,a9 as z,ax as wt,cw as ue,a5 as Y,aB as Nt,a1 as _t,af as St,at as se,R as be,cx as Ct,L as ne,aM as Et,au as Pt,al as Ot,am as ye,ac as At,d as He,aa as xe,ab as Be,cy as _e,cz as Se,cA as Ce,cB as Lt,cC as Tt,ao as It,Z as Ve,l as me,cD as Ee,k as Pe,cE as Rt,cF as Dt,cG as Gt,z as Ut,cH as Mt,cI as $t,cJ as zt,cK as Ft,cL as Ht,cM as Bt,cN as Vt,v as Ke,cO as Kt,cP as qt,bc as Oe,_ as Wt,e as Yt,cQ as Zt,cR as Jt,bw as Qt}from"./__vite-browser-external-2g_4s3ot.js";import{a as Xt,b as Ae,s as ea,K as ta,P as aa,D as sa,c as na,S as ia,v as ra,u as oa,C as la}from"./sortable.esm-B-qN-Xk2.js";import{a as ca}from"./modifiers.esm-DHqnp2ol.js";import{d as Le,l as Te,u as da,b as Ie}from"./use-limits-display-prefs-D3HOcRFv.js";import{P as ua}from"./ProviderIcon-Bp7iFJ_m.js";import{a as E,S as q,b as V,T as D}from"./Controls-MTUhGWy8.js";import{m as qe}from"./react-DlHjGQFN.js";import{P as ma,C as We,a as ga,u as pa,b as ha}from"./CloudUsageExport-C_DqZKo1.js";import{C as fa}from"./check-C_cfrxiz.js";import{C as xa,i as ba}from"./host-mode-r2SW9Mdv.js";import{A as Ye}from"./index-BV7qwUw4.js";import{r as ya,C as ge,o as va}from"./cloud-checkout-PYnwNfdH.js";import{G as Re}from"./gift-dEHDFMc6.js";import{C as ja}from"./chevron-down-Ck8ml43e.js";import{C as pe}from"./Card-BYoxd4OC.js";import{E as De}from"./external-link-CI3crg4K.js";import{a as ka,P as wa}from"./play-Cxp-ronD.js";import{I as Ze}from"./info-BBdY9hV4.js";import{a as Na,b as _a,c as Sa,d as Ca,e as Ea}from"./TooltipPopup-bnMJyilQ.js";import{L as Pa}from"./loader-circle-ETrjzfmn.js";import{u as Oa}from"./useCurrency-CM22CmAq.js";import{u as Aa}from"./useTokenFormat-D7nzgxKw.js";import{S as ve}from"./Select-kIcvQFAo.js";import{u as ie}from"./use-native-settings-BniKwA_n.js";import{C as La}from"./ConfirmModal-tkgZwz4u.js";import{A as Ta}from"./arrow-up-right-DLvfE0Wu.js";import{D as Ia}from"./download-B7uokeIo.js";import"./DialogTitle-B-VifiA3.js";import"./composite-INW-ELWX.js";import"./store-gHeBU8dQ.js";import"./SelectItemText-BpIsAg3b.js";import"./usePositioner-B3l2ulTw.js";import"./safePolygon-CVZ27a2_.js";import"./DialogClose-uVUNu4rg.js";import"./DateRangePopover-B-BMOm3O.js";import"./calendar-days-B0aDoKSG.js";import"./PopoverPopup-NYiGE8A2.js";import"./DialogDescription-DBqGGWNj.js";const Je={name:"credit-card",size:24,node:[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}],["path",{d:"M6 14h2",key:"mk7k0u"}]]};Je.node;const Ra=W(Je);const Qe={name:"flask-conical",size:24,node:[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]};Qe.node;const Da=W(Qe);const Xe={name:"grip-vertical",size:24,node:[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]};Xe.node;const Ga=W(Xe);const et={name:"languages",size:24,node:[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]};et.node;const Ua=W(et);const tt={name:"log-out",size:24,node:[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]]};tt.node;const Ma=W(tt);const at={name:"palette",size:24,node:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]};at.node;const $a=W(at);const st={name:"user-round",size:24,node:[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],aliases:["user-2"]};st.node;const za=W(st),Fa="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Ha({checked:t,onChange:s,ariaLabel:n}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":n,onClick:s,className:B("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",t?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:e.jsx("span",{className:B("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",t?"translate-x-[18px]":"translate-x-[3px]")})})}function Ba({id:t,visible:s,onToggle:n}){const{attributes:i,listeners:r,setNodeRef:c,transform:g,transition:o,isDragging:d}=oa({id:t}),y={transform:la.Transform.toString(g)||void 0,transition:o,zIndex:d?20:void 0};return e.jsxs("div",{ref:c,style:y,className:B("flex items-center gap-3 py-2 rounded-md select-none touch-none","cursor-grab active:cursor-grabbing","hover:bg-oai-gray-100/60 dark:hover:bg-oai-gray-800/60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",d&&"relative bg-oai-gray-100 dark:bg-oai-gray-800"),...i,...r,children:[e.jsx(Ga,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),Le(t)?e.jsx(ua,{provider:Le(t),size:18,className:B("pointer-events-none",Fa)}):null,e.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:Te(t)}),e.jsx("div",{onPointerDown:p=>p.stopPropagation(),children:e.jsx(Ha,{checked:s,onChange:n,ariaLabel:`${a("limits.settings.toggle_visible")}: ${Te(t)}`})})]})}function Va({prefs:t}){const{order:s,visibility:n,toggle:i,setAllVisible:r,moveToward:c}=t,g=s.every(u=>n[u]!==!1),o=s.every(u=>n[u]===!1),d=s.filter(u=>n[u]!==!1).length,y=Xt(Ae(aa,{activationConstraint:{distance:6}}),Ae(ta,{coordinateGetter:ea})),p=({active:u,over:x})=>{x&&u.id!==x.id&&c(u.id,x.id)};return e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("limits.settings.bulk_visibility"),hint:a("limits.settings.enabled_count",{enabled:d,total:s.length}),control:e.jsx(q,{options:[{value:"enabled",label:a("limits.settings.enable_all")},{value:"disabled",label:a("limits.settings.disable_all")}],value:g?"enabled":o?"disabled":null,onChange:u=>r(u==="enabled")})}),e.jsx(sa,{sensors:y,collisionDetection:na,modifiers:[ca],onDragEnd:p,children:e.jsx(ia,{items:s,strategy:ra,children:e.jsx("div",{className:"flex flex-col",children:s.map(u=>e.jsx(Ba,{id:u,visible:n[u]!==!1,onToggle:()=>i(u)},u))})})})]})}function Ka(t){if(!t||typeof t!="object")return"";const s=t.user_metadata&&typeof t.user_metadata=="object"?t.user_metadata:{},n=t.profile&&typeof t.profile=="object"?t.profile:{},i=s.full_name||s.name||n.name||s.user_name||s.preferred_username;return typeof i=="string"&&i.trim()?i.trim():typeof t.email=="string"&&t.email.includes("@")?t.email.split("@")[0].trim()||t.email.trim():typeof t.email=="string"?t.email.trim():""}function qa(t){return!t||typeof t!="object"?"":typeof t.email=="string"?t.email.trim():""}function Wa(t){const s=typeof t=="string"?t.trim():"";if(!s)return null;const n=s.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),i=s.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),r=n?.[1]||i?.[1];return r?`https://github.com/${r}`:null}function je(t,s){console.warn(`[tokentracker] settings ${t}:`,s)}function Ya(t,s,n,i){const[r,c]=l.useState(()=>X()),g=s&&n&&ze(),o=l.useMemo(()=>({active:!0,busy:!1}),[t,s,n,i]),d=l.useRef(o);d.current=o;const[y,p]=l.useState(null),u=y?.scope===o?y:null;l.useEffect(()=>{o.active=!0;const j=()=>{const m=X();c(m),m||p(k=>k?.scope===o?{...k,error:null}:k)},h=()=>{p(m=>m?.scope===o?{...m,error:null}:m),de(i,"cloud-sync")};return j(),window.addEventListener("tt.cloudSyncChanged",j),window.addEventListener("storage",j),window.addEventListener(we,h),()=>{o.active=!1,window.removeEventListener("tt.cloudSyncChanged",j),window.removeEventListener("storage",j),window.removeEventListener(we,h)}},[o,i]);const x=l.useCallback(async()=>{if(!g||!X()||o.busy||!o.active||d.current!==o)return;o.busy=!0,p({scope:o,pending:!0,error:null});const j=()=>o.active&&d.current===o&&X();try{await xt(()=>t())}catch(h){if(!j())return;["cloud_membership_required","cloud_read_only_expired","cloud_history_window_exceeded","cloud_machine_limit","machine_limit_exceeded","cloud_machine_paused"].includes(h?.code)?bt(i,h.code,h.membership,"cloud-sync"):p({scope:o,pending:!0,error:{code:"billing_network_error"}}),je("cloud sync",h)}finally{o.busy=!1,o.active&&d.current===o&&p(h=>h?.scope===o?{...h,pending:!1}:h)}},[g,o,t,i]),v=l.useCallback(async()=>{if(!g||o.busy||!o.active||d.current!==o)return;const j=!X();p({scope:o,pending:!1,error:null}),Ne(j),c(j),j?await x():de(i,"cloud-sync")},[g,o,x,i]),N=l.useCallback(()=>{!g||!o.active||d.current!==o||(Ne(!1),c(!1),p(j=>j?.scope===o?{...j,error:null}:j),de(i,"cloud-sync"))},[g,o,i]);return{cloudSyncOn:r,cloudSyncPending:!!u?.pending,cloudSyncError:u?.error,handleCloudSyncToggle:v,handleCloudSyncRetry:x,handleCloudSyncDisable:N,showLocalCloudSync:g}}function Za(t){const[s,n]=l.useState(!1),[i,r]=l.useState(!1),[c,g]=l.useState(!1),[o,d]=l.useState(!1),[y,p]=l.useState(null),[u,x]=l.useState(!1),[v,N]=l.useState(""),[j,h]=l.useState(!1),[m,k]=l.useState(""),[C,f]=l.useState(""),[S,_]=l.useState(!1),[w,A]=l.useState(null),T=l.useMemo(()=>Ka(t),[t]),b=l.useMemo(()=>qa(t),[t]),P=l.useMemo(()=>typeof t?.id=="string"?t.id.trim():"",[t]),U=l.useMemo(()=>({setAnonymousOn:r,setCustomDisplayName:p,setGithubUrl:k,setProfileLoading:g,setPublicProfileOn:n,setShowGithubOn:h}),[]);return{anonymousOn:i,customDisplayName:y,displayName:T,editingGithub:S,editingName:u,email:b,githubError:w,githubInput:C,githubUrl:m,loadSetters:U,nameInput:v,profileLoading:c,profileSaving:o,publicProfileOn:s,setAnonymousOn:r,setCustomDisplayName:p,setEditingGithub:_,setEditingName:x,setGithubError:A,setGithubInput:f,setGithubUrl:k,setNameInput:N,setProfileLoading:g,setProfileSaving:d,setPublicProfileOn:n,setShowGithubOn:h,showGithubOn:j,userId:P}}function Ja(t,s,n){l.useEffect(()=>{if(!s)return;let i=!0;return n.setProfileLoading(!0),(async()=>{try{const r=await $e({getAccessToken:t});if(!i||!r)return;const c=await yt({accessToken:r});if(!i)return;n.setPublicProfileOn(!!c?.enabled),n.setAnonymousOn(!!c?.anonymous),c?.display_name&&n.setCustomDisplayName(c.display_name),n.setShowGithubOn(!!c?.show_github_url),n.setGithubUrl(c?.github_url||"")}catch(r){je("load public profile",r)}finally{i&&n.setProfileLoading(!1)}})(),()=>{i=!1}},[t,s,n])}function Qa(t,s,n){return l.useCallback(async(i,{label:r,onError:c,onSuccess:g}={})=>{if(!n||s.profileSaving)return!1;s.setProfileSaving(!0);try{const o=await $e({getAccessToken:t});if(!o)return!1;const d=await vt({accessToken:o,...i});return g?.(d),!0}catch(o){return c?c(o):je(r||"mutate profile",o),!1}finally{s.setProfileSaving(!1)}},[t,s,n])}function Xa(t,s){return{anonymousOn:t.anonymousOn,customDisplayName:t.customDisplayName,displayName:t.displayName,editingName:t.editingName,handleAnonymousToggle:s.handleAnonymousToggle,handleSaveName:s.handleSaveName,nameInput:t.nameInput,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingName:t.setEditingName,setNameInput:t.setNameInput,startEditingName:s.startEditingName}}function es(t,s){return{editingGithub:t.editingGithub,githubError:t.githubError,githubInput:t.githubInput,githubUrl:t.githubUrl,handleSaveGithub:s.handleSaveGithub,handleShowGithubToggle:s.handleShowGithubToggle,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingGithub:t.setEditingGithub,setGithubError:t.setGithubError,setGithubInput:t.setGithubInput,showGithubOn:t.showGithubOn,startEditingGithub:s.startEditingGithub}}function ts(t,s){const n=l.useCallback(async()=>{const r=!t.publicProfileOn;await s({enabled:r},{label:"toggle public profile",onSuccess:()=>t.setPublicProfileOn(r)})},[s,t]);return{handleAnonymousToggle:l.useCallback(async()=>{const r=!t.anonymousOn;await s({anonymous:r},{label:"toggle anonymous",onSuccess:()=>t.setAnonymousOn(r)})},[s,t]),handlePublicProfileToggle:n}}function as(t,s,n){const i=l.useCallback(async()=>{const c=t.nameInput.trim().slice(0,50);c&&await s({display_name:c},{label:"save display name",onSuccess:()=>{t.setCustomDisplayName(c),t.setEditingName(!1),n?.()}})},[s,t,n]),r=l.useCallback(()=>{t.setNameInput(t.customDisplayName||t.displayName),t.setEditingName(!0)},[t]);return{handleSaveName:i,startEditingName:r}}function ss(t,s){const n=l.useCallback(async()=>{if(!t.showGithubOn&&!t.githubUrl){t.setEditingGithub(!0),t.setGithubInput(""),t.setGithubError(null);return}const c=!t.showGithubOn;await s({show_github_url:c},{label:"toggle GitHub profile",onSuccess:()=>t.setShowGithubOn(c)})},[s,t]),i=l.useCallback(async()=>{const c=Wa(t.githubInput);if(t.githubInput.trim()&&!c){t.setGithubError(a("settings.account.githubUrlInvalid"));return}t.setGithubError(null),await s({github_url:c,show_github_url:!!c},{label:"save GitHub profile",onError:g=>t.setGithubError(g?.message||a("settings.account.githubUrlInvalid")),onSuccess:g=>{t.setGithubUrl(g?.github_url||c||""),t.setShowGithubOn(!!c),t.setEditingGithub(!1)}})},[s,t]),r=l.useCallback(()=>{t.setGithubInput(t.githubUrl),t.setGithubError(null),t.setEditingGithub(!0)},[t]);return{handleSaveGithub:i,handleShowGithubToggle:n,startEditingGithub:r}}function ke(){const t=mt();l.useSyncExternalStore(gt,pt,()=>0);const s=ht(t.user?.id),i=!(s.membership?.status==="self_hosted"||s.catalog?.policy?.hosting_mode==="self_hosted")&&(ft()||s.membership?.hosting_mode==="hosted"),r=Za(t.user),c=Ya(t.getAccessToken,t.enabled,t.signedIn,t.user?.id);Ja(t.getAccessToken,t.signedIn&&i,r.loadSetters);const g=Qa(t.getAccessToken,r,i),o=ts(r,g),d=as(r,g,t.refreshDisplayName),y=ss(r,g);return{...t,...c,email:r.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:r.userId,name:Xa(r,{...o,...d}),github:es(r,y),profileLoading:r.profileLoading,profileSaving:r.profileSaving,publicProfileOn:i&&r.publicProfileOn,publicProfileAvailable:i}}function nt({disabled:t,onCancel:s,onSave:n,saveLabel:i=a("settings.account.save")}){return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:n,disabled:t,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:i}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md px-2 py-1.5 text-xs text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:a("settings.account.cancel")})]})}function ns({nameInput:t,setEditingName:s,setNameInput:n,profileSaving:i,handleSaveName:r}){return e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:c=>n(c.target.value),onKeyDown:c=>{c.key==="Enter"&&r(),c.key==="Escape"&&s(!1)},maxLength:50,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.displayName")}),e.jsx(nt,{disabled:i||!t.trim(),onCancel:()=>s(!1),onSave:r,saveLabel:i?a("settings.account.saving"):void 0})]})}function is({githubError:t,githubInput:s,handleSaveGithub:n,profileSaving:i,setEditingGithub:r,setGithubError:c,setGithubInput:g}){return e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:o=>{g(o.target.value),t&&c(null)},onKeyDown:o=>{o.key==="Enter"&&n(),o.key==="Escape"&&(r(!1),c(null))},maxLength:100,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.githubUrlPlaceholder")}),e.jsx(nt,{disabled:i,onCancel:()=>{r(!1),c(null)},onSave:n,saveLabel:i?a("settings.account.saving"):void 0})]}),t?e.jsx("div",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400",children:t}):null]})}function it({disabled:t=!1,label:s,onClick:n,title:i}){return e.jsxs("button",{type:"button",onClick:n,disabled:t,title:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-40 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(ma,{className:"h-3.5 w-3.5","aria-hidden":!0}),s]})}function rt({actions:t,editing:s,editor:n,hint:i,label:r}){return e.jsx("div",{className:"py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:r}),s?n:e.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i})]}),s?null:t]})})}function rs({name:t}){const s=t.anonymousOn?a("settings.account.displayNameDisabledWhileAnon"):void 0;return e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(it,{disabled:t.anonymousOn,label:a("settings.account.edit"),onClick:t.startEditingName,title:s}),e.jsx(D,{checked:!t.anonymousOn,onChange:t.handleAnonymousToggle,disabled:t.profileLoading||t.profileSaving,ariaLabel:a("settings.account.displayName")})]})}function os({name:t}){const{anonymousOn:s,customDisplayName:n,displayName:i,editingName:r,handleAnonymousToggle:c,handleSaveName:g,nameInput:o,profileLoading:d,profileSaving:y,setEditingName:p,setNameInput:u,startEditingName:x}=t,v=s?a("settings.account.displayNameAnonymousHint"):n||i;return e.jsx(rt,{label:a("settings.account.displayName"),editing:r,hint:v,editor:e.jsx(ns,{nameInput:o,setEditingName:p,setNameInput:u,profileSaving:y,handleSaveName:g}),actions:e.jsx(rs,{name:t})})}function ls({github:t}){const{editingGithub:s,githubError:n,githubInput:i,githubUrl:r,handleSaveGithub:c,handleShowGithubToggle:g,profileLoading:o,profileSaving:d,setEditingGithub:y,setGithubError:p,setGithubInput:u,showGithubOn:x,startEditingGithub:v}=t;return e.jsx(e.Fragment,{children:e.jsx(rt,{label:a("settings.account.githubUrl"),editing:s,hint:r||a("settings.account.githubUrlHint"),editor:e.jsx(is,{githubError:n,githubInput:i,handleSaveGithub:c,profileSaving:d,setEditingGithub:y,setGithubError:p,setGithubInput:u}),actions:e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(it,{label:a("settings.account.edit"),onClick:v}),e.jsx(D,{checked:x,onChange:g,disabled:o||d,ariaLabel:a("settings.account.githubUrl")})]})})})}function cs(){const{openLoginModal:t}=Fe();return e.jsx(V,{title:a("settings.section.account"),children:e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.account.signedOutHint")}),e.jsx("button",{type:"button",onClick:t,className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-oai-gray-900 px-4 text-xs font-medium text-white transition-colors hover:bg-oai-gray-800 dark:bg-white dark:text-oai-gray-900 dark:hover:bg-oai-gray-100",children:a("settings.account.signIn")})]})})}function ds({name:t,github:s}){return e.jsxs(e.Fragment,{children:[e.jsx(os,{name:t}),e.jsx(ls,{github:s})]})}function us({settings:t}={}){return t?e.jsx(ot,{settings:t}):e.jsx(ms,{})}function ms(){const t=ke();return e.jsx(ot,{settings:t})}function ot({settings:t}){return t.enabled?t.signedIn?e.jsxs(V,{title:a("settings.section.account"),subtitle:t.email||t.name.customDisplayName||t.name.displayName,action:e.jsx(ps,{onSignOut:t.signOut}),children:[e.jsx(gs,{userId:t.userId}),e.jsx(hs,{checked:t.publicProfileOn,disabled:t.profileLoading||t.profileSaving||t.publicProfileAvailable===!1,onChange:t.handlePublicProfileToggle,unavailable:t.publicProfileAvailable===!1}),e.jsx(fs,{visible:t.publicProfileOn,name:t.name,github:t.github})]}):e.jsx(cs,{}):null}function gs({userId:t}){const[s,n]=fe.useState(!1);if(!t)return null;const i=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(t),n(!0),globalThis.setTimeout(()=>n(!1),1200)}catch{n(!1)}};return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:a("settings.account.userId")}),e.jsx("div",{className:"mt-0.5 truncate font-mono text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t})]}),e.jsxs("button",{type:"button",onClick:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800","aria-label":a("settings.account.copyUserId"),children:[s?e.jsx(fa,{className:"h-3.5 w-3.5","aria-hidden":!0}):e.jsx(xa,{className:"h-3.5 w-3.5","aria-hidden":!0}),s?a("settings.account.copied"):a("settings.account.copy")]})]})}function ps({onSignOut:t}){return e.jsxs("button",{type:"button",onClick:()=>t(),className:"inline-flex h-7 items-center gap-1.5 text-xs font-medium text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:[e.jsx(Ma,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.account.signOut")]})}function hs({checked:t,disabled:s,onChange:n,unavailable:i}){return e.jsx(E,{label:a("settings.account.publicProfile"),hint:a(i?"cloud.self_host.public_profile_disabled":"settings.account.publicProfileHint"),control:e.jsx(D,{checked:t,onChange:n,disabled:s,ariaLabel:a("settings.account.publicProfile")})})}function fs({visible:t,name:s,github:n}){return e.jsx(Ye,{initial:!1,children:t?e.jsx(qe.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:e.jsx(ds,{name:s,github:n})},"public-profile-fields"):null})}function ae(t){return t.replace(/[\t\n\r\f\v -]/g,"").toUpperCase()}function xs({account:t,auth:s,refresh:n,compact:i=!1,panelContainer:r=null,layout:c="default",dialogOpen:g,onDialogOpenChange:o}){const d=c==="settings-row",[y,p]=l.useState(!1),u=d&&typeof g=="boolean"?g:y,[x,v]=l.useState(""),[N,j]=l.useState(!1),[h,m]=l.useState(null),[k,C]=l.useState(null),[f,S]=l.useState(!1),_=l.useId(),w=l.useRef(null),A=l.useRef(null),T=l.useRef(!1),b=l.useRef(!1),P=l.useRef(0),U=`${jt()}.${t?.environment||"unknown"}.${s?.signedIn?s.user?.id:""}`,F=l.useRef(U);F.current=U,l.useEffect(()=>(b.current=!0,P.current+=1,A.current=null,T.current=!1,p(!1),v(""),j(!1),m(null),C(null),S(!1),()=>{b.current=!1,P.current+=1}),[U]);const K=t?.membership?.status==="self_hosted"||t?.membership?.hosting_mode==="self_hosted",$=t?.gift_redemption_available===!0,Z=d?t?.gifts||[]:[];if(!s?.signedIn||K||!$&&!Z.length)return null;const J=t.redemption_restriction,re=O=>{!O&&T.current||(typeof g!="boolean"&&p(O),o?.(O))},L=async(O,oe)=>{const le=await n();oe()&&S(!!le?.gifts?.some(H=>H.id===O?.id))},ee=async O=>{if(T.current||O&&(!$||!x.trim()))return;if(O&&J){m(new ue(J));return}T.current=!0;const oe=++P.current,le=U,H=()=>b.current&&P.current===oe&&F.current===le;j(!0),m(null);try{if(O){const te=x.trim();(!A.current||ae(A.current.code)!==ae(te))&&(A.current={code:te,request_id:crypto.randomUUID()});const ce=await Y("redeem-gift",{auth:async()=>{const ut=await Nt(s.getAccessToken);if(!H())throw new ue("authentication_required",401);return ut},body:A.current});if(!H())return;if(!ce?.gift?.id)throw new ue("billing_operation_failed");C(ce),S(!1),v(""),A.current=null,await L(ce.gift,H)}else await L(k?.gift,H)}catch(te){H()&&m(te)}finally{H()&&(T.current=!1,j(!1))}};let Q=null;return(d||u)&&(Q=e.jsxs("div",{id:`${_}-panel`,className:d?"space-y-3":i?"w-full space-y-3 rounded-lg bg-oai-gray-50 p-4 dark:bg-oai-gray-950/50":"mt-3 space-y-3",children:[$?e.jsxs(e.Fragment,{children:[e.jsx("p",{id:`${_}-detail`,className:d?"sr-only":"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.detail")}),k?e.jsxs("div",{role:"status",className:"space-y-2 text-sm leading-6",children:[e.jsx("p",{children:a(f?k.already_redeemed?"cloud.gift.already_redeemed":"cloud.gift.redeemed":"cloud.gift.refresh_needed")}),k.gift?e.jsx("p",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.term",{days:k.gift.duration_days,start:G(k.gift.starts_at),end:G(k.gift.ends_at)})}):null,f?e.jsx(R,{type:"button",variant:"ghost",onClick:()=>{C(null),S(!1)},children:a("cloud.gift.redeem_another")}):e.jsx(R,{type:"button",variant:"secondary",disabled:N,onClick:()=>{ee(!1)},children:a("cloud.action.refresh_membership")})]}):e.jsxs("form",{onSubmit:O=>{O.preventDefault(),ee(!0)},"aria-busy":N,children:[e.jsx("label",{htmlFor:_,className:d?"sr-only":"text-sm font-medium",children:a("cloud.gift.code_label")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:_,ref:w,value:x,disabled:N,maxLength:128,autoComplete:"off",spellCheck:!1,autoCapitalize:"characters","data-ph-no-capture":"true","aria-describedby":`${_}-detail${h?` ${_}-error`:""}`,"aria-invalid":!!h,onChange:O=>{ae(O.target.value)!==ae(x)&&(A.current=null),v(O.target.value),m(null)},className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 font-mono text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700"}),e.jsx(R,{type:"submit",variant:"secondary",disabled:N||!x.trim(),children:a(N?"cloud.gift.redeeming":"cloud.gift.confirm")})]})]}),h?e.jsx("div",{id:`${_}-error`,children:["gift_checkout_pending","gift_requires_renewal_cancel"].includes(h.code)?e.jsx("p",{role:"alert",className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:kt(h,"gift")}):e.jsx(z,{error:h,context:"gift"})}):null]}):null,Z.length?e.jsx("ul",{"aria-label":a("cloud.gift.history_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:Z.map(O=>e.jsxs("li",{className:"py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-sm",children:[e.jsx("span",{children:a("cloud.gift.duration",{days:O.duration_days})}),e.jsx("span",{children:a(["active","pending","expired","revoked"].includes(O.state)?`cloud.gift.state_${O.state}`:"cloud.status.unknown")})]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.history.term",{start:G(O.starts_at),end:G(O.ends_at)})})]},O.id))}):null]})),d?e.jsx(We,{open:u,onOpenChange:re,title:a($?"cloud.gift.redeem_action":"cloud.gift.history_title"),icon:Re,preventClose:N,initialFocus:$&&!k?w:void 0,children:Q}):e.jsxs("div",{className:d?void 0:i?"contents":"mt-4",children:[e.jsxs(R,{type:"button",variant:"ghost",size:i||d?"sm":"md",className:d?"!h-11 !w-full !justify-start !px-0 !text-oai-black dark:!text-oai-white hover:!bg-oai-gray-100 dark:hover:!bg-oai-gray-800 active:!scale-100":i?"!h-10 !px-0":void 0,"aria-expanded":u,"aria-controls":d||u?`${_}-panel`:void 0,onClick:()=>p(O=>!O),disabled:N,children:[i||d?e.jsx(Re,{size:16,className:`${d?"mr-3":"mr-2"} shrink-0`,"aria-hidden":!0}):null,a($?"cloud.gift.redeem_action":"cloud.gift.history_title"),d?e.jsx(ja,{size:16,className:`ml-auto shrink-0 transition-transform motion-reduce:transition-none ${u?"rotate-180":""}`,"aria-hidden":!0}):null]}),!d&&r&&Q?wt.createPortal(Q,r):Q]})}function bs({text:t,label:s}){const[n,i]=l.useState(!1);return e.jsxs(Na,{open:n,onOpenChange:i,children:[e.jsx(_a,{delay:0,closeOnClick:!1,"aria-label":s,onClick:()=>i(!0),className:"inline-flex size-8 shrink-0 items-center justify-center rounded-md text-oai-gray-400 transition-colors hover:bg-oai-gray-100 hover:text-oai-gray-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-500/40 dark:hover:bg-oai-gray-800 dark:hover:text-oai-gray-200",children:e.jsx(Ze,{size:14,"aria-hidden":!0})}),e.jsx(Sa,{children:e.jsx(Ca,{side:"bottom",sideOffset:6,className:"z-[110]",children:e.jsx(Ea,{role:"tooltip",className:"max-w-[min(320px,calc(100vw-2rem))] rounded-lg border border-oai-gray-200 bg-white px-3 py-2 text-xs leading-5 text-oai-gray-600 shadow-lg dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-gray-300",children:t})})})]})}function ys(t){return typeof t!="string"||!t.trim()?a("cloud.devices.platform_unknown"):/^(mac|darwin)/i.test(t)?a("leaderboard.community.modal.platform.darwin"):/^win/i.test(t)?a("leaderboard.community.modal.platform.win32"):/^linux/i.test(t)?a("leaderboard.community.modal.platform.linux"):t}function vs(t,s){if(!t)return null;const n=t.status==="active"&&t.access_source==="gift";if(s&&Number.isFinite(Date.parse(s))){const i=t.status==="transition"?"cloud.membership.transition_until":t.status==="trial"?"cloud.membership.trial_until":t.status==="active"?n?"cloud.membership.gift_until":"cloud.membership.active_until":t.status==="expired"&&Date.parse(s)<=Date.now()?"cloud.membership.expired_on":null;if(i)return a(i,{date:G(s)})}return n?a("cloud.gift.membership_label"):Pt(t.status)}function js({auth:t,machineLimit:s,accountRevision:n,selfHosted:i=!1}){const[r,c]=l.useState(null),[g,o]=l.useState(null),[d,y]=l.useState(null),[p,u]=l.useState(!1),[x,v]=l.useState(null),N=l.useRef(!1),j=l.useRef(0),h=l.useRef(!0),m=t?.user?.id,k=t?.getAccessToken,C=l.useCallback(async()=>{const b=++j.current;try{let P;if(ze())try{const F=await Ot(),K=await fetch("/functions/tokentracker-machine-id",{headers:F});K.ok&&(P=(await K.json())?.machineId)}catch{}const U=await Y("devices",{auth:k,params:P?{current_machine_id:P}:{}});b===j.current&&(c(U),o(null))}catch(P){b===j.current&&o({...P,code:"billing_devices_unavailable"})}},[k,m]);l.useEffect(()=>(h.current=!0,C(),()=>{h.current=!1,j.current+=1}),[C,n]);const f=async b=>{if(!N.current){N.current=!0,u(!0),o(null),v(null);try{if(await Y("remove-device",{auth:k,body:{machine_id:b}}),!h.current)return;r?.machines?.find(P=>P.machine_id===b)?.is_current&&Se(),y(null),await C()}catch(P){h.current&&o(P)}finally{N.current=!1,u(!1)}}},S=async b=>{if(!N.current){N.current=!0,u(!0),o(null),v(null);try{if(await Y("resume-device",{auth:k,body:{machine_id:b.machine_id}}),!h.current)return;b.is_current&&Se(),v(a("cloud.devices.resumed")),await C()}catch(P){h.current&&o(P)}finally{N.current=!1,u(!1)}}},_=r?.machines||[],w=r?.machine_count??_.filter(b=>b.status!=="paused").length,A=r?.machine_limit??s,T=A==null||w<A;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("cloud.devices.title")}),e.jsx(bs,{label:a("cloud.devices.detail"),text:a("cloud.devices.detail")})]}),e.jsx("span",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:r?A==null?a(i?"cloud.devices.unlimited_self_hosted":"cloud.devices.unlimited",{count:w}):a("cloud.devices.count",{count:w,limit:A}):g?a("cloud.devices.count_unknown"):a("cloud.catalog.loading")})]}),r?.over_machine_limit||A!=null&&A<w?e.jsx("div",{className:"mb-4",children:e.jsx(z,{children:a("cloud.devices.over_limit")})}):null,g?e.jsx(z,{error:g,onRetry:C,context:"account"}):null,x?e.jsx("div",{className:"mb-3",children:e.jsx(z,{children:x})}):null,!g&&r&&_.length===0?e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.empty")}):null,_.length!==0?e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:_.map(b=>e.jsxs("li",{className:"py-1.5",children:[e.jsxs("div",{className:"grid grid-cols-[17px_minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1",children:[e.jsx(ye,{size:17,className:"col-start-1 row-start-1 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx("p",{title:b.name||a("cloud.devices.unnamed"),className:"col-start-2 row-start-1 min-w-0 truncate text-sm font-medium",children:b.name||a("cloud.devices.unnamed")}),e.jsxs("div",{className:"col-span-2 col-start-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-1 sm:col-start-2",children:[e.jsx("span",{children:ys(b.platform)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:b.last_seen_at?a("cloud.devices.last_seen",{date:At(b.last_seen_at)}):a("cloud.devices.last_seen_unknown")}),b.is_current?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.current")})]}):null,b.status==="paused"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.paused")})]}):null]}),b.status==="paused"&&!T?e.jsx("p",{className:"col-start-2 row-start-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.no_slot")}):null,e.jsxs(R,{variant:"ghost",size:"sm",className:"col-start-3 row-start-1 !min-h-10 !px-2 sm:row-span-2","aria-expanded":b.status!=="paused"?d===b.machine_id:void 0,"aria-controls":d===b.machine_id?`cloud-machine-confirm-${b.machine_id}`:void 0,onClick:()=>b.status==="paused"?S(b):y(P=>P===b.machine_id?null:b.machine_id),disabled:p||b.status==="paused"&&!T,children:[b.status==="paused"?e.jsx(ka,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}):e.jsx(wa,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}),b.status==="paused"?a("cloud.devices.resume"):a("cloud.devices.remove")]})]}),d===b.machine_id?e.jsxs("div",{id:`cloud-machine-confirm-${b.machine_id}`,className:"mt-3 rounded-lg bg-oai-gray-50 p-3 dark:bg-oai-gray-800",children:[e.jsx("p",{className:"text-xs leading-5",children:a("cloud.devices.remove_detail")}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx(R,{variant:"secondary",onClick:()=>f(b.machine_id),disabled:p,children:a("cloud.devices.confirm_remove")}),e.jsx(R,{variant:"ghost",onClick:()=>y(null),disabled:p,children:a("cloud.action.keep")})]})]}):null]},b.machine_id))}):null]})}function ks({recent:t,pendingOrders:s,conflictOrders:n,userId:i,payments:r=[],footerActions:c}){const g=He(),[o,d]=l.useState(t?.order_id&&ge.test(t.order_id)?t.order_id:""),[y,p]=l.useState(!1),[u,x]=l.useState(!1),v=l.useId(),N=l.useRef(null);l.useEffect(()=>{u&&N.current?.focus()},[u]);const j=new Set([...r.map(m=>m.order_id).filter(m=>typeof m=="string"),...(s||[]).filter(m=>m.status==="paid"||["paid","partially_refunded","refunded"].includes(m.payment_state)).map(m=>m.id)].map(m=>m.toLowerCase())),h=[...n||[],...(s||[]).filter(m=>m.retry_payment_conflict_at||!j.has(m.id.toLowerCase()))].filter((m,k,C)=>C.findIndex(f=>f.id===m.id)===k);return e.jsxs("div",{className:"mt-2 space-y-3",children:[t?.request_id&&!t.order_id?e.jsx(ne,{to:`/billing/checkout?sku=${encodeURIComponent(t.sku)}`,className:"mt-3 inline-flex min-h-10 items-center text-sm text-oai-brand underline underline-offset-4",children:a("cloud.action.resume_purchase")}):null,h.length||r.length?e.jsxs("div",{className:"sm:grid sm:grid-cols-[minmax(0,1fr)_auto_minmax(7rem,auto)] sm:gap-x-4",children:[e.jsxs("div",{"aria-hidden":!0,className:"hidden gap-x-4 pb-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[e.jsx("span",{children:a("cloud.history.date")}),e.jsx("span",{className:"text-right",children:a("cloud.history.amount")}),e.jsx("span",{className:"text-right",children:a("cloud.history.status")})]}),e.jsxs("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[h.map(m=>{const k=typeof m.created_at=="string"&&Number.isFinite(Date.parse(m.created_at))?G(m.created_at):null;let C=null;Number.isInteger(m.amount_cents)&&m.amount_cents>=0&&["USD","CNY"].includes(m.currency)&&(C=xe(m.amount_cents,m.currency));const f=a(m.retry_payment_conflict_at?"cloud.action.review_duplicate_payment":"cloud.history.pending");return e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:k||f}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:C}),m.provider||k?e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[m.provider?e.jsx("span",{children:Be(m.provider)}):null,k?e.jsxs(e.Fragment,{children:[m.provider?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,e.jsx("span",{children:f})]}):null]}):null,e.jsx(ne,{to:`/billing/checkout?order=${encodeURIComponent(m.id)}`,onClick:S=>{m.retry_payment_conflict_at||S.button!==0||S.metaKey||S.ctrlKey||S.shiftKey||S.altKey||!ge.test(m.id)||(S.preventDefault(),g(_e({orderId:m.id,userId:i})))},className:"col-start-2 row-start-2 inline-flex min-h-10 items-center justify-end rounded-sm text-right text-sm underline-offset-4 hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 sm:col-start-3 sm:row-span-2 sm:row-start-1 sm:self-start sm:items-start",children:e.jsx("span",{children:m.retry_payment_conflict_at?a("cloud.action.review_duplicate_payment"):a("cloud.action.resume_order")})})]},m.id)}),e.jsx(ws,{payments:r})]})]}):e.jsx(e.Fragment,{children:(!t?.request_id||t.order_id)&&e.jsx("p",{className:"py-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.history.empty")})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-1",children:[e.jsx(R,{variant:"ghost",size:"sm",className:"!h-10 !px-0","aria-expanded":u,"aria-controls":`${v}-panel`,onClick:()=>x(m=>!m),children:a("cloud.restore.title")}),c]}),u?e.jsxs("div",{id:`${v}-panel`,className:"mt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.restore.detail")}),e.jsxs("form",{className:"mt-4",onSubmit:m=>{if(m.preventDefault(),!ge.test(o.trim())){p(!0);return}const k=o.trim(),C=h.some(f=>f.id.toLowerCase()===k.toLowerCase()&&f.retry_payment_conflict_at);g(C?`/billing/checkout?order=${encodeURIComponent(k)}`:_e({orderId:k,userId:i}))},children:[e.jsx("label",{htmlFor:`${v}-input`,className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.checkout.order_id")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:`${v}-input`,ref:N,value:o,onChange:m=>{d(m.target.value),p(!1)},placeholder:a("cloud.restore.placeholder"),className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700","aria-invalid":y,"aria-describedby":y?`${v}-error`:void 0}),e.jsx(R,{type:"submit",variant:"secondary",children:a("cloud.action.restore")})]}),y?e.jsx("p",{id:`${v}-error`,role:"alert",className:"mt-2 text-xs text-red-600 dark:text-red-400",children:a("cloud.restore.invalid")}):null]})]}):null]})]})}function ws({payments:t}){return e.jsx(e.Fragment,{children:t.map(s=>e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:G(s.paid_at)}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:xe(s.amount_cents,s.currency)}),e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:Be(s.provider)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.history.term",{start:G(s.starts_at),end:G(s.ends_at)})})]}),e.jsx("p",{className:`col-start-2 row-start-2 text-right text-sm font-medium sm:col-start-3 sm:row-span-1 sm:row-start-1 sm:self-start ${s.refunded_cents>0?"text-amber-700 dark:text-amber-400":"text-oai-gray-600 dark:text-oai-gray-300"}`,children:s.refunded_cents>0?a("cloud.history.refunded",{amount:xe(s.refunded_cents,s.currency)}):a("cloud.history.paid")})]},s.id))})}function Ns({showTitle:t=!0,heading:s,syncControl:n,active:i=!0}){const r=_t();return e.jsx(_s,{showTitle:t,heading:s,syncControl:n,active:i,...r},r.auth?.signedIn?r.auth.user?.id:"signed-out")}function _s({account:t,auth:s,loading:n,error:i,refresh:r,showTitle:c,heading:g,syncControl:o,active:d=!0}){const{openLoginModal:y}=Fe(),[p,u]=l.useState(null),[x,v]=l.useState(null),[N,j]=l.useState(!1),[h,m]=l.useState(null),k=l.useRef(!1),C=l.useRef(!0);l.useEffect(()=>{d||u(null)},[d]),l.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]);const f=t?.membership,S=f?.status==="self_hosted"||f?.hosting_mode==="self_hosted",_=[...t?.conflict_orders||[],...t?.pending_orders||[]].some(L=>L.retry_payment_conflict_at),w=!S&&t?.subscriptions?.find(L=>["active","trialing","past_due","paused","canceling"].includes(L.status)),A=!S&&(w?w.provider==="waffo":t?.payments?.some(L=>L.provider==="waffo")),T=w&&!w.cancel_at_period_end&&w.status!=="canceling",b=T&&w.status!=="paused",P=w?.next_billed_at,U=P&&Number.isFinite(Date.parse(P));l.useEffect(()=>{h&&t&&!T&&(m(null),v(null))},[t,h,T]);const F=S?null:f?.status==="trial"?f.trial_ends_at:f?.status==="transition"?f.transition_ends_at:f?.expires_at,K=async L=>{if(!k.current){k.current=!0,j(!0),v(null);try{await L()}catch(ee){C.current&&v(ee)}finally{k.current=!1,j(!1)}}},$=()=>K(async()=>{const L=await Y("portal",{auth:s.getAccessToken,body:w?{subscription_id:w.provider_subscription_id}:{}});C.current&&await va(L.url||L.portal_url)}),Z=()=>K(async()=>{await Y("cancel",{auth:s.getAccessToken,body:{subscription_id:h}}),C.current&&(m(null),await r())}),J=vs(f,F),re=A&&!w||f?.can_read_cloud||!S&&t?.gift_redemption_available===!0;return s?.signedIn?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("section",{"aria-label":a("cloud.membership.title"),className:"tt-cloud-theme space-y-3",children:[t?.environment==="sandbox"?e.jsx(z,{children:a("cloud.catalog.sandbox")}):null,_?e.jsx(St,{showBillingLink:!1}):null,e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-3 gap-y-2",children:[g?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:g}):null,!g&&c?e.jsxs("h2",{className:"inline-flex items-center gap-2 text-base font-semibold",children:[e.jsx(se,{size:18,className:"text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),a("cloud.membership.title")]}):null,J?e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:J}):null]}),e.jsx(R,{onClick:r,variant:"ghost",size:"sm",className:"!size-10 shrink-0 !p-0",disabled:n,"aria-label":a("cloud.action.refresh_membership"),children:e.jsx(be,{size:15,className:n?"motion-safe:animate-spin":void 0,"aria-hidden":!0})})]}),f?.status==="expired"?e.jsx("p",{className:"mt-3 max-w-2xl text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:f.can_read_cloud?a("cloud.membership.read_only",{date:G(f.read_only_until)}):a("cloud.membership.expired_detail")}):null,f?e.jsx(Ct,{userId:s.user?.id,membership:f,subscriptions:t?.subscriptions,className:"mt-3"}):null,!f&&n?e.jsx("p",{role:"status",className:"mt-3 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.catalog.loading")}):null,w?e.jsx("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-3",children:w?e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:w.status==="paused"?a("cloud.membership.renewal_paused"):w.status==="past_due"?a("cloud.membership.payment_due"):b?U?a("cloud.membership.renews",{date:G(P)}):a("cloud.membership.renewal_unknown"):a("cloud.membership.renewal_off")}),T?e.jsx(R,{"aria-expanded":!!h,"aria-controls":h?"cloud-cancel-confirm":void 0,onClick:()=>m(L=>L===w.provider_subscription_id?null:w.provider_subscription_id),variant:"ghost",size:"sm",className:"!h-10 !px-2",disabled:N,children:a("cloud.action.cancel_renewal")}):null]}):null}):null,h?e.jsxs("div",{id:"cloud-cancel-confirm",className:"mt-4 rounded-lg border border-oai-gray-200 p-4 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6",children:F?a("cloud.cancel.detail",{date:G(F)}):a("cloud.cancel.no_term")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(R,{onClick:Z,variant:"secondary",disabled:N,children:a("cloud.cancel.confirm")}),e.jsx(R,{onClick:()=>m(null),variant:"ghost",disabled:N,children:a("cloud.action.keep")})]})]}):null,i?e.jsx("div",{className:"mt-4",children:e.jsx(z,{error:i,onRetry:r,context:"account"})}):null,x&&p!=="billing"?e.jsx("div",{className:"mt-4",children:e.jsx(z,{error:x,context:"account"})}):null]})]}),f?e.jsx(pe,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-3",children:e.jsx(js,{auth:s,machineLimit:f.machine_limit,accountRevision:t,selfHosted:S})}):null,re||t&&!S||o?e.jsx(pe,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-2",children:e.jsxs("section",{"aria-label":a("cloud.membership.tools_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:[S?null:w?e.jsxs("button",{type:"button",onClick:$,disabled:N,className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 disabled:opacity-50 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(se,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.manage_subscription")}),e.jsx(De,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}):e.jsxs(ne,{to:"/cloud",className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(se,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.subscribe")}),e.jsx(Et,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}),t&&!S?e.jsxs(We,{open:p==="billing",onOpenChange:L=>u(L?"billing":null),title:a("cloud.billing.title"),icon:Ra,wide:!0,children:[x?e.jsx("div",{className:"mb-3",children:e.jsx(z,{error:x,context:"account"})}):null,e.jsx(ks,{userId:s.user?.id,recent:ya(s.user?.id),pendingOrders:t?.pending_orders,conflictOrders:t?.conflict_orders,payments:t.payments,footerActions:A&&!w?e.jsx("div",{className:"flex items-center gap-0.5",children:e.jsxs(R,{onClick:$,variant:"ghost",size:"sm",className:"!h-10 !px-0",disabled:N,children:[a("cloud.action.view_bills"),e.jsx(De,{size:14,className:"ml-2","aria-hidden":!0})]})}):null})]}):null,f?.can_read_cloud?e.jsx(ga,{auth:s,layout:"settings-row",dialogOpen:p==="export",onDialogOpenChange:L=>u(L?"export":null)}):null,e.jsx(xs,{account:t,auth:s,refresh:r,layout:"settings-row",dialogOpen:p==="redeem",onDialogOpenChange:L=>u(L?"redeem":null)}),o?e.jsx("section",{children:o}):null]})}):null]}):e.jsxs("div",{className:"space-y-4",children:[g?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:g}):null,e.jsxs(pe,{className:"tt-cloud-theme",children:[!g&&c?e.jsx("h2",{className:"text-base font-semibold",children:a("cloud.membership.title")}):null,e.jsx("p",{className:`${!g&&c?"mt-2 ":""}text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400`,children:a("cloud.membership.signed_out")}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:e.jsx(R,{onClick:()=>y({subtitle:a("cloud.membership.signed_out")}),children:a("cloud.action.sign_in_continue")})})]})]})}function Ss({settings:t,active:s=!0}={}){return t?e.jsx(lt,{settings:t,active:s}):e.jsx(Cs,{active:s})}function Cs({active:t}){const s=ke();return e.jsx(lt,{settings:s,active:t})}function lt({settings:t,active:s}){return e.jsx(Ns,{showTitle:!1,heading:a("settings.section.cloud"),active:s,syncControl:t.showLocalCloudSync?e.jsx(Es,{settings:t}):null})}function Es({settings:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-11 items-center justify-between gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-3 text-sm font-medium",children:[e.jsx(be,{size:16,className:"shrink-0","aria-hidden":!0}),a("settings.account.cloudSync")]}),e.jsx("span",{className:"tt-cloud-theme tt-cloud-sync-control inline-flex","aria-busy":t.cloudSyncPending||void 0,children:e.jsx(D,{checked:t.cloudSyncOn,disabled:t.cloudSyncPending,onChange:()=>(t.cloudSyncOn?Ce(t.userId):Lt(t.userId,"sync"),t.handleCloudSyncToggle()),ariaLabel:a("settings.account.cloudSync")})})]}),t.cloudSyncOn&&t.cloudSyncPending?e.jsxs("p",{role:"status",className:"flex items-center gap-2 py-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Pa,{size:14,className:"motion-safe:animate-spin","aria-hidden":!0}),a("settings.account.cloudSyncPending")]}):null,t.cloudSyncOn&&t.cloudSyncError&&!t.cloudSyncPending?e.jsx("div",{className:"tt-cloud-theme py-3",children:e.jsx(z,{role:"alert",onRetry:t.handleCloudSyncRetry,children:a("settings.account.cloudSyncError")})}):null,e.jsx(Tt,{userId:t.userId,panel:"sync",localHost:!0,className:"py-3",onContinueLocal:()=>{Ce(t.userId),t.cloudSyncOn&&t.handleCloudSyncDisable()}})]})}function Ps(){return[{value:"light",label:a("settings.appearance.theme.light"),Icon:Rt},{value:"dark",label:a("settings.appearance.theme.dark"),Icon:Dt},{value:"system",label:a("settings.appearance.theme.system"),Icon:ye}]}function Os(){return[{value:Mt,label:a("settings.appearance.language.system")},{value:$t,label:a("settings.appearance.language.english")},{value:zt,label:a("settings.appearance.language.chinese")},{value:Ft,label:a("settings.appearance.language.traditional_chinese")},{value:Ht,label:a("settings.appearance.language.japanese")},{value:Bt,label:a("settings.appearance.language.korean")},{value:Vt,label:a("settings.appearance.language.german")}]}function As(t){if(!t)return null;try{const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleString()}catch{return null}}function Ls(t,s){const n=a(`settings.appearance.currency.rate_source.${t}`),i=As(s),r=i?a("settings.appearance.currency.rate_updated",{when:i}):a("settings.appearance.currency.rate_never");return`${n} · ${r}`}function Ts({locale:t,setLocale:s}){const n=Os();return e.jsx(ve,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:e.jsx(Ua,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function Is({currency:t,setCurrency:s}){const n=Gt().map(i=>({value:i.code,label:a(i.labelKey)}));return e.jsx(ve,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function Rs({currency:t,rate:s,rateSource:n,rateFetchedAt:i}){if(t===Ut)return e.jsx(e.Fragment,{children:a("settings.appearance.currency.hint")});const r=Ls(n,i);return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{children:`1 USD = ${s.toFixed(4)} ${t}`}),e.jsx("span",{role:"img","aria-label":r,title:r,className:"inline-flex h-4 w-4 cursor-help items-center justify-center text-oai-gray-400 hover:text-oai-gray-600 dark:text-oai-gray-500 dark:hover:text-oai-gray-300",children:e.jsx(Ze,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function Ds(){const{theme:t,setTheme:s}=It(),{locale:n,setLocale:i}=Ve(),{currency:r,rate:c,rateSource:g,rateFetchedAt:o,setCurrency:d}=Oa(),{mode:y,setMode:p,unitSystem:u,setUnitSystem:x,grouping:v,setGrouping:N}=Aa();return e.jsxs(V,{title:a("settings.section.appearance"),children:[e.jsx(E,{label:a("settings.appearance.theme.label"),hint:a("settings.appearance.theme.hint"),control:e.jsx(q,{options:Ps(),value:t,onChange:s})}),e.jsx(E,{label:a("settings.appearance.language.label"),hint:a("settings.appearance.language.hint"),control:e.jsx(Ts,{locale:n,setLocale:i})}),e.jsx(E,{label:a("settings.appearance.currency.label"),hint:e.jsx(Rs,{currency:r,rate:c,rateSource:g,rateFetchedAt:o}),control:e.jsx(Is,{currency:r,setCurrency:d})}),e.jsx(E,{label:a("settings.appearance.token_format.label"),hint:a("settings.appearance.token_format.hint"),control:e.jsx(q,{options:[{value:me.COMPACT,label:a("settings.appearance.token_format.compact")},{value:me.FULL,label:a("settings.appearance.token_format.full")}],value:y,onChange:p})}),e.jsx(E,{label:a("settings.appearance.token_unit.label"),hint:a("settings.appearance.token_unit.hint"),control:e.jsx(q,{disabled:y!==me.COMPACT,options:[{value:Ee.ENGLISH,label:a("settings.appearance.token_unit.english")},{value:Ee.CHINESE,label:a("settings.appearance.token_unit.chinese")}],value:u,onChange:x})}),e.jsx(E,{label:a("settings.appearance.token_grouping.label"),hint:a("settings.appearance.token_grouping.hint"),control:e.jsx(q,{options:[{value:Pe.THOUSAND,label:a("settings.appearance.token_grouping.thousand")},{value:Pe.WAN,label:a("settings.appearance.token_grouping.wan")}],value:v,onChange:N})})]})}function he({labelKey:t}){return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:a(t)}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:a("qpd.card.badge")})]})}function Gs(){const{enabled:t,toggle:s}=pa(),{enabled:n,toggle:i}=ha(),{available:r,settings:c,setSetting:g}=ie(),o=r&&!!c?.dynamicIslandSupported,d=!!c?.dynamicIslandEnabled;return e.jsxs(V,{title:a("settings.section.labs"),children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.island.label"}),hint:a("settings.labs.island.hint"),control:e.jsx(D,{checked:d,onChange:()=>g("dynamicIslandEnabled",!d),ariaLabel:a("settings.labs.island.aria")})}),d&&e.jsx(E,{label:a("settings.labs.island_hide_menubar.label"),hint:a("settings.labs.island_hide_menubar.hint"),control:e.jsx(D,{checked:!!c?.hideMenuBarIcon,onChange:()=>g("hideMenuBarIcon",!c?.hideMenuBarIcon),ariaLabel:a("settings.labs.island_hide_menubar.aria")})})]}),e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.qpd.label"}),hint:a("settings.labs.qpd.hint"),control:e.jsx(D,{checked:t,onChange:s,ariaLabel:a("settings.labs.qpd.aria")})}),e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.sessions.label"}),hint:a("settings.labs.sessions.hint"),control:e.jsx(D,{checked:n,onChange:i,ariaLabel:a("settings.labs.sessions.aria")})})]})}function Us(){const{available:t,settings:s,setSetting:n,runAction:i}=ie();if(!t)return null;const r=Ke(),c=!!s?.launchAtLogin,g=s?.toastOnReset!==!1,o=s?.confettiOnReset!==!1,d=s?.launchAtLoginSupported!==!1,y=s?.autoUpdateEnabled!==!1,p=s?.updateStatus||null,u=!!s?.updateBusy,x=!!s?.isSyncing;return e.jsxs(V,{title:a("settings.section.menubar"),children:[r?null:e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("settings.menubar.appearance"),hint:a("settings.menubar.appearanceHint"),control:e.jsxs(ne,{to:"/widgets",className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 no-underline transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[a("settings.menubar.appearanceLink"),e.jsx(Ta,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),e.jsx(E,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(D,{checked:g,onChange:()=>n("toastOnReset",!g),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(E,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(D,{checked:o,onChange:()=>n("confettiOnReset",!o),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),d?e.jsx(E,{label:a("settings.menubar.launchAtLogin"),hint:a("settings.menubar.launchAtLoginHint"),control:e.jsx(D,{checked:c,onChange:()=>n("launchAtLogin",!c),ariaLabel:a("settings.menubar.launchAtLogin")})}):null,e.jsx(E,{label:a("settings.menubar.syncNow"),hint:a("settings.menubar.syncNowHint"),control:e.jsxs("button",{type:"button",onClick:()=>i("syncNow"),disabled:x,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(be,{className:B("h-3.5 w-3.5",x&&"animate-spin"),"aria-hidden":!0}),x?a("settings.menubar.syncing"):a("settings.menubar.syncNow")]})}),e.jsx(E,{label:a("settings.menubar.autoUpdate"),hint:a("settings.menubar.autoUpdateHint"),control:e.jsx(D,{checked:y,onChange:()=>n("autoUpdateEnabled",!y),ariaLabel:a("settings.menubar.autoUpdate")})}),e.jsx(E,{label:a("settings.menubar.updates"),hint:p||void 0,control:e.jsxs("button",{type:"button",onClick:()=>i("checkForUpdates"),disabled:u,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(Ia,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.menubar.checkUpdates")]})})]})}function Ms(t,s){function n(c){return c.replace(/^v/,"").split(".").map(Number)}const i=n(t),r=n(s);for(let c=0;c<Math.max(i.length,r.length);c++){const g=i[c]||0,o=r[c]||0;if(g<o)return!0;if(g>o)return!1}return!1}function $s(){const{available:t,settings:s,runAction:n}=ie(),i=t&&s?.version,r=s?.platform||"macos",[c,g]=fe.useState(!1),[o,d]=fe.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:y}=Ve(),p="1.3.5",u=async()=>{g(!0);try{const h=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!h.ok)throw new Error("Failed to fetch");const m=await h.json(),k=m.tag_name;Ms(p,k)?d({open:!0,latestVersion:k,htmlUrl:m.html_url}):Oe({title:a("settings.menubar.updates.upToDate")})}catch(h){console.error("Check updates failed:",h),Oe({title:a("settings.menubar.updates.failed")})}finally{g(!1)}},x=a("settings.menubar.updates.modalTitle"),v=a("settings.menubar.updates.modalDescription",{version:o.latestVersion}),N=a("settings.menubar.updates.modalConfirm"),j=a("settings.menubar.updates.modalCancel");return e.jsxs("div",{className:"mt-6 flex flex-col items-center justify-center gap-4 text-xs text-oai-gray-500 dark:text-oai-gray-500",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[i?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:r==="windows"?a("settings.menubar.updates.footerCore",{version:s.version}):a("settings.menubar.updates.footerCombined",{barVersion:s.version,coreVersion:p})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:()=>n("openAbout"),className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:"GitHub"}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a("settings.menubar.updates.footerCore",{version:p})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:u,disabled:c,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:c?a("settings.menubar.updates.checking"):a("settings.menubar.checkUpdates")}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}),e.jsxs("a",{href:Kt,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:[e.jsx(qt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.footer.statusPage")]})]}),e.jsx(La,{open:o.open,title:x,description:v,confirmLabel:N,cancelLabel:j,onConfirm:()=>{window.open(o.htmlUrl,"_blank"),d(h=>({...h,open:!1}))},onCancel:()=>d(h=>({...h,open:!1}))})]})}const zs=()=>[{value:"system",label:a("settings.network.mode.system")},{value:"manual",label:a("settings.network.mode.manual")},{value:"off",label:a("settings.network.mode.off")}],Fs=()=>[{value:"http",label:a("settings.network.protocol.http")},{value:"https",label:a("settings.network.protocol.https")},{value:"socks5",label:a("settings.network.protocol.socks5")}],Ge="w-full rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white";function Ue(t){const s={},n=String(t.host||"").trim();(!n||/:\/\//.test(n)||n.includes("/"))&&(s.host=a("settings.network.error.host"));const i=String(t.port??"").trim(),r=Number(i);return(!i||!/^\d+$/.test(i)||!Number.isInteger(r)||r<1||r>65535)&&(s.port=a("settings.network.error.port")),s}function Hs({proxySettings:t}){const{config:s,save:n,testConnection:i}=t,[r,c]=l.useState(()=>({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})),[g,o]=l.useState({}),[d,y]=l.useState(!1),[p,u]=l.useState(""),[x,v]=l.useState(null),[N,j]=l.useState(!1),[h,m]=l.useState(null);l.useEffect(()=>{c({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})},[s.mode,s.protocol,s.host,s.port]);const k=l.useMemo(()=>s.effective==="manual"?a("settings.network.effective.manual"):s.effective==="env"?a("settings.network.effective.env"):s.effective==="system"?a("settings.network.effective.system"):s.effective==="blocked"?a("settings.network.effective.blocked"):a("settings.network.effective.none"),[s.effective]),C=_=>{c(w=>({...w,..._})),o({}),u(""),v(null),m(null)},f=async()=>{if(r.mode==="manual"){const _=Ue(r);if(Object.keys(_).length){o(_);return}}y(!0),u(""),v(null);try{await n(r),u("saved")}catch(_){u("error"),v(_)}finally{y(!1)}},S=async()=>{const _=Ue(r);if(Object.keys(_).length){o(_);return}j(!0),m(null);try{const w=await i(r);m(w)}catch(w){m({ok:!1,error:w?.message||String(w)})}finally{j(!1)}};return e.jsxs(V,{title:a("settings.section.network"),subtitle:k,children:[s.applyError?e.jsx("p",{role:"alert",className:"mb-3 text-xs text-red-600 dark:text-red-400",children:a("settings.network.apply_error",{error:s.applyError})}):null,e.jsx(E,{label:a("settings.network.mode.label"),hint:a("settings.network.mode.hint"),control:e.jsx(q,{options:zs(),value:r.mode,onChange:_=>C({mode:_})})}),e.jsx(Ye,{initial:!1,children:r.mode==="manual"?e.jsxs(qe.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:[e.jsx(E,{label:a("settings.network.protocol.label"),control:e.jsx(ve,{value:r.protocol,onValueChange:_=>C({protocol:_}),options:Fs(),ariaLabel:a("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),e.jsx(E,{label:a("settings.network.host.label"),hint:g.host,control:e.jsx("input",{type:"text",value:r.host,onChange:_=>C({host:_.target.value}),placeholder:a("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":g.host?!0:void 0,"aria-label":a("settings.network.host.label"),className:Ge})}),e.jsx(E,{label:a("settings.network.port.label"),hint:g.port,control:e.jsx("input",{type:"text",inputMode:"numeric",value:r.port,onChange:_=>C({port:_.target.value}),placeholder:a("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":g.port?!0:void 0,"aria-label":a("settings.network.port.label"),className:Ge})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[e.jsx("button",{type:"button",onClick:S,disabled:N||d,className:"rounded-md border border-oai-gray-200 px-3 py-1.5 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:N?a("settings.network.test.testing"):a("settings.network.test")}),e.jsx("button",{type:"button",onClick:f,disabled:d||N,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})]}),h?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:h.ok?a("settings.network.test.ok",{status:String(h.status??"")}):a("settings.network.test.fail",{error:h.error||""})}):null]},"manual-proxy-fields"):e.jsx("div",{className:"flex justify-end py-3",children:e.jsx("button",{type:"button",onClick:f,disabled:d,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})},"non-manual-save")}),p==="saved"?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.network.saved")}):null,p==="error"?e.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:x?.unprotected?a("settings.network.save_error_unprotected",{error:x?.message||String(x||"")}):a("settings.network.save_error",{error:x?.message||String(x||"")})}):null]})}const ct="/functions/tokentracker-proxy-config",Bs="/functions/tokentracker-proxy-test",Vs={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function dt(t){return!t||typeof t.mode!="string"?null:{mode:t.mode,protocol:typeof t.protocol=="string"?t.protocol:"http",host:typeof t.host=="string"?t.host:"",port:t.port==null||t.port===0?"":String(t.port),effective:typeof t.effective=="string"?t.effective:"none",applyError:typeof t.applyError=="string"&&t.applyError.trim()?t.applyError:null}}async function Ks(){const t=await fetch(ct,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!t.ok)return null;const s=await t.json().catch(()=>null);return dt(s)}async function Me(){const{getLocalApiAuthHeaders:t}=await Wt(async()=>{const{getLocalApiAuthHeaders:s}=await import("./__vite-browser-external-2g_4s3ot.js").then(n=>n.dZ);return{getLocalApiAuthHeaders:s}},__vite__mapDeps([0,1]));return t()}function qs(){const[t,s]=l.useState(!1),[n,i]=l.useState(!0),[r,c]=l.useState(Vs);l.useEffect(()=>{if(!ba()){s(!1),i(!1);return}let d=!1;return(async()=>{try{const y=await Ks();if(d)return;if(!y){s(!1),i(!1);return}c(y),s(!0),i(!1)}catch{d||(s(!1),i(!1))}})(),()=>{d=!0}},[]);const g=l.useCallback(async d=>{const y=await Me(),p=await fetch(ct,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...y},cache:"no-store",body:JSON.stringify({mode:d.mode,protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),u=await p.json().catch(()=>null);if(!p.ok){const v=u&&typeof u.error=="string"?u.error:`HTTP ${p.status}`;throw new Error(v)}const x=dt(u);if(x&&c(x),u&&u.ok===!1){const v=u&&typeof u.applyError=="string"&&u.applyError||u&&typeof u.error=="string"&&u.error||`HTTP ${p.status}`,N=new Error(v);throw u.unprotected===!0&&(N.unprotected=!0),N}return x||u},[]),o=l.useCallback(async d=>{const y=await Me(),p=await fetch(Bs,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...y},cache:"no-store",body:JSON.stringify({protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),u=await p.json().catch(()=>null);if(!u||typeof u.ok!="boolean")throw new Error(u&&typeof u.error=="string"?u.error:`HTTP ${p.status}`);return u},[]);return{available:t,loading:n,config:r,save:g,testConnection:o}}const I={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",CLOUD:"cloud",LIMITS:"limits",LABS:"labs"},M={PERSONAL:"personal",APP:"app",DEVELOPER:"developer"};function Ws({prefs:t}){return e.jsx(q,{options:[{value:Ie.USED,label:a("limits.settings.display_mode_used")},{value:Ie.REMAINING,label:a("limits.settings.display_mode_remaining")}],value:t.displayMode,onChange:t.setDisplayMode})}function In(){const t=ke(),s=da(),{available:n,settings:i,setSetting:r}=ie(),c=qs(),{available:g}=c,o=i?.toastOnReset!==!1,d=i?.confettiOnReset!==!1,y=Ke()||i?.platform==="windows",[p,u]=Yt(),x=He(),v=p.get("section"),j=Object.values(I).includes(v)&&(v!==I.NATIVE_APP||n)&&(v!==I.NETWORK||g)?v:I.APPEARANCE,h=f=>{const S=new URLSearchParams(p);f===I.APPEARANCE?S.delete("section"):S.set("section",f),u(S,{replace:!0})},m=[{id:I.APPEARANCE,label:a("settings.section.appearance"),description:a("settings.section.appearance.description"),group:M.PERSONAL,Icon:$a,content:e.jsx(Ds,{})},...n?[{id:I.NATIVE_APP,label:a("settings.section.menubar"),description:a("settings.section.menubar.description"),group:M.APP,Icon:ye,content:e.jsx(Us,{})}]:[],...g?[{id:I.NETWORK,label:a("settings.section.network"),description:a("settings.section.network.description"),group:M.APP,Icon:Zt,content:e.jsx(Hs,{proxySettings:c})}]:[],{id:I.ACCOUNT,label:a("settings.section.account"),description:a("settings.section.account.description"),group:M.PERSONAL,Icon:za,content:e.jsx(us,{settings:t})},{id:I.CLOUD,label:a("settings.section.cloud"),description:a("settings.section.cloud.description"),group:M.PERSONAL,Icon:se,content:e.jsx(Ss,{settings:t,active:j===I.CLOUD})},{id:I.LIMITS,label:a("settings.section.limits"),description:a("settings.section.limits.description"),group:M.APP,Icon:Jt,content:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(V,{title:a("settings.section.limits"),children:[e.jsx(E,{label:a("limits.settings.display_mode_label"),control:e.jsx(Ws,{prefs:s})}),y?null:e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(D,{checked:o,disabled:!n,onChange:()=>r("toastOnReset",!o),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(E,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(D,{checked:d,disabled:!n,onChange:()=>r("confettiOnReset",!d),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),e.jsx(E,{label:a("settings.limits.showSubscriptions"),hint:a("settings.limits.showSubscriptionsHint"),control:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>x("/limits?openSubscriptions=1"),"aria-label":a("limits.page.openSubscriptions"),title:a("limits.page.openSubscriptions"),className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(Qt,{size:14,"aria-hidden":!0})}),e.jsx(D,{checked:s.showSubscriptions!==!1,onChange:()=>s.setShowSubscriptions(!s.showSubscriptions),ariaLabel:a("settings.limits.showSubscriptions")})]})})]}),e.jsx(V,{title:a("settings.limits.providers"),children:e.jsx(Va,{prefs:s})})]})},{id:I.LABS,label:a("settings.section.labs"),description:a("settings.section.labs.description"),group:M.DEVELOPER,Icon:Da,content:e.jsx(Gs,{})}],k=[{id:M.PERSONAL,label:a("settings.nav.group.personal")},{id:M.APP,label:a("settings.nav.group.app")},{id:M.DEVELOPER,label:a("settings.nav.group.developer")}].map(f=>({...f,sections:m.filter(S=>S.group===f.id)})).filter(f=>f.sections.length>0);let C=m[0];for(const f of m)if(f.id===j){C=f;break}return e.jsx("div",{className:B("flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",j===I.CLOUD&&"tt-cloud-settings"),children:e.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:e.jsxs("div",{className:"mx-auto w-full max-w-5xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-7 max-w-2xl",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:a("settings.page.title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:a("settings.page.subtitle")})]}),e.jsxs("div",{className:"tt-settings-sections grid min-w-0 gap-6 md:grid-cols-[11rem_minmax(0,1fr)] md:gap-8",children:[e.jsx("aside",{className:"min-w-0 rounded-xl border border-oai-gray-200 bg-oai-gray-50/70 p-2 dark:border-oai-gray-800 dark:bg-oai-gray-900/60 md:border-0 md:bg-transparent md:p-0 md:dark:bg-transparent",children:e.jsx("nav",{"aria-label":a("settings.page.title"),className:"flex gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden md:sticky md:top-6 md:flex-col md:gap-4 md:overflow-visible",children:k.map(({id:f,label:S,sections:_})=>e.jsxs("div",{className:"flex shrink-0 gap-1 md:block",children:[e.jsx("div",{className:"hidden px-3 pb-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-oai-gray-400 dark:text-oai-gray-500 md:block",children:S}),e.jsx("div",{className:"flex gap-1 md:flex-col",children:_.map(({id:w,label:A,Icon:T})=>{const b=j===w;return e.jsxs("button",{id:`settings-nav-${w}`,type:"button","aria-current":b?"page":void 0,"aria-controls":`settings-panel-${w}`,onClick:()=>h(w),className:B("inline-flex min-h-10 min-w-max shrink-0 items-center gap-1.5 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand-500 md:w-full md:min-w-0 md:gap-2 md:px-3",b?"bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:bg-oai-gray-50 hover:text-oai-gray-900 dark:text-oai-gray-400 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200"),children:[e.jsx(T,{className:B("h-4 w-4 shrink-0",b?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:A})]},w)})})]},f))})}),e.jsxs("div",{className:"min-w-0",children:[j!==I.CLOUD?e.jsxs("div",{className:"mb-4 border-b border-oai-gray-200 pb-4 dark:border-oai-gray-800",children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight text-oai-black dark:text-white",children:C.label}),e.jsx("p",{className:"mt-1 text-sm leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:C.description})]}):null,m.map(({id:f,label:S,content:_})=>e.jsx("section",{id:`settings-panel-${f}`,"aria-labelledby":`settings-nav-${f}`,"aria-label":S,"data-settings-panel":f,hidden:j!==f,children:_},f)),e.jsx($s,{})]})]})]})})})}export{In as SettingsPage};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-DWN9Fb-H.js","assets/__vite-browser-external-LpFw4zXh.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as W,j as e,c as a,y as B,a as mt,r as l,cm as gt,cn as pt,co as ht,cp as ft,a7 as X,cq as we,bu as xt,cr as bt,bt as Ne,cs as de,aP as $e,ct as yt,cu as vt,ag as ze,u as Fe,V as fe,x as jt,B as R,a8 as G,cv as kt,a9 as z,ax as wt,cw as ue,a5 as Y,aB as Nt,a1 as _t,af as St,at as se,R as be,cx as Ct,L as ne,aM as Et,au as Pt,al as Ot,am as ye,ac as At,d as He,aa as xe,ab as Be,cy as _e,cz as Se,cA as Ce,cB as Lt,cC as Tt,ao as It,Z as Ve,l as me,cD as Ee,k as Pe,cE as Rt,cF as Dt,cG as Gt,z as Ut,cH as Mt,cI as $t,cJ as zt,cK as Ft,cL as Ht,cM as Bt,cN as Vt,v as Ke,cO as Kt,cP as qt,bc as Oe,_ as Wt,e as Yt,cQ as Zt,cR as Jt,bw as Qt}from"./__vite-browser-external-DWN9Fb-H.js";import{a as Xt,b as Ae,s as ea,K as ta,P as aa,D as sa,c as na,S as ia,v as ra,u as oa,C as la}from"./sortable.esm-BCn2Ms6R.js";import{a as ca}from"./modifiers.esm-CYLYBECB.js";import{d as Le,l as Te,u as da,b as Ie}from"./use-limits-display-prefs-BOk5f-HM.js";import{P as ua}from"./ProviderIcon-ClHXNkQ0.js";import{a as E,S as q,b as V,T as D}from"./Controls-BmT6-x_L.js";import{m as qe}from"./react-CCNSVHEA.js";import{P as ma,C as We,a as ga,u as pa,b as ha}from"./CloudUsageExport-jXdoiD0e.js";import{C as fa}from"./check-CSZvcC3X.js";import{C as xa,i as ba}from"./host-mode-xzpMLcwP.js";import{A as Ye}from"./index-DX7nYrHb.js";import{r as ya,C as ge,o as va}from"./cloud-checkout-z_eDVwm6.js";import{G as Re}from"./gift-CCp4Hh50.js";import{C as ja}from"./chevron-down-CsiGcG0G.js";import{C as pe}from"./Card-C9FjyAwh.js";import{E as De}from"./external-link-B8E8tbB3.js";import{a as ka,P as wa}from"./play-CUrMOLtq.js";import{I as Ze}from"./info-B3NKYwWG.js";import{a as Na,b as _a,c as Sa,d as Ca,e as Ea}from"./TooltipPopup-DMliWhoK.js";import{L as Pa}from"./loader-circle-Cm5Nsgp-.js";import{u as Oa}from"./useCurrency-CbCnjf-N.js";import{u as Aa}from"./useTokenFormat-Bq-rwuKa.js";import{S as ve}from"./Select-BHEXdYHu.js";import{u as ie}from"./use-native-settings-B2gc_m9W.js";import{C as La}from"./ConfirmModal-DRhgBoGE.js";import{A as Ta}from"./arrow-up-right-DxY0neJ4.js";import{D as Ia}from"./download-DqLpubIF.js";import"./DialogTitle-B9NNSz5p.js";import"./composite-Cq0CmNAv.js";import"./store-B22kwLs0.js";import"./SelectItemText-aaQK_QIt.js";import"./usePositioner-MepYlL0A.js";import"./safePolygon-DsolkMUX.js";import"./DialogClose-DjnC3P4V.js";import"./DateRangePopover-DuqNLatr.js";import"./calendar-days-bzh7-lab.js";import"./PopoverPopup-BzfELnIC.js";import"./DialogDescription-yy_QHg7O.js";const Je={name:"credit-card",size:24,node:[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}],["path",{d:"M6 14h2",key:"mk7k0u"}]]};Je.node;const Ra=W(Je);const Qe={name:"flask-conical",size:24,node:[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]]};Qe.node;const Da=W(Qe);const Xe={name:"grip-vertical",size:24,node:[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]};Xe.node;const Ga=W(Xe);const et={name:"languages",size:24,node:[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]};et.node;const Ua=W(et);const tt={name:"log-out",size:24,node:[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]]};tt.node;const Ma=W(tt);const at={name:"palette",size:24,node:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]};at.node;const $a=W(at);const st={name:"user-round",size:24,node:[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],aliases:["user-2"]};st.node;const za=W(st),Fa="shrink-0 text-oai-gray-900 dark:text-oai-gray-200";function Ha({checked:t,onChange:s,ariaLabel:n}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":n,onClick:s,className:B("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",t?"bg-oai-brand-500":"bg-oai-gray-300 dark:bg-oai-gray-700"),children:e.jsx("span",{className:B("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",t?"translate-x-[18px]":"translate-x-[3px]")})})}function Ba({id:t,visible:s,onToggle:n}){const{attributes:i,listeners:r,setNodeRef:c,transform:g,transition:o,isDragging:d}=oa({id:t}),y={transform:la.Transform.toString(g)||void 0,transition:o,zIndex:d?20:void 0};return e.jsxs("div",{ref:c,style:y,className:B("flex items-center gap-3 py-2 rounded-md select-none touch-none","cursor-grab active:cursor-grabbing","hover:bg-oai-gray-100/60 dark:hover:bg-oai-gray-800/60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",d&&"relative bg-oai-gray-100 dark:bg-oai-gray-800"),...i,...r,children:[e.jsx(Ga,{className:"h-4 w-4 shrink-0 text-oai-gray-400 dark:text-oai-gray-500",strokeWidth:1.75,"aria-hidden":!0}),Le(t)?e.jsx(ua,{provider:Le(t),size:18,className:B("pointer-events-none",Fa)}):null,e.jsx("span",{className:"flex-1 text-sm text-oai-gray-900 dark:text-oai-gray-200",children:Te(t)}),e.jsx("div",{onPointerDown:p=>p.stopPropagation(),children:e.jsx(Ha,{checked:s,onChange:n,ariaLabel:`${a("limits.settings.toggle_visible")}: ${Te(t)}`})})]})}function Va({prefs:t}){const{order:s,visibility:n,toggle:i,setAllVisible:r,moveToward:c}=t,g=s.every(u=>n[u]!==!1),o=s.every(u=>n[u]===!1),d=s.filter(u=>n[u]!==!1).length,y=Xt(Ae(aa,{activationConstraint:{distance:6}}),Ae(ta,{coordinateGetter:ea})),p=({active:u,over:x})=>{x&&u.id!==x.id&&c(u.id,x.id)};return e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("limits.settings.bulk_visibility"),hint:a("limits.settings.enabled_count",{enabled:d,total:s.length}),control:e.jsx(q,{options:[{value:"enabled",label:a("limits.settings.enable_all")},{value:"disabled",label:a("limits.settings.disable_all")}],value:g?"enabled":o?"disabled":null,onChange:u=>r(u==="enabled")})}),e.jsx(sa,{sensors:y,collisionDetection:na,modifiers:[ca],onDragEnd:p,children:e.jsx(ia,{items:s,strategy:ra,children:e.jsx("div",{className:"flex flex-col",children:s.map(u=>e.jsx(Ba,{id:u,visible:n[u]!==!1,onToggle:()=>i(u)},u))})})})]})}function Ka(t){if(!t||typeof t!="object")return"";const s=t.user_metadata&&typeof t.user_metadata=="object"?t.user_metadata:{},n=t.profile&&typeof t.profile=="object"?t.profile:{},i=s.full_name||s.name||n.name||s.user_name||s.preferred_username;return typeof i=="string"&&i.trim()?i.trim():typeof t.email=="string"&&t.email.includes("@")?t.email.split("@")[0].trim()||t.email.trim():typeof t.email=="string"?t.email.trim():""}function qa(t){return!t||typeof t!="object"?"":typeof t.email=="string"?t.email.trim():""}function Wa(t){const s=typeof t=="string"?t.trim():"";if(!s)return null;const n=s.match(/^@?([A-Za-z0-9][A-Za-z0-9-]{0,38})$/),i=s.match(/^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/?$/i),r=n?.[1]||i?.[1];return r?`https://github.com/${r}`:null}function je(t,s){console.warn(`[tokentracker] settings ${t}:`,s)}function Ya(t,s,n,i){const[r,c]=l.useState(()=>X()),g=s&&n&&ze(),o=l.useMemo(()=>({active:!0,busy:!1}),[t,s,n,i]),d=l.useRef(o);d.current=o;const[y,p]=l.useState(null),u=y?.scope===o?y:null;l.useEffect(()=>{o.active=!0;const j=()=>{const m=X();c(m),m||p(k=>k?.scope===o?{...k,error:null}:k)},h=()=>{p(m=>m?.scope===o?{...m,error:null}:m),de(i,"cloud-sync")};return j(),window.addEventListener("tt.cloudSyncChanged",j),window.addEventListener("storage",j),window.addEventListener(we,h),()=>{o.active=!1,window.removeEventListener("tt.cloudSyncChanged",j),window.removeEventListener("storage",j),window.removeEventListener(we,h)}},[o,i]);const x=l.useCallback(async()=>{if(!g||!X()||o.busy||!o.active||d.current!==o)return;o.busy=!0,p({scope:o,pending:!0,error:null});const j=()=>o.active&&d.current===o&&X();try{await xt(()=>t())}catch(h){if(!j())return;["cloud_membership_required","cloud_read_only_expired","cloud_history_window_exceeded","cloud_machine_limit","machine_limit_exceeded","cloud_machine_paused"].includes(h?.code)?bt(i,h.code,h.membership,"cloud-sync"):p({scope:o,pending:!0,error:{code:"billing_network_error"}}),je("cloud sync",h)}finally{o.busy=!1,o.active&&d.current===o&&p(h=>h?.scope===o?{...h,pending:!1}:h)}},[g,o,t,i]),v=l.useCallback(async()=>{if(!g||o.busy||!o.active||d.current!==o)return;const j=!X();p({scope:o,pending:!1,error:null}),Ne(j),c(j),j?await x():de(i,"cloud-sync")},[g,o,x,i]),N=l.useCallback(()=>{!g||!o.active||d.current!==o||(Ne(!1),c(!1),p(j=>j?.scope===o?{...j,error:null}:j),de(i,"cloud-sync"))},[g,o,i]);return{cloudSyncOn:r,cloudSyncPending:!!u?.pending,cloudSyncError:u?.error,handleCloudSyncToggle:v,handleCloudSyncRetry:x,handleCloudSyncDisable:N,showLocalCloudSync:g}}function Za(t){const[s,n]=l.useState(!1),[i,r]=l.useState(!1),[c,g]=l.useState(!1),[o,d]=l.useState(!1),[y,p]=l.useState(null),[u,x]=l.useState(!1),[v,N]=l.useState(""),[j,h]=l.useState(!1),[m,k]=l.useState(""),[C,f]=l.useState(""),[S,_]=l.useState(!1),[w,A]=l.useState(null),T=l.useMemo(()=>Ka(t),[t]),b=l.useMemo(()=>qa(t),[t]),P=l.useMemo(()=>typeof t?.id=="string"?t.id.trim():"",[t]),U=l.useMemo(()=>({setAnonymousOn:r,setCustomDisplayName:p,setGithubUrl:k,setProfileLoading:g,setPublicProfileOn:n,setShowGithubOn:h}),[]);return{anonymousOn:i,customDisplayName:y,displayName:T,editingGithub:S,editingName:u,email:b,githubError:w,githubInput:C,githubUrl:m,loadSetters:U,nameInput:v,profileLoading:c,profileSaving:o,publicProfileOn:s,setAnonymousOn:r,setCustomDisplayName:p,setEditingGithub:_,setEditingName:x,setGithubError:A,setGithubInput:f,setGithubUrl:k,setNameInput:N,setProfileLoading:g,setProfileSaving:d,setPublicProfileOn:n,setShowGithubOn:h,showGithubOn:j,userId:P}}function Ja(t,s,n){l.useEffect(()=>{if(!s)return;let i=!0;return n.setProfileLoading(!0),(async()=>{try{const r=await $e({getAccessToken:t});if(!i||!r)return;const c=await yt({accessToken:r});if(!i)return;n.setPublicProfileOn(!!c?.enabled),n.setAnonymousOn(!!c?.anonymous),c?.display_name&&n.setCustomDisplayName(c.display_name),n.setShowGithubOn(!!c?.show_github_url),n.setGithubUrl(c?.github_url||"")}catch(r){je("load public profile",r)}finally{i&&n.setProfileLoading(!1)}})(),()=>{i=!1}},[t,s,n])}function Qa(t,s,n){return l.useCallback(async(i,{label:r,onError:c,onSuccess:g}={})=>{if(!n||s.profileSaving)return!1;s.setProfileSaving(!0);try{const o=await $e({getAccessToken:t});if(!o)return!1;const d=await vt({accessToken:o,...i});return g?.(d),!0}catch(o){return c?c(o):je(r||"mutate profile",o),!1}finally{s.setProfileSaving(!1)}},[t,s,n])}function Xa(t,s){return{anonymousOn:t.anonymousOn,customDisplayName:t.customDisplayName,displayName:t.displayName,editingName:t.editingName,handleAnonymousToggle:s.handleAnonymousToggle,handleSaveName:s.handleSaveName,nameInput:t.nameInput,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingName:t.setEditingName,setNameInput:t.setNameInput,startEditingName:s.startEditingName}}function es(t,s){return{editingGithub:t.editingGithub,githubError:t.githubError,githubInput:t.githubInput,githubUrl:t.githubUrl,handleSaveGithub:s.handleSaveGithub,handleShowGithubToggle:s.handleShowGithubToggle,profileLoading:t.profileLoading,profileSaving:t.profileSaving,setEditingGithub:t.setEditingGithub,setGithubError:t.setGithubError,setGithubInput:t.setGithubInput,showGithubOn:t.showGithubOn,startEditingGithub:s.startEditingGithub}}function ts(t,s){const n=l.useCallback(async()=>{const r=!t.publicProfileOn;await s({enabled:r},{label:"toggle public profile",onSuccess:()=>t.setPublicProfileOn(r)})},[s,t]);return{handleAnonymousToggle:l.useCallback(async()=>{const r=!t.anonymousOn;await s({anonymous:r},{label:"toggle anonymous",onSuccess:()=>t.setAnonymousOn(r)})},[s,t]),handlePublicProfileToggle:n}}function as(t,s,n){const i=l.useCallback(async()=>{const c=t.nameInput.trim().slice(0,50);c&&await s({display_name:c},{label:"save display name",onSuccess:()=>{t.setCustomDisplayName(c),t.setEditingName(!1),n?.()}})},[s,t,n]),r=l.useCallback(()=>{t.setNameInput(t.customDisplayName||t.displayName),t.setEditingName(!0)},[t]);return{handleSaveName:i,startEditingName:r}}function ss(t,s){const n=l.useCallback(async()=>{if(!t.showGithubOn&&!t.githubUrl){t.setEditingGithub(!0),t.setGithubInput(""),t.setGithubError(null);return}const c=!t.showGithubOn;await s({show_github_url:c},{label:"toggle GitHub profile",onSuccess:()=>t.setShowGithubOn(c)})},[s,t]),i=l.useCallback(async()=>{const c=Wa(t.githubInput);if(t.githubInput.trim()&&!c){t.setGithubError(a("settings.account.githubUrlInvalid"));return}t.setGithubError(null),await s({github_url:c,show_github_url:!!c},{label:"save GitHub profile",onError:g=>t.setGithubError(g?.message||a("settings.account.githubUrlInvalid")),onSuccess:g=>{t.setGithubUrl(g?.github_url||c||""),t.setShowGithubOn(!!c),t.setEditingGithub(!1)}})},[s,t]),r=l.useCallback(()=>{t.setGithubInput(t.githubUrl),t.setGithubError(null),t.setEditingGithub(!0)},[t]);return{handleSaveGithub:i,handleShowGithubToggle:n,startEditingGithub:r}}function ke(){const t=mt();l.useSyncExternalStore(gt,pt,()=>0);const s=ht(t.user?.id),i=!(s.membership?.status==="self_hosted"||s.catalog?.policy?.hosting_mode==="self_hosted")&&(ft()||s.membership?.hosting_mode==="hosted"),r=Za(t.user),c=Ya(t.getAccessToken,t.enabled,t.signedIn,t.user?.id);Ja(t.getAccessToken,t.signedIn&&i,r.loadSetters);const g=Qa(t.getAccessToken,r,i),o=ts(r,g),d=as(r,g,t.refreshDisplayName),y=ss(r,g);return{...t,...c,email:r.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:r.userId,name:Xa(r,{...o,...d}),github:es(r,y),profileLoading:r.profileLoading,profileSaving:r.profileSaving,publicProfileOn:i&&r.publicProfileOn,publicProfileAvailable:i}}function nt({disabled:t,onCancel:s,onSave:n,saveLabel:i=a("settings.account.save")}){return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:n,disabled:t,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:i}),e.jsx("button",{type:"button",onClick:s,className:"rounded-md px-2 py-1.5 text-xs text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:a("settings.account.cancel")})]})}function ns({nameInput:t,setEditingName:s,setNameInput:n,profileSaving:i,handleSaveName:r}){return e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:c=>n(c.target.value),onKeyDown:c=>{c.key==="Enter"&&r(),c.key==="Escape"&&s(!1)},maxLength:50,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.displayName")}),e.jsx(nt,{disabled:i||!t.trim(),onCancel:()=>s(!1),onSave:r,saveLabel:i?a("settings.account.saving"):void 0})]})}function is({githubError:t,githubInput:s,handleSaveGithub:n,profileSaving:i,setEditingGithub:r,setGithubError:c,setGithubInput:g}){return e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:o=>{g(o.target.value),t&&c(null)},onKeyDown:o=>{o.key==="Enter"&&n(),o.key==="Escape"&&(r(!1),c(null))},maxLength:100,autoFocus:!0,className:"flex-1 rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white",placeholder:a("settings.account.githubUrlPlaceholder")}),e.jsx(nt,{disabled:i,onCancel:()=>{r(!1),c(null)},onSave:n,saveLabel:i?a("settings.account.saving"):void 0})]}),t?e.jsx("div",{className:"mt-1.5 text-xs text-red-600 dark:text-red-400",children:t}):null]})}function it({disabled:t=!1,label:s,onClick:n,title:i}){return e.jsxs("button",{type:"button",onClick:n,disabled:t,title:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-40 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(ma,{className:"h-3.5 w-3.5","aria-hidden":!0}),s]})}function rt({actions:t,editing:s,editor:n,hint:i,label:r}){return e.jsx("div",{className:"py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:r}),s?n:e.jsx("div",{className:"mt-0.5 truncate text-xs text-oai-gray-500 dark:text-oai-gray-400",children:i})]}),s?null:t]})})}function rs({name:t}){const s=t.anonymousOn?a("settings.account.displayNameDisabledWhileAnon"):void 0;return e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(it,{disabled:t.anonymousOn,label:a("settings.account.edit"),onClick:t.startEditingName,title:s}),e.jsx(D,{checked:!t.anonymousOn,onChange:t.handleAnonymousToggle,disabled:t.profileLoading||t.profileSaving,ariaLabel:a("settings.account.displayName")})]})}function os({name:t}){const{anonymousOn:s,customDisplayName:n,displayName:i,editingName:r,handleAnonymousToggle:c,handleSaveName:g,nameInput:o,profileLoading:d,profileSaving:y,setEditingName:p,setNameInput:u,startEditingName:x}=t,v=s?a("settings.account.displayNameAnonymousHint"):n||i;return e.jsx(rt,{label:a("settings.account.displayName"),editing:r,hint:v,editor:e.jsx(ns,{nameInput:o,setEditingName:p,setNameInput:u,profileSaving:y,handleSaveName:g}),actions:e.jsx(rs,{name:t})})}function ls({github:t}){const{editingGithub:s,githubError:n,githubInput:i,githubUrl:r,handleSaveGithub:c,handleShowGithubToggle:g,profileLoading:o,profileSaving:d,setEditingGithub:y,setGithubError:p,setGithubInput:u,showGithubOn:x,startEditingGithub:v}=t;return e.jsx(e.Fragment,{children:e.jsx(rt,{label:a("settings.account.githubUrl"),editing:s,hint:r||a("settings.account.githubUrlHint"),editor:e.jsx(is,{githubError:n,githubInput:i,handleSaveGithub:c,profileSaving:d,setEditingGithub:y,setGithubError:p,setGithubInput:u}),actions:e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(it,{label:a("settings.account.edit"),onClick:v}),e.jsx(D,{checked:x,onChange:g,disabled:o||d,ariaLabel:a("settings.account.githubUrl")})]})})})}function cs(){const{openLoginModal:t}=Fe();return e.jsx(V,{title:a("settings.section.account"),children:e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.account.signedOutHint")}),e.jsx("button",{type:"button",onClick:t,className:"inline-flex h-8 shrink-0 items-center justify-center rounded-md bg-oai-gray-900 px-4 text-xs font-medium text-white transition-colors hover:bg-oai-gray-800 dark:bg-white dark:text-oai-gray-900 dark:hover:bg-oai-gray-100",children:a("settings.account.signIn")})]})})}function ds({name:t,github:s}){return e.jsxs(e.Fragment,{children:[e.jsx(os,{name:t}),e.jsx(ls,{github:s})]})}function us({settings:t}={}){return t?e.jsx(ot,{settings:t}):e.jsx(ms,{})}function ms(){const t=ke();return e.jsx(ot,{settings:t})}function ot({settings:t}){return t.enabled?t.signedIn?e.jsxs(V,{title:a("settings.section.account"),subtitle:t.email||t.name.customDisplayName||t.name.displayName,action:e.jsx(ps,{onSignOut:t.signOut}),children:[e.jsx(gs,{userId:t.userId}),e.jsx(hs,{checked:t.publicProfileOn,disabled:t.profileLoading||t.profileSaving||t.publicProfileAvailable===!1,onChange:t.handlePublicProfileToggle,unavailable:t.publicProfileAvailable===!1}),e.jsx(fs,{visible:t.publicProfileOn,name:t.name,github:t.github})]}):e.jsx(cs,{}):null}function gs({userId:t}){const[s,n]=fe.useState(!1);if(!t)return null;const i=async()=>{try{if(typeof navigator>"u"||!navigator.clipboard?.writeText)return;await navigator.clipboard.writeText(t),n(!0),globalThis.setTimeout(()=>n(!1),1200)}catch{n(!1)}};return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-oai-gray-900 dark:text-oai-gray-200",children:a("settings.account.userId")}),e.jsx("div",{className:"mt-0.5 truncate font-mono text-xs text-oai-gray-500 dark:text-oai-gray-400",children:t})]}),e.jsxs("button",{type:"button",onClick:i,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800","aria-label":a("settings.account.copyUserId"),children:[s?e.jsx(fa,{className:"h-3.5 w-3.5","aria-hidden":!0}):e.jsx(xa,{className:"h-3.5 w-3.5","aria-hidden":!0}),s?a("settings.account.copied"):a("settings.account.copy")]})]})}function ps({onSignOut:t}){return e.jsxs("button",{type:"button",onClick:()=>t(),className:"inline-flex h-7 items-center gap-1.5 text-xs font-medium text-oai-gray-500 transition-colors hover:text-oai-gray-700 dark:hover:text-oai-gray-300",children:[e.jsx(Ma,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.account.signOut")]})}function hs({checked:t,disabled:s,onChange:n,unavailable:i}){return e.jsx(E,{label:a("settings.account.publicProfile"),hint:a(i?"cloud.self_host.public_profile_disabled":"settings.account.publicProfileHint"),control:e.jsx(D,{checked:t,onChange:n,disabled:s,ariaLabel:a("settings.account.publicProfile")})})}function fs({visible:t,name:s,github:n}){return e.jsx(Ye,{initial:!1,children:t?e.jsx(qe.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:e.jsx(ds,{name:s,github:n})},"public-profile-fields"):null})}function ae(t){return t.replace(/[\t\n\r\f\v -]/g,"").toUpperCase()}function xs({account:t,auth:s,refresh:n,compact:i=!1,panelContainer:r=null,layout:c="default",dialogOpen:g,onDialogOpenChange:o}){const d=c==="settings-row",[y,p]=l.useState(!1),u=d&&typeof g=="boolean"?g:y,[x,v]=l.useState(""),[N,j]=l.useState(!1),[h,m]=l.useState(null),[k,C]=l.useState(null),[f,S]=l.useState(!1),_=l.useId(),w=l.useRef(null),A=l.useRef(null),T=l.useRef(!1),b=l.useRef(!1),P=l.useRef(0),U=`${jt()}.${t?.environment||"unknown"}.${s?.signedIn?s.user?.id:""}`,F=l.useRef(U);F.current=U,l.useEffect(()=>(b.current=!0,P.current+=1,A.current=null,T.current=!1,p(!1),v(""),j(!1),m(null),C(null),S(!1),()=>{b.current=!1,P.current+=1}),[U]);const K=t?.membership?.status==="self_hosted"||t?.membership?.hosting_mode==="self_hosted",$=t?.gift_redemption_available===!0,Z=d?t?.gifts||[]:[];if(!s?.signedIn||K||!$&&!Z.length)return null;const J=t.redemption_restriction,re=O=>{!O&&T.current||(typeof g!="boolean"&&p(O),o?.(O))},L=async(O,oe)=>{const le=await n();oe()&&S(!!le?.gifts?.some(H=>H.id===O?.id))},ee=async O=>{if(T.current||O&&(!$||!x.trim()))return;if(O&&J){m(new ue(J));return}T.current=!0;const oe=++P.current,le=U,H=()=>b.current&&P.current===oe&&F.current===le;j(!0),m(null);try{if(O){const te=x.trim();(!A.current||ae(A.current.code)!==ae(te))&&(A.current={code:te,request_id:crypto.randomUUID()});const ce=await Y("redeem-gift",{auth:async()=>{const ut=await Nt(s.getAccessToken);if(!H())throw new ue("authentication_required",401);return ut},body:A.current});if(!H())return;if(!ce?.gift?.id)throw new ue("billing_operation_failed");C(ce),S(!1),v(""),A.current=null,await L(ce.gift,H)}else await L(k?.gift,H)}catch(te){H()&&m(te)}finally{H()&&(T.current=!1,j(!1))}};let Q=null;return(d||u)&&(Q=e.jsxs("div",{id:`${_}-panel`,className:d?"space-y-3":i?"w-full space-y-3 rounded-lg bg-oai-gray-50 p-4 dark:bg-oai-gray-950/50":"mt-3 space-y-3",children:[$?e.jsxs(e.Fragment,{children:[e.jsx("p",{id:`${_}-detail`,className:d?"sr-only":"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.detail")}),k?e.jsxs("div",{role:"status",className:"space-y-2 text-sm leading-6",children:[e.jsx("p",{children:a(f?k.already_redeemed?"cloud.gift.already_redeemed":"cloud.gift.redeemed":"cloud.gift.refresh_needed")}),k.gift?e.jsx("p",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.term",{days:k.gift.duration_days,start:G(k.gift.starts_at),end:G(k.gift.ends_at)})}):null,f?e.jsx(R,{type:"button",variant:"ghost",onClick:()=>{C(null),S(!1)},children:a("cloud.gift.redeem_another")}):e.jsx(R,{type:"button",variant:"secondary",disabled:N,onClick:()=>{ee(!1)},children:a("cloud.action.refresh_membership")})]}):e.jsxs("form",{onSubmit:O=>{O.preventDefault(),ee(!0)},"aria-busy":N,children:[e.jsx("label",{htmlFor:_,className:d?"sr-only":"text-sm font-medium",children:a("cloud.gift.code_label")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:_,ref:w,value:x,disabled:N,maxLength:128,autoComplete:"off",spellCheck:!1,autoCapitalize:"characters","data-ph-no-capture":"true","aria-describedby":`${_}-detail${h?` ${_}-error`:""}`,"aria-invalid":!!h,onChange:O=>{ae(O.target.value)!==ae(x)&&(A.current=null),v(O.target.value),m(null)},className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 font-mono text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700"}),e.jsx(R,{type:"submit",variant:"secondary",disabled:N||!x.trim(),children:a(N?"cloud.gift.redeeming":"cloud.gift.confirm")})]})]}),h?e.jsx("div",{id:`${_}-error`,children:["gift_checkout_pending","gift_requires_renewal_cancel"].includes(h.code)?e.jsx("p",{role:"alert",className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:kt(h,"gift")}):e.jsx(z,{error:h,context:"gift"})}):null]}):null,Z.length?e.jsx("ul",{"aria-label":a("cloud.gift.history_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:Z.map(O=>e.jsxs("li",{className:"py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-sm",children:[e.jsx("span",{children:a("cloud.gift.duration",{days:O.duration_days})}),e.jsx("span",{children:a(["active","pending","expired","revoked"].includes(O.state)?`cloud.gift.state_${O.state}`:"cloud.status.unknown")})]}),e.jsx("p",{className:"mt-1 text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.history.term",{start:G(O.starts_at),end:G(O.ends_at)})})]},O.id))}):null]})),d?e.jsx(We,{open:u,onOpenChange:re,title:a($?"cloud.gift.redeem_action":"cloud.gift.history_title"),icon:Re,preventClose:N,initialFocus:$&&!k?w:void 0,children:Q}):e.jsxs("div",{className:d?void 0:i?"contents":"mt-4",children:[e.jsxs(R,{type:"button",variant:"ghost",size:i||d?"sm":"md",className:d?"!h-11 !w-full !justify-start !px-0 !text-oai-black dark:!text-oai-white hover:!bg-oai-gray-100 dark:hover:!bg-oai-gray-800 active:!scale-100":i?"!h-10 !px-0":void 0,"aria-expanded":u,"aria-controls":d||u?`${_}-panel`:void 0,onClick:()=>p(O=>!O),disabled:N,children:[i||d?e.jsx(Re,{size:16,className:`${d?"mr-3":"mr-2"} shrink-0`,"aria-hidden":!0}):null,a($?"cloud.gift.redeem_action":"cloud.gift.history_title"),d?e.jsx(ja,{size:16,className:`ml-auto shrink-0 transition-transform motion-reduce:transition-none ${u?"rotate-180":""}`,"aria-hidden":!0}):null]}),!d&&r&&Q?wt.createPortal(Q,r):Q]})}function bs({text:t,label:s}){const[n,i]=l.useState(!1);return e.jsxs(Na,{open:n,onOpenChange:i,children:[e.jsx(_a,{delay:0,closeOnClick:!1,"aria-label":s,onClick:()=>i(!0),className:"inline-flex size-8 shrink-0 items-center justify-center rounded-md text-oai-gray-400 transition-colors hover:bg-oai-gray-100 hover:text-oai-gray-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-500/40 dark:hover:bg-oai-gray-800 dark:hover:text-oai-gray-200",children:e.jsx(Ze,{size:14,"aria-hidden":!0})}),e.jsx(Sa,{children:e.jsx(Ca,{side:"bottom",sideOffset:6,className:"z-[110]",children:e.jsx(Ea,{role:"tooltip",className:"max-w-[min(320px,calc(100vw-2rem))] rounded-lg border border-oai-gray-200 bg-white px-3 py-2 text-xs leading-5 text-oai-gray-600 shadow-lg dark:border-oai-gray-700 dark:bg-oai-gray-900 dark:text-oai-gray-300",children:t})})})]})}function ys(t){return typeof t!="string"||!t.trim()?a("cloud.devices.platform_unknown"):/^(mac|darwin)/i.test(t)?a("leaderboard.community.modal.platform.darwin"):/^win/i.test(t)?a("leaderboard.community.modal.platform.win32"):/^linux/i.test(t)?a("leaderboard.community.modal.platform.linux"):t}function vs(t,s){if(!t)return null;const n=t.status==="active"&&t.access_source==="gift";if(s&&Number.isFinite(Date.parse(s))){const i=t.status==="transition"?"cloud.membership.transition_until":t.status==="trial"?"cloud.membership.trial_until":t.status==="active"?n?"cloud.membership.gift_until":"cloud.membership.active_until":t.status==="expired"&&Date.parse(s)<=Date.now()?"cloud.membership.expired_on":null;if(i)return a(i,{date:G(s)})}return n?a("cloud.gift.membership_label"):Pt(t.status)}function js({auth:t,machineLimit:s,accountRevision:n,selfHosted:i=!1}){const[r,c]=l.useState(null),[g,o]=l.useState(null),[d,y]=l.useState(null),[p,u]=l.useState(!1),[x,v]=l.useState(null),N=l.useRef(!1),j=l.useRef(0),h=l.useRef(!0),m=t?.user?.id,k=t?.getAccessToken,C=l.useCallback(async()=>{const b=++j.current;try{let P;if(ze())try{const F=await Ot(),K=await fetch("/functions/tokentracker-machine-id",{headers:F});K.ok&&(P=(await K.json())?.machineId)}catch{}const U=await Y("devices",{auth:k,params:P?{current_machine_id:P}:{}});b===j.current&&(c(U),o(null))}catch(P){b===j.current&&o({...P,code:"billing_devices_unavailable"})}},[k,m]);l.useEffect(()=>(h.current=!0,C(),()=>{h.current=!1,j.current+=1}),[C,n]);const f=async b=>{if(!N.current){N.current=!0,u(!0),o(null),v(null);try{if(await Y("remove-device",{auth:k,body:{machine_id:b}}),!h.current)return;r?.machines?.find(P=>P.machine_id===b)?.is_current&&Se(),y(null),await C()}catch(P){h.current&&o(P)}finally{N.current=!1,u(!1)}}},S=async b=>{if(!N.current){N.current=!0,u(!0),o(null),v(null);try{if(await Y("resume-device",{auth:k,body:{machine_id:b.machine_id}}),!h.current)return;b.is_current&&Se(),v(a("cloud.devices.resumed")),await C()}catch(P){h.current&&o(P)}finally{N.current=!1,u(!1)}}},_=r?.machines||[],w=r?.machine_count??_.filter(b=>b.status!=="paused").length,A=r?.machine_limit??s,T=A==null||w<A;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1",children:[e.jsx("h3",{className:"text-sm font-semibold",children:a("cloud.devices.title")}),e.jsx(bs,{label:a("cloud.devices.detail"),text:a("cloud.devices.detail")})]}),e.jsx("span",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:r?A==null?a(i?"cloud.devices.unlimited_self_hosted":"cloud.devices.unlimited",{count:w}):a("cloud.devices.count",{count:w,limit:A}):g?a("cloud.devices.count_unknown"):a("cloud.catalog.loading")})]}),r?.over_machine_limit||A!=null&&A<w?e.jsx("div",{className:"mb-4",children:e.jsx(z,{children:a("cloud.devices.over_limit")})}):null,g?e.jsx(z,{error:g,onRetry:C,context:"account"}):null,x?e.jsx("div",{className:"mb-3",children:e.jsx(z,{children:x})}):null,!g&&r&&_.length===0?e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.empty")}):null,_.length!==0?e.jsx("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:_.map(b=>e.jsxs("li",{className:"py-1.5",children:[e.jsxs("div",{className:"grid grid-cols-[17px_minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1",children:[e.jsx(ye,{size:17,className:"col-start-1 row-start-1 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),e.jsx("p",{title:b.name||a("cloud.devices.unnamed"),className:"col-start-2 row-start-1 min-w-0 truncate text-sm font-medium",children:b.name||a("cloud.devices.unnamed")}),e.jsxs("div",{className:"col-span-2 col-start-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-1 sm:col-start-2",children:[e.jsx("span",{children:ys(b.platform)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:b.last_seen_at?a("cloud.devices.last_seen",{date:At(b.last_seen_at)}):a("cloud.devices.last_seen_unknown")}),b.is_current?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.current")})]}):null,b.status==="paused"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.paused")})]}):null]}),b.status==="paused"&&!T?e.jsx("p",{className:"col-start-2 row-start-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.devices.no_slot")}):null,e.jsxs(R,{variant:"ghost",size:"sm",className:"col-start-3 row-start-1 !min-h-10 !px-2 sm:row-span-2","aria-expanded":b.status!=="paused"?d===b.machine_id:void 0,"aria-controls":d===b.machine_id?`cloud-machine-confirm-${b.machine_id}`:void 0,onClick:()=>b.status==="paused"?S(b):y(P=>P===b.machine_id?null:b.machine_id),disabled:p||b.status==="paused"&&!T,children:[b.status==="paused"?e.jsx(ka,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}):e.jsx(wa,{size:14,className:"mr-1.5 shrink-0","aria-hidden":!0}),b.status==="paused"?a("cloud.devices.resume"):a("cloud.devices.remove")]})]}),d===b.machine_id?e.jsxs("div",{id:`cloud-machine-confirm-${b.machine_id}`,className:"mt-3 rounded-lg bg-oai-gray-50 p-3 dark:bg-oai-gray-800",children:[e.jsx("p",{className:"text-xs leading-5",children:a("cloud.devices.remove_detail")}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx(R,{variant:"secondary",onClick:()=>f(b.machine_id),disabled:p,children:a("cloud.devices.confirm_remove")}),e.jsx(R,{variant:"ghost",onClick:()=>y(null),disabled:p,children:a("cloud.action.keep")})]})]}):null]},b.machine_id))}):null]})}function ks({recent:t,pendingOrders:s,conflictOrders:n,userId:i,payments:r=[],footerActions:c}){const g=He(),[o,d]=l.useState(t?.order_id&&ge.test(t.order_id)?t.order_id:""),[y,p]=l.useState(!1),[u,x]=l.useState(!1),v=l.useId(),N=l.useRef(null);l.useEffect(()=>{u&&N.current?.focus()},[u]);const j=new Set([...r.map(m=>m.order_id).filter(m=>typeof m=="string"),...(s||[]).filter(m=>m.status==="paid"||["paid","partially_refunded","refunded"].includes(m.payment_state)).map(m=>m.id)].map(m=>m.toLowerCase())),h=[...n||[],...(s||[]).filter(m=>m.retry_payment_conflict_at||!j.has(m.id.toLowerCase()))].filter((m,k,C)=>C.findIndex(f=>f.id===m.id)===k);return e.jsxs("div",{className:"mt-2 space-y-3",children:[t?.request_id&&!t.order_id?e.jsx(ne,{to:`/billing/checkout?sku=${encodeURIComponent(t.sku)}`,className:"mt-3 inline-flex min-h-10 items-center text-sm text-oai-brand underline underline-offset-4",children:a("cloud.action.resume_purchase")}):null,h.length||r.length?e.jsxs("div",{className:"sm:grid sm:grid-cols-[minmax(0,1fr)_auto_minmax(7rem,auto)] sm:gap-x-4",children:[e.jsxs("div",{"aria-hidden":!0,className:"hidden gap-x-4 pb-1 text-xs text-oai-gray-500 dark:text-oai-gray-400 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[e.jsx("span",{children:a("cloud.history.date")}),e.jsx("span",{className:"text-right",children:a("cloud.history.amount")}),e.jsx("span",{className:"text-right",children:a("cloud.history.status")})]}),e.jsxs("ul",{className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800 sm:col-span-3 sm:grid sm:grid-cols-subgrid",children:[h.map(m=>{const k=typeof m.created_at=="string"&&Number.isFinite(Date.parse(m.created_at))?G(m.created_at):null;let C=null;Number.isInteger(m.amount_cents)&&m.amount_cents>=0&&["USD","CNY"].includes(m.currency)&&(C=xe(m.amount_cents,m.currency));const f=a(m.retry_payment_conflict_at?"cloud.action.review_duplicate_payment":"cloud.history.pending");return e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:k||f}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:C}),m.provider||k?e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[m.provider?e.jsx("span",{children:Be(m.provider)}):null,k?e.jsxs(e.Fragment,{children:[m.provider?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,e.jsx("span",{children:f})]}):null]}):null,e.jsx(ne,{to:`/billing/checkout?order=${encodeURIComponent(m.id)}`,onClick:S=>{m.retry_payment_conflict_at||S.button!==0||S.metaKey||S.ctrlKey||S.shiftKey||S.altKey||!ge.test(m.id)||(S.preventDefault(),g(_e({orderId:m.id,userId:i})))},className:"col-start-2 row-start-2 inline-flex min-h-10 items-center justify-end rounded-sm text-right text-sm underline-offset-4 hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 sm:col-start-3 sm:row-span-2 sm:row-start-1 sm:self-start sm:items-start",children:e.jsx("span",{children:m.retry_payment_conflict_at?a("cloud.action.review_duplicate_payment"):a("cloud.action.resume_order")})})]},m.id)}),e.jsx(ws,{payments:r})]})]}):e.jsx(e.Fragment,{children:(!t?.request_id||t.order_id)&&e.jsx("p",{className:"py-2 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.history.empty")})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-1",children:[e.jsx(R,{variant:"ghost",size:"sm",className:"!h-10 !px-0","aria-expanded":u,"aria-controls":`${v}-panel`,onClick:()=>x(m=>!m),children:a("cloud.restore.title")}),c]}),u?e.jsxs("div",{id:`${v}-panel`,className:"mt-2",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.restore.detail")}),e.jsxs("form",{className:"mt-4",onSubmit:m=>{if(m.preventDefault(),!ge.test(o.trim())){p(!0);return}const k=o.trim(),C=h.some(f=>f.id.toLowerCase()===k.toLowerCase()&&f.retry_payment_conflict_at);g(C?`/billing/checkout?order=${encodeURIComponent(k)}`:_e({orderId:k,userId:i}))},children:[e.jsx("label",{htmlFor:`${v}-input`,className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.checkout.order_id")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{id:`${v}-input`,ref:N,value:o,onChange:m=>{d(m.target.value),p(!1)},placeholder:a("cloud.restore.placeholder"),className:"min-h-10 min-w-0 flex-1 rounded-md border border-oai-gray-300 bg-transparent px-3 text-sm outline-none focus:border-oai-brand focus:ring-2 focus:ring-inset focus:ring-oai-brand/30 dark:border-oai-gray-700","aria-invalid":y,"aria-describedby":y?`${v}-error`:void 0}),e.jsx(R,{type:"submit",variant:"secondary",children:a("cloud.action.restore")})]}),y?e.jsx("p",{id:`${v}-error`,role:"alert",className:"mt-2 text-xs text-red-600 dark:text-red-400",children:a("cloud.restore.invalid")}):null]})]}):null]})]})}function ws({payments:t}){return e.jsx(e.Fragment,{children:t.map(s=>e.jsxs("li",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1 py-3 sm:col-span-3 sm:grid-cols-subgrid",children:[e.jsx("p",{className:"col-start-1 row-start-1 text-sm tabular-nums",children:G(s.paid_at)}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:xe(s.amount_cents,s.currency)}),e.jsxs("div",{className:"col-start-1 row-start-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:Be(s.provider)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.history.term",{start:G(s.starts_at),end:G(s.ends_at)})})]}),e.jsx("p",{className:`col-start-2 row-start-2 text-right text-sm font-medium sm:col-start-3 sm:row-span-1 sm:row-start-1 sm:self-start ${s.refunded_cents>0?"text-amber-700 dark:text-amber-400":"text-oai-gray-600 dark:text-oai-gray-300"}`,children:s.refunded_cents>0?a("cloud.history.refunded",{amount:xe(s.refunded_cents,s.currency)}):a("cloud.history.paid")})]},s.id))})}function Ns({showTitle:t=!0,heading:s,syncControl:n,active:i=!0}){const r=_t();return e.jsx(_s,{showTitle:t,heading:s,syncControl:n,active:i,...r},r.auth?.signedIn?r.auth.user?.id:"signed-out")}function _s({account:t,auth:s,loading:n,error:i,refresh:r,showTitle:c,heading:g,syncControl:o,active:d=!0}){const{openLoginModal:y}=Fe(),[p,u]=l.useState(null),[x,v]=l.useState(null),[N,j]=l.useState(!1),[h,m]=l.useState(null),k=l.useRef(!1),C=l.useRef(!0);l.useEffect(()=>{d||u(null)},[d]),l.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]);const f=t?.membership,S=f?.status==="self_hosted"||f?.hosting_mode==="self_hosted",_=[...t?.conflict_orders||[],...t?.pending_orders||[]].some(L=>L.retry_payment_conflict_at),w=!S&&t?.subscriptions?.find(L=>["active","trialing","past_due","paused","canceling"].includes(L.status)),A=!S&&(w?w.provider==="waffo":t?.payments?.some(L=>L.provider==="waffo")),T=w&&!w.cancel_at_period_end&&w.status!=="canceling",b=T&&w.status!=="paused",P=w?.next_billed_at,U=P&&Number.isFinite(Date.parse(P));l.useEffect(()=>{h&&t&&!T&&(m(null),v(null))},[t,h,T]);const F=S?null:f?.status==="trial"?f.trial_ends_at:f?.status==="transition"?f.transition_ends_at:f?.expires_at,K=async L=>{if(!k.current){k.current=!0,j(!0),v(null);try{await L()}catch(ee){C.current&&v(ee)}finally{k.current=!1,j(!1)}}},$=()=>K(async()=>{const L=await Y("portal",{auth:s.getAccessToken,body:w?{subscription_id:w.provider_subscription_id}:{}});C.current&&await va(L.url||L.portal_url)}),Z=()=>K(async()=>{await Y("cancel",{auth:s.getAccessToken,body:{subscription_id:h}}),C.current&&(m(null),await r())}),J=vs(f,F),re=A&&!w||f?.can_read_cloud||!S&&t?.gift_redemption_available===!0;return s?.signedIn?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("section",{"aria-label":a("cloud.membership.title"),className:"tt-cloud-theme space-y-3",children:[t?.environment==="sandbox"?e.jsx(z,{children:a("cloud.catalog.sandbox")}):null,_?e.jsx(St,{showBillingLink:!1}):null,e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-baseline gap-x-3 gap-y-2",children:[g?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:g}):null,!g&&c?e.jsxs("h2",{className:"inline-flex items-center gap-2 text-base font-semibold",children:[e.jsx(se,{size:18,className:"text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),a("cloud.membership.title")]}):null,J?e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:J}):null]}),e.jsx(R,{onClick:r,variant:"ghost",size:"sm",className:"!size-10 shrink-0 !p-0",disabled:n,"aria-label":a("cloud.action.refresh_membership"),children:e.jsx(be,{size:15,className:n?"motion-safe:animate-spin":void 0,"aria-hidden":!0})})]}),f?.status==="expired"?e.jsx("p",{className:"mt-3 max-w-2xl text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:f.can_read_cloud?a("cloud.membership.read_only",{date:G(f.read_only_until)}):a("cloud.membership.expired_detail")}):null,f?e.jsx(Ct,{userId:s.user?.id,membership:f,subscriptions:t?.subscriptions,className:"mt-3"}):null,!f&&n?e.jsx("p",{role:"status",className:"mt-3 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.catalog.loading")}):null,w?e.jsx("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-3",children:w?e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("p",{className:"text-xs leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:w.status==="paused"?a("cloud.membership.renewal_paused"):w.status==="past_due"?a("cloud.membership.payment_due"):b?U?a("cloud.membership.renews",{date:G(P)}):a("cloud.membership.renewal_unknown"):a("cloud.membership.renewal_off")}),T?e.jsx(R,{"aria-expanded":!!h,"aria-controls":h?"cloud-cancel-confirm":void 0,onClick:()=>m(L=>L===w.provider_subscription_id?null:w.provider_subscription_id),variant:"ghost",size:"sm",className:"!h-10 !px-2",disabled:N,children:a("cloud.action.cancel_renewal")}):null]}):null}):null,h?e.jsxs("div",{id:"cloud-cancel-confirm",className:"mt-4 rounded-lg border border-oai-gray-200 p-4 dark:border-oai-gray-800",children:[e.jsx("p",{className:"text-sm leading-6",children:F?a("cloud.cancel.detail",{date:G(F)}):a("cloud.cancel.no_term")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(R,{onClick:Z,variant:"secondary",disabled:N,children:a("cloud.cancel.confirm")}),e.jsx(R,{onClick:()=>m(null),variant:"ghost",disabled:N,children:a("cloud.action.keep")})]})]}):null,i?e.jsx("div",{className:"mt-4",children:e.jsx(z,{error:i,onRetry:r,context:"account"})}):null,x&&p!=="billing"?e.jsx("div",{className:"mt-4",children:e.jsx(z,{error:x,context:"account"})}):null]})]}),f?e.jsx(pe,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-3",children:e.jsx(js,{auth:s,machineLimit:f.machine_limit,accountRevision:t,selfHosted:S})}):null,re||t&&!S||o?e.jsx(pe,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-2",children:e.jsxs("section",{"aria-label":a("cloud.membership.tools_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:[S?null:w?e.jsxs("button",{type:"button",onClick:$,disabled:N,className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 disabled:opacity-50 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(se,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.manage_subscription")}),e.jsx(De,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}):e.jsxs(ne,{to:"/cloud",className:"inline-flex h-11 w-full items-center gap-3 rounded-md border-0 bg-transparent p-0 text-left text-sm font-medium text-oai-black transition-colors hover:bg-oai-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-oai-gray-500 dark:text-oai-white dark:hover:bg-oai-gray-800",children:[e.jsx(se,{size:16,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"min-w-0 flex-1",children:a("cloud.action.subscribe")}),e.jsx(Et,{size:16,className:"shrink-0 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})]}),t&&!S?e.jsxs(We,{open:p==="billing",onOpenChange:L=>u(L?"billing":null),title:a("cloud.billing.title"),icon:Ra,wide:!0,children:[x?e.jsx("div",{className:"mb-3",children:e.jsx(z,{error:x,context:"account"})}):null,e.jsx(ks,{userId:s.user?.id,recent:ya(s.user?.id),pendingOrders:t?.pending_orders,conflictOrders:t?.conflict_orders,payments:t.payments,footerActions:A&&!w?e.jsx("div",{className:"flex items-center gap-0.5",children:e.jsxs(R,{onClick:$,variant:"ghost",size:"sm",className:"!h-10 !px-0",disabled:N,children:[a("cloud.action.view_bills"),e.jsx(De,{size:14,className:"ml-2","aria-hidden":!0})]})}):null})]}):null,f?.can_read_cloud?e.jsx(ga,{auth:s,layout:"settings-row",dialogOpen:p==="export",onDialogOpenChange:L=>u(L?"export":null)}):null,e.jsx(xs,{account:t,auth:s,refresh:r,layout:"settings-row",dialogOpen:p==="redeem",onDialogOpenChange:L=>u(L?"redeem":null)}),o?e.jsx("section",{children:o}):null]})}):null]}):e.jsxs("div",{className:"space-y-4",children:[g?e.jsx("h2",{className:"shrink-0 !text-2xl font-semibold",children:g}):null,e.jsxs(pe,{className:"tt-cloud-theme",children:[!g&&c?e.jsx("h2",{className:"text-base font-semibold",children:a("cloud.membership.title")}):null,e.jsx("p",{className:`${!g&&c?"mt-2 ":""}text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400`,children:a("cloud.membership.signed_out")}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:e.jsx(R,{onClick:()=>y({subtitle:a("cloud.membership.signed_out")}),children:a("cloud.action.sign_in_continue")})})]})]})}function Ss({settings:t,active:s=!0}={}){return t?e.jsx(lt,{settings:t,active:s}):e.jsx(Cs,{active:s})}function Cs({active:t}){const s=ke();return e.jsx(lt,{settings:s,active:t})}function lt({settings:t,active:s}){return e.jsx(Ns,{showTitle:!1,heading:a("settings.section.cloud"),active:s,syncControl:t.showLocalCloudSync?e.jsx(Es,{settings:t}):null})}function Es({settings:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-11 items-center justify-between gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-3 text-sm font-medium",children:[e.jsx(be,{size:16,className:"shrink-0","aria-hidden":!0}),a("settings.account.cloudSync")]}),e.jsx("span",{className:"tt-cloud-theme tt-cloud-sync-control inline-flex","aria-busy":t.cloudSyncPending||void 0,children:e.jsx(D,{checked:t.cloudSyncOn,disabled:t.cloudSyncPending,onChange:()=>(t.cloudSyncOn?Ce(t.userId):Lt(t.userId,"sync"),t.handleCloudSyncToggle()),ariaLabel:a("settings.account.cloudSync")})})]}),t.cloudSyncOn&&t.cloudSyncPending?e.jsxs("p",{role:"status",className:"flex items-center gap-2 py-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx(Pa,{size:14,className:"motion-safe:animate-spin","aria-hidden":!0}),a("settings.account.cloudSyncPending")]}):null,t.cloudSyncOn&&t.cloudSyncError&&!t.cloudSyncPending?e.jsx("div",{className:"tt-cloud-theme py-3",children:e.jsx(z,{role:"alert",onRetry:t.handleCloudSyncRetry,children:a("settings.account.cloudSyncError")})}):null,e.jsx(Tt,{userId:t.userId,panel:"sync",localHost:!0,className:"py-3",onContinueLocal:()=>{Ce(t.userId),t.cloudSyncOn&&t.handleCloudSyncDisable()}})]})}function Ps(){return[{value:"light",label:a("settings.appearance.theme.light"),Icon:Rt},{value:"dark",label:a("settings.appearance.theme.dark"),Icon:Dt},{value:"system",label:a("settings.appearance.theme.system"),Icon:ye}]}function Os(){return[{value:Mt,label:a("settings.appearance.language.system")},{value:$t,label:a("settings.appearance.language.english")},{value:zt,label:a("settings.appearance.language.chinese")},{value:Ft,label:a("settings.appearance.language.traditional_chinese")},{value:Ht,label:a("settings.appearance.language.japanese")},{value:Bt,label:a("settings.appearance.language.korean")},{value:Vt,label:a("settings.appearance.language.german")}]}function As(t){if(!t)return null;try{const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleString()}catch{return null}}function Ls(t,s){const n=a(`settings.appearance.currency.rate_source.${t}`),i=As(s),r=i?a("settings.appearance.currency.rate_updated",{when:i}):a("settings.appearance.currency.rate_never");return`${n} · ${r}`}function Ts({locale:t,setLocale:s}){const n=Os();return e.jsx(ve,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.language.label"),className:"px-2.5 py-1.5 text-xs font-medium",leadingIcon:e.jsx(Ua,{className:"h-3.5 w-3.5 text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0})})}function Is({currency:t,setCurrency:s}){const n=Gt().map(i=>({value:i.code,label:a(i.labelKey)}));return e.jsx(ve,{value:t,onValueChange:s,options:n,ariaLabel:a("settings.appearance.currency.label"),className:"px-3 py-1.5 text-xs font-medium"})}function Rs({currency:t,rate:s,rateSource:n,rateFetchedAt:i}){if(t===Ut)return e.jsx(e.Fragment,{children:a("settings.appearance.currency.hint")});const r=Ls(n,i);return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{children:`1 USD = ${s.toFixed(4)} ${t}`}),e.jsx("span",{role:"img","aria-label":r,title:r,className:"inline-flex h-4 w-4 cursor-help items-center justify-center text-oai-gray-400 hover:text-oai-gray-600 dark:text-oai-gray-500 dark:hover:text-oai-gray-300",children:e.jsx(Ze,{className:"h-3.5 w-3.5","aria-hidden":!0})})]})}function Ds(){const{theme:t,setTheme:s}=It(),{locale:n,setLocale:i}=Ve(),{currency:r,rate:c,rateSource:g,rateFetchedAt:o,setCurrency:d}=Oa(),{mode:y,setMode:p,unitSystem:u,setUnitSystem:x,grouping:v,setGrouping:N}=Aa();return e.jsxs(V,{title:a("settings.section.appearance"),children:[e.jsx(E,{label:a("settings.appearance.theme.label"),hint:a("settings.appearance.theme.hint"),control:e.jsx(q,{options:Ps(),value:t,onChange:s})}),e.jsx(E,{label:a("settings.appearance.language.label"),hint:a("settings.appearance.language.hint"),control:e.jsx(Ts,{locale:n,setLocale:i})}),e.jsx(E,{label:a("settings.appearance.currency.label"),hint:e.jsx(Rs,{currency:r,rate:c,rateSource:g,rateFetchedAt:o}),control:e.jsx(Is,{currency:r,setCurrency:d})}),e.jsx(E,{label:a("settings.appearance.token_format.label"),hint:a("settings.appearance.token_format.hint"),control:e.jsx(q,{options:[{value:me.COMPACT,label:a("settings.appearance.token_format.compact")},{value:me.FULL,label:a("settings.appearance.token_format.full")}],value:y,onChange:p})}),e.jsx(E,{label:a("settings.appearance.token_unit.label"),hint:a("settings.appearance.token_unit.hint"),control:e.jsx(q,{disabled:y!==me.COMPACT,options:[{value:Ee.ENGLISH,label:a("settings.appearance.token_unit.english")},{value:Ee.CHINESE,label:a("settings.appearance.token_unit.chinese")}],value:u,onChange:x})}),e.jsx(E,{label:a("settings.appearance.token_grouping.label"),hint:a("settings.appearance.token_grouping.hint"),control:e.jsx(q,{options:[{value:Pe.THOUSAND,label:a("settings.appearance.token_grouping.thousand")},{value:Pe.WAN,label:a("settings.appearance.token_grouping.wan")}],value:v,onChange:N})})]})}function he({labelKey:t}){return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:a(t)}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:a("qpd.card.badge")})]})}function Gs(){const{enabled:t,toggle:s}=pa(),{enabled:n,toggle:i}=ha(),{available:r,settings:c,setSetting:g}=ie(),o=r&&!!c?.dynamicIslandSupported,d=!!c?.dynamicIslandEnabled;return e.jsxs(V,{title:a("settings.section.labs"),children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.island.label"}),hint:a("settings.labs.island.hint"),control:e.jsx(D,{checked:d,onChange:()=>g("dynamicIslandEnabled",!d),ariaLabel:a("settings.labs.island.aria")})}),d&&e.jsx(E,{label:a("settings.labs.island_hide_menubar.label"),hint:a("settings.labs.island_hide_menubar.hint"),control:e.jsx(D,{checked:!!c?.hideMenuBarIcon,onChange:()=>g("hideMenuBarIcon",!c?.hideMenuBarIcon),ariaLabel:a("settings.labs.island_hide_menubar.aria")})})]}),e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.qpd.label"}),hint:a("settings.labs.qpd.hint"),control:e.jsx(D,{checked:t,onChange:s,ariaLabel:a("settings.labs.qpd.aria")})}),e.jsx(E,{label:e.jsx(he,{labelKey:"settings.labs.sessions.label"}),hint:a("settings.labs.sessions.hint"),control:e.jsx(D,{checked:n,onChange:i,ariaLabel:a("settings.labs.sessions.aria")})})]})}function Us(){const{available:t,settings:s,setSetting:n,runAction:i}=ie();if(!t)return null;const r=Ke(),c=!!s?.launchAtLogin,g=s?.toastOnReset!==!1,o=s?.confettiOnReset!==!1,d=s?.launchAtLoginSupported!==!1,y=s?.autoUpdateEnabled!==!1,p=s?.updateStatus||null,u=!!s?.updateBusy,x=!!s?.isSyncing;return e.jsxs(V,{title:a("settings.section.menubar"),children:[r?null:e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("settings.menubar.appearance"),hint:a("settings.menubar.appearanceHint"),control:e.jsxs(ne,{to:"/widgets",className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 no-underline transition-colors hover:bg-oai-gray-100 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[a("settings.menubar.appearanceLink"),e.jsx(Ta,{className:"h-3.5 w-3.5","aria-hidden":!0})]})}),e.jsx(E,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(D,{checked:g,onChange:()=>n("toastOnReset",!g),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(E,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(D,{checked:o,onChange:()=>n("confettiOnReset",!o),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),d?e.jsx(E,{label:a("settings.menubar.launchAtLogin"),hint:a("settings.menubar.launchAtLoginHint"),control:e.jsx(D,{checked:c,onChange:()=>n("launchAtLogin",!c),ariaLabel:a("settings.menubar.launchAtLogin")})}):null,e.jsx(E,{label:a("settings.menubar.syncNow"),hint:a("settings.menubar.syncNowHint"),control:e.jsxs("button",{type:"button",onClick:()=>i("syncNow"),disabled:x,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(be,{className:B("h-3.5 w-3.5",x&&"animate-spin"),"aria-hidden":!0}),x?a("settings.menubar.syncing"):a("settings.menubar.syncNow")]})}),e.jsx(E,{label:a("settings.menubar.autoUpdate"),hint:a("settings.menubar.autoUpdateHint"),control:e.jsx(D,{checked:y,onChange:()=>n("autoUpdateEnabled",!y),ariaLabel:a("settings.menubar.autoUpdate")})}),e.jsx(E,{label:a("settings.menubar.updates"),hint:p||void 0,control:e.jsxs("button",{type:"button",onClick:()=>i("checkForUpdates"),disabled:u,className:"inline-flex h-8 items-center gap-1.5 rounded-md border border-oai-gray-200 px-3 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:cursor-not-allowed disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:[e.jsx(Ia,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.menubar.checkUpdates")]})})]})}function Ms(t,s){function n(c){return c.replace(/^v/,"").split(".").map(Number)}const i=n(t),r=n(s);for(let c=0;c<Math.max(i.length,r.length);c++){const g=i[c]||0,o=r[c]||0;if(g<o)return!0;if(g>o)return!1}return!1}function $s(){const{available:t,settings:s,runAction:n}=ie(),i=t&&s?.version,r=s?.platform||"macos",[c,g]=fe.useState(!1),[o,d]=fe.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:y}=Ve(),p="1.3.6",u=async()=>{g(!0);try{const h=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!h.ok)throw new Error("Failed to fetch");const m=await h.json(),k=m.tag_name;Ms(p,k)?d({open:!0,latestVersion:k,htmlUrl:m.html_url}):Oe({title:a("settings.menubar.updates.upToDate")})}catch(h){console.error("Check updates failed:",h),Oe({title:a("settings.menubar.updates.failed")})}finally{g(!1)}},x=a("settings.menubar.updates.modalTitle"),v=a("settings.menubar.updates.modalDescription",{version:o.latestVersion}),N=a("settings.menubar.updates.modalConfirm"),j=a("settings.menubar.updates.modalCancel");return e.jsxs("div",{className:"mt-6 flex flex-col items-center justify-center gap-4 text-xs text-oai-gray-500 dark:text-oai-gray-500",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[i?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:r==="windows"?a("settings.menubar.updates.footerCore",{version:s.version}):a("settings.menubar.updates.footerCombined",{barVersion:s.version,coreVersion:p})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:()=>n("openAbout"),className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:"GitHub"}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a("settings.menubar.updates.footerCore",{version:p})}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("button",{type:"button",onClick:u,disabled:c,className:"underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300 disabled:opacity-50",children:c?a("settings.menubar.updates.checking"):a("settings.menubar.checkUpdates")}),e.jsx("span",{"aria-hidden":!0,children:"·"})]}),e.jsxs("a",{href:Kt,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 underline-offset-2 transition-colors hover:text-oai-gray-700 hover:underline dark:hover:text-oai-gray-300",children:[e.jsx(qt,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("settings.footer.statusPage")]})]}),e.jsx(La,{open:o.open,title:x,description:v,confirmLabel:N,cancelLabel:j,onConfirm:()=>{window.open(o.htmlUrl,"_blank"),d(h=>({...h,open:!1}))},onCancel:()=>d(h=>({...h,open:!1}))})]})}const zs=()=>[{value:"system",label:a("settings.network.mode.system")},{value:"manual",label:a("settings.network.mode.manual")},{value:"off",label:a("settings.network.mode.off")}],Fs=()=>[{value:"http",label:a("settings.network.protocol.http")},{value:"https",label:a("settings.network.protocol.https")},{value:"socks5",label:a("settings.network.protocol.socks5")}],Ge="w-full rounded-md border border-oai-gray-300 bg-transparent px-2.5 py-1.5 text-sm text-oai-black outline-none focus:border-oai-brand-500 focus:ring-1 focus:ring-inset focus:ring-oai-brand-500 dark:border-oai-gray-700 dark:text-white";function Ue(t){const s={},n=String(t.host||"").trim();(!n||/:\/\//.test(n)||n.includes("/"))&&(s.host=a("settings.network.error.host"));const i=String(t.port??"").trim(),r=Number(i);return(!i||!/^\d+$/.test(i)||!Number.isInteger(r)||r<1||r>65535)&&(s.port=a("settings.network.error.port")),s}function Hs({proxySettings:t}){const{config:s,save:n,testConnection:i}=t,[r,c]=l.useState(()=>({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})),[g,o]=l.useState({}),[d,y]=l.useState(!1),[p,u]=l.useState(""),[x,v]=l.useState(null),[N,j]=l.useState(!1),[h,m]=l.useState(null);l.useEffect(()=>{c({mode:s.mode,protocol:s.protocol||"http",host:s.host||"",port:s.port||""})},[s.mode,s.protocol,s.host,s.port]);const k=l.useMemo(()=>s.effective==="manual"?a("settings.network.effective.manual"):s.effective==="env"?a("settings.network.effective.env"):s.effective==="system"?a("settings.network.effective.system"):s.effective==="blocked"?a("settings.network.effective.blocked"):a("settings.network.effective.none"),[s.effective]),C=_=>{c(w=>({...w,..._})),o({}),u(""),v(null),m(null)},f=async()=>{if(r.mode==="manual"){const _=Ue(r);if(Object.keys(_).length){o(_);return}}y(!0),u(""),v(null);try{await n(r),u("saved")}catch(_){u("error"),v(_)}finally{y(!1)}},S=async()=>{const _=Ue(r);if(Object.keys(_).length){o(_);return}j(!0),m(null);try{const w=await i(r);m(w)}catch(w){m({ok:!1,error:w?.message||String(w)})}finally{j(!1)}};return e.jsxs(V,{title:a("settings.section.network"),subtitle:k,children:[s.applyError?e.jsx("p",{role:"alert",className:"mb-3 text-xs text-red-600 dark:text-red-400",children:a("settings.network.apply_error",{error:s.applyError})}):null,e.jsx(E,{label:a("settings.network.mode.label"),hint:a("settings.network.mode.hint"),control:e.jsx(q,{options:zs(),value:r.mode,onChange:_=>C({mode:_})})}),e.jsx(Ye,{initial:!1,children:r.mode==="manual"?e.jsxs(qe.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{height:{duration:.28,ease:[.22,1,.36,1]},opacity:{duration:.2,ease:[.22,1,.36,1]}},style:{overflow:"hidden"},className:"divide-y divide-oai-gray-200/60 dark:divide-oai-gray-800/60",children:[e.jsx(E,{label:a("settings.network.protocol.label"),control:e.jsx(ve,{value:r.protocol,onValueChange:_=>C({protocol:_}),options:Fs(),ariaLabel:a("settings.network.protocol.label"),className:"px-2.5 py-1.5 text-xs font-medium"})}),e.jsx(E,{label:a("settings.network.host.label"),hint:g.host,control:e.jsx("input",{type:"text",value:r.host,onChange:_=>C({host:_.target.value}),placeholder:a("settings.network.host.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":g.host?!0:void 0,"aria-label":a("settings.network.host.label"),className:Ge})}),e.jsx(E,{label:a("settings.network.port.label"),hint:g.port,control:e.jsx("input",{type:"text",inputMode:"numeric",value:r.port,onChange:_=>C({port:_.target.value}),placeholder:a("settings.network.port.placeholder"),autoComplete:"off",spellCheck:!1,"aria-invalid":g.port?!0:void 0,"aria-label":a("settings.network.port.label"),className:Ge})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 py-3",children:[e.jsx("button",{type:"button",onClick:S,disabled:N||d,className:"rounded-md border border-oai-gray-200 px-3 py-1.5 text-xs font-medium text-oai-gray-700 transition-colors hover:bg-oai-gray-100 disabled:opacity-50 dark:border-oai-gray-800 dark:text-oai-gray-300 dark:hover:bg-oai-gray-800",children:N?a("settings.network.test.testing"):a("settings.network.test")}),e.jsx("button",{type:"button",onClick:f,disabled:d||N,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})]}),h?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:h.ok?a("settings.network.test.ok",{status:String(h.status??"")}):a("settings.network.test.fail",{error:h.error||""})}):null]},"manual-proxy-fields"):e.jsx("div",{className:"flex justify-end py-3",children:e.jsx("button",{type:"button",onClick:f,disabled:d,className:"rounded-md bg-oai-brand-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-oai-brand-600 disabled:opacity-50",children:d?a("settings.network.saving"):a("settings.network.save")})},"non-manual-save")}),p==="saved"?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.network.saved")}):null,p==="error"?e.jsx("p",{role:"alert",className:"py-2 text-xs text-red-600 dark:text-red-400",children:x?.unprotected?a("settings.network.save_error_unprotected",{error:x?.message||String(x||"")}):a("settings.network.save_error",{error:x?.message||String(x||"")})}):null]})}const ct="/functions/tokentracker-proxy-config",Bs="/functions/tokentracker-proxy-test",Vs={mode:"system",protocol:"http",host:"",port:"",effective:"none",applyError:null};function dt(t){return!t||typeof t.mode!="string"?null:{mode:t.mode,protocol:typeof t.protocol=="string"?t.protocol:"http",host:typeof t.host=="string"?t.host:"",port:t.port==null||t.port===0?"":String(t.port),effective:typeof t.effective=="string"?t.effective:"none",applyError:typeof t.applyError=="string"&&t.applyError.trim()?t.applyError:null}}async function Ks(){const t=await fetch(ct,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!t.ok)return null;const s=await t.json().catch(()=>null);return dt(s)}async function Me(){const{getLocalApiAuthHeaders:t}=await Wt(async()=>{const{getLocalApiAuthHeaders:s}=await import("./__vite-browser-external-DWN9Fb-H.js").then(n=>n.dZ);return{getLocalApiAuthHeaders:s}},__vite__mapDeps([0,1]));return t()}function qs(){const[t,s]=l.useState(!1),[n,i]=l.useState(!0),[r,c]=l.useState(Vs);l.useEffect(()=>{if(!ba()){s(!1),i(!1);return}let d=!1;return(async()=>{try{const y=await Ks();if(d)return;if(!y){s(!1),i(!1);return}c(y),s(!0),i(!1)}catch{d||(s(!1),i(!1))}})(),()=>{d=!0}},[]);const g=l.useCallback(async d=>{const y=await Me(),p=await fetch(ct,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...y},cache:"no-store",body:JSON.stringify({mode:d.mode,protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),u=await p.json().catch(()=>null);if(!p.ok){const v=u&&typeof u.error=="string"?u.error:`HTTP ${p.status}`;throw new Error(v)}const x=dt(u);if(x&&c(x),u&&u.ok===!1){const v=u&&typeof u.applyError=="string"&&u.applyError||u&&typeof u.error=="string"&&u.error||`HTTP ${p.status}`,N=new Error(v);throw u.unprotected===!0&&(N.unprotected=!0),N}return x||u},[]),o=l.useCallback(async d=>{const y=await Me(),p=await fetch(Bs,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...y},cache:"no-store",body:JSON.stringify({protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),u=await p.json().catch(()=>null);if(!u||typeof u.ok!="boolean")throw new Error(u&&typeof u.error=="string"?u.error:`HTTP ${p.status}`);return u},[]);return{available:t,loading:n,config:r,save:g,testConnection:o}}const I={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",CLOUD:"cloud",LIMITS:"limits",LABS:"labs"},M={PERSONAL:"personal",APP:"app",DEVELOPER:"developer"};function Ws({prefs:t}){return e.jsx(q,{options:[{value:Ie.USED,label:a("limits.settings.display_mode_used")},{value:Ie.REMAINING,label:a("limits.settings.display_mode_remaining")}],value:t.displayMode,onChange:t.setDisplayMode})}function In(){const t=ke(),s=da(),{available:n,settings:i,setSetting:r}=ie(),c=qs(),{available:g}=c,o=i?.toastOnReset!==!1,d=i?.confettiOnReset!==!1,y=Ke()||i?.platform==="windows",[p,u]=Yt(),x=He(),v=p.get("section"),j=Object.values(I).includes(v)&&(v!==I.NATIVE_APP||n)&&(v!==I.NETWORK||g)?v:I.APPEARANCE,h=f=>{const S=new URLSearchParams(p);f===I.APPEARANCE?S.delete("section"):S.set("section",f),u(S,{replace:!0})},m=[{id:I.APPEARANCE,label:a("settings.section.appearance"),description:a("settings.section.appearance.description"),group:M.PERSONAL,Icon:$a,content:e.jsx(Ds,{})},...n?[{id:I.NATIVE_APP,label:a("settings.section.menubar"),description:a("settings.section.menubar.description"),group:M.APP,Icon:ye,content:e.jsx(Us,{})}]:[],...g?[{id:I.NETWORK,label:a("settings.section.network"),description:a("settings.section.network.description"),group:M.APP,Icon:Zt,content:e.jsx(Hs,{proxySettings:c})}]:[],{id:I.ACCOUNT,label:a("settings.section.account"),description:a("settings.section.account.description"),group:M.PERSONAL,Icon:za,content:e.jsx(us,{settings:t})},{id:I.CLOUD,label:a("settings.section.cloud"),description:a("settings.section.cloud.description"),group:M.PERSONAL,Icon:se,content:e.jsx(Ss,{settings:t,active:j===I.CLOUD})},{id:I.LIMITS,label:a("settings.section.limits"),description:a("settings.section.limits.description"),group:M.APP,Icon:Jt,content:e.jsxs("div",{className:"space-y-4",children:[e.jsxs(V,{title:a("settings.section.limits"),children:[e.jsx(E,{label:a("limits.settings.display_mode_label"),control:e.jsx(Ws,{prefs:s})}),y?null:e.jsxs(e.Fragment,{children:[e.jsx(E,{label:a("settings.menubar.toastOnReset"),hint:a("settings.menubar.toastOnResetHint"),control:e.jsx(D,{checked:o,disabled:!n,onChange:()=>r("toastOnReset",!o),ariaLabel:a("settings.menubar.toastOnReset")})}),e.jsx(E,{label:a("settings.menubar.confettiOnReset"),hint:a("settings.menubar.confettiOnResetHint"),control:e.jsx(D,{checked:d,disabled:!n,onChange:()=>r("confettiOnReset",!d),ariaLabel:a("settings.menubar.confettiOnReset")})})]}),e.jsx(E,{label:a("settings.limits.showSubscriptions"),hint:a("settings.limits.showSubscriptionsHint"),control:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>x("/limits?openSubscriptions=1"),"aria-label":a("limits.page.openSubscriptions"),title:a("limits.page.openSubscriptions"),className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 hover:text-oai-black dark:hover:text-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",children:e.jsx(Qt,{size:14,"aria-hidden":!0})}),e.jsx(D,{checked:s.showSubscriptions!==!1,onChange:()=>s.setShowSubscriptions(!s.showSubscriptions),ariaLabel:a("settings.limits.showSubscriptions")})]})})]}),e.jsx(V,{title:a("settings.limits.providers"),children:e.jsx(Va,{prefs:s})})]})},{id:I.LABS,label:a("settings.section.labs"),description:a("settings.section.labs.description"),group:M.DEVELOPER,Icon:Da,content:e.jsx(Gs,{})}],k=[{id:M.PERSONAL,label:a("settings.nav.group.personal")},{id:M.APP,label:a("settings.nav.group.app")},{id:M.DEVELOPER,label:a("settings.nav.group.developer")}].map(f=>({...f,sections:m.filter(S=>S.group===f.id)})).filter(f=>f.sections.length>0);let C=m[0];for(const f of m)if(f.id===j){C=f;break}return e.jsx("div",{className:B("flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",j===I.CLOUD&&"tt-cloud-settings"),children:e.jsx("main",{className:"flex-1 pb-12 pt-8 sm:pb-16 sm:pt-10",children:e.jsxs("div",{className:"mx-auto w-full max-w-5xl px-4 sm:px-6",children:[e.jsxs("div",{className:"mb-7 max-w-2xl",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-oai-black dark:text-white sm:text-4xl",children:a("settings.page.title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-oai-gray-500 dark:text-oai-gray-400 sm:text-base",children:a("settings.page.subtitle")})]}),e.jsxs("div",{className:"tt-settings-sections grid min-w-0 gap-6 md:grid-cols-[11rem_minmax(0,1fr)] md:gap-8",children:[e.jsx("aside",{className:"min-w-0 rounded-xl border border-oai-gray-200 bg-oai-gray-50/70 p-2 dark:border-oai-gray-800 dark:bg-oai-gray-900/60 md:border-0 md:bg-transparent md:p-0 md:dark:bg-transparent",children:e.jsx("nav",{"aria-label":a("settings.page.title"),className:"flex gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden md:sticky md:top-6 md:flex-col md:gap-4 md:overflow-visible",children:k.map(({id:f,label:S,sections:_})=>e.jsxs("div",{className:"flex shrink-0 gap-1 md:block",children:[e.jsx("div",{className:"hidden px-3 pb-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-oai-gray-400 dark:text-oai-gray-500 md:block",children:S}),e.jsx("div",{className:"flex gap-1 md:flex-col",children:_.map(({id:w,label:A,Icon:T})=>{const b=j===w;return e.jsxs("button",{id:`settings-nav-${w}`,type:"button","aria-current":b?"page":void 0,"aria-controls":`settings-panel-${w}`,onClick:()=>h(w),className:B("inline-flex min-h-10 min-w-max shrink-0 items-center gap-1.5 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand-500 md:w-full md:min-w-0 md:gap-2 md:px-3",b?"bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-white":"text-oai-gray-500 hover:bg-oai-gray-50 hover:text-oai-gray-900 dark:text-oai-gray-400 dark:hover:bg-oai-gray-900 dark:hover:text-oai-gray-200"),children:[e.jsx(T,{className:B("h-4 w-4 shrink-0",b?"text-oai-black dark:text-white":"text-oai-gray-400 dark:text-oai-gray-500"),"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:A})]},w)})})]},f))})}),e.jsxs("div",{className:"min-w-0",children:[j!==I.CLOUD?e.jsxs("div",{className:"mb-4 border-b border-oai-gray-200 pb-4 dark:border-oai-gray-800",children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight text-oai-black dark:text-white",children:C.label}),e.jsx("p",{className:"mt-1 text-sm leading-5 text-oai-gray-500 dark:text-oai-gray-400",children:C.description})]}):null,m.map(({id:f,label:S,content:_})=>e.jsx("section",{id:`settings-panel-${f}`,"aria-labelledby":`settings-nav-${f}`,"aria-label":S,"data-settings-panel":f,hidden:j!==f,children:_},f)),e.jsx($s,{})]})]})]})})})}export{In as SettingsPage};
|