import{bb as e,o6 as s,o7 as t,o8 as n,o9 as o,et as a,m as i,w as r,x as l,h as d,bN as c,oa as u,ob as g,oc as p,d8 as m,ev as h,nL as f,nv as x,od as b,a0 as w,y as k,mU as v,iW as j,bB as y,f as M,oe as C,of as _,g4 as I,d9 as N,B as $,b9 as L,at as S,dZ as A,ad as E,V as R}from"./c818056db-BBpc4u6S.js";import{j as P,r as z}from"./vendor-react-RSDKEZ60.js";import{c as F,u as O,M as G}from"./vendor-intl-BNW8a19h.js";import{c as H,u as D,b as q}from"./vendor-query-AdjnXGiH.js";import{z as T}from"./vendor-zod-D1-NLVm9.js";import{bj as B}from"./ca9c256b9-B7ADeATc.js";import{C as U}from"./c12f02e29-BpK360cp.js";import{W as V}from"./vendor-icons-CjJMeNuY.js";import{c as W,n as Z,o as Q,p as K,q as X,r as J,a as Y,b as ee,d as se,s as te,t as ne,v as oe}from"./cbf215181-BtpZx0Q9.js";import{j as ae,k as ie,l as re}from"./c0632795f-CeVeaenZ.js";const le=s=>P.jsx(e,{...s,children:P.jsx("path",{d:"M14.5 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0V6.707l-8.147 8.147a.5.5 0 0 1-.707-.707L13.293 6H7.5a.5.5 0 0 1 0-1z"})});function de(e){return T.union([T.object({value:e,source:T.string().optional(),path:T.string().optional()}),e.transform(e=>({value:e}))])}function ce(e,s){return s.optional().catch(s=>{r.warn(l.LOCAL_SESSION,`resolveLocalSettings field '${e}' failed schema validation`,{issues:s.error.issues})})}const ue=T.object({model:ce("model",de(T.string())),availableModels:ce("availableModels",de(T.array(T.string()))),fastMode:ce("fastMode",de(T.boolean())),fastModePerSessionOptIn:ce("fastModePerSessionOptIn",de(T.boolean())),defaultPermissionMode:ce("defaultPermissionMode",de(T.string())),sshHostAllowlist:ce("sshHostAllowlist",de(T.array(T.string()))),disableBypassPermissionsMode:ce("disableBypassPermissionsMode",de(T.string())),disableAutoMode:ce("disableAutoMode",de(T.string())),enableWorkflows:ce("enableWorkflows",de(T.boolean())),disableWorkflows:ce("disableWorkflows",de(T.boolean())),switchModelsOnFlag:ce("switchModelsOnFlag",de(T.boolean()))}),ge="ccd-resolved-settings",pe={};function me(e){if(null==e)return pe;const s=ue.safeParse(e);return s.success?s.data:(r.warn(l.LOCAL_SESSION,"resolveLocalSettings IPC payload is not an object",{issues:s.error.issues}),pe)}function he(e){return null!=e&&"object"==typeof e&&("disableBypassPermissionsMode"in e&&"disableAutoMode"in e)}function fe(e,r){const l=s(),d=t(),c=n(),u=r?.sshHost,g=r?.sshPort,p=r?.sshIdentityFile,m=o?.resolveLocalSettings,h=a?.resolveSSHSettings,f=u?!!h:!!m,{data:x=null}=H({queryKey:[ge,e,u,g,p],queryFn:async()=>{const s=u&&h?h({sshHost:u,sshPort:g,sshIdentityFile:p},e):m?.(e)??null,t=await Promise.resolve(s);return{config:me(t),desktopResolvesDisableModes:he(t)}},enabled:f,staleTime:6e5}),b=i("claudeai_permission_modes_managed_settings"),w=x?.config??null,k=!(!b||!f)&&(x?.desktopResolvesDisableModes??!0);return z.useMemo(()=>({capabilities:{fastMode:l,bypassPermissions:d,autoPermissions:c},config:w,desktopResolvesDisableModes:k}),[l,d,c,w,k])}const xe={model:F({defaultMessage:"Not available for the selected model",id:"02PRGQeXvq"})};function be(e){if(!e)return!0;const s=e.toLowerCase();return!s.includes("claude-3-")&&!/claude-[a-z]+-4(?:$|-(?:[0-5](?!\d)|\d{8}))/.test(s)}function we(e){return{kind:"disabled",reason:e,tooltip:xe[e]}}function ke(e){const{isAnt:s,rolloutDisabled:t,model:n,gating:o}=e,a="custom-3p"===o.source?function(e){if(!be(e))return!1;if(!e)return!0;const s=e.toLowerCase();return!(/opus-4-6(?!\d)/.test(s)||/(?:sonnet|haiku)(?=-\d|$)/.test(s))}(n):be(n);if(t)return{kind:"hidden"};if(s&&"custom-3p"!==o.source)return a?{kind:"available"}:we("model");switch(o.source){case"desktop-sdk":case"custom-3p":return o.configLoading?{kind:"loading"}:o.deviceManagedDisablesAuto||"desktop-sdk"===o.source&&void 0!==o.accessStatus&&"available"!==o.accessStatus&&"blocked_by_org_admin"!==o.accessStatus?{kind:"hidden"}:a?{kind:"available"}:we("model");case"remote-policy":return void 0===o.policyAllowed?{kind:"loading"}:!1===o.policyAllowed?{kind:"hidden"}:a?{kind:"available"}:we("model");case"legacy-desktop":return!1===o.legacyOrgEnabled?{kind:"hidden"}:void 0===o.legacyOrgEnabled?{kind:"loading"}:a?{kind:"available"}:we("model")}}function ve(e){const{account:s}=d(),t=c("claude_code_desktop_auto_permissions"),n=u(),o=g(s),{config:a,desktopResolvesDisableModes:i}=fe(),r="disable"===a?.disableAutoMode?.value,l=null===a;return z.useMemo(()=>ke({isAnt:o,rolloutDisabled:"disabled"===n,model:e,gating:i?{source:"desktop-sdk",configLoading:l,deviceManagedDisablesAuto:r,accessStatus:t.status}:{source:"legacy-desktop",legacyOrgEnabled:t.isAvailable}}),[o,n,t.status,t.isAvailable,i,r,l,e])}function je(e,s){const t=ve(e),n=function(e){const s=i("ccr_auto_permission_mode"),{account:t}=d(),{auto:n,isLoading:o,isError:a}=p(),r=u(),l=g(t);return z.useMemo(()=>s?ke({isAnt:l,rolloutDisabled:"disabled"===r,model:e,gating:{source:"remote-policy",policyAllowed:!a&&(o?void 0:n?.allowed)}}):{kind:"hidden"},[s,l,r,n?.allowed,o,a,e])}(e);return s?t:n}function ye(){return new BroadcastChannel("github-app-install")}function Me(e,s){const t={type:"GITHUB_INSTALL_COMPLETE",installationId:s,timestamp:Date.now()};e.postMessage(t)}function Ce(e){const s={type:"GITHUB_INSTALL_MODAL_CLOSED",timestamp:Date.now()};e.postMessage(s)}function _e(e,s=1e3){return new Promise(t=>{const n=setTimeout(()=>{e.removeEventListener("message",o),t(!1)},s),o=s=>{"GITHUB_INSTALL_MODAL_CLOSED"===s.data.type&&(clearTimeout(n),e.removeEventListener("message",o),t(!0))};e.addEventListener("message",o)})}function Ie(e){const s=`${e.owner.login}/${e.name}`;if(!e.ghe)return s;return`https://${e.ghe.host.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/+$/,"")}/${s}`}function Ne(e,s){const t=e.match(/^(?<host>[a-z0-9][a-z0-9.-]*(?::\d+)?)\/[^/\s:@]+\/[^/\s:@]+?(?:\.git)?\/?$/i),n=t?.groups?.host;if(!n||!s)return e;const o=n.replace(/:\d+$/,"").toLowerCase();return o.includes(".")&&s.has(o)?`https://${e.replace(/\/+$/,"")}`:e}function $e({enabled:e=!0,skipStatus:s,skipGhe:t=!1,skipGheFullList:n=!1,skipGheDedup:o=!1,skipMountRefetch:a=!1}={}){const{activeOrganization:i}=d(),r=i?.uuid,[l,c]=z.useState(!1),u=r?`code-github-repos-${r}-no-status`:"code-github-repos-no-status",[g,p]=m({key:u,defaultValue:null,getInitialValueInEffect:!0}),b=o?"-nodedup":"",w=r?`code-ghe-repos-${r}${b}`:`code-ghe-repos${b}`,[k,v]=m({key:w,defaultValue:null,getInitialValueInEffect:!0}),j=W({enabled:e,skipStatus:s,refetchOnWindowFocus:"always",timeoutMs:3e4}),{data:y}=H({queryKey:[x,{orgUuid:r}],enabled:!1}),M=z.useMemo(()=>t?[]:y?.ghe_connections??[],[t,y?.ghe_connections]),C=z.useMemo(()=>M.map(e=>({configId:e.ghe_config_id,hostname:e.hostname,port:e.port})),[M]),_=z.useMemo(()=>M.filter(e=>e.is_connected).toSorted((e,s)=>e.ghe_config_id-s.ghe_config_id),[M]),I=z.useMemo(()=>new Set(_.map(e=>e.ghe_config_id)),[_]),N=z.useMemo(()=>M.filter(e=>!e.is_connected).map(e=>({configId:e.ghe_config_id,hostname:e.hostname})),[M]),$=h(),L=D(),S=q({queries:_.map(e=>({queryKey:[f,{orgUuid:r,skipStatus:!0,gheConfigurationId:e.ghe_config_id}],queryFn:async()=>{const s=`/api/organizations/${r}/code/repos?skip_status=true&ghe_configuration_id=${e.ghe_config_id}`,t=await $(s,{signal:AbortSignal.timeout(3e4)});if(Z(t,L,r),!t.ok)throw new Error(`Failed to fetch repos from ${e.hostname}: ${t.status}`);const n=await t.json(),o=Q(e.hostname,e.port);return n.repos.map(s=>({...s.repo,ghe:{host:o,configuration_id:e.ghe_config_id}}))},enabled:Boolean(r)&&!n,staleTime:3e5,retry:!1,meta:{noToast:!0}})),combine:e=>({repos:K(e.map(e=>e.data),o),isPending:e.some(e=>e.isPending),hasError:e.some(e=>e.isError)})}),A=!n&&S.isPending,{refetch:E,data:R,isLoading:P,error:F}=j;z.useEffect(()=>{if(R?.repos){const e=R.repos.map(e=>e.repo);p(e)}},[R?.repos,p]),z.useEffect(()=>{!S.isPending&&!S.hasError&&_.length>0?v(S.repos):t||void 0===y||0!==_.length||v(null)},[S.isPending,S.hasError,S.repos,v,t,y,_.length]),z.useEffect(()=>{a||r&&(c(!0),E().finally(()=>{c(!1)}))},[r,E,a]);const O=z.useCallback(async()=>{c(!0);try{await E()}finally{c(!1)}},[E]);z.useEffect(()=>{if(!e)return;if("undefined"==typeof window)return;if("undefined"==typeof BroadcastChannel)return;const s=ye();let t;const n=e=>{"GITHUB_INSTALL_COMPLETE"===e.data.type&&(L.invalidateQueries({queryKey:[x,{orgUuid:r}]}),O(),t&&clearTimeout(t),t=setTimeout(()=>{O()},2e3))};return s.addEventListener("message",n),()=>{t&&clearTimeout(t),s.removeEventListener("message",n),s.close()}},[e,r,L,O]);const G=z.useMemo(()=>{const e=R?.repos?R.repos.map(e=>e.repo):g??null,s=t?[]:!S.isPending&&!S.hasError&&_.length>0?S.repos:k??S.repos;return null===e?s.length>0?s:null:0===s.length?e:[...e,...s]},[R?.repos,g,S.repos,S.isPending,S.hasError,k,t,_.length]);return{repos:G,statusMap:z.useMemo(()=>{const e=new Map;if(R?.repos)for(const{repo:s,status:t}of R.repos){const n=`${s.owner.login}/${s.name}`;e.set(n,t)}return e},[R?.repos]),gheSources:C,gheSourcesNeedingAuth:N,gheConnectedConfigIds:I,gheIsPending:A,isLoading:null===G&&(P||l||A),error:F,refetchRepos:O,ssoRequiredOrgIds:R?.sso_required_org_ids??null,ssoRequiredOrgs:R?.sso_required_orgs??null,ssoAuthorizeUrl:R?.sso_authorize_url??null}}const Le="code-recently-used-repos";function Se(e,s,t){return`${t?.host?.replace(/:443$/,"")??"github.com"}|${e}/${s}`}function Ae(){const{activeOrganization:e}=d(),s=e?.uuid,t=s?`${Le}-${s}`:Le,[n,o]=m({key:t,defaultValue:[],getInitialValueInEffect:!1,deserialize:e=>{try{const s=JSON.parse(e);if(function(e){return!!Array.isArray(e)&&e.every(e=>"object"==typeof e&&null!==e&&"string"==typeof e.owner&&"string"==typeof e.name&&"number"==typeof e.usedAt)}(s))return s}catch{}return[]}}),a=z.useCallback(e=>{const s=Se(e.owner.login,e.name,e.ghe);o(t=>{const n=t.filter(e=>Se(e.owner,e.name,e.ghe)!==s);return[{owner:e.owner.login,name:e.name,usedAt:Date.now(),...e.ghe?{ghe:e.ghe}:{}},...n].slice(0,3)})},[o]),i=z.useCallback(e=>{if(!e||0===e.length)return[];const s=new Map;for(const n of e)s.set(Se(n.owner.login,n.name,n.ghe),n);const t=[];for(const o of n){const e=s.get(Se(o.owner,o.name,o.ghe));e&&t.push(e)}return t},[n]);return z.useMemo(()=>({recentlyUsed:n,addRecentlyUsed:a,getRecentlyUsedFromAvailable:i}),[n,a,i])}function Ee({onLoad:e,isLoading:s=!1,label:t}){const{ref:n,entry:o}=b({threshold:.1});return z.useEffect(()=>{o?.isIntersecting&&!s&&e()},[o?.isIntersecting,s,e]),P.jsx("div",{ref:n,className:"px-4 py-3 text-center",children:P.jsx(w,{variant:"secondary",size:"sm",onClick:e,disabled:s,className:"text-xs",children:t})})}function Re(e){return Se(e.owner.login,e.name,e.ghe)}const Pe=z.memo(({repo:e,isSelected:s,isHighlighted:t,isExcluded:n,onSelect:o,appInstalled:a})=>{const i=O();return P.jsxs(re,{onClick:n?void 0:()=>o(e),disabled:n,className:M("flex items-center justify-between gap-2",t&&!n&&"bg-bg-300",n&&"opacity-60 cursor-default"),children:[P.jsxs("div",{className:"flex flex-col min-w-0",children:[P.jsxs("div",{className:"flex items-center gap-1.5",children:[P.jsx("span",{className:"text-sm",children:e.name}),te(e)&&P.jsx("span",{className:"text-[10px] text-text-500 bg-bg-200 rounded px-1 py-0.5 shrink-0",title:e.ghe?.host,children:P.jsx(G,{defaultMessage:"GHE",id:"4b42RZpF6C"})}),!1===a&&P.jsx("span",{className:"text-[10px] text-warning-000 bg-warning-900 rounded px-1 py-0.5 shrink-0",title:i.formatMessage({defaultMessage:"Claude GitHub app not installed. Install the app to scan this repository.",id:"0VQErO+c/3"}),children:P.jsx(G,{defaultMessage:"App not installed",id:"8aW1mhjPCF"})})]}),P.jsx("span",{className:"text-xs text-text-500",children:e.owner.login})]}),(s||n)&&P.jsx(L,{size:12,className:"text-accent-brand shrink-0"})]})});function ze({onClick:e,children:s}){return P.jsxs(S,{onClick:e,className:"!inline-flex items-center gap-1 align-bottom",children:[P.jsx("span",{className:"underline underline-offset-[3px]",children:s}),P.jsx(le,{size:12,className:"shrink-0"})]})}function Fe({onInstallClick:e,hasRepos:s}){const{track:t}=k(),n=z.useCallback(()=>{t({event_key:"claudeai.code.github_app.install_button.clicked",source:"repo_dropdown"}),e()},[t,e]);return s?P.jsx("div",{className:"font-small text-text-500 mx-2 my-1",children:P.jsx(G,{defaultMessage:"Repo missing? <link>Install the Claude GitHub app</link> in a private repository to access it here.",id:"HuSmwBEcR7",values:{link:e=>P.jsxs(S,{onClick:n,className:"!inline-flex items-center gap-1 align-bottom",children:[P.jsx("span",{className:"underline underline-offset-[3px]",children:e}),P.jsx(le,{size:12,className:"shrink-0"})]})}})}):P.jsxs("div",{className:"flex flex-col gap-1",children:[P.jsx("div",{className:"font-small text-text-500 mx-2 mt-1",children:P.jsx(G,{defaultMessage:"Repo missing? Install the Claude GitHub app in a private repository to access it here.",id:"3vzqq2gVEq"})}),P.jsx(re,{onClick:n,children:P.jsxs("div",{className:"flex flex-row align-justify items-center gap-2",children:[P.jsx(A,{size:22}),P.jsx("div",{children:P.jsx("div",{className:"font-base",children:P.jsx(G,{defaultMessage:"Install GitHub App",id:"J/um7ldhI0"})})})]})})]})}function Oe({error:e}){const s=e instanceof E?e.errorCode:null;return"github_ip_allowlist"===s?P.jsx(G,{defaultMessage:"Your GitHub organization has an IP allowlist that is blocking Claude's servers. Add <link>Claude's IP ranges</link> to your GitHub allowlist, then try again.",id:"7knnVyGATZ",values:{link:e=>P.jsx(R,{href:"https://platform.claude.com/docs/en/api/ip-addresses",external:!0,children:e})}}):"github_rate_limited"===s?P.jsx(G,{defaultMessage:"GitHub rate limit exceeded. Wait a few minutes and try again.",id:"zLLXnHcurs"}):"github_oauth_app_required"===s?P.jsx(G,{defaultMessage:"This GitHub Enterprise connection is set up with OAuth App credentials. Ask an org admin to reconfigure it with GitHub App credentials in the Claude Code settings.",id:"PF/zgwFq3h"}):P.jsx(G,{defaultMessage:"Couldn't search repositories. Try again in a moment.",id:"xg6ybsQQF2"})}Pe.displayName="RepositorySelectItem";const Ge=z.forwardRef(({value:e,onChange:s,values:t,onValuesChange:n,multiSelect:o=!1,onCloseAutoFocus:a,disabled:i,isGithubAuthenticated:r,showIcon:l=!0,showChevron:d=!0,iconOnly:c=!1,className:u,size:g="sm",variant:p="default",containerRef:m,dropdownWidth:h,dropdownSide:f,excludeRepoKeys:x,repoFilter:b,extraRepos:L,lockedHint:S,showAppInstallStatus:A,hideInstallAppFooter:E=!1,hideGheConnectItems:R=!1,allowFreeInput:F=!1,onCustomValue:H,customValue:D,skipStatus:q,skipGhe:T=!1,skipGheDedup:W=!1,searchPlaceholder:Z,autoFocus:Q,triggerId:K,triggerLabelledBy:te,triggerDescribedBy:oe},le)=>{const de=z.useId(),ce=K??de,ue=te?`${te} ${ce}`:void 0,[ge,pe]=z.useState(!1),[me,he]=z.useState(3),[fe,xe]=z.useState(!1),[be,we]=z.useState(""),[ke,ve]=z.useState(null),[je,Me]=z.useState(null),[_e,Ne]=z.useState(10),[Le,Ge]=z.useState(-4),He=z.useRef(null),De=z.useRef(null),qe=z.useRef(new Map),Te=O(),{track:Be}=k();z.useLayoutEffect(()=>{if(!m?.current||!He.current)return;const e=m.current.getBoundingClientRect(),s=He.current.getBoundingClientRect();Ne(Math.round(e.bottom-s.bottom)+8),Ge(Math.round(e.left-s.left))},[m]);const Ue=v(),{repos:Ve,statusMap:We,gheSources:Ze,gheSourcesNeedingAuth:Qe,gheConnectedConfigIds:Ke,gheIsPending:Xe,isLoading:Je,error:Ye,refetchRepos:es,ssoRequiredOrgIds:ss,ssoRequiredOrgs:ts,ssoAuthorizeUrl:ns}=$e({enabled:!0===r,skipStatus:q,skipGhe:T,skipGheDedup:W}),[os]=j(be,300),as=os.trim(),is=be.trim(),rs=ge&&is.length>=2&&is===as,ls=!0===r&&rs,{data:ds,isFetching:cs,isError:us,error:gs}=X({q:as,enabled:ls}),ps=z.useMemo(()=>T?[]:Ze.filter(e=>Ke.has(e.configId)),[T,Ze,Ke]),ms=J({q:as,connectedGheSources:ps,enabled:rs}),hs=!0===r||ps.length>0,fs=hs&&is.length>=2&&(cs||ms.isFetching||is!==as),xs=z.useMemo(()=>[...ds?.map(e=>e.repo)??[],...ms.data.map(e=>e.repo)],[ds,ms.data]),bs=z.useMemo(()=>{const e=new Map;for(const s of ds??[])e.set(Se(s.repo.owner.login,s.repo.name,void 0),s.status);for(const s of ms.data)e.set(Se(s.repo.owner.login,s.repo.name,s.repo.ghe),s.status);return e},[ds,ms.data]),{recentlyUsed:ws,addRecentlyUsed:ks}=Ae(),{checkIsGithubAuthenticated:vs,initGithubAuth:js}=Y({callerIdentifier:"code",fetchImmediately:!1}),ys=ee(),{eligibleRepos:Ms,sortedRepos:Cs,visibleRepos:_s,hasMoreRepos:Is,recentlyUsedRepos:Ns}=z.useMemo(()=>{const e=Ve||[],s=b?e.filter(b):e,t=L&&L.length>0?[...s,...L.filter(e=>!s.some(s=>s.owner.login===e.owner.login&&s.name===e.name))]:s;let n=t;const o=new Set;if(rs&&hs&&xs.length>0){const e=b?xs.filter(b):xs;for(const t of e)o.add(Se(t.owner.login,t.name,t.ghe));const s=new Set(t.map(e=>Se(e.owner.login,e.name,e.ghe))),a=e.filter(e=>!s.has(Se(e.owner.login,e.name,e.ghe)));a.length>0&&(n=[...t,...a])}if(!n.length)return{eligibleRepos:[],sortedRepos:[],visibleRepos:[],hasMoreRepos:!1,recentlyUsedRepos:[]};const a=new Map;for(const d of n)a.set(Se(d.owner.login,d.name,d.ghe),d);const i=[];for(const d of ws){const e=a.get(Se(d.owner,d.name,d.ghe));e&&i.push(e)}const r=(be.trim()?n.filter(e=>{if(o.has(Se(e.owner.login,e.name,e.ghe)))return!0;const s=be.toLowerCase().trim(),t=e.name.toLowerCase(),n=e.owner.login.toLowerCase(),a=`${n}/${t}`;return t.includes(s)||n.includes(s)||a.includes(s)}):n).slice().sort((e,s)=>{if(be.trim()){const t=be.toLowerCase().trim(),n=e.name.toLowerCase().includes(t),o=s.name.toLowerCase().includes(t);if(n&&!o)return-1;if(!n&&o)return 1}return`${e.owner.login}/${e.name}`.toLowerCase().localeCompare(`${s.owner.login}/${s.name}`.toLowerCase())}),l=r.slice(0,me);return{eligibleRepos:n,sortedRepos:r,visibleRepos:l,hasMoreRepos:l.length<r.length,recentlyUsedRepos:i}},[Ve,me,be,ws,b,L,xs,rs,hs]),$s=z.useCallback(e=>e>=0&&e<_s.length?Re(_s[e]):null,[_s]),Ls=z.useMemo(()=>ke?_s.findIndex(e=>Re(e)===ke):-1,[_s,ke]);z.useEffect(()=>{!F&&be&&null===ke&&Cs.length>0&&ve(Re(Cs[0]))},[F,be,ke,Cs]),z.useEffect(()=>{if(Ls>=0&&Ls<_s.length){const e=qe.current.get(Ls);e&&e.scrollIntoView({block:"nearest",behavior:"smooth"})}},[Ls,_s.length]),z.useEffect(()=>{},[ss,ts,ns,Ve?.length]);const Ss=z.useMemo(()=>ts&&ts.length>0?ts.map(e=>e.login).join(", "):ss&&ss.length>0?Te.formatMessage({defaultMessage:"{count, plural, one {# organization} other {# organizations}}",id:"2cYChMCf7w"},{count:ss.length}):null,[ts,ss,Te]);z.useEffect(()=>{const e=ye(),s=s=>{"GITHUB_INSTALL_COMPLETE"===s.data.type&&(es(),Ce(e))};return e.addEventListener("message",s),()=>{e.removeEventListener("message",s),e.close()}},[es]);const As=z.useCallback(()=>{he(3),ve(null),F||we("")},[F]),Es=z.useCallback(async()=>{if(!1!==r||F)As(),pe(!0);else{await vs()||js()}},[r,F,vs,js,As]);z.useImperativeHandle(le,()=>({open(){i||Es()}}),[i,Es]);const Rs=z.useCallback(()=>{!fe&&Is&&(xe(!0),setTimeout(()=>{he(e=>Math.min(e+20,Cs.length)),xe(!1)},100))},[fe,Is,Cs.length]),Ps=z.useCallback(e=>{if(ks(e),o){const s=t||[],o=Re(e),a=s.some(e=>Re(e)===o);n?.(a?s.filter(e=>Re(e)!==o):[...s,e])}else s?.(e),F&&we(""),pe(!1)},[ks,s,o,t,n,F]),zs=be.trim(),Fs=z.useMemo(()=>{if(!zs)return!1;const e=zs.toLowerCase();return Cs.some(s=>`${s.owner.login}/${s.name}`.toLowerCase()===e)},[zs,Cs]),Os=Boolean(F&&zs&&!Fs),Gs=z.useCallback(()=>{zs&&(H?.(zs),we(""),pe(!1))},[zs,H]),Hs=z.useCallback(()=>{if(!zs)return;const e=Cs.find(e=>`${e.owner.login}/${e.name}`.toLowerCase()===zs.toLowerCase());e?Ps(e):Gs()},[zs,Cs,Ps,Gs]),Ds=!F&&void 0===r,qs=o?t&&t.length>0:e?.owner?.login&&e?.name||Boolean(D),Ts=z.useCallback(s=>{const n=Re(s);return o?(t||[]).some(e=>Re(e)===n):!(!e||Re(e)!==n)||!!D&&function(e,s){const t=e.toLowerCase().replace(/\/$/,"").replace(/\.git$/,""),n=`${s.owner.login}/${s.name}`.toLowerCase();return t===n||(s.ghe?t===`${s.ghe.host}/${n}`.toLowerCase()||t===Ie(s).toLowerCase():t===`https://github.com/${n}`)}(D,s)},[o,t,e,D]),Bs=z.useCallback(e=>{if(!A)return;const s=(e.ghe?void 0:We.get(`${e.owner.login}/${e.name}`))??bs.get(Se(e.owner.login,e.name,e.ghe));return s?.app_installed},[A,We,bs]),Us=z.useMemo(()=>!o&&D?D:Ds?o&&t&&t.length>0?1===t.length?"minimal"===p?t[0].name:`${t[0].owner.login}/${t[0].name}`:`${t.length} repositories`:qs?"minimal"===p?e.name:`${e.owner.login}/${e.name}`:"Loading\u2026":!1!==r||F?o&&t&&t.length>0?1===t.length?"minimal"===p?t[0].name:`${t[0].owner.login}/${t[0].name}`:`${t.length} repositories`:e?.owner?.login&&e?.name&&!o?"minimal"===p?e.name:`${e.owner.login}/${e.name}`:o?Te.formatMessage({defaultMessage:"Select repositories",id:"SuTv3tbdBC"}):Te.formatMessage({defaultMessage:"Select a repository",id:"OM1Xt60kRs"}):"Connect to GitHub",[Te,Ds,qs,e,t,r,p,o,D,F]),Vs=Ds?qs?()=>pe(!0):void 0:Es,Ws=c?P.jsx("button",{ref:He,type:"button",onClick:Vs,disabled:i||Ds&&!qs,"aria-label":Te.formatMessage({defaultMessage:"Add repository",id:"FvUsYi2+QN"}),className:M("flex items-center justify-center w-5 h-5 rounded-[4px] text-text-400 hover:text-text-100 hover:bg-bg-200 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",u),children:P.jsx(y,{size:12})}):"input"===p?P.jsxs("button",{ref:He,type:"button",id:te||K?ce:void 0,"aria-labelledby":ue,"aria-describedby":oe,"aria-haspopup":"listbox","aria-expanded":ge,onClick:Vs,disabled:i||Ds&&!qs,autoFocus:Q,className:M(C(),"flex w-full items-center justify-between",u),children:[P.jsx("span",{className:M("truncate",qs?"text-text-100":"text-text-500"),children:Us}),P.jsx(U,{size:16,className:"shrink-0 text-text-300"})]}):"minimal"===p?P.jsxs("button",{ref:He,type:"button",onClick:Vs,disabled:i||Ds&&!qs,title:S,className:M("group flex items-center gap-1.5 px-2 py-1.5 rounded-md border-0.5 border-border-300 shadow-sm text-xs text-text-300 hover:text-text-100 hover:bg-bg-100 disabled:opacity-50 disabled:cursor-not-allowed transition-colors min-w-0",u),children:[l&&P.jsx(_,{type:I.GITHUB,size:16,className:"w-4 h-4 shrink-0 text-text-300 group-hover:text-text-100 transition-colors"}),P.jsx("span",{className:M("truncate",!qs&&"text-text-100"),children:Us}),qs&&!o&&e?.default_branch&&P.jsxs(P.Fragment,{children:[P.jsx(N,{size:14,className:"shrink-0 text-text-400"}),P.jsx("span",{className:"truncate max-w-[120px] text-text-400",children:e.default_branch})]}),S&&P.jsx(V,{size:12,className:"shrink-0 text-text-500"})]}):P.jsx(w,{ref:He,className:M("!text-left !justify-start active:!scale-100",u||"!flex-[2]"),variant:"secondary",size:g,type:"button",onClick:Vs,disabled:i||Ds&&!qs,title:S,prepend:l?P.jsx(_,{className:"mr-0.5",type:I.GITHUB,size:16}):void 0,append:S?P.jsx(V,{size:12,className:"text-text-500"}):d?P.jsx(U,{size:12,className:"text-text-400"}):void 0,children:P.jsx("span",{className:"truncate w-full",children:Us})});return!1!==r||ys||F?!1!==r||F?P.jsx(P.Fragment,{children:P.jsx(ae,{trigger:Ws,unstyledTrigger:!0,open:ge,onOpenChange:e=>{if(pe(e),e){if(As(),m?.current&&Me(m.current.offsetWidth),m?.current&&He.current){const e=m.current.getBoundingClientRect(),s=He.current.getBoundingClientRect();Ne(Math.round(e.bottom-s.bottom)+8),Ge(Math.round(e.left-s.left))}Be({event_key:"claudeai.code.github_app.repo_dropdown.opened",repos_count:Ms.length}),ss&&ss.length>0&&Be({event_key:"claudeai.code.github_sso_banner.shown",org_count:ss.length})}},onOpenAutoFocus:e=>{e.preventDefault(),De.current?.focus(),De.current?.select()},onInteractOutside:F&&(H||s)?Hs:void 0,onCloseAutoFocus:a,align:"start",side:f??("minimal"===p?"bottom":void 0),avoidCollisions:"minimal"!==p&&void 0,sideOffset:m?_e:"minimal"===p?4:void 0,alignOffset:m?Le:void 0,style:h?{width:h}:je?{width:je}:void 0,className:M(h||je?void 0:"minimal"===p?"w-[300px]":"w-[calc(var(--radix-dropdown-menu-trigger-width)+8px)]","min-w-[300px]"),children:P.jsxs("div",{className:"flex flex-col gap-2 w-full",children:[P.jsx("div",{role:"presentation",onClick:e=>e.stopPropagation(),children:P.jsx("input",{ref:De,type:"text",role:"combobox","aria-expanded":ge,"aria-controls":"repo-listbox","aria-activedescendant":Ls>=0?`repo-item-${Ls}`:void 0,"aria-autocomplete":"list",autoComplete:"off",placeholder:Z??Te.formatMessage({defaultMessage:"Search repositories",id:"74ciYOB1D8"}),value:be,onChange:e=>{e.stopPropagation(),we(e.target.value),ve(null),he(3)},onKeyDown:e=>{if(e.stopPropagation(),"ArrowDown"===e.key){e.preventDefault();const s=Ls<0?0:(Ls+1)%_s.length;ve($s(s))}else if("ArrowUp"===e.key){e.preventDefault();const s=Ls<=0?_s.length-1:Ls-1;ve($s(s))}else if("Home"===e.key)e.preventDefault(),ve($s(0));else if("End"===e.key)e.preventDefault(),ve($s(_s.length-1));else if("Enter"===e.key)if(e.preventDefault(),Ls>=0&&Ls<_s.length)Ps(_s[Ls]);else if(ke){const e=Cs.find(e=>Re(e)===ke);e?Ps(e):F&&zs&&Hs()}else F&&zs&&Hs();else"Escape"===e.key&&(e.preventDefault(),F&&we(""),pe(!1))},onClick:e=>e.stopPropagation(),onFocus:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),className:"w-full px-2 py-1 text-sm bg-bg-200 rounded-md border-none focus:outline-none focus:ring-0 focus:shadow-none",style:{outline:"none",boxShadow:"none"}})}),P.jsxs("div",{id:"repo-listbox",role:"listbox",className:M("overflow-y-auto [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-border-400 [scrollbar-width:thin] [scrollbar-color:hsl(var(--border-400))_transparent]","minimal"===p?"max-h-[min(320px,calc(100vh-16rem))]":"max-h-[min(360px,calc(100vh-16rem))]"),children:[0===Cs.length?(()=>{const e=fs?P.jsx(G,{defaultMessage:"Searching\u2026",id:"/MzoqvXdpg"}):us&&is?P.jsx(Oe,{error:gs}):Je?P.jsx(G,{defaultMessage:"Loading repositories\u2026",id:"p6WaetusEa"}):Xe||F?null:P.jsx(G,{defaultMessage:"No repositories found",id:"eugOeGuaQ2"});return e?P.jsx("div",{className:"px-4 py-4 text-sm text-center text-text-500",children:e}):null})():P.jsxs(P.Fragment,{children:[!be&&Ns.length>0&&P.jsxs(P.Fragment,{children:[P.jsx("div",{className:"px-2 pt-1 pb-0.5",children:P.jsx("span",{className:"text-xs font-medium text-text-500",children:P.jsx(G,{defaultMessage:"Recently Used",id:"ciiINmAmPC"})})}),Ns.map(e=>{const s=Ts(e),t=Re(e),n=x?.includes(t)||!e.ghe&&x?.includes(`${e.owner.login}/${e.name}`);return P.jsx("div",{role:"option","aria-selected":s,children:P.jsx(Pe,{repo:e,isSelected:s,isHighlighted:!1,isExcluded:n,onSelect:Ps,appInstalled:Bs(e)})},`recent-${t}`)}),P.jsx(ie,{}),P.jsx("div",{className:"px-2 pt-1 pb-0.5",children:P.jsx("span",{className:"text-xs font-medium text-text-500",children:P.jsx(G,{defaultMessage:"All Repositories",id:"RVWo/bXfJX"})})})]}),_s.map((e,s)=>{const t=Ts(e),n=s===Ls,o=Re(e),a=x?.includes(o)||!e.ghe&&x?.includes(`${e.owner.login}/${e.name}`);return P.jsx("div",{id:`repo-item-${s}`,role:"option","aria-selected":t,ref:e=>{e?qe.current.set(s,e):qe.current.delete(s)},children:P.jsx(Pe,{repo:e,isSelected:t,isHighlighted:n,isExcluded:a,onSelect:Ps,appInstalled:Bs(e)})},o)}),Is&&P.jsx(Ee,{onLoad:Rs,isLoading:fe,label:fe?"Loading more\u2026":"Load more"})]}),F&&Boolean(Ye)&&0===Ms.length&&!Je&&!fs&&!Xe&&P.jsx("div",{className:"px-4 py-3 text-sm text-center text-text-500",children:P.jsx(G,{defaultMessage:"Couldn't load the repository list. Type owner/repo below to continue.",id:"dz33KviCE3"})}),Xe&&!Je&&!T&&P.jsx("div",{className:"px-4 py-3 text-sm text-center text-text-500",children:P.jsx(G,{defaultMessage:"Loading enterprise repositories\u2026",id:"57CBM/xcqu"})})]}),Os&&P.jsxs(P.Fragment,{children:[(Ms.length>0||Je)&&P.jsx(ie,{}),P.jsx(re,{onClick:Gs,children:P.jsxs("span",{className:"flex items-center gap-2 min-w-0 text-sm",children:[P.jsx(B,{size:12,className:"shrink-0 text-text-400","aria-hidden":!0}),P.jsx("span",{className:"truncate",children:P.jsx(G,{defaultMessage:'Use "{query}"',id:"mxy1AjprZX",values:{query:zs}})})]})})]}),(()=>{const e=!E,s=e&&!R?Ze:[],t=Boolean(ss&&ss.length>0),n=R?0:Qe.length,o=(e?1:0)+s.length+(t?1:0)+n,a=()=>{Be({event_key:"claudeai.code.github_app.install_button.clicked",source:"repo_dropdown"}),pe(!1),window.open(se(window.location.pathname),"_blank","noopener,noreferrer")},i=e=>{if(!/^[A-Za-z0-9.-]+$/.test(e.hostname))return;Be({event_key:"claudeai.code.github_app.install_button.clicked",source:"repo_dropdown",ghe_config_id:e.configId}),pe(!1);const s=e.port?`${e.hostname}:${e.port}`:e.hostname;window.open(`https://${s}/settings/installations`,"_blank","noopener,noreferrer")},r=()=>{Be({event_key:"claudeai.code.github_sso_banner.clicked",org_count:ss?.length??0}),ns&&ne(ns,["github.com"])&&window.open(ns,"_blank","noopener,noreferrer")};return Ms.length>0&&o>=2?P.jsxs(P.Fragment,{children:[P.jsx(ie,{}),P.jsxs("div",{className:"font-small text-text-500 mx-2 my-1",children:[P.jsx("div",{className:"mb-1",children:P.jsx(G,{defaultMessage:"Repo missing?",id:"c4z/8TuJuI"})}),P.jsxs("ul",{className:"list-disc pl-4 space-y-1",children:[e&&P.jsx("li",{children:P.jsx(G,{defaultMessage:"<link>Install the Claude GitHub app</link> to access private repositories",id:"kwcDEQ7Cum",values:{link:e=>P.jsx(ze,{onClick:a,children:e})}})}),s.map(e=>P.jsx("li",{children:P.jsx(G,{defaultMessage:"<link>Install the GitHub App on {hostname}</link> to access its private repositories",id:"dOyg7JNugw",values:{hostname:e.hostname,link:s=>P.jsx(ze,{onClick:()=>i(e),children:s})}})},`ghe-install-${e.configId}`)),t&&P.jsx("li",{children:P.jsx(G,{defaultMessage:"<link>Authorize SSO on GitHub</link> to use repos from {orgs}",id:"k/PZum/1ij",values:{orgs:Ss,link:e=>ns?P.jsx(ze,{onClick:r,children:e}):P.jsx(P.Fragment,{children:e})}})}),n>0&&Qe.map(e=>P.jsx("li",{children:P.jsx(G,{defaultMessage:"<link>Connect to {hostname}</link> to access its repositories",id:"NdZ0pwqIte",values:{hostname:e.hostname,link:s=>P.jsx(ze,{onClick:()=>{pe(!1),js({gheConfigId:e.configId})},children:s})}})},e.configId))]})]})]}):P.jsxs(P.Fragment,{children:[e&&P.jsxs(P.Fragment,{children:[Ms.length>0&&P.jsx(ie,{}),P.jsx(Fe,{hasRepos:Ms.length>0,onInstallClick:()=>{pe(!1),window.open(se(window.location.pathname),"_blank","noopener,noreferrer")}})]}),s.map(e=>P.jsx("div",{className:"font-small text-text-500 mx-2 my-1",children:P.jsx(G,{defaultMessage:"<link>Install the GitHub App on {hostname}</link> to access its private repositories",id:"dOyg7JNugw",values:{hostname:e.hostname,link:s=>P.jsx(ze,{onClick:()=>i(e),children:s})}})},`ghe-install-${e.configId}`)),t&&P.jsxs(P.Fragment,{children:[!e&&Ms.length>0&&P.jsx(ie,{}),P.jsx("div",{className:"font-small text-text-500 mx-2 my-1",children:P.jsx(G,{defaultMessage:"<link>Authorize SSO on GitHub</link> to use repos from {orgs}",id:"k/PZum/1ij",values:{orgs:Ss,link:e=>ns?P.jsx(ze,{onClick:r,children:e}):P.jsx(P.Fragment,{children:e})}})})]}),n>0&&P.jsxs(P.Fragment,{children:[!e&&!t&&Ms.length>0&&P.jsx(ie,{}),Qe.map(e=>P.jsx("div",{className:"font-small text-text-500 mx-2 my-1",children:P.jsx(G,{defaultMessage:"<link>Connect to {hostname}</link> to access its repositories",id:"NdZ0pwqIte",values:{hostname:e.hostname,link:s=>P.jsx(ze,{onClick:()=>{pe(!1),js({gheConfigId:e.configId})},children:s})}})},e.configId))]})]})})()]})})}):Ws:P.jsx($,{className:u||"!flex-[2]",children:Ue?P.jsx(G,{defaultMessage:"GitHub access is required. Enable it in <link>connector settings</link>.",id:"k50hRmpM4R",values:{link:e=>P.jsx("a",{href:"/admin-settings/connectors",className:"underline hover:text-text-000",children:e})}}):P.jsx(G,{defaultMessage:"GitHub access is required. Contact an organization owner.",id:"fV1VFEZD+P"})})});function He(e){return`https://${oe(e)??"github.com"}/${e.owner.login}/${e.name}`}function De(e){const s=oe(e);return void 0===s?`${e.owner.login}/${e.name}`:`${s}/${e.owner.login}/${e.name}`}Ge.displayName="RepositorySelect";export{le as A,ge as C,Ee as I,Ge as R,ve as a,Ce as b,ye as c,$e as d,fe as e,Ae as f,Ie as g,Me as h,De as i,Ne as p,He as r,je as u,_e as w};
