@kyro-cms/admin 0.11.5 → 0.12.0

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 Ca=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'),Dp=require('@tiptap/starter-kit'),Pp=require('@tiptap/extension-link'),Ip=require('@tiptap/extension-image'),Bp=require('@tiptap/extension-text-align'),Lp=require('@tiptap/extension-underline'),Mp=require('@tiptap/extension-highlight'),Ep=require('@tiptap/extension-task-list'),$p=require('@tiptap/extension-task-item'),extensionTextStyle=require('@tiptap/extension-text-style'),Up=require('@tiptap/extension-color'),hp=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'),km=require('unstorage/drivers/indexedb'),templates=require('@kyro-cms/core/templates'),Do=require('fs'),core=require('@dnd-kit/core'),sortable=require('@dnd-kit/sortable'),utilities=require('@dnd-kit/utilities'),vanilla=require('zustand/vanilla'),Zu=require('@uiw/react-codemirror'),langJson=require('@codemirror/lang-json');require('@kyro-cms/core');var yr=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 Ca__default=/*#__PURE__*/_interopDefault(Ca);var Dp__default=/*#__PURE__*/_interopDefault(Dp);var Pp__default=/*#__PURE__*/_interopDefault(Pp);var Ip__default=/*#__PURE__*/_interopDefault(Ip);var Bp__default=/*#__PURE__*/_interopDefault(Bp);var Lp__default=/*#__PURE__*/_interopDefault(Lp);var Mp__default=/*#__PURE__*/_interopDefault(Mp);var Ep__default=/*#__PURE__*/_interopDefault(Ep);var $p__default=/*#__PURE__*/_interopDefault($p);var Up__default=/*#__PURE__*/_interopDefault(Up);var hp__default=/*#__PURE__*/_interopDefault(hp);var km__default=/*#__PURE__*/_interopDefault(km);var Do__default=/*#__PURE__*/_interopDefault(Do);var Zu__default=/*#__PURE__*/_interopDefault(Zu);var yr__default=/*#__PURE__*/_interopDefault(yr);var Ge=typeof __KYRO_ADMIN_PATH__<"u"?__KYRO_ADMIN_PATH__:"/admin",br=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function tt(e){if(e.startsWith("http")||e.startsWith(br))return e;if(e.startsWith("/api/"))return br+e.slice(4);let t=e.startsWith("/")?"":"/";return `${br}${t}${e}`}function ss(e){return e.startsWith("http")||e.startsWith(Ge)?e:e.startsWith("/admin/")?Ge+e.slice(6):e.startsWith("/")?Ge+e:e}function ba(e){return !e||typeof e!="string"?"":e.startsWith("http")||e.startsWith("blob:")||e.startsWith("data:")||e.startsWith("/")?e:`/${e}`}var Yc={admin:Ge,api:br,resolveApi:tt,resolveAdmin:ss,resolveMedia:ba};var Ur=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:[]})})),M={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 dt=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 Zc="/api/auth/refresh";async function vi(){try{return (await fetch(tt(Zc),{method:"POST",credentials:"include"})).ok}catch{return false}}async function at(e,t={}){let r={};t.body instanceof FormData||(r["Content-Type"]="application/json"),Object.assign(r,t.headers);let o=await fetch(tt(e),{...t,credentials:"include",headers:r});if(o.status===401){if(await vi()){let n={};return t.body instanceof FormData||(n["Content-Type"]="application/json"),Object.assign(n,t.headers),await fetch(tt(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 at(e,o);if(!a.ok){let n=`GET Failed: ${a.status}`;throw r&&M.error(n),new Error(n)}return a.json()}async function nt(e,t,r){let{autoToast:o=true,...a}=r||{},n=await at(e,{method:"POST",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`POST Failed: ${n.status}`;try{let l=await n.json();l.error&&(s=l.error);}catch{}throw o&&M.error(s),new Error(s)}return n.json()}async function Gt(e,t,r){let{autoToast:o=true,...a}=r||{},n=await at(e,{method:"PATCH",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`Update Failed: ${n.status}`;try{let l=await n.json();l.error&&(s=l.error);}catch{}throw o&&M.error(s),new Error(s)}return n.json()}async function xt(e,t){let{autoToast:r=true,...o}={},a=await at(e,{method:"DELETE",...o});if(!a.ok){let s=`Delete Failed: ${a.status}`;try{let l=await a.json();l.error&&(s=l.error);}catch{}throw r&&M.error(s),new Error(s)}let n=await a.text();return n?JSON.parse(n):{}}function zr(e){let t=e.includes("?")?"&":"?";return `${e}${t}t=${Date.now()}`}function Za(e,t,r=50){return !e||t.length===0?`limit=${r}`:`${t.map(a=>`where[${a}][contains]=${encodeURIComponent(e)}`).join("&")}&limit=${r}`}async function en(e,t,r){if(!r){let o=await at(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",tt(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?vi().then(s=>{if(!s){a(new Error(`Upload Error: ${n.status}`));return}let l=new XMLHttpRequest;l.open("POST",tt(e)),l.withCredentials=true,l.upload.addEventListener("progress",i=>{i.lengthComputable&&r(Math.round(i.loaded/i.total*100));}),l.addEventListener("load",()=>{if(l.status>=200&&l.status<300)try{o(JSON.parse(l.responseText));}catch{a(new Error("Invalid JSON"));}else a(new Error(`Upload Error: ${l.status}`));}),l.addEventListener("error",()=>a(new Error("Network error"))),l.send(t);}):a(new Error(`Upload Error: ${n.status}`));}),n.addEventListener("error",()=>a(new Error("Network error during upload"))),n.send(t);})}function kr({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 ol({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 tp({breadcrumbs:e}){return e?.map((t,r)=>jsxRuntime.jsxs(Ca__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 al({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,disabled:t.disabled,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.disabled?"opacity-50 cursor-wait pointer-events-none":""} ${t.className||""}`,children:[t.icon&&jsxRuntime.jsx(t.icon,{className:"w-4 h-4"}),t.label]},r))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function nl({action:e}){return jsxRuntime.jsxs("button",{type:"button",onClick:e.onClick,disabled:e.disabled,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.disabled?"opacity-50 cursor-wait pointer-events-none":""} ${e.className||""}`,children:[e.icon&&jsxRuntime.jsx(e.icon,{className:"w-4 h-4"}),e.label]})}function Dt({title:e,description:t,icon:r,breadcrumbs:o,metadata:a,back:n,action:s,actions:l,children:i}){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(ol,{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(Ca__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:f=>{c.onClick&&(f.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(Ca__default.default.Fragment,{children:c},m))}),i]})]})]}),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(Ca__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(ol,{back:n}),o&&jsxRuntime.jsx(tp,{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(Ca__default.default.Fragment,{children:[m===0&&(t||m>0)&&jsxRuntime.jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))}),i]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3 flex-wrap shrink-0",children:[l&&jsxRuntime.jsx(al,{actions:l}),s&&jsxRuntime.jsx(nl,{action:s})]})]}),(l||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(nl,{action:s}),l&&jsxRuntime.jsx(al,{actions:l})]})]})}var op={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=op[n],l=s?s.class:`kyro-badge-${n}`;return jsxRuntime.jsxs("span",{className:`kyro-badge ${l} ${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 vs({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 gs({variant:e="secondary",size:t="md",loading:r=false,children:o,className:a="",disabled:n,...s}){let l="kyro-btn",i=`kyro-btn-${e}`,d=`kyro-btn-${t}`;return jsxRuntime.jsxs("button",{type:"button",className:`${l} ${i} ${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 il({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(gs,{variant:"ghost",size:"sm",disabled:e<=1,onClick:()=>a(e-1),children:"\u2190 Previous"}),jsxRuntime.jsx(gs,{variant:"ghost",size:"sm",disabled:e>=t,onClick:()=>a(e+1),children:"Next \u2192"})]})]})]})}function go(e,t,r){return r in t?t[r]:bs(e,t,r)}function bs(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=bs(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=bs(o.fields||[],a,r);if(n!==void 0)return n}}}}function ks({collection:e,collectionSlug:t,initialDocs:r=[],initialTotal:o=0,onCreate:a,onEdit:n,config:s}){let l=t||e.slug,{permissions:i}=Ur(),d=i?.collections?.[l]?.create!==false,c=i?.collections?.[l]?.delete!==false,m=i?.collections?.[l]?.update!==false,f=()=>{d&&(a?a():window.location.href=`${Ge}/${l}/new`);},v=I=>{n?n(I):window.location.href=`${Ge}/${l}/${I}`;},[b,g]=Ca.useState(r),[x,u]=Ca.useState(o),[y,h]=Ca.useState(false),[R,P]=Ca.useState(1),[w,k]=Ca.useState(10),[p,T]=Ca.useState(new Set),[B,S]=Ca.useState(""),[F,A]=Ca.useState([]),{confirm:X,alert:K}=dt(),$=()=>{A([...F,{field:"",operator:"equals",value:""}]);},j=()=>{S(""),A([]),re(null);},ae=I=>{A(F.filter((W,ie)=>ie!==I));},ne=(I,W)=>{A(F.map((ie,sr)=>sr===I?{...ie,...W}:ie));},[H,re]=Ca.useState(null),[ve,L]=Ca.useState(false),[O,pe]=Ca.useState(false);function ge(I){let W=[];for(let ie of I||[])if(!(!ie.name||ie.hidden===true||ie.admin?.hidden||ie.name==="id"))if(ie.type==="tabs"&&ie.tabs)for(let sr of ie.tabs)sr.fields&&W.push(...ge(sr.fields));else (ie.type==="row"||ie.type==="collapsible")&&ie.fields?W.push(...ge(ie.fields)):W.push(ie);return W}let Se=Ca.useMemo(()=>ge(e.fields),[e.fields]),Ne=typeof e.admin?.useAsTitle=="string"?e.admin.useAsTitle:Se.find(I=>I.type!=="group"&&typeof I.name=="string")?.name,[U,Y]=Ca.useState(()=>{let I;return e.admin?.defaultColumns?I=[...e.admin?.defaultColumns||[]]:I=Se.slice(0,4).map(W=>W.name).filter(W=>!!W),Ne&&I.includes(Ne)&&(I=[Ne,...I.filter(W=>W!==Ne)]),I.includes("updatedAt")||I.push("updatedAt"),new Set(I)}),le=Ca.useCallback(I=>{Y(W=>{let ie=new Set(W);return ie.has(I)?ie.delete(I):ie.add(I),ie});},[]);function Re(I){let W=Se.find(ie=>ie.name===I);return W&&W.type==="group"&&W.fields?.[0]?.name?`${I}.${W.fields[0].name}`:I}let Ue=Ca.useCallback(I=>{let W=Re(I);re(ie=>ie&&ie.field===W?{field:W,direction:ie.direction==="asc"?"desc":"asc"}:{field:W,direction:"asc"});},[]),Ie=Ca.useMemo(()=>{let I=Se.filter(W=>!!W.name&&U.has(W.name));return U.has("status")&&I.push({name:"status",type:"select",label:"Status",options:[{value:"draft",label:"Draft"},{value:"published",label:"Published"}]}),I},[Se,U]);function et(I){return !I.name||!Ne?false:I.name===Ne||I.type==="group"&&I.fields?.[0]?.name===Ne}function Ct(I,W){return W.name?go(e.fields,I,W.name)??null:null}let St=Ca.useCallback(async()=>{h(true);try{let I=new URLSearchParams({page:R.toString(),limit:w.toString()});B&&I.append("search",B),H&&I.append("sort",H.field),H&&I.append("order",H.direction),F.length>0&&I.append("filters",JSON.stringify(F));let W=await Be(zr(`/api/${l}?${I}`),{autoToast:!1});g(W.docs||[]),u(W.totalDocs||0);}catch(I){console.error("Failed to load docs:",I);}finally{h(false);}},[l,R,w,B,H,F]);Ca.useEffect(()=>{b.length===0&&o===0&&St();},[]);let Q=Ca.useRef(true);Ca.useEffect(()=>{if(Q.current){Q.current=false;return}St();},[R,w,B,H,F]);let te=()=>{p.size===b.length?T(new Set):T(new Set(b.map(I=>I.id)));},ce=I=>{let W=new Set(p);W.has(I)?W.delete(I):W.add(I),T(W);},Te=()=>{X({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 I of Array.from(p))await xt(`/api/${l}/${I}`);T(new Set),St(),M.success("Documents deleted");}catch(I){console.error("Bulk delete failed:",I),M.error("Failed to delete some documents");}}});},Fe=I=>{X({title:"Delete Document",message:"Are you sure you want to delete this document? This cannot be undone.",variant:"danger",onConfirm:async()=>{try{await xt(`/api/${l}/${I}`),St(),M.success("Document deleted");}catch(W){console.error("Delete failed:",W),M.error("Failed to delete document");}}});},lt=Math.ceil(x/w),Tt=B||F.length>0||H;return jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx(Dt,{title:e.label||l,description:e.admin?.description||`Manage your ${e.label||l}`,metadata:x>0?[jsxRuntime.jsxs("span",{className:"text-xs font-bold opacity-60",children:[x," documents"]},"count")]:void 0,action:d?{label:`Create ${e.singularLabel||e.label||l}`,onClick:f,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:B,onChange:I=>S(I.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:()=>L(!ve),className:`flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm transition-all ${ve||F.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",F.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:F.length})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>pe(!O),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"]}),O&&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:Se.map(I=>I.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:U.has(I.name),onChange:()=>le(I.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:I.label||I.name})]},I.name):null)})]})]}),Tt&&jsxRuntime.jsx("button",{type:"button",onClick:j,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"})]})]}),ve&&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:$,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:[F.map((I,W)=>jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[jsxRuntime.jsx("select",{value:I.field,onChange:ie=>ne(W,{field:ie.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:Se.map(ie=>jsxRuntime.jsx("option",{value:ie.name,children:ie.label||ie.name},ie.name))}),jsxRuntime.jsxs("select",{value:I.operator,onChange:ie=>ne(W,{operator:ie.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:I.value,onChange:ie=>ne(W,{value:ie.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:()=>ae(W),className:"p-2 text-[var(--kyro-text-muted)] hover:text-red-500 transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]},W)),F.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:Te,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:()=>T(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:y?jsxRuntime.jsx("div",{className:"space-y-2 p-4",children:jsxRuntime.jsx(Et,{variant:"table-row",count:8})}):b.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:Tt?"Try adjusting your filters or search query.":`Get started by creating your first ${(e.singularLabel||e.label||l).toLowerCase()}.`}),!Tt&&d&&jsxRuntime.jsxs("button",{type:"button",onClick:f,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||l)]})]}):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===b.length&&b.length>0,onChange:te,className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),Ie.map(I=>jsxRuntime.jsx("th",{className:"px-4 py-4 cursor-pointer hover:text-[var(--kyro-text-primary)] transition-colors",onClick:()=>Ue(I.name),children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[lp(Ie,I.type)??(I.label||I.name),H&&H.field===I.name&&jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4"})]})},I.name)),e.timestamps?jsxRuntime.jsx("th",{className:"px-4 py-4",children:"Created"}):null,e.timestamps?jsxRuntime.jsx("th",{className:"px-4 py-4",children:"Last Modified"}):null,jsxRuntime.jsx("th",{className:"px-4 py-4 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:b.map(I=>jsxRuntime.jsxs("tr",{className:"hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer group",onClick:()=>v(I.id),children:[jsxRuntime.jsx("td",{className:"px-4 py-3",onClick:W=>W.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:p.has(I.id),onChange:()=>ce(I.id),className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),Ie.map(W=>{let ie=Ct(I,W),sr=W.type==="select"&&ie&&Array.isArray(W.options)?W.options.find(po=>po.value===ie)?.label||ie:ip(ie,W.type);return jsxRuntime.jsx("td",{className:`px-4 py-3 ${et(W)?"font-medium text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)]"}`,children:sr},W.name)}),e.timestamps?jsxRuntime.jsx("td",{className:"px-4 py-3 text-sm text-[var(--kyro-text-secondary)]",children:I.createdAt?new Date(I.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"\u2014"}):null,e.timestamps?jsxRuntime.jsx("td",{className:"px-4 py-3 text-sm text-[var(--kyro-text-secondary)]",children:I.updatedAt?new Date(I.updatedAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"\u2014"}):null,jsxRuntime.jsx("td",{className:"px-4 py-3 text-right",onClick:W=>W.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:()=>v(I.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:()=>Fe(I.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"})})]})})]},I.id))})]})})}),jsxRuntime.jsx(il,{page:R,totalPages:lt,totalDocs:x,limit:w,onPageChange:P,onLimitChange:I=>{k(I),P(1);}})]})}function ip(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 lp(e,t){return t!=="tabs"?void 0:e[0]?.tabs?.[0]?.fields?.[0]?.label}var hs=(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"},ul=({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=Ca.useRef(null),n=Ca.useRef(null),[s,l]=Ca.useState(false),[i,d]=Ca.useState(false),[c,m]=Ca.useState(false),[f,v]=Ca.useState([]),[b,g]=Ca.useState([]),[x,u]=Ca.useState(""),[y,h]=Ca.useState(false),[R,P]=Ca.useState(""),[w,k]=Ca.useState(false),[p,T]=Ca.useState(""),[B,S]=Ca.useState(""),[F,A]=Ca.useState([]),X=e?.label||e?.name||"File",K=e.maxCount??(e.hasMany?999:1),$=K>1,j=Array.isArray(t)?t:t?[t]:[],ae=j.length<K;Ca.useEffect(()=>{(async()=>{let Y=j.filter(Ue=>typeof Ue=="string").map(Ue=>Ue),le=j.filter(Ue=>typeof Ue=="object"&&Ue!==null&&typeof Ue.id=="string"&&!Ue.url&&!Ue.filename&&!Ue.mimeType).map(Ue=>Ue.id),Re=[...Y,...le];if(Re.length!==0)try{let Ue=await Promise.all(Re.map(et=>Be(`/api/media/${et}`))),Ie=[...j];Ue.forEach(et=>{let Ct=et.id,St=Ie.findIndex(te=>te===Ct);if(St!==-1){Ie[St]=et;return}let Q=Ie.findIndex(te=>typeof te=="object"&&te!==null&&te.id===Ct);Q!==-1&&(Ie[Q]=et);}),r($?Ie:Ie[0]);}catch(Ue){console.error("Failed to fetch media details:",Ue);}})();},[t]),Ca.useEffect(()=>{i&&(ne(),H());},[i,x]);let ne=async()=>{try{let U=await Be(zr("/api/media/folders"));g(U.folders||[]);}catch{g([]);}},H=async()=>{h(true);try{let U=zr("/api/media?limit=60&sortBy=createdAt&sortDir=desc");x&&(U+="&folder="+encodeURIComponent(x));let Y=await Be(U);v(Y.docs||[]);}catch{v([]);}finally{h(false);}},re=async U=>{l(true);try{let Y=new FormData;Y.append("file",U),x&&Y.append("folder",x);let le=await en("/api/media/upload",Y),Re={id:le.id,filename:le.filename,originalName:le.originalName??U.name,url:le.url,mimeType:U.type};r($?[...j,Re]:Re),M.success(`Asset synchronized: ${Re.filename}`);}catch(Y){console.error("Upload failed:",Y),M.error(`Upload failed: ${Y instanceof Error?Y.message:"Unknown error"}`);}finally{l(false);}},ve=async()=>{let U=p.trim();if(U){S("");try{let Y=await nt("/api/media/upload",{url:U}),le=(()=>{try{return new URL(U).pathname.split("/").pop()||Y.originalName||"url-image"}catch{return Y.originalName||"url-image"}})(),Re={id:Y.id,filename:Y.filename,originalName:le,url:Y.url,mimeType:Y.mimeType||"image/*"};r($?[...j,Re]:Re),M.success(`URL asset established: ${Re.filename}`),T(""),k(!1);}catch(Y){let le=Y instanceof Error?Y.message:"Invalid URL";S(le);}}},L=U=>({id:U.id,filename:U.filename,url:U.url,mimeType:U.mimeType}),O=U=>{$?A(Y=>Y.find(Re=>Re.id===U.id)?Y.filter(Re=>Re.id!==U.id):[...Y,U]):(r(L(U)),d(false),P(""));},pe=()=>{if(F.length>0){let U=[...j,...F.map(L)];r(U);}A([]),d(false),P("");},ge=U=>{let Y=[...j];Y.splice(U,1),r($?Y:Y[0]||null);},Se=Ca.useMemo(()=>f.filter(U=>!R||U.filename?.toLowerCase().includes(R.toLowerCase())||U.title?.toLowerCase().includes(R.toLowerCase())),[f,R]);if(s)return jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] p-2",children:"Uploading..."});let Ne=(U,Y)=>{if(!U)return null;let le=hs(U.mimeType,U.filename||U.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:le==="image"?jsxRuntime.jsx("img",{src:ba(U.url),alt:U.filename||"Preview",className:"w-full h-full object-cover"}):jsxRuntime.jsx(ul,{type:le,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:U.originalName||U.filename||"Unnamed File"}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] tracking-wider font-bold",children:X})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>Y!==void 0?ge(Y):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"})})]},Y)};return jsxRuntime.jsxs("div",{className:"space-y-2 relative",children:[jsxRuntime.jsx("input",{ref:a,type:"file",accept:e.allowedTypes?.join(",")||"*/*",onChange:U=>{let Y=U.target.files?.[0];Y&&re(Y);},disabled:o,className:"hidden"}),j.length>0&&jsxRuntime.jsx("div",{className:$?"grid grid-cols-2 gap-2":"space-y-2",children:j.map((U,Y)=>Ne(U,Y))}),(!j.length||ae)&&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 ",X]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{A([]),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:()=>k(!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:U=>{T(U.target.value),S("");},onKeyDown:U=>U.key==="Enter"&&ve(),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:ve,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"}),B&&jsxRuntime.jsx("span",{className:"text-xs text-[var(--kyro-error)]",children:B})]}),i&&(c?reactDom.createPortal(jsxRuntime.jsx(ml,{isFullscreen:true,isMultiple:$,selectedItems:F,pickerSearch:R,setPickerSearch:P,folders:b,selectedFolder:x,setSelectedFolder:u,mediaLoading:y,filteredMedia:Se,selectFromLibrary:O,onDone:pe,setIsPickerFullscreen:m,setShowPicker:d}),document.body):jsxRuntime.jsx(ml,{isFullscreen:false,isMultiple:$,selectedItems:F,pickerSearch:R,setPickerSearch:P,folders:b,selectedFolder:x,setSelectedFolder:u,mediaLoading:y,filteredMedia:Se,selectFromLibrary:O,onDone:pe,setIsPickerFullscreen:m,setShowPicker:d}))]})}function ml({isFullscreen:e,isMultiple:t,selectedItems:r,pickerSearch:o,setPickerSearch:a,folders:n,selectedFolder:s,setSelectedFolder:l,mediaLoading:i,filteredMedia:d,selectFromLibrary:c,onDone:m,setIsPickerFullscreen:f,setShowPicker:v}){let b=g=>r.some(x=>x.id===g);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:g=>a(g.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:()=>l(""),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(g=>jsxRuntime.jsx("button",{type:"button",onClick:()=>l(g.path),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===g.path?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:g.name},g.path))]})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-2",children:i?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(g=>{let x=b(g.id);return jsxRuntime.jsxs("button",{type:"button",onClick:()=>c(g),className:`border rounded-md overflow-hidden cursor-pointer p-0 bg-[var(--kyro-surface)] transition-all relative group ${x?"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:hs(g.mimeType,g.filename)==="image"?jsxRuntime.jsx("img",{src:ba(g.thumbnailUrl||g.url),alt:g.filename,className:"w-full h-full object-cover"}):jsxRuntime.jsx(ul,{type:hs(g.mimeType,g.filename),className:e?"w-10 h-10":"w-8 h-8"})}),t&&x&&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"})})]},g.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:()=>f(!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:()=>{v(false),f(false);},className:"text-xs text-[var(--kyro-text-secondary)] bg-transparent border-none cursor-pointer hover:text-[var(--kyro-text-primary)]",children:"Close"})]})]})]})}function pt({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 l=Ca.useRef(null),[i,d]=Ca.useState(false);Ca.useEffect(()=>{d(true);},[]),Ca.useEffect(()=>{let m=f=>{f.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||!i?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:l,"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 Sa=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'),Lp=require('@tiptap/starter-kit'),Mp=require('@tiptap/extension-link'),Ep=require('@tiptap/extension-image'),$p=require('@tiptap/extension-text-align'),Op=require('@tiptap/extension-underline'),Up=require('@tiptap/extension-highlight'),zp=require('@tiptap/extension-task-list'),jp=require('@tiptap/extension-task-item'),extensionTextStyle=require('@tiptap/extension-text-style'),Hp=require('@tiptap/extension-color'),Sp=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'),Cm=require('unstorage/drivers/indexedb'),templates=require('@kyro-cms/core/templates'),Io=require('fs'),core=require('@dnd-kit/core'),sortable=require('@dnd-kit/sortable'),utilities=require('@dnd-kit/utilities'),vanilla=require('zustand/vanilla'),ay=require('@uiw/react-codemirror'),langJson=require('@codemirror/lang-json');require('@kyro-cms/core');var yr=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 Sa__default=/*#__PURE__*/_interopDefault(Sa);var Lp__default=/*#__PURE__*/_interopDefault(Lp);var Mp__default=/*#__PURE__*/_interopDefault(Mp);var Ep__default=/*#__PURE__*/_interopDefault(Ep);var $p__default=/*#__PURE__*/_interopDefault($p);var Op__default=/*#__PURE__*/_interopDefault(Op);var Up__default=/*#__PURE__*/_interopDefault(Up);var zp__default=/*#__PURE__*/_interopDefault(zp);var jp__default=/*#__PURE__*/_interopDefault(jp);var Hp__default=/*#__PURE__*/_interopDefault(Hp);var Sp__default=/*#__PURE__*/_interopDefault(Sp);var Cm__default=/*#__PURE__*/_interopDefault(Cm);var Io__default=/*#__PURE__*/_interopDefault(Io);var ay__default=/*#__PURE__*/_interopDefault(ay);var yr__default=/*#__PURE__*/_interopDefault(yr);var ze=typeof __KYRO_ADMIN_PATH__<"u"?__KYRO_ADMIN_PATH__:"/admin",kr=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function qe(e){if(e.startsWith("http")||e.startsWith(kr))return e;if(e.startsWith("/api/"))return kr+e.slice(4);let t=e.startsWith("/")?"":"/";return `${kr}${t}${e}`}function ps(e){return e.startsWith("http")||e.startsWith(ze)?e:e.startsWith("/admin/")?ze+e.slice(6):e.startsWith("/")?ze+e:e}function ba(e){return !e||typeof e!="string"?"":e.startsWith("http")||e.startsWith("blob:")||e.startsWith("data:")||e.startsWith("/")?e:`/${e}`}var tp={admin:ze,api:kr,resolveApi:qe,resolveAdmin:ps,resolveMedia:ba};var _r=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 dt=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 op="/api/auth/refresh";async function ki(){try{return (await fetch(qe(op),{method:"POST",credentials:"include"})).ok}catch{return false}}async function nt(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 ki()){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 Te(e,t){let{autoToast:r=true,...o}=t||{},a=await nt(e,o);if(!a.ok){let n=`GET Failed: ${a.status}`;throw r&&$.error(n),new Error(n)}return a.json()}async function st(e,t,r){let{autoToast:o=true,...a}=r||{},n=await nt(e,{method:"POST",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`POST Failed: ${n.status}`;try{let l=await n.json();l.error&&(s=l.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function Gt(e,t,r){let{autoToast:o=true,...a}=r||{},n=await nt(e,{method:"PATCH",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`Update Failed: ${n.status}`;try{let l=await n.json();l.error&&(s=l.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function kt(e,t){let{autoToast:r=true,...o}={},a=await nt(e,{method:"DELETE",...o});if(!a.ok){let s=`Delete Failed: ${a.status}`;try{let l=await a.json();l.error&&(s=l.error);}catch{}throw r&&$.error(s),new Error(s)}let n=await a.text();return n?JSON.parse(n):{}}function Hr(e){let t=e.includes("?")?"&":"?";return `${e}${t}t=${Date.now()}`}function on(e,t,r=50){return !e||t.length===0?`limit=${r}`:`${t.map(a=>`where[${a}][contains]=${encodeURIComponent(e)}`).join("&")}&limit=${r}`}async function an(e,t,r){if(!r){let o=await nt(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?ki().then(s=>{if(!s){a(new Error(`Upload Error: ${n.status}`));return}let l=new XMLHttpRequest;l.open("POST",qe(e)),l.withCredentials=true,l.upload.addEventListener("progress",i=>{i.lengthComputable&&r(Math.round(i.loaded/i.total*100));}),l.addEventListener("load",()=>{if(l.status>=200&&l.status<300)try{o(JSON.parse(l.responseText));}catch{a(new Error("Invalid JSON"));}else a(new Error(`Upload Error: ${l.status}`));}),l.addEventListener("error",()=>a(new Error("Network error"))),l.send(t);}):a(new Error(`Upload Error: ${n.status}`));}),n.addEventListener("error",()=>a(new Error("Network error during upload"))),n.send(t);})}function wr({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 Ut({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 il({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 np({breadcrumbs:e}){return e?.map((t,r)=>jsxRuntime.jsxs(Sa__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 ll({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,disabled:t.disabled,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.disabled?"opacity-50 cursor-wait pointer-events-none":""} ${t.className||""}`,children:[t.icon&&jsxRuntime.jsx(t.icon,{className:"w-4 h-4"}),t.label]},r))}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function dl({action:e}){return jsxRuntime.jsxs("button",{type:"button",onClick:e.onClick,disabled:e.disabled,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.disabled?"opacity-50 cursor-wait pointer-events-none":""} ${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:l,children:i}){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(il,{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,p)=>jsxRuntime.jsxs(Sa__default.default.Fragment,{children:[p>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})]},p))}),a&&jsxRuntime.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:a.map((c,p)=>jsxRuntime.jsx(Sa__default.default.Fragment,{children:c},p))}),i]})]})]}),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,p)=>jsxRuntime.jsxs(Sa__default.default.Fragment,{children:[p===0&&jsxRuntime.jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},p))})]})]}),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(il,{back:n}),o&&jsxRuntime.jsx(np,{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,p)=>jsxRuntime.jsxs(Sa__default.default.Fragment,{children:[p===0&&(t||p>0)&&jsxRuntime.jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},p))}),i]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3 flex-wrap shrink-0",children:[l&&jsxRuntime.jsx(ll,{actions:l}),s&&jsxRuntime.jsx(dl,{action:s})]})]}),(l||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(dl,{action:s}),l&&jsxRuntime.jsx(ll,{actions:l})]})]})}var ip={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 St({variant:e,status:t,className:r="",children:o,dot:a=false}){let n=e||t||"default",s=ip[n],l=s?s.class:`kyro-badge-${n}`;return jsxRuntime.jsxs("span",{className:`kyro-badge ${l} ${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 ks({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 hs({variant:e="secondary",size:t="md",loading:r=false,children:o,className:a="",disabled:n,...s}){let l="kyro-btn",i=`kyro-btn-${e}`,d=`kyro-btn-${t}`;return jsxRuntime.jsxs("button",{type:"button",className:`${l} ${i} ${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 pl({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(hs,{variant:"ghost",size:"sm",disabled:e<=1,onClick:()=>a(e-1),children:"\u2190 Previous"}),jsxRuntime.jsx(hs,{variant:"ghost",size:"sm",disabled:e>=t,onClick:()=>a(e+1),children:"Next \u2192"})]})]})]})}function xo(e,t,r){return r in t?t[r]:ws(e,t,r)}function ws(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=ws(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=ws(o.fields||[],a,r);if(n!==void 0)return n}}}}function Cs({collection:e,collectionSlug:t,initialDocs:r=[],initialTotal:o=0,onCreate:a,onEdit:n,config:s}){let l=t||e.slug,{permissions:i}=_r(),d=i?.collections?.[l]?.create!==false,c=i?.collections?.[l]?.delete!==false,p=i?.collections?.[l]?.update!==false,y=()=>{d&&(a?a():window.location.href=`${ze}/${l}/new`);},v=B=>{n?n(B):window.location.href=`${ze}/${l}/${B}`;},[b,g]=Sa.useState(r),[h,f]=Sa.useState(o),[m,w]=Sa.useState(false),[A,T]=Sa.useState(1),[k,x]=Sa.useState(10),[u,F]=Sa.useState(new Set),[M,S]=Sa.useState(""),[P,D]=Sa.useState([]),{confirm:Q,alert:G}=dt(),O=()=>{D([...P,{field:"",operator:"equals",value:""}]);},z=()=>{S(""),D([]),R(null);},se=B=>{D(P.filter((X,de)=>de!==B));},le=(B,X)=>{D(P.map((de,vr)=>vr===B?{...de,...X}:de));},[H,R]=Sa.useState(null),[V,L]=Sa.useState(false),[Z,fe]=Sa.useState(false);function W(B){let X=[];for(let de of B||[])if(!(!de.name||de.hidden===true||de.admin?.hidden||de.name==="id"))if(de.type==="tabs"&&de.tabs)for(let vr of de.tabs)vr.fields&&X.push(...W(vr.fields));else (de.type==="row"||de.type==="collapsible")&&de.fields?X.push(...W(de.fields)):X.push(de);return X}let be=Sa.useMemo(()=>W(e.fields),[e.fields]),xe=typeof e.admin?.useAsTitle=="string"?e.admin.useAsTitle:be.find(B=>B.type!=="group"&&typeof B.name=="string")?.name,[U,te]=Sa.useState(()=>{let B;return e.admin?.defaultColumns?B=[...e.admin?.defaultColumns||[]]:B=be.slice(0,4).map(X=>X.name).filter(X=>!!X),xe&&B.includes(xe)&&(B=[xe,...B.filter(X=>X!==xe)]),B.includes("updatedAt")||B.push("updatedAt"),new Set(B)}),me=Sa.useCallback(B=>{te(X=>{let de=new Set(X);return de.has(B)?de.delete(B):de.add(B),de});},[]);function Fe(B){let X=be.find(de=>de.name===B);return X&&X.type==="group"&&X.fields?.[0]?.name?`${B}.${X.fields[0].name}`:B}let Ue=Sa.useCallback(B=>{let X=Fe(B);R(de=>de&&de.field===X?{field:X,direction:de.direction==="asc"?"desc":"asc"}:{field:X,direction:"asc"});},[]),Ie=Sa.useMemo(()=>{let B=be.filter(X=>!!X.name&&U.has(X.name));return U.has("status")&&B.push({name:"status",type:"select",label:"Status",options:[{value:"draft",label:"Draft"},{value:"published",label:"Published"}]}),B},[be,U]);function rt(B){return !B.name||!xe?false:B.name===xe||B.type==="group"&&B.fields?.[0]?.name===xe}function Nt(B,X){return X.name?xo(e.fields,B,X.name)??null:null}let Ct=Sa.useCallback(async()=>{w(true);try{let B=new URLSearchParams({page:A.toString(),limit:k.toString()});M&&B.append("search",M),H&&B.append("sort",H.field),H&&B.append("order",H.direction),P.length>0&&B.append("filters",JSON.stringify(P));let X=await Te(Hr(`/api/${l}?${B}`),{autoToast:!1});g(X.docs||[]),f(X.totalDocs||0);}catch(B){console.error("Failed to load docs:",B);}finally{w(false);}},[l,A,k,M,H,P]);Sa.useEffect(()=>{b.length===0&&o===0&&Ct();},[]);let fr=Sa.useRef(true);Sa.useEffect(()=>{if(fr.current){fr.current=false;return}Ct();},[A,k,M,H,P]);let q=()=>{u.size===b.length?F(new Set):F(new Set(b.map(B=>B.id)));},ne=B=>{let X=new Set(u);X.has(B)?X.delete(B):X.add(B),F(X);},ie=()=>{Q({title:"Delete Documents",message:`Are you sure you want to delete ${u.size} document(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let B of Array.from(u))await kt(`/api/${l}/${B}`);F(new Set),Ct(),$.success("Documents deleted");}catch(B){console.error("Bulk delete failed:",B),$.error("Failed to delete some documents");}}});},Se=B=>{Q({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/${l}/${B}`),Ct(),$.success("Document deleted");}catch(X){console.error("Delete failed:",X),$.error("Failed to delete document");}}});},$e=Math.ceil(h/k),Ve=M||P.length>0||H;return jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsx(Ft,{title:e.label||l,description:e.admin?.description||`Manage your ${e.label||l}`,metadata:h>0?[jsxRuntime.jsxs("span",{className:"text-xs font-bold opacity-60",children:[h," documents"]},"count")]:void 0,action:d?{label:`Create ${e.singularLabel||e.label||l}`,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:M,onChange:B=>S(B.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:()=>L(!V),className:`flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm transition-all ${V||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:()=>fe(!Z),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"]}),Z&&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:be.map(B=>B.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:U.has(B.name),onChange:()=>me(B.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:B.label||B.name})]},B.name):null)})]})]}),Ve&&jsxRuntime.jsx("button",{type:"button",onClick:z,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"})]})]}),V&&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:O,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((B,X)=>jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[jsxRuntime.jsx("select",{value:B.field,onChange:de=>le(X,{field:de.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:be.map(de=>jsxRuntime.jsx("option",{value:de.name,children:de.label||de.name},de.name))}),jsxRuntime.jsxs("select",{value:B.operator,onChange:de=>le(X,{operator:de.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:B.value,onChange:de=>le(X,{value:de.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:()=>se(X),className:"p-2 text-[var(--kyro-text-muted)] hover:text-red-500 transition-colors",children:jsxRuntime.jsx(lucideReact.X,{className:"w-4 h-4"})})]},X)),P.length===0&&jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-muted)]",children:'No filters applied. Click "Add Filter" to create one.'})]})]}),u.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:[u.size," selected"]}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[c&&jsxRuntime.jsxs("button",{type:"button",onClick:ie,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:()=>F(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:m?jsxRuntime.jsx("div",{className:"space-y-2 p-4",children:jsxRuntime.jsx(Ut,{variant:"table-row",count:8})}):b.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:Ve?"Try adjusting your filters or search query.":`Get started by creating your first ${(e.singularLabel||e.label||l).toLowerCase()}.`}),!Ve&&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||l)]})]}):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:u.size===b.length&&b.length>0,onChange:q,className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),Ie.map(B=>jsxRuntime.jsx("th",{className:"px-4 py-4 cursor-pointer hover:text-[var(--kyro-text-primary)] transition-colors",onClick:()=>Ue(B.name),children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[mp(Ie,B.type)??(B.label||B.name),H&&H.field===B.name&&jsxRuntime.jsx(lucideReact.ChevronUp,{className:"w-4 h-4"})]})},B.name)),e.timestamps?jsxRuntime.jsx("th",{className:"px-4 py-4",children:"Created"}):null,e.timestamps?jsxRuntime.jsx("th",{className:"px-4 py-4",children:"Last Modified"}):null,jsxRuntime.jsx("th",{className:"px-4 py-4 text-right",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:b.map(B=>jsxRuntime.jsxs("tr",{className:"hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer group",onClick:()=>v(B.id),children:[jsxRuntime.jsx("td",{className:"px-4 py-3",onClick:X=>X.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:u.has(B.id),onChange:()=>ne(B.id),className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),Ie.map(X=>{let de=Nt(B,X),vr=X.type==="select"&&de&&Array.isArray(X.options)?X.options.find(yo=>yo.value===de)?.label||de:pp(de,X.type);return jsxRuntime.jsx("td",{className:`px-4 py-3 ${rt(X)?"font-medium text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)]"}`,children:vr},X.name)}),e.timestamps?jsxRuntime.jsx("td",{className:"px-4 py-3 text-sm text-[var(--kyro-text-secondary)]",children:B.createdAt?new Date(B.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"\u2014"}):null,e.timestamps?jsxRuntime.jsx("td",{className:"px-4 py-3 text-sm text-[var(--kyro-text-secondary)]",children:B.updatedAt?new Date(B.updatedAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"\u2014"}):null,jsxRuntime.jsx("td",{className:"px-4 py-3 text-right",onClick:X=>X.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:()=>v(B.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:p?"Edit":"View",children:jsxRuntime.jsx(lucideReact.Pencil,{className:"w-4 h-4"})}),c&&jsxRuntime.jsx("button",{type:"button",onClick:()=>Se(B.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"})})]})})]},B.id))})]})})}),jsxRuntime.jsx(pl,{page:A,totalPages:$e,totalDocs:h,limit:k,onPageChange:T,onLimitChange:B=>{x(B),T(1);}})]})}function pp(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 mp(e,t){return t!=="tabs"?void 0:e[0]?.tabs?.[0]?.fields?.[0]?.label}var Ss=(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"},gl=({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 ir({field:e,value:t,onChange:r,disabled:o}){let a=Sa.useRef(null),n=Sa.useRef(null),[s,l]=Sa.useState(false),[i,d]=Sa.useState(false),[c,p]=Sa.useState(false),[y,v]=Sa.useState([]),[b,g]=Sa.useState([]),[h,f]=Sa.useState(""),[m,w]=Sa.useState(false),[A,T]=Sa.useState(""),[k,x]=Sa.useState(false),[u,F]=Sa.useState(""),[M,S]=Sa.useState(""),[P,D]=Sa.useState([]),Q=e?.label||e?.name||"File",G=e.maxCount??(e.hasMany?999:1),O=G>1,z=Array.isArray(t)?t:t?[t]:[],se=z.length<G;Sa.useEffect(()=>{(async()=>{let te=z.filter(Ue=>typeof Ue=="string").map(Ue=>Ue),me=z.filter(Ue=>typeof Ue=="object"&&Ue!==null&&typeof Ue.id=="string"&&!Ue.url&&!Ue.filename&&!Ue.mimeType).map(Ue=>Ue.id),Fe=[...te,...me];if(Fe.length!==0)try{let Ue=await Promise.all(Fe.map(rt=>Te(`/api/media/${rt}`))),Ie=[...z];Ue.forEach(rt=>{let Nt=rt.id,Ct=Ie.findIndex(q=>q===Nt);if(Ct!==-1){Ie[Ct]=rt;return}let fr=Ie.findIndex(q=>typeof q=="object"&&q!==null&&q.id===Nt);fr!==-1&&(Ie[fr]=rt);}),r(O?Ie:Ie[0]);}catch(Ue){console.error("Failed to fetch media details:",Ue);}})();},[t]),Sa.useEffect(()=>{i&&(le(),H());},[i,h]);let le=async()=>{try{let U=await Te(Hr("/api/media/folders"));g(U.folders||[]);}catch{g([]);}},H=async()=>{w(true);try{let U=Hr("/api/media?limit=60&sortBy=createdAt&sortDir=desc");h&&(U+="&folder="+encodeURIComponent(h));let te=await Te(U);v(te.docs||[]);}catch{v([]);}finally{w(false);}},R=async U=>{l(true);try{let te=new FormData;te.append("file",U),h&&te.append("folder",h);let me=await an("/api/media/upload",te),Fe={id:me.id,filename:me.filename,originalName:me.originalName??U.name,url:me.url,mimeType:U.type};r(O?[...z,Fe]:Fe),$.success(`Asset synchronized: ${Fe.filename}`);}catch(te){console.error("Upload failed:",te),$.error(`Upload failed: ${te instanceof Error?te.message:"Unknown error"}`);}finally{l(false);}},V=async()=>{let U=u.trim();if(U){S("");try{let te=await st("/api/media/upload",{url:U}),me=(()=>{try{return new URL(U).pathname.split("/").pop()||te.originalName||"url-image"}catch{return te.originalName||"url-image"}})(),Fe={id:te.id,filename:te.filename,originalName:me,url:te.url,mimeType:te.mimeType||"image/*"};r(O?[...z,Fe]:Fe),$.success(`URL asset established: ${Fe.filename}`),F(""),x(!1);}catch(te){let me=te instanceof Error?te.message:"Invalid URL";S(me);}}},L=U=>({id:U.id,filename:U.filename,url:U.url,mimeType:U.mimeType}),Z=U=>{O?D(te=>te.find(Fe=>Fe.id===U.id)?te.filter(Fe=>Fe.id!==U.id):[...te,U]):(r(L(U)),d(false),T(""));},fe=()=>{if(P.length>0){let U=[...z,...P.map(L)];r(U);}D([]),d(false),T("");},W=U=>{let te=[...z];te.splice(U,1),r(O?te:te[0]||null);},be=Sa.useMemo(()=>y.filter(U=>!A||U.filename?.toLowerCase().includes(A.toLowerCase())||U.title?.toLowerCase().includes(A.toLowerCase())),[y,A]);if(s)return jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] p-2",children:"Uploading..."});let xe=(U,te)=>{if(!U)return null;let me=Ss(U.mimeType,U.filename||U.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:me==="image"?jsxRuntime.jsx("img",{src:ba(U.url),alt:U.filename||"Preview",className:"w-full h-full object-cover"}):jsxRuntime.jsx(gl,{type:me,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:U.originalName||U.filename||"Unnamed File"}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] tracking-wider font-bold",children:Q})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>te!==void 0?W(te):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"})})]},te)};return jsxRuntime.jsxs("div",{className:"space-y-2 relative",children:[jsxRuntime.jsx("input",{ref:a,type:"file",accept:e.allowedTypes?.join(",")||"*/*",onChange:U=>{let te=U.target.files?.[0];te&&R(te);},disabled:o,className:"hidden"}),z.length>0&&jsxRuntime.jsx("div",{className:O?"grid grid-cols-2 gap-2":"space-y-2",children:z.map((U,te)=>xe(U,te))}),(!z.length||se)&&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 ",Q]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{D([]),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:()=>x(!k),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"})]}),k&&jsxRuntime.jsxs("div",{className:"flex gap-2 items-center",children:[jsxRuntime.jsx("input",{ref:n,type:"url",placeholder:"https://example.com/image.jpg",value:u,onChange:U=>{F(U.target.value),S("");},onKeyDown:U=>U.key==="Enter"&&V(),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:V,disabled:o||!u.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"}),M&&jsxRuntime.jsx("span",{className:"text-xs text-[var(--kyro-error)]",children:M})]}),i&&(c?reactDom.createPortal(jsxRuntime.jsx(vl,{isFullscreen:true,isMultiple:O,selectedItems:P,pickerSearch:A,setPickerSearch:T,folders:b,selectedFolder:h,setSelectedFolder:f,mediaLoading:m,filteredMedia:be,selectFromLibrary:Z,onDone:fe,setIsPickerFullscreen:p,setShowPicker:d}),document.body):jsxRuntime.jsx(vl,{isFullscreen:false,isMultiple:O,selectedItems:P,pickerSearch:A,setPickerSearch:T,folders:b,selectedFolder:h,setSelectedFolder:f,mediaLoading:m,filteredMedia:be,selectFromLibrary:Z,onDone:fe,setIsPickerFullscreen:p,setShowPicker:d}))]})}function vl({isFullscreen:e,isMultiple:t,selectedItems:r,pickerSearch:o,setPickerSearch:a,folders:n,selectedFolder:s,setSelectedFolder:l,mediaLoading:i,filteredMedia:d,selectFromLibrary:c,onDone:p,setIsPickerFullscreen:y,setShowPicker:v}){let b=g=>r.some(h=>h.id===g);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:g=>a(g.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:()=>l(""),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(g=>jsxRuntime.jsx("button",{type:"button",onClick:()=>l(g.path),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===g.path?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:g.name},g.path))]})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-2",children:i?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(g=>{let h=b(g.id);return jsxRuntime.jsxs("button",{type:"button",onClick:()=>c(g),className:`border rounded-md overflow-hidden cursor-pointer p-0 bg-[var(--kyro-surface)] transition-all relative group ${h?"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:Ss(g.mimeType,g.filename)==="image"?jsxRuntime.jsx("img",{src:ba(g.thumbnailUrl||g.url),alt:g.filename,className:"w-full h-full object-cover"}):jsxRuntime.jsx(gl,{type:Ss(g.mimeType,g.filename),className:e?"w-10 h-10":"w-8 h-8"})}),t&&h&&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"})})]},g.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:p,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:()=>{v(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 pt({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 lr({open:e,onClose:t,title:r,children:o,width:a="md",showOverlay:n=false,accentClass:s}){let l=Sa.useRef(null),[i,d]=Sa.useState(false);Sa.useEffect(()=>{d(true);},[]),Sa.useEffect(()=>{let p=y=>{y.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",p),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",p),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||!i?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:l,"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 Hr({children:e}){return jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:e})}function Vr({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(Ca.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 l={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",full:"w-full h-full max-w-none rounded-none border-0"},i=s==="lightbox";return reactDom.createPortal(jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-center justify-center p-4",children:[jsxRuntime.jsx("div",{className:`absolute inset-0 transition-all duration-500 ${i?"bg-black/95 backdrop-blur-none":"bg-[var(--kyro-black)]/40 backdrop-blur-md"}`,onClick:t}),jsxRuntime.jsxs("div",{className:`relative ${l[n]} ${i?"bg-transparent text-white":"bg-[var(--kyro-surface)]"} ${!i&&n!=="full"?"rounded-[var(--kyro-radius-lg)]":""} shadow-2xl animate-in fade-in zoom-in-95 duration-300 ${i?"":"border"} ${s==="danger"?"border-red-500/30":"border-[var(--kyro-border)]"} flex flex-col overflow-hidden`,children:[!i&&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 ${i?"":"px-8 py-8"}`,children:o}),a&&!i&&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 Ns({open:e,onClose:t,onConfirm:r,title:o,message:a,confirmLabel:n="Confirm",cancelLabel:s="Cancel",variant:l="default",loading:i=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:i,className:"kyro-btn kyro-btn-md kyro-btn-secondary",children:s}),jsxRuntime.jsx("button",{type:"button",onClick:r,disabled:i,className:`kyro-btn kyro-btn-md ${l==="danger"?"kyro-btn-danger":"kyro-btn-primary"}`,children:i?"Loading...":n})]}),children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)]",children:a})})}function fl({open:e,onClose:t,onSubmit:r,title:o,placeholder:a="",defaultValue:n=""}){let[s,l]=Ca.useState(n),i=d=>{d.preventDefault(),s.trim()&&(r(s.trim()),l(""),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:i,children:[jsxRuntime.jsx("div",{className:"px-6 py-4",children:jsxRuntime.jsx("input",{type:"text",value:s,onChange:d=>l(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 gl({url:e,initialCrop:t,initialHotspot:r,onSave:o,onCancel:a,isSaving:n=false}){let[s,l]=Ca.useState("crop"),[i,d]=Ca.useState(t?{unit:"%",...t}:void 0),[c,m]=Ca.useState(r||{x:40,y:40,width:20,height:20}),[f,v]=Ca.useState(!!r),b=Ca.useRef(null),g=Ca.useRef(null),[x,u]=Ca.useState(false),[y,h]=Ca.useState(null),R=Ca.useRef(null),P=(S,F)=>{s==="hotspot"&&(S.stopPropagation(),S.preventDefault(),F?h(F):u(true),R.current={x:S.clientX,y:S.clientY,hX:c.x,hY:c.y,hW:c.width,hH:c.height});},w=Ca.useCallback(S=>{if(!R.current||!b.current)return;let F=b.current.getBoundingClientRect(),A=(S.clientX-R.current.x)/F.width*100,X=(S.clientY-R.current.y)/F.height*100,K=R.current;if(x){let $=K.hX+A,j=K.hY+X;$=Math.max(0,Math.min($,100-K.hW)),j=Math.max(0,Math.min(j,100-K.hH)),m(ae=>({...ae,x:$,y:j}));}else if(y){let $=K.hX,j=K.hY,ae=K.hW,ne=K.hH;y.includes("e")&&(ae=K.hW+A),y.includes("w")&&($=K.hX+A,ae=K.hW-A),y.includes("s")&&(ne=K.hH+X),y.includes("n")&&(j=K.hY+X,ne=K.hH-X),ae<5&&(ae=5,y.includes("w")&&($=K.hX+K.hW-5)),ne<5&&(ne=5,y.includes("n")&&(j=K.hY+K.hH-5)),$=Math.max(0,Math.min($,100-ae)),j=Math.max(0,Math.min(j,100-ne)),ae=Math.min(ae,100-$),ne=Math.min(ne,100-j),m({x:$,y:j,width:ae,height:ne});}},[x,y,c]),k=Ca.useCallback(()=>{u(false),h(null),R.current=null;},[]);return Ca.useEffect(()=>((x||y)&&(window.addEventListener("pointermove",w),window.addEventListener("pointerup",k)),()=>{window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",k);}),[x,y,w,k]),jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-[var(--kyro-bg)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("button",{onClick:()=>l("crop"),className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ${s==="crop"?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,children:[jsxRuntime.jsx(lucideReact.Crop,{className:"w-4 h-4"}),"Crop"]}),jsxRuntime.jsxs("button",{onClick:()=>{l("hotspot"),f||v(true);},className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ${s==="hotspot"?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,children:[jsxRuntime.jsx(lucideReact.MousePointerClick,{className:"w-4 h-4"}),"Hotspot"]}),jsxRuntime.jsx("div",{className:"w-px h-6 bg-[var(--kyro-border)] mx-2"}),jsxRuntime.jsxs("button",{onClick:()=>{d(void 0),v(false);},className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:[jsxRuntime.jsx(lucideReact.RefreshCcw,{className:"w-4 h-4"}),"Reset"]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("button",{onClick:a,className:"px-4 py-2 text-sm font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:()=>{let S=i?.width&&i?.height?{x:i.x,y:i.y,width:i.width,height:i.height}:void 0;o(S,f?c:void 0);},disabled:n,className:"flex items-center justify-center min-w-[120px] px-6 py-2 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] text-sm font-bold rounded-lg shadow-lg hover:opacity-90 transition-all active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed",children:n?jsxRuntime.jsxs("svg",{className:"animate-spin h-4 w-4 text-current",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"})]}):"Save Edits"})]})]}),jsxRuntime.jsx("div",{className:"flex-1 w-full flex items-center justify-center p-8 overflow-hidden relative select-none",children:jsxRuntime.jsxs("div",{className:"relative max-w-full max-h-full flex items-center justify-center",ref:g,children:[jsxRuntime.jsx(hp__default.default,{crop:i,onChange:(S,F)=>d(F),locked:s==="hotspot",className:s==="hotspot"?"opacity-70 transition-opacity":"transition-opacity",children:jsxRuntime.jsx("img",{ref:b,src:e,alt:"Focal Editor",className:"max-h-[70vh] object-contain pointer-events-none",onLoad:S=>{}})}),f&&b.current&&jsxRuntime.jsx("div",{className:"absolute inset-0 z-10 pointer-events-none flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"relative",style:{width:b.current.width,height:b.current.height},children:jsxRuntime.jsxs("div",{className:`absolute border-2 shadow-2xl transition-colors duration-200 ${s==="hotspot"?"border-blue-500 bg-blue-500/20 cursor-move pointer-events-auto shadow-blue-500/50":"border-blue-500/50 bg-blue-500/10 pointer-events-none"}`,style:{left:`${c.x}%`,top:`${c.y}%`,width:`${c.width}%`,height:`${c.height}%`,borderRadius:"50%"},onPointerDown:S=>P(S),children:[jsxRuntime.jsx("div",{className:"absolute top-1/2 left-1/2 w-2 h-2 -ml-1 -mt-1 bg-blue-500 rounded-full"}),s==="hotspot"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"absolute top-0 left-1/2 w-4 h-4 -ml-2 -mt-2 bg-blue-500 rounded-full cursor-ns-resize",onPointerDown:S=>P(S,"n")}),jsxRuntime.jsx("div",{className:"absolute bottom-0 left-1/2 w-4 h-4 -ml-2 -mb-2 bg-blue-500 rounded-full cursor-ns-resize",onPointerDown:S=>P(S,"s")}),jsxRuntime.jsx("div",{className:"absolute top-1/2 left-0 w-4 h-4 -ml-2 -mt-2 bg-blue-500 rounded-full cursor-ew-resize",onPointerDown:S=>P(S,"w")}),jsxRuntime.jsx("div",{className:"absolute top-1/2 right-0 w-4 h-4 -mr-2 -mt-2 bg-blue-500 rounded-full cursor-ew-resize",onPointerDown:S=>P(S,"e")})]})]})})})]})}),jsxRuntime.jsx("div",{className:"p-4 text-center bg-[var(--kyro-surface-accent)] border-t border-[var(--kyro-border)] text-sm text-[var(--kyro-text-secondary)]",children:s==="crop"?"Drag to define the crop area. This creates a bounding box for the image.":"Drag the circle to define the focal hotspot. This area will always remain visible when the image is resized."})]})}function Gr(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 wn(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 Sp(e){return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function Tp(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 Nn({onSelect:e,multiple:t=true,pickerMode:r=false}){let{permissions:o}=Ur(),a=o?.media?.create!==false,n=o?.media?.delete!==false,s=o?.media?.update!==false,[l,i]=Ca.useState([]),[d,c]=Ca.useState(true),[m,f]=Ca.useState(false),[v,b]=Ca.useState([]),[g,x]=Ca.useState(""),[u,y]=Ca.useState(""),[h,R]=Ca.useState("all"),[P,w]=Ca.useState("grid"),[k,p]=Ca.useState(null),[T,B]=Ca.useState(false),[S,F]=Ca.useState(false),[A,X]=Ca.useState(false),[K,$]=Ca.useState({}),[j,ae]=Ca.useState(false),[ne,H]=Ca.useState(false),[re,ve]=Ca.useState(null),[L,O]=Ca.useState(false),[pe,ge]=Ca.useState(false),[Se,Ne]=Ca.useState(1),[U,Y]=Ca.useState(0),[le,Re]=Ca.useState(1),Ue=40,[Ie,et]=Ca.useState(new Set),{confirm:Ct,alert:St}=dt(),[Q,te]=Ca.useState(false),ce=Ca.useRef(null),Te=Ca.useCallback(async C=>{C===1?c(true):f(true);try{let me=new URLSearchParams({page:C.toString(),limit:Ue.toString()});g&&me.append("folder",g),u&&me.append("search",u),h!=="all"&&me.append("type",h);let De=await Be(zr(`/api/media?${me}`)),qt=(De.docs||[]).map(Rt=>({...Rt,type:Tp(Rt.mimeType)}));i(Rt=>C===1?qt:[...Rt,...qt]),Y(De.totalDocs||0),Re(De.totalPages||1);}catch(me){console.error("Failed to load media:",me);}finally{c(false),f(false);}},[g,u,h,Ue]),Fe=Ca.useCallback(async()=>{try{let C=await Be(zr("/api/media/folders"));b(Array.isArray(C)?C:C.folders||[]);}catch(C){console.error("Failed to load folders:",C);}},[]),lt=Ca.useCallback(async()=>{try{let me=!!(await Be("/api/globals/storage-settings"))?.data?.provider;ve(me);}catch{ve(false);}},[]);Ca.useEffect(()=>{r||lt();},[lt,r]),Ca.useEffect(()=>{r||re===false&&!L&&(O(true),ge(true));},[r,re,L]),Ca.useEffect(()=>{Ne(1),Te(1);},[g,u,h,Te]);let Tt=()=>{if(m||Se>=le)return;let C=Se+1;Ne(C),Te(C);};Ca.useEffect(()=>{Fe();},[Fe]),Ca.useEffect(()=>{if(r)return;let C=me=>{let De=me.clipboardData?.files;De&&De.length>0&&I(De);};return window.addEventListener("paste",C),()=>window.removeEventListener("paste",C)},[r,g,re]);let I=async C=>{if(!re){ge(true);return}X(true);let me=0,De=0;for(let qt=0;qt<C.length;qt++){let Rt=C[qt];try{let fr=new FormData;fr.append("file",Rt),g&&fr.append("folder",g),await en("/api/media/upload",fr,os=>{$(Po=>({...Po,[Rt.name]:os}));}),me++;}catch(fr){console.error(`Upload failed for ${Rt.name}:`,fr),De++;}}X(false),$({}),Ne(1),Te(1),Fe(),De>0&&M.error(`${De} file(s) failed to upload`),me>0&&M.success(`${me} file(s) uploaded successfully`);},W=()=>{Ct({title:"Delete Media",message:`Are you sure you want to delete ${Ie.size} item(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let C of Array.from(Ie))await xt(`/api/media/${C}`);et(new Set),Ne(1),Te(1),M.success(`${Ie.size} item(s) deleted`);}catch(C){console.error("Bulk delete failed:",C),M.error("Failed to delete some items");}}});},ie=(C,me)=>{me.stopPropagation();let De=new Set(Ie);De.has(C)?De.delete(C):(t||De.clear(),De.add(C)),et(De);},sr=async C=>{try{await nt("/api/media/folders",{name:C}),Fe(),ae(!1),M.success(`Folder "${C}" created`);}catch(me){console.error("Failed to create folder:",me),M.error("Failed to create folder");}},po=C=>{Ct({title:"Delete Folder",message:`Are you sure you want to delete the folder "${C}"? All media in this folder will be moved to the root.`,variant:"danger",confirmLabel:"Delete Folder",onConfirm:async()=>{try{await xt(`/api/media/folders?path=${encodeURIComponent(C)}`),g===C&&x(""),Fe(),Ne(1),Te(1),M.success(`Folder "${C}" deleted`);}catch(me){console.error("Failed to delete folder:",me),M.error("Failed to delete folder");}}});},ya=async(C,me)=>{try{let De=await Gt(`/api/media/${C}`,me);i(qt=>qt.map(Rt=>Rt.id===C?De.doc:Rt)),k?.id===C&&p(De.doc),M.success("Metadata updated");}catch(De){console.error("Failed to update metadata:",De),M.error("Failed to update metadata");}},qa=async(C,me)=>{if(k)try{X(!0);let De={...k.metadata,crop:C,hotspot:me},qt=await Gt(`/api/media/${k.id}`,{metadata:De});i(Rt=>Rt.map(fr=>fr.id===k.id?qt.doc:fr)),p(qt.doc),F(!1),M.success("Focal metadata saved");}catch(De){console.error("Save failed:",De),M.error("Failed to save focal metadata");}finally{X(false);}},rs=Ca.useMemo(()=>l.reduce((C,me)=>(C.totalSize+=me.fileSize||0,C),{totalSize:0}),[l]);return jsxRuntime.jsxs("div",{className:`flex flex-col h-full bg-[var(--kyro-bg)] transition-all duration-300 ${Q?"ring-4 ring-[var(--kyro-sidebar-active)] ring-inset":""}`,...r?{}:{onDragOver:C=>{C.preventDefault(),te(true);},onDragLeave:()=>te(false),onDrop:C=>{C.preventDefault(),te(false),C.dataTransfer.files&&I(C.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:[U," Items \xB7 ",wn(rs.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:u,onChange:C=>y(C.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:()=>w("grid"),className:`p-2 rounded-lg transition-all ${P==="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:()=>w("list"),className:`p-2 rounded-lg transition-all ${P==="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:()=>H(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:()=>ce.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(C=>jsxRuntime.jsxs("button",{onClick:()=>R(C),className:`w-full flex items-center gap-3 px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all ${h===C?"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 ${h===C?"bg-[var(--kyro-primary)]":"bg-transparent border border-current opacity-30"}`}),C]},C))})]}),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:()=>ae(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"]}),v.map(C=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>x(C),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===C?"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===C?"currentColor":"none"})}),C]}),jsxRuntime.jsx("button",{onClick:me=>{me.stopPropagation(),po(C);},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"})})]},C))]})]})]})}),jsxRuntime.jsx("div",{className:"flex-1 flex flex-col min-h-0 min-w-0 bg-[var(--kyro-bg)]",children:jsxRuntime.jsxs("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})}):l.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:()=>ce.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"})]}):P==="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:l.map((C,me)=>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 ${Ie.has(C.id)?"border-[var(--kyro-primary)]":"border-transparent hover:border-[var(--kyro-border-strong)] hover:shadow-2xl hover:-translate-y-1"}`,onClick:()=>p(C),onContextMenu:De=>{De.preventDefault(),ie(C.id,De);},children:[C.type==="image"?jsxRuntime.jsx("img",{src:C.url,alt:C.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:C.type==="video"?jsxRuntime.jsx(lucideReact.Film,{className:"w-8 h-8"}):C.type==="audio"?jsxRuntime.jsx(lucideReact.Music,{className:"w-8 h-8"}):C.type==="document"?jsxRuntime.jsx(lucideReact.FileText,{className:"w-8 h-8"}):C.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:C.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:C.filename}),jsxRuntime.jsx("div",{className:"flex gap-1",children:jsxRuntime.jsx("button",{onClick:De=>ie(C.id,De),className:`kyro-btn-primary p-1.5 rounded-lg transition-all ${Ie.has(C.id)?"":"bg-white/10 text-white hover:bg-white/20"}`,children:jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})})})]})}),Ie.has(C.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"})})]},C.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:Ie.size===l.length,onChange:C=>{C.target.checked?et(new Set(l.map(me=>me.id))):et(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:l.map(C=>jsxRuntime.jsxs("tr",{className:`group hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer ${Ie.has(C.id)?"bg-[var(--kyro-surface-accent)]":""}`,onClick:()=>p(C),children:[jsxRuntime.jsx("td",{className:"px-6 py-4",onClick:me=>me.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:Ie.has(C.id),onChange:me=>ie(C.id,me),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:C.type==="image"?jsxRuntime.jsx("img",{src:C.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:C.title||C.filename}),jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:C.filename})]})]})}),jsxRuntime.jsx("td",{className:"px-6 py-4",children:jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[9px]",children:C.mimeType})}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:wn(C.fileSize)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:Sp(C.createdAt)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-right",children:jsxRuntime.jsx("button",{onClick:me=>{me.stopPropagation(),ie(C.id,me);},className:`kyro-btn-primary p-2 rounded-lg transition-all ${Ie.has(C.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"})})})]},C.id))})]})}),!d&&Se<le&&jsxRuntime.jsx("div",{className:"flex justify-center mt-8 pb-8",children:jsxRuntime.jsx("button",{onClick:Tt,disabled:m,className:"px-8 py-3 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs hover:scale-105 active:scale-95 transition-all shadow-xl disabled:opacity-50 flex items-center gap-2",children:m?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(kr,{size:"sm"})," Loading..."]}):"Load More"})})]})})]}),!r&&A&&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(kr,{})}),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(K).length," Total"]})]}),jsxRuntime.jsx("div",{className:"space-y-4 max-h-[160px] overflow-y-auto pr-2 custom-scrollbar",children:Object.entries(K).map(([C,me])=>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:C}),jsxRuntime.jsxs("span",{className:"text-[var(--kyro-primary)]",children:[me,"%"]})]}),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:`${me}%`}})})]},C))})]})}),Ie.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:Ie.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:()=>et(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 C=l.filter(me=>Ie.has(me.id));e(C);},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:W,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"})})]})]}),ne&&!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:()=>H(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:()=>H(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(C=>jsxRuntime.jsx("button",{onClick:()=>{R(C),H(false);},className:`px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all border ${h===C?"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:C},C))})]}),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:()=>{ae(true),H(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(""),H(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"]}),v.map(C=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>{x(C),H(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===C?"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===C?"currentColor":"none"})}),C]}),jsxRuntime.jsx("button",{onClick:me=>{me.stopPropagation(),po(C),H(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"})})]},C))]})]})]})]})]}),jsxRuntime.jsx(dr,{open:!!k,onClose:()=>p(null),title:"Asset Details",subtitle:k?.filename,children:k&&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:[k.type==="image"?jsxRuntime.jsx("img",{src:Gr(k.url),alt:"",className:"w-full h-full object-contain p-4"}):k.type==="video"?jsxRuntime.jsx("video",{src:Gr(k.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:k.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:()=>B(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:k.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:wn(k.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:Gr(k.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(Gr(k.url)),M.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:k.alt||"",onChange:C=>ya(k.id,{alt:C.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:k.caption||"",onChange:C=>ya(k.id,{caption:C.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 C=document.createElement("a");C.href=Gr(k.url),C.download=k.filename,C.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"]}),k.type==="image"&&s&&jsxRuntime.jsx("button",{onClick:()=>F(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:()=>{Ct({title:"Delete Asset",message:`Are you sure you want to delete ${k.filename}? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await xt(`/api/media/${k.id}`),p(null),Te();}catch(C){console.error("Delete failed:",C),M.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"})})]})]})}),T&&k&&jsxRuntime.jsxs(Ot,{open:T,onClose:()=>B(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:k.filename}),jsxRuntime.jsxs("span",{className:"text-white/40 text-[10px] font-bold tracking-widest mt-1",children:[wn(k.fileSize)," \xB7 ",k.mimeType]})]}),jsxRuntime.jsx("button",{onClick:()=>B(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:k.type==="image"?jsxRuntime.jsx("img",{src:Gr(k.url),alt:"",className:"max-h-full max-w-full object-contain shadow-2xl rounded-lg animate-in zoom-in-95 duration-500"}):k.type==="video"?jsxRuntime.jsx("video",{src:Gr(k.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&&S&&k&&jsxRuntime.jsx(Ot,{open:S,onClose:()=>F(false),title:"",size:"full",variant:"lightbox",children:jsxRuntime.jsx(gl,{url:Gr(k.url),initialCrop:k.metadata?.crop,initialHotspot:k.metadata?.hotspot,onSave:qa,onCancel:()=>F(false),isSaving:A})}),!r&&jsxRuntime.jsx(fl,{open:j,onClose:()=>ae(false),onSubmit:sr,title:"Create New Folder",placeholder:"Folder name"}),!r&&jsxRuntime.jsx(Ot,{open:pe,onClose:()=>ge(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:()=>{nt("/api/globals/storage-settings",{provider:"local",local:{uploadDir:"./public/uploads",baseUrl:"/uploads"}}).then(()=>{ge(false),ve(true),window.location.reload();}).catch(()=>{M.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:ce,onChange:C=>{C.target.files&&I(C.target.files);},multiple:true,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.txt,.zip,.rar,.tar"})]})}var tm=[{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"}],Al=({editor:e,isExpanded:t,setIsExpanded:r,onOpenMediaPicker:o})=>{let[a,n]=Ca.useState(null),s=Ca.useRef(null);if(Ca.useEffect(()=>{function u(y){s.current&&!s.current.contains(y.target)&&n(null);}return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]),!e)return null;let l=()=>{o();},i=()=>{let u=e.getAttributes("link").href,y=window.prompt("URL",u);if(y!==null){if(y===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:y}).run();}},d=u=>{u==="inherit"?e.chain().focus().unsetColor().run():e.chain().focus().setColor(u).run(),n(null);},c=u=>{n(a===u?null:u);},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",f=()=>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}),v=()=>e.isActive("orderedList")?jsxRuntime.jsx(lucideReact.ListOrdered,{size:12}):e.isActive("taskList")?jsxRuntime.jsx(lucideReact.CheckSquare,{size:12}):jsxRuntime.jsx(lucideReact.List,{size:12}),b=()=>e.isActive("codeBlock")?jsxRuntime.jsx(lucideReact.Terminal,{size:12}):jsxRuntime.jsx(lucideReact.Quote,{size:12}),g=({onClick:u,isActive:y=false,disabled:h=false,children:R,title:P})=>jsxRuntime.jsx("button",{type:"button",onClick:u,disabled:h,title:P,className:`p-1 rounded flex items-center justify-center transition-all duration-150 relative
10
- ${y?"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
- ${h?"opacity-35 cursor-not-allowed":"cursor-pointer active:scale-90"}`,children:R}),x=({onClick:u,isActive:y,children:h,title:R})=>jsxRuntime.jsxs("button",{type:"button",onClick:u,title:R,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
- ${y?"bg-[var(--kyro-bg-hover)] border-[var(--kyro-border)]":""}`,children:[h,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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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:tm.map(u=>jsxRuntime.jsx("button",{type:"button",onClick:()=>d(u.value),title:u.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:u.value==="inherit"?"transparent":u.value},children:u.value==="inherit"&&jsxRuntime.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[10px] text-[var(--kyro-text)] font-semibold",children:"\u2205"})},u.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(x,{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
- ${e.isActive("heading")?"":"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]"}`,children:"Normal Text"}),[1,2,3,4].map(u=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleHeading({level:u}).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:u})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:["Heading ",u]},u))]})]}),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(x,{onClick:()=>c("lists"),isActive:a==="lists",title:"List Types",children:v()}),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
9
+ `})]}),document.body)}function Lr({children:e}){return jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:e})}function Gr({children:e}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-3 mt-6",children:e})}function Pt({open:e,onClose:t,title:r,children:o,footer:a,size:n="md",variant:s="default"}){if(Sa.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 l={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",full:"w-full h-full max-w-none rounded-none border-0"},i=s==="lightbox";return reactDom.createPortal(jsxRuntime.jsxs("div",{className:"fixed inset-0 z-[999999] flex items-center justify-center p-4",children:[jsxRuntime.jsx("div",{className:`absolute inset-0 transition-all duration-500 ${i?"bg-black/95 backdrop-blur-none":"bg-[var(--kyro-black)]/40 backdrop-blur-md"}`,onClick:t}),jsxRuntime.jsxs("div",{className:`relative ${l[n]} ${i?"bg-transparent text-white":"bg-[var(--kyro-surface)]"} ${!i&&n!=="full"?"rounded-[var(--kyro-radius-lg)]":""} shadow-2xl animate-in fade-in zoom-in-95 duration-300 ${i?"":"border"} ${s==="danger"?"border-red-500/30":"border-[var(--kyro-border)]"} flex flex-col overflow-hidden`,children:[!i&&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 ${i?"":"px-8 py-8"}`,children:o}),a&&!i&&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 Ts({open:e,onClose:t,onConfirm:r,title:o,message:a,confirmLabel:n="Confirm",cancelLabel:s="Cancel",variant:l="default",loading:i=false}){return jsxRuntime.jsx(Pt,{open:e,onClose:t,title:o,size:"sm",footer:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",onClick:t,disabled:i,className:"kyro-btn kyro-btn-md kyro-btn-secondary",children:s}),jsxRuntime.jsx("button",{type:"button",onClick:r,disabled:i,className:`kyro-btn kyro-btn-md ${l==="danger"?"kyro-btn-danger":"kyro-btn-primary"}`,children:i?"Loading...":n})]}),children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)]",children:a})})}function xl({open:e,onClose:t,onSubmit:r,title:o,placeholder:a="",defaultValue:n=""}){let[s,l]=Sa.useState(n),i=d=>{d.preventDefault(),s.trim()&&(r(s.trim()),l(""),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:i,children:[jsxRuntime.jsx("div",{className:"px-6 py-4",children:jsxRuntime.jsx("input",{type:"text",value:s,onChange:d=>l(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 hl({url:e,initialCrop:t,initialHotspot:r,onSave:o,onCancel:a,isSaving:n=false}){let[s,l]=Sa.useState("crop"),[i,d]=Sa.useState(t?{unit:"%",...t}:void 0),[c,p]=Sa.useState(r||{x:40,y:40,width:20,height:20}),[y,v]=Sa.useState(!!r),b=Sa.useRef(null),g=Sa.useRef(null),[h,f]=Sa.useState(false),[m,w]=Sa.useState(null),A=Sa.useRef(null),T=(S,P)=>{s==="hotspot"&&(S.stopPropagation(),S.preventDefault(),P?w(P):f(true),A.current={x:S.clientX,y:S.clientY,hX:c.x,hY:c.y,hW:c.width,hH:c.height});},k=Sa.useCallback(S=>{if(!A.current||!b.current)return;let P=b.current.getBoundingClientRect(),D=(S.clientX-A.current.x)/P.width*100,Q=(S.clientY-A.current.y)/P.height*100,G=A.current;if(h){let O=G.hX+D,z=G.hY+Q;O=Math.max(0,Math.min(O,100-G.hW)),z=Math.max(0,Math.min(z,100-G.hH)),p(se=>({...se,x:O,y:z}));}else if(m){let O=G.hX,z=G.hY,se=G.hW,le=G.hH;m.includes("e")&&(se=G.hW+D),m.includes("w")&&(O=G.hX+D,se=G.hW-D),m.includes("s")&&(le=G.hH+Q),m.includes("n")&&(z=G.hY+Q,le=G.hH-Q),se<5&&(se=5,m.includes("w")&&(O=G.hX+G.hW-5)),le<5&&(le=5,m.includes("n")&&(z=G.hY+G.hH-5)),O=Math.max(0,Math.min(O,100-se)),z=Math.max(0,Math.min(z,100-le)),se=Math.min(se,100-O),le=Math.min(le,100-z),p({x:O,y:z,width:se,height:le});}},[h,m,c]),x=Sa.useCallback(()=>{f(false),w(null),A.current=null;},[]);return Sa.useEffect(()=>((h||m)&&(window.addEventListener("pointermove",k),window.addEventListener("pointerup",x)),()=>{window.removeEventListener("pointermove",k),window.removeEventListener("pointerup",x);}),[h,m,k,x]),jsxRuntime.jsxs("div",{className:"flex flex-col h-full bg-[var(--kyro-bg)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("button",{onClick:()=>l("crop"),className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ${s==="crop"?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,children:[jsxRuntime.jsx(lucideReact.Crop,{className:"w-4 h-4"}),"Crop"]}),jsxRuntime.jsxs("button",{onClick:()=>{l("hotspot"),y||v(true);},className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ${s==="hotspot"?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,children:[jsxRuntime.jsx(lucideReact.MousePointerClick,{className:"w-4 h-4"}),"Hotspot"]}),jsxRuntime.jsx("div",{className:"w-px h-6 bg-[var(--kyro-border)] mx-2"}),jsxRuntime.jsxs("button",{onClick:()=>{d(void 0),v(false);},className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:[jsxRuntime.jsx(lucideReact.RefreshCcw,{className:"w-4 h-4"}),"Reset"]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("button",{onClick:a,className:"px-4 py-2 text-sm font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-colors",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:()=>{let S=i?.width&&i?.height?{x:i.x,y:i.y,width:i.width,height:i.height}:void 0;o(S,y?c:void 0);},disabled:n,className:"flex items-center justify-center min-w-[120px] px-6 py-2 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] text-sm font-bold rounded-lg shadow-lg hover:opacity-90 transition-all active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed",children:n?jsxRuntime.jsxs("svg",{className:"animate-spin h-4 w-4 text-current",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"})]}):"Save Edits"})]})]}),jsxRuntime.jsx("div",{className:"flex-1 w-full flex items-center justify-center p-8 overflow-hidden relative select-none",children:jsxRuntime.jsxs("div",{className:"relative max-w-full max-h-full flex items-center justify-center",ref:g,children:[jsxRuntime.jsx(Sp__default.default,{crop:i,onChange:(S,P)=>d(P),locked:s==="hotspot",className:s==="hotspot"?"opacity-70 transition-opacity":"transition-opacity",children:jsxRuntime.jsx("img",{ref:b,src:e,alt:"Focal Editor",className:"max-h-[70vh] object-contain pointer-events-none",onLoad:S=>{}})}),y&&b.current&&jsxRuntime.jsx("div",{className:"absolute inset-0 z-10 pointer-events-none flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"relative",style:{width:b.current.width,height:b.current.height},children:jsxRuntime.jsxs("div",{className:`absolute border-2 shadow-2xl transition-colors duration-200 ${s==="hotspot"?"border-blue-500 bg-blue-500/20 cursor-move pointer-events-auto shadow-blue-500/50":"border-blue-500/50 bg-blue-500/10 pointer-events-none"}`,style:{left:`${c.x}%`,top:`${c.y}%`,width:`${c.width}%`,height:`${c.height}%`,borderRadius:"50%"},onPointerDown:S=>T(S),children:[jsxRuntime.jsx("div",{className:"absolute top-1/2 left-1/2 w-2 h-2 -ml-1 -mt-1 bg-blue-500 rounded-full"}),s==="hotspot"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"absolute top-0 left-1/2 w-4 h-4 -ml-2 -mt-2 bg-blue-500 rounded-full cursor-ns-resize",onPointerDown:S=>T(S,"n")}),jsxRuntime.jsx("div",{className:"absolute bottom-0 left-1/2 w-4 h-4 -ml-2 -mb-2 bg-blue-500 rounded-full cursor-ns-resize",onPointerDown:S=>T(S,"s")}),jsxRuntime.jsx("div",{className:"absolute top-1/2 left-0 w-4 h-4 -ml-2 -mt-2 bg-blue-500 rounded-full cursor-ew-resize",onPointerDown:S=>T(S,"w")}),jsxRuntime.jsx("div",{className:"absolute top-1/2 right-0 w-4 h-4 -mr-2 -mt-2 bg-blue-500 rounded-full cursor-ew-resize",onPointerDown:S=>T(S,"e")})]})]})})})]})}),jsxRuntime.jsx("div",{className:"p-4 text-center bg-[var(--kyro-surface-accent)] border-t border-[var(--kyro-border)] text-sm text-[var(--kyro-text-secondary)]",children:s==="crop"?"Drag to define the crop area. This creates a bounding box for the image.":"Drag the circle to define the focal hotspot. This area will always remain visible when the image is resized."})]})}function qr(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 Rn(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 Dp(e){return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function Fp(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 Tn({onSelect:e,multiple:t=true,pickerMode:r=false}){let{permissions:o}=_r(),a=o?.media?.create!==false,n=o?.media?.delete!==false,s=o?.media?.update!==false,[l,i]=Sa.useState([]),[d,c]=Sa.useState(true),[p,y]=Sa.useState(false),[v,b]=Sa.useState([]),[g,h]=Sa.useState(""),[f,m]=Sa.useState(""),[w,A]=Sa.useState("all"),[T,k]=Sa.useState("grid"),[x,u]=Sa.useState(null),[F,M]=Sa.useState(false),[S,P]=Sa.useState(false),[D,Q]=Sa.useState(false),[G,O]=Sa.useState({}),[z,se]=Sa.useState(false),[le,H]=Sa.useState(false),[R,V]=Sa.useState(null),[L,Z]=Sa.useState(false),[fe,W]=Sa.useState(false),[be,xe]=Sa.useState(1),[U,te]=Sa.useState(0),[me,Fe]=Sa.useState(1),Ue=40,[Ie,rt]=Sa.useState(new Set),{confirm:Nt,alert:Ct}=dt(),[fr,q]=Sa.useState(false),ne=Sa.useRef(null),ie=Sa.useCallback(async C=>{C===1?c(true):y(true);try{let ee=new URLSearchParams({page:C.toString(),limit:Ue.toString()});g&&ee.append("folder",g),f&&ee.append("search",f),w!=="all"&&ee.append("type",w);let Be=await Te(Hr(`/api/media?${ee}`)),Mt=(Be.docs||[]).map(Et=>({...Et,type:Fp(Et.mimeType)}));i(Et=>C===1?Mt:[...Et,...Mt]),te(Be.totalDocs||0),Fe(Be.totalPages||1);}catch(ee){console.error("Failed to load media:",ee);}finally{c(false),y(false);}},[g,f,w,Ue]),Se=Sa.useCallback(async()=>{try{let C=await Te(Hr("/api/media/folders"));b(Array.isArray(C)?C:C.folders||[]);}catch(C){console.error("Failed to load folders:",C);}},[]),$e=Sa.useCallback(async()=>{try{let ee=!!(await Te("/api/globals/storage-settings"))?.data?.provider;V(ee);}catch{V(false);}},[]);Sa.useEffect(()=>{r||$e();},[$e,r]),Sa.useEffect(()=>{r||R===false&&!L&&(Z(true),W(true));},[r,R,L]),Sa.useEffect(()=>{xe(1),ie(1);},[g,f,w,ie]);let Ve=()=>{if(p||be>=me)return;let C=be+1;xe(C),ie(C);};Sa.useEffect(()=>{Se();},[Se]),Sa.useEffect(()=>{if(r)return;let C=ee=>{let Be=ee.clipboardData?.files;Be&&Be.length>0&&B(Be);};return window.addEventListener("paste",C),()=>window.removeEventListener("paste",C)},[r,g,R]);let B=async C=>{if(!R){W(true);return}Q(true);let ee=0,Be=0;for(let Mt=0;Mt<C.length;Mt++){let Et=C[Mt];try{let gr=new FormData;gr.append("file",Et),g&&gr.append("folder",g),await an("/api/media/upload",gr,ls=>{O(ds=>({...ds,[Et.name]:ls}));}),ee++;}catch(gr){console.error(`Upload failed for ${Et.name}:`,gr),Be++;}}Q(false),O({}),xe(1),ie(1),Se(),Be>0&&$.error(`${Be} file(s) failed to upload`),ee>0&&$.success(`${ee} file(s) uploaded successfully`);},X=()=>{Nt({title:"Delete Media",message:`Are you sure you want to delete ${Ie.size} item(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let C of Array.from(Ie))await kt(`/api/media/${C}`);rt(new Set),xe(1),ie(1),$.success(`${Ie.size} item(s) deleted`);}catch(C){console.error("Bulk delete failed:",C),$.error("Failed to delete some items");}}});},de=(C,ee)=>{ee.stopPropagation();let Be=new Set(Ie);Be.has(C)?Be.delete(C):(t||Be.clear(),Be.add(C)),rt(Be);},vr=async C=>{try{await st("/api/media/folders",{name:C}),Se(),se(!1),$.success(`Folder "${C}" created`);}catch(ee){console.error("Failed to create folder:",ee),$.error("Failed to create folder");}},yo=C=>{Nt({title:"Delete Folder",message:`Are you sure you want to delete the folder "${C}"? 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(C)}`),g===C&&h(""),Se(),xe(1),ie(1),$.success(`Folder "${C}" deleted`);}catch(ee){console.error("Failed to delete folder:",ee),$.error("Failed to delete folder");}}});},ya=async(C,ee)=>{try{let Be=await Gt(`/api/media/${C}`,ee);i(Mt=>Mt.map(Et=>Et.id===C?Be.doc:Et)),x?.id===C&&u(Be.doc),$.success("Metadata updated");}catch(Be){console.error("Failed to update metadata:",Be),$.error("Failed to update metadata");}},Xa=async(C,ee)=>{if(x)try{Q(!0);let Be={...x.metadata,crop:C,hotspot:ee},Mt=await Gt(`/api/media/${x.id}`,{metadata:Be});i(Et=>Et.map(gr=>gr.id===x.id?Mt.doc:gr)),u(Mt.doc),P(!1),$.success("Focal metadata saved");}catch(Be){console.error("Save failed:",Be),$.error("Failed to save focal metadata");}finally{Q(false);}},Ya=Sa.useMemo(()=>l.reduce((C,ee)=>(C.totalSize+=ee.fileSize||0,C),{totalSize:0}),[l]);return jsxRuntime.jsxs("div",{className:`flex flex-col h-full bg-[var(--kyro-bg)] transition-all duration-300 ${fr?"ring-4 ring-[var(--kyro-sidebar-active)] ring-inset":""}`,...r?{}:{onDragOver:C=>{C.preventDefault(),q(true);},onDragLeave:()=>q(false),onDrop:C=>{C.preventDefault(),q(false),C.dataTransfer.files&&B(C.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:[U," Items \xB7 ",Rn(Ya.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:C=>m(C.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:()=>k("grid"),className:`p-2 rounded-lg transition-all ${T==="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:()=>k("list"),className:`p-2 rounded-lg transition-all ${T==="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:()=>H(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:()=>ne.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(C=>jsxRuntime.jsxs("button",{onClick:()=>A(C),className:`w-full flex items-center gap-3 px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all ${w===C?"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 ${w===C?"bg-[var(--kyro-primary)]":"bg-transparent border border-current opacity-30"}`}),C]},C))})]}),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:()=>h(""),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"]}),v.map(C=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>h(C),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===C?"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===C?"currentColor":"none"})}),C]}),jsxRuntime.jsx("button",{onClick:ee=>{ee.stopPropagation(),yo(C);},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"})})]},C))]})]})]})}),jsxRuntime.jsx("div",{className:"flex-1 flex flex-col min-h-0 min-w-0 bg-[var(--kyro-bg)]",children:jsxRuntime.jsxs("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(Ut,{variant:"media-card",count:12})}):l.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:()=>ne.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"})]}):T==="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:l.map((C,ee)=>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 ${Ie.has(C.id)?"border-[var(--kyro-primary)]":"border-transparent hover:border-[var(--kyro-border-strong)] hover:shadow-2xl hover:-translate-y-1"}`,onClick:()=>u(C),onContextMenu:Be=>{Be.preventDefault(),de(C.id,Be);},children:[C.type==="image"?jsxRuntime.jsx("img",{src:C.url,alt:C.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:C.type==="video"?jsxRuntime.jsx(lucideReact.Film,{className:"w-8 h-8"}):C.type==="audio"?jsxRuntime.jsx(lucideReact.Music,{className:"w-8 h-8"}):C.type==="document"?jsxRuntime.jsx(lucideReact.FileText,{className:"w-8 h-8"}):C.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:C.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:C.filename}),jsxRuntime.jsx("div",{className:"flex gap-1",children:jsxRuntime.jsx("button",{onClick:Be=>de(C.id,Be),className:`kyro-btn-primary p-1.5 rounded-lg transition-all ${Ie.has(C.id)?"":"bg-white/10 text-white hover:bg-white/20"}`,children:jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"})})})]})}),Ie.has(C.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"})})]},C.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:Ie.size===l.length,onChange:C=>{C.target.checked?rt(new Set(l.map(ee=>ee.id))):rt(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:l.map(C=>jsxRuntime.jsxs("tr",{className:`group hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer ${Ie.has(C.id)?"bg-[var(--kyro-surface-accent)]":""}`,onClick:()=>u(C),children:[jsxRuntime.jsx("td",{className:"px-6 py-4",onClick:ee=>ee.stopPropagation(),children:jsxRuntime.jsx("input",{type:"checkbox",checked:Ie.has(C.id),onChange:ee=>de(C.id,ee),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:C.type==="image"?jsxRuntime.jsx("img",{src:C.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:C.title||C.filename}),jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:C.filename})]})]})}),jsxRuntime.jsx("td",{className:"px-6 py-4",children:jsxRuntime.jsx(St,{variant:"outline",className:"text-[9px]",children:C.mimeType})}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:Rn(C.fileSize)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:Dp(C.createdAt)}),jsxRuntime.jsx("td",{className:"px-6 py-4 text-right",children:jsxRuntime.jsx("button",{onClick:ee=>{ee.stopPropagation(),de(C.id,ee);},className:`kyro-btn-primary p-2 rounded-lg transition-all ${Ie.has(C.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"})})})]},C.id))})]})}),!d&&be<me&&jsxRuntime.jsx("div",{className:"flex justify-center mt-8 pb-8",children:jsxRuntime.jsx("button",{onClick:Ve,disabled:p,className:"px-8 py-3 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs hover:scale-105 active:scale-95 transition-all shadow-xl disabled:opacity-50 flex items-center gap-2",children:p?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(wr,{size:"sm"})," Loading..."]}):"Load More"})})]})})]}),!r&&D&&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(wr,{})}),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(G).length," Total"]})]}),jsxRuntime.jsx("div",{className:"space-y-4 max-h-[160px] overflow-y-auto pr-2 custom-scrollbar",children:Object.entries(G).map(([C,ee])=>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:C}),jsxRuntime.jsxs("span",{className:"text-[var(--kyro-primary)]",children:[ee,"%"]})]}),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:`${ee}%`}})})]},C))})]})}),Ie.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:Ie.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:()=>rt(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 C=l.filter(ee=>Ie.has(ee.id));e(C);},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:X,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"})})]})]}),le&&!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:()=>H(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:()=>H(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(C=>jsxRuntime.jsx("button",{onClick:()=>{A(C),H(false);},className:`px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all border ${w===C?"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:C},C))})]}),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),H(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:()=>{h(""),H(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"]}),v.map(C=>jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsxs("button",{onClick:()=>{h(C),H(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===C?"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===C?"currentColor":"none"})}),C]}),jsxRuntime.jsx("button",{onClick:ee=>{ee.stopPropagation(),yo(C),H(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"})})]},C))]})]})]})]})]}),jsxRuntime.jsx(lr,{open:!!x,onClose:()=>u(null),title:"Asset Details",subtitle:x?.filename,children:x&&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:[x.type==="image"?jsxRuntime.jsx("img",{src:qr(x.url),alt:"",className:"w-full h-full object-contain p-4"}):x.type==="video"?jsxRuntime.jsx("video",{src:qr(x.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(St,{variant:"outline",className:"text-xs font-bold",children:x.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:()=>M(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:x.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:Rn(x.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:qr(x.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(qr(x.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:x.alt||"",onChange:C=>ya(x.id,{alt:C.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:x.caption||"",onChange:C=>ya(x.id,{caption:C.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 C=document.createElement("a");C.href=qr(x.url),C.download=x.filename,C.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"]}),x.type==="image"&&s&&jsxRuntime.jsx("button",{onClick:()=>P(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:()=>{Nt({title:"Delete Asset",message:`Are you sure you want to delete ${x.filename}? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await kt(`/api/media/${x.id}`),u(null),ie();}catch(C){console.error("Delete failed:",C),$.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"})})]})]})}),F&&x&&jsxRuntime.jsxs(Pt,{open:F,onClose:()=>M(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:x.filename}),jsxRuntime.jsxs("span",{className:"text-white/40 text-[10px] font-bold tracking-widest mt-1",children:[Rn(x.fileSize)," \xB7 ",x.mimeType]})]}),jsxRuntime.jsx("button",{onClick:()=>M(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:x.type==="image"?jsxRuntime.jsx("img",{src:qr(x.url),alt:"",className:"max-h-full max-w-full object-contain shadow-2xl rounded-lg animate-in zoom-in-95 duration-500"}):x.type==="video"?jsxRuntime.jsx("video",{src:qr(x.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&&S&&x&&jsxRuntime.jsx(Pt,{open:S,onClose:()=>P(false),title:"",size:"full",variant:"lightbox",children:jsxRuntime.jsx(hl,{url:qr(x.url),initialCrop:x.metadata?.crop,initialHotspot:x.metadata?.hotspot,onSave:Xa,onCancel:()=>P(false),isSaving:D})}),!r&&jsxRuntime.jsx(xl,{open:z,onClose:()=>se(false),onSubmit:vr,title:"Create New Folder",placeholder:"Folder name"}),!r&&jsxRuntime.jsx(Pt,{open:fe,onClose:()=>W(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:()=>{st("/api/globals/storage-settings",{provider:"local",local:{uploadDir:"./public/uploads",baseUrl:"/uploads"}}).then(()=>{W(false),V(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:ne,onChange:C=>{C.target.files&&B(C.target.files);},multiple:true,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.txt,.zip,.rar,.tar"})]})}var nm=[{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"}],Il=({editor:e,isExpanded:t,setIsExpanded:r,onOpenMediaPicker:o})=>{let[a,n]=Sa.useState(null),s=Sa.useRef(null);if(Sa.useEffect(()=>{function f(m){s.current&&!s.current.contains(m.target)&&n(null);}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[]),!e)return null;let l=()=>{o();},i=()=>{let f=e.getAttributes("link").href,m=window.prompt("URL",f);if(m!==null){if(m===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:m}).run();}},d=f=>{f==="inherit"?e.chain().focus().unsetColor().run():e.chain().focus().setColor(f).run(),n(null);},c=f=>{n(a===f?null:f);},p=()=>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}),v=()=>e.isActive("orderedList")?jsxRuntime.jsx(lucideReact.ListOrdered,{size:12}):e.isActive("taskList")?jsxRuntime.jsx(lucideReact.CheckSquare,{size:12}):jsxRuntime.jsx(lucideReact.List,{size:12}),b=()=>e.isActive("codeBlock")?jsxRuntime.jsx(lucideReact.Terminal,{size:12}):jsxRuntime.jsx(lucideReact.Quote,{size:12}),g=({onClick:f,isActive:m=false,disabled:w=false,children:A,title:T})=>jsxRuntime.jsx("button",{type:"button",onClick:f,disabled:w,title:T,className:`p-1 rounded flex items-center justify-center transition-all duration-150 relative
10
+ ${m?"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
+ ${w?"opacity-35 cursor-not-allowed":"cursor-pointer active:scale-90"}`,children:A}),h=({onClick:f,isActive:m,children:w,title:A})=>jsxRuntime.jsxs("button",{type:"button",onClick:f,title:A,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
+ ${m?"bg-[var(--kyro-bg-hover)] border-[var(--kyro-border)]":""}`,children:[w,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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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(g,{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:nm.map(f=>jsxRuntime.jsx("button",{type:"button",onClick:()=>d(f.value),title:f.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:f.value==="inherit"?"transparent":f.value},children:f.value==="inherit"&&jsxRuntime.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[10px] text-[var(--kyro-text)] font-semibold",children:"\u2205"})},f.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(h,{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:p()})}),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
+ ${e.isActive("heading")?"":"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]"}`,children:"Normal Text"}),[1,2,3,4].map(f=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleHeading({level:f}).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:f})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:["Heading ",f]},f))]})]}),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(h,{onClick:()=>c("lists"),isActive:a==="lists",title:"List Types",children:v()}),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(x,{onClick:()=>c("blocks"),isActive:a==="blocks",title:"Structural Blocks",children:b()}),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(h,{onClick:()=>c("blocks"),isActive:a==="blocks",title:"Structural Blocks",children:b()}),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(x,{onClick:()=>c("align"),isActive:a==="align",title:"Alignment",children:f()}),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(h,{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
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(g,{onClick:i,isActive:e.isActive("link"),title:"Link",children:jsxRuntime.jsx(lucideReact.Link,{size:12})}),jsxRuntime.jsx(g,{onClick:l,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(g,{onClick:()=>r(!t),title:t?"Collapse Workspace":"Enlarge Workspace",children:t?jsxRuntime.jsx(lucideReact.Minimize2,{size:12}):jsxRuntime.jsx(lucideReact.Maximize2,{size:12})})})]})};function jo({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=Ca.useState(false);return Ca.useEffect(()=>{s(true);},[]),n?jsxRuntime.jsx(rm,{field:e,value:t,onChange:r,error:o,disabled:a}):jsxRuntime.jsx(pt,{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(g,{onClick:i,isActive:e.isActive("link"),title:"Link",children:jsxRuntime.jsx(lucideReact.Link,{size:12})}),jsxRuntime.jsx(g,{onClick:l,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(g,{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]=Sa.useState(false);return Sa.useEffect(()=>{s(true);},[]),n?jsxRuntime.jsx(sm,{field:e,value:t,onChange:r,error:o,disabled:a}):jsxRuntime.jsx(pt,{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 rm({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=Ca.useState(false),[l,i]=Ca.useState(0),[d,c]=Ca.useState(false);Ca.useEffect(()=>{if(!n){i(0);return}let f=document.querySelector('[data-kyro-slide-panel="true"]'),v=()=>{i(f?f.getBoundingClientRect().width:0);};v();let b=new MutationObserver(()=>{v();});f&&b.observe(f),window.addEventListener("resize",v);let g=setInterval(v,100);return ()=>{b&&b.disconnect(),window.removeEventListener("resize",v),clearInterval(g);}},[n]);let m=react.useEditor({extensions:[Dp__default.default.configure({codeBlock:true,link:false,underline:false}),Pp__default.default.configure({openOnClick:false}),Ip__default.default,Bp__default.default.configure({types:["heading","paragraph"]}),Lp__default.default,Mp__default.default.configure({multicolor:true}),Ep__default.default,$p__default.default.configure({nested:true}),extensionTextStyle.TextStyle,Up__default.default],content:Array.isArray(t)?{type:"doc",content:t}:t||{type:"doc",content:[]},editable:!a,onUpdate:({editor:f})=>{r(f.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 Ca.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(pt,{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 sm({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=Sa.useState(false),[l,i]=Sa.useState(0),[d,c]=Sa.useState(false);Sa.useEffect(()=>{if(!n){i(0);return}let y=document.querySelector('[data-kyro-slide-panel="true"]'),v=()=>{i(y?y.getBoundingClientRect().width:0);};v();let b=new MutationObserver(()=>{v();});y&&b.observe(y),window.addEventListener("resize",v);let g=setInterval(v,100);return ()=>{b&&b.disconnect(),window.removeEventListener("resize",v),clearInterval(g);}},[n]);let p=react.useEditor({extensions:[Lp__default.default.configure({codeBlock:true,link:false,underline:false}),Mp__default.default.configure({openOnClick:false}),Ep__default.default,$p__default.default.configure({types:["heading","paragraph"]}),Op__default.default,Up__default.default.configure({multicolor:true}),zp__default.default,jp__default.default.configure({nested:true}),extensionTextStyle.TextStyle,Hp__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 Sa.useEffect(()=>{p&&t&&JSON.stringify(t)!==JSON.stringify(p.getJSON())&&p.commands.setContent(Array.isArray(t)?{type:"doc",content:t}:t);},[t,p]),jsxRuntime.jsxs(pt,{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(Al,{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:l>0?`${l+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(Al,{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(Il,{editor:p,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:p})})]}),n&&typeof document<"u"&&reactDom.createPortal(jsxRuntime.jsxs("div",{style:{position:"fixed",top:"16px",bottom:"16px",left:"16px",right:l>0?`${l+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(Il,{editor:p,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:p})})]}),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(Nn,{pickerMode:true,multiple:false,onSelect:f=>{if(f&&f.length>0){let v=f[0];m.chain().focus().setImage({src:v.url,alt:v.alt||v.title||"",title:v.title||""}).run();}c(false);}})})]})}var _o={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)"}},Fa={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 Da(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 Il=Ca.createContext(null);function Ho(){let e=Ca.useContext(Il);return e||{mode:"light",theme:_o,lightTheme:_o,darkTheme:Fa,setMode:()=>{},updateTheme:()=>{},getCssVar:t=>`var(--kyro-${t})`}}function Dl(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`,Pl(o,.9)),t.style.setProperty(`--kyro-${r}-dark`,Pl(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 Pl(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 hr({children:e,defaultMode:t="light",light:r,dark:o}){let[a,n]=Ca.useState(t),[s,l]=Ca.useState(r||{}),[i,d]=Ca.useState(o||{}),c=Da(_o,s),m=Da(Fa,i),f=Ca.useCallback(()=>a==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?m:c:a==="dark"?m:c,[a,c,m]),[v,b]=Ca.useState(f());Ca.useEffect(()=>{let u=f();b(u),Dl(u);},[f]),Ca.useEffect(()=>{if(a!=="system")return;let u=window.matchMedia("(prefers-color-scheme: dark)"),y=()=>{let h=f();b(h),Dl(h);};return u.addEventListener("change",y),()=>u.removeEventListener("change",y)},[a,f]);let g=Ca.useCallback(u=>{l(y=>({...y,...u})),d(y=>({...y,...u}));},[]),x=Ca.useCallback(u=>`var(--kyro-${u})`,[]);return jsxRuntime.jsx(Il.Provider,{value:{mode:a,theme:v,lightTheme:c,darkTheme:m,setMode:n,updateTheme:g,getCssVar:x},children:e})}var Tn=e=>jsxRuntime.jsx(hr,{defaultMode:"light",...e}),Rn=e=>jsxRuntime.jsx(hr,{defaultMode:"dark",...e});var dm=Ca.lazy(()=>import('@uiw/react-codemirror').then(e=>({default:e.default}))),cm=[{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"}],Ll={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())},Pa=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=Ca.useState(false),[l,i]=Ca.useState(false),[d,c]=Ca.useState([]),[m,f]=Ca.useState(false),[v,b]=Ca.useState(false),[g,x]=Ca.useState(false),{theme:u}=Ho(),y=u.colors?.accent||u.colors?.primary||"#6366f1",h=e.language?.toLowerCase()||"javascript";Ca.useEffect(()=>{s(true),i(document.documentElement.classList.contains("dark"));let B=new MutationObserver(()=>{i(document.documentElement.classList.contains("dark"));});return B.observe(document.documentElement,{attributes:true,attributeFilter:["class"]}),()=>B.disconnect()},[]),Ca.useEffect(()=>{if(!n)return;(async()=>{f(true);try{let F=await(Ll[h]||Ll.javascript)();c([F]);}catch(S){console.error("Failed to load language extension:",S),c([]);}finally{f(false);}})();},[h,n]);let R=Ca.useCallback(B=>r?.(B),[r]),P=Ca.useCallback(()=>{navigator.clipboard.writeText(t),b(true),setTimeout(()=>b(false),1500);},[t]),w=Ca.useCallback(()=>{x(B=>!B),document.body.style.overflow=g?"":"hidden";},[g]),k=l?codemirrorThemeAura.aura:codemirrorThemeGithub.githubLight,p=cm.find(B=>B.value===h)?.label||h,T=(B,S=1)=>{let F=parseInt(B.slice(1,3),16),A=parseInt(B.slice(3,5),16),X=parseInt(B.slice(5,7),16);return `rgba(${F}, ${A}, ${X}, ${S})`};return n?jsxRuntime.jsxs("div",{className:"group",style:{"--accent":y,"--accent-light":T(y,.1),"--accent-light-2":T(y,.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)":y,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:P,className:"text-[10px] px-2 py-0.5 rounded font-medium transition-all",style:{backgroundColor:v?"var(--kyro-success)":"var(--kyro-surface-accent)",color:v?"white":"var(--kyro-text-secondary)"},children:v?"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:g?"Exit":"Expand"})]})]}),jsxRuntime.jsxs("div",{className:`relative rounded-md overflow-hidden transition-all duration-200 ${g?"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:y}}),jsxRuntime.jsx(Ca.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:y,borderWidth:"2px"}})}),children:jsxRuntime.jsx(dm,{value:t??"",height:g?"calc(100vh - 100px)":"280px",width:"100%",extensions:d,theme:k,onChange:R,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:y},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 ym(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 Fs=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=Ca.useState(false),[l,i]=Ca.useState(false);Ca.useEffect(()=>{i(true);},[]);let d=Ca.useCallback(f=>{r?.(f.target.value);},[r]),c=Ca.useMemo(()=>t?t.trim().split(/\s+/).filter(Boolean).length:0,[t]),m=t?.length||0;return l?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:ym(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(lr,{open:d,onClose:()=>c(false),title:"Select Image",width:"xl",children:jsxRuntime.jsx(Tn,{pickerMode:true,multiple:false,onSelect:y=>{if(y&&y.length>0){let v=y[0];p.chain().focus().setImage({src:v.url,alt:v.alt||v.title||"",title:v.title||""}).run();}c(false);}})})]})}var Ho={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)"}},Fa={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 Pa(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 El=Sa.createContext(null);function Vo(){let e=Sa.useContext(El);return e||{mode:"light",theme:Ho,lightTheme:Ho,darkTheme:Fa,setMode:()=>{},updateTheme:()=>{},getCssVar:t=>`var(--kyro-${t})`}}function Ll(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`,Ml(o,.9)),t.style.setProperty(`--kyro-${r}-dark`,Ml(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 Ml(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 Nr({children:e,defaultMode:t="light",light:r,dark:o}){let[a,n]=Sa.useState(t),[s,l]=Sa.useState(r||{}),[i,d]=Sa.useState(o||{}),c=Pa(Ho,s),p=Pa(Fa,i),y=Sa.useCallback(()=>a==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?p:c:a==="dark"?p:c,[a,c,p]),[v,b]=Sa.useState(y());Sa.useEffect(()=>{let f=y();b(f),Ll(f);},[y]),Sa.useEffect(()=>{if(a!=="system")return;let f=window.matchMedia("(prefers-color-scheme: dark)"),m=()=>{let w=y();b(w),Ll(w);};return f.addEventListener("change",m),()=>f.removeEventListener("change",m)},[a,y]);let g=Sa.useCallback(f=>{l(m=>({...m,...f})),d(m=>({...m,...f}));},[]),h=Sa.useCallback(f=>`var(--kyro-${f})`,[]);return jsxRuntime.jsx(El.Provider,{value:{mode:a,theme:v,lightTheme:c,darkTheme:p,setMode:n,updateTheme:g,getCssVar:h},children:e})}var Fn=e=>jsxRuntime.jsx(Nr,{defaultMode:"light",...e}),Pn=e=>jsxRuntime.jsx(Nr,{defaultMode:"dark",...e});var um=Sa.lazy(()=>import('@uiw/react-codemirror').then(e=>({default:e.default}))),ym=[{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"}],Ol={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())},Ia=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=Sa.useState(false),[l,i]=Sa.useState(false),[d,c]=Sa.useState([]),[p,y]=Sa.useState(false),[v,b]=Sa.useState(false),[g,h]=Sa.useState(false),{theme:f}=Vo(),m=f.colors?.accent||f.colors?.primary||"#6366f1",w=e.language?.toLowerCase()||"javascript";Sa.useEffect(()=>{s(true),i(document.documentElement.classList.contains("dark"));let M=new MutationObserver(()=>{i(document.documentElement.classList.contains("dark"));});return M.observe(document.documentElement,{attributes:true,attributeFilter:["class"]}),()=>M.disconnect()},[]),Sa.useEffect(()=>{if(!n)return;(async()=>{y(true);try{let P=await(Ol[w]||Ol.javascript)();c([P]);}catch(S){console.error("Failed to load language extension:",S),c([]);}finally{y(false);}})();},[w,n]);let A=Sa.useCallback(M=>r?.(M),[r]),T=Sa.useCallback(()=>{navigator.clipboard.writeText(t),b(true),setTimeout(()=>b(false),1500);},[t]),k=Sa.useCallback(()=>{h(M=>!M),document.body.style.overflow=g?"":"hidden";},[g]),x=l?codemirrorThemeAura.aura:codemirrorThemeGithub.githubLight,u=ym.find(M=>M.value===w)?.label||w,F=(M,S=1)=>{let P=parseInt(M.slice(1,3),16),D=parseInt(M.slice(3,5),16),Q=parseInt(M.slice(5,7),16);return `rgba(${P}, ${D}, ${Q}, ${S})`};return n?jsxRuntime.jsxs("div",{className:"group",style:{"--accent":m,"--accent-light":F(m,.1),"--accent-light-2":F(m,.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:p?"var(--kyro-surface-accent)":m,color:p?"var(--kyro-text-muted)":"white"},children:p?"...":u})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:T,className:"text-[10px] px-2 py-0.5 rounded font-medium transition-all",style:{backgroundColor:v?"var(--kyro-success)":"var(--kyro-surface-accent)",color:v?"white":"var(--kyro-text-secondary)"},children:v?"Copied":"Copy"}),jsxRuntime.jsx("button",{type:"button",onClick:k,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:g?"Exit":"Expand"})]})]}),jsxRuntime.jsxs("div",{className:`relative rounded-md overflow-hidden transition-all duration-200 ${g?"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:m}}),jsxRuntime.jsx(Sa.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:m,borderWidth:"2px"}})}),children:jsxRuntime.jsx(um,{value:t??"",height:g?"calc(100vh - 100px)":"280px",width:"100%",extensions:d,theme:x,onChange:A,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:m},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 bm(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 Bs=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=Sa.useState(false),[l,i]=Sa.useState(false);Sa.useEffect(()=>{i(true);},[]);let d=Sa.useCallback(y=>{r?.(y.target.value);},[r]),c=Sa.useMemo(()=>t?t.trim().split(/\s+/).filter(Boolean).length:0,[t]),p=t?.length||0;return l?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 ",p," 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:bm(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 An({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=Ca.useState(false),[l,i]=Ca.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 v=document.createElement("textarea");v.value=d,v.style.position="fixed",v.style.opacity="0",document.body.appendChild(v),v.select(),document.execCommand("copy"),document.body.removeChild(v),s(true),setTimeout(()=>s(false),1800);}},f=()=>{if(l||a)return;i(true);let v=new Uint8Array(32);crypto.getRandomValues(v);let b=Array.from(v).map(g=>g.toString(16).padStart(2,"0")).join("");r?.(b),setTimeout(()=>i(false),400);};return jsxRuntime.jsx(pt,{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:f,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 ${l?"animate-spin":""}`})})]})})}var Fn=null,$l=false,Ds=async()=>(Fn&&$l||(Fn=unstorage.createStorage({driver:km__default.default({dbName:"kyro-autosave",storeName:"autosave"})}),$l=true),Fn),hm=()=>typeof window>"u"?{getItem:async()=>null,setItem:async()=>{},removeItem:async()=>{}}:{getItem:async e=>{try{return await(await Ds()).getItem(e)??null}catch(t){return console.error("Storage getItem error:",t),localStorage.getItem(e)}},setItem:async(e,t)=>{try{await(await Ds()).setItem(e,t);}catch(r){console.error("Storage setItem error:",r),localStorage.setItem(e,t);}},removeItem:async e=>{try{await(await Ds()).removeItem(e);}catch(t){console.error("Storage removeItem error:",t),localStorage.removeItem(e);}}},$e=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},l=s;for(let i=0;i<n.length-1;i++)l[n[i]]===void 0&&(l[n[i]]={}),l[n[i]]={...l[n[i]]},l=l[n[i]];return l[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,l]of Object.entries(a))o-new Date(l.draftUpdatedAt).getTime()<6048e5&&(n[s]=l);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(()=>hm()),partialize:e=>({sidebarCollapsed:e.sidebarCollapsed,draftCache:e.draftCache}),onRehydrateStorage:()=>e=>{e&&e.pruneExpiredDrafts();}}));function Dn(e){return e?e.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function Go({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",l=e.name==="slug",{isSlugLocked:i,setIsSlugLocked:d,formData:c}=$e(),m=e.variant==="email"?"email":e.variant==="password"?"password":e.variant==="url"?"url":"text",f=t==null?"":String(t),v={id:e.name,value:f,onChange:b=>r?.(b.target.value),placeholder:e.admin?.placeholder,disabled:a||n||l&&i,minLength:e.minLength,maxLength:e.maxLength,required:e.required,className:`kyro-form-input ${l?"pr-24":""} ${a||n||l&&i?"opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed":""}`};return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"relative",children:[s?jsxRuntime.jsx("textarea",{...v,rows:e.rows||4}):jsxRuntime.jsx("input",{type:m,...v,pattern:e.pattern}),l&&jsxRuntime.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:[!i&&jsxRuntime.jsx("button",{type:"button",onClick:()=>r?.(Dn(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(!i),className:`p-1.5 rounded transition-colors ${i?"text-[var(--kyro-primary)] bg-[var(--kyro-primary-alpha)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,title:i?"Unlock slug":"Lock slug",children:i?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:f.length>60?"text-red-500":f.length>=40?"text-green-500":"text-amber-600",children:[f.length," / 60 \u2014 ",f.length>60?"Too Long":f.length>=40?"Ideal":"Short"]})})]})})}function Pn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(pt,{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 In({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(pt,{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:l=>r?.(l.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 Bn({field:e,value:t="",onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(pt,{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 Ba(e){return e?Array.isArray(e)?e:Object.values(e):[]}function Mn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function En(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Ia(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 Nm={pages:"FileText",posts:"Newspaper",categories:"Tags",menu:"Menu",products:"ShoppingBag",customers:"Users",orders:"ShoppingCart",coupons:"Ticket",forms:"FileInput","form-entries":"Inbox"};function bo(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 bo(s.fields,n,r);if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let i of s.tabs)if(i.fields&&Array.isArray(i.fields)&&bo(i.fields,n,r))return true;return false}if(s.type==="blocks"&&s.blocks&&Array.isArray(s.blocks)){let i=n.split(".")[0],d=n.split(".").slice(1).join(".");if(!d)return false;for(let c of s.blocks)if(c.slug===i&&c.fields&&Array.isArray(c.fields))return bo(c.fields,d,r);return false}return s.type==="array"&&s.fields&&Array.isArray(s.fields)?bo(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)&&bo(s.fields,t,r))return true;if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let i of s.tabs)if(i.fields&&Array.isArray(i.fields)&&bo(i.fields,t,r))return true}}}return false}function Cm(e,t){for(let[r,o]of Object.entries(e)){let a=Nm[r],n=t?.[r];if(a&&!o.admin?.icon&&(o.admin={...o.admin,icon:a}),n){let{fields:s,...l}=n;if(o.admin={...o.admin,...l},s&&o.fields&&Array.isArray(o.fields))for(let[i,d]of Object.entries(s))bo(o.fields,i,d);}}}function Sm(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 Ia(t,Object.values(templates.mediaCollections)),Ia(t,Object.values(templates.authCollections)),{collections:Mn(t),globals:En(r)}}function Tm(e){let t=Ba(e.collections),r=Ba(e.globals);if(t.length===0&&r.length===0)return Sm("kitchen-sink");let o=[];return Ia(o,Object.values(templates.mediaCollections)),Ia(o,Object.values(templates.authCollections)),Ia(o,t),{collections:Mn(o),globals:En(r)}}var Ln=null;function Rm(){if(Ln)return Ln;try{if(typeof __KYRO_ADMIN_CONFIG_FILE__=="string"&&Do__default.default.existsSync(__KYRO_ADMIN_CONFIG_FILE__))return Ln=JSON.parse(Do__default.default.readFileSync(__KYRO_ADMIN_CONFIG_FILE__,"utf8")),Ln}catch{}return null}var ql=Rm()||{collections:[],globals:[]},Xl=Tm(ql);Cm(Xl.collections,ql.collectionOverrides);var Yl=Xl,Wo=Yl.collections,Ql=Yl.globals,Bs=["users","audit_logs"];Object.values(Wo).filter(e=>!Bs.includes(e.slug)&&e.admin?.hidden!==true);function $n({field:e,value:t,onChange:r,error:o,disabled:a,formData:n,siblingData:s,collectionSlug:l,globalSlug:i}){let d=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,[c,m]=Ca.useState(null),f=JSON.stringify(n||{}),v=JSON.stringify(s||{});Ca.useEffect(()=>{if(e.options!=="__KYRO_DYNAMIC_OPTIONS__")return;let x=setTimeout(async()=>{try{let u="";if(l)u=`${br}/${l}/dynamic-options/${e.name}`;else if(i)u=`${br}/globals/${i}/dynamic-options/${e.name}`;else return;let y=await at(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:JSON.parse(f),siblingData:JSON.parse(v)})});if(y.ok){let h=await y.json();h.options&&m(h.options);}}catch(u){console.error("Failed to fetch dynamic options:",u);}},300);return ()=>clearTimeout(x)},[f,v,e.name,e.options,l,i]);let b=c||[];return e.options!=="__KYRO_DYNAMIC_OPTIONS__"&&(typeof e.options=="function"?b=e.options({data:n||{},siblingData:s||{}}):Array.isArray(e.options)&&(b=e.options)),e.dynamicOptions==="collections"&&(b=Object.keys(Wo).filter(g=>g!=="media").map(g=>({label:Wo[g]?.label||g,value:g}))),jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsxs("select",{id:e.name,value:e.hasMany?Array.isArray(t)?t:[]:t||"",onChange:g=>{if(e.hasMany){let x=Array.from(g.target.selectedOptions,u=>u.value);r?.(x);}else r?.(g.target.value||void 0);},multiple:e.hasMany,disabled:a||d,required:e.required,className:`kyro-form-input ${a||d?"opacity-50 cursor-not-allowed":""}`,children:[!e.required&&!e.hasMany&&jsxRuntime.jsx("option",{value:"",children:"Select..."}),b.map(g=>jsxRuntime.jsx("option",{value:g.value,children:g.label},g.value))]})})}function On({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 Us(e){let t=e?.mainTabs;return e?.title||t?.title||e?.name||e?.label||e?.email||e?.filename||e?.slug||"Untitled"}function jm({id:e,label:t,relation:r,onRemove:o,disabled:a}){let{attributes:n,listeners:s,setNodeRef:l,transform:i,transition:d,isDragging:c}=sortable.useSortable({id:e}),m={transform:utilities.CSS.Transform.toString(i),transition:d,zIndex:c?10:1,opacity:c?.8:1};return jsxRuntime.jsxs("span",{ref:l,style:m,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)] border border-transparent ${c?"border-[var(--kyro-primary)] shadow-sm bg-[var(--kyro-sidebar-active)]/20":""}`,children:[!a&&jsxRuntime.jsx("div",{...n,...s,className:"cursor-grab active:cursor-grabbing hover:bg-[var(--kyro-sidebar-active)]/20 rounded p-0.5 text-[var(--kyro-sidebar-active)] opacity-70 flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-2.5 h-2.5"})}),r&&jsxRuntime.jsxs("span",{className:"opacity-60 mr-0.5",children:[r,":"]}),t,!a&&jsxRuntime.jsx("button",{type:"button",onClick:o,className:"hover:opacity-70 p-0.5 ml-0.5 flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})}function _m({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=Ca.useState(false),[l,i]=Ca.useState(""),[d,c]=Ca.useState([]),[m,f]=Ca.useState(false),[v,b]=Ca.useState([]),g=Ca.useRef(new Set),x=Ca.useRef(null),u=Ca.useRef(()=>{});u.current=r||(()=>{});let y=e.hasMany,h=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],R=h.length>1,[P,w]=Ca.useState(h[0]||""),k=Ca.useCallback(()=>t?(y?Array.isArray(t)?t:[]:t?[t]:[]).map(j=>typeof j=="object"&&j!==null?j.value||j.id||"":String(j)).filter(Boolean):[],[t,y]),p=Ca.useCallback($=>{$.length!==0&&$.forEach(j=>{if(g.current.has(j))return;g.current.add(j);let ae=R?(()=>{if(!t)return P;let H=(y?Array.isArray(t)?t:[]:[t]).find(re=>typeof re=="object"&&re!==null?re.value===j||re.id===j:false);return H&&typeof H=="object"&&H.relationTo||P})():P;Be(`/api/${ae}/${j}`).then(ne=>{let H=ne.data||ne;!H||typeof H!="object"||b(re=>re.some(ve=>ve.id===j)?re:[...re,{...H,id:String(H.id),relationTo:ae}]);}).catch(()=>{});});},[R,t,P,y]);Ca.useEffect(()=>{let $=k();p($);},[k,p]);let T=Ca.useCallback(($="")=>{f(true);let ae=`/api/${P}?${Za($,["title","name","label","email"])}`;Be(ae).then(ne=>{c(H=>{let re=new Set(H.map(L=>L.id)),ve=(ne.docs||[]).filter(L=>!re.has(L.id)).map(L=>({...L,id:L.id}));return [...H,...ve]}),f(false);}).catch(()=>{f(false);});},[P]);Ca.useEffect(()=>{n&&(c([]),T(l));},[n,P]),Ca.useEffect(()=>{let $=j=>{x.current&&!x.current.contains(j.target)&&s(false);};return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[]);let B=$=>typeof $=="object"&&$!==null?$.value||$.id||"":String($),S=$=>{let j=$.id;return t?y&&Array.isArray(t)?t.some(ae=>B(ae)===j):B(t)===j:false},F=$=>{let j=$.id;if(y){let ae=Array.isArray(t)?t:[];if(S($))u.current?.(ae.filter(ne=>B(ne)!==j));else {let ne=R?{relationTo:P,value:j}:j;u.current?.([...ae,ne]);}}else if(S($))u.current?.(null);else {let ae=R?{relationTo:P,value:j}:j;u.current?.(ae),s(false),i("");}},A=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}})),X=$=>{let{active:j,over:ae}=$;if(!ae||j.id===ae.id)return;let ne=y?Array.isArray(t)?t:[]:[],H=ne.findIndex(ve=>B(ve)===j.id),re=ne.findIndex(ve=>B(ve)===ae.id);if(H!==-1&&re!==-1){let ve=[...ne],[L]=ve.splice(H,1);ve.splice(re,0,L),u.current?.(ve);}},K=()=>{if(!t)return null;let $=y?Array.isArray(t)?t:[]:t?[t]:[],j=$.map(ae=>B(ae));return y&&$.length>1?jsxRuntime.jsx(core.DndContext,{sensors:A,collisionDetection:core.closestCenter,onDragEnd:X,children:jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:jsxRuntime.jsx(sortable.SortableContext,{items:j,strategy:sortable.horizontalListSortingStrategy,children:$.map(ae=>{let ne=B(ae),H=v.find(L=>L.id===ne),re=H?Us(H):ne.slice(0,12),ve=R&&H?H.relationTo:null;return jsxRuntime.jsx(jm,{id:ne,label:re,relation:ve,onRemove:()=>{let L=$.filter(O=>B(O)!==ne);u.current?.(L);},disabled:a},ne)})})})}):jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:$.map(ae=>{let ne=B(ae),H=v.find(L=>L.id===ne),re=H?Us(H):ne.slice(0,12),ve=R&&H?H.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:[ve&&jsxRuntime.jsxs("span",{className:"opacity-60 mr-0.5",children:[ve,":"]}),re,!a&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{let L=$.filter(O=>B(O)!==ne);u.current?.(y?L:L[0]??null);},className:"hover:opacity-70 flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},ne)})})};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:x,className:"relative",children:[R&&jsxRuntime.jsx("div",{className:"flex gap-1 mb-1.5",children:h.map($=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{w($),c([]),i("");},className:`px-2 py-0.5 text-[10px] font-bold rounded transition-colors ${P===$?"kyro-btn-primary":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,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:l,onChange:$=>{i($.target.value),s(true),T($.target.value);},onFocus:()=>s(true),placeholder:e.admin?.placeholder||`Search ${P}...`,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(On,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:d.map($=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>F($),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors ${S($)?"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:Us($)}),S($)&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-sidebar-active)]",children:"\u2713"})]}),"slug"in $&&typeof $.slug=="string"&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)]",children:$.slug})]},$.id))})}),K()]}),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 La=_m;var xo=Ca.createContext(null);function ed(e=[],t=[]){return vanilla.createStore((r,o)=>({blocks:[],allowedBlocks:e,dynamicCategories:t,setBlocks:a=>{let n=zs(a||[]);r({blocks:n});},onBlocksChange:null,setOnBlocksChange:a=>r({onBlocksChange:a}),addBlock:(a,n)=>{let s=qo(a),{blocks:l}=o(),i=[...l];n!==void 0?i.splice(n,0,s):i.push(s),r({blocks:i});let{onBlocksChange:d}=o();d&&d();},updateBlock:(a,n)=>{let{blocks:s}=o(),l=Ma(s,i=>{let d=i.findIndex(c=>c.id===a);if(d!==-1){let c=[...i];return c[d]={...c[d],...n},{newList:c,found:true}}return {newList:i,found:false}});if(l!==s){r({blocks:l});let{onBlocksChange:i}=o();i&&i();}},removeBlock:a=>{if(!a)return;let{blocks:n}=o(),s=Ma(n,l=>{let i=l.filter(d=>d.id!==a);return i.length!==l.length?{newList:i,found:true}:{newList:l,found:false}});if(s!==n){r({blocks:s});let{onBlocksChange:l}=o();l&&l();}},moveBlock:(a,n)=>{let{blocks:s}=o(),l=Ma(s,i=>{let d=i.findIndex(c=>c.id===a);if(d!==-1){let c=n==="up"?d-1:d+1;if(c>=0&&c<i.length){let m=[...i];return [m[d],m[c]]=[m[c],m[d]],{newList:m,found:true}}}return {newList:i,found:false}});if(l!==s){r({blocks:l});let{onBlocksChange:i}=o();i&&i();}}}))}function zs(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=zs(r.children)),r.data?.columnData&&Array.isArray(r.data.columnData)&&(r.data={...r.data,columnData:r.data.columnData.map(o=>({...o,children:o.children?zs(o.children):o.children}))}),r}):[]}function qo(e){let t=Gm(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 Gm(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 je(e){let t=Ca.useContext(xo);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 l=o(s.children);if(l)return l}}}};return o(r.blocks)})}function Le(){let e=Ca.useContext(xo);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 Ma(e,t){let{newList:r,found:o}=t(e);if(o)return r;let a=false,n=e.map(s=>{let l={...s},i=false;if(s.children&&s.children.length>0){let d=Ma(s.children,t);d!==s.children&&(l.children=d,i=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=Ma(c.children,t);if(m!==c.children)return {...c,children:m}}return c});d.some((c,m)=>c!==s.data.columnData[m])&&(l.data={...l.data,columnData:d},i=true);}return i&&(a=true),i?l:s});return a?n:e}function $a({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 td({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 ko=({id:e,type:t,label:r,children:o,className:a=""})=>{let{moveBlock:n,removeBlock:s}=Le();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 ad=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,l)=>{o(e.id,{data:{...a,[s]:l}});};return jsxRuntime.jsx(ko,{id:e.id,type:"heading",label:"Heading",children:jsxRuntime.jsx(_s,{text:a.text||"",onChange:n,compact:true})})};var sd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,l)=>{o(e.id,{data:{...a,[s]:l}});};return jsxRuntime.jsx(ko,{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 id=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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:i=>l("src",i)})]}),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:i=>l("alt",i.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:i=>l("caption",i.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 Vs=({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 dd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(Vs,{src:s.src||"",title:s.title||"",onChange:l,onUploadChange:i=>l("src",i),compact:true})]})};function ou({id:e,text:t,onRemove:r}){let{attributes:o,listeners:a,setNodeRef:n,transform:s,transition:l,isDragging:i}=sortable.useSortable({id:e}),d={transform:utilities.CSS.Transform.toString(s),transition:l,zIndex:i?10:1,opacity:i?.8:1};return jsxRuntime.jsxs("div",{ref:n,style:d,className:`flex items-center gap-2 group/item p-1.5 hover:bg-[var(--kyro-surface-accent)]/50 rounded-md transition-colors ${i?"bg-[var(--kyro-surface-accent)] shadow-sm":""}`,children:[jsxRuntime.jsx("div",{...o,...a,className:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-border)] rounded flex-shrink-0",onClick:c=>c.stopPropagation(),children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsxs("span",{className:"text-sm text-[var(--kyro-text-primary)] flex-1",children:["\u2022 ",t]}),jsxRuntime.jsx("button",{type:"button",onClick:r,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"})]})}var Oa=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=Ca__default.default.useState(""),[n,s]=Ca__default.default.useState([]);Ca__default.default.useEffect(()=>{let v=n.map(b=>b.text);JSON.stringify(v)!==JSON.stringify(e)&&s(e.map((b,g)=>({id:`${b}-${g}-${Math.random().toString(36).substr(2,4)}`,text:b})));},[e]);let l=()=>{o.trim()&&(t([...e,o.trim()]),a(""));},i=v=>{v.key==="Enter"&&(v.preventDefault(),l());},d=v=>{t(e.filter((b,g)=>g!==v));},c=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}})),m=v=>{let{active:b,over:g}=v;if(!g||b.id===g.id)return;let x=n.findIndex(y=>y.id===b.id),u=n.findIndex(y=>y.id===g.id);if(x!==-1&&u!==-1){let y=[...e],[h]=y.splice(x,1);y.splice(u,0,h),t(y);}},f=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.jsx(core.DndContext,{sensors:c,collisionDetection:core.closestCenter,onDragEnd:m,children: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(sortable.SortableContext,{items:n.map(v=>v.id),strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsx("div",{className:"space-y-1",children:n.map((v,b)=>jsxRuntime.jsx(ou,{id:v.id,text:v.text,onRemove:()=>d(b)},v.id))})}),jsxRuntime.jsx("input",{type:"text",value:o,onChange:v=>a(v.target.value),onKeyDown:i,className:f,placeholder:"Type and press Enter to add..."})]})})};var cd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},l=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(Oa,{items:l,onChange:d=>{o(e.id,{data:{...s,items:d}});},compact:true})]})};var pd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(Pa,{field:{type:"code",name:"code",label:"Source Code",language:s.language||"javascript"},value:s.code||"",onChange:i=>l("code",i)}),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:i=>l("language",i.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 md=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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:i=>l("file",i)})]})};var Xs=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=Ca__default.default.useState(0),n=(m,f)=>{let v=[...e];v[m]={...v[m],title:f},t(v);},s=(m,f)=>{let v=[...e];v[m]={...v[m],content:f},t(v);},l=m=>{let f=e.filter((v,b)=>b!==m);t(f),o===m?a(null):o!==null&&o>m&&a(o-1);},i=()=>{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,f)=>{let v=o===f;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(v?null:f),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 ${f+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),l(f);},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"})}),v?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)]"})]})]}),v&&jsxRuntime.jsxs("div",{className:"p-2.5 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:m.title||"",onChange:b=>n(f,b.target.value),onClick:b=>b.stopPropagation(),className:c,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:m.content||"",onChange:b=>s(f,b.target.value),onClick:b=>b.stopPropagation(),className:`${c} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},f)})}),jsxRuntime.jsxs("button",{type:"button",onClick:i,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,f)=>{let v=o===f;return jsxRuntime.jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(v?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",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${f+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),l(f);},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"})}),v?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)]"})]})]}),v&&jsxRuntime.jsxs("div",{className:"p-3 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:m.title||"",onChange:b=>n(f,b.target.value),className:d,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:m.content||"",onChange:b=>s(f,b.target.value),className:`${d} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},f)})}),jsxRuntime.jsxs("button",{type:"button",onClick:i,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 ud=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=Array.isArray(s.items)?s.items:[],i=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:["(",l.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(Xs,{items:l,onChange:i,compact:true})]})};var yd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},l=i=>{o(e.id,{data:{...s,content:i}});};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(jo,{field:{name:"content",label:"Content",type:"richtext"},value:s.content,onChange:l})]})};var Ys=({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",l=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:i=>a("heading",i.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:i=>a("subheading",i.target.value),className:l,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:i=>a("ctaText",i.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:i=>a("ctaUrl",i.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:i=>a("heading",i.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:i=>a("subheading",i.target.value),className:l,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:i=>a("ctaText",i.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:i=>a("ctaUrl",i.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 jn({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 uu=new Set(["text","number","checkbox","select","radio","color","email","password"]);function yu(e){let t=e.fields||[];return t.length===0||t.length>4?false:t.every(r=>uu.has(r.type))}function bd({id:e,index:t,isOpen:r,setOpenIndex:o,item:a,field:n,renderField:s,onChangeItem:l,onRemove:i,disabled:d,compact:c,getItemLabel:m}){let{attributes:f,listeners:v,setNodeRef:b,transform:g,transition:x,isDragging:u}=sortable.useSortable({id:e}),y={transform:utilities.CSS.Transform.toString(g),transition:x,zIndex:u?10:1,opacity:u?.8:1};return c?jsxRuntime.jsxs("div",{ref:b,style:y,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 ${u?"bg-[var(--kyro-surface-accent)]/50":""}`,children:[jsxRuntime.jsx("div",{...f,...v,className:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-surface-accent)] rounded flex-shrink-0 mt-1",children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] pt-2.5 min-w-[18px] text-center",children:t+1}),jsxRuntime.jsx("div",{className:`flex-1 min-w-0 ${(n.fields||[]).length>=3?"flex flex-col gap-1.5":"flex items-start gap-1.5"}`,children:(n.fields||[]).map(h=>jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:s(h,a,l)},h.name))}),jsxRuntime.jsx("button",{type:"button",disabled:d,onClick:i,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"})]})})]}):jsxRuntime.jsxs("div",{ref:b,style:y,className:`border border-[var(--kyro-border)] rounded-lg overflow-hidden group bg-[var(--kyro-surface)] ${u?"border-[var(--kyro-primary)] shadow-md":""}`,children:[jsxRuntime.jsxs("div",{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.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[jsxRuntime.jsx("div",{...f,...v,className:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-border)] rounded flex-shrink-0",children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-4 h-4"})}),jsxRuntime.jsx("span",{role:"button",tabIndex:0,onClick:()=>o(r?null:t),onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),o(r?null:t));},className:"text-xs font-bold tracking-widest text-[var(--kyro-text-muted)] truncate cursor-pointer flex-1 py-1 text-left",children:m(a)||`Item ${t+1}`})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",disabled:d,onClick:h=>{h.stopPropagation(),i();},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"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o(r?null:t),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",children:r?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)]"})})]})]}),r&&jsxRuntime.jsx("div",{className:"p-4 bg-[var(--kyro-surface)] space-y-4",children:(n.fields||[]).map(h=>s(h,a,l))})]})}function _n({field:e,value:t,onChange:r,renderField:o,disabled:a}){let n=Array.isArray(t)?t:[],s=e.fields||[],l=s[0],i=l?.name||"user",d=l?.type==="relationship",[c,m]=Ca__default.default.useState(0);Ca__default.default.useEffect(()=>{let u=false,y=n.filter(h=>typeof h!="object"||h===null?(u=true,false):true).map(h=>!h.id&&!h._key?(u=true,{...h,id:Math.random().toString(36).substr(2,9)}):h);u&&r(y);},[t,r]);function f(u){for(let y of ["label","title","name"]){let h=u[y];if(h&&typeof h=="string")return h}for(let y of s){if(y.type==="text"||y.type==="textarea"){let h=u[y.name];if(h&&typeof h=="string")return h}if(y.type==="group"&&y.fields){for(let h of y.fields)if(h.type==="text"||h.type==="textarea"){let P=u[y.name]?.[h.name];if(P&&typeof P=="string")return P}}}return ""}let v=yu(e),b=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}})),g=u=>{let{active:y,over:h}=u;if(!h||y.id===h.id)return;let R=n.findIndex(w=>(w.id||w._key)===y.id),P=n.findIndex(w=>(w.id||w._key)===h.id);if(R!==-1&&P!==-1){let w=[...n],[k]=w.splice(R,1);w.splice(P,0,k),r(w);}},x=Ca__default.default.useMemo(()=>n.map(u=>u?.id||u?._key||""),[n]);return d?jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),jsxRuntime.jsx(La,{field:{name:i,relationTo:e.fields?.[0]?.relationTo||"",hasMany:true,label:e.fields?.[0]?.label},value:n.map(u=>u[i]).filter(Boolean),onChange:u=>{let y=(u||[]).map(h=>({[i]:h,id:Math.random().toString(36).substr(2,9)}));r(y);},disabled:a})]}):jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),jsxRuntime.jsx(core.DndContext,{sensors:b,collisionDetection:core.closestCenter,onDragEnd:g,children:v?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:[jsxRuntime.jsx(sortable.SortableContext,{items:x,strategy:sortable.verticalListSortingStrategy,children:n.map((u,y)=>jsxRuntime.jsx(bd,{id:u.id||u._key||`idx-${y}`,index:y,isOpen:false,setOpenIndex:()=>{},item:u,field:e,renderField:o,onChangeItem:h=>{let R=[...n];R[y]=h,r(R);},onRemove:()=>r(n.filter((h,R)=>R!==y)),disabled:a,compact:true,getItemLabel:f},u.id||u._key||y))}),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,{id:Math.random().toString(36).substr(2,9)}]),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:[jsxRuntime.jsx(sortable.SortableContext,{items:x,strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsx("div",{className:"space-y-2",children:n.map((u,y)=>{let h=c===y;return jsxRuntime.jsx(bd,{id:u.id||u._key||`idx-${y}`,index:y,isOpen:h,setOpenIndex:m,item:u,field:e,renderField:o,onChangeItem:R=>{let P=[...n];P[y]=R,r(P);},onRemove:()=>r(n.filter((R,P)=>P!==y)),disabled:a,compact:false,getItemLabel:f},u.id||u._key||y)})})}),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:()=>{let u=Math.random().toString(36).substr(2,9);r([...n,{id:u}]),m(n.length);},children:"+ Add Item"})]})})]})}var xd="other";function kd(){return xd}function Hn(e){xd=e;}var wo=({field:e,value:t,onChange:r,error:o,disabled:a,formData:n,siblingData:s,collectionSlug:l,globalSlug:i})=>{if(e.hidden===true||e.admin?.hidden===true)return null;let d=c=>{Hn("keystroke"),r(c);};switch(e.type){case "text":case "email":case "url":return jsxRuntime.jsx(Go,{field:e,value:t,onChange:d,error:o,disabled:a});case "textarea":return jsxRuntime.jsx(Go,{field:{...e,variant:"textarea"},value:t,onChange:d,error:o,disabled:a});case "password":return jsxRuntime.jsx(Go,{field:{...e,variant:"password"},value:t,onChange:d,error:o,disabled:a});case "secret":return jsxRuntime.jsx(An,{field:e,value:t,onChange:r,error:o,disabled:a});case "number":return jsxRuntime.jsx(Pn,{field:e,value:t,onChange:r,disabled:a,error:o});case "checkbox":return jsxRuntime.jsx(In,{field:e,value:t,onChange:r,disabled:a,error:o});case "select":return jsxRuntime.jsx($n,{field:e,value:t,onChange:d,error:o,disabled:a,formData:n,siblingData:s,collectionSlug:l,globalSlug:i});case "date":return jsxRuntime.jsx(Bn,{field:e,value:t,onChange:r,disabled:a,error:o});case "richtext":return jsxRuntime.jsx(jo,{field:e,value:t,onChange:d,disabled:a,error:o});case "markdown":return jsxRuntime.jsx(Fs,{field:e,value:t,onChange:d,disabled:a,error:o});case "code":return jsxRuntime.jsx(Pa,{field:e,value:t,onChange:d,disabled:a,error:o});case "image":case "upload":return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsx(lr,{field:e,value:t,onChange:r,disabled:a})});case "relationship":return jsxRuntime.jsx(La,{field:e,value:t,onChange:r,disabled:a,error:o});case "list":return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsx(Oa,{items:Array.isArray(t)?t:[],onChange:r,compact:true})});case "array":return jsxRuntime.jsx(_n,{field:e,value:Array.isArray(t)?t:[],onChange:r,disabled:a,renderField:(c,m,f)=>{let v=m[c.name];return jsxRuntime.jsx(wo,{field:c,value:v,onChange:b=>{f({...m,[c.name]:b});},disabled:a,error:o},c.name)}});case "blocks":return jsxRuntime.jsx(Zs,{field:e,value:t,onChange:d,disabled:a,error:o});case "group":return jsxRuntime.jsx(jn,{field:e,value:t,onChange:r,renderField:(c,m,f)=>{let v=m[c.name];return jsxRuntime.jsx(wo,{field:c,value:v,onChange:b=>{f({...m,[c.name]:b});},disabled:a,error:o,collectionSlug:l,globalSlug:i},c.name)}});case "color":return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("input",{type:"color",value:t||"#000000",onChange:c=>r(c.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:c=>r(c.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 Qo=({block:e,blockSchema:t,onClose:r})=>{let o=je(e.id),{updateBlock:a}=Le(),n=o?.data||e.data||{},s=o?.children||e.children||[],l=(m,f)=>{a(e.id,{data:{...n,[m]:f}});},i=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 v={values:n,...n};if(!m.admin.condition(v,v))return null}catch(v){console.warn(`Condition error for field ${m.name}:`,v);}else if(typeof m.admin.condition=="object")try{let v=m.admin.condition,b=v.field,g=n[b],x=!0;if("equals"in v?x=g===v.equals:"notEquals"in v?x=g!==v.notEquals:"in"in v&&Array.isArray(v.in)&&(x=v.in.includes(g)),!x)return null}catch(v){console.warn(`Declarative condition error for field ${m.name}:`,v);}}let f=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(wo,{field:m,value:f,onChange:v=>l(m.name,v)})},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=Pe[e.type]||Pe.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(Zr,{blockId:e.id,children:s,onUpdateChildren:i})]})]}),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 fu=6,Zr=({blockId:e,children:t,onUpdateChildren:r,depth:o=0,maxDepth:a=fu})=>{let[n,s]=Ca.useState(false),[l,i]=Ca.useState(new Set),[d,c]=Ca.useState(null),[m,f]=Ca.useState(null),v=Ca.useContext(xo);if(!v)throw new Error("ChildBlocksTree must be used within a BlocksContext");let b=zustand.useStore(v,p=>p.dynamicCategories),g=zustand.useStore(v,p=>p.allowedBlocks),x=o<a,u=16,y=p=>{let T=qo(p);r([...t,T]),c(T.id);},h=p=>{let T=t.filter(B=>B.id!==p);r(T);},P=(p,T)=>{let B=t.map(S=>S.id===p?{...S,children:T}:S);r(B);},w=p=>{i(T=>{let B=new Set(T);return B.has(p)?B.delete(p):B.add(p),B});},k=p=>{let T=p.children&&p.children.length>0,B=l.has(p.id);ei(p.type);let F=T,A=d===p.id,X=g.find(K=>K.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 ${A?"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"} ${x?"cursor-pointer":""}`,style:{marginLeft:o*u},onClick:()=>{x&&c(A?null:p.id);},children:[F?jsxRuntime.jsx("button",{type:"button",onClick:K=>{K.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:B?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:[ja(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),X?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:X.admin.description})]}),T&&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:K=>K.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{h(p.id),f(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>f(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:K=>{K.stopPropagation(),f(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"})})]}),A&&jsxRuntime.jsx(Qo,{block:p,onClose:()=>c(null)}),T&&B&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(Nd,{parentId:p.id,children:p.children,onUpdateChildren:K=>P(p.id,K),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(k)}),x&&jsxRuntime.jsxs("div",{style:{marginLeft:o*u},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($a,{open:n,onClose:()=>s(false),onSelect:y,children:b.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(T=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{y(T.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[T.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:T.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:T.admin?.description||""})]})]},T.slug))})]},p.title))})]}),t.length===0&&x&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*u},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*u},children:["Maximum nesting level (",a,") reached"]})]})},Nd=({parentId:e,children:t,onUpdateChildren:r,depth:o,maxDepth:a})=>{let[n,s]=Ca.useState(false),[l,i]=Ca.useState(new Set),[d,c]=Ca.useState(null),[m,f]=Ca.useState(null),v=Ca.useContext(xo);if(!v)throw new Error("NestedChildBlocks must be used within a BlocksContext");let b=zustand.useStore(v,p=>p.dynamicCategories),g=zustand.useStore(v,p=>p.allowedBlocks),x=o<a,u=16,y=p=>{let T=qo(p);r([...t,T]),c(T.id);},h=p=>{let T=t.filter(B=>B.id!==p);r(T);},P=(p,T)=>{let B=t.map(S=>S.id===p?{...S,children:T}:S);r(B);},w=p=>{i(T=>{let B=new Set(T);return B.has(p)?B.delete(p):B.add(p),B});},k=p=>{let T=p.children&&p.children.length>0,B=l.has(p.id);ei(p.type);let F=T,A=d===p.id,X=g.find(K=>K.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 ${A?"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"} ${x?"cursor-pointer":""}`,style:{marginLeft:o*u},onClick:()=>{x&&c(A?null:p.id);},children:[F?jsxRuntime.jsx("button",{type:"button",onClick:K=>{K.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:B?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:[ja(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),X?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:X.admin.description})]}),T&&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:K=>K.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{h(p.id),f(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>f(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:K=>{K.stopPropagation(),f(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)]"})})]}),A&&jsxRuntime.jsx(Qo,{block:p,onClose:()=>c(null)}),T&&B&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(Nd,{parentId:p.id,children:p.children,onUpdateChildren:K=>P(p.id,K),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(k)}),x&&jsxRuntime.jsxs("div",{style:{marginLeft:o*u},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($a,{open:n,onClose:()=>s(false),onSelect:y,children:b.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(T=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{y(T.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[T.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:T.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:T.admin?.description||""})]})]},T.slug))})]},p.title))})]}),t.length===0&&x&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*u},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*u},children:["Maximum nesting level (",a,") reached"]})]})};var Cd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=r?.children??e.children??[],i=(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(Ys,{heading:s.heading||"",subheading:s.subheading||"",ctaText:s.ctaText||"",ctaUrl:s.ctaUrl||"",onChange:i,compact:true}),jsxRuntime.jsx(lr,{field:{label:"Background",name:"bgImage",maxCount:1},value:s.bgImage,onChange:d=>i("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 (",l.length,")"]}),jsxRuntime.jsx(Zr,{blockId:e.id,children:l,onUpdateChildren:d=>o(e.id,{children:d})})]})]})]})};var ti=({title:e="",description:t="",icon:r="",link:o="",linkText:a="",onChange:n,compact:s=false})=>{let 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)] 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=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:`${l} font-bold text-base`,placeholder:"Card title..."}),jsxRuntime.jsx("textarea",{value:t,onChange:d=>n("description",d.target.value),className:i,placeholder:"Card description..."}),jsxRuntime.jsx("input",{type:"text",value:r,onChange:d=>n("icon",d.target.value),className:l,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 Rd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,l)=>{o(e.id,{data:{...a,[s]:l}});};return jsxRuntime.jsx(ko,{id:e.id,type:"card",label:"Card",children:jsxRuntime.jsx(ti,{title:a.title||"",description:a.description||"",icon:a.icon||"",link:a.link||"",linkText:a.linkText||"",onChange:n,compact:true})})};var Ad=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le();r?.data??e.data??{};let l=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:["(",l.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(Zr,{blockId:e.id,children:l,onUpdateChildren:i=>o(e.id,{children:i})})})]})};var Ha=({relationTo:e="pages",hasMany:t=false,selectedIds:r=[],selectedId:o,labelField:a="title",onChange:n,compact:s=false})=>{let[l,i]=Ca.useState(false),[d,c]=Ca.useState(""),[m,f]=Ca.useState([]),[v,b]=Ca.useState(false),[g,x]=Ca.useState([]),[u,y]=Ca.useState(true);Ca.useEffect(()=>{Be("/api/collections").then(S=>{x((S.collections||[]).map(F=>F.slug||F.name||F)),y(false);}).catch(()=>y(false));},[]);let h=(S="")=>{b(true);let F=`/api/${e}?${Za(S,[a],20)}`;Be(F).then(A=>{f(A.docs||[]),b(false);}).catch(()=>b(false));};Ca.useEffect(()=>{l&&h(d);},[l,d,e,a]);let R=S=>S?.[a]||S?.title||S?.name||S?.label||S?.filename||S?.slug||S?.id||"Untitled",P=t?r:o?[o]:[],w=S=>{t?P.includes(S.id)?n("selectedIds",P.filter(F=>F!==S.id)):n("selectedIds",[...P,S.id]):(n("selectedId",S.id),n("selectedIds",[S.id]),i(false));},k=S=>P.includes(S),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",T=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",B=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:[!B&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:u?jsxRuntime.jsx("div",{className:T+" text-[var(--kyro-text-muted)]",children:"Loading..."}):jsxRuntime.jsxs("select",{value:e,onChange:S=>n("relationTo",S.target.value),className:T,children:[jsxRuntime.jsx("option",{value:"",children:"Select collection..."}),g.map(S=>jsxRuntime.jsx("option",{value:S,children:S},S))]})}),!s&&jsxRuntime.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:t,onChange:S=>n("hasMany",S.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:S=>{c(S.target.value),i(true);},onFocus:()=>i(true),onBlur:()=>setTimeout(()=>i(false),200),placeholder:`Search ${e}...`,className:`${p} pl-9`}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:v&&jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"})})]}),l&&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:v?jsxRuntime.jsx("div",{className:"p-3 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):m.length===0?jsxRuntime.jsx(On,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:m.map(S=>jsxRuntime.jsxs("button",{type:"button",onMouseDown:F=>F.preventDefault(),onClick:()=>w(S),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors flex items-center justify-between ${k(S.id)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("span",{children:R(S)}),k(S.id)&&jsxRuntime.jsx("span",{children:"\u2713"})]},S.id))})})]}),P.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5",children:P.map(S=>{let F=m.find(A=>A.id===S)||{id:S};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:[R(F),jsxRuntime.jsx("button",{type:"button",onMouseDown:A=>A.preventDefault(),onClick:()=>{t?n("selectedIds",P.filter(A=>A!==S)):(n("selectedId",null),n("selectedIds",[]));},className:"hover:opacity-70",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},S)})})]})};var Dd=({block:e,index:t})=>{let r=je(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(Ha,{relationTo:s.relationTo||"pages",hasMany:s.hasMany||false,selectedIds:Array.isArray(s.selectedIds)?s.selectedIds:[],selectedId:s.selectedId,labelField:s.labelField||"title",onChange:l,compact:true})]})};var gu={heading:ad,paragraph:sd,image:id,video:dd,list:cd,code:pd,file:md,accordion:ud,richtext:yd,hero:Cd,card:Rd,array:Ad,relationship:Dd},Pe={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"}},zt={heading:jsxRuntime.jsx(lucideReact.Heading1,{className:`w-4 h-4 ${Pe.default.text}`}),paragraph:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Pe.default.text}`}),image:jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Pe.default.text}`}),video:jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Pe.default.text}`}),list:jsxRuntime.jsx(lucideReact.List,{className:`w-4 h-4 ${Pe.default.text}`}),code:jsxRuntime.jsx(lucideReact.Code,{className:`w-4 h-4 ${Pe.default.text}`}),file:jsxRuntime.jsx(lucideReact.File,{className:`w-4 h-4 ${Pe.default.text}`}),accordion:jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-4 h-4 ${Pe.default.text}`}),richtext:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Pe.default.text}`}),hero:jsxRuntime.jsx(lucideReact.Star,{className:`w-4 h-4 ${Pe.hero.text}`}),card:jsxRuntime.jsx(lucideReact.Box,{className:`w-4 h-4 ${Pe.card.text}`}),array:jsxRuntime.jsx(lucideReact.ListOrdered,{className:`w-4 h-4 ${Pe.default.text}`}),relationship:jsxRuntime.jsx(lucideReact.Link2,{className:`w-4 h-4 ${Pe.default.text}`}),featureSplit:jsxRuntime.jsx(lucideReact.Columns3,{className:`w-4 h-4 ${Pe.featureSplit.text}`}),featureGrid:jsxRuntime.jsx(lucideReact.Blocks,{className:`w-4 h-4 ${Pe.featureGrid.text}`}),ctaBanner:jsxRuntime.jsx(lucideReact.Sparkles,{className:`w-4 h-4 ${Pe.ctaBanner.text}`}),testimonials:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Pe.testimonials.text}`}),faq:jsxRuntime.jsx(lucideReact.CircleHelp,{className:`w-4 h-4 ${Pe.faq.text}`}),stats:jsxRuntime.jsx(lucideReact.Activity,{className:`w-4 h-4 ${Pe.stats.text}`}),logoCloud:jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Pe.logoCloud.text}`}),pricing:jsxRuntime.jsx(lucideReact.Tag,{className:`w-4 h-4 ${Pe.pricing.text}`}),team:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Pe.team.text}`}),recentFeed:jsxRuntime.jsx(lucideReact.Database,{className:`w-4 h-4 ${Pe.recentFeed.text}`}),processSteps:jsxRuntime.jsx(lucideReact.Clock,{className:`w-4 h-4 ${Pe.processSteps.text}`}),formEmbed:jsxRuntime.jsx(lucideReact.Mail,{className:`w-4 h-4 ${Pe.formEmbed.text}`}),videoShowcase:jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Pe.videoShowcase.text}`})};function ei(e){return gu[e]||null}function ri(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 ja(e){let t=e.name;return t&&t.trim()?t.trim():ri(e.type)}function Pu(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 Iu=({block:e,index:t,blockSchema:r,editingBlockId:o,setEditingBlockId:a,onDuplicate:n,compact:s})=>{let{attributes:l,listeners:i,setNodeRef:d,transform:c,transition:m,isDragging:f}=sortable.useSortable({id:e.id}),{removeBlock:v,updateBlock:b}=Le(),g=o===e.id,[x,u]=Ca.useState(false),[y,h]=Ca.useState(false),[R,P]=Ca.useState(e.name||""),w=Ca.useRef(null);Ca.useEffect(()=>{y&&w.current&&(w.current.focus(),w.current.select());},[y]);let k=Ca.useCallback(()=>{h(false);let F=R.trim();F!==(e.name||"").trim()&&b(e.id,{name:F||""});},[R,e.name,e.id,b]),p={transform:utilities.CSS.Transform.toString(c),transition:m,zIndex:f?10:1,opacity:f?.8:1},T=ja(e),B=e.data||{},S=Pu(B,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 ${g?`${(Pe[e.type]||Pe.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 touch-none",...l,...i,onClick:F=>F.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]}),y?jsxRuntime.jsx("input",{ref:w,value:R,onChange:F=>P(F.target.value),onBlur:k,onKeyDown:F=>{F.key==="Enter"&&k(),F.key==="Escape"&&(P(e.name||""),h(false));},onClick:F=>F.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",{className:"font-medium text-[var(--kyro-text-secondary)] truncate max-w-[120px] transition-colors",children:T}),x?jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5",onClick:F=>F.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{v(e.id),u(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:()=>u(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:F=>{F.stopPropagation(),P(e.name||""),h(true);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Rename",children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",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:F=>{F.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:F=>{F.stopPropagation(),u(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"})})]})]}),g&&jsxRuntime.jsx(Qo,{block:e,blockSchema:r,onClose:()=>a(null)})]}):jsxRuntime.jsxs("div",{ref:d,style:p,className:"relative group mb-2",children:[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 ${g?`${(Pe[e.type]||Pe.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:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-surface-accent)] rounded flex-shrink-0 touch-none",...l,...i,onClick:F=>F.stopPropagation(),children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-4 h-4"})}),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:[y?jsxRuntime.jsx("input",{ref:w,value:R,onChange:F=>P(F.target.value),onBlur:k,onKeyDown:F=>{F.key==="Enter"&&k(),F.key==="Escape"&&(P(e.name||""),h(false));},onClick:F=>F.stopPropagation(),placeholder:ri(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",{className:"text-xs font-semibold text-[var(--kyro-text-secondary)] truncate transition-colors",children:[T,S&&typeof S=="string"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-text-muted)] font-normal ml-1.5",children:["- ",S.length>40?`${S.slice(0,40)}...`:S]})]}),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"]}),x?jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",onClick:F=>F.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{v(e.id),u(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:()=>u(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:F=>{F.stopPropagation(),P(e.name||""),h(true);},className:"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:F=>{F.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:F=>{F.stopPropagation(),u(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"})})]})]}),g&&jsxRuntime.jsx(Qo,{block:e,blockSchema:r,onClose:()=>a(null)})]})},Bu=Ca__default.default.memo(Iu),Zs=({field:e,value:t,onChange:r,onBlocksChange:o,error:a,disabled:n,documentStatus:s,justSaved:l})=>{let[i,d]=Ca.useState(false),[c,m]=Ca.useState(false),f=Ca.useRef(null),v=e.admin?.pickerMode||"drawer",b=e.blocks||[],g=b.reduce((L,O)=>{let pe=O.admin?.group||"Custom Blocks";return L[pe]||(L[pe]=[]),L[pe].push(O),L},{}),x=["Structural Sections","Marketing Grids","Lead Capture & Interactive","Dynamic Content","Basic Content Elements","Custom Blocks"],u=Object.entries(g).sort(([L],[O])=>{let pe=x.indexOf(L),ge=x.indexOf(O);return pe!==-1&&ge!==-1?pe-ge:pe!==-1?-1:ge!==-1?1:L.localeCompare(O)}).map(([L,O])=>({title:L,blocks:O})),y=Ca.useRef(null);y.current||(y.current=ed(b,u));let h=y.current,R=zustand.useStore(h,L=>L.blocks),[P,w]=Ca.useState(null),[k,p]=Ca.useState(null),T=Ca.useRef(R.length),B=Ca.useRef(new Set(R.map(L=>L.id))),S=Ca.useRef(false);Ca.useEffect(()=>{if(S.current&&R.length>T.current){let L=R.find(O=>O.id&&!B.current.has(O.id));L&&p(L.id);}T.current=R.length,B.current=new Set(R.map(L=>L.id));},[R]),Ca.useEffect(()=>(o&&h.getState().setOnBlocksChange(o),()=>{h.getState().setOnBlocksChange(()=>{});}),[o,h]);let F=Ca.useRef(null);Ca.useEffect(()=>{let L=Array.isArray(t)?t:[],O=F.current||[];if(JSON.stringify(L)!==JSON.stringify(O)){let pe=[...L];T.current=pe.length,B.current=new Set(pe.map(ge=>ge.id)),h.getState().setBlocks(pe),F.current=pe,S.current=true;}else L.length===0&&!S.current&&(S.current=true,F.current=[]);},[t,e.name,h]);let A=Ca.useRef(r);A.current=r,Ca.useEffect(()=>{if(!A.current)return;let L=F.current;L&&JSON.stringify(R)!==JSON.stringify(L)&&(F.current=[...R],A.current(R));},[R]);let K=Ca.useCallback(L=>{h.getState().addBlock(L);},[h]),$=Ca.useCallback(L=>{let O=R.findIndex(U=>U.id===L);if(O===-1)return;let pe=R[O],ge=U=>{let Y=Math.random().toString(36).substr(2,9);return {...U,id:Y,children:U.children?U.children.map(le=>ge(le)):U.children,data:U.data?JSON.parse(JSON.stringify(U.data)):U.data}},Se=ge(pe),Ne=[...R];Ne.splice(O+1,0,Se),h.getState().setBlocks(Ne);},[R,h]),j=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}}),core.useSensor(core.TouchSensor,{activationConstraint:{delay:250,tolerance:5}}),core.useSensor(core.KeyboardSensor)),ae=L=>{w(L.active);},ne=L=>{let{active:O,over:pe}=L;if(w(null),!!pe){if(O.id.toString().startsWith("drawer-")){let ge=O.id.toString().replace("drawer-","");if(pe.id.toString().startsWith("container-")){let Se=pe.id.toString().replace("container-",""),Ne=R.find(U=>U.id===Se);if(Ne){let U=qo(ge);h.getState().updateBlock(Se,{children:[...Ne.children||[],U]});}}else {let Se=R.findIndex(Ne=>Ne.id===pe.id);Se!==-1?h.getState().addBlock(ge,Se):K(ge);}return}if(O.id!==pe.id){let ge=R.findIndex(Ne=>Ne.id===O.id),Se=R.findIndex(Ne=>Ne.id===pe.id);if(ge!==-1&&Se!==-1){let Ne=[...R],[U]=Ne.splice(ge,1);Ne.splice(Se,0,U),h.getState().setBlocks(Ne);}}}},H=P?u.flatMap(L=>L.blocks).find(L=>`drawer-${L.type}`===P.id)||R.find(L=>L.id===P.id):null;H?"label"in H?H.label:H.type:"Block";return Ca.useEffect(()=>{if(!c)return;let L=O=>{f.current&&!f.current.contains(O.target)&&m(false);};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[c]),jsxRuntime.jsx(xo.Provider,{value:y.current,children:jsxRuntime.jsxs("div",{className:"kyro-blocks-field",children:[jsxRuntime.jsxs(core.DndContext,{sensors:j,collisionDetection:core.closestCenter,onDragStart:ae,onDragEnd:ne,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}),v==="dropdown"?jsxRuntime.jsxs("div",{ref:f,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:u.map(L=>jsxRuntime.jsxs("div",{children:[u.length>1&&jsxRuntime.jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold tracking-wider text-[var(--kyro-text-muted)] uppercase",children:L.title}),L.blocks.map(O=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{K(O.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[O.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:O.label}),O.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] truncate",children:O.admin.description})]})]},O.slug))]},L.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($a,{open:i,onClose:()=>d(false),onSelect:K,children:jsxRuntime.jsx("div",{className:"space-y-4",children:u.map(L=>jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] mb-2 tracking-wider",children:L.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:L.blocks.map(O=>jsxRuntime.jsx(td,{block:{type:O.slug,label:O.label,description:O.admin?.description||"",icon:null},onSelect:K,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[O.slug]||jsxRuntime.jsx(lucideReact.Box,{className:"w-4 h-4"})})})},O.slug))})]},L.title))})})}),jsxRuntime.jsx(sortable.SortableContext,{items:R.map(L=>L.id),strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsxs("div",{className:v==="dropdown"?"flex flex-wrap gap-1.5":"space-y-4",children:[R.map((L,O)=>{let pe=e.blocks?.find(ge=>ge.slug===L.type);return jsxRuntime.jsx(Bu,{block:L,index:O,blockSchema:pe,editingBlockId:k,setEditingBlockId:p,onDuplicate:$,compact:v==="dropdown"},L.id||O)}),R.length===0&&jsxRuntime.jsx("div",{className:v==="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:v==="dropdown"?"No elements added":"Click the button above to add your first block"})]})}),jsxRuntime.jsx(core.DragOverlay,{children:P&&H&&jsxRuntime.jsx("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-primary)] rounded-md p-3 shadow-lg",children:H.label||H.type||"Block"})})]}),a&&jsxRuntime.jsx("p",{className:"kyro-form-error",children:a})]})})};function Sr(e){if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(Sr);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<=25)return t.id;let n={};for(let s of r)n[s]=Sr(t[s]);return n}return e}function Id(){let e=Ca.useRef([]),t=Ca.useRef(false);return {queueTask:Ca.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(l){console.error("Error in queued function:",l);}finally{t.current=false,typeof a?.afterProcess=="function"&&a.afterProcess();}}}n();},[])}}function Bd({config:e,initialData:t,collectionSlug:r,globalSlug:o,documentId:a,onChange:n,onActionSuccess:s,onActionError:l}){let i=$e(),{confirm:d}=dt(),{formData:c,setFormData:m,setField:f,lastSavedData:v,setLastSavedData:b,setHasUnsavedChanges:g,isSlugLocked:x,loadDocument:u,setIsAutoSaving:y,setAutoSaveStatus:h,setVersions:R,setLoadingVersions:P,sidebarCollapsed:w,setSidebarCollapsed:k,getDraftCache:p,setDraftCache:T,clearDraftCache:B,resetForm:S}=i,F=!!e.versions,A=o||t?.id||a||r,X=Ca.useRef(false);!o&&A&&c&&Object.keys(c).length>0&&c.id!==A&&(X.current=true),Ca.useEffect(()=>{X.current&&(X.current=false,S());},[S]);let K=Ca.useRef(null),$=Ca.useRef(null),j=Ca.useRef(null),ae=Ca.useRef(typeof navigator<"u"?navigator.onLine:true),ne=Ca.useRef(0),H=Ca.useRef(false),re=Ca.useRef(null),ve=Ca.useRef(""),L=Ca.useRef(""),{queueTask:O}=Id(),pe=Ca.useCallback(Q=>o?`global:${o}`:r&&Q?`${r}:${Q}`:null,[r,o]),ge=Ca.useCallback((Q,te,ce)=>{T(Q,{data:te,baseUpdatedAt:v.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:ce?.lastSyncedAt??null});},[v.updatedAt,T]),Se=Ca.useCallback(async()=>{let Q=o?tt(`/api/globals/${o}/versions`):r&&c.id?tt(`/api/${r}/${c.id}/versions`):null;if(Q){P(true);try{let ce=await(await at(Q)).json();R(ce.docs||[]);}catch(te){console.error("Failed to fetch versions:",te);}finally{P(false);}}},[c.id,r,o,P,R]),Ne=Ca.useCallback(()=>{let Q=$e.getState(),te=Q.formData;if(H.current||!r||!te.id||!Q.hasDirtyFields())return;let ce=pe(te.id);ce&&ge(ce,te);},[r,pe,ge]),U=Ca.useCallback(async Q=>{let te=$e.getState(),ce=te.formData,Te=te.lastSavedData;if(H.current||!F&&o||!o&&(!r||!ce.id)||!te.hasDirtyFields())return;let Fe=pe(ce.id);if(Fe&&ge(Fe,ce),!ae.current){h("offline");return}y(true),h("saving"),te.setBackgroundProcessing(true);try{let lt=o?tt(`/api/globals/${o}?autosave=true`):tt(`/api/${r}/${ce.id}?autosave=true`),Tt=await at(lt,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":"true"},keepalive:Q?.keepalive,body:JSON.stringify({...Sr(ce),baseUpdatedAt:Te.updatedAt??null})});if(Tt.ok)ne.current=Date.now(),te.setRetryCount(0),te.setLastSavedAt(Date.now()),j.current&&clearTimeout(j.current),Fe&&T(Fe,{data:ce,baseUpdatedAt:Te.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:(await Tt.clone().json()).data?.updatedAt||new Date().toISOString()}),h("success"),setTimeout(()=>{$e.getState().autoSaveStatus==="success"&&h("idle");},2e3);else if(Tt.status===409)h("conflict");else throw new Error(`Draft auto-save failed with status ${Tt.status}`)}catch(lt){console.error("Auto-save failed:",lt);let Tt=$e.getState(),I=Tt.retryCount;if(I<5){Tt.setRetryCount(I+1),h("retrying");let W=Math.min(1e3*Math.pow(2,I),6e4);j.current&&clearTimeout(j.current),j.current=setTimeout(()=>Y(Q),W);}else h("offline");}finally{y(false),$e.getState().setBackgroundProcessing(false);}},[r,pe,o,ge,h,T,y,F]),Y=Ca.useCallback(Q=>{O(()=>U(Q),{beforeProcess:()=>true,afterProcess:()=>{}});},[U,O]),le=Ca.useCallback(async(Q,te=true)=>{let ce=$e.getState(),Te=Q||ce.formData,Fe=o?tt(`/api/globals/${o}`):tt(`/api/${r}/${Te.id}`),lt=await at(Fe,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":String(te)},body:JSON.stringify({...Sr(Te),baseUpdatedAt:ce.lastSavedData.updatedAt??null})});return lt.status===409&&h("conflict"),lt},[r,o,h]);Ca.useEffect(()=>{let Q=()=>{k(!w);};return window.addEventListener("toggle-sidebar",Q),()=>window.removeEventListener("toggle-sidebar",Q)},[w,k]);let Re=Ca.useRef(null),Ue=Ca.useRef(""),Ie=Ca.useRef(false);Ca.useEffect(()=>{let Q=o||t?.id,te=JSON.stringify(t);Ie.current&&Re.current===Q&&Ue.current===te||(u(t||{},t||{}),Ie.current=true,Re.current=Q,Ue.current=te);},[r,c.id,o,t,u]),Ca.useEffect(()=>{if(!r||!t?.id)return;let Q=pe(t.id);if(!Q||re.current===Q)return;let te=false;return (async()=>{if(!F)return;let Te=p(Q);if(Te){if(JSON.stringify(Te.data)===JSON.stringify(t)){B(Q);return}re.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(te)return;let lt={...$e.getState().formData,...Te.data};m(lt),s?.("Recovered autosaved draft");},onCancel:async()=>{B(Q);}});}})(),()=>{te=true;}},[B,r,d,pe,p,t,s,m,F]);function et(Q,te){for(let ce of Q){if(ce.name===te&&ce.admin?.autoGenerate==="title")return ce;if(ce.type==="tabs"&&"tabs"in ce)for(let Te of ce.tabs){let Fe=et(Te.fields,te);if(Fe)return Fe}if((ce.type==="group"||ce.type==="collapsible")&&"fields"in ce){let Te=et(ce.fields,te);if(Te)return Te}}}Ca.useEffect(()=>{let Q=e.fields;if(!et(Q,"metaTitle"))return;let ce=go(Q,c,"title"),Te=ce?String(ce):"";Te&&(!c.metaTitle||c.metaTitle===c._lastMetaTitle)&&f("metaTitle",Te);},[c,e.fields,f]),Ca.useEffect(()=>{let Q=e.fields,te=Q.find(Fe=>Fe.name==="slug"&&Fe.admin?.autoGenerate);if(!te?.admin?.autoGenerate)return;let ce=te.admin.autoGenerate,Te=go(Q,c,ce);if(x&&Te){let Fe=Dn(Te);Fe!==c.slug&&f("slug",Fe);}},[c,x,e.fields,f]),Ca.useEffect(()=>{if(w||!o&&(!r||!c.id)||!$e.getState().hasDirtyFields()||kd()!=="keystroke")return;Hn("other");let te=JSON.stringify(c);te!==ve.current&&(K.current&&clearTimeout(K.current),K.current=setTimeout(Ne,1500),$.current&&clearTimeout($.current),$.current=setTimeout(()=>{ve.current=te,Y();},8e3));},[c,w,r,o,Ne,Y]),Ca.useEffect(()=>{if(!o&&(!r||!c.id))return;let Q=()=>{H.current||!$e.getState().hasDirtyFields()||Y({keepalive:true});},te=()=>{document.hidden&&Q();},ce=()=>{ae.current=true,Q();},Te=()=>{ae.current=false;let Fe=$e.getState();Fe.hasDirtyFields()&&Fe.setAutoSaveStatus("offline");};return window.addEventListener("blur",Q),window.addEventListener("pagehide",Q),window.addEventListener("online",ce),window.addEventListener("offline",Te),document.addEventListener("visibilitychange",te),()=>{window.removeEventListener("blur",Q),window.removeEventListener("pagehide",Q),window.removeEventListener("online",ce),window.removeEventListener("offline",Te),document.removeEventListener("visibilitychange",te);}},[r,o,c.id,Y]),Ca.useEffect(()=>{let Q=JSON.stringify(c);if(Q===L.current)return;L.current=Q;let te=document.getElementById("form-data");te&&(te.value=Q),n?.(c);},[c,n]),Ca.useEffect(()=>{(o||c.id)&&Se();},[c.id,o,Se]);let Ct=!c.id&&!o?"draft":F&&c.status||"published",St=(!!c.id||!!o)&&Ct==="draft";return {...i,fetchVersions:Se,performAutoSave:Y,saveDocument:le,autoSaveSkipRef:H,lastAutoSaveTimeRef:ne,documentStatus:Ct,hasUnpublishedChanges:St,versionsEnabled:F}}function So({trigger:e,children:t,align:r="right",direction:o="up"}){let[a,n]=Ca.useState(false),s=Ca.useRef(null);return Ca.useEffect(()=>{let l=i=>{s.current&&!s.current.contains(i.target)&&n(false);};return a&&document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[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 Ka(){return jsxRuntime.jsx("div",{className:"my-1 border-t border-[var(--kyro-border)] opacity-50"})}function Ro({status:e,saveStatus:t,hasChanges:r,onPublish:o,children:a,disabled:n,direction:s="down"}){let l=e==="published"&&!r&&t!=="saving"&&t!=="error",i=n||t==="saving"||l,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)]`:l?`${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",f=()=>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)]`:l?`${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)]`,v=()=>t==="saving"?"Publishing...":t==="saved"?"Published \u2713":t==="error"?"Retry":l?"Published":"Publish Changes";return jsxRuntime.jsxs("div",{className:"inline-flex items-center",children:[jsxRuntime.jsxs("button",{type:"button",onClick:o,disabled:i,className:`${c()} ${a?"":"rounded-r-lg border-r border-[var(--kyro-border)]"}`,children:[t==="saving"&&jsxRuntime.jsx(kr,{size:"sm",className:"inline mr-1.5"}),l&&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"})}),v()]}),a&&jsxRuntime.jsx(So,{trigger:jsxRuntime.jsx("button",{type:"button",className:f(),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 Ed=({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 Od({field:e,formData:t,onTabDataChange:r,renderField:o}){let[a,n]=Ca.useState(0),s=e.tabs||[],l=s[a]||s[0],i=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:l?.fields.map(d=>o(d,i,r))}),l?.label==="SEO Settings"&&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(Ed,{title:String((typeof i.metaTitle=="object"?"":i.metaTitle)||(typeof i.title=="object"?"":i.title)||"Untitled"),description:String((typeof i.metaDescription=="object"?"":i.metaDescription)||"Please enter a description..."),slug:String((typeof t.slug=="object"?"":t.slug)||"your-slug")})]})]})}function jd({collectionSlug:e,globalSlug:t,documentStatus:r,hasUnpublishedChanges:o,localSaveStatus:a,isDuplicating:n,handleCreateNew:s,handleDuplicate:l,handleUnpublish:i,handleDelete:d,handlePublish:c,handleSchedulePublish:m}){let[f,v]=Ca.useState(Date.now()),[b,g]=Ca.useState(false),x=Ca.useRef(null),{formData:u,hasUnsavedChanges:y,autoSaveStatus:h,lastSavedAt:R,retryCount:P,view:w,setView:k,showPreview:p,setShowPreview:T,setFormData:B,markSaved:S,lastSavedData:F}=$e(),A=!u.id;Ca.useEffect(()=>{let O=setInterval(()=>v(Date.now()),1e4);return ()=>clearInterval(O)},[]),Ca.useEffect(()=>{let O=pe=>{x.current&&!x.current.contains(pe.target)&&g(false);};if(b)return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[b]);let X=String(u.mainTabs?.title||(typeof u.title=="object"?"":u.title)||(typeof u.name=="object"?"":u.name)||"Untitled"),K=u.updatedAt?new Date(u.updatedAt).toLocaleString():"Just now",$=u.createdAt?new Date(u.createdAt).toLocaleString():"Just now",j=o?"Draft (unpublished changes)":r==="published"?"Published":"Draft",ae=o?"Unpublished":r==="published"?"Published":"Draft",ne=r==="published"&&!y?"bg-[var(--kyro-success)]":o?"bg-[var(--kyro-warning)]":"bg-[var(--kyro-text-muted)]",H=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",re=(O=false)=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[h==="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"})]}),O?"Saving\u2026":"Saving draft..."]}),h==="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"}),O?"Saved":R?`Saved ${Math.floor((Date.now()-R)/6e4)}m ago`:"Draft saved"]}),h==="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"})]}),O?`Retry ${P}/5`:`Retrying save (${P}/5)`]}),h==="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"})]}),O?"Offline":"Offline \u2014 cached locally"]}),h==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:O?"Failed":"Draft save failed"}),h==="conflict"&&(O?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"})]}))]}),ve=()=>!A&&jsxRuntime.jsxs(So,{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:s,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:l,disabled:n,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:n?"Duplicating...":"Duplicate"}),jsxRuntime.jsx(jt,{onClick:()=>g(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(Ka,{}),jsxRuntime.jsx(jt,{onClick:d,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"})]})]}),L=()=>b&&jsxRuntime.jsx("div",{ref:x,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:()=>g(false),className:"px-3 py-1.5 text-xs kyro-btn rounded-lg",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{let O=document.getElementById("schedule-datetime")?.value;O&&m(O);},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:`${Ge}/${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:X}),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 ${H}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ne}`}),ae]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[jsxRuntime.jsx(Ro,{status:r,saveStatus:a,hasChanges:y,onPublish:c,disabled:a==="saving"}),ve(),L()]})]}),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(O=>jsxRuntime.jsx("button",{type:"button",onClick:()=>k(O),className:`px-3 py-1 text-[10px] font-bold rounded-md transition-all ${w===O?"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:O==="edit"?"Edit":O==="version"?"History":"API"},O))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-medium",children:[re(true),y&&h!=="saving"&&h!=="retrying"&&h!=="conflict"&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{B(F),S();},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:()=>T(!p),className:`p-1.5 rounded-lg transition-all ${p?"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)] z-50 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:`${Ge}/${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:X}),jsxRuntime.jsxs("span",{className:`shrink-0 inline-flex items-center gap-1.5 px-2 rounded-full text-[10px] font-regular border ${H}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ne}`}),j]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 text-[11px] font-medium tracking-wide opacity-60 ml-12",children:[re(false),y&&h!=="saving"&&h!=="retrying"&&h!=="conflict"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"opacity-30",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{B(F),S();},className:"text-[var(--kyro-primary)] hover:underline",children:"Revert changes"})]}),R&&h!=="saving"&&h!=="retrying"&&h!=="success"&&jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Draft saved ",(()=>{let O=f-R,pe=Math.floor(O/6e4),ge=Math.floor(O/1e3);return pe>=1?`${pe}m ago`:ge>=5?`${ge}s ago`:"just now"})()]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Modified ",K]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Created ",$]})]})]}),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(O=>jsxRuntime.jsx("button",{type:"button",onClick:()=>k(O),className:`px-5 py-2 text-xs font-bold rounded-lg transition-all ${w===O?"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:O.toUpperCase()},O))}),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:()=>T(!p),className:`kyro-btn p-2.5 rounded-xl transition-all flex items-center gap-2 ${p?"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"}),p&&jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest pr-1",children:"Active"})]}),ve(),L(),jsxRuntime.jsx(Ro,{status:r,saveStatus:a,hasChanges:y,onPublish:c,disabled:a==="saving"})]})]})]})]})}function _d({config:e,layout:t,collectionSlug:r,renderField:o}){let{showPreview:a,sidebarCollapsed:n,formData:s}=$e();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 i=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||!i?"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 Hd({handleRestoreVersion:e,handleCompareVersions:t,toggleCompareSelection:r}){let{compareMode:o,setCompareMode:a,compareSelected:n,setCompareSelected:s,compareDiffs:l,setCompareDiffs:i,loadingDiffs:d,loadingVersions:c,versions:m}=$e();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([]),i([]);},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"})]})]}),l.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:[l.length," change",l.length!==1?"s":""]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>i([]),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:l.map((f,v)=>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:f.field}),jsxRuntime.jsx("div",{className:"text-[var(--kyro-text-muted)] truncate hidden md:block",children:typeof f.oldValue=="object"?JSON.stringify(f.oldValue):String(f.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 f.newValue=="object"?JSON.stringify(f.newValue):String(f.newValue??"null")]})]},v))})]}),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((f,v)=>{let b=n.includes(f.id),g=(f.changeDescription||"").toLowerCase().includes("auto");return jsxRuntime.jsxs("div",{onClick:o?()=>r(f.id):void 0,className:`transition-all ${o?b?"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 ${b?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:b&&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-v})}),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:[f.changeDescription||"Snapshot",g&&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(f.createdAt||f.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),jsxRuntime.jsx("div",{className:"col-span-3",children:f.status&&jsxRuntime.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold capitalize tracking-wider ${f.status==="published"?" text-[var(--kyro-success)]":" text-[var(--kyro-warning)]"}`,children:[jsxRuntime.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${f.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),f.status]})}),jsxRuntime.jsx("div",{className:"col-span-2 text-[11px] text-[var(--kyro-text-muted)]",children:f.createdBy||"system"}),jsxRuntime.jsx("div",{className:"col-span-2 flex justify-end",children:!o&&jsxRuntime.jsx("button",{type:"button",onClick:()=>e(f.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 ${b?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:b&&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-v})}),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:[f.changeDescription||"Snapshot",g&&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(f.createdAt||f.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}),f.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 ${f.status==="published"?"text-[var(--kyro-success)]":"text-[var(--kyro-warning)]"}`,children:[jsxRuntime.jsx("span",{className:`w-1 h-1 rounded-full ${f.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),f.status]}),jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-muted)] opacity-60",children:f.createdBy||"system"})]})]}),!o&&jsxRuntime.jsx("button",{type:"button",onClick:()=>e(f.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"})]})]},f.id)})})]})})}function Vd({collectionSlug:e,globalSlug:t}){let{formData:r}=$e();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 Kd={};function Wa({config:e,data:t=Kd,errors:r=Kd,onChange:o,disabled:a,collectionSlug:n,globalSlug:s,documentId:l,documentName:i,layout:d="split",onActionSuccess:c,onActionError:m,justSaved:f}){let v=e||(s?Ql[s]:n?Wo[n]:null),[b,g]=Ca.useState(v);Ca.useEffect(()=>{s==="storage-settings"?Be("/api/kyro/schema").then(D=>{D?.globals?.["storage-settings"]&&g(D.globals["storage-settings"]);}).catch(D=>console.error("[AutoForm] Failed to fetch dynamic schema",D)):g(v);},[s,v]);let x=b||v,{confirm:u}=dt(),{formData:y,hasUnsavedChanges:R,autoSaveStatus:k,lastSavedAt:p,view:$,setView:j,setShowPreview:L,isMenuOpen:O,setIsMenuOpen:pe,loadingFields:ge,setLoadingFields:Se,compareSelected:Y,setCompareSelected:le,setCompareDiffs:Ue,setLoadingDiffs:et,setField:Ct,setFormData:St,setLastSavedData:te,setAutoSaveStatus:ce,fetchVersions:Te,saveDocument:Fe,autoSaveSkipRef:lt,lastAutoSaveTimeRef:Tt,documentStatus:I,hasUnpublishedChanges:W,versionsEnabled:ie}=Bd({config:x,initialData:t,collectionSlug:n,globalSlug:s,documentId:l,onChange:o,onActionSuccess:c,onActionError:m}),sr=Ca.useRef(null),po=Ca.useRef(null),[ya,qa]=Ca.useState(false),[rs,C]=Ca.useState("idle"),[me,De]=Ca.useState(false),[qt,Rt]=Ca.useState(Date.now()),fr=a,[os,Po]=Ca.useState(false),[Ec,as]=Ca.useState(false),[$c,Oc]=Ca.useState(0),yi=Ca.useRef(new Map),Uc=3e4;Ca.useEffect(()=>{let D=s?`global:${s}`:`${n}:${l}`;if(!(s||n&&l&&l!=="new")||t&&Object.keys(t).length>0)return;let be=yi.current.get(D),Ee=be&&Date.now()-be.ts<Uc,At=be&&!Ee;if(Ee){$e.getState().loadDocument(be.data,be.data);return}At&&$e.getState().loadDocument(be.data,be.data);let Ht=new AbortController;as(false),be||Po(true);let Ar=s?`/api/globals/${s}`:`/api/${n}/${l}`;return Be(Ar,{autoToast:false,signal:Ht.signal}).then(ut=>{let mo=ut.data||{};yi.current.set(D,{data:mo,ts:Date.now()}),$e.getState().loadDocument(mo,mo),Po(false);}).catch(ut=>{ut.name!=="AbortError"&&(Po(false),be||as(true));}),()=>Ht.abort()},[n,l,s,t,$c]),Ca.useEffect(()=>{let D=setInterval(()=>Rt(Date.now()),1e4);return ()=>clearInterval(D)},[]);let fi=(D,J)=>{if(typeof D=="function")try{return D(y,J)}catch(be){return console.warn("Error evaluating admin runtime flag:",be),false}return !!D},zc=D=>{u({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?tt(`/api/globals/${s}/versions/${D}/restore`):tt(`/api/${n}/${y.id}/versions/${D}/restore`),be=await at(J,{method:"POST"});!be.ok&&n&&(be=await at(tt(`/api/${n}/${y.id}/versions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({versionId:D,action:"restore"})}));let Ee=await be.json();if(Ee.data){let{updatedAt:At,createdAt:Ht,...Ar}=Ee.data,ut={...y,...Ar};St(ut),$e.getState().loadDocument(ut,ut),c?.("Version restored successfully"),Te(),j("edit");}else M.error(Ee.error||"Failed to restore version");}catch(J){console.error("Failed to restore version:",J),M.error("Failed to restore version");}}});},jc=async()=>{if(Y.length===2){et(true);try{let J=await(await at(tt(`/api/${n}/${y.id}/versions?compareA=${Y[0]}&compareB=${Y[1]}`))).json();Ue(J.diffs||[]);}catch(D){console.error("Compare failed:",D),Ue([]);}finally{et(false);}}},_c=D=>{le(J=>J.includes(D)?J.filter(be=>be!==D):J.length>=2?[J[1],D]:[...J,D]);};Ca.useEffect(()=>{let D=J=>{(J.metaKey||J.ctrlKey)&&J.key==="s"&&(J.preventDefault(),ns()),(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(),L(be=>!be)),document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA"&&(J.key==="1"&&j("edit"),J.key==="2"&&j("version"),J.key==="3"&&j("api"));};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[]),Ca.useEffect(()=>{let D=()=>j("version");return window.addEventListener("kyro:show-version-history",D),()=>window.removeEventListener("kyro:show-version-history",D)},[]),Ca.useEffect(()=>{let D=J=>{sr.current&&!sr.current.contains(J.target)&&pe(false);};if(O)return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[O]),Ca.useEffect(()=>{let D=J=>{po.current&&!po.current.contains(J.target)&&qa(false);};if(ya)return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[ya]);let Hc=()=>{R?u({title:"Unsaved Changes",message:"You have unsaved changes. Save before creating new?",onConfirm:async()=>{await ns(),await new Promise(D=>setTimeout(D,1e3)),window.location.href=`${Ge}/${n}/new`;}}):window.location.href=`${Ge}/${n}/new`;},Vc=()=>{if(!y.id){M.error("Please save the document before duplicating.");return}let D=async()=>{try{De(!0);let J=await at(`/api/${n}/${y.id}/duplicate`,{method:"POST"});if(J.ok){let be=await J.json();c?.("Document duplicated successfully"),be.data?.id?window.location.href=`${Ge}/${n}/${be.data.id}`:window.location.href=`${Ge}/${n}`;}else {let be=await J.json();M.error(be.error||"Failed to duplicate");}}catch{M.error("Failed to duplicate document");}finally{De(false);}};if(R){u({title:"Unsaved Changes",message:"You have unsaved changes. Please save the document before duplicating.",onConfirm:async()=>{await ns(),await D();}});return}u({title:"Duplicate Document",message:"Are you sure you want to duplicate this document?",onConfirm:async()=>{await D();}});},Kc=()=>{u({title:"Delete Document",message:"Delete this document? This cannot be undone. Are you absolutely sure?",variant:"danger",onConfirm:async()=>{try{await xt(`/api/${n}/${y.id}`),window.location.href=`${Ge}/${n}`;}catch(D){M.error(D.message||"Failed to delete document");}}});},Gc=()=>{u({title:"Unpublish Document",message:"Unpublish this document?",onConfirm:async()=>{try{let D=await Fe({...y,status:"draft"},!1);if(D?.ok)c?.("Document unpublished successfully"),$e.getState().loadDocument({...y,status:"draft"},{...y,status:"draft"});else {let J=await D?.json().catch(()=>({}));M.error(J?.error||"Failed to unpublish");}}catch{M.error("Failed to unpublish");}}});},ns=async()=>{let D=!y.id;lt.current=true,C("saving");try{let J=Sr({...y}),be=D&&!s,Ee=be?await at(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J)}):await Fe(J);if(Ee.ok){let Ht=(await Ee.json()).data||J;St({...y,...Ht}),te({...y,...Ht}),Tt.current=Date.now(),ce("success"),C("saved"),ie&&Te(),setTimeout(()=>{ce("idle"),C("idle");},2e3),c?.(be?"Document created successfully":"Changes saved"),be&&setTimeout(()=>{window.location.href=`${Ge}/${n}`;},800);}else {let At=await Ee.json();Ee.status===409&&ce("conflict"),C("error"),M.error(At.error||"Failed to save"),setTimeout(()=>C("idle"),3e3);}}catch{C("error"),M.error("Failed to save document"),setTimeout(()=>C("idle"),3e3);}finally{window.dispatchEvent(new CustomEvent("kyro:global-save-end")),lt.current=false;}},Wc=async()=>{let D=!y.id;lt.current=true,C("saving");try{let J={...y};if(D&&!s){let At=Sr({...y}),Ht=await at(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(At)});if(!Ht.ok){let mo=await Ht.json().catch(()=>({}));Ht.status===409&&ce("conflict"),C("error"),M.error(mo.error||"Failed to create document"),setTimeout(()=>C("idle"),3e3);return}let ut=(await Ht.json()).data||At;St({...y,...ut}),te({...y,...ut}),J={...y,...ut};}let be=Sr(J),Ee=await Fe(be,!1);if(Ee?.ok)C("saved"),c?.("Published successfully");else {let At=await Ee?.json().catch(()=>({}));Ee?.status===409&&ce("conflict"),C("error"),M.error(At?.error||"Failed to publish"),setTimeout(()=>C("idle"),3e3);}}catch{C("error"),M.error("Failed to publish"),setTimeout(()=>C("idle"),3e3);}finally{lt.current=false;}},Jc=async D=>{let J=!y.id;lt.current=true;try{let be={...Sr({...y}),_schedulePublishAt:D};if(J&&!s){let Ee=await at(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(be)});if(!Ee.ok){let At=await Ee.json().catch(()=>({}));M.error(At.error||"Failed to schedule publish");return}}else {let Ee=await Fe(be);if(!Ee.ok){let At=await Ee.json().catch(()=>({}));M.error(At.error||"Failed to schedule publish");return}}c?.(`Scheduled publish for ${new Date(D).toLocaleString()}`),qa(!1);}catch{M.error("Failed to schedule publish");}finally{lt.current=false;}},qc=(D,J)=>{Ct(D,J);},fa=(D,J,be)=>{let Ee=J!==void 0?J:y;if(fi(D.hidden!==void 0?D.hidden:D.admin?.hidden,Ee))return null;let Ht=fi(D.readOnly!==void 0?D.readOnly:D.admin?.readOnly,Ee),Ar=!!(fr||Ht);if(D.admin?.condition){if(typeof D.admin.condition=="function")try{let Oe={values:y||{},...y||{}};if(!D.admin.condition(Oe,Ee))return null}catch(Oe){console.warn(`Condition error for field ${D.name}:`,Oe);}else if(typeof D.admin.condition=="object")try{let Oe=D.admin.condition,He=Oe.field,Vt=Ee&&Ee[He]!==void 0?Ee[He]:y&&y[He]!==void 0?y[He]:void 0,Fr=!0;if("equals"in Oe?Fr=Vt===Oe.equals:"notEquals"in Oe?Fr=Vt!==Oe.notEquals:"in"in Oe&&Array.isArray(Oe.in)&&(Fr=Oe.in.includes(Vt)),!Fr)return null}catch(Oe){console.warn(`Declarative condition error for field ${D.name}:`,Oe);}}let ut=Ee[D.name],mo=r[D.name],Xa=Oe=>{be?be({...Ee,[D.name]:Oe}):qc(D.name,Oe);};if(D.type==="row"&&"fields"in D){let Oe=D.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:Oe?.map(He=>{let Vt=He.admin||{},Fr=Vt?.action;if((He.type==="button"||He.type==="action")&&Fr){let vr=Oe?.find(va=>va.type==="email");return jsxRuntime.jsx("div",{className:"flex-shrink-0",children:jsxRuntime.jsx("button",{type:"button",onClick:async()=>{let va=D.name,Ya=vr?.name,Qa=Ya?y[Ya]:void 0;if(!Qa&&va&&typeof va=="string"&&Ya&&(Qa=y[va]?.[Ya]),!!Qa){Se(gr=>({...gr,[He.name]:true}));try{let gr=await at(tt(Fr),{method:Vt.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:Qa})}),ga={};try{ga=await gr.json();}catch{ga={};}if(gr.ok&&ga.success)c?.(ga.message||"Action completed successfully");else {let Xc=ga.error||`Request failed (${gr.status})`;m?.(Xc);}}catch(gr){m?.(gr instanceof Error?gr.message:"Error connecting to server");}finally{Se(gr=>({...gr,[He.name]:false}));}}},disabled:ge[He.name]||Ar,className:"kyro-btn kyro-btn-primary px-4 py-2 rounded-lg font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:ge[He.name]?"Sending...":He.label||"Click"})},He.name)}return jsxRuntime.jsx("div",{className:He.type==="button"||He.type==="action"?"flex-shrink-0":"flex-1",style:Vt?.width?{width:Vt.width,flex:"none"}:{},children:fa(He,J,be)},He.name)})},D.name||`row-${Math.random()}`)}switch(D.type){case "tabs":return jsxRuntime.jsx(Od,{field:D,formData:y,onTabDataChange:Oe=>{Ct(D.name,Oe);},renderField:(Oe,He,Vt)=>fa(Oe,He,Vt)},D.name||`tabs-${Math.random()}`);case "group":return jsxRuntime.jsx(jn,{field:D,value:ut,onChange:Xa,renderField:fa},D.name);case "array":return jsxRuntime.jsx(_n,{field:D,value:ut,onChange:Xa,renderField:fa,disabled:Ar},D.name);case "button":case "action":{let Oe=D.name,He=ge[Oe];return jsxRuntime.jsx("div",{className:"kyro-form-field",children:jsxRuntime.jsxs("button",{type:"button",disabled:He||Ar,onClick:async()=>{let Vt=D.admin?.action||D.action,Fr=D.admin?.method||D.method||"POST";if(Vt){Se(vr=>({...vr,[Oe]:true}));try{let vr=await at(Vt,{method:Fr,headers:{"Content-Type":"application/json"},body:JSON.stringify(y)});await vr.json(),vr.ok;}catch(vr){console.error("Error executing action:",vr);}finally{Se(vr=>({...vr,[Oe]:false}));}}},className:`kyro-btn kyro-btn-md kyro-btn-secondary transition-all active:scale-95 whitespace-nowrap flex items-center gap-2 ${He?"opacity-70 cursor-not-allowed":""}`,children:[He&&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"})]}),He?"Processing...":D.label||"Click"]})},Oe)}case "relationship-block":return jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[D.label||D.name,D.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsx(Ha,{relationTo:D.relationTo,hasMany:D.hasMany,selectedIds:Array.isArray(ut)?ut:ut?[ut]:[],onChange:(Oe,He)=>{Xa(He);},compact:true}),D.admin?.description?jsxRuntime.jsx("p",{className:"kyro-form-help",children:String(D.admin?.description)}):null]},D.name);default:return jsxRuntime.jsx(wo,{field:D,value:ut,onChange:Xa,error:mo,disabled:Ar,formData:y,siblingData:Ee,collectionSlug:n,globalSlug:s},D.name||Math.random().toString())}};return os?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})})]}):Ec?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:()=>{as(false),Po(true),Oc(D=>D+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(jd,{collectionSlug:n,globalSlug:s,documentStatus:I||"draft",hasUnpublishedChanges:W,localSaveStatus:rs,isDuplicating:me,handleCreateNew:Hc,handleDuplicate:Vc,handleUnpublish:Gc,handleDelete:Kc,handlePublish:Wc,handleSchedulePublish:Jc}),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:[k==="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..."]}),k==="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"]}),k==="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..."]}),k==="offline"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]",children:"Offline \u2014 cached locally"}),k==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Save failed"}),k==="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Conflict detected"}),R&&k!=="saving"&&k!=="retrying"&&k!=="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-warning)]",children:"Unsaved changes"}),!R&&k!=="success"&&k!=="saving"&&k!=="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:y.updatedAt?`Modified ${new Date(y.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 D=await Fe(y);if(D.ok){let be=(await D.json()).data||y;St({...y,...be}),te({...y,...be}),c?.("Changes saved");}}catch(D){console.error("Save error exception:",D),m?.("Save failed: "+D.message);}}})]}),jsxRuntime.jsxs("main",{className:"w-full pt-6 md:pt-0",children:[$==="edit"&&jsxRuntime.jsx(_d,{config:x,layout:d,collectionSlug:n,renderField:fa}),$==="version"&&jsxRuntime.jsx(Hd,{handleRestoreVersion:zc,handleCompareVersions:jc,toggleCompareSelection:_c}),$==="api"&&jsxRuntime.jsx(Vd,{collectionSlug:n,globalSlug:s})]})]})}var Gd={draft:"bg-[var(--kyro-warning)]",published:"bg-[var(--kyro-success)]",scheduled:"bg-[var(--kyro-primary)]",archived:"bg-[var(--kyro-text-muted)]"};function si({status:e,saveStatus:t,hasChanges:r,onSave:o,onPublish:a,onUnpublish:n,onDuplicate:s,onViewHistory:l,onPreview:i,onDelete:d,onBack:c,onToggleSidebar:m,publishedAt:f,updatedAt:v}){let b=$e(k=>k.view)||"edit",g=$e(k=>k.setView),[x,u]=Ca.useState(false),y=Ca.useRef(null);Ca.useEffect(()=>{let k=p=>{y.current&&!y.current.contains(p.target)&&u(false);};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[]);let h=()=>t==="saving"?"Saving...":t==="saved"?"Saved":t==="error"?"Error saving":r?"Unsaved":null,R=["edit","version","api"],P=h(),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 ${Gd[e]||"bg-[var(--kyro-text-muted)]"}`}),P&&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(kr,{size:"sm",className:"inline mr-0.5"}),P]}),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:R.map(k=>jsxRuntime.jsx("button",{type:"button",onClick:()=>g(k),className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all ${b===k?"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:k==="edit"?"Edit":k==="version"?"Ver":"API"},k))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1 ml-auto shrink-0",children:[i&&jsxRuntime.jsx("button",{type:"button",onClick:i,className:`${w} max-md:hidden`,title:"Preview",children:jsxRuntime.jsx(lucideReact.Eye,{className:"w-3.5 h-3.5"})}),l&&jsxRuntime.jsx("button",{type:"button",onClick:l,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:y,className:"relative md:hidden",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>u(!x),className:w,title:"More",children:jsxRuntime.jsx(lucideReact.EllipsisVertical,{className:"w-3.5 h-3.5"})}),x&&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:[P&&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 ${Gd[e]}`}),jsxRuntime.jsx("span",{className:"capitalize",children:e}),jsxRuntime.jsx("span",{children:"\xB7"}),t==="saving"&&jsxRuntime.jsx(kr,{size:"sm",className:"inline"}),jsxRuntime.jsx("span",{children:P})]}),jsxRuntime.jsx("div",{className:"flex gap-1 px-2 py-2 border-b border-[var(--kyro-border)]",children:R.map(k=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(k),u(false);},className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all flex-1 ${b===k?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)]"}`,children:k==="edit"?"Edit":k==="version"?"Ver":"API"},k))}),l&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{l(),u(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(),u(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"]}),i&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{i(),u(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(),u(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(Ro,{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"}),l&&jsxRuntime.jsx(jt,{icon:jsxRuntime.jsx(lucideReact.Clock,{className:"w-4 h-4"}),children:"View History"}),i&&jsxRuntime.jsx(jt,{icon:jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"}),children:"Preview"}),(s||l||i)&&jsxRuntime.jsx(Ka,{}),d&&jsxRuntime.jsx(jt,{onClick:d,danger:true,icon:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"}),children:"Delete"})]})]})]})}function li({config:e,collection:t,global:r,documentId:o,onBack:a,onSave:n,onDelete:s,onError:l,mode:i="collection"}){let{confirm:d,alert:c}=dt(),[m,f]=Ca.useState({}),[v,b]=Ca.useState({}),[g,x]=Ca.useState(true),[u,y]=Ca.useState(false),[h,R]=Ca.useState(false),[P,w]=Ca.useState(false),[k,p]=Ca.useState("idle"),[T,B]=Ca.useState("draft"),[S,F]=Ca.useState(null),[A,X]=Ca.useState(null),[K,$]=Ca.useState(null),[j,ae]=Ca.useState(false),ne=r?.fields||t?.fields||[],H=r?.label||t?.label||"Document",re=r?.slug||t?.slug||"",ve=JSON.stringify(m)!==JSON.stringify(v);Ca.useEffect(()=>{ve&&T==="published"&&B("draft");},[ve,T]),Ca.useEffect(()=>{ve&&k==="saved"&&p("idle");},[ve,k]),Ca.useEffect(()=>{i==="global"?O():o&&L();},[o,i,re]);let L=async()=>{try{x(!0);let le=await Be(`/api/${re}/${o}`,{autoToast:!1}),Re=le.data||{};f(Re),b(Re),B(Re?.status||le.status||"draft"),F(le.createdAt||Re.createdAt||null),X(le.updatedAt||Re.updatedAt||null),$(le.publishedAt||Re.publishedAt||null);}catch{l("Failed to load document");}finally{x(false);}},O=async()=>{try{x(!0);let le=await Be(`/api/globals/${re}`,{autoToast:!1}),Re=le.data||{};f(Re),b(Re),F(le.createdAt||null),X(le.updatedAt||null);}catch{l("Failed to load global");}finally{x(false);}},pe=Ca.useCallback(async(le=false)=>{try{p("saving");let Re=i==="global"?`/api/globals/${re}`:`/api/${re}/${o}`,Ue=T==="draft"||m?.status==="draft",Ie=await Gt(Re,m,{autoToast:!1,headers:{"X-Draft":String(Ue)}}),et=Ie&&(Ie.data||Ie)||m;le||(b(et),n()),f(et),B(et?.status||T),p("saved"),X(new Date().toISOString()),ae(!0),setTimeout(()=>ae(!1),3e3),le||(T==="draft"||et?.status==="draft"?M.warning("Draft saved"):M.success("Updated")),setTimeout(()=>{p("idle");},2e3);}catch{p("error"),le||(l("Failed to save changes"),M.error("Failed to save changes"));}finally{y(false);}},[m,i,re,o,T,n,l]),ge=async()=>{try{y(!0),await Gt(`/api/${re}/${o}`,m,{autoToast:!1,headers:{"X-Draft":"false"}}),B("published"),$(new Date().toISOString()),M.success("Published successfully"),n();}catch{l("Failed to publish"),M.error("Failed to publish");}finally{y(false);}},Se=async()=>{try{y(!0),await Gt(`/api/${re}/${o}`,{status:"draft"},{autoToast:!1,headers:{"X-Draft":"false"}}),B("draft"),M.warning("Document unpublished"),n();}catch{l("Failed to unpublish"),M.error("Failed to unpublish");}finally{y(false);}},Ne=async()=>{try{R(!0);let le=await nt(`/api/${re}/${o}/duplicate`,void 0,{autoToast:!1});M.success("Document duplicated"),le?.data?.id?window.location.href=`${Ge}/${re}/${le.data.id}`:window.location.href=`${Ge}/${re}`;}catch(le){M.error(le.message||"Failed to duplicate document");}finally{R(false);}},U=()=>{d({title:`Delete ${H}?`,message:"This action cannot be undone.",variant:"danger",onConfirm:async()=>{try{w(!0),await xt(`/api/${re}/${o}`),window.location.href=`${Ge}/${re}`;}catch{w(false);}}});};if(g)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 Y=i==="global"||t?.admin?.layout==="single";return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Dt,{back:{onClick:a},breadcrumbs:[{label:i==="global"?"Globals":"Collections"},{label:H,href:i==="collection"?`${Ge}/${re}`:void 0},{label:i==="global"||o?"Edit":"New"}],title:i==="global"?H:go(t?.fields,m,t?.admin?.useAsTitle||"title")||m.name||o||`New ${t?.singularLabel||H}`,metadata:[jsxRuntime.jsx(Pt,{variant:T==="published"?"success":"warning",dot:true,className:"text-[10px] font-bold ",children:T},"status")]}),jsxRuntime.jsx(si,{status:T,saveStatus:k,hasChanges:ve,onSave:()=>pe(false),onPublish:ge,onUnpublish:T==="published"?Se:void 0,onDuplicate:Ne,onViewHistory:()=>{window.dispatchEvent(new CustomEvent("kyro:show-version-history"));},onPreview:()=>window.open(`/preview/${re}/${o}`,"_blank"),onDelete:U,onBack:a,onToggleSidebar:()=>window.dispatchEvent(new CustomEvent("toggle-sidebar")),publishedAt:K,updatedAt:A}),jsxRuntime.jsxs("div",{className:Y?"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(Wa,{config:t?{...t,fields:ne}:{slug:"unknown",fields:ne},data:m,onChange:f,layout:Y?"single":"split",globalSlug:i==="global"?re:void 0,collectionSlug:i==="collection"?re:void 0,onActionSuccess:le=>M.success(le),onActionError:le=>M.error(le),documentStatus:T,justSaved:j}),Y&&jsxRuntime.jsxs("div",{className:"mt-8 pt-8 border-t border-[var(--kyro-border)] flex justify-end gap-3",children:[i==="collection"&&o&&jsxRuntime.jsx("button",{type:"button",onClick:U,disabled:P||u,className:"kyro-btn kyro-btn-sm text-[var(--kyro-danger)] hover:bg-[var(--kyro-danger)]/10 w-full justify-start mt-2",children:P?"Deleting...":"Delete Document"}),jsxRuntime.jsx(Ro,{status:T,saveStatus:u?"saving":"idle",hasChanges:ve,onPublish:()=>pe(false),disabled:u})]})]})}),!Y&&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 ${T==="published"?"bg-green-500/10 text-green-500":"bg-amber-500/10 text-amber-500"}`,children:T||"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:S?new Date(S).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:A?new Date(A).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"Just now"})]}),K&&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(K).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:Ne,disabled:h||u,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:h?"Duplicating...":"Duplicate Document"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(`/preview/${re}/${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:U,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 di({config:e,collection:t,onCancel:r,onSuccess:o,onError:a}){let[n,s]=Ca.useState({}),[l,i]=Ca.useState(false),d=t.fields||[],c=t.label||t.slug,m=async f=>{try{i(!0),await nt(`/api/${t.slug}`,n),M.success(`${t.singularLabel||t.label||"Document"} created`),o();}catch(v){a(v instanceof Error?v.message:"Failed to create");}finally{i(false);}};return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Dt,{back:{onClick:r},breadcrumbs:[{label:"Collections"},{label:c,href:`${Ge}/${t.slug}`},{label:"New"}],title:`Create ${t.singularLabel||c}`,action:{label:l?"Creating...":`Create ${t.singularLabel||c}`,onClick:()=>m(),disabled:l}}),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(Wa,{config:{...t,fields:d},data:n,onChange:s})})})})})]})}function Jd({type:e,message:t,onClose:r}){let[o,a]=Ca__default.default.useState(false),n=Ca__default.default.useRef(null),s=()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(r,5e3);},l=()=>{n.current&&clearTimeout(n.current);};Ca__default.default.useEffect(()=>(o?l():s(),l),[o,r]);let i={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(i,{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 X3({children:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function Y3(){let e=Kt(o=>o.addToast),t=Kt(o=>o.removeToast);return {toasts:Kt(o=>o.toasts),addToast:e,removeToast:t}}function qn(){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:1e5,pointerEvents:"none"},children:e.map(r=>jsxRuntime.jsx("div",{style:{pointerEvents:"auto"},children:jsxRuntime.jsx(Jd,{type:r.type,message:r.message,onClose:()=>t(r.id)})},r.id))})}function mi({onAuth:e,theme:t="light"}){let[r,o]=Ca.useState("login"),[a,n]=Ca.useState(""),[s,l]=Ca.useState(""),[i,d]=Ca.useState(""),[c,m]=Ca.useState(false),[f,v]=Ca.useState(false),b=Kt(u=>u.addToast);Ca.useEffect(()=>{g();},[]);let g=async()=>{try{await Be("/api/users");}catch{v(true),o("register");}};return jsxRuntime.jsx(hr,{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:f?"Create Admin Account":r==="login"?"Sign In":"Create Account"}),jsxRuntime.jsx("p",{className:"kyro-login-subtitle",children:f?"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 u=>{u.preventDefault(),m(true);try{let y=r==="login"?"/api/auth/login":"/api/auth/register",h={email:a,password:s};r==="register"&&(h.confirmPassword=i);let R=await nt(y,h);R.isFirstUser&&v(!0),localStorage.setItem("kyro_user",JSON.stringify(R.user)),b("success",r==="login"?"Welcome back!":"Account created!"),e(R.token,R.user);}catch{b("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:u=>n(u.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:u=>l(u.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:i,onChange:u=>d(u.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"})]}),!f&&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(qn,{})]})})}function Yd({collections:e,onNavigate:t,user:r}){let{permissions:o}=Ur(),[a,n]=Ca.useState({totalDocs:0,totalMedia:0,totalUsers:0,recentActivity:[]}),[s,l]=Ca.useState(true);Ca.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"}]}),l(false);},800);return ()=>clearTimeout(d)},[]);let i=Object.entries(e).filter(([d])=>!Bs.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(Dt,{title:`Welcome back, ${r?.email?.split("@")[0]||"Admin"}`,description:"Everything looks great in your command center today.",action:i.length>0&&o?.collections?.[i[0]?.[0]]?.create!==false?{label:"New Document",onClick:()=>t("create",i[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:i.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:[i.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)),i.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 Zd(){let[e,t]=Ca.useState([]),[r,o]=Ca.useState(true),[a,n]=Ca.useState(""),[s,l]=Ca.useState(false),[i,d]=Ca.useState({name:"",email:"",password:"",role:"customer"}),[c,m]=Ca.useState(""),[f,v]=Ca.useState(false),{confirm:b,alert:g}=dt();Ca.useEffect(()=>{x();},[]);let x=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);}},u=w=>{let k=!w.locked;b({title:k?"Lock User Account?":"Unlock User Account?",message:k?`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:k?"danger":"success",onConfirm:async()=>{try{await Gt(`/api/users/${w.id}`,{locked:k}),t(p=>p.map(T=>T.id===w.id?{...T,locked:k}:T)),M.success(k?`Account locked: ${w.email}`:`Account restored: ${w.email}`);}catch(p){console.error("Failed to toggle user lock:",p),M.error("Failed to update account status");}}});},y=w=>{b({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 xt(`/api/users/${w.id}`),t(k=>k.filter(p=>p.id!==w.id)),M.success(`Identity purged: ${w.email}`);}catch(k){console.error("Failed to delete user:",k),M.error("Failed to delete user");}}});},h=async()=>{if(!i.email.trim()||!i.password.trim()){m("Email and password are required");return}v(true),m("");try{await nt("/api/users",{name:i.name.trim()||void 0,email:i.email.trim(),password:i.password,role:i.role}),l(!1),d({name:"",email:"",password:"",role:"customer"}),M.success("User created successfully"),x();}catch(w){let k=w instanceof Error?w.message:"Failed to create user";m(k),M.error(k);}finally{v(false);}},R=["super_admin","admin","editor","author","customer","guest"],P=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(Dt,{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(""),l(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,k)=>jsxRuntime.jsx("tr",{className:"animate-pulse",children:jsxRuntime.jsx("td",{colSpan:5,className:"px-6 py-5 bg-[var(--kyro-surface-accent)]/30"})},k)):P.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"})})}):P.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(Xu,{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:()=>u(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:()=>y(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:()=>l(false),title:"Create User",size:"lg",children:[jsxRuntime.jsx(Hr,{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:i.name,onChange:w=>d({...i,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:i.email,onChange:w=>d({...i,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:i.password,onChange:w=>d({...i,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:i.role,onChange:w=>d({...i,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:R.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(Vr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>l(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:h,disabled:f,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:f?"Creating...":"Create User"})]})]})]})}function Xu({user:e}){let[t,r]=Ca.useState(null);return Ca.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 ec(){let[e,t]=Ca.useState("Kyro CMS"),[r,o]=Ca.useState("Command Center"),[a,n]=Ca.useState("#6366f1"),[s,l]=Ca.useState("Welcome back to your Command Center."),[i,d]=Ca.useState(false),[c,m]=Ca.useState(false);return Ca.useEffect(()=>{(async()=>{try{let g=await Be("/api/globals/site-settings"),x=g.data||g;x&&Object.keys(x).length>0&&(x.siteName&&t(x.siteName),x.adminTitle&&o(x.adminTitle),x.primaryColor&&n(x.primaryColor),x.dashboardGreeting&&l(x.dashboardGreeting));}catch(g){console.error("Failed to load branding:",g);}})();},[]),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 Gt("/api/globals/site-settings",{siteName:e,adminTitle:r,primaryColor:a,dashboardGreeting:s}),m(!0),M.success("Branding updated"),document.documentElement.style.setProperty("--kyro-primary",a),setTimeout(()=>window.location.reload(),800);}catch(b){M.error("Failed to save branding"),console.error(b);}finally{d(false);}},disabled:i,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:[i?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"}),i?"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:b=>t(b.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:b=>o(b.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:b=>l(b.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(b=>jsxRuntime.jsx("button",{type:"button",onClick:()=>n(b.hex),className:`aspect-square rounded-xl transition-all border-4 ${a===b.hex?"border-white ring-2 ring-[var(--kyro-primary)]":"border-transparent opacity-60 hover:opacity-100"}`,style:{backgroundColor:b.hex},title:b.name},b.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 In({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=Sa.useState(false),[l,i]=Sa.useState(false),d=t??"",c=d.length>8?d.slice(0,-8)+"*".repeat(8):d,p=async()=>{if(d)try{await navigator.clipboard.writeText(d),s(!0),setTimeout(()=>s(!1),1800);}catch{let v=document.createElement("textarea");v.value=d,v.style.position="fixed",v.style.opacity="0",document.body.appendChild(v),v.select(),document.execCommand("copy"),document.body.removeChild(v),s(true),setTimeout(()=>s(false),1800);}},y=()=>{if(l||a)return;i(true);let v=new Uint8Array(32);crypto.getRandomValues(v);let b=Array.from(v).map(g=>g.toString(16).padStart(2,"0")).join("");r?.(b),setTimeout(()=>i(false),400);};return jsxRuntime.jsx(pt,{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:p,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 ${l?"animate-spin":""}`})})]})})}var Bn=null,jl=false,Ls=async()=>(Bn&&jl||(Bn=unstorage.createStorage({driver:Cm__default.default({dbName:"kyro-autosave",storeName:"autosave"})}),jl=true),Bn),Sm=()=>typeof window>"u"?{getItem:async()=>null,setItem:async()=>{},removeItem:async()=>{}}:{getItem:async e=>{try{return await(await Ls()).getItem(e)??null}catch(t){return console.error("Storage getItem error:",t),localStorage.getItem(e)}},setItem:async(e,t)=>{try{await(await Ls()).setItem(e,t);}catch(r){console.error("Storage setItem error:",r),localStorage.setItem(e,t);}},removeItem:async e=>{try{await(await Ls()).removeItem(e);}catch(t){console.error("Storage removeItem error:",t),localStorage.removeItem(e);}}},Ae=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},l=s;for(let i=0;i<n.length-1;i++)l[n[i]]===void 0&&(l[n[i]]={}),l[n[i]]={...l[n[i]]},l=l[n[i]];return l[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,l]of Object.entries(a))o-new Date(l.draftUpdatedAt).getTime()<6048e5&&(n[s]=l);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(()=>Sm()),partialize:e=>({sidebarCollapsed:e.sidebarCollapsed,draftCache:e.draftCache}),onRehydrateStorage:()=>e=>{e&&e.pruneExpiredDrafts();}}));function Ln(e){return e?e.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function Wo({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",l=e.name==="slug",{isSlugLocked:i,setIsSlugLocked:d,formData:c}=Ae(),p=e.variant==="email"?"email":e.variant==="password"?"password":e.variant==="url"?"url":"text",y=t==null?"":String(t),v={id:e.name,value:y,onChange:b=>r?.(b.target.value),placeholder:e.admin?.placeholder,disabled:a||n||l&&i,minLength:e.minLength,maxLength:e.maxLength,required:e.required,className:`kyro-form-input ${l?"pr-24":""} ${a||n||l&&i?"opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed":""}`};return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"relative",children:[s?jsxRuntime.jsx("textarea",{...v,rows:e.rows||4}):jsxRuntime.jsx("input",{type:p,...v,pattern:e.pattern}),l&&jsxRuntime.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:[!i&&jsxRuntime.jsx("button",{type:"button",onClick:()=>r?.(Ln(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(!i),className:`p-1.5 rounded transition-colors ${i?"text-[var(--kyro-primary)] bg-[var(--kyro-primary-alpha)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,title:i?"Unlock slug":"Lock slug",children:i?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 Mn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(pt,{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 En({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(pt,{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:l=>r?.(l.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 $n({field:e,value:t="",onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsxRuntime.jsx(pt,{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 La(e){return e?Array.isArray(e)?e:Object.values(e):[]}function Un(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function zn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Ba(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 Tm={pages:"FileText",posts:"Newspaper",categories:"Tags",menu:"Menu",products:"ShoppingBag",customers:"Users",orders:"ShoppingCart",coupons:"Ticket",forms:"FileInput","form-entries":"Inbox"};function ko(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 ko(s.fields,n,r);if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let i of s.tabs)if(i.fields&&Array.isArray(i.fields)&&ko(i.fields,n,r))return true;return false}if(s.type==="blocks"&&s.blocks&&Array.isArray(s.blocks)){let i=n.split(".")[0],d=n.split(".").slice(1).join(".");if(!d)return false;for(let c of s.blocks)if(c.slug===i&&c.fields&&Array.isArray(c.fields))return ko(c.fields,d,r);return false}return s.type==="array"&&s.fields&&Array.isArray(s.fields)?ko(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)&&ko(s.fields,t,r))return true;if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let i of s.tabs)if(i.fields&&Array.isArray(i.fields)&&ko(i.fields,t,r))return true}}}return false}function Am(e,t){for(let[r,o]of Object.entries(e)){let a=Tm[r],n=t?.[r];if(a&&!o.admin?.icon&&(o.admin={...o.admin,icon:a}),n){let{fields:s,...l}=n;if(o.admin={...o.admin,...l},s&&o.fields&&Array.isArray(o.fields))for(let[i,d]of Object.entries(s))ko(o.fields,i,d);}}}function Dm(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 Ba(t,Object.values(templates.mediaCollections)),Ba(t,Object.values(templates.authCollections)),{collections:Un(t),globals:zn(r)}}function Fm(e){let t=La(e.collections),r=La(e.globals);if(t.length===0&&r.length===0)return Dm("kitchen-sink");let o=[];return Ba(o,Object.values(templates.mediaCollections)),Ba(o,Object.values(templates.authCollections)),Ba(o,t),{collections:Un(o),globals:zn(r)}}var On=null;function Pm(){if(On)return On;try{if(typeof __KYRO_ADMIN_CONFIG_FILE__=="string"&&Io__default.default.existsSync(__KYRO_ADMIN_CONFIG_FILE__))return On=JSON.parse(Io__default.default.readFileSync(__KYRO_ADMIN_CONFIG_FILE__,"utf8")),On}catch{}return null}var Zl=Pm()||{collections:[],globals:[]},ed=Fm(Zl);Am(ed.collections,Zl.collectionOverrides);var td=ed,qo=td.collections,rd=td.globals,$s=["users","audit_logs"];Object.values(qo).filter(e=>!$s.includes(e.slug)&&e.admin?.hidden!==true);function jn({field:e,value:t,onChange:r,error:o,disabled:a,formData:n,siblingData:s,collectionSlug:l,globalSlug:i}){let d=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,[c,p]=Sa.useState(null),y=JSON.stringify(n||{}),v=JSON.stringify(s||{});Sa.useEffect(()=>{if(e.options!=="__KYRO_DYNAMIC_OPTIONS__")return;let h=setTimeout(async()=>{try{let f="";if(l)f=`${kr}/${l}/dynamic-options/${e.name}`;else if(i)f=`${kr}/globals/${i}/dynamic-options/${e.name}`;else return;let m=await nt(f,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:JSON.parse(y),siblingData:JSON.parse(v)})});if(m.ok){let w=await m.json();w.options&&p(w.options);}}catch(f){console.error("Failed to fetch dynamic options:",f);}},300);return ()=>clearTimeout(h)},[y,v,e.name,e.options,l,i]);let b=c||[];return e.options!=="__KYRO_DYNAMIC_OPTIONS__"&&(typeof e.options=="function"?b=e.options({data:n||{},siblingData:s||{}}):Array.isArray(e.options)&&(b=e.options)),e.dynamicOptions==="collections"&&(b=Object.keys(qo).filter(g=>g!=="media").map(g=>({label:qo[g]?.label||g,value:g}))),jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsxs("select",{id:e.name,value:e.hasMany?Array.isArray(t)?t:[]:t||"",onChange:g=>{if(e.hasMany){let h=Array.from(g.target.selectedOptions,f=>f.value);r?.(h);}else r?.(g.target.value||void 0);},multiple:e.hasMany,disabled:a||d,required:e.required,className:`kyro-form-input ${a||d?"opacity-50 cursor-not-allowed":""}`,children:[!e.required&&!e.hasMany&&jsxRuntime.jsx("option",{value:"",children:"Select..."}),b.map(g=>jsxRuntime.jsx("option",{value:g.value,children:g.label},g.value))]})})}function _n({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 Hs(e){let t=e?.tabs;return e?.title||t?.title||e?.name||e?.label||e?.email||e?.filename||e?.slug||"Untitled"}function Km({id:e,label:t,relation:r,onRemove:o,disabled:a}){let{attributes:n,listeners:s,setNodeRef:l,transform:i,transition:d,isDragging:c}=sortable.useSortable({id:e}),p={transform:utilities.CSS.Transform.toString(i),transition:d,zIndex:c?10:1,opacity:c?.8:1};return jsxRuntime.jsxs("span",{ref:l,style:p,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)] border border-transparent ${c?"border-[var(--kyro-primary)] shadow-sm bg-[var(--kyro-sidebar-active)]/20":""}`,children:[!a&&jsxRuntime.jsx("div",{...n,...s,className:"cursor-grab active:cursor-grabbing hover:bg-[var(--kyro-sidebar-active)]/20 rounded p-0.5 text-[var(--kyro-sidebar-active)] opacity-70 flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-2.5 h-2.5"})}),r&&jsxRuntime.jsxs("span",{className:"opacity-60 mr-0.5",children:[r,":"]}),t,!a&&jsxRuntime.jsx("button",{type:"button",onClick:o,className:"hover:opacity-70 p-0.5 ml-0.5 flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]})}function Gm({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=Sa.useState(false),[l,i]=Sa.useState(""),[d,c]=Sa.useState([]),[p,y]=Sa.useState(false),[v,b]=Sa.useState([]),g=Sa.useRef(new Set),h=Sa.useRef(null),f=Sa.useRef(()=>{});f.current=r||(()=>{});let m=e.hasMany,w=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],A=w.length>1,[T,k]=Sa.useState(w[0]||""),x=Sa.useCallback(()=>t?(m?Array.isArray(t)?t:[]:t?[t]:[]).map(z=>typeof z=="object"&&z!==null?z.value||z.id||"":String(z)).filter(Boolean):[],[t,m]),u=Sa.useCallback(O=>{O.length!==0&&O.forEach(z=>{if(g.current.has(z))return;g.current.add(z);let se=A?(()=>{if(!t)return T;let H=(m?Array.isArray(t)?t:[]:[t]).find(R=>typeof R=="object"&&R!==null?R.value===z||R.id===z:false);return H&&typeof H=="object"&&H.relationTo||T})():T;Te(`/api/${se}/${z}`).then(le=>{let H=le.data||le;!H||typeof H!="object"||b(R=>R.some(V=>V.id===z)?R:[...R,{...H,id:String(H.id),relationTo:se}]);}).catch(()=>{});});},[A,t,T,m]);Sa.useEffect(()=>{let O=x();u(O);},[x,u]);let F=Sa.useCallback((O="")=>{y(true);let se=`/api/${T}?${on(O,["title","name","label","email"])}`;Te(se).then(le=>{c(H=>{let R=new Set(H.map(L=>L.id)),V=(le.docs||[]).filter(L=>!R.has(L.id)).map(L=>({...L,id:L.id}));return [...H,...V]}),y(false);}).catch(()=>{y(false);});},[T]);Sa.useEffect(()=>{n&&(c([]),F(l));},[n,T]),Sa.useEffect(()=>{let O=z=>{h.current&&!h.current.contains(z.target)&&s(false);};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[]);let M=O=>typeof O=="object"&&O!==null?O.value||O.id||"":String(O),S=O=>{let z=O.id;return t?m&&Array.isArray(t)?t.some(se=>M(se)===z):M(t)===z:false},P=O=>{let z=O.id;if(m){let se=Array.isArray(t)?t:[];if(S(O))f.current?.(se.filter(le=>M(le)!==z));else {let le=A?{relationTo:T,value:z}:z;f.current?.([...se,le]);}}else if(S(O))f.current?.(null);else {let se=A?{relationTo:T,value:z}:z;f.current?.(se),s(false),i("");}},D=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}})),Q=O=>{let{active:z,over:se}=O;if(!se||z.id===se.id)return;let le=m?Array.isArray(t)?t:[]:[],H=le.findIndex(V=>M(V)===z.id),R=le.findIndex(V=>M(V)===se.id);if(H!==-1&&R!==-1){let V=[...le],[L]=V.splice(H,1);V.splice(R,0,L),f.current?.(V);}},G=()=>{if(!t)return null;let O=m?Array.isArray(t)?t:[]:t?[t]:[],z=O.map(se=>M(se));return m&&O.length>1?jsxRuntime.jsx(core.DndContext,{sensors:D,collisionDetection:core.closestCenter,onDragEnd:Q,children:jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:jsxRuntime.jsx(sortable.SortableContext,{items:z,strategy:sortable.horizontalListSortingStrategy,children:O.map(se=>{let le=M(se),H=v.find(L=>L.id===le),R=H?Hs(H):le.slice(0,12),V=A&&H?H.relationTo:null;return jsxRuntime.jsx(Km,{id:le,label:R,relation:V,onRemove:()=>{let L=O.filter(Z=>M(Z)!==le);f.current?.(L);},disabled:a},le)})})})}):jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:O.map(se=>{let le=M(se),H=v.find(L=>L.id===le),R=H?Hs(H):le.slice(0,12),V=A&&H?H.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:[V&&jsxRuntime.jsxs("span",{className:"opacity-60 mr-0.5",children:[V,":"]}),R,!a&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{let L=O.filter(Z=>M(Z)!==le);f.current?.(m?L:L[0]??null);},className:"hover:opacity-70 flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},le)})})};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:h,className:"relative",children:[A&&jsxRuntime.jsx("div",{className:"flex gap-1 mb-1.5",children:w.map(O=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{k(O),c([]),i("");},className:`px-2 py-0.5 text-[10px] font-bold rounded transition-colors ${T===O?"kyro-btn-primary":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:O},O))}),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:l,onChange:O=>{i(O.target.value),s(true),F(O.target.value);},onFocus:()=>s(true),placeholder:e.admin?.placeholder||`Search ${T}...`,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:p?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:p?jsxRuntime.jsx("div",{className:"p-4 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsxRuntime.jsx(_n,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:d.map(O=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>P(O),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors ${S(O)?"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:Hs(O)}),S(O)&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-sidebar-active)]",children:"\u2713"})]}),"slug"in O&&typeof O.slug=="string"&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)]",children:O.slug})]},O.id))})}),G()]}),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 Ma=Gm;var ho=Sa.createContext(null);function ad(e=[],t=[]){return vanilla.createStore((r,o)=>({blocks:[],allowedBlocks:e,dynamicCategories:t,setBlocks:a=>{let n=Vs(a||[]);r({blocks:n});},onBlocksChange:null,setOnBlocksChange:a=>r({onBlocksChange:a}),addBlock:(a,n)=>{let s=Xo(a),{blocks:l}=o(),i=[...l];n!==void 0?i.splice(n,0,s):i.push(s),r({blocks:i});let{onBlocksChange:d}=o();d&&d();},updateBlock:(a,n)=>{let{blocks:s}=o(),l=Ea(s,i=>{let d=i.findIndex(c=>c.id===a);if(d!==-1){let c=[...i];return c[d]={...c[d],...n},{newList:c,found:true}}return {newList:i,found:false}});if(l!==s){r({blocks:l});let{onBlocksChange:i}=o();i&&i();}},removeBlock:a=>{if(!a)return;let{blocks:n}=o(),s=Ea(n,l=>{let i=l.filter(d=>d.id!==a);return i.length!==l.length?{newList:i,found:true}:{newList:l,found:false}});if(s!==n){r({blocks:s});let{onBlocksChange:l}=o();l&&l();}},moveBlock:(a,n)=>{let{blocks:s}=o(),l=Ea(s,i=>{let d=i.findIndex(c=>c.id===a);if(d!==-1){let c=n==="up"?d-1:d+1;if(c>=0&&c<i.length){let p=[...i];return [p[d],p[c]]=[p[c],p[d]],{newList:p,found:true}}}return {newList:i,found:false}});if(l!==s){r({blocks:l});let{onBlocksChange:i}=o();i&&i();}}}))}function Vs(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=Vs(r.children)),r.data?.columnData&&Array.isArray(r.data.columnData)&&(r.data={...r.data,columnData:r.data.columnData.map(o=>({...o,children:o.children?Vs(o.children):o.children}))}),r}):[]}function Xo(e){let t=Xm(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 Xm(e){return {heading:{level:1,text:""},"heading-subheading":{title:"",subtitle:""},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 _e(e){let t=Sa.useContext(ho);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 l=o(s.children);if(l)return l}}}};return o(r.blocks)})}function Le(){let e=Sa.useContext(ho);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 Ea(e,t){let{newList:r,found:o}=t(e);if(o)return r;let a=false,n=e.map(s=>{let l={...s},i=false;if(s.children&&s.children.length>0){let d=Ea(s.children,t);d!==s.children&&(l.children=d,i=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 p=Ea(c.children,t);if(p!==c.children)return {...c,children:p}}return c});d.some((c,p)=>c!==s.data.columnData[p])&&(l.data={...l.data,columnData:d},i=true);}return i&&(a=true),i?l:s});return a?n:e}function Oa({open:e,onClose:t,onSelect:r,children:o}){return e?jsxRuntime.jsxs(lr,{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 nd({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 Gs=({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 wo=({id:e,type:t,label:r,children:o,className:a=""})=>{let{moveBlock:n,removeBlock:s}=Le();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 ld=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,l)=>{o(e.id,{data:{...a,[s]:l}});};return jsxRuntime.jsx(wo,{id:e.id,type:"heading",label:"Heading",children:jsxRuntime.jsx(Gs,{text:a.text||"",onChange:n,compact:true})})};var cd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,l)=>{o(e.id,{data:{...a,[s]:l}});};return jsxRuntime.jsx(wo,{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 pd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(ir,{field:{label:"Image Asset",name:"src",maxCount:1},value:s.src,onChange:i=>l("src",i)})]}),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:i=>l("alt",i.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:i=>l("caption",i.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 qs=({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(ir,{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 ud=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(qs,{src:s.src||"",title:s.title||"",onChange:l,onUploadChange:i=>l("src",i),compact:true})]})};function iu({id:e,text:t,onRemove:r}){let{attributes:o,listeners:a,setNodeRef:n,transform:s,transition:l,isDragging:i}=sortable.useSortable({id:e}),d={transform:utilities.CSS.Transform.toString(s),transition:l,zIndex:i?10:1,opacity:i?.8:1};return jsxRuntime.jsxs("div",{ref:n,style:d,className:`flex items-center gap-2 group/item p-1.5 hover:bg-[var(--kyro-surface-accent)]/50 rounded-md transition-colors ${i?"bg-[var(--kyro-surface-accent)] shadow-sm":""}`,children:[jsxRuntime.jsx("div",{...o,...a,className:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-border)] rounded flex-shrink-0",onClick:c=>c.stopPropagation(),children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsxs("span",{className:"text-sm text-[var(--kyro-text-primary)] flex-1",children:["\u2022 ",t]}),jsxRuntime.jsx("button",{type:"button",onClick:r,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"})]})}var Ua=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=Sa__default.default.useState(""),[n,s]=Sa__default.default.useState([]);Sa__default.default.useEffect(()=>{let v=n.map(b=>b.text);JSON.stringify(v)!==JSON.stringify(e)&&s(e.map((b,g)=>({id:`${b}-${g}-${Math.random().toString(36).substr(2,4)}`,text:b})));},[e]);let l=()=>{o.trim()&&(t([...e,o.trim()]),a(""));},i=v=>{v.key==="Enter"&&(v.preventDefault(),l());},d=v=>{t(e.filter((b,g)=>g!==v));},c=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}})),p=v=>{let{active:b,over:g}=v;if(!g||b.id===g.id)return;let h=n.findIndex(m=>m.id===b.id),f=n.findIndex(m=>m.id===g.id);if(h!==-1&&f!==-1){let m=[...e],[w]=m.splice(h,1);m.splice(f,0,w),t(m);}},y=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.jsx(core.DndContext,{sensors:c,collisionDetection:core.closestCenter,onDragEnd:p,children: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(sortable.SortableContext,{items:n.map(v=>v.id),strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsx("div",{className:"space-y-1",children:n.map((v,b)=>jsxRuntime.jsx(iu,{id:v.id,text:v.text,onRemove:()=>d(b)},v.id))})}),jsxRuntime.jsx("input",{type:"text",value:o,onChange:v=>a(v.target.value),onKeyDown:i,className:y,placeholder:"Type and press Enter to add..."})]})})};var yd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},l=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(Ua,{items:l,onChange:d=>{o(e.id,{data:{...s,items:d}});},compact:true})]})};var fd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(Ia,{field:{type:"code",name:"code",label:"Source Code",language:s.language||"javascript"},value:s.code||"",onChange:i=>l("code",i)}),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:i=>l("language",i.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 vd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(ir,{field:{label:"File",name:"file",maxCount:1},value:s.file,onChange:i=>l("file",i)})]})};var ei=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=Sa__default.default.useState(0),n=(p,y)=>{let v=[...e];v[p]={...v[p],title:y},t(v);},s=(p,y)=>{let v=[...e];v[p]={...v[p],content:y},t(v);},l=p=>{let y=e.filter((v,b)=>b!==p);t(y),o===p?a(null):o!==null&&o>p&&a(o-1);},i=()=>{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((p,y)=>{let v=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(v?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:p.title||`Item ${y+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),l(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"})}),v?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)]"})]})]}),v&&jsxRuntime.jsxs("div",{className:"p-2.5 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:p.title||"",onChange:b=>n(y,b.target.value),onClick:b=>b.stopPropagation(),className:c,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:p.content||"",onChange:b=>s(y,b.target.value),onClick:b=>b.stopPropagation(),className:`${c} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},y)})}),jsxRuntime.jsxs("button",{type:"button",onClick:i,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((p,y)=>{let v=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(v?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:p.title||`Item ${y+1}`}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),l(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"})}),v?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)]"})]})]}),v&&jsxRuntime.jsxs("div",{className:"p-3 bg-[var(--kyro-surface)] space-y-2",children:[jsxRuntime.jsx("input",{type:"text",value:p.title||"",onChange:b=>n(y,b.target.value),className:d,placeholder:"Item title..."}),jsxRuntime.jsx("textarea",{value:p.content||"",onChange:b=>s(y,b.target.value),className:`${d} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},y)})}),jsxRuntime.jsxs("button",{type:"button",onClick:i,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 gd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=Array.isArray(s.items)?s.items:[],i=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:["(",l.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(ei,{items:l,onChange:i,compact:true})]})};var bd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},l=i=>{o(e.id,{data:{...s,content:i}});};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:l})]})};var ti=({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",l=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:i=>a("title",i.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:i=>a("subtitle",i.target.value),className:l,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:i=>a("ctaText",i.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:i=>a("ctaUrl",i.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:i=>a("title",i.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsxRuntime.jsx("textarea",{value:t,onChange:i=>a("subtitle",i.target.value),className:l,placeholder:"Hero subheading..."}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("input",{type:"text",value:r,onChange:i=>a("ctaText",i.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:i=>a("ctaUrl",i.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 Kn({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 gu=new Set(["text","number","checkbox","select","radio","color","email","password"]);function bu(e){let t=e.fields||[];return t.length===0||t.length>4?false:t.every(r=>gu.has(r.type))}function wd({id:e,index:t,isOpen:r,setOpenIndex:o,item:a,field:n,renderField:s,onChangeItem:l,onRemove:i,disabled:d,compact:c,getItemLabel:p}){let{attributes:y,listeners:v,setNodeRef:b,transform:g,transition:h,isDragging:f}=sortable.useSortable({id:e}),m={transform:utilities.CSS.Transform.toString(g),transition:h,zIndex:f?10:1,opacity:f?.8:1};return c?jsxRuntime.jsxs("div",{ref:b,style:m,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 ${f?"bg-[var(--kyro-surface-accent)]/50":""}`,children:[jsxRuntime.jsx("div",{...y,...v,className:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-surface-accent)] rounded flex-shrink-0 mt-1",children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] pt-2.5 min-w-[18px] text-center",children:t+1}),jsxRuntime.jsx("div",{className:`flex-1 min-w-0 ${(n.fields||[]).length>=3?"flex flex-col gap-1.5":"flex items-start gap-1.5"}`,children:(n.fields||[]).map(w=>jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:s(w,a,l)},w.name))}),jsxRuntime.jsx("button",{type:"button",disabled:d,onClick:i,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"})]})})]}):jsxRuntime.jsxs("div",{ref:b,style:m,className:`border border-[var(--kyro-border)] rounded-lg overflow-hidden group bg-[var(--kyro-surface)] ${f?"border-[var(--kyro-primary)] shadow-md":""}`,children:[jsxRuntime.jsxs("div",{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.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[jsxRuntime.jsx("div",{...y,...v,className:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-border)] rounded flex-shrink-0",children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-4 h-4"})}),jsxRuntime.jsx("span",{role:"button",tabIndex:0,onClick:()=>o(r?null:t),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),o(r?null:t));},className:"text-xs font-bold tracking-widest text-[var(--kyro-text-muted)] truncate cursor-pointer flex-1 py-1 text-left",children:p(a)||`Item ${t+1}`})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("button",{type:"button",disabled:d,onClick:w=>{w.stopPropagation(),i();},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"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o(r?null:t),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",children:r?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)]"})})]})]}),r&&jsxRuntime.jsx("div",{className:"p-4 bg-[var(--kyro-surface)] space-y-4",children:(n.fields||[]).map(w=>s(w,a,l))})]})}function Gn({field:e,value:t,onChange:r,renderField:o,disabled:a}){let n=Array.isArray(t)?t:[],s=e.fields||[],l=s[0],i=l?.name||"user",d=l?.type==="relationship",[c,p]=Sa__default.default.useState(0);Sa__default.default.useEffect(()=>{let f=false,m=n.filter(w=>typeof w!="object"||w===null?(f=true,false):true).map(w=>!w.id&&!w._key?(f=true,{...w,id:Math.random().toString(36).substr(2,9)}):w);f&&r(m);},[t,r]);function y(f){for(let m of ["label","title","name"]){let w=f[m];if(w&&typeof w=="string")return w}for(let m of s){if(m.type==="text"||m.type==="textarea"){let w=f[m.name];if(w&&typeof w=="string")return w}if(m.type==="group"&&m.fields){for(let w of m.fields)if(w.type==="text"||w.type==="textarea"){let T=f[m.name]?.[w.name];if(T&&typeof T=="string")return T}}}return ""}let v=bu(e),b=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}})),g=f=>{let{active:m,over:w}=f;if(!w||m.id===w.id)return;let A=n.findIndex(k=>(k.id||k._key)===m.id),T=n.findIndex(k=>(k.id||k._key)===w.id);if(A!==-1&&T!==-1){let k=[...n],[x]=k.splice(A,1);k.splice(T,0,x),r(k);}},h=Sa__default.default.useMemo(()=>n.map(f=>f?.id||f?._key||""),[n]);return d?jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),jsxRuntime.jsx(Ma,{field:{name:i,relationTo:e.fields?.[0]?.relationTo||"",hasMany:true,label:e.fields?.[0]?.label},value:n.map(f=>f[i]).filter(Boolean),onChange:f=>{let m=(f||[]).map(w=>({[i]:w,id:Math.random().toString(36).substr(2,9)}));r(m);},disabled:a})]}):jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsx("label",{className:"kyro-form-label",children:e.label||e.name}),jsxRuntime.jsx(core.DndContext,{sensors:b,collisionDetection:core.closestCenter,onDragEnd:g,children:v?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:[jsxRuntime.jsx(sortable.SortableContext,{items:h,strategy:sortable.verticalListSortingStrategy,children:n.map((f,m)=>jsxRuntime.jsx(wd,{id:f.id||f._key||`idx-${m}`,index:m,isOpen:false,setOpenIndex:()=>{},item:f,field:e,renderField:o,onChangeItem:w=>{let A=[...n];A[m]=w,r(A);},onRemove:()=>r(n.filter((w,A)=>A!==m)),disabled:a,compact:true,getItemLabel:y},f.id||f._key||m))}),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,{id:Math.random().toString(36).substr(2,9)}]),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:[jsxRuntime.jsx(sortable.SortableContext,{items:h,strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsx("div",{className:"space-y-2",children:n.map((f,m)=>{let w=c===m;return jsxRuntime.jsx(wd,{id:f.id||f._key||`idx-${m}`,index:m,isOpen:w,setOpenIndex:p,item:f,field:e,renderField:o,onChangeItem:A=>{let T=[...n];T[m]=A,r(T);},onRemove:()=>r(n.filter((A,T)=>T!==m)),disabled:a,compact:false,getItemLabel:y},f.id||f._key||m)})})}),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:()=>{let f=Math.random().toString(36).substr(2,9);r([...n,{id:f}]),p(n.length);},children:"+ Add Item"})]})})]})}var Nd="other";function Cd(){return Nd}function Wn(e){Nd=e;}var Co=({field:e,value:t,onChange:r,error:o,disabled:a,formData:n,siblingData:s,collectionSlug:l,globalSlug:i})=>{if(e.hidden===true||e.admin?.hidden===true)return null;let d=c=>{Wn("keystroke"),r(c);};switch(e.type){case "text":case "email":case "url":return jsxRuntime.jsx(Wo,{field:e,value:t,onChange:d,error:o,disabled:a});case "textarea":return jsxRuntime.jsx(Wo,{field:{...e,variant:"textarea"},value:t,onChange:d,error:o,disabled:a});case "password":return jsxRuntime.jsx(Wo,{field:{...e,variant:"password"},value:t,onChange:d,error:o,disabled:a});case "secret":return jsxRuntime.jsx(In,{field:e,value:t,onChange:r,error:o,disabled:a});case "number":return jsxRuntime.jsx(Mn,{field:e,value:t,onChange:r,disabled:a,error:o});case "checkbox":return jsxRuntime.jsx(En,{field:e,value:t,onChange:r,disabled:a,error:o});case "select":return jsxRuntime.jsx(jn,{field:e,value:t,onChange:d,error:o,disabled:a,formData:n,siblingData:s,collectionSlug:l,globalSlug:i});case "date":return jsxRuntime.jsx($n,{field:e,value:t,onChange:r,disabled:a,error:o});case "richtext":return jsxRuntime.jsx(_o,{field:e,value:t,onChange:d,disabled:a,error:o});case "markdown":return jsxRuntime.jsx(Bs,{field:e,value:t,onChange:d,disabled:a,error:o});case "code":return jsxRuntime.jsx(Ia,{field:e,value:t,onChange:d,disabled:a,error:o});case "image":case "upload":return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsx(ir,{field:e,value:t,onChange:r,disabled:a})});case "relationship":return jsxRuntime.jsx(Ma,{field:e,value:t,onChange:r,disabled:a,error:o});case "list":return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsx(Ua,{items:Array.isArray(t)?t:[],onChange:r,compact:true})});case "array":return jsxRuntime.jsx(Gn,{field:e,value:Array.isArray(t)?t:[],onChange:r,disabled:a,renderField:(c,p,y)=>{let v=p[c.name];return jsxRuntime.jsx(Co,{field:c,value:v,onChange:b=>{y({...p,[c.name]:b});},disabled:a,error:o},c.name)}});case "blocks":return jsxRuntime.jsx(oi,{field:e,value:t,onChange:d,disabled:a,error:o});case "group":return jsxRuntime.jsx(Kn,{field:e,value:t,onChange:r,renderField:(c,p,y)=>{let v=p[c.name];return jsxRuntime.jsx(Co,{field:c,value:v,onChange:b=>{y({...p,[c.name]:b});},disabled:a,error:o,collectionSlug:l,globalSlug:i},c.name)}});case "color":return jsxRuntime.jsx(pt,{field:e,error:o,children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[jsxRuntime.jsx("input",{type:"color",value:t||"#000000",onChange:c=>r(c.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:c=>r(c.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 Zo=({block:e,blockSchema:t,onClose:r})=>{let o=_e(e.id),{updateBlock:a}=Le(),n=o?.data||e.data||{},s=o?.children||e.children||[],l=(p,y)=>{a(e.id,{data:{...n,[p]:y}});},i=p=>{a(e.id,{children:p});},d=()=>t&&Array.isArray(t.fields)?jsxRuntime.jsx("div",{className:"space-y-4 pt-2",children:t.fields.map(p=>{if(p.admin?.condition){if(typeof p.admin.condition=="function")try{let v={values:n,...n};if(!p.admin.condition(v,v))return null}catch(v){console.warn(`Condition error for field ${p.name}:`,v);}else if(typeof p.admin.condition=="object")try{let v=p.admin.condition,b=v.field,g=n[b],h=!0;if("equals"in v?h=g===v.equals:"notEquals"in v?h=g!==v.notEquals:"in"in v&&Array.isArray(v.in)&&(h=v.in.includes(g)),!h)return null}catch(v){console.warn(`Declarative condition error for field ${p.name}:`,v);}}let y=n[p.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(Co,{field:p,value:y,onChange:v=>l(p.name,v)})},p.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=Pe[e.type]||Pe.default;return jsxRuntime.jsxs(lr,{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(to,{blockId:e.id,children:s,onUpdateChildren:i})]})]}),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 xu=6,to=({blockId:e,children:t,onUpdateChildren:r,depth:o=0,maxDepth:a=xu})=>{let[n,s]=Sa.useState(false),[l,i]=Sa.useState(new Set),[d,c]=Sa.useState(null),[p,y]=Sa.useState(null),v=Sa.useContext(ho);if(!v)throw new Error("ChildBlocksTree must be used within a BlocksContext");let b=zustand.useStore(v,u=>u.dynamicCategories),g=zustand.useStore(v,u=>u.allowedBlocks),h=o<a,f=16,m=u=>{let F=Xo(u);r([...t,F]),c(F.id);},w=u=>{let F=t.filter(M=>M.id!==u);r(F);},T=(u,F)=>{let M=t.map(S=>S.id===u?{...S,children:F}:S);r(M);},k=u=>{i(F=>{let M=new Set(F);return M.has(u)?M.delete(u):M.add(u),M});},x=u=>{let F=u.children&&u.children.length>0,M=l.has(u.id);ai(u.type);let P=F,D=d===u.id,Q=g.find(G=>G.slug===u.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 ${D?"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"} ${h?"cursor-pointer":""}`,style:{marginLeft:o*f},onClick:()=>{h&&c(D?null:u.id);},children:[P?jsxRuntime.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),k(u.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:M?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"}),_t[u.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:_t[u.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:[_a(u),u.data?.text?` - ${u.data.text.slice(0,30)}`:"",u.data?.heading?` - ${u.data.heading.slice(0,30)}`:""]}),Q?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:Q.admin.description})]}),F&&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:[u.children.length," nested"]}),p===u.id?jsxRuntime.jsxs("div",{className:"flex items-center gap-1",onClick:G=>G.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{w(u.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:G=>{G.stopPropagation(),y(u.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"})})]}),D&&jsxRuntime.jsx(Zo,{block:u,onClose:()=>c(null)}),F&&M&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(Td,{parentId:u.id,children:u.children,onUpdateChildren:G=>T(u.id,G),depth:o+1,maxDepth:a})})]},u.id)};return jsxRuntime.jsxs("div",{className:"space-y-2",children:[t.length>0&&jsxRuntime.jsx("div",{className:"space-y-1",children:t.map(x)}),h&&jsxRuntime.jsxs("div",{style:{marginLeft:o*f},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(Oa,{open:n,onClose:()=>s(false),onSelect:m,children:b.map(u=>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:u.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:u.blocks.map(F=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{m(F.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:_t[F.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:F.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:F.admin?.description||""})]})]},F.slug))})]},u.title))})]}),t.length===0&&h&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*f},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*f},children:["Maximum nesting level (",a,") reached"]})]})},Td=({parentId:e,children:t,onUpdateChildren:r,depth:o,maxDepth:a})=>{let[n,s]=Sa.useState(false),[l,i]=Sa.useState(new Set),[d,c]=Sa.useState(null),[p,y]=Sa.useState(null),v=Sa.useContext(ho);if(!v)throw new Error("NestedChildBlocks must be used within a BlocksContext");let b=zustand.useStore(v,u=>u.dynamicCategories),g=zustand.useStore(v,u=>u.allowedBlocks),h=o<a,f=16,m=u=>{let F=Xo(u);r([...t,F]),c(F.id);},w=u=>{let F=t.filter(M=>M.id!==u);r(F);},T=(u,F)=>{let M=t.map(S=>S.id===u?{...S,children:F}:S);r(M);},k=u=>{i(F=>{let M=new Set(F);return M.has(u)?M.delete(u):M.add(u),M});},x=u=>{let F=u.children&&u.children.length>0,M=l.has(u.id);ai(u.type);let P=F,D=d===u.id,Q=g.find(G=>G.slug===u.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 ${D?"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"} ${h?"cursor-pointer":""}`,style:{marginLeft:o*f},onClick:()=>{h&&c(D?null:u.id);},children:[P?jsxRuntime.jsx("button",{type:"button",onClick:G=>{G.stopPropagation(),k(u.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:M?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"}),_t[u.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:_t[u.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:[_a(u),u.data?.text?` - ${u.data.text.slice(0,30)}`:"",u.data?.heading?` - ${u.data.heading.slice(0,30)}`:""]}),Q?.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:Q.admin.description})]}),F&&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:[u.children.length," nested"]}),p===u.id?jsxRuntime.jsxs("div",{className:"flex items-center gap-1",onClick:G=>G.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{w(u.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:G=>{G.stopPropagation(),y(u.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)]"})})]}),D&&jsxRuntime.jsx(Zo,{block:u,onClose:()=>c(null)}),F&&M&&jsxRuntime.jsx("div",{className:"mt-1",children:jsxRuntime.jsx(Td,{parentId:u.id,children:u.children,onUpdateChildren:G=>T(u.id,G),depth:o+1,maxDepth:a})})]},u.id)};return jsxRuntime.jsxs("div",{className:"space-y-2",children:[t.length>0&&jsxRuntime.jsx("div",{className:"space-y-1",children:t.map(x)}),h&&jsxRuntime.jsxs("div",{style:{marginLeft:o*f},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(Oa,{open:n,onClose:()=>s(false),onSelect:m,children:b.map(u=>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:u.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:u.blocks.map(F=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{m(F.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:_t[F.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:F.label}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:F.admin?.description||""})]})]},F.slug))})]},u.title))})]}),t.length===0&&h&&jsxRuntime.jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*f},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*f},children:["Maximum nesting level (",a,") reached"]})]})};var Ad=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=r?.children??e.children??[],i=(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(ti,{heading:s.title||"",subheading:s.subtitle||"",ctaText:s.ctaText||"",ctaUrl:s.ctaUrl||"",onChange:i,compact:true}),jsxRuntime.jsx(ir,{field:{label:"Background",name:"bgImage",maxCount:1},value:s.bgImage,onChange:d=>i("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 (",l.length,")"]}),jsxRuntime.jsx(to,{blockId:e.id,children:l,onUpdateChildren:d=>o(e.id,{children:d})})]})]})]})};var ni=({title:e="",description:t="",icon:r="",link:o="",linkText:a="",onChange:n,compact:s=false})=>{let 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)] 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=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:`${l} font-bold text-base`,placeholder:"Card title..."}),jsxRuntime.jsx("textarea",{value:t,onChange:d=>n("description",d.target.value),className:i,placeholder:"Card description..."}),jsxRuntime.jsx("input",{type:"text",value:r,onChange:d=>n("icon",d.target.value),className:l,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 Pd=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,l)=>{o(e.id,{data:{...a,[s]:l}});};return jsxRuntime.jsx(wo,{id:e.id,type:"card",label:"Card",children:jsxRuntime.jsx(ni,{title:a.title||"",description:a.description||"",icon:a.icon||"",link:a.link||"",linkText:a.linkText||"",onChange:n,compact:true})})};var Id=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le();r?.data??e.data??{};let l=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:["(",l.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(to,{blockId:e.id,children:l,onUpdateChildren:i=>o(e.id,{children:i})})})]})};var Va=({relationTo:e="pages",hasMany:t=false,selectedIds:r=[],selectedId:o,labelField:a="title",onChange:n,compact:s=false})=>{let[l,i]=Sa.useState(false),[d,c]=Sa.useState(""),[p,y]=Sa.useState([]),[v,b]=Sa.useState(false),[g,h]=Sa.useState([]),[f,m]=Sa.useState(true);Sa.useEffect(()=>{Te("/api/collections").then(S=>{h((S.collections||[]).map(P=>P.slug||P.name||P)),m(false);}).catch(()=>m(false));},[]);let w=(S="")=>{b(true);let P=`/api/${e}?${on(S,[a],20)}`;Te(P).then(D=>{y(D.docs||[]),b(false);}).catch(()=>b(false));};Sa.useEffect(()=>{l&&w(d);},[l,d,e,a]);let A=S=>S?.[a]||S?.title||S?.name||S?.label||S?.filename||S?.slug||S?.id||"Untitled",T=t?r:o?[o]:[],k=S=>{t?T.includes(S.id)?n("selectedIds",T.filter(P=>P!==S.id)):n("selectedIds",[...T,S.id]):(n("selectedId",S.id),n("selectedIds",[S.id]),i(false));},x=S=>T.includes(S),u=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",F=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",M=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:[!M&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:f?jsxRuntime.jsx("div",{className:F+" text-[var(--kyro-text-muted)]",children:"Loading..."}):jsxRuntime.jsxs("select",{value:e,onChange:S=>n("relationTo",S.target.value),className:F,children:[jsxRuntime.jsx("option",{value:"",children:"Select collection..."}),g.map(S=>jsxRuntime.jsx("option",{value:S,children:S},S))]})}),!s&&jsxRuntime.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:t,onChange:S=>n("hasMany",S.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:S=>{c(S.target.value),i(true);},onFocus:()=>i(true),onBlur:()=>setTimeout(()=>i(false),200),placeholder:`Search ${e}...`,className:`${u} pl-9`}),jsxRuntime.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:v&&jsxRuntime.jsx(lucideReact.LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"})})]}),l&&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:v?jsxRuntime.jsx("div",{className:"p-3 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):p.length===0?jsxRuntime.jsx(_n,{title:"No results found"}):jsxRuntime.jsx("div",{className:"py-1",children:p.map(S=>jsxRuntime.jsxs("button",{type:"button",onMouseDown:P=>P.preventDefault(),onClick:()=>k(S),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors flex items-center justify-between ${x(S.id)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxRuntime.jsx("span",{children:A(S)}),x(S.id)&&jsxRuntime.jsx("span",{children:"\u2713"})]},S.id))})})]}),T.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5",children:T.map(S=>{let P=p.find(D=>D.id===S)||{id:S};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:[A(P),jsxRuntime.jsx("button",{type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>{t?n("selectedIds",T.filter(D=>D!==S)):(n("selectedId",null),n("selectedIds",[]));},className:"hover:opacity-70",children:jsxRuntime.jsx(lucideReact.X,{className:"w-3 h-3"})})]},S)})})]})};var Ld=({block:e,index:t})=>{let r=_e(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},l=(i,d)=>{o(e.id,{data:{...s,[i]: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(Va,{relationTo:s.relationTo||"pages",hasMany:s.hasMany||false,selectedIds:Array.isArray(s.selectedIds)?s.selectedIds:[],selectedId:s.selectedId,labelField:s.labelField||"title",onChange:l,compact:true})]})};var hu={heading:ld,paragraph:cd,image:pd,video:ud,list:yd,code:fd,file:vd,accordion:gd,richtext:bd,hero:Ad,card:Pd,array:Id,relationship:Ld},Pe={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"}},_t={heading:jsxRuntime.jsx(lucideReact.Heading1,{className:`w-4 h-4 ${Pe.default.text}`}),paragraph:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Pe.default.text}`}),image:jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Pe.default.text}`}),video:jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Pe.default.text}`}),list:jsxRuntime.jsx(lucideReact.List,{className:`w-4 h-4 ${Pe.default.text}`}),code:jsxRuntime.jsx(lucideReact.Code,{className:`w-4 h-4 ${Pe.default.text}`}),file:jsxRuntime.jsx(lucideReact.File,{className:`w-4 h-4 ${Pe.default.text}`}),accordion:jsxRuntime.jsx(lucideReact.ChevronDown,{className:`w-4 h-4 ${Pe.default.text}`}),richtext:jsxRuntime.jsx(lucideReact.AlignLeft,{className:`w-4 h-4 ${Pe.default.text}`}),hero:jsxRuntime.jsx(lucideReact.Star,{className:`w-4 h-4 ${Pe.hero.text}`}),card:jsxRuntime.jsx(lucideReact.Box,{className:`w-4 h-4 ${Pe.card.text}`}),array:jsxRuntime.jsx(lucideReact.ListOrdered,{className:`w-4 h-4 ${Pe.default.text}`}),relationship:jsxRuntime.jsx(lucideReact.Link2,{className:`w-4 h-4 ${Pe.default.text}`}),featureSplit:jsxRuntime.jsx(lucideReact.Columns3,{className:`w-4 h-4 ${Pe.featureSplit.text}`}),featureGrid:jsxRuntime.jsx(lucideReact.Blocks,{className:`w-4 h-4 ${Pe.featureGrid.text}`}),ctaBanner:jsxRuntime.jsx(lucideReact.Sparkles,{className:`w-4 h-4 ${Pe.ctaBanner.text}`}),testimonials:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Pe.testimonials.text}`}),faq:jsxRuntime.jsx(lucideReact.CircleHelp,{className:`w-4 h-4 ${Pe.faq.text}`}),stats:jsxRuntime.jsx(lucideReact.Activity,{className:`w-4 h-4 ${Pe.stats.text}`}),logoCloud:jsxRuntime.jsx(lucideReact.Image,{className:`w-4 h-4 ${Pe.logoCloud.text}`}),pricing:jsxRuntime.jsx(lucideReact.Tag,{className:`w-4 h-4 ${Pe.pricing.text}`}),team:jsxRuntime.jsx(lucideReact.Users,{className:`w-4 h-4 ${Pe.team.text}`}),recentFeed:jsxRuntime.jsx(lucideReact.Database,{className:`w-4 h-4 ${Pe.recentFeed.text}`}),processSteps:jsxRuntime.jsx(lucideReact.Clock,{className:`w-4 h-4 ${Pe.processSteps.text}`}),formEmbed:jsxRuntime.jsx(lucideReact.Mail,{className:`w-4 h-4 ${Pe.formEmbed.text}`}),videoShowcase:jsxRuntime.jsx(lucideReact.Video,{className:`w-4 h-4 ${Pe.videoShowcase.text}`})};function ai(e){return hu[e]||null}function si(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 _a(e){let t=e.name;return t&&t.trim()?t.trim():si(e.type)}function Mu(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.title||e.text||e.name||e.label||""}var Eu=({block:e,index:t,blockSchema:r,editingBlockId:o,setEditingBlockId:a,onDuplicate:n,compact:s})=>{let{attributes:l,listeners:i,setNodeRef:d,transform:c,transition:p,isDragging:y}=sortable.useSortable({id:e.id}),{removeBlock:v,updateBlock:b}=Le(),g=o===e.id,[h,f]=Sa.useState(false),[m,w]=Sa.useState(false),[A,T]=Sa.useState(e.name||""),k=Sa.useRef(null);Sa.useEffect(()=>{m&&k.current&&(k.current.focus(),k.current.select());},[m]);let x=Sa.useCallback(()=>{w(false);let P=A.trim();P!==(e.name||"").trim()&&b(e.id,{name:P||""});},[A,e.name,e.id,b]),u={transform:utilities.CSS.Transform.toString(c),transition:p,zIndex:y?10:1,opacity:y?.8:1},F=_a(e),M=e.data||{},S=Mu(M,r);return s?jsxRuntime.jsxs("div",{ref:d,style:u,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 ${g?`${(Pe[e.type]||Pe.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 touch-none",...l,...i,onClick:P=>P.stopPropagation(),children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-2.5 h-2.5"})}),_t[e.type]&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-secondary)] flex-shrink-0",children:_t[e.type]}),m?jsxRuntime.jsx("input",{ref:k,value:A,onChange:P=>T(P.target.value),onBlur:x,onKeyDown:P=>{P.key==="Enter"&&x(),P.key==="Escape"&&(T(e.name||""),w(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",{className:"font-medium text-[var(--kyro-text-secondary)] truncate max-w-[120px] transition-colors",children:F}),h?jsxRuntime.jsxs("div",{className:"flex items-center gap-0.5",onClick:P=>P.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{v(e.id),f(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:()=>f(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(),T(e.name||""),w(true);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Rename",children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",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-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(),f(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"})})]})]}),g&&jsxRuntime.jsx(Zo,{block:e,blockSchema:r,onClose:()=>a(null)})]}):jsxRuntime.jsxs("div",{ref:d,style:u,className:"relative group mb-2",children:[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 ${g?`${(Pe[e.type]||Pe.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:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-surface-accent)] rounded flex-shrink-0 touch-none",...l,...i,onClick:P=>P.stopPropagation(),children:jsxRuntime.jsx(lucideReact.GripVertical,{className:"w-4 h-4"})}),_t[e.type]&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-secondary)]",children:_t[e.type]}),jsxRuntime.jsxs("div",{className:"flex-1 min-w-0",children:[m?jsxRuntime.jsx("input",{ref:k,value:A,onChange:P=>T(P.target.value),onBlur:x,onKeyDown:P=>{P.key==="Enter"&&x(),P.key==="Escape"&&(T(e.name||""),w(false));},onClick:P=>P.stopPropagation(),placeholder:si(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",{className:"text-xs font-semibold text-[var(--kyro-text-secondary)] truncate transition-colors",children:[F,S&&typeof S=="string"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-text-muted)] font-normal ml-1.5",children:["- ",S.length>40?`${S.slice(0,40)}...`:S]})]}),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"]}),h?jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5",onClick:P=>P.stopPropagation(),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>{v(e.id),f(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:()=>f(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(),T(e.name||""),w(true);},className:"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(),f(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"})})]})]}),g&&jsxRuntime.jsx(Zo,{block:e,blockSchema:r,onClose:()=>a(null)})]})},$u=Sa__default.default.memo(Eu),oi=({field:e,value:t,onChange:r,onBlocksChange:o,error:a,disabled:n,documentStatus:s,justSaved:l})=>{let[i,d]=Sa.useState(false),[c,p]=Sa.useState(false),y=Sa.useRef(null),v=e.admin?.pickerMode||"drawer",b=e.blocks||[],g=b.reduce((L,Z)=>{let fe=Z.admin?.group||"Custom Blocks";return L[fe]||(L[fe]=[]),L[fe].push(Z),L},{}),h=["Structural Sections","Marketing Grids","Lead Capture & Interactive","Dynamic Content","Basic Content Elements","Custom Blocks"],f=Object.entries(g).sort(([L],[Z])=>{let fe=h.indexOf(L),W=h.indexOf(Z);return fe!==-1&&W!==-1?fe-W:fe!==-1?-1:W!==-1?1:L.localeCompare(Z)}).map(([L,Z])=>({title:L,blocks:Z})),m=Sa.useRef(null);m.current||(m.current=ad(b,f));let w=m.current,A=zustand.useStore(w,L=>L.blocks),[T,k]=Sa.useState(null),[x,u]=Sa.useState(null),F=Sa.useRef(A.length),M=Sa.useRef(new Set(A.map(L=>L.id))),S=Sa.useRef(false);Sa.useEffect(()=>{if(S.current&&A.length>F.current){let L=A.find(Z=>Z.id&&!M.current.has(Z.id));L&&u(L.id);}F.current=A.length,M.current=new Set(A.map(L=>L.id));},[A]),Sa.useEffect(()=>(o&&w.getState().setOnBlocksChange(o),()=>{w.getState().setOnBlocksChange(()=>{});}),[o,w]);let P=Sa.useRef(null);Sa.useEffect(()=>{let L=Array.isArray(t)?t:[],Z=P.current||[];if(JSON.stringify(L)!==JSON.stringify(Z)){let fe=[...L];F.current=fe.length,M.current=new Set(fe.map(W=>W.id)),w.getState().setBlocks(fe),P.current=fe,S.current=true;}else L.length===0&&!S.current&&(S.current=true,P.current=[]);},[t,e.name,w]);let D=Sa.useRef(r);D.current=r,Sa.useEffect(()=>{if(!D.current)return;let L=P.current;L&&JSON.stringify(A)!==JSON.stringify(L)&&(P.current=[...A],D.current(A));},[A]);let G=Sa.useCallback(L=>{w.getState().addBlock(L);},[w]),O=Sa.useCallback(L=>{let Z=A.findIndex(U=>U.id===L);if(Z===-1)return;let fe=A[Z],W=U=>{let te=Math.random().toString(36).substr(2,9);return {...U,id:te,children:U.children?U.children.map(me=>W(me)):U.children,data:U.data?JSON.parse(JSON.stringify(U.data)):U.data}},be=W(fe),xe=[...A];xe.splice(Z+1,0,be),w.getState().setBlocks(xe);},[A,w]),z=core.useSensors(core.useSensor(core.PointerSensor,{activationConstraint:{distance:3}}),core.useSensor(core.TouchSensor,{activationConstraint:{delay:250,tolerance:5}}),core.useSensor(core.KeyboardSensor)),se=L=>{k(L.active);},le=L=>{let{active:Z,over:fe}=L;if(k(null),!!fe){if(Z.id.toString().startsWith("drawer-")){let W=Z.id.toString().replace("drawer-","");if(fe.id.toString().startsWith("container-")){let be=fe.id.toString().replace("container-",""),xe=A.find(U=>U.id===be);if(xe){let U=Xo(W);w.getState().updateBlock(be,{children:[...xe.children||[],U]});}}else {let be=A.findIndex(xe=>xe.id===fe.id);be!==-1?w.getState().addBlock(W,be):G(W);}return}if(Z.id!==fe.id){let W=A.findIndex(xe=>xe.id===Z.id),be=A.findIndex(xe=>xe.id===fe.id);if(W!==-1&&be!==-1){let xe=[...A],[U]=xe.splice(W,1);xe.splice(be,0,U),w.getState().setBlocks(xe);}}}},H=T?f.flatMap(L=>L.blocks).find(L=>`drawer-${L.type}`===T.id)||A.find(L=>L.id===T.id):null;H?"label"in H?H.label:H.type:"Block";return Sa.useEffect(()=>{if(!c)return;let L=Z=>{y.current&&!y.current.contains(Z.target)&&p(false);};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[c]),jsxRuntime.jsx(ho.Provider,{value:m.current,children:jsxRuntime.jsxs("div",{className:"kyro-blocks-field",children:[jsxRuntime.jsxs(core.DndContext,{sensors:z,collisionDetection:core.closestCenter,onDragStart:se,onDragEnd:le,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}),v==="dropdown"?jsxRuntime.jsxs("div",{ref:y,className:"relative",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>p(!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:f.map(L=>jsxRuntime.jsxs("div",{children:[f.length>1&&jsxRuntime.jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold tracking-wider text-[var(--kyro-text-muted)] uppercase",children:L.title}),L.blocks.map(Z=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{G(Z.slug),p(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:_t[Z.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:Z.label}),Z.admin?.description&&jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] truncate",children:Z.admin.description})]})]},Z.slug))]},L.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(Oa,{open:i,onClose:()=>d(false),onSelect:G,children:jsxRuntime.jsx("div",{className:"space-y-4",children:f.map(L=>jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] mb-2 tracking-wider",children:L.title}),jsxRuntime.jsx("div",{className:"grid grid-cols-3 gap-2",children:L.blocks.map(Z=>jsxRuntime.jsx(nd,{block:{type:Z.slug,label:Z.label,description:Z.admin?.description||"",icon:null},onSelect:G,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:_t[Z.slug]||jsxRuntime.jsx(lucideReact.Box,{className:"w-4 h-4"})})})},Z.slug))})]},L.title))})})}),jsxRuntime.jsx(sortable.SortableContext,{items:A.map(L=>L.id),strategy:sortable.verticalListSortingStrategy,children:jsxRuntime.jsxs("div",{className:v==="dropdown"?"flex flex-wrap gap-1.5":"space-y-4",children:[A.map((L,Z)=>{let fe=e.blocks?.find(W=>W.slug===L.type);return jsxRuntime.jsx($u,{block:L,index:Z,blockSchema:fe,editingBlockId:x,setEditingBlockId:u,onDuplicate:O,compact:v==="dropdown"},L.id||Z)}),A.length===0&&jsxRuntime.jsx("div",{className:v==="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:v==="dropdown"?"No elements added":"Click the button above to add your first block"})]})}),jsxRuntime.jsx(core.DragOverlay,{children:T&&H&&jsxRuntime.jsx("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-primary)] rounded-md p-3 shadow-lg",children:H.label||H.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<=25)return t.id;let n={};for(let s of r)n[s]=mr(t[s]);return n}return e}function Ed(){let e=Sa.useRef([]),t=Sa.useRef(false);return {queueTask:Sa.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(l){console.error("Error in queued function:",l);}finally{t.current=false,typeof a?.afterProcess=="function"&&a.afterProcess();}}}n();},[])}}function $d({config:e,initialData:t,collectionSlug:r,globalSlug:o,documentId:a,onChange:n,onActionSuccess:s,onActionError:l}){let i=Ae(),{confirm:d}=dt(),{formData:c,setFormData:p,setField:y,lastSavedData:v,setLastSavedData:b,setHasUnsavedChanges:g,isSlugLocked:h,loadDocument:f,setIsAutoSaving:m,setAutoSaveStatus:w,setVersions:A,setLoadingVersions:T,sidebarCollapsed:k,setSidebarCollapsed:x,getDraftCache:u,setDraftCache:F,clearDraftCache:M,resetForm:S}=i,P=!!e.versions,D=o||t?.id||a||r,Q=Sa.useRef(false);!o&&D&&c&&Object.keys(c).length>0&&c.id!==D&&(Q.current=true),Sa.useEffect(()=>{Q.current&&(Q.current=false,S());},[S]);let G=Sa.useRef(null),O=Sa.useRef(null),z=Sa.useRef(null),se=Sa.useRef(typeof navigator<"u"?navigator.onLine:true),le=Sa.useRef(0),H=Sa.useRef(false),R=Sa.useRef(null),V=Sa.useRef(""),L=Sa.useRef(""),{queueTask:Z}=Ed(),fe=Sa.useCallback(q=>o?`global:${o}`:r&&q?`${r}:${q}`:null,[r,o]),W=Sa.useCallback((q,ne,ie)=>{F(q,{data:ne,baseUpdatedAt:v.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:ie?.lastSyncedAt??null});},[v.updatedAt,F]),be=Sa.useCallback(async()=>{let q=o?qe(`/api/globals/${o}/versions`):r&&c.id?qe(`/api/${r}/${c.id}/versions`):null;if(q){T(true);try{let ie=await(await nt(q)).json();A(ie.docs||[]);}catch(ne){console.error("Failed to fetch versions:",ne);}finally{T(false);}}},[c.id,r,o,T,A]),xe=Sa.useCallback(()=>{let q=Ae.getState(),ne=q.formData;if(H.current||!r||!ne.id||!q.hasDirtyFields())return;let ie=fe(ne.id);ie&&W(ie,ne);},[r,fe,W]),U=Sa.useCallback(async q=>{let ne=Ae.getState(),ie=ne.formData,Se=ne.lastSavedData;if(H.current||!o&&(!r||!ie.id)||!ne.hasDirtyFields())return;let $e=fe(ie.id);if($e&&W($e,ie),!se.current){w("offline");return}m(true),w("saving"),ne.setBackgroundProcessing(true),o&&window.dispatchEvent(new Event("kyro:global-save-start"));try{let Ve=o?qe(`/api/globals/${o}?autosave=true`):qe(`/api/${r}/${ie.id}?autosave=true`),B=await nt(Ve,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":"true"},keepalive:q?.keepalive,body:JSON.stringify({...mr(ie),baseUpdatedAt:Se.updatedAt??null})});if(B.ok)le.current=Date.now(),ne.setRetryCount(0),ne.setLastSavedAt(Date.now()),z.current&&clearTimeout(z.current),$e&&F($e,{data:ie,baseUpdatedAt:Se.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:(await B.clone().json()).data?.updatedAt||new Date().toISOString()}),w("success"),setTimeout(()=>{Ae.getState().autoSaveStatus==="success"&&w("idle");},2e3);else if(B.status===409)w("conflict");else throw new Error(`Draft auto-save failed with status ${B.status}`)}catch(Ve){console.error("Auto-save failed:",Ve);let B=Ae.getState(),X=B.retryCount;if(X<5){B.setRetryCount(X+1),w("retrying");let de=Math.min(1e3*Math.pow(2,X),6e4);z.current&&clearTimeout(z.current),z.current=setTimeout(()=>te(q),de);}else w("offline");}finally{o&&window.dispatchEvent(new Event("kyro:global-save-end")),m(false),Ae.getState().setBackgroundProcessing(false);}},[r,fe,o,W,w,F,m,P]),te=Sa.useCallback(q=>{Z(()=>U(q),{beforeProcess:()=>true,afterProcess:()=>{}});},[U,Z]),me=Sa.useCallback(async(q,ne=true)=>{let ie=Ae.getState(),Se=q||ie.formData,$e=o?qe(`/api/globals/${o}`):qe(`/api/${r}/${Se.id}`),Ve=await nt($e,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":String(ne)},body:JSON.stringify({...mr(Se),baseUpdatedAt:ie.lastSavedData.updatedAt??null})});return Ve.status===409&&w("conflict"),Ve},[r,o,w]),Fe=Sa.useCallback(async(q=true)=>{let ne=Ae.getState(),ie=ne.formData,Se=o?qe(`/api/globals/${o}`):qe(`/api/${r}/${ie.id}`),$e=await nt(Se,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":String(q)},body:JSON.stringify({...mr(ie)})});if($e.ok){let B=(await $e.json()).data||ie;ne.setFormData({...ie,...B}),ne.setLastSavedData({...ie,...B}),w("success"),setTimeout(()=>{Ae.getState().autoSaveStatus==="success"&&w("idle");},2e3);}return $e},[r,o,w]);Sa.useEffect(()=>{let q=()=>{x(!k);};return window.addEventListener("toggle-sidebar",q),()=>window.removeEventListener("toggle-sidebar",q)},[k,x]);let Ue=Sa.useRef(null),Ie=Sa.useRef(""),rt=Sa.useRef(false);Sa.useEffect(()=>{let q=o||t?.id,ne=JSON.stringify(t);rt.current&&Ue.current===q&&Ie.current===ne||(f(t||{},t||{}),rt.current=true,Ue.current=q,Ie.current=ne);},[r,c.id,o,t,f]),Sa.useEffect(()=>{if(!r||!t?.id)return;let q=fe(t.id);if(!q||R.current===q)return;let ne=false;return (async()=>{if(!P)return;let Se=u(q);if(Se){if(JSON.stringify(Se.data)===JSON.stringify(t)){M(q);return}R.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(ne)return;let Ve={...Ae.getState().formData,...Se.data};p(Ve),s?.("Recovered autosaved draft");},onCancel:async()=>{M(q);}});}})(),()=>{ne=true;}},[M,r,d,fe,u,t,s,p,P]);function Nt(q,ne){for(let ie of q){if(ie.name===ne&&ie.admin?.autoGenerate==="title")return ie;if(ie.type==="tabs"&&"tabs"in ie)for(let Se of ie.tabs){let $e=Nt(Se.fields,ne);if($e)return $e}if((ie.type==="group"||ie.type==="collapsible")&&"fields"in ie){let Se=Nt(ie.fields,ne);if(Se)return Se}}}Sa.useEffect(()=>{let q=e.fields;if(!Nt(q,"metaTitle"))return;let ie=xo(q,c,"title"),Se=ie?String(ie):"";Se&&(!c.metaTitle||c.metaTitle===c._lastMetaTitle)&&y("metaTitle",Se);},[c,e.fields,y]),Sa.useEffect(()=>{let q=e.fields,ne=q.find($e=>$e.name==="slug"&&$e.admin?.autoGenerate);if(!ne?.admin?.autoGenerate)return;let ie=ne.admin.autoGenerate,Se=xo(q,c,ie);if(h&&Se){let $e=Ln(Se);$e!==c.slug&&y("slug",$e);}},[c,h,e.fields,y]),Sa.useEffect(()=>{if(k||!o&&(!r||!c.id)||!Ae.getState().hasDirtyFields()||Cd()!=="keystroke")return;Wn("other");let ne=JSON.stringify(c);ne!==V.current&&(G.current&&clearTimeout(G.current),G.current=setTimeout(xe,1500),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{V.current=ne,te();},8e3));},[c,k,r,o,xe,te]),Sa.useEffect(()=>{if(!o&&(!r||!c.id))return;let q=()=>{H.current||!Ae.getState().hasDirtyFields()||te({keepalive:true});},ne=()=>{document.hidden&&q();},ie=()=>{se.current=true,q();},Se=()=>{se.current=false;let $e=Ae.getState();$e.hasDirtyFields()&&$e.setAutoSaveStatus("offline");};return window.addEventListener("blur",q),window.addEventListener("pagehide",q),window.addEventListener("online",ie),window.addEventListener("offline",Se),document.addEventListener("visibilitychange",ne),()=>{window.removeEventListener("blur",q),window.removeEventListener("pagehide",q),window.removeEventListener("online",ie),window.removeEventListener("offline",Se),document.removeEventListener("visibilitychange",ne);}},[r,o,c.id,te]),Sa.useEffect(()=>{let q=JSON.stringify(c);if(q===L.current)return;L.current=q;let ne=document.getElementById("form-data");ne&&(ne.value=q),n?.(c);},[c,n]),Sa.useEffect(()=>{(o||c.id)&&be();},[c.id,o,be]);let Ct=!c.id&&!o?"draft":P&&c.status||"published",fr=(!!c.id||!!o)&&Ct==="draft";return {...i,fetchVersions:be,performAutoSave:te,saveDocument:me,forceSave:Fe,autoSaveSkipRef:H,lastAutoSaveTimeRef:le,documentStatus:Ct,hasUnpublishedChanges:fr,versionsEnabled:P}}function Ro({trigger:e,children:t,align:r="right",direction:o="up"}){let[a,n]=Sa.useState(false),s=Sa.useRef(null);return Sa.useEffect(()=>{let l=i=>{s.current&&!s.current.contains(i.target)&&n(false);};return a&&document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[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 It({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 Ga(){return jsxRuntime.jsx("div",{className:"my-1 border-t border-[var(--kyro-border)] opacity-50"})}function Ao({status:e,saveStatus:t,hasChanges:r,onPublish:o,children:a,disabled:n,direction:s="down"}){let l=e==="published"&&!r&&t!=="saving"&&t!=="error",i=n||t==="saving"||l,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)]`:l?`${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)]`,p="kyro-btn kyro-btn-md px-2 rounded-l-none border-l-[1px] border-white/20 transition-all duration-300",y=()=>t==="saving"?`${p} bg-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)]/70`:t==="saved"?`${p} bg-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-success)]`:t==="error"?`${p} bg-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-error)]`:l?`${p} bg-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] border-[var(--kyro-gray-200)]`:`${p} bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)] hover:bg-[var(--kyro-primary-hover)]`,v=()=>t==="saving"?"Publishing...":t==="saved"?"Published \u2713":t==="error"?"Retry":l?"Published":"Publish Changes";return jsxRuntime.jsxs("div",{className:"inline-flex items-center",children:[jsxRuntime.jsxs("button",{type:"button",onClick:o,disabled:i,className:`${c()} ${a?"":"rounded-r-lg border-r border-[var(--kyro-border)]"}`,children:[t==="saving"&&jsxRuntime.jsx(wr,{size:"sm",className:"inline mr-1.5"}),l&&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"})}),v()]}),a&&jsxRuntime.jsx(Ro,{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 zd=({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 _d({field:e,formData:t,onTabDataChange:r,renderField:o}){let[a,n]=Sa.useState(0),s=e.tabs||[],l=s[a]||s[0],i=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:l?.fields.map(d=>o(d,i,r))}),l?.label==="SEO Settings"&&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(zd,{title:String((typeof i.metaTitle=="object"?"":i.metaTitle)||(typeof i.title=="object"?"":i.title)||"Untitled"),description:String((typeof i.metaDescription=="object"?"":i.metaDescription)||"Please enter a description..."),slug:String((typeof t.slug=="object"?"":t.slug)||"your-slug")})]})]})}function Kd({collectionSlug:e,globalSlug:t,documentStatus:r,hasUnpublishedChanges:o,localSaveStatus:a,isDuplicating:n,handleCreateNew:s,handleDuplicate:l,handleUnpublish:i,handleDelete:d,handlePublish:c,handleSaveDraft:p,handleSchedulePublish:y,handleConflictOverride:v}){let[b,g]=Sa.useState(Date.now()),[h,f]=Sa.useState(false),m=Sa.useRef(null),{formData:w,hasUnsavedChanges:A,autoSaveStatus:T,lastSavedAt:k,retryCount:x,view:u,setView:F,showPreview:M,setShowPreview:S,setFormData:P,markSaved:D,lastSavedData:Q}=Ae(),G=!w.id;Sa.useEffect(()=>{let W=setInterval(()=>g(Date.now()),1e4);return ()=>clearInterval(W)},[]),Sa.useEffect(()=>{let W=be=>{m.current&&!m.current.contains(be.target)&&f(false);};if(h)return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[h]);let O=String(w.tabs?.title||(typeof w.title=="object"?"":w.title)||(typeof w.name=="object"?"":w.name)||"Untitled"),z=w.updatedAt?new Date(w.updatedAt).toLocaleString():"Just now",se=w.createdAt?new Date(w.createdAt).toLocaleString():"Just now",le=o?"Draft (unpublished changes)":r==="published"?"Published":"Draft",H=o?"Unpublished":r==="published"?"Published":"Draft",R=r==="published"&&!A?"bg-[var(--kyro-success)]":o?"bg-[var(--kyro-warning)]":"bg-[var(--kyro-text-muted)]",V=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",L=(W=false)=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[T==="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"})]}),W?"Saving\u2026":"Saving draft..."]}),T==="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"}),W?"Saved":k?`Saved ${Math.floor((Date.now()-k)/6e4)}m ago`:"Draft saved"]}),T==="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"})]}),W?`Retry ${x}/5`:`Retrying save (${x}/5)`]}),T==="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"})]}),W?"Offline":"Offline \u2014 cached locally"]}),T==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:W?"Failed":"Draft save failed"}),T==="conflict"&&(W?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:()=>v?.(),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"})]}))]}),Z=()=>!G&&jsxRuntime.jsxs(Ro,{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:[jsxRuntime.jsxs(It,{onClick:p,icon:jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsxRuntime.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),jsxRuntime.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),jsxRuntime.jsx("polyline",{points:"7 3 7 8 15 8"})]}),children:["Save Draft",jsxRuntime.jsx("span",{className:"ml-auto text-[9px] opacity-40 font-mono",children:"\u2318S"})]}),!t&&jsxRuntime.jsx(It,{onClick:s,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(It,{onClick:l,disabled:n,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:n?"Duplicating...":"Duplicate"}),jsxRuntime.jsx(It,{onClick:()=>f(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(It,{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(Ga,{}),jsxRuntime.jsx(It,{onClick:d,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"})]})]}),fe=()=>h&&jsxRuntime.jsx("div",{ref:m,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:()=>f(false),className:"px-3 py-1.5 text-xs kyro-btn rounded-lg",children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{let W=document.getElementById("schedule-datetime")?.value;W&&y(W);},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:`${ze}/${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:O}),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 ${V}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${R}`}),H]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[jsxRuntime.jsx(Ao,{status:r,saveStatus:a,hasChanges:A,onPublish:c,disabled:a==="saving"}),Z(),fe()]})]}),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(W=>jsxRuntime.jsx("button",{type:"button",onClick:()=>F(W),className:`px-3 py-1 text-[10px] font-bold rounded-md transition-all ${u===W?"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:W==="edit"?"Edit":W==="version"?"History":"API"},W))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-medium",children:[L(true),A&&T!=="saving"&&T!=="retrying"&&T!=="conflict"&&jsxRuntime.jsx("button",{type:"button",onClick:()=>{P(Q),D();},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:()=>S(!M),className:`p-1.5 rounded-lg transition-all ${M?"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)] z-50 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:`${ze}/${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:O}),jsxRuntime.jsxs("span",{className:`shrink-0 inline-flex items-center gap-1.5 px-2 rounded-full text-[10px] font-regular border ${V}`,children:[jsxRuntime.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${R}`}),le]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-4 text-[11px] font-medium tracking-wide opacity-60 ml-12",children:[L(false),A&&T!=="saving"&&T!=="retrying"&&T!=="conflict"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"opacity-30",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{P(Q),D();},className:"text-[var(--kyro-primary)] hover:underline",children:"Revert changes"})]}),k&&T!=="saving"&&T!=="retrying"&&T!=="success"&&jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Draft saved ",(()=>{let W=b-k,be=Math.floor(W/6e4),xe=Math.floor(W/1e3);return be>=1?`${be}m ago`:xe>=5?`${xe}s ago`:"just now"})()]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Modified ",z]}),jsxRuntime.jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Created ",se]})]})]}),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(W=>jsxRuntime.jsx("button",{type:"button",onClick:()=>F(W),className:`px-5 py-2 text-xs font-bold rounded-lg transition-all ${u===W?"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:W.toUpperCase()},W))}),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:()=>S(!M),className:`kyro-btn p-2.5 rounded-xl transition-all flex items-center gap-2 ${M?"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"}),M&&jsxRuntime.jsx("span",{className:"text-[10px] font-bold tracking-widest pr-1",children:"Active"})]}),Z(),fe(),jsxRuntime.jsx(Ao,{status:r,saveStatus:a,hasChanges:A,onPublish:c,disabled:a==="saving"})]})]})]})]})}function Gd({config:e,layout:t,collectionSlug:r,renderField:o}){let{showPreview:a,sidebarCollapsed:n,formData:s}=Ae();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 i=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||!i?"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 Wd({handleRestoreVersion:e,handleCompareVersions:t,toggleCompareSelection:r}){let{compareMode:o,setCompareMode:a,compareSelected:n,setCompareSelected:s,compareDiffs:l,setCompareDiffs:i,loadingDiffs:d,loadingVersions:c,versions:p}=Ae();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`:`${p.length} snapshot${p.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([]),i([]);},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"})]})]}),l.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:[l.length," change",l.length!==1?"s":""]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>i([]),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:l.map((y,v)=>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")]})]},v))})]}),c?jsxRuntime.jsx("div",{className:"flex justify-center py-16",children:jsxRuntime.jsx("span",{className:"animate-spin text-[var(--kyro-primary)]",children:"\u231B"})}):p.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:p.map((y,v)=>{let b=n.includes(y.id),g=(y.changeDescription||"").toLowerCase().includes("auto");return jsxRuntime.jsxs("div",{onClick:o?()=>r(y.id):void 0,className:`transition-all ${o?b?"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 ${b?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:b&&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:p.length-v})}),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",g&&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||y.created_at).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 ${b?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:b&&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:p.length-v})}),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",g&&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||y.created_at).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 qd({collectionSlug:e,globalSlug:t}){let{formData:r}=Ae();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 es=class extends Sa.Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t}}componentDidCatch(t,r){console.error("[ErrorBoundary] Caught:",t,r),this.setState({errorInfo:r.componentStack||null});}handleCopyToClipboard=()=>{let{error:t,errorInfo:r}=this.state,o=Ae.getState().formData,a={error:t?.message,stack:t?.stack,componentStack:r,formData:o,timestamp:new Date().toISOString()};navigator.clipboard.writeText(JSON.stringify(a,null,2)).then(()=>{$.success("Crash details copied to clipboard");});};handleReload=()=>{window.location.reload();};render(){return this.state.hasError?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-16",children:[jsxRuntime.jsx("div",{className:"w-16 h-16 rounded-2xl bg-red-500/10 flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-8 h-8 text-red-500"})}),jsxRuntime.jsx("h3",{className:"text-lg font-bold text-[var(--kyro-text-primary)]",children:this.props.fallbackTitle||"Something went wrong"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] text-center max-w-md",children:"The form encountered an unexpected error. Your unsaved changes may still be recoverable."}),this.state.error&&jsxRuntime.jsx("p",{className:"text-xs font-mono text-red-500/70 bg-red-500/5 px-4 py-2 rounded-lg max-w-full overflow-auto",children:this.state.error.message}),jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[jsxRuntime.jsxs("button",{type:"button",onClick:this.handleReload,className:"flex items-center gap-2 px-4 py-2 text-sm font-bold rounded-xl border border-[var(--kyro-border)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"w-4 h-4"}),"Reload Page"]}),jsxRuntime.jsxs("button",{type:"button",onClick:this.handleCopyToClipboard,className:"flex items-center gap-2 px-4 py-2 text-sm font-bold rounded-xl bg-[var(--kyro-primary)]/10 text-[var(--kyro-primary)] hover:bg-[var(--kyro-primary)]/20 transition-colors",children:[jsxRuntime.jsx(lucideReact.Copy,{className:"w-4 h-4"}),"Copy Details"]})]})]}):this.props.children}};var Jd={};function qa({config:e,data:t=Jd,errors:r=Jd,onChange:o,disabled:a,collectionSlug:n,globalSlug:s,documentId:l,documentName:i,layout:d="split",onActionSuccess:c,onActionError:p,justSaved:y}){let v=e||(s?rd[s]:n?qo[n]:null),[b,g]=Sa.useState(v);Sa.useEffect(()=>{s==="storage-settings"?Te("/api/kyro/schema").then(I=>{I?.globals?.["storage-settings"]&&g(I.globals["storage-settings"]);}).catch(I=>console.error("[AutoForm] Failed to fetch dynamic schema",I)):g(v);},[s,v]);let h=b||v,{confirm:f}=dt(),{formData:m,hasUnsavedChanges:A,autoSaveStatus:x,lastSavedAt:u,view:O,setView:z,setShowPreview:L,isMenuOpen:Z,setIsMenuOpen:fe,loadingFields:W,setLoadingFields:be,compareSelected:te,setCompareSelected:me,setCompareDiffs:Ue,setLoadingDiffs:rt,setField:Nt,setFormData:Ct,setLastSavedData:q,setAutoSaveStatus:ne,fetchVersions:ie,saveDocument:Se,forceSave:$e,autoSaveSkipRef:Ve,lastAutoSaveTimeRef:B,documentStatus:X,hasUnpublishedChanges:de,versionsEnabled:vr}=$d({config:h,initialData:t,collectionSlug:n,globalSlug:s,documentId:l,onChange:o,onActionSuccess:c,onActionError:p}),yo=Sa.useRef(null),ya=Sa.useRef(null),[Xa,Ya]=Sa.useState(false),[C,ee]=Sa.useState("idle"),[Be,Mt]=Sa.useState(false),[Et,gr]=Sa.useState(Date.now()),ls=a,[ds,Qa]=Sa.useState(false),[zc,cs]=Sa.useState(false),[jc,_c]=Sa.useState(0),bi=Sa.useRef(new Map),Hc=3e4;Sa.useEffect(()=>{let I=s?`global:${s}`:`${n}:${l}`;if(!(s||n&&l&&l!=="new")||t&&Object.keys(t).length>0)return;let he=bi.current.get(I),Ee=he&&Date.now()-he.ts<Hc,xt=he&&!Ee;if(Ee){Ae.getState().loadDocument(he.data,he.data);return}xt&&Ae.getState().loadDocument(he.data,he.data);let At=new AbortController;cs(false),he||Qa(true);let Fr=s?`/api/globals/${s}`:`/api/${n}/${l}`;return Te(Fr,{autoToast:false,signal:At.signal}).then(ut=>{let fo=ut.data||{};bi.current.set(I,{data:fo,ts:Date.now()}),Ae.getState().loadDocument(fo,fo),Qa(false);}).catch(ut=>{ut.name!=="AbortError"&&(Qa(false),he||cs(true));}),()=>At.abort()},[n,l,s,t,jc]),Sa.useEffect(()=>{let I=setInterval(()=>gr(Date.now()),1e4);return ()=>clearInterval(I)},[]);let xi=(I,J)=>{if(typeof I=="function")try{return I(m,J)}catch(he){return console.warn("Error evaluating admin runtime flag:",he),false}return !!I},Vc=I=>{f({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/${I}/restore`):qe(`/api/${n}/${m.id}/versions/${I}/restore`),he=await nt(J,{method:"POST"});!he.ok&&n&&(he=await nt(qe(`/api/${n}/${m.id}/versions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({versionId:I,action:"restore"})}));let Ee=await he.json();if(Ee.data){let{updatedAt:xt,createdAt:At,...Fr}=Ee.data,ut={...m,...Fr};Ct(ut),Ae.getState().loadDocument(ut,ut),c?.("Version restored successfully"),ie(),z("edit");}else $.error(Ee.error||"Failed to restore version");}catch(J){console.error("Failed to restore version:",J),$.error("Failed to restore version");}}});},Kc=async()=>{if(te.length===2){rt(true);try{let J=await(await nt(qe(`/api/${n}/${m.id}/versions?compareA=${te[0]}&compareB=${te[1]}`))).json();Ue(J.diffs||[]);}catch(I){console.error("Compare failed:",I),Ue([]);}finally{rt(false);}}},Gc=I=>{me(J=>J.includes(I)?J.filter(he=>he!==I):J.length>=2?[J[1],I]:[...J,I]);};Sa.useEffect(()=>{let I=J=>{(J.metaKey||J.ctrlKey)&&J.key==="s"&&(J.preventDefault(),Za()),(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(),L(he=>!he)),document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA"&&(J.key==="1"&&z("edit"),J.key==="2"&&z("version"),J.key==="3"&&z("api"));};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[]),Sa.useEffect(()=>{let I=()=>z("version");return window.addEventListener("kyro:show-version-history",I),()=>window.removeEventListener("kyro:show-version-history",I)},[]),Sa.useEffect(()=>{let I=J=>{yo.current&&!yo.current.contains(J.target)&&fe(false);};if(Z)return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[Z]),Sa.useEffect(()=>{let I=J=>{ya.current&&!ya.current.contains(J.target)&&Ya(false);};if(Xa)return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[Xa]);let Wc=()=>{A?f({title:"Unsaved Changes",message:"You have unsaved changes. Save before creating new?",onConfirm:async()=>{await Za(),await new Promise(I=>setTimeout(I,1e3)),window.location.href=`${ze}/${n}/new`;}}):window.location.href=`${ze}/${n}/new`;},qc=()=>{if(!m.id){$.error("Please save the document before duplicating.");return}let I=async()=>{try{Mt(!0);let J=await nt(`/api/${n}/${m.id}/duplicate`,{method:"POST"});if(J.ok){let he=await J.json();c?.("Document duplicated successfully"),he.data?.id?window.location.href=`${ze}/${n}/${he.data.id}`:window.location.href=`${ze}/${n}`;}else {let he=await J.json();$.error(he.error||"Failed to duplicate");}}catch{$.error("Failed to duplicate document");}finally{Mt(false);}};if(A){f({title:"Unsaved Changes",message:"You have unsaved changes. Please save the document before duplicating.",onConfirm:async()=>{await Za(),await I();}});return}f({title:"Duplicate Document",message:"Are you sure you want to duplicate this document?",onConfirm:async()=>{await I();}});},Jc=()=>{f({title:"Delete Document",message:"Delete this document? This cannot be undone. Are you absolutely sure?",variant:"danger",onConfirm:async()=>{Ve.current=true;try{await kt(`/api/${n}/${m.id}`),window.location.href=`${ze}/${n}`;}catch(I){$.error(I.message||"Failed to delete document");}finally{Ve.current=false;}}});},Xc=()=>{f({title:"Unpublish Document",message:"Unpublish this document?",onConfirm:async()=>{Ve.current=true;try{let I=await Se({...m,status:"draft"},!1);if(I?.ok)c?.("Document unpublished successfully"),Ae.getState().loadDocument({...m,status:"draft"},{...m,status:"draft"});else {let J=await I?.json().catch(()=>({}));$.error(J?.error||"Failed to unpublish");}}catch{$.error("Failed to unpublish");}finally{Ve.current=false;}}});},Za=async()=>{let I=!m.id;Ve.current=true,ee("saving");try{let J=mr({...m}),he=I&&!s,Ee=he?await nt(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J)}):await Se(J);if(Ee.ok){let xt=await Ee.json(),At=xt.data||J;Ct({...m,...At}),q({...m,...At}),B.current=Date.now(),ne("success"),ee("saved"),vr&&ie(),setTimeout(()=>{ne("idle"),ee("idle");},2e3),c?.(he?"Document created successfully":"Changes saved"),he&&setTimeout(()=>{window.location.href=`${ze}/${n}/${xt.data.id}`;},800);}else {let xt=await Ee.json();Ee.status===409&&ne("conflict"),ee("error"),$.error(xt.error||"Failed to save"),setTimeout(()=>ee("idle"),3e3);}}catch{ee("error"),$.error("Failed to save document"),setTimeout(()=>ee("idle"),3e3);}finally{window.dispatchEvent(new CustomEvent("kyro:global-save-end")),Ve.current=false;}},Yc=async()=>{let I=!m.id;Ve.current=true,ee("saving");try{let J={...m};if(I&&!s){let xt=mr({...m}),At=await nt(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(xt)});if(!At.ok){let fo=await At.json().catch(()=>({}));At.status===409&&ne("conflict"),ee("error"),$.error(fo.error||"Failed to create document"),setTimeout(()=>ee("idle"),3e3);return}let ut=(await At.json()).data||xt;Ct({...m,...ut}),q({...m,...ut}),J={...m,...ut};}let he=mr(J),Ee=await Se(he,!1);if(Ee?.ok)ee("saved"),c?.("Published successfully"),I&&!s&&J.id&&setTimeout(()=>{window.location.href=`${ze}/${n}/${J.id}`;},800);else {if(I&&!s&&J.id){let At=await Ee?.json().catch(()=>({}));$.warning("Document saved as draft. Publishing failed: "+(At?.error||"Unknown error")),setTimeout(()=>{window.location.href=`${ze}/${n}/${J.id}`;},1200);return}let xt=await Ee?.json().catch(()=>({}));Ee?.status===409&&ne("conflict"),ee("error"),$.error(xt?.error||"Failed to publish"),setTimeout(()=>ee("idle"),3e3);}}catch{ee("error"),$.error("Failed to publish"),setTimeout(()=>ee("idle"),3e3);}finally{Ve.current=false;}},Qc=async I=>{let J=!m.id;Ve.current=true;try{let he={...mr({...m}),_schedulePublishAt:I};if(J&&!s){let Ee=await nt(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(he)});if(!Ee.ok){let xt=await Ee.json().catch(()=>({}));$.error(xt.error||"Failed to schedule publish");return}}else {let Ee=await Se(he);if(!Ee.ok){let xt=await Ee.json().catch(()=>({}));$.error(xt.error||"Failed to schedule publish");return}}c?.(`Scheduled publish for ${new Date(I).toLocaleString()}`),Ya(!1);}catch{$.error("Failed to schedule publish");}finally{Ve.current=false;}},Zc=(I,J)=>{Nt(I,J);},fa=(I,J,he)=>{let Ee=J!==void 0?J:m;if(xi(I.hidden!==void 0?I.hidden:I.admin?.hidden,Ee))return null;let At=xi(I.readOnly!==void 0?I.readOnly:I.admin?.readOnly,Ee),Fr=!!(ls||At);if(I.admin?.condition){if(typeof I.admin.condition=="function")try{let Oe={values:m||{},...m||{}};if(!I.admin.condition(Oe,Ee))return null}catch(Oe){console.warn(`Condition error for field ${I.name}:`,Oe);}else if(typeof I.admin.condition=="object")try{let Oe=I.admin.condition,Ke=Oe.field,Vt=Ee&&Ee[Ke]!==void 0?Ee[Ke]:m&&m[Ke]!==void 0?m[Ke]:void 0,Pr=!0;if("equals"in Oe?Pr=Vt===Oe.equals:"notEquals"in Oe?Pr=Vt!==Oe.notEquals:"in"in Oe&&Array.isArray(Oe.in)&&(Pr=Oe.in.includes(Vt)),!Pr)return null}catch(Oe){console.warn(`Declarative condition error for field ${I.name}:`,Oe);}}let ut=Ee[I.name],fo=r[I.name],en=Oe=>{he?he({...Ee,[I.name]:Oe}):Zc(I.name,Oe);};if(I.type==="row"&&"fields"in I){let Oe=I.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:Oe?.map(Ke=>{let Vt=Ke.admin||{},Pr=Vt?.action;if((Ke.type==="button"||Ke.type==="action")&&Pr){let br=Oe?.find(va=>va.type==="email");return jsxRuntime.jsx("div",{className:"flex-shrink-0",children:jsxRuntime.jsx("button",{type:"button",onClick:async()=>{let va=I.name,tn=br?.name,rn=tn?m[tn]:void 0;if(!rn&&va&&typeof va=="string"&&tn&&(rn=m[va]?.[tn]),!!rn){be(xr=>({...xr,[Ke.name]:true}));try{let xr=await nt(qe(Pr),{method:Vt.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:rn})}),ga={};try{ga=await xr.json();}catch{ga={};}if(xr.ok&&ga.success)c?.(ga.message||"Action completed successfully");else {let ep=ga.error||`Request failed (${xr.status})`;p?.(ep);}}catch(xr){p?.(xr instanceof Error?xr.message:"Error connecting to server");}finally{be(xr=>({...xr,[Ke.name]:false}));}}},disabled:W[Ke.name]||Fr,className:"kyro-btn kyro-btn-primary px-4 py-2 rounded-lg font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:W[Ke.name]?"Sending...":Ke.label||"Click"})},Ke.name)}return jsxRuntime.jsx("div",{className:Ke.type==="button"||Ke.type==="action"?"flex-shrink-0":"flex-1",style:Vt?.width?{width:Vt.width,flex:"none"}:{},children:fa(Ke,J,he)},Ke.name)})},I.name||`row-${Math.random()}`)}switch(I.type){case "tabs":return jsxRuntime.jsx(_d,{field:I,formData:m,onTabDataChange:Oe=>{Nt(I.name,Oe);},renderField:(Oe,Ke,Vt)=>fa(Oe,Ke,Vt)},I.name||`tabs-${Math.random()}`);case "group":return jsxRuntime.jsx(Kn,{field:I,value:ut,onChange:en,renderField:fa},I.name);case "array":return jsxRuntime.jsx(Gn,{field:I,value:ut,onChange:en,renderField:fa,disabled:Fr},I.name);case "button":case "action":{let Oe=I.name,Ke=W[Oe];return jsxRuntime.jsx("div",{className:"kyro-form-field",children:jsxRuntime.jsxs("button",{type:"button",disabled:Ke||Fr,onClick:async()=>{let Vt=I.admin?.action||I.action,Pr=I.admin?.method||I.method||"POST";if(Vt){be(br=>({...br,[Oe]:true}));try{let br=await nt(Vt,{method:Pr,headers:{"Content-Type":"application/json"},body:JSON.stringify(m)});await br.json(),br.ok;}catch(br){console.error("Error executing action:",br);}finally{be(br=>({...br,[Oe]:false}));}}},className:`kyro-btn kyro-btn-md kyro-btn-secondary transition-all active:scale-95 whitespace-nowrap flex items-center gap-2 ${Ke?"opacity-70 cursor-not-allowed":""}`,children:[Ke&&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"})]}),Ke?"Processing...":I.label||"Click"]})},Oe)}case "relationship-block":return jsxRuntime.jsxs("div",{className:"kyro-form-field",children:[jsxRuntime.jsxs("label",{className:"kyro-form-label",children:[I.label||I.name,I.required&&jsxRuntime.jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxRuntime.jsx(Va,{relationTo:I.relationTo,hasMany:I.hasMany,selectedIds:Array.isArray(ut)?ut:ut?[ut]:[],onChange:(Oe,Ke)=>{en(Ke);},compact:true}),I.admin?.description?jsxRuntime.jsx("p",{className:"kyro-form-help",children:String(I.admin?.description)}):null]},I.name);default:return jsxRuntime.jsx(Co,{field:I,value:ut,onChange:en,error:fo,disabled:Fr,formData:m,siblingData:Ee,collectionSlug:n,globalSlug:s},I.name||Math.random().toString())}};return ds?jsxRuntime.jsxs("div",{className:"space-y-6 p-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(Ut,{variant:"text",className:"w-1/3"}),jsxRuntime.jsx(Ut,{variant:"text",className:"w-2/3"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Ut,{variant:"rect",count:4})})]}):zc?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:()=>{cs(false),Qa(true),_c(I=>I+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(Kd,{collectionSlug:n,globalSlug:s,documentStatus:X||"draft",hasUnpublishedChanges:de,localSaveStatus:C,isDuplicating:Be,handleCreateNew:Wc,handleDuplicate:qc,handleUnpublish:Xc,handleDelete:Jc,handlePublish:Yc,handleSaveDraft:Za,handleSchedulePublish:Qc,handleConflictOverride:()=>$e()}),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:[x==="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..."]}),x==="success"&&jsxRuntime.jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsxRuntime.jsx(lucideReact.Check,{className:"w-4 h-4"}),u?`Saved ${Math.floor((Date.now()-u)/6e4)}m ago`:"Saved"]}),x==="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..."]}),x==="offline"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-text-muted)]",children:"Offline \u2014 cached locally"}),x==="error"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Save failed"}),x==="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-danger)]",children:"Conflict detected"}),A&&x!=="saving"&&x!=="retrying"&&x!=="conflict"&&jsxRuntime.jsx("span",{className:"text-[var(--kyro-warning)]",children:"Unsaved changes"}),!A&&x!=="success"&&x!=="saving"&&x!=="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:m.updatedAt?`Modified ${new Date(m.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()=>{Ve.current=true;try{window.dispatchEvent(new Event("kyro:global-save-start"));let I=await Se(m);if(I.ok){let he=(await I.json()).data||m;Ct({...m,...he}),q({...m,...he}),c?.("Changes saved");}}catch(I){console.error("Save error exception:",I),p?.("Save failed: "+I.message);}finally{Ve.current=false,window.dispatchEvent(new Event("kyro:global-save-end"));}}})]}),jsxRuntime.jsx("main",{className:"w-full pt-6 md:pt-0",children:jsxRuntime.jsxs(es,{children:[O==="edit"&&jsxRuntime.jsx(Gd,{config:h,layout:d,collectionSlug:n,renderField:fa}),O==="version"&&jsxRuntime.jsx(Wd,{handleRestoreVersion:Vc,handleCompareVersions:Kc,toggleCompareSelection:Gc}),O==="api"&&jsxRuntime.jsx(qd,{collectionSlug:n,globalSlug:s})]})})]})}var Xd={draft:"bg-[var(--kyro-warning)]",published:"bg-[var(--kyro-success)]",scheduled:"bg-[var(--kyro-primary)]",archived:"bg-[var(--kyro-text-muted)]"};function ci({status:e,saveStatus:t,hasChanges:r,onSave:o,onPublish:a,onUnpublish:n,onDuplicate:s,onViewHistory:l,onPreview:i,onDelete:d,onBack:c,onToggleSidebar:p,publishedAt:y,updatedAt:v}){let b=Ae(x=>x.view)||"edit",g=Ae(x=>x.setView),[h,f]=Sa.useState(false),m=Sa.useRef(null);Sa.useEffect(()=>{let x=u=>{m.current&&!m.current.contains(u.target)&&f(false);};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]);let w=()=>t==="saving"?"Saving...":t==="saved"?"Saved":t==="error"?"Error saving":r?"Unsaved":null,A=["edit","version","api"],T=w(),k="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 ${Xd[e]||"bg-[var(--kyro-text-muted)]"}`}),T&&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(wr,{size:"sm",className:"inline mr-0.5"}),T]}),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:A.map(x=>jsxRuntime.jsx("button",{type:"button",onClick:()=>g(x),className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all ${b===x?"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:x==="edit"?"Edit":x==="version"?"Ver":"API"},x))}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1 ml-auto shrink-0",children:[i&&jsxRuntime.jsx("button",{type:"button",onClick:i,className:`${k} max-md:hidden`,title:"Preview",children:jsxRuntime.jsx(lucideReact.Eye,{className:"w-3.5 h-3.5"})}),l&&jsxRuntime.jsx("button",{type:"button",onClick:l,className:`${k} 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:`${k} 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:`${k} 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"})}),p&&jsxRuntime.jsx("button",{type:"button",onClick:p,className:`${k} 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:m,className:"relative md:hidden",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>f(!h),className:k,title:"More",children:jsxRuntime.jsx(lucideReact.EllipsisVertical,{className:"w-3.5 h-3.5"})}),h&&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:[T&&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 ${Xd[e]}`}),jsxRuntime.jsx("span",{className:"capitalize",children:e}),jsxRuntime.jsx("span",{children:"\xB7"}),t==="saving"&&jsxRuntime.jsx(wr,{size:"sm",className:"inline"}),jsxRuntime.jsx("span",{children:T})]}),jsxRuntime.jsx("div",{className:"flex gap-1 px-2 py-2 border-b border-[var(--kyro-border)]",children:A.map(x=>jsxRuntime.jsx("button",{type:"button",onClick:()=>{g(x),f(false);},className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all flex-1 ${b===x?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)]"}`,children:x==="edit"?"Edit":x==="version"?"Ver":"API"},x))}),l&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{l(),f(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(),f(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"]}),i&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{i(),f(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(),f(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(Ao,{status:e,saveStatus:t,hasChanges:r,onPublish:o,children:[s&&jsxRuntime.jsx(It,{icon:jsxRuntime.jsx(lucideReact.Copy,{className:"w-4 h-4"}),children:"Duplicate"}),l&&jsxRuntime.jsx(It,{icon:jsxRuntime.jsx(lucideReact.Clock,{className:"w-4 h-4"}),children:"View History"}),i&&jsxRuntime.jsx(It,{icon:jsxRuntime.jsx(lucideReact.Eye,{className:"w-4 h-4"}),children:"Preview"}),(s||l||i)&&jsxRuntime.jsx(Ga,{}),d&&jsxRuntime.jsx(It,{onClick:d,danger:true,icon:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-4 h-4"}),children:"Delete"})]})]})]})}function mi({config:e,collection:t,global:r,documentId:o,onBack:a,onSave:n,onDelete:s,onError:l,mode:i="collection"}){let{confirm:d,alert:c}=dt(),[p,y]=Sa.useState({}),[v,b]=Sa.useState({}),[g,h]=Sa.useState(true),[f,m]=Sa.useState(false),[w,A]=Sa.useState(false),[T,k]=Sa.useState(false),[x,u]=Sa.useState("idle"),[F,M]=Sa.useState("draft"),[S,P]=Sa.useState(null),[D,Q]=Sa.useState(null),[G,O]=Sa.useState(null),[z,se]=Sa.useState(false),le=r?.fields||t?.fields||[],H=r?.label||t?.label||"Document",R=r?.slug||t?.slug||"",V=JSON.stringify(p)!==JSON.stringify(v);Sa.useEffect(()=>{V&&F==="published"&&M("draft");},[V,F]),Sa.useEffect(()=>{V&&x==="saved"&&u("idle");},[V,x]),Sa.useEffect(()=>{i==="global"?Z():o&&L();},[o,i,R]);let L=async()=>{try{h(!0);let me=await Te(`/api/${R}/${o}`,{autoToast:!1}),Fe=me.data||{};y(Fe),b(Fe),M(Fe?.status||me.status||"draft"),P(me.createdAt||Fe.createdAt||null),Q(me.updatedAt||Fe.updatedAt||null),O(me.publishedAt||Fe.publishedAt||null);}catch{l("Failed to load document");}finally{h(false);}},Z=async()=>{try{h(!0);let me=await Te(`/api/globals/${R}`,{autoToast:!1}),Fe=me.data||{};y(Fe),b(Fe),P(me.createdAt||null),Q(me.updatedAt||null);}catch{l("Failed to load global");}finally{h(false);}},fe=Sa.useCallback(async(me=false)=>{try{u("saving");let Fe=i==="global"?`/api/globals/${R}`:`/api/${R}/${o}`,Ue=F==="draft"||p?.status==="draft",Ie=await Gt(Fe,p,{autoToast:!1,headers:{"X-Draft":String(Ue)}}),rt=Ie&&(Ie.data||Ie)||p;me||(b(rt),n()),y(rt),M(rt?.status||F),u("saved"),Q(new Date().toISOString()),se(!0),setTimeout(()=>se(!1),3e3),me||(F==="draft"||rt?.status==="draft"?$.warning("Draft saved"):$.success("Updated")),setTimeout(()=>{u("idle");},2e3);}catch{u("error"),me||(l("Failed to save changes"),$.error("Failed to save changes"));}finally{m(false);}},[p,i,R,o,F,n,l]),W=async()=>{try{m(!0),await Gt(`/api/${R}/${o}`,p,{autoToast:!1,headers:{"X-Draft":"false"}}),M("published"),O(new Date().toISOString()),$.success("Published successfully"),n();}catch{l("Failed to publish"),$.error("Failed to publish");}finally{m(false);}},be=async()=>{try{m(!0),await Gt(`/api/${R}/${o}`,{status:"draft"},{autoToast:!1,headers:{"X-Draft":"false"}}),M("draft"),$.warning("Document unpublished"),n();}catch{l("Failed to unpublish"),$.error("Failed to unpublish");}finally{m(false);}},xe=async()=>{try{A(!0);let me=await st(`/api/${R}/${o}/duplicate`,void 0,{autoToast:!1});$.success("Document duplicated"),me?.data?.id?window.location.href=`${ze}/${R}/${me.data.id}`:window.location.href=`${ze}/${R}`;}catch(me){$.error(me.message||"Failed to duplicate document");}finally{A(false);}},U=()=>{d({title:`Delete ${H}?`,message:"This action cannot be undone.",variant:"danger",onConfirm:async()=>{try{k(!0),await kt(`/api/${R}/${o}`),window.location.href=`${ze}/${R}`;}catch{k(false);}}});};if(g)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(Ut,{variant:"text",className:"w-1/3"}),jsxRuntime.jsx(Ut,{variant:"text",className:"w-2/3"})]}),jsxRuntime.jsx("div",{className:"space-y-4",children:jsxRuntime.jsx(Ut,{variant:"rect",count:4})})]})});let te=i==="global"||t?.admin?.layout==="single";return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Ft,{back:{onClick:a},breadcrumbs:[{label:i==="global"?"Globals":"Collections"},{label:H,href:i==="collection"?`${ze}/${R}`:void 0},{label:i==="global"||o?"Edit":"New"}],title:i==="global"?H:xo(t?.fields,p,t?.admin?.useAsTitle||"title")||p.name||o||`New ${t?.singularLabel||H}`,metadata:[jsxRuntime.jsx(St,{variant:F==="published"?"success":"warning",dot:true,className:"text-[10px] font-bold ",children:F},"status")]}),jsxRuntime.jsx(ci,{status:F,saveStatus:x,hasChanges:V,onSave:()=>fe(false),onPublish:W,onUnpublish:F==="published"?be:void 0,onDuplicate:xe,onViewHistory:()=>{window.dispatchEvent(new CustomEvent("kyro:show-version-history"));},onPreview:()=>window.open(`/preview/${R}/${o}`,"_blank"),onDelete:U,onBack:a,onToggleSidebar:()=>window.dispatchEvent(new CustomEvent("toggle-sidebar")),publishedAt:G,updatedAt:D}),jsxRuntime.jsxs("div",{className:te?"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(qa,{config:t?{...t,fields:le}:{slug:"unknown",fields:le},data:p,onChange:y,layout:te?"single":"split",globalSlug:i==="global"?R:void 0,collectionSlug:i==="collection"?R:void 0,onActionSuccess:me=>$.success(me),onActionError:me=>$.error(me),documentStatus:F,justSaved:z}),te&&jsxRuntime.jsxs("div",{className:"mt-8 pt-8 border-t border-[var(--kyro-border)] flex justify-end gap-3",children:[i==="collection"&&o&&jsxRuntime.jsx("button",{type:"button",onClick:U,disabled:T||f,className:"kyro-btn kyro-btn-sm text-[var(--kyro-danger)] hover:bg-[var(--kyro-danger)]/10 w-full justify-start mt-2",children:T?"Deleting...":"Delete Document"}),jsxRuntime.jsx(Ao,{status:F,saveStatus:f?"saving":"idle",hasChanges:V,onPublish:()=>fe(false),disabled:f})]})]})}),!te&&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 ${F==="published"?"bg-green-500/10 text-green-500":"bg-amber-500/10 text-amber-500"}`,children:F||"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:S?new Date(S).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:D?new Date(D).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"Just now"})]}),G&&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(G).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:xe,disabled:w||f,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:w?"Duplicating...":"Duplicate Document"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>window.open(`/preview/${R}/${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:U,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 ui({config:e,collection:t,onCancel:r,onSuccess:o,onError:a}){let[n,s]=Sa.useState({}),[l,i]=Sa.useState(false),d=t.fields||[],c=t.label||t.slug,p=async y=>{try{i(!0),await st(`/api/${t.slug}`,n),$.success(`${t.singularLabel||t.label||"Document"} created`),o();}catch(v){a(v instanceof Error?v.message:"Failed to create");}finally{i(false);}};return jsxRuntime.jsxs("div",{className:"kyro-detail",children:[jsxRuntime.jsx(Ft,{back:{onClick:r},breadcrumbs:[{label:"Collections"},{label:c,href:`${ze}/${t.slug}`},{label:"New"}],title:`Create ${t.singularLabel||c}`,action:{label:l?"Creating...":`Create ${t.singularLabel||c}`,onClick:()=>p(),disabled:l}}),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(qa,{config:{...t,fields:d},data:n,onChange:s})})})})})]})}function Qd({type:e,message:t,onClose:r}){let[o,a]=Sa__default.default.useState(false),n=Sa__default.default.useRef(null),s=()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(r,5e3);},l=()=>{n.current&&clearTimeout(n.current);};Sa__default.default.useEffect(()=>(o?l():s(),l),[o,r]);let i={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(i,{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 pR({children:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}function mR(){let e=Kt(o=>o.addToast),t=Kt(o=>o.removeToast);return {toasts:Kt(o=>o.toasts),addToast:e,removeToast:t}}function ts(){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:1e5,pointerEvents:"none"},children:e.map(r=>jsxRuntime.jsx("div",{style:{pointerEvents:"auto"},children:jsxRuntime.jsx(Qd,{type:r.type,message:r.message,onClose:()=>t(r.id)})},r.id))})}function vi({onAuth:e,theme:t="light"}){let[r,o]=Sa.useState("login"),[a,n]=Sa.useState(""),[s,l]=Sa.useState(""),[i,d]=Sa.useState(""),[c,p]=Sa.useState(false),[y,v]=Sa.useState(false),b=Kt(f=>f.addToast);Sa.useEffect(()=>{g();},[]);let g=async()=>{try{await Te("/api/users");}catch{v(true),o("register");}};return jsxRuntime.jsx(Nr,{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 f=>{f.preventDefault(),p(true);try{let m=r==="login"?"/api/auth/login":"/api/auth/register",w={email:a,password:s};r==="register"&&(w.confirmPassword=i);let A=await st(m,w);A.isFirstUser&&v(!0),localStorage.setItem("kyro_user",JSON.stringify(A.user)),b("success",r==="login"?"Welcome back!":"Account created!"),e(A.token,A.user);}catch{b("error","Connection failed");}finally{p(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:f=>n(f.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:f=>l(f.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:i,onChange:f=>d(f.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(ts,{})]})})}function tc({collections:e,onNavigate:t,user:r}){let{permissions:o}=_r(),[a,n]=Sa.useState({totalDocs:0,totalMedia:0,totalUsers:0,recentActivity:[]}),[s,l]=Sa.useState(true);Sa.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"}]}),l(false);},800);return ()=>clearTimeout(d)},[]);let i=Object.entries(e).filter(([d])=>!$s.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:i.length>0&&o?.collections?.[i[0]?.[0]]?.create!==false?{label:"New Document",onClick:()=>t("create",i[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(Ut,{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:i.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:[i.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)),i.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 oc(){let[e,t]=Sa.useState([]),[r,o]=Sa.useState(true),[a,n]=Sa.useState(""),[s,l]=Sa.useState(false),[i,d]=Sa.useState({name:"",email:"",password:"",role:"customer"}),[c,p]=Sa.useState(""),[y,v]=Sa.useState(false),{confirm:b,alert:g}=dt();Sa.useEffect(()=>{h();},[]);let h=async()=>{try{o(!0);let k=await Te("/api/users");t(k.docs||[]);}catch(k){console.error("Failed to load users:",k);}finally{o(false);}},f=k=>{let x=!k.locked;b({title:x?"Lock User Account?":"Unlock User Account?",message:x?`Are you sure you want to lock ${k.email}? They will be immediately logged out and unable to return.`:`Restore system access for ${k.email}?`,variant:x?"danger":"success",onConfirm:async()=>{try{await Gt(`/api/users/${k.id}`,{locked:x}),t(u=>u.map(F=>F.id===k.id?{...F,locked:x}:F)),$.success(x?`Account locked: ${k.email}`:`Account restored: ${k.email}`);}catch(u){console.error("Failed to toggle user lock:",u),$.error("Failed to update account status");}}});},m=k=>{b({title:"Destroy User Account",message:`You are about to permanently delete ${k.email}. This will remove all their data and cannot be undone.`,variant:"danger",confirmLabel:"Destroy Account",onConfirm:async()=>{try{await kt(`/api/users/${k.id}`),t(x=>x.filter(u=>u.id!==k.id)),$.success(`Identity purged: ${k.email}`);}catch(x){console.error("Failed to delete user:",x),$.error("Failed to delete user");}}});},w=async()=>{if(!i.email.trim()||!i.password.trim()){p("Email and password are required");return}v(true),p("");try{await st("/api/users",{name:i.name.trim()||void 0,email:i.email.trim(),password:i.password,role:i.role}),l(!1),d({name:"",email:"",password:"",role:"customer"}),$.success("User created successfully"),h();}catch(k){let x=k instanceof Error?k.message:"Failed to create user";p(x),$.error(x);}finally{v(false);}},A=["super_admin","admin","editor","author","customer","guest"],T=e.filter(k=>k.email.toLowerCase().includes(a.toLowerCase())||k.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"}),p(""),l(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:k=>n(k.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((k,x)=>jsxRuntime.jsx("tr",{className:"animate-pulse",children:jsxRuntime.jsx("td",{colSpan:5,className:"px-6 py-5 bg-[var(--kyro-surface-accent)]/30"})},x)):T.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"})})}):T.map(k=>jsxRuntime.jsxs("tr",{className:`hover:bg-[var(--kyro-surface-accent)]/50 transition-colors group ${k.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(ty,{user:k}),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:k.name||k.email.split("@")[0]}),k.tenantId&&jsxRuntime.jsx(St,{variant:"outline",className:"text-[7px] px-1 py-0 border-none bg-[var(--kyro-surface-accent)] opacity-50",children:k.tenantId})]}),jsxRuntime.jsx("div",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:k.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:k.role})]})}),jsxRuntime.jsx("td",{className:"px-6 py-3.5",children:jsxRuntime.jsx(St,{variant:k.locked?"danger":"success",dot:true,className:"text-[8px] font-bold uppercase tracking-widest",children:k.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"}),k.lastLogin?new Date(k.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:()=>f(k),className:`p-1.5 rounded-lg border transition-all ${k.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:k.locked?"Restore Access":"Restrict Access",children:k.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:()=>m(k),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"})})]})})]},k.id))})]})}),jsxRuntime.jsxs(Pt,{open:s,onClose:()=>l(false),title:"Create User",size:"lg",children:[jsxRuntime.jsx(Lr,{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:i.name,onChange:k=>d({...i,name:k.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:i.email,onChange:k=>d({...i,email:k.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:i.password,onChange:k=>d({...i,password:k.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:i.role,onChange:k=>d({...i,role:k.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:A.map(k=>jsxRuntime.jsx("option",{value:k,children:k},k))})]}),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(Gr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>l(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:w,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 ty({user:e}){let[t,r]=Sa.useState(null);return Sa.useEffect(()=>{let o=e.avatar;typeof o=="string"&&/^[0-9a-f-]+$/i.test(o)&&Te(`/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 ac(){let[e,t]=Sa.useState("Kyro CMS"),[r,o]=Sa.useState("Command Center"),[a,n]=Sa.useState("#6366f1"),[s,l]=Sa.useState("Welcome back to your Command Center."),[i,d]=Sa.useState(false),[c,p]=Sa.useState(false);return Sa.useEffect(()=>{(async()=>{try{let g=await Te("/api/globals/site-settings"),h=g.data||g;h&&Object.keys(h).length>0&&(h.siteName&&t(h.siteName),h.adminTitle&&o(h.adminTitle),h.primaryColor&&n(h.primaryColor),h.dashboardGreeting&&l(h.dashboardGreeting));}catch(g){console.error("Failed to load branding:",g);}})();},[]),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 Gt("/api/globals/site-settings",{siteName:e,adminTitle:r,primaryColor:a,dashboardGreeting:s}),p(!0),$.success("Branding updated"),document.documentElement.style.setProperty("--kyro-primary",a),setTimeout(()=>window.location.reload(),800);}catch(b){$.error("Failed to save branding"),console.error(b);}finally{d(false);}},disabled:i,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:[i?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"}),i?"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:b=>t(b.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:b=>o(b.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:b=>l(b.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(b=>jsxRuntime.jsx("button",{type:"button",onClick:()=>n(b.hex),className:`aspect-square rounded-xl transition-all border-4 ${a===b.hex?"border-white ring-2 ring-[var(--kyro-primary)]":"border-transparent opacity-60 hover:opacity-100"}`,style:{backgroundColor:b.hex},title:b.name},b.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 ry=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function tc({collections:e}){let[t,r]=Ca.useState([]),[o,a]=Ca.useState(false),[n,s]=Ca.useState(null),[l,i]=Ca.useState(""),[d,c]=Ca.useState(null),[m,f]=Ca.useState(false),{confirm:v,alert:b}=dt(),[g,x]=Ca.useState(false),[u,y]=Ca.useState(""),h=async()=>{try{let p=await Be("/api/keys");r(p);}catch(p){console.error(p);}};Ca.useEffect(()=>{h();},[]);let R=async()=>{y(""),x(true);},P=async()=>{if(u.trim())try{await nt("/api/keys",{name:u}),h(),x(!1),y(""),M.success("API key generated");}catch(p){console.error(p),M.error("Failed to generate API key");}},w=p=>{v({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 xt(`/api/keys/${p}`),h(),M.success("API key revoked");}catch(T){console.error(T),M.error("Failed to revoke API key");}}});},k=async()=>{if(l){f(true);try{let T=await(await fetch(tt(`/api/${l}`))).json();c(T);}catch{c({error:"Failed to fetch. Ensure the endpoint exists."});}finally{f(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(Dt,{title:"Developer Center",description:"Provision access keys and explore the headless API ecosystem.",icon:lucideReact.CodeXml,actions:[{label:"Generate Key",onClick:R,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),M.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 ",ry,"/"]}),jsxRuntime.jsx("input",{type:"text",value:l,onChange:p=>i(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:k,disabled:m||!l,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(Zu__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:g,onClose:()=>x(false),title:"Generate Access Token",size:"lg",children:[jsxRuntime.jsx(Hr,{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:u,onChange:p=>y(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"&&P()})]})]})}),jsxRuntime.jsxs(Vr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>x(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:P,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 rc(e){let[t,r]=Ca.useState([]),[o,a]=Ca.useState(false),[n,s]=Ca.useState(null),[l,i]=Ca.useState(false),{confirm:d}=dt(),c=Ca.useCallback(async()=>{a(true),s(null);try{let b=await Be(e.endpoint),g=Array.isArray(b)?b:b.docs||[],x=e.transformLoad?e.transformLoad(g):g;r(x),e.onSuccess?.("load",x);}catch(b){let g=b instanceof Error?b.message:"Failed to load resources";s(g),e.onError?.("load",b);}finally{a(false);}},[e.endpoint,e.transformLoad]);Ca.useEffect(()=>{c();},[c]);let m=Ca.useCallback((b,g="item")=>{d({title:`Delete ${g}`,message:`Are you sure you want to delete this ${g.toLowerCase()}? This action cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await xt(`${e.endpoint}/${b}`),r(x=>x.filter(u=>u.id!==b)),e.onSuccess?.("delete",b),M.success(`${g} deleted`);}catch(x){let u=x instanceof Error?x.message:`Failed to delete ${g}`;M.error(u),e.onError?.("delete",x);}}});},[e.endpoint,d]),f=Ca.useCallback(async b=>{s(null);try{let g=await nt(e.endpoint,b);return r(x=>[g,...x]),i(!1),e.onSuccess?.("create",g),g}catch(g){let x=g instanceof Error?g.message:"Failed to create resource";throw s(x),e.onError?.("create",g),g}},[e.endpoint]),v=Ca.useCallback(async(b,g)=>{s(null);try{let x=await Gt(`${e.endpoint}/${b}`,g);return r(u=>u.map(y=>y.id===b?x:y)),e.onSuccess?.("update",x),x}catch(x){let u=x instanceof Error?x.message:"Failed to update resource";throw s(u),e.onError?.("update",x),x}},[e.endpoint]);return {items:t,setItems:r,loading:o,error:n,load:c,remove:m,create:f,update:v,isCreateModalOpen:l,setIsCreateModalOpen:i}}function oc(){let{items:e,loading:t,create:r,remove:o,update:a,isCreateModalOpen:n,setIsCreateModalOpen:s}=rc({endpoint:"/api/webhooks"}),{confirm:l}=dt(),[i,d]=Ca.useState(false),[c,m]=Ca.useState(false),[f,v]=Ca.useState(null),[b,g]=Ca.useState(null),[x,u]=Ca.useState({name:"",url:"",events:[],secret:""}),[y,h]=Ca.useState(""),R=async()=>{if(!x.name.trim()||!x.url.trim()){h("Name and URL are required");return}try{await r(x),u({name:"",url:"",events:[],secret:""}),M.success(`Webhook established: ${x.name}`);}catch{h("Failed to create webhook"),M.error("Failed to create webhook");}},P=async p=>{g(p),v(null),d(true);try{let T=await nt(`/api/webhooks/${p}/test`);v({success:!0,message:T.message||"Webhook triggered successfully"}),M.success("Dispatch verified: Remote endpoint responded");}catch{v({success:false,message:"Failed to trigger webhook"});}},w=async(p,T)=>{try{let B=T==="active"?"paused":"active";await a(p,{status:B}),M.success(B==="active"?"Signals resumed":"Dispatcher paused");}catch(B){console.error(B),M.error("Failed to toggle webhook status");}},k=[{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(Dt,{title:"Webhooks",description:"Receive real-time notifications when your content changes.",icon:lucideReact.Webhook,actions:[{label:"Create Webhook",onClick:()=>{u({name:"",url:"",events:["collection.create","collection.update","collection.delete"],secret:""}),h(""),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(T=>jsxRuntime.jsx(Pt,{variant:"outline",className:"text-[8px] font-bold px-1.5 opacity-60",children:T},T)),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:()=>P(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(Hr,{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:x.name,onChange:p=>u({...x,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:x.url,onChange:p=>u({...x,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:x.secret,onChange:p=>u({...x,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:k.map(p=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{let T=x.events.includes(p.value)?x.events.filter(B=>B!==p.value):[...x.events,p.value];u({...x,events:T});},className:`flex items-center gap-3 p-3 rounded-lg border transition-all text-left ${x.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 ${x.events.includes(p.value)?"bg-[var(--kyro-primary)] border-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:x.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))})]})]}),y&&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"}),y]})]})}),jsxRuntime.jsxs(Vr,{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:R,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:i,onClose:()=>d(false),title:"Webhook Test Dispatcher",children:[jsxRuntime.jsx(Hr,{children:jsxRuntime.jsx("div",{className:"p-8 rounded-[2rem] bg-[var(--kyro-surface-accent)]/30 border border-[var(--kyro-border)] text-center",children:f?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 ${f.success?"bg-green-500/10 text-green-500":"bg-red-500/10 text-red-500"}`,children:f.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:f.success?"Dispatch Successful":"Dispatch Failed"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70",children:f.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(Vr,{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(Hr,{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(Vr,{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 sc({isOpen:e,onClose:t,collections:r,globals:o,onNavigate:a}){let{user:n,permissions:s}=Ur(),[l,i]=Ca.useState(""),[d,c]=Ca.useState(0),[m,f]=Ca.useState(false),[v,b]=Ca.useState([]),g=Ca.useRef(null),x=Ca.useRef(null);Ca.useEffect(()=>{e&&(i(""),c(0),b([]),f(false),setTimeout(()=>g.current?.focus(),100));},[e]);let u=Ca.useCallback(async A=>{if(!A||A.length<2){b([]);return}f(true);try{let K=await(await fetch(tt(`/api/search?q=${encodeURIComponent(A)}&limit=15`))).json();K.results&&b(K.results);}catch(X){console.error("Search error:",X),b([]);}finally{f(false);}},[]);if(Ca.useEffect(()=>(x.current&&clearTimeout(x.current),l.length>=2?x.current=setTimeout(()=>u(l),300):b([]),()=>{x.current&&clearTimeout(x.current);}),[l,u]),!e)return null;let y=Object.entries(r).filter(([A])=>s?.collections?.[A]?.read!==false).map(([A,X])=>({id:`col-${A}`,label:X.label||A,type:"collection",slug:A,icon:lucideReact.FileText})),h=Object.entries(o).filter(([A])=>s?.globals?.[A]?.read!==false).map(([A,X])=>({id:`global-${A}`,label:X.label||A,type:"global",slug:A,icon:lucideReact.Settings})),R=typeof document<"u"&&document.documentElement.classList.contains("dark"),P=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:P},{id:"action-audit",label:"Audit Logs",type:"action",view:"audit",icon:lucideReact.File,visible:P},{id:"action-roles",label:"Roles & Permissions",type:"action",view:"roles",icon:lucideReact.Shield,visible:P},{id:"action-api",label:"REST API Explorer",type:"action",view:"api-explorer",icon:lucideReact.Database,visible:P},{id:"action-graphql",label:"GraphQL Playground",type:"action",view:"graphql",icon:lucideReact.Hexagon,visible:P},{id:"action-rest",label:"REST Playground",type:"action",view:"rest",icon:lucideReact.Network,visible:P},{id:"action-theme",label:R?"Switch to Light Mode":"Switch to Dark Mode",type:"action",view:"theme",icon:R?lucideReact.Sun:lucideReact.Moon,visible:true},{id:"action-logout",label:"Sign Out",type:"action",view:"logout",icon:lucideReact.LogOut,visible:true}].filter(A=>A.visible),k=v.map((A,X)=>({id:`doc-${A.collection}-${A.id}`,label:A.title,type:"document",collection:A.collection,label2:A.label,docId:A.id,icon:lucideReact.File,doc:A.doc})),p=l.length>=2?[...w,...y,...h,...k]:[...w,...y,...h],T=l===""?p:p.filter(A=>A.label.toLowerCase().includes(l.toLowerCase())),B=A=>{if(A.key==="ArrowDown")A.preventDefault(),c(X=>(X+1)%T.length);else if(A.key==="ArrowUp")A.preventDefault(),c(X=>(X-1+T.length)%T.length);else if(A.key==="Enter"){let X=T[d];X&&S(X);}else A.key==="Escape"&&t();},S=A=>{A.type==="collection"?A.slug==="users"?a(A.slug,A.slug):a("list",A.slug):A.type==="global"?a("settings",A.slug):A.type==="document"?A.collection==="users"?a("users","users",A.docId):a("edit",A.collection,A.docId):A.type==="action"&&(A.view==="users"?a("users","users"):A.view==="media"?a("media","media"):a(A.view,A.view)),t();},F=()=>l===""?"Quick Actions & Collections":v.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:g,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:l,onChange:A=>i(A.target.value),onKeyDown:B}),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:T.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:F()}),T.map((A,X)=>jsxRuntime.jsxs("div",{onClick:()=>S(A),onMouseEnter:()=>c(X),className:`flex items-center justify-between px-4 py-4 rounded-2xl cursor-pointer ${X===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 ${X===d?"bg-white/20":"bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)]"}`,children:jsxRuntime.jsx(A.icon,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-bold text-sm",children:A.label}),A.type==="document"&&A.label2&&jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest ${X===d?"text-[var(--kyro-sidebar-text-active)]/60":"opacity-40"}`,children:A.label2})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest opacity-40 ${X===d?"text-[var(--kyro-sidebar-text-active)] p-1":""}`,children:A.type}),X===d&&jsxRuntime.jsx(lucideReact.ArrowRight,{className:"w-4 h-4 mr-2"})]})]},A.id))]}):jsxRuntime.jsx("div",{className:"py-12 text-center",children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] italic opacity-60",children:l.length>=2&&!m?`No results found for "${l}"`:"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 ic(){let{modal:e,closeModal:t}=dt(),[r,o]=Ca.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(l){console.error("Modal confirm action failed:",l);}finally{o(false),t();}else t();},s=()=>{a.onCancel&&a.onCancel(),t();};return jsxRuntime.jsx(Ns,{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 iy({config:e,theme:t="light",onThemeChange:r}){let[o,a]=Ca.useState(false),[n,s]=Ca.useState(null),l=Ca.useMemo(()=>Mn(Ba(e.collections)),[e.collections]),i=Ca.useMemo(()=>En(Ba(e.globals)),[e.globals]),[d,c]=Ca.useState(null),[m,f]=Ca.useState(null),[v,b]=Ca.useState("list"),[g,x]=Ca.useState(null),[u,y]=Ca.useState(false);Ca.useEffect(()=>{(async()=>{try{let k=await fetch("/api/users/me");if(k.ok){let p=await k.json();s(p),a(!0);}}catch(k){console.error("Auth check failed",k);}})();},[]),Ca.useEffect(()=>{if(o&&!d){let w=Object.keys(l)[0];w&&c(w);}},[o,l,d]);let h=(w,k=null,p=null)=>{b(w),k&&c(k),p&&x(p),y(false);};Ca.useEffect(()=>{let w=k=>{(k.metaKey||k.ctrlKey)&&k.key==="k"&&(k.preventDefault(),y(p=>!p));};return window.addEventListener("keydown",w),window.openCommandPalette=()=>y(true),()=>{window.removeEventListener("keydown",w),delete window.openCommandPalette;}},[]);return o?jsxRuntime.jsx(hr,{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(sc,{isOpen:u,onClose:()=>y(false),collections:l,globals:i,onNavigate:h}),(()=>{let w=d?l[d]:null;switch(v){case "create":return w?jsxRuntime.jsx(di,{config:e,collection:w,onSuccess:()=>b("list"),onCancel:()=>b("list"),onError:k=>M.error(k)}):null;case "detail":return w&&g?jsxRuntime.jsx(li,{config:e,collection:w,documentId:g,onBack:()=>b("list"),onSave:()=>{},onError:k=>M.error(k)}):null;case "users":return jsxRuntime.jsx(Zd,{});case "media":return jsxRuntime.jsx(Nn,{});case "branding":return jsxRuntime.jsx(ec,{});case "developer":return jsxRuntime.jsx(tc,{collections:l});case "webhooks":return jsxRuntime.jsx(oc,{});default:return w?jsxRuntime.jsx(ks,{config:e,collection:w,onCreate:()=>b("create"),onEdit:k=>h("detail",d,k)}):jsxRuntime.jsx(Yd,{onNavigate:h,collections:l,user:n})}})()]})})}),jsxRuntime.jsx(ic,{}),jsxRuntime.jsx(qn,{})]})}):jsxRuntime.jsx(mi,{onAuth:(w,k)=>{s(k),a(true);},theme:t})}function ly({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(vs,{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(So,{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 vy({open:e,onClose:t,versions:r,currentVersionId:o,onPreview:a,onRestore:n,onCompare:s,loading:l=false}){let i=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime())){let f=Date.parse(c);return isNaN(f)?"Invalid date":new Date(f).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 i(c);let v=new Date().getTime()-m.getTime();if(v<0)return "Just now";let b=Math.floor(v/6e4),g=Math.floor(v/36e5),x=Math.floor(v/864e5);return b<1?"Just now":b<60?`${b}m ago`:g<24?`${g}h ago`:x<7?`${x}d ago`:i(c)};return jsxRuntime.jsx(dr,{open:e,onClose:t,title:"Version History",width:"md",children:l?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-12",children:jsxRuntime.jsx(kr,{})}):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(f=>f.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 gA({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 ts(e){return nr.ready.push(e),()=>{nr.ready=nr.ready.filter(t=>t!==e);}}function cc(e){return nr.beforeDeploy.push(e),()=>{nr.beforeDeploy=nr.beforeDeploy.filter(t=>t!==e);}}function pc(e){return nr.afterDeploy.push(e),()=>{nr.afterDeploy=nr.afterDeploy.filter(t=>t!==e);}}async function mc(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 uc(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 yc(e,t){for(let r of nr.afterDeploy)try{await r(e,t);}catch{}}function vc(e){return `${typeof window<"u"?window.location.origin:""}${e}`}function gc(e,t={}){let[r,o]=Ca.useState(null),[a,n]=Ca.useState(true),[s,l]=Ca.useState(null),i=Ca.useCallback(async()=>{n(true),l(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=`${vc(`/api/${e}`)}?${d.toString()}`,m=await fetch(c,{credentials:"include"});if(!m.ok)throw new Error(`HTTP ${m.status}: ${m.statusText}`);let f=await m.json();o(f.data??f);}catch(d){l(d instanceof Error?d.message:String(d));}finally{n(false);}},[e,t.page,t.limit,t.sort,t.order]);return Ca.useEffect(()=>{i();},[i]),{data:r,loading:a,error:s,refetch:i}}function bc(e,t="POST"){let[r,o]=Ca.useState(false),[a,n]=Ca.useState(null);return {mutate:Ca.useCallback(async l=>{o(true),n(null);try{let i=vc(`/api/${e}`),d=await fetch(i,{method:t,credentials:"include",headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0});if(!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);let c=await d.json();return c.data??c}catch(i){return n(i instanceof Error?i.message:String(i)),null}finally{o(false);}},[e,t]),loading:r,error:a}}var la=new Map;function da(e){if(!e.name||typeof e.name!="string")throw new Error("Plugin must have a valid name");la.has(e.name)&&console.warn(`Plugin "${e.name}" is already registered. Overwriting.`),la.set(e.name,e),e.apply&&e.apply({});}function xc(e){la.delete(e);}function kc(e){return la.get(e)}function hc(){return Array.from(la.values())}function wc(e){return Array.from(la.values()).filter(t=>t.hooks&&typeof t.hooks[e]=="function")}var by={name:"sample-plugin",version:"0.1.0",description:"A tiny sample plugin to demonstrate the extensibility surface",hooks:{onAdminReady:()=>{}}};da(by);var xy={name:"sample-plugin-2",version:"0.1.0",description:"Second MVP plugin demonstrating beforeDeploy hook",hooks:{beforeDeploy:e=>({success:true})}};da(xy);var ca=new Map;function pa(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");ca.set(e.id,e);}function Nc(e){ca.delete(e);}function Cc(e){return ca.get(e)}function Sc(){return Array.from(ca.values())}function Tc(e){return Array.from(ca.values()).filter(t=>t.category===e)}function Rc(e){let t=ca.get(e);return t?t.render:(console.warn(`Block "${e}" not found in registry`),null)}var ky=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)})]})},hy={id:"sample-block",label:"Sample Block",category:"demo",schema:[{name:"title",label:"Title",type:"text",required:true}],render:ky};pa(hy);var Ny=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)})]})},Cy={id:"sample-block-2",label:"Sample Block 2",category:"demo",schema:[{name:"subtitle",label:"Subtitle",type:"text",required:false}],render:Ny};pa(Cy);var ma=new Map;function ua(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");ma.set(e.id,e);}function Dc(e){ma.delete(e);}function Pc(e){return ma.get(e)}function Ic(){return Array.from(ma.values())}function Bc(e){return Array.from(ma.values()).find(t=>t.type===e)}function Lc(e,t){let r=ma.get(e);if(!r)return console.warn(`Field "${e}" not found in registry`),null;let o=r.editor;return jsxRuntime.jsx(o,{...t})}var Ry=({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"}),Ay={id:"sample-text",type:"text",label:"Sample Text",editor:Ry};ua(Ay);var Dy=({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"}),Py={id:"sample-textarea",type:"textarea",label:"Sample Textarea",editor:Dy};ua(Py);var Mc=yr__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");yr__default.default.join(Mc,"use-sync-external-store.js");yr__default.default.join(Mc,"use-sync-external-store-with-selector.js");function $y(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:l})=>{l.info(`Kyro Admin mounted at ${t} (API: ${r})`);let i=yr__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=yr__default.default.resolve(a.root.pathname,"..",o),c=yr__default.default.resolve(a.root.pathname,o),m=Do__default.default.existsSync(d)?d:Do__default.default.existsSync(c)?c:i;m!==i?l.info(`Loaded config from ${m}`):l.warn("Config file not found. Using defaults.");let f=yr__default.default.join(yr__default.default.dirname(m),".kyro-admin-config.json"),v="";try{let g=yr__default.default.join(yr__default.default.dirname(m),".env");Do__default.default.existsSync(g)&&dotenv.config({path:g});let x=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/*"]});v=m.replace(/\.ts$/,".admin.mjs"),Do__default.default.writeFileSync(v,x.outputFiles[0].text,"utf8");let u=`
106
+ `}})]})]})]})}var iy=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function nc({collections:e}){let[t,r]=Sa.useState([]),[o,a]=Sa.useState(false),[n,s]=Sa.useState(null),[l,i]=Sa.useState(""),[d,c]=Sa.useState(null),[p,y]=Sa.useState(false),{confirm:v,alert:b}=dt(),[g,h]=Sa.useState(false),[f,m]=Sa.useState(""),w=async()=>{try{let u=await Te("/api/keys");r(u);}catch(u){console.error(u);}};Sa.useEffect(()=>{w();},[]);let A=async()=>{m(""),h(true);},T=async()=>{if(f.trim())try{await st("/api/keys",{name:f}),w(),h(!1),m(""),$.success("API key generated");}catch(u){console.error(u),$.error("Failed to generate API key");}},k=u=>{v({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/${u}`),w(),$.success("API key revoked");}catch(F){console.error(F),$.error("Failed to revoke API key");}}});},x=async()=>{if(l){y(true);try{let F=await(await fetch(qe(`/api/${l}`))).json();c(F);}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:A,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(u=>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:u.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===u.id?u.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===u.id?null:u.id),className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all text-[var(--kyro-text-secondary)]",children:n===u.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(u.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(u.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:()=>k(u.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"})})]})},u.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(St,{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(St,{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 ",iy,"/"]}),jsxRuntime.jsx("input",{type:"text",value:l,onChange:u=>i(u.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:x,disabled:p||!l,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:[p?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(St,{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(ay__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(Pt,{open:g,onClose:()=>h(false),title:"Generate Access Token",size:"lg",children:[jsxRuntime.jsx(Lr,{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:f,onChange:u=>m(u.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:u=>u.key==="Enter"&&T()})]})]})}),jsxRuntime.jsxs(Gr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>h(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:T,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 sc(e){let[t,r]=Sa.useState([]),[o,a]=Sa.useState(false),[n,s]=Sa.useState(null),[l,i]=Sa.useState(false),{confirm:d}=dt(),c=Sa.useCallback(async()=>{a(true),s(null);try{let b=await Te(e.endpoint),g=Array.isArray(b)?b:b.docs||[],h=e.transformLoad?e.transformLoad(g):g;r(h),e.onSuccess?.("load",h);}catch(b){let g=b instanceof Error?b.message:"Failed to load resources";s(g),e.onError?.("load",b);}finally{a(false);}},[e.endpoint,e.transformLoad]);Sa.useEffect(()=>{c();},[c]);let p=Sa.useCallback((b,g="item")=>{d({title:`Delete ${g}`,message:`Are you sure you want to delete this ${g.toLowerCase()}? This action cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await kt(`${e.endpoint}/${b}`),r(h=>h.filter(f=>f.id!==b)),e.onSuccess?.("delete",b),$.success(`${g} deleted`);}catch(h){let f=h instanceof Error?h.message:`Failed to delete ${g}`;$.error(f),e.onError?.("delete",h);}}});},[e.endpoint,d]),y=Sa.useCallback(async b=>{s(null);try{let g=await st(e.endpoint,b);return r(h=>[g,...h]),i(!1),e.onSuccess?.("create",g),g}catch(g){let h=g instanceof Error?g.message:"Failed to create resource";throw s(h),e.onError?.("create",g),g}},[e.endpoint]),v=Sa.useCallback(async(b,g)=>{s(null);try{let h=await Gt(`${e.endpoint}/${b}`,g);return r(f=>f.map(m=>m.id===b?h:m)),e.onSuccess?.("update",h),h}catch(h){let f=h instanceof Error?h.message:"Failed to update resource";throw s(f),e.onError?.("update",h),h}},[e.endpoint]);return {items:t,setItems:r,loading:o,error:n,load:c,remove:p,create:y,update:v,isCreateModalOpen:l,setIsCreateModalOpen:i}}var cy={generic:"\u{1F517}","github-dispatch":"\u2699\uFE0F","dokploy-deploy":"\u{1F680}","coolify-deploy":"\u{1F3AF}"};function ic(){let{items:e,loading:t,create:r,remove:o,update:a,isCreateModalOpen:n,setIsCreateModalOpen:s}=sc({endpoint:"/api/webhooks"}),{confirm:l}=dt(),[i,d]=Sa.useState(false),[c,p]=Sa.useState(false),[y,v]=Sa.useState(null),[b,g]=Sa.useState(null),[h,f]=Sa.useState({}),[m,w]=Sa.useState(true),[A,T]=Sa.useState("action"),[k,x]=Sa.useState("generic"),[u,F]=Sa.useState({name:"",url:"",events:[],secret:"",action:"generic",config:{}}),[M,S]=Sa.useState("");Sa.useEffect(()=>{P();},[]);let P=async()=>{try{let R=await Te("/api/webhooks/actions");f(R.actions);}catch(R){console.error("Failed to load webhook actions:",R);}finally{w(false);}},D=()=>{T("action"),x("generic"),F({name:"",url:"",events:["collection.create","collection.update","collection.delete"],secret:"",action:"generic",config:{}}),S("");},Q=R=>{x(R),F(V=>({...V,action:R,config:{}})),T("config");},G=(R,V)=>{F(L=>({...L,config:{...L.config,[R]:V}}));},O=async()=>{if(!u.name.trim()){S("Name is required");return}if(k==="generic"&&!u.url.trim()){S("URL is required for custom webhooks");return}let R=h[k];if(R){for(let V of R.configFields)if(V.required&&!u.config[V.name]?.trim()){S(`${V.label} is required`);return}}try{await r(u),D(),$.success(`Webhook created: ${u.name}`);}catch{S("Failed to create webhook"),$.error("Failed to create webhook");}},z=async R=>{g(R),v(null),d(true);try{let V=await st(`/api/webhooks/${R}/test`);v({success:!0,message:V.message||"Webhook triggered successfully"}),$.success("Test delivered successfully");}catch{v({success:false,message:"Failed to trigger webhook"});}},se=async(R,V)=>{try{let L=V==="active"?"paused":"active";await a(R,{status:L}),$.success(L==="active"?"Webhook activated":"Webhook paused");}catch(L){console.error(L),$.error("Failed to toggle webhook status");}},le=[{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"}],H=R=>h[R||"generic"]?.label||"Custom URL";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:"Get notified when your content changes.",icon:lucideReact.Webhook,actions:[{label:"New webhook",onClick:()=>{D(),s(true);},icon:lucideReact.Plus},{label:"Guide",onClick:()=>p(true),icon:lucideReact.Info,variant:"outline"}]}),jsxRuntime.jsx("div",{className:"relative overflow-hidden rounded-2xl border border-[var(--kyro-border)] bg-[var(--kyro-surface)] p-6",children:jsxRuntime.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-6 relative z-10",children:[jsxRuntime.jsx("div",{className:"p-3 bg-[var(--kyro-primary)]/10 rounded-xl",children:jsxRuntime.jsx(lucideReact.Zap,{className:"w-6 h-6 text-[var(--kyro-primary)]"})}),jsxRuntime.jsx("div",{className:"flex-1 text-center md:text-left",children:jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70 max-w-2xl leading-relaxed",children:"Receive instant HTTP notifications when events happen in your CMS. Choose a platform preset or point to any custom endpoint."})})]})}),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 text-[var(--kyro-text-secondary)]",children:"Endpoints"})]}),jsxRuntime.jsxs("div",{className:"text-xs text-[var(--kyro-text-secondary)] opacity-50",children:[e.length," hook",e.length!==1&&"s"]})]}),t?jsxRuntime.jsx("div",{className:"flex items-center justify-center p-20 opacity-50 text-sm text-[var(--kyro-text-secondary)]",children:"Loading webhooks..."}):e.length===0?jsxRuntime.jsxs("div",{className:"p-16 text-center rounded-2xl border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface)]/50",children:[jsxRuntime.jsx("div",{className:"w-16 h-16 mx-auto mb-5 bg-[var(--kyro-primary)]/10 rounded-2xl flex items-center justify-center",children:jsxRuntime.jsx(lucideReact.Webhook,{className:"w-8 h-8 text-[var(--kyro-primary)]"})}),jsxRuntime.jsx("h3",{className:"text-lg font-bold mb-2",children:"No webhooks yet"}),jsxRuntime.jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-60 mb-6 max-w-sm mx-auto",children:"Create a webhook to get notified when your content changes."}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>{D(),s(true);},className:"kyro-btn kyro-btn-primary inline-flex items-center gap-2 px-6 py-3 rounded-xl text-sm font-medium",children:[jsxRuntime.jsx(lucideReact.Plus,{className:"w-4 h-4"}),"Create webhook"]})]}):jsxRuntime.jsx("div",{className:"grid gap-4",children:e.map(R=>jsxRuntime.jsx("div",{className:"group relative overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-2xl p-5 hover:border-[var(--kyro-primary)]/30 transition-all duration-200",children:jsxRuntime.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-5 relative z-10",children:[jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[jsxRuntime.jsx("div",{className:"p-2 bg-[var(--kyro-surface-accent)] rounded-lg",children:jsxRuntime.jsx(lucideReact.Webhook,{className:"w-4 h-4 text-[var(--kyro-text-secondary)]"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h3",{className:"text-sm font-semibold",children:R.name}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[jsxRuntime.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${R.status==="active"?"bg-green-500":"bg-amber-500"}`}),jsxRuntime.jsx("span",{className:`text-[10px] font-medium ${R.status==="active"?"text-green-500":"text-amber-500"}`,children:R.status}),jsxRuntime.jsx(St,{variant:"outline",className:"text-[9px] px-1.5 opacity-50",children:H(R.action)})]})]})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 pt-1",children:[jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50",children:"Destination"}),jsxRuntime.jsx("div",{className:"font-mono text-xs text-[var(--kyro-text-secondary)] opacity-60 truncate max-w-[200px]",title:R.url,children:R.url||`${H(R.action)} webhook`})]}),jsxRuntime.jsxs("div",{className:"space-y-1 sm:border-l border-t sm:border-t-0 border-[var(--kyro-border)] pt-3 sm:pt-0 sm:pl-4",children:[jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50",children:"Events"}),jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-1",children:[R.events.slice(0,3).map(V=>jsxRuntime.jsx(St,{variant:"outline",className:"text-[9px] px-1.5 opacity-50",children:V},V)),R.events.length>3&&jsxRuntime.jsxs("span",{className:"text-[9px] text-[var(--kyro-text-secondary)] opacity-30",children:["+",R.events.length-3]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-1 sm:border-l border-t sm:border-t-0 border-[var(--kyro-border)] pt-3 sm:pt-0 sm:pl-4",children:[jsxRuntime.jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50",children:"Activity"}),jsxRuntime.jsxs("div",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-60 flex items-center gap-1.5",children:[jsxRuntime.jsx(lucideReact.Clock,{className:"w-3 h-3"}),R.lastTriggered?`Last triggered ${new Date(R.lastTriggered).toLocaleDateString()}`:"Never triggered"]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 lg:opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>z(R.id),className:"p-2 rounded-lg border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] transition-colors flex items-center gap-1.5",title:"Send test request",children:[jsxRuntime.jsx(lucideReact.Send,{className:"w-3.5 h-3.5"}),jsxRuntime.jsx("span",{className:"text-[11px] font-medium",children:"Test"})]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>se(R.id,R.status),className:`p-2 rounded-lg border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] transition-colors ${R.status==="active"?"text-amber-500/60 hover:text-amber-500":"text-green-500/60 hover:text-green-500"}`,title:R.status==="active"?"Pause":"Activate",children:R.status==="active"?jsxRuntime.jsx(lucideReact.Pause,{className:"w-3.5 h-3.5"}):jsxRuntime.jsx(lucideReact.Play,{className:"w-3.5 h-3.5"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o(R.id,"Webhook"),className:"p-2 rounded-lg border border-[var(--kyro-border)] hover:border-red-500/30 hover:bg-red-500/5 transition-colors",title:"Delete",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"w-3.5 h-3.5 text-red-500/50 hover:text-red-500"})})]})]})},R.id))})]}),jsxRuntime.jsx(Pt,{open:n&&A==="action",onClose:()=>s(false),title:"New webhook",children:jsxRuntime.jsx(Lr,{children:jsxRuntime.jsx("div",{className:"space-y-4",children:m?jsxRuntime.jsx("div",{className:"flex items-center justify-center p-12 opacity-50",children:jsxRuntime.jsx(lucideReact.RefreshCw,{className:"w-5 h-5 animate-spin text-[var(--kyro-primary)]"})}):jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(h).map(([R,V])=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>Q(R),className:"flex flex-col items-start p-4 rounded-xl border border-[var(--kyro-border)] bg-[var(--kyro-surface)] hover:border-[var(--kyro-primary)]/40 transition-all text-left group",children:[jsxRuntime.jsx("div",{className:"text-lg mb-2",children:cy[R]||"\u{1F517}"}),jsxRuntime.jsx("h3",{className:"text-sm font-medium mb-0.5 group-hover:text-[var(--kyro-primary)] transition-colors",children:V.label}),jsxRuntime.jsx("p",{className:"text-[11px] text-[var(--kyro-text-secondary)] opacity-50 leading-relaxed",children:V.description}),V.envVars.length>0&&jsxRuntime.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:V.envVars.map(L=>jsxRuntime.jsx("span",{className:"text-[9px] font-mono bg-[var(--kyro-surface-accent)] px-1.5 py-0.5 rounded opacity-40",children:L},L))})]},R))})})})}),jsxRuntime.jsxs(Pt,{open:n&&A==="config",onClose:()=>s(false),title:h[k]?.label||"Webhook",children:[jsxRuntime.jsx(Lr,{children:jsxRuntime.jsxs("div",{className:"space-y-5",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-5",children:[jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-medium mb-1.5 text-[var(--kyro-text-secondary)]",children:"Name"}),jsxRuntime.jsx("input",{type:"text",value:u.name,onChange:R=>F({...u,name:R.target.value}),placeholder:"e.g., Deploy on content update",className:"w-full px-3 py-2.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),k==="generic"&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-medium mb-1.5 text-[var(--kyro-text-secondary)]",children:"URL"}),jsxRuntime.jsx("input",{type:"url",value:u.url,onChange:R=>F({...u,url:R.target.value}),placeholder:"https://your-server.com/webhook",className:"w-full px-3 py-2.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),k!=="generic"&&h[k]?.configFields.map(R=>jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("label",{className:"block text-xs font-medium mb-1.5 text-[var(--kyro-text-secondary)]",children:[R.label," ",R.required&&jsxRuntime.jsx("span",{className:"text-red-500",children:"*"})]}),jsxRuntime.jsx("input",{type:"text",value:u.config[R.name]||"",onChange:V=>G(R.name,V.target.value),placeholder:R.placeholder,className:"w-full px-3 py-2.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]},R.name)),k==="generic"&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("label",{className:"block text-xs font-medium mb-1.5 text-[var(--kyro-text-secondary)]",children:"Signing secret"}),jsxRuntime.jsx("input",{type:"text",value:u.secret,onChange:R=>F({...u,secret:R.target.value}),placeholder:"Optional",className:"w-full px-3 py-2.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]})]}),k!=="generic"&&h[k]?.envVars.length>0&&jsxRuntime.jsxs("div",{className:"p-3 rounded-lg bg-amber-500/5 border border-amber-500/15",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-3.5 h-3.5 text-amber-500"}),jsxRuntime.jsx("span",{className:"text-[11px] font-medium text-amber-600",children:"Environment variables required"})]}),jsxRuntime.jsxs("p",{className:"text-[11px] text-amber-600/60 mb-2",children:["Add these to your ",jsxRuntime.jsx("code",{className:"font-mono bg-amber-500/10 px-1 py-0.5 rounded text-[10px]",children:".env"})," file:"]}),jsxRuntime.jsx("div",{className:"flex flex-wrap gap-1.5",children:h[k].envVars.map(R=>jsxRuntime.jsxs("code",{className:"text-[10px] font-mono bg-amber-500/10 text-amber-600 px-1.5 py-0.5 rounded",children:[R,"=..."]},R))})]}),jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("label",{className:"block text-xs font-medium text-[var(--kyro-text-secondary)]",children:"Events"}),jsxRuntime.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:le.map(R=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{let V=u.events.includes(R.value)?u.events.filter(L=>L!==R.value):[...u.events,R.value];F({...u,events:V});},className:`flex items-center gap-2.5 p-2.5 rounded-lg border transition-all text-left text-sm ${u.events.includes(R.value)?"bg-[var(--kyro-primary)]/5 border-[var(--kyro-primary)]/30 text-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/20"}`,children:[jsxRuntime.jsx("div",{className:`w-3.5 h-3.5 rounded flex items-center justify-center border transition-all ${u.events.includes(R.value)?"bg-[var(--kyro-primary)] border-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:u.events.includes(R.value)&&jsxRuntime.jsx(lucideReact.CircleCheck,{className:"w-2.5 h-2.5 text-white"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"text-xs font-medium",children:R.label}),jsxRuntime.jsx("div",{className:"text-[10px] opacity-40",children:R.description})]})]},R.value))})]})]}),M&&jsxRuntime.jsxs("div",{className:"p-2.5 bg-red-500/10 border border-red-500/20 rounded-lg flex items-center gap-2 text-red-500 text-xs",children:[jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-3.5 h-3.5"}),M]})]})}),jsxRuntime.jsxs(Gr,{children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>T("action"),className:"px-4 py-2 rounded-lg text-sm font-medium border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:O,className:"kyro-btn kyro-btn-primary px-4 py-2 rounded-lg text-sm font-medium",children:"Create webhook"})]})]}),jsxRuntime.jsxs(Pt,{open:i,onClose:()=>d(false),title:"Test webhook",children:[jsxRuntime.jsx(Lr,{children:jsxRuntime.jsx("div",{className:"p-6 rounded-xl bg-[var(--kyro-surface)] border border-[var(--kyro-border)] text-center",children:y?jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("div",{className:`w-12 h-12 mx-auto rounded-xl flex items-center justify-center ${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-6 h-6"}):jsxRuntime.jsx(lucideReact.TriangleAlert,{className:"w-6 h-6"})}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-sm font-semibold mb-1",children:y.success?"Delivered":"Failed"}),jsxRuntime.jsx("p",{className:"text-xs text-[var(--kyro-text-secondary)] opacity-60",children:y.message})]})]}):jsxRuntime.jsxs("div",{className:"space-y-4 py-4",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"w-8 h-8 text-[var(--kyro-primary)] animate-spin mx-auto opacity-40"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h4",{className:"text-sm font-semibold mb-1",children:"Sending test payload"}),jsxRuntime.jsx("p",{className:"text-xs text-[var(--kyro-text-secondary)] opacity-50",children:"Dispatching..."})]})]})})}),jsxRuntime.jsx(Gr,{children:jsxRuntime.jsx("button",{type:"button",onClick:()=>d(false),className:"w-full py-2.5 rounded-lg text-sm font-medium bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] hover:bg-[var(--kyro-surface)] transition-colors",children:"Close"})})]}),jsxRuntime.jsxs(Pt,{open:c,onClose:()=>p(false),title:"How webhooks work",children:[jsxRuntime.jsx(Lr,{children:jsxRuntime.jsxs("div",{className:"space-y-6",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[jsxRuntime.jsxs("div",{className:"p-4 rounded-xl bg-[var(--kyro-surface)] border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("h4",{className:"text-sm font-medium mb-1.5 flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.ExternalLink,{className:"w-3.5 h-3.5 text-[var(--kyro-primary)]"}),"Request format"]}),jsxRuntime.jsxs("p",{className:"text-xs text-[var(--kyro-text-secondary)] leading-relaxed opacity-70",children:["When an event triggers, Kyro sends a ",jsxRuntime.jsx("span",{className:"font-medium",children:"POST"})," request to your endpoint with a JSON payload containing document metadata and operation details."]})]}),jsxRuntime.jsxs("div",{className:"p-4 rounded-xl bg-[var(--kyro-surface)] border border-[var(--kyro-border)]",children:[jsxRuntime.jsxs("h4",{className:"text-sm font-medium mb-1.5 flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Shield,{className:"w-3.5 h-3.5 text-[var(--kyro-primary)]"}),"Signature verification"]}),jsxRuntime.jsxs("p",{className:"text-xs text-[var(--kyro-text-secondary)] leading-relaxed opacity-70",children:["If a secret is set, each request includes an ",jsxRuntime.jsx("span",{className:"font-mono text-[10px] bg-[var(--kyro-surface-accent)] px-1 py-0.5 rounded",children:"X-Webhook-Signature"})," header with an HMAC-SHA256 signature. Verify it in production."]})]})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("h4",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] opacity-50",children:"Example payload"}),jsxRuntime.jsx("div",{className:"bg-[var(--kyro-bg)] rounded-xl border border-[var(--kyro-border)] p-4 font-mono text-xs overflow-hidden",children:jsxRuntime.jsxs("div",{className:"space-y-0.5 text-[var(--kyro-text-secondary)]",children:[jsxRuntime.jsx("div",{children:"{"}),jsxRuntime.jsxs("div",{className:"pl-3",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-3",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"collection"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"posts"'}),","]}),jsxRuntime.jsxs("div",{className:"pl-3",children:[jsxRuntime.jsx("span",{className:"text-[var(--kyro-primary)]",children:'"timestamp"'}),": ",jsxRuntime.jsx("span",{className:"text-green-500",children:'"2026-06-28T12:00:00Z"'})]}),jsxRuntime.jsx("div",{children:"}"})]})})]})]})}),jsxRuntime.jsx(Gr,{children:jsxRuntime.jsx("button",{type:"button",onClick:()=>p(false),className:"kyro-btn kyro-btn-primary w-full py-2.5 rounded-lg text-sm font-medium",children:"Got it"})})]})]})}function cc({isOpen:e,onClose:t,collections:r,globals:o,onNavigate:a}){let{user:n,permissions:s}=_r(),[l,i]=Sa.useState(""),[d,c]=Sa.useState(0),[p,y]=Sa.useState(false),[v,b]=Sa.useState([]),g=Sa.useRef(null),h=Sa.useRef(null);Sa.useEffect(()=>{e&&(i(""),c(0),b([]),y(false),setTimeout(()=>g.current?.focus(),100));},[e]);let f=Sa.useCallback(async D=>{if(!D||D.length<2){b([]);return}y(true);try{let G=await(await fetch(qe(`/api/search?q=${encodeURIComponent(D)}&limit=15`))).json();G.results&&b(G.results);}catch(Q){console.error("Search error:",Q),b([]);}finally{y(false);}},[]);if(Sa.useEffect(()=>(h.current&&clearTimeout(h.current),l.length>=2?h.current=setTimeout(()=>f(l),300):b([]),()=>{h.current&&clearTimeout(h.current);}),[l,f]),!e)return null;let m=Object.entries(r).filter(([D])=>s?.collections?.[D]?.read!==false).map(([D,Q])=>({id:`col-${D}`,label:Q.label||D,type:"collection",slug:D,icon:lucideReact.FileText})),w=Object.entries(o).filter(([D])=>s?.globals?.[D]?.read!==false).map(([D,Q])=>({id:`global-${D}`,label:Q.label||D,type:"global",slug:D,icon:lucideReact.Settings})),A=typeof document<"u"&&document.documentElement.classList.contains("dark"),T=n?.role==="admin",k=[{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:T},{id:"action-audit",label:"Audit Logs",type:"action",view:"audit",icon:lucideReact.File,visible:T},{id:"action-roles",label:"Roles & Permissions",type:"action",view:"roles",icon:lucideReact.Shield,visible:T},{id:"action-api",label:"REST API Explorer",type:"action",view:"api-explorer",icon:lucideReact.Database,visible:T},{id:"action-graphql",label:"GraphQL Playground",type:"action",view:"graphql",icon:lucideReact.Hexagon,visible:T},{id:"action-rest",label:"REST Playground",type:"action",view:"rest",icon:lucideReact.Network,visible:T},{id:"action-theme",label:A?"Switch to Light Mode":"Switch to Dark Mode",type:"action",view:"theme",icon:A?lucideReact.Sun:lucideReact.Moon,visible:true},{id:"action-logout",label:"Sign Out",type:"action",view:"logout",icon:lucideReact.LogOut,visible:true}].filter(D=>D.visible),x=v.map((D,Q)=>({id:`doc-${D.collection}-${D.id}`,label:D.title,type:"document",collection:D.collection,label2:D.label,docId:D.id,icon:lucideReact.File,doc:D.doc})),u=l.length>=2?[...k,...m,...w,...x]:[...k,...m,...w],F=l===""?u:u.filter(D=>D.label.toLowerCase().includes(l.toLowerCase())),M=D=>{if(D.key==="ArrowDown")D.preventDefault(),c(Q=>(Q+1)%F.length);else if(D.key==="ArrowUp")D.preventDefault(),c(Q=>(Q-1+F.length)%F.length);else if(D.key==="Enter"){let Q=F[d];Q&&S(Q);}else D.key==="Escape"&&t();},S=D=>{D.type==="collection"?D.slug==="users"?a(D.slug,D.slug):a("list",D.slug):D.type==="global"?a("settings",D.slug):D.type==="document"?D.collection==="users"?a("users","users",D.docId):a("edit",D.collection,D.docId):D.type==="action"&&(D.view==="users"?a("users","users"):D.view==="media"?a("media","media"):a(D.view,D.view)),t();},P=()=>l===""?"Quick Actions & Collections":v.length>0?"Documents":p?"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:[p?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:g,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:l,onChange:D=>i(D.target.value),onKeyDown:M}),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:F.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()}),F.map((D,Q)=>jsxRuntime.jsxs("div",{onClick:()=>S(D),onMouseEnter:()=>c(Q),className:`flex items-center justify-between px-4 py-4 rounded-2xl cursor-pointer ${Q===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 ${Q===d?"bg-white/20":"bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)]"}`,children:jsxRuntime.jsx(D.icon,{className:"w-4 h-4"})}),jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx("span",{className:"font-bold text-sm",children:D.label}),D.type==="document"&&D.label2&&jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest ${Q===d?"text-[var(--kyro-sidebar-text-active)]/60":"opacity-40"}`,children:D.label2})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:`text-[10px] font-bold tracking-widest opacity-40 ${Q===d?"text-[var(--kyro-sidebar-text-active)] p-1":""}`,children:D.type}),Q===d&&jsxRuntime.jsx(lucideReact.ArrowRight,{className:"w-4 h-4 mr-2"})]})]},D.id))]}):jsxRuntime.jsx("div",{className:"py-12 text-center",children:jsxRuntime.jsx("p",{className:"text-[var(--kyro-text-secondary)] italic opacity-60",children:l.length>=2&&!p?`No results found for "${l}"`:"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 pc(){let{modal:e,closeModal:t}=dt(),[r,o]=Sa.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(l){console.error("Modal confirm action failed:",l);}finally{o(false),t();}else t();},s=()=>{a.onCancel&&a.onCancel(),t();};return jsxRuntime.jsx(Ts,{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 yy({config:e,theme:t="light",onThemeChange:r}){let[o,a]=Sa.useState(false),[n,s]=Sa.useState(null),l=Sa.useMemo(()=>Un(La(e.collections)),[e.collections]),i=Sa.useMemo(()=>zn(La(e.globals)),[e.globals]),[d,c]=Sa.useState(null),[p,y]=Sa.useState(null),[v,b]=Sa.useState("list"),[g,h]=Sa.useState(null),[f,m]=Sa.useState(false);Sa.useEffect(()=>{(async()=>{try{let x=await fetch("/api/users/me");if(x.ok){let u=await x.json();s(u),a(!0);}}catch(x){console.error("Auth check failed",x);}})();},[]),Sa.useEffect(()=>{if(o&&!d){let k=Object.keys(l)[0];k&&c(k);}},[o,l,d]);let w=(k,x=null,u=null)=>{b(k),x&&c(x),u&&h(u),m(false);};Sa.useEffect(()=>{let k=x=>{(x.metaKey||x.ctrlKey)&&x.key==="k"&&(x.preventDefault(),m(u=>!u));};return window.addEventListener("keydown",k),window.openCommandPalette=()=>m(true),()=>{window.removeEventListener("keydown",k),delete window.openCommandPalette;}},[]);return o?jsxRuntime.jsx(Nr,{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(cc,{isOpen:f,onClose:()=>m(false),collections:l,globals:i,onNavigate:w}),(()=>{let k=d?l[d]:null;switch(v){case "create":return k?jsxRuntime.jsx(ui,{config:e,collection:k,onSuccess:()=>b("list"),onCancel:()=>b("list"),onError:x=>$.error(x)}):null;case "detail":return k&&g?jsxRuntime.jsx(mi,{config:e,collection:k,documentId:g,onBack:()=>b("list"),onSave:()=>{},onError:x=>$.error(x)}):null;case "users":return jsxRuntime.jsx(oc,{});case "media":return jsxRuntime.jsx(Tn,{});case "branding":return jsxRuntime.jsx(ac,{});case "developer":return jsxRuntime.jsx(nc,{collections:l});case "webhooks":return jsxRuntime.jsx(ic,{});default:return k?jsxRuntime.jsx(Cs,{config:e,collection:k,onCreate:()=>b("create"),onEdit:x=>w("detail",d,x)}):jsxRuntime.jsx(tc,{onNavigate:w,collections:l,user:n})}})()]})})}),jsxRuntime.jsx(pc,{}),jsxRuntime.jsx(ts,{})]})}):jsxRuntime.jsx(vi,{onAuth:(k,x)=>{s(x),a(true);},theme:t})}function fy({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(ks,{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(Ro,{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(It,{onClick:a.onClick,icon:a.icon,danger:a.danger,children:a.label},n))})]})}function Ny({open:e,onClose:t,versions:r,currentVersionId:o,onPreview:a,onRestore:n,onCompare:s,loading:l=false}){let i=c=>{if(!c)return "Unknown date";let p=new Date(c);if(isNaN(p.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 p.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})},d=c=>{if(!c)return "Unknown date";let p=new Date(c);if(isNaN(p.getTime()))return i(c);let v=new Date().getTime()-p.getTime();if(v<0)return "Just now";let b=Math.floor(v/6e4),g=Math.floor(v/36e5),h=Math.floor(v/864e5);return b<1?"Just now":b<60?`${b}m ago`:g<24?`${g}h ago`:h<7?`${h}d ago`:i(c)};return jsxRuntime.jsx(lr,{open:e,onClose:t,title:"Version History",width:"md",children:l?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-12",children:jsxRuntime.jsx(wr,{})}):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 p=c.id===o;return jsxRuntime.jsxs("div",{className:`p-4 rounded-xl border transition-all duration-200 group relative overflow-hidden ${p?"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:[p&&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]}),p&&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"})}),!p&&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 FA({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 is(e){return nr.ready.push(e),()=>{nr.ready=nr.ready.filter(t=>t!==e);}}function yc(e){return nr.beforeDeploy.push(e),()=>{nr.beforeDeploy=nr.beforeDeploy.filter(t=>t!==e);}}function fc(e){return nr.afterDeploy.push(e),()=>{nr.afterDeploy=nr.afterDeploy.filter(t=>t!==e);}}async function vc(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 gc(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 bc(e,t){for(let r of nr.afterDeploy)try{await r(e,t);}catch{}}function kc(e){return `${typeof window<"u"?window.location.origin:""}${e}`}function hc(e,t={}){let[r,o]=Sa.useState(null),[a,n]=Sa.useState(true),[s,l]=Sa.useState(null),i=Sa.useCallback(async()=>{n(true),l(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=`${kc(`/api/${e}`)}?${d.toString()}`,p=await fetch(c,{credentials:"include"});if(!p.ok)throw new Error(`HTTP ${p.status}: ${p.statusText}`);let y=await p.json();o(y.data??y);}catch(d){l(d instanceof Error?d.message:String(d));}finally{n(false);}},[e,t.page,t.limit,t.sort,t.order]);return Sa.useEffect(()=>{i();},[i]),{data:r,loading:a,error:s,refetch:i}}function wc(e,t="POST"){let[r,o]=Sa.useState(false),[a,n]=Sa.useState(null);return {mutate:Sa.useCallback(async l=>{o(true),n(null);try{let i=kc(`/api/${e}`),d=await fetch(i,{method:t,credentials:"include",headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0});if(!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);let c=await d.json();return c.data??c}catch(i){return n(i instanceof Error?i.message:String(i)),null}finally{o(false);}},[e,t]),loading:r,error:a}}var la=new Map;function da(e){if(!e.name||typeof e.name!="string")throw new Error("Plugin must have a valid name");la.has(e.name)&&console.warn(`Plugin "${e.name}" is already registered. Overwriting.`),la.set(e.name,e),e.apply&&e.apply({});}function Nc(e){la.delete(e);}function Cc(e){return la.get(e)}function Sc(){return Array.from(la.values())}function Rc(e){return Array.from(la.values()).filter(t=>t.hooks&&typeof t.hooks[e]=="function")}var Sy={name:"sample-plugin",version:"0.1.0",description:"A tiny sample plugin to demonstrate the extensibility surface",hooks:{onAdminReady:()=>{}}};da(Sy);var Ry={name:"sample-plugin-2",version:"0.1.0",description:"Second MVP plugin demonstrating beforeDeploy hook",hooks:{beforeDeploy:e=>({success:true})}};da(Ry);var ca=new Map;function pa(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");ca.set(e.id,e);}function Tc(e){ca.delete(e);}function Ac(e){return ca.get(e)}function Dc(){return Array.from(ca.values())}function Fc(e){return Array.from(ca.values()).filter(t=>t.category===e)}function Pc(e){let t=ca.get(e);return t?t.render:(console.warn(`Block "${e}" not found in registry`),null)}var Ty=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)})]})},Ay={id:"sample-block",label:"Sample Block",category:"demo",schema:[{name:"title",label:"Title",type:"text",required:true}],render:Ty};pa(Ay);var Fy=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)})]})},Py={id:"sample-block-2",label:"Sample Block 2",category:"demo",schema:[{name:"subtitle",label:"Subtitle",type:"text",required:false}],render:Fy};pa(Py);var ma=new Map;function ua(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");ma.set(e.id,e);}function Lc(e){ma.delete(e);}function Mc(e){return ma.get(e)}function Ec(){return Array.from(ma.values())}function $c(e){return Array.from(ma.values()).find(t=>t.type===e)}function Oc(e,t){let r=ma.get(e);if(!r)return console.warn(`Field "${e}" not found in registry`),null;let o=r.editor;return jsxRuntime.jsx(o,{...t})}var Ly=({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"}),My={id:"sample-text",type:"text",label:"Sample Text",editor:Ly};ua(My);var $y=({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"}),Oy={id:"sample-textarea",type:"textarea",label:"Sample Textarea",editor:$y};ua(Oy);var Uc=yr__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");yr__default.default.join(Uc,"use-sync-external-store.js");yr__default.default.join(Uc,"use-sync-external-store-with-selector.js");function Vy(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:l})=>{l.info(`Kyro Admin mounted at ${t} (API: ${r})`);let i=yr__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=yr__default.default.resolve(a.root.pathname,"..",o),c=yr__default.default.resolve(a.root.pathname,o),p=Io__default.default.existsSync(d)?d:Io__default.default.existsSync(c)?c:i;p!==i?l.info(`Loaded config from ${p}`):l.warn("Config file not found. Using defaults.");let y=yr__default.default.join(yr__default.default.dirname(p),".kyro-admin-config.json"),v="";try{let g=yr__default.default.join(yr__default.default.dirname(p),".env");Io__default.default.existsSync(g)&&dotenv.config({path:g});let h=await esbuild.build({entryPoints:[p],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/*"]});v=p.replace(/\.ts$/,".admin.mjs"),Io__default.default.writeFileSync(v,h.outputFiles[0].text,"utf8");let f=`
107
107
  import { parentPort } from 'worker_threads';
108
108
  import('${url.pathToFileURL(v).href}').then(mod => {
109
109
  const cfg = mod.default || mod;
@@ -132,7 +132,7 @@ code block
132
132
  }).catch(err => {
133
133
  parentPort.postMessage({ error: err.message });
134
134
  });
135
- `,y=new worker_threads.Worker(u,{eval:!0,env:{...process.env,NODE_OPTIONS:""}}),h=await new Promise((P,w)=>{y.on("message",P),y.on("error",w);let k=setTimeout(()=>{y.terminate(),w(new Error("Config loading timed out"));},3e4);});if(y.terminate(),h.error)throw new Error(h.error);let R=[{name:"metaTitle",type:"text",label:"Meta Title",admin:{description:"The title used for search engines (recommended < 60 chars).",autoGenerate:"title"}},{name:"metaDescription",type:"textarea",label:"Meta Description",admin:{description:"A brief summary for search engines (recommended < 160 chars).",autoGenerate:"content"}},{name:"keywords",type:"text",label:"Keywords",admin:{description:"Comma-separated list of keywords for this page."}},{name:"ogImage",type:"upload",label:"OpenGraph Image",relationTo:"media",admin:{description:"The image shown when shared on social media."}},{name:"twitter",type:"group",label:"Twitter Card",fields:[{name:"title",type:"text",label:"Twitter Title"},{name:"description",type:"textarea",label:"Twitter Description"},{name:"image",type:"upload",label:"Twitter Image",relationTo:"media"}]},{name:"advanced",type:"group",label:"Advanced Search Settings",fields:[{name:"noindex",type:"checkbox",label:"Hide from search engines (noindex)",defaultValue:!1},{name:"nofollow",type:"checkbox",label:"Do not follow links (nofollow)",defaultValue:!1},{name:"canonicalUrl",type:"text",label:"Canonical URL Override",admin:{description:"Leave empty to use the default canonical URL."}},{name:"structuredData",type:"code",label:"JSON-LD Structured Data",admin:{description:"Custom JSON-LD schema for this specific page."}}]}];for(let P of h.collections||[])if(P.seo){let w=P.fields?.find(k=>k.type==="tabs"&&k.name==="mainTabs");w?.tabs&&(w.tabs.find(k=>k.label==="SEO Settings")||w.tabs.push({label:"SEO Settings",fields:R}));}Do__default.default.writeFileSync(f,JSON.stringify(h,null,2),"utf8"),l.info("Project config loaded for admin");}catch(g){l.error(`Could not load project config: ${g.message}`);}finally{if(v&&Do__default.default.existsSync(v))try{Do__default.default.unlinkSync(v);}catch{}}n({vite:{plugins:[{name:"kyro-admin-tsx-loader",enforce:"pre",config(g){let x=g.esbuild,u=x?.exclude,y=/\/node_modules\/(?!.*@kyro-cms\/(admin|core))/;return {esbuild:{...x||{},exclude:u?Array.isArray(u)?[...u,y]:[u,y]:y}}}},{name:"kyro-cjs-shim",enforce:"pre",resolveId(g){if(g.includes("react/compiler-runtime"))return "\0react-compiler-runtime";if(g==="debug"||g.includes("debug/src/browser.js"))return "\0debug-browser"},load(g){if(g==="\0react-compiler-runtime")return `
135
+ `,m=new worker_threads.Worker(f,{eval:!0,env:{...process.env,NODE_OPTIONS:""}}),w=await new Promise((T,k)=>{m.on("message",T),m.on("error",k);let x=setTimeout(()=>{m.terminate(),k(new Error("Config loading timed out"));},3e4);});if(m.terminate(),w.error)throw new Error(w.error);let A=[{name:"metaTitle",type:"text",label:"Meta Title",admin:{description:"The title used for search engines (recommended < 60 chars).",autoGenerate:"title"}},{name:"metaDescription",type:"textarea",label:"Meta Description",admin:{description:"A brief summary for search engines (recommended < 160 chars).",autoGenerate:"content"}},{name:"keywords",type:"text",label:"Keywords",admin:{description:"Comma-separated list of keywords for this page."}},{name:"ogImage",type:"upload",label:"OpenGraph Image",relationTo:"media",admin:{description:"The image shown when shared on social media."}},{name:"twitter",type:"group",label:"Twitter Card",fields:[{name:"title",type:"text",label:"Twitter Title"},{name:"description",type:"textarea",label:"Twitter Description"},{name:"image",type:"upload",label:"Twitter Image",relationTo:"media"}]},{name:"advanced",type:"group",label:"Advanced Search Settings",fields:[{name:"noindex",type:"checkbox",label:"Hide from search engines (noindex)",defaultValue:!1},{name:"nofollow",type:"checkbox",label:"Do not follow links (nofollow)",defaultValue:!1},{name:"canonicalUrl",type:"text",label:"Canonical URL Override",admin:{description:"Leave empty to use the default canonical URL."}},{name:"structuredData",type:"code",label:"JSON-LD Structured Data",admin:{description:"Custom JSON-LD schema for this specific page."}}]}];for(let T of w.collections||[])if(T.seo){let k=T.fields?.find(x=>x.type==="tabs"&&x.name==="tabs");k?.tabs&&(k.tabs.find(x=>x.label==="SEO Settings")||k.tabs.push({label:"SEO Settings",fields:A}));}Io__default.default.writeFileSync(y,JSON.stringify(w,null,2),"utf8"),l.info("Project config loaded for admin");}catch(g){l.error(`Could not load project config: ${g.message}`);}finally{if(v&&Io__default.default.existsSync(v))try{Io__default.default.unlinkSync(v);}catch{}}n({vite:{plugins:[{name:"kyro-admin-tsx-loader",enforce:"pre",config(g){let h=g.esbuild,f=h?.exclude,m=/\/node_modules\/(?!.*@kyro-cms\/(admin|core))/;return {esbuild:{...h||{},exclude:f?Array.isArray(f)?[...f,m]:[f,m]:m}}}},{name:"kyro-cjs-shim",enforce:"pre",resolveId(g){if(g.includes("react/compiler-runtime"))return "\0react-compiler-runtime";if(g==="debug"||g.includes("debug/src/browser.js"))return "\0debug-browser"},load(g){if(g==="\0react-compiler-runtime")return `
136
136
  import React from "react";
137
137
  export function c(size) {
138
138
  const internals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
@@ -154,4 +154,4 @@ debug.enable = function() {};
154
154
  debug.disable = function() {};
155
155
  debug.enabled = function() { return false; };
156
156
  export default debug;
157
- `}}],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(f)},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 b=[{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 g of b){let x=`${t}${g.pattern}`.replace(/\/$/,"");s({pattern:x||"/",entrypoint:yr__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,g.entrypoint)});}},"astro:build:done":({logger:a})=>{a.info("Kyro Admin build complete");}}}}exports.ActionBar=si;exports.Admin=iy;exports.AutoForm=Wa;exports.Badge=Pt;exports.BulkActionsBar=ly;exports.Button=gs;exports.ConfirmModal=Ns;exports.CountBadge=vs;exports.CreateView=di;exports.DARK_THEME=Fa;exports.DarkThemeProvider=Rn;exports.DetailView=li;exports.Dropdown=So;exports.DropdownItem=jt;exports.DropdownSeparator=Ka;exports.ExtDarkThemeProvider=Rn;exports.ExtLightThemeProvider=Tn;exports.ExtThemeProvider=hr;exports.Header=gA;exports.LIGHT_THEME=_o;exports.LightThemeProvider=Tn;exports.ListView=ks;exports.LoginPage=mi;exports.Modal=Ot;exports.PageHeader=Dt;exports.SlidePanel=dr;exports.Spinner=kr;exports.ThemeProvider=hr;exports.Toast=Jd;exports.ToastProvider=X3;exports.VersionHistoryPanel=vy;exports.adminPath=Ge;exports.afterDeploy=pc;exports.apiPath=br;exports.beforeDeploy=cc;exports.emitAdminReady=mc;exports.emitAfterDeploy=yc;exports.emitBeforeDeploy=uc;exports.getBlock=Cc;exports.getBlocks=Sc;exports.getBlocksByCategory=Tc;exports.getField=Pc;exports.getFieldByType=Bc;exports.getFields=Ic;exports.getPlugin=kc;exports.getPlugins=hc;exports.getPluginsWithHook=wc;exports.kyroAdmin=$y;exports.mergeThemes=Da;exports.onAdminReady=ts;exports.paths=Yc;exports.registerBlock=pa;exports.registerField=ua;exports.registerPlugin=da;exports.resolveAdmin=ss;exports.resolveApi=tt;exports.unregisterBlock=Nc;exports.unregisterField=Dc;exports.unregisterPlugin=xc;exports.useBlockRenderer=Rc;exports.useExtTheme=Ho;exports.useFieldRenderer=Lc;exports.useKyroMutation=bc;exports.useKyroQuery=gc;exports.useTheme=Ho;exports.useToast=Y3;
157
+ `}}],resolve:{alias:{"kyro:config":p}},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 b=[{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 g of b){let h=`${t}${g.pattern}`.replace(/\/$/,"");s({pattern:h||"/",entrypoint:yr__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,g.entrypoint)});}},"astro:build:done":({logger:a})=>{a.info("Kyro Admin build complete");}}}}exports.ActionBar=ci;exports.Admin=yy;exports.AutoForm=qa;exports.Badge=St;exports.BulkActionsBar=fy;exports.Button=hs;exports.ConfirmModal=Ts;exports.CountBadge=ks;exports.CreateView=ui;exports.DARK_THEME=Fa;exports.DarkThemeProvider=Pn;exports.DetailView=mi;exports.Dropdown=Ro;exports.DropdownItem=It;exports.DropdownSeparator=Ga;exports.ExtDarkThemeProvider=Pn;exports.ExtLightThemeProvider=Fn;exports.ExtThemeProvider=Nr;exports.Header=FA;exports.LIGHT_THEME=Ho;exports.LightThemeProvider=Fn;exports.ListView=Cs;exports.LoginPage=vi;exports.Modal=Pt;exports.PageHeader=Ft;exports.SlidePanel=lr;exports.Spinner=wr;exports.ThemeProvider=Nr;exports.Toast=Qd;exports.ToastProvider=pR;exports.VersionHistoryPanel=Ny;exports.adminPath=ze;exports.afterDeploy=fc;exports.apiPath=kr;exports.beforeDeploy=yc;exports.emitAdminReady=vc;exports.emitAfterDeploy=bc;exports.emitBeforeDeploy=gc;exports.getBlock=Ac;exports.getBlocks=Dc;exports.getBlocksByCategory=Fc;exports.getField=Mc;exports.getFieldByType=$c;exports.getFields=Ec;exports.getPlugin=Cc;exports.getPlugins=Sc;exports.getPluginsWithHook=Rc;exports.kyroAdmin=Vy;exports.mergeThemes=Pa;exports.onAdminReady=is;exports.paths=tp;exports.registerBlock=pa;exports.registerField=ua;exports.registerPlugin=da;exports.resolveAdmin=ps;exports.resolveApi=qe;exports.unregisterBlock=Tc;exports.unregisterField=Lc;exports.unregisterPlugin=Nc;exports.useBlockRenderer=Pc;exports.useExtTheme=Vo;exports.useFieldRenderer=Oc;exports.useKyroMutation=wc;exports.useKyroQuery=hc;exports.useTheme=Vo;exports.useToast=mR;