1import{_ as J}from"./DfQzjviO.js";import{_ as U}from"./CeO01nzs.js";import{e as X,B as Y,l as f,m as k,c as p,a as o,b as T,w as B,u as e,i as v,d as A,t as D,q as G,D as Z,p as b,o as u}from"./DAkdLEaj.js";import{u as K}from"./BehGChwl.js";import{u as x}from"./iN4FCMy5.js";import"./BWo25ybC.js";import"./CHNi2R5m.js";import"./Ch-ghsjQ.js";const Q={class:"max-w-3xl mx-auto"},tt={class:"mb-5 flex items-start justify-between gap-3"},st={class:"flex items-center gap-2"},et=["disabled"],at={key:0,class:"animate-spin w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24"},nt=["href"],ot={key:0,class:"text-center py-10 text-gray-500"},it={key:1,class:"card p-8 text-center"},lt={class:"text-sm text-gray-500 mb-4"},rt={class:"flex justify-center gap-3"},yt=X({__name:"[id]",async setup(ct){let a,l;const i=Y(),{success:y,error:d}=K(),g=f(i.query.shortLinkWarning==="1"),{data:C,pending:M,error:_,refresh:m}=([a,l]=k(()=>x(`/api/admin/blog/${i.params.id}`,"$FaWauWTyW5")),a=await a,l(),a),{data:R}=([a,l]=k(()=>x("/api/admin/sms-groups","$YRJRzxfBkM")),a=await a,l(),a),{data:W,refresh:w}=([a,l]=k(()=>x(`/api/admin/blog/${i.params.id}/shortlink/stats`,"$SzRgWF1akI")),a=await a,l(),a),{data:F}=([a,l]=k(()=>x("/api/admin/settings/social-accounts","$eJiWnr2ZDR")),a=await a,l(),a),r=b(()=>{const t=C.value?.post;return t?{title:t.title,slug:t.slug,excerpt:t.excerpt??"",coverImage:t.coverImage??"",coverImageAlt:t.coverImageAlt??"",content:t.content,status:t.status,visibility:t.visibility??"public",publishedAt:t.publishedAt?q(t.publishedAt):"",shortLink:t.shortLink??"",smsOnPublish:t.smsOnPublish??!1,smsAudienceType:t.smsAudienceType??"all",socialInstagram:t.socialInstagram??!1,socialFacebook:t.socialFacebook??!1,socialX:t.socialX??!1}:null}),I=b(()=>F.value?.accounts??[]),V=b(()=>C.value?.smsBatches??[]),E=b(()=>R.value?.events??[]),N=b(()=>W.value?.clickCount??null),$=f(!1),S=f(!1),P=f(!1),h=f(!1);async function O(){h.value=!0;try{await $fetch(`/api/admin/blog/${i.params.id}`,{method:"PATCH",body:{status:"published",publishedAt:new Date().toISOString(),smsAudience:null}}),y("Published","Post is now live."),await m()}catch(t){d("Could not publish",t?.data?.statusMessage||t?.message)}finally{h.value=!1}}async function j(){P.value=!0;try{await $fetch(`/api/admin/blog/${i.params.id}/shortlink`,{method:"DELETE"}),await m();const t=await $fetch(`/api/admin/blog/${i.params.id}/shortlink`,{method:"POST"});t.shortLinkWarning?d("Generation failed","Short link could not be created. Try again later."):(g.value=!1,y("Short link regenerated",t.shortLink),await Promise.all([m(),w()]))}catch(t){d("Could not regenerate",t?.data?.statusMessage||t?.message)}finally{P.value=!1}}async function z(){S.value=!0;try{const t=await $fetch(`/api/admin/blog/${i.params.id}/shortlink`,{method:"POST"});t.shortLinkWarning?d("Retry failed","The short-link service is still unavailable. Try again later."):(g.value=!1,y("Short link created",t.shortLink),await Promise.all([m(),w()]))}catch(t){d("Retry failed",t?.data?.statusMessage||t?.message)}finally{S.value=!1}}async function H(t){$.value=!0,g.value=!1;try{const s={...t,publishedAt:t.publishedAt?new Date(t.publishedAt).toISOString():null},n=await $fetch(`/api/admin/blog/${i.params.id}`,{method:"PATCH",body:s});g.value=n.shortLinkWarning??!1;let c="Post updated.";n.smsSent>0&&(c+=` SMS sent to ${n.smsSent} recipient${n.smsSent!==1?"s":""}.`),n.smsFailed>0&&(c+=` ${n.smsFailed} failed.`),n.socialPosted?.length&&(c+=` Posted to ${n.socialPosted.join(", ")}.`),y("Saved",c),await Promise.all([m(),w()])}catch(s){d("Could not save",s?.data?.statusMessage||s?.message)}finally{$.value=!1}}function q(t){const s=new Date(t),n=c=>String(c).padStart(2,"0");return`${s.getFullYear()}-${n(s.getMonth()+1)}-${n(s.getDate())}T${n(s.getHours())}:${n(s.getMinutes())}`}return(t,s)=>{const n=J,c=U;return u(),p("div",Q,[o("div",tt,[o("div",null,[T(n,{to:"/admin/blog",class:"text-sm text-[#003082] font-semibold hover:underline"},{default:B(()=>[...s[2]||(s[2]=[A("â All posts",-1)])]),_:1}),s[3]||(s[3]=o("h1",{class:"text-xl font-bold text-gray-900 mt-2"},"Edit Post",-1))]),o("div",st,[e(r)?.status==="published"?(u(),p("button",{key:0,t
1ype:"button",onClick:O,disabled:e(h),class:"btn-primary text-sm flex items-center gap-1.5"},[e(h)?(u(),p("svg",at,[...s[4]||(s[4]=[o("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"},null,-1),o("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"},null,-1)])])):v("",!0),A(" "+D(e(h)?"Publishingâ¦":"Publish now"),1)],8,et)):v("",!0),e(r)?.status==="published"&&e(r)?.slug?(u(),p("a",{key:1,href:`/blog/${e(r).slug}`,target:"_blank",class:"btn-secondary text-sm"},"View on site â",8,nt)):v("",!0)])]),e(M)?(u(),p("div",ot,"Loadingâ¦")):e(_)?(u(),p("div",it,[s[6]||(s[6]=o("p",{class:"text-red-600 font-semibold mb-1"},"Could not load post",-1)),o("p",lt,D(e(_)?.data?.statusMessage||e(_)?.message||"Unknown error"),1),o("div",rt,[o("button",{onClick:s[0]||(s[0]=L=>e(m)()),class:"btn-primary text-sm"},"Try again"),T(n,{to:"/admin/blog",class:"btn-secondary text-sm"},{default:B(()=>[...s[5]||(s[5]=[A("Back to posts",-1)])]),_:1})])])):e(r)?(u(),G(c,{key:2,modelValue:e(r),"onUpdate:modelValue":s[1]||(s[1]=L=>Z(r)?r.value=L:null),saving:e($),"short-link-warning":e(g),"can-retry-short-link":!0,"retrying-short-link":e(S),"regenerating-short-link":e(P),"click-count":e(N),"sms-batches":e(V),"sms-event-options":e(E),"social-accounts":e(I),"post-id":Number(e(i).params.id),"submit-label":"Save changes",onSubmit:H,onRetryShortLink:z,onRegenerateShortLink:j},null,8,["modelValue","saving","short-link-warning","retrying-short-link","regenerating-short-link","click-count","sms-batches","sms-event-options","social-accounts","post-id"])):v("",!0)])}}});export{yt 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.