1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jszip.min-DXD3Oxvq.js","assets/_commonjsHelpers-Cpj98o6Y.js"])))=>i.map(i=>d[i]); 2import{r as f,j as s,_ as xa}from"./index-BFZ9jTwb.js";import{k as C,I as T,aj as ja,u as ya,n as qe,ag as wa,q as Y,t as ee,w as O,p as se,v as ba,y as ys,a as va,H as Na,A as Ta,M as Sa}from"./FooterEngravedTerrain-CQKj1iKp.js";import{e as te,j as Fe,f as $,g as ka,h as Fa}from"./contentAuthors-y64pmOeD.js";import{d0 as Ca,cM as Aa,d1 as Ge,cP as Da,cW as _a,cQ as Pa,cR as Ua,cU as La}from"./App-A23lvCYV.js";import{M as $a,r as za}from"./index-CsDbW2MO.js";import"./_commonjsHelpers-Cpj98o6Y.js";const ws=["free","pro","lifetime","designcode","max"],Ls=["HTML Landing Page","React Landing Page","Figma File","Agent Skill","Design System","Xcode Project","Component","HTML Template","React Project","Prompt Pack","Automation Tutorial","General Document"],$s=["html","react","markdown","figma","swift","xcode","zip","other"],zs=[{key:"html",label:"HTML"},{key:"react",label:"React"},{key:"xcode",label:"Xcode"},{key:"markdown",label:"Markdown"},{key:"figma",label:"Figma"},{key:"assets",label:"Assets"},{key:"other",label:"Other"}],Ea=".md,.markdown,.html,.htm,.json,.swift,.zip",Ra=new Set(["md","markdown","html","htm","json","swift","zip"]),Ia=new Set(["md","markdown","html","htm","txt","json","css","js","jsx","ts","tsx","swift"]),Oa=40*1024*1024,Ze=48e3,Ma=18,Es=(e="")=>String(e||"").normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),Ka={"landing-pages":"html-landing-pages","html-template":"html-landing-pages","html-templates":"html-landing-pages","react-projects":"react-landing-pages","react-project":"react-landing-pages","react-template":"react-landing-pages",figma:"figma-files","figma-file":"figma-files","agent-skill":"agent-skills","automations-tutorials":"agent-skills","design-system":"design-systems","design-md":"design-systems",xcode:"xcode-projects","xcode-project":"xcode-projects","ios-projects":"xcode-projects","swiftui-projects":"xcode-projects"},ae=(e="")=>{const a=Es(e);return Ka[a]||a},Rs=[{key:"html-landing-pages",title:"Landing Pages",sortOrder:10},{key:"figma-files",title:"Figma Files",sortOrder:30},{key:"agent-skills",title:"Agent Skills",sortOrder:40},{key:"design-systems",title:"Design Systems",sortOrder:50},{key:"xcode-projects",title:"Xcode Projects",sortOrder:60}],Ba=(e={})=>{const a=Es(e.key||e.id||e.docId||e.title),t=ae(e.key||e.id||e.docId||e.title),n=Rs.find(o=>o.key===t);return{...n,...e,key:t,title:!!(a&&a!==t&&n)?n.title:e.title||n?.title||t}},Is=(e=[])=>{const a=new Map(Rs.map(t=>[t.key,t]));return e.map(Ba).forEach(t=>{t.key!=="react-landing-pages"&&a.set(t.key,{...a.get(t.key)||{},...t})}),[...a.values()].sort((t,n)=>(t.sortOrder??1e3)-(n.sortOrder??1e3)||String(t.title).localeCompare(String(n.title)))},U={title:"New Template",slug:"new-template",templateId:"",headline:"",description:"",summary:"",shortDescription:"",longDescription:`## Overview 3 4Describe what this template includes and how members should use it.`,templateType:"HTML Landing Page",category:"Landing Pages",collectionKey:"html-landing-pages",tags:"Landing Page, Template, DesignCode",accessLevel:"free",contentAccessLevel:"pro",sortOrder:100,pageCount:1,views:0,forks:0,published:!1,featured:!0,premium:!0,shareSourceCode:!0,coverUrl:"",downloadUrl:"",downloadPath:"",downloadFileName:"",downloadFileSize:0,templateFiles:[],proLink:"",purchaseUrl:"",priceUsd:"",lockedFiles:"Source pack, Implementation checklist, Prompt sequence",authorName:"DesignCode",username:"designcode",createdAt:"",seoTitle:"",seoDescription:"",language:"html"},oe={status:"idle",progress:0,fileName:"",fileSize:0,fileType:"",textFileCount:0,totalCharacters:0,message:""},Ha=[{key:"designcode",docId:"designcode",id:"designcode",slug:"designcode",username:"designcode",name:"DesignCode",title:"DesignCode"}],L=(e="")=>String(e||"").toLowerCase().trim().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,120),me=(e="")=>{const a=String(e||"").toLowerCase().match(/\.([a-z0-9]+)$/);return a?a[1]:""},Os=(e=null)=>!!(e&&Ra.has(me(e.name))),qa=(e="")=>Ia.has(me(e)),Ga=e=>new Promise((a,t)=>{const n=new FileReader;n.onload=()=>a(String(n.result||"")),n.onerror=()=>t(n.error||new Error("Unable to read this source file.")),n.readAsText(e)}),Xe=(e="",a=Ze)=>String(e||"").replace(/\r/g,"").split("\0").join("").trim().slice(0,a),Ms=({path:e="",text:a=""}={})=>{const t=Xe(a,12e3);return t?`--- ${e||"source"} --- 5${t}`:""},Va=async e=>{const a=await Ga(e),t=Xe(a);if(!t)throw new Error("This source file does not contain readable text.");return{kind:me(e.name).startsWith("htm")?"html":"markdown",files:[{path:e.name,characters:t.length}],text:Ms({path:e.name,text:t}),totalCharacters:t.length}},Za=async e=>{const{default:a}=await xa(async()=>{const{default:g}=await import("./jszip.min-DXD3Oxvq.js").then(x=>x.j);return{default:g}},__vite__mapDeps([0,1])),t=await a.loadAsync(e),n=Object.values(t.files).filter(g=>!g.dir&&qa(g.name)).slice(0,Ma);if(!n.length)throw new Error("This ZIP does not include readable Markdown, HTML, or text files.");const l=[];let o="",c=0;for(const g of n){if(o.length>=Ze)break;const x=await g.async("text"),m=Xe(x,12e3);if(!m)continue;const j=Ms({path:g.name,text:m});o=`${o}${o?` 6 7`:""}${j}`.slice(0,Ze),c+=m.length,l.push({path:g.name,characters:m.length})}if(!o.trim())throw new Error("This ZIP does not include readable text content.");return{kind:"zip",files:l,text:o,totalCharacters:c}},Wa=async e=>{if(!Os(e))throw new Error("Attach a Markdown, HTML, or ZIP file to start a template.");if(e.size>Oa)throw new Error("Template source files must be under 40 MB.");return me(e.name)==="zip"?Za(e):Va(e)},Ja=(e="",a=[],t="")=>{const n=L(e)||"template",l=String(t||""),o=new Set(a.filter(c=>!l||![c.docId,c.id,ce(c.slug||"")].includes(l)).flatMap(c=>[c.slug,c.id,c.docId]).map(c=>
7L(c)).filter(Boolean));if(!o.has(n))return n;for(let c=2;c<100;c+=1){const g=`${n}-${c}`;if(!o.has(g))return g}return`${n}-${Date.now().toString(36)}`},bs=(e="")=>{const a=Array.isArray(e)?e:We(e);return Je(a.slice(0,8))},vs=({current:e={},generated:a={},templates:t=[],selectedId:n="",fallbackFileName:l=""}={})=>{const o=a.title||e.title||l.replace(/\.[^.]+$/,"")||"New Template",c=Ja(a.slug||o,t,n),g=ae(a.collectionKey||e.collectionKey||U.collectionKey),x=Ls.includes(a.templateType)?a.templateType:e.templateType||U.templateType,m=$s.includes(a.language)?a.language:e.language||U.language;return{...e,title:o,slug:c,headline:a.headline||o,description:a.description||a.shortDescription||a.summary||e.description,summary:a.summary||a.description||a.shortDescription||e.summary,shortDescription:a.shortDescription||a.description||a.summary||e.shortDescription,longDescription:a.longDescription||e.longDescription,templateType:x,category:a.category||x,collectionKey:g,tags:bs(a.tags||e.tags),language:m,pageCount:Number(a.pageCount)||e.pageCount||1,lockedFiles:bs(a.lockedFiles||e.lockedFiles),seoTitle:a.seoTitle||`${o} | DesignCode`,seoDescription:a.seoDescription||a.description||a.shortDescription||e.seoDescription}},ce=(e="")=>encodeURIComponent(e),We=(e="")=>String(e||"").split(/[,\n]/).map(a=>a.trim()).filter(Boolean),Je=(e=[])=>Array.isArray(e)?e.join(", "):String(e||""),Xa=(e="")=>{const a=L(e);return["html","html-template","html-landing-page","static-site"].includes(a)?"html":["react","react-package","react-project","jsx","tsx","vite","next"].includes(a)?"react":["xcode","xcode-project","swift","swiftui","ios","macos"].includes(a)?"xcode":["markdown","md","readme","prompt","prompts","instructions"].includes(a)?"markdown":["figma","fig","figma-file","design-file"].includes(a)?"figma":["asset","assets","image","images","media","video"].includes(a)?"assets":zs.some(t=>t.key===a)?a:"other"},Ks=(e={},a="other")=>{const t=e.templateFileType||e.template_file_type||e.fileType||e.file_type||e.type||e.group||e.language||a,n=Xa(t);if(n!=="other")return n;const l=[e.title,e.label,e.fileName,e.downloadFileName,e.name,e.path,e.url,e.contentType].filter(Boolean).join(" ").toLowerCase(),o=me(e.fileName||e.downloadFileName||e.name||e.path||e.url||"");return["html","htm"].includes(o)||l.includes("html")?"html":["jsx","tsx"].includes(o)||l.includes("react")||l.includes("package.json")?"react":["swift","xcodeproj","xcworkspace"].includes(o)||l.includes("xcode")||l.includes("swift")?"xcode":["md","markdown"].includes(o)||l.includes("markdown")||l.includes("readme")||l.includes("prompt")?"markdown":["fig","figma"].includes(o)||l.includes("figma")?"figma":["png","jpg","jpeg","gif","webp","svg","mp4","mov","webm"].includes(o)||l.includes("asset")?"assets":"other"},Qa=(e={})=>{const a=[],t=(n,l="")=>{if(n){if(Array.isArray(n)){n.forEach(o=>t(o,l));return}typeof n=="object"&&a.push(l?{...n,templateFileType:n.templateFileType||n.template_file_type||n.type||l}:n)}};return["templateFiles","template_files","memberFileDetails","member_file_details","downloadFiles","download_files","downloads"].forEach(n=>t(e[n])),["memberFileGroups","member_file_groups","fileGroups","file_groups"].forEach(n=>{Array.isArray(e[n])&&e[n].forEach(l=>{const o=l?.key||l?.type||l?.label||l?.title||"";[l?.files,l?.items,l?.resources,l?.downloads].forEach(c=>t(c,o))})}),["memberFiles","lockedFiles","files"].forEach(n=>{Array.isArray(e[n])&&e[n].forEach(l=>{n==="files"&&!Ae(l)&&!Ye(l)||l&&typeof l=="object"&&t(l)})}),a},Ce=(e={},a=0)=>{const t=Ae(e),n=Ye(e),l=e.fileName||e.downloadFileName||e.download_file_name||e.filename||e.name||"";return{id:e.id||e.key||n||t||`template-file-${a+1}`,type:Ks(e),title:e.title||e.label||l||`Template file ${a+1}`,url:Hs(t)?"":t,path:n,fileName:l,fileSize:Number(e.fileSize||e.downloadFileSize||e.download_file_size||e.size||0)||0,contentType:e.contentType||e.content_type||e.mimeType||""}},Ya=(e={})=>Qa(e).map((a,t)=>Ce(a,t)),et=(e={})=>(Array.isArray(e.lockedFiles)?e.lockedFiles:Array.isArray(e.memberFiles)?e.memberFiles:Array.isArray(e.files)?e.files:[]).map((a,t)=>
7typeof a=="string"?a:!a||typeof a!="object"?"":a.title||a.label||a.fileName||a.downloadFileName||a.name||`Template file ${t+1}`).filter(Boolean),Ns=(e=[])=>(Array.isArray(e)?e:[]).map((a,t)=>Ce(a,t)).filter(a=>String(a.title||"").trim()||String(a.url||"").trim()||String(a.path||"").trim()).map((a,t)=>({id:a.id||`template-file-${t+1}`,templateFileType:a.type,type:a.type,title:String(a.title||"").trim()||String(a.fileName||"").trim()||`Template file ${t+1}`,url:String(a.url||"").trim(),path:String(a.path||"").trim(),fileName:String(a.fileName||"").trim(),fileSize:Number(a.fileSize)||0,contentType:a.contentType||""})),st=e=>{const{type:a,checked:t,value:n}=e.target;return a==="checkbox"?t:n},at=e=>{if(!e)return"";if(typeof e=="string"&&/^\d{4}-\d{2}-\d{2}/.test(e))return e.slice(0,10);if(typeof e.toDate=="function")return e.toDate().toISOString().slice(0,10);if(typeof e.seconds=="number")return new Date(e.seconds*1e3).toISOString().slice(0,10);const a=new Date(e);return Number.isNaN(a.getTime())?"":a.toISOString().slice(0,10)},tt=(e={})=>e.coverUrl||e.imageUrl||e.image_url||e.img||e.cover?.url||e.cover?.file?.url||e.previewImage?.url||"",Ae=(e={})=>e.downloadUrl||e.download_url||e.fileUrl||e.file_url||e.resourceUrl||"",it="members/pro/promptui/template-downloads/",Qe=(e="")=>{const a=String(e||"").trim();if(!a)return"";try{const t=new URL(a);if(t.hostname!=="firebasestorage.googleapis.com")return"";const n=t.pathname.match(/^\/v0\/b\/[^/]+\/o\/(.+)$/);return n?decodeURIComponent(n[1]):""}catch{return""}},Bs=(e="")=>String(e||"").trim().startsWith(it),Hs=(e="")=>Bs(Qe(e)),nt=(e={})=>{const a=Ae(e);return Hs(a)?"":a},Ye=(e={})=>e.downloadPath||e.download_path||e.storagePath||e.firebaseStoragePath||Qe(Ae(e))||"",Ts=(e={})=>e.purchaseUrl||e.purchase_url||e.proLink||e.pro_link||"",rt=(e={})=>({...U,...e,slug:e.slug||e.id||"",templateId:e.templateId||e.template_id||"",headline:e.headline||e.title||"",description:e.description||e.summary||"",summary:e.summary||e.description||"",shortDescription:e.shortDescription||e.short_description||e.excerpt||e.summary||e.description||"",longDescription:e.longDescription||e.long_description||e.markdown||"",templateType:e.templateType||e.template_type||e.type||U.templateType,category:e.category||e.tag||e.collectionTitle||U.category,collectionKey:ae(e.collectionKey||e.collection_key||e.collectionTitle||U.collectionKey),tags:Je(e.tags),accessLevel:e.accessLevel||"free",contentAccessLevel:e.contentAccessLevel||e.content_access_level||(e.premium?"pro":"free"),pageCount:Number(e.pageCount||e.pages||1),views:Number(e.views||0),forks:Number(e.forks||e.remixes||0),published:e.published??!1,featured:e.featured??!0,premium:e.premium??!0,shareSourceCode:e.shareSourceCode??e.share_source_code??!0,coverUrl:tt(e),downloadUrl:nt(e),downloadPath:Ye(e),downloadFileName:e.downloadFileName||e.download_file_name||"",downloadFileSize:Number(e.downloadFileSize||e.download_file_size||0),templateFiles:Ya(e),proLink:e.proLink||e.pro_link||Ts(e),purchaseUrl:Ts(e),priceUsd:e.priceUsd??e.price_usd??e.price??"",lockedFiles:Je(et(e)),authorName:e.authorName||e.author_name||e.username||"DesignCode",username:e.username||e.userSlug||e.user_slug||"designcode",createdAt:at(e.createdAt||e.created_at||e.publishedAt),seoTitle:e.seoTitle||e.metadata?.title||"",seoDescription:e.seoDescription||e.metadata?.description||"",language:e.language||U.language}),de=(e={})=>{const a=e.authorName||e.author_name||e.name||e.title||e.displayName||e.username||"DesignCode",t=e.username||e.userSlug||e.user_slug||e.slug||L(a),n=e.key||e.docId||e.id||t||L(a);return{...e,key:n,docId:e.docId||e.id||n,id:e.id||e.docId||n,slug:e.slug||t,username:t,name:a,title:e.title||a}},qs=(e={})=>{const a=de(e),t=$(a).trim().toLowerCase(),n=Fe(a).trim().toLowerCase();return t==="designcode"||n==="designcode"?"designcode":n||t||te(a).trim().toLowerCase()},lt=(e=[])=>{const a=new Map;return e.forEach(t=>{const n=de(t),l=qs(n);!l||!$(n)||a.has(l)||a.set(l,{...n,key:l,docId:l,id:l})}),[...a.values()].sort((t,n)=>{const l=$(t),o=$(n);return l==="DesignCode"?-1:o==="DesignCode"?1:l.localeCompare(o)})},ot=(e={},a=[])=>{const t=de(e),n=$(t).toLowerCase(),l=Fe(t).toLowerCase(),o=a.find(c=>{const g=$(c).toLowerCase(),x=Fe(c).toLowerCase(),m=te(c).toLowerCase();return l&&(x===l||m===l)||n&&g===n});return o?te(o):qs(t)},Q=e=>{const a=`${e?.code||""} ${e?.message||e||""}`.toLowerCase();return a.includes("permission-denied")||a.includes("missing or insufficient permissions")},Ss=(e={})=>{const a=e.updatedAt||e.createdAt||e.created_at||e.publishedAt;if(!a)return 0;if(typeof a.toMillis=="function")return a.toMillis();if(typeof a.toDate=="function")return a.toDate().getTime();if(typeof a.seconds=="number")return a.seconds*1e3;const n=new Date(a).getTime();return Number.isNaN(n)?0:n},Gs=(e=[])=>[...e].sort((a,t)=>{const n=Ss(t),l=Ss(a);return n!==l?n-l:(a.sortOrder??1e3)-(t.sortOrder??1e3)||String(a.title).localeCompare(String(t.title))}),ks=async()=>{const e=await Y(ee(se(C,"templates"),O("siteKey","==","promptui")));return Gs(e.docs.map(a=>({...a.data(),docId:a.id})))},Fs=async(e={})=>{const a=new Map,t=l=>{l.docs.forEach(o=>{const c={...o.data(),docId:o.id};c.siteKey==="promptui"&&a.set(o.id,c)})};e.uid&&t(await Y(ee(se(C,"templates"),O("ownerUids","array-contains",e.uid)))),e.email&&t(await Y(ee(se(C,"templates"),O("ownerEmails","array-contains",e.email))));const n=Pa(e.authorKeys||[]).map(Ua).slice(0,10);return n.length&&t(await Y(ee(se(C,"templates"),O("ownerAuthorKeys","array-contains-any",n)))),Gs([...a.values()])},Cs=async()=>{const a=(await Y(ee(se(C,"templateCollections"),O("siteKey","==","promptui")))).docs.map(t=>({...t.data(),docId:t.id})).sort((t,n)=>(t.sortOrder??1e3)-(n.sortOrder??1e3)||String(t.title).localeCompare(String(n.title)));return Is(a)},As=async()=>{const a=(await Y(ee(se(C,"templateCollections"),O("siteKey","==","promptui"),O("published","==",!0),O("accessLevel","==","free")))).docs.map(t=>({...t.data(),docId:t.id})).sort((t,n)=>(t.sortOrder??1e3)-(n.sortOrder??1e3)||String(t.title).localeCompare(String(n.title)));return Is(a)},ct=(e="asset")=>String(e||"asset").toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,120)||"asset",Ds=({file:e,slug:a,kind:t,onProgress:n})=>new Promise((l,o)=>{if(!ys){o(new Error("Firebase Storage is not configured."));return}const c=va?.currentUser?.uid;if(!c){o(new Error("Sign in is required to upload template assets."));return}const g=L(a||"template"),x=Date.now(),j=`${t==="download"?`members/pro/promptui/template-downloads/${c}`:`public/promptui/template-assets/${c}`}/${g}/${t}-${x}-${ct(e.name)}
7`,h=Na(Ta(ys,j),e,{contentType:e.type||"application/octet-stream"});h.on("state_changed",S=>{const B=S.totalBytes?S.bytesTransferred/S.totalBytes*100:0;n?.(B)},o,async()=>{const S=t==="download"?"":await Sa(h.snapshot.ref);l({url:S,path:j,name:e.name,size:e.size,contentType:e.type||"application/octet-stream"})})});function N({label:e,hint:a="",className:t="",children:n}){return s.jsxs("label",{className:`admin-course-field ${t}`.trim(),children:[s.jsxs("span",{children:[e,a?s.jsx("em",{children:a}):null]}),n]})}function dt({title:e,description:a,children:t}){return s.jsxs("details",{className:"admin-advanced-panel",children:[s.jsxs("summary",{children:[s.jsxs("span",{children:[s.jsx("strong",{children:e}),a?s.jsx("em",{children:a}):null]}),s.jsx(T,{icon:"solar:alt-arrow-down-linear",width:16,height:16,"aria-hidden":"true"})]}),s.jsx("div",{className:"admin-advanced-panel-body",children:t})]})}function Ve({label:e,checked:a,onChange:t,disabled:n=!1}){return s.jsxs("label",{className:"admin-course-toggle",children:[s.jsx("input",{type:"checkbox",checked:a,onChange:t,disabled:n}),s.jsx("span",{"aria-hidden":"true"}),s.jsx("strong",{children:e})]})}function _s({author:e,className:a=""}){const t=$(e),n=ka(e);return s.jsx("span",{className:`admin-author-avatar ${a}`.trim(),"aria-hidden":"true",children:n?s.jsx("img",{src:n,alt:"",loading:"lazy",decoding:"async"}):Fa(t)})}function mt({options:e=[],selectedId:a="",onChange:t,disabled:n=!1}){const[l,o]=f.useState(!1),c=f.useRef(null);if(f.useEffect(()=>{if(!l)return;const m=h=>{c.current&&!c.current.contains(h.target)&&o(!1)},j=h=>{h.key==="Escape"&&o(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",j)}},[l]),!e.length)return s.jsx("p",{className:"admin-author-select-empty",children:"No authors found."});const g=e.find(m=>te(m)===a)||e[0],x=$(g)||"Select author";return s.jsxs("div",{className:`admin-author-select${l?" is-open":""}`,ref:c,children:[s.jsxs("button",{type:"button",className:"admin-author-select-trigger",onClick:()=>!n&&o(m=>!m),"aria-expanded":l,"aria-haspopup":"listbox",disabled:n,children:[s.jsx("span",{className:"admin-author-select-trigger-avatars",children:s.jsx(_s,{author:g,className:"is-compact"})}),s.jsx("span",{className:"admin-author-select-trigger-label",children:x}),s.jsx(T,{icon:"solar:alt-arrow-down-linear",className:"admin-author-select-chevron",width:16,height:16,"aria-hidden":"true"})]}),l?s.jsx("div",{className:"admin-author-select-menu",role:"listbox","aria-label":"Authors",children:e.map(m=>{const j=te(m),h=$(m),S=j===a;return s.jsxs("button",{type:"button",role:"option","aria-selected":S,className:`admin-author-select-option${S?" is-selected":""}`,onClick:()=>{t?.(j),o(!1)},children:[s.jsx(_s,{author:m}),s.jsx("span",{className:"admin-author-select-option-name",children:h}),S?s.jsx(T,{icon:"lucide:check",width:14,height:14,"aria-hidden":"true"}):null]},j)})}):null]})}function ut({coverUrl:e="",uploadState:a={},onUpload:t,disabled:n=!1}){const l=f.useRef(null),o=a.status==="uploading";return s.jsxs("div",{className:"admin-course-field admin-course-cover-field",children:[s.jsx("span",{children:"Cover"}),s.jsxs("div",{className:"admin-course-cover-upload",children:[s.jsx("input",{ref:l,type:"file",accept:"image/png,image/jpeg,image/jpg,image/webp,image/avif",disabled:n||o,onChange:c=>{t?.(c.target.files?.[0]),c.target.value=""}}),s.jsxs("button",{type:"button",className:`admin-course-cover-button${e?" has-image":""}`,disabled:n||o,onClick:()=>l.current?.click(),children:[e?s.jsx("img",{src:e,alt:"",loading:"lazy",decoding:"async"}):s.jsxs("span",{className:"admin-course-cover-placeholder","aria-hidden":"true",children:[s.jsx(T,{icon:"solar:gallery-add-linear",width:28,height:28}),s.jsx("strong",{children:"Upload cover"}),s.jsx("em",{children:"PNG, JPG, or WebP"})]}),s.jsxs("span",{className:"admin-course-cover-overlay",children:[s.jsx(T,{icon:"solar:upload-square-linear",width:18,height:18,"aria-hidden":"true"}),e?"Replace image":"Choose image"]})]}),o?s.jsx("div",{className:"admin-upload-meter","aria-label":"Cover upload progress",children:s.jsx("span",{style:{width:`${Math.min(100,Math.round(a.progress||0))}%`}})}):null,a.message?s.jsx("p",{className:`admin-course-cover-note${a.status==="error"?" is-error":""}`,children:a.message}):null]})]})}function pt({downloadUrl:e="",downloadPath:a="",fileName:t="",fileSize:n=0,uploadState:l={},inputId:o="admin-template-download-file",onUpload:c,disabled:g=!1}){const x=l.status==="uploading",m=!!(e||a),j=t||(m?"Download file attached":"ZIP, source files, prompts, templates, or project assets."),h=x?`${Math.round(l.progress||0)}%`:m?es(n)||"Attached":"Upload";return s.jsx("div",{className:"admin-download-editor admin-template-download-editor",children:s.jsxs("div",{className:"admin-download-upload",children:[s.jsx("input",{id:o,type:"file",accept:".zip,.html,.htm,.md,.txt,.json,.fig,.sketch,.tsx,.jsx,.js,.css,.pdf",disabled:g||x,onChange:S=>{c?.(S.target.files?.[0]),S.target.value=""}}),s.jsxs("label",{htmlFor:o,children:[s.jsx(T,{icon:"solar:download-minimalistic-linear",width:21,height:21,"aria-hidden":"true"}),s.jsxs("span",{children:["Download file",s.jsx("em",{children:l.message||j})]}),s.jsx("strong",{children:h})]}),x?s.jsx("div",{className:"admin-upload-meter","aria-label":"Download upload progress",children:s.jsx("span",{style:{width:`${Math.min(100,Math.round(l.progress||0))}%`}})}):null,l.status==="error"&&l.message?s.jsx("p",{className:"admin-course-error",children:l.message}):null]})})}function ht({files:e=[],uploadState:a={}
7,inputId:t="admin-template-member-file",onAdd:n,onRemove:l,onChange:o,onUpload:c,disabled:g=!1}){const x=a.status==="uploading";return s.jsxs("div",{className:"admin-download-editor admin-template-files-editor",children:[s.jsxs("div",{className:"admin-download-editor-head",children:[s.jsxs("div",{children:[s.jsx("h3",{children:"Typed member files"}),s.jsx("p",{children:"Group template downloads by format for the public detail page."})]}),s.jsx("button",{type:"button",className:"admin-course-icon-button",onClick:n,disabled:g,"aria-label":"Add typed template file",children:s.jsx(T,{icon:"lucide:plus",width:17,height:17,"aria-hidden":"true"})})]}),s.jsxs("div",{className:"admin-download-upload",children:[s.jsx("input",{id:t,type:"file",accept:".zip,.html,.htm,.md,.markdown,.txt,.json,.fig,.sketch,.tsx,.jsx,.js,.css,.pdf,.swift,.xcodeproj,.xcworkspace,.png,.jpg,.jpeg,.webp,.svg,.mp4,.mov",disabled:g||x,onChange:m=>{c?.(m.target.files?.[0]),m.target.value=""}}),s.jsxs("label",{htmlFor:t,children:[s.jsx(T,{icon:"solar:folder-with-files-linear",width:21,height:21,"aria-hidden":"true"}),s.jsxs("span",{children:["Upload typed file",s.jsx("em",{children:a.message||"HTML, React packages, Xcode projects, Markdown, Figma, or assets."})]}),s.jsx("strong",{children:x?`${Math.round(a.progress||0)}%`:"Upload"})]}),x?s.jsx("div",{className:"admin-upload-meter","aria-label":"Template file upload progress",children:s.jsx("span",{style:{width:`${Math.min(100,Math.round(a.progress||0))}%`}})}):null,a.status==="error"&&a.message?s.jsx("p",{className:"admin-course-error",children:a.message}):null]}),s.jsx("div",{className:"admin-download-list",children:e.length?e.map((m,j)=>s.jsxs("div",{className:"admin-download-row admin-template-file-row",children:[s.jsxs("div",{className:"admin-download-row-fields admin-template-file-row-fields",children:[s.jsx("select",{value:m.type||"other",onChange:h=>o?.(j,"type",h.target.value),"aria-label":`Template file ${j+1} type`,disabled:g,children:zs.map(h=>s.jsx("option",{value:h.key,children:h.label},`template-file-type-${h.key}`))}),s.jsx("input",{value:m.title||"",onChange:h=>o?.(j,"title",h.target.value),placeholder:"File title","aria-label":`Template file ${j+1} title`,disabled:g}),s.jsx("input",{value:m.url||m.path||"",onChange:h=>{const S=h.target.value;o?.(j,m.path&&!m.url?"path":"url",S)},placeholder:m.path&&!m.url?"Protected Firebase Storage file":"https://...","aria-label":`Template file ${j+1} URL or path`,disabled:g})]}),s.jsx("span",{className:"admin-download-row-meta",children:es(m.fileSize)}),s.jsx("button",{type:"button",className:"admin-course-icon-button is-danger",onClick:()=>l?.(j),disabled:g,"aria-label":`Remove ${m.title||"template file"}`,children:s.jsx(T,{icon:"lucide:trash-2",width:15,height:15,"aria-hidden":"true"})})]},m.id||m.path||m.url||`template-file-${j}`)):s.jsx("p",{className:"admin-download-empty",children:"No typed template files yet."})})]})}function gt({sourceState:e={},uploadState:a={},onUpload:t,disabled:n=!1}){const l=f.useRef(null),o=["reading","generating","uploading"].includes(e.status)||a.status==="uploading",c=e.status==="ready",g=e.status==="error",x=e.message||(c?`${e.fileName} processed.`:o?"Processing source file...":"Attach Markdown, HTML, JSON, Swift, or ZIP to generate template info."),m=c?`${e.textFileCount||1} text file${e.textFileCount===1?"":"s"} scanned`:"Step 01";return s.jsxs("article",{id:"source",className:`spotlight-card admin-course-card admin-template-source-card${c?" is-ready":""}`.trim(),children:[s.jsxs("div",{className:"admin-course-panel-head",children:[s.jsx("h2",{children:"Source File"}),s.jsx("span",{children:m})]}),s.jsxs("div",{className:"admin-template-source-body",children:[s.jsxs("div",{className:"admin-template-source-copy",children:[s.jsx("span",{className:"admin-template-source-mark","aria-hidden":"true",children:s.jsx(T,{icon:c?"solar:verified-check-linear":g?"solar:danger-triangle-linear":"solar:file-text-linear",width:24,height:24})}),s.jsxs("div",{children:[s.jsx("strong",{children:c?"Template info generated":"Start with one file"}),s.jsx("p",{children:x}),e.fileName?s.jsxs("em",{children:[e.fileName,e.fileSize?` · ${es(e.fileSize)}`:""]}):null]})]}),s.jsxs("div",{className:"admin-template-source-actions",children:[s.jsx("input",{ref:l,type:"file",accept:Ea,disabled:n||o,onChange:j=>{t?.(j.target.files?.[0]),j.target.value=""}}),s.jsxs("button",{type:"button",className:c?"btn-secondary":"btn-primary",disabled:n||o,onClick:()=>l.current?.click(),children:[s.jsx(T,{icon:o?"solar:refresh-circle-linear":c?"solar:refresh-linear":"solar:upload-square-linear",width:16,height:16,className:o?"admin-action-icon
7is-spinning":"admin-action-icon","aria-hidden":"true"}),o?"Processing...":c?"Replace Source":"Attach Source"]})]})]}),o?s.jsx("div",{className:"admin-upload-meter admin-template-source-meter","aria-label":"Source processing progress",children:s.jsx("span",{style:{width:`${Math.min(100,Math.round(e.progress||a.progress||18))}%`}})}):null,g&&e.message?s.jsx("p",{className:"admin-course-error admin-template-source-error",children:e.message}):null]})}function ft({authReady:e,isLoggedIn:a,isAdmin:t,canAccessStudio:n=t,isRefreshingClaims:l=!1,claimRefreshError:o="",onRefreshClaims:c=()=>{},onRequestLogin:g}){if(!e)return s.jsx("section",{className:"admin-course-guard admin-course-guard-loading","aria-busy":"true","aria-label":"Loading",children:s.jsx(La,{})});const x=a?"Template access required.":"Sign in to continue.",m=a?"Your current account cannot edit this template. Ask an admin to add you as an owner or refresh your session if access was just granted.":"Use the same account menu you use for the site, then return here.";return s.jsx("section",{className:"admin-course-guard",children:s.jsxs("div",{className:"spotlight-card admin-course-guard-panel",children:[s.jsx("span",{className:"admin-course-orbit","aria-hidden":"true",children:s.jsx(T,{icon:t?"solar:verified-check-linear":"solar:lock-keyhole-linear",width:28,height:28})}),s.jsxs("div",{className:"eyebrow admin-course-eyebrow",children:[s.jsx("span",{className:"dot"}),"Template Studio"]}),s.jsx("h1",{className:"hero-title",children:s.jsx("span",{className:"title-muted",children:x})}),s.jsx("p",{className:"hero-subtitle",children:m}),!a&&s.jsx("button",{type:"button",className:"btn-primary",onClick:g,children:"Login"}),e&&a&&!n&&s.jsxs("button",{type:"button",className:"btn-primary",onClick:c,disabled:l,children:[s.jsx(T,{icon:"solar:refresh-linear",width:16,height:16,"aria-hidden":"true"}),l?"Refreshing":"Refresh session"]}),o&&s.jsx("p",{className:"admin-course-error",children:o})]})})}function xt({title:e="",message:a="",tone:t="idle",progress:n=0,isSaving:l=!1,onDismiss:o}){if(!a&&!l)return null;const c=Math.max(0,Math.min(100,Number(n)||0));return s.jsxs("div",{className:`admin-template-save-toast is-${t}`.trim(),role:"status","aria-live":"polite","aria-busy":l,children:[s.jsxs("div",{className:"admin-template-save-row",children:[s.jsxs("div",{className:"admin-template-save-copy",children:[s.jsx("span",{className:"admin-template-save-dot","aria-hidden":"true"}),s.jsx("strong",{children:e}),a?s.jsx("em",{children:a}):null]}),s.jsx("button",{type:"button",className:"admin-template-save-close",onClick:o,"aria-label":"Dismiss notification",children:s.jsx(T,{icon:"lucide:x",width:14,height:14,"aria-hidden":"true"})})]}),s.jsx("div",{className:"admin-template-save-track",role:"progressbar","aria-label":e||"Save progress","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":c,children:s.jsx("span",{style:{"--admin-template-save-progress":`${c}%`}})})]})}const Ps=(e={})=>e.published?"Published":"Draft",es=(e=0)=>{const a=Number(e)||0;return a?a<1024*1024?`${Math.max(1,Math.round(a/1024))} KB`:`${(a/(1024*1024)).toFixed(1)} MB`:"No file"},Us=(e="")=>{const a=String(e||"");try{return decodeURIComponent(a)}catch{return a}},jt=(e={})=>[e.docId,e.id,e.slug,e.templateId,e.template_id,e.slug?ce(e.slug):""].map(a=>String(a||"").trim()).filter(Boolean),yt=(e={},a="")=>{const t=String(a||"").trim();if(!t)return!1;const n=Us(t);return jt(e).some(l=>l===t||Us(l)===n)};function Ct({authReady:e=!1,isLoggedIn:a=!1,currentUser:t=null,userEmail:n="",onRefreshClaims:l=async()=>!1,onRequestLogin:o=()=>{},onContentChange:c=()=>{},SiteHeader:g,isModal:x=!1,initialMode:m="create",initialTemplate:j=null}){const h=Ca(t),S=f.useMemo(()=>Aa(t,n),[t,n]),B=j?.docId||j?.id||j?.slug||"",k=!!(h||m==="edit"&&Ge(j,t,n)),ss=f.useRef(!1),De=f.useRef(""),ue=f.useRef(!1),_e=f.useRef(""),[pe,as]=f.useState([]),[Pe,ts]=f.useState([]),[he,ge]=f.useState("idle"),[is,ns]=f.useState(""),[D,Ue]=f.useState(""),[r,A]=f.useState(U),[z,Le]=f.useState("idle"),[$e,ze]=f.useState("idle"),[Ee,H]=f.useState("idle"),[rs,M]=f.useState(""),[Vs,ie]=f.useState(!1),[ls,q]=f.useState("idle"),[os,ne]=f.useState(""),[Zs,fe]=f.useState("idle"),[Ws,xe]=f.useState(""),[je,_]=f.useState({cover:{status:"idle",progress:0,message:""},download:{status:"idle",progress:0,message:""},templateFile:{status:"idle",progress:0,message:""}}),[cs,R]=f.useState(oe),ye=t?.uid||n||"",P=L(r.slug||r.title),Re=!!(D?Ge(r,t,n):h),G=!!h,Js=Zs==="refreshing",F=pe,Xs=Pe.find(i=>ae(i.key||i.id||i.docId)===ae(r.collectionKey)),Qs=F.filter(i=>i.published).length,Ys=F.filter(i=>i.premium).length,Ie=We(r.lockedFiles),ea=Ns(r.templateFiles),we=P?`/templates/${ce(P)}`:"/templates",V=!!(h&&!D),ds=!V||cs.status==="ready",re=!!(k&&Re&&C&&P&&r.title.trim()&&ds),E=z==="saving",be=ls==="deleting",ve=E||be,Z=E&&$e==="publish",W=E&&$e==="draft",ms=!!(x&&h&&D&&C),Ne=$e==="publish"?"publish":"draft",sa=Ne==="publish"?"Publish":"Draft",aa=Ne==="publish"?"Publishing":"Saving",ta=E?Ee==="refreshing"?82:46:z==="ready"||z==="error"?100:0,ia=z==="error"?"error":z==="ready"?"success":E?"saving":"idle",na=z==="error"?`${sa} failed`:z==="ready"?Ne==="publish"?"Published":"Saved":E?Ee==="refreshing"?"Refreshing library":`${aa} template`:"Ready",ra=rs||(E?Ee==="refreshing"?"Updating the template list and preview data.":Ne==="publish"?"Sending the template live.":"Saving this draft.":""),la=!!((E||rs)&&!Vs),Oe=f.useMemo(()=>lt([...Ha,...Da,...F.map(de),de(r)]),[r,F]),oa=ot(r,Oe),Me=f.useCallback(async({silent:i=!1}={})=>
7{if(!a||k)return!0;fe("refreshing"),xe("");try{const d=await l();return fe(d?"ready":"missing"),!d&&!i&&xe("Template access is still unavailable. Try logging out and back in if access was just granted."),d}catch(d){return fe("error"),i||xe(d instanceof Error?d.message:"Unable to refresh the Firebase session."),!1}},[k,a,l]),Ke=f.useCallback(async()=>{if(!(!k||!C)){ge("loading"),ns("");try{const[i,d]=await Promise.all([h?ks():Fs(S),h?Cs():As()]);as(i),ts(d),ge("ready")}catch(i){if(Q(i)&&a&&!ue.current){ue.current=!0;try{if(await l()||k){const[u,p]=await Promise.all([h?ks():Fs(S),h?Cs():As()]);as(u),ts(p),ge("ready");return}}catch{}}ge("error"),ns(Q(i)?"Firebase still denied template access after refreshing your session. Sign out and back in, then reopen Template Studio.":i instanceof Error?i.message:"Unable to load admin templates.")}}},[k,S,h,a,l]);f.useEffect(()=>{if(!ye){De.current="",ue.current=!1;return}De.current!==ye&&(De.current=ye,ue.current=!1)},[ye]),f.useEffect(()=>{!e||!a||!k||Ke()},[e,a,k,Ke]),f.useEffect(()=>{!e||!a||k||ss.current||(ss.current=!0,Me({silent:!0}))},[e,a,k,Me]),f.useEffect(()=>{k&&(fe("idle"),xe(""))},[k]);const Te=f.useCallback(i=>{Ue(i.docId||ce(i.slug||"")),A(rt(i)),M(""),ie(!1),ze("idle"),H("idle"),q("idle"),ne(""),_({cover:{status:"idle",progress:0,message:""},download:{status:"idle",progress:0,message:""},templateFile:{status:"idle",progress:0,message:""}}),R(oe)},[]),J=f.useCallback(()=>{h&&(Ue(""),A({...U,slug:`new-template-${F.length+1}`,title:"New Template",createdAt:new Date().toISOString().slice(0,10),sortOrder:(F.length+1)*10}),M(""),ie(!1),ze("idle"),H("idle"),q("idle"),ne(""),_({cover:{status:"idle",progress:0,message:""},download:{status:"idle",progress:0,message:""},templateFile:{status:"idle",progress:0,message:""}}),R(oe))},[h,F.length]),Se=`${m}:${B}`;f.useEffect(()=>{if(!(!e||!a||!k)&&_e.current!==Se){if(m==="edit"&&B){const i=pe.find(d=>yt(d,B))||j;if(!i?.slug||!Ge(i,t,n))return;_e.current=Se,Te(i);return}h&&(_e.current=Se,J())}},[e,k,t,m,Se,j,B,h,a,Te,J,pe,n]);const y=i=>d=>{const u=st(d);A(p=>i==="title"&&(!p.slug||p.slug.startsWith("new-template"))?{...p,title:u,headline:p.headline||u,slug:L(u)||p.slug}:i==="templateType"?{...p,templateType:u,category:p.category||u}:i==="proLink"?{...p,proLink:u,purchaseUrl:p.purchaseUrl||u}:i==="purchaseUrl"?{...p,purchaseUrl:u,proLink:u}:{...p,[i]:u})},ca=i=>{const d=Oe.find(u=>te(u)===i);d&&A(u=>({...u,authorName:$(d)||u.authorName,username:Fe(d)||u.username}))},Be=async(i,d,{throwOnError:u=!1,slugOverride:p=""}={})=>{if(!d)return;const w=p||P||L(r.title)||"template";_(b=>({...b,[i]:{status:"uploading",progress:0,message:d.name}}));try{const b=await Ds({file:d,slug:w,kind:i,onProgress:v=>_(K=>({...K,[i]:{...K[i],status:"uploading",progress:v,message:d.name}}))});return A(v=>i==="cover"?{...v,coverUrl:b.url}:{...v,downloadUrl:b.url||"",downloadPath:b.path,downloadFileName:b.name,downloadFileSize:b.size}),_(v=>({...v,[i]:{status:"ready",progress:100,message:`${b.name} uploaded.`}})),b}catch(b){const v=b instanceof Error?b.message:"Upload failed.";if(_(K=>({...K,[i]:{status:"error",progress:0,message:v}})),u)throw new Error(v)}},da=()=>{A(i=>{const d=Array.isArray(i.templateFiles)?i.templateFiles:[];return{...i,templateFiles:[...d,Ce({type:i.language||"html",title:"",url:""},d.length)]}})},ma=(i,d,u)=>{A(p=>({...p,templateFiles:(Array.isArray(p.templateFiles)?p.templateFiles:[]).map((w,b)=>b===i?{...w,[d]:u}:w)}))},ua=i=>{A(d=>({...d,templateFiles:(Array.isArray(d.templateFiles)?d.templateFiles:[]).filter((u,p)=>p!==i)}))},pa=async i=>{if(!i)return;const d=P||L(r.title)||"template";_(u=>({...u,templateFile:{status:"uploading",progress:0,message:i.name}}));try{const u=await Ds({file:i,slug:d,kind:"download",onProgress:p=>_(w=>({...w,templateFile:{...w.templateFile,status:"uploading",progress:p,message:i.name}}))});A(p=>{const w=Array.isArray(p.templateFiles)?p.templateFiles:[];return{...p,templateFiles:[...w,Ce({type:Ks({name:u.name,contentType:u.contentType},p.language||"other"),title:u.name,fileName:u.name,fileSize:u.size,contentType:u.contentType,path:u.path,url:u.url},w.length)]}}),_(p=>({...p,templateFile:{status:"ready",progress:100,message:`${u.name} uploaded.`}}))}catch(u){_(p=>({...p,templateFile:{status:"error",progress:0,message:u instanceof Error?u.message:"Template file upload failed."}}))}},ha=async i=>{if(i){if(M(""),ie(!1),!Os(i)){R({...oe,status:"error",fileName:i.name||"",fileSize:i.size||0,fileType:i.type||"",message:"Attach a Markdown, HTML, JSON, Swift, or ZIP file."});return}R({...oe,status:"reading",progress:18,fileName:i.name,fileSize:i.size,fileType:i.type||"",message:"Reading source text..."});try{const d=await Wa(i),u=Pe.map(v=>({key:v.key||v.id||v.docId||"",title:v.title||v.name||v.key||""}));R(v=>({...v,status:"generating",progress:42,textFileCount:d.files.length,totalCharacters:d.totalCharacters,message:"Generating title, slug, descriptions, and metadata..."}));const p=await ja({source:d,file:{name:i.name,size:i.size,type:i.type||"application/octet-stream"},collections:u}),w=p?.payload?.template||p?.payload||{},b=vs({current:r,generated:w,templates:F,selectedId:D,fallbackFileName:i.name});A(v=>vs({current:v,generated:w,templates:F,selectedId:D,fallbackFileName:i.name})),R(v=>({...v,status:"uploading",progress:76,message:"Uploading the source file to the member download area..."}
7)),await Be("download",i,{throwOnError:!0,slugOverride:b.slug}),R({status:"ready",progress:100,fileName:i.name,fileSize:i.size,fileType:i.type||"",textFileCount:d.files.length,totalCharacters:d.totalCharacters,message:"AI generated the template information. Review the draft below."})}catch(d){R(u=>({...u,status:"error",progress:100,message:d instanceof Error?d.message:"Unable to generate template metadata."}))}}},le=async(i=!1,d=!0)=>{if(!re||i&&!G)return;const u=i?"publish":"draft";Le("saving"),ze(u),H("writing"),M(i?"Publishing template...":"Saving draft..."),ie(!1);const p=P,w=ce(p),b=G&&i?!0:!!r.published,v=r.coverUrl.trim(),K=r.downloadUrl.trim(),He=r.downloadPath.trim()||Qe(K),ps=Bs(He)?"":K,hs=(r.purchaseUrl||r.proLink).trim(),gs=(r.proLink||r.purchaseUrl).trim(),fs=String(r.priceUsd??"").trim(),X=fs===""?null:Number(fs),xs=Ie,ke=Ns(r.templateFiles),fa=ba(),js={id:w,slug:p,templateId:r.templateId.trim()||String(F.length+1).padStart(2,"0"),title:r.title.trim(),headline:(r.headline||r.title).trim(),description:r.description.trim()||r.shortDescription.trim()||r.summary.trim(),summary:r.summary.trim()||r.shortDescription.trim()||r.description.trim(),shortDescription:r.shortDescription.trim(),longDescription:r.longDescription.trim(),templateType:r.templateType,category:r.category.trim()||r.templateType,collectionKey:ae(r.collectionKey),collectionTitle:Xs?.title||r.category.trim()||r.templateType,tags:We(r.tags),accessLevel:r.accessLevel||"free",contentAccessLevel:r.contentAccessLevel||"pro",sortOrder:Number(r.sortOrder)||0,pageCount:Number(r.pageCount)||1,pages:Number(r.pageCount)||1,views:Number(r.views)||0,forks:Number(r.forks)||0,published:b,featured:!!r.featured,premium:!!r.premium,shareSourceCode:!!r.shareSourceCode,share_source_code:!!r.shareSourceCode,coverUrl:v,imageUrl:v,image_url:v,downloadUrl:ps,download_url:ps,downloadPath:He,download_path:He,downloadFileName:r.downloadFileName.trim(),download_file_name:r.downloadFileName.trim(),downloadFileSize:Number(r.downloadFileSize)||0,download_file_size:Number(r.downloadFileSize)||0,purchaseUrl:hs,purchase_url:hs,proLink:gs,pro_link:gs,priceUsd:Number.isFinite(X)?X:null,price_usd:Number.isFinite(X)?X:null,price:Number.isFinite(X)?X:null,lockedFiles:xs,memberFiles:xs,templateFiles:ke,template_files:ke,memberFileDetails:ke,member_file_details:ke,authorName:r.authorName.trim(),username:r.username.trim(),createdAt:r.createdAt||null,publishedAt:b&&r.createdAt||null,seoTitle:r.seoTitle.trim(),seoDescription:r.seoDescription.trim(),metadata:{title:r.seoTitle.trim(),description:r.seoDescription.trim(),image:v},language:r.language||"html",siteKey:"promptui",contentKind:"template",updatedByUid:t?.uid||"",updatedByEmail:_a(t?.email||n),updatedAt:fa};try{await ya(qe(C,"templates",w),js,{merge:!0}),H("refreshing"),M(b?"Template saved. Refreshing library...":"Draft saved. Refreshing library...");try{c({docId:w,template:js,published:b})}catch(I){console.warn("Unable to refresh template content after save.",I)}A(I=>({...I,slug:p,published:b})),Ue(w),await Ke(),Le("ready"),H("complete"),M(i&&b?"Template published and library refreshed.":b?"Template saved.":"Draft saved.")}catch(I){if(d&&Q(I)&&a)try{if(await l()){await le(i,!1);return}}catch{}Le("error"),H("error"),M(Q(I)?"Firebase still denied template edits after refreshing your session. Ask an admin to confirm owner access, then try again.":I instanceof Error?I.message:"Unable to save template.")}},us=async({confirmed:i=!1,retryPermission:d=!0,bypassBusy:u=!1}={})=>{if(!ms||ve&&!u)return;const p=r.title.trim()||r.slug||"this template";if(!(!i&&!(typeof window<"u"&&window.confirm(`Delete "${p}"? This removes the template and its gallery card. This cannot be undone.`)))){q("deleting"),ne(`Deleting ${p}...`);try{const w=wa(C);w.delete(qe(C,"templates",D)),w.delete(qe(C,"templateCards",D)),await w.commit();try{c({docId:D,template:r,deleted:!0})}catch(b){console.warn("Unable to refresh template content after deletion.",b)}q("ready"),ne(`${p} was deleted.`),typeof window<"u"?window.location.assign("/templates"):J()}catch(w){if(d&&Q(w)&&a)try{if(await l()){q("idle"),await us({confirmed:!0,retryPermission:!1,bypassBusy:!0});return}}catch{}
7q("error"),ne(Q(w)?"Firebase denied template deletion after refreshing your session. Ask an admin to confirm access, then try again.":w instanceof Error?w.message:"Unable to delete template.")}}},ga=i=>{const d=i.target.value;if(d==="__new__"){J();return}const u=pe.find(p=>(p.docId||p.id)===d);u&&Te(u)};return s.jsx("div",{className:"page templates-library-page admin-course-page admin-template-page",children:s.jsxs("div",{className:"app-shell",children:[s.jsx("div",{className:"background-grid"}),g?s.jsx(g,{pathname:"/admin/templates",isLoggedIn:a,userEmail:n,subNavKey:"adminTemplates"}):null,s.jsx("main",{id:"top",children:!e||!a||!k?s.jsx(ft,{authReady:e,isLoggedIn:a,isAdmin:h,canAccessStudio:k,isRefreshingClaims:Js,claimRefreshError:Ws,onRefreshClaims:Me,onRequestLogin:o}):s.jsxs("section",{className:`admin-course-studio${x?" is-modal":""}`,children:[la&&s.jsx(xt,{title:na,message:ra,tone:ia,progress:ta,isSaving:E,onDismiss:()=>ie(!0)}),x&&s.jsxs("header",{className:"admin-course-toolbar",children:[s.jsxs("div",{className:"admin-course-toolbar-start",children:[s.jsxs("label",{className:"admin-course-select",children:[s.jsx("span",{className:"admin-course-select-label",children:"Template"}),s.jsxs("select",{value:D||"__new__",onChange:ga,children:[h&&s.jsx("option",{value:"__new__",children:"New Template"}),!h&&s.jsx("option",{value:"__new__",children:"Select Template"}),F.map(i=>s.jsxs("option",{value:i.docId||i.id,children:[i.title||i.slug," (",Ps(i),")"]},i.docId||i.id||i.slug))]})]}),he==="loading"&&s.jsx("span",{className:"admin-course-toolbar-note",children:"Loading templates..."}),he==="error"&&s.jsx("span",{className:"admin-course-toolbar-error",children:is}),os&&s.jsx("span",{className:ls==="error"?"admin-course-toolbar-error":"admin-course-toolbar-note",role:"status",children:os})]}),s.jsxs("div",{className:"admin-course-actions",children:[h&&s.jsxs("button",{type:"button",className:"btn-secondary",onClick:J,children:[s.jsx(T,{icon:"solar:add-circle-linear",width:16,height:16,"aria-hidden":"true"}),"New Template"]}),s.jsxs("button",{type:"button",className:"btn-secondary",onClick:()=>le(!1),disabled:!re||ve,children:[s.jsx(T,{icon:W?"solar:refresh-circle-linear":"solar:diskette-linear",width:16,height:16,className:W?"admin-action-icon is-spinning":"admin-action-icon","aria-hidden":"true"}),W?"Saving...":"Save Draft"]}),G&&s.jsxs("button",{type:"button",className:"btn-primary",onClick:()=>le(!0),disabled:!re||ve,children:[s.jsx(T,{icon:Z?"solar:refresh-circle-linear":"solar:upload-square-linear",width:16,height:16,className:Z?"admin-action-icon is-spinning":"admin-action-icon","aria-hidden":"true"}),Z?"Publishing...":"Publish"]}),ms&&s.jsxs("button",{type:"button",className:"btn-secondary admin-template-delete-button",onClick:()=>us(),disabled:ve,children:[s.jsx(T,{icon:be?"solar:refresh-circle-linear":"lucide:trash-2",width:16,height:16,className:be?"admin-action-icon is-spinning":"admin-action-icon","aria-hidden":"true"}),be?"Deleting...":"Delete"]})]})]}),!x&&s.jsxs("header",{className:"hero-section curriculum-hero contentful-course-hero admin-course-hero",children:[s.jsxs("div",{className:"hero-copy",children:[s.jsxs("div",{className:"eyebrow admin-course-eyebrow",children:[s.jsx("span",{className:"dot"}),"Admin"]}),s.jsx("h1",{className:"hero-title admin-course-title",children:s.jsx("span",{className:"title-muted",children:"Template Studio"})}),s.jsx("p",{className:"hero-subtitle",children:"Add landing pages, React projects, HTML packs, prompts, and member downloads to the public template library."}),s.jsxs("div",{className:"contentful-course-stats contentful-course-hero-stats admin-course-hero-stats",children:[s.jsxs("span",{children:[F.length," templates"]}),s.jsxs("span",{children:[Qs," published"]}),s.jsxs("span",{children:[Ys," premium"]})]}),s.jsxs("div",{className:"admin-course-actions hero-actions",children:[h&&s.jsxs("button",{type:"button",className:"btn-secondary",onClick:J,children:[s.jsx(T,{icon:"solar:add-circle-linear",width:16,height:16,"aria-hidden":"true"}),"New Template"]}),s.jsxs("button",{type:"button",className:"btn-secondary",onClick:()=>le(!1),disabled:!re||z==="saving",children:[s.jsx(T,{icon:W?"solar:refresh-circle-linear":"solar:diskette-linear",width:16,height:16,className:W?"admin-action-icon
7is-spinning":"admin-action-icon","aria-hidden":"true"}),W?"Saving...":"Save Draft"]}),G&&s.jsxs("button",{type:"button",className:"btn-primary",onClick:()=>le(!0),disabled:!re||z==="saving",children:[s.jsx(T,{icon:Z?"solar:refresh-circle-linear":"solar:upload-square-linear",width:16,height:16,className:Z?"admin-action-icon is-spinning":"admin-action-icon","aria-hidden":"true"}),Z?"Publishing...":"Publish"]})]})]}),s.jsxs("aside",{className:"contentful-course-hero-media admin-course-hero-media","aria-label":"Template Studio summary",children:[s.jsx("span",{className:"contentful-course-logo","aria-hidden":"true",children:s.jsx(T,{icon:"solar:window-frame-linear",width:18,height:18})}),s.jsxs("div",{className:"admin-course-media-panel",children:[s.jsx("span",{children:"Editing"}),s.jsx("strong",{children:r.title||"New Template"}),s.jsx("em",{children:P||"template-slug"})]}),s.jsxs("div",{className:"admin-course-media-list",children:[s.jsxs("div",{children:[s.jsx("span",{children:"Type"}),s.jsx("strong",{children:r.templateType})]}),s.jsxs("div",{children:[s.jsx("span",{children:"State"}),s.jsx("strong",{children:r.published?"Published":"Draft"})]}),s.jsxs("div",{children:[s.jsx("span",{children:"Access"}),s.jsx("strong",{children:r.contentAccessLevel||"pro"})]})]})]})]}),s.jsxs("div",{className:x?"admin-course-main admin-template-modal-main":"admin-course-grid",children:[!x&&s.jsxs("aside",{id:"library",className:"spotlight-card admin-course-sidebar",children:[s.jsxs("div",{className:"admin-course-panel-head",children:[s.jsx("h2",{children:"Templates"}),s.jsx("span",{children:F.length})]}),he==="loading"&&s.jsx("p",{className:"admin-course-note",children:"Loading templates..."}),he==="error"&&s.jsx("p",{className:"admin-course-error",children:is}),s.jsx("div",{className:"admin-course-list",children:F.map(i=>s.jsxs("button",{type:"button",className:`admin-course-list-item ${D===(i.docId||i.id)?"is-active":""}`,onClick:()=>Te(i),children:[s.jsxs("span",{children:[s.jsx("strong",{children:i.title||i.slug}),s.jsx("em",{children:i.slug})]}),s.jsx("small",{className:i.published?"is-live":"",children:Ps(i)})]},i.docId||i.id||i.slug))})]}),s.jsxs("div",{className:"admin-course-editor",children:[!x&&s.jsxs("nav",{className:"admin-course-workflow-nav","aria-label":"Template Studio workflow",children:[V?s.jsxs("a",{href:"#source",children:[s.jsx("span",{children:"01"}),"Source"]}):null,s.jsxs("a",{href:"#metadata",children:[s.jsx("span",{children:V?"02":"01"}),"Info"]}),s.jsxs("a",{href:"#content",children:[s.jsx("span",{children:V?"03":"02"}),"Detail"]}),s.jsxs("a",{href:"#files",children:[s.jsx("span",{children:V?"04":"03"}),"Files"]})]}),V?s.jsx(gt,{sourceState:cs,uploadState:je.download,onUpload:ha,disabled:!k||!Re}):null,ds?s.jsxs(s.Fragment,{children:[s.jsxs("article",{id:"metadata",className:"spotlight-card admin-course-card",children:[s.jsxs("div",{className:"admin-course-panel-head",children:[s.jsx("h2",{children:"Template"}),s.jsxs("div",{className:"admin-course-panel-head-actions",children:[s.jsx("span",{children:r.published?"Published":"Draft"}),s.jsx(Ve,{label:G?"Published template":"Published template (admin only)",checked:!!r.published,onChange:y("published"),disabled:!G})]})]}),s.jsxs("div",{className:"admin-course-form-grid admin-course-primary-grid admin-template-basics-grid",children:[s.jsx(N,{label:"Title",hint:"required",children:s.jsx("input",{value:r.title,onChange:y("title")})}),s.jsx(N,{label:"Author",children:s.jsx(mt,{options:Oe,selectedId:oa,onChange:ca})}),s.jsx(N,{label:"Type",children:s.jsx("select",{value:r.templateType,onChange:y("templateType"),children:Ls.map(i=>s.jsx("option",{value:i,children:i},`template-type-${i}`))})}),s.jsx(N,{label:"Collection",children:s.jsxs("select",{value:r.collectionKey,onChange:y("collectionKey"),children:[s.jsx("option",{value:"",children:"No collection"}),Pe.map(i=>{const d=i.key||i.id||i.docId;return s.jsx("option",{value:d,children:i.title||d},`template-collection-${d}`)})]})}),s.jsx(N,{label:"Required plan",children:s.jsx("select",{value:r.contentAccessLevel,onChange:y("contentAccessLevel"),children:ws.map(i=>s.jsx("option",{value:i,children:i},`template-access-${i}`))})}),s.jsx(N,{label:"Short Description",className:"admin-template-summary-field",children:s.jsx("textarea",{rows:3,value:r.shortDe
7scription,onChange:y("shortDescription")})}),s.jsx(ut,{coverUrl:r.coverUrl,uploadState:je.cover,onUpload:i=>Be("cover",i)})]}),s.jsx(dt,{title:"Advanced template metadata",description:"SEO, ordering, metrics, and compatibility fields.",children:s.jsxs("div",{className:"admin-course-form-grid admin-course-advanced-grid",children:[s.jsx(N,{label:"Slug",hint:"auto from title",children:s.jsx("input",{value:r.slug,onChange:y("slug")})}),s.jsx(N,{label:"Template ID",children:s.jsx("input",{value:r.templateId,onChange:y("templateId")})}),s.jsx(N,{label:"Category",children:s.jsx("input",{value:r.category,onChange:y("category")})}),s.jsx(N,{label:"Language",children:s.jsx("select",{value:r.language,onChange:y("language"),children:$s.map(i=>s.jsx("option",{value:i,children:i},`template-language-${i}`))})}),s.jsx(N,{label:"Tags",hint:"comma separated",children:s.jsx("input",{value:r.tags,onChange:y("tags")})}),s.jsx(N,{label:"Catalog access",children:s.jsx("select",{value:r.accessLevel,onChange:y("accessLevel"),children:ws.map(i=>s.jsx("option",{value:i,children:i},`template-catalog-access-${i}`))})}),s.jsx(N,{label:"Sort Order",children:s.jsx("input",{type:"number",value:r.sortOrder,onChange:y("sortOrder")})}),s.jsx(N,{label:"Page Count",children:s.jsx("input",{type:"number",value:r.pageCount,onChange:y("pageCount")})}),s.jsx(N,{label:"Download filename",children:s.jsx("input",{value:r.downloadFileName,onChange:y("downloadFileName")}
7)}),s.jsx(N,{label:"Views",children:s.jsx("input",{type:"number",value:r.views,onChange:y("views")})}),s.jsx(N,{label:"Remixes",children:s.jsx("input",{type:"number",value:r.forks,onChange:y("forks")})}),s.jsx(N,{label:"Username",children:s.jsx("input",{value:r.username,onChange:y("username")})}),s.jsx(N,{label:"Created",children:s.jsx("input",{type:"date",value:r.createdAt,onChange:y("createdAt")})}),s.jsx(N,{label:"SEO Title",children:s.jsx("input",{value:r.seoTitle,onChange:y("seoTitle")})}),s.jsx(N,{label:"SEO Description",children:s.jsx("input",{value:r.seoDescription,onChange:y("seoDescription")})}),s.jsx(N,{label:"Member files",hint:"comma or line separated",className:"is-full",children:s.jsx("textarea",{rows:4,value:r.lockedFiles,onChange:y("lockedFiles")})})]})})]}),s.jsxs("article",{id:"content",className:"spotlight-card admin-course-card",children:[s.jsx("div",{className:"admin-course-panel-head",children:s.jsx("h2",{children:"Template Detail"})}),s.jsxs("div",{className:"admin-course-form-grid admin-course-primary-grid",children:[s.jsx(N,{label:"Headline",hint:"detail hero",className:"is-full",children:s.jsx("input",{value:r.headline,onChange:y("headline")})}),s.jsx(N,{label:"Summary",hint:"hero subtitle",className:"is-full",children:s.jsx("textarea",{rows:3,value:r.summary,onChange:y("summary")})})]}),s.jsxs("div",{className:"admin-markdown-grid",children:[s.jsx(N,{label:"Long Description",hint:"markdown supported",children:s.jsx("textarea",{rows:16,value:r.longDescription,onChange:y("longDescription")})}),s.jsxs("div",{className:"admin-markdown-preview",children:[s.jsx("span",{children:"Preview"}),s.jsx($a,{remarkPlugins:[za],children:r.longDescription||"Add template notes."})]})]})]}),s.jsxs("article",{id:"files",className:"spotlight-card admin-course-card",children:[s.jsxs("div",{className:"admin-course-panel-head",children:[s.jsx("h2",{children:"Files and Links"}),s.jsxs("div",{className:"admin-course-panel-head-actions",children:[s.jsx("span",{children:"Member pack"}),s.jsx(Ve,{label:"Premium",checked:!!r.premium,onChange:y("premium")}),s.jsx(Ve,{label:"Featured",checked:!!r.featured,onChange:y("featured")})]})]}),s.jsxs("div",{className:"admin-course-form-grid admin-course-primary-grid",children:[s.jsx(pt,{downloadUrl:r.downloadUrl,downloadPath:r.downloadPath,fileName:r.downloadFileName,fileSize:r.downloadFileSize,uploadState:je.download,inputId:`admin-template-download-${P||"new"}`,onUpload:i=>Be("download",i)}),s.jsx(ht,{files:Array.isArray(r.templateFiles)?r.templateFiles:[],uploadState:je.templateFile,inputId:`admin-template-file-${P||"new"}`,onAdd:da,onChange:ma,onRemove:ua,onUpload:pa,disabled:!Re})]})]}),s.jsxs("article",{id:"paid-template",className:"spotlight-card admin-course-card",children:[s.jsxs("div",{className:"admin-course-panel-head",children:[s.jsx("h2",{children:"Paid template"}),s.jsx("span",{children:"Commerce"})]}),s.jsxs("div",{className:"admin-course-form-grid admin-template-paid-grid",children:[s.jsx(N,{label:"Price in USD",children:s.jsx("input",{type:"number",min:"0",step:"0.01",value:r.priceUsd,onChange:y("priceUsd")})}),s.jsx(N,{label:"Paid URL",hint:"purchase or private URL",children:s.jsx("input",{value:r.purchaseUrl,onChange:y("purchaseUrl")})})]})]})]}):s.jsxs("article",{className:"spotlight-card admin-course-card admin-template-locked-card",children:[s.jsxs("div",{className:"admin-course-panel-head",children:[s.jsx("h2",{children:"Review Info"}),s.jsx("span",{children:"Waiting for source"})]}),s.jsx("p",{className:"admin-course-card-lede",children:"Attach a Markdown, HTML, or ZIP file first. The template fields will unlock after AI generates the title, slug, descriptions, tags, SEO fields, and member file notes."})]})]}),!x&&s.jsxs("aside",{id:"publish",className:"spotlight-card admin-course-status-panel",children:[s.jsxs("div",{className:"admin-course-panel-head",children:[s.jsx("h2",{children:"Publish Check"}),s.jsx("span",{children:r.published?"Live":"Draft"})]}),s.jsxs("div",{className:"admin-course-signal-grid",children:[s.jsxs("div",{children:[s.jsx("strong",{children:F.length}),s.jsx("span",{children:"Templates"})]}),s.jsxs("div",{children:[s.jsx("strong",{children:Ie.length}),s.jsx("span",{children:"Files"})]}),s.jsxs("div",{children:[s.jsx("strong",{children:r.templateType.split(" ")[0]}),s.jsx("span",{children:"Type"})]}),s.jsxs("div",{children:[s.jsx("strong",{children:r.contentAccessLevel}),s.jsx("span",{children:"Access"})]})]}),s.jsxs("ul",{className:"admin-course-checklist",children:[s.jsx("li",{className:r.title.trim()?"is-done":"",children:"Title is set"}),s.jsx("li",{className:P?"is-done":"",children:"Slug is valid"}),s.jsx("li",{className:r.coverUrl.trim()?"is-done":"",children:"Cover image is ready"}
7),s.jsx("li",{className:r.shortDescription.trim()||r.summary.trim()?"is-done":"",children:"Description is written"}),s.jsx("li",{className:r.downloadUrl.trim()||r.downloadPath.trim()||r.proLink.trim()||Ie.length||ea.length?"is-done":"",children:"Member files are defined"})]}),s.jsxs("div",{className:"admin-course-preview-link",children:[s.jsx("span",{children:"Preview URL"}),s.jsx("a",{href:we,children:we})]}),s.jsxs("div",{className:"admin-course-current-user",children:[s.jsx(T,{icon:"solar:user-id-linear",width:17,height:17,"aria-hidden":"true"}),s.jsx("span",{children:n||t?.email||"Admin user"})]})]})]}),x&&s.jsxs("footer",{className:"admin-course-footer",children:[s.jsx("div",{className:"admin-course-footer-status"}),s.jsx("a",{className:"admin-course-footer-preview",href:we,target:"_blank",rel:"noreferrer",children:we}),s.jsxs("div",{className:"admin-course-footer-user",children:[s.jsx(T,{icon:"solar:user-check-linear",width:16,height:16,"aria-hidden":"true"}),s.jsx("span",{children:n||t?.email||"Admin user"})]})]})]})})]})})}export{Ct 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.