PageSourceSearch

https://socialbrilliance.ai/assets/Index-DLf1dyl-.js

js socialbrilliance.ai collected 2026-10-05 15:07:38 UTC 177,472 bytes, 103 lines download raw bytes

1var Yn=Object.defineProperty;var Kn=(t,s,r)=>s in t?Yn(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var Ze=(t,s,r)=>Kn(t,typeof s!="symbol"?s+"":s,r);import{c as se,r as c,s as W,g as kt,j as e,S as q,C as Z,B as g,R as gs,a as bs,T as ys,b as ze,t as N,E as w,A as He,u as xe,d as vr,L as ae,e as Ee,U as We,f as ye,h as Xn,I as pe,X as te,i as je,G as Jn,Z as Nr,k as wr,F as js,l as Vn,P as St,M as kr,m as qn,n as Zn,o as Qn,p as ea,q as ta,v as sa,w as ra,x as na,y as aa,z as ia,D as oa}from"./index-BRZCj0Re.js";import{A as ds,g as ir}from"./audience-presets-BzG7fYsQ.js";import{W as Pe,H as Sr}from"./wand-sparkles-CqyNPuin.js";import{L as _r}from"./lightbulb-CQfwAI4X.js";import{M as ve}from"./message-square-C8rg7zWz.js";import{L as Cr,T as Ar,H as ms,P as la,R as ca,F as da,f as ma}from"./diagnosis-findings-CqUy9fmo.js";import{S as Ir}from"./share-2-BRcE5BzD.js";import{C as Me}from"./copy-q8U8Nw7W.js";import{S as It}from"./send-BzrHhqdO.js";import{T as st}from"./textarea-qYbQ7l9N.js";import{S as ua,B as xa}from"./BrandProfileEditor-Cp8B2i6T.js";import{T as us}from"./trash-2-BcpRJ2AL.js";import{P as Er}from"./plus-DfQ5ZUn4.js";import{u as ha,M as pa,a as fa}from"./use-theme-GHz9ExbZ.js";import{S as ga}from"./sun-_S95CTvg.js";import{A as Pr}from"./arrow-left-CZ27GFxq.js";import{B as ba}from"./book-open-D_hGwOqK.js";import{L as ya}from"./list-U4_fNM4J.js";import{M as ja}from"./minus-b9Z8p4tW.js";import{r as va,C as xs,l as Na,i as wa,g as or,s as lr,b as ka,a as Sa}from"./composer-asset-B2yJNrEH.js";import{T as vs}from"./trending-down--hx7wGvs.js";import{l as _a,c as Ca,a as Aa,b as Ia}from"./work-context-CpdKjtVO.js";import{u as Tr}from"./use-brand-profiles-BhGXxN34.js";import{P as Ea}from"./progress-rm4iflDQ.js";import{L as Pa}from"./link-CgJ0mgTx.js";import{E as vt}from"./eye-oVG2_fbt.js";import{c as Ta}from"./brand-drift-Cl51nCoS.js";import{C as cr}from"./calendar-BKNXgi0b.js";import{M as Ma}from"./megaphone-hR1J6cd0.js";import{A as Ra}from"./award-D3H9-_JY.js";import{C as Oa}from"./chevron-down-CxZl0YU8.js";import"./report-qa-BqLJeMRX.js";/**
2 * @license lucide-react v0.462.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 La=se("Bold",[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]]);/**
7 * @license lucide-react v0.462.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 Mr=se("Bookmark",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]]);/**
12 * @license lucide-react v0.462.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 Nt=se("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
17 * @license lucide-react v0.462.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 Fa=se("Italic",[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]]);/**
22 * @license lucide-react v0.462.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const Rr=se("Languages",[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]]);/**
27 * @license lucide-react v0.462.0 - ISC
28 *
29 * This source code is licensed under the ISC license.
30 * See the LICENSE file in the root directory of this source tree.
31 */const dr=se("MessageSquareText",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M13 8H7",key:"14i4kc"}],["path",{d:"M17 12H7",key:"16if0g"}]]);/**
32 * @license lucide-react v0.462.0 - ISC
33 *
34 * This source code is licensed under the ISC license.
35 * See the LICENSE file in the root directory of this source tree.
36 */const Da=se("MicOff",[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M18.89 13.23A7.12 7.12 0 0 0 19 12v-2",key:"80xlxr"}],["path",{d:"M5 10v2a7 7 0 0 0 12 5",key:"p2k8kg"}],["path",{d:"M15 9.34V5a3 3 0 0 0-5.68-1.33",key:"1gzdoj"}],["path",{d:"M9 9v3a3 3 0 0 0 5.12 2.12",key:"r2i35w"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/**
37 * @license lucide-react v0.462.0 - ISC
38 *
39 * This source code is licensed under the ISC license.
40 * See the LICENSE file in the root directory of this source tree.
41 */const $a=se("Mic",[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/**
42 * @license lucide-react v0.462.0 - ISC
43 *
44 * This source code is licensed under the ISC license.
45 * See the LICENSE file in the root directory of this source tree.
46 */const Or=se("Repeat2",[["path",{d:"m2 9 3-3 3 3",key:"1ltn5i"}],["path",{d:"M13 18H7a2 2 0 0 1-2-2V6",key:"1r6tfw"}],["path",{d:"m22 15-3 3-3-3",key:"4rnwn2"}],["path",{d:"M11 6h6a2 2 0 0 1 2 2v10",key:"2f72bc"}]]);/**
47 * @license lucide-react v0.462.0 - ISC
48 *
49 * This source code is licensed under the ISC license.
50 * See the LICENSE file in the root directory of this source tree.
51 */const _t=se("Repeat",[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]]);/**
52 * @license lucide-react v0.462.0 - ISC
53 *
54 * This source code is licensed under the ISC license.
55 * See the LICENSE file in the root directory of this source tree.
56 */const za=se("Strikethrough",[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]]);/**
57 * @license lucide-react v0.462.0 - ISC
58 *
59 * This source code is licensed under the ISC license.
60 * See the LICENSE file in the root directory of this source tree.
61 */const Ns=se("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);/**
62 * @license lucide-react v0.462.0 - ISC
63 *
64 * This source code is licensed under the ISC license.
65 * See the LICENSE file in the root directory of this source tree.
66 */const Ha=se("Underline",[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]]);/**
67 * @license lucide-react v0.462.0 - ISC
68 *
69 * This source code is licensed under the ISC license.
70 * See the LICENSE file in the root directory of this source tree.
71 */const mr=se("Wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",key:"cbrjhi"}]]),Ge=new Map,rt=new Map;function Ne(t,s,r,n,i){for(let a=0;a<r;a+=1){const o=String.fromCharCode(s+a),l=String.fromCodePoint(t+a);Ge.set(l,{plain:o,style:n}),i&&rt.set(o,{...rt.get(o),[n]:l})}}function Re(t,s,r,n){Ne(t,s,r,n,!1)}Ne(120276,65,26,"bold",!0);Ne(120302,97,26,"bold",!0);Ne(120812,48,10,"bold",!0);Ne(120328,65,26,"italic",!0);Ne(120354,97,26,"italic",!0);Ne(120380,65,26,"boldItalic",!0);Ne(120406,97,26,"boldItalic",!0);Re(119808,65,26,"bold");Re(119834,97,26,"bold");Re(120782,48,10,"bold");Re(119860,65,26,"italic");Re(119886,97,26,"italic");Re(119912,65,26,"boldItalic");Re(119938,97,26,"boldItalic");Ge.set("ℎ",{plain:"h",style:"italic"});rt.set("h",{...rt.get("h"),italic:"ℎ"});const ws="̲",ks="̶",Ue=/[\u0332\u0336]/gu;function nt(t){var r;const s=((r=Ge.get(t))==null?void 0:r.plain)??t;return/[\p{L}\p{N}]/u.test(s)}function Lr(t,s){var n;const r=((n=Ge.get(t))==null?void 0:n.style)??"plain";return s==="bold"?r==="bold"||r==="boldItalic":r==="italic"||r==="boldItalic"}function Ua(t,s,r){var m;const n=Ge.get(t),i=(n==null?void 0:n.plain)??t;if(!/[A-Za-z0-9]/.test(i))return t;const a=(n==null?void 0:n.style)==="bold"||(n==null?void 0:n.style)==="boldItalic",o=(n==null?void 0:n.style)==="italic"||(n==null?void 0:n.style)==="boldItalic",l=s==="bold"?!r:a,u=s==="italic"?!r:o,x=l&&u?"boldItalic":l?"bold":u?"italic":"plain";return x==="plain"?i:((m=rt.get(i))==null?void 0:m[x])??i}function Ba(t,s){const r=Array.from(t),n=r.filter(nt),i=n.length>0&&n.every(a=>Lr(a,s));return r.map(a=>Ua(a,s,i)).join("")}function Ss(t){const s=[];for(const r of Array.from(t))Ue.test(r)&&s.length>0?s[s.length-1]+=r:s.push(r),Ue.lastIndex=0;return s}function ur(t,s){const r=Ss(t),n=r.filter(a=>nt(a.replace(Ue,""))),i=n.length>0&&n.every(a=>a.includes(s));return r.map(a=>nt(a.replace(Ue,""))?i?a.split(s).join(""):a.includes(s)?a:`${a}${s}`:a).join("")}function Wa(t){const s=t.split(`
72`),r=s.filter(i=>i.trim().length>0),n=r.length>0&&r.every(i=>/^\s*•\s+/.test(i));return s.map(i=>{var o;if(!i.trim())return i;if(n)return i.replace(/^(\s*)•\s+/,"$1");if(/^\s*•\s+/.test(i))return i;const a=((o=i.match(/^\s*/))==null?void 0:o[0])??"";return`${a}• ${i.slice(a.length)}`}).join(`
73`)}function Fr(t,s){const r=Math.max(0,Math.min(s.start,t.length)),n=Math.max(r,Math.min(s.end,t.length));if(r!==n)return{start:r,end:n};const i=t.lastIndexOf(`
74`,Math.max(0,r-1))+1,a=t.indexOf(`
75`,r);return{start:i,end:a===-1?t.length:a}}function Ga(t,s,r){if(r==="separator"){const l=Math.max(0,Math.min(s.start,t.length)),u=`${l>0&&t[l-1]!==`
76`?`
77`:""}———————————
78`,x=t.slice(0,l)+u+t.slice(l),m=l+u.length;return{content:x,selection:{start:m,end:m},changed:!0}}const n=Fr(t,s),i=t.slice(n.start,n.end);if(!i.trim())return{content:t,selection:n,changed:!1};const a=r==="bold"||r==="italic"?Ba(i,r):r==="underline"?ur(i,ws):r==="strikethrough"?ur(i,ks):Wa(i),o=t.slice(0,n.start)+a+t.slice(n.end);return{content:o,selection:{start:n.start,end:n.start+a.length},changed:o!==t}}function Ya(t,s,r){const n=Fr(t,s),i=t.slice(n.start,n.end);if(!i.trim())return!1;if(r==="list")return i.split(`
79`).filter(o=>o.trim()).every(o=>/^\s*•\s+/.test(o));if(r==="underline"||r==="strikethrough"){const o=r==="underline"?ws:ks,l=Ss(i).filter(u=>nt(u.replace(Ue,"")));return l.length>0&&l.every(u=>u.includes(o))}const a=Array.from(i).filter(nt);return a.length>0&&a.every(o=>Lr(o,r))}function Ka(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Xa(t){const s=[];for(const r of Ss(t)){const n=r.replace(Ue,""),i=Ge.get(n),a=(i==null?void 0:i.plain)??n,o=(i==null?void 0:i.style)==="bold"||(i==null?void 0:i.style)==="boldItalic"||!1,l=(i==null?void 0:i.style)==="italic"||(i==null?void 0:i.style)==="boldItalic"||!1,u=r.includes(ws),x=r.includes(ks),m=s[s.length-1];m&&m.bold===o&&m.italic===l&&m.underline===u&&m.strikethrough===x?m.text+=a:s.push({text:a,bold:o,italic:l,underline:u,strikethrough:x})}return s}function Ja(t){const s=Xa(t);let r="",n=!1,i=!1,a=!1,o=!1;const l=x=>{r+=x},u=x=>{r+=x};for(const x of s)o&&!x.strikethrough&&(l("</s>"),o=!1),a&&!x.underline&&(l("</u>"),a=!1),i&&!x.italic&&(l("</em>"),i=!1),n&&!x.bold&&(l("</strong>"),n=!1),!n&&x.bold&&(u("<strong>"),n=!0),!i&&x.italic&&(u("<em>"),i=!0),!a&&x.underline&&(u("<u>"),a=!0),!o&&x.strikethrough&&(u("<s>"),o=!0),r+=Ka(x.text);return o&&l("</s>"),a&&l("</u>"),i&&l("</em>"),n&&l("</strong>"),r}async function _s(t){await navigator.clipboard.writeText(t)}
79function Va(t){const[s,r]=c.useState(!1),n=c.useRef(null);c.useEffect(()=>()=>{n.current&&n.current.stop()},[]);const i=c.useCallback(()=>{const l=window.SpeechRecognition||window.webkitSpeechRecognition;if(!l){alert("Voice input is not supported in this browser. Try Chrome.");return}const u=new l;u.continuous=!0,u.interimResults=!0,u.lang="en-US",u.onresult=x=>{let m="";for(let p=x.resultIndex;p<x.results.length;p++)x.results[p].isFinal&&(m+=x.results[p][0].transcript);m&&t(m)},u.onerror=()=>r(!1),u.onend=()=>r(!1),u.start(),n.current=u,r(!0)},[t]),a=c.useCallback(()=>{n.current&&n.current.stop(),r(!1)},[]),o=c.useCallback(()=>{s?a():i()},[s,i,a]);return{isListening:s,toggle:o}}const Be=[{key:"hook",label:"Hook / stopping power",weight:.2},{key:"clarity",label:"Clarity",weight:.2},{key:"relevance",label:"Audience relevance",weight:.15},{key:"differentiation",label:"Differentiation",weight:.15},{key:"credibility",label:"Credibility / proof",weight:.1},{key:"structure",label:"Structure / readability",weight:.1},{key:"cta",label:"CTA / conversation",weight:.05},{key:"platformFit",label:"LinkedIn platform fit",weight:.05}];Be.reduce((t,s)=>t+s.weight,0);function Dr(t){const s=typeof t=="number"&&Number.isFinite(t)?t:0;return Math.min(100,Math.max(0,s))}const qa={relevance:["audienceFit"],platformFit:["linkedinFit"]};function Cs(t,s){if(t[s]!==void 0)return t[s];for(const r of qa[s]??[])if(t[r]!==void 0)return t[r]}function $r(t){const s=t??{},r={};for(const n of Be)r[n.key]=Dr(Cs(s,n.key));return r}const Za=["platformFit"];function zr(t="linkedin"){if(t==="linkedin")return Be.map(n=>({...n}));const s=Be.filter(n=>!Za.includes(n.key)),r=s.reduce((n,i)=>n+i.weight,0);return s.map(n=>({...n,weight:n.weight/r}))}function As(t,s="linkedin"){const r=$r(t),n=zr(s).reduce((i,a)=>i+r[a.key]*a.weight,0);return Math.min(100,Math.max(0,Math.round(n)))}function xr(t,s="linkedin"){return As(t,s)}function Qa(t){if(!t||typeof t!="object")return!1;const s=t;return Be.some(r=>{const n=Cs(s,r.key);return typeof n=="number"&&Number.isFinite(n)})}function ei(t){if(!t||typeof t!="object")return!1;const s=t;return Be.every(r=>{const n=Cs(s,r.key);return typeof n=="number"&&Number.isFinite(n)})}function hs(t,s="linkedin"){return zr(s).map(r=>({key:r.key,label:r.label,weight:r.weight,value:Dr(t[r.key])}))}const ti="Editorial/message-quality score — not a prediction of reach or engagement.";function Hr(t){return t==="linkedin"?"Scored for LinkedIn.":"Scored for general message quality — LinkedIn-specific fit is excluded for this asset."}function Ur(t,s="linkedin"){return t?s==="linkedin"||!Qa(t.dimensions)?t.score:As(t.dimensions,"generic"):null}function si(t){return t==="linkedin"?"Publish readiness":"Message readiness"}async function Ye(t){var s,r,n,i,a,o;if(t.brandMemory)return t;try{const l=kt();if(!l)return t;const u=localStorage.getItem("sb_active_profile");if(u){const{data:p}=await W.rpc("get_brand_profiles_by_device",{p_device_id:l}),h=p==null?void 0:p.find(j=>j.id===u);if(h){const j={...t,audiencePreset:h.audience_preset||t.audiencePreset,language:h.language||t.language};return((s=h.voice_samples)!=null&&s.length||(r=h.recurring_themes)!=null&&r.length||(n=h.banned_phrases)!=null&&n.length||h.cta_style||h.goal)&&(j.brandMemory={voice_samples:h.voice_samples??[],recurring_themes:h.recurring_themes??[],banned_phrases:h.banned_phrases??[],cta_style:[h.cta_style,h.goal].filter(Boolean).join(". ")}),j}}const{data:x}=await W.rpc("get_brand_memory_by_device",{p_device_id:l}),m=Array.isArray(x)?x[0]:null;if(m&&((i=m.voice_samples)!=null&&i.length||(a=m.recurring_themes)!=null&&a.length||(o=m.banned_phrases)!=null&&o.length||m.cta_style))return{...t,brandMemory:m}}catch{}return t}const ue=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"&&s.trim().length>0):[];function ri(t){var o,l,u;const s=$r(t==null?void 0:t.dimensions),r=typeof(t==null?void 0:t.score)=="number"&&Number.isFinite(t.score)?t.score:null;let n;if(ei(t==null?void 0:t.dimensions))n=As(s);else if(r!==null)n=Math.min(100,Math.max(0,Math.round(r)));else throw new Error("Incomplete analysis: missing dimension scores");const i=ue((o=t==null?void 0:t.hashtagStrategy)==null?void 0:o.suggested),a=ue(t==null?void 0:t.hashtags);
79return{audience:typeof(t==null?void 0:t.audience)=="string"?t.audience:"",goal:typeof(t==null?void 0:t.goal)=="string"?t.goal:"",tone:typeof(t==null?void 0:t.tone)=="string"?t.tone:"",score:n,dimensions:s,suggestions:ue(t==null?void 0:t.suggestions),hashtags:a.length?a:i,hookAlternatives:ue(t==null?void 0:t.hookAlternatives),linkedinRecommendations:ue(t==null?void 0:t.linkedinRecommendations),discoveryKeywords:ue(t==null?void 0:t.discoveryKeywords),hashtagStrategy:{recommendation:typeof((l=t==null?void 0:t.hashtagStrategy)==null?void 0:l.recommendation)=="string"?t.hashtagStrategy.recommendation:"",suggested:i.length?i:a,rationale:typeof((u=t==null?void 0:t.hashtagStrategy)==null?void 0:u.rationale)=="string"?t.hashtagStrategy.rationale:""}}}async function ni(t,s){const r=await Ye(s),{data:n,error:i}=await W.functions.invoke("linkedin-ai",{body:{action:"analyze",content:t,settings:r}});if(i)throw i;let a;try{a=JSON.parse(n.result)}catch{throw new Error("Failed to parse analysis")}return ri(a)}async function ai(t,s){const r=await Ye(s),{data:n,error:i}=await W.functions.invoke("linkedin-ai",{body:{action:"format",content:t,settings:r}});if(i)throw i;return n.result}async function ii(t){const{data:s,error:r}=await W.functions.invoke("linkedin-ai",{body:{action:"format_only",content:t,settings:{}}});if(r)throw r;return s.result}async function oi(t,s){const{data:r,error:n}=await W.functions.invoke("linkedin-ai",{body:{action:"translate",content:t,settings:{targetLanguage:s}}});if(n)throw n;return r.result}async function Qe(t,s,r,n={}){const i=await Ye(r),{data:a,error:o}=await W.functions.invoke("linkedin-ai",{body:{action:"apply_suggestions",content:t,settings:i,suggestions:s},...n.signal?{signal:n.signal}:{}});if(o)throw o;let l;try{l=JSON.parse(a==null?void 0:a.result)}catch{const u=new Error("Failed to parse revised posts");throw u.code="malformed_response",u}if(!Array.isArray(l)||!l.some(u=>typeof u=="string"&&u.trim().length>0)){const u=new Error("Revision service returned no usable revisions");throw u.code="malformed_response",u}return l.filter(u=>typeof u=="string"&&u.trim().length>0)}async function li(t,s){const r=await Ye(s),{data:n,error:i}=await W.functions.invoke("linkedin-ai",{body:{action:"generate_comments",content:t,settings:r}});if(i)throw i;try{return JSON.parse(n.result)}catch{throw new Error("Failed to parse comments")}}async function ci(t,s,r,n){const i=await Ye(n),{data:a,error:o}=await W.functions.invoke("linkedin-ai",{body:{action:"generate_from_file",content:JSON.stringify({fileUrl:t,fileName:s,fileType:r}),settings:i}});if(o)throw o;return a.result}const di=["linkedin","x","facebook","instagram"];function mi(t){var r,n,i,a;const s={};for(const o of di){const l=(r=t==null?void 0:t.guidance)==null?void 0:r[o];s[o]={whyChanged:ue(l==null?void 0:l.whyChanged),discoveryKeywords:ue(l==null?void 0:l.discoveryKeywords),channelTips:ue(l==null?void 0:l.channelTips),hashtagStrategy:{recommendation:typeof((n=l==null?void 0:l.hashtagStrategy)==null?void 0:n.recommendation)=="string"?l.hashtagStrategy.recommendation:"",suggested:ue((i=l==null?void 0:l.hashtagStrategy)==null?void 0:i.suggested),rationale:typeof((a=l==null?void 0:l.hashtagStrategy)==null?void 0:a.rationale)=="string"?l.hashtagStrategy.rationale:""}}}return{linkedin:typeof(t==null?void 0:t.linkedin)=="string"?t.linkedin:"",x:typeof(t==null?void 0:t.x)=="string"?t.x:"",facebook:typeof(t==null?void 0:t.facebook)=="string"?t.facebook:"",instagram:typeof(t==null?void 0:t.instagram)=="string"?t.instagram:"",guidance:s}}async function ui(t,s,r={}){const n=await Ye(s),i=typeof r.xCharLimit=="number"&&Number.isFinite(r.xCharLimit)?Math.min(Math.max(Math.floor(r.xCharLimit),1),25e3):280,{data:a,error:o}=await W.functions.invoke("linkedin-ai",{body:{action:"adapt_platforms",content:t,settings:n,xCharLimit:i}});if(o)throw o;try{return mi(JSON.parse(a.result))}catch{throw new Error("Failed to parse platform adaptations")}}function xi(t){return t>=70?{label:"Ready",tone:"text-success",bg:"bg-success/10 border-success/30"}:t>=40?{label:"Almost ready",tone:"text-warning",bg:"bg-warning/10 border-warning/30"}:{label:"Needs work",tone:"text-destructive",bg:"bg-destructive/10 border-destructive/30"}}const hi=ti;function yt({icon:t,children:s}){return e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[t,e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:s})]})}
79function pi({analysis:t,isLoading:s,onApplySuggestions:r,isApplying:n,variations:i,onPickVariation:a,onAnalyze:o,isStale:l,onRecheck:u,onFixTopSuggestion:x,isFixingTop:m,topRecKept:p,onKeepTopRecommendation:h,previousScore:j,onFormatForLinkedIn:k,isFormattingForLinkedIn:E,isFormattedPreserved:S,onApplyRecommendation:v,applyingRecommendationIndex:L,onUseHook:G,scoreMode:B,assetLabel:H}){var Y,re,ne,ce,we,y,O,ke,ie,at,Oe;if(s)return e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary",children:[e.jsx(q,{className:"w-4 h-4 animate-pulse-glow"}),e.jsx("span",{className:"text-sm font-semibold",children:"Analyzing post..."})]}),[1,2,3,4].map(P=>e.jsxs("div",{className:"space-y-2 animate-pulse",children:[e.jsx("div",{className:"h-3 bg-muted rounded w-1/3"}),e.jsx("div",{className:"h-3 bg-muted rounded w-2/3"})]},P))]});if(i&&i.length>0&&a)return e.jsxs("div",{"data-testid":"variation-picker",className:"rounded-xl border border-border bg-card p-4 space-y-3 animate-slide-up",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:t?"Pick a revised version":"Pick a version to start from"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t?"Choose one to use, then recheck the draft.":"Choose one to use, then Score & Review it."}),e.jsx("div",{className:"space-y-2",children:i.map((P,X)=>{const Mt=P.replace(/\n{3,}/g,`
80
81`).trim();return e.jsxs("button",{onClick:()=>a(P,X),className:"w-full text-left rounded-lg border border-border bg-secondary/40 hover:bg-secondary hover:border-primary/30 transition-all p-3 group min-h-[44px]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("span",{className:"text-[10px] font-semibold text-primary uppercase tracking-wider",children:["Option ",X+1]}),e.jsx(Z,{className:"w-3.5 h-3.5 text-primary opacity-0 group-hover:opacity-100 transition-opacity"})]}),e.jsx("p",{className:"text-xs text-foreground whitespace-pre-wrap",children:Mt})]},X)})})]});if(!t)return e.jsx("div",{className:`rounded-xl border border-border bg-card p-5 ${o?"cursor-pointer hover:border-primary/50 transition-colors":""}`,onClick:o,children:e.jsxs("div",{className:"text-center space-y-3 py-8",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-secondary mx-auto flex items-center justify-center",children:e.jsx(q,{className:"w-5 h-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Score this draft before you publish"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Check the opening, clarity, structure, audience fit, and next action before you publish."})]}),o&&e.jsxs(g,{size:"sm",variant:"outline",className:"gap-1.5 font-semibold min-h-[44px] sm:min-h-0",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),"Score & Review"]})]})});const A=B??"linkedin",F=A==="linkedin",f=Ur(t,A)??t.score,_=xi(f),R=(Y=t.suggestions)==null?void 0:Y[0],M=!l&&typeof j=="number"?f-j:null,V=hs(t.dimensions,A),C=[...(t.suggestions??[]).map(P=>({text:P,applicable:!0})),...F?(t.linkedinRecommendations??[]).map(P=>({text:P,applicable:!1})):[]],D=F?t.hookAlternatives??[]:[],Q=F&&((((re=t.discoveryKeywords)==null?void 0:re.length)??0)>0||(((ce=(ne=t.hashtagStrategy)==null?void 0:ne.suggested)==null?void 0:ce.length)??0)>0||!!((we=t.hashtagStrategy)!=null&&we.recommendation));return e.jsxs("div",{"data-testid":"analysis-panel","data-score-mode":A,className:"rounded-xl border border-border bg-card p-4 sm:p-5 space-y-5 animate-slide-up",children:[l?e.jsxs("div",{className:"rounded-lg border border-border bg-secondary/40 p-3",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Previous review"}),e.jsx("p",{className:"text-sm text-foreground mt-1",children:"The draft or brand context changed since this review."}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Previous message score: ",e.jsxs("span",{className:"font-mono font-semibold",children:[f," / 100"]})]}),u&&e.jsxs(g,{size:"sm",onClick:u,className:"mt-3 w-full min-h-[44px] sm:min-h-0 gradient-primary text-primary-foreground gap-1.5 font-semibold",children:[e.jsx(gs,{className:"w-3.5 h-3.5"}),"Recheck draft"]})]}):e.jsxs("div",{className:`rounded-lg border p-3 ${_.bg}`,children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Message score"}),e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[e.jsxs("p",{"data-testid":"message-score",className:"text-3xl font-bold font-mono text-foreground leading-tight",children:[f,e.jsx("span",{className:"text-base font-semibold text-muted-foreground",children:" / 100"})]}),e.jsx("span",{className:`text-sm font-bold ${_.tone}`,children:_.label})]}),e.jsxs("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground mt-0.5",children:[si(A),H&&!F?` · ${H}`:""]}),M!==null&&M!==0&&e.jsxs("p",{className:`text-xs font-semibold mt-1.5 ${M>0?"text-success":"text-destructive"}`,children:[M>0?`+${M}`:`−${Math.abs(M)}`," since last review"]}),R&&!p&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-xs text-foreground mt-2",children:[e.jsx("span",{className:"font-semibold",children:"One thing I'd improve: "}),R]}),x&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(g,{size:"sm",onClick:x,disabled:m,className:"min-h-[44px] sm:min-h-0 gradient-primary text-primary-foreground font-semibold",children:m?"Working…":"Fix this"}),h&&e.jsx(g,{size:"sm",variant:"outline",onClick:h,className:"min-h-[44px] sm:min-h-0",children:"Keep as is"})]})]}),F&&(S?e.jsx("p",{className:"mt-3 text-[11px] font-semibold text-success",children:"✓ Formatted for LinkedIn · wording preserved"}):k&&e.jsxs("div",{className:"mt-3",children:[e.jsxs(g,{size:"sm",variant:"outline",onClick:k,disabled:E,className:"min-h-[44px] sm:min-h-0 gap-1.5 font-semibold border-primary/40 text-primary",children:[e.jsx(Ns,{className:"w-3.5 h-3.5"}),E?"Formatting…":"Format for LinkedIn"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Keeps your wording; improves presentation."})]})),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-2",children:hi}),e.jsx("p",{"data-testid":"score-scope",className:"text-[10px] text-muted-foreground mt-1",children:Hr(A)})]}),!l&&C.length>0&&e.jsxs("details",{"data-testid":"inline-recommendations",className:"rounded-lg border border-border bg-secondary/20 px-3 py-2",open:!0,children:[e.jsx("summary",{className:"cursor-pointer list-none",children:e.jsxs(yt,{icon:e.jsx(_r,{className:"w-3.5 h-3.5 text-warning"}),children:["More recommendations (",C.length,")"]})}),e.jsx("ul",{className:"space-y-1.5",children:C.map((P,X)=>e.jsxs("li",{className:"rounded-lg bg-secondary px-3 py-2 text-xs text-secondary-foreground flex flex-wrap items-start justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 break-words",children:P.text}),P.applicable&&v?e.jsx(g,{size:"sm",variant:"outline",onClick:()=>v(P.text,X),disabled:L!=null,className:"h-7 shrink-0 px-2 text-[11px] font-semibold",title:"Fix this — generates revised versions of your draft for this recommendation",children:L===X?"Working…":"Fix this"}):e.jsx("span",{className:"shrink-0 rounded-full border border-border bg-card px-2 py-0.5 text-[10px] font-semibold text-muted-foreground",title:"Advisory guidance — no automatic rewrite for this one",children:"Adv
81isory"})]},X))})]}),!l&&(Q||D.length>0)&&e.jsxs("details",{"data-testid":"optimize-for-linkedin",className:"rounded-lg border border-border bg-secondary/20 px-3 py-2",open:!0,children:[e.jsx("summary",{className:"cursor-pointer list-none",children:e.jsx(yt,{icon:e.jsx(Nt,{className:"w-3.5 h-3.5 text-primary"}),children:"Optimize for LinkedIn"})}),!l&&Q&&e.jsxs("div",{"data-testid":"inline-discovery",children:[e.jsx(yt,{icon:e.jsx(Nt,{className:"w-3.5 h-3.5 text-primary"}),children:"LinkedIn discovery strategy"}),((y=t.hashtagStrategy)==null?void 0:y.recommendation)&&e.jsx("p",{className:"text-xs text-foreground",children:t.hashtagStrategy.recommendation}),(((ke=(O=t.hashtagStrategy)==null?void 0:O.suggested)==null?void 0:ke.length)??0)>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:t.hashtagStrategy.suggested.map((P,X)=>e.jsx("span",{className:"max-w-full break-all rounded-full bg-primary/10 px-2.5 py-1 font-mono text-xs text-primary",children:P.startsWith("#")?P:`#${P}`},X))}),(((ie=t.discoveryKeywords)==null?void 0:ie.length)??0)>0&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mt-2 flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:[e.jsx(bs,{className:"w-2.5 h-2.5"})," Discovery terms"]}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1.5",children:t.discoveryKeywords.map((P,X)=>e.jsx("span",{className:"max-w-full break-words rounded-full bg-accent/10 px-2.5 py-1 text-xs text-accent",children:P},X))})]}),e.jsx("p",{className:"mt-2 text-[10px] text-muted-foreground",children:"Topic and discovery strategy for LinkedIn — not a reach or engagement promise."})]}),!l&&D.length>0&&e.jsxs("div",{"data-testid":"inline-hooks",children:[e.jsx(yt,{icon:e.jsx(q,{className:"w-3.5 h-3.5 text-accent"}),children:"Hook options"}),e.jsx("div",{className:"space-y-1.5",children:D.map((P,X)=>e.jsxs("div",{className:"rounded-lg bg-secondary px-3 py-2 text-xs text-secondary-foreground flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("span",{className:"min-w-0 flex-1 break-words italic",children:['"',P,'"']}),G&&e.jsx(g,{size:"sm",variant:"outline",onClick:()=>G(P),className:"h-7 shrink-0 px-2 text-[11px] font-semibold",title:"Replace only the opening line of your draft with this hook",children:"Use"})]},X))}),e.jsx("p",{className:"mt-1.5 text-[10px] text-muted-foreground",children:"Use replaces only your opening line. The rest of your draft is untouched, and the review needs a recheck after."})]})]}),r&&!l&&e.jsxs("div",{className:"rounded-lg border border-border bg-secondary/30 px-3 py-2",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"More improvements"}),e.jsxs(g,{size:"sm",variant:"outline",onClick:r,disabled:n,className:"mt-2 w-full gap-1.5 font-semibold",children:[e.jsx(Pe,{className:"w-3.5 h-3.5"}),n?"Generating revised versions…":"Improve using all suggestions"]})]}),e.jsxs("details",{className:"group",children:[e.jsx("summary",{className:"cursor-pointer list-none text-xs font-semibold text-primary hover:underline",children:l?"Previous score details":"Details"}),e.jsxs("div",{className:"mt-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2",children:"Score breakdown"}),e.jsx("div",{className:"space-y-1.5",children:V.map(P=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground w-[42%] shrink-0 truncate",title:P.label,children:P.label}),e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-secondary overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${P.value}%`}})}),e.jsx("span",{className:"text-[11px] font-mono font-semibold text-foreground w-7 text-right",children:P.value}),e.jsxs("span",{className:"text-[10px] text-muted-foreground/70 w-8 text-right",children:[Math.round(P.weight*100),"%"]})]},P.key))}),e.jsx("p",{className:"mt-2 text-[10px] text-muted-foreground",children:"Weights are fixed and the total is computed on this device from these dimensions."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ys,{className:"w-4 h-4 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Target Audience"}),e.jsx("p",{className:"text-sm text-foreground mt-0.5",children:t.audience})]})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ze,{className:"w-4 h-4 text-accent mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Goal"}),e.jsx("p",{className:"text-sm text-foreground mt-0.5",children:t.goal})]})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ve,{className:"w-4 h-4 text-warning mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Tone"}),e.jsx("p",{className:"text-sm text-foreground mt-0.5",children:t.tone})]})]})]}),((at=t.hashtagStrategy)==null?void 0:at.rationale)&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Nt,{className:"w-3.5 h-3.5 text-primary"}),e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Discovery rationale"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.hashtagStrategy.rationale})]}),l&&(((Oe=t.suggestions)==null?void 0:Oe.length)??0)>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Cr,{className:"w-3.5 h-3.5 text-primary"}),e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Previous recommendations"})]}),e.jsx("ul",{className:"space-y-1.5",children:t.suggestions.map((P,X)=>e.jsx("li",{className:"text-xs text-secondary-foreground bg-secondary rounded-lg px-3 py-2",children:P},X))})]})]})]})]})}const Ie=280,tt=25e3,ps="li_x_post_mode";function fi(t){return t==="unknown"||t==="standard"||t==="premium"}function gi(){try{const t=localStorage.getItem(ps);return fi(t)?t:"unknown"}catch{return"unknown"}}function bi(t){try{t==="unknown"?localStorage.removeItem(ps):localStorage.setItem(ps,t)}catch{}}function Br(t){return t==="standard"?Ie:tt}function yi(t){return t==="premium"?tt:Ie}function ji(t,s){return t>tt?{level:"warning",limit:s==="standard"?Ie:tt,message:`Over 25,000 characters (${t.toLocaleStr
81ing()}) — too long for any X account.`}:s==="standard"?t>Ie?{level:"warning",limit:Ie,message:`Over 280 characters (${t}) — shorten or adapt before posting to X.`}:{level:"ok",limit:Ie,message:null}:s==="premium"?{level:"ok",limit:tt,message:null}:t>Ie?{level:"info",limit:null,message:"Longer than 280 characters. X Premium supports posts up to 25,000. Choose your X posting limit to validate this draft."}:{level:"ok",limit:null,message:null}}const vi=/[\u{1D400}-\u{1D433}\u{1D5D4}-\u{1D607}\u{1D63C}-\u{1D66F}\u{1D7CE}-\u{1D7D7}\u{1D7EC}-\u{1D7F5}]/u,Ni=/(?:^|\s)#[\p{L}\p{N}_]+/gu,wi=new RegExp("\\p{Extended_Pictographic}","gu"),ki=/\b(?:bit\.ly|t\.co|tinyurl\.com|goo\.gl|ow\.ly|buff\.ly|is\.gd|rebrand\.ly)\//i,Is={linkedin:3e3,x:280,facebook:63206,instagram:2200},Si=5,_i=2,Ci=3,Ai=2;function Et(t){return(t.match(Ni)??[]).length}function fs(t){return(t.match(wi)??[]).length}function Es(t){return vi.test(t)}const Ps="Stylized Unicode text is not read reliably by screen readers — use it sparingly.";function Ii(t,s={}){const r=[],n=[],i=s.xMode??"unknown",a=Br(i);t.length>a&&r.push(`Exceeds the ${a.toLocaleString()}-character limit (got ${t.length.toLocaleString()}).`);const o=Et(t);return o>_i&&n.push(`X recommends no more than 2 hashtags (got ${o}) — keep tags few and relevant.`),Es(t)&&n.push(Ps),fs(t)>3&&n.push(`Heavy emoji use for X (got ${fs(t)}) — 0-3 reads cleaner.`),{ok:r.length===0,violations:r,recommendations:n}}function Ei(t){const s=[],r=[];t.length>Is.linkedin&&s.push(`Exceeds the 3,000-character limit (got ${t.length}).`);const n=Et(t);return n>Ci&&r.push(`${n} hashtags on LinkedIn — hashtags are optional here; a few highly relevant tags beat volume.`),/\.{4,}$/.test(t.trim())&&r.push("Trailing 4+ dots read like truncation — end on a clear line."),{ok:s.length===0,violations:s,recommendations:r}}function Pi(t){const s=[],r=[];t.length>Is.facebook&&s.push(`Exceeds Facebook's 63,206-character ceiling (got ${t.length}).`);const n=Et(t);return n>Ai&&r.push(`${n} hashtags on Facebook — Meta penalizes spammy or unrelated hashtag use; 0-2 relevant tags is safer.`),ki.test(t)&&r.push("Prefer native URLs over link shorteners for link quality."),Es(t)&&r.push(Ps),{ok:s.length===0,violations:s,recommendations:r}}function Ti(t){const s=[],r=[];t.length>Is.instagram&&s.push(`Exceeds the 2,200-character caption limit (got ${t.length}).`);const n=Et(t);return n>Si&&s.push(`Instagram allows a maximum of 5 hashtags per post (got ${n}).`),n>0&&n<3&&r.push(`${n} hashtag${n===1?"":"s"} — 3-5 highly relevant tags help topical discovery.`),Es(t)&&r.push(Ps),fs(t)<1&&r.push("Instagram captions usually read better with an emoji or two."),{ok:s.length===0,violations:s,recommendations:r}}const Mi={x:Ii,linkedin:Ei,facebook:Pi,instagram:Ti};function hr(t,s,r={}){return Mi[t](s??"",r)}const Ct="sb_composer_publish_flow",ss="sb_composer_publish_opportunities",Wr=2*60*60*1e3,Ri=2e3,Oi={linkedin:"LinkedIn",x:"X",facebook:"Facebook",instagram:"Instagram",native_share:"Share"};function At(t){return Oi[t]}function Li(t){return t<=280?"0-280":t<=800?"281-800":t<=1500?"801-1500":t<=3e3?"1501-3000":"3000+"}function Gr(t){return`https://x.com/intent/post?text=${encodeURIComponent(t)}`}function Yr(t,s){return t!=="x"?!1:Gr(s).length<=Ri}function Fi(t,s=""){switch(t){case"x":return Yr("x",s)?Gr(s):"https://x.com/compose/post";case"linkedin":return"https://www.linkedin.com/feed/?shareActive=true";case"facebook":return"https://www.facebook.com/";case"instagram":return"https://www.instagram.com/";default:return"https://www.linkedin.com/feed/?shareActive=true"}}function Di(t,s=""){return t==="native_share"?"Share…":`Open in ${At(t)}`}function $i(t,s,r){let n=0;for(let i=0;i<r.length;i++)n=n*31+r.charCodeAt(i)|0;return`${t}:${s}:${r.length}:${n}`}function zi(){try{const t=sessionStorage.getItem(Ct);if(!t)return null;const s=JSON.parse(t);return!(s!=null&&s.platform)||!(s!=null&&s.outcomeId)?null:Date.now()-(s.updatedAt??0)>Wr?(sessionStorage.removeItem(Ct),null):s}catch{return null}}function Hi(t){try{sessionStorage.setItem(Ct,JSON.stringify({...t,updatedAt:Date.now()}))}catch{}}
81function Ui(){try{sessionStorage.removeItem(Ct)}catch{}}function Bi(t){try{const s=sessionStorage.getItem(ss),r=s?JSON.parse(s):{},n=Date.now(),i=Object.fromEntries(Object.entries(r).filter(([,a])=>Number.isFinite(a)&&n-a<=Wr));return i[t]?(sessionStorage.setItem(ss,JSON.stringify(i)),!1):(i[t]=n,sessionStorage.setItem(ss,JSON.stringify(i)),!0)}catch{return!0}}function jt(t,s={}){return{platform:t.platform,source_action:t.sourceAction,character_bucket:t.characterBucket,stage:t.stage,...s}}function Wi(){return typeof navigator<"u"&&typeof navigator.share=="function"}function Kr({text:t,platform:s,sourceAction:r,composerMode:n,runId:i,onComplete:a}){const o=$i(s,r,t),[l,u]=c.useState(()=>{const E=zi();return E&&E.outcomeId===o?E:{platform:s,sourceAction:r,characterBucket:Li(t.length),stage:"copied",outcomeId:o,updatedAt:Date.now()}}),x=c.useRef(null);c.useEffect(()=>{Hi(l)},[l]);const m={composer_mode:n??null,run_id:i??null};c.useEffect(()=>{x.current!==o&&(x.current=o,Bi(o)&&N(w.COMPOSER_PUBLISH_PROMPT_SHOWN,jt(l,m)))},[o]);const p=Yr(s,t),h=Wi(),j=async E=>{const S={...l,platform:E,stage:"destination_opened",updatedAt:Date.now()};if(N(w.COMPOSER_PUBLISH_ACTION_CLICKED,jt({...l,platform:E},{...m,prefilled:E==="x"&&p})),E==="native_share")try{await navigator.share({text:t})}catch{}else{if(!p||E!=="x")try{await _s(t)}catch{}window.open(Fi(E,t),"_blank","noopener,noreferrer")}u(S),N(w.COMPOSER_PUBLISH_DESTINATION_OPENED,jt(S,{...m,prefilled:E==="x"&&p}))},k=E=>{const S={...l,stage:E?"confirmed":"not_yet",updatedAt:Date.now()};u(S),N(E?w.COMPOSER_PUBLISH_CONFIRMED:w.COMPOSER_PUBLISH_NOT_YET,jt(S,m)),E&&(Ui(),a==null||a())};return l.stage==="confirmed"?null:e.jsxs("div",{"data-testid":"publish-inline",className:"flex min-w-0 flex-1 flex-wrap items-center gap-2",children:[l.stage==="copied"&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{"data-testid":"publish-copied-status",className:"inline-flex h-9 shrink-0 items-center gap-1.5 text-xs font-semibold text-success",children:["Copied ",e.jsx(Z,{className:"w-3.5 h-3.5","aria-hidden":"true"})]}),e.jsxs(g,{size:"sm","data-testid":"publish-open-destination",className:"min-w-[10.5rem] flex-1 gap-1.5 font-semibold",onClick:()=>void j(s),children:[Di(s,t),e.jsx(He,{"aria-hidden":"true"})]}),h&&e.jsxs(g,{size:"sm",variant:"outline","data-testid":"publish-native-share",className:"shrink-0 gap-1.5 text-xs",onClick:()=>void j("native_share"),children:[e.jsx(Ir,{className:"w-3.5 h-3.5"})," Share…"]})]}),(l.stage==="destination_opened"||l.stage==="not_yet")&&e.jsxs("div",{"data-testid":"publish-inline-confirmation",className:"flex min-w-0 flex-1 flex-wrap items-center gap-2",children:[e.jsxs("p",{className:"mr-auto text-[11px] font-semibold text-foreground",children:["Published it on ",At(l.platform),"?"]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsxs(g,{size:"sm","data-testid":"publish-confirm-yes",className:"gap-1.5 text-xs",onClick:()=>k(!0),children:[e.jsx(Z,{className:"w-3.5 h-3.5"})," Yes, published"]}),e.jsx(g,{size:"sm",variant:"outline","data-testid":"publish-confirm-no",className:"text-xs",onClick:()=>k(!1),children:"Not yet"})]}),l.stage==="not_yet"&&e.jsxs(g,{size:"sm",variant:"ghost",onClick:()=>void j(l.platform),"data-testid":"publish-reopen-destination",className:"h-8 px-2 text-[10px] text-primary",children:["Open ",At(l.platform)," again"]})]})]})}const et={linkedin:{name:"LinkedIn",color:"hsl(210, 100%, 45%)",maxChars:3e3},x:{name:"X (Twitter)",color:"hsl(0, 0%, 15%)",maxChars:280},facebook:{name:"Facebook",color:"hsl(220, 46%, 48%)",maxChars:63206},instagram:{name:"Instagram",color:"hsl(340, 75%, 54%)",maxChars:2200}};function Pt(t,s){return t.length<=s?t:t.slice(0,s-3)+"..."}function Ts({files:t}){const s=t.filter(r=>r.type.startsWith("image/"));return s.length?e.jsx("div",{className:`grid gap-1 mt-2 ${s.length===1?"grid-cols-1":"grid-cols-2"}`,children:s.slice(0,4).map(r=>e.jsx("img",{src:r.url,alt:r.name,className:"w-full h-32 object-cover rounded-md"},r.id))}):null}function Te({text:t,className:s}){return e.jsx("span",{className:s,dangerouslySetInnerHTML:{__html:Ja(t)}})}function Gi({content:t,files:s}){const r=Pt(t,3e3),[n,i]=c.useState(!1),a=r.length>200;return e.jsxs("div",{className:"rounded-lg bg-card border border-border p-3 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-secondary flex items-center justify-center",children:e.jsx(We,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-foreground",children:"Your Name"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Your headline · 1m"})]})]}),e.jsx("div",{className:"text-xs text-foreground whitespace-pre-wrap leading-relaxed",children:a&&!n?e.jsxs(e.Fragment,{children:[e.jsx(Te,{text:r.slice(0,200)}),e.jsx("button",{onClick:()=>i(!0),className:"text-muted-foreground hover:text-foreground ml-1 underline-offset-2 hover:underline",children:"...see more"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{text:r}),a&&e.jsx("button",{onClick:()=>i(!1),className:"block mt-1 text-muted-foreground hover:text-foreground underline-offset-2 hover:underline",children:"show less"})]})}),e.jsx(Ts,{files:s}),e.jsx("div",{className:"flex items-center gap-4 pt-1.5 border-t border-border/50 text-muted-foreground",children:[{icon:Ar,l:"Like"},{icon:ve,l:"Comment"},{icon:Or,l:"Repost"},{icon:It,l:"Send"}].map(({icon:o,l})=>e.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[e.jsx(o,{className:"w-3 h-3"}),l]},l))})]})}function Yi({mode:t,onChange:s,compact:r=!1}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5","data-testid":"x-limit-choice",children:[!r&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"X posting limit:"}),[{key:"standard",label:"Standard (280)"},{key:"premium",label:"Premium (25,000)"}].map(n=>e.jsx("button",{type:"button",onClick:()=>s(t===n.key?"unknown":n.key),"aria-pressed":t===n.key,className:`px-2 py-0.5 rounded-full text-[10px] font-semibold border transition-colors ${t===n.key?"bg-primary text-primary-foreground border-primary":"bg-secondary text-secondary-foreground border-border"}`,children:n.label},n.key))]})}function Ki({content:t,files:s,xMode:r,onXModeChange:n}){const i=Pt(t,Br(r)),a=ji(t.length,r);return e.jsxs("div",{className:"rounded-lg bg-card border border-border p-3 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-secondary flex items-center justify-center",children:e.jsx(We,{className:"w-4 h-4 text-muted-foreground"})}),e.jsx("div",{children:e.jsx("p",{className:"text-xs font-semibold text-foreground",children:"@yourhandle"})})]}),e.jsx("div",{className:"text-xs text-foreground whitespace-pre-wrap leading-relaxed break-words",children:e.jsx(Te,{text:i})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-1.5",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums","data-testid":"x-char-count",children:[t.length.toLocaleStr
81ing(),a.limit!==null?` / ${a.limit.toLocaleString()}`:" characters"]}),e.jsx(Yi,{mode:r,onChange:n,compact:!0})]}),a.message&&a.level==="warning"&&e.jsxs("p",{className:"text-[10px] text-warning font-medium","data-testid":"x-length-warning",children:["⚠️ ",a.message]}),a.message&&a.level==="info"&&e.jsx("p",{className:"text-[10px] text-muted-foreground","data-testid":"x-length-info",children:a.message}),e.jsx(Ts,{files:s}),e.jsx("div",{className:"flex items-center gap-5 pt-1.5 text-muted-foreground",children:[{icon:ve,l:"0"},{icon:Or,l:"0"},{icon:Sr,l:"0"},{icon:Mr,l:""}].map(({icon:o,l},u)=>e.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[e.jsx(o,{className:"w-3 h-3"}),l]},u))})]})}function Xi({content:t,files:s}){const r=Pt(t,63206),[n,i]=c.useState(!1),a=r.length>200;return e.jsxs("div",{className:"rounded-lg bg-card border border-border p-3 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-secondary flex items-center justify-center",children:e.jsx(We,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-foreground",children:"Your Name"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Just now · 🌐"})]})]}),e.jsx("div",{className:"text-xs text-foreground whitespace-pre-wrap leading-relaxed",children:a&&!n?e.jsxs(e.Fragment,{children:[e.jsx(Te,{text:r.slice(0,200)}),e.jsx("button",{onClick:()=>i(!0),className:"text-muted-foreground hover:text-foreground ml-1 underline-offset-2 hover:underline",children:"...See more"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{text:r}),a&&e.jsx("button",{onClick:()=>i(!1),className:"block mt-1 text-muted-foreground hover:text-foreground underline-offset-2 hover:underline",children:"See less"})]})}),e.jsx(Ts,{files:s}),e.jsxs("div",{className:"flex items-center justify-between pt-1.5 border-t border-border/50 text-muted-foreground text-[10px]",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ar,{className:"w-3 h-3"})," Like"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ve,{className:"w-3 h-3"})," Comment"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ir,{className:"w-3 h-3"})," Share"]})]})]})}function Ji({content:t,files:s}){const r=Pt(t,2200),n=s.filter(i=>i.type.startsWith("image/"));return e.jsxs("div",{className:"rounded-lg bg-card border border-border overflow-hidden text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 p-3",children:[e.jsx("div",{className:"w-7 h-7 rounded-full bg-secondary flex items-center justify-center",children:e.jsx(We,{className:"w-3.5 h-3.5 text-muted-foreground"})}),e.jsx("p",{className:"text-xs font-semibold text-foreground",children:"yourhandle"})]}),n.length>0?e.jsx("img",{src:n[0].url,alt:"Post",className:"w-full h-40 object-cover"}):e.jsx("div",{className:"w-full h-40 bg-secondary/50 flex items-center justify-center text-muted-foreground text-xs",children:"Add an image for Instagram"}),e.jsxs("div",{className:"p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-foreground",children:[e.jsx(Sr,{className:"w-4 h-4"}),e.jsx(ve,{className:"w-4 h-4"}),e.jsx(It,{className:"w-4 h-4"}),e.jsx(Mr,{className:"w-4 h-4 ml-auto"})]}),e.jsx(Vi,{text:r})]})]})}function Vi({text:t}){const[s,r]=c.useState(!1),n=t.length>125;return e.jsxs("div",{className:"text-xs text-foreground",children:[e.jsx("span",{className:"font-semibold",children:"yourhandle "}),n&&!s?e.jsxs(e.Fragment,{children:[e.jsx(Te,{text:t.slice(0,125)}),e.jsx("button",{onClick:()=>r(!0),className:"text-muted-foreground hover:text-foreground ml-1 underline-offset-2 hover:underline",children:"...more"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{text:t,className:"whitespace-pre-wrap"}),n&&e.jsx("button",{onClick:()=>r(!1),className:"block mt-1 text-muted-foreground hover:text-foreground underline-offset-2 hover:underline",children:"less"})]})]})}function qi({platform:t,guidance:s}){if(!s)return null;const r=s.hashtagStrategy,n=!!r.recommendation||r.suggested.length>0;if(!(s.whyChanged.length>0||s.discoveryKeywords.length>0||n))return null;const a=et[t].name;return e.jsxs("div",{className:"mt-2 rounded-md border border-border bg-secondary/30 px-2 py-2 space-y-2 text-[10px] text-muted-foreground","data-testid":`channel-strategy-${t}`,children:[e.jsxs("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-primary",children:[a," strategy"]}
81),s.whyChanged.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-foreground",children:"Why this version changed"}),e.jsx("ul",{className:"list-disc pl-4",children:s.whyChanged.map((o,l)=>e.jsx("li",{className:"break-words",children:o},l))})]}),s.discoveryKeywords.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-foreground flex items-center gap-1",children:[e.jsx(bs,{className:"w-2.5 h-2.5"})," ",a," discovery terms"]}),e.jsx("p",{className:"break-words",children:s.discoveryKeywords.slice(0,8).join(" · ")})]}),n&&e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-foreground flex items-center gap-1",children:[e.jsx(Nt,{className:"w-2.5 h-2.5"})," ",a," hashtag strategy"]}),r.recommendation&&e.jsx("p",{className:"break-words",children:r.recommendation}),r.suggested.length>0&&e.jsx("p",{className:"font-mono text-primary break-all",children:r.suggested.map(o=>o.startsWith("#")?o:`#${o}`).join(" ")})]})]})}function Zi({guidance:t,recommendations:s}){var i;const r=(t==null?void 0:t.channelTips)??[],n=((i=t==null?void 0:t.hashtagStrategy)==null?void 0:i.rationale)??"";return r.length===0&&s.length===0&&!n?null:e.jsxs("details",{className:"mt-2 rounded-md border border-border bg-secondary/30 px-2 py-1.5",children:[e.jsx("summary",{className:"cursor-pointer list-none text-[10px] font-semibold text-primary",children:"More channel intelligence"}),e.jsxs("div",{className:"mt-2 space-y-2 text-[10px] text-muted-foreground",children:[n&&e.jsx("p",{className:"break-words",children:n}),r.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-foreground",children:"Channel tips"}),e.jsx("ul",{className:"list-disc pl-4",children:r.map((a,o)=>e.jsx("li",{className:"break-words",children:a},o))})]}),s.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-accent flex items-center gap-1",children:[e.jsx(q,{className:"w-2.5 h-2.5"})," Channel recommendations"]}),e.jsx("ul",{className:"list-disc pl-4",children:s.map((a,o)=>e.jsx("li",{className:"break-words",children:a},o))})]})]})]})}function Qi({content:t,files:s=[]}){const[r,n]=c.useState(["linkedin","x","facebook","instagram"]),[i,a]=c.useState("linkedin"),[o,l]=c.useState(null),[u,x]=c.useState(null),[m,p]=c.useState(!1),[h,j]=c.useState(null),{settings:k}=xe(),E=vr(),[S,v]=c.useState(()=>gi()),[L,G]=c.useState(null),B=C=>{v(C),bi(C),N("composer_x_limit_set",{mode:C})},H=!!o&&u!==t,A=!!o&&!H,F=C=>(A?o==null?void 0:o[C]:void 0)||t,f=async C=>{const D=F(C);try{await _s(D)}catch(Q){console.error("Copy failed:",Q),ye.error("Copy failed",{description:"We couldn't copy that to your clipboard."});return}j(C),G({platform:C,text:D}),N(w.COMPOSER_PLATFORM_COPY,{platform:C}),setTimeout(()=>j(null),2e3)};if(!t.trim()&&s.length===0)return null;const _=async()=>{if(!t.trim()||m)return;const C=t;p(!0),N(w.COMPOSER_PLATFORM_ADAPT_STARTED,{platform_count:4,stale_recheck:H});try{const D=await ui(C,k,{xCharLimit:yi(S)});l(D),x(C),N(w.COMPOSER_PLATFORM_ADAPT_COMPLETED,{platform_count:4})}catch(D){console.error("Adapt failed:",D),N(w.COMPOSER_PLATFORM_ADAPT_FAILED,{platform_count:4}),ye.error("Couldn't adapt these versions",{description:"Your draft is unchanged. Try again."})}finally{p(!1)}},R={linkedin:e.jsx(Gi,{content:F("linkedin"),files:s}),x:e.jsx(Ki,{content:F("x"),files:s,xMode:S,onXModeChange:B}),facebook:e.jsx(Xi,{content:F("facebook"),files:s}),instagram:e.jsx(Ji,{content:F("instagram"),files:s})},M=Object.keys(et),V=E?[i]:r;return e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 animate-slide-up",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Adapt to other channels"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:"Adapt this message for X, Facebook and Instagram with channel-specific strategy."})]}),e.jsx(g,{variant:o?"secondary":"default",size:"sm",onClick:_,disabled:m||!t.trim(),className:"gap-1.5 text-xs shrink-0",children:m?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-3 h-3 animate-spin"})," Adapting..."]}):H?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-3 h-3"}
81)," Re-adapt"]}):o?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-3 h-3"})," Adapt again"]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{className:"w-3 h-3"})," Adapt versions"]})})]}),H&&e.jsxs("div",{className:"mb-2 rounded-md border border-border bg-secondary/50 px-2 py-1.5 text-[10px] text-muted-foreground",children:[e.jsx("p",{className:"font-semibold text-foreground",children:"Your draft changed since these versions were adapted."}),e.jsx("p",{children:"Re-adapt to refresh them."})]}),A&&e.jsx("p",{className:"text-[10px] text-accent mb-1",children:"✅ Platform versions are ready. Review before publishing."}),o&&e.jsx("p",{className:"text-[10px] text-muted-foreground mb-2",children:"Platform guidance is directional and may change; these checks are not platform certification."}),e.jsx("div",{className:"flex gap-1.5 mb-3 flex-wrap",children:M.map(C=>{const D=F(C),Q=E?i===C:r.includes(C),Y=A?hr(C,D,{xMode:S}):null;return e.jsxs("button",{onClick:()=>{E?a(C):n(re=>re.includes(C)?re.filter(ne=>ne!==C):[...re,C])},className:`px-2.5 py-1 rounded-full text-[10px] font-semibold border transition-colors flex items-center gap-1 ${Q?"bg-primary text-primary-foreground border-primary":"bg-secondary text-secondary-foreground border-border"}`,title:Y&&!Y.ok?Y.violations.join(`
82`):void 0,children:[et[C].name,Y&&!Y.ok&&e.jsx(Ee,{className:"w-2.5 h-2.5 text-warning"})]},C)})}),e.jsx("div",{className:`grid gap-3 ${!E&&V.length>1?"grid-cols-1 sm:grid-cols-2":"grid-cols-1"}`,children:V.map(C=>{var Q,Y;const D=A?hr(C,F(C),{xMode:S}):null;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex min-w-0 flex-wrap items-center justify-between gap-2",children:[e.jsx("p",{className:"text-[10px] font-semibold text-muted-foreground",children:et[C].name}),(L==null?void 0:L.platform)===C&&L.text===F(C)?e.jsx("div",{"data-testid":`platform-copy-action-row-${C}`,className:"flex min-w-[15rem] flex-1 justify-end",children:e.jsx(Kr,{text:L.text,platform:L.platform,sourceAction:"platform_copy",onComplete:()=>G(null)},`${L.platform}:platform_copy:${L.text}`)}):e.jsx(g,{size:"sm",variant:"ghost",onClick:()=>f(C),className:"h-8 gap-1 px-2 text-[10px] text-muted-foreground",title:`Copy ${et[C].name} version`,children:h===C?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-3 h-3 text-accent"})," Copied!"]}):e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"w-3 h-3"})," Copy"]})})]}),D&&D.violations.length>0&&e.jsxs("div",{className:"mb-2 rounded-md border border-warning/40 bg-warning/10 px-2 py-1.5 text-[10px] text-warning-foreground space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1 font-semibold text-warning",children:[e.jsx(Ee,{className:"w-3 h-3"})," Platform limits (",D.violations.length,")"]}),e.jsx("ul",{className:"list-disc pl-4 text-muted-foreground",children:D.violations.map((re,ne)=>e.jsx("li",{children:re},ne))})]}),R[C],e.jsx(qi,{platform:C,guidance:A?(Q=o==null?void 0:o.guidance)==null?void 0:Q[C]:void 0}),e.jsx(Zi,{guidance:A?(Y=o==null?void 0:o.guidance)==null?void 0:Y[C]:void 0,recommendations:(D==null?void 0:D.recommendations)??[]})]},C)})})]})}const eo={voice_samples:[],recurring_themes:[],banned_phrases:[],cta_style:""};function to(){let t=localStorage.getItem("li_device_id");return t||(t=crypto.randomUUID(),localStorage.setItem("li_device_id",t)),t}function so(){const[t,s]=c.useState(eo),[r,n]=c.useState(!0),[i,a]=c.useState(!1),o=to();c.useEffect(()=>{(async()=>{const{data:u}=await W.rpc("get_brand_memory_by_device",{p_device_id:o}),x=Array.isArray(u)?u[0]:null;x&&s({voice_samples:x.voice_samples??[],recurring_themes:x.recurring_themes??[],banned_phrases:x.banned_phrases??[],cta_style:x.cta_style??""}),n(!1)})()},[o]);const l=c.useCallback(async u=>{a(!0),s(u);const{error:x}=await W.functions.invoke("secure-mutate",{body:{table:"brand_memory",operation:"upsert",device_id:o,data:u}});return a(!1),!x},[o]);return{memory:t,loading:r,saving:i,save:l}}function rs({label:t,hint:s,items:r,placeholder:n,onChange:i}){const[a,o]=c.useState(""),l=()=>{const u=a.trim();!u||r.includes(u)||(i([...r,u]),o(""))};return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:t}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-2",children:s}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx(pe,{value:a,onChange:u=>o(u.target.value),onKeyDown:u=>u.key==="Enter"&&(u.preventDefault(),l()),placeholder:n,className:"text-sm h-8"}),e.jsx(g,{variant:"outline",size:"sm",onClick:l,className:"h-8 px-2",children:e.jsx(Er,{className:"w-3.5 h-3.5"})})]}),r.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map((u,x)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs px-2.5 py-1 rounded-full bg-secondary text-secondary-foreground border border-border",children:[u,e.jsx("button",{onClick:()=>i(r.filter((m,p)=>p!==x)),className:"hover:text-destructive",children:e.jsx(te,{className:"w-3 h-3"})})]},x))})]})}function ro(){const{memory:t,loading:s,saving:r,save:n}=so(),[i,a]=c.useState(null),o=i??t,l=h=>{a({...o,...h})},u=async()=>
82{if(!i)return;await n(i)?(a(null),ye.success("Brand memory saved")):ye.error("Failed to save")},x=async()=>{await n({voice_samples:[],recurring_themes:[],banned_phrases:[],cta_style:""})&&(a(null),ye.success("Brand memory cleared"))};if(s)return e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground py-4",children:[e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin"})," Loading brand memory…"]});const m=i!==null,p=o.voice_samples.length>0||o.recurring_themes.length>0||o.banned_phrases.length>0||o.cta_style.length>0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xn,{className:"w-4 h-4 text-primary"}),e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Brand Memory"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground -mt-2",children:"Teach the AI your voice. This context is injected into every prompt automatically."}),e.jsx(rs,{label:"Voice Samples",hint:"Paste short phrases that sound like you (e.g. 'Here's the thing…', 'Let me be blunt:')",items:o.voice_samples,placeholder:"Add a signature phrase…",onChange:h=>l({voice_samples:h})}),e.jsx(rs,{label:"Recurring Themes",hint:"Topics you frequently post about (e.g. 'remote work', 'AI in healthcare')",items:o.recurring_themes,placeholder:"Add a theme…",onChange:h=>l({recurring_themes:h})}),e.jsx(rs,{label:"Banned Phrases",hint:"Words or phrases the AI should never use (e.g. 'synergy', 'game-changer')",items:o.banned_phrases,placeholder:"Add a banned phrase…",onChange:h=>l({banned_phrases:h})}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Preferred CTA Style"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-2",children:`How you like to end posts (e.g. "Drop a 🔥 if you agree" or "DM me 'GUIDE' for the full doc")`}),e.jsx(st,{value:o.cta_style,onChange:h=>l({cta_style:h.target.value}),placeholder:"Describe your preferred call-to-action style…",className:"text-sm min-h-[60px]",maxLength:300})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[m&&e.jsxs(g,{size:"sm",onClick:u,disabled:r,className:"gap-1.5",children:[r?e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ua,{className:"w-3.5 h-3.5"}),"Save"]}),p&&e.jsxs(g,{variant:"ghost",size:"sm",onClick:x,disabled:r,className:"gap-1.5 text-destructive hover:text-destructive",children:[e.jsx(us,{className:"w-3.5 h-3.5"})," Clear All"]})]})]})}const no=["English","Spanish","French","German","Portuguese","Arabic","Chinese","Japanese","Hindi"];function ao({onClose:t}){const{settings:s,updateSettings:r}=xe(),{theme:n,setTheme:i}=ha(),a=[{value:"light",label:"Light",icon:ga},{value:"dark",label:"Dark",icon:pa},{value:"system",label:"System",icon:fa}];return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:t,children:e.jsxs("div",{className:"w-full max-w-lg max-h-[85vh] overflow-y-auto rounded-xl border border-border bg-card p-6 shadow-2xl animate-slide-up mx-4",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-foreground",children:"Writing Settings"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Choose your audience to shape how AI writes for you"})]}),e.jsx(g,{variant:"ghost",size:"sm",onClick:t,children:e.jsx(te,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Audience Mode"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2.5",children:ds.map(o=>{const l=s.audiencePreset===o.id;return e.jsxs("button",{onClick:()=>r({audiencePreset:o.id}),className:`relative text-left rounded-lg border p-3 transition-all ${l?"border-primary bg-primary/5 ring-1 ring-primary/20":"border-border bg-secondary/30 hover:border-primary/40 hover:bg-secondary/60"}`,children:[l&&e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(Z,{className:"w-3.5 h-3.5 text-primary"})}),e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-base",children:o.emoji}),e.jsx("span",{className:`text-sm font-semibold ${l?"text-primary":"text-foreground"}`,children:o.label})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug pr-4",children:o.description})]},o.id)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Default Language"}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:no.map(o=>e.jsx("button",{onClick:()=>r({language:o}),className:`text-xs px-3 py-1.5 rounded-full border transition-colors ${s.language===o?"bg-primary text-primary-foreground border-primary":"bg-secondary text-secondary-foreground border-border hover:border-primary/50"}`,children:o},o))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Theme"}),e.jsx("div",{className:"flex gap-2 mt-2",children:a.map(o=>{const l=o.icon;return e.jsxs("button",{onClick:()=>
82i(o.value),className:`flex items-center gap-2 text-xs px-3 py-2 rounded-lg border transition-colors ${n===o.value?"bg-primary text-primary-foreground border-primary":"bg-secondary text-secondary-foreground border-border hover:border-primary/50"}`,children:[e.jsx(l,{className:"w-3.5 h-3.5"}),o.label]},o.value)})})]}),e.jsx("div",{className:"border-t border-border pt-5",children:e.jsx(ro,{})})]})]})})}function io(){const[t,s]=c.useState(""),[r,n]=c.useState(!1),[i,a]=c.useState(!1),{applyPromo:o,promoApplied:l}=xe(),{toast:u}=je(),x=async()=>{if(!t.trim()||i)return;a(!0);const m=await o(t);a(!1),m.success?(u({title:"Promo code applied",description:"You've unlocked extra free creation uses."}),s(""),n(!1)):u({variant:"destructive",title:"Code not valid",description:m.error})};return l?null:e.jsxs("div",{className:"rounded-xl border border-primary/20 bg-primary/5 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(Jn,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Have a promo code?"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"If you received a promo code, enter it here."})]})]}),r?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:m=>s(m.target.value),placeholder:"Enter your code",className:"flex-1 rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring font-mono uppercase",onKeyDown:m=>m.key==="Enter"&&x(),disabled:i}),e.jsxs(g,{size:"sm",onClick:x,disabled:i,className:"gradient-primary text-primary-foreground gap-1",children:[i?e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Z,{className:"w-3.5 h-3.5"}),"Apply"]})]}):e.jsxs(g,{variant:"secondary",size:"sm",onClick:()=>n(!0),className:"w-full gap-1.5",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),"I have a promo code"]})]})}const oo=[{id:"thought-leadership",label:"Thought Leadership",icon:_r,description:"Share an insight or bold opinion in your field"},{id:"personal-story",label:"Personal Story",icon:ba,description:"A lesson learned from a real experience"},{id:"case-study",label:"Case Study / Win",icon:ze,description:"Showcase a result, project, or milestone"},{id:"audience-question",label:"Engage Your Audience",icon:wr,description:"Ask a question or spark a debate"},{id:"free-form",label:"Free Form",icon:js,description:"Just tell the AI your idea and it'll coach you"}];function lo({onClose:t,onPostReady:s}){const[r,n]=c.useState("menu"),[i,a]=c.useState(null),[o,l]=c.useState([]),[u,x]=c.useState(""),[m,p]=c.useState(!1),[h,j]=c.useState(null),[k,E]=c.useState([]),{settings:S}=xe(),{toast:v}=je(),L=async()=>{n("strategist"),p(!0);try{const{data:f,error:_}=await W.functions.invoke("linkedin-ai",{body:{action:"content_strategist",content:`My audience preset: ${S.audiencePreset}, language: ${S.language}`,settings:S}});if(_)throw _;const R=JSON.parse(f.result);E(R)}catch(f){v({variant:"destructive",title:"Failed to generate ideas",description:f.message}),n("menu")}finally{p(!1)}},G=f=>{const _=f.template||"free-form";a(_),n("chat"),p(!0),(async()=>{try{const{data:R,error:M}=await W.functions.invoke("linkedin-ai",{body:{action:"guided_coach",content:"",settings:{...S,template:_,step:"start",seedHook:f.hook,seedDescription:f.description}}});if(M)throw M;l([{role:"assistant",content:`💡 Great choice! Here's the idea we're working with:
83
84**Hook:** "${f.hook}"
85
86${R.result}`}])}catch(R){v({variant:"destructive",title:"Failed to start",description:R.message})}finally{p(!1)}})()},B=async f=>{a(f),n("chat"),p(!0);try{const{data:_,error:R}=await W.functions.invoke("linkedin-ai",{body:{action:"guided_coach",content:"",settings:{...S,template:f,step:"start"}}});if(R)throw R;l([{role:"assistant",content:_.result}])}catch(_){v({variant:"destructive",title:"Failed to start",description:_.message})}finally{p(!1)}},H=async()=>{if(!u.trim()||m)return;const f={role:"user",content:u.trim()},_=[...o,f];l(_),x(""),p(!0);try{const{data:R,error:M}=await W.functions.invoke("linkedin-ai",{body:{action:"guided_coach",content:JSON.stringify(_.map(D=>({role:D.role,content:D.content}))),settings:{...S,template:i,step:"continue"}}});if(M)throw M;const V=R.result,C=V.match(/===POST===([\s\S]*?)===END===/);if(C){j(C[1].trim()),n("preview");const D=V.replace(/===POST===[\s\S]*?===END===/,"").trim();D&&l([..._,{role:"assistant",content:D}])}else l([..._,{role:"assistant",content:V}])}catch(R){v({variant:"destructive",title:"Error",description:R.message})}finally{p(!1)}},A=()=>{r==="preview"?(n("chat"),j(null)):r==="chat"?(n("menu"),l([]),a(null)):r==="strategist"||r==="templates"?(n("menu"),E([])):t()},F=r==="strategist"?"💡 What Should I Post?":r==="templates"?"Choose a Template":r==="preview"?"Your Post is Ready!":r==="chat"?"AI Post Coach":"Create from Scratch";return e.jsx("div",{className:"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl shadow-2xl w-full max-w-2xl max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[r!=="menu"&&e.jsx(g,{variant:"ghost",size:"icon",onClick:A,children:e.jsx(Pr,{className:"w-4 h-4"})}),e.jsx(q,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-bold text-foreground",children:F})]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(te,{className:"w-4 h-4"})})]}),r==="menu"?e.jsxs("div",{className:"p-5 space-y-3 overflow-y-auto flex-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Start with AI-powered topic ideas or choose a template to build a post step-by-step."}),e.jsxs("button",{onClick:L,className:"w-full flex items-center gap-4 p-4 rounded-xl border-2 border-primary/30 bg-primary/5 hover:bg-primary/10 transition-all text-left group",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg gradient-primary flex items-center justify-center shrink-0",children:e.jsx(Nr,{className:"w-5 h-5 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-foreground text-sm",children:"💡 What Should I Post Today?"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"AI suggests 5 topic ideas based on your brand profile & audience"})]})]}),e.jsxs("div",{className:"relative py-2",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-border"})}),e.jsx("div",{className:"relative flex justify-center",children:e.jsx("span",{className:"bg-card px-3 text-xs text-muted-foreground",children:"or pick a template"})})]}),oo.map(f=>e.jsxs("button",{onClick:()=>B(f.id),disabled:m,className:"w-full flex items-center gap-4 p-4 rounded-xl border border-border hover:border-primary/50 hover:bg-secondary/50 transition-all text-left group",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center shrink-0 group-hover:bg-primary/20 transition-colors",children:e.jsx(f.icon,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-foreground text-sm",children:f.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f.description})]})]},f.id))]}):r==="strategist"?e.jsx("div",{className:"p-5 overflow-y-auto flex-1 space-y-3",children:m?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-3",children:[e.jsx(ae,{className:"w-8 h-8 text-primary animate-spin"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Analyzing your brand & generating ideas…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Here are 5 tailored post ideas based on your profile. Tap one to start building it."}),k.map((f,_)=>{var R;return e.jsx("button",{onClick:()=>G(f),className:"w-full text-left rounded-xl border border-border hover:border-primary/50 hover:bg-secondary/30 transition-all p-4 group",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm font-semibold text-foreground leading-snug mb-1",children:['"',f.hook,'"']}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f.description})]}),e.jsxs("div",{className:"shrink-0 flex flex-col items-end gap-1",children:[e.jsx("span",{className:`text-[10px] font-semibold px-2 py-0.5 rounded-full ${f.engagement==="high"?"bg-success/20 text-success":"bg-warning/20 text-warning"}`,children:f.engagement==="high"?"🔥 High":"📈 Medium"}),e.jsx("span",{className:"text-[10px] text-muted-foreground capitalize",children:(R=f.template)==null?void 0:R.replace("-"," ")})]})]})},_)})]})}):r==="preview"&&h?e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-4",children:[e.jsx("div",{className:"rounded-xl border border-primary/30 bg-primary/5 p-4",children:e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap leading-relaxed",children:h})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(g,{className:"flex-1 gradient-primary text-primary-foreground font-semibold",onClick:()=>{s(h),t()},children:"Use This Post"}),e.jsx(g,{variant:"secondary",className:"flex-1",onClick:A,children:"Keep Chatting"})]})]}):r==="chat"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-4",children:[o.map((f,_)=>e.jsx("div",{className:`flex ${f.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[85%] rounded-2xl px-4 py-3 text-sm leading-relaxed ${f.role==="user"?"bg-primary text-primary-foreground rounded-br-md":"bg-secondary text-secondary-foreground rounded-bl-md"}`,children:f.content})},_)),m&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-secondary text-secondary-foreground rounded-2xl rounded-bl-md px-4 py-3 text-sm",children:e.jsx("span",{className:"animate-pulse",children:"Thinking…"})})})]}),e.jsxs("div",{className:"border-t border-border/50 p-4 flex gap-2",children:[e.jsx("input",{value:u,onChange:f=>x(f.target.value),onKeyDown:f=>f.key==="Enter"&&!f.shiftKey&&H(),placeholder:"Type your answer…",className:"flex-1 bg-secondary rounded-lg px-4 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring",disabled:m}),e.jsx(g,{size:"icon",onClick:H,disabled:!u.trim()||m,className:"gradient-primary text-primary-foreground shrink-0",children:e.jsx(It,{className:"w-4 h-4"})})]})]}):null]})})}function co({postContent:t}){const[s,r]=c.useState([]),[n,i]=c.useState(!1),[a,o]=c.useState(null),{settings:l}=xe(),{toast:u}=je(),x=async()=>
86{if(!t.trim()){u({variant:"destructive",title:"No post content",description:"Write your post first, then generate comments."});return}i(!0),N(w.GENERATE_COMMENTS);try{const p=await li(t,l);r(p),u({title:"💬 Comments ready!",description:"Pick one to post under your LinkedIn post."})}catch(p){u({variant:"destructive",title:"Generation failed",description:p.message})}finally{i(!1)}},m=(p,h)=>{navigator.clipboard.writeText(p),o(h),setTimeout(()=>o(null),2e3),u({title:"📋 Comment copied!"})};return s.length===0?e.jsx("div",{className:"rounded-xl border border-border bg-card p-5",children:e.jsxs("div",{className:"text-center space-y-3 py-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-secondary mx-auto flex items-center justify-center",children:e.jsx(dr,{className:"w-5 h-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Comment Booster"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Generate 5 strategic first comments to increase reach and start better conversations."})]}),e.jsxs(g,{size:"sm",onClick:x,disabled:n||!t.trim(),className:"gradient-primary text-primary-foreground font-semibold gap-1.5",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),n?"Generating...":"Generate First Comments"]})]})}):e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5 space-y-4 animate-slide-up",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(dr,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"First Comment Options"})]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:x,disabled:n,title:"Regenerate comments",className:"h-7 w-7",children:e.jsx(gs,{className:`w-3.5 h-3.5 ${n?"animate-spin":""}`})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Post one of these as your first comment to boost reach and engagement."}),e.jsx("div",{className:"space-y-2.5",children:s.map((p,h)=>e.jsxs("div",{className:"rounded-lg border border-border bg-secondary/40 p-3 group hover:border-primary/30 transition-all",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-[10px] font-semibold text-primary uppercase tracking-wider",children:p.label}),e.jsx("button",{onClick:()=>m(p.text,h),className:"text-muted-foreground hover:text-primary transition-colors",title:"Copy comment",children:a===h?e.jsx(Z,{className:"w-3.5 h-3.5 text-success"}):e.jsx(Me,{className:"w-3.5 h-3.5"})})]}),e.jsx("p",{className:"text-xs text-foreground leading-relaxed",children:p.text})]},h))})]})}const mo=["Make it shorter","Make it punchier","Clarify the main point","Add a stronger hook","Make it more conversational","Add a call to action"],pr="sb_chat_history";function uo({currentPost:t,onApplyPost:s,onClose:r}){const[n,i]=c.useState(()=>{try{return JSON.parse(localStorage.getItem(pr)||"[]")}catch{return[]}}),[a,o]=c.useState(""),[l,u]=c.useState(!1),x=c.useRef(null),m=c.useRef(null),{settings:p}=xe(),{toast:h}=je();c.useEffect(()=>{n.length>0&&localStorage.setItem(pr,JSON.stringify(n))},[n]),c.useEffect(()=>{var S;(S=x.current)==null||S.scrollTo({top:x.current.scrollHeight,behavior:"smooth"})},[n]);const j=S=>{const v=S.match(/===POST===([\s\S]*?)===END===/);return v?v[1].trim():null},k=async S=>{var G;if(!S.trim()||l)return;const v={role:"user",content:S.trim()},L=[...n,v];i(L),o(""),u(!0);try{const{data:B,error:H}=await W.functions.invoke("linkedin-ai",{body:{action:"refine_post",content:JSON.stringify(L),settings:{...p,currentPost:t}}});if(H)throw H;if(B!=null&&B.error)throw new Error(B.error);const A={role:"assistant",content:B.result};i([...L,A])}catch(B){h({variant:"destructive",title:"Chat error",description:B.message||"Failed to get response"})}finally{u(!1),(G=m.current)==null||G.focus()}},E=S=>{const v=j(S);v&&(s(v),h({title:"✅ Post updated!",description:"The refined version has been applied."}))};return e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden animate-slide-up",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-border/50 bg-secondary/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:"Refine with AI Chat"})]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:r,className:"h-7 w-7",children:e.jsx(te,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{ref:x,className:"h-64 overflow-y-auto p-3 space-y-3",children:[n.length===0&&e.jsxs("div",{className:"text-center space-y-3 py-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tell me how you'd like to change your post — or pick a quick action:"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 justify-center",children:mo.map(S=>e.jsx("button",{onClick:()=>k(S),className:"px-2.5 py-1 rounded-full text-[10px] font-medium border border-border bg-secondary text-secondary-foreground hover:bg-primary hover:text-primary-foreground transition-colors",children:S},S))})]}),n.map((S,v)=>e.jsx("div",{className:`flex ${S.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[85%] rounded-lg px-3 py-2 text-xs leading-relaxed ${S.role==="user"?"bg-primary text-primary-foreground":"bg-secondary text-secondary-foreground"}`,children:[e.jsx("div",{className:"whitespace-pre-wrap",children:S.content.replace(/===POST===[\s\S]*?===END===/g,"").trim()}),S.role==="assistant"&&j(S.content)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 p-2 rounded-md bg-background border border-border/50 text-[11px] whitespace-pre-wrap max-h-40 overflow-y-auto",children:j(S.content)}),e.jsxs(g,{size:"sm",variant:"outline",className:"mt-2 gap-1 text-[10px] h-6 bg-card",onClick:()=>E(S.content),children:[e.jsx(Z,{className:"w-3 h-3"})," Apply this version"]})]})]})},v)),l&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-secondary rounded-lg px-3 py-2",children:e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"})})})]}),e.jsxs("div",{className:"border-t border-border/50 p-2 flex gap-2",children:[e.jsx("input",{ref:m,type:"text",value:a,onChange:S=>o(S.target.value),onKeyDown:S=>S.key==="Enter"&&k(a),placeholder:"e.g. Make the opening more dramatic...",className:"flex-1 rounded-lg border border-border bg-background px-3 py-2 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring",disabled:l}),e.jsx(g,{size:"icon",onClick:()=>k(a),disabled:l||!a.trim(),className:"h-8 w-8 shrink-0",children:e.jsx(It,{className:"w-3.5 h-3.5"})})]})]})}function xo({textareaRef:t,content:s,onContentChange:r}){const n=c.useRef({start:0,end:0}),[i,a]=c.useState({start:0,end:0}),o=c.useCallback(()=>{const x=t.current;if(x){const m={start:x.selectionStart,end:x.selectionEnd};n.current=m,a(m)}},[t]);c.useEffect(()=>{const x=t.current;if(!x)return;const m=["select","keyup","input","touchend","mouseup","click","focus"];m.forEach(h=>x.addEventListener(h,o));const p=()=>{document.activeElement===x&&o()};return document.addEventListener("selectionchange",p),()=>{m.forEach(h=>x.removeEventListener(h,o)),document.removeEventListener("selectionchange",p)}},[o,t]);const l=c.useCallback(x=>{const m=t.current;if(!m)return;const p=Ga(s,n.current,x);p.changed&&(n.current=p.selection,a(p.selection),r(p.content),requestAnimationFrame(()=>{m.focus(),m.setSelectionRange(p.selection.start,p.selection.end)}))},[s,r,t]),u=[{action:"bold",icon:La,label:"Bold"}
86,{action:"italic",icon:Fa,label:"Italic"},{action:"underline",icon:Ha,label:"Underline"},{action:"strikethrough",icon:za,label:"Strikethrough"},{action:"list",icon:ya,label:"Bullet list"},{action:"separator",icon:ja,label:"Insert separator"}];return e.jsxs("div",{className:"flex items-center gap-0.5 px-3 py-1.5 border-b border-border/30 bg-muted/30",children:[u.map(({action:x,icon:m,label:p},h)=>{const j=x!=="separator"&&Ya(s,i,x);return e.jsx(g,{type:"button",variant:"ghost",size:"icon",onPointerDown:k=>{document.activeElement===t.current&&o(),k.preventDefault()},onMouseDown:k=>k.preventDefault(),onClick:()=>l(x),title:p,"aria-label":p,"aria-pressed":x==="separator"?void 0:j,className:Vn("relative w-9 h-9 shrink-0 rounded-md text-muted-foreground","hover:bg-secondary hover:text-foreground active:scale-95","transition-all duration-150 ease-out","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",j&&"bg-primary/10 text-primary",h<u.length-2&&h===3&&"mr-1.5"),children:e.jsx(m,{className:"w-4 h-4"})},x)}),e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground/60 hidden sm:inline select-none",children:"Select text → format"})]})}const Tt="sb_post_history",ho=30;function Xr(){try{return JSON.parse(localStorage.getItem(Tt)||"[]")}catch{return[]}}function ns(t){if(!t.trim()||t.trim().length<20)return;const s=Xr();if(s.length>0&&s[0].content===t)return;const n=[{id:crypto.randomUUID(),content:t,createdAt:new Date().toISOString(),preview:t.slice(0,120).replace(/\n/g," ")},...s].slice(0,ho);localStorage.setItem(Tt,JSON.stringify(n))}function po(){localStorage.removeItem(Tt)}function fo(t){const s=Date.now()-new Date(t).getTime(),r=Math.floor(s/6e4);if(r<1)return"just now";if(r<60)return`${r}m ago`;const n=Math.floor(r/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function go({open:t,onClose:s,onRestore:r}){const[n,i]=c.useState([]),[a,o]=c.useState(null);if(c.useEffect(()=>{t&&i(Xr())},[t]),!t)return null;const l=m=>{navigator.clipboard.writeText(m.content),o(m.id),setTimeout(()=>o(null),1500)},u=m=>{const p=n.filter(h=>h.id!==m);localStorage.setItem(Tt,JSON.stringify(p)),i(p)},x=()=>{po(),i([])};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",onClick:s,children:e.jsxs("div",{className:"w-full max-w-lg max-h-[80vh] flex flex-col rounded-xl border border-border bg-card shadow-2xl animate-slide-up mx-4",onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"w-4 h-4 text-primary"}),e.jsx("h2",{className:"text-base font-bold text-foreground",children:"Post History"}),e.jsx("span",{className:"text-[10px] bg-secondary text-muted-foreground rounded-full px-2 py-0.5",children:n.length})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[n.length>0&&e.jsxs(g,{variant:"ghost",size:"sm",onClick:x,className:"text-xs text-destructive hover:text-destructive h-7 gap-1",children:[e.jsx(us,{className:"w-3 h-3"})," Clear"]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:s,className:"w-7 h-7",children:e.jsx(te,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:n.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(ms,{className:"w-8 h-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No posts yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Generated and copied posts will appear here."})]}):n.map(m=>e.jsxs("div",{className:"group rounded-lg border border-border/60 bg-secondary/20 p-3 hover:border-primary/30 transition-colors",children:[e.jsxs("p",{className:"text-sm text-foreground line-clamp-3 leading-relaxed mb-2",children:[m.preview,m.content.length>120?"…":""]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:fo(m.createdAt)}),e.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 text-[11px] gap-1 text-primary",onClick:()=>{r(m.content),s()},children:"Restore"}),e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>l(m),children:a===m.id?e.jsx(Z,{className:"w-3 h-3 text-success"}):e.jsx(Me,{className:"w-3 h-3"})}),e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>u(m.id),children:e.jsx(us,{className:"w-3 h-3"})})]})]})]},m.id))})]})})}const bo=9e4;
86class yo extends Error{constructor(r){super(`Fix timed out after ${Math.round(r/1e3)}s`);Ze(this,"code","timeout");this.name="ComposerFixTimeoutError"}}function jo(t){const s=t,r=typeof(s==null?void 0:s.code)=="string"?s.code:"",n=typeof(s==null?void 0:s.name)=="string"?s.name:"",i=typeof(s==null?void 0:s.message)=="string"?s.message.toLowerCase():"";return r==="timeout"||n==="ComposerFixTimeoutError"||n==="TimeoutError"?"timeout":r==="aborted"||n==="AbortError"||i.includes("aborted")?"aborted":r==="malformed_response"||i.includes("failed to parse")?"malformed_response":r==="empty_result"?"empty_result":n==="FunctionsHttpError"||typeof(s==null?void 0:s.status)=="number"||i.includes("non-2xx")||i.includes("rate limit")||i.includes("credits")?"server_error":n==="FunctionsFetchError"||n==="TypeError"||i.includes("failed to fetch")||i.includes("network")?"network_error":"unknown"}function as(t){switch(t){case"timeout":return"That took too long. Nothing was changed — try again.";case"aborted":return"That fix was cancelled. Your draft is unchanged.";case"malformed_response":case"empty_result":return"The revision came back unusable. Your draft is unchanged — try again.";case"server_error":return"The revision service is busy right now. Your draft is unchanged — try again.";case"network_error":return"Connection problem. Your draft is unchanged — try again.";default:return"Something went wrong. Your draft is unchanged — try again."}}async function fr(t){const s=t.timeoutMs??bo,r=Date.now(),n=new AbortController;let i=!1;const a=x=>{i||(i=!0,x())};let o=!1,l;const u=new Promise((x,m)=>{l=setTimeout(()=>{o=!0;try{n.abort()}catch{}m(new yo(s))},s)});try{const x=await Promise.race([t.run(n.signal),u]);if(o||n.signal.aborted){a(()=>t.onFailed("timeout",Date.now()-r,as("timeout")));return}if(!(t.isUsable?t.isUsable(x):x!=null)){a(()=>t.onFailed("empty_result",Date.now()-r,as("empty_result")));return}a(()=>t.onCompleted(x,Date.now()-r))}catch(x){const m=jo(x);a(()=>t.onFailed(m,Date.now()-r,as(m)))}finally{l&&clearTimeout(l)}}const vo=t=>Array.from(t).map(s=>{const r=s.codePointAt(0),n=[[119808,119833,65,!1],[119834,119859,97,!1],[119860,119885,65,!1],[119886,119911,97,!1],[120224,120249,65,!1],[120250,120275,97,!1],[120276,120301,65,!1],[120302,120327,97,!1],[120432,120457,65,!1],[120458,120483,97,!1],[120782,120791,48,!0],[120802,120811,48,!0]];for(const[i,a,o]of n)if(r>=i&&r<=a)return String.fromCharCode(o+(r-i));return s}).join(""),No=/[\u0332\u0333\u0336\u0335\u0347\u0338]/gu,wo=/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu,gr=new RegExp("(\\p{Extended_Pictographic}|\\p{Emoji_Presentation})","gu");function br(t){const s=vo(t??"").normalize("NFKC").replace(/[\u2018\u2019\u02bc]/g,"'").replace(/[\u201c\u201d]/g,'"').replace(/[\u2013\u2014\u2212]/g,"-").replace(/\u00a0/g," ").replace(No,""),r=[];for(const n of s.split(/\s+/)){const i=n.match(gr)??[],a=n.replace(gr,"").replace(/[*_`~#>\u200b-\u200d\ufe0e\ufe0f\ufeff]/g,"").replace(wo,"").toLowerCase();a.length>0&&r.push(a);for(const o of i)r.push(o)}return r}function ko(t,s){const r=t.length,n=s.length,i=Array.from({length:r+1},()=>new Array(n+1).fill(0));for(let x=r-1;x>=0;x--)for(let m=n-1;m>=0;m--)i[x][m]=t[x]===s[m]?i[x+1][m+1]+1:Math.max(i[x+1][m],i[x][m+1]);const a=[],o=[];let l=0,u=0;for(;l<r&&u<n;)t[l]===s[u]?(l++,u++):i[l+1][u]>=i[l][u+1]?o.push(t[l++]):a.push(s[u++]);for(;l<r;)o.push(t[l++]);for(;u<n;)a.push(s[u++]);return{added:a,removed:o}}function yr(t,s){const r=br(t),n=br(s),{added:i,removed:a}=ko(r,n),o=Math.max(a.length,i.length),l=o===0;return{preserved:l,changedWords:o,addedWords:i,removedWords:a,originalWordCount:r.length,formattedWordCount:n.length,summary:l?"0 words changed — your words stay yours.":`${o} word${o===1?"":"s"} changed — wording was altered, not just formatting.`}}const So=[['"','"'],["'","'"],["“","”"],["‘","’"]];function _o(t){let s=(t??"").trim();for(let r=0;r<3&&So.find(([i,a])=>s.length>1&&s.startsWith(i)&&s.endsWith(a));r++)s=s.slice(1,-1).trim();return s}function Co(t){const s=t??"",r=s.split(`
87`),n=r.findIndex(u=>u.trim().length>0);if(n===-1)return{leading:"",hook:"",rest:s};const i=r.slice(0,n).join(`
88`)+(n>0?`
89`:""),a=r[n],o=r.slice(n+1),l=o.length?`
90`+o.join(`
91`):"";return{leading:i,hook:a,rest:l}}function Ao(t,s){const r=_o(s);if(!r)return t??"";const{leading:n,hook:i,rest:a}=Co(t??"");return i.trim()===r?t??"":n+r+a}function Io({context:t,hasDraft:s,onApplyFindings:r,isApplying:n,appliedFindings:i,onRecheck:a,onStartDraft:o,onDismiss:l}
91){const[u,x]=c.useState(!1),m=t.findings.length,p=i??null;return e.jsxs("div",{"data-testid":"diagnosis-context-strip",className:"mb-4 rounded-xl border border-primary/25 bg-primary/5 p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-xs font-bold text-primary",children:[e.jsx(Z,{className:"w-3.5 h-3.5"}),"Signal Audit connected ✓"]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:[m," ",m===1?"finding":"findings"," available for this draft",t.diagnosisInput?` · ${t.diagnosisInput}`:""]})]}),e.jsx("button",{onClick:l,"aria-label":"Dismiss Signal Audit context",className:"shrink-0 text-muted-foreground hover:text-foreground p-1",children:e.jsx(te,{className:"w-4 h-4"})})]}),p&&p.length>0?e.jsxs("div",{className:"mt-3 rounded-lg border border-success/30 bg-success/5 p-3",children:[e.jsxs("p",{className:"text-xs font-semibold text-success",children:[p.length," Signal Audit ",p.length===1?"finding":"findings"," applied"]}),e.jsx("ul",{className:"mt-1 space-y-0.5",children:p.map((h,j)=>e.jsxs("li",{className:"text-[11px] text-muted-foreground",children:["· ",h.label]},j))}),a&&e.jsxs(g,{size:"sm",onClick:a,className:"mt-3 w-full min-h-[44px] sm:min-h-0 gap-1.5 gradient-primary text-primary-foreground font-semibold",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),"Recheck draft"]})]}):e.jsxs("div",{className:"mt-3 space-y-2",children:[s?e.jsxs(g,{size:"sm",onClick:r,disabled:n||m===0,className:"w-full min-h-[44px] sm:min-h-0 gap-1.5 gradient-primary text-primary-foreground font-semibold",children:[n?e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(q,{className:"w-3.5 h-3.5"}),n?"Applying…":"Apply these findings to my draft"]}):e.jsxs(g,{size:"sm",variant:"outline",onClick:o,className:"w-full min-h-[44px] sm:min-h-0 gap-1.5",children:[e.jsx(St,{className:"w-3.5 h-3.5"}),"Paste a draft I already have"]}),e.jsx("button",{onClick:()=>x(h=>!h),className:"text-[11px] font-semibold text-primary hover:underline underline-offset-2",children:u?"Hide findings":"View findings"})]}),u&&m>0&&e.jsx("ul",{className:"mt-2 space-y-1.5",children:t.findings.map((h,j)=>e.jsxs("li",{className:"rounded-lg bg-card px-3 py-2 text-[11px] text-foreground",children:[e.jsx("span",{className:"font-semibold",children:h.label}),h.detail&&h.detail!==h.label&&e.jsx("span",{className:"block text-muted-foreground mt-0.5",children:h.detail})]},j))})]})}function Eo({context:t,isGenerating:s,onGenerate:r,onWriteMyself:n,initialAsset:i=null,retry:a=!1}){var p;const o=c.useRef(va(t.findings,t.diagnosisInput)).current,[l,u]=c.useState(i??o.key),x=c.useRef(!1);c.useEffect(()=>{x.current||(x.current=!0,N(w.COMPOSER_ASSET_CHOOSER_SHOWN,{recommended_asset:o.key,inferred:o.inferred,finding_count:t.findings.length,source:t.origin}))},[o,t.findings.length,t.origin]);const m=h=>{u(h),N(w.COMPOSER_ASSET_SELECTED,{asset:h,recommended_asset:o.key,accepted_recommendation:h===o.key,inferred:o.inferred})};return e.jsxs("div",{"data-testid":"diagnosis-asset-chooser",className:"mt-3 rounded-xl border border-border bg-card p-3",children:[e.jsx("p",{className:"text-xs font-bold text-foreground",children:a?"We couldn't write that draft automatically":"What do you want to fix first?"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:a?"Your findings are still here. Confirm the asset and try again.":o.inferred?`Suggested from your findings: ${o.basis}`:"Pick the asset you want to work on."}),e.jsx("div",{role:"radiogroup","aria-label":"Asset to fix",className:"mt-2.5 flex flex-wrap gap-1.5",children:xs.map(h=>{const j=l===h.key;return e.jsxs("button",{role:"radio","aria-checked":j,onClick:()=>m(h.key),disabled:s,title:h.hint,className:`min-h-[44px] sm:min-h-0 rounded-full border px-3 py-2 text-[11px] font-semibold transition-colors disabled:opacity-60 ${j?"border-primary bg-primary/10 text-primary":"border-border bg-secondary/40 text-foreground hover:border-primary/40"}`,children:[h.label,o.inferred&&h.key===o.key&&e.jsx("span",{className:"ml-1 text-[10px] font-normal opacity-70",children:"· suggested"})]},h.key)})}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:(p=xs.find(h=>h.key===l))==null?void 0:p.hint}),e.jsxs("div",{className:"mt-3 space-y-1.5",children:[e.jsxs(g,{size:"sm","data-testid":"diagnosis-asset-generate",onClick:()=>r(l),disabled:s,className:"w-full min-h-[44px] sm:min-h-0 gap-1.5 gradient-primary text-primary-foreground font-semibold",children:[s?e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(q,{className:"w-3.5 h-3.5"}),s?"Writing your first draft…":a?"Retry writing my draft":"Write my first draft from these findings"]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:()=>n(l),disabled:s,className:"w-full min-h-[44px] sm:min-h-0 gap-1.5 text-muted-foreground",children:[e.jsx(St,{className:"w-3.5 h-3.5"}),"I'll write it myself"]}
91)]})]})}function Po({proof:t,journey:s,assetKey:r,scopeLine:n}){const i=c.useRef(null),a=`${t.before}:${t.after}`;c.useEffect(()=>{i.current!==a&&(i.current=a,N(w.PROOF_VIEWED,{comparable:!0,old_score:t.before,new_score:t.after,delta:t.delta,changed_dimension_count:t.changed.length,asset:r??null,journey:s}))},[a,t,r,s]);const o=t.delta>0,l=t.delta===0;return e.jsxs("div",{"data-testid":"before-after-proof",className:`rounded-2xl border p-4 ${o?"border-success/40 bg-success/5":l?"border-border bg-card":"border-warning/40 bg-warning/5"}`,children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Before → after this fix"}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("span",{className:"font-mono text-xl font-bold text-muted-foreground line-through decoration-1",children:t.before}),e.jsx(He,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs("span",{className:"font-mono text-3xl font-bold leading-none text-foreground",children:[t.after,e.jsx("span",{className:"text-sm font-semibold text-muted-foreground",children:" / 100"})]}),e.jsxs("span",{"data-testid":"proof-delta",className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-bold ${o?"bg-success/15 text-success":l?"bg-secondary text-muted-foreground":"bg-warning/15 text-warning"}`,children:[o?e.jsx(ze,{className:"w-3 h-3"}):l?null:e.jsx(vs,{className:"w-3 h-3"}),l?"No change":o?`+${t.delta}`:`−${Math.abs(t.delta)}`]})]}),t.changed.length>0&&e.jsx("ul",{className:"mt-3 space-y-1",children:t.changed.map(u=>e.jsxs("li",{className:"flex items-center justify-between gap-2 text-[11px]",children:[e.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:u.label}),e.jsxs("span",{className:"shrink-0 font-mono text-foreground",children:[u.before," → ",u.after," ",e.jsxs("span",{className:u.delta>0?"text-success":"text-warning",children:["(",u.delta>0?`+${u.delta}`:u.delta,")"]})]})]},u.key))}),e.jsxs("p",{className:"mt-2.5 text-[10px] text-muted-foreground",children:["Measured change in the scored dimensions between your previous and current review of this same draft. ",n]})]})}function To(t,s){return!t||!t.text.trim()?!1:t.text===s}function Mo(t="linkedin"){return t==="linkedin"?"Copy + publish →":`Copy + publish to ${At(t)} →`}function Ro(t){return t.completed&&!t.entitled}const Oo="Keep this voice consistent — brand memory with Pro",is="sb_composer_completion_surface",Lo=2*60*60*1e3;function Fo(t,s){let r=0;for(let n=0;n<s.length;n++)r=r*31+s.charCodeAt(n)|0;return`${t}:${s.length}:${r}`}function Do(t){try{const s=sessionStorage.getItem(is),r=s?JSON.parse(s):{},n=Date.now(),i=Object.fromEntries(Object.entries(r).filter(([,a])=>Number.isFinite(a)&&n-a<=Lo));return i[t]?(sessionStorage.setItem(is,JSON.stringify(i)),!1):(i[t]=n,sessionStorage.setItem(is,JSON.stringify(i)),!0)}catch{return!0}}function $o(t){return{completion_source:t.source,platform:t.platform,value_action_shown:t.valueActionShown}}function zo(t){const{previous:s,current:r,lineageIntact:n}=t;if(!s)return{comparable:!1,reason:"no_previous_review"};if(!r)return{comparable:!1,reason:"no_current_review"};if(!n)return{comparable:!1,reason:"lineage_broken"};if(s.profileId!==r.profileId)return{comparable:!1,reason:"profile_changed"};if((s.assetKey??null)!==(r.assetKey??null))return{comparable:!1,reason:"asset_changed"};if(s.mode!==r.mode)return{comparable:!1,reason:"scale_changed"};const i=xr(s.dimensions,s.mode),a=xr(r.dimensions,r.mode),o=hs(s.dimensions,s.mode),l=hs(r.dimensions,r.mode),u=new Map(l.map(m=>[m.key,m])),x=[];for(const m of o){const p=u.get(m.key);if(!p)continue;const h=p.value-m.value;h!==0&&x.push({key:m.key,label:m.label,before:m.value,after:p.value,delta:h})}return x.sort((m,p)=>Math.abs(p.delta)-Math.abs(m.delta)),{comparable:!0,before:i,after:a,delta:a-i,changed:x.slice(0,Math.max(0,t.maxDimensions??3))}}const Jr="sb_proof_offer_dismissed:";function Ho(t){return!t||t.type!=="diagnosis"?null:String(t.diagnosisId||t.diagnosisInput||t.savedAt||"diagnosis")}function Uo(t){if(!t)return!1;try{return sessionStorage.getItem(Jr+t)==="1"}catch{return!1}}function Bo(t){if(t)try{sessionStorage.setItem(Jr+t,"1")}catch{}}function Wo(t){var s;return!(((s=t.workContext)==null?void 0:s.type)!=="diagnosis"||typeof t.proofDelta!="number"||t.proofDelta<=0||t.entitled||t.dismissed)}class Go{constructor(){Ze(this,"nextId",0);Ze(this,"pending",null);Ze(this,"lastCompletedId",null)}markValueAction(s,r,n,i){this.nextId+=1,this.pending={id:this.nextId,source:s,content:r,profileId:n,formatPreserved:i}}invalidate(s){this.pending&&(!s||s(this.pending))&&(this.pending=null)}reset(){this.pending=null,this.lastCompletedId=null}peek(){return this.pending}resolveCopy(s,r){const n=this.pending;return n?n.content!==s||n.profileId!==r?(this.pending=null,null):n.id===this.lastCompletedId?null:(this.lastCompletedId=n.id,{source:n.source,...typeof n.formatPreserved=="boolean"?{format_preserved:n.formatPreserved}:{}}):null}}function Yo(t){return t.hasAnalysis?t.content!==t.analyzedContent||t.profileId!==t.analyzedProfileId:!1}const De="Recheck this draft before applying earlier suggestions.";function Vr(t=10){try{navigator.vibrate&&navigator.vibrate(t)}
91catch{}}const Ko=()=>Vr(8),wt=()=>Vr([10,50,10]),qr="sb_email_captured",Zr="sb_email_dismissed";function Xo(t){return localStorage.getItem(qr)||localStorage.getItem(Zr)?!1:t>=1}function Jo({onClose:t}){const[s,r]=c.useState(""),[n,i]=c.useState(!1),[a,o]=c.useState(!1),[l,u]=c.useState(""),x=async p=>{if(p.preventDefault(),!s.trim()||!s.includes("@")){u("Please enter a valid email.");return}i(!0),u("");try{const{error:h}=await W.from("email_captures").insert([{email:s.trim().toLowerCase(),device_id:kt()}]);if(h)throw h;localStorage.setItem(qr,s.trim()),o(!0),setTimeout(t,1500)}catch{u("Something went wrong. Try again.")}finally{i(!1)}},m=()=>{localStorage.setItem(Zr,"true"),t()};return e.jsx("div",{className:"fixed inset-0 z-[70] flex items-end sm:items-center justify-center bg-background/80 backdrop-blur-sm",onClick:m,children:e.jsxs("div",{className:"w-full max-w-sm mx-4 mb-4 sm:mb-0 rounded-2xl border border-border bg-card p-5 shadow-2xl animate-slide-up",onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg gradient-primary flex items-center justify-center",children:e.jsx(q,{className:"w-4 h-4 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-foreground",children:"Save your progress"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Get tips & never lose your posts"})]})]}),e.jsx("button",{onClick:m,className:"text-muted-foreground hover:text-foreground",children:e.jsx(te,{className:"w-4 h-4"})})]}),a?e.jsxs("div",{className:"text-center py-3",children:[e.jsx("p",{className:"text-sm font-semibold text-success",children:"✅ You're in!"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"We'll send you tips to level up your posts."})]}):e.jsxs("form",{onSubmit:x,className:"space-y-2.5",children:[e.jsx(pe,{type:"email",value:s,onChange:p=>r(p.target.value),placeholder:"[email protected]",className:"h-9 text-sm",autoFocus:!0}),l&&e.jsx("p",{className:"text-xs text-destructive",children:l}),e.jsxs(g,{type:"submit",disabled:n,className:"w-full gradient-primary text-primary-foreground font-semibold gap-1.5 h-9",children:[n?e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(kr,{className:"w-3.5 h-3.5"}),n?"Saving…":"Keep me posted"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center",children:"We only email you about your own results and product updates."})]})]})})}const Vo=[{key:"li_posts_created",label:"Posts created",icon:q},{key:"sb_copies",label:"Posts copied",icon:Me},{key:"sb_formats",label:"Format Only uses",icon:Ns},{key:"sb_translates",label:"Translations",icon:Rr},{key:"sb_refines",label:"Chat refinements",icon:ve},{key:"sb_analyzes",label:"Analyses run",icon:Pe}];function Qr(t){return parseInt(localStorage.getItem(t)||"0")}function os(t){const s=Qr(t);localStorage.setItem(t,String(s+1))}function qo(){const t=Vo.map(r=>({...r,value:Qr(r.key)}));return t.reduce((r,n)=>r+n.value,0)===0?null:e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 animate-slide-up",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(qn,{
91className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Your Stats"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.filter(r=>r.value>0).map(r=>{const n=r.icon;return e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-secondary/40 px-3 py-2",children:[e.jsx(n,{className:"w-3.5 h-3.5 text-primary shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-foreground leading-none",children:r.value}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:r.label})]})]},r.key)})})]})}function Zo({profiles:t,activeId:s,canAdd:r,onSwitch:n,onAdd:i,onEdit:a}){return t.length===0?null:e.jsxs("div",{className:"flex items-center gap-1.5 overflow-x-auto scrollbar-hide",children:[t.map(o=>{const l=o.id===s;return e.jsxs("button",{onClick:()=>l?a(o.id):n(o.id),className:`flex items-center gap-1.5 rounded-full px-2.5 py-1 sm:px-3 sm:py-1.5 text-xs font-medium transition-all whitespace-nowrap border ${l?"bg-primary/10 border-primary/30 text-primary ring-1 ring-primary/20 shadow-sm":"bg-secondary/60 border-border text-muted-foreground hover:bg-secondary hover:border-primary/20"}`,title:l?`Edit "${o.name}"`:`Switch to "${o.name}"`,children:[e.jsx("span",{className:"text-sm",children:o.emoji}),e.jsx("span",{className:"hidden sm:inline max-w-[80px] truncate",children:o.name})]},o.id)}),r&&e.jsxs("button",{onClick:i,className:"flex items-center gap-1 rounded-full px-2 py-1 sm:px-2.5 sm:py-1.5 text-xs text-muted-foreground border border-dashed border-border hover:border-primary/40 hover:text-primary transition-colors",title:"Add profile",children:[e.jsx(Er,{className:"w-3 h-3"}),e.jsx("span",{className:"hidden sm:inline",children:"Add"})]})]})}const Qo=["🧑","🏢","🚀","💼","🎯","🔬","📚","🎨","💡","⚡","🌟","✨"],el=["#3b82f6","#8b5cf6","#ec4899","#f97316","#10b981","#06b6d4","#6366f1","#f43f5e"],$e=["intro","identity","audie
91nce","voice","review"];function tl({onComplete:t,onClose:s,saving:r}){var M,V,C,D,Q,Y,re,ne,ce,we;const[n,i]=c.useState("intro"),[a,o]=c.useState({name:"",emoji:"✨",color:"#8b5cf6",goal:"",audience_preset:"general",language:"English",voice_samples:[],recurring_themes:[],banned_phrases:[],cta_style:""}),[l,u]=c.useState(""),[x,m]=c.useState(""),[p,h]=c.useState(""),[j,k]=c.useState(""),E=$e.indexOf(n),S=(E+1)/$e.length*100,v=y=>o(O=>({...O,...y})),L=()=>i($e[Math.min(E+1,$e.length-1)]),G=()=>i($e[Math.max(E-1,0)]),B=3,H=20,A=500,F=()=>{const y=l.trim(),O=a.voice_samples||[];if(O.length>=B){m(`You can add up to ${B} samples here. You can add more later in Brand.`);return}if(y.length<H){m(`That's a little short — paste at least ${H} characters you actually wrote.`);return}if(y.length>A){m(`That's a bit long — keep each sample under ${A} characters.`);return}if(O.includes(y)){m("You already added that sample.");return}v({voice_samples:[...O,y]}),u(""),m("")},f=()=>{var O;const y=p.trim();!y||(O=a.recurring_themes)!=null&&O.includes(y)||(v({recurring_themes:[...a.recurring_themes||[],y]}),h(""))},_=()=>{var O;const y=j.trim();!y||(O=a.banned_phrases)!=null&&O.includes(y)||(v({banned_phrases:[...a.banned_phrases||[],y]}),k(""))},R=async()=>{var O;if(!((O=a.name)!=null&&O.trim())){ye.error("Give your profile a name");return}await t(a)?(ye.success("Brand context saved"),s()):ye.error("Failed to create profile")};return e.jsx("div",{className:"fixed inset-0 z-[70] flex items-center justify-center bg-background/85 backdrop-blur-md",onClick:s,children:e.jsxs("div",{className:"w-full max-w-md max-h-[90vh] overflow-y-auto rounded-2xl border border-border bg-card shadow-2xl mx-4 animate-slide-up",onClick:y=>y.stopPropagation(),children:[e.jsxs("div",{className:"px-5 pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-xs font-semibold text-primary uppercase tracking-wide",children:"Brand Setup"})]}),e.jsx("button",{onClick:s,className:"text-muted-foreground hover:text-foreground",children:e.jsx(te,{className:"w-4 h-4"})})]}),e.jsx(Ea,{value:S,className:"h-1.5"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1",children:["Step ",E+1," of ",$e.length]})]}),e.jsxs("div",{className:"p-5",children:[n==="intro"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"text-5xl",children:"🎯"}),e.jsx("h2",{className:"text-xl font-bold text-foreground",children:"Give SocialBrilliance context it can remember"}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:"Add a few facts about your brand, audience, and writing style so Composer and Brand don't start from zero each time."}),e.jsxs(g,{onClick:L,className:"w-full gap-2 font-semibold",children:["Let's go ",e.jsx(He,{className:"w-4 h-4"})]}),e.jsx("button",{onClick:s,className:"text-xs text-muted-foreground hover:text-foreground",children:"Skip — I'll set it up later"})]}),n==="identity"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-foreground mb-1",children:"Who are you?"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Give this profile a name and pick an icon."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Profile Name"}),e.jsx(pe,{value:a.name,onChange:y=>v({name:y.target.value}),placeholder:"e.g. Personal Brand, Acme Corp",className:"mt-1 text-sm h-9",maxLength:30,autoFocus:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Icon"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:Qo.map(y=>e.jsx("button",{onClick:()=>v({emoji:y}),className:`w-8 h-8 rounded-lg text-base flex items-center justify-center border transition-all ${a.emoji===y?"border-primary bg-primary/10 ring-1 ring-primary/20 scale-110":"border-border bg-secondary/30 hover:border-primary/40"}`,children:y},y))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Accent Color"}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-1.5",children:el.map(y=>e.jsx("button",{onClick:()=>v({color:y}),className:`w-7 h-7 rounded-full border-2 transition-all ${a.color===y?"border-foreground scale-110 ring-2 ring-primary/30":"border-transparent hover:scale-105"}`,style:{backgroundColor:y}},y))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Goal / Mission"}
91),e.jsx(pe,{value:a.goal,onChange:y=>v({goal:y.target.value}),placeholder:"e.g. Build thought leadership in AI healthcare",className:"mt-1 text-sm h-9",maxLength:120})]})]}),n==="audience"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-foreground mb-1",children:"Who do you write for?"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pick the audience that best matches your content."})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ds.map(y=>e.jsxs("button",{onClick:()=>v({audience_preset:y.id}),className:`text-left rounded-xl border p-3 transition-all text-xs ${a.audience_preset===y.id?"border-primary bg-primary/5 ring-1 ring-primary/20":"border-border bg-secondary/30 hover:border-primary/40"}`,children:[e.jsx("div",{className:"text-lg mb-1",children:y.emoji}),e.jsx("div",{className:"font-medium text-foreground",children:y.label})]},y.id))}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Topics you post about"}),e.jsxs("div",{className:"flex gap-2 mt-1.5",children:[e.jsx(pe,{value:p,onChange:y=>h(y.target.value),onKeyDown:y=>y.key==="Enter"&&(y.preventDefault(),f()),placeholder:"e.g. AI, Leadership, Remote work",className:"text-sm h-8"}),e.jsx(g,{variant:"outline",size:"sm",onClick:f,className:"h-8 px-3 text-xs",children:"Add"})]}),(((M=a.recurring_themes)==null?void 0:M.length)??0)>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:a.recurring_themes.map((y,O)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded-full bg-secondary text-secondary-foreground border border-border",children:[y,e.jsx("button",{onClick:()=>v({recurring_themes:a.recurring_themes.filter((ke,ie)=>ie!==O)}),className:"hover:text-destructive",children:e.jsx(te,{className:"w-3 h-3"})})]},O))})]})]}),n==="voice"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-foreground mb-1",children:"Help SocialBrilliance learn your voice"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional, but powerful. Paste 1–3 short examples you actually wrote. We use these as reference — we won't invent a voice sample for you."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Writing sample (something you wrote)"}),e.jsx(st,{value:l,onChange:y=>{u(y.target.value),m("")},placeholder:"Paste a sentence or short excerpt…",className:"mt-1.5 text-sm min-h-[80px]",maxLength:A}),e.jsxs("div",{className:"flex items-center justify-between mt-1.5 gap-2",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[((V=a.voice_samples)==null?void 0:V.length)??0,"/",B," samples added"]}),e.jsx(g,{variant:"outline",size:"sm",onClick:F,disabled:!l.trim()||(((C=a.voice_samples)==null?void 0:C.length)??0)>=B,className:"h-8 px-3 text-xs",children:"Add sample"})]}),x&&e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:x})]}),(((D=a.voice_samples)==null?void 0:D.length)??0)>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Your writing samples"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Reference examples you provided — not generated analysis."}),a.voice_samples.map((y,O)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs bg-secondary/40 rounded-lg p-2 border border-border",children:[e.jsxs("span",{className:"flex-1 text-foreground leading-relaxed",children:['"',y.length>120?`${y.slice(0,120)}…`:y,'"']}),e.jsx("button",{onClick:()=>v({voice_samples:a.voice_samples.filter((ke,ie)=>ie!==O)}),className:"text-muted-foreground hover:text-destructive mt-0.5","aria-label":"Remove writing sample",children:e.jsx(te,{className:"w-3 h-3"})})]},O))]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Words to avoid"}),e.jsxs("div",{className:"flex gap-2 mt-1.5",children:[e.jsx(pe,{value:j,onChange:y=>k(y.target.value),onKeyDown:y=>y.key==="Enter"&&(y.preventDefault(),_()),placeholder:"e.g. synergy, disrupt, leverage",className:"text-sm h-8"}),e.jsx(g,{variant:"outline",size:"sm",onClick:_,className:"h-8 px-3 text-xs",children:"Add"})]}),(((Q=a.banned_phrases)==null?void 0:Q.length)??0)>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:a.banned_phrases.map((y,O)=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive border border-destructive/20",children:[y,e.jsx("button",{onClick:()=>v({banned_phrases:a.banned_phrases.filter((ke,ie)=>ie!==O)}),children:e.jsx(te,{className:"w-3 h-3"})})]},O))})]})]}),n==="review"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-foreground mb-1",children:"Looking great! 🎉"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Here's your brand profile. You can always edit it later."})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-secondary/20 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-xl",style:{backgroundColor:a.color+"20",border:`2px solid ${a.color}`}
91,children:a.emoji}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-foreground",children:a.name||"Unnamed"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a.goal||"No goal set"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs("div",{className:"bg-background rounded-lg p-2 border border-border",children:[e.jsx("div",{className:"text-muted-foreground mb-0.5",children:"Audience"}),e.jsx("div",{className:"font-medium text-foreground",children:((Y=ds.find(y=>y.id===a.audience_preset))==null?void 0:Y.label)||"General"})]}),e.jsxs("div",{className:"bg-background rounded-lg p-2 border border-border",children:[e.jsx("div",{className:"text-muted-foreground mb-0.5",children:"Writing samples"}),e.jsxs("div",{className:"font-medium text-foreground",children:[((re=a.voice_samples)==null?void 0:re.length)||0," you added"]})]}),e.jsxs("div",{className:"bg-background rounded-lg p-2 border border-border",children:[e.jsx("div",{className:"text-muted-foreground mb-0.5",children:"Themes"}),e.jsxs("div",{className:"font-medium text-foreground",children:[((ne=a.recurring_themes)==null?void 0:ne.length)||0," topics"]})]}),e.jsxs("div",{className:"bg-background rounded-lg p-2 border border-border",children:[e.jsx("div",{className:"text-muted-foreground mb-0.5",children:"Phrases to avoid"}),e.jsxs("div",{className:"font-medium text-foreground",children:[((ce=a.banned_phrases)==null?void 0:ce.length)||0," words"]})]})]})]})]}),n!=="intro"&&e.jsxs("div",{className:"flex gap-2 mt-5 pt-4 border-t border-border",children:[e.jsxs(g,{variant:"ghost",size:"sm",onClick:G,className:"gap-1.5",children:[e.jsx(Pr,{className:"w-3.5 h-3.5"})," Back"]}),e.jsx("div",{className:"flex-1"}),n==="review"?e.jsxs(g,{size:"sm",onClick:R,disabled:r||!((we=a.name)!=null&&we.trim()),className:"gap-1.5 font-semibold",children:[r?e.jsx(ae,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Z,{className:"w-3.5 h-3.5"}),"Create Profile"]}):e.jsxs(g,{size:"sm",onClick:L,className:"gap-1.5 font-semibold",children:["Continue ",e.jsx(He,{className:"w-3.5 h-3.5"})]})]})]})]})})}const ls={linkedin:{emoji:"💼",color:"text-[hsl(210,100%,45%)]"},x:{emoji:"𝕏",color:"text-foreground"},facebook:{emoji:"📘",color:"text-[hsl(220,70%,50%)]"},instagram:{emoji:"📸",color:"text-[hsl(330,70%,55%)]"}},sl=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];function rl({onClose:t,onUsePost:s}){var H;const[r,n]=c.useState("text"),[i,a]=c.useState(""),[o,l]=c.useState(""),[u,x]=c.useState(!1),[m,p]=c.useState([]),[h,j]=c.useState(0),[k,E]=c.useState(null),{settings:S}=xe(),{toast:v}=je(),L=async()=>{const A=r==="url"?`Please repurpose content from this URL: ${i.trim()}`:o.trim();if(!A){v({variant:"destructive",title:"Nothing to repurpose",description:"Paste your source content first."});return}x(!0);try{const{data:F,error:f}=await W.functions.invoke("linkedin-ai",{body:{action:"repurpose",content:A,settings:S}});if(f)throw f;const _=JSON.parse(F.result);p(_),j(0)}catch(F){v({variant:"destructive",title:"Repurpose failed",description:F.message})}finally{x(!1)}},G=A=>{navigator.clipboard.writeText(m[A].content),wt(),E(A),setTimeout(()=>E(null),2e3)},B=A=>{s(A),t()};return e.jsx("div",{className:"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl shadow-2xl w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_t,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-foreground",children:"Repurpose Engine"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"One source → 7 days of content across platforms"})]})]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:t,children:e.jsx(te,{className:"w-4 h-4"})})]}),m.length===0?e.jsxs("div",{className:"p-5 space-y-4 flex-1 overflow-y-auto",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{disabled:!0,title:"URL import coming soon",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border bg-secondary/30 border-border text-muted-foreground
91/60 cursor-not-allowed",children:[e.jsx(Pa,{className:"w-3.5 h-3.5"})," URL import coming soon"]}),e.jsxs("button",{onClick:()=>n("text"),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium transition-all border ${r==="text"?"bg-primary/10 border-primary/30 text-primary":"bg-secondary/50 border-border text-muted-foreground hover:border-primary/20"}`,children:[e.jsx(js,{className:"w-3.5 h-3.5"})," Paste content"]})]}),r==="url"?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Blog / Article / YouTube URL"}),e.jsx(pe,{value:i,onChange:A=>a(A.target.value),placeholder:"https://yourblog.com/article-title",className:"mt-1.5 text-sm"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"URL import is not available yet — paste the content instead."})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Source Content"}),e.jsx(st,{value:o,onChange:A=>l(A.target.value),placeholder:"Paste your blog post, newsletter, meeting notes, podcast transcript, or any raw content…",className:"mt-1.5 text-sm min-h-[180px]",maxLength:1e4}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1",children:[o.length.toLocaleString(),"/10,000 characters"]})]}),e.jsx(g,{onClick:L,disabled:u||(r==="url"?!i.trim():!o.trim()),className:"w-full gradient-primary text-primary-foreground font-semibold gap-2",children:u?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 animate-spin"}),"Generating 7-day calendar…"]}):e.jsxs(e.Fragment,{children:[e.jsx(_t,{className:"w-4 h-4"}),"Generate Content Calendar"]})})]}):e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 pb-2 border-b border-border/50 overflow-x-auto",children:e.jsx("div",{className:"flex gap-1.5 min-w-max",children:m.map((A,F)=>{const f=ls[A.platform]||ls.linkedin,_=F===h;return e.jsxs("button",{onClick:()=>j(F),className:`flex flex-col items-center gap-0.5 px-3 py-2 rounded-lg text-xs transition-all border min-w-[60px] ${_?"bg-primary/10 border-primary/30 ring-1 ring-primary/20":"bg-secondary/30 border-border hover:bg-secondary/60"}`,children:[e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:sl[F]||`D${F+1}`}),e.jsx("span",{className:"text-base",children:f.emoji}),e.jsx("span",{className:`text-[10px] font-medium capitalize ${_?"text-primary":"text-muted-foreground"}`,children:A.platform})]},F)})})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-5",children:m[h]&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:(H=ls[m[h].platform])==null?void 0:H.emoji}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground capitalize",children:m[h].platform}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:m[h].angle})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(g,{variant:"ghost",size:"icon",onClick:()=>j(Math.max(0,h-1)),disabled:h===0,className:"w-7 h-7",children:e.jsx(Zn,{className:"w-4 h-4"})}),e.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:[h+1,"/7"]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:()=>j(Math.min(m.length-1,h+1)),disabled:h>=m.length-1,className:"w-7 h-7",children:e.jsx(Qn,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"rounded-xl border border-border bg-secondary/20 p-4",children:e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap leading-relaxed",children:m[h].content})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(g,{size:"sm",onClick:()=>G(h),className:"flex-1 gap-1.5",variant:"outline",children:[k===h?e.jsx(Z,{className:"w-3.5 h-3.5"}):e.jsx(Me,{className:"w-3.5 h-3.5"}),k===h?"Copied!":"Copy"]}),e.jsx(g,{size:"sm",onClick:()=>B(m[h].content),className:"flex-1 gap-1.5 gradient-primary text-primary-foreground",children:"Use in Editor"})]})]})}),e.jsxs("div",{className:"px-5 py-3 border-t border-border/50 flex items-center justify-between",children:[e.jsx("button",{onClick:()=>p([]),className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"← Start Over"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Tip: Edit any post in the main editor after using it"})]})]})]})})}const jr={premium:{bg:"bg-accent/10",text:"text-accent",icon:ze},credible:{bg:"bg-success/10",text:"text-success",icon:ze},scattered:{bg:"bg-warning/10",text:"text-warning",icon:Ee},"too-broad":{bg:"bg-warning/10",text:"text-warning",icon:Ee},"too-salesy":{bg:"bg-destructive/10",text:"text-destructive",icon:Ee},invisible:{bg:"bg-muted",text:"text-muted-foreground",icon:vs},inconsistent:{bg:"bg-warning/10",text:"text-warning",icon:Ee}};function nl({onClose:t,onGenerateBrief:s}){const[r,n]=c.useState("url"),[i,a]=c.useState(""),[o,l]=c.useState(""),[u,x]=c.useState(""),[m,p]=c.useState(!1),[h,j]=c.useState(!1),[k,E]=c.useState(null),{settings:S}=xe(),{activeProfile:v}=Tr(),{toast:L}
91=je(),G=async()=>{if(r==="url"){if(!i.trim())return L({variant:"destructive",title:"Enter a name or URL",description:"Type your name or paste a LinkedIn URL."}),null;p(!0);try{const f=i.trim(),_=f.startsWith("http")||f.includes("linkedin.com"),{data:R,error:M}=await W.functions.invoke("scrape-profile",{body:_?{url:f}:{name:f}});if(M)throw M;if(!(R!=null&&R.success))throw new Error((R==null?void 0:R.error)||"Could not find profile info");return R.content}catch(f){return L({variant:"destructive",title:"Search failed",description:f.message+". Try pasting your content instead."}),null}finally{p(!1)}}else{if(r==="paste")return o.trim()?o:(L({variant:"destructive",title:"Nothing to audit",description:"Paste your headline, about, or recent posts."}),null);{if(!v)return L({variant:"destructive",title:"No brand profile",description:"Create a brand profile first in Settings."}),null;const f=[`Brand Name: ${v.name}`,v.goal?`Goal: ${v.goal}`:"",v.voice_samples.length?`Voice Samples:
92${v.voice_samples.map(_=>`- "${_}"`).join(`
93`)}`:"",v.recurring_themes.length?`Recurring Themes: ${v.recurring_themes.join(", ")}`:"",v.cta_style?`CTA Style: ${v.cta_style}`:"",v.banned_phrases.length?`Banned Phrases: ${v.banned_phrases.join(", ")}`:"",`Audience: ${v.audience_preset}`,`Language: ${v.language}`].filter(Boolean);return o.trim()&&f.push(`
94Additional context / recent posts:
95${o}`),f.join(`
96
97`)}}},B=async()=>{const f=await G();if(f){j(!0);try{const{data:_,error:R}=await W.functions.invoke("linkedin-ai",{body:{action:"perception_audit",content:f,settings:S}});if(R)throw R;const M=JSON.parse(_.result);E(M),u.trim()&&localStorage.setItem("sb_audit_email",u.trim())}catch(_){L({variant:"destructive",title:"Audit failed",description:_.message})}finally{j(!1)}}};c.useEffect(()=>{const f=localStorage.getItem("sb_audit_email");f&&x(f)},[]);const H=m||h,A=k?jr[k.perception_tag]||jr.scattered:null,F=[{id:"url",label:"Search Name",icon:bs,desc:"We'll find your public presence"},{id:"paste",label:"Paste Content",icon:js,desc:"Paste headline, about & posts"},{id:"profile",label:"Brand Profile",icon:We,desc:"Use your saved brand data"}];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-3",onClick:t,children:[e.jsx("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-card border border-border rounded-2xl shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto animate-in fade-in zoom-in-95 duration-200",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 bg-card/95 backdrop-blur-sm border-b border-border/50 px-5 py-4 flex items-center justify-between z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(vt,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold text-foreground text-base",children:"Perception Audit"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"How the world actually sees you"})]})]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:t,className:"text-muted-foreground",children:e.jsx(te,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"px-5 py-5 space-y-5",children:k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center gap-2 rounded-xl px-4 py-3 ${A==null?void 0:A.bg}`,children:[A&&e.jsx(A.icon,{className:`w-5 h-5 ${A.text}`}),e.jsxs("div",{children:[e.jsxs("p",{className:`text-sm font-bold ${A==null?void 0:A.text}`,children:["Your presence reads as: ",k.perception_tag.replace("-"," ")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:k.overall_perception})]})]}),e.jsxs("div",{className:"flex items-center gap-4 bg-secondary/30 rounded-xl px-4 py-3",children:[e.jsxs("div",{className:"relative w-14 h-14",children:[e.jsxs("svg",{viewBox:"0 0 36 36",className:"w-14 h-14 -rotate-90",children:[e.jsx("circle",{cx:"18",cy:"18",r:"15.5",fill:"none",stroke:"hsl(var(--border))",strokeWidth:"3"}),e.jsx("circle",{cx:"18",cy:"18",r:"15.5",fill:"none",stroke:"hsl(var(--primary))",strokeWidth:"3",strokeDasharray:`${k.credibility_score*.975} 100`,strokeLinecap:"round"})]}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-sm font-bold text-foreground",children:k.credibility_score})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Credibility Score"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"How authoritative and trustworthy you appear"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(ys,{className:"w-3.5 h-3.5"})," Currently known for"]}),e.jsx("p",{className:"text-sm text-foreground leading-relaxed bg-secondary/20 rounded-lg px-3 py-2.5",children:k.known_for})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(Nr,{className:"w-3.5 h-3.5"})," Audience alignment"]}),e.jsx("p",{className:"text-sm text-foreground leading-relaxed bg-secondary/20 rounded-lg px-3 py-2.5",children:k.audience_alignment})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground",children:"🔍 Sharp diagnosis"}),e.jsx("div",{className:"space-y-2",children:k.sharp_diagnoses.map((f,_)=>e.jsxs("div",{className:"flex items-start gap-2.5 bg-destructive/5 border border-destructive/10 rounded-lg px-3 py-2.5",children:[e.jsx(Ee,{className:"w-3.5 h-3.5 text-destructive mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-foreground leading-relaxed",children:f})]},_))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-warning flex items-center gap-1",children:[e.jsx(ze,{className:"w-3.5 h-3.5"})," Overrepresented"]}),e.jsx("div",{className:"space-y-1",children:k.overrepresented_themes.map((f,_)=>e.jsx("span",{className:"inline-block bg-warning/10 text-warning text-xs font-medium rounded-full px-2.5 py-1 mr-1.5 mb-1",children:f},_))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-accent flex items-center gap-1",children:[e.jsx(vs,{className:"w-3.5 h-3.5"})," Under-signaled"]}),e.jsx("div",{className:"space-y-1",children:k.under_signaled_strengths.map((f,_)=>e.jsx("span",{className:"inline-block bg-accent/10 text-accent text-xs font-medium rounded-full px-2.5 py-1 mr-1.5 mb-1",children:f},_))})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 pt-2",children:[e.jsxs(g,{onClick:()=>s(k),className:"flex-1 gradient-primary text-primary-foreground font-semibold gap-2",children:[e.jsx(He,{className:"w-4 h-4"}),"Generate Weekly Brief"]}),e.jsxs(g,{variant:"outline",onClick:()=>E(null),className:"gap-1.5",children:[e.jsx(vt,{className:"w-4 h-4"}),"Re-audit"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-3 gap-2",children:F.map(f=>e.jsxs("button",{onClick:()=>n(f.id),className:`flex flex-col items-center gap-1.5 rounded-xl p-3 text-center transition-all border-2 ${r===f.id?"border-primary bg-primary/5 text-primary":"border-transparent bg-secondary/30 text-muted-foreground hover:bg-secondary/50"}`,children:[e.jsx(f.icon,{className:"w-5 h-5"}),e.jsx("span",{className:"text-xs font-semibold",children:f.label}),e.jsx("span",{className:"text-[10px] leading-tight opacity-70 hidden sm:block",children:f.desc})]},f.id))}),r==="url"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-sm font-semibold text-foreground",children:"Your name or LinkedIn URL"}),e.jsx(pe,{value:i,onChange:f=>a(f.target.value),placeholder:"Jane Smith or linkedin.com/in/janesmith",className:"text-sm",type:"text"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"We'll search the web for your public professional presence."})]}),r==="paste"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-sm font-semibold text-foreground",children:"Your public presence"}),e.jsx(st,{value:o,onChange:f=>l(f.target.value),placeholder:`LinkedIn headline: ...
98
99About section: ...
100
101Recent post 1: ...
102
103Recent post 2: ...`,className:"min-h-[160px] text-sm leading-relaxed"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"The more you share, the sharper the diagnosis."})]}),r==="profile"&&e.jsxs("div",{className:"space-y-3",children:[v?e.jsxs("div",{className:"bg-secondary/20 rounded-xl p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:v.emoji}),e.jsx("span",{className:"font-semibold text-sm text-foreground",children:v.name}),e.jsx("span",{className:"text-[10px] bg-primary/10 text-primary rounded-full px-2 py-0.5",children:"Active"})]}),v.goal&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["🎯 ",v.goal]}),v.voice_samples.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["🗣️ ",v.voice_samples.length," voice sample",v.voice_samples.length!==1?"s":""]}),v.recurring_themes.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:v.recurring_themes.map((f,_)=>e.jsx("span",{className:"text-[10px] bg-accent/10 text-accent rounded-full px-2 py-0.5",children:f},_))})]}):e.jsxs("div",{className:"bg-secondary/20 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"No brand profile found."}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Create one in Settings → Brand Memory first."})]}),e.jsx(st,{value:o,onChange:f=>l(f.target.value),placeholder:"Optionally add recent posts or extra context…",className:"min-h-[80px] text-sm leading-relaxed"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1.5",children:[e.jsx(kr,{className:"w-3.5 h-3.5"})," Email (optional — to receive your results)"]}),e.jsx(pe,{value:u,onChange:f=>x(f.target.value),placeholder:"[email protected]",type:"email",className:"text-sm"})]}),e.jsx(g,{onClick:B,disabled:H,className:"w-full gradient-primary text-primary-foreground font-semibold gap-2 h-11",children:H?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 animate-spin"}),m?"Fetching profile…":"Analyzing your presence…"]}):e.jsxs(e.Fragment,{children:[e.jsx(vt,{className:"w-4 h-4"}),"Run Perception Audit"]})})]})})]})]})}function al({auditResult:t,onClose:s,onUseAngle:r}){const[n,i]=c.useState(!1),[a,o]=c.useState(null),[l,u]=c.useState(null),{settings:x}=xe(),{toast:m}=je();c.useEffect(()=>{t&&!a&&p()},[t]);const p=async()=>{i(!0);try{const{data:j,error:k}=await W.functions.invoke("linkedin-ai",{body:{action:"weekly_brief",content:JSON.stringify(t),settings:x}});if(k)throw k;o(JSON.parse(j.result))}catch(j){m({variant:"destructive",title:"Brief generation failed",description:j.message})}finally{i(!1)}},h=(j,k)=>{navigator.clipboard.writeText(j),u(k),setTimeout(()=>u(null),2e3)};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-3",onClick:s,children:[e.jsx("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-card border border-border rounded-2xl shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto animate-in fade-in zoom-in-95 duration-200",onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 bg-card/95 backdrop-blur-sm border-b border-border/50 px-5 py-4 flex items-center justify-between z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-accent/10 flex items-center justify-center",children:e.jsx(cr,{className:"w-5 h-5 text-accent"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold text-foreground text-base",children:"Weekly Opportunity Brief"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your action plan to become more trusted this week"})]})]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:s,className:"text-muted-foreground",children:e.jsx(te,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"px-5 py-5 space-y-5",children:n?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx(ae,{className:"w-8 h-8 animate-spin text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground font-medium",children:"Building your opportunity brief…"}
103),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:"Turning diagnosis into action"})]}):a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-primary/5 border border-primary/10 rounded-xl px-4 py-3",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wider text-primary mb-1",children:"🎯 This week's theme"}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:a.weekly_theme})]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(ys,{className:"w-3.5 h-3.5"})," 3 Post angles to strengthen positioning"]}),a.post_angles.map((j,k)=>e.jsxs("div",{className:"border border-border/50 rounded-xl p-3.5 space-y-2 hover:border-primary/30 transition-colors",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"inline-block bg-primary/10 text-primary text-[10px] font-bold uppercase rounded-full px-2 py-0.5 mb-1.5",children:j.template.replace("-"," ")}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:j.angle})]}),e.jsx("span",{className:"text-lg shrink-0",children:k===0?"🔥":k===1?"💡":"⚡"})]}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:j.why}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>r(j.angle),className:"gap-1.5 text-xs h-7 border-primary/20 text-primary",children:[e.jsx(He,{className:"w-3 h-3"}),"Use this angle"]})]},k))]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(wr,{className:"w-3.5 h-3.5"})," 5 People / conversations to engage"]}),e.jsx("div",{className:"space-y-1.5",children:a.people_to_engage.map((j,k)=>e.jsxs("div",{className:"flex items-start gap-2.5 bg-secondary/20 rounded-lg px-3 py-2.5",children:[e.jsxs("span",{className:"text-xs font-bold text-primary mt-0.5",children:[k+1,"."]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-foreground",children:j.description}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 italic",children:["→ ",j.action]})]})]},k))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(mr,{className:"w-3.5 h-3.5"})," 2 Profile gaps to fix"]}),a.profile_gaps.map((j,k)=>e.jsxs("div",{className:"flex items-start gap-2 bg-warning/5 border border-warning/10 rounded-lg px-3 py-2.5",children:[e.jsx(mr,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-foreground",children:j})]},k))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(Ma,{className:"w-3.5 h-3.5"})," 1 Smart CTA to test"]}),e.jsxs("div",{className:"bg-primary/5 border border-primary/10 rounded-lg px-3 py-2.5 flex items-start justify-between gap-2",children:[e.jsxs("p",{className:"text-sm text-foreground italic",children:['"',a.smart_cta,'"']}),e.jsx(g,{variant:"ghost",size:"icon",className:"w-7 h-7 shrink-0",onClick:()=>h(a.smart_cta,99),children:l===99?e.jsx(Z,{className:"w-3.5 h-3.5 text-success"}):e.jsx(Me,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5",children:[e.jsx(Ra,{className:"w-3.5 h-3.5"})," 1 Credibility asset to publish"]}),e.jsx("div",{className:"bg-accent/5 border border-accent/10 rounded-lg px-3 py-2.5",children:e.jsx("p",{className:"text-sm text-foreground",children:a.credibility_asset})})]}),e.jsx("div",{className:"pt-2",children:e.jsxs(g,{variant:"outline",onClick:p,className:"w-full gap-2",children:[e.jsx(cr,{className:"w-4 h-4"}),"Regenerate Brief"]})})]}):e.jsx("div",{className:"text-center py-12 text-muted-foreground text-sm",children:"No audit data. Run a Perception Audit first."})})]})]})}const il=["Spanish","French","German","Portuguese","Arabic","Chinese","Japanese","Hindi"],cs="sb_draft_post",ol=[{key:"polish",label:"Polish a draft"},{key:"format",label:"Format my words"},{key:"create",label:"Create something"},{key:"repurpose",label:"Repurpose something"}],Ul=()=>{const t=ea(),s=vr(),r=ta("composer_empty_state","Paste a draft, notes, an email, attach something, or dictate an idea."),{user:n,signOut:i}=sa(),[a,o]=c.useState(()=>localStorage.getItem(cs)||""),[l,u]=c.useState(null),[x,m]=c.useState(null),[p,h]=c.useState(null),[j,k]=c.useState(!1),[E,S]=c.useState(null),[v,L]=c.useState(!1),[G,B]=c.useState(!1),[H,A]=c.useState(!1),[F,f]=c.useState(!1),[_,R]=c.useState(null),[M,V]=c.useState(null),[C,D]=c.useState(!1),[Q,Y]=c.useState(!1),[re,ne]=c.useState(!1),[ce,we]=c.useState(!1),[y,O]=c.useState([]),[ke,ie]=c.useState(!1),[at,Oe]=c.useState(!1),[P,X]=c.useState([]),[Mt,Ms]=c.useState(!1),[it,Rs]=c.useState(!1),[Rt,Se]=c.useState(!1),[Os,Ls]=c.useState(!1),[en,Fs]=c.useState(!1),[tn,Ot]=c.useState(!1),[sn,Lt]=c.useState(!1),[rn,Ft]=c.useState(!1),[nn,an]=c.useState(null),[ot,Dt]=c.useState(null),[on,$t]=c.useState(!1),[ln,cn]=c.useState(!1),[fe,Ds]=c.useState(()=>Na()),[dn,zt]=c.useState(!1),[lt,ct]=c.useState(null),[mn,un]=c.useState(!1),Ht=c.useRef(null),Ke=wa(fe)?"linkedin":"generic",Le=Ke==="linkedin",Ut=fe?or(fe).label:null,{profiles:Xe,activeProfile:de,activeId:oe,loading:ll,saving:$s,canAddProfile:xn,switchProfile:hn,
103createProfile:pn,updateProfile:fn,deleteProfile:gn}=Tr(),{settings:me,canCreatePost:Bt,incrementPosts:Wt,postsCreated:zs,maxFree:bn,isFoundingMember:dt,foundingExpiresAt:Hs,checkFoundingStatus:yn,grantFoundingAccess:jn}=xe(),{isPremium:Je,tier:Us}=ra(),{toast:T}=je(),Gt=c.useRef(null),mt=c.useRef(null),Ve=c.useRef(null),_e=c.useRef(new Go),qe=(d,b,I)=>{_e.current.markValueAction(d,b,oe??null,I)},vn=()=>{_e.current.reset()},Yt=c.useRef(!1),ut=()=>{Yt.current=!1,S(null)},ge=d=>{_e.current.invalidate(),ut(),le(d)},Nn=d=>{_e.current.invalidate(),ut(),hn(d)};c.useEffect(()=>{yn();const d=new URLSearchParams(window.location.search);d.get("new_profile")==="1"&&($t(!0),window.history.replaceState({},"",window.location.pathname));const b=d.get("checkout"),I=d.get("session_id"),U=d.get("device_id"),z=d.get("repurpose");if(z&&z.trim()){const $=z.trim();o($);try{localStorage.setItem(cs,$)}catch{}d.delete("repurpose");const ee=d.toString();window.history.replaceState({},"",window.location.pathname+(ee?`?${ee}`:""))}b==="success"&&I?(oa(),(async()=>{try{const{data:$,error:ee}=await W.functions.invoke("verify-founding",{body:{sessionId:I,deviceId:U||kt()}});$!=null&&$.success?(jn($.expires_at),T({title:"🎉 Welcome, Founding Member!",description:"You now have 90 days of unlimited access!"})):T({title:"🎉 Payment successful!",description:"Your premium access is now active."})}catch{T({title:"🎉 Payment successful!",description:"Your premium access is now active."})}})(),window.history.replaceState({},"",window.location.pathname)):b==="canceled"&&(T({variant:"destructive",title:"Checkout canceled",description:"No charges were made."}),window.history.replaceState({},"",window.location.pathname))},[]);const le=c.useCallback(d=>{o(b=>{const I=typeof d=="function"?d(b):d;return localStorage.setItem(cs,I),I})},[]),wn=d=>{var b,I;if(N(w.COMPOSER_STARTER_CLICKED,{starter:d}),d==="create"){Oe(!0);return}if(d==="repurpose"){Ot(!0);return}cn(d==="format"),(b=Ve.current)==null||b.focus(),(I=mt.current)==null||I.scrollIntoView({behavior:"smooth",block:"start"})},kn=c.useCallback(d=>{le(b=>b+(b?" ":"")+d)},[]),{isListening:Kt,toggle:Sn}=Va(kn),[J,Bs]=c.useState(null),[_n,Ws]=c.useState(!1),[Cn,Gs]=c.useState(null),[xt,Ys]=c.useState(null),[An,Xt]=c.useState(!1),Ks=c.useRef(!1);c.useEffect(()=>{const d=_a();if(!d||d.findings.length===0){Ca();return}Bs(d),N(w.WORK_CONTEXT_RESTORED,{source:d.origin,type:d.type});const b=new URLSearchParams(window.location.search).get("autostart")==="1",I=Aa(),U=xs.some(z=>z.key===I)?I:null;b&&U&&Ys(U)},[]);const In=()=>{Ia(),Bs(null),Gs(null),Ds(null),lr(null)},En=async()=>{if(!J||!a.trim())return;const d=ma(J.findings);if(d.length!==0){Ws(!0),N(w.DIAGNOSIS_FINDINGS_APPLY_STARTED,{finding_count:d.length});try{const b=await Qe(a,d,me);O(b),Gs(J.findings),N(w.DIAGNOSIS_FINDINGS_APPLY_COMPLETED,{finding_count:d.length,option_count:b.length}),T({title:"Signal Audit findings applied",description:"Pick a version below, then recheck the draft."})}catch(b){N(w.DIAGNOSIS_FINDINGS_APPLY_FAILED,{finding_count:d.length}),T({variant:"destructive",title:"Could not apply the findings",description:b.message})}finally{Ws(!1)}}},Xs=()=>{var d,b;(d=Ve.current)==null||d.focus(),(b=mt.current)==null||b.scrollIntoView({behavior:"smooth",block:"start"})},Jt=d=>{Ds(d),lr(d)},Js=async d=>{if(!J)return!1;Jt(d);const b=or(d),I={diagnosisInput:J.diagnosisInput,findings:J.findings};zt(!0),N(w.DIAGNOSIS_DRAFT_STARTED,{asset:d,finding_count:J.findings.length});try{const U=await Qe(ka(b,I),Sa(b,I),me),z=U.find($=>$&&$.trim().length>0);if(!z)throw new Error("The draft came back empty. Try again.");ge(z),O(U.length>1?U:[]),u(null),ct(null),Ht.current=null,N(w.DIAGNOSIS_DRAFT_COMPLETED,{asset:d,option_count:U.length}),Xt(!1),T({title:"First draft ready",description:"Edit it, then review to see your score."}),setTimeout(()=>{var $,ee;($=mt.current)==null||$.scrollIntoView({behavior:"smooth",block:"start"}),(ee=Ve.current)==null||ee.focus()},100)}catch(U){return N(w.DIAGNOSIS_DRAFT_FAILED,{asset:d}),T({variant:"destructive",title:"Could not write the first draft",description:U.message}),zt(!1),!1}return zt(!1),!0};c.useEffect(()=>{if(!(!J||!xt||Ks.current)){if(a.trim().length>0){Ys(null);return}Ks.current=!0,(async()=>await Js(xt)||Xt(!0))()}},[J,xt]);const ht=async(d="initial")=>{if(!a.trim()&&P.length>0){Zt(P[0]);return}if(!a.trim()){T({variant:"destructive",title:"Nothing to analyze",description:"Type or paste your post first."});return}B(!0);try{N(w.ANALYZE),N(w.COMPOSER_ANALYZE_STARTED),d==="recheck"&&N(w.COMPOSER_RECHECK_STARTED);const b=Ur(l,Ke),I=d==="recheck"&&Yt.current&&x!==null&&b!==null&&p===(oe??null),U=Ht.current,z=await ni(a,me);S(I?b:null),u(z);const $={score:z.score,dimensions:z.dimensions,profileId:oe??null,assetKey:fe??null,mode:Ke};if(d==="recheck"){const ee=zo({previous:U,current:$,lineageIntact:I});if(ee.comparable===!0)ct(ee);else{ct(null);const Gn="reason"in ee?ee.reason:"no_current_review";N(w.PROOF_UNAVAILABLE,{reason:Gn,asset:fe??null})}}else ct(null);Ht.current=$,Yt.current=!0,m(a),h(oe??null),L(!1),qe("analyze_keep",a),N(w.COMPOSER_ANALYZE_COMPLETED),d==="recheck"&&N(w.COMPOSER_RECHECK_COMPLETED),setTimeout(()=>{var ee;return(ee=Gt.current)==null?void 0:ee.scrollIntoView({behavior:"smooth",block:"start"})},100)}catch(b){T({variant:"destructive",title:"Analysis failed",description:b.message})}finally{B(!1)}},K=Yo({hasAnalysis:!!l,content:a,analyzedContent:x,profileId:oe??null,analyzedProfileId:p});c.useEffect(()=>{K&&O(d=>d.length?[]:d)},[K]);const pt=c.useRef(void 0);c.useEffect(()=>{const d=oe??null;if(pt.current===void 0){pt.current=d;return}
103pt.current!==d&&(pt.current=d,_e.current.invalidate(),ut())},[oe]);const Vs=async()=>{if(!a.trim()&&P.length>0){Zt(P[0]);return}if(!a.trim()){T({variant:"destructive",title:"Nothing to format",description:"Type or paste your post first."});return}if(!Je&&!Bt()){N(w.PAYWALL_HIT,{trigger:"ai_magic"}),Y(!0);return}A(!0);try{N(w.AI_MAGIC),N(w.COMPOSER_POLISH_STARTED);const d=await ai(a,me);if(le(d),Fe(null),he(null),qe("polish",d),N(w.COMPOSER_POLISH_COMPLETED),ns(d),Wt(),wt(),T({title:"✨ Polished",description:"Strategic formatting applied to your content."}),de!=null&&de.id){const b=kt();Ta(d,de,b,de.id).then(I=>{if(I.length>0){const U=I.find($=>$.severity==="critical"||$.severity==="warning"),z=I.find($=>$.severity==="positive");U?T({title:"⚠️ Brand drift detected",description:U.title}):z&&T({title:"✅ On-brand content",description:z.title})}})}Xo(zs+1)&&setTimeout(()=>Fs(!0),1500)}catch(d){T({variant:"destructive",title:"Formatting failed",description:d.message})}finally{A(!1)}},[Vt,qs]=c.useState(!1),[be,Fe]=c.useState(null),[ft,he]=c.useState(null),qt=async d=>{const b=typeof d=="string"?d:a;if(!b.trim()){T({variant:"destructive",title:"Nothing to format",description:"Type or paste your post first."});return}if(!Je&&!Bt()){N(w.PAYWALL_HIT,{trigger:"format_only"}),Y(!0);return}const I=b,U=!!l&&x!==null&&x===I&&p===(oe??null);qs(!0);try{N(w.FORMAT_ONLY),N(w.COMPOSER_FORMAT_ONLY_STARTED);const z=await ii(I),$=yr(I,z);le(z),Fe({...$,original:I}),$.preserved?(he(z),U&&m(z)):he(null),qe($.preserved?"format_only_preserved":"format_only_changed",z,$.preserved),V({source:"format_only",text:z}),N(w.COMPOSER_FORMAT_ONLY_COMPLETED,{preserved:$.preserved,changed_words:$.changedWords}),ns(z),os("sb_formats"),Wt(),wt(),T($.preserved?{title:"🎨 Formatted",description:"0 words changed — your words stay yours."}:{variant:"destructive",title:`⚠️ ${$.changedWords} word${$.changedWords===1?"":"s"} changed`,description:"Formatting altered your wording. Review, revert, or run Format Only again."})}catch(z){T({variant:"destructive",title:"Formatting failed",description:z.message})}finally{qs(!1)}},Pn=()=>{be&&(le(be.original),Fe(null),he(null),_e.current.invalidate(d=>d.source.startsWith("format_only")),T({title:"Reverted",description:"Your original wording is back."}))},Tn=()=>{if(!be)return;const d=be.original;le(d),Fe(null),he(null),qt(d)},Mn=async d=>{if(a.trim()){ne(!1),N(w.TRANSLATE,{language:d});try{const b=await oi(a,d);ge(b),os("sb_translates"),Ko(),T({title:`🌐 Translated to ${d}`})}catch(b){T({variant:"destructive",title:"Translation failed",description:b.message})}}},Rn=async()=>{if(!a.trim())return;try{await _s(a)}catch{T({variant:"destructive",title:"Copy failed",description:"We couldn't copy this draft to your clipboard."});return}ns(a),os("sb_copies"),N(w.COPY_POST),N(w.COMPOSER_COPY),wt(),f(!0),R(a),setTimeout(()=>f(!1),2e3);
103const d=_e.current.resolveCopy(a,oe??null);d&&N(w.MARKETING_WIN_COMPLETED,{...d,brand_context:!!oe,had_analysis:!!l&&!K}),T({title:"📋 Copied!",description:"Paste it into LinkedIn."})},On=async()=>{var d;if(!(!a.trim()||!((d=l==null?void 0:l.suggestions)!=null&&d.length))){if(K){T({title:"Review out of date",description:De});return}ie(!0);try{const b=await Qe(a,l.suggestions,me);O(b),T({title:"Revised versions ready",description:"Pick one below, then recheck the draft."})}catch(b){T({variant:"destructive",title:"Failed to apply suggestions",description:b.message})}finally{ie(!1)}}},Ln=async()=>{var b;const d=(b=l==null?void 0:l.suggestions)==null?void 0:b[0];if(!(!a.trim()||!d)){if(K){T({title:"Review out of date",description:De});return}k(!0);try{N(w.COMPOSER_FIX_STARTED),await fr({run:I=>Qe(a,[d],me,{signal:I}),isUsable:I=>Array.isArray(I)&&I.length>0,onCompleted:(I,U)=>{O(I),N(w.COMPOSER_FIX_COMPLETED,{option_count:I.length,duration_ms:U}),T({title:"Revised versions ready",description:"Pick one below, then recheck the draft."})},onFailed:(I,U,z)=>{N(w.COMPOSER_FIX_FAILED,{reason:I,duration_ms:U}),T({variant:"destructive",title:"Could not apply that fix",description:z})}})}finally{k(!1)}}},[Fn,Zs]=c.useState(null),Dn=async(d,b)=>{if(!(!a.trim()||!d)){if(K){T({title:"Review out of date",description:De});return}Zs(b);try{N(w.COMPOSER_FIX_STARTED,{recommendation_index:b}),await fr({run:I=>Qe(a,[d],me,{signal:I}),isUsable:I=>Array.isArray(I)&&I.length>0,onCompleted:(I,U)=>{O(I),N(w.COMPOSER_FIX_COMPLETED,{option_count:I.length,recommendation_index:b,duration_ms:U}),T({title:"Revised versions ready",description:"Pick one below, then recheck the draft."})},onFailed:(I,U,z)=>{N(w.COMPOSER_FIX_FAILED,{reason:I,duration_ms:U,recommendation_index:b}),T({variant:"destructive",title:"Could not apply that recommendation",description:z})}})}finally{Zs(null)}}},$n=d=>{if(K){T({title:"Review out of date",description:De});return}const b=Ao(a,d);if(b===a){T({title:"Already your opening line",description:"That hook is already in place."});return}le(b),he(null),qe("revision_selected",b),V({source:"revision_selected",text:b}),N(w.COMPOSER_HOOK_APPLIED),T({title:"Hook swapped",description:"Only your opening line changed. Recheck the draft when you're ready."})},zn=(d,b)=>{if(l&&K){T({title:"Review out of date",description:De});return}le(d),O([]),qe("revision_selected",d),V({source:"revision_selected",text:d}),N(w.COMPOSER_REVISION_SELECTED,typeof b=="number"?{option_index:b}:{}),T({title:"Draft updated",description:"Recheck the draft when you're ready."})},Hn=()=>{if(K){T({title:"Review out of date",description:De});return}L(!0),N(w.COMPOSER_RECOMMENDATION_KEPT)},Zt=async d=>{if(!Je&&!Bt()){N(w.PAYWALL_HIT,{trigger:"generate_from_file"}),Y(!0);return}Ms(!0);try{N(w.GENERATE_FROM_FILE,{fileType:d.type});const b=await ci(d.url,d.name,d.type,me);ge(b),Wt(),T({title:"✨ Post generated from file!",description:`Created from ${d.name}`})}catch(b){T({variant:"destructive",title:"Generation failed",description:b.message})}finally{Ms(!1)}},Qs=a.length,Qt=3e3,Ce=dt?1/0:Math.max(0,bn-zs),gt=!!l&&!K,es=ft!==null&&ft===a,er=gt&&!es,tr=!gt,bt=gt&&es,Un=d=>{yr(a,d).preserved?(x!==null&&x===a&&m(d),ft!==null&&ft===a&&he(d)):he(null),le(d)},sr=Ho(J),rr=Je||dt||Us==="owner"||Us==="enterprise",Bn=Wo({workContext:J,proofDelta:lt?lt.delta:null,entitled:rr,dismissed:mn||Uo(sr)}),Ae=To(M,a),nr=Ro({completed:Ae,entitled:rr}),ts=c.useRef(null);c.useEffect(()=>{if(!Ae||!M){Ae||(ts.current=null);return}const d=Fo(M.source,M.text);ts.current!==d&&(ts.current=d,Do(d)&&N(w.COMPOSER_COMPLETION_SURFACE_SHOWN,$o({source:M.source,platform:"linkedin",valueActionShown:nr})))},[Ae,M==null?void 0:M.source,M==null?void 0:M.text]);const ar=e.jsxs("div",{className:"space-y-4",children:[lt&&e.jsx(Po,{proof:lt,journey:J?"diagnosis_composer":"composer",assetKey:fe,scopeLine:Hr(Ke)}),Bn&&e.jsx(la,{outcome:"Keep improving assets like this one",benefit:"You just measured a real improvement. Pro keeps the Diagnose → Fix → Recheck loop running on your next assets.",returnTo:"/composer",source:"composer_proof",journey:"proof_moment",dismissLabel:"Maybe later",onDismiss:()=>{Bo(sr),un(!0)}}),e.jsx(pi,{analysis:l,isLoading:G,onApplySuggestions:K?void 0:On,isApplying:ke,variations:y,onPickVariation:zn,onAnalyze:a.trim()?()=>ht("initial"):void 0,isStale:K,onRecheck:a.trim()?()=>ht("recheck"):void 0,onFixTopSuggestion:Ln,isFixingTop:j,topRecKept:v,onKeepTopRecommendation:
103Hn,previousScore:E,onFormatForLinkedIn:Le&&!K?()=>qt():void 0,isFormattingForLinkedIn:Vt,isFormattedPreserved:es,onApplyRecommendation:K?void 0:Dn,applyingRecommendationIndex:Fn,onUseHook:Le&&!K?$n:void 0,scoreMode:Ke,assetLabel:Ut})]}),Wn=!!a.trim()||G||!!l;return e.jsxs("div",{className:"min-h-screen bg-background flex flex-col overflow-y-auto overflow-x-hidden",children:[e.jsx("header",{className:"border-b border-border/50 bg-card/80 backdrop-blur-sm sticky top-0 z-40",children:e.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-4 py-2.5 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(St,{className:"w-4 h-4 text-primary shrink-0"}),e.jsx("span",{className:"text-sm sm:text-base font-bold text-foreground truncate",children:"Composer"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[Xe.length>0&&e.jsx("div",{className:"hidden sm:block",children:e.jsx(Zo,{profiles:Xe,activeId:oe,canAdd:xn,onSwitch:Nn,onAdd:()=>$t(!0),onEdit:d=>Dt(d)})}),Xe.length===0&&e.jsxs("button",{onClick:()=>D(!0),className:"hidden sm:flex items-center gap-1 bg-secondary/80 rounded-full px-2 py-1 hover:bg-secondary transition-colors",children:[e.jsx("span",{className:"text-sm",children:ir(me.audiencePreset).emoji}),e.jsx("span",{className:"text-[11px] font-medium text-secondary-foreground hidden sm:inline",children:ir(me.audiencePreset).label})]}),dt?(()=>{const d=Hs?Math.max(0,Math.ceil((new Date(Hs).getTime()-Date.now())/864e5)):0;return e.jsxs("div",{className:"flex items-center gap-1.5 bg-primary/10 rounded-full px-2.5 py-1",children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full ${d>7?"bg-success":"bg-warning"}`}),e.jsxs("span",{className:"text-xs font-mono text-primary font-semibold",children:["⭐ ",d,"d"]})]})})():e.jsxs("span",{className:"text-xs font-semibold text-foreground bg-secondary/80 rounded-full px-2.5 py-1 whitespace-nowrap",title:`Free plan · ${Ce} free creation${Ce===1?"":"s"} left on this device`,"aria-label":`Free plan. ${Ce} free creations left on this device.`,children:["Free",Ce>0?` · ${Ce} creation${Ce===1?"":"s"} left`:""]}),!Je&&!dt&&Ce===0&&e.jsx(g,{size:"sm",onClick:()=>{N(w.UPGRADE_CLICKED),Y(!0)},className:"bg-primary text-primary-foreground text-[11px] h-7 px-2.5",children:"Upgrade"}),!n&&e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>t("/auth"),className:"text-[11px] h-7 px-2 sm:px-2.5 gap-1",children:[e.jsx(We,{className:"w-3 h-3"})," ",e.jsx("span",{className:"hidden sm:inline",children:"Sign In"})]}),e.jsx(g,{variant:"ghost",size:"icon",onClick:()=>D(!0),className:"text-muted-foreground hover:text-foreground w-7 h-7 shrink-0",children:e.jsx(na,{className:"w-3.5 h-3.5"})})]})]})}),e.jsxs("main",{className:"max-w-5xl mx-auto px-3 sm:px-4 py-4 sm:py-6 flex-1",children:[!a.trim()&&P.length===0&&e.jsxs("div",{className:"mb-6 text-center",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold text-foreground",children:"What are you working on?"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1.5",children:r}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center justify-center gap-2",children:ol.map(d=>e.jsx("button",{onClick:()=>wn(d.key),className:"rounded-full border border-border bg-card px-3.5 py-2 text-xs font-medium text-foreground hover:border-primary/40 hover:text-primary transition-colors",children:d.label},d.key))}),ln&&e.jsx("p",{className:"mt-3 text-[11px] text-primary",children:"Format is ready — add your words above and it will format them without rewriting them."})]}),J&&e.jsx(Io,{context:J,hasDraft:a.trim().length>0,onApplyFindings:En,isApplying:_n,appliedFindings:Cn,onRecheck:()=>ht("recheck"),onStartDraft:Xs,onDismiss:In}),J&&!a.trim()&&e.jsx(Eo,{context:J,isGenerating:dn,initialAsset:xt??fe,retry:An,onGenerate:d=>{Xt(!1),Js(d)},onWriteMyself:d=>{Jt(d),Xs()}}),e.jsx("div",{ref:mt,className:"scroll-mt-20"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"px-3 sm:px-4 py-2 sm:py-3 border-b border-border/50 bg-secondary/20 space-y-2",children:[de&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[11px] font-medium border border-primary/20 bg-primary/5 text-primary curs
103or-pointer hover:bg-primary/10 transition-colors",onClick:()=>Dt(de.id),title:`Writing as "${de.name}" — click to edit`,children:[e.jsx("span",{className:"text-sm",children:de.emoji}),e.jsx("span",{className:"truncate max-w-[120px]",children:de.name}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success shrink-0"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"AI uses this voice"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-primary/25 bg-primary/5 px-2 py-0.5 text-[10px] font-semibold text-primary",title:Le?"Score, recommendations and formatting target LinkedIn. Other channels are available under Adapt to other channels.":`Reviewing a ${Ut}. LinkedIn-specific fit is excluded from the score.`,children:[e.jsx(Cr,{className:"w-3 h-3"}),Le?"Primary channel: LinkedIn":`Reviewing: ${Ut}`]}),!Le&&e.jsx("button",{type:"button",onClick:()=>Jt("linkedin_post"),className:"text-[10px] font-medium text-primary underline underline-offset-2 hover:no-underline",title:"Switch back to the LinkedIn-first Composer",children:"Switch to LinkedIn post"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2",children:[e.jsxs(g,{size:"sm",onClick:()=>ht(K?"recheck":"initial"),disabled:G,variant:tr?"default":"outline",className:`gap-1.5 text-xs shrink-0 h-8 ${tr?"font-semibold gradient-primary text-primary-foreground":"font-medium"}`,title:K?"Recheck: re-score the draft after your changes":"Score & Review: evaluate message quality for LinkedIn and get recommendations","aria-label":K?"Recheck this draft":"Score and review this draft",children:[K?e.jsx(gs,{className:"w-3.5 h-3.5"}):e.jsx(q,{className:"w-3.5 h-3.5"}),G?"Scoring…":K?"Recheck":gt?"Re-score":e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:"Score"}),e.jsx("span",{className:"hidden sm:inline",children:"Score & Review"})]})]}),Le&&e.jsxs(g,{variant:er?"default":"outline",size:"sm",onClick:()=>qt(),disabled:Vt,className:`gap-1.5 text-xs shrink-0 h-8 ${er?"font-semibold gradient-primary text-primary-foreground":"font-medium"}`,title:"Format for LinkedIn: improves presentation and preserves your exact wording","aria-label":"Format for LinkedIn — improves presentation and preserves your exact wording",children:[e.jsx(Ns,{className:"w-3.5 h-3.5"}),Vt?"…":e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:"Format"}),e.jsx("span",{className:"hidden sm:inline",children:"Format for LinkedIn"})]})]}),e.jsx("button",{onClick:Vs,disabled:H,className:"shrink-0 text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline disabled:opacity-50",title:"Polish: REWRITES your wording and structure","aria-label":"Rewrite / Polish wording — rewrites your wording and structure",children:H?"Working…":"Rewrite / Polish wording"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 shrink-0",children:[e.jsx(g,{variant:Kt?"destructive":"ghost",size:"sm",onClick:Sn,className:"h-8 w-8 p-0 text-xs shrink-0",title:"Dictate your post using voice",children:Kt?e.jsx(Da,{className:"w-4 h-4"}):e.jsx($a,{className:"w-4 h-4"})}),e.jsx(g,{variant:"ghost",size:"sm",onClick:()=>{le(""),X([]),u(null),O([]),Fe(null),he(null),m(null),h(null),L(!1),ut(),vn()},disabled:!a&&P.length===0,title:"Clear",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",children:e.jsx(ca,{className:"w-3.5 h-3.5"})})]})]}),be&&e.jsxs("div",{className:`rounded-lg border px-2.5 py-2 text-[11px] flex flex-wrap items-center gap-x-2 gap-y-1 ${be.preserved?"border-success/30 bg-success/5 text-success":"border-destructive/40 bg-destructive/5 text-destructive"}`,children:[e.jsx("span",{className:"font-semibold",children:be.summary}),!be.preserved&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:Pn,className:"underline font-semibold",children:"Revert to my original"}),e.jsx("button",{onClick:Tn,className:"underline",children:"Revert & retry"})]}),e.jsx("button",{onClick:()=>Fe(null),className:"ml-auto text-muted-foreground hover:text-foreground","aria-label":"Dismiss formatting check",children:"✕"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 -mx-1 px-1",children:[e.jsxs("div",{className:"relative",children:[e.jsxs(g,{variant:"ghost",size:"sm",onClick:()=>Se(!Rt),className:"gap-1 text-xs shrink-0 h-7 text-muted-foreground hover:text-foreground",children:[e.jsx(aa,{className:"w-3.5 h-3.5"}),"More",e.jsx(Oa,{className:`w-3 h-3 transition-transform ${Rt?"rotate-180":""}`})]}),Rt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Se(!1)}),e.jsxs("div",{className:"absolute top-full left-0 mt-1 z-50 bg-card border border-border rounded-xl shadow-xl py-1 min-w-[180px] animate-in fade-in zoom-in-95 duration-100",children:[e.jsxs("button",{onClick:()=>{Se(!1),Vs()},disabled:H,className:"flex items-center gap-2 w-full px-3 py-2.5 text-sm text-foreground hover:bg-secondary transition-colors disabled:opacity-50",title:"Polish: REWRITES your wording and structure",children:[e.jsx(Pe,{className:"w-4 h-4 text-muted-foreground"}
103),"Rewrite / Polish wording"]}),e.jsxs("button",{onClick:()=>{Se(!1),ne(!0)},className:"flex items-center gap-2 w-full px-3 py-2.5 text-sm text-foreground hover:bg-secondary transition-colors",children:[e.jsx(Rr,{className:"w-4 h-4 text-muted-foreground"}),"Translate"]}),e.jsxs("button",{onClick:()=>{Se(!1),Ot(!0)},className:"flex items-center gap-2 w-full px-3 py-2.5 text-sm text-foreground hover:bg-secondary transition-colors",children:[e.jsx(_t,{className:"w-4 h-4 text-muted-foreground"}),"Repurpose"]}),e.jsxs("button",{onClick:()=>{Se(!1),Lt(!0)},className:"flex items-center gap-2 w-full px-3 py-2.5 text-sm text-foreground hover:bg-secondary transition-colors",children:[e.jsx(vt,{className:"w-4 h-4 text-muted-foreground"}),"Perception Audit"]}),e.jsxs("button",{onClick:()=>{Se(!1),Ls(!0)},className:"flex items-center gap-2 w-full px-3 py-2.5 text-sm text-foreground hover:bg-secondary transition-colors border-t border-border/50",children:[e.jsx(ms,{className:"w-4 h-4 text-muted-foreground"}),"Post History"]})]})]})]}),e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground/50 hidden sm:inline",children:"Polish rewrites your words · Format only changes presentation"})]})]}),e.jsx(xo,{textareaRef:Ve,content:a,onContentChange:Un}),e.jsxs("div",{className:"relative",children:[!a.trim()&&P.length===0&&e.jsx("div",{className:"flex justify-center px-4 pt-3",children:e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>{N(w.CREATE_FROM_SCRATCH),Oe(!0)},className:"gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx(St,{className:"w-3.5 h-3.5"}),"Start from scratch with AI"]})}),e.jsx("textarea",{ref:Ve,value:a,onChange:d=>{d.nativeEvent.inputType==="insertFromPaste"&&N(w.PASTE_TEXT),le(d.target.value)},placeholder:"Paste a draft, notes, or an email — or dictate an idea.",className:"w-full min-h-[200px] sm:min-h-[280px] bg-transparent p-4 sm:p-5 text-foreground placeholder:text-muted-foreground/40 resize-none focus:outline-none font-sans text-[15px] leading-relaxed",maxLength:Qt}),Kt&&e.jsxs("div",{className:"absolute top-4 right-4 flex items-center gap-2 text-destructive",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-destructive animate-pulse-glow"}),e.jsx("span",{className:"text-xs font-mono font-semibold",children:"Recording..."})]})]}),e.jsx("div",{className:"px-4 py-2 border-t border-border/30",children:e.jsx(da,{files:P,onFilesChange:X,onGenerateFromFile:Zt,isGenerating:Mt})}),e.jsxs("div",{className:"px-4 py-3 border-t border-border/50 bg-secondary/20 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:`text-xs font-mono ${Qs>Qt*.9?"text-warning":"text-muted-foreground"}`,children:[Qs.toLocaleString(),"/",Qt.toLocaleString()]}),a.trim()&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-muted-foreground/70",children:[e.jsx(Z,{className:"w-3 h-3 text-success"}),"Draft saved"]})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("button",{onClick:()=>{it||N(w.REFINE_CHAT),Rs(!it)},className:"text-xs text-primary hover:underline flex items-center gap-1 whitespace-nowrap",disabled:!a.trim(),children:[e.jsx(ve,{className:"w-3 h-3"}),it?"Hide Chat":"Refine"]})})]}),s&&Wn&&e.jsx("div",{ref:Gt,className:"scroll-mt-20",children:ar}),e.jsx("div",{"data-testid":"composer-copy-action-row",className:"flex min-w-0 flex-wrap items-center gap-2",children:_&&_===a?e.jsx(Kr,{text:_,platform:"linkedin",sourceAction:"copy",composerMode:fe??null,onComplete:()=>R(null)},`linkedin:copy:${_}`):e.jsxs(g,{size:"sm",variant:bt||Ae?"default":"outline",onClick:Rn,disabled:!a.trim(),"data-testid":"composer-copy-action",className:`flex-1 font-semibold gap-1.5 ${bt||Ae?"gradient-primary text-primary-foreground":""}`,children:[F?e.jsx(Z,{className:"w-3.5 h-3.5"}):e.jsx(Me,{className:"w-3.5 h-3.5"}),F?"Copied!":Ae?Mo("linkedin"):"Copy for LinkedIn"]})}),e.jsxs(g,{size:"sm",variant:bt?"secondary":"ghost",onClick:()=>{ce||(N(w.PREVIEWS_OPENED),N(w.COMPOSER_USE_ELSEWHERE_OPENED)),we(!ce)},disabled:!a.trim(),"data-testid":"adapt-channels-toggle",className:`w-full gap-1.5 font-semibold ${bt?"border border-border":"text-primary"}`,children:[e.jsx(_t,{className:"w-3.5 h-3.5"}),ce?"Hide other channels":"Adapt to other channels"]}),nr&&e.jsxs("button",{type:"button","data-testid":"composer-completion-value-action",onClick:()=>{N(w.COMPOSER_COMPLETION_VALUE_ACTION_CLICKED,{completion_source:(M==null?void 0:M.source)??null,platform:"linkedin"}),Y(!0)},className:"w-full text-left text-[11px] text-muted-foreground hover:text-primary hover:underline",children:[Oo," →"]})]})]}),ce&&e.jsx(Qi,{content:a,files:P}),it&&a.trim()&&e.jsx(uo,{currentPost:a,onApplyPost:d=>ge(d),onClose:()=>Rs(!1)})]}),e.jsxs("div",{className:"space-y-4",...s?{}:{ref:Gt},children:[!s&&ar,e.jsxs("details",{className:"rounded-xl border border-border bg-card/60",children:[e.jsx("summary",{className:"cursor-pointer list-none px-4 py-3 text-xs font-semibold text-muted-foreground uppercase tracking-wide hover:text-foreground",children:"More creator tools"}),e.jsxs("div",{className:"p-3 pt-0 space-y-4",children:[e.jsx(co,{postContent:a}),e.jsx(qo,{}),e.jsx(io,{})]})]})]})]})]}),e.jsx("footer",{className:"border-t border-border/50 py-3 mt-auto",children:e.jsx("div",{className:"max-w-5xl mx-auto px-4 text-center",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"© Social Brilliance 2026"})})}),re&&e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",onClick:()=>ne(!1),style:{touchAction:"manipulation"},children:[e.jsx("div",{className:"absolute inset-0 bg-background/60 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-card border border-border rounded-xl shadow-2xl min-w-[220px] py-2 mx-4 animate-in fade-in zoom-in-95 duration-150",onClick:d=>d.stopPropagation(),children:[e.jsx("p",{className:"px-4 py-2 text-xs font-semibold text-muted-foreground border-b border-border mb-1",children:"Translate post to:"}),il.map(d=>e.jsx("button",{onClick:()=>Mn(d),className:"block w-full text-left px-4 py-3 text-sm text-foreground hover:bg-secondary active:bg-secondary/80 transition-colors",style:{touchAction:"manipulation"},children:d},d))]})]}),C&&e.jsx(ao,{onClose:()=>D(!1)}),Q&&e.jsx(ia,{onClose:()=>Y(!1)}),Os&&e.jsx(go,{open:Os,onClose:()=>Ls(!1),onRestore:d=>ge(d)}),en&&e.jsx(Jo,{onClose:()=>Fs(!1)}),ot&&e.jsx(xa,{profile:Xe.find(d=>d.id===ot)??null,onSave:d=>fn(ot,d),onDelete:Xe.length>1?()=>gn(ot):void 0,onClose:()=>Dt(null),saving:$s}),on&&e.jsx(tl,{onComplete:d=>pn(d),onClose:()=>$t(!1),saving:$s}),at&&e.jsx(lo,{onClose:()=>Oe(!1),onPostReady:d=>ge(d)}),tn&&e.jsx(rl,{onClose:()=>Ot(!1),onUsePost:d=>ge(d)}),sn&&e.jsx(nl,{onClose:()=>Lt(!1),onGenerateBrief:d=>{an(d),Lt(!1),Ft(!0)}}),rn&&e.jsx(al,{auditResult:nn,onClose:()=>Ft(!1),onUseAngle:d=>{ge(d),Ft(!1)}})]})};export{Ul 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.