1import{j as e,u as rt,r as C,a as Dt}from"./react-vendor-Cw2rj2c7.js";import{c as Le,t as S,b as v,s as me,M as R,a9 as Rt,B as j,j as At,u as It,g as Ht,i as Ft,k as Ke,h as ie,C as G,w as q,L as H,D as oe,z as Lt,P as le,S as Ge,p as Et}from"./main-BUfwPRuc.js";import{T as Ot,a as Bt,b as V,c as zt}from"./tabs-D73gLUm7.js";import{u as he}from"./useMutation-CAKW8DkJ.js";import{t as $t}from"./after-paint-DlOAbvpA.js";import{T as Ut,a as Yt,b as qe,c as z,d as Kt,e as $}from"./table-BEJR6EKI.js";import{I as xe}from"./input-C9sO-jyd.js";import{T as Ve}from"./textarea-CCnckY2U.js";import{I as ce}from"./info-tip-fi6ZTZFs.js";import{S as _e,E as Gt}from"./skeleton-afAWPbFm.js";import{A as Se,a as ke,g as Te,b as Me,c as Pe,d as De,e as Re,f as Ae}from"./alert-dialog-D7GaoqIR.js";import{D as qt,a as Vt,b as Xt,e as Jt,c as Xe}from"./dropdown-menu-C6P1TNR6.js";import{c as Qt,e as Zt,g as Je,m as Qe,a as de,b as Wt,f as Fe,r as es}from"./published-url-SJE_lReL.js";import{g as ts}from"./wordpress-connection-Dz9HJ69e.js";import{T as ss,u as ns}from"./use-recommendation-counts-BhsqUyBE.js";import{C as it}from"./clock-DQkWBdsK.js";import{A as as}from"./arrow-right-Dj1eof4E.js";import{X as rs}from"./x-BPMOWgoe.js";import{e as is,A as Ie}from"./articles-view-switch-CzLDAlBu.js";import{X as ue}from"./x-circle-DEL5q5oi.js";import{A as Ze}from"./arrow-left-BSffJPMe.js";import{C as We}from"./copy-CXOG8E98.js";import{G as X}from"./globe-DFvzWVdB.js";import{S as os}from"./search-aW8k2ckt.js";import{B as J}from"./bot-DXx2_CDb.js";import"./index-DgBybkPx.js";import"./index-DHXvX4xE.js";import"./chevron-right-BPkCpY8S.js";import"./circle-Dik_iVf1.js";import"./image-D7zqNXJb.js";import"./trash-2-sCOoqYXA.js";/** 2 * @license lucide-react v0.344.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const et=Le("FileClock",[["path",{d:"M16 22h2a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"37hlfg"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"8",cy:"16",r:"6",key:"10v15b"}],["path",{d:"M9.5 17.5 8 16.25V14",key:"1o80t2"}]]);/** 7 * @license lucide-react v0.344.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const He=Le("RefreshCcw",[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]);/** 12 * @license lucide-react v0.344.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const tt=Le("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a2.121 2.121 0 1 1 3 3L12 15l-4 1 1-4Z",key:"1lpok0"}]]);function fe(t,u){const d=S(t),h=S(u),o=d.getTime()-h.getTime();return o<0?-1:o>0?1:o}function ls(t){return Qt(t,Date.now())}function cs(t,u){const d=S(t),h=S(u),o=d.getFullYear()-h.getFullYear(),g=d.getMonth()-h.getMonth();return o*12+g}function ds(t){return u=>{const h=(t?Math[t]:Math.trunc)(u);return h===0?0:h}}function us(t,u){return+S(t)-+S(u)}function ms(t){const u=S(t);return u.setHours(23,59,59,999),u}function hs(t){const u=S(t);return+ms(u)==+is(u)}function xs(t,u){const d=S(t),h=S(u),o=fe(d,h),g=Math.abs(cs(d,h));let f;if(g<1)f=0;else{d.getMonth()===1&&d.getDate()>27&&d.setDate(30),d.setMonth(d.getMonth()-o*g);let x=fe(d,h)===-o;hs(S(t))&&g===1&&fe(t,h)===1&&(x=!1),f=o*(g-Number(x))}return f===0?0:f}function fs(t,u,d){const h=us(t,u)/1e3;return ds(d==null?void 0:d.roundingMethod)(h)}function gs(t,u,d){const h=Wt(),o=(d==null?void 0:d.locale)??h.locale??Zt,g=2520,f=fe(t,u);if(isNaN(f))throw new RangeError("Invalid time value");const x=Object.assign({},d,{addSuffix:d==null?void 0:d.addSuffix,comparison:f});let l,w;f>0?(l=S(u),w=S(t)):(l=S(t),w=S(u));const k=fs(w,l),Z=(Je(w)-Je(l))/1e3,_=Math.round((k-Z)/60);let A;if(_<2)return d!=null&&d.includeSeconds?k<5?o.formatDistance("lessThanXSeconds",5,x):k<10?o.formatDistance("lessThanXSeconds",10,x):k<20?o.formatDistance("lessThanXSeconds",20,x):k<40?o.formatDistance("halfAMinute",0,x):k<60?o.formatDistance("lessThanXMinutes",1,x):o.formatDistance("xMinutes",1,x):_===0?o.formatDistance("lessThanXMinutes",1,x):o.formatDistance("xMinutes",_,x);if(_<45)return o.formatDistance("xMinutes",_,x);if(_<90)return o.formatDistance("aboutXHours",1,x);if(_<Qe){const M=Math.round(_/60);return o.formatDistance("aboutXHours",M,x)}else{if(_<g)return o.formatDistance("xDays",1,x);if(_<de){const M=Math.round(_/Qe);return o.formatDistance("xDays",M,x)}else if(_<de*2)return A=Math.round(_/de),o.formatDistance("aboutXMonths",A,x)}if(A=xs(w,l),A<12){const M=Math.round(_/de);return o.formatDistance("xMonths",M,x)}else{const M=A%12,T=Math.trunc(A/12);return M<3?o.formatDistance("aboutXYears",T,x):M<9?o.formatDistance("overXYears",T,x):o.formatDistance("almostXYears",T+1,x)}}function st(t,u){return gs(t,ls(t),u)}const ps=new Set(["success","success_with_warning","draft_saved"]);function js(t){if(!(t!=null&&t.status)||!ps.has(t.status))throw new Error((t==null?void 0:t.message)||"Failed to publish blog post");return t}function nt({getEndpoint:t,successTitle:u,errorTitle:d,onSuccess:h}){return he({mutationFn:async({postId:o,instructions:g})=>{var l;const{data:{session:f}}=await me.auth.getSession();if(!((l=f==null?void 0:f.user)!=null&&l.id))throw v.error("Authentication
16Error",{description:"You must be logged in to proceed."}),new Error("User not authenticated");const x=await fetch(t(o),{method:"POST",headers:{"Content-Type":"application/json","X-User-Id":f.user.id},body:JSON.stringify({instructions:g})});if(!x.ok){let w="Request failed";try{w=(await x.json()).detail||w}catch{}throw new Error(w)}return x.json()},onSuccess:o=>{v.success(u),h==null||h(o)},onError:o=>v.error(d,{description:o.message})})}const U=t=>{if(!t.keywords)return[];if(Array.isArray(t.keywords))return t.keywords;if(typeof t.keywords=="string")try{return JSON.parse(t.keywords)}catch(u){return console.error("Failed to parse keywords string:",u),[t.keywords]}return[]},ys=({blog:t,isEditing:u,onInputChange:d,youtubeUrl:h,onYoutubeUrlChange:o})=>{if(!t)return null;const g=U(t),f=t.content||"",x=l=>{d&&d(l.target.name,l.target.value)};return e.jsxs("div",{className:"bg-white p-6 rounded-lg shadow-md",children:[u?e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{htmlFor:"featured_image",className:"block text-sm font-medium text-slate-700 mb-1",children:"Featured Image URL"}),e.jsx(xe,{type:"text",name:"featured_image",id:"featured_image",value:t.featured_image||"",onChange:x,placeholder:"Enter image URL or leave blank/empty string to remove",className:"w-full"}),t.featured_image&&!t.featured_image.startsWith("http")&&e.jsx("p",{className:"text-xs text-amber-600 mt-1",children:"Consider using an absolute URL (starting with http/https)."}),t.featured_image&&e.jsx("img",{loading:"lazy",src:t.featured_image,alt:"Current Featured Image",className:"mt-2 w-full max-w-xs h-auto object-contain rounded-md"})]}):t.featured_image&&e.jsx("div",{className:"mb-6",children:e.jsx("img",{loading:"lazy",src:t.featured_image,alt:t.title,className:"w-full max-w-full h-auto object-contain rounded-md"})}),u&&o&&e.jsxs("div",{className:"my-6",children:[e.jsx("label",{htmlFor:"youtube_url",className:"block text-sm font-medium text-slate-700 mb-1",children:"YouTube Video URL"}),e.jsx(xe,{type:"text",name:"youtube_url",id:"youtube_url",value:h||"",onChange:l=>o(l.target.value),placeholder:"Enter YouTube video URL or leave blank to remove",className:"w-full"}),h&&!h.includes("youtube.com/")&&!h.includes("youtu.be/")&&e.jsx("p",{className:"text-xs text-amber-600 mt-1",children:"Please enter a valid YouTube URL."}),(()=>{if(h){const l=h.match(/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/),w=l?l[1]:null;if(w)return e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-sm font-medium text-slate-700 mb-2",children:"Video Preview:"}),e.jsx("div",{className:"aspect-video",children:e.jsx("iframe",{width:"100%",height:"100%",src:`https://www.youtube.com/embed/${w}`,title:"YouTube video player preview",style:{border:0},allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,className:"rounded-md"})})]})}return null})()]}),u&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"title",className:"block text-sm font-medium text-slate-700 mb-1",children:"Title"}),e.jsx(xe,{type:"text",name:"title",id:"title",value:t.title,onChange:x,className:"text-3xl font-bold w-full"})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-6 text-sm text-slate-500",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(it,{className:"w-4 h-4 mr-1"}),t.created_at&&e.jsxs("span",{children:["Created ",Fe(new Date(t.created_at),"MMM d, yyyy")]})]}),u?g.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("label",{className:"w-full block text-sm font-medium text-slate-700 mb-1",children:"Keywords (read-only)"}),g.map((l,w)=>{const k=typeof l=="string"?l:l&&typeof l=="object"&&"keyword"in l?l.keyword:JSON.stringify(l).substring(0,15)+"...";return e.jsx(R,{variant:"outline",className:"bg-slate-100",children:k},w)})]}):g.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:g.map((l,w)=>{const k=typeof l=="string"?l:l&&typeof l=="object"&&"keyword"in l?l.keyword:JSON.stringify(l).substring(0,15)+"...";return e.jsx(R,{variant:"outline",className:"bg-slate-100",children:k},w)})}),t.volume&&!u&&e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"font-medium mr-2",children:"Volume:"}),t.volume]}),t.difficulty&&!u&&e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"font-medium mr-2",children:"Difficulty:"}),e.jsx("span",{className:t.difficulty<33?"text-green-600":t.difficulty<66?"text-yellow-600":"text-red-600",children:t.difficulty})]})]}),u?e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{htmlFor:"content",className:"block text-sm font-medium text-slate-700 mb-1",children:"Content"}),e.jsx(ss,{content:t.content||"",onChange:l=>
16{d&&d("content",l)},editable:u})]}):e.jsx("div",{className:"prose prose-slate max-w-none prose-a:text-blue-600 hover:prose-a:text-blue-700 dark:prose-a:text-blue-400 dark:hover:prose-a:text-blue-500",dangerouslySetInnerHTML:{__html:f}}),u?e.jsx("div",{className:"mt-8 pt-6 border-t border-slate-200 space-y-6",children:e.jsxs("div",{children:[e.jsx("label",{htmlFor:"meta_description",className:"block text-sm font-medium text-slate-700 mb-1",children:"Meta Description"}),e.jsx("textarea",{name:"meta_description",id:"meta_description",value:t.meta_description||"",onChange:x,rows:3,className:"w-full p-2 border border-slate-300 rounded-md",placeholder:"Enter meta description..."})]})}):e.jsx("div",{className:"mt-8 pt-6 border-t border-slate-200 space-y-6",children:t.meta_description&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900 mb-2",children:"Meta Description:"}),e.jsx("p",{className:"text-sm text-slate-600 italic",children:t.meta_description})]})})]})};function at(t){if(typeof window>"u")return null;try{const u=window.localStorage.getItem(t);if(!u)return null;const d=JSON.parse(u);return typeof d.count=="number"?d.count:null}catch{return null}}function bs({websiteId:t}){const[,u]=rt(),d=C.useMemo(()=>`content-health-banner-dismissed-${t??"unknown"}`,[t]),[h,o]=C.useState(()=>at(d)),{data:g,isError:f,isLoading:x}=ns(t),l=(g==null?void 0:g.counts.pending)??0;if(C.useEffect(()=>{o(at(d))},[d]),!t||x||f||l<=0||h!==null&&l<=h)return null;const w=()=>{try{window.localStorage.setItem(d,JSON.stringify({count:l}))}catch{}o(l)};return e.jsxs("div",{className:"flex flex-col gap-3 rounded-md border border-emerald-200 bg-emerald-50 px-4 py-3 text-emerald-900 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx(Rt,{className:"mt-0.5 h-5 w-5 shrink-0"}),e.jsxs("p",{className:"text-sm font-medium",children:["Fix old articles: ",l," issue",l===1?"":"s"," found across your published pages"]})]}),e.jsxs("div",{className:"flex items-center gap-2 self-start sm:self-auto",children:[e.jsxs(j,{size:"sm",className:"bg-emerald-700 hover:bg-emerald-800",onClick:()=>u("/overview?tab=recommendations"),children:["Review",e.jsx(as,{className:"h-4 w-4"})]}),e.jsx(j,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-emerald-900 hover:bg-emerald-100","aria-label":"Dismiss Fix old articles banner",onClick:w,children:e.jsx(rs,{className:"h-4 w-4"})})]})]})}const Q=t=>t?{wix:"Wix",wordpress:"WordPress",hubspot:"HubSpot",webflow:"Webflow",shopify:"Shopify",magento:"Magento",ghost:"Ghost",blogger:"Blogger"}[t.toLowerCase()]||t:"Website",ws=new Set(["wordpress","wix"]);function Ws(){var Ue,Ye;console.log("Content History - Component initializing");const{selectedWebsite:t,isWebsitesLoading:u}=At(),{subscription:d}=It(),h=!!d,o=Ht(),[g,f]=rt(),l=Dt().blogId,w=C.useRef(null);console.log("Content History - Selected website:",t),console.log("Content History - Current URL (raw from useLocation):",g),console.log("Content History - Blog ID from params:",l);const k=typeof g=="string"?g.split("?")[1]:"",Z=new URLSearchParams(k||""),_=Z.get("highlight")?parseInt(Z.get("highlight"),10):null;console.log("Content History - Parsed highlight ID (query param):",_);const[A,M]=C.useState(""),[T,ot]=C.useState("all"),F=Ft(),[ge,lt]=C.useState(25),[L,pe]=C.useState(!1),[E,B]=C.useState(null),[je,Y]=C.useState(""),[ct,W]=C.useState(!1),[Ee,ye]=C.useState(null),[dt,ee]=C.useState(!1),[ut,te]=C.useState(!1),[se,O]=C.useState(""),mt=async s=>{const a=navigator.clipboard;if(a&&"write"in a&&typeof window<"u"&&"ClipboardItem"in window){const N=window.ClipboardItem,c=new Blob([s],{type:"text/html"}),p=new Blob([s],{type:"text/plain"}),b=new N({"text/html":c,"text/plain":p});await a.write([b]);return}if(a!=null&&a.writeText){await a.writeText(s);return}const i=document.createElement("textarea");i.value=s,i.setAttribute("readonly",""),i.style.position="fixed",i.style.top="-9999px",document.body.appendChild(i),i.select();const m=document.execCommand("copy");if(document.body.removeChild(i),!m)throw new Error("Copy command was unsuccessful")},{data:n}=Ke({queryKey:[`/api/websites/${t==null?void 0:t.id}`],enabled:!!(t!=null&&t.id)}),{data:y,isLoading:Oe,error:Be}=Ke({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-drafts`],enabled:!!(t!=null&&t.id)}),r=l&&y?y.find(s=>s.id===parseInt(l,10)):null;C.useEffect(()=>{if(y&&(console.log("Content History - Blog posts loaded:",y.length),y.length>0&&console.log("Content History - Sample post:",y[0])),r)if(console.log("Content History - Now displaying blog:",r.title),B(r),console.log("Content History - Initialized editedBlog for:",r.title),r.content){const s=/<iframe[^>]+src="https?:\/\/(?:www\.)?youtube\.com\/embed\/([^"?]+)[^>]*><\/iframe>/,a=r.content.match(s);a&&a[1]?(Y(`https://www.youtube.com/embed/${a[1]}`),console.log("Content History - Extracted YouTube URL:",`https://www.youtube.com/embed/${a[1]}`)):(Y(""),console.log("Content History - No YouTube URL found in content."))}else Y(""),console.log("Content History - No content to parse for YouTube URL.");else B(null),Y("")},[y,r]),C.useEffect(()=>{if(y&&y.length>0&&(console.log("Content History - Blog post sample:",y[0]),y[0].keywords))if(console.log("Content History - Keywords raw:",y[0].keywords),console.log("Content History - Keywords type:",typeof y[0].keywords),typeof y[0].keywords=="string")try{const s=JSON.parse(y[0].keywords);console.log("Content History - Parsed keywords:",s)}catch{console.error("Failed to parse keywords as JSON")}else Array.isArray(y[0].keywords)&&y[0].keywords.length>0&&console.log("Content History - First keyword type:",typeof y[0].keywords[0])},[y]);const ht=(n==null?void 0:n.platform)==="hubspot"&&(n==null?void 0:n.hubspot_access_token)&&(n==null?void 0:n.hubspot_content_group_id),xt=(n==null?void 0:n.platform)==="wordpress"&&ts(n).isConnected,ft=(n==null?void 0:n.platform)==="webflow"&&(n==null?void 0:n.webflow_api_key)&&(n==null?void 0:n.webflow_site_id),gt=(n==null?void 0:n.platform)==="shopify"&&(n==null?void 0:n.shopify_store_name)&&(n==null?void 0:n.shopify_access_token),pt=(n==null?void 0:n.platform)==="duda"&&!!(n!=null&&n.duda_rss_api_key),jt=(n==null?void 0:n.platform)==="magento"&&!!(n!=null&&n.magento_base_url)&&(!!(n!=null&&n.magento_access_token)||!!(n!=null&&n.magento_username)&&!!(n!=null&&n.magento_password)),yt=(n==null?void 0:n.platform)==="ghost"&&(n==null?void 0:n.ghost_api_url)&&(n==null?void 0:n.ghost_admin_api_key),bt=(n==null?void 0:n.platform)==="wix"&&(n==null?void 0:n.wix_api_key)&&(n==null?void 0:n.wix_site_id),wt=(n==null?void 0:n.platform)==="blogger"&&(n==null?void 0:n.blogger_access_token)&&(n==null?void 0:n.blogger_blog_id),Nt=(n==null?void 0:n.platform)==="gohighlevel"&&(n==null?void 0:n.gohighlevel_location_id)&&(n==null?void 0:n.gohighlevel_access_token),ne=ht||xt||ft||gt||pt||jt||yt||bt||wt||Nt,ae=(n==null?void 0:n.subscription)&&n.subscription.blogs_published_this_month>=n.subscription.monthly_limit,vt=((Ue=n==null?void 0:n.platform)==null?void 0:Ue.toLowerCase())||"",Ct=ws.has(vt),ze=!!(r&&["draft","published_as_draft"].includes(r.status)&&h&&!ne&&!ae);C.useEffect(()=>{const s=`${g}:${(t==null?void 0:t.id)??"none"}:${(r==null?void 0:r.id)??"none"}`;if(!ze){w.current=null;return}w.current!==s&&(w.current=s,ie(o,le.publishWallHit,{reason:"no_cms"}))},[r==null?void 0:r.id,g,o,t==null?void 0:t.id,ze]);const _t=()=>{ie(o,le.paywallHit,{source:"history_publish"}),ie(o,le.publishWallHit,{reason:"no_subscription",source:"history_publish"})},be=he({mutationFn:async s=>{var N;if(!s)throw new Error("No blog data to update");const{data:{session:a}}=await me.auth.getSession();if(!((N=a==null?void 0:a.user)!=null&&N.id))throw v.error("Authentication
16Error",{description:"You must be logged in to update posts.",duration:5e3}),new Error("User not authenticated");const i={title:s.title,content:s.content,meta_description:s.meta_description,featured_image:s.featured_image===""?null:s.featured_image},m=await fetch(`/api/blog-drafts/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json","X-User-Id":a.user.id},body:JSON.stringify(i)});if(!m.ok){const c=await m.json();throw new Error(c.detail||"Failed to update blog post")}return m.json()},onSuccess:s=>{v.success("Blog post updated successfully!"),F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-drafts`]}),F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-status-by-date`]}),pe(!1)},onError:s=>{v.error("Failed to update blog post",{description:s.message})}}),St=()=>{if(E){let s=E.content||"";const a=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,i=/<iframe[^>]+src="https?:\/\/(?:www\.)?youtube\.com\/embed\/[^"?]+[^>]*><\/iframe>/g;if(je){const N=je.match(a);if(N&&N[1]){const p=`<iframe width="100%" height="450" src="https://www.youtube.com/embed/${N[1]}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;if(i.test(s))s=s.replace(i,p),console.log("Content History - Replaced existing YouTube iframe.");else{const b=/<\/h2>/i.exec(s);b?(s=s.slice(0,b.index+5)+p+s.slice(b.index+5),console.log("Content History - Inserted YouTube iframe after first h2.")):(s=p+s,console.log("Content History - Inserted YouTube iframe at the beginning."))}}else s=s.replace(i,""),console.log("Content History - Invalid YouTube URL, removed existing iframe.")}else s=s.replace(i,""),console.log("Content History - No YouTube URL provided, removed existing iframe.");const m={...E,content:s};console.log("Content History - Saving changes for blog:",m.title),console.log("Content History - Payload to save:",{title:m.title,content:m.content,meta_description:m.meta_description,featured_image:m.featured_image}),be.mutate(m)}else v.error("Error saving changes",{description:"No blog data to save. Please try again."}),console.error("Content History - handleSaveChanges called with no editedBlog")},P=he({mutationFn:async({postId:s,publishAsDraft:a=!1})=>{var c;const{data:{session:i}}=await me.auth.getSession();if(!((c=i==null?void 0:i.user)!=null&&c.id))throw v.error("Authentication Error",{description:"You must be logged in to publish posts.",duration:1e4}),new Error("User not authenticated");const m=await fetch(`/api/blog-drafts/${s}/publish`,{method:"POST",headers:{"Content-Type":"application/json","X-User-Id":i.user.id},body:JSON.stringify({website_id:t==null?void 0:t.id,publish_as_draft:a}),credentials:"include"});if(!m.ok){const p=await m.json().catch(()=>({detail:"Failed to publish blog post"})),b=Et(p),D=p==null?void 0:p.detail,I=D&&typeof D=="object"?D:null,Ce=(I==null?void 0:I.message)||(typeof D=="str
16ing"?D:null)||(p==null?void 0:p.message);throw b||m.status===402?new Ge((b==null?void 0:b.message)||Ce||"Your plan isn't active right now. Reactivate to resume publishing."):new Error(Ce||"Failed to publish blog post")}const N=await m.json();return js(N)},onSuccess:(s,a)=>{var D;F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-drafts`]}),F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-status-by-date`]});const i=((D=n==null?void 0:n.platform)==null?void 0:D.toLowerCase())||"",m=es(s),N=(s==null?void 0:s.message)==="Blog marked as published (no CMS integration configured)",c=(s==null?void 0:s.status)==="draft_saved",p=c?"cms_draft":N?"local_only":"cms",b={websiteId:t==null?void 0:t.id,blogId:a.postId,publishedUrl:m||void 0,destination:i||"unknown",delivery:p};if(o&&o.capture("article_published",b),$t("article_published",b),c){const I=Q(n==null?void 0:n.platform);v.success(e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"font-medium",children:["Saved to ",I," as a draft"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Visit your CMS to review and publish this article when you're ready."}),m&&e.jsxs("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:["Open in ",I]})]}));return}if((s==null?void 0:s.status)==="success_with_warning"){v.warning(e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium",children:s.message||"The post was published with a warning"}),m&&e.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"View published post"})]}));return}if(N)v("Blog Marked as Published Locally",{description:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{children:"This blog post has been marked as published in SEOPro AI, but it appears you haven't connected a CMS for this website yet."}),e.jsxs("p",{children:["Please go to ",e.jsx("strong",{children:"Settings > Integrations"})," to connect your ",i||"CMS (e.g., WordPress, HubSpot, Webflow)"," to publish directly."]}),e.jsx(j,{onClick:()=>f("/settings#integrations"),size:"sm",className:"mt-2",children:"Go to Integrations"})]}),duration:1e4});else{const I=i==="wordpress"?"The post has been published to WordPress":i==="hubspot"?"The post has been published to HubSpot":i==="webflow"?"The post has been published to Webflow":i==="shopify"?"The post has been published to Shopify":i==="magento"?"The post has been published to Magento":i==="ghost"?"The post has been published to Ghost":i==="wix"?"The post has been published to Wix":i==="blogger"?"The post has been published to Blogger":i==="gohighlevel"?"The post has been published to GoHighLevel":"The post has been published";v.success(e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium",children:I}),m&&e.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"View published post"})]}))}},onError:s=>{var N;if(s instanceof Ge){ie(o,le.publishWallHit,{reason:"subscription_inactive",source:"publish"}),v.error(s.message);return}const a=s.message,i=((N=n==null?void 0:n.platform)==null?void 0:N.toLowerCase())||"",m=()=>{let c=null;return i==="wordpress"&&a.includes("authentication failed")?c=e.jsxs("ul",{className:"list-disc list-inside mt-2 text-sm",children:[e.jsx("li",{children:"Check if your WordPress credentials are correct"}),e.jsx("li",{children:"Ensure the user has permission to create posts"}),e.jsx("li",{children:"If using 2FA, make sure to use an application password"})]}):i==="webflow"&&a.includes("authentication failed")?c=e.jsxs("ul",{className:"list-disc list-inside mt-2 text-sm",children:[e.jsx("li",{children:"Check if your Webflow API key is valid"}),e.jsx("li",{children:"Ensure the API key has 'Edit and read access' permissions"}),e.jsx("li",{children:"Verify your Site ID is correct"})]}):i==="ghost"&&(a.includes("authentication failed")||a.includes("Invalid Admin API Key")||a.includes("Unauthorized"))&&(c=e.jsxs("ul",{className:"list-disc list-inside mt-2 text-sm",children:[e.jsx("li",{children:"Check if your Ghost Admin API Key and API URL are correct in Settings > Integrations."}),e.jsx("li",{children:"Ensure the Admin API Key has permissions to create posts."}),e.jsx("li",{children:"Verify the API URL points to your Ghost admin domain (e.g., https://yourdomain.ghost.io)."})]})),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{children:a}),c]})};v.error("Failed to publish blog post",{description:m()})}}),K=(s,a=!1)=>{P.mutate({postId:s,publishAsDraft:a})},we=he({mutationFn:async({postId:s,feedback:a})=>{var N;const{data:{session:i}}=await me.auth.getSession();if(!((N=i==null?void 0:i.user)!=null&&N.id))throw v.error("Authentication
16Error",{description:"You must be logged in to reject posts."}),new Error("User not authenticated");const m=await fetch(`/api/blog-drafts/${s}/reject`,{method:"POST",headers:{"Content-Type":"application/json","X-User-Id":i.user.id},body:JSON.stringify({feedback:a}),credentials:"include"});if(!m.ok){const c=await m.json();throw new Error(c.detail||"Failed to reject blog post")}return m.json()},onSuccess:()=>{F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-drafts`]}),F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-status-by-date`]}),v.success("Blog post rejected"),f("/content-history")},onError:s=>v.error("Failed to reject blog post",{description:s.message})}),Ne=nt({getEndpoint:s=>`/api/blog-drafts/${s}/regenerate`,successTitle:"Blog regenerated",errorTitle:"Failed to regenerate blog",onSuccess:s=>{F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-drafts`]}),B(a=>a&&{...a,...s})}}),ve=nt({getEndpoint:s=>`/api/blog-drafts/${s}/regenerate-image`,successTitle:"Blog image regenerated",errorTitle:"Failed to regenerate blog image",onSuccess:s=>{F.invalidateQueries({queryKey:[`/api/websites/${t==null?void 0:t.id}/blog-drafts`]}),B(a=>a&&{...a,featured_image:s.featured_image})}}),re=!y||l?[]:y.filter(s=>{const a=s.title.toLowerCase().includes(A.toLowerCase()),i=T==="all"||s.status===T||T==="draft"&&s.status==="published_as_draft";return a&&i}).sort((s,a)=>new Date(a.created_at).getTime()-new Date(s.created_at).getTime()),$e=(s,a)=>{switch(s){case"published":return e.jsxs(R,{variant:"outline",className:"bg-green-50 text-green-700 border-green-200",children:[e.jsx(oe,{className:"mr-1 h-3 w-3"}),"Published ",a.autopilot_generated&&e.jsx(ce,{label:"autopilot generation",trigger:e.jsx("button",{type:"button","aria-label":"Generated by autopilot",className:"ml-1 inline-flex text-current",children:e.jsx(J,{className:"h-3 w-3"})}),children:"Generated by autopilot"})]});case"scheduled":return e.jsxs(R,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:[e.jsx(it,{className:"mr-1 h-3 w-3"}),"Scheduled for ",a.scheduled_publish_date?Fe(new Date(a.scheduled_publish_date),"MMM d, h:mm a"):"publication"]});case"draft":return e.jsxs(R,{variant:"outline",className:"bg-amber-50 text-amber-700 border-amber-200",children:[e.jsx(tt,{className:"mr-1 h-3 w-3"}),"Draft ",a.autopilot_generated&&e.jsx(ce,{label:"autopilot generation",trigger:e.jsx("button",{type:"button","aria-label":"Generated by autopilot",className:"ml-1 inline-flex text-current",children:e.jsx(J,{className:"h-3 w-3"})}),children:"Generated by autopilot"})]});case"published_as_draft":return e.jsxs(R,{variant:"outline",className:"bg-amber-50 text-amber-700 border-amber-200",children:[e.jsx(et,{className:"mr-1 h-3 w-3"}),"CMS Draft ",a.autopilot_generated&&e.jsx(ce,{label:"autopilot generation",trigger:e.jsx("button",{type:"button","aria-label":"Generated by autopilot",className:"ml-1 inline-flex text-current",children:e.jsx(J,{className:"h-3 w-3"})}),children:"Generated by autopilot"})]});case"rejected":return e.jsxs(R,{variant:"outline",className:"bg-red-50 text-red-700 border-red-200",children:[e.jsx(ue,{className:"mr-1 h-3 w-3"}),"Rejected"]});default:return e.jsx(R,{variant:"outline",children:s})}},kt=s=>s?Fe(new Date(s),"MMM d, yyyy"):"N/A";if(u&&!(t!=null&&t.id))return e.jsxs("div",{className:"mx-auto w-full max-w-3xl space-y-6","data-testid":"content-history-website-loading",children:[e.jsx(_e,{className:"h-8 w-44"}),e.jsx(G,{children:e.jsx(q,{className:"space-y-4 p-6",children:[0,1,2].map(s=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(_e,{className:"h-4 w-32"}),e.jsx(_e,{className:"h-10 w-full"})]},s))})})]});if(!(t!=null&&t.id))return e.jsx("div",{className:"flex justify-center items-center h-[60vh]",children:e.jsx("p",{children:"Please select a website from the sidebar to view content history."})});if(Oe)return e.jsxs("div",{className:"flex justify-center items-center h-[60vh]",children:[e.jsx(H,{className:"h-8 w-8 animate-spin text-primary mr-2"}),e.jsx("p",{children:"Loading content history..."})]});if(Be)return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h1",{className:"text-lg sm:text-xl md:text-2xl font-bold",children:"Content History"}),e.jsx(Ie,{}),e.jsx(G,{className:"border-red-200",children:e.jsxs(q,{className:"flex flex-col items-center justify-center py-8",children:[e.jsx("div",{className:"text-red-500 mb-4",children:e.jsx(ue,{className:"h-12 w-12 mx-auto"})}),e.jsx("p",{className:"text-center font-semibold text-red-600 mb-2",children:"Error loading blog posts"}),e.jsx("p",{className:"text-center text-muted-foreground",children:Be.toString()}),e.jsx(j,{className:"mt-4",onClick:()=>window.location.reload(),children:"Retry"})]})})]});if(!l&&(!y||y.length===0))return console.log("No blog posts found for website:",t==null?void 0:t.id),e.jsxs("div",{className:"space-y-6",children:[e.jsx("h1",{className:"text-lg sm:text-xl md:text-2xl font-bold",children:"Content History"}),e.jsx(Ie,{}),e.jsx(G,{children:e.jsxs(q,{className:"flex flex-col items-center justify-center py-8",children:[e.jsx("p",{className:"text-muted-foreground",children:"No content yet. Generate your first blog post from the Content Planner."}),e.jsx(j,{className:"mt-4",onClick:()=>f("/content-planner"),children:"Go to Content Planner"})]})})]});if(l){if(Oe)return e.jsxs("div",{className:"flex justify-center items-center h-[60vh]",children:[e.jsx(H,{className:"h-8 w-8 animate-spin text-primary mr-2"}),e.jsx("p",{children:"Loading blog post..."})]});if(!r)return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(j,{variant:"outline",onClick:()=>f("/content-history"),children:[e.jsx(Ze,{className:"mr-2 h-4 w-4"})," Back to Content History"]}),e.jsx(G,{children:e.jsxs(q,{className:"flex flex-col items-center justify-center py-8",children:[e.jsx(ue,{className:"h-12 w-12 text-red-500 mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Blog post not found."})]})})]});const s=L&&E?E:r,a=(s==null?void 0:s.content)||"",i=((Ye=s==null?void 0:s.meta_description)==null?void 0:Ye.trim())||"",m=i.length>0,N=!h&&["draft","published_as_draft"].includes(r.status);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(j,{variant:"outline",size:"icon",onClick:()=>{L?(pe(!1),B(r)):f("/content-history")},className:"flex-shrink-0",children:e.jsx(Ze,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!L&&r&&r.status!=="published"?e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>{B(r),pe(!0)},children:[e.jsx(tt,{className:"mr-2 h-4 w-4"}),"Edit Post"]}):L?e.jsx(j,{size:"sm",onClick:St,disabled:be.isPending||!E,children:be.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),"Save Changes"]})}):null,!L&&r&&e.jsxs(e.Fragment,{children:[e.jsxs(j,{variant:"outline",size:"sm",onClick:async()=>
16{if(r&&r.content){const c=` 17 <!-- Begin SEOPro AI Content --> 18 <h1>${r.title}</h1> 19 ${r.featured_image?`<img loading="lazy" src="${r.featured_image}" alt="${r.title}">`:""} 20 ${r.content} 21 <!-- End SEOPro AI Content -->`;try{await mt(c),v("HTML copied to clipboard",{description:"Complete HTML has been copied and can be pasted directly into your CMS."})}catch(p){console.error("Could not copy HTML: ",p),v.error("Error Copying HTML",{description:"Failed to copy HTML to clipboard."})}}},children:[e.jsx(We,{className:"mr-2 h-4 w-4"}),"Copy HTML"]}),e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>{if(r&&r.content){const c=document.createElement("div");c.innerHTML=r.content;const p=c.textContent||c.innerText||"";navigator.clipboard.writeText(p).then(()=>{v("Copied to clipboard",{description:"Content has been copied to clipboard."})}).catch(b=>{console.error("Could not copy text: ",b),v.error("Error Copying Text",{description:"Failed to copy content to clipboard."})})}},children:[e.jsx(We,{className:"mr-2 h-4 w-4"}),"Copy Text"]}),h&&e.jsxs(e.Fragment,{children:[e.jsx(j,{variant:"outline",size:"sm",onClick:()=>{O(""),ee(!0)},disabled:Ne.isPending,children:Ne.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}),"Regenerating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"mr-2 h-4 w-4"}),"Regenerate Blog Content"]})}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>{O(""),te(!0)},disabled:ve.isPending,children:ve.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}),"Regenerating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"mr-2 h-4 w-4"}),"Regenerate Blog Image"]})})]}),!L&&r.status!=="rejected"&&r.status!=="published"&&e.jsx(j,{variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700 border-red-300 hover:border-red-400",onClick:()=>{const c=window.prompt("Optional feedback for rejection:","")??"";we.mutate({postId:r.id,feedback:c})},disabled:we.isPending,children:we.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}),"Rejecting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"mr-2 h-4 w-4"}),"Reject"]})}),N?e.jsxs(j,{size:"sm",className:"bg-green-600 hover:bg-green-700 text-white",onClick:()=>{_t(),f("/pricing?from=preview")},children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"Publish this â start free trial"]}):r.status==="published"?ne&&!ae?e.jsx(j,{size:"sm",className:"bg-green-600 hover:bg-green-700 text-white",onClick:()=>{ye(r.id),W(!0)},disabled:P.isPending,children:P.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}),"Republishing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"mr-2 h-4 w-4"}),"Republish to ",Q(n==null?void 0:n.platform)]})}):e.jsxs(j,{variant:"outline",size:"sm",disabled:!0,className:"bg-white text-slate-700 border-slate-300",children:[e.jsx(oe,{className:"mr-2 h-4 w-4 text-green-500"}),"Published"]}):["draft","published_as_draft"].includes(r.status)&&ne&&!ae&&(Ct?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(j,{size:"sm",className:"bg-green-600 hover:bg-green-700 text-white rounded-r-none",onClick:()=>K(r.id),disabled:P.isPending,children:P.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}),"Publishing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"Publish to ",Q(n==null?void 0:n.platform)]})}),e.jsxs(qt,{children:[e.jsx(Vt,{asChild:!0,children:e.jsx(j,{size:"sm",variant:"outline",className:"bg-green-600 hover:bg-green-700 text-white border-green-700 rounded-l-none px-2",disabled:P.isPending,"aria-label":"Publish options",children:e.jsx(Lt,{className:"h-4 w-4"})})}),e.jsxs(Xt,{align:"end",className:"w-56",children:[e.jsx(Jt,{children:"Publish options"}),e.jsxs(Xe,{className:"flex items-center gap-2",onSelect:c=>{if(P.isPending){c.preventDefault();return}K(r.id)},children:[e.jsx(X,{className:"h-4 w-4"}),"Publish immediately"]}),e.jsxs(Xe,{className:"flex items-center gap-2",onSelect:c=>{if(P.isPending){c.preventDefault();return}K(r.id,!0)},children:[e.jsx(et,{className:"h-4 w-4"}),"Save to CMS as draft"]})]})]})]}):e.jsx(j,{size:"sm",className:"bg-green-600 hover:bg-green-700 text-white",onClick:()=>K(r.id),disabled:P.isPending,children:P.isPending?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"mr-2 h-4 w-4 animate-spin"}),"Publishing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"Publish to ",Q(n==null?void 0:n.platform)]})})),["draft","published_as_draft"].includes(r.status)&&h&&!ne&&!ae&&e.jsxs(j,{variant:"outline",size:"sm",title:"Connect WordPress, Shopify or another platform to publish with one click.",onClick:()=>f("/settings#integrations"),children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"Connect your site to publish"]})]})]})]}),e.jsx(Se,{open:ct,onOpenChange:W,children:e.jsxs(ke,{children:[e.jsxs(Te,{children:[e.jsx(Me,{children:"Republish Blog Post"}),e.jsxs(Pe,{children:["Are you sure you want to republish this post to ",Q(n==null?void 0:n.platform),"? This will update the content on your CMS with the current version."]})]}),e.jsxs(De,{children:[e.jsx(Re,{onClick:()=>{W(!1),ye(null)},children:"Cancel"}),e.jsx(Ae,{onClick:()=>{Ee&&(K(Ee),W(!1),ye(null))},children:"Republish"})]})]})}),e.jsx(Se,{open:dt,onOpenChange:ee,children:e.jsxs(ke,{children:[e.jsxs(Te,{children:[e.jsx(Me,{children:"Regenerate Blog Content"}),e.jsx(Pe,{children:"This will regenerate the entire blog content using AI. The current content will be replaced."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx("label",{htmlFor:"content-instructions",className:"text-sm font-medium",children:"Optional Instructions"}),e.jsx(Ve,{id:"content-instructions",placeholder:"Enter any specific instructions for regenerating the content...",value:se,onChange:c=>O(c.target.value),className:"mt-2",rows:3})]}),e.jsxs(De,{children:[e.jsx(Re,{onClick:()=>{ee(!1),O("")},children:"Cancel"}),e.jsx(Ae,{onClick:()=>{r&&(Ne.mutate({postId:r.id,instructions:se}),ee(!1),O(""))},children:"Regenerate Content"})]})]})}),e.jsx(Se,{open:ut,onOpenChange:te,children:e.jsxs(ke,{children:[e.jsxs(Te,{children:[e.jsx(Me,{children:"Regenerate Blog Image"}),e.jsx(Pe,{children:"This will generate a new featured image for your blog post. The current image will be replaced."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx("label",{htmlFor:"image-instructions",className:"text-sm font-medium",children:"Optional Instructions"}),e.jsx(Ve,{id:"image-instructions",placeholder:"Enter any specific instructions for the image generation...",value:se,onChange:c=>O(c.target.value),className:"mt-2",rows:3})]}),e.jsxs(De,{children:[e.jsx(Re,{onClick:()=>{te(!1),O("")},children:"Cancel"}),e.jsx(Ae,{onClick:()=>{r&&(ve.mutate({postId:r.id,instructions:se}),te(!1),O(""))},children:"Regenerate Image"})]})]})}),N&&e.jsx("p",{className:"px-4 text-sm font-medium text-green-800",children:"This is your free preview article. Start a trial to publish it and generate the next one."}),e.jsxs("div",{className:"flex gap-6 px-4",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ys,{blog:L&&E?E:r,isEditing:L,onInputChange:(c,p)=>{B(b=>b?c==="keywords"&&!Array.isArray(p)?(console.warn("Keywords received non-array value:",p),{...b,[c]:Array.isArray(b.keywords)?b.keywords:[]}):{...b,[c]:p}:null)},youtubeUrl:je,onYoutubeUrlChange:Y})}),e.jsx("div",{className:"w-64 flex-shrink-0 sticky top-24 self-start",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"flex flex-col gap-1 bg-white p-3 rounded-lg shadow-md",children:(()=>{const c=a,p=/<a\s+[^>]*href\s*=/i.test(c),b=c.includes("youtube.com")||c.includes("youtu.be")||c.includes("<iframe"),D=c.includes("action")||c.includes("contact")||c.includes("sign up")||c.includes("buy now")||c.includes("learn more");return[{key:"title",label:"Title",present:/<h1[^>]*>[\s\S]*?<\/h1>/i.test(c)},{key:"meta",label:"Meta Description",present:m},{key:"linking",label:"Internal Linking",present:p},{key:"youtube",label:"YouTube Video",present:b},{key:"cta",label:"Call to Action",present:D}].map(({key:Tt,label:Mt,present:Pt})=>e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded text-slate-700",children:[Pt&&e.jsx(oe,{className:"h-4 w-4 text-green-600 flex-shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:Mt})]},Tt))})()}),m&&e.jsxs("div",{className:"bg-white p-4 rounded-lg shadow-md",children:[e.jsx("p",{className:"font-semibold text-slate-800 mb-1.5",children:"Meta Description"}),e.jsx("p",{className:"text-xs text-slate-500 mb-3",children:"We automatically add this to your blog's metadata."}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:i})]})]})})]})]})}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-lg sm:text-xl md:text-2xl font-bold",children:"Content History"}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(os,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(xe,{type:"search",placeholder:"Search blog posts...",className:"pl-8 w-[250px]",value:A,onChange:s=>M(s.target.value)})]})})]}),e.jsx(Ie,{}),e.jsx(bs,{websiteId:t.id}),e.jsxs(Ot,{defaultValue:"all",value:T,onValueChange:ot,className:"space-y-4",children:[e.jsxs(Bt,{children:[e.jsx(V,{value:"all",children:"All Content"}),e.jsx(V,{value:"published",children:"Published"}),e.jsx(V,{value:"scheduled",children:"Scheduled"}),e.jsx(V,{value:"draft",children:"Drafts"}),e.jsx(V,{value:"rejected",children:"Rejected"})]}),e.jsxs(zt,{value:T,className:"space-y-4",children:[re.length===0?e.jsx(G,{children:e.jsxs(q,{className:"flex flex-col items-center justify-center py-8",children:[e.jsxs("p",{className:"text-muted-foreground",children:["No ",T!=="all"?T:""," content found."]}),e.jsx(j,{className:"mt-4",onClick:()=>f("/content-planner"),children:"Go to Content Planner"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden sm:block rounded-md border overflow-x-auto",children:e.jsxs(Ut,{children:[e.jsx(Yt,{children:e.jsxs(qe,{children:[e.jsx(z,{className:"w-[30px]",children:e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("input",{type:"checkbox",className:"rounded"})})}),e.jsx(z,{className:"w-[100px]",children:"Image"}),e.jsx(z,{children:"Title"}),e.jsx(z,{children:"Status"}),e.jsx(z,{children:"Keywords"}),e.jsx(z,{children:"Created"}),e.jsx(z,{className:"text-right",children:"Actions"})]})}),e.jsx(Kt,{children:re.slice(0,ge).map(s=>e.jsxs(qe,{"data-post-id":s.id,children:[e.jsx($,{children:e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("input",{type:"checkbox",className:"rounded"})})}),e.jsx($,{children:s.featured_image?e.jsx("img",{loading:"lazy",src:s.featured_image,alt:s.title,className:"w-[80px] h-[45px] object-cover rounded-md"}):e.jsx("div",{className:"w-[80px] h-[45px] bg-slate-100 rounded-md flex items-center justify-center text-slate-400",children:"No image"})}),e.jsx($,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-1 cursor-pointer hover:text-blue-600",onClick:()=>f(`/content-history/${s.id}`),children:[s.title,s.autopilot_generated&&e.jsx(ce,{label:"autopilot generation",trigger:e.jsx("button",{type:"button","aria-label":"Generated by autopilot",className:"ml-1 inline-flex text-muted-foreground",children:e.jsx(J,{className:"h-3.5 w-3.5"})}),children:e.jsx("p",{children:"Generated by autopilot"})})]})}),e.jsx($,{children:$e(s.status,s)}),e.jsx($,{children:s.keywords?e.jsxs("div",{className:"flex flex-wrap gap-1",children:[U(s).slice(0,2).map((a,i)=>
21{const m=typeof a=="string"?a:a&&typeof a=="object"&&"keyword"in a?a.keyword:JSON.stringify(a).substring(0,15)+"...";return e.jsx(R,{variant:"secondary",className:"text-xs",children:m},i)}),U(s).length>2&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["+",U(s).length-2," more"]})]}):e.jsx("span",{className:"text-muted-foreground",children:"No keywords"})}),e.jsx($,{children:s.created_at&&e.jsxs(e.Fragment,{children:[kt(s.created_at),e.jsx("div",{className:"text-xs text-muted-foreground",children:st(new Date(s.created_at),{addSuffix:!0})})]})}),e.jsx($,{className:"text-right",children:e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>f(`/content-history/${s.id}`),children:e.jsx(Gt,{className:"h-4 w-4"})})})]},s.id))})]})}),e.jsx("div",{className:"sm:hidden space-y-4",children:re.slice(0,ge).map(s=>e.jsx("div",{className:"border rounded-lg p-4 shadow bg-white dark:bg-gray-800",onClick:()=>f(`/content-history/${s.id}`),children:e.jsxs("div",{className:"flex items-start gap-3",children:[s.featured_image?e.jsx("img",{loading:"lazy",src:s.featured_image,alt:s.title,className:"w-20 h-12 object-cover rounded-md flex-shrink-0"}):e.jsx("div",{className:"w-20 h-12 bg-slate-100 rounded-md flex items-center justify-center text-slate-400 flex-shrink-0 text-xs",children:"No image"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-medium text-sm leading-snug line-clamp-3",children:s.title}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[$e(s.status,s),s.autopilot_generated&&e.jsx(J,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),s.keywords&&e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[U(s).slice(0,2).map((a,i)=>{const m=typeof a=="string"?a:a&&typeof a=="object"&&"keyword"in a?a.keyword:JSON.stringify(a).substring(0,15)+"...";return e.jsx(R,{variant:"secondary",className:"text-[10px]",children:m},i)}),U(s).length>2&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",U(s).length-2," more"]})]}),e.jsx("div",{className:"mt-2 text-[11px] text-muted-foreground",children:s.created_at&&st(new Date(s.created_at),{addSuffix:!0})})]})]})},s.id))})]}),re.length>ge&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(j,{variant:"outline",onClick:()=>lt(s=>s+25),children:"Load More"})})]})]})]})}export{Ws as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.