1import{ag as ie,d as ce,b as de,r as a,z as l,j as e,a4 as ue,J as he,B as u,I as y,ak as me,X as xe}from"./index-BIdkve2-.js";import{i as c}from"./integrations-Ce3RP6k9.js";import{B as ye}from"./bar-chart-3-BiuTGg39.js";import{L as p}from"./loader-circle-E1TIqegY.js";/** 2 * @license lucide-react v0.400.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ge=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]),pe=[{id:"semrush",icon:ue,title:"SEMrush",desc:"Keyword research, domain overview; stores insights for your workspace.",action:"Configure",available:!0},{id:"google-analytics",icon:ye,title:"Google Analytics",desc:"GA4 traffic metrics for analytics dashboard (OAuth + property ID).",action:"Connect",available:!0},{id:"open-api",icon:ge,title:"Open API",desc:"API documentation and SDK for custom integrations.",action:"Coming Soon",available:!1}];function N(d){if(!(d!=null&&d.length))return"No rows returned.";const f=Object.keys(d[0]);return d.slice(0,8).map(o=>f.map(m=>`${m}: ${o[m]??""}`).join(" · ")).join(` 7`)}function je(){const{user:d,isReadOnlyTenant:f}=ce(),o=!!(d!=null&&d.is_admin),[m,A]=de(),[r,g]=a.useState(null),[_,C]=a.useState(!1),[b,I]=a.useState(""),[P,v]=a.useState(""),[w,O]=a.useState(!1),[G,j]=a.useState(""),[E,L]=a.useState(""),[D,K]=a.useState(""),[Z,ee]=a.useState(!1),[R,se]=a.useState(""),[z,te]=a.useState(""),[$,B]=a.useState(!1),[T,H]=a.useState(null),[V,F]=a.useState(!1),[M,U]=a.useState(!1),[q,J]=a.useState(null),[X,Y]=a.useState(!1),[Q,W]=a.useState(null),k=a.useCallback(()=>{c.getSemrush().then(({data:s})=>{v(s.domain||""),O(s.has_api_key);const t=s.sync_keywords;j(Array.isArray(t)&&t.length?t.join(", "):"")}).catch(()=>{})},[]),h=a.useCallback(()=>{c.getStatus().then(({data:s})=>{const t=[];s.semrush.connected&&t.push(`SEMrush: ${s.semrush.keyword_insight_count} stored keywords`+(s.semrush.last_sync_at?` · last sync ${s.semrush.last_sync_at}`:"")),(s.google_analytics.connected||s.google_analytics.has_property)&&t.push(`GA4: ${s.google_analytics.connected?"connected":"property set"}`+(s.google_analytics.oauth_email?` (${s.google_analytics.oauth_email})`:"")+(s.google_analytics.last_sync_at?` · last sync ${s.google_analytics.last_sync_at}`:"")),W(t.length?t.join(" · "):null)}).catch(()=>W(null))},[]);a.useEffect(()=>{k(),h()},[k,h]),a.useEffect(()=>{const s=m.get("ga");s==="connected"&&l.success("Google Analytics connected."),s==="error"&&l.error("Google Analytics connection failed or was cancelled."),s&&(A({},{replace:!0}),h())},[m,A,h]),a.useEffect(()=>{(r==null?void 0:r.id)==="semrush"?c.getSemrush().then(({data:s})=>{v(s.domain||""),O(s.has_api_key),I("");const t=s.sync_keywords;j(Array.isArray(t)&&t.length?t.join(", "):"")}).catch(()=>{}):(r==null?void 0:r.id)==="google-analytics"&&c.getGoogleAnalytics().then(({data:s})=>{const t=s;L(t.property_id||""),K(""),ee(!!t.has_oauth_tokens),se(t.oauth_email||"")}).catch(()=>{})},[r]);const ae=async()=>{if(!o){l.error("Only tenant admins can save integration credentials.");return}C(!0);try{if((r==null?void 0:r.id)==="semrush"){const s=G.split(",").map(n=>n.trim()).filter(Boolean),t={domain:P.trim(),sync_keywords:s};b.trim()&&(t.api_key=b.trim()),await c.updateSemrush(t),l.success("SEMrush configuration saved!"),k()}else(r==null?void 0:r.id)==="google-analytics"&&(await c.updateGoogleAnalytics({property_id:E,access_token:D||void 0}),l.success("Google Analytics configuration saved!"),h());g(null)}catch{l.error("Failed to save configuration")}finally{C(!1)}},ne=async()=>{if(!o){l.error("Only tenant admins can connect Google Analytics.");return}Y(!0);try{const{data:s}=await c.getGoogleAnalyticsOAuthUrl();window.location.href=s.authorization_url}catch{l.error("Could not start Google sign-in. Check server OAuth settings.")}finally{Y(!1)}},re=async()=>{var s,t;if(!o){l.error("Only tenant admins can verify the API key.");return}F(!0);try{const{data:n}=await c.verifySemrush();n!=null&&n.valid?l.success(n.detail||"SEMrush API key works."):l.error((n==null?void 0:n.detail)||"Verification failed.")}catch(n){const i=n;l.error(((t=(s=i.response)==null?void 0:s.data)==null?void 0:t.detail)||"Verification failed.")}finally{F(!1)}},le=async()=>{var t,n;const s=z.trim();if(!s)return l.error("Enter a keyword.");B(!0),H(null);try{const{data:i}=await c.researchKeyword(s),x=["Overview (first rows):",N(i.overview||[]),"","Suggestions (first rows):",N(i.suggestions||[])];H(x.join(` 8`)),l.success("Keyword data loaded; insights saved for your tenant."),h()}catch(i){const x=i;l.error(((n=(t=x.response)==null?void 0:t.data)==null?void 0:n.detail)||"Research failed.")}finally{B(!1)}},oe=async()=>{var s,t;U(!0),J(null);try{const{data:n}=await c.getDomainOverview();J(N(n.overview||[])),l.success("Domain overview loaded.")}catch(n){const i=n;l.error(((t=(s=i.response)==null?void 0:s.data)==null?void 0:t.detail)||"Domain overview failed.")}finally{U(!1)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-semibold text-claude-text tracking-tight",children:"Integrations"}),e.jsx("p",{className:"text-sm text-claude-text-tertiary mt-1",children:"Connect external tools. SEMrush powers optional keyword insights (stored per workspace) â not required for content or publishing."}),Q&&e.jsx("p",{className:"text-xs text-claude-text-secondary mt-2 rounded-xl bg-claude-bg-alt px-3 py-2 border border-claude-border/60",children:Q})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:pe.map(({id:s,icon:t,title:n,desc:i,action:x,available:S})=>e.jsxs("div",{className:`bg-claude-surface rounded-2xl border border-claude-border shadow-soft p-6 ${S?"hover:shadow-card":"opacity-60"} transition-shadow`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-claude-bg-alt flex items-center justify-center",children:e.jsx(t,{className:"h-5 w-5 text-claude-text-secondary"})}),!S&&e.jsx(he,{className:"bg-claude-bg-alt text-claude-text-tertiary",children:"Soon"})]}),e.jsx("h3",{className:"font-semibold text-claude-text mb-1.5",children:n}),e.jsx("p",{className:"text-sm text-claude-text-tertiary mb-4",children:i}),!f&&e.jsx(u,{variant:"outline",size:"sm",disabled:!S,onClick:()=>
8g({id:s,title:n}),children:x})]},n))}),w&&e.jsxs("section",{className:"mt-10 rounded-2xl border border-claude-border bg-claude-surface p-6 shadow-soft",children:[e.jsx("h2",{className:"text-lg font-semibold text-claude-text mb-1",children:"SEMrush tools"}),e.jsx("p",{className:"text-sm text-claude-text-tertiary mb-4",children:"Uses your saved API key. Results preview below; keyword rows are also stored under your tenant for future features."}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[o&&e.jsxs(u,{type:"button",size:"sm",variant:"outline",disabled:V,onClick:re,children:[V?e.jsx(p,{className:"h-4 w-4 animate-spin"}):null,"Test API key"]}),e.jsxs(u,{type:"button",size:"sm",variant:"outline",disabled:M,onClick:oe,children:[M?e.jsx(p,{className:"h-4 w-4 animate-spin"}):null,"Domain overview"]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 mb-2",children:[e.jsx(y,{label:"Keyword research",value:z,onChange:s=>te(s.target.value),placeholder:"e.g. content marketing",className:"flex-1"}),e.jsx("div",{className:"sm:pt-6",children:e.jsxs(u,{type:"button",size:"sm",disabled:$,onClick:le,children:[$?e.jsx(p,{className:"h-4 w-4 animate-spin"}):null,"Research"]})})]}),q&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-xs font-semibold text-claude-text-secondary mb-1",children:"Domain overview"}),e.jsx("pre",{className:"text-xs bg-claude-bg-alt rounded-xl p-3 overflow-x-auto whitespace-pre-wrap max-h-40",children:q})]}),T&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-claude-text-secondary mb-1",children:"Last research"}),e.jsx("pre",{className:"text-xs bg-claude-bg-alt rounded-xl p-3 overflow-x-auto whitespace-pre-wrap max-h-56",children:T})]})]}),r&&me.createPortal(e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/40 px-4",children:e.jsxs("div",{className:"bg-white rounded-2xl border border-claude-border shadow-dropdown p-6 max-w-md w-full animate-in fade-in scale-in duration-150",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"font-semibold text-claude-text",children:[r.title," Configuration"]}),e.jsx("button",{type:"button",onClick:()=>g(null),className:"text-claude-text-tertiary hover:text-claude-text",children:e.jsx(xe,{className:"h-4 w-4"})})]}),!o&&e.jsx("p",{className:"text-xs text-claude-warning mb-3 rounded-lg bg-claude-warning-light px-2 py-1.5",children:"Only tenant admins can change credentials. You can still use research tools above if an API key is saved."}),e.jsxs("div",{className:"space-y-4",children:[r.id==="semrush"&&e.jsxs(e.Fragment,{children:[w&&e.jsx("p",{className:"text-xs text-claude-text-secondary",children:"API key is stored. Enter a new key only if you want to replace it."}),e.jsx(y,{label:"API Key",type:"password",value:b,onChange:s=>I(s.target.value),placeholder:w?"â¢â¢â¢â¢â¢â¢â¢â¢ (leave blank to keep)":"SEMrush API key",disabled:!o}),e.jsx(y,{label:"Target domain",value:P,onChange:s=>v(s.target.value),placeholder:"e.g. example.com (for domain overview)",disabled:!o}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-claude-text-secondary mb-1",children:"Scheduled sync keywords (comma-separated)"}),e.jsx("textarea",{value:G,onChange:s=>j(s.target.value),disabled:!o,placeholder:"e.g. content marketing, seo tips",className:"w-full min-h-[72px] rounded-xl border border-claude-border bg-claude-surface px-3 py-2 text-sm text-claude-text"}),e.jsx("p",{className:"text-[10px] text-claude-text-tertiary mt-1",children:"Nightly sync refreshes these in KeywordInsight (rate-limited)."})]})]}),r.id==="google-analytics"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{label:"GA4 Property ID",value:E,onChange:s=>L(s.target.value),placeholder:"e.g. 123456789 (Admin â Property settings)",disabled:!o}),Z&&e.jsxs("p",{className:"text-xs text-claude-text-secondary",children:["OAuth tokens stored",R?` for ${R}`:"",'. Use "Sign in with Google" to replace.']}),o&&e.jsxs(u,{type:"button",variant:"outline",className:"w-full",disabled:X,onClick:ne,children:[X?e.jsx(p,{className:"h-4 w-4 animate-spin mr-2"}):null,"Sign in with Google (Analytics read-only)"]}),e.jsx(y,{label:"Manual access token (optional fallback)",type:"password",value:D,onChange:s=>K(s.target.value),placeholder:"Leave empty if using OAuth",disabled:!o})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(u,{className:"flex-1",onClick:ae,disabled:_||!o,children:_?"Saving...":"Save"}),e.jsx(u,{variant:"outline",className:"flex-1",onClick:()=>g(null),children:"Cancel"})]})]})]})}),document.body)]})}
8export{je as IntegrationsPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.