tokentracker-cli 1.3.7 → 1.3.9
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-B6Ys-Iv6.js → AchievementBadge-C6ZoXGzv.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-C7EJYb05.js → AchievementsPage-BkHoOrUq.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-KjJeaWDP.js → AchievementsSection-BmK0_LQF.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-BdoapwT5.js → BadgeDetailModal-DwoD1Nsr.js} +1 -1
- package/dashboard/dist/assets/BotAnimated-m4GXCXTJ.js +1 -0
- package/dashboard/dist/assets/{Card-CMShFKqX.js → Card-D_SqQIBC.js} +1 -1
- package/dashboard/dist/assets/{CloudCheckoutPage-DQ16a4Ui.js → CloudCheckoutPage-BSYvxA_x.js} +1 -1
- package/dashboard/dist/assets/{CloudPage-D1PEMzr2.js → CloudPage-Bwnj7Ocg.js} +2 -2
- package/dashboard/dist/assets/{CommandPalette-t3sXFKqr.js → CommandPalette-CBMCbek2.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-DHyreMHY.js → CommunityStatsModal-DkMCREYc.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-DiguIoDY.js → ConfirmModal-DAt5opxx.js} +1 -1
- package/dashboard/dist/assets/Controls-DsJLsMpr.js +1 -0
- package/dashboard/dist/assets/DashboardPage-B4hR6Jr1.js +1 -0
- package/dashboard/dist/assets/{DateRangePopover-CVZTfOUX.js → DateRangePopover-CyAT0F7i.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-BagH0rTy.js → DevicePage-CaZzXt8j.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-IWs31AbB.js → DialogClose-Dg8Rrcbc.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-gdxwXQBG.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-CI8xcLkd.js → DialogTitle-CgQTzYDB.js} +1 -1
- package/dashboard/dist/assets/{ElectricLogo-CakZnEiu.js → ElectricLogo-PbWNE6Jw.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-BJiqknMG.js → FadeIn-CgGVCeA7.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-Bo6VoGCl.js → HeaderGithubStar-D8I6O4H1.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-DjJmYzbc.js → HoverTooltip-BQ0w0NcA.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-Cp2ELhP8.js → IpCheckPage-D9vVoMNk.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-gvBFMTKh.js → LandingPage-DNV9PcRZ.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardPage-CbWwclwl.js → LeaderboardPage-BVfC39jk.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProBadge-QK4hLmn1.js → LeaderboardProBadge-g6XLqOpA.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardProfileModal-DuggTNlv.js → LeaderboardProfileModal-Dxwperqt.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-CZZAm33s.js → LeaderboardProfilePage-C9552VgQ.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-DJkws70g.js → LimitsPage-CWaM8Ubc.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-Cf9NPAL1.js → LocalOnlyNotice-DJ8t4CkI.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-s3qsEOET.js → LoginCard-5cDUjlaP.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-BTLHl4eP.js → LoginModal-CaEskXOR.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-DDqQpy85.js → LoginPage--buWhwDc.js} +1 -1
- package/dashboard/dist/assets/PetPage-DZlGXdiW.js +2 -0
- package/dashboard/dist/assets/{PopoverPopup-B_fwRpm_.js → PopoverPopup-IQrgeWzz.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-B1oef_V8.js → ProviderIcon-CSKhjDnT.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-BduujSou.js → ResetPasswordPage-ClzIMLjQ.js} +1 -1
- package/dashboard/dist/assets/{Select-ClkKzKsi.js → Select-KHVnbrwD.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-D_4VNKEi.js → SelectItemText-BqAFvX8b.js} +1 -1
- package/dashboard/dist/assets/{SelfHostPage-CDNLHmOx.js → SelfHostPage-DHA9hDnA.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-V1exv7gK.js → ServiceStatusPage-A4WcSrnG.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-BR5gBSc1.js → SessionsPage-CWu0gXwO.js} +1 -1
- package/dashboard/dist/assets/SettingsPage-DzurIV6u.js +5 -0
- package/dashboard/dist/assets/{SkillsPage-D0oeWRew.js → SkillsPage-CfM8w0xf.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-h5USfWnF.js → TokenGalaxy-BiCXCnEH.js} +1 -1
- package/dashboard/dist/assets/TooltipPopup-BcnMVc6a.js +1 -0
- package/dashboard/dist/assets/{TrendMonitor-gMTrGZzH.js → TrendMonitor-PFSJn43N.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-xghIyvm_.js → WidgetsPage-CnH4zkP8.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-O4zzP87x.js → WrappedPage-BpsnuM4e.js} +1 -1
- package/dashboard/dist/assets/__vite-browser-external-CbUj3l39.css +1 -0
- package/dashboard/dist/assets/{__vite-browser-external-DKVGjnxf.js → __vite-browser-external-CbhiyufG.js} +2 -2
- package/dashboard/dist/assets/{agent-logos-CyXPIQ5S.js → agent-logos-DFupeEJz.js} +1 -1
- package/dashboard/dist/assets/{arrow-left-BqMZ7dgK.js → arrow-left-Cu0jOgzo.js} +1 -1
- package/dashboard/dist/assets/{arrow-right-D2cfRUf2.js → arrow-right-DgFuyz9F.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-DSJpQHMH.js → arrow-up-right-COoZfksW.js} +1 -1
- package/dashboard/dist/assets/{calendar-days-Cpu5CPAM.js → calendar-days-B_QPPq3a.js} +1 -1
- package/dashboard/dist/assets/{check-BTSG8HIW.js → check-D_enaDhp.js} +1 -1
- package/dashboard/dist/assets/{chevron-down-0nuZGQbD.js → chevron-down-Di_xdF9P.js} +1 -1
- package/dashboard/dist/assets/{cloud-checkout-Jv0vhd5v.js → cloud-checkout-DNFMqoiZ.js} +1 -1
- package/dashboard/dist/assets/{composite-_t6vz49X.js → composite-CUbvhoGL.js} +1 -1
- package/dashboard/dist/assets/{download-CzxvhDR9.js → download-CrDgjohg.js} +1 -1
- package/dashboard/dist/assets/{external-link-BwKhoPLM.js → external-link-DgnNV6zS.js} +1 -1
- package/dashboard/dist/assets/{flame-Bni4FlSO.js → flame-Lsd5DkgX.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-BLPhLm4w.js → format-tokens-DSxX2imE.js} +1 -1
- package/dashboard/dist/assets/{gift-lj3smodH.js → gift-BA3WiW1-.js} +1 -1
- package/dashboard/dist/assets/{host-mode-DluVCV7W.js → host-mode-BiJLkMdX.js} +1 -1
- package/dashboard/dist/assets/{icons-BThVE2Zq.js → icons-BxxxA-aw.js} +1 -1
- package/dashboard/dist/assets/{index-CETYrL7R.js → index-BTC0A20d.js} +1 -1
- package/dashboard/dist/assets/{index-D_ERbEBI.js → index-BlvkImKO.js} +1 -1
- package/dashboard/dist/assets/{index-CarMa6Pv.js → index-V-WILWJ0.js} +1 -1
- package/dashboard/dist/assets/{info-DSgWF_40.js → info-CluBWyTe.js} +1 -1
- package/dashboard/dist/assets/{link-2-C7H_UH8Q.js → link-2-M880npIj.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-B2ln5DKm.js → loader-circle-BEowiVYF.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-DHEGy9eE.js → modifiers.esm-pR4sKZep.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-BI3aJPNi.js → monitor-smartphone-GOnwL7NC.js} +1 -1
- package/dashboard/dist/assets/{play-CVxzAkNo.js → play-C2Yih72t.js} +1 -1
- package/dashboard/dist/assets/{plus-UGoZah-U.js → plus-KF6U4UP_.js} +1 -1
- package/dashboard/dist/assets/{provider-display-C-ibpm5u.js → provider-display-Bio3tJX4.js} +1 -1
- package/dashboard/dist/assets/{react-_bbDNdaT.js → react-Dt52_FiQ.js} +1 -1
- package/dashboard/dist/assets/{safePolygon-DeLf2a7a.js → safePolygon-D7wQNKcm.js} +1 -1
- package/dashboard/dist/assets/{search-BzL7DvcZ.js → search-CW0YCdKx.js} +1 -1
- package/dashboard/dist/assets/{server-BsilXoLs.js → server-DKLG1DuM.js} +1 -1
- package/dashboard/dist/assets/{shield-check-Dx8cSMB0.js → shield-check-DkJ3sCHH.js} +1 -1
- package/dashboard/dist/assets/{skills-api-CnOpyIPR.js → skills-api-yS1uW-mw.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-DrIfxJ2p.js → sortable.esm-DZo9A4kG.js} +1 -1
- package/dashboard/dist/assets/{store-CjkDYjXp.js → store-BbYtf4Vy.js} +1 -1
- package/dashboard/dist/assets/{terminal-CExBqXDx.js → terminal-FK6txO2c.js} +1 -1
- package/dashboard/dist/assets/{trash-DSHRpaMy.js → trash-QX4FHz_p.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-B1W63PCE.js → use-community-stats-DaURJ5sU.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-8-lur0NI.js → use-latest-request-guard-BZnnoQct.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-Dq0e_5PV.js → use-limits-display-prefs-C77UTTya.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-CkPyWn4W.js → use-native-settings-DHS101SR.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-Cul7GZDv.js → use-ordered-list-h5iXqXbU.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-Bpc6LGag.js +1 -0
- package/dashboard/dist/assets/use-session-efficiency-pref-DZVvvmoq.js +1 -0
- package/dashboard/dist/assets/{use-transform-DzUhSbxH.js → use-transform-dcPyhMQK.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-3ZkgTe7n.js → use-usage-limits-BBAi4Wvb.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-EbqxSlEF.js → useCurrency-CW5GHWIB.js} +1 -1
- package/dashboard/dist/assets/{usePositioner-cTX1WPQP.js → usePositioner-BQgBHX5s.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-CanmWK4w.js → useTokenFormat-DntK8yNR.js} +1 -1
- package/dashboard/dist/assets/{zap-DQHYg9o6.js → zap-Brp6hC7u.js} +1 -1
- package/dashboard/dist/index.html +2 -2
- package/dashboard/dist/ip-check.html +2 -2
- package/dashboard/dist/leaderboard.html +2 -2
- package/dashboard/dist/share.html +2 -2
- package/package.json +1 -1
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/dashboard/dist/assets/BotAnimated-coLP7eiI.js +0 -1
- package/dashboard/dist/assets/CloudUsageExport-Dn7_qVGy.js +0 -4
- package/dashboard/dist/assets/Controls-D6267L_q.js +0 -1
- package/dashboard/dist/assets/DashboardPage-0xC6i2rZ.js +0 -1
- package/dashboard/dist/assets/DialogDescription-JwE-wyWI.js +0 -1
- package/dashboard/dist/assets/PetPage-D4P5yDL8.js +0 -1
- package/dashboard/dist/assets/SettingsPage-LJJCS1G0.js +0 -2
- package/dashboard/dist/assets/TooltipPopup-1KxZ_iHu.js +0 -1
- package/dashboard/dist/assets/__vite-browser-external-DvNSoTb8.css +0 -1
- package/dashboard/dist/assets/skins-Mc0sI20C.js +0 -1
- package/dashboard/dist/assets/use-pet-settings-DkNURWe6.js +0 -2
- package/dashboard/dist/assets/use-reduced-motion-CkHJN2uY.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as L,al as q,r as n,c as a,j as e,y as g,bb as le,bc as V,X as ne}from"./__vite-browser-external-DKVGjnxf.js";import{T as $,S as de}from"./Controls-D6267L_q.js";import{P as ce}from"./ProviderIcon-B1oef_V8.js";import{u as pe,p as me,C as W,B as xe,a as be,b as ue}from"./use-pet-settings-DkNURWe6.js";import{u as ge}from"./use-native-settings-CkPyWn4W.js";import{C as A}from"./skins-Mc0sI20C.js";import{F}from"./FadeIn-BJiqknMG.js";import{L as he}from"./link-2-C7H_UH8Q.js";import{L as X}from"./loader-circle-B2ln5DKm.js";import{Z as fe}from"./zap-DQHYg9o6.js";import{T as ye}from"./trash-DSHRpaMy.js";import{D as ke,a as ve,b as je,c as we,d as Ne,e as Ce}from"./DialogTitle-CI8xcLkd.js";import{D as Se}from"./DialogDescription-JwE-wyWI.js";import{D as Ie}from"./DialogClose-IWs31AbB.js";import"./Card-CMShFKqX.js";import"./react-_bbDNdaT.js";import"./use-reduced-motion-CkHJN2uY.js";import"./composite-_t6vz49X.js";import"./store-CjkDYjXp.js";const Y={name:"file-archive",size:24,node:[["path",{d:"M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5",key:"4pqfef"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 12v-1",key:"1ej8lb"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["path",{d:"M8 7V6",key:"1nbb54"}],["circle",{cx:"8",cy:"20",r:"2",key:"ckkr5m"}]]};Y.node;const Pe=L(Y);const Z={name:"monitor-up",size:24,node:[["path",{d:"m9 10 3-3 3 3",key:"11gsxs"}],["path",{d:"M12 13V7",key:"h0r20n"}],["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}]]};Z.node;const De=L(Z);const G={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};G.node;const ze=L(G),v=[{id:"clawd",displayName:"Clawd",nameKey:"pet.character.clawd",spriteVersionNumber:1,custom:!1},{id:"bot",displayName:"Bot",nameKey:"pet.character.bot",spriteVersionNumber:1,custom:!1},{id:"sprout",displayName:"Sprout",nameKey:"pet.character.sprout",spriteVersionNumber:1,custom:!1,assetUrl:"/pets/sprout/spritesheet.webp"},{id:"byte",displayName:"Byte",nameKey:"pet.character.byte",spriteVersionNumber:1,custom:!1,assetUrl:"/pets/byte/spritesheet.webp"},{id:"ember",displayName:"Ember",nameKey:"pet.character.ember",spriteVersionNumber:1,custom:!1,assetUrl:"/pets/ember/spritesheet.webp"}];async function P(t){const r=await t.json().catch(()=>null);if(!t.ok||r?.ok===!1)throw new Error(r?.error||`Pet request failed with HTTP ${t.status}`);return r}async function Te(){const t=await fetch("/functions/tokentracker-pets",{headers:{Accept:"application/json"},cache:"no-store"}),r=await P(t),o=new Set(Array.isArray(r.hiddenBuiltinIds)?r.hiddenBuiltinIds:[]);return[...v.filter(s=>!s.assetUrl||!o.has(s.id)),...Array.isArray(r.pets)?r.pets:[]]}async function O(t){const r=await q();return P(await fetch("/functions/tokentracker-pets",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...r},cache:"no-store",body:JSON.stringify(t)}))}function _e(t){return O({action:"install_url",url:t})}async function H(t){const r=await q();return P(await fetch("/api/pets/import",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/zip",...r},cache:"no-store",body:t}))}function Ae(t){return O({action:"remove",id:t})}async function Be(){const t=await fetch("/functions/tokentracker-pets?scope=codex",{headers:{Accept:"application/json"},cache:"no-store"}),r=await P(t);return{importable:Array.isArray(r.importable)?r.importable:[],codexDetected:r.codexDetected===!0}}function Le(t){return O({action:"import_codex",ids:t})}let B=v;function Oe(){const[t,r]=n.useState(B),[o,s]=n.useState(!0),[x,d]=n.useState(!1),b=n.useCallback(async()=>{s(!0);try{const m=await Te();return B=m,r(m),d(!0),m}catch{return B=v,r(v),d(!1),v}finally{s(!1)}},[]);return n.useEffect(()=>{b()},[b]),{pets:t,loading:o,available:x,refresh:b}}const Ee={clawd:"from-oai-amber-50 dark:from-orange-950/70",bot:"from-oai-brand-50 dark:from-teal-950/70",sprout:"from-oai-brand-100 dark:from-emerald-950/70",byte:"from-oai-gray-200 dark:from-slate-800/70",ember:"from-orange-100 dark:from-orange-950/80"};function Me(){const t=a("pet.import.subtitle"),r="codex-pets.net",o=t.indexOf(r);return o<0?t:e.jsxs(e.Fragment,{children:[t.slice(0,o),e.jsx("a",{href:"https://codex-pets.net",target:"_blank",rel:"noreferrer",className:"underline decoration-oai-gray-400 underline-offset-2 transition-colors hover:text-oai-black dark:decoration-oai-gray-500 dark:hover:text-white",children:r}),t.slice(o+r.length)]})}const j=[{id:"idle-living",labelKey:"pet.state.calm"},{id:"working-thinking",labelKey:"pet.state.focus"},{id:"working-juggling",labelKey:"pet.state.multitask"},{id:"working-wizard",labelKey:"pet.state.streak"},{id:"happy",labelKey:"pet.state.celebrate"},{id:"sleeping",labelKey:"pet.state.rest"}];function J({character:t,selected:r,onSelect:o,onRemove:s,removeDisabled:x}){const d=t.nameKey?a(t.nameKey):t.displayName;return e.jsxs("div",{className:"group relative",children:[e.jsxs("button",{type:"button",onClick:o,"aria-pressed":r,className:g("relative w-full overflow-hidden rounded-xl border p-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",r?"border-oai-brand-500/40 bg-white dark:border-oai-brand-500/25 dark:bg-oai-gray-900/80":"border-oai-gray-200/80 bg-white/55 hover:border-oai-gray-400 dark:border-oai-gray-800 dark:bg-oai-gray-950/55 dark:hover:border-oai-gray-600"),children:[e.jsx("div",{className:g("absolute inset-0 bg-gradient-to-br to-transparent opacity-80 dark:opacity-55",Ee[t.id]||"from-oai-gray-200/80 dark:from-oai-gray-800/70")}),e.jsxs("div",{className:"relative flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center",children:e.jsx(W,{state:"idle-living",character:t.id,pet:t,size:44})}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-oai-black dark:text-white",children:d}),t.spriteVersionNumber===2?e.jsx("span",{className:"shrink-0 rounded border border-oai-gray-300/80 px-1 text-[9px] font-semibold text-oai-gray-500 dark:border-oai-gray-600 dark:text-oai-gray-400",children:a("pet.format.v2")}):null,r?e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-oai-brand-500","aria-hidden":!0}):null]})]})]}),s?e.jsx("button",{type:"button",disabled:x,onClick:s,"aria-label":`${a("pet.import.remove")} · ${d}`,className:g("absolute right-1.5 top-1.5 flex h-6 w-6 items-center justify-center rounded-md border border-oai-gray-200/90 bg-white/95 text-oai-gray-500 transition-opacity hover:text-red-600 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500 disabled:opacity-40 dark:border-oai-gray-700 dark:bg-oai-gray-900/95 dark:text-oai-gray-400 dark:hover:text-red-400","opacity-0 group-hover:opacity-100"),children:e.jsx(ye,{className:"h-3 w-3","aria-hidden":!0})}):null]})}function Ke({value:t,onChange:r}){const o={auto:a("pet.bot.color.auto"),bleu:a("pet.bot.color.bleu"),turquoise:a("pet.bot.color.turquoise"),vert:a("pet.bot.color.vert"),ambre:a("pet.bot.color.ambre"),rose:a("pet.bot.color.rose"),violet:a("pet.bot.color.violet")};return e.jsx("div",{className:"flex flex-wrap items-center justify-end gap-1.5 rounded-full border border-black/5 bg-white/65 px-2.5 py-1.5 backdrop-blur-md dark:border-white/10 dark:bg-black/20",role:"radiogroup","aria-label":a("pet.bot.color"),children:xe.map(s=>{const x=(t||"auto")===s;return e.jsx("button",{type:"button",role:"radio","aria-checked":x,"aria-label":o[s],title:o[s],onClick:()=>r(s),className:g("h-4 w-4 rounded-full border transition-transform duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand-500",x?"scale-125 border-oai-black shadow-sm dark:border-white":"border-black/15 hover:scale-110 dark:border-white/25"),style:s==="auto"?{background:`linear-gradient(135deg, ${A.get(be).hex} 0 50%, ${A.get(ue).hex} 50% 100%)`}:{background:A.get(s)?.hex}},s)})})}function Re({pet:t,state:r,onStateChange:o,botColor:s,onBotColorChange:x}){const[d,b]=n.useState(null),m=n.useRef(null),h=j.find(function(l){return l.id===r}),c=a(h?.labelKey||"pet.state.calm");return e.jsxs("section",{className:"relative flex min-h-[400px] flex-col overflow-hidden bg-oai-gray-50 dark:bg-oai-gray-950 sm:min-h-[440px] lg:min-h-[480px]",onPointerMove:p=>{if(t?.spriteVersionNumber!==2||!m.current)return;const l=m.current.getBoundingClientRect(),w=p.clientX-(l.left+l.width/2),N=p.clientY-(l.top+l.height/2),y=(Math.atan2(w,-N)*180/Math.PI+360)%360;b(Math.round(y/22.5)%16)},onPointerLeave:()=>b(null),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.16] dark:opacity-[0.12]",style:{backgroundImage:"radial-gradient(currentColor 0.7px, transparent 0.7px)",backgroundSize:"14px 14px"},"aria-hidden":!0}),e.jsxs("div",{className:"relative flex items-center justify-between gap-3 px-5 pt-5",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-oai-gray-500 dark:text-oai-gray-400",children:a("pet.preview.states")}),e.jsxs("div",{className:"flex items-center gap-2",children:[me(t?.id)==="vector"?e.jsx(Ke,{value:s,onChange:x}):null,e.jsxs("div",{className:"flex items-center gap-2 rounded-full border border-black/5 bg-white/65 px-3 py-1.5 text-[11px] font-medium text-oai-gray-600 backdrop-blur-md dark:border-white/10 dark:bg-black/20 dark:text-oai-gray-300",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500","aria-hidden":!0}),c]})]})]}),e.jsx("div",{className:"relative flex flex-1 items-center justify-center px-6 py-5",children:e.jsx("div",{ref:m,className:"relative flex h-52 w-52 items-center justify-center sm:h-56 sm:w-56 lg:h-64 lg:w-64",children:e.jsx("div",{className:"origin-bottom lg:scale-[1.18]",children:e.jsx(W,{state:r,character:t?.id||"clawd",pet:t,size:190,lookDirectionIndex:d,botColor:s})})})}),e.jsx("div",{className:"relative border-t border-oai-gray-200/70 bg-white/85 px-3 py-2 dark:border-oai-gray-800 dark:bg-oai-gray-950/85",children:e.jsx("div",{className:"grid grid-cols-3 gap-1","aria-label":a("pet.preview.states"),children:j.map(p=>e.jsxs("button",{type:"button",onClick:()=>o(p.id),"aria-pressed":r===p.id,className:g("flex min-h-10 flex-col items-center justify-center gap-1 rounded-lg px-1.5 text-xs transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand-500",r===p.id?"font-semibold text-oai-black dark:text-white":"font-medium text-oai-gray-500 hover:text-oai-black dark:text-oai-gray-400 dark:hover:text-white"),children:[e.jsx("span",{children:a(p.labelKey)}),e.jsx("span",{className:g("h-1 w-1 rounded-full transition-colors duration-200",r===p.id?"bg-oai-black dark:bg-white":"bg-transparent"),"aria-hidden":!0})]},p.id))})})]})}function Ue({pets:t,busy:r,error:o,onImport:s,onClose:x}){const[d,b]=n.useState(()=>new Set),m=c=>b(p=>{const l=new Set(p);return l.has(c)?l.delete(c):l.add(c),l}),h=t.length!==0&&d.size===t.length;return e.jsx(ke,{open:!0,onOpenChange:c=>{!c&&!r&&x()},children:e.jsxs(ve,{children:[e.jsx(je,{className:"fixed inset-0 z-50 bg-black/15 backdrop-blur-md dark:bg-black/40 animate-tt-fade-in"}),e.jsx(we,{className:"fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6",children:e.jsxs(Ne,{className:"relative flex max-h-[86vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-oai-gray-200/50 bg-white/95 shadow-2xl backdrop-blur-2xl dark:border-white/10 dark:bg-oai-gray-900/95 animate-tt-modal",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-oai-gray-200/70 px-5 py-4 dark:border-oai-gray-800",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(Ce,{className:"text-base font-semibold",children:a("pet.codex.title")}),e.jsx(Se,{className:"mt-0.5 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:a("pet.codex.subtitle")})]}),e.jsx(Ie,{type:"button",disabled:r,"aria-label":a("pet.codex.close"),className:"shrink-0 rounded-full border border-oai-gray-200/60 p-1.5 text-oai-gray-500 transition-colors hover:text-oai-black disabled:opacity-40 dark:border-oai-gray-800/60 dark:text-oai-gray-400 dark:hover:text-white",children:e.jsx(ne,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4",children:[t.length===0?e.jsx("p",{className:"py-8 text-center text-sm text-oai-gray-400 dark:text-oai-gray-500",children:a("pet.codex.empty")}):e.jsx("div",{className:"grid grid-cols-2 gap-2.5 sm:grid-cols-3",children:t.map(c=>e.jsx(J,{character:c,selected:d.has(c.id),onSelect:()=>m(c.id)},c.id))}),o?e.jsx("p",{role:"alert",className:"mt-3 text-xs text-red-600 dark:text-red-400",children:o}):null]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-t border-oai-gray-200/70 px-5 py-3 dark:border-oai-gray-800",children:[e.jsx("button",{type:"button",disabled:r||t.length===0,onClick:()=>b(h?new Set:new Set(t.map(c=>c.id))),className:"text-xs font-medium text-oai-gray-500 underline-offset-2 hover:underline disabled:opacity-40 dark:text-oai-gray-400",children:a("pet.codex.select_all")}),e.jsxs("button",{type:"button",disabled:r||d.size===0,onClick:()=>s([...d]),className:"flex h-9 items-center gap-1.5 rounded-lg bg-oai-black px-4 text-xs font-semibold text-white transition-colors disabled:bg-oai-gray-200 disabled:text-oai-gray-400 dark:bg-white dark:text-black dark:disabled:bg-oai-gray-800 dark:disabled:text-oai-gray-500",children:[r?e.jsx(X,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):null,d.size>0?`${a("pet.codex.import")} · ${d.size}`:a("pet.codex.import")]})]})]})})]})})}function lt(){const{available:t,settings:r,setSetting:o}=pe(),{pets:s,loading:x,available:d,refresh:b}=Oe(),[m,h]=n.useState(""),[c,p]=n.useState(""),[l,w]=n.useState(!1),[N,y]=n.useState([]),[Q,D]=n.useState(!1),[C,E]=n.useState(!1),[ee,z]=n.useState(""),[te,M]=n.useState("idle-living"),[K,ae]=n.useState(!0),k=r.character||"clawd",T=ge(),R=T.settings?.menuBarIconStyle==="pet",re=s.find(i=>i.id===k)||s[0],S=l?{kind:"busy",text:a("pet.import.busy")}:c?{kind:"error",text:c}:null,U=N.length!==0;n.useEffect(()=>{!x&&s.length>0&&!s.some(i=>i.id===k)&&o("character","clawd")},[x,s,k,o]);async function I(i,u=a("pet.import.success")){w(!0),p("");try{const f=await i();await b(),le(),f?.pet?.id&&o("character",f.pet.id),V({title:u,timeout:4e3}),h("")}catch(f){p(f?.message||a("pet.import.failed"))}finally{w(!1)}}const _=n.useCallback(async()=>{if(!d){y([]);return}try{const i=await Be();y(i.importable)}catch{y([])}},[d]);n.useEffect(()=>{_()},[_]);async function ie(i){E(!0),z("");try{return await Le(i),await b(),await _(),V({title:a("pet.codex.imported"),timeout:4e3}),!0}catch(u){return z(u?.message||a("pet.import.failed")),!1}finally{E(!1)}}n.useEffect(()=>{if(!K)return;const i=window.setInterval(()=>{M(u=>{const f=j.findIndex(oe=>oe.id===u);return j[(f+1)%j.length].id})},5e3);return()=>window.clearInterval(i)},[K]);const se=[{value:"small",label:a("pet.size.small")},{value:"medium",label:a("pet.size.medium")},{value:"large",label:a("pet.size.large")}];return e.jsx("div",{className:"flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",children:e.jsx("main",{className:"flex-1 pb-14 pt-8 sm:pt-10",children:e.jsxs("div",{className:"mx-auto max-w-5xl px-4 sm:px-6",children:[e.jsx(F,{y:12,children:e.jsxs("header",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight sm:text-4xl",children:a("pet.page.title")}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:a("pet.page.subtitle")})]})}),e.jsx(F,{y:12,delay:.04,children:e.jsxs("div",{className:"overflow-hidden rounded-[28px] border border-oai-gray-200 bg-white/75 dark:border-oai-gray-800 dark:bg-oai-gray-900/60 lg:grid lg:grid-cols-[1.12fr_0.88fr]",children:[e.jsx(Re,{pet:re,state:te,onStateChange:i=>{ae(!1),M(i)},botColor:r.botColor,onBotColorChange:i=>o("botColor",i)}),e.jsxs("aside",{className:"flex flex-col border-t border-oai-gray-200 p-5 dark:border-oai-gray-800 lg:min-h-[480px] lg:border-l lg:border-t-0",children:[e.jsxs("section",{"aria-labelledby":"pet-character-title",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"pet-character-title",className:"text-sm font-semibold",children:a("pet.characters.title")}),e.jsx("p",{className:"mt-1 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:a("pet.characters.subtitle")})]}),e.jsx("div",{className:"mt-4 grid max-h-72 grid-cols-2 gap-2 overflow-y-auto pr-1 -mr-1",children:s.map(i=>e.jsx(J,{character:i,selected:k===i.id,onSelect:()=>o("character",i.id),removeDisabled:l,onRemove:d&&i.id!=="clawd"&&i.id!=="bot"?()=>I(async()=>(await Ae(i.id),k===i.id&&o("character","clawd"),null),a("pet.import.removed")):void 0},i.id))}),T.available?e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-3 rounded-xl border border-oai-gray-200/70 bg-oai-gray-50/60 px-3 py-2.5 dark:border-oai-gray-800 dark:bg-oai-gray-900/40",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold",children:a("pet.menubar.title")}),e.jsx("p",{className:"mt-0.5 text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:a("pet.menubar.hint")})]}),e.jsx($,{checked:R,onChange:()=>T.setSetting("menuBarIconStyle",R?"clawd":"pet"),ariaLabel:a("pet.menubar.title")})]}):null]}),d?e.jsxs("section",{className:"mt-6 border-t border-oai-gray-200/70 pt-5 dark:border-oai-gray-800","aria-labelledby":"pet-import-title",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4 shrink-0 text-oai-gray-500","aria-hidden":!0}),e.jsx("h2",{id:"pet-import-title",className:"text-sm font-semibold",children:a("pet.import.title")})]}),e.jsx("p",{className:"mt-1 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:e.jsx(Me,{})}),e.jsxs("form",{className:"mt-3 flex gap-2",onSubmit:i=>{i.preventDefault(),!l&&m.trim()&&I(()=>_e(m))},children:[e.jsxs("label",{className:"relative flex min-w-0 flex-1 items-center",children:[e.jsx(he,{className:"pointer-events-none absolute left-3 h-3.5 w-3.5 text-oai-gray-400","aria-hidden":!0}),e.jsx("input",{value:m,onChange:i=>h(i.target.value),"aria-label":a("pet.import.url_label"),placeholder:"codex-pets.net/#/pets/…",className:"h-9 w-full rounded-lg border border-oai-gray-200 bg-white pl-9 pr-3 text-xs outline-none focus:border-oai-brand-500 dark:border-oai-gray-700 dark:bg-oai-gray-950"})]}),e.jsxs("button",{type:"submit",disabled:l||!m.trim(),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-lg bg-oai-black px-3.5 text-xs font-semibold text-white transition-colors disabled:bg-oai-gray-200 disabled:text-oai-gray-400 dark:bg-white dark:text-black dark:disabled:bg-oai-gray-800 dark:disabled:text-oai-gray-500",children:[l?e.jsx(X,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":!0}):null,a("pet.import.add")]})]}),e.jsxs("div",{className:g("mt-2 grid gap-2",U?"grid-cols-2":"grid-cols-1"),children:[U?e.jsxs("button",{type:"button",disabled:l||C,onClick:()=>{z(""),D(!0)},className:g("flex h-9 cursor-pointer items-center justify-center gap-1.5 rounded-lg border border-dashed border-oai-gray-300 text-xs font-medium text-oai-gray-500 transition-colors hover:border-oai-gray-500 hover:text-oai-black dark:border-oai-gray-600 dark:text-oai-gray-400 dark:hover:border-oai-gray-400 dark:hover:text-white",(l||C)&&"pointer-events-none opacity-40"),children:[e.jsx(ce,{provider:"codex",size:14,className:"fill-current"}),a("pet.codex.browse")]}):null,e.jsxs("label",{onDragOver:i=>i.preventDefault(),onDrop:i=>{if(i.preventDefault(),l)return;const u=i.dataTransfer?.files?.[0];u&&I(()=>H(u))},className:g("flex h-9 cursor-pointer items-center justify-center gap-1.5 rounded-lg border border-dashed border-oai-gray-300 text-xs font-medium text-oai-gray-500 transition-colors hover:border-oai-gray-500 hover:text-oai-black dark:border-oai-gray-600 dark:text-oai-gray-400 dark:hover:border-oai-gray-400 dark:hover:text-white",l&&"pointer-events-none opacity-40"),children:[e.jsx(Pe,{className:"h-3.5 w-3.5","aria-hidden":!0}),a("pet.import.zip"),e.jsx("input",{type:"file",accept:".zip,.codex-pet.zip,application/zip",className:"sr-only",disabled:l,onChange:i=>{const u=i.target.files?.[0];u&&I(()=>H(u)),i.target.value=""}})]})]}),S?e.jsx("p",{role:S.kind==="error"?"alert":"status",className:g("mt-2 text-xs",S.kind==="error"?"text-red-600 dark:text-red-400":"text-oai-gray-500 dark:text-oai-gray-400"),children:S.text}):null,Q?e.jsx(Ue,{pets:N,busy:C,error:ee,onClose:()=>{C||D(!1)},onImport:async i=>{await ie(i)&&D(!1)}}):null]}):null,e.jsxs("section",{className:"mt-6 border-t border-oai-gray-200/70 pt-5 dark:border-oai-gray-800",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4 text-oai-gray-500 dark:text-oai-gray-400",strokeWidth:1.75,"aria-hidden":!0}),e.jsx("h2",{className:"text-sm font-semibold",children:a("pet.controls.title")})]}),e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"text-sm font-medium",children:a("pet.controls.show")}),e.jsx($,{checked:r.visible,onChange:()=>o("visible",!r.visible),disabled:!t,ariaLabel:a("pet.controls.show")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("div",{className:"text-sm font-medium",children:a("pet.controls.size")}),e.jsx("div",{className:"shrink-0",children:e.jsx(de,{options:se,value:r.size,onChange:i=>o("size",i),disabled:!t})})]})]})]}),t?null:e.jsxs("div",{className:"mt-6 flex gap-2 rounded-xl bg-oai-gray-100 p-3 text-xs leading-relaxed text-oai-gray-500 dark:bg-oai-gray-800/70 dark:text-oai-gray-400",children:[e.jsx(fe,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}),a("pet.controls.native_only")]})]})]})})]})})})}export{lt as PetPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/__vite-browser-external-DKVGjnxf.js","assets/__vite-browser-external-DvNSoTb8.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 I,a8 as G,cv as kt,a9 as z,ar as wt,cw as ue,a5 as Z,aB as Nt,a1 as _t,af as St,au as ne,R as be,cx as Ct,L as ie,aM as Et,av 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-DKVGjnxf.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-DrIfxJ2p.js";import{a as ca}from"./modifiers.esm-DHEGy9eE.js";import{d as Le,l as Te,u as da,b as Ie}from"./use-limits-display-prefs-Dq0e_5PV.js";import{P as ua}from"./ProviderIcon-B1oef_V8.js";import{a as E,S as q,b as V,T as D}from"./Controls-D6267L_q.js";import{m as qe}from"./react-_bbDNdaT.js";import{P as ma,C as We,a as ga,u as pa,b as ha}from"./CloudUsageExport-Dn7_qVGy.js";import{C as fa}from"./check-BTSG8HIW.js";import{C as xa,i as ba}from"./host-mode-DluVCV7W.js";import{A as Ye}from"./index-D_ERbEBI.js";import{r as ya,C as ge,o as va}from"./cloud-checkout-Jv0vhd5v.js";import{G as Re}from"./gift-lj3smodH.js";import{C as ja}from"./chevron-down-0nuZGQbD.js";import{C as pe}from"./Card-CMShFKqX.js";import{E as De}from"./external-link-BwKhoPLM.js";import{a as ka,P as wa}from"./play-CVxzAkNo.js";import{I as Ze}from"./info-DSgWF_40.js";import{a as Na,b as _a,c as Sa,d as Ca,e as Ea}from"./TooltipPopup-1KxZ_iHu.js";import{L as Pa}from"./loader-circle-B2ln5DKm.js";import{u as Oa}from"./useCurrency-EbqxSlEF.js";import{u as Aa}from"./useTokenFormat-CanmWK4w.js";import{S as ve}from"./Select-ClkKzKsi.js";import{u as re}from"./use-native-settings-CkPyWn4W.js";import{C as La}from"./ConfirmModal-DiguIoDY.js";import{A as Ta}from"./arrow-up-right-DSJpQHMH.js";import{D as Ia}from"./download-CzxvhDR9.js";import"./DialogTitle-CI8xcLkd.js";import"./composite-_t6vz49X.js";import"./store-CjkDYjXp.js";import"./SelectItemText-D_4VNKEi.js";import"./usePositioner-cTX1WPQP.js";import"./safePolygon-DeLf2a7a.js";import"./DialogClose-IWs31AbB.js";import"./DateRangePopover-CVZTfOUX.js";import"./calendar-days-Cpu5CPAM.js";import"./PopoverPopup-B_fwRpm_.js";import"./DialogDescription-JwE-wyWI.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}),v={transform:la.Transform.toString(g)||void 0,transition:o,zIndex:d?20:void 0};return e.jsxs("div",{ref:c,style:v,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:h=>h.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,v=Xt(Ae(aa,{activationConstraint:{distance:6}}),Ae(ta,{coordinateGetter:ea})),h=({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:v,collisionDetection:na,modifiers:[ca],onDragEnd:h,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[v,h]=l.useState(null),u=v?.scope===o?v:null;l.useEffect(()=>{o.active=!0;const k=()=>{const m=X();c(m),m||h(b=>b?.scope===o?{...b,error:null}:b)},f=()=>{h(m=>m?.scope===o?{...m,error:null}:m),de(i,"cloud-sync")};return k(),window.addEventListener("tt.cloudSyncChanged",k),window.addEventListener("storage",k),window.addEventListener(we,f),()=>{o.active=!1,window.removeEventListener("tt.cloudSyncChanged",k),window.removeEventListener("storage",k),window.removeEventListener(we,f)}},[o,i]);const x=l.useCallback(async()=>{if(!g||!X()||o.busy||!o.active||d.current!==o)return;o.busy=!0,h({scope:o,pending:!0,error:null});const k=()=>o.active&&d.current===o&&X();try{await xt(()=>t())}catch(f){if(!k())return;["cloud_membership_required","cloud_read_only_expired","cloud_history_window_exceeded","cloud_machine_limit","machine_limit_exceeded","cloud_machine_paused"].includes(f?.code)?bt(i,f.code,f.membership,"cloud-sync"):h({scope:o,pending:!0,error:{code:"billing_network_error"}}),je("cloud sync",f)}finally{o.busy=!1,o.active&&d.current===o&&h(f=>f?.scope===o?{...f,pending:!1}:f)}},[g,o,t,i]),j=l.useCallback(async()=>{if(!g||o.busy||!o.active||d.current!==o)return;const k=!X();h({scope:o,pending:!1,error:null}),Ne(k),c(k),k?await x():de(i,"cloud-sync")},[g,o,x,i]),N=l.useCallback(()=>{!g||!o.active||d.current!==o||(Ne(!1),c(!1),h(k=>k?.scope===o?{...k,error:null}:k),de(i,"cloud-sync"))},[g,o,i]);return{cloudSyncOn:r,cloudSyncPending:!!u?.pending,cloudSyncError:u?.error,handleCloudSyncToggle:j,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),[v,h]=l.useState(null),[u,x]=l.useState(!1),[j,N]=l.useState(""),[k,f]=l.useState(!1),[m,b]=l.useState(""),[C,p]=l.useState(""),[S,_]=l.useState(!1),[w,A]=l.useState(null),T=l.useMemo(()=>Ka(t),[t]),y=l.useMemo(()=>qa(t),[t]),P=l.useMemo(()=>typeof t?.id=="string"?t.id.trim():"",[t]),U=l.useMemo(()=>({setAnonymousOn:r,setCustomDisplayName:h,setGithubUrl:b,setProfileLoading:g,setPublicProfileOn:n,setShowGithubOn:f}),[]);return{anonymousOn:i,customDisplayName:v,displayName:T,editingGithub:S,editingName:u,email:y,githubError:w,githubInput:C,githubUrl:m,loadSetters:U,nameInput:j,profileLoading:c,profileSaving:o,publicProfileOn:s,setAnonymousOn:r,setCustomDisplayName:h,setEditingGithub:_,setEditingName:x,setGithubError:A,setGithubInput:p,setGithubUrl:b,setNameInput:N,setProfileLoading:g,setProfileSaving:d,setPublicProfileOn:n,setShowGithubOn:f,showGithubOn:k,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),v=ss(r,g);return{...t,...c,email:r.email,handlePublicProfileToggle:o.handlePublicProfileToggle,userId:r.userId,name:Xa(r,{...o,...d}),github:es(r,v),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:v,setEditingName:h,setNameInput:u,startEditingName:x}=t,j=s?a("settings.account.displayNameAnonymousHint"):n||i;return e.jsx(rt,{label:a("settings.account.displayName"),editing:r,hint:j,editor:e.jsx(ns,{nameInput:o,setEditingName:h,setNameInput:u,profileSaving:v,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:v,setGithubError:h,setGithubInput:u,showGithubOn:x,startEditingGithub:j}=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:v,setGithubError:h,setGithubInput:u}),actions:e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(it,{label:a("settings.account.edit"),onClick:j}),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 se(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",[v,h]=l.useState(!1),u=d&&typeof g=="boolean"?g:v,[x,j]=l.useState(""),[N,k]=l.useState(!1),[f,m]=l.useState(null),[b,C]=l.useState(null),[p,S]=l.useState(!1),_=l.useId(),w=l.useRef(null),A=l.useRef(null),T=l.useRef(!1),y=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(()=>(y.current=!0,P.current+=1,A.current=null,T.current=!1,h(!1),j(""),k(!1),m(null),C(null),S(!1),()=>{y.current=!1,P.current+=1}),[U]);const K=t?.membership?.status==="self_hosted"||t?.membership?.hosting_mode==="self_hosted",M=t?.gift_redemption_available===!0,J=d?t?.gifts||[]:[];if(!s?.signedIn||K||!M&&!J.length)return null;const Y=t.redemption_restriction,ee=O=>{!O&&T.current||(typeof g!="boolean"&&h(O),o?.(O))},L=async(O,oe)=>{const le=await n();oe()&&S(!!le?.gifts?.some(H=>H.id===O?.id))},te=async O=>{if(T.current||O&&(!M||!x.trim()))return;if(O&&Y&&Y!=="gift_checkout_pending"){m(new ue(Y));return}T.current=!0;const oe=++P.current,le=U,H=()=>y.current&&P.current===oe&&F.current===le;k(!0),m(null);try{if(O){const ae=x.trim();(!A.current||se(A.current.code)!==se(ae))&&(A.current={code:ae,request_id:crypto.randomUUID()});const ce=await Z("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),j(""),A.current=null,await L(ce.gift,H)}else await L(b?.gift,H)}catch(ae){H()&&m(ae)}finally{H()&&(T.current=!1,k(!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:[M?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")}),b?e.jsxs("div",{role:"status",className:"space-y-2 text-sm leading-6",children:[d&&p?null:e.jsx("p",{children:a(p?b.already_redeemed?"cloud.gift.already_redeemed":"cloud.gift.redeemed":"cloud.gift.refresh_needed")}),b.gift?d&&p?e.jsxs("div",{className:"py-1",children:[e.jsx("p",{className:"text-base font-medium text-oai-black dark:text-oai-white",children:a("cloud.gift.duration",{days:b.gift.duration_days})}),e.jsx("p",{className:"mt-1 text-sm text-oai-gray-500 dark:text-oai-gray-400",children:a("cloud.history.term",{start:G(b.gift.starts_at),end:G(b.gift.ends_at)})})]}):e.jsx("p",{className:"text-xs text-oai-gray-600 dark:text-oai-gray-300",children:a("cloud.gift.term",{days:b.gift.duration_days,start:G(b.gift.starts_at),end:G(b.gift.ends_at)})}):null,p?e.jsxs("div",{className:"flex flex-wrap justify-end gap-2 pt-3",children:[e.jsx(I,{type:"button",variant:"secondary",size:"sm",onClick:()=>{C(null),S(!1),requestAnimationFrame(()=>w.current?.focus())},children:a("cloud.gift.redeem_another")}),d?e.jsx(I,{type:"button",size:"sm",className:"min-w-20",disabled:N,onClick:()=>ee(!1),children:a("cloud.gift.done")}):null]}):e.jsx(I,{type:"button",variant:"secondary",disabled:N,onClick:()=>{te(!1)},children:a("cloud.action.refresh_membership")})]}):e.jsxs("form",{onSubmit:O=>{O.preventDefault(),te(!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${f?` ${_}-error`:""}`,"aria-invalid":!!f,onChange:O=>{se(O.target.value)!==se(x)&&(A.current=null),j(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(I,{type:"submit",variant:"secondary",disabled:N||!x.trim(),children:a(N?"cloud.gift.redeeming":"cloud.gift.confirm")})]})]}),f?e.jsx("div",{id:`${_}-error`,children:["gift_checkout_pending","gift_requires_renewal_cancel"].includes(f.code)?e.jsx("p",{role:"alert",className:"text-xs leading-5 text-oai-gray-600 dark:text-oai-gray-300",children:kt(f,"gift")}):e.jsx(z,{error:f,context:"gift"})}):null]}):null,J.length&&!b?e.jsx("ul",{"aria-label":a("cloud.gift.history_title"),className:"divide-y divide-oai-gray-200 dark:divide-oai-gray-800",children:J.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:ee,title:a(b&&p?"cloud.gift.redeemed":M?"cloud.gift.redeem_action":"cloud.gift.history_title"),triggerLabel:a(M?"cloud.gift.redeem_action":"cloud.gift.history_title"),icon:Re,preventClose:N,initialFocus:M&&!b?w:void 0,children:Q}):e.jsxs("div",{className:d?void 0:i?"contents":"mt-4",children:[e.jsxs(I,{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:()=>h(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(M?"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,v]=l.useState(null),[h,u]=l.useState(!1),[x,j]=l.useState(null),N=l.useRef(!1),k=l.useRef(0),f=l.useRef(!0),m=t?.user?.id,b=t?.getAccessToken,C=l.useCallback(async()=>{const y=++k.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 Z("devices",{auth:b,params:P?{current_machine_id:P}:{}});y===k.current&&(c(U),o(null))}catch(P){y===k.current&&o({...P,code:"billing_devices_unavailable"})}},[b,m]);l.useEffect(()=>(f.current=!0,C(),()=>{f.current=!1,k.current+=1}),[C,n]);const p=async y=>{if(!N.current){N.current=!0,u(!0),o(null),j(null);try{if(await Z("remove-device",{auth:b,body:{machine_id:y}}),!f.current)return;r?.machines?.find(P=>P.machine_id===y)?.is_current&&Se(),v(null),await C()}catch(P){f.current&&o(P)}finally{N.current=!1,u(!1)}}},S=async y=>{if(!N.current){N.current=!0,u(!0),o(null),j(null);try{if(await Z("resume-device",{auth:b,body:{machine_id:y.machine_id}}),!f.current)return;y.is_current&&Se(),j(a("cloud.devices.resumed")),await C()}catch(P){f.current&&o(P)}finally{N.current=!1,u(!1)}}},_=r?.machines||[],w=r?.machine_count??_.filter(y=>y.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(y=>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:y.name||a("cloud.devices.unnamed"),className:"col-start-2 row-start-1 min-w-0 truncate text-sm font-medium",children:y.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(y.platform)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:y.last_seen_at?a("cloud.devices.last_seen",{date:At(y.last_seen_at)}):a("cloud.devices.last_seen_unknown")}),y.is_current?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.current")})]}):null,y.status==="paused"?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{children:a("cloud.devices.paused")})]}):null]}),y.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(I,{variant:"ghost",size:"sm",className:"col-start-3 row-start-1 !min-h-10 !px-2 sm:row-span-2","aria-expanded":y.status!=="paused"?d===y.machine_id:void 0,"aria-controls":d===y.machine_id?`cloud-machine-confirm-${y.machine_id}`:void 0,onClick:()=>y.status==="paused"?S(y):v(P=>P===y.machine_id?null:y.machine_id),disabled:h||y.status==="paused"&&!T,children:[y.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}),y.status==="paused"?a("cloud.devices.resume"):a("cloud.devices.remove")]})]}),d===y.machine_id?e.jsxs("div",{id:`cloud-machine-confirm-${y.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(I,{variant:"secondary",onClick:()=>p(y.machine_id),disabled:h,children:a("cloud.devices.confirm_remove")}),e.jsx(I,{variant:"ghost",onClick:()=>v(null),disabled:h,children:a("cloud.action.keep")})]})]}):null]},y.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:""),[v,h]=l.useState(!1),[u,x]=l.useState(!1),j=l.useId(),N=l.useRef(null);l.useEffect(()=>{u&&N.current?.focus()},[u]);const k=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())),f=[...n||[],...(s||[]).filter(m=>m.retry_payment_conflict_at||!k.has(m.id.toLowerCase()))].filter((m,b,C)=>C.findIndex(p=>p.id===m.id)===b);return e.jsxs("div",{className:"mt-2 space-y-3",children:[t?.request_id&&!t.order_id?e.jsx(ie,{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,f.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:[f.map(m=>{const b=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 p=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:b||p}),e.jsx("p",{className:"col-start-2 row-start-1 text-right text-sm font-medium tabular-nums",children:C}),m.provider||b?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,b?e.jsxs(e.Fragment,{children:[m.provider?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,e.jsx("span",{children:p})]}):null]}):null,e.jsx(ie,{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(I,{variant:"ghost",size:"sm",className:"!h-10 !px-0","aria-expanded":u,"aria-controls":`${j}-panel`,onClick:()=>x(m=>!m),children:a("cloud.restore.title")}),c]}),u?e.jsxs("div",{id:`${j}-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())){h(!0);return}const b=o.trim(),C=f.some(p=>p.id.toLowerCase()===b.toLowerCase()&&p.retry_payment_conflict_at);g(C?`/billing/checkout?order=${encodeURIComponent(b)}`:_e({orderId:b,userId:i}))},children:[e.jsx("label",{htmlFor:`${j}-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:`${j}-input`,ref:N,value:o,onChange:m=>{d(m.target.value),h(!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":v,"aria-describedby":v?`${j}-error`:void 0}),e.jsx(I,{type:"submit",variant:"secondary",children:a("cloud.action.restore")})]}),v?e.jsx("p",{id:`${j}-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:v}=Fe(),[h,u]=l.useState(null),[x,j]=l.useState(null),[N,k]=l.useState(!1),[f,m]=l.useState(null),b=l.useRef(!1),C=l.useRef(!0);l.useEffect(()=>{d||u(null)},[d]),l.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]);const p=t?.membership,S=p?.status==="self_hosted"||p?.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",y=T&&w.status!=="paused",P=w?.next_billed_at,U=P&&Number.isFinite(Date.parse(P));l.useEffect(()=>{f&&t&&!T&&(m(null),j(null))},[t,f,T]);const F=S?null:p?.status==="trial"?p.trial_ends_at:p?.status==="transition"?p.transition_ends_at:p?.expires_at,K=async L=>{if(!b.current){b.current=!0,k(!0),j(null);try{await L()}catch(te){C.current&&j(te)}finally{b.current=!1,k(!1)}}},M=()=>K(async()=>{const L=await Z("portal",{auth:s.getAccessToken,body:w?{subscription_id:w.provider_subscription_id}:{}});C.current&&await va(L.url||L.portal_url)}),J=()=>K(async()=>{await Z("cancel",{auth:s.getAccessToken,body:{subscription_id:f}}),C.current&&(m(null),await r())}),Y=vs(p,F),ee=A&&!w||p?.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(ne,{size:18,className:"text-oai-gray-500 dark:text-oai-gray-400","aria-hidden":!0}),a("cloud.membership.title")]}):null,Y?e.jsx("span",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400",children:Y}):null]}),e.jsx(I,{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})})]}),p?.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:p.can_read_cloud?a("cloud.membership.read_only",{date:G(p.read_only_until)}):a("cloud.membership.expired_detail")}):null,p?e.jsx(Ct,{userId:s.user?.id,membership:p,subscriptions:t?.subscriptions,className:"mt-3"}):null,!p&&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"):y?U?a("cloud.membership.renews",{date:G(P)}):a("cloud.membership.renewal_unknown"):a("cloud.membership.renewal_off")}),T?e.jsx(I,{"aria-expanded":!!f,"aria-controls":f?"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,f?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(I,{onClick:J,variant:"secondary",disabled:N,children:a("cloud.cancel.confirm")}),e.jsx(I,{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&&h!=="billing"?e.jsx("div",{className:"mt-4",children:e.jsx(z,{error:x,context:"account"})}):null]})]}),p?e.jsx(pe,{className:"tt-cloud-theme !rounded-lg",bodyClassName:"!py-3",children:e.jsx(js,{auth:s,machineLimit:p.machine_limit,accountRevision:t,selfHosted:S})}):null,ee||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:M,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(ne,{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(ie,{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(ne,{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:h==="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(I,{onClick:M,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,p?.can_read_cloud?e.jsx(ga,{auth:s,layout:"settings-row",dialogOpen:h==="export",onDialogOpenChange:L=>u(L?"export":null)}):null,e.jsx(xs,{account:t,auth:s,refresh:r,layout:"settings-row",dialogOpen:h==="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(I,{onClick:()=>v({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:v,setMode:h,unitSystem:u,setUnitSystem:x,grouping:j,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:v,onChange:h})}),e.jsx(E,{label:a("settings.appearance.token_unit.label"),hint:a("settings.appearance.token_unit.hint"),control:e.jsx(q,{disabled:v!==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:j,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}=re(),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}=re();if(!t)return null;const r=Ke(),c=!!s?.launchAtLogin,g=s?.toastOnReset!==!1,o=s?.confettiOnReset!==!1,d=s?.launchAtLoginSupported!==!1,v=s?.autoUpdateEnabled!==!1,h=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(ie,{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:v,onChange:()=>n("autoUpdateEnabled",!v),ariaLabel:a("settings.menubar.autoUpdate")})}),e.jsx(E,{label:a("settings.menubar.updates"),hint:h||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}=re(),i=t&&s?.version,r=s?.platform||"macos",[c,g]=fe.useState(!1),[o,d]=fe.useState({open:!1,latestVersion:"",htmlUrl:""}),{resolvedLocale:v}=Ve(),h="1.3.7",u=async()=>{g(!0);try{const f=await fetch("https://api.github.com/repos/xiufengsun/TokenTracker/releases/latest");if(!f.ok)throw new Error("Failed to fetch");const m=await f.json(),b=m.tag_name;Ms(h,b)?d({open:!0,latestVersion:b,htmlUrl:m.html_url}):Oe({title:a("settings.menubar.updates.upToDate")})}catch(f){console.error("Check updates failed:",f),Oe({title:a("settings.menubar.updates.failed")})}finally{g(!1)}},x=a("settings.menubar.updates.modalTitle"),j=a("settings.menubar.updates.modalDescription",{version:o.latestVersion}),N=a("settings.menubar.updates.modalConfirm"),k=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:h})}),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:h})}),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:j,confirmLabel:N,cancelLabel:k,onConfirm:()=>{window.open(o.htmlUrl,"_blank"),d(f=>({...f,open:!1}))},onCancel:()=>d(f=>({...f,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,v]=l.useState(!1),[h,u]=l.useState(""),[x,j]=l.useState(null),[N,k]=l.useState(!1),[f,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 b=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(""),j(null),m(null)},p=async()=>{if(r.mode==="manual"){const _=Ue(r);if(Object.keys(_).length){o(_);return}}v(!0),u(""),j(null);try{await n(r),u("saved")}catch(_){u("error"),j(_)}finally{v(!1)}},S=async()=>{const _=Ue(r);if(Object.keys(_).length){o(_);return}k(!0),m(null);try{const w=await i(r);m(w)}catch(w){m({ok:!1,error:w?.message||String(w)})}finally{k(!1)}};return e.jsxs(V,{title:a("settings.section.network"),subtitle:b,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:p,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")})]}),f?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:f.ok?a("settings.network.test.ok",{status:String(f.status??"")}):a("settings.network.test.fail",{error:f.error||""})}):null]},"manual-proxy-fields"):e.jsx("div",{className:"flex justify-end py-3",children:e.jsx("button",{type:"button",onClick:p,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")}),h==="saved"?e.jsx("p",{className:"py-2 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.network.saved")}):null,h==="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-DKVGjnxf.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 v=await Ks();if(d)return;if(!v){s(!1),i(!1);return}c(v),s(!0),i(!1)}catch{d||(s(!1),i(!1))}})(),()=>{d=!0}},[]);const g=l.useCallback(async d=>{const v=await Me(),h=await fetch(ct,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...v},cache:"no-store",body:JSON.stringify({mode:d.mode,protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),u=await h.json().catch(()=>null);if(!h.ok){const j=u&&typeof u.error=="string"?u.error:`HTTP ${h.status}`;throw new Error(j)}const x=dt(u);if(x&&c(x),u&&u.ok===!1){const j=u&&typeof u.applyError=="string"&&u.applyError||u&&typeof u.error=="string"&&u.error||`HTTP ${h.status}`,N=new Error(j);throw u.unprotected===!0&&(N.unprotected=!0),N}return x||u},[]),o=l.useCallback(async d=>{const v=await Me(),h=await fetch(Bs,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...v},cache:"no-store",body:JSON.stringify({protocol:d.protocol,host:d.host,port:d.port===""?0:Number(d.port)})}),u=await h.json().catch(()=>null);if(!u||typeof u.ok!="boolean")throw new Error(u&&typeof u.error=="string"?u.error:`HTTP ${h.status}`);return u},[]);return{available:t,loading:n,config:r,save:g,testConnection:o}}const R={APPEARANCE:"appearance",NATIVE_APP:"native-app",NETWORK:"network",ACCOUNT:"account",CLOUD:"cloud",LIMITS:"limits",LABS:"labs"},$={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}=re(),c=qs(),{available:g}=c,o=i?.toastOnReset!==!1,d=i?.confettiOnReset!==!1,v=Ke()||i?.platform==="windows",[h,u]=Yt(),x=He(),j=h.get("section"),k=Object.values(R).includes(j)&&(j!==R.NATIVE_APP||n)&&(j!==R.NETWORK||g)?j:R.APPEARANCE,f=p=>{const S=new URLSearchParams(h);p===R.APPEARANCE?S.delete("section"):S.set("section",p),u(S,{replace:!0})},m=[{id:R.APPEARANCE,label:a("settings.section.appearance"),description:a("settings.section.appearance.description"),group:$.PERSONAL,Icon:$a,content:e.jsx(Ds,{})},...n?[{id:R.NATIVE_APP,label:a("settings.section.menubar"),description:a("settings.section.menubar.description"),group:$.APP,Icon:ye,content:e.jsx(Us,{})}]:[],...g?[{id:R.NETWORK,label:a("settings.section.network"),description:a("settings.section.network.description"),group:$.APP,Icon:Zt,content:e.jsx(Hs,{proxySettings:c})}]:[],{id:R.ACCOUNT,label:a("settings.section.account"),description:a("settings.section.account.description"),group:$.PERSONAL,Icon:za,content:e.jsx(us,{settings:t})},{id:R.CLOUD,label:a("settings.section.cloud"),description:a("settings.section.cloud.description"),group:$.PERSONAL,Icon:ne,content:e.jsx(Ss,{settings:t,active:k===R.CLOUD})},{id:R.LIMITS,label:a("settings.section.limits"),description:a("settings.section.limits.description"),group:$.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})}),v?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:R.LABS,label:a("settings.section.labs"),description:a("settings.section.labs.description"),group:$.DEVELOPER,Icon:Da,content:e.jsx(Gs,{})}],b=[{id:$.PERSONAL,label:a("settings.nav.group.personal")},{id:$.APP,label:a("settings.nav.group.app")},{id:$.DEVELOPER,label:a("settings.nav.group.developer")}].map(p=>({...p,sections:m.filter(S=>S.group===p.id)})).filter(p=>p.sections.length>0);let C=m[0];for(const p of m)if(p.id===k){C=p;break}return e.jsx("div",{className:B("flex flex-1 flex-col font-oai text-oai-black antialiased dark:text-oai-white",k===R.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:b.map(({id:p,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 y=k===w;return e.jsxs("button",{id:`settings-nav-${w}`,type:"button","aria-current":y?"page":void 0,"aria-controls":`settings-panel-${w}`,onClick:()=>f(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",y?"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",y?"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)})})]},p))})}),e.jsxs("div",{className:"min-w-0",children:[k!==R.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:p,label:S,content:_})=>e.jsx("section",{id:`settings-panel-${p}`,"aria-labelledby":`settings-nav-${p}`,"aria-label":S,"data-settings-panel":p,hidden:k!==p,children:_},p)),e.jsx($s,{})]})]})]})})})}export{In as SettingsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as a,a$ as ee,b1 as w,j as k,a_ as we,N as M,c3 as de,b0 as z,bR as ge,b5 as X,b7 as he,ba as _,b4 as Ae,c4 as ke,c5 as He,b2 as F,c6 as Fe,c7 as ce,b3 as ue,b9 as le,c8 as q,c9 as Le,ca as Ne,bO as Be,by as me,bz as je,bi as $,bx as Ue,bC as _e,cb as Ve,K as Ye,cc as Ge,bD as Xe,bh as Ke,J as Te,cd as $e,b6 as Q,ce as Je,bK as We,bN as ze}from"./__vite-browser-external-DKVGjnxf.js";import{i as Re,A as qe,P as Qe,n as Ze,k as et,l as tt,m as nt,o as ot,p as rt,u as st,d as it,c as at,t as ct,x as ut,y as lt}from"./composite-_t6vz49X.js";import{p as pt,c as ft}from"./store-CjkDYjXp.js";import{g as K,u as dt,c as gt,a as ht,s as mt,b as Tt}from"./safePolygon-DeLf2a7a.js";import{u as Rt,a as Pt,g as Ct}from"./usePositioner-cTX1WPQP.js";const Pe=a.createContext({hasProvider:!1,timeoutMs:0,delayRef:{current:0},initialDelayRef:{current:0},timeout:new we,currentIdRef:{current:null},currentContextRef:{current:null}});function vt(e,n){e.current=n.current}function Xt(e){const{children:n,delay:t,timeoutMs:u=0}=e,o=a.useRef(t),p=a.useRef(t),i=a.useRef(null),c=a.useRef(null),h=ee();return w(()=>{if(p.current=t,!i.current){o.current=t;return}o.current={open:K(o.current,"open"),close:K(t,"close")}},[t,i,o,p]),k.jsx(Pe.Provider,{value:a.useMemo(()=>({hasProvider:!0,delayRef:o,initialDelayRef:p,currentIdRef:i,timeoutMs:u,currentContextRef:c,timeout:h}),[u,h]),children:n})}function yt(e,n={open:!1}){const{open:t}=n,u="rootStore"in e?e.rootStore:e,o=u.useState("floatingId"),p=a.useContext(Pe),{currentIdRef:i,delayRef:c,timeoutMs:h,initialDelayRef:m,currentContextRef:l,hasProvider:T,timeout:f}=p,[g,r]=a.useState(!1),P=a.useRef(t);return w(()=>{P.current=t},[t]),w(()=>{function s(){l.current?.setIsInstantPhase(!1),i.current=null,l.current=null,c.current=m.current,f.clear()}if(i.current&&!t&&i.current===o){if(r(!1),h){const d=o;return f.start(h,()=>{u.select("open")||i.current&&i.current!==d||s()}),()=>{(P.current||i.current!==d)&&f.clear()}}s()}},[t,o,i,c,h,m,l,f,u]),w(()=>{if(!t)return;const s=l.current,d=i.current;f.clear(),l.current={onOpenChange:u.setOpen,setIsInstantPhase:r},i.current=o,c.current={open:0,close:K(m.current,"close")},d!==null&&d!==o?(r(!0),s?.setIsInstantPhase(!0),s?.onOpenChange(!1,M(de))):(r(!1),s?.setIsInstantPhase(!1))},[t,o,u,i,c,m,l,f]),w(()=>()=>{if(i.current===o){if(l.current=null,!P.current)return;i.current=null,vt(c,m),f.clear()}},[l,i,c,o,m,f]),a.useMemo(()=>({activeIdRef:i,hasProvider:T,delayRef:c,isInstantPhase:g}),[i,T,c,g])}function bt(e,n){let t=null,u=null,o=!1;return{contextElement:e||void 0,getBoundingClientRect(){const p=e?.getBoundingClientRect()||{width:0,height:0,x:0,y:0},i=n.axis==="x"||n.axis==="both",c=n.axis==="y"||n.axis==="both",h=["mouseenter","mousemove"].includes(n.dataRef.current.openEvent?.type||"")&&n.pointerType!=="touch";let m=p.width,l=p.height,T=p.x,f=p.y;return t==null&&n.x&&i&&(t=p.x-n.x),u==null&&n.y&&c&&(u=p.y-n.y),T-=t||0,f-=u||0,m=0,l=0,!o||h?(m=n.axis==="y"?p.width:0,l=n.axis==="x"?p.height:0,T=i&&n.x!=null?n.x:T,f=c&&n.y!=null?n.y:f):o&&!h&&(l=n.axis==="x"?p.height:l,m=n.axis==="y"?p.width:m),o=!0,{width:m,height:l,x:T,y:f,top:f,right:T+m,bottom:f+l,left:T}}}}function pe(e){return e!=null&&e.clientX!=null}function xt(e,n={}){const{enabled:t=!0,axis:u="both"}=n,o="rootStore"in e?e.rootStore:e,p=o.useState("open"),i=o.useState("floatingElement"),c=o.useState("domReferenceElement"),h=o.context.dataRef,m=a.useRef(!1),l=a.useRef(null),[T,f]=a.useState(),[g,r]=a.useState([]),P=z(R=>{o.set("positionReference",R)}),s=z((R,y,S)=>{m.current||h.current.openEvent&&!pe(h.current.openEvent)||o.set("positionReference",bt(S??c,{x:R,y,axis:u,dataRef:h,pointerType:T}))}),d=z(R=>{p?l.current||(s(R.clientX,R.clientY,R.currentTarget),r([])):s(R.clientX,R.clientY,R.currentTarget)}),b=Re(T)?i:p;a.useEffect(()=>{if(!t){P(c);return}if(!b)return;function R(){l.current?.(),l.current=null}const y=ge(i);function S(x){const O=he(x);_(i,O)?R():s(x.clientX,x.clientY)}return!h.current.openEvent||pe(h.current.openEvent)?l.current=X(y,"mousemove",S):P(c),R},[b,t,i,h,c,o,s,P,g]),a.useEffect(()=>()=>{o.set("positionReference",null)},[o]),a.useEffect(()=>{t&&!i&&(m.current=!1)},[t,i]),a.useEffect(()=>{!t&&p&&(m.current=!0)},[t,p]);const C=a.useMemo(()=>{function R(y){f(y.pointerType)}return{onPointerDown:R,onPointerEnter:R,onMouseMove:d,onMouseEnter:d}},[d]);return a.useMemo(()=>t?{reference:C,trigger:C}:{},[t,C])}const Z=ke&&He;function St(e,n={}){const{enabled:t=!0,delay:u}=n,o="rootStore"in e?e.rootStore:e,{events:p,dataRef:i}=o.context,c=a.useRef(!1),h=a.useRef(null),m=a.useRef(!0),l=ee();a.useEffect(()=>{const f=o.select("domReferenceElement");if(!t)return;const g=ge(f);function r(){const d=o.select("domReferenceElement");!o.select("open")&&Be(d)&&d===ce(ue(d))&&(c.current=!0,h.current=d)}function P(){m.current=!0}function s(){m.current=!1}return Ae(X(g,"blur",r),Z&&X(g,"keydown",P,!0),Z&&X(g,"pointerdown",s,!0))},[o,t]),a.useEffect(()=>{if(!t)return;function f(g){if(g.reason===me||g.reason===je){const r=o.select("domReferenceElement");F(r)&&(h.current=r,c.current=!0)}}return p.on("openchange",f),()=>{p.off("openchange",f)}},[p,t,o]);const T=a.useMemo(()=>{function f(){c.current=!1,h.current=null}return{onMouseLeave(){f()},onFocus(g){const r=g.currentTarget;if(c.current){if(h.current===r)return;f()}const P=he(g.nativeEvent);if(F(P)){if(Z&&!g.relatedTarget){if(!m.current&&!Le(P))return}else if(!Ne(P))return}const s=le(g.relatedTarget,o.context.triggerElements),{nativeEvent:d,currentTarget:b}=g,C=typeof u=="function"?u():u;if(o.select("open")&&s||C===0||C===void 0){o.setOpen(!0,M(q,d,b));return}l.start(C,()=>{c.current||o.setOpen(!0,M(q,d,b))})},onBlur(g){f();const r=g.relatedTarget,P=g.nativeEvent,s=F(r)&&r.hasAttribute(Fe("focus-guard"))&&r.getAttribute("data-type")==="outside";l.start(0,()=>{const d=o.select("domReferenceElement"),b=ce(ue(d));!r&&b===d||_(i.current.floatingContext?.refs.floating.current,b)||_(d,b)||s||le(r??b,o.context.triggerElements)||o.setOpen(!1,M(q,P))})}}},[i,u,o,l]);return a.useMemo(()=>t?{reference:T,trigger:T}:{},[t,T])}const Ce=a.createContext(void 0);function J(e){const n=a.useContext(Ce);if(n===void 0&&!e)throw new Error($(72));return n}const Et={...pt,disabled:e=>e.disabled,instantType:e=>e.instantType,isInstantPhase:e=>e.isInstantPhase,trackCursorAxis:e=>e.trackCursorAxis,disableHoverablePopup:e=>e.disableHoverablePopup,lastOpenChangeReason:e=>e.openChangeReason,closeOnClick:e=>e.closeOnClick,closeDelay:e=>e.closeDelay,adaptiveOrigin:e=>e.adaptiveOrigin};class Ot extends Ue{constructor(n,t,u){const o=new Qe;super(It(n,o,t,u),Mt(o),Et)}setOpen=(n,t)=>{qe(this,n,t,{extraState:{openChangeReason:t.reason}})};cancelPendingOpen(n){this.state.floatingRootContext.dispatchOpenChange(!1,M(me,n))}}function It(e,n,t,u=!1){return{...ft(n,t,u),disabled:!1,instantType:void 0,isInstantPhase:!1,trackCursorAxis:"none",disableHoverablePopup:!1,openChangeReason:null,closeOnClick:!0,closeDelay:0,adaptiveOrigin:void 0,...e}}function Mt(e){return{popupRef:a.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerElements:e}}const Kt=_e(function(n){const{disabled:t=!1,defaultOpen:u=!1,open:o,disableHoverablePopup:p=!1,trackCursorAxis:i="none",actionsRef:c,onOpenChange:h,onOpenChangeComplete:m,handle:l,triggerId:T,defaultTriggerId:f=null,children:g}=n,r=Ze((L,N)=>new Ot({open:u,openProp:o,activeTriggerId:f,triggerIdProp:T},L,N));r.useControlledProp("openProp",o),r.useControlledProp("triggerIdProp",T),r.useContextCallback("onOpenChange",h),r.useContextCallback("onOpenChangeComplete",m);const P=r.useState("open"),s=!t&&P,d=r.useState("activeTriggerId"),b=r.useState("mounted"),C=r.useState("payload");r.useSyncedValues({trackCursorAxis:i,disableHoverablePopup:p,disabled:t}),et(r,{closeOnActiveTriggerUnmount:!0});const{forceUnmount:R,transitionStatus:y}=tt(s,r),S=r.useState("isInstantPhase"),x=r.useState("instantType"),O=r.useState("lastOpenChangeReason"),D=a.useRef(null);w(()=>{P&&t&&r.setOpen(!1,M(Ge))},[P,t,r]),w(()=>{y==="ending"&&O===de||y!=="ending"&&S?(x!=="delay"&&(D.current=x),r.set("instantType","delay")):D.current!==null&&(r.set("instantType",D.current),D.current=null)},[y,S,O,x,r]),w(()=>{s&&d==null&&r.set("payload",void 0)},[r,d,s]),a.useImperativeHandle(c,()=>({unmount:R,close:()=>r.setOpen(!1,M(Xe))}),[R,r]);const H=s||b||!t&&i!=="none";return k.jsxs(Ce.Provider,{value:r,children:[l&&k.jsx(nt,{handle:l,store:r}),H&&k.jsx(Dt,{store:r,disabled:t,trackCursorAxis:i}),typeof g=="function"?g({payload:C}):g]})});function Dt({store:e,disabled:n,trackCursorAxis:t}){const u=e.useState("floatingRootContext"),o=ot(u,{enabled:!n,referencePress:()=>e.select("closeOnClick")}),p=xt(u,{enabled:!n&&t!=="none",axis:t==="none"?void 0:t}),i=a.useMemo(()=>Ve(p.reference,o.reference),[p.reference,o.reference]);return rt(e,{activeTriggerProps:i,inactiveTriggerProps:i,popupProps:o.floating??Ye}),null}const wt=a.createContext(void 0);function At(){return a.useContext(wt)}const kt=600,ve="data-base-ui-tooltip-trigger";function fe(e){if("composedPath"in e){const t=e.composedPath();for(let u=0;u<t.length;u+=1){const o=t[u];if(F(o))return o}}const n=e.target;return F(n)?n:null}function Ht(e){let n=e;for(;n;){const t=n.closest(`[${ve}]`);if(t)return t;const u=n.getRootNode();n="host"in u&&F(u.host)?u.host:null}return null}const $t=Ke(function(n,t){const{render:u,className:o,style:p,handle:i,payload:c,disabled:h,delay:m,closeOnClick:l=!0,closeDelay:T,id:f,...g}=n,r=J(!0),s=dt(i)??r;if(!s)throw new Error($(82));const d=st(f),b=s.useState("isTriggerActive",d),C=s.useState("isOpenedByTrigger",d),R=s.useState("floatingRootContext"),y=a.useRef(null),S=T??0,{registerTrigger:x,isMountedByThisTrigger:O}=it(d,y,s,{payload:c,closeOnClick:l,closeDelay:S}),D=At(),{activeIdRef:H,delayRef:L,isInstantPhase:N,hasProvider:E}=yt(R,{open:C}),B=gt(R);s.useSyncedValue("isInstantPhase",N);const W=s.useState("disabled"),j=h??W,te=at(j),ne=s.useState("trackCursorAxis"),xe=s.useState("disableHoverablePopup"),U=a.useRef(!1),V=ee(),Y=a.useRef(void 0);function oe(){return E&&H.current!=null?0:m??D??kt}function re(v){const I=y.current;if(!I||!v)return!1;const A=Ht(v);return A!==null&&A!==I&&_(I,A)}function Se(v){const I=re(v);return U.current=I,I&&(B.openChangeTimeout.clear(),B.restTimeout.clear(),B.restTimeoutPending=!1,V.clear()),I}const Ee=ht(R,{enabled:!j,mouseOnly:!0,move:!1,handleClose:!xe&&ne!=="both"?mt():null,restMs:oe,delay(){return T==null&&E?{close:K(L.current,"close")}:{close:S}},triggerElementRef:y,isActiveTrigger:b,isClosing:()=>s.select("transitionStatus")==="ending",shouldOpen(){return!U.current}}),Oe=St(R,{enabled:!j}).reference,Ie=v=>{const I=U.current,A=fe(v),se=Se(A),G=y.current,De=G&&A&&_(G,A);if(se&&s.select("open")&&s.select("lastOpenChangeReason")===Q){s.setOpen(!1,M(Q,v));return}if(I&&!se&&De&&!te.current&&!s.select("open")&&G&&Re(Y.current)){const ie=()=>{!U.current&&!te.current&&!s.select("open")&&s.setOpen(!0,M(Q,v,G))},ae=oe();ae===0?(V.clear(),ie()):V.start(ae,ie)}},Me=s.useState("triggerProps",O);return Te("button",n,{state:{open:C},ref:[t,x,y],props:[Ee,Oe,O||ne!=="none"?Me:void 0,{onMouseOver(v){Ie(v.nativeEvent)},onFocus(v){re(fe(v.nativeEvent))&&v.preventBaseUIHandler()},onMouseLeave(){U.current=!1,V.clear(),Y.current=void 0},onPointerEnter(v){Y.current=v.pointerType},onPointerDown(v){Y.current=v.pointerType,s.set("closeOnClick",l),l&&!s.select("open")&&s.cancelPendingOpen(v.nativeEvent)},onClick(v){l&&!s.select("open")&&s.cancelPendingOpen(v.nativeEvent)},id:d,[$e]:j?"":void 0,[ve]:j?void 0:""},g],stateAttributesMapping:ct})}),ye=a.createContext(void 0);function Ft(){const e=a.useContext(ye);if(e===void 0)throw new Error($(70));return e}const Jt=a.forwardRef(function(n,t){const{keepMounted:u=!1,...o}=n;return J().useState("mounted")||u?k.jsx(ye.Provider,{value:u,children:k.jsx(Je,{ref:t,...o})}):null}),be=a.createContext(void 0);function Lt(){const e=a.useContext(be);if(e===void 0)throw new Error($(71));return e}const Wt=a.forwardRef(function(n,t){const{render:u,className:o,anchor:p,positionMethod:i="absolute",side:c="top",align:h="center",sideOffset:m=0,alignOffset:l=0,collisionBoundary:T="clipping-ancestors",collisionPadding:f=5,arrowPadding:g=5,sticky:r=!1,disableAnchorTracking:P=!1,collisionAvoidance:s=We,style:d,...b}=n,C=J(),R=Ft(),y=C.useState("open"),S=C.useState("mounted"),x=C.useState("trackCursorAxis"),O=C.useState("disableHoverablePopup"),D=C.useState("floatingRootContext"),H=C.useState("instantType"),L=C.useState("transitionStatus"),N=C.useState("adaptiveOrigin"),E=Rt({anchor:p,positionMethod:i,floatingRootContext:D,mounted:S,side:c,sideOffset:m,align:h,alignOffset:l,collisionBoundary:T,collisionPadding:f,sticky:r,arrowPadding:g,disableAnchorTracking:P,keepMounted:R,collisionAvoidance:s,adaptiveOrigin:N}),B=a.useMemo(()=>({open:y,side:E.side,align:E.align,anchorHidden:E.anchorHidden,instant:x!=="none"?"tracking-cursor":H}),[y,E.side,E.align,E.anchorHidden,x,H]),W=Pt(n,B,{styles:E.positionerStyles,transitionStatus:L,props:b,refs:[t,C.useStateSetter("positionerElement")],hidden:!S,inert:!y||x==="both"||O});return k.jsx(be.Provider,{value:E,children:W})}),zt=a.forwardRef(function(n,t){const{render:u,className:o,style:p,...i}=n,c=J(),{side:h,align:m}=Lt(),l=c.useState("open"),T=c.useState("instantType"),f=c.useState("transitionStatus"),g=c.useState("popupProps"),r=c.useState("floatingRootContext"),P=c.useState("disabled"),s=c.useState("closeDelay");ze({open:l,ref:c.context.popupRef,onComplete(){l&&c.context.onOpenChangeComplete?.(!0)}}),Tt(r,{enabled:!P,closeDelay:s});const d=c.useStateSetter("popupElement");return Te("div",n,{state:{open:l,side:h,align:m,instant:T,transitionStatus:f},ref:[t,c.context.popupRef,d],props:[ut,g,Ct(f),i],stateAttributesMapping:lt})});export{Xt as F,wt as T,Kt as a,$t as b,Jt as c,Wt as d,zt as e};
|