1import{r as _,j as e}from"./ll-6IjxXPIz.js";import{c as M,a as H,y as $,aX as B,C as U,e as T,am as V,f as A,g as S,h as I,B as v,l as X,m as z,x as u,aW as G,L as q,d as j,aO as K,aQ as y,a$ as D,a_ as Q}from"./ll-CkZW7G1U.js";import{A as Y}from"./ll-CQn3hjdm.js";const F=["lemtask.com","lemtask.lovable.app","lemledger.com","lemledger.lovable.app","lovable.app","lovableproject.com"],J=2048;function Z(t){try{const s=new URL(t);return s.protocol!=="https:"?!1:F.some(n=>s.hostname===n||s.hostname.endsWith(`.${n}`))}catch{return!1}}function ee(t){try{return new URL(t).protocol==="https:"}catch{return!1}}function o(t,s=J){return(t??"").trim().slice(0,s)}function ne(){const[t]=M(),s=H(),{profile:n,updateProfileAsync:h}=$(),{deliverWebhook:w}=B(),[p,f]=_.useState(!1),a=_.useMemo(()=>({source:o(t.get("source")),handshakeId:o(t.get("handshake_id")),callbackUrl:o(t.get("callback_url")),inboundUrl:o(t.get("inbound_url")),inboundToken:o(t.get("inbound_token"))}),[t]),N=_.useMemo(()=>!a.source||!a.handshakeId||!a.callbackUrl?"Missing required parameters. This page should be opened from LemTask.":!a.inboundUrl||!ee(a.inboundUrl)?"LemTask did not provide a valid sync URL. Start the connection again from LemTask.":a.source!=="lemtask"?`Unsupported integration source: "${a.source}".`:Z(a.callbackUrl)?null:"Invalid callback URL. Only lemtask.com and lemtask.lovable.app domains are allowed.",[a]),k=async()=>{if(n){f(!0);try{const c="https://prihaalhoeukpwfimjcj.supabase.co",x=n.ai_config||{},C=K(x),i=C.ledger_inbound_token||x.inbound_webhook_token||crypto.randomUUID(),L=`${c}/functions/v1/inbound-webhook?token=${i}`,l=a.inboundToken||C.peer_token,R=new Date().toISOString(),E=y(x,{status:"checking",connected_via:"handshake",webhook_url:a.inboundUrl,ledger_inbound_token:i,peer_token:l,last_checked_at:R,last_error:null});await h({ai_config:D(E,a.inboundUrl,l)});const g=await w("deliverable.created",{id:"handshake-verify-"+Date.now(),title:"ð¤ LemLedger Push Verification",status:"not_started",priority:"medium",due_date:null,client_name:null,project_name:null,internal_commentary:"Handshake verification â LemTask should validate without creating a real task.",_test:!0}),d=Q(g);if(d.kind!=="healthy"){if(!(g.success===!0&&g.lemtaskAttempted===!0)){const b=n.ai_config||{};await h({ai_config:y(b,{status:d.kind==="auth_failed"?"needs_reconnect":"checking",last_checked_at:new Date().toISOString(),last_error:d.message})})}j.error(d.message,{action:{label:"Try again",onClick:()=>void k()}}),f(!1);return}const m=new Date().toISOString(),O=n.ai_config||{},W=y(O,{status:"connected",connected_via:"handshake",webhook_url:a.inboundUrl,ledger_inbound_token:i,peer_token:l,last_verified_at:m,last_push_verified_at:m,last_checked_at:m,last_error:null});await h({ai_config:D(W,a.inboundUrl,l)});try{await w("connection.verified",{provider:"lemtask",ledger_url:L,ledger_token:i,verified_at:m,connection_status:"connected"})}catch(b){console.warn("[Connect] connection.verified notify failed (non-blocking):",b)}try{localStorage.removeItem("lemtask_handshake_pending")}catch{}j.success("Connected â returning you to LemTaskâ¦");const r=new URL(a.callbackUrl);r.searchParams.set("handshake_id",a.handshakeId),r.searchParams.set("ledger_url",L),r.searchParams.set("ledger_token",i),r.searchParams.set("connection_status","connected"),r.searchParams.set("connection_provider","lemtask"),window.location.href=r.toString()}catch(c){console.error("Handshake approval failed:",c),j.error("Couldn't complete the connection. Please try again.",{action:{label:"Try again",onClick:()=>void k()}}),f(!1)}}},P=()=>{try{localStorage.removeItem("lemtask_handshake_pending")}catch{}s("/settings")};return N?e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center p-6",children:e.jsxs(U,{className:"w-full max-w-md",children:[e.jsxs(T,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10",children:e.jsx(V,{className:"h-6 w-6 text-destructive"})}
1),e.jsx(A,{className:"text-lg",children:"Connection Error"}),e.jsx(S,{children:N})]}),e.jsx(I,{className:"flex justify-center",children:e.jsx(v,{variant:"outline",onClick:()=>s("/settings"),children:"Go to Settings"})})]})}):e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center p-6",children:e.jsxs(U,{className:"w-full max-w-md",children:[e.jsxs(T,{className:"text-center space-y-3",children:[e.jsx("div",{className:"mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Y,{className:"h-7 w-7 text-primary"})}),e.jsxs("div",{children:[e.jsx(A,{className:"text-lg",children:"Connect to LemTask"}),e.jsx(S,{className:"mt-1.5",children:"LemTask wants to connect to your LemLedger account. This enables bidirectional sync of deliverables and tasks."})]}),e.jsxs(X,{variant:"outline",className:"mx-auto text-xs",children:[e.jsx(z,{className:"h-3 w-3 mr-1"}),"Secure handshake"]})]}),e.jsxs(I,{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-4 space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"What gets synced"}),e.jsxs("ul",{className:"text-sm text-foreground space-y-1.5",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(u,{className:"h-4 w-4 text-primary mt-0.5 shrink-0"}),e.jsx("span",{children:"Deliverable creation, completion & status changes"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(u,{className:"h-4 w-4 text-primary mt-0.5 shrink-0"}),e.jsx("span",{children:"Task assignments matched by email"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(u,{className:"h-4 w-4 text-primary mt-0.5 shrink-0"}),e.jsx("span",{children:"Near real-time bidirectional updates"})]})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground text-center leading-relaxed rounded-md bg-muted/40 border border-border/50 p-2.5",children:"After you approve, we'll send you back to LemTask to finish â then both apps stay in sync automatically."}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(v,{variant:"outline",className:"flex-1",onClick:P,disabled:p,children:[e.jsx(G,{className:"h-4 w-4 mr-1"}),"Decline"]}),e.jsxs(v,{className:"flex-1",onClick:k,disabled:p,children:[p?e.jsx(q,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(u,{className:"h-4 w-4 mr-1"}),"Approve Connection"]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground text-center",children:"You can disconnect at any time from Settings â Integrations."})]})]})})}export{ne as default}; 2//# sourceMappingURL=ll-_3X4-L3i.js.map
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.