Plugin Directory

Changeset 3365400


Ignore:
Timestamp:
09/21/2025 07:15:22 PM (5 months ago)
Author:
navarroido
Message:

Deploy version 2.0.2

Location:
llmagnet-llm-txt-generator
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • llmagnet-llm-txt-generator/tags/2.0.2/assets/react-build/js/dashboard.js

    r3364798 r3365400  
    1 import{r as x,R as U,j as e,B as z,g as oe}from"./index-b15a82cd.js";import{L as W,I as K}from"./input-647e65c0.js";const ie=()=>({toast:({title:t,description:L,variant:D})=>{alert(D==="destructive"?`Error: ${t}
     1import{r as u,R as G,j as e,B as V,g as de}from"./index-b15a82cd.js";import{L as F,I as te}from"./input-647e65c0.js";const ce=()=>({toast:({title:t,description:L,variant:S})=>{alert(S==="destructive"?`Error: ${t}
    22${L}`:`${t}
    3 ${L}`)}});function de({currentImages:t,onImagesChange:L,isPremium:D}){const{toast:w}=ie(),[g,E]=x.useState(!1),[T,S]=x.useState({});U.useEffect(()=>{const n=async()=>{for(const d of t)if(!T[d.id]){const a=wp.media.attachment(d.id);a.fetch().then(()=>{var k,b;const u={id:d.id,url:a.get("url"),preview_url:((b=(k=a.get("sizes"))==null?void 0:k.medium)==null?void 0:b.url)||a.get("url"),width:a.get("width"),height:a.get("height")};S(v=>({...v,[d.id]:u}))})}};t.length>0&&n()},[t]);const M=async n=>{var a,u,k,b;const d=(a=n.target.files)==null?void 0:a[0];if(d){if(!d.type.startsWith("image/")){w({title:"Error",description:"Please select an image file.",variant:"destructive"});return}E(!0);try{const v=new FormData;v.append("action","llmagnet_ai_seo_upload_image"),v.append("nonce",((u=window.llmagnetDashboardData)==null?void 0:u.nonce)||""),v.append("image",d);const $=await(await fetch(((k=window.llmagnetDashboardData)==null?void 0:k.ajaxUrl)||"/wp-admin/admin-ajax.php",{method:"POST",body:v,credentials:"same-origin"})).json();if($.success){const P={id:$.data.attachment_id,position:"after"},I=[...t,P];L(I),S(G=>({...G,[$.data.attachment_id]:$.data})),w({title:"Success",description:"Image uploaded successfully!"})}else w({title:"Upload Error",description:((b=$.data)==null?void 0:b.message)||"Failed to upload image.",variant:"destructive"})}catch(v){console.error("Upload error:",v),w({title:"Upload Error",description:"An error occurred while uploading the image.",variant:"destructive"})}finally{E(!1),n.target.value=""}}},y=()=>{if(typeof wp<"u"&&wp.media){const n=wp.media({title:"Select LLM Response Images",button:{text:"Select Images"},multiple:!0});n.on("select",()=>{const d=n.state().get("selection").toJSON(),a=[],u={};d.forEach(b=>{var v,R;a.push({id:b.id,position:"after"}),u[b.id]={id:b.id,url:b.url,preview_url:((R=(v=b.sizes)==null?void 0:v.medium)==null?void 0:R.url)||b.url,width:b.width,height:b.height}});const k=[...t,...a];L(k),S(b=>({...b,...u})),w({title:"Success",description:`${d.length} image(s) selected successfully!`})}),n.open()}},j=n=>{const d=t.filter(a=>a.id!==n);L(d),S(a=>{const u={...a};return delete u[n],u}),w({title:"Success",description:"Image removed successfully!"})},i=(n,d)=>{const a=t.map(u=>u.id===n?{...u,position:d}:u);L(a)};return D?e.jsxs("div",{className:"space-y-6",children:[t.length>0&&e.jsxs("div",{className:"mb-6 space-y-4",children:[e.jsxs("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:["Current Images (",t.length,")"]}),t.map((n,d)=>{const a=T[n.id];return e.jsxs("div",{className:"flex items-start gap-4 p-4 bg-gradient-to-r from-gray-50 to-gray-100/50 rounded-xl border border-gray-200/60 hover:shadow-md transition-all duration-200",children:[a&&e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:a.preview_url,alt:`LLM Response Image ${d+1}`,className:"w-24 h-24 object-cover rounded-lg border-2 border-white shadow-sm"}),e.jsx("div",{className:"absolute -top-1 -right-1 bg-blue-500 text-white text-xs font-medium px-1.5 py-0.5 rounded-full",children:d+1})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsxs("h6",{className:"font-semibold text-gray-900 mb-1",children:["Image ",d+1]}),a&&e.jsxs("div",{className:"text-sm text-gray-600 bg-white px-2 py-1 rounded-md inline-block",children:[a.width," × ",a.height,"px"]})]}),e.jsx(z,{onClick:()=>j(n.id),variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200",children:"Remove"})]}),e.jsxs("div",{className:"bg-white p-3 rounded-lg border border-gray-200/60",children:[e.jsx(W,{className:"text-sm font-semibold text-gray-700 mb-2 block",children:"Display Position"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${n.id}`,value:"before",checked:n.position==="before",onChange:()=>i(n.id,"before"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Before text"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${n.id}`,value:"after",checked:n.position==="after",onChange:()=>i(n.id,"after"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"After text"})]})]})]})]})]},n.id)})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Add New Images"}),e.jsx("div",{className:"flex items-center gap-4 p-3 rounded-xl bg-white/60",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(z,{onClick:y,variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:g,children:"Select from Media Library"}),e.jsxs("div",{className:"relative",children:[e.jsx(K,{type:"file",accept:"image/*",onChange:M,disabled:g,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"}),e.jsx(z,{variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:g,children:g?"Uploading...":"Upload New Image"})]})]})}),e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"You can select multiple images from the media library or upload them one by one."})]})]}):e.jsxs("div",{className:"bg-gray-50 border border-gray-200 rounded-md p-4",children:[e.jsx("h4",{className:"font-medium mb-2 text-gray-700",children:"LLM Response Images (Premium Feature)"}),e.jsx("p",{className:"text-sm text-gray-600 mb-3",children:"Attach multiple images that will be displayed with responses from all Large Language Models (ChatGPT, Claude, Gemini, GPT-4, etc.) and included in the llms.txt file."}),e.jsxs("div",{className:"bg-yellow-50 border border-yellow-200 text-yellow-800 p-3 rounded-md text-sm",children:[e.jsx("strong",{children:"Premium Feature:"})," This feature is available for premium users only. Upgrade to attach multiple images to your LLM responses."]})]})}function ce({apiRoot:t,apiNamespace:L,isPremium:D=!1}){const[w,g]=x.useState(!0),[E,T]=x.useState(null),[S,M]=x.useState([]),[y,j]=x.useState([]),[i,n]=x.useState("7days"),[d,a]=x.useState(!1),[u,k]=x.useState(null),[b,v]=x.useState(""),[R,$]=x.useState(!1),[P,I]=x.useState(null),G=x.useRef(null),o=x.useRef(null),N=x.useRef(new Map),f=x.useRef(new Map),X=Object.entries({ChatGPT:"openai.com",Claude:"anthropic.com",Bard:"google.com",Bing:"microsoft.com",Perplexity:"perplexity.ai",Cohere:"cohere.ai",Llama:"meta.com",Mistral:"mistral.ai","Other LLM":"ai.com"}).reduce((s,[r,c])=>(s[r]=`https://img.logo.dev/${c}?token=pk_LWY53QLNRjW3a2uzvqdwPg`,s),{}),V={ChatGPT:"#10a37f",Claude:"#6f42c1",Bard:"#4285f4",Bing:"#00a4ef",Perplexity:"#5436da",Cohere:"#ff0080",Llama:"#0668e1",Mistral:"#007bff","Other LLM":"#ff9800"},J="https://img.logo.dev/ai.com?token=pk_LWY53QLNRjW3a2uzvqdwPg",ee=()=>window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"||window.location.hostname.includes(".local")||window.location.hostname.includes(".test"),te=()=>{const s=[],r=new Date;for(let p=29;p>=0;p--){const l=new Date(r);l.setDate(r.getDate()-p),s.push(l.toISOString().split("T")[0])}const c=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"],h=[];return c.forEach(p=>{s.forEach(l=>{h.push({bot_name:p,date:l,visits:0})})}),h},se=()=>{const s=[],r=new Date;for(let l=29;l>=0;l--){const _=new Date(r);_.setDate(r.getDate()-l),s.push(_.toISOString().split("T")[0])}const c=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"],h=[],p=ee();return c.forEach(l=>{if(p){let _=l==="ChatGPT"?10:l==="Claude"?8:l==="Bard"?7:l==="Bing"?5:l==="Perplexity"?4:l==="Cohere"?3:l==="Llama"||l==="Mistral"?2:1;s.forEach((O,C)=>{const m=new Date(O).getDay(),A=m===0||m===6?.6:1,F=1+C*.01,Q=.7+Math.random()*.6;let B=Math.round(_*A*F*Q);B=Math.max(1,B),Math.random()<.1&&(B=Math.round(B*(1.5+Math.random()))),h.push({bot_name:l,date:O,visits:B})})}else{const _=l==="ChatGPT"?8:l==="Claude"?6:l==="Bard"?5:l==="Bing"?4:l==="Other LLM"?2:3;s.forEach(O=>{const C=Math.floor(Math.random()*(_+1));h.push({bot_name:l,date:O,visits:C})})}}),h};x.useEffect(()=>{D&&(async()=>{var r;try{const c=await fetch(`${t}llm-analytics/v1/report-email`,{headers:{"X-WP-Nonce":((r=window.wpApiSettings)==null?void 0:r.nonce)||""}});if(!c.ok){console.error(`Error fetching report email: ${c.status}`);return}const h=await c.json();h.email&&v(h.email)}catch(c){console.error("Error fetching report email:",c)}})()},[D,t]);const ae=async()=>{var s;if(!R){$(!0),I(null);try{const r=await fetch(`${t}llm-analytics/v1/report-email`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((s=window.wpApiSettings)==null?void 0:s.nonce)||""},body:JSON.stringify({email:b})});if(!r.ok)throw new Error(`Error: ${r.status}`);const c=await r.json();c.success?I({type:"success",text:"Report email address saved successfully."}):I({type:"error",text:c.message||"Failed to save email address."})}catch(r){console.error("Error saving report email:",r),I({type:"error",text:"Failed to save email address. Please try again."})}finally{$(!1),(P==null?void 0:P.type)==="success"&&setTimeout(()=>{I(null)},3e3)}}};x.useEffect(()=>{if(D){const s=async()=>{var c;try{const h=await fetch(`${t}${L}/stats`,{headers:{"X-WP-Nonce":((c=window.wpApiSettings)==null?void 0:c.nonce)||""}});if(!h.ok){console.error(`API error: ${h.status}`),r();return}const l=await h.json();if(!l||!Array.isArray(l)||l.length===0){console.log("No analytics data available, using empty data"),r();return}M(l);const _={};l.forEach(m=>{_[m.bot_name]||(_[m.bot_name]=0),_[m.bot_name]+=m.visits});const C=Array.from(new Set(l.map(m=>m.bot_name))).sort().map(m=>({bot_name:m,total_visits:_[m]||0,logo:X[m]||J}));j(C),g(!1)}catch(h){console.error("Error fetching analytics data:",h),r()}},r=()=>{const c=te();M(c);const p=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"].map(l=>({bot_name:l,total_visits:0,logo:X[l]||J}));j(p),g(!1),T(null)};s()}else{const s=se();M(s);const r={};s.forEach(p=>{r[p.bot_name]||(r[p.bot_name]=0),r[p.bot_name]+=p.visits});const h=Array.from(new Set(s.map(p=>p.bot_name))).sort().map(p=>({bot_name:p,total_visits:r[p]||0,logo:X[p]||J}));j(h),g(!1)}},[D,t,L]),x.useEffect(()=>{!w&&G.current&&(console.log("Time range changed, re-rendering main chart"),q())},[i]);const q=()=>{const s=document.getElementById("main-chart");if(!s){console.error("Main chart canvas not found");return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly");return}console.log("Rendering main chart"),o.current&&o.current.destroy();const r=new Date,c=i==="7days"?7:30,h=new Date(r);h.setDate(r.getDate()-c+1);const p=[];for(let m=0;m<c;m++){const A=new Date(h);A.setDate(h.getDate()+m),p.push(A.toISOString().split("T")[0])}const l=p[0],_=S.filter(m=>m.date>=l),C=Array.from(new Set(S.map(m=>m.bot_name))).sort().map(m=>{const A=p.map(F=>_.filter(B=>B.date===F&&B.bot_name===m).reduce((B,le)=>B+le.visits,0));return{label:m,data:A,backgroundColor:V[m]||"#999",borderColor:V[m]||"#999",borderWidth:1.5,tension:.3,fill:!1,pointRadius:2}});o.current=new window.Chart(s,{type:"line",data:{labels:p,datasets:C},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{boxWidth:12,font:{size:10}}},tooltip:{mode:"index",intersect:!1}},scales:{y:{beginAtZero:!0,ticks:{precision:0},grid:{color:"rgba(0, 0, 0, 0.05)"}},x:{ticks:{maxRotation:0,autoSkip:!0,maxTicksLimit:i==="7days"?7:10,font:{size:9}},grid:{display:!1}}},animation:{duration:1e3}}})},re=s=>{const r=N.current.get(s);if(!r){console.error(`Canvas for ${s} not available`);return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly for bot charts");return}console.log(`Rendering chart for ${s}`),f.current.get(s)&&f.current.get(s).destroy();const c=new Date,h=[];for(let C=6;C>=0;C--){const m=new Date(c);m.setDate(c.getDate()-C),h.push(m.toISOString().split("T")[0])}const p=h[0],l=S.filter(C=>C.bot_name===s&&C.date>=p),_=h.map(C=>l.filter(A=>A.date===C).reduce((A,F)=>A+F.visits,0)),O=Math.max(..._);f.current.set(s,new window.Chart(r,{type:"line",data:{labels:h,datasets:[{label:s,data:_,backgroundColor:V[s]||"#999",borderColor:V[s]||"#999",borderWidth:1.5,tension:.3,pointRadius:0,fill:!1}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},scales:{y:{display:!1,beginAtZero:!0,min:0,max:O===0?1:void 0,grid:{display:!1}},x:{display:!1,grid:{display:!1}}},elements:{point:{radius:0},line:{borderWidth:1.5}},animation:{duration:800}}}))},ne=async()=>{var s;if(!d){a(!0),k(null);try{const r=await fetch(`${t}llm-analytics/v1/send-report`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((s=window.wpApiSettings)==null?void 0:s.nonce)||""}});if(!r.ok)throw new Error(`Error: ${r.status}`);const c=await r.json();c.success?k({type:"success",text:"Analytics report has been sent to your email."}):k({type:"error",text:c.message||"Failed to send analytics report."})}catch(r){console.error("Error sending report:",r),k({type:"error",text:"Failed to send analytics report. Please try again later."})}finally{a(!1),(u==null?void 0:u.type)==="success"&&setTimeout(()=>{k(null)},5e3)}}};x.useEffect(()=>{if(!w&&y.length>0)if(console.log("Attempting to render charts..."),typeof window.Chart>"u"){console.log("Chart.js not found, loading it directly");const s=document.createElement("script");s.src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js",s.async=!0,s.onload=()=>{console.log("Chart.js loaded successfully"),H()},document.head.appendChild(s)}else console.log("Chart.js found, rendering charts"),setTimeout(H,300)},[w,y]);const H=()=>{console.log("Rendering all charts now"),document.getElementById("main-chart")?q():console.error("Main chart canvas not found"),y.forEach(r=>{const c=document.getElementById(`bot-chart-${r.bot_name}`);c?(N.current.set(r.bot_name,c),re(r.bot_name)):console.error(`Canvas element for ${r.bot_name} not found`)})};return e.jsxs("div",{className:"analytics-dashboard-summary",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"LLM Bot Analytics Summary"}),w?e.jsx("div",{className:"p-4",children:"Loading analytics data..."}):E?e.jsx("div",{className:"p-4 text-red-600",children:e.jsx("p",{children:E})}):e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"bg-white p-4 rounded-lg shadow border border-gray-200 mb-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h4",{className:"font-medium",children:"Bot Visits Over Time"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(W,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"7days",checked:i==="7days",onChange:()=>n("7days"),className:"mr-1"}),"Last 7 days"]}),e.jsxs(W,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"30days",checked:i==="30days",onChange:()=>n("30days"),className:"mr-1"}),"Last 30 days"]})]})]}),e.jsx("div",{className:"h-64",children:e.jsx("canvas",{id:"main-chart",height:"300"})})]}),e.jsx("div",{className:"bot-summaries grid grid-cols-1 md:grid-cols-3 gap-4",children:y.map(s=>e.jsxs("div",{className:"overflow-hidden bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsxs("div",{className:"flex items-center mb-2",children:[e.jsx("div",{className:"bot-logo mr-3 bg-white rounded-full p-1 shadow-sm border border-gray-100",children:e.jsx("img",{src:s.logo,alt:`${s.bot_name} logo`,className:"h-10 w-10 object-contain rounded-full",onError:r=>{r.target.src=J,console.log(`Failed to load logo for ${s.bot_name}, using default`)},loading:"lazy"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",children:s.bot_name}),e.jsxs("p",{className:"text-sm text-gray-500",children:["Total visits: ",s.total_visits]})]})]}),e.jsx("div",{className:"h-24 mt-4 border-t pt-2 border-gray-100",children:e.jsx("canvas",{id:`bot-chart-${s.bot_name}`,height:"80"})})]},s.bot_name))}),!D&&e.jsx("div",{className:"absolute inset-0 bg-white/60 backdrop-blur-sm flex flex-col items-center justify-center z-10",style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.6)",backdropFilter:"blur(4px)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10},children:e.jsxs("div",{className:"text-center p-6 max-w-md bg-white rounded-lg shadow-lg",children:[e.jsx("h3",{className:"text-xl font-bold mb-2",children:"Premium Feature"}),e.jsx("p",{className:"mb-4",children:"Access to real analytics data is available in the premium version."}),e.jsx("a",{href:"admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"inline-block px-6 py-3 bg-gradient-to-r from-purple-600 to-pink-600 text-white rounded-lg font-medium shadow-lg hover:from-purple-700 hover:to-pink-700 transition-all",children:"Upgrade Now"})]})})]}),D&&e.jsxs("div",{className:"mt-6 bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Analytics Reports"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Report Email Address"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{id:"report-email",type:"email",value:b,onChange:s=>v(s.target.value),className:"flex-1 px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm",placeholder:"[email protected]"}),e.jsx("button",{onClick:ae,disabled:R,className:"inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500",children:R?"Saving...":"Save"})]}),P&&e.jsx("p",{className:`mt-1 text-xs ${P.type==="success"?"text-green-600":"text-red-600"}`,children:P.text})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{onClick:ne,disabled:d,className:`inline-block px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors ${d?"opacity-70 cursor-not-allowed":""}`,children:d?"Sending...":"Send Analytics Report Now"}),u&&e.jsx("div",{className:`mt-2 p-2 rounded text-sm ${u.type==="success"?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:u.text})]})]})]})]})}function me({data:t,onGenerateNow:L,onImagesChange:D,onSettingsChange:w}){var P,I,G;console.log("Dashboard Data:",{rootPath:t.rootPath,isWritable:t.isWritable,lastGenerated:t.lastGenerated,llmsTxtExists:t.llmsTxtExists,llmsTxtUrl:t.llmsTxtUrl,llmsTxtSize:t.llmsTxtSize,postsCount:t.postsCount,markdownCount:t.markdownCount,settings:t.settings,postTypes:t.postTypes,isPremium:t.isPremium,planData:t.planData,imageData:t.imageData,pluginVersion:t.pluginVersion,wordpressVersion:t.wordpressVersion});const[g,E]=x.useState(!1),[T,S]=x.useState(null),[M,y]=x.useState(t.settings.llm_response_images||[]),[j,i]=x.useState(!1),n=U.useRef(null),d=t.planData.plan_name==="free"?t.settings.post_types.filter(o=>o==="post"||o==="page"):t.settings.post_types,[a,u]=x.useState({post_types:d,full_content:t.settings.full_content,days_to_include:t.settings.days_to_include,delete_on_uninstall:t.settings.delete_on_uninstall});U.useEffect(()=>{function o(N){n.current&&!n.current.contains(N.target)&&i(!1)}return document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o)}},[]);const k=async()=>{E(!0),S(null);try{const o=await L();S({type:o.success?"success":"error",text:o.message}),setTimeout(()=>S(null),5e3)}catch{S({type:"error",text:"An error occurred while generating files."})}finally{E(!1)}},b=o=>{y(o),D(o)},v=(o,N)=>{const f={...a,post_types:N?[...a.post_types,o]:a.post_types.filter(Y=>Y!==o)};u(f),w(f)},R=(o,N)=>{const f={...a,[o]:N};u(f),w(f)},$=o=>{const N=parseInt(o,10),f={...a,days_to_include:isNaN(N)?0:N};u(f),w(f)};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("style",{dangerouslySetInnerHTML:{__html:`
     3${L}`)}});function me({currentImages:t,onImagesChange:L,isPremium:S}){const{toast:_}=ce(),[p,P]=u.useState(!1),[A,C]=u.useState({});G.useEffect(()=>{const r=async()=>{for(const d of t)if(!A[d.id]){const s=wp.media.attachment(d.id);s.fetch().then(()=>{var R,x;const b={id:d.id,url:s.get("url"),preview_url:((x=(R=s.get("sizes"))==null?void 0:R.medium)==null?void 0:x.url)||s.get("url"),width:s.get("width"),height:s.get("height")};C(v=>({...v,[d.id]:b}))})}};t.length>0&&r()},[t]);const T=async r=>{var s,b,R,x;const d=(s=r.target.files)==null?void 0:s[0];if(d){if(!d.type.startsWith("image/")){_({title:"Error",description:"Please select an image file.",variant:"destructive"});return}P(!0);try{const v=new FormData;v.append("action","llmagnet_ai_seo_upload_image"),v.append("nonce",((b=window.llmagnetDashboardData)==null?void 0:b.nonce)||""),v.append("image",d);const $=await(await fetch(((R=window.llmagnetDashboardData)==null?void 0:R.ajaxUrl)||"/wp-admin/admin-ajax.php",{method:"POST",body:v,credentials:"same-origin"})).json();if($.success){const O={id:$.data.attachment_id,position:"after"},W=[...t,O];L(W),C(I=>({...I,[$.data.attachment_id]:$.data})),_({title:"Success",description:"Image uploaded successfully!"})}else _({title:"Upload Error",description:((x=$.data)==null?void 0:x.message)||"Failed to upload image.",variant:"destructive"})}catch(v){console.error("Upload error:",v),_({title:"Upload Error",description:"An error occurred while uploading the image.",variant:"destructive"})}finally{P(!1),r.target.value=""}}},j=()=>{if(typeof wp<"u"&&wp.media){const r=wp.media({title:"Select LLM Response Images",button:{text:"Select Images"},multiple:!0});r.on("select",()=>{const d=r.state().get("selection").toJSON(),s=[],b={};d.forEach(x=>{var v,B;s.push({id:x.id,position:"after"}),b[x.id]={id:x.id,url:x.url,preview_url:((B=(v=x.sizes)==null?void 0:v.medium)==null?void 0:B.url)||x.url,width:x.width,height:x.height}});const R=[...t,...s];L(R),C(x=>({...x,...b})),_({title:"Success",description:`${d.length} image(s) selected successfully!`})}),r.open()}},D=r=>{const d=t.filter(s=>s.id!==r);L(d),C(s=>{const b={...s};return delete b[r],b}),_({title:"Success",description:"Image removed successfully!"})},c=(r,d)=>{const s=t.map(b=>b.id===r?{...b,position:d}:b);L(s)};return S?e.jsxs("div",{className:"space-y-6",children:[t.length>0&&e.jsxs("div",{className:"mb-6 space-y-4",children:[e.jsxs("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:["Current Images (",t.length,")"]}),t.map((r,d)=>{const s=A[r.id];return e.jsxs("div",{className:"flex items-start gap-4 p-4 bg-gradient-to-r from-gray-50 to-gray-100/50 rounded-xl border border-gray-200/60 hover:shadow-md transition-all duration-200",children:[s&&e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:s.preview_url,alt:`LLM Response Image ${d+1}`,className:"w-24 h-24 object-cover rounded-lg border-2 border-white shadow-sm"}),e.jsx("div",{className:"absolute -top-1 -right-1 bg-blue-500 text-white text-xs font-medium px-1.5 py-0.5 rounded-full",children:d+1})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsxs("h6",{className:"font-semibold text-gray-900 mb-1",children:["Image ",d+1]}),s&&e.jsxs("div",{className:"text-sm text-gray-600 bg-white px-2 py-1 rounded-md inline-block",children:[s.width," × ",s.height,"px"]})]}),e.jsx(V,{onClick:()=>D(r.id),variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200",children:"Remove"})]}),e.jsxs("div",{className:"bg-white p-3 rounded-lg border border-gray-200/60",children:[e.jsx(F,{className:"text-sm font-semibold text-gray-700 mb-2 block",children:"Display Position"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${r.id}`,value:"before",checked:r.position==="before",onChange:()=>c(r.id,"before"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Before text"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${r.id}`,value:"after",checked:r.position==="after",onChange:()=>c(r.id,"after"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"After text"})]})]})]})]})]},r.id)})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Add New Images"}),e.jsx("div",{className:"flex items-center gap-4 p-3 rounded-xl bg-white/60",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(V,{onClick:j,variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:p,children:"Select from Media Library"}),e.jsxs("div",{className:"relative",children:[e.jsx(te,{type:"file",accept:"image/*",onChange:T,disabled:p,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"}),e.jsx(V,{variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:p,children:p?"Uploading...":"Upload New Image"})]})]})}),e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"You can select multiple images from the media library or upload them one by one."})]})]}):e.jsxs("div",{className:"bg-gray-50 border border-gray-200 rounded-md p-4",children:[e.jsx("h4",{className:"font-medium mb-2 text-gray-700",children:"LLM Response Images (Premium Feature)"}),e.jsx("p",{className:"text-sm text-gray-600 mb-3",children:"Attach multiple images that will be displayed with responses from all Large Language Models (ChatGPT, Claude, Gemini, GPT-4, etc.) and included in the llms.txt file."}),e.jsxs("div",{className:"bg-yellow-50 border border-yellow-200 text-yellow-800 p-3 rounded-md text-sm",children:[e.jsx("strong",{children:"Premium Feature:"})," This feature is available for premium users only. Upgrade to attach multiple images to your LLM responses."]})]})}const z=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"];function pe({apiRoot:t,apiNamespace:L,isPremium:S=!1}){const[_,p]=u.useState(!0),[P,A]=u.useState(null),[C,T]=u.useState([]),[j,D]=u.useState([]),[c,r]=u.useState(!1),[d,s]=u.useState("7days"),[b,R]=u.useState(!1),[x,v]=u.useState(null),[B,$]=u.useState(""),[O,W]=u.useState(!1),[I,n]=u.useState(null),k=u.useRef(null),y=u.useRef(null),J=u.useRef(new Map),q=u.useRef(new Map),H=Object.entries({ChatGPT:"openai.com",Claude:"anthropic.com",Bard:"google.com",Bing:"microsoft.com",Perplexity:"perplexity.ai",Cohere:"cohere.ai",Llama:"meta.com",Mistral:"mistral.ai","Other LLM":"ai.com"}).reduce((a,[o,i])=>(a[o]=`https://img.logo.dev/${i}?token=pk_LWY53QLNRjW3a2uzvqdwPg`,a),{}),X={ChatGPT:"#10a37f",Claude:"#6f42c1",Bard:"#4285f4",Bing:"#00a4ef",Perplexity:"#5436da",Cohere:"#ff0080",Llama:"#0668e1",Mistral:"#007bff","Other LLM":"#ff9800"},Y="https://img.logo.dev/ai.com?token=pk_LWY53QLNRjW3a2uzvqdwPg",se=()=>window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"||window.location.hostname.includes(".local")||window.location.hostname.includes(".test"),ae=()=>{const a=[],o=new Date;for(let f=29;f>=0;f--){const l=new Date(o);l.setDate(o.getDate()-f),a.push(l.toISOString().split("T")[0])}const i=[...z],m=[];return i.forEach(f=>{a.forEach(l=>{m.push({bot_name:f,date:l,visits:0})})}),m},re=()=>{const a=[],o=new Date;for(let l=29;l>=0;l--){const g=new Date(o);g.setDate(o.getDate()-l),a.push(g.toISOString().split("T")[0])}const i=[...z],m=[],f=se();return i.forEach(l=>{if(f){let g=l==="ChatGPT"?10:l==="Claude"?8:l==="Bard"?7:l==="Bing"?5:l==="Perplexity"?4:l==="Cohere"?3:l==="Llama"||l==="Mistral"?2:1;a.forEach((E,w)=>{const h=new Date(E).getDay(),M=h===0||h===6?.6:1,N=1+w*.01,K=.7+Math.random()*.6;let U=Math.round(g*M*N*K);U=Math.max(1,U),Math.random()<.1&&(U=Math.round(U*(1.5+Math.random()))),m.push({bot_name:l,date:E,visits:U})})}else{const g=l==="ChatGPT"?8:l==="Claude"?6:l==="Bard"?5:l==="Bing"?4:l==="Other LLM"?2:3;a.forEach(E=>{const w=Math.floor(Math.random()*(g+1));m.push({bot_name:l,date:E,visits:w})})}}),m};u.useEffect(()=>{S&&(async()=>{var o;try{const i=await fetch("/wp-json/llm-analytics/v1/report-email",{headers:{"X-WP-Nonce":((o=window.wpApiSettings)==null?void 0:o.nonce)||""}});if(!i.ok){console.error(`Error fetching report email: ${i.status}`);return}const m=await i.json();m.email&&$(m.email)}catch(i){console.error("Error fetching report email:",i)}})()},[S,t]);const ne=async()=>{var a;if(!O){W(!0),n(null);try{const o=await fetch("/wp-json/llm-analytics/v1/report-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((a=window.wpApiSettings)==null?void 0:a.nonce)||""},body:JSON.stringify({email:B})});if(!o.ok)throw new Error(`Error: ${o.status}`);const i=await o.json();i.success?n({type:"success",text:"Report email address saved successfully."}):n({type:"error",text:i.message||"Failed to save email address."})}catch(o){console.error("Error saving report email:",o),n({type:"error",text:"Failed to save email address. Please try again."})}finally{W(!1),(I==null?void 0:I.type)==="success"&&setTimeout(()=>{n(null)},3e3)}}};u.useEffect(()=>{console.log("isPremium status:",S),console.log("API Root:",t),console.log("API Namespace:",L);const a=async()=>{var i;try{console.log("Attempting to fetch data from API...");const m="/wp-json/llm-analytics/v1/stats";console.log("Using endpoint:",m),console.log("WP API Settings:",window.wpApiSettings);const f=((i=window.wpApiSettings)==null?void 0:i.nonce)||"";console.log("Nonce available:",f?"Yes":"No");const l=await fetch(m,{headers:{"X-WP-Nonce":f},credentials:"same-origin"});if(console.log("API Request URL:",m),console.log("API Response Status:",l.status),!l.ok){console.error(`API error: ${l.status}`),o();return}const g=await l.json();console.log("API Response Data:",g);const E=g;if(!E||!Array.isArray(E)||E.length===0){console.log("No analytics data available, using empty data"),o();return}console.log("Valid data received from API, processing..."),T(E);const w=[...z],h={};w.forEach(N=>{h[N]=0}),E.forEach(N=>{h[N.bot_name]!==void 0?h[N.bot_name]+=N.visits:(h[N.bot_name]=N.visits,w.includes(N.bot_name)||w.push(N.bot_name))}),console.log("Bot totals calculated:",h),console.log("All supported bots:",w);const M=w.sort().map(N=>({bot_name:N,total_visits:Number(h[N]||0),logo:H[N]||Y}));r(!0),console.log("Setting hasRealData to true"),D(M),p(!1)}catch(m){console.error("Error fetching analytics data:",m),o()}},o=()=>{console.log("Using empty or mock data as fallback");const i=[...z],m=ae();T(m);const f=i.sort().map(l=>({bot_name:l,total_visits:0,logo:H[l]||Y}));D(f),p(!1),A(null)};if(S)console.log("Premium user detected, fetching real data"),a();else{console.log("Free user detected, generating mock data"),console.log("DEBUG: Attempting to fetch data anyway for debugging"),a();const i=re();T(i);const m=[...z],f={};m.forEach(g=>{f[g]=0}),i.forEach(g=>{f[g.bot_name]!==void 0?f[g.bot_name]+=g.visits:f[g.bot_name]=g.visits});const l=m.sort().map(g=>({bot_name:g,total_visits:f[g]||0,logo:H[g]||Y}));D(l),p(!1)}},[S,t,L]),u.useEffect(()=>{!_&&k.current&&(console.log("Time range changed, re-rendering main chart"),Q())},[d]);const Q=()=>{const a=document.getElementById("main-chart");if(!a){console.error("Main chart canvas not found");return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly");return}console.log("Rendering main chart"),y.current&&y.current.destroy();const o=new Date,i=d==="7days"?7:30,m=new Date(o);m.setDate(o.getDate()-i+1);const f=[];for(let h=0;h<i;h++){const M=new Date(m);M.setDate(m.getDate()+h),f.push(M.toISOString().split("T")[0])}const l=f[0],g=C.filter(h=>h.date>=l),w=Array.from(new Set(C.map(h=>h.bot_name))).sort().map(h=>{const M=f.map(N=>g.filter(U=>U.date===N&&U.bot_name===h).reduce((U,ie)=>U+ie.visits,0));return{label:h,data:M,backgroundColor:X[h]||"#999",borderColor:X[h]||"#999",borderWidth:1.5,tension:.3,fill:!1,pointRadius:2}});y.current=new window.Chart(a,{type:"line",data:{labels:f,datasets:w},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{boxWidth:12,font:{size:10}}},tooltip:{mode:"index",intersect:!1}},scales:{y:{beginAtZero:!0,ticks:{precision:0},grid:{color:"rgba(0, 0, 0, 0.05)"}},x:{ticks:{maxRotation:0,autoSkip:!0,maxTicksLimit:d==="7days"?7:10,font:{size:9}},grid:{display:!1}}},animation:{duration:1e3}}})},oe=a=>{const o=J.current.get(a);if(!o){console.error(`Canvas for ${a} not available`);return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly for bot charts");return}console.log(`Rendering chart for ${a}`),q.current.get(a)&&q.current.get(a).destroy();const i=new Date,m=[];for(let w=6;w>=0;w--){const h=new Date(i);h.setDate(i.getDate()-w),m.push(h.toISOString().split("T")[0])}const f=m[0],l=C.filter(w=>w.bot_name===a&&w.date>=f),g=m.map(w=>l.filter(M=>M.date===w).reduce((M,N)=>M+N.visits,0)),E=Math.max(...g);q.current.set(a,new window.Chart(o,{type:"line",data:{labels:m,datasets:[{label:a,data:g,backgroundColor:X[a]||"#999",borderColor:X[a]||"#999",borderWidth:1.5,tension:.3,pointRadius:0,fill:!1}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},scales:{y:{display:!1,beginAtZero:!0,min:0,max:E===0?1:void 0,grid:{display:!1}},x:{display:!1,grid:{display:!1}}},elements:{point:{radius:0},line:{borderWidth:1.5}},animation:{duration:800}}}))},le=async()=>{var a;if(!b){R(!0),v(null);try{const o=await fetch("/wp-json/llm-analytics/v1/send-report",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((a=window.wpApiSettings)==null?void 0:a.nonce)||""}});if(!o.ok)throw new Error(`Error: ${o.status}`);const i=await o.json();i.success?v({type:"success",text:"Analytics report has been sent to your email."}):v({type:"error",text:i.message||"Failed to send analytics report."})}catch(o){console.error("Error sending report:",o),v({type:"error",text:"Failed to send analytics report. Please try again later."})}finally{R(!1),(x==null?void 0:x.type)==="success"&&setTimeout(()=>{v(null)},5e3)}}};u.useEffect(()=>{if(!_&&j.length>0)if(console.log("Attempting to render charts..."),typeof window.Chart>"u"){console.log("Chart.js not found, loading it directly");const a=document.createElement("script");a.src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js",a.async=!0,a.onload=()=>{console.log("Chart.js loaded successfully"),Z()},document.head.appendChild(a)}else console.log("Chart.js found, rendering charts"),setTimeout(Z,300)},[_,j]);const Z=()=>{console.log("Rendering all charts now"),document.getElementById("main-chart")?Q():console.error("Main chart canvas not found"),j.forEach(o=>{const i=document.getElementById(`bot-chart-${o.bot_name}`);i?(J.current.set(o.bot_name,i),oe(o.bot_name)):console.error(`Canvas element for ${o.bot_name} not found`)})};return e.jsxs("div",{className:"analytics-dashboard-summary",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"LLM Bot Analytics Summary"}),_?e.jsx("div",{className:"p-4",children:"Loading analytics data..."}):P?e.jsx("div",{className:"p-4 text-red-600",children:e.jsx("p",{children:P})}):e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"bg-white p-4 rounded-lg shadow border border-gray-200 mb-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h4",{className:"font-medium",children:"Bot Visits Over Time"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(F,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"7days",checked:d==="7days",onChange:()=>s("7days"),className:"mr-1"}),"Last 7 days"]}),e.jsxs(F,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"30days",checked:d==="30days",onChange:()=>s("30days"),className:"mr-1"}),"Last 30 days"]})]})]}),e.jsx("div",{className:"h-64",children:e.jsx("canvas",{id:"main-chart",height:"300"})})]}),e.jsx("div",{className:"bot-summaries grid grid-cols-1 md:grid-cols-3 gap-4",children:j.map(a=>e.jsxs("div",{className:"overflow-hidden bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsxs("div",{className:"flex items-center mb-2",children:[e.jsx("div",{className:"bot-logo mr-3 bg-white rounded-full p-1 shadow-sm border border-gray-100",children:e.jsx("img",{src:a.logo,alt:`${a.bot_name} logo`,className:"h-10 w-10 object-contain rounded-full",onError:o=>{o.target.src=Y,console.log(`Failed to load logo for ${a.bot_name}, using default`)},loading:"lazy"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",children:a.bot_name}),e.jsxs("p",{className:"text-sm text-gray-500",children:["Total visits: ",Number(a.total_visits)]})]})]}),e.jsx("div",{className:"h-24 mt-4 border-t pt-2 border-gray-100",children:e.jsx("canvas",{id:`bot-chart-${a.bot_name}`,height:"80"})})]},a.bot_name))}),!S&&!c&&e.jsx("div",{className:"absolute inset-0 bg-white/60 backdrop-blur-sm flex flex-col items-center justify-center z-10",style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.6)",backdropFilter:"blur(4px)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10},children:e.jsxs("div",{className:"text-center p-6 max-w-md bg-white rounded-lg shadow-lg",children:[e.jsx("h3",{className:"text-xl font-bold mb-2",children:"Premium Feature"}),e.jsx("p",{className:"mb-4",children:"Access to real analytics data is available in the premium version."}),e.jsx("a",{href:"admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"inline-block px-6 py-3 bg-gradient-to-r from-purple-600 to-pink-600 text-white rounded-lg font-medium shadow-lg hover:from-purple-700 hover:to-pink-700 transition-all",children:"Upgrade Now"})]})}),!S&&c&&e.jsx("div",{style:{position:"absolute",top:"10px",right:"10px",backgroundColor:"rgba(0, 128, 0, 0.8)",color:"white",padding:"10px",borderRadius:"5px",fontSize:"12px",zIndex:20},children:"Debug Mode: Real data detected and displayed"})]}),S&&e.jsxs("div",{className:"mt-6 bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Analytics Reports"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Report Email Address"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{id:"report-email",type:"email",value:B,onChange:a=>$(a.target.value),className:"flex-1 px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm",placeholder:"[email protected]"}),e.jsx("button",{onClick:ne,disabled:O,className:"inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500",children:O?"Saving...":"Save"})]}),I&&e.jsx("p",{className:`mt-1 text-xs ${I.type==="success"?"text-green-600":"text-red-600"}`,children:I.text})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{onClick:le,disabled:b,className:`inline-block px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors ${b?"opacity-70 cursor-not-allowed":""}`,children:b?"Sending...":"Send Analytics Report Now"}),x&&e.jsx("div",{className:`mt-2 p-2 rounded text-sm ${x.type==="success"?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:x.text})]})]})]})]})}function ge({data:t,onGenerateNow:L,onImagesChange:S,onSettingsChange:_}){var O,W,I;console.log("Dashboard Data:",{rootPath:t.rootPath,isWritable:t.isWritable,lastGenerated:t.lastGenerated,llmsTxtExists:t.llmsTxtExists,llmsTxtUrl:t.llmsTxtUrl,llmsTxtSize:t.llmsTxtSize,postsCount:t.postsCount,markdownCount:t.markdownCount,settings:t.settings,postTypes:t.postTypes,isPremium:t.isPremium,planData:t.planData,imageData:t.imageData,pluginVersion:t.pluginVersion,wordpressVersion:t.wordpressVersion});const[p,P]=u.useState(!1),[A,C]=u.useState(null),[T,j]=u.useState(t.settings.llm_response_images||[]),[D,c]=u.useState(!1),r=G.useRef(null),d=t.planData.plan_name==="free"?t.settings.post_types.filter(n=>n==="post"||n==="page"):t.settings.post_types,[s,b]=u.useState({post_types:d,full_content:t.settings.full_content,days_to_include:t.settings.days_to_include,delete_on_uninstall:t.settings.delete_on_uninstall});G.useEffect(()=>{function n(k){r.current&&!r.current.contains(k.target)&&c(!1)}return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}},[]);const R=async()=>{P(!0),C(null);try{const n=await L();C({type:n.success?"success":"error",text:n.message}),setTimeout(()=>C(null),5e3)}catch{C({type:"error",text:"An error occurred while generating files."})}finally{P(!1)}},x=n=>{j(n),S(n)},v=(n,k)=>{const y={...s,post_types:k?[...s.post_types,n]:s.post_types.filter(J=>J!==n)};b(y),_(y)},B=(n,k)=>{const y={...s,[n]:k};b(y),_(y)},$=n=>{const k=parseInt(n,10),y={...s,days_to_include:isNaN(k)?0:k};b(y),_(y)};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("style",{dangerouslySetInnerHTML:{__html:`
    44        .premium-tooltip {
    55          position: absolute;
     
    2222          visibility: visible;
    2323        }
    24       `}}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("img",{src:`${((P=window.llmagnetDashboardData)==null?void 0:P.pluginUrl)||""}assets/react-build/assets/banner_upgrade.png`,alt:"LLMagnet AI SEO Optimizer",className:"max-w-full h-auto",onError:o=>{var f;const N=o.target;N.onerror=null,N.src=`${((f=window.llmagnetDashboardData)==null?void 0:f.pluginUrl)||""}src/assets/images/banner_upgrade.png`,console.log("Trying fallback image path:",N.src)}})}),e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-900",children:"LLMagnet Dashboard"}),e.jsx("div",{className:`px-3 py-1 rounded-full text-xs font-semibold ${t.planData.plan_name==="enterprise"?"bg-purple-100 text-purple-800 border border-purple-200":t.planData.plan_name==="pro"?"bg-green-100 text-green-800 border border-green-200":"bg-gray-100 text-gray-600 border border-gray-200"}`,children:t.planData.is_trial?"Trial":t.planData.plan_title})]}),e.jsxs("div",{className:"relative",ref:n,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(z,{onClick:k,disabled:g||!t.isWritable,variant:"gradient",className:"whitespace-nowrap px-4 py-2 text-sm font-medium rounded-r-none",children:g?"Generating...":"Generate Now"}),e.jsx(z,{onClick:()=>i(!j),disabled:g||!t.isWritable,variant:"gradient",className:"px-2 py-2 rounded-l-none border-l border-purple-400",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),j&&e.jsx("div",{className:"absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 border border-gray-200",children:e.jsx("div",{className:"py-1",children:t.llmsTxtExists&&e.jsxs("a",{href:t.llmsTxtUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100",onClick:()=>i(!1),children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}),"View LLMS.txt"]})})})]})]}),e.jsx("p",{className:"text-gray-600",children:"Manage your LLMS.txt file and LLM response settings"})]})}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"Status Overview"}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLMS.txt Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.llmsTxtExists?"text-green-600":"text-red-600"}`,children:t.llmsTxtExists?"Active":"Not Generated"}),t.llmsTxtSize&&e.jsx("div",{className:"text-sm text-gray-500",children:t.llmsTxtSize})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Posts to Export"}),e.jsx("div",{className:"text-lg font-bold text-blue-600 mb-1",children:t.postsCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Content items"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Markdown Files"}),e.jsx("div",{className:"text-lg font-bold text-purple-600 mb-1",children:t.markdownCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Generated files"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLM Images"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${M.length>0?"text-green-600":"text-gray-400"}`,children:M.length}),e.jsx("div",{className:"text-sm text-gray-500",children:"Configured"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Directory Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.isWritable?"text-green-600":"text-red-600"}`,children:t.isWritable?"Writable":"Not Writable"}),e.jsx("div",{className:"text-sm text-gray-500",children:"Root directory"})]})})]}),t.lastGenerated&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200",children:e.jsxs("div",{className:"text-sm text-gray-600",children:[e.jsx("strong",{children:"Last Generated:"})," ",t.lastGenerated]})})]}),T&&e.jsx("div",{className:"mb-4",children:e.jsx("div",{className:`px-4 py-3 rounded-md text-sm ${T.type==="success"?"bg-green-50 text-green-800 border border-green-200":"bg-red-50 text-red-800 border border-red-200"}`,children:T.text})}),!t.isWritable&&e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded-md p-4",children:e.jsxs("p",{className:"text-yellow-800 text-sm",children:[e.jsx("strong",{children:"Warning:"})," Root directory is not writable. Please check file permissions before generating files."]})}),e.jsx("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md mb-6",children:e.jsx(ce,{pluginUrl:((I=window.llmagnetDashboardData)==null?void 0:I.pluginUrl)||"",apiRoot:((G=window.llmagnetDashboardData)==null?void 0:G.ajaxUrl)||"",apiNamespace:"llm-analytics/v1",reportEmail:"",isPremium:t.planData.plan_name!=="free"})}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-3 items-stretch",children:[e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"Content Settings"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Configure which content should be included in the llms.txt file and associated Markdown exports."})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Types to Include"}),e.jsx("div",{className:"space-y-3",children:t.postTypes.map(o=>{const f=!(o.name==="post"||o.name==="page")&&t.planData.plan_name==="free";return e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsxs("div",{className:`relative ${f?"tooltip-trigger":""}`,children:[e.jsx("button",{onClick:()=>!f&&v(o.name,!a.post_types.includes(o.name)),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${a.post_types.includes(o.name)?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"} ${f?"opacity-50 cursor-not-allowed":""}`,disabled:f,"aria-label":f?"Premium feature - Upgrade to enable":`Toggle ${o.label}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${a.post_types.includes(o.name)?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),f&&e.jsx("div",{className:"premium-tooltip -translate-y-full left-0 top-0",children:"Premium feature - Upgrade to enable"})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:o.label}),f&&e.jsxs("div",{className:"tooltip-trigger relative ml-2 bg-amber-100 text-amber-800 text-xs font-medium px-2 py-0.5 rounded cursor-help flex items-center",children:[e.jsx("span",{className:"mr-1",children:"Premium"}),e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"premium-tooltip mt-2 translate-y-1 left-0",children:[e.jsx("p",{className:"mb-2",children:"This post type is available in the premium version."}),e.jsx("a",{href:"/wp-admin/admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"block w-full px-3 py-2 text-center text-white bg-purple-600 rounded-md hover:bg-purple-700 transition-colors",children:"Upgrade Now"})]})]})]})]},o.name)})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Export"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>R("full_content",!a.full_content),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${a.full_content?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${a.full_content?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),e.jsxs("span",{className:"text-sm font-medium text-gray-700",children:["Include full content ",!a.full_content&&"(excerpt only)"]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Time Period"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl bg-white/60",children:[e.jsx("div",{className:"flex-1 max-w-32",children:e.jsx(K,{type:"number",min:"0",value:a.days_to_include,onChange:o=>$(o.target.value),className:"text-center font-semibold border-gray-300/50 focus:border-purple-400 focus:ring-purple-400/20 rounded-xl"})}),e.jsx("span",{className:"text-sm font-medium text-gray-600",children:a.days_to_include>0?"days of content":"all content"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Cleanup on Uninstall"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>R("delete_on_uninstall",!a.delete_on_uninstall),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-red-500/20 ${a.delete_on_uninstall?"bg-red-500 shadow-lg shadow-red-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${a.delete_on_uninstall?"translate-x-6 shadow-red-500/20":"translate-x-1"}`})}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Delete files when plugin is uninstalled"})]})]})]})]}),e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"LLM Response Images"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Select multiple images to display with responses from all Large Language Models. These images will be included in the llms.txt file and will work with ChatGPT, Claude, Gemini, GPT-4, and other LLMs."})]}),e.jsx(de,{currentImages:M,onImagesChange:b,isPremium:!0})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"System Information"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(W,{className:"text-sm font-medium text-gray-700",children:"WordPress Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.wordpressVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(W,{className:"text-sm font-medium text-gray-700",children:"Plugin Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.pluginVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(W,{className:"text-sm font-medium text-gray-700",children:"Root Path"}),e.jsx("code",{className:"text-xs text-gray-600 bg-gray-100 px-2 py-1 rounded",children:t.rootPath})]})]})]})]})}function pe(){const[t,L]=U.useState(!0),[D,w]=U.useState(null),[g,E]=U.useState(null);U.useEffect(()=>{try{window.llmagnetDashboardData?E(window.llmagnetDashboardData):w("Dashboard data not found.")}catch(y){console.error("Error loading dashboard data:",y),w("Error loading dashboard data.")}finally{L(!1)}},[]);const T=async()=>{var y,j;if(!g)return{success:!1,message:"No data available"};try{const i=new FormData;i.append("action","llmagnet_ai_seo_generate_now"),i.append("nonce",g.nonce);const d=await(await fetch(g.ajaxUrl,{method:"POST",body:i,credentials:"same-origin"})).json();return{success:d.success,message:((y=d.data)==null?void 0:y.message)||"Unknown error",timestamp:(j=d.data)==null?void 0:j.timestamp}}catch(i){return console.error("Error generating LLMS.txt:",i),{success:!1,message:"Error generating LLMS.txt. Please check server permissions."}}},S=async y=>{var j;if(g){E(i=>i?{...i,settings:{...i.settings,llm_response_images:y}}:null);try{const i={...g.settings,llm_response_images:y},n=new FormData;n.append("action","llmagnet_ai_seo_save_settings"),n.append("nonce",g.nonce),n.append("settings",JSON.stringify(i));const a=await(await fetch(g.ajaxUrl,{method:"POST",body:n,credentials:"same-origin"})).json();a.success||console.error("Failed to save images setting:",(j=a.data)==null?void 0:j.message)}catch(i){console.error("Error saving images setting:",i)}}},M=async y=>{var j;if(g){E(i=>i?{...i,settings:{...i.settings,...y}}:null);try{const i={...g.settings,...y},n=new FormData;n.append("action","llmagnet_ai_seo_save_settings"),n.append("nonce",g.nonce),n.append("settings",JSON.stringify(i));const a=await(await fetch(g.ajaxUrl,{method:"POST",body:n,credentials:"same-origin"})).json();a.success||console.error("Failed to save settings:",(j=a.data)==null?void 0:j.message)}catch(i){console.error("Error saving settings:",i)}}};return t?e.jsx("div",{className:"p-4",children:"Loading dashboard..."}):D||!g?e.jsx("div",{className:"p-4 text-red-600",children:D||"Unknown error"}):e.jsx("div",{className:"llms-txt-react-app",children:e.jsx("div",{className:"wrap",children:e.jsx(me,{data:g,onGenerateNow:T,onImagesChange:S,onSettingsChange:M})})})}const Z=document.getElementById("llms-txt-dashboard-app");Z&&oe.createRoot(Z).render(e.jsx(pe,{}));
     24      `}}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("img",{src:`${((O=window.llmagnetDashboardData)==null?void 0:O.pluginUrl)||""}assets/react-build/assets/banner_upgrade.png`,alt:"LLMagnet AI SEO Optimizer",className:"max-w-full h-auto",onError:n=>{var y;const k=n.target;k.onerror=null,k.src=`${((y=window.llmagnetDashboardData)==null?void 0:y.pluginUrl)||""}src/assets/images/banner_upgrade.png`,console.log("Trying fallback image path:",k.src)}})}),e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-900",children:"LLMagnet Dashboard"}),e.jsx("div",{className:`px-3 py-1 rounded-full text-xs font-semibold ${t.planData.plan_name==="enterprise"?"bg-purple-100 text-purple-800 border border-purple-200":t.planData.plan_name==="pro"?"bg-green-100 text-green-800 border border-green-200":"bg-gray-100 text-gray-600 border border-gray-200"}`,children:t.planData.is_trial?"Trial":t.planData.plan_title})]}),e.jsxs("div",{className:"relative",ref:r,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(V,{onClick:R,disabled:p||!t.isWritable,variant:"gradient",className:"whitespace-nowrap px-4 py-2 text-sm font-medium rounded-r-none",children:p?"Generating...":"Generate Now"}),e.jsx(V,{onClick:()=>c(!D),disabled:p||!t.isWritable,variant:"gradient",className:"px-2 py-2 rounded-l-none border-l border-purple-400",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),D&&e.jsx("div",{className:"absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 border border-gray-200",children:e.jsx("div",{className:"py-1",children:t.llmsTxtExists&&e.jsxs("a",{href:t.llmsTxtUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100",onClick:()=>c(!1),children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}),"View LLMS.txt"]})})})]})]}),e.jsx("p",{className:"text-gray-600",children:"Manage your LLMS.txt file and LLM response settings"})]})}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"Status Overview"}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLMS.txt Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.llmsTxtExists?"text-green-600":"text-red-600"}`,children:t.llmsTxtExists?"Active":"Not Generated"}),t.llmsTxtSize&&e.jsx("div",{className:"text-sm text-gray-500",children:t.llmsTxtSize})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Posts to Export"}),e.jsx("div",{className:"text-lg font-bold text-blue-600 mb-1",children:t.postsCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Content items"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Markdown Files"}),e.jsx("div",{className:"text-lg font-bold text-purple-600 mb-1",children:t.markdownCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Generated files"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLM Images"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${T.length>0?"text-green-600":"text-gray-400"}`,children:T.length}),e.jsx("div",{className:"text-sm text-gray-500",children:"Configured"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Directory Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.isWritable?"text-green-600":"text-red-600"}`,children:t.isWritable?"Writable":"Not Writable"}),e.jsx("div",{className:"text-sm text-gray-500",children:"Root directory"})]})})]}),t.lastGenerated&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200",children:e.jsxs("div",{className:"text-sm text-gray-600",children:[e.jsx("strong",{children:"Last Generated:"})," ",t.lastGenerated]})})]}),A&&e.jsx("div",{className:"mb-4",children:e.jsx("div",{className:`px-4 py-3 rounded-md text-sm ${A.type==="success"?"bg-green-50 text-green-800 border border-green-200":"bg-red-50 text-red-800 border border-red-200"}`,children:A.text})}),!t.isWritable&&e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded-md p-4",children:e.jsxs("p",{className:"text-yellow-800 text-sm",children:[e.jsx("strong",{children:"Warning:"})," Root directory is not writable. Please check file permissions before generating files."]})}),e.jsx("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md mb-6",children:e.jsx(pe,{pluginUrl:((W=window.llmagnetDashboardData)==null?void 0:W.pluginUrl)||"",apiRoot:((I=window.llmagnetDashboardData)==null?void 0:I.ajaxUrl)||"",apiNamespace:"llm-analytics/v1",reportEmail:"",isPremium:t.planData.plan_name!=="free"})}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-3 items-stretch",children:[e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"Content Settings"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Configure which content should be included in the llms.txt file and associated Markdown exports."})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Types to Include"}),e.jsx("div",{className:"space-y-3",children:t.postTypes.map(n=>{const y=!(n.name==="post"||n.name==="page")&&t.planData.plan_name==="free";return e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsxs("div",{className:`relative ${y?"tooltip-trigger":""}`,children:[e.jsx("button",{onClick:()=>!y&&v(n.name,!s.post_types.includes(n.name)),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${s.post_types.includes(n.name)?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"} ${y?"opacity-50 cursor-not-allowed":""}`,disabled:y,"aria-label":y?"Premium feature - Upgrade to enable":`Toggle ${n.label}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${s.post_types.includes(n.name)?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),y&&e.jsx("div",{className:"premium-tooltip -translate-y-full left-0 top-0",children:"Premium feature - Upgrade to enable"})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:n.label}),y&&e.jsxs("div",{className:"tooltip-trigger relative ml-2 bg-amber-100 text-amber-800 text-xs font-medium px-2 py-0.5 rounded cursor-help flex items-center",children:[e.jsx("span",{className:"mr-1",children:"Premium"}),e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"premium-tooltip mt-2 translate-y-1 left-0",children:[e.jsx("p",{className:"mb-2",children:"This post type is available in the premium version."}),e.jsx("a",{href:"/wp-admin/admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"block w-full px-3 py-2 text-center text-white bg-purple-600 rounded-md hover:bg-purple-700 transition-colors",children:"Upgrade Now"})]})]})]})]},n.name)})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Export"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>B("full_content",!s.full_content),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${s.full_content?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${s.full_content?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),e.jsxs("span",{className:"text-sm font-medium text-gray-700",children:["Include full content ",!s.full_content&&"(excerpt only)"]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Time Period"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl bg-white/60",children:[e.jsx("div",{className:"flex-1 max-w-32",children:e.jsx(te,{type:"number",min:"0",value:s.days_to_include,onChange:n=>$(n.target.value),className:"text-center font-semibold border-gray-300/50 focus:border-purple-400 focus:ring-purple-400/20 rounded-xl"})}),e.jsx("span",{className:"text-sm font-medium text-gray-600",children:s.days_to_include>0?"days of content":"all content"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Cleanup on Uninstall"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>B("delete_on_uninstall",!s.delete_on_uninstall),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-red-500/20 ${s.delete_on_uninstall?"bg-red-500 shadow-lg shadow-red-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${s.delete_on_uninstall?"translate-x-6 shadow-red-500/20":"translate-x-1"}`})}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Delete files when plugin is uninstalled"})]})]})]})]}),e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"LLM Response Images"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Select multiple images to display with responses from all Large Language Models. These images will be included in the llms.txt file and will work with ChatGPT, Claude, Gemini, GPT-4, and other LLMs."})]}),e.jsx(me,{currentImages:T,onImagesChange:x,isPremium:!0})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"System Information"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(F,{className:"text-sm font-medium text-gray-700",children:"WordPress Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.wordpressVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(F,{className:"text-sm font-medium text-gray-700",children:"Plugin Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.pluginVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(F,{className:"text-sm font-medium text-gray-700",children:"Root Path"}),e.jsx("code",{className:"text-xs text-gray-600 bg-gray-100 px-2 py-1 rounded",children:t.rootPath})]})]})]})]})}function he(){const[t,L]=G.useState(!0),[S,_]=G.useState(null),[p,P]=G.useState(null);G.useEffect(()=>{try{window.llmagnetDashboardData?P(window.llmagnetDashboardData):_("Dashboard data not found.")}catch(j){console.error("Error loading dashboard data:",j),_("Error loading dashboard data.")}finally{L(!1)}},[]);const A=async()=>{var j,D;if(!p)return{success:!1,message:"No data available"};try{const c=new FormData;c.append("action","llmagnet_ai_seo_generate_now"),c.append("nonce",p.nonce);const d=await(await fetch(p.ajaxUrl,{method:"POST",body:c,credentials:"same-origin"})).json();return{success:d.success,message:((j=d.data)==null?void 0:j.message)||"Unknown error",timestamp:(D=d.data)==null?void 0:D.timestamp}}catch(c){return console.error("Error generating LLMS.txt:",c),{success:!1,message:"Error generating LLMS.txt. Please check server permissions."}}},C=async j=>{var D;if(p){P(c=>c?{...c,settings:{...c.settings,llm_response_images:j}}:null);try{const c={...p.settings,llm_response_images:j},r=new FormData;r.append("action","llmagnet_ai_seo_save_settings"),r.append("nonce",p.nonce),r.append("settings",JSON.stringify(c));const s=await(await fetch(p.ajaxUrl,{method:"POST",body:r,credentials:"same-origin"})).json();s.success||console.error("Failed to save images setting:",(D=s.data)==null?void 0:D.message)}catch(c){console.error("Error saving images setting:",c)}}},T=async j=>{var D;if(p){P(c=>c?{...c,settings:{...c.settings,...j}}:null);try{const c={...p.settings,...j},r=new FormData;r.append("action","llmagnet_ai_seo_save_settings"),r.append("nonce",p.nonce),r.append("settings",JSON.stringify(c));const s=await(await fetch(p.ajaxUrl,{method:"POST",body:r,credentials:"same-origin"})).json();s.success||console.error("Failed to save settings:",(D=s.data)==null?void 0:D.message)}catch(c){console.error("Error saving settings:",c)}}};return t?e.jsx("div",{className:"p-4",children:"Loading dashboard..."}):S||!p?e.jsx("div",{className:"p-4 text-red-600",children:S||"Unknown error"}):e.jsx("div",{className:"llms-txt-react-app",children:e.jsx("div",{className:"wrap",children:e.jsx(ge,{data:p,onGenerateNow:A,onImagesChange:C,onSettingsChange:T})})})}const ee=document.getElementById("llms-txt-dashboard-app");ee&&de.createRoot(ee).render(e.jsx(he,{}));
    2525//# sourceMappingURL=dashboard.js.map
  • llmagnet-llm-txt-generator/tags/2.0.2/includes/class-admin.php

    r3364798 r3365400  
    554554                    'wordpressVersion' => get_bloginfo('version'),
    555555                    'pluginUrl' => LLMAGNET_AISEO_PLUGIN_URL,
     556                ]);
     557               
     558                // Add WordPress REST API settings with nonce for REST API calls
     559                wp_localize_script('llmagnet-dashboard', 'wpApiSettings', [
     560                    'root' => esc_url_raw(rest_url()),
     561                    'nonce' => wp_create_nonce('wp_rest')
    556562                ]);
    557563            }
  • llmagnet-llm-txt-generator/tags/2.0.2/includes/class-analytics.php

    r3365069 r3365400  
    3535        // Add hook to detect and log LLM bot visits
    3636        add_action('init', [$this, 'detect_and_log_llm_bot'], 1);
     37       
     38        // Add a test function to verify hooks are working
     39        add_action('wp_footer', function() {
     40            // Get the current user agent
     41            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Unknown';
     42           
     43            // Call the bot detection directly
     44            $bot_name = $this->identify_llm_bot($user_agent);
     45           
     46            $this->detect_and_log_llm_bot();
     47
     48            // echo '<div style="position: fixed; bottom: 0; left: 0; right: 0; background: #ff5722; color: #fff; padding: 10px; z-index: 9999; font-family: monospace;">';
     49            // echo 'HOOK TEST: Analytics class initialized. Current time: ' . current_time('mysql');
     50            // echo '<br>DIRECT TEST: detect_and_log_llm_bot should have been called on init hook.';
     51            // echo '<br>USER AGENT: ' . esc_html($user_agent);
     52            // echo '<br>BOT DETECTION TEST: ' . ($bot_name ? '<strong>Bot detected: ' . esc_html($bot_name) . '</strong>' : 'No bot detected');
     53            // echo '<br><button onclick="this.parentNode.style.height=\'auto\'" style="background:#fff; color:#ff5722; border:none; padding:5px 10px; margin-top:5px; cursor:pointer; border-radius:3px;">Show More</button>';
     54            // echo '</div>';
     55           
     56           
     57            // Force a direct call to the function for testing
     58            // echo '<script>
     59            //     console.log("Forcing direct call to detect_and_log_llm_bot");
     60            //     fetch("?llm_test=1&time=' . time() . '");
     61            // </script>';
     62        });
     63       
     64        // Add a direct test endpoint
     65        if (isset($_GET['llm_test'])) {
     66            // This bypasses the normal WordPress flow
     67            $this->detect_and_log_llm_bot();
     68            if (!headers_sent()) {
     69                header('Content-Type: application/json');
     70                echo json_encode(['success' => true, 'message' => 'Test completed']);
     71                exit;
     72            }
     73        }
    3774       
    3875        // Register REST API endpoints
     
    68105     */
    69106    public function detect_and_log_llm_bot() {
    70         // Skip if in admin area or AJAX request
    71         if (is_admin() || wp_doing_ajax() || wp_doing_cron()) {
     107        // DIRECT DEBUG OUTPUT - will show on all pages regardless of hooks
     108        echo '<!-- LLM BOT DETECTION FUNCTION CALLED -->';
     109       
     110        // Check if we're in a test context
     111        $is_test = isset($_GET['llm_test']);
     112       
     113        // Skip if in admin area or AJAX request (unless it's a test)
     114        if (!$is_test && (is_admin() || wp_doing_ajax() || wp_doing_cron())) {
     115            echo '<!-- SKIPPED: Admin/AJAX/Cron request -->';
    72116            return;
    73117        }
     
    75119        // Check if user agent exists
    76120        if (!isset($_SERVER['HTTP_USER_AGENT'])) {
     121            echo '<!-- SKIPPED: No User Agent -->';
    77122            return;
    78123        }
     
    80125        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
    81126        $bot_name = $this->identify_llm_bot($user_agent);
     127       
     128        // DIRECT DEBUG OUTPUT - will show on all pages
     129        echo '<!-- USER AGENT: ' . esc_html($user_agent) . ' -->';
     130        echo '<!-- BOT DETECTED: ' . ($bot_name ? esc_html($bot_name) : 'NONE') . ' -->';
     131       
     132        // // Add direct output to page body
     133        // echo '<div id="llm-bot-debug" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.8); color: #fff; padding: 20px; z-index: 99999; font-family: monospace; border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.5); max-width: 80%;">';
     134        // echo '<h3 style="margin-top: 0; color: #ff5722;">LLM Bot Detection Debug</h3>';
     135        // echo '<p><strong>Function called:</strong> detect_and_log_llm_bot()</p>';
     136        // echo '<p><strong>User Agent:</strong> ' . esc_html($user_agent) . '</p>';
     137        // echo '<p><strong>Bot Detected:</strong> ' . ($bot_name ? '<span style="color: #4caf50; font-weight: bold;">' . esc_html($bot_name) . '</span>' : '<span style="color: #f44336;">None</span>') . '</p>';
     138        // echo '<p><strong>Time:</strong> ' . current_time('mysql') . '</p>';
     139        // echo '<button onclick="document.getElementById(\'llm-bot-debug\').style.display=\'none\'" style="background: #ff5722; color: white; border: none; padding: 5px 10px; cursor: pointer; border-radius: 3px;">Close</button>';
     140        // echo '</div>';
     141       
     142        // Also log to error log for headless requests
     143        error_log('LLM Bot Detection Function Called: ' . ($bot_name ? 'Bot detected: ' . $bot_name : 'No bot detected') . ' | User Agent: ' . $user_agent);
    82144
    83145        if ($bot_name) {
    84             $this->log_bot_visit($bot_name, $user_agent);
     146            $result = $this->log_bot_visit($bot_name, $user_agent);
     147            echo '<!-- DATABASE INSERT: ' . ($result ? 'SUCCESS' : 'FAILED') . ' -->';
    85148        }
    86149    }
     
    120183     * @param string $bot_name Bot name
    121184     * @param string $user_agent User agent string
    122      * @return void
     185     * @return bool True if successful, false otherwise
    123186     */
    124187    private function log_bot_visit($bot_name, $user_agent) {
    125188        global $wpdb;
    126189       
    127         $wpdb->insert(
     190        $result = $wpdb->insert(
    128191            $this->table_name,
    129192            [
     
    133196            ['%s', '%s']
    134197        );
     198       
     199        if ($result === false) {
     200            error_log('LLM Bot Database Insert Failed: ' . $wpdb->last_error);
     201        }
     202       
     203        return $result !== false;
    135204    }
    136205
  • llmagnet-llm-txt-generator/tags/2.0.2/llmagnet-ai-seo-optimizer.php

    r3365069 r3365400  
    1212 * Plugin URI:        https://llmagnet.com
    1313 * Description:       Automatically creates and maintains an llms.txt file and associated Markdown files for LLM crawlers.
    14  * Version:           2.0.1
     14 * Version:           2.0.2
    1515 * Requires at least: 6.0
    1616 * Requires PHP:      8.0
     
    2929
    3030// Define plugin constants
    31 define('LLMAGNET_AISEO_VERSION', '2.0.1');
     31define('LLMAGNET_AISEO_VERSION', '2.0.2');
    3232define('LLMAGNET_AISEO_PLUGIN_DIR', plugin_dir_path(__FILE__));
    3333define('LLMAGNET_AISEO_PLUGIN_URL', plugin_dir_url(__FILE__));
  • llmagnet-llm-txt-generator/tags/2.0.2/readme.txt

    r3365069 r3365400  
    44Requires at least: 6.0
    55Tested up to: 6.8
    6 Stable tag: 2.0.1
     6Stable tag: 2.0.2
    77Requires PHP: 8.0
    88License: GPLv2 or later
     
    109109== Changelog ==
    110110
     111= 2.0.2 =
     112* Fix analytics dhasboard
     113
     114= 2.0.0 =
     115* Add analytics per llm bot agent
     116* Improve detect llms user-agent
     117* Add email report
     118
    111119= 1.0.8 =
    112120* Add Freemius SDK bootstrap and autoload guard
  • llmagnet-llm-txt-generator/trunk/assets/react-build/js/dashboard.js

    r3364798 r3365400  
    1 import{r as x,R as U,j as e,B as z,g as oe}from"./index-b15a82cd.js";import{L as W,I as K}from"./input-647e65c0.js";const ie=()=>({toast:({title:t,description:L,variant:D})=>{alert(D==="destructive"?`Error: ${t}
     1import{r as u,R as G,j as e,B as V,g as de}from"./index-b15a82cd.js";import{L as F,I as te}from"./input-647e65c0.js";const ce=()=>({toast:({title:t,description:L,variant:S})=>{alert(S==="destructive"?`Error: ${t}
    22${L}`:`${t}
    3 ${L}`)}});function de({currentImages:t,onImagesChange:L,isPremium:D}){const{toast:w}=ie(),[g,E]=x.useState(!1),[T,S]=x.useState({});U.useEffect(()=>{const n=async()=>{for(const d of t)if(!T[d.id]){const a=wp.media.attachment(d.id);a.fetch().then(()=>{var k,b;const u={id:d.id,url:a.get("url"),preview_url:((b=(k=a.get("sizes"))==null?void 0:k.medium)==null?void 0:b.url)||a.get("url"),width:a.get("width"),height:a.get("height")};S(v=>({...v,[d.id]:u}))})}};t.length>0&&n()},[t]);const M=async n=>{var a,u,k,b;const d=(a=n.target.files)==null?void 0:a[0];if(d){if(!d.type.startsWith("image/")){w({title:"Error",description:"Please select an image file.",variant:"destructive"});return}E(!0);try{const v=new FormData;v.append("action","llmagnet_ai_seo_upload_image"),v.append("nonce",((u=window.llmagnetDashboardData)==null?void 0:u.nonce)||""),v.append("image",d);const $=await(await fetch(((k=window.llmagnetDashboardData)==null?void 0:k.ajaxUrl)||"/wp-admin/admin-ajax.php",{method:"POST",body:v,credentials:"same-origin"})).json();if($.success){const P={id:$.data.attachment_id,position:"after"},I=[...t,P];L(I),S(G=>({...G,[$.data.attachment_id]:$.data})),w({title:"Success",description:"Image uploaded successfully!"})}else w({title:"Upload Error",description:((b=$.data)==null?void 0:b.message)||"Failed to upload image.",variant:"destructive"})}catch(v){console.error("Upload error:",v),w({title:"Upload Error",description:"An error occurred while uploading the image.",variant:"destructive"})}finally{E(!1),n.target.value=""}}},y=()=>{if(typeof wp<"u"&&wp.media){const n=wp.media({title:"Select LLM Response Images",button:{text:"Select Images"},multiple:!0});n.on("select",()=>{const d=n.state().get("selection").toJSON(),a=[],u={};d.forEach(b=>{var v,R;a.push({id:b.id,position:"after"}),u[b.id]={id:b.id,url:b.url,preview_url:((R=(v=b.sizes)==null?void 0:v.medium)==null?void 0:R.url)||b.url,width:b.width,height:b.height}});const k=[...t,...a];L(k),S(b=>({...b,...u})),w({title:"Success",description:`${d.length} image(s) selected successfully!`})}),n.open()}},j=n=>{const d=t.filter(a=>a.id!==n);L(d),S(a=>{const u={...a};return delete u[n],u}),w({title:"Success",description:"Image removed successfully!"})},i=(n,d)=>{const a=t.map(u=>u.id===n?{...u,position:d}:u);L(a)};return D?e.jsxs("div",{className:"space-y-6",children:[t.length>0&&e.jsxs("div",{className:"mb-6 space-y-4",children:[e.jsxs("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:["Current Images (",t.length,")"]}),t.map((n,d)=>{const a=T[n.id];return e.jsxs("div",{className:"flex items-start gap-4 p-4 bg-gradient-to-r from-gray-50 to-gray-100/50 rounded-xl border border-gray-200/60 hover:shadow-md transition-all duration-200",children:[a&&e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:a.preview_url,alt:`LLM Response Image ${d+1}`,className:"w-24 h-24 object-cover rounded-lg border-2 border-white shadow-sm"}),e.jsx("div",{className:"absolute -top-1 -right-1 bg-blue-500 text-white text-xs font-medium px-1.5 py-0.5 rounded-full",children:d+1})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsxs("h6",{className:"font-semibold text-gray-900 mb-1",children:["Image ",d+1]}),a&&e.jsxs("div",{className:"text-sm text-gray-600 bg-white px-2 py-1 rounded-md inline-block",children:[a.width," × ",a.height,"px"]})]}),e.jsx(z,{onClick:()=>j(n.id),variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200",children:"Remove"})]}),e.jsxs("div",{className:"bg-white p-3 rounded-lg border border-gray-200/60",children:[e.jsx(W,{className:"text-sm font-semibold text-gray-700 mb-2 block",children:"Display Position"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${n.id}`,value:"before",checked:n.position==="before",onChange:()=>i(n.id,"before"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Before text"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${n.id}`,value:"after",checked:n.position==="after",onChange:()=>i(n.id,"after"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"After text"})]})]})]})]})]},n.id)})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Add New Images"}),e.jsx("div",{className:"flex items-center gap-4 p-3 rounded-xl bg-white/60",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(z,{onClick:y,variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:g,children:"Select from Media Library"}),e.jsxs("div",{className:"relative",children:[e.jsx(K,{type:"file",accept:"image/*",onChange:M,disabled:g,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"}),e.jsx(z,{variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:g,children:g?"Uploading...":"Upload New Image"})]})]})}),e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"You can select multiple images from the media library or upload them one by one."})]})]}):e.jsxs("div",{className:"bg-gray-50 border border-gray-200 rounded-md p-4",children:[e.jsx("h4",{className:"font-medium mb-2 text-gray-700",children:"LLM Response Images (Premium Feature)"}),e.jsx("p",{className:"text-sm text-gray-600 mb-3",children:"Attach multiple images that will be displayed with responses from all Large Language Models (ChatGPT, Claude, Gemini, GPT-4, etc.) and included in the llms.txt file."}),e.jsxs("div",{className:"bg-yellow-50 border border-yellow-200 text-yellow-800 p-3 rounded-md text-sm",children:[e.jsx("strong",{children:"Premium Feature:"})," This feature is available for premium users only. Upgrade to attach multiple images to your LLM responses."]})]})}function ce({apiRoot:t,apiNamespace:L,isPremium:D=!1}){const[w,g]=x.useState(!0),[E,T]=x.useState(null),[S,M]=x.useState([]),[y,j]=x.useState([]),[i,n]=x.useState("7days"),[d,a]=x.useState(!1),[u,k]=x.useState(null),[b,v]=x.useState(""),[R,$]=x.useState(!1),[P,I]=x.useState(null),G=x.useRef(null),o=x.useRef(null),N=x.useRef(new Map),f=x.useRef(new Map),X=Object.entries({ChatGPT:"openai.com",Claude:"anthropic.com",Bard:"google.com",Bing:"microsoft.com",Perplexity:"perplexity.ai",Cohere:"cohere.ai",Llama:"meta.com",Mistral:"mistral.ai","Other LLM":"ai.com"}).reduce((s,[r,c])=>(s[r]=`https://img.logo.dev/${c}?token=pk_LWY53QLNRjW3a2uzvqdwPg`,s),{}),V={ChatGPT:"#10a37f",Claude:"#6f42c1",Bard:"#4285f4",Bing:"#00a4ef",Perplexity:"#5436da",Cohere:"#ff0080",Llama:"#0668e1",Mistral:"#007bff","Other LLM":"#ff9800"},J="https://img.logo.dev/ai.com?token=pk_LWY53QLNRjW3a2uzvqdwPg",ee=()=>window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"||window.location.hostname.includes(".local")||window.location.hostname.includes(".test"),te=()=>{const s=[],r=new Date;for(let p=29;p>=0;p--){const l=new Date(r);l.setDate(r.getDate()-p),s.push(l.toISOString().split("T")[0])}const c=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"],h=[];return c.forEach(p=>{s.forEach(l=>{h.push({bot_name:p,date:l,visits:0})})}),h},se=()=>{const s=[],r=new Date;for(let l=29;l>=0;l--){const _=new Date(r);_.setDate(r.getDate()-l),s.push(_.toISOString().split("T")[0])}const c=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"],h=[],p=ee();return c.forEach(l=>{if(p){let _=l==="ChatGPT"?10:l==="Claude"?8:l==="Bard"?7:l==="Bing"?5:l==="Perplexity"?4:l==="Cohere"?3:l==="Llama"||l==="Mistral"?2:1;s.forEach((O,C)=>{const m=new Date(O).getDay(),A=m===0||m===6?.6:1,F=1+C*.01,Q=.7+Math.random()*.6;let B=Math.round(_*A*F*Q);B=Math.max(1,B),Math.random()<.1&&(B=Math.round(B*(1.5+Math.random()))),h.push({bot_name:l,date:O,visits:B})})}else{const _=l==="ChatGPT"?8:l==="Claude"?6:l==="Bard"?5:l==="Bing"?4:l==="Other LLM"?2:3;s.forEach(O=>{const C=Math.floor(Math.random()*(_+1));h.push({bot_name:l,date:O,visits:C})})}}),h};x.useEffect(()=>{D&&(async()=>{var r;try{const c=await fetch(`${t}llm-analytics/v1/report-email`,{headers:{"X-WP-Nonce":((r=window.wpApiSettings)==null?void 0:r.nonce)||""}});if(!c.ok){console.error(`Error fetching report email: ${c.status}`);return}const h=await c.json();h.email&&v(h.email)}catch(c){console.error("Error fetching report email:",c)}})()},[D,t]);const ae=async()=>{var s;if(!R){$(!0),I(null);try{const r=await fetch(`${t}llm-analytics/v1/report-email`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((s=window.wpApiSettings)==null?void 0:s.nonce)||""},body:JSON.stringify({email:b})});if(!r.ok)throw new Error(`Error: ${r.status}`);const c=await r.json();c.success?I({type:"success",text:"Report email address saved successfully."}):I({type:"error",text:c.message||"Failed to save email address."})}catch(r){console.error("Error saving report email:",r),I({type:"error",text:"Failed to save email address. Please try again."})}finally{$(!1),(P==null?void 0:P.type)==="success"&&setTimeout(()=>{I(null)},3e3)}}};x.useEffect(()=>{if(D){const s=async()=>{var c;try{const h=await fetch(`${t}${L}/stats`,{headers:{"X-WP-Nonce":((c=window.wpApiSettings)==null?void 0:c.nonce)||""}});if(!h.ok){console.error(`API error: ${h.status}`),r();return}const l=await h.json();if(!l||!Array.isArray(l)||l.length===0){console.log("No analytics data available, using empty data"),r();return}M(l);const _={};l.forEach(m=>{_[m.bot_name]||(_[m.bot_name]=0),_[m.bot_name]+=m.visits});const C=Array.from(new Set(l.map(m=>m.bot_name))).sort().map(m=>({bot_name:m,total_visits:_[m]||0,logo:X[m]||J}));j(C),g(!1)}catch(h){console.error("Error fetching analytics data:",h),r()}},r=()=>{const c=te();M(c);const p=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"].map(l=>({bot_name:l,total_visits:0,logo:X[l]||J}));j(p),g(!1),T(null)};s()}else{const s=se();M(s);const r={};s.forEach(p=>{r[p.bot_name]||(r[p.bot_name]=0),r[p.bot_name]+=p.visits});const h=Array.from(new Set(s.map(p=>p.bot_name))).sort().map(p=>({bot_name:p,total_visits:r[p]||0,logo:X[p]||J}));j(h),g(!1)}},[D,t,L]),x.useEffect(()=>{!w&&G.current&&(console.log("Time range changed, re-rendering main chart"),q())},[i]);const q=()=>{const s=document.getElementById("main-chart");if(!s){console.error("Main chart canvas not found");return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly");return}console.log("Rendering main chart"),o.current&&o.current.destroy();const r=new Date,c=i==="7days"?7:30,h=new Date(r);h.setDate(r.getDate()-c+1);const p=[];for(let m=0;m<c;m++){const A=new Date(h);A.setDate(h.getDate()+m),p.push(A.toISOString().split("T")[0])}const l=p[0],_=S.filter(m=>m.date>=l),C=Array.from(new Set(S.map(m=>m.bot_name))).sort().map(m=>{const A=p.map(F=>_.filter(B=>B.date===F&&B.bot_name===m).reduce((B,le)=>B+le.visits,0));return{label:m,data:A,backgroundColor:V[m]||"#999",borderColor:V[m]||"#999",borderWidth:1.5,tension:.3,fill:!1,pointRadius:2}});o.current=new window.Chart(s,{type:"line",data:{labels:p,datasets:C},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{boxWidth:12,font:{size:10}}},tooltip:{mode:"index",intersect:!1}},scales:{y:{beginAtZero:!0,ticks:{precision:0},grid:{color:"rgba(0, 0, 0, 0.05)"}},x:{ticks:{maxRotation:0,autoSkip:!0,maxTicksLimit:i==="7days"?7:10,font:{size:9}},grid:{display:!1}}},animation:{duration:1e3}}})},re=s=>{const r=N.current.get(s);if(!r){console.error(`Canvas for ${s} not available`);return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly for bot charts");return}console.log(`Rendering chart for ${s}`),f.current.get(s)&&f.current.get(s).destroy();const c=new Date,h=[];for(let C=6;C>=0;C--){const m=new Date(c);m.setDate(c.getDate()-C),h.push(m.toISOString().split("T")[0])}const p=h[0],l=S.filter(C=>C.bot_name===s&&C.date>=p),_=h.map(C=>l.filter(A=>A.date===C).reduce((A,F)=>A+F.visits,0)),O=Math.max(..._);f.current.set(s,new window.Chart(r,{type:"line",data:{labels:h,datasets:[{label:s,data:_,backgroundColor:V[s]||"#999",borderColor:V[s]||"#999",borderWidth:1.5,tension:.3,pointRadius:0,fill:!1}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},scales:{y:{display:!1,beginAtZero:!0,min:0,max:O===0?1:void 0,grid:{display:!1}},x:{display:!1,grid:{display:!1}}},elements:{point:{radius:0},line:{borderWidth:1.5}},animation:{duration:800}}}))},ne=async()=>{var s;if(!d){a(!0),k(null);try{const r=await fetch(`${t}llm-analytics/v1/send-report`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((s=window.wpApiSettings)==null?void 0:s.nonce)||""}});if(!r.ok)throw new Error(`Error: ${r.status}`);const c=await r.json();c.success?k({type:"success",text:"Analytics report has been sent to your email."}):k({type:"error",text:c.message||"Failed to send analytics report."})}catch(r){console.error("Error sending report:",r),k({type:"error",text:"Failed to send analytics report. Please try again later."})}finally{a(!1),(u==null?void 0:u.type)==="success"&&setTimeout(()=>{k(null)},5e3)}}};x.useEffect(()=>{if(!w&&y.length>0)if(console.log("Attempting to render charts..."),typeof window.Chart>"u"){console.log("Chart.js not found, loading it directly");const s=document.createElement("script");s.src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js",s.async=!0,s.onload=()=>{console.log("Chart.js loaded successfully"),H()},document.head.appendChild(s)}else console.log("Chart.js found, rendering charts"),setTimeout(H,300)},[w,y]);const H=()=>{console.log("Rendering all charts now"),document.getElementById("main-chart")?q():console.error("Main chart canvas not found"),y.forEach(r=>{const c=document.getElementById(`bot-chart-${r.bot_name}`);c?(N.current.set(r.bot_name,c),re(r.bot_name)):console.error(`Canvas element for ${r.bot_name} not found`)})};return e.jsxs("div",{className:"analytics-dashboard-summary",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"LLM Bot Analytics Summary"}),w?e.jsx("div",{className:"p-4",children:"Loading analytics data..."}):E?e.jsx("div",{className:"p-4 text-red-600",children:e.jsx("p",{children:E})}):e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"bg-white p-4 rounded-lg shadow border border-gray-200 mb-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h4",{className:"font-medium",children:"Bot Visits Over Time"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(W,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"7days",checked:i==="7days",onChange:()=>n("7days"),className:"mr-1"}),"Last 7 days"]}),e.jsxs(W,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"30days",checked:i==="30days",onChange:()=>n("30days"),className:"mr-1"}),"Last 30 days"]})]})]}),e.jsx("div",{className:"h-64",children:e.jsx("canvas",{id:"main-chart",height:"300"})})]}),e.jsx("div",{className:"bot-summaries grid grid-cols-1 md:grid-cols-3 gap-4",children:y.map(s=>e.jsxs("div",{className:"overflow-hidden bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsxs("div",{className:"flex items-center mb-2",children:[e.jsx("div",{className:"bot-logo mr-3 bg-white rounded-full p-1 shadow-sm border border-gray-100",children:e.jsx("img",{src:s.logo,alt:`${s.bot_name} logo`,className:"h-10 w-10 object-contain rounded-full",onError:r=>{r.target.src=J,console.log(`Failed to load logo for ${s.bot_name}, using default`)},loading:"lazy"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",children:s.bot_name}),e.jsxs("p",{className:"text-sm text-gray-500",children:["Total visits: ",s.total_visits]})]})]}),e.jsx("div",{className:"h-24 mt-4 border-t pt-2 border-gray-100",children:e.jsx("canvas",{id:`bot-chart-${s.bot_name}`,height:"80"})})]},s.bot_name))}),!D&&e.jsx("div",{className:"absolute inset-0 bg-white/60 backdrop-blur-sm flex flex-col items-center justify-center z-10",style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.6)",backdropFilter:"blur(4px)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10},children:e.jsxs("div",{className:"text-center p-6 max-w-md bg-white rounded-lg shadow-lg",children:[e.jsx("h3",{className:"text-xl font-bold mb-2",children:"Premium Feature"}),e.jsx("p",{className:"mb-4",children:"Access to real analytics data is available in the premium version."}),e.jsx("a",{href:"admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"inline-block px-6 py-3 bg-gradient-to-r from-purple-600 to-pink-600 text-white rounded-lg font-medium shadow-lg hover:from-purple-700 hover:to-pink-700 transition-all",children:"Upgrade Now"})]})})]}),D&&e.jsxs("div",{className:"mt-6 bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Analytics Reports"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Report Email Address"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{id:"report-email",type:"email",value:b,onChange:s=>v(s.target.value),className:"flex-1 px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm",placeholder:"[email protected]"}),e.jsx("button",{onClick:ae,disabled:R,className:"inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500",children:R?"Saving...":"Save"})]}),P&&e.jsx("p",{className:`mt-1 text-xs ${P.type==="success"?"text-green-600":"text-red-600"}`,children:P.text})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{onClick:ne,disabled:d,className:`inline-block px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors ${d?"opacity-70 cursor-not-allowed":""}`,children:d?"Sending...":"Send Analytics Report Now"}),u&&e.jsx("div",{className:`mt-2 p-2 rounded text-sm ${u.type==="success"?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:u.text})]})]})]})]})}function me({data:t,onGenerateNow:L,onImagesChange:D,onSettingsChange:w}){var P,I,G;console.log("Dashboard Data:",{rootPath:t.rootPath,isWritable:t.isWritable,lastGenerated:t.lastGenerated,llmsTxtExists:t.llmsTxtExists,llmsTxtUrl:t.llmsTxtUrl,llmsTxtSize:t.llmsTxtSize,postsCount:t.postsCount,markdownCount:t.markdownCount,settings:t.settings,postTypes:t.postTypes,isPremium:t.isPremium,planData:t.planData,imageData:t.imageData,pluginVersion:t.pluginVersion,wordpressVersion:t.wordpressVersion});const[g,E]=x.useState(!1),[T,S]=x.useState(null),[M,y]=x.useState(t.settings.llm_response_images||[]),[j,i]=x.useState(!1),n=U.useRef(null),d=t.planData.plan_name==="free"?t.settings.post_types.filter(o=>o==="post"||o==="page"):t.settings.post_types,[a,u]=x.useState({post_types:d,full_content:t.settings.full_content,days_to_include:t.settings.days_to_include,delete_on_uninstall:t.settings.delete_on_uninstall});U.useEffect(()=>{function o(N){n.current&&!n.current.contains(N.target)&&i(!1)}return document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o)}},[]);const k=async()=>{E(!0),S(null);try{const o=await L();S({type:o.success?"success":"error",text:o.message}),setTimeout(()=>S(null),5e3)}catch{S({type:"error",text:"An error occurred while generating files."})}finally{E(!1)}},b=o=>{y(o),D(o)},v=(o,N)=>{const f={...a,post_types:N?[...a.post_types,o]:a.post_types.filter(Y=>Y!==o)};u(f),w(f)},R=(o,N)=>{const f={...a,[o]:N};u(f),w(f)},$=o=>{const N=parseInt(o,10),f={...a,days_to_include:isNaN(N)?0:N};u(f),w(f)};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("style",{dangerouslySetInnerHTML:{__html:`
     3${L}`)}});function me({currentImages:t,onImagesChange:L,isPremium:S}){const{toast:_}=ce(),[p,P]=u.useState(!1),[A,C]=u.useState({});G.useEffect(()=>{const r=async()=>{for(const d of t)if(!A[d.id]){const s=wp.media.attachment(d.id);s.fetch().then(()=>{var R,x;const b={id:d.id,url:s.get("url"),preview_url:((x=(R=s.get("sizes"))==null?void 0:R.medium)==null?void 0:x.url)||s.get("url"),width:s.get("width"),height:s.get("height")};C(v=>({...v,[d.id]:b}))})}};t.length>0&&r()},[t]);const T=async r=>{var s,b,R,x;const d=(s=r.target.files)==null?void 0:s[0];if(d){if(!d.type.startsWith("image/")){_({title:"Error",description:"Please select an image file.",variant:"destructive"});return}P(!0);try{const v=new FormData;v.append("action","llmagnet_ai_seo_upload_image"),v.append("nonce",((b=window.llmagnetDashboardData)==null?void 0:b.nonce)||""),v.append("image",d);const $=await(await fetch(((R=window.llmagnetDashboardData)==null?void 0:R.ajaxUrl)||"/wp-admin/admin-ajax.php",{method:"POST",body:v,credentials:"same-origin"})).json();if($.success){const O={id:$.data.attachment_id,position:"after"},W=[...t,O];L(W),C(I=>({...I,[$.data.attachment_id]:$.data})),_({title:"Success",description:"Image uploaded successfully!"})}else _({title:"Upload Error",description:((x=$.data)==null?void 0:x.message)||"Failed to upload image.",variant:"destructive"})}catch(v){console.error("Upload error:",v),_({title:"Upload Error",description:"An error occurred while uploading the image.",variant:"destructive"})}finally{P(!1),r.target.value=""}}},j=()=>{if(typeof wp<"u"&&wp.media){const r=wp.media({title:"Select LLM Response Images",button:{text:"Select Images"},multiple:!0});r.on("select",()=>{const d=r.state().get("selection").toJSON(),s=[],b={};d.forEach(x=>{var v,B;s.push({id:x.id,position:"after"}),b[x.id]={id:x.id,url:x.url,preview_url:((B=(v=x.sizes)==null?void 0:v.medium)==null?void 0:B.url)||x.url,width:x.width,height:x.height}});const R=[...t,...s];L(R),C(x=>({...x,...b})),_({title:"Success",description:`${d.length} image(s) selected successfully!`})}),r.open()}},D=r=>{const d=t.filter(s=>s.id!==r);L(d),C(s=>{const b={...s};return delete b[r],b}),_({title:"Success",description:"Image removed successfully!"})},c=(r,d)=>{const s=t.map(b=>b.id===r?{...b,position:d}:b);L(s)};return S?e.jsxs("div",{className:"space-y-6",children:[t.length>0&&e.jsxs("div",{className:"mb-6 space-y-4",children:[e.jsxs("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:["Current Images (",t.length,")"]}),t.map((r,d)=>{const s=A[r.id];return e.jsxs("div",{className:"flex items-start gap-4 p-4 bg-gradient-to-r from-gray-50 to-gray-100/50 rounded-xl border border-gray-200/60 hover:shadow-md transition-all duration-200",children:[s&&e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:s.preview_url,alt:`LLM Response Image ${d+1}`,className:"w-24 h-24 object-cover rounded-lg border-2 border-white shadow-sm"}),e.jsx("div",{className:"absolute -top-1 -right-1 bg-blue-500 text-white text-xs font-medium px-1.5 py-0.5 rounded-full",children:d+1})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsxs("h6",{className:"font-semibold text-gray-900 mb-1",children:["Image ",d+1]}),s&&e.jsxs("div",{className:"text-sm text-gray-600 bg-white px-2 py-1 rounded-md inline-block",children:[s.width," × ",s.height,"px"]})]}),e.jsx(V,{onClick:()=>D(r.id),variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200",children:"Remove"})]}),e.jsxs("div",{className:"bg-white p-3 rounded-lg border border-gray-200/60",children:[e.jsx(F,{className:"text-sm font-semibold text-gray-700 mb-2 block",children:"Display Position"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${r.id}`,value:"before",checked:r.position==="before",onChange:()=>c(r.id,"before"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Before text"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-md hover:bg-gray-50 transition-colors",children:[e.jsx("input",{type:"radio",name:`position-${r.id}`,value:"after",checked:r.position==="after",onChange:()=>c(r.id,"after"),className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"After text"})]})]})]})]})]},r.id)})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Add New Images"}),e.jsx("div",{className:"flex items-center gap-4 p-3 rounded-xl bg-white/60",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(V,{onClick:j,variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:p,children:"Select from Media Library"}),e.jsxs("div",{className:"relative",children:[e.jsx(te,{type:"file",accept:"image/*",onChange:T,disabled:p,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"}),e.jsx(V,{variant:"outline",className:"px-4 py-2 text-sm font-medium border-gray-300/50 hover:bg-gray-50 hover:border-gray-400",disabled:p,children:p?"Uploading...":"Upload New Image"})]})]})}),e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"You can select multiple images from the media library or upload them one by one."})]})]}):e.jsxs("div",{className:"bg-gray-50 border border-gray-200 rounded-md p-4",children:[e.jsx("h4",{className:"font-medium mb-2 text-gray-700",children:"LLM Response Images (Premium Feature)"}),e.jsx("p",{className:"text-sm text-gray-600 mb-3",children:"Attach multiple images that will be displayed with responses from all Large Language Models (ChatGPT, Claude, Gemini, GPT-4, etc.) and included in the llms.txt file."}),e.jsxs("div",{className:"bg-yellow-50 border border-yellow-200 text-yellow-800 p-3 rounded-md text-sm",children:[e.jsx("strong",{children:"Premium Feature:"})," This feature is available for premium users only. Upgrade to attach multiple images to your LLM responses."]})]})}const z=["ChatGPT","Claude","Bard","Bing","Perplexity","Cohere","Llama","Mistral","Other LLM"];function pe({apiRoot:t,apiNamespace:L,isPremium:S=!1}){const[_,p]=u.useState(!0),[P,A]=u.useState(null),[C,T]=u.useState([]),[j,D]=u.useState([]),[c,r]=u.useState(!1),[d,s]=u.useState("7days"),[b,R]=u.useState(!1),[x,v]=u.useState(null),[B,$]=u.useState(""),[O,W]=u.useState(!1),[I,n]=u.useState(null),k=u.useRef(null),y=u.useRef(null),J=u.useRef(new Map),q=u.useRef(new Map),H=Object.entries({ChatGPT:"openai.com",Claude:"anthropic.com",Bard:"google.com",Bing:"microsoft.com",Perplexity:"perplexity.ai",Cohere:"cohere.ai",Llama:"meta.com",Mistral:"mistral.ai","Other LLM":"ai.com"}).reduce((a,[o,i])=>(a[o]=`https://img.logo.dev/${i}?token=pk_LWY53QLNRjW3a2uzvqdwPg`,a),{}),X={ChatGPT:"#10a37f",Claude:"#6f42c1",Bard:"#4285f4",Bing:"#00a4ef",Perplexity:"#5436da",Cohere:"#ff0080",Llama:"#0668e1",Mistral:"#007bff","Other LLM":"#ff9800"},Y="https://img.logo.dev/ai.com?token=pk_LWY53QLNRjW3a2uzvqdwPg",se=()=>window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"||window.location.hostname.includes(".local")||window.location.hostname.includes(".test"),ae=()=>{const a=[],o=new Date;for(let f=29;f>=0;f--){const l=new Date(o);l.setDate(o.getDate()-f),a.push(l.toISOString().split("T")[0])}const i=[...z],m=[];return i.forEach(f=>{a.forEach(l=>{m.push({bot_name:f,date:l,visits:0})})}),m},re=()=>{const a=[],o=new Date;for(let l=29;l>=0;l--){const g=new Date(o);g.setDate(o.getDate()-l),a.push(g.toISOString().split("T")[0])}const i=[...z],m=[],f=se();return i.forEach(l=>{if(f){let g=l==="ChatGPT"?10:l==="Claude"?8:l==="Bard"?7:l==="Bing"?5:l==="Perplexity"?4:l==="Cohere"?3:l==="Llama"||l==="Mistral"?2:1;a.forEach((E,w)=>{const h=new Date(E).getDay(),M=h===0||h===6?.6:1,N=1+w*.01,K=.7+Math.random()*.6;let U=Math.round(g*M*N*K);U=Math.max(1,U),Math.random()<.1&&(U=Math.round(U*(1.5+Math.random()))),m.push({bot_name:l,date:E,visits:U})})}else{const g=l==="ChatGPT"?8:l==="Claude"?6:l==="Bard"?5:l==="Bing"?4:l==="Other LLM"?2:3;a.forEach(E=>{const w=Math.floor(Math.random()*(g+1));m.push({bot_name:l,date:E,visits:w})})}}),m};u.useEffect(()=>{S&&(async()=>{var o;try{const i=await fetch("/wp-json/llm-analytics/v1/report-email",{headers:{"X-WP-Nonce":((o=window.wpApiSettings)==null?void 0:o.nonce)||""}});if(!i.ok){console.error(`Error fetching report email: ${i.status}`);return}const m=await i.json();m.email&&$(m.email)}catch(i){console.error("Error fetching report email:",i)}})()},[S,t]);const ne=async()=>{var a;if(!O){W(!0),n(null);try{const o=await fetch("/wp-json/llm-analytics/v1/report-email",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((a=window.wpApiSettings)==null?void 0:a.nonce)||""},body:JSON.stringify({email:B})});if(!o.ok)throw new Error(`Error: ${o.status}`);const i=await o.json();i.success?n({type:"success",text:"Report email address saved successfully."}):n({type:"error",text:i.message||"Failed to save email address."})}catch(o){console.error("Error saving report email:",o),n({type:"error",text:"Failed to save email address. Please try again."})}finally{W(!1),(I==null?void 0:I.type)==="success"&&setTimeout(()=>{n(null)},3e3)}}};u.useEffect(()=>{console.log("isPremium status:",S),console.log("API Root:",t),console.log("API Namespace:",L);const a=async()=>{var i;try{console.log("Attempting to fetch data from API...");const m="/wp-json/llm-analytics/v1/stats";console.log("Using endpoint:",m),console.log("WP API Settings:",window.wpApiSettings);const f=((i=window.wpApiSettings)==null?void 0:i.nonce)||"";console.log("Nonce available:",f?"Yes":"No");const l=await fetch(m,{headers:{"X-WP-Nonce":f},credentials:"same-origin"});if(console.log("API Request URL:",m),console.log("API Response Status:",l.status),!l.ok){console.error(`API error: ${l.status}`),o();return}const g=await l.json();console.log("API Response Data:",g);const E=g;if(!E||!Array.isArray(E)||E.length===0){console.log("No analytics data available, using empty data"),o();return}console.log("Valid data received from API, processing..."),T(E);const w=[...z],h={};w.forEach(N=>{h[N]=0}),E.forEach(N=>{h[N.bot_name]!==void 0?h[N.bot_name]+=N.visits:(h[N.bot_name]=N.visits,w.includes(N.bot_name)||w.push(N.bot_name))}),console.log("Bot totals calculated:",h),console.log("All supported bots:",w);const M=w.sort().map(N=>({bot_name:N,total_visits:Number(h[N]||0),logo:H[N]||Y}));r(!0),console.log("Setting hasRealData to true"),D(M),p(!1)}catch(m){console.error("Error fetching analytics data:",m),o()}},o=()=>{console.log("Using empty or mock data as fallback");const i=[...z],m=ae();T(m);const f=i.sort().map(l=>({bot_name:l,total_visits:0,logo:H[l]||Y}));D(f),p(!1),A(null)};if(S)console.log("Premium user detected, fetching real data"),a();else{console.log("Free user detected, generating mock data"),console.log("DEBUG: Attempting to fetch data anyway for debugging"),a();const i=re();T(i);const m=[...z],f={};m.forEach(g=>{f[g]=0}),i.forEach(g=>{f[g.bot_name]!==void 0?f[g.bot_name]+=g.visits:f[g.bot_name]=g.visits});const l=m.sort().map(g=>({bot_name:g,total_visits:f[g]||0,logo:H[g]||Y}));D(l),p(!1)}},[S,t,L]),u.useEffect(()=>{!_&&k.current&&(console.log("Time range changed, re-rendering main chart"),Q())},[d]);const Q=()=>{const a=document.getElementById("main-chart");if(!a){console.error("Main chart canvas not found");return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly");return}console.log("Rendering main chart"),y.current&&y.current.destroy();const o=new Date,i=d==="7days"?7:30,m=new Date(o);m.setDate(o.getDate()-i+1);const f=[];for(let h=0;h<i;h++){const M=new Date(m);M.setDate(m.getDate()+h),f.push(M.toISOString().split("T")[0])}const l=f[0],g=C.filter(h=>h.date>=l),w=Array.from(new Set(C.map(h=>h.bot_name))).sort().map(h=>{const M=f.map(N=>g.filter(U=>U.date===N&&U.bot_name===h).reduce((U,ie)=>U+ie.visits,0));return{label:h,data:M,backgroundColor:X[h]||"#999",borderColor:X[h]||"#999",borderWidth:1.5,tension:.3,fill:!1,pointRadius:2}});y.current=new window.Chart(a,{type:"line",data:{labels:f,datasets:w},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{boxWidth:12,font:{size:10}}},tooltip:{mode:"index",intersect:!1}},scales:{y:{beginAtZero:!0,ticks:{precision:0},grid:{color:"rgba(0, 0, 0, 0.05)"}},x:{ticks:{maxRotation:0,autoSkip:!0,maxTicksLimit:d==="7days"?7:10,font:{size:9}},grid:{display:!1}}},animation:{duration:1e3}}})},oe=a=>{const o=J.current.get(a);if(!o){console.error(`Canvas for ${a} not available`);return}if(typeof window.Chart>"u"){console.error("Chart.js library not loaded properly for bot charts");return}console.log(`Rendering chart for ${a}`),q.current.get(a)&&q.current.get(a).destroy();const i=new Date,m=[];for(let w=6;w>=0;w--){const h=new Date(i);h.setDate(i.getDate()-w),m.push(h.toISOString().split("T")[0])}const f=m[0],l=C.filter(w=>w.bot_name===a&&w.date>=f),g=m.map(w=>l.filter(M=>M.date===w).reduce((M,N)=>M+N.visits,0)),E=Math.max(...g);q.current.set(a,new window.Chart(o,{type:"line",data:{labels:m,datasets:[{label:a,data:g,backgroundColor:X[a]||"#999",borderColor:X[a]||"#999",borderWidth:1.5,tension:.3,pointRadius:0,fill:!1}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},scales:{y:{display:!1,beginAtZero:!0,min:0,max:E===0?1:void 0,grid:{display:!1}},x:{display:!1,grid:{display:!1}}},elements:{point:{radius:0},line:{borderWidth:1.5}},animation:{duration:800}}}))},le=async()=>{var a;if(!b){R(!0),v(null);try{const o=await fetch("/wp-json/llm-analytics/v1/send-report",{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":((a=window.wpApiSettings)==null?void 0:a.nonce)||""}});if(!o.ok)throw new Error(`Error: ${o.status}`);const i=await o.json();i.success?v({type:"success",text:"Analytics report has been sent to your email."}):v({type:"error",text:i.message||"Failed to send analytics report."})}catch(o){console.error("Error sending report:",o),v({type:"error",text:"Failed to send analytics report. Please try again later."})}finally{R(!1),(x==null?void 0:x.type)==="success"&&setTimeout(()=>{v(null)},5e3)}}};u.useEffect(()=>{if(!_&&j.length>0)if(console.log("Attempting to render charts..."),typeof window.Chart>"u"){console.log("Chart.js not found, loading it directly");const a=document.createElement("script");a.src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js",a.async=!0,a.onload=()=>{console.log("Chart.js loaded successfully"),Z()},document.head.appendChild(a)}else console.log("Chart.js found, rendering charts"),setTimeout(Z,300)},[_,j]);const Z=()=>{console.log("Rendering all charts now"),document.getElementById("main-chart")?Q():console.error("Main chart canvas not found"),j.forEach(o=>{const i=document.getElementById(`bot-chart-${o.bot_name}`);i?(J.current.set(o.bot_name,i),oe(o.bot_name)):console.error(`Canvas element for ${o.bot_name} not found`)})};return e.jsxs("div",{className:"analytics-dashboard-summary",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"LLM Bot Analytics Summary"}),_?e.jsx("div",{className:"p-4",children:"Loading analytics data..."}):P?e.jsx("div",{className:"p-4 text-red-600",children:e.jsx("p",{children:P})}):e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"bg-white p-4 rounded-lg shadow border border-gray-200 mb-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h4",{className:"font-medium",children:"Bot Visits Over Time"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(F,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"7days",checked:d==="7days",onChange:()=>s("7days"),className:"mr-1"}),"Last 7 days"]}),e.jsxs(F,{className:"text-sm font-normal",children:[e.jsx("input",{type:"radio",name:"timeRange",value:"30days",checked:d==="30days",onChange:()=>s("30days"),className:"mr-1"}),"Last 30 days"]})]})]}),e.jsx("div",{className:"h-64",children:e.jsx("canvas",{id:"main-chart",height:"300"})})]}),e.jsx("div",{className:"bot-summaries grid grid-cols-1 md:grid-cols-3 gap-4",children:j.map(a=>e.jsxs("div",{className:"overflow-hidden bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsxs("div",{className:"flex items-center mb-2",children:[e.jsx("div",{className:"bot-logo mr-3 bg-white rounded-full p-1 shadow-sm border border-gray-100",children:e.jsx("img",{src:a.logo,alt:`${a.bot_name} logo`,className:"h-10 w-10 object-contain rounded-full",onError:o=>{o.target.src=Y,console.log(`Failed to load logo for ${a.bot_name}, using default`)},loading:"lazy"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",children:a.bot_name}),e.jsxs("p",{className:"text-sm text-gray-500",children:["Total visits: ",Number(a.total_visits)]})]})]}),e.jsx("div",{className:"h-24 mt-4 border-t pt-2 border-gray-100",children:e.jsx("canvas",{id:`bot-chart-${a.bot_name}`,height:"80"})})]},a.bot_name))}),!S&&!c&&e.jsx("div",{className:"absolute inset-0 bg-white/60 backdrop-blur-sm flex flex-col items-center justify-center z-10",style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255, 255, 255, 0.6)",backdropFilter:"blur(4px)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10},children:e.jsxs("div",{className:"text-center p-6 max-w-md bg-white rounded-lg shadow-lg",children:[e.jsx("h3",{className:"text-xl font-bold mb-2",children:"Premium Feature"}),e.jsx("p",{className:"mb-4",children:"Access to real analytics data is available in the premium version."}),e.jsx("a",{href:"admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"inline-block px-6 py-3 bg-gradient-to-r from-purple-600 to-pink-600 text-white rounded-lg font-medium shadow-lg hover:from-purple-700 hover:to-pink-700 transition-all",children:"Upgrade Now"})]})}),!S&&c&&e.jsx("div",{style:{position:"absolute",top:"10px",right:"10px",backgroundColor:"rgba(0, 128, 0, 0.8)",color:"white",padding:"10px",borderRadius:"5px",fontSize:"12px",zIndex:20},children:"Debug Mode: Real data detected and displayed"})]}),S&&e.jsxs("div",{className:"mt-6 bg-white p-4 rounded-lg shadow border border-gray-200",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Analytics Reports"}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Report Email Address"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{id:"report-email",type:"email",value:B,onChange:a=>$(a.target.value),className:"flex-1 px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm",placeholder:"[email protected]"}),e.jsx("button",{onClick:ne,disabled:O,className:"inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500",children:O?"Saving...":"Save"})]}),I&&e.jsx("p",{className:`mt-1 text-xs ${I.type==="success"?"text-green-600":"text-red-600"}`,children:I.text})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{onClick:le,disabled:b,className:`inline-block px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition-colors ${b?"opacity-70 cursor-not-allowed":""}`,children:b?"Sending...":"Send Analytics Report Now"}),x&&e.jsx("div",{className:`mt-2 p-2 rounded text-sm ${x.type==="success"?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:x.text})]})]})]})]})}function ge({data:t,onGenerateNow:L,onImagesChange:S,onSettingsChange:_}){var O,W,I;console.log("Dashboard Data:",{rootPath:t.rootPath,isWritable:t.isWritable,lastGenerated:t.lastGenerated,llmsTxtExists:t.llmsTxtExists,llmsTxtUrl:t.llmsTxtUrl,llmsTxtSize:t.llmsTxtSize,postsCount:t.postsCount,markdownCount:t.markdownCount,settings:t.settings,postTypes:t.postTypes,isPremium:t.isPremium,planData:t.planData,imageData:t.imageData,pluginVersion:t.pluginVersion,wordpressVersion:t.wordpressVersion});const[p,P]=u.useState(!1),[A,C]=u.useState(null),[T,j]=u.useState(t.settings.llm_response_images||[]),[D,c]=u.useState(!1),r=G.useRef(null),d=t.planData.plan_name==="free"?t.settings.post_types.filter(n=>n==="post"||n==="page"):t.settings.post_types,[s,b]=u.useState({post_types:d,full_content:t.settings.full_content,days_to_include:t.settings.days_to_include,delete_on_uninstall:t.settings.delete_on_uninstall});G.useEffect(()=>{function n(k){r.current&&!r.current.contains(k.target)&&c(!1)}return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}},[]);const R=async()=>{P(!0),C(null);try{const n=await L();C({type:n.success?"success":"error",text:n.message}),setTimeout(()=>C(null),5e3)}catch{C({type:"error",text:"An error occurred while generating files."})}finally{P(!1)}},x=n=>{j(n),S(n)},v=(n,k)=>{const y={...s,post_types:k?[...s.post_types,n]:s.post_types.filter(J=>J!==n)};b(y),_(y)},B=(n,k)=>{const y={...s,[n]:k};b(y),_(y)},$=n=>{const k=parseInt(n,10),y={...s,days_to_include:isNaN(k)?0:k};b(y),_(y)};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("style",{dangerouslySetInnerHTML:{__html:`
    44        .premium-tooltip {
    55          position: absolute;
     
    2222          visibility: visible;
    2323        }
    24       `}}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("img",{src:`${((P=window.llmagnetDashboardData)==null?void 0:P.pluginUrl)||""}assets/react-build/assets/banner_upgrade.png`,alt:"LLMagnet AI SEO Optimizer",className:"max-w-full h-auto",onError:o=>{var f;const N=o.target;N.onerror=null,N.src=`${((f=window.llmagnetDashboardData)==null?void 0:f.pluginUrl)||""}src/assets/images/banner_upgrade.png`,console.log("Trying fallback image path:",N.src)}})}),e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-900",children:"LLMagnet Dashboard"}),e.jsx("div",{className:`px-3 py-1 rounded-full text-xs font-semibold ${t.planData.plan_name==="enterprise"?"bg-purple-100 text-purple-800 border border-purple-200":t.planData.plan_name==="pro"?"bg-green-100 text-green-800 border border-green-200":"bg-gray-100 text-gray-600 border border-gray-200"}`,children:t.planData.is_trial?"Trial":t.planData.plan_title})]}),e.jsxs("div",{className:"relative",ref:n,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(z,{onClick:k,disabled:g||!t.isWritable,variant:"gradient",className:"whitespace-nowrap px-4 py-2 text-sm font-medium rounded-r-none",children:g?"Generating...":"Generate Now"}),e.jsx(z,{onClick:()=>i(!j),disabled:g||!t.isWritable,variant:"gradient",className:"px-2 py-2 rounded-l-none border-l border-purple-400",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),j&&e.jsx("div",{className:"absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 border border-gray-200",children:e.jsx("div",{className:"py-1",children:t.llmsTxtExists&&e.jsxs("a",{href:t.llmsTxtUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100",onClick:()=>i(!1),children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}),"View LLMS.txt"]})})})]})]}),e.jsx("p",{className:"text-gray-600",children:"Manage your LLMS.txt file and LLM response settings"})]})}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"Status Overview"}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLMS.txt Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.llmsTxtExists?"text-green-600":"text-red-600"}`,children:t.llmsTxtExists?"Active":"Not Generated"}),t.llmsTxtSize&&e.jsx("div",{className:"text-sm text-gray-500",children:t.llmsTxtSize})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Posts to Export"}),e.jsx("div",{className:"text-lg font-bold text-blue-600 mb-1",children:t.postsCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Content items"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Markdown Files"}),e.jsx("div",{className:"text-lg font-bold text-purple-600 mb-1",children:t.markdownCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Generated files"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLM Images"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${M.length>0?"text-green-600":"text-gray-400"}`,children:M.length}),e.jsx("div",{className:"text-sm text-gray-500",children:"Configured"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Directory Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.isWritable?"text-green-600":"text-red-600"}`,children:t.isWritable?"Writable":"Not Writable"}),e.jsx("div",{className:"text-sm text-gray-500",children:"Root directory"})]})})]}),t.lastGenerated&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200",children:e.jsxs("div",{className:"text-sm text-gray-600",children:[e.jsx("strong",{children:"Last Generated:"})," ",t.lastGenerated]})})]}),T&&e.jsx("div",{className:"mb-4",children:e.jsx("div",{className:`px-4 py-3 rounded-md text-sm ${T.type==="success"?"bg-green-50 text-green-800 border border-green-200":"bg-red-50 text-red-800 border border-red-200"}`,children:T.text})}),!t.isWritable&&e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded-md p-4",children:e.jsxs("p",{className:"text-yellow-800 text-sm",children:[e.jsx("strong",{children:"Warning:"})," Root directory is not writable. Please check file permissions before generating files."]})}),e.jsx("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md mb-6",children:e.jsx(ce,{pluginUrl:((I=window.llmagnetDashboardData)==null?void 0:I.pluginUrl)||"",apiRoot:((G=window.llmagnetDashboardData)==null?void 0:G.ajaxUrl)||"",apiNamespace:"llm-analytics/v1",reportEmail:"",isPremium:t.planData.plan_name!=="free"})}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-3 items-stretch",children:[e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"Content Settings"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Configure which content should be included in the llms.txt file and associated Markdown exports."})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Types to Include"}),e.jsx("div",{className:"space-y-3",children:t.postTypes.map(o=>{const f=!(o.name==="post"||o.name==="page")&&t.planData.plan_name==="free";return e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsxs("div",{className:`relative ${f?"tooltip-trigger":""}`,children:[e.jsx("button",{onClick:()=>!f&&v(o.name,!a.post_types.includes(o.name)),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${a.post_types.includes(o.name)?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"} ${f?"opacity-50 cursor-not-allowed":""}`,disabled:f,"aria-label":f?"Premium feature - Upgrade to enable":`Toggle ${o.label}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${a.post_types.includes(o.name)?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),f&&e.jsx("div",{className:"premium-tooltip -translate-y-full left-0 top-0",children:"Premium feature - Upgrade to enable"})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:o.label}),f&&e.jsxs("div",{className:"tooltip-trigger relative ml-2 bg-amber-100 text-amber-800 text-xs font-medium px-2 py-0.5 rounded cursor-help flex items-center",children:[e.jsx("span",{className:"mr-1",children:"Premium"}),e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"premium-tooltip mt-2 translate-y-1 left-0",children:[e.jsx("p",{className:"mb-2",children:"This post type is available in the premium version."}),e.jsx("a",{href:"/wp-admin/admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"block w-full px-3 py-2 text-center text-white bg-purple-600 rounded-md hover:bg-purple-700 transition-colors",children:"Upgrade Now"})]})]})]})]},o.name)})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Export"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>R("full_content",!a.full_content),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${a.full_content?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${a.full_content?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),e.jsxs("span",{className:"text-sm font-medium text-gray-700",children:["Include full content ",!a.full_content&&"(excerpt only)"]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Time Period"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl bg-white/60",children:[e.jsx("div",{className:"flex-1 max-w-32",children:e.jsx(K,{type:"number",min:"0",value:a.days_to_include,onChange:o=>$(o.target.value),className:"text-center font-semibold border-gray-300/50 focus:border-purple-400 focus:ring-purple-400/20 rounded-xl"})}),e.jsx("span",{className:"text-sm font-medium text-gray-600",children:a.days_to_include>0?"days of content":"all content"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Cleanup on Uninstall"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>R("delete_on_uninstall",!a.delete_on_uninstall),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-red-500/20 ${a.delete_on_uninstall?"bg-red-500 shadow-lg shadow-red-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${a.delete_on_uninstall?"translate-x-6 shadow-red-500/20":"translate-x-1"}`})}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Delete files when plugin is uninstalled"})]})]})]})]}),e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"LLM Response Images"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Select multiple images to display with responses from all Large Language Models. These images will be included in the llms.txt file and will work with ChatGPT, Claude, Gemini, GPT-4, and other LLMs."})]}),e.jsx(de,{currentImages:M,onImagesChange:b,isPremium:!0})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"System Information"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(W,{className:"text-sm font-medium text-gray-700",children:"WordPress Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.wordpressVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(W,{className:"text-sm font-medium text-gray-700",children:"Plugin Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.pluginVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(W,{className:"text-sm font-medium text-gray-700",children:"Root Path"}),e.jsx("code",{className:"text-xs text-gray-600 bg-gray-100 px-2 py-1 rounded",children:t.rootPath})]})]})]})]})}function pe(){const[t,L]=U.useState(!0),[D,w]=U.useState(null),[g,E]=U.useState(null);U.useEffect(()=>{try{window.llmagnetDashboardData?E(window.llmagnetDashboardData):w("Dashboard data not found.")}catch(y){console.error("Error loading dashboard data:",y),w("Error loading dashboard data.")}finally{L(!1)}},[]);const T=async()=>{var y,j;if(!g)return{success:!1,message:"No data available"};try{const i=new FormData;i.append("action","llmagnet_ai_seo_generate_now"),i.append("nonce",g.nonce);const d=await(await fetch(g.ajaxUrl,{method:"POST",body:i,credentials:"same-origin"})).json();return{success:d.success,message:((y=d.data)==null?void 0:y.message)||"Unknown error",timestamp:(j=d.data)==null?void 0:j.timestamp}}catch(i){return console.error("Error generating LLMS.txt:",i),{success:!1,message:"Error generating LLMS.txt. Please check server permissions."}}},S=async y=>{var j;if(g){E(i=>i?{...i,settings:{...i.settings,llm_response_images:y}}:null);try{const i={...g.settings,llm_response_images:y},n=new FormData;n.append("action","llmagnet_ai_seo_save_settings"),n.append("nonce",g.nonce),n.append("settings",JSON.stringify(i));const a=await(await fetch(g.ajaxUrl,{method:"POST",body:n,credentials:"same-origin"})).json();a.success||console.error("Failed to save images setting:",(j=a.data)==null?void 0:j.message)}catch(i){console.error("Error saving images setting:",i)}}},M=async y=>{var j;if(g){E(i=>i?{...i,settings:{...i.settings,...y}}:null);try{const i={...g.settings,...y},n=new FormData;n.append("action","llmagnet_ai_seo_save_settings"),n.append("nonce",g.nonce),n.append("settings",JSON.stringify(i));const a=await(await fetch(g.ajaxUrl,{method:"POST",body:n,credentials:"same-origin"})).json();a.success||console.error("Failed to save settings:",(j=a.data)==null?void 0:j.message)}catch(i){console.error("Error saving settings:",i)}}};return t?e.jsx("div",{className:"p-4",children:"Loading dashboard..."}):D||!g?e.jsx("div",{className:"p-4 text-red-600",children:D||"Unknown error"}):e.jsx("div",{className:"llms-txt-react-app",children:e.jsx("div",{className:"wrap",children:e.jsx(me,{data:g,onGenerateNow:T,onImagesChange:S,onSettingsChange:M})})})}const Z=document.getElementById("llms-txt-dashboard-app");Z&&oe.createRoot(Z).render(e.jsx(pe,{}));
     24      `}}),e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx("img",{src:`${((O=window.llmagnetDashboardData)==null?void 0:O.pluginUrl)||""}assets/react-build/assets/banner_upgrade.png`,alt:"LLMagnet AI SEO Optimizer",className:"max-w-full h-auto",onError:n=>{var y;const k=n.target;k.onerror=null,k.src=`${((y=window.llmagnetDashboardData)==null?void 0:y.pluginUrl)||""}src/assets/images/banner_upgrade.png`,console.log("Trying fallback image path:",k.src)}})}),e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-900",children:"LLMagnet Dashboard"}),e.jsx("div",{className:`px-3 py-1 rounded-full text-xs font-semibold ${t.planData.plan_name==="enterprise"?"bg-purple-100 text-purple-800 border border-purple-200":t.planData.plan_name==="pro"?"bg-green-100 text-green-800 border border-green-200":"bg-gray-100 text-gray-600 border border-gray-200"}`,children:t.planData.is_trial?"Trial":t.planData.plan_title})]}),e.jsxs("div",{className:"relative",ref:r,children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(V,{onClick:R,disabled:p||!t.isWritable,variant:"gradient",className:"whitespace-nowrap px-4 py-2 text-sm font-medium rounded-r-none",children:p?"Generating...":"Generate Now"}),e.jsx(V,{onClick:()=>c(!D),disabled:p||!t.isWritable,variant:"gradient",className:"px-2 py-2 rounded-l-none border-l border-purple-400",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),D&&e.jsx("div",{className:"absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 border border-gray-200",children:e.jsx("div",{className:"py-1",children:t.llmsTxtExists&&e.jsxs("a",{href:t.llmsTxtUrl,target:"_blank",rel:"noopener noreferrer",className:"flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100",onClick:()=>c(!1),children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 mr-2",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("polyline",{points:"10 9 9 9 8 9"})]}),"View LLMS.txt"]})})})]})]}),e.jsx("p",{className:"text-gray-600",children:"Manage your LLMS.txt file and LLM response settings"})]})}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"Status Overview"}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLMS.txt Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.llmsTxtExists?"text-green-600":"text-red-600"}`,children:t.llmsTxtExists?"Active":"Not Generated"}),t.llmsTxtSize&&e.jsx("div",{className:"text-sm text-gray-500",children:t.llmsTxtSize})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Posts to Export"}),e.jsx("div",{className:"text-lg font-bold text-blue-600 mb-1",children:t.postsCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Content items"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Markdown Files"}),e.jsx("div",{className:"text-lg font-bold text-purple-600 mb-1",children:t.markdownCount}),e.jsx("div",{className:"text-sm text-gray-500",children:"Generated files"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"LLM Images"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${T.length>0?"text-green-600":"text-gray-400"}`,children:T.length}),e.jsx("div",{className:"text-sm text-gray-500",children:"Configured"})]})}),e.jsx("div",{className:"flex items-center bg-gray-50 rounded-lg px-4 py-3 min-w-0 flex-1 min-w-[160px]",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium text-gray-600 mb-1",children:"Directory Status"}),e.jsx("div",{className:`text-lg font-bold mb-1 ${t.isWritable?"text-green-600":"text-red-600"}`,children:t.isWritable?"Writable":"Not Writable"}),e.jsx("div",{className:"text-sm text-gray-500",children:"Root directory"})]})})]}),t.lastGenerated&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200",children:e.jsxs("div",{className:"text-sm text-gray-600",children:[e.jsx("strong",{children:"Last Generated:"})," ",t.lastGenerated]})})]}),A&&e.jsx("div",{className:"mb-4",children:e.jsx("div",{className:`px-4 py-3 rounded-md text-sm ${A.type==="success"?"bg-green-50 text-green-800 border border-green-200":"bg-red-50 text-red-800 border border-red-200"}`,children:A.text})}),!t.isWritable&&e.jsx("div",{className:"bg-yellow-50 border border-yellow-200 rounded-md p-4",children:e.jsxs("p",{className:"text-yellow-800 text-sm",children:[e.jsx("strong",{children:"Warning:"})," Root directory is not writable. Please check file permissions before generating files."]})}),e.jsx("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md mb-6",children:e.jsx(pe,{pluginUrl:((W=window.llmagnetDashboardData)==null?void 0:W.pluginUrl)||"",apiRoot:((I=window.llmagnetDashboardData)==null?void 0:I.ajaxUrl)||"",apiNamespace:"llm-analytics/v1",reportEmail:"",isPremium:t.planData.plan_name!=="free"})}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-3 items-stretch",children:[e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"Content Settings"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Configure which content should be included in the llms.txt file and associated Markdown exports."})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Types to Include"}),e.jsx("div",{className:"space-y-3",children:t.postTypes.map(n=>{const y=!(n.name==="post"||n.name==="page")&&t.planData.plan_name==="free";return e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsxs("div",{className:`relative ${y?"tooltip-trigger":""}`,children:[e.jsx("button",{onClick:()=>!y&&v(n.name,!s.post_types.includes(n.name)),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${s.post_types.includes(n.name)?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"} ${y?"opacity-50 cursor-not-allowed":""}`,disabled:y,"aria-label":y?"Premium feature - Upgrade to enable":`Toggle ${n.label}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${s.post_types.includes(n.name)?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),y&&e.jsx("div",{className:"premium-tooltip -translate-y-full left-0 top-0",children:"Premium feature - Upgrade to enable"})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:n.label}),y&&e.jsxs("div",{className:"tooltip-trigger relative ml-2 bg-amber-100 text-amber-800 text-xs font-medium px-2 py-0.5 rounded cursor-help flex items-center",children:[e.jsx("span",{className:"mr-1",children:"Premium"}),e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"premium-tooltip mt-2 translate-y-1 left-0",children:[e.jsx("p",{className:"mb-2",children:"This post type is available in the premium version."}),e.jsx("a",{href:"/wp-admin/admin.php?page=llmagnet-ai-seo-optimizer-pricing",className:"block w-full px-3 py-2 text-center text-white bg-purple-600 rounded-md hover:bg-purple-700 transition-colors",children:"Upgrade Now"})]})]})]})]},n.name)})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Content Export"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>B("full_content",!s.full_content),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500/20 ${s.full_content?"bg-gradient-to-r from-purple-500 to-pink-500 shadow-lg shadow-purple-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${s.full_content?"translate-x-6 shadow-purple-500/20":"translate-x-1"}`})}),e.jsxs("span",{className:"text-sm font-medium text-gray-700",children:["Include full content ",!s.full_content&&"(excerpt only)"]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Time Period"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl bg-white/60",children:[e.jsx("div",{className:"flex-1 max-w-32",children:e.jsx(te,{type:"number",min:"0",value:s.days_to_include,onChange:n=>$(n.target.value),className:"text-center font-semibold border-gray-300/50 focus:border-purple-400 focus:ring-purple-400/20 rounded-xl"})}),e.jsx("span",{className:"text-sm font-medium text-gray-600",children:s.days_to_include>0?"days of content":"all content"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-4 text-sm text-gray-800 uppercase tracking-wide",children:"Cleanup on Uninstall"}),e.jsxs("div",{className:"flex items-center gap-4 p-2 rounded-xl hover:bg-white/60 transition-all duration-300",children:[e.jsx("button",{onClick:()=>B("delete_on_uninstall",!s.delete_on_uninstall),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-red-500/20 ${s.delete_on_uninstall?"bg-red-500 shadow-lg shadow-red-500/25":"bg-gray-300 hover:bg-gray-400"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-all duration-300 shadow-md ${s.delete_on_uninstall?"translate-x-6 shadow-red-500/20":"translate-x-1"}`})}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Delete files when plugin is uninstalled"})]})]})]})]}),e.jsxs("div",{className:"bg-gradient-to-br from-white to-gray-50/50 border border-gray-200/60 shadow-lg backdrop-blur-sm p-7 rounded-2xl w-full max-w-2xl flex-shrink-0",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-xl font-semibold mb-2 text-gray-900 tracking-tight",children:"LLM Response Images"}),e.jsx("p",{className:"text-gray-500 text-sm leading-relaxed",children:"Select multiple images to display with responses from all Large Language Models. These images will be included in the llms.txt file and will work with ChatGPT, Claude, Gemini, GPT-4, and other LLMs."})]}),e.jsx(me,{currentImages:T,onImagesChange:x,isPremium:!0})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 shadow-sm p-6 rounded-md",children:[e.jsx("h3",{className:"text-lg font-medium mb-4",children:"System Information"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(F,{className:"text-sm font-medium text-gray-700",children:"WordPress Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.wordpressVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(F,{className:"text-sm font-medium text-gray-700",children:"Plugin Version"}),e.jsx("span",{className:"text-sm text-gray-600",children:t.pluginVersion})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(F,{className:"text-sm font-medium text-gray-700",children:"Root Path"}),e.jsx("code",{className:"text-xs text-gray-600 bg-gray-100 px-2 py-1 rounded",children:t.rootPath})]})]})]})]})}function he(){const[t,L]=G.useState(!0),[S,_]=G.useState(null),[p,P]=G.useState(null);G.useEffect(()=>{try{window.llmagnetDashboardData?P(window.llmagnetDashboardData):_("Dashboard data not found.")}catch(j){console.error("Error loading dashboard data:",j),_("Error loading dashboard data.")}finally{L(!1)}},[]);const A=async()=>{var j,D;if(!p)return{success:!1,message:"No data available"};try{const c=new FormData;c.append("action","llmagnet_ai_seo_generate_now"),c.append("nonce",p.nonce);const d=await(await fetch(p.ajaxUrl,{method:"POST",body:c,credentials:"same-origin"})).json();return{success:d.success,message:((j=d.data)==null?void 0:j.message)||"Unknown error",timestamp:(D=d.data)==null?void 0:D.timestamp}}catch(c){return console.error("Error generating LLMS.txt:",c),{success:!1,message:"Error generating LLMS.txt. Please check server permissions."}}},C=async j=>{var D;if(p){P(c=>c?{...c,settings:{...c.settings,llm_response_images:j}}:null);try{const c={...p.settings,llm_response_images:j},r=new FormData;r.append("action","llmagnet_ai_seo_save_settings"),r.append("nonce",p.nonce),r.append("settings",JSON.stringify(c));const s=await(await fetch(p.ajaxUrl,{method:"POST",body:r,credentials:"same-origin"})).json();s.success||console.error("Failed to save images setting:",(D=s.data)==null?void 0:D.message)}catch(c){console.error("Error saving images setting:",c)}}},T=async j=>{var D;if(p){P(c=>c?{...c,settings:{...c.settings,...j}}:null);try{const c={...p.settings,...j},r=new FormData;r.append("action","llmagnet_ai_seo_save_settings"),r.append("nonce",p.nonce),r.append("settings",JSON.stringify(c));const s=await(await fetch(p.ajaxUrl,{method:"POST",body:r,credentials:"same-origin"})).json();s.success||console.error("Failed to save settings:",(D=s.data)==null?void 0:D.message)}catch(c){console.error("Error saving settings:",c)}}};return t?e.jsx("div",{className:"p-4",children:"Loading dashboard..."}):S||!p?e.jsx("div",{className:"p-4 text-red-600",children:S||"Unknown error"}):e.jsx("div",{className:"llms-txt-react-app",children:e.jsx("div",{className:"wrap",children:e.jsx(ge,{data:p,onGenerateNow:A,onImagesChange:C,onSettingsChange:T})})})}const ee=document.getElementById("llms-txt-dashboard-app");ee&&de.createRoot(ee).render(e.jsx(he,{}));
    2525//# sourceMappingURL=dashboard.js.map
  • llmagnet-llm-txt-generator/trunk/includes/class-admin.php

    r3364798 r3365400  
    554554                    'wordpressVersion' => get_bloginfo('version'),
    555555                    'pluginUrl' => LLMAGNET_AISEO_PLUGIN_URL,
     556                ]);
     557               
     558                // Add WordPress REST API settings with nonce for REST API calls
     559                wp_localize_script('llmagnet-dashboard', 'wpApiSettings', [
     560                    'root' => esc_url_raw(rest_url()),
     561                    'nonce' => wp_create_nonce('wp_rest')
    556562                ]);
    557563            }
  • llmagnet-llm-txt-generator/trunk/includes/class-analytics.php

    r3365069 r3365400  
    3535        // Add hook to detect and log LLM bot visits
    3636        add_action('init', [$this, 'detect_and_log_llm_bot'], 1);
     37       
     38        // Add a test function to verify hooks are working
     39        add_action('wp_footer', function() {
     40            // Get the current user agent
     41            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Unknown';
     42           
     43            // Call the bot detection directly
     44            $bot_name = $this->identify_llm_bot($user_agent);
     45           
     46            $this->detect_and_log_llm_bot();
     47
     48            // echo '<div style="position: fixed; bottom: 0; left: 0; right: 0; background: #ff5722; color: #fff; padding: 10px; z-index: 9999; font-family: monospace;">';
     49            // echo 'HOOK TEST: Analytics class initialized. Current time: ' . current_time('mysql');
     50            // echo '<br>DIRECT TEST: detect_and_log_llm_bot should have been called on init hook.';
     51            // echo '<br>USER AGENT: ' . esc_html($user_agent);
     52            // echo '<br>BOT DETECTION TEST: ' . ($bot_name ? '<strong>Bot detected: ' . esc_html($bot_name) . '</strong>' : 'No bot detected');
     53            // echo '<br><button onclick="this.parentNode.style.height=\'auto\'" style="background:#fff; color:#ff5722; border:none; padding:5px 10px; margin-top:5px; cursor:pointer; border-radius:3px;">Show More</button>';
     54            // echo '</div>';
     55           
     56           
     57            // Force a direct call to the function for testing
     58            // echo '<script>
     59            //     console.log("Forcing direct call to detect_and_log_llm_bot");
     60            //     fetch("?llm_test=1&time=' . time() . '");
     61            // </script>';
     62        });
     63       
     64        // Add a direct test endpoint
     65        if (isset($_GET['llm_test'])) {
     66            // This bypasses the normal WordPress flow
     67            $this->detect_and_log_llm_bot();
     68            if (!headers_sent()) {
     69                header('Content-Type: application/json');
     70                echo json_encode(['success' => true, 'message' => 'Test completed']);
     71                exit;
     72            }
     73        }
    3774       
    3875        // Register REST API endpoints
     
    68105     */
    69106    public function detect_and_log_llm_bot() {
    70         // Skip if in admin area or AJAX request
    71         if (is_admin() || wp_doing_ajax() || wp_doing_cron()) {
     107        // DIRECT DEBUG OUTPUT - will show on all pages regardless of hooks
     108        echo '<!-- LLM BOT DETECTION FUNCTION CALLED -->';
     109       
     110        // Check if we're in a test context
     111        $is_test = isset($_GET['llm_test']);
     112       
     113        // Skip if in admin area or AJAX request (unless it's a test)
     114        if (!$is_test && (is_admin() || wp_doing_ajax() || wp_doing_cron())) {
     115            echo '<!-- SKIPPED: Admin/AJAX/Cron request -->';
    72116            return;
    73117        }
     
    75119        // Check if user agent exists
    76120        if (!isset($_SERVER['HTTP_USER_AGENT'])) {
     121            echo '<!-- SKIPPED: No User Agent -->';
    77122            return;
    78123        }
     
    80125        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
    81126        $bot_name = $this->identify_llm_bot($user_agent);
     127       
     128        // DIRECT DEBUG OUTPUT - will show on all pages
     129        echo '<!-- USER AGENT: ' . esc_html($user_agent) . ' -->';
     130        echo '<!-- BOT DETECTED: ' . ($bot_name ? esc_html($bot_name) : 'NONE') . ' -->';
     131       
     132        // // Add direct output to page body
     133        // echo '<div id="llm-bot-debug" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.8); color: #fff; padding: 20px; z-index: 99999; font-family: monospace; border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.5); max-width: 80%;">';
     134        // echo '<h3 style="margin-top: 0; color: #ff5722;">LLM Bot Detection Debug</h3>';
     135        // echo '<p><strong>Function called:</strong> detect_and_log_llm_bot()</p>';
     136        // echo '<p><strong>User Agent:</strong> ' . esc_html($user_agent) . '</p>';
     137        // echo '<p><strong>Bot Detected:</strong> ' . ($bot_name ? '<span style="color: #4caf50; font-weight: bold;">' . esc_html($bot_name) . '</span>' : '<span style="color: #f44336;">None</span>') . '</p>';
     138        // echo '<p><strong>Time:</strong> ' . current_time('mysql') . '</p>';
     139        // echo '<button onclick="document.getElementById(\'llm-bot-debug\').style.display=\'none\'" style="background: #ff5722; color: white; border: none; padding: 5px 10px; cursor: pointer; border-radius: 3px;">Close</button>';
     140        // echo '</div>';
     141       
     142        // Also log to error log for headless requests
     143        error_log('LLM Bot Detection Function Called: ' . ($bot_name ? 'Bot detected: ' . $bot_name : 'No bot detected') . ' | User Agent: ' . $user_agent);
    82144
    83145        if ($bot_name) {
    84             $this->log_bot_visit($bot_name, $user_agent);
     146            $result = $this->log_bot_visit($bot_name, $user_agent);
     147            echo '<!-- DATABASE INSERT: ' . ($result ? 'SUCCESS' : 'FAILED') . ' -->';
    85148        }
    86149    }
     
    120183     * @param string $bot_name Bot name
    121184     * @param string $user_agent User agent string
    122      * @return void
     185     * @return bool True if successful, false otherwise
    123186     */
    124187    private function log_bot_visit($bot_name, $user_agent) {
    125188        global $wpdb;
    126189       
    127         $wpdb->insert(
     190        $result = $wpdb->insert(
    128191            $this->table_name,
    129192            [
     
    133196            ['%s', '%s']
    134197        );
     198       
     199        if ($result === false) {
     200            error_log('LLM Bot Database Insert Failed: ' . $wpdb->last_error);
     201        }
     202       
     203        return $result !== false;
    135204    }
    136205
  • llmagnet-llm-txt-generator/trunk/llmagnet-ai-seo-optimizer.php

    r3365069 r3365400  
    1212 * Plugin URI:        https://llmagnet.com
    1313 * Description:       Automatically creates and maintains an llms.txt file and associated Markdown files for LLM crawlers.
    14  * Version:           2.0.1
     14 * Version:           2.0.2
    1515 * Requires at least: 6.0
    1616 * Requires PHP:      8.0
     
    2929
    3030// Define plugin constants
    31 define('LLMAGNET_AISEO_VERSION', '2.0.1');
     31define('LLMAGNET_AISEO_VERSION', '2.0.2');
    3232define('LLMAGNET_AISEO_PLUGIN_DIR', plugin_dir_path(__FILE__));
    3333define('LLMAGNET_AISEO_PLUGIN_URL', plugin_dir_url(__FILE__));
  • llmagnet-llm-txt-generator/trunk/readme.txt

    r3365069 r3365400  
    44Requires at least: 6.0
    55Tested up to: 6.8
    6 Stable tag: 2.0.1
     6Stable tag: 2.0.2
    77Requires PHP: 8.0
    88License: GPLv2 or later
     
    109109== Changelog ==
    110110
     111= 2.0.2 =
     112* Fix analytics dhasboard
     113
     114= 2.0.0 =
     115* Add analytics per llm bot agent
     116* Improve detect llms user-agent
     117* Add email report
     118
    111119= 1.0.8 =
    112120* Add Freemius SDK bootstrap and autoload guard
Note: See TracChangeset for help on using the changeset viewer.