1import{j as e,aT as H,aW as A,aX as W,aY as M,aZ as I,a_ as B,d as Z,r as c,hL as J,fD as K,y as ee,fp as O,d3 as se,hM as te,aL as U,E as T,S as ae,fy as ne}from"./index-DMQ34O7E.js";import{a as oe,u as re,b as ie}from"./hubspotService-DSYpXQ7w.js";function ce({domains:x,selectedDomain:g,onDomainChange:y,disabled:E=!1}){return e.jsxs("div",{className:"flex flex-col gap-2 w-full",children:[e.jsx(H,{htmlFor:"domain",className:"text-sm font-medium text-[#27283c]",children:"Select domain to connect"}),e.jsxs(A,{value:g,onValueChange:y,disabled:E,children:[e.jsx(W,{className:"h-12 bg-white border border-[#c7cade] rounded-[4px] px-4 py-3",children:e.jsx(M,{placeholder:"Select domain",children:g||"Select domain"})}),e.jsx(I,{position:"popper",className:"max-h-[300px] overflow-y-auto bg-white rounded-[4px] shadow-lg border border-[#c7cade]",children:x.map(r=>e.jsx(B,{value:r.domain,className:"py-3 px-4 cursor-pointer hover:bg-gray-100",children:r.domain},r.id))})]})]})}const ge=Z("/hubspot/domains")({component:le});function le(){const[x,g]=c.useState(null),[y,E]=c.useState(null),[r,z]=c.useState(""),[m,D]=c.useState(""),_=new URLSearchParams(globalThis.location.search),t=_.get("hub_id"),l=_.get("domain"),j=_.get("organization_id"),R=_.get("license_retry")==="1";c.useEffect(()=>{const s=new URLSearchParams(globalThis.location.search);if(s.get("connect_error")!=="1")return;const a=s.get("connect_error_msg");E((a==null?void 0:a.trim())||"We couldn't connect your site automatically. Choose a HubSpot domain below or try again.");const n=new URL(globalThis.location.href);n.searchParams.delete("connect_error"),n.searchParams.delete("connect_error_msg"),globalThis.history.replaceState(null,"",n.toString())},[]);const{isLoading:V}=J(),d=K(s=>s.accessibleOrganizations),{data:v=[],isLoading:u,isError:b,error:N}=oe(t,!1,!!t),w=ee(s=>s.user),{data:f,isFetched:k}=re(t,null,!!t),L=!!t&&(w==null?void 0:w.id)!=null&&!!(f!=null&&f.exists)&&f.user_id!=null&&String(f.user_id)!==String(w.id),i=ie(),$=c.useMemo(()=>{var s;return(s=d.find(a=>a.id.toString()===r))==null?void 0:s.name},[d,r]);c.useEffect(()=>{if(l&&t&&d.length>0&&!u&&!i.isPending&&!r&&d.length>0){const s=j&&d.some(a=>a.id.toString()===j)?j:d[0].id.toString();z(s),D(l),Y(s,l,t)}},[l,j,t,d,u,i.isPending,r]);const Y=async(s,a,n)=>{var S,h;try{const o=await i.mutateAsync({hub_id:n,domain:a,organization_id:s});globalThis.location.href=O(o,n)}catch(o){if(console.error(o),((h=(S=o.response)==null?void 0:S.data)==null?void 0:h.code)==="hubspot.agency_license_error"){const p=new URLSearchParams;p.set("hub_id",n),p.set("domain",a),p.set("organization_id",s),R&&(p.set("license_retry","1"),p.set("license_error","1")),globalThis.location.href=`/hubspot/agency-license?${p.toString()}`;return}const P=o instanceof Error?o.message:"Failed to create website";g(P)}},q=s=>ne(s,35);c.useEffect(()=>{var a,n;if(!t){g("Missing HubSpot account ID");return}if(!b||!N)return;if((se(N)?(n=(a=N.response)==null?void 0:a.data)==null?void 0:n.code:void 0)==="hubspot.oauth_reauth_required"){const S="",h=new URLSearchParams({hub_id:t,source:"hubspot",access:"direct",oauth_reauth:"1"}),o=te();for(const[F,P]of Object.entries(o))h.set(F,String(P));globalThis.location.replace(`${S}/connect-hubspot?${h.toString()}`);return}g("Failed to fetch domains from HubSpot")},[t,b,N]),c.useEffect(()=>{if(!t||!k||!L)return;const s="",a=new URLSearchParams({hub_id:t,source:"hubspot",access:"direct"});globalThis.location.href=`${s}/connect-hubspot?${a.toString()}`},[t,k,L]),c.useEffect(()=>{if(!u&&!b&&!l&&t&&v.length===0&&!i.isPending&&!i.isSuccess&&k&&!L){const s="";globalThis.location.href=`${s}/dashboard`}},[u,b,l,t,v.length,i.isPending,i.isSuccess,k,L]);const G=async()=>{var s,a;if(!(!r||!m||!t))try{const n=await i.mutateAsync({hub_id:t,domain:m,organization_id:r});globalThis.location.href=O(n,t)}catch(n){if(console.error(n),((a=(s=n.response)==null?void 0:s.data)==null?void 0:a.code)==="hubspot.agency_license_error"){const o=new URLSearchParams;o.set("hub_id",t),o.set("domain",m),o.set("organization_id",r),R&&(o.set("license_retry","1"),o.set("license_error","1")),globalThis.location.href=`/hubspot/agency-license?${o.toString()}`;return}const h=n instanceof Error?n.message:"Failed to create website";g(h)}},Q=!u&&!b&&!l&&!!t&&v.length===0&&!i.isSuccess;if(u||V||l&&!x||Q)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#f8f9ff] bg-cover",style:{backgroundImage:"url(undefined/images/maintenance-gradient-bg.svg)"},children:e.jsx(U,{})});if(x)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#f8f9ff] bg-cover px-4",style:{backgroundImage:"url(undefined/images/maintenance-gradient-bg.svg)"},children:e.jsx("div",{className:"w-full max-w-[640px] bg-white rounded-[9px] shadow-[0px_0px_5px_0px_rgba(0,0,0,0.06),0px_9px_10px_0px_rgba(0,0,0,0.02),0px_17px_23px_0px_rgba(0,0,0,0.03)] px-10 py-8",children:e.jsxs("div",{className:"flex flex-col gap-6 text-center",children:[e.jsx("div",{className:"mb-4",children:e.jsx("svg",{className:"mx-auto h-12 w-12 text-danger",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("h2",{className:"text-[26px] font-semibold text-dark leading-[39px] font-[Poppins]",children:"Unable to Add Website"}),e.jsx("p",{className:"text-base text-secondary-dark leading-6",children:x}),e.jsxs("div",{className:"flex gap-4 justify-center",children:[e.jsx(T,{onClick:()=>globalThis.location.reload(),variant:"outline-secondary",className:"px-4 py-2",children:"Go Back"}),(x.includes("upgrade")||x.includes("plan"))&&e.jsx(T,{onClick:()=>
1{globalThis.location.href="https://app.cookieyes.com/v1/settings"},className:"px-4 py-2",children:"Upgrade Plan"})]})]})})});const C=i.isPending,X=!r||!m||C;return e.jsxs("div",{className:"min-h-screen relative bg-[#f8f9ff] bg-cover overflow-hidden",style:{backgroundImage:"url(undefined/images/maintenance-gradient-bg.svg)"},children:[e.jsx("div",{className:"absolute top-[32px] left-[32px]",children:e.jsx("img",{src:"undefined/images/cy-logo.svg",alt:"CookieYes",className:"h-[24px] w-auto"})}),e.jsx("div",{className:"flex items-center justify-center min-h-screen px-4 relative z-10",children:e.jsx("div",{className:"w-full max-w-[640px] bg-white rounded-[9px] shadow-[0px_0px_5px_0px_rgba(0,0,0,0.06),0px_9px_10px_0px_rgba(0,0,0,0.02),0px_17px_23px_0px_rgba(0,0,0,0.03)] px-10 py-8",children:e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx("div",{className:"flex flex-col gap-2 text-center",children:e.jsx("h1",{className:"text-[26px] font-semibold text-dark leading-[39px] font-[Poppins]",children:"Choose a HubSpot domain to connect"})}),e.jsxs("div",{className:"flex flex-col gap-6",children:[y&&e.jsx("div",{role:"alert",className:"rounded-[4px] border border-danger/30 bg-danger/5 px-4 py-3 text-left text-sm text-danger",children:y}),e.jsx("p",{className:"text-base text-secondary-dark leading-6",children:"Select the HubSpot domain where you'd like to add your CookieYes banner."}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(H,{htmlFor:"organization",className:"text-sm font-medium text-[#27283c]",children:"Select Organisation to add site"}),e.jsxs(A,{value:r,onValueChange:z,children:[e.jsx(W,{className:"h-12 bg-white border border-[#c7cade] rounded-[4px] px-4 py-3",children:e.jsx(M,{placeholder:"Select organisation",children:r&&$?q($):"Select organisation"})}),e.jsx(I,{position:"popper",className:"max-h-[300px] overflow-y-auto bg-white rounded-[4px] shadow-lg border border-[#c7cade]",children:d.map(s=>e.jsxs(B,{value:s.id.toString(),className:"py-3 px-4 cursor-pointer hover:bg-gray-100",children:[s.name," (Org ID: ",s.id,")"]},s.id))})]})]}),e.jsx(ce,{domains:v,selectedDomain:m,onDomainChange:D,disabled:C}),e.jsx(T,{onClick:G,disabled:X,className:"w-full h-12 bg-primary hover:bg-primary-dark text-white text-base font-semibold rounded-[4px] disabled:bg-secondary disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:["Next",C&&e.jsx(ae,{className:"h-4 w-4"})]})})]})]})})}),C&&e.jsx(U,{fullScreen:!0})]})}export{le as HubSpotDomains,ge as Route};
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.