1import{g as F,P,r as a,b as E,j as e,L as g,B as u,o as q,C as w,K as b,N as k,bJ as D,c as L,I as f,s as l}from"./index-PtGACUVf.js";import{u as B}from"./useMutation-B6B2ZZTv.js";import{L as p}from"./label-BGYTmHnu.js";import{A as M,b as R,a as K}from"./alert-aNjvcd0z.js";import{A as Q}from"./arrow-left-QiRMPYSA.js";import{L as z}from"./link-2-BVFjxgEn.js";import{E as H}from"./eye-off-CXoqCu0T.js";import{E as O}from"./eye-B9hDvAFW.js";import{S as W}from"./save-BZd-y5bh.js";import{C as $}from"./circle-check-big-sSf7dLsd.js";import{C as J}from"./circle-x-D8wBAwq0.js";function ie(){const{toast:m}=F(),_=P(),[d,y]=a.useState(""),[n,v]=a.useState(""),[i,j]=a.useState(""),[x,S]=a.useState(!1),[r,c]=a.useState(null),[C,N]=a.useState(!1),{data:t,isLoading:T}=E({queryKey:["ghl-agency-config"],queryFn:async()=>{const{data:s,error:o}=await l.from("ghl_agency_config").select("*").eq("is_active",!0).maybeSingle();if(o)throw o;return s}});a.useEffect(()=>{t&&(y(t.agency_name||""),v(t.relationship_id||""),j(t.private_token||""))},[t]);const h=B({mutationFn:async()=>{if(t!=null&&t.id){const{error:s}=await l.from("ghl_agency_config").update({agency_name:d,relationship_id:n,private_token:i}).eq("id",t.id);if(s)throw s}else{await l.from("ghl_agency_config").update({is_active:!1}).eq("is_active",!0);const{error:s}=await l.from("ghl_agency_config").insert({agency_name:d,relationship_id:n,private_token:i,is_active:!0});if(s)throw s}},onSuccess:()=>{_.invalidateQueries({queryKey:["ghl-agency-config"]}),m({title:"Configuration saved",description:"LeadConnector credentials have been saved successfully."})},onError:s=>{m({title:"Error saving configuration",description:s.message||"Failed to save configuration.",variant:"destructive"})}}),A=async()=>{if(!i||!n){c({success:!1,message:"Please enter both Relationship ID and Private Token before testing."});return}N(!0),c(null);try{const{data:s,error:o}=await l.functions.invoke("ghl-integration",{body:{action:"verify-agency",relationshipId:n,privateToken:i}});if(o)throw o;
1s!=null&&s.valid?c({success:!0,message:`Successfully connected to LeadConnector agency${s.agencyName?`: ${s.agencyName}`:""}.`}):c({success:!1,message:(s==null?void 0:s.error)||"Failed to verify connection. Please check your credentials."})}catch(s){c({success:!1,message:s.message||"Connection test failed. Please verify your credentials."})}finally{N(!1)}},I=()=>{if(!d||!n||!i){m({title:"Missing fields",description:"Please fill in all required fields.",variant:"destructive"});return}h.mutate()};return T?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(g,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsx(u,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs(q,{to:"/admin/settings",children:[e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Back to Settings"]})})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-2",children:[e.jsx(z,{className:"h-8 w-8"}),"LeadConnector Integration"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Connect your LeadConnector agency to automatically provision sub-accounts for new customers"})]}),e.jsxs(w,{children:[e.jsxs(b,{children:[e.jsx(k,{children:"Agency Configuration"}),e.jsx(D,{children:"Enter your LeadConnector agency credentials to enable automatic sub-account creation when customers claim their listings."})]}),e.jsxs(L,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"agencyName",children:"Agency Name"}),e.jsx(f,{id:"agencyName",value:d,onChange:s=>y(s.target.value),placeholder:"247365.ai"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"A friendly name to identify your agency"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"relationshipId",children:"Relationship ID"}),e.jsx(f,{id:"relationshipId",value:n,onChange:s=>v(s.target.value),placeholder:"0-031-643"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in LeadConnector under Settings when viewing your agency"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"privateToken",children:"Private Integration Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(f,{id:"privateToken",type:x?"text":"password",value:i,onChange:s=>j(s.target.value),placeholder:"pit-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",className:"pr-10"}),e.jsx(u,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>S(!x),children:x?e.jsx(H,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(O,{className:"h-4 w-4 text-muted-foreground"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Create in LeadConnector â Settings â Private Integrations"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{onClick:I,disabled:h.isPending,children:h.isPending?e.jsxs(e.Fragment,{children:[e.jsx(g,{className:"h-4 w-4 animate-spin mr-2"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"h-4 w-4 mr-2"}),"Save Configuration"]})}),e.jsx(u,{variant:"outline",onClick:A,disabled:C,children:C?e.jsxs(e.Fragment,{children:[e.jsx(g,{className:"h-4 w-4 animate-spin mr-2"}),"Testing..."]}):"Test Connection"})]}),r&&e.jsxs(M,{variant:r.success?"default":"destructive",children:[r.success?e.jsx($,{className:"h-4 w-4"}):e.jsx(J,{className:"h-4 w-4"}),e.jsx(R,{children:r.success?"Connected":"Connection Failed"}),e.jsx(K,{children:r.message})]}),t&&e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Configuration last saved: ",new Date(t.created_at).toLocaleDateString()]})})]})]}),e.jsxs(w,{children:[e.jsx(b,{children:e.jsx(k,{children:"How It Works"})}),e.jsxs(L,{className:"space-y-4 text-sm text-muted-foreground",children:[e.jsx("p",{children:"When a customer claims a listing and completes their subscription:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-2",children:[e.jsx("li",{children:"A new sub-account is created in your LeadConnector agency"}),e.jsx("li",{children:"The customer receives an invitation email to access their account"}),e.jsx("li",{children:"The sub-account is linked to their business listing in I AM LOCAL AI"}),e.jsx("li",{children:"Alternatively, existing customers can link their Location ID during checkout"})]})]})]})]})}export{ie 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.