1import{e as E,r as i,s as d,j as e,C as f,f as p,g as L,h as j,i as _,k as w,B as g,L as N,l as q,m as D}from"./index-snQw3C60.js";function U(){var k,z;const[l]=E(),a=l.get("authorization_id")??"",[u,R]=i.useState(null),[y,c]=i.useState(null),[o,m]=i.useState(!1),[b,h]=i.useState(null);i.useEffect(()=>{let r=!0;return(async()=>{if(!a)return c("Missing authorization_id");const{data:t}=await d.auth.getSession();if(!t.session){const S=window.location.pathname+window.location.search,B=P(S)?S:"/";window.location.href=`/auth?redirect=${encodeURIComponent(B)}`;return}const{data:s,error:n}=await d.auth.oauth.getAuthorizationDetails(a);if(!r)return;if(n)return c(n.message);const A=(s==null?void 0:s.redirect_url)??(s==null?void 0:s.redirect_to);if(A&&!(s!=null&&s.client)){window.location.href=A;return}R(s)})(),()=>{r=!1}},[a]);async function C(r){m(!0),h(r?"approved":"denied");const{data:t,error:s}=r?await d.auth.oauth.approveAuthorization(a):await d.auth.oauth.denyAuthorization(a);if(s)return m(!1),h(null),c(s.message);const n=(t==null?void 0:t.redirect_url)??(t==null?void 0:t.redirect_to);if(!n)return m(!1),h(null),c("No redirect returned by the authorization server.");window.location.href=n}if(y)return e.jsx("main",{className:"min-h-screen flex items-center justify-center p-6 bg-background",children:e.jsxs(f,{className:"max-w-md w-full",children:[e.jsxs(p,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(L,{className:"h-6 w-6 text-destructive"}),e.jsx(j,{children:"Authorization request failed"})]}),e.jsx(_,{children:"We could not load this authorization request."})]}),e.jsxs(w,{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:y}),e.jsx(g,{variant:"outline",className:"mt-4 w-full",onClick:()=>window.location.href="/",children:"Go home"})]})]})});if(!u)return e.jsx("main",{className:"min-h-screen flex items-center justify-center p-6 bg-background",children:e.jsxs(f,{className:"max-w-md w-full",children:[e.jsx(p,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(N,{className:"h-6 w-6 animate-spin"}),e.jsx(j,{children:"Loading authorization requestâ¦"})]})}),e.jsx(w,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait while we load the app that wants to connect."})})]})});const v=((k=u.client)==null?void 0:k.name)||"An unknown app",x=(z=u.client)==null?void 0:z.client_uri;return e.jsx("main",{className:"min-h-screen flex items-center justify-center p-6 bg-background",children:e.jsxs(f,{className:"max-w-md w-full",children:[e.jsxs(p,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(q,{className:"h-6 w-6 text-primary"}),e.jsxs(j,{children:["Connect ",v," to your account"]})]}),e.jsxs(_,{children:[v," is asking for permission to access your Trading Post merchant data."]})]}),e.jsxs(w,{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsx("p",{className:"text-sm font-medium",children:"This app will be able to:"}),e.jsxs("ul",{className:"space-y-2 text-sm text-muted-foreground",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(D,{className:"h-4 w-4 mt-0.5 text-primary"}),e.jsx("span",{children:"Read your marketplace listings and inventory"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(D,{className:"h-4 w-4 mt-0.5 text-primary"}),e.jsx("span",{children:"Act on your behalf while you are connected"})]})]}),x&&e.jsxs("p",{className:"text-xs text-muted-foreground pt-2",children:["App website: "," ",e.jsx("a",{href:x,target:"_blank",rel:"noreferrer",className:"underline",children:x})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsxs(g,{variant:"outline",className:"flex-1",disabled:o,onClick:()=>C(!1),children:[b==="denied"&&o&&e.jsx(N,{className:"mr-2 h-4 w-4 animate-spin"}),"Deny"]}),e.jsxs(g,{className:"flex-1",disabled:o,onClick:()=>C(!0),children:[b==="approved"&&o&&e.jsx(N,{className:"mr-2 h-4 w-4 animate-spin"}),"Approve"]})]})]})]})})}function P(l){try{return l.startsWith("/")?new URL(l,window.location.origin).origin===window.location.origin:!1}catch{return!1}}export{U 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.