1import{c as Be,G as vt,u as Oe,r as s,j as e,C as Z,R as _e,L as ne,S as ke,s as R,a as Ke,J as Qt,w as De,O as ue,A as Ie,F as xt,a2 as es,B as $,P as ze,o as Se,X as ye,$ as Te,a3 as ts,t as We,a4 as Nt,g as _t,U as ss,x as as,a5 as St,m as je,W as Ct,h as Tt,K as $e,a6 as Ge,M as He,l as rs,f as ns,y as is,a7 as ls,Z as mt,D as os,a8 as ee,k as Ve}from"./index-tXC5CGqy.js";import{M as cs,s as ds}from"./nangoSync-Karq4YUt.js";import{u as Et}from"./twinManagerStore-DDkaitwW.js";import{g as ht}from"./twinRouting-CdmvyaJX.js";import{a as xs,m as ms,g as hs,c as us,p as gs,K as ut,T as ps}from"./walletCrypto-Btwr7Oeq.js";import{a as At,M as Rt}from"./minting-CBtIGJbM.js";import{S as $t}from"./shield-check-DxilX4-v.js";import{W as gt}from"./wallet-Ct8tMV62.js";import{E as Dt}from"./external-link-DhCOLCLl.js";import{Y as ys,T as fs}from"./TwinKnowledgeBaseManager-B9KW6Z4g.js";import{G as ve}from"./globe-ByCQ53Up.js";import{F as It}from"./file-text-69Yhy93Y.js";import{C as be}from"./chevron-right-CExTYD18.js";import{C as ce,b as ge,a as Bt}from"./Card-DW8yetjY.js";import{P as Ot}from"./pen-0wjniSkH.js";import{D as Ce}from"./database-D6GBN1R0.js";import{U as pt}from"./user-cog-B49Uxlz3.js";import{S as bs}from"./search-Bh8Remer.js";import{U as ws}
1from"./user-plus-Df42s8b-.js";import{M as Ye}from"./mail-BeJiuejh.js";import{C as js}from"./credit-card-CghhQ8_v.js";import{C as we}from"./copy-CyJ-K1TQ.js";import{C as ks}from"./code-DqZ0Q0Oc.js";import{H as vs}from"./hash-BOcez4lR.js";import{C as Ns}from"./CategoryTrustPanel-CwGUyc0q.js";import{R as Je,F as _s}from"./FavoriteButton-oa6xxVUs.js";import{U as Ss}from"./user-BKTtiH60.js";import{u as Cs}from"./brandClaimStore-0bemNqOO.js";import{e as Ts,d as Es}from"./twinPortability-D06PJnfJ.js";import{S as yt}from"./square-pen-CNvR7OM5.js";import{H as As}from"./hand-Bf9JOOnz.js";import{H as ft}from"./heart-DoP-56QC.js";import{P as Rs}from"./palette-Bq-K4EJ6.js";import{A as $s}from"./activity-CCsyTtiG.js";import{L as Ds}from"./layers-CoGAVLpq.js";import{R as Is}from"./rocket-CGOvXNsB.js";import"./index-ZTqVCowg.js";import"./twinKnowledgeBaseStore-CgPsPtq7.js";import"./index-CZtop_rq.js";import"./star-DIt62vLX.js";import"./favoritesStore-5YpD6LVl.js";import"./jszip.min-BpwVKktM.js";/** 2 * @license lucide-react v0.344.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 Bs=Be("ArrowUpCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 12-4-4-4 4",key:"177agl"}],["path",{d:"M12 16V8",key:"1sbj14"}]]);/** 7 * @license lucide-react v0.344.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Os=Be("Rss",[["path",{d:"M4 11a9 9 0 0 1 9 9",key:"pv89mb"}],["path",{d:"M4 4a16 16 0 0 1 16 16",key:"k0647b"}],["circle",{cx:"5",cy:"19",r:"1",key:"bfqh0e"}]]);/** 12 * @license lucide-react v0.344.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Fs=Be("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/** 17 * @license lucide-react v0.344.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Ps=Be("ToggleRight",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"16",cy:"12",r:"2",key:"4ma0v8"}]]);function Ms({twinId:a,isOwner:i=!1,className:n=""}){const{mintTwin:o,getMintStatus:g,verifyTwin:t}=vt(),{user:m}=Oe(),[u,y]=s.useState("loading"),[_,p]=s.useState(null),[v,h]=s.useState(0),[f,w]=s.useState(null),[E,S]=s.useState(null),[O,B]=s.useState(!1),[D,j]=s.useState(null),[F,P]=s.useState(!1),[U,q]=s.useState(null),[N,C]=s.useState(!1),[L,W]=s.useState(!1),Q=s.useRef(typeof window<"u"&&new URLSearchParams(window.location.search).get("mint")==="success"),d=async()=>{var K;const M=await g(a);if(y(M),M==="minted"){const{data:G}=await R.from("mint_attempts").select("explorer_url, updated_at, transfer_offer_id, claimed_at").eq("twin_id",a).eq("status","minted").order("updated_at",{ascending:!1}).limit(1),x=G==null?void 0:G[0];p((x==null?void 0:x.explorer_url)??null),q((x==null?void 0:x.transfer_offer_id)??null),C(!!(x!=null&&x.claimed_at));const{data:k,count:V}=await R.from("twin_mint_versions").select("minted_at",{count:"exact"}).eq("twin_id",a).order("version_number",{ascending:!1}).limit(1);h(V??0),w(((K=k==null?void 0:k[0])==null?void 0:K.minted_at)??null),t(a).then(S)}else S(null);return M};s.useEffect(()=>{d()},[a]);const c=u==="paid"||Q.current&&(u==="intent"||u==="paid"||u==="loading");s.useEffect(()=>{if(!c)return;let M=0;const K=setInterval(async()=>{M+=4,M>=45&&P(!0);const G=await d();(G==="minted"||G==="failed")&&clearInterval(K)},4e3);return()=>clearInterval(K)},[c]);const T=async()=>{if(m!=null&&m.id&&(await hs(m.id)).address)return;const{address:M}=await us();m!=null&&m.id&&await gs(m.id,M)},te=async()=>{B(!0),j(null);try{await T();const M=await o(a);window.location.href=M}catch(M){j((M==null?void 0:M.message)||"Could not start"),B(!1)}},J=async()=>{if(U){W(!0),j(null);try{const M=await xs(U);await R.from("mint_attempts").update({claim_tx_hash:M,claimed_at:new Date().toISOString()}).eq("twin_id",a).eq("transfer_offer_id",U),m!=null&&m.id&&await ms(m.id),C(!0)}catch(M){j((M==null?void 0:M.message)||"Could not bring it into your wallet")}finally{W(!1)}}};if(u==="minted"){const M=f?new Date(f).toLocaleDateString():null,K=i&&!!U&&!N;return e.jsxs("div",{className:`inline-flex items-center gap-2 flex-wrap ${n}`,children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-lg bg-green-100 px-3 py-2 text-sm font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:[e.jsx(Z,{className:"h-4 w-4"})," Minted",v>1?` · v${v}`:""]}),(E==null?void 0:E.verdict)==="verified"&&e.jsxs("span",{title:E.hash_source==="xrpl-onchain"?"Re-checked against the hash committed on the XRP Ledger":"Checked against the mint record",className:"inline-flex items-center gap-1.5 rounded-lg bg-emerald-100 px-3 py-2 text-sm font-medium text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400",children:[e.jsx($t,{className:"h-4 w-4"})," Verified against chain"]}),(E==null?void 0:E.verdict)==="evolved"&&e.jsxs("span",{title:"This VirtualTwin has changed since its last mint. Re-mint to re-anchor it on-chain.",className:"inline-flex items-center gap-1.5 rounded-lg bg-amber-100 px-3 py-2 text-sm font-medium text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",children:[e.jsx(_e,{className:"h-4 w-4"})," Changed since mint"]}),K&&e.jsxs("button",{onClick:J,disabled:L,className:"inline-flex items-center gap-1.5 rounded-lg bg-gradient-to-r from-emerald-500 to-teal-500 px-3 py-2 text-sm font-semibold text-white shadow-sm transition hover:from-emerald-600 hover:to-teal-600 disabled:cursor-not-allowed disabled:opacity-60",children:[L?e.jsx(ne,{className:"h-4 w-4 animate-spin"}):e.jsx(gt,{className:"h-4 w-4"}),L?"Bringing it homeâ¦":"Bring it home â your wallet"]}),i&&N&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-lg bg-emerald-100 px-3 py-2 text-sm font-medium text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400",children:[e.jsx(gt,{className:"h-4 w-4"})," In your wallet"]}),_&&e.jsxs("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-purple-600 hover:underline dark:text-purple-400",children:["View on-chain ",e.jsx(Dt,{className:"h-3.5 w-3.5"})]}),v>1&&M&&e.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["updated ",M]}
21),i&&e.jsxs("button",{onClick:te,disabled:O,title:"Upgraded this VirtualTwin? Re-mint a new dated version on-chain.",className:"inline-flex items-center gap-1.5 rounded-lg border border-purple-300 px-3 py-2 text-sm font-medium text-purple-700 transition hover:bg-purple-50 disabled:cursor-not-allowed disabled:opacity-60 dark:border-purple-700 dark:text-purple-300 dark:hover:bg-purple-900/20",children:[O?e.jsx(ne,{className:"h-4 w-4 animate-spin"}):e.jsx(_e,{className:"h-4 w-4"}),"Update on-chain â $3"]}),D&&e.jsx("p",{className:"w-full text-xs text-red-600 dark:text-red-400",children:D})]})}return c?e.jsxs("div",{className:`inline-flex flex-col gap-1 ${n}`,children:[e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-lg bg-purple-50 px-3 py-2 text-sm font-medium text-purple-700 dark:bg-purple-900/20 dark:text-purple-300",children:[e.jsx(ne,{className:"h-4 w-4 animate-spin"})," Mintingâ¦"]}),F&&e.jsxs("button",{onClick:()=>d(),className:"inline-flex items-center gap-1 text-xs text-purple-600 hover:underline dark:text-purple-400",children:[e.jsx(_e,{className:"h-3 w-3"})," Taking longer than usual â check again"]})]}):i?e.jsxs("div",{className:n,children:[e.jsxs("div",{"aria-disabled":"true",className:"inline-flex items-center gap-2 rounded-lg px-4 py-2.5 text-sm font-semibold cursor-not-allowed select-none",style:{background:"#F2F2F4",color:"#8A8A8F",border:"1px solid #E5E5EA"},children:[e.jsx(ke,{className:"h-4 w-4"}),At]}),e.jsx("p",{className:"mt-1.5 text-xs text-gray-500 dark:text-gray-400",children:Rt})]}):null}function Us(){const a=window.blueprintx;return a&&typeof a.sendMessage=="function"?a:null}async function bt(a){const i=window.blueprintx;if(i&&typeof i.localBuildCall=="function"&&typeof i.localBuildAvailable=="function"&&await i.localBuildAvailable().then(m=>!!(m!=null&&m.available)).catch(()=>!1))return await i.localBuildCall(a);const{data:{session:n}}=await R.auth.getSession();if(!(n!=null&&n.access_token))return{error:"signed_out",message:"Your session expired â please sign in again."};const o=await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/co-builder-engine",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.access_token}`},body:JSON.stringify(a)}),g=await o.json().catch(()=>({}));return!o.ok&&!g.error&&(g.error=`http_${o.status}`),g}function Ls(a){const i=a.replace(/```(?:json)?/gi,""),n=i.indexOf("{"),o=i.lastIndexOf("}");if(n===-1||o<=n)return null;try{const g=JSON.parse(i.slice(n,o+1));return g&&typeof g=="object"?g:null}catch{return null}}const Vs=({twinId:a,twinType:i,twinName:n,onApplied:o})=>{const g=Ke(),[t,m]=s.useState(""),[u,y]=s.useState(!1),[_,p]=s.useState([]),[v,h]=s.useState(null),[f,w]=s.useState(!1),[E,S]=s.useState([]),[O,B]=s.useState(null),[D,j]=s.useState(null),[F,P]=s.useState(0),U=`bpx_refine_${a}`,q=`bpx_refine_done_${a}`,[N,C]=s.useState(null),L=Qt.useRef(null),W=Us(),Q=i==="built_app",d=e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center text-white bpx-accent-bg shrink-0",children:e.jsx(ke,{className:"w-4 h-4"})}),e.jsx("span",{className:"bpx-display text-lg uppercase text-slate-900 dark:text-white",children:"Refine it"})]}),c=x=>p(k=>[{kind:"applied",text:x},...k]),T=x=>p(k=>[{kind:"not_applied",text:x},...k]),te=async x=>{var pe;const{data:k,error:V}=await R.from("virtual_twins").select("name, twin_type, training_essence, surface_config").eq("id",a).single();if(V||!k){T("I couldn't load this VirtualTwin to refine it â please try again.");return}if(k.twin_type==="outreach"){T("Your CRM's layout is a fixed, hand-built design, so I can't restructure it from here. To add or remove people, use the CRM's own Select â Delete and Import CSV.");return}const Y=!!k.surface_config,l=Y?`You are revising the configuration of a ${((pe=k.surface_config)==null?void 0:pe.surface)||"board"} VirtualTwin called "${k.name}". 22 23CURRENT CONFIG (JSON): 24${JSON.stringify(k.surface_config).slice(0,6e3)} 25 26THE CREATOR'S CHANGE REQUEST: 27"${x}" 28 29Reply with ONLY strict JSON, no prose, no code fences: {"config": <the FULL updated config object, same shape, with the change applied>, "changes": ["short change 1"]}. Keep everything the creator did NOT ask to change exactly as-is. Keep data.list_tool="records_list" and data.mutate_tool="records_mutate". For a board keep board.group_by="stage". If the request cannot be applied to this kind of surface, return the config unchanged with "changes": [].`:`You are revising the instructions for a VirtualTwin called "${k.name}". 30 31CURRENT INSTRUCTIONS: 32${(k.training_essence||"").slice(0,6e3)} 33 34THE CREATOR'S CHANGE REQUEST: 35"${x}" 36 37Rewrite the instructions to apply the change, keeping everything else intact. Reply with ONLY strict JSON, no prose, no code fences: {"training_essence"
37: "<full revised instructions>", "changes": ["short change 1"]}. If the request truly cannot be applied, return the instructions unchanged with "changes": [].`,b=await W.sendMessage(l);if(!(b!=null&&b.success)||!b.output){T("Your local engine could not run that change â nothing was altered. Please try again.");return}const se=Ls(b.output),ae=Array.isArray(se==null?void 0:se.changes)?se.changes.filter(Boolean).map(String):[];if(!se||ae.length===0){T("I couldn't apply that change â try describing it more specifically.");return}if(Y){const H=se.config;if(!H||typeof H!="object"){T("I couldn't apply that change â try describing it more specifically.");return}const le=k.surface_config;H.surface=H.surface||le.surface||"board";const de=H.data&&typeof H.data=="object"?H.data:le.data||{};de.list_tool="records_list",de.mutate_tool="records_mutate",H.data=de,H.surface==="board"&&H.board&&typeof H.board=="object"&&(H.board.group_by="stage");const{error:re}=await R.from("virtual_twins").update({surface_config:H}).eq("id",a);if(re){T(`Could not save the change: ${re.message}`);return}}else{const H=se.training_essence;if(typeof H!="string"||!H.trim()){T("I couldn't apply that change â try describing it more specifically.");return}const{error:le}=await R.from("virtual_twins").update({training_essence:H}).eq("id",a);if(le){T(`Could not save the change: ${le.message}`);return}}c(`Done â ${ae.join(", ")}.`),m(""),o()},J=async(x,k)=>{var Y;y(!0),B(k||Date.now()),h("Opening your VirtualTwin to make that changeâ¦");const V=Date.now()+20*6e4;for(;Date.now()<V;){await new Promise(ae=>setTimeout(ae,3e3));const l=await bt({action:"status",build_id:x}).catch(()=>null);if(!l)continue;const b=Array.isArray(l.milestones)?l.milestones:[],se=b.map(ae=>String((ae==null?void 0:ae.message)||"")).filter(Boolean);if(S(se),se.length&&h(se[se.length-1]),typeof l.preview_url=="string"&&l.preview_url&&j(l.preview_url),l.status==="complete"){h(null),y(!1);try{window.localStorage.removeItem(U)}catch{}const ae=(Y=l.result)==null?void 0:Y.app_url,pe=b.some(re=>{var xe;return!!((xe=re==null?void 0:re.data)!=null&&xe.app_url)}),H=!!ae||pe,le=ae||b.map(re=>{var xe;return(xe=re==null?void 0:re.data)==null?void 0:xe.app_url}).find(Boolean)||null,de={live:H,appUrl:le||null};C(de);try{window.localStorage.setItem(q,JSON.stringify(de))}catch{}m(""),o();return}if(l.status==="failed"||l.status==="cancelled"){h(null),y(!1);try{window.localStorage.removeItem(U)}catch{}T(String(l.error||"That change could not be applied â your VirtualTwin is untouched."));return}}h(null),y(!1),T("That change is taking longer than expected. It may still be running â check back in a few minutes.")};s.useEffect(()=>{try{const k=window.localStorage.getItem(q);k&&C(JSON.parse(k))}catch{}let x=null;try{x=window.localStorage.getItem(U)}catch{}if(x)try{const k=JSON.parse(x);k!=null&&k.buildId&&J(k.buildId,k.startedAt)}catch{}},[a]),s.useEffect(()=>{const x=L.current;x&&(x.style.height="auto",x.style.height=`${Math.min(x.scrollHeight,320)}px`)},[t]),s.useEffect(()=>{if(!u)return;const x=window.setInterval(()=>P(k=>k+1),1e3);return()=>window.clearInterval(x)},[u]);const M=async x=>{const{data:{session:k}}=await R.auth.getSession(),V=await bt({action:"twinRefine",twin_id:a,instruction:x,twin_name:n||null,owner_token:(k==null?void 0:k.access_token)||null});if(V!=null&&V.error||!(V!=null&&V.build_id)){if((V==null?void 0:V.error)==="no_kept_source"){w(!0),T("This app was built before BlueprintX started keeping its source, so there's nothing here to edit yet. Open the Builder to make the change â and from then on changes like this land in minutes.");return}T(String((V==null?void 0:V.message)||"I couldn't start that change â please try again."));return}const Y=String(V.build_id);try{window.localStorage.setItem(U,JSON.stringify({buildId:Y,startedAt:Date.now()}))}catch{}await J(Y)},K=async x=>{const{data:{session:k}}=await R.auth.getSession();if(!(k!=null&&k.access_token)){T("Your session expired â please sign in again.");return}const V=await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/co-builder-revise",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${k.access_token}`},body:JSON.stringify({twinId:a,feedback:x})}),Y=await V.json().catch(()=>({}));if(V.status===402||Y.error==="insufficient_credits"){T("You're out of credits â top up to keep refining.");return}Y.changed?(c(String(Y.message||"Change applied.")),m(""),o()):T(String(Y.message||Y.error||"I couldn't apply that change â try describing it more specifically."))},G=async()=>{const x=t.trim();if(!(!x||u)){y(!0);try{Q?await M(x):W?await te(x):await K(x)}catch{T("Something interrupted that change â nothing was altered. Please try again.")}finally{y(!1)}}};return e.jsxs("div",{className:"rounded-2xl border border-slate-100 dar
37k:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5 sm:p-6",children:[d,e.jsx("p",{className:"text-sm text-slate-500 dark:text-gray-400 leading-relaxed mb-4",children:Q?"Tell it what to change, in plain words â the app you already have is edited in place, so everything you liked stays exactly as it is. A change takes a few minutes and you can keep going forever. Nothing here is ever final.":"Tell it what to change, in plain words â it's applied to this VirtualTwin, and you can keep revising forever. Nothing here is ever final."}),e.jsxs("div",{children:[e.jsx("textarea",{ref:L,value:t,onChange:x=>m(x.target.value),onKeyDown:x=>{x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),G())},disabled:u,rows:3,placeholder:Q?'e.g. "make the header smaller" or "add a Notes box to each entry"':'e.g. "Answer more briefly" or "rename the stages to Cold, Warm, Signed"',className:"w-full px-4 py-3 rounded-xl text-sm leading-relaxed bg-slate-50 dark:bg-gray-900 border border-slate-200 dark:border-gray-700 text-slate-900 dark:text-white placeholder:text-slate-400 dark:placeholder:text-gray-500 focus:outline-none focus:border-[#ff2e7c]/50 resize-none overflow-y-auto",style:{minHeight:84,maxHeight:320}}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-[11.5px] text-slate-400 dark:text-gray-500",children:t.trim()?`${t.trim().split(/\s+/).length} words · Shift+Enter for a new line`:"Enter sends · Shift+Enter for a new line"}),e.jsx("button",{onClick:G,disabled:u||!t.trim(),className:"shrink-0 inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold text-white bpx-accent-bg shadow-[0_4px_16px_rgba(255,46,124,0.25)] hover:opacity-95 transition-opacity disabled:opacity-50 disabled:cursor-not-allowed",children:u?"Shapingâ¦":"Apply"})]})]}),N&&!v&&e.jsx("div",{className:"mt-4 rounded-2xl p-5",style:{background:"#FFFFFF",border:"1px solid #ECE9E3"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center shrink-0",style:{background:N.live?"#EAF8EE":"#FFF6E5"},children:N.live?e.jsx(De,{className:"w-5 h-5",style:{color:"#34C759"}}):e.jsx(ue,{className:"w-5 h-5",style:{color:"#FF9500"}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[17px] font-semibold tracking-tight text-slate-900 dark:text-white",children:N.live?"Your change is live.":"Your change is saved."}),e.jsx("p",{className:"mt-1 text-[13.5px] leading-snug text-slate-500 dark:text-gray-400",children:N.live?"Everything else stayed exactly as it was. Open it and take a look.":"It's safely saved and you can see it in the preview â it just hasn't gone live yet. Press Apply again to publish it."}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[N.live&&N.appUrl&&e.jsxs("a",{href:N.appUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 rounded-2xl px-5 py-2.5 text-[14px] font-semibold text-white bpx-accent-bg hover:opacity-95 transition-opacity",children:["Open your VirtualTwin",e.jsx(Ie,{className:"w-4 h-4"})]}),e.jsx("button",{onClick:()=>{C(null);try{window.localStorage.removeItem(q)}catch{}},className:"text-[13px] font-medium text-slate-400 hover:text-slate-600 transition-colors",children:"Make another change"})]})]})]})}),v&&e.jsxs("div",{className:"mt-3 rounded-xl border border-slate-200 dark:border-gray-700 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-slate-50 dark:bg-gray-800/60",children:[e.jsx(ke,{className:"w-4 h-4 shrink-0 bpx-accent-text animate-pulse"}),e.jsx("span",{className:"text-sm font-medium text-slate-800 dark:text-gray-100 flex-1",children:v}),O&&e.jsx("span",{className:"text-[11px] tabular-nums text-slate-400",title:"How long this change has been running",children:(()=>{const x=Math.max(0,Math.floor((Date.now()-O)/1e3))+F*0;return`${Math.floor(x/60)}:${String(x%60).padStart(2,"0")}`})()})]}),E.length>1&&e.jsx("ul",{className:"max-h-40 overflow-y-auto px-3 py-2 space-y-1",children:E.slice(-8,-1).reverse().map((x,k)=>e.jsx("li",{className:"text-[12px] leading-snug text-slate-500 dark:text-gray-400",children:x},`${k}-${x.slice(0,18)}`))}),D&&e.jsxs("div",{className:"border-t border-slate-200 dark:border-gray-700",children:[e.jsxs("div",{className:"px-3 py-1.5 text-[11px] text-slate-400 flex items-center justify-between",children:[e.jsx("span",{children:"Live preview â updating as it works"}),e.jsx("a",{href:D,target:"_blank",rel:"noreferrer",className:"bpx-accent-text font-semibold",children:"Open â"})]}),e.jsx("iframe",{src:D,title:"Live preview of your change",className:"w-full bg-white",style:{height:320,border:0}})]})]}),f&&e.jsxs("button",{onClick:()=>g(`/cobuilder?twin=${a}`),className:"mt-3 inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold text-white bpx-accent-bg shadow-[0_4px_16px_rgba(255,46,124,0.25)] hover:opacity-95 transition-opacity",children:["Open the Builder",e.jsx(Ie,{className:"w-4 h-4"})]}),_.length>0&&e.jsx("ul",{className:"mt-4 space-y-2",children:_.map((x,k)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[x.kind==="applied"?e.jsx(De,{className:"w-4 h-4 mt-0.5 shrink-0 text-emerald-500"}):e.jsx(ue,{className:"w-4 h-4 mt-0.5 shrink-0 text-amber-500"}),e.jsx("span",{className:x.kind==="applied"?"text-slate-700 dark:text-gray-200":"text-slate-500 dark:text-gray-400",children:x.text})]},`${_.length-k}`))}),e.jsx("p",{className:"mt-3 text-[11px] text-slate-400 dark:text-gray-500",children:W?"Runs on your computer, on your own AI account â free.":Q?"Each change uses a small amount of AI from your credits. Leaving this page will not stop it.":"Eac
37h applied change uses a small amount of AI â about 1â2¢ of your credits."})]})};function wt(){const a=window.blueprintx;return a&&typeof a.localBuildCall=="function"&&typeof a.localBuildAvailable=="function"?a:null}const qs=({twinId:a,twinName:i})=>{const[n,o]=s.useState(!1),[g,t]=s.useState(!1),[m,u]=s.useState(!1),[y,_]=s.useState(!1),[p,v]=s.useState(null),h=s.useCallback(async()=>{const w=wt();if(!w||!await w.localBuildAvailable().then(O=>!!(O!=null&&O.available)).catch(()=>!1))return;const S=await w.localBuildCall({action:"templateStatus",twin_id:a}).catch(()=>null);!S||S.error||(o(!!S.behind),t(!!S.can_update))},[a]);s.useEffect(()=>{h()},[h]);const f=async()=>{u(!0),v(null);try{const w=await wt().localBuildCall({action:"templateUpdate",twin_id:a});if(w!=null&&w.error){v(w.error==="no_kept_source"?"This one was built before BlueprintX started keeping its source, so it can't be updated in place. Rebuilding it once will fix that for good.":String(w.message||"Couldn't update it just now."));return}_(!0),o(!1)}catch{v("Couldn't update it just now.")}finally{u(!1)}};return y?e.jsxs("div",{className:"mt-6 rounded-2xl border border-emerald-100 dark:border-emerald-900/40 bg-emerald-50/60 dark:bg-emerald-950/20 p-4 flex items-start gap-2.5",children:[e.jsx(Z,{className:"w-4 h-4 mt-0.5 shrink-0 text-emerald-600"}),e.jsxs("p",{className:"text-sm text-emerald-900 dark:text-emerald-200",children:[i||"Your VirtualTwin"," now has the latest abilities. Nothing you built was changed."]})]}):!n||!g?null:e.jsx("div",{className:"mt-6 rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5 sm:p-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center text-white shrink-0",style:{background:"linear-gradient(120deg, #ff2e7c, #ff8a38)"},children:e.jsx(Bs,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-slate-900 dark:text-white",children:"There's an update for this VirtualTwin"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-gray-400 leading-relaxed",children:"New abilities have been added to BlueprintX since this one was built. Picking them up takes a minute or two, and nothing you shaped about it changes â only the parts BlueprintX provides."}),p&&e.jsx("p",{className:"mt-2 text-sm text-amber-700 dark:text-amber-400",children:p}),e.jsx("button",{onClick:f,disabled:m,className:"mt-4 inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold text-white bpx-accent-bg shadow-[0_4px_16px_rgba(255,46,124,0.25)] hover:opacity-95 transition-opacity disabled:opacity-50",children:m?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4 animate-spin"})," Updatingâ¦"]}):e.jsx(e.Fragment,{children:"Update it"})})]})]})})},zs=({twinId:a,twinName:i,isPublic:n,price:o,onListed:g})=>{const[t,m]=s.useState(!1),[u,y]=s.useState(""),_=async p=>{if(t)return;m(!0),y("");const{error:v}=await R.from("virtual_twins").update({is_public:p}).eq("id",a);if(m(!1),v){y("That didn't save â please try again.");return}g()};return e.jsxs("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center text-white bpx-accent-bg shrink-0",children:e.jsx(ut,{className:"w-4 h-4"})}),e.jsx("span",{className:"bpx-display text-lg uppercase text-slate-900 dark:text-white",children:n?"Rented out":"Rent it out"})]}),n?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-slate-500 dark:text-gray-400 leading-relaxed mb-4",children:[i," is listed. People can rent it",o?` for $${o}`:" for free",", and it answers from what you've taught it â without that ever leaving here."]}),e.jsxs("button",{onClick:()=>_(!1),disabled:t,className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold text-slate-500 dark:text-gray-400 border border-slate-200 dark:border-gray-700 hover:text-slate-700 dark:hover:text-gray-200 transition-colors disabled:opacity-50",children:[t?e.jsx(ne,{className:"w-4 h-4 animate-spin"}):null,"Stop renting it out"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-slate-500 dark:text-gray-400 leading-relaxed mb-4",children:["Let other people use ",i,". It runs on their computer, so it costs you nothing â however many people rent it."]}),e.jsxs("div",{className:"rounded-xl bg-slate-50 dark:bg-gray-900 p-4 mb-5 space-y-2.5",children:[e.jsxs(qe,{good:!0,children:[e.jsx("b",{children:"What you've taught it stays here."})," Only the lines that answer someone's question are looked up â never your documents."]}),e.jsxs(qe,{good:!0,children:[e.jsx("b",{children:"Your accounts stay yours."})," If it does things, it does them on the renter's own logins, on their machine â never through yours."]}),e.jsxs(qe,{children:[e.jsx("b",{children:"Its voice travels with it."})," Its name, tone and manner go wherever it goes â nothing can speak without those."]})]}),e.jsxs("button",{onClick:()=>_(!0),disabled:t,className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold text-white bpx-accent-bg shadow-[0_4px_16px_rgba(255,46,124,0.25)] hover:opacity-95 transition-opacity disabled:opacity-50 disabled:cursor-not-allowed",children:[t?e.jsx(ne,{className:"w-4 h-4 animate-spin"}):e.jsx(ut,{className:"w-4 h-4"}),t?"Listingâ¦":"Rent it out"]}),e.jsx("p",{className:"mt-3 text-[11px] text-slate-400 dark:text-gray-500",children:"Set a price in Edit if you want to charge. You can stop renting it out at any time."})]}),u&&e.jsxs("p",{className:"mt-3 flex items-start gap-2 text-sm text-amber-600 dar
37k:text-amber-400",children:[e.jsx(ue,{className:"w-4 h-4 mt-0.5 shrink-0"})," ",u]})]})},qe=({good:a,children:i})=>e.jsxs("p",{className:"flex items-start gap-2 text-[13.5px] leading-relaxed text-slate-500 dark:text-gray-400",children:[a?e.jsx(Z,{className:"w-3.5 h-3.5 mt-1 shrink-0 text-emerald-500"}):e.jsx("span",{className:"w-3.5 h-3.5 mt-1 shrink-0 rounded-full border border-slate-300 dark:border-gray-600"}),e.jsx("span",{children:i})]});function jt(){const a=window.blueprintx;return a&&typeof a.localBuildCall=="function"&&typeof a.localBuildAvailable=="function"?a:null}const Ws=({twinId:a,twinName:i,isPublished:n})=>{const[o,g]=s.useState(!1),[t,m]=s.useState(!1),[u,y]=s.useState(null),[_,p]=s.useState(null),v=s.useCallback(async()=>{const f=jt();f&&g(await f.localBuildAvailable().then(w=>!!(w!=null&&w.available)).catch(()=>!1))},[]);s.useEffect(()=>{v()},[v]);const h=async f=>{m(!0),p(null),y(null);try{const{data:{session:w}}=await R.auth.getSession();if(!(w!=null&&w.access_token)){p("Your session expired â please sign in again.");return}const E=await jt().localBuildCall({action:f==="down"?"twinMakeLocal":"twinPublish",twin_id:a,twin_name:i||null,user_id:w.user.id,owner_token:w.access_token});if(E!=null&&E.error){p(E.error==="no_kept_source"?"This one was built before BlueprintX kept editable source, so it can't be moved in place yet. Refining it once fixes that for good.":String(E.message||"Couldn't move it just now."));return}y(f==="down"?`${i||"It"} is coming down to this computer â a minute or two.`:`${i||"It"} is going to your library â a minute or two.`)}catch{p("Couldn't move it just now.")}finally{m(!1)}};return o?e.jsx("div",{className:"mt-6 rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5 sm:p-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-gray-800 flex items-center justify-center text-slate-500 shrink-0",children:n?e.jsx(ve,{className:"w-5 h-5"}):e.jsx(xt,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-slate-900 dark:text-white",children:"Where it lives"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-gray-400 leading-relaxed",children:n?"In your library â you can open it on any device, and anyone with the link can too. Bring it down and it runs from this computer alone, reachable by nobody else.":"On this computer alone â not on our servers, and nobody else can reach it. Put it in your library to open it from anywhere."}),e.jsx("p",{className:"mt-2 text-[12.5px] text-slate-400 dark:text-gray-500",children:"Either way it moves as it is â nothing is rebuilt from scratch and nothing you shaped changes."}),u?e.jsxs("p",{className:"mt-4 flex items-start gap-2 text-sm text-emerald-700 dark:text-emerald-300",children:[e.jsx(Z,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsx("span",{children:u})]}):e.jsx("button",{onClick:()=>h(n?"down":"up"),disabled:t,className:"mt-4 inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold text-white bpx-accent-bg shadow-[0_4px_16px_rgba(255,46,124,0.25)] hover:opacity-95 transition-opacity disabled:opacity-50",children:t?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4 animate-spin"})," Movingâ¦"]}):n?e.jsxs(e.Fragment,{children:[e.jsx(xt,{className:"w-4 h-4"})," Keep it on this computer only"]}):e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"w-4 h-4"})," Put it in my library"]})}),_&&e.jsx("p",{className:"mt-3 text-sm text-amber-700 dark:text-amber-400",children:_})]})]})}):null},Hs=({twinId:a})=>{const[i,n]=s.useState(!1),[o,g]=s.useState(null);return s.useEffect(()=>{!i||o!==null||(async()=>{try{const{data:t}=await R.from("co_builder_sessions").select("id").eq("generated_twin_id",a).order("updated_at",{ascending:!1}).limit(5),m=(t||[]).map(y=>y.id);if(!m.length){g([]);return}const{data:u}=await R.from("co_builder_messages").select("content, created_at, role").in("session_id",m).eq("role","user").order("created_at",{ascending:!0}).limit(50);g((u||[]).map(y=>({content:y.content,created_at:y.created_at})))}catch{g([])}})()},[i,o,a]),e.jsxs("div",{className:"rounded-2xl border border-slate-100 dar
37k:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>n(t=>!t),"aria-expanded":i,className:"w-full flex items-center justify-between px-5 py-4 text-left hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(It,{className:"w-4 h-4 text-slate-400 dark:text-gray-500"}),e.jsx("span",{className:"bpx-display text-lg uppercase text-slate-400 dark:text-gray-500",children:"Build notes"}),e.jsx("span",{className:"text-xs text-slate-400 dark:text-gray-500",children:"everything you've told the Builder"})]}),e.jsx(be,{className:`w-4 h-4 text-slate-400 dark:text-gray-500 transition-transform ${i?"rotate-90":""}`})]}),i&&e.jsxs("div",{className:"px-5 pb-4 border-t border-slate-100 dark:border-gray-800/60 max-h-[320px] overflow-y-auto",children:[o===null&&e.jsx("p",{className:"text-sm text-slate-400 pt-3",children:"Loadingâ¦"}),o!==null&&o.length===0&&e.jsx("p",{className:"text-sm text-slate-400 pt-3",children:"No saved Builder conversations found for this VirtualTwin yet."}),(o||[]).map((t,m)=>e.jsxs("div",{className:"pt-3",children:[e.jsx("p",{className:"text-[11px] text-slate-400 dark:text-gray-500",children:new Date(t.created_at).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}),e.jsx("p",{className:"text-sm text-slate-700 dark:text-gray-200 whitespace-pre-wrap leading-relaxed",children:t.content})]},m))]})]})},Ys=es(a=>({loading:!1,error:null})),Js=({twinId:a,canEdit:i=!0})=>{const{sources:n,schedules:o,updates:g,loading:t,error:m,fetchSources:u,createSource:y,updateSource:_,deleteSource:p,toggleSourceActive:v,fetchSchedules:h,updateSchedule:f,fetchUpdates:w,triggerManualUpdate:E}=Ys(),[S,O]=s.useState(!1),[B,D]=s.useState(null),[j,F]=s.useState(null),[P,U]=s.useState(!1),[q,N]=s.useState(!1),[C,L]=s.useState({source_type:"url",source_url:"",source_name:"",source_description:"",is_active:!0}),[W,Q]=s.useState({frequency:"daily",status:"active"});s.useEffect(()=>{u(a),n.length===0&&O(!0)},[a,u,n.length]),s.useEffect(()=>{j&&(h(j),q&&w(j))},[j,q,h,w]);const d=async l=>{l.preventDefault(),B?(await _(B,{source_type:C.source_type,source_url:C.source_url,source_name:C.source_name||null,source_description:C.source_description||null,is_active:C.is_active}),D(null)):await y({twin_id:a,source_type:C.source_type,source_url:C.source_url,source_name:C.source_name||null,source_description:C.source_description||null,config:{},is_active:C.is_active}),x()},c=l=>{L({source_type:l.source_type,source_url:l.source_url,source_name:l.source_name||"",source_description:l.source_description||"",is_active:l.is_active}),D(l.id),O(!0)},T=async l=>{window.confirm("Are you sure you want to delete this data source? All associated schedules and updates will also be deleted.")&&(await p(l),j===l&&(F(null),U(!1),N(!1)))},te=async(l,b)=>{await v(l,!b)},J=l=>{F(l),U(!0),N(!1)},M=async()=>{if(!j)return;const l=o.find(b=>b.source_id===j);l&&await f(l.id,{frequency:W.frequency,status:W.status,next_run:K(W.frequency)})},K=l=>{const b=new Date;switch(l){case"hourly":b.setHours(b.getHours()+1);break;case"12h":b.setHours(b.getHours()+12);break;case"daily":b.setDate(b.getDate()+1);break;case"weekly":b.setDate(b.getDate()+7);break;case"monthly":b.setMonth(b.getMonth()+1);break}return b.toISOString()},G=async l=>{await E(l)},x=()=>{L({source_type:"url",source_url:"",source_name:"",source_description:"",is_active:!0}),O(!1),D(null)},k=l=>{switch(l){case"api":return e.jsx(Ce,{className:"h-5 w-5 text-blue-500"});case"url":return e.jsx(ve,{className:"h-5 w-5 text-green-500"});case"doc":return e.jsx(It,{className:"h-5 w-5 text-purple-500"});case"youtube":return e.jsx(ys,{className:"h-5 w-5 text-red-500"});case"rss":return e.jsx(Os,{className:"h-5 w-5 text-orange-500"});default:return e.jsx(Ce,{className:"h-5 w-5 text-gray-500"})}},V=l=>{switch(l){case"hourly":return"Every hour";case"12h":return"Every 12 hours";case"daily":return"Daily";case"weekly":return"Weekly";case"monthly":return"Monthly";default:return l}},Y=l=>{switch(l){case"active":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"paused":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";
37case"error":return"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300";case"pending":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"processed":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";default:return"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300"}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Live Data Sources"}),i&&!S&&e.jsxs($,{onClick:()=>O(!0),className:"flex items-center gap-2",children:[e.jsx(ze,{className:"w-4 h-4"}),"Add Source"]})]}),m&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-800 dark:text-red-200",children:[e.jsx(Se,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium",children:"Error"})]}),e.jsx("p",{className:"text-red-700 dark:text-red-300 text-sm mt-1",children:m})]}),S&&i&&e.jsxs(ce,{className:"p-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h4",{className:"text-lg font-medium text-gray-900 dark:text-white",children:B?"Edit Data Source":"Add Data Source"}),e.jsx($,{variant:"ghost",size:"sm",onClick:x,className:"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200",children:e.jsx(ye,{className:"w-4 h-4"})})]}),e.jsxs("form",{onSubmit:d,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Source Type"}),e.jsxs("select",{value:C.source_type,onChange:l=>L({...C,source_type:l.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:[e.jsx("option",{value:"url",children:"Website URL"}),e.jsx("option",{value:"api",children:"API Endpoint"}),e.jsx("option",{value:"rss",children:"RSS Feed"}),e.jsx("option",{value:"youtube",children:"YouTube Channel"}),e.jsx("option",{value:"doc",children:"Document URL"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Source URL"}),e.jsx("input",{type:"url",value:C.source_url,onChange:l=>L({...C,source_url:l.target.value}),placeholder:C.source_type==="url"?"https://example.com/blog":C.source_type==="api"?"https://api.example.com/data":C.source_type==="rss"?"https://example.com/feed.xml":C.source_type==="youtube"?"https://youtube.com/channel/...":"https://example.com/document.pdf",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-white",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Source Name (Optional)"}),e.jsx("input",{type:"text",value:C.source_name,onChange:l=>L({...C,source_name:l.target.value}),placeholder:"Company Blog",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Description (Optional)"}),e.jsx("textarea",{value:C.source_description,onChange:l=>L({...C,source_description:l.target.value}),placeholder:"What kind of information does this source provide?",rows:3,className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-white"})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",id:"is_active",checked:C.is_active,onChange:l=>L({...C,is_active:l.target.checked}),className:"h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:border-gray-600 dark:bg-gray-700"}),e.jsx("label",{htmlFor:"is_active",className:"ml-2 block text-sm text-gray-900 dark:text-gray-300",children:"Active (source will be updated according to schedule)"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx($,{type:"submit",disabled:t,className:"flex items-center gap-2",children:B?"Update Source":"Add Source"}),e.jsx($,{type:"button",variant:"outline",onClick:x,children:"Cancel"})]})]})]}),e.jsx("div",{className:"space-y-4",children:t&&n.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"Loading data sources..."}):n.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:["No data sources yet. ",i?"Add some sources to keep this twin updated with fresh information.":"The owner has not added any data sources yet."]}):e.jsx("div",{className:"grid grid-cols-1 gap-4",children:n.map(l=>e.jsx(ce,{className:`overflow-hidden ${j===l.id?"border-primary-500 dark:border-primary-400":""}`,children:e.jsxs(ge,{className:"p-0",children:[e.jsxs("div",{className:"p-4 flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1",children:[e.jsx("div",{className:"text-gray-500 dark:text-gray-400 mt-1",children:k(l.source_type)}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:"font-medium text-gray-900 dark:text-white",children:l.source_name||l.source_url.split("/")[2]||"Unnamed Source"}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${Y(l.is_active?"active":"paused")}`,children:l.is_active?"Active":"Paused"})]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-2",children:l.source_description||`${l.source_type.toUpperCase()} source`}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 flex items-center",children:[e.jsx(ve,{className:"h-3 w-3 mr-1"}),e.jsx("a",{href:l.source_url,target:"_blank",rel:"noopener noreferrer",className:"hover:underline text-primary-600 dark:text-primary-400",onClick:b=>b.stopPropagation(),children:l.source_url})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx($,{variant:"ghost",size:"sm",onClick:()=>te(l.id,l.is_active),title:l.is_active?"Pause updates":"Resume updates",children:l.is_active?e.jsx(Ps,{className:"h-5 w-5 text-green-500"}):e.jsx(Fs,{className:"h-5 w-5 text-gray-400"})}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>G(l.id),title:"Update now",children:e.jsx(_e,{className:"h-4 w-4"})}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>c(l),title:"Edit source",children:e.jsx(Ot,{className:"h-4 w-4"})}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>T(l.id),className:"text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20",title:"Delete source",children:e.jsx(Te,{className:"h-4 w-4"})})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>J(l.id),title:"View details",children:e.jsx(ts,{className:"h-4 w-4"})})]})]}),j===l.id&&P&&e.jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 p-4 bg-gray-50 dark:bg-gray-800",children:[e.jsxs("h5",{className:"font-medium text-gray-900 dark:text-white mb-3 flex items-center",children:[e.jsx(We,{className:"h-4 w-4 mr-2 text-gray-500 dark:text-gray-400"}),"Update Schedule"]}),o.length>0?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Update Frequency"}),e.jsxs("select",{value:W.frequency,onChange:b=>Q({...W,frequency:b.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white sm:text-sm",disabled:!i,children:[e.jsx("option",{value:"hourly",children:"Every hour"}),e.jsx("option",{value:"12h",children:"Every 12 hours"}),e.jsx("option",{value:"daily",children:"Daily"}),e.jsx("option",{value:"weekly",children:"Weekly"}),e.jsx("option",{value:"monthly",children:"Monthly"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Status"}),e.jsxs("select",{value:W.status,onChange:b=>Q({...W,status:b.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white sm:text-sm",disabled:!i,children:[e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"paused",children:"Paused"})]})]})]}),o.map(b=>e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-3 rounded-md shadow-sm",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(Nt,{className:"h-4 w-4 text-gray-500 dark:text-gray-400 mr-2"}),e.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:V(b.frequency)})]}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${Y(b.status)}`,children:b.status})]}),e.jsxs("div",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400 grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Last run:"}
37)," ",b.last_run?new Date(b.last_run).toLocaleString():"Never"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Next run:"})," ",b.next_run?new Date(b.next_run).toLocaleString():"Not scheduled"]})]}),b.error_message&&e.jsxs("div",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:[e.jsx(Se,{className:"h-3 w-3 inline mr-1"}),b.error_message]})]},b.id)),i&&e.jsx("div",{className:"flex justify-end",children:e.jsxs($,{onClick:M,size:"sm",className:"flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"Update Schedule"]})})]}):e.jsx("div",{className:"text-center py-4 text-gray-500 dark:text-gray-400",children:"No schedule found for this source."}),e.jsxs("div",{className:"mt-4 flex justify-between",children:[e.jsx($,{variant:"ghost",size:"sm",onClick:()=>N(!q),className:"flex items-center gap-2",children:q?"Hide Updates":"View Updates"}),i&&e.jsxs($,{size:"sm",onClick:()=>G(l.id),className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),"Update Now"]})]})]}),j===l.id&&q&&e.jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 p-4 bg-gray-50 dark:bg-gray-800",children:[e.jsxs("h5",{className:"font-medium text-gray-900 dark:text-white mb-3 flex items-center",children:[e.jsx(Ce,{className:"h-4 w-4 mr-2 text-gray-500 dark:text-gray-400"}),"Recent Updates"]}),g.length>0?e.jsx("div",{className:"space-y-3",children:g.map(b=>e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-3 rounded-md shadow-sm",children:[e.jsx("div",{className:"flex justify-between items-start",children:e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center mb-1",children:[e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${Y(b.status)}`,children:b.status}),e.jsx("span",{className:"ml-2 text-xs text-gray-500 dark:text-gray-400",children:new Date(b.created_at).toLocaleString()})]}),e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300 mt-1",children:e.jsxs("div",{className:"max-h-24 overflow-y-auto bg-gray-50 dark:bg-gray-800 p-2 rounded text-xs font-mono",children:[b.content.substring(0,200),b.content.length>200&&"..."]})})]})}),b.error_message&&e.jsxs("div",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:[e.jsx(Se,{className:"h-3 w-3 inline mr-1"}),b.error_message]})]},b.id))}):e.jsx("div",{className:"text-center py-4 text-gray-500 dark:text-gray-400",children:"No updates found for this source."})]})]})},l.id))})})]})},Ks=({twinId:a,isOwner:i})=>{const{managers:n,loading:o,error:g,fetchTwinManagers:t,addTwinManager:m,updateTwinManagerRole:u,removeTwinManager:y,searchUsers:_}=Et(),[p,v]=s.useState(!1),[h,f]=s.useState(""),[w,E]=s.useState("editor"),[S,O]=s.useState(null),[B,D]=s.useState("editor"),[j,F]=s.useState([]),[P,U]=s.useState(!1),[q,N]=s.useState(!1);s.useEffect(()=>{t(a)},[a,t]);const C=async()=>{if(h){U(!0);try{const c=await _(h);F(c)}catch(c){console.error("Error searching users:",c)}finally{U(!1)}}},L=async c=>{N(!0);try{await m(a,c,w),v(!1),f(""),F([])}catch(T){console.error("Error adding manager:",T)}finally{N(!1)}},W=async()=>{if(S){N(!0);try{await u(S,B),O(null)}catch(c){console.error("Error updating role:",c)}finally{N(!1)}}},Q=async c=>{if(window.confirm("Are you sure you want to remove this manager?")){N(!0);try{await y(c)}catch(T){console.error("Error removing manager:",T)}finally{N(!1)}}},d=c=>{O(c.id),D(c.role)};return e.jsxs(ce,{children:[e.jsxs(Bt,{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white flex items-center",children:[e.jsx(pt,{className:"h-5 w-5 mr-2 text-gray-500 dark:text-gray-400"}),"Twin Managers"]}
37),i&&!p&&e.jsx($,{onClick:()=>v(!0),size:"sm",leftIcon:e.jsx(ze,{className:"h-4 w-4"}),children:"Add Manager"})]}),e.jsxs(ge,{className:"p-0",children:[g&&e.jsx("div",{className:"p-4 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 text-sm",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Se,{className:"h-4 w-4 mr-2"}),e.jsx("span",{children:g})]})}),p&&e.jsxs("div",{className:"p-4 border-b border-gray-200 dark:border-gray-700",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900 dark:text-white mb-3",children:"Add New Manager"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Search User by Email"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"email",value:h,onChange:c=>f(c.target.value),placeholder:"Enter email address",className:"flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white sm:text-sm"}),e.jsx($,{onClick:C,disabled:!h||P,isLoading:P,leftIcon:e.jsx(bs,{className:"h-4 w-4"}),children:"Search"})]})]}),j.length>0&&e.jsx("div",{className:"border border-gray-200 dark:border-gray-700 rounded-md overflow-hidden",children:j.map(c=>{var T;return e.jsxs("div",{className:"p-3 hover:bg-gray-50 dark:hover:bg-gray-750 flex items-center justify-between border-b border-gray-200 dark:border-gray-700 last:border-b-0",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-gray-100 dark:bg-gray-700 flex items-center justify-center text-gray-600 dark:text-gray-300 font-semibold",children:(((T=c.first_name)==null?void 0:T[0])||c.email[0]).toUpperCase()}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:[c.first_name," ",c.last_name]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:c.email})]})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>L(c.id),leftIcon:e.jsx(ws,{className:"h-4 w-4"}),children:"Add"})]},c.id)})}),j.length===0&&h&&!P&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No users found with that email."}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Role"}),e.jsxs("select",{value:w,onChange:c=>E(c.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white sm:text-sm",children:[e.jsx("option",{value:"manager",children:"Manager (Full Access)"}),e.jsx("option",{value:"editor",children:"Editor (Limited Access)"})]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Managers can add/remove knowledge and manage other editors. Editors can only add/edit knowledge."})]}),e.jsx("div",{className:"flex justify-end space-x-2",children:e.jsx($,{type:"button",variant:"ghost",onClick:()=>{v(!1),f(""),F([])},disabled:q,children:"Cancel"})})]})]}),e.jsx("div",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:o&&n.length===0?e.jsxs("div",{className:"p-4 text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-primary-600 mx-auto"}),e.jsx("p",{className:"mt-2 text-sm text-gray-500 dark:text-gray-400",children:"Loading managers..."})]}):n.length>0?n.map(c=>{var T,te,J,M,K,G,x;return e.jsx("div",{className:"p-4 hover:bg-gray-50 dark:hover:bg-gray-750",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-gray-100 dark:bg-gray-700 flex items-center justify-center text-gray-600 dark:text-gray-300 font-semibold",children:(((te=(T=c.user)==null?void 0:T.first_name)==null?void 0:te[0])||((M=(J=c.user)==null?void 0:J.email)==null?void 0:M[0])||"U").toUpperCase()}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:[(K=c.user)==null?void 0:K.first_name," ",(G=c.user)==null?void 0:G.last_name]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(Ye,{className:"h-3 w-3 text-gray-400 mr-1"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:(x=c.user)==null?void 0:x.email})]})]})]}),e.jsx("div",{className:"flex items-center",children:S===c.id?e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("select",{value:B,onChange:k=>D(k.target.value),className:"px-2 py-1 text-sm border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white",children:[e.jsx("option",{value:"manager",children:"Manager"}),e.jsx("option",{value:"editor",children:"Editor"})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:W,disabled:q,isLoading:q,children:e.jsx(Z,{className:"h-4 w-4 text-green-500"})}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>O(null),disabled:q,children:e.jsx(ye,{className:"h-4 w-4 text-red-500"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${c.role==="manager"?"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300":"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300"}`,children:c.role}),i&&e.jsxs("div",{className:"ml-2 flex space-x-1",children:[e.jsx($,{variant:"ghost",size:"sm",onClick:()=>d(c),children:e.jsx(Ot,{className:"h-4 w-4 text-gray-500"})}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>Q(c.id),disabled:q,children:e.jsx(Te,{className:"h-4 w-4 text-red-500"})})]})]})})]})},c.id)}):e.jsxs("div",{className:"p-4 text-center",children:[e.jsx("div",{className:"mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-gray-100 dark:bg-gray-700",children:e.jsx(pt,{className:"h-6 w-6 text-gray-600 dark:text-gray-400"})}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900 dark:text-white",children:"No managers"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:i?"Add managers to help maintain this twin's knowledge base":"This twin doesn't have any managers yet"}),i&&!p&&e.jsx("div",{className:"mt-6",children:e.jsx($,{onClick:()=>v(!0),size:"sm",leftIcon:e.jsx(ze,{className:"h-4 w-4"}),children:"Add Manager"})})]})})]})]})},Gs=[{key:"private",icon:_t,title:"Only you",sub:"Private â no one else can open or use it."},{key:"members",icon:ss,title:"People you invite",sub:"Only the specific people you add below."},{key:"company",icon:as,title:"Everyone at your company",sub:"Anyone signed in who belongs to your company."},{key:"public",icon:ve,title:"Anyone",sub:"Anyone with the link can chat it."}],Xs=({twinId:a,canManage:i})=>{const[n,o]=s.useState(!0),[g,t]=s.useState("private"),[m,u]=s.useState(null),[y,_]=s.useState([]),[p,v]=s.useState([]),[h,f]=s.useState(null),[w,E]=s.useState(""),[S,O]=s.useState(""),[B,D]=s.useState(!1),[j,F]=s.useState(null),P=s.useCallback(async()=>{o(!0);const{data:d,error:c}=await R.functions.invoke("twin-access",{body:{action:"get_access",twinId:a}});!c&&d&&!d.error&&(t(d.visibility||"private"),u(d.company_id??null),_(d.members??[]),v(d.invites??[])),o(!1)},[a]);s.useEffect(()=>{P()},[P]);const U=d=>{F(d),setTimeout(()=>F(null),3500)};async function q(d){if(!i||h)return;if(d==="company"&&!m){D(!0);return}f("vis");const{data:c,error:T}=await R.functions.invoke("twin-access",{body:{action:"set_visibility",twinId:a,visibility:d}});if(f(null),T||c!=null&&c.error){U((c==null?void 0:c.message)||(c==null?void 0:c.error)||"Could not change that â try again.");return}
37t(d),U(d==="private"?"Locked to just you.":d==="public"?"Anyone with the link can now chat it.":"Access updated.")}async function N(){var J;if(!S.trim())return;f("company");const{data:d,error:c}=await R.functions.invoke("twin-access",{body:{action:"create_company",name:S.trim()}});if(c||d!=null&&d.error){f(null),U((d==null?void 0:d.error)||"Could not create the company.");return}const T=d.company.id,te=await R.functions.invoke("twin-access",{body:{action:"set_visibility",twinId:a,visibility:"company",companyId:T}});if(f(null),te.error||(J=te.data)!=null&&J.error){U("Company created, but could not set access.");return}u(T),t("company"),D(!1),O(""),U(`Everyone at ${d.company.name} can now use it.`)}async function C(){const d=w.trim().toLowerCase();if(!d||h)return;f("invite");const{data:c,error:T}=await R.functions.invoke("twin-access",{body:{action:"invite_member",twinId:a,email:d}});if(f(null),T||c!=null&&c.error){U((c==null?void 0:c.message)||(c==null?void 0:c.error)||"Could not add that person.");return}E(""),c.granted==="invite"?U(`Invite sent to ${d} â they'll get access when they join.`):U(`${d} can now use it.`),P()}async function L(d){f(d);const{data:c,error:T}=await R.functions.invoke("twin-access",{body:{action:"remove_member",twinId:a,userId:d}});if(f(null),T||c!=null&&c.error){U("Could not remove them â try again.");return}_(te=>te.filter(J=>J.user_id!==d)),U("Removed.")}const W=g==="members",Q=d=>[d.first_name,d.last_name].filter(Boolean).join(" ")||d.email||"Member";return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"bpx-display text-lg uppercase text-slate-400 dark:text-gray-500",children:"Who can use it"}),e.jsx("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] overflow-hidden",children:n?e.jsxs("div",{className:"flex items-center gap-3 px-5 py-8 text-slate-400",children:[e.jsx(ne,{className:"w-4 h-4 animate-spin"})," Loading accessâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"divide-y divide-slate-100 dark:divide-gray-800/60",children:Gs.map(({key:d,icon:c,title:T,sub:te})=>{const J=g===d;return e.jsxs("button",{type:"button",disabled:!i||!!h,onClick:()=>q(d),className:`w-full flex items-center gap-4 px-5 py-4 text-left transition-colors ${J?"bg-slate-50 dark:bg-gray-900/50":"hover:bg-slate-50 dark:hover:bg-gray-900/40"} ${!i||h?"cursor-default":"cursor-pointer"}`,children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center shrink-0 ${J?"bpx-accent-bg text-white":"bg-slate-100 dark:bg-gray-800 text-slate-500 dark:text-gray-300"}`,children:e.jsx(c,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900 dark:text-white",children:T}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-gray-400",children:te})]}),J&&(h==="vis"?e.jsx(ne,{className:"w-4 h-4 animate-spin text-slate-400 shrink-0"}):e.jsx(Z,{className:"w-5 h-5 bpx-accent-text shrink-0"}))]},d)})}),B&&e.jsxs("div",{className:"px-5 py-4 border-t border-slate-100 dark:border-gray-800/60 bg-slate-50/60 dark:bg-gray-900/30",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900 dark:text-white mb-1",children:"Name your company"}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-gray-400 mb-3",children:"We'll create it and make you its admin so you can add people."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:S,onChange:d=>O(d.target.value),placeholder:"e.g. Acme Corp",className:"flex-1 rounded-xl border border-slate-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-3 py-2 text-sm text-slate-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-pink-400/40"}),e.jsx("button",{type:"button",disabled:h==="company"||!S.trim(),onClick:N,className:"rounded-xl bpx-accent-bg text-white text-sm font-medium px-4 py-2 disabled:opacity-50 shrink-0",children:h==="company"?e.jsx(ne,{className:"w-4 h-4 animate-spin"}):"Create"}),e.jsx("button",{type:"button",onClick:()=>D(!1),className:"text-sm text-slate-400 px-2 shrink-0",children:"Cancel"})]})]}
37),W&&e.jsxs("div",{className:"border-t border-slate-100 dark:border-gray-800/60 px-5 py-4 space-y-3",children:[i&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"email",value:w,onChange:d=>E(d.target.value),onKeyDown:d=>{d.key==="Enter"&&C()},placeholder:"Invite by emailâ¦",className:"flex-1 rounded-xl border border-slate-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-3 py-2 text-sm text-slate-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-pink-400/40"}),e.jsx("button",{type:"button",disabled:h==="invite"||!w.trim(),onClick:C,className:"rounded-xl bpx-accent-bg text-white text-sm font-medium px-4 py-2 disabled:opacity-50 shrink-0 flex items-center gap-1.5",children:h==="invite"?e.jsx(ne,{className:"w-4 h-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(Ye,{className:"w-4 h-4"})," Invite"]})})]}),y.length===0&&p.length===0?e.jsx("div",{className:"text-xs text-slate-400 py-1",children:"No one added yet â it's just you."}):e.jsxs("div",{className:"space-y-1.5",children:[y.map(d=>e.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-slate-100 dark:bg-gray-800 flex items-center justify-center text-xs font-semibold text-slate-500 dark:text-gray-300 shrink-0",children:Q(d).charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-slate-900 dark:text-white truncate",children:Q(d)}),d.email&&e.jsx("div",{className:"text-xs text-slate-400 truncate",children:d.email})]}),i&&e.jsx("button",{type:"button",onClick:()=>L(d.user_id),disabled:h===d.user_id,className:"text-slate-300 hover:text-red-500 transition-colors shrink-0",title:"Remove",children:h===d.user_id?e.jsx(ne,{className:"w-4 h-4 animate-spin"}):e.jsx(Te,{className:"w-4 h-4"})})]},d.user_id)),p.map(d=>e.jsxs("div",{className:"flex items-center gap-3 py-1.5 opacity-70",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-slate-100 dark:bg-gray-800 flex items-center justify-center shrink-0",children:e.jsx(Ye,{className:"w-4 h-4 text-slate-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-slate-900 dark:text-white truncate",children:d.invite_email}),e.jsx("div",{className:"text-xs text-slate-400",children:"Invited â waiting for them to join"})]})]},d.id))]})]}),e.jsxs("div",{className:"flex items-start gap-2.5 px-5 py-3 border-t border-slate-100 dark:border-gray-800/60 bg-slate-50/50 dark:bg-gray-900/20",children:[e.jsx($t,{className:"w-4 h-4 text-slate-400 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-gray-400 leading-relaxed",children:"Reaching your connected programs always stays limited to people you authorize here â never the public, even if the twin itself is public."})]})]})}),j&&e.jsx("div",{className:"text-xs bpx-accent-text font-medium px-1",children:j}),!i&&!n&&e.jsx("div",{className:"text-xs text-slate-400 px-1",children:"Only the owner or a manager can change who can use this."})]})},Zs=({isOpen:a,onClose:i,twin:n,onSubscribe:o,isLoading:g})=>{const[t,m]=s.useState(!1),u=()=>{o(n.id)},y=()=>{m(!0);const _=localStorage.getItem("goodchain_ref")||"",p=encodeURIComponent(`${window.location.origin}/purchase-success?twin_id=${n.id}&twin_name=${encodeURIComponent(n.name)}&payment_method=goodchain`),v=encodeURIComponent(`${window.location.origin}/marketplace`),h=`https://goodchain.io/checkout?platform=blueprintx&external_product_id=${n.stripe_product_id}&amount=${n.price}&ref=${_}&return_url=${p}&cancel_url=${v}`;window.location.href=h};return e.jsx(St,{children:a&&e.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:e.jsxs("div",{className:"flex min-h-screen items-center justify-center p-4",children:[e.jsx(je.div,{initial:{opacity:0}
37,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black bg-opacity-50",onClick:i}),e.jsxs(je.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-full max-w-md bg-white dark:bg-gray-800 rounded-lg shadow-xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center",children:[n.avatar_url?e.jsx("img",{src:n.avatar_url,alt:n.name,className:"h-10 w-10 rounded-full object-cover mr-3"}):e.jsx("div",{className:"h-10 w-10 rounded-full bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center text-purple-600 dark:text-purple-400 mr-3",children:e.jsx(Ct,{className:"h-6 w-6"})}),e.jsxs("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:["Subscribe to ",n.name]})]}),e.jsx("button",{onClick:i,className:"text-gray-400 hover:text-gray-500 dark:hover:text-gray-300",children:e.jsx(ye,{className:"h-6 w-6"})})]}),e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"text-center mb-4",children:e.jsxs("div",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:["$",n.price.toFixed(2),e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"/month"})]})}),e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-700 rounded-lg p-4 mb-6",children:[e.jsx("h3",{className:"font-medium text-gray-900 dark:text-white mb-2",children:"Subscription access includes:"}),e.jsxs("ul",{className:"space-y-2",children:[e.jsxs("li",{className:"flex items-center text-gray-600 dark:text-gray-300",children:[e.jsx(Z,{className:"h-4 w-4 text-green-500 mr-2 flex-shrink-0"}),"Chat with ",n.name," on BlueprintX"]}),e.jsxs("li",{className:"flex items-center text-gray-600 dark:text-gray-300",children:[e.jsx(Z,{className:"h-4 w-4 text-green-500 mr-2 flex-shrink-0"}),"Use in your own private rooms"]}),e.jsxs("li",{className:"flex items-center text-gray-600 dark:text-gray-300",children:[e.jsx(Z,{className:"h-4 w-4 text-green-500 mr-2 flex-shrink-0"}),"Access to specialized knowledge base"]}),e.jsxs("li",{className:"flex items-center text-gray-600 dark:text-gray-300",children:[e.jsx(Z,{className:"h-4 w-4 text-green-500 mr-2 flex-shrink-0"}),"Unlimited messages"]}),e.jsxs("li",{className:"flex items-center text-gray-600 dark:text-gray-300",children:[e.jsx(Z,{className:"h-4 w-4 text-green-500 mr-2 flex-shrink-0"}),"Cancel anytime"]})]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-3 pt-3 border-t border-gray-200 dark:border-gray-600",children:["For deploying this VirtualTwin to your own channels (website, Discord, API), see the ",e.jsx("strong",{children:"Deploy"})," option."]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:y,disabled:t||g,className:"w-full bg-gradient-to-r from-green-500 to-emerald-600 hover:from-green-600 hover:to-emerald-700 text-white rounded-lg p-4 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(Tt,{className:"h-5 w-5 mr-2"}),e.jsx("span",{className:"font-semibold",children:t?"Redirecting...":"Pay with GoodChain"})]}),e.jsxs("div",{className:"flex items-center justify-center mt-1",children:[e.jsx(ke,{className:"h-3 w-3 mr-1 text-green-200"}),e.jsx("span",{className:"text-sm text-green-100",children:"Save more. Earn rewards."})]})]}),e.jsx($,{onClick:u,fullWidth:!0,variant:"outline",isLoading:g,disabled:t,leftIcon:e.jsx(js,{className:"h-4 w-4"}),children:"Pay with Card"})]}),e.jsxs("div",{className:"flex items-center justify-center mt-4",children:[e.jsx($e,{className:"h-4 w-4 text-gray-400 mr-2"}),e.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Secure payment processing"})]})]}),e.jsx("div",{className:"text-xs text-center text-gray-500 dark:text-gray-400",children:"By subscribing, you agree to our Terms of Service and Privacy Policy. You can cancel your subscription at any time from your account settings."})]})]})]})})})},Qs="'Avenir Next', 'Avenir', -apple-system, 'Helvetica Neue', sans-serif",kt="linear-gradient(120deg, #ff2e7c 0%, #ff8a38 100%)",ea=[{id:"vivavoxx",name:"VivaVoxx · Voice",icon:e.jsx("img",{src:"/vivavoxx-icon-192.png",alt:"
37VivaVoxx",className:"w-6 h-6 rounded-md"}),description:"Talk to it in your own voice",needs:"Opens in VivaVoxx",color:"from-pink-500 to-orange-500"},{id:"website_widget",name:"Website Widget",icon:e.jsx(ve,{className:"w-5 h-5"}),description:"Drop-in chat bubble for any website",needs:"Copy-paste one line of code",color:"from-blue-500 to-cyan-500"},{id:"discord",name:"Discord Bot",icon:e.jsx(cs,{className:"w-5 h-5"}),description:"Responds in Discord servers",needs:"Connect your Discord app",color:"from-indigo-500 to-purple-500"},{id:"telegram",name:"Telegram Bot",icon:e.jsx(Ge,{className:"w-5 h-5"}),description:"Responds in Telegram chats",needs:"Bot token from @BotFather",color:"from-sky-500 to-blue-500"},{id:"api",name:"Custom API",icon:e.jsx(ks,{className:"w-5 h-5"}),description:"Integrate with your own apps",needs:"REST endpoint + API key",color:"from-emerald-500 to-teal-500"},{id:"slack",name:"Slack",icon:e.jsx(vs,{className:"w-5 h-5"}),description:"Posts in your Slack workspace",needs:"Connect Slack workspace",color:"from-pink-500 to-rose-500"},{id:"twitter",name:"Twitter / X",icon:e.jsx(ps,{className:"w-5 h-5"}),description:"Autoposts to your Twitter / X",needs:"Connect your X account",color:"from-gray-700 to-gray-900"}],ta=({isOpen:a,onClose:i,twin:n,currentUserId:o,onDeploymentCreated:g})=>{const[t,m]=s.useState("pick"),[u,y]=s.useState(null),[_,p]=s.useState(!1),[v,h]=s.useState(null),[f,w]=s.useState(null),[E,S]=s.useState(!1),O=Ke(),B=n.user_id===o,D=B?0:n.price||0,j=N=>{if(h(null),N.id==="vivavoxx"){i(),O(`/vivavoxx/${n.id}`);return}y(N),m("confirm")},F=async()=>{if(u){p(!0),h(null);try{const{data:{session:N}}=await R.auth.getSession(),C=await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/deployment-create",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${N==null?void 0:N.access_token}`},body:JSON.stringify({twin_id:n.id,channel:u.id})}),L=await C.json();if(!C.ok||!L.success)throw new Error(L.error||"Deployment failed");if(w(L),L.checkout_url){window.location.href=L.checkout_url;return}m("created"),g&&g({id:L.deployment_id,api_key:L.api_key,channel:L.channel})}catch(N){h(N instanceof Error?N.message:"Deployment failed")}finally{p(!1)}}},P=()=>{f!=null&&f.api_key&&(navigator.clipboard.writeText(f.api_key),S(!0),setTimeout(()=>S(!1),2e3))},U=()=>{m("pick"),y(null),h(null),w(null),p(!1)},q=()=>{U(),i()};return e.jsx(St,{children:a&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{fontFamily:Qs},children:[e.jsx(je.div,{initial:{opacity:0}
37,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/70 backdrop-blur-xl",onClick:q}),e.jsxs(je.div,{initial:{opacity:0,scale:.96,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.96},className:"relative w-full max-w-lg rounded-3xl overflow-hidden",style:{background:"#0a0a0f",border:"1px solid rgba(255,255,255,0.08)"},children:[t==="pick"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-start justify-between p-6 pb-4",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-bold text-white mb-1",style:{letterSpacing:"-0.01em"},children:["Deploy ",n.name]}),e.jsx("p",{className:"text-sm text-gray-400",children:B?"Pick where it runs. Free â this is your twin.":`$${D}/month · Pick where it runs.`})]}),e.jsx("button",{onClick:q,className:"text-gray-500 hover:text-white transition-colors",children:e.jsx(ye,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"px-6 pb-6",children:e.jsx("div",{className:"grid grid-cols-1 gap-2",children:ea.map(N=>e.jsxs("button",{onClick:()=>j(N),className:"flex items-center gap-4 p-4 rounded-2xl border border-white/5 hover:border-white/20 bg-white/[0.02] hover:bg-white/[0.04] transition-all text-left group",children:[e.jsx("div",{className:`bg-gradient-to-br ${N.color} rounded-xl p-2.5 flex-shrink-0 text-white`,children:N.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-semibold text-white text-[15px]",children:N.name}),e.jsx("div",{className:"text-xs text-gray-500 mt-0.5",children:N.description})]}),e.jsx(Ie,{className:"w-4 h-4 text-gray-600 group-hover:text-white group-hover:translate-x-0.5 transition-all flex-shrink-0"})]},N.id))})})]}),t==="confirm"&&u&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-start justify-between p-6 pb-4",children:[e.jsx("button",{onClick:U,className:"text-gray-500 hover:text-white text-sm flex items-center gap-1.5",children:"â Change"}),e.jsx("button",{onClick:q,className:"text-gray-500 hover:text-white",children:e.jsx(ye,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"px-6 pb-6",children:[e.jsx("div",{className:`bg-gradient-to-br ${u.color} rounded-2xl p-4 w-14 h-14 flex items-center justify-center text-white mb-5`,children:u.icon}),e.jsx("h2",{className:"text-2xl font-bold text-white mb-1",style:{letterSpacing:"-0.01em"},children:u.name}),e.jsx("p",{className:"text-[15px] text-gray-400 mb-6",children:u.description}),e.jsxs("div",{className:"bg-white/[0.03] rounded-xl p-4 mb-6 border border-white/5",children:[e.jsxs("div",{className:"flex justify-between items-center mb-3 pb-3 border-b border-white/5",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"VirtualTwin"}),e.jsx("span",{className:"text-sm font-semibold text-white",children:n.name})]}),e.jsxs("div",{className:"flex justify-between items-center mb-3 pb-3 border-b border-white/5",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Channel"}),e.jsx("span",{className:"text-sm font-semibold text-white",children:u.name})]}),e.jsxs("div",{className:"flex justify-between items-center mb-3 pb-3 border-b border-white/5",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Setup"}),e.jsx("span",{className:"text-sm text-white text-right",children:u.needs})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-gray-400",children:"Monthly"}),e.jsx("span",{className:"text-lg font-bold text-white",children:D===0?"Free":`$${D}`})]})]}),v&&e.jsx("div",{className:"bg-red-500/10 border border-red-500/20 rounded-xl p-3 mb-4 text-sm text-red-400",children:v}),e.jsx("button",{onClick:F,disabled:_,className:"w-full py-4 rounded-2xl text-white font-semibold text-[15px] transition-all hover:scale-[1.01] active:scale-[0.99] disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",style:{background:kt,boxShadow:"0 8px 28px rgba(236, 72, 153, 0.3)"},children:_?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-5 h-5 animate-spin"}),"Deploying..."]}):D===0?e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"w-5 h-5"}),"Deploy Now â Free"]}):e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"w-5 h-5"}),"Continue to Checkout"]})}),e.jsx("p",{className:"text-xs text-gray-500 text-center mt-3",children:B?"You can deploy your own VirtualTwin to unlimited channels at no cost.":"Creator earns 97% · Cancel anytime · Your credits, your credentials."})]})]}),t==="created"&&f&&u&&e.jsx("div",{children:e.jsxs("div",{className:"p-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:q,className:"text-gray-500 hover:text-white",children:e.jsx(ye,{className:"w-5 h-5"})})}),e.jsxs("div",{className:"flex flex-col items-center text-center mb-6 mt-2",children:[e.jsx(je.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",stiffness:200},className:"w-16 h-16 rounded-full flex items-center justify-center mb-4",style:{background:kt},children:e.jsx(Z,{className:"w-8 h-8 text-white",strokeWidth:3})}),e.jsx("h2",{className:"text-2xl font-bold text-white mb-1",style:{letterSpacing:"-0.01em"},children:"You're live"}),e.jsxs("p",{className:"text-sm text-gray-400",children:[n.name," is deployed to ",u.name]})]}),e.jsxs("div",{className:"bg-white/[0.03] rounded-xl p-4 mb-4 border border-white/5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Your API Key"}),e.jsx("button",{onClick:P,className:"text-xs text-gray-500 hover:text-white flex items-center gap-1",children:E?e.
37jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-3 h-3 text-emerald-400"})," Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"w-3 h-3"})," Copy"]})})]}),e.jsx("code",{className:"text-xs text-orange-300 font-mono break-all block",children:f.api_key}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"Keep this private. Save it now â you'll see it in Seller Hub later."})]}),e.jsx(sa,{channel:u.id,apiKey:f.api_key,deploymentId:f.deployment_id,twinId:n.id,twinName:n.name}),e.jsx("button",{onClick:q,className:"w-full py-3 rounded-2xl text-white font-semibold mt-4 bg-white/10 hover:bg-white/15 transition-colors",children:"Done"})]})})]})]})})},sa=({channel:a,apiKey:i,deploymentId:n,twinId:o})=>{const[g,t]=s.useState(!1),[m,u]=s.useState(!1),y="https://wqqiillyujpxsgjzgcfz.supabase.co".replace(".supabase.co",".supabase.co/functions/v1"),_=(p,v="chat")=>{navigator.clipboard.writeText(p);const h=v==="badge"?u:t;h(!0),setTimeout(()=>h(!1),2e3)};if(a==="website_widget"){const p=`<script src="https://blueprintx.world/widget/bpx-widget.js" 38 data-api-key="${i}" 39 data-twin-name="Your Agent"><\/script>`,v=`<script src="https://blueprintx.world/widget/bpx-agent-badge.js" 40 data-twin-id="${o}"><\/script>`;return e.jsxs("div",{className:"bg-black/40 rounded-xl p-4 border border-white/5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Embed Code"}),e.jsx("button",{onClick:()=>_(p),className:"text-xs text-gray-500 hover:text-white flex items-center gap-1",children:g?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-3 h-3 text-emerald-400"})," Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"w-3 h-3"})," Copy"]})})]}),e.jsx("pre",{className:"text-[11px] text-gray-300 font-mono whitespace-pre-wrap break-all",children:p}),e.jsxs("p",{className:"text-xs text-gray-500 mt-2",children:["Paste this before ","</body>"," on any page."]}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-white/10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Credentials badge"}),e.jsx("button",{onClick:()=>_(v,"badge"),className:"text-xs text-gray-500 hover:text-white flex items-center gap-1",children:m?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-3 h-3 text-emerald-400"})," Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"w-3 h-3"})," Copy"]})})]}),e.jsx("pre",{className:"text-[11px] text-gray-300 font-mono whitespace-pre-wrap break-all",children:v}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"Shows what this VirtualTwin is proven at, and makes it discoverable to other agents."})]})]})}if(a==="telegram"){const p=`${y}/webhook-telegram?deployment_id=${n}`;return e.jsxs("div",{className:"bg-black/40 rounded-xl p-4 border border-white/5",children:[e.jsx("p",{className:"text-sm text-white font-semibold mb-3",children:"Set up your Telegram bot:"}),e.jsxs("ol",{className:"text-xs text-gray-400 space-y-2 mb-3",children:[e.jsxs("li",{children:["1. Create a bot with ",e.jsx("a",{href:"https://t.me/botfather",target:"_blank",rel:"noopener noreferrer",className:"text-orange-400 hover:underline",children:"@BotFather"})]}),e.jsx("li",{children:"2. Save the bot token in Connect Apps"}),e.jsx("li",{children:"3. Point your bot's webhook to:"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("code",{className:"text-[11px] text-orange-300 font-mono break-all flex-1 mr-2",children:p}),e.jsx("button",{onClick:()=>_(p),className:"text-xs text-gray-500 hover:text-white flex items-center gap-1 flex-shrink-0",children:g?e.jsx(Z,{className:"w-3 h-3 text-emerald-400"}):e.jsx(we,{className:"w-3 h-3"})})]})]})}if(a==="discord"){const p=`${y}/webhook-discord?deployment_id=${n}`;return e.jsxs("div",{className:"bg-black/40 rounded-xl p-4 border border-white/5",children:[e.jsx("p",{className:"text-sm text-white font-semibold mb-3",children:"Set up your Discord bot:"}),e.jsxs("ol",{className:"text-xs text-gray-400 space-y-2 mb-3",children:[e.jsxs("li",{children:["1. Create an app in ",e.jsx("a",{href:"https://discord.com/developers/applications",target:"_blank",rel:"noopener noreferrer",className:"text-orange-400 hover:underline",children:"Discord Developer Portal"})]}),e.jsx("li",{children:"2. Set Interactions Endpoint URL to:"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("code",{className:"text-[11px] text-orange-300 font-mono break-all flex-1 mr-2",children:p}),e.jsx("button",{onClick:()=>_(p),className:"text-xs text-gray-500 hover:text-white flex items-center gap-1 flex-shrink-0",children:g?e.jsx(Z,{className:"w-3 h-3 text-emerald-400"}):e.jsx(we,{className:"w-3 h-3"})})]})]})}if(a==="api"){const p=`curl -X POST ${y}/twin-api \\ 41 -H "Authorization: Bearer ${i}" \\ 42 -H "Content-Type: application/json" \\ 43 -d '{"message":"Hello, twin!"}'`;return e.jsxs("div",{className:"bg-black/40 rounded-xl p-4 border border-white/5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Example Request"}),e.jsx("button",{onClick:()=>_(p),className:"text-xs text-gray-500 hover:text-white flex items-center gap-1",children:g?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-3 h-3 text-emerald-400"})," Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"w-3 h-3"})," Copy"]})})]}),e.jsx("pre",{className:"text-[11px] text-gray-300 font-mono whitespace-pre-wrap",children:p})]})}return e.jsx("div",{className:"bg-black/40 rounded-xl p-4 border border-white/5 text-sm text-gray-400",children:e.jsxs("p",{children:["Head to ",e.jsxs("a",{href:"/seller-hub",className:"text-orange-400 hover:underline inline-flex items-center gap-1",children:["Seller Hub ",e.jsx(Dt,{className:"w-3 h-3"})]})," to manage this deployment."]})})},aa=({itemId:a,itemType:i,onReviewSubmitted:n})=>{const[o,g]=s.useState(0),[t,m]=s.useState(""),[u,y]=s.useState(!1),[_,p]=s.useState(null),{user:v}=Oe(),h=async f=>{var w,E;if(f.preventDefault(),!v){p("You must be logged in to submit a review");return}if(o===0){p("Please select a rating");return}try{y(!0),p(null);const{data:S,error:O}=await R.from("ratings_reviews").select("id").eq("item_id",a).eq("item_type",i).eq("user_id",v.id).maybeSingle();O&&console.warn("Error checking for existing review:",O);try{if(S){const{error:j}=await R.from("ratings_reviews").update({rating:o,review_text:t||null}).eq("id",S.id);if(j)throw j}else{const{error:j}=await R.from("ratings_reviews").insert({item_id:a,item_type:i,user_id:v.id,rating:o,review_text:t||null});if(j)throw j}g(0),m(""),n(),y(!1);return}catch(j){console.warn("Direct database approach failed, falling back to edge function:",j)}const{data:{session:B}}=await R.auth.getSession();if(!(B!=null&&B.access_token))throw new Error("No valid session found");const D=await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/submit-review",{method:"POST",headers:{Authorization:`Bearer ${B.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({itemId:a,itemType:i,rating:o,review:t})});if(!D.ok){const j=await D.json();throw new Error(j.error||"Failed to submit review")}g(0),m(""),n()}catch(S){console.error("Error submitting review:",S),(w=S.message)!=null&&w.includes("duplicate key")||(E=S.message)!=null&&E.includes("23505")?(p("You have already reviewed this item. Your review has been updated."),n()):p(S.message||"Failed to submit review")}finally{y(!1)}};return e.jsxs(ce,{children:[e.jsx(Bt,{children:e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Write a Review"})}),e.jsxs(ge,{children:[_&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md text-red-600 dark:text-red-400 text-sm",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Se,{className:"h-4 w-4 mr-2"}),e.jsx("span",{children:_})]})}),e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Your Rating"}),e.jsx(Je,{rating:o,size:"lg",interactive:!0,onRatingChange:g})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Your Review (Optional)"}),e.jsx("textarea",{value:t,onChange:f=>m(f.target.value),rows:4,maxLength:1e3,placeholder:"Share your experience... (Max 1000 characters)",className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white sm:text-sm"}),e.jsxs("div",{className:"mt-1 flex justify-between",children:[e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Optional detailed review of your experience"}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[t.length,"/1000"]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx($,{type:"submit",disabled:u||o===0||!v,isLoading:u,leftIcon:u?e.jsx(ne,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"}),children:"Submit Review"})})]})]})]})},ra=({itemId:a,itemType:i,refreshTrigger:n=0})=>{const[o,g]=s.useState([]),[t,m]=s.useState(!0),[u,y]=s.useState(null),[_,p]=s.useState(0);s.useEffect(()=>
43{v()},[a,i,n]);const v=async()=>{try{m(!0),y(null);try{const{data:E}=await R.rpc("get_average_rating",{p_item_id:a,p_item_type:i}),{data:S,error:O}=await R.from("ratings_reviews").select("id, user_id, rating, review_text, created_at").eq("item_id",a).eq("item_type",i).order("created_at",{ascending:!1});if(O)throw O;const B=await Promise.all((S||[]).map(async D=>{try{const{data:j}=await R.from("public_profiles").select("first_name, last_name").eq("id",D.user_id).single();let F="Anonymous User";if(j)if(j.first_name&&j.last_name)F=`${j.first_name} ${j.last_name}`;else{const{data:P}=await R.auth.getUser();P&&P.user&&P.user.id===D.user_id&&(F=P.user.email||"Anonymous User")}return{...D,user_name:F}}catch(j){return console.error(`Error fetching user details for review ${D.id}:`,j),{...D,user_name:"Anonymous User"}}}));g(B),p(E||0),m(!1);return}catch(E){console.warn("Direct database query failed, falling back to edge function:",E)}const{data:{session:h}}=await R.auth.getSession();if(!(h!=null&&h.access_token))throw new Error("No valid session found");const f=await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/fetch-reviews",{method:"POST",headers:{Authorization:`Bearer ${h.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({itemId:a,itemType:i})});if(!f.ok){const E=await f.json();throw new Error(E.error||"Failed to fetch reviews")}const w=await f.json();g(w.reviews),p(w.averageRating)}catch(h){console.error("Error fetching reviews:",h),y(h.message||"Failed to fetch reviews")}finally{m(!1)}};return t?e.jsx("div",{className:"flex justify-center items-center py-8",children:e.jsx(ne,{className:"h-8 w-8 animate-spin text-primary-600 dark:text-primary-400"})}):u?e.jsx("div",{className:"text-center py-8 text-red-600 dark:text-red-400",children:e.jsx("p",{children:u})}):o.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:[e.jsx(He,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No reviews yet. Be the first to leave a review!"})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:["Reviews (",o.length,")"]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx(Je,{rating:_,size:"md"}),e.jsxs("span",{className:"ml-2 text-gray-600 dark:text-gray-400",children:[_.toFixed(1)," out of 5"]})]})]}),e.jsx("div",{className:"space-y-4",children:o.map(h=>e.jsx(ce,{children:e.jsxs(ge,{children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-gray-100 dark:bg-gray-700 flex items-center justify-center",children:e.jsx(Ss,{className:"h-5 w-5 text-gray-500 dark:text-gray-400"})}),e.jsxs("div",{className:"ml-3",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:h.user_name}),e.jsx("div",{className:"flex items-center mt-1",children:e.jsx(Je,{rating:h.rating,size:"sm"})})]})]}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-400 flex items-center",children:[e.jsx(Nt,{className:"h-3 w-3 mr-1"}),new Date(h.created_at).toLocaleDateString()]})]}),h.review_text&&e.jsx("div",{className:"mt-3 text-sm text-gray-600 dark:text-gray-300",children:h.review_text})]})},h.id))})]})};function na({twinId:a,brandName:i,brandDomain:n}){const{user:o}=Oe(),{existingClaimForTwin:g,submitting:t,error:m,successMessage:u,checkExistingClaim:y,submitClaim:_,clearError:p,clearSuccess:v}=Cs(),[h,f]=s.useState(!1),[w,E]=s.useState(i),[S,O]=s.useState(""),[B,D]=s.useState("");s.useEffect(()=>{o!=null&&o.email&&O(o.email)},[o==null?void 0:o.email]),s.useEffect(()=>{y(a)},[a,y]),s.useEffect(()=>{if(u){f(!1);const P=setTimeout(()=>v(),5e3);return()=>clearTimeout(P)}},[u,v]);const j=s.useCallback(async P=>{P.preventDefault(),!(!w.trim()||!S.trim()||!B.trim())&&await _(a,w.trim(),S.trim(),B.trim())},[a,w,S,B,_]),F=g;return(F==null?void 0:F.status)==="approved"?e.jsx(ce,{children:e.jsx(ge,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center",children:e.jsx(rs,{className:"w-5 h-5 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-green-800 dark:text-green-300",children:"Verified Brand Owner"}),e.jsx("p",{className:"text-sm text-green-600 dark:text-green-400",children:"You are the verified owner of this brand twin."})]})]})})}
43):(F==null?void 0:F.status)==="pending"?e.jsx(ce,{children:e.jsx(ge,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-yellow-100 dark:bg-yellow-900/30 rounded-full flex items-center justify-center",children:e.jsx(We,{className:"w-5 h-5 text-yellow-600 dark:text-yellow-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-yellow-800 dark:text-yellow-300",children:"Claim Under Review"}),e.jsxs("p",{className:"text-sm text-yellow-600 dark:text-yellow-400",children:["Your brand ownership claim was submitted on"," ",new Date(F.created_at).toLocaleDateString(),". An admin will review it shortly."]})]})]})})}):(F==null?void 0:F.status)==="rejected"?e.jsx(ce,{children:e.jsx(ge,{children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center flex-shrink-0",children:e.jsx(ue,{className:"w-5 h-5 text-red-600 dark:text-red-400"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-red-800 dark:text-red-300",children:"Claim Not Approved"}),F.admin_notes&&e.jsxs("p",{className:"text-sm text-red-600 dark:text-red-400 mt-1",children:["Admin notes: ",F.admin_notes]}),e.jsx("button",{onClick:()=>{f(!0),D("")},className:"mt-2 text-sm text-blue-600 dark:text-blue-400 hover:underline",children:"Submit a new claim with additional evidence"})]})]})})}):e.jsx(ce,{children:e.jsx(ge,{children:h?e.jsxs("form",{onSubmit:j,className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("h3",{className:"font-semibold text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx($e,{className:"w-5 h-5 text-indigo-600"}),"Claim Brand Ownership"]}),e.jsx("button",{type:"button",onClick:()=>{f(!1),p()},className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx(ye,{className:"w-5 h-5"})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Brand Name"}),e.jsx("input",{type:"text",value:w,onChange:P=>E(P.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-indigo-500",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Your Email"}),e.jsx("input",{type:"email",value:S,onChange:P=>O(P.target.value),className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-indigo-500",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Proof of Ownership"}),e.jsx("textarea",{value:B,onChange:P=>D(P.target.value),placeholder:"Describe how you can verify you own or represent this brand. For example: domain ownership, company email, role at the company, etc.",rows:3,className:"w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-indigo-500 resize-none",required:!0})]}),m&&e.jsx("div",{className:"px-3 py-2 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg text-sm text-red-700 dark:text-red-300",children:m}),u&&e.jsx("div",{className:"px-3 py-2 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg text-sm text-green-700 dark:text-green-300",children:u}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx($,{type:"button",variant:"ghost",onClick:()=>{f(!1),p()},children:"Cancel"}),e.jsx($,{type:"submit",disabled:t||!B.trim(),children:t?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"}),"Submitting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{className:"w-4 h-4 mr-1.5"}),"Submit Claim"]})})]})]}):e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-indigo-100 dark:bg-indigo-900/30 rounded-full flex items-center justify-center",children:e.jsx($e,{className:"w-5 h-5 text-indigo-600 dark:text-indigo-400"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium text-gray-900 dark:text-white",children:["Are you the owner of ",i,"?"]}),e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Claim this twin to take ownership and manage it",n?` (${n})`:""]})]})]}),e.jsxs($,{onClick:()=>f(!0),variant:"outline",size:"sm",children:[e.jsx($e,{className:"w-4 h-4 mr-1.5"}),"Claim This Brand"]})]})})})}const er=()=>{var ot,ct,dt;const{id:a}=ns(),i=Ke(),{user:n,profile:o}=Oe(),{subscription:g}=is(),{currentTwin:t,loading:m,error:u,fetchTwinById:y,updateTwin:_,deleteTwin:p,getMintStatus:v,mintTwin:h}=vt(),{managers:f,fetchTwinManagers:w}
43=Et(),[E,S]=s.useState("knowledge"),[O,B]=s.useState(!1),[D,j]=s.useState(!1),[F,P]=s.useState(0),[U,q]=s.useState(!1),[N,C]=s.useState([]),[L,W]=s.useState(!1),[Q,d]=s.useState(!1),[c,T]=s.useState(!1),[te,J]=s.useState(null),[M,K]=s.useState(!1),[G,x]=s.useState(null),[k,V]=s.useState(!1),[Y,l]=s.useState(null),[b,se]=s.useState(!1),[ae,pe]=s.useState(!1),[H,le]=s.useState(""),[de,re]=s.useState(!1),[xe,Xe]=s.useState(""),[ia,la]=s.useState(!1),[oa,ca]=s.useState(""),[Ze,Ee]=s.useState(!1),[Ae,Re]=s.useState(!1),[Ft,Fe]=s.useState(!1),[Pt,Qe]=s.useState(null),[da,xa]=s.useState(!1),[Pe,Mt]=s.useState(!1);s.useEffect(()=>{a&&y(a)},[a,y,w]),s.useEffect(()=>{let r=!1;return a&&v(a).then(I=>{r||Qe(I)}).catch(()=>{r||Qe("unminted")}),()=>{r=!0}},[a,v]),s.useEffect(()=>{if(window.location.hash!=="#refine")return;const r=window.setTimeout(()=>{var I;(I=document.getElementById("refine"))==null||I.scrollIntoView({behavior:"smooth",block:"center"})},350);return()=>window.clearTimeout(r)},[a,t]),s.useEffect(()=>{if(a&&t){const r=t.owner_id===(n==null?void 0:n.id),I=(o==null?void 0:o.role)==="admin"||(o==null?void 0:o.role)==="superadmin";(r&&(g==null?void 0:g.plan)==="pro"||I)&&w(a)}},[a,t,n==null?void 0:n.id,o==null?void 0:o.role,g==null?void 0:g.plan,w]),s.useEffect(()=>{a&&(t!=null&&t.is_agentic)&&(n!=null&&n.id)&&R.from("twin_connections").select("provider, status").eq("twin_id",a).eq("user_id",n.id).then(({data:r})=>{r&&C(r)})},[a,t==null?void 0:t.is_agentic,n==null?void 0:n.id]);const Ut=async r=>{if(!(!a||!n)){W(!0);try{const{data:{session:I}}=await R.auth.getSession(),z=await(await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/nango-connect",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${I==null?void 0:I.access_token}`},body:JSON.stringify({twinId:a,userId:n.id,provider:r})})).json();if(z.connect_link){const ie=window.open(z.connect_link,"nango-connect","width=600,height=700"),oe=setInterval(async()=>{if(ie!=null&&ie.closed){clearInterval(oe),await ds(r);const{data:fe}=await R.from("twin_connections").select("provider, status").eq("twin_id",a).eq("user_id",n.id);fe&&C(fe),W(!1)}},1e3)}else console.error("No connect link returned:",z),W(!1)}catch(I){console.error("OAuth connect failed:",I),ee.error("We couldn't finish connecting that account.","Nothing was changed. Please try again in a moment."),W(!1)}}},Lt=()=>{P(r=>r+1)},Vt=async()=>{if(a){j(!0);try{const{data:{session:r}}=await R.auth.getSession();if(!(r!=null&&r.access_token))throw new Error("Please log in to subscribe");const I=await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/create-twin-checkout-session",{method:"POST",headers:{Authorization:`Bearer ${r.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({twinId:a,goodchainRef:localStorage.getItem("goodchain_ref")||void 0})});if(!I.ok){const z=await I.json();throw new Error(z.error||"Failed to create checkout session")}const{url:A}=await I.json();A&&(window.location.href=A)}catch(r){console.error("Subscription error:",r),ee.error("We couldn't start your subscription just now.","Please try again in a moment â you were not charged.")}finally{j(!1),B(!1)}}},qt=async()=>{if(!a||!t)return;const r=`Are you sure you want to delete "${t.name}"? This action cannot be undone and will permanently remove the VirtualTwin and all its associated data.`;if(window.confirm(r))try{d(!0),await p(a),i("/virtualtwins")}catch(I){console.error("Error deleting VirtualTwin:",I),ee.error("We couldn't delete this VirtualTwin just now.","It is still here and nothing was removed. Please try again in a moment.")}finally{d(!1)}},et=async()=>{if(!(!a||!t||!window.confirm(`Export "${t.name}" as a .vtwin file? 44 45Any active OAuth connections (Gmail, Sheets, etc.) for this twin will be disconnected. The exported file contains no tokens or API keys.`)))try{Ee(!0);const I=await Ts(a);Es(I),ee.success("Your VirtualTwin was exported.","Check your downloads for the .vtwin file.")}catch(I){console.error("Export failed:",I),ee.error("We couldn't export your VirtualTwin just now.","Please try again in a moment.")}finally{Ee(!1)}},zt=async()=>
45{if(t)try{V(!0);const{data:{session:r}}=await R.auth.getSession(),A=await(await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/deployment-create",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r==null?void 0:r.access_token}`},body:JSON.stringify({twin_id:t.id,channel:"api"})})).json();A!=null&&A.api_key?x(A.api_key):(console.error("Connect to Copilot: no api_key returned",A),ee.error("We couldn't create your connection key just now.","Please try again in a moment."))}catch(r){console.error("Connect to Copilot failed:",r),ee.error("We couldn't set up the Copilot connection just now.","Please try again in a moment.")}finally{V(!1)}},tt=async(r,I)=>{try{await navigator.clipboard.writeText(r),l(I),setTimeout(()=>l(null),1500);return}catch{}try{const A=document.createElement("textarea");A.value=r,A.style.position="fixed",A.style.opacity="0",document.body.appendChild(A),A.select();const z=document.execCommand("copy");if(document.body.removeChild(A),z){l(I),setTimeout(()=>l(null),1500);return}}catch{}ee.error("Copying is blocked in this window.","Select the text and press âC instead.")},Wt=async()=>{if(t)try{pe(!0);const{data:{session:r}}=await R.auth.getSession(),A=await(await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/offboard-twin",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r==null?void 0:r.access_token}`},body:JSON.stringify({twin_id:t.id})})).json();A!=null&&A.success?i("/virtualtwins"):(console.error("Offboard: unsuccessful response",A),ee.error("We couldn't remove this VirtualTwin just now.","Please try again in a moment, or reach out to support if it keeps happening."))}catch(r){console.error("Offboard failed:",r),ee.error("We couldn't remove this VirtualTwin just now.","Please try again in a moment, or reach out to support if it keeps happening.")}finally{pe(!1)}},st=async()=>{if(!t)return;const r=xe.trim();if(!r||r===t.name){re(!1);return}const{error:I}=await R.from("virtual_twins").update({name:r}).eq("id",t.id);if(I){ee.error("Couldn't save the new name.","Please try again in a moment.");return}re(!1),await y(t.id),ee.success(`Renamed to ${r}.`)};if(m)return e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-[#ff2e7c]"})});if(u||!t)return e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"VirtualTwin Not Found"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-4",children:"We couldn't open this VirtualTwin. It may have been moved or removed â head back to your VirtualTwins and try again."}),e.jsx($,{onClick:()=>i("/virtualtwins"),children:"Back to VirtualTwins"})]})});const X=t.owner_id===(n==null?void 0:n.id),Ne=f.some(r=>r.user_id===(n==null?void 0:n.id)),me=(o==null?void 0:o.role)==="admin"||(o==null?void 0:o.role)==="superadmin",Me=t.price&&t.price>0,he=X||Ne||me,Ht=X&&(g==null?void 0:g.plan)==="pro",Yt=me,Ue=t.name||"Untitled VirtualTwin",Jt=(Ue.trim().charAt(0)||"?").toUpperCase(),Kt=t.public_description||"A VirtualTwin that speaks and works as you.",at=Pt==="minted"||!!t.goodchain_tx_hash,Le=(t.goodchain_tx_hash||t.id||"").replace(/-/g,""),Gt=Le?`0x${Le.slice(0,4)}â¦${Le.slice(-4)}`:"0x0000â¦0000",Xt={nascent:20,emerging:45,established:70,mature:95},rt=t.maturity_state?Xt[t.maturity_state]??20:Math.max(8,Math.min(90,12+(t.total_interactions||0))),Zt={brand_voice:"Brand voice",mirror:"Mirror",architect:"Architect",agentic_doer:"Agentic doer"},nt=t.species?Zt[t.species]:t.twin_type||null,it=N.filter(r=>r.status==="active").length,lt=t.adoption_count??0;return e.jsxs(je.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"max-w-[820px] mx-auto px-4 sm:px-6 py-10 space-y-8",children:[e.jsx("button",{onClick:()=>i(-1),className:"inline-flex items-center gap-1.5 text-[14px] font-medium text-slate-400 dark:text-gray-500 hover:text-slate-700 dark:hover:text-gray-300 transition-colors -mb-3",children:"â Back"}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start gap-4",children:[t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:Ue,className:"w-16 h-16 rounded-2xl object-cover border border-slate-100 dar
45k:border-gray-800/60 shrink-0"}):e.jsx("div",{className:"w-16 h-16 rounded-2xl shrink-0 flex items-center justify-center bg-slate-100 dark:bg-gray-800 text-slate-500 dark:text-gray-300 text-2xl font-semibold",children:Jt}),e.jsxs("div",{className:"flex-1 min-w-0",children:[de?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:xe,onChange:r=>Xe(r.target.value),onKeyDown:r=>{r.key==="Enter"&&st(),r.key==="Escape"&&re(!1)},autoFocus:!0,className:"bpx-display text-3xl sm:text-4xl uppercase bg-transparent border-b-2 border-[#ff2e7c] outline-none text-slate-900 dark:text-white leading-none min-w-0 flex-1"}),e.jsx("button",{onClick:st,className:"px-3 py-1.5 rounded-lg text-sm font-semibold text-white bpx-accent-bg shrink-0",children:"Save"})]}):e.jsxs("h1",{className:"bpx-display text-3xl sm:text-4xl uppercase text-slate-900 dark:text-white leading-none group/name",children:[Ue,X&&e.jsx("button",{onClick:()=>{Xe(t.name||""),re(!0)},title:"Rename",className:"ml-2 align-middle text-slate-300 dark:text-gray-600 hover:text-[#ff2e7c] transition-colors",children:e.jsx(yt,{className:"w-5 h-5 inline"})})]}),e.jsx("p",{className:"mt-2 text-slate-500 dark:text-gray-400",children:Kt})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{onClick:()=>i(ht(t)),className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium border border-slate-200 dark:border-gray-700 text-slate-700 dark:text-gray-200 hover:bg-slate-50 dark:hover:bg-gray-800 transition-colors",children:[e.jsx(He,{className:"w-4 h-4"}),"Chat"]}),(t==null?void 0:t.name)==="BossXO"?e.jsx("button",{onClick:()=>i("/bossxo"),className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold shadow-[0_4px_16px_rgba(233,184,76,0.35)] hover:opacity-95 transition-opacity",style:{backgroundImage:"linear-gradient(135deg,#fde7b0,#e9b84c,#b8860b)",color:"#231a05"},children:"Open the Studio â"}):e.jsx("button",{onClick:()=>K(!0),className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-semibold text-white bpx-accent-bg shadow-[0_4px_16px_rgba(255,46,124,0.25)] hover:opacity-95 transition-opacity",children:"Put it to work â"})]})]}),X&&e.jsx(qs,{twinId:t.id,twinName:t.name}),X&&e.jsx("div",{id:"refine",children:e.jsx(Vs,{twinId:t.id,twinType:t.twin_type,twinName:t.name,onApplied:()=>y(t.id)})}),X&&e.jsx(Hs,{twinId:t.id}),X&&e.jsx("button",{onClick:()=>i(`/virtualtwins/${t.id}/edit?tab=connections`),className:"w-full text-left rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5 sm:p-6 hover:border-slate-200 dark:hover:border-gray-700 transition-colors",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center text-white shrink-0",style:{background:"linear-gradient(120deg, #ff2e7c, #ff8a38)"},children:e.jsx(As,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-[15px] font-semibold text-slate-900 dark:text-white",children:"Connect it to a website, or a folder"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500 dark:text-gray-400 leading-relaxed",children:["Let ",t.name," work inside sites you're already signed in to, or read a folder on your computer. It never sees your password, and never presses Post, Send or Buy."]})]}),e.jsx(Ie,{className:"w-5 h-5 text-slate-300 dark:text-gray-600 shrink-0"})]})}),X&&e.jsx(Ws,{twinId:t.id,twinName:t.name,isPublished:t.twin_type==="built_app"}),X&&e.jsx("div",{className:"mt-6",children:e.jsx(zs,{twinId:t.id,twinName:t.name,isPublic:!!t.is_public,price:t.price??null,onListed:()=>y(t.id)})}),e.jsxs("div",{className:"rounded-[20px] border border-[#ff2e7c]/25 bg-white dark:bg-gray-950 p-6 sm:p-8",style:{boxShadow:"0 8px 40px rgba(255,46,124,0.10)"},children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-6",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center text-white bpx-accent-bg shrink-0",children:e.jsx(ft,{className:"w-5 h-5",fill:"currentColor"})}),e.jsx("span",{className:"text-[11px] font-semibold tracking-[0.16em] bpx-accent-text uppercase",children:"Ownership"})]}),e.jsx("h2",{className:"text-xl sm:text-2xl font-semibold text-slate-900 dark:text-white",children:"This VirtualTwin is yours â make it provable."}),e.jsx("p",{className:"mt-2 text-sm text-slate-500 dark:text-gray-400 leading-relaxed",children:"Mint it and its Heart â a permanent fingerprint of who it is â is married to you on GoodChain. One mint, infinite instances: rent it, sell it, or run it anywhere, and the proof of ownership travels with it. Nobody can erase it."})]}),e.jsx("div",{className:"shrink-0 w-full sm:w-auto",children:at?e.jsxs("div",{className:"inline-flex w-full sm:w-auto items-center justify-center gap-2 px-6 py-3.5 rounded-2xl text-base font-semibold border border-emerald-500/30 bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 dark:text-emerald-400",children:[e.jsx(De,{className:"w-5 h-5"}),"Minted â"]}):e.jsxs("div",{className:"w-full sm:w-auto",children:[e.jsx("div",{"aria-disabled":"true",className:"inline-flex w-full sm:w-auto items-center justify-center gap-2 px-6 py-3.5 rounded-2xl text-base font-semibold cursor-not-allowed select-none",style:{background:"#F2F2F4",color:"#8A8A8F",border:"1px solid #E5E5EA"},children:At}),e.jsx("p",{className:"mt-2 text-[12.5px] leading-snug text-slate-400 dark:text-gray-500 max-w-sm",children:Rt})]})})]}),e.jsxs("div",{className:"mt-6 pt-5 border-t border-slate-100 dar
45k:border-gray-800/60 flex flex-wrap items-center gap-3",children:[e.jsx("span",{className:"text-[11px] font-semibold tracking-[0.16em] text-slate-400 uppercase cursor-help",title:"The Heart is a one-of-a-kind fingerprint of who this VirtualTwin is.",children:"Heart"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 font-medium text-xs px-2.5 py-1 rounded-lg bg-slate-50 dark:bg-gray-900 border border-slate-100 dark:border-gray-800/60 text-slate-600 dark:text-gray-300 cursor-help",title:`The Heart is a one-of-a-kind fingerprint of who this VirtualTwin is. 46Unique fingerprint: ${Gt}`,children:[e.jsx(ft,{className:"w-3 h-3 text-[#ff2e7c]",fill:"currentColor"}),"Unique fingerprint"]}),e.jsx("span",{className:"text-xs text-slate-400 dark:text-gray-500",children:at?"owned & provable on GoodChain":"ready to mint â computed from its brain, voice & character"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"bpx-display text-lg uppercase text-slate-400 dark:text-gray-500",children:"What makes it yours"}),e.jsxs("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] divide-y divide-slate-100 dark:divide-gray-800/60",children:[e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>i(`/virtualtwins/${a}/make-it-yours`),onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),i(`/virtualtwins/${a}/make-it-yours`))},className:"flex items-center gap-4 px-5 py-4 cursor-pointer hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-gray-800 flex items-center justify-center text-slate-500 dark:text-gray-300 shrink-0",children:e.jsx(ls,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900 dark:text-white",children:"Voice"}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-gray-400",children:"Speaks every reply as you"})]}),e.jsx("span",{className:"text-sm bpx-accent-text font-medium shrink-0",children:"Set a voice"}),e.jsx(be,{className:"w-4 h-4 text-slate-300 dark:text-gray-600 shrink-0"})]}),e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>i(`/virtualtwins/${a}/make-it-yours`),onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),i(`/virtualtwins/${a}/make-it-yours`))},className:"flex items-center gap-4 px-5 py-4 cursor-pointer hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-gray-800 flex items-center justify-center text-slate-500 dark:text-gray-300 shrink-0",children:e.jsx(Rs,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900 dark:text-white",children:"Look & tone"}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-gray-400",children:"How it presents itself"})]}),nt?e.jsx("span",{className:"text-sm text-slate-600 dark:text-gray-300 shrink-0 capitalize",children:nt}):e.jsx("span",{className:"text-sm bpx-accent-text font-medium shrink-0",children:"Add a look"}),e.jsx(be,{className:"w-4 h-4 text-slate-300 dark:text-gray-600 shrink-0"})]}),e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>i(`/virtualtwins/${a}/make-it-yours`),onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),i(`/virtualtwins/${a}/make-it-yours`))},className:"flex items-center gap-4 px-5 py-4 cursor-pointer hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-slate-100 dark:bg-gray-800 flex items-center justify-center text-slate-500 dark:text-gray-300 shrink-0",children:e.jsx(mt,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900 dark:text-white",children:"What it can do"}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-gray-400",children:"Connections & capabilities"})]}),it>
460?e.jsxs("span",{className:"text-sm text-slate-600 dark:text-gray-300 shrink-0",children:[it," connected"]}):e.jsx("span",{className:"text-sm bpx-accent-text font-medium shrink-0",children:"Add a connection"}),e.jsx(be,{className:"w-4 h-4 text-slate-300 dark:text-gray-600 shrink-0"})]})]})]}),e.jsx(Xs,{twinId:a,canManage:X||Ne||me}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"bpx-display text-lg uppercase text-slate-400 dark:text-gray-500",children:"Its brain & its work"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5 cursor-help",title:"How much of your thinking this VirtualTwin has learned so far.",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ct,{className:"w-4 h-4 text-slate-400 dark:text-gray-500"}),e.jsx("span",{className:"text-[11px] font-semibold tracking-[0.16em] text-slate-400 uppercase",children:"Brain"})]}),e.jsxs("div",{className:"text-3xl font-semibold text-slate-900 dark:text-white",children:[rt,"%"]}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-gray-400 mb-3",children:"how much of you it holds · estimated"}),e.jsx("div",{className:"h-1.5 rounded-full bg-slate-100 dark:bg-gray-800 overflow-hidden",children:e.jsx("div",{className:"h-full bpx-accent-bg rounded-full",style:{width:`${rt}%`}})})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx($s,{className:"w-4 h-4 text-slate-400 dark:text-gray-500"}),e.jsx("span",{className:"text-[11px] font-semibold tracking-[0.16em] text-slate-400 uppercase",children:"Working now"})]}),e.jsx("div",{className:"text-3xl font-semibold text-slate-900 dark:text-white",children:lt}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-gray-400",children:lt>0?"active instances":"Not deployed yet â put it to work"})]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>Mt(r=>!r),"aria-expanded":Pe,className:"w-full flex items-center justify-between px-5 py-4 text-left hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsx("span",{className:"bpx-display text-lg uppercase text-slate-400 dark:text-gray-500",children:"Manage"}),e.jsx(be,{className:`w-4 h-4 text-slate-400 dark:text-gray-500 transition-transform ${Pe?"rotate-90":""}`})]}),Pe&&e.jsxs("div",{className:"px-2 pb-2 flex flex-col divide-y divide-slate-100 dark:divide-gray-800/60 border-t border-slate-100 dark:border-gray-800/60",children:[e.jsx(_s,{item:{id:t.id,type:"twin",name:t.name,image:t.avatar_url,price:t.price},size:"md"}),e.jsx($,{variant:"ghost",fullWidth:!0,onClick:()=>i(ht(t)),leftIcon:e.jsx(He,{className:"h-4 w-4"}),children:"Chat"}),e.jsx(Ms,{twinId:t.id,isOwner:X}),he&&e.jsx($,{variant:"ghost",fullWidth:!0,onClick:et,isLoading:Ze,leftIcon:e.jsx(os,{className:"h-4 w-4"}),children:"Export"}),he&&e.jsx($,{variant:"ghost",fullWidth:!0,onClick:async()=>{try{Ee(!0);const{data:{session:r}}=await R.auth.getSession(),A=await(await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/twin-export-content",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r==null?void 0:r.access_token}`},body:JSON.stringify({twin_id:t.id})})).json();if(A.error){console.error("Full export: error response",A.error),ee.error("We couldn't download your VirtualTwin's content just now.","Please try again in a moment.");return}const z=`${t.name.replace(/[^a-zA-Z0-9_-]/g,"_").toLowerCase()}_full_export.json`,ie=new Blob([JSON.stringify(A,null,2)],{type:"application/json"}),oe=URL.createObjectURL(ie),fe=document.createElement("a");fe.href=oe,fe.download=z,fe.click(),URL.revokeObjectURL(oe),ee.success("Your VirtualTwin export is ready.","Check your downloads for the file.")}catch(r){console.error("Full export failed:",r),ee.error("We couldn't download your VirtualTwin's content just now.","Please try again in a moment.")}finally{Ee(!1)}},isLoading:Ze,leftIcon:e.jsx(Ce,{className:"h-4 w-4"}),children:"Download All"}),me&&e.jsx($,{variant:"ghost",fullWidth:!0,onClick:async()=>
46{if(confirm(`Clone "${t.name}"? This creates an exact copy you can rename and modify.`))try{const{data:{session:r}}=await R.auth.getSession(),A=await(await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/duplicate-twin",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r==null?void 0:r.access_token}`},body:JSON.stringify({twin_id:t.id})})).json();A.clone_id?i(`/virtualtwins/${A.clone_id}`):(console.error("Clone: no clone_id returned",A==null?void 0:A.error),ee.error("We couldn't clone this VirtualTwin just now.","Please try again in a moment."))}catch(r){console.error("Clone failed:",r),ee.error("We couldn't clone this VirtualTwin just now.","Please try again in a moment.")}},leftIcon:e.jsx(Ds,{className:"h-4 w-4"}),children:"Clone"}),he&&e.jsx($,{variant:"ghost",fullWidth:!0,onClick:()=>i(`/virtualtwins/${a}/edit`),leftIcon:e.jsx(yt,{className:"h-4 w-4"}),children:"Settings"}),he&&e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg text-sm font-medium text-slate-500 dark:text-gray-400 cursor-pointer select-none hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx(be,{className:"h-4 w-4 shrink-0 transition-transform group-open:rotate-90"}),"Developer access (advanced)"]}),e.jsxs("div",{className:"pt-1 pb-1",children:[e.jsx("p",{className:"px-3 py-1 text-xs text-slate-400 dark:text-gray-500",children:"Let an outside AI assistant call this VirtualTwin. Most people never need this."}),e.jsx($,{variant:"ghost",fullWidth:!0,onClick:zt,isLoading:k,leftIcon:e.jsx(Ve,{className:"h-4 w-4"}),children:"Connect to Copilot"})]})]}),X&&e.jsxs("button",{onClick:()=>{le(""),se(!0)},className:"w-full inline-flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg text-sm font-medium text-red-600 dark:text-red-400 hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsx(Te,{className:"h-4 w-4"}),"Remove"]}),b&&t&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>!ae&&se(!1),children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl bg-white dark:bg-gray-800 shadow-xl border border-gray-200 dark:border-gray-700 p-6",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ue,{className:"h-5 w-5 text-slate-400 dark:text-gray-500"}),e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:["Remove ",t.name," from BlueprintX"]})]}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-3",children:["This permanently removes this VirtualTwin, its knowledge, and all its deployments from BlueprintX.",t.goodchain_tx_hash?" Its on-chain mint stays as permanent provenance.":""," This canât be undone."]}),e.jsxs("div",{className:"mb-3 rounded-lg bg-slate-50 dark:bg-gray-900 border border-slate-100 dark:border-gray-800/60 p-3 text-xs text-slate-600 dark:text-gray-300",children:["Own it â donât lose it. ",e.jsx("button",{onClick:et,className:"bpx-accent-text underline font-medium",children:"Download your VirtualTwin first"})," so it stays yours."]}),e.jsxs("label",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Type ",e.jsx("b",{children:t.name})," to confirm"]}),e.jsx("input",{autoFocus:!0,value:H,onChange:r=>le(r.target.value),className:"mt-1 w-full rounded-lg border border-gray-300 dark:border-gray-600 bg-transparent px-3 py-2 text-sm text-gray-900 dark:text-white outline-none focus:border-[#ff2e7c]",placeholder:t.name}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx($,{variant:"outline",onClick:()=>se(!1),disabled:ae,children:"Cancel"}),e.jsx("button",{onClick:Wt,disabled:ae||H.trim()!==t.name,className:"inline-flex items-center gap-2 rounded-lg border border-red-200 dark:border-red-900/40 px-4 py-2 text-sm font-semibold text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:cursor-not-allowed disabled:opacity-50",children:ae?"Removingâ¦":"Remove permanently"})]})]})}),G&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>x(null),children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl bg-white dark:bg-gray-800 shadow-xl border border-gray-200 dark:border-gray-700 p-6",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ve,{className:"h-5 w-5 text-slate-500 dark:text-gray-400"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Connect to Copilot"})]}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:["Add ",e.jsx("b",{children:t.name})," as a ",e.jsx("b",{children:"remote MCP server"}
46)," in Copilot, Claude, or Cursor. It answers and runs its capabilities â metered to you."]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide text-gray-500 dark:text-gray-400 font-semibold",children:"Server URL"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 truncate rounded-lg bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 px-3 py-2 text-xs text-gray-800 dark:text-gray-200",children:"https://blueprintx.world/mcp"}),e.jsx("button",{onClick:()=>tt("https://blueprintx.world/mcp","url"),className:"shrink-0 rounded-lg border border-gray-300 dark:border-gray-600 px-3 py-2 text-xs font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700",children:Y==="url"?"Copied â":"Copy"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide text-gray-500 dark:text-gray-400 font-semibold",children:"Access key â keep private"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 truncate rounded-lg bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 px-3 py-2 text-xs text-gray-800 dark:text-gray-200",children:G}),e.jsx("button",{onClick:()=>tt(G,"key"),className:"shrink-0 rounded-lg border border-gray-300 dark:border-gray-600 px-3 py-2 text-xs font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700",children:Y==="key"?"Copied â":"Copy"})]})]})]}),e.jsx("p",{className:"mt-4 text-[11px] text-gray-400",children:`Paste both into your agent's "add MCP server" settings. Anyone with the key can call this twin â it bills your credits.`}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx($,{variant:"outline",onClick:()=>x(null),children:"Done"})})]})}),e.jsxs("button",{onClick:()=>K(!0),className:"w-full inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium text-slate-700 dark:text-gray-200 hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsx(Is,{className:"h-4 w-4"}),"Deploy"]}),t.goodchain_tx_hash?e.jsxs("a",{href:`https://xrpscan.com/tx/${t.goodchain_tx_hash}`,target:"_blank",rel:"noopener noreferrer",className:"w-full inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium text-slate-700 dark:text-gray-200 hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors",children:[e.jsx(Tt,{className:"h-4 w-4"}),"Protected",e.jsx("span",{className:"text-xs text-slate-400 dark:text-gray-500",children:"Verify on blockchain"})]}):null,t.goodchain_tx_hash&&X&&!t.is_recalled&&e.jsxs("button",{onClick:()=>Fe(!0),disabled:Ae,className:"w-full inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium text-red-600 dark:text-red-400 hover:bg-slate-50 dark:hover:bg-gray-900/40 transition-colors disabled:opacity-50",children:[e.jsx(ue,{className:"h-4 w-4"}),Ae?"Recalling...":"Recall"]}),t.is_recalled&&e.jsxs("div",{className:"w-full inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium text-red-600 dark:text-red-400",children:[e.jsx(ue,{className:"h-4 w-4"}),"Recalled",e.jsx("button",{onClick:async()=>{Re(!0);try{const{data:{session:r}}=await R.auth.getSession();(await(await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/twin-recall",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r==null?void 0:r.access_token}`},body:JSON.stringify({twin_id:t.id,action:"reinstate"})})).json()).success&&y(t.id)}catch(r){console.error("[Reinstate] Error:",r)}finally{Re(!1)}},className:"ml-2 text-xs underline bpx-accent-text",children:"Reinstate"})]}),Yt&&e.jsx($,{variant:"ghost",fullWidth:!0,onClick:qt,isLoading:Q,leftIcon:e.jsx(Te,{className:"h-4 w-4"}),className:"text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20",children:Q?"Deleting...":"Delete VirtualTwin"}),X&&!t.is_public&&e.jsx("button",{onClick:()=>i(`/virtualtwins/${a}/edit`),className:"w-full py-3 text-center transition-colors hover:bg-slate-50 dark:hover:bg-gray-900/40 group",children:e.jsxs("span",{className:"text-sm text-slate-400 dark:text-gray-500 group-hover:text-slate-600 dar
46k:group-hover:text-gray-300",style:{fontFamily:"'Avenir Next', 'Avenir', sans-serif"},children:["Only you can see this VirtualTwin. ",e.jsx("span",{className:"bpx-accent-text",children:"Share it â"})]})}),(Ht||me)&&e.jsx(Ks,{twinId:a,isOwner:!!X})]})]}),t.is_agentic&&he&&(()=>{const r=N.filter(z=>z.status==="active").map(z=>z.provider),I=["linkedin"].filter(z=>!r.includes(z)),A={linkedin:{name:"LinkedIn",icon:"ð¼"},gmail:{name:"Gmail",icon:"ð§"},google_calendar:{name:"Calendar",icon:"ð
"},slack:{name:"Slack",icon:"ð¬"}};return I.length===0&&r.length===0?null:e.jsxs("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ve,{className:"w-4 h-4 text-slate-400 dark:text-gray-500"}),e.jsx("h3",{className:"bpx-display text-lg uppercase text-slate-400 dark:text-gray-500",children:"Connections"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.map(z=>{var ie,oe;return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full border border-emerald-500/30 bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 dark:text-emerald-400 text-sm font-medium",children:[e.jsx(De,{className:"w-4 h-4"}),(ie=A[z])==null?void 0:ie.icon," ",((oe=A[z])==null?void 0:oe.name)||z]},z)}),I.map(z=>{var ie,oe;return e.jsxs($,{variant:"outline",size:"sm",onClick:()=>Ut(z),isLoading:L,className:"border-slate-200 dark:border-gray-700 text-slate-700 dark:text-gray-200 hover:bg-slate-50 dark:hover:bg-gray-800",children:[(ie=A[z])==null?void 0:ie.icon," Connect ",((oe=A[z])==null?void 0:oe.name)||z]},z)})]})]})})(),((ot=t.capabilities)==null?void 0:ot.can_be_claimed)&&e.jsx(na,{twinId:t.id,brandName:((ct=t.capabilities)==null?void 0:ct.brand_domain)||t.name,brandDomain:(dt=t.capabilities)==null?void 0:dt.brand_domain}),t.is_dynamic_mode&&he&&e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"border-b border-gray-200 dark:border-gray-700",children:e.jsxs("nav",{className:"-mb-px flex space-x-8 px-6",children:[e.jsxs("button",{onClick:()=>S("knowledge"),className:`py-4 px-1 border-b-2 font-medium text-sm ${E==="knowledge"?"border-[#ff2e7c] bpx-accent-text":"border-transparent text-slate-500 hover:text-slate-700 hover:border-slate-300 dark:text-gray-400 dark:hover:text-gray-300"}`,children:[e.jsx(Ce,{className:"w-4 h-4 mr-2 inline"}),"Knowledge Base"]}),e.jsxs("button",{onClick:()=>S("data-sources"),className:`py-4 px-1 border-b-2 font-medium text-sm ${E==="data-sources"?"border-[#ff2e7c] bpx-accent-text":"border-transparent text-slate-500 hover:text-slate-700 hover:border-slate-300 dark:text-gray-400 dark:hover:text-gray-300"}`,children:[e.jsx(mt,{className:"w-4 h-4 mr-2 inline"}),"Live Data Sources"]})]})})}),Me&&!X&&!Ne&&!me&&e.jsx("div",{className:"rounded-2xl border border-slate-100 dark:border-gray-800/60 bg-white dark:bg-gray-950 shadow-[0_2px_16px_rgba(0,0,0,0.05)] p-6",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(_t,{className:"w-5 h-5 text-slate-400 dark:text-gray-500 mr-3"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-white",children:"Premium VirtualTwin"}),e.jsxs("p",{className:"text-sm text-slate-500 dark:text-gray-400",children:["This VirtualTwin requires a subscription to access. Subscribe for $",t.price,"/month."]})]})]}),e.jsx("button",{onClick:()=>B(!0),className:"shrink-0 inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-semibold text-white bpx-accent-bg shadow-[0_4px_16px_rgba(255,46,124,0.25)] hover:opacity-95 transition-opacity",children:"Subscribe Now"})]})}),(!Me||X||Ne||me)&&e.jsxs(e.Fragment,{children:[e.jsx(Ns,{twinId:a,className:"rounded-2xl border border-slate-200 dark:border-gray-800 bg-white dark:bg-gray-900 p-5"}),!X&&!Ne&&!me&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(aa,{itemId:a,itemType:"twin",onReviewSubmitted:Lt}),e.jsx(ra,{itemId:a,itemType:"twin",refreshTrigger:F})]}),E==="knowledge"||!t.is_dynamic_mode?e.jsx(fs,{twinId:a,canEdit:he}):e.jsx(Js,{twinId:a,canEdit:he})]}),Me&&e.jsx(Zs,{isOpen:O,onClose:()=>B(!1),twin:{id:t.id,name:t.name,avatar_url:t.avatar_url,price:t.price,stripe_product_id:t.stripe_product_id},onSubscribe:Vt,isLoading:D}),n&&e.jsx(ta,{isOpen:M,onClose:()=>K(!1),twin:{id:t.id,name:t.name,price:t.price,user_id:t.owner_id},currentUserId:n.id}),Ft&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl p-6 max-w-md w-full mx-4 shadow-2xl",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-full bg-slate-100 dar
46k:bg-gray-800",children:e.jsx(ue,{className:"h-6 w-6 text-slate-400 dark:text-gray-500"})}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Recall this VirtualTwin?"})]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300 mb-2",children:"This will immediately:"}),e.jsxs("ul",{className:"text-sm text-gray-600 dark:text-gray-300 mb-6 list-disc ml-5 space-y-1",children:[e.jsx("li",{children:"Deactivate all active deployments"}),e.jsx("li",{children:"Invalidate all API keys"}),e.jsx("li",{children:"Stop the twin from responding to any requests"}),e.jsx("li",{children:"Record the recall on GoodChain"})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-6",children:"You can reinstate the twin later, but deployments will need to be recreated."}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx("button",{onClick:()=>Fe(!1),className:"px-4 py-2 rounded-lg text-sm font-medium text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:"Cancel"}),e.jsx("button",{onClick:async()=>{Fe(!1),Re(!0);try{const{data:{session:r}}=await R.auth.getSession(),A=await(await fetch("https://wqqiillyujpxsgjzgcfz.supabase.co/functions/v1/twin-recall",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r==null?void 0:r.access_token}`},body:JSON.stringify({twin_id:t.id,reason:"Manual recall by owner"})})).json();A.success?y(t.id):console.error("[Recall] Failed:",A.error)}catch(r){console.error("[Recall] Error:",r)}finally{Re(!1)}},disabled:Ae,className:"px-4 py-2 rounded-lg text-sm font-semibold border border-red-200 dark:border-red-900/40 text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors disabled:opacity-50",children:Ae?"Recalling...":"Confirm Recall"})]})]})})]})};export{er 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.