PageSourceSearch

https://founder-spark-63.lovable.app/assets/Profile-mRwhijEd.js

js founder-spark-63.lovable.app collected 2026-10-03 03:32:11 UTC 89,211 bytes, 7 lines download raw bytes

1import{j as e,u as Z,b as Ye,c as ar}from"./query-_koPiPsI.js";import{r as i,h as nr,f as ir,u as or}from"./react-vendor-h1rQ_Bae.js";import{O as k,C as U,E as we,B as x,I,g as t,f as oe,s as l,K as He,k as he,L as E,J as cr,H as lr,M as ps,Q as xs,y as Se,P as dr,aw as ur,S as fs,a7 as mr,ai as hr,ao as pr,ah as ds,D as xr,h as fr,i as gr,j as yr,x as jr,t as br,w as De,m as vr,l as us,al as wr}from"./index-Dq2zLArw.js";import{s as H,u as Nr,A as ze,a as qe,b as $e,o as _r,l as kr,t as Cr}from"./alert-QqYnt24b.js";import{C as We,a as Ge,b as Oe}from"./collapsible-BqfEIKWx.js";import{S as gs,a as ys,b as js,c as bs,d as Pe}from"./select-S0HS5dUY.js";import{T as xe}from"./trash-2-DwNrObEE.js";import{P as de}from"./plus-BKP-C_hU.js";import{I as Ie}from"./info-DI8_flyN.js";import{C as ie}from"./circle-check-big-BlhODvES.js";import{C as pe}from"./circle-x-DYzxr_B1.js";import{S as Ne}from"./switch-CyEfQhNS.js";import{a as vs,u as Xe,P as Ae,f as Ke,d as Sr,y as Pr,J as Ir,K as ws,x as Ar,b as Tr,M as Fr,N as Lr}from"./ui-radix-CKwvnS8F.js";import{C as Rr}from"./circle-CflMNCk5.js";import{C as Er}from"./copy-BJMOZJfL.js";import{S as Ns}from"./save-bi9ogCha.js";import{F as Me}from"./supabase-DL6nu9mS.js";import{C as Ur}from"./crown-Uhwa5ZKt.js";import"./charts-Xu79y1bN.js";import"./motion-nVmI7L5T.js";import"./chevron-up-Dbq7Df3-.js";function Dr({ctas:r,onChange:d,maxCTAs:u=5}){const[j,b]=i.useState(""),[g,p]=i.useState(""),[N,o]=i.useState("primary"),h=()=>{if(!j.trim()){t.error("Please enter a button label");return}if(!g.trim()){t.error("Please enter a URL");return}try{new URL(g)}catch{t.error("Please enter a valid URL (e.g., https://example.com)");return}if(r.length>=u){t.error(`Maximum ${u} CTAs allowed`);return}const m={id:crypto.randomUUID(),label:j.trim(),url:g.trim(),style:N};d([...r,m]),b(""),p(""),o("primary"),t.success("CTA added!")},y=m=>{d(r.filter(F=>F.id!==m)),t.success("CTA removed")},f=m=>{switch(m){case"primary":return"bg-primary text-primary-foreground";case"outline":return"border border-primary text-primary bg-transparent";case"secondary":return"bg-secondary text-secondary-foreground";default:return"bg-primary text-primary-foreground"}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(k,{children:"Your Call-to-Action Buttons"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Create CTAs once, insert them anywhere in your articles using /cta command"})]}),r.length>0&&e.jsx("div",{className:"space-y-2",children:r.map(m=>e.jsxs(U,{className:"p-3 flex items-center gap-3",children:[e.jsx("div",{className:`px-3 py-1.5 rounded text-sm font-medium ${f(m.style)}`,children:m.label}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground flex items-center gap-1 truncate",children:[m.url,e.jsx(we,{className:"h-3 w-3 flex-shrink-0"})]})}),e.jsx(x,{type:"button",variant:"ghost",size:"sm",onClick:()=>y(m.id),className:"text-destructive hover:text-destructive/80",children:e.jsx(xe,{className:"h-4 w-4"})})]},m.id))}),r.length<u&&e.jsxs(U,{className:"p-4 space-y-3 bg-muted/30",children:[e.jsx(k,{className:"text-sm",children:"Add New CTA"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:"Button Text"}),e.jsx(I,{placeholder:"e.g., Subscribe Now",value:j,onChange:m=>b(m.target.value),maxLength:50})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:"URL"}),e.jsx(I,{placeholder:"https://...",value:g,onChange:m=>p(m.target.value)})]})]}),e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(k,{className:"text-xs text-muted-foreground",children:"Style"}),e.jsxs(gs,{value:N,onValueChange:m=>o(m),children:[e.jsx(ys,{children:e.jsx(js,{})}),e.jsxs(bs,{children:[e.jsx(Pe,{value:"primary",children:"Primary (Filled)"}),e.jsx(Pe,{value:"outline",children:"Outline"}),e.jsx(Pe,{value:"secondary",children:"Secondary"})]})]})]}),e.jsxs(x,{type:"button",onClick:h,size:"sm",children:[e.jsx(de,{className:"h-4 w-4 mr-1"}),"Add CTA"]})]})]}),r.length>=u&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Maximum ",u," CTAs reached. Remove one to add more."]})]})}function zr(){const{user:r}=oe(),[d,u]=i.useState(!1),[j,b]=i.useState(!1),[g,p]=i.useState(!1),[N,o]=i.useState(!1),[h,y]=i.useState(!1),[f,m]=i.useState(!1),[F,v]=i.useState(!1),[C,P]=i.useState(""),[z,q]=i.useState(""),[$,B]=i.useState(""),[X,ee]=i.useState(""),[G,A]=i.useState(""),[D,te]=i.useState(""),{data:_e,refetch:K}=Z({queryKey:["cms-integrations",r?.id],queryFn:async()=>
1{if(!r)return[];const{data:w,error:T}=await l.from("cms_integrations").select("id, platform, site_url, username, status, last_published, blog_id").eq("user_id",r.id).order("created_at",{ascending:!1});if(T)throw T;return w},enabled:!!r}),L=_e?.find(w=>w.platform==="wordpress"),Q=_e?.find(w=>w.platform==="shopify"),ke=async()=>{m(!0);try{const{data:{session:w},error:T}=await l.auth.getSession();if(T||!w){t.error("Session expired. Please refresh and try again."),m(!1);return}const{data:W,error:ae}=await l.functions.invoke("wordpress-oauth",{body:{action:"connect"}});if(ae)throw ae;W?.authUrl&&(window.location.href=W.authUrl)}catch(w){t.error(`Failed to connect: ${w.message||"Unknown error"}`),m(!1)}},ce=async()=>{if(!X.trim()){t.error("Please enter your store name");return}v(!0);try{const{data:{session:w},error:T}=await l.auth.getSession();if(T||!w){t.error("Session expired. Please refresh and try again."),v(!1);return}const W=X.trim().replace(/^https?:\/\//,"").replace(/\.myshopify\.com.*$/,"").replace(/\/+$/,""),{data:ae,error:ye}=await l.functions.invoke("shopify-oauth",{body:{action:"connect",shop:W}});if(ye)throw ye;ae?.authUrl&&(window.location.href=ae.authUrl)}catch(w){t.error(`Failed to connect: ${w.message||"Unknown error"}`),v(!1)}},Fe=async()=>{o(!0);try{const w=C.replace(/\/+$/,""),T=await fetch(`${w}/wp-json/wp/v2/users/me`,{headers:{Authorization:`Basic ${btoa(`${z}:${$}`)}`}});T.ok?t.success("WordPress connection verified!"):t.error(`Connection failed (${T.status}). Check your credentials.`)}catch{t.error("Could not reach your WordPress site. Check the URL.")}finally{o(!1)}},Ce=async()=>{if(!(!r||!C||!z||!$)){y(!0);try{const{error:w}=await l.from("cms_integrations").insert({user_id:r.id,platform:"wordpress",site_url:C.replace(/\/+$/,""),username:z,api_token:$,status:"active"});if(w)throw w;t.success("WordPress connected!"),u(!1),P(""),q(""),B(""),K()}catch(w){t.error(w.message||"Failed to save")}finally{y(!1)}}},fe=async()=>{o(!0);try{const w=G.replace(/\/+$/,""),T=await fetch(`${w}/admin/api/2024-01/shop.json`,{headers:{"X-Shopify-Access-Token":D}});T.ok?t.success("Shopify connection verified!"):t.error(`Connection failed (${T.status}). Check your token.`)}catch{t.error("Could not reach your Shopify store. Check the URL.")}finally{o(!1)}},Le=async()=>{if(!(!r||!G||!D)){y(!0);try{const{error:w}=await l.from("cms_integrations").insert({user_id:r.id,platform:"shopify",site_url:G.replace(/\/+$/,""),api_token:D,status:"active"});if(w)throw w;t.success("Shopify connected!"),p(!1),A(""),te(""),K()}catch(w){t.error(w.message||"Failed to save")}finally{y(!1)}}},ge=async(w,T)=>{try{const{error:W}=await l.from("cms_integrations").delete().eq("id",w);if(W)throw W;t.success(`${T==="wordpress"?"WordPress":"Shopify"} disconnected`),K()}catch(W){t.error(W.message||"Failed to disconnect")}},se=({status:w})=>e.jsx(he,{variant:w==="active"?"default":"destructive",className:"text-xs",children:w==="active"?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"h-3 w-3 mr-1"})," Active"]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-3 w-3 mr-1"})," Error"]})}),O=!!(C&&z&&$);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-medium flex items-center gap-2",children:[e.jsx(He,{className:"h-5 w-5"})," CMS Auto-Publish"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect your WordPress or Shopify site. When you publish an article here, it automatically appears on your site too."}),e.jsxs(U,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"font-medium",children:"WordPress"}),L?e.jsx(se,{status:L.status}):null]}),L?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(we,{className:"h-3 w-3"}),e.jsx("span",{children:L.site_url}),L.username==="__wpcom__"&&e.jsx(he,{variant:"outline",className:"text-xs",children:"WordPress.com"})]}),L.last_published&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last published: ",new Date(L.last_published).toLocaleDateString()]}),e.jsxs(x,{variant:"destructive",size:"sm",onClick:()=>ge(L.id,"wordpress"),children:[e.jsx(xe,{className:"h-3 w-3 mr-1"})," Disconnect"]})]}):d?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Site URL"}),e.jsx(I,{value:C,onChange:w=>P(w.target.value),placeholder:"https://myblog.com"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"WordPress Username"}),e.jsx(I,{value:z,onChange:w=>q(w.target.value),placeholder:"admin"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Application Password"}
1),e.jsx(I,{type:"password",value:$,onChange:w=>B(w.target.value),placeholder:"xxxx xxxx xxxx xxxx"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generate one at: WordPress Admin → Users → Profile → Application Passwords"})]}),e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-accent/50 text-xs text-muted-foreground",children:[e.jsx(Ie,{className:"h-3 w-3 mt-0.5 shrink-0"}),e.jsx("span",{children:'This is for self-hosted WordPress sites only. If your site is on WordPress.com, use the "Connect WordPress.com" button instead.'})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(x,{size:"sm",variant:"outline",onClick:Fe,disabled:N||!O,children:[N?e.jsx(E,{className:"h-3 w-3 animate-spin mr-1"}):null," Test"]}),e.jsxs(x,{size:"sm",onClick:Ce,disabled:h||!O,children:[h?e.jsx(E,{className:"h-3 w-3 animate-spin mr-1"}):null," Save"]}),e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>u(!1),children:"Cancel"})]})]}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(x,{size:"sm",variant:"outline",onClick:ke,disabled:f,children:[f?e.jsx(E,{className:"h-3 w-3 animate-spin mr-1"}):e.jsx(de,{className:"h-3 w-3 mr-1"}),"Connect WordPress.com"]}),e.jsxs(x,{size:"sm",variant:"ghost",onClick:()=>u(!0),children:[e.jsx(de,{className:"h-3 w-3 mr-1"})," Connect Self-Hosted WordPress"]})]})]}),e.jsxs(U,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"font-medium",children:"Shopify"}),Q?e.jsx(se,{status:Q.status}):null]}),Q?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(we,{className:"h-3 w-3"}),e.jsx("span",{children:Q.site_url}),Q.username==="__shopify_oauth__"&&e.jsx(he,{variant:"outline",className:"text-xs",children:"OAuth"})]}),Q.last_published&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last published: ",new Date(Q.last_published).toLocaleDateString()]}),e.jsxs(x,{variant:"destructive",size:"sm",onClick:()=>ge(Q.id,"shopify"),children:[e.jsx(xe,{className:"h-3 w-3 mr-1"})," Disconnect"]})]}):j?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Shopify Store Name"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(I,{value:X,onChange:w=>ee(w.target.value),placeholder:"mystore",className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:".myshopify.com"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Enter just the store name, e.g. "mystore" from mystore.myshopify.com'})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(x,{size:"sm",onClick:ce,disabled:F||!X.trim(),children:[F?e.jsx(E,{className:"h-3 w-3 animate-spin mr-1"}):null," Connect"]}),e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>{b(!1),ee("")},children:"Cancel"})]})]}):g?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Store URL"}),e.jsx(I,{value:G,onChange:w=>A(w.target.value),placeholder:"https://mystore.myshopify.com"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Admin API Access Token"}),e.jsx(I,{type:"password",value:D,onChange:w=>te(w.target.value),placeholder:"shpat_xxxxx"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Create a Custom App in Shopify Admin → Settings → Apps → Develop apps"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(x,{size:"sm",variant:"outline",onClick:fe,disabled:N||!G||!D,children:[N?e.jsx(E,{className:"h-3 w-3 animate-spin mr-1"}):null," Test"]}),e.jsxs(x,{size:"sm",onClick:Le,disabled:h||!G||!D,children:[h?e.jsx(E,{className:"h-3 w-3 animate-spin mr-1"}):null," Save"]}),e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>p(!1),children:"Cancel"})]})]}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(x,{size:"sm",variant:"outline",onClick:()=>b(!0),children:[e.jsx(de,{className:"h-3 w-3 mr-1"})," Connect Shopify"]}),e.jsxs(x,{size:"sm",variant:"ghost",onClick:()=>p(!0),children:[e.jsx(de,{className:"h-3 w-3 mr-1"})," Connect with API Token (Advanced)"]})]})]})]})}function qr(){const{user:r}=oe(),d=Ye(),[u,j]=nr(),[b,g]=i.useState(!1),[p,N]=i.useState(!1),[o,h]=i.useState(!1),[y,f]=i.useState(!1),[m,F]=i.useState([]),[v,C]=i.useState(""),[P,z]=i.useState(!1),{data:q,isLoading:$}=Z({queryKey:["gsc-connection",r?.id],queryFn:async()=>
1{if(!r)return null;const{data:A}=await l.from("gsc_connections").select("*").eq("user_id",r.id).single();return A},enabled:!!r});i.useEffect(()=>{if(u.get("gsc")==="select-property"&&q){B();const A=new URLSearchParams(u);A.delete("gsc"),j(A,{replace:!0})}},[q,u]),i.useEffect(()=>{q&&!q.site_url&&!P&&B()},[q]);const B=async()=>{h(!0),z(!0);try{const{data:A,error:D}=await l.functions.invoke("gsc-oauth",{method:"POST",body:{action:"list-properties"}});if(D){t.error("Failed to load properties: "+D.message);return}A?.sites&&(F(A.sites),A.sites.length===1&&C(A.sites[0].siteUrl))}catch{t.error("Failed to load properties")}finally{h(!1)}},X=async()=>{if(!v){t.error("Please select a property");return}f(!0);try{const{data:A,error:D}=await l.functions.invoke("gsc-oauth",{method:"POST",body:{action:"select-property",site_url:v}});if(D||!A?.success){t.error("Failed to save property selection");return}t.success(`Connected to ${v}`),z(!1),d.invalidateQueries({queryKey:["gsc-connection"]})}catch{t.error("Failed to save property selection")}finally{f(!1)}},ee=async()=>{g(!0);try{if(!(await l.auth.getSession()).data.session){t.error("Please sign in first");return}const{data:D,error:te}=await l.functions.invoke("gsc-oauth",{method:"POST",body:{action:"authorize"}});if(te){t.error("Failed to connect: "+te.message);return}D?.url?window.location.href=D.url:D?.error&&t.error(D.error)}catch(A){t.error("Failed to connect: "+(A.message||"Unknown error"))}finally{g(!1)}},G=async()=>{N(!0);try{const{data:A,error:D}=await l.functions.invoke("gsc-oauth",{method:"POST",body:{action:"disconnect"}});A?.success?(t.success("Google Search Console disconnected"),z(!1),F([]),d.invalidateQueries({queryKey:["gsc-connection"]})):t.error("Failed to disconnect")}catch{t.error("Failed to disconnect")}finally{N(!1)}};return $?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(E,{className:"h-4 w-4 animate-spin"})," Loading..."]}):q&&q.site_url&&!P?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ie,{className:"w-5 h-5 text-emerald-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Connected to Google Search Console"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:q.site_url})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(x,{variant:"outline",size:"sm",onClick:()=>B(),children:"Change Property"}),e.jsxs(x,{variant:"outline",size:"sm",onClick:G,disabled:p,children:[p?e.jsx(E,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(pe,{className:"h-4 w-4 mr-2"}),"Disconnect"]})]})]}):q&&P?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Google account connected. Select which property to track:"}),o?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(E,{className:"h-4 w-4 animate-spin"})," Loading properties..."]}):m.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsxs(gs,{value:v,onValueChange:C,children:[e.jsx(ys,{className:"w-full",children:e.jsx(js,{placeholder:"Select a property..."})}),e.jsx(bs,{children:m.map(A=>e.jsx(Pe,{value:A.siteUrl,children:A.siteUrl},A.siteUrl))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(x,{size:"sm",onClick:X,disabled:!v||y,children:[y?e.jsx(E,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ie,{className:"h-4 w-4 mr-2"}),"Confirm"]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:G,disabled:p,children:[p?e.jsx(E,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(pe,{className:"h-4 w-4 mr-2"}),"Disconnect"]})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:"No properties found in your Google Search Console account."}),e.jsx(x,{variant:"outline",size:"sm",onClick:G,disabled:p,children:"Disconnect"})]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect Google Search Console to track real keyword rankings, impressions, clicks, and average position for your published articles."}),e.jsxs(x,{onClick:ee,disabled:b,size:"sm",children:[b?e.jsx(E,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(cr,{className:"h-4 w-4 mr-2"}),"Connect Google Search Console"]})]})}const ms=[{id:"medium",name:"Medium",description:"100M+ readers. Auto-sets canonical URL back to ThoughtForge.",tokenLabel:"Integration Token",tokenHelp:"Get from medium.com/me/settings → Security and apps → Integration tokens"},{id:"devto",name:"Dev.to",description:"1M+ developers. Markdown-native, great for te
1chnical content.",tokenLabel:"API Key",tokenHelp:"Get from dev.to/settings/extensions → DEV Community API Keys"},{id:"hashnode",name:"Hashnode",description:"Developer publication network. Requires a publication ID.",tokenLabel:"Personal Access Token",tokenHelp:"Get from hashnode.com/settings/developer",needsPubId:!0}];function $r(){const{user:r}=oe(),d=Ye(),[u,j]=i.useState(null),[b,g]=i.useState(""),[p,N]=i.useState(""),[o,h]=i.useState(!1),{data:y}=Z({queryKey:["syndication-connections",r?.id],queryFn:async()=>{if(!r)return[];const{data:v}=await l.from("syndication_connections").select("platform, publication_id, created_at").eq("user_id",r.id);return v||[]},enabled:!!r}),f=v=>y?.some(C=>C.platform===v),m=async v=>{if(!r||!b.trim()){t.error("Token required");return}const C=ms.find(P=>P.id===v);if(C.needsPubId&&!p.trim()){t.error("Publication ID required for Hashnode");return}h(!0);try{const{error:P}=await l.from("syndication_connections").upsert({user_id:r.id,platform:v,api_token:b.trim(),publication_id:C.needsPubId?p.trim():null},{onConflict:"user_id,platform"});if(P)throw P;t.success(`${C.name} connected!`),j(null),g(""),N(""),d.invalidateQueries({queryKey:["syndication-connections"]})}catch(P){t.error(P?.message||"Failed to connect")}finally{h(!1)}},F=async v=>{if(r&&confirm(`Disconnect from ${v}? Existing syndicated posts will remain on the platform.`))try{const{error:C}=await l.from("syndication_connections").delete().eq("user_id",r.id).eq("platform",v);if(C)throw C;t.success("Disconnected"),d.invalidateQueries({queryKey:["syndication-connections"]})}catch(C){t.error(C?.message||"Failed to disconnect")}};return e.jsxs(U,{className:"p-6 space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"font-semibold",children:"Publication Syndication"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Auto-publish to Medium, Dev.to, and Hashnode with canonical URLs pointing back to your domain. SEO juice flows home — every syndicated post links back to you."})]}),e.jsx("div",{className:"space-y-3",children:ms.map(v=>{const C=f(v.id),P=u===v.id;return e.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5 flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:v.name}),C&&e.jsxs(he,{variant:"outline",className:"gap-1 text-[10px] text-foreground border-border",children:[e.jsx(lr,{className:"h-3 w-3"}),"Connected"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:v.description})]}),C?e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>F(v.id),className:"text-destructive hover:text-destructive",children:e.jsx(xe,{className:"h-3.5 w-3.5"})}):e.jsx(x,{size:"sm",variant:P?"outline":"default",onClick:()=>{j(P?null:v.id),g(""),N("")},children:P?"Cancel":"Connect"})]}),P&&!C&&e.jsxs("div",{className:"space-y-2 pt-2 border-t border-border",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:v.tokenLabel}),e.jsx(I,{type:"password",value:b,onChange:z=>g(z.target.value),placeholder:"Paste your token",className:"h-8 text-sm"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:v.tokenHelp})]}),v.needsPubId&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-xs",children:"Publication ID"}),e.jsx(I,{value:p,onChange:z=>N(z.target.value),placeholder:"e.g. 5f1a2b3c4d5e6f7a8b9c0d1e",className:"h-8 text-sm"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Find in Hashnode → your blog dashboard URL"})]}),e.jsxs(x,{size:"sm",onClick:()=>m(v.id),disabled:o,className:"w-full",children:[o?e.jsx(E,{className:"h-3 w-3 animate-spin mr-1"}):null,"Save & Connect"]})]})]},v.id)})})]})}function Wr(){const{user:r}=oe(),[d,u]=i.useState(!1),[j,b]=i.useState(!0),[g,p]=i.useState(!1),[N,o]=i.useState(null);i.useEffect(()=>{if(!r)return;let y=!1;return(async()=>{const{data:f,error:m}=await l.from("digest_preferences").select("weekly_digest_enabled, last_sent_at").eq("user_id",r.id).maybeSingle();y||(m&&console.warn("[WeeklyDigestSettings] load error:",m.message),u(!!f?.weekly_digest_enabled),o(f?.last_sent_at??null),b(!1))})(),()=>{y=!0}},[r]);const h=async y=>{if(!r)return;p(!0);const{error:f}=await l.from("digest_preferences").upsert({user_id:r.id,weekly_digest_enabled:y},{onConflict:"user_id"});if(p(!1),f){t.error("Could not save preference"),console.error(f);return}u(y),t.success(y?"Weekly digest enabled — first email arrives Monday 9am UTC":"Weekly digest disabled")};return e.jsx(U,{className:"p-6",children:e.jsxs("div",{className:"flex items-start justify-between gap-6",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("h2",{className:"text-xl font-medium mb-1 flex items-center gap-2",children:[e.jsx(ps,{className:"h-5 w-5"}),"Weekly performance digest"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Every Monday at 9am UTC, get a snapshot of your AI citations, humans driven from ChatGPT/Perplexity/Claude, GSC clicks & ranking moves, and what you published."}),N&&d&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Last sent: ",new Date(N).toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[j||g?e.jsx(E,{className:"h-4 w-4 animate-spin text-muted-foreground"}):null,e.jsx(k,{htmlFor:"weekly-digest-toggle",className:"sr-only",children:"Weekly digest"}),e.jsx(Ne,{id:"weekly-digest-toggle",checked:d,disabled:j||g,onCheckedChange:h})]})]})})}const hs={bio:!0,articles:!0,pillars:!0,projects:!1,newsletter:!0,socials:!0},Gr=[{key:"bio",label:"Bio",help:"Your short description on the public profile."},{key:"articles",label:"Articles",help:"Your published articles grid."},{key:"pillars",label:"Content pillars",help:"The themes you write about."},{key:"projects",label:"Projects / Portfolio",help:"Showcase work outside articles."},{key:"newsletter",label:"Newsletter signup",help:"Let readers subscribe."},{key:"socials",label:"Social links",help:"Show links to your other accounts."}];function Or(){const{user:r}=oe(),[d,u]=i.useState(hs),[j,b]=i.useState(!0),[g,p]=i.useState(!1);i.useEffect(()=>{r&&(async()=>{const{data:o}=await l.from("profiles").select("profile_visibility").eq("id",r.id).maybeSingle();o?.profile_visibility&&u({...hs,...o.profile_visibility}),b(!1)})()},[r]);const N=async o=>{if(!r)return;const h={...d,[o]:!d[o]};u(h),p(!0);const{error:y}=await l.from("profiles").update({profile_visibility:h}).eq("id",r.id);p(!1),y&&(t.error("Could not save visibility"),u(d))};return e.jsxs(U,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Public profile sections"}),g&&e.jsx(E,{className:"h-4 w-4 animate-spin text-muted-foreground"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Pick which sections appear on your public profile page."}),j?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(E,{className:"h-4 w-4 animate-spin"})," Loading…"]}):e.jsx("div",{className:"space-y-3",children:Gr.map(o=>e.jsxs("div",{className:"flex items-start justify-between gap-4 py-1",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(k,{className:"text-sm font-medium",children:o.label}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:o.help})]}),e.jsx(Ne,{checked:d[o.key],onCheckedChange:()=>N(o.key)})]},o.key))})]})}var Qe="Radio",[Mr,_s]=vs(Qe),[Br,Kr]=Mr(Qe),ks=i.forwardRef((r,d)=>{const{__scopeRadio:u,name:j,checked:b=!1,required:g,disabled:p,value:N="on",onCheck:o,form:h,...y}=r,[f,m]=i.useState(null),F=Xe(d,P=>m(P)),v=i.useRef(!1),C=f?h||!!f.closest("form"):!0;return e.jsxs(Br,{scope:u,checked:b,disabled:p,children:[e.jsx(Ae.button,{type:"button",role:"radio","aria-checked":b,"data-state":Is(b),"data-disabled":p?"":void 0,disabled:p,value:N,...y,ref:F,onClick:Ke(r.onClick,P=>{b||o?.(),C&&(v.current=P.isPropagationStopped(),v.current||P.stopPropagation())})}),C&&e.jsx(Ps,{control:f,bubbles:!v.current,name:j,value:N,checked:b,required:g,disabled:p,form:h,style:{transform:"translateX(-100%)"}})]})});ks.displayName=Qe;var Cs="RadioIndicator",Ss=i.forwardRef((r,d)=>{const{__scopeRadio:u,forceMount:j,...b}=r,g=Kr(Cs,u);return e.jsx(Sr,{present:j||g.checked,children:e.jsx(Ae.span,{"data-state":Is(g.checked),"data-disabled":g.disabled?"":void 0,...b,ref:d})})});Ss.displayName=Cs;var Vr="RadioBubbleInput",Ps=i.forwardRef(({__scopeRadio:r,control:d,checked:u,bubbles:j=!0,...b},g)=>{const p=i.useRef(null),N=Xe(p,g),o=Pr(u),h=Ir(d);return i.useEffect(()=>{const y=p.current;if(!y)return;const f=window.HTMLInputElement.prototype,F=Object.getOwnPropertyDescriptor(f,"checked").set;if(o!==u&&F){const v=new Event("click",{bubbles:j});F.call(y,u),y.dispatchEvent(v)}},[o,u,j]),e.jsx(Ae.input,{type:"radio","aria-hidden":!0,defaultChecked:u,...b,tabIndex:-1,ref:N,style:{...b.style,...h,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Ps.displayName=Vr;function Is(r){return r?"checked":"unchecked"}var Yr=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Te="RadioGroup",[Hr,At]=vs(Te,[ws,_s]),As=ws(),Ts=_s(),[Xr,Qr]=Hr(Te),Fs=i.forwardRef((r,d)=>{const{__scopeRadioGroup:u,name:j,defaultValue:b,value:g,required:p=!1,disabled:N=!1,orientation:o,dir:h,loop:y=!0,onValueChange:f,...m}=r,F=As(u),v=Ar(h),[C,P]=Tr({prop:g,defaultProp:b??null,onChange:f,caller:Te});return e.jsx(Xr,{scope:u,name:j,required:p,disabled:N,value:C,onValueChange:P,children:e.jsx(Fr,{asChild:!0,...F,orientation:o,dir:v,loop:y,children:e.jsx(Ae.div,{role:"radiogroup","aria-required":p,"aria-orientation":o,"data-disabled":N?"":void 0,dir:v,...m,ref:d})})})});Fs.displayName=Te;var Ls="RadioGroupItem",Rs=i.forwardRef((r,d)=>{const{__scopeRadioGroup:u,disabled:j,...b}=r,g=Qr(Ls,u),p=g.disabled||j,N=As(u),o=Ts(u),h=i.useRef(null),y=Xe(d,h),f=g.value===b.value,m=i.useRef(!1);return i.useEffect(()=>{const F=C=>{Yr.includes(C.key)&&(m.current=!0)},v=()=>m.current=!1;return document.addEventListener("keydown",F),document.addEventListener("keyup",v),()=>{document.removeEventListener("keydown",F),document.removeEventListener("keyup",v)}}
1,[]),e.jsx(Lr,{asChild:!0,...N,focusable:!p,active:f,children:e.jsx(ks,{disabled:p,required:g.required,checked:f,...o,...b,name:g.name,ref:y,onCheck:()=>g.onValueChange(b.value),onKeyDown:Ke(F=>{F.key==="Enter"&&F.preventDefault()}),onFocus:Ke(b.onFocus,()=>{m.current&&h.current?.click()})})})});Rs.displayName=Ls;var Jr="RadioGroupIndicator",Es=i.forwardRef((r,d)=>{const{__scopeRadioGroup:u,...j}=r,b=Ts(u);return e.jsx(Ss,{...b,...j,ref:d})});Es.displayName=Jr;var Us=Fs,Ds=Rs,Zr=Es;const zs=i.forwardRef(({className:r,...d},u)=>e.jsx(Us,{className:xs("grid gap-2",r),...d,ref:u}));zs.displayName=Us.displayName;const Ve=i.forwardRef(({className:r,...d},u)=>e.jsx(Ds,{ref:u,className:xs("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",r),...d,children:e.jsx(Zr,{className:"flex items-center justify-center",children:e.jsx(Rr,{className:"h-2.5 w-2.5 fill-current text-current"})})}));Ve.displayName=Ds.displayName;const et={brand_text:"",brand_show_on_images:!0,brand_position:"corner"};function st(){const{user:r}=oe(),[d,u]=i.useState(et),[j,b]=i.useState(""),[g,p]=i.useState(!0),[N,o]=i.useState(!1);i.useEffect(()=>{r&&(async()=>{const{data:f}=await l.from("profiles").select("brand_text, brand_show_on_images, brand_position, username").eq("id",r.id).maybeSingle();f&&(u({brand_text:f.brand_text||"",brand_show_on_images:f.brand_show_on_images!==!1,brand_position:f.brand_position||"corner"}),b(f.username?`@${f.username}`:"")),p(!1)})()},[r]);const h=async()=>{if(!r)return;o(!0);const{error:f}=await l.from("profiles").update({brand_text:d.brand_text.trim()||null,brand_show_on_images:d.brand_show_on_images,brand_position:d.brand_position}).eq("id",r.id);if(o(!1),f){t.error("Could not save branding");return}t.success("Image branding saved")};if(g)return e.jsxs(U,{className:"p-6 flex items-center gap-2 text-muted-foreground",children:[e.jsx(E,{className:"w-4 h-4 animate-spin"})," Loading branding…"]});const y=d.brand_text.trim()||j;return e.jsxs(U,{className:"p-6 space-y-5",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Image branding"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Adds a small mark to carousel images so saves and reshares trace back to you."})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(k,{htmlFor:"brand-show",children:"Show on generated images"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Turn off if you'd rather post clean slides."})]}),e.jsx(Ne,{id:"brand-show",checked:d.brand_show_on_images,onCheckedChange:f=>u(m=>({...m,brand_show_on_images:f}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"brand-text",children:"Brand text"}),e.jsx(I,{id:"brand-text",placeholder:j||"@yourhandle or yourbrand.com",value:d.brand_text,onChange:f=>u(m=>({...m,brand_text:f.target.value})),maxLength:40,disabled:!d.brand_show_on_images}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y?e.jsxs(e.Fragment,{children:["Will render as ",e.jsx("span",{className:"font-mono",children:y}),"."]}):"Leave blank to use your username."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Position"}),e.jsxs(zs,{value:d.brand_position,onValueChange:f=>u(m=>({...m,brand_position:f})),disabled:!d.brand_show_on_images,className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ve,{id:"pos-corner",value:"corner",className:"mt-1"}),e.jsxs(k,{htmlFor:"pos-corner",className:"font-normal cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:"Top-right corner"})," · subtle, on every slide"]})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ve,{id:"pos-last",value:"last_slide",className:"mt-1"}),e.jsxs(k,{htmlFor:"pos-last",className:"font-normal cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:"Last slide only"})," · larger signature"]})]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(x,{onClick:h,disabled:N,children:[N&&e.jsx(E,{className:"w-4 h-4 mr-2 animate-spin"}),"Save branding"]})})]})}const rt=H().trim().email().max(255),Be=r=>`Best,
2${r&&r.trim()||"Your name"}`;function tt({userId:r,userEmail:d,username:u,initialEnabled:j,initialReplyTo:b,initialSignature:g,fullName:p,onSaved:N}){const[o,h]=i.useState(j),[y,f]=i.useState(b||d||""),[m,F]=i.useState(g??Be(p)),[v,C]=i.useState(!1);i.useEffect(()=>h(j),[j]),i.useEffect(()=>{f(b||d||"")},[b,d]),i.useEffect(()=>{F(g??Be(p))},[g,p]);const P=u?`${window.location.origin}/user/${u}`:null,z=async()=>{P&&(await navigator.clipboard.writeText(P),t.success("Signup link copied"))},q=async()=>
2{if(!r)return;const $=y.trim();if($&&!rt.safeParse($).success){t.error("Enter a valid reply-to email");return}const B=m.trim();if(B.length>500){t.error("Signature must be 500 characters or less");return}C(!0);const{error:X}=await l.from("profiles").update({newsletter_enabled:o,newsletter_reply_to_email:$||null,newsletter_signature:B||null}).eq("id",r);if(C(!1),X){t.error(X.message||"Failed to save");return}t.success("Newsletter settings saved"),N?.()};return e.jsxs(U,{className:"p-6 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ps,{className:"h-5 w-5"}),e.jsx("h2",{className:"text-xl font-medium",children:"Newsletter"})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(k,{className:"text-base",children:"Enable newsletter"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Turn on the public signup form on your profile and allow sending campaigns."})]}),e.jsx(Ne,{checked:o,onCheckedChange:h})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"reply_to",children:"Reply-to email"}),e.jsx(I,{id:"reply_to",type:"email",value:y,onChange:$=>f($.target.value),placeholder:d||"[email protected]",className:"bg-card"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Newsletters are sent from ",e.jsx("code",{children:"[email protected]"}),", but replies go directly to this address. Defaults to your account email."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"signature",children:"Email signature"}),e.jsx(Se,{id:"signature",value:m,onChange:$=>F($.target.value),placeholder:Be(p),rows:4,maxLength:500,className:"bg-card font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Appears at the end of every newsletter (and test send). Plain text only — line breaks are kept. Leave blank to use ",e.jsxs("em",{children:["Best, ",p||"your name"]}),`. So you don't double-sign, skip writing "Cheers!" or your name at the end of the newsletter itself.`]})]}),P&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Public signup link"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{value:P,readOnly:!0,className:"bg-card font-mono text-sm"}),e.jsx(x,{type:"button",variant:"outline",size:"icon",onClick:z,children:e.jsx(Er,{className:"h-4 w-4"})}),e.jsx(x,{type:"button",variant:"outline",size:"icon",asChild:!0,children:e.jsx("a",{href:P,target:"_blank",rel:"noreferrer",children:e.jsx(we,{className:"h-4 w-4"})})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Share this link to start collecting subscribers."})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(x,{type:"button",onClick:q,disabled:v,children:v?"Saving...":"Save newsletter settings"})})]})}function at(){const{user:r}=oe(),[d,u]=i.useState(!0),[j,b]=i.useState(!0);i.useEffect(()=>{r&&(async()=>{const{data:p}=await l.from("profiles").select("humanity_prompt_on_publish").eq("id",r.id).maybeSingle();p&&typeof p.humanity_prompt_on_publish=="boolean"&&u(p.humanity_prompt_on_publish),b(!1)})()},[r]);const g=async p=>{if(u(p),!r)return;const{error:N}=await l.from("profiles").update({humanity_prompt_on_publish:p}).eq("id",r.id);N&&(t.error("Couldn't save preference"),u(!p))};return e.jsx(U,{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(dr,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Prove your humanity"}),e.jsx("span",{className:"text-[10px] uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:"Optional"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-4 max-w-prose",children:["After you publish, sign any post with Face ID, Touch ID, Windows Hello, or a hardware key via"," ",e.jsx("span",{className:"font-medium text-foreground",children:"gethumanity.id"}),". The signature is hardware-bound to your device and your post shows a Verified Human Origin badge anyone can click to inspect the certificate. Edit the post later and we'll prompt you to re-sign."]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-card/50 px-3 py-2.5 mb-4",children:[e.jsx(k,{htmlFor:"humanity-prompt",className:"text-sm cursor-pointer flex-1",children:"Prompt me to sign each post after publishing"}),e.jsx(Ne,{id:"humanity-prompt",checked:d,onCheckedChange:g,disabled:j})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(x,{asChild:!0,size:"sm",children:e.jsxs("a",{href:"https://gethumanity.id",target:"_blank",rel:"noopener noreferrer",children:["Visit GetHumanity.id",e.jsx(we,{className:"h-3.5 w-3.5"})]})}),e.jsx(x,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs("a",{href:"https://chromewebstore.google.com/search/gethumanity",target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ur,{className:"h-3.5 w-3.5"}),"Chrome extension"]})})]})]})]})})}const nt={role_title:"",linkedin_url:"",twitter_url:"",github_url:"",youtube_url:"",medium_url:"",substack_url:"",personal_url:""};function it({userId:r}){const[d,u]=i.useState(nt),[j,b]=i.useState(!0),[g,p]=i.useState(!1);i.useEffect(()=>{r&&(async()=>{const{data:h,error:y}=await l.from("profiles").select("role_title, linkedin_url, twitter_url, github_url, youtube_url, medium_url, substack_url, personal_url").eq("id",r).maybeSingle();!y&&h&&u({role_title:h.role_title||"",linkedin_url:h.linkedin_url||"",twitter_url:h.twitter_url||"",github_url:h.github_url||"",youtube_url:h.youtube_url||"",medium_url:h.medium_url||"",substack_url:h.substack_url||"",personal_url:h.personal_url||""}),b(!1)})()},[r]);const N=h=>y=>u(f=>({...f,[h]:y.target.value})),o=async()=>
2{if(!r)return;const h=Object.fromEntries(Object.entries(d).map(([f,m])=>[f,m.trim()===""?null:m.trim()]));p(!0);const{error:y}=await l.from("profiles").update(h).eq("id",r);p(!1),y?t.error("Failed to save identity",{description:y.message}):t.success("Author identity saved",{description:"Your articles now emit stronger entity signals to AI models."})};return j?null:e.jsxs(U,{className:"p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(fs,{className:"h-5 w-5 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Author Identity (for AI citations)"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"ChatGPT, Perplexity, Claude, and Gemini build entity graphs to decide who to cite. Filling these once links every article you publish to a real, identifiable person — the single biggest unlock for getting cited by name in AI answers."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"role_title",children:"Role / Title"}),e.jsx(I,{id:"role_title",value:d.role_title,onChange:N("role_title"),placeholder:"e.g. Founder of ThoughtForge",className:"bg-card"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Emitted as ",e.jsx("code",{children:"Person.jobTitle"})," in JSON-LD."]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"linkedin_url",children:"LinkedIn URL"}),e.jsx(I,{id:"linkedin_url",value:d.linkedin_url,onChange:N("linkedin_url"),placeholder:"https://www.linkedin.com/in/your-handle",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"twitter_url",children:"X / Twitter URL"}),e.jsx(I,{id:"twitter_url",value:d.twitter_url,onChange:N("twitter_url"),placeholder:"https://x.com/your-handle",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"personal_url",children:"Personal site"}),e.jsx(I,{id:"personal_url",value:d.personal_url,onChange:N("personal_url"),placeholder:"https://yourname.com",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"github_url",children:"GitHub URL"}),e.jsx(I,{id:"github_url",value:d.github_url,onChange:N("github_url"),placeholder:"https://github.com/your-handle",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"youtube_url",children:"YouTube channel"}),e.jsx(I,{id:"youtube_url",value:d.youtube_url,onChange:N("youtube_url"),placeholder:"https://youtube.com/@your-handle",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"medium_url",children:"Medium profile"}),e.jsx(I,{id:"medium_url",value:d.medium_url,onChange:N("medium_url"),placeholder:"https://medium.com/@your-handle",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(k,{htmlFor:"substack_url",children:"Substack"}),e.jsx(I,{id:"substack_url",value:d.substack_url,onChange:N("substack_url"),placeholder:"https://yourname.substack.com",className:"bg-card"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(x,{onClick:o,disabled:g,size:"sm",children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),g?"Saving...":"Save identity"]})})]})}const ot=_r({username:H().min(3,"Username must be at least 3 characters").max(20,"Username must be less than 20 characters").regex(/^[a-z0-9_]+$/,"Username must be lowercase letters, numbers, and underscores only").optional(),name:H().optional(),headline:H().optional(),avatar_url:H().url().optional().or(kr("")),writing_tone:H().optional(),avoid_words:H().optional(),topics:H().optional(),offers:H().optional(),writing_rules:H().optional(),business_description:H().optional(),ideal_customer:H().optional(),primary_goal:H().optional()});function Tt(){const{user:r,loading:d}=oe(),{tier:u,subscribed:j,subscriptionEnd:b,isTrial:g,refreshSubscription:p,loading:N}=mr(),o=ir(),h=or(),y=Ye(),[f,m]=i.useState("saved"),[F,v]=i.useState(!1),[C,P]=i.useState(!1),[z,q]=i.useState(!1),[$,B]=i.useState(!1),[X,ee]=i.useState(!1),[G,A]=i.useState(!1),[D,te]=i.useState(!1),[_e,K]=i.useState(!1),L=i.useRef(!1),[Q,ke]=i.useState([]),[ce,Fe]=i.useState(!1);i.useEffect(()=>{r&&l.from("user_roles").select("role").eq("user_id",r.id).eq("role","admin").maybeSingle().then(({data:s})=>Fe(!!s))},[r]),i.useEffect(()=>{if(h.hash==="#subscription"){const s=setTimeout(()=>{document.getElementById("subscription")?.scrollIntoView({behavior:"smooth",block:"center"})},400);return()=>clearTimeout(s)}},[h.hash]);const Ce=i.useRef(!1);i.useEffect(()=>{const s=new URLSearchParams(h.search);if(s.get("card_updated")!=="1"||Ce.current)return;Ce.current=!0;const n=s.get("session_id");(async()=>{try{if(n){const{data:a,error:c}=await l.functions.invoke("update-payment-method",{body:{session_id:n}});if(c)throw c;if(!a?.success)throw new Error(a?.error||"Could not confirm card update")}t.success("Payment method updated",{description:"Your new card is now the default for future charges."})}catch(a){t.error("Couldn't confirm card update",{description:a instanceof Error?a.message:String(a)})}finally{o("/profile#subscription",{replace:!0})}})()},[h.search,o]);const{data:fe,isLoading:Le}=Z({queryKey:["billing-invoices",r?.id],queryFn:async()=>{const{data:s,error:n}=await l.functions.invoke("list-invoices");if(n)throw n;if(!s?.success)throw new Error(s?.error||"Failed to load billing history");return s.invoices??[]},enabled:!!r&&j,staleTime:5*60*1e3}),[ge,se]=i.useState([]),{register:O,handleSubmit:w,setValue:T,watch:W,formState:{isDirty:ae,errors:ye}}=Nr({resolver:Cr(ot),defaultValues:{username:"",name:"",headline:"",avatar_url:"",writing_tone:"conversational",avoid_words:"",topics:"",offers:"",writing_rules:"",business_description:"",ideal_customer:"",primary_goal:"aeo_geo"}}),{data:M}=Z({queryKey:["writer-profile",r?.id],queryFn:async()=>
2{if(!r)return null;const{data:s,error:n}=await l.from("writer_profiles").select("*").eq("user_id",r.id).maybeSingle();if(n)throw n;return s},enabled:!!r}),{data:R}=Z({queryKey:["user-profile",r?.id],queryFn:async()=>{if(!r)return null;const{data:s,error:n}=await l.from("profiles").select("*").eq("id",r.id).single();if(n)throw n;return s},enabled:!!r}),[Je,Re]=i.useState(null),[qs,Ze]=i.useState(!1),le=W("username"),{data:Ee,refetch:es}=Z({queryKey:["linkedin-connection",r?.id],queryFn:async()=>{if(!r)return null;const{data:s,error:n}=await l.from("linkedin_connections").select("*").eq("user_id",r.id).single();if(n&&n.code!=="PGRST116")throw n;return s},enabled:!!r}),{data:ue,refetch:ss}=Z({queryKey:["twitter-connection",r?.id],queryFn:async()=>{if(!r)return null;const{data:s,error:n}=await l.from("twitter_connections").select("*").eq("user_id",r.id).single();if(n&&n.code!=="PGRST116")throw n;return s},enabled:!!r}),{data:Ue,refetch:rs}=Z({queryKey:["threads-connection",r?.id],queryFn:async()=>{if(!r)return null;const{data:s,error:n}=await l.from("threads_connections").select("*").eq("user_id",r.id).single();if(n&&n.code!=="PGRST116")throw n;return s},enabled:!!r}),[ts,as]=i.useState(!1),{data:ne,refetch:$s}=Z({queryKey:["writer-patterns",r?.id],queryFn:async()=>{if(!r)return null;const{data:s,error:n}=await l.from("writer_patterns").select("*").eq("user_id",r.id).single();if(n&&n.code!=="PGRST116")throw n;return s},enabled:!!r}),Ws=async()=>{if(r){as(!0);try{const s=await l.auth.getSession();if(!s.data.session)throw new Error("Not authenticated");const{data:n,error:a}=await l.functions.invoke("analyze-writing-patterns",{headers:{Authorization:`Bearer ${s.data.session.access_token}`}});if(a)throw a;n?.patterns?(t.success("Voice analysis complete!",{description:`Analyzed ${n.patterns.articles_analyzed||"your"} published articles`}),$s()):n?.message?.includes("No published posts")&&t.info("No published posts found",{description:"Publish some articles first so I can learn your writing style"})}catch(s){console.error("Voice analysis error:",s),t.error("Failed to analyze voice",{description:s.message||"Please try again"})}finally{as(!1)}}},[je,Gs]=i.useState(null),[ct,Os]=i.useState(""),[Ms,ns]=i.useState(!1),{data:me,refetch:is}=Z({queryKey:["ip-exclusions",r?.id],queryFn:async()=>{if(!r)return[];const{data:s,error:n}=await l.from("user_ip_exclusions").select("*").eq("user_id",r.id).order("created_at",{ascending:!1});if(n)throw n;return s},enabled:!!r});i.useEffect(()=>{(async()=>{try{const a=await(await fetch("https://api.ipify.org?format=json")).json();Gs(a.ip)}catch(n){console.error("Failed to fetch IP:",n)}})()},[]);const Bs=async(s,n)=>{if(r){ns(!0);try{const{error:a}=await l.from("user_ip_exclusions").insert({user_id:r.id,ip_address:s,label:n||null});if(a)if(a.message.includes("duplicate"))t.error("This IP address is already excluded");else throw a;else t.success("IP address excluded from analytics"),is(),Os("")}catch(a){t.error(a.message||"Failed to add IP exclusion")}finally{ns(!1)}}},Ks=async s=>{try{const{error:n}=await l.from("user_ip_exclusions").delete().eq("id",s);if(n)throw n;t.success("IP exclusion removed"),is()}catch(n){t.error(n.message||"Failed to remove IP exclusion")}};i.useEffect(()=>{const n=setTimeout(async()=>{if(!le||le===R?.username){Re(null);return}if(le.length<3){Re(null);return}Ze(!0);const{data:a,error:c}=await l.from("profiles").select("username").eq("username",le).maybeSingle();Ze(!1),Re(!a&&!c)},500);return()=>clearTimeout(n)},[le,R?.username]),i.useEffect(()=>{if(d||!r)return;const s=new URLSearchParams(h.search),n=s.get("linkedin"),a=s.get("twitter"),c=s.get("wordpress"),_=s.get("shopify"),S=s.get("threads");if(n==="callback"){if(L.current)return;const V=s.get("code"),J=s.get("state"),Y=s.get("error"),re=s.get("error_description");Y?(t.error(`LinkedIn error: ${re||Y}`),console.error("LinkedIn OAuth error:",{error:Y,errorDescription:re}),o("/profile",{replace:!0})):V?(L.current=!0,K(!0),window.history.replaceState({},document.title,"/profile"),Vs(V,J).finally(()=>{K(!1),L.current=!1})):(t.error("No authorization code received from LinkedIn"),o("/profile",{replace:!0}))}else if(a==="callback"){if(L.current)return;const V=s.get("code"),J=s.get("state"),Y=s.get("error"),re=s.get("error_description");Y?(t.error(`Twitter error: ${re||Y}`),console.error("Twitter OAuth error:",{error:Y,errorDescription:re}),o("/profile",{replace:!0})):V?(L.current=!0,K(!0),window.history.replaceState({},document.title,"/profile"),Xs(V,J).finally(()=>{K(!1),L.current=!1})):(t.error("No authorization code received from Twitter"),o("/profile",{replace:!0}))}else if(c==="callback"){if(L.current)return;const V=s.get("code"),J=s.get("state"),Y=s.get("error"),re=s.get("error_description");Y?(t.error(`WordPress error: ${re||Y}`),o("/profile",{replace:!0})):V?(L.current=!0,K(!0),window.history.replaceState({},document.title,"/profile"),sr(V,J).finally(()=>{K(!1),L.current=!1})):(t.error("No authorization code received from WordPress"),o("/profile",{replace:!0}))}else if(_==="callback"){if(L.current)return;const V=s.get("code"),J=s.get("shop"),Y=s.get("state"),re=s.get("error"),tr=s.get("error_description");re?(t.error(`Shopify error: ${tr||re}`),o("/profile",{replace:!0})):V&&J?(L.current=!0,K(!0),window.history.replaceState({},document.title,"/profile"),(async()=>{try{const{data:ve,error:ls}=await l.functions.invoke("shopify-oauth",{body:{action:"callback",code:V,shop:J,state:Y}});if(ls)throw ls;if(ve?.success)t.success("Shopify connected. Auto-publishing enabled."),y.invalidateQueries({queryKey:["cms-integrations"]}),o("/profile",{replace:!0});else throw new Error(ve?.error||"Unknown error")}catch(ve){t.error(`Failed to connect Shopify: ${ve.message||ve}`),o("/profile",{replace:!0})}finally{K(!1),L.current=!1}})()):(t.error("No authorization code received from Shopify"),o("/profile",{replace:!0}))}
2else if(S==="callback"){if(L.current)return;const V=s.get("code"),J=s.get("error"),Y=s.get("error_description");J?(t.error(`Threads error: ${Y||J}`),o("/profile",{replace:!0})):V?(L.current=!0,K(!0),window.history.replaceState({},document.title,"/profile"),Js(V).finally(()=>{K(!1),L.current=!1})):(t.error("No authorization code received from Threads"),o("/profile",{replace:!0}))}},[h.search,d,r,o]);const Vs=async(s,n)=>{if(!n){t.error("Invalid OAuth response. Please try again."),o("/profile",{replace:!0});return}try{const{data:a,error:c}=await l.functions.invoke("linkedin-oauth",{body:{action:"callback",code:s,state:n}});if(c){console.error("LinkedIn OAuth error:",c);let _=c.message;if(c instanceof Me)try{const S=await c.context.json();_=S.message||S.error||c.message}catch(S){console.error("Failed to parse error body:",S)}_?.includes("Security validation failed")||_?.includes("state mismatch")?t.error("Security check failed. This may happen if you switched accounts. Please try connecting again."):_?.includes("Unauthorized")||_?.includes("session")?t.error("Session expired. Please refresh the page and try again."):t.error(`Failed to connect: ${_||"Unknown error"}`),o("/profile",{replace:!0});return}if(a?.success)t.success("LinkedIn connected. Publishing enabled."),es(),window.history.replaceState({},document.title,"/profile"),o("/profile",{replace:!0});else throw new Error(a?.error||"Unknown error")}catch(a){t.error(`Failed to connect LinkedIn: ${a.message||a}`),console.error("LinkedIn callback error:",a),o("/profile",{replace:!0})}},Ys=async()=>{ee(!0);try{const{data:{session:s},error:n}=await l.auth.getSession();if(n||!s){t.error("Your session has expired. Please refresh the page and try again."),ee(!1);return}const{data:a,error:c}=await l.functions.invoke("linkedin-oauth",{body:{action:"connect"}});if(c){if(c.message?.includes("Unauthorized")||c.message?.includes("session"))t.error("Session expired. Please refresh the page and try again.");else throw c;ee(!1);return}a?.authUrl&&(window.location.href=a.authUrl)}catch(s){t.error(`Failed to connect: ${s.message||"Unknown error"}`),console.error("LinkedIn connection error:",s),ee(!1)}},be=async()=>{try{localStorage.clear(),sessionStorage.clear(),await l.auth.signOut(),t.success("Logged out successfully"),o("/")}catch{localStorage.clear(),sessionStorage.clear(),o("/")}},Hs=async()=>{try{const{data:{session:s},error:n}=await l.auth.getSession();if(n||!s){t.error("Session expired. Please log in again."),be();return}const{error:a}=await l.functions.invoke("linkedin-oauth",{body:{action:"disconnect"}});if(a){if(a.message?.includes("Unauthorized")||a.message?.includes("session")){t.error("Session expired. Logging you out..."),be();return}throw a}t.success("LinkedIn disconnected"),es()}catch(s){console.error("Disconnect error:",s),t.error(`Failed to disconnect LinkedIn: ${s.message||"Unknown error"}`)}},Xs=async(s,n)=>{if(!n){t.error("Invalid OAuth response. Please try again."),o("/profile",{replace:!0});return}try{const{data:a,error:c}=await l.functions.invoke("twitter-oauth",{body:{action:"callback",code:s,state:n}});if(c){console.error("Twitter OAuth error:",c);let _=c.message||"Unknown error";if(c instanceof Me)try{_=(await c.context.json()).error||_}catch{}t.error("Failed to connect Twitter",{description:_}),o("/profile",{replace:!0});return}if(a?.success)t.success(a.username?`Twitter connected as @${a.username}`:"Twitter connected successfully!"),ss(),window.history.replaceState({},document.title,"/profile"),o("/profile",{replace:!0});else if(a?.success===!1){const _=a.error||"Unknown error",S=a.errorCode||"";console.error("Twitter OAuth structured error:",S,_),S==="TOKEN_EXCHANGE_FAILED"?t.error("Authorization expired",{description:"Please try connecting again."}):S==="PROFILE_FETCH_FAILED"?t.error("Could not fetch Twitter profile",{description:"Please disconnect and reconnect your account."}):S==="INVALID_STATE"?t.error("Security check failed",{description:"Please try connecting again."}):t.error("Failed to connect Twitter",{description:_}),o("/profile",{replace:!0})}else throw new Error(a?.error||"Unknown error")}catch(a){t.error(`Failed to connect Twitter: ${a.message||a}`),console.error("Twitter callback error:",a),o("/profile",{replace:!0})}},os=async()=>{A(!0);try{const{data:{session:s},error:n}=await l.auth.getSession();if(n||!s){t.error("Your session has expired. Please refresh the page and try again."),A(!1);return}const{data:a,error:c}=await l.functions.invoke("twitter-oauth",{body:{action:"connect"}});if(c)throw c;a?.authUrl&&(window.location.href=a.authUrl)}catch(s){t.error(`Failed to connect: ${s.message||"Unknown error"}`),console.error("Twitter connection error:",s),A(!1)}},Qs=async()=>{try{const{data:{session:s},error:n}=await l.auth.getSession();if(n||!s){t.error("Session expired. Please log in again."),be();return}const{error:a}=await l.functions.invoke("twitter-oauth",{body:{action:"disconnect"}});if(a)throw a;t.success("Twitter disconnected"),ss()}catch(s){console.error("Disconnect error:",s),t.error(`Failed to disconnect Twitter: ${s.message||"Unknown error"}`)}},Js=async s=>{try{const n=`${window.location.origin}/profile?threads=callback`,{data:a,error:c}=await l.functions.invoke("threads-oauth",{body:{action:"exchange-code",code:s,redirectUri:n}});if(c){console.error("Threads OAuth error:",c);let _=c.message||"Unknown error";if(c instanceof Me)try{_=(await c.context.json())?.error||_}catch{}_.includes("threads_basic")?t.error("Your Threads account must be added as a tester in Meta Developer Console, or the app must pass review."):t.error(`Failed to connect Threads: ${_}`),o("/profile",{replace:!0});return}if(a?.success)t.success(`Threads connected${a.username?` as @${a.username}`:""}`),rs(),o("/profile",{replace:!0});else throw new Error(a?.error||"Unknown error")}catch(n){t.error(`Failed to connect Threads: ${n.message||n}`),console.error("Threads callback error:",n),o("/profile",{replace:!0})}},Zs=async()=>{te(!0);try{const{data:{session:s},error:n}=await l.auth.getSession();if(n||!s){t.error("Your session has expired. Please refresh the page and try again."),te(!1);return}const a=`${window.location.origin}/profile?threads=callback`,{data:c,error:_}=await l.functions.invoke("threads-oauth",{body:{action:"get-auth-url",redirectUri:a}});if(_)throw _;c?.authUrl&&(window.location.href=c.authUrl)}catch(s){t.error(`Failed to connect: ${s.message||"Unknown error"}`),console.error("Threads connection error:",s),te(!1)}},er=async()=>{try{const{data:{session:s},error:n}=await l.auth.getSession();if(n||!s){t.error("Session expired. Please log in again."),be();return}const{error:a}=await l.functions.invoke("threads-oauth",{body:{action:"disconnect"}});if(a)throw a;t.success("Threads disconnected"),rs()}catch(s){console.error("Disconnect error:",s),t.error(`Failed to disconnect Threads: ${s.message||"Unknown error"}`)}},sr=async(s,n)=>{if(!n){t.error("Invalid OAuth response. Please try again."),o("/profile",{replace:!0});return}try{const{data:a,error:c}=await l.functions.invoke("wordpress-oauth",{body:{action:"callback",code:s,state:n}});if(c){console.error("WordPress OAuth error:",c),t.error(`Failed to connect: ${c.message||"Unknown error"}`),o("/profile",{replace:!0});return}if(a?.success)t.success("WordPress.com connected"),y.invalidateQueries({queryKey:["cms-integrations"]}),o("/profile",{replace:!0});else throw new Error(a?.error||"Unknown error")}catch(a){t.error(`Failed to connect WordPress: ${a.message||a}`),o("/profile",{replace:!0})}};i.useEffect(()=>{R&&T("username",R.username||"")},[R,T]),i.useEffect(()=>{if(M){T("name",M.name||""),T("headline",M.headline||""),T("avatar_url",M.avatar_url||"");const s=M.writing_voice;T("writing_tone",s?.tone||"conversational"),T("avoid_words",Array.isArray(s?.avoid_words)?s.avoid_words.join(", "):"");const n=M.topics;T("topics",Array.isArray(n)?n.join(", "):"");const a=M.offers;T("offers",Array.isArray(a)?a.map(S=>`${S.name}: ${S.url}`).join(`
3`):""),T("writing_rules",M.writing_rules||""),T("business_description",M.business_description||""),T("ideal_customer",M.ideal_customer||""),T("primary_goal",M.primary_goal||"aeo_geo");const c=M.ctas;ke(Array.isArray(c)?c:[]);const _=M.projects;se(Array.isArray(_)?_:[])}},[M,T]);const rr=ar({mutationFn:async s=>{if(!r)throw new Error("Not authenticated");if(s.username&&s.username!==R?.username){const{error:a}=await l.from("profiles").update({username:s.username}).eq("id",r.id);if(a)throw a}const n={user_id:r.id,name:s.name,headline:s.headline,avatar_url:s.avatar_url,writing_voice:{tone:s.writing_tone,avoid_words:s.avoid_words?.split(",").map(a=>
3a.trim()).filter(Boolean)||[]},topics:s.topics?.split(",").map(a=>a.trim()).filter(Boolean)||[],offers:s.offers?.split(`
4`).filter(Boolean).map(a=>{const[c,_]=a.split(":").map(S=>S.trim());return{name:c,url:_}})||[],writing_rules:s.writing_rules,business_description:s.business_description||null,ideal_customer:s.ideal_customer||null,primary_goal:s.primary_goal||null,ctas:Q,projects:ge};if(M){const{data:a,error:c}=await l.from("writer_profiles").update(n).eq("user_id",r.id).select().single();if(c)throw c;return a}else{const{data:a,error:c}=await l.from("writer_profiles").insert([n]).select().single();if(c)throw c;return a}},onSuccess:()=>{y.invalidateQueries({queryKey:["writer-profile"]}),y.invalidateQueries({queryKey:["user-profile"]}),m("saved"),t.success("Profile saved successfully!")},onError:s=>{t.error(s.message||"Failed to save profile"),m("unsaved")}}),cs=s=>{m("saving"),rr.mutate(s)};return i.useEffect(()=>{ae&&m("unsaved")},[ae]),d?e.jsx("div",{className:"min-h-screen bg-background"}):e.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[e.jsxs("div",{className:"fixed top-0 left-0 right-0 h-14 border-b border-border bg-background/80 backdrop-blur-sm z-40 flex items-center justify-between px-6",children:[e.jsxs(x,{variant:"ghost",size:"sm",onClick:()=>o("/dashboard"),className:"text-muted-foreground hover:text-foreground",children:[e.jsx(hr,{className:"h-4 w-4 mr-2"}),"Back"]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[f==="saved"&&"Saved",f==="saving"&&"Saving...",f==="unsaved"&&"Unsaved changes"]}),e.jsxs(x,{variant:"ghost",size:"sm",onClick:w(cs),disabled:f==="saving",className:"text-muted-foreground hover:text-foreground",children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),"Save"]})]}),e.jsx("div",{className:"pt-14 pb-12 px-6",children:e.jsxs("div",{className:"max-w-2xl mx-auto space-y-8",children:[(()=>{const s=[!!W("username"),!!W("name"),!!W("headline"),!!W("avatar_url"),!!W("writing_tone"),!!W("topics"),!!Ee,!!ue],n=s.filter(
4Boolean).length,a=Math.round(n/s.length*100);return e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-light mb-2",children:"Writer Profile"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Configure your writing style and preferences to personalize AI transformations"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pr,{value:a,className:"flex-1 h-2"}),e.jsxs("span",{className:"text-sm font-medium text-muted-foreground whitespace-nowrap",children:[a,"% complete"]})]})]})})(),e.jsxs("form",{onSubmit:w(cs),className:"space-y-6",children:[e.jsxs(U,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Subscription"}),e.jsx(he,{variant:j||ce?"default":"secondary",className:"capitalize",children:ce?"Admin (bypass)":j?u||"Professional":"Inactive"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ur,{className:`w-5 h-5 ${j||ce?"text-yellow-500":"text-muted-foreground"}`}),e.jsx("div",{children:(()=>{const s=!!R?.trial_pass_expires_at&&new Date(R.trial_pass_expires_at)>new Date,n=ce?"Admin access":s?"7-Day Trial Pass":j?u||"Professional":"No Active Plan",a=ce?"Admin role bypasses subscription checks":s?"Full access during your trial week":j?"You have access to all features":"Subscribe to unlock all features";return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-medium capitalize",children:n}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a})]})})()})]}),!!R?.trial_pass_expires_at&&new Date(R.trial_pass_expires_at)>new Date?e.jsxs("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[e.jsx(ds,{className:"w-4 h-4"}),e.jsxs("span",{children:["Trial ends on ",new Date(R.trial_pass_expires_at).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"})]})]}):j&&b?e.jsxs("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[e.jsx(ds,{className:"w-4 h-4"}),e.jsxs("span",{children:["Renews on ",new Date(b).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"})]})]}):null,e.jsx("div",{id:"subscription",className:"pt-2 flex flex-wrap gap-2",children:(()=>{if(!!R?.trial_pass_expires_at&&new Date(R.trial_pass_expires_at)>new Date)return e.jsx(x,{type:"button",variant:"default",size:"sm",onClick:()=>o("/pricing"),children:"Upgrade to monthly subscription"});const n=!!R?.cancel_at_period_end;return j?e.jsxs(e.Fragment,{children:[!n&&e.jsx(x,{type:"button",variant:"outline",size:"sm",className:"border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive",disabled:C,onClick:()=>B(!0),children:C?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"w-4 h-4 mr-2 animate-spin"}),"Canceling…"]}):g?"Cancel trial (no charge)":"Cancel subscription"}),n&&e.jsx(x,{type:"button",variant:"default",size:"sm",disabled:z,onClick:async()=>{try{q(!0);const{data:a,error:c}=await l.functions.invoke("reactivate-subscription");if(c)throw c;if(!a?.success)throw new Error(a?.error||"Reactivation failed");t.success(g?"Trial reactivated":"Subscription reactivated"),await p(),y.invalidateQueries({queryKey:["user-profile",r?.id]})}catch(a){t.error("Couldn't reactivate",{description:a instanceof Error?a.message:String(a)})}finally{q(!1)}},children:z?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"w-4 h-4 mr-2 animate-spin"}),"Reactivating…"]}):g?"Reactivate trial":"Reactivate subscription"}),e.jsx(x,{type:"button",variant:"outline",size:"sm",disabled:F,onClick:async()=>{try{v(!0);const{data:a,error:c}=await l.functions.invoke("update-payment-method");if(c)throw c;if(!a?.success||!a?.url)throw new Error(a?.error||"Could not start card update");window.location.href=a.url}catch(a){t.error("Couldn't open card update",{description:a instanceof Error?a.message:String(a)}),v(!1)}},children:F?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"w-4 h-4 mr-2 animate-spin"}),"Opening…"]}):"Update card"})]}):e.jsx(x,{type:"button",variant:"default",size:"sm",onClick:()=>o("/pricing"),children:"Upgrade Plan"})})()}),j&&e.jsxs("div",{className:"pt-3 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Billing history"}),Le?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading billing history…"}):fe&&fe.length>0?e.jsx("div",{className:"space-y-1",children:fe.map(s=>e.jsxs("div",{className:"flex items-center gap-3 justify-between text-sm py-1.5 border-b border-border/50 last:border-0",children:[e.jsx("span",{className:"text-muted-foreground whitespace-nowrap",children:new Date(s.created*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}),e.jsx("span",{className:"font-medium",children:((s.amount_paid||s.amount_due)/100).toLocaleStr
4ing("en-US",{style:"currency",currency:(s.currency||"usd").toUpperCase()})}),e.jsx(he,{variant:s.status==="paid"?"default":"secondary",className:"capitalize",children:s.status}),s.hosted_invoice_url?e.jsx("a",{href:s.hosted_invoice_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline whitespace-nowrap",children:"View receipt"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})]},s.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No invoices yet — your first invoice appears when your trial converts to a paid plan."})]}),R?.cancel_at_period_end&&j&&e.jsx("p",{className:"text-xs text-muted-foreground pt-1",children:g?"Your trial is canceled. You keep full access until it ends — no charge.":"Your subscription is set to cancel at the end of the current period."}),e.jsx(xr,{open:$,onOpenChange:B,children:e.jsxs(fr,{children:[e.jsxs(gr,{children:[e.jsx(yr,{children:g?"Cancel your free trial?":"Cancel your subscription?"}),e.jsx(jr,{children:g?"You won't be charged. You keep full access until your trial ends. You can reactivate anytime before then.":"You'll keep access until the end of your current billing period. No refund is issued for the current period."})]}),e.jsxs(br,{children:[e.jsx(x,{variant:"outline",onClick:()=>B(!1),disabled:C,children:"Never mind"}),e.jsx(x,{variant:"destructive",disabled:C,onClick:async()=>{try{P(!0);const{data:s,error:n}=await l.functions.invoke("cancel-subscription");if(n)throw n;if(!s?.success)throw new Error(s?.error||"Cancellation failed");const a=Date.now();for(;Date.now()-a<8e3;){const{data:c}=await l.from("profiles").select("cancel_at_period_end").eq("id",r.id).maybeSingle();if(c?.cancel_at_period_end)break;await new Promise(_=>setTimeout(_,1500))}t.success(s.alreadyCanceled?"Already scheduled to cancel":g?"Trial canceled — no charge":"Subscription canceled"),B(!1),await p(),y.invalidateQueries({queryKey:["user-profile",r?.id]}),y.invalidateQueries({queryKey:["billing-invoices",r?.id]})}catch(s){t.error("Couldn't cancel",{description:s instanceof Error?s.message:String(s)})}finally{P(!1)}},children:C?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"w-4 h-4 mr-2 animate-spin"}),"Canceling…"]}):g?"Yes, cancel trial":"Yes, cancel"})]})]})})]})]}),e.jsx(Wr,{}),e.jsxs(We,{children:[e.jsxs(Ge,{className:"flex items-center justify-between w-full py-3 text-lg font-medium hover:text-primary transition-colors group",children:["Connections",e.jsx(De,{className:"h-5 w-5 text-muted-foreground transition-transform group-data-[state=open]:rotate-180"})]}),e.jsxs(Oe,{className:"space-y-6 pt-2",children:[e.jsxs(U,{className:"p-6",children:[e.jsx("h2",{className:"text-xl font-medium mb-4",children:"Google Search Console"}),e.jsx(qr,{})]}),e.jsxs(U,{className:"p-6",children:[e.jsx("h2",{className:"text-xl font-medium mb-4",children:"LinkedIn Connection"}),Ee?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ie,{className:"w-5 h-5 text-green-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Connected to LinkedIn"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:Ee.profile_data?.name||"Account connected"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Publishing enabled"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsx(x,{type:"button",variant:"outline",onClick:Hs,size:"sm",children:"Disconnect LinkedIn"}),e.jsx(x,{type:"button",variant:"ghost",onClick:be,size:"sm",className:"text-muted-foreground",children:"Force Logout"})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pe,{className:"w-5 h-5 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"Not connected to LinkedIn"})]}),e.jsxs(x,{type:"button",variant:"outline",onClick:Ys,disabled:X,size:"sm",children:[e.jsx(vr,{className:"w-4 h-4 mr-2"}),X?"Connecting...":"Connect LinkedIn"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect LinkedIn to publish posts and carousels directly from ThoughtForge"})]})]}),(()=>{const s=ue?.token_expires_at?new Date(ue.token_expires_at).getTime():null,n=Date.now(),a=!!ue?.refresh_token,c=s!==null&&s<n,_=s!==null&&!c&&s-n<24*60*60*1e3&&!a,S=c&&!a;return e.jsxs(U,{className:"p-6",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1",children:e.jsx("h2",{className:"text-xl font-medium",children:"X Connection"})}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Connect your X account to publish posts and threads directly."}),ue?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[S?e.jsx("span",{className:"inline-flex h-2.5 w-2.5 rounded-full bg-amber-500","aria-hidden":!0}):e.jsx(ie,{className:"w-5 h-5 text-green-500"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium",children:S?"Reconnect required":"Connected to X"}),e.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:["@",ue.twitter_username||"Account connected",!S&&a&&e.jsx("span",{className:"ml-2 text-xs",children:"· Auto-refreshes before each post"})]})]})]}),S&&e.jsxs(ze,{className:"border-amber-200 bg-amber-50/60 dark:border-amber-900/50 dark:bg-amber-950/20",children:[e.jsx(Ie,{className:"h-4 w-4 text-amber-600 dar
4k:text-amber-400"}),e.jsx(qe,{className:"text-amber-900 dark:text-amber-100",children:"Your X access has expired"}),e.jsx($e,{className:"text-sm text-amber-800 dark:text-amber-200",children:"Reconnect to keep publishing. Scheduled posts to X will fail until you reconnect."})]}),_&&!S&&e.jsxs(ze,{className:"border-amber-200 bg-amber-50/60 dark:border-amber-900/50 dark:bg-amber-950/20",children:[e.jsx(Ie,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"}),e.jsx(qe,{className:"text-amber-900 dark:text-amber-100",children:"Reconnect soon"}),e.jsx($e,{className:"text-sm text-amber-800 dark:text-amber-200",children:"Your X access expires within 24 hours. Reconnect now to avoid interruption."})]}),!S&&e.jsxs(ze,{className:"border-blue-200 bg-blue-50/50 dark:border-blue-900/50 dark:bg-blue-950/20",children:[e.jsx(Ie,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"}),e.jsx(qe,{className:"text-blue-900 dark:text-blue-100",children:"X Posting"}),e.jsx($e,{className:"text-sm text-blue-800 dark:text-blue-200",children:"Post threads directly to X. 280 characters per post — longer drafts auto-split into a thread."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[S&&e.jsxs(x,{type:"button",variant:"default",onClick:os,disabled:G,size:"sm",children:[e.jsx(us,{className:"w-4 h-4 mr-2"}),G?"Reconnecting...":"Reconnect X"]}),e.jsx(x,{type:"button",variant:"outline",onClick:Qs,size:"sm",children:"Disconnect X"})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pe,{className:"w-5 h-5 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"Not connected to X"})]}),e.jsxs(x,{type:"button",variant:"outline",onClick:os,disabled:G,size:"sm",children:[e.jsx(us,{className:"w-4 h-4 mr-2"}),G?"Connecting...":"Connect X"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect X to publish posts and threads directly to your account"})]})]})})(),e.jsxs(U,{className:"p-6",children:[e.jsx("h2",{className:"text-xl font-medium mb-4 flex items-center gap-2",children:"Threads Connection"}),Ue?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ie,{className:"w-5 h-5 text-emerald-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Connected to Threads"}),Ue.username&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["@",Ue.username]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:e.jsx(x,{type:"button",variant:"outline",onClick:er,size:"sm",children:"Disconnect Threads"})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pe,{className:"w-5 h-5 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"Not connected to Threads"})]}),e.jsx(x,{type:"button",variant:"outline",onClick:Zs,disabled:D,size:"sm",children:D?"Connecting...":"Connect Threads"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect Threads to cross-post your content"})]})]}),e.jsxs(U,{className:"p-6",children:[e.jsx("h2",{className:"text-xl font-medium mb-4",children:"Analytics Settings"}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Exclude your own IP addresses from analytics to see accurate visitor data."}),je&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted/50 rounded-lg mb-4",children:[e.jsx(He,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm",children:["Your current IP: ",e.jsx("code",{className:"bg-muted px-1 rounded",children:je})]}),!me?.some(s=>s.ip_address===je)&&e.jsxs(x,{type:"button",variant:"outline",size:"sm",onClick:()=>Bs(je,"My current IP"),disabled:Ms,className:"ml-auto",children:[e.jsx(de,{className:"h-3 w-3 mr-1"}),"Exclude"]}),me?.some(s=>s.ip_address===je)&&e.jsxs("span",{className:"ml-auto text-xs text-green-600 flex items-center gap-1",children:[e.jsx(ie,{className:"h-3 w-3"})," Excluded"]})]}),me&&me.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Excluded IP Addresses"}),e.jsx("div",{className:"space-y-2",children:me.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-card border border-border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"text-sm",children:String(s.ip_address)}),s.label&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",s.label,")"]})]}),e.jsx(x,{type:"button",variant:"ghost",size:"sm",onClick:()=>Ks(s.id),className:"text-destructive hover:text-destructive",children:e.jsx(xe,{className:"h-4 w-4"})})]},s.id))})]}),me?.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground italic",children:'No IP addresses excluded. Click "Exclude" above to filter out your own traffic.'})]})})]}),e.jsx(zr,{}),e.jsx($r,{}),e.jsx(at,{})]})]}),e.jsxs(U,{className:"p-6",children:[e.jsx("h2",{className:"text-xl font-medium mb-4",children:"Public Profile"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"username",children:"Username"}),e.jsx(I,{id:"username",...O("username"),placeholder:"yourname",className:"bg-card"}),ye.username&&e.jsx("p",{className:"text-sm text-destructive",children:ye.username.message}),qs&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking availability..."}),Je===!0&&le&&le!==R?.username&&e.jsx("p",{className:"text-sm text-green-500",children:"✓ Username available"}),Je===!1&&e.jsx("p",{className:"text-sm text-destructive",children:"✗ Username already taken"})]}),R?.username&&e.jsxs("div",{className:"p-4 bg-muted/50 rounded-lg",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Your public profile:"}),e.jsxs("a",{href:`${window.location.origin}/user/${R.username}`,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline",children:[window.location.host,"/user/",R.username]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your username will be used in your public profile URL. Must be 3-20 characters, lowercase letters, numbers, and underscores only."})]})]}),e.jsx(Or,{}),e.jsx(st,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Basic Info"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"name",children:"Name"}),e.jsx(I,{id:"name",...O("name"),placeholder:"Your full name",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"headline",children:"Headline"}),e.jsx(I,{id:"headline",...O("headline"),placeholder:"Your professional headline",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"avatar_url",children:"Avatar URL"}),e.jsx(I,{id:"avatar_url",...O("avatar_url"),placeholder:"https://example.com/avatar.jpg",className:"bg-card"})]})]}),e.jsx("div",{id:"identity",className:"scroll-mt-24",children:e.jsx(it,{userId:r?.id})}),e.jsxs(U,{className:"p-6",children:[e.jsx("h2",{className:"text-xl font-medium mb-4",children:"Call-to-Action Buttons"}),e.jsx(Dr,{ctas:Q,onChange:s=>{ke(s),m("unsaved")}})]}),e.jsx(tt,{userId:r?.id,userEmail:r?.email,username:R?.username,initialEnabled:!!R?.newsletter_enabled,initialReplyTo:R?.newsletter_reply_to_email||"",initialSignature:R?.newsletter_signature??void 0,fullName:R?.full_name,onSaved:()=>y.invalidateQueries({queryKey:["user-profile"]})}),e.jsxs(We,{children:[e.jsxs(Ge,{className:"flex items-center justify-between w-full py-3 text-lg font-medium hover:text-primary transition-colors group",children:["Writing & Voice",e.jsx(De,{className:"h-5 w-5 text-muted-foreground transition-transform group-data-[state=open]:rotate-180"})]}),e.jsxs(Oe,{className:"space-y-6 pt-2",children:[e.jsxs(U,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Voice Learning"}),e.jsx(x,{type:"button",variant:ne?"outline":"default",size:"sm",onClick:Ws,disabled:ts,children:ts?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-4 w-4 mr-2 animate-spin"}),"Analyzing..."]}):ne?e.jsxs(e.Fragment,{children:[e.jsx(fs,{className:"h-4 w-4 mr-2"}),"Re-analyze Voice"]}):e.jsxs(e.Fragment,{children:[e.jsx(wr,{className:"h-4 w-4 mr-2"}),"Learn My Voice"]})})]}),ne?e.jsxs("div",{className:"space-y-3 p-4 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Voice patterns learned"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Articles analyzed:"}),e.jsx("span",{className:"ml-2 font-medium",children:ne.articles_analyzed||0})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Vocabulary:"}),e.jsx("span",{className:"ml-2 font-medium capitalize",children:ne.vocabulary_level||"Unknown"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Avg sentence:"}),e.jsxs("span",{className:"ml-2 font-medium",children:[ne.avg_sentence_length||0," words"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Last analyzed:"}),e.jsx("span",{className:"ml-2 font-medium",children:ne.last_analyzed_at?new Date(ne.last_analyzed_at).toLocaleDateString():"Never"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Your writing voice is used to make LinkedIn and X posts sound authentically like you."})]}):e.jsx("div",{className:"p-4 bg-muted/30 rounded-lg border border-dashed",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:'Click "Learn My Voice" to analyze your published articles and teach the AI your unique writing style. This makes your LinkedIn and X posts sound authentically like you.'})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Writing Style"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"writing_tone",children:"Tone"}),e.jsxs("select",{id:"writing_tone",...O("writing_tone"),className:"w-full px-3 py-2 bg-card border border-input rounded-md text-sm",children:[e.jsx("option",{value:"conversational",children:"Conversational"}),e.jsx("option",{value:"professional",children:"Professional"}),e.jsx("option",{value:"technical",children:"Technical"}),e.jsx("option",{value:"casual",children:"Casual"}),e.jsx("option",{value:"academic",children:"Academic"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"avoid_words",children:"Avoid Words"}),e.jsx(I,{id:"avoid_words",...O("avoid_words"),placeholder:"leverage, synergy, disrupt (comma-separated)",className:"bg-card"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Words to never use in transformations"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"topics",children:"Topics You Write About"}),e.jsx(I,{id:"topics",...O("topics"),placeholder:"AI, productivity, entrepreneurship (comma-separated)",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-4 pt-2 border-t border-border/50",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:"Content Strategy"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used by Fill Calendar (Discoverability Plan) s
4o we never re-ask these questions."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"business_description",children:"What does your business do?"}),e.jsx(Se,{id:"business_description",...O("business_description"),placeholder:"e.g., We sell project management software for remote teams...",className:"min-h-[70px] bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"ideal_customer",children:"Who is your ideal customer?"}),e.jsx(I,{id:"ideal_customer",...O("ideal_customer"),placeholder:"e.g., SaaS founders, ecommerce store owners",className:"bg-card"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"primary_goal",children:"Primary goal"}),e.jsxs("select",{id:"primary_goal",...O("primary_goal"),className:"w-full h-10 rounded-md border border-input bg-card px-3 text-sm",children:[e.jsx("option",{value:"aeo_geo",children:"Get cited by AI (AEO + GEO)"}),e.jsx("option",{value:"traffic",children:"Rank on Google (organic traffic)"}),e.jsx("option",{value:"authority",children:"Build authority on LinkedIn"}),e.jsx("option",{value:"all",children:"All of the above"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"offers",children:"Your Offers"}),e.jsx(Se,{id:"offers",...O("offers"),placeholder:`AI Coaching: https://example.com/coaching
5Newsletter: https://example.com/newsletter`,className:"min-h-[100px] bg-card"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"One per line: Name: URL"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"writing_rules",children:"Writing Rules"}),e.jsx(Se,{id:"writing_rules",...O("writing_rules"),placeholder:`- Never use emojis
6- Always include a CTA
7- Keep it under 1000 characters`,className:"min-h-[120px] bg-card"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Free-form rules and guidelines for your writing"})]})]})]})]}),e.jsxs(We,{children:[e.jsx(Ge,{asChild:!0,children:e.jsxs(x,{variant:"ghost",type:"button",className:"w-full flex items-center justify-between p-0 h-auto group",children:[e.jsx("h2",{className:"text-xl font-medium",children:"Portfolio Projects"}),e.jsx(De,{className:"h-5 w-5 text-muted-foreground transition-transform group-data-[state=open]:rotate-180"})]})}),e.jsxs(Oe,{className:"space-y-4 mt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Showcase what you've built on your personal site."}),ge.map((s,n)=>e.jsxs(U,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["Project ",n+1]}),e.jsx(x,{type:"button",variant:"ghost",size:"sm",onClick:()=>{se(a=>a.filter((c,_)=>_!==n)),m("unsaved")},children:e.jsx(xe,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(I,{placeholder:"Project name",value:s.name,onChange:a=>{se(c=>c.map((_,S)=>S===n?{..._,name:a.target.value}:_)),m("unsaved")},className:"bg-card"}),e.jsx(I,{placeholder:"Short description",value:s.description,onChange:a=>{se(c=>c.map((_,S)=>S===n?{..._,description:a.target.value}:_)),m("unsaved")},className:"bg-card"}),e.jsx(I,{placeholder:"URL (https://...)",value:s.url,onChange:a=>{se(c=>c.map((_,S)=>S===n?{..._,url:a.target.value}:_)),m("unsaved")},className:"bg-card"}),e.jsx(I,{placeholder:"Badge (optional, e.g. 'Live', 'Beta')",value:s.badge||"",onChange:a=>{se(c=>c.map((_,S)=>S===n?{..._,badge:a.target.value||void 0}:_)),m("unsaved")},className:"bg-card"})]},n)),e.jsxs(x,{type:"button",variant:"outline",size:"sm",onClick:()=>{se(s=>[...s,{name:"",description:"",url:""}]),m("unsaved")},className:"w-full",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Add Project"]})]})]}),e.jsx(x,{type:"submit",disabled:f==="saving",className:"w-full",children:f==="saving"?"Saving...":"Save Profile"})]})]})}),(_e||d&&h.search.includes("callback"))&&e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsx(U,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(E,{className:"h-5 w-5 animate-spin"}),e.jsxs("span",{children:["Connecting to ",h.search.includes("threads")?"Threads":h.search.includes("twitter")?"Twitter":h.search.includes("wordpress")?"WordPress":h.search.includes("shopify")?"Shopify":h.search.includes("linkedin")?"LinkedIn":"your account","..."]}
7)]})})})]})}export{Tt 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.