PageSourceSearch

https://firstsearch.ai/assets/Schedule-D5PURmey.js

js firstsearch.ai collected 2026-10-05 12:02:49 UTC 46,115 bytes, 1 lines download raw bytes

1import{v as De,j as e,B as _,w as Se,h as oe,i as se,x as Ve,u as b,g as L,L as E,t as B,o as q,m as w,S as Ae,C as Ye,F as Qe,a as He,l as Je}from"./index-CqoLzrvk.js";import{h as re,b as p}from"./vendor-B3Zfkia6.js";import{g as Xe,S as Ze,f as es}from"./DashboardSidebar-C7UfKuXK.js";import{C as k,d as R,a as ne,b as ie,c as ce}from"./card-B-v3vNZX.js";import{db as ue}from"./firebase-CVMOik5C.js";import{o as me,d as ss,c as Pe,q as Te,a as _e}from"./firebase-DnU9FFJ0.js";import{T as ts}from"./trial-conversion-guard-vpi_3OB5.js";import{P as as}from"./plug-F7-mao52.js";import{S as Ie}from"./send-1RuJ_Gsc.js";import{T as M}from"./triangle-alert-CYizpZA3.js";import{t as Q,c as Re,s as I,p as $,f as K,u as Ee}from"./useCalendar-XIK2XLSM.js";import{R as ee}from"./refresh-cw-DE-W54Oo.js";import{G as rs}from"./gift-CXANu7uI.js";import{G as Fe}from"./globe-DFMQqiGd.js";import{A as ns,f as is,a as ls,b as ds,c as os,d as cs,e as us,g as ms,h as hs}from"./alert-dialog-fguOc2Hl.js";import"./index-Gr-2yF49.js";import"./building-2-BHt6EPwR.js";import"./users-DTiJW43I.js";import"./check-BLdLswMy.js";import"./input-BZpOEthB.js";import"./separator-CnoxNz2q.js";import"./house-B23I8gsr.js";import"./settings-LH3mtmKZ.js";import"./shield-GmEhA0QT.js";const Ge=De("CirclePause",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]]);const xs=De("CirclePlay",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]]);function gs(s,r){const n=Q(s);return isNaN(r)?Re(s,NaN):(r&&n.setDate(n.getDate()+r),n)}function fs(s){return Re(s,Date.now())}function ps(s,r){const n=I(s),h=I(r);return+n==+h}function te(s,r){const n=Q(s),h=Q(r);return n.getTime()>h.getTime()}function W(s,r){const n=Q(s),h=Q(r);return+n<+h}function Oe(s){return ps(s,fs(s))}function ae(s,r){return gs(s,-r)}const bs="No active subscription",js="Website is paused",ys="Auto-publishing disabled",Ns="No active integration";function ws(s){const r=I(new Date);return s.filter(n=>{if(n.status!=="planned"||!n.scheduledDate)return!1;try{return W($(n.scheduledDate),r)}catch{return!1}}).length}function vs({articles:s,isPaused:r,isResuming:n,onResume:h}){const g=re(),{skippedByReason:j,pastDuePlanned:m}=p.useMemo(()=>{const S=new Map;for(const i of s){if(i.status!=="publish_skipped")continue;const y=i.publishSkipReason||"Unknown reason";S.set(y,(S.get(y)??0)+1)}return{skippedByReason:S,pastDuePlanned:ws(s)}},[s]),c=Array.from(j.values()).reduce((S,i)=>S+i,0),f=S=>j.get(S)??0;if(r)return e.jsx(k,{className:"border-slate-300 bg-slate-50 dark:border-slate-700 dark:bg-slate-900/40",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ge,{className:"h-5 w-5 text-slate-600 dark:text-slate-300 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-slate-900 dark:text-slate-100",children:"This website is paused"}),e.jsx("p",{className:"text-sm text-slate-700 dark:text-slate-300 mt-1",children:"No articles are being generated or published for this site. Your calendar, articles and billing are untouched, and everything resumes where it left off."})]}),h&&e.jsx(_,{size:"sm",onClick:h,disabled:n,children:n?"Resuming...":"Resume"})]})})});if(c===0&&m===0)return null;const C=f(bs),T=f(Ns),P=f(ys),D=f(js),d=f(ts);if(d>0)return e.jsx(k,{className:"border-amber-300 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Se,{className:"h-5 w-5 text-amber-700 dark:text-amber-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h4",{className:"font-semibold text-amber-900 dark:text-amber-100",children:[d," ",d===1?"article is":"articles are"," waiting on $99/month"]}),e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200 mt-1",children:"The first article publishes free once it is live on your site. The rest of the calendar unlocks when you start the subscription."})]}),e.jsx(_,{size:"sm",onClick:()=>g("/first-article"),children:"Unlock publishing"})]})})});if(C>0){const S=C;return e.jsx(k,{className:"border-amber-300 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Se,{className:"h-5 w-5 text-amber-700 dark:text-amber-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-amber-900 dark:text-amber-100",children:"Content is paused: no active subscription on this website"}),e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-200 mt-1",children:[S," finished"," ",S===1?"article is":"articles are"," waiting to be delivered to your site",m>0&&`, and ${m} more never started`,". Once a subscription is active they publish automatically, oldest first. Nothing is lost in the meantime."]})]}),e.jsx(_,{size:"sm",onClick:()=>g("/pricing"),children:"View plans"})]})})})}if(T>0)return e.jsx(k,{className:"border-amber-300 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(as,{className:"h-5 w-5 text-amber-700 dark:text-amber-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-amber-900 dark:text-amber-100",children:"Nowhere to deliver: this website has no active integration"}),e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-200 mt-1",children:[T," finished ",T===1?"article is":"articles are"," ","ready but we have no webhook or CMS connection to send them to. Add one and they publish automatically."]})]}),e.jsx(_,{size:"sm",onClick:()=>g("/settings?tab=integrations"),children:"Connect"})]})})});if(P>0)return e.jsx(k,{className:"border-blue-300 bg-blue-50 dark:border-blue-800 dark:bg-blue-950/30",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ie,{className:"h-5 w-5 text-blue-700 dark:text-blue-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-blue-900 dark:text-blue-100",children:"Auto-publishing is off for this website"}),e.jsxs("p",{className:"text-sm text-blue-800 dark:text-blue-200 mt-1",children:[P," finished"," ",P===1?"article is":"articles are"," waiting. Publish them yourself from the list below, or turn auto-publishing back on."]})]}),e.jsx(_,{size:"sm",variant:"outline",onClick:()=>g("/settings?tab=general"),children:"Settings"})]})})});if(c===0&&m>0)return e.jsx(k,{className:"border-yellow-300 bg-yellow-50 dark:border-yellow-800 dark:bg-yellow-950/30",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(M,{className:"h-5 w-5 text-yellow-700 dark:text-yellow-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h4",{className:"font-semibold text-yellow-900 dark:text-yellow-100",children:[m," scheduled ",m===1?"article has":"articles have"," not been generated"]}),e.jsx("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mt-1",children:"We retry past-due articles automatically for 14 days. You can also generate any of them now from the list below."})]})]})})});const N=D>0?" They were skipped while this website was paused and will be retried automatically.":"";return e.jsx(k,{className:"border-yellow-300 bg-yellow-50 dark:border-yellow-800 dark:bg-yellow-950/30",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(M,{className:"h-5 w-5 text-yellow-700 dark:text-yellow-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h4",{className:"font-semibold text-yellow-900 dark:text-yellow-100",children:[c," ",c===1?"article was":"articles were"," not delivered"]}),e.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mt-1",children:[Array.from(j.entries()).map(([S,i])=>`${i} x ${S}`).join(", "),".",N]})]})]})})})}
1const Ce={title:"Article generation was interrupted",detail:"This usually clears on its own. Try again, and if it keeps happening let us know.",actionable:!0},ks=[{test:/not_found_error|model:\s*[\w.-]+|does not exist|deprecated|no such model/i,result:{title:"Article generation was interrupted",detail:"This was caused by a change on our side, not by anything you did. It has been reported automatically and your article credits were not used.",actionable:!1}},{test:/credit|billing|quota|insufficient_quota|payment required|402/i,result:{title:"Article generation is temporarily paused",detail:"We are restoring capacity with one of our providers. Nothing is needed from you.",actionable:!1}},{test:/rate.?limit|429|too many requests|overloaded/i,result:{title:"Our writers are busy right now",detail:"Generation is queued and will resume shortly. Nothing is needed from you.",actionable:!1}},{test:/timeout|ETIMEDOUT|ECONNRESET|socket hang up|network|ENOTFOUND|EAI_AGAIN/i,result:{title:"A network problem interrupted generation",detail:"Try again in a few minutes.",actionable:!0}},{test:/webhook|publish|delivery failed|integration/i,result:{title:"The article was written but could not be delivered",detail:"Check the webhook URL in Settings, then retry publishing.",actionable:!0}},{test:/subscription|not entitled|trial (has )?(ended|expired)|403/i,result:{title:"This needs an active subscription",detail:"Reactivate your plan in Settings to continue generating articles.",actionable:!0}}];function Y(s){const r=typeof s=="string"?s:s instanceof Error?s.message:String(s??"");if(!r.trim())return{...Ce,raw:""};const n=ks.find(h=>h.test.test(r));return{...n?n.result:Ce,raw:r}}function Ss({articles:s,calendarId:r,calendarStatus:n,listenerError:h,isLoading:g}){console.log("[ScheduleTimeline] Props received:",{articlesCount:s.length,calendarId:r,calendarStatus:n,listenerError:h,isLoading:g,firstArticle:s[0]});const[j,m]=p.useState(null),[c,f]=p.useState(null),[C,T]=p.useState(null),[P,D]=p.useState(!1),[d,N]=p.useState(!1),[S,i]=p.useState(null),[y,l]=p.useState(!1),{currentUser:x}=oe(),{currentWebsite:u,refreshWebsites:A}=se(),F=Ve(),he=re(),H=p.useRef(null),V=p.useRef(!1),xe=p.useRef(s);xe.current=s;const z=!!u?.webhookUrl,[$e,ge]=p.useState(!1),Me=async()=>{if(u?.id){ge(!0);try{await L.websites.setPaused(u.id,!1),b.success(`Resumed ${u.domain}`,{description:"Article generation and publishing are back on."}),await A()}catch(a){b.error("Could not resume website",{description:a?.message||"Please try again."})}finally{ge(!1)}}};p.useEffect(()=>{if(!u?.id||!x?.uid)return;console.log("[ScheduleTimeline] Setting up real-time listener for website:",u.id);const a=me(ss(ue,"websites",u.id),o=>{if(o.exists()){const t=o.data(),v=t.calendarGenerationStatus,G=t.calendarGenerationError;if(H.current===v)return;if(console.log("[ScheduleTimeline] Real-time update received:",{status:v,error:G}),H.current=v,v==="processing"||v==="generating")N(!0),D(!1),i(null);else if(v==="failed")N(!1),D(!1),xe.current.length===0?(i(G||"Calendar generation failed"),b.error(G||"Calendar generation failed")):i(null);else{const U=H.current==="processing"||H.current==="generating";N(!1),D(!1),i(null),U&&(F.invalidateQueries({queryKey:["calendar",u.id,x.uid]}),b.success("Calendar generated successfully!"))}}},o=>{console.error("[ScheduleTimeline] Real-time listener error:",o)});return()=>{console.log("[ScheduleTimeline] Cleaning up real-time listener"),a()}},[u?.id,x?.uid,F]),p.useEffect(()=>{if(!j||s.length===0)return;const a=s.find(o=>o.id===j);a&&(a.status==="images_generated"?(b.success(`"${a.title}" generated successfully!`,{description:`${a.wordCount||0} words • ${a.readingTimeMinutes||0} min read`}),m(null)):a.status==="content_generated"||a.status==="generation_failed"&&(b.error(`Failed to generate "${a.title}"`,{description:"An error occurred during generation"}),m(null)))},[s,j]),p.useEffect(()=>{if(!u?.id||!x?.uid||V.current||d||n==="processing"||n==="generating")return;const a=I(new Date);s.filter(t=>{if(!t.scheduledDate)return!1;const v=I($(t.scheduledDate));return!W(v,a)}).length>0||(V.current=!0,l(!0),L.content.extendCalendar(u.id,x.uid).then(t=>{if(t.futureCount&&t.futureCount>0){V.current=!0;return}b.info("Extending your calendar",{description:"We are adding new future articles now."})}).catch(t=>{const v=t?.status;if(v===429||v===409){V.current=!0;return}b.error("Could not add more articles",{description:"We will try again automatically. No action needed."}),V.current=!0}).finally(()=>{l(!1)}))},[s,n,x?.uid,u?.id,d]);const fe=async()=>
1{if(!u||!x){console.log("[ScheduleTimeline] Cannot generate: missing currentWebsite or currentUser");return}console.log("[ScheduleTimeline] Starting calendar generation for website:",u.id),D(!0),i(null);try{const a=await L.content.generateCalendar({websiteId:u.id,userId:x.uid});console.log("[ScheduleTimeline] Generate API response:",a),b.success("Calendar generation started",{description:"Your content calendar is being generated. This may take 5-10 minutes."}),D(!1),N(!0)}catch(a){console.error("[ScheduleTimeline] Error generating calendar:",a);const o=a.message||"Failed to generate calendar. Please try again.";i(o),b.error("Generation failed",{description:o}),D(!1)}},pe=async(a,o)=>{if(a.stopPropagation(),console.log("[ScheduleTimeline] handleGenerate called for article:",o.id,o.title),console.log("[ScheduleTimeline] currentWebsite:",u?.id),console.log("[ScheduleTimeline] calendarId:",r),console.log("[ScheduleTimeline] currentUser:",x?.uid),!u||!r){console.error("[ScheduleTimeline] Missing required data:",{currentWebsite:!!u,calendarId:r}),b.error("Missing website or calendar ID");return}try{console.log("[ScheduleTimeline] Setting generatingId to:",o.id),m(o.id),console.log("[ScheduleTimeline] Calling API to generate content..."),await L.content.generateContent(o.id,r,u.id,x.uid),console.log("[ScheduleTimeline] API call succeeded"),b.info(`Generating "${o.title}"...`,{description:"This may take 3-5 minutes. You can continue working - we'll notify you when it's ready."})}catch(t){console.error("[ScheduleTimeline] Error starting generation:",t),b.error(t.message||"Failed to start generation"),m(null)}},be=async(a,o)=>{if(a.stopPropagation(),!z){b.error("No webhook configured. Go to Settings to connect your blog.");return}if(!u||!r){b.error("Missing website or calendar ID");return}try{f(o.id),await L.content.publishArticle(o.id,r,u.id,x.uid),b.success("Article published successfully!"),F.invalidateQueries({queryKey:["calendar",u.id,x?.uid]})}catch(t){console.error("Error publishing:",t),b.error(t.message||"Failed to publish article")}finally{f(null)}},We=async(a,o)=>{if(a.stopPropagation(),!u||!r){b.error("Missing website or calendar ID");return}try{T(o.id),b.info("Retrying image generation...",{description:"This may take 1-2 minutes."}),await L.content.retryImages(o.id,r,u.id)}catch(t){console.error("Error retrying images:",t),b.error(t.message||"Failed to retry image generation")}finally{T(null)}},J=I(new Date),je=ae(J,7),Be=ae(J,14),ye=s.filter(a=>{if(!a.scheduledDate)return!1;const o=I($(a.scheduledDate));return!!(!W(o,J)||a.status==="generation_failed"||a.status==="publish_failed"||a.status==="publish_skipped"||a.status==="images_generated"||a.status==="generating"||a.status==="content_generated"||(a.status==="planned"||a.status==="draft")&&te(o,Be)||a.status==="published"&&te(o,je))}),Ne=ye.reduce((a,o)=>{if(!o.scheduledDate)return a;const t=$(o.scheduledDate),v=K(t,"MMMM yyyy");return a[v]||(a[v]=[]),a[v].push(o),a},{}),we=s.length,ve=ye.length,Le=we-ve,le=s.filter(a=>{if(a.status!=="published"||!a.scheduledDate)return!1;const o=I($(a.scheduledDate));return W(o,je)}).length;console.log("[ScheduleTimeline] Total articles:",we),console.log("[ScheduleTimeline] Visible articles:",ve,"(hidden:",Le,"old published)"),console.log("[ScheduleTimeline] Grouped by month:",Object.keys(Ne).length,"months");const Ue=h&&s.length>0,de=n==="processing"||d;if(de&&s.length===0)return e.jsx(k,{className:"p-12",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 text-center",children:[e.jsx(E,{className:"h-12 w-12 animate-spin text-primary"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Generating Your Content Calendar"}),e.jsx("p",{className:"text-muted-foreground max-w-md",children:"We're analyzing your website and creating a personalized content strategy. This usually takes 5-10 minutes."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Feel free to explore other pages - we'll notify you when it's ready!"})]})]})});if(g&&s.length===0)return e.jsx(k,{className:"p-12",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 text-center",children:[e.jsx(E,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Loading Schedule"}),e.jsx("p",{className:"text-muted-foreground max-w-md",children:"Fetching your content calendar..."})]})]})});if(s.length===0)return e.jsx(k,{className:"p-12",children:e.jsx("div",{className:"flex flex-col items-center justify-center gap-4 text-center",children:S?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-destructive/10 rounded-full h-16 w-16 flex items-center justify-center",children:e.jsx(B,{className:"h-8 w-8 text-destructive"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:Y(S).title}),e.jsx("p",{className:"text-muted-foreground max-w-md mb-4",children:Y(S).detail})]}),e.jsx("div",{className:"flex gap-3 justify-center",children:e.jsx(_,{onClick:fe,disabled:P,children:P?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),"Retry"]})})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-primary/10 rounded-full h-16 w-16 flex items-center justify-center",children:e.jsx(q,{className:"h-8 w-8 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Content Calendar"}),e.jsx("p",{className:"text-muted-foreground max-w-md",children:"Generate your personalized content calendar with AI-optimized articles and publishing schedule."})]}),e.jsx(_,{onClick:fe,size:"lg",disabled:P,children:P?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-4 w-4 mr-2 animate-spin"}),"Starting Generation..."]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Generate Calendar"]})})]})})});const ze=a=>{if(a.status==="published")return e.jsx(w,{variant:"default",children:"Published"});if(a.status==="publish_failed")return e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(w,{variant:"destructive",className:"gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),"Publish Failed"]})});if(a.status==="publish_skipped")return e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(w,{variant:"secondary",className:"gap-1 bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-200",children:[e.jsx(M,{className:"h-3 w-3"}),"Publish Skipped"]})});if(a.status==="images_generated")return e.jsx(w,{variant:"default",children:"Ready to Publish"});if(a.status==="content_generated")return a.imagesStatus==="failed"||a.imagesStatus==="partial_failure"?e.jsxs(w,{variant:"destructive",className:"gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),"Images Failed"]}):e.jsx(w,{variant:"secondary",children:"Generating Images..."});if(a.status==="generation_failed")return e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(w,{variant:"destructive",className:"gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),"Failed"]})});if(a.status==="outline_generated")return e.jsx(w,{variant:"secondary",children:"Outline Ready"});if(a.status==="generating")return null;if((a.status==="planned"||a.status==="draft")&&a.scheduledDate){const o=I($(a.scheduledDate));if(W(o,J))return e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(w,{variant:"secondary",className:"gap-1 bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-200",children:[e.jsx(M,{className:"h-3 w-3"}),"Past Due"]})})}return e.jsx(w,{variant:"outline",children:"Scheduled"})};return e.jsxs("div",{className:"space-y-8",children:[e.jsx(vs,{articles:s,isPaused:u?.isPaused,isResuming:$e,onResume:Me}),Ue&&e.jsx(k,{className:"border-yellow-600 bg-yellow-50 dark:bg-yellow-950/20",children:e.jsx(R,{className:"pt-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(M,{className:"h-5 w-5 text-yellow-600 dark:text-yellow-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-yellow-900 dark:text-yellow-100",children:"Connection Issue"}),e.jsxs("p",{className:"text-sm text-yellow-800 dark:text-yellow-200 mt-1",children:[h," Data may be outdated."]})]})]})})}),de&&s.length>0&&e.jsx(k,{className:"border-primary/50 bg-primary/5",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(E,{className:"h-5 w-5 animate-spin text-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-primary",children:"Extending Your Calendar"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"New articles are being added to your content calendar. This usually takes 5-10 minutes."})]})]})})}),y&&e.jsx(k,{className:"border-primary/30 bg-primary/5",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(E,{className:"h-5 w-5 animate-spin text-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-primary",children:"Adding future articles"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your calendar was empty from today onward, so we started an extension."})]})]})})}),S&&e.jsx(k,{className:"border-red-200 bg-red-50",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(M,{className:"h-5 w-5 text-red-600"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-red-700",children:"Calendar generation failed"}),e.jsx("p",{className:"text-sm text-red-700",children:S})]})]})})}),Object.entries(Ne).map(([a,o])=>e.jsxs(k,{children:[e.jsxs(ne,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5 text-accent"}),e.jsx(ie,{children:a})]}),e.jsxs(ce,{children:[o.length," article",o.length!==1?"s":""," scheduled this month"]})]}),e.jsx(R,{children:e.jsx("div",{className:"space-y-4",children:o.map(t=>{const v=t.scheduledDate?$(t.scheduledDate):null,G=v&&Oe(v),U=v&&W(I(v),I(new Date))&&!G,ke=!t.content&&t.status!=="content_generated"&&t.status!=="images_generated"&&t.status!=="published"&&t.status!=="generating",qe=t.status==="images_generated",X=j===t.id||t.status==="generating",Z=c===t.id,Ke=G||U;return e.jsxs("div",{className:`flex gap-4 p-4 rounded-lg border-2 transition-colors ${G?"border-primary bg-primary/5 shadow-md cursor-pointer hover:bg-primary/10":U&&ke?"border-yellow-500/50 bg-yellow-50/50 dark:bg-yellow-900/10 cursor-pointer hover:bg-yellow-100/50 dark:hover:bg-yellow-900/20":U?"border-border hover:bg-muted/50 cursor-pointer":"border-border opacity-60 cursor-default"}`,onClick:()=>{Ke&&u&&r&&he(`/article/${t.id}?calendarId=${r}&websiteId=${u.id}`)},children:[v&&e.jsxs("div",{className:"flex flex-col items-center min-w-[60px]",children:[G&&e.jsx("div",{className:"text-[10px] font-bold text-primary uppercase tracking-wider mb-1",children:"Today"}),e.jsx("div",{className:`text-2xl font-bold ${G?"text-primary":"text-foreground"}`,children:K(v,"d")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:K(v,"EEE")})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"font-semibold text-foreground",children:t.title}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.keyword||"No keyword",t.searchVolume!==void 0&&t.searchVolume!==null&&` • ${t.searchVolume.toLocaleStr
1ing()}/mo`,t.difficulty!==void 0&&t.difficulty!==null&&` • Difficulty: ${t.difficulty}/100`]})]}),ze(t)]}),t.status==="generation_failed"&&t.generationError&&e.jsxs("div",{className:"p-2 bg-destructive/10 border border-destructive/20 rounded-md",children:[e.jsx("p",{className:"text-xs text-destructive",children:Y(t.generationError).title}),e.jsx("p",{className:"text-xs text-destructive/80",children:Y(t.generationError).detail}),e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"text-[10px] text-destructive/60 cursor-pointer select-none",children:"Technical details"}),e.jsx("p",{className:"text-[10px] text-destructive/60 break-all mt-1",children:t.generationError})]})]}),t.status==="publish_failed"&&t.publishFailReason&&e.jsx("div",{className:"p-2 bg-destructive/10 border border-destructive/20 rounded-md",children:e.jsxs("p",{className:"text-xs text-destructive",children:["Publish failed: ",t.publishFailReason]})}),t.status==="publish_skipped"&&t.publishSkipReason&&e.jsx("div",{className:"p-2 bg-yellow-100/50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-md",children:e.jsxs("p",{className:"text-xs text-yellow-800 dark:text-yellow-200",children:["Publish skipped: ",t.publishSkipReason]})}),(t.imagesStatus==="failed"||t.imagesStatus==="partial_failure")&&t.imagesError&&e.jsx("div",{className:"p-2 bg-destructive/10 border border-destructive/20 rounded-md",children:e.jsx("p",{className:"text-xs text-destructive",children:t.imagesError})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[t.wordCount&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[t.wordCount," words"]}),t.intent&&e.jsx(w,{variant:"outline",className:"text-xs",children:t.intent})]}),e.jsxs("div",{className:"flex items-center gap-2",onClick:O=>O.stopPropagation(),children:[X&&e.jsxs(_,{size:"sm",variant:"outline",disabled:!0,className:"gap-1",children:[e.jsx(E,{className:"h-3 w-3 animate-spin"}),"Generating..."]}),t.status==="generation_failed"&&!X&&(G||U)&&e.jsxs(_,{size:"sm",variant:"outline",onClick:O=>pe(O,t),className:"gap-1 border-destructive/50 text-destructive hover:bg-destructive/10",children:[e.jsx(ee,{className:"h-3 w-3"}),"Retry"]}),(t.imagesStatus==="failed"||t.imagesStatus==="partial_failure")&&e.jsx(_,{size:"sm",variant:"outline",onClick:O=>We(O,t),disabled:C===t.id,className:"gap-1 border-destructive/50 text-destructive hover:bg-destructive/10",children:C===t.id?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-3 w-3 animate-spin"}),"Retrying..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"h-3 w-3"}),"Retry Images"]})}),ke&&!X&&t.status!=="generation_failed"&&(G||U)&&e.jsxs(_,{size:"sm",variant:G?"default":"outline",onClick:O=>{console.log("[ScheduleTimeline] Generate button clicked for:",t.id),console.log("[ScheduleTimeline] Current generatingId:",j),console.log("[ScheduleTimeline] isGenerating:",X),pe(O,t)},className:"gap-1",children:[e.jsx(Ae,{className:"h-3 w-3"}),"Generate"]}),t.status==="publish_failed"&&e.jsxs(e.Fragment,{children:[!z&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-yellow-600 dark:text-yellow-400",children:[e.jsx(M,{className:"h-3 w-3"}),e.jsx("span",{children:"No webhook"})]}),e.jsx(_,{size:"sm",variant:"outline",onClick:O=>be(O,t),disabled:Z||!z,className:"gap-1 border-destructive/50 text-destructive hover:bg-destructive/10",children:Z?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-3 w-3 animate-spin"}),"Retrying..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"h-3 w-3"}),"Retry Publish"]})})]}),qe&&e.jsxs(e.Fragment,{children:[!z&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-yellow-600 dark:text-yellow-400",children:[e.jsx(M,{className:"h-3 w-3"}),e.jsx("span",{children:"No webhook"})]}),e.jsx(_,{size:"sm",variant:z?"default":"outline",onClick:O=>be(O,t),disabled:Z||!z,className:"gap-1",children:Z?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-3 w-3 animate-spin"}),"Publishing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"h-3 w-3"}),"Publish"]})})]})]})]})]})]},t.id)})})})]},a)),de&&s.length>0&&e.jsx(k,{className:"border-primary/50 bg-primary/5",children:e.jsx(R,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(E,{className:"h-5 w-5 animate-spin text-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-primary",children:"Extending Your Calendar"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"New articles are being added. They will appear here once ready."})]})]})})}),le>0&&e.jsx("div",{className:"text-center py-4",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[le," older published article",le!==1?"s":""," hidden."," ",e.jsx("button",{onClick:()=>he("/published"),className:"text-primary hover:underline",children:"View all in Published Articles →"})]})})]})}function Cs({articles:s,isLoading:r}){const n=s.length,h=s.filter(c=>c.status==="published").length,g=s.filter(c=>c.status==="images_generated").length,j=s.filter(c=>c.status==="generating"||c.status==="content_generated").length,m=[{title:"Total Articles",value:n.toString(),description:"Planned content pieces",icon:q},{title:"Published",value:h.toString(),description:"Live on your site",icon:Ye},{title:"Ready to Publish",value:g.toString(),description:"Content generated",icon:Qe},{title:"In Progress",value:j.toString(),description:"Currently generating",icon:He}];return e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:m.map(c=>{const f=c.icon;return e.jsxs(k,{children:[e.jsxs(ne,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(ie,{className:"text-sm font-medium text-muted-foreground",children:c.title}),e.jsx(f,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(R,{children:[r?e.jsx(Xe,{className:"h-9 w-16"}):e.jsx("div",{className:"text-3xl font-bold text-foreground",children:c.value}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:c.description})]})]},c.title)})})}function Ds({websiteId:s,calendarId:r,bonusCredits:n,onCreditsUsed:h}){const[g,j]=p.useState(!1),[m,c]=p.useState(!1),[f,C]=p.useState(Math.min(5,n.amount));if(!n||n.amount<=0)return null;const T=async()=>
1{if(!r){b.error("No content calendar found. Please wait for your calendar to be generated.");return}j(!0),c(!1);try{const d=await L.content.generateBonusArticles(s,r,f);if(d.status==="research_started"){c(!0),b.info("Keyword Research Started",{description:d.message||"Please wait 2-3 minutes and try again.",duration:6e3});return}b.success("Bonus Articles Added!",{description:`${d.articlesAdded} new articles have been added to your content calendar.`}),h?.()}catch(d){c(!1),b.error("Failed to generate bonus articles",{description:d.message||"Please try again later."})}finally{j(!1)}},P=n.expiresAt?new Date(n.expiresAt):null,D=P?Math.ceil((P.getTime()-Date.now())/(1e3*60*60*24)):null;return e.jsxs(k,{className:"border-emerald-200 dark:border-emerald-800 bg-gradient-to-r from-emerald-50 to-teal-50 dark:from-emerald-950/30 dark:to-teal-950/30",children:[e.jsx(ne,{className:"pb-3",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-emerald-100 dark:bg-emerald-900",children:e.jsx(rs,{className:"h-5 w-5 text-emerald-600 dark:text-emerald-400"})}),e.jsxs("div",{children:[e.jsxs(ie,{className:"text-lg flex items-center gap-2",children:["Bonus Article Credits",e.jsxs(w,{className:"bg-emerald-600 hover:bg-emerald-700",children:[n.amount," available"]})]}),e.jsx(ce,{children:n.reason||"Use these credits to generate extra articles for your calendar"})]})]})})}),e.jsx(R,{children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"articleCount",className:"text-sm text-muted-foreground",children:"Articles to generate:"}),e.jsx("select",{id:"articleCount",value:f,onChange:d=>C(parseInt(d.target.value)),className:"h-9 rounded-md border border-input bg-background px-3 py-1 text-sm",disabled:g||m,children:Array.from({length:Math.min(20,n.amount)},(d,N)=>N+1).map(d=>e.jsx("option",{value:d,children:d},d))})]}),e.jsx(_,{onClick:T,disabled:g||m||!r,className:"bg-emerald-600 hover:bg-emerald-700",children:g?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"mr-2 h-4 w-4 animate-spin"}),"Generating..."]}):m?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"mr-2 h-4 w-4 animate-spin"}),"Researching keywords..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"mr-2 h-4 w-4"}),"Generate ",f," Bonus Article",f>1?"s":""]})}),m&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"Keyword research is running. Try again in a few minutes."}),!m&&D!==null&&D<=7&&e.jsxs("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:["Expires in ",D," day",D!==1?"s":""]})]})})]})}function As(s){const{currentUser:r}=oe(),{data:n,isLoading:h}=Ee(s,r?.uid||void 0),[g,j]=p.useState([]),m=n?.calendarId||null;return p.useEffect(()=>{if(!m)return;const c=Pe(ue,"content-calendars",m,"articles"),f=Te(c,_e("publishDate","asc")),C=me(f,T=>{const D=T.docs.map(d=>({...d.data(),id:d.id})).map(d=>{let N=d.scheduledDate;return!N&&d.publishDate&&(typeof d.publishDate=="string"?N=d.publishDate:d.publishDate.toDate?N=d.publishDate.toDate().toISOString():(d.publishDate instanceof Date||d.publishDate.toISOString)&&(N=d.publishDate.toISOString())),{...d,scheduledDate:N,keyword:d.targetKeyword||d.keyword}});j(D)});return()=>C()},[m]),{articles:g,calendarId:m,isLoading:h}}function Ps({websiteId:s,websiteDomain:r,onArticles:n}){const{articles:h,calendarId:g,isLoading:j}=As(s);return p.useEffect(()=>{const m=h.map(c=>({...c,_websiteId:s,_websiteDomain:r,_calendarId:g}));n(s,m,j)},[h,g,j,s,r]),null}function Ts(s){const r=I(new Date);if(s.status==="published")return e.jsx(w,{variant:"default",children:"Published"});if(s.status==="publish_failed")return e.jsxs(w,{variant:"destructive",className:"gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),"Publish Failed"]});if(s.status==="publish_skipped")return e.jsxs(w,{variant:"secondary",className:"gap-1 bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-200",children:[e.jsx(M,{className:"h-3 w-3"}),"Publish Skipped"]});if(s.status==="images_generated")return e.jsx(w,{variant:"default",children:"Ready to Publish"});if(s.status==="content_generated")return s.imagesStatus==="failed"||s.imagesStatus==="partial_failure"?e.jsxs(w,{variant:"destructive",className:"gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),"Images Failed"]}):e.jsx(w,{variant:"secondary",children:"Generating Images..."});if(s.status==="generation_failed")return e.jsxs(w,{variant:"destructive",className:"gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),"Failed"]});if(s.status==="generating")return e.jsx(w,{variant:"secondary",children:"Generating..."});if((s.status==="planned"||s.status==="draft")&&s.scheduledDate){const n=I($(s.scheduledDate));if(W(n,r))return e.jsxs(w,{variant:"secondary",className:"gap-1 bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-200",children:[e.jsx(M,{className:"h-3 w-3"}),"Past Due"]})}return e.jsx(w,{variant:"outline",children:"Scheduled"})}function _s(){const{websites:s}=se(),r=re(),{selectWebsiteById:n}=se(),[h,g]=p.useState({}),[j,m]=p.useState({}),c=(i,y,l)=>{g(x=>({...x,[i]:y})),m(x=>({...x,[i]:l}))},f=I(new Date),C=ae(f,7),T=ae(f,14),P=Object.values(h).flat(),D=Object.values(j).some(i=>i),d=P.filter(i=>{if(!i.scheduledDate)return!1;const y=I($(i.scheduledDate));return!!(!W(y,f)||["generation_failed","publish_failed","publish_skipped","images_generated","generating","content_generated"].includes(i.status)||(i.status==="planned"||i.status==="draft")&&te(y,T)||i.status==="published"&&te(y,C))});d.sort((i,y)=>{const l=i.scheduledDate?new Date(i.scheduledDate).getTime():0,x=y.scheduledDate?new Date(y.scheduledDate).getTime():0;return l-x});const N=d.reduce((i,y)=>{if(!y.scheduledDate)return i;const l=$(y.scheduledDate),x=K(l,"MMMM yyyy");return i[x]||(i[x]=[]),i[x].push(y),i},{}),S=i=>{i._calendarId&&(n(i._websiteId),r(`/article/${i.id}?calendarId=${i._calendarId}&websiteId=${i._websiteId}`))};return e.jsxs(e.Fragment,{children:[s.map(i=>e.jsx(Ps,{websiteId:i.id,websiteDomain:i.domain,onArticles:c},i.id)),e.jsxs("div",{className:"space-y-8",children:[D&&P.length===0&&e.jsx(k,{className:"p-12",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 text-center",children:[e.jsx(E,{className:"h-12 w-12 animate-spin text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Loading Schedules"}),e.jsx("p",{className:"text-muted-foreground",children:"Fetching content calendars across all websites..."})]})]})}),!D&&P.length===0&&e.jsx(k,{className:"p-12",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 text-center",children:[e.jsx(q,{className:"h-12 w-12 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Content Calendars"}),e.jsx("p",{className:"text-muted-foreground",children:"None of your websites have content calendars yet."})]})]})}),Object.entries(N).map(([i,y])=>e.jsxs(k,{children:[e.jsxs(ne,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5 text-accent"}),e.jsx(ie,{children:i})]}),e.jsxs(ce,{children:[y.length," article",y.length!==1?"s":""," across ",new Set(y.map(l=>l._websiteId)).size," website",new Set(y.map(l=>l._websiteId)).size!==1?"s":""]})]}),e.jsx(R,{children:e.jsx("div",{className:"space-y-4",children:y.map(l=>{const x=l.scheduledDate?$(l.scheduledDate):null,u=x&&Oe(x),A=x&&W(I(x),f)&&!u,F=(u||A)&&!!l._calendarId;return e.jsxs("div",{className:`flex gap-4 p-4 rounded-lg border-2 transition-colors ${u?"border-primary bg-primary/5 shadow-md cursor-pointer hover:bg-primary/10":A?"border-border hover:bg-muted/50 cursor-pointer":"border-border opacity-60 cursor-default"}`,onClick:()=>F&&S(l),children:[x&&e.jsxs("div",{className:"flex flex-col items-center min-w-[60px]",children:[u&&e.jsx("div",{className:"text-[10px] font-bold text-primary uppercase tracking-wider mb-1",children:"Today"}),e.jsx("div",{className:`text-2xl font-bold ${u?"text-primary":"text-foreground"}`,children:K(x,"d")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:K(x,"EEE")})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h4",{className:"font-semibold text-foreground",children:l.title})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(w,{variant:"outline",className:"text-xs gap-1 font-normal",children:[e.jsx(Fe,{className:"h-3 w-3"}),l._websiteDomain]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[l.keyword||"No keyword",l.searchVolume!==void 0&&l.searchVolume!==null&&` • ${l.searchVolume.toLocaleStr
1ing()}/mo`]})]})]}),Ts(l)]}),l.status==="generation_failed"&&l.generationError&&e.jsx("div",{className:"p-2 bg-destructive/10 border border-destructive/20 rounded-md",children:e.jsx("p",{className:"text-xs text-destructive",children:Y(l.generationError).title})}),l.status==="publish_failed"&&l.publishFailReason&&e.jsx("div",{className:"p-2 bg-destructive/10 border border-destructive/20 rounded-md",children:e.jsxs("p",{className:"text-xs text-destructive",children:["Publish failed: ",l.publishFailReason]})}),l.status==="publish_skipped"&&l.publishSkipReason&&e.jsx("div",{className:"p-2 bg-yellow-100/50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-md",children:e.jsxs("p",{className:"text-xs text-yellow-800 dark:text-yellow-200",children:["Publish skipped: ",l.publishSkipReason]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[l.wordCount&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[l.wordCount," words"]}),l.intent&&e.jsx(w,{variant:"outline",className:"text-xs",children:l.intent})]})]})]},`${l._websiteId}-${l.id}`)})})})]},i))]})]})}
1function Is({websiteId:s,domain:r,isPaused:n,onChanged:h}){const[g,j]=p.useState(!1),[m,c]=p.useState(!1),f=async C=>{j(!0);try{await L.websites.setPaused(s,C),b.success(C?`Paused ${r}`:`Resumed ${r}`,{description:C?"No new articles will be generated or published for this site.":"Article generation and publishing are back on."}),c(!1),await h?.()}catch(T){b.error(C?"Could not pause website":"Could not resume website",{description:T?.message||"Please try again."})}finally{j(!1)}};return n?e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>f(!1),disabled:g,children:[g?e.jsx(E,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(xs,{className:"h-4 w-4 mr-2"}),"Resume this site"]}):e.jsxs(ns,{open:m,onOpenChange:c,children:[e.jsx(is,{asChild:!0,children:e.jsxs(_,{variant:"ghost",size:"sm",className:"text-muted-foreground",children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Pause this site"]})}),e.jsxs(ls,{children:[e.jsxs(ds,{children:[e.jsxs(os,{children:["Pause ",r,"?"]}),e.jsx(cs,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("p",{children:"We stop generating and publishing articles for this website."}),e.jsx("p",{children:"Your calendar, keywords and every article already written stay exactly as they are. Resume whenever you like and the schedule picks up from there."}),e.jsx("p",{className:"text-muted-foreground",children:"Pausing does not cancel your subscription. To stop being billed for this site, cancel it in billing settings."})]})})]}),e.jsxs(us,{children:[e.jsx(ms,{disabled:g,children:"Keep it running"}),e.jsx(hs,{onClick:C=>{C.preventDefault(),f(!0)},disabled:g,children:g?"Pausing...":"Pause website"})]})]})]})}function Rs({websiteId:s,websiteDomain:r,sitemapUrl:n,bonusArticleCredits:h,showHeader:g}){const{currentUser:j}=oe(),{data:m,isLoading:c,error:f}=Ee(s,j?.uid||void 0),[C,T]=p.useState([]),[P,D]=p.useState(null),d=re(),N=m?.calendarId||null;return p.useEffect(()=>{if(!N)return;D(null);const S=Pe(ue,"content-calendars",N,"articles"),i=Te(S,_e("publishDate","asc")),y=me(i,l=>{const u=l.docs.map(A=>({...A.data(),id:A.id})).map(A=>{let F=A.scheduledDate;return!F&&A.publishDate&&(typeof A.publishDate=="string"?F=A.publishDate:A.publishDate.toDate?F=A.publishDate.toDate().toISOString():(A.publishDate instanceof Date||A.publishDate.toISOString)&&(F=A.publishDate.toISOString())),{...A,scheduledDate:F,keyword:A.targetKeyword||A.keyword}});T(u)},l=>{console.error("[Schedule] Real-time listener error:",l),D("Lost connection to real-time updates. Please refresh the page."),b.error("Connection Error",{description:"Lost connection to real-time updates."})});return()=>y()},[N]),e.jsxs("div",{className:"space-y-6",children:[g&&e.jsxs("div",{className:"flex items-center gap-2 pt-4 first:pt-0",children:[e.jsx(Fe,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h2",{className:"text-xl font-semibold",children:r})]}),f&&!N&&e.jsx(k,{className:"p-8",children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 text-center",children:[e.jsx(B,{className:"h-8 w-8 text-yellow-600 dark:text-yellow-400"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-1",children:"Unable to Load Schedule"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:f.toString()})]})]})}),!f&&e.jsxs(e.Fragment,{children:[e.jsx(Cs,{articles:C,isLoading:c}),!n&&e.jsx(k,{className:"border-amber-200 bg-amber-50",children:e.jsxs("div",{className:"p-4 flex items-start gap-3",children:[e.jsx(B,{className:"h-5 w-5 text-amber-700 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-amber-900",children:"Add your sitemap for better keywords"}),e.jsx("p",{className:"text-sm text-amber-800",children:"We use your sitemap to avoid duplicates and plan smarter topics. Set it once in Settings."})]}),e.jsx("button",{onClick:()=>d("/settings?tab=general"),className:"text-sm text-amber-900 hover:underline",children:"Go to Settings →"})]})}),h&&h.amount>0&&e.jsx(Ds,{websiteId:s,calendarId:N,bonusCredits:h}),e.jsx(Ss,{articles:C,calendarId:N,calendarStatus:m?.status,listenerError:P,isLoading:c})]})]})}const rt=()=>{const{currentWebsite:s,websites:r,isAllWebsites:n,isLoading:h,refreshWebsites:g}=se();return e.jsxs(Ze,{children:[e.jsx(Je,{noindex:!0}),e.jsxs("div",{className:"min-h-screen flex w-full bg-background",children:[e.jsx(es,{}),e.jsx("main",{className:"flex-1 p-8",children:e.jsxs("div",{className:"max-w-7xl mx-auto 
1space-y-8",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-4xl font-semibold text-foreground mb-2",children:"Content Schedule"}),e.jsx("p",{className:"text-muted-foreground",children:n?"Content schedules across all your websites":"View and manage your upcoming SEO content and backlink campaigns"})]}),!n&&s&&e.jsx(Is,{websiteId:s.id,domain:s.domain,isPaused:s.isPaused===!0,onChanged:g})]}),n?e.jsx(_s,{}):s?e.jsx(Rs,{websiteId:s.id,websiteDomain:s.domain,sitemapUrl:s.sitemapUrl,bonusArticleCredits:s.bonusArticleCredits,showHeader:!1}):null]})})]})]})};export{rt 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.