@kyro-cms/admin 0.10.14 → 0.10.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var ka=require('react'),zustand=require('zustand'),middleware=require('zustand/middleware'),lucideReact=require('lucide-react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom'),react=require('@tiptap/react'),hp=require('@tiptap/starter-kit'),wp=require('@tiptap/extension-link'),Np=require('@tiptap/extension-image'),Cp=require('@tiptap/extension-text-align'),Sp=require('@tiptap/extension-underline'),Tp=require('@tiptap/extension-highlight'),Ap=require('@tiptap/extension-task-list'),Rp=require('@tiptap/extension-task-item'),extensionTextStyle=require('@tiptap/extension-text-style'),Pp=require('@tiptap/extension-color'),pp=require('react-image-crop');require('react-image-crop/dist/ReactCrop.css');var codemirrorThemeGithub=require('@uiw/codemirror-theme-github'),codemirrorThemeAura=require('@uiw/codemirror-theme-aura'),unstorage=require('unstorage'),pm=require('unstorage/drivers/indexedb'),templates=require('@kyro-cms/core/templates'),Ro=require('fs'),vanilla=require('zustand/vanilla'),core=require('@dnd-kit/core'),sortable=require('@dnd-kit/sortable'),utilities=require('@dnd-kit/utilities'),gu=require('@uiw/react-codemirror'),langJson=require('@codemirror/lang-json');require('@kyro-cms/core');var fr=require('path'),url=require('url'),esbuild=require('esbuild'),dotenv=require('dotenv'),worker_threads=require('worker_threads');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ka__default=/*#__PURE__*/_interopDefault(ka);var hp__default=/*#__PURE__*/_interopDefault(hp);var wp__default=/*#__PURE__*/_interopDefault(wp);var Np__default=/*#__PURE__*/_interopDefault(Np);var Cp__default=/*#__PURE__*/_interopDefault(Cp);var Sp__default=/*#__PURE__*/_interopDefault(Sp);var Tp__default=/*#__PURE__*/_interopDefault(Tp);var Ap__default=/*#__PURE__*/_interopDefault(Ap);var Rp__default=/*#__PURE__*/_interopDefault(Rp);var Pp__default=/*#__PURE__*/_interopDefault(Pp);var pp__default=/*#__PURE__*/_interopDefault(pp);var pm__default=/*#__PURE__*/_interopDefault(pm);var Ro__default=/*#__PURE__*/_interopDefault(Ro);var gu__default=/*#__PURE__*/_interopDefault(gu);var fr__default=/*#__PURE__*/_interopDefault(fr);var Ye=typeof __KYRO_ADMIN_PATH__<"u"?__KYRO_ADMIN_PATH__:"/admin",lo=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function qe(e){if(e.startsWith("http")||e.startsWith(lo))return e;if(e.startsWith("/api/"))return lo+e.slice(4);let t=e.startsWith("/")?"":"/";return `${lo}${t}${e}`}function ts(e){return e.startsWith("http")||e.startsWith(Ye)?e:e.startsWith("/admin/")?Ye+e.slice(6):e.startsWith("/")?Ye+e:e}function ua(e){return !e||typeof e!="string"?"":e.startsWith("http")||e.startsWith("blob:")||e.startsWith("data:")||e.startsWith("/")?e:`/${e}`}var jc={admin:Ye,api:lo,resolveApi:qe,resolveAdmin:ts,resolveMedia:ua};var Mr=zustand.create(e=>({user:null,permissions:null,isAuthenticated:false,isLoading:true,error:null,setUser:(t,r=null)=>e({user:t,permissions:r,isAuthenticated:!!t,isLoading:false,error:null}),setLoading:t=>e({isLoading:t}),setError:t=>e({error:t,isLoading:false,isAuthenticated:false,user:null,permissions:null}),logout:()=>e({user:null,permissions:null,isAuthenticated:false,isLoading:false,error:null})}));var Vt=zustand.create(e=>({toasts:[],addToast:(t,r)=>{let o=Math.random().toString(36).substring(7);e(a=>({toasts:[...a.toasts,{id:o,type:t,message:r}]}));},removeToast:t=>e(r=>({toasts:r.toasts.filter(o=>o.id!==t)})),clearToasts:()=>e({toasts:[]})})),$={success:e=>Vt.getState().addToast("success",e),error:e=>Vt.getState().addToast("error",e),warning:e=>Vt.getState().addToast("warning",e),info:e=>Vt.getState().addToast("info",e)};zustand.create()(middleware.persist(e=>({mode:"light",setMode:t=>e({mode:t}),toggleMode:()=>e(t=>({mode:t.mode==="light"?"dark":"light"}))}),{name:"kyro-theme"}));var at=zustand.create(e=>({sidebarOpen:true,toggleSidebar:()=>e(t=>({sidebarOpen:!t.sidebarOpen})),setSidebarOpen:t=>e({sidebarOpen:t}),modal:{open:false,config:null},confirm:t=>e({modal:{open:true,config:{...t,variant:t.variant||"default"}}}),alert:t=>e({modal:{open:true,config:{...t,variant:t.variant||"default",confirmLabel:t.confirmLabel||"OK",onConfirm:()=>e(r=>({modal:{...r.modal,open:false}}))}}}),closeModal:()=>e(t=>({modal:{...t.modal,open:false},activeModal:null})),activeModal:null,openModal:t=>e({activeModal:t})}));zustand.create(e=>({editor:null,setEditor:t=>e({editor:t}),blockDrawerOpen:false,openBlockDrawer:t=>e({blockDrawerOpen:true,pendingInsert:{pos:null,column:t?.targetColumn??null}}),closeBlockDrawer:()=>e({blockDrawerOpen:false,pendingInsert:{pos:null,column:null}}),toggleBlockDrawer:()=>e(t=>({blockDrawerOpen:!t.blockDrawerOpen})),selectedBlock:null,setSelectedBlock:t=>e({selectedBlock:t}),pendingInsert:{pos:null,column:null},setPendingInsert:(t,r)=>e({pendingInsert:{pos:t,column:r??null}}),clearPendingInsert:()=>e({pendingInsert:{pos:null,column:null}})}));zustand.create((e,t)=>({cache:{},setCache:(r,o)=>e(a=>({cache:{...a.cache,[r]:{data:o,loading:false,error:null,lastFetch:Date.now()}}})),setLoading:(r,o)=>e(a=>({cache:{...a.cache,[r]:{...a.cache[r],loading:o,error:null}}})),setError:(r,o)=>e(a=>({cache:{...a.cache,[r]:{data:null,loading:false,error:o,lastFetch:null}}})),getCache:r=>t().cache[r]||null,invalidateCache:r=>e(o=>{if(r){let{[r]:a,...n}=o.cache;return {cache:n}}return {cache:{}}})}));var _c="/api/auth/refresh";async function ci(){try{return (await fetch(qe(_c),{method:"POST",credentials:"include"})).ok}catch{return false}}async function ct(e,t={}){let r={};t.body instanceof FormData||(r["Content-Type"]="application/json"),Object.assign(r,t.headers);let o=await fetch(qe(e),{...t,credentials:"include",headers:r});if(o.status===401){if(await ci()){let n={};return t.body instanceof FormData||(n["Content-Type"]="application/json"),Object.assign(n,t.headers),await fetch(qe(e),{...t,credentials:"include",headers:n})}window.location.href="/admin/login";}return o}async function Be(e,t){let{autoToast:r=true,...o}=t||{},a=await ct(e,o);if(!a.ok){let n=`GET Failed: ${a.status}`;throw r&&$.error(n),new Error(n)}return a.json()}async function et(e,t,r){let{autoToast:o=true,...a}=r||{},n=await ct(e,{method:"POST",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`POST Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function Xt(e,t,r){let{autoToast:o=true,...a}=r||{},n=await ct(e,{method:"PATCH",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`Update Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function bt(e,t){let{autoToast:r=true,...o}=t||{},a=await ct(e,{method:"DELETE",...o});if(!a.ok){let s=`Delete Failed: ${a.status}`;try{let i=await a.json();i.error&&(s=i.error);}catch{}throw r&&$.error(s),new Error(s)}let n=await a.text();return n?JSON.parse(n):{}}function $r(e){let t=e.includes("?")?"&":"?";return `${e}${t}t=${Date.now()}`}function Ja(e,t,r=50){return !e||t.length===0?`limit=${r}`:`${t.map(a=>`where[${a}][contains]=${encodeURIComponent(e)}`).join("&")}&limit=${r}`}async function ya(e,t,r){if(!r){let o=await ct(e,{method:"POST",body:t});if(!o.ok)throw new Error(`Upload Error: ${o.status}`);return o.json()}return new Promise((o,a)=>{let n=new XMLHttpRequest;n.open("POST",qe(e)),n.withCredentials=true,n.upload.addEventListener("progress",s=>{s.lengthComputable&&r(Math.round(s.loaded/s.total*100));}),n.addEventListener("load",()=>{if(n.status>=200&&n.status<300)try{o(JSON.parse(n.responseText));}catch{a(new Error("Invalid JSON response"));}else n.status===401?ci().then(s=>{if(!s){a(new Error(`Upload Error: ${n.status}`));return}let i=new XMLHttpRequest;i.open("POST",qe(e)),i.withCredentials=true,i.upload.addEventListener("progress",l=>{l.lengthComputable&&r(Math.round(l.loaded/l.total*100));}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{o(JSON.parse(i.responseText));}catch{a(new Error("Invalid JSON"));}else a(new Error(`Upload Error: ${i.status}`));}),i.addEventListener("error",()=>a(new Error("Network error"))),i.send(t);}):a(new Error(`Upload Error: ${n.status}`));}),n.addEventListener("error",()=>a(new Error("Network error during upload"))),n.send(t);})}function Ar({size:e="md",className:t=""}){return jsxRuntime.jsx("svg",{className:`kyro-spinner kyro-spinner-${e} ${t}`,viewBox:"0 0 24 24",fill:"none",children:jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"40 20"})})}function Et({variant:e,count:t=1,className:r=""}){let o={text:"h-3 rounded-md",circle:"size-10 rounded-full",rect:"h-10 rounded-xl",card:"h-32 rounded-2xl","table-row":"h-14 rounded-xl","media-card":"aspect-square rounded-2xl","stat-card":"h-24 rounded-2xl"};return jsxRuntime.jsx(jsxRuntime.Fragment,{children:Array.from({length:t}).map((a,n)=>jsxRuntime.jsx("div",{className:`kyro-shimmer ${o[e]} ${r}`},n))})}function Xi({back:e}){return e.href?jsxRuntime.jsx("a",{href:e.href,onClick:t=>{e.onClick&&(t.preventDefault(),e.onClick());},className:"p-1.5 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] transition-all",children:jsxRuntime.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}):jsxRuntime.jsx("button",{type:"button",onClick:e.onClick,className:"p-1.5 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] transition-all",children:jsxRuntime.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})})}function Kc({breadcrumbs:e}){return e?.map((t,r)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[r>0&&jsxRuntime.jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),t.href||t.onClick?jsxRuntime.jsx("a",{href:t.href,onClick:o=>{t.onClick&&(o.preventDefault(),t.onClick());},className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] transition-all",children:t.label}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:t.label})]},r))}function Qi({actions:e}){return Array.isArray(e)?jsxRuntime.jsx("div",{className:"flex items-center gap-3",children:e.map((t,r)=>jsxRuntime.jsxs("button",{type:"button",onClick:t.onClick,className:`flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm transition-all shadow-lg shadow-[var(--kyro-primary)]/10 ${t.variant==="outline"?"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]":t.variant==="ghost"?"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] shadow-none":"kyro-btn-primary hover:opacity-90"} ${t.className||""}`,children:[t.icon&&jsxRuntime.jsx(t.icon,{className:"w-4 h-4"}),t.label]},r))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function Yi({action:e}){return jsxRuntime.jsxs("button",{type:"button",onClick:e.onClick,className:`kyro-btn kyro-btn-primary flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10 w-full lg:w-auto justify-center ${e.className||""}`,children:[e.icon&&jsxRuntime.jsx(e.icon,{className:"w-4 h-4"}),e.label]})}function Ft({title:e,description:t,icon:r,breadcrumbs:o,metadata:a,back:n,action:s,actions:i,children:l}){let d=o?.[o.length-1];return jsxRuntime.jsxs("div",{className:"surface-tile px-3 md:px-6 py-3 md:pt-4 mb-4 md:mb-8",children:[jsxRuntime.jsxs("div",{className:"md:hidden space-y-2",children:[(o||n)&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[n&&jsxRuntime.jsx(Xi,{back:n}),jsxRuntime.jsxs("details",{className:"group [&::-webkit-details-marker]:hidden flex-1 min-w-0",children:[jsxRuntime.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[jsxRuntime.jsx("span",{className:"flex-1 text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] truncate",children:d?.label||""}),jsxRuntime.jsx("svg",{className:"w-3 h-3 text-[var(--kyro-text-secondary)] opacity-40 group-open:rotate-180 transition-transform",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M6 9l6 6 6-6"})})]}),jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-[var(--kyro-border)] space-y-2",children:[o&&jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:o.map((c,m)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[m>0&&jsxRuntime.jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),c.href||c.onClick?jsxRuntime.jsx("a",{href:c.href,onClick:y=>{c.onClick&&(y.preventDefault(),c.onClick());},className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] transition-all",children:c.label}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:c.label})]},m))}),a&&jsxRuntime.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:a.map((c,m)=>jsxRuntime.jsx(ka__default.default.Fragment,{children:c},m))}),l]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[r&&jsxRuntime.jsx(r,{className:"w-5 h-5 text-[var(--kyro-primary)] shrink-0"}),e&&jsxRuntime.jsx("h1",{className:"text-lg font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e}),a&&!t&&jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full bg-[var(--kyro-primary)] shrink-0"})]}),t&&jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0 text-xs",children:t}),a&&jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[m===0&&jsxRuntime.jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))})]})]}),jsxRuntime.jsxs("div",{className:"hidden md:flex md:flex-row md:items-center justify-between gap-6",children:[jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[(o||n)&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n&&jsxRuntime.jsx(Xi,{back:n}),o&&jsxRuntime.jsx(Kc,{breadcrumbs:o})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[r&&jsxRuntime.jsx(r,{className:"w-6 h-6 text-[var(--kyro-primary)]"}),e&&jsxRuntime.jsx("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e})]}),(t||a)&&jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 mt-1",children:[t&&jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0",children:t}),a&&jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[m===0&&(t||m>0)&&jsxRuntime.jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))}),l]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3 flex-wrap shrink-0",children:[i&&jsxRuntime.jsx(Qi,{actions:i}),s&&jsxRuntime.jsx(Yi,{action:s})]})]}),(i||s)&&jsxRuntime.jsxs("div",{className:"md:hidden flex items-center gap-2 mt-3 pt-3 border-t border-[var(--kyro-border)]",children:[s&&jsxRuntime.jsx(Yi,{action:s}),i&&jsxRuntime.jsx(Qi,{actions:i})]})]})}var Wc={draft:{class:"bg-gray-100 text-gray-600",label:"Draft"},published:{class:"bg-green-100 text-green-700",label:"Published"},scheduled:{class:"bg-blue-100 text-blue-700",label:"Scheduled"},archived:{class:"bg-yellow-100 text-yellow-700",label:"Archived"},active:{class:"bg-green-100 text-green-700",label:"Active"},inactive:{class:"bg-gray-100 text-gray-600",label:"Inactive"},pending:{class:"bg-yellow-100 text-yellow-700",label:"Pending"},completed:{class:"bg-green-100 text-green-700",label:"Completed"},cancelled:{class:"bg-red-100 text-red-700",label:"Cancelled"}};function Pt({variant:e,status:t,className:r="",children:o,dot:a=false}){let n=e||t||"default",s=Wc[n],i=s?s.class:`kyro-badge-${n}`;return jsxRuntime.jsxs("span",{className:`kyro-badge ${i} ${r}`,children:[a&&jsxRuntime.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current mr-1.5 opacity-60"}),o||s?.label||n]})}function us({count:e,max:t=99}){return e===0?null:jsxRuntime.jsx("span",{className:"inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 text-xs font-medium bg-gray-200 text-gray-700 rounded-full",children:e>t?`${t}+`:e})}function ys({variant:e="secondary",size:t="md",loading:r=false,children:o,className:a="",disabled:n,...s}){let i="kyro-btn",l=`kyro-btn-${e}`,d=`kyro-btn-${t}`;return jsxRuntime.jsxs("button",{type:"button",className:`${i} ${l} ${d} ${a}`,disabled:n||r,...s,children:[r?jsxRuntime.jsx("span",{className:"kyro-btn-loading",children:jsxRuntime.jsx("svg",{className:"kyro-btn-spinner",viewBox:"0 0 24 24",children:jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",fill:"none",strokeDasharray:"60 30"})})}):null,jsxRuntime.jsx("span",{className:r?"kyro-btn-text-hidden":"",children:o})]})}function fn({page:e,totalPages:t,totalDocs:r,limit:o,onPageChange:a,onLimitChange:n}){return t<=1?null:jsxRuntime.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 px-4 py-3 border-t border-[var(--kyro-border)]",children:[r!==void 0&&o?jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-secondary)] font-medium",children:["Showing ",(e-1)*o+1," to ",Math.min(e*o,r)," of ",r]}):jsxRuntime.jsx("span",{}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-center",children:[n&&jsxRuntime.jsxs("select",{value:o,onChange:s=>n(Number(s.target.value)),className:"text-xs border border-[var(--kyro-border)] rounded-lg px-2 py-1 bg-[var(--kyro-bg)] text-[var(--kyro-text-secondary)]",children:[jsxRuntime.jsx("option",{value:10,children:"10/page"}),jsxRuntime.jsx("option",{value:25,children:"25/page"}),jsxRuntime.jsx("option",{value:50,children:"50/page"}),jsxRuntime.jsx("option",{value:100,children:"100/page"})]}),jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-secondary)] font-medium",children:["Page ",e," of ",t]}),jsxRuntime.jsxs("div",{className:"flex gap-1",children:[jsxRuntime.jsx(ys,{variant:"ghost",size:"sm",disabled:e<=1,onClick:()=>a(e-1),children:"\u2190 Previous"}),jsxRuntime.jsx(ys,{variant:"ghost",size:"sm",disabled:e>=t,onClick:()=>a(e+1),children:"Next \u2192"})]})]})]})}function yo(e,t,r){return r in t?t[r]:fs(e,t,r)}function fs(e,t,r){for(let o of e)if(o.name){if(o.type==="tabs"&&"tabs"in o){let a=t[o.name];if(a&&typeof a=="object"){if(r in a)return a[r];let n=fs(o.tabs?.flatMap(s=>s.fields||[])||[],a,r);if(n!==void 0)return n}}if((o.type==="group"||o.type==="collapsible")&&"fields"in o){let a=t[o.name];if(a&&typeof a=="object"){if(r in a)return a[r];let n=fs(o.fields||[],a,r);if(n!==void 0)return n}}}}function gs({collection:e,collectionSlug:t,initialDocs:r=[],initialTotal:o=0,onCreate:a,onEdit:n,config:s}){let i=t||e.slug,{permissions:l}=Mr(),d=l?.collections?.[i]?.create!==false,c=l?.collections?.[i]?.delete!==false,m=l?.collections?.[i]?.update!==false,y=()=>{d&&(a?a():window.location.href=`${Ye}/${i}/new`);},g=D=>{n?n(D):window.location.href=`${Ye}/${i}/${D}`;},[x,f]=ka.useState(r),[u,b]=ka.useState(o),[v,R]=ka.useState(false),[L,C]=ka.useState(1),[w,N]=ka.useState(10),[p,A]=ka.useState(new Set),[O,F]=ka.useState(""),[P,S]=ka.useState([]),{confirm:M,alert:j}=at(),se=()=>{S([...P,{field:"",operator:"equals",value:""}]);},ie=()=>{F(""),S([]),je(null);},ue=D=>{S(P.filter((G,te)=>te!==D));},oe=(D,G)=>{S(P.map((te,sr)=>sr===D?{...te,...G}:te));},[ne,je]=ka.useState(null),[ft,B]=ka.useState(false),[K,ce]=ka.useState(false);function he(D){let G=[];for(let te of D||[])if(!(!te.name||te.hidden===true||te.admin?.hidden||te.name==="id"))if(te.type==="tabs"&&te.tabs)for(let sr of te.tabs)sr.fields&&G.push(...he(sr.fields));else (te.type==="row"||te.type==="collapsible")&&te.fields?G.push(...he(te.fields)):G.push(te);return G}let De=ka.useMemo(()=>he(e.fields),[e.fields]),Ce=typeof e.admin?.useAsTitle=="string"?e.admin.useAsTitle:De.find(D=>D.type!=="group"&&typeof D.name=="string")?.name,[I,z]=ka.useState(()=>{let D;return e.admin?.defaultColumns?D=[...e.admin?.defaultColumns||[]]:D=De.slice(0,4).map(G=>G.name).filter(G=>!!G),Ce&&D.includes(Ce)&&(D=[Ce,...D.filter(G=>G!==Ce)]),D.includes("updatedAt")||D.push("updatedAt"),new Set(D)}),Ke=ka.useCallback(D=>{z(G=>{let te=new Set(G);return te.has(D)?te.delete(D):te.add(D),te});},[]);function ye(D){let G=De.find(te=>te.name===D);return G&&G.type==="group"&&G.fields?.[0]?.name?`${D}.${G.fields[0].name}`:D}let Se=ka.useCallback(D=>{let G=ye(D);je(te=>te&&te.field===G?{field:G,direction:te.direction==="asc"?"desc":"asc"}:{field:G,direction:"asc"});},[]),dt=ka.useMemo(()=>{let D=De.filter(G=>!!G.name&&I.has(G.name));return I.has("status")&&D.push({name:"status",type:"select",label:"Status",options:[{value:"draft",label:"Draft"},{value:"published",label:"Published"}]}),D},[De,I]);function Tt(D){return !D.name||!Ce?false:D.name===Ce||D.type==="group"&&D.fields?.[0]?.name===Ce}function Wt(D,G){return G.name?yo(e.fields,D,G.name)??null:null}let vt=ka.useCallback(async()=>{R(true);try{let D=new URLSearchParams({page:L.toString(),limit:w.toString()});O&&D.append("search",O),ne&&D.append("sort",ne.field),ne&&D.append("order",ne.direction),P.length>0&&D.append("filters",JSON.stringify(P));let G=await Be($r(`/api/${i}?${D}`),{autoToast:!1});f(G.docs||[]),b(G.totalDocs||0);}catch(D){console.error("Failed to load docs:",D);}finally{R(false);}},[i,L,w,O,ne,P]);ka.useEffect(()=>{x.length===0&&o===0&&vt();},[]);let q=ka.useRef(true);ka.useEffect(()=>{if(q.current){q.current=false;return}vt();},[L,w,O,ne,P]);let X=()=>{p.size===x.length?A(new Set):A(new Set(x.map(D=>D.id)));},le=D=>{let G=new Set(p);G.has(D)?G.delete(D):G.add(D),A(G);},xe=()=>{M({title:"Delete Documents",message:`Are you sure you want to delete ${p.size} document(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let D of Array.from(p))await bt(`/api/${i}/${D}`);A(new Set),vt(),$.success("Documents deleted");}catch(D){console.error("Bulk delete failed:",D),$.error("Failed to delete some documents");}}});},we=D=>{M({title:"Delete Document",message:"Are you sure you want to delete this document? This cannot be undone.",variant:"danger",onConfirm:async()=>{try{await bt(`/api/${i}/${D}`),vt(),$.success("Document deleted");}catch(G){console.error("Delete failed:",G),$.error("Failed to delete document");}}});},Qe=Math.ceil(u/w),wt=O||P.length>0||ne;return jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx(Ft,{title:e.label||i,description:e.admin?.description||`Manage your ${e.label||i}`,metadata:u>0?[jsxRuntime.jsxs("span",{className:"text-xs font-bold opacity-60",children:[u," documents"]},"count")]:void 0,action:d?{label:`Create ${e.singularLabel||e.label||i}`,onClick:y,icon:lucideReact.Plus}:void 0}),jsxRuntime.jsxs("div",{className:"surface-tile p-4 flex flex-col lg:flex-row gap-4 items-start lg:items-center",children:[jsxRuntime.jsxs("div",{className:"relative flex-1 w-full lg:max-w-md",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search...",value:O,onChange:D=>F(D.target.value),className:"w-full pl-10 pr-4 py-2.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-sm font-medium text-[var(--kyro-text-primary)] placeholder:text-[var(--kyro-text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>B(!ft),className:`flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm transition-all ${ft||P.length>0?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx(lucideReact.Filter,{className:"w-4 h-4"}),"Filters",P.length>0&&jsxRuntime.jsx("span",{className:"ml-1 px-1.5 py-0.5 bg-[var(--kyro-sidebar-text-active)] text-[var(--kyro-sidebar-active)] rounded-full text-xs",children:P.length})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>ce(!K),className:"flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-all",children:[jsxRuntime.jsx(lucideReact.Columns3,{className:"w-4 h-4"}),"Columns"]}),K&&jsxRuntime.jsxs("div",{className:"absolute right-0 top-full mt-2 w-56 surface-tile border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 overflow-hidden",children:[jsxRuntime.jsx("div",{className:"p-3 border-b border-[var(--kyro-border)]",children:jsxRuntime.jsx("span",{className:"text-xs font-bold tracking-wider text-[var(--kyro-text-secondary)]",children:"Toggle Columns"})}),jsxRuntime.jsx("div",{className:"p-2 max-h-64 overflow-y-auto",children:De.map(D=>D.name?jsxRuntime.jsxs("label",{className:"flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-[var(--kyro-surface-accent)] cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:I.has(D.name),onChange:()=>Ke(D.name),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"}),jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:D.label||D.name})]},D.name):null)})]})]}),wt&&jsxRuntime.jsx("button",{type:"button",onClick:ie,className:"px-4 py-2 rounded-xl font-bold text-sm text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10 transition-all",children:"Clear All"})]})]}),ft&&jsxRuntime.jsxs("div",{className:"surface-tile p-4 border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsx("h3",{className:"font-medium text-[var(--kyro-text-primary)]",children:"Advanced Filters"}),jsxRuntime.jsxs("button",{type:"button",onClick:se,className:"flex items-center gap-2 px-3 py-1.5 text-sm font-bold text-[var(--kyro-sidebar-active)] hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4"}),"Add Filter"]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[P.map((D,G)=>jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[jsxRuntime.jsx("select",{value:D.field,onChange:te=>oe(G,{field:te.target.value}),className:"px-3 py-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm font-medium text-[var(--kyro-text-primary)]",children:De.map(te=>jsxRuntime.jsx("option",{value:te.name,children:te.label||te.name},te.name))}),jsxRuntime.jsxs("select",{value:D.operator,onChange:te=>oe(G,{operator:te.target.value}),className:"px-3 py-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm font-medium text-[var(--kyro-text-primary)]",children:[jsxRuntime.jsx("option",{value:"equals",children:"Equals"}),jsxRuntime.jsx("option",{value:"contains",children:"Contains"}),jsxRuntime.jsx("option",{value:"gt",children:"Greater than"}),jsxRuntime.jsx("option",{value:"lt",children:"Less than"}),jsxRuntime.jsx("option",{value:"gte",children:"Greater or equal"}),jsxRuntime.jsx("option",{value:"lte",children:"Less or equal"})]}),jsxRuntime.jsx("input",{type:"text",value:D.value,onChange:te=>oe(G,{value:te.target.value}),placeholder:"Value...",className:"flex-1 min-w-[150px] px-3 py-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm font-medium text-[var(--kyro-text-primary)]"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>ue(G),className:"p-2 text-[var(--kyro-text-muted)] hover:text-red-500 transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]},G)),P.length===0&&jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-muted)]",children:'No filters applied. Click "Add Filter" to create one.'})]})]}),p.size>0&&jsxRuntime.jsxs("div",{className:"surface-tile p-4 flex items-center justify-between border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:[p.size," selected"]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[c&&jsxRuntime.jsxs("button",{type:"button",onClick:xe,className:"flex items-center gap-2 px-4 py-2 bg-red-500 text-white rounded-lg font-bold text-sm hover:bg-red-600 transition-all",children:[jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"}),"Delete Selected"]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>A(new Set),className:"px-4 py-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] font-bold text-sm transition-all",children:"Cancel"})]})]}),jsxRuntime.jsx("div",{className:"surface-tile overflow-hidden",children:v?jsxRuntime.jsx("div",{className:"space-y-2 p-4",children:jsxRuntime.jsx(Et,{variant:"table-row",count:8})}):x.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8",children:[jsxRuntime.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:jsxRuntime.jsx(lucideReact.Archive,{className:"w-4 h-4"})}),jsxRuntime.jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:"No documents found"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:wt?"Try adjusting your filters or search query.":`Get started by creating your first ${(e.singularLabel||e.label||i).toLowerCase()}.`}),!wt&&d&&jsxRuntime.jsxs("button",{type:"button",onClick:y,className:"mt-4 kyro-btn kyro-btn-md kyro-btn-primary shadow-md flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4"}),"Create"," ",String(e.singularLabel||e.label||i)]})]}):jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-left",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"text-[var(--kyro-text-secondary)] font-bold text-[10px] tracking-[0.3em] border-b border-[var(--kyro-border)] whitespace-nowrap",children:[jsxRuntime.jsx("th",{className:"px-4 py-4 w-10",children:jsxRuntime.jsx("input",{type:"checkbox",checked:p.size===x.length&&x.length>0,onChange:X,className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),dt.map(D=>jsxRuntime.jsx("th",{className:"px-4 py-4 cursor-pointer hover:text-[var(--kyro-text-primary)] transition-colors",onClick:()=>Se(D.name),children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[Yc(dt,D.type)??(D.label||D.name),ne&&ne.field===D.name&&jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4"})]})},D.name)),e.timestamps?jsxRuntime.jsx("th",{className:"px-4 py-4",children:"Created"}):null,jsxRuntime.jsx("th",{className:"px-4 py-4 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:x.map(D=>jsxRuntime.jsxs("tr",{className:"hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer group",onClick:()=>g(D.id),children:[jsxRuntime.jsx("td",{className:"px-4 py-3",onClick:G=>G.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:p.has(D.id),onChange:()=>le(D.id),className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),dt.map(G=>{let te=Wt(D,G),sr=G.type==="select"&&te?G.options?.find(so=>so.value===te)?.label||te:Qc(te,G.type);return jsxRuntime.jsx("td",{className:`px-4 py-3 ${Tt(G)?"font-medium text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)]"}`,children:sr},G.name)}),e.timestamps?jsxRuntime.jsx("td",{className:"px-4 py-3 text-sm text-[var(--kyro-text-secondary)]",children:D.createdAt?new Date(D.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"\u2014"}):null,jsxRuntime.jsx("td",{className:"px-4 py-3 text-right",onClick:G=>G.stopPropagation(),children:jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>g(D.id),className:"flex items-center gap-2 px-3 py-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg text-sm font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-all",title:m?"Edit":"View",children:jsxRuntime.jsx(lucideReact.Pencil,{className:"w-4 h-4"})}),c&&jsxRuntime.jsx("button",{type:"button",onClick:()=>we(D.id),className:"inline-flex items-center justify-center w-8 h-8 rounded-md text-[var(--kyro-text-muted)] hover:bg-red-50 hover:text-red-500 dark:hover:bg-red-500/10 transition-colors",title:"Delete",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"})})]})})]},D.id))})]})})}),jsxRuntime.jsx(fn,{page:L,totalPages:Qe,totalDocs:u,limit:w,onPageChange:C,onLimitChange:D=>{N(D),C(1);}})]})}function Qc(e,t){return e==null?"\u2014":typeof e=="boolean"?e?"Yes":"No":t==="number"||t==="price"?String(e):t==="date"||t==="datetime"?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):Array.isArray(e)?e.map(r=>r&&typeof r=="object"?r.title||r.name||r.email||r.filename||r.url||JSON.stringify(r).slice(0,30):String(r??"").slice(0,30)).filter(Boolean).join(", "):typeof e=="object"?e.title?e.title:e.name?e.name:e.email?e.email:JSON.stringify(e).slice(0,50):String(e).slice(0,60)}function Yc(e,t){return t!=="tabs"?void 0:e[0]?.tabs?.[0]?.fields?.[0]?.label}var bs=(e,t)=>{let r=e?.toLowerCase()||"",o=t?.toLowerCase()||"";return r.startsWith("image/")||o.match(/\.(jpe?g|png|gif|webp|avif|svg)$/i)?"image":r.startsWith("video/")||o.match(/\.(mp4|webm|ogg|mov)$/i)?"video":r.startsWith("audio/")||o.match(/\.(mp3|wav|ogg|m4a)$/i)?"audio":r.includes("pdf")||o.endsWith(".pdf")?"pdf":o.match(/\.(doc|docx|txt|rtf|odt)$/i)?"document":o.match(/\.(xls|xlsx|csv)$/i)?"spreadsheet":o.match(/\.(zip|tar|gz|7z|rar)$/i)?"archive":"other"},nl=({type:e,className:t})=>{switch(e){case "image":return jsxRuntime.jsx(lucideReact.Image,{className:t});case "video":return jsxRuntime.jsx(lucideReact.Film,{className:t});case "audio":return jsxRuntime.jsx(lucideReact.Music,{className:t});case "pdf":case "document":return jsxRuntime.jsx(lucideReact.FileText,{className:t});default:return jsxRuntime.jsx(lucideReact.File,{className:t})}};function lr({field:e,value:t,onChange:r,disabled:o}){let a=ka.useRef(null),n=ka.useRef(null),[s,i]=ka.useState(false),[l,d]=ka.useState(false),[c,m]=ka.useState(false),[y,g]=ka.useState([]),[x,f]=ka.useState([]),[u,b]=ka.useState(""),[v,R]=ka.useState(false),[L,C]=ka.useState(""),[w,N]=ka.useState(false),[p,A]=ka.useState(""),[O,F]=ka.useState(""),[P,S]=ka.useState([]),M=e?.label||e?.name||"File",j=e.maxCount??(e.hasMany?999:1),se=j>1,ie=Array.isArray(t)?t:t?[t]:[],ue=ie.length<j;ka.useEffect(()=>{(async()=>{let z=ie.filter(Se=>typeof Se=="string").map(Se=>Se),Ke=ie.filter(Se=>typeof Se=="object"&&Se!==null&&typeof Se.id=="string"&&!Se.url&&!Se.filename&&!Se.mimeType).map(Se=>Se.id),ye=[...z,...Ke];if(ye.length!==0)try{let Se=await Promise.all(ye.map(Tt=>Be(`/api/media/${Tt}`))),dt=[...ie];Se.forEach(Tt=>{let Wt=Tt.id,vt=dt.findIndex(X=>X===Wt);if(vt!==-1){dt[vt]=Tt;return}let q=dt.findIndex(X=>typeof X=="object"&&X!==null&&X.id===Wt);q!==-1&&(dt[q]=Tt);}),r(se?dt:dt[0]);}catch(Se){console.error("Failed to fetch media details:",Se);}})();},[t]),ka.useEffect(()=>{l&&(oe(),ne());},[l,u]);let oe=async()=>{try{let I=await Be($r("/api/media/folders"));f(I.folders||[]);}catch{f([]);}},ne=async()=>{R(true);try{let I=$r("/api/media?limit=60&sortBy=createdAt&sortDir=desc");u&&(I+="&folder="+encodeURIComponent(u));let z=await Be(I);g(z.docs||[]);}catch{g([]);}finally{R(false);}},je=async I=>{i(true);try{let z=new FormData;z.append("file",I),u&&z.append("folder",u);let Ke=await ya("/api/media/upload",z),ye={id:Ke.id,filename:Ke.filename,originalName:Ke.originalName??I.name,url:Ke.url,mimeType:I.type};r(se?[...ie,ye]:ye),$.success(`Asset synchronized: ${ye.filename}`);}catch(z){console.error("Upload failed:",z),$.error(`Upload failed: ${z instanceof Error?z.message:"Unknown error"}`);}finally{i(false);}},ft=async()=>{let I=p.trim();if(I){F("");try{let z=await et("/api/media/upload",{url:I}),Ke=(()=>{try{return new URL(I).pathname.split("/").pop()||z.originalName||"url-image"}catch{return z.originalName||"url-image"}})(),ye={id:z.id,filename:z.filename,originalName:Ke,url:z.url,mimeType:z.mimeType||"image/*"};r(se?[...ie,ye]:ye),$.success(`URL asset established: ${ye.filename}`),A(""),N(!1);}catch(z){let Ke=z instanceof Error?z.message:"Invalid URL";F(Ke);}}},B=I=>({id:I.id,filename:I.filename,url:I.url,mimeType:I.mimeType}),K=I=>{se?S(z=>z.find(ye=>ye.id===I.id)?z.filter(ye=>ye.id!==I.id):[...z,I]):(r(B(I)),d(false),C(""));},ce=()=>{if(P.length>0){let I=[...ie,...P.map(B)];r(I);}S([]),d(false),C("");},he=I=>{let z=[...ie];z.splice(I,1),r(se?z:z[0]||null);},De=ka.useMemo(()=>y.filter(I=>!L||I.filename?.toLowerCase().includes(L.toLowerCase())||I.title?.toLowerCase().includes(L.toLowerCase())),[y,L]);if(s)return jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] p-2",children:"Uploading..."});let Ce=(I,z)=>{if(!I)return null;let Ke=bs(I.mimeType,I.filename||I.url);return jsxRuntime.jsxs("div",{className:"flex items-center gap-3 p-2.5 bg-[var(--kyro-surface-accent)] rounded-lg border border-[var(--kyro-border)] group",children:[jsxRuntime.jsx("div",{className:"w-10 h-10 rounded-md overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] flex items-center justify-center flex-shrink-0",children:Ke==="image"?jsxRuntime.jsx("img",{src:ua(I.url),alt:I.filename||"Preview",className:"w-full h-full object-cover"}):jsxRuntime.jsx(nl,{type:Ke,className:"w-5 h-5 text-[var(--kyro-text-secondary)]"})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-[11px] font-medium truncate text-[var(--kyro-text-primary)]",children:I.originalName||I.filename||"Unnamed File"}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] tracking-wider font-bold",children:M})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>z!==void 0?he(z):r(null),disabled:o,className:"p-1.5 rounded-md text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] hover:bg-[var(--kyro-danger-bg)] transition-all opacity-0 group-hover:opacity-100",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]},z)};return t?jsxRuntime.jsxs("div",{className:"space-y-2",children:[se?jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[ie.map((I,z)=>Ce(I,z)),ue&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{S([]),d(true);},disabled:o,className:"flex items-center justify-center h-12 border-2 border-dashed border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-border-active)] cursor-pointer transition-colors",children:["+ Add ",M]})]}):Ce(t),jsxRuntime.jsx("input",{ref:a,type:"file",accept:"image/*",onChange:I=>{let z=I.target.files?.[0];z&&je(z);},disabled:o,className:"hidden"})]}):jsxRuntime.jsxs("div",{className:"space-y-2 relative",children:[jsxRuntime.jsx("input",{ref:a,type:"file",accept:e.allowedTypes?.join(",")||"*/*",onChange:I=>{let z=I.target.files?.[0];z&&je(z);},disabled:o,className:"hidden"}),jsxRuntime.jsxs("div",{className:"flex gap-2 flex-wrap",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a.current?.click(),disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:["+ Upload ",M]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{S([]),d(true);},disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:"Library"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>N(!w),disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:"URL"})]}),w&&jsxRuntime.jsxs("div",{className:"flex gap-2 items-center",children:[jsxRuntime.jsx("input",{ref:n,type:"url",placeholder:"https://example.com/image.jpg",value:p,onChange:I=>{A(I.target.value),F("");},onKeyDown:I=>I.key==="Enter"&&ft(),disabled:o,className:"flex-1 px-2 py-1.5 text-xs rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-primary)]"}),jsxRuntime.jsx("button",{type:"button",onClick:ft,disabled:o||!p.trim(),className:"kyro-btn kyro-btn-primary px-3 py-1.5 text-xs rounded cursor-pointer hover:opacity-90 transition-opacity disabled:opacity-50",children:"Add"}),O&&jsxRuntime.jsx("span",{className:"text-xs text-[var(--kyro-error)]",children:O})]}),l&&(c?reactDom.createPortal(jsxRuntime.jsx(al,{isFullscreen:true,isMultiple:se,selectedItems:P,pickerSearch:L,setPickerSearch:C,folders:x,selectedFolder:u,setSelectedFolder:b,mediaLoading:v,filteredMedia:De,selectFromLibrary:K,onDone:ce,setIsPickerFullscreen:m,setShowPicker:d}),document.body):jsxRuntime.jsx(al,{isFullscreen:false,isMultiple:se,selectedItems:P,pickerSearch:L,setPickerSearch:C,folders:x,selectedFolder:u,setSelectedFolder:b,mediaLoading:v,filteredMedia:De,selectFromLibrary:K,onDone:ce,setIsPickerFullscreen:m,setShowPicker:d}))]})}function al({isFullscreen:e,isMultiple:t,selectedItems:r,pickerSearch:o,setPickerSearch:a,folders:n,selectedFolder:s,setSelectedFolder:i,mediaLoading:l,filteredMedia:d,selectFromLibrary:c,onDone:m,setIsPickerFullscreen:y,setShowPicker:g}){let x=f=>r.some(u=>u.id===f);return jsxRuntime.jsxs("div",{className:`${e?"fixed inset-0 z-[9999]":"relative z-[9999] w-[360px] max-h-[400px] mt-1 rounded-lg shadow-lg"} overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] flex flex-col`,children:[jsxRuntime.jsxs("div",{className:"p-2 border-b border-[var(--kyro-border)] flex flex-col gap-2",children:[jsxRuntime.jsx("input",{type:"text",placeholder:"Search media...",value:o,onChange:f=>a(f.target.value),className:"w-full px-2 py-1.5 text-xs rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-primary)]"}),n.length>0&&jsxRuntime.jsxs("div",{className:"flex gap-1 flex-wrap",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>i(""),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===""?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:"All"}),n.slice(0,6).map(f=>jsxRuntime.jsx("button",{type:"button",onClick:()=>i(f.path),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===f.path?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:f.name},f.path))]})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-2",children:l?jsxRuntime.jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsxRuntime.jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"No media found"}):jsxRuntime.jsx("div",{className:`grid gap-1 ${e?"grid-cols-[repeat(auto-fill,minmax(140px,1fr))]":"grid-cols-3"}`,children:d.map(f=>{let u=x(f.id);return jsxRuntime.jsxs("button",{type:"button",onClick:()=>c(f),className:`border rounded-md overflow-hidden cursor-pointer p-0 bg-[var(--kyro-surface)] transition-all relative group ${u?"border-[var(--kyro-primary)] ring-2 ring-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]"}`,children:[jsxRuntime.jsx("div",{className:`w-full flex items-center justify-center bg-[var(--kyro-surface-accent)] ${e?"h-[120px]":"h-[80px]"}`,children:bs(f.mimeType,f.filename)==="image"?jsxRuntime.jsx("img",{src:ua(f.thumbnailUrl||f.url),alt:f.filename,className:"w-full h-full object-cover"}):jsxRuntime.jsx(nl,{type:bs(f.mimeType,f.filename),className:e?"w-10 h-10":"w-8 h-8"})}),t&&u&&jsxRuntime.jsx("div",{className:"absolute top-1 right-1 w-5 h-5 rounded-full bg-[var(--kyro-primary)] flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.Check,{className:"w-3 h-3 text-white"})})]},f.id)})})}),jsxRuntime.jsxs("div",{className:"p-2 border-t border-[var(--kyro-border)] flex justify-between items-center",children:[jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[d.length," items"]}),jsxRuntime.jsxs("div",{className:"flex gap-2 items-center",children:[t&&jsxRuntime.jsxs("button",{type:"button",onClick:m,className:"kyro-btn kyro-btn-primary px-3 py-1 text-xs font-semibold rounded cursor-pointer hover:opacity-90 transition-opacity",children:["Done",r.length>0?` (${r.length})`:""]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>y(!e),className:"p-1.5 rounded text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",title:e?"Exit fullscreen":"Fullscreen",children:e?jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"})}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(false),y(false);},className:"text-xs text-[var(--kyro-text-secondary)] bg-transparent border-none cursor-pointer hover:text-[var(--kyro-text-primary)]",children:"Close"})]})]})]})}function st({field:e,error:t,children:r,hideLabel:o=false}){return jsxRuntime.jsxs("div",{className:"space-y-2.5 w-full group",children:[e.label&&!o&&jsxRuntime.jsx("div",{className:"flex justify-between items-end mb-1",children:jsxRuntime.jsxs("label",{className:"block text-xs font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 group-focus-within:opacity-100 group-focus-within:text-[var(--kyro-primary)] transition-all duration-300",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})}),jsxRuntime.jsx("div",{className:"relative transform transition-transform duration-200 focus-within:scale-[1.002]",children:r}),(e.admin?.description||t)&&jsxRuntime.jsxs("div",{className:"flex flex-col gap-1.5 px-1",children:[e.admin?.description&&!t&&jsxRuntime.jsx("p",{className:"text-[11px] leading-relaxed text-[var(--kyro-text-muted)] font-medium opacity-60 italic",children:e.admin.description}),t&&jsxRuntime.jsxs("p",{className:"text-[11px] leading-relaxed text-[var(--kyro-error)] font-bold flex items-center gap-2 animate-in fade-in slide-in-from-top-1 duration-300",children:[jsxRuntime.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-error)] shadow-[0_0_8px_var(--kyro-error)]"}),t]})]})]})}function dr({open:e,onClose:t,title:r,children:o,width:a="md",showOverlay:n=false,accentClass:s}){let i=ka.useRef(null),[l,d]=ka.useState(false);ka.useEffect(()=>{d(true);},[]),ka.useEffect(()=>{let m=y=>{y.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",m),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",m),document.body.style.overflow="";}},[e,t]);let c={sm:"w-full sm:w-[320px]",md:"w-full sm:w-[400px]",lg:"w-full sm:w-[550px]",xl:"w-full sm:w-[700px]"};return !e||!l?null:reactDom.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n&&jsxRuntime.jsx("div",{className:"fixed inset-0 z-[99998] bg-black/50 backdrop-blur-sm",onClick:t}),jsxRuntime.jsxs("div",{ref:i,"data-kyro-slide-panel":"true","data-kyro-slide-width":a,className:`fixed right-0 top-0 bottom-0 z-[99999] ${c[a]} bg-[var(--kyro-surface)] ${s?`border-l-2 ${s}`:"border-l border-[var(--kyro-border)]"} shadow-2xl flex flex-col animate-slideIn`,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxRuntime.jsx("h2",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:r}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"p-1.5 text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o})]}),jsxRuntime.jsx("style",{children:`
1
+ 'use strict';var ka=require('react'),zustand=require('zustand'),middleware=require('zustand/middleware'),lucideReact=require('lucide-react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom'),react=require('@tiptap/react'),gp=require('@tiptap/starter-kit'),bp=require('@tiptap/extension-link'),xp=require('@tiptap/extension-image'),kp=require('@tiptap/extension-text-align'),hp=require('@tiptap/extension-underline'),wp=require('@tiptap/extension-highlight'),Np=require('@tiptap/extension-task-list'),Cp=require('@tiptap/extension-task-item'),extensionTextStyle=require('@tiptap/extension-text-style'),Tp=require('@tiptap/extension-color'),ip=require('react-image-crop');require('react-image-crop/dist/ReactCrop.css');var codemirrorThemeGithub=require('@uiw/codemirror-theme-github'),codemirrorThemeAura=require('@uiw/codemirror-theme-aura'),unstorage=require('unstorage'),im=require('unstorage/drivers/indexedb'),templates=require('@kyro-cms/core/templates'),Ro=require('fs'),vanilla=require('zustand/vanilla'),core=require('@dnd-kit/core'),sortable=require('@dnd-kit/sortable'),utilities=require('@dnd-kit/utilities'),mu=require('@uiw/react-codemirror'),langJson=require('@codemirror/lang-json');require('@kyro-cms/core');var fr=require('path'),url=require('url'),esbuild=require('esbuild'),dotenv=require('dotenv'),worker_threads=require('worker_threads');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ka__default=/*#__PURE__*/_interopDefault(ka);var gp__default=/*#__PURE__*/_interopDefault(gp);var bp__default=/*#__PURE__*/_interopDefault(bp);var xp__default=/*#__PURE__*/_interopDefault(xp);var kp__default=/*#__PURE__*/_interopDefault(kp);var hp__default=/*#__PURE__*/_interopDefault(hp);var wp__default=/*#__PURE__*/_interopDefault(wp);var Np__default=/*#__PURE__*/_interopDefault(Np);var Cp__default=/*#__PURE__*/_interopDefault(Cp);var Tp__default=/*#__PURE__*/_interopDefault(Tp);var ip__default=/*#__PURE__*/_interopDefault(ip);var im__default=/*#__PURE__*/_interopDefault(im);var Ro__default=/*#__PURE__*/_interopDefault(Ro);var mu__default=/*#__PURE__*/_interopDefault(mu);var fr__default=/*#__PURE__*/_interopDefault(fr);var Ye=typeof __KYRO_ADMIN_PATH__<"u"?__KYRO_ADMIN_PATH__:"/admin",io=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function qe(e){if(e.startsWith("http")||e.startsWith(io))return e;if(e.startsWith("/api/"))return io+e.slice(4);let t=e.startsWith("/")?"":"/";return `${io}${t}${e}`}function ts(e){return e.startsWith("http")||e.startsWith(Ye)?e:e.startsWith("/admin/")?Ye+e.slice(6):e.startsWith("/")?Ye+e:e}function ua(e){return !e||typeof e!="string"?"":e.startsWith("http")||e.startsWith("blob:")||e.startsWith("data:")||e.startsWith("/")?e:`/${e}`}var Ec={admin:Ye,api:io,resolveApi:qe,resolveAdmin:ts,resolveMedia:ua};var Lr=zustand.create(e=>({user:null,permissions:null,isAuthenticated:false,isLoading:true,error:null,setUser:(t,r=null)=>e({user:t,permissions:r,isAuthenticated:!!t,isLoading:false,error:null}),setLoading:t=>e({isLoading:t}),setError:t=>e({error:t,isLoading:false,isAuthenticated:false,user:null,permissions:null}),logout:()=>e({user:null,permissions:null,isAuthenticated:false,isLoading:false,error:null})}));var Kt=zustand.create(e=>({toasts:[],addToast:(t,r)=>{let o=Math.random().toString(36).substring(7);e(a=>({toasts:[...a.toasts,{id:o,type:t,message:r}]}));},removeToast:t=>e(r=>({toasts:r.toasts.filter(o=>o.id!==t)})),clearToasts:()=>e({toasts:[]})})),$={success:e=>Kt.getState().addToast("success",e),error:e=>Kt.getState().addToast("error",e),warning:e=>Kt.getState().addToast("warning",e),info:e=>Kt.getState().addToast("info",e)};zustand.create()(middleware.persist(e=>({mode:"light",setMode:t=>e({mode:t}),toggleMode:()=>e(t=>({mode:t.mode==="light"?"dark":"light"}))}),{name:"kyro-theme"}));var ot=zustand.create(e=>({sidebarOpen:true,toggleSidebar:()=>e(t=>({sidebarOpen:!t.sidebarOpen})),setSidebarOpen:t=>e({sidebarOpen:t}),modal:{open:false,config:null},confirm:t=>e({modal:{open:true,config:{...t,variant:t.variant||"default"}}}),alert:t=>e({modal:{open:true,config:{...t,variant:t.variant||"default",confirmLabel:t.confirmLabel||"OK",onConfirm:()=>e(r=>({modal:{...r.modal,open:false}}))}}}),closeModal:()=>e(t=>({modal:{...t.modal,open:false},activeModal:null})),activeModal:null,openModal:t=>e({activeModal:t})}));zustand.create(e=>({editor:null,setEditor:t=>e({editor:t}),blockDrawerOpen:false,openBlockDrawer:t=>e({blockDrawerOpen:true,pendingInsert:{pos:null,column:t?.targetColumn??null}}),closeBlockDrawer:()=>e({blockDrawerOpen:false,pendingInsert:{pos:null,column:null}}),toggleBlockDrawer:()=>e(t=>({blockDrawerOpen:!t.blockDrawerOpen})),selectedBlock:null,setSelectedBlock:t=>e({selectedBlock:t}),pendingInsert:{pos:null,column:null},setPendingInsert:(t,r)=>e({pendingInsert:{pos:t,column:r??null}}),clearPendingInsert:()=>e({pendingInsert:{pos:null,column:null}})}));zustand.create((e,t)=>({cache:{},setCache:(r,o)=>e(a=>({cache:{...a.cache,[r]:{data:o,loading:false,error:null,lastFetch:Date.now()}}})),setLoading:(r,o)=>e(a=>({cache:{...a.cache,[r]:{...a.cache[r],loading:o,error:null}}})),setError:(r,o)=>e(a=>({cache:{...a.cache,[r]:{data:null,loading:false,error:o,lastFetch:null}}})),getCache:r=>t().cache[r]||null,invalidateCache:r=>e(o=>{if(r){let{[r]:a,...n}=o.cache;return {cache:n}}return {cache:{}}})}));var Uc="/api/auth/refresh";async function li(){try{return (await fetch(qe(Uc),{method:"POST",credentials:"include"})).ok}catch{return false}}async function ct(e,t={}){let r={};t.body instanceof FormData||(r["Content-Type"]="application/json"),Object.assign(r,t.headers);let o=await fetch(qe(e),{...t,credentials:"include",headers:r});if(o.status===401){if(await li()){let n={};return t.body instanceof FormData||(n["Content-Type"]="application/json"),Object.assign(n,t.headers),await fetch(qe(e),{...t,credentials:"include",headers:n})}window.location.href="/admin/login";}return o}async function De(e,t){let{autoToast:r=true,...o}=t||{},a=await ct(e,o);if(!a.ok){let n=`GET Failed: ${a.status}`;throw r&&$.error(n),new Error(n)}return a.json()}async function et(e,t,r){let{autoToast:o=true,...a}=r||{},n=await ct(e,{method:"POST",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`POST Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function Xt(e,t,r){let{autoToast:o=true,...a}=r||{},n=await ct(e,{method:"PATCH",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`Update Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function kt(e,t){let{autoToast:r=true,...o}=t||{},a=await ct(e,{method:"DELETE",...o});if(!a.ok){let s=`Delete Failed: ${a.status}`;try{let i=await a.json();i.error&&(s=i.error);}catch{}throw r&&$.error(s),new Error(s)}let n=await a.text();return n?JSON.parse(n):{}}function Mr(e){let t=e.includes("?")?"&":"?";return `${e}${t}t=${Date.now()}`}function Ja(e,t,r=50){return !e||t.length===0?`limit=${r}`:`${t.map(a=>`where[${a}][contains]=${encodeURIComponent(e)}`).join("&")}&limit=${r}`}async function ya(e,t,r){if(!r){let o=await ct(e,{method:"POST",body:t});if(!o.ok)throw new Error(`Upload Error: ${o.status}`);return o.json()}return new Promise((o,a)=>{let n=new XMLHttpRequest;n.open("POST",qe(e)),n.withCredentials=true,n.upload.addEventListener("progress",s=>{s.lengthComputable&&r(Math.round(s.loaded/s.total*100));}),n.addEventListener("load",()=>{if(n.status>=200&&n.status<300)try{o(JSON.parse(n.responseText));}catch{a(new Error("Invalid JSON response"));}else n.status===401?li().then(s=>{if(!s){a(new Error(`Upload Error: ${n.status}`));return}let i=new XMLHttpRequest;i.open("POST",qe(e)),i.withCredentials=true,i.upload.addEventListener("progress",l=>{l.lengthComputable&&r(Math.round(l.loaded/l.total*100));}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{o(JSON.parse(i.responseText));}catch{a(new Error("Invalid JSON"));}else a(new Error(`Upload Error: ${i.status}`));}),i.addEventListener("error",()=>a(new Error("Network error"))),i.send(t);}):a(new Error(`Upload Error: ${n.status}`));}),n.addEventListener("error",()=>a(new Error("Network error during upload"))),n.send(t);})}function Ar({size:e="md",className:t=""}){return jsxRuntime.jsx("svg",{className:`kyro-spinner kyro-spinner-${e} ${t}`,viewBox:"0 0 24 24",fill:"none",children:jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"40 20"})})}function Ot({variant:e,count:t=1,className:r=""}){let o={text:"h-3 rounded-md",circle:"size-10 rounded-full",rect:"h-10 rounded-xl",card:"h-32 rounded-2xl","table-row":"h-14 rounded-xl","media-card":"aspect-square rounded-2xl","stat-card":"h-24 rounded-2xl"};return jsxRuntime.jsx(jsxRuntime.Fragment,{children:Array.from({length:t}).map((a,n)=>jsxRuntime.jsx("div",{className:`kyro-shimmer ${o[e]} ${r}`},n))})}function Ji({back:e}){return e.href?jsxRuntime.jsx("a",{href:e.href,onClick:t=>{e.onClick&&(t.preventDefault(),e.onClick());},className:"p-1.5 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] transition-all",children:jsxRuntime.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}):jsxRuntime.jsx("button",{type:"button",onClick:e.onClick,className:"p-1.5 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] transition-all",children:jsxRuntime.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})})}function jc({breadcrumbs:e}){return e?.map((t,r)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[r>0&&jsxRuntime.jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),t.href||t.onClick?jsxRuntime.jsx("a",{href:t.href,onClick:o=>{t.onClick&&(o.preventDefault(),t.onClick());},className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] transition-all",children:t.label}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:t.label})]},r))}function Xi({actions:e}){return Array.isArray(e)?jsxRuntime.jsx("div",{className:"flex items-center gap-3",children:e.map((t,r)=>jsxRuntime.jsxs("button",{type:"button",onClick:t.onClick,className:`flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm transition-all shadow-lg shadow-[var(--kyro-primary)]/10 ${t.variant==="outline"?"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]":t.variant==="ghost"?"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] shadow-none":"kyro-btn-primary hover:opacity-90"} ${t.className||""}`,children:[t.icon&&jsxRuntime.jsx(t.icon,{className:"w-4 h-4"}),t.label]},r))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function Qi({action:e}){return jsxRuntime.jsxs("button",{type:"button",onClick:e.onClick,className:`kyro-btn kyro-btn-primary flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10 w-full lg:w-auto justify-center ${e.className||""}`,children:[e.icon&&jsxRuntime.jsx(e.icon,{className:"w-4 h-4"}),e.label]})}function Ft({title:e,description:t,icon:r,breadcrumbs:o,metadata:a,back:n,action:s,actions:i,children:l}){let d=o?.[o.length-1];return jsxRuntime.jsxs("div",{className:"surface-tile px-3 md:px-6 py-3 md:pt-4 mb-4 md:mb-8",children:[jsxRuntime.jsxs("div",{className:"md:hidden space-y-2",children:[(o||n)&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[n&&jsxRuntime.jsx(Ji,{back:n}),jsxRuntime.jsxs("details",{className:"group [&::-webkit-details-marker]:hidden flex-1 min-w-0",children:[jsxRuntime.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[jsxRuntime.jsx("span",{className:"flex-1 text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] truncate",children:d?.label||""}),jsxRuntime.jsx("svg",{className:"w-3 h-3 text-[var(--kyro-text-secondary)] opacity-40 group-open:rotate-180 transition-transform",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M6 9l6 6 6-6"})})]}),jsxRuntime.jsxs("div",{className:"mt-2 pt-2 border-t border-[var(--kyro-border)] space-y-2",children:[o&&jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:o.map((c,m)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[m>0&&jsxRuntime.jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),c.href||c.onClick?jsxRuntime.jsx("a",{href:c.href,onClick:u=>{c.onClick&&(u.preventDefault(),c.onClick());},className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] transition-all",children:c.label}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:c.label})]},m))}),a&&jsxRuntime.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:a.map((c,m)=>jsxRuntime.jsx(ka__default.default.Fragment,{children:c},m))}),l]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[r&&jsxRuntime.jsx(r,{className:"w-5 h-5 text-[var(--kyro-primary)] shrink-0"}),e&&jsxRuntime.jsx("h1",{className:"text-lg font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e}),a&&!t&&jsxRuntime.jsx("span",{className:"h-2 w-2 rounded-full bg-[var(--kyro-primary)] shrink-0"})]}),t&&jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0 text-xs",children:t}),a&&jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[m===0&&jsxRuntime.jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))})]})]}),jsxRuntime.jsxs("div",{className:"hidden md:flex md:flex-row md:items-center justify-between gap-6",children:[jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[(o||n)&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n&&jsxRuntime.jsx(Ji,{back:n}),o&&jsxRuntime.jsx(jc,{breadcrumbs:o})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[r&&jsxRuntime.jsx(r,{className:"w-6 h-6 text-[var(--kyro-primary)]"}),e&&jsxRuntime.jsx("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e})]}),(t||a)&&jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 mt-1",children:[t&&jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0",children:t}),a&&jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxRuntime.jsxs(ka__default.default.Fragment,{children:[m===0&&(t||m>0)&&jsxRuntime.jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))}),l]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3 flex-wrap shrink-0",children:[i&&jsxRuntime.jsx(Xi,{actions:i}),s&&jsxRuntime.jsx(Qi,{action:s})]})]}),(i||s)&&jsxRuntime.jsxs("div",{className:"md:hidden flex items-center gap-2 mt-3 pt-3 border-t border-[var(--kyro-border)]",children:[s&&jsxRuntime.jsx(Qi,{action:s}),i&&jsxRuntime.jsx(Xi,{actions:i})]})]})}var _c={draft:{class:"bg-gray-100 text-gray-600",label:"Draft"},published:{class:"bg-green-100 text-green-700",label:"Published"},scheduled:{class:"bg-blue-100 text-blue-700",label:"Scheduled"},archived:{class:"bg-yellow-100 text-yellow-700",label:"Archived"},active:{class:"bg-green-100 text-green-700",label:"Active"},inactive:{class:"bg-gray-100 text-gray-600",label:"Inactive"},pending:{class:"bg-yellow-100 text-yellow-700",label:"Pending"},completed:{class:"bg-green-100 text-green-700",label:"Completed"},cancelled:{class:"bg-red-100 text-red-700",label:"Cancelled"}};function Pt({variant:e,status:t,className:r="",children:o,dot:a=false}){let n=e||t||"default",s=_c[n],i=s?s.class:`kyro-badge-${n}`;return jsxRuntime.jsxs("span",{className:`kyro-badge ${i} ${r}`,children:[a&&jsxRuntime.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current mr-1.5 opacity-60"}),o||s?.label||n]})}function ms({count:e,max:t=99}){return e===0?null:jsxRuntime.jsx("span",{className:"inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 text-xs font-medium bg-gray-200 text-gray-700 rounded-full",children:e>t?`${t}+`:e})}function us({variant:e="secondary",size:t="md",loading:r=false,children:o,className:a="",disabled:n,...s}){let i="kyro-btn",l=`kyro-btn-${e}`,d=`kyro-btn-${t}`;return jsxRuntime.jsxs("button",{type:"button",className:`${i} ${l} ${d} ${a}`,disabled:n||r,...s,children:[r?jsxRuntime.jsx("span",{className:"kyro-btn-loading",children:jsxRuntime.jsx("svg",{className:"kyro-btn-spinner",viewBox:"0 0 24 24",children:jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",fill:"none",strokeDasharray:"60 30"})})}):null,jsxRuntime.jsx("span",{className:r?"kyro-btn-text-hidden":"",children:o})]})}function fn({page:e,totalPages:t,totalDocs:r,limit:o,onPageChange:a,onLimitChange:n}){return t<=1?null:jsxRuntime.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 px-4 py-3 border-t border-[var(--kyro-border)]",children:[r!==void 0&&o?jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-secondary)] font-medium",children:["Showing ",(e-1)*o+1," to ",Math.min(e*o,r)," of ",r]}):jsxRuntime.jsx("span",{}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-center",children:[n&&jsxRuntime.jsxs("select",{value:o,onChange:s=>n(Number(s.target.value)),className:"text-xs border border-[var(--kyro-border)] rounded-lg px-2 py-1 bg-[var(--kyro-bg)] text-[var(--kyro-text-secondary)]",children:[jsxRuntime.jsx("option",{value:10,children:"10/page"}),jsxRuntime.jsx("option",{value:25,children:"25/page"}),jsxRuntime.jsx("option",{value:50,children:"50/page"}),jsxRuntime.jsx("option",{value:100,children:"100/page"})]}),jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-secondary)] font-medium",children:["Page ",e," of ",t]}),jsxRuntime.jsxs("div",{className:"flex gap-1",children:[jsxRuntime.jsx(us,{variant:"ghost",size:"sm",disabled:e<=1,onClick:()=>a(e-1),children:"\u2190 Previous"}),jsxRuntime.jsx(us,{variant:"ghost",size:"sm",disabled:e>=t,onClick:()=>a(e+1),children:"Next \u2192"})]})]})]})}function uo(e,t,r){return r in t?t[r]:ys(e,t,r)}function ys(e,t,r){for(let o of e)if(o.name){if(o.type==="tabs"&&"tabs"in o){let a=t[o.name];if(a&&typeof a=="object"){if(r in a)return a[r];let n=ys(o.tabs?.flatMap(s=>s.fields||[])||[],a,r);if(n!==void 0)return n}}if((o.type==="group"||o.type==="collapsible")&&"fields"in o){let a=t[o.name];if(a&&typeof a=="object"){if(r in a)return a[r];let n=ys(o.fields||[],a,r);if(n!==void 0)return n}}}}function vs({collection:e,collectionSlug:t,initialDocs:r=[],initialTotal:o=0,onCreate:a,onEdit:n,config:s}){let i=t||e.slug,{permissions:l}=Lr(),d=l?.collections?.[i]?.create!==false,c=l?.collections?.[i]?.delete!==false,m=l?.collections?.[i]?.update!==false,u=()=>{d&&(a?a():window.location.href=`${Ye}/${i}/new`);},g=D=>{n?n(D):window.location.href=`${Ye}/${i}/${D}`;},[x,f]=ka.useState(r),[y,b]=ka.useState(o),[v,R]=ka.useState(false),[L,C]=ka.useState(1),[w,N]=ka.useState(10),[p,A]=ka.useState(new Set),[O,F]=ka.useState(""),[P,S]=ka.useState([]),{confirm:M,alert:j}=ot(),se=()=>{S([...P,{field:"",operator:"equals",value:""}]);},ie=()=>{F(""),S([]),je(null);},ue=D=>{S(P.filter((G,te)=>te!==D));},oe=(D,G)=>{S(P.map((te,sr)=>sr===D?{...te,...G}:te));},[ne,je]=ka.useState(null),[ft,B]=ka.useState(false),[K,ce]=ka.useState(false);function he(D){let G=[];for(let te of D||[])if(!(!te.name||te.hidden===true||te.admin?.hidden||te.name==="id"))if(te.type==="tabs"&&te.tabs)for(let sr of te.tabs)sr.fields&&G.push(...he(sr.fields));else (te.type==="row"||te.type==="collapsible")&&te.fields?G.push(...he(te.fields)):G.push(te);return G}let Pe=ka.useMemo(()=>he(e.fields),[e.fields]),Ce=typeof e.admin?.useAsTitle=="string"?e.admin.useAsTitle:Pe.find(D=>D.type!=="group"&&typeof D.name=="string")?.name,[I,z]=ka.useState(()=>{let D;return e.admin?.defaultColumns?D=[...e.admin?.defaultColumns||[]]:D=Pe.slice(0,4).map(G=>G.name).filter(G=>!!G),Ce&&D.includes(Ce)&&(D=[Ce,...D.filter(G=>G!==Ce)]),D.includes("updatedAt")||D.push("updatedAt"),new Set(D)}),Ve=ka.useCallback(D=>{z(G=>{let te=new Set(G);return te.has(D)?te.delete(D):te.add(D),te});},[]);function ye(D){let G=Pe.find(te=>te.name===D);return G&&G.type==="group"&&G.fields?.[0]?.name?`${D}.${G.fields[0].name}`:D}let Se=ka.useCallback(D=>{let G=ye(D);je(te=>te&&te.field===G?{field:G,direction:te.direction==="asc"?"desc":"asc"}:{field:G,direction:"asc"});},[]),lt=ka.useMemo(()=>{let D=Pe.filter(G=>!!G.name&&I.has(G.name));return I.has("status")&&D.push({name:"status",type:"select",label:"Status",options:[{value:"draft",label:"Draft"},{value:"published",label:"Published"}]}),D},[Pe,I]);function At(D){return !D.name||!Ce?false:D.name===Ce||D.type==="group"&&D.fields?.[0]?.name===Ce}function qt(D,G){return G.name?uo(e.fields,D,G.name)??null:null}let vt=ka.useCallback(async()=>{R(true);try{let D=new URLSearchParams({page:L.toString(),limit:w.toString()});O&&D.append("search",O),ne&&D.append("sort",ne.field),ne&&D.append("order",ne.direction),P.length>0&&D.append("filters",JSON.stringify(P));let G=await De(Mr(`/api/${i}?${D}`),{autoToast:!1});f(G.docs||[]),b(G.totalDocs||0);}catch(D){console.error("Failed to load docs:",D);}finally{R(false);}},[i,L,w,O,ne,P]);ka.useEffect(()=>{x.length===0&&o===0&&vt();},[]);let q=ka.useRef(true);ka.useEffect(()=>{if(q.current){q.current=false;return}vt();},[L,w,O,ne,P]);let X=()=>{p.size===x.length?A(new Set):A(new Set(x.map(D=>D.id)));},le=D=>{let G=new Set(p);G.has(D)?G.delete(D):G.add(D),A(G);},xe=()=>{M({title:"Delete Documents",message:`Are you sure you want to delete ${p.size} document(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let D of Array.from(p))await kt(`/api/${i}/${D}`);A(new Set),vt(),$.success("Documents deleted");}catch(D){console.error("Bulk delete failed:",D),$.error("Failed to delete some documents");}}});},we=D=>{M({title:"Delete Document",message:"Are you sure you want to delete this document? This cannot be undone.",variant:"danger",onConfirm:async()=>{try{await kt(`/api/${i}/${D}`),vt(),$.success("Document deleted");}catch(G){console.error("Delete failed:",G),$.error("Failed to delete document");}}});},Qe=Math.ceil(y/w),Ct=O||P.length>0||ne;return jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx(Ft,{title:e.label||i,description:e.admin?.description||`Manage your ${e.label||i}`,metadata:y>0?[jsxRuntime.jsxs("span",{className:"text-xs font-bold opacity-60",children:[y," documents"]},"count")]:void 0,action:d?{label:`Create ${e.singularLabel||e.label||i}`,onClick:u,icon:lucideReact.Plus}:void 0}),jsxRuntime.jsxs("div",{className:"surface-tile p-4 flex flex-col lg:flex-row gap-4 items-start lg:items-center",children:[jsxRuntime.jsxs("div",{className:"relative flex-1 w-full lg:max-w-md",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search...",value:O,onChange:D=>F(D.target.value),className:"w-full pl-10 pr-4 py-2.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-sm font-medium text-[var(--kyro-text-primary)] placeholder:text-[var(--kyro-text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>B(!ft),className:`flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm transition-all ${ft||P.length>0?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx(lucideReact.Filter,{className:"w-4 h-4"}),"Filters",P.length>0&&jsxRuntime.jsx("span",{className:"ml-1 px-1.5 py-0.5 bg-[var(--kyro-sidebar-text-active)] text-[var(--kyro-sidebar-active)] rounded-full text-xs",children:P.length})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>ce(!K),className:"flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-all",children:[jsxRuntime.jsx(lucideReact.Columns3,{className:"w-4 h-4"}),"Columns"]}),K&&jsxRuntime.jsxs("div",{className:"absolute right-0 top-full mt-2 w-56 surface-tile border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 overflow-hidden",children:[jsxRuntime.jsx("div",{className:"p-3 border-b border-[var(--kyro-border)]",children:jsxRuntime.jsx("span",{className:"text-xs font-bold tracking-wider text-[var(--kyro-text-secondary)]",children:"Toggle Columns"})}),jsxRuntime.jsx("div",{className:"p-2 max-h-64 overflow-y-auto",children:Pe.map(D=>D.name?jsxRuntime.jsxs("label",{className:"flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-[var(--kyro-surface-accent)] cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:I.has(D.name),onChange:()=>Ve(D.name),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"}),jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:D.label||D.name})]},D.name):null)})]})]}),Ct&&jsxRuntime.jsx("button",{type:"button",onClick:ie,className:"px-4 py-2 rounded-xl font-bold text-sm text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10 transition-all",children:"Clear All"})]})]}),ft&&jsxRuntime.jsxs("div",{className:"surface-tile p-4 border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsx("h3",{className:"font-medium text-[var(--kyro-text-primary)]",children:"Advanced Filters"}),jsxRuntime.jsxs("button",{type:"button",onClick:se,className:"flex items-center gap-2 px-3 py-1.5 text-sm font-bold text-[var(--kyro-sidebar-active)] hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4"}),"Add Filter"]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[P.map((D,G)=>jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[jsxRuntime.jsx("select",{value:D.field,onChange:te=>oe(G,{field:te.target.value}),className:"px-3 py-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm font-medium text-[var(--kyro-text-primary)]",children:Pe.map(te=>jsxRuntime.jsx("option",{value:te.name,children:te.label||te.name},te.name))}),jsxRuntime.jsxs("select",{value:D.operator,onChange:te=>oe(G,{operator:te.target.value}),className:"px-3 py-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm font-medium text-[var(--kyro-text-primary)]",children:[jsxRuntime.jsx("option",{value:"equals",children:"Equals"}),jsxRuntime.jsx("option",{value:"contains",children:"Contains"}),jsxRuntime.jsx("option",{value:"gt",children:"Greater than"}),jsxRuntime.jsx("option",{value:"lt",children:"Less than"}),jsxRuntime.jsx("option",{value:"gte",children:"Greater or equal"}),jsxRuntime.jsx("option",{value:"lte",children:"Less or equal"})]}),jsxRuntime.jsx("input",{type:"text",value:D.value,onChange:te=>oe(G,{value:te.target.value}),placeholder:"Value...",className:"flex-1 min-w-[150px] px-3 py-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm font-medium text-[var(--kyro-text-primary)]"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>ue(G),className:"p-2 text-[var(--kyro-text-muted)] hover:text-red-500 transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]},G)),P.length===0&&jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-muted)]",children:'No filters applied. Click "Add Filter" to create one.'})]})]}),p.size>0&&jsxRuntime.jsxs("div",{className:"surface-tile p-4 flex items-center justify-between border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:[p.size," selected"]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[c&&jsxRuntime.jsxs("button",{type:"button",onClick:xe,className:"flex items-center gap-2 px-4 py-2 bg-red-500 text-white rounded-lg font-bold text-sm hover:bg-red-600 transition-all",children:[jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"}),"Delete Selected"]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>A(new Set),className:"px-4 py-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] font-bold text-sm transition-all",children:"Cancel"})]})]}),jsxRuntime.jsx("div",{className:"surface-tile overflow-hidden",children:v?jsxRuntime.jsx("div",{className:"space-y-2 p-4",children:jsxRuntime.jsx(Ot,{variant:"table-row",count:8})}):x.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8",children:[jsxRuntime.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:jsxRuntime.jsx(lucideReact.Archive,{className:"w-4 h-4"})}),jsxRuntime.jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:"No documents found"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:Ct?"Try adjusting your filters or search query.":`Get started by creating your first ${(e.singularLabel||e.label||i).toLowerCase()}.`}),!Ct&&d&&jsxRuntime.jsxs("button",{type:"button",onClick:u,className:"mt-4 kyro-btn kyro-btn-md kyro-btn-primary shadow-md flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4"}),"Create"," ",String(e.singularLabel||e.label||i)]})]}):jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-left",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"text-[var(--kyro-text-secondary)] font-bold text-[10px] tracking-[0.3em] border-b border-[var(--kyro-border)] whitespace-nowrap",children:[jsxRuntime.jsx("th",{className:"px-4 py-4 w-10",children:jsxRuntime.jsx("input",{type:"checkbox",checked:p.size===x.length&&x.length>0,onChange:X,className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),lt.map(D=>jsxRuntime.jsx("th",{className:"px-4 py-4 cursor-pointer hover:text-[var(--kyro-text-primary)] transition-colors",onClick:()=>Se(D.name),children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[qc(lt,D.type)??(D.label||D.name),ne&&ne.field===D.name&&jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4"})]})},D.name)),e.timestamps?jsxRuntime.jsx("th",{className:"px-4 py-4",children:"Created"}):null,jsxRuntime.jsx("th",{className:"px-4 py-4 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:x.map(D=>jsxRuntime.jsxs("tr",{className:"hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer group",onClick:()=>g(D.id),children:[jsxRuntime.jsx("td",{className:"px-4 py-3",onClick:G=>G.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:p.has(D.id),onChange:()=>le(D.id),className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),lt.map(G=>{let te=qt(D,G),sr=G.type==="select"&&te?G.options?.find(no=>no.value===te)?.label||te:Wc(te,G.type);return jsxRuntime.jsx("td",{className:`px-4 py-3 ${At(G)?"font-medium text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)]"}`,children:sr},G.name)}),e.timestamps?jsxRuntime.jsx("td",{className:"px-4 py-3 text-sm text-[var(--kyro-text-secondary)]",children:D.createdAt?new Date(D.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"\u2014"}):null,jsxRuntime.jsx("td",{className:"px-4 py-3 text-right",onClick:G=>G.stopPropagation(),children:jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>g(D.id),className:"flex items-center gap-2 px-3 py-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg text-sm font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-all",title:m?"Edit":"View",children:jsxRuntime.jsx(lucideReact.Pencil,{className:"w-4 h-4"})}),c&&jsxRuntime.jsx("button",{type:"button",onClick:()=>we(D.id),className:"inline-flex items-center justify-center w-8 h-8 rounded-md text-[var(--kyro-text-muted)] hover:bg-red-50 hover:text-red-500 dark:hover:bg-red-500/10 transition-colors",title:"Delete",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"})})]})})]},D.id))})]})})}),jsxRuntime.jsx(fn,{page:L,totalPages:Qe,totalDocs:y,limit:w,onPageChange:C,onLimitChange:D=>{N(D),C(1);}})]})}function Wc(e,t){return e==null?"\u2014":typeof e=="boolean"?e?"Yes":"No":t==="number"||t==="price"?String(e):t==="date"||t==="datetime"?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):Array.isArray(e)?e.map(r=>r&&typeof r=="object"?r.title||r.name||r.email||r.filename||r.url||JSON.stringify(r).slice(0,30):String(r??"").slice(0,30)).filter(Boolean).join(", "):typeof e=="object"?e.title?e.title:e.name?e.name:e.email?e.email:JSON.stringify(e).slice(0,50):String(e).slice(0,60)}function qc(e,t){return t!=="tabs"?void 0:e[0]?.tabs?.[0]?.fields?.[0]?.label}var gs=(e,t)=>{let r=e?.toLowerCase()||"",o=t?.toLowerCase()||"";return r.startsWith("image/")||o.match(/\.(jpe?g|png|gif|webp|avif|svg)$/i)?"image":r.startsWith("video/")||o.match(/\.(mp4|webm|ogg|mov)$/i)?"video":r.startsWith("audio/")||o.match(/\.(mp3|wav|ogg|m4a)$/i)?"audio":r.includes("pdf")||o.endsWith(".pdf")?"pdf":o.match(/\.(doc|docx|txt|rtf|odt)$/i)?"document":o.match(/\.(xls|xlsx|csv)$/i)?"spreadsheet":o.match(/\.(zip|tar|gz|7z|rar)$/i)?"archive":"other"},al=({type:e,className:t})=>{switch(e){case "image":return jsxRuntime.jsx(lucideReact.Image,{className:t});case "video":return jsxRuntime.jsx(lucideReact.Film,{className:t});case "audio":return jsxRuntime.jsx(lucideReact.Music,{className:t});case "pdf":case "document":return jsxRuntime.jsx(lucideReact.FileText,{className:t});default:return jsxRuntime.jsx(lucideReact.File,{className:t})}};function lr({field:e,value:t,onChange:r,disabled:o}){let a=ka.useRef(null),n=ka.useRef(null),[s,i]=ka.useState(false),[l,d]=ka.useState(false),[c,m]=ka.useState(false),[u,g]=ka.useState([]),[x,f]=ka.useState([]),[y,b]=ka.useState(""),[v,R]=ka.useState(false),[L,C]=ka.useState(""),[w,N]=ka.useState(false),[p,A]=ka.useState(""),[O,F]=ka.useState(""),[P,S]=ka.useState([]),M=e?.label||e?.name||"File",j=e.maxCount??(e.hasMany?999:1),se=j>1,ie=Array.isArray(t)?t:t?[t]:[],ue=ie.length<j;ka.useEffect(()=>{(async()=>{let z=ie.filter(Se=>typeof Se=="string").map(Se=>Se),Ve=ie.filter(Se=>typeof Se=="object"&&Se!==null&&typeof Se.id=="string"&&!Se.url&&!Se.filename&&!Se.mimeType).map(Se=>Se.id),ye=[...z,...Ve];if(ye.length!==0)try{let Se=await Promise.all(ye.map(At=>De(`/api/media/${At}`))),lt=[...ie];Se.forEach(At=>{let qt=At.id,vt=lt.findIndex(X=>X===qt);if(vt!==-1){lt[vt]=At;return}let q=lt.findIndex(X=>typeof X=="object"&&X!==null&&X.id===qt);q!==-1&&(lt[q]=At);}),r(se?lt:lt[0]);}catch(Se){console.error("Failed to fetch media details:",Se);}})();},[t]),ka.useEffect(()=>{l&&(oe(),ne());},[l,y]);let oe=async()=>{try{let I=await De(Mr("/api/media/folders"));f(I.folders||[]);}catch{f([]);}},ne=async()=>{R(true);try{let I=Mr("/api/media?limit=60&sortBy=createdAt&sortDir=desc");y&&(I+="&folder="+encodeURIComponent(y));let z=await De(I);g(z.docs||[]);}catch{g([]);}finally{R(false);}},je=async I=>{i(true);try{let z=new FormData;z.append("file",I),y&&z.append("folder",y);let Ve=await ya("/api/media/upload",z),ye={id:Ve.id,filename:Ve.filename,originalName:Ve.originalName??I.name,url:Ve.url,mimeType:I.type};r(se?[...ie,ye]:ye),$.success(`Asset synchronized: ${ye.filename}`);}catch(z){console.error("Upload failed:",z),$.error(`Upload failed: ${z instanceof Error?z.message:"Unknown error"}`);}finally{i(false);}},ft=async()=>{let I=p.trim();if(I){F("");try{let z=await et("/api/media/upload",{url:I}),Ve=(()=>{try{return new URL(I).pathname.split("/").pop()||z.originalName||"url-image"}catch{return z.originalName||"url-image"}})(),ye={id:z.id,filename:z.filename,originalName:Ve,url:z.url,mimeType:z.mimeType||"image/*"};r(se?[...ie,ye]:ye),$.success(`URL asset established: ${ye.filename}`),A(""),N(!1);}catch(z){let Ve=z instanceof Error?z.message:"Invalid URL";F(Ve);}}},B=I=>({id:I.id,filename:I.filename,url:I.url,mimeType:I.mimeType}),K=I=>{se?S(z=>z.find(ye=>ye.id===I.id)?z.filter(ye=>ye.id!==I.id):[...z,I]):(r(B(I)),d(false),C(""));},ce=()=>{if(P.length>0){let I=[...ie,...P.map(B)];r(I);}S([]),d(false),C("");},he=I=>{let z=[...ie];z.splice(I,1),r(se?z:z[0]||null);},Pe=ka.useMemo(()=>u.filter(I=>!L||I.filename?.toLowerCase().includes(L.toLowerCase())||I.title?.toLowerCase().includes(L.toLowerCase())),[u,L]);if(s)return jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] p-2",children:"Uploading..."});let Ce=(I,z)=>{if(!I)return null;let Ve=gs(I.mimeType,I.filename||I.url);return jsxRuntime.jsxs("div",{className:"flex items-center gap-3 p-2.5 bg-[var(--kyro-surface-accent)] rounded-lg border border-[var(--kyro-border)] group",children:[jsxRuntime.jsx("div",{className:"w-10 h-10 rounded-md overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] flex items-center justify-center flex-shrink-0",children:Ve==="image"?jsxRuntime.jsx("img",{src:ua(I.url),alt:I.filename||"Preview",className:"w-full h-full object-cover"}):jsxRuntime.jsx(al,{type:Ve,className:"w-5 h-5 text-[var(--kyro-text-secondary)]"})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-[11px] font-medium truncate text-[var(--kyro-text-primary)]",children:I.originalName||I.filename||"Unnamed File"}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] tracking-wider font-bold",children:M})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>z!==void 0?he(z):r(null),disabled:o,className:"p-1.5 rounded-md text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] hover:bg-[var(--kyro-danger-bg)] transition-all opacity-0 group-hover:opacity-100",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]},z)};return t?jsxRuntime.jsxs("div",{className:"space-y-2",children:[se?jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[ie.map((I,z)=>Ce(I,z)),ue&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{S([]),d(true);},disabled:o,className:"flex items-center justify-center h-12 border-2 border-dashed border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-border-active)] cursor-pointer transition-colors",children:["+ Add ",M]})]}):Ce(t),jsxRuntime.jsx("input",{ref:a,type:"file",accept:"image/*",onChange:I=>{let z=I.target.files?.[0];z&&je(z);},disabled:o,className:"hidden"})]}):jsxRuntime.jsxs("div",{className:"space-y-2 relative",children:[jsxRuntime.jsx("input",{ref:a,type:"file",accept:e.allowedTypes?.join(",")||"*/*",onChange:I=>{let z=I.target.files?.[0];z&&je(z);},disabled:o,className:"hidden"}),jsxRuntime.jsxs("div",{className:"flex gap-2 flex-wrap",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a.current?.click(),disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:["+ Upload ",M]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{S([]),d(true);},disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:"Library"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>N(!w),disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:"URL"})]}),w&&jsxRuntime.jsxs("div",{className:"flex gap-2 items-center",children:[jsxRuntime.jsx("input",{ref:n,type:"url",placeholder:"https://example.com/image.jpg",value:p,onChange:I=>{A(I.target.value),F("");},onKeyDown:I=>I.key==="Enter"&&ft(),disabled:o,className:"flex-1 px-2 py-1.5 text-xs rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-primary)]"}),jsxRuntime.jsx("button",{type:"button",onClick:ft,disabled:o||!p.trim(),className:"kyro-btn kyro-btn-primary px-3 py-1.5 text-xs rounded cursor-pointer hover:opacity-90 transition-opacity disabled:opacity-50",children:"Add"}),O&&jsxRuntime.jsx("span",{className:"text-xs text-[var(--kyro-error)]",children:O})]}),l&&(c?reactDom.createPortal(jsxRuntime.jsx(ol,{isFullscreen:true,isMultiple:se,selectedItems:P,pickerSearch:L,setPickerSearch:C,folders:x,selectedFolder:y,setSelectedFolder:b,mediaLoading:v,filteredMedia:Pe,selectFromLibrary:K,onDone:ce,setIsPickerFullscreen:m,setShowPicker:d}),document.body):jsxRuntime.jsx(ol,{isFullscreen:false,isMultiple:se,selectedItems:P,pickerSearch:L,setPickerSearch:C,folders:x,selectedFolder:y,setSelectedFolder:b,mediaLoading:v,filteredMedia:Pe,selectFromLibrary:K,onDone:ce,setIsPickerFullscreen:m,setShowPicker:d}))]})}function ol({isFullscreen:e,isMultiple:t,selectedItems:r,pickerSearch:o,setPickerSearch:a,folders:n,selectedFolder:s,setSelectedFolder:i,mediaLoading:l,filteredMedia:d,selectFromLibrary:c,onDone:m,setIsPickerFullscreen:u,setShowPicker:g}){let x=f=>r.some(y=>y.id===f);return jsxRuntime.jsxs("div",{className:`${e?"fixed inset-0 z-[9999]":"relative z-[9999] w-[360px] max-h-[400px] mt-1 rounded-lg shadow-lg"} overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] flex flex-col`,children:[jsxRuntime.jsxs("div",{className:"p-2 border-b border-[var(--kyro-border)] flex flex-col gap-2",children:[jsxRuntime.jsx("input",{type:"text",placeholder:"Search media...",value:o,onChange:f=>a(f.target.value),className:"w-full px-2 py-1.5 text-xs rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-primary)]"}),n.length>0&&jsxRuntime.jsxs("div",{className:"flex gap-1 flex-wrap",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>i(""),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===""?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:"All"}),n.slice(0,6).map(f=>jsxRuntime.jsx("button",{type:"button",onClick:()=>i(f.path),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===f.path?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:f.name},f.path))]})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-2",children:l?jsxRuntime.jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsxRuntime.jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"No media found"}):jsxRuntime.jsx("div",{className:`grid gap-1 ${e?"grid-cols-[repeat(auto-fill,minmax(140px,1fr))]":"grid-cols-3"}`,children:d.map(f=>{let y=x(f.id);return jsxRuntime.jsxs("button",{type:"button",onClick:()=>c(f),className:`border rounded-md overflow-hidden cursor-pointer p-0 bg-[var(--kyro-surface)] transition-all relative group ${y?"border-[var(--kyro-primary)] ring-2 ring-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]"}`,children:[jsxRuntime.jsx("div",{className:`w-full flex items-center justify-center bg-[var(--kyro-surface-accent)] ${e?"h-[120px]":"h-[80px]"}`,children:gs(f.mimeType,f.filename)==="image"?jsxRuntime.jsx("img",{src:ua(f.thumbnailUrl||f.url),alt:f.filename,className:"w-full h-full object-cover"}):jsxRuntime.jsx(al,{type:gs(f.mimeType,f.filename),className:e?"w-10 h-10":"w-8 h-8"})}),t&&y&&jsxRuntime.jsx("div",{className:"absolute top-1 right-1 w-5 h-5 rounded-full bg-[var(--kyro-primary)] flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.Check,{className:"w-3 h-3 text-white"})})]},f.id)})})}),jsxRuntime.jsxs("div",{className:"p-2 border-t border-[var(--kyro-border)] flex justify-between items-center",children:[jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[d.length," items"]}),jsxRuntime.jsxs("div",{className:"flex gap-2 items-center",children:[t&&jsxRuntime.jsxs("button",{type:"button",onClick:m,className:"kyro-btn kyro-btn-primary px-3 py-1 text-xs font-semibold rounded cursor-pointer hover:opacity-90 transition-opacity",children:["Done",r.length>0?` (${r.length})`:""]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>u(!e),className:"p-1.5 rounded text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",title:e?"Exit fullscreen":"Fullscreen",children:e?jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"})}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(false),u(false);},className:"text-xs text-[var(--kyro-text-secondary)] bg-transparent border-none cursor-pointer hover:text-[var(--kyro-text-primary)]",children:"Close"})]})]})]})}function nt({field:e,error:t,children:r,hideLabel:o=false}){return jsxRuntime.jsxs("div",{className:"space-y-2.5 w-full group",children:[e.label&&!o&&jsxRuntime.jsx("div",{className:"flex justify-between items-end mb-1",children:jsxRuntime.jsxs("label",{className:"block text-xs font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 group-focus-within:opacity-100 group-focus-within:text-[var(--kyro-primary)] transition-all duration-300",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})}),jsxRuntime.jsx("div",{className:"relative transform transition-transform duration-200 focus-within:scale-[1.002]",children:r}),(e.admin?.description||t)&&jsxRuntime.jsxs("div",{className:"flex flex-col gap-1.5 px-1",children:[e.admin?.description&&!t&&jsxRuntime.jsx("p",{className:"text-[11px] leading-relaxed text-[var(--kyro-text-muted)] font-medium opacity-60 italic",children:e.admin.description}),t&&jsxRuntime.jsxs("p",{className:"text-[11px] leading-relaxed text-[var(--kyro-error)] font-bold flex items-center gap-2 animate-in fade-in slide-in-from-top-1 duration-300",children:[jsxRuntime.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-error)] shadow-[0_0_8px_var(--kyro-error)]"}),t]})]})]})}function dr({open:e,onClose:t,title:r,children:o,width:a="md",showOverlay:n=false,accentClass:s}){let i=ka.useRef(null),[l,d]=ka.useState(false);ka.useEffect(()=>{d(true);},[]),ka.useEffect(()=>{let m=u=>{u.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",m),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",m),document.body.style.overflow="";}},[e,t]);let c={sm:"w-full sm:w-[320px]",md:"w-full sm:w-[400px]",lg:"w-full sm:w-[550px]",xl:"w-full sm:w-[700px]"};return !e||!l?null:reactDom.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[n&&jsxRuntime.jsx("div",{className:"fixed inset-0 z-[99998] bg-black/50 backdrop-blur-sm",onClick:t}),jsxRuntime.jsxs("div",{ref:i,"data-kyro-slide-panel":"true","data-kyro-slide-width":a,className:`fixed right-0 top-0 bottom-0 z-[99999] ${c[a]} bg-[var(--kyro-surface)] ${s?`border-l-2 ${s}`:"border-l border-[var(--kyro-border)]"} shadow-2xl flex flex-col animate-slideIn`,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxRuntime.jsx("h2",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:r}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"p-1.5 text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o})]}),jsxRuntime.jsx("style",{children:`
2
2
  @keyframes slideIn {
3
3
  from { transform: translateX(100%); }
4
4
  to { transform: translateX(0); }
@@ -6,24 +6,24 @@
6
6
  .animate-slideIn {
7
7
  animation: slideIn 300ms ease-out;
8
8
  }
9
- `})]}),document.body)}function Ur({children:e}){return jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:e})}function zr({children:e}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-3 mt-6",children:e})}function Ot({open:e,onClose:t,title:r,children:o,footer:a,size:n="md",variant:s="default"}){if(ka.useEffect(()=>{let d=c=>{c.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",d),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",d),document.body.style.overflow="";}},[e,t]),!e)return null;let i={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",full:"w-full h-full max-w-none rounded-none border-0"},l=s==="lightbox";return reactDom.createPortal(jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",children:[jsxRuntime.jsx("div",{className:`absolute inset-0 transition-all duration-500 ${l?"bg-black/95 backdrop-blur-none":"bg-[var(--kyro-black)]/40 backdrop-blur-md"}`,onClick:t}),jsxRuntime.jsxs("div",{className:`relative ${i[n]} ${l?"bg-transparent text-white":"bg-[var(--kyro-surface)]"} ${!l&&n!=="full"?"rounded-[var(--kyro-radius-lg)]":""} shadow-2xl animate-in fade-in zoom-in-95 duration-300 ${l?"":"border"} ${s==="danger"?"border-red-500/30":"border-[var(--kyro-border)]"} flex flex-col overflow-hidden`,children:[!l&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-8 py-6 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/50 backdrop-blur-md",children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold text-[var(--kyro-text-primary)]",children:r}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"p-2 text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] rounded-xl hover:bg-[var(--kyro-surface)] transition-all duration-200",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("div",{className:`flex-1 overflow-auto ${l?"":"px-8 py-8"}`,children:o}),a&&!l&&jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-3 px-8 py-6 border-t border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/50",children:a})]})]}),document.body)}function ks({open:e,onClose:t,onConfirm:r,title:o,message:a,confirmLabel:n="Confirm",cancelLabel:s="Cancel",variant:i="default",loading:l=false}){return jsxRuntime.jsx(Ot,{open:e,onClose:t,title:o,size:"sm",footer:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:t,disabled:l,className:"kyro-btn kyro-btn-md kyro-btn-secondary",children:s}),jsxRuntime.jsx("button",{type:"button",onClick:r,disabled:l,className:`kyro-btn kyro-btn-md ${i==="danger"?"kyro-btn-danger":"kyro-btn-primary"}`,children:l?"Loading...":n})]}),children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)]",children:a})})}function il({open:e,onClose:t,onSubmit:r,title:o,placeholder:a="",defaultValue:n=""}){let[s,i]=ka.useState(n),l=d=>{d.preventDefault(),s.trim()&&(r(s.trim()),i(""),t());};return e?reactDom.createPortal(jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),jsxRuntime.jsxs("div",{className:"relative w-full max-w-lg mx-4 bg-[var(--kyro-surface)] rounded-lg shadow-2xl animate-in fade-in zoom-in-95 duration-200 border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-[var(--kyro-text-primary)]",children:o}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"p-1 text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] rounded-lg hover:bg-[var(--kyro-surface-accent)] transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("form",{onSubmit:l,children:[jsxRuntime.jsx("div",{className:"px-6 py-4",children:jsxRuntime.jsx("input",{type:"text",value:s,onChange:d=>i(d.target.value),placeholder:a,autoFocus:true,className:"w-full px-3 py-2 border border-[var(--kyro-input-border)] rounded-lg bg-[var(--kyro-input-bg)] text-[var(--kyro-text-primary)] placeholder-[var(--kyro-text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent"})}),jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] rounded-b-lg",children:[jsxRuntime.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 rounded-lg font-medium text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"submit",disabled:!s.trim(),className:"px-4 py-2 rounded-lg font-medium text-sm bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] hover:opacity-90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"Confirm"})]})]})]})]}),document.body):null}function fo(e){if(typeof e!="string"||!e)return "";if(typeof window>"u"||e.startsWith("http")||e.startsWith("blob:"))return e;let t=e.replace(/^\/+/,"/");return `${window.location.origin}${t}`}function bn(e){if(e===0)return "0 B";let t=1024,r=["B","KB","MB","GB"],o=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,o)).toFixed(1))+" "+r[o]}function fp(e){return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function vp(e){return e.startsWith("image/")?"image":e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":e.includes("zip")||e.includes("tar")||e.includes("archive")?"archive":e.includes("pdf")||e.includes("doc")||e.includes("text")?"document":"other"}function xn({onSelect:e,multiple:t=true,pickerMode:r=false}){let{permissions:o}=Mr(),a=o?.media?.create!==false,n=o?.media?.delete!==false,s=o?.media?.update!==false,[i,l]=ka.useState([]),[d,c]=ka.useState(true),[m,y]=ka.useState([]),[g,x]=ka.useState(""),[f,u]=ka.useState(""),[b,v]=ka.useState("all"),[R,L]=ka.useState("grid"),[C,w]=ka.useState(null),[N,p]=ka.useState(false),[A,O]=ka.useState(false),[F,P]=ka.useState(false),[S,M]=ka.useState({}),[j,se]=ka.useState(false),[ie,ue]=ka.useState(false),[oe,ne]=ka.useState(null),[je,ft]=ka.useState(false),[B,K]=ka.useState(false),[ce,he]=ka.useState(1),[De,Ce]=ka.useState(0),[I,z]=ka.useState(1),Ke=40,[ye,Se]=ka.useState(new Set),{confirm:dt,alert:Tt}=at(),[Wt,vt]=ka.useState(false),q=ka.useRef(null),[X,le]=ka.useState(),xe=ka.useRef(null),we=ka.useCallback(async()=>{c(true);try{let h=new URLSearchParams({page:ce.toString(),limit:Ke.toString()});g&&h.append("folder",g),f&&h.append("search",f),b!=="all"&&h.append("type",b);let re=await Be($r(`/api/media?${h}`));l((re.docs||[]).map(Pe=>({...Pe,type:vp(Pe.mimeType)}))),Ce(re.totalDocs||0),z(re.totalPages||1);}catch(h){console.error("Failed to load media:",h);}finally{c(false);}},[ce,g,f,b]),Qe=ka.useCallback(async()=>{try{let h=await Be($r("/api/media/folders"));y(Array.isArray(h)?h:h.folders||[]);}catch(h){console.error("Failed to load folders:",h);}},[]),wt=ka.useCallback(async()=>{try{let re=!!(await Be("/api/globals/storage-settings"))?.data?.provider;ne(re);}catch{ne(false);}},[]);ka.useEffect(()=>{r||wt();},[wt,r]),ka.useEffect(()=>{r||oe===false&&!je&&(ft(true),K(true));},[r,oe,je]),ka.useEffect(()=>{we();},[we]),ka.useEffect(()=>{Qe();},[Qe]),ka.useEffect(()=>{if(r)return;let h=re=>{let Pe=re.clipboardData?.files;Pe&&Pe.length>0&&D(Pe);};return window.addEventListener("paste",h),()=>window.removeEventListener("paste",h)},[r,g,oe]);let D=async h=>{if(!oe){K(true);return}P(true);let re=0,Pe=0;for(let qt=0;qt<h.length;qt++){let Lt=h[qt];try{let vr=new FormData;vr.append("file",Lt),g&&vr.append("folder",g),await ya("/api/media/upload",vr,ir=>{M(es=>({...es,[Lt.name]:ir}));}),re++;}catch(vr){console.error(`Upload failed for ${Lt.name}:`,vr),Pe++;}}P(false),M({}),we(),Qe(),Pe>0&&$.error(`${Pe} file(s) failed to upload`),re>0&&$.success(`${re} file(s) uploaded successfully`);},G=()=>{dt({title:"Delete Media",message:`Are you sure you want to delete ${ye.size} item(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let h of Array.from(ye))await bt(`/api/media/${h}`);Se(new Set),we(),$.success(`${ye.size} item(s) deleted`);}catch(h){console.error("Bulk delete failed:",h),$.error("Failed to delete some items");}}});},te=(h,re)=>{re.stopPropagation();let Pe=new Set(ye);Pe.has(h)?Pe.delete(h):(t||Pe.clear(),Pe.add(h)),Se(Pe);},sr=async h=>{try{await et("/api/media/folders",{name:h}),Qe(),se(!1),$.success(`Folder "${h}" created`);}catch(re){console.error("Failed to create folder:",re),$.error("Failed to create folder");}},so=h=>{dt({title:"Delete Folder",message:`Are you sure you want to delete the folder "${h}"? All media in this folder will be moved to the root.`,variant:"danger",confirmLabel:"Delete Folder",onConfirm:async()=>{try{await bt(`/api/media/folders?path=${encodeURIComponent(h)}`),g===h&&x(""),Qe(),we(),$.success(`Folder "${h}" deleted`);}catch(re){console.error("Failed to delete folder:",re),$.error("Failed to delete folder");}}});},da=async(h,re)=>{try{let Pe=await Xt(`/api/media/${h}`,re);l(qt=>qt.map(Lt=>Lt.id===h?Pe.doc:Lt)),C?.id===h&&w(Pe.doc),$.success("Metadata updated");}catch(Pe){console.error("Failed to update metadata:",Pe),$.error("Failed to update metadata");}},Ka=h=>{let{width:re,height:Pe}=h.currentTarget,qt=pp.centerCrop(pp.makeAspectCrop({unit:"%",width:90},1,re,Pe),re,Pe);le(qt);},Zn=async()=>{if(!(!X||!xe.current||!C)){P(true);try{let h=pp.convertToPixelCrop(X,xe.current.width,xe.current.height),re=document.createElement("canvas"),Pe=xe.current.naturalWidth/xe.current.width,qt=xe.current.naturalHeight/xe.current.height;re.width=h.width,re.height=h.height;let Lt=re.getContext("2d");if(Lt){Lt.drawImage(xe.current,h.x*Pe,h.y*qt,h.width*Pe,h.height*qt,0,0,h.width,h.height);let vr=await new Promise(ir=>re.toBlob(ir,C.mimeType));if(vr){let ir=new FormData;ir.append("file",vr,`cropped-${C.filename}`),g&&ir.append("folder",g),await ya("/api/media",ir),we(),O(!1),$.success("Cropped image saved");}}}catch(h){console.error("Crop failed:",h),$.error("Crop failed");}finally{P(false);}}},gt=ka.useMemo(()=>i.reduce((h,re)=>(h.totalSize+=re.fileSize||0,h),{totalSize:0}),[i]);return jsxRuntime.jsxs("div",{className:`flex flex-col h-full bg-[var(--kyro-bg)] transition-all duration-300 ${Wt?"ring-4 ring-[var(--kyro-sidebar-active)] ring-inset":""}`,...r?{}:{onDragOver:h=>{h.preventDefault(),vt(true);},onDragLeave:()=>vt(false),onDrop:h=>{h.preventDefault(),vt(false),h.dataTransfer.files&&D(h.dataTransfer.files);}},children:[jsxRuntime.jsxs("div",{className:`flex flex-col lg:flex-row lg:items-center justify-between gap-6 border-b border-[var(--kyro-border)] backdrop-blur-md sticky top-0 ${r?"p-2":"p-6 rounded-xl surface-tile"}`,children:[!r&&jsxRuntime.jsx("div",{className:"flex items-center gap-4",children:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:"Media Library"}),jsxRuntime.jsx("div",{className:"flex items-center gap-3 mt-1",children:jsxRuntime.jsxs("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50",children:[De," Items \xB7 ",bn(gt.totalSize)]})})]})}),jsxRuntime.jsxs("div",{className:`flex items-center gap-3 flex-wrap lg:flex-nowrap ${r?"w-full":""}`,children:[jsxRuntime.jsxs("div",{className:"relative group flex-1 min-w-[200px]",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search assets...",value:f,onChange:h=>u(h.target.value),className:"w-full pl-11 pr-4 py-2.5 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] transition-all text-xs font-bold"})]}),!r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{onClick:()=>L("grid"),className:`p-2 rounded-lg transition-all ${R==="grid"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsxRuntime.jsx(lucideReact.Grid3X3,{className:"w-4 h-4"})}),jsxRuntime.jsx("button",{onClick:()=>L("list"),className:`p-2 rounded-lg transition-all ${R==="list"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsxRuntime.jsx(lucideReact.File,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("button",{onClick:()=>ue(true),className:"md:hidden p-2 rounded-xl bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-colors",children:jsxRuntime.jsx(lucideReact.Filter,{className:"w-4 h-4"})})]}),a&&jsxRuntime.jsxs("button",{onClick:()=>q.current?.click(),className:"flex items-center gap-2 px-6 py-2.5 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs shadow-lg active:scale-95 transition-all",children:[jsxRuntime.jsx(lucideReact.Maximize2,{className:"w-4 h-4"}),"Upload"]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[!r&&jsxRuntime.jsx("div",{className:"w-64 border-r border-[var(--kyro-border)] surface-tile mt-6 overflow-y-auto hidden md:block",children:jsxRuntime.jsxs("div",{className:"p-6 space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsxRuntime.jsx("div",{className:"space-y-1",children:["all","image","video","audio","document","archive"].map(h=>jsxRuntime.jsxs("button",{onClick:()=>v(h),className:`w-full flex items-center gap-3 px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all ${b===h?"text-[var(--kyro-text-primary)] bg-[var(--kyro-surface-accent)]":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]/50"}`,children:[jsxRuntime.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${b===h?"bg-[var(--kyro-primary)]":"bg-transparent border border-current opacity-30"}`}),h]},h))})]}),jsxRuntime.jsxs("div",{className:"pt-6 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),jsxRuntime.jsx("button",{onClick:()=>se(true),className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors text-[var(--kyro-text-primary)]",children:jsxRuntime.jsx(lucideReact.FolderPlus,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("nav",{className:"space-y-1",children:[jsxRuntime.jsxs("button",{onClick:()=>x(""),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===""?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx(lucideReact.FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(h=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>x(h),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsxRuntime.jsx(lucideReact.Folder,{fill:g===h?"currentColor":"none"})}),h]}),jsxRuntime.jsx("button",{onClick:re=>{re.stopPropagation(),so(h);},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-red-500 opacity-0 group-hover:opacity-100 transition-all hover:bg-red-50 rounded-lg",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})})]},h))]})]})]})}),jsxRuntime.jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-[var(--kyro-bg)]",children:[jsxRuntime.jsx("div",{className:`flex-1 overflow-y-auto custom-scrollbar ${r?"px-2 py-4":"py-4 px-2 md:py-8 md:px-4"}`,children:d?jsxRuntime.jsx("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5",children:jsxRuntime.jsx(Et,{variant:"media-card",count:12})}):i.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center py-32 text-center",children:[jsxRuntime.jsx("div",{className:"w-24 h-24 rounded-[2rem] bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-8 rotate-12 group-hover:rotate-0 transition-transform duration-500",children:jsxRuntime.jsx(lucideReact.Grid3X3,{className:"w-10 h-10 text-[var(--kyro-text-muted)] opacity-30"})}),jsxRuntime.jsx("h3",{className:"text-xl font-bold text-[var(--kyro-text-primary)] tracking-tight",children:"No assets found"}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] mt-2 max-w-xs mx-auto text-sm font-medium leading-relaxed",children:"Upload your first file or create a folder to organize your media assets."}),!r&&a&&jsxRuntime.jsx("button",{onClick:()=>q.current?.click(),className:"mt-8 px-8 py-3 bg-[var(--kyro-text-primary)] text-[var(--kyro-bg)] rounded-2xl font-bold text-xs hover:scale-105 transition-all shadow-xl",children:"Start Uploading"})]}):R==="grid"?jsxRuntime.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-1",children:i.map((h,re)=>jsxRuntime.jsxs("div",{className:`group relative aspect-square rounded-lg overflow-hidden bg-[var(--kyro-surface-accent)] border-2 transition-all duration-300 cursor-pointer ${ye.has(h.id)?"border-[var(--kyro-primary)]":"border-transparent hover:border-[var(--kyro-border-strong)] hover:shadow-2xl hover:-translate-y-1"}`,onClick:()=>w(h),onContextMenu:Pe=>{Pe.preventDefault(),te(h.id,Pe);},children:[h.type==="image"?jsxRuntime.jsx("img",{src:h.url,alt:h.title,className:"w-full h-full object-cover transition-transform duration-700 group-hover:scale-110",loading:"lazy"}):jsxRuntime.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-6 gap-4",children:[jsxRuntime.jsx("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface)] shadow-inner text-[var(--kyro-text-secondary)] group-hover:scale-110 transition-transform duration-500",children:h.type==="video"?jsxRuntime.jsx(lucideReact.Film,{className:"w-8 h-8"}):h.type==="audio"?jsxRuntime.jsx(lucideReact.Music,{className:"w-8 h-8"}):h.type==="document"?jsxRuntime.jsx(lucideReact.FileText,{className:"w-8 h-8"}):h.type==="archive"?jsxRuntime.jsx(lucideReact.Archive,{className:"w-8 h-8"}):jsxRuntime.jsx(lucideReact.File,{className:"w-8 h-8"})}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 text-center px-4 line-clamp-2",children:h.title})]}),jsxRuntime.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-col justify-end p-4",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-white font-bold text-[10px] truncate max-w-[120px]",children:h.filename}),jsxRuntime.jsx("div",{className:"flex gap-1",children:jsxRuntime.jsx("button",{onClick:Pe=>te(h.id,Pe),className:`kyro-btn-primary p-1.5 rounded-lg transition-all ${ye.has(h.id)?"":"bg-white/10 text-white hover:bg-white/20"}`,children:jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})})})]})}),ye.has(h.id)&&jsxRuntime.jsx("div",{className:"absolute top-3 left-3 w-6 h-6 rounded-lg bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center shadow-lg border-2 border-white/20 animate-in zoom-in duration-300",children:jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})})]},h.id))}):jsxRuntime.jsx("div",{className:"surface-tile overflow-hidden animate-in fade-in duration-500",children:jsxRuntime.jsxs("table",{className:"w-full text-left",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsx("th",{className:"px-6 py-4 w-12",children:jsxRuntime.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]",checked:ye.size===i.length,onChange:h=>{h.target.checked?Se(new Set(i.map(re=>re.id))):Se(new Set);}})}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Asset"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Type"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Size"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Date"}),jsxRuntime.jsx("th",{className:"px-6 py-4 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:i.map(h=>jsxRuntime.jsxs("tr",{className:`group hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer ${ye.has(h.id)?"bg-[var(--kyro-surface-accent)]":""}`,onClick:()=>w(h),children:[jsxRuntime.jsx("td",{className:"px-6 py-4",onClick:re=>re.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:ye.has(h.id),onChange:re=>te(h.id,re),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]"})}),jsxRuntime.jsx("td",{className:"px-6 py-4",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 rounded-xl bg-[var(--kyro-bg)] overflow-hidden border border-[var(--kyro-border)] flex-shrink-0 flex items-center justify-center",children:h.type==="image"?jsxRuntime.jsx("img",{src:h.url,alt:"",className:"w-full h-full object-cover"}):jsxRuntime.jsx(lucideReact.File,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50"})}),jsxRuntime.jsxs("div",{className:"flex flex-col min-w-0",children:[jsxRuntime.jsx("span",{className:"font-bold text-xs text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:h.title||h.filename}),jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:h.filename})]})]})}),jsxRuntime.jsx("td",{className:"px-6 py-4",children:jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[9px]",children:h.mimeType})}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:bn(h.fileSize)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:fp(h.createdAt)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-right",children:jsxRuntime.jsx("button",{onClick:re=>{re.stopPropagation(),te(h.id,re);},className:`kyro-btn-primary p-2 rounded-lg transition-all ${ye.has(h.id)?"":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] opacity-0 group-hover:opacity-100"}`,children:jsxRuntime.jsx(lucideReact.Grid3X3,{className:"w-4 h-4"})})})]},h.id))})]})})}),jsxRuntime.jsx(fn,{page:ce,totalPages:I,onPageChange:he})]})]}),!r&&F&&jsxRuntime.jsx("div",{className:"fixed bottom-12 left-1/2 -translate-x-1/2 z-[60] w-full max-w-lg",children:jsxRuntime.jsxs("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-[2rem] shadow-2xl p-6 ring-1 ring-white/10 animate-in slide-in-from-bottom-12 duration-700",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center animate-pulse",children:jsxRuntime.jsx(Ar,{})}),jsxRuntime.jsx("span",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Uploading Files"})]}),jsxRuntime.jsxs("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-50",children:[Object.keys(S).length," Total"]})]}),jsxRuntime.jsx("div",{className:"space-y-4 max-h-[160px] overflow-y-auto pr-2 custom-scrollbar",children:Object.entries(S).map(([h,re])=>jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex justify-between text-[10px] font-bold",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:h}),jsxRuntime.jsxs("span",{className:"text-[var(--kyro-primary)]",children:[re,"%"]})]}),jsxRuntime.jsx("div",{className:"h-1.5 w-full bg-[var(--kyro-surface-accent)] rounded-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full bg-[var(--kyro-primary)] transition-all duration-300 rounded-full",style:{width:`${re}%`}})})]},h))})]})}),ye.size>0&&jsxRuntime.jsxs("div",{className:"fixed bottom-12 left-1/2 -translate-x-1/2 z-[60] bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-full shadow-2xl px-2 py-2 flex items-center gap-12 animate-in slide-in-from-bottom-12 duration-700 ring-1 ring-white/10 backdrop-blur-xl",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-5 border-r border-[var(--kyro-border)] ",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 rounded-full bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center text-lg font-bold shadow-inner",children:ye.size}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-[11px] font-bold tracking-[0.2em] text-[var(--kyro-text-primary)]",children:"Selected"}),jsxRuntime.jsx("button",{onClick:()=>Se(new Set),className:"text-[10px] font-bold text-[var(--kyro-primary)] hover:underline opacity-80",children:"Clear all"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[e&&jsxRuntime.jsx("button",{onClick:()=>{let h=i.filter(re=>ye.has(re.id));e(h);},className:"px-8 py-3 bg-[var(--kyro-text-primary)] text-[var(--kyro-bg)] rounded-full font-bold text-xs hover:scale-105 transition-all shadow-xl",children:"Confirm Selection"}),!r&&n&&jsxRuntime.jsx("button",{onClick:G,className:"p-3 bg-red-500/10 text-red-500 hover:bg-red-500 hover:text-white rounded-full transition-all active:scale-90",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-5 h-5"})})]})]}),ie&&!r&&jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[70] md:hidden",children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>ue(false)}),jsxRuntime.jsxs("div",{className:"fixed bottom-0 left-0 right-0 bg-[var(--kyro-surface)] rounded-t-3xl shadow-2xl max-h-[70vh] overflow-y-auto animate-in slide-in-from-bottom-12 duration-300",children:[jsxRuntime.jsxs("div",{className:"sticky top-0 bg-[var(--kyro-surface)] z-10 flex items-center justify-between p-6 pb-4 border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsx("h3",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Filters"}),jsxRuntime.jsx("button",{onClick:()=>ue(false),className:"p-2 rounded-xl hover:bg-[var(--kyro-surface-accent)] transition-colors text-[var(--kyro-text-muted)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("div",{className:"p-6 space-y-8",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsxRuntime.jsx("div",{className:"flex flex-wrap gap-2",children:["all","image","video","audio","document","archive"].map(h=>jsxRuntime.jsx("button",{onClick:()=>{v(h),ue(false);},className:`px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all border ${b===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] border-transparent":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] border-[var(--kyro-border)] hover:border-[var(--kyro-text-muted)]"}`,children:h},h))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),jsxRuntime.jsx("button",{onClick:()=>{se(true),ue(false);},className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors text-[var(--kyro-text-primary)]",children:jsxRuntime.jsx(lucideReact.FolderPlus,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("nav",{className:"space-y-1",children:[jsxRuntime.jsxs("button",{onClick:()=>{x(""),ue(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===""?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx(lucideReact.FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(h=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>{x(h),ue(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsxRuntime.jsx(lucideReact.Folder,{fill:g===h?"currentColor":"none"})}),h]}),jsxRuntime.jsx("button",{onClick:re=>{re.stopPropagation(),so(h),ue(false);},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-red-500 opacity-0 group-hover:opacity-100 transition-all hover:bg-red-50 rounded-lg",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})})]},h))]})]})]})]})]}),jsxRuntime.jsx(dr,{open:!!C,onClose:()=>w(null),title:"Asset Details",subtitle:C?.filename,children:C&&jsxRuntime.jsxs("div",{className:"flex flex-col h-full",children:[jsxRuntime.jsxs("div",{className:"aspect-video w-full rounded-2xl bg-[var(--kyro-bg)] border border-[var(--kyro-border)] overflow-hidden relative group",children:[C.type==="image"?jsxRuntime.jsx("img",{src:fo(C.url),alt:"",className:"w-full h-full object-contain p-4"}):C.type==="video"?jsxRuntime.jsx("video",{src:fo(C.url),controls:true,className:"w-full h-full"}):jsxRuntime.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-12 gap-6",children:[jsxRuntime.jsx("div",{className:"w-20 h-20 rounded-[2rem] bg-[var(--kyro-surface-accent)] flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.File,{className:"w-10 h-10 text-[var(--kyro-text-secondary)]"})}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-xs font-bold",children:C.mimeType})]}),jsxRuntime.jsx("div",{className:"absolute top-4 right-4 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:jsxRuntime.jsx("button",{onClick:()=>p(true),className:"p-2.5 bg-black/50 backdrop-blur-md text-white rounded-xl hover:bg-black/70 transition-all",children:jsxRuntime.jsx(lucideReact.Maximize2,{className:"w-4 h-4"})})})]}),jsxRuntime.jsxs("div",{className:"mt-8 space-y-8 flex-1",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"Dimensions"}),jsxRuntime.jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:C.type==="image"?"Original Resolution":"N/A"})]}),jsxRuntime.jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"File Size"}),jsxRuntime.jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:bn(C.fileSize)})]})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Public Link"}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx("input",{type:"text",readOnly:true,value:fo(C.url),className:"flex-1 px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl text-[10px] font-bold font-mono focus:outline-none"}),jsxRuntime.jsx("button",{onClick:()=>{navigator.clipboard.writeText(fo(C.url)),$.success("URL copied to clipboard");},className:"p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] border border-[var(--kyro-border)] rounded-xl transition-all",children:jsxRuntime.jsx(lucideReact.Link,{className:"w-4 h-4 text-[var(--kyro-text-primary)]"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Alt Text"}),jsxRuntime.jsx("textarea",{value:C.alt||"",onChange:h=>da(C.id,{alt:h.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-lg text-xs font-bold transition-all resize-none min-h-[80px] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Describe this asset..."})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Caption"}),jsxRuntime.jsx("textarea",{value:C.caption||"",onChange:h=>da(C.id,{caption:h.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-lg text-xs font-bold transition-all resize-none min-h-[80px] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Add a caption..."})]})]})]})]}),!r&&jsxRuntime.jsxs("div",{className:"pt-8 border-t border-[var(--kyro-border)] mt-8 flex gap-3 pb-8",children:[jsxRuntime.jsxs("button",{onClick:()=>{let h=document.createElement("a");h.href=fo(C.url),h.download=C.filename,h.click();},className:"flex-1 flex items-center justify-center gap-2 px-6 py-3 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs shadow-lg hover:opacity-90 transition-all",children:[jsxRuntime.jsx(lucideReact.Download,{className:"w-4 h-4"}),"Download"]}),C.type==="image"&&s&&jsxRuntime.jsx("button",{onClick:()=>O(true),className:"p-3 border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:jsxRuntime.jsx(lucideReact.Crop,{className:"w-4 h-4"})}),n&&jsxRuntime.jsx("button",{onClick:()=>{dt({title:"Delete Asset",message:`Are you sure you want to delete ${C.filename}? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await bt(`/api/media/${C.id}`),w(null),we();}catch(h){console.error("Delete failed:",h),$.error("Failed to delete asset");}}});},className:"p-3 border border-red-100 text-red-500 rounded-xl hover:bg-red-50 transition-all",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"})})]})]})}),N&&C&&jsxRuntime.jsxs(Ot,{open:N,onClose:()=>p(false),title:"",size:"full",variant:"lightbox",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-6",children:[jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-white font-bold text-lg tracking-tight",children:C.filename}),jsxRuntime.jsxs("span",{className:"text-white/40 text-[10px] font-bold tracking-widest mt-1",children:[bn(C.fileSize)," \xB7 ",C.mimeType]})]}),jsxRuntime.jsx("button",{onClick:()=>p(false),className:"p-3 bg-white/10 hover:bg-white/20 text-white rounded-2xl transition-all active:scale-90",children:jsxRuntime.jsx(lucideReact.X,{className:"w-6 h-6"})})]}),jsxRuntime.jsx("div",{className:"flex-1 w-full flex items-center justify-center p-12",children:C.type==="image"?jsxRuntime.jsx("img",{src:fo(C.url),alt:"",className:"max-h-full max-w-full object-contain shadow-2xl rounded-lg animate-in zoom-in-95 duration-500"}):C.type==="video"?jsxRuntime.jsx("video",{src:fo(C.url),controls:true,autoPlay:true,className:"max-h-full max-w-full rounded-lg shadow-2xl"}):jsxRuntime.jsxs("div",{className:"text-white text-center",children:[jsxRuntime.jsx(lucideReact.File,{className:"w-24 h-24 mx-auto mb-6 opacity-20"}),jsxRuntime.jsx("p",{className:"text-xl font-bold opacity-50",children:"Preview not available for this file type"})]})})]}),!r&&A&&C&&jsxRuntime.jsx(Ot,{open:A,onClose:()=>O(false),title:"",size:"full",variant:"lightbox",children:jsxRuntime.jsxs("div",{className:"flex flex-col h-full p-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-8",children:[jsxRuntime.jsx("h3",{className:"text-white font-bold text-2xl tracking-tighter",children:"Crop Image"}),jsxRuntime.jsxs("div",{className:"flex gap-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>O(false),className:"px-4 py-2 border border-white/20 text-white/80 hover:bg-white/10 rounded-lg font-bold text-sm transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",disabled:F,onClick:Zn,className:"px-4 py-2 bg-[var(--kyro-sidebar-active)] hover:opacity-90 text-[var(--kyro-sidebar-text-active)] rounded-lg font-bold text-sm transition-colors",children:F?"Saving...":"Save Crop"})]})]}),jsxRuntime.jsx("div",{className:"flex-1 w-full flex items-center justify-center overflow-auto",children:jsxRuntime.jsx(pp__default.default,{crop:X,onChange:h=>le(h),children:jsxRuntime.jsx("img",{ref:xe,src:C.url,alt:"Crop preview",className:"max-h-[70vh] object-contain",onLoad:Ka})})})]})}),!r&&jsxRuntime.jsx(il,{open:j,onClose:()=>se(false),onSubmit:sr,title:"Create New Folder",placeholder:"Folder name"}),!r&&jsxRuntime.jsx(Ot,{open:B,onClose:()=>K(false),title:"Storage Not Configured",size:"md",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-[var(--kyro-sidebar-active)] flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.Server,{className:"w-8 h-8 text-[var(--kyro-sidebar-text-active)]"})}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] mb-6 text-sm",children:"Before uploading media, you need to configure your storage settings. Choose where files should be stored and how URLs are generated."}),jsxRuntime.jsxs("div",{className:"flex gap-3",children:[jsxRuntime.jsx("a",{href:"/settings/storage-settings",className:"flex-1 px-4 py-3 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-center hover:opacity-90 transition-colors",children:"Configure Storage"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{et("/api/globals/storage-settings",{provider:"local",local:{uploadDir:"./public/uploads",baseUrl:"/uploads"}}).then(()=>{K(false),ne(true),window.location.reload();}).catch(()=>{$.error("Failed to configure storage");});},className:"flex-1 px-4 py-3 border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded-xl font-bold hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Use Defaults"})]})]})}),!r&&jsxRuntime.jsx("input",{type:"file",ref:q,onChange:h=>{h.target.files&&D(h.target.files);},multiple:true,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.txt,.zip,.rar,.tar"})]})}var Gp=[{name:"Default",value:"inherit"},{name:"Red",value:"#ef4444"},{name:"Orange",value:"#f97316"},{name:"Amber",value:"#f59e0b"},{name:"Emerald",value:"#10b981"},{name:"Blue",value:"#3b82f6"},{name:"Indigo",value:"#6366f1"},{name:"Violet",value:"#8b5cf6"},{name:"Rose",value:"#f43f5e"},{name:"Slate",value:"#64748b"}],bl=({editor:e,isExpanded:t,setIsExpanded:r,onOpenMediaPicker:o})=>{let[a,n]=ka.useState(null),s=ka.useRef(null);if(ka.useEffect(()=>{function b(v){s.current&&!s.current.contains(v.target)&&n(null);}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]),!e)return null;let i=()=>{o();},l=()=>{let b=e.getAttributes("link").href,v=window.prompt("URL",b);if(v!==null){if(v===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:v}).run();}},d=b=>{b==="inherit"?e.chain().focus().unsetColor().run():e.chain().focus().setColor(b).run(),n(null);},c=b=>{n(a===b?null:b);},m=()=>e.isActive("heading",{level:1})?"Heading 1":e.isActive("heading",{level:2})?"Heading 2":e.isActive("heading",{level:3})?"Heading 3":e.isActive("heading",{level:4})?"Heading 4":"Normal Text",y=()=>e.isActive({textAlign:"center"})?jsxRuntime.jsx(lucideReact.AlignCenter,{size:12}):e.isActive({textAlign:"right"})?jsxRuntime.jsx(lucideReact.AlignRight,{size:12}):jsxRuntime.jsx(lucideReact.AlignLeft,{size:12}),g=()=>e.isActive("orderedList")?jsxRuntime.jsx(lucideReact.ListOrdered,{size:12}):e.isActive("taskList")?jsxRuntime.jsx(lucideReact.CheckSquare,{size:12}):jsxRuntime.jsx(lucideReact.List,{size:12}),x=()=>e.isActive("codeBlock")?jsxRuntime.jsx(lucideReact.Terminal,{size:12}):jsxRuntime.jsx(lucideReact.Quote,{size:12}),f=({onClick:b,isActive:v=false,disabled:R=false,children:L,title:C})=>jsxRuntime.jsx("button",{type:"button",onClick:b,disabled:R,title:C,className:`p-1 rounded flex items-center justify-center transition-all duration-150 relative
9
+ `})]}),document.body)}function Or({children:e}){return jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:e})}function Ur({children:e}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-3 mt-6",children:e})}function Ut({open:e,onClose:t,title:r,children:o,footer:a,size:n="md",variant:s="default"}){if(ka.useEffect(()=>{let d=c=>{c.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",d),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",d),document.body.style.overflow="";}},[e,t]),!e)return null;let i={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",full:"w-full h-full max-w-none rounded-none border-0"},l=s==="lightbox";return reactDom.createPortal(jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",children:[jsxRuntime.jsx("div",{className:`absolute inset-0 transition-all duration-500 ${l?"bg-black/95 backdrop-blur-none":"bg-[var(--kyro-black)]/40 backdrop-blur-md"}`,onClick:t}),jsxRuntime.jsxs("div",{className:`relative ${i[n]} ${l?"bg-transparent text-white":"bg-[var(--kyro-surface)]"} ${!l&&n!=="full"?"rounded-[var(--kyro-radius-lg)]":""} shadow-2xl animate-in fade-in zoom-in-95 duration-300 ${l?"":"border"} ${s==="danger"?"border-red-500/30":"border-[var(--kyro-border)]"} flex flex-col overflow-hidden`,children:[!l&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-8 py-6 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/50 backdrop-blur-md",children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold text-[var(--kyro-text-primary)]",children:r}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"p-2 text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] rounded-xl hover:bg-[var(--kyro-surface)] transition-all duration-200",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("div",{className:`flex-1 overflow-auto ${l?"":"px-8 py-8"}`,children:o}),a&&!l&&jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-3 px-8 py-6 border-t border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/50",children:a})]})]}),document.body)}function xs({open:e,onClose:t,onConfirm:r,title:o,message:a,confirmLabel:n="Confirm",cancelLabel:s="Cancel",variant:i="default",loading:l=false}){return jsxRuntime.jsx(Ut,{open:e,onClose:t,title:o,size:"sm",footer:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:t,disabled:l,className:"kyro-btn kyro-btn-md kyro-btn-secondary",children:s}),jsxRuntime.jsx("button",{type:"button",onClick:r,disabled:l,className:`kyro-btn kyro-btn-md ${i==="danger"?"kyro-btn-danger":"kyro-btn-primary"}`,children:l?"Loading...":n})]}),children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)]",children:a})})}function sl({open:e,onClose:t,onSubmit:r,title:o,placeholder:a="",defaultValue:n=""}){let[s,i]=ka.useState(n),l=d=>{d.preventDefault(),s.trim()&&(r(s.trim()),i(""),t());};return e?reactDom.createPortal(jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),jsxRuntime.jsxs("div",{className:"relative w-full max-w-lg mx-4 bg-[var(--kyro-surface)] rounded-lg shadow-2xl animate-in fade-in zoom-in-95 duration-200 border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-[var(--kyro-text-primary)]",children:o}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"p-1 text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] rounded-lg hover:bg-[var(--kyro-surface-accent)] transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("form",{onSubmit:l,children:[jsxRuntime.jsx("div",{className:"px-6 py-4",children:jsxRuntime.jsx("input",{type:"text",value:s,onChange:d=>i(d.target.value),placeholder:a,autoFocus:true,className:"w-full px-3 py-2 border border-[var(--kyro-input-border)] rounded-lg bg-[var(--kyro-input-bg)] text-[var(--kyro-text-primary)] placeholder-[var(--kyro-text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent"})}),jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-3 px-6 py-4 border-t border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] rounded-b-lg",children:[jsxRuntime.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 rounded-lg font-medium text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"submit",disabled:!s.trim(),className:"px-4 py-2 rounded-lg font-medium text-sm bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] hover:opacity-90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"Confirm"})]})]})]})]}),document.body):null}function yo(e){if(typeof e!="string"||!e)return "";if(typeof window>"u"||e.startsWith("http")||e.startsWith("blob:"))return e;let t=e.replace(/^\/+/,"/");return `${window.location.origin}${t}`}function bn(e){if(e===0)return "0 B";let t=1024,r=["B","KB","MB","GB"],o=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,o)).toFixed(1))+" "+r[o]}function pp(e){return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function mp(e){return e.startsWith("image/")?"image":e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":e.includes("zip")||e.includes("tar")||e.includes("archive")?"archive":e.includes("pdf")||e.includes("doc")||e.includes("text")?"document":"other"}function xn({onSelect:e,multiple:t=true,pickerMode:r=false}){let{permissions:o}=Lr(),a=o?.media?.create!==false,n=o?.media?.delete!==false,s=o?.media?.update!==false,[i,l]=ka.useState([]),[d,c]=ka.useState(true),[m,u]=ka.useState([]),[g,x]=ka.useState(""),[f,y]=ka.useState(""),[b,v]=ka.useState("all"),[R,L]=ka.useState("grid"),[C,w]=ka.useState(null),[N,p]=ka.useState(false),[A,O]=ka.useState(false),[F,P]=ka.useState(false),[S,M]=ka.useState({}),[j,se]=ka.useState(false),[ie,ue]=ka.useState(false),[oe,ne]=ka.useState(null),[je,ft]=ka.useState(false),[B,K]=ka.useState(false),[ce,he]=ka.useState(1),[Pe,Ce]=ka.useState(0),[I,z]=ka.useState(1),Ve=40,[ye,Se]=ka.useState(new Set),{confirm:lt,alert:At}=ot(),[qt,vt]=ka.useState(false),q=ka.useRef(null),[X,le]=ka.useState(),xe=ka.useRef(null),we=ka.useCallback(async()=>{c(true);try{let h=new URLSearchParams({page:ce.toString(),limit:Ve.toString()});g&&h.append("folder",g),f&&h.append("search",f),b!=="all"&&h.append("type",b);let re=await De(Mr(`/api/media?${h}`));l((re.docs||[]).map(Re=>({...Re,type:mp(Re.mimeType)}))),Ce(re.totalDocs||0),z(re.totalPages||1);}catch(h){console.error("Failed to load media:",h);}finally{c(false);}},[ce,g,f,b]),Qe=ka.useCallback(async()=>{try{let h=await De(Mr("/api/media/folders"));u(Array.isArray(h)?h:h.folders||[]);}catch(h){console.error("Failed to load folders:",h);}},[]),Ct=ka.useCallback(async()=>{try{let re=!!(await De("/api/globals/storage-settings"))?.data?.provider;ne(re);}catch{ne(false);}},[]);ka.useEffect(()=>{r||Ct();},[Ct,r]),ka.useEffect(()=>{r||oe===false&&!je&&(ft(true),K(true));},[r,oe,je]),ka.useEffect(()=>{we();},[we]),ka.useEffect(()=>{Qe();},[Qe]),ka.useEffect(()=>{if(r)return;let h=re=>{let Re=re.clipboardData?.files;Re&&Re.length>0&&D(Re);};return window.addEventListener("paste",h),()=>window.removeEventListener("paste",h)},[r,g,oe]);let D=async h=>{if(!oe){K(true);return}P(true);let re=0,Re=0;for(let Jt=0;Jt<h.length;Jt++){let Lt=h[Jt];try{let vr=new FormData;vr.append("file",Lt),g&&vr.append("folder",g),await ya("/api/media/upload",vr,ir=>{M(es=>({...es,[Lt.name]:ir}));}),re++;}catch(vr){console.error(`Upload failed for ${Lt.name}:`,vr),Re++;}}P(false),M({}),we(),Qe(),Re>0&&$.error(`${Re} file(s) failed to upload`),re>0&&$.success(`${re} file(s) uploaded successfully`);},G=()=>{lt({title:"Delete Media",message:`Are you sure you want to delete ${ye.size} item(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let h of Array.from(ye))await kt(`/api/media/${h}`);Se(new Set),we(),$.success(`${ye.size} item(s) deleted`);}catch(h){console.error("Bulk delete failed:",h),$.error("Failed to delete some items");}}});},te=(h,re)=>{re.stopPropagation();let Re=new Set(ye);Re.has(h)?Re.delete(h):(t||Re.clear(),Re.add(h)),Se(Re);},sr=async h=>{try{await et("/api/media/folders",{name:h}),Qe(),se(!1),$.success(`Folder "${h}" created`);}catch(re){console.error("Failed to create folder:",re),$.error("Failed to create folder");}},no=h=>{lt({title:"Delete Folder",message:`Are you sure you want to delete the folder "${h}"? All media in this folder will be moved to the root.`,variant:"danger",confirmLabel:"Delete Folder",onConfirm:async()=>{try{await kt(`/api/media/folders?path=${encodeURIComponent(h)}`),g===h&&x(""),Qe(),we(),$.success(`Folder "${h}" deleted`);}catch(re){console.error("Failed to delete folder:",re),$.error("Failed to delete folder");}}});},da=async(h,re)=>{try{let Re=await Xt(`/api/media/${h}`,re);l(Jt=>Jt.map(Lt=>Lt.id===h?Re.doc:Lt)),C?.id===h&&w(Re.doc),$.success("Metadata updated");}catch(Re){console.error("Failed to update metadata:",Re),$.error("Failed to update metadata");}},Ka=h=>{let{width:re,height:Re}=h.currentTarget,Jt=ip.centerCrop(ip.makeAspectCrop({unit:"%",width:90},1,re,Re),re,Re);le(Jt);},Zn=async()=>{if(!(!X||!xe.current||!C)){P(true);try{let h=ip.convertToPixelCrop(X,xe.current.width,xe.current.height),re=document.createElement("canvas"),Re=xe.current.naturalWidth/xe.current.width,Jt=xe.current.naturalHeight/xe.current.height;re.width=h.width,re.height=h.height;let Lt=re.getContext("2d");if(Lt){Lt.drawImage(xe.current,h.x*Re,h.y*Jt,h.width*Re,h.height*Jt,0,0,h.width,h.height);let vr=await new Promise(ir=>re.toBlob(ir,C.mimeType));if(vr){let ir=new FormData;ir.append("file",vr,`cropped-${C.filename}`),g&&ir.append("folder",g),await ya("/api/media",ir),we(),O(!1),$.success("Cropped image saved");}}}catch(h){console.error("Crop failed:",h),$.error("Crop failed");}finally{P(false);}}},gt=ka.useMemo(()=>i.reduce((h,re)=>(h.totalSize+=re.fileSize||0,h),{totalSize:0}),[i]);return jsxRuntime.jsxs("div",{className:`flex flex-col h-full bg-[var(--kyro-bg)] transition-all duration-300 ${qt?"ring-4 ring-[var(--kyro-sidebar-active)] ring-inset":""}`,...r?{}:{onDragOver:h=>{h.preventDefault(),vt(true);},onDragLeave:()=>vt(false),onDrop:h=>{h.preventDefault(),vt(false),h.dataTransfer.files&&D(h.dataTransfer.files);}},children:[jsxRuntime.jsxs("div",{className:`flex flex-col lg:flex-row lg:items-center justify-between gap-6 border-b border-[var(--kyro-border)] backdrop-blur-md sticky top-0 ${r?"p-2":"p-6 rounded-xl surface-tile"}`,children:[!r&&jsxRuntime.jsx("div",{className:"flex items-center gap-4",children:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:"Media Library"}),jsxRuntime.jsx("div",{className:"flex items-center gap-3 mt-1",children:jsxRuntime.jsxs("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50",children:[Pe," Items \xB7 ",bn(gt.totalSize)]})})]})}),jsxRuntime.jsxs("div",{className:`flex items-center gap-3 flex-wrap lg:flex-nowrap ${r?"w-full":""}`,children:[jsxRuntime.jsxs("div",{className:"relative group flex-1 min-w-[200px]",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search assets...",value:f,onChange:h=>y(h.target.value),className:"w-full pl-11 pr-4 py-2.5 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] transition-all text-xs font-bold"})]}),!r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{onClick:()=>L("grid"),className:`p-2 rounded-lg transition-all ${R==="grid"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsxRuntime.jsx(lucideReact.Grid3X3,{className:"w-4 h-4"})}),jsxRuntime.jsx("button",{onClick:()=>L("list"),className:`p-2 rounded-lg transition-all ${R==="list"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsxRuntime.jsx(lucideReact.File,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("button",{onClick:()=>ue(true),className:"md:hidden p-2 rounded-xl bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-colors",children:jsxRuntime.jsx(lucideReact.Filter,{className:"w-4 h-4"})})]}),a&&jsxRuntime.jsxs("button",{onClick:()=>q.current?.click(),className:"flex items-center gap-2 px-6 py-2.5 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs shadow-lg active:scale-95 transition-all",children:[jsxRuntime.jsx(lucideReact.Maximize2,{className:"w-4 h-4"}),"Upload"]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[!r&&jsxRuntime.jsx("div",{className:"w-64 border-r border-[var(--kyro-border)] surface-tile mt-6 overflow-y-auto hidden md:block",children:jsxRuntime.jsxs("div",{className:"p-6 space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsxRuntime.jsx("div",{className:"space-y-1",children:["all","image","video","audio","document","archive"].map(h=>jsxRuntime.jsxs("button",{onClick:()=>v(h),className:`w-full flex items-center gap-3 px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all ${b===h?"text-[var(--kyro-text-primary)] bg-[var(--kyro-surface-accent)]":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]/50"}`,children:[jsxRuntime.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${b===h?"bg-[var(--kyro-primary)]":"bg-transparent border border-current opacity-30"}`}),h]},h))})]}),jsxRuntime.jsxs("div",{className:"pt-6 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),jsxRuntime.jsx("button",{onClick:()=>se(true),className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors text-[var(--kyro-text-primary)]",children:jsxRuntime.jsx(lucideReact.FolderPlus,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("nav",{className:"space-y-1",children:[jsxRuntime.jsxs("button",{onClick:()=>x(""),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===""?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx(lucideReact.FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(h=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>x(h),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsxRuntime.jsx(lucideReact.Folder,{fill:g===h?"currentColor":"none"})}),h]}),jsxRuntime.jsx("button",{onClick:re=>{re.stopPropagation(),no(h);},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-red-500 opacity-0 group-hover:opacity-100 transition-all hover:bg-red-50 rounded-lg",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})})]},h))]})]})]})}),jsxRuntime.jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-[var(--kyro-bg)]",children:[jsxRuntime.jsx("div",{className:`flex-1 overflow-y-auto custom-scrollbar ${r?"px-2 py-4":"py-4 px-2 md:py-8 md:px-4"}`,children:d?jsxRuntime.jsx("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5",children:jsxRuntime.jsx(Ot,{variant:"media-card",count:12})}):i.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center py-32 text-center",children:[jsxRuntime.jsx("div",{className:"w-24 h-24 rounded-[2rem] bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-8 rotate-12 group-hover:rotate-0 transition-transform duration-500",children:jsxRuntime.jsx(lucideReact.Grid3X3,{className:"w-10 h-10 text-[var(--kyro-text-muted)] opacity-30"})}),jsxRuntime.jsx("h3",{className:"text-xl font-bold text-[var(--kyro-text-primary)] tracking-tight",children:"No assets found"}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] mt-2 max-w-xs mx-auto text-sm font-medium leading-relaxed",children:"Upload your first file or create a folder to organize your media assets."}),!r&&a&&jsxRuntime.jsx("button",{onClick:()=>q.current?.click(),className:"mt-8 px-8 py-3 bg-[var(--kyro-text-primary)] text-[var(--kyro-bg)] rounded-2xl font-bold text-xs hover:scale-105 transition-all shadow-xl",children:"Start Uploading"})]}):R==="grid"?jsxRuntime.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-1",children:i.map((h,re)=>jsxRuntime.jsxs("div",{className:`group relative aspect-square rounded-lg overflow-hidden bg-[var(--kyro-surface-accent)] border-2 transition-all duration-300 cursor-pointer ${ye.has(h.id)?"border-[var(--kyro-primary)]":"border-transparent hover:border-[var(--kyro-border-strong)] hover:shadow-2xl hover:-translate-y-1"}`,onClick:()=>w(h),onContextMenu:Re=>{Re.preventDefault(),te(h.id,Re);},children:[h.type==="image"?jsxRuntime.jsx("img",{src:h.url,alt:h.title,className:"w-full h-full object-cover transition-transform duration-700 group-hover:scale-110",loading:"lazy"}):jsxRuntime.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-6 gap-4",children:[jsxRuntime.jsx("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface)] shadow-inner text-[var(--kyro-text-secondary)] group-hover:scale-110 transition-transform duration-500",children:h.type==="video"?jsxRuntime.jsx(lucideReact.Film,{className:"w-8 h-8"}):h.type==="audio"?jsxRuntime.jsx(lucideReact.Music,{className:"w-8 h-8"}):h.type==="document"?jsxRuntime.jsx(lucideReact.FileText,{className:"w-8 h-8"}):h.type==="archive"?jsxRuntime.jsx(lucideReact.Archive,{className:"w-8 h-8"}):jsxRuntime.jsx(lucideReact.File,{className:"w-8 h-8"})}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 text-center px-4 line-clamp-2",children:h.title})]}),jsxRuntime.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-col justify-end p-4",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-white font-bold text-[10px] truncate max-w-[120px]",children:h.filename}),jsxRuntime.jsx("div",{className:"flex gap-1",children:jsxRuntime.jsx("button",{onClick:Re=>te(h.id,Re),className:`kyro-btn-primary p-1.5 rounded-lg transition-all ${ye.has(h.id)?"":"bg-white/10 text-white hover:bg-white/20"}`,children:jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})})})]})}),ye.has(h.id)&&jsxRuntime.jsx("div",{className:"absolute top-3 left-3 w-6 h-6 rounded-lg bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center shadow-lg border-2 border-white/20 animate-in zoom-in duration-300",children:jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})})]},h.id))}):jsxRuntime.jsx("div",{className:"surface-tile overflow-hidden animate-in fade-in duration-500",children:jsxRuntime.jsxs("table",{className:"w-full text-left",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsx("th",{className:"px-6 py-4 w-12",children:jsxRuntime.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]",checked:ye.size===i.length,onChange:h=>{h.target.checked?Se(new Set(i.map(re=>re.id))):Se(new Set);}})}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Asset"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Type"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Size"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Date"}),jsxRuntime.jsx("th",{className:"px-6 py-4 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:i.map(h=>jsxRuntime.jsxs("tr",{className:`group hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer ${ye.has(h.id)?"bg-[var(--kyro-surface-accent)]":""}`,onClick:()=>w(h),children:[jsxRuntime.jsx("td",{className:"px-6 py-4",onClick:re=>re.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:ye.has(h.id),onChange:re=>te(h.id,re),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]"})}),jsxRuntime.jsx("td",{className:"px-6 py-4",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 rounded-xl bg-[var(--kyro-bg)] overflow-hidden border border-[var(--kyro-border)] flex-shrink-0 flex items-center justify-center",children:h.type==="image"?jsxRuntime.jsx("img",{src:h.url,alt:"",className:"w-full h-full object-cover"}):jsxRuntime.jsx(lucideReact.File,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50"})}),jsxRuntime.jsxs("div",{className:"flex flex-col min-w-0",children:[jsxRuntime.jsx("span",{className:"font-bold text-xs text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:h.title||h.filename}),jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:h.filename})]})]})}),jsxRuntime.jsx("td",{className:"px-6 py-4",children:jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[9px]",children:h.mimeType})}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:bn(h.fileSize)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:pp(h.createdAt)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-right",children:jsxRuntime.jsx("button",{onClick:re=>{re.stopPropagation(),te(h.id,re);},className:`kyro-btn-primary p-2 rounded-lg transition-all ${ye.has(h.id)?"":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] opacity-0 group-hover:opacity-100"}`,children:jsxRuntime.jsx(lucideReact.Grid3X3,{className:"w-4 h-4"})})})]},h.id))})]})})}),jsxRuntime.jsx(fn,{page:ce,totalPages:I,onPageChange:he})]})]}),!r&&F&&jsxRuntime.jsx("div",{className:"fixed bottom-12 left-1/2 -translate-x-1/2 z-[60] w-full max-w-lg",children:jsxRuntime.jsxs("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-[2rem] shadow-2xl p-6 ring-1 ring-white/10 animate-in slide-in-from-bottom-12 duration-700",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center animate-pulse",children:jsxRuntime.jsx(Ar,{})}),jsxRuntime.jsx("span",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Uploading Files"})]}),jsxRuntime.jsxs("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-50",children:[Object.keys(S).length," Total"]})]}),jsxRuntime.jsx("div",{className:"space-y-4 max-h-[160px] overflow-y-auto pr-2 custom-scrollbar",children:Object.entries(S).map(([h,re])=>jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex justify-between text-[10px] font-bold",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:h}),jsxRuntime.jsxs("span",{className:"text-[var(--kyro-primary)]",children:[re,"%"]})]}),jsxRuntime.jsx("div",{className:"h-1.5 w-full bg-[var(--kyro-surface-accent)] rounded-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full bg-[var(--kyro-primary)] transition-all duration-300 rounded-full",style:{width:`${re}%`}})})]},h))})]})}),ye.size>0&&jsxRuntime.jsxs("div",{className:"fixed bottom-12 left-1/2 -translate-x-1/2 z-[60] bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-full shadow-2xl px-2 py-2 flex items-center gap-12 animate-in slide-in-from-bottom-12 duration-700 ring-1 ring-white/10 backdrop-blur-xl",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-5 border-r border-[var(--kyro-border)] ",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 rounded-full bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center text-lg font-bold shadow-inner",children:ye.size}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-[11px] font-bold tracking-[0.2em] text-[var(--kyro-text-primary)]",children:"Selected"}),jsxRuntime.jsx("button",{onClick:()=>Se(new Set),className:"text-[10px] font-bold text-[var(--kyro-primary)] hover:underline opacity-80",children:"Clear all"})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[e&&jsxRuntime.jsx("button",{onClick:()=>{let h=i.filter(re=>ye.has(re.id));e(h);},className:"px-8 py-3 bg-[var(--kyro-text-primary)] text-[var(--kyro-bg)] rounded-full font-bold text-xs hover:scale-105 transition-all shadow-xl",children:"Confirm Selection"}),!r&&n&&jsxRuntime.jsx("button",{onClick:G,className:"p-3 bg-red-500/10 text-red-500 hover:bg-red-500 hover:text-white rounded-full transition-all active:scale-90",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-5 h-5"})})]})]}),ie&&!r&&jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[70] md:hidden",children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>ue(false)}),jsxRuntime.jsxs("div",{className:"fixed bottom-0 left-0 right-0 bg-[var(--kyro-surface)] rounded-t-3xl shadow-2xl max-h-[70vh] overflow-y-auto animate-in slide-in-from-bottom-12 duration-300",children:[jsxRuntime.jsxs("div",{className:"sticky top-0 bg-[var(--kyro-surface)] z-10 flex items-center justify-between p-6 pb-4 border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsx("h3",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Filters"}),jsxRuntime.jsx("button",{onClick:()=>ue(false),className:"p-2 rounded-xl hover:bg-[var(--kyro-surface-accent)] transition-colors text-[var(--kyro-text-muted)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("div",{className:"p-6 space-y-8",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsxRuntime.jsx("div",{className:"flex flex-wrap gap-2",children:["all","image","video","audio","document","archive"].map(h=>jsxRuntime.jsx("button",{onClick:()=>{v(h),ue(false);},className:`px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all border ${b===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] border-transparent":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] border-[var(--kyro-border)] hover:border-[var(--kyro-text-muted)]"}`,children:h},h))})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),jsxRuntime.jsx("button",{onClick:()=>{se(true),ue(false);},className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors text-[var(--kyro-text-primary)]",children:jsxRuntime.jsx(lucideReact.FolderPlus,{className:"w-4 h-4"})})]}),jsxRuntime.jsxs("nav",{className:"space-y-1",children:[jsxRuntime.jsxs("button",{onClick:()=>{x(""),ue(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===""?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx(lucideReact.FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(h=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>{x(h),ue(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsxRuntime.jsx(lucideReact.Folder,{fill:g===h?"currentColor":"none"})}),h]}),jsxRuntime.jsx("button",{onClick:re=>{re.stopPropagation(),no(h),ue(false);},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-red-500 opacity-0 group-hover:opacity-100 transition-all hover:bg-red-50 rounded-lg",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})})]},h))]})]})]})]})]}),jsxRuntime.jsx(dr,{open:!!C,onClose:()=>w(null),title:"Asset Details",subtitle:C?.filename,children:C&&jsxRuntime.jsxs("div",{className:"flex flex-col h-full",children:[jsxRuntime.jsxs("div",{className:"aspect-video w-full rounded-2xl bg-[var(--kyro-bg)] border border-[var(--kyro-border)] overflow-hidden relative group",children:[C.type==="image"?jsxRuntime.jsx("img",{src:yo(C.url),alt:"",className:"w-full h-full object-contain p-4"}):C.type==="video"?jsxRuntime.jsx("video",{src:yo(C.url),controls:true,className:"w-full h-full"}):jsxRuntime.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-12 gap-6",children:[jsxRuntime.jsx("div",{className:"w-20 h-20 rounded-[2rem] bg-[var(--kyro-surface-accent)] flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.File,{className:"w-10 h-10 text-[var(--kyro-text-secondary)]"})}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-xs font-bold",children:C.mimeType})]}),jsxRuntime.jsx("div",{className:"absolute top-4 right-4 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:jsxRuntime.jsx("button",{onClick:()=>p(true),className:"p-2.5 bg-black/50 backdrop-blur-md text-white rounded-xl hover:bg-black/70 transition-all",children:jsxRuntime.jsx(lucideReact.Maximize2,{className:"w-4 h-4"})})})]}),jsxRuntime.jsxs("div",{className:"mt-8 space-y-8 flex-1",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[jsxRuntime.jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"Dimensions"}),jsxRuntime.jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:C.type==="image"?"Original Resolution":"N/A"})]}),jsxRuntime.jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"File Size"}),jsxRuntime.jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:bn(C.fileSize)})]})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Public Link"}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx("input",{type:"text",readOnly:true,value:yo(C.url),className:"flex-1 px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl text-[10px] font-bold font-mono focus:outline-none"}),jsxRuntime.jsx("button",{onClick:()=>{navigator.clipboard.writeText(yo(C.url)),$.success("URL copied to clipboard");},className:"p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] border border-[var(--kyro-border)] rounded-xl transition-all",children:jsxRuntime.jsx(lucideReact.Link,{className:"w-4 h-4 text-[var(--kyro-text-primary)]"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Alt Text"}),jsxRuntime.jsx("textarea",{value:C.alt||"",onChange:h=>da(C.id,{alt:h.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-lg text-xs font-bold transition-all resize-none min-h-[80px] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Describe this asset..."})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Caption"}),jsxRuntime.jsx("textarea",{value:C.caption||"",onChange:h=>da(C.id,{caption:h.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-lg text-xs font-bold transition-all resize-none min-h-[80px] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Add a caption..."})]})]})]})]}),!r&&jsxRuntime.jsxs("div",{className:"pt-8 border-t border-[var(--kyro-border)] mt-8 flex gap-3 pb-8",children:[jsxRuntime.jsxs("button",{onClick:()=>{let h=document.createElement("a");h.href=yo(C.url),h.download=C.filename,h.click();},className:"flex-1 flex items-center justify-center gap-2 px-6 py-3 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs shadow-lg hover:opacity-90 transition-all",children:[jsxRuntime.jsx(lucideReact.Download,{className:"w-4 h-4"}),"Download"]}),C.type==="image"&&s&&jsxRuntime.jsx("button",{onClick:()=>O(true),className:"p-3 border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:jsxRuntime.jsx(lucideReact.Crop,{className:"w-4 h-4"})}),n&&jsxRuntime.jsx("button",{onClick:()=>{lt({title:"Delete Asset",message:`Are you sure you want to delete ${C.filename}? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await kt(`/api/media/${C.id}`),w(null),we();}catch(h){console.error("Delete failed:",h),$.error("Failed to delete asset");}}});},className:"p-3 border border-red-100 text-red-500 rounded-xl hover:bg-red-50 transition-all",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"})})]})]})}),N&&C&&jsxRuntime.jsxs(Ut,{open:N,onClose:()=>p(false),title:"",size:"full",variant:"lightbox",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-6",children:[jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-white font-bold text-lg tracking-tight",children:C.filename}),jsxRuntime.jsxs("span",{className:"text-white/40 text-[10px] font-bold tracking-widest mt-1",children:[bn(C.fileSize)," \xB7 ",C.mimeType]})]}),jsxRuntime.jsx("button",{onClick:()=>p(false),className:"p-3 bg-white/10 hover:bg-white/20 text-white rounded-2xl transition-all active:scale-90",children:jsxRuntime.jsx(lucideReact.X,{className:"w-6 h-6"})})]}),jsxRuntime.jsx("div",{className:"flex-1 w-full flex items-center justify-center p-12",children:C.type==="image"?jsxRuntime.jsx("img",{src:yo(C.url),alt:"",className:"max-h-full max-w-full object-contain shadow-2xl rounded-lg animate-in zoom-in-95 duration-500"}):C.type==="video"?jsxRuntime.jsx("video",{src:yo(C.url),controls:true,autoPlay:true,className:"max-h-full max-w-full rounded-lg shadow-2xl"}):jsxRuntime.jsxs("div",{className:"text-white text-center",children:[jsxRuntime.jsx(lucideReact.File,{className:"w-24 h-24 mx-auto mb-6 opacity-20"}),jsxRuntime.jsx("p",{className:"text-xl font-bold opacity-50",children:"Preview not available for this file type"})]})})]}),!r&&A&&C&&jsxRuntime.jsx(Ut,{open:A,onClose:()=>O(false),title:"",size:"full",variant:"lightbox",children:jsxRuntime.jsxs("div",{className:"flex flex-col h-full p-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-8",children:[jsxRuntime.jsx("h3",{className:"text-white font-bold text-2xl tracking-tighter",children:"Crop Image"}),jsxRuntime.jsxs("div",{className:"flex gap-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>O(false),className:"px-4 py-2 border border-white/20 text-white/80 hover:bg-white/10 rounded-lg font-bold text-sm transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",disabled:F,onClick:Zn,className:"px-4 py-2 bg-[var(--kyro-sidebar-active)] hover:opacity-90 text-[var(--kyro-sidebar-text-active)] rounded-lg font-bold text-sm transition-colors",children:F?"Saving...":"Save Crop"})]})]}),jsxRuntime.jsx("div",{className:"flex-1 w-full flex items-center justify-center overflow-auto",children:jsxRuntime.jsx(ip__default.default,{crop:X,onChange:h=>le(h),children:jsxRuntime.jsx("img",{ref:xe,src:C.url,alt:"Crop preview",className:"max-h-[70vh] object-contain",onLoad:Ka})})})]})}),!r&&jsxRuntime.jsx(sl,{open:j,onClose:()=>se(false),onSubmit:sr,title:"Create New Folder",placeholder:"Folder name"}),!r&&jsxRuntime.jsx(Ut,{open:B,onClose:()=>K(false),title:"Storage Not Configured",size:"md",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-[var(--kyro-sidebar-active)] flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.Server,{className:"w-8 h-8 text-[var(--kyro-sidebar-text-active)]"})}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] mb-6 text-sm",children:"Before uploading media, you need to configure your storage settings. Choose where files should be stored and how URLs are generated."}),jsxRuntime.jsxs("div",{className:"flex gap-3",children:[jsxRuntime.jsx("a",{href:"/settings/storage-settings",className:"flex-1 px-4 py-3 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-center hover:opacity-90 transition-colors",children:"Configure Storage"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{et("/api/globals/storage-settings",{provider:"local",local:{uploadDir:"./public/uploads",baseUrl:"/uploads"}}).then(()=>{K(false),ne(true),window.location.reload();}).catch(()=>{$.error("Failed to configure storage");});},className:"flex-1 px-4 py-3 border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded-xl font-bold hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Use Defaults"})]})]})}),!r&&jsxRuntime.jsx("input",{type:"file",ref:q,onChange:h=>{h.target.files&&D(h.target.files);},multiple:true,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.txt,.zip,.rar,.tar"})]})}var Hp=[{name:"Default",value:"inherit"},{name:"Red",value:"#ef4444"},{name:"Orange",value:"#f97316"},{name:"Amber",value:"#f59e0b"},{name:"Emerald",value:"#10b981"},{name:"Blue",value:"#3b82f6"},{name:"Indigo",value:"#6366f1"},{name:"Violet",value:"#8b5cf6"},{name:"Rose",value:"#f43f5e"},{name:"Slate",value:"#64748b"}],gl=({editor:e,isExpanded:t,setIsExpanded:r,onOpenMediaPicker:o})=>{let[a,n]=ka.useState(null),s=ka.useRef(null);if(ka.useEffect(()=>{function b(v){s.current&&!s.current.contains(v.target)&&n(null);}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]),!e)return null;let i=()=>{o();},l=()=>{let b=e.getAttributes("link").href,v=window.prompt("URL",b);if(v!==null){if(v===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:v}).run();}},d=b=>{b==="inherit"?e.chain().focus().unsetColor().run():e.chain().focus().setColor(b).run(),n(null);},c=b=>{n(a===b?null:b);},m=()=>e.isActive("heading",{level:1})?"Heading 1":e.isActive("heading",{level:2})?"Heading 2":e.isActive("heading",{level:3})?"Heading 3":e.isActive("heading",{level:4})?"Heading 4":"Normal Text",u=()=>e.isActive({textAlign:"center"})?jsxRuntime.jsx(lucideReact.AlignCenter,{size:12}):e.isActive({textAlign:"right"})?jsxRuntime.jsx(lucideReact.AlignRight,{size:12}):jsxRuntime.jsx(lucideReact.AlignLeft,{size:12}),g=()=>e.isActive("orderedList")?jsxRuntime.jsx(lucideReact.ListOrdered,{size:12}):e.isActive("taskList")?jsxRuntime.jsx(lucideReact.CheckSquare,{size:12}):jsxRuntime.jsx(lucideReact.List,{size:12}),x=()=>e.isActive("codeBlock")?jsxRuntime.jsx(lucideReact.Terminal,{size:12}):jsxRuntime.jsx(lucideReact.Quote,{size:12}),f=({onClick:b,isActive:v=false,disabled:R=false,children:L,title:C})=>jsxRuntime.jsx("button",{type:"button",onClick:b,disabled:R,title:C,className:`p-1 rounded flex items-center justify-center transition-all duration-150 relative
10
10
  ${v?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] shadow-xs scale-95":"text-[var(--kyro-text)] hover:bg-[var(--kyro-bg-hover)]"}
11
- ${R?"opacity-35 cursor-not-allowed":"cursor-pointer active:scale-90"}`,children:L}),u=({onClick:b,isActive:v,children:R,title:L})=>jsxRuntime.jsxs("button",{type:"button",onClick:b,title:L,className:`px-2 py-1 rounded flex items-center gap-1 transition-all duration-150 text-xs border border-transparent hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] active:scale-98
12
- ${v?"bg-[var(--kyro-bg-hover)] border-[var(--kyro-border)]":""}`,children:[R,jsxRuntime.jsx(lucideReact.ChevronDown,{size:10,className:"opacity-60"})]});return jsxRuntime.jsxs("div",{ref:s,className:"flex flex-wrap items-center gap-1.5 p-1.5 border-b border-[var(--kyro-border)] bg-[var(--kyro-bg-secondary)] rounded-t-lg select-none",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().undo().run(),disabled:!e.can().chain().focus().undo().run(),title:"Undo (Ctrl+Z)",children:jsxRuntime.jsx(lucideReact.Undo,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().redo().run(),disabled:!e.can().chain().focus().redo().run(),title:"Redo (Ctrl+Y)",children:jsxRuntime.jsx(lucideReact.Redo,{size:12})})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleBold().run(),disabled:!e.can().chain().focus().toggleBold().run(),isActive:e.isActive("bold"),title:"Bold (Ctrl+B)",children:jsxRuntime.jsx(lucideReact.Bold,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleItalic().run(),disabled:!e.can().chain().focus().toggleItalic().run(),isActive:e.isActive("italic"),title:"Italic (Ctrl+I)",children:jsxRuntime.jsx(lucideReact.Italic,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleUnderline().run(),disabled:!e.can().chain().focus().toggleUnderline().run(),isActive:e.isActive("underline"),title:"Underline (Ctrl+U)",children:jsxRuntime.jsx(lucideReact.Underline,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleStrike().run(),disabled:!e.can().chain().focus().toggleStrike().run(),isActive:e.isActive("strike"),title:"Strikethrough",children:jsxRuntime.jsx(lucideReact.Strikethrough,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleCode().run(),disabled:!e.can().chain().focus().toggleCode().run(),isActive:e.isActive("code"),title:"Inline Code",children:jsxRuntime.jsx(lucideReact.Code,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleHighlight().run(),isActive:e.isActive("highlight"),title:"Highlight Text",children:jsxRuntime.jsx(lucideReact.Highlighter,{size:12})}),jsxRuntime.jsxs("div",{className:"relative flex items-center justify-center",children:[jsxRuntime.jsx(f,{onClick:()=>c("color"),title:"Text Color",isActive:a==="color"||e.isActive("textStyle"),children:jsxRuntime.jsx(lucideReact.Palette,{size:12})}),a==="color"&&jsxRuntime.jsx("div",{className:"absolute top-full left-0 mt-1.5 p-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 flex flex-wrap gap-1 w-44 animate-in fade-in slide-in-from-top-1 duration-150",children:Gp.map(b=>jsxRuntime.jsx("button",{type:"button",onClick:()=>d(b.value),title:b.name,className:"w-6 h-6 rounded-full border border-[var(--kyro-border)] transition-transform hover:scale-115 active:scale-95 cursor-pointer relative",style:{backgroundColor:b.value==="inherit"?"transparent":b.value},children:b.value==="inherit"&&jsxRuntime.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[10px] text-[var(--kyro-text)] font-semibold",children:"\u2205"})},b.name))})]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(u,{onClick:()=>c("heading"),isActive:a==="heading",title:"Heading hierarchy",children:jsxRuntime.jsx("span",{className:"font-medium text-[11px] leading-none min-w-[70px] text-left",children:m()})}),a==="heading"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-36 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{e.chain().focus().setParagraph().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] transition-colors
11
+ ${R?"opacity-35 cursor-not-allowed":"cursor-pointer active:scale-90"}`,children:L}),y=({onClick:b,isActive:v,children:R,title:L})=>jsxRuntime.jsxs("button",{type:"button",onClick:b,title:L,className:`px-2 py-1 rounded flex items-center gap-1 transition-all duration-150 text-xs border border-transparent hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] active:scale-98
12
+ ${v?"bg-[var(--kyro-bg-hover)] border-[var(--kyro-border)]":""}`,children:[R,jsxRuntime.jsx(lucideReact.ChevronDown,{size:10,className:"opacity-60"})]});return jsxRuntime.jsxs("div",{ref:s,className:"flex flex-wrap items-center gap-1.5 p-1.5 border-b border-[var(--kyro-border)] bg-[var(--kyro-bg-secondary)] rounded-t-lg select-none",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().undo().run(),disabled:!e.can().chain().focus().undo().run(),title:"Undo (Ctrl+Z)",children:jsxRuntime.jsx(lucideReact.Undo,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().redo().run(),disabled:!e.can().chain().focus().redo().run(),title:"Redo (Ctrl+Y)",children:jsxRuntime.jsx(lucideReact.Redo,{size:12})})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleBold().run(),disabled:!e.can().chain().focus().toggleBold().run(),isActive:e.isActive("bold"),title:"Bold (Ctrl+B)",children:jsxRuntime.jsx(lucideReact.Bold,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleItalic().run(),disabled:!e.can().chain().focus().toggleItalic().run(),isActive:e.isActive("italic"),title:"Italic (Ctrl+I)",children:jsxRuntime.jsx(lucideReact.Italic,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleUnderline().run(),disabled:!e.can().chain().focus().toggleUnderline().run(),isActive:e.isActive("underline"),title:"Underline (Ctrl+U)",children:jsxRuntime.jsx(lucideReact.Underline,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleStrike().run(),disabled:!e.can().chain().focus().toggleStrike().run(),isActive:e.isActive("strike"),title:"Strikethrough",children:jsxRuntime.jsx(lucideReact.Strikethrough,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleCode().run(),disabled:!e.can().chain().focus().toggleCode().run(),isActive:e.isActive("code"),title:"Inline Code",children:jsxRuntime.jsx(lucideReact.Code,{size:12})}),jsxRuntime.jsx(f,{onClick:()=>e.chain().focus().toggleHighlight().run(),isActive:e.isActive("highlight"),title:"Highlight Text",children:jsxRuntime.jsx(lucideReact.Highlighter,{size:12})}),jsxRuntime.jsxs("div",{className:"relative flex items-center justify-center",children:[jsxRuntime.jsx(f,{onClick:()=>c("color"),title:"Text Color",isActive:a==="color"||e.isActive("textStyle"),children:jsxRuntime.jsx(lucideReact.Palette,{size:12})}),a==="color"&&jsxRuntime.jsx("div",{className:"absolute top-full left-0 mt-1.5 p-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 flex flex-wrap gap-1 w-44 animate-in fade-in slide-in-from-top-1 duration-150",children:Hp.map(b=>jsxRuntime.jsx("button",{type:"button",onClick:()=>d(b.value),title:b.name,className:"w-6 h-6 rounded-full border border-[var(--kyro-border)] transition-transform hover:scale-115 active:scale-95 cursor-pointer relative",style:{backgroundColor:b.value==="inherit"?"transparent":b.value},children:b.value==="inherit"&&jsxRuntime.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[10px] text-[var(--kyro-text)] font-semibold",children:"\u2205"})},b.name))})]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(y,{onClick:()=>c("heading"),isActive:a==="heading",title:"Heading hierarchy",children:jsxRuntime.jsx("span",{className:"font-medium text-[11px] leading-none min-w-[70px] text-left",children:m()})}),a==="heading"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-36 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{e.chain().focus().setParagraph().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] transition-colors
13
13
  ${e.isActive("heading")?"":"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]"}`,children:"Normal Text"}),[1,2,3,4].map(b=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleHeading({level:b}).run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] transition-colors
14
- ${e.isActive("heading",{level:b})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:["Heading ",b]},b))]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(u,{onClick:()=>c("lists"),isActive:a==="lists",title:"List Types",children:g()}),a==="lists"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-36 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleBulletList().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
14
+ ${e.isActive("heading",{level:b})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:["Heading ",b]},b))]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(y,{onClick:()=>c("lists"),isActive:a==="lists",title:"List Types",children:g()}),a==="lists"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-36 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleBulletList().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
15
15
  ${e.isActive("bulletList")?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.List,{size:12}),"Bullet List"]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleOrderedList().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
16
16
  ${e.isActive("orderedList")?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.ListOrdered,{size:12}),"Ordered List"]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleTaskList().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
17
- ${e.isActive("taskList")?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.CheckSquare,{size:12}),"Task Checklist"]})]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(u,{onClick:()=>c("blocks"),isActive:a==="blocks",title:"Structural Blocks",children:x()}),a==="blocks"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-36 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleBlockquote().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
17
+ ${e.isActive("taskList")?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.CheckSquare,{size:12}),"Task Checklist"]})]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(y,{onClick:()=>c("blocks"),isActive:a==="blocks",title:"Structural Blocks",children:x()}),a==="blocks"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-36 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleBlockquote().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
18
18
  ${e.isActive("blockquote")?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.Quote,{size:12}),"Blockquote"]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleCodeBlock().run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
19
- ${e.isActive("codeBlock")?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.Terminal,{size:12}),"Code Block"]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().setHorizontalRule().run(),n(null);},className:"px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors",children:[jsxRuntime.jsx(lucideReact.Minus,{size:12}),"Horizontal Rule"]})]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(u,{onClick:()=>c("align"),isActive:a==="align",title:"Alignment",children:y()}),a==="align"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-32 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().setTextAlign("left").run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
19
+ ${e.isActive("codeBlock")?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.Terminal,{size:12}),"Code Block"]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().setHorizontalRule().run(),n(null);},className:"px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors",children:[jsxRuntime.jsx(lucideReact.Minus,{size:12}),"Horizontal Rule"]})]})]}),jsxRuntime.jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(y,{onClick:()=>c("align"),isActive:a==="align",title:"Alignment",children:u()}),a==="align"&&jsxRuntime.jsxs("div",{className:"absolute top-full left-0 mt-1.5 p-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 min-w-32 flex flex-col gap-0.5 animate-in fade-in slide-in-from-top-1 duration-150",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().setTextAlign("left").run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
20
20
  ${e.isActive({textAlign:"left"})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.AlignLeft,{size:12}),"Align Left"]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().setTextAlign("center").run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
21
21
  ${e.isActive({textAlign:"center"})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.AlignCenter,{size:12}),"Align Center"]}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().setTextAlign("right").run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] flex items-center gap-2 transition-colors
22
- ${e.isActive({textAlign:"right"})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.AlignRight,{size:12}),"Align Right"]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(f,{onClick:l,isActive:e.isActive("link"),title:"Link",children:jsxRuntime.jsx(lucideReact.Link,{size:12})}),jsxRuntime.jsx(f,{onClick:i,title:"Add Image",children:jsxRuntime.jsx(lucideReact.Image,{size:12})})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs ml-auto",children:jsxRuntime.jsx(f,{onClick:()=>r(!t),title:t?"Collapse Workspace":"Enlarge Workspace",children:t?jsxRuntime.jsx(lucideReact.Minimize2,{size:12}):jsxRuntime.jsx(lucideReact.Maximize2,{size:12})})})]})};function $o({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false);return ka.useEffect(()=>{s(true);},[]),n?jsxRuntime.jsx(Wp,{field:e,value:t,onChange:r,error:o,disabled:a}):jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:`border rounded-lg bg-[var(--kyro-bg)] overflow-hidden border-[var(--kyro-border)] flex flex-col shadow-sm transition-all duration-200
22
+ ${e.isActive({textAlign:"right"})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:[jsxRuntime.jsx(lucideReact.AlignRight,{size:12}),"Align Right"]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsxRuntime.jsx(f,{onClick:l,isActive:e.isActive("link"),title:"Link",children:jsxRuntime.jsx(lucideReact.Link,{size:12})}),jsxRuntime.jsx(f,{onClick:i,title:"Add Image",children:jsxRuntime.jsx(lucideReact.Image,{size:12})})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-0.5 p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs ml-auto",children:jsxRuntime.jsx(f,{onClick:()=>r(!t),title:t?"Collapse Workspace":"Enlarge Workspace",children:t?jsxRuntime.jsx(lucideReact.Minimize2,{size:12}):jsxRuntime.jsx(lucideReact.Maximize2,{size:12})})})]})};function $o({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false);return ka.useEffect(()=>{s(true);},[]),n?jsxRuntime.jsx(_p,{field:e,value:t,onChange:r,error:o,disabled:a}):jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:`border rounded-lg bg-[var(--kyro-bg)] overflow-hidden border-[var(--kyro-border)] flex flex-col shadow-sm transition-all duration-200
23
23
  ${o?"border-[var(--kyro-error)] shadow-[0_0_0_1px_var(--kyro-error)]":"border-[var(--kyro-border)]"}
24
- ${a?"opacity-60 cursor-not-allowed":""}`,children:[jsxRuntime.jsx("div",{className:"flex flex-wrap items-center gap-1.5 p-1.5 border-b border-[var(--kyro-border)] bg-[var(--kyro-bg-secondary)] rounded-t-lg h-[40px]"}),jsxRuntime.jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px] p-4"})]})})}function Wp({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false),[i,l]=ka.useState(0),[d,c]=ka.useState(false);ka.useEffect(()=>{if(!n){l(0);return}let y=document.querySelector('[data-kyro-slide-panel="true"]'),g=()=>{l(y?y.getBoundingClientRect().width:0);};g();let x=new MutationObserver(()=>{g();});y&&x.observe(y),window.addEventListener("resize",g);let f=setInterval(g,100);return ()=>{x&&x.disconnect(),window.removeEventListener("resize",g),clearInterval(f);}},[n]);let m=react.useEditor({extensions:[hp__default.default.configure({codeBlock:true,link:false,underline:false}),wp__default.default.configure({openOnClick:false}),Np__default.default,Cp__default.default.configure({types:["heading","paragraph"]}),Sp__default.default,Tp__default.default.configure({multicolor:true}),Ap__default.default,Rp__default.default.configure({nested:true}),extensionTextStyle.TextStyle,Pp__default.default],content:Array.isArray(t)?{type:"doc",content:t}:t||{type:"doc",content:[]},editable:!a,onUpdate:({editor:y})=>{r(y.getJSON());},editorProps:{attributes:{class:"prose prose-sm dark:prose-invert focus:outline-none min-h-[160px] p-4 max-w-none kyro-richtext text-[0.875rem] leading-relaxed"}}});return ka.useEffect(()=>{m&&t&&JSON.stringify(t)!==JSON.stringify(m.getJSON())&&m.commands.setContent(Array.isArray(t)?{type:"doc",content:t}:t);},[t,m]),jsxRuntime.jsxs(st,{field:e,error:o,children:[n?jsxRuntime.jsxs("div",{className:"border rounded-lg bg-[var(--kyro-bg-secondary)] border-[var(--kyro-border)] p-4 text-center text-xs text-[var(--kyro-text-muted)] flex items-center justify-center gap-3 h-20 transition-all duration-200 shadow-inner",children:[jsxRuntime.jsx("span",{className:"font-medium",children:"Rich text editor workspace is currently maximized."}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(false),className:"px-2.5 py-1 bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] text-xs rounded-md shadow-sm font-medium hover:scale-102 active:scale-98 transition-transform cursor-pointer",children:"Minimize Workspace"})]}):jsxRuntime.jsxs("div",{className:`border rounded-lg bg-[var(--kyro-bg)] overflow-hidden border-[var(--kyro-border)] flex flex-col shadow-sm transition-all duration-200
24
+ ${a?"opacity-60 cursor-not-allowed":""}`,children:[jsxRuntime.jsx("div",{className:"flex flex-wrap items-center gap-1.5 p-1.5 border-b border-[var(--kyro-border)] bg-[var(--kyro-bg-secondary)] rounded-t-lg h-[40px]"}),jsxRuntime.jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px] p-4"})]})})}function _p({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false),[i,l]=ka.useState(0),[d,c]=ka.useState(false);ka.useEffect(()=>{if(!n){l(0);return}let u=document.querySelector('[data-kyro-slide-panel="true"]'),g=()=>{l(u?u.getBoundingClientRect().width:0);};g();let x=new MutationObserver(()=>{g();});u&&x.observe(u),window.addEventListener("resize",g);let f=setInterval(g,100);return ()=>{x&&x.disconnect(),window.removeEventListener("resize",g),clearInterval(f);}},[n]);let m=react.useEditor({extensions:[gp__default.default.configure({codeBlock:true,link:false,underline:false}),bp__default.default.configure({openOnClick:false}),xp__default.default,kp__default.default.configure({types:["heading","paragraph"]}),hp__default.default,wp__default.default.configure({multicolor:true}),Np__default.default,Cp__default.default.configure({nested:true}),extensionTextStyle.TextStyle,Tp__default.default],content:Array.isArray(t)?{type:"doc",content:t}:t||{type:"doc",content:[]},editable:!a,onUpdate:({editor:u})=>{r(u.getJSON());},editorProps:{attributes:{class:"prose prose-sm dark:prose-invert focus:outline-none min-h-[160px] p-4 max-w-none kyro-richtext text-[0.875rem] leading-relaxed"}}});return ka.useEffect(()=>{m&&t&&JSON.stringify(t)!==JSON.stringify(m.getJSON())&&m.commands.setContent(Array.isArray(t)?{type:"doc",content:t}:t);},[t,m]),jsxRuntime.jsxs(nt,{field:e,error:o,children:[n?jsxRuntime.jsxs("div",{className:"border rounded-lg bg-[var(--kyro-bg-secondary)] border-[var(--kyro-border)] p-4 text-center text-xs text-[var(--kyro-text-muted)] flex items-center justify-center gap-3 h-20 transition-all duration-200 shadow-inner",children:[jsxRuntime.jsx("span",{className:"font-medium",children:"Rich text editor workspace is currently maximized."}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(false),className:"px-2.5 py-1 bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] text-xs rounded-md shadow-sm font-medium hover:scale-102 active:scale-98 transition-transform cursor-pointer",children:"Minimize Workspace"})]}):jsxRuntime.jsxs("div",{className:`border rounded-lg bg-[var(--kyro-bg)] overflow-hidden border-[var(--kyro-border)] flex flex-col shadow-sm transition-all duration-200
25
25
  ${o?"border-[var(--kyro-error)] shadow-[0_0_0_1px_var(--kyro-error)]":"border-[var(--kyro-border)] focus-within:border-[var(--kyro-primary)] focus-within:ring-1 focus-within:ring-[var(--kyro-primary)]"}
26
- ${a?"opacity-60 cursor-not-allowed":""}`,children:[jsxRuntime.jsx(bl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsxRuntime.jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px]",children:jsxRuntime.jsx(react.EditorContent,{editor:m})})]}),n&&typeof document<"u"&&reactDom.createPortal(jsxRuntime.jsxs("div",{style:{position:"fixed",top:"16px",bottom:"16px",left:"16px",right:i>0?`${i+16}px`:"16px",zIndex:9999},className:"flex flex-col bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-200 transition-all duration-300",children:[jsxRuntime.jsx(bl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsxRuntime.jsx("div",{className:"overflow-y-auto flex-1 h-[calc(100vh-140px)] bg-[var(--kyro-bg)]",children:jsxRuntime.jsx(react.EditorContent,{editor:m})})]}),document.body),jsxRuntime.jsx("style",{children:`
26
+ ${a?"opacity-60 cursor-not-allowed":""}`,children:[jsxRuntime.jsx(gl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsxRuntime.jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px]",children:jsxRuntime.jsx(react.EditorContent,{editor:m})})]}),n&&typeof document<"u"&&reactDom.createPortal(jsxRuntime.jsxs("div",{style:{position:"fixed",top:"16px",bottom:"16px",left:"16px",right:i>0?`${i+16}px`:"16px",zIndex:9999},className:"flex flex-col bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-200 transition-all duration-300",children:[jsxRuntime.jsx(gl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsxRuntime.jsx("div",{className:"overflow-y-auto flex-1 h-[calc(100vh-140px)] bg-[var(--kyro-bg)]",children:jsxRuntime.jsx(react.EditorContent,{editor:m})})]}),document.body),jsxRuntime.jsx("style",{children:`
27
27
  .kyro-richtext ul[data-type="taskList"] {
28
28
  list-style: none !important;
29
29
  padding: 0 !important;
@@ -79,8 +79,8 @@
79
79
  font-style: italic !important;
80
80
  }
81
81
 
82
- `}),d&&jsxRuntime.jsx(dr,{open:d,onClose:()=>c(false),title:"Select Image",width:"xl",children:jsxRuntime.jsx(xn,{pickerMode:true,multiple:false,onSelect:y=>{if(y&&y.length>0){let g=y[0];m.chain().focus().setImage({src:g.url,alt:g.alt||g.title||"",title:g.title||""}).run();}c(false);}})})]})}var Eo={id:"light",label:"Light",colors:{primary:"#3b82f6",secondary:"#8b5cf6",background:"#f8fafc",surface:"#ffffff",text:"#0f172a",textMuted:"#64748b",border:"#e2e8f0",success:"#22c55e",error:"#ef4444",warning:"#f59e0b",info:"#06b6d4"},typography:{fontFamily:"'Inter', system-ui, -apple-system, sans-serif",fontFamilyMono:"'Fira Code', 'Cascadia Code', monospace"},spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem","2xl":"3rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},shadows:{sm:"0 1px 2px rgba(0,0,0,0.05)",md:"0 4px 6px -1px rgba(0,0,0,0.1)",lg:"0 10px 15px -3px rgba(0,0,0,0.1)",xl:"0 20px 25px -5px rgba(0,0,0,0.1)"}},Sa={id:"dark",label:"Dark",colors:{primary:"#60a5fa",secondary:"#a78bfa",background:"#0b1222",surface:"#1e293b",text:"#f1f5f9",textMuted:"#94a3b8",border:"#334155",success:"#4ade80",error:"#f87171",warning:"#fbbf24",info:"#22d3ee"},typography:{fontFamily:"'Inter', system-ui, -apple-system, sans-serif",fontFamilyMono:"'Fira Code', 'Cascadia Code', monospace"},spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem","2xl":"3rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},shadows:{sm:"0 1px 2px rgba(0,0,0,0.3)",md:"0 4px 6px -1px rgba(0,0,0,0.4)",lg:"0 10px 15px -3px rgba(0,0,0,0.4)",xl:"0 20px 25px -5px rgba(0,0,0,0.5)"}};function Ta(e,t){return {...e,...t,colors:{...e.colors,...t.colors},typography:{...e.typography,...t.typography},spacing:{...e.spacing,...t.spacing},borderRadius:{...e.borderRadius,...t.borderRadius},shadows:{...e.shadows,...t.shadows},blocks:e.blocks?{...e.blocks,...t.blocks}:t.blocks,fields:e.fields?{...e.fields,...t.fields}:t.fields}}var wl=ka.createContext(null);function Oo(){let e=ka.useContext(wl);return e||{mode:"light",theme:Eo,lightTheme:Eo,darkTheme:Sa,setMode:()=>{},updateTheme:()=>{},getCssVar:t=>`var(--kyro-${t})`}}function kl(e){let t=document.documentElement;t&&(e.colors&&Object.entries(e.colors).forEach(([r,o])=>{o&&(t.style.setProperty(`--kyro-${r}`,o),t.style.setProperty(`--kyro-${r}-light`,hl(o,.9)),t.style.setProperty(`--kyro-${r}-dark`,hl(o,.8)));}),e.typography&&(e.typography.fontFamily&&t.style.setProperty("--kyro-font-family",e.typography.fontFamily),e.typography.fontFamilyMono&&t.style.setProperty("--kyro-font-mono",e.typography.fontFamilyMono)),e.spacing&&Object.entries(e.spacing).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-spacing-${r}`,o);}),e.borderRadius&&Object.entries(e.borderRadius).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-radius-${r}`,o);}),e.shadows&&Object.entries(e.shadows).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-shadow-${r}`,o);}),e.blocks&&(e.blocks.card&&Object.entries(e.blocks.card).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-block-card-${r}`,o);}),e.blocks.hero?.background&&t.style.setProperty("--kyro-block-hero-bg",e.blocks.hero.background),e.blocks.code&&Object.entries(e.blocks.code).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-block-code-${r}`,o);})),e.fields&&(e.fields.input&&Object.entries(e.fields.input).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-field-input-${r}`,o);}),e.fields.upload&&e.fields.upload.dropzoneBackground&&t.style.setProperty("--kyro-field-upload-dropzone-bg",e.fields.upload.dropzoneBackground)));}function hl(e,t){if(!e.startsWith("#"))return e;let r=parseInt(e.slice(1,3),16),o=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16),n=s=>Math.round(s*t).toString(16).padStart(2,"0");return `#${n(r)}${n(o)}${n(a)}`}function kr({children:e,defaultMode:t="light",light:r,dark:o}){let[a,n]=ka.useState(t),[s,i]=ka.useState(r||{}),[l,d]=ka.useState(o||{}),c=Ta(Eo,s),m=Ta(Sa,l),y=ka.useCallback(()=>a==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?m:c:a==="dark"?m:c,[a,c,m]),[g,x]=ka.useState(y());ka.useEffect(()=>{let b=y();x(b),kl(b);},[y]),ka.useEffect(()=>{if(a!=="system")return;let b=window.matchMedia("(prefers-color-scheme: dark)"),v=()=>{let R=y();x(R),kl(R);};return b.addEventListener("change",v),()=>b.removeEventListener("change",v)},[a,y]);let f=ka.useCallback(b=>{i(v=>({...v,...b})),d(v=>({...v,...b}));},[]),u=ka.useCallback(b=>`var(--kyro-${b})`,[]);return jsxRuntime.jsx(wl.Provider,{value:{mode:a,theme:g,lightTheme:c,darkTheme:m,setMode:n,updateTheme:f,getCssVar:u},children:e})}var wn=e=>jsxRuntime.jsx(kr,{defaultMode:"light",...e}),Nn=e=>jsxRuntime.jsx(kr,{defaultMode:"dark",...e});var em=ka.lazy(()=>import('@uiw/react-codemirror').then(e=>({default:e.default}))),tm=[{value:"javascript",label:"JavaScript"},{value:"typescript",label:"TypeScript"},{value:"json",label:"JSON"},{value:"html",label:"HTML"},{value:"css",label:"CSS"},{value:"sql",label:"SQL"},{value:"python",label:"Python"},{value:"rust",label:"Rust"},{value:"java",label:"Java"},{value:"php",label:"PHP"},{value:"markdown",label:"Markdown"}],Cl={javascript:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true,typescript:true})),typescript:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true,typescript:true})),js:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true})),jsx:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true})),ts:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({typescript:true})),json:()=>import('@codemirror/lang-json').then(e=>e.json()),css:()=>import('@codemirror/lang-css').then(e=>e.css()),sql:()=>import('@codemirror/lang-sql').then(e=>e.sql()),python:()=>import('@codemirror/lang-python').then(e=>e.python()),html:()=>import('@codemirror/lang-html').then(e=>e.html()),rust:()=>import('@codemirror/lang-rust').then(e=>e.rust()),java:()=>import('@codemirror/lang-java').then(e=>e.java()),cpp:()=>import('@codemirror/lang-cpp').then(e=>e.cpp()),c:()=>import('@codemirror/lang-cpp').then(e=>e.cpp()),php:()=>import('@codemirror/lang-php').then(e=>e.php()),markdown:()=>import('@codemirror/lang-markdown').then(e=>e.markdown()),py:()=>import('@codemirror/lang-python').then(e=>e.python())},Aa=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(false),[d,c]=ka.useState([]),[m,y]=ka.useState(false),[g,x]=ka.useState(false),[f,u]=ka.useState(false),{theme:b}=Oo(),v=b.colors?.accent||b.colors?.primary||"#6366f1",R=e.language?.toLowerCase()||"javascript";ka.useEffect(()=>{s(true),l(document.documentElement.classList.contains("dark"));let O=new MutationObserver(()=>{l(document.documentElement.classList.contains("dark"));});return O.observe(document.documentElement,{attributes:true,attributeFilter:["class"]}),()=>O.disconnect()},[]),ka.useEffect(()=>{if(!n)return;(async()=>{y(true);try{let P=await(Cl[R]||Cl.javascript)();c([P]);}catch(F){console.error("Failed to load language extension:",F),c([]);}finally{y(false);}})();},[R,n]);let L=ka.useCallback(O=>r?.(O),[r]),C=ka.useCallback(()=>{navigator.clipboard.writeText(t),x(true),setTimeout(()=>x(false),1500);},[t]),w=ka.useCallback(()=>{u(O=>!O),document.body.style.overflow=f?"":"hidden";},[f]),N=i?codemirrorThemeAura.aura:codemirrorThemeGithub.githubLight,p=tm.find(O=>O.value===R)?.label||R,A=(O,F=1)=>{let P=parseInt(O.slice(1,3),16),S=parseInt(O.slice(3,5),16),M=parseInt(O.slice(5,7),16);return `rgba(${P}, ${S}, ${M}, ${F})`};return n?jsxRuntime.jsxs("div",{className:"group",style:{"--accent":v,"--accent-light":A(v,.1),"--accent-light-2":A(v,.05)},children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:e.label||e.name}),jsxRuntime.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-semibold transition-colors",style:{backgroundColor:m?"var(--kyro-surface-accent)":v,color:m?"var(--kyro-text-muted)":"white"},children:m?"...":p})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:C,className:"text-[10px] px-2 py-0.5 rounded font-medium transition-all",style:{backgroundColor:g?"var(--kyro-success)":"var(--kyro-surface-accent)",color:g?"white":"var(--kyro-text-secondary)"},children:g?"Copied":"Copy"}),jsxRuntime.jsx("button",{type:"button",onClick:w,className:"text-[10px] px-2 py-0.5 rounded font-medium bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] transition-all",style:{color:"var(--kyro-text-secondary)"},children:f?"Exit":"Expand"})]})]}),jsxRuntime.jsxs("div",{className:`relative rounded-md overflow-hidden transition-all duration-200 ${f?"fixed inset-4 z-50":""}`,style:{backgroundColor:"var(--kyro-surface)",borderColor:o?"var(--kyro-error)":"var(--kyro-border)",borderWidth:"1px"},children:[jsxRuntime.jsx("div",{className:"absolute top-0 left-0 right-0 h-0.5 transition-all duration-200",style:{backgroundColor:v}}),jsxRuntime.jsx(ka.Suspense,{fallback:jsxRuntime.jsx("div",{className:"h-[280px] flex items-center justify-center",style:{backgroundColor:"var(--kyro-surface)"},children:jsxRuntime.jsx("div",{className:"w-6 h-6 rounded-full animate-spin",style:{borderColor:"var(--kyro-border)",borderTopColor:v,borderWidth:"2px"}})}),children:jsxRuntime.jsx(em,{value:t??"",height:f?"calc(100vh - 100px)":"280px",width:"100%",extensions:d,theme:N,onChange:L,editable:!a,basicSetup:{lineNumbers:true,highlightActiveLine:true,bracketMatching:true,closeBrackets:true,autocompletion:true,foldGutter:true},style:{fontSize:"13px",fontFamily:"'JetBrains Mono', 'Fira Code', monospace"}})}),o&&jsxRuntime.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 py-2 text-xs font-medium",style:{backgroundColor:"var(--kyro-danger-bg)",color:"var(--kyro-error)"},children:o})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mt-2 text-[10px]",style:{color:"var(--kyro-text-muted)"},children:[jsxRuntime.jsxs("span",{children:[t.split(`
83
- `).length," lines"]}),jsxRuntime.jsx("span",{style:{color:v},children:"CodeMirror"})]})]}):jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"h-5 w-24 rounded bg-[var(--kyro-surface-accent)] animate-pulse"}),jsxRuntime.jsx("div",{className:"h-5 w-16 rounded bg-[var(--kyro-surface-accent)] animate-pulse"})]}),jsxRuntime.jsx("div",{className:"h-[280px] rounded-xl bg-[var(--kyro-surface-accent)] animate-pulse"})]})};function nm(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/```(\w+)?\n([\s\S]*?)```/g,'<pre class="bg-gray-100 dark:bg-gray-800 p-3 rounded overflow-x-auto my-2"><code>$2</code></pre>').replace(/`([^`]+)`/g,'<code class="bg-gray-100 dark:bg-gray-800 px-1 rounded text-sm font-mono">$1</code>').replace(/^### (.+)$/gm,'<h3 class="text-lg font-semibold mt-4 mb-2">$1</h3>').replace(/^## (.+)$/gm,'<h2 class="text-xl font-semibold mt-4 mb-2">$1</h2>').replace(/^# (.+)$/gm,'<h1 class="text-2xl font-bold mt-4 mb-2">$1</h1>').replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>").replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/\*(.+?)\*/g,"<em>$1</em>").replace(/___(.+?)___/g,"<strong><em>$1</em></strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/_(.+?)_/g,"<em>$1</em>").replace(/~~(.+?)~~/g,"<del>$1</del>").replace(/^> (.+)$/gm,'<blockquote class="border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic my-2 text-gray-600 dark:text-gray-400">$1</blockquote>').replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" class="text-blue-600 hover:underline" target="_blank" rel="noopener noreferrer">$1</a>').replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" class="max-w-full h-auto rounded my-2" />').replace(/^---$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^\*\*\*$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^[\*\-] (.+)$/gm,'<li class="ml-4">$1</li>').replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>').replace(/^(?!<[a-z]|$)(.+)$/gm,'<p class="my-2">$1</p>').replace(/<p class="my-2"><\/p>/g,"").replace(/(<li class="ml-4">.*<\/li>\n?)+/g,'<ul class="list-disc pl-6 my-2">$&</ul>'):""}var Ss=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(false);ka.useEffect(()=>{l(true);},[]);let d=ka.useCallback(y=>{r?.(y.target.value);},[r]),c=ka.useMemo(()=>t?t.trim().split(/\s+/).filter(Boolean).length:0,[t]),m=t?.length||0;return i?jsxRuntime.jsxs("div",{className:"kyro-form-field",style:{position:"relative",zIndex:10,pointerEvents:"auto"},children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[c," words \u2022 ",m," chars"]}),jsxRuntime.jsxs("div",{className:"flex rounded-md overflow-hidden border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>s(false),className:`px-3 py-1 text-xs font-medium transition-colors ${n?"bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]":"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]"}`,children:"Write"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(true),className:`px-3 py-1 text-xs font-medium transition-colors ${n?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,children:"Preview"})]})]})]}),jsxRuntime.jsx("div",{style:{pointerEvents:"auto",position:"relative",zIndex:50},className:`border border-[var(--kyro-border)] rounded-md overflow-hidden ${a?"opacity-50 cursor-not-allowed":""} ${o?"border-[var(--kyro-error)]":""}`,children:n?jsxRuntime.jsx("div",{className:"p-6 min-h-[300px] overflow-auto bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)]",children:t?jsxRuntime.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",dangerouslySetInnerHTML:{__html:nm(t)}}):jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-muted)] italic",children:"Nothing to preview"})}):jsxRuntime.jsx("textarea",{value:t??"",onChange:d,disabled:a,rows:12,style:{pointerEvents:"auto",cursor:"text",zIndex:100},className:"w-full p-4 font-mono text-sm resize-y focus:outline-none bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)]",placeholder:`Enter markdown content...
82
+ `}),d&&jsxRuntime.jsx(dr,{open:d,onClose:()=>c(false),title:"Select Image",width:"xl",children:jsxRuntime.jsx(xn,{pickerMode:true,multiple:false,onSelect:u=>{if(u&&u.length>0){let g=u[0];m.chain().focus().setImage({src:g.url,alt:g.alt||g.title||"",title:g.title||""}).run();}c(false);}})})]})}var Eo={id:"light",label:"Light",colors:{primary:"#3b82f6",secondary:"#8b5cf6",background:"#f8fafc",surface:"#ffffff",text:"#0f172a",textMuted:"#64748b",border:"#e2e8f0",success:"#22c55e",error:"#ef4444",warning:"#f59e0b",info:"#06b6d4"},typography:{fontFamily:"'Inter', system-ui, -apple-system, sans-serif",fontFamilyMono:"'Fira Code', 'Cascadia Code', monospace"},spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem","2xl":"3rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},shadows:{sm:"0 1px 2px rgba(0,0,0,0.05)",md:"0 4px 6px -1px rgba(0,0,0,0.1)",lg:"0 10px 15px -3px rgba(0,0,0,0.1)",xl:"0 20px 25px -5px rgba(0,0,0,0.1)"}},Sa={id:"dark",label:"Dark",colors:{primary:"#60a5fa",secondary:"#a78bfa",background:"#0b1222",surface:"#1e293b",text:"#f1f5f9",textMuted:"#94a3b8",border:"#334155",success:"#4ade80",error:"#f87171",warning:"#fbbf24",info:"#22d3ee"},typography:{fontFamily:"'Inter', system-ui, -apple-system, sans-serif",fontFamilyMono:"'Fira Code', 'Cascadia Code', monospace"},spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem","2xl":"3rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},shadows:{sm:"0 1px 2px rgba(0,0,0,0.3)",md:"0 4px 6px -1px rgba(0,0,0,0.4)",lg:"0 10px 15px -3px rgba(0,0,0,0.4)",xl:"0 20px 25px -5px rgba(0,0,0,0.5)"}};function Ta(e,t){return {...e,...t,colors:{...e.colors,...t.colors},typography:{...e.typography,...t.typography},spacing:{...e.spacing,...t.spacing},borderRadius:{...e.borderRadius,...t.borderRadius},shadows:{...e.shadows,...t.shadows},blocks:e.blocks?{...e.blocks,...t.blocks}:t.blocks,fields:e.fields?{...e.fields,...t.fields}:t.fields}}var hl=ka.createContext(null);function Oo(){let e=ka.useContext(hl);return e||{mode:"light",theme:Eo,lightTheme:Eo,darkTheme:Sa,setMode:()=>{},updateTheme:()=>{},getCssVar:t=>`var(--kyro-${t})`}}function xl(e){let t=document.documentElement;t&&(e.colors&&Object.entries(e.colors).forEach(([r,o])=>{o&&(t.style.setProperty(`--kyro-${r}`,o),t.style.setProperty(`--kyro-${r}-light`,kl(o,.9)),t.style.setProperty(`--kyro-${r}-dark`,kl(o,.8)));}),e.typography&&(e.typography.fontFamily&&t.style.setProperty("--kyro-font-family",e.typography.fontFamily),e.typography.fontFamilyMono&&t.style.setProperty("--kyro-font-mono",e.typography.fontFamilyMono)),e.spacing&&Object.entries(e.spacing).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-spacing-${r}`,o);}),e.borderRadius&&Object.entries(e.borderRadius).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-radius-${r}`,o);}),e.shadows&&Object.entries(e.shadows).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-shadow-${r}`,o);}),e.blocks&&(e.blocks.card&&Object.entries(e.blocks.card).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-block-card-${r}`,o);}),e.blocks.hero?.background&&t.style.setProperty("--kyro-block-hero-bg",e.blocks.hero.background),e.blocks.code&&Object.entries(e.blocks.code).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-block-code-${r}`,o);})),e.fields&&(e.fields.input&&Object.entries(e.fields.input).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-field-input-${r}`,o);}),e.fields.upload&&e.fields.upload.dropzoneBackground&&t.style.setProperty("--kyro-field-upload-dropzone-bg",e.fields.upload.dropzoneBackground)));}function kl(e,t){if(!e.startsWith("#"))return e;let r=parseInt(e.slice(1,3),16),o=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16),n=s=>Math.round(s*t).toString(16).padStart(2,"0");return `#${n(r)}${n(o)}${n(a)}`}function kr({children:e,defaultMode:t="light",light:r,dark:o}){let[a,n]=ka.useState(t),[s,i]=ka.useState(r||{}),[l,d]=ka.useState(o||{}),c=Ta(Eo,s),m=Ta(Sa,l),u=ka.useCallback(()=>a==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?m:c:a==="dark"?m:c,[a,c,m]),[g,x]=ka.useState(u());ka.useEffect(()=>{let b=u();x(b),xl(b);},[u]),ka.useEffect(()=>{if(a!=="system")return;let b=window.matchMedia("(prefers-color-scheme: dark)"),v=()=>{let R=u();x(R),xl(R);};return b.addEventListener("change",v),()=>b.removeEventListener("change",v)},[a,u]);let f=ka.useCallback(b=>{i(v=>({...v,...b})),d(v=>({...v,...b}));},[]),y=ka.useCallback(b=>`var(--kyro-${b})`,[]);return jsxRuntime.jsx(hl.Provider,{value:{mode:a,theme:g,lightTheme:c,darkTheme:m,setMode:n,updateTheme:f,getCssVar:y},children:e})}var wn=e=>jsxRuntime.jsx(kr,{defaultMode:"light",...e}),Nn=e=>jsxRuntime.jsx(kr,{defaultMode:"dark",...e});var Xp=ka.lazy(()=>import('@uiw/react-codemirror').then(e=>({default:e.default}))),Qp=[{value:"javascript",label:"JavaScript"},{value:"typescript",label:"TypeScript"},{value:"json",label:"JSON"},{value:"html",label:"HTML"},{value:"css",label:"CSS"},{value:"sql",label:"SQL"},{value:"python",label:"Python"},{value:"rust",label:"Rust"},{value:"java",label:"Java"},{value:"php",label:"PHP"},{value:"markdown",label:"Markdown"}],Nl={javascript:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true,typescript:true})),typescript:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true,typescript:true})),js:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true})),jsx:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true})),ts:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({typescript:true})),json:()=>import('@codemirror/lang-json').then(e=>e.json()),css:()=>import('@codemirror/lang-css').then(e=>e.css()),sql:()=>import('@codemirror/lang-sql').then(e=>e.sql()),python:()=>import('@codemirror/lang-python').then(e=>e.python()),html:()=>import('@codemirror/lang-html').then(e=>e.html()),rust:()=>import('@codemirror/lang-rust').then(e=>e.rust()),java:()=>import('@codemirror/lang-java').then(e=>e.java()),cpp:()=>import('@codemirror/lang-cpp').then(e=>e.cpp()),c:()=>import('@codemirror/lang-cpp').then(e=>e.cpp()),php:()=>import('@codemirror/lang-php').then(e=>e.php()),markdown:()=>import('@codemirror/lang-markdown').then(e=>e.markdown()),py:()=>import('@codemirror/lang-python').then(e=>e.python())},Aa=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(false),[d,c]=ka.useState([]),[m,u]=ka.useState(false),[g,x]=ka.useState(false),[f,y]=ka.useState(false),{theme:b}=Oo(),v=b.colors?.accent||b.colors?.primary||"#6366f1",R=e.language?.toLowerCase()||"javascript";ka.useEffect(()=>{s(true),l(document.documentElement.classList.contains("dark"));let O=new MutationObserver(()=>{l(document.documentElement.classList.contains("dark"));});return O.observe(document.documentElement,{attributes:true,attributeFilter:["class"]}),()=>O.disconnect()},[]),ka.useEffect(()=>{if(!n)return;(async()=>{u(true);try{let P=await(Nl[R]||Nl.javascript)();c([P]);}catch(F){console.error("Failed to load language extension:",F),c([]);}finally{u(false);}})();},[R,n]);let L=ka.useCallback(O=>r?.(O),[r]),C=ka.useCallback(()=>{navigator.clipboard.writeText(t),x(true),setTimeout(()=>x(false),1500);},[t]),w=ka.useCallback(()=>{y(O=>!O),document.body.style.overflow=f?"":"hidden";},[f]),N=i?codemirrorThemeAura.aura:codemirrorThemeGithub.githubLight,p=Qp.find(O=>O.value===R)?.label||R,A=(O,F=1)=>{let P=parseInt(O.slice(1,3),16),S=parseInt(O.slice(3,5),16),M=parseInt(O.slice(5,7),16);return `rgba(${P}, ${S}, ${M}, ${F})`};return n?jsxRuntime.jsxs("div",{className:"group",style:{"--accent":v,"--accent-light":A(v,.1),"--accent-light-2":A(v,.05)},children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:e.label||e.name}),jsxRuntime.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-semibold transition-colors",style:{backgroundColor:m?"var(--kyro-surface-accent)":v,color:m?"var(--kyro-text-muted)":"white"},children:m?"...":p})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:C,className:"text-[10px] px-2 py-0.5 rounded font-medium transition-all",style:{backgroundColor:g?"var(--kyro-success)":"var(--kyro-surface-accent)",color:g?"white":"var(--kyro-text-secondary)"},children:g?"Copied":"Copy"}),jsxRuntime.jsx("button",{type:"button",onClick:w,className:"text-[10px] px-2 py-0.5 rounded font-medium bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] transition-all",style:{color:"var(--kyro-text-secondary)"},children:f?"Exit":"Expand"})]})]}),jsxRuntime.jsxs("div",{className:`relative rounded-md overflow-hidden transition-all duration-200 ${f?"fixed inset-4 z-50":""}`,style:{backgroundColor:"var(--kyro-surface)",borderColor:o?"var(--kyro-error)":"var(--kyro-border)",borderWidth:"1px"},children:[jsxRuntime.jsx("div",{className:"absolute top-0 left-0 right-0 h-0.5 transition-all duration-200",style:{backgroundColor:v}}),jsxRuntime.jsx(ka.Suspense,{fallback:jsxRuntime.jsx("div",{className:"h-[280px] flex items-center justify-center",style:{backgroundColor:"var(--kyro-surface)"},children:jsxRuntime.jsx("div",{className:"w-6 h-6 rounded-full animate-spin",style:{borderColor:"var(--kyro-border)",borderTopColor:v,borderWidth:"2px"}})}),children:jsxRuntime.jsx(Xp,{value:t??"",height:f?"calc(100vh - 100px)":"280px",width:"100%",extensions:d,theme:N,onChange:L,editable:!a,basicSetup:{lineNumbers:true,highlightActiveLine:true,bracketMatching:true,closeBrackets:true,autocompletion:true,foldGutter:true},style:{fontSize:"13px",fontFamily:"'JetBrains Mono', 'Fira Code', monospace"}})}),o&&jsxRuntime.jsx("div",{className:"absolute bottom-0 left-0 right-0 px-3 py-2 text-xs font-medium",style:{backgroundColor:"var(--kyro-danger-bg)",color:"var(--kyro-error)"},children:o})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mt-2 text-[10px]",style:{color:"var(--kyro-text-muted)"},children:[jsxRuntime.jsxs("span",{children:[t.split(`
83
+ `).length," lines"]}),jsxRuntime.jsx("span",{style:{color:v},children:"CodeMirror"})]})]}):jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"h-5 w-24 rounded bg-[var(--kyro-surface-accent)] animate-pulse"}),jsxRuntime.jsx("div",{className:"h-5 w-16 rounded bg-[var(--kyro-surface-accent)] animate-pulse"})]}),jsxRuntime.jsx("div",{className:"h-[280px] rounded-xl bg-[var(--kyro-surface-accent)] animate-pulse"})]})};function tm(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/```(\w+)?\n([\s\S]*?)```/g,'<pre class="bg-gray-100 dark:bg-gray-800 p-3 rounded overflow-x-auto my-2"><code>$2</code></pre>').replace(/`([^`]+)`/g,'<code class="bg-gray-100 dark:bg-gray-800 px-1 rounded text-sm font-mono">$1</code>').replace(/^### (.+)$/gm,'<h3 class="text-lg font-semibold mt-4 mb-2">$1</h3>').replace(/^## (.+)$/gm,'<h2 class="text-xl font-semibold mt-4 mb-2">$1</h2>').replace(/^# (.+)$/gm,'<h1 class="text-2xl font-bold mt-4 mb-2">$1</h1>').replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>").replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/\*(.+?)\*/g,"<em>$1</em>").replace(/___(.+?)___/g,"<strong><em>$1</em></strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/_(.+?)_/g,"<em>$1</em>").replace(/~~(.+?)~~/g,"<del>$1</del>").replace(/^> (.+)$/gm,'<blockquote class="border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic my-2 text-gray-600 dark:text-gray-400">$1</blockquote>').replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" class="text-blue-600 hover:underline" target="_blank" rel="noopener noreferrer">$1</a>').replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" class="max-w-full h-auto rounded my-2" />').replace(/^---$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^\*\*\*$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^[\*\-] (.+)$/gm,'<li class="ml-4">$1</li>').replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>').replace(/^(?!<[a-z]|$)(.+)$/gm,'<p class="my-2">$1</p>').replace(/<p class="my-2"><\/p>/g,"").replace(/(<li class="ml-4">.*<\/li>\n?)+/g,'<ul class="list-disc pl-6 my-2">$&</ul>'):""}var Cs=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(false);ka.useEffect(()=>{l(true);},[]);let d=ka.useCallback(u=>{r?.(u.target.value);},[r]),c=ka.useMemo(()=>t?t.trim().split(/\s+/).filter(Boolean).length:0,[t]),m=t?.length||0;return i?jsxRuntime.jsxs("div",{className:"kyro-form-field",style:{position:"relative",zIndex:10,pointerEvents:"auto"},children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[c," words \u2022 ",m," chars"]}),jsxRuntime.jsxs("div",{className:"flex rounded-md overflow-hidden border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>s(false),className:`px-3 py-1 text-xs font-medium transition-colors ${n?"bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]":"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]"}`,children:"Write"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(true),className:`px-3 py-1 text-xs font-medium transition-colors ${n?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,children:"Preview"})]})]})]}),jsxRuntime.jsx("div",{style:{pointerEvents:"auto",position:"relative",zIndex:50},className:`border border-[var(--kyro-border)] rounded-md overflow-hidden ${a?"opacity-50 cursor-not-allowed":""} ${o?"border-[var(--kyro-error)]":""}`,children:n?jsxRuntime.jsx("div",{className:"p-6 min-h-[300px] overflow-auto bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)]",children:t?jsxRuntime.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",dangerouslySetInnerHTML:{__html:tm(t)}}):jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-muted)] italic",children:"Nothing to preview"})}):jsxRuntime.jsx("textarea",{value:t??"",onChange:d,disabled:a,rows:12,style:{pointerEvents:"auto",cursor:"text",zIndex:100},className:"w-full p-4 font-mono text-sm resize-y focus:outline-none bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)]",placeholder:`Enter markdown content...
84
84
 
85
85
  # Heading 1
86
86
  ## Heading 2
@@ -96,14 +96,14 @@
96
96
 
97
97
  \`\`\`
98
98
  code block
99
- \`\`\``})}),!n&&jsxRuntime.jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsx("span",{children:"**bold**"}),jsxRuntime.jsx("span",{children:"*italic*"}),jsxRuntime.jsx("span",{children:"`code`"}),jsxRuntime.jsx("span",{children:"[link](url)"}),jsxRuntime.jsx("span",{children:"# heading"})]}),e.admin?.description&&!o&&jsxRuntime.jsx("p",{className:"kyro-form-help",children:e.admin.description}),o&&jsxRuntime.jsx("p",{className:"kyro-form-error",children:o})]}):jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsx("div",{className:"h-[200px] bg-[var(--kyro-surface)] animate-pulse rounded-md border border-[var(--kyro-border)]"})]})};function Cn({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false),[i,l]=ka.useState(false),d=t??"",c=d.length>8?d.slice(0,-8)+"*".repeat(8):d,m=async()=>{if(d)try{await navigator.clipboard.writeText(d),s(!0),setTimeout(()=>s(!1),1800);}catch{let g=document.createElement("textarea");g.value=d,g.style.position="fixed",g.style.opacity="0",document.body.appendChild(g),g.select(),document.execCommand("copy"),document.body.removeChild(g),s(true),setTimeout(()=>s(false),1800);}},y=()=>{if(i||a)return;l(true);let g=new Uint8Array(32);crypto.getRandomValues(g);let x=Array.from(g).map(f=>f.toString(16).padStart(2,"0")).join("");r?.(x),setTimeout(()=>l(false),400);};return jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("div",{className:"relative flex-1",children:jsxRuntime.jsx("input",{id:e.name,type:"text",value:c,readOnly:true,disabled:a,className:"kyro-form-input font-mono text-xs tracking-wider pr-10 opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed select-none",spellCheck:false})}),jsxRuntime.jsx("button",{type:"button",onClick:m,disabled:!d||a,className:"p-2 rounded-lg border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] hover:bg-[var(--kyro-primary-alpha)] transition-all disabled:opacity-40 disabled:cursor-not-allowed active:scale-95",title:n?"Copied!":"Copy full secret",children:n?jsxRuntime.jsx(lucideReact.Check,{className:"w-3.5 h-3.5 text-[var(--kyro-success)]"}):jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("button",{type:"button",onClick:y,disabled:a,className:"p-2 rounded-lg border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-warning)] hover:bg-[var(--kyro-warning)]/10 transition-all disabled:opacity-40 disabled:cursor-not-allowed active:scale-95",title:"Regenerate secret",children:jsxRuntime.jsx(lucideReact.RefreshCw,{className:`w-3.5 h-3.5 ${i?"animate-spin":""}`})})]})})}var Sn=null,Al=false,Ts=async()=>(Sn&&Al||(Sn=unstorage.createStorage({driver:pm__default.default({dbName:"kyro-autosave",storeName:"autosave"})}),Al=true),Sn),mm=()=>typeof window>"u"?{getItem:async()=>null,setItem:async()=>{},removeItem:async()=>{}}:{getItem:async e=>{try{return await(await Ts()).getItem(e)??null}catch(t){return console.error("Storage getItem error:",t),localStorage.getItem(e)}},setItem:async(e,t)=>{try{await(await Ts()).setItem(e,t);}catch(r){console.error("Storage setItem error:",r),localStorage.setItem(e,t);}},removeItem:async e=>{try{await(await Ts()).removeItem(e);}catch(t){console.error("Storage removeItem error:",t),localStorage.removeItem(e);}}},Le=zustand.create()(middleware.persist((e,t)=>({formData:{},lastSavedData:{},sidebarCollapsed:false,draftCache:{},dirtyFields:new Set,activeTab:0,isSlugLocked:true,view:"edit",isDropdownOpen:false,versions:[],loadingVersions:false,showPreview:false,isMenuOpen:false,hasUnsavedChanges:false,loadingFields:{},compareMode:false,compareSelected:[],compareDiffs:[],loadingDiffs:false,isAutoSaving:false,autoSaveStatus:"idle",backgroundProcessing:false,lastAutoSaveTime:0,lastSavedAt:null,retryCount:0,autoSaveSkip:false,autoSaveTimer:null,setField:(r,o)=>{let a=t(),n=new Set(a.dirtyFields);JSON.stringify(o)!==JSON.stringify(a.lastSavedData[r])?n.add(r):n.delete(r),e({formData:{...a.formData,[r]:o},dirtyFields:n,hasUnsavedChanges:n.size>0});},setFormData:r=>{e({formData:r});},setNestedField:(r,o)=>{e(a=>{let n=r.split("."),s={...a.formData},i=s;for(let l=0;l<n.length-1;l++)i[n[l]]===void 0&&(i[n[l]]={}),i[n[l]]={...i[n[l]]},i=i[n[l]];return i[n[n.length-1]]=o,{formData:s}});},setActiveTab:r=>e({activeTab:r}),setIsSlugLocked:r=>e(o=>({isSlugLocked:typeof r=="function"?r(o.isSlugLocked):r})),setView:r=>e({view:r}),setIsDropdownOpen:r=>e(o=>({isDropdownOpen:typeof r=="function"?r(o.isDropdownOpen):r})),setVersions:r=>e({versions:r}),setLoadingVersions:r=>e({loadingVersions:r}),setShowPreview:r=>e(o=>({showPreview:typeof r=="function"?r(o.showPreview):r})),setIsMenuOpen:r=>e(o=>({isMenuOpen:typeof r=="function"?r(o.isMenuOpen):r})),setHasUnsavedChanges:r=>e({hasUnsavedChanges:r}),setLoadingFields:r=>e(o=>({loadingFields:typeof r=="function"?r(o.loadingFields):r})),updateLoadingField:(r,o)=>e(a=>({loadingFields:{...a.loadingFields,[r]:o}})),setCompareMode:r=>e({compareMode:r}),setCompareSelected:r=>e(o=>({compareSelected:typeof r=="function"?r(o.compareSelected):r})),setCompareDiffs:r=>e({compareDiffs:r}),setLoadingDiffs:r=>e({loadingDiffs:r}),setIsAutoSaving:r=>e({isAutoSaving:r}),setAutoSaveStatus:r=>e({autoSaveStatus:r}),setBackgroundProcessing:r=>e({backgroundProcessing:r}),setSidebarCollapsed:r=>e({sidebarCollapsed:r}),setLastSavedAt:r=>e({lastSavedAt:r}),setRetryCount:r=>e({retryCount:r}),setAutoSaveSkip:r=>e({autoSaveSkip:r}),setLastAutoSaveTime:r=>e({lastAutoSaveTime:r}),startAutoSaveTimer:(r,o)=>{let{autoSaveTimer:a}=t();a&&clearTimeout(a);let n=setTimeout(r,o);e({autoSaveTimer:n});},clearAutoSaveTimer:()=>{let{autoSaveTimer:r}=t();r&&(clearTimeout(r),e({autoSaveTimer:null}));},markSaved:()=>{let{formData:r}=t();e({lastSavedData:r,hasUnsavedChanges:false,dirtyFields:new Set,lastSavedAt:Date.now()});},setLastSavedData:r=>{e({lastSavedData:r});},resetForm:()=>{e({formData:{},lastSavedData:{},hasUnsavedChanges:false,dirtyFields:new Set,activeTab:0});},loadDocument:(r,o)=>{let a=t();a.formData===r&&a.lastSavedData===(o||r)&&!a.hasUnsavedChanges||e({formData:r,lastSavedData:o||r,hasUnsavedChanges:false,dirtyFields:new Set});},getField:r=>t().formData[r],getNestedField:r=>{let o=r.split("."),a=t().formData;for(let n of o){if(a==null)return;a=a[n];}return a},getHasChanges:()=>t().dirtyFields.size>0,hasDirtyFields:()=>t().dirtyFields.size>0,getDirtyData:()=>{let{formData:r,dirtyFields:o}=t(),a={};for(let n of o)a[n]=r[n];return a},clearDirtyFields:()=>{e({dirtyFields:new Set,hasUnsavedChanges:false});},pruneExpiredDrafts:()=>{let o=Date.now(),{draftCache:a}=t(),n={};for(let[s,i]of Object.entries(a))o-new Date(i.draftUpdatedAt).getTime()<6048e5&&(n[s]=i);e({draftCache:n});},setDraftCache:(r,o)=>e(a=>({draftCache:{...a.draftCache,[r]:o}})),getDraftCache:r=>t().draftCache[r]||null,clearDraftCache:r=>e(o=>{let a={...o.draftCache};return delete a[r],{draftCache:a}})}),{name:"kyro-autoform-storage",storage:middleware.createJSONStorage(()=>mm()),partialize:e=>({sidebarCollapsed:e.sidebarCollapsed,draftCache:e.draftCache}),onRehydrateStorage:()=>e=>{e&&e.pruneExpiredDrafts();}}));function Tn(e){return e?e.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function jo({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.variant==="textarea",i=e.name==="slug",{isSlugLocked:l,setIsSlugLocked:d,formData:c}=Le(),m=e.variant==="email"?"email":e.variant==="password"?"password":e.variant==="url"?"url":"text",y=t==null?"":String(t),g={id:e.name,value:y,onChange:x=>r?.(x.target.value),placeholder:e.admin?.placeholder,disabled:a||n||i&&l,minLength:e.minLength,maxLength:e.maxLength,required:e.required,className:`kyro-form-input ${i?"pr-24":""} ${a||n||i&&l?"opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed":""}`};return jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"relative",children:[s?jsxRuntime.jsx("textarea",{...g,rows:e.rows||4}):jsxRuntime.jsx("input",{type:m,...g,pattern:e.pattern}),i&&jsxRuntime.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:[!l&&jsxRuntime.jsx("button",{type:"button",onClick:()=>r?.(Tn(c[e.admin?.autoGenerate||"title"]||"")),className:"p-1 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)]",title:"Regenerate slug",children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),jsxRuntime.jsx("path",{d:"M21 3v5h-5"})]})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>d(!l),className:`p-1.5 rounded transition-colors ${l?"text-[var(--kyro-primary)] bg-[var(--kyro-primary-alpha)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,title:l?"Unlock slug":"Lock slug",children:l?jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsxRuntime.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}):jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsxRuntime.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})})]}),e.name?.toLowerCase().includes("metatitle")&&jsxRuntime.jsx("div",{className:"flex items-center justify-between mt-1 text-[10px] font-bold tracking-wider",children:jsxRuntime.jsxs("span",{className:y.length>60?"text-red-500":y.length>=40?"text-green-500":"text-amber-600",children:[y.length," / 60 \u2014 ",y.length>60?"Too Long":y.length>=40?"Ideal":"Short"]})})]})})}function An({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsx("input",{type:"number",id:e.name,value:t??"",onChange:s=>r?.(parseFloat(s.target.value)||0),placeholder:e.admin?.placeholder,disabled:a||n,min:e.min,max:e.max,step:e.step||(e.integer?1:"any"),required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`})})}function Rn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(st,{field:e,error:o,hideLabel:true,children:jsxRuntime.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer group py-0.5",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:t??false,onChange:i=>r?.(i.target.checked),disabled:a||n,className:`w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)] transition-all ${a||n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`}),jsxRuntime.jsxs("span",{className:"text-sm font-semibold text-[var(--kyro-text-primary)] tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors",children:[e.label||e.name,e.required&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})]})})}function Fn({field:e,value:t="",onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsx("input",{type:e.time?"datetime-local":"date",id:e.name,value:t??"",onChange:s=>r?.(s.target.value),disabled:a||n,min:e.minDate,max:e.maxDate,required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`})})}function Fa(e){return e?Array.isArray(e)?e:Object.values(e):[]}function Dn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Bn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Ra(e,t){let r=new Set(e.map(o=>o.slug));for(let o of t)r.has(o.slug)||(e.push(o),r.add(o.slug));}var ym={pages:"FileText",posts:"Newspaper",categories:"Tags",menu:"Menu",products:"ShoppingBag",customers:"Users",orders:"ShoppingCart",coupons:"Ticket",forms:"FileInput","form-entries":"Inbox"};function vo(e,t,r){let o=t.split(".");if(o.length===0)return false;let a=o[0],n=o.slice(1).join(".");for(let s of e){if(s.name===a)if(n){if(s.fields&&Array.isArray(s.fields))return vo(s.fields,n,r);if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&vo(l.fields,n,r))return true;return false}if(s.type==="blocks"&&s.blocks&&Array.isArray(s.blocks)){let l=n.split(".")[0],d=n.split(".").slice(1).join(".");if(!d)return false;for(let c of s.blocks)if(c.slug===l&&c.fields&&Array.isArray(c.fields))return vo(c.fields,d,r);return false}return s.type==="array"&&s.fields&&Array.isArray(s.fields)?vo(s.fields,n,r):false}else return Object.assign(s,r),true;if(!s.name||s.type==="tabs"||s.type==="row"||s.type==="collapsible"){if(s.fields&&Array.isArray(s.fields)&&vo(s.fields,t,r))return true;if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&vo(l.fields,t,r))return true}}}return false}function fm(e,t){for(let[r,o]of Object.entries(e)){let a=ym[r],n=t?.[r];if(a&&!o.admin?.icon&&(o.admin={...o.admin,icon:a}),n){let{fields:s,...i}=n;if(o.admin={...o.admin,...i},s&&o.fields&&Array.isArray(o.fields))for(let[l,d]of Object.entries(s))vo(o.fields,l,d);}}}function vm(e="blog"){let t=[],r=[];switch(e){case "minimal":t.push(...Object.values(templates.minimalCollections)),r.push(...templates.coreSettingsGlobals);break;case "starter":t.push(...Object.values(templates.starterCollections)),r.push(...templates.coreSettingsGlobals);break;case "blog":t.push(...Object.values(templates.blogCollections)),r.push(...templates.coreSettingsGlobals);break;case "ecommerce":t.push(...Object.values(templates.ecommerceCollections)),r.push(...templates.allSettingsGlobals);break;case "kitchen-sink":t.push(...Object.values(templates.minimalCollections),...Object.values(templates.starterCollections),...Object.values(templates.blogCollections),...Object.values(templates.ecommerceCollections),...Object.values(templates.kitchenSinkCollections)),r.push(...templates.allSettingsGlobals);break}return Ra(t,Object.values(templates.mediaCollections)),Ra(t,Object.values(templates.authCollections)),{collections:Dn(t),globals:Bn(r)}}function gm(e){let t=Fa(e.collections),r=Fa(e.globals);if(t.length===0&&r.length===0)return vm("kitchen-sink");let o=[];return Ra(o,Object.values(templates.mediaCollections)),Ra(o,Object.values(templates.authCollections)),Ra(o,t),{collections:Dn(o),globals:Bn(r)}}var Pn=null;function bm(){if(Pn)return Pn;try{if(typeof __KYRO_ADMIN_CONFIG_FILE__=="string"&&Ro__default.default.existsSync(__KYRO_ADMIN_CONFIG_FILE__))return Pn=JSON.parse(Ro__default.default.readFileSync(__KYRO_ADMIN_CONFIG_FILE__,"utf8")),Pn}catch{}return null}var Ul=bm()||{collections:[],globals:[]},zl=gm(Ul);fm(zl.collections,Ul.collectionOverrides);var jl=zl,Ho=jl.collections,Hl=jl.globals,Fs=["users","audit_logs"];Object.values(Ho).filter(e=>!Fs.includes(e.slug)&&e.admin?.hidden!==true);function In({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.options||[];return e.dynamicOptions==="collections"&&(s=Object.keys(Ho).filter(i=>i!=="media").map(i=>({label:Ho[i]?.label||i,value:i}))),jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsxs("select",{id:e.name,value:e.hasMany?Array.isArray(t)?t:[]:t||"",onChange:i=>{if(e.hasMany){let l=Array.from(i.target.selectedOptions,d=>d.value);r?.(l);}else r?.(i.target.value||void 0);},multiple:e.hasMany,disabled:a||n,required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`,children:[!e.required&&!e.hasMany&&jsxRuntime.jsx("option",{value:"",children:"Select..."}),s.map(i=>jsxRuntime.jsx("option",{value:i.value,children:i.label},i.value))]})})}function Ln({icon:e,title:t,description:r,action:o}){return jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-3 justify-center py-16 px-8",children:[e&&jsxRuntime.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:e}),jsxRuntime.jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:t}),r&&jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:r}),o]})}function _l(e){let t=e?.mainTabs;return e?.title||t?.title||e?.name||e?.label||e?.email||e?.filename||e?.slug||"Untitled"}function hm({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false),[i,l]=ka.useState(""),[d,c]=ka.useState([]),[m,y]=ka.useState(false),[g,x]=ka.useState([]),f=ka.useRef(new Set),u=ka.useRef(null),b=ka.useRef(()=>{});b.current=r||(()=>{});let v=e.hasMany,R=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],L=R.length>1,[C,w]=ka.useState(R[0]||""),N=ka.useCallback(()=>t?(v?Array.isArray(t)?t:[]:t?[t]:[]).map(j=>typeof j=="object"&&j!==null?j.value||j.id||"":String(j)).filter(Boolean):[],[t,v]),p=ka.useCallback(M=>{M.length!==0&&M.forEach(j=>{if(f.current.has(j))return;f.current.add(j);let se=L?(()=>{if(!t)return C;let ue=(v?Array.isArray(t)?t:[]:[t]).find(oe=>typeof oe=="object"&&oe!==null?oe.value===j||oe.id===j:false);return ue&&typeof ue=="object"&&ue.relationTo||C})():C;Be(`/api/${se}/${j}`).then(ie=>{let ue=ie.data||ie;!ue||typeof ue!="object"||x(oe=>oe.some(ne=>ne.id===j)?oe:[...oe,{...ue,id:String(ue.id),relationTo:se}]);}).catch(()=>{});});},[L,t,C,v]);ka.useEffect(()=>{let M=N();p(M);},[N,p]);let A=ka.useCallback((M="")=>{y(true);let se=`/api/${C}?${Ja(M,["title","name","label","email"])}`;Be(se).then(ie=>{c(ue=>{let oe=new Set(ue.map(je=>je.id)),ne=(ie.docs||[]).filter(je=>!oe.has(je.id)).map(je=>({...je,id:je.id}));return [...ue,...ne]}),y(false);}).catch(()=>{y(false);});},[C]);ka.useEffect(()=>{n&&(c([]),A(i));},[n,C]),ka.useEffect(()=>{let M=j=>{u.current&&!u.current.contains(j.target)&&s(false);};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]);let O=M=>typeof M=="object"&&M!==null?M.value||M.id||"":String(M),F=M=>{let j=M.id;return t?v&&Array.isArray(t)?t.some(se=>O(se)===j):O(t)===j:false},P=M=>{let j=M.id;if(v){let se=Array.isArray(t)?t:[];if(F(M))b.current?.(se.filter(ie=>O(ie)!==j));else {let ie=L?{relationTo:C,value:j}:j;b.current?.([...se,ie]);}}else if(F(M))b.current?.(null);else {let se=L?{relationTo:C,value:j}:j;b.current?.(se),s(false),l("");}},S=()=>{if(!t)return null;let M=v?Array.isArray(t)?t:[]:t?[t]:[];return jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:M.map(j=>{let se=O(j),ie=g.find(ne=>ne.id===se),ue=ie?_l(ie):se.slice(0,12),oe=L&&ie?ie.relationTo:null;return jsxRuntime.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]",children:[oe&&jsxRuntime.jsxs("span",{className:"opacity-60 mr-0.5",children:[oe,":"]}),ue,!a&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{let ne=M.filter(je=>O(je)!==se);b.current?.(v?ne:ne[0]??null);},className:"hover:opacity-70",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},se)})})};return jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[e.label&&jsxRuntime.jsxs("label",{className:"block text-sm font-medium text-[var(--kyro-text-primary)]",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]}),jsxRuntime.jsxs("div",{ref:u,className:"relative",children:[L&&jsxRuntime.jsx("div",{className:"flex gap-1 mb-1.5",children:R.map(M=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{w(M),c([]),l("");},className:`px-2 py-0.5 text-[10px] font-bold rounded transition-colors ${C===M?"kyro-btn-primary":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:M},M))}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",value:i,onChange:M=>{l(M.target.value),s(true),A(M.target.value);},onFocus:()=>s(true),placeholder:e.admin?.placeholder||`Search ${C}...`,disabled:a||(typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly),className:"w-full pl-9 pr-10 py-2 border border-[var(--kyro-border)] rounded-md bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent disabled:opacity-50"}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:m?jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-4 h-4 text-[var(--kyro-text-muted)] transition-transform ${n?"rotate-180":""}`})})]}),n&&jsxRuntime.jsx("div",{className:"relative z-20 w-full mt-1 border border-[var(--kyro-border)] rounded-lg shadow-lg bg-[var(--kyro-surface)] max-h-64 overflow-auto",children:m?jsxRuntime.jsx("div",{className:"p-4 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsxRuntime.jsx(Ln,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:d.map(M=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>P(M),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors ${F(M)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{children:_l(M)}),F(M)&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-sidebar-active)]",children:"\u2713"})]}),"slug"in M&&typeof M.slug=="string"&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)]",children:M.slug})]},M.id))})}),S()]}),e.admin?.description&&!o&&jsxRuntime.jsx("p",{className:"text-xs text-[var(--kyro-text-muted)]",children:e.admin.description}),o&&jsxRuntime.jsx("p",{className:"text-xs text-[var(--kyro-error)]",children:o})]})}var Pa=hm;var go=ka.createContext(null);function Kl(e=[],t=[]){return vanilla.createStore((r,o)=>({blocks:[],allowedBlocks:e,dynamicCategories:t,setBlocks:a=>{let n=Ms(a||[]);r({blocks:n});},onBlocksChange:null,setOnBlocksChange:a=>r({onBlocksChange:a}),addBlock:(a,n)=>{let s=Vo(a),{blocks:i}=o(),l=[...i];n!==void 0?l.splice(n,0,s):l.push(s),r({blocks:l});let{onBlocksChange:d}=o();d&&d();},updateBlock:(a,n)=>{let{blocks:s}=o(),i=Da(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=[...l];return c[d]={...c[d],...n},{newList:c,found:true}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}},removeBlock:a=>{if(!a)return;let{blocks:n}=o(),s=Da(n,i=>{let l=i.filter(d=>d.id!==a);return l.length!==i.length?{newList:l,found:true}:{newList:i,found:false}});if(s!==n){r({blocks:s});let{onBlocksChange:i}=o();i&&i();}},moveBlock:(a,n)=>{let{blocks:s}=o(),i=Da(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=n==="up"?d-1:d+1;if(c>=0&&c<l.length){let m=[...l];return [m[d],m[c]]=[m[c],m[d]],{newList:m,found:true}}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}}}))}function Ms(e){return Array.isArray(e)?e.map(t=>{let r={...t,id:t.id||Math.random().toString(36).substr(2,9)};return r.children&&Array.isArray(r.children)&&(r.children=Ms(r.children)),r.data?.columnData&&Array.isArray(r.data.columnData)&&(r.data={...r.data,columnData:r.data.columnData.map(o=>({...o,children:o.children?Ms(o.children):o.children}))}),r}):[]}function Vo(e){let t=Sm(e),{options:r,children:o,...a}=t;return {id:Math.random().toString(36).substr(2,9),type:e,name:"",data:a,options:r,children:o,order:Date.now()}}function Sm(e){return {heading:{level:1,text:""},"heading-subheading":{heading:"",subheading:""},hero:{isMultiScreen:false},card:{title:"",description:"",icon:"",link:"",linkText:"",isMultiCard:false},paragraph:{text:""},divider:{},callout:{text:"",variant:"info"},image:{src:"",alt:"",caption:""},video:{src:"",title:""},list:{type:"unordered",items:""},code:{language:"plaintext",code:""},link:{url:"",text:""},table:{rows:3,columns:3,content:""},quote:{text:"",author:""},file:{filename:"",url:""},columns:{columns:2,direction:"horizontal"},vstack:{direction:"vertical",gap:"md"},container:{options:{backgroundColor:"transparent",padding:"md",width:"full",margin:"none",minHeight:"none",borderRadius:"none"},children:[]},button:{text:"Button",url:"",variant:"primary",size:"md"},accordion:{title:"Accordion Item",content:""},gallery:{images:[]},tabs:{tabs:[{label:"Tab 1",content:""}]}}[e]||{}}function Me(e){let t=ka.useContext(go);if(t)return zustand.useStore(t,r=>{let o=a=>{for(let n of a){if(n.id===e)return n;if(n.children&&n.children.length>0){let s=o(n.children);if(s)return s}if(n.data?.columnData){for(let s of n.data.columnData)if(s&&s.children&&s.children.length>0){let i=o(s.children);if(i)return i}}}};return o(r.blocks)})}function Ae(){let e=ka.useContext(go);if(!e)throw new Error("useBlockActions must be used within a BlocksContext.Provider");return {updateBlock:(t,r)=>e.getState().updateBlock(t,r),removeBlock:t=>e.getState().removeBlock(t),moveBlock:(t,r)=>e.getState().moveBlock(t,r)}}function Da(e,t){let{newList:r,found:o}=t(e);if(o)return r;let a=false,n=e.map(s=>{let i={...s},l=false;if(s.children&&s.children.length>0){let d=Da(s.children,t);d!==s.children&&(i.children=d,l=true);}if(s.data?.columnData&&Array.isArray(s.data.columnData)){let d=s.data.columnData.map(c=>{if(c.children&&c.children.length>0){let m=Da(c.children,t);if(m!==c.children)return {...c,children:m}}return c});d.some((c,m)=>c!==s.data.columnData[m])&&(i.data={...i.data,columnData:d},l=true);}return l&&(a=true),l?i:s});return a?n:e}function Ia({open:e,onClose:t,onSelect:r,children:o}){return e?jsxRuntime.jsxs(dr,{open:e,onClose:t,title:"Insert Block",width:"md",children:[jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-muted)] mb-4",children:"Drag blocks into the editor or click to insert"}),o]}):null}function Gl({block:e,onSelect:t,children:r}){let{attributes:o,listeners:a,setNodeRef:n,isDragging:s}=core.useDraggable({id:`drawer-${e.type}`,data:{source:"drawer",blockType:e.type}});return jsxRuntime.jsxs("div",{ref:n,...a,...o,onClick:()=>t(e.type),className:`flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group ${s?"opacity-50 border-[var(--kyro-primary)]":""}`,style:{opacity:s?.5:1},children:[jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all duration-300",children:r||jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]"})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)] leading-tight",children:e.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 leading-tight",children:e.description})]})]})}var Es=({text:e="",onChange:t,compact:r=false})=>jsxRuntime.jsx("div",{className:r?"":"space-y-3",children:jsxRuntime.jsx("input",{type:"text",value:e,onChange:a=>t("text",a.target.value),className:r?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Enter heading text..."})});var Pr=({id:e,type:t,label:r,children:o,className:a=""})=>{let{moveBlock:n,removeBlock:s}=Ae();return jsxRuntime.jsxs("div",{className:`block-${t} border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group bg-[var(--kyro-surface)] transition-all hover:border-[var(--kyro-primary)]/30 ${a}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] tracking-wider",children:r||t}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-muted)] hover:text-[var(--kyro-primary)]",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-muted)] hover:text-[var(--kyro-primary)]",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(e),className:"p-1 hover:bg-[var(--kyro-error)]/10 rounded text-[var(--kyro-error)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx("div",{className:"block-content",children:o})]})};var Jl=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o}=Ae(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsxRuntime.jsx(Pr,{id:e.id,type:"heading",label:"Heading",children:jsxRuntime.jsx(Es,{text:a.text||"",onChange:n,compact:true})})};var Ql=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o}=Ae(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsxRuntime.jsx(Pr,{id:e.id,type:"paragraph",label:"Paragraph",children:jsxRuntime.jsx("textarea",{value:a.text||"",onChange:s=>n("text",s.target.value),className:"w-full px-3 py-3 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm min-h-[100px] resize-none",placeholder:"Enter paragraph text..."})})};var Yl=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data||e.data||{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-image border border-[var(--kyro-border)] rounded-lg p-4 mb-4 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Image"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Image Asset"}),jsxRuntime.jsx(lr,{field:{label:"Image Asset",name:"src",maxCount:1},value:s.src,onChange:l=>i("src",l)})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Alt Text"}),jsxRuntime.jsx("input",{type:"text",value:s.alt||"",onChange:l=>i("alt",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Alternative text..."})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Caption"}),jsxRuntime.jsx("input",{type:"text",value:s.caption||"",onChange:l=>i("caption",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Image caption..."})]})]})]})};var Us=({src:e="",title:t="",onChange:r,onUploadChange:o,compact:a=false})=>{e.includes("youtube.com")||e.includes("vimeo.com")||e.includes("youtu.be");return a?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("input",{type:"url",value:e,onChange:s=>r("src",s.target.value),className:"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"MP4 URL, YouTube, or Vimeo link..."}),jsxRuntime.jsx("input",{type:"text",value:t,onChange:s=>r("title",s.target.value),className:"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Video title (optional)..."})]}):jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx(lr,{field:{label:"Video Asset",name:"src",maxCount:1},value:e,onChange:o||(s=>r("src",s))}),jsxRuntime.jsx("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:"or paste a URL"}),jsxRuntime.jsx("input",{type:"url",value:e,onChange:s=>r("src",s.target.value),className:"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"MP4 URL, YouTube, or Vimeo link..."}),jsxRuntime.jsx("input",{type:"text",value:t,onChange:s=>r("title",s.target.value),className:"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Video title (optional)..."})]})};var ed=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-video border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Video"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(Us,{src:s.src||"",title:s.title||"",onChange:i,onUploadChange:l=>i("src",l),compact:true})]})};var La=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=ka__default.default.useState(""),n=()=>{o.trim()&&(t([...e,o.trim()]),a(""));},s=d=>{d.key==="Enter"&&(d.preventDefault(),n());},i=d=>{t(e.filter((c,m)=>m!==d));},l=r?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded-md bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxRuntime.jsxs("div",{className:r?"space-y-1.5":"space-y-2",children:[e.length===0?jsxRuntime.jsx("div",{className:"text-center py-4 text-[var(--kyro-text-muted)] text-sm border border-dashed border-[var(--kyro-border)] rounded-md",children:"No items. Type below to add."}):jsxRuntime.jsx("div",{className:"space-y-1",children:e.map((d,c)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-2 group/item",children:[jsxRuntime.jsxs("span",{className:"text-sm text-[var(--kyro-text-primary)] flex-1",children:["\u2022 ",d]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>i(c),className:"opacity-0 group-hover/item:opacity-100 p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",children:"\xD7"})]},c))}),jsxRuntime.jsx("input",{type:"text",value:o,onChange:d=>a(d.target.value),onKeyDown:s,className:l,placeholder:"Type and press Enter to add..."})]})};var td=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data||e.data||{},i=Array.isArray(s.items)?s.items:[];return jsxRuntime.jsxs("div",{className:"block-list border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"List"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(La,{items:i,onChange:d=>{o(e.id,{data:{...s,items:d}});},compact:true})]})};var rd=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"group/block relative border border-[var(--kyro-border)] rounded-2xl p-6 mb-6 transition-all duration-300 bg-[var(--kyro-surface)] hover:border-[var(--kyro-primary)]/20",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"w-9 h-9 rounded-xl bg-[var(--kyro-primary)]/10 flex items-center justify-center text-[var(--kyro-primary)] transition-transform group-hover/block:scale-110",children:jsxRuntime.jsx(lucideReact.CodeXml,{className:"w-5 h-5"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Code Snippet"}),jsxRuntime.jsxs("p",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] tracking-widest",children:["Block Editor \u2022 ",s.language||"javascript"]})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-1.5 opacity-0 group-hover/block:opacity-100 transition-all translate-x-2 group-hover/block:translate-x-0",children:jsxRuntime.jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)]/50 p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1.5 hover:bg-[var(--kyro-surface)] rounded-lg transition-all text-[var(--kyro-text-muted)] hover:text-[var(--kyro-primary)]",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4 rotate-[-90deg]"})}),jsxRuntime.jsx("div",{className:"w-px h-4 bg-[var(--kyro-border)] mx-1 self-center"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1.5 hover:bg-[var(--kyro-danger-bg)] rounded-lg transition-all text-[var(--kyro-text-muted)] hover:text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]})})]}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx(Aa,{field:{type:"code",name:"code",label:"Source Code",language:s.language||"javascript"},value:s.code||"",onChange:l=>i("code",l)}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 bg-[var(--kyro-surface-accent)]/20 p-4 rounded-xl border border-[var(--kyro-border)]/50",children:[jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2 block",children:"Syntax Highlighting"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("select",{value:s.language||"javascript",onChange:l=>i("language",l.target.value),className:"w-full pl-4 pr-10 py-2.5 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl text-xs font-medium text-[var(--kyro-text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)]/20 focus:border-[var(--kyro-primary)] transition-all appearance-none cursor-pointer",children:[jsxRuntime.jsx("option",{value:"plaintext",children:"Plain Text"}),jsxRuntime.jsx("option",{value:"javascript",children:"JavaScript"}),jsxRuntime.jsx("option",{value:"typescript",children:"TypeScript"}),jsxRuntime.jsx("option",{value:"python",children:"Python"}),jsxRuntime.jsx("option",{value:"json",children:"JSON"}),jsxRuntime.jsx("option",{value:"html",children:"HTML"}),jsxRuntime.jsx("option",{value:"css",children:"CSS"}),jsxRuntime.jsx("option",{value:"sql",children:"SQL"}),jsxRuntime.jsx("option",{value:"rust",children:"Rust"}),jsxRuntime.jsx("option",{value:"markdown",children:"Markdown"})]}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--kyro-text-muted)]",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4 rotate-90"})})]})]}),jsxRuntime.jsx("div",{className:"hidden sm:block w-px h-10 bg-[var(--kyro-border)]"}),jsxRuntime.jsxs("div",{className:"hidden sm:flex flex-col justify-center",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2",children:"Status"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl",children:[jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500 animate-pulse"}),jsxRuntime.jsx("span",{className:"text-[10px] font-medium text-[var(--kyro-text-primary)] tracking-wide",children:"EDITING"})]})]})]})]})]})};var od=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-file border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"File"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(lr,{field:{label:"File",name:"file",maxCount:1},value:s.file,onChange:l=>i("file",l)})]})};var Vs=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=ka__default.default.useState(0),n=(m,y)=>{let g=[...e];g[m]={...g[m],title:y},t(g);},s=(m,y)=>{let g=[...e];g[m]={...g[m],content:y},t(g);},i=m=>{let y=e.filter((g,x)=>x!==m);t(y),o===m?a(null):o!==null&&o>m&&a(o-1);},l=()=>{t([...e,{title:`Item ${e.length+1}`,content:""}]),a(e.length);},d="w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",c="w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return r?jsxRuntime.jsxs("div",{className:"space-y-2",children:[e.length===0?jsxRuntime.jsx("div",{className:"text-center py-4 text-[var(--kyro-text-muted)] text-sm border border-dashed border-[var(--kyro-border)] rounded-md",children:'No items. Click "Add Item" to create one.'}):jsxRuntime.jsx("div",{className:"space-y-1.5",children:e.map((m,y)=>{let g=o===y;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(g?null:y),className:"w-full flex items-center justify-between p-2.5 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${y+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),i(y);},className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5"})}),g?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),g&&jsxRuntime.jsxs("div",{className:"p-2.5 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:m.title||"",onChange:x=>n(y,x.target.value),onClick:x=>x.stopPropagation(),className:c,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:m.content||"",onChange:x=>s(y,x.target.value),onClick:x=>x.stopPropagation(),className:`${c} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},y)})}),jsxRuntime.jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]}):jsxRuntime.jsxs("div",{className:"space-y-2",children:[e.length===0?jsxRuntime.jsx("div",{className:"text-center py-4 text-[var(--kyro-text-muted)] text-sm border border-dashed border-[var(--kyro-border)] rounded-md",children:'No items. Click "Add Item" to create one.'}):jsxRuntime.jsx("div",{className:"space-y-2",children:e.map((m,y)=>{let g=o===y;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(g?null:y),className:"w-full flex items-center justify-between p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${y+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),i(y);},className:"opacity-0 group-hover:opacity-100 p-1.5 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})}),g?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),g&&jsxRuntime.jsxs("div",{className:"p-3 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:m.title||"",onChange:x=>n(y,x.target.value),className:d,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:m.content||"",onChange:x=>s(y,x.target.value),className:`${d} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},y)})}),jsxRuntime.jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]})};var ad=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data??e.data??{},i=Array.isArray(s.items)?s.items:[],l=d=>{o(e.id,{data:{...s,items:d}});};return jsxRuntime.jsxs("div",{className:"block-accordion border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Accordion"}),jsxRuntime.jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(Vs,{items:i,onChange:l,compact:true})]})};var nd=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data||e.data||{},i=l=>{o(e.id,{data:{...s,content:l}});};return jsxRuntime.jsxs("div",{className:"block-richtext border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.AlignLeft,{className:"w-3.5 h-3.5 text-[var(--kyro-primary)]"}),jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Rich Text"})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx($o,{field:{name:"content",label:"Content",type:"richtext"},value:s.content,onChange:i})]})};var Ks=({heading:e="",subheading:t="",ctaText:r="",ctaUrl:o="",onChange:a,compact:n=false})=>{let s=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",i=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return n?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsxRuntime.jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]}):jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsxRuntime.jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]})};function On({field:e,value:t,onChange:r,renderField:o}){let a=t||{};return jsxRuntime.jsxs("div",{className:"kyro-form-group border border-[var(--kyro-border)] rounded-[var(--kyro-radius-lg)] p-6 bg-[var(--kyro-surface-accent)]/30",children:[jsxRuntime.jsx("h3",{className:"text-sm font-bold tracking-widest text-[var(--kyro-text-primary)] mb-6 border-b border-[var(--kyro-border)] pb-2 inline-block",children:e.label||e.name}),jsxRuntime.jsx("div",{className:e.admin?.inline?"flex items-start gap-4":"space-y-6",children:e.fields.map(n=>o(n,a,r))})]})}var Dm=new Set(["text","textarea","number","checkbox","select","radio","color","email","password","code","markdown","upload"]);function Bm(e){let t=e.fields||[];return t.length===0||t.length>4?false:t.every(r=>Dm.has(r.type))}function Un({field:e,value:t,onChange:r,renderField:o,disabled:a}){let n=Array.isArray(t)?t:[],s=e.fields||[],i=s[0],l=i?.name||"user",d=i?.type==="relationship",[c,m]=ka__default.default.useState(0);function y(x){for(let f of ["label","title","name"]){let u=x[f];if(u&&typeof u=="string")return u}for(let f of s){if(f.type==="text"||f.type==="textarea"){let u=x[f.name];if(u&&typeof u=="string")return u}if(f.type==="group"&&f.fields){for(let u of f.fields)if(u.type==="text"||u.type==="textarea"){let v=x[f.name]?.[u.name];if(v&&typeof v=="string")return v}}}return ""}let g=Bm(e);return jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),d?jsxRuntime.jsx(Pa,{field:{name:l,relationTo:e.fields?.[0]?.relationTo||"",hasMany:true,label:e.fields?.[0]?.label},value:n.map(x=>x[l]).filter(Boolean),onChange:x=>{let f=(x||[]).map(u=>({[l]:u}));r(f);},disabled:a}):g?jsxRuntime.jsxs("div",{className:"kyro-form-array kyro-form-array--compact border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30 rounded-md overflow-hidden",children:[n.map((x,f)=>jsxRuntime.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 border-b border-[var(--kyro-border)] last:border-b-0 hover:bg-[var(--kyro-sidebar-active)]/5 transition-colors",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] pt-2 min-w-[18px] text-center",children:f+1}),jsxRuntime.jsx("div",{className:"flex-1 flex items-start gap-1.5 min-w-0",children:e.fields.map(u=>jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:o(u,x,b=>{let v=[...n];v[f]=b,r(v);})},u.name))}),jsxRuntime.jsx("button",{type:"button",disabled:a,onClick:()=>r(n.filter((u,b)=>b!==f)),className:"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] transition-colors disabled:opacity-30 p-0.5 mt-1.5 flex-shrink-0",title:"Remove",children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f)),jsxRuntime.jsx("button",{type:"button",className:"w-full py-2 border-2 border-dashed border-[var(--kyro-border)] rounded-none text-xs font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:border-[var(--kyro-primary)] transition-all disabled:opacity-50",disabled:a,onClick:()=>r([...n,{}]),children:"+ Add Item"})]}):jsxRuntime.jsxs("div",{className:"kyro-form-array border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30 rounded-md p-3 space-y-4",children:[n.map((x,f)=>{let u=c===f;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("div",{role:"button",tabIndex:0,onClick:()=>m(u?null:f),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),m(u?null:f));},className:"w-full flex items-center justify-between p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors cursor-pointer",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold tracking-widest text-[var(--kyro-text-muted)] truncate",children:y(x)||`Item ${f+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",disabled:a,onClick:b=>{b.stopPropagation(),r(n.filter((v,R)=>R!==f));},className:"text-[11px] font-bold text-[var(--kyro-error)] opacity-0 group-hover:opacity-100 transition-opacity disabled:opacity-30 hover:bg-[var(--kyro-danger-bg)] rounded px-1.5 py-0.5",children:"Remove"}),u?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),u&&jsxRuntime.jsx("div",{className:"p-4 bg-[var(--kyro-surface)] space-y-4",children:e.fields.map(b=>o(b,x,v=>{let R=[...n];R[f]=v,r(R);}))})]},f)}),jsxRuntime.jsx("button",{type:"button",className:"w-full py-3 border-2 border-dashed border-[var(--kyro-border)] rounded-lg text-xs font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:border-[var(--kyro-primary)] transition-all disabled:opacity-50",disabled:a,onClick:()=>r([...n,{}]),children:"+ Add Item"})]})]})}var id="other";function ld(){return id}function zn(e){id=e;}var xo=({field:e,value:t,onChange:r,error:o,disabled:a})=>{if(e.hidden===true||e.admin?.hidden===true)return null;let n=s=>{zn("keystroke"),r(s);};switch(e.type){case "text":case "email":case "url":return jsxRuntime.jsx(jo,{field:e,value:t,onChange:n,error:o,disabled:a});case "textarea":return jsxRuntime.jsx(jo,{field:{...e,variant:"textarea"},value:t,onChange:n,error:o,disabled:a});case "password":return jsxRuntime.jsx(jo,{field:{...e,variant:"password"},value:t,onChange:n,error:o,disabled:a});case "secret":return jsxRuntime.jsx(Cn,{field:e,value:t,onChange:r,error:o,disabled:a});case "number":return jsxRuntime.jsx(An,{field:e,value:t,onChange:r,disabled:a,error:o});case "checkbox":return jsxRuntime.jsx(Rn,{field:e,value:t,onChange:r,disabled:a,error:o});case "select":return jsxRuntime.jsx(In,{field:e,value:t,onChange:r,disabled:a,error:o});case "date":return jsxRuntime.jsx(Fn,{field:e,value:t,onChange:r,disabled:a,error:o});case "richtext":return jsxRuntime.jsx($o,{field:e,value:t,onChange:n,disabled:a,error:o});case "markdown":return jsxRuntime.jsx(Ss,{field:e,value:t,onChange:n,disabled:a,error:o});case "code":return jsxRuntime.jsx(Aa,{field:e,value:t,onChange:n,disabled:a,error:o});case "image":case "upload":return jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsx(lr,{field:e,value:t,onChange:r,disabled:a})});case "relationship":return jsxRuntime.jsx(Pa,{field:e,value:t,onChange:r,disabled:a,error:o});case "list":return jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsx(La,{items:Array.isArray(t)?t:[],onChange:r,compact:true})});case "array":return jsxRuntime.jsx(Un,{field:e,value:Array.isArray(t)?t:[],onChange:r,disabled:a,renderField:(s,i,l)=>{let d=i[s.name];return jsxRuntime.jsx(xo,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "blocks":return jsxRuntime.jsx(Gs,{field:e,value:t,onChange:n,disabled:a,error:o});case "group":return jsxRuntime.jsx(On,{field:e,value:t,onChange:r,renderField:(s,i,l)=>{let d=i[s.name];return jsxRuntime.jsx(xo,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "color":return jsxRuntime.jsx(st,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("input",{type:"color",value:t||"#000000",onChange:s=>r(s.target.value),disabled:a,className:"h-10 w-14 p-1 cursor-pointer bg-[var(--kyro-input-bg)] border border-[var(--kyro-input-border)] rounded-lg"}),jsxRuntime.jsx("input",{type:"text",className:"kyro-form-input font-mono ",value:t||"",onChange:s=>r(s.target.value),disabled:a,placeholder:"#000000"})]})});default:return jsxRuntime.jsxs("div",{className:"p-4 bg-amber-50 border border-amber-200 rounded-lg text-amber-800 text-xs italic",children:['Field type "',e.type,'" is not yet supported in this renderer.']})}};var Wo=({block:e,blockSchema:t,onClose:r})=>{let o=Me(e.id),{updateBlock:a}=Ae(),n=o?.data||e.data||{},s=o?.children||e.children||[],i=(m,y)=>{a(e.id,{data:{...n,[m]:y}});},l=m=>{a(e.id,{children:m});},d=()=>t&&Array.isArray(t.fields)?jsxRuntime.jsx("div",{className:"space-y-4 pt-2",children:t.fields.map(m=>{if(m.admin?.condition){if(typeof m.admin.condition=="function")try{let g={values:n,...n};if(!m.admin.condition(g,g))return null}catch(g){console.warn(`Condition error for field ${m.name}:`,g);}else if(typeof m.admin.condition=="object")try{let g=m.admin.condition,x=g.field,f=n[x],u=!0;if("equals"in g?u=f===g.equals:"notEquals"in g?u=f!==g.notEquals:"in"in g&&Array.isArray(g.in)&&(u=g.in.includes(f)),!u)return null}catch(g){console.warn(`Declarative condition error for field ${m.name}:`,g);}}let y=n[m.name];return jsxRuntime.jsx("div",{className:"kyro-block-field-row border-b border-[var(--kyro-border)]/30 pb-3 last:border-b-0 last:pb-0",children:jsxRuntime.jsx(xo,{field:m,value:y,onChange:g=>i(m.name,g)})},m.name)})}):jsxRuntime.jsxs("div",{className:"text-center py-8 text-[var(--kyro-text-muted)] text-sm italic",children:['No schema defined for block type "',e.type,'"']}),c=Re[e.type]||Re.default;return jsxRuntime.jsxs(dr,{open:true,onClose:r,title:`Edit ${t?.label||e.type}`,width:"xl",showOverlay:false,accentClass:c.border,children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[d(),s.length>0&&jsxRuntime.jsxs("div",{className:"pt-4 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",s.length,")"]}),jsxRuntime.jsx(Xr,{blockId:e.id,children:s,onUpdateChildren:l})]})]}),jsxRuntime.jsx("div",{className:"mt-6 pt-4 border-t border-[var(--kyro-border)]",children:jsxRuntime.jsx("button",{type:"button",onClick:r,className:"w-full py-2.5 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-lg font-medium hover:opacity-90 transition-opacity",children:"Done"})})]})};var Im=6,Xr=({blockId:e,children:t,onUpdateChildren:r,depth:o=0,maxDepth:a=Im})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(new Set),[d,c]=ka.useState(null),[m,y]=ka.useState(null),g=ka.useContext(go);if(!g)throw new Error("ChildBlocksTree must be used within a BlocksContext");let x=zustand.useStore(g,p=>p.dynamicCategories),f=zustand.useStore(g,p=>p.allowedBlocks),u=o<a,b=16,v=p=>{let A=Vo(p);r([...t,A]),c(A.id);},R=p=>{let A=t.filter(O=>O.id!==p);r(A);},C=(p,A)=>{let O=t.map(F=>F.id===p?{...F,children:A}:F);r(O);},w=p=>{l(A=>{let O=new Set(A);return O.has(p)?O.delete(p):O.add(p),O});},N=p=>{let A=p.children&&p.children.length>0,O=i.has(p.id);Ws(p.type);let P=A,S=d===p.id,M=f.find(j=>j.slug===p.type);return jsxRuntime.jsxs("div",{className:"relative group",children:[jsxRuntime.jsxs("div",{className:`flex items-center group/column gap-2 p-2 bg-[var(--kyro-bg-secondary)] rounded border transition-colors ${S?"bg-[var(--kyro-primary)]/10 border-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"} ${u?"cursor-pointer":""}`,style:{marginLeft:o*b},onClick:()=>{u&&c(S?null:p.id);},children:[P?jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:O?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsxRuntime.jsx("span",{className:"w-4"}),zt[p.type]&&jsxRuntime.jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:zt[p.type]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ea(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),M?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:M.admin.description})]}),A&&jsxRuntime.jsxs("span",{className:"text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium",children:[p.children.length," nested"]}),m===p.id?jsxRuntime.jsxs("div",{className:"flex items-center gap-1",onClick:j=>j.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{R(p.id),y(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>y(null),className:"px-2 py-1 text-xs bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] rounded hover:bg-[var(--kyro-border)]",children:"Cancel"})]}):jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),y(p.id);},className:"p-1.5 rounded-md transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)] invisible group-hover/column:visible"})})]}),S&&jsxRuntime.jsx(Wo,{block:p,onClose:()=>c(null)}),A&&O&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(pd,{parentId:p.id,children:p.children,onUpdateChildren:j=>C(p.id,j),depth:o+1,maxDepth:a})})]},p.id)};return jsxRuntime.jsxs("div",{className:"space-y-2",children:[t.length>0&&jsxRuntime.jsx("div",{className:"space-y-1",children:t.map(N)}),u&&jsxRuntime.jsxs("div",{style:{marginLeft:o*b},children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(true),className:"flex items-center gap-1 px-2 py-1 text-xs font-medium text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)] rounded transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3 h-3"}),"Add Block"]}),jsxRuntime.jsx(Ia,{open:n,onClose:()=>s(false),onSelect:v,children:x.map(p=>jsxRuntime.jsxs("div",{className:"mb-4",children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(A=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{v(A.slug),s(false);},className:"flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group",children:[jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:zt[A.slug]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:A.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:A.admin?.description||""})]})]},A.slug))})]},p.title))})]}),t.length===0&&u&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*b},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxRuntime.jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*b},children:["Maximum nesting level (",a,") reached"]})]})},pd=({parentId:e,children:t,onUpdateChildren:r,depth:o,maxDepth:a})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(new Set),[d,c]=ka.useState(null),[m,y]=ka.useState(null),g=ka.useContext(go);if(!g)throw new Error("NestedChildBlocks must be used within a BlocksContext");let x=zustand.useStore(g,p=>p.dynamicCategories),f=zustand.useStore(g,p=>p.allowedBlocks),u=o<a,b=16,v=p=>{let A=Vo(p);r([...t,A]),c(A.id);},R=p=>{let A=t.filter(O=>O.id!==p);r(A);},C=(p,A)=>{let O=t.map(F=>F.id===p?{...F,children:A}:F);r(O);},w=p=>{l(A=>{let O=new Set(A);return O.has(p)?O.delete(p):O.add(p),O});},N=p=>{let A=p.children&&p.children.length>0,O=i.has(p.id);Ws(p.type);let P=A,S=d===p.id,M=f.find(j=>j.slug===p.type);return jsxRuntime.jsxs("div",{className:"relative group",children:[jsxRuntime.jsxs("div",{className:`flex items-center gap-2 p-2 bg-[var(--kyro-bg-secondary)] rounded border transition-colors ${S?"bg-[var(--kyro-primary)]/10 border-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"} ${u?"cursor-pointer":""}`,style:{marginLeft:o*b},onClick:()=>{u&&c(S?null:p.id);},children:[P?jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:O?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsxRuntime.jsx("span",{className:"w-4"}),zt[p.type]&&jsxRuntime.jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:zt[p.type]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ea(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),M?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:M.admin.description})]}),A&&jsxRuntime.jsxs("span",{className:"text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium",children:[p.children.length," nested"]}),m===p.id?jsxRuntime.jsxs("div",{className:"flex items-center gap-1",onClick:j=>j.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{R(p.id),y(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>y(null),className:"px-2 py-1 text-xs bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] rounded hover:bg-[var(--kyro-border)]",children:"Cancel"})]}):jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),y(p.id);},className:"p-1.5 rounded-md invisible group-hover:visible transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)]"})})]}),S&&jsxRuntime.jsx(Wo,{block:p,onClose:()=>c(null)}),A&&O&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(pd,{parentId:p.id,children:p.children,onUpdateChildren:j=>C(p.id,j),depth:o+1,maxDepth:a})})]},p.id)};return jsxRuntime.jsxs("div",{className:"space-y-2",children:[t.length>0&&jsxRuntime.jsx("div",{className:"space-y-1",children:t.map(N)}),u&&jsxRuntime.jsxs("div",{style:{marginLeft:o*b},children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(true),className:"flex items-center gap-1 px-2 py-1 text-xs font-medium text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)] rounded transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3 h-3"}),"Add Block"]}),jsxRuntime.jsx(Ia,{open:n,onClose:()=>s(false),onSelect:v,children:x.map(p=>jsxRuntime.jsxs("div",{className:"mb-4",children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(A=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{v(A.slug),s(false);},className:"flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group",children:[jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:zt[A.slug]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:A.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:A.admin?.description||""})]})]},A.slug))})]},p.title))})]}),t.length===0&&u&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*b},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxRuntime.jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*b},children:["Maximum nesting level (",a,") reached"]})]})};var md=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data??e.data??{},i=r?.children??e.children??[],l=(d,c)=>{o(e.id,{data:{...s,[d]:c}});};return jsxRuntime.jsxs("div",{className:"block-hero border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Hero Section"})}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx(Ks,{heading:s.heading||"",subheading:s.subheading||"",ctaText:s.ctaText||"",ctaUrl:s.ctaUrl||"",onChange:l,compact:true}),jsxRuntime.jsx(lr,{field:{label:"Background",name:"bgImage",maxCount:1},value:s.bgImage,onChange:d=>l("bgImage",d)}),jsxRuntime.jsxs("div",{className:"pt-3 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",i.length,")"]}),jsxRuntime.jsx(Xr,{blockId:e.id,children:i,onUpdateChildren:d=>o(e.id,{children:d})})]})]})]})};var qs=({heading:e="",subheading:t="",onChange:r,compact:o=false})=>{let a=o?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",n=o?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxRuntime.jsxs("div",{className:o?"space-y-2":"space-y-3",children:[jsxRuntime.jsx("input",{type:"text",value:e,onChange:s=>r("heading",s.target.value),className:`${a} font-bold text-base`,placeholder:"Heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:s=>r("subheading",s.target.value),className:n,placeholder:"Subheading..."})]})};var fd=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o}=Ae(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsxRuntime.jsx(Pr,{id:e.id,type:"heading-subheading",label:"Heading + Subheading",children:jsxRuntime.jsx(qs,{heading:a.heading||"",subheading:a.subheading||"",onChange:n,compact:true})})};var Js=({title:e="",description:t="",icon:r="",link:o="",linkText:a="",onChange:n,compact:s=false})=>{let i=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",l=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxRuntime.jsxs("div",{className:s?"space-y-2":"space-y-3",children:[jsxRuntime.jsx("input",{type:"text",value:e,onChange:d=>n("title",d.target.value),className:`${i} font-bold text-base`,placeholder:"Card title..."}),jsxRuntime.jsx("textarea",{value:t,onChange:d=>n("description",d.target.value),className:l,placeholder:"Card description..."}),jsxRuntime.jsx("input",{type:"text",value:r,onChange:d=>n("icon",d.target.value),className:i,placeholder:"Icon (emoji or name)..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:a,onChange:d=>n("linkText",d.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Link text..."}),jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsxRuntime.jsx("input",{type:"url",value:o,onChange:d=>n("link",d.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]})};var bd=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o}=Ae(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsxRuntime.jsx(Pr,{id:e.id,type:"card",label:"Card",children:jsxRuntime.jsx(Js,{title:a.title||"",description:a.description||"",icon:a.icon||"",link:a.link||"",linkText:a.linkText||"",onChange:n,compact:true})})};var xd=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae();r?.data??e.data??{};let i=r?.children??e.children??[];return jsxRuntime.jsxs("div",{className:"block-array border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Repeater"}),jsxRuntime.jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx("div",{className:"space-y-3",children:jsxRuntime.jsx(Xr,{blockId:e.id,children:i,onUpdateChildren:l=>o(e.id,{children:l})})})]})};var Ua=({relationTo:e="pages",hasMany:t=false,selectedIds:r=[],selectedId:o,labelField:a="title",onChange:n,compact:s=false})=>{let[i,l]=ka.useState(false),[d,c]=ka.useState(""),[m,y]=ka.useState([]),[g,x]=ka.useState(false),[f,u]=ka.useState([]),[b,v]=ka.useState(true);ka.useEffect(()=>{Be("/api/collections").then(F=>{u((F.collections||[]).map(P=>P.slug||P.name||P)),v(false);}).catch(()=>v(false));},[]);let R=(F="")=>{x(true);let P=`/api/${e}?${Ja(F,[a],20)}`;Be(P).then(S=>{y(S.docs||[]),x(false);}).catch(()=>x(false));};ka.useEffect(()=>{i&&R(d);},[i,d,e,a]);let L=F=>F?.[a]||F?.title||F?.name||F?.label||F?.filename||F?.slug||F?.id||"Untitled",C=t?r:o?[o]:[],w=F=>{t?C.includes(F.id)?n("selectedIds",C.filter(P=>P!==F.id)):n("selectedIds",[...C,F.id]):(n("selectedId",F.id),n("selectedIds",[F.id]),l(false));},N=F=>C.includes(F),p=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",A=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",O=e&&typeof e=="string"&&e.length>0;return jsxRuntime.jsxs("div",{className:s?"space-y-2":"space-y-4",children:[jsxRuntime.jsxs("div",{className:s?"flex items-center gap-2":"space-y-3",children:[!O&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:b?jsxRuntime.jsx("div",{className:A+" text-[var(--kyro-text-muted)]",children:"Loading..."}):jsxRuntime.jsxs("select",{value:e,onChange:F=>n("relationTo",F.target.value),className:A,children:[jsxRuntime.jsx("option",{value:"",children:"Select collection..."}),f.map(F=>jsxRuntime.jsx("option",{value:F,children:F},F))]})}),!s&&jsxRuntime.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:t,onChange:F=>n("hasMany",F.target.checked),className:"w-4 h-4 rounded border-[var(--kyro-border)] focus:ring-[var(--kyro-sidebar-active)] focus:ring-offset-0"}),jsxRuntime.jsx("span",{className:"text-sm text-[var(--kyro-text-primary)]",children:"Allow multiple"})]})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",value:d,onChange:F=>{c(F.target.value),l(true);},onFocus:()=>l(true),onBlur:()=>setTimeout(()=>l(false),200),placeholder:`Search ${e}...`,className:`${p} pl-9`}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:g&&jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"})})]}),i&&jsxRuntime.jsx("div",{className:"absolute z-20 w-full mt-1 border border-[var(--kyro-border)] rounded-lg shadow-lg bg-[var(--kyro-surface)] max-h-48 overflow-auto",children:g?jsxRuntime.jsx("div",{className:"p-3 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):m.length===0?jsxRuntime.jsx(Ln,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:m.map(F=>jsxRuntime.jsxs("button",{type:"button",onMouseDown:P=>P.preventDefault(),onClick:()=>w(F),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors flex items-center justify-between ${N(F.id)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("span",{children:L(F)}),N(F.id)&&jsxRuntime.jsx("span",{children:"\u2713"})]},F.id))})})]}),C.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5",children:C.map(F=>{let P=m.find(S=>S.id===F)||{id:F};return jsxRuntime.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-md bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]",children:[L(P),jsxRuntime.jsx("button",{type:"button",onMouseDown:S=>S.preventDefault(),onClick:()=>{t?n("selectedIds",C.filter(S=>S!==F)):(n("selectedId",null),n("selectedIds",[]));},className:"hover:opacity-70",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},F)})})]})};var hd=({block:e,index:t})=>{let r=Me(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Ae(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-relationship border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Relationship"}),jsxRuntime.jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["\u2192 ",s.relationTo||"pages"]})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(Ua,{relationTo:s.relationTo||"pages",hasMany:s.hasMany||false,selectedIds:Array.isArray(s.selectedIds)?s.selectedIds:[],selectedId:s.selectedId,labelField:s.labelField||"title",onChange:i,compact:true})]})};var $m={heading:Jl,paragraph:Ql,image:Yl,video:ed,list:td,code:rd,file:od,accordion:ad,richtext:nd,hero:md,"heading-subheading":fd,card:bd,array:xd,relationship:hd},Re={"feature-split":{text:"text-indigo-500",border:"border-indigo-500",borderLeft:"border-l-indigo-500"},"feature-grid":{text:"text-blue-500",border:"border-blue-500",borderLeft:"border-l-blue-500"},"cta-banner":{text:"text-amber-500",border:"border-amber-500",borderLeft:"border-l-amber-500"},testimonials:{text:"text-emerald-500",border:"border-emerald-500",borderLeft:"border-l-emerald-500"},faq:{text:"text-orange-500",border:"border-orange-500",borderLeft:"border-l-orange-500"},stats:{text:"text-rose-500",border:"border-rose-500",borderLeft:"border-l-rose-500"},"logo-cloud":{text:"text-cyan-500",border:"border-cyan-500",borderLeft:"border-l-cyan-500"},pricing:{text:"text-green-500",border:"border-green-500",borderLeft:"border-l-green-500"},team:{text:"text-violet-500",border:"border-violet-500",borderLeft:"border-l-violet-500"},"recent-feed":{text:"text-sky-500",border:"border-sky-500",borderLeft:"border-l-sky-500"},"process-steps":{text:"text-fuchsia-500",border:"border-fuchsia-500",borderLeft:"border-l-fuchsia-500"},"form-embed":{text:"text-pink-500",border:"border-pink-500",borderLeft:"border-l-pink-500"},"video-showcase":{text:"text-red-500",border:"border-red-500",borderLeft:"border-l-red-500"},hero:{text:"text-yellow-500",border:"border-yellow-500",borderLeft:"border-l-yellow-500"},card:{text:"text-teal-500",border:"border-teal-500",borderLeft:"border-l-teal-500"},default:{text:"text-zinc-400",border:"border-zinc-400",borderLeft:"border-l-zinc-400"}},zt={heading:jsxRuntime.jsx(lucideReact.Heading1,{className:`w-4 h-4 ${Re.default.text}`}),paragraph:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Re.default.text}`}),image:jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Re.default.text}`}),video:jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Re.default.text}`}),list:jsxRuntime.jsx(lucideReact.List,{className:`w-4 h-4 ${Re.default.text}`}),code:jsxRuntime.jsx(lucideReact.Code,{className:`w-4 h-4 ${Re.default.text}`}),file:jsxRuntime.jsx(lucideReact.File,{className:`w-4 h-4 ${Re.default.text}`}),accordion:jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-4 h-4 ${Re.default.text}`}),richtext:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Re.default.text}`}),hero:jsxRuntime.jsx(lucideReact.Star,{className:`w-4 h-4 ${Re.hero.text}`}),"heading-subheading":jsxRuntime.jsx(lucideReact.Heading1,{className:`w-4 h-4 ${Re.default.text}`}),card:jsxRuntime.jsx(lucideReact.Box,{className:`w-4 h-4 ${Re.card.text}`}),array:jsxRuntime.jsx(lucideReact.ListOrdered,{className:`w-4 h-4 ${Re.default.text}`}),relationship:jsxRuntime.jsx(lucideReact.Link2,{className:`w-4 h-4 ${Re.default.text}`}),"feature-split":jsxRuntime.jsx(lucideReact.Columns3,{className:`w-4 h-4 ${Re["feature-split"].text}`}),"feature-grid":jsxRuntime.jsx(lucideReact.Blocks,{className:`w-4 h-4 ${Re["feature-grid"].text}`}),"cta-banner":jsxRuntime.jsx(lucideReact.Sparkles,{className:`w-4 h-4 ${Re["cta-banner"].text}`}),testimonials:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Re.testimonials.text}`}),faq:jsxRuntime.jsx(lucideReact.CircleHelp,{className:`w-4 h-4 ${Re.faq.text}`}),stats:jsxRuntime.jsx(lucideReact.Activity,{className:`w-4 h-4 ${Re.stats.text}`}),"logo-cloud":jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Re["logo-cloud"].text}`}),pricing:jsxRuntime.jsx(lucideReact.Tag,{className:`w-4 h-4 ${Re.pricing.text}`}),team:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Re.team.text}`}),"recent-feed":jsxRuntime.jsx(lucideReact.Database,{className:`w-4 h-4 ${Re["recent-feed"].text}`}),"process-steps":jsxRuntime.jsx(lucideReact.Clock,{className:`w-4 h-4 ${Re["process-steps"].text}`}),"form-embed":jsxRuntime.jsx(lucideReact.Mail,{className:`w-4 h-4 ${Re["form-embed"].text}`}),"video-showcase":jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Re["video-showcase"].text}`})};function Ws(e){return $m[e]||null}function Xs(e){return {paragraph:"Paragraph",heading:"Heading",image:"Image",video:"Video",list:"List",code:"Code",file:"File",accordion:"Accordion",array:"Repeater",relationship:"Relationship",richtext:"Rich Text",hero:"Hero Section","heading-subheading":"Heading + Subheading",card:"Card Block","feature-split":"Feature Split","feature-grid":"Feature Grid","cta-banner":"CTA Banner",testimonials:"Testimonials Stack",faq:"FAQ Section",stats:"Stats & Metrics","logo-cloud":"Logo Cloud",pricing:"Pricing Grid / Plan",team:"Team Profiles Showcase","recent-feed":"Dynamic Content Feed","process-steps":"Process Timeline / Steps","form-embed":"Lead Intake Form","video-showcase":"Cinematic Video Showcase","heading-element":"Heading","text-element":"Text","image-element":"Image","richtext-element":"Rich Text","button-element":"Button","video-element":"Video","list-element":"List"}[e]||e}function Ea(e){let t=e.name;return t&&t.trim()?t.trim():Xs(e.type)}function Jm(e,t){if(t?.fields){for(let r of t.fields)if(r.type==="text"||r.type==="textarea"){let o=e[r.name];if(o&&typeof o=="string")return o}}return e.heading||e.title||e.text||e.name||e.label||e.sectionTitle||""}var Xm=({block:e,index:t,blockSchema:r,editingBlockId:o,setEditingBlockId:a,onDuplicate:n,compact:s})=>{let{attributes:i,listeners:l,setNodeRef:d,transform:c,transition:m,isDragging:y}=sortable.useSortable({id:e.id}),{removeBlock:g,updateBlock:x}=Ae(),f=o===e.id,[u,b]=ka.useState(false),[v,R]=ka.useState(false),[L,C]=ka.useState(e.name||""),w=ka.useRef(null);ka.useEffect(()=>{v&&w.current&&(w.current.focus(),w.current.select());},[v]);let N=ka.useCallback(()=>{R(false);let P=L.trim();P!==(e.name||"").trim()&&x(e.id,{name:P||""});},[L,e.name,e.id,x]),p={transform:utilities.CSS.Transform.toString(c),transition:m,zIndex:y?10:1,opacity:y?.8:1},A=Ea(e),O=e.data||{},F=Jm(O,r);return s?jsxRuntime.jsxs("div",{ref:d,style:p,className:"relative group",children:[jsxRuntime.jsxs("div",{onClick:()=>a(e.id),className:`flex items-center gap-1 pl-5 pr-1.5 py-1 bg-[var(--kyro-bg-secondary)] rounded-md border transition-colors cursor-pointer text-xs whitespace-nowrap ${f?`${(Re[e.type]||Re.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[jsxRuntime.jsx("div",{className:"absolute left-0.5 top-1/2 -translate-y-1/2 p-0.5 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] opacity-0 group-hover:opacity-100 transition-opacity hover:bg-[var(--kyro-surface-accent)] rounded",...i,...l,onClick:P=>P.stopPropagation(),children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-2.5 h-2.5"})}),zt[e.type]&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-secondary)] flex-shrink-0",children:zt[e.type]}),v?jsxRuntime.jsx("input",{ref:w,value:L,onChange:P=>C(P.target.value),onBlur:N,onKeyDown:P=>{P.key==="Enter"&&N(),P.key==="Escape"&&(C(e.name||""),R(false));},onClick:P=>P.stopPropagation(),className:"flex-1 min-w-0 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-primary)] rounded px-1.5 py-0.5 text-[10px] font-medium text-[var(--kyro-text-primary)] outline-none"}):jsxRuntime.jsx("span",{onClick:P=>{P.stopPropagation(),C(e.name||""),R(true);},className:"font-medium text-[var(--kyro-text-secondary)] truncate max-w-[120px] cursor-text hover:text-[var(--kyro-text-primary)] transition-colors",title:"Click to rename",children:A}),u?jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5",onClick:P=>P.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(e.id),b(false);},className:"px-1.5 py-0.5 text-[9px] bg-[var(--kyro-danger)] text-white rounded font-semibold transition-colors hover:brightness-90",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>b(false),className:"px-1.5 py-0.5 text-[9px] bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded font-semibold transition-colors",children:"Cancel"})]}):jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5",children:[jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),n(e.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Duplicate",children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),b(true);},className:"p-0.5 hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] rounded text-[var(--kyro-text-muted)] transition-colors",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),f&&jsxRuntime.jsx(Wo,{block:e,blockSchema:r,onClose:()=>a(null)})]}):jsxRuntime.jsxs("div",{ref:d,style:p,className:"relative group md:pl-8 mb-2",children:[jsxRuntime.jsx("div",{className:"hidden md:absolute left-0 top-1/2 -translate-y-1/2 p-1.5 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] opacity-0 group-hover:opacity-100 transition-opacity hover:bg-[var(--kyro-surface-accent)] rounded",...i,...l,children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{onClick:()=>a(e.id),className:`flex items-center gap-3 p-3 bg-[var(--kyro-bg-secondary)] rounded-lg border transition-colors cursor-pointer ${f?`${(Re[e.type]||Re.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[zt[e.type]&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-secondary)]",children:zt[e.type]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[v?jsxRuntime.jsx("input",{ref:w,value:L,onChange:P=>C(P.target.value),onBlur:N,onKeyDown:P=>{P.key==="Enter"&&N(),P.key==="Escape"&&(C(e.name||""),R(false));},onClick:P=>P.stopPropagation(),placeholder:Xs(e.type),className:"w-full max-w-[150px] sm:max-w-[250px] md:max-w-[400px] bg-[var(--kyro-surface-accent)] border border-[var(--kyro-primary)] rounded px-2 py-0.5 text-xs font-semibold text-[var(--kyro-text-primary)] outline-none"}):jsxRuntime.jsxs("div",{onClick:P=>{window.innerWidth>=768&&(P.stopPropagation(),C(e.name||""),R(true));},className:"text-xs font-semibold text-[var(--kyro-text-secondary)] truncate md:cursor-text hover:text-[var(--kyro-text-primary)] transition-colors",title:"Click to rename",children:[A,F&&typeof F=="string"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-text-muted)] font-normal ml-1.5",children:["- ",F.length>40?`${F.slice(0,40)}...`:F]})]}),r?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:r.admin.description})]}),e.children&&Array.isArray(e.children)&&e.children.length>0&&jsxRuntime.jsxs("span",{className:"text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium",children:[e.children.length," nested"]}),u?jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",onClick:P=>P.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(e.id),b(false);},className:"px-2.5 py-1 text-[10px] bg-[var(--kyro-danger)] text-white rounded font-semibold transition-colors hover:brightness-90",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>b(false),className:"px-2.5 py-1 text-[10px] bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded font-semibold transition-colors",children:"Cancel"})]}):jsxRuntime.jsxs("div",{className:"flex items-center gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),C(e.name||""),R(true);},className:"md:hidden p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Rename Block",children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"}),jsxRuntime.jsx("path",{d:"m15 5 4 4"})]})}),jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),n(e.id);},className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Duplicate Block",children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),b(true);},className:"p-1 hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] rounded text-[var(--kyro-text-muted)] transition-colors",title:"Remove Block",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5"})})]})]}),f&&jsxRuntime.jsx(Wo,{block:e,blockSchema:r,onClose:()=>a(null)})]})},Qm=ka__default.default.memo(Xm),Gs=({field:e,value:t,onChange:r,onBlocksChange:o,error:a,disabled:n,documentStatus:s,justSaved:i})=>{let[l,d]=ka.useState(false),[c,m]=ka.useState(false),y=ka.useRef(null),g=e.admin?.pickerMode||"drawer",x=e.blocks||[],f=x.reduce((B,K)=>{let ce=K.admin?.group||"Custom Blocks";return B[ce]||(B[ce]=[]),B[ce].push(K),B},{}),u=["Structural Sections","Marketing Grids","Lead Capture & Interactive","Dynamic Content","Basic Content Elements","Custom Blocks"],b=Object.entries(f).sort(([B],[K])=>{let ce=u.indexOf(B),he=u.indexOf(K);return ce!==-1&&he!==-1?ce-he:ce!==-1?-1:he!==-1?1:B.localeCompare(K)}).map(([B,K])=>({title:B,blocks:K})),v=ka.useRef(null);v.current||(v.current=Kl(x,b));let R=v.current,L=zustand.useStore(R,B=>B.blocks),[C,w]=ka.useState(null),[N,p]=ka.useState(null),A=ka.useRef(L.length),O=ka.useRef(new Set(L.map(B=>B.id))),F=ka.useRef(false);ka.useEffect(()=>{if(F.current&&L.length>A.current){let B=L.find(K=>K.id&&!O.current.has(K.id));B&&p(B.id);}A.current=L.length,O.current=new Set(L.map(B=>B.id));},[L]),ka.useEffect(()=>(o&&R.getState().setOnBlocksChange(o),()=>{R.getState().setOnBlocksChange(()=>{});}),[o,R]);let P=ka.useRef(null);ka.useEffect(()=>{let B=Array.isArray(t)?t:[],K=P.current||[];if(JSON.stringify(B)!==JSON.stringify(K)){let ce=[...B];A.current=ce.length,O.current=new Set(ce.map(he=>he.id)),R.getState().setBlocks(ce),P.current=ce,F.current=true;}else B.length===0&&!F.current&&(F.current=true,P.current=[]);},[t,e.name,R]);let S=ka.useRef(r);S.current=r,ka.useEffect(()=>{if(!S.current)return;let B=P.current;B&&JSON.stringify(L)!==JSON.stringify(B)&&(P.current=[...L],S.current(L));},[L]);let j=ka.useCallback(B=>{R.getState().addBlock(B);},[R]),se=ka.useCallback(B=>{let K=L.findIndex(I=>I.id===B);if(K===-1)return;let ce=L[K],he=I=>{let z=Math.random().toString(36).substr(2,9);return {...I,id:z,children:I.children?I.children.map(Ke=>he(Ke)):I.children,data:I.data?JSON.parse(JSON.stringify(I.data)):I.data}},De=he(ce),Ce=[...L];Ce.splice(K+1,0,De),R.getState().setBlocks(Ce);},[L,R]),ie=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:8}}),core.useSensor(core.KeyboardSensor)),ue=B=>{w(B.active);},oe=B=>{let{active:K,over:ce}=B;if(w(null),!!ce){if(K.id.toString().startsWith("drawer-")){let he=K.id.toString().replace("drawer-","");if(ce.id.toString().startsWith("container-")){let De=ce.id.toString().replace("container-",""),Ce=L.find(I=>I.id===De);if(Ce){let I=Vo(he);R.getState().updateBlock(De,{children:[...Ce.children||[],I]});}}else j(he);return}if(K.id!==ce.id){let he=L.findIndex(Ce=>Ce.id===K.id),De=L.findIndex(Ce=>Ce.id===ce.id);if(he!==-1&&De!==-1){let Ce=[...L],[I]=Ce.splice(he,1);Ce.splice(De,0,I),R.getState().setBlocks(Ce);}}}},ne=C?b.flatMap(B=>B.blocks).find(B=>`drawer-${B.type}`===C.id)||L.find(B=>B.id===C.id):null;ne?"label"in ne?ne.label:ne.type:"Block";return ka.useEffect(()=>{if(!c)return;let B=K=>{y.current&&!y.current.contains(K.target)&&m(false);};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[c]),jsxRuntime.jsx(go.Provider,{value:v.current,children:jsxRuntime.jsxs("div",{className:"kyro-blocks-field",children:[jsxRuntime.jsxs(core.DndContext,{sensors:ie,collisionDetection:core.closestCenter,onDragStart:ue,onDragEnd:oe,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),g==="dropdown"?jsxRuntime.jsxs("div",{ref:y,className:"relative",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>m(!c),disabled:n,className:"flex items-center gap-1.5 px-3 py-2 text-sm text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)]/30 rounded-md transition-colors disabled:opacity-50 font-semibold",children:[jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsxRuntime.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add Element",jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-3.5 h-3.5 transition-transform ${c?"rotate-180":""}`})]}),c&&jsxRuntime.jsx("div",{className:"absolute right-0 top-full mt-1 w-56 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 py-2 max-h-80 overflow-y-auto",children:b.map(B=>jsxRuntime.jsxs("div",{children:[b.length>1&&jsxRuntime.jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold tracking-wider text-[var(--kyro-text-muted)] uppercase",children:B.title}),B.blocks.map(K=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{j(K.slug),m(false);},className:"w-full flex items-center gap-3 px-3 py-2 text-sm text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]/50 transition-colors text-left",children:[jsxRuntime.jsx("span",{className:"flex-shrink-0 w-5 h-5 flex items-center justify-center text-[var(--kyro-text-muted)]",children:zt[K.slug]||jsxRuntime.jsx(lucideReact.Box,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsx("div",{className:"text-xs font-semibold truncate",children:K.label}),K.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] truncate",children:K.admin.description})]})]},K.slug))]},B.title))})]}):jsxRuntime.jsxs("button",{type:"button",onClick:()=>d(true),disabled:n,className:"flex items-center gap-2 px-3 py-2 text-sm text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)]/30 rounded-md transition-colors disabled:opacity-50 font-semibold",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4"}),"Add Block"]})]}),jsxRuntime.jsx("div",{className:"mb-4",children:jsxRuntime.jsx(Ia,{open:l,onClose:()=>d(false),onSelect:j,children:jsxRuntime.jsx("div",{className:"space-y-4",children:b.map(B=>jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] mb-2 tracking-wider",children:B.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:B.blocks.map(K=>jsxRuntime.jsx(Gl,{block:{type:K.slug,label:K.label,description:K.admin?.description||"",icon:null},onSelect:j,children:jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all duration-300",children:jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]",children:zt[K.slug]||jsxRuntime.jsx(lucideReact.Box,{className:"w-4 h-4"})})})},K.slug))})]},B.title))})})}),jsxRuntime.jsx(sortable.SortableContext,{items:L.map(B=>B.id),strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsxs("div",{className:g==="dropdown"?"flex flex-wrap gap-1.5":"space-y-4",children:[L.map((B,K)=>{let ce=e.blocks?.find(he=>he.slug===B.type);return jsxRuntime.jsx(Qm,{block:B,index:K,blockSchema:ce,editingBlockId:N,setEditingBlockId:p,onDuplicate:se,compact:g==="dropdown"},B.id||K)}),L.length===0&&jsxRuntime.jsx("div",{className:g==="dropdown"?"text-xs text-[var(--kyro-text-muted)] italic py-1":"text-center py-12 text-[var(--kyro-text-muted)] border-2 border-dashed border-[var(--kyro-border)] rounded-lg",children:g==="dropdown"?"No elements added":"Click the button above to add your first block"})]})}),jsxRuntime.jsx(core.DragOverlay,{children:C&&ne&&jsxRuntime.jsx("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-primary)] rounded-md p-3 shadow-lg",children:ne.label||ne.type||"Block"})})]}),a&&jsxRuntime.jsx("p",{className:"kyro-form-error",children:a})]})})};function mr(e){if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(mr);if(typeof e=="object"){let t=e,r=Object.keys(t),o="id"in t&&(typeof t.id=="string"||t.id===null),a="url"in t||"filename"in t||"mimeType"in t;if(o&&(a||r.length<=2)&&r.length<=8)return t.id;let n={};for(let s of r)n[s]=mr(t[s]);return n}return e}function Cd(){let e=ka.useRef([]),t=ka.useRef(false);return {queueTask:ka.useCallback((o,a)=>{e.current.push(o);async function n(){if(!t.current&&!(typeof a?.beforeProcess=="function"&&a.beforeProcess()===false))for(;e.current.length>0;){let s=e.current.pop();e.current=[],t.current=true;try{await s();}catch(i){console.error("Error in queued function:",i);}finally{t.current=false,typeof a?.afterProcess=="function"&&a.afterProcess();}}}n();},[])}}function Sd({config:e,initialData:t,collectionSlug:r,globalSlug:o,documentId:a,onChange:n,onActionSuccess:s,onActionError:i}){let l=Le(),{confirm:d}=at(),{formData:c,setFormData:m,setField:y,lastSavedData:g,setLastSavedData:x,setHasUnsavedChanges:f,isSlugLocked:u,loadDocument:b,setIsAutoSaving:v,setAutoSaveStatus:R,setVersions:L,setLoadingVersions:C,sidebarCollapsed:w,setSidebarCollapsed:N,getDraftCache:p,setDraftCache:A,clearDraftCache:O,resetForm:F}=l,P=!!e.versions,S=o||t?.id||a||r,M=ka.useRef(false);!o&&S&&c&&Object.keys(c).length>0&&c.id!==S&&(M.current=true),ka.useEffect(()=>{M.current&&(M.current=false,F());},[F]);let j=ka.useRef(null),se=ka.useRef(null),ie=ka.useRef(null),ue=ka.useRef(typeof navigator<"u"?navigator.onLine:true),oe=ka.useRef(0),ne=ka.useRef(false),je=ka.useRef(null),ft=ka.useRef(""),B=ka.useRef(""),{queueTask:K}=Cd(),ce=ka.useCallback(q=>o?`global:${o}`:r&&q?`${r}:${q}`:null,[r,o]),he=ka.useCallback((q,X,le)=>{A(q,{data:X,baseUpdatedAt:g.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:le?.lastSyncedAt??null});},[g.updatedAt,A]),De=ka.useCallback(async()=>{let q=o?qe(`/api/globals/${o}/versions`):r&&c.id?qe(`/api/${r}/${c.id}/versions`):null;if(q){C(true);try{let le=await(await ct(q)).json();L(le.docs||[]);}catch(X){console.error("Failed to fetch versions:",X);}finally{C(false);}}},[c.id,r,o,C,L]),Ce=ka.useCallback(()=>{let q=Le.getState(),X=q.formData;if(ne.current||!r||!X.id||!q.hasDirtyFields())return;let le=ce(X.id);le&&he(le,X);},[r,ce,he]),I=ka.useCallback(async q=>{let X=Le.getState(),le=X.formData,xe=X.lastSavedData;if(ne.current||!P&&o||!o&&(!r||!le.id)||!X.hasDirtyFields())return;let we=ce(le.id);if(we&&he(we,le),!ue.current){R("offline");return}v(true),R("saving"),X.setBackgroundProcessing(true);try{let Qe=o?qe(`/api/globals/${o}?autosave=true`):qe(`/api/${r}/${le.id}?autosave=true`),wt=await ct(Qe,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":"true"},keepalive:q?.keepalive,body:JSON.stringify({...mr(le),baseUpdatedAt:xe.updatedAt??null})});if(wt.ok)oe.current=Date.now(),X.setRetryCount(0),X.setLastSavedAt(Date.now()),ie.current&&clearTimeout(ie.current),we&&A(we,{data:le,baseUpdatedAt:xe.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:(await wt.clone().json()).data?.updatedAt||new Date().toISOString()}),R("success"),setTimeout(()=>{Le.getState().autoSaveStatus==="success"&&R("idle");},2e3);else if(wt.status===409)R("conflict");else throw new Error(`Draft auto-save failed with status ${wt.status}`)}catch(Qe){console.error("Auto-save failed:",Qe);let wt=Le.getState(),D=wt.retryCount;if(D<5){wt.setRetryCount(D+1),R("retrying");let G=Math.min(1e3*Math.pow(2,D),6e4);ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>z(q),G);}else R("offline");}finally{v(false),Le.getState().setBackgroundProcessing(false);}},[r,ce,o,he,R,A,v,P]),z=ka.useCallback(q=>{K(()=>I(q),{beforeProcess:()=>true,afterProcess:()=>{}});},[I,K]),Ke=ka.useCallback(async(q,X=true)=>{let le=Le.getState(),xe=q||le.formData,we=o?qe(`/api/globals/${o}`):qe(`/api/${r}/${xe.id}`),Qe=await ct(we,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":String(X)},body:JSON.stringify({...mr(xe),baseUpdatedAt:le.lastSavedData.updatedAt??null})});return Qe.status===409&&R("conflict"),Qe},[r,o,R]);ka.useEffect(()=>{let q=()=>{N(!w);};return window.addEventListener("toggle-sidebar",q),()=>window.removeEventListener("toggle-sidebar",q)},[w,N]);let ye=ka.useRef(null),Se=ka.useRef(""),dt=ka.useRef(false);ka.useEffect(()=>{let q=o||t?.id,X=JSON.stringify(t);dt.current&&ye.current===q&&Se.current===X||(b(t||{},t||{}),dt.current=true,ye.current=q,Se.current=X);},[r,c.id,o,t,b]),ka.useEffect(()=>{if(!r||!t?.id)return;let q=ce(t.id);if(!q||je.current===q)return;let X=false;return (async()=>{if(!P)return;let xe=p(q);if(xe){if(JSON.stringify(xe.data)===JSON.stringify(t)){O(q);return}je.current=q,d({title:"Restore draft?",message:"A newer autosaved draft was found for this document. Restore it or discard it and continue with the saved version.",confirmLabel:"Restore draft",cancelLabel:"Discard draft",onConfirm:async()=>{if(X)return;let Qe={...Le.getState().formData,...xe.data};m(Qe),s?.("Recovered autosaved draft");},onCancel:async()=>{O(q);}});}})(),()=>{X=true;}},[O,r,d,ce,p,t,s,m,P]);function Tt(q,X){for(let le of q){if(le.name===X&&le.admin?.autoGenerate==="title")return le;if(le.type==="tabs"&&"tabs"in le)for(let xe of le.tabs){let we=Tt(xe.fields,X);if(we)return we}if((le.type==="group"||le.type==="collapsible")&&"fields"in le){let xe=Tt(le.fields,X);if(xe)return xe}}}ka.useEffect(()=>{let q=e.fields;if(!Tt(q,"metaTitle"))return;let le=yo(q,c,"title"),xe=le?String(le):"";xe&&(!c.metaTitle||c.metaTitle===c._lastMetaTitle)&&y("metaTitle",xe);},[c,e.fields,y]),ka.useEffect(()=>{let q=e.fields,X=q.find(we=>we.name==="slug"&&we.admin?.autoGenerate);if(!X?.admin?.autoGenerate)return;let le=X.admin.autoGenerate,xe=yo(q,c,le);if(u&&xe){let we=Tn(xe);we!==c.slug&&y("slug",we);}},[c,u,e.fields,y]),ka.useEffect(()=>{if(w||!o&&(!r||!c.id)||!Le.getState().hasDirtyFields()||ld()!=="keystroke")return;zn("other");let X=JSON.stringify(c);X!==ft.current&&(j.current&&clearTimeout(j.current),j.current=setTimeout(Ce,1500),se.current&&clearTimeout(se.current),se.current=setTimeout(()=>{ft.current=X,z();},8e3));},[c,w,r,o,Ce,z]),ka.useEffect(()=>{if(!o&&(!r||!c.id))return;let q=()=>{ne.current||!Le.getState().hasDirtyFields()||z({keepalive:true});},X=()=>{document.hidden&&q();},le=()=>{ue.current=true,q();},xe=()=>{ue.current=false;let we=Le.getState();we.hasDirtyFields()&&we.setAutoSaveStatus("offline");};return window.addEventListener("blur",q),window.addEventListener("pagehide",q),window.addEventListener("online",le),window.addEventListener("offline",xe),document.addEventListener("visibilitychange",X),()=>{window.removeEventListener("blur",q),window.removeEventListener("pagehide",q),window.removeEventListener("online",le),window.removeEventListener("offline",xe),document.removeEventListener("visibilitychange",X);}},[r,o,c.id,z]),ka.useEffect(()=>{let q=JSON.stringify(c);if(q===B.current)return;B.current=q;let X=document.getElementById("form-data");X&&(X.value=q),n?.(c);},[c,n]),ka.useEffect(()=>{(o||c.id)&&De();},[c.id,o,De]);let Wt=!c.id&&!o?"draft":P&&c.status||"published",vt=(!!c.id||!!o)&&Wt==="draft";return {...l,fetchVersions:De,performAutoSave:z,saveDocument:Ke,autoSaveSkipRef:ne,lastAutoSaveTimeRef:oe,documentStatus:Wt,hasUnpublishedChanges:vt,versionsEnabled:P}}function wo({trigger:e,children:t,align:r="right",direction:o="up"}){let[a,n]=ka.useState(false),s=ka.useRef(null);return ka.useEffect(()=>{let i=l=>{s.current&&!s.current.contains(l.target)&&n(false);};return a&&document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[a]),jsxRuntime.jsxs("div",{className:"relative",ref:s,children:[jsxRuntime.jsx("div",{onClick:()=>n(!a),className:"cursor-pointer",children:e}),a&&jsxRuntime.jsx("div",{className:`absolute z-[100] min-w-[200px] py-2 bg-[var(--kyro-surface)] rounded-2xl shadow-2xl border border-[var(--kyro-border)] animate-in fade-in zoom-in-95 duration-100 ${r==="right"?"right-0":"left-0"} ${o==="down"?"top-full mt-2":"bottom-full mb-2"}`,onClick:()=>n(false),children:t})]})}function jt({children:e,onClick:t,icon:r,danger:o,disabled:a,className:n=""}){return jsxRuntime.jsx("div",{className:"px-1.5",children:jsxRuntime.jsxs("button",{type:"button",onClick:t,disabled:a,className:`w-full flex items-center gap-3 px-3 py-2.5 text-[11px] font-medium tracking-wide text-left transition-all rounded-xl ${o?"text-red-500 hover:bg-red-500/10":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]"} ${a?"opacity-50 cursor-not-allowed":""} ${n}`,children:[r&&jsxRuntime.jsx("span",{className:"w-4 h-4 opacity-70",children:r}),jsxRuntime.jsx("span",{className:"flex-1",children:e})]})})}function ja(){return jsxRuntime.jsx("div",{className:"my-1 border-t border-[var(--kyro-border)] opacity-50"})}function Co({status:e,saveStatus:t,hasChanges:r,onPublish:o,children:a,disabled:n,direction:s="down"}){let i=e==="published"&&!r&&t!=="saving"&&t!=="error",l=n||t==="saving"||i,d="kyro-btn kyro-btn-sm text-[11px] font-regular tracking-widest transition-all duration-300 rounded-lg",c=()=>t==="saving"?`${d} bg-[var(--kyro-primary)]/70 border-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] cursor-wait`:t==="saved"?`${d} bg-[var(--kyro-success)] border-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)]`:t==="error"?`${d} bg-[var(--kyro-error)] border-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)]`:i?`${d} bg-[var(--kyro-gray-200)] border-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] cursor-not-allowed`:`${d} bg-[var(--kyro-primary)] border-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] hover:bg-[var(--kyro-primary-hover)]`,m="kyro-btn kyro-btn-md px-2 rounded-l-none border-l-[1px] border-white/20 transition-all duration-300",y=()=>t==="saving"?`${m} bg-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)]/70`:t==="saved"?`${m} bg-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-success)]`:t==="error"?`${m} bg-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-error)]`:i?`${m} bg-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] border-[var(--kyro-gray-200)]`:`${m} bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)] hover:bg-[var(--kyro-primary-hover)]`,g=()=>t==="saving"?"Publishing...":t==="saved"?"Published \u2713":t==="error"?"Retry":i?"Published":"Publish Changes";return jsxRuntime.jsxs("div",{className:"inline-flex items-center",children:[jsxRuntime.jsxs("button",{type:"button",onClick:o,disabled:l,className:`${c()} ${a?"":"rounded-r-lg border-r border-[var(--kyro-border)]"}`,children:[t==="saving"&&jsxRuntime.jsx(Ar,{size:"sm",className:"inline mr-1.5"}),i&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"inline mr-1",children:jsxRuntime.jsx("polyline",{points:"20 6 9 17 4 12"})}),g()]}),a&&jsxRuntime.jsx(wo,{trigger:jsxRuntime.jsx("button",{type:"button",className:y(),disabled:t==="saving",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"m6 9 6 6 6-6"})})}),direction:s,children:a})]})}var Rd=({title:e,description:t,slug:r})=>jsxRuntime.jsxs("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg p-6 max-w-2xl shadow-sm transition-colors duration-300",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[jsxRuntime.jsx("div",{className:"w-7 h-7 bg-[var(--kyro-bg-secondary)] rounded-full flex items-center justify-center text-[10px] text-[var(--kyro-text-primary)] font-medium border border-[var(--kyro-border)]",children:"K"}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-tight",children:"kyro-cms.com"}),jsxRuntime.jsxs("span",{className:"text-[12px] text-[var(--kyro-text-secondary)] leading-tight opacity-80",children:["https://kyro-cms.com \u203A posts \u203A ",r]})]})]}),jsxRuntime.jsx("h3",{className:"text-[20px] text-[#2563eb] dark:text-[#60a5fa] font-medium hover:underline cursor-pointer mb-1 leading-tight transition-colors",children:e}),jsxRuntime.jsx("p",{className:"text-[14px] text-[var(--kyro-text-secondary)] leading-relaxed line-clamp-2",children:t})]});function Pd({field:e,formData:t,onTabDataChange:r,renderField:o}){let[a,n]=ka.useState(0),s=e.tabs||[],i=s[a]||s[0],l=e.name?t[e.name]||{}:t;return jsxRuntime.jsxs("div",{className:"space-y-8",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-2 border-b border-[var(--kyro-border)] mb-6 overflow-x-auto hide-scrollbar",children:s.map((d,c)=>jsxRuntime.jsx("button",{type:"button",className:`px-6 py-3 text-sm tracking-widest font-medium transition-all border-b-2 -mb-[1px] whitespace-nowrap ${a===c?"border-[var(--kyro-primary)] text-[var(--kyro-primary)]":"border-transparent text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] opacity-60 hover:opacity-100"}`,onClick:()=>n(c),children:d.label},c))}),jsxRuntime.jsx("div",{className:"space-y-6",children:i?.fields.map(d=>o(d,l,r))}),i?.label==="SEO"&&jsxRuntime.jsxs("div",{className:"mt-12 pt-8 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsx("h4",{className:"text-[10px] font-bold text-[var(--kyro-text-secondary)] tracking-[0.2em] mb-6 opacity-50",children:"Live Google Preview"}),jsxRuntime.jsx(Rd,{title:String((typeof l.metaTitle=="object"?"":l.metaTitle)||(typeof l.title=="object"?"":l.title)||"Untitled"),description:String((typeof l.metaDescription=="object"?"":l.metaDescription)||"Please enter a description..."),slug:String((typeof t.slug=="object"?"":t.slug)||"your-slug")})]})]})}function Id({collectionSlug:e,globalSlug:t,documentStatus:r,hasUnpublishedChanges:o,localSaveStatus:a,handleCreateNew:n,handleDuplicate:s,handleUnpublish:i,handleDelete:l,handlePublish:d,handleSchedulePublish:c}){let[m,y]=ka.useState(Date.now()),[g,x]=ka.useState(false),f=ka.useRef(null),{formData:u,hasUnsavedChanges:b,autoSaveStatus:v,lastSavedAt:R,retryCount:L,view:C,setView:w,showPreview:N,setShowPreview:p,setFormData:A,markSaved:O,lastSavedData:F}=Le(),P=!u.id;ka.useEffect(()=>{let B=setInterval(()=>y(Date.now()),1e4);return ()=>clearInterval(B)},[]),ka.useEffect(()=>{let B=K=>{f.current&&!f.current.contains(K.target)&&x(false);};if(g)return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[g]);let S=String(u.mainTabs?.title||(typeof u.title=="object"?"":u.title)||(typeof u.name=="object"?"":u.name)||"Untitled"),M=u.updatedAt?new Date(u.updatedAt).toLocaleString():"Just now",j=u.createdAt?new Date(u.createdAt).toLocaleString():"Just now",se=o?"Draft (unpublished changes)":r==="published"?"Published":"Draft",ie=o?"Unpublished":r==="published"?"Published":"Draft",ue=r==="published"&&!b?"bg-[var(--kyro-success)]":o?"bg-[var(--kyro-warning)]":"bg-[var(--kyro-text-muted)]",oe=r==="published"&&!o?"bg-[var(--kyro-success)]/10 text-[var(--kyro-success)] border-[var(--kyro-success)]/20":o?"bg-[var(--kyro-warning)]/10 text-[var(--kyro-warning)] border-[var(--kyro-warning)]/20":"bg-[var(--kyro-text-muted)]/10 text-[var(--kyro-text-muted)] border-[var(--kyro-text-muted)]/20",ne=(B=false)=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[v==="saving"&&jsxRuntime.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),B?"Saving\u2026":"Saving draft..."]}),v==="success"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsxRuntime.jsx(lucideReact.Check,{className:"w-3.5 h-3.5 shrink-0"}),B?"Saved":R?`Saved ${Math.floor((Date.now()-R)/6e4)}m ago`:"Draft saved"]}),v==="retrying"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),B?`Retry ${L}/5`:`Retrying save (${L}/5)`]}),v==="offline"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-text-muted)] flex items-center gap-1.5",children:[jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[jsxRuntime.jsx("path",{d:"M10.61 10.61a3 3 0 0 0 4.24 4.24"}),jsxRuntime.jsx("path",{d:"M13.36 13.36a3 3 0 0 0-4.24-4.24"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"}),jsxRuntime.jsx("path",{d:"M18.36 5.64a9 9 0 0 0-12.72 0"}),jsxRuntime.jsx("path",{d:"M22.61 1.39a15 15 0 0 0-21.22 0"})]}),B?"Offline":"Offline \u2014 cached locally"]}),v==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:B?"Failed":"Draft save failed"}),v==="conflict"&&(B?jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict"}):jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict detected"}),jsxRuntime.jsx("span",{className:"opacity-30",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",onClick:async()=>{},className:"text-[var(--kyro-primary)] hover:underline",children:"Keep my changes"}),jsxRuntime.jsx("span",{className:"opacity-30",children:"|"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"text-[var(--kyro-danger)] hover:underline",children:"Reload server version"})]}))]}),je=()=>!P&&jsxRuntime.jsxs(wo,{trigger:jsxRuntime.jsx("button",{type:"button",className:"kyro-btn p-2 md:p-2.5 rounded-xl border border-[var(--kyro-border)] hover:bg-[var(--kyro-bg-secondary)] transition-all",title:"More actions",children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[jsxRuntime.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),jsxRuntime.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})}),direction:"down",children:[!t&&jsxRuntime.jsx(jt,{onClick:n,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsxRuntime.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),children:"Create New"}),!t&&jsxRuntime.jsx(jt,{onClick:s,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),children:"Duplicate"}),jsxRuntime.jsx(jt,{onClick:()=>x(true),icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),jsxRuntime.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),jsxRuntime.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),jsxRuntime.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),children:"Schedule Publish"}),r==="published"&&jsxRuntime.jsx(jt,{onClick:i,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),jsxRuntime.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}),children:"Unpublish"}),!t&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ja,{}),jsxRuntime.jsx(jt,{onClick:l,danger:true,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("polyline",{points:"3 6 5 6 21 6"}),jsxRuntime.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),children:"Delete"})]})]}),ft=()=>g&&jsxRuntime.jsx("div",{ref:f,className:"relative",children:jsxRuntime.jsxs("div",{className:"absolute right-0 top-2 p-4 rounded-lg border border-[var(--kyro-border)] bg-[var(--kyro-surface)] shadow-2xl z-50 min-w-[260px]",children:[jsxRuntime.jsx("p",{className:"text-xs font-medium mb-2",children:"Schedule Publish"}),jsxRuntime.jsx("input",{type:"datetime-local",id:"schedule-datetime",className:"kyro-form-input text-xs mb-3 w-full",min:new Date().toISOString().slice(0,16)}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>x(false),className:"px-3 py-1.5 text-xs kyro-btn rounded-lg",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{let B=document.getElementById("schedule-datetime")?.value;B&&c(B);},className:"px-3 py-1.5 text-xs kyro-btn-success rounded-lg",children:"Schedule"})]})]})});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("header",{className:"md:hidden border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)] backdrop-blur-md rounded-lg",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[jsxRuntime.jsx("a",{href:`${Ye}/${e}`,className:"p-1.5 rounded-lg hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[jsxRuntime.jsx("h1",{className:"text-base font-bold tracking-tight truncate min-w-0",children:S}),jsxRuntime.jsxs("span",{className:`shrink-0 inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[9px] font-medium border ${oe}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ue}`}),ie]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[jsxRuntime.jsx(Co,{status:r,saveStatus:a,hasChanges:b,onPublish:d,disabled:a==="saving"}),je(),ft()]})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-t border-[var(--kyro-border)]/50 bg-[var(--kyro-bg-secondary)]/30",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-0.5 bg-[var(--kyro-bg-secondary)] p-0.5 rounded-lg border border-[var(--kyro-border)]/50",children:["edit","version","api"].map(B=>jsxRuntime.jsx("button",{type:"button",onClick:()=>w(B),className:`px-3 py-1 text-[10px] font-bold rounded-md transition-all ${C===B?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 active:opacity-100"}`,children:B==="edit"?"Edit":B==="version"?"History":"API"},B))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-medium",children:[ne(true),b&&v!=="saving"&&v!=="retrying"&&v!=="conflict"&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{A(F),O();},className:"text-[var(--kyro-primary)] text-[10px] font-medium hover:underline",children:"Revert"}),jsxRuntime.jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>p(!N),className:`p-1.5 rounded-lg transition-all ${N?"bg-[var(--kyro-primary)]/10 text-[var(--kyro-primary)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,children:jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-3.5 h-3.5"})})]})]})]}),jsxRuntime.jsxs("header",{className:"hidden md:flex surface-tile px-8 py-6 items-center justify-between sticky top-0 border-b border-[var(--kyro-border)] mb-8 bg-[var(--kyro-surface)] backdrop-blur-md",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-2 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 flex-wrap min-w-0",children:[jsxRuntime.jsx("a",{href:`${Ye}/${e}`,className:"p-2 border border-[var(--kyro-border)] rounded-xl hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4"})}),jsxRuntime.jsx("h1",{className:"text-xl font-bold tracking-tighter truncate min-w-0",children:S}),jsxRuntime.jsxs("span",{className:`shrink-0 inline-flex items-center gap-1.5 px-2 rounded-full text-[10px] font-regular border ${oe}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ue}`}),se]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 text-[11px] font-medium tracking-wide opacity-60 ml-12",children:[ne(false),b&&v!=="saving"&&v!=="retrying"&&v!=="conflict"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"opacity-30",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{A(F),O();},className:"text-[var(--kyro-primary)] hover:underline",children:"Revert changes"})]}),R&&v!=="saving"&&v!=="retrying"&&v!=="success"&&jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Draft saved ",(()=>{let B=m-R,K=Math.floor(B/6e4),ce=Math.floor(B/1e3);return K>=1?`${K}m ago`:ce>=5?`${ce}s ago`:"just now"})()]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Modified ",M]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Created ",j]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-1 bg-[var(--kyro-bg-secondary)] p-1 rounded-xl border border-[var(--kyro-border)]",children:["edit","version","api"].map(B=>jsxRuntime.jsx("button",{type:"button",onClick:()=>w(B),className:`px-5 py-2 text-xs font-bold rounded-lg transition-all ${C===B?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:B.toUpperCase()},B))}),jsxRuntime.jsx("div",{className:"h-8 w-px bg-[var(--kyro-border)] mx-2"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>p(!N),className:`kyro-btn p-2.5 rounded-xl transition-all flex items-center gap-2 ${N?"shadow-lg":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,title:"Live Preview",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-4 h-4"}),N&&jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest pr-1",children:"Active"})]}),je(),ft(),jsxRuntime.jsx(Co,{status:r,saveStatus:a,hasChanges:b,onPublish:d,disabled:a==="saving"})]})]})]})]})}function Ld({config:e,layout:t,collectionSlug:r,renderField:o}){let{showPreview:a,sidebarCollapsed:n,formData:s}=Le();if(t==="single")return jsxRuntime.jsx("div",{className:"w-full space-y-6 md:space-y-8",children:jsxRuntime.jsx("div",{className:"surface-tile p-4 md:p-8 space-y-6 md:space-y-8",children:e.fields.map(d=>o(d))})});let l=e.fields.some(d=>d.admin?.position==="sidebar")&&!a;return jsxRuntime.jsxs("div",{className:`w-full mx-auto grid gap-4 md:gap-8 pb-32 transition-all duration-700 ${a?"grid-cols-1 lg:grid-cols-2":n||!l?"grid-cols-1":"grid-cols-1 lg:grid-cols-[1fr_380px]"}`,children:[jsxRuntime.jsx("div",{className:"space-y-6 md:space-y-8 animate-in fade-in slide-in-from-left-4 duration-500",children:e.tabs?o({type:"tabs",tabs:e.tabs}):jsxRuntime.jsx("div",{className:"surface-tile p-4 md:p-8 space-y-6 md:space-y-8",children:e.fields.filter(d=>!d.admin?.position||d.admin.position==="main").map(d=>o(d))})}),a?jsxRuntime.jsx("div",{className:"sticky top-36 h-[calc(100vh-280px)] animate-in fade-in slide-in-from-right-10 duration-700",children:jsxRuntime.jsxs("div",{className:"w-full h-full rounded-3xl border border-[var(--kyro-border)] bg-[var(--kyro-bg-secondary)] shadow-2xl overflow-hidden relative group",children:[jsxRuntime.jsxs("div",{className:"absolute top-4 left-4 z-10 flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-green-500 animate-pulse"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest text-white/60",children:"Live Preview Mode"})]}),jsxRuntime.jsx("iframe",{src:`/${r}/${s.slug||s.id}?preview=true`,className:"w-full h-full border-none",title:"Live Preview"}),jsxRuntime.jsx("div",{className:"absolute inset-0 bg-transparent pointer-events-none border-[12px] border-[var(--kyro-surface)] rounded-3xl"})]})}):n?null:jsxRuntime.jsx("div",{className:"space-y-4 md:space-y-6 animate-in fade-in slide-in-from-right-4 duration-500",children:e.fields.some(d=>d.admin?.position==="sidebar")&&jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-6 space-y-4 md:space-y-6",children:[jsxRuntime.jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Settings"}),e.fields.filter(d=>d.admin?.position==="sidebar").map(d=>o(d))]})})]})}function Md({handleRestoreVersion:e,handleCompareVersions:t,toggleCompareSelection:r}){let{compareMode:o,setCompareMode:a,compareSelected:n,setCompareSelected:s,compareDiffs:i,setCompareDiffs:l,loadingDiffs:d,loadingVersions:c,versions:m}=Le();return jsxRuntime.jsx("div",{className:"w-full animate-in fade-in slide-in-from-bottom-4 pb-12",children:jsxRuntime.jsxs("div",{className:"surface-tile p-0 overflow-hidden",children:[jsxRuntime.jsxs("div",{className:"px-4 md:px-6 py-3 md:py-4 border-b border-[var(--kyro-border)] flex flex-col md:flex-row md:items-center justify-between gap-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h2",{className:"text-base md:text-lg font-bold text-[var(--kyro-text-primary)]",children:"Version History"}),jsxRuntime.jsx("p",{className:"text-[11px] text-[var(--kyro-text-muted)] mt-0.5",children:o?`Select 2 versions \xB7 ${n.length}/2 chosen`:`${m.length} snapshot${m.length!==1?"s":""} \xB7 Auto-saved`})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[o&&n.length===2&&jsxRuntime.jsx("button",{type:"button",onClick:t,disabled:d,className:"kyro-btn kyro-btn-primary px-3 py-1.5 rounded-lg text-[11px] font-bold tracking-wider hover:opacity-90 disabled:opacity-50",children:d?"Comparing...":"Compare"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{a(!o),s([]),l([]);},className:`px-3 py-1.5 rounded-lg text-[11px] font-bold tracking-wider transition-all ${o?"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]":"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:o?"Done":"Compare"})]})]}),i.length>0&&jsxRuntime.jsxs("div",{className:"border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("div",{className:"px-6 py-3 flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-[11px] font-bold text-[var(--kyro-text-primary)] tracking-wider",children:[i.length," change",i.length!==1?"s":""]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l([]),className:"p-1 rounded hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-muted)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:i.map((y,g)=>jsxRuntime.jsxs("div",{className:"flex flex-col md:grid md:grid-cols-4 gap-1 md:gap-3 px-4 md:px-6 py-2.5 text-[11px] font-mono border-t border-[var(--kyro-border)] hover:bg-[var(--kyro-bg-secondary)]",children:[jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-muted)] truncate font-semibold md:font-normal",children:y.field}),jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-muted)] truncate hidden md:block",children:typeof y.oldValue=="object"?JSON.stringify(y.oldValue):String(y.oldValue??"null")}),jsxRuntime.jsxs("div",{className:"md:col-span-2 text-[var(--kyro-text-primary)] truncate",children:[jsxRuntime.jsx("span",{className:"md:hidden text-[var(--kyro-text-muted)]",children:"\u2192 "}),typeof y.newValue=="object"?JSON.stringify(y.newValue):String(y.newValue??"null")]})]},g))})]}),c?jsxRuntime.jsx("div",{className:"flex justify-center py-16",children:jsxRuntime.jsx("span",{className:"animate-spin text-[var(--kyro-primary)]",children:"\u231B"})}):m.length===0?jsxRuntime.jsx("div",{className:"text-center py-16 text-[var(--kyro-text-muted)] text-sm italic",children:"No versions yet."}):jsxRuntime.jsx("div",{className:"divide-y divide-[var(--kyro-border)]",children:m.map((y,g)=>{let x=n.includes(y.id),f=(y.changeDescription||"").toLowerCase().includes("auto");return jsxRuntime.jsxs("div",{onClick:o?()=>r(y.id):void 0,className:`transition-all ${o?x?"bg-[var(--kyro-primary)]/5 cursor-pointer":"hover:bg-[var(--kyro-bg-secondary)] cursor-pointer":"hover:bg-[var(--kyro-bg-secondary)]"}`,children:[jsxRuntime.jsxs("div",{className:"hidden md:grid grid-cols-12 gap-3 px-6 py-3 items-center",children:[jsxRuntime.jsx("div",{className:"col-span-1 flex items-center gap-2",children:o?jsxRuntime.jsx("div",{className:`w-4 h-4 rounded-full border ${x?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:x&&jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5",children:m.length-g})}),jsxRuntime.jsxs("div",{className:"col-span-4 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-2",children:[y.changeDescription||"Snapshot",f&&jsxRuntime.jsx("span",{className:"text-[9px] px-1.5 py-0.5 bg-[var(--kyro-bg-secondary)] text-[var(--kyro-text-secondary)] rounded font-bold tracking-wider",children:"Auto"})]}),jsxRuntime.jsx("div",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(y.createdAt).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),jsxRuntime.jsx("div",{className:"col-span-3",children:y.status&&jsxRuntime.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold capitalize tracking-wider ${y.status==="published"?" text-[var(--kyro-success)]":" text-[var(--kyro-warning)]"}`,children:[jsxRuntime.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${y.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),y.status]})}),jsxRuntime.jsx("div",{className:"col-span-2 text-[11px] text-[var(--kyro-text-muted)]",children:y.createdBy||"system"}),jsxRuntime.jsx("div",{className:"col-span-2 flex justify-end",children:!o&&jsxRuntime.jsx("button",{type:"button",onClick:()=>e(y.id),className:"px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[11px] font-bold tracking-wider text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] transition-all active:scale-95",children:"Restore"})})]}),jsxRuntime.jsxs("div",{className:"md:hidden flex items-start gap-3 px-4 py-3",children:[jsxRuntime.jsx("div",{className:"pt-0.5 shrink-0",children:o?jsxRuntime.jsx("div",{className:`w-4 h-4 rounded-full border ${x?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:x&&jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5 inline-block text-center",children:m.length-g})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-1.5",children:[y.changeDescription||"Snapshot",f&&jsxRuntime.jsx("span",{className:"text-[9px] px-1 py-0.5 bg-[var(--kyro-bg-secondary)] text-[var(--kyro-text-secondary)] rounded font-bold tracking-wider shrink-0",children:"Auto"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[jsxRuntime.jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(y.createdAt).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}),y.status&&jsxRuntime.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-bold capitalize tracking-wider ${y.status==="published"?"text-[var(--kyro-success)]":"text-[var(--kyro-warning)]"}`,children:[jsxRuntime.jsx("span",{className:`w-1 h-1 rounded-full ${y.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),y.status]}),jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-muted)] opacity-60",children:y.createdBy||"system"})]})]}),!o&&jsxRuntime.jsx("button",{type:"button",onClick:()=>e(y.id),className:"shrink-0 px-2.5 py-1 rounded-lg border border-[var(--kyro-border)] text-[10px] font-bold tracking-wider text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] transition-all active:scale-95",children:"Restore"})]})]},y.id)})})]})})}function $d({collectionSlug:e,globalSlug:t}){let{formData:r}=Le();return jsxRuntime.jsx("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4",children:jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_300px] gap-8",children:[jsxRuntime.jsxs("div",{className:"surface-tile p-8 min-w-0",children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold mb-6",children:"Response Payload"}),jsxRuntime.jsx("div",{className:"bg-[#0f172a] p-6 rounded-2xl border border-white/5 overflow-x-auto max-h-[800px]",children:jsxRuntime.jsx("pre",{className:"text-blue-300 text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(r,null,2)})})]}),jsxRuntime.jsx("div",{className:"space-y-6",children:jsxRuntime.jsxs("div",{className:"surface-tile p-8 space-y-6",children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold mb-6",children:"API Info"}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Reference Path"}),jsxRuntime.jsx("div",{className:"bg-[var(--kyro-bg-secondary)] px-4 py-3 rounded-xl border border-[var(--kyro-border)] text-[11px] font-mono break-all selection:bg-[var(--kyro-primary)]/20 text-[var(--kyro-text-primary)]",children:t?`kyro.globals('${t}').get()`:r.id?`kyro.collection('${e}').get('${r.id}')`:"Not saved yet"})]}),r.id&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Document ID"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"text-xs font-mono bg-[var(--kyro-bg-secondary)] px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]",children:String(r.id)}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(String(r.id));},className:"p-1.5 hover:bg-[var(--kyro-bg-secondary)] rounded-lg transition-colors text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]",title:"Copy ID",children:jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]}),t&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Global Slug"}),jsxRuntime.jsx("code",{className:"text-xs font-mono bg-[var(--kyro-bg-secondary)] px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]",children:t})]})]})]})})]})})}var Ed={};function _a({config:e,data:t=Ed,errors:r=Ed,onChange:o,disabled:a,collectionSlug:n,globalSlug:s,documentId:i,documentName:l,layout:d="split",onActionSuccess:c,onActionError:m,justSaved:y}){let g=e||(s?Hl[s]:n?Ho[n]:null),[x,f]=ka.useState(g);ka.useEffect(()=>{s==="storage-settings"?Be("/api/kyro/schema").then(T=>{T?.globals?.["storage-settings"]&&f(T.globals["storage-settings"]);}).catch(T=>console.error("[AutoForm] Failed to fetch dynamic schema",T)):f(g);},[s,g]);let u=x||g,{confirm:b}=at(),{formData:v,hasUnsavedChanges:L,autoSaveStatus:N,lastSavedAt:p,view:se,setView:ie,setShowPreview:B,isMenuOpen:K,setIsMenuOpen:ce,loadingFields:he,setLoadingFields:De,compareSelected:z,setCompareSelected:Ke,setCompareDiffs:Se,setLoadingDiffs:Tt,setField:Wt,setFormData:vt,setLastSavedData:X,setAutoSaveStatus:le,fetchVersions:xe,saveDocument:we,autoSaveSkipRef:Qe,lastAutoSaveTimeRef:wt,documentStatus:D,hasUnpublishedChanges:G,versionsEnabled:te}=Sd({config:u,initialData:t,collectionSlug:n,globalSlug:s,documentId:i,onChange:o,onActionSuccess:c,onActionError:m}),sr=ka.useRef(null),so=ka.useRef(null),[da,Ka]=ka.useState(false),[Zn,gt]=ka.useState("idle"),[h,re]=ka.useState(Date.now()),Pe=a,[qt,Lt]=ka.useState(false),[vr,ir]=ka.useState(false),[es,Rc]=ka.useState(0),ii=ka.useRef(new Map),Fc=3e4;ka.useEffect(()=>{let T=s?`global:${s}`:`${n}:${i}`;if(!(s||n&&i&&i!=="new")||t&&Object.keys(t).length>0)return;let Ne=ii.current.get(T),Te=Ne&&Date.now()-Ne.ts<Fc,ot=Ne&&!Te;if(Te){Le.getState().loadDocument(Ne.data,Ne.data);return}ot&&Le.getState().loadDocument(Ne.data,Ne.data);let Nt=new AbortController;ir(false),Ne||Lt(true);let Jt=s?`/api/globals/${s}`:`/api/${n}/${i}`;return Be(Jt,{autoToast:false,signal:Nt.signal}).then(At=>{let io=At.data||{};ii.current.set(T,{data:io,ts:Date.now()}),Le.getState().loadDocument(io,io),Lt(false);}).catch(At=>{At.name!=="AbortError"&&(Lt(false),Ne||ir(true));}),()=>Nt.abort()},[n,i,s,t,es]),ka.useEffect(()=>{let T=setInterval(()=>re(Date.now()),1e4);return ()=>clearInterval(T)},[]);let li=(T,J)=>{if(typeof T=="function")try{return T(v,J)}catch(Ne){return console.warn("Error evaluating admin runtime flag:",Ne),false}return !!T},Pc=T=>{b({title:"Restore Version",message:"Are you sure you want to restore this version? This will overwrite your current changes.",onConfirm:async()=>{try{let J=s?qe(`/api/globals/${s}/versions/${T}/restore`):qe(`/api/${n}/${v.id}/versions/${T}/restore`),Ne=await ct(J,{method:"POST"});!Ne.ok&&n&&(Ne=await ct(qe(`/api/${n}/${v.id}/versions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({versionId:T,action:"restore"})}));let Te=await Ne.json();if(Te.data){let ot={...v,...Te.data};vt(ot),Le.getState().loadDocument(ot,ot),c?.("Version restored successfully"),xe(),ie("edit");}else $.error(Te.error||"Failed to restore version");}catch(J){console.error("Failed to restore version:",J),$.error("Failed to restore version");}}});},Dc=async()=>{if(z.length===2){Tt(true);try{let J=await(await ct(qe(`/api/${n}/${v.id}/versions?compareA=${z[0]}&compareB=${z[1]}`))).json();Se(J.diffs||[]);}catch(T){console.error("Compare failed:",T),Se([]);}finally{Tt(false);}}},Bc=T=>{Ke(J=>J.includes(T)?J.filter(Ne=>Ne!==T):J.length>=2?[J[1],T]:[...J,T]);};ka.useEffect(()=>{let T=J=>{(J.metaKey||J.ctrlKey)&&J.key==="s"&&(J.preventDefault(),di()),(J.metaKey||J.ctrlKey)&&J.shiftKey&&(J.key==="P"||J.key==="p")&&(J.preventDefault(),document.getElementById("btn-publish")?.click()),(J.metaKey||J.ctrlKey)&&!J.shiftKey&&J.key==="p"&&(J.preventDefault(),B(Ne=>!Ne)),document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA"&&(J.key==="1"&&ie("edit"),J.key==="2"&&ie("version"),J.key==="3"&&ie("api"));};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]),ka.useEffect(()=>{let T=()=>ie("version");return window.addEventListener("kyro:show-version-history",T),()=>window.removeEventListener("kyro:show-version-history",T)},[]),ka.useEffect(()=>{let T=J=>{sr.current&&!sr.current.contains(J.target)&&ce(false);};if(K)return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[K]),ka.useEffect(()=>{let T=J=>{so.current&&!so.current.contains(J.target)&&Ka(false);};if(da)return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[da]);let Ic=()=>{L?b({title:"Unsaved Changes",message:"You have unsaved changes. Save before creating new?",onConfirm:async()=>{await di(),await new Promise(T=>setTimeout(T,1e3)),window.location.href=`${Ye}/${n}/new`;}}):window.location.href=`${Ye}/${n}/new`;},Lc=()=>{b({title:"Duplicate Document",message:"Are you sure you want to duplicate this document?",onConfirm:async()=>{try{let{id:T,createdAt:J,updatedAt:Ne,...Te}=v,ot=mr(Te),Nt=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...ot,title:`${Te.title||Te.name||"Copy"} (Copy)`,slug:`${Te.slug||"copy"}-${Date.now()}`,status:"draft"})});if(Nt.ok){let Jt=await Nt.json();c?.("Document duplicated successfully"),Jt.data?.id&&(window.location.href=`${Ye}/${n}/${Jt.data.id}`);}else {let Jt=await Nt.json();$.error(Jt.error||"Failed to duplicate document");}}catch{$.error("Failed to duplicate document");}}});},Mc=()=>{b({title:"Delete Document",message:"Delete this document? This cannot be undone. Are you absolutely sure?",variant:"danger",onConfirm:async()=>{try{await bt(`/api/${n}/${v.id}`),window.location.href=`${Ye}/${n}`;}catch(T){$.error(T.message||"Failed to delete document");}}});},$c=()=>{b({title:"Unpublish Document",message:"Unpublish this document?",onConfirm:async()=>{try{let T=await we({...v,status:"draft"},!1);if(T?.ok)c?.("Document unpublished successfully"),Le.getState().loadDocument({...v,status:"draft"},{...v,status:"draft"});else {let J=await T?.json().catch(()=>({}));$.error(J?.error||"Failed to unpublish");}}catch{$.error("Failed to unpublish");}}});},di=async()=>{let T=!v.id;Qe.current=true,gt("saving");try{let J=mr({...v}),Ne=T&&!s,Te=Ne?await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J)}):await we(J);if(Te.ok){let Nt=(await Te.json()).data||J;vt({...v,...Nt}),X({...v,...Nt}),wt.current=Date.now(),le("success"),gt("saved"),te&&xe(),setTimeout(()=>{le("idle"),gt("idle");},2e3),c?.(Ne?"Document created successfully":"Changes saved"),Ne&&setTimeout(()=>{window.location.href=`${Ye}/${n}`;},800);}else {let ot=await Te.json();Te.status===409&&le("conflict"),gt("error"),$.error(ot.error||"Failed to save"),setTimeout(()=>gt("idle"),3e3);}}catch{gt("error"),$.error("Failed to save document"),setTimeout(()=>gt("idle"),3e3);}finally{Qe.current=false;}},Ec=async()=>{let T=!v.id;Qe.current=true,gt("saving");try{let J={...v};if(T&&!s){let ot=mr({...v}),Nt=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ot)});if(!Nt.ok){let io=await Nt.json().catch(()=>({}));Nt.status===409&&le("conflict"),gt("error"),$.error(io.error||"Failed to create document"),setTimeout(()=>gt("idle"),3e3);return}let At=(await Nt.json()).data||ot;vt({...v,...At}),X({...v,...At}),J={...v,...At};}let Ne=mr(J),Te=await we(Ne,!1);if(Te?.ok)gt("saved"),c?.("Published successfully");else {let ot=await Te?.json().catch(()=>({}));Te?.status===409&&le("conflict"),gt("error"),$.error(ot?.error||"Failed to publish"),setTimeout(()=>gt("idle"),3e3);}}catch{gt("error"),$.error("Failed to publish"),setTimeout(()=>gt("idle"),3e3);}finally{Qe.current=false;}},Oc=async T=>{let J=!v.id;Qe.current=true;try{let Ne={...mr({...v}),_schedulePublishAt:T};if(J&&!s){let Te=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Ne)});if(!Te.ok){let ot=await Te.json().catch(()=>({}));$.error(ot.error||"Failed to schedule publish");return}}else {let Te=await we(Ne);if(!Te.ok){let ot=await Te.json().catch(()=>({}));$.error(ot.error||"Failed to schedule publish");return}}c?.(`Scheduled publish for ${new Date(T).toLocaleString()}`),Ka(!1);}catch{$.error("Failed to schedule publish");}finally{Qe.current=false;}},Uc=(T,J)=>{Wt(T,J);},ca=(T,J,Ne)=>{let Te=J!==void 0?J:v;if(li(T.hidden!==void 0?T.hidden:T.admin?.hidden,Te))return null;let Nt=li(T.readOnly!==void 0?T.readOnly:T.admin?.readOnly,Te),Jt=!!(Pe||Nt);if(T.admin?.condition){if(typeof T.admin.condition=="function")try{let $e={values:v||{},...v||{}};if(!T.admin.condition($e,Te))return null}catch($e){console.warn(`Condition error for field ${T.name}:`,$e);}else if(typeof T.admin.condition=="object")try{let $e=T.admin.condition,Ue=$e.field,_t=Te&&Te[Ue]!==void 0?Te[Ue]:v&&v[Ue]!==void 0?v[Ue]:void 0,Cr=!0;if("equals"in $e?Cr=_t===$e.equals:"notEquals"in $e?Cr=_t!==$e.notEquals:"in"in $e&&Array.isArray($e.in)&&(Cr=$e.in.includes(_t)),!Cr)return null}catch($e){console.warn(`Declarative condition error for field ${T.name}:`,$e);}}let At=Te[T.name],io=r[T.name],Ga=$e=>{Ne?Ne({...Te,[T.name]:$e}):Uc(T.name,$e);};if(T.type==="row"&&"fields"in T){let $e=T.fields;return jsxRuntime.jsx("div",{className:"kyro-form-row flex flex-col md:flex-row gap-4 md:gap-6 items-start md:items-end w-full",children:$e?.map(Ue=>{let _t=Ue.admin||{},Cr=_t?.action;if((Ue.type==="button"||Ue.type==="action")&&Cr){let gr=$e?.find(pa=>pa.type==="email");return jsxRuntime.jsx("div",{className:"flex-shrink-0",children:jsxRuntime.jsx("button",{type:"button",onClick:async()=>{let pa=T.name,Wa=gr?.name,qa=Wa?v[Wa]:void 0;if(!qa&&pa&&typeof pa=="string"&&Wa&&(qa=v[pa]?.[Wa]),!!qa){De(br=>({...br,[Ue.name]:true}));try{let br=await ct(qe(Cr),{method:_t.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:qa})}),ma={};try{ma=await br.json();}catch{ma={};}if(br.ok&&ma.success)c?.(ma.message||"Action completed successfully");else {let zc=ma.error||`Request failed (${br.status})`;m?.(zc);}}catch(br){m?.(br instanceof Error?br.message:"Error connecting to server");}finally{De(br=>({...br,[Ue.name]:false}));}}},disabled:he[Ue.name]||Jt,className:"kyro-btn kyro-btn-primary px-4 py-2 rounded-lg font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:he[Ue.name]?"Sending...":Ue.label||"Click"})},Ue.name)}return jsxRuntime.jsx("div",{className:Ue.type==="button"||Ue.type==="action"?"flex-shrink-0":"flex-1",style:_t?.width?{width:_t.width,flex:"none"}:{},children:ca(Ue,J,Ne)},Ue.name)})},T.name||`row-${Math.random()}`)}switch(T.type){case "tabs":return jsxRuntime.jsx(Pd,{field:T,formData:v,onTabDataChange:$e=>{Wt(T.name,$e);},renderField:($e,Ue,_t)=>ca($e,Ue,_t)},T.name||`tabs-${Math.random()}`);case "group":return jsxRuntime.jsx(On,{field:T,value:At,onChange:Ga,renderField:ca},T.name);case "array":return jsxRuntime.jsx(Un,{field:T,value:At,onChange:Ga,renderField:ca,disabled:Jt},T.name);case "button":case "action":{let $e=T.name,Ue=he[$e];return jsxRuntime.jsx("div",{className:"kyro-form-field",children:jsxRuntime.jsxs("button",{type:"button",disabled:Ue||Jt,onClick:async()=>{let _t=T.admin?.action||T.action,Cr=T.admin?.method||T.method||"POST";if(_t){De(gr=>({...gr,[$e]:true}));try{let gr=await ct(_t,{method:Cr,headers:{"Content-Type":"application/json"},body:JSON.stringify(v)});await gr.json(),gr.ok;}catch(gr){console.error("Error executing action:",gr);}finally{De(gr=>({...gr,[$e]:false}));}}},className:`kyro-btn kyro-btn-md kyro-btn-secondary transition-all active:scale-95 whitespace-nowrap flex items-center gap-2 ${Ue?"opacity-70 cursor-not-allowed":""}`,children:[Ue&&jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),Ue?"Processing...":T.label||"Click"]})},$e)}case "relationship-block":return jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[T.label||T.name,T.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsx(Ua,{relationTo:T.relationTo,hasMany:T.hasMany,selectedIds:Array.isArray(At)?At:At?[At]:[],onChange:($e,Ue)=>{Ga(Ue);},compact:true}),T.admin?.description?jsxRuntime.jsx("p",{className:"kyro-form-help",children:String(T.admin?.description)}):null]},T.name);default:return jsxRuntime.jsx(xo,{field:T,value:At,onChange:Ga,error:io,disabled:Jt},T.name||Math.random().toString())}};return qt?jsxRuntime.jsxs("div",{className:"space-y-6 p-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Et,{variant:"text",className:"w-1/3"}),jsxRuntime.jsx(Et,{variant:"text",className:"w-2/3"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Et,{variant:"rect",count:4})})]}):vr?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-16",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-8 h-8 text-[var(--kyro-danger)]"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)]",children:"Failed to load document. Check your connection."}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{ir(false),Lt(true),Rc(T=>T+1);},className:"kyro-btn kyro-btn-primary px-6 py-2 rounded-xl text-sm font-bold",children:"Retry"})]}):jsxRuntime.jsxs("div",{className:"flex flex-col h-full",children:[d!=="single"&&jsxRuntime.jsx(Id,{collectionSlug:n,globalSlug:s,documentStatus:D||"draft",hasUnpublishedChanges:G,localSaveStatus:Zn,handleCreateNew:Ic,handleDuplicate:Lc,handleUnpublish:$c,handleDelete:Mc,handlePublish:Ec,handleSchedulePublish:Oc}),d==="single"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 text-[11px] font-medium",children:[N==="saving"&&jsxRuntime.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Saving..."]}),N==="success"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"}),p?`Saved ${Math.floor((Date.now()-p)/6e4)}m ago`:"Saved"]}),N==="retrying"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Retrying..."]}),N==="offline"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]",children:"Offline \u2014 cached locally"}),N==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Save failed"}),N==="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Conflict detected"}),L&&N!=="saving"&&N!=="retrying"&&N!=="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-warning)]",children:"Unsaved changes"}),!L&&N!=="success"&&N!=="saving"&&N!=="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-success)]",children:"All changes saved"})]}),jsxRuntime.jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)] opacity-60",children:v.updatedAt?`Modified ${new Date(v.updatedAt).toLocaleString()}`:""})]}),jsxRuntime.jsx("button",{id:"btn-save",type:"button",style:{width:0,height:0,opacity:0,padding:0,margin:0,border:"none",position:"absolute"},onClick:async()=>{try{let T=await we(v);if(T.ok){let Ne=(await T.json()).data||v;vt({...v,...Ne}),X({...v,...Ne}),c?.("Changes saved");}}catch(T){console.error("Save error exception:",T),m?.("Save failed: "+T.message);}}})]}),jsxRuntime.jsxs("main",{className:"w-full pt-6 md:pt-0",children:[se==="edit"&&jsxRuntime.jsx(Ld,{config:u,layout:d,collectionSlug:n,renderField:ca}),se==="version"&&jsxRuntime.jsx(Md,{handleRestoreVersion:Pc,handleCompareVersions:Dc,toggleCompareSelection:Bc}),se==="api"&&jsxRuntime.jsx($d,{collectionSlug:n,globalSlug:s})]})]})}var Od={draft:"bg-[var(--kyro-warning)]",published:"bg-[var(--kyro-success)]",scheduled:"bg-[var(--kyro-primary)]",archived:"bg-[var(--kyro-text-muted)]"};function Zs({status:e,saveStatus:t,hasChanges:r,onSave:o,onPublish:a,onUnpublish:n,onDuplicate:s,onViewHistory:i,onPreview:l,onDelete:d,onBack:c,onToggleSidebar:m,publishedAt:y,updatedAt:g}){let x=Le(N=>N.view)||"edit",f=Le(N=>N.setView),[u,b]=ka.useState(false),v=ka.useRef(null);ka.useEffect(()=>{let N=p=>{v.current&&!v.current.contains(p.target)&&b(false);};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);let R=()=>t==="saving"?"Saving...":t==="saved"?"Saved":t==="error"?"Error saving":r?"Unsaved":null,L=["edit","version","api"],C=R(),w="p-1.5 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] transition-all shrink-0";return jsxRuntime.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 bg-[var(--kyro-surface)] border-b border-[var(--kyro-border)] w-full overflow-x-auto",children:[c&&jsxRuntime.jsx("button",{type:"button",onClick:c,className:"p-1 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] transition-all shrink-0",children:jsxRuntime.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),jsxRuntime.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${Od[e]||"bg-[var(--kyro-text-muted)]"}`}),C&&jsxRuntime.jsxs("span",{className:`text-[10px] whitespace-nowrap max-md:hidden ${t==="error"?"text-[var(--kyro-error)]":"text-[var(--kyro-text-muted)]"}`,children:[t==="saving"&&jsxRuntime.jsx(Ar,{size:"sm",className:"inline mr-0.5"}),C]}),jsxRuntime.jsx("div",{className:"flex items-center gap-0.5 bg-[var(--kyro-bg-secondary)] p-0.5 rounded-lg border border-[var(--kyro-border)] shrink-0 max-md:hidden",children:L.map(N=>jsxRuntime.jsx("button",{type:"button",onClick:()=>f(N),className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all ${x===N?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:N==="edit"?"Edit":N==="version"?"Ver":"API"},N))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1 ml-auto shrink-0",children:[l&&jsxRuntime.jsx("button",{type:"button",onClick:l,className:`${w} max-md:hidden`,title:"Preview",children:jsxRuntime.jsx(lucideReact.Eye,{className:"w-3.5 h-3.5"})}),i&&jsxRuntime.jsx("button",{type:"button",onClick:i,className:`${w} max-md:hidden`,title:"View History",children:jsxRuntime.jsx(lucideReact.Clock,{className:"w-3.5 h-3.5"})}),s&&jsxRuntime.jsx("button",{type:"button",onClick:s,className:`${w} max-md:hidden`,title:"Duplicate",children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})}),d&&jsxRuntime.jsx("button",{type:"button",onClick:d,className:`${w} hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] max-md:hidden`,title:"Delete",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})}),m&&jsxRuntime.jsx("button",{type:"button",onClick:m,className:`${w} max-md:hidden`,title:"Toggle Sidebar",children:jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),jsxRuntime.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsxRuntime.jsxs("div",{ref:v,className:"relative md:hidden",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>b(!u),className:w,title:"More",children:jsxRuntime.jsx(lucideReact.EllipsisVertical,{className:"w-3.5 h-3.5"})}),u&&jsxRuntime.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 py-1 max-h-[70vh] overflow-y-auto",children:[C&&jsxRuntime.jsxs("div",{className:"px-3 py-2 text-[10px] text-[var(--kyro-text-muted)] border-b border-[var(--kyro-border)] flex items-center gap-1.5",children:[jsxRuntime.jsx("div",{className:`w-1.5 h-1.5 rounded-full ${Od[e]}`}),jsxRuntime.jsx("span",{className:"capitalize",children:e}),jsxRuntime.jsx("span",{children:"\xB7"}),t==="saving"&&jsxRuntime.jsx(Ar,{size:"sm",className:"inline"}),jsxRuntime.jsx("span",{children:C})]}),jsxRuntime.jsx("div",{className:"flex gap-1 px-2 py-2 border-b border-[var(--kyro-border)]",children:L.map(N=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{f(N),b(false);},className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all flex-1 ${x===N?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)]"}`,children:N==="edit"?"Edit":N==="version"?"Ver":"API"},N))}),i&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{i(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3.5 h-3.5"})," View History"]}),s&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{s(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})," Duplicate"]}),l&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{l(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Eye,{className:"w-3.5 h-3.5"})," Preview"]}),d&&jsxRuntime.jsx("div",{className:"border-t border-[var(--kyro-border)] mt-1 pt-1",children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>{d(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-danger)] hover:bg-[var(--kyro-danger-bg)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})," Delete"]})})]})]}),jsxRuntime.jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),e==="draft"&&a&&jsxRuntime.jsxs("button",{type:"button",onClick:a,disabled:t==="saving",className:"kyro-btn kyro-btn-primary kyro-btn-sm flex items-center gap-1 shrink-0",children:[jsxRuntime.jsx(lucideReact.Send,{className:"w-3.5 h-3.5"}),jsxRuntime.jsx("span",{className:"max-md:hidden",children:"Publish"})]}),e==="published"&&n&&jsxRuntime.jsxs("button",{type:"button",onClick:n,disabled:t==="saving",className:"kyro-btn kyro-btn-secondary kyro-btn-sm flex items-center gap-1 shrink-0",children:[jsxRuntime.jsx(lucideReact.Undo,{className:"w-3.5 h-3.5"}),jsxRuntime.jsx("span",{className:"max-md:hidden",children:"Unpublish"})]}),jsxRuntime.jsxs(Co,{status:e,saveStatus:t,hasChanges:r,onPublish:o,children:[s&&jsxRuntime.jsx(jt,{icon:jsxRuntime.jsx(lucideReact.Copy,{className:"w-4 h-4"}),children:"Duplicate"}),i&&jsxRuntime.jsx(jt,{icon:jsxRuntime.jsx(lucideReact.Clock,{className:"w-4 h-4"}),children:"View History"}),l&&jsxRuntime.jsx(jt,{icon:jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"}),children:"Preview"}),(s||i||l)&&jsxRuntime.jsx(ja,{}),d&&jsxRuntime.jsx(jt,{onClick:d,danger:true,icon:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"}),children:"Delete"})]})]})]})}function ti({config:e,collection:t,global:r,documentId:o,onBack:a,onSave:n,onDelete:s,onError:i,mode:l="collection"}){let{confirm:d,alert:c}=at(),[m,y]=ka.useState({}),[g,x]=ka.useState({}),[f,u]=ka.useState(true),[b,v]=ka.useState(false),[R,L]=ka.useState("idle"),[C,w]=ka.useState(false),[N,p]=ka.useState("draft"),[A,O]=ka.useState(null),[F,P]=ka.useState(null),[S,M]=ka.useState(null),[j,se]=ka.useState(false),ie=r?.fields||t?.fields||[],ue=r?.label||t?.label||"Document",oe=r?.slug||t?.slug||"",ne=JSON.stringify(m)!==JSON.stringify(g);ka.useEffect(()=>{ne&&N==="published"&&p("draft");},[ne,N]),ka.useEffect(()=>{ne&&R==="saved"&&L("idle");},[ne,R]),ka.useEffect(()=>{l==="global"?ft():o&&je();},[o,l,oe]);let je=async()=>{try{u(!0);let I=await Be(`/api/${oe}/${o}`,{autoToast:!1}),z=I.data||{};y(z),x(z),p(z?.status||I.status||"draft"),O(I.createdAt||z.createdAt||null),P(I.updatedAt||z.updatedAt||null),M(I.publishedAt||z.publishedAt||null);}catch{i("Failed to load document");}finally{u(false);}},ft=async()=>{try{u(!0);let I=await Be(`/api/globals/${oe}`,{autoToast:!1}),z=I.data||{};y(z),x(z),O(I.createdAt||null),P(I.updatedAt||null);}catch{i("Failed to load global");}finally{u(false);}},B=ka.useCallback(async(I=false)=>{try{L("saving");let z=l==="global"?`/api/globals/${oe}`:`/api/${oe}/${o}`,Ke=N==="draft"||m?.status==="draft",ye=await Xt(z,m,{autoToast:!1,headers:{"X-Draft":String(Ke)}}),Se=ye&&(ye.data||ye)||m;I||(x(Se),n()),y(Se),p(Se?.status||N),L("saved"),P(new Date().toISOString()),se(!0),setTimeout(()=>se(!1),3e3),I||(N==="draft"||Se?.status==="draft"?$.warning("Draft saved"):$.success("Updated")),setTimeout(()=>{L("idle");},2e3);}catch{L("error"),I||(i("Failed to save changes"),$.error("Failed to save changes"));}finally{v(false);}},[m,l,oe,o,N,n,i]),K=async()=>{try{v(!0),await Xt(`/api/${oe}/${o}`,m,{autoToast:!1,headers:{"X-Draft":"false"}}),p("published"),M(new Date().toISOString()),$.success("Published successfully"),n();}catch{i("Failed to publish"),$.error("Failed to publish");}finally{v(false);}},ce=async()=>{try{v(!0),await Xt(`/api/${oe}/${o}`,{status:"draft"},{autoToast:!1,headers:{"X-Draft":"false"}}),p("draft"),$.warning("Document unpublished"),n();}catch{i("Failed to unpublish"),$.error("Failed to unpublish");}finally{v(false);}},he=async()=>{try{v(!0),await et(`/api/${oe}/${o}/duplicate`,void 0,{autoToast:!1}),$.success("Document duplicated");}catch(I){let z=I instanceof Error?I.message:"Failed to duplicate document";i(z),$.error(z);}finally{v(false);}},De=()=>{d({title:`Delete ${ue}?`,message:"This action cannot be undone.",variant:"danger",onConfirm:async()=>{try{w(!0),await bt(`/api/${oe}/${o}`,{autoToast:!1}),s?.(),$.error("Document deleted");}catch(I){let z=I instanceof Error?I.message:"Failed to delete document";$.error(z);}finally{w(false);}}});};if(f)return jsxRuntime.jsx("div",{className:"kyro-detail",children:jsxRuntime.jsxs("div",{className:"space-y-6 p-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Et,{variant:"text",className:"w-1/3"}),jsxRuntime.jsx(Et,{variant:"text",className:"w-2/3"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Et,{variant:"rect",count:4})})]})});let Ce=l==="global"||t?.admin?.layout==="single";return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Ft,{back:{onClick:a},breadcrumbs:[{label:l==="global"?"Globals":"Collections"},{label:ue,href:l==="collection"?`${Ye}/${oe}`:void 0},{label:l==="global"||o?"Edit":"New"}],title:l==="global"?ue:yo(t?.fields,m,t?.admin?.useAsTitle||"title")||m.name||o||`New ${t?.singularLabel||ue}`,metadata:[jsxRuntime.jsx(Pt,{variant:N==="published"?"success":"warning",dot:true,className:"text-[10px] font-bold ",children:N},"status")]}),jsxRuntime.jsx(Zs,{status:N,saveStatus:R,hasChanges:ne,onSave:()=>B(false),onPublish:K,onUnpublish:N==="published"?ce:void 0,onDuplicate:he,onViewHistory:()=>{window.dispatchEvent(new CustomEvent("kyro:show-version-history"));},onPreview:()=>window.open(`/preview/${oe}/${o}`,"_blank"),onDelete:De,onBack:a,onToggleSidebar:()=>window.dispatchEvent(new CustomEvent("toggle-sidebar")),publishedAt:S,updatedAt:F}),jsxRuntime.jsxs("div",{className:Ce?"w-full pt-4 md:pt-8":"w-full mx-auto grid grid-cols-1 lg:grid-cols-[1fr_360px] gap-4 md:gap-8 pt-4 md:pt-0",children:[jsxRuntime.jsx("div",{className:"space-y-4 md:space-y-8 min-w-0",children:jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-8 px-1",children:[jsxRuntime.jsx("h2",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Core Configuration"}),jsxRuntime.jsx("div",{className:"h-px flex-1 bg-[var(--kyro-border)] ml-6 opacity-30"})]}),jsxRuntime.jsx(_a,{config:t?{...t,fields:ie}:{slug:"unknown",fields:ie},data:m,onChange:y,layout:Ce?"single":"split",globalSlug:l==="global"?oe:void 0,collectionSlug:l==="collection"?oe:void 0,onActionSuccess:I=>$.success(I),onActionError:I=>$.error(I),documentStatus:N,justSaved:j}),Ce&&jsxRuntime.jsxs("div",{className:"mt-8 pt-8 border-t border-[var(--kyro-border)] flex justify-end gap-3",children:[l==="collection"&&o&&jsxRuntime.jsx("button",{type:"button",onClick:De,className:"kyro-btn kyro-btn-lg kyro-btn-ghost text-[var(--kyro-error)]",children:"Delete"}),jsxRuntime.jsx(Co,{status:N,saveStatus:b?"saving":"idle",hasChanges:ne,onPublish:()=>B(false),disabled:b})]})]})}),!Ce&&jsxRuntime.jsxs("div",{className:"space-y-4 md:space-y-6 animate-in fade-in slide-in-from-right-4 duration-500",children:[jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsxRuntime.jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4 md:mb-6",children:"Metadata"}),jsxRuntime.jsxs("div",{className:"space-y-4 md:space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Dynamic Status"}),jsxRuntime.jsx("div",{children:jsxRuntime.jsx("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-[9px] font-bold tracking-widest ${N==="published"?"bg-green-500/10 text-green-500":"bg-amber-500/10 text-amber-500"}`,children:N||"draft"})})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Date Created"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:A?new Date(A).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Last Modified"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:F?new Date(F).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"Just now"})]}),S&&jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Public At"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:new Date(S).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"})})]})]})]}),jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-8 bg-[var(--kyro-bg-secondary)]",children:[jsxRuntime.jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-3 md:mb-4",children:"Quick Links"}),jsxRuntime.jsxs("div",{className:"space-y-2 md:space-y-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:he,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"Duplicate Document"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(`/preview/${oe}/${o}`,"_blank"),className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"View Public Page"}),jsxRuntime.jsx("button",{type:"button",onClick:De,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start text-[var(--kyro-error)] hover:bg-[var(--kyro-danger-bg)]",children:"Delete Entry"})]})]})]})]})]})}function ri({config:e,collection:t,onCancel:r,onSuccess:o,onError:a}){let[n,s]=ka.useState({}),[i,l]=ka.useState(false),d=t.fields||[],c=t.label||t.slug,m=async y=>{try{l(!0),await et(`/api/${t.slug}`,n),$.success(`${t.singularLabel||t.label||"Document"} created`),o();}catch(g){a(g instanceof Error?g.message:"Failed to create");}finally{l(false);}};return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Ft,{back:{onClick:r},breadcrumbs:[{label:"Collections"},{label:c,href:`${Ye}/${t.slug}`},{label:"New"}],title:`Create ${t.singularLabel||c}`,action:{label:i?"Creating...":`Create ${t.singularLabel||c}`,onClick:()=>m()}}),jsxRuntime.jsx("div",{className:"kyro-detail-body",children:jsxRuntime.jsx("div",{className:"kyro-card",children:jsxRuntime.jsx("div",{className:"kyro-card-content",children:jsxRuntime.jsx("form",{children:jsxRuntime.jsx(_a,{config:{...t,fields:d},data:n,onChange:s})})})})})]})}function zd({type:e,message:t,onClose:r}){let[o,a]=ka__default.default.useState(false),n=ka__default.default.useRef(null),s=()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(r,5e3);},i=()=>{n.current&&clearTimeout(n.current);};ka__default.default.useEffect(()=>(o?i():s(),i),[o,r]);let l={success:lucideReact.CircleCheck,error:lucideReact.ShieldAlert,warning:lucideReact.TriangleAlert,info:lucideReact.Info}[e];return jsxRuntime.jsxs("div",{className:`kyro-toast kyro-toast-${e} group animate-in fade-in slide-in-from-right-4 duration-300`,onMouseEnter:()=>a(true),onMouseLeave:()=>a(false),children:[jsxRuntime.jsx("div",{className:"kyro-toast-accent"}),jsxRuntime.jsx("div",{className:"kyro-toast-icon-container",children:jsxRuntime.jsx(l,{className:"w-4 h-4"})}),jsxRuntime.jsx("div",{className:"kyro-toast-content",children:jsxRuntime.jsx("p",{className:"kyro-toast-message",children:t})}),jsxRuntime.jsx("button",{type:"button",className:"kyro-toast-close group-hover:opacity-100 opacity-40 transition-opacity",onClick:r,children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5"})})]})}function H4({children:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function _4(){let e=Vt(o=>o.addToast),t=Vt(o=>o.removeToast);return {toasts:Vt(o=>o.toasts),addToast:e,removeToast:t}}function Gn(){let e=Vt(r=>r.toasts),t=Vt(r=>r.removeToast);return jsxRuntime.jsx("div",{className:"kyro-toasts-container",style:{position:"fixed",bottom:"24px",right:"24px",display:"flex",flexDirection:"column",gap:"12px",zIndex:9999,pointerEvents:"none"},children:e.map(r=>jsxRuntime.jsx("div",{style:{pointerEvents:"auto"},children:jsxRuntime.jsx(zd,{type:r.type,message:r.message,onClose:()=>t(r.id)})},r.id))})}function ni({onAuth:e,theme:t="light"}){let[r,o]=ka.useState("login"),[a,n]=ka.useState(""),[s,i]=ka.useState(""),[l,d]=ka.useState(""),[c,m]=ka.useState(false),[y,g]=ka.useState(false),x=Vt(b=>b.addToast);ka.useEffect(()=>{f();},[]);let f=async()=>{try{await Be("/api/users");}catch{g(true),o("register");}};return jsxRuntime.jsx(kr,{defaultMode:t,children:jsxRuntime.jsxs("div",{className:"kyro-login-page",children:[jsxRuntime.jsxs("div",{className:"kyro-login-container",children:[jsxRuntime.jsxs("div",{className:"kyro-login-header",children:[jsxRuntime.jsx("h1",{className:"kyro-login-title",children:y?"Create Admin Account":r==="login"?"Sign In":"Create Account"}),jsxRuntime.jsx("p",{className:"kyro-login-subtitle",children:y?"Set up your admin account to get started":r==="login"?"Enter your credentials to access the admin":"Create an account to access the admin"})]}),jsxRuntime.jsxs("form",{onSubmit:async b=>{b.preventDefault(),m(true);try{let v=r==="login"?"/api/auth/login":"/api/auth/register",R={email:a,password:s};r==="register"&&(R.confirmPassword=l);let L=await et(v,R);L.isFirstUser&&g(!0),localStorage.setItem("kyro_user",JSON.stringify(L.user)),x("success",r==="login"?"Welcome back!":"Account created!"),e(L.token,L.user);}catch{x("error","Connection failed");}finally{m(false);}},className:"kyro-login-form",children:[jsxRuntime.jsxs("div",{className:"kyro-form-group",children:[jsxRuntime.jsx("label",{htmlFor:"email",children:"Email"}),jsxRuntime.jsx("input",{id:"email",type:"email",value:a,onChange:b=>n(b.target.value),placeholder:"admin@example.com",required:true,autoComplete:"email"})]}),jsxRuntime.jsxs("div",{className:"kyro-form-group",children:[jsxRuntime.jsx("label",{htmlFor:"password",children:"Password"}),jsxRuntime.jsx("input",{id:"password",type:"password",value:s,onChange:b=>i(b.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:r==="login"?"current-password":"new-password"})]}),r==="register"&&jsxRuntime.jsxs("div",{className:"kyro-form-group",children:[jsxRuntime.jsx("label",{htmlFor:"confirmPassword",children:"Confirm Password"}),jsxRuntime.jsx("input",{id:"confirmPassword",type:"password",value:l,onChange:b=>d(b.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:"new-password"})]}),jsxRuntime.jsx("button",{type:"submit",className:"kyro-btn kyro-btn-primary kyro-btn-lg",disabled:c,children:c?r==="login"?"Signing in...":"Creating account...":r==="login"?"Sign In":"Create Account"})]}),!y&&jsxRuntime.jsx("div",{className:"kyro-login-footer",children:jsxRuntime.jsx("p",{children:r==="login"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Don't have an account?"," ",jsxRuntime.jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("register"),children:"Sign up"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Already have an account?"," ",jsxRuntime.jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("login"),children:"Sign in"})]})})})]}),jsxRuntime.jsx(Gn,{})]})})}function _d({collections:e,onNavigate:t,user:r}){let{permissions:o}=Mr(),[a,n]=ka.useState({totalDocs:0,totalMedia:0,totalUsers:0,recentActivity:[]}),[s,i]=ka.useState(true);ka.useEffect(()=>{let d=setTimeout(()=>{n({totalDocs:124,totalMedia:856,totalUsers:12,recentActivity:[{id:1,type:"edit",user:"Daniel Dozie",doc:"Getting Started with Kyro",collection:"posts",time:"2m ago"},{id:2,type:"create",user:"Jane Smith",doc:"New Product Launch",collection:"products",time:"15m ago"},{id:3,type:"upload",user:"Daniel Dozie",doc:"hero-banner.jpg",collection:"media",time:"1h ago"},{id:4,type:"publish",user:"System",doc:"Weekly Update",collection:"posts",time:"3h ago"}]}),i(false);},800);return ()=>clearTimeout(d)},[]);let l=Object.entries(e).filter(([d])=>!Fs.includes(d)&&o?.collections?.[d]?.read!==false);return jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 px-8 pb-12",children:[jsxRuntime.jsx(Ft,{title:`Welcome back, ${r?.email?.split("@")[0]||"Admin"}`,description:"Everything looks great in your command center today.",action:l.length>0&&o?.collections?.[l[0]?.[0]]?.create!==false?{label:"New Document",onClick:()=>t("create",l[0]?.[0]),icon:lucideReact.Plus}:void 0}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[{label:"Total Content",value:a.totalDocs,icon:lucideReact.FileText,color:"text-blue-500"},{label:"Media Assets",value:a.totalMedia,icon:lucideReact.Image,color:"text-purple-500"},{label:"Active Users",value:a.totalUsers,icon:lucideReact.Users,color:"text-green-500"},{label:"System Health",value:"100%",icon:lucideReact.Activity,color:"text-amber-500"}].map((d,c)=>jsxRuntime.jsxs("div",{className:"surface-tile p-6 flex items-center justify-between group hover:border-[var(--kyro-primary)] transition-all duration-500 cursor-default",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-1",children:d.label}),jsxRuntime.jsx("h3",{className:"text-3xl font-bold tracking-tighter",children:s?jsxRuntime.jsx(Et,{variant:"text",className:"w-16"}):d.value})]}),jsxRuntime.jsx("div",{className:`p-3 rounded-2xl bg-[var(--kyro-bg-secondary)] group-hover:scale-110 transition-transform duration-500 ${d.color}`,children:jsxRuntime.jsx(d.icon,{className:"w-6 h-6"})})]},c))}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_400px] gap-8",children:[jsxRuntime.jsxs("div",{className:"space-y-8 min-w-0",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-8",children:[jsxRuntime.jsxs("h2",{className:"text-xl font-bold mb-1 tracking-tight flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.LayoutDashboard,{className:"w-5 h-5 opacity-40"}),"Content Growth"]}),jsxRuntime.jsx("p",{className:"text-[10px] font-bold tracking-widest opacity-40 mb-8",children:"Snapshot of document velocity over the last 7 days"}),jsxRuntime.jsxs("div",{className:"h-48 w-full relative mb-12",children:[jsxRuntime.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 1000 200",preserveAspectRatio:"none",children:[jsxRuntime.jsx("defs",{children:jsxRuntime.jsxs("linearGradient",{id:"chartGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[jsxRuntime.jsx("stop",{offset:"0%",stopColor:"var(--kyro-primary)",stopOpacity:"0.3"}),jsxRuntime.jsx("stop",{offset:"100%",stopColor:"var(--kyro-primary)",stopOpacity:"0"})]})}),jsxRuntime.jsx("path",{d:"M0,180 Q100,140 200,160 T400,100 T600,120 T800,40 T1000,60 L1000,200 L0,200 Z",fill:"url(#chartGradient)",className:"animate-pulse duration-[4s]"}),jsxRuntime.jsx("path",{d:"M0,180 Q100,140 200,160 T400,100 T600,120 T800,40 T1000,60",fill:"none",stroke:"var(--kyro-primary)",strokeWidth:"4",strokeLinecap:"round",vectorEffect:"non-scaling-stroke",className:"filter drop-shadow-[0_0_8px_var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-4 text-[10px] font-bold opacity-30 tracking-widest ",children:[jsxRuntime.jsx("span",{children:"Mon"}),jsxRuntime.jsx("span",{children:"Tue"}),jsxRuntime.jsx("span",{children:"Wed"}),jsxRuntime.jsx("span",{children:"Thu"}),jsxRuntime.jsx("span",{children:"Fri"}),jsxRuntime.jsx("span",{children:"Sat"}),jsxRuntime.jsx("span",{children:"Sun"})]})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:l.map(([d,c])=>jsxRuntime.jsxs("div",{onClick:()=>t("list",d),className:"p-6 rounded-2xl border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] bg-[var(--kyro-bg-secondary)] hover:bg-[var(--kyro-surface)] transition-all cursor-pointer group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("h3",{className:"font-bold text-lg tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors",children:c.label||d}),jsxRuntime.jsx(lucideReact.ArrowUpRight,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-all"})]}),jsxRuntime.jsx("div",{className:"w-full h-1 bg-[var(--kyro-bg-secondary)] rounded-full mb-3 overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full bg-[var(--kyro-primary)]",style:{width:`${Math.random()*60+20}%`}})}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] line-clamp-1",children:c.admin?.description||`Manage ${d} content.`})]},d))})]}),jsxRuntime.jsxs("section",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-6 border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] transition-all cursor-pointer group",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between mb-4",children:jsxRuntime.jsxs("h3",{className:"text-xl font-bold tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-5 h-5"}),"Quick Links"]})}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[l.filter(([d])=>o?.collections?.[d]?.create!==false).map(([d])=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>t("new",d),className:"w-full flex items-center justify-between p-4 bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl hover:bg-[var(--kyro-surface-accent)] hover:border-[var(--kyro-primary)] transition-all group/btn",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:["New ",e[d]?.singularLabel||e[d]?.label||d]}),jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4 text-[var(--kyro-text-secondary)] group-hover/btn:text-[var(--kyro-primary)]"})]},d)),l.every(([d])=>o?.collections?.[d]?.create===false)&&jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] py-2",children:"No collections available for creation."})]})]}),jsxRuntime.jsxs("div",{className:"surface-tile p-8 bg-[#0f172a] text-white border-none shadow-2xl shadow-blue-500/10 overflow-hidden relative group cursor-pointer",children:[jsxRuntime.jsxs("div",{className:"relative z-10",children:[jsxRuntime.jsx("h3",{className:"text-2xl font-bold tracking-tighter mb-2",children:"Media Library"}),jsxRuntime.jsx("p",{className:"opacity-80 text-sm font-medium mb-6",children:"Manage high-fidelity assets with our liquid masonry gallery."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 font-bold text-xs tracking-widest text-blue-400",children:["Open Assets"," ",jsxRuntime.jsx(lucideReact.ArrowRight,{className:"w-4 h-4 group-hover:translate-x-1 transition-transform"})]})]}),jsxRuntime.jsx(lucideReact.Image,{className:"absolute bottom-[-20px] right-[-20px] w-48 h-48 opacity-10 rotate-12 group-hover:scale-110 transition-transform duration-1000"})]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-8",children:[jsxRuntime.jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-5 h-5 opacity-40"}),"Recent Activity"]}),jsxRuntime.jsx("div",{className:"space-y-6",children:a.recentActivity.map(d=>jsxRuntime.jsxs("div",{className:"flex gap-4 group",children:[jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--kyro-bg-secondary)] flex items-center justify-center border border-[var(--kyro-border)] group-hover:bg-[var(--kyro-primary)] transition-colors",children:jsxRuntime.jsx("span",{className:"text-[10px] font-bold",children:d.user[0]})})}),jsxRuntime.jsxs("div",{className:"flex-1 border-b border-[var(--kyro-border)] pb-4 group-last:border-none",children:[jsxRuntime.jsxs("p",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-snug",children:[jsxRuntime.jsx("span",{className:"font-bold",children:d.user})," ",d.type==="create"?"created":d.type==="edit"?"edited":d.type==="publish"?"published":"uploaded"," ",jsxRuntime.jsxs("span",{className:"text-[var(--kyro-primary)] italic",children:['"',d.doc,'"']})," ","in ",jsxRuntime.jsx("span",{className:"opacity-60",children:d.collection})]}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 mt-1 block",children:d.time})]})]},d.id))}),jsxRuntime.jsx("button",{type:"button",className:"w-full mt-6 py-3 text-xs font-bold tracking-widest text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-colors border-t border-[var(--kyro-border)] pt-6",children:"View Audit Logs"})]}),jsxRuntime.jsxs("section",{className:"surface-tile p-8",children:[jsxRuntime.jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Activity,{className:"w-5 h-5 opacity-40"}),"System Status"]}),jsxRuntime.jsx("div",{className:"space-y-4",children:[{label:"Cloud API",status:"Optimal",pulse:"bg-green-500"},{label:"Database Node",status:"Healthy",pulse:"bg-green-500"},{label:"Media CDN",status:"Active",pulse:"bg-blue-500"},{label:"Auth Service",status:"Secure",pulse:"bg-green-500"}].map((d,c)=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-4 bg-[var(--kyro-bg-secondary)] rounded-2xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-secondary)]",children:d.label}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:d.status}),jsxRuntime.jsx("div",{className:`w-2 h-2 rounded-full ${d.pulse} animate-pulse shadow-[0_0_8px] shadow-current`})]})]},c))})]})]})]})]})}function Kd(){let[e,t]=ka.useState([]),[r,o]=ka.useState(true),[a,n]=ka.useState(""),[s,i]=ka.useState(false),[l,d]=ka.useState({name:"",email:"",password:"",role:"customer"}),[c,m]=ka.useState(""),[y,g]=ka.useState(false),{confirm:x,alert:f}=at();ka.useEffect(()=>{u();},[]);let u=async()=>{try{o(!0);let w=await Be("/api/users");t(w.docs||[]);}catch(w){console.error("Failed to load users:",w);}finally{o(false);}},b=w=>{let N=!w.locked;x({title:N?"Lock User Account?":"Unlock User Account?",message:N?`Are you sure you want to lock ${w.email}? They will be immediately logged out and unable to return.`:`Restore system access for ${w.email}?`,variant:N?"danger":"success",onConfirm:async()=>{try{await Xt(`/api/users/${w.id}`,{locked:N}),t(p=>p.map(A=>A.id===w.id?{...A,locked:N}:A)),$.success(N?`Account locked: ${w.email}`:`Account restored: ${w.email}`);}catch(p){console.error("Failed to toggle user lock:",p),$.error("Failed to update account status");}}});},v=w=>{x({title:"Destroy User Account",message:`You are about to permanently delete ${w.email}. This will remove all their data and cannot be undone.`,variant:"danger",confirmLabel:"Destroy Account",onConfirm:async()=>{try{await bt(`/api/users/${w.id}`),t(N=>N.filter(p=>p.id!==w.id)),$.success(`Identity purged: ${w.email}`);}catch(N){console.error("Failed to delete user:",N),$.error("Failed to delete user");}}});},R=async()=>{if(!l.email.trim()||!l.password.trim()){m("Email and password are required");return}g(true),m("");try{await et("/api/users",{name:l.name.trim()||void 0,email:l.email.trim(),password:l.password,role:l.role}),i(!1),d({name:"",email:"",password:"",role:"customer"}),$.success("User created successfully"),u();}catch(w){let N=w instanceof Error?w.message:"Failed to create user";m(N),$.error(N);}finally{g(false);}},L=["super_admin","admin","editor","author","customer","guest"],C=e.filter(w=>w.email.toLowerCase().includes(a.toLowerCase())||w.name?.toLowerCase().includes(a.toLowerCase()));return jsxRuntime.jsxs("div",{className:"w-full space-y-6 animate-in fade-in slide-in-from-bottom-4 duration-700 px-4 md:px-8 pb-12",children:[jsxRuntime.jsx(Ft,{title:"Identity & Access",description:"Manage the core administrative team and security permissions.",icon:lucideReact.Users,action:{label:"New User",onClick:()=>{d({name:"",email:"",password:"",role:"customer"}),m(""),i(true);},icon:lucideReact.UserPlus}}),jsxRuntime.jsxs("div",{className:"flex flex-col md:flex-row gap-3",children:[jsxRuntime.jsxs("div",{className:"relative flex-1 group",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-secondary)] opacity-40 group-focus-within:opacity-100 transition-opacity"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search by identity or email...",value:a,onChange:w=>n(w.target.value),className:"w-full pl-10 pr-4 py-2.5 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] transition-all text-xs font-bold"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1 bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest bg-[var(--kyro-surface)] shadow-sm rounded-lg border border-[var(--kyro-border)]",children:"ALL"}),jsxRuntime.jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"ADMINS"}),jsxRuntime.jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"LOCKED"})]})]}),jsxRuntime.jsx("div",{className:"surface-tile overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-left",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"text-[var(--kyro-text-secondary)] font-bold text-[9px] tracking-[0.2em] uppercase border-b border-[var(--kyro-border)] whitespace-nowrap",children:[jsxRuntime.jsx("th",{className:"px-6 py-4 w-64",children:"Member Identity"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Administrative Role"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Security Status"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Last Activity"}),jsxRuntime.jsx("th",{className:"px-6 py-4 w-32 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:r?Array.from({length:6}).map((w,N)=>jsxRuntime.jsx("tr",{className:"animate-pulse",children:jsxRuntime.jsx("td",{colSpan:5,className:"px-6 py-5 bg-[var(--kyro-surface-accent)]/30"})},N)):C.length===0?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:5,className:"px-6 py-20 text-center",children:jsxRuntime.jsx("p",{className:"text-xs font-bold opacity-30 tracking-widest uppercase italic",children:"No identity matches found"})})}):C.map(w=>jsxRuntime.jsxs("tr",{className:`hover:bg-[var(--kyro-surface-accent)]/50 transition-colors group ${w.locked?"opacity-50 grayscale":""}`,children:[jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(yu,{user:w}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"text-xs font-bold text-[var(--kyro-text-primary)] truncate",children:w.name||w.email.split("@")[0]}),w.tenantId&&jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[7px] px-1 py-0 border-none bg-[var(--kyro-surface-accent)] opacity-50",children:w.tenantId})]}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:w.email})]})]})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Shield,{className:"w-3.5 h-3.5 opacity-30"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest uppercase opacity-70",children:w.role})]})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsx(Pt,{variant:w.locked?"danger":"success",dot:true,className:"text-[8px] font-bold uppercase tracking-widest",children:w.locked?"Restricted":"Authorized"})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold text-[var(--kyro-text-secondary)] opacity-50 uppercase tabular-nums",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3 h-3"}),w.lastLogin?new Date(w.lastLogin).toLocaleDateString():"Never"]})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5 text-right",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-all",children:[jsxRuntime.jsx("button",{onClick:()=>b(w),className:`p-1.5 rounded-lg border transition-all ${w.locked?"bg-green-500/10 text-green-500 border-green-500/20 hover:bg-green-500/20":"bg-amber-500/10 text-amber-500 border-amber-500/20 hover:bg-amber-500/20"}`,title:w.locked?"Restore Access":"Restrict Access",children:w.locked?jsxRuntime.jsx(lucideReact.LockOpen,{className:"w-3.5 h-3.5"}):jsxRuntime.jsx(lucideReact.Lock,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("button",{onClick:()=>v(w),className:"p-1.5 rounded-lg border border-red-500/20 bg-red-500/10 text-red-500 hover:bg-red-500/20 transition-all",title:"Delete User",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})})]})})]},w.id))})]})}),jsxRuntime.jsxs(Ot,{open:s,onClose:()=>i(false),title:"Create User",size:"lg",children:[jsxRuntime.jsx(Ur,{children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Name (optional)"}),jsxRuntime.jsx("input",{type:"text",value:l.name,onChange:w=>d({...l,name:w.target.value}),placeholder:"John Doe",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Email Address"}),jsxRuntime.jsx("input",{type:"email",value:l.email,onChange:w=>d({...l,email:w.target.value}),placeholder:"user@example.com",required:true,className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Password"}),jsxRuntime.jsx("input",{type:"password",value:l.password,onChange:w=>d({...l,password:w.target.value}),placeholder:"Minimum 12 characters",required:true,minLength:12,className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Role"}),jsxRuntime.jsx("select",{value:l.role,onChange:w=>d({...l,role:w.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]",children:L.map(w=>jsxRuntime.jsx("option",{value:w,children:w},w))})]}),c&&jsxRuntime.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-xl flex items-center gap-2 text-red-500 text-xs font-bold",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-4 h-4"}),c]})]})}),jsxRuntime.jsxs(zr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>i(false),className:"px-6 py-2.5 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:R,disabled:y,className:"kyro-btn kyro-btn-primary px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10 disabled:opacity-50",children:y?"Creating...":"Create User"})]})]})]})}function yu({user:e}){let[t,r]=ka.useState(null);return ka.useEffect(()=>{let o=e.avatar;typeof o=="string"&&/^[0-9a-f-]+$/i.test(o)&&Be(`/api/media/${o}`).then(a=>r(a?.thumbnailUrl||a?.url||null)).catch(()=>r(null));},[e.avatar]),t?jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-lg overflow-hidden border border-[var(--kyro-border)] flex-shrink-0",children:jsxRuntime.jsx("img",{src:t,alt:"",className:"w-full h-full object-cover"})}):jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-lg bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] flex items-center justify-center text-xs font-bold text-[var(--kyro-primary)] flex-shrink-0",children:e.name?e.name[0]:e.email[0].toUpperCase()})}function Gd(){let[e,t]=ka.useState("Kyro CMS"),[r,o]=ka.useState("Command Center"),[a,n]=ka.useState("#6366f1"),[s,i]=ka.useState("Welcome back to your Command Center."),[l,d]=ka.useState(false),[c,m]=ka.useState(false);return ka.useEffect(()=>{(async()=>{try{let f=await Be("/api/globals/site-settings"),u=f.data||f;u&&Object.keys(u).length>0&&(u.siteName&&t(u.siteName),u.adminTitle&&o(u.adminTitle),u.primaryColor&&n(u.primaryColor),u.dashboardGreeting&&i(u.dashboardGreeting));}catch(f){console.error("Failed to load branding:",f);}})();},[]),jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxRuntime.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 pt-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:["Branding ",jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:"Hub"})]}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] mt-1 font-medium opacity-60",children:"Customize the identity and aesthetic of your administrative ecosystem."})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-3",children:jsxRuntime.jsxs("button",{type:"button",onClick:async()=>{d(true);try{await Xt("/api/globals/site-settings",{siteName:e,adminTitle:r,primaryColor:a,dashboardGreeting:s}),m(!0),$.success("Branding updated"),document.documentElement.style.setProperty("--kyro-primary",a),setTimeout(()=>window.location.reload(),800);}catch(x){$.error("Failed to save branding"),console.error(x);}finally{d(false);}},disabled:l,className:`flex items-center gap-2 px-8 py-3 rounded-2xl font-bold text-sm shadow-xl transition-all active:scale-95 ${c?"bg-green-500 text-white":"kyro-btn-primary hover:shadow-[var(--kyro-primary)]"}`,children:[l?jsxRuntime.jsx(lucideReact.RefreshCcw,{className:"w-4 h-4 animate-spin"}):c?jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"}):jsxRuntime.jsx(lucideReact.Save,{className:"w-4 h-4"}),l?"Saving...":c?"Identity Updated":"Publish Branding"]})})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsxRuntime.jsx(lucideReact.Tag,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsxRuntime.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Core Identity"})]}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Site Public Name"}),jsxRuntime.jsx("input",{type:"text",value:e,onChange:x=>t(x.target.value),className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all",placeholder:"e.g. Acme Corp CMS"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Admin Dashboard Title"}),jsxRuntime.jsx("input",{type:"text",value:r,onChange:x=>o(x.target.value),className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all",placeholder:"e.g. Command Center"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"System Greeting"}),jsxRuntime.jsx("textarea",{value:s,onChange:x=>i(x.target.value),rows:3,className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all resize-none",placeholder:"Greeting text for the dashboard..."})]})]})]}),jsxRuntime.jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsxRuntime.jsx(lucideReact.Palette,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsxRuntime.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Visual Aesthetic"})]}),jsxRuntime.jsxs("div",{className:"space-y-8",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Primary Brand Color"}),jsxRuntime.jsx("div",{className:"grid grid-cols-6 gap-3",children:[{name:"Indigo",hex:"#6366f1"},{name:"Emerald",hex:"#10b981"},{name:"Rose",hex:"#f43f5e"},{name:"Amber",hex:"#f59e0b"},{name:"Sky",hex:"#0ea5e9"},{name:"Violet",hex:"#8b5cf6"}].map(x=>jsxRuntime.jsx("button",{type:"button",onClick:()=>n(x.hex),className:`aspect-square rounded-xl transition-all border-4 ${a===x.hex?"border-white ring-2 ring-[var(--kyro-primary)]":"border-transparent opacity-60 hover:opacity-100"}`,style:{backgroundColor:x.hex},title:x.name},x.name))})]}),jsxRuntime.jsxs("div",{className:"space-y-4 pt-4 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Project Logo (SVG/PNG)"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6",children:[jsxRuntime.jsxs("div",{className:"w-20 h-20 rounded-2xl bg-[var(--kyro-bg-secondary)] border-2 border-dashed border-[var(--kyro-border)] flex flex-col items-center justify-center text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-primary)] hover:text-[var(--kyro-primary)] cursor-pointer transition-all",children:[jsxRuntime.jsx(lucideReact.Image,{className:"w-6 h-6 mb-1 opacity-40"}),jsxRuntime.jsx("span",{className:"text-[8px] font-bold ",children:"Upload"})]}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("p",{className:"text-xs font-bold mb-1",children:"Upload global CMS logo"}),jsxRuntime.jsx("p",{className:"text-[10px] opacity-40 leading-relaxed",children:"This will replace the Kyro brand in the sidebar and login screens."})]})]})]})]})]}),jsxRuntime.jsxs("section",{className:"lg:col-span-2 surface-tile p-8 overflow-hidden relative group",children:[jsxRuntime.jsxs("div",{className:"absolute top-0 right-0 p-8 flex items-center gap-2 text-[var(--kyro-primary)]",children:[jsxRuntime.jsx(lucideReact.Sparkles,{className:"w-4 h-4"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest",children:"Live Preview"})]}),jsxRuntime.jsxs("div",{className:"max-w-2xl mx-auto py-12 text-center space-y-6",children:[jsxRuntime.jsxs("div",{className:"inline-flex items-center gap-3 px-4 py-2 bg-[var(--kyro-bg-secondary)] rounded-full border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),jsxRuntime.jsxs("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:[r," Online"]})]}),jsxRuntime.jsxs("h2",{className:"text-5xl font-bold tracking-tighter leading-none italic",children:["Welcome to ",e,"."]}),jsxRuntime.jsx("p",{className:"text-xl font-medium text-[var(--kyro-text-secondary)] opacity-60",children:s})]}),jsxRuntime.jsx("style",{dangerouslySetInnerHTML:{__html:`
99
+ \`\`\``})}),!n&&jsxRuntime.jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsx("span",{children:"**bold**"}),jsxRuntime.jsx("span",{children:"*italic*"}),jsxRuntime.jsx("span",{children:"`code`"}),jsxRuntime.jsx("span",{children:"[link](url)"}),jsxRuntime.jsx("span",{children:"# heading"})]}),e.admin?.description&&!o&&jsxRuntime.jsx("p",{className:"kyro-form-help",children:e.admin.description}),o&&jsxRuntime.jsx("p",{className:"kyro-form-error",children:o})]}):jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsx("div",{className:"h-[200px] bg-[var(--kyro-surface)] animate-pulse rounded-md border border-[var(--kyro-border)]"})]})};function Cn({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false),[i,l]=ka.useState(false),d=t??"",c=d.length>8?d.slice(0,-8)+"*".repeat(8):d,m=async()=>{if(d)try{await navigator.clipboard.writeText(d),s(!0),setTimeout(()=>s(!1),1800);}catch{let g=document.createElement("textarea");g.value=d,g.style.position="fixed",g.style.opacity="0",document.body.appendChild(g),g.select(),document.execCommand("copy"),document.body.removeChild(g),s(true),setTimeout(()=>s(false),1800);}},u=()=>{if(i||a)return;l(true);let g=new Uint8Array(32);crypto.getRandomValues(g);let x=Array.from(g).map(f=>f.toString(16).padStart(2,"0")).join("");r?.(x),setTimeout(()=>l(false),400);};return jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",children:[jsxRuntime.jsx("div",{className:"relative flex-1",children:jsxRuntime.jsx("input",{id:e.name,type:"text",value:c,readOnly:true,disabled:a,className:"kyro-form-input font-mono text-xs tracking-wider pr-10 opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed select-none",spellCheck:false})}),jsxRuntime.jsx("button",{type:"button",onClick:m,disabled:!d||a,className:"p-2 rounded-lg border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] hover:bg-[var(--kyro-primary-alpha)] transition-all disabled:opacity-40 disabled:cursor-not-allowed active:scale-95",title:n?"Copied!":"Copy full secret",children:n?jsxRuntime.jsx(lucideReact.Check,{className:"w-3.5 h-3.5 text-[var(--kyro-success)]"}):jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("button",{type:"button",onClick:u,disabled:a,className:"p-2 rounded-lg border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-warning)] hover:bg-[var(--kyro-warning)]/10 transition-all disabled:opacity-40 disabled:cursor-not-allowed active:scale-95",title:"Regenerate secret",children:jsxRuntime.jsx(lucideReact.RefreshCw,{className:`w-3.5 h-3.5 ${i?"animate-spin":""}`})})]})})}var Sn=null,Tl=false,Ss=async()=>(Sn&&Tl||(Sn=unstorage.createStorage({driver:im__default.default({dbName:"kyro-autosave",storeName:"autosave"})}),Tl=true),Sn),lm=()=>typeof window>"u"?{getItem:async()=>null,setItem:async()=>{},removeItem:async()=>{}}:{getItem:async e=>{try{return await(await Ss()).getItem(e)??null}catch(t){return console.error("Storage getItem error:",t),localStorage.getItem(e)}},setItem:async(e,t)=>{try{await(await Ss()).setItem(e,t);}catch(r){console.error("Storage setItem error:",r),localStorage.setItem(e,t);}},removeItem:async e=>{try{await(await Ss()).removeItem(e);}catch(t){console.error("Storage removeItem error:",t),localStorage.removeItem(e);}}},Le=zustand.create()(middleware.persist((e,t)=>({formData:{},lastSavedData:{},sidebarCollapsed:false,draftCache:{},dirtyFields:new Set,activeTab:0,isSlugLocked:true,view:"edit",isDropdownOpen:false,versions:[],loadingVersions:false,showPreview:false,isMenuOpen:false,hasUnsavedChanges:false,loadingFields:{},compareMode:false,compareSelected:[],compareDiffs:[],loadingDiffs:false,isAutoSaving:false,autoSaveStatus:"idle",backgroundProcessing:false,lastAutoSaveTime:0,lastSavedAt:null,retryCount:0,autoSaveSkip:false,autoSaveTimer:null,setField:(r,o)=>{let a=t(),n=new Set(a.dirtyFields);JSON.stringify(o)!==JSON.stringify(a.lastSavedData[r])?n.add(r):n.delete(r),e({formData:{...a.formData,[r]:o},dirtyFields:n,hasUnsavedChanges:n.size>0});},setFormData:r=>{e({formData:r});},setNestedField:(r,o)=>{e(a=>{let n=r.split("."),s={...a.formData},i=s;for(let l=0;l<n.length-1;l++)i[n[l]]===void 0&&(i[n[l]]={}),i[n[l]]={...i[n[l]]},i=i[n[l]];return i[n[n.length-1]]=o,{formData:s}});},setActiveTab:r=>e({activeTab:r}),setIsSlugLocked:r=>e(o=>({isSlugLocked:typeof r=="function"?r(o.isSlugLocked):r})),setView:r=>e({view:r}),setIsDropdownOpen:r=>e(o=>({isDropdownOpen:typeof r=="function"?r(o.isDropdownOpen):r})),setVersions:r=>e({versions:r}),setLoadingVersions:r=>e({loadingVersions:r}),setShowPreview:r=>e(o=>({showPreview:typeof r=="function"?r(o.showPreview):r})),setIsMenuOpen:r=>e(o=>({isMenuOpen:typeof r=="function"?r(o.isMenuOpen):r})),setHasUnsavedChanges:r=>e({hasUnsavedChanges:r}),setLoadingFields:r=>e(o=>({loadingFields:typeof r=="function"?r(o.loadingFields):r})),updateLoadingField:(r,o)=>e(a=>({loadingFields:{...a.loadingFields,[r]:o}})),setCompareMode:r=>e({compareMode:r}),setCompareSelected:r=>e(o=>({compareSelected:typeof r=="function"?r(o.compareSelected):r})),setCompareDiffs:r=>e({compareDiffs:r}),setLoadingDiffs:r=>e({loadingDiffs:r}),setIsAutoSaving:r=>e({isAutoSaving:r}),setAutoSaveStatus:r=>e({autoSaveStatus:r}),setBackgroundProcessing:r=>e({backgroundProcessing:r}),setSidebarCollapsed:r=>e({sidebarCollapsed:r}),setLastSavedAt:r=>e({lastSavedAt:r}),setRetryCount:r=>e({retryCount:r}),setAutoSaveSkip:r=>e({autoSaveSkip:r}),setLastAutoSaveTime:r=>e({lastAutoSaveTime:r}),startAutoSaveTimer:(r,o)=>{let{autoSaveTimer:a}=t();a&&clearTimeout(a);let n=setTimeout(r,o);e({autoSaveTimer:n});},clearAutoSaveTimer:()=>{let{autoSaveTimer:r}=t();r&&(clearTimeout(r),e({autoSaveTimer:null}));},markSaved:()=>{let{formData:r}=t();e({lastSavedData:r,hasUnsavedChanges:false,dirtyFields:new Set,lastSavedAt:Date.now()});},setLastSavedData:r=>{e({lastSavedData:r});},resetForm:()=>{e({formData:{},lastSavedData:{},hasUnsavedChanges:false,dirtyFields:new Set,activeTab:0});},loadDocument:(r,o)=>{let a=t();a.formData===r&&a.lastSavedData===(o||r)&&!a.hasUnsavedChanges||e({formData:r,lastSavedData:o||r,hasUnsavedChanges:false,dirtyFields:new Set});},getField:r=>t().formData[r],getNestedField:r=>{let o=r.split("."),a=t().formData;for(let n of o){if(a==null)return;a=a[n];}return a},getHasChanges:()=>t().dirtyFields.size>0,hasDirtyFields:()=>t().dirtyFields.size>0,getDirtyData:()=>{let{formData:r,dirtyFields:o}=t(),a={};for(let n of o)a[n]=r[n];return a},clearDirtyFields:()=>{e({dirtyFields:new Set,hasUnsavedChanges:false});},pruneExpiredDrafts:()=>{let o=Date.now(),{draftCache:a}=t(),n={};for(let[s,i]of Object.entries(a))o-new Date(i.draftUpdatedAt).getTime()<6048e5&&(n[s]=i);e({draftCache:n});},setDraftCache:(r,o)=>e(a=>({draftCache:{...a.draftCache,[r]:o}})),getDraftCache:r=>t().draftCache[r]||null,clearDraftCache:r=>e(o=>{let a={...o.draftCache};return delete a[r],{draftCache:a}})}),{name:"kyro-autoform-storage",storage:middleware.createJSONStorage(()=>lm()),partialize:e=>({sidebarCollapsed:e.sidebarCollapsed,draftCache:e.draftCache}),onRehydrateStorage:()=>e=>{e&&e.pruneExpiredDrafts();}}));function Tn(e){return e?e.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function jo({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.variant==="textarea",i=e.name==="slug",{isSlugLocked:l,setIsSlugLocked:d,formData:c}=Le(),m=e.variant==="email"?"email":e.variant==="password"?"password":e.variant==="url"?"url":"text",u=t==null?"":String(t),g={id:e.name,value:u,onChange:x=>r?.(x.target.value),placeholder:e.admin?.placeholder,disabled:a||n||i&&l,minLength:e.minLength,maxLength:e.maxLength,required:e.required,className:`kyro-form-input ${i?"pr-24":""} ${a||n||i&&l?"opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed":""}`};return jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"relative",children:[s?jsxRuntime.jsx("textarea",{...g,rows:e.rows||4}):jsxRuntime.jsx("input",{type:m,...g,pattern:e.pattern}),i&&jsxRuntime.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:[!l&&jsxRuntime.jsx("button",{type:"button",onClick:()=>r?.(Tn(c[e.admin?.autoGenerate||"title"]||"")),className:"p-1 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)]",title:"Regenerate slug",children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),jsxRuntime.jsx("path",{d:"M21 3v5h-5"})]})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>d(!l),className:`p-1.5 rounded transition-colors ${l?"text-[var(--kyro-primary)] bg-[var(--kyro-primary-alpha)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,title:l?"Unlock slug":"Lock slug",children:l?jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsxRuntime.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}):jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsxRuntime.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})})]}),e.name?.toLowerCase().includes("metatitle")&&jsxRuntime.jsx("div",{className:"flex items-center justify-between mt-1 text-[10px] font-bold tracking-wider",children:jsxRuntime.jsxs("span",{className:u.length>60?"text-red-500":u.length>=40?"text-green-500":"text-amber-600",children:[u.length," / 60 \u2014 ",u.length>60?"Too Long":u.length>=40?"Ideal":"Short"]})})]})})}function An({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsx("input",{type:"number",id:e.name,value:t??"",onChange:s=>r?.(parseFloat(s.target.value)||0),placeholder:e.admin?.placeholder,disabled:a||n,min:e.min,max:e.max,step:e.step||(e.integer?1:"any"),required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`})})}function Rn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(nt,{field:e,error:o,hideLabel:true,children:jsxRuntime.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer group py-0.5",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:t??false,onChange:i=>r?.(i.target.checked),disabled:a||n,className:`w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)] transition-all ${a||n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`}),jsxRuntime.jsxs("span",{className:"text-sm font-semibold text-[var(--kyro-text-primary)] tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors",children:[e.label||e.name,e.required&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})]})})}function Fn({field:e,value:t="",onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsx("input",{type:e.time?"datetime-local":"date",id:e.name,value:t??"",onChange:s=>r?.(s.target.value),disabled:a||n,min:e.minDate,max:e.maxDate,required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`})})}function Fa(e){return e?Array.isArray(e)?e:Object.values(e):[]}function Dn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Bn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Ra(e,t){let r=new Set(e.map(o=>o.slug));for(let o of t)r.has(o.slug)||(e.push(o),r.add(o.slug));}var cm={pages:"FileText",posts:"Newspaper",categories:"Tags",menu:"Menu",products:"ShoppingBag",customers:"Users",orders:"ShoppingCart",coupons:"Ticket",forms:"FileInput","form-entries":"Inbox"};function fo(e,t,r){let o=t.split(".");if(o.length===0)return false;let a=o[0],n=o.slice(1).join(".");for(let s of e){if(s.name===a)if(n){if(s.fields&&Array.isArray(s.fields))return fo(s.fields,n,r);if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&fo(l.fields,n,r))return true;return false}if(s.type==="blocks"&&s.blocks&&Array.isArray(s.blocks)){let l=n.split(".")[0],d=n.split(".").slice(1).join(".");if(!d)return false;for(let c of s.blocks)if(c.slug===l&&c.fields&&Array.isArray(c.fields))return fo(c.fields,d,r);return false}return s.type==="array"&&s.fields&&Array.isArray(s.fields)?fo(s.fields,n,r):false}else return Object.assign(s,r),true;if(!s.name||s.type==="tabs"||s.type==="row"||s.type==="collapsible"){if(s.fields&&Array.isArray(s.fields)&&fo(s.fields,t,r))return true;if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&fo(l.fields,t,r))return true}}}return false}function pm(e,t){for(let[r,o]of Object.entries(e)){let a=cm[r],n=t?.[r];if(a&&!o.admin?.icon&&(o.admin={...o.admin,icon:a}),n){let{fields:s,...i}=n;if(o.admin={...o.admin,...i},s&&o.fields&&Array.isArray(o.fields))for(let[l,d]of Object.entries(s))fo(o.fields,l,d);}}}function mm(e="blog"){let t=[],r=[];switch(e){case "minimal":t.push(...Object.values(templates.minimalCollections)),r.push(...templates.coreSettingsGlobals);break;case "starter":t.push(...Object.values(templates.starterCollections)),r.push(...templates.coreSettingsGlobals);break;case "blog":t.push(...Object.values(templates.blogCollections)),r.push(...templates.coreSettingsGlobals);break;case "ecommerce":t.push(...Object.values(templates.ecommerceCollections)),r.push(...templates.allSettingsGlobals);break;case "kitchen-sink":t.push(...Object.values(templates.minimalCollections),...Object.values(templates.starterCollections),...Object.values(templates.blogCollections),...Object.values(templates.ecommerceCollections),...Object.values(templates.kitchenSinkCollections)),r.push(...templates.allSettingsGlobals);break}return Ra(t,Object.values(templates.mediaCollections)),Ra(t,Object.values(templates.authCollections)),{collections:Dn(t),globals:Bn(r)}}function um(e){let t=Fa(e.collections),r=Fa(e.globals);if(t.length===0&&r.length===0)return mm("kitchen-sink");let o=[];return Ra(o,Object.values(templates.mediaCollections)),Ra(o,Object.values(templates.authCollections)),Ra(o,t),{collections:Dn(o),globals:Bn(r)}}var Pn=null;function ym(){if(Pn)return Pn;try{if(typeof __KYRO_ADMIN_CONFIG_FILE__=="string"&&Ro__default.default.existsSync(__KYRO_ADMIN_CONFIG_FILE__))return Pn=JSON.parse(Ro__default.default.readFileSync(__KYRO_ADMIN_CONFIG_FILE__,"utf8")),Pn}catch{}return null}var Ol=ym()||{collections:[],globals:[]},Ul=um(Ol);pm(Ul.collections,Ol.collectionOverrides);var zl=Ul,Ho=zl.collections,jl=zl.globals,Rs=["users","audit_logs"];Object.values(Ho).filter(e=>!Rs.includes(e.slug)&&e.admin?.hidden!==true);function In({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.options||[];return e.dynamicOptions==="collections"&&(s=Object.keys(Ho).filter(i=>i!=="media").map(i=>({label:Ho[i]?.label||i,value:i}))),jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsxs("select",{id:e.name,value:e.hasMany?Array.isArray(t)?t:[]:t||"",onChange:i=>{if(e.hasMany){let l=Array.from(i.target.selectedOptions,d=>d.value);r?.(l);}else r?.(i.target.value||void 0);},multiple:e.hasMany,disabled:a||n,required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`,children:[!e.required&&!e.hasMany&&jsxRuntime.jsx("option",{value:"",children:"Select..."}),s.map(i=>jsxRuntime.jsx("option",{value:i.value,children:i.label},i.value))]})})}function Ln({icon:e,title:t,description:r,action:o}){return jsxRuntime.jsxs("div",{className:"flex flex-col items-center gap-3 justify-center py-16 px-8",children:[e&&jsxRuntime.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:e}),jsxRuntime.jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:t}),r&&jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:r}),o]})}function Hl(e){let t=e?.mainTabs;return e?.title||t?.title||e?.name||e?.label||e?.email||e?.filename||e?.slug||"Untitled"}function gm({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=ka.useState(false),[i,l]=ka.useState(""),[d,c]=ka.useState([]),[m,u]=ka.useState(false),[g,x]=ka.useState([]),f=ka.useRef(new Set),y=ka.useRef(null),b=ka.useRef(()=>{});b.current=r||(()=>{});let v=e.hasMany,R=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],L=R.length>1,[C,w]=ka.useState(R[0]||""),N=ka.useCallback(()=>t?(v?Array.isArray(t)?t:[]:t?[t]:[]).map(j=>typeof j=="object"&&j!==null?j.value||j.id||"":String(j)).filter(Boolean):[],[t,v]),p=ka.useCallback(M=>{M.length!==0&&M.forEach(j=>{if(f.current.has(j))return;f.current.add(j);let se=L?(()=>{if(!t)return C;let ue=(v?Array.isArray(t)?t:[]:[t]).find(oe=>typeof oe=="object"&&oe!==null?oe.value===j||oe.id===j:false);return ue&&typeof ue=="object"&&ue.relationTo||C})():C;De(`/api/${se}/${j}`).then(ie=>{let ue=ie.data||ie;!ue||typeof ue!="object"||x(oe=>oe.some(ne=>ne.id===j)?oe:[...oe,{...ue,id:String(ue.id),relationTo:se}]);}).catch(()=>{});});},[L,t,C,v]);ka.useEffect(()=>{let M=N();p(M);},[N,p]);let A=ka.useCallback((M="")=>{u(true);let se=`/api/${C}?${Ja(M,["title","name","label","email"])}`;De(se).then(ie=>{c(ue=>{let oe=new Set(ue.map(je=>je.id)),ne=(ie.docs||[]).filter(je=>!oe.has(je.id)).map(je=>({...je,id:je.id}));return [...ue,...ne]}),u(false);}).catch(()=>{u(false);});},[C]);ka.useEffect(()=>{n&&(c([]),A(i));},[n,C]),ka.useEffect(()=>{let M=j=>{y.current&&!y.current.contains(j.target)&&s(false);};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]);let O=M=>typeof M=="object"&&M!==null?M.value||M.id||"":String(M),F=M=>{let j=M.id;return t?v&&Array.isArray(t)?t.some(se=>O(se)===j):O(t)===j:false},P=M=>{let j=M.id;if(v){let se=Array.isArray(t)?t:[];if(F(M))b.current?.(se.filter(ie=>O(ie)!==j));else {let ie=L?{relationTo:C,value:j}:j;b.current?.([...se,ie]);}}else if(F(M))b.current?.(null);else {let se=L?{relationTo:C,value:j}:j;b.current?.(se),s(false),l("");}},S=()=>{if(!t)return null;let M=v?Array.isArray(t)?t:[]:t?[t]:[];return jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:M.map(j=>{let se=O(j),ie=g.find(ne=>ne.id===se),ue=ie?Hl(ie):se.slice(0,12),oe=L&&ie?ie.relationTo:null;return jsxRuntime.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]",children:[oe&&jsxRuntime.jsxs("span",{className:"opacity-60 mr-0.5",children:[oe,":"]}),ue,!a&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{let ne=M.filter(je=>O(je)!==se);b.current?.(v?ne:ne[0]??null);},className:"hover:opacity-70",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},se)})})};return jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[e.label&&jsxRuntime.jsxs("label",{className:"block text-sm font-medium text-[var(--kyro-text-primary)]",children:[e.label,e.required&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]}),jsxRuntime.jsxs("div",{ref:y,className:"relative",children:[L&&jsxRuntime.jsx("div",{className:"flex gap-1 mb-1.5",children:R.map(M=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{w(M),c([]),l("");},className:`px-2 py-0.5 text-[10px] font-bold rounded transition-colors ${C===M?"kyro-btn-primary":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:M},M))}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",value:i,onChange:M=>{l(M.target.value),s(true),A(M.target.value);},onFocus:()=>s(true),placeholder:e.admin?.placeholder||`Search ${C}...`,disabled:a||(typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly),className:"w-full pl-9 pr-10 py-2 border border-[var(--kyro-border)] rounded-md bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent disabled:opacity-50"}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:m?jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-4 h-4 text-[var(--kyro-text-muted)] transition-transform ${n?"rotate-180":""}`})})]}),n&&jsxRuntime.jsx("div",{className:"relative z-20 w-full mt-1 border border-[var(--kyro-border)] rounded-lg shadow-lg bg-[var(--kyro-surface)] max-h-64 overflow-auto",children:m?jsxRuntime.jsx("div",{className:"p-4 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsxRuntime.jsx(Ln,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:d.map(M=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>P(M),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors ${F(M)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{children:Hl(M)}),F(M)&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-sidebar-active)]",children:"\u2713"})]}),"slug"in M&&typeof M.slug=="string"&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)]",children:M.slug})]},M.id))})}),S()]}),e.admin?.description&&!o&&jsxRuntime.jsx("p",{className:"text-xs text-[var(--kyro-text-muted)]",children:e.admin.description}),o&&jsxRuntime.jsx("p",{className:"text-xs text-[var(--kyro-error)]",children:o})]})}var Pa=gm;var vo=ka.createContext(null);function Vl(e=[],t=[]){return vanilla.createStore((r,o)=>({blocks:[],allowedBlocks:e,dynamicCategories:t,setBlocks:a=>{let n=Ls(a||[]);r({blocks:n});},onBlocksChange:null,setOnBlocksChange:a=>r({onBlocksChange:a}),addBlock:(a,n)=>{let s=Vo(a),{blocks:i}=o(),l=[...i];n!==void 0?l.splice(n,0,s):l.push(s),r({blocks:l});let{onBlocksChange:d}=o();d&&d();},updateBlock:(a,n)=>{let{blocks:s}=o(),i=Da(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=[...l];return c[d]={...c[d],...n},{newList:c,found:true}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}},removeBlock:a=>{if(!a)return;let{blocks:n}=o(),s=Da(n,i=>{let l=i.filter(d=>d.id!==a);return l.length!==i.length?{newList:l,found:true}:{newList:i,found:false}});if(s!==n){r({blocks:s});let{onBlocksChange:i}=o();i&&i();}},moveBlock:(a,n)=>{let{blocks:s}=o(),i=Da(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=n==="up"?d-1:d+1;if(c>=0&&c<l.length){let m=[...l];return [m[d],m[c]]=[m[c],m[d]],{newList:m,found:true}}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}}}))}function Ls(e){return Array.isArray(e)?e.map(t=>{let r={...t,id:t.id||Math.random().toString(36).substr(2,9)};return r.children&&Array.isArray(r.children)&&(r.children=Ls(r.children)),r.data?.columnData&&Array.isArray(r.data.columnData)&&(r.data={...r.data,columnData:r.data.columnData.map(o=>({...o,children:o.children?Ls(o.children):o.children}))}),r}):[]}function Vo(e){let t=hm(e),{options:r,children:o,...a}=t;return {id:Math.random().toString(36).substr(2,9),type:e,name:"",data:a,options:r,children:o,order:Date.now()}}function hm(e){return {heading:{level:1,text:""},"heading-subheading":{heading:"",subheading:""},hero:{isMultiScreen:false},card:{title:"",description:"",icon:"",link:"",linkText:"",isMultiCard:false},paragraph:{text:""},divider:{},callout:{text:"",variant:"info"},image:{src:"",alt:"",caption:""},video:{src:"",title:""},list:{type:"unordered",items:""},code:{language:"plaintext",code:""},link:{url:"",text:""},table:{rows:3,columns:3,content:""},quote:{text:"",author:""},file:{filename:"",url:""},columns:{columns:2,direction:"horizontal"},vstack:{direction:"vertical",gap:"md"},container:{options:{backgroundColor:"transparent",padding:"md",width:"full",margin:"none",minHeight:"none",borderRadius:"none"},children:[]},button:{text:"Button",url:"",variant:"primary",size:"md"},accordion:{title:"Accordion Item",content:""},gallery:{images:[]},tabs:{tabs:[{label:"Tab 1",content:""}]}}[e]||{}}function Ee(e){let t=ka.useContext(vo);if(t)return zustand.useStore(t,r=>{let o=a=>{for(let n of a){if(n.id===e)return n;if(n.children&&n.children.length>0){let s=o(n.children);if(s)return s}if(n.data?.columnData){for(let s of n.data.columnData)if(s&&s.children&&s.children.length>0){let i=o(s.children);if(i)return i}}}};return o(r.blocks)})}function Be(){let e=ka.useContext(vo);if(!e)throw new Error("useBlockActions must be used within a BlocksContext.Provider");return {updateBlock:(t,r)=>e.getState().updateBlock(t,r),removeBlock:t=>e.getState().removeBlock(t),moveBlock:(t,r)=>e.getState().moveBlock(t,r)}}function Da(e,t){let{newList:r,found:o}=t(e);if(o)return r;let a=false,n=e.map(s=>{let i={...s},l=false;if(s.children&&s.children.length>0){let d=Da(s.children,t);d!==s.children&&(i.children=d,l=true);}if(s.data?.columnData&&Array.isArray(s.data.columnData)){let d=s.data.columnData.map(c=>{if(c.children&&c.children.length>0){let m=Da(c.children,t);if(m!==c.children)return {...c,children:m}}return c});d.some((c,m)=>c!==s.data.columnData[m])&&(i.data={...i.data,columnData:d},l=true);}return l&&(a=true),l?i:s});return a?n:e}function Ia({open:e,onClose:t,onSelect:r,children:o}){return e?jsxRuntime.jsxs(dr,{open:e,onClose:t,title:"Insert Block",width:"md",children:[jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-muted)] mb-4",children:"Drag blocks into the editor or click to insert"}),o]}):null}function Kl({block:e,onSelect:t,children:r}){let{attributes:o,listeners:a,setNodeRef:n,isDragging:s}=core.useDraggable({id:`drawer-${e.type}`,data:{source:"drawer",blockType:e.type}});return jsxRuntime.jsxs("div",{ref:n,...a,...o,onClick:()=>t(e.type),className:`flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group ${s?"opacity-50 border-[var(--kyro-primary)]":""}`,style:{opacity:s?.5:1},children:[jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all duration-300",children:r||jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]"})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)] leading-tight",children:e.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 leading-tight",children:e.description})]})]})}var $s=({text:e="",onChange:t,compact:r=false})=>jsxRuntime.jsx("div",{className:r?"":"space-y-3",children:jsxRuntime.jsx("input",{type:"text",value:e,onChange:a=>t("text",a.target.value),className:r?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Enter heading text..."})});var go=({id:e,type:t,label:r,children:o,className:a=""})=>{let{moveBlock:n,removeBlock:s}=Be();return jsxRuntime.jsxs("div",{className:`block-${t} border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group bg-[var(--kyro-surface)] transition-all hover:border-[var(--kyro-primary)]/30 ${a}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] tracking-wider",children:r||t}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-muted)] hover:text-[var(--kyro-primary)]",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-muted)] hover:text-[var(--kyro-primary)]",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>s(e),className:"p-1 hover:bg-[var(--kyro-error)]/10 rounded text-[var(--kyro-error)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx("div",{className:"block-content",children:o})]})};var ql=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o}=Be(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsxRuntime.jsx(go,{id:e.id,type:"heading",label:"Heading",children:jsxRuntime.jsx($s,{text:a.text||"",onChange:n,compact:true})})};var Xl=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o}=Be(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsxRuntime.jsx(go,{id:e.id,type:"paragraph",label:"Paragraph",children:jsxRuntime.jsx("textarea",{value:a.text||"",onChange:s=>n("text",s.target.value),className:"w-full px-3 py-3 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm min-h-[100px] resize-none",placeholder:"Enter paragraph text..."})})};var Ql=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data||e.data||{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-image border border-[var(--kyro-border)] rounded-lg p-4 mb-4 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Image"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Image Asset"}),jsxRuntime.jsx(lr,{field:{label:"Image Asset",name:"src",maxCount:1},value:s.src,onChange:l=>i("src",l)})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Alt Text"}),jsxRuntime.jsx("input",{type:"text",value:s.alt||"",onChange:l=>i("alt",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Alternative text..."})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Caption"}),jsxRuntime.jsx("input",{type:"text",value:s.caption||"",onChange:l=>i("caption",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Image caption..."})]})]})]})};var Os=({src:e="",title:t="",onChange:r,onUploadChange:o,compact:a=false})=>{e.includes("youtube.com")||e.includes("vimeo.com")||e.includes("youtu.be");return a?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("input",{type:"url",value:e,onChange:s=>r("src",s.target.value),className:"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"MP4 URL, YouTube, or Vimeo link..."}),jsxRuntime.jsx("input",{type:"text",value:t,onChange:s=>r("title",s.target.value),className:"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Video title (optional)..."})]}):jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx(lr,{field:{label:"Video Asset",name:"src",maxCount:1},value:e,onChange:o||(s=>r("src",s))}),jsxRuntime.jsx("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:"or paste a URL"}),jsxRuntime.jsx("input",{type:"url",value:e,onChange:s=>r("src",s.target.value),className:"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"MP4 URL, YouTube, or Vimeo link..."}),jsxRuntime.jsx("input",{type:"text",value:t,onChange:s=>r("title",s.target.value),className:"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Video title (optional)..."})]})};var Zl=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-video border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Video"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(Os,{src:s.src||"",title:s.title||"",onChange:i,onUploadChange:l=>i("src",l),compact:true})]})};var La=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=ka__default.default.useState(""),n=()=>{o.trim()&&(t([...e,o.trim()]),a(""));},s=d=>{d.key==="Enter"&&(d.preventDefault(),n());},i=d=>{t(e.filter((c,m)=>m!==d));},l=r?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded-md bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxRuntime.jsxs("div",{className:r?"space-y-1.5":"space-y-2",children:[e.length===0?jsxRuntime.jsx("div",{className:"text-center py-4 text-[var(--kyro-text-muted)] text-sm border border-dashed border-[var(--kyro-border)] rounded-md",children:"No items. Type below to add."}):jsxRuntime.jsx("div",{className:"space-y-1",children:e.map((d,c)=>jsxRuntime.jsxs("div",{className:"flex items-center gap-2 group/item",children:[jsxRuntime.jsxs("span",{className:"text-sm text-[var(--kyro-text-primary)] flex-1",children:["\u2022 ",d]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>i(c),className:"opacity-0 group-hover/item:opacity-100 p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",children:"\xD7"})]},c))}),jsxRuntime.jsx("input",{type:"text",value:o,onChange:d=>a(d.target.value),onKeyDown:s,className:l,placeholder:"Type and press Enter to add..."})]})};var ed=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data||e.data||{},i=Array.isArray(s.items)?s.items:[];return jsxRuntime.jsxs("div",{className:"block-list border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"List"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(La,{items:i,onChange:d=>{o(e.id,{data:{...s,items:d}});},compact:true})]})};var td=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"group/block relative border border-[var(--kyro-border)] rounded-2xl p-6 mb-6 transition-all duration-300 bg-[var(--kyro-surface)] hover:border-[var(--kyro-primary)]/20",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"w-9 h-9 rounded-xl bg-[var(--kyro-primary)]/10 flex items-center justify-center text-[var(--kyro-primary)] transition-transform group-hover/block:scale-110",children:jsxRuntime.jsx(lucideReact.CodeXml,{className:"w-5 h-5"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Code Snippet"}),jsxRuntime.jsxs("p",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] tracking-widest",children:["Block Editor \u2022 ",s.language||"javascript"]})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-1.5 opacity-0 group-hover/block:opacity-100 transition-all translate-x-2 group-hover/block:translate-x-0",children:jsxRuntime.jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)]/50 p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1.5 hover:bg-[var(--kyro-surface)] rounded-lg transition-all text-[var(--kyro-text-muted)] hover:text-[var(--kyro-primary)]",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4 rotate-[-90deg]"})}),jsxRuntime.jsx("div",{className:"w-px h-4 bg-[var(--kyro-border)] mx-1 self-center"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1.5 hover:bg-[var(--kyro-danger-bg)] rounded-lg transition-all text-[var(--kyro-text-muted)] hover:text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]})})]}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx(Aa,{field:{type:"code",name:"code",label:"Source Code",language:s.language||"javascript"},value:s.code||"",onChange:l=>i("code",l)}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 bg-[var(--kyro-surface-accent)]/20 p-4 rounded-xl border border-[var(--kyro-border)]/50",children:[jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2 block",children:"Syntax Highlighting"}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("select",{value:s.language||"javascript",onChange:l=>i("language",l.target.value),className:"w-full pl-4 pr-10 py-2.5 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl text-xs font-medium text-[var(--kyro-text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)]/20 focus:border-[var(--kyro-primary)] transition-all appearance-none cursor-pointer",children:[jsxRuntime.jsx("option",{value:"plaintext",children:"Plain Text"}),jsxRuntime.jsx("option",{value:"javascript",children:"JavaScript"}),jsxRuntime.jsx("option",{value:"typescript",children:"TypeScript"}),jsxRuntime.jsx("option",{value:"python",children:"Python"}),jsxRuntime.jsx("option",{value:"json",children:"JSON"}),jsxRuntime.jsx("option",{value:"html",children:"HTML"}),jsxRuntime.jsx("option",{value:"css",children:"CSS"}),jsxRuntime.jsx("option",{value:"sql",children:"SQL"}),jsxRuntime.jsx("option",{value:"rust",children:"Rust"}),jsxRuntime.jsx("option",{value:"markdown",children:"Markdown"})]}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--kyro-text-muted)]",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4 rotate-90"})})]})]}),jsxRuntime.jsx("div",{className:"hidden sm:block w-px h-10 bg-[var(--kyro-border)]"}),jsxRuntime.jsxs("div",{className:"hidden sm:flex flex-col justify-center",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2",children:"Status"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl",children:[jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500 animate-pulse"}),jsxRuntime.jsx("span",{className:"text-[10px] font-medium text-[var(--kyro-text-primary)] tracking-wide",children:"EDITING"})]})]})]})]})]})};var rd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-file border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"File"}),jsxRuntime.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(lr,{field:{label:"File",name:"file",maxCount:1},value:s.file,onChange:l=>i("file",l)})]})};var _s=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=ka__default.default.useState(0),n=(m,u)=>{let g=[...e];g[m]={...g[m],title:u},t(g);},s=(m,u)=>{let g=[...e];g[m]={...g[m],content:u},t(g);},i=m=>{let u=e.filter((g,x)=>x!==m);t(u),o===m?a(null):o!==null&&o>m&&a(o-1);},l=()=>{t([...e,{title:`Item ${e.length+1}`,content:""}]),a(e.length);},d="w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",c="w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return r?jsxRuntime.jsxs("div",{className:"space-y-2",children:[e.length===0?jsxRuntime.jsx("div",{className:"text-center py-4 text-[var(--kyro-text-muted)] text-sm border border-dashed border-[var(--kyro-border)] rounded-md",children:'No items. Click "Add Item" to create one.'}):jsxRuntime.jsx("div",{className:"space-y-1.5",children:e.map((m,u)=>{let g=o===u;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(g?null:u),className:"w-full flex items-center justify-between p-2.5 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${u+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),i(u);},className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5"})}),g?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),g&&jsxRuntime.jsxs("div",{className:"p-2.5 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:m.title||"",onChange:x=>n(u,x.target.value),onClick:x=>x.stopPropagation(),className:c,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:m.content||"",onChange:x=>s(u,x.target.value),onClick:x=>x.stopPropagation(),className:`${c} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},u)})}),jsxRuntime.jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]}):jsxRuntime.jsxs("div",{className:"space-y-2",children:[e.length===0?jsxRuntime.jsx("div",{className:"text-center py-4 text-[var(--kyro-text-muted)] text-sm border border-dashed border-[var(--kyro-border)] rounded-md",children:'No items. Click "Add Item" to create one.'}):jsxRuntime.jsx("div",{className:"space-y-2",children:e.map((m,u)=>{let g=o===u;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(g?null:u),className:"w-full flex items-center justify-between p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${u+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),i(u);},className:"opacity-0 group-hover:opacity-100 p-1.5 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})}),g?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),g&&jsxRuntime.jsxs("div",{className:"p-3 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:m.title||"",onChange:x=>n(u,x.target.value),className:d,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:m.content||"",onChange:x=>s(u,x.target.value),className:`${d} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},u)})}),jsxRuntime.jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]})};var od=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=Array.isArray(s.items)?s.items:[],l=d=>{o(e.id,{data:{...s,items:d}});};return jsxRuntime.jsxs("div",{className:"block-accordion border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Accordion"}),jsxRuntime.jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(_s,{items:i,onChange:l,compact:true})]})};var ad=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data||e.data||{},i=l=>{o(e.id,{data:{...s,content:l}});};return jsxRuntime.jsxs("div",{className:"block-richtext border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.AlignLeft,{className:"w-3.5 h-3.5 text-[var(--kyro-primary)]"}),jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Rich Text"})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx($o,{field:{name:"content",label:"Content",type:"richtext"},value:s.content,onChange:i})]})};var Vs=({heading:e="",subheading:t="",ctaText:r="",ctaUrl:o="",onChange:a,compact:n=false})=>{let s=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",i=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return n?jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsxRuntime.jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]}):jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsxRuntime.jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]})};function On({field:e,value:t,onChange:r,renderField:o}){let a=t||{};return jsxRuntime.jsxs("div",{className:"kyro-form-group border border-[var(--kyro-border)] rounded-[var(--kyro-radius-lg)] p-6 bg-[var(--kyro-surface-accent)]/30",children:[jsxRuntime.jsx("h3",{className:"text-sm font-bold tracking-widest text-[var(--kyro-text-primary)] mb-6 border-b border-[var(--kyro-border)] pb-2 inline-block",children:e.label||e.name}),jsxRuntime.jsx("div",{className:e.admin?.inline?"flex items-start gap-4":"space-y-6",children:e.fields.map(n=>o(n,a,r))})]})}var Am=new Set(["text","textarea","number","checkbox","select","radio","color","email","password","code","markdown","upload"]);function Rm(e){let t=e.fields||[];return t.length===0||t.length>4?false:t.every(r=>Am.has(r.type))}function Un({field:e,value:t,onChange:r,renderField:o,disabled:a}){let n=Array.isArray(t)?t:[],s=e.fields||[],i=s[0],l=i?.name||"user",d=i?.type==="relationship",[c,m]=ka__default.default.useState(0);function u(x){for(let f of ["label","title","name"]){let y=x[f];if(y&&typeof y=="string")return y}for(let f of s){if(f.type==="text"||f.type==="textarea"){let y=x[f.name];if(y&&typeof y=="string")return y}if(f.type==="group"&&f.fields){for(let y of f.fields)if(y.type==="text"||y.type==="textarea"){let v=x[f.name]?.[y.name];if(v&&typeof v=="string")return v}}}return ""}let g=Rm(e);return jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),d?jsxRuntime.jsx(Pa,{field:{name:l,relationTo:e.fields?.[0]?.relationTo||"",hasMany:true,label:e.fields?.[0]?.label},value:n.map(x=>x[l]).filter(Boolean),onChange:x=>{let f=(x||[]).map(y=>({[l]:y}));r(f);},disabled:a}):g?jsxRuntime.jsxs("div",{className:"kyro-form-array kyro-form-array--compact border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30 rounded-md overflow-hidden",children:[n.map((x,f)=>jsxRuntime.jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 border-b border-[var(--kyro-border)] last:border-b-0 hover:bg-[var(--kyro-sidebar-active)]/5 transition-colors",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] pt-2 min-w-[18px] text-center",children:f+1}),jsxRuntime.jsx("div",{className:"flex-1 flex items-start gap-1.5 min-w-0",children:e.fields.map(y=>jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:o(y,x,b=>{let v=[...n];v[f]=b,r(v);})},y.name))}),jsxRuntime.jsx("button",{type:"button",disabled:a,onClick:()=>r(n.filter((y,b)=>b!==f)),className:"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] transition-colors disabled:opacity-30 p-0.5 mt-1.5 flex-shrink-0",title:"Remove",children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f)),jsxRuntime.jsx("button",{type:"button",className:"w-full py-2 border-2 border-dashed border-[var(--kyro-border)] rounded-none text-xs font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:border-[var(--kyro-primary)] transition-all disabled:opacity-50",disabled:a,onClick:()=>r([...n,{}]),children:"+ Add Item"})]}):jsxRuntime.jsxs("div",{className:"kyro-form-array border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30 rounded-md p-3 space-y-4",children:[n.map((x,f)=>{let y=c===f;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("div",{role:"button",tabIndex:0,onClick:()=>m(y?null:f),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),m(y?null:f));},className:"w-full flex items-center justify-between p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors cursor-pointer",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold tracking-widest text-[var(--kyro-text-muted)] truncate",children:u(x)||`Item ${f+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",disabled:a,onClick:b=>{b.stopPropagation(),r(n.filter((v,R)=>R!==f));},className:"text-[11px] font-bold text-[var(--kyro-error)] opacity-0 group-hover:opacity-100 transition-opacity disabled:opacity-30 hover:bg-[var(--kyro-danger-bg)] rounded px-1.5 py-0.5",children:"Remove"}),y?jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),y&&jsxRuntime.jsx("div",{className:"p-4 bg-[var(--kyro-surface)] space-y-4",children:e.fields.map(b=>o(b,x,v=>{let R=[...n];R[f]=v,r(R);}))})]},f)}),jsxRuntime.jsx("button",{type:"button",className:"w-full py-3 border-2 border-dashed border-[var(--kyro-border)] rounded-lg text-xs font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:border-[var(--kyro-primary)] transition-all disabled:opacity-50",disabled:a,onClick:()=>r([...n,{}]),children:"+ Add Item"})]})]})}var sd="other";function id(){return sd}function zn(e){sd=e;}var xo=({field:e,value:t,onChange:r,error:o,disabled:a})=>{if(e.hidden===true||e.admin?.hidden===true)return null;let n=s=>{zn("keystroke"),r(s);};switch(e.type){case "text":case "email":case "url":return jsxRuntime.jsx(jo,{field:e,value:t,onChange:n,error:o,disabled:a});case "textarea":return jsxRuntime.jsx(jo,{field:{...e,variant:"textarea"},value:t,onChange:n,error:o,disabled:a});case "password":return jsxRuntime.jsx(jo,{field:{...e,variant:"password"},value:t,onChange:n,error:o,disabled:a});case "secret":return jsxRuntime.jsx(Cn,{field:e,value:t,onChange:r,error:o,disabled:a});case "number":return jsxRuntime.jsx(An,{field:e,value:t,onChange:r,disabled:a,error:o});case "checkbox":return jsxRuntime.jsx(Rn,{field:e,value:t,onChange:r,disabled:a,error:o});case "select":return jsxRuntime.jsx(In,{field:e,value:t,onChange:r,disabled:a,error:o});case "date":return jsxRuntime.jsx(Fn,{field:e,value:t,onChange:r,disabled:a,error:o});case "richtext":return jsxRuntime.jsx($o,{field:e,value:t,onChange:n,disabled:a,error:o});case "markdown":return jsxRuntime.jsx(Cs,{field:e,value:t,onChange:n,disabled:a,error:o});case "code":return jsxRuntime.jsx(Aa,{field:e,value:t,onChange:n,disabled:a,error:o});case "image":case "upload":return jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsx(lr,{field:e,value:t,onChange:r,disabled:a})});case "relationship":return jsxRuntime.jsx(Pa,{field:e,value:t,onChange:r,disabled:a,error:o});case "list":return jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsx(La,{items:Array.isArray(t)?t:[],onChange:r,compact:true})});case "array":return jsxRuntime.jsx(Un,{field:e,value:Array.isArray(t)?t:[],onChange:r,disabled:a,renderField:(s,i,l)=>{let d=i[s.name];return jsxRuntime.jsx(xo,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "blocks":return jsxRuntime.jsx(Ks,{field:e,value:t,onChange:n,disabled:a,error:o});case "group":return jsxRuntime.jsx(On,{field:e,value:t,onChange:r,renderField:(s,i,l)=>{let d=i[s.name];return jsxRuntime.jsx(xo,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "color":return jsxRuntime.jsx(nt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("input",{type:"color",value:t||"#000000",onChange:s=>r(s.target.value),disabled:a,className:"h-10 w-14 p-1 cursor-pointer bg-[var(--kyro-input-bg)] border border-[var(--kyro-input-border)] rounded-lg"}),jsxRuntime.jsx("input",{type:"text",className:"kyro-form-input font-mono ",value:t||"",onChange:s=>r(s.target.value),disabled:a,placeholder:"#000000"})]})});default:return jsxRuntime.jsxs("div",{className:"p-4 bg-amber-50 border border-amber-200 rounded-lg text-amber-800 text-xs italic",children:['Field type "',e.type,'" is not yet supported in this renderer.']})}};var Wo=({block:e,blockSchema:t,onClose:r})=>{let o=Ee(e.id),{updateBlock:a}=Be(),n=o?.data||e.data||{},s=o?.children||e.children||[],i=(m,u)=>{a(e.id,{data:{...n,[m]:u}});},l=m=>{a(e.id,{children:m});},d=()=>t&&Array.isArray(t.fields)?jsxRuntime.jsx("div",{className:"space-y-4 pt-2",children:t.fields.map(m=>{if(m.admin?.condition){if(typeof m.admin.condition=="function")try{let g={values:n,...n};if(!m.admin.condition(g,g))return null}catch(g){console.warn(`Condition error for field ${m.name}:`,g);}else if(typeof m.admin.condition=="object")try{let g=m.admin.condition,x=g.field,f=n[x],y=!0;if("equals"in g?y=f===g.equals:"notEquals"in g?y=f!==g.notEquals:"in"in g&&Array.isArray(g.in)&&(y=g.in.includes(f)),!y)return null}catch(g){console.warn(`Declarative condition error for field ${m.name}:`,g);}}let u=n[m.name];return jsxRuntime.jsx("div",{className:"kyro-block-field-row border-b border-[var(--kyro-border)]/30 pb-3 last:border-b-0 last:pb-0",children:jsxRuntime.jsx(xo,{field:m,value:u,onChange:g=>i(m.name,g)})},m.name)})}):jsxRuntime.jsxs("div",{className:"text-center py-8 text-[var(--kyro-text-muted)] text-sm italic",children:['No schema defined for block type "',e.type,'"']}),c=Fe[e.type]||Fe.default;return jsxRuntime.jsxs(dr,{open:true,onClose:r,title:`Edit ${t?.label||e.type}`,width:"xl",showOverlay:false,accentClass:c.border,children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[d(),s.length>0&&jsxRuntime.jsxs("div",{className:"pt-4 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",s.length,")"]}),jsxRuntime.jsx(Jr,{blockId:e.id,children:s,onUpdateChildren:l})]})]}),jsxRuntime.jsx("div",{className:"mt-6 pt-4 border-t border-[var(--kyro-border)]",children:jsxRuntime.jsx("button",{type:"button",onClick:r,className:"w-full py-2.5 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-lg font-medium hover:opacity-90 transition-opacity",children:"Done"})})]})};var Fm=6,Jr=({blockId:e,children:t,onUpdateChildren:r,depth:o=0,maxDepth:a=Fm})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(new Set),[d,c]=ka.useState(null),[m,u]=ka.useState(null),g=ka.useContext(vo);if(!g)throw new Error("ChildBlocksTree must be used within a BlocksContext");let x=zustand.useStore(g,p=>p.dynamicCategories),f=zustand.useStore(g,p=>p.allowedBlocks),y=o<a,b=16,v=p=>{let A=Vo(p);r([...t,A]),c(A.id);},R=p=>{let A=t.filter(O=>O.id!==p);r(A);},C=(p,A)=>{let O=t.map(F=>F.id===p?{...F,children:A}:F);r(O);},w=p=>{l(A=>{let O=new Set(A);return O.has(p)?O.delete(p):O.add(p),O});},N=p=>{let A=p.children&&p.children.length>0,O=i.has(p.id);Gs(p.type);let P=A,S=d===p.id,M=f.find(j=>j.slug===p.type);return jsxRuntime.jsxs("div",{className:"relative group",children:[jsxRuntime.jsxs("div",{className:`flex items-center group/column gap-2 p-2 bg-[var(--kyro-bg-secondary)] rounded border transition-colors ${S?"bg-[var(--kyro-primary)]/10 border-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"} ${y?"cursor-pointer":""}`,style:{marginLeft:o*b},onClick:()=>{y&&c(S?null:p.id);},children:[P?jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:O?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsxRuntime.jsx("span",{className:"w-4"}),jt[p.type]&&jsxRuntime.jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:jt[p.type]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ea(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),M?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:M.admin.description})]}),A&&jsxRuntime.jsxs("span",{className:"text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium",children:[p.children.length," nested"]}),m===p.id?jsxRuntime.jsxs("div",{className:"flex items-center gap-1",onClick:j=>j.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{R(p.id),u(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>u(null),className:"px-2 py-1 text-xs bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] rounded hover:bg-[var(--kyro-border)]",children:"Cancel"})]}):jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),u(p.id);},className:"p-1.5 rounded-md transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)] invisible group-hover/column:visible"})})]}),S&&jsxRuntime.jsx(Wo,{block:p,onClose:()=>c(null)}),A&&O&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(cd,{parentId:p.id,children:p.children,onUpdateChildren:j=>C(p.id,j),depth:o+1,maxDepth:a})})]},p.id)};return jsxRuntime.jsxs("div",{className:"space-y-2",children:[t.length>0&&jsxRuntime.jsx("div",{className:"space-y-1",children:t.map(N)}),y&&jsxRuntime.jsxs("div",{style:{marginLeft:o*b},children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(true),className:"flex items-center gap-1 px-2 py-1 text-xs font-medium text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)] rounded transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3 h-3"}),"Add Block"]}),jsxRuntime.jsx(Ia,{open:n,onClose:()=>s(false),onSelect:v,children:x.map(p=>jsxRuntime.jsxs("div",{className:"mb-4",children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(A=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{v(A.slug),s(false);},className:"flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group",children:[jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:jt[A.slug]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:A.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:A.admin?.description||""})]})]},A.slug))})]},p.title))})]}),t.length===0&&y&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*b},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxRuntime.jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*b},children:["Maximum nesting level (",a,") reached"]})]})},cd=({parentId:e,children:t,onUpdateChildren:r,depth:o,maxDepth:a})=>{let[n,s]=ka.useState(false),[i,l]=ka.useState(new Set),[d,c]=ka.useState(null),[m,u]=ka.useState(null),g=ka.useContext(vo);if(!g)throw new Error("NestedChildBlocks must be used within a BlocksContext");let x=zustand.useStore(g,p=>p.dynamicCategories),f=zustand.useStore(g,p=>p.allowedBlocks),y=o<a,b=16,v=p=>{let A=Vo(p);r([...t,A]),c(A.id);},R=p=>{let A=t.filter(O=>O.id!==p);r(A);},C=(p,A)=>{let O=t.map(F=>F.id===p?{...F,children:A}:F);r(O);},w=p=>{l(A=>{let O=new Set(A);return O.has(p)?O.delete(p):O.add(p),O});},N=p=>{let A=p.children&&p.children.length>0,O=i.has(p.id);Gs(p.type);let P=A,S=d===p.id,M=f.find(j=>j.slug===p.type);return jsxRuntime.jsxs("div",{className:"relative group",children:[jsxRuntime.jsxs("div",{className:`flex items-center gap-2 p-2 bg-[var(--kyro-bg-secondary)] rounded border transition-colors ${S?"bg-[var(--kyro-primary)]/10 border-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"} ${y?"cursor-pointer":""}`,style:{marginLeft:o*b},onClick:()=>{y&&c(S?null:p.id);},children:[P?jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:O?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsxRuntime.jsx("span",{className:"w-4"}),jt[p.type]&&jsxRuntime.jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:jt[p.type]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ea(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),M?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:M.admin.description})]}),A&&jsxRuntime.jsxs("span",{className:"text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium",children:[p.children.length," nested"]}),m===p.id?jsxRuntime.jsxs("div",{className:"flex items-center gap-1",onClick:j=>j.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{R(p.id),u(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>u(null),className:"px-2 py-1 text-xs bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] rounded hover:bg-[var(--kyro-border)]",children:"Cancel"})]}):jsxRuntime.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),u(p.id);},className:"p-1.5 rounded-md invisible group-hover:visible transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)]"})})]}),S&&jsxRuntime.jsx(Wo,{block:p,onClose:()=>c(null)}),A&&O&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(cd,{parentId:p.id,children:p.children,onUpdateChildren:j=>C(p.id,j),depth:o+1,maxDepth:a})})]},p.id)};return jsxRuntime.jsxs("div",{className:"space-y-2",children:[t.length>0&&jsxRuntime.jsx("div",{className:"space-y-1",children:t.map(N)}),y&&jsxRuntime.jsxs("div",{style:{marginLeft:o*b},children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(true),className:"flex items-center gap-1 px-2 py-1 text-xs font-medium text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)] rounded transition-colors",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-3 h-3"}),"Add Block"]}),jsxRuntime.jsx(Ia,{open:n,onClose:()=>s(false),onSelect:v,children:x.map(p=>jsxRuntime.jsxs("div",{className:"mb-4",children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(A=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{v(A.slug),s(false);},className:"flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group",children:[jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:jt[A.slug]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:A.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:A.admin?.description||""})]})]},A.slug))})]},p.title))})]}),t.length===0&&y&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*b},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxRuntime.jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*b},children:["Maximum nesting level (",a,") reached"]})]})};var pd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=r?.children??e.children??[],l=(d,c)=>{o(e.id,{data:{...s,[d]:c}});};return jsxRuntime.jsxs("div",{className:"block-hero border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Hero Section"})}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx(Vs,{heading:s.heading||"",subheading:s.subheading||"",ctaText:s.ctaText||"",ctaUrl:s.ctaUrl||"",onChange:l,compact:true}),jsxRuntime.jsx(lr,{field:{label:"Background",name:"bgImage",maxCount:1},value:s.bgImage,onChange:d=>l("bgImage",d)}),jsxRuntime.jsxs("div",{className:"pt-3 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",i.length,")"]}),jsxRuntime.jsx(Jr,{blockId:e.id,children:i,onUpdateChildren:d=>o(e.id,{children:d})})]})]})]})};var Ws=({title:e="",description:t="",icon:r="",link:o="",linkText:a="",onChange:n,compact:s=false})=>{let i=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",l=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxRuntime.jsxs("div",{className:s?"space-y-2":"space-y-3",children:[jsxRuntime.jsx("input",{type:"text",value:e,onChange:d=>n("title",d.target.value),className:`${i} font-bold text-base`,placeholder:"Card title..."}),jsxRuntime.jsx("textarea",{value:t,onChange:d=>n("description",d.target.value),className:l,placeholder:"Card description..."}),jsxRuntime.jsx("input",{type:"text",value:r,onChange:d=>n("icon",d.target.value),className:i,placeholder:"Icon (emoji or name)..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:a,onChange:d=>n("linkText",d.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Link text..."}),jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsxRuntime.jsx("input",{type:"url",value:o,onChange:d=>n("link",d.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]})};var yd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o}=Be(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsxRuntime.jsx(go,{id:e.id,type:"card",label:"Card",children:jsxRuntime.jsx(Ws,{title:a.title||"",description:a.description||"",icon:a.icon||"",link:a.link||"",linkText:a.linkText||"",onChange:n,compact:true})})};var fd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be();r?.data??e.data??{};let i=r?.children??e.children??[];return jsxRuntime.jsxs("div",{className:"block-array border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Repeater"}),jsxRuntime.jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx("div",{className:"space-y-3",children:jsxRuntime.jsx(Jr,{blockId:e.id,children:i,onUpdateChildren:l=>o(e.id,{children:l})})})]})};var Ua=({relationTo:e="pages",hasMany:t=false,selectedIds:r=[],selectedId:o,labelField:a="title",onChange:n,compact:s=false})=>{let[i,l]=ka.useState(false),[d,c]=ka.useState(""),[m,u]=ka.useState([]),[g,x]=ka.useState(false),[f,y]=ka.useState([]),[b,v]=ka.useState(true);ka.useEffect(()=>{De("/api/collections").then(F=>{y((F.collections||[]).map(P=>P.slug||P.name||P)),v(false);}).catch(()=>v(false));},[]);let R=(F="")=>{x(true);let P=`/api/${e}?${Ja(F,[a],20)}`;De(P).then(S=>{u(S.docs||[]),x(false);}).catch(()=>x(false));};ka.useEffect(()=>{i&&R(d);},[i,d,e,a]);let L=F=>F?.[a]||F?.title||F?.name||F?.label||F?.filename||F?.slug||F?.id||"Untitled",C=t?r:o?[o]:[],w=F=>{t?C.includes(F.id)?n("selectedIds",C.filter(P=>P!==F.id)):n("selectedIds",[...C,F.id]):(n("selectedId",F.id),n("selectedIds",[F.id]),l(false));},N=F=>C.includes(F),p=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",A=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",O=e&&typeof e=="string"&&e.length>0;return jsxRuntime.jsxs("div",{className:s?"space-y-2":"space-y-4",children:[jsxRuntime.jsxs("div",{className:s?"flex items-center gap-2":"space-y-3",children:[!O&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:b?jsxRuntime.jsx("div",{className:A+" text-[var(--kyro-text-muted)]",children:"Loading..."}):jsxRuntime.jsxs("select",{value:e,onChange:F=>n("relationTo",F.target.value),className:A,children:[jsxRuntime.jsx("option",{value:"",children:"Select collection..."}),f.map(F=>jsxRuntime.jsx("option",{value:F,children:F},F))]})}),!s&&jsxRuntime.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:t,onChange:F=>n("hasMany",F.target.checked),className:"w-4 h-4 rounded border-[var(--kyro-border)] focus:ring-[var(--kyro-sidebar-active)] focus:ring-offset-0"}),jsxRuntime.jsx("span",{className:"text-sm text-[var(--kyro-text-primary)]",children:"Allow multiple"})]})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsxRuntime.jsx("input",{type:"text",value:d,onChange:F=>{c(F.target.value),l(true);},onFocus:()=>l(true),onBlur:()=>setTimeout(()=>l(false),200),placeholder:`Search ${e}...`,className:`${p} pl-9`}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:g&&jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"})})]}),i&&jsxRuntime.jsx("div",{className:"absolute z-20 w-full mt-1 border border-[var(--kyro-border)] rounded-lg shadow-lg bg-[var(--kyro-surface)] max-h-48 overflow-auto",children:g?jsxRuntime.jsx("div",{className:"p-3 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):m.length===0?jsxRuntime.jsx(Ln,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:m.map(F=>jsxRuntime.jsxs("button",{type:"button",onMouseDown:P=>P.preventDefault(),onClick:()=>w(F),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors flex items-center justify-between ${N(F.id)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("span",{children:L(F)}),N(F.id)&&jsxRuntime.jsx("span",{children:"\u2713"})]},F.id))})})]}),C.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5",children:C.map(F=>{let P=m.find(S=>S.id===F)||{id:F};return jsxRuntime.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-md bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]",children:[L(P),jsxRuntime.jsx("button",{type:"button",onMouseDown:S=>S.preventDefault(),onClick:()=>{t?n("selectedIds",C.filter(S=>S!==F)):(n("selectedId",null),n("selectedIds",[]));},className:"hover:opacity-70",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},F)})})]})};var gd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxRuntime.jsxs("div",{className:"block-relationship border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Relationship"}),jsxRuntime.jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["\u2192 ",s.relationTo||"pages"]})]}),jsxRuntime.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-danger)]",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),jsxRuntime.jsx(Ua,{relationTo:s.relationTo||"pages",hasMany:s.hasMany||false,selectedIds:Array.isArray(s.selectedIds)?s.selectedIds:[],selectedId:s.selectedId,labelField:s.labelField||"title",onChange:i,compact:true})]})};var Dm={heading:ql,paragraph:Xl,image:Ql,video:Zl,list:ed,code:td,file:rd,accordion:od,richtext:ad,hero:pd,card:yd,array:fd,relationship:gd},Fe={featureSplit:{text:"text-indigo-500",border:"border-indigo-500",borderLeft:"border-l-indigo-500"},featureGrid:{text:"text-blue-500",border:"border-blue-500",borderLeft:"border-l-blue-500"},ctaBanner:{text:"text-amber-500",border:"border-amber-500",borderLeft:"border-l-amber-500"},testimonials:{text:"text-emerald-500",border:"border-emerald-500",borderLeft:"border-l-emerald-500"},faq:{text:"text-orange-500",border:"border-orange-500",borderLeft:"border-l-orange-500"},stats:{text:"text-rose-500",border:"border-rose-500",borderLeft:"border-l-rose-500"},logoCloud:{text:"text-cyan-500",border:"border-cyan-500",borderLeft:"border-l-cyan-500"},pricing:{text:"text-green-500",border:"border-green-500",borderLeft:"border-l-green-500"},team:{text:"text-violet-500",border:"border-violet-500",borderLeft:"border-l-violet-500"},recentFeed:{text:"text-sky-500",border:"border-sky-500",borderLeft:"border-l-sky-500"},processSteps:{text:"text-fuchsia-500",border:"border-fuchsia-500",borderLeft:"border-l-fuchsia-500"},formEmbed:{text:"text-pink-500",border:"border-pink-500",borderLeft:"border-l-pink-500"},videoShowcase:{text:"text-red-500",border:"border-red-500",borderLeft:"border-l-red-500"},hero:{text:"text-yellow-500",border:"border-yellow-500",borderLeft:"border-l-yellow-500"},card:{text:"text-teal-500",border:"border-teal-500",borderLeft:"border-l-teal-500"},default:{text:"text-zinc-400",border:"border-zinc-400",borderLeft:"border-l-zinc-400"}},jt={heading:jsxRuntime.jsx(lucideReact.Heading1,{className:`w-4 h-4 ${Fe.default.text}`}),paragraph:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Fe.default.text}`}),image:jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Fe.default.text}`}),video:jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Fe.default.text}`}),list:jsxRuntime.jsx(lucideReact.List,{className:`w-4 h-4 ${Fe.default.text}`}),code:jsxRuntime.jsx(lucideReact.Code,{className:`w-4 h-4 ${Fe.default.text}`}),file:jsxRuntime.jsx(lucideReact.File,{className:`w-4 h-4 ${Fe.default.text}`}),accordion:jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-4 h-4 ${Fe.default.text}`}),richtext:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Fe.default.text}`}),hero:jsxRuntime.jsx(lucideReact.Star,{className:`w-4 h-4 ${Fe.hero.text}`}),card:jsxRuntime.jsx(lucideReact.Box,{className:`w-4 h-4 ${Fe.card.text}`}),array:jsxRuntime.jsx(lucideReact.ListOrdered,{className:`w-4 h-4 ${Fe.default.text}`}),relationship:jsxRuntime.jsx(lucideReact.Link2,{className:`w-4 h-4 ${Fe.default.text}`}),featureSplit:jsxRuntime.jsx(lucideReact.Columns3,{className:`w-4 h-4 ${Fe.featureSplit.text}`}),featureGrid:jsxRuntime.jsx(lucideReact.Blocks,{className:`w-4 h-4 ${Fe.featureGrid.text}`}),ctaBanner:jsxRuntime.jsx(lucideReact.Sparkles,{className:`w-4 h-4 ${Fe.ctaBanner.text}`}),testimonials:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Fe.testimonials.text}`}),faq:jsxRuntime.jsx(lucideReact.CircleHelp,{className:`w-4 h-4 ${Fe.faq.text}`}),stats:jsxRuntime.jsx(lucideReact.Activity,{className:`w-4 h-4 ${Fe.stats.text}`}),logoCloud:jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Fe.logoCloud.text}`}),pricing:jsxRuntime.jsx(lucideReact.Tag,{className:`w-4 h-4 ${Fe.pricing.text}`}),team:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Fe.team.text}`}),recentFeed:jsxRuntime.jsx(lucideReact.Database,{className:`w-4 h-4 ${Fe.recentFeed.text}`}),processSteps:jsxRuntime.jsx(lucideReact.Clock,{className:`w-4 h-4 ${Fe.processSteps.text}`}),formEmbed:jsxRuntime.jsx(lucideReact.Mail,{className:`w-4 h-4 ${Fe.formEmbed.text}`}),videoShowcase:jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Fe.videoShowcase.text}`})};function Gs(e){return Dm[e]||null}function qs(e){return {paragraph:"Paragraph",heading:"Heading",image:"Image",video:"Video",list:"List",code:"Code",file:"File",accordion:"Accordion",array:"Repeater",relationship:"Relationship",richtext:"Rich Text",hero:"Hero Section",card:"Card Block",featureSplit:"Feature Split",featureGrid:"Feature Grid",ctaBanner:"CTA Banner",testimonials:"Testimonials Stack",faq:"FAQ Section",stats:"Stats & Metrics",logoCloud:"Logo Cloud",pricing:"Pricing Grid / Plan",team:"Team Profiles Showcase",recentFeed:"Dynamic Content Feed",processSteps:"Process Timeline / Steps",formEmbed:"Lead Intake Form",videoShowcase:"Cinematic Video Showcase",headingElement:"Heading",textElement:"Text",imageElement:"Image",richtextElement:"Rich Text",buttonElement:"Button",videoElement:"Video",listElement:"List"}[e]||e}function Ea(e){let t=e.name;return t&&t.trim()?t.trim():qs(e.type)}function Vm(e,t){if(t?.fields){for(let r of t.fields)if(r.type==="text"||r.type==="textarea"){let o=e[r.name];if(o&&typeof o=="string")return o}}return e.heading||e.title||e.text||e.name||e.label||e.sectionTitle||""}var Km=({block:e,index:t,blockSchema:r,editingBlockId:o,setEditingBlockId:a,onDuplicate:n,compact:s})=>{let{attributes:i,listeners:l,setNodeRef:d,transform:c,transition:m,isDragging:u}=sortable.useSortable({id:e.id}),{removeBlock:g,updateBlock:x}=Be(),f=o===e.id,[y,b]=ka.useState(false),[v,R]=ka.useState(false),[L,C]=ka.useState(e.name||""),w=ka.useRef(null);ka.useEffect(()=>{v&&w.current&&(w.current.focus(),w.current.select());},[v]);let N=ka.useCallback(()=>{R(false);let P=L.trim();P!==(e.name||"").trim()&&x(e.id,{name:P||""});},[L,e.name,e.id,x]),p={transform:utilities.CSS.Transform.toString(c),transition:m,zIndex:u?10:1,opacity:u?.8:1},A=Ea(e),O=e.data||{},F=Vm(O,r);return s?jsxRuntime.jsxs("div",{ref:d,style:p,className:"relative group",children:[jsxRuntime.jsxs("div",{onClick:()=>a(e.id),className:`flex items-center gap-1 pl-5 pr-1.5 py-1 bg-[var(--kyro-bg-secondary)] rounded-md border transition-colors cursor-pointer text-xs whitespace-nowrap ${f?`${(Fe[e.type]||Fe.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[jsxRuntime.jsx("div",{className:"absolute left-0.5 top-1/2 -translate-y-1/2 p-0.5 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] opacity-0 group-hover:opacity-100 transition-opacity hover:bg-[var(--kyro-surface-accent)] rounded",...i,...l,onClick:P=>P.stopPropagation(),children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-2.5 h-2.5"})}),jt[e.type]&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-secondary)] flex-shrink-0",children:jt[e.type]}),v?jsxRuntime.jsx("input",{ref:w,value:L,onChange:P=>C(P.target.value),onBlur:N,onKeyDown:P=>{P.key==="Enter"&&N(),P.key==="Escape"&&(C(e.name||""),R(false));},onClick:P=>P.stopPropagation(),className:"flex-1 min-w-0 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-primary)] rounded px-1.5 py-0.5 text-[10px] font-medium text-[var(--kyro-text-primary)] outline-none"}):jsxRuntime.jsx("span",{onClick:P=>{P.stopPropagation(),C(e.name||""),R(true);},className:"font-medium text-[var(--kyro-text-secondary)] truncate max-w-[120px] cursor-text hover:text-[var(--kyro-text-primary)] transition-colors",title:"Click to rename",children:A}),y?jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5",onClick:P=>P.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(e.id),b(false);},className:"px-1.5 py-0.5 text-[9px] bg-[var(--kyro-danger)] text-white rounded font-semibold transition-colors hover:brightness-90",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>b(false),className:"px-1.5 py-0.5 text-[9px] bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded font-semibold transition-colors",children:"Cancel"})]}):jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5",children:[jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),n(e.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Duplicate",children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-3 h-3"})}),jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),b(true);},className:"p-0.5 hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] rounded text-[var(--kyro-text-muted)] transition-colors",title:"Remove",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})]}),f&&jsxRuntime.jsx(Wo,{block:e,blockSchema:r,onClose:()=>a(null)})]}):jsxRuntime.jsxs("div",{ref:d,style:p,className:"relative group md:pl-8 mb-2",children:[jsxRuntime.jsx("div",{className:"hidden md:absolute left-0 top-1/2 -translate-y-1/2 p-1.5 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] opacity-0 group-hover:opacity-100 transition-opacity hover:bg-[var(--kyro-surface-accent)] rounded",...i,...l,children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{onClick:()=>a(e.id),className:`flex items-center gap-3 p-3 bg-[var(--kyro-bg-secondary)] rounded-lg border transition-colors cursor-pointer ${f?`${(Fe[e.type]||Fe.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[jt[e.type]&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-secondary)]",children:jt[e.type]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[v?jsxRuntime.jsx("input",{ref:w,value:L,onChange:P=>C(P.target.value),onBlur:N,onKeyDown:P=>{P.key==="Enter"&&N(),P.key==="Escape"&&(C(e.name||""),R(false));},onClick:P=>P.stopPropagation(),placeholder:qs(e.type),className:"w-full max-w-[150px] sm:max-w-[250px] md:max-w-[400px] bg-[var(--kyro-surface-accent)] border border-[var(--kyro-primary)] rounded px-2 py-0.5 text-xs font-semibold text-[var(--kyro-text-primary)] outline-none"}):jsxRuntime.jsxs("div",{onClick:P=>{window.innerWidth>=768&&(P.stopPropagation(),C(e.name||""),R(true));},className:"text-xs font-semibold text-[var(--kyro-text-secondary)] truncate md:cursor-text hover:text-[var(--kyro-text-primary)] transition-colors",title:"Click to rename",children:[A,F&&typeof F=="string"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-text-muted)] font-normal ml-1.5",children:["- ",F.length>40?`${F.slice(0,40)}...`:F]})]}),r?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:r.admin.description})]}),e.children&&Array.isArray(e.children)&&e.children.length>0&&jsxRuntime.jsxs("span",{className:"text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium",children:[e.children.length," nested"]}),y?jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",onClick:P=>P.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(e.id),b(false);},className:"px-2.5 py-1 text-[10px] bg-[var(--kyro-danger)] text-white rounded font-semibold transition-colors hover:brightness-90",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>b(false),className:"px-2.5 py-1 text-[10px] bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded font-semibold transition-colors",children:"Cancel"})]}):jsxRuntime.jsxs("div",{className:"flex items-center gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),C(e.name||""),R(true);},className:"md:hidden p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Rename Block",children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"}),jsxRuntime.jsx("path",{d:"m15 5 4 4"})]})}),jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),n(e.id);},className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Duplicate Block",children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),b(true);},className:"p-1 hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] rounded text-[var(--kyro-text-muted)] transition-colors",title:"Remove Block",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5"})})]})]}),f&&jsxRuntime.jsx(Wo,{block:e,blockSchema:r,onClose:()=>a(null)})]})},Gm=ka__default.default.memo(Km),Ks=({field:e,value:t,onChange:r,onBlocksChange:o,error:a,disabled:n,documentStatus:s,justSaved:i})=>{let[l,d]=ka.useState(false),[c,m]=ka.useState(false),u=ka.useRef(null),g=e.admin?.pickerMode||"drawer",x=e.blocks||[],f=x.reduce((B,K)=>{let ce=K.admin?.group||"Custom Blocks";return B[ce]||(B[ce]=[]),B[ce].push(K),B},{}),y=["Structural Sections","Marketing Grids","Lead Capture & Interactive","Dynamic Content","Basic Content Elements","Custom Blocks"],b=Object.entries(f).sort(([B],[K])=>{let ce=y.indexOf(B),he=y.indexOf(K);return ce!==-1&&he!==-1?ce-he:ce!==-1?-1:he!==-1?1:B.localeCompare(K)}).map(([B,K])=>({title:B,blocks:K})),v=ka.useRef(null);v.current||(v.current=Vl(x,b));let R=v.current,L=zustand.useStore(R,B=>B.blocks),[C,w]=ka.useState(null),[N,p]=ka.useState(null),A=ka.useRef(L.length),O=ka.useRef(new Set(L.map(B=>B.id))),F=ka.useRef(false);ka.useEffect(()=>{if(F.current&&L.length>A.current){let B=L.find(K=>K.id&&!O.current.has(K.id));B&&p(B.id);}A.current=L.length,O.current=new Set(L.map(B=>B.id));},[L]),ka.useEffect(()=>(o&&R.getState().setOnBlocksChange(o),()=>{R.getState().setOnBlocksChange(()=>{});}),[o,R]);let P=ka.useRef(null);ka.useEffect(()=>{let B=Array.isArray(t)?t:[],K=P.current||[];if(JSON.stringify(B)!==JSON.stringify(K)){let ce=[...B];A.current=ce.length,O.current=new Set(ce.map(he=>he.id)),R.getState().setBlocks(ce),P.current=ce,F.current=true;}else B.length===0&&!F.current&&(F.current=true,P.current=[]);},[t,e.name,R]);let S=ka.useRef(r);S.current=r,ka.useEffect(()=>{if(!S.current)return;let B=P.current;B&&JSON.stringify(L)!==JSON.stringify(B)&&(P.current=[...L],S.current(L));},[L]);let j=ka.useCallback(B=>{R.getState().addBlock(B);},[R]),se=ka.useCallback(B=>{let K=L.findIndex(I=>I.id===B);if(K===-1)return;let ce=L[K],he=I=>{let z=Math.random().toString(36).substr(2,9);return {...I,id:z,children:I.children?I.children.map(Ve=>he(Ve)):I.children,data:I.data?JSON.parse(JSON.stringify(I.data)):I.data}},Pe=he(ce),Ce=[...L];Ce.splice(K+1,0,Pe),R.getState().setBlocks(Ce);},[L,R]),ie=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:8}}),core.useSensor(core.KeyboardSensor)),ue=B=>{w(B.active);},oe=B=>{let{active:K,over:ce}=B;if(w(null),!!ce){if(K.id.toString().startsWith("drawer-")){let he=K.id.toString().replace("drawer-","");if(ce.id.toString().startsWith("container-")){let Pe=ce.id.toString().replace("container-",""),Ce=L.find(I=>I.id===Pe);if(Ce){let I=Vo(he);R.getState().updateBlock(Pe,{children:[...Ce.children||[],I]});}}else j(he);return}if(K.id!==ce.id){let he=L.findIndex(Ce=>Ce.id===K.id),Pe=L.findIndex(Ce=>Ce.id===ce.id);if(he!==-1&&Pe!==-1){let Ce=[...L],[I]=Ce.splice(he,1);Ce.splice(Pe,0,I),R.getState().setBlocks(Ce);}}}},ne=C?b.flatMap(B=>B.blocks).find(B=>`drawer-${B.type}`===C.id)||L.find(B=>B.id===C.id):null;ne?"label"in ne?ne.label:ne.type:"Block";return ka.useEffect(()=>{if(!c)return;let B=K=>{u.current&&!u.current.contains(K.target)&&m(false);};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[c]),jsxRuntime.jsx(vo.Provider,{value:v.current,children:jsxRuntime.jsxs("div",{className:"kyro-blocks-field",children:[jsxRuntime.jsxs(core.DndContext,{sensors:ie,collisionDetection:core.closestCenter,onDragStart:ue,onDragEnd:oe,children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),g==="dropdown"?jsxRuntime.jsxs("div",{ref:u,className:"relative",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>m(!c),disabled:n,className:"flex items-center gap-1.5 px-3 py-2 text-sm text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)]/30 rounded-md transition-colors disabled:opacity-50 font-semibold",children:[jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsxRuntime.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add Element",jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-3.5 h-3.5 transition-transform ${c?"rotate-180":""}`})]}),c&&jsxRuntime.jsx("div",{className:"absolute right-0 top-full mt-1 w-56 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 py-2 max-h-80 overflow-y-auto",children:b.map(B=>jsxRuntime.jsxs("div",{children:[b.length>1&&jsxRuntime.jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold tracking-wider text-[var(--kyro-text-muted)] uppercase",children:B.title}),B.blocks.map(K=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{j(K.slug),m(false);},className:"w-full flex items-center gap-3 px-3 py-2 text-sm text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]/50 transition-colors text-left",children:[jsxRuntime.jsx("span",{className:"flex-shrink-0 w-5 h-5 flex items-center justify-center text-[var(--kyro-text-muted)]",children:jt[K.slug]||jsxRuntime.jsx(lucideReact.Box,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"min-w-0 flex-1",children:[jsxRuntime.jsx("div",{className:"text-xs font-semibold truncate",children:K.label}),K.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] truncate",children:K.admin.description})]})]},K.slug))]},B.title))})]}):jsxRuntime.jsxs("button",{type:"button",onClick:()=>d(true),disabled:n,className:"flex items-center gap-2 px-3 py-2 text-sm text-[var(--kyro-primary)] hover:bg-[var(--kyro-surface-accent)]/30 rounded-md transition-colors disabled:opacity-50 font-semibold",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4"}),"Add Block"]})]}),jsxRuntime.jsx("div",{className:"mb-4",children:jsxRuntime.jsx(Ia,{open:l,onClose:()=>d(false),onSelect:j,children:jsxRuntime.jsx("div",{className:"space-y-4",children:b.map(B=>jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] mb-2 tracking-wider",children:B.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:B.blocks.map(K=>jsxRuntime.jsx(Kl,{block:{type:K.slug,label:K.label,description:K.admin?.description||"",icon:null},onSelect:j,children:jsxRuntime.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all duration-300",children:jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]",children:jt[K.slug]||jsxRuntime.jsx(lucideReact.Box,{className:"w-4 h-4"})})})},K.slug))})]},B.title))})})}),jsxRuntime.jsx(sortable.SortableContext,{items:L.map(B=>B.id),strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsxs("div",{className:g==="dropdown"?"flex flex-wrap gap-1.5":"space-y-4",children:[L.map((B,K)=>{let ce=e.blocks?.find(he=>he.slug===B.type);return jsxRuntime.jsx(Gm,{block:B,index:K,blockSchema:ce,editingBlockId:N,setEditingBlockId:p,onDuplicate:se,compact:g==="dropdown"},B.id||K)}),L.length===0&&jsxRuntime.jsx("div",{className:g==="dropdown"?"text-xs text-[var(--kyro-text-muted)] italic py-1":"text-center py-12 text-[var(--kyro-text-muted)] border-2 border-dashed border-[var(--kyro-border)] rounded-lg",children:g==="dropdown"?"No elements added":"Click the button above to add your first block"})]})}),jsxRuntime.jsx(core.DragOverlay,{children:C&&ne&&jsxRuntime.jsx("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-primary)] rounded-md p-3 shadow-lg",children:ne.label||ne.type||"Block"})})]}),a&&jsxRuntime.jsx("p",{className:"kyro-form-error",children:a})]})})};function mr(e){if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(mr);if(typeof e=="object"){let t=e,r=Object.keys(t),o="id"in t&&(typeof t.id=="string"||t.id===null),a="url"in t||"filename"in t||"mimeType"in t;if(o&&(a||r.length<=2)&&r.length<=8)return t.id;let n={};for(let s of r)n[s]=mr(t[s]);return n}return e}function kd(){let e=ka.useRef([]),t=ka.useRef(false);return {queueTask:ka.useCallback((o,a)=>{e.current.push(o);async function n(){if(!t.current&&!(typeof a?.beforeProcess=="function"&&a.beforeProcess()===false))for(;e.current.length>0;){let s=e.current.pop();e.current=[],t.current=true;try{await s();}catch(i){console.error("Error in queued function:",i);}finally{t.current=false,typeof a?.afterProcess=="function"&&a.afterProcess();}}}n();},[])}}function hd({config:e,initialData:t,collectionSlug:r,globalSlug:o,documentId:a,onChange:n,onActionSuccess:s,onActionError:i}){let l=Le(),{confirm:d}=ot(),{formData:c,setFormData:m,setField:u,lastSavedData:g,setLastSavedData:x,setHasUnsavedChanges:f,isSlugLocked:y,loadDocument:b,setIsAutoSaving:v,setAutoSaveStatus:R,setVersions:L,setLoadingVersions:C,sidebarCollapsed:w,setSidebarCollapsed:N,getDraftCache:p,setDraftCache:A,clearDraftCache:O,resetForm:F}=l,P=!!e.versions,S=o||t?.id||a||r,M=ka.useRef(false);!o&&S&&c&&Object.keys(c).length>0&&c.id!==S&&(M.current=true),ka.useEffect(()=>{M.current&&(M.current=false,F());},[F]);let j=ka.useRef(null),se=ka.useRef(null),ie=ka.useRef(null),ue=ka.useRef(typeof navigator<"u"?navigator.onLine:true),oe=ka.useRef(0),ne=ka.useRef(false),je=ka.useRef(null),ft=ka.useRef(""),B=ka.useRef(""),{queueTask:K}=kd(),ce=ka.useCallback(q=>o?`global:${o}`:r&&q?`${r}:${q}`:null,[r,o]),he=ka.useCallback((q,X,le)=>{A(q,{data:X,baseUpdatedAt:g.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:le?.lastSyncedAt??null});},[g.updatedAt,A]),Pe=ka.useCallback(async()=>{let q=o?qe(`/api/globals/${o}/versions`):r&&c.id?qe(`/api/${r}/${c.id}/versions`):null;if(q){C(true);try{let le=await(await ct(q)).json();L(le.docs||[]);}catch(X){console.error("Failed to fetch versions:",X);}finally{C(false);}}},[c.id,r,o,C,L]),Ce=ka.useCallback(()=>{let q=Le.getState(),X=q.formData;if(ne.current||!r||!X.id||!q.hasDirtyFields())return;let le=ce(X.id);le&&he(le,X);},[r,ce,he]),I=ka.useCallback(async q=>{let X=Le.getState(),le=X.formData,xe=X.lastSavedData;if(ne.current||!P&&o||!o&&(!r||!le.id)||!X.hasDirtyFields())return;let we=ce(le.id);if(we&&he(we,le),!ue.current){R("offline");return}v(true),R("saving"),X.setBackgroundProcessing(true);try{let Qe=o?qe(`/api/globals/${o}?autosave=true`):qe(`/api/${r}/${le.id}?autosave=true`),Ct=await ct(Qe,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":"true"},keepalive:q?.keepalive,body:JSON.stringify({...mr(le),baseUpdatedAt:xe.updatedAt??null})});if(Ct.ok)oe.current=Date.now(),X.setRetryCount(0),X.setLastSavedAt(Date.now()),ie.current&&clearTimeout(ie.current),we&&A(we,{data:le,baseUpdatedAt:xe.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:(await Ct.clone().json()).data?.updatedAt||new Date().toISOString()}),R("success"),setTimeout(()=>{Le.getState().autoSaveStatus==="success"&&R("idle");},2e3);else if(Ct.status===409)R("conflict");else throw new Error(`Draft auto-save failed with status ${Ct.status}`)}catch(Qe){console.error("Auto-save failed:",Qe);let Ct=Le.getState(),D=Ct.retryCount;if(D<5){Ct.setRetryCount(D+1),R("retrying");let G=Math.min(1e3*Math.pow(2,D),6e4);ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>z(q),G);}else R("offline");}finally{v(false),Le.getState().setBackgroundProcessing(false);}},[r,ce,o,he,R,A,v,P]),z=ka.useCallback(q=>{K(()=>I(q),{beforeProcess:()=>true,afterProcess:()=>{}});},[I,K]),Ve=ka.useCallback(async(q,X=true)=>{let le=Le.getState(),xe=q||le.formData,we=o?qe(`/api/globals/${o}`):qe(`/api/${r}/${xe.id}`),Qe=await ct(we,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":String(X)},body:JSON.stringify({...mr(xe),baseUpdatedAt:le.lastSavedData.updatedAt??null})});return Qe.status===409&&R("conflict"),Qe},[r,o,R]);ka.useEffect(()=>{let q=()=>{N(!w);};return window.addEventListener("toggle-sidebar",q),()=>window.removeEventListener("toggle-sidebar",q)},[w,N]);let ye=ka.useRef(null),Se=ka.useRef(""),lt=ka.useRef(false);ka.useEffect(()=>{let q=o||t?.id,X=JSON.stringify(t);lt.current&&ye.current===q&&Se.current===X||(b(t||{},t||{}),lt.current=true,ye.current=q,Se.current=X);},[r,c.id,o,t,b]),ka.useEffect(()=>{if(!r||!t?.id)return;let q=ce(t.id);if(!q||je.current===q)return;let X=false;return (async()=>{if(!P)return;let xe=p(q);if(xe){if(JSON.stringify(xe.data)===JSON.stringify(t)){O(q);return}je.current=q,d({title:"Restore draft?",message:"A newer autosaved draft was found for this document. Restore it or discard it and continue with the saved version.",confirmLabel:"Restore draft",cancelLabel:"Discard draft",onConfirm:async()=>{if(X)return;let Qe={...Le.getState().formData,...xe.data};m(Qe),s?.("Recovered autosaved draft");},onCancel:async()=>{O(q);}});}})(),()=>{X=true;}},[O,r,d,ce,p,t,s,m,P]);function At(q,X){for(let le of q){if(le.name===X&&le.admin?.autoGenerate==="title")return le;if(le.type==="tabs"&&"tabs"in le)for(let xe of le.tabs){let we=At(xe.fields,X);if(we)return we}if((le.type==="group"||le.type==="collapsible")&&"fields"in le){let xe=At(le.fields,X);if(xe)return xe}}}ka.useEffect(()=>{let q=e.fields;if(!At(q,"metaTitle"))return;let le=uo(q,c,"title"),xe=le?String(le):"";xe&&(!c.metaTitle||c.metaTitle===c._lastMetaTitle)&&u("metaTitle",xe);},[c,e.fields,u]),ka.useEffect(()=>{let q=e.fields,X=q.find(we=>we.name==="slug"&&we.admin?.autoGenerate);if(!X?.admin?.autoGenerate)return;let le=X.admin.autoGenerate,xe=uo(q,c,le);if(y&&xe){let we=Tn(xe);we!==c.slug&&u("slug",we);}},[c,y,e.fields,u]),ka.useEffect(()=>{if(w||!o&&(!r||!c.id)||!Le.getState().hasDirtyFields()||id()!=="keystroke")return;zn("other");let X=JSON.stringify(c);X!==ft.current&&(j.current&&clearTimeout(j.current),j.current=setTimeout(Ce,1500),se.current&&clearTimeout(se.current),se.current=setTimeout(()=>{ft.current=X,z();},8e3));},[c,w,r,o,Ce,z]),ka.useEffect(()=>{if(!o&&(!r||!c.id))return;let q=()=>{ne.current||!Le.getState().hasDirtyFields()||z({keepalive:true});},X=()=>{document.hidden&&q();},le=()=>{ue.current=true,q();},xe=()=>{ue.current=false;let we=Le.getState();we.hasDirtyFields()&&we.setAutoSaveStatus("offline");};return window.addEventListener("blur",q),window.addEventListener("pagehide",q),window.addEventListener("online",le),window.addEventListener("offline",xe),document.addEventListener("visibilitychange",X),()=>{window.removeEventListener("blur",q),window.removeEventListener("pagehide",q),window.removeEventListener("online",le),window.removeEventListener("offline",xe),document.removeEventListener("visibilitychange",X);}},[r,o,c.id,z]),ka.useEffect(()=>{let q=JSON.stringify(c);if(q===B.current)return;B.current=q;let X=document.getElementById("form-data");X&&(X.value=q),n?.(c);},[c,n]),ka.useEffect(()=>{(o||c.id)&&Pe();},[c.id,o,Pe]);let qt=!c.id&&!o?"draft":P&&c.status||"published",vt=(!!c.id||!!o)&&qt==="draft";return {...l,fetchVersions:Pe,performAutoSave:z,saveDocument:Ve,autoSaveSkipRef:ne,lastAutoSaveTimeRef:oe,documentStatus:qt,hasUnpublishedChanges:vt,versionsEnabled:P}}function wo({trigger:e,children:t,align:r="right",direction:o="up"}){let[a,n]=ka.useState(false),s=ka.useRef(null);return ka.useEffect(()=>{let i=l=>{s.current&&!s.current.contains(l.target)&&n(false);};return a&&document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[a]),jsxRuntime.jsxs("div",{className:"relative",ref:s,children:[jsxRuntime.jsx("div",{onClick:()=>n(!a),className:"cursor-pointer",children:e}),a&&jsxRuntime.jsx("div",{className:`absolute z-[100] min-w-[200px] py-2 bg-[var(--kyro-surface)] rounded-2xl shadow-2xl border border-[var(--kyro-border)] animate-in fade-in zoom-in-95 duration-100 ${r==="right"?"right-0":"left-0"} ${o==="down"?"top-full mt-2":"bottom-full mb-2"}`,onClick:()=>n(false),children:t})]})}function Ht({children:e,onClick:t,icon:r,danger:o,disabled:a,className:n=""}){return jsxRuntime.jsx("div",{className:"px-1.5",children:jsxRuntime.jsxs("button",{type:"button",onClick:t,disabled:a,className:`w-full flex items-center gap-3 px-3 py-2.5 text-[11px] font-medium tracking-wide text-left transition-all rounded-xl ${o?"text-red-500 hover:bg-red-500/10":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]"} ${a?"opacity-50 cursor-not-allowed":""} ${n}`,children:[r&&jsxRuntime.jsx("span",{className:"w-4 h-4 opacity-70",children:r}),jsxRuntime.jsx("span",{className:"flex-1",children:e})]})})}function ja(){return jsxRuntime.jsx("div",{className:"my-1 border-t border-[var(--kyro-border)] opacity-50"})}function Co({status:e,saveStatus:t,hasChanges:r,onPublish:o,children:a,disabled:n,direction:s="down"}){let i=e==="published"&&!r&&t!=="saving"&&t!=="error",l=n||t==="saving"||i,d="kyro-btn kyro-btn-sm text-[11px] font-regular tracking-widest transition-all duration-300 rounded-lg",c=()=>t==="saving"?`${d} bg-[var(--kyro-primary)]/70 border-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] cursor-wait`:t==="saved"?`${d} bg-[var(--kyro-success)] border-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)]`:t==="error"?`${d} bg-[var(--kyro-error)] border-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)]`:i?`${d} bg-[var(--kyro-gray-200)] border-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] cursor-not-allowed`:`${d} bg-[var(--kyro-primary)] border-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] hover:bg-[var(--kyro-primary-hover)]`,m="kyro-btn kyro-btn-md px-2 rounded-l-none border-l-[1px] border-white/20 transition-all duration-300",u=()=>t==="saving"?`${m} bg-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)]/70`:t==="saved"?`${m} bg-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-success)]`:t==="error"?`${m} bg-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-error)]`:i?`${m} bg-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] border-[var(--kyro-gray-200)]`:`${m} bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)] hover:bg-[var(--kyro-primary-hover)]`,g=()=>t==="saving"?"Publishing...":t==="saved"?"Published \u2713":t==="error"?"Retry":i?"Published":"Publish Changes";return jsxRuntime.jsxs("div",{className:"inline-flex items-center",children:[jsxRuntime.jsxs("button",{type:"button",onClick:o,disabled:l,className:`${c()} ${a?"":"rounded-r-lg border-r border-[var(--kyro-border)]"}`,children:[t==="saving"&&jsxRuntime.jsx(Ar,{size:"sm",className:"inline mr-1.5"}),i&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"inline mr-1",children:jsxRuntime.jsx("polyline",{points:"20 6 9 17 4 12"})}),g()]}),a&&jsxRuntime.jsx(wo,{trigger:jsxRuntime.jsx("button",{type:"button",className:u(),disabled:t==="saving",children:jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"m6 9 6 6 6-6"})})}),direction:s,children:a})]})}var Cd=({title:e,description:t,slug:r})=>jsxRuntime.jsxs("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg p-6 max-w-2xl shadow-sm transition-colors duration-300",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[jsxRuntime.jsx("div",{className:"w-7 h-7 bg-[var(--kyro-bg-secondary)] rounded-full flex items-center justify-center text-[10px] text-[var(--kyro-text-primary)] font-medium border border-[var(--kyro-border)]",children:"K"}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-tight",children:"kyro-cms.com"}),jsxRuntime.jsxs("span",{className:"text-[12px] text-[var(--kyro-text-secondary)] leading-tight opacity-80",children:["https://kyro-cms.com \u203A posts \u203A ",r]})]})]}),jsxRuntime.jsx("h3",{className:"text-[20px] text-[#2563eb] dark:text-[#60a5fa] font-medium hover:underline cursor-pointer mb-1 leading-tight transition-colors",children:e}),jsxRuntime.jsx("p",{className:"text-[14px] text-[var(--kyro-text-secondary)] leading-relaxed line-clamp-2",children:t})]});function Td({field:e,formData:t,onTabDataChange:r,renderField:o}){let[a,n]=ka.useState(0),s=e.tabs||[],i=s[a]||s[0],l=e.name?t[e.name]||{}:t;return jsxRuntime.jsxs("div",{className:"space-y-8",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-2 border-b border-[var(--kyro-border)] mb-6 overflow-x-auto hide-scrollbar",children:s.map((d,c)=>jsxRuntime.jsx("button",{type:"button",className:`px-6 py-3 text-sm tracking-widest font-medium transition-all border-b-2 -mb-[1px] whitespace-nowrap ${a===c?"border-[var(--kyro-primary)] text-[var(--kyro-primary)]":"border-transparent text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] opacity-60 hover:opacity-100"}`,onClick:()=>n(c),children:d.label},c))}),jsxRuntime.jsx("div",{className:"space-y-6",children:i?.fields.map(d=>o(d,l,r))}),i?.label==="SEO"&&jsxRuntime.jsxs("div",{className:"mt-12 pt-8 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsx("h4",{className:"text-[10px] font-bold text-[var(--kyro-text-secondary)] tracking-[0.2em] mb-6 opacity-50",children:"Live Google Preview"}),jsxRuntime.jsx(Cd,{title:String((typeof l.metaTitle=="object"?"":l.metaTitle)||(typeof l.title=="object"?"":l.title)||"Untitled"),description:String((typeof l.metaDescription=="object"?"":l.metaDescription)||"Please enter a description..."),slug:String((typeof t.slug=="object"?"":t.slug)||"your-slug")})]})]})}function Fd({collectionSlug:e,globalSlug:t,documentStatus:r,hasUnpublishedChanges:o,localSaveStatus:a,handleCreateNew:n,handleDuplicate:s,handleUnpublish:i,handleDelete:l,handlePublish:d,handleSchedulePublish:c}){let[m,u]=ka.useState(Date.now()),[g,x]=ka.useState(false),f=ka.useRef(null),{formData:y,hasUnsavedChanges:b,autoSaveStatus:v,lastSavedAt:R,retryCount:L,view:C,setView:w,showPreview:N,setShowPreview:p,setFormData:A,markSaved:O,lastSavedData:F}=Le(),P=!y.id;ka.useEffect(()=>{let B=setInterval(()=>u(Date.now()),1e4);return ()=>clearInterval(B)},[]),ka.useEffect(()=>{let B=K=>{f.current&&!f.current.contains(K.target)&&x(false);};if(g)return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[g]);let S=String(y.mainTabs?.title||(typeof y.title=="object"?"":y.title)||(typeof y.name=="object"?"":y.name)||"Untitled"),M=y.updatedAt?new Date(y.updatedAt).toLocaleString():"Just now",j=y.createdAt?new Date(y.createdAt).toLocaleString():"Just now",se=o?"Draft (unpublished changes)":r==="published"?"Published":"Draft",ie=o?"Unpublished":r==="published"?"Published":"Draft",ue=r==="published"&&!b?"bg-[var(--kyro-success)]":o?"bg-[var(--kyro-warning)]":"bg-[var(--kyro-text-muted)]",oe=r==="published"&&!o?"bg-[var(--kyro-success)]/10 text-[var(--kyro-success)] border-[var(--kyro-success)]/20":o?"bg-[var(--kyro-warning)]/10 text-[var(--kyro-warning)] border-[var(--kyro-warning)]/20":"bg-[var(--kyro-text-muted)]/10 text-[var(--kyro-text-muted)] border-[var(--kyro-text-muted)]/20",ne=(B=false)=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[v==="saving"&&jsxRuntime.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),B?"Saving\u2026":"Saving draft..."]}),v==="success"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsxRuntime.jsx(lucideReact.Check,{className:"w-3.5 h-3.5 shrink-0"}),B?"Saved":R?`Saved ${Math.floor((Date.now()-R)/6e4)}m ago`:"Draft saved"]}),v==="retrying"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),B?`Retry ${L}/5`:`Retrying save (${L}/5)`]}),v==="offline"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-text-muted)] flex items-center gap-1.5",children:[jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[jsxRuntime.jsx("path",{d:"M10.61 10.61a3 3 0 0 0 4.24 4.24"}),jsxRuntime.jsx("path",{d:"M13.36 13.36a3 3 0 0 0-4.24-4.24"}),jsxRuntime.jsx("path",{d:"m2 2 20 20"}),jsxRuntime.jsx("path",{d:"M18.36 5.64a9 9 0 0 0-12.72 0"}),jsxRuntime.jsx("path",{d:"M22.61 1.39a15 15 0 0 0-21.22 0"})]}),B?"Offline":"Offline \u2014 cached locally"]}),v==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:B?"Failed":"Draft save failed"}),v==="conflict"&&(B?jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict"}):jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict detected"}),jsxRuntime.jsx("span",{className:"opacity-30",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",onClick:async()=>{},className:"text-[var(--kyro-primary)] hover:underline",children:"Keep my changes"}),jsxRuntime.jsx("span",{className:"opacity-30",children:"|"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"text-[var(--kyro-danger)] hover:underline",children:"Reload server version"})]}))]}),je=()=>!P&&jsxRuntime.jsxs(wo,{trigger:jsxRuntime.jsx("button",{type:"button",className:"kyro-btn p-2 md:p-2.5 rounded-xl border border-[var(--kyro-border)] hover:bg-[var(--kyro-bg-secondary)] transition-all",title:"More actions",children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[jsxRuntime.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),jsxRuntime.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})}),direction:"down",children:[!t&&jsxRuntime.jsx(Ht,{onClick:n,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsxRuntime.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),children:"Create New"}),!t&&jsxRuntime.jsx(Ht,{onClick:s,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),children:"Duplicate"}),jsxRuntime.jsx(Ht,{onClick:()=>x(true),icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),jsxRuntime.jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),jsxRuntime.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),jsxRuntime.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),children:"Schedule Publish"}),r==="published"&&jsxRuntime.jsx(Ht,{onClick:i,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),jsxRuntime.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}),children:"Unpublish"}),!t&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ja,{}),jsxRuntime.jsx(Ht,{onClick:l,danger:true,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("polyline",{points:"3 6 5 6 21 6"}),jsxRuntime.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),children:"Delete"})]})]}),ft=()=>g&&jsxRuntime.jsx("div",{ref:f,className:"relative",children:jsxRuntime.jsxs("div",{className:"absolute right-0 top-2 p-4 rounded-lg border border-[var(--kyro-border)] bg-[var(--kyro-surface)] shadow-2xl z-50 min-w-[260px]",children:[jsxRuntime.jsx("p",{className:"text-xs font-medium mb-2",children:"Schedule Publish"}),jsxRuntime.jsx("input",{type:"datetime-local",id:"schedule-datetime",className:"kyro-form-input text-xs mb-3 w-full",min:new Date().toISOString().slice(0,16)}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>x(false),className:"px-3 py-1.5 text-xs kyro-btn rounded-lg",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{let B=document.getElementById("schedule-datetime")?.value;B&&c(B);},className:"px-3 py-1.5 text-xs kyro-btn-success rounded-lg",children:"Schedule"})]})]})});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("header",{className:"md:hidden border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)] backdrop-blur-md rounded-lg",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[jsxRuntime.jsx("a",{href:`${Ye}/${e}`,className:"p-1.5 rounded-lg hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[jsxRuntime.jsx("h1",{className:"text-base font-bold tracking-tight truncate min-w-0",children:S}),jsxRuntime.jsxs("span",{className:`shrink-0 inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[9px] font-medium border ${oe}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ue}`}),ie]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[jsxRuntime.jsx(Co,{status:r,saveStatus:a,hasChanges:b,onPublish:d,disabled:a==="saving"}),je(),ft()]})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-t border-[var(--kyro-border)]/50 bg-[var(--kyro-bg-secondary)]/30",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-0.5 bg-[var(--kyro-bg-secondary)] p-0.5 rounded-lg border border-[var(--kyro-border)]/50",children:["edit","version","api"].map(B=>jsxRuntime.jsx("button",{type:"button",onClick:()=>w(B),className:`px-3 py-1 text-[10px] font-bold rounded-md transition-all ${C===B?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 active:opacity-100"}`,children:B==="edit"?"Edit":B==="version"?"History":"API"},B))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-medium",children:[ne(true),b&&v!=="saving"&&v!=="retrying"&&v!=="conflict"&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{A(F),O();},className:"text-[var(--kyro-primary)] text-[10px] font-medium hover:underline",children:"Revert"}),jsxRuntime.jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>p(!N),className:`p-1.5 rounded-lg transition-all ${N?"bg-[var(--kyro-primary)]/10 text-[var(--kyro-primary)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,children:jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-3.5 h-3.5"})})]})]})]}),jsxRuntime.jsxs("header",{className:"hidden md:flex surface-tile px-8 py-6 items-center justify-between sticky top-0 border-b border-[var(--kyro-border)] mb-8 bg-[var(--kyro-surface)] backdrop-blur-md",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-2 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 flex-wrap min-w-0",children:[jsxRuntime.jsx("a",{href:`${Ye}/${e}`,className:"p-2 border border-[var(--kyro-border)] rounded-xl hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-4 h-4"})}),jsxRuntime.jsx("h1",{className:"text-xl font-bold tracking-tighter truncate min-w-0",children:S}),jsxRuntime.jsxs("span",{className:`shrink-0 inline-flex items-center gap-1.5 px-2 rounded-full text-[10px] font-regular border ${oe}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ue}`}),se]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 text-[11px] font-medium tracking-wide opacity-60 ml-12",children:[ne(false),b&&v!=="saving"&&v!=="retrying"&&v!=="conflict"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"opacity-30",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{A(F),O();},className:"text-[var(--kyro-primary)] hover:underline",children:"Revert changes"})]}),R&&v!=="saving"&&v!=="retrying"&&v!=="success"&&jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Draft saved ",(()=>{let B=m-R,K=Math.floor(B/6e4),ce=Math.floor(B/1e3);return K>=1?`${K}m ago`:ce>=5?`${ce}s ago`:"just now"})()]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Modified ",M]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Created ",j]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-1 bg-[var(--kyro-bg-secondary)] p-1 rounded-xl border border-[var(--kyro-border)]",children:["edit","version","api"].map(B=>jsxRuntime.jsx("button",{type:"button",onClick:()=>w(B),className:`px-5 py-2 text-xs font-bold rounded-lg transition-all ${C===B?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:B.toUpperCase()},B))}),jsxRuntime.jsx("div",{className:"h-8 w-px bg-[var(--kyro-border)] mx-2"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>p(!N),className:`kyro-btn p-2.5 rounded-xl transition-all flex items-center gap-2 ${N?"shadow-lg":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,title:"Live Preview",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-4 h-4"}),N&&jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest pr-1",children:"Active"})]}),je(),ft(),jsxRuntime.jsx(Co,{status:r,saveStatus:a,hasChanges:b,onPublish:d,disabled:a==="saving"})]})]})]})]})}function Pd({config:e,layout:t,collectionSlug:r,renderField:o}){let{showPreview:a,sidebarCollapsed:n,formData:s}=Le();if(t==="single")return jsxRuntime.jsx("div",{className:"w-full space-y-6 md:space-y-8",children:jsxRuntime.jsx("div",{className:"surface-tile p-4 md:p-8 space-y-6 md:space-y-8",children:e.fields.map(d=>o(d))})});let l=e.fields.some(d=>d.admin?.position==="sidebar")&&!a;return jsxRuntime.jsxs("div",{className:`w-full mx-auto grid gap-4 md:gap-8 pb-32 transition-all duration-700 ${a?"grid-cols-1 lg:grid-cols-2":n||!l?"grid-cols-1":"grid-cols-1 lg:grid-cols-[1fr_380px]"}`,children:[jsxRuntime.jsx("div",{className:"space-y-6 md:space-y-8 animate-in fade-in slide-in-from-left-4 duration-500",children:e.tabs?o({type:"tabs",tabs:e.tabs}):jsxRuntime.jsx("div",{className:"surface-tile p-4 md:p-8 space-y-6 md:space-y-8",children:e.fields.filter(d=>!d.admin?.position||d.admin.position==="main").map(d=>o(d))})}),a?jsxRuntime.jsx("div",{className:"sticky top-36 h-[calc(100vh-280px)] animate-in fade-in slide-in-from-right-10 duration-700",children:jsxRuntime.jsxs("div",{className:"w-full h-full rounded-3xl border border-[var(--kyro-border)] bg-[var(--kyro-bg-secondary)] shadow-2xl overflow-hidden relative group",children:[jsxRuntime.jsxs("div",{className:"absolute top-4 left-4 z-10 flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"h-2 w-2 rounded-full bg-green-500 animate-pulse"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest text-white/60",children:"Live Preview Mode"})]}),jsxRuntime.jsx("iframe",{src:`/${r}/${s.slug||s.id}?preview=true`,className:"w-full h-full border-none",title:"Live Preview"}),jsxRuntime.jsx("div",{className:"absolute inset-0 bg-transparent pointer-events-none border-[12px] border-[var(--kyro-surface)] rounded-3xl"})]})}):n?null:jsxRuntime.jsx("div",{className:"space-y-4 md:space-y-6 animate-in fade-in slide-in-from-right-4 duration-500",children:e.fields.some(d=>d.admin?.position==="sidebar")&&jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-6 space-y-4 md:space-y-6",children:[jsxRuntime.jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Settings"}),e.fields.filter(d=>d.admin?.position==="sidebar").map(d=>o(d))]})})]})}function Dd({handleRestoreVersion:e,handleCompareVersions:t,toggleCompareSelection:r}){let{compareMode:o,setCompareMode:a,compareSelected:n,setCompareSelected:s,compareDiffs:i,setCompareDiffs:l,loadingDiffs:d,loadingVersions:c,versions:m}=Le();return jsxRuntime.jsx("div",{className:"w-full animate-in fade-in slide-in-from-bottom-4 pb-12",children:jsxRuntime.jsxs("div",{className:"surface-tile p-0 overflow-hidden",children:[jsxRuntime.jsxs("div",{className:"px-4 md:px-6 py-3 md:py-4 border-b border-[var(--kyro-border)] flex flex-col md:flex-row md:items-center justify-between gap-2",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h2",{className:"text-base md:text-lg font-bold text-[var(--kyro-text-primary)]",children:"Version History"}),jsxRuntime.jsx("p",{className:"text-[11px] text-[var(--kyro-text-muted)] mt-0.5",children:o?`Select 2 versions \xB7 ${n.length}/2 chosen`:`${m.length} snapshot${m.length!==1?"s":""} \xB7 Auto-saved`})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[o&&n.length===2&&jsxRuntime.jsx("button",{type:"button",onClick:t,disabled:d,className:"kyro-btn kyro-btn-primary px-3 py-1.5 rounded-lg text-[11px] font-bold tracking-wider hover:opacity-90 disabled:opacity-50",children:d?"Comparing...":"Compare"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{a(!o),s([]),l([]);},className:`px-3 py-1.5 rounded-lg text-[11px] font-bold tracking-wider transition-all ${o?"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]":"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:o?"Done":"Compare"})]})]}),i.length>0&&jsxRuntime.jsxs("div",{className:"border-b border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("div",{className:"px-6 py-3 flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"text-[11px] font-bold text-[var(--kyro-text-primary)] tracking-wider",children:[i.length," change",i.length!==1?"s":""]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>l([]),className:"p-1 rounded hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-muted)]",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]}),jsxRuntime.jsx("div",{className:"max-h-[400px] overflow-y-auto",children:i.map((u,g)=>jsxRuntime.jsxs("div",{className:"flex flex-col md:grid md:grid-cols-4 gap-1 md:gap-3 px-4 md:px-6 py-2.5 text-[11px] font-mono border-t border-[var(--kyro-border)] hover:bg-[var(--kyro-bg-secondary)]",children:[jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-muted)] truncate font-semibold md:font-normal",children:u.field}),jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-muted)] truncate hidden md:block",children:typeof u.oldValue=="object"?JSON.stringify(u.oldValue):String(u.oldValue??"null")}),jsxRuntime.jsxs("div",{className:"md:col-span-2 text-[var(--kyro-text-primary)] truncate",children:[jsxRuntime.jsx("span",{className:"md:hidden text-[var(--kyro-text-muted)]",children:"\u2192 "}),typeof u.newValue=="object"?JSON.stringify(u.newValue):String(u.newValue??"null")]})]},g))})]}),c?jsxRuntime.jsx("div",{className:"flex justify-center py-16",children:jsxRuntime.jsx("span",{className:"animate-spin text-[var(--kyro-primary)]",children:"\u231B"})}):m.length===0?jsxRuntime.jsx("div",{className:"text-center py-16 text-[var(--kyro-text-muted)] text-sm italic",children:"No versions yet."}):jsxRuntime.jsx("div",{className:"divide-y divide-[var(--kyro-border)]",children:m.map((u,g)=>{let x=n.includes(u.id),f=(u.changeDescription||"").toLowerCase().includes("auto");return jsxRuntime.jsxs("div",{onClick:o?()=>r(u.id):void 0,className:`transition-all ${o?x?"bg-[var(--kyro-primary)]/5 cursor-pointer":"hover:bg-[var(--kyro-bg-secondary)] cursor-pointer":"hover:bg-[var(--kyro-bg-secondary)]"}`,children:[jsxRuntime.jsxs("div",{className:"hidden md:grid grid-cols-12 gap-3 px-6 py-3 items-center",children:[jsxRuntime.jsx("div",{className:"col-span-1 flex items-center gap-2",children:o?jsxRuntime.jsx("div",{className:`w-4 h-4 rounded-full border ${x?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:x&&jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5",children:m.length-g})}),jsxRuntime.jsxs("div",{className:"col-span-4 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-2",children:[u.changeDescription||"Snapshot",f&&jsxRuntime.jsx("span",{className:"text-[9px] px-1.5 py-0.5 bg-[var(--kyro-bg-secondary)] text-[var(--kyro-text-secondary)] rounded font-bold tracking-wider",children:"Auto"})]}),jsxRuntime.jsx("div",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(u.createdAt||u.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),jsxRuntime.jsx("div",{className:"col-span-3",children:u.status&&jsxRuntime.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold capitalize tracking-wider ${u.status==="published"?" text-[var(--kyro-success)]":" text-[var(--kyro-warning)]"}`,children:[jsxRuntime.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${u.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),u.status]})}),jsxRuntime.jsx("div",{className:"col-span-2 text-[11px] text-[var(--kyro-text-muted)]",children:u.createdBy||"system"}),jsxRuntime.jsx("div",{className:"col-span-2 flex justify-end",children:!o&&jsxRuntime.jsx("button",{type:"button",onClick:()=>e(u.id),className:"px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[11px] font-bold tracking-wider text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] transition-all active:scale-95",children:"Restore"})})]}),jsxRuntime.jsxs("div",{className:"md:hidden flex items-start gap-3 px-4 py-3",children:[jsxRuntime.jsx("div",{className:"pt-0.5 shrink-0",children:o?jsxRuntime.jsx("div",{className:`w-4 h-4 rounded-full border ${x?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:x&&jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})}):jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5 inline-block text-center",children:m.length-g})}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-1.5",children:[u.changeDescription||"Snapshot",f&&jsxRuntime.jsx("span",{className:"text-[9px] px-1 py-0.5 bg-[var(--kyro-bg-secondary)] text-[var(--kyro-text-secondary)] rounded font-bold tracking-wider shrink-0",children:"Auto"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[jsxRuntime.jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(u.createdAt||u.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}),u.status&&jsxRuntime.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-bold capitalize tracking-wider ${u.status==="published"?"text-[var(--kyro-success)]":"text-[var(--kyro-warning)]"}`,children:[jsxRuntime.jsx("span",{className:`w-1 h-1 rounded-full ${u.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),u.status]}),jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-muted)] opacity-60",children:u.createdBy||"system"})]})]}),!o&&jsxRuntime.jsx("button",{type:"button",onClick:()=>e(u.id),className:"shrink-0 px-2.5 py-1 rounded-lg border border-[var(--kyro-border)] text-[10px] font-bold tracking-wider text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] transition-all active:scale-95",children:"Restore"})]})]},u.id)})})]})})}function Bd({collectionSlug:e,globalSlug:t}){let{formData:r}=Le();return jsxRuntime.jsx("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4",children:jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_300px] gap-8",children:[jsxRuntime.jsxs("div",{className:"surface-tile p-8 min-w-0",children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold mb-6",children:"Response Payload"}),jsxRuntime.jsx("div",{className:"bg-[#0f172a] p-6 rounded-2xl border border-white/5 overflow-x-auto max-h-[800px]",children:jsxRuntime.jsx("pre",{className:"text-blue-300 text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(r,null,2)})})]}),jsxRuntime.jsx("div",{className:"space-y-6",children:jsxRuntime.jsxs("div",{className:"surface-tile p-8 space-y-6",children:[jsxRuntime.jsx("h2",{className:"text-xl font-bold mb-6",children:"API Info"}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Reference Path"}),jsxRuntime.jsx("div",{className:"bg-[var(--kyro-bg-secondary)] px-4 py-3 rounded-md border border-[var(--kyro-border)] text-[11px] font-mono break-all selection:bg-[var(--kyro-primary)]/20 text-[var(--kyro-text-primary)]",children:t?`kyro.globals('${t}').get()`:r.id?`kyro.collection('${e}').get('${r.id}')`:"Not saved yet"})]}),r.id&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Document ID"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("code",{className:"text-xs font-mono bg-[var(--kyro-bg-secondary)] px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]",children:String(r.id)}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(String(r.id));},className:"p-1.5 hover:bg-[var(--kyro-bg-secondary)] rounded-lg transition-colors text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]",title:"Copy ID",children:jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]}),t&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Global Slug"}),jsxRuntime.jsx("code",{className:"text-xs font-mono bg-[var(--kyro-bg-secondary)] px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]",children:t})]})]})]})})]})})}var Id={};function _a({config:e,data:t=Id,errors:r=Id,onChange:o,disabled:a,collectionSlug:n,globalSlug:s,documentId:i,documentName:l,layout:d="split",onActionSuccess:c,onActionError:m,justSaved:u}){let g=e||(s?jl[s]:n?Ho[n]:null),[x,f]=ka.useState(g);ka.useEffect(()=>{s==="storage-settings"?De("/api/kyro/schema").then(T=>{T?.globals?.["storage-settings"]&&f(T.globals["storage-settings"]);}).catch(T=>console.error("[AutoForm] Failed to fetch dynamic schema",T)):f(g);},[s,g]);let y=x||g,{confirm:b}=ot(),{formData:v,hasUnsavedChanges:L,autoSaveStatus:N,lastSavedAt:p,view:se,setView:ie,setShowPreview:B,isMenuOpen:K,setIsMenuOpen:ce,loadingFields:he,setLoadingFields:Pe,compareSelected:z,setCompareSelected:Ve,setCompareDiffs:Se,setLoadingDiffs:At,setField:qt,setFormData:vt,setLastSavedData:X,setAutoSaveStatus:le,fetchVersions:xe,saveDocument:we,autoSaveSkipRef:Qe,lastAutoSaveTimeRef:Ct,documentStatus:D,hasUnpublishedChanges:G,versionsEnabled:te}=hd({config:y,initialData:t,collectionSlug:n,globalSlug:s,documentId:i,onChange:o,onActionSuccess:c,onActionError:m}),sr=ka.useRef(null),no=ka.useRef(null),[da,Ka]=ka.useState(false),[Zn,gt]=ka.useState("idle"),[h,re]=ka.useState(Date.now()),Re=a,[Jt,Lt]=ka.useState(false),[vr,ir]=ka.useState(false),[es,Cc]=ka.useState(0),ni=ka.useRef(new Map),Sc=3e4;ka.useEffect(()=>{let T=s?`global:${s}`:`${n}:${i}`;if(!(s||n&&i&&i!=="new")||t&&Object.keys(t).length>0)return;let Ne=ni.current.get(T),Te=Ne&&Date.now()-Ne.ts<Sc,bt=Ne&&!Te;if(Te){Le.getState().loadDocument(Ne.data,Ne.data);return}bt&&Le.getState().loadDocument(Ne.data,Ne.data);let xt=new AbortController;ir(false),Ne||Lt(true);let Mt=s?`/api/globals/${s}`:`/api/${n}/${i}`;return De(Mt,{autoToast:false,signal:xt.signal}).then(dt=>{let so=dt.data||{};ni.current.set(T,{data:so,ts:Date.now()}),Le.getState().loadDocument(so,so),Lt(false);}).catch(dt=>{dt.name!=="AbortError"&&(Lt(false),Ne||ir(true));}),()=>xt.abort()},[n,i,s,t,es]),ka.useEffect(()=>{let T=setInterval(()=>re(Date.now()),1e4);return ()=>clearInterval(T)},[]);let si=(T,J)=>{if(typeof T=="function")try{return T(v,J)}catch(Ne){return console.warn("Error evaluating admin runtime flag:",Ne),false}return !!T},Tc=T=>{b({title:"Restore Version",message:"Are you sure you want to restore this version? This will overwrite your current changes.",onConfirm:async()=>{try{let J=s?qe(`/api/globals/${s}/versions/${T}/restore`):qe(`/api/${n}/${v.id}/versions/${T}/restore`),Ne=await ct(J,{method:"POST"});!Ne.ok&&n&&(Ne=await ct(qe(`/api/${n}/${v.id}/versions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({versionId:T,action:"restore"})}));let Te=await Ne.json();if(Te.data){let{updatedAt:bt,createdAt:xt,...Mt}=Te.data,dt={...v,...Mt};vt(dt),Le.getState().loadDocument(dt,dt),c?.("Version restored successfully"),xe(),ie("edit");}else $.error(Te.error||"Failed to restore version");}catch(J){console.error("Failed to restore version:",J),$.error("Failed to restore version");}}});},Ac=async()=>{if(z.length===2){At(true);try{let J=await(await ct(qe(`/api/${n}/${v.id}/versions?compareA=${z[0]}&compareB=${z[1]}`))).json();Se(J.diffs||[]);}catch(T){console.error("Compare failed:",T),Se([]);}finally{At(false);}}},Rc=T=>{Ve(J=>J.includes(T)?J.filter(Ne=>Ne!==T):J.length>=2?[J[1],T]:[...J,T]);};ka.useEffect(()=>{let T=J=>{(J.metaKey||J.ctrlKey)&&J.key==="s"&&(J.preventDefault(),ii()),(J.metaKey||J.ctrlKey)&&J.shiftKey&&(J.key==="P"||J.key==="p")&&(J.preventDefault(),document.getElementById("btn-publish")?.click()),(J.metaKey||J.ctrlKey)&&!J.shiftKey&&J.key==="p"&&(J.preventDefault(),B(Ne=>!Ne)),document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA"&&(J.key==="1"&&ie("edit"),J.key==="2"&&ie("version"),J.key==="3"&&ie("api"));};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]),ka.useEffect(()=>{let T=()=>ie("version");return window.addEventListener("kyro:show-version-history",T),()=>window.removeEventListener("kyro:show-version-history",T)},[]),ka.useEffect(()=>{let T=J=>{sr.current&&!sr.current.contains(J.target)&&ce(false);};if(K)return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[K]),ka.useEffect(()=>{let T=J=>{no.current&&!no.current.contains(J.target)&&Ka(false);};if(da)return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[da]);let Fc=()=>{L?b({title:"Unsaved Changes",message:"You have unsaved changes. Save before creating new?",onConfirm:async()=>{await ii(),await new Promise(T=>setTimeout(T,1e3)),window.location.href=`${Ye}/${n}/new`;}}):window.location.href=`${Ye}/${n}/new`;},Pc=()=>{b({title:"Duplicate Document",message:"Are you sure you want to duplicate this document?",onConfirm:async()=>{try{let{id:T,createdAt:J,updatedAt:Ne,...Te}=v,bt=mr(Te),xt=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...bt,title:`${Te.title||Te.name||"Copy"} (Copy)`,slug:`${Te.slug||"copy"}-${Date.now()}`,status:"draft"})});if(xt.ok){let Mt=await xt.json();c?.("Document duplicated successfully"),Mt.data?.id&&(window.location.href=`${Ye}/${n}/${Mt.data.id}`);}else {let Mt=await xt.json();$.error(Mt.error||"Failed to duplicate document");}}catch{$.error("Failed to duplicate document");}}});},Dc=()=>{b({title:"Delete Document",message:"Delete this document? This cannot be undone. Are you absolutely sure?",variant:"danger",onConfirm:async()=>{try{await kt(`/api/${n}/${v.id}`),window.location.href=`${Ye}/${n}`;}catch(T){$.error(T.message||"Failed to delete document");}}});},Bc=()=>{b({title:"Unpublish Document",message:"Unpublish this document?",onConfirm:async()=>{try{let T=await we({...v,status:"draft"},!1);if(T?.ok)c?.("Document unpublished successfully"),Le.getState().loadDocument({...v,status:"draft"},{...v,status:"draft"});else {let J=await T?.json().catch(()=>({}));$.error(J?.error||"Failed to unpublish");}}catch{$.error("Failed to unpublish");}}});},ii=async()=>{let T=!v.id;Qe.current=true,gt("saving");try{let J=mr({...v}),Ne=T&&!s,Te=Ne?await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J)}):await we(J);if(Te.ok){let xt=(await Te.json()).data||J;vt({...v,...xt}),X({...v,...xt}),Ct.current=Date.now(),le("success"),gt("saved"),te&&xe(),setTimeout(()=>{le("idle"),gt("idle");},2e3),c?.(Ne?"Document created successfully":"Changes saved"),Ne&&setTimeout(()=>{window.location.href=`${Ye}/${n}`;},800);}else {let bt=await Te.json();Te.status===409&&le("conflict"),gt("error"),$.error(bt.error||"Failed to save"),setTimeout(()=>gt("idle"),3e3);}}catch{gt("error"),$.error("Failed to save document"),setTimeout(()=>gt("idle"),3e3);}finally{Qe.current=false;}},Ic=async()=>{let T=!v.id;Qe.current=true,gt("saving");try{let J={...v};if(T&&!s){let bt=mr({...v}),xt=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(bt)});if(!xt.ok){let so=await xt.json().catch(()=>({}));xt.status===409&&le("conflict"),gt("error"),$.error(so.error||"Failed to create document"),setTimeout(()=>gt("idle"),3e3);return}let dt=(await xt.json()).data||bt;vt({...v,...dt}),X({...v,...dt}),J={...v,...dt};}let Ne=mr(J),Te=await we(Ne,!1);if(Te?.ok)gt("saved"),c?.("Published successfully");else {let bt=await Te?.json().catch(()=>({}));Te?.status===409&&le("conflict"),gt("error"),$.error(bt?.error||"Failed to publish"),setTimeout(()=>gt("idle"),3e3);}}catch{gt("error"),$.error("Failed to publish"),setTimeout(()=>gt("idle"),3e3);}finally{Qe.current=false;}},Lc=async T=>{let J=!v.id;Qe.current=true;try{let Ne={...mr({...v}),_schedulePublishAt:T};if(J&&!s){let Te=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Ne)});if(!Te.ok){let bt=await Te.json().catch(()=>({}));$.error(bt.error||"Failed to schedule publish");return}}else {let Te=await we(Ne);if(!Te.ok){let bt=await Te.json().catch(()=>({}));$.error(bt.error||"Failed to schedule publish");return}}c?.(`Scheduled publish for ${new Date(T).toLocaleString()}`),Ka(!1);}catch{$.error("Failed to schedule publish");}finally{Qe.current=false;}},Mc=(T,J)=>{qt(T,J);},ca=(T,J,Ne)=>{let Te=J!==void 0?J:v;if(si(T.hidden!==void 0?T.hidden:T.admin?.hidden,Te))return null;let xt=si(T.readOnly!==void 0?T.readOnly:T.admin?.readOnly,Te),Mt=!!(Re||xt);if(T.admin?.condition){if(typeof T.admin.condition=="function")try{let Me={values:v||{},...v||{}};if(!T.admin.condition(Me,Te))return null}catch(Me){console.warn(`Condition error for field ${T.name}:`,Me);}else if(typeof T.admin.condition=="object")try{let Me=T.admin.condition,Ue=Me.field,Vt=Te&&Te[Ue]!==void 0?Te[Ue]:v&&v[Ue]!==void 0?v[Ue]:void 0,Cr=!0;if("equals"in Me?Cr=Vt===Me.equals:"notEquals"in Me?Cr=Vt!==Me.notEquals:"in"in Me&&Array.isArray(Me.in)&&(Cr=Me.in.includes(Vt)),!Cr)return null}catch(Me){console.warn(`Declarative condition error for field ${T.name}:`,Me);}}let dt=Te[T.name],so=r[T.name],Ga=Me=>{Ne?Ne({...Te,[T.name]:Me}):Mc(T.name,Me);};if(T.type==="row"&&"fields"in T){let Me=T.fields;return jsxRuntime.jsx("div",{className:"kyro-form-row flex flex-col md:flex-row gap-4 md:gap-6 items-start md:items-end w-full",children:Me?.map(Ue=>{let Vt=Ue.admin||{},Cr=Vt?.action;if((Ue.type==="button"||Ue.type==="action")&&Cr){let gr=Me?.find(pa=>pa.type==="email");return jsxRuntime.jsx("div",{className:"flex-shrink-0",children:jsxRuntime.jsx("button",{type:"button",onClick:async()=>{let pa=T.name,Wa=gr?.name,qa=Wa?v[Wa]:void 0;if(!qa&&pa&&typeof pa=="string"&&Wa&&(qa=v[pa]?.[Wa]),!!qa){Pe(br=>({...br,[Ue.name]:true}));try{let br=await ct(qe(Cr),{method:Vt.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:qa})}),ma={};try{ma=await br.json();}catch{ma={};}if(br.ok&&ma.success)c?.(ma.message||"Action completed successfully");else {let $c=ma.error||`Request failed (${br.status})`;m?.($c);}}catch(br){m?.(br instanceof Error?br.message:"Error connecting to server");}finally{Pe(br=>({...br,[Ue.name]:false}));}}},disabled:he[Ue.name]||Mt,className:"kyro-btn kyro-btn-primary px-4 py-2 rounded-lg font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:he[Ue.name]?"Sending...":Ue.label||"Click"})},Ue.name)}return jsxRuntime.jsx("div",{className:Ue.type==="button"||Ue.type==="action"?"flex-shrink-0":"flex-1",style:Vt?.width?{width:Vt.width,flex:"none"}:{},children:ca(Ue,J,Ne)},Ue.name)})},T.name||`row-${Math.random()}`)}switch(T.type){case "tabs":return jsxRuntime.jsx(Td,{field:T,formData:v,onTabDataChange:Me=>{qt(T.name,Me);},renderField:(Me,Ue,Vt)=>ca(Me,Ue,Vt)},T.name||`tabs-${Math.random()}`);case "group":return jsxRuntime.jsx(On,{field:T,value:dt,onChange:Ga,renderField:ca},T.name);case "array":return jsxRuntime.jsx(Un,{field:T,value:dt,onChange:Ga,renderField:ca,disabled:Mt},T.name);case "button":case "action":{let Me=T.name,Ue=he[Me];return jsxRuntime.jsx("div",{className:"kyro-form-field",children:jsxRuntime.jsxs("button",{type:"button",disabled:Ue||Mt,onClick:async()=>{let Vt=T.admin?.action||T.action,Cr=T.admin?.method||T.method||"POST";if(Vt){Pe(gr=>({...gr,[Me]:true}));try{let gr=await ct(Vt,{method:Cr,headers:{"Content-Type":"application/json"},body:JSON.stringify(v)});await gr.json(),gr.ok;}catch(gr){console.error("Error executing action:",gr);}finally{Pe(gr=>({...gr,[Me]:false}));}}},className:`kyro-btn kyro-btn-md kyro-btn-secondary transition-all active:scale-95 whitespace-nowrap flex items-center gap-2 ${Ue?"opacity-70 cursor-not-allowed":""}`,children:[Ue&&jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),Ue?"Processing...":T.label||"Click"]})},Me)}case "relationship-block":return jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[T.label||T.name,T.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsx(Ua,{relationTo:T.relationTo,hasMany:T.hasMany,selectedIds:Array.isArray(dt)?dt:dt?[dt]:[],onChange:(Me,Ue)=>{Ga(Ue);},compact:true}),T.admin?.description?jsxRuntime.jsx("p",{className:"kyro-form-help",children:String(T.admin?.description)}):null]},T.name);default:return jsxRuntime.jsx(xo,{field:T,value:dt,onChange:Ga,error:so,disabled:Mt},T.name||Math.random().toString())}};return Jt?jsxRuntime.jsxs("div",{className:"space-y-6 p-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Ot,{variant:"text",className:"w-1/3"}),jsxRuntime.jsx(Ot,{variant:"text",className:"w-2/3"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Ot,{variant:"rect",count:4})})]}):vr?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-16",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-8 h-8 text-[var(--kyro-danger)]"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)]",children:"Failed to load document. Check your connection."}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{ir(false),Lt(true),Cc(T=>T+1);},className:"kyro-btn kyro-btn-primary px-6 py-2 rounded-xl text-sm font-bold",children:"Retry"})]}):jsxRuntime.jsxs("div",{className:"flex flex-col h-full",children:[d!=="single"&&jsxRuntime.jsx(Fd,{collectionSlug:n,globalSlug:s,documentStatus:D||"draft",hasUnpublishedChanges:G,localSaveStatus:Zn,handleCreateNew:Fc,handleDuplicate:Pc,handleUnpublish:Bc,handleDelete:Dc,handlePublish:Ic,handleSchedulePublish:Lc}),d==="single"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 text-[11px] font-medium",children:[N==="saving"&&jsxRuntime.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Saving..."]}),N==="success"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"}),p?`Saved ${Math.floor((Date.now()-p)/6e4)}m ago`:"Saved"]}),N==="retrying"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Retrying..."]}),N==="offline"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]",children:"Offline \u2014 cached locally"}),N==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Save failed"}),N==="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Conflict detected"}),L&&N!=="saving"&&N!=="retrying"&&N!=="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-warning)]",children:"Unsaved changes"}),!L&&N!=="success"&&N!=="saving"&&N!=="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-success)]",children:"All changes saved"})]}),jsxRuntime.jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)] opacity-60",children:v.updatedAt?`Modified ${new Date(v.updatedAt).toLocaleString()}`:""})]}),jsxRuntime.jsx("button",{id:"btn-save",type:"button",style:{width:0,height:0,opacity:0,padding:0,margin:0,border:"none",position:"absolute"},onClick:async()=>{try{let T=await we(v);if(T.ok){let Ne=(await T.json()).data||v;vt({...v,...Ne}),X({...v,...Ne}),c?.("Changes saved");}}catch(T){console.error("Save error exception:",T),m?.("Save failed: "+T.message);}}})]}),jsxRuntime.jsxs("main",{className:"w-full pt-6 md:pt-0",children:[se==="edit"&&jsxRuntime.jsx(Pd,{config:y,layout:d,collectionSlug:n,renderField:ca}),se==="version"&&jsxRuntime.jsx(Dd,{handleRestoreVersion:Tc,handleCompareVersions:Ac,toggleCompareSelection:Rc}),se==="api"&&jsxRuntime.jsx(Bd,{collectionSlug:n,globalSlug:s})]})]})}var Ld={draft:"bg-[var(--kyro-warning)]",published:"bg-[var(--kyro-success)]",scheduled:"bg-[var(--kyro-primary)]",archived:"bg-[var(--kyro-text-muted)]"};function Qs({status:e,saveStatus:t,hasChanges:r,onSave:o,onPublish:a,onUnpublish:n,onDuplicate:s,onViewHistory:i,onPreview:l,onDelete:d,onBack:c,onToggleSidebar:m,publishedAt:u,updatedAt:g}){let x=Le(N=>N.view)||"edit",f=Le(N=>N.setView),[y,b]=ka.useState(false),v=ka.useRef(null);ka.useEffect(()=>{let N=p=>{v.current&&!v.current.contains(p.target)&&b(false);};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);let R=()=>t==="saving"?"Saving...":t==="saved"?"Saved":t==="error"?"Error saving":r?"Unsaved":null,L=["edit","version","api"],C=R(),w="p-1.5 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] transition-all shrink-0";return jsxRuntime.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 bg-[var(--kyro-surface)] border-b border-[var(--kyro-border)] w-full overflow-x-auto",children:[c&&jsxRuntime.jsx("button",{type:"button",onClick:c,className:"p-1 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] transition-all shrink-0",children:jsxRuntime.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsxRuntime.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),jsxRuntime.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${Ld[e]||"bg-[var(--kyro-text-muted)]"}`}),C&&jsxRuntime.jsxs("span",{className:`text-[10px] whitespace-nowrap max-md:hidden ${t==="error"?"text-[var(--kyro-error)]":"text-[var(--kyro-text-muted)]"}`,children:[t==="saving"&&jsxRuntime.jsx(Ar,{size:"sm",className:"inline mr-0.5"}),C]}),jsxRuntime.jsx("div",{className:"flex items-center gap-0.5 bg-[var(--kyro-bg-secondary)] p-0.5 rounded-lg border border-[var(--kyro-border)] shrink-0 max-md:hidden",children:L.map(N=>jsxRuntime.jsx("button",{type:"button",onClick:()=>f(N),className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all ${x===N?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:N==="edit"?"Edit":N==="version"?"Ver":"API"},N))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1 ml-auto shrink-0",children:[l&&jsxRuntime.jsx("button",{type:"button",onClick:l,className:`${w} max-md:hidden`,title:"Preview",children:jsxRuntime.jsx(lucideReact.Eye,{className:"w-3.5 h-3.5"})}),i&&jsxRuntime.jsx("button",{type:"button",onClick:i,className:`${w} max-md:hidden`,title:"View History",children:jsxRuntime.jsx(lucideReact.Clock,{className:"w-3.5 h-3.5"})}),s&&jsxRuntime.jsx("button",{type:"button",onClick:s,className:`${w} max-md:hidden`,title:"Duplicate",children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})}),d&&jsxRuntime.jsx("button",{type:"button",onClick:d,className:`${w} hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] max-md:hidden`,title:"Delete",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})}),m&&jsxRuntime.jsx("button",{type:"button",onClick:m,className:`${w} max-md:hidden`,title:"Toggle Sidebar",children:jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),jsxRuntime.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsxRuntime.jsxs("div",{ref:v,className:"relative md:hidden",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>b(!y),className:w,title:"More",children:jsxRuntime.jsx(lucideReact.EllipsisVertical,{className:"w-3.5 h-3.5"})}),y&&jsxRuntime.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 py-1 max-h-[70vh] overflow-y-auto",children:[C&&jsxRuntime.jsxs("div",{className:"px-3 py-2 text-[10px] text-[var(--kyro-text-muted)] border-b border-[var(--kyro-border)] flex items-center gap-1.5",children:[jsxRuntime.jsx("div",{className:`w-1.5 h-1.5 rounded-full ${Ld[e]}`}),jsxRuntime.jsx("span",{className:"capitalize",children:e}),jsxRuntime.jsx("span",{children:"\xB7"}),t==="saving"&&jsxRuntime.jsx(Ar,{size:"sm",className:"inline"}),jsxRuntime.jsx("span",{children:C})]}),jsxRuntime.jsx("div",{className:"flex gap-1 px-2 py-2 border-b border-[var(--kyro-border)]",children:L.map(N=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{f(N),b(false);},className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all flex-1 ${x===N?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)]"}`,children:N==="edit"?"Edit":N==="version"?"Ver":"API"},N))}),i&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{i(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3.5 h-3.5"})," View History"]}),s&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{s(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5"})," Duplicate"]}),l&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{l(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Eye,{className:"w-3.5 h-3.5"})," Preview"]}),d&&jsxRuntime.jsx("div",{className:"border-t border-[var(--kyro-border)] mt-1 pt-1",children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>{d(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-danger)] hover:bg-[var(--kyro-danger-bg)] transition-colors",children:[jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})," Delete"]})})]})]}),jsxRuntime.jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),e==="draft"&&a&&jsxRuntime.jsxs("button",{type:"button",onClick:a,disabled:t==="saving",className:"kyro-btn kyro-btn-primary kyro-btn-sm flex items-center gap-1 shrink-0",children:[jsxRuntime.jsx(lucideReact.Send,{className:"w-3.5 h-3.5"}),jsxRuntime.jsx("span",{className:"max-md:hidden",children:"Publish"})]}),e==="published"&&n&&jsxRuntime.jsxs("button",{type:"button",onClick:n,disabled:t==="saving",className:"kyro-btn kyro-btn-secondary kyro-btn-sm flex items-center gap-1 shrink-0",children:[jsxRuntime.jsx(lucideReact.Undo,{className:"w-3.5 h-3.5"}),jsxRuntime.jsx("span",{className:"max-md:hidden",children:"Unpublish"})]}),jsxRuntime.jsxs(Co,{status:e,saveStatus:t,hasChanges:r,onPublish:o,children:[s&&jsxRuntime.jsx(Ht,{icon:jsxRuntime.jsx(lucideReact.Copy,{className:"w-4 h-4"}),children:"Duplicate"}),i&&jsxRuntime.jsx(Ht,{icon:jsxRuntime.jsx(lucideReact.Clock,{className:"w-4 h-4"}),children:"View History"}),l&&jsxRuntime.jsx(Ht,{icon:jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"}),children:"Preview"}),(s||i||l)&&jsxRuntime.jsx(ja,{}),d&&jsxRuntime.jsx(Ht,{onClick:d,danger:true,icon:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"}),children:"Delete"})]})]})]})}function Zs({config:e,collection:t,global:r,documentId:o,onBack:a,onSave:n,onDelete:s,onError:i,mode:l="collection"}){let{confirm:d,alert:c}=ot(),[m,u]=ka.useState({}),[g,x]=ka.useState({}),[f,y]=ka.useState(true),[b,v]=ka.useState(false),[R,L]=ka.useState("idle"),[C,w]=ka.useState(false),[N,p]=ka.useState("draft"),[A,O]=ka.useState(null),[F,P]=ka.useState(null),[S,M]=ka.useState(null),[j,se]=ka.useState(false),ie=r?.fields||t?.fields||[],ue=r?.label||t?.label||"Document",oe=r?.slug||t?.slug||"",ne=JSON.stringify(m)!==JSON.stringify(g);ka.useEffect(()=>{ne&&N==="published"&&p("draft");},[ne,N]),ka.useEffect(()=>{ne&&R==="saved"&&L("idle");},[ne,R]),ka.useEffect(()=>{l==="global"?ft():o&&je();},[o,l,oe]);let je=async()=>{try{y(!0);let I=await De(`/api/${oe}/${o}`,{autoToast:!1}),z=I.data||{};u(z),x(z),p(z?.status||I.status||"draft"),O(I.createdAt||z.createdAt||null),P(I.updatedAt||z.updatedAt||null),M(I.publishedAt||z.publishedAt||null);}catch{i("Failed to load document");}finally{y(false);}},ft=async()=>{try{y(!0);let I=await De(`/api/globals/${oe}`,{autoToast:!1}),z=I.data||{};u(z),x(z),O(I.createdAt||null),P(I.updatedAt||null);}catch{i("Failed to load global");}finally{y(false);}},B=ka.useCallback(async(I=false)=>{try{L("saving");let z=l==="global"?`/api/globals/${oe}`:`/api/${oe}/${o}`,Ve=N==="draft"||m?.status==="draft",ye=await Xt(z,m,{autoToast:!1,headers:{"X-Draft":String(Ve)}}),Se=ye&&(ye.data||ye)||m;I||(x(Se),n()),u(Se),p(Se?.status||N),L("saved"),P(new Date().toISOString()),se(!0),setTimeout(()=>se(!1),3e3),I||(N==="draft"||Se?.status==="draft"?$.warning("Draft saved"):$.success("Updated")),setTimeout(()=>{L("idle");},2e3);}catch{L("error"),I||(i("Failed to save changes"),$.error("Failed to save changes"));}finally{v(false);}},[m,l,oe,o,N,n,i]),K=async()=>{try{v(!0),await Xt(`/api/${oe}/${o}`,m,{autoToast:!1,headers:{"X-Draft":"false"}}),p("published"),M(new Date().toISOString()),$.success("Published successfully"),n();}catch{i("Failed to publish"),$.error("Failed to publish");}finally{v(false);}},ce=async()=>{try{v(!0),await Xt(`/api/${oe}/${o}`,{status:"draft"},{autoToast:!1,headers:{"X-Draft":"false"}}),p("draft"),$.warning("Document unpublished"),n();}catch{i("Failed to unpublish"),$.error("Failed to unpublish");}finally{v(false);}},he=async()=>{try{v(!0),await et(`/api/${oe}/${o}/duplicate`,void 0,{autoToast:!1}),$.success("Document duplicated");}catch(I){let z=I instanceof Error?I.message:"Failed to duplicate document";i(z),$.error(z);}finally{v(false);}},Pe=()=>{d({title:`Delete ${ue}?`,message:"This action cannot be undone.",variant:"danger",onConfirm:async()=>{try{w(!0),await kt(`/api/${oe}/${o}`,{autoToast:!1}),s?.(),$.error("Document deleted");}catch(I){let z=I instanceof Error?I.message:"Failed to delete document";$.error(z);}finally{w(false);}}});};if(f)return jsxRuntime.jsx("div",{className:"kyro-detail",children:jsxRuntime.jsxs("div",{className:"space-y-6 p-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Ot,{variant:"text",className:"w-1/3"}),jsxRuntime.jsx(Ot,{variant:"text",className:"w-2/3"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Ot,{variant:"rect",count:4})})]})});let Ce=l==="global"||t?.admin?.layout==="single";return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Ft,{back:{onClick:a},breadcrumbs:[{label:l==="global"?"Globals":"Collections"},{label:ue,href:l==="collection"?`${Ye}/${oe}`:void 0},{label:l==="global"||o?"Edit":"New"}],title:l==="global"?ue:uo(t?.fields,m,t?.admin?.useAsTitle||"title")||m.name||o||`New ${t?.singularLabel||ue}`,metadata:[jsxRuntime.jsx(Pt,{variant:N==="published"?"success":"warning",dot:true,className:"text-[10px] font-bold ",children:N},"status")]}),jsxRuntime.jsx(Qs,{status:N,saveStatus:R,hasChanges:ne,onSave:()=>B(false),onPublish:K,onUnpublish:N==="published"?ce:void 0,onDuplicate:he,onViewHistory:()=>{window.dispatchEvent(new CustomEvent("kyro:show-version-history"));},onPreview:()=>window.open(`/preview/${oe}/${o}`,"_blank"),onDelete:Pe,onBack:a,onToggleSidebar:()=>window.dispatchEvent(new CustomEvent("toggle-sidebar")),publishedAt:S,updatedAt:F}),jsxRuntime.jsxs("div",{className:Ce?"w-full pt-4 md:pt-8":"w-full mx-auto grid grid-cols-1 lg:grid-cols-[1fr_360px] gap-4 md:gap-8 pt-4 md:pt-0",children:[jsxRuntime.jsx("div",{className:"space-y-4 md:space-y-8 min-w-0",children:jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-8 px-1",children:[jsxRuntime.jsx("h2",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Core Configuration"}),jsxRuntime.jsx("div",{className:"h-px flex-1 bg-[var(--kyro-border)] ml-6 opacity-30"})]}),jsxRuntime.jsx(_a,{config:t?{...t,fields:ie}:{slug:"unknown",fields:ie},data:m,onChange:u,layout:Ce?"single":"split",globalSlug:l==="global"?oe:void 0,collectionSlug:l==="collection"?oe:void 0,onActionSuccess:I=>$.success(I),onActionError:I=>$.error(I),documentStatus:N,justSaved:j}),Ce&&jsxRuntime.jsxs("div",{className:"mt-8 pt-8 border-t border-[var(--kyro-border)] flex justify-end gap-3",children:[l==="collection"&&o&&jsxRuntime.jsx("button",{type:"button",onClick:Pe,className:"kyro-btn kyro-btn-lg kyro-btn-ghost text-[var(--kyro-error)]",children:"Delete"}),jsxRuntime.jsx(Co,{status:N,saveStatus:b?"saving":"idle",hasChanges:ne,onPublish:()=>B(false),disabled:b})]})]})}),!Ce&&jsxRuntime.jsxs("div",{className:"space-y-4 md:space-y-6 animate-in fade-in slide-in-from-right-4 duration-500",children:[jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsxRuntime.jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4 md:mb-6",children:"Metadata"}),jsxRuntime.jsxs("div",{className:"space-y-4 md:space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Dynamic Status"}),jsxRuntime.jsx("div",{children:jsxRuntime.jsx("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-[9px] font-bold tracking-widest ${N==="published"?"bg-green-500/10 text-green-500":"bg-amber-500/10 text-amber-500"}`,children:N||"draft"})})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Date Created"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:A?new Date(A).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"N/A"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Last Modified"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:F?new Date(F).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"Just now"})]}),S&&jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Public At"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:new Date(S).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"})})]})]})]}),jsxRuntime.jsxs("div",{className:"surface-tile p-4 md:p-8 bg-[var(--kyro-bg-secondary)]",children:[jsxRuntime.jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-3 md:mb-4",children:"Quick Links"}),jsxRuntime.jsxs("div",{className:"space-y-2 md:space-y-3",children:[jsxRuntime.jsx("button",{type:"button",onClick:he,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"Duplicate Document"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(`/preview/${oe}/${o}`,"_blank"),className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"View Public Page"}),jsxRuntime.jsx("button",{type:"button",onClick:Pe,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start text-[var(--kyro-error)] hover:bg-[var(--kyro-danger-bg)]",children:"Delete Entry"})]})]})]})]})]})}function ei({config:e,collection:t,onCancel:r,onSuccess:o,onError:a}){let[n,s]=ka.useState({}),[i,l]=ka.useState(false),d=t.fields||[],c=t.label||t.slug,m=async u=>{try{l(!0),await et(`/api/${t.slug}`,n),$.success(`${t.singularLabel||t.label||"Document"} created`),o();}catch(g){a(g instanceof Error?g.message:"Failed to create");}finally{l(false);}};return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Ft,{back:{onClick:r},breadcrumbs:[{label:"Collections"},{label:c,href:`${Ye}/${t.slug}`},{label:"New"}],title:`Create ${t.singularLabel||c}`,action:{label:i?"Creating...":`Create ${t.singularLabel||c}`,onClick:()=>m()}}),jsxRuntime.jsx("div",{className:"kyro-detail-body",children:jsxRuntime.jsx("div",{className:"kyro-card",children:jsxRuntime.jsx("div",{className:"kyro-card-content",children:jsxRuntime.jsx("form",{children:jsxRuntime.jsx(_a,{config:{...t,fields:d},data:n,onChange:s})})})})})]})}function $d({type:e,message:t,onClose:r}){let[o,a]=ka__default.default.useState(false),n=ka__default.default.useRef(null),s=()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(r,5e3);},i=()=>{n.current&&clearTimeout(n.current);};ka__default.default.useEffect(()=>(o?i():s(),i),[o,r]);let l={success:lucideReact.CircleCheck,error:lucideReact.ShieldAlert,warning:lucideReact.TriangleAlert,info:lucideReact.Info}[e];return jsxRuntime.jsxs("div",{className:`kyro-toast kyro-toast-${e} group animate-in fade-in slide-in-from-right-4 duration-300`,onMouseEnter:()=>a(true),onMouseLeave:()=>a(false),children:[jsxRuntime.jsx("div",{className:"kyro-toast-accent"}),jsxRuntime.jsx("div",{className:"kyro-toast-icon-container",children:jsxRuntime.jsx(l,{className:"w-4 h-4"})}),jsxRuntime.jsx("div",{className:"kyro-toast-content",children:jsxRuntime.jsx("p",{className:"kyro-toast-message",children:t})}),jsxRuntime.jsx("button",{type:"button",className:"kyro-toast-close group-hover:opacity-100 opacity-40 transition-opacity",onClick:r,children:jsxRuntime.jsx(lucideReact.X,{className:"w-3.5 h-3.5"})})]})}function B4({children:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function I4(){let e=Kt(o=>o.addToast),t=Kt(o=>o.removeToast);return {toasts:Kt(o=>o.toasts),addToast:e,removeToast:t}}function Gn(){let e=Kt(r=>r.toasts),t=Kt(r=>r.removeToast);return jsxRuntime.jsx("div",{className:"kyro-toasts-container",style:{position:"fixed",bottom:"24px",right:"24px",display:"flex",flexDirection:"column",gap:"12px",zIndex:9999,pointerEvents:"none"},children:e.map(r=>jsxRuntime.jsx("div",{style:{pointerEvents:"auto"},children:jsxRuntime.jsx($d,{type:r.type,message:r.message,onClose:()=>t(r.id)})},r.id))})}function oi({onAuth:e,theme:t="light"}){let[r,o]=ka.useState("login"),[a,n]=ka.useState(""),[s,i]=ka.useState(""),[l,d]=ka.useState(""),[c,m]=ka.useState(false),[u,g]=ka.useState(false),x=Kt(b=>b.addToast);ka.useEffect(()=>{f();},[]);let f=async()=>{try{await De("/api/users");}catch{g(true),o("register");}};return jsxRuntime.jsx(kr,{defaultMode:t,children:jsxRuntime.jsxs("div",{className:"kyro-login-page",children:[jsxRuntime.jsxs("div",{className:"kyro-login-container",children:[jsxRuntime.jsxs("div",{className:"kyro-login-header",children:[jsxRuntime.jsx("h1",{className:"kyro-login-title",children:u?"Create Admin Account":r==="login"?"Sign In":"Create Account"}),jsxRuntime.jsx("p",{className:"kyro-login-subtitle",children:u?"Set up your admin account to get started":r==="login"?"Enter your credentials to access the admin":"Create an account to access the admin"})]}),jsxRuntime.jsxs("form",{onSubmit:async b=>{b.preventDefault(),m(true);try{let v=r==="login"?"/api/auth/login":"/api/auth/register",R={email:a,password:s};r==="register"&&(R.confirmPassword=l);let L=await et(v,R);L.isFirstUser&&g(!0),localStorage.setItem("kyro_user",JSON.stringify(L.user)),x("success",r==="login"?"Welcome back!":"Account created!"),e(L.token,L.user);}catch{x("error","Connection failed");}finally{m(false);}},className:"kyro-login-form",children:[jsxRuntime.jsxs("div",{className:"kyro-form-group",children:[jsxRuntime.jsx("label",{htmlFor:"email",children:"Email"}),jsxRuntime.jsx("input",{id:"email",type:"email",value:a,onChange:b=>n(b.target.value),placeholder:"admin@example.com",required:true,autoComplete:"email"})]}),jsxRuntime.jsxs("div",{className:"kyro-form-group",children:[jsxRuntime.jsx("label",{htmlFor:"password",children:"Password"}),jsxRuntime.jsx("input",{id:"password",type:"password",value:s,onChange:b=>i(b.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:r==="login"?"current-password":"new-password"})]}),r==="register"&&jsxRuntime.jsxs("div",{className:"kyro-form-group",children:[jsxRuntime.jsx("label",{htmlFor:"confirmPassword",children:"Confirm Password"}),jsxRuntime.jsx("input",{id:"confirmPassword",type:"password",value:l,onChange:b=>d(b.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:"new-password"})]}),jsxRuntime.jsx("button",{type:"submit",className:"kyro-btn kyro-btn-primary kyro-btn-lg",disabled:c,children:c?r==="login"?"Signing in...":"Creating account...":r==="login"?"Sign In":"Create Account"})]}),!u&&jsxRuntime.jsx("div",{className:"kyro-login-footer",children:jsxRuntime.jsx("p",{children:r==="login"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Don't have an account?"," ",jsxRuntime.jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("register"),children:"Sign up"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Already have an account?"," ",jsxRuntime.jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("login"),children:"Sign in"})]})})})]}),jsxRuntime.jsx(Gn,{})]})})}function Ud({collections:e,onNavigate:t,user:r}){let{permissions:o}=Lr(),[a,n]=ka.useState({totalDocs:0,totalMedia:0,totalUsers:0,recentActivity:[]}),[s,i]=ka.useState(true);ka.useEffect(()=>{let d=setTimeout(()=>{n({totalDocs:124,totalMedia:856,totalUsers:12,recentActivity:[{id:1,type:"edit",user:"Daniel Dozie",doc:"Getting Started with Kyro",collection:"posts",time:"2m ago"},{id:2,type:"create",user:"Jane Smith",doc:"New Product Launch",collection:"products",time:"15m ago"},{id:3,type:"upload",user:"Daniel Dozie",doc:"hero-banner.jpg",collection:"media",time:"1h ago"},{id:4,type:"publish",user:"System",doc:"Weekly Update",collection:"posts",time:"3h ago"}]}),i(false);},800);return ()=>clearTimeout(d)},[]);let l=Object.entries(e).filter(([d])=>!Rs.includes(d)&&o?.collections?.[d]?.read!==false);return jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 px-8 pb-12",children:[jsxRuntime.jsx(Ft,{title:`Welcome back, ${r?.email?.split("@")[0]||"Admin"}`,description:"Everything looks great in your command center today.",action:l.length>0&&o?.collections?.[l[0]?.[0]]?.create!==false?{label:"New Document",onClick:()=>t("create",l[0]?.[0]),icon:lucideReact.Plus}:void 0}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[{label:"Total Content",value:a.totalDocs,icon:lucideReact.FileText,color:"text-blue-500"},{label:"Media Assets",value:a.totalMedia,icon:lucideReact.Image,color:"text-purple-500"},{label:"Active Users",value:a.totalUsers,icon:lucideReact.Users,color:"text-green-500"},{label:"System Health",value:"100%",icon:lucideReact.Activity,color:"text-amber-500"}].map((d,c)=>jsxRuntime.jsxs("div",{className:"surface-tile p-6 flex items-center justify-between group hover:border-[var(--kyro-primary)] transition-all duration-500 cursor-default",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-1",children:d.label}),jsxRuntime.jsx("h3",{className:"text-3xl font-bold tracking-tighter",children:s?jsxRuntime.jsx(Ot,{variant:"text",className:"w-16"}):d.value})]}),jsxRuntime.jsx("div",{className:`p-3 rounded-2xl bg-[var(--kyro-bg-secondary)] group-hover:scale-110 transition-transform duration-500 ${d.color}`,children:jsxRuntime.jsx(d.icon,{className:"w-6 h-6"})})]},c))}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_400px] gap-8",children:[jsxRuntime.jsxs("div",{className:"space-y-8 min-w-0",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-8",children:[jsxRuntime.jsxs("h2",{className:"text-xl font-bold mb-1 tracking-tight flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.LayoutDashboard,{className:"w-5 h-5 opacity-40"}),"Content Growth"]}),jsxRuntime.jsx("p",{className:"text-[10px] font-bold tracking-widest opacity-40 mb-8",children:"Snapshot of document velocity over the last 7 days"}),jsxRuntime.jsxs("div",{className:"h-48 w-full relative mb-12",children:[jsxRuntime.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 1000 200",preserveAspectRatio:"none",children:[jsxRuntime.jsx("defs",{children:jsxRuntime.jsxs("linearGradient",{id:"chartGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[jsxRuntime.jsx("stop",{offset:"0%",stopColor:"var(--kyro-primary)",stopOpacity:"0.3"}),jsxRuntime.jsx("stop",{offset:"100%",stopColor:"var(--kyro-primary)",stopOpacity:"0"})]})}),jsxRuntime.jsx("path",{d:"M0,180 Q100,140 200,160 T400,100 T600,120 T800,40 T1000,60 L1000,200 L0,200 Z",fill:"url(#chartGradient)",className:"animate-pulse duration-[4s]"}),jsxRuntime.jsx("path",{d:"M0,180 Q100,140 200,160 T400,100 T600,120 T800,40 T1000,60",fill:"none",stroke:"var(--kyro-primary)",strokeWidth:"4",strokeLinecap:"round",vectorEffect:"non-scaling-stroke",className:"filter drop-shadow-[0_0_8px_var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{className:"flex justify-between mt-4 text-[10px] font-bold opacity-30 tracking-widest ",children:[jsxRuntime.jsx("span",{children:"Mon"}),jsxRuntime.jsx("span",{children:"Tue"}),jsxRuntime.jsx("span",{children:"Wed"}),jsxRuntime.jsx("span",{children:"Thu"}),jsxRuntime.jsx("span",{children:"Fri"}),jsxRuntime.jsx("span",{children:"Sat"}),jsxRuntime.jsx("span",{children:"Sun"})]})]}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:l.map(([d,c])=>jsxRuntime.jsxs("div",{onClick:()=>t("list",d),className:"p-6 rounded-2xl border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] bg-[var(--kyro-bg-secondary)] hover:bg-[var(--kyro-surface)] transition-all cursor-pointer group",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxRuntime.jsx("h3",{className:"font-bold text-lg tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors",children:c.label||d}),jsxRuntime.jsx(lucideReact.ArrowUpRight,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-all"})]}),jsxRuntime.jsx("div",{className:"w-full h-1 bg-[var(--kyro-bg-secondary)] rounded-full mb-3 overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full bg-[var(--kyro-primary)]",style:{width:`${Math.random()*60+20}%`}})}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] line-clamp-1",children:c.admin?.description||`Manage ${d} content.`})]},d))})]}),jsxRuntime.jsxs("section",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-6 border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] transition-all cursor-pointer group",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between mb-4",children:jsxRuntime.jsxs("h3",{className:"text-xl font-bold tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-5 h-5"}),"Quick Links"]})}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[l.filter(([d])=>o?.collections?.[d]?.create!==false).map(([d])=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>t("new",d),className:"w-full flex items-center justify-between p-4 bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl hover:bg-[var(--kyro-surface-accent)] hover:border-[var(--kyro-primary)] transition-all group/btn",children:[jsxRuntime.jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:["New ",e[d]?.singularLabel||e[d]?.label||d]}),jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4 text-[var(--kyro-text-secondary)] group-hover/btn:text-[var(--kyro-primary)]"})]},d)),l.every(([d])=>o?.collections?.[d]?.create===false)&&jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] py-2",children:"No collections available for creation."})]})]}),jsxRuntime.jsxs("div",{className:"surface-tile p-8 bg-[#0f172a] text-white border-none shadow-2xl shadow-blue-500/10 overflow-hidden relative group cursor-pointer",children:[jsxRuntime.jsxs("div",{className:"relative z-10",children:[jsxRuntime.jsx("h3",{className:"text-2xl font-bold tracking-tighter mb-2",children:"Media Library"}),jsxRuntime.jsx("p",{className:"opacity-80 text-sm font-medium mb-6",children:"Manage high-fidelity assets with our liquid masonry gallery."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 font-bold text-xs tracking-widest text-blue-400",children:["Open Assets"," ",jsxRuntime.jsx(lucideReact.ArrowRight,{className:"w-4 h-4 group-hover:translate-x-1 transition-transform"})]})]}),jsxRuntime.jsx(lucideReact.Image,{className:"absolute bottom-[-20px] right-[-20px] w-48 h-48 opacity-10 rotate-12 group-hover:scale-110 transition-transform duration-1000"})]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-8",children:[jsxRuntime.jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-5 h-5 opacity-40"}),"Recent Activity"]}),jsxRuntime.jsx("div",{className:"space-y-6",children:a.recentActivity.map(d=>jsxRuntime.jsxs("div",{className:"flex gap-4 group",children:[jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--kyro-bg-secondary)] flex items-center justify-center border border-[var(--kyro-border)] group-hover:bg-[var(--kyro-primary)] transition-colors",children:jsxRuntime.jsx("span",{className:"text-[10px] font-bold",children:d.user[0]})})}),jsxRuntime.jsxs("div",{className:"flex-1 border-b border-[var(--kyro-border)] pb-4 group-last:border-none",children:[jsxRuntime.jsxs("p",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-snug",children:[jsxRuntime.jsx("span",{className:"font-bold",children:d.user})," ",d.type==="create"?"created":d.type==="edit"?"edited":d.type==="publish"?"published":"uploaded"," ",jsxRuntime.jsxs("span",{className:"text-[var(--kyro-primary)] italic",children:['"',d.doc,'"']})," ","in ",jsxRuntime.jsx("span",{className:"opacity-60",children:d.collection})]}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 mt-1 block",children:d.time})]})]},d.id))}),jsxRuntime.jsx("button",{type:"button",className:"w-full mt-6 py-3 text-xs font-bold tracking-widest text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-colors border-t border-[var(--kyro-border)] pt-6",children:"View Audit Logs"})]}),jsxRuntime.jsxs("section",{className:"surface-tile p-8",children:[jsxRuntime.jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Activity,{className:"w-5 h-5 opacity-40"}),"System Status"]}),jsxRuntime.jsx("div",{className:"space-y-4",children:[{label:"Cloud API",status:"Optimal",pulse:"bg-green-500"},{label:"Database Node",status:"Healthy",pulse:"bg-green-500"},{label:"Media CDN",status:"Active",pulse:"bg-blue-500"},{label:"Auth Service",status:"Secure",pulse:"bg-green-500"}].map((d,c)=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-4 bg-[var(--kyro-bg-secondary)] rounded-2xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-secondary)]",children:d.label}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:d.status}),jsxRuntime.jsx("div",{className:`w-2 h-2 rounded-full ${d.pulse} animate-pulse shadow-[0_0_8px] shadow-current`})]})]},c))})]})]})]})]})}function jd(){let[e,t]=ka.useState([]),[r,o]=ka.useState(true),[a,n]=ka.useState(""),[s,i]=ka.useState(false),[l,d]=ka.useState({name:"",email:"",password:"",role:"customer"}),[c,m]=ka.useState(""),[u,g]=ka.useState(false),{confirm:x,alert:f}=ot();ka.useEffect(()=>{y();},[]);let y=async()=>{try{o(!0);let w=await De("/api/users");t(w.docs||[]);}catch(w){console.error("Failed to load users:",w);}finally{o(false);}},b=w=>{let N=!w.locked;x({title:N?"Lock User Account?":"Unlock User Account?",message:N?`Are you sure you want to lock ${w.email}? They will be immediately logged out and unable to return.`:`Restore system access for ${w.email}?`,variant:N?"danger":"success",onConfirm:async()=>{try{await Xt(`/api/users/${w.id}`,{locked:N}),t(p=>p.map(A=>A.id===w.id?{...A,locked:N}:A)),$.success(N?`Account locked: ${w.email}`:`Account restored: ${w.email}`);}catch(p){console.error("Failed to toggle user lock:",p),$.error("Failed to update account status");}}});},v=w=>{x({title:"Destroy User Account",message:`You are about to permanently delete ${w.email}. This will remove all their data and cannot be undone.`,variant:"danger",confirmLabel:"Destroy Account",onConfirm:async()=>{try{await kt(`/api/users/${w.id}`),t(N=>N.filter(p=>p.id!==w.id)),$.success(`Identity purged: ${w.email}`);}catch(N){console.error("Failed to delete user:",N),$.error("Failed to delete user");}}});},R=async()=>{if(!l.email.trim()||!l.password.trim()){m("Email and password are required");return}g(true),m("");try{await et("/api/users",{name:l.name.trim()||void 0,email:l.email.trim(),password:l.password,role:l.role}),i(!1),d({name:"",email:"",password:"",role:"customer"}),$.success("User created successfully"),y();}catch(w){let N=w instanceof Error?w.message:"Failed to create user";m(N),$.error(N);}finally{g(false);}},L=["super_admin","admin","editor","author","customer","guest"],C=e.filter(w=>w.email.toLowerCase().includes(a.toLowerCase())||w.name?.toLowerCase().includes(a.toLowerCase()));return jsxRuntime.jsxs("div",{className:"w-full space-y-6 animate-in fade-in slide-in-from-bottom-4 duration-700 px-4 md:px-8 pb-12",children:[jsxRuntime.jsx(Ft,{title:"Identity & Access",description:"Manage the core administrative team and security permissions.",icon:lucideReact.Users,action:{label:"New User",onClick:()=>{d({name:"",email:"",password:"",role:"customer"}),m(""),i(true);},icon:lucideReact.UserPlus}}),jsxRuntime.jsxs("div",{className:"flex flex-col md:flex-row gap-3",children:[jsxRuntime.jsxs("div",{className:"relative flex-1 group",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-secondary)] opacity-40 group-focus-within:opacity-100 transition-opacity"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search by identity or email...",value:a,onChange:w=>n(w.target.value),className:"w-full pl-10 pr-4 py-2.5 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] transition-all text-xs font-bold"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1 bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest bg-[var(--kyro-surface)] shadow-sm rounded-lg border border-[var(--kyro-border)]",children:"ALL"}),jsxRuntime.jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"ADMINS"}),jsxRuntime.jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"LOCKED"})]})]}),jsxRuntime.jsx("div",{className:"surface-tile overflow-x-auto",children:jsxRuntime.jsxs("table",{className:"w-full text-left",children:[jsxRuntime.jsx("thead",{children:jsxRuntime.jsxs("tr",{className:"text-[var(--kyro-text-secondary)] font-bold text-[9px] tracking-[0.2em] uppercase border-b border-[var(--kyro-border)] whitespace-nowrap",children:[jsxRuntime.jsx("th",{className:"px-6 py-4 w-64",children:"Member Identity"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Administrative Role"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Security Status"}),jsxRuntime.jsx("th",{className:"px-6 py-4",children:"Last Activity"}),jsxRuntime.jsx("th",{className:"px-6 py-4 w-32 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:r?Array.from({length:6}).map((w,N)=>jsxRuntime.jsx("tr",{className:"animate-pulse",children:jsxRuntime.jsx("td",{colSpan:5,className:"px-6 py-5 bg-[var(--kyro-surface-accent)]/30"})},N)):C.length===0?jsxRuntime.jsx("tr",{children:jsxRuntime.jsx("td",{colSpan:5,className:"px-6 py-20 text-center",children:jsxRuntime.jsx("p",{className:"text-xs font-bold opacity-30 tracking-widest uppercase italic",children:"No identity matches found"})})}):C.map(w=>jsxRuntime.jsxs("tr",{className:`hover:bg-[var(--kyro-surface-accent)]/50 transition-colors group ${w.locked?"opacity-50 grayscale":""}`,children:[jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx(du,{user:w}),jsxRuntime.jsxs("div",{className:"min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"text-xs font-bold text-[var(--kyro-text-primary)] truncate",children:w.name||w.email.split("@")[0]}),w.tenantId&&jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[7px] px-1 py-0 border-none bg-[var(--kyro-surface-accent)] opacity-50",children:w.tenantId})]}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:w.email})]})]})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Shield,{className:"w-3.5 h-3.5 opacity-30"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest uppercase opacity-70",children:w.role})]})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsx(Pt,{variant:w.locked?"danger":"success",dot:true,className:"text-[8px] font-bold uppercase tracking-widest",children:w.locked?"Restricted":"Authorized"})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold text-[var(--kyro-text-secondary)] opacity-50 uppercase tabular-nums",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3 h-3"}),w.lastLogin?new Date(w.lastLogin).toLocaleDateString():"Never"]})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5 text-right",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-all",children:[jsxRuntime.jsx("button",{onClick:()=>b(w),className:`p-1.5 rounded-lg border transition-all ${w.locked?"bg-green-500/10 text-green-500 border-green-500/20 hover:bg-green-500/20":"bg-amber-500/10 text-amber-500 border-amber-500/20 hover:bg-amber-500/20"}`,title:w.locked?"Restore Access":"Restrict Access",children:w.locked?jsxRuntime.jsx(lucideReact.LockOpen,{className:"w-3.5 h-3.5"}):jsxRuntime.jsx(lucideReact.Lock,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("button",{onClick:()=>v(w),className:"p-1.5 rounded-lg border border-red-500/20 bg-red-500/10 text-red-500 hover:bg-red-500/20 transition-all",title:"Delete User",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5"})})]})})]},w.id))})]})}),jsxRuntime.jsxs(Ut,{open:s,onClose:()=>i(false),title:"Create User",size:"lg",children:[jsxRuntime.jsx(Or,{children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Name (optional)"}),jsxRuntime.jsx("input",{type:"text",value:l.name,onChange:w=>d({...l,name:w.target.value}),placeholder:"John Doe",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Email Address"}),jsxRuntime.jsx("input",{type:"email",value:l.email,onChange:w=>d({...l,email:w.target.value}),placeholder:"user@example.com",required:true,className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Password"}),jsxRuntime.jsx("input",{type:"password",value:l.password,onChange:w=>d({...l,password:w.target.value}),placeholder:"Minimum 12 characters",required:true,minLength:12,className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Role"}),jsxRuntime.jsx("select",{value:l.role,onChange:w=>d({...l,role:w.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]",children:L.map(w=>jsxRuntime.jsx("option",{value:w,children:w},w))})]}),c&&jsxRuntime.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-xl flex items-center gap-2 text-red-500 text-xs font-bold",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-4 h-4"}),c]})]})}),jsxRuntime.jsxs(Ur,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>i(false),className:"px-6 py-2.5 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:R,disabled:u,className:"kyro-btn kyro-btn-primary px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10 disabled:opacity-50",children:u?"Creating...":"Create User"})]})]})]})}function du({user:e}){let[t,r]=ka.useState(null);return ka.useEffect(()=>{let o=e.avatar;typeof o=="string"&&/^[0-9a-f-]+$/i.test(o)&&De(`/api/media/${o}`).then(a=>r(a?.thumbnailUrl||a?.url||null)).catch(()=>r(null));},[e.avatar]),t?jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-lg overflow-hidden border border-[var(--kyro-border)] flex-shrink-0",children:jsxRuntime.jsx("img",{src:t,alt:"",className:"w-full h-full object-cover"})}):jsxRuntime.jsx("div",{className:"w-8 h-8 rounded-lg bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] flex items-center justify-center text-xs font-bold text-[var(--kyro-primary)] flex-shrink-0",children:e.name?e.name[0]:e.email[0].toUpperCase()})}function Hd(){let[e,t]=ka.useState("Kyro CMS"),[r,o]=ka.useState("Command Center"),[a,n]=ka.useState("#6366f1"),[s,i]=ka.useState("Welcome back to your Command Center."),[l,d]=ka.useState(false),[c,m]=ka.useState(false);return ka.useEffect(()=>{(async()=>{try{let f=await De("/api/globals/site-settings"),y=f.data||f;y&&Object.keys(y).length>0&&(y.siteName&&t(y.siteName),y.adminTitle&&o(y.adminTitle),y.primaryColor&&n(y.primaryColor),y.dashboardGreeting&&i(y.dashboardGreeting));}catch(f){console.error("Failed to load branding:",f);}})();},[]),jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxRuntime.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 pt-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:["Branding ",jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:"Hub"})]}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] mt-1 font-medium opacity-60",children:"Customize the identity and aesthetic of your administrative ecosystem."})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-3",children:jsxRuntime.jsxs("button",{type:"button",onClick:async()=>{d(true);try{await Xt("/api/globals/site-settings",{siteName:e,adminTitle:r,primaryColor:a,dashboardGreeting:s}),m(!0),$.success("Branding updated"),document.documentElement.style.setProperty("--kyro-primary",a),setTimeout(()=>window.location.reload(),800);}catch(x){$.error("Failed to save branding"),console.error(x);}finally{d(false);}},disabled:l,className:`flex items-center gap-2 px-8 py-3 rounded-2xl font-bold text-sm shadow-xl transition-all active:scale-95 ${c?"bg-green-500 text-white":"kyro-btn-primary hover:shadow-[var(--kyro-primary)]"}`,children:[l?jsxRuntime.jsx(lucideReact.RefreshCcw,{className:"w-4 h-4 animate-spin"}):c?jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"}):jsxRuntime.jsx(lucideReact.Save,{className:"w-4 h-4"}),l?"Saving...":c?"Identity Updated":"Publish Branding"]})})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[jsxRuntime.jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsxRuntime.jsx(lucideReact.Tag,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsxRuntime.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Core Identity"})]}),jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Site Public Name"}),jsxRuntime.jsx("input",{type:"text",value:e,onChange:x=>t(x.target.value),className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all",placeholder:"e.g. Acme Corp CMS"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Admin Dashboard Title"}),jsxRuntime.jsx("input",{type:"text",value:r,onChange:x=>o(x.target.value),className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all",placeholder:"e.g. Command Center"})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"System Greeting"}),jsxRuntime.jsx("textarea",{value:s,onChange:x=>i(x.target.value),rows:3,className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all resize-none",placeholder:"Greeting text for the dashboard..."})]})]})]}),jsxRuntime.jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsxRuntime.jsx(lucideReact.Palette,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsxRuntime.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Visual Aesthetic"})]}),jsxRuntime.jsxs("div",{className:"space-y-8",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Primary Brand Color"}),jsxRuntime.jsx("div",{className:"grid grid-cols-6 gap-3",children:[{name:"Indigo",hex:"#6366f1"},{name:"Emerald",hex:"#10b981"},{name:"Rose",hex:"#f43f5e"},{name:"Amber",hex:"#f59e0b"},{name:"Sky",hex:"#0ea5e9"},{name:"Violet",hex:"#8b5cf6"}].map(x=>jsxRuntime.jsx("button",{type:"button",onClick:()=>n(x.hex),className:`aspect-square rounded-xl transition-all border-4 ${a===x.hex?"border-white ring-2 ring-[var(--kyro-primary)]":"border-transparent opacity-60 hover:opacity-100"}`,style:{backgroundColor:x.hex},title:x.name},x.name))})]}),jsxRuntime.jsxs("div",{className:"space-y-4 pt-4 border-t border-[var(--kyro-border)]",children:[jsxRuntime.jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Project Logo (SVG/PNG)"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6",children:[jsxRuntime.jsxs("div",{className:"w-20 h-20 rounded-2xl bg-[var(--kyro-bg-secondary)] border-2 border-dashed border-[var(--kyro-border)] flex flex-col items-center justify-center text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-primary)] hover:text-[var(--kyro-primary)] cursor-pointer transition-all",children:[jsxRuntime.jsx(lucideReact.Image,{className:"w-6 h-6 mb-1 opacity-40"}),jsxRuntime.jsx("span",{className:"text-[8px] font-bold ",children:"Upload"})]}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("p",{className:"text-xs font-bold mb-1",children:"Upload global CMS logo"}),jsxRuntime.jsx("p",{className:"text-[10px] opacity-40 leading-relaxed",children:"This will replace the Kyro brand in the sidebar and login screens."})]})]})]})]})]}),jsxRuntime.jsxs("section",{className:"lg:col-span-2 surface-tile p-8 overflow-hidden relative group",children:[jsxRuntime.jsxs("div",{className:"absolute top-0 right-0 p-8 flex items-center gap-2 text-[var(--kyro-primary)]",children:[jsxRuntime.jsx(lucideReact.Sparkles,{className:"w-4 h-4"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest",children:"Live Preview"})]}),jsxRuntime.jsxs("div",{className:"max-w-2xl mx-auto py-12 text-center space-y-6",children:[jsxRuntime.jsxs("div",{className:"inline-flex items-center gap-3 px-4 py-2 bg-[var(--kyro-bg-secondary)] rounded-full border border-[var(--kyro-border)]",children:[jsxRuntime.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),jsxRuntime.jsxs("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:[r," Online"]})]}),jsxRuntime.jsxs("h2",{className:"text-5xl font-bold tracking-tighter leading-none italic",children:["Welcome to ",e,"."]}),jsxRuntime.jsx("p",{className:"text-xl font-medium text-[var(--kyro-text-secondary)] opacity-60",children:s})]}),jsxRuntime.jsx("style",{dangerouslySetInnerHTML:{__html:`
100
100
  :root {
101
101
  --kyro-primary-temp: ${a};
102
102
  }
103
103
  .preview-btn {
104
104
  background-color: var(--kyro-primary-temp);
105
105
  }
106
- `}})]})]})]})}var ku=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function Wd({collections:e}){let[t,r]=ka.useState([]),[o,a]=ka.useState(false),[n,s]=ka.useState(null),[i,l]=ka.useState(""),[d,c]=ka.useState(null),[m,y]=ka.useState(false),{confirm:g,alert:x}=at(),[f,u]=ka.useState(false),[b,v]=ka.useState(""),R=async()=>{try{let p=await Be("/api/keys");r(p);}catch(p){console.error(p);}};ka.useEffect(()=>{R();},[]);let L=async()=>{v(""),u(true);},C=async()=>{if(b.trim())try{await et("/api/keys",{name:b}),R(),u(!1),v(""),$.success("API key generated");}catch(p){console.error(p),$.error("Failed to generate API key");}},w=p=>{g({title:"Revoke API Key",message:"Are you sure you want to revoke this key? Any integrations using it will stop working.",variant:"danger",onConfirm:async()=>{try{await bt(`/api/keys/${p}`),R(),$.success("API key revoked");}catch(A){console.error(A),$.error("Failed to revoke API key");}}});},N=async()=>{if(i){y(true);try{let A=await(await fetch(qe(`/api/${i}`))).json();c(A);}catch{c({error:"Failed to fetch. Ensure the endpoint exists."});}finally{y(false);}}};return jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxRuntime.jsx(Ft,{title:"Developer Center",description:"Provision access keys and explore the headless API ecosystem.",icon:lucideReact.CodeXml,actions:[{label:"Generate Key",onClick:L,icon:lucideReact.Key}]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-8",children:[jsxRuntime.jsxs("section",{className:"xl:col-span-2 space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-2",children:[jsxRuntime.jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsxRuntime.jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40 uppercase",children:"Access Credentials"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:t.length===0?jsxRuntime.jsxs("div",{className:"p-12 text-center rounded-[2rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[jsxRuntime.jsx(lucideReact.Lock,{className:"w-10 h-10 mx-auto mb-4 opacity-20"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-50",children:"No API keys found. Generate one to get started."})]}):t.map(p=>jsxRuntime.jsx("div",{className:"group relative overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-3xl p-6 hover:border-[var(--kyro-primary)]/50 transition-all duration-300",children:jsxRuntime.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 relative z-10",children:[jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsxRuntime.jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsxRuntime.jsx(lucideReact.Key,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsxRuntime.jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors truncate",children:p.name})]}),jsxRuntime.jsxs("div",{className:"flex-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-2xl px-4 py-3 flex items-center justify-between group/key overflow-hidden",children:[jsxRuntime.jsx("code",{className:"text-xs font-mono opacity-80 truncate mr-4",children:n===p.id?p.key:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>s(n===p.id?null:p.id),className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all text-[var(--kyro-text-secondary)]",children:n===p.id?jsxRuntime.jsx(lucideReact.EyeOff,{className:"w-4 h-4"}):jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"})}),jsxRuntime.jsx("button",{type:"button",className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all text-[var(--kyro-text-secondary)]",onClick:()=>{navigator.clipboard.writeText(p.key),$.success("API key copied to clipboard");},children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-4 h-4"})})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6 mt-4 text-[10px] font-bold opacity-30 uppercase tracking-widest",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{children:"Issued:"}),jsxRuntime.jsx("span",{children:new Date(p.createdAt).toLocaleDateString()})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{children:"Status:"}),jsxRuntime.jsx("span",{className:"text-green-500",children:"Active"})]})]})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>w(p.id),className:"p-3.5 bg-red-500/5 text-red-500 rounded-2xl hover:bg-red-500/10 transition-all border border-transparent hover:border-red-500/30 self-start md:self-center",title:"Revoke Key",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-5 h-5"})})]})},p.id))})]}),jsxRuntime.jsxs("section",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"relative overflow-hidden rounded-[2.5rem] border border-[var(--kyro-border)] bg-gradient-to-br from-[var(--kyro-primary)] to-[var(--kyro-primary)]/80 p-8 group shadow-2xl shadow-[var(--kyro-primary)]/20",children:[jsxRuntime.jsx("div",{className:"absolute top-0 right-0 p-8 opacity-[0.1] pointer-events-none group-hover:scale-110 transition-transform duration-700",children:jsxRuntime.jsx(lucideReact.Terminal,{className:"w-48 h-48 rotate-12"})}),jsxRuntime.jsxs("div",{className:"relative z-10",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 bg-white/20 backdrop-blur-md rounded-2xl flex items-center justify-center mb-6",children:jsxRuntime.jsx(lucideReact.Terminal,{className:"w-6 h-6 text-white"})}),jsxRuntime.jsx("h3",{className:"text-white text-2xl font-bold tracking-tight mb-3",children:"Endpoint Hub"}),jsxRuntime.jsx("p",{className:"text-white/80 text-sm font-medium leading-relaxed mb-8",children:"Kyro CMS is built for high-performance content delivery. Use these endpoints to power your headless frontends."}),jsxRuntime.jsxs("button",{type:"button",className:"w-full py-4 bg-white text-[var(--kyro-primary)] rounded-[1.2rem] font-bold text-xs uppercase tracking-widest hover:shadow-xl transition-all flex items-center justify-center gap-2 active:scale-[0.98]",children:["Full API Documentation",jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-3.5 h-3.5"})]})]})]}),jsxRuntime.jsxs("div",{className:"rounded-[2.5rem] border border-[var(--kyro-border)] bg-[var(--kyro-surface)]/50 p-8 space-y-6",children:[jsxRuntime.jsx("h4",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Environment Matrix"}),jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold",children:"Content API"}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Production"})]}),jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsx("div",{className:"absolute -inset-0.5 bg-gradient-to-r from-[var(--kyro-primary)]/30 to-transparent rounded-xl blur opacity-0 group-hover:opacity-100 transition-all"}),jsxRuntime.jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsxRuntime.jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://api.kyro.io/v1"}),jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5 opacity-0 group-hover:opacity-40 cursor-pointer transition-opacity",onClick:()=>navigator.clipboard.writeText("https://api.kyro.io/v1")})]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold",children:"Draft Explorer"}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Staging"})]}),jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsx("div",{className:"absolute -inset-0.5 bg-gradient-to-r from-amber-500/30 to-transparent rounded-xl blur opacity-0 group-hover:opacity-100 transition-all"}),jsxRuntime.jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsxRuntime.jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://preview.kyro.io/v1"}),jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5 opacity-0 group-hover:opacity-40 cursor-pointer transition-opacity",onClick:()=>navigator.clipboard.writeText("https://preview.kyro.io/v1")})]})]})]})]})]})]}),jsxRuntime.jsxs("section",{className:"xl:col-span-3 rounded-[3rem] border border-[var(--kyro-border)] bg-[var(--kyro-surface)]/50 p-10 space-y-10 overflow-hidden relative",children:[jsxRuntime.jsx("div",{className:"absolute top-0 right-0 p-20 opacity-[0.02] pointer-events-none",children:jsxRuntime.jsx(lucideReact.CirclePlay,{className:"w-96 h-96"})}),jsxRuntime.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-10 relative z-10",children:[jsxRuntime.jsxs("div",{className:"max-w-xl",children:[jsxRuntime.jsxs("h2",{className:"text-3xl font-bold tracking-tighter flex items-center gap-4 mb-3",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 bg-[var(--kyro-primary)]/10 rounded-2xl flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.CirclePlay,{className:"w-7 h-7 text-[var(--kyro-primary)]"})}),"API ",jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:"Explorer"})]}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] text-sm font-medium opacity-60 leading-relaxed",children:"Test your collection endpoints and analyze live response payloads. Enter a collection slug to fetch its latest documents."})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 flex-1 lg:max-w-2xl bg-[var(--kyro-bg)] p-2 rounded-[2rem] border border-[var(--kyro-border)] shadow-2xl",children:[jsxRuntime.jsxs("div",{className:"flex-1 relative flex items-center pl-6",children:[jsxRuntime.jsxs("span",{className:"text-[11px] font-bold opacity-30 uppercase tracking-widest mr-2 whitespace-nowrap",children:["GET ",ku,"/"]}),jsxRuntime.jsx("input",{type:"text",value:i,onChange:p=>l(p.target.value),placeholder:"collection-slug",className:"w-full py-4 bg-transparent focus:outline-none font-mono text-sm font-bold text-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("button",{type:"button",onClick:N,disabled:m||!i,className:"kyro-btn kyro-btn-primary px-8 py-4 rounded-[1.5rem] font-bold text-sm shadow-xl disabled:opacity-50 disabled:cursor-not-allowed hover:scale-[1.02] transition-all flex items-center gap-3 shrink-0",children:[m?jsxRuntime.jsx(lucideReact.RefreshCcw,{className:"w-4 h-4 animate-spin"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-5 h-5"}),"Run Query"]})]})]}),d?jsxRuntime.jsxs("div",{className:"animate-in fade-in zoom-in-95 duration-500 relative z-10",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4 px-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"w-1 h-3 bg-[var(--kyro-primary)] rounded-full"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Response Payload"})]}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[9px] font-mono px-3",children:"200 OK"})]}),jsxRuntime.jsxs("div",{className:"rounded-[2rem] overflow-hidden border border-[var(--kyro-border)] shadow-2xl bg-[#090b10]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-6 py-4 bg-[#11141d] border-b border-[var(--kyro-border)]/50",children:[jsxRuntime.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500/20"}),jsxRuntime.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-amber-500/20"}),jsxRuntime.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500/20"})]}),jsxRuntime.jsx(gu__default.default,{value:JSON.stringify(d,null,2),height:"450px",theme:codemirrorThemeAura.aura,extensions:[langJson.json()],editable:false,className:"text-sm"})]})]}):jsxRuntime.jsxs("div",{className:"h-80 rounded-[3rem] border-2 border-dashed border-[var(--kyro-border)] flex flex-col items-center justify-center bg-[var(--kyro-surface-accent)]/20 transition-all duration-700",children:[jsxRuntime.jsx("div",{className:"w-20 h-20 bg-[var(--kyro-surface)] rounded-3xl flex items-center justify-center shadow-lg border border-[var(--kyro-border)] mb-6 opacity-20",children:jsxRuntime.jsx(lucideReact.CodeXml,{className:"w-10 h-10"})}),jsxRuntime.jsx("p",{className:"font-bold text-sm opacity-30 uppercase tracking-[0.2em]",children:"Awaiting request dispatch..."})]})]})]}),jsxRuntime.jsxs(Ot,{open:f,onClose:()=>u(false),title:"Generate Access Token",size:"lg",children:[jsxRuntime.jsx(Ur,{children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70 leading-relaxed",children:"Define a name for this API key to identify its integration context. Keys are encrypted at rest and should be treated with extreme caution."}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Token Name"}),jsxRuntime.jsx("input",{type:"text",value:b,onChange:p=>v(p.target.value),placeholder:"e.g., Mobile App SDK, Production Server",className:"w-full px-6 py-4 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-2xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)] shadow-sm transition-all",onKeyDown:p=>p.key==="Enter"&&C()})]})]})}),jsxRuntime.jsxs(zr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>u(false),className:"px-6 py-3 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:C,className:"kyro-btn kyro-btn-primary px-8 py-3 rounded-xl font-bold text-sm hover:opacity-90 shadow-lg shadow-[var(--kyro-primary)]/20 transition-all",children:"Generate Token"})]})]})]})}function qd(e){let[t,r]=ka.useState([]),[o,a]=ka.useState(false),[n,s]=ka.useState(null),[i,l]=ka.useState(false),{confirm:d}=at(),c=ka.useCallback(async()=>{a(true),s(null);try{let x=await Be(e.endpoint),f=Array.isArray(x)?x:x.docs||[],u=e.transformLoad?e.transformLoad(f):f;r(u),e.onSuccess?.("load",u);}catch(x){let f=x instanceof Error?x.message:"Failed to load resources";s(f),e.onError?.("load",x);}finally{a(false);}},[e.endpoint,e.transformLoad]);ka.useEffect(()=>{c();},[c]);let m=ka.useCallback((x,f="item")=>{d({title:`Delete ${f}`,message:`Are you sure you want to delete this ${f.toLowerCase()}? This action cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await bt(`${e.endpoint}/${x}`),r(u=>u.filter(b=>b.id!==x)),e.onSuccess?.("delete",x),$.success(`${f} deleted`);}catch(u){let b=u instanceof Error?u.message:`Failed to delete ${f}`;$.error(b),e.onError?.("delete",u);}}});},[e.endpoint,d]),y=ka.useCallback(async x=>{s(null);try{let f=await et(e.endpoint,x);return r(u=>[f,...u]),l(!1),e.onSuccess?.("create",f),f}catch(f){let u=f instanceof Error?f.message:"Failed to create resource";throw s(u),e.onError?.("create",f),f}},[e.endpoint]),g=ka.useCallback(async(x,f)=>{s(null);try{let u=await Xt(`${e.endpoint}/${x}`,f);return r(b=>b.map(v=>v.id===x?u:v)),e.onSuccess?.("update",u),u}catch(u){let b=u instanceof Error?u.message:"Failed to update resource";throw s(b),e.onError?.("update",u),u}},[e.endpoint]);return {items:t,setItems:r,loading:o,error:n,load:c,remove:m,create:y,update:g,isCreateModalOpen:i,setIsCreateModalOpen:l}}function Jd(){let{items:e,loading:t,create:r,remove:o,update:a,isCreateModalOpen:n,setIsCreateModalOpen:s}=qd({endpoint:"/api/webhooks"}),{confirm:i}=at(),[l,d]=ka.useState(false),[c,m]=ka.useState(false),[y,g]=ka.useState(null),[x,f]=ka.useState(null),[u,b]=ka.useState({name:"",url:"",events:[],secret:""}),[v,R]=ka.useState(""),L=async()=>{if(!u.name.trim()||!u.url.trim()){R("Name and URL are required");return}try{await r(u),b({name:"",url:"",events:[],secret:""}),$.success(`Webhook established: ${u.name}`);}catch{R("Failed to create webhook"),$.error("Failed to create webhook");}},C=async p=>{f(p),g(null),d(true);try{let A=await et(`/api/webhooks/${p}/test`);g({success:!0,message:A.message||"Webhook triggered successfully"}),$.success("Dispatch verified: Remote endpoint responded");}catch{g({success:false,message:"Failed to trigger webhook"});}},w=async(p,A)=>{try{let O=A==="active"?"paused":"active";await a(p,{status:O}),$.success(O==="active"?"Signals resumed":"Dispatcher paused");}catch(O){console.error(O),$.error("Failed to toggle webhook status");}},N=[{label:"Create",value:"create",description:"When a new document is created"},{label:"Update",value:"update",description:"When a document is updated"},{label:"Delete",value:"delete",description:"When a document is deleted"},{label:"Auth",value:"auth",description:"User login/logout events"}];return jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxRuntime.jsx(Ft,{title:"Webhooks",description:"Receive real-time notifications when your content changes.",icon:lucideReact.Webhook,actions:[{label:"Create Webhook",onClick:()=>{b({name:"",url:"",events:["collection.create","collection.update","collection.delete"],secret:""}),R(""),s(true);},icon:lucideReact.Plus},{label:"Guide",onClick:()=>m(true),icon:lucideReact.Info,variant:"outline"}]}),jsxRuntime.jsxs("div",{className:"relative overflow-hidden rounded-[2rem] border border-[var(--kyro-border)] bg-gradient-to-br from-[var(--kyro-surface)] to-[var(--kyro-surface-accent)] p-8",children:[jsxRuntime.jsx("div",{className:"absolute top-0 right-0 p-8 opacity-[0.03] pointer-events-none",children:jsxRuntime.jsx(lucideReact.Zap,{className:"w-64 h-64 rotate-12"})}),jsxRuntime.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-8 relative z-10",children:[jsxRuntime.jsx("div",{className:"p-5 bg-gradient-to-br from-[var(--kyro-primary)] to-[var(--kyro-primary)]/50 rounded-[1.5rem] shadow-xl shadow-[var(--kyro-primary)]/20",children:jsxRuntime.jsx(lucideReact.Zap,{className:"w-8 h-8 text-white"})}),jsxRuntime.jsxs("div",{className:"flex-1 text-center md:text-left",children:[jsxRuntime.jsx("h3",{className:"text-xl font-bold mb-2",children:"Real-time Event Synchronization"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70 max-w-2xl leading-relaxed",children:"Webhooks allow your application to receive instant HTTP notifications when events happen in your CMS. Eliminate polling and build responsive, event-driven architectures with ease."})]}),jsxRuntime.jsxs("div",{className:"flex gap-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center px-4 py-2 bg-[var(--kyro-surface)]/50 border border-[var(--kyro-border)] rounded-2xl",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Collections"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"Triggered"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center px-4 py-2 bg-[var(--kyro-surface)]/50 border border-[var(--kyro-border)] rounded-2xl",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Latency"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"<200ms"})]})]})]})]}),jsxRuntime.jsxs("section",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsxRuntime.jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40",children:"ACTIVE ENDPOINTS"})]}),jsxRuntime.jsxs("div",{className:"text-[10px] font-bold opacity-40 uppercase",children:[e.length," Hook",e.length!==1&&"s"]})]}),t?jsxRuntime.jsx("div",{className:"flex items-center justify-center p-20 surface-tile rounded-3xl opacity-50 italic",children:"Connecting to dispatcher..."}):e.length===0?jsxRuntime.jsxs("div",{className:"p-16 text-center rounded-[3rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[jsxRuntime.jsx("div",{className:"w-20 h-20 mx-auto mb-6 bg-gradient-to-tr from-[var(--kyro-surface)] to-[var(--kyro-surface-accent)] rounded-3xl flex items-center justify-center shadow-xl border border-[var(--kyro-border)]",children:jsxRuntime.jsx(lucideReact.Webhook,{className:"w-10 h-10 text-[var(--kyro-primary)]"})}),jsxRuntime.jsx("h3",{className:"text-2xl font-bold mb-3",children:"No Webhooks Found"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-60 mb-8 max-w-sm mx-auto",children:"Your CMS is currently silent. Create a webhook to start broadcasting events to your external services."}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(true),className:"kyro-btn kyro-btn-primary inline-flex items-center gap-3 px-8 py-4 rounded-2xl font-bold hover:scale-[1.05] transition-all shadow-xl shadow-[var(--kyro-primary)]/10",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-5 h-5"}),"Configure Webhook"]})]}):jsxRuntime.jsx("div",{className:"grid gap-4",children:e.map(p=>jsxRuntime.jsx("div",{className:"group relative overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-3xl p-6 hover:border-[var(--kyro-primary)]/50 transition-all duration-300",children:jsxRuntime.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 relative z-10",children:[jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsxRuntime.jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsxRuntime.jsx(lucideReact.Webhook,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors",children:p.name}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[jsxRuntime.jsx("span",{className:`w-2 h-2 rounded-full ${p.status==="active"?"bg-green-500 animate-pulse":"bg-amber-500"}`}),jsxRuntime.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${p.status==="active"?"text-green-500":"text-amber-500"}`,children:p.status})]})]})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 pt-2",children:[jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Destination"}),jsxRuntime.jsx("div",{className:"font-mono text-xs opacity-60 truncate max-w-[200px]",title:p.url,children:p.url})]}),jsxRuntime.jsxs("div",{className:"space-y-1 sm:border-l border-t sm:border-t-0 border-[var(--kyro-border)] pt-4 sm:pt-0 sm:pl-6 mt-4 sm:mt-0",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Events"}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-1",children:[p.events.slice(0,2).map(A=>jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[8px] font-bold px-1.5 opacity-60",children:A},A)),p.events.length>2&&jsxRuntime.jsxs("span",{className:"text-[8px] font-bold opacity-30",children:["+",p.events.length-2," more"]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-1 sm:border-l border-t sm:border-t-0 border-[var(--kyro-border)] pt-4 sm:pt-0 sm:pl-6 mt-4 sm:mt-0",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Activity"}),jsxRuntime.jsxs("div",{className:"text-[10px] font-bold opacity-60 flex items-center gap-1.5",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3 h-3"}),p.lastTriggered?`Last triggered: ${new Date(p.lastTriggered).toLocaleDateString()}`:"Never triggered"]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 lg:bg-[var(--kyro-surface-accent)]/50 lg:p-2 lg:rounded-2xl lg:opacity-0 group-hover:opacity-100 transition-all duration-300 lg:translate-x-4 group-hover:translate-x-0",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>C(p.id),className:"flex-1 lg:flex-none p-3 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl hover:border-[var(--kyro-primary)] transition-all flex items-center justify-center gap-2",title:"Send test request",children:[jsxRuntime.jsx(lucideReact.Send,{className:"w-4 h-4"}),jsxRuntime.jsx("span",{className:"text-xs font-bold",children:"Test"})]}),jsxRuntime.jsx("div",{className:"w-px h-6 bg-[var(--kyro-border)] mx-1 hidden lg:block"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>w(p.id,p.status),className:`p-3 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl hover:border-[var(--kyro-primary)] transition-all group/toggle ${p.status==="active"?"text-amber-500/50 hover:text-amber-500":"text-green-500/50 hover:text-green-500"}`,title:p.status==="active"?"Pause webhook":"Activate webhook",children:p.status==="active"?jsxRuntime.jsx(lucideReact.Pause,{className:"w-4 h-4"}):jsxRuntime.jsx(lucideReact.Play,{className:"w-4 h-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o(p.id,"Webhook"),className:"p-3 bg-red-500/5 border border-red-500/10 rounded-xl hover:bg-red-500/10 hover:border-red-500/30 transition-all group/delete",title:"Delete webhook",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4 text-red-500/50 group-hover/delete:text-red-500"})})]})]})},p.id))})]}),jsxRuntime.jsxs(Ot,{open:n,onClose:()=>s(false),title:"Register Webhook",size:"lg",children:[jsxRuntime.jsx(Ur,{children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Webhook Name"}),jsxRuntime.jsx("input",{type:"text",value:u.name,onChange:p=>b({...u,name:p.target.value}),placeholder:"e.g., Slack Notifications",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Payload URL"}),jsxRuntime.jsx("input",{type:"url",value:u.url,onChange:p=>b({...u,url:p.target.value}),placeholder:"https://your-server.com/webhook",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Signing Secret"}),jsxRuntime.jsx("input",{type:"text",value:u.secret,onChange:p=>b({...u,secret:p.target.value}),placeholder:"Optional secret for verification",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Subscribed Events"}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:N.map(p=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{let A=u.events.includes(p.value)?u.events.filter(O=>O!==p.value):[...u.events,p.value];b({...u,events:A});},className:`flex items-center gap-3 p-3 rounded-lg border transition-all text-left ${u.events.includes(p.value)?"bg-[var(--kyro-primary)]/5 border-[var(--kyro-primary)]/30 text-[var(--kyro-primary)]":"bg-[var(--kyro-surface-accent)]/50 border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/30"}`,children:[jsxRuntime.jsx("div",{className:`w-4 h-4 rounded flex items-center justify-center border transition-all ${u.events.includes(p.value)?"bg-[var(--kyro-primary)] border-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:u.events.includes(p.value)&&jsxRuntime.jsx(lucideReact.CircleCheck,{className:"w-3 h-3 text-white"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-xs font-bold",children:p.label}),jsxRuntime.jsx("div",{className:"text-[10px] opacity-50",children:p.description})]})]},p.value))})]})]}),v&&jsxRuntime.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-xl flex items-center gap-2 text-red-500 text-xs font-bold",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-4 h-4"}),v]})]})}),jsxRuntime.jsxs(zr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>s(false),className:"px-6 py-2.5 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:L,className:"kyro-btn kyro-btn-primary px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10",children:"Create Webhook"})]})]}),jsxRuntime.jsxs(Ot,{open:l,onClose:()=>d(false),title:"Webhook Test Dispatcher",children:[jsxRuntime.jsx(Ur,{children:jsxRuntime.jsx("div",{className:"p-8 rounded-[2rem] bg-[var(--kyro-surface-accent)]/30 border border-[var(--kyro-border)] text-center",children:y?jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx("div",{className:`w-16 h-16 mx-auto rounded-2xl flex items-center justify-center shadow-xl ${y.success?"bg-green-500/10 text-green-500":"bg-red-500/10 text-red-500"}`,children:y.success?jsxRuntime.jsx(lucideReact.CircleCheck,{className:"w-8 h-8"}):jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-8 h-8"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-xl font-bold mb-2",children:y.success?"Dispatch Successful":"Dispatch Failed"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70",children:y.message})]})]}):jsxRuntime.jsxs("div",{className:"space-y-6 py-4",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"w-12 h-12 text-[var(--kyro-primary)] animate-spin mx-auto opacity-50"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-xl font-bold mb-1",children:"Synthesizing Payload"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-50 italic",children:"Dispatching to remote endpoint..."})]})]})})}),jsxRuntime.jsx(zr,{children:jsxRuntime.jsx("button",{type:"button",onClick:()=>d(false),className:"w-full py-3 rounded-xl font-bold text-sm bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] hover:bg-[var(--kyro-surface)] transition-all",children:"Acknowledge"})})]}),jsxRuntime.jsxs(Ot,{open:c,onClose:()=>m(false),title:"Webhook Integration Guide",size:"lg",children:[jsxRuntime.jsx(Ur,{children:jsxRuntime.jsxs("div",{className:"space-y-8",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 gap-6",children:[jsxRuntime.jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Request Context"]}),jsxRuntime.jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["When an event triggers, Kyro sends a standard ",jsxRuntime.jsx("span",{className:"font-bold text-[var(--kyro-text-primary)]",children:"POST"})," request to your endpoint with a JSON payload containing document metadata and operation details."]})]}),jsxRuntime.jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Shield,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Security Verification"]}),jsxRuntime.jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["If a secret is provided, each request includes an ",jsxRuntime.jsx("span",{className:"font-mono text-[var(--kyro-primary)]",children:"X-Kyro-Signature"})," header. Always verify this signature in production environments."]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("h4",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Payload Architecture"}),jsxRuntime.jsxs("div",{className:"relative group",children:[jsxRuntime.jsx("div",{className:"absolute -inset-1 bg-gradient-to-r from-[var(--kyro-primary)]/20 to-transparent rounded-2xl blur opacity-25 group-hover:opacity-50 transition-all"}),jsxRuntime.jsxs("div",{className:"relative bg-[var(--kyro-bg)] rounded-2xl border border-[var(--kyro-border)] p-6 font-mono text-sm overflow-hidden",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-4 border-b border-[var(--kyro-border)] pb-4 opacity-30",children:[jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-red-500/50"}),jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500/50"}),jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500/50"}),jsxRuntime.jsx("span",{className:"text-[10px] ml-2 tracking-tighter",children:"payload.json"})]}),jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"{"}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"event"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"collection.create"'}),","]}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"collection"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"products"'}),","]}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"id"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"prod_8273"'}),","]}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"timestamp"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"2026-05-14T02:53:22Z"'})]}),jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"}"})]})]})]})]})]})}),jsxRuntime.jsx(zr,{children:jsxRuntime.jsx("button",{type:"button",onClick:()=>m(false),className:"kyro-btn kyro-btn-primary w-full py-3 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/20",children:"I Understand"})})]})]})}function Yd({isOpen:e,onClose:t,collections:r,globals:o,onNavigate:a}){let{user:n,permissions:s}=Mr(),[i,l]=ka.useState(""),[d,c]=ka.useState(0),[m,y]=ka.useState(false),[g,x]=ka.useState([]),f=ka.useRef(null),u=ka.useRef(null);ka.useEffect(()=>{e&&(l(""),c(0),x([]),y(false),setTimeout(()=>f.current?.focus(),100));},[e]);let b=ka.useCallback(async S=>{if(!S||S.length<2){x([]);return}y(true);try{let j=await(await fetch(qe(`/api/search?q=${encodeURIComponent(S)}&limit=15`))).json();j.results&&x(j.results);}catch(M){console.error("Search error:",M),x([]);}finally{y(false);}},[]);if(ka.useEffect(()=>(u.current&&clearTimeout(u.current),i.length>=2?u.current=setTimeout(()=>b(i),300):x([]),()=>{u.current&&clearTimeout(u.current);}),[i,b]),!e)return null;let v=Object.entries(r).filter(([S])=>s?.collections?.[S]?.read!==false).map(([S,M])=>({id:`col-${S}`,label:M.label||S,type:"collection",slug:S,icon:lucideReact.FileText})),R=Object.entries(o).filter(([S])=>s?.globals?.[S]?.read!==false).map(([S,M])=>({id:`global-${S}`,label:M.label||S,type:"global",slug:S,icon:lucideReact.Settings})),L=typeof document<"u"&&document.documentElement.classList.contains("dark"),C=n?.role==="admin",w=[{id:"action-media",label:"Media Gallery",type:"action",view:"media",icon:lucideReact.Image,visible:s?.collections?.media?.read!==false},{id:"action-users",label:"Team Management",type:"action",view:"users",icon:lucideReact.Clock,visible:C},{id:"action-audit",label:"Audit Logs",type:"action",view:"audit",icon:lucideReact.File,visible:C},{id:"action-roles",label:"Roles & Permissions",type:"action",view:"roles",icon:lucideReact.Shield,visible:C},{id:"action-api",label:"REST API Explorer",type:"action",view:"api-explorer",icon:lucideReact.Database,visible:C},{id:"action-graphql",label:"GraphQL Playground",type:"action",view:"graphql",icon:lucideReact.Hexagon,visible:C},{id:"action-rest",label:"REST Playground",type:"action",view:"rest",icon:lucideReact.Network,visible:C},{id:"action-theme",label:L?"Switch to Light Mode":"Switch to Dark Mode",type:"action",view:"theme",icon:L?lucideReact.Sun:lucideReact.Moon,visible:true},{id:"action-logout",label:"Sign Out",type:"action",view:"logout",icon:lucideReact.LogOut,visible:true}].filter(S=>S.visible),N=g.map((S,M)=>({id:`doc-${S.collection}-${S.id}`,label:S.title,type:"document",collection:S.collection,label2:S.label,docId:S.id,icon:lucideReact.File,doc:S.doc})),p=i.length>=2?[...w,...v,...R,...N]:[...w,...v,...R],A=i===""?p:p.filter(S=>S.label.toLowerCase().includes(i.toLowerCase())),O=S=>{if(S.key==="ArrowDown")S.preventDefault(),c(M=>(M+1)%A.length);else if(S.key==="ArrowUp")S.preventDefault(),c(M=>(M-1+A.length)%A.length);else if(S.key==="Enter"){let M=A[d];M&&F(M);}else S.key==="Escape"&&t();},F=S=>{S.type==="collection"?S.slug==="users"?a(S.slug,S.slug):a("list",S.slug):S.type==="global"?a("settings",S.slug):S.type==="document"?S.collection==="users"?a("users","users",S.docId):a("edit",S.collection,S.docId):S.type==="action"&&(S.view==="users"?a("users","users"):S.view==="media"?a("media","media"):a(S.view,S.view)),t();},P=()=>i===""?"Quick Actions & Collections":g.length>0?"Documents":m?"Searching...":"Search Results";return jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-start justify-center pt-[15vh] px-4",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm animate-in fade-in duration-300",onClick:t}),jsxRuntime.jsxs("div",{className:"relative w-full max-w-2xl bg-[var(--kyro-surface)] rounded-3xl shadow-2xl overflow-hidden animate-in zoom-in-95 fade-in duration-300 ring-1 ring-white/10 border border-white/5",children:[jsxRuntime.jsxs("div",{className:"flex items-center px-6 py-5 border-b border-[var(--kyro-border)]",children:[m?jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4 animate-spin"}):jsxRuntime.jsx(lucideReact.Search,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4"}),jsxRuntime.jsx("input",{ref:f,placeholder:"Search anything...",className:"flex-1 bg-transparent border-none focus:outline-none text-lg font-medium text-[var(--kyro-text-primary)] placeholder:text-[var(--kyro-text-muted)]",value:i,onChange:S=>l(S.target.value),onKeyDown:O}),jsxRuntime.jsx("div",{className:"flex items-center gap-2 px-2 py-1 bg-[var(--kyro-bg-secondary)] rounded-lg border border-[var(--kyro-border)]",children:jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 tracking-widest",children:"ESC"})})]}),jsxRuntime.jsx("div",{className:"max-h-[400px] overflow-y-auto py-4",children:A.length>0?jsxRuntime.jsxs("div",{className:"space-y-1 px-4",children:[jsxRuntime.jsx("p",{className:"px-4 text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4",children:P()}),A.map((S,M)=>jsxRuntime.jsxs("div",{onClick:()=>F(S),onMouseEnter:()=>c(M),className:`flex items-center justify-between px-4 py-4 rounded-2xl cursor-pointer ${M===d?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] shadow-xl shadow-[var(--kyro-primary)]":"hover:bg-[var(--kyro-bg-secondary)] text-[var(--kyro-text-secondary)]"}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx("div",{className:`p-2 rounded-xl ${M===d?"bg-white/20":"bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)]"}`,children:jsxRuntime.jsx(S.icon,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-bold text-sm",children:S.label}),S.type==="document"&&S.label2&&jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest ${M===d?"text-[var(--kyro-sidebar-text-active)]/60":"opacity-40"}`,children:S.label2})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest opacity-40 ${M===d?"text-[var(--kyro-sidebar-text-active)] p-1":""}`,children:S.type}),M===d&&jsxRuntime.jsx(lucideReact.ArrowRight,{className:"w-4 h-4 mr-2"})]})]},S.id))]}):jsxRuntime.jsx("div",{className:"py-12 text-center",children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] italic opacity-60",children:i.length>=2&&!m?`No results found for "${i}"`:"Start typing to search..."})})}),jsxRuntime.jsxs("div",{className:"px-8 py-4 bg-[var(--kyro-bg-secondary)] border-t border-[var(--kyro-border)] flex items-center justify-between text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-60",children:[jsxRuntime.jsxs("div",{className:"flex gap-6",children:[jsxRuntime.jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u2191\u2193 Navigate"}),jsxRuntime.jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u23CE Select"})]}),jsxRuntime.jsx("div",{children:"Kyro Universal Search"})]})]})]})}function Zd(){let{modal:e,closeModal:t}=at(),[r,o]=ka.useState(false);if(!e.open||!e.config)return null;let{config:a}=e,n=async()=>{if(a.onConfirm)try{o(!0),await a.onConfirm();}catch(i){console.error("Modal confirm action failed:",i);}finally{o(false),t();}else t();},s=()=>{a.onCancel&&a.onCancel(),t();};return jsxRuntime.jsx(ks,{open:e.open,onClose:s,onConfirm:n,title:a.title,message:a.message,confirmLabel:a.confirmLabel,cancelLabel:a.cancelLabel,variant:a.variant==="danger"?"danger":"default",loading:r})}function Su({config:e,theme:t="light",onThemeChange:r}){let[o,a]=ka.useState(false),[n,s]=ka.useState(null),i=ka.useMemo(()=>Dn(Fa(e.collections)),[e.collections]),l=ka.useMemo(()=>Bn(Fa(e.globals)),[e.globals]),[d,c]=ka.useState(null),[m,y]=ka.useState(null),[g,x]=ka.useState("list"),[f,u]=ka.useState(null),[b,v]=ka.useState(false);ka.useEffect(()=>{(async()=>{try{let N=await fetch("/api/users/me");if(N.ok){let p=await N.json();s(p),a(!0);}}catch(N){console.error("Auth check failed",N);}})();},[]),ka.useEffect(()=>{if(o&&!d){let w=Object.keys(i)[0];w&&c(w);}},[o,i,d]);let R=(w,N=null,p=null)=>{x(w),N&&c(N),p&&u(p),v(false);};ka.useEffect(()=>{let w=N=>{(N.metaKey||N.ctrlKey)&&N.key==="k"&&(N.preventDefault(),v(p=>!p));};return window.addEventListener("keydown",w),window.openCommandPalette=()=>v(true),()=>{window.removeEventListener("keydown",w),delete window.openCommandPalette;}},[]);return o?jsxRuntime.jsx(kr,{mode:t,onChange:r,children:jsxRuntime.jsxs("div",{className:"kyro-admin min-h-screen bg-[var(--kyro-bg)] text-[var(--kyro-text-primary)]",children:[jsxRuntime.jsx("div",{className:"flex h-screen overflow-hidden",children:jsxRuntime.jsx("main",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:jsxRuntime.jsxs("div",{className:"flex-1 overflow-y-auto",children:[jsxRuntime.jsx(Yd,{isOpen:b,onClose:()=>v(false),collections:i,globals:l,onNavigate:R}),(()=>{let w=d?i[d]:null;switch(g){case "create":return w?jsxRuntime.jsx(ri,{config:e,collection:w,onSuccess:()=>x("list"),onCancel:()=>x("list"),onError:N=>$.error(N)}):null;case "detail":return w&&f?jsxRuntime.jsx(ti,{config:e,collection:w,documentId:f,onBack:()=>x("list"),onSave:()=>{},onError:N=>$.error(N)}):null;case "users":return jsxRuntime.jsx(Kd,{});case "media":return jsxRuntime.jsx(xn,{});case "branding":return jsxRuntime.jsx(Gd,{});case "developer":return jsxRuntime.jsx(Wd,{collections:i});case "webhooks":return jsxRuntime.jsx(Jd,{});default:return w?jsxRuntime.jsx(gs,{config:e,collection:w,onCreate:()=>x("create"),onEdit:N=>R("detail",d,N)}):jsxRuntime.jsx(_d,{onNavigate:R,collections:i,user:n})}})()]})})}),jsxRuntime.jsx(Zd,{}),jsxRuntime.jsx(Gn,{})]})}):jsxRuntime.jsx(ni,{onAuth:(w,N)=>{s(N),a(true);},theme:t})}function Tu({selectedCount:e,onClearSelection:t,actions:r,onSelectAll:o}){return e===0?null:jsxRuntime.jsxs("div",{className:"flex items-center justify-between py-2 px-4 bg-gray-50 border-b border-gray-200",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(us,{count:e}),jsxRuntime.jsx("span",{className:"text-sm text-gray-600",children:"selected"})]}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"text-sm text-gray-500 hover:text-gray-700",children:"Clear selection"}),o&&jsxRuntime.jsx("button",{type:"button",onClick:o,className:"text-sm text-gray-500 hover:text-gray-700",children:"Select all"})]}),jsxRuntime.jsx(wo,{trigger:jsxRuntime.jsxs("button",{type:"button",className:"kyro-btn kyro-btn-secondary kyro-btn-sm",children:["Actions",jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M6 9l6 6 6-6"})})]}),children:r.map((a,n)=>jsxRuntime.jsx(jt,{onClick:a.onClick,icon:a.icon,danger:a.danger,children:a.label},n))})]})}function Lu({open:e,onClose:t,versions:r,currentVersionId:o,onPreview:a,onRestore:n,onCompare:s,loading:i=false}){let l=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime())){let y=Date.parse(c);return isNaN(y)?"Invalid date":new Date(y).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}return m.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})},d=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime()))return l(c);let g=new Date().getTime()-m.getTime();if(g<0)return "Just now";let x=Math.floor(g/6e4),f=Math.floor(g/36e5),u=Math.floor(g/864e5);return x<1?"Just now":x<60?`${x}m ago`:f<24?`${f}h ago`:u<7?`${u}d ago`:l(c)};return jsxRuntime.jsx(dr,{open:e,onClose:t,title:"Version History",width:"md",children:i?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-12",children:jsxRuntime.jsx(Ar,{})}):r.length===0?jsxRuntime.jsxs("div",{className:"text-center flex flex-col items-center justify-center py-16 text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsx(lucideReact.History,{className:"w-12 h-12 mb-4 opacity-20"}),jsxRuntime.jsx("p",{className:"font-medium text-[var(--kyro-text)]",children:"No version history yet"}),jsxRuntime.jsx("p",{className:"text-sm mt-1",children:"Versions are automatically saved as you work."})]}):jsxRuntime.jsx("div",{className:"space-y-3 px-1 pb-4 pt-1",children:r.map(c=>{let m=c.id===o;return jsxRuntime.jsxs("div",{className:`p-4 rounded-xl border transition-all duration-200 group relative overflow-hidden ${m?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]/5 shadow-sm":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/30 hover:bg-[var(--kyro-surface-accent)] hover:shadow-sm bg-[var(--kyro-surface)]"}`,children:[m&&jsxRuntime.jsx("div",{className:"absolute top-0 left-0 w-1 h-full bg-[var(--kyro-primary)] shadow-[0_0_8px_var(--kyro-primary)]"}),jsxRuntime.jsxs("div",{className:"flex items-start justify-between gap-4",children:[jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[jsxRuntime.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold tracking-wide uppercase ${c.status==="published"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":"bg-zinc-500/10 text-zinc-600 dark:text-zinc-400"}`,children:[c.status==="published"&&jsxRuntime.jsx(lucideReact.CheckCircle2,{className:"w-3 h-3"}),c.status==="published"?"Published":"Draft"]}),jsxRuntime.jsxs("span",{className:"text-xs font-semibold text-[var(--kyro-text)] px-2 py-0.5 rounded-md bg-[var(--kyro-surface-accent)]",children:["v",c.version]}),m&&jsxRuntime.jsxs("span",{className:"text-[10px] font-medium text-[var(--kyro-primary)] flex items-center gap-1",children:[jsxRuntime.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-primary)] animate-pulse"}),"Current"]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium text-[var(--kyro-text)] truncate mb-1",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3.5 h-3.5 text-[var(--kyro-text-muted)]"}),d(c.createdAt)]}),c.createdBy&&jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-[var(--kyro-text-muted)] mt-1.5",children:[jsxRuntime.jsx(lucideReact.User,{className:"w-3.5 h-3.5"}),jsxRuntime.jsx("span",{children:c.createdBy.name||c.createdBy.email})]}),c.changelog&&jsxRuntime.jsxs("p",{className:"text-xs text-[var(--kyro-text-secondary)] mt-2 italic border-l-2 border-[var(--kyro-border)] pl-2",children:['"',c.changelog,'"']})]}),jsxRuntime.jsxs("div",{className:"flex flex-col sm:flex-row items-center gap-1.5 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>a(c),className:"p-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:bg-[var(--kyro-primary)]/10 rounded-md transition-colors",title:"Preview this version",children:jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"})}),s&&jsxRuntime.jsx("button",{type:"button",onClick:()=>s(c,r.find(y=>y.id===o)||c),className:"p-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:bg-[var(--kyro-primary)]/10 rounded-md transition-colors",title:"Compare with current",children:jsxRuntime.jsx(lucideReact.GitCompare,{className:"w-4 h-4"})}),!m&&jsxRuntime.jsx("button",{type:"button",onClick:()=>n(c),className:"p-2 text-amber-600 hover:bg-amber-500/10 rounded-md transition-colors",title:"Restore this version",children:jsxRuntime.jsx(lucideReact.Undo2,{className:"w-4 h-4"})})]})]})]},c.id)})})})}function dA({title:e,onMenuClick:t,actions:r}){return jsxRuntime.jsxs("header",{className:"kyro-header",children:[jsxRuntime.jsxs("div",{className:"kyro-header-left",children:[jsxRuntime.jsx("button",{type:"button",className:"kyro-header-menu",onClick:t,"aria-label":"Toggle menu",children:jsxRuntime.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M3 12h18M3 6h18M3 18h18"})})}),jsxRuntime.jsx("h1",{className:"kyro-header-title",children:e})]}),jsxRuntime.jsxs("div",{className:"kyro-header-right",children:[r,jsxRuntime.jsx("div",{className:"kyro-header-user",children:jsxRuntime.jsx("button",{type:"button",className:"kyro-header-user-btn",children:jsxRuntime.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("circle",{cx:"12",cy:"8",r:"4"}),jsxRuntime.jsx("path",{d:"M4 20c0-4 4-6 8-6s8 2 8 6"})]})})})]})]})}var nr={ready:[],beforeDeploy:[],afterDeploy:[]};function Yn(e){return nr.ready.push(e),()=>{nr.ready=nr.ready.filter(t=>t!==e);}}function rc(e){return nr.beforeDeploy.push(e),()=>{nr.beforeDeploy=nr.beforeDeploy.filter(t=>t!==e);}}function oc(e){return nr.afterDeploy.push(e),()=>{nr.afterDeploy=nr.afterDeploy.filter(t=>t!==e);}}async function ac(e){let t=[];for(let r of nr.ready)try{let o=await r(e);o&&typeof o=="object"&&"success"in o&&t.push(o);}catch(o){t.push({success:false,error:String(o)});}return t}async function nc(e){let t=[];for(let r of nr.beforeDeploy)try{let o=await r(e);o&&typeof o=="object"&&"success"in o&&t.push(o);}catch(o){t.push({success:false,error:String(o)});}return t}async function sc(e,t){for(let r of nr.afterDeploy)try{await r(e,t);}catch{}}function lc(e){return `${typeof window<"u"?window.location.origin:""}${e}`}function dc(e,t={}){let[r,o]=ka.useState(null),[a,n]=ka.useState(true),[s,i]=ka.useState(null),l=ka.useCallback(async()=>{n(true),i(null);try{let d=new URLSearchParams;t.page&&d.set("page",String(t.page)),t.limit&&d.set("limit",String(t.limit)),t.sort&&d.set("sort",t.sort),t.order&&d.set("order",t.order);let c=`${lc(`/api/${e}`)}?${d.toString()}`,m=await fetch(c,{credentials:"include"});if(!m.ok)throw new Error(`HTTP ${m.status}: ${m.statusText}`);let y=await m.json();o(y.data??y);}catch(d){i(d instanceof Error?d.message:String(d));}finally{n(false);}},[e,t.page,t.limit,t.sort,t.order]);return ka.useEffect(()=>{l();},[l]),{data:r,loading:a,error:s,refetch:l}}function cc(e,t="POST"){let[r,o]=ka.useState(false),[a,n]=ka.useState(null);return {mutate:ka.useCallback(async i=>{o(true),n(null);try{let l=lc(`/api/${e}`),d=await fetch(l,{method:t,credentials:"include",headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0});if(!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);let c=await d.json();return c.data??c}catch(l){return n(l instanceof Error?l.message:String(l)),null}finally{o(false);}},[e,t]),loading:r,error:a}}var oa=new Map;function aa(e){if(!e.name||typeof e.name!="string")throw new Error("Plugin must have a valid name");oa.has(e.name)&&console.warn(`Plugin "${e.name}" is already registered. Overwriting.`),oa.set(e.name,e),e.apply&&e.apply({});}function pc(e){oa.delete(e);}function mc(e){return oa.get(e)}function uc(){return Array.from(oa.values())}function yc(e){return Array.from(oa.values()).filter(t=>t.hooks&&typeof t.hooks[e]=="function")}var $u={name:"sample-plugin",version:"0.1.0",description:"A tiny sample plugin to demonstrate the extensibility surface",hooks:{onAdminReady:()=>{}}};aa($u);var Eu={name:"sample-plugin-2",version:"0.1.0",description:"Second MVP plugin demonstrating beforeDeploy hook",hooks:{beforeDeploy:e=>({success:true})}};aa(Eu);var na=new Map;function sa(e){if(!e.id||typeof e.id!="string")throw new Error("Block must have a valid id");if(!e.label)throw new Error("Block must have a label");na.set(e.id,e);}function fc(e){na.delete(e);}function vc(e){return na.get(e)}function gc(){return Array.from(na.values())}function bc(e){return Array.from(na.values()).filter(t=>t.category===e)}function xc(e){let t=na.get(e);return t?t.render:(console.warn(`Block "${e}" not found in registry`),null)}var Ou=e=>{let{data:t}=e;return jsxRuntime.jsxs("div",{style:{border:"1px solid #ccc",padding:8,borderRadius:6},children:[jsxRuntime.jsx("strong",{children:"Sample Block"}),jsxRuntime.jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},Uu={id:"sample-block",label:"Sample Block",category:"demo",schema:[{name:"title",label:"Title",type:"text",required:true}],render:Ou};sa(Uu);var ju=e=>{let{data:t}=e;return jsxRuntime.jsxs("div",{style:{border:"2px dashed #888",padding:10,borderRadius:8},children:[jsxRuntime.jsx("strong",{children:"Sample Block 2"}),jsxRuntime.jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},Hu={id:"sample-block-2",label:"Sample Block 2",category:"demo",schema:[{name:"subtitle",label:"Subtitle",type:"text",required:false}],render:ju};sa(Hu);var ia=new Map;function la(e){if(!e.id||typeof e.id!="string")throw new Error("Field must have a valid id");if(!e.type||typeof e.type!="string")throw new Error("Field must have a valid type");ia.set(e.id,e);}function wc(e){ia.delete(e);}function Nc(e){return ia.get(e)}function Cc(){return Array.from(ia.values())}function Sc(e){return Array.from(ia.values()).find(t=>t.type===e)}function Tc(e,t){let r=ia.get(e);if(!r)return console.warn(`Field "${e}" not found in registry`),null;let o=r.editor;return jsxRuntime.jsx(o,{...t})}var Ku=({name:e,value:t,onChange:r})=>jsxRuntime.jsx("input",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample text"}),Gu={id:"sample-text",type:"text",label:"Sample Text",editor:Ku};la(Gu);var qu=({name:e,value:t,onChange:r})=>jsxRuntime.jsx("textarea",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample textarea"}),Ju={id:"sample-textarea",type:"textarea",label:"Sample Textarea",editor:qu};la(Ju);var Ac=fr__default.default.resolve(new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,"lib/shim");fr__default.default.join(Ac,"use-sync-external-store.js");fr__default.default.join(Ac,"use-sync-external-store-with-selector.js");function ty(e={}){let{basePath:t="/admin",apiPath:r="/api",configPath:o="kyro.config.ts"}=e;return {name:"@kyro-cms/admin",hooks:{"astro:config:setup":async({config:a,updateConfig:n,injectRoute:s,logger:i})=>{i.info(`Kyro Admin mounted at ${t} (API: ${r})`);let l=fr__default.default.resolve(new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,"lib/default-kyro-config.ts"),d=fr__default.default.resolve(a.root.pathname,"..",o),c=fr__default.default.resolve(a.root.pathname,o),m=Ro__default.default.existsSync(d)?d:Ro__default.default.existsSync(c)?c:l;m!==l?i.info(`Loaded config from ${m}`):i.warn("Config file not found. Using defaults.");let y=fr__default.default.join(fr__default.default.dirname(m),".kyro-admin-config.json"),g="";try{let f=fr__default.default.join(fr__default.default.dirname(m),".env");Ro__default.default.existsSync(f)&&dotenv.config({path:f});let u=await esbuild.build({entryPoints:[m],bundle:!0,format:"esm",platform:"node",target:"es2022",write:!1,sourcemap:!1,loader:{".ts":"ts",".tsx":"tsx"},resolveExtensions:[".ts",".tsx",".js",".jsx",".mjs",".cjs",".json"],external:["@kyro-cms/*"]});g=m.replace(/\.ts$/,".admin.mjs"),Ro__default.default.writeFileSync(g,u.outputFiles[0].text,"utf8");let b=`
106
+ `}})]})]})]})}var fu=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function _d({collections:e}){let[t,r]=ka.useState([]),[o,a]=ka.useState(false),[n,s]=ka.useState(null),[i,l]=ka.useState(""),[d,c]=ka.useState(null),[m,u]=ka.useState(false),{confirm:g,alert:x}=ot(),[f,y]=ka.useState(false),[b,v]=ka.useState(""),R=async()=>{try{let p=await De("/api/keys");r(p);}catch(p){console.error(p);}};ka.useEffect(()=>{R();},[]);let L=async()=>{v(""),y(true);},C=async()=>{if(b.trim())try{await et("/api/keys",{name:b}),R(),y(!1),v(""),$.success("API key generated");}catch(p){console.error(p),$.error("Failed to generate API key");}},w=p=>{g({title:"Revoke API Key",message:"Are you sure you want to revoke this key? Any integrations using it will stop working.",variant:"danger",onConfirm:async()=>{try{await kt(`/api/keys/${p}`),R(),$.success("API key revoked");}catch(A){console.error(A),$.error("Failed to revoke API key");}}});},N=async()=>{if(i){u(true);try{let A=await(await fetch(qe(`/api/${i}`))).json();c(A);}catch{c({error:"Failed to fetch. Ensure the endpoint exists."});}finally{u(false);}}};return jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxRuntime.jsx(Ft,{title:"Developer Center",description:"Provision access keys and explore the headless API ecosystem.",icon:lucideReact.CodeXml,actions:[{label:"Generate Key",onClick:L,icon:lucideReact.Key}]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-8",children:[jsxRuntime.jsxs("section",{className:"xl:col-span-2 space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-2",children:[jsxRuntime.jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsxRuntime.jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40 uppercase",children:"Access Credentials"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:t.length===0?jsxRuntime.jsxs("div",{className:"p-12 text-center rounded-[2rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[jsxRuntime.jsx(lucideReact.Lock,{className:"w-10 h-10 mx-auto mb-4 opacity-20"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-50",children:"No API keys found. Generate one to get started."})]}):t.map(p=>jsxRuntime.jsx("div",{className:"group relative overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-3xl p-6 hover:border-[var(--kyro-primary)]/50 transition-all duration-300",children:jsxRuntime.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 relative z-10",children:[jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsxRuntime.jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsxRuntime.jsx(lucideReact.Key,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsxRuntime.jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors truncate",children:p.name})]}),jsxRuntime.jsxs("div",{className:"flex-1 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-2xl px-4 py-3 flex items-center justify-between group/key overflow-hidden",children:[jsxRuntime.jsx("code",{className:"text-xs font-mono opacity-80 truncate mr-4",children:n===p.id?p.key:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>s(n===p.id?null:p.id),className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all text-[var(--kyro-text-secondary)]",children:n===p.id?jsxRuntime.jsx(lucideReact.EyeOff,{className:"w-4 h-4"}):jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"})}),jsxRuntime.jsx("button",{type:"button",className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all text-[var(--kyro-text-secondary)]",onClick:()=>{navigator.clipboard.writeText(p.key),$.success("API key copied to clipboard");},children:jsxRuntime.jsx(lucideReact.Copy,{className:"w-4 h-4"})})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-6 mt-4 text-[10px] font-bold opacity-30 uppercase tracking-widest",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{children:"Issued:"}),jsxRuntime.jsx("span",{children:new Date(p.createdAt).toLocaleDateString()})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{children:"Status:"}),jsxRuntime.jsx("span",{className:"text-green-500",children:"Active"})]})]})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>w(p.id),className:"p-3.5 bg-red-500/5 text-red-500 rounded-2xl hover:bg-red-500/10 transition-all border border-transparent hover:border-red-500/30 self-start md:self-center",title:"Revoke Key",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-5 h-5"})})]})},p.id))})]}),jsxRuntime.jsxs("section",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"relative overflow-hidden rounded-[2.5rem] border border-[var(--kyro-border)] bg-gradient-to-br from-[var(--kyro-primary)] to-[var(--kyro-primary)]/80 p-8 group shadow-2xl shadow-[var(--kyro-primary)]/20",children:[jsxRuntime.jsx("div",{className:"absolute top-0 right-0 p-8 opacity-[0.1] pointer-events-none group-hover:scale-110 transition-transform duration-700",children:jsxRuntime.jsx(lucideReact.Terminal,{className:"w-48 h-48 rotate-12"})}),jsxRuntime.jsxs("div",{className:"relative z-10",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 bg-white/20 backdrop-blur-md rounded-2xl flex items-center justify-center mb-6",children:jsxRuntime.jsx(lucideReact.Terminal,{className:"w-6 h-6 text-white"})}),jsxRuntime.jsx("h3",{className:"text-white text-2xl font-bold tracking-tight mb-3",children:"Endpoint Hub"}),jsxRuntime.jsx("p",{className:"text-white/80 text-sm font-medium leading-relaxed mb-8",children:"Kyro CMS is built for high-performance content delivery. Use these endpoints to power your headless frontends."}),jsxRuntime.jsxs("button",{type:"button",className:"w-full py-4 bg-white text-[var(--kyro-primary)] rounded-[1.2rem] font-bold text-xs uppercase tracking-widest hover:shadow-xl transition-all flex items-center justify-center gap-2 active:scale-[0.98]",children:["Full API Documentation",jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-3.5 h-3.5"})]})]})]}),jsxRuntime.jsxs("div",{className:"rounded-[2.5rem] border border-[var(--kyro-border)] bg-[var(--kyro-surface)]/50 p-8 space-y-6",children:[jsxRuntime.jsx("h4",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Environment Matrix"}),jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold",children:"Content API"}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Production"})]}),jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsx("div",{className:"absolute -inset-0.5 bg-gradient-to-r from-[var(--kyro-primary)]/30 to-transparent rounded-xl blur opacity-0 group-hover:opacity-100 transition-all"}),jsxRuntime.jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsxRuntime.jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://api.kyro.io/v1"}),jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5 opacity-0 group-hover:opacity-40 cursor-pointer transition-opacity",onClick:()=>navigator.clipboard.writeText("https://api.kyro.io/v1")})]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold",children:"Draft Explorer"}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Staging"})]}),jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsx("div",{className:"absolute -inset-0.5 bg-gradient-to-r from-amber-500/30 to-transparent rounded-xl blur opacity-0 group-hover:opacity-100 transition-all"}),jsxRuntime.jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsxRuntime.jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://preview.kyro.io/v1"}),jsxRuntime.jsx(lucideReact.Copy,{className:"w-3.5 h-3.5 opacity-0 group-hover:opacity-40 cursor-pointer transition-opacity",onClick:()=>navigator.clipboard.writeText("https://preview.kyro.io/v1")})]})]})]})]})]})]}),jsxRuntime.jsxs("section",{className:"xl:col-span-3 rounded-[3rem] border border-[var(--kyro-border)] bg-[var(--kyro-surface)]/50 p-10 space-y-10 overflow-hidden relative",children:[jsxRuntime.jsx("div",{className:"absolute top-0 right-0 p-20 opacity-[0.02] pointer-events-none",children:jsxRuntime.jsx(lucideReact.CirclePlay,{className:"w-96 h-96"})}),jsxRuntime.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-10 relative z-10",children:[jsxRuntime.jsxs("div",{className:"max-w-xl",children:[jsxRuntime.jsxs("h2",{className:"text-3xl font-bold tracking-tighter flex items-center gap-4 mb-3",children:[jsxRuntime.jsx("div",{className:"w-12 h-12 bg-[var(--kyro-primary)]/10 rounded-2xl flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.CirclePlay,{className:"w-7 h-7 text-[var(--kyro-primary)]"})}),"API ",jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:"Explorer"})]}),jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] text-sm font-medium opacity-60 leading-relaxed",children:"Test your collection endpoints and analyze live response payloads. Enter a collection slug to fetch its latest documents."})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 flex-1 lg:max-w-2xl bg-[var(--kyro-bg)] p-2 rounded-[2rem] border border-[var(--kyro-border)] shadow-2xl",children:[jsxRuntime.jsxs("div",{className:"flex-1 relative flex items-center pl-6",children:[jsxRuntime.jsxs("span",{className:"text-[11px] font-bold opacity-30 uppercase tracking-widest mr-2 whitespace-nowrap",children:["GET ",fu,"/"]}),jsxRuntime.jsx("input",{type:"text",value:i,onChange:p=>l(p.target.value),placeholder:"collection-slug",className:"w-full py-4 bg-transparent focus:outline-none font-mono text-sm font-bold text-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("button",{type:"button",onClick:N,disabled:m||!i,className:"kyro-btn kyro-btn-primary px-8 py-4 rounded-[1.5rem] font-bold text-sm shadow-xl disabled:opacity-50 disabled:cursor-not-allowed hover:scale-[1.02] transition-all flex items-center gap-3 shrink-0",children:[m?jsxRuntime.jsx(lucideReact.RefreshCcw,{className:"w-4 h-4 animate-spin"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"w-5 h-5"}),"Run Query"]})]})]}),d?jsxRuntime.jsxs("div",{className:"animate-in fade-in zoom-in-95 duration-500 relative z-10",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-4 px-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("div",{className:"w-1 h-3 bg-[var(--kyro-primary)] rounded-full"}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Response Payload"})]}),jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[9px] font-mono px-3",children:"200 OK"})]}),jsxRuntime.jsxs("div",{className:"rounded-[2rem] overflow-hidden border border-[var(--kyro-border)] shadow-2xl bg-[#090b10]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-6 py-4 bg-[#11141d] border-b border-[var(--kyro-border)]/50",children:[jsxRuntime.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500/20"}),jsxRuntime.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-amber-500/20"}),jsxRuntime.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500/20"})]}),jsxRuntime.jsx(mu__default.default,{value:JSON.stringify(d,null,2),height:"450px",theme:codemirrorThemeAura.aura,extensions:[langJson.json()],editable:false,className:"text-sm"})]})]}):jsxRuntime.jsxs("div",{className:"h-80 rounded-[3rem] border-2 border-dashed border-[var(--kyro-border)] flex flex-col items-center justify-center bg-[var(--kyro-surface-accent)]/20 transition-all duration-700",children:[jsxRuntime.jsx("div",{className:"w-20 h-20 bg-[var(--kyro-surface)] rounded-3xl flex items-center justify-center shadow-lg border border-[var(--kyro-border)] mb-6 opacity-20",children:jsxRuntime.jsx(lucideReact.CodeXml,{className:"w-10 h-10"})}),jsxRuntime.jsx("p",{className:"font-bold text-sm opacity-30 uppercase tracking-[0.2em]",children:"Awaiting request dispatch..."})]})]})]}),jsxRuntime.jsxs(Ut,{open:f,onClose:()=>y(false),title:"Generate Access Token",size:"lg",children:[jsxRuntime.jsx(Or,{children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70 leading-relaxed",children:"Define a name for this API key to identify its integration context. Keys are encrypted at rest and should be treated with extreme caution."}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("label",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Token Name"}),jsxRuntime.jsx("input",{type:"text",value:b,onChange:p=>v(p.target.value),placeholder:"e.g., Mobile App SDK, Production Server",className:"w-full px-6 py-4 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-2xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)] shadow-sm transition-all",onKeyDown:p=>p.key==="Enter"&&C()})]})]})}),jsxRuntime.jsxs(Ur,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>y(false),className:"px-6 py-3 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:C,className:"kyro-btn kyro-btn-primary px-8 py-3 rounded-xl font-bold text-sm hover:opacity-90 shadow-lg shadow-[var(--kyro-primary)]/20 transition-all",children:"Generate Token"})]})]})]})}function Vd(e){let[t,r]=ka.useState([]),[o,a]=ka.useState(false),[n,s]=ka.useState(null),[i,l]=ka.useState(false),{confirm:d}=ot(),c=ka.useCallback(async()=>{a(true),s(null);try{let x=await De(e.endpoint),f=Array.isArray(x)?x:x.docs||[],y=e.transformLoad?e.transformLoad(f):f;r(y),e.onSuccess?.("load",y);}catch(x){let f=x instanceof Error?x.message:"Failed to load resources";s(f),e.onError?.("load",x);}finally{a(false);}},[e.endpoint,e.transformLoad]);ka.useEffect(()=>{c();},[c]);let m=ka.useCallback((x,f="item")=>{d({title:`Delete ${f}`,message:`Are you sure you want to delete this ${f.toLowerCase()}? This action cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await kt(`${e.endpoint}/${x}`),r(y=>y.filter(b=>b.id!==x)),e.onSuccess?.("delete",x),$.success(`${f} deleted`);}catch(y){let b=y instanceof Error?y.message:`Failed to delete ${f}`;$.error(b),e.onError?.("delete",y);}}});},[e.endpoint,d]),u=ka.useCallback(async x=>{s(null);try{let f=await et(e.endpoint,x);return r(y=>[f,...y]),l(!1),e.onSuccess?.("create",f),f}catch(f){let y=f instanceof Error?f.message:"Failed to create resource";throw s(y),e.onError?.("create",f),f}},[e.endpoint]),g=ka.useCallback(async(x,f)=>{s(null);try{let y=await Xt(`${e.endpoint}/${x}`,f);return r(b=>b.map(v=>v.id===x?y:v)),e.onSuccess?.("update",y),y}catch(y){let b=y instanceof Error?y.message:"Failed to update resource";throw s(b),e.onError?.("update",y),y}},[e.endpoint]);return {items:t,setItems:r,loading:o,error:n,load:c,remove:m,create:u,update:g,isCreateModalOpen:i,setIsCreateModalOpen:l}}function Kd(){let{items:e,loading:t,create:r,remove:o,update:a,isCreateModalOpen:n,setIsCreateModalOpen:s}=Vd({endpoint:"/api/webhooks"}),{confirm:i}=ot(),[l,d]=ka.useState(false),[c,m]=ka.useState(false),[u,g]=ka.useState(null),[x,f]=ka.useState(null),[y,b]=ka.useState({name:"",url:"",events:[],secret:""}),[v,R]=ka.useState(""),L=async()=>{if(!y.name.trim()||!y.url.trim()){R("Name and URL are required");return}try{await r(y),b({name:"",url:"",events:[],secret:""}),$.success(`Webhook established: ${y.name}`);}catch{R("Failed to create webhook"),$.error("Failed to create webhook");}},C=async p=>{f(p),g(null),d(true);try{let A=await et(`/api/webhooks/${p}/test`);g({success:!0,message:A.message||"Webhook triggered successfully"}),$.success("Dispatch verified: Remote endpoint responded");}catch{g({success:false,message:"Failed to trigger webhook"});}},w=async(p,A)=>{try{let O=A==="active"?"paused":"active";await a(p,{status:O}),$.success(O==="active"?"Signals resumed":"Dispatcher paused");}catch(O){console.error(O),$.error("Failed to toggle webhook status");}},N=[{label:"Create",value:"create",description:"When a new document is created"},{label:"Update",value:"update",description:"When a document is updated"},{label:"Delete",value:"delete",description:"When a document is deleted"},{label:"Auth",value:"auth",description:"User login/logout events"}];return jsxRuntime.jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxRuntime.jsx(Ft,{title:"Webhooks",description:"Receive real-time notifications when your content changes.",icon:lucideReact.Webhook,actions:[{label:"Create Webhook",onClick:()=>{b({name:"",url:"",events:["collection.create","collection.update","collection.delete"],secret:""}),R(""),s(true);},icon:lucideReact.Plus},{label:"Guide",onClick:()=>m(true),icon:lucideReact.Info,variant:"outline"}]}),jsxRuntime.jsxs("div",{className:"relative overflow-hidden rounded-[2rem] border border-[var(--kyro-border)] bg-gradient-to-br from-[var(--kyro-surface)] to-[var(--kyro-surface-accent)] p-8",children:[jsxRuntime.jsx("div",{className:"absolute top-0 right-0 p-8 opacity-[0.03] pointer-events-none",children:jsxRuntime.jsx(lucideReact.Zap,{className:"w-64 h-64 rotate-12"})}),jsxRuntime.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-8 relative z-10",children:[jsxRuntime.jsx("div",{className:"p-5 bg-gradient-to-br from-[var(--kyro-primary)] to-[var(--kyro-primary)]/50 rounded-[1.5rem] shadow-xl shadow-[var(--kyro-primary)]/20",children:jsxRuntime.jsx(lucideReact.Zap,{className:"w-8 h-8 text-white"})}),jsxRuntime.jsxs("div",{className:"flex-1 text-center md:text-left",children:[jsxRuntime.jsx("h3",{className:"text-xl font-bold mb-2",children:"Real-time Event Synchronization"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70 max-w-2xl leading-relaxed",children:"Webhooks allow your application to receive instant HTTP notifications when events happen in your CMS. Eliminate polling and build responsive, event-driven architectures with ease."})]}),jsxRuntime.jsxs("div",{className:"flex gap-4",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center px-4 py-2 bg-[var(--kyro-surface)]/50 border border-[var(--kyro-border)] rounded-2xl",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Collections"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"Triggered"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col items-center px-4 py-2 bg-[var(--kyro-surface)]/50 border border-[var(--kyro-border)] rounded-2xl",children:[jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Latency"}),jsxRuntime.jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"<200ms"})]})]})]})]}),jsxRuntime.jsxs("section",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsxRuntime.jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40",children:"ACTIVE ENDPOINTS"})]}),jsxRuntime.jsxs("div",{className:"text-[10px] font-bold opacity-40 uppercase",children:[e.length," Hook",e.length!==1&&"s"]})]}),t?jsxRuntime.jsx("div",{className:"flex items-center justify-center p-20 surface-tile rounded-3xl opacity-50 italic",children:"Connecting to dispatcher..."}):e.length===0?jsxRuntime.jsxs("div",{className:"p-16 text-center rounded-[3rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[jsxRuntime.jsx("div",{className:"w-20 h-20 mx-auto mb-6 bg-gradient-to-tr from-[var(--kyro-surface)] to-[var(--kyro-surface-accent)] rounded-3xl flex items-center justify-center shadow-xl border border-[var(--kyro-border)]",children:jsxRuntime.jsx(lucideReact.Webhook,{className:"w-10 h-10 text-[var(--kyro-primary)]"})}),jsxRuntime.jsx("h3",{className:"text-2xl font-bold mb-3",children:"No Webhooks Found"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-60 mb-8 max-w-sm mx-auto",children:"Your CMS is currently silent. Create a webhook to start broadcasting events to your external services."}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>s(true),className:"kyro-btn kyro-btn-primary inline-flex items-center gap-3 px-8 py-4 rounded-2xl font-bold hover:scale-[1.05] transition-all shadow-xl shadow-[var(--kyro-primary)]/10",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-5 h-5"}),"Configure Webhook"]})]}):jsxRuntime.jsx("div",{className:"grid gap-4",children:e.map(p=>jsxRuntime.jsx("div",{className:"group relative overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-3xl p-6 hover:border-[var(--kyro-primary)]/50 transition-all duration-300",children:jsxRuntime.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 relative z-10",children:[jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsxRuntime.jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsxRuntime.jsx(lucideReact.Webhook,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors",children:p.name}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[jsxRuntime.jsx("span",{className:`w-2 h-2 rounded-full ${p.status==="active"?"bg-green-500 animate-pulse":"bg-amber-500"}`}),jsxRuntime.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${p.status==="active"?"text-green-500":"text-amber-500"}`,children:p.status})]})]})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 pt-2",children:[jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Destination"}),jsxRuntime.jsx("div",{className:"font-mono text-xs opacity-60 truncate max-w-[200px]",title:p.url,children:p.url})]}),jsxRuntime.jsxs("div",{className:"space-y-1 sm:border-l border-t sm:border-t-0 border-[var(--kyro-border)] pt-4 sm:pt-0 sm:pl-6 mt-4 sm:mt-0",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Events"}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-1",children:[p.events.slice(0,2).map(A=>jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[8px] font-bold px-1.5 opacity-60",children:A},A)),p.events.length>2&&jsxRuntime.jsxs("span",{className:"text-[8px] font-bold opacity-30",children:["+",p.events.length-2," more"]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-1 sm:border-l border-t sm:border-t-0 border-[var(--kyro-border)] pt-4 sm:pt-0 sm:pl-6 mt-4 sm:mt-0",children:[jsxRuntime.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Activity"}),jsxRuntime.jsxs("div",{className:"text-[10px] font-bold opacity-60 flex items-center gap-1.5",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3 h-3"}),p.lastTriggered?`Last triggered: ${new Date(p.lastTriggered).toLocaleDateString()}`:"Never triggered"]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 lg:bg-[var(--kyro-surface-accent)]/50 lg:p-2 lg:rounded-2xl lg:opacity-0 group-hover:opacity-100 transition-all duration-300 lg:translate-x-4 group-hover:translate-x-0",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>C(p.id),className:"flex-1 lg:flex-none p-3 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl hover:border-[var(--kyro-primary)] transition-all flex items-center justify-center gap-2",title:"Send test request",children:[jsxRuntime.jsx(lucideReact.Send,{className:"w-4 h-4"}),jsxRuntime.jsx("span",{className:"text-xs font-bold",children:"Test"})]}),jsxRuntime.jsx("div",{className:"w-px h-6 bg-[var(--kyro-border)] mx-1 hidden lg:block"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>w(p.id,p.status),className:`p-3 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl hover:border-[var(--kyro-primary)] transition-all group/toggle ${p.status==="active"?"text-amber-500/50 hover:text-amber-500":"text-green-500/50 hover:text-green-500"}`,title:p.status==="active"?"Pause webhook":"Activate webhook",children:p.status==="active"?jsxRuntime.jsx(lucideReact.Pause,{className:"w-4 h-4"}):jsxRuntime.jsx(lucideReact.Play,{className:"w-4 h-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o(p.id,"Webhook"),className:"p-3 bg-red-500/5 border border-red-500/10 rounded-xl hover:bg-red-500/10 hover:border-red-500/30 transition-all group/delete",title:"Delete webhook",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4 text-red-500/50 group-hover/delete:text-red-500"})})]})]})},p.id))})]}),jsxRuntime.jsxs(Ut,{open:n,onClose:()=>s(false),title:"Register Webhook",size:"lg",children:[jsxRuntime.jsx(Or,{children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-6",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Webhook Name"}),jsxRuntime.jsx("input",{type:"text",value:y.name,onChange:p=>b({...y,name:p.target.value}),placeholder:"e.g., Slack Notifications",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Payload URL"}),jsxRuntime.jsx("input",{type:"url",value:y.url,onChange:p=>b({...y,url:p.target.value}),placeholder:"https://your-server.com/webhook",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Signing Secret"}),jsxRuntime.jsx("input",{type:"text",value:y.secret,onChange:p=>b({...y,secret:p.target.value}),placeholder:"Optional secret for verification",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Subscribed Events"}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:N.map(p=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{let A=y.events.includes(p.value)?y.events.filter(O=>O!==p.value):[...y.events,p.value];b({...y,events:A});},className:`flex items-center gap-3 p-3 rounded-lg border transition-all text-left ${y.events.includes(p.value)?"bg-[var(--kyro-primary)]/5 border-[var(--kyro-primary)]/30 text-[var(--kyro-primary)]":"bg-[var(--kyro-surface-accent)]/50 border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/30"}`,children:[jsxRuntime.jsx("div",{className:`w-4 h-4 rounded flex items-center justify-center border transition-all ${y.events.includes(p.value)?"bg-[var(--kyro-primary)] border-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:y.events.includes(p.value)&&jsxRuntime.jsx(lucideReact.CircleCheck,{className:"w-3 h-3 text-white"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-xs font-bold",children:p.label}),jsxRuntime.jsx("div",{className:"text-[10px] opacity-50",children:p.description})]})]},p.value))})]})]}),v&&jsxRuntime.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-xl flex items-center gap-2 text-red-500 text-xs font-bold",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-4 h-4"}),v]})]})}),jsxRuntime.jsxs(Ur,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>s(false),className:"px-6 py-2.5 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:L,className:"kyro-btn kyro-btn-primary px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10",children:"Create Webhook"})]})]}),jsxRuntime.jsxs(Ut,{open:l,onClose:()=>d(false),title:"Webhook Test Dispatcher",children:[jsxRuntime.jsx(Or,{children:jsxRuntime.jsx("div",{className:"p-8 rounded-[2rem] bg-[var(--kyro-surface-accent)]/30 border border-[var(--kyro-border)] text-center",children:u?jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx("div",{className:`w-16 h-16 mx-auto rounded-2xl flex items-center justify-center shadow-xl ${u.success?"bg-green-500/10 text-green-500":"bg-red-500/10 text-red-500"}`,children:u.success?jsxRuntime.jsx(lucideReact.CircleCheck,{className:"w-8 h-8"}):jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-8 h-8"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-xl font-bold mb-2",children:u.success?"Dispatch Successful":"Dispatch Failed"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70",children:u.message})]})]}):jsxRuntime.jsxs("div",{className:"space-y-6 py-4",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"w-12 h-12 text-[var(--kyro-primary)] animate-spin mx-auto opacity-50"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-xl font-bold mb-1",children:"Synthesizing Payload"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-50 italic",children:"Dispatching to remote endpoint..."})]})]})})}),jsxRuntime.jsx(Ur,{children:jsxRuntime.jsx("button",{type:"button",onClick:()=>d(false),className:"w-full py-3 rounded-xl font-bold text-sm bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] hover:bg-[var(--kyro-surface)] transition-all",children:"Acknowledge"})})]}),jsxRuntime.jsxs(Ut,{open:c,onClose:()=>m(false),title:"Webhook Integration Guide",size:"lg",children:[jsxRuntime.jsx(Or,{children:jsxRuntime.jsxs("div",{className:"space-y-8",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 gap-6",children:[jsxRuntime.jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Request Context"]}),jsxRuntime.jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["When an event triggers, Kyro sends a standard ",jsxRuntime.jsx("span",{className:"font-bold text-[var(--kyro-text-primary)]",children:"POST"})," request to your endpoint with a JSON payload containing document metadata and operation details."]})]}),jsxRuntime.jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Shield,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Security Verification"]}),jsxRuntime.jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["If a secret is provided, each request includes an ",jsxRuntime.jsx("span",{className:"font-mono text-[var(--kyro-primary)]",children:"X-Kyro-Signature"})," header. Always verify this signature in production environments."]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("h4",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Payload Architecture"}),jsxRuntime.jsxs("div",{className:"relative group",children:[jsxRuntime.jsx("div",{className:"absolute -inset-1 bg-gradient-to-r from-[var(--kyro-primary)]/20 to-transparent rounded-2xl blur opacity-25 group-hover:opacity-50 transition-all"}),jsxRuntime.jsxs("div",{className:"relative bg-[var(--kyro-bg)] rounded-2xl border border-[var(--kyro-border)] p-6 font-mono text-sm overflow-hidden",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-4 border-b border-[var(--kyro-border)] pb-4 opacity-30",children:[jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-red-500/50"}),jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500/50"}),jsxRuntime.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500/50"}),jsxRuntime.jsx("span",{className:"text-[10px] ml-2 tracking-tighter",children:"payload.json"})]}),jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"{"}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"event"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"collection.create"'}),","]}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"collection"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"products"'}),","]}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"id"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"prod_8273"'}),","]}),jsxRuntime.jsxs("div",{className:"pl-4",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"timestamp"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"2026-05-14T02:53:22Z"'})]}),jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"}"})]})]})]})]})]})}),jsxRuntime.jsx(Ur,{children:jsxRuntime.jsx("button",{type:"button",onClick:()=>m(false),className:"kyro-btn kyro-btn-primary w-full py-3 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/20",children:"I Understand"})})]})]})}function qd({isOpen:e,onClose:t,collections:r,globals:o,onNavigate:a}){let{user:n,permissions:s}=Lr(),[i,l]=ka.useState(""),[d,c]=ka.useState(0),[m,u]=ka.useState(false),[g,x]=ka.useState([]),f=ka.useRef(null),y=ka.useRef(null);ka.useEffect(()=>{e&&(l(""),c(0),x([]),u(false),setTimeout(()=>f.current?.focus(),100));},[e]);let b=ka.useCallback(async S=>{if(!S||S.length<2){x([]);return}u(true);try{let j=await(await fetch(qe(`/api/search?q=${encodeURIComponent(S)}&limit=15`))).json();j.results&&x(j.results);}catch(M){console.error("Search error:",M),x([]);}finally{u(false);}},[]);if(ka.useEffect(()=>(y.current&&clearTimeout(y.current),i.length>=2?y.current=setTimeout(()=>b(i),300):x([]),()=>{y.current&&clearTimeout(y.current);}),[i,b]),!e)return null;let v=Object.entries(r).filter(([S])=>s?.collections?.[S]?.read!==false).map(([S,M])=>({id:`col-${S}`,label:M.label||S,type:"collection",slug:S,icon:lucideReact.FileText})),R=Object.entries(o).filter(([S])=>s?.globals?.[S]?.read!==false).map(([S,M])=>({id:`global-${S}`,label:M.label||S,type:"global",slug:S,icon:lucideReact.Settings})),L=typeof document<"u"&&document.documentElement.classList.contains("dark"),C=n?.role==="admin",w=[{id:"action-media",label:"Media Gallery",type:"action",view:"media",icon:lucideReact.Image,visible:s?.collections?.media?.read!==false},{id:"action-users",label:"Team Management",type:"action",view:"users",icon:lucideReact.Clock,visible:C},{id:"action-audit",label:"Audit Logs",type:"action",view:"audit",icon:lucideReact.File,visible:C},{id:"action-roles",label:"Roles & Permissions",type:"action",view:"roles",icon:lucideReact.Shield,visible:C},{id:"action-api",label:"REST API Explorer",type:"action",view:"api-explorer",icon:lucideReact.Database,visible:C},{id:"action-graphql",label:"GraphQL Playground",type:"action",view:"graphql",icon:lucideReact.Hexagon,visible:C},{id:"action-rest",label:"REST Playground",type:"action",view:"rest",icon:lucideReact.Network,visible:C},{id:"action-theme",label:L?"Switch to Light Mode":"Switch to Dark Mode",type:"action",view:"theme",icon:L?lucideReact.Sun:lucideReact.Moon,visible:true},{id:"action-logout",label:"Sign Out",type:"action",view:"logout",icon:lucideReact.LogOut,visible:true}].filter(S=>S.visible),N=g.map((S,M)=>({id:`doc-${S.collection}-${S.id}`,label:S.title,type:"document",collection:S.collection,label2:S.label,docId:S.id,icon:lucideReact.File,doc:S.doc})),p=i.length>=2?[...w,...v,...R,...N]:[...w,...v,...R],A=i===""?p:p.filter(S=>S.label.toLowerCase().includes(i.toLowerCase())),O=S=>{if(S.key==="ArrowDown")S.preventDefault(),c(M=>(M+1)%A.length);else if(S.key==="ArrowUp")S.preventDefault(),c(M=>(M-1+A.length)%A.length);else if(S.key==="Enter"){let M=A[d];M&&F(M);}else S.key==="Escape"&&t();},F=S=>{S.type==="collection"?S.slug==="users"?a(S.slug,S.slug):a("list",S.slug):S.type==="global"?a("settings",S.slug):S.type==="document"?S.collection==="users"?a("users","users",S.docId):a("edit",S.collection,S.docId):S.type==="action"&&(S.view==="users"?a("users","users"):S.view==="media"?a("media","media"):a(S.view,S.view)),t();},P=()=>i===""?"Quick Actions & Collections":g.length>0?"Documents":m?"Searching...":"Search Results";return jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-start justify-center pt-[15vh] px-4",children:[jsxRuntime.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm animate-in fade-in duration-300",onClick:t}),jsxRuntime.jsxs("div",{className:"relative w-full max-w-2xl bg-[var(--kyro-surface)] rounded-3xl shadow-2xl overflow-hidden animate-in zoom-in-95 fade-in duration-300 ring-1 ring-white/10 border border-white/5",children:[jsxRuntime.jsxs("div",{className:"flex items-center px-6 py-5 border-b border-[var(--kyro-border)]",children:[m?jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4 animate-spin"}):jsxRuntime.jsx(lucideReact.Search,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4"}),jsxRuntime.jsx("input",{ref:f,placeholder:"Search anything...",className:"flex-1 bg-transparent border-none focus:outline-none text-lg font-medium text-[var(--kyro-text-primary)] placeholder:text-[var(--kyro-text-muted)]",value:i,onChange:S=>l(S.target.value),onKeyDown:O}),jsxRuntime.jsx("div",{className:"flex items-center gap-2 px-2 py-1 bg-[var(--kyro-bg-secondary)] rounded-lg border border-[var(--kyro-border)]",children:jsxRuntime.jsx("span",{className:"text-[10px] font-bold opacity-40 tracking-widest",children:"ESC"})})]}),jsxRuntime.jsx("div",{className:"max-h-[400px] overflow-y-auto py-4",children:A.length>0?jsxRuntime.jsxs("div",{className:"space-y-1 px-4",children:[jsxRuntime.jsx("p",{className:"px-4 text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4",children:P()}),A.map((S,M)=>jsxRuntime.jsxs("div",{onClick:()=>F(S),onMouseEnter:()=>c(M),className:`flex items-center justify-between px-4 py-4 rounded-2xl cursor-pointer ${M===d?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] shadow-xl shadow-[var(--kyro-primary)]":"hover:bg-[var(--kyro-bg-secondary)] text-[var(--kyro-text-secondary)]"}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx("div",{className:`p-2 rounded-xl ${M===d?"bg-white/20":"bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)]"}`,children:jsxRuntime.jsx(S.icon,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-bold text-sm",children:S.label}),S.type==="document"&&S.label2&&jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest ${M===d?"text-[var(--kyro-sidebar-text-active)]/60":"opacity-40"}`,children:S.label2})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest opacity-40 ${M===d?"text-[var(--kyro-sidebar-text-active)] p-1":""}`,children:S.type}),M===d&&jsxRuntime.jsx(lucideReact.ArrowRight,{className:"w-4 h-4 mr-2"})]})]},S.id))]}):jsxRuntime.jsx("div",{className:"py-12 text-center",children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] italic opacity-60",children:i.length>=2&&!m?`No results found for "${i}"`:"Start typing to search..."})})}),jsxRuntime.jsxs("div",{className:"px-8 py-4 bg-[var(--kyro-bg-secondary)] border-t border-[var(--kyro-border)] flex items-center justify-between text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-60",children:[jsxRuntime.jsxs("div",{className:"flex gap-6",children:[jsxRuntime.jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u2191\u2193 Navigate"}),jsxRuntime.jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u23CE Select"})]}),jsxRuntime.jsx("div",{children:"Kyro Universal Search"})]})]})]})}function Jd(){let{modal:e,closeModal:t}=ot(),[r,o]=ka.useState(false);if(!e.open||!e.config)return null;let{config:a}=e,n=async()=>{if(a.onConfirm)try{o(!0),await a.onConfirm();}catch(i){console.error("Modal confirm action failed:",i);}finally{o(false),t();}else t();},s=()=>{a.onCancel&&a.onCancel(),t();};return jsxRuntime.jsx(xs,{open:e.open,onClose:s,onConfirm:n,title:a.title,message:a.message,confirmLabel:a.confirmLabel,cancelLabel:a.cancelLabel,variant:a.variant==="danger"?"danger":"default",loading:r})}function ku({config:e,theme:t="light",onThemeChange:r}){let[o,a]=ka.useState(false),[n,s]=ka.useState(null),i=ka.useMemo(()=>Dn(Fa(e.collections)),[e.collections]),l=ka.useMemo(()=>Bn(Fa(e.globals)),[e.globals]),[d,c]=ka.useState(null),[m,u]=ka.useState(null),[g,x]=ka.useState("list"),[f,y]=ka.useState(null),[b,v]=ka.useState(false);ka.useEffect(()=>{(async()=>{try{let N=await fetch("/api/users/me");if(N.ok){let p=await N.json();s(p),a(!0);}}catch(N){console.error("Auth check failed",N);}})();},[]),ka.useEffect(()=>{if(o&&!d){let w=Object.keys(i)[0];w&&c(w);}},[o,i,d]);let R=(w,N=null,p=null)=>{x(w),N&&c(N),p&&y(p),v(false);};ka.useEffect(()=>{let w=N=>{(N.metaKey||N.ctrlKey)&&N.key==="k"&&(N.preventDefault(),v(p=>!p));};return window.addEventListener("keydown",w),window.openCommandPalette=()=>v(true),()=>{window.removeEventListener("keydown",w),delete window.openCommandPalette;}},[]);return o?jsxRuntime.jsx(kr,{mode:t,onChange:r,children:jsxRuntime.jsxs("div",{className:"kyro-admin min-h-screen bg-[var(--kyro-bg)] text-[var(--kyro-text-primary)]",children:[jsxRuntime.jsx("div",{className:"flex h-screen overflow-hidden",children:jsxRuntime.jsx("main",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:jsxRuntime.jsxs("div",{className:"flex-1 overflow-y-auto",children:[jsxRuntime.jsx(qd,{isOpen:b,onClose:()=>v(false),collections:i,globals:l,onNavigate:R}),(()=>{let w=d?i[d]:null;switch(g){case "create":return w?jsxRuntime.jsx(ei,{config:e,collection:w,onSuccess:()=>x("list"),onCancel:()=>x("list"),onError:N=>$.error(N)}):null;case "detail":return w&&f?jsxRuntime.jsx(Zs,{config:e,collection:w,documentId:f,onBack:()=>x("list"),onSave:()=>{},onError:N=>$.error(N)}):null;case "users":return jsxRuntime.jsx(jd,{});case "media":return jsxRuntime.jsx(xn,{});case "branding":return jsxRuntime.jsx(Hd,{});case "developer":return jsxRuntime.jsx(_d,{collections:i});case "webhooks":return jsxRuntime.jsx(Kd,{});default:return w?jsxRuntime.jsx(vs,{config:e,collection:w,onCreate:()=>x("create"),onEdit:N=>R("detail",d,N)}):jsxRuntime.jsx(Ud,{onNavigate:R,collections:i,user:n})}})()]})})}),jsxRuntime.jsx(Jd,{}),jsxRuntime.jsx(Gn,{})]})}):jsxRuntime.jsx(oi,{onAuth:(w,N)=>{s(N),a(true);},theme:t})}function hu({selectedCount:e,onClearSelection:t,actions:r,onSelectAll:o}){return e===0?null:jsxRuntime.jsxs("div",{className:"flex items-center justify-between py-2 px-4 bg-gray-50 border-b border-gray-200",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(ms,{count:e}),jsxRuntime.jsx("span",{className:"text-sm text-gray-600",children:"selected"})]}),jsxRuntime.jsx("button",{type:"button",onClick:t,className:"text-sm text-gray-500 hover:text-gray-700",children:"Clear selection"}),o&&jsxRuntime.jsx("button",{type:"button",onClick:o,className:"text-sm text-gray-500 hover:text-gray-700",children:"Select all"})]}),jsxRuntime.jsx(wo,{trigger:jsxRuntime.jsxs("button",{type:"button",className:"kyro-btn kyro-btn-secondary kyro-btn-sm",children:["Actions",jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M6 9l6 6 6-6"})})]}),children:r.map((a,n)=>jsxRuntime.jsx(Ht,{onClick:a.onClick,icon:a.icon,danger:a.danger,children:a.label},n))})]})}function Fu({open:e,onClose:t,versions:r,currentVersionId:o,onPreview:a,onRestore:n,onCompare:s,loading:i=false}){let l=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime())){let u=Date.parse(c);return isNaN(u)?"Invalid date":new Date(u).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}return m.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})},d=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime()))return l(c);let g=new Date().getTime()-m.getTime();if(g<0)return "Just now";let x=Math.floor(g/6e4),f=Math.floor(g/36e5),y=Math.floor(g/864e5);return x<1?"Just now":x<60?`${x}m ago`:f<24?`${f}h ago`:y<7?`${y}d ago`:l(c)};return jsxRuntime.jsx(dr,{open:e,onClose:t,title:"Version History",width:"md",children:i?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-12",children:jsxRuntime.jsx(Ar,{})}):r.length===0?jsxRuntime.jsxs("div",{className:"text-center flex flex-col items-center justify-center py-16 text-[var(--kyro-text-muted)]",children:[jsxRuntime.jsx(lucideReact.History,{className:"w-12 h-12 mb-4 opacity-20"}),jsxRuntime.jsx("p",{className:"font-medium text-[var(--kyro-text)]",children:"No version history yet"}),jsxRuntime.jsx("p",{className:"text-sm mt-1",children:"Versions are automatically saved as you work."})]}):jsxRuntime.jsx("div",{className:"space-y-3 px-1 pb-4 pt-1",children:r.map(c=>{let m=c.id===o;return jsxRuntime.jsxs("div",{className:`p-4 rounded-xl border transition-all duration-200 group relative overflow-hidden ${m?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]/5 shadow-sm":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/30 hover:bg-[var(--kyro-surface-accent)] hover:shadow-sm bg-[var(--kyro-surface)]"}`,children:[m&&jsxRuntime.jsx("div",{className:"absolute top-0 left-0 w-1 h-full bg-[var(--kyro-primary)] shadow-[0_0_8px_var(--kyro-primary)]"}),jsxRuntime.jsxs("div",{className:"flex items-start justify-between gap-4",children:[jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[jsxRuntime.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold tracking-wide uppercase ${c.status==="published"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":"bg-zinc-500/10 text-zinc-600 dark:text-zinc-400"}`,children:[c.status==="published"&&jsxRuntime.jsx(lucideReact.CheckCircle2,{className:"w-3 h-3"}),c.status==="published"?"Published":"Draft"]}),jsxRuntime.jsxs("span",{className:"text-xs font-semibold text-[var(--kyro-text)] px-2 py-0.5 rounded-md bg-[var(--kyro-surface-accent)]",children:["v",c.version]}),m&&jsxRuntime.jsxs("span",{className:"text-[10px] font-medium text-[var(--kyro-primary)] flex items-center gap-1",children:[jsxRuntime.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-primary)] animate-pulse"}),"Current"]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium text-[var(--kyro-text)] truncate mb-1",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3.5 h-3.5 text-[var(--kyro-text-muted)]"}),d(c.createdAt)]}),c.createdBy&&jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-[var(--kyro-text-muted)] mt-1.5",children:[jsxRuntime.jsx(lucideReact.User,{className:"w-3.5 h-3.5"}),jsxRuntime.jsx("span",{children:c.createdBy.name||c.createdBy.email})]}),c.changelog&&jsxRuntime.jsxs("p",{className:"text-xs text-[var(--kyro-text-secondary)] mt-2 italic border-l-2 border-[var(--kyro-border)] pl-2",children:['"',c.changelog,'"']})]}),jsxRuntime.jsxs("div",{className:"flex flex-col sm:flex-row items-center gap-1.5 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>a(c),className:"p-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:bg-[var(--kyro-primary)]/10 rounded-md transition-colors",title:"Preview this version",children:jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"})}),s&&jsxRuntime.jsx("button",{type:"button",onClick:()=>s(c,r.find(u=>u.id===o)||c),className:"p-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:bg-[var(--kyro-primary)]/10 rounded-md transition-colors",title:"Compare with current",children:jsxRuntime.jsx(lucideReact.GitCompare,{className:"w-4 h-4"})}),!m&&jsxRuntime.jsx("button",{type:"button",onClick:()=>n(c),className:"p-2 text-amber-600 hover:bg-amber-500/10 rounded-md transition-colors",title:"Restore this version",children:jsxRuntime.jsx(lucideReact.Undo2,{className:"w-4 h-4"})})]})]})]},c.id)})})})}function ZT({title:e,onMenuClick:t,actions:r}){return jsxRuntime.jsxs("header",{className:"kyro-header",children:[jsxRuntime.jsxs("div",{className:"kyro-header-left",children:[jsxRuntime.jsx("button",{type:"button",className:"kyro-header-menu",onClick:t,"aria-label":"Toggle menu",children:jsxRuntime.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("path",{d:"M3 12h18M3 6h18M3 18h18"})})}),jsxRuntime.jsx("h1",{className:"kyro-header-title",children:e})]}),jsxRuntime.jsxs("div",{className:"kyro-header-right",children:[r,jsxRuntime.jsx("div",{className:"kyro-header-user",children:jsxRuntime.jsx("button",{type:"button",className:"kyro-header-user-btn",children:jsxRuntime.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("circle",{cx:"12",cy:"8",r:"4"}),jsxRuntime.jsx("path",{d:"M4 20c0-4 4-6 8-6s8 2 8 6"})]})})})]})]})}var nr={ready:[],beforeDeploy:[],afterDeploy:[]};function Yn(e){return nr.ready.push(e),()=>{nr.ready=nr.ready.filter(t=>t!==e);}}function Yd(e){return nr.beforeDeploy.push(e),()=>{nr.beforeDeploy=nr.beforeDeploy.filter(t=>t!==e);}}function Zd(e){return nr.afterDeploy.push(e),()=>{nr.afterDeploy=nr.afterDeploy.filter(t=>t!==e);}}async function ec(e){let t=[];for(let r of nr.ready)try{let o=await r(e);o&&typeof o=="object"&&"success"in o&&t.push(o);}catch(o){t.push({success:false,error:String(o)});}return t}async function tc(e){let t=[];for(let r of nr.beforeDeploy)try{let o=await r(e);o&&typeof o=="object"&&"success"in o&&t.push(o);}catch(o){t.push({success:false,error:String(o)});}return t}async function rc(e,t){for(let r of nr.afterDeploy)try{await r(e,t);}catch{}}function ac(e){return `${typeof window<"u"?window.location.origin:""}${e}`}function nc(e,t={}){let[r,o]=ka.useState(null),[a,n]=ka.useState(true),[s,i]=ka.useState(null),l=ka.useCallback(async()=>{n(true),i(null);try{let d=new URLSearchParams;t.page&&d.set("page",String(t.page)),t.limit&&d.set("limit",String(t.limit)),t.sort&&d.set("sort",t.sort),t.order&&d.set("order",t.order);let c=`${ac(`/api/${e}`)}?${d.toString()}`,m=await fetch(c,{credentials:"include"});if(!m.ok)throw new Error(`HTTP ${m.status}: ${m.statusText}`);let u=await m.json();o(u.data??u);}catch(d){i(d instanceof Error?d.message:String(d));}finally{n(false);}},[e,t.page,t.limit,t.sort,t.order]);return ka.useEffect(()=>{l();},[l]),{data:r,loading:a,error:s,refetch:l}}function sc(e,t="POST"){let[r,o]=ka.useState(false),[a,n]=ka.useState(null);return {mutate:ka.useCallback(async i=>{o(true),n(null);try{let l=ac(`/api/${e}`),d=await fetch(l,{method:t,credentials:"include",headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0});if(!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);let c=await d.json();return c.data??c}catch(l){return n(l instanceof Error?l.message:String(l)),null}finally{o(false);}},[e,t]),loading:r,error:a}}var oa=new Map;function aa(e){if(!e.name||typeof e.name!="string")throw new Error("Plugin must have a valid name");oa.has(e.name)&&console.warn(`Plugin "${e.name}" is already registered. Overwriting.`),oa.set(e.name,e),e.apply&&e.apply({});}function ic(e){oa.delete(e);}function lc(e){return oa.get(e)}function dc(){return Array.from(oa.values())}function cc(e){return Array.from(oa.values()).filter(t=>t.hooks&&typeof t.hooks[e]=="function")}var Du={name:"sample-plugin",version:"0.1.0",description:"A tiny sample plugin to demonstrate the extensibility surface",hooks:{onAdminReady:()=>{}}};aa(Du);var Bu={name:"sample-plugin-2",version:"0.1.0",description:"Second MVP plugin demonstrating beforeDeploy hook",hooks:{beforeDeploy:e=>({success:true})}};aa(Bu);var na=new Map;function sa(e){if(!e.id||typeof e.id!="string")throw new Error("Block must have a valid id");if(!e.label)throw new Error("Block must have a label");na.set(e.id,e);}function pc(e){na.delete(e);}function mc(e){return na.get(e)}function uc(){return Array.from(na.values())}function yc(e){return Array.from(na.values()).filter(t=>t.category===e)}function fc(e){let t=na.get(e);return t?t.render:(console.warn(`Block "${e}" not found in registry`),null)}var Iu=e=>{let{data:t}=e;return jsxRuntime.jsxs("div",{style:{border:"1px solid #ccc",padding:8,borderRadius:6},children:[jsxRuntime.jsx("strong",{children:"Sample Block"}),jsxRuntime.jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},Lu={id:"sample-block",label:"Sample Block",category:"demo",schema:[{name:"title",label:"Title",type:"text",required:true}],render:Iu};sa(Lu);var $u=e=>{let{data:t}=e;return jsxRuntime.jsxs("div",{style:{border:"2px dashed #888",padding:10,borderRadius:8},children:[jsxRuntime.jsx("strong",{children:"Sample Block 2"}),jsxRuntime.jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},Eu={id:"sample-block-2",label:"Sample Block 2",category:"demo",schema:[{name:"subtitle",label:"Subtitle",type:"text",required:false}],render:$u};sa(Eu);var ia=new Map;function la(e){if(!e.id||typeof e.id!="string")throw new Error("Field must have a valid id");if(!e.type||typeof e.type!="string")throw new Error("Field must have a valid type");ia.set(e.id,e);}function bc(e){ia.delete(e);}function xc(e){return ia.get(e)}function kc(){return Array.from(ia.values())}function hc(e){return Array.from(ia.values()).find(t=>t.type===e)}function wc(e,t){let r=ia.get(e);if(!r)return console.warn(`Field "${e}" not found in registry`),null;let o=r.editor;return jsxRuntime.jsx(o,{...t})}var zu=({name:e,value:t,onChange:r})=>jsxRuntime.jsx("input",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample text"}),ju={id:"sample-text",type:"text",label:"Sample Text",editor:zu};la(ju);var _u=({name:e,value:t,onChange:r})=>jsxRuntime.jsx("textarea",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample textarea"}),Vu={id:"sample-textarea",type:"textarea",label:"Sample Textarea",editor:_u};la(Vu);var Nc=fr__default.default.resolve(new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,"lib/shim");fr__default.default.join(Nc,"use-sync-external-store.js");fr__default.default.join(Nc,"use-sync-external-store-with-selector.js");function Xu(e={}){let{basePath:t="/admin",apiPath:r="/api",configPath:o="kyro.config.ts"}=e;return {name:"@kyro-cms/admin",hooks:{"astro:config:setup":async({config:a,updateConfig:n,injectRoute:s,logger:i})=>{i.info(`Kyro Admin mounted at ${t} (API: ${r})`);let l=fr__default.default.resolve(new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,"lib/default-kyro-config.ts"),d=fr__default.default.resolve(a.root.pathname,"..",o),c=fr__default.default.resolve(a.root.pathname,o),m=Ro__default.default.existsSync(d)?d:Ro__default.default.existsSync(c)?c:l;m!==l?i.info(`Loaded config from ${m}`):i.warn("Config file not found. Using defaults.");let u=fr__default.default.join(fr__default.default.dirname(m),".kyro-admin-config.json"),g="";try{let f=fr__default.default.join(fr__default.default.dirname(m),".env");Ro__default.default.existsSync(f)&&dotenv.config({path:f});let y=await esbuild.build({entryPoints:[m],bundle:!0,format:"esm",platform:"node",target:"es2022",write:!1,sourcemap:!1,loader:{".ts":"ts",".tsx":"tsx"},resolveExtensions:[".ts",".tsx",".js",".jsx",".mjs",".cjs",".json"],external:["@kyro-cms/*"]});g=m.replace(/\.ts$/,".admin.mjs"),Ro__default.default.writeFileSync(g,y.outputFiles[0].text,"utf8");let b=`
107
107
  import { parentPort } from 'worker_threads';
108
108
  import('${url.pathToFileURL(g).href}').then(mod => {
109
109
  const cfg = mod.default || mod;
@@ -129,7 +129,7 @@ code block
129
129
  }).catch(err => {
130
130
  parentPort.postMessage({ error: err.message });
131
131
  });
132
- `,v=new worker_threads.Worker(b,{eval:!0,env:{...process.env,NODE_OPTIONS:""}}),R=await new Promise((L,C)=>{v.on("message",L),v.on("error",C);let w=setTimeout(()=>{v.terminate(),C(new Error("Config loading timed out"));},3e4);});if(v.terminate(),R.error)throw new Error(R.error);Ro__default.default.writeFileSync(y,JSON.stringify(R,null,2),"utf8"),i.info("Project config loaded for admin");}catch(f){i.error(`Could not load project config: ${f.message}`);}finally{if(g&&Ro__default.default.existsSync(g))try{Ro__default.default.unlinkSync(g);}catch{}}n({vite:{plugins:[{name:"kyro-admin-tsx-loader",enforce:"pre",config(f){let u=f.esbuild,b=u?.exclude,v=/\/node_modules\/(?!.*@kyro-cms\/(admin|core))/;return {esbuild:{...u||{},exclude:b?Array.isArray(b)?[...b,v]:[b,v]:v}}}},{name:"kyro-cjs-shim",enforce:"pre",resolveId(f){if(f.includes("react/compiler-runtime"))return "\0react-compiler-runtime";if(f==="debug"||f.includes("debug/src/browser.js"))return "\0debug-browser"},load(f){if(f==="\0react-compiler-runtime")return `
132
+ `,v=new worker_threads.Worker(b,{eval:!0,env:{...process.env,NODE_OPTIONS:""}}),R=await new Promise((L,C)=>{v.on("message",L),v.on("error",C);let w=setTimeout(()=>{v.terminate(),C(new Error("Config loading timed out"));},3e4);});if(v.terminate(),R.error)throw new Error(R.error);Ro__default.default.writeFileSync(u,JSON.stringify(R,null,2),"utf8"),i.info("Project config loaded for admin");}catch(f){i.error(`Could not load project config: ${f.message}`);}finally{if(g&&Ro__default.default.existsSync(g))try{Ro__default.default.unlinkSync(g);}catch{}}n({vite:{plugins:[{name:"kyro-admin-tsx-loader",enforce:"pre",config(f){let y=f.esbuild,b=y?.exclude,v=/\/node_modules\/(?!.*@kyro-cms\/(admin|core))/;return {esbuild:{...y||{},exclude:b?Array.isArray(b)?[...b,v]:[b,v]:v}}}},{name:"kyro-cjs-shim",enforce:"pre",resolveId(f){if(f.includes("react/compiler-runtime"))return "\0react-compiler-runtime";if(f==="debug"||f.includes("debug/src/browser.js"))return "\0debug-browser"},load(f){if(f==="\0react-compiler-runtime")return `
133
133
  import React from "react";
134
134
  export function c(size) {
135
135
  const internals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
@@ -151,4 +151,4 @@ debug.enable = function() {};
151
151
  debug.disable = function() {};
152
152
  debug.enabled = function() { return false; };
153
153
  export default debug;
154
- `}}],resolve:{alias:{"kyro:config":m}},optimizeDeps:{include:["@kyro-cms/admin"],exclude:["debug","react/compiler-runtime"]},define:{__KYRO_ADMIN_PATH__:JSON.stringify(t),__KYRO_API_PATH__:JSON.stringify(r),__KYRO_ADMIN_CONFIG_FILE__:JSON.stringify(y)},ssr:{noExternal:["@kyro-cms/admin","@kyro-cms/core","@tiptap/core","@tiptap/react","@tiptap/pm","@tiptap/starter-kit","@tiptap/extension-link","@tiptap/extension-image","@tiptap/extension-text-align","@tiptap/extension-underline","@tiptap/extension-highlight","@tiptap/extension-task-list","@tiptap/extension-task-item","@tiptap/extension-text-style","@tiptap/extension-color","prosemirror-model","prosemirror-state","prosemirror-view","prosemirror-schema-list","prosemirror-commands","prosemirror-keymap","prosemirror-transform","prosemirror-inputrules"]}}}),globalThis.__KYRO_ADMIN_PROJECT_CONFIG__={collections:[],globals:[],adapter:null};let x=[{pattern:"",entrypoint:"./pages/index.astro"},{pattern:"/login",entrypoint:"./pages/auth/login.astro"},{pattern:"/register",entrypoint:"./pages/auth/register.astro"},{pattern:"/media",entrypoint:"./pages/media.astro"},{pattern:"/users",entrypoint:"./pages/users/index.astro"},{pattern:"/users/new",entrypoint:"./pages/users/new.astro"},{pattern:"/users/[id]",entrypoint:"./pages/users/[id].astro"},{pattern:"/roles",entrypoint:"./pages/roles/index.astro"},{pattern:"/settings",entrypoint:"./pages/settings/index.astro"},{pattern:"/settings/[slug]",entrypoint:"./pages/settings/[slug].astro"},{pattern:"/audit",entrypoint:"./pages/audit/index.astro"},{pattern:"/sessions",entrypoint:"./pages/sessions.astro"},{pattern:"/keys",entrypoint:"./pages/keys.astro"},{pattern:"/webhooks",entrypoint:"./pages/webhooks.astro"},{pattern:"/plugins",entrypoint:"./pages/plugins.astro"},{pattern:"/marketplace",entrypoint:"./pages/marketplace.astro"},{pattern:"/graphql",entrypoint:"./pages/graphql.astro"},{pattern:"/rest-playground",entrypoint:"./pages/rest-playground.astro"},{pattern:"/[collection]",entrypoint:"./pages/[collection]/index.astro"},{pattern:"/[collection]/[id]",entrypoint:"./pages/[collection]/[id].astro"}];for(let f of x){let u=`${t}${f.pattern}`.replace(/\/$/,"");s({pattern:u||"/",entrypoint:fr__default.default.resolve(new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,f.entrypoint)});}},"astro:build:done":({logger:a})=>{a.info("Kyro Admin build complete");}}}}exports.ActionBar=Zs;exports.Admin=Su;exports.AutoForm=_a;exports.Badge=Pt;exports.BulkActionsBar=Tu;exports.Button=ys;exports.ConfirmModal=ks;exports.CountBadge=us;exports.CreateView=ri;exports.DARK_THEME=Sa;exports.DarkThemeProvider=Nn;exports.DetailView=ti;exports.Dropdown=wo;exports.DropdownItem=jt;exports.DropdownSeparator=ja;exports.ExtDarkThemeProvider=Nn;exports.ExtLightThemeProvider=wn;exports.ExtThemeProvider=kr;exports.Header=dA;exports.LIGHT_THEME=Eo;exports.LightThemeProvider=wn;exports.ListView=gs;exports.LoginPage=ni;exports.Modal=Ot;exports.PageHeader=Ft;exports.SlidePanel=dr;exports.Spinner=Ar;exports.ThemeProvider=kr;exports.Toast=zd;exports.ToastProvider=H4;exports.VersionHistoryPanel=Lu;exports.adminPath=Ye;exports.afterDeploy=oc;exports.apiPath=lo;exports.beforeDeploy=rc;exports.emitAdminReady=ac;exports.emitAfterDeploy=sc;exports.emitBeforeDeploy=nc;exports.getBlock=vc;exports.getBlocks=gc;exports.getBlocksByCategory=bc;exports.getField=Nc;exports.getFieldByType=Sc;exports.getFields=Cc;exports.getPlugin=mc;exports.getPlugins=uc;exports.getPluginsWithHook=yc;exports.kyroAdmin=ty;exports.mergeThemes=Ta;exports.onAdminReady=Yn;exports.paths=jc;exports.registerBlock=sa;exports.registerField=la;exports.registerPlugin=aa;exports.resolveAdmin=ts;exports.resolveApi=qe;exports.unregisterBlock=fc;exports.unregisterField=wc;exports.unregisterPlugin=pc;exports.useBlockRenderer=xc;exports.useExtTheme=Oo;exports.useFieldRenderer=Tc;exports.useKyroMutation=cc;exports.useKyroQuery=dc;exports.useTheme=Oo;exports.useToast=_4;
154
+ `}}],resolve:{alias:{"kyro:config":m}},optimizeDeps:{include:["@kyro-cms/admin"],exclude:["debug","react/compiler-runtime"]},define:{__KYRO_ADMIN_PATH__:JSON.stringify(t),__KYRO_API_PATH__:JSON.stringify(r),__KYRO_ADMIN_CONFIG_FILE__:JSON.stringify(u)},ssr:{noExternal:["@kyro-cms/admin","@kyro-cms/core","@tiptap/core","@tiptap/react","@tiptap/pm","@tiptap/starter-kit","@tiptap/extension-link","@tiptap/extension-image","@tiptap/extension-text-align","@tiptap/extension-underline","@tiptap/extension-highlight","@tiptap/extension-task-list","@tiptap/extension-task-item","@tiptap/extension-text-style","@tiptap/extension-color","prosemirror-model","prosemirror-state","prosemirror-view","prosemirror-schema-list","prosemirror-commands","prosemirror-keymap","prosemirror-transform","prosemirror-inputrules"]}}}),globalThis.__KYRO_ADMIN_PROJECT_CONFIG__={collections:[],globals:[],adapter:null};let x=[{pattern:"",entrypoint:"./pages/index.astro"},{pattern:"/login",entrypoint:"./pages/auth/login.astro"},{pattern:"/register",entrypoint:"./pages/auth/register.astro"},{pattern:"/media",entrypoint:"./pages/media.astro"},{pattern:"/users",entrypoint:"./pages/users/index.astro"},{pattern:"/users/new",entrypoint:"./pages/users/new.astro"},{pattern:"/users/[id]",entrypoint:"./pages/users/[id].astro"},{pattern:"/roles",entrypoint:"./pages/roles/index.astro"},{pattern:"/settings",entrypoint:"./pages/settings/index.astro"},{pattern:"/settings/[slug]",entrypoint:"./pages/settings/[slug].astro"},{pattern:"/audit",entrypoint:"./pages/audit/index.astro"},{pattern:"/sessions",entrypoint:"./pages/sessions.astro"},{pattern:"/keys",entrypoint:"./pages/keys.astro"},{pattern:"/webhooks",entrypoint:"./pages/webhooks.astro"},{pattern:"/plugins",entrypoint:"./pages/plugins.astro"},{pattern:"/marketplace",entrypoint:"./pages/marketplace.astro"},{pattern:"/graphql",entrypoint:"./pages/graphql.astro"},{pattern:"/rest-playground",entrypoint:"./pages/rest-playground.astro"},{pattern:"/[collection]",entrypoint:"./pages/[collection]/index.astro"},{pattern:"/[collection]/[id]",entrypoint:"./pages/[collection]/[id].astro"}];for(let f of x){let y=`${t}${f.pattern}`.replace(/\/$/,"");s({pattern:y||"/",entrypoint:fr__default.default.resolve(new URL(".",(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).pathname,f.entrypoint)});}},"astro:build:done":({logger:a})=>{a.info("Kyro Admin build complete");}}}}exports.ActionBar=Qs;exports.Admin=ku;exports.AutoForm=_a;exports.Badge=Pt;exports.BulkActionsBar=hu;exports.Button=us;exports.ConfirmModal=xs;exports.CountBadge=ms;exports.CreateView=ei;exports.DARK_THEME=Sa;exports.DarkThemeProvider=Nn;exports.DetailView=Zs;exports.Dropdown=wo;exports.DropdownItem=Ht;exports.DropdownSeparator=ja;exports.ExtDarkThemeProvider=Nn;exports.ExtLightThemeProvider=wn;exports.ExtThemeProvider=kr;exports.Header=ZT;exports.LIGHT_THEME=Eo;exports.LightThemeProvider=wn;exports.ListView=vs;exports.LoginPage=oi;exports.Modal=Ut;exports.PageHeader=Ft;exports.SlidePanel=dr;exports.Spinner=Ar;exports.ThemeProvider=kr;exports.Toast=$d;exports.ToastProvider=B4;exports.VersionHistoryPanel=Fu;exports.adminPath=Ye;exports.afterDeploy=Zd;exports.apiPath=io;exports.beforeDeploy=Yd;exports.emitAdminReady=ec;exports.emitAfterDeploy=rc;exports.emitBeforeDeploy=tc;exports.getBlock=mc;exports.getBlocks=uc;exports.getBlocksByCategory=yc;exports.getField=xc;exports.getFieldByType=hc;exports.getFields=kc;exports.getPlugin=lc;exports.getPlugins=dc;exports.getPluginsWithHook=cc;exports.kyroAdmin=Xu;exports.mergeThemes=Ta;exports.onAdminReady=Yn;exports.paths=Ec;exports.registerBlock=sa;exports.registerField=la;exports.registerPlugin=aa;exports.resolveAdmin=ts;exports.resolveApi=qe;exports.unregisterBlock=pc;exports.unregisterField=bc;exports.unregisterPlugin=ic;exports.useBlockRenderer=fc;exports.useExtTheme=Oo;exports.useFieldRenderer=wc;exports.useKyroMutation=sc;exports.useKyroQuery=nc;exports.useTheme=Oo;exports.useToast=I4;