1import{aY as S,ao as A,r as g,t as d,j as a,L as C}from"./index-C0lZH1NI.js";import{u as y}from"./useServerFn-Z02nAU3g.js";import{c as N,e as I}from"./admin-content.functions-diScN-tk.js";import{A as _,R as q,I as D}from"./RichEditor-DeueB29k.js";import{B as f}from"./button-B4BIIZ4G.js";import{I as n}from"./input-BahSpN_5.js";import{T as m}from"./textarea-BzHHN18k.js";import{L}from"./label-Dail02p5.js";import{S as P}from"./switch-BwdCqwcz.js";import{S as B}from"./save-DCV49aY8.js";import"./auth-middleware-B0R0L93u.js";import"./index-C7yKKq-w.js";import"./index-CO0pw0kS.js";import"./index-qSbe3Nbs.js";function h(o){return o.toLowerCase().normalize("NFKD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"").slice(0,120)}const F={originalSlug:"",slug:"",title:"",category:"",metaTitle:"",metaDescription:"",readTime:"",author:"IMPROV Communication",quickAnswer:"",keyTakeawaysText:"",keywordsText:"",coverImage:"",coverImageAlt:"",bodyHtml:"",published:!1,publishedAt:new Date().toISOString()};function J(){const{slug:o}=S({from:"/_authenticated/admin/blog/$slug"}),u=A(),j=y(N),w=y(I),c=o==="new",[t,p]=g.useState(F),[k,T]=g.useState(!c),[x,v]=g.useState(!1);g.useEffect(()=>{c||(async()=>{try{const e=await j({data:{slug:o}});if(!e){d.error("Not found");return}p({originalSlug:e.slug,slug:e.slug,title:e.title??"",category:e.category??"",metaTitle:e.meta_title??"",metaDescription:e.meta_description??"",readTime:e.read_time??"",author:e.author??"",quickAnswer:e.quick_answer??"",keyTakeawaysText:(e.key_takeaways??[]).join(` 2`),keywordsText:(e.keywords??[]).join(", "),coverImage:e.cover_image??"",coverImageAlt:e.cover_image_alt??"",bodyHtml:e.body_html??"",published:!!e.published,publishedAt:e.published_at})}catch(e){d.error(String(e.message??e))}finally{T(!1)}})()},[o,c]);function s(e,r){p(i=>({...i,[e]:r}))}async function b(e){if(!t.title.trim()){d.error("Title is required");return}const r=(t.slug||h(t.title)).trim();if(!r){d.error("Slug is required");return}v(!0);try{await w({data:{originalSlug:c?void 0:t.originalSlug,slug:r,title:t.title,category:t.category,metaTitle:t.metaTitle||t.title,metaDescription:t.metaDescription,readTime:t.readTime,publishedAt:t.publishedAt,author:t.author,quickAnswer:t.quickAnswer,keyTakeaways:t.keyTakeawaysText.split(` 3`).map(i=>i.trim()).filter(Boolean),keywords:t.keywordsText.split(",").map(i=>i.trim()).filter(Boolean),coverImage:t.coverImage||null,coverImageAlt:t.coverImageAlt||null,bodyHtml:t.bodyHtml,published:e??t.published}}),d.success(e===!0?"Published":e===!1?"Saved as draft":"Saved"),c?u({to:"/admin/blog/$slug",params:{slug:r},replace:!0}):r!==t.originalSlug?u({to:"/admin/blog/$slug",params:{slug:r},replace:!0}):(s("originalSlug",r),e!==void 0&&s("published",e))}catch(i){d.error(String(i.message??i))}finally{v(!1)}}return k?a.jsx("div",{className:"text-white/40",children:"Loadingâ¦"}):a.jsxs("div",{className:"space-y-6 pb-20",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsxs(C,{to:"/admin/blog",className:"inline-flex items-center gap-2 text-sm text-white/60 hover:text-white",children:[a.jsx(_,{className:"h-4 w-4"})," All posts"]}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx(P,{checked:t.published,onCheckedChange:e=>s("published",e)}),a.jsx("span",{className:"text-white/70",children:t.published?"Published":"Draft"})]}),a.jsxs(f,{onClick:()=>b(),disabled:x,variant:"secondary",children:[a.jsx(B,{className:"h-4 w-4 mr-2"})," Save"]}),a.jsx(f,{onClick:()=>b(!0),disabled:x,className:"bg-[color:var(--brand-blue)] text-[color:var(--deep-purple)] hover:bg-[color:var(--brand-blue)]/90 font-semibold",children:t.published?"Update & keep published":"Publish"})]})]}),a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_320px] gap-6",children:[a.jsxs("div",{className:"space-y-4",children:[a.jsx("div",{children:a.jsx(n,{value:t.title,onChange:e=>{const r=e.target.value;s("title",r),c&&!t.slug&&s("slug",h(r))},placeholder:"Post title",className:"text-2xl font-extrabold tracking-tight h-14 bg-black/20 border-white/10"})}),a.jsx(q,{value:t.bodyHtml,onChange:e=>s("bodyHtml",e),placeholder:"Write your postâ¦",uploadFolder:"blog"})]}),a.jsxs("aside",{className:"space-y-5",children:[a.jsx(l,{label:"Slug",children:a.jsx(n,{value:t.slug,onChange:e=>s("slug",h(e.target.value)),placeholder:"my-post"})}),a.jsx(l,{label:"Category",children:a.jsx(n,{value:t.category,onChange:e=>s("category",e.target.value),placeholder:"Leadership"})}),a.jsx(l,{label:"Read time",children:a.jsx(n,{value:t.readTime,onChange:e=>s("readTime",e.target.value),placeholder:"6 min read"})}),a.jsx(l,{label:"Author",children:a.jsx(n,{value:t.author,onChange:e=>s("author",e.target.value)})}),a.jsx(l,{label:"Cover image",children:a.jsx(D,{value:t.coverImage,onChange:e=>s("coverImage",e),folder:"blog"})}),a.jsx(l,{label:"Cover image alt",children:a.jsx(n,{value:t.coverImageAlt,onChange:e=>s("coverImageAlt",e.target.value)})}),a.jsx(l,{label:"Meta title",children:a.jsx(n,{value:t.metaTitle,onChange:e=>s("metaTitle",e.target.value)})}),a.jsx(l,{label:"Meta description",children:a.jsx(m,{rows:3,value:t.metaDescription,onChange:e=>s("metaDescription",e.target.value)})}),a.jsx(l,{label:"Quick answer (AEO)",children:a.jsx(m,{rows:3,value:t.quickAnswer,onChange:e=>s("quickAnswer",e.target.value)})}),a.jsx(l,{label:"Key takeaways (one per line)",children:a.jsx(m,{rows:4,value:t.keyTakeawaysText,onChange:e=>s("keyTakeawaysText",e.target.value)})}),a.jsx(l,{label:"Keywords (comma-separated)",children:a.jsx(m,{rows:2,value:t.keywordsText,onChange:e=>s("keywordsText",e.target.value)})})]})]})]})}function l({label:o,children:u}){return a.jsxs("div",{className:"space-y-1.5",children:[a.jsx(L,{className:"text-xs uppercase tracking-widest text-white/50",children:o}),u]})}export{J as component};
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.