1import{$ as M,u as H,r as i,j as e,L as d,a0 as U,a1 as q,a2 as z,a3 as G,a4 as J}from"./main-Bo0oayNO.js";function O(){const{templates:B,pagination:u,counts:p}=M.useLoaderData(),{status:r,page:c,search:n}=M.useSearch(),x=H(),[g,k]=i.useState(null),[v,w]=i.useState(null),[C,P]=i.useState(n),[a,h]=i.useState([]),[y,S]=i.useState(!1),[D,$]=i.useState(!1),[j,I]=i.useState("title"),[f,T]=i.useState("asc"),o=r==="trash",N=t=>{j===t?T(f==="asc"?"desc":"asc"):(I(t),T("asc"))},b=({field:t})=>e.jsx("span",{className:"ml-1 inline-block",children:j===t?f==="asc"?e.jsx("svg",{className:"w-4 h-4 inline",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})}):e.jsx("svg",{className:"w-4 h-4 inline",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})}):e.jsx("svg",{className:"w-4 h-4 inline opacity-30",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})})}),R=async(t,s)=>{const l=o?`Permanently delete template "${s}"? This cannot be undone.`:`Move template "${s}" to trash?`;if(confirm(l)){k(t);try{o?await G({data:t}):await J({data:t}),x({to:"/admin/templates",search:{status:r,page:1,search:n}})}finally{k(null)}}},F=async(t,s)=>{if(confirm(`Restore template "${s}"?`)){w(t);try{await z({data:t}),x({to:"/admin/templates",search:{status:r,page:1,search:n}})}finally{w(null)}}},m=[...B].sort((t,s)=>{let l=0;switch(j){case"title":l=t.title.localeCompare(s.title);break;case"usageCount":l=t.usageCount-s.usageCount;break;case"status":l=t.status.localeCompare(s.status);break}return f==="asc"?l:-l}),V=t=>{t.target.checked?h(m.map(s=>s.id)):h([])},W=t=>{h(s=>s.includes(t)?s.filter(l=>l!==t):[...s,t])},L=async()=>{if(a.length===0)return;const t=o?`Permanently delete ${a.length} templates? This cannot be undone.`:`Move ${a.length} templates to trash?`;if(confirm(t)){S(!0);try{await q({data:a}),h([]),x({to:"/admin/templates",search:{status:r,page:1,search:n}})}finally{S(!1)}}},A=async()=>{if(a.length!==0&&confirm(`Restore ${a.length} templates?`)){$(!0);try{await U({data:a}),h([]),x({to:"/admin/templates",search:{status:r,page:1,search:n}})}finally{$(!1)}}},E=t=>{t.preventDefault(),x({to:"/admin/templates",search:{status:r,page:1,search:C}})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Content Templates"}),e.jsx("p",{className:"text-gray-600",children:"Manage reusable post templates"})]}),e.jsxs(d,{to:"/admin/templates/new",className:"btn-primary",children:[e.jsx("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"New Template"]})]}),e.jsx("div",{className:"border-b border-gray-200",children:e.jsx("nav",{className:"-mb-px flex space-x-8",children:[{key:"all",label:"All",count:p.all},{key:"published",label:"Published",count:p.published},{key:"draft",label:"Draft",count:p.draft},{key:"trash",label:"Trash",count:p.trash}].map(t=>e.jsxs(d,{to:"/admin/templates",search:{status:t.key,page:1,search:n},className:`py-2 px-1 border-b-2 font-medium text-sm ${r===t.key?"border-primary-500 text-primary-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:[t.label,e.jsx("span",{className:`ml-2 py-0.5 px-2 rounded-full text-xs ${r===t.key?"bg-primary-100 text-primary-600":"bg-gray-100 text-gray-600"}`,children:t.count})]},t.key))})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 justify-between",children:[e.jsxs("form",{onSubmit:E,className:"flex gap-2",children:[e.jsx("input",{type:"text",value:C,onChange:t=>P(t.target.value),placeholder:"Search templates...",className:"input w-64"}),e.jsx("button",{type:"submit",className:"btn-secondary",children:"Search"})]}),a.length>0&&e.jsx("div",{className:"flex gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:A,disabled:D,className:"btn-secondary",children:D?"Restoring...":`Restore (${a.length})`}),e.jsx("button",{onClick:L,disabled:y,className:"btn-danger",children:y?"Deleting...":`Delete Permanently (${a.length})`})]}):e.jsx("button",{onClick:L,disabled:y,className:"btn-danger",children:y?"Moving...":`Move to Trash (${a.length})`})})]}),e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 w-10",children:e.jsx("input",{type:"checkbox",onChange:V,checked:a.length===m.length&&m.length>0,className:"h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded-sm"})}),e.jsxs("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer",onClick:()=>N("title"),children:["Template ",e.jsx(b,{field:"title"})]}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Description"}),e.jsxs("th",{className:"px-6 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer",onClick:()=>N("usageCount"),children:["Uses ",e.jsx(b,{field:"usageCount"})]}),e.jsxs("th",{className:"px-6 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer",onClick:()=>N("status"),children:["Status ",e.jsx(b,{field:"status"})]}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:m.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-6 py-12 text-center text-gray-500",children:n?"No templates found matching your search.":o?"No templates in trash.":"No templates yet. Create your first template!"})}):m.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsx("input",{type:"checkbox",checked:a.includes(t.id),onChange:()=>W(t.id),className:"h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded-sm"})}),e.jsxs("td",{className:"px-6 py-4",children:[e.jsx(d,{to:"/admin/templates/$id",params:{id:t.id},className:"font-medium text-gray-900 hover:text-primary-600",children:t.title}),e.jsx("p",{className:"text-sm text-gray-500",children:t.slug})]}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("p",{className:"text-sm text-gray-600 truncate max-w-xs",children:t.description||"-"})}),e.jsx("td",{className:"px-6 py-4 text-center",children:e.jsx("span",{className:"text-sm text-gray-600",children:t.usageCount})}),e.jsx("td",{className:"px-6 py-4 text-center",children:e.jsx("span",{className:`px-2 py-1 text-xs rounded-full ${t.status==="published"?"bg-green-100 text-green-800":"bg-yellow-100 text-yellow-800"}`,children:t.status})}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsx("div",{className:"flex justify-end gap-2",children:o?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>F(t.id,t.title),disabled:v===t.id,className:"text-sm text-blue-600 hover:text-blue-800",children:v===t.id?"Restoring...":"Restore"}),e.jsx("button",{onClick:()=>R(t.id,t.title),disabled:g===t.id,className:"text-sm text-red-600 hover:text-red-800",children:g===t.id?"Deleting...":"Delete"})]}):e.jsxs(e.Fragment,{children:[e.jsx(d,{to:"/admin/templates/$id",params:{id:t.id},className:"text-sm text-primary-600 hover:text-primary-800",children:"Edit"}),e.jsx("button",{onClick:()=>R(t.id,t.title),disabled:g===t.id,className:"text-sm text-red-600 hover:text-red-800",children:g===t.id?"Moving...":"Trash"})]})})})]},t.id))})]})}),u.totalPages>1&&e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("p",{className:"text-sm text-gray-600",children:["Showing ",(c-1)*10+1," to ",Math.min(c*10,u.total)," of"," ",u.total," templates"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(d,{to:"/admin/templates",search:{status:r,page:c-1,search:n},className:`btn-secondary ${c===1?"opacity-50 pointer-events-none":""}`,children:"Previous"}),e.jsx(d,{to:"/admin/templates",search:{status:r,page:c+1,search:n},className:`btn-secondary ${c===u.totalPages?"opacity-50 pointer-events-none":""}`,children:"Next"})]})]})]})}export{O 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.