(function(e,Ee,be,z,w){"use strict";/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */var ke={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const we=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().trim(),u=(t,p)=>{const _=e.forwardRef(({color:k="currentColor",size:b=24,strokeWidth:v=2,absoluteStrokeWidth:q,className:g="",children:m,...f},E)=>e.createElement("svg",{ref:E,...ke,width:b,height:b,stroke:k,strokeWidth:q?Number(v)*24/Number(b):v,className:["lucide",`lucide-${we(t)}`,g].join(" "),...f},[...p.map(([N,F])=>e.createElement(N,F)),...Array.isArray(m)?m:[m]]));return _.displayName=`${t}`,_};/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ve=u("AlertTriangle",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z",key:"c3ski4"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ne=u("Bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Se=u("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const xe=u("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ae=u("Code2",[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ce=u("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Me=u("HelpCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const qe=u("Lightbulb",[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Te=u("ListOrdered",[["line",{x1:"10",x2:"21",y1:"6",y2:"6",key:"76qw6h"}],["line",{x1:"10",x2:"21",y1:"12",y2:"12",key:"16nom4"}],["line",{x1:"10",x2:"21",y1:"18",y2:"18",key:"u3jurt"}],["path",{d:"M4 6h1v4",key:"cnovpq"}],["path",{d:"M4 10h2",key:"16xx2s"}],["path",{d:"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1",key:"m9a95d"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const K=u("Loader2",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const J=u("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Pe=u("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z",key:"ymcmye"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const R=u("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Le=u("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ze=u("Sparkles",[["path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z",key:"17u4zn"}],["path",{d:"M5 3v4",key:"bklmnn"}],["path",{d:"M19 17v4",key:"iiml17"}],["path",{d:"M3 5h4",key:"nem4j1"}],["path",{d:"M17 19h4",key:"lbex7p"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Oe=u("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Fe=u("Volume2",[["polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5",key:"16drj5"}],["path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07",key:"ltjumu"}],["path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14",key:"1kegas"}]]);/**
 * @license lucide-react v0.344.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const $e=u("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),x={name:"AEO God Mode",logo_url:"",support_url:"",docs_url:"",account_url:"",footer_text:"",hide_attribution:!1,rev:0};function Ie(t){return t===!0||t===1||t==="1"||t==="true"}function ee(){const t=window.asgmBrand;return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function O(t,p){return typeof t!="string"?p:t.slice(0,255)}function j(){const t=ee();if(!t)return{...x};const p=O(t.name,x.name).trim();return{name:p!==""?p:x.name,logo_url:O(t.logo_url,x.logo_url),support_url:O(t.support_url,x.support_url),docs_url:O(t.docs_url,x.docs_url),account_url:O(t.account_url,x.account_url),footer_text:O(t.footer_text,x.footer_text),hide_attribution:Ie(t.hide_attribution),rev:Number.isFinite(Number(t.rev))?Number(t.rev):0}}const te=(()=>{const t=ee();return!!t&&typeof t.name=="string"&&t.name.trim()!==""})(),D={thin_content:{label:"Content Depth",icon:Ce,group:"content"},no_schema:{label:"Schema Markup",icon:Ae,group:"schema"},schema_errors:{label:"Schema Quality",icon:ve,group:"schema"},schema_warnings:{label:"Schema Fields",icon:qe,group:"schema"},faq_opportunity:{label:"FAQ Schema",icon:Me,group:"schema"},howto_opportunity:{label:"HowTo Schema",icon:Te,group:"schema"},no_meta_description:{label:"Meta Description",icon:Le,group:"aeo",fixType:"generate_meta_description",alwaysActionable:!0,passMsg:"Meta description exists. Re-write or optimize it specifically for AI engines."},aeo_title:{label:"AEO Title",icon:Pe,group:"aeo",fixType:"generate_aeo_titles",alwaysActionable:!0,passMsg:"AEO Title previously generated. You can generate 5 new options."},aeo_weak:{label:"AEO Readiness",icon:Oe,group:"aeo"},content_improvements:{label:"Content Improvements",icon:ze,group:"content",fixType:"suggest_content_improvements",alwaysActionable:!0},no_speakable:{label:"Speakable Summary",icon:Fe,group:"aeo"},no_llms_desc:{label:"llms.txt Entry",icon:Ne,group:"aeo"}},De={schema:"Schema",content:"Content",aeo:"AEO Signals"},Be=["content","schema","aeo"],He={add_article_schema:"Add Schema",add_faq_schema:"Add FAQ Schema",add_howto_schema:"Add HowTo Schema",generate_meta_description:"Generate Meta",generate_aeo_titles:"Generate Titles",analyze_citability:"Score Citability",suggest_content_improvements:"Analyze Content",generate_speakable_summary:"Generate Summary",generate_llms_description:"Generate Description"},se=new Set(["analyze_citability","suggest_content_improvements","generate_speakable_summary","generate_llms_description"]),ae={generate_meta_description:1,generate_aeo_titles:1,analyze_citability:1,suggest_content_improvements:1,generate_speakable_summary:1,generate_llms_description:1,add_howto_schema:1},ne={setup:{label:"Setup",tone:"amber",how:"Move setup to sentence 2. Lead with a concrete answer."},hedge:{label:"Hedge",tone:"amber",how:'Lead with a definite answer ("X is Y because Z."), then add nuance.'},filler:{label:"Filler",tone:"rose",how:"Cut the opener entirely. Answer the heading in sentence 1."},indirect:{label:"Could be more direct",tone:"sky",how:"The opener does answer this, but takes a roundabout path. Tighten to a single concrete claim that names the subject in sentence 1."},no_answer:{label:"No direct answer",tone:"rose",how:"Add a one-sentence direct answer as sentence 1 under this heading."}};let S=null,M=null;function re(t,p=!1){if(!p&&S&&S.postId===t&&S.score!=null)return Promise.resolve(S.score);if(!p&&M&&M.postId===t)return M.p;const _=w({path:`asgm/v1/editor-panel/${t}${p?"?force=1":""}`}).then(k=>{const b=k&&typeof k.aeo_score=="number"?k.aeo_score:null;return S={postId:t,score:b},b}).catch(()=>null).then(k=>(M&&M.p===_&&(M=null),k));return M={postId:t,p:_},_}function le(t,p){S={postId:t,score:p};try{window.dispatchEvent(new CustomEvent("asgm:score",{detail:{postId:t,score:p}}))}catch{}}const We=t=>t>=80?"#22c55e":t>=60?"#3b82f6":t>=40?"#f59e0b":"#ef4444";function je(){const[t,p]=e.useState(null),[_,k]=e.useState(!1),[b,v]=e.useState(null),[q,g]=e.useState({}),[m,f]=e.useState(null),[E,N]=e.useState({}),[F,Z]=e.useState(()=>new Set),Q=e.useRef(null),Ze=e.useCallback(s=>{Z(n=>{const a=new Set(n);return a.has(s)?a.delete(s):a.add(s),a})},[]),Qe=e.useCallback(s=>{Z(n=>{const a=new Set(n);return s.forEach(r=>a.add(r)),a})},[]),[$,oe]=e.useState(""),[ie,ce]=e.useState(!1),[B,Ue]=e.useState(null),[me,Ve]=e.useState(null),U=e.useRef(void 0),[c,Xe]=e.useState(null),[V,pe]=e.useState(!1),[de,A]=e.useState({}),h=z.useSelect(s=>{var n,a;return(a=(n=s("core/editor"))==null?void 0:n.getCurrentPostId)==null?void 0:a.call(n)},[]),{editPost:ue}=z.useDispatch("core/editor"),I=z.useDispatch("core/block-editor"),ge=s=>{if(!ue){alert("Editor store not ready");return}ue({title:s})},T=e.useCallback(async(s=!1)=>{if(h){k(!0);try{const n=await w({path:`asgm/v1/editor-panel/${h}${s?"?force=1":""}`});p(n),le(h,n&&typeof n.aeo_score=="number"?n.aeo_score:null),s&&Ve(new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}))}catch(n){console.error("ASGM Editor Panel:",n)}k(!1)}},[h]);e.useEffect(()=>{T()},[T]);const X=e.useCallback(async(s=!1)=>{if(!(!h||!asgmEditorPanel.isPro)){pe(!0);try{const n=await w({path:`aeo-god-mode/v1/answer-density/${h}${s?"?force=1":""}`});Xe(n)}catch(n){console.error("Answer Density:",n)}pe(!1)}},[h]);e.useEffect(()=>{X()},[X]);const he=async(s,n)=>{if(h){A(a=>({...a,[s]:{...a[s]||{},loading:!0,error:void 0}}));try{const a=await w({path:"aeo-god-mode/v1/answer-density/rewrite-opener",method:"POST",data:{post_id:h,heading:s,classification:n}});a!=null&&a.success?A(r=>({...r,[s]:{result:a.rewrite}})):A(r=>({...r,[s]:{error:(a==null?void 0:a.error)||"AI rewrite failed."}}))}catch(a){A(r=>({...r,[s]:{error:(a==null?void 0:a.message)||"AI rewrite failed."}}))}}},Ye=async s=>{if(!h)return;const n=de[s];if(n!=null&&n.result){A(a=>({...a,[s]:{...n,loading:!0}}));try{const a=await w({path:"aeo-god-mode/v1/answer-density/apply-rewrite",method:"POST",data:{post_id:h,heading:s,rewrite:n.result}});if(a!=null&&a.success){if(a.content)try{const r=window.wp.blocks.parse(a.content);I&&I.resetBlocks&&I.resetBlocks(r)}catch{}A(r=>({...r,[s]:{...n,applied:!0,loading:!1}}))}else A(r=>({...r,[s]:{...n,error:(a==null?void 0:a.error)||"Apply failed.",loading:!1}}))}catch(a){A(r=>({...r,[s]:{...n,error:(a==null?void 0:a.message)||"Apply failed.",loading:!1}}))}}},H=z.useSelect(s=>{var n,a,r,d;return((a=(n=s("core/editor"))==null?void 0:n.isSavingPost)==null?void 0:a.call(n))&&!((d=(r=s("core/editor"))==null?void 0:r.isAutosavingPost)!=null&&d.call(r))},[]);e.useEffect(()=>{if(U.current===!0&&H===!1&&t){const s=setTimeout(()=>T(!0),500);return U.current=H,()=>clearTimeout(s)}U.current=H},[H]);const Ke=async s=>{if(!(!h||b)){if(se.has(s)&&!asgmEditorPanel.isPro){g(n=>({...n,[s]:{success:!1,message:"Requires Pro or Agency license."}}));return}v(s);try{const n=await w({path:`asgm/v1/editor-panel/${h}/fix`,method:"POST",data:{fix_type:s}});if(n.success&&s==="generate_aeo_titles"&&n.result){const a={...n,titles:n.result.titles||[],recommended:n.result.recommended||""};g(r=>({...r,[s]:a}))}else g(a=>({...a,[s]:n}));await T(!0)}catch(n){g(a=>({...a,[s]:{success:!1,message:(n==null?void 0:n.message)||"Fix failed."}}))}v(null)}},Je=async(s,n)=>{if(!(!h||m!==null)){if(!asgmEditorPanel.isPro){N(a=>({...a,[n]:"Applying suggestions requires Pro or Agency."}));return}f(n);try{const a=await w({path:`asgm/v1/editor-panel/${h}/fix`,method:"POST",data:{fix_type:"apply_improvement",suggestion:s}});if(a.success&&a.matched&&a.applied_content)try{const r=window.wp.blocks.parse(a.applied_content);I&&I.resetBlocks&&I.resetBlocks(r),N(d=>({...d,[n]:"✓ "+(a.summary||"Applied")+". Review and Save to keep it."}))}catch{N(d=>({...d,[n]:"✓ Applied to the content. Reload the editor to see it."}))}else N(r=>({...r,[n]:a.message||"Could not apply this one automatically."}))}catch(a){N(r=>({...r,[n]:(a==null?void 0:a.message)||"Apply failed."}))}f(null)}},W=s=>s>=80?"#22c55e":s>=60?"#3b82f6":s>=40?"#f59e0b":"#ef4444",Re=new Set((t==null?void 0:t.applicable_checks)||Object.keys(D)),et=Object.keys(D).filter(s=>Re.has(s)),ye=new Set(((t==null?void 0:t.issues)||[]).map(s=>s.type)),tt=Object.fromEntries(((t==null?void 0:t.issues)||[]).map(s=>[s.type,s]));return e.createElement("div",{className:"asgm-editor-panel"},e.createElement("div",{className:"asgm-ep-score-header"},t?e.createElement(e.Fragment,null,e.createElement("div",{className:"asgm-ep-score-badge",style:{backgroundColor:W(t.aeo_score)}},e.createElement("span",{className:"asgm-ep-score-num"},t.aeo_score),e.createElement("span",{className:"asgm-ep-score-denom"},"/100")),e.createElement("div",{className:"asgm-ep-score-info"},e.createElement("span",{className:"asgm-ep-score-label"},"AEO Score"),t.gap_count===0?e.createElement("span",{className:"asgm-ep-score-detail asgm-ep-score-detail--clean"},"No issues found"):e.createElement("button",{type:"button",className:"asgm-ep-score-detail asgm-ep-score-detail--btn",onClick:()=>{const s=(t.issues||[]).map(n=>n.type);F.size>=s.length&&s.every(n=>F.has(n))?Z(new Set):(Qe(s),setTimeout(()=>{var a,r;(r=((a=Q.current)==null?void 0:a.querySelector(".asgm-ep-criterion.is-failed"))||Q.current)==null||r.scrollIntoView({behavior:"smooth",block:"center"})},60))},title:"Click to expand all failed checks"},t.gap_count," issue",t.gap_count>1?"s":""," found",e.createElement(xe,{size:12,strokeWidth:2,className:`asgm-ep-score-detail-chevron${(t.issues||[]).some(s=>F.has(s.type))?" is-open":""}`})),e.createElement("span",{className:"asgm-ep-word-count"},t.word_count," words",me&&e.createElement(e.Fragment,null," · Scanned ",me)))):_?e.createElement("div",{className:"asgm-ep-loading"},"Scanning..."):e.createElement("div",{className:"asgm-ep-loading"},"Waiting for post..."),e.createElement("button",{className:"asgm-ep-rescan",onClick:()=>T(!0),disabled:_,title:"Re-scan"},_?e.createElement(K,{size:14,strokeWidth:2,className:"asgm-ep-spin"}):e.createElement(R,{size:14,strokeWidth:2}))),t&&e.createElement("div",{className:"asgm-ep-score-bar-wrap"},e.createElement("div",{className:"asgm-ep-score-bar",style:{width:`${t.aeo_score}%`,backgroundColor:W(t.aeo_score)}})),t&&e.createElement("div",{className:"asgm-ep-criteria",ref:Q},Be.map(s=>{const n=et.filter(r=>D[r].group===s);if(n.length===0)return null;const a=n.filter(r=>ye.has(r)).length;return e.createElement("div",{key:s,className:"asgm-ep-group"},e.createElement("div",{className:"asgm-ep-group-header"},e.createElement("span",{className:"asgm-ep-group-label"},De[s]),a>0&&e.createElement("span",{className:"asgm-ep-group-count"},a," to fix")),n.map(r=>{const d=D[r],o=d.icon,P=ye.has(r),L=tt[r],fe=F.has(r),Y=P&&L?L.fix_type:d.fixType,l=Y?q[Y]:null;return e.createElement("div",{key:r,className:`asgm-ep-criterion ${P?"is-failed":"is-passed"} ${fe?"is-expanded":""}`},e.createElement("button",{className:"asgm-ep-criterion-header",onClick:()=>Ze(r)},e.createElement(o,{className:"asgm-ep-criterion-icon",size:16,strokeWidth:1.75}),e.createElement("span",{className:"asgm-ep-criterion-label"},d.label),e.createElement("span",{className:`asgm-ep-criterion-status ${P?"status-fail":"status-pass"}`},P?e.createElement($e,{size:14,strokeWidth:2.5}):e.createElement(Se,{size:14,strokeWidth:2.5}))),fe&&e.createElement("div",{className:"asgm-ep-criterion-body"},P&&L?e.createElement("p",{className:"asgm-ep-issue-msg"},L.message):e.createElement("p",{className:"asgm-ep-pass-msg"},d.passMsg?d.passMsg:d.alwaysActionable?"No issues detected, but you can still run AI generation.":"No issues detected."),(P&&(L==null?void 0:L.fix_type)||!P&&d.alwaysActionable&&d.fixType)&&(()=>{const C=Y;return e.createElement("div",{className:"asgm-ep-fix-row"},l!=null&&l.success?e.createElement("div",{className:"asgm-ep-fix-detail"},e.createElement("span",{className:"asgm-ep-fix-success"},["analyze_citability","suggest_content_improvements"].includes(l.fix_type)?"✓ Analyzed":"✓ Applied"),e.createElement("p",{className:"asgm-ep-fix-summary"},l.fix_type==="add_faq_schema"&&e.createElement("div",{className:"asgm-ep-faq-preview"},e.createElement("strong",null,l.faq_count||0," FAQ pair",(l.faq_count||0)!==1?"s":""," (",l.source==="ai"?"AI extracted":"pattern matched",")"),l.faq_pairs&&l.faq_pairs.length>0&&e.createElement("ul",{className:"asgm-ep-faq-list"},l.faq_pairs.map((i,y)=>e.createElement("li",{key:y,className:`asgm-ep-faq-item ${B===y?"is-open":""}`},e.createElement("button",{className:"asgm-ep-faq-q",onClick:()=>Ue(B===y?null:y)},e.createElement("span",{className:"asgm-ep-faq-q-icon"},"Q"),e.createElement("span",{className:"asgm-ep-faq-q-text"},i.question),e.createElement("span",{className:"asgm-ep-faq-toggle"},B===y?"▾":"▸")),B===y&&e.createElement("div",{className:"asgm-ep-faq-a"},e.createElement("span",{className:"asgm-ep-faq-a-icon"},"A"),e.createElement("span",{className:"asgm-ep-faq-a-text"},i.answer)))))),l.fix_type==="add_howto_schema"&&e.createElement(e.Fragment,null,"Added HowTo schema with ",l.step_count||0," step",(l.step_count||0)!==1?"s":""),l.fix_type==="add_article_schema"&&e.createElement(e.Fragment,null,"Article schema applied"),l.fix_type==="generate_meta_description"&&l.meta_description&&e.createElement("div",{className:"asgm-ep-meta-edit"},e.createElement("textarea",{className:"asgm-ep-meta-textarea",value:$||l.meta_description,onChange:i=>oe(i.target.value),rows:3,maxLength:160}),e.createElement("div",{className:"asgm-ep-meta-footer"},e.createElement("span",{className:"asgm-ep-meta-count"},($||l.meta_description).length,"/160"),$&&$!==l.meta_description&&e.createElement("button",{className:"asgm-ep-meta-save",disabled:ie,onClick:async()=>{ce(!0);try{await w({path:`asgm/v1/editor-panel/${h}/fix`,method:"POST",data:{fix_type:"save_meta_description",meta_description:$}}),g(i=>({...i,generate_meta_description:{...i.generate_meta_description,meta_description:$}})),oe("")}catch(i){console.error("Save meta failed:",i)}ce(!1)}},ie?"⏳":"💾 Save"))),l.fix_type==="generate_aeo_titles"&&l.titles&&e.createElement("div",{className:"asgm-ep-titles-results"},l.recommended&&e.createElement("div",{className:"asgm-ep-recommended-title"},e.createElement("h4",{style:{margin:"0 0 5px 0",fontSize:"12px",color:"#8b5cf6"}},"★ RECOMMENDED"),e.createElement("p",{style:{margin:"0 0 10px 0",fontWeight:"bold"}},l.recommended),e.createElement("button",{className:"asgm-ep-fix-save-btn",onClick:async()=>{ge(l.recommended),await w({path:`asgm/v1/editor-panel/${h}/fix`,method:"POST",data:{fix_type:"save_post_title",post_title:l.recommended}}),T(!0)}},"Apply Recommended Title")),l.titles.length>0&&e.createElement("div",{className:"asgm-ep-other-titles",style:{marginTop:"15px"}},e.createElement("h4",{style:{fontSize:"13px",borderBottom:"1px solid rgba(255,255,255,0.1)",paddingBottom:"5px",marginBottom:"10px"}},"All Options"),l.titles.map((i,y)=>e.createElement("div",{key:y,className:"asgm-ep-title-card",style:{backgroundColor:"rgba(255,255,255,0.03)",padding:"10px",borderRadius:"6px",marginBottom:"10px",textAlign:"left"}},e.createElement("p",{style:{margin:"0 0 5px 0",fontSize:"13px",fontWeight:"bold"}},i.title),e.createElement("div",{style:{fontSize:"11px",color:"#9ca3af",marginBottom:"8px",lineHeight:"1.4"}},i.characters&&e.createElement("span",null,e.createElement("strong",null,"Length:")," ",i.characters,e.createElement("br",null)),i.format&&e.createElement("span",null,e.createElement("strong",null,"Format:")," ",i.format,e.createElement("br",null)),i.strength&&e.createElement("span",null,e.createElement("strong",null,"AI Citation:")," ",i.strength,e.createElement("br",null)),i.seoNote&&e.createElement("span",null,e.createElement("strong",null,"SEO:")," ",i.seoNote)),e.createElement("button",{className:"asgm-ep-fix-btn",style:{fontSize:"11px",padding:"4px 8px"},onClick:async()=>{ge(i.title),await w({path:`asgm/v1/editor-panel/${h}/fix`,method:"POST",data:{fix_type:"save_post_title",post_title:i.title}}),T(!0)}},"Apply"))))),l.fix_type==="analyze_citability"&&e.createElement(e.Fragment,null,"Citability score: ",l.score,"/100",l.top_improvement?`. Top improvement: ${l.top_improvement}`:""),l.fix_type==="suggest_content_improvements"&&e.createElement(e.Fragment,null,e.createElement("strong",null,l.count||0," improvement",(l.count||0)!==1?"s":""," (Grade: ",l.grade||"N/A",")"),l.improvements&&l.improvements.length>0&&e.createElement("ul",{className:"asgm-ep-improvements-list"},l.improvements.map((i,y)=>{const _e=String(i.suggestion||i.text||i).replace(/^[\s-]*\s*/,"");return e.createElement("li",{key:y,className:"asgm-ep-improvement-item"},e.createElement("span",{className:"asgm-ep-imp-category"},i.category||"General"),e.createElement("span",{className:"asgm-ep-imp-text"},_e),E[y]?e.createElement("span",{className:"asgm-ep-imp-applied"},E[y]):e.createElement("button",{type:"button",className:"asgm-ep-imp-apply",disabled:m!==null,onClick:()=>Je(_e,y)},m===y?"Applying…":"Apply (1 credit)"))}))),l.fix_type==="generate_speakable_summary"&&e.createElement(e.Fragment,null,"Speakable summary generated"),l.fix_type==="generate_llms_description"&&e.createElement(e.Fragment,null,"llms.txt description generated")),e.createElement("div",{className:"asgm-ep-fix-actions"},e.createElement("button",{className:"asgm-ep-fix-undo",onClick:()=>{g(i=>{const y={...i};return delete y[C],y})}},["analyze_citability","suggest_content_improvements","generate_aeo_titles"].includes(l.fix_type)?"↩ Re-analyze":"↩ Re-run"))):e.createElement("button",{className:"asgm-ep-fix-btn",onClick:()=>Ke(C),disabled:b===C},b===C?"⏳ Working...":e.createElement(e.Fragment,null,"⚡ ",He[C]||"Auto Fix",se.has(C)&&e.createElement("span",{className:"asgm-ep-pro-tag"},"Pro"),ae[C]&&e.createElement("span",{className:"asgm-ep-credit-tag"},ae[C]," credit"))),l&&!l.success&&e.createElement("span",{className:"asgm-ep-fix-error"},l.message))})()))}))})),asgmEditorPanel.isPro?e.createElement("div",{className:"asgm-ep-section asgm-ep-ad"},e.createElement("div",{className:"asgm-ep-score-header asgm-ep-ad-header"},e.createElement("div",{className:"asgm-ep-score-badge",style:{backgroundColor:W((c==null?void 0:c.answer_density_score)||0)}},e.createElement("span",{className:"asgm-ep-score-num"},c?c.answer_density_score??0:"–"),e.createElement("span",{className:"asgm-ep-score-denom"},"/100")),e.createElement("div",{className:"asgm-ep-score-info"},e.createElement("span",{className:"asgm-ep-score-label"},e.createElement(J,{size:11,strokeWidth:2,className:"asgm-ep-ad-label-icon"}),"Answer Density"),e.createElement("span",{className:"asgm-ep-score-detail asgm-ep-score-detail--clean"},c?c.question_headings===0?"No question-shaped headings":`${c.direct_answers??0} of ${c.question_headings} headings lead with a direct answer`:V?"Checking…":"Check to score this post"),e.createElement("span",{className:"asgm-ep-word-count"},c?c.question_headings===0?"Add H2/H3 phrased as questions to start scoring":`${c.buried_answers??0} buried · ${c.word_count??0} words`:"")),e.createElement("button",{className:"asgm-ep-rescan",onClick:()=>X(!0),disabled:V,title:"Check Answer Density now"},V?e.createElement(K,{size:14,strokeWidth:2,className:"asgm-ep-spin"}):e.createElement(R,{size:14,strokeWidth:2}))),c&&e.createElement("div",{className:"asgm-ep-score-bar-wrap"},e.createElement("div",{className:"asgm-ep-score-bar",style:{width:`${c.answer_density_score??0}%`,backgroundColor:W(c.answer_density_score||0)}})),c&&Array.isArray(c.issues)&&c.issues.length>0&&e.createElement("div",{className:"asgm-ep-ad-issues"},c.issues.slice(0,5).map((s,n)=>{const a=s.opener_kind||(s.issue==="no_direct_answer"?"no_answer":"setup"),r=ne[a]||ne.setup,d=(s.first_sentence||"").slice(0,120),o=de[s.heading];return e.createElement("div",{key:n,className:`asgm-ep-ad-issue is-${r.tone}`},e.createElement("div",{className:"asgm-ep-ad-issue-head"},e.createElement("span",{className:`asgm-ep-ad-tag is-${r.tone}`},r.label),e.createElement("span",{className:"asgm-ep-ad-heading"},'"',s.heading,'"')),d&&e.createElement("p",{className:"asgm-ep-ad-opener"},'"',d,d.length>=120?"…":"",'"'),e.createElement("p",{className:"asgm-ep-ad-fix"},e.createElement("strong",null,"Fix →")," ",r.how),(o==null?void 0:o.error)&&e.createElement("p",{className:"asgm-ep-ad-error"},o.error),(o==null?void 0:o.result)&&!o.applied&&e.createElement("div",{className:"asgm-ep-ad-suggest"},e.createElement("div",{className:"asgm-ep-ad-suggest-label"},"Suggested opener"),e.createElement("p",{className:"asgm-ep-ad-suggest-text"},o.result),e.createElement("div",{className:"asgm-ep-ad-suggest-actions"},e.createElement("button",{className:"asgm-ep-ad-btn is-primary",onClick:()=>Ye(s.heading),disabled:o.loading},o.loading?"Applying…":"Apply to post"),e.createElement("button",{className:"asgm-ep-ad-btn",onClick:()=>he(s.heading,a),disabled:o.loading},"Regenerate"))),(o==null?void 0:o.applied)&&e.createElement("p",{className:"asgm-ep-ad-applied"},"✓ Applied. Review and Save to keep it."),!(o!=null&&o.result)&&!(o!=null&&o.applied)&&e.createElement("button",{className:"asgm-ep-ad-btn is-primary",onClick:()=>he(s.heading,a),disabled:o==null?void 0:o.loading},o!=null&&o.loading?"Drafting…":"✨ AI Rewrite (1 credit)"))}),c.issues.length>5&&e.createElement("p",{className:"asgm-ep-ad-more"},"+ ",c.issues.length-5," more headings need attention")),c&&c.question_headings>0&&(!c.issues||c.issues.length===0)&&e.createElement("p",{className:"asgm-ep-ad-allgood"},"✓ Every question heading on this post leads with a direct answer.")):e.createElement("div",{className:"asgm-ep-section asgm-ep-ad asgm-ep-ad-locked"},e.createElement("div",{className:"asgm-ep-ad-lock-head"},e.createElement(J,{size:13,strokeWidth:2}),e.createElement("span",null,"Answer Density"),e.createElement("span",{className:"asgm-ep-pro-tag"},"Pro")),e.createElement("p",{className:"asgm-ep-ad-lock-desc"},"Scores whether each question heading answers in sentence 1, and AI-rewrites the openers that bury it."),(!te||j().account_url!=="")&&e.createElement("a",{className:"asgm-ep-ad-btn is-pro asgm-ep-ad-lock-btn",href:te?j().account_url:"https://aeogodmode.io/pricing/",target:"_blank",rel:"noopener noreferrer"},"👑 Unlock with Pro")))}const G=()=>e.createElement("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2"},e.createElement("path",{d:"M13 2L3 14h9l-1 8 10-12h-9l1-8z"})),Ge=()=>{const t=z.useSelect(g=>{var m,f;return(f=(m=g("core/editor"))==null?void 0:m.getCurrentPostId)==null?void 0:f.call(m)},[]),[p,_]=e.useState(()=>S&&S.postId===t?S.score:null),[k,b]=e.useState(!1);e.useEffect(()=>{let g=!0;b(!1),t&&re(t).then(f=>{g&&(_(f),b(!0))});const m=f=>{const E=f==null?void 0:f.detail;E&&E.postId===t&&_(typeof E.score=="number"?E.score:null)};return window.addEventListener("asgm:score",m),()=>{g=!1,window.removeEventListener("asgm:score",m)}},[t]);const v=z.useSelect(g=>{var m,f,E,N;return((f=(m=g("core/editor"))==null?void 0:m.isSavingPost)==null?void 0:f.call(m))&&!((N=(E=g("core/editor"))==null?void 0:E.isAutosavingPost)!=null&&N.call(E))},[]),q=e.useRef(void 0);return e.useEffect(()=>{if(q.current===!0&&v===!1&&t){const g=setTimeout(()=>re(t,!0).then(m=>{le(t,m)}),600);return q.current=v,()=>clearTimeout(g)}q.current=v},[v,t]),p==null?e.createElement("span",{className:"asgm-score-pill is-loading","aria-label":"AEO Score"},e.createElement(G,null),!k&&e.createElement("span",{className:"asgm-score-pill__num"},"··")):e.createElement("span",{className:"asgm-score-pill",style:{"--asgm-pill":We(p)},"aria-label":`AEO Score ${p} of 100`},e.createElement(G,null),e.createElement("span",{className:"asgm-score-pill__num"},p),e.createElement("span",{className:"asgm-score-pill__denom"},"/100"))};Ee.registerPlugin("asgm-editor-panel",{icon:G,render:()=>e.createElement(e.Fragment,null,e.createElement(be.PluginSidebar,{name:"asgm-aeo-panel",title:j().name,icon:e.createElement(Ge,null)},e.createElement(je,null)))})})(React,wp.plugins,wp.editPost,wp.data,wp.apiFetch);
