1import{q as A,r,j as e,x as _,L as M,H as b,S as j,a4 as L,c7 as f,z as n}from"./index-BACUqBz4.js";import{A as R}from"./arrow-left-BCEZxjJ3.js";import{R as I}from"./refresh-cw-B0_1m12Q.js";import{T as B}from"./trash-2-BnqHyW3k.js";/** 2 * @license lucide-react v0.383.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 D=A("Megaphone",[["path",{d:"m3 11 18-5v12L3 14v-3z",key:"n962bs"}],["path",{d:"M11.6 16.8a3 3 0 1 1-5.8-1.6",key:"1yl0tm"}]]),y={width:"100%",padding:"10px 12px",border:"1px solid var(--border-default)",borderRadius:8,background:"var(--bg-raised)",color:"var(--fg-primary)",fontSize:"0.9rem"},p={fontSize:"0.8rem",fontWeight:700,color:"var(--fg-secondary)",marginBottom:6,display:"block"};function F(){const[t,h]=r.useState(null),[u,v]=r.useState(""),[g,x]=r.useState(""),[m,k]=r.useState(""),[o,a]=r.useState(!1);async function c(){try{h((await f.status()).data)}catch{h({connected:!1})}}r.useEffect(()=>{c()},[]);async function S(){var s,i,d;if(!g.trim()||!u.trim()){n.error("Enter the access token and ad account id");return}a(!0);try{await f.connect(g,u,m),n.success("Connected â pulling Meta Ads metrics"),x(""),await c()}catch(l){((s=l==null?void 0:l.response)==null?void 0:s.status)!==402&&n.error(((d=(i=l.response)==null?void 0:i.data)==null?void 0:d.detail)||"Could not connect")}finally{a(!1)}}async function w(){var s,i;a(!0);try{await f.sync(),n.success("Synced"),await c()}catch(d){n.error(((i=(s=d.response)==null?void 0:s.data)==null?void 0:i.detail)||"Sync failed")}finally{a(!1)}}async function C(){if(window.confirm("Disconnect Meta Ads?")){a(!0);try{await f.disconnect(),n.success("Disconnected"),await c()}catch{n.error("Could not disconnect")}finally{a(!1)}}}const z=t==null?void 0:t.connected;return e.jsxs(_,{width:760,children:[e.jsxs(M,{to:"/integrations",style:{display:"inline-flex",alignItems:"center",gap:6,color:"var(--fg-secondary)",textDecoration:"none",fontSize:"0.85rem",marginBottom:8},children:[e.jsx(R,{size:15})," Integrations"]}),e.jsx(b,{eyebrow:"Data source",title:e.jsxs(e.Fragment,{children:["Connect ",e.jsx(b.Accent,{children:"Meta Ads"})]}),description:"Pull spend, impressions, clicks and CTR from your Meta (Facebook/Instagram) ad account every day.",chart:!1}),t===null?e.jsxs("div",{style:{padding:"var(--space-5) 0"},"aria-busy":"true","aria-label":"Checking connection",children:[e.jsx(j,{width:190,height:18,style:{marginBottom:"var(--space-3)"}}),e.jsx(j.Card,{height:92})]}):z?e.jsxs("div",{className:"card",style:{padding:22},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:10},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:10,background:"#0866ff18",color:"#0866ff",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(D,{size:20})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:800,color:"var(--fg-primary)"},children:t.account_label||"Meta Ads"}),e.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--fg-secondary)"},children:[t.ad_account_id," · ",t.status==="error"?"needs attention":"active"]})]}),e.jsxs("span",{style:{marginLeft:"auto",color:t.status==="error"?"#b91c1c":"#059669",fontWeight:700,fontSize:"0.82rem",display:"inline-flex",gap:6,alignItems:"center"},children:[e.jsx(L,{size:15})," ",t.status==="error"?"Error":"Connected"]})]}),t.last_error&&e.jsx("div",{style:{background:"#fef2f2",border:"1px solid #fee2e2",color:"#b91c1c",borderRadius:8,padding:"8px 12px",fontSize:"0.82rem",marginBottom:12},children:t.last_error}),e.jsxs("div",{style:{fontSize:"0.82rem",color:"var(--fg-secondary)",marginBottom:14},children:["Last synced: ",t.last_synced_at?new Date(t.last_synced_at).toLocaleString():"â"," · updates daily"]}),e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("button",{onClick:w,disabled:o,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"9px 14px",borderRadius:8,border:"none",background:"linear-gradient(135deg,#a855f7,#ec4899)",color:"#fff",fontWeight:700,cursor:"pointer"},children:[e.jsx(I,{size:15})," Sync now"]}),e.jsxs("button",{onClick:C,disabled:o,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"9px 14px",borderRadius:8,border:"1px solid #f0d0d0",background:"#fff",color:"#b91c1c",fontWeight:700,cursor:"pointer"},children:[e.jsx(B,{size:15})," Disconnect"]})]})]}):e.jsx("div",{className:"card",style:{padding:22},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[e.jsxs("div",{children:[e.jsx("label",{style:p,children:"Ad account ID"}),e.jsx("input",{style:y,value:u,onChange:s=>v(s.target.value),placeholder:"act_1234567890 (or just the number)"})]}),e.jsxs("div",{children:[e.jsx("label",{style:p,children:"Label (optional)"}),e.jsx("input",{style:y,value:m,onChange:s=>k(s.target.value),placeholder:"Acme â Meta Ads"})]}),e.jsxs("div",{children:[e.jsx("label",{style:p,children:"Access token (ads_read)"}),e.jsx("textarea",{style:{...y,minHeight:90,fontFamily:"monospace",fontSize:"0.78rem"},value:g,onChange:s=>x(s.target.value),placeholder:"Long-lived or system-user token with ads_read"})]}),e.jsx("button",{onClick:S,disabled:o,style:{padding:"11px",borderRadius:10,border:"none",background:"linear-gradient(135deg,#a855f7,#ec4899)",color:"#fff",fontWeight:800,cursor:o?"wait":"pointer"},children:o?"Connectingâ¦":"Connect Meta Ads"}),e.jsxs("div",{style:{background:"var(--bg-raised)",border:"1px solid var(--border-default)",borderRadius:10,padding:"12px 14px",fontSize:"0.8rem",color:"var(--fg-secondary)",lineHeight:1.55},children:[e.jsx("strong",{style:{color:"var(--fg-primary)"},children:"Where to get these:"})," create a system-user (or long-lived) access token with the ",e.jsx("strong",{children:"ads_read"})," permission in Meta Business Settings, and copy your ",e.jsx("strong",{children:"ad account id"})," (starts with ",e.jsx("code",{children:"act_"}),") from Ads Manager."]})]})})]})}export{F as default};
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.