1import{_ as G}from"./dMhLlsre.js";import{_ as A,a as D}from"./BrmdqU7B.js";import{_ as H}from"./BoStOfpR.js";import{e as O,r as c,f as g,B as Z,l as q,c as d,a as s,h as _,b as l,w as r,j as o,v as J,x as K,t as $,g as Q,G as C,o as n,d as T,F as N,i as P,C as R,I as W}from"./C_kRKsmz.js";import{_ as M}from"./TG5nIkyV.js";import{_ as S}from"./Bm4W9Oo4.js";import{_ as X,a as Y,b as ee,c as te,d as ae,e as se,f as le}from"./CWcmC0gl.js";import{u as oe}from"./c6KYU9E-.js";import{u as E}from"./jbTebY_y.js";import"./DlAUqK2U.js";import"./BuouZTU-.js";import"./NIDhVy6u.js";import"./KlaINRS-.js";import"./Dd4laE0G.js";import"./CPTxyssP.js";import"./NRo6c83J.js";const ne={class:"mx-auto w-full max-w-[1700px]"},re={class:"mb-6 flex flex-wrap items-center justify-between gap-3"},ie={class:"mb-6 max-w-sm"},ue={class:"relative"},ce={class:"space-y-3 p-3.5"},de={key:1,class:"flex min-h-[50vh] items-center justify-center"},me={class:"max-w-md text-center"},pe={class:"mb-2 text-xl font-semibold"},_e={class:"mb-6 text-muted-foreground"},fe={key:2},ve={key:0,class:"mt-8 flex justify-center"},he=["onClick"],f=8,ge=24,Ue=O({__name:"public",setup(ye){oe({title:"Public templates - Templates On"});const i=c([]),y=c(!0),F=c(0),b=c(0),p=c(1),u=c(""),x=c(null),w=g(()=>b.value>0&&i.value.length>=F.value),v=g(()=>{const t=u.value.trim().toLowerCase();return t?i.value.filter(e=>(e.name||"").toLowerCase().includes(t)):i.value}),B=g(()=>Math.ceil(v.value.length/f)||1),I=g(()=>{const t=(p.value-1)*f;return v.value.slice(t,t+f)}),k=async()=>{if(!w.value)try{y.value=!0;const t=b.value+1,e=await E(`/api/v1/templates/public?page=${t}&limit=${ge}`),h=new Set(i.value.map(m=>m.id));i.value=[...i.value,...(e.templates||[]).filter(m=>!h.has(m.id))],F.value=e.pagination?.total??i.value.length,b.value=t}catch(t){console.error("Failed to fetch public templates:",t),C.error("Could not load public templates")}finally{y.value=!1}},j=t=>{p.value=t;const e=Math.floor(i.value.length/f);t>=e&&!w.value&&k()};Z(u,t=>{p.value=1,t.trim()&&!w.value&&k()});const U=async t=>{if(t.id)try{x.value=t.id;const e=await E(`/api/v1/templates/${t.id}/clone`,{method:"POST"});C.success(`"${t.name}" added to your templates`),W(`/app/templates/edit/${e.template.id}`)}catch{C.error("Failed to use this template. Please try again.")}finally{x.value=null}};return q(k),(t,e)=>{const h=G,m=A,V=H,L=D;return n(),d("div",ne,[s("div",re,[e[3]||(e[3]=s("div",null,[s("h1",{class:"text-2xl font-bold tracking-tight"},"Public templates"),s("p",{class:"mt-1 text-muted-foreground"},' Start from a ready-made design â "Use template" copies it into your account so you can edit it freely ')],-1)),l(o(M),{variant:"outline","as-child":""},{default:r(()=>[l(h,{to:"/app/templates"},{default:r(()=>[...e[2]||(e[2]=[T("My templates",-1)])]),_:1})]),_:1})]),s("div",ie,[s("div",ue,[e[4]||(e[4]=s("svg",{class:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[s("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)),J(s("input",{"onUpdate:modelValue":e[0]||(e[0]=a=>u.value=a),type:"search",placeholder:"Search templatesâ¦",class:"w-full rounded-md border border-input bg-background py-2 pl-9 pr-3 text-sm focus:outline-none focus:ring-2 focus:ring-ring"},null,512),[[K,u.value]])])]),y.value&&!i.value.length?(n(),_(m,{key:0},{default:r(()=>[(n(),d(N,null,P(8,a=>s("div",{key:a,class:"overflow-hidden rounded-xl border bg-card"},[l(o(S),{class:"w-full rounded-none",style:R({height:`${[10,14,12,16][a%4]}rem`})},null,8,["style"]),s("div",ce,[l(o(S),{class:"h-4 w-3/4"}),l(o(S),{class:"h-8 w-full"})])])),64))]),_:1})):v.value.length?(n(),d("div",fe,[l(m,null,{default:r(()=>[(n(!0),d(N,null,P(I.value,a=>(n(),_(L,{key:a.id,template:a,variant:"public",busy:x.value===a.id,onUse:z=>U(a)},null,8,["template","busy","onUse"]))),128))]),_:1}),B.value>1?(n(),d("div",ve,[l(o(le),{total:v.value.length,"sibling-count":1,page:p.value,"items-per-page":f,"onUpdate:page":j},{default:r(()=>[l(o(X),{class:"flex items-center gap-1"},{default:r(()=>[l(o(Y)),l(o(ee)),(n(!0),d(N,null,P(B.value,a=>(n(),_(o(te),{key:a,value:a,"is-active":p.value===a,"as-child":""},{default:r(()=>[s("button",{onClick:z=>j(a)},$(a),9,he)]),_:2},1032,["value","is-active"]))),128)),l(o(ae)),l(o(se))]),_:1})]),_:1},8,["total","page"])])):Q("",!0)])):(n(),d("div",de,[s("div",me,[l(V,{asset:"gallery",alt:"Nimo browsing the template gallery",size:"section",class:"mx-auto mb-6"}),s("h2",pe,$(u.value?"No templates match that search":"No public templates yet"),1),s("p",_e,$(u.value?"Try a different word, or start from a blank canvas instead.":"C
1ommunity templates will show up here as they are published."),1),u.value?(n(),_(o(M),{key:0,variant:"outline",onClick:e[1]||(e[1]=a=>u.value="")},{default:r(()=>[...e[5]||(e[5]=[T("Clear search",-1)])]),_:1})):(n(),_(o(M),{key:1,"as-child":""},{default:r(()=>[l(h,{to:"/app/templates"},{default:r(()=>[...e[6]||(e[6]=[T("Create your own",-1)])]),_:1})]),_:1}))])]))])}}});export{Ue 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.