import{c as s}from"./CVq-Ik9t.js";function y(e){return e.raw_route||e.route}function S(e){const t=e.split("/").filter(Boolean);return t.length<=1?"/":"/"+t.slice(0,-1).join("/")}async function $(e,t="order",a="asc",n,r){const c={children_of:e,sort:t,order:a,per_page:String(200)};n&&(c.lang=n);const f=await s.getFullBody("/pages",{...c,page:"1"}),i=Math.max(1,f.meta?.pagination?.total_pages??1),o=[...f.data??[]];if(i>1){const h=await Promise.all(Array.from({length:i-1},(l,g)=>s.getFullBody("/pages",{...c,page:String(g+2)}).then(d=>d.data??[])));for(const l of h)o.push(...l)}return o}function p(e){const t={};return e.page&&(t.page=String(e.page)),e.per_page&&(t.per_page=String(e.per_page)),e.sort&&(t.sort=e.sort),e.order&&(t.order=e.order),e.published!==void 0&&(t.published=String(e.published)),e.template&&(t.template=e.template),e.routable!==void 0&&(t.routable=String(e.routable)),e.visible!==void 0&&(t.visible=String(e.visible)),e.parent&&(t.parent=e.parent),e.children_of&&(t.children_of=e.children_of),e.root&&(t.root="true"),e.lang&&(t.lang=e.lang),e.translations&&(t.translations="true"),e.search&&(t.search=e.search),t}async function w(e={}){return s.get("/pages",p(e))}async function R(e,t){return s.get("/pages",p({search:e,per_page:t?.per_page??500,lang:t?.lang,translations:t?.translations}))}async function v(e=5){return s.get("/pages",{sort:"modified",order:"desc",per_page:String(e)})}async function W(e,t){const a={};t?.render&&(a.render="true"),t?.summary&&(a.summary="true"),t?.summary_size&&(a.summary_size=String(t.summary_size)),t?.children&&(a.children="true"),t?.children_depth&&(a.children_depth=String(t.children_depth)),t?.translations&&(a.translations="true"),t?.lang&&(a.lang=t.lang);const n=e.startsWith("/")?e.slice(1):e;return s.get(`/pages/${n}`,a)}async function z(e){return s.post("/pages",e)}async function x(e){const t=e.startsWith("/")?e.slice(1):e;return s.post(`/pages/${t}/preview-token`,{})}async function P(e,t,a,n){const r=e.startsWith("/")?e.slice(1):e,u=n?`/pages/${r}?lang=${encodeURIComponent(n)}`:`/pages/${r}`;return s.patch(u,t)}async function B(e,t){const a=e.startsWith("/")?e.slice(1):e,n=[];t?.children!==void 0&&n.push(`children=${t.children}`),t?.lang&&n.push(`lang=${encodeURIComponent(t.lang)}`);const r=n.length?`/pages/${a}?${n.join("&")}`:`/pages/${a}`;return s.delete(r,void 0)}async function C(e,t){const a=e.startsWith("/")?e.slice(1):e;return s.post(`/pages/${a}/move`,t)}async function _(e,t){const a=e.startsWith("/")?e.slice(1):e;return s.post(`/pages/${a}/copy`,{route:t})}async function I(e){const t=y(e),a=t==="/"?"/":t.substring(0,t.lastIndexOf("/"))||"/",n=e.slug.match(/^(.*?)(?:-(\d+))?$/),r=n?.[1]||e.slug,u=n?.[2]?Number(n[2])+1:2,c=await $(a),f=new Set(c.map(m=>m.slug));let i=u;for(;f.has(`${r}-${i}`);)i++;const o=`${r}-${i}`,h=a==="/"?`/${o}`:`${a}/${o}`,l=await _(t,h),g=e.title.match(/^(.*?)(\d+)\s*$/),d=g?`${g[1]}${Number(g[2])+1}`:`${e.title} 2`;try{await P(l.route,{title:d})}catch{}return l}async function M(e){return s.post("/pages/reorganize",{operations:e})}export{S as a,w as b,z as c,W as d,B as e,I as f,$ as g,x as h,v as i,C as m,y as p,M as r,R as s,P as u};
