@openchamber/web 1.18.0 → 1.18.1
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/dist/assets/{DiagramView-1-LZVuzn.js → DiagramView-DZmf30ko.js} +1 -1
- package/dist/assets/{FilesView-BDRX8vU2.js → FilesView-cJPeFhDe.js} +6 -6
- package/dist/assets/{MarkdownRendererImpl-fZSdR7PD.js → MarkdownRendererImpl-DZezL90a.js} +1 -1
- package/dist/assets/{OnboardingScreen-D81UrlA4.js → OnboardingScreen-ChYr0xqs.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-cSK3t3TR.js → SessionSwitcherDropdown-BV7FfPbT.js} +1 -1
- package/dist/assets/{SettingsWindow-CozowJLm.js → SettingsWindow-UybkBD1p.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CQYNvKbk.js → contextPanelEmbeddedChat-DW3atb4h.js} +1 -1
- package/dist/assets/{de-C2n4oo1Z.js → de-rVJ-hXrd.js} +3 -3
- package/dist/assets/es-D7ZyOToq.js +15 -0
- package/dist/assets/{fr-DDFUp5jS.js → fr-hl5i-ZI0.js} +2 -2
- package/dist/assets/{index-BCCcokur.css → index-CL9MYe8V.css} +1 -1
- package/dist/assets/{ja-B7SxobKm.js → ja-DqakdvOp.js} +2 -2
- package/dist/assets/{ko-CWGq93SO.js → ko-dNl8A3Xf.js} +2 -2
- package/dist/assets/main-B5TIsU2y.js +209 -0
- package/dist/assets/{main-Cts0BwVk.js → main-_m6HD9-a.js} +2 -2
- package/dist/assets/{markdownCore-BqzEkymd.js → markdownCore-DpT1vbbv.js} +2 -2
- package/dist/assets/{miniChat-ChuQD2KK.js → miniChat-wYb8p9vG.js} +2 -2
- package/dist/assets/{mobile-c-CRD1Cz.js → mobile-ExXAVUcv.js} +2 -2
- package/dist/assets/{pl-DZmyxLo7.js → pl-C5HQx1Hf.js} +3 -3
- package/dist/assets/pt-BR-CNCoBDAM.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-9uaZAJjw.js → renderElectronMiniChatApp-DPDzIT8W.js} +2 -2
- package/dist/assets/{renderMobileApp-Dm1tmU2a.js → renderMobileApp-CzWvxR9e.js} +3 -3
- package/dist/assets/runtimeEndpointReset-DKzVWH1w.js +180 -0
- package/dist/assets/uk-Bn-3AMpk.js +15 -0
- package/dist/assets/{useAppFontEffects-pyTMaGQu.js → useAppFontEffects-DdvGxoPX.js} +133 -133
- package/dist/assets/zh-CN-BCwvQpZm.js +15 -0
- package/dist/assets/zh-TW-TRHrkN9l.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/lib/openchamber-control/DOCUMENTATION.md +9 -1
- package/server/lib/openchamber-sessions/routes.js +117 -4
- package/server/lib/openchamber-sessions/routes.test.js +129 -16
- package/server/lib/opencode/DOCUMENTATION.md +2 -0
- package/server/lib/opencode/proxy.js +21 -3
- package/server/lib/small-model/DOCUMENTATION.md +11 -4
- package/server/lib/small-model/call.js +19 -3
- package/server/lib/small-model/call.test.js +9 -2
- package/server/lib/small-model/index.js +10 -1
- package/server/lib/small-model/index.test.js +20 -1
- package/server/lib/walkthrough/DOCUMENTATION.md +23 -0
- package/server/lib/walkthrough/index.js +17 -0
- package/server/lib/walkthrough/reproduce-2607.test.js +148 -0
- package/server/opencode-proxy.test.js +83 -0
- package/dist/assets/es-DP7jRKkr.js +0 -15
- package/dist/assets/main-Cqfcxvqq.js +0 -209
- package/dist/assets/pt-BR-BKR5oHQ7.js +0 -15
- package/dist/assets/runtimeEndpointReset-DL5z84w2.js +0 -180
- package/dist/assets/uk-D7oAI_Wc.js +0 -15
- package/dist/assets/zh-CN-Ddjz1_9w.js +0 -15
- package/dist/assets/zh-TW-D3X01YXj.js +0 -15
- /package/dist/assets/{index-ChZvuURI.js → index-DjZ4W8hy.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-
|
|
2
|
-
import{f as de,r as ls,j as t,R as l,c as ct,h as Yr}from"./vendor-react-BUCujlKS.js";import{u as Ve,a as Pt,b as Hn,d as sn,i as Ce,e as Ge,s as it,f as Et,r as bs,h as Jr,j as Gn,p as Qr,k as dt,l as Xr,m as nn,n as rn,o as Zr,q as on,t as eo,v as to}from"./index-ChZvuURI.js";import{u as gs,a as so,b as Oe,c as Kn,d as qn,r as xs,e as no,f as ue,t as le,o as ro,I as se,B as ge,O as Je,g as te,h as oo,i as ze,j as io,p as an,k as ln,l as ys,m as ao,n as lo,P as co,q as uo,s as fo,v as ve,w as mo,x as Yn,y as Jn,z as po,A as vs,C as ho,D as Qn,E as bo,F as go,M as xo,G as Xn,H as Zn,J as er,K as tr,L as ws,N as yo,Q as vo,R as js,S as wo,T as jo,U as cn,V as ks,W as sr,X as nr,Y as Ss,Z as ko,_ as So,$ as No,a0 as Ue,a1 as Eo,a2 as Co,a3 as Ro,a4 as Po,a5 as To,a6 as Io,a7 as _o,a8 as Be,a9 as Ao,aa as Do,ab as dn,ac as Mo,ad as Lo,ae as zo,af as Oo,ag as Bo,ah as $o,ai as Fo,aj as Wo,ak as Uo,al as Vo,am as Ho,an as Go,ao as Ko,ap as qo,aq as Yo,ar as Jo,as as Qo,at as Xo,au as Zo,av as ei,aw as ti,ax as si,ay as ni,az as ri,aA as oi,aB as ii,aC as ai,aD as li,aE as ci,aF as di,aG as ui,aH as fi}from"./useAppFontEffects-pyTMaGQu.js";import{u as at,a as Ye,b as mi,Q as pi,g as hi,D as bi,N as gi,S as xi,C as yi,c as vi,P as wi,M as ji,d as ki,T as Si,e as Ni,f as Ei,h as Bt,i as Ci,r as Ri,j as Pi,k as Ti,l as Ii,O as _i,m as Ai,n as Di,o as Mi,p as Li,A as zi,q as Oi}from"./runtimeEndpointReset-DL5z84w2.js";import{_ as $e}from"./vendor-vite-runtime-DD1OZmLC.js";import{p as Bi}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as $i}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as cs,s as rr,M as Ns,a as Ut,J as ds,p as Fi,_ as un,b as or,P as ir,d as Wi,f as Es,V as Ui,K as fn,c as Vi,Q as Hi,r as Gi,U as Ki,Z as qi}from"./vendor-remixicon-react-Dil0zKKT.js";import{f as Cs,h as ut,i as Rs,P as Ps,D as Ts,j as Is}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as _s,S as As,v as Ds,u as Ms}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Ls}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as zs,p as ar}from"./vendor-zustand-BAGL70zf.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BuzaMvKv.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CQYNvKbk.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-pierre-diffs-B1TeaSIY.js";import"./vendor-lru_map-Tstukz9J.js";import"./vendor-pierre-theming-D_y07OK2.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-diff-C3JhlQdm.js";import"./vendor-shiki-DuWDB27E.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-CTJVwiVf.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-B3NPxZ-7.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CWhyzlcb.js";import"./vendor-codemirror-lang-json-Bty2AtQK.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-D_jk9hVN.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-Dxy5thAH.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-dH8tblNV.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-o9e2Fm3f.js";import"./vendor-codemirror-lang-python-PETDP1TX.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-legacy-modes-DBXLFsoH.js";import"./vendor-codemirror-commands-eyb3xW_0.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-yaml-3778uTud.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-D0xSkRWg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-ghostty-web-CfpAcbEe.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";let lr=null,mn=!1;const Yi=new Promise(s=>{lr=s});function Ji(){mn||(mn=!0,lr?.())}const Qi=6,Xi=s=>s.parentID??null,pn=s=>{const e=s.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},Zi=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),ea=(s,e)=>{if(!s)return"";let n=null,o=-1;for(const r of e){const i=Zi(r.path);(s===i||s.startsWith(`${i}/`))&&i.length>o&&(n=r,o=i.length)}return n?n.label?.trim()||pn(n.path):pn(s)},ta=()=>{const s=gs.getState().activeSessions,e=so.getState().index.session.unseenCount,n=Ve.getState().notifyOnSubtasks,o=Oe.getState().projects,r=Kn.getState().ids,i=qn.getState().rankById;let a=0;const c=[];for(const u of s){const f=Xi(u)!==null,b=(e[u.id]??0)>0&&(!f||n);b&&(a+=1),f||c.push({session:u,unread:b,project:ea(xs(u),o)})}c.sort((u,f)=>no(u.session,f.session,r,i));const d=c.slice(0,Qi).map(({session:u,unread:f,project:p})=>({id:u.id,title:u.title??"",unread:f,project:p}));return{runtimeKey:Pt(),attentionCount:a,recentSessions:d}},sa="__OPENCHAMBER_WIDGET_SNAPSHOT__",na=()=>{typeof window>"u"||(window[sa]=()=>{try{return JSON.stringify(ta())}catch{return null}})},es="mobile-app-update-available",hn="mobile-app-update-toast-dismissed-version",ra=()=>{const s=de.c(8),{t:e}=ue(),n=at(oa),o=at(ia),r=at(aa),i=at(la);let a;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,s[0]=a):a=s[0];const c=ls.useRef(a);let d,u;return s[1]!==n||s[2]!==i||s[3]!==o||s[4]!==e||s[5]!==r?(d=()=>{if(Hn()!=="android"||o!=="mobile"||!n||!r||!i){le.dismiss(es);return}sn().getItem(hn)!==r&&(c.current.has(r)||(c.current.add(r),le.info(e("mobileUpdate.toast.available.title"),{id:es,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(se,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{ro(i)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{sn().setItem(hn,r),le.dismiss(es)}}})))},u=[n,i,o,e,r],s[1]=n,s[2]=i,s[3]=o,s[4]=e,s[5]=r,s[6]=d,s[7]=u):(d=s[6],u=s[7]),ls.useEffect(d,u),null};function oa(s){return s.available}function ia(s){return s.runtimeType}function aa(s){return s.info?.version}function la(s){return s.info?.downloadUrl}const Vt="openchamber.mobile.connections.v1",ca="openchamber.mobile.",bn="openchamber.mobile.deviceId",da=()=>{try{const s=window.localStorage.getItem(bn);if(s&&s.trim())return s.trim();const e=crypto.randomUUID();return window.localStorage.setItem(bn,e),e}catch{return crypto.randomUUID()}},gn=()=>`mobile:${da()}`,xn=()=>{try{const s=$i.getPlatform();return s==="ios"||s==="android"?s:void 0}catch{return}},cr=12,ua=8e3,fa=2500,ma=3e3,Ht=2500,pa=()=>{let s=0;return{begin:()=>(s+=1,s),cancel:()=>{s+=1},isCurrent:e=>e===s}},pt=s=>{const e=s.trim();if(!e)return"";const n=/^https?:\/\//i.test(e)?e:`http://${e}`,o=new URL(n);return o.hash="",o.search="",o.pathname=o.pathname.replace(/\/+$/,""),o.toString().replace(/\/+$/,"")},$t=s=>{try{return new URL(s).host}catch{return s}},ft=s=>{try{return pt(s)}catch{return s.trim().replace(/\/+$/g,"")}},dr=(s,e)=>ft(s)===ft(e),ur=s=>`relay:${s.serverId}@${s.relayUrl.trim()}`,ha=s=>`relay://${s.serverId}`,Yt=s=>s.candidates.filter(e=>e.kind==="direct"),Ze=s=>{const e=s.candidates.find(n=>n.kind==="relay");return e&&e.kind==="relay"?e.relay:null},He=s=>{const e=Yt(s)[0];if(e)return e.url;const n=Ze(s);return n?ha(n):""},Ee=s=>{const e=Ze(s);if(e)return ur(e);const n=Yt(s)[0];return n?ft(n.url):""},Gt=(s,e)=>{const n=s.find(i=>i.kind==="relay"),o=n&&n.kind==="relay"?n.relay.serverId:null,r=new Set(s.filter(i=>i.kind==="direct").map(i=>ft(i.url)));return e.some(i=>i.kind==="relay"?o!==null&&i.relay.serverId===o:r.has(ft(i.url)))},Os=s=>{const e=(()=>{try{return pt(s)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},yn=s=>{if(s.candidates&&s.candidates.length>0)return s.candidates;const e=[];return typeof s.url=="string"&&s.url.trim()&&!/^relay:\/\//i.test(s.url.trim())&&e.push(...Os(s.url)),s.relay&&e.push({kind:"relay",relay:s.relay}),e},Bs=s=>{if(!s||typeof s!="object"||Array.isArray(s))return null;const e=s;if(typeof e.relayUrl!="string"||!e.relayUrl.trim()||typeof e.serverId!="string"||!e.serverId.trim())return null;const n=e.hostEncPubJwk;if(!n||typeof n!="object"||Array.isArray(n))return null;const o=n;return o.kty!=="EC"||o.crv!=="P-256"||typeof o.x!="string"||!o.x||typeof o.y!="string"||!o.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:o.x,y:o.y}}},Jt=s=>{try{return JSON.stringify(s)}catch{return String(s)}},Pe=(s,e={})=>{console.info("[mobile-connect]",s,Jt(e))},mt=(s,e={})=>{console.info("[mobile-storage]",s,Jt(e))},ba=s=>{if(typeof s!="string")return s;try{return JSON.parse(s)}catch{return s}},ga=s=>{if(typeof s!="string")return s??void 0;try{return JSON.parse(s)}catch{return s}},xa=async(s,e)=>{if(!Ce())return null;try{const{CapacitorHttp:n}=await $e(async()=>{const{CapacitorHttp:i}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:i}},[]),o=Object.fromEntries(new Headers(e?.headers).entries()),r=await n.request({url:s,method:e?.method||"GET",headers:o,data:ga(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>ba(r.data)}}catch(n){return console.warn("[mobile-connect]","native-http failed",Jt({url:s,error:n instanceof Error?n.message:String(n)})),null}},ya=async(s,e)=>{const n=await fetch(s,e).catch(o=>(console.warn("[mobile-connect]","browser-fetch failed",Jt({url:s,error:o instanceof Error?o.message:String(o)})),null));return n?{ok:n.ok,status:n.status,source:"browser-fetch",json:()=>n.json()}:null},qe=async(s,e,n)=>{let o;const r=new Promise(i=>{o=window.setTimeout(()=>{n?.(),i(null)},s)});try{return await Promise.race([e,r])}catch{return null}finally{o!==void 0&&window.clearTimeout(o)}},et=async(s,e,n)=>{const o=n?.totalTimeoutMs??ua,r=Date.now(),i=await qe(Math.min(fa,o),xa(s,e));if(i)return i;const a=new AbortController,c=Math.max(500,o-(Date.now()-r));return qe(c,ya(s,{...e,signal:a.signal}),()=>a.abort())},Qt=async s=>{if(!s)return null;const e=await s.json().catch(()=>null);if(!e||typeof e!="object")return null;const n=e;return{authenticated:typeof n.authenticated=="boolean"?n.authenticated:void 0,disabled:typeof n.disabled=="boolean"?n.disabled:void 0,scope:typeof n.scope=="string"?n.scope:void 0}},Ct=15e3,va=async(s,e,n,o=Ct,r)=>{const i=Gn({relayUrl:s.relayUrl,serverId:s.serverId,hostEncPubJwk:s.hostEncPubJwk}),a=c=>c==="ok"&&r?.keepTunnel?{outcome:c,tunnel:i}:(i.close(),{outcome:c});try{const c=e?{Authorization:`Bearer ${e}`}:void 0,d=await qe(o,i.fetch("/auth/session",{headers:c}).catch(()=>null));if(Pe("relay:session",{ok:d?.ok===!0,status:d?.status??null,hasToken:!!e}),!d)return a("unreachable");if(d.status===401)return a(e?"auth-failed":"needs-login");if(!d.ok&&d.status!==404)return a("auth-failed");const u=await Qt(d);return u&&u.disabled!==!0&&u.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(c){throw i.close(),c}},wa=(s,e,n,o,r)=>{const i=typeof window<"u"?window.location.origin:"",a={relayUrl:s.relayUrl,serverId:s.serverId,hostEncPubJwk:s.hostEncPubJwk,...n?{grant:n}:{}};r&&Jr(a,r),it({apiBaseUrl:i,clientToken:e,runtimeKey:o??ur(s),relay:a})},ja=s=>{if(!s||typeof s!="object")return null;const e=s;if(e.kind==="direct")return typeof e.url=="string"&&e.url.trim()?{kind:"direct",url:e.url}:null;if(e.kind==="relay"){const n=Bs(e.relay);return n?{kind:"relay",relay:n}:null}return null},ka=s=>{if(s.mode==="relay"){const e=Bs(s.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof s.url=="string"?Os(s.url):[]},st=()=>{if(typeof window>"u")return[];let s;try{s=JSON.parse(window.localStorage.getItem(Vt)||"[]")}catch{return[]}if(!Array.isArray(s))return[];const e=Ce();return s.flatMap(n=>{if(!n||typeof n!="object")return[];const o=n;if(typeof o.id!="string")return[];const r=Array.isArray(o.candidates)?o.candidates.map(ja).filter(d=>!!d):ka(o);if(r.length===0)return[];const i=typeof o.clientToken=="string"&&o.clientToken.trim()?o.clientToken:void 0,a=typeof o.label=="string"&&o.label.trim()?o.label:$t(He({candidates:r})),c={id:o.id,label:a,candidates:r,lastUsedAt:typeof o.lastUsedAt=="number"?o.lastUsedAt:0};return e?[{...c,hasToken:!!o.hasToken||!!i}]:[{...c,clientToken:i,hasToken:!!i}]}).sort((n,o)=>o.lastUsedAt-n.lastUsedAt)},us=s=>s.kind==="relay"?{kind:"relay",relay:{relayUrl:s.relay.relayUrl,serverId:s.relay.serverId,hostEncPubJwk:s.relay.hostEncPubJwk}}:{kind:"direct",url:s.url},$s=s=>{if(typeof window>"u")return;const e=Ce(),n=s.slice(0,cr).map(o=>{const r={id:o.id,label:o.label,candidates:o.candidates.map(us),lastUsedAt:o.lastUsedAt};return e?{...r,hasToken:!!(o.hasToken||o.clientToken)}:{...r,clientToken:o.clientToken}});try{window.localStorage.setItem(Vt,JSON.stringify(n))}catch(o){console.warn("[mobile-storage] failed to persist connection metadata",o)}},fr=(s,e)=>{const n=s.find(i=>e.id&&i.id===e.id||Gt(i.candidates,e.candidates)),o=Ce(),r={id:e.id||n?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...o?{hasToken:e.hasToken??(!!e.clientToken||n?.hasToken||!1)}:{clientToken:e.clientToken??n?.clientToken,hasToken:!!(e.clientToken??n?.clientToken)}};return[r,...s.filter(i=>i.id!==r.id&&!Gt(i.candidates,e.candidates))].slice(0,cr)},Fs=Bi,Sa=0,Ws=s=>`${ca}token.${encodeURIComponent(s)}`,Na=async(s,e)=>{let n;const o=new Promise(r=>{n=window.setTimeout(()=>r(e),ma)});try{return await Promise.race([s.catch(()=>e),o])}finally{n!==void 0&&window.clearTimeout(n)}},Us=async(s,e,n)=>Ce()?Na(e().catch(o=>(console.warn(`[mobile-storage] ${s} failed`,o),n)),n):n,Rt=async s=>{mt("secure:read-start",{key:s});const e=await Us("secure:read",async()=>(await Fs.internalGetItem({prefixedKey:Ws(s),sync:!1})).data,null),n=typeof e=="string"&&e.trim()?e:void 0;return mt("secure:read",{key:s,hasToken:!!n}),n},Qe=async(s,e)=>{mt("secure:write-start",{key:s});const n=await Us("secure:write",async()=>(await Fs.internalSetItem({prefixedKey:Ws(s),data:e,sync:!1,access:Sa}),!0),!1);return mt("secure:write",{key:s,ok:n}),n},Ea=async s=>{await Us("secure:delete",async()=>(await Fs.internalRemoveItem({prefixedKey:Ws(s),sync:!1}),!0),!1)},Ca=async(s,e)=>{let n=0,o=0;return{records:await Promise.all(s.map(async i=>{if(!i||typeof i!="object")return i;const a=i,c=typeof a.url=="string"?a.url:null,d=typeof a.clientToken=="string"?a.clientToken.trim():"";if(!c||!d)return i;if(!await e(c,d))return o+=1,i;n+=1;const{clientToken:u,...f}=a;return{...f,hasToken:!0}})),migrated:n,failed:o}},mr=async()=>{if(typeof window>"u"||!Ce())return;let s;try{s=JSON.parse(window.localStorage.getItem(Vt)||"[]")}catch{return}if(!Array.isArray(s))return;const e=s.filter(o=>!!o&&typeof o=="object"&&typeof o.url=="string"&&typeof o.clientToken=="string"&&!!o.clientToken.trim());if(e.length===0)return;mt("secure:migrate-start",{count:e.length});const n=await Ca(s,async(o,r)=>{const i=ft(o);return await Qe(i,r)?await Rt(i)===r:!1});if(n.migrated>0)try{window.localStorage.setItem(Vt,JSON.stringify(n.records))}catch(o){console.warn("[mobile-storage] failed to finalize secure token migration",o);return}mt("secure:migrate-done",{migrated:n.migrated,failed:n.failed})},Ra=async()=>(await mr(),st()),Kt=async s=>{const e=fr(st(),s);return $s(e),Ce()&&s.clientToken&&await Qe(Ee({candidates:s.candidates}),s.clientToken),e},Pa=async s=>{const e=st(),n=e.find(r=>r.id===s)??null,o=e.filter(r=>r.id!==s);return $s(o),n&&Ce()&&await Ea(Ee(n)),o},Ta=1500,qt=async(s,e,n)=>{const o=n?.fast?{totalTimeoutMs:Ht}:void 0,r=Ze({candidates:s})?.serverId??null,i=s.find(u=>u.kind==="relay")??null,a=s.filter(u=>u.kind==="direct"),c=async()=>{for(const u of a){const f=pt(u.url)||u.url,p=e?{Authorization:`Bearer ${e}`}:void 0,b=await et(`${f}/health`,{method:"GET"},o);if(!b?.ok)continue;if(r){const g=await b.json().catch(()=>null),I=g&&typeof g=="object"?g.serverId:null;if(typeof I=="string"&&I&&I!==r){Pe("probe:server-id-mismatch",{url:f});continue}}const x=await et(`${f}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},o);if(x?.status===401)return{status:"needs-login"};if(!x||!x.ok&&x.status!==404)continue;const v=await Qt(x);if(v&&v.disabled!==!0&&v.authenticated===!1)return{status:"needs-login"};const S=v?.disabled===!0;return!e&&Ce()&&!S&&v?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:f}}}return{status:"unreachable"}},d=async()=>{if(!i)return{status:"unreachable"};const{outcome:u,tunnel:f}=await va(i.relay,e,void 0,n?.fast?Ht:void 0,{keepTunnel:!0});return u==="ok"?{status:"ok",transport:{kind:"relay",relay:i.relay,tunnel:f}}:u==="needs-login"||u==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return i?a.length===0?d():new Promise(u=>{let f=!1,p=!1,b,x=null,v=null;const S=P=>{P?.status==="ok"&&P.transport.kind==="relay"&&P.transport.tunnel?.close()},g=P=>{f||(f=!0,u(P))},I=()=>{p||f||(b!==void 0&&(window.clearTimeout(b),b=void 0),d().then(P=>{if(v=P,f||p){S(P);return}if(P.status==="ok"||P.status==="needs-login"){g(P);return}x&&g(x)}))};c().then(P=>{if(x=P,!f){if(P.status==="ok"||P.status==="needs-login"){p=!0,b!==void 0&&window.clearTimeout(b),S(v),g(P);return}if(v){g(v);return}I()}}),b=window.setTimeout(I,Ta)}):c()},Xe=(s,e,n)=>{s.kind==="relay"?wa(s.relay,e,n?.grant,n?.runtimeKey,s.tunnel):it({apiBaseUrl:s.url,clientToken:e,runtimeKey:n?.runtimeKey}),hr()},yt=()=>{const s=st()[0];return s?.label?.trim()?s.label:null},ts=async()=>{await mr();const s=st()[0];if(!s)return{status:"no-candidate"};let e;if(Ce()){if(!s.hasToken)return{status:"no-candidate"};if(e=await Rt(Ee(s)),!e)return{status:"no-candidate"}}else if(e=s.clientToken,!e)return{status:"no-candidate"};const n=await qt(s.candidates,e,{fast:!0});return n.status==="needs-login"?{status:"needs-login",label:s.label}:n.status!=="ok"?{status:"unreachable",label:s.label}:(await Kt({id:s.id,label:s.label,candidates:s.candidates}),Xe(n.transport,e,{runtimeKey:Ee(s)}),{status:"connected"})},Ia=async(s,e)=>{let n="";try{n=pt(s.url)}catch{return!1}if(!n)return!1;const o=s.clientToken?.trim()||void 0,r=o?{Authorization:`Bearer ${o}`}:void 0,i={totalTimeoutMs:Ht};if(!(await et(`${n}/health`,{method:"GET",headers:r},i))?.ok)return!1;const c=await et(`${n}/auth/session`,{method:"GET",credentials:o?"omit":"include",headers:r},i);if(!c||!c.ok&&c.status!==404)return!1;const d=await Qt(c);return!(d&&d.disabled!==!0&&d.authenticated===!1)},_a=s=>[...s].sort((e,n)=>{const o=(e.priority??100)-(n.priority??100);if(o!==0)return o;const r=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return r(e)-r(n)}).flatMap(e=>{if(e.type==="relay"){const n=Bs({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return n?[{kind:"relay",relay:n}]:[]}return Os(e.url)}),vn=async s=>{const e=Ze({candidates:s})?.serverId??null;for(const n of s){if(n.kind==="relay"){const i=Gn(n.relay),a=await qe(Ct,i.fetch("/health").catch(()=>null));if(Pe("establish:relay:health",{ok:a?.ok===!0,status:a?.status??null}),a?.ok)return{kind:"relay",relay:n.relay,tunnel:i};i.close();continue}const o=pt(n.url)||n.url,r=await et(`${o}/health`,{method:"GET"});if(Pe("establish:direct:health",{ok:r?.ok===!0,status:r?.status??null}),!!r?.ok){if(e){const i=await r.json().catch(()=>null),a=i&&typeof i=="object"?i.serverId:null;if(typeof a=="string"&&a&&a!==e){Pe("establish:server-id-mismatch",{url:o});continue}}return{kind:"direct",url:o}}}return null},Aa=async(s,e)=>{if(!Et())return Ia(s);const n=await qe(Ht,bs("/auth/session").then(r=>r).catch(()=>null));if(!n)return!0;if(n.status===401)return!1;if(!n.ok&&n.status!==404)return!0;const o=await Qt(n);return!(o&&o.disabled!==!0&&o.authenticated===!1)},Da=s=>s.kind==="relay"?Et():!Et()&&dr(s.url,Ge()),pr=()=>{const s=Pt();return s?st().find(e=>Ee(e)===s)??null:null},wn=s=>{const e=Pt();return!!e&&Ee(s)===e},Ft=async()=>{const s=pr();if(!s)return"no-connection";let e;if(Ce()?e=s.hasToken?await Rt(Ee(s)):void 0:e=s.clientToken,!e)return"unreachable";const n=s.candidates.findIndex(c=>Da(c.kind==="relay"?{kind:"relay",relay:c.relay}:{kind:"direct",url:c.url})),o=n>=0?s.candidates.slice(0,n):s.candidates,r=await qt(o,e,{fast:!0});if(r.status==="ok")return await Kt({id:s.id,label:s.label,candidates:s.candidates}),Xe(r.transport,e,{runtimeKey:Ee(s)}),"switched";if(r.status==="needs-login")return"needs-login";if(n>=0&&await Aa({url:Ge(),clientToken:e}))return hr(),"unchanged";const i=n>=0?s.candidates.slice(n+1):[],a=await qt(i,e,{fast:!0});return a.status==="ok"?(await Kt({id:s.id,label:s.label,candidates:s.candidates}),Xe(a.transport,e,{runtimeKey:Ee(s)}),"switched"):a.status==="needs-login"?"needs-login":"unreachable"},Ma=5e3;let ss=!1;const La=async()=>{if(ss)return"skipped";const s=pr();if(!s)return Pe("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=Ze(s);if(!e)return Pe("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";ss=!0;try{const n=await qe(Ct,bs("/api/client-auth/connection/candidates").then(u=>u).catch(()=>null));if(!n?.ok)return Pe("candidates:refresh-skip",{reason:"fetch-failed",status:n?.status??null}),"skipped";const o=await n.json().catch(()=>null);if(!o||o.serverId!==e.serverId)return Pe("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const r=Array.isArray(o.candidates)?o.candidates:[],i=[];for(const u of r){if(!u||typeof u!="object")continue;const f=u;if(!(f.type!=="lan"||typeof f.url!="string"))try{const p=pt(f.url);p&&!i.includes(p)&&i.push(p)}catch{}}if(i.length===0)return Pe("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const a=Yt(s).filter(u=>u.url.startsWith("https://")),c=[...i.map(u=>({kind:"direct",url:u})),...a,{kind:"relay",relay:e}];return JSON.stringify(s.candidates.map(us))===JSON.stringify(c.map(us))?"unchanged":(Pe("candidates:refreshed",{lanCount:i.length}),await Kt({id:s.id,label:s.label,candidates:c}),"updated")}finally{ss=!1}},hr=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const s=await La().catch(()=>"skipped");Pe("candidates:refresh-result",{result:s}),s==="updated"&&Et()&&await Ft().catch(()=>null)})()},Ma)},br=s=>{const{t:e}=ue(),[n,o]=l.useState(()=>st()),[r,i]=l.useState(null),[a,c]=l.useState(null),[d,u]=l.useState(null),f=l.useRef(n),p=l.useRef(null),b=l.useRef(pa()),x=l.useCallback(w=>{f.current=w,o(w)},[]),v=l.useCallback(w=>{p.current=w,i(w)},[]),S=l.useCallback(w=>{p.current===w&&(p.current=null,i(null))},[]);l.useEffect(()=>{let w=!1;return Ra().then(C=>{w||x(C)}),()=>{w=!0}},[x]);const g=l.useCallback(w=>{const C=fr(f.current,w);return x(C),$s(C),C},[x]),I=l.useCallback(async w=>{c(null),v("connect");try{const C=yn(w);if(C.length===0){c(e("mobile.connect.error.urlRequired"));return}const y=w.id?f.current.find(z=>z.id===w.id):f.current.find(z=>Gt(z.candidates,C)),k=w.label?.trim()||y?.label||$t(He({candidates:C})),A=w.relayGrant;let R=w.clientToken?.trim()||void 0;const j=!!R;R||(Ce()?y?.hasToken&&(R=await Rt(Ee({candidates:C}))):R=y?.clientToken),Pe("connect:start",{candidates:C.map(z=>z.kind),hasToken:!!R});const V=await qt(C,R);if(Pe("connect:probe",{status:V.status}),V.status==="unreachable"){c(e("mobile.connect.error.unreachable"));return}if(V.status==="needs-login"){g({id:y?.id,label:k,candidates:C}),u({id:y?.id??crypto.randomUUID(),label:k,candidates:C,relay:Ze({candidates:C})??void 0,relayGrant:A});return}R&&j&&Ce()&&await Qe(Ee({candidates:C}),R),g({id:y?.id,label:k,candidates:C,clientToken:R}),Xe(V.transport,R??null,{runtimeKey:Ee({candidates:C}),grant:A}),s()}catch(C){console.warn("[mobile-connect] connect threw",C),c(e("mobile.connect.error.invalidUrl"))}finally{S("connect")}},[v,S,s,g,e]),P=l.useCallback(async w=>{if(p.current==="pairing")return;c(null),v("pairing");const C=_a(w.candidates);let y=null,k=!1;try{if(y=await vn(C),!y){c(e("mobile.connect.error.unreachable"));return}const A=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:xn(),dedupeKey:gn()}),R={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:A},j=y.kind==="relay"?await qe(Ct,y.tunnel.fetch("/api/client-auth/pairing/redeem",R).catch(()=>null)):await et(`${y.url}/api/client-auth/pairing/redeem`,R);if(!j?.ok){c(e("mobile.connect.error.authRequired"));return}const V=await j.json().catch(()=>null),z=typeof V?.clientToken=="string"?V.clientToken.trim():"";if(!z){c(e("mobile.connect.error.authRequired"));return}const h=typeof V?.server?.label=="string"?V.server.label:"",L=w.label||h||$t(He({candidates:C}));if(Ce()&&!await Qe(Ee({candidates:C}),z)){c(e("mobile.connect.error.authRequired"));return}g({label:L,candidates:C,clientToken:z}),Xe(y.kind==="relay"?{kind:"relay",relay:y.relay,tunnel:y.tunnel}:{kind:"direct",url:y.url},z,{runtimeKey:Ee({candidates:C})}),k=y.kind==="relay",s()}catch(A){console.warn("[mobile-connect] pairing threw",A),c(e("mobile.connect.error.authRequired"))}finally{!k&&y?.kind==="relay"&&y.tunnel.close(),S("pairing")}},[v,S,s,g,e]),T=l.useCallback(async w=>{if(!d||!w.trim()||p.current==="password")return;c(null),v("password");const C=b.current.begin(),y=()=>b.current.isCurrent(C),{id:k,label:A,candidates:R}=d;let j=null,V=!1;try{if(j=await vn(R),!y())return;if(!j){c(e("mobile.connect.error.unreachable"));return}const z={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:w,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:xn(),dedupeKey:gn()})};Pe("password:start",{transport:j.kind});const h=j.kind==="relay"?await qe(Ct,j.tunnel.fetch("/auth/session",z).catch(()=>null)):await et(`${j.url}/auth/session`,z);if(!y())return;if(Pe("password:done",{ok:h?.ok===!0,status:h?.status??null}),!h?.ok){c(e("mobile.connect.error.passwordFailed"));return}const L=await h.json().catch(()=>null);if(!y())return;const M=typeof L?.clientToken=="string"?L.clientToken.trim():"";if(Pe("password:token",{issued:!!M}),!M){if(j.kind==="direct"&&!Ce()){g({id:k,label:A,candidates:R}),u(null),Xe({kind:"direct",url:j.url},null,{runtimeKey:Ee({candidates:R})}),s();return}c(e("mobile.connect.error.authRequired"));return}if(Ce()&&(!y()||(await Qe(Ee({candidates:R}),M),!y()))||!y()||(g({id:k,label:A,candidates:R,clientToken:M}),u(null),Xe(j.kind==="relay"?{kind:"relay",relay:j.relay,tunnel:j.tunnel}:{kind:"direct",url:j.url},M,{runtimeKey:Ee({candidates:R})}),V=j.kind==="relay",!y()))return;s()}catch(z){if(!y())return;console.warn("[mobile-connect] password threw",z),c(e("mobile.connect.error.passwordFailed"))}finally{!V&&j?.kind==="relay"&&j.tunnel.close(),y()&&S("password")}},[v,S,s,d,g,e]),N=l.useCallback(()=>{b.current.cancel(),S("password"),u(null),c(null)},[S]),E=l.useCallback(async w=>{c(null);let C=yn(w);const y=w.id?f.current.find(j=>j.id===w.id)??null:null;if(y){const j=C.filter(h=>h.kind==="direct"),V=Yt(y).filter(h=>h.url.startsWith("https://")&&!j.some(L=>dr(L.url,h.url))),z=Ze(y);C=[...j,...V,...z?[{kind:"relay",relay:z}]:[]]}if(C.length===0)return c(e("mobile.connect.error.urlRequired")),null;const k=w.clientToken?.trim()||void 0,A=w.label?.trim()||$t(He({candidates:C}));if(Ce()){const j=Ee({candidates:C});if(k)await Qe(j,k);else if(y?.hasToken){const V=Ee(y);if(V&&j&&V!==j){const z=await Rt(V);z&&await Qe(j,z)}}}return g({id:w.id,label:A,candidates:C,clientToken:k}).find(j=>Gt(j.candidates,C))??null},[g,e]),D=l.useCallback(async w=>{const C=f.current.find(k=>k.id===w)??null,y=await Pa(w);return x(y),C},[x]);return{connections:n,isBusy:r!==null,isPasswordBusy:r==="password",error:a,pendingConnection:d,connect:I,redeemPairingConnection:P,submitPassword:T,cancelPassword:N,saveConnection:E,removeConnection:D,setError:c}},gr=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},za=()=>window.Capacitor?.getPlatform?.()==="android",xr=s=>{const e=s.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const n=Qr(e);return n?{pairing:n}:null}return/^https?:\/\//i.test(e)?{url:e}:null},yr=s=>{const e=xr(s);return e?"pairing"in e?{status:"pairing",...e}:{status:"ok",...e}:{status:"invalid"}},Oa=async(s,e)=>{if(!s.startScan||!s.stopScan||!s.addListener)return{status:"unsupported"};if(e?.aborted)return{status:"cancelled"};let n,o,r=!1,i=()=>{};const a=new Promise(u=>{i=u}),c=u=>{r||(r=!0,i(u))},d=()=>c({status:"cancelled"});e?.addEventListener("abort",d,{once:!0});try{return(await Promise.allSettled([Promise.resolve(s.addListener("barcodesScanned",({barcodes:f})=>{const p=f?.[0],b=(p?.rawValue??p?.displayValue??"").trim();b&&c(yr(b))})).then(f=>{n=f}),Promise.resolve(s.addListener("scanError",()=>c({status:"failed"}))).then(f=>{o=f})])).some(({status:f})=>f==="rejected")?c({status:"failed"}):r||s.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await a}finally{e?.removeEventListener("abort",d),await Promise.allSettled([Promise.resolve(n?.remove()),Promise.resolve(o?.remove()),s.stopScan()])}},fs=()=>gr()!==null,vr=async s=>{const e=gr();if(!e)return{status:"unsupported"};try{if(e.requestPermissions){const a=(await e.requestPermissions())?.camera;if(a&&a!=="granted"&&a!=="limited")return{status:"permission-denied"}}if(s?.signal?.aborted)return{status:"cancelled"};if(za())return Oa(e,s?.signal);if(!e.scan)return{status:"unsupported"};const o=(await e.scan({formats:["QR_CODE"]}))?.barcodes?.[0],r=(o?.rawValue??o?.displayValue??"").trim();return r?yr(r):{status:"cancelled"}}catch{return{status:"failed"}}},lt={autoComplete:"off",autoCorrect:"off",spellCheck:!1},vt="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20",wr=s=>{const e=de.c(22),{onCancel:n}=s,{t:o}=ue(),r=l.useRef(null);let i,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{const I={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},P={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const T=new Map,N=D=>{!(D instanceof HTMLElement)||D===r.current||T.has(D)||(T.set(D,{opacity:D.style.opacity,pointerEvents:D.style.pointerEvents}),D.style.setProperty("opacity","0"),D.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(N);const E=new MutationObserver(D=>{D.forEach(w=>w.addedNodes.forEach(N))});return E.observe(document.body,{childList:!0}),()=>{E.disconnect(),T.forEach(Ba),I.value?document.documentElement.style.setProperty("background-color",I.value,I.priority):document.documentElement.style.removeProperty("background-color"),P.value?document.body.style.setProperty("background-color",P.value,P.priority):document.body.style.removeProperty("background-color")}},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),l.useLayoutEffect(i,a);let c,d;e[2]!==n?(c=()=>{const I=()=>{document.visibilityState==="hidden"&&n()};return document.addEventListener("visibilitychange",I),()=>document.removeEventListener("visibilitychange",I)},d=[n],e[2]=n,e[3]=c,e[4]=d):(c=e[3],d=e[4]),l.useEffect(c,d);let u;e[5]!==o?(u=o("mobile.connect.scanQr"),e[5]=o,e[6]=u):u=e[6];let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),e[7]=f):f=e[7];let p;e[8]!==o?(p=o("mobile.connect.welcome.scanHint"),e[8]=o,e[9]=p):p=e[9];let b;e[10]!==p?(b=t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[f,t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:p})]}),e[10]=p,e[11]=b):b=e[11];let x;e[12]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(se,{name:"close",className:"size-[18px]"}),e[12]=x):x=e[12];let v;e[13]!==o?(v=o("mobile.instances.cancelEdit"),e[13]=o,e[14]=v):v=e[14];let S;e[15]!==n||e[16]!==v?(S=t.jsxs(ge,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:n,children:[x,v]}),e[15]=n,e[16]=v,e[17]=S):S=e[17];let g;return e[18]!==S||e[19]!==u||e[20]!==b?(g=ct.createPortal(t.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-label":u,className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[b,S]}),document.body),e[18]=S,e[19]=u,e[20]=b,e[21]=g):g=e[21],g},jr=()=>{const s=de.c(6),{t:e}=ue();let n;s[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx(Je,{width:96,height:96,isAnimated:!0}),s[0]=n):n=s[0];let o;s[1]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx(se,{name:"loader-4",className:"size-[18px] animate-spin"}),s[1]=o):o=s[1];let r;s[2]!==e?(r=e("mobile.connect.connecting"),s[2]=e,s[3]=r):r=s[3];let i;return s[4]!==r?(i=ct.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[n,t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[o,t.jsx("span",{children:r})]})]}),document.body),s[4]=r,s[5]=i):i=s[5],i};function Ba(s,e){e.style.opacity=s.opacity,e.style.pointerEvents=s.pointerEvents}const $a=({onConnected:s,notice:e=null})=>{const{t:n}=ue(),o=br(s),{connections:r,isBusy:i,isPasswordBusy:a,error:c,pendingConnection:d}=o,[u,f]=l.useState(""),[p,b]=l.useState(""),[x,v]=l.useState(""),[S,g]=l.useState(!1),[I,P]=l.useState(!1),T=l.useRef(null),N=l.useMemo(()=>fs(),[]),[E,D]=l.useState(()=>!fs()),[w,C]=l.useState(null),[y,k]=l.useState(""),A=l.useCallback(h=>{h.preventDefault(),o.connect({url:u,clientToken:x,label:p})},[x,o,p,u]),R=l.useCallback(h=>{if(/^openchamber:\/\//i.test(h.trim())){const L=xr(h);if(L){if("pairing"in L){o.redeemPairingConnection(L.pairing);return}f(L.url),L.label&&b(L.label),L.clientToken&&v(L.clientToken);return}}f(h)},[o]),j=l.useCallback(async()=>{if(T.current||i)return;o.setError(null),g(!0);const h=new AbortController;T.current=h;try{const L=await vr({signal:h.signal});switch(T.current===h&&(T.current=null,g(!1)),L.status){case"ok":P(!0),f(L.url),L.label&&b(L.label),L.clientToken&&v(L.clientToken),await o.connect({url:L.url,clientToken:L.clientToken,label:L.label});break;case"pairing":P(!0),await o.redeemPairingConnection(L.pairing);break;case"permission-denied":o.setError(n("mobile.connect.scan.permissionDenied"));break;case"invalid":o.setError(n("mobile.connect.scan.invalid"));break;case"unsupported":o.setError(n("mobile.connect.scan.unsupported"));break;case"failed":o.setError(n("mobile.connect.scan.failed"));break;default:break}}finally{P(!1),T.current===h&&(T.current=null,g(!1))}},[o,i,n]);l.useEffect(()=>()=>T.current?.abort(),[]);const V=l.useCallback(h=>{h.preventDefault(),o.submitPassword(y)},[o,y]),z=l.useCallback(()=>{k(""),o.cancelPassword()},[o]);return t.jsxs(t.Fragment,{children:[S?t.jsx(wr,{onCancel:()=>T.current?.abort()}):null,I?t.jsx(jr,{}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx(Je,{width:72,height:72,className:"size-[72px]"}),t.jsx("h1",{className:"typography-h2 text-foreground",children:n("mobile.connect.welcome.title")})]}),e?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(se,{name:e.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:e.kind==="auth-expired"?n("mobile.connect.notice.authExpired",{label:e.label}):n("mobile.connect.notice.unreachable",{label:e.label})})]}):null,d?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:V,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(se,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(h=>h.kind==="direct")?He(d):n("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...lt,value:y,onChange:h=>k(h.target.value),placeholder:n("mobile.connect.password.placeholder"),"aria-label":n("mobile.connect.password.label"),type:"password",autoFocus:!0,className:vt}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!y.trim(),children:n(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:z,children:n("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[N?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(ge,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{j()},disabled:S||i,children:[t.jsx(se,{name:"scan-2",className:te("size-[18px]",S&&"animate-pulse")}),n(i?"mobile.connect.connecting":"mobile.connect.scanQr")]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:n("mobile.connect.welcome.scanHint")})]}):null,c&&!E?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:n("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(h=>{const L=w===h.id;return t.jsxs("button",{type:"button",disabled:i,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-70",onClick:()=>{C(h.id),o.connect({id:h.id,candidates:h.candidates,clientToken:h.clientToken,label:h.label}).finally(()=>C(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(se,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:h.label}),t.jsx("span",{className:te("block truncate typography-small",L?"text-foreground":"text-muted-foreground"),children:L?n("mobile.connect.connecting"):h.candidates.some(M=>M.kind==="direct")?He(h):n("mobile.connect.relay.badge")})]}),L?t.jsx(se,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(se,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},h.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[N?t.jsxs("button",{type:"button",onClick:()=>D(h=>!h),"aria-expanded":E,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:n("mobile.connect.manual.toggle")}),t.jsx(se,{name:"arrow-down-s",className:te("size-4 transition-transform duration-200",E&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:E?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:A,children:[t.jsx("input",{...lt,value:u,onChange:h=>R(h.target.value),placeholder:n("mobile.connect.url.placeholder"),"aria-label":n("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:E?void 0:-1,className:te(vt,"text-center")}),t.jsx("input",{value:p,onChange:h=>b(h.target.value),placeholder:n("mobile.instances.label.placeholder"),"aria-label":n("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:E?void 0:-1,className:te(vt,"text-center")}),t.jsx("input",{...lt,value:x,onChange:h=>v(h.target.value),placeholder:n("mobile.connect.token.placeholder"),"aria-label":n("mobile.connect.token.label"),tabIndex:E?void 0:-1,autoCapitalize:"none",className:te(vt,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:n("mobile.connect.token.hint")}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",variant:N?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||S||!u.trim(),children:n(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},jn=380,Fa=(s,e)=>{if(!s||typeof s!="object")return;const n=s[e];return typeof n=="number"&&Number.isFinite(n)?n:void 0},gt=s=>typeof s=="number"&&Number.isFinite(s)?s:0,kn=s=>s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:String(s),Wa=s=>{const e=s.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},kr=s=>{const e=de.c(19),{percentage:n}=s;let o,r,i,a,c,d,u;if(e[0]!==n){i=ao(n)??0;const v=lo(n);r=v==="critical"?"var(--status-error)":v==="warn"?"var(--status-warning)":"var(--status-success)",o=2*Math.PI*7.5,a="0 0 18 18",c="size-[18px] -rotate-90",d="progressbar",u=Math.round(i),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=a,e[5]=c,e[6]=d,e[7]=u}else o=e[1],r=e[2],i=e[3],a=e[4],c=e[5],d=e[6],u=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=f):f=e[8];const p=o*(1-i/100);let b;e[9]!==o||e[10]!==r||e[11]!==p?(b=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:o,strokeDashoffset:p,className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=o,e[10]=r,e[11]=p,e[12]=b):b=e[12];let x;return e[13]!==a||e[14]!==c||e[15]!==d||e[16]!==u||e[17]!==b?(x=t.jsxs("svg",{viewBox:a,className:c,role:d,"aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,children:[f,b]}),e[13]=a,e[14]=c,e[15]=d,e[16]=u,e[17]=b,e[18]=x):x=e[18],x},Ua=s=>{const e=de.c(13),{icon:n,iconNode:o,label:r,children:i}=s;let a;e[0]!==n||e[1]!==o?(a=o??(n?t.jsx(se,{name:n,className:"size-[18px]"}):null),e[0]=n,e[1]=o,e[2]=a):a=e[2];let c;e[3]!==a?(c=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==r?(d=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=d):d=e[6];let u;e[7]!==i?(u=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:i}),e[7]=i,e[8]=u):u=e[8];let f;return e[9]!==c||e[10]!==d||e[11]!==u?(f=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[c,d,u]}),e[9]=c,e[10]=d,e[11]=u,e[12]=f):f=e[12],f},Va=s=>{const e=de.c(49),{open:n,onClose:o,anchorRef:r,contextDisplay:i,usageGroups:a,usageDisplayMode:c,isUsageLoading:d,timeFormatPreference:u}=s,{t:f}=ue(),p=l.useRef(null),[b,x]=l.useState(n),[v,S]=l.useState(!1),{enabled:g}=ys(),I=l.useRef(null),[P,T]=l.useState(null);let N,E;e[0]!==r||e[1]!==g||e[2]!==n||e[3]!==b?(N=()=>{if(!n||!g||!b)return;const F=()=>{const ee=r.current?.getBoundingClientRect(),W=I.current?.getBoundingClientRect();if(!ee||!W){T(null);return}const oe=ee.left-W.left,ie=Math.min(Math.max(oe,8),Math.max(8,W.width-jn-8));T(ie)};F();const U=I.current;if(typeof ResizeObserver>"u"||!U)return;const X=new ResizeObserver(F);return X.observe(U),()=>X.disconnect()},E=[r,g,n,b],e[0]=r,e[1]=g,e[2]=n,e[3]=b,e[4]=N,e[5]=E):(N=e[4],E=e[5]),l.useLayoutEffect(N,E);const D=g&&P!==null;let w,C;e[6]!==n||e[7]!==b?(w=()=>{if(n){x(!0),S(!1);return}if(!b)return;S(!0);const F=window.setTimeout(()=>{x(!1),S(!1)},140);return()=>window.clearTimeout(F)},C=[n,b],e[6]=n,e[7]=b,e[8]=w,e[9]=C):(w=e[8],C=e[9]),l.useEffect(w,C);let y,k;e[10]!==o||e[11]!==n?(y=()=>{if(!n)return;const F=U=>{U.key==="Escape"&&o()};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},k=[o,n],e[10]=o,e[11]=n,e[12]=y,e[13]=k):(y=e[12],k=e[13]),l.useEffect(y,k);let A,R;if(e[14]!==r||e[15]!==o||e[16]!==n?(A=()=>{if(!n)return;const F=U=>{const X=U.target;if(!(X instanceof Node)){o();return}p.current?.contains(X)||r.current?.contains(X)||o()};return document.addEventListener("pointerdown",F,!0),document.addEventListener("wheel",F,!0),()=>{document.removeEventListener("pointerdown",F,!0),document.removeEventListener("wheel",F,!0)}},R=[r,o,n],e[14]=r,e[15]=o,e[16]=n,e[17]=A,e[18]=R):(A=e[17],R=e[18]),l.useEffect(A,R),!b)return null;let j;e[19]!==f?(j=f("mobile.header.openMetadataAria"),e[19]=f,e[20]=j):j=e[20];const V=D?"absolute origin-top-left":"mx-3 mt-2",z=v?"pointer-events-none":"pointer-events-auto";let h;e[21]!==V||e[22]!==z?(h=te("overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",V,z),e[21]=V,e[22]=z,e[23]=h):h=e[23];const L=`${v?"session-metadata-out":"session-metadata-in"} ${v?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let M;e[24]!==P||e[25]!==D?(M=D?{top:8,left:P??8,width:`min(${jn}px, calc(100% - 16px))`}:null,e[24]=P,e[25]=D,e[26]=M):M=e[26];let B;e[27]!==L||e[28]!==M?(B={animation:L,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...M},e[27]=L,e[28]=M,e[29]=B):B=e[29];let H;e[30]!==i||e[31]!==f?(H=i?t.jsx(Ua,{iconNode:t.jsx(kr,{percentage:i.percentage}),label:f("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:te("font-semibold",i.colorClass),children:[i.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:i.tokens})]})}):null,e[30]=i,e[31]=f,e[32]=H):H=e[32];let Z;e[33]!==d||e[34]!==u||e[35]!==c||e[36]!==a?(Z=t.jsx(Ha,{groups:a,displayMode:c,isLoading:d,timeFormatPreference:u}),e[33]=d,e[34]=u,e[35]=c,e[36]=a,e[37]=Z):Z=e[37];let Q;e[38]!==H||e[39]!==Z?(Q=t.jsxs("div",{className:"space-y-1",children:[H,Z]}),e[38]=H,e[39]=Z,e[40]=Q):Q=e[40];let _;e[41]!==h||e[42]!==B||e[43]!==Q||e[44]!==j?(_=t.jsx("div",{ref:p,role:"dialog","aria-label":j,className:h,style:B,children:Q}),e[41]=h,e[42]=B,e[43]=Q,e[44]=j,e[45]=_):_=e[45];let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J=t.jsx("style",{children:`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesView-cJPeFhDe.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-DjZ4W8hy.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/vendor-zustand-BAGL70zf.js","assets/index-CL9MYe8V.css","assets/useAppFontEffects-DdvGxoPX.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BuzaMvKv.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-DKpLs02S.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-DW3atb4h.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-pierre-diffs-B1TeaSIY.js","assets/vendor-lru_map-Tstukz9J.js","assets/vendor-pierre-theming-D_y07OK2.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-diff-C3JhlQdm.js","assets/vendor-shiki-DuWDB27E.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-CTJVwiVf.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-B3NPxZ-7.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-CWhyzlcb.js","assets/vendor-codemirror-lang-json-Bty2AtQK.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-D_jk9hVN.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-Dxy5thAH.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-dH8tblNV.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-o9e2Fm3f.js","assets/vendor-codemirror-lang-python-PETDP1TX.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-legacy-modes-DBXLFsoH.js","assets/vendor-codemirror-commands-eyb3xW_0.js","assets/vendor-framer-motion-CRSgBxjL.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/runtimeEndpointReset-DKzVWH1w.js","assets/vendor-yaml-3778uTud.js","assets/vendor-codemirror-search-8kyQdB3f.js","assets/vendor-replit-codemirror-vim-D0xSkRWg.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/vendor-ghostty-web-CfpAcbEe.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/vendor-capacitor-status-bar-B-N0EOVk.js","assets/vendor-capacitor-core-B4EWRrHz.js","assets/vendor-capacitor-app-BrDJj9I_.js","assets/vendor-capacitor-keyboard-CYccoJjr.js","assets/vendor-capacitor-push-notifications-KNe1zSBF.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{f as de,r as ls,j as t,R as l,c as ct,h as Yr}from"./vendor-react-BUCujlKS.js";import{u as Ve,a as Pt,b as Hn,d as sn,i as Ce,e as Ge,s as it,f as Et,r as bs,h as Jr,j as Gn,p as Qr,k as dt,l as Xr,m as nn,n as rn,o as Zr,q as on,t as eo,v as to}from"./index-DjZ4W8hy.js";import{u as gs,a as so,b as Oe,c as Kn,d as qn,r as xs,e as no,f as ue,t as le,o as ro,I as se,B as ge,O as Je,g as te,h as oo,i as ze,j as io,p as an,k as ln,l as ys,m as ao,n as lo,P as co,q as uo,s as fo,v as ve,w as mo,x as Yn,y as Jn,z as po,A as vs,C as ho,D as Qn,E as bo,F as go,M as xo,G as Xn,H as Zn,J as er,K as tr,L as ws,N as yo,Q as vo,R as js,S as wo,T as jo,U as cn,V as ks,W as sr,X as nr,Y as Ss,Z as ko,_ as So,$ as No,a0 as Ue,a1 as Eo,a2 as Co,a3 as Ro,a4 as Po,a5 as To,a6 as Io,a7 as _o,a8 as Be,a9 as Ao,aa as Do,ab as dn,ac as Mo,ad as Lo,ae as zo,af as Oo,ag as Bo,ah as $o,ai as Fo,aj as Wo,ak as Uo,al as Vo,am as Ho,an as Go,ao as Ko,ap as qo,aq as Yo,ar as Jo,as as Qo,at as Xo,au as Zo,av as ei,aw as ti,ax as si,ay as ni,az as ri,aA as oi,aB as ii,aC as ai,aD as li,aE as ci,aF as di,aG as ui,aH as fi}from"./useAppFontEffects-DdvGxoPX.js";import{u as at,a as Ye,b as mi,Q as pi,g as hi,D as bi,N as gi,S as xi,C as yi,c as vi,P as wi,M as ji,d as ki,T as Si,e as Ni,f as Ei,h as Bt,i as Ci,r as Ri,j as Pi,k as Ti,l as Ii,O as _i,m as Ai,n as Di,o as Mi,p as Li,A as zi,q as Oi}from"./runtimeEndpointReset-DKzVWH1w.js";import{_ as $e}from"./vendor-vite-runtime-DD1OZmLC.js";import{p as Bi}from"./vendor-aparajita-capacitor-secure-storage-5IShChL0.js";import{Capacitor as $i}from"./vendor-capacitor-core-B4EWRrHz.js";import{k as cs,s as rr,M as Ns,a as Ut,J as ds,p as Fi,_ as un,b as or,P as ir,d as Wi,f as Es,V as Ui,K as fn,c as Vi,Q as Hi,r as Gi,U as Ki,Z as qi}from"./vendor-remixicon-react-Dil0zKKT.js";import{f as Cs,h as ut,i as Rs,P as Ps,D as Ts,j as Is}from"./vendor-dnd-kit-core-BZknOX2w.js";import{s as _s,S as As,v as Ds,u as Ms}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Ls}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{c as zs,p as ar}from"./vendor-zustand-BAGL70zf.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BuzaMvKv.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-DW3atb4h.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-pierre-diffs-B1TeaSIY.js";import"./vendor-lru_map-Tstukz9J.js";import"./vendor-pierre-theming-D_y07OK2.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-diff-C3JhlQdm.js";import"./vendor-shiki-DuWDB27E.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-CTJVwiVf.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-B3NPxZ-7.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CWhyzlcb.js";import"./vendor-codemirror-lang-json-Bty2AtQK.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-D_jk9hVN.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-Dxy5thAH.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-dH8tblNV.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-o9e2Fm3f.js";import"./vendor-codemirror-lang-python-PETDP1TX.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-legacy-modes-DBXLFsoH.js";import"./vendor-codemirror-commands-eyb3xW_0.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-yaml-3778uTud.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-D0xSkRWg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-ghostty-web-CfpAcbEe.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";let lr=null,mn=!1;const Yi=new Promise(s=>{lr=s});function Ji(){mn||(mn=!0,lr?.())}const Qi=6,Xi=s=>s.parentID??null,pn=s=>{const e=s.replace(/\/+$/,"");return e.slice(e.lastIndexOf("/")+1)||e},Zi=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),ea=(s,e)=>{if(!s)return"";let n=null,o=-1;for(const r of e){const i=Zi(r.path);(s===i||s.startsWith(`${i}/`))&&i.length>o&&(n=r,o=i.length)}return n?n.label?.trim()||pn(n.path):pn(s)},ta=()=>{const s=gs.getState().activeSessions,e=so.getState().index.session.unseenCount,n=Ve.getState().notifyOnSubtasks,o=Oe.getState().projects,r=Kn.getState().ids,i=qn.getState().rankById;let a=0;const c=[];for(const u of s){const f=Xi(u)!==null,b=(e[u.id]??0)>0&&(!f||n);b&&(a+=1),f||c.push({session:u,unread:b,project:ea(xs(u),o)})}c.sort((u,f)=>no(u.session,f.session,r,i));const d=c.slice(0,Qi).map(({session:u,unread:f,project:p})=>({id:u.id,title:u.title??"",unread:f,project:p}));return{runtimeKey:Pt(),attentionCount:a,recentSessions:d}},sa="__OPENCHAMBER_WIDGET_SNAPSHOT__",na=()=>{typeof window>"u"||(window[sa]=()=>{try{return JSON.stringify(ta())}catch{return null}})},es="mobile-app-update-available",hn="mobile-app-update-toast-dismissed-version",ra=()=>{const s=de.c(8),{t:e}=ue(),n=at(oa),o=at(ia),r=at(aa),i=at(la);let a;s[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,s[0]=a):a=s[0];const c=ls.useRef(a);let d,u;return s[1]!==n||s[2]!==i||s[3]!==o||s[4]!==e||s[5]!==r?(d=()=>{if(Hn()!=="android"||o!=="mobile"||!n||!r||!i){le.dismiss(es);return}sn().getItem(hn)!==r&&(c.current.has(r)||(c.current.add(r),le.info(e("mobileUpdate.toast.available.title"),{id:es,description:e("mobileUpdate.toast.available.description",{version:r}),duration:1/0,icon:t.jsx(se,{name:"download",className:"h-4 w-4 text-muted-foreground"}),action:{label:e("mobileUpdate.toast.actions.download"),onClick:()=>{ro(i)}},cancel:{label:e("mobileUpdate.toast.actions.dismiss"),onClick:()=>{sn().setItem(hn,r),le.dismiss(es)}}})))},u=[n,i,o,e,r],s[1]=n,s[2]=i,s[3]=o,s[4]=e,s[5]=r,s[6]=d,s[7]=u):(d=s[6],u=s[7]),ls.useEffect(d,u),null};function oa(s){return s.available}function ia(s){return s.runtimeType}function aa(s){return s.info?.version}function la(s){return s.info?.downloadUrl}const Vt="openchamber.mobile.connections.v1",ca="openchamber.mobile.",bn="openchamber.mobile.deviceId",da=()=>{try{const s=window.localStorage.getItem(bn);if(s&&s.trim())return s.trim();const e=crypto.randomUUID();return window.localStorage.setItem(bn,e),e}catch{return crypto.randomUUID()}},gn=()=>`mobile:${da()}`,xn=()=>{try{const s=$i.getPlatform();return s==="ios"||s==="android"?s:void 0}catch{return}},cr=12,ua=8e3,fa=2500,ma=3e3,Ht=2500,pa=()=>{let s=0;return{begin:()=>(s+=1,s),cancel:()=>{s+=1},isCurrent:e=>e===s}},pt=s=>{const e=s.trim();if(!e)return"";const n=/^https?:\/\//i.test(e)?e:`http://${e}`,o=new URL(n);return o.hash="",o.search="",o.pathname=o.pathname.replace(/\/+$/,""),o.toString().replace(/\/+$/,"")},$t=s=>{try{return new URL(s).host}catch{return s}},ft=s=>{try{return pt(s)}catch{return s.trim().replace(/\/+$/g,"")}},dr=(s,e)=>ft(s)===ft(e),ur=s=>`relay:${s.serverId}@${s.relayUrl.trim()}`,ha=s=>`relay://${s.serverId}`,Yt=s=>s.candidates.filter(e=>e.kind==="direct"),Ze=s=>{const e=s.candidates.find(n=>n.kind==="relay");return e&&e.kind==="relay"?e.relay:null},He=s=>{const e=Yt(s)[0];if(e)return e.url;const n=Ze(s);return n?ha(n):""},Ee=s=>{const e=Ze(s);if(e)return ur(e);const n=Yt(s)[0];return n?ft(n.url):""},Gt=(s,e)=>{const n=s.find(i=>i.kind==="relay"),o=n&&n.kind==="relay"?n.relay.serverId:null,r=new Set(s.filter(i=>i.kind==="direct").map(i=>ft(i.url)));return e.some(i=>i.kind==="relay"?o!==null&&i.relay.serverId===o:r.has(ft(i.url)))},Os=s=>{const e=(()=>{try{return pt(s)}catch{return""}})();return e?[{kind:"direct",url:e}]:[]},yn=s=>{if(s.candidates&&s.candidates.length>0)return s.candidates;const e=[];return typeof s.url=="string"&&s.url.trim()&&!/^relay:\/\//i.test(s.url.trim())&&e.push(...Os(s.url)),s.relay&&e.push({kind:"relay",relay:s.relay}),e},Bs=s=>{if(!s||typeof s!="object"||Array.isArray(s))return null;const e=s;if(typeof e.relayUrl!="string"||!e.relayUrl.trim()||typeof e.serverId!="string"||!e.serverId.trim())return null;const n=e.hostEncPubJwk;if(!n||typeof n!="object"||Array.isArray(n))return null;const o=n;return o.kty!=="EC"||o.crv!=="P-256"||typeof o.x!="string"||!o.x||typeof o.y!="string"||!o.y?null:{relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:{kty:"EC",crv:"P-256",x:o.x,y:o.y}}},Jt=s=>{try{return JSON.stringify(s)}catch{return String(s)}},Pe=(s,e={})=>{console.info("[mobile-connect]",s,Jt(e))},mt=(s,e={})=>{console.info("[mobile-storage]",s,Jt(e))},ba=s=>{if(typeof s!="string")return s;try{return JSON.parse(s)}catch{return s}},ga=s=>{if(typeof s!="string")return s??void 0;try{return JSON.parse(s)}catch{return s}},xa=async(s,e)=>{if(!Ce())return null;try{const{CapacitorHttp:n}=await $e(async()=>{const{CapacitorHttp:i}=await import("./vendor-capacitor-core-B4EWRrHz.js");return{CapacitorHttp:i}},[]),o=Object.fromEntries(new Headers(e?.headers).entries()),r=await n.request({url:s,method:e?.method||"GET",headers:o,data:ga(e?.body)});return{ok:r.status>=200&&r.status<300,status:r.status,source:"native-http",json:async()=>ba(r.data)}}catch(n){return console.warn("[mobile-connect]","native-http failed",Jt({url:s,error:n instanceof Error?n.message:String(n)})),null}},ya=async(s,e)=>{const n=await fetch(s,e).catch(o=>(console.warn("[mobile-connect]","browser-fetch failed",Jt({url:s,error:o instanceof Error?o.message:String(o)})),null));return n?{ok:n.ok,status:n.status,source:"browser-fetch",json:()=>n.json()}:null},qe=async(s,e,n)=>{let o;const r=new Promise(i=>{o=window.setTimeout(()=>{n?.(),i(null)},s)});try{return await Promise.race([e,r])}catch{return null}finally{o!==void 0&&window.clearTimeout(o)}},et=async(s,e,n)=>{const o=n?.totalTimeoutMs??ua,r=Date.now(),i=await qe(Math.min(fa,o),xa(s,e));if(i)return i;const a=new AbortController,c=Math.max(500,o-(Date.now()-r));return qe(c,ya(s,{...e,signal:a.signal}),()=>a.abort())},Qt=async s=>{if(!s)return null;const e=await s.json().catch(()=>null);if(!e||typeof e!="object")return null;const n=e;return{authenticated:typeof n.authenticated=="boolean"?n.authenticated:void 0,disabled:typeof n.disabled=="boolean"?n.disabled:void 0,scope:typeof n.scope=="string"?n.scope:void 0}},Ct=15e3,va=async(s,e,n,o=Ct,r)=>{const i=Gn({relayUrl:s.relayUrl,serverId:s.serverId,hostEncPubJwk:s.hostEncPubJwk}),a=c=>c==="ok"&&r?.keepTunnel?{outcome:c,tunnel:i}:(i.close(),{outcome:c});try{const c=e?{Authorization:`Bearer ${e}`}:void 0,d=await qe(o,i.fetch("/auth/session",{headers:c}).catch(()=>null));if(Pe("relay:session",{ok:d?.ok===!0,status:d?.status??null,hasToken:!!e}),!d)return a("unreachable");if(d.status===401)return a(e?"auth-failed":"needs-login");if(!d.ok&&d.status!==404)return a("auth-failed");const u=await Qt(d);return u&&u.disabled!==!0&&u.authenticated===!1?a(e?"auth-failed":"needs-login"):a("ok")}catch(c){throw i.close(),c}},wa=(s,e,n,o,r)=>{const i=typeof window<"u"?window.location.origin:"",a={relayUrl:s.relayUrl,serverId:s.serverId,hostEncPubJwk:s.hostEncPubJwk,...n?{grant:n}:{}};r&&Jr(a,r),it({apiBaseUrl:i,clientToken:e,runtimeKey:o??ur(s),relay:a})},ja=s=>{if(!s||typeof s!="object")return null;const e=s;if(e.kind==="direct")return typeof e.url=="string"&&e.url.trim()?{kind:"direct",url:e.url}:null;if(e.kind==="relay"){const n=Bs(e.relay);return n?{kind:"relay",relay:n}:null}return null},ka=s=>{if(s.mode==="relay"){const e=Bs(s.relay);return e?[{kind:"relay",relay:e}]:[]}return typeof s.url=="string"?Os(s.url):[]},st=()=>{if(typeof window>"u")return[];let s;try{s=JSON.parse(window.localStorage.getItem(Vt)||"[]")}catch{return[]}if(!Array.isArray(s))return[];const e=Ce();return s.flatMap(n=>{if(!n||typeof n!="object")return[];const o=n;if(typeof o.id!="string")return[];const r=Array.isArray(o.candidates)?o.candidates.map(ja).filter(d=>!!d):ka(o);if(r.length===0)return[];const i=typeof o.clientToken=="string"&&o.clientToken.trim()?o.clientToken:void 0,a=typeof o.label=="string"&&o.label.trim()?o.label:$t(He({candidates:r})),c={id:o.id,label:a,candidates:r,lastUsedAt:typeof o.lastUsedAt=="number"?o.lastUsedAt:0};return e?[{...c,hasToken:!!o.hasToken||!!i}]:[{...c,clientToken:i,hasToken:!!i}]}).sort((n,o)=>o.lastUsedAt-n.lastUsedAt)},us=s=>s.kind==="relay"?{kind:"relay",relay:{relayUrl:s.relay.relayUrl,serverId:s.relay.serverId,hostEncPubJwk:s.relay.hostEncPubJwk}}:{kind:"direct",url:s.url},$s=s=>{if(typeof window>"u")return;const e=Ce(),n=s.slice(0,cr).map(o=>{const r={id:o.id,label:o.label,candidates:o.candidates.map(us),lastUsedAt:o.lastUsedAt};return e?{...r,hasToken:!!(o.hasToken||o.clientToken)}:{...r,clientToken:o.clientToken}});try{window.localStorage.setItem(Vt,JSON.stringify(n))}catch(o){console.warn("[mobile-storage] failed to persist connection metadata",o)}},fr=(s,e)=>{const n=s.find(i=>e.id&&i.id===e.id||Gt(i.candidates,e.candidates)),o=Ce(),r={id:e.id||n?.id||crypto.randomUUID(),label:e.label,candidates:e.candidates,lastUsedAt:Date.now(),...o?{hasToken:e.hasToken??(!!e.clientToken||n?.hasToken||!1)}:{clientToken:e.clientToken??n?.clientToken,hasToken:!!(e.clientToken??n?.clientToken)}};return[r,...s.filter(i=>i.id!==r.id&&!Gt(i.candidates,e.candidates))].slice(0,cr)},Fs=Bi,Sa=0,Ws=s=>`${ca}token.${encodeURIComponent(s)}`,Na=async(s,e)=>{let n;const o=new Promise(r=>{n=window.setTimeout(()=>r(e),ma)});try{return await Promise.race([s.catch(()=>e),o])}finally{n!==void 0&&window.clearTimeout(n)}},Us=async(s,e,n)=>Ce()?Na(e().catch(o=>(console.warn(`[mobile-storage] ${s} failed`,o),n)),n):n,Rt=async s=>{mt("secure:read-start",{key:s});const e=await Us("secure:read",async()=>(await Fs.internalGetItem({prefixedKey:Ws(s),sync:!1})).data,null),n=typeof e=="string"&&e.trim()?e:void 0;return mt("secure:read",{key:s,hasToken:!!n}),n},Qe=async(s,e)=>{mt("secure:write-start",{key:s});const n=await Us("secure:write",async()=>(await Fs.internalSetItem({prefixedKey:Ws(s),data:e,sync:!1,access:Sa}),!0),!1);return mt("secure:write",{key:s,ok:n}),n},Ea=async s=>{await Us("secure:delete",async()=>(await Fs.internalRemoveItem({prefixedKey:Ws(s),sync:!1}),!0),!1)},Ca=async(s,e)=>{let n=0,o=0;return{records:await Promise.all(s.map(async i=>{if(!i||typeof i!="object")return i;const a=i,c=typeof a.url=="string"?a.url:null,d=typeof a.clientToken=="string"?a.clientToken.trim():"";if(!c||!d)return i;if(!await e(c,d))return o+=1,i;n+=1;const{clientToken:u,...f}=a;return{...f,hasToken:!0}})),migrated:n,failed:o}},mr=async()=>{if(typeof window>"u"||!Ce())return;let s;try{s=JSON.parse(window.localStorage.getItem(Vt)||"[]")}catch{return}if(!Array.isArray(s))return;const e=s.filter(o=>!!o&&typeof o=="object"&&typeof o.url=="string"&&typeof o.clientToken=="string"&&!!o.clientToken.trim());if(e.length===0)return;mt("secure:migrate-start",{count:e.length});const n=await Ca(s,async(o,r)=>{const i=ft(o);return await Qe(i,r)?await Rt(i)===r:!1});if(n.migrated>0)try{window.localStorage.setItem(Vt,JSON.stringify(n.records))}catch(o){console.warn("[mobile-storage] failed to finalize secure token migration",o);return}mt("secure:migrate-done",{migrated:n.migrated,failed:n.failed})},Ra=async()=>(await mr(),st()),Kt=async s=>{const e=fr(st(),s);return $s(e),Ce()&&s.clientToken&&await Qe(Ee({candidates:s.candidates}),s.clientToken),e},Pa=async s=>{const e=st(),n=e.find(r=>r.id===s)??null,o=e.filter(r=>r.id!==s);return $s(o),n&&Ce()&&await Ea(Ee(n)),o},Ta=1500,qt=async(s,e,n)=>{const o=n?.fast?{totalTimeoutMs:Ht}:void 0,r=Ze({candidates:s})?.serverId??null,i=s.find(u=>u.kind==="relay")??null,a=s.filter(u=>u.kind==="direct"),c=async()=>{for(const u of a){const f=pt(u.url)||u.url,p=e?{Authorization:`Bearer ${e}`}:void 0,b=await et(`${f}/health`,{method:"GET"},o);if(!b?.ok)continue;if(r){const g=await b.json().catch(()=>null),I=g&&typeof g=="object"?g.serverId:null;if(typeof I=="string"&&I&&I!==r){Pe("probe:server-id-mismatch",{url:f});continue}}const x=await et(`${f}/auth/session`,{method:"GET",credentials:e?"omit":"include",headers:p},o);if(x?.status===401)return{status:"needs-login"};if(!x||!x.ok&&x.status!==404)continue;const v=await Qt(x);if(v&&v.disabled!==!0&&v.authenticated===!1)return{status:"needs-login"};const S=v?.disabled===!0;return!e&&Ce()&&!S&&v?.scope!=="client"?{status:"needs-login"}:{status:"ok",transport:{kind:"direct",url:f}}}return{status:"unreachable"}},d=async()=>{if(!i)return{status:"unreachable"};const{outcome:u,tunnel:f}=await va(i.relay,e,void 0,n?.fast?Ht:void 0,{keepTunnel:!0});return u==="ok"?{status:"ok",transport:{kind:"relay",relay:i.relay,tunnel:f}}:u==="needs-login"||u==="auth-failed"?{status:"needs-login"}:{status:"unreachable"}};return i?a.length===0?d():new Promise(u=>{let f=!1,p=!1,b,x=null,v=null;const S=P=>{P?.status==="ok"&&P.transport.kind==="relay"&&P.transport.tunnel?.close()},g=P=>{f||(f=!0,u(P))},I=()=>{p||f||(b!==void 0&&(window.clearTimeout(b),b=void 0),d().then(P=>{if(v=P,f||p){S(P);return}if(P.status==="ok"||P.status==="needs-login"){g(P);return}x&&g(x)}))};c().then(P=>{if(x=P,!f){if(P.status==="ok"||P.status==="needs-login"){p=!0,b!==void 0&&window.clearTimeout(b),S(v),g(P);return}if(v){g(v);return}I()}}),b=window.setTimeout(I,Ta)}):c()},Xe=(s,e,n)=>{s.kind==="relay"?wa(s.relay,e,n?.grant,n?.runtimeKey,s.tunnel):it({apiBaseUrl:s.url,clientToken:e,runtimeKey:n?.runtimeKey}),hr()},yt=()=>{const s=st()[0];return s?.label?.trim()?s.label:null},ts=async()=>{await mr();const s=st()[0];if(!s)return{status:"no-candidate"};let e;if(Ce()){if(!s.hasToken)return{status:"no-candidate"};if(e=await Rt(Ee(s)),!e)return{status:"no-candidate"}}else if(e=s.clientToken,!e)return{status:"no-candidate"};const n=await qt(s.candidates,e,{fast:!0});return n.status==="needs-login"?{status:"needs-login",label:s.label}:n.status!=="ok"?{status:"unreachable",label:s.label}:(await Kt({id:s.id,label:s.label,candidates:s.candidates}),Xe(n.transport,e,{runtimeKey:Ee(s)}),{status:"connected"})},Ia=async(s,e)=>{let n="";try{n=pt(s.url)}catch{return!1}if(!n)return!1;const o=s.clientToken?.trim()||void 0,r=o?{Authorization:`Bearer ${o}`}:void 0,i={totalTimeoutMs:Ht};if(!(await et(`${n}/health`,{method:"GET",headers:r},i))?.ok)return!1;const c=await et(`${n}/auth/session`,{method:"GET",credentials:o?"omit":"include",headers:r},i);if(!c||!c.ok&&c.status!==404)return!1;const d=await Qt(c);return!(d&&d.disabled!==!0&&d.authenticated===!1)},_a=s=>[...s].sort((e,n)=>{const o=(e.priority??100)-(n.priority??100);if(o!==0)return o;const r=i=>i.type==="relay"?2:i.url.startsWith("https://")?0:1;return r(e)-r(n)}).flatMap(e=>{if(e.type==="relay"){const n=Bs({relayUrl:e.relayUrl,serverId:e.serverId,hostEncPubJwk:e.hostEncPubJwk});return n?[{kind:"relay",relay:n}]:[]}return Os(e.url)}),vn=async s=>{const e=Ze({candidates:s})?.serverId??null;for(const n of s){if(n.kind==="relay"){const i=Gn(n.relay),a=await qe(Ct,i.fetch("/health").catch(()=>null));if(Pe("establish:relay:health",{ok:a?.ok===!0,status:a?.status??null}),a?.ok)return{kind:"relay",relay:n.relay,tunnel:i};i.close();continue}const o=pt(n.url)||n.url,r=await et(`${o}/health`,{method:"GET"});if(Pe("establish:direct:health",{ok:r?.ok===!0,status:r?.status??null}),!!r?.ok){if(e){const i=await r.json().catch(()=>null),a=i&&typeof i=="object"?i.serverId:null;if(typeof a=="string"&&a&&a!==e){Pe("establish:server-id-mismatch",{url:o});continue}}return{kind:"direct",url:o}}}return null},Aa=async(s,e)=>{if(!Et())return Ia(s);const n=await qe(Ht,bs("/auth/session").then(r=>r).catch(()=>null));if(!n)return!0;if(n.status===401)return!1;if(!n.ok&&n.status!==404)return!0;const o=await Qt(n);return!(o&&o.disabled!==!0&&o.authenticated===!1)},Da=s=>s.kind==="relay"?Et():!Et()&&dr(s.url,Ge()),pr=()=>{const s=Pt();return s?st().find(e=>Ee(e)===s)??null:null},wn=s=>{const e=Pt();return!!e&&Ee(s)===e},Ft=async()=>{const s=pr();if(!s)return"no-connection";let e;if(Ce()?e=s.hasToken?await Rt(Ee(s)):void 0:e=s.clientToken,!e)return"unreachable";const n=s.candidates.findIndex(c=>Da(c.kind==="relay"?{kind:"relay",relay:c.relay}:{kind:"direct",url:c.url})),o=n>=0?s.candidates.slice(0,n):s.candidates,r=await qt(o,e,{fast:!0});if(r.status==="ok")return await Kt({id:s.id,label:s.label,candidates:s.candidates}),Xe(r.transport,e,{runtimeKey:Ee(s)}),"switched";if(r.status==="needs-login")return"needs-login";if(n>=0&&await Aa({url:Ge(),clientToken:e}))return hr(),"unchanged";const i=n>=0?s.candidates.slice(n+1):[],a=await qt(i,e,{fast:!0});return a.status==="ok"?(await Kt({id:s.id,label:s.label,candidates:s.candidates}),Xe(a.transport,e,{runtimeKey:Ee(s)}),"switched"):a.status==="needs-login"?"needs-login":"unreachable"},Ma=5e3;let ss=!1;const La=async()=>{if(ss)return"skipped";const s=pr();if(!s)return Pe("candidates:refresh-skip",{reason:"no-active-connection"}),"skipped";const e=Ze(s);if(!e)return Pe("candidates:refresh-skip",{reason:"no-relay-candidate"}),"skipped";ss=!0;try{const n=await qe(Ct,bs("/api/client-auth/connection/candidates").then(u=>u).catch(()=>null));if(!n?.ok)return Pe("candidates:refresh-skip",{reason:"fetch-failed",status:n?.status??null}),"skipped";const o=await n.json().catch(()=>null);if(!o||o.serverId!==e.serverId)return Pe("candidates:refresh-skip",{reason:"server-id-mismatch"}),"skipped";const r=Array.isArray(o.candidates)?o.candidates:[],i=[];for(const u of r){if(!u||typeof u!="object")continue;const f=u;if(!(f.type!=="lan"||typeof f.url!="string"))try{const p=pt(f.url);p&&!i.includes(p)&&i.push(p)}catch{}}if(i.length===0)return Pe("candidates:refresh-skip",{reason:"no-lan-reported"}),"skipped";const a=Yt(s).filter(u=>u.url.startsWith("https://")),c=[...i.map(u=>({kind:"direct",url:u})),...a,{kind:"relay",relay:e}];return JSON.stringify(s.candidates.map(us))===JSON.stringify(c.map(us))?"unchanged":(Pe("candidates:refreshed",{lanCount:i.length}),await Kt({id:s.id,label:s.label,candidates:c}),"updated")}finally{ss=!1}},hr=()=>{typeof window>"u"||window.setTimeout(()=>{(async()=>{const s=await La().catch(()=>"skipped");Pe("candidates:refresh-result",{result:s}),s==="updated"&&Et()&&await Ft().catch(()=>null)})()},Ma)},br=s=>{const{t:e}=ue(),[n,o]=l.useState(()=>st()),[r,i]=l.useState(null),[a,c]=l.useState(null),[d,u]=l.useState(null),f=l.useRef(n),p=l.useRef(null),b=l.useRef(pa()),x=l.useCallback(w=>{f.current=w,o(w)},[]),v=l.useCallback(w=>{p.current=w,i(w)},[]),S=l.useCallback(w=>{p.current===w&&(p.current=null,i(null))},[]);l.useEffect(()=>{let w=!1;return Ra().then(C=>{w||x(C)}),()=>{w=!0}},[x]);const g=l.useCallback(w=>{const C=fr(f.current,w);return x(C),$s(C),C},[x]),I=l.useCallback(async w=>{c(null),v("connect");try{const C=yn(w);if(C.length===0){c(e("mobile.connect.error.urlRequired"));return}const y=w.id?f.current.find(z=>z.id===w.id):f.current.find(z=>Gt(z.candidates,C)),k=w.label?.trim()||y?.label||$t(He({candidates:C})),A=w.relayGrant;let R=w.clientToken?.trim()||void 0;const j=!!R;R||(Ce()?y?.hasToken&&(R=await Rt(Ee({candidates:C}))):R=y?.clientToken),Pe("connect:start",{candidates:C.map(z=>z.kind),hasToken:!!R});const V=await qt(C,R);if(Pe("connect:probe",{status:V.status}),V.status==="unreachable"){c(e("mobile.connect.error.unreachable"));return}if(V.status==="needs-login"){g({id:y?.id,label:k,candidates:C}),u({id:y?.id??crypto.randomUUID(),label:k,candidates:C,relay:Ze({candidates:C})??void 0,relayGrant:A});return}R&&j&&Ce()&&await Qe(Ee({candidates:C}),R),g({id:y?.id,label:k,candidates:C,clientToken:R}),Xe(V.transport,R??null,{runtimeKey:Ee({candidates:C}),grant:A}),s()}catch(C){console.warn("[mobile-connect] connect threw",C),c(e("mobile.connect.error.invalidUrl"))}finally{S("connect")}},[v,S,s,g,e]),P=l.useCallback(async w=>{if(p.current==="pairing")return;c(null),v("pairing");const C=_a(w.candidates);let y=null,k=!1;try{if(y=await vn(C),!y){c(e("mobile.connect.error.unreachable"));return}const A=JSON.stringify({pairingId:w.pairingId,secret:w.secret,clientLabel:"OpenChamber Mobile",clientKind:"mobile",deviceName:"OpenChamber Mobile",devicePlatform:xn(),dedupeKey:gn()}),R={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:A},j=y.kind==="relay"?await qe(Ct,y.tunnel.fetch("/api/client-auth/pairing/redeem",R).catch(()=>null)):await et(`${y.url}/api/client-auth/pairing/redeem`,R);if(!j?.ok){c(e("mobile.connect.error.authRequired"));return}const V=await j.json().catch(()=>null),z=typeof V?.clientToken=="string"?V.clientToken.trim():"";if(!z){c(e("mobile.connect.error.authRequired"));return}const h=typeof V?.server?.label=="string"?V.server.label:"",L=w.label||h||$t(He({candidates:C}));if(Ce()&&!await Qe(Ee({candidates:C}),z)){c(e("mobile.connect.error.authRequired"));return}g({label:L,candidates:C,clientToken:z}),Xe(y.kind==="relay"?{kind:"relay",relay:y.relay,tunnel:y.tunnel}:{kind:"direct",url:y.url},z,{runtimeKey:Ee({candidates:C})}),k=y.kind==="relay",s()}catch(A){console.warn("[mobile-connect] pairing threw",A),c(e("mobile.connect.error.authRequired"))}finally{!k&&y?.kind==="relay"&&y.tunnel.close(),S("pairing")}},[v,S,s,g,e]),T=l.useCallback(async w=>{if(!d||!w.trim()||p.current==="password")return;c(null),v("password");const C=b.current.begin(),y=()=>b.current.isCurrent(C),{id:k,label:A,candidates:R}=d;let j=null,V=!1;try{if(j=await vn(R),!y())return;if(!j){c(e("mobile.connect.error.unreachable"));return}const z={method:"POST",credentials:"include",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({password:w,trustDevice:!0,issueClientToken:!0,clientLabel:"OpenChamber Mobile",clientKind:"mobile",devicePlatform:xn(),dedupeKey:gn()})};Pe("password:start",{transport:j.kind});const h=j.kind==="relay"?await qe(Ct,j.tunnel.fetch("/auth/session",z).catch(()=>null)):await et(`${j.url}/auth/session`,z);if(!y())return;if(Pe("password:done",{ok:h?.ok===!0,status:h?.status??null}),!h?.ok){c(e("mobile.connect.error.passwordFailed"));return}const L=await h.json().catch(()=>null);if(!y())return;const M=typeof L?.clientToken=="string"?L.clientToken.trim():"";if(Pe("password:token",{issued:!!M}),!M){if(j.kind==="direct"&&!Ce()){g({id:k,label:A,candidates:R}),u(null),Xe({kind:"direct",url:j.url},null,{runtimeKey:Ee({candidates:R})}),s();return}c(e("mobile.connect.error.authRequired"));return}if(Ce()&&(!y()||(await Qe(Ee({candidates:R}),M),!y()))||!y()||(g({id:k,label:A,candidates:R,clientToken:M}),u(null),Xe(j.kind==="relay"?{kind:"relay",relay:j.relay,tunnel:j.tunnel}:{kind:"direct",url:j.url},M,{runtimeKey:Ee({candidates:R})}),V=j.kind==="relay",!y()))return;s()}catch(z){if(!y())return;console.warn("[mobile-connect] password threw",z),c(e("mobile.connect.error.passwordFailed"))}finally{!V&&j?.kind==="relay"&&j.tunnel.close(),y()&&S("password")}},[v,S,s,d,g,e]),N=l.useCallback(()=>{b.current.cancel(),S("password"),u(null),c(null)},[S]),E=l.useCallback(async w=>{c(null);let C=yn(w);const y=w.id?f.current.find(j=>j.id===w.id)??null:null;if(y){const j=C.filter(h=>h.kind==="direct"),V=Yt(y).filter(h=>h.url.startsWith("https://")&&!j.some(L=>dr(L.url,h.url))),z=Ze(y);C=[...j,...V,...z?[{kind:"relay",relay:z}]:[]]}if(C.length===0)return c(e("mobile.connect.error.urlRequired")),null;const k=w.clientToken?.trim()||void 0,A=w.label?.trim()||$t(He({candidates:C}));if(Ce()){const j=Ee({candidates:C});if(k)await Qe(j,k);else if(y?.hasToken){const V=Ee(y);if(V&&j&&V!==j){const z=await Rt(V);z&&await Qe(j,z)}}}return g({id:w.id,label:A,candidates:C,clientToken:k}).find(j=>Gt(j.candidates,C))??null},[g,e]),D=l.useCallback(async w=>{const C=f.current.find(k=>k.id===w)??null,y=await Pa(w);return x(y),C},[x]);return{connections:n,isBusy:r!==null,isPasswordBusy:r==="password",error:a,pendingConnection:d,connect:I,redeemPairingConnection:P,submitPassword:T,cancelPassword:N,saveConnection:E,removeConnection:D,setError:c}},gr=()=>{if(typeof window>"u")return null;const e=window.Capacitor?.Plugins?.BarcodeScanner;return e&&(typeof e.scan=="function"||typeof e.startScan=="function")?e:null},za=()=>window.Capacitor?.getPlatform?.()==="android",xr=s=>{const e=s.trim();if(!e)return null;if(/^openchamber:\/\//i.test(e)){const n=Qr(e);return n?{pairing:n}:null}return/^https?:\/\//i.test(e)?{url:e}:null},yr=s=>{const e=xr(s);return e?"pairing"in e?{status:"pairing",...e}:{status:"ok",...e}:{status:"invalid"}},Oa=async(s,e)=>{if(!s.startScan||!s.stopScan||!s.addListener)return{status:"unsupported"};if(e?.aborted)return{status:"cancelled"};let n,o,r=!1,i=()=>{};const a=new Promise(u=>{i=u}),c=u=>{r||(r=!0,i(u))},d=()=>c({status:"cancelled"});e?.addEventListener("abort",d,{once:!0});try{return(await Promise.allSettled([Promise.resolve(s.addListener("barcodesScanned",({barcodes:f})=>{const p=f?.[0],b=(p?.rawValue??p?.displayValue??"").trim();b&&c(yr(b))})).then(f=>{n=f}),Promise.resolve(s.addListener("scanError",()=>c({status:"failed"}))).then(f=>{o=f})])).some(({status:f})=>f==="rejected")?c({status:"failed"}):r||s.startScan({formats:["QR_CODE"]}).catch(()=>c({status:"failed"})),await a}finally{e?.removeEventListener("abort",d),await Promise.allSettled([Promise.resolve(n?.remove()),Promise.resolve(o?.remove()),s.stopScan()])}},fs=()=>gr()!==null,vr=async s=>{const e=gr();if(!e)return{status:"unsupported"};try{if(e.requestPermissions){const a=(await e.requestPermissions())?.camera;if(a&&a!=="granted"&&a!=="limited")return{status:"permission-denied"}}if(s?.signal?.aborted)return{status:"cancelled"};if(za())return Oa(e,s?.signal);if(!e.scan)return{status:"unsupported"};const o=(await e.scan({formats:["QR_CODE"]}))?.barcodes?.[0],r=(o?.rawValue??o?.displayValue??"").trim();return r?yr(r):{status:"cancelled"}}catch{return{status:"failed"}}},lt={autoComplete:"off",autoCorrect:"off",spellCheck:!1},vt="h-12 w-full rounded-[16px] border border-border/70 bg-surface-elevated px-4 text-[16px] text-foreground outline-none transition-colors placeholder:text-muted-foreground focus:border-primary focus:ring-2 focus:ring-primary/20",wr=s=>{const e=de.c(22),{onCancel:n}=s,{t:o}=ue(),r=l.useRef(null);let i,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{const I={value:document.documentElement.style.getPropertyValue("background-color"),priority:document.documentElement.style.getPropertyPriority("background-color")},P={value:document.body.style.getPropertyValue("background-color"),priority:document.body.style.getPropertyPriority("background-color")};document.documentElement.style.setProperty("background-color","rgba(0, 0, 0, 0)","important"),document.body.style.setProperty("background-color","rgba(0, 0, 0, 0)","important");const T=new Map,N=D=>{!(D instanceof HTMLElement)||D===r.current||T.has(D)||(T.set(D,{opacity:D.style.opacity,pointerEvents:D.style.pointerEvents}),D.style.setProperty("opacity","0"),D.style.setProperty("pointer-events","none"))};Array.from(document.body.children).forEach(N);const E=new MutationObserver(D=>{D.forEach(w=>w.addedNodes.forEach(N))});return E.observe(document.body,{childList:!0}),()=>{E.disconnect(),T.forEach(Ba),I.value?document.documentElement.style.setProperty("background-color",I.value,I.priority):document.documentElement.style.removeProperty("background-color"),P.value?document.body.style.setProperty("background-color",P.value,P.priority):document.body.style.removeProperty("background-color")}},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),l.useLayoutEffect(i,a);let c,d;e[2]!==n?(c=()=>{const I=()=>{document.visibilityState==="hidden"&&n()};return document.addEventListener("visibilitychange",I),()=>document.removeEventListener("visibilitychange",I)},d=[n],e[2]=n,e[3]=c,e[4]=d):(c=e[3],d=e[4]),l.useEffect(c,d);let u;e[5]!==o?(u=o("mobile.connect.scanQr"),e[5]=o,e[6]=u):u=e[6];let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("div",{className:"aspect-square w-full max-w-72 rounded-[28px] border-2 border-foreground/90 shadow-[0_0_0_9999px_color-mix(in_srgb,var(--surface-background)_18%,transparent)]","aria-hidden":!0}),e[7]=f):f=e[7];let p;e[8]!==o?(p=o("mobile.connect.welcome.scanHint"),e[8]=o,e[9]=p):p=e[9];let b;e[10]!==p?(b=t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-6",children:[f,t.jsx("p",{className:"max-w-sm rounded-[16px] border border-border/60 bg-background px-4 py-3 text-center typography-body text-foreground shadow-sm",children:p})]}),e[10]=p,e[11]=b):b=e[11];let x;e[12]===Symbol.for("react.memo_cache_sentinel")?(x=t.jsx(se,{name:"close",className:"size-[18px]"}),e[12]=x):x=e[12];let v;e[13]!==o?(v=o("mobile.instances.cancelEdit"),e[13]=o,e[14]=v):v=e[14];let S;e[15]!==n||e[16]!==v?(S=t.jsxs(ge,{type:"button",variant:"outline",size:"lg",className:"mx-auto min-h-12 w-full max-w-sm bg-background",onClick:n,children:[x,v]}),e[15]=n,e[16]=v,e[17]=S):S=e[17];let g;return e[18]!==S||e[19]!==u||e[20]!==b?(g=ct.createPortal(t.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-label":u,className:"fixed inset-0 z-[1000] flex flex-col bg-transparent px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+24px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+24px)] text-foreground",children:[b,S]}),document.body),e[18]=S,e[19]=u,e[20]=b,e[21]=g):g=e[21],g},jr=()=>{const s=de.c(6),{t:e}=ue();let n;s[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx(Je,{width:96,height:96,isAnimated:!0}),s[0]=n):n=s[0];let o;s[1]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx(se,{name:"loader-4",className:"size-[18px] animate-spin"}),s[1]=o):o=s[1];let r;s[2]!==e?(r=e("mobile.connect.connecting"),s[2]=e,s[3]=r):r=s[3];let i;return s[4]!==r?(i=ct.createPortal(t.jsxs("div",{role:"status",className:"fixed inset-0 z-[1000] flex flex-col items-center justify-center gap-5 bg-background px-6 text-foreground",children:[n,t.jsxs("div",{className:"flex items-center gap-2 typography-ui-label text-muted-foreground",children:[o,t.jsx("span",{children:r})]})]}),document.body),s[4]=r,s[5]=i):i=s[5],i};function Ba(s,e){e.style.opacity=s.opacity,e.style.pointerEvents=s.pointerEvents}const $a=({onConnected:s,notice:e=null})=>{const{t:n}=ue(),o=br(s),{connections:r,isBusy:i,isPasswordBusy:a,error:c,pendingConnection:d}=o,[u,f]=l.useState(""),[p,b]=l.useState(""),[x,v]=l.useState(""),[S,g]=l.useState(!1),[I,P]=l.useState(!1),T=l.useRef(null),N=l.useMemo(()=>fs(),[]),[E,D]=l.useState(()=>!fs()),[w,C]=l.useState(null),[y,k]=l.useState(""),A=l.useCallback(h=>{h.preventDefault(),o.connect({url:u,clientToken:x,label:p})},[x,o,p,u]),R=l.useCallback(h=>{if(/^openchamber:\/\//i.test(h.trim())){const L=xr(h);if(L){if("pairing"in L){o.redeemPairingConnection(L.pairing);return}f(L.url),L.label&&b(L.label),L.clientToken&&v(L.clientToken);return}}f(h)},[o]),j=l.useCallback(async()=>{if(T.current||i)return;o.setError(null),g(!0);const h=new AbortController;T.current=h;try{const L=await vr({signal:h.signal});switch(T.current===h&&(T.current=null,g(!1)),L.status){case"ok":P(!0),f(L.url),L.label&&b(L.label),L.clientToken&&v(L.clientToken),await o.connect({url:L.url,clientToken:L.clientToken,label:L.label});break;case"pairing":P(!0),await o.redeemPairingConnection(L.pairing);break;case"permission-denied":o.setError(n("mobile.connect.scan.permissionDenied"));break;case"invalid":o.setError(n("mobile.connect.scan.invalid"));break;case"unsupported":o.setError(n("mobile.connect.scan.unsupported"));break;case"failed":o.setError(n("mobile.connect.scan.failed"));break;default:break}}finally{P(!1),T.current===h&&(T.current=null,g(!1))}},[o,i,n]);l.useEffect(()=>()=>T.current?.abort(),[]);const V=l.useCallback(h=>{h.preventDefault(),o.submitPassword(y)},[o,y]),z=l.useCallback(()=>{k(""),o.cancelPassword()},[o]);return t.jsxs(t.Fragment,{children:[S?t.jsx(wr,{onCancel:()=>T.current?.abort()}):null,I?t.jsx(jr,{}):null,t.jsx("main",{className:"oc-keyboard-fill-screen flex min-h-dvh flex-col overflow-y-auto bg-background px-6 pb-[calc(var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px))+28px)] pt-[calc(var(--safe-area-inset-top,env(safe-area-inset-top,0px))+28px)] text-foreground",children:t.jsxs("div",{className:"m-auto flex w-full max-w-[360px] shrink-0 flex-col items-center gap-9 py-8",children:[t.jsxs("div",{className:"flex flex-col items-center gap-5 text-center",children:[t.jsx(Je,{width:72,height:72,className:"size-[72px]"}),t.jsx("h1",{className:"typography-h2 text-foreground",children:n("mobile.connect.welcome.title")})]}),e?t.jsxs("div",{role:"status",className:"flex w-full items-center gap-3 rounded-[18px] border border-[color-mix(in_srgb,var(--status-warning)_35%,transparent)] bg-[color-mix(in_srgb,var(--status-warning)_10%,transparent)] px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-[color-mix(in_srgb,var(--status-warning)_16%,transparent)] text-[var(--status-warning)]",children:t.jsx(se,{name:e.kind==="auth-expired"?"lock":"cloud-off",className:"size-[18px]"})}),t.jsx("p",{className:"min-w-0 flex-1 typography-small text-foreground",children:e.kind==="auth-expired"?n("mobile.connect.notice.authExpired",{label:e.label}):n("mobile.connect.notice.unreachable",{label:e.label})})]}):null,d?t.jsxs("form",{className:"flex w-full flex-col gap-3",onSubmit:V,children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(se,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0 text-left",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(h=>h.kind==="direct")?He(d):n("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...lt,value:y,onChange:h=>k(h.target.value),placeholder:n("mobile.connect.password.placeholder"),"aria-label":n("mobile.connect.password.label"),type:"password",autoFocus:!0,className:vt}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!y.trim(),children:n(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:z,children:n("mobile.connect.cancelPassword")})]}):t.jsxs("div",{className:"flex w-full flex-col gap-6",children:[N?t.jsxs("div",{className:"flex w-full flex-col gap-2",children:[t.jsxs(ge,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{j()},disabled:S||i,children:[t.jsx(se,{name:"scan-2",className:te("size-[18px]",S&&"animate-pulse")}),n(i?"mobile.connect.connecting":"mobile.connect.scanQr")]}),t.jsx("p",{className:"px-2 text-center typography-small text-muted-foreground",children:n("mobile.connect.welcome.scanHint")})]}):null,c&&!E?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,r.length>0?t.jsxs("section",{className:"flex w-full flex-col gap-2.5",children:[t.jsx("h2",{className:"text-center typography-micro uppercase tracking-[0.14em] text-muted-foreground",children:n("mobile.connect.saved.title")}),t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(h=>{const L=w===h.id;return t.jsxs("button",{type:"button",disabled:i,className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3.5 py-2.5 text-left last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-70",onClick:()=>{C(h.id),o.connect({id:h.id,candidates:h.candidates,clientToken:h.clientToken,label:h.label}).finally(()=>C(null))},children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(se,{name:"server",className:"size-[18px]"})}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:h.label}),t.jsx("span",{className:te("block truncate typography-small",L?"text-foreground":"text-muted-foreground"),children:L?n("mobile.connect.connecting"):h.candidates.some(M=>M.kind==="direct")?He(h):n("mobile.connect.relay.badge")})]}),L?t.jsx(se,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(se,{name:"arrow-right-s",className:"size-5 text-muted-foreground"})]},h.id)})})]}):null,t.jsxs("div",{className:"flex w-full flex-col",children:[N?t.jsxs("button",{type:"button",onClick:()=>D(h=>!h),"aria-expanded":E,className:"mx-auto flex items-center gap-1 rounded-full px-2 py-1 typography-small text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:[t.jsx("span",{children:n("mobile.connect.manual.toggle")}),t.jsx(se,{name:"arrow-down-s",className:te("size-4 transition-transform duration-200",E&&"rotate-180")})]}):null,t.jsx("div",{className:"grid transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:E?"1fr":"0fr"},children:t.jsx("div",{className:"min-h-0 overflow-hidden",children:t.jsxs("form",{className:"flex w-full flex-col gap-3 pt-3",onSubmit:A,children:[t.jsx("input",{...lt,value:u,onChange:h=>R(h.target.value),placeholder:n("mobile.connect.url.placeholder"),"aria-label":n("mobile.connect.url.label"),type:"url",inputMode:"url",autoCapitalize:"none",tabIndex:E?void 0:-1,className:te(vt,"text-center")}),t.jsx("input",{value:p,onChange:h=>b(h.target.value),placeholder:n("mobile.instances.label.placeholder"),"aria-label":n("mobile.instances.label.label"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,tabIndex:E?void 0:-1,className:te(vt,"text-center")}),t.jsx("input",{...lt,value:x,onChange:h=>v(h.target.value),placeholder:n("mobile.connect.token.placeholder"),"aria-label":n("mobile.connect.token.label"),tabIndex:E?void 0:-1,autoCapitalize:"none",className:te(vt,"text-center")}),t.jsx("p",{className:"px-1 text-center typography-micro text-muted-foreground",children:n("mobile.connect.token.hint")}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",variant:N?"outline":"default",size:"lg",className:"h-12 w-full",disabled:i||S||!u.trim(),children:n(i?"mobile.connect.connecting":"mobile.connect.connectButton")})]})})})]})]})]})})]})},jn=380,Fa=(s,e)=>{if(!s||typeof s!="object")return;const n=s[e];return typeof n=="number"&&Number.isFinite(n)?n:void 0},gt=s=>typeof s=="number"&&Number.isFinite(s)?s:0,kn=s=>s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:String(s),Wa=s=>{const e=s.usedPercent;return typeof e!="number"||!Number.isFinite(e)?"text-foreground":e>=80?"text-[var(--status-error)]":e>=50?"text-[var(--status-warning)]":"text-foreground"},kr=s=>{const e=de.c(19),{percentage:n}=s;let o,r,i,a,c,d,u;if(e[0]!==n){i=ao(n)??0;const v=lo(n);r=v==="critical"?"var(--status-error)":v==="warn"?"var(--status-warning)":"var(--status-success)",o=2*Math.PI*7.5,a="0 0 18 18",c="size-[18px] -rotate-90",d="progressbar",u=Math.round(i),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=a,e[5]=c,e[6]=d,e[7]=u}else o=e[1],r=e[2],i=e[3],a=e[4],c=e[5],d=e[6],u=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:"var(--interactive-border)",strokeWidth:3}),e[8]=f):f=e[8];const p=o*(1-i/100);let b;e[9]!==o||e[10]!==r||e[11]!==p?(b=t.jsx("circle",{cx:9,cy:9,r:7.5,fill:"none",stroke:r,strokeWidth:3,strokeLinecap:"round",strokeDasharray:o,strokeDashoffset:p,className:"transition-[stroke-dashoffset,stroke] duration-300"}),e[9]=o,e[10]=r,e[11]=p,e[12]=b):b=e[12];let x;return e[13]!==a||e[14]!==c||e[15]!==d||e[16]!==u||e[17]!==b?(x=t.jsxs("svg",{viewBox:a,className:c,role:d,"aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,children:[f,b]}),e[13]=a,e[14]=c,e[15]=d,e[16]=u,e[17]=b,e[18]=x):x=e[18],x},Ua=s=>{const e=de.c(13),{icon:n,iconNode:o,label:r,children:i}=s;let a;e[0]!==n||e[1]!==o?(a=o??(n?t.jsx(se,{name:n,className:"size-[18px]"}):null),e[0]=n,e[1]=o,e[2]=a):a=e[2];let c;e[3]!==a?(c=t.jsx("span",{className:"flex size-5 shrink-0 items-center justify-center text-muted-foreground",children:a}),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==r?(d=t.jsx("span",{className:"shrink-0 typography-ui-label text-muted-foreground",children:r}),e[5]=r,e[6]=d):d=e[6];let u;e[7]!==i?(u=t.jsx("span",{className:"min-w-0 flex-1 truncate text-right typography-ui-label font-medium text-foreground",children:i}),e[7]=i,e[8]=u):u=e[8];let f;return e[9]!==c||e[10]!==d||e[11]!==u?(f=t.jsxs("div",{className:"flex min-w-0 items-center gap-3 rounded-xl px-2.5 py-2.5",children:[c,d,u]}),e[9]=c,e[10]=d,e[11]=u,e[12]=f):f=e[12],f},Va=s=>{const e=de.c(49),{open:n,onClose:o,anchorRef:r,contextDisplay:i,usageGroups:a,usageDisplayMode:c,isUsageLoading:d,timeFormatPreference:u}=s,{t:f}=ue(),p=l.useRef(null),[b,x]=l.useState(n),[v,S]=l.useState(!1),{enabled:g}=ys(),I=l.useRef(null),[P,T]=l.useState(null);let N,E;e[0]!==r||e[1]!==g||e[2]!==n||e[3]!==b?(N=()=>{if(!n||!g||!b)return;const F=()=>{const ee=r.current?.getBoundingClientRect(),W=I.current?.getBoundingClientRect();if(!ee||!W){T(null);return}const oe=ee.left-W.left,ie=Math.min(Math.max(oe,8),Math.max(8,W.width-jn-8));T(ie)};F();const U=I.current;if(typeof ResizeObserver>"u"||!U)return;const X=new ResizeObserver(F);return X.observe(U),()=>X.disconnect()},E=[r,g,n,b],e[0]=r,e[1]=g,e[2]=n,e[3]=b,e[4]=N,e[5]=E):(N=e[4],E=e[5]),l.useLayoutEffect(N,E);const D=g&&P!==null;let w,C;e[6]!==n||e[7]!==b?(w=()=>{if(n){x(!0),S(!1);return}if(!b)return;S(!0);const F=window.setTimeout(()=>{x(!1),S(!1)},140);return()=>window.clearTimeout(F)},C=[n,b],e[6]=n,e[7]=b,e[8]=w,e[9]=C):(w=e[8],C=e[9]),l.useEffect(w,C);let y,k;e[10]!==o||e[11]!==n?(y=()=>{if(!n)return;const F=U=>{U.key==="Escape"&&o()};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},k=[o,n],e[10]=o,e[11]=n,e[12]=y,e[13]=k):(y=e[12],k=e[13]),l.useEffect(y,k);let A,R;if(e[14]!==r||e[15]!==o||e[16]!==n?(A=()=>{if(!n)return;const F=U=>{const X=U.target;if(!(X instanceof Node)){o();return}p.current?.contains(X)||r.current?.contains(X)||o()};return document.addEventListener("pointerdown",F,!0),document.addEventListener("wheel",F,!0),()=>{document.removeEventListener("pointerdown",F,!0),document.removeEventListener("wheel",F,!0)}},R=[r,o,n],e[14]=r,e[15]=o,e[16]=n,e[17]=A,e[18]=R):(A=e[17],R=e[18]),l.useEffect(A,R),!b)return null;let j;e[19]!==f?(j=f("mobile.header.openMetadataAria"),e[19]=f,e[20]=j):j=e[20];const V=D?"absolute origin-top-left":"mx-3 mt-2",z=v?"pointer-events-none":"pointer-events-auto";let h;e[21]!==V||e[22]!==z?(h=te("overflow-y-auto overscroll-contain rounded-[20px] border border-border/70 bg-[var(--surface-elevated)] p-2 shadow-[0_12px_32px_rgb(0_0_0_/_0.2)] will-change-transform",V,z),e[21]=V,e[22]=z,e[23]=h):h=e[23];const L=`${v?"session-metadata-out":"session-metadata-in"} ${v?140:170}ms cubic-bezier(0.32, 0.72, 0, 1) forwards`;let M;e[24]!==P||e[25]!==D?(M=D?{top:8,left:P??8,width:`min(${jn}px, calc(100% - 16px))`}:null,e[24]=P,e[25]=D,e[26]=M):M=e[26];let B;e[27]!==L||e[28]!==M?(B={animation:L,maxHeight:"min(72dvh, calc(100dvh - var(--oc-safe-area-top, 0px) - var(--oc-header-height, 56px) - 1rem))",...M},e[27]=L,e[28]=M,e[29]=B):B=e[29];let H;e[30]!==i||e[31]!==f?(H=i?t.jsx(Ua,{iconNode:t.jsx(kr,{percentage:i.percentage}),label:f("mobile.header.metadata.context"),children:t.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.jsxs("span",{className:te("font-semibold",i.colorClass),children:[i.percentage.toFixed(1),"%"]}),t.jsx("span",{className:"text-muted-foreground",children:i.tokens})]})}):null,e[30]=i,e[31]=f,e[32]=H):H=e[32];let Z;e[33]!==d||e[34]!==u||e[35]!==c||e[36]!==a?(Z=t.jsx(Ha,{groups:a,displayMode:c,isLoading:d,timeFormatPreference:u}),e[33]=d,e[34]=u,e[35]=c,e[36]=a,e[37]=Z):Z=e[37];let Q;e[38]!==H||e[39]!==Z?(Q=t.jsxs("div",{className:"space-y-1",children:[H,Z]}),e[38]=H,e[39]=Z,e[40]=Q):Q=e[40];let _;e[41]!==h||e[42]!==B||e[43]!==Q||e[44]!==j?(_=t.jsx("div",{ref:p,role:"dialog","aria-label":j,className:h,style:B,children:Q}),e[41]=h,e[42]=B,e[43]=Q,e[44]=j,e[45]=_):_=e[45];let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J=t.jsx("style",{children:`
|
|
3
3
|
@keyframes session-metadata-in {
|
|
4
4
|
from { opacity: 0; transform: translateY(-8px) scale(0.985); }
|
|
5
5
|
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
@@ -20,4 +20,4 @@ import{f as de,r as ls,j as t,R as l,c as ct,h as Yr}from"./vendor-react-BUCujlK
|
|
|
20
20
|
`}),e[47]=q):q=e[47];let F;return e[48]!==J?(F=t.jsxs("div",{ref:b,className:"fixed inset-x-0 bottom-0 top-[calc(var(--oc-safe-area-top,0px)+var(--oc-header-height,56px))] z-20 pointer-events-none",children:[J,q]}),e[48]=J,e[49]=F):F=e[49],F};function Qa(s){return s.currentSessionId}function Xa(s){return s.setCurrentSession}function Za(s){return s.setActiveProjectIdOnly}const el=s=>{const e=de.c(71),{onOpenSessions:n,onOpenWorkspace:o,compactTitle:r}=s,i=r===void 0?!1:r,{t:a}=ue(),[c,d]=l.useState(!1),[u,f]=l.useState(!1),p=l.useRef(null),b=dt(tl),x=ve(sl);let v;e[0]!==x?(v=ke=>x?ke.getDirectoryForSession(x):null,e[0]=x,e[1]=v):v=e[1];const g=ve(v)||b,I=ho(x,g||void 0),P=ve(nl);let T;e[2]!==I?.title?(T=I?.title?.trim(),e[2]=I?.title,e[3]=T):T=e[3];const N=T;let E;e[4]!==x||e[5]!==N||e[6]!==a?(E=N||a(x?"mobile.sessions.untitled":"sessions.switcher.draftTitle"),e[4]=x,e[5]=N,e[6]=a,e[7]=E):E=e[7];const D=E;let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{d(!1),f(!1)},e[8]=w):w=e[8];let C;e[9]!==x||e[10]!==g?(C=[x,g],e[9]=x,e[10]=g,e[11]=C):C=e[11],l.useEffect(w,C);let y;e[12]!==n?(y=()=>{d(!1),f(!1),n()},e[12]=n,e[13]=y):y=e[13];const k=y;let A;e[14]===Symbol.for("react.memo_cache_sentinel")?(A=ke=>{d(_e=>{const be=typeof ke=="function"?ke(_e):ke;return be&&f(!1),be})},e[14]=A):A=e[14];const R=A;let j;e[15]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{f(ke=>{const _e=!ke;return _e&&d(!1),_e})},e[15]=j):j=e[15];const V=j;let z;e[16]===Symbol.for("react.memo_cache_sentinel")?(z={paddingTop:"var(--oc-safe-area-top, 0px)"},e[16]=z):z=e[16];let h;e[17]!==a?(h=a("mobile.sessions.openSheetAria"),e[17]=a,e[18]=h):h=e[18];let L,M;e[19]===Symbol.for("react.memo_cache_sentinel")?(L={touchAction:"manipulation"},M=t.jsx(se,{name:"list-unordered",className:"size-5"}),e[19]=L,e[20]=M):(L=e[19],M=e[20]);let B;e[21]!==k||e[22]!==h?(B=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":h,onClick:k,style:L,children:M}),e[21]=k,e[22]=h,e[23]=B):B=e[23];const H=i?"shrink":"flex-1";let Z;e[24]!==H?(Z=te("flex min-w-0 items-center rounded-lg px-2 py-1.5 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",H),e[24]=H,e[25]=Z):Z=e[25];let Q;e[26]!==a?(Q=a("sessions.switcher.openAria"),e[26]=a,e[27]=Q):Q=e[27];let _;e[28]===Symbol.for("react.memo_cache_sentinel")?(_={touchAction:"manipulation"},e[28]=_):_=e[28];let J;e[29]!==D?(J=t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",children:D}),e[29]=D,e[30]=J):J=e[30];const q=u&&"rotate-180";let F;e[31]!==q?(F=te("size-4 shrink-0 text-muted-foreground transition-transform duration-150",q),e[31]=q,e[32]=F):F=e[32];let U;e[33]!==F?(U=t.jsx(se,{name:"arrow-down-s",className:F}),e[33]=F,e[34]=U):U=e[34];let X;e[35]!==J||e[36]!==U?(X=t.jsxs("span",{className:"flex min-w-0 items-center gap-1",children:[J,U]}),e[35]=J,e[36]=U,e[37]=X):X=e[37];let ee;e[38]!==u||e[39]!==Z||e[40]!==Q||e[41]!==X?(ee=t.jsx("button",{ref:p,type:"button",className:Z,"aria-label":Q,"aria-haspopup":"dialog","aria-expanded":u,onClick:V,style:_,children:X}),e[38]=u,e[39]=Z,e[40]=Q,e[41]=X,e[42]=ee):ee=e[42];let W;e[43]!==i?(W=i?t.jsx("div",{className:"min-w-0 flex-1"}):null,e[43]=i,e[44]=W):W=e[44];let oe;e[45]!==x||e[46]!==g||e[47]!==P||e[48]!==c?(oe=t.jsx(Ga,{open:c,onOpenChange:R,currentSessionId:x,effectiveDirectory:g,isNewSessionDraftOpen:P}),e[45]=x,e[46]=g,e[47]=P,e[48]=c,e[49]=oe):oe=e[49];let ie;e[50]!==a?(ie=a("mobile.header.openWorkspaceAria"),e[50]=a,e[51]=ie):ie=e[51];let fe;e[52]!==o?(fe=()=>{d(!1),f(!1),o()},e[52]=o,e[53]=fe):fe=e[53];let je,Y;e[54]===Symbol.for("react.memo_cache_sentinel")?(je={touchAction:"manipulation"},Y=t.jsx(se,{name:"pencil-ruler-2",className:"size-5"}),e[54]=je,e[55]=Y):(je=e[54],Y=e[55]);let ce;e[56]!==ie||e[57]!==fe?(ce=t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":ie,onClick:fe,style:je,children:Y}),e[56]=ie,e[57]=fe,e[58]=ce):ce=e[58];let Se;e[59]!==B||e[60]!==ee||e[61]!==W||e[62]!==oe||e[63]!==ce?(Se=t.jsx("header",{className:"oc-mobile-header relative z-30 flex shrink-0 items-center gap-1 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80",style:z,children:t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] w-full items-center gap-1 px-2",children:[B,ee,W,oe,ce]})}),e[59]=B,e[60]=ee,e[61]=W,e[62]=oe,e[63]=ce,e[64]=Se):Se=e[64];let Ae;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ae=()=>f(!1),e[65]=Ae):Ae=e[65];let Re;e[66]!==u?(Re=t.jsx(Ja,{open:u,onClose:Ae,anchorRef:p}),e[66]=u,e[67]=Re):Re=e[67];let Ie;return e[68]!==Se||e[69]!==Re?(Ie=t.jsxs(t.Fragment,{children:[Se,Re]}),e[68]=Se,e[69]=Re,e[70]=Ie):Ie=e[70],Ie};function tl(s){return s.currentDirectory}function sl(s){return s.currentSessionId}function nl(s){return!!s.newSessionDraft?.open}const rl=({onActiveConnectionDeleted:s,onConnect:e})=>{const{t:n}=ue(),o=br(e),{connections:r,isBusy:i,isPasswordBusy:a,error:c,pendingConnection:d,connect:u,submitPassword:f,cancelPassword:p,saveConnection:b,removeConnection:x,setError:v}=o,[S,g]=l.useState(null),I=S?r.find(W=>W.id===S)??null:null,[P,T]=l.useState(null),[N,E]=l.useState(""),[D,w]=l.useState(""),[C,y]=l.useState(""),[k,A]=l.useState(""),[R,j]=l.useState(!1),[V,z]=l.useState(!1),h=l.useRef(null),L=l.useMemo(()=>fs(),[]),[M,B]=l.useState(!1),[H,Z]=l.useState(null),Q=l.useCallback(()=>{g(null),E(""),w(""),y(""),v(null),B(!1)},[v]),_=l.useCallback(W=>{W.preventDefault(),b({id:S??void 0,url:N,label:D,clientToken:C}).then(oe=>{oe&&Q()})},[C,S,D,Q,b,N]),J=l.useCallback(async()=>{if(h.current)return;v(null),j(!0);const W=new AbortController;h.current=W;try{const oe=await vr({signal:W.signal});switch(h.current===W&&(h.current=null,j(!1)),oe.status){case"ok":E(oe.url),oe.label&&w(oe.label),oe.clientToken&&y(oe.clientToken),B(!0);break;case"pairing":z(!0),await o.redeemPairingConnection(oe.pairing);break;case"permission-denied":v(n("mobile.connect.scan.permissionDenied"));break;case"invalid":v(n("mobile.connect.scan.invalid"));break;case"unsupported":v(n("mobile.connect.scan.unsupported"));break;case"failed":v(n("mobile.connect.scan.failed"));break;default:break}}finally{z(!1),h.current===W&&(h.current=null,j(!1))}},[o,v,n]);l.useEffect(()=>()=>h.current?.abort(),[]);const q=l.useCallback(W=>{W.preventDefault(),f(k)},[k,f]),F=l.useCallback(()=>{A(""),p()},[p]),U=l.useCallback(W=>{T(oe=>oe===W?null:W)},[]),X=l.useCallback(W=>{T(null),S===W&&Q();const oe=r.length===1;x(W).then(ie=>{ie&&(oe||wn(ie))&&s()})},[r.length,S,s,x,Q]),ee=vt;return d?t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("form",{className:"flex-1 overflow-y-auto px-5 py-4",onSubmit:q,children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-[18px] border border-border/70 bg-surface-elevated px-3.5 py-3",children:[t.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:t.jsx(se,{name:"lock",className:"size-[18px]"})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate typography-ui-label text-foreground",children:d.label}),t.jsx("p",{className:"truncate typography-small text-muted-foreground",children:d.candidates.some(W=>W.kind==="direct")?He(d):n("mobile.connect.relay.badge")})]})]}),t.jsx("input",{...lt,value:k,onChange:W=>A(W.target.value),placeholder:n("mobile.connect.password.placeholder"),"aria-label":n("mobile.connect.password.label"),type:"password",autoFocus:!0,className:ee}),c?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",disabled:a||!k.trim(),children:n(a?"mobile.connect.connecting":"mobile.connect.unlockButton")}),t.jsx(ge,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:F,children:n("mobile.connect.cancelPassword")})]})})}):t.jsxs(t.Fragment,{children:[R?t.jsx(wr,{onCancel:()=>h.current?.abort()}):null,V?t.jsx(jr,{}):null,t.jsx("div",{className:"flex h-full flex-col overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:t.jsxs("div",{className:"space-y-6",children:[r.length>0?t.jsx("div",{className:"overflow-hidden rounded-[18px] border border-border/70 bg-surface-elevated",children:r.map(W=>{const oe=P===W.id,ie=wn(W),fe=H===W.id,je=fe?n("mobile.connect.connecting"):ie?Et()?n("mobile.instances.status.connectedRelay"):n("mobile.instances.status.connectedDirect"):W.candidates.some(Y=>Y.kind==="direct")?He(W):n("mobile.connect.relay.badge");return t.jsxs("div",{className:te("flex items-center border-b border-border/70 transition-colors last:border-b-0",oe&&"bg-[color-mix(in_srgb,var(--destructive)_8%,transparent)]"),children:[t.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 px-3.5 py-3 text-left transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary disabled:opacity-60",onClick:()=>{ie||(Z(W.id),u({id:W.id,candidates:W.candidates,clientToken:W.clientToken,label:W.label}).finally(()=>Z(null)))},disabled:i&&!fe||oe,children:[t.jsxs("span",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-[12px] bg-interactive-hover text-foreground",children:[t.jsx(se,{name:"server",className:"size-[18px]"}),ie?t.jsx("span",{className:"absolute -right-0.5 -top-0.5 size-2.5 rounded-full border-2 border-[var(--surface-elevated)] bg-[var(--status-success)]","aria-hidden":!0}):null]}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate typography-ui-label text-foreground",children:W.label}),t.jsx("span",{className:te("block truncate typography-small",ie&&!fe?"text-[var(--status-success)]":"text-muted-foreground"),children:je})]}),fe?t.jsx(se,{name:"loader-4",className:"size-5 shrink-0 animate-spin text-muted-foreground"}):null]}),t.jsxs("div",{className:"flex items-center gap-0.5 pr-2",children:[oe?t.jsxs("button",{type:"button","aria-label":n("mobile.instances.confirmDeleteAria",{label:W.label}),className:"flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-destructive px-3 text-destructive-foreground transition-opacity active:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive",onClick:()=>X(W.id),style:{touchAction:"manipulation"},children:[t.jsx(se,{name:"delete-bin",className:"size-[18px]"}),t.jsx("span",{className:"typography-ui-label",children:n("mobile.instances.delete")})]}):W.candidates.some(Y=>Y.kind==="direct")?t.jsx("button",{type:"button","aria-label":n("mobile.instances.edit"),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>{g(W.id),E(He(W)),w(W.label),y(W.clientToken||""),v(null)},style:{touchAction:"manipulation"},children:t.jsx(se,{name:"edit",className:"size-[18px]"})}):null,t.jsx("button",{type:"button","aria-label":oe?n("mobile.instances.cancelDeleteAria",{label:W.label}):n("mobile.instances.deleteAria",{label:W.label}),className:"flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors active:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>U(W.id),style:{touchAction:"manipulation"},children:t.jsx(se,{name:oe?"close":"delete-bin",className:"size-[18px]"})})]})]},W.id)})}):t.jsx("p",{className:"rounded-[18px] border border-dashed border-border/70 px-4 py-6 text-center typography-small text-muted-foreground",children:n("mobile.connect.saved.empty")}),!M&&!I?t.jsxs("div",{className:"space-y-2",children:[L?t.jsxs(ge,{type:"button",size:"lg",className:"h-12 w-full",onClick:()=>{J()},disabled:R,children:[t.jsx(se,{name:"scan-2",className:te("size-[18px]",R&&"animate-pulse")}),n("mobile.connect.scanQr")]}):null,t.jsxs(ge,{type:"button",variant:L?"ghost":"outline",size:"lg",className:"h-12 w-full",onClick:()=>{v(null),B(!0)},children:[t.jsx(se,{name:"add",className:"size-[18px]"}),n("mobile.instances.addManual")]}),c?t.jsx("p",{className:"px-1 text-center typography-small text-[var(--status-error)]",children:c}):null]}):t.jsxs("form",{className:"space-y-3",onSubmit:_,children:[t.jsxs("div",{className:"flex h-8 items-center justify-between gap-3 px-1",children:[t.jsx("h3",{className:"typography-ui-label text-foreground",children:n(I?"mobile.instances.editTitle":"mobile.instances.addTitle")}),t.jsx(ge,{type:"button",variant:"ghost",size:"xs",onClick:Q,children:n("mobile.instances.cancelEdit")})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:n("mobile.connect.url.label")}),t.jsx("input",{...lt,value:N,onChange:W=>E(W.target.value),placeholder:n("mobile.connect.url.placeholder"),type:"url",inputMode:"url",autoCapitalize:"none",className:ee})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:n("mobile.instances.label.label")}),t.jsx("input",{value:D,onChange:W=>w(W.target.value),placeholder:n("mobile.instances.label.placeholder"),autoComplete:"off",autoCapitalize:"words",autoCorrect:"off",spellCheck:!1,className:ee})]}),t.jsxs("label",{className:"block space-y-1.5",children:[t.jsx("span",{className:"block px-1 typography-ui-label text-foreground",children:n("mobile.connect.token.label")}),t.jsx("input",{...lt,value:C,onChange:W=>y(W.target.value),placeholder:n("mobile.connect.token.placeholder"),autoCapitalize:"none",className:ee}),t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:n("mobile.connect.token.hint")})]}),c?t.jsx("p",{className:"px-1 typography-small text-[var(--status-error)]",children:c}):null,t.jsx(ge,{type:"submit",size:"lg",className:"mt-1 h-12 w-full",children:n(I?"mobile.instances.saveEdit":"mobile.instances.saveNew")})]})]})})})]})},we=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),ns=s=>{const e=we(s);if(!e)return"";const n=e.split("/").filter(Boolean);return n[n.length-1]?.replace(/[-_]/g," ")||e},Nn=zs(s=>({expandedParents:{},toggleParent:e=>s(n=>{const o={...n.expandedParents};return o[e]?delete o[e]:o[e]=!0,{expandedParents:o}})})),zt=zs()(ar(s=>({projectExpanded:{},worktreeExpanded:{},setProjectExpanded:(e,n)=>s(o=>({projectExpanded:{...o.projectExpanded,[e]:n}})),setWorktreeExpanded:(e,n)=>s(o=>({worktreeExpanded:{...o.worktreeExpanded,[e]:n}}))}),{name:"mobile-session-tree"})),ms=zs()(ar(s=>({orderByProject:{},setWorktreeOrder:(e,n)=>s(o=>({orderByProject:{...o.orderByProject,[e]:n}}))}),{name:"mobile-worktree-order"})),En=s=>s.replace(/\\/g,"/").replace(/\/+$/,""),ol=(s,e)=>{if(!s||s.length===0)return e;const n=new Map(s.map((r,i)=>[En(r),i])),o=r=>n.get(En(r.path))??Number.MAX_SAFE_INTEGER;return e.map((r,i)=>({worktree:r,index:i})).sort((r,i)=>{const a=o(r.worktree)-o(i.worktree);return a!==0?a:r.index-i.index}).map(r=>r.worktree)},wt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),il=s=>{const e=s;return wt(e.directory??e.project?.worktree??null)},Sr=({open:s,project:e,worktree:n,onClose:o,onDeleted:r})=>{const{t:i}=ue(),a=Qn(),c=gs(y=>y.activeSessions),d=ve(y=>y.archiveSessions),u=dt(y=>y.currentDirectory),[f,p]=l.useState(!1),[b,x]=l.useState(!1),[v,S]=l.useState(!1),[g,I]=l.useState(!1),P=wt(n?.path),T=typeof n?.branch=="string"&&n.branch.trim().length>0,N=l.useMemo(()=>{if(!P)return[];const y=new Map;for(const k of[...c,...a])il(k)===P&&y.set(k.id,k);return Array.from(y.values())},[c,a,P]);l.useEffect(()=>{if(!s){p(!1),x(!1),S(!1),I(!1);return}if(!n?.path)return;let y=!1;return bo(n.path).then(k=>{y||S(!!k?.isDirty)}).catch(()=>{y||S(!!n.status?.isDirty)}),()=>{y=!0}},[s,n?.path,n?.status?.isDirty]);const E=l.useCallback(y=>{(async()=>{try{await go(e,y,{deleteRemoteBranch:T&&b,deleteLocalBranch:T&&f}),wt(u)===P&&wt(e.path)&&dt.getState().setDirectory(wt(e.path),{showOverlay:!1}),le.success(i("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:i(T&&b?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed")}),r?.()}catch(k){le.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:k instanceof Error?k.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")})}})()},[u,f,b,T,r,e,i,P]),D=async()=>{if(!(!n||g)){I(!0);try{if(N.length>0){const{archivedIds:y,failedIds:k}=await d(N.map(A=>A.id));if(k.length>0){y.length>0&&le.success(y.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:y.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:y.length})),le.error(k.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:k.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:k.length}),{description:i("sessions.sidebar.dialogs.deleteResult.tryAgain")}),I(!1);return}}E(n),o()}catch(y){le.error(i("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:y instanceof Error?y.message:i("sessions.sidebar.dialogs.deleteResult.tryAgain")}),I(!1)}finally{s||I(!1)}}};if(!n)return null;const w=n.branch||n.label||n.path,C=(y,k,A,R)=>t.jsxs("button",{type:"button",role:"switch","aria-checked":y,disabled:R,onClick:()=>k(!y),className:te("flex w-full items-center justify-between gap-3 rounded-xl border border-border/70 px-3.5 py-3 text-left transition-colors","hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",R&&"pointer-events-none opacity-40"),style:{touchAction:"manipulation"},children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:A}),t.jsx("span",{className:te("relative h-6 w-10 shrink-0 rounded-full transition-colors",y?"bg-primary":"bg-muted-foreground/30"),children:t.jsx("span",{className:te("absolute top-0.5 size-5 rounded-full bg-white transition-transform",y?"translate-x-[1.125rem]":"translate-x-0.5")})})]});return t.jsx(xo,{open:s,onClose:o,title:i("mobile.projectEdit.deleteWorktreeTitle"),footer:t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ge,{variant:"ghost",className:"flex-1",onClick:o,disabled:g,children:i("projectEditDialog.actions.cancel")}),t.jsx(ge,{variant:"destructive",className:"flex-1",onClick:()=>{D()},disabled:g,children:i("mobile.projectEdit.deleteWorktreeConfirmButton")})]}),children:t.jsxs("div",{className:"flex flex-col gap-4 px-1 py-1",children:[t.jsx("p",{className:"typography-ui-body text-foreground",children:i("mobile.projectEdit.deleteWorktreeConfirm",{name:w})}),v?t.jsx("p",{className:"rounded-xl border border-[var(--warning)]/40 bg-[color-mix(in_srgb,var(--warning)_10%,transparent)] px-3.5 py-3 typography-meta text-foreground",children:i("mobile.projectEdit.deleteWorktreeDirty")}):null,N.length>0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:i("mobile.projectEdit.deleteWorktreeArchiveNote",{count:N.length})}):null,T?t.jsxs("div",{className:"flex flex-col gap-2",children:[C(f,p,i("mobile.projectEdit.deleteLocalBranch"),g),C(b,x,i("mobile.projectEdit.deleteRemoteBranch"),g)]}):null]})})},Cn="mobile-surface-root",rs=16,Ot=200,al=()=>{if(typeof document>"u")return null;let s=document.getElementById(Cn);return s||(s=document.createElement("div"),s.id=Cn,document.body.appendChild(s)),s},jt=({open:s,onClose:e,title:n,subtitle:o,trailing:r,disableEscapeDismiss:i=!1,headerless:a=!1,noHeaderBorder:c=!1,ariaLabel:d,variant:u="fullscreen",dialogAlign:f="chat",children:p})=>{const{t:b}=ue(),x=l.useRef(null),[v,S]=l.useState(!1),[g,I]=l.useState(!1),P=l.useRef(null),T=l.useRef(null),N=l.useRef(e);if(l.useEffect(()=>{N.current=e},[e]),typeof document<"u"&&!x.current&&(x.current=al()),l.useEffect(()=>{if(!s){S(!1);return}const w=window.setTimeout(()=>S(!0),rs);return()=>window.clearTimeout(w)},[s]),l.useEffect(()=>{if(!s){I(!1);return}const w=window.setTimeout(()=>I(!0),rs+Ot+80);return()=>window.clearTimeout(w)},[s]),l.useEffect(()=>{if(!s)return;const w=document.body.style.overflow;T.current=document.activeElement instanceof HTMLElement?document.activeElement:null,document.body.style.overflow="hidden";const C=()=>{const A=P.current;if(!A)return;(A.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')??A).focus({preventScroll:!0})},y=window.setTimeout(C,rs),k=A=>{if(A.key==="Escape"&&!i){N.current();return}if(A.key!=="Tab")return;const R=P.current;if(!R)return;const j=Array.from(R.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(L=>!L.hasAttribute("disabled")&&L.getAttribute("aria-hidden")!=="true");if(j.length===0){A.preventDefault(),R.focus({preventScroll:!0});return}const V=j[0],z=j[j.length-1],h=document.activeElement;A.shiftKey&&h===V?(A.preventDefault(),z.focus({preventScroll:!0})):!A.shiftKey&&h===z&&(A.preventDefault(),V.focus({preventScroll:!0}))};return document.addEventListener("keydown",k),()=>{window.clearTimeout(y),document.body.style.overflow=w,document.removeEventListener("keydown",k),T.current?.focus?.({preventScroll:!0}),T.current=null}},[i,s]),!s||!x.current)return null;const E=u==="dialog",D=t.jsxs("section",{ref:P,role:"dialog","aria-modal":"true","aria-label":d,tabIndex:-1,className:te("flex flex-col bg-background text-foreground",E?"h-[min(88dvh,860px)] w-full max-w-[720px] overflow-hidden rounded-2xl border border-border/70 shadow-[0_24px_64px_rgb(0_0_0_/_0.32)]":"oc-keyboard-inset-surface fixed inset-0 z-50"),style:E?{opacity:v?1:0,transform:v?"none":"scale(0.97)",transition:`opacity ${Ot}ms ease-out, transform ${Ot}ms cubic-bezier(0.32, 0.72, 0, 1)`}:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:v?"none":"translateX(100%)",transition:`transform ${Ot}ms cubic-bezier(0.32, 0.72, 0, 1)`},onTransitionEnd:w=>{v&&w.target===w.currentTarget&&w.propertyName==="transform"&&I(!0)},children:[a?null:t.jsxs("header",{className:te("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",!c&&"border-b border-border/70"),children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":b("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})}),t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[n?typeof n=="string"?t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:n}):n:null,o?typeof o=="string"?t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:o}):o:null]}),r?t.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:r}):null]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:g?t.jsx("div",{className:"h-full",style:{animation:"oc-surface-content-in 200ms ease-out"},children:p}):null}),t.jsx("style",{children:"@keyframes oc-surface-content-in { from { opacity: 0 } to { opacity: 1 } }"})]});return E?ct.createPortal(t.jsx("div",{className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex items-center justify-center p-4 transition-opacity duration-200 ease-out",style:{background:"rgb(0 0 0 / 0.45)",opacity:v?1:0,paddingLeft:f==="chat"?"max(1rem, var(--oc-chat-inset-left, 0px))":"1rem",paddingRight:f==="chat"?"max(1rem, var(--oc-chat-inset-right, 0px))":"1rem",paddingTop:"max(1rem, var(--oc-safe-area-top, 0px))"},onClick:e,children:t.jsx("div",{className:"flex w-full max-w-[720px] justify-center",onClick:w=>w.stopPropagation(),children:D})}),x.current):ct.createPortal(D,x.current)},ll=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),cl=s=>{const e=de.c(36),{worktree:n,onDelete:o}=s,{t:r}=ue();let i;e[0]!==n.path?(i={id:n.path},e[0]=n.path,e[1]=i):i=e[1];const{attributes:a,listeners:c,setNodeRef:d,transform:u,transition:f,isDragging:p}=Ms(i);let b;e[2]!==u?(b=Ls.Transform.toString(u),e[2]=u,e[3]=b):b=e[3];const x=p?10:1;let v;e[4]!==b||e[5]!==x||e[6]!==f?(v={transform:b,transition:f,zIndex:x},e[4]=b,e[5]=x,e[6]=f,e[7]=v):v=e[7];const S=v,g=n.branch||n.label||n.path,I=p&&"shadow-lg shadow-black/20";let P;e[8]!==I?(P=te("flex items-center gap-1 rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",I),e[8]=I,e[9]=P):P=e[9];let T;e[10]!==g||e[11]!==r?(T=r("mobile.projectEdit.dragWorktreeAria",{label:g}),e[10]=g,e[11]=r,e[12]=T):T=e[12];let N;e[13]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(Ns,{className:"size-4"}),e[13]=N):N=e[13];let E;e[14]!==a||e[15]!==c||e[16]!==T?(E=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":T,...a,...c,children:N}),e[14]=a,e[15]=c,e[16]=T,e[17]=E):E=e[17];let D;e[18]===Symbol.for("react.memo_cache_sentinel")?(D=t.jsx(se,{name:"node-tree",className:"size-4 shrink-0 text-muted-foreground"}),e[18]=D):D=e[18];let w;e[19]!==g?(w=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:g}),e[19]=g,e[20]=w):w=e[20];let C;e[21]!==g||e[22]!==r?(C=r("mobile.projectEdit.deleteWorktreeAria",{label:g}),e[21]=g,e[22]=r,e[23]=C):C=e[23];let y,k;e[24]===Symbol.for("react.memo_cache_sentinel")?(y={touchAction:"manipulation"},k=t.jsx(Ut,{className:"size-4"}),e[24]=y,e[25]=k):(y=e[24],k=e[25]);let A;e[26]!==o||e[27]!==C?(A=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-xl text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive","aria-label":C,onClick:o,style:y,children:k}),e[26]=o,e[27]=C,e[28]=A):A=e[28];let R;return e[29]!==d||e[30]!==S||e[31]!==w||e[32]!==A||e[33]!==P||e[34]!==E?(R=t.jsxs("div",{ref:d,style:S,className:P,children:[E,D,w,A]}),e[29]=d,e[30]=S,e[31]=w,e[32]=A,e[33]=P,e[34]=E,e[35]=R):R=e[35],R},dl=({open:s,project:e,onClose:n,onWorktreesChanged:o})=>{const{t:r}=ue(),{currentTheme:i}=Xn(),a=Oe(h=>h.updateProjectMeta),c=Oe(h=>h.discoverProjectIcon),d=Oe(h=>h.removeProjectIcon),u=ms(h=>h.setWorktreeOrder),f=Oe(h=>e?h.projects.find(L=>L.id===e.id)?.iconImage??null:null),[p,b]=l.useState(""),[x,v]=l.useState(null),[S,g]=l.useState(null),[I,P]=l.useState(!1),[T,N]=l.useState([]),[E,D]=l.useState(null),w=e?.id??null;l.useEffect(()=>{!s||!e||(b(e.label),v(e.icon??null),g(e.color??null),N(e.worktrees))},[s,w]),l.useEffect(()=>{!s||!e||N(h=>{const L=e.worktrees.map(H=>H.path),M=h.map(H=>H.path);return L.length===M.length&&L.every(H=>M.includes(H))?h:e.worktrees})},[e?.worktrees]);const C=Cs(ut(Ps,{activationConstraint:{distance:8}}),ut(Rs,{coordinateGetter:_s})),y=()=>{if(!e)return;const h=p.trim();a(e.id,{label:h||e.label,icon:x,color:S}),n()},k=()=>{!e||I||(P(!0),c(e.id).then(h=>{if(!h.ok){le.error(h.error||r("projectEditDialog.toast.failedToDiscoverIcon"));return}if(h.skipped){le.success(r("projectEditDialog.toast.customIconAlreadySet"));return}le.success(r("projectEditDialog.toast.iconDiscovered"))}).finally(()=>P(!1)))},A=()=>{e&&d(e.id).then(h=>{if(!h.ok){le.error(h.error||r("projectEditDialog.toast.failedToRemoveIcon"));return}le.success(r("projectEditDialog.toast.iconRemoved"))})},R=h=>{const{active:L,over:M}=h;if(!M||L.id===M.id||!e)return;const B=T.findIndex(_=>_.path===L.id),H=T.findIndex(_=>_.path===M.id);if(B<0||H<0)return;const Z=[...T],[Q]=Z.splice(B,1);Z.splice(H,0,Q),N(Z),u(e.id,Z.map(_=>ll(_.path)))},j=S?Zn[S]??null:null,V=x?er[x]:null,z=!!f;return t.jsxs(t.Fragment,{children:[t.jsx(jt,{open:s,onClose:n,title:r("projectEditDialog.title"),ariaLabel:r("projectEditDialog.title"),noHeaderBorder:!0,trailing:t.jsxs(ge,{type:"button",variant:"default",size:"sm","aria-label":r("projectEditDialog.actions.save"),onClick:y,disabled:!p.trim(),style:{touchAction:"manipulation"},children:[t.jsx(rr,{className:"size-4"}),r("projectEditDialog.actions.save")]}),children:e?t.jsxs("div",{className:"h-full space-y-6 overflow-y-auto px-4 pb-8 pt-2",children:[t.jsx("div",{className:"flex justify-center pt-2",children:t.jsx("span",{className:"flex size-16 items-center justify-center overflow-hidden rounded-2xl bg-[var(--surface-muted)] text-muted-foreground",style:e.iconBackground?{backgroundColor:e.iconBackground}:void 0,children:z?t.jsx(tr,{project:{id:e.id,iconImage:f},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:t.jsx(cs,{className:"size-7"})}):V?t.jsx(se,{name:V,className:"size-7",style:j?{color:j}:void 0}):t.jsx(cs,{className:"size-7",style:j?{color:j}:void 0})})}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.name")}),t.jsx(ws,{value:p,onChange:h=>b(h.target.value),placeholder:r("projectEditDialog.field.namePlaceholder"),className:"h-11"}),t.jsx("p",{className:"truncate typography-meta text-muted-foreground",title:e.path,children:e.path})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.color")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>g(null),"aria-label":r("projectEditDialog.option.none"),className:te("flex size-9 items-center justify-center rounded-xl border-2 transition-all",S===null?"border-foreground":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),yo.map(h=>t.jsx("button",{type:"button",onClick:()=>g(h.key),"aria-label":h.label,title:h.label,className:te("size-9 rounded-xl border-2 transition-all",S===h.key?"border-foreground":"border-transparent hover:border-border/70"),style:{backgroundColor:h.cssVar,touchAction:"manipulation"}},h.key))]})]}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("projectEditDialog.field.icon")}),t.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[t.jsx("button",{type:"button",onClick:()=>v(null),"aria-label":r("projectEditDialog.option.none"),className:te("flex size-9 items-center justify-center rounded-xl border-2 transition-all",x===null?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx("span",{className:"h-0.5 w-4 rotate-45 rounded-full bg-muted-foreground/40"})}),vo.map(h=>t.jsx("button",{type:"button",onClick:()=>v(h.key),"aria-label":h.label,title:h.label,className:te("flex size-9 items-center justify-center rounded-xl border-2 transition-all",x===h.key?"border-foreground bg-[var(--surface-elevated)]":"border-border/70 hover:border-border/70"),style:{touchAction:"manipulation"},children:t.jsx(se,{name:h.Icon,className:"size-4",style:j?{color:j}:void 0})},h.key))]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[t.jsx(ge,{size:"sm",variant:"outline",onClick:k,disabled:I,children:r(I?"projectEditDialog.actions.discovering":"projectEditDialog.actions.discoverFavicon")}),z?t.jsx(ge,{size:"sm",variant:"outline",onClick:A,children:r("projectEditDialog.actions.removeProjectIcon")}):null]})]}),e.isGitRepo?t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:r("mobile.projectEdit.worktreesTitle")}),T.length===0?t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.worktreesEmpty")}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:r("mobile.projectEdit.reorderHint")}),t.jsx(Ts,{sensors:C,collisionDetection:Is,onDragEnd:R,children:t.jsx(As,{items:T.map(h=>h.path),strategy:Ds,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:T.map(h=>t.jsx(cl,{worktree:h,onDelete:()=>D(h)},h.path))})})})]})]}):null]}):null}),e?t.jsx(Sr,{open:!!E,project:{id:e.id,path:e.path},worktree:E,onClose:()=>D(null),onDeleted:()=>{N(h=>h.filter(L=>L.path!==E?.path)),o?.()}}):null]})},ul=new Set,os=7,Rn=40,fl=16,xt=s=>s.parentID??null,ot=s=>{const e=s;return we(e.directory??e.project?.worktree??null)},ml=s=>{const e=s.time?.updated??s.time?.created,n=typeof e=="number"?e:Number(e);return Number.isFinite(n)&&n>0?n:0},pl=s=>{if(s<=0)return"";const e=Date.now()-s;if(e<6e4)return"now";const n=Math.floor(e/6e4);if(n<60)return`${n}m`;const o=Math.floor(n/60);if(o<24)return`${o}h`;const r=Math.floor(o/24);return r<7?`${r}d`:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(s))},hl=(s,e)=>{const n=we(s),o=we(e);return!!(n&&o&&(n===o||n.startsWith(`${o}/`)))},Wt=(s,e)=>s.worktrees.find(n=>we(n.path)===e)??null,ps=(s,e)=>e===s.path||!!Wt(s,e),is=(s,e)=>{const n=we(e);return n?s.find(o=>ps(o,n))??null:null},as=(s,e,n)=>n?`${s.title??""} ${s.id} ${ot(s)} ${e}`.toLowerCase().includes(n):!0,hs=s=>{const e=de.c(17),{project:n,size:o}=s,r=o===void 0?"md":o,{currentTheme:i}=Xn(),a=n.icon?er[n.icon]:null,c=n.color?Zn[n.color]??null:null,d=r==="sm"?"size-6 rounded-md":"size-8 rounded-lg",u=r==="sm"?"size-3.5":"size-4";let f;e[0]!==a||e[1]!==c||e[2]!==u?(f=a?t.jsx(se,{name:a,className:u,style:c?{color:c}:void 0}):t.jsx(cs,{className:u,style:c?{color:c}:void 0}),e[0]=a,e[1]=c,e[2]=u,e[3]=f):f=e[3];const p=f;let b;e[4]!==d?(b=te("flex shrink-0 items-center justify-center overflow-hidden bg-[var(--surface-muted)] text-muted-foreground",d),e[4]=d,e[5]=b):b=e[5];let x;e[6]!==n.iconBackground?(x=n.iconBackground?{backgroundColor:n.iconBackground}:void 0,e[6]=n.iconBackground,e[7]=x):x=e[7];let v;e[8]!==i||e[9]!==p||e[10]!==n.iconImage||e[11]!==n.id?(v=n.iconImage?t.jsx(tr,{project:{id:n.id,iconImage:n.iconImage??null},options:{themeVariant:i.metadata.variant,iconColor:i.colors.surface.foreground},className:"size-full object-contain",fallback:p}):p,e[8]=i,e[9]=p,e[10]=n.iconImage,e[11]=n.id,e[12]=v):v=e[12];let S;return e[13]!==b||e[14]!==x||e[15]!==v?(S=t.jsx("span",{className:b,style:x,children:v}),e[13]=b,e[14]=x,e[15]=v,e[16]=S):S=e[16],S},Pn=s=>{const e=de.c(2),{ariaLabel:n}=s;let o;return e[0]!==n?(o=t.jsx("span",{className:"inline-block size-1.5 shrink-0 rounded-full bg-primary","aria-label":n}),e[0]=n,e[1]=o):o=e[1],o},Tn=s=>{const e=de.c(12),{onClick:n,className:o}=s,{t:r}=ue();let i;e[0]!==r?(i=r("sessions.sidebar.project.actions.newWorktree"),e[0]=r,e[1]=i):i=e[1];const a=i;let c;e[2]!==o?(c=te("flex size-9 shrink-0 items-center justify-center rounded-full text-[var(--surface-mutedForeground)] transition-colors hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",o),e[2]=o,e[3]=c):c=e[3];let d;e[4]!==n?(d=b=>{b.stopPropagation(),n()},e[4]=n,e[5]=d):d=e[5];let u,f;e[6]===Symbol.for("react.memo_cache_sentinel")?(u={touchAction:"manipulation"},f=t.jsx(se,{name:"node-tree",className:"size-4"}),e[6]=u,e[7]=f):(u=e[6],f=e[7]);let p;return e[8]!==a||e[9]!==c||e[10]!==d?(p=t.jsx("button",{type:"button",className:c,"aria-label":a,title:a,onClick:d,style:u,children:f}),e[8]=a,e[9]=c,e[10]=d,e[11]=p):p=e[11],p},rt=144,Nr=180,In=s=>{const e=de.c(25),{actionsWidth:n,actions:o,revealed:r,onRevealedChange:i,children:a}=s,c=l.useRef(null),d=l.useRef(null),u=l.useRef(!1),f=l.useRef(0),p=l.useRef(r);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=(R,j)=>{const V=c.current;V&&(V.style.transition=j?`transform ${Nr}ms ease-out`:"none",V.style.transform=R===0?"none":`translateX(${R}px)`,f.current=R)},e[0]=b):b=e[0];const x=b;let v,S;e[1]!==n||e[2]!==r?(v=()=>{p.current=r,x(r?-n:0,!0)},S=[n,x,r],e[1]=n,e[2]=r,e[3]=v,e[4]=S):(v=e[3],S=e[4]),l.useEffect(v,S);let g;e[5]===Symbol.for("react.memo_cache_sentinel")?(g=R=>{if(R.touches.length!==1)return;const j=R.touches[0];d.current={x:j.clientX,y:j.clientY},u.current=!1},e[5]=g):g=e[5];const I=g;let P;e[6]!==n?(P=R=>{if(!d.current)return;const j=R.touches[0],V=j.clientX-d.current.x,z=j.clientY-d.current.y;if(!u.current){if(Math.abs(V)<8||Math.abs(V)<=Math.abs(z))return;u.current=!0}const h=p.current?-n:0;x(Math.min(0,Math.max(-n,h+V)),!1)},e[6]=n,e[7]=P):P=e[7];const T=P;let N;e[8]!==n||e[9]!==i?(N=()=>{if(d.current=null,!u.current)return;u.current=!1;const R=f.current<-n/2;x(R?-n:0,!0),R!==p.current&&i(R)},e[8]=n,e[9]=i,e[10]=N):N=e[10];const E=N;let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D={touchAction:"pan-y"},e[11]=D):D=e[11];let w;e[12]!==n?(w={width:n},e[12]=n,e[13]=w):w=e[13];const C=!r;let y;e[14]!==o||e[15]!==w||e[16]!==C?(y=t.jsx("div",{className:"absolute inset-y-0 right-0 flex items-stretch",style:w,"aria-hidden":C,children:o}),e[14]=o,e[15]=w,e[16]=C,e[17]=y):y=e[17];let k;e[18]!==a?(k=t.jsx("div",{ref:c,className:"relative flex w-full items-center bg-background",children:a}),e[18]=a,e[19]=k):k=e[19];let A;return e[20]!==E||e[21]!==T||e[22]!==y||e[23]!==k?(A=t.jsxs("div",{className:"relative overflow-hidden",onTouchStart:I,onTouchMove:T,onTouchEnd:E,onTouchCancel:E,style:D,children:[y,k]}),e[20]=E,e[21]=T,e[22]=y,e[23]=k,e[24]=A):A=e[24],A},bl=s=>{const e=de.c(41),{initialTitle:n,indent:o,onSubmit:r,onCancel:i}=s,{t:a}=ue(),[c,d]=l.useState(n);let u;e[0]!==n||e[1]!==i||e[2]!==r||e[3]!==c?(u=()=>{const R=c.trim();if(!R||R===n.trim()){i();return}r(R)},e[0]=n,e[1]=i,e[2]=r,e[3]=c,e[4]=u):u=e[4];const f=u;let p;e[5]!==o?(p={paddingLeft:o},e[5]=o,e[6]=p):p=e[6];let b;e[7]!==f?(b=R=>{R.preventDefault(),f()},e[7]=f,e[8]=b):b=e[8];let x;e[9]===Symbol.for("react.memo_cache_sentinel")?(x=R=>d(R.target.value),e[9]=x):x=e[9];let v;e[10]!==i?(v=R=>{R.stopPropagation(),R.key==="Escape"&&i()},e[10]=i,e[11]=v):v=e[11];let S;e[12]!==a?(S=a("sessions.sidebar.session.rename.save"),e[12]=a,e[13]=S):S=e[13];let g;e[14]!==a?(g=a("sessions.sidebar.session.menu.rename"),e[14]=a,e[15]=g):g=e[15];let I;e[16]===Symbol.for("react.memo_cache_sentinel")?(I={minHeight:0},e[16]=I):I=e[16];let P;e[17]!==v||e[18]!==S||e[19]!==g||e[20]!==c?(P=t.jsx("input",{autoFocus:!0,value:c,onChange:x,onKeyDown:v,"aria-label":S,placeholder:g,className:"min-w-0 flex-1 bg-transparent text-[16px] typography-ui-label text-foreground outline-none placeholder:text-muted-foreground",style:I,enterKeyHint:"done"}),e[17]=v,e[18]=S,e[19]=g,e[20]=c,e[21]=P):P=e[21];let T;e[22]!==a?(T=a("sessions.sidebar.session.rename.save"),e[22]=a,e[23]=T):T=e[23];let N,E;e[24]===Symbol.for("react.memo_cache_sentinel")?(N={touchAction:"manipulation",minHeight:0,minWidth:0},E=t.jsx(se,{name:"check",className:"size-4"}),e[24]=N,e[25]=E):(N=e[24],E=e[25]);let D;e[26]!==T?(D=t.jsx("button",{type:"submit","aria-label":T,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:N,children:E}),e[26]=T,e[27]=D):D=e[27];let w;e[28]!==a?(w=a("sessions.sidebar.session.rename.cancel"),e[28]=a,e[29]=w):w=e[29];let C,y;e[30]===Symbol.for("react.memo_cache_sentinel")?(C={touchAction:"manipulation",minHeight:0,minWidth:0},y=t.jsx(se,{name:"close",className:"size-4"}),e[30]=C,e[31]=y):(C=e[30],y=e[31]);let k;e[32]!==i||e[33]!==w?(k=t.jsx("button",{type:"button",onClick:i,"aria-label":w,className:"flex size-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:C,children:y}),e[32]=i,e[33]=w,e[34]=k):k=e[34];let A;return e[35]!==D||e[36]!==k||e[37]!==p||e[38]!==b||e[39]!==P?(A=t.jsxs("form",{className:"flex h-9 min-w-0 flex-1 items-center gap-2 pr-2",style:p,onSubmit:b,children:[P,D,k]}),e[35]=D,e[36]=k,e[37]=p,e[38]=b,e[39]=P,e[40]=A):A=e[40],A},_n=s=>{const e=de.c(48),{session:n,active:o,indent:r,contextLabel:i,hasChildren:a,expanded:c,onToggleChildren:d,onSelect:u,revealed:f,onRevealedChange:p,confirmingDelete:b,onArchive:x,onRequestDelete:v,onConfirmDelete:S,renaming:g,onRequestRename:I,onSubmitRename:P,onCancelRename:T}=s,N=a===void 0?!1:a,E=c===void 0?!1:c,D=f===void 0?!1:f,w=b===void 0?!1:b,C=g===void 0?!1:g,{t:y}=ue();let k;e[0]!==n?(k=pl(ml(n)),e[0]=n,e[1]=k):k=e[1];const A=k,R=n.title?.trim()||y("mobile.sessions.untitled"),j=!!(p&&x),V=Yn(n.id),z=Jn(n.id),h=V?.type??"idle",L=h==="busy"||h==="retry",M=!L&&z>0&&!o,B=l.useRef(null),H=l.useRef(null),Z=l.useRef(!1),Q=l.useRef(0),_=l.useRef(D);let J;e[2]===Symbol.for("react.memo_cache_sentinel")?(J=($,re)=>{const me=B.current;me&&(me.style.transition=re?`transform ${Nr}ms ease-out`:"none",me.style.transform=$===0?"none":`translateX(${$}px)`,Q.current=$)},e[2]=J):J=e[2];const q=J;let F,U;e[3]!==D?(F=()=>{_.current=D,q(D?-rt:0,!0)},U=[q,D],e[3]=D,e[4]=F,e[5]=U):(F=e[4],U=e[5]),l.useEffect(F,U);let X;e[6]!==j?(X=$=>{if(!j||$.touches.length!==1)return;const re=$.touches[0];H.current={x:re.clientX,y:re.clientY},Z.current=!1},e[6]=j,e[7]=X):X=e[7];const ee=X;let W;e[8]!==j?(W=$=>{if(!j||!H.current)return;const re=$.touches[0],me=re.clientX-H.current.x,Me=re.clientY-H.current.y;if(!Z.current){if(Math.abs(me)<8||Math.abs(me)<=Math.abs(Me))return;Z.current=!0}const xe=_.current?-rt:0,We=Math.min(0,Math.max(-rt,xe+me));q(We,!1)},e[8]=j,e[9]=W):W=e[9];const oe=W;let ie;e[10]!==p?(ie=()=>{if(H.current=null,!Z.current)return;Z.current=!1;const $=Q.current<-rt/2;q($?-rt:0,!0),$!==_.current&&p?.($)},e[10]=p,e[11]=ie):ie=e[11];const fe=ie,je=o||void 0,Y="relative overflow-hidden";let ce;e[12]!==j?(ce=j?{touchAction:"pan-y"}:void 0,e[12]=j,e[13]=ce):ce=e[13];const Se=j?t.jsxs("div",{className:"absolute inset-y-0 right-0 flex items-stretch",style:{width:rt},"aria-hidden":!D,children:[t.jsx("button",{type:"button",tabIndex:D?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary","aria-label":y("mobile.sessions.renameSessionAria",{title:R}),onClick:I,style:{touchAction:"manipulation"},children:t.jsx(ds,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:D?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary","aria-label":y("mobile.sessions.archiveSessionAria",{title:R}),onClick:x,style:{touchAction:"manipulation"},children:t.jsx(Wi,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:D?0:-1,className:te("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",w?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":w?y("mobile.sessions.confirmDeleteSessionAria",{title:R}):y("mobile.sessions.deleteSessionAria",{title:R}),onClick:w?S:v,style:{touchAction:"manipulation"},children:t.jsx(Ut,{className:"size-[18px]"})})]}):null,Ae=j&&"bg-background",Re=o&&(j?"bg-[color-mix(in_srgb,var(--primary)_10%,var(--background))]":"bg-[color-mix(in_srgb,var(--primary)_10%,transparent)]");let Ie;e[14]!==Ae||e[15]!==Re?(Ie=te("relative flex items-center gap-1 transition-colors",Ae,Re),e[14]=Ae,e[15]=Re,e[16]=Ie):Ie=e[16];let ke;e[17]!==E||e[18]!==N||e[19]!==r||e[20]!==L||e[21]!==d||e[22]!==M||e[23]!==y?(ke=L||M||N&&d?t.jsx("button",{type:"button",className:"absolute z-10 flex w-6 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",style:{left:Math.max(r-32,2),top:0,bottom:0,touchAction:"manipulation"},"aria-label":y(E?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),disabled:!N||!d,onClick:$=>{$.stopPropagation(),d?.()},children:L?t.jsx(se,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}):M?t.jsx("span",{className:"size-1.5 rounded-full bg-[var(--status-info)]","aria-hidden":!0}):t.jsx(Es,{className:te("size-[18px] transition-transform duration-150",E?"rotate-0":"-rotate-90")})}):null,e[17]=E,e[18]=N,e[19]=r,e[20]=L,e[21]=d,e[22]=M,e[23]=y,e[24]=ke):ke=e[24];let _e;e[25]!==o||e[26]!==i||e[27]!==r||e[28]!==T||e[29]!==p||e[30]!==u||e[31]!==P||e[32]!==C||e[33]!==A||e[34]!==R?(_e=C&&P&&T?t.jsx(bl,{initialTitle:R,indent:r,onSubmit:P,onCancel:T}):t.jsx("button",{type:"button",className:te("flex min-w-0 flex-1 items-center gap-2.5 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",i?"min-h-10 py-1":"h-9"),style:{paddingLeft:r,touchAction:"manipulation"},onClick:()=>{if(_.current){p?.(!1);return}u()},children:t.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[t.jsxs("span",{className:"flex items-center gap-2.5",children:[t.jsx("span",{className:te("block min-w-0 flex-1 truncate typography-ui-label",o?"text-primary":"text-foreground"),children:R}),A?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:A}):null]}),i?t.jsx("span",{className:"block truncate typography-micro text-muted-foreground",children:i}):null]})}),e[25]=o,e[26]=i,e[27]=r,e[28]=T,e[29]=p,e[30]=u,e[31]=P,e[32]=C,e[33]=A,e[34]=R,e[35]=_e):_e=e[35];let be;e[36]!==Ie||e[37]!==ke||e[38]!==_e?(be=t.jsxs("div",{ref:B,className:Ie,children:[ke,_e]}),e[36]=Ie,e[37]=ke,e[38]=_e,e[39]=be):be=e[39];let O;return e[40]!==fe||e[41]!==oe||e[42]!==ee||e[43]!==je||e[44]!==ce||e[45]!==Se||e[46]!==be?(O=t.jsxs("div",{"data-active-session":je,className:Y,onTouchStart:ee,onTouchMove:oe,onTouchEnd:fe,onTouchCancel:fe,style:ce,children:[Se,be]}),e[40]=fe,e[41]=oe,e[42]=ee,e[43]=je,e[44]=ce,e[45]=Se,e[46]=be,e[47]=O):O=e[47],O},gl=s=>{const e=de.c(11),{indent:n,onClick:o}=s,{t:r}=ue();let i;e[0]!==n?(i={paddingLeft:n,touchAction:"manipulation"},e[0]=n,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(Es,{className:"size-4"}),e[2]=a):a=e[2];let c;e[3]!==r?(c=r("sessions.sidebar.group.showMore"),e[3]=r,e[4]=c):c=e[4];let d;e[5]!==c?(d=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=d):d=e[6];let u;return e[7]!==o||e[8]!==i||e[9]!==d?(u=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:i,onClick:o,children:[a,d]}),e[7]=o,e[8]=i,e[9]=d,e[10]=u):u=e[10],u},xl=s=>{const e=de.c(11),{indent:n,onClick:o}=s,{t:r}=ue();let i;e[0]!==n?(i={paddingLeft:n,touchAction:"manipulation"},e[0]=n,e[1]=i):i=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(Ui,{className:"size-4"}),e[2]=a):a=e[2];let c;e[3]!==r?(c=r("sessions.sidebar.group.showFewer"),e[3]=r,e[4]=c):c=e[4];let d;e[5]!==c?(d=t.jsx("span",{className:"typography-micro",children:c}),e[5]=c,e[6]=d):d=e[6];let u;return e[7]!==o||e[8]!==i||e[9]!==d?(u=t.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center gap-2 py-1 pr-3 text-left text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",style:i,onClick:o,children:[a,d]}),e[7]=o,e[8]=i,e[9]=d,e[10]=u):u=e[10],u},yl=s=>{const e=de.c(29),{worktree:n}=s,{t:o}=ue();let r;e[0]!==n.path?(r=we(n.path),e[0]=n.path,e[1]=r):r=e[1];const i=r;let a;e[2]!==i?(a={id:i},e[2]=i,e[3]=a):a=e[3];const{attributes:c,listeners:d,setNodeRef:u,transform:f,transition:p,isDragging:b}=Ms(a),x=n.branch||n.label||n.path;let v;e[4]!==f?(v=Ls.Transform.toString(f),e[4]=f,e[5]=v):v=e[5];const S=b?10:1;let g;e[6]!==v||e[7]!==S||e[8]!==p?(g={transform:v,transition:p,zIndex:S},e[6]=v,e[7]=S,e[8]=p,e[9]=g):g=e[9];const I=b&&"shadow-lg shadow-black/20";let P;e[10]!==I?(P=te("flex items-center gap-1 rounded-xl bg-background px-1 py-1",I),e[10]=I,e[11]=P):P=e[11];let T;e[12]!==x||e[13]!==o?(T=o("mobile.sessions.dragHandleAria",{label:x}),e[12]=x,e[13]=o,e[14]=T):T=e[14];let N;e[15]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(Ns,{className:"size-4"}),e[15]=N):N=e[15];let E;e[16]!==c||e[17]!==d||e[18]!==T?(E=t.jsx("button",{type:"button",className:"flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-lg text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":T,...c,...d,children:N}),e[16]=c,e[17]=d,e[18]=T,e[19]=E):E=e[19];let D;e[20]===Symbol.for("react.memo_cache_sentinel")?(D=t.jsx(se,{name:"git-branch",className:"size-4 shrink-0 text-muted-foreground"}),e[20]=D):D=e[20];let w;e[21]!==x?(w=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-bold text-muted-foreground",children:x}),e[21]=x,e[22]=w):w=e[22];let C;return e[23]!==u||e[24]!==E||e[25]!==w||e[26]!==g||e[27]!==P?(C=t.jsxs("div",{ref:u,style:g,className:P,children:[E,D,w]}),e[23]=u,e[24]=E,e[25]=w,e[26]=g,e[27]=P,e[28]=C):C=e[28],C},vl=s=>{const e=de.c(61),{project:n,totalSessions:o,expanded:r,onToggleExpanded:i,onReorderWorktrees:a}=s,{t:c}=ue();let d;e[0]!==n.id?(d={id:n.id},e[0]=n.id,e[1]=d):d=e[1];const{attributes:u,listeners:f,setNodeRef:p,transform:b,transition:x,isDragging:v}=Ms(d);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S={activationConstraint:{distance:8}},e[2]=S):S=e[2];let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g={coordinateGetter:_s},e[3]=g):g=e[3];const I=Cs(ut(Ps,S),ut(Rs,g)),P=n.worktrees.length>0;let T;e[4]!==a||e[5]!==n.worktrees?(T=J=>{const{active:q,over:F}=J;if(!F||q.id===F.id)return;const U=n.worktrees.map(Sl),X=U.indexOf(String(q.id)),ee=U.indexOf(String(F.id));if(X<0||ee<0)return;const W=[...U],[oe]=W.splice(X,1);W.splice(ee,0,oe),a(W)},e[4]=a,e[5]=n.worktrees,e[6]=T):T=e[6];const N=T;let E;e[7]!==b?(E=Ls.Transform.toString(b),e[7]=b,e[8]=E):E=e[8];const D=v?10:1;let w;e[9]!==E||e[10]!==D||e[11]!==x?(w={transform:E,transition:x,zIndex:D},e[9]=E,e[10]=D,e[11]=x,e[12]=w):w=e[12];const C=v&&"shadow-lg shadow-black/20";let y;e[13]!==C?(y=te("rounded-2xl border border-border/70 bg-[var(--surface-elevated)] px-1.5 py-1.5 transition-colors",C),e[13]=C,e[14]=y):y=e[14];let k;e[15]!==n.label||e[16]!==c?(k=c("mobile.sessions.dragHandleAria",{label:n.label}),e[15]=n.label,e[16]=c,e[17]=k):k=e[17];let A;e[18]===Symbol.for("react.memo_cache_sentinel")?(A=t.jsx(Ns,{className:"size-4"}),e[18]=A):A=e[18];let R;e[19]!==u||e[20]!==f||e[21]!==k?(R=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 cursor-grab touch-none items-center justify-center rounded-xl text-muted-foreground/70 transition-colors hover:text-foreground active:cursor-grabbing","aria-label":k,...u,...f,children:A}),e[19]=u,e[20]=f,e[21]=k,e[22]=R):R=e[22];let j;e[23]!==r||e[24]!==n.label||e[25]!==c?(j=r?c("sessions.sidebar.group.collapseAria",{label:n.label}):c("sessions.sidebar.group.expandAria",{label:n.label}),e[23]=r,e[24]=n.label,e[25]=c,e[26]=j):j=e[26];const V=!P;let z;e[27]===Symbol.for("react.memo_cache_sentinel")?(z={touchAction:"manipulation"},e[27]=z):z=e[27];let h;e[28]!==n?(h=t.jsx(hs,{project:n}),e[28]=n,e[29]=h):h=e[29];let L;e[30]!==n.label?(L=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:n.label}),e[30]=n.label,e[31]=L):L=e[31];let M;e[32]!==o?(M=t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:o}),e[32]=o,e[33]=M):M=e[33];let B;e[34]!==r||e[35]!==P?(B=P?t.jsx(Es,{className:te("size-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-180")}):null,e[34]=r,e[35]=P,e[36]=B):B=e[36];let H;e[37]!==r||e[38]!==i||e[39]!==j||e[40]!==V||e[41]!==h||e[42]!==L||e[43]!==M||e[44]!==B?(H=t.jsxs("button",{type:"button",className:"flex min-h-9 min-w-0 flex-1 items-center gap-2 rounded-xl px-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",onClick:i,"aria-expanded":r,"aria-label":j,disabled:V,style:z,children:[h,L,M,B]}),e[37]=r,e[38]=i,e[39]=j,e[40]=V,e[41]=h,e[42]=L,e[43]=M,e[44]=B,e[45]=H):H=e[45];let Z;e[46]!==R||e[47]!==H?(Z=t.jsxs("div",{className:"flex items-center gap-1",children:[R,H]}),e[46]=R,e[47]=H,e[48]=Z):Z=e[48];let Q;e[49]!==r||e[50]!==N||e[51]!==P||e[52]!==n.worktrees||e[53]!==I?(Q=r&&P?t.jsx(Ts,{sensors:I,collisionDetection:Is,onDragEnd:N,children:t.jsx(As,{items:n.worktrees.map(Nl),strategy:Ds,children:t.jsx("div",{className:"mt-1 flex flex-col gap-0.5 pl-3",children:n.worktrees.map(El)})})}):null,e[49]=r,e[50]=N,e[51]=P,e[52]=n.worktrees,e[53]=I,e[54]=Q):Q=e[54];let _;return e[55]!==p||e[56]!==Z||e[57]!==Q||e[58]!==w||e[59]!==y?(_=t.jsxs("div",{ref:p,style:w,className:y,children:[Z,Q]}),e[55]=p,e[56]=Z,e[57]=Q,e[58]=w,e[59]=y,e[60]=_):_=e[60],_},An=({open:s,onOpenChange:e,variant:n="drawer",footer:o})=>{const{t:r}=ue(),{git:i}=js(),a=Qn(),c=gs(m=>m.activeSessions),d=Kn(l.useCallback(m=>s||n==="sidebar"?m.ids:ul,[s,n])),u=qn(l.useCallback(m=>s||n==="sidebar"?m.rankById:wo,[s,n])),f=Oe(m=>m.projects),p=Oe(m=>m.activeProjectId),b=dt(m=>m.currentDirectory),x=ve(m=>m.currentSessionId),v=ve(m=>m.setCurrentSession),S=ve(m=>m.archiveSession),g=ve(m=>m.deleteSession),I=ve(m=>m.updateSessionTitle),P=ve(m=>m.openNewSessionDraft),T=Oe(m=>m.setActiveProject),N=Oe(m=>m.setActiveProjectIdOnly),E=Oe(m=>m.reorderProjects),D=Oe(m=>m.removeProject),w=zt(m=>m.projectExpanded),C=zt(m=>m.worktreeExpanded),y=zt(m=>m.setProjectExpanded),k=zt(m=>m.setWorktreeExpanded),A=ms(m=>m.orderByProject),R=ms(m=>m.setWorktreeOrder),j=Nn(m=>m.expandedParents),V=Nn(m=>m.toggleParent),[z,h]=l.useState(""),[L,M]=l.useState(null),[B,H]=l.useState(null),[Z,Q]=l.useState(null),[_,J]=l.useState(null),[q,F]=l.useState(null),[U,X]=l.useState(null),[ee,W]=l.useState(null),[oe,ie]=l.useState(0),[fe,je]=l.useState(!1),[Y,ce]=l.useState(!1),[Se,Ae]=l.useState(null),[Re,Ie]=l.useState(()=>new Map(ve.getState().availableWorktreesByProject)),[ke,_e]=l.useState(()=>{const m=new Set;for(const[G,K]of ve.getState().availableWorktreesByProject)K.length>0&&m.add(G);return m}),[be,O]=l.useState(!1),[$,re]=l.useState(new Set),[me,Me]=l.useState(new Map);l.useEffect(()=>{if(!s){h(""),O(!1),re(new Set),Me(new Map),M(null),H(null),Q(null),J(null),F(null),X(null);return}vs(a)},[s]),l.useEffect(()=>{be||re(new Set)},[be]),l.useEffect(()=>{if(!s||f.length===0)return;let m=!1;return(async()=>{const K=await Promise.all(f.map(async ae=>{const Ne=we(ae.path);if(!Ne)return null;const pe=await i.checkIsGitRepository(Ne).catch(()=>!1),De=pe?await sr({id:ae.id,path:Ne}).catch(()=>[]):[];return[Ne,De,pe]}));if(m)return;const ne=new Map,ye=new Set;for(const ae of K)ae&&(ne.set(ae[0],ae[1]),ae[2]&&ye.add(ae[0]));Ie(nr(f,ne)),_e(ye)})(),()=>{m=!0}},[i,s,f,oe]);const xe=l.useMemo(()=>f.map(m=>({id:m.id,label:m.label?.trim()||ns(m.path),path:we(m.path),icon:m.icon,color:m.color,iconImage:m.iconImage,iconBackground:m.iconBackground,isGitRepo:ke.has(we(m.path)),worktrees:ol(A[m.id],Re.get(we(m.path))??[])})),[ke,f,A,Re]),We=l.useMemo(()=>{const m=new Map(a.map(ne=>[ne.id,ne])),G=c.map(ne=>{const ye=m.get(ne.id);return ye?jo(ye,ne):ne}),K=new Set(G.map(ne=>ne.id));for(const ne of a)K.has(ne.id)||G.push(ne);return G.filter(ne=>!ne.time?.archived)},[c,a]),Te=z.trim().toLowerCase(),It=l.useRef(null);l.useEffect(()=>{if(!s)return;const m=window.requestAnimationFrame(()=>{const G=It.current;if(!G)return;(G.querySelector('[data-active-session="true"]')??G.querySelector('[data-active-project="true"]'))?.scrollIntoView({block:"center"})});return()=>window.cancelAnimationFrame(m)},[s]);const _t=l.useMemo(()=>{const m=xe.map(K=>({project:K,buckets:[],totalSessions:0,isActive:K.id===p})),G=(K,ne,ye)=>{const ae=we(ne)||K.project.path,Ne=ae||"__root__";let pe=K.buckets.find(De=>De.key===Ne);return pe||(pe={key:Ne,label:ye?.branch||ns(ae),path:ae,worktree:ye,sessions:[]},K.buckets.push(pe)),pe};for(const K of m){G(K,K.project.path,null);for(const ne of K.project.worktrees)G(K,ne.path,ne)}for(const K of We){const ne=ot(K);if(!ne)continue;const ye=we(ne),ae=m.find(De=>ps(De.project,ye));if(!ae)continue;const Ne=Wt(ae.project,ye);(Ne?G(ae,Ne.path,Ne):G(ae,ae.project.path,null)).sessions.push(K)}for(const K of m)for(const ne of K.buckets){ne.sessions=cn(ne.sessions,d,u);for(const ye of ne.sessions)xt(ye)||(K.totalSessions+=1)}return m},[p,d,xe,u,We]),Hs=we(b),Pr=m=>m.isActive?Hs===m.project.path?m.project.path:m.project.worktrees.find(K=>hl(Hs,K.path))?.path??m.project.path:null,Tr=m=>w[m.project.id]??!0,Ir=(m,G)=>C[`${m.project.id}::${G.key}`]??!0,Gs=m=>{Me(G=>{if(!G.has(m))return G;const K=new Map(G);return K.delete(m),K})},_r=m=>{Me(G=>{let K=!1;const ne=new Map(G),ye=`${m}::`;for(const ae of ne.keys())ae.startsWith(ye)&&(ne.delete(ae),K=!0);return K?ne:G})},Ar=(m,G)=>{Me(K=>{const ne=new Map(K);return ne.set(m,G+os),ne})},Ks=(m,G,K)=>{const ne=`${m.project.id}::${G.key}`,ye=new Set(G.sessions.map(he=>he.id)),ae=new Map;for(const he of G.sessions){const Fe=xt(he);if(Fe&&ye.has(Fe)){const ht=ae.get(Fe)??[];ht.push(he),ae.set(Fe,ht)}}const Ne=G.sessions.filter(he=>{const Fe=xt(he);return!Fe||!ye.has(Fe)}),pe=me.get(ne)??os,De=Ne.slice(0,pe),nt=Ne.length-De.length,Xt=Ne.length>os&&nt===0,en=(he,Fe)=>{const ht=ae.get(he.id)??[],Zt=ht.length>0,tn=!!j[he.id];return t.jsxs(l.Fragment,{children:[t.jsx(_n,{session:he,active:x===he.id,indent:Fe,hasChildren:Zt,expanded:tn,onToggleChildren:Zt?()=>V(he.id):void 0,onSelect:()=>qs(he),revealed:B===he.id,onRevealedChange:bt=>Lr(he.id,bt),confirmingDelete:Z===he.id,onArchive:()=>{zr(he)},onRequestDelete:()=>Q(he.id),onConfirmDelete:()=>{Or(he)},renaming:_===he.id,onRequestRename:()=>Br(he.id),onSubmitRename:bt=>{$r(he.id,bt)},onCancelRename:()=>J(null)}),Zt&&tn?ht.map(bt=>en(bt,Fe+fl)):null]},he.id)};return t.jsxs("div",{children:[De.map(he=>en(he,K)),nt>0?t.jsx(gl,{indent:K,onClick:()=>Ar(ne,De.length)}):null,Xt?t.jsx(xl,{indent:K,onClick:()=>Gs(ne)}):null]})},Dr=(m,G)=>{y(m,!G),_r(m)},Mr=(m,G,K)=>{k(`${m}::${G}`,!K),Gs(`${m}::${G}`)},qs=m=>{const G=ot(m)||null,K=is(xe,G??"");if(K){N(K.id),y(K.id,!0);const ne=Wt(K,we(G??""));ne&&k(`${K.id}::${we(ne.path)}`,!0)}v(m.id,G),e(!1)},Lr=(m,G)=>{H(G?m:null),Q(null),F(null),X(null)},At=(m,G)=>{F(G?m:null),X(null),H(null),Q(null)},zr=async m=>{H(null),Q(null),await S(m.id)?le.success(r("sessions.sidebar.session.archive.success")):le.error(r("sessions.sidebar.session.archive.error"))},Or=async m=>{H(null),Q(null),await g(m.id)?le.success(r("sessions.sidebar.session.delete.success")):le.error(r("sessions.sidebar.session.delete.error"))},Br=m=>{H(null),Q(null),J(m)},$r=async(m,G)=>{J(null);try{await I(m,G)}catch{le.error(r("mobile.sessions.renameError"))}},Fr=()=>{P(),e(!1)},Ys=m=>{Ae(m),N(m),ce(!0)},Wr=Cs(ut(Ps,{activationConstraint:{distance:8}}),ut(Rs,{coordinateGetter:_s})),Ur=m=>{const{active:G,over:K}=m;if(!K||G.id===K.id)return;const ne=xe.findIndex(ae=>ae.id===G.id),ye=xe.findIndex(ae=>ae.id===K.id);ne<0||ye<0||E(ne,ye)},Vr=m=>{re(G=>{const K=new Set(G);return K.has(m)?K.delete(m):K.add(m),K})},Hr=l.useCallback(m=>{const G=ot(m),K=is(xe,G);if(!K)return ns(G)||G;const ne=Wt(K,we(G));return ne?.branch?`${K.label} · ${ne.branch}`:K.label},[xe]),Gr=m=>{T(m.id),e(!1)},Kr=l.useMemo(()=>Te?_t.filter(m=>`${m.project.label} ${m.project.path}`.toLowerCase().includes(Te)?!0:m.buckets.some(G=>G.sessions.some(K=>as(K,m.project.label,Te)))):_t,[Te,_t]),Dt=l.useMemo(()=>Te?cn(We.filter(m=>{if(xt(m))return!1;const G=ot(m),K=is(xe,G);return as(m,K?.label??"",Te)}),d,u):[],[Te,d,xe,u,We]),Mt=l.useMemo(()=>Te?xe.filter(m=>`${m.label} ${m.path}`.toLowerCase().includes(Te)).map(m=>({...m,sessionCount:We.filter(G=>{if(xt(G))return!1;const K=we(ot(G));return ps(m,K)}).length})):[],[Te,xe,We]),qr=Te&&Dt.length===0&&Mt.length===0,Js=!Te&&xe.length>1?t.jsx(ge,{type:"button",variant:"chip",size:"sm","aria-label":r(be?"mobile.sessions.doneEditing":"mobile.sessions.editOrder"),"aria-pressed":be,onClick:()=>O(m=>!m),style:{touchAction:"manipulation"},children:be?t.jsx(rr,{className:"size-4"}):t.jsx(ds,{className:"size-4"})}):null,Qs=!be&&xe.length>0?t.jsxs(ge,{type:"button",variant:"default",size:"sm","aria-label":r("mobile.sessions.newChat"),onClick:Fr,style:{touchAction:"manipulation"},children:[t.jsx(Fi,{className:"size-4"}),r("mobile.sessions.newChat")]}):null,Xs=be?null:t.jsx(ge,{type:"button",variant:"chip",size:"sm","aria-label":r("sessions.sidebar.header.actions.addProject"),title:r("sessions.sidebar.header.actions.addProject"),onClick:()=>je(!0),style:{touchAction:"manipulation"},children:t.jsx(un,{className:"size-4"})}),Lt=Qs||Xs||Js?t.jsxs(t.Fragment,{children:[Qs,Xs,Js]}):null,Zs=t.jsxs("div",{ref:It,className:"flex min-h-0 flex-1 flex-col",children:[t.jsxs(ks,{className:"min-h-0 flex-1 overflow-y-auto pb-4",children:[t.jsx("div",{className:te("px-4 pb-2 pt-1",be&&"hidden"),children:t.jsxs("div",{className:"relative",children:[t.jsx(or,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ws,{value:z,onChange:m=>h(m.target.value),placeholder:r("mobile.sessions.search.placeholder"),className:te("h-11 pl-9",z&&"pr-10")}),z?t.jsx("button",{type:"button",className:"absolute right-1.5 top-1/2 flex size-8 -translate-y-1/2 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.sessions.clearSearchAria"),onClick:()=>h(""),style:{touchAction:"manipulation"},children:t.jsx(ir,{className:"size-4"})}):null]})}),xe.length===0?t.jsx(Ln,{title:r("mobile.sessions.empty.noProjectsTitle"),description:r("mobile.sessions.empty.noProjectsDescription"),action:t.jsxs("button",{type:"button",className:"flex items-center justify-center gap-2 rounded-2xl bg-primary px-5 py-3 typography-ui-label text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:()=>je(!0),children:[t.jsx(un,{className:"size-4"}),r("sessions.sidebar.header.actions.addProject")]})}):qr?t.jsx(Ln,{title:r("mobile.sessions.empty.searchTitle"),description:r("mobile.sessions.empty.searchDescription")}):Te&&!be?t.jsxs("div",{className:"flex flex-col gap-3 px-3 pt-2",children:[Dt.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.sessions")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Dt.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Dt.map((m,G)=>t.jsx("div",{className:te(G>0&&"border-t border-border/70"),children:t.jsx(_n,{session:m,active:x===m.id,indent:12,contextLabel:Hr(m),onSelect:()=>qs(m)})},m.id))})]}):null,Mt.length>0?t.jsxs("section",{children:[t.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5",children:[t.jsx("span",{className:"typography-micro font-semibold uppercase tracking-wider text-muted-foreground",children:r("mobile.sessions.search.section.projects")}),t.jsx("span",{className:"typography-micro text-muted-foreground tabular-nums",children:Mt.length})]}),t.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:Mt.map((m,G)=>t.jsxs("div",{className:te("flex items-center",G>0&&"border-t border-border/70"),children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-3 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>Gr(m),style:{touchAction:"manipulation"},children:[t.jsx(hs,{project:m}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:m.label}),t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:m.sessionCount})]}),m.isGitRepo?t.jsx(Tn,{className:"mr-2",onClick:()=>Ys(m.id)}):null]},m.id))})]}):null]}):be?t.jsxs("div",{className:"flex flex-col gap-2 px-3 py-2",children:[t.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:r("mobile.sessions.editOrderHint")}),t.jsx(Ts,{sensors:Wr,collisionDetection:Is,onDragEnd:Ur,children:t.jsx(As,{items:xe.map(m=>m.id),strategy:Ds,children:t.jsx("div",{className:"flex flex-col gap-1.5",children:xe.map(m=>{const G=_t.find(K=>K.project.id===m.id);return t.jsx(vl,{project:m,totalSessions:G?.totalSessions??0,expanded:$.has(m.id),onToggleExpanded:()=>Vr(m.id),onReorderWorktrees:K=>R(m.id,K)},m.id)})})})})]}):t.jsx("div",{className:"flex flex-col",children:Kr.map((m,G)=>{const K=Tr(m),ne=Te?m.buckets.filter(ae=>ae.sessions.some(Ne=>as(Ne,m.project.label,Te))):m.buckets,ye=Pr(m);return t.jsxs("section",{className:te(G>0&&"border-t border-border/70"),children:[t.jsx(In,{actionsWidth:96,revealed:q===`project:${m.project.id}`,onRevealedChange:ae=>At(`project:${m.project.id}`,ae),actions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",tabIndex:q===`project:${m.project.id}`?0:-1,className:"flex flex-1 items-center justify-center text-muted-foreground transition-colors active:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary","aria-label":r("mobile.sessions.editProjectAria",{label:m.project.label}),onClick:()=>{F(null),M(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(ds,{className:"size-[18px]"})}),t.jsx("button",{type:"button",tabIndex:q===`project:${m.project.id}`?0:-1,className:te("flex flex-1 items-center justify-center transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive",U===m.project.id?"rounded-lg bg-destructive text-destructive-foreground":"text-[var(--status-error)] active:opacity-80"),"aria-label":U===m.project.id?r("mobile.sessions.confirmRemoveProjectAria",{label:m.project.label}):r("mobile.sessions.removeProjectAria",{label:m.project.label}),onClick:()=>{if(U===m.project.id){F(null),X(null),D(m.project.id),le.success(r("mobile.sessions.toast.projectRemoved",{label:m.project.label}));return}X(m.project.id)},style:{touchAction:"manipulation"},children:t.jsx(Ut,{className:"size-[18px]"})})]}),children:t.jsxs("div",{"data-active-project":m.isActive||void 0,className:"flex min-h-12 w-full items-center",children:[t.jsxs("button",{type:"button",className:"flex min-h-12 min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>{if(q){At(q,!1);return}Dr(m.project.id,K)},"aria-expanded":K,"aria-label":K?r("sessions.sidebar.group.collapseAria",{label:m.project.label}):r("sessions.sidebar.group.expandAria",{label:m.project.label}),style:{touchAction:"manipulation"},children:[t.jsx(hs,{project:m.project}),t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground",children:m.project.label}),m.isActive?t.jsx(Pn,{ariaLabel:r("mobile.sessions.activeProjectAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:m.totalSessions})]}),m.project.isGitRepo?t.jsx(Tn,{className:"mr-2",onClick:()=>Ys(m.project.id)}):null]})}),K?t.jsx("div",{className:"pb-2",children:(()=>{const ae=ne.find(pe=>pe.worktree===null),Ne=ne.filter(pe=>pe.worktree!==null);return t.jsxs(t.Fragment,{children:[ae&&ae.sessions.length>0?Ks(m,ae,Rn):null,Ne.map(pe=>{const De=Ir(m,pe),nt=ye===pe.path;return t.jsxs("div",{children:[t.jsx(In,{actionsWidth:48,revealed:q===`wt:${pe.key}`,onRevealedChange:Xt=>At(`wt:${pe.key}`,Xt),actions:t.jsx("button",{type:"button",tabIndex:q===`wt:${pe.key}`?0:-1,className:"flex flex-1 items-center justify-center text-[var(--status-error)] transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-destructive","aria-label":r("mobile.projectEdit.deleteWorktreeAria",{label:pe.label}),onClick:()=>{F(null),pe.worktree&&W({project:m.project,worktree:pe.worktree})},style:{touchAction:"manipulation"},children:t.jsx(Ut,{className:"size-[18px]"})}),children:t.jsxs("button",{type:"button",className:"flex min-h-10 w-full items-center gap-2 px-3 py-1 text-left transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:()=>{if(q){At(q,!1);return}Mr(m.project.id,pe.key,De)},"aria-expanded":De,"aria-label":De?r("sessions.sidebar.group.collapseAria",{label:pe.label}):r("sessions.sidebar.group.expandAria",{label:pe.label}),style:{touchAction:"manipulation"},children:[t.jsx(se,{name:"git-branch",className:te("size-4 shrink-0",nt?"text-primary":"text-muted-foreground")}),t.jsx("span",{className:te("block min-w-0 flex-1 truncate typography-ui-label font-bold",nt?"text-foreground":"text-muted-foreground"),children:pe.label}),nt?t.jsx(Pn,{ariaLabel:r("mobile.sessions.activeWorktreeAria")}):null,t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground tabular-nums",children:pe.sessions.length})]})}),De?Ks(m,pe,Rn):null]},pe.key)})]})})()}):null]},m.project.id)})})]}),o?t.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/70 px-2 pt-1.5",style:{paddingBottom:"calc(0.375rem + var(--oc-safe-area-bottom, 0px))"},children:[o.instanceLabel&&o.onOpenInstances?t.jsxs(ge,{type:"button",variant:"info",size:"lg",className:"min-w-0 shrink justify-start",onClick:o.onOpenInstances,"aria-label":r("mobile.menu.instances"),style:{touchAction:"manipulation"},children:[t.jsx(se,{name:"server",className:"size-[18px]"}),t.jsx("span",{className:"block min-w-0 truncate",children:o.instanceLabel})]}):t.jsx("div",{className:"min-w-0 flex-1"}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o.onOpenUpdate?t.jsxs(ge,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenUpdate,"aria-label":r("mobile.menu.update"),title:r("mobile.menu.update"),style:{touchAction:"manipulation"},children:[t.jsx(se,{name:"download",className:"size-5"}),t.jsx("span",{className:"absolute right-2 top-2 inline-flex size-2 rounded-full bg-primary","aria-hidden":!0})]}):null,t.jsx(ge,{type:"button",variant:"default",size:"lg",className:"w-10 px-0",onClick:o.onOpenSettings,"aria-label":r("mobile.menu.settings"),title:r("mobile.menu.settings"),style:{touchAction:"manipulation"},children:t.jsx(se,{name:"settings-3",className:"size-5"})})]})]}):null,t.jsx(bi,{open:fe,onOpenChange:je}),t.jsx(gi,{open:Y,onOpenChange:m=>{ce(m),m||Ae(null)},onWorktreeCreated:(m,G)=>{G?.sessionId?v(G.sessionId,m):P({selectedProjectId:Se,directoryOverride:m,preserveDirectoryOverride:!0}),e(!1)}}),t.jsx(dl,{open:L!==null,project:xe.find(m=>m.id===L)??null,onClose:()=>M(null),onWorktreesChanged:()=>ie(m=>m+1)}),ee?t.jsx(Sr,{open:!0,project:{id:ee.project.id,path:ee.project.path},worktree:ee.worktree,onClose:()=>W(null),onDeleted:()=>ie(m=>m+1)}):null]});return n==="sidebar"?s?t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center justify-between gap-2 border-b border-border/70 px-4",children:[t.jsx("h2",{className:"truncate typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Lt?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Lt}):null]}),Zs]}):null:t.jsxs(kl,{open:s,onClose:()=>e(!1),ariaLabel:r("mobile.sessions.sheet.title"),children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":r("mobile.surface.closeAria"),onClick:()=>e(!1),style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})}),t.jsx("h2",{className:"min-w-0 flex-1 truncate px-1 typography-ui-label font-semibold text-foreground",children:r("mobile.sessions.sheet.title")}),Lt?t.jsx("div",{className:"flex shrink-0 items-center gap-2",children:Lt}):null]}),Zs]})},Dn="mobile-surface-root",wl=16,Mn=320,jl="cubic-bezier(0.22, 1, 0.36, 1)",kl=({open:s,onClose:e,ariaLabel:n,children:o})=>{const r=l.useRef(null),[i,a]=l.useState(!1),[c,d]=l.useState(s),u=l.useRef(e);if(l.useEffect(()=>{u.current=e},[e]),typeof document<"u"&&!r.current){let f=document.getElementById(Dn);f||(f=document.createElement("div"),f.id=Dn,document.body.appendChild(f)),r.current=f}return l.useEffect(()=>{if(s){d(!0);const p=window.setTimeout(()=>a(!0),wl);return()=>window.clearTimeout(p)}a(!1);const f=window.setTimeout(()=>d(!1),Mn+40);return()=>window.clearTimeout(f)},[s]),l.useEffect(()=>{if(!s)return;const f=document.body.style.overflow;document.body.style.overflow="hidden";const p=b=>{b.key==="Escape"&&u.current()};return document.addEventListener("keydown",p),()=>{document.body.style.overflow=f,document.removeEventListener("keydown",p)}},[s]),r.current?ct.createPortal(t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":n,"aria-hidden":!s,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:i?"none":"translateX(-100%)",transition:`transform ${Mn}ms ${jl}`,visibility:c?"visible":"hidden",pointerEvents:s?"auto":"none"},children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:o})}),r.current):null},Ln=s=>{const e=de.c(10),{title:n,description:o,action:r}=s;let i;e[0]!==n?(i=t.jsx("p",{className:"typography-ui-label text-foreground",children:n}),e[0]=n,e[1]=i):i=e[1];let a;e[2]!==o?(a=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[2]=o,e[3]=a):a=e[3];let c;e[4]!==r?(c=r?t.jsx("div",{className:"pt-2",children:r}):null,e[4]=r,e[5]=c):c=e[5];let d;return e[6]!==i||e[7]!==a||e[8]!==c?(d=t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[i,a,c]}),e[6]=i,e[7]=a,e[8]=c,e[9]=d):d=e[9],d};function Sl(s){return we(s.path)}function Nl(s){return we(s.path)}function El(s){return t.jsx(yl,{worktree:s},we(s.path))}const Cl=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),Rl=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Pl=s=>{const e=s.working_dir?.trim(),n=s.index?.trim();return!!(e||n==="?")},zn=(s,e)=>e?`${s}\0staged`:s,Tl=({onClose:s,initialDiffPath:e,initialDiffStaged:n=!1})=>{const{t:o}=ue(),{git:r}=js(),i=Cl(Ss()??null),a=ko(i||null),c=So(i||null),d=No(i||null),u=Ue(O=>O.setActiveDirectory),f=Ue(O=>O.ensureAll),p=Ue(O=>O.fetchStatus),b=Ue(O=>O.fetchBranches),x=Ue(O=>O.prefetchDiffs),v=Ue(O=>O.getDiff),S=Ue(O=>O.setDiff),[g,I]=l.useState(()=>e?{type:"diff",path:e,staged:n}:{type:"list"});l.useEffect(()=>{e&&I(O=>O.type==="diff"&&O.path===e&&O.staged===n?O:{type:"diff",path:e,staged:n})},[e,n]);const[P,T]=l.useState(null),[N,E]=l.useState(null),[D,w]=l.useState(""),[C,y]=l.useState(new Set),[k,A]=l.useState(!1),[R,j]=l.useState(!1),[V,z]=l.useState([]),[h,L]=l.useState([]),[M,B]=l.useState([]),[H,Z]=l.useState(null),[Q,_]=l.useState(null),[J,q]=l.useState(0),F=l.useMemo(()=>{const O=a?.files??[],$=new Map;for(const re of O)$.set(re.path,re);return Array.from($.values()).sort((re,me)=>re.path.localeCompare(me.path))},[a?.files]),U=l.useMemo(()=>F.filter(Rl),[F]),X=l.useMemo(()=>F.filter(Pl),[F]),ee=l.useMemo(()=>{if(M.length>0)return M;const O=a?.tracking?.includes("/")?a.tracking.split("/")[0]:null;return O||H?[{name:O||"origin",fetchUrl:H??"",pushUrl:H??""}]:[]},[H,M,a?.tracking]),W=Ue(l.useCallback(O=>!i||g.type!=="diff"?null:O.directories.get(i)?.diffCache.get(zn(g.path,g.staged))??null,[i,g])),oe=l.useMemo(()=>g.type!=="diff"?null:F.find(O=>O.path===g.path)??null,[F,g]),ie=l.useCallback(async(O=!0)=>{if(i)try{await Promise.all([p(i,r),b(i,r)])}catch($){O&&le.error($ instanceof Error?$.message:o("gitView.toast.refreshRepositoryFailed"))}},[i,b,p,r,o]),fe=l.useCallback(async()=>{if(!i){B([]),Z(null);return}try{const[O,$]=await Promise.all([r.getRemotes(i).catch(()=>[]),r.getRemoteUrl?r.getRemoteUrl(i).catch(()=>null):Promise.resolve(null)]);B(O),Z($)}catch{B([]),Z(null)}},[i,r]);l.useEffect(()=>{i&&(u(i),f(i,r))},[i,f,r,u]),l.useEffect(()=>{fe()},[fe]),l.useEffect(()=>{if(!i||F.length===0)return;const O=Array.from(new Set([...U.map(re=>re.path),...h,...F.slice(0,20).map(re=>re.path)])).filter(Boolean);if(O.length===0)return;const $=window.setTimeout(()=>{x(i,r,O,{maxFiles:40})},120);return()=>window.clearTimeout($)},[F,i,r,x,U,h]),l.useEffect(()=>{if(g.type!=="diff"){_(null);return}const O=zn(g.path,g.staged);if(!i||v(i,O)){_(null);return}let $=!1;const re=Pt();return _(null),r.getGitFileDiff(i,{path:g.path,staged:g.staged||void 0}).then(me=>{$||S(i,O,{original:me.original??"",modified:me.modified??"",isBinary:me.isBinary},re)}).catch(me=>{$||_(me instanceof Error?me.message:String(me))}),()=>{$=!0}},[i,J,v,r,g,S]);const je=async(O,$)=>{if(i){T(O);try{const re=me=>{const Me=`${me.name}/`,xe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;return{remote:me.name,branch:xe,rebase:!0}};if(O==="fetch"){if(!$)throw new Error(o("mobile.changes.noRemote"));await r.gitFetch(i,{remote:$.name}),le.success(o("gitView.toast.fetchedFromRemote",{name:$.name}))}else if(O==="sync"){if(!$)throw new Error(o("mobile.changes.noRemote"));await r.gitFetch(i,{remote:$.name});const me=await r.getGitStatus(i);if((me.behind??0)>0){if((me.files?.length??0)>0){le.error(o("gitView.toast.commitOrStashBeforeSync"));return}await r.gitPull(i,re($))}((await r.getGitStatus(i)).ahead??0)>0&&await r.gitPush(i),le.success(o("gitView.toast.alreadyUpToDate"))}await ie(!1),await fe()}catch(re){le.error(re instanceof Error?re.message:o("gitView.toast.syncActionFailed",{action:o("gitView.sync.syncChanges")}))}finally{T(null)}}},Y=l.useCallback(async(O,$)=>{if(!(!i||O.length===0))try{$==="stage"?O.length>1?await Eo(i,O):await Co(i,O[0]):O.length>1?await Ro(i,O):await Po(i,O[0]),await ie(!1)}catch(re){le.error(re instanceof Error?re.message:o($==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed"))}},[i,ie,o]),ce=l.useCallback((O,$=!1)=>{I({type:"diff",path:O,staged:$})},[]),Se=l.useCallback(async O=>{if(i){y($=>new Set($).add(O));try{await r.revertGitFile(i,O),le.success(o("gitView.toast.revertedFile",{path:O})),await ie(!1)}catch($){le.error($ instanceof Error?$.message:o("gitView.toast.revertFailed"))}finally{y($=>{const re=new Set($);return re.delete(O),re})}}},[i,r,ie,o]),Ae=l.useCallback(async O=>{if(!i||O.length===0||k)return;const $=Array.from(new Set(O));A(!0),y(new Set($));try{await Promise.all($.map(re=>r.revertGitFile(i,re))),await ie(!1),le.success($.length===1?o("gitView.toast.revertedFilesSingle",{count:$.length}):o("gitView.toast.revertedFilesPlural",{count:$.length}))}catch(re){le.error(re instanceof Error?re.message:o("gitView.toast.revertFailed"))}finally{y(new Set),A(!1)}},[i,r,k,ie,o]),Re=l.useCallback(O=>{const $=O.map(re=>re.trim()).filter(Boolean);if($.length===0){z([]);return}w(re=>`${re.trim()}${re.trim()?`
|
|
21
21
|
|
|
22
22
|
`:""}${$.join(`
|
|
23
|
-
`)}`.trim()),z([])},[]),Ie=l.useCallback(async()=>{if(!i)return;const O=U.map($=>$.path).sort();if(O.length===0){le.error(o("gitView.toast.selectFileToDescribe"));return}j(!0);try{const{message:$}=await To(i,O);w($.subject?.trim()??""),z(Array.isArray($.highlights)?$.highlights:[])}catch($){le.error($ instanceof Error?$.message:o("gitView.toast.generateCommitMessageFailed"))}finally{j(!1)}},[i,U,o]),ke=async(O={})=>{if(!i)return;if(!D.trim()){le.error(o("gitView.toast.enterCommitMessage"));return}const $=U.map(re=>re.path).sort();if($.length===0){le.error(o("gitView.toast.selectFileToCommit"));return}E(O.pushAfter?"commitAndPush":"commit");try{if(await r.createGitCommit(i,D.trim(),{files:$}),le.success(o("gitView.toast.commitCreated")),w(""),z([]),O.pushAfter){const re=a?.tracking?.split("/")[0],me=ee.find(It=>It.name===re)??ee[0];if(!me)throw new Error(o("mobile.changes.noRemote"));T("sync");const Me=`${me.name}/`,xe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;await r.gitFetch(i,{remote:me.name}),((await r.getGitStatus(i)).behind??0)>0&&await r.gitPull(i,{remote:me.name,branch:xe,rebase:!0}),((await r.getGitStatus(i)).ahead??0)>0&&await r.gitPush(i),await ie(!1),await fe()}else await ie(!1)}catch(re){le.error(re instanceof Error?re.message:o("gitView.toast.createCommitFailed"))}finally{E(null),O.pushAfter&&T(null)}},_e=l.useMemo(()=>{const O=[];return U.length>0&&O.push({id:"staged",title:o("gitView.changes.stagedTitle"),entries:U,actionSymbol:"-",actionAllLabel:o("gitView.changes.unstageAllAria"),getActionLabel:$=>o("gitView.changes.unstageFileAria",{path:$}),onActionFile:$=>{Y([$],"unstage")},onActionAll:$=>{Y($,"unstage")},onViewDiff:$=>ce($,!0),onRevertFile:Se,showRevertActions:!1,accent:!0}),X.length>0&&O.push({id:"unstaged",title:o("gitView.changes.title"),entries:X,actionSymbol:"+",actionAllLabel:o("gitView.changes.stageAllAria"),getActionLabel:$=>o("gitView.changes.stageFileAria",{path:$}),onActionFile:$=>{Y([$],"stage")},onActionAll:$=>{Y($,"stage")},onViewDiff:$=>ce($,!1),onRevertFile:Se}),O},[Se,ce,Y,U,o,X]),be=O=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||i||""})]})]}),t.jsx("div",{className:"min-h-0 flex-1",children:O})]});return i?d&&c===null?be(t.jsx(Ke,{loading:!0,message:o("gitView.loading.checkingRepository")})):c===!1?be(t.jsx(Ke,{icon:!0,message:o("gitView.empty.notGitRepository"),description:o("gitView.empty.notGitRepositoryDescription")})):g.type==="diff"?t.jsx(Il,{path:g.path,diff:W,fileExists:!!oe,error:Q,onBack:()=>I({type:"list"}),onRetry:()=>q(O=>O+1)}):t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||i})]}),t.jsx(xi,{syncAction:P,remotes:ee,onFetch:O=>{je("fetch",O)},onSync:O=>{je("sync",O)},disabled:N!==null||d,aheadCount:a?.ahead??0,behindCount:a?.behind??0,trackingRemoteName:a?.tracking?.split("/")[0],hasUncommittedChanges:F.length>0})]}),F.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(yi,{groups:_e,diffStats:a?.diffStats,revertingPaths:C,onRevertAll:Ae,isRevertingAll:k,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:L})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(vi,{stagedCount:U.length,commitMessage:D,onCommitMessageChange:w,generatedHighlights:V,onInsertHighlights:Re,onGenerateMessage:Ie,isGeneratingMessage:R,onCommit:()=>{ke({pushAfter:!1})},onCommitAndPush:()=>{ke({pushAfter:!0})},commitAction:N,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ke,{icon:!0,message:o("gitView.empty.cleanTitle"),description:o("mobile.changes.cleanDescription")})})]}):be(t.jsx(Ke,{message:o("gitView.empty.selectSessionOrDirectory")}))},Ke=s=>{const e=de.c(13),{message:n,description:o,loading:r,icon:i}=s,a=r===void 0?!1:r,c=i===void 0?!1:i;let d;e[0]!==a?(d=a?t.jsx(se,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=d):d=e[1];let u;e[2]!==c?(u=c?t.jsx(se,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=c,e[3]=u):u=e[3];let f;e[4]!==n?(f=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),e[4]=n,e[5]=f):f=e[5];let p;e[6]!==o?(p=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[6]=o,e[7]=p):p=e[7];let b;return e[8]!==d||e[9]!==u||e[10]!==f||e[11]!==p?(b=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[d,u,f,p]})}),e[8]=d,e[9]=u,e[10]=f,e[11]=p,e[12]=b):b=e[12],b},Il=s=>{const e=de.c(24),{path:n,diff:o,fileExists:r,error:i,onBack:a,onRetry:c}=s,{t:d}=ue();let u;e[0]!==n?(u=Io(n)||"text",e[0]=n,e[1]=u):u=e[1];const f=u;let p;e[2]!==d?(p=d("header.actions.backAria"),e[2]=d,e[3]=p):p=e[3];let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b=t.jsx(se,{name:"arrow-left",className:"size-5"}),e[4]=b):b=e[4];let x;e[5]!==a||e[6]!==p?(x=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":p,onClick:a,children:b}),e[5]=a,e[6]=p,e[7]=x):x=e[7];let v;e[8]!==n?(v=t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:n})}),e[8]=n,e[9]=v):v=e[9];let S;e[10]!==x||e[11]!==v?(S=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/70 px-3 text-foreground",children:[x,v]}),e[10]=x,e[11]=v,e[12]=S):S=e[12];let g;e[13]!==o||e[14]!==i||e[15]!==r||e[16]!==f||e[17]!==c||e[18]!==n||e[19]!==d?(g=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r?i?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:d("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}),t.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:c,children:d("diffView.actions.retry")})]})}):o?o.isBinary?t.jsx(Ke,{icon:!0,message:d("diffView.binary.unavailable")}):_o(n)?t.jsx(Ke,{icon:!0,message:d("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(ks,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(wi,{original:o.original,modified:o.modified,language:f,fileName:n,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(Ke,{loading:!0,message:d("diffView.state.loadingDiff")}):t.jsx(Ke,{icon:!0,message:d("mobile.changes.diffDetail.missingTitle"),description:d("mobile.changes.diffDetail.missingDescription")})}),e[13]=o,e[14]=i,e[15]=r,e[16]=f,e[17]=c,e[18]=n,e[19]=d,e[20]=g):g=e[20];let I;return e[21]!==S||e[22]!==g?(I=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[S,g]}),e[21]=S,e[22]=g,e[23]=I):I=e[23],I},_l=l.lazy(()=>$e(()=>import("./FilesView-BDRX8vU2.js").then(s=>s.a),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116])).then(s=>({default:s.FilesView}))),tt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),St=s=>{const e=tt(s);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},Al=s=>{const e=tt(s);if(!e||e==="/")return null;const n=e.lastIndexOf("/");return n<=0?e.startsWith("/")?"/":null:e.slice(0,n)},Dl=(s,e)=>{const n=tt(s),o=tt(e);return!o||n===o?St(n):n.startsWith(`${o}/`)?n.slice(o.length+1):n},Ml=s=>{if(typeof s!="number"||!Number.isFinite(s)||s<0)return"";if(s<1024)return`${s} B`;const e=["KB","MB","GB"];let n=s/1024;for(const o of e){if(n<1024||o===e[e.length-1])return`${n.toFixed(n>=10?0:1)} ${o}`;n/=1024}return""},Ll=({onClose:s})=>{const{t:e}=ue(),{files:n}=js(),o=Xr(h=>h.setSelectedPath),r=tt(Ss()??null),[i,a]=l.useState(()=>({type:"browser",directory:r})),[c,d]=l.useState([]),[u,f]=l.useState(!1),[p,b]=l.useState(null),[x,v]=l.useState(""),[S,g]=l.useState([]),[I,P]=l.useState(!1),T=l.useRef(0);l.useEffect(()=>{r&&a(h=>h.type==="browser"&&h.directory?h:{type:"browser",directory:r})},[r]);const N=i.type==="browser"?i.directory:i.returnDirectory,E=l.useCallback(async h=>{if(!h)return;const L=T.current+1;T.current=L,f(!0),b(null);try{const M=await n.listDirectory(h);if(T.current!==L)return;d(M.entries.slice().sort((B,H)=>B.isDirectory!==H.isDirectory?B.isDirectory?-1:1:B.name.localeCompare(H.name)))}catch(M){if(T.current!==L)return;d([]),b(M instanceof Error?M.message:e("mobile.files.error.listFailed"))}finally{T.current===L&&f(!1)}},[n,e]);l.useEffect(()=>{i.type==="browser"&&E(i.directory)},[E,i]),l.useEffect(()=>{if(i.type!=="browser")return;const h=x.trim();if(!h){g([]),P(!1);return}let L=!1;const M=window.setTimeout(()=>{P(!0),n.search({directory:i.directory,query:h,maxResults:40}).then(B=>{L||g(B)}).catch(()=>{L||g([])}).finally(()=>{L||P(!1)})},250);return()=>{L=!0,window.clearTimeout(M)}},[n,x,i]);const D=h=>{v(""),a({type:"browser",directory:h})},w=h=>{o(r,h),a({type:"file",path:h,returnDirectory:N||r})},C=Ve(h=>h.pendingFileFocusPath),y=Ve(h=>h.pendingFileNavigation);if(l.useEffect(()=>{const h=tt(y?.path??C??"");!h||!r||h!==r&&!h.startsWith(`${r}/`)||(o(r,h),a({type:"file",path:h,returnDirectory:r}),C&&Ve.getState().setPendingFileFocusPath(null))},[C,y,r,o]),!r)return t.jsx(Nt,{message:e("mobile.files.empty.noDirectory")});if(i.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b border-border/70 px-3 text-foreground",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("header.actions.backAria"),onClick:()=>a({type:"browser",directory:i.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(fn,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:St(i.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Be,{children:t.jsx(l.Suspense,{fallback:t.jsx(Nt,{loading:!0,message:e("filesView.state.loading")}),children:t.jsx(_l,{mode:"editor-only"})})})})]});const k=i.directory===r?e("mobile.files.rootDirectory"):St(i.directory),A=x.trim()?S:[],R=Al(i.directory),j=i.directory!==r&&R!==null&&(R===r||R.startsWith(`${r}/`)),V=j&&!x.trim(),z=j?R:null;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(ir,{className:"size-5"})}):null,V&&z?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.backToParentAria",{name:St(z)}),onClick:()=>D(z),style:{touchAction:"manipulation"},children:t.jsx(fn,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:k})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.refreshAria"),onClick:()=>{E(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(Vi,{className:te("size-5",u&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(or,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ws,{value:x,onChange:h=>v(h.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(ks,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(Nt,{message:p}):x.trim()?t.jsx(zl,{results:A,isSearching:I,onOpenFile:w}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[c.length===0&&!u?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:e("mobile.files.empty.directory")}):null,c.map(h=>t.jsx(Er,{name:h.name,path:h.path,directory:h.isDirectory,meta:h.isDirectory?void 0:Ml(h.size),onClick:()=>h.isDirectory?D(h.path):w(h.path)},h.path))]})})]})},Er=s=>{const e=de.c(16),{name:n,path:o,directory:r,meta:i,onClick:a}=s;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={touchAction:"manipulation"},e[0]=c):c=e[0];let d;e[1]!==r||e[2]!==o?(d=r?t.jsx(Hi,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(Ao,{filePath:o,className:"size-5 shrink-0"}),e[1]=r,e[2]=o,e[3]=d):d=e[3];let u;e[4]!==n?(u=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:n}),e[4]=n,e[5]=u):u=e[5];let f;e[6]!==i?(f=i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,e[6]=i,e[7]=f):f=e[7];let p;e[8]!==r?(p=r?t.jsx(Gi,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=r,e[9]=p):p=e[9];let b;return e[10]!==a||e[11]!==d||e[12]!==u||e[13]!==f||e[14]!==p?(b=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:a,style:c,children:[d,u,f,p]}),e[10]=a,e[11]=d,e[12]=u,e[13]=f,e[14]=p,e[15]=b):b=e[15],b},zl=s=>{const e=de.c(10),{results:n,isSearching:o,onOpenFile:r}=s,{t:i}=ue(),a=tt(Ss()??null);if(o){let f;e[0]!==i?(f=i("common.loading"),e[0]=i,e[1]=f):f=e[1];let p;return e[2]!==f?(p=t.jsx(Nt,{loading:!0,message:f}),e[2]=f,e[3]=p):p=e[3],p}if(n.length===0){let f;e[4]!==i?(f=i("mobile.files.search.empty"),e[4]=i,e[5]=f):f=e[5];let p;return e[6]!==f?(p=t.jsx(Nt,{message:f}),e[6]=f,e[7]=p):p=e[7],p}const c="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",d=n.map(f=>t.jsx(Er,{name:St(f.path),path:f.path,directory:!1,meta:Dl(f.path,a),onClick:()=>r(f.path)},f.path));let u;return e[8]!==d?(u=t.jsx("div",{className:c,children:d}),e[8]=d,e[9]=u):u=e[9],u},Nt=s=>{const e=de.c(7),{message:n,loading:o}=s,r=o===void 0?!1:o;let i;e[0]!==r?(i=r?t.jsx(Ki,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(qi,{className:"size-6 text-muted-foreground"}),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==n?(a=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),e[2]=n,e[3]=a):a=e[3];let c;return e[4]!==i||e[5]!==a?(c=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[i,a]})}),e[4]=i,e[5]=a,e[6]=c):c=e[6],c},On="mobile-surface-root",Ol=16,Bn=320,Bl="cubic-bezier(0.22, 1, 0.36, 1)",$l=s=>{const e=de.c(36),{onOpenMcpSettings:n}=s,{t:o}=ue(),[r,i]=l.useState(!1),a=dt(Fl),c=Ei(Wl),d=Bt(Ul);let u;e[0]!==a||e[1]!==r||e[2]!==d||e[3]!==c?(u=()=>{if(r)return;i(!0);const k=new Promise(Vl);Promise.all([c({directory:a||null,silent:!0}),d({force:!0}),k]).finally(()=>i(!1))},e[0]=a,e[1]=r,e[2]=d,e[3]=c,e[4]=u):u=e[4];const f=u;let p;e[5]!==o?(p=o("settings.mcp.sidebar.actions.addServerTitle"),e[5]=o,e[6]=p):p=e[6];let b;e[7]!==o?(b=o("settings.mcp.sidebar.actions.addServerTitle"),e[7]=o,e[8]=b):b=e[8];let x,v;e[9]===Symbol.for("react.memo_cache_sentinel")?(x={touchAction:"manipulation"},v=t.jsx(se,{name:"add",className:"size-5"}),e[9]=x,e[10]=v):(x=e[9],v=e[10]);let S;e[11]!==n||e[12]!==p||e[13]!==b?(S=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:n,"aria-label":p,title:b,style:x,children:v}),e[11]=n,e[12]=p,e[13]=b,e[14]=S):S=e[14];let g;e[15]!==o?(g=o("mcpDropdown.actions.refreshAria"),e[15]=o,e[16]=g):g=e[16];let I;e[17]!==o?(I=o("mcpDropdown.actions.refreshAria"),e[17]=o,e[18]=I):I=e[18];let P;e[19]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"manipulation"},e[19]=P):P=e[19];const T=r&&"animate-spin";let N;e[20]!==T?(N=te("size-5",T),e[20]=T,e[21]=N):N=e[21];let E;e[22]!==N?(E=t.jsx(se,{name:"refresh",className:N}),e[22]=N,e[23]=E):E=e[23];let D;e[24]!==r||e[25]!==f||e[26]!==E||e[27]!==g||e[28]!==I?(D=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:f,disabled:r,"aria-label":g,title:I,style:P,children:E}),e[24]=r,e[25]=f,e[26]=E,e[27]=g,e[28]=I,e[29]=D):D=e[29];let w;e[30]!==D||e[31]!==S?(w=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[S,D]}),e[30]=D,e[31]=S,e[32]=w):w=e[32];let C;e[33]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ci,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=C):C=e[33];let y;return e[34]!==w?(y=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[w,C]}),e[34]=w,e[35]=y):y=e[35],y},$n=({open:s,onClose:e,tab:n,onTabChange:o,pendingChangesDiff:r,onOpenPlan:i,onOpenMcpSettings:a,variant:c="drawer"})=>{const{t:d}=ue(),u=l.useRef(null),[f,p]=l.useState(!1),[b,x]=l.useState(s),v=l.useRef(e);l.useEffect(()=>{v.current=e},[e]);const S=l.useRef(n);l.useEffect(()=>{S.current=n},[n]);const[g,I]=l.useState(()=>new Set);if(l.useEffect(()=>{s&&I(N=>{if(N.has(n))return N;const E=new Set(N);return E.add(n),E})},[s,n]),typeof document<"u"&&!u.current){let N=document.getElementById(On);N||(N=document.createElement("div"),N.id=On,document.body.appendChild(N)),u.current=N}if(l.useEffect(()=>{if(s){x(!0);const E=window.setTimeout(()=>p(!0),Ol);return()=>window.clearTimeout(E)}p(!1);const N=window.setTimeout(()=>x(!1),Bn+40);return()=>window.clearTimeout(N)},[s]),l.useEffect(()=>{if(!s)return;const N=document.body.style.overflow;c==="drawer"&&(document.body.style.overflow="hidden");const E=D=>{D.key==="Escape"&&S.current!=="terminal"&&v.current()};return document.addEventListener("keydown",E),()=>{c==="drawer"&&(document.body.style.overflow=N),document.removeEventListener("keydown",E)}},[s,c]),c==="drawer"&&!u.current)return null;const P=[{id:"changes",label:d("mobile.menu.changes"),icon:t.jsx(se,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:d("mobile.menu.files"),icon:t.jsx(se,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:d("mobile.menu.terminal"),icon:t.jsx(se,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:d("contextRail.surface.notes"),icon:t.jsx(se,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:d("mobile.menu.mcp"),icon:t.jsx(ji,{className:"h-3.5 w-3.5"})}],T=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("div",{className:"flex h-9 min-w-0 flex-1 items-center",children:b?t.jsx(ki,{items:P,activeId:n,onSelect:N=>o(N),layoutMode:"fit",variant:"active-pill",nonCompositedIndicator:!0,inactiveTabsIconOnly:!0,className:"h-full"}):null}),t.jsx("button",{type:"button",className:"-mr-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":d("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[g.has("changes")?t.jsx("div",{className:te("h-full",n!=="changes"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Tl,{initialDiffPath:r?.path??null,initialDiffStaged:r?.staged===!0})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,g.has("files")?t.jsx("div",{className:te("h-full",n!=="files"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Ll,{})})}):null,g.has("terminal")?t.jsx("div",{className:te("h-full",n!=="terminal"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Si,{visible:s&&n==="terminal"})})}):null,g.has("notes")?t.jsx("div",{className:te("h-full",n!=="notes"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Ni,{onActionComplete:e,onOpenPlan:i})})}):null,g.has("mcp")?t.jsx("div",{className:te("h-full",n!=="mcp"&&"hidden"),children:t.jsx(Be,{children:t.jsx($l,{onOpenMcpSettings:a})})}):null]})]});return c==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:T}):ct.createPortal(t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":d("mobile.header.openWorkspaceAria"),"aria-hidden":!s,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:f?"none":"translateX(100%)",transition:`transform ${Bn}ms ${Bl}`,visibility:b?"visible":"hidden",pointerEvents:s?"auto":"none"},children:T}),u.current)};function Fl(s){return s.currentDirectory}function Wl(s){return s.refresh}function Ul(s){return s.loadMcpConfigs}function Vl(s){return window.setTimeout(s,500)}const Tt=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",Hl=()=>{l.useEffect(()=>{if(!Tt())return;let s=!1;const e=[],n=document.documentElement;n.classList.add("oc-capacitor-app"),window.Capacitor?.getPlatform?.()==="android"&&n.classList.add("oc-platform-android"),e.push(Do());const r=i=>{n.style.setProperty("--oc-keyboard-inset",`${Math.max(0,Math.round(i))}px`)};return $e(()=>import("./vendor-capacitor-status-bar-B-N0EOVk.js"),__vite__mapDeps([117,118])).then(async({StatusBar:i,Style:a})=>{if(s)return;const c=window.Capacitor?.getPlatform?.(),d=async()=>{if(c==="android"){const b=document.documentElement.classList.contains("dark"),x=(b?localStorage.getItem("splashBgDark"):localStorage.getItem("splashBgLight"))||(b?"#171515":"#fffdf4");await i.setOverlaysWebView({overlay:!1}).catch(()=>{}),await i.setBackgroundColor({color:x}).catch(()=>{}),await i.setStyle({style:b?a.Dark:a.Light}).catch(()=>{}),await i.show().catch(()=>{});return}await i.setStyle({style:a.Default}).catch(()=>{}),await i.setOverlaysWebView({overlay:!0}).catch(()=>{}),await i.show().catch(()=>{})};await d();const u=window.setTimeout(()=>{d()},400);e.push(()=>window.clearTimeout(u));const{App:f}=await $e(async()=>{const{App:b}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:b}},__vite__mapDeps([119,4,118])),p=await f.addListener("appStateChange",({isActive:b})=>{b&&d()});if(s){p.remove();return}e.push(()=>{p.remove()})}).catch(()=>{}),$e(()=>import("./vendor-capacitor-keyboard-CYccoJjr.js"),__vite__mapDeps([120,118])).then(async({Keyboard:i})=>{if(s)return;if(window.Capacitor?.getPlatform?.()==="android"){const k=await i.addListener("keyboardWillShow",z=>{dn(z.keyboardHeight),n.classList.add("oc-keyboard-open"),window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),A=await i.addListener("keyboardDidShow",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),R=await i.addListener("keyboardWillHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-intent",{detail:{open:!1}})),n.classList.remove("oc-keyboard-open")}),j=await i.addListener("keyboardDidHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!1}}))}),V=()=>{k.remove(),A.remove(),R.remove(),j.remove()};if(s){V();return}e.push(V);return}await i.setAccessoryBarVisible({isVisible:!1}).catch(()=>{});const c=250,d=200,u="cubic-bezier(0.38, 0.7, 0.125, 1)";let f=null,p=null,b=0,x=!1,v=0,S=!1;const g=(k,A)=>{n.style.setProperty(k,`${Math.max(0,Math.round(A))}px`)},I=()=>{f!==null&&(window.clearTimeout(f),f=null)},P=(k,A)=>{window.dispatchEvent(new CustomEvent(k,{detail:A}))},T=()=>{const k=[],A=document.querySelector(".oc-mobile-composer");A&&k.push({el:A,factor:1});const R=document.querySelector(".oc-draft-center");return R&&k.push({el:R,factor:.5}),k},N=()=>{for(const{el:k}of T())k.style.transition="",k.style.transform=""},E=await i.addListener("keyboardWillShow",k=>{if(I(),dn(k.keyboardHeight),S=!0,b=k.keyboardHeight,!x){const R=document.querySelector(".oc-mobile-app-shell");v=R&&parseFloat(getComputedStyle(R).paddingBottom)||0}const A=Math.max(0,b-v);n.classList.remove("oc-kb-hide"),p!==null&&(window.clearTimeout(p),p=null),n.classList.add("oc-keyboard-open","oc-kb-animating","oc-kb-caret-hold"),r(b);for(const{el:R,factor:j}of T())R.style.transition=`transform ${c}ms ${u}`,R.style.transform=`translateY(${-A*j}px)`;g("--oc-kb-scroll-inset",A),P("oc:keyboard-settled",{open:!0}),P("oc:keyboard-anim",{phase:"show",slide:A,durationMs:c,easing:u}),f=window.setTimeout(()=>{f=null,n.classList.remove("oc-kb-animating"),g("--oc-kb-layout",b),x=!0,N(),P("oc:keyboard-settled",{open:!0}),p=window.setTimeout(()=>{p=null,n.classList.remove("oc-kb-caret-hold")},250)},c+20)}),D=()=>{if(!S)return;S=!1,I(),P("oc:keyboard-intent",{open:!1}),p!==null&&(window.clearTimeout(p),p=null),n.classList.remove("oc-kb-caret-hold");const k=Math.max(0,b-v);if(n.classList.remove("oc-keyboard-open"),r(0),g("--oc-kb-scroll-inset",0),x){n.classList.remove("oc-kb-animating"),g("--oc-kb-layout",0),x=!1;for(const{el:A,factor:R}of T())A.style.transition="none",A.style.transform=`translateY(${-k*R}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}P("oc:keyboard-anim",{phase:"hide",slide:k,durationMs:d,easing:u}),n.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:A}of T())A.style.transition=`transform ${d}ms ${u}`,A.style.transform="translateY(0px)";f=window.setTimeout(()=>{f=null,n.classList.remove("oc-kb-animating","oc-kb-hide"),N(),P("oc:keyboard-settled",{open:!1})},d+20)},w=await i.addListener("keyboardWillHide",D),C=k=>k instanceof HTMLElement&&(k.tagName==="TEXTAREA"||k.tagName==="INPUT"||k.isContentEditable),y=k=>{S&&C(k.target)&&(C(k.relatedTarget)||window.setTimeout(()=>{S&&(C(document.activeElement)||D())},0))};if(document.addEventListener("focusout",y,!0),s){I(),document.removeEventListener("focusout",y,!0),E.remove(),w.remove();return}e.push(I,()=>{p!==null&&(window.clearTimeout(p),p=null)},()=>document.removeEventListener("focusout",y,!0),()=>{E.remove()},()=>{w.remove()})}).catch(()=>{}),()=>{s=!0,e.forEach(i=>i()),Mo(),n.classList.remove("oc-capacitor-app","oc-keyboard-open","oc-kb-animating","oc-kb-hide","oc-kb-caret-hold","oc-platform-android"),n.style.removeProperty("--oc-keyboard-inset"),n.style.removeProperty("--oc-kb-shift"),n.style.removeProperty("--oc-kb-layout"),n.style.removeProperty("--oc-kb-scroll-inset")}},[])},Gl=s=>{const e=l.useRef(!1);l.useEffect(()=>{if(!Tt())return;let n=!1;const o=[],r=()=>{e.current&&(e.current=!1,s())},i=()=>{if(document.visibilityState==="hidden"){e.current=!0;return}r()};return document.addEventListener("visibilitychange",i),o.push(()=>document.removeEventListener("visibilitychange",i)),$e(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([119,4,118])).then(async({App:a})=>{if(n)return;const c=await a.addListener("appStateChange",({isActive:u})=>{if(document.documentElement.classList.toggle("oc-native-app-active",u),!u){e.current=!0;return}r()}),d=await a.addListener("resume",r);if(n){c.remove(),d.remove();return}o.push(()=>{c.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{n=!0,o.forEach(a=>a())}},[s])},Kl=s=>{l.useEffect(()=>{if(!Tt())return;let e=!1,n=null;return $e(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([119,4,118])).then(async({App:o})=>{if(e)return;const r=await o.addListener("backButton",()=>{s()||o.minimizeApp().catch(()=>{})});if(e){r.remove();return}n=()=>{r.remove()}}).catch(()=>{}),()=>{e=!0,n?.()}},[s])};function ql(s){const e=de.c(4),n=2500,{uiFont:o}=Lo(),[r,i]=l.useState(!1);let a,c;return e[0]!==n||e[1]!==o?(a=()=>{let d=!1;const u=()=>{d||i(!0)},f=()=>{requestAnimationFrame(()=>requestAnimationFrame(u))},p=Promise.all([zo(o).catch(Zl),document.fonts?.ready?.then(Xl).catch(Ql)??Promise.resolve(),Yi.catch(Jl)]).then(Yl),b=new Promise(x=>{window.setTimeout(x,n)});return Promise.race([p,b]).then(f),()=>{d=!0}},c=[o,n],e[0]=n,e[1]=o,e[2]=a,e[3]=c):(a=e[2],c=e[3]),l.useEffect(a,c),r}function Yl(){}function Jl(){}function Ql(){}function Xl(){}function Zl(){}const ec="openchamber",tc=s=>s.replace(/^\/+|\/+$/g,""),sc=s=>{const e=tc(s.pathname).split("/").filter(Boolean);return s.host?[s.host,...e]:e};function nc(s){if(typeof s!="string"||s.length===0)return null;let e;try{e=new URL(s)}catch{return null}if(e.protocol!==`${ec}:`)return null;const n=sc(e),o=(n[0]??"").toLowerCase(),r=n.slice(1),i=e.searchParams;switch(o){case"session":{const a=r[0]||i.get("id")||"";return a?{type:"session",sessionId:a,directory:i.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:i.get("dir")??void 0,projectId:i.get("project")??void 0,agent:i.get("agent")??void 0,model:i.get("model")??void 0};case"sessions":{const a=i.get("filter");return{type:"sessions",filter:a==="attention"||a==="recent"||a==="all"?a:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:r[0]||i.get("section")||void 0};case"changes":return{type:"changes",path:r.join("/")||i.get("path")||void 0,staged:i.get("staged")==="true"};case"view":{const a=(r[0]||"").toLowerCase();return a==="changes"?{type:"changes"}:a==="files"||a==="mcp"||a==="instances"||a==="update"?{type:"view",target:a}:null}default:return null}}let Le={},Cr=!1,kt=null;const rc=s=>{switch(s.type){case"session":return ve.getState().setCurrentSession(s.sessionId,s.directory??null),!0;case"new-session":{const e=ve.getState();return e.openNewSessionDraft(),(s.directory||s.projectId)&&e.setNewSessionDraftTarget({directoryOverride:s.directory??null,projectId:s.projectId??null,selectedProjectId:s.projectId??null}),!0}case"sessions":return Le.openSessions?(Le.openSessions(s.filter),!0):!1;case"status":return Le.openSessions?(Le.openSessions(),!0):!1;case"view":return Le.openView?(Le.openView(s.target),!0):!1;case"changes":return Le.openChanges?(Le.openChanges({path:s.path,staged:s.staged}),!0):!1;case"settings":return Le.openSettings?(Le.openSettings(s.section),!0):!1}},Vs=()=>{if(!Cr||!kt)return;const s=kt;kt=null,rc(s)||(kt=s)},Rr=s=>{kt=s,Vs()},Fn=s=>{const e=nc(s);e&&Rr(e)},oc=s=>{Cr=s,Vs()},ic=s=>{const e=de.c(3);let n,o;e[0]!==s?(n=()=>(Le=s,Vs(),()=>{Le===s&&(Le={})}),o=[s],e[0]=s,e[1]=n,e[2]=o):(n=e[1],o=e[2]),l.useEffect(n,o)},ac=s=>{const{ready:e}=s;l.useEffect(()=>{oc(e)},[e]),l.useEffect(()=>{if(!Ce())return;let n=!1;const o=[];return $e(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([119,4,118])).then(async({App:r})=>{if(n)return;const i=await r.addListener("appUrlOpen",a=>{Fn(a?.url)});if(n){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),$e(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([121,118])).then(async({PushNotifications:r})=>{if(n)return;const i=await r.addListener("pushNotificationActionPerformed",a=>{const c=a?.notification?.data,d=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(d){Fn(d);return}const u=typeof c?.sessionId=="string"?c.sessionId:void 0;u&&Rr({type:"session",sessionId:u})});if(n){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),()=>{n=!0,o.forEach(r=>r())}},[])},lc=32,cc=80,dc=64,uc=.7,fc=(s,e)=>{const n=l.useRef(e);n.current=e,l.useEffect(()=>{const o=s.current;if(!o)return;const i=window.Capacitor?.getPlatform?.()==="android"?cc:lc;let a=!1,c=!1,d=0,u=0;const f=b=>{if(b.touches.length!==1){a=!1;return}const x=b.touches[0],v=o.clientWidth,S=x.clientX<=i,g=x.clientX>=v-i;a=S||g,c=S,d=x.clientX,u=x.clientY},p=b=>{if(!a)return;a=!1;const x=b.changedTouches[0];if(!x)return;const v=x.clientX-d,S=x.clientY-u;Math.abs(v)<dc||Math.abs(S)>Math.abs(v)*uc||c&&v<=0||!c&&v>=0||(c?n.current.onLeftEdgeSwipe?.():n.current.onRightEdgeSwipe?.())};return o.addEventListener("touchstart",f,{passive:!0}),o.addEventListener("touchend",p,{passive:!0}),()=>{o.removeEventListener("touchstart",f),o.removeEventListener("touchend",p)}},[s])},mc=()=>{if(typeof window>"u")return;const s=window.__OPENCHAMBER_APNS_ENV__;if(s==="development")return"sandbox";if(s==="production")return"production"},pc=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},hc=s=>{const{enabled:e}=s,n=Ve(r=>r.nativeNotificationsEnabled),o=l.useRef(null);l.useEffect(()=>{if(!e||!n||!pc())return;let r=!1;const i=[];return $e(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([121,118])).then(async({PushNotifications:a})=>{if(r)return;let c=await a.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await a.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const d=await a.addListener("registration",f=>{o.current=f.value,nn()?.push?.registerApnsToken?.({token:f.value,platform:Hn(),environment:mc()})}),u=await a.addListener("registrationError",f=>{console.warn("[Push] APNs registration error:",f)});if(await a.register().catch(()=>{}),r){d.remove(),u.remove();return}i.push(()=>{d.remove()},()=>{u.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(a=>a())}},[e,n]),l.useEffect(()=>{if(n)return;const r=o.current;if(!r)return;o.current=null,nn()?.push?.unregisterApnsToken?.({token:r})},[n])},Wn=s=>{const e=de.c(12),{side:n,isResizing:o,ariaLabel:r,handleProps:i}=s,a=n==="left"?"right-0":"left-0";let c;e[0]!==a?(c=te("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=c):c=e[1];const d=n==="left"?"right-0":"left-0",u=o&&"bg-[var(--interactive-border)]";let f;e[2]!==d||e[3]!==u?(f=te("absolute inset-y-0 w-[3px] transition-colors",d,u),e[2]=d,e[3]=u,e[4]=f):f=e[4];let p;e[5]!==f?(p=t.jsx("div",{className:f}),e[5]=f,e[6]=p):p=e[6];let b;return e[7]!==r||e[8]!==i||e[9]!==c||e[10]!==p?(b=t.jsx("div",{className:c,role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:p}),e[7]=r,e[8]=i,e[9]=c,e[10]=p,e[11]=b):b=e[11],b},bc=320,gc=380,Un=280,xc=560,yc=900;function Vn(s,e,n,o){const r=de.c(23),i=o===void 0?xc:o,a=l.useRef(null);let c;r[0]!==n||r[1]!==i||r[2]!==e?(c=()=>{if(typeof window>"u")return n;const j=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(j)?Math.min(i,Math.max(Un,j)):n},r[0]=n,r[1]=i,r[2]=e,r[3]=c):c=r[3];const[d,u]=l.useState(c),[f,p]=l.useState(!1),b=l.useRef(0),x=l.useRef(d),v=l.useRef(null),S=l.useRef(null);let g;r[4]!==i?(g=j=>Math.min(i,Math.max(Un,Math.round(j))),r[4]=i,r[5]=g):g=r[5];const I=g;let P;r[6]===Symbol.for("react.memo_cache_sentinel")?(P=j=>{const V=a.current;V&&(V.style.width=`${j}px`,V.style.minWidth=`${j}px`,V.style.maxWidth=`${j}px`,V.style.setProperty("--oc-ipad-sidebar-width",`${j}px`))},r[6]=P):P=r[6];const T=P;let N;r[7]!==d?(N=j=>{try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}S.current=j.pointerId,b.current=j.clientX,x.current=d,v.current=d,p(!0),j.preventDefault()},r[7]=d,r[8]=N):N=r[8];const E=N;let D;r[9]!==I||r[10]!==s?(D=j=>{if(S.current!==j.pointerId)return;const V=j.clientX-b.current,z=I(x.current+(s==="left"?V:-V));v.current!==z&&(v.current=z,T(z))},r[9]=I,r[10]=s,r[11]=D):D=r[11];const w=D;let C;r[12]!==I||r[13]!==e?(C=j=>{if(S.current!==j.pointerId)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const V=I(v.current??x.current);S.current=null,v.current=null,p(!1),u(V);try{window.localStorage.setItem(e,String(V))}catch{}},r[12]=I,r[13]=e,r[14]=C):C=r[14];const y=C;let k;r[15]!==E||r[16]!==y||r[17]!==w?(k={onPointerDown:E,onPointerMove:w,onPointerUp:y,onPointerCancel:y},r[15]=E,r[16]=y,r[17]=w,r[18]=k):k=r[18];const A=k;let R;return r[19]!==A||r[20]!==f||r[21]!==d?(R={asideRef:a,width:d,isResizing:f,handleProps:A},r[19]=A,r[20]=f,r[21]=d,r[22]=R):R=r[22],R}const vc=["general","appearance","chat","notifications","sessions","git","magic-prompts","behavior","mcp","providers","usage","voice","about"],wc=1e3,jc=({onActiveConnectionDeleted:s})=>{const{t:e}=ue(),[n,o]=l.useState(!1),[r,i]=l.useState(null),[a,c]=l.useState(!1),[d,u]=l.useState("changes"),[f,p]=l.useState(null),[b,x]=l.useState("nav"),[v,S]=l.useState(null),g=Ve(Y=>Y.setSettingsPage),I=Ve(Y=>Y.wideChatLayoutEnabled),P=at(Y=>Y.available),T=at(Y=>Y.runtimeType),N=l.useMemo(()=>Tt(),[]),E=Bt(Y=>Y.mcpServers),D=Bt(Y=>Y.setMcpDraft),w=Bt(Y=>Y.setSelectedMcp),C=l.useCallback(()=>{i(null),p(null)},[]),y=l.useCallback(Y=>{i(Y)},[]),k=l.useCallback(()=>{c(!1)},[]),A=l.useCallback(Y=>{x(Y),y("settings")},[y]),{enabled:R,roomyForPanels:j}=ys(),z=Xo()==="portrait",h=Zo(),[L,M]=l.useState(()=>ei().roomyForPanels),B=l.useCallback(()=>{M(Y=>!Y)},[]);l.useEffect(()=>{R||M(!1)},[R]);const H=l.useCallback(()=>{S(null),u("files"),c(!0)},[]),Z=l.useCallback((Y=null)=>{S(Y),u("changes"),c(!0)},[]),Q=Vn("left","openchamber.ipad.leftSidebarWidth",bc),_=Vn("right","openchamber.ipad.rightSidebarWidth",gc,yc),J=j,q=J&&a?_.width:0,F=R&&L?Q.width:0;l.useEffect(()=>{if(typeof document>"u")return;const Y=document.documentElement;return Y.style.setProperty("--oc-chat-inset-left",`${F}px`),Y.style.setProperty("--oc-chat-inset-right",`${q}px`),()=>{Y.style.removeProperty("--oc-chat-inset-left"),Y.style.removeProperty("--oc-chat-inset-right")}},[F,q]),l.useEffect(()=>{if(typeof document>"u")return;const Y=document.documentElement;return Y.classList.toggle("wide-chat-layout",I),()=>Y.classList.remove("wide-chat-layout")},[I]),l.useEffect(()=>{if(typeof document>"u")return;const Y=R&&(z||h),ce=document.documentElement;return ce.classList.toggle("oc-keep-draft-starters",Y),()=>ce.classList.remove("oc-keep-draft-starters")},[h,R,z]);const U=l.useMemo(()=>({openChanges:({diffPath:Y,staged:ce}={})=>{Z(Y?{path:Y,staged:ce===!0}:null)},openFiles:()=>H(),openSettings:()=>A("nav")}),[Z,H,A]),X=l.useMemo(()=>({openSessions:()=>{R?M(!0):o(!0)},openView:Y=>{if(Y==="files"){H();return}if(Y==="mcp"){u("mcp"),c(!0);return}y(Y)},openChanges:({path:Y,staged:ce}={})=>{Z(Y?{path:Y,staged:ce===!0}:null)},openSettings:Y=>{Y&&g(Y),A(Y?"page-content":"nav")}}),[R,Z,H,A,y,g]);ic(X);const ee=l.useRef(null);fc(ee,{onLeftEdgeSwipe:()=>{R?M(!0):o(!0)},onRightEdgeSwipe:()=>c(!0)});const W=l.useCallback(()=>f?(p(null),!0):r?(C(),!0):a?(k(),!0):n?(o(!1),!0):!1,[r,C,k,f,n,a]);Kl(W);const oe=!N&&P&&(T==="desktop"||T==="web"),ie=R?"dialog":"fullscreen",fe=l.useMemo(()=>({instanceLabel:N?yt():null,onOpenInstances:N?()=>y("instances"):void 0,onOpenSettings:()=>A("nav"),onOpenUpdate:oe?()=>y("update"):void 0}),[A,y,N,oe]),je=l.useCallback(()=>{const Y="new-mcp-server";let ce=Y,Se=1;for(;E.some(Re=>Re.name===ce);)ce=`${Y}-${Se}`,Se+=1;D({name:ce,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),w(ce),g("mcp"),A("page-content")},[E,A,D,w,g]);return t.jsx(ti,{actions:U,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[R?t.jsxs("aside",{ref:Q.asideRef,className:te("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!L&&"border-r-0"),style:{width:L?Q.width:0,minWidth:L?Q.width:0,maxWidth:L?Q.width:0,"--oc-ipad-sidebar-width":`${Q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:Q.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!L,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:te("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",Q.isResizing&&"pointer-events-none",!L&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Be,{children:t.jsx(An,{open:!0,variant:"sidebar",onOpenChange:Y=>{!Y&&!j&&M(!1)},footer:fe})})}),L?t.jsx(Wn,{side:"left",isResizing:Q.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:Q.handleProps}):null]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(el,{onOpenSessions:()=>R?B():o(!0),onOpenWorkspace:()=>c(!0),compactTitle:R}),t.jsx("main",{ref:ee,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{className:"h-full w-full",children:t.jsx(Be,{children:t.jsx(Di,{})})})})]}),R?null:t.jsx(An,{open:n,onOpenChange:o,footer:fe}),R?t.jsxs("aside",{ref:_.asideRef,className:te("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!q&&"border-l-0"),style:{width:q,minWidth:q,maxWidth:q,"--oc-ipad-sidebar-width":`${_.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:_.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!q,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:te("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",_.isResizing&&"pointer-events-none",!q&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Be,{children:t.jsx($n,{open:a,onClose:k,tab:d,onTabChange:u,pendingChangesDiff:v,onOpenPlan:p,onOpenMcpSettings:je,variant:J?"panel":"drawer"})})}),q?t.jsx(Wn,{side:"right",isResizing:_.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:_.handleProps}):null]}):t.jsx($n,{open:a,onClose:k,tab:d,onTabChange:u,pendingChangesDiff:v,onOpenPlan:p,onOpenMcpSettings:je}),f?t.jsx(jt,{open:!0,variant:ie,onClose:()=>p(null),ariaLabel:f.title,title:f.title,children:t.jsx(Be,{children:t.jsx(Mi,{targetPath:f.path,onNavigatedToChat:()=>{C(),k()}})})}):null,r==="instances"&&N?t.jsx(jt,{open:!0,variant:ie,dialogAlign:"app",onClose:C,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(rl,{onConnect:C,onActiveConnectionDeleted:s})}):null,r==="settings"?t.jsx(jt,{open:!0,variant:ie,dialogAlign:"app",onClose:C,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Be,{children:t.jsx(Li,{forceMobile:!0,isWindowed:!0,initialMobileStage:b,visiblePageSlugs:vc.filter(Y=>!(N&&Y==="about")),onClose:C})})}):null,r==="update"?t.jsx(jt,{open:!0,variant:ie,dialogAlign:"app",onClose:C,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Be,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(zi,{initialUpdateDialogOpen:!0})})})}):null]})})};function kc({apis:s}){const{t:e}=ue(),n=ze(_=>_.initializeApp),o=ze(_=>_.isInitialized),r=ze(_=>_.isConnected),i=ze(_=>_.connectionPhase),a=ze(_=>_.providers.length),c=ze(_=>_.agents.length),d=ze(_=>_.loadProviders),u=ze(_=>_.loadAgents),f=dt(_=>_.currentDirectory),p=ve(_=>_.error),b=ve(_=>_.clearError),x=Ve(_=>_.setIsMobile),v=Oo(_=>_.refreshStatus),S=Bo(_=>_.setPlanModeEnabled),g=Oe(_=>_.projects),[I,P]=l.useState(0),[T,N]=l.useState(0),[E,D]=l.useState(!1),[w,C]=l.useState("pending"),[y,k]=l.useState(null),A=l.useMemo(()=>yt(),[]),[,R]=l.useReducer(_=>_+1,0),j=l.useMemo(()=>Tt(),[]),V=l.useRef(0),z=l.useRef(0),h=l.useCallback(()=>{const _=Ge(),J=z.current+1;if(z.current=J,!_){ts();return}const q=()=>{n(),v(s.github,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),c===0&&u({source:"mobileApp:nativeResume"})},F=()=>{it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(X=>X+1)};Ft().then(X=>{if(z.current===J){if(X==="no-connection"){F();return}if(X==="needs-login"){k({kind:"auth-expired",label:yt()??""}),F();return}if(X==="unreachable"){window.setTimeout(()=>{z.current===J&&Ft().then(ee=>{if(z.current===J&&ee!=="switched"){if(ee==="unchanged"){q();return}ee==="needs-login"&&k({kind:"auth-expired",label:yt()??""}),F()}})},4e3);return}X!=="switched"&&q()}});const U=Date.now();U-V.current>=wc&&(V.current=U,window.dispatchEvent(new Event("openchamber:system-resume")))},[c,s.github,n,u,d,a,v]);Hl(),Gl(h),l.useEffect(()=>{if(!j)return;let _;const J=()=>{window.clearTimeout(_),_=window.setTimeout(()=>h(),1500)};return window.addEventListener("online",J),()=>{window.removeEventListener("online",J),window.clearTimeout(_)}},[j,h]),l.useEffect(()=>(rn(s),()=>rn(null)),[s]),l.useEffect(()=>Zr(_=>{if(!!_.runtimeKey&&_.runtimeKey===_.previousRuntimeKey){Ri(),R();return}Pi(_),N(q=>q+1),P(q=>q+1)}),[]),l.useEffect(()=>{if(!j||r||Ge()){C("done");return}let _=!1;return C("attempting"),ts().catch(()=>({status:"no-candidate"})).then(J=>{_||(J.status==="unreachable"?k({kind:"unreachable",label:J.label}):J.status==="needs-login"&&k({kind:"auth-expired",label:J.label}),C("done"))}),()=>{_=!0}},[]),l.useEffect(()=>{if(!j||!Ge())return;let _=!1;const J=q=>{q&&k(q),it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(F=>F+1)};return Ft().then(async q=>{if(_||q==="switched"||q==="unchanged")return;const F=yt();if(q==="needs-login"){J({kind:"auth-expired",label:F??""});return}if(q==="unreachable"){J(F?{kind:"unreachable",label:F}:null);return}const U=await ts().catch(()=>({status:"no-candidate"}));_||U.status==="connected"||(U.status==="needs-login"?J({kind:"auth-expired",label:U.label}):U.status==="unreachable"?J({kind:"unreachable",label:U.label}):J(null))}),()=>{_=!0}},[]),l.useEffect(()=>{x(!0)},[x]),l.useEffect(()=>{j&&!Ge()||n()},[I,n,j]),l.useEffect(()=>{r&&(a===0&&d({source:"mobileApp:recovery"}),c===0&&u({source:"mobileApp:recovery"}))},[c,r,u,d,a]);const L=l.useRef(!1),[M,B]=l.useState(j);l.useEffect(()=>{if(!j||!r||L.current)return;if(ve.getState().currentSessionId){L.current=!0,B(!1);return}const _=Pt(),J=$o(_);if(!J){L.current=!0,B(!1);return}let q=!1;const F=window.setTimeout(()=>B(!1),6e3);return(async()=>{const U=await vs().catch(()=>null);if(q)return;if(!U){B(!1);return}L.current=!0;const X=U.activeSessions.find(W=>W.id===J.sessionId);if(!X){Fo(_),B(!1);return}const ee=ve.getState();ee.currentSessionId||ee.setCurrentSession(X.id,xs(X)??J.directory??void 0),B(!1)})(),()=>{q=!0,window.clearTimeout(F)}},[I,r,j]),l.useEffect(()=>{r&&on.setDirectory(f)},[f,r]),l.useEffect(()=>{r&&v(s.github,{force:!0})},[s.github,r,v]),l.useEffect(()=>{if(!r||g.length===0)return;let _=!1;return(async()=>{const q=new Map(ve.getState().availableWorktreesByProject);if(await Promise.all(g.map(async X=>{const ee=X.path.replace(/\\/g,"/").replace(/\/+$/,"");if(ee)try{if(!(Ue.getState().directories.get(ee)?.isGitRepo??await $e(()=>import("./useAppFontEffects-pyTMaGQu.js").then(fe=>fe.fU),__vite__mapDeps([8,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108])).then(fe=>fe.checkIsGitRepository(ee))))return;const ie=await sr({id:X.id,path:ee});if(_)return;q.set(ee,ie)}catch{}})),_)return;const F=nr(g,q),U=ve.getState().availableWorktreesByProject;Qo(F,U)||ve.setState({availableWorktrees:[...F.values()].flat(),availableWorktreesByProject:F})})(),()=>{_=!0}},[r,g]),l.useEffect(()=>{let _=!1;return(async()=>{const q=await bs("/health",{method:"GET"}).catch(()=>null);if(!q||!q.ok||_)return;const F=await q.json().catch(()=>null);if(!F||_)return;const U=F.planModeExperimentalEnabled;S(U===!0||U===1||U==="1"||U==="true")})(),()=>{_=!0}},[S]),l.useEffect(()=>{if(!p)return;const _=window.setTimeout(()=>b(),5e3);return()=>window.clearTimeout(_)},[b,p]),l.useEffect(()=>{if(!(!r&&(j?!!Ge():!0))){D(!1);return}const J=window.setTimeout(()=>{D(!0)},j?4e3:8e3);return()=>window.clearTimeout(J)},[r,j,I,T]),Wo(),Uo({enabled:!0}),Ti(),Vo(),Ii(),hc({enabled:j&&r}),ac({ready:j&&r&&o});const H=ql(),Z=!r&&i==="reconnecting";if(!H)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Je,{width:120,height:120,isAnimated:!0})});const Q=!!Ge();return j&&(!Q||!r&&!Z)?Q?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(Je,{width:120,height:120,isAnimated:!E}),E?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("mobile.connect.recovery.description")})]}),t.jsx(ge,{type:"button",variant:"outline",onClick:()=>{it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(_=>_+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):w!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(Je,{width:120,height:120,isAnimated:!0}),A?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[A,t.jsx(Ho,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx($a,{onConnected:()=>P(_=>_+1),notice:y})}):!r&&!Z?E?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Je,{width:120,height:120,isAnimated:!0})}):t.jsx(Be,{children:t.jsx(Go,{sdk:on.getSdkClient(),directory:f||"",children:t.jsx(Ko,{apis:s,children:t.jsx(qo,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[j&&M?t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:t.jsx(Je,{width:120,height:120,isAnimated:!0})}):null,t.jsx(Yo,{embeddedBackgroundWorkEnabled:o}),t.jsx(_i,{}),t.jsx(ra,{}),t.jsx(jc,{onActiveConnectionDeleted:()=>{it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(_=>_+1)}}),t.jsx(Jo,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),o?t.jsx(Ai,{}):null]})})})},T)})}const Sc=()=>{li(),eo().then(()=>{Promise.all([to(),ci()]).catch(s=>{console.error("[mobile-main] settings init failed:",s)}),di(),ui(),fi()}).catch(s=>{console.error("[mobile-main] appearance init failed:",s)}).finally(()=>{Ji()})};function Lu(s){window.__OPENCHAMBER_SURFACE__="mobile",si(),Sc(),na(),ni();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const o=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",r=o?{...s,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:s,i=t.jsx(kc,{apis:r});Yr.createRoot(e).render(t.jsx(ls.StrictMode,{children:t.jsx(ri,{children:t.jsx(oi,{children:t.jsx(ii,{children:t.jsx(Oi,{children:o?i:t.jsx(ai,{children:i})})})})})}))}export{Lu as renderMobileApp};
|
|
23
|
+
`)}`.trim()),z([])},[]),Ie=l.useCallback(async()=>{if(!i)return;const O=U.map($=>$.path).sort();if(O.length===0){le.error(o("gitView.toast.selectFileToDescribe"));return}j(!0);try{const{message:$}=await To(i,O);w($.subject?.trim()??""),z(Array.isArray($.highlights)?$.highlights:[])}catch($){le.error($ instanceof Error?$.message:o("gitView.toast.generateCommitMessageFailed"))}finally{j(!1)}},[i,U,o]),ke=async(O={})=>{if(!i)return;if(!D.trim()){le.error(o("gitView.toast.enterCommitMessage"));return}const $=U.map(re=>re.path).sort();if($.length===0){le.error(o("gitView.toast.selectFileToCommit"));return}E(O.pushAfter?"commitAndPush":"commit");try{if(await r.createGitCommit(i,D.trim(),{files:$}),le.success(o("gitView.toast.commitCreated")),w(""),z([]),O.pushAfter){const re=a?.tracking?.split("/")[0],me=ee.find(It=>It.name===re)??ee[0];if(!me)throw new Error(o("mobile.changes.noRemote"));T("sync");const Me=`${me.name}/`,xe=a?.tracking?.startsWith(Me)?a.tracking.slice(Me.length):void 0;await r.gitFetch(i,{remote:me.name}),((await r.getGitStatus(i)).behind??0)>0&&await r.gitPull(i,{remote:me.name,branch:xe,rebase:!0}),((await r.getGitStatus(i)).ahead??0)>0&&await r.gitPush(i),await ie(!1),await fe()}else await ie(!1)}catch(re){le.error(re instanceof Error?re.message:o("gitView.toast.createCommitFailed"))}finally{E(null),O.pushAfter&&T(null)}},_e=l.useMemo(()=>{const O=[];return U.length>0&&O.push({id:"staged",title:o("gitView.changes.stagedTitle"),entries:U,actionSymbol:"-",actionAllLabel:o("gitView.changes.unstageAllAria"),getActionLabel:$=>o("gitView.changes.unstageFileAria",{path:$}),onActionFile:$=>{Y([$],"unstage")},onActionAll:$=>{Y($,"unstage")},onViewDiff:$=>ce($,!0),onRevertFile:Se,showRevertActions:!1,accent:!0}),X.length>0&&O.push({id:"unstaged",title:o("gitView.changes.title"),entries:X,actionSymbol:"+",actionAllLabel:o("gitView.changes.stageAllAria"),getActionLabel:$=>o("gitView.changes.stageFileAria",{path:$}),onActionFile:$=>{Y([$],"stage")},onActionAll:$=>{Y($,"stage")},onViewDiff:$=>ce($,!1),onRevertFile:Se}),O},[Se,ce,Y,U,o,X]),be=O=>t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||i||""})]})]}),t.jsx("div",{className:"min-h-0 flex-1",children:O})]});return i?d&&c===null?be(t.jsx(Ke,{loading:!0,message:o("gitView.loading.checkingRepository")})):c===!1?be(t.jsx(Ke,{icon:!0,message:o("gitView.empty.notGitRepository"),description:o("gitView.empty.notGitRepositoryDescription")})):g.type==="diff"?t.jsx(Il,{path:g.path,diff:W,fileExists:!!oe,error:Q,onBack:()=>I({type:"list"}),onRetry:()=>q(O=>O+1)}):t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":o("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})}):null,t.jsxs("div",{className:"min-w-0 flex-1 px-1",children:[t.jsx("h2",{className:"typography-ui-label text-foreground",children:o("mobile.nav.changes")}),t.jsx("p",{className:"truncate typography-micro text-muted-foreground",children:a?.current||i})]}),t.jsx(xi,{syncAction:P,remotes:ee,onFetch:O=>{je("fetch",O)},onSync:O=>{je("sync",O)},disabled:N!==null||d,aheadCount:a?.ahead??0,behindCount:a?.behind??0,trackingRemoteName:a?.tracking?.split("/")[0],hasUncommittedChanges:F.length>0})]}),F.length>0?t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden px-4 pt-4",children:t.jsx(yi,{groups:_e,diffStats:a?.diffStats,revertingPaths:C,onRevertAll:Ae,isRevertingAll:k,headerBackgroundClassName:"bg-transparent",onVisiblePathsChange:L})}),t.jsx("div",{className:"shrink-0 border-t border-border/70 px-4 pb-4 pt-3",children:t.jsx(vi,{stagedCount:U.length,commitMessage:D,onCommitMessageChange:w,generatedHighlights:V,onInsertHighlights:Re,onGenerateMessage:Ie,isGeneratingMessage:R,onCommit:()=>{ke({pushAfter:!1})},onCommitAndPush:()=>{ke({pushAfter:!0})},commitAction:N,gitmojiEnabled:!1,onOpenGitmojiPicker:()=>{}})})]}):t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ke,{icon:!0,message:o("gitView.empty.cleanTitle"),description:o("mobile.changes.cleanDescription")})})]}):be(t.jsx(Ke,{message:o("gitView.empty.selectSessionOrDirectory")}))},Ke=s=>{const e=de.c(13),{message:n,description:o,loading:r,icon:i}=s,a=r===void 0?!1:r,c=i===void 0?!1:i;let d;e[0]!==a?(d=a?t.jsx(se,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):null,e[0]=a,e[1]=d):d=e[1];let u;e[2]!==c?(u=c?t.jsx(se,{name:"git-branch",className:"size-6 text-muted-foreground"}):null,e[2]=c,e[3]=u):u=e[3];let f;e[4]!==n?(f=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),e[4]=n,e[5]=f):f=e[5];let p;e[6]!==o?(p=o?t.jsx("p",{className:"typography-meta text-muted-foreground",children:o}):null,e[6]=o,e[7]=p):p=e[7];let b;return e[8]!==d||e[9]!==u||e[10]!==f||e[11]!==p?(b=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[d,u,f,p]})}),e[8]=d,e[9]=u,e[10]=f,e[11]=p,e[12]=b):b=e[12],b},Il=s=>{const e=de.c(24),{path:n,diff:o,fileExists:r,error:i,onBack:a,onRetry:c}=s,{t:d}=ue();let u;e[0]!==n?(u=Io(n)||"text",e[0]=n,e[1]=u):u=e[1];const f=u;let p;e[2]!==d?(p=d("header.actions.backAria"),e[2]=d,e[3]=p):p=e[3];let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b=t.jsx(se,{name:"arrow-left",className:"size-5"}),e[4]=b):b=e[4];let x;e[5]!==a||e[6]!==p?(x=t.jsx("button",{type:"button",className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":p,onClick:a,children:b}),e[5]=a,e[6]=p,e[7]=x):x=e[7];let v;e[8]!==n?(v=t.jsx("div",{className:"min-w-0 flex-1 px-2",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:n})}),e[8]=n,e[9]=v):v=e[9];let S;e[10]!==x||e[11]!==v?(S=t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-3 border-b border-border/70 px-3 text-foreground",children:[x,v]}),e[10]=x,e[11]=v,e[12]=S):S=e[12];let g;e[13]!==o||e[14]!==i||e[15]!==r||e[16]!==f||e[17]!==c||e[18]!==n||e[19]!==d?(g=t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r?i?t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-3",children:[t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:d("mobile.changes.diffDetail.loadFailed")}),t.jsx("p",{className:"typography-meta text-muted-foreground",children:i}),t.jsx(ge,{type:"button",size:"sm",variant:"outline",onClick:c,children:d("diffView.actions.retry")})]})}):o?o.isBinary?t.jsx(Ke,{icon:!0,message:d("diffView.binary.unavailable")}):_o(n)?t.jsx(Ke,{icon:!0,message:d("mobile.changes.diffDetail.imageUnavailable")}):t.jsx(ks,{className:"h-full overflow-y-auto overflow-x-hidden p-3","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:t.jsx(wi,{original:o.original,modified:o.modified,language:f,fileName:n,renderSideBySide:!1,wrapLines:!0,layout:"inline"})}):t.jsx(Ke,{loading:!0,message:d("diffView.state.loadingDiff")}):t.jsx(Ke,{icon:!0,message:d("mobile.changes.diffDetail.missingTitle"),description:d("mobile.changes.diffDetail.missingDescription")})}),e[13]=o,e[14]=i,e[15]=r,e[16]=f,e[17]=c,e[18]=n,e[19]=d,e[20]=g):g=e[20];let I;return e[21]!==S||e[22]!==g?(I=t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[S,g]}),e[21]=S,e[22]=g,e[23]=I):I=e[23],I},_l=l.lazy(()=>$e(()=>import("./FilesView-cJPeFhDe.js").then(s=>s.a),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116])).then(s=>({default:s.FilesView}))),tt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/g,""),St=s=>{const e=tt(s);return!e||e==="/"?e||"/":e.split("/").filter(Boolean).at(-1)??e},Al=s=>{const e=tt(s);if(!e||e==="/")return null;const n=e.lastIndexOf("/");return n<=0?e.startsWith("/")?"/":null:e.slice(0,n)},Dl=(s,e)=>{const n=tt(s),o=tt(e);return!o||n===o?St(n):n.startsWith(`${o}/`)?n.slice(o.length+1):n},Ml=s=>{if(typeof s!="number"||!Number.isFinite(s)||s<0)return"";if(s<1024)return`${s} B`;const e=["KB","MB","GB"];let n=s/1024;for(const o of e){if(n<1024||o===e[e.length-1])return`${n.toFixed(n>=10?0:1)} ${o}`;n/=1024}return""},Ll=({onClose:s})=>{const{t:e}=ue(),{files:n}=js(),o=Xr(h=>h.setSelectedPath),r=tt(Ss()??null),[i,a]=l.useState(()=>({type:"browser",directory:r})),[c,d]=l.useState([]),[u,f]=l.useState(!1),[p,b]=l.useState(null),[x,v]=l.useState(""),[S,g]=l.useState([]),[I,P]=l.useState(!1),T=l.useRef(0);l.useEffect(()=>{r&&a(h=>h.type==="browser"&&h.directory?h:{type:"browser",directory:r})},[r]);const N=i.type==="browser"?i.directory:i.returnDirectory,E=l.useCallback(async h=>{if(!h)return;const L=T.current+1;T.current=L,f(!0),b(null);try{const M=await n.listDirectory(h);if(T.current!==L)return;d(M.entries.slice().sort((B,H)=>B.isDirectory!==H.isDirectory?B.isDirectory?-1:1:B.name.localeCompare(H.name)))}catch(M){if(T.current!==L)return;d([]),b(M instanceof Error?M.message:e("mobile.files.error.listFailed"))}finally{T.current===L&&f(!1)}},[n,e]);l.useEffect(()=>{i.type==="browser"&&E(i.directory)},[E,i]),l.useEffect(()=>{if(i.type!=="browser")return;const h=x.trim();if(!h){g([]),P(!1);return}let L=!1;const M=window.setTimeout(()=>{P(!0),n.search({directory:i.directory,query:h,maxResults:40}).then(B=>{L||g(B)}).catch(()=>{L||g([])}).finally(()=>{L||P(!1)})},250);return()=>{L=!0,window.clearTimeout(M)}},[n,x,i]);const D=h=>{v(""),a({type:"browser",directory:h})},w=h=>{o(r,h),a({type:"file",path:h,returnDirectory:N||r})},C=Ve(h=>h.pendingFileFocusPath),y=Ve(h=>h.pendingFileNavigation);if(l.useEffect(()=>{const h=tt(y?.path??C??"");!h||!r||h!==r&&!h.startsWith(`${r}/`)||(o(r,h),a({type:"file",path:h,returnDirectory:r}),C&&Ve.getState().setPendingFileFocusPath(null))},[C,y,r,o]),!r)return t.jsx(Nt,{message:e("mobile.files.empty.noDirectory")});if(i.type==="file")return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 border-b border-border/70 px-3 text-foreground",children:[t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-lg text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("header.actions.backAria"),onClick:()=>a({type:"browser",directory:i.returnDirectory}),style:{touchAction:"manipulation"},children:t.jsx(fn,{className:"size-5"})}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx("h2",{className:"truncate typography-ui-header text-foreground",children:St(i.path)})})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:t.jsx(Be,{children:t.jsx(l.Suspense,{fallback:t.jsx(Nt,{loading:!0,message:e("filesView.state.loading")}),children:t.jsx(_l,{mode:"editor-only"})})})})]});const k=i.directory===r?e("mobile.files.rootDirectory"):St(i.directory),A=x.trim()?S:[],R=Al(i.directory),j=i.directory!==r&&R!==null&&(R===r||R.startsWith(`${r}/`)),V=j&&!x.trim(),z=j?R:null;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsxs("header",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3 text-foreground",children:[s?t.jsx("button",{type:"button",className:"-ml-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.surface.closeAria"),onClick:s,style:{touchAction:"manipulation"},children:t.jsx(ir,{className:"size-5"})}):null,V&&z?t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.backToParentAria",{name:St(z)}),onClick:()=>D(z),style:{touchAction:"manipulation"},children:t.jsx(fn,{className:"size-5"})}):null,t.jsx("div",{className:"min-w-0 flex-1 px-1",children:t.jsx("h2",{className:"truncate typography-ui-label text-foreground",children:k})}),t.jsx("button",{type:"button",className:"flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":e("mobile.files.refreshAria"),onClick:()=>{E(i.directory)},style:{touchAction:"manipulation"},children:t.jsx(Vi,{className:te("size-5",u&&"animate-spin")})})]}),t.jsx("div",{className:"shrink-0 px-4 pb-2 pt-1",children:t.jsxs("div",{className:"relative",children:[t.jsx(or,{className:"pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(ws,{value:x,onChange:h=>v(h.target.value),placeholder:e("mobile.files.search.placeholder"),className:"h-11 pl-9"})]})}),t.jsx(ks,{className:"min-h-0 flex-1 overflow-y-auto px-4 pb-3",children:p?t.jsx(Nt,{message:p}):x.trim()?t.jsx(zl,{results:A,isSearching:I,onOpenFile:w}):t.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",children:[c.length===0&&!u?t.jsx("div",{className:"px-4 py-8 text-center typography-body text-muted-foreground",children:e("mobile.files.empty.directory")}):null,c.map(h=>t.jsx(Er,{name:h.name,path:h.path,directory:h.isDirectory,meta:h.isDirectory?void 0:Ml(h.size),onClick:()=>h.isDirectory?D(h.path):w(h.path)},h.path))]})})]})},Er=s=>{const e=de.c(16),{name:n,path:o,directory:r,meta:i,onClick:a}=s;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={touchAction:"manipulation"},e[0]=c):c=e[0];let d;e[1]!==r||e[2]!==o?(d=r?t.jsx(Hi,{className:"size-5 shrink-0 text-primary/80"}):t.jsx(Ao,{filePath:o,className:"size-5 shrink-0"}),e[1]=r,e[2]=o,e[3]=d):d=e[3];let u;e[4]!==n?(u=t.jsx("span",{className:"block min-w-0 flex-1 truncate typography-ui-label text-foreground",children:n}),e[4]=n,e[5]=u):u=e[5];let f;e[6]!==i?(f=i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,e[6]=i,e[7]=f):f=e[7];let p;e[8]!==r?(p=r?t.jsx(Gi,{className:"size-4 shrink-0 text-muted-foreground/60"}):null,e[8]=r,e[9]=p):p=e[9];let b;return e[10]!==a||e[11]!==d||e[12]!==u||e[13]!==f||e[14]!==p?(b=t.jsxs("button",{type:"button",className:"flex min-h-14 w-full items-center gap-3 border-b border-border/70 px-3 py-2.5 text-left transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset",onClick:a,style:c,children:[d,u,f,p]}),e[10]=a,e[11]=d,e[12]=u,e[13]=f,e[14]=p,e[15]=b):b=e[15],b},zl=s=>{const e=de.c(10),{results:n,isSearching:o,onOpenFile:r}=s,{t:i}=ue(),a=tt(Ss()??null);if(o){let f;e[0]!==i?(f=i("common.loading"),e[0]=i,e[1]=f):f=e[1];let p;return e[2]!==f?(p=t.jsx(Nt,{loading:!0,message:f}),e[2]=f,e[3]=p):p=e[3],p}if(n.length===0){let f;e[4]!==i?(f=i("mobile.files.search.empty"),e[4]=i,e[5]=f):f=e[5];let p;return e[6]!==f?(p=t.jsx(Nt,{message:f}),e[6]=f,e[7]=p):p=e[7],p}const c="overflow-hidden rounded-2xl border border-border/70 bg-[var(--surface-elevated)]",d=n.map(f=>t.jsx(Er,{name:St(f.path),path:f.path,directory:!1,meta:Dl(f.path,a),onClick:()=>r(f.path)},f.path));let u;return e[8]!==d?(u=t.jsx("div",{className:c,children:d}),e[8]=d,e[9]=u):u=e[9],u},Nt=s=>{const e=de.c(7),{message:n,loading:o}=s,r=o===void 0?!1:o;let i;e[0]!==r?(i=r?t.jsx(Ki,{className:"size-5 animate-spin text-muted-foreground"}):t.jsx(qi,{className:"size-6 text-muted-foreground"}),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==n?(a=t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:n}),e[2]=n,e[3]=a):a=e[3];let c;return e[4]!==i||e[5]!==a?(c=t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[i,a]})}),e[4]=i,e[5]=a,e[6]=c):c=e[6],c},On="mobile-surface-root",Ol=16,Bn=320,Bl="cubic-bezier(0.22, 1, 0.36, 1)",$l=s=>{const e=de.c(36),{onOpenMcpSettings:n}=s,{t:o}=ue(),[r,i]=l.useState(!1),a=dt(Fl),c=Ei(Wl),d=Bt(Ul);let u;e[0]!==a||e[1]!==r||e[2]!==d||e[3]!==c?(u=()=>{if(r)return;i(!0);const k=new Promise(Vl);Promise.all([c({directory:a||null,silent:!0}),d({force:!0}),k]).finally(()=>i(!1))},e[0]=a,e[1]=r,e[2]=d,e[3]=c,e[4]=u):u=e[4];const f=u;let p;e[5]!==o?(p=o("settings.mcp.sidebar.actions.addServerTitle"),e[5]=o,e[6]=p):p=e[6];let b;e[7]!==o?(b=o("settings.mcp.sidebar.actions.addServerTitle"),e[7]=o,e[8]=b):b=e[8];let x,v;e[9]===Symbol.for("react.memo_cache_sentinel")?(x={touchAction:"manipulation"},v=t.jsx(se,{name:"add",className:"size-5"}),e[9]=x,e[10]=v):(x=e[9],v=e[10]);let S;e[11]!==n||e[12]!==p||e[13]!==b?(S=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:n,"aria-label":p,title:b,style:x,children:v}),e[11]=n,e[12]=p,e[13]=b,e[14]=S):S=e[14];let g;e[15]!==o?(g=o("mcpDropdown.actions.refreshAria"),e[15]=o,e[16]=g):g=e[16];let I;e[17]!==o?(I=o("mcpDropdown.actions.refreshAria"),e[17]=o,e[18]=I):I=e[18];let P;e[19]===Symbol.for("react.memo_cache_sentinel")?(P={touchAction:"manipulation"},e[19]=P):P=e[19];const T=r&&"animate-spin";let N;e[20]!==T?(N=te("size-5",T),e[20]=T,e[21]=N):N=e[21];let E;e[22]!==N?(E=t.jsx(se,{name:"refresh",className:N}),e[22]=N,e[23]=E):E=e[23];let D;e[24]!==r||e[25]!==f||e[26]!==E||e[27]!==g||e[28]!==I?(D=t.jsx("button",{type:"button",className:"flex size-10 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground disabled:opacity-60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",onClick:f,disabled:r,"aria-label":g,title:I,style:P,children:E}),e[24]=r,e[25]=f,e[26]=E,e[27]=g,e[28]=I,e[29]=D):D=e[29];let w;e[30]!==D||e[31]!==S?(w=t.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1 px-2 pt-1",children:[S,D]}),e[30]=D,e[31]=S,e[32]=w):w=e[32];let C;e[33]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx("div",{className:"min-h-0 flex-1",children:t.jsx(Ci,{active:!0,className:"h-full",listClassName:"max-h-none",hideHeader:!0,mobileListDensity:!0})}),e[33]=C):C=e[33];let y;return e[34]!==w?(y=t.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[w,C]}),e[34]=w,e[35]=y):y=e[35],y},$n=({open:s,onClose:e,tab:n,onTabChange:o,pendingChangesDiff:r,onOpenPlan:i,onOpenMcpSettings:a,variant:c="drawer"})=>{const{t:d}=ue(),u=l.useRef(null),[f,p]=l.useState(!1),[b,x]=l.useState(s),v=l.useRef(e);l.useEffect(()=>{v.current=e},[e]);const S=l.useRef(n);l.useEffect(()=>{S.current=n},[n]);const[g,I]=l.useState(()=>new Set);if(l.useEffect(()=>{s&&I(N=>{if(N.has(n))return N;const E=new Set(N);return E.add(n),E})},[s,n]),typeof document<"u"&&!u.current){let N=document.getElementById(On);N||(N=document.createElement("div"),N.id=On,document.body.appendChild(N)),u.current=N}if(l.useEffect(()=>{if(s){x(!0);const E=window.setTimeout(()=>p(!0),Ol);return()=>window.clearTimeout(E)}p(!1);const N=window.setTimeout(()=>x(!1),Bn+40);return()=>window.clearTimeout(N)},[s]),l.useEffect(()=>{if(!s)return;const N=document.body.style.overflow;c==="drawer"&&(document.body.style.overflow="hidden");const E=D=>{D.key==="Escape"&&S.current!=="terminal"&&v.current()};return document.addEventListener("keydown",E),()=>{c==="drawer"&&(document.body.style.overflow=N),document.removeEventListener("keydown",E)}},[s,c]),c==="drawer"&&!u.current)return null;const P=[{id:"changes",label:d("mobile.menu.changes"),icon:t.jsx(se,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"files",label:d("mobile.menu.files"),icon:t.jsx(se,{name:"file-text",className:"h-3.5 w-3.5"})},{id:"terminal",label:d("mobile.menu.terminal"),icon:t.jsx(se,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"notes",label:d("contextRail.surface.notes"),icon:t.jsx(se,{name:"sticky-note",className:"h-3.5 w-3.5"})},{id:"mcp",label:d("mobile.menu.mcp"),icon:t.jsx(ji,{className:"h-3.5 w-3.5"})}],T=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",children:[t.jsx("div",{className:"flex h-9 min-w-0 flex-1 items-center",children:b?t.jsx(ki,{items:P,activeId:n,onSelect:N=>o(N),layoutMode:"fit",variant:"active-pill",nonCompositedIndicator:!0,inactiveTabsIconOnly:!0,className:"h-full"}):null}),t.jsx("button",{type:"button",className:"-mr-1 flex size-10 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":d("mobile.surface.closeAria"),onClick:e,style:{touchAction:"manipulation"},children:t.jsx(se,{name:"close",className:"size-5"})})]}),t.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[g.has("changes")?t.jsx("div",{className:te("h-full",n!=="changes"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Tl,{initialDiffPath:r?.path??null,initialDiffStaged:r?.staged===!0})})},r?`changes:${r.path}:${r.staged}`:"changes"):null,g.has("files")?t.jsx("div",{className:te("h-full",n!=="files"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Ll,{})})}):null,g.has("terminal")?t.jsx("div",{className:te("h-full",n!=="terminal"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Si,{visible:s&&n==="terminal"})})}):null,g.has("notes")?t.jsx("div",{className:te("h-full",n!=="notes"&&"hidden"),children:t.jsx(Be,{children:t.jsx(Ni,{onActionComplete:e,onOpenPlan:i})})}):null,g.has("mcp")?t.jsx("div",{className:te("h-full",n!=="mcp"&&"hidden"),children:t.jsx(Be,{children:t.jsx($l,{onOpenMcpSettings:a})})}):null]})]});return c==="panel"?t.jsx("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:T}):ct.createPortal(t.jsx("section",{role:"dialog","aria-modal":"true","aria-label":d("mobile.header.openWorkspaceAria"),"aria-hidden":!s,className:"oc-keyboard-inset-surface fixed inset-0 z-50 flex flex-col bg-background text-foreground",style:{paddingTop:"var(--oc-safe-area-top, 0px)",transform:f?"none":"translateX(100%)",transition:`transform ${Bn}ms ${Bl}`,visibility:b?"visible":"hidden",pointerEvents:s?"auto":"none"},children:T}),u.current)};function Fl(s){return s.currentDirectory}function Wl(s){return s.refresh}function Ul(s){return s.loadMcpConfigs}function Vl(s){return window.setTimeout(s,500)}const Tt=()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0?!0:window.location.protocol==="capacitor:",Hl=()=>{l.useEffect(()=>{if(!Tt())return;let s=!1;const e=[],n=document.documentElement;n.classList.add("oc-capacitor-app"),window.Capacitor?.getPlatform?.()==="android"&&n.classList.add("oc-platform-android"),e.push(Do());const r=i=>{n.style.setProperty("--oc-keyboard-inset",`${Math.max(0,Math.round(i))}px`)};return $e(()=>import("./vendor-capacitor-status-bar-B-N0EOVk.js"),__vite__mapDeps([117,118])).then(async({StatusBar:i,Style:a})=>{if(s)return;const c=window.Capacitor?.getPlatform?.(),d=async()=>{if(c==="android"){const b=document.documentElement.classList.contains("dark"),x=(b?localStorage.getItem("splashBgDark"):localStorage.getItem("splashBgLight"))||(b?"#171515":"#fffdf4");await i.setOverlaysWebView({overlay:!1}).catch(()=>{}),await i.setBackgroundColor({color:x}).catch(()=>{}),await i.setStyle({style:b?a.Dark:a.Light}).catch(()=>{}),await i.show().catch(()=>{});return}await i.setStyle({style:a.Default}).catch(()=>{}),await i.setOverlaysWebView({overlay:!0}).catch(()=>{}),await i.show().catch(()=>{})};await d();const u=window.setTimeout(()=>{d()},400);e.push(()=>window.clearTimeout(u));const{App:f}=await $e(async()=>{const{App:b}=await import("./vendor-capacitor-app-BrDJj9I_.js");return{App:b}},__vite__mapDeps([119,4,118])),p=await f.addListener("appStateChange",({isActive:b})=>{b&&d()});if(s){p.remove();return}e.push(()=>{p.remove()})}).catch(()=>{}),$e(()=>import("./vendor-capacitor-keyboard-CYccoJjr.js"),__vite__mapDeps([120,118])).then(async({Keyboard:i})=>{if(s)return;if(window.Capacitor?.getPlatform?.()==="android"){const k=await i.addListener("keyboardWillShow",z=>{dn(z.keyboardHeight),n.classList.add("oc-keyboard-open"),window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),A=await i.addListener("keyboardDidShow",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!0}}))}),R=await i.addListener("keyboardWillHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-intent",{detail:{open:!1}})),n.classList.remove("oc-keyboard-open")}),j=await i.addListener("keyboardDidHide",()=>{window.dispatchEvent(new CustomEvent("oc:keyboard-settled",{detail:{open:!1}}))}),V=()=>{k.remove(),A.remove(),R.remove(),j.remove()};if(s){V();return}e.push(V);return}await i.setAccessoryBarVisible({isVisible:!1}).catch(()=>{});const c=250,d=200,u="cubic-bezier(0.38, 0.7, 0.125, 1)";let f=null,p=null,b=0,x=!1,v=0,S=!1;const g=(k,A)=>{n.style.setProperty(k,`${Math.max(0,Math.round(A))}px`)},I=()=>{f!==null&&(window.clearTimeout(f),f=null)},P=(k,A)=>{window.dispatchEvent(new CustomEvent(k,{detail:A}))},T=()=>{const k=[],A=document.querySelector(".oc-mobile-composer");A&&k.push({el:A,factor:1});const R=document.querySelector(".oc-draft-center");return R&&k.push({el:R,factor:.5}),k},N=()=>{for(const{el:k}of T())k.style.transition="",k.style.transform=""},E=await i.addListener("keyboardWillShow",k=>{if(I(),dn(k.keyboardHeight),S=!0,b=k.keyboardHeight,!x){const R=document.querySelector(".oc-mobile-app-shell");v=R&&parseFloat(getComputedStyle(R).paddingBottom)||0}const A=Math.max(0,b-v);n.classList.remove("oc-kb-hide"),p!==null&&(window.clearTimeout(p),p=null),n.classList.add("oc-keyboard-open","oc-kb-animating","oc-kb-caret-hold"),r(b);for(const{el:R,factor:j}of T())R.style.transition=`transform ${c}ms ${u}`,R.style.transform=`translateY(${-A*j}px)`;g("--oc-kb-scroll-inset",A),P("oc:keyboard-settled",{open:!0}),P("oc:keyboard-anim",{phase:"show",slide:A,durationMs:c,easing:u}),f=window.setTimeout(()=>{f=null,n.classList.remove("oc-kb-animating"),g("--oc-kb-layout",b),x=!0,N(),P("oc:keyboard-settled",{open:!0}),p=window.setTimeout(()=>{p=null,n.classList.remove("oc-kb-caret-hold")},250)},c+20)}),D=()=>{if(!S)return;S=!1,I(),P("oc:keyboard-intent",{open:!1}),p!==null&&(window.clearTimeout(p),p=null),n.classList.remove("oc-kb-caret-hold");const k=Math.max(0,b-v);if(n.classList.remove("oc-keyboard-open"),r(0),g("--oc-kb-scroll-inset",0),x){n.classList.remove("oc-kb-animating"),g("--oc-kb-layout",0),x=!1;for(const{el:A,factor:R}of T())A.style.transition="none",A.style.transform=`translateY(${-k*R}px)`;document.querySelector(".oc-mobile-app-shell")?.offsetHeight}P("oc:keyboard-anim",{phase:"hide",slide:k,durationMs:d,easing:u}),n.classList.add("oc-kb-animating","oc-kb-hide");for(const{el:A}of T())A.style.transition=`transform ${d}ms ${u}`,A.style.transform="translateY(0px)";f=window.setTimeout(()=>{f=null,n.classList.remove("oc-kb-animating","oc-kb-hide"),N(),P("oc:keyboard-settled",{open:!1})},d+20)},w=await i.addListener("keyboardWillHide",D),C=k=>k instanceof HTMLElement&&(k.tagName==="TEXTAREA"||k.tagName==="INPUT"||k.isContentEditable),y=k=>{S&&C(k.target)&&(C(k.relatedTarget)||window.setTimeout(()=>{S&&(C(document.activeElement)||D())},0))};if(document.addEventListener("focusout",y,!0),s){I(),document.removeEventListener("focusout",y,!0),E.remove(),w.remove();return}e.push(I,()=>{p!==null&&(window.clearTimeout(p),p=null)},()=>document.removeEventListener("focusout",y,!0),()=>{E.remove()},()=>{w.remove()})}).catch(()=>{}),()=>{s=!0,e.forEach(i=>i()),Mo(),n.classList.remove("oc-capacitor-app","oc-keyboard-open","oc-kb-animating","oc-kb-hide","oc-kb-caret-hold","oc-platform-android"),n.style.removeProperty("--oc-keyboard-inset"),n.style.removeProperty("--oc-kb-shift"),n.style.removeProperty("--oc-kb-layout"),n.style.removeProperty("--oc-kb-scroll-inset")}},[])},Gl=s=>{const e=l.useRef(!1);l.useEffect(()=>{if(!Tt())return;let n=!1;const o=[],r=()=>{e.current&&(e.current=!1,s())},i=()=>{if(document.visibilityState==="hidden"){e.current=!0;return}r()};return document.addEventListener("visibilitychange",i),o.push(()=>document.removeEventListener("visibilitychange",i)),$e(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([119,4,118])).then(async({App:a})=>{if(n)return;const c=await a.addListener("appStateChange",({isActive:u})=>{if(document.documentElement.classList.toggle("oc-native-app-active",u),!u){e.current=!0;return}r()}),d=await a.addListener("resume",r);if(n){c.remove(),d.remove();return}o.push(()=>{c.remove()},()=>{d.remove()})}).catch(()=>{}),()=>{n=!0,o.forEach(a=>a())}},[s])},Kl=s=>{l.useEffect(()=>{if(!Tt())return;let e=!1,n=null;return $e(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([119,4,118])).then(async({App:o})=>{if(e)return;const r=await o.addListener("backButton",()=>{s()||o.minimizeApp().catch(()=>{})});if(e){r.remove();return}n=()=>{r.remove()}}).catch(()=>{}),()=>{e=!0,n?.()}},[s])};function ql(s){const e=de.c(4),n=2500,{uiFont:o}=Lo(),[r,i]=l.useState(!1);let a,c;return e[0]!==n||e[1]!==o?(a=()=>{let d=!1;const u=()=>{d||i(!0)},f=()=>{requestAnimationFrame(()=>requestAnimationFrame(u))},p=Promise.all([zo(o).catch(Zl),document.fonts?.ready?.then(Xl).catch(Ql)??Promise.resolve(),Yi.catch(Jl)]).then(Yl),b=new Promise(x=>{window.setTimeout(x,n)});return Promise.race([p,b]).then(f),()=>{d=!0}},c=[o,n],e[0]=n,e[1]=o,e[2]=a,e[3]=c):(a=e[2],c=e[3]),l.useEffect(a,c),r}function Yl(){}function Jl(){}function Ql(){}function Xl(){}function Zl(){}const ec="openchamber",tc=s=>s.replace(/^\/+|\/+$/g,""),sc=s=>{const e=tc(s.pathname).split("/").filter(Boolean);return s.host?[s.host,...e]:e};function nc(s){if(typeof s!="string"||s.length===0)return null;let e;try{e=new URL(s)}catch{return null}if(e.protocol!==`${ec}:`)return null;const n=sc(e),o=(n[0]??"").toLowerCase(),r=n.slice(1),i=e.searchParams;switch(o){case"session":{const a=r[0]||i.get("id")||"";return a?{type:"session",sessionId:a,directory:i.get("dir")??void 0}:null}case"new":case"new-session":return{type:"new-session",directory:i.get("dir")??void 0,projectId:i.get("project")??void 0,agent:i.get("agent")??void 0,model:i.get("model")??void 0};case"sessions":{const a=i.get("filter");return{type:"sessions",filter:a==="attention"||a==="recent"||a==="all"?a:void 0}}case"status":return{type:"status"};case"settings":return{type:"settings",section:r[0]||i.get("section")||void 0};case"changes":return{type:"changes",path:r.join("/")||i.get("path")||void 0,staged:i.get("staged")==="true"};case"view":{const a=(r[0]||"").toLowerCase();return a==="changes"?{type:"changes"}:a==="files"||a==="mcp"||a==="instances"||a==="update"?{type:"view",target:a}:null}default:return null}}let Le={},Cr=!1,kt=null;const rc=s=>{switch(s.type){case"session":return ve.getState().setCurrentSession(s.sessionId,s.directory??null),!0;case"new-session":{const e=ve.getState();return e.openNewSessionDraft(),(s.directory||s.projectId)&&e.setNewSessionDraftTarget({directoryOverride:s.directory??null,projectId:s.projectId??null,selectedProjectId:s.projectId??null}),!0}case"sessions":return Le.openSessions?(Le.openSessions(s.filter),!0):!1;case"status":return Le.openSessions?(Le.openSessions(),!0):!1;case"view":return Le.openView?(Le.openView(s.target),!0):!1;case"changes":return Le.openChanges?(Le.openChanges({path:s.path,staged:s.staged}),!0):!1;case"settings":return Le.openSettings?(Le.openSettings(s.section),!0):!1}},Vs=()=>{if(!Cr||!kt)return;const s=kt;kt=null,rc(s)||(kt=s)},Rr=s=>{kt=s,Vs()},Fn=s=>{const e=nc(s);e&&Rr(e)},oc=s=>{Cr=s,Vs()},ic=s=>{const e=de.c(3);let n,o;e[0]!==s?(n=()=>(Le=s,Vs(),()=>{Le===s&&(Le={})}),o=[s],e[0]=s,e[1]=n,e[2]=o):(n=e[1],o=e[2]),l.useEffect(n,o)},ac=s=>{const{ready:e}=s;l.useEffect(()=>{oc(e)},[e]),l.useEffect(()=>{if(!Ce())return;let n=!1;const o=[];return $e(()=>import("./vendor-capacitor-app-BrDJj9I_.js"),__vite__mapDeps([119,4,118])).then(async({App:r})=>{if(n)return;const i=await r.addListener("appUrlOpen",a=>{Fn(a?.url)});if(n){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),$e(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([121,118])).then(async({PushNotifications:r})=>{if(n)return;const i=await r.addListener("pushNotificationActionPerformed",a=>{const c=a?.notification?.data,d=typeof c?.url=="string"?c.url:typeof c?.deeplink=="string"?c.deeplink:void 0;if(d){Fn(d);return}const u=typeof c?.sessionId=="string"?c.sessionId:void 0;u&&Rr({type:"session",sessionId:u})});if(n){i.remove();return}o.push(()=>{i.remove()})}).catch(()=>{}),()=>{n=!0,o.forEach(r=>r())}},[])},lc=32,cc=80,dc=64,uc=.7,fc=(s,e)=>{const n=l.useRef(e);n.current=e,l.useEffect(()=>{const o=s.current;if(!o)return;const i=window.Capacitor?.getPlatform?.()==="android"?cc:lc;let a=!1,c=!1,d=0,u=0;const f=b=>{if(b.touches.length!==1){a=!1;return}const x=b.touches[0],v=o.clientWidth,S=x.clientX<=i,g=x.clientX>=v-i;a=S||g,c=S,d=x.clientX,u=x.clientY},p=b=>{if(!a)return;a=!1;const x=b.changedTouches[0];if(!x)return;const v=x.clientX-d,S=x.clientY-u;Math.abs(v)<dc||Math.abs(S)>Math.abs(v)*uc||c&&v<=0||!c&&v>=0||(c?n.current.onLeftEdgeSwipe?.():n.current.onRightEdgeSwipe?.())};return o.addEventListener("touchstart",f,{passive:!0}),o.addEventListener("touchend",p,{passive:!0}),()=>{o.removeEventListener("touchstart",f),o.removeEventListener("touchend",p)}},[s])},mc=()=>{if(typeof window>"u")return;const s=window.__OPENCHAMBER_APNS_ENV__;if(s==="development")return"sandbox";if(s==="production")return"production"},pc=()=>{if(typeof window>"u")return!1;const e=window.Capacitor?.getPlatform?.();return e==="ios"||e==="android"},hc=s=>{const{enabled:e}=s,n=Ve(r=>r.nativeNotificationsEnabled),o=l.useRef(null);l.useEffect(()=>{if(!e||!n||!pc())return;let r=!1;const i=[];return $e(()=>import("./vendor-capacitor-push-notifications-KNe1zSBF.js"),__vite__mapDeps([121,118])).then(async({PushNotifications:a})=>{if(r)return;let c=await a.checkPermissions().catch(()=>null);if(c?.receive!=="granted"&&(c=await a.requestPermissions().catch(()=>null)),c?.receive!=="granted")return;const d=await a.addListener("registration",f=>{o.current=f.value,nn()?.push?.registerApnsToken?.({token:f.value,platform:Hn(),environment:mc()})}),u=await a.addListener("registrationError",f=>{console.warn("[Push] APNs registration error:",f)});if(await a.register().catch(()=>{}),r){d.remove(),u.remove();return}i.push(()=>{d.remove()},()=>{u.remove()})}).catch(()=>{}),()=>{r=!0,i.forEach(a=>a())}},[e,n]),l.useEffect(()=>{if(n)return;const r=o.current;if(!r)return;o.current=null,nn()?.push?.unregisterApnsToken?.({token:r})},[n])},Wn=s=>{const e=de.c(12),{side:n,isResizing:o,ariaLabel:r,handleProps:i}=s,a=n==="left"?"right-0":"left-0";let c;e[0]!==a?(c=te("absolute inset-y-0 z-50 w-6 cursor-col-resize touch-none",a),e[0]=a,e[1]=c):c=e[1];const d=n==="left"?"right-0":"left-0",u=o&&"bg-[var(--interactive-border)]";let f;e[2]!==d||e[3]!==u?(f=te("absolute inset-y-0 w-[3px] transition-colors",d,u),e[2]=d,e[3]=u,e[4]=f):f=e[4];let p;e[5]!==f?(p=t.jsx("div",{className:f}),e[5]=f,e[6]=p):p=e[6];let b;return e[7]!==r||e[8]!==i||e[9]!==c||e[10]!==p?(b=t.jsx("div",{className:c,role:"separator","aria-orientation":"vertical","aria-label":r,...i,children:p}),e[7]=r,e[8]=i,e[9]=c,e[10]=p,e[11]=b):b=e[11],b},bc=320,gc=380,Un=280,xc=560,yc=900;function Vn(s,e,n,o){const r=de.c(23),i=o===void 0?xc:o,a=l.useRef(null);let c;r[0]!==n||r[1]!==i||r[2]!==e?(c=()=>{if(typeof window>"u")return n;const j=Number.parseInt(window.localStorage.getItem(e)??"",10);return Number.isFinite(j)?Math.min(i,Math.max(Un,j)):n},r[0]=n,r[1]=i,r[2]=e,r[3]=c):c=r[3];const[d,u]=l.useState(c),[f,p]=l.useState(!1),b=l.useRef(0),x=l.useRef(d),v=l.useRef(null),S=l.useRef(null);let g;r[4]!==i?(g=j=>Math.min(i,Math.max(Un,Math.round(j))),r[4]=i,r[5]=g):g=r[5];const I=g;let P;r[6]===Symbol.for("react.memo_cache_sentinel")?(P=j=>{const V=a.current;V&&(V.style.width=`${j}px`,V.style.minWidth=`${j}px`,V.style.maxWidth=`${j}px`,V.style.setProperty("--oc-ipad-sidebar-width",`${j}px`))},r[6]=P):P=r[6];const T=P;let N;r[7]!==d?(N=j=>{try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}S.current=j.pointerId,b.current=j.clientX,x.current=d,v.current=d,p(!0),j.preventDefault()},r[7]=d,r[8]=N):N=r[8];const E=N;let D;r[9]!==I||r[10]!==s?(D=j=>{if(S.current!==j.pointerId)return;const V=j.clientX-b.current,z=I(x.current+(s==="left"?V:-V));v.current!==z&&(v.current=z,T(z))},r[9]=I,r[10]=s,r[11]=D):D=r[11];const w=D;let C;r[12]!==I||r[13]!==e?(C=j=>{if(S.current!==j.pointerId)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const V=I(v.current??x.current);S.current=null,v.current=null,p(!1),u(V);try{window.localStorage.setItem(e,String(V))}catch{}},r[12]=I,r[13]=e,r[14]=C):C=r[14];const y=C;let k;r[15]!==E||r[16]!==y||r[17]!==w?(k={onPointerDown:E,onPointerMove:w,onPointerUp:y,onPointerCancel:y},r[15]=E,r[16]=y,r[17]=w,r[18]=k):k=r[18];const A=k;let R;return r[19]!==A||r[20]!==f||r[21]!==d?(R={asideRef:a,width:d,isResizing:f,handleProps:A},r[19]=A,r[20]=f,r[21]=d,r[22]=R):R=r[22],R}const vc=["general","appearance","chat","notifications","sessions","git","magic-prompts","behavior","mcp","providers","usage","voice","about"],wc=1e3,jc=({onActiveConnectionDeleted:s})=>{const{t:e}=ue(),[n,o]=l.useState(!1),[r,i]=l.useState(null),[a,c]=l.useState(!1),[d,u]=l.useState("changes"),[f,p]=l.useState(null),[b,x]=l.useState("nav"),[v,S]=l.useState(null),g=Ve(Y=>Y.setSettingsPage),I=Ve(Y=>Y.wideChatLayoutEnabled),P=at(Y=>Y.available),T=at(Y=>Y.runtimeType),N=l.useMemo(()=>Tt(),[]),E=Bt(Y=>Y.mcpServers),D=Bt(Y=>Y.setMcpDraft),w=Bt(Y=>Y.setSelectedMcp),C=l.useCallback(()=>{i(null),p(null)},[]),y=l.useCallback(Y=>{i(Y)},[]),k=l.useCallback(()=>{c(!1)},[]),A=l.useCallback(Y=>{x(Y),y("settings")},[y]),{enabled:R,roomyForPanels:j}=ys(),z=Xo()==="portrait",h=Zo(),[L,M]=l.useState(()=>ei().roomyForPanels),B=l.useCallback(()=>{M(Y=>!Y)},[]);l.useEffect(()=>{R||M(!1)},[R]);const H=l.useCallback(()=>{S(null),u("files"),c(!0)},[]),Z=l.useCallback((Y=null)=>{S(Y),u("changes"),c(!0)},[]),Q=Vn("left","openchamber.ipad.leftSidebarWidth",bc),_=Vn("right","openchamber.ipad.rightSidebarWidth",gc,yc),J=j,q=J&&a?_.width:0,F=R&&L?Q.width:0;l.useEffect(()=>{if(typeof document>"u")return;const Y=document.documentElement;return Y.style.setProperty("--oc-chat-inset-left",`${F}px`),Y.style.setProperty("--oc-chat-inset-right",`${q}px`),()=>{Y.style.removeProperty("--oc-chat-inset-left"),Y.style.removeProperty("--oc-chat-inset-right")}},[F,q]),l.useEffect(()=>{if(typeof document>"u")return;const Y=document.documentElement;return Y.classList.toggle("wide-chat-layout",I),()=>Y.classList.remove("wide-chat-layout")},[I]),l.useEffect(()=>{if(typeof document>"u")return;const Y=R&&(z||h),ce=document.documentElement;return ce.classList.toggle("oc-keep-draft-starters",Y),()=>ce.classList.remove("oc-keep-draft-starters")},[h,R,z]);const U=l.useMemo(()=>({openChanges:({diffPath:Y,staged:ce}={})=>{Z(Y?{path:Y,staged:ce===!0}:null)},openFiles:()=>H(),openSettings:()=>A("nav")}),[Z,H,A]),X=l.useMemo(()=>({openSessions:()=>{R?M(!0):o(!0)},openView:Y=>{if(Y==="files"){H();return}if(Y==="mcp"){u("mcp"),c(!0);return}y(Y)},openChanges:({path:Y,staged:ce}={})=>{Z(Y?{path:Y,staged:ce===!0}:null)},openSettings:Y=>{Y&&g(Y),A(Y?"page-content":"nav")}}),[R,Z,H,A,y,g]);ic(X);const ee=l.useRef(null);fc(ee,{onLeftEdgeSwipe:()=>{R?M(!0):o(!0)},onRightEdgeSwipe:()=>c(!0)});const W=l.useCallback(()=>f?(p(null),!0):r?(C(),!0):a?(k(),!0):n?(o(!1),!0):!1,[r,C,k,f,n,a]);Kl(W);const oe=!N&&P&&(T==="desktop"||T==="web"),ie=R?"dialog":"fullscreen",fe=l.useMemo(()=>({instanceLabel:N?yt():null,onOpenInstances:N?()=>y("instances"):void 0,onOpenSettings:()=>A("nav"),onOpenUpdate:oe?()=>y("update"):void 0}),[A,y,N,oe]),je=l.useCallback(()=>{const Y="new-mcp-server";let ce=Y,Se=1;for(;E.some(Re=>Re.name===ce);)ce=`${Y}-${Se}`,Se+=1;D({name:ce,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),w(ce),g("mcp"),A("page-content")},[E,A,D,w,g]);return t.jsx(ti,{actions:U,children:t.jsxs("div",{className:"oc-mobile-app-shell main-content-safe-area flex h-[100dvh] flex-row bg-background text-foreground","data-page-scroll-lock":"true",children:[R?t.jsxs("aside",{ref:Q.asideRef,className:te("relative flex h-full shrink-0 flex-col overflow-hidden border-r border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!L&&"border-r-0"),style:{width:L?Q.width:0,minWidth:L?Q.width:0,maxWidth:L?Q.width:0,"--oc-ipad-sidebar-width":`${Q.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:Q.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!L,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:te("flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",Q.isResizing&&"pointer-events-none",!L&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Be,{children:t.jsx(An,{open:!0,variant:"sidebar",onOpenChange:Y=>{!Y&&!j&&M(!1)},footer:fe})})}),L?t.jsx(Wn,{side:"left",isResizing:Q.isResizing,ariaLabel:e("sidebar.resize.leftPanelAria"),handleProps:Q.handleProps}):null]}):null,t.jsxs("div",{className:"flex h-full min-w-0 flex-1 flex-col","data-page-scroll-lock":"true",children:[t.jsx(el,{onOpenSessions:()=>R?B():o(!0),onOpenWorkspace:()=>c(!0),compactTitle:R}),t.jsx("main",{ref:ee,className:"relative min-h-0 flex-1 overflow-hidden","data-page-scroll-lock":"true",children:t.jsx("div",{className:"h-full w-full",children:t.jsx(Be,{children:t.jsx(Di,{})})})})]}),R?null:t.jsx(An,{open:n,onOpenChange:o,footer:fe}),R?t.jsxs("aside",{ref:_.asideRef,className:te("relative flex h-full shrink-0 flex-col overflow-hidden border-l border-border/70 bg-background will-change-[width] motion-reduce:transition-none",!q&&"border-l-0"),style:{width:q,minWidth:q,maxWidth:q,"--oc-ipad-sidebar-width":`${_.width}px`,overflowX:"clip",paddingTop:"var(--oc-safe-area-top, 0px)",transitionProperty:_.isResizing?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!q,"data-page-scroll-lock":"true",children:[t.jsx("div",{className:te("flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",_.isResizing&&"pointer-events-none",!q&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-ipad-sidebar-width)",overflowX:"hidden"},children:t.jsx(Be,{children:t.jsx($n,{open:a,onClose:k,tab:d,onTabChange:u,pendingChangesDiff:v,onOpenPlan:p,onOpenMcpSettings:je,variant:J?"panel":"drawer"})})}),q?t.jsx(Wn,{side:"right",isResizing:_.isResizing,ariaLabel:e("sidebar.resize.rightPanelAria"),handleProps:_.handleProps}):null]}):t.jsx($n,{open:a,onClose:k,tab:d,onTabChange:u,pendingChangesDiff:v,onOpenPlan:p,onOpenMcpSettings:je}),f?t.jsx(jt,{open:!0,variant:ie,onClose:()=>p(null),ariaLabel:f.title,title:f.title,children:t.jsx(Be,{children:t.jsx(Mi,{targetPath:f.path,onNavigatedToChat:()=>{C(),k()}})})}):null,r==="instances"&&N?t.jsx(jt,{open:!0,variant:ie,dialogAlign:"app",onClose:C,ariaLabel:e("mobile.menu.instances"),title:e("mobile.menu.instances"),children:t.jsx(rl,{onConnect:C,onActiveConnectionDeleted:s})}):null,r==="settings"?t.jsx(jt,{open:!0,variant:ie,dialogAlign:"app",onClose:C,ariaLabel:e("mobile.menu.settings"),headerless:!0,children:t.jsx(Be,{children:t.jsx(Li,{forceMobile:!0,isWindowed:!0,initialMobileStage:b,visiblePageSlugs:vc.filter(Y=>!(N&&Y==="about")),onClose:C})})}):null,r==="update"?t.jsx(jt,{open:!0,variant:ie,dialogAlign:"app",onClose:C,ariaLabel:e("mobile.menu.update"),title:e("mobile.menu.update"),children:t.jsx(Be,{children:t.jsx("div",{className:"h-full overflow-auto px-5 py-4",children:t.jsx(zi,{initialUpdateDialogOpen:!0})})})}):null]})})};function kc({apis:s}){const{t:e}=ue(),n=ze(_=>_.initializeApp),o=ze(_=>_.isInitialized),r=ze(_=>_.isConnected),i=ze(_=>_.connectionPhase),a=ze(_=>_.providers.length),c=ze(_=>_.agents.length),d=ze(_=>_.loadProviders),u=ze(_=>_.loadAgents),f=dt(_=>_.currentDirectory),p=ve(_=>_.error),b=ve(_=>_.clearError),x=Ve(_=>_.setIsMobile),v=Oo(_=>_.refreshStatus),S=Bo(_=>_.setPlanModeEnabled),g=Oe(_=>_.projects),[I,P]=l.useState(0),[T,N]=l.useState(0),[E,D]=l.useState(!1),[w,C]=l.useState("pending"),[y,k]=l.useState(null),A=l.useMemo(()=>yt(),[]),[,R]=l.useReducer(_=>_+1,0),j=l.useMemo(()=>Tt(),[]),V=l.useRef(0),z=l.useRef(0),h=l.useCallback(()=>{const _=Ge(),J=z.current+1;if(z.current=J,!_){ts();return}const q=()=>{n(),v(s.github,{force:!0}),a===0&&d({source:"mobileApp:nativeResume"}),c===0&&u({source:"mobileApp:nativeResume"})},F=()=>{it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(X=>X+1)};Ft().then(X=>{if(z.current===J){if(X==="no-connection"){F();return}if(X==="needs-login"){k({kind:"auth-expired",label:yt()??""}),F();return}if(X==="unreachable"){window.setTimeout(()=>{z.current===J&&Ft().then(ee=>{if(z.current===J&&ee!=="switched"){if(ee==="unchanged"){q();return}ee==="needs-login"&&k({kind:"auth-expired",label:yt()??""}),F()}})},4e3);return}X!=="switched"&&q()}});const U=Date.now();U-V.current>=wc&&(V.current=U,window.dispatchEvent(new Event("openchamber:system-resume")))},[c,s.github,n,u,d,a,v]);Hl(),Gl(h),l.useEffect(()=>{if(!j)return;let _;const J=()=>{window.clearTimeout(_),_=window.setTimeout(()=>h(),1500)};return window.addEventListener("online",J),()=>{window.removeEventListener("online",J),window.clearTimeout(_)}},[j,h]),l.useEffect(()=>(rn(s),()=>rn(null)),[s]),l.useEffect(()=>Zr(_=>{if(!!_.runtimeKey&&_.runtimeKey===_.previousRuntimeKey){Ri(),R();return}Pi(_),N(q=>q+1),P(q=>q+1)}),[]),l.useEffect(()=>{if(!j||r||Ge()){C("done");return}let _=!1;return C("attempting"),ts().catch(()=>({status:"no-candidate"})).then(J=>{_||(J.status==="unreachable"?k({kind:"unreachable",label:J.label}):J.status==="needs-login"&&k({kind:"auth-expired",label:J.label}),C("done"))}),()=>{_=!0}},[]),l.useEffect(()=>{if(!j||!Ge())return;let _=!1;const J=q=>{q&&k(q),it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(F=>F+1)};return Ft().then(async q=>{if(_||q==="switched"||q==="unchanged")return;const F=yt();if(q==="needs-login"){J({kind:"auth-expired",label:F??""});return}if(q==="unreachable"){J(F?{kind:"unreachable",label:F}:null);return}const U=await ts().catch(()=>({status:"no-candidate"}));_||U.status==="connected"||(U.status==="needs-login"?J({kind:"auth-expired",label:U.label}):U.status==="unreachable"?J({kind:"unreachable",label:U.label}):J(null))}),()=>{_=!0}},[]),l.useEffect(()=>{x(!0)},[x]),l.useEffect(()=>{j&&!Ge()||n()},[I,n,j]),l.useEffect(()=>{r&&(a===0&&d({source:"mobileApp:recovery"}),c===0&&u({source:"mobileApp:recovery"}))},[c,r,u,d,a]);const L=l.useRef(!1),[M,B]=l.useState(j);l.useEffect(()=>{if(!j||!r||L.current)return;if(ve.getState().currentSessionId){L.current=!0,B(!1);return}const _=Pt(),J=$o(_);if(!J){L.current=!0,B(!1);return}let q=!1;const F=window.setTimeout(()=>B(!1),6e3);return(async()=>{const U=await vs().catch(()=>null);if(q)return;if(!U){B(!1);return}L.current=!0;const X=U.activeSessions.find(W=>W.id===J.sessionId);if(!X){Fo(_),B(!1);return}const ee=ve.getState();ee.currentSessionId||ee.setCurrentSession(X.id,xs(X)??J.directory??void 0),B(!1)})(),()=>{q=!0,window.clearTimeout(F)}},[I,r,j]),l.useEffect(()=>{r&&on.setDirectory(f)},[f,r]),l.useEffect(()=>{r&&v(s.github,{force:!0})},[s.github,r,v]),l.useEffect(()=>{if(!r||g.length===0)return;let _=!1;return(async()=>{const q=new Map(ve.getState().availableWorktreesByProject);if(await Promise.all(g.map(async X=>{const ee=X.path.replace(/\\/g,"/").replace(/\/+$/,"");if(ee)try{if(!(Ue.getState().directories.get(ee)?.isGitRepo??await $e(()=>import("./useAppFontEffects-DdvGxoPX.js").then(fe=>fe.fV),__vite__mapDeps([8,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108])).then(fe=>fe.checkIsGitRepository(ee))))return;const ie=await sr({id:X.id,path:ee});if(_)return;q.set(ee,ie)}catch{}})),_)return;const F=nr(g,q),U=ve.getState().availableWorktreesByProject;Qo(F,U)||ve.setState({availableWorktrees:[...F.values()].flat(),availableWorktreesByProject:F})})(),()=>{_=!0}},[r,g]),l.useEffect(()=>{let _=!1;return(async()=>{const q=await bs("/health",{method:"GET"}).catch(()=>null);if(!q||!q.ok||_)return;const F=await q.json().catch(()=>null);if(!F||_)return;const U=F.planModeExperimentalEnabled;S(U===!0||U===1||U==="1"||U==="true")})(),()=>{_=!0}},[S]),l.useEffect(()=>{if(!p)return;const _=window.setTimeout(()=>b(),5e3);return()=>window.clearTimeout(_)},[b,p]),l.useEffect(()=>{if(!(!r&&(j?!!Ge():!0))){D(!1);return}const J=window.setTimeout(()=>{D(!0)},j?4e3:8e3);return()=>window.clearTimeout(J)},[r,j,I,T]),Wo(),Uo({enabled:!0}),Ti(),Vo(),Ii(),hc({enabled:j&&r}),ac({ready:j&&r&&o});const H=ql(),Z=!r&&i==="reconnecting";if(!H)return t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Je,{width:120,height:120,isAnimated:!0})});const Q=!!Ge();return j&&(!Q||!r&&!Z)?Q?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-4",children:[t.jsx(Je,{width:120,height:120,isAnimated:!E}),E?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("mobile.connect.recovery.description")})]}),t.jsx(ge,{type:"button",variant:"outline",onClick:()=>{it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(_=>_+1)},children:e("mobile.connect.cancelPassword")})]}):null]})}):w!=="done"?t.jsxs("main",{className:"relative flex min-h-dvh items-center justify-center bg-background text-foreground",children:[t.jsx(Je,{width:120,height:120,isAnimated:!0}),A?t.jsxs("div",{className:"absolute inset-x-0 top-[calc(50%+84px)] flex flex-col items-center gap-0.5 px-6 text-center",children:[t.jsx("p",{className:"typography-small text-muted-foreground",children:e("mobile.connect.splash.connectingTo")}),t.jsxs("p",{className:"typography-small text-foreground",children:[A,t.jsx(Ho,{})]})]}):null]}):t.jsx(t.Fragment,{children:t.jsx($a,{onConnected:()=>P(_=>_+1),notice:y})}):!r&&!Z?E?t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background px-6 text-center text-foreground",children:t.jsxs("div",{className:"max-w-sm space-y-3",children:[t.jsx("h1",{className:"typography-h3 text-foreground",children:e("sessionAuth.error.networkTitle")}),t.jsx("p",{className:"typography-body text-muted-foreground",children:e("sessionAuth.error.networkDescription")})]})}):t.jsx("main",{className:"flex min-h-dvh items-center justify-center bg-background text-foreground",children:t.jsx(Je,{width:120,height:120,isAnimated:!0})}):t.jsx(Be,{children:t.jsx(Go,{sdk:on.getSdkClient(),directory:f||"",children:t.jsx(Ko,{apis:s,children:t.jsx(qo,{delayDuration:300,skipDelayDuration:150,children:t.jsxs("div",{className:"h-full bg-background text-foreground",children:[j&&M?t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background",children:t.jsx(Je,{width:120,height:120,isAnimated:!0})}):null,t.jsx(Yo,{embeddedBackgroundWorkEnabled:o}),t.jsx(_i,{}),t.jsx(ra,{}),t.jsx(jc,{onActiveConnectionDeleted:()=>{it({apiBaseUrl:"",clientToken:null,runtimeKey:"mobile-disconnected"}),P(_=>_+1)}}),t.jsx(Jo,{position:"top-center",offset:"calc(var(--oc-safe-area-top, 0px) + 16px)"}),o?t.jsx(Ai,{}):null]})})})},T)})}const Sc=()=>{li(),eo().then(()=>{Promise.all([to(),ci()]).catch(s=>{console.error("[mobile-main] settings init failed:",s)}),di(),ui(),fi()}).catch(s=>{console.error("[mobile-main] appearance init failed:",s)}).finally(()=>{Ji()})};function Lu(s){window.__OPENCHAMBER_SURFACE__="mobile",si(),Sc(),na(),ni();const e=document.getElementById("root");if(!e)throw new Error("Root element not found");const o=window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",r=o?{...s,notifications:{notifyAgentCompletion:async()=>!1,canNotify:()=>!1}}:s,i=t.jsx(kc,{apis:r});Yr.createRoot(e).render(t.jsx(ls.StrictMode,{children:t.jsx(ri,{children:t.jsx(oi,{children:t.jsx(ii,{children:t.jsx(Oi,{children:o?i:t.jsx(ai,{children:i})})})})})}))}export{Lu as renderMobileApp};
|