@kyro-cms/admin 0.10.20 → 0.11.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.js CHANGED
@@ -1,4 +1,4 @@
1
- import ka,{createContext,lazy,useState,useRef,useEffect,useCallback,useContext,useMemo,Suspense}from'react';import {create,useStore}from'zustand';import {persist,createJSONStorage}from'zustand/middleware';import {Video,Mail,Clock,Database,Users,Tag,Image,Activity,CircleHelp,Sparkles,Blocks,Columns3,Link2,ListOrdered,Box,Star,AlignLeft,ChevronDown,File,Code,List,Heading1,GripVertical,Copy,X,Plus,ChevronRight,ChevronUp,Search,LoaderCircle,Check,RefreshCw,CodeXml,FileText,Music,Film,Undo,Redo,Bold,Italic,Underline,Strikethrough,Highlighter,Palette,CheckSquare,Quote,Terminal,Minus,AlignCenter,AlignRight,Link,Minimize2,Maximize2,Grid3X3,Filter,FolderPlus,FolderInput,Folder,Trash2,Archive,Download,Crop,Server,Pencil,TriangleAlert,Eye,EllipsisVertical,Send,Info,ShieldAlert,CircleCheck,History,CheckCircle2,User,GitCompare,Undo2,ExternalLink,Settings,Shield,Hexagon,Network,Sun,Moon,LogOut,ArrowRight,LayoutDashboard,ArrowUpRight,Webhook,Zap,Pause,Play,Key,Lock,EyeOff,CirclePlay,RefreshCcw,Save,UserPlus,LockOpen}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {useEditor,EditorContent}from'@tiptap/react';import gp from'@tiptap/starter-kit';import bp from'@tiptap/extension-link';import xp from'@tiptap/extension-image';import kp from'@tiptap/extension-text-align';import hp from'@tiptap/extension-underline';import wp from'@tiptap/extension-highlight';import Np from'@tiptap/extension-task-list';import Cp from'@tiptap/extension-task-item';import {TextStyle}from'@tiptap/extension-text-style';import Tp from'@tiptap/extension-color';import ip,{convertToPixelCrop,centerCrop,makeAspectCrop}from'react-image-crop';import'react-image-crop/dist/ReactCrop.css';import {githubLight}from'@uiw/codemirror-theme-github';import {aura}from'@uiw/codemirror-theme-aura';import {createStorage}from'unstorage';import im from'unstorage/drivers/indexedb';import {mediaCollections,authCollections,minimalCollections,starterCollections,blogCollections,ecommerceCollections,kitchenSinkCollections,allSettingsGlobals,coreSettingsGlobals}from'@kyro-cms/core/templates';import Ro from'fs';import {createStore}from'zustand/vanilla';import {useSensors,useSensor,PointerSensor,KeyboardSensor,DndContext,closestCenter,DragOverlay,useDraggable}from'@dnd-kit/core';import {useSortable,SortableContext,verticalListSortingStrategy}from'@dnd-kit/sortable';import {CSS}from'@dnd-kit/utilities';import mu from'@uiw/react-codemirror';import {json}from'@codemirror/lang-json';import'@kyro-cms/core';import fr from'path';import {pathToFileURL}from'url';import {build}from'esbuild';import {config}from'dotenv';import {Worker}from'worker_threads';var Ye=typeof __KYRO_ADMIN_PATH__<"u"?__KYRO_ADMIN_PATH__:"/admin",io=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function qe(e){if(e.startsWith("http")||e.startsWith(io))return e;if(e.startsWith("/api/"))return io+e.slice(4);let t=e.startsWith("/")?"":"/";return `${io}${t}${e}`}function ts(e){return e.startsWith("http")||e.startsWith(Ye)?e:e.startsWith("/admin/")?Ye+e.slice(6):e.startsWith("/")?Ye+e:e}function ua(e){return !e||typeof e!="string"?"":e.startsWith("http")||e.startsWith("blob:")||e.startsWith("data:")||e.startsWith("/")?e:`/${e}`}var Ec={admin:Ye,api:io,resolveApi:qe,resolveAdmin:ts,resolveMedia:ua};var Lr=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=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)};create()(persist(e=>({mode:"light",setMode:t=>e({mode:t}),toggleMode:()=>e(t=>({mode:t.mode==="light"?"dark":"light"}))}),{name:"kyro-theme"}));var ot=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})}));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}})}));create((e,t)=>({cache:{},setCache:(r,o)=>e(a=>({cache:{...a.cache,[r]:{data:o,loading:false,error:null,lastFetch:Date.now()}}})),setLoading:(r,o)=>e(a=>({cache:{...a.cache,[r]:{...a.cache[r],loading:o,error:null}}})),setError:(r,o)=>e(a=>({cache:{...a.cache,[r]:{data:null,loading:false,error:o,lastFetch:null}}})),getCache:r=>t().cache[r]||null,invalidateCache:r=>e(o=>{if(r){let{[r]:a,...n}=o.cache;return {cache:n}}return {cache:{}}})}));var Uc="/api/auth/refresh";async function ii(){try{return (await fetch(qe(Uc),{method:"POST",credentials:"include"})).ok}catch{return false}}async function ct(e,t={}){let r={};t.body instanceof FormData||(r["Content-Type"]="application/json"),Object.assign(r,t.headers);let o=await fetch(qe(e),{...t,credentials:"include",headers:r});if(o.status===401){if(await ii()){let n={};return t.body instanceof FormData||(n["Content-Type"]="application/json"),Object.assign(n,t.headers),await fetch(qe(e),{...t,credentials:"include",headers:n})}window.location.href="/admin/login";}return o}async function De(e,t){let{autoToast:r=true,...o}=t||{},a=await ct(e,o);if(!a.ok){let n=`GET Failed: ${a.status}`;throw r&&$.error(n),new Error(n)}return a.json()}async function et(e,t,r){let{autoToast:o=true,...a}=r||{},n=await ct(e,{method:"POST",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`POST Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function Xt(e,t,r){let{autoToast:o=true,...a}=r||{},n=await ct(e,{method:"PATCH",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`Update Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&$.error(s),new Error(s)}return n.json()}async function kt(e,t){let{autoToast:r=true,...o}=t||{},a=await ct(e,{method:"DELETE",...o});if(!a.ok){let s=`Delete Failed: ${a.status}`;try{let i=await a.json();i.error&&(s=i.error);}catch{}throw r&&$.error(s),new Error(s)}let n=await a.text();return n?JSON.parse(n):{}}function Mr(e){let t=e.includes("?")?"&":"?";return `${e}${t}t=${Date.now()}`}function Ja(e,t,r=50){return !e||t.length===0?`limit=${r}`:`${t.map(a=>`where[${a}][contains]=${encodeURIComponent(e)}`).join("&")}&limit=${r}`}async function ya(e,t,r){if(!r){let o=await ct(e,{method:"POST",body:t});if(!o.ok)throw new Error(`Upload Error: ${o.status}`);return o.json()}return new Promise((o,a)=>{let n=new XMLHttpRequest;n.open("POST",qe(e)),n.withCredentials=true,n.upload.addEventListener("progress",s=>{s.lengthComputable&&r(Math.round(s.loaded/s.total*100));}),n.addEventListener("load",()=>{if(n.status>=200&&n.status<300)try{o(JSON.parse(n.responseText));}catch{a(new Error("Invalid JSON response"));}else n.status===401?ii().then(s=>{if(!s){a(new Error(`Upload Error: ${n.status}`));return}let i=new XMLHttpRequest;i.open("POST",qe(e)),i.withCredentials=true,i.upload.addEventListener("progress",l=>{l.lengthComputable&&r(Math.round(l.loaded/l.total*100));}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{o(JSON.parse(i.responseText));}catch{a(new Error("Invalid JSON"));}else a(new Error(`Upload Error: ${i.status}`));}),i.addEventListener("error",()=>a(new Error("Network error"))),i.send(t);}):a(new Error(`Upload Error: ${n.status}`));}),n.addEventListener("error",()=>a(new Error("Network error during upload"))),n.send(t);})}function Ar({size:e="md",className:t=""}){return jsx("svg",{className:`kyro-spinner kyro-spinner-${e} ${t}`,viewBox:"0 0 24 24",fill:"none",children:jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"40 20"})})}function Ot({variant:e,count:t=1,className:r=""}){let o={text:"h-3 rounded-md",circle:"size-10 rounded-full",rect:"h-10 rounded-xl",card:"h-32 rounded-2xl","table-row":"h-14 rounded-xl","media-card":"aspect-square rounded-2xl","stat-card":"h-24 rounded-2xl"};return jsx(Fragment,{children:Array.from({length:t}).map((a,n)=>jsx("div",{className:`kyro-shimmer ${o[e]} ${r}`},n))})}function Ji({back:e}){return e.href?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:jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}):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:jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})})}function jc({breadcrumbs:e}){return e?.map((t,r)=>jsxs(ka.Fragment,{children:[r>0&&jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),t.href||t.onClick?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}):jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:t.label})]},r))}function Xi({actions:e}){return Array.isArray(e)?jsx("div",{className:"flex items-center gap-3",children:e.map((t,r)=>jsxs("button",{type:"button",onClick:t.onClick,className:`flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm transition-all shadow-lg shadow-[var(--kyro-primary)]/10 ${t.variant==="outline"?"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]":t.variant==="ghost"?"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] shadow-none":"kyro-btn-primary hover:opacity-90"} ${t.className||""}`,children:[t.icon&&jsx(t.icon,{className:"w-4 h-4"}),t.label]},r))}):jsx(Fragment,{children:e})}function Qi({action:e}){return jsxs("button",{type:"button",onClick:e.onClick,className:`kyro-btn kyro-btn-primary flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10 w-full lg:w-auto justify-center ${e.className||""}`,children:[e.icon&&jsx(e.icon,{className:"w-4 h-4"}),e.label]})}function Ft({title:e,description:t,icon:r,breadcrumbs:o,metadata:a,back:n,action:s,actions:i,children:l}){let d=o?.[o.length-1];return jsxs("div",{className:"surface-tile px-3 md:px-6 py-3 md:pt-4 mb-4 md:mb-8",children:[jsxs("div",{className:"md:hidden space-y-2",children:[(o||n)&&jsxs("div",{className:"flex items-center gap-2",children:[n&&jsx(Ji,{back:n}),jsxs("details",{className:"group [&::-webkit-details-marker]:hidden flex-1 min-w-0",children:[jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[jsx("span",{className:"flex-1 text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] truncate",children:d?.label||""}),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:jsx("path",{d:"M6 9l6 6 6-6"})})]}),jsxs("div",{className:"mt-2 pt-2 border-t border-[var(--kyro-border)] space-y-2",children:[o&&jsx("div",{className:"flex items-center gap-2",children:o.map((c,m)=>jsxs(ka.Fragment,{children:[m>0&&jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),c.href||c.onClick?jsx("a",{href:c.href,onClick:u=>{c.onClick&&(u.preventDefault(),c.onClick());},className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] transition-all",children:c.label}):jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:c.label})]},m))}),a&&jsx("div",{className:"flex items-center gap-2 flex-wrap",children:a.map((c,m)=>jsx(ka.Fragment,{children:c},m))}),l]})]})]}),jsxs("div",{className:"flex items-center gap-2",children:[r&&jsx(r,{className:"w-5 h-5 text-[var(--kyro-primary)] shrink-0"}),e&&jsx("h1",{className:"text-lg font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e}),a&&!t&&jsx("span",{className:"h-2 w-2 rounded-full bg-[var(--kyro-primary)] shrink-0"})]}),t&&jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0 text-xs",children:t}),a&&jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxs(ka.Fragment,{children:[m===0&&jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))})]})]}),jsxs("div",{className:"hidden md:flex md:flex-row md:items-center justify-between gap-6",children:[jsxs("div",{className:"min-w-0 flex-1",children:[(o||n)&&jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n&&jsx(Ji,{back:n}),o&&jsx(jc,{breadcrumbs:o})]}),jsxs("div",{className:"flex items-center gap-3",children:[r&&jsx(r,{className:"w-6 h-6 text-[var(--kyro-primary)]"}),e&&jsx("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e})]}),(t||a)&&jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 mt-1",children:[t&&jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0",children:t}),a&&jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxs(ka.Fragment,{children:[m===0&&(t||m>0)&&jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))}),l]})]}),jsxs("div",{className:"flex items-center gap-3 flex-wrap shrink-0",children:[i&&jsx(Xi,{actions:i}),s&&jsx(Qi,{action:s})]})]}),(i||s)&&jsxs("div",{className:"md:hidden flex items-center gap-2 mt-3 pt-3 border-t border-[var(--kyro-border)]",children:[s&&jsx(Qi,{action:s}),i&&jsx(Xi,{actions:i})]})]})}var _c={draft:{class:"bg-gray-100 text-gray-600",label:"Draft"},published:{class:"bg-green-100 text-green-700",label:"Published"},scheduled:{class:"bg-blue-100 text-blue-700",label:"Scheduled"},archived:{class:"bg-yellow-100 text-yellow-700",label:"Archived"},active:{class:"bg-green-100 text-green-700",label:"Active"},inactive:{class:"bg-gray-100 text-gray-600",label:"Inactive"},pending:{class:"bg-yellow-100 text-yellow-700",label:"Pending"},completed:{class:"bg-green-100 text-green-700",label:"Completed"},cancelled:{class:"bg-red-100 text-red-700",label:"Cancelled"}};function Pt({variant:e,status:t,className:r="",children:o,dot:a=false}){let n=e||t||"default",s=_c[n],i=s?s.class:`kyro-badge-${n}`;return jsxs("span",{className:`kyro-badge ${i} ${r}`,children:[a&&jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current mr-1.5 opacity-60"}),o||s?.label||n]})}function ps({count:e,max:t=99}){return e===0?null: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 ms({variant:e="secondary",size:t="md",loading:r=false,children:o,className:a="",disabled:n,...s}){let i="kyro-btn",l=`kyro-btn-${e}`,d=`kyro-btn-${t}`;return jsxs("button",{type:"button",className:`${i} ${l} ${d} ${a}`,disabled:n||r,...s,children:[r?jsx("span",{className:"kyro-btn-loading",children:jsx("svg",{className:"kyro-btn-spinner",viewBox:"0 0 24 24",children:jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",fill:"none",strokeDasharray:"60 30"})})}):null,jsx("span",{className:r?"kyro-btn-text-hidden":"",children:o})]})}function fn({page:e,totalPages:t,totalDocs:r,limit:o,onPageChange:a,onLimitChange:n}){return t<=1?null: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?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]}):jsx("span",{}),jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-center",children:[n&&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:[jsx("option",{value:10,children:"10/page"}),jsx("option",{value:25,children:"25/page"}),jsx("option",{value:50,children:"50/page"}),jsx("option",{value:100,children:"100/page"})]}),jsxs("span",{className:"text-xs text-[var(--kyro-text-secondary)] font-medium",children:["Page ",e," of ",t]}),jsxs("div",{className:"flex gap-1",children:[jsx(ms,{variant:"ghost",size:"sm",disabled:e<=1,onClick:()=>a(e-1),children:"\u2190 Previous"}),jsx(ms,{variant:"ghost",size:"sm",disabled:e>=t,onClick:()=>a(e+1),children:"Next \u2192"})]})]})]})}function uo(e,t,r){return r in t?t[r]:us(e,t,r)}function us(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=us(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=us(o.fields||[],a,r);if(n!==void 0)return n}}}}function fs({collection:e,collectionSlug:t,initialDocs:r=[],initialTotal:o=0,onCreate:a,onEdit:n,config:s}){let i=t||e.slug,{permissions:l}=Lr(),d=l?.collections?.[i]?.create!==false,c=l?.collections?.[i]?.delete!==false,m=l?.collections?.[i]?.update!==false,u=()=>{d&&(a?a():window.location.href=`${Ye}/${i}/new`);},g=D=>{n?n(D):window.location.href=`${Ye}/${i}/${D}`;},[x,f]=useState(r),[y,b]=useState(o),[v,R]=useState(false),[L,C]=useState(1),[w,N]=useState(10),[p,A]=useState(new Set),[O,F]=useState(""),[P,S]=useState([]),{confirm:M,alert:j}=ot(),se=()=>{S([...P,{field:"",operator:"equals",value:""}]);},ie=()=>{F(""),S([]),je(null);},ue=D=>{S(P.filter((G,ee)=>ee!==D));},oe=(D,G)=>{S(P.map((ee,sr)=>sr===D?{...ee,...G}:ee));},[ne,je]=useState(null),[ft,B]=useState(false),[K,ce]=useState(false);function he(D){let G=[];for(let ee of D||[])if(!(!ee.name||ee.hidden===true||ee.admin?.hidden||ee.name==="id"))if(ee.type==="tabs"&&ee.tabs)for(let sr of ee.tabs)sr.fields&&G.push(...he(sr.fields));else (ee.type==="row"||ee.type==="collapsible")&&ee.fields?G.push(...he(ee.fields)):G.push(ee);return G}let Pe=useMemo(()=>he(e.fields),[e.fields]),Ce=typeof e.admin?.useAsTitle=="string"?e.admin.useAsTitle:Pe.find(D=>D.type!=="group"&&typeof D.name=="string")?.name,[I,z]=useState(()=>{let D;return e.admin?.defaultColumns?D=[...e.admin?.defaultColumns||[]]:D=Pe.slice(0,4).map(G=>G.name).filter(G=>!!G),Ce&&D.includes(Ce)&&(D=[Ce,...D.filter(G=>G!==Ce)]),D.includes("updatedAt")||D.push("updatedAt"),new Set(D)}),Ve=useCallback(D=>{z(G=>{let ee=new Set(G);return ee.has(D)?ee.delete(D):ee.add(D),ee});},[]);function ye(D){let G=Pe.find(ee=>ee.name===D);return G&&G.type==="group"&&G.fields?.[0]?.name?`${D}.${G.fields[0].name}`:D}let Se=useCallback(D=>{let G=ye(D);je(ee=>ee&&ee.field===G?{field:G,direction:ee.direction==="asc"?"desc":"asc"}:{field:G,direction:"asc"});},[]),lt=useMemo(()=>{let D=Pe.filter(G=>!!G.name&&I.has(G.name));return I.has("status")&&D.push({name:"status",type:"select",label:"Status",options:[{value:"draft",label:"Draft"},{value:"published",label:"Published"}]}),D},[Pe,I]);function At(D){return !D.name||!Ce?false:D.name===Ce||D.type==="group"&&D.fields?.[0]?.name===Ce}function qt(D,G){return G.name?uo(e.fields,D,G.name)??null:null}let vt=useCallback(async()=>{R(true);try{let D=new URLSearchParams({page:L.toString(),limit:w.toString()});O&&D.append("search",O),ne&&D.append("sort",ne.field),ne&&D.append("order",ne.direction),P.length>0&&D.append("filters",JSON.stringify(P));let G=await De(Mr(`/api/${i}?${D}`),{autoToast:!1});f(G.docs||[]),b(G.totalDocs||0);}catch(D){console.error("Failed to load docs:",D);}finally{R(false);}},[i,L,w,O,ne,P]);useEffect(()=>{x.length===0&&o===0&&vt();},[]);let q=useRef(true);useEffect(()=>{if(q.current){q.current=false;return}vt();},[L,w,O,ne,P]);let X$1=()=>{p.size===x.length?A(new Set):A(new Set(x.map(D=>D.id)));},le=D=>{let G=new Set(p);G.has(D)?G.delete(D):G.add(D),A(G);},xe=()=>{M({title:"Delete Documents",message:`Are you sure you want to delete ${p.size} document(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let D of Array.from(p))await kt(`/api/${i}/${D}`);A(new Set),vt(),$.success("Documents deleted");}catch(D){console.error("Bulk delete failed:",D),$.error("Failed to delete some documents");}}});},we=D=>{M({title:"Delete Document",message:"Are you sure you want to delete this document? This cannot be undone.",variant:"danger",onConfirm:async()=>{try{await kt(`/api/${i}/${D}`),vt(),$.success("Document deleted");}catch(G){console.error("Delete failed:",G),$.error("Failed to delete document");}}});},Qe=Math.ceil(y/w),Ct=O||P.length>0||ne;return jsxs("div",{className:"space-y-6",children:[jsx(Ft,{title:e.label||i,description:e.admin?.description||`Manage your ${e.label||i}`,metadata:y>0?[jsxs("span",{className:"text-xs font-bold opacity-60",children:[y," documents"]},"count")]:void 0,action:d?{label:`Create ${e.singularLabel||e.label||i}`,onClick:u,icon:Plus}:void 0}),jsxs("div",{className:"surface-tile p-4 flex flex-col lg:flex-row gap-4 items-start lg:items-center",children:[jsxs("div",{className:"relative flex-1 w-full lg:max-w-md",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",placeholder:"Search...",value:O,onChange:D=>F(D.target.value),className:"w-full pl-10 pr-4 py-2.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-sm font-medium text-[var(--kyro-text-primary)] placeholder:text-[var(--kyro-text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent"})]}),jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[jsxs("button",{type:"button",onClick:()=>B(!ft),className:`flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm transition-all ${ft||P.length>0?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)]":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsx(Filter,{className:"w-4 h-4"}),"Filters",P.length>0&&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})]}),jsxs("div",{className:"relative",children:[jsxs("button",{type:"button",onClick:()=>ce(!K),className:"flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-all",children:[jsx(Columns3,{className:"w-4 h-4"}),"Columns"]}),K&&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:[jsx("div",{className:"p-3 border-b border-[var(--kyro-border)]",children:jsx("span",{className:"text-xs font-bold tracking-wider text-[var(--kyro-text-secondary)]",children:"Toggle Columns"})}),jsx("div",{className:"p-2 max-h-64 overflow-y-auto",children:Pe.map(D=>D.name?jsxs("label",{className:"flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-[var(--kyro-surface-accent)] cursor-pointer",children:[jsx("input",{type:"checkbox",checked:I.has(D.name),onChange:()=>Ve(D.name),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"}),jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:D.label||D.name})]},D.name):null)})]})]}),Ct&&jsx("button",{type:"button",onClick:ie,className:"px-4 py-2 rounded-xl font-bold text-sm text-red-500 hover:bg-red-50 dark:hover:bg-red-500/10 transition-all",children:"Clear All"})]})]}),ft&&jsxs("div",{className:"surface-tile p-4 border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsx("h3",{className:"font-medium text-[var(--kyro-text-primary)]",children:"Advanced Filters"}),jsxs("button",{type:"button",onClick:se,className:"flex items-center gap-2 px-3 py-1.5 text-sm font-bold text-[var(--kyro-sidebar-active)] hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all",children:[jsx(Plus,{className:"w-4 h-4"}),"Add Filter"]})]}),jsxs("div",{className:"space-y-3",children:[P.map((D,G)=>jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[jsx("select",{value:D.field,onChange:ee=>oe(G,{field:ee.target.value}),className:"px-3 py-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg text-sm font-medium text-[var(--kyro-text-primary)]",children:Pe.map(ee=>jsx("option",{value:ee.name,children:ee.label||ee.name},ee.name))}),jsxs("select",{value:D.operator,onChange:ee=>oe(G,{operator:ee.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:[jsx("option",{value:"equals",children:"Equals"}),jsx("option",{value:"contains",children:"Contains"}),jsx("option",{value:"gt",children:"Greater than"}),jsx("option",{value:"lt",children:"Less than"}),jsx("option",{value:"gte",children:"Greater or equal"}),jsx("option",{value:"lte",children:"Less or equal"})]}),jsx("input",{type:"text",value:D.value,onChange:ee=>oe(G,{value:ee.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)]"}),jsx("button",{type:"button",onClick:()=>ue(G),className:"p-2 text-[var(--kyro-text-muted)] hover:text-red-500 transition-colors",children:jsx(X,{className:"w-4 h-4"})})]},G)),P.length===0&&jsx("p",{className:"text-sm text-[var(--kyro-text-muted)]",children:'No filters applied. Click "Add Filter" to create one.'})]})]}),p.size>0&&jsxs("div",{className:"surface-tile p-4 flex items-center justify-between border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:[p.size," selected"]}),jsxs("div",{className:"flex gap-2",children:[c&&jsxs("button",{type:"button",onClick:xe,className:"flex items-center gap-2 px-4 py-2 bg-red-500 text-white rounded-lg font-bold text-sm hover:bg-red-600 transition-all",children:[jsx(Trash2,{className:"w-4 h-4"}),"Delete Selected"]}),jsx("button",{type:"button",onClick:()=>A(new Set),className:"px-4 py-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] font-bold text-sm transition-all",children:"Cancel"})]})]}),jsx("div",{className:"surface-tile overflow-hidden",children:v?jsx("div",{className:"space-y-2 p-4",children:jsx(Ot,{variant:"table-row",count:8})}):x.length===0?jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8",children:[jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:jsx(Archive,{className:"w-4 h-4"})}),jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:"No documents found"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:Ct?"Try adjusting your filters or search query.":`Get started by creating your first ${(e.singularLabel||e.label||i).toLowerCase()}.`}),!Ct&&d&&jsxs("button",{type:"button",onClick:u,className:"mt-4 kyro-btn kyro-btn-md kyro-btn-primary shadow-md flex items-center gap-2",children:[jsx(Plus,{className:"w-4 h-4"}),"Create"," ",String(e.singularLabel||e.label||i)]})]}):jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-left",children:[jsx("thead",{children:jsxs("tr",{className:"text-[var(--kyro-text-secondary)] font-bold text-[10px] tracking-[0.3em] border-b border-[var(--kyro-border)] whitespace-nowrap",children:[jsx("th",{className:"px-4 py-4 w-10",children:jsx("input",{type:"checkbox",checked:p.size===x.length&&x.length>0,onChange:X$1,className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),lt.map(D=>jsx("th",{className:"px-4 py-4 cursor-pointer hover:text-[var(--kyro-text-primary)] transition-colors",onClick:()=>Se(D.name),children:jsxs("div",{className:"flex items-center gap-2",children:[qc(lt,D.type)??(D.label||D.name),ne&&ne.field===D.name&&jsx(ChevronUp,{className:"w-4 h-4"})]})},D.name)),e.timestamps?jsx("th",{className:"px-4 py-4",children:"Created"}):null,jsx("th",{className:"px-4 py-4 text-right",children:"Actions"})]})}),jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:x.map(D=>jsxs("tr",{className:"hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer group",onClick:()=>g(D.id),children:[jsx("td",{className:"px-4 py-3",onClick:G=>G.stopPropagation(),children:jsx("input",{type:"checkbox",checked:p.has(D.id),onChange:()=>le(D.id),className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),lt.map(G=>{let ee=qt(D,G),sr=G.type==="select"&&ee?G.options?.find(no=>no.value===ee)?.label||ee:Wc(ee,G.type);return jsx("td",{className:`px-4 py-3 ${At(G)?"font-medium text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)]"}`,children:sr},G.name)}),e.timestamps?jsx("td",{className:"px-4 py-3 text-sm text-[var(--kyro-text-secondary)]",children:D.createdAt?new Date(D.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"\u2014"}):null,jsx("td",{className:"px-4 py-3 text-right",onClick:G=>G.stopPropagation(),children:jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>g(D.id),className:"flex items-center gap-2 px-3 py-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg text-sm font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-all",title:m?"Edit":"View",children:jsx(Pencil,{className:"w-4 h-4"})}),c&&jsx("button",{type:"button",onClick:()=>we(D.id),className:"inline-flex items-center justify-center w-8 h-8 rounded-md text-[var(--kyro-text-muted)] hover:bg-red-50 hover:text-red-500 dark:hover:bg-red-500/10 transition-colors",title:"Delete",children:jsx(Trash2,{className:"w-4 h-4"})})]})})]},D.id))})]})})}),jsx(fn,{page:L,totalPages:Qe,totalDocs:y,limit:w,onPageChange:C,onLimitChange:D=>{N(D),C(1);}})]})}function Wc(e,t){return e==null?"\u2014":typeof e=="boolean"?e?"Yes":"No":t==="number"||t==="price"?String(e):t==="date"||t==="datetime"?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):Array.isArray(e)?e.map(r=>r&&typeof r=="object"?r.title||r.name||r.email||r.filename||r.url||JSON.stringify(r).slice(0,30):String(r??"").slice(0,30)).filter(Boolean).join(", "):typeof e=="object"?e.title?e.title:e.name?e.name:e.email?e.email:JSON.stringify(e).slice(0,50):String(e).slice(0,60)}function qc(e,t){return t!=="tabs"?void 0:e[0]?.tabs?.[0]?.fields?.[0]?.label}var vs=(e,t)=>{let r=e?.toLowerCase()||"",o=t?.toLowerCase()||"";return r.startsWith("image/")||o.match(/\.(jpe?g|png|gif|webp|avif|svg)$/i)?"image":r.startsWith("video/")||o.match(/\.(mp4|webm|ogg|mov)$/i)?"video":r.startsWith("audio/")||o.match(/\.(mp3|wav|ogg|m4a)$/i)?"audio":r.includes("pdf")||o.endsWith(".pdf")?"pdf":o.match(/\.(doc|docx|txt|rtf|odt)$/i)?"document":o.match(/\.(xls|xlsx|csv)$/i)?"spreadsheet":o.match(/\.(zip|tar|gz|7z|rar)$/i)?"archive":"other"},al=({type:e,className:t})=>{switch(e){case "image":return jsx(Image,{className:t});case "video":return jsx(Film,{className:t});case "audio":return jsx(Music,{className:t});case "pdf":case "document":return jsx(FileText,{className:t});default:return jsx(File,{className:t})}};function lr({field:e,value:t,onChange:r,disabled:o}){let a=useRef(null),n=useRef(null),[s,i]=useState(false),[l,d]=useState(false),[c,m]=useState(false),[u,g]=useState([]),[x,f]=useState([]),[y,b]=useState(""),[v,R]=useState(false),[L,C]=useState(""),[w,N]=useState(false),[p,A]=useState(""),[O,F]=useState(""),[P,S]=useState([]),M=e?.label||e?.name||"File",j=e.maxCount??(e.hasMany?999:1),se=j>1,ie=Array.isArray(t)?t:t?[t]:[],ue=ie.length<j;useEffect(()=>{(async()=>{let z=ie.filter(Se=>typeof Se=="string").map(Se=>Se),Ve=ie.filter(Se=>typeof Se=="object"&&Se!==null&&typeof Se.id=="string"&&!Se.url&&!Se.filename&&!Se.mimeType).map(Se=>Se.id),ye=[...z,...Ve];if(ye.length!==0)try{let Se=await Promise.all(ye.map(At=>De(`/api/media/${At}`))),lt=[...ie];Se.forEach(At=>{let qt=At.id,vt=lt.findIndex(X=>X===qt);if(vt!==-1){lt[vt]=At;return}let q=lt.findIndex(X=>typeof X=="object"&&X!==null&&X.id===qt);q!==-1&&(lt[q]=At);}),r(se?lt:lt[0]);}catch(Se){console.error("Failed to fetch media details:",Se);}})();},[t]),useEffect(()=>{l&&(oe(),ne());},[l,y]);let oe=async()=>{try{let I=await De(Mr("/api/media/folders"));f(I.folders||[]);}catch{f([]);}},ne=async()=>{R(true);try{let I=Mr("/api/media?limit=60&sortBy=createdAt&sortDir=desc");y&&(I+="&folder="+encodeURIComponent(y));let z=await De(I);g(z.docs||[]);}catch{g([]);}finally{R(false);}},je=async I=>{i(true);try{let z=new FormData;z.append("file",I),y&&z.append("folder",y);let Ve=await ya("/api/media/upload",z),ye={id:Ve.id,filename:Ve.filename,originalName:Ve.originalName??I.name,url:Ve.url,mimeType:I.type};r(se?[...ie,ye]:ye),$.success(`Asset synchronized: ${ye.filename}`);}catch(z){console.error("Upload failed:",z),$.error(`Upload failed: ${z instanceof Error?z.message:"Unknown error"}`);}finally{i(false);}},ft=async()=>{let I=p.trim();if(I){F("");try{let z=await et("/api/media/upload",{url:I}),Ve=(()=>{try{return new URL(I).pathname.split("/").pop()||z.originalName||"url-image"}catch{return z.originalName||"url-image"}})(),ye={id:z.id,filename:z.filename,originalName:Ve,url:z.url,mimeType:z.mimeType||"image/*"};r(se?[...ie,ye]:ye),$.success(`URL asset established: ${ye.filename}`),A(""),N(!1);}catch(z){let Ve=z instanceof Error?z.message:"Invalid URL";F(Ve);}}},B=I=>({id:I.id,filename:I.filename,url:I.url,mimeType:I.mimeType}),K=I=>{se?S(z=>z.find(ye=>ye.id===I.id)?z.filter(ye=>ye.id!==I.id):[...z,I]):(r(B(I)),d(false),C(""));},ce=()=>{if(P.length>0){let I=[...ie,...P.map(B)];r(I);}S([]),d(false),C("");},he=I=>{let z=[...ie];z.splice(I,1),r(se?z:z[0]||null);},Pe=useMemo(()=>u.filter(I=>!L||I.filename?.toLowerCase().includes(L.toLowerCase())||I.title?.toLowerCase().includes(L.toLowerCase())),[u,L]);if(s)return jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] p-2",children:"Uploading..."});let Ce=(I,z)=>{if(!I)return null;let Ve=vs(I.mimeType,I.filename||I.url);return 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:[jsx("div",{className:"w-10 h-10 rounded-md overflow-hidden bg-[var(--kyro-surface)] border border-[var(--kyro-border)] flex items-center justify-center flex-shrink-0",children:Ve==="image"?jsx("img",{src:ua(I.url),alt:I.filename||"Preview",className:"w-full h-full object-cover"}):jsx(al,{type:Ve,className:"w-5 h-5 text-[var(--kyro-text-secondary)]"})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-[11px] font-medium truncate text-[var(--kyro-text-primary)]",children:I.originalName||I.filename||"Unnamed File"}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] tracking-wider font-bold",children:M})]}),jsx("button",{type:"button",onClick:()=>z!==void 0?he(z):r(null),disabled:o,className:"p-1.5 rounded-md text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] hover:bg-[var(--kyro-danger-bg)] transition-all opacity-0 group-hover:opacity-100",children:jsx(X,{className:"w-4 h-4"})})]},z)};return t?jsxs("div",{className:"space-y-2",children:[se?jsxs("div",{className:"grid grid-cols-2 gap-2",children:[ie.map((I,z)=>Ce(I,z)),ue&&jsxs("button",{type:"button",onClick:()=>{S([]),d(true);},disabled:o,className:"flex items-center justify-center h-12 border-2 border-dashed border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-border-active)] cursor-pointer transition-colors",children:["+ Add ",M]})]}):Ce(t),jsx("input",{ref:a,type:"file",accept:"image/*",onChange:I=>{let z=I.target.files?.[0];z&&je(z);},disabled:o,className:"hidden"})]}):jsxs("div",{className:"space-y-2 relative",children:[jsx("input",{ref:a,type:"file",accept:e.allowedTypes?.join(",")||"*/*",onChange:I=>{let z=I.target.files?.[0];z&&je(z);},disabled:o,className:"hidden"}),jsxs("div",{className:"flex gap-2 flex-wrap",children:[jsxs("button",{type:"button",onClick:()=>a.current?.click(),disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:["+ Upload ",M]}),jsx("button",{type:"button",onClick:()=>{S([]),d(true);},disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:"Library"}),jsx("button",{type:"button",onClick:()=>N(!w),disabled:o,className:"px-3 py-1.5 text-xs font-semibold rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] cursor-pointer hover:border-[var(--kyro-border-active)] transition-colors",children:"URL"})]}),w&&jsxs("div",{className:"flex gap-2 items-center",children:[jsx("input",{ref:n,type:"url",placeholder:"https://example.com/image.jpg",value:p,onChange:I=>{A(I.target.value),F("");},onKeyDown:I=>I.key==="Enter"&&ft(),disabled:o,className:"flex-1 px-2 py-1.5 text-xs rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-primary)]"}),jsx("button",{type:"button",onClick:ft,disabled:o||!p.trim(),className:"kyro-btn kyro-btn-primary px-3 py-1.5 text-xs rounded cursor-pointer hover:opacity-90 transition-opacity disabled:opacity-50",children:"Add"}),O&&jsx("span",{className:"text-xs text-[var(--kyro-error)]",children:O})]}),l&&(c?createPortal(jsx(ol,{isFullscreen:true,isMultiple:se,selectedItems:P,pickerSearch:L,setPickerSearch:C,folders:x,selectedFolder:y,setSelectedFolder:b,mediaLoading:v,filteredMedia:Pe,selectFromLibrary:K,onDone:ce,setIsPickerFullscreen:m,setShowPicker:d}),document.body):jsx(ol,{isFullscreen:false,isMultiple:se,selectedItems:P,pickerSearch:L,setPickerSearch:C,folders:x,selectedFolder:y,setSelectedFolder:b,mediaLoading:v,filteredMedia:Pe,selectFromLibrary:K,onDone:ce,setIsPickerFullscreen:m,setShowPicker:d}))]})}function ol({isFullscreen:e,isMultiple:t,selectedItems:r,pickerSearch:o,setPickerSearch:a,folders:n,selectedFolder:s,setSelectedFolder:i,mediaLoading:l,filteredMedia:d,selectFromLibrary:c,onDone:m,setIsPickerFullscreen:u,setShowPicker:g}){let x=f=>r.some(y=>y.id===f);return 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:[jsxs("div",{className:"p-2 border-b border-[var(--kyro-border)] flex flex-col gap-2",children:[jsx("input",{type:"text",placeholder:"Search media...",value:o,onChange:f=>a(f.target.value),className:"w-full px-2 py-1.5 text-xs rounded border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-primary)]"}),n.length>0&&jsxs("div",{className:"flex gap-1 flex-wrap",children:[jsx("button",{type:"button",onClick:()=>i(""),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===""?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:"All"}),n.slice(0,6).map(f=>jsx("button",{type:"button",onClick:()=>i(f.path),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===f.path?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:f.name},f.path))]})]}),jsx("div",{className:"flex-1 overflow-auto p-2",children:l?jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"No media found"}):jsx("div",{className:`grid gap-1 ${e?"grid-cols-[repeat(auto-fill,minmax(140px,1fr))]":"grid-cols-3"}`,children:d.map(f=>{let y=x(f.id);return jsxs("button",{type:"button",onClick:()=>c(f),className:`border rounded-md overflow-hidden cursor-pointer p-0 bg-[var(--kyro-surface)] transition-all relative group ${y?"border-[var(--kyro-primary)] ring-2 ring-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]"}`,children:[jsx("div",{className:`w-full flex items-center justify-center bg-[var(--kyro-surface-accent)] ${e?"h-[120px]":"h-[80px]"}`,children:vs(f.mimeType,f.filename)==="image"?jsx("img",{src:ua(f.thumbnailUrl||f.url),alt:f.filename,className:"w-full h-full object-cover"}):jsx(al,{type:vs(f.mimeType,f.filename),className:e?"w-10 h-10":"w-8 h-8"})}),t&&y&&jsx("div",{className:"absolute top-1 right-1 w-5 h-5 rounded-full bg-[var(--kyro-primary)] flex items-center justify-center",children:jsx(Check,{className:"w-3 h-3 text-white"})})]},f.id)})})}),jsxs("div",{className:"p-2 border-t border-[var(--kyro-border)] flex justify-between items-center",children:[jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[d.length," items"]}),jsxs("div",{className:"flex gap-2 items-center",children:[t&&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})`:""]}),jsx("button",{type:"button",onClick:()=>u(!e),className:"p-1.5 rounded text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",title:e?"Exit fullscreen":"Fullscreen",children:e?jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children: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"})}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}),jsx("button",{type:"button",onClick:()=>{g(false),u(false);},className:"text-xs text-[var(--kyro-text-secondary)] bg-transparent border-none cursor-pointer hover:text-[var(--kyro-text-primary)]",children:"Close"})]})]})]})}function nt({field:e,error:t,children:r,hideLabel:o=false}){return jsxs("div",{className:"space-y-2.5 w-full group",children:[e.label&&!o&&jsx("div",{className:"flex justify-between items-end mb-1",children: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&&jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})}),jsx("div",{className:"relative transform transition-transform duration-200 focus-within:scale-[1.002]",children:r}),(e.admin?.description||t)&&jsxs("div",{className:"flex flex-col gap-1.5 px-1",children:[e.admin?.description&&!t&&jsx("p",{className:"text-[11px] leading-relaxed text-[var(--kyro-text-muted)] font-medium opacity-60 italic",children:e.admin.description}),t&&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:[jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-error)] shadow-[0_0_8px_var(--kyro-error)]"}),t]})]})]})}function dr({open:e,onClose:t,title:r,children:o,width:a="md",showOverlay:n=false,accentClass:s}){let i=useRef(null),[l,d]=useState(false);useEffect(()=>{d(true);},[]),useEffect(()=>{let m=u=>{u.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",m),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",m),document.body.style.overflow="";}},[e,t]);let c={sm:"w-full sm:w-[320px]",md:"w-full sm:w-[400px]",lg:"w-full sm:w-[550px]",xl:"w-full sm:w-[700px]"};return !e||!l?null:createPortal(jsxs(Fragment,{children:[n&&jsx("div",{className:"fixed inset-0 z-[99998] bg-black/50 backdrop-blur-sm",onClick:t}),jsxs("div",{ref:i,"data-kyro-slide-panel":"true","data-kyro-slide-width":a,className:`fixed right-0 top-0 bottom-0 z-[99999] ${c[a]} bg-[var(--kyro-surface)] ${s?`border-l-2 ${s}`:"border-l border-[var(--kyro-border)]"} shadow-2xl flex flex-col animate-slideIn`,children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsx("h2",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:r}),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:jsx(X,{className:"w-4 h-4"})})]}),jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o})]}),jsx("style",{children:`
1
+ import wa,{createContext,lazy,useState,useRef,useEffect,useCallback,useContext,useMemo,Suspense}from'react';import {create,useStore}from'zustand';import {persist,createJSONStorage}from'zustand/middleware';import {Video,Mail,Clock,Database,Users,Tag,Image,Activity,CircleHelp,Sparkles,Blocks,Columns3,Link2,ListOrdered,Box,Star,AlignLeft,ChevronDown,File,Code,List,Heading1,GripVertical,Copy,X,Plus,ChevronRight,Search,LoaderCircle,Check,RefreshCw,ChevronUp,CodeXml,FileText,Music,Film,Undo,Redo,Bold,Italic,Underline,Strikethrough,Highlighter,Palette,CheckSquare,Quote,Terminal,Minus,AlignCenter,AlignRight,Link,Minimize2,Maximize2,Grid3X3,Filter,FolderPlus,FolderInput,Folder,Trash2,Archive,Download,Crop,Server,Pencil,TriangleAlert,Eye,EllipsisVertical,Send,Info,ShieldAlert,CircleCheck,History,CheckCircle2,User,GitCompare,Undo2,ExternalLink,Settings,Shield,Hexagon,Network,Sun,Moon,LogOut,ArrowRight,LayoutDashboard,ArrowUpRight,Webhook,Zap,Pause,Play,Key,Lock,EyeOff,CirclePlay,RefreshCcw,Save,UserPlus,LockOpen}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {useEditor,EditorContent}from'@tiptap/react';import wp from'@tiptap/starter-kit';import Np from'@tiptap/extension-link';import Cp from'@tiptap/extension-image';import Sp from'@tiptap/extension-text-align';import Tp from'@tiptap/extension-underline';import Rp from'@tiptap/extension-highlight';import Ap from'@tiptap/extension-task-list';import Fp from'@tiptap/extension-task-item';import {TextStyle}from'@tiptap/extension-text-style';import Dp from'@tiptap/extension-color';import mp,{convertToPixelCrop,centerCrop,makeAspectCrop}from'react-image-crop';import'react-image-crop/dist/ReactCrop.css';import {githubLight}from'@uiw/codemirror-theme-github';import {aura}from'@uiw/codemirror-theme-aura';import {createStorage}from'unstorage';import mm from'unstorage/drivers/indexedb';import {mediaCollections,authCollections,minimalCollections,starterCollections,blogCollections,ecommerceCollections,kitchenSinkCollections,allSettingsGlobals,coreSettingsGlobals}from'@kyro-cms/core/templates';import Po from'fs';import {useSensors,useSensor,PointerSensor,KeyboardSensor,DndContext,closestCenter,DragOverlay,useDraggable}from'@dnd-kit/core';import {useSortable,SortableContext,verticalListSortingStrategy,horizontalListSortingStrategy}from'@dnd-kit/sortable';import {CSS}from'@dnd-kit/utilities';import {createStore}from'zustand/vanilla';import _u from'@uiw/react-codemirror';import {json}from'@codemirror/lang-json';import'@kyro-cms/core';import vr from'path';import {pathToFileURL}from'url';import {build}from'esbuild';import {config}from'dotenv';import {Worker}from'worker_threads';var tt=typeof __KYRO_ADMIN_PATH__<"u"?__KYRO_ADMIN_PATH__:"/admin",co=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function Ye(e){if(e.startsWith("http")||e.startsWith(co))return e;if(e.startsWith("/api/"))return co+e.slice(4);let t=e.startsWith("/")?"":"/";return `${co}${t}${e}`}function rs(e){return e.startsWith("http")||e.startsWith(tt)?e:e.startsWith("/admin/")?tt+e.slice(6):e.startsWith("/")?tt+e:e}function fa(e){return !e||typeof e!="string"?"":e.startsWith("http")||e.startsWith("blob:")||e.startsWith("data:")||e.startsWith("/")?e:`/${e}`}var _c={admin:tt,api:co,resolveApi:Ye,resolveAdmin:rs,resolveMedia:fa};var Or=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=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:[]})})),E={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)};create()(persist(e=>({mode:"light",setMode:t=>e({mode:t}),toggleMode:()=>e(t=>({mode:t.mode==="light"?"dark":"light"}))}),{name:"kyro-theme"}));var st=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})}));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}})}));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 Vc="/api/auth/refresh";async function pi(){try{return (await fetch(Ye(Vc),{method:"POST",credentials:"include"})).ok}catch{return false}}async function mt(e,t={}){let r={};t.body instanceof FormData||(r["Content-Type"]="application/json"),Object.assign(r,t.headers);let o=await fetch(Ye(e),{...t,credentials:"include",headers:r});if(o.status===401){if(await pi()){let n={};return t.body instanceof FormData||(n["Content-Type"]="application/json"),Object.assign(n,t.headers),await fetch(Ye(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 mt(e,o);if(!a.ok){let n=`GET Failed: ${a.status}`;throw r&&E.error(n),new Error(n)}return a.json()}async function ot(e,t,r){let{autoToast:o=true,...a}=r||{},n=await mt(e,{method:"POST",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`POST Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&E.error(s),new Error(s)}return n.json()}async function Xt(e,t,r){let{autoToast:o=true,...a}=r||{},n=await mt(e,{method:"PATCH",body:t?JSON.stringify(t):void 0,...a});if(!n.ok){let s=`Update Failed: ${n.status}`;try{let i=await n.json();i.error&&(s=i.error);}catch{}throw o&&E.error(s),new Error(s)}return n.json()}async function ht(e,t){let{autoToast:r=true,...o}=t||{},a=await mt(e,{method:"DELETE",...o});if(!a.ok){let s=`Delete Failed: ${a.status}`;try{let i=await a.json();i.error&&(s=i.error);}catch{}throw r&&E.error(s),new Error(s)}let n=await a.text();return n?JSON.parse(n):{}}function Ur(e){let t=e.includes("?")?"&":"?";return `${e}${t}t=${Date.now()}`}function Qa(e,t,r=50){return !e||t.length===0?`limit=${r}`:`${t.map(a=>`where[${a}][contains]=${encodeURIComponent(e)}`).join("&")}&limit=${r}`}async function va(e,t,r){if(!r){let o=await mt(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",Ye(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?pi().then(s=>{if(!s){a(new Error(`Upload Error: ${n.status}`));return}let i=new XMLHttpRequest;i.open("POST",Ye(e)),i.withCredentials=true,i.upload.addEventListener("progress",l=>{l.lengthComputable&&r(Math.round(l.loaded/l.total*100));}),i.addEventListener("load",()=>{if(i.status>=200&&i.status<300)try{o(JSON.parse(i.responseText));}catch{a(new Error("Invalid JSON"));}else a(new Error(`Upload Error: ${i.status}`));}),i.addEventListener("error",()=>a(new Error("Network error"))),i.send(t);}):a(new Error(`Upload Error: ${n.status}`));}),n.addEventListener("error",()=>a(new Error("Network error during upload"))),n.send(t);})}function Pr({size:e="md",className:t=""}){return jsx("svg",{className:`kyro-spinner kyro-spinner-${e} ${t}`,viewBox:"0 0 24 24",fill:"none",children:jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"40 20"})})}function Ot({variant:e,count:t=1,className:r=""}){let o={text:"h-3 rounded-md",circle:"size-10 rounded-full",rect:"h-10 rounded-xl",card:"h-32 rounded-2xl","table-row":"h-14 rounded-xl","media-card":"aspect-square rounded-2xl","stat-card":"h-24 rounded-2xl"};return jsx(Fragment,{children:Array.from({length:t}).map((a,n)=>jsx("div",{className:`kyro-shimmer ${o[e]} ${r}`},n))})}function Yi({back:e}){return e.href?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:jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}):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:jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})})}function Gc({breadcrumbs:e}){return e?.map((t,r)=>jsxs(wa.Fragment,{children:[r>0&&jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),t.href||t.onClick?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}):jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:t.label})]},r))}function Zi({actions:e}){return Array.isArray(e)?jsx("div",{className:"flex items-center gap-3",children:e.map((t,r)=>jsxs("button",{type:"button",onClick:t.onClick,className:`flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm transition-all shadow-lg shadow-[var(--kyro-primary)]/10 ${t.variant==="outline"?"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]":t.variant==="ghost"?"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] shadow-none":"kyro-btn-primary hover:opacity-90"} ${t.className||""}`,children:[t.icon&&jsx(t.icon,{className:"w-4 h-4"}),t.label]},r))}):jsx(Fragment,{children:e})}function el({action:e}){return jsxs("button",{type:"button",onClick:e.onClick,className:`kyro-btn kyro-btn-primary flex items-center gap-2 px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10 w-full lg:w-auto justify-center ${e.className||""}`,children:[e.icon&&jsx(e.icon,{className:"w-4 h-4"}),e.label]})}function Pt({title:e,description:t,icon:r,breadcrumbs:o,metadata:a,back:n,action:s,actions:i,children:l}){let d=o?.[o.length-1];return jsxs("div",{className:"surface-tile px-3 md:px-6 py-3 md:pt-4 mb-4 md:mb-8",children:[jsxs("div",{className:"md:hidden space-y-2",children:[(o||n)&&jsxs("div",{className:"flex items-center gap-2",children:[n&&jsx(Yi,{back:n}),jsxs("details",{className:"group [&::-webkit-details-marker]:hidden flex-1 min-w-0",children:[jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[jsx("span",{className:"flex-1 text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] truncate",children:d?.label||""}),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:jsx("path",{d:"M6 9l6 6 6-6"})})]}),jsxs("div",{className:"mt-2 pt-2 border-t border-[var(--kyro-border)] space-y-2",children:[o&&jsx("div",{className:"flex items-center gap-2",children:o.map((c,m)=>jsxs(wa.Fragment,{children:[m>0&&jsx("span",{className:"opacity-20 text-[10px]",children:"/"}),c.href||c.onClick?jsx("a",{href:c.href,onClick:v=>{c.onClick&&(v.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}):jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:c.label})]},m))}),a&&jsx("div",{className:"flex items-center gap-2 flex-wrap",children:a.map((c,m)=>jsx(wa.Fragment,{children:c},m))}),l]})]})]}),jsxs("div",{className:"flex items-center gap-2",children:[r&&jsx(r,{className:"w-5 h-5 text-[var(--kyro-primary)] shrink-0"}),e&&jsx("h1",{className:"text-lg font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e}),a&&!t&&jsx("span",{className:"h-2 w-2 rounded-full bg-[var(--kyro-primary)] shrink-0"})]}),t&&jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0 text-xs",children:t}),a&&jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxs(wa.Fragment,{children:[m===0&&jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))})]})]}),jsxs("div",{className:"hidden md:flex md:flex-row md:items-center justify-between gap-6",children:[jsxs("div",{className:"min-w-0 flex-1",children:[(o||n)&&jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n&&jsx(Yi,{back:n}),o&&jsx(Gc,{breadcrumbs:o})]}),jsxs("div",{className:"flex items-center gap-3",children:[r&&jsx(r,{className:"w-6 h-6 text-[var(--kyro-primary)]"}),e&&jsx("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)] truncate",children:e})]}),(t||a)&&jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 mt-1",children:[t&&jsx("p",{className:"text-[var(--kyro-text-secondary)] font-medium opacity-60 line-clamp-1 min-w-0",children:t}),a&&jsx("div",{className:"flex items-center gap-2",children:a.map((c,m)=>jsxs(wa.Fragment,{children:[m===0&&(t||m>0)&&jsx("span",{className:"opacity-20 ml-1",children:"\xB7"}),c]},m))}),l]})]}),jsxs("div",{className:"flex items-center gap-3 flex-wrap shrink-0",children:[i&&jsx(Zi,{actions:i}),s&&jsx(el,{action:s})]})]}),(i||s)&&jsxs("div",{className:"md:hidden flex items-center gap-2 mt-3 pt-3 border-t border-[var(--kyro-border)]",children:[s&&jsx(el,{action:s}),i&&jsx(Zi,{actions:i})]})]})}var qc={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 Dt({variant:e,status:t,className:r="",children:o,dot:a=false}){let n=e||t||"default",s=qc[n],i=s?s.class:`kyro-badge-${n}`;return jsxs("span",{className:`kyro-badge ${i} ${r}`,children:[a&&jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-current mr-1.5 opacity-60"}),o||s?.label||n]})}function ms({count:e,max:t=99}){return e===0?null:jsx("span",{className:"inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 text-xs font-medium bg-gray-200 text-gray-700 rounded-full",children:e>t?`${t}+`:e})}function us({variant:e="secondary",size:t="md",loading:r=false,children:o,className:a="",disabled:n,...s}){let i="kyro-btn",l=`kyro-btn-${e}`,d=`kyro-btn-${t}`;return jsxs("button",{type:"button",className:`${i} ${l} ${d} ${a}`,disabled:n||r,...s,children:[r?jsx("span",{className:"kyro-btn-loading",children:jsx("svg",{className:"kyro-btn-spinner",viewBox:"0 0 24 24",children:jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",fill:"none",strokeDasharray:"60 30"})})}):null,jsx("span",{className:r?"kyro-btn-text-hidden":"",children:o})]})}function gn({page:e,totalPages:t,totalDocs:r,limit:o,onPageChange:a,onLimitChange:n}){return t<=1?null: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?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]}):jsx("span",{}),jsxs("div",{className:"flex items-center gap-2 flex-wrap justify-center",children:[n&&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:[jsx("option",{value:10,children:"10/page"}),jsx("option",{value:25,children:"25/page"}),jsx("option",{value:50,children:"50/page"}),jsx("option",{value:100,children:"100/page"})]}),jsxs("span",{className:"text-xs text-[var(--kyro-text-secondary)] font-medium",children:["Page ",e," of ",t]}),jsxs("div",{className:"flex gap-1",children:[jsx(us,{variant:"ghost",size:"sm",disabled:e<=1,onClick:()=>a(e-1),children:"\u2190 Previous"}),jsx(us,{variant:"ghost",size:"sm",disabled:e>=t,onClick:()=>a(e+1),children:"Next \u2192"})]})]})]})}function fo(e,t,r){return r in t?t[r]:ys(e,t,r)}function ys(e,t,r){for(let o of e)if(o.name){if(o.type==="tabs"&&"tabs"in o){let a=t[o.name];if(a&&typeof a=="object"){if(r in a)return a[r];let n=ys(o.tabs?.flatMap(s=>s.fields||[])||[],a,r);if(n!==void 0)return n}}if((o.type==="group"||o.type==="collapsible")&&"fields"in o){let a=t[o.name];if(a&&typeof a=="object"){if(r in a)return a[r];let n=ys(o.fields||[],a,r);if(n!==void 0)return n}}}}function vs({collection:e,collectionSlug:t,initialDocs:r=[],initialTotal:o=0,onCreate:a,onEdit:n,config:s}){let i=t||e.slug,{permissions:l}=Or(),d=l?.collections?.[i]?.create!==false,c=l?.collections?.[i]?.delete!==false,m=l?.collections?.[i]?.update!==false,v=()=>{d&&(a?a():window.location.href=`${tt}/${i}/new`);},f=B=>{n?n(B):window.location.href=`${tt}/${i}/${B}`;},[b,x]=useState(r),[g,y]=useState(o),[u,N]=useState(false),[R,S]=useState(1),[h,C]=useState(10),[p,P]=useState(new Set),[M,D]=useState(""),[I,A]=useState([]),{confirm:re,alert:me}=st(),O=()=>{A([...I,{field:"",operator:"equals",value:""}]);},W=()=>{D(""),A([]),Ne(null);},se=B=>{A(I.filter((G,ae)=>ae!==B));},X$1=(B,G)=>{A(I.map((ae,sr)=>sr===B?{...ae,...G}:ae));},[K,Ne]=useState(null),[Re,T]=useState(false),[_,de]=useState(false);function ke(B){let G=[];for(let ae of B||[])if(!(!ae.name||ae.hidden===true||ae.admin?.hidden||ae.name==="id"))if(ae.type==="tabs"&&ae.tabs)for(let sr of ae.tabs)sr.fields&&G.push(...ke(sr.fields));else (ae.type==="row"||ae.type==="collapsible")&&ae.fields?G.push(...ke(ae.fields)):G.push(ae);return G}let Ce=useMemo(()=>ke(e.fields),[e.fields]),he=typeof e.admin?.useAsTitle=="string"?e.admin.useAsTitle:Ce.find(B=>B.type!=="group"&&typeof B.name=="string")?.name,[L,z]=useState(()=>{let B;return e.admin?.defaultColumns?B=[...e.admin?.defaultColumns||[]]:B=Ce.slice(0,4).map(G=>G.name).filter(G=>!!G),he&&B.includes(he)&&(B=[he,...B.filter(G=>G!==he)]),B.includes("updatedAt")||B.push("updatedAt"),new Set(B)}),We=useCallback(B=>{z(G=>{let ae=new Set(G);return ae.has(B)?ae.delete(B):ae.add(B),ae});},[]);function ye(B){let G=Ce.find(ae=>ae.name===B);return G&&G.type==="group"&&G.fields?.[0]?.name?`${B}.${G.fields[0].name}`:B}let Ae=useCallback(B=>{let G=ye(B);Ne(ae=>ae&&ae.field===G?{field:G,direction:ae.direction==="asc"?"desc":"asc"}:{field:G,direction:"asc"});},[]),ct=useMemo(()=>{let B=Ce.filter(G=>!!G.name&&L.has(G.name));return L.has("status")&&B.push({name:"status",type:"select",label:"Status",options:[{value:"draft",label:"Draft"},{value:"published",label:"Published"}]}),B},[Ce,L]);function At(B){return !B.name||!he?false:B.name===he||B.type==="group"&&B.fields?.[0]?.name===he}function qt(B,G){return G.name?fo(e.fields,B,G.name)??null:null}let gt=useCallback(async()=>{N(true);try{let B=new URLSearchParams({page:R.toString(),limit:h.toString()});M&&B.append("search",M),K&&B.append("sort",K.field),K&&B.append("order",K.direction),I.length>0&&B.append("filters",JSON.stringify(I));let G=await Be(Ur(`/api/${i}?${B}`),{autoToast:!1});x(G.docs||[]),y(G.totalDocs||0);}catch(B){console.error("Failed to load docs:",B);}finally{N(false);}},[i,R,h,M,K,I]);useEffect(()=>{b.length===0&&o===0&&gt();},[]);let J=useRef(true);useEffect(()=>{if(J.current){J.current=false;return}gt();},[R,h,M,K,I]);let Z=()=>{p.size===b.length?P(new Set):P(new Set(b.map(B=>B.id)));},le=B=>{let G=new Set(p);G.has(B)?G.delete(B):G.add(B),P(G);},xe=()=>{re({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 B of Array.from(p))await ht(`/api/${i}/${B}`);P(new Set),gt(),E.success("Documents deleted");}catch(B){console.error("Bulk delete failed:",B),E.error("Failed to delete some documents");}}});},Se=B=>{re({title:"Delete Document",message:"Are you sure you want to delete this document? This cannot be undone.",variant:"danger",onConfirm:async()=>{try{await ht(`/api/${i}/${B}`),gt(),E.success("Document deleted");}catch(G){console.error("Delete failed:",G),E.error("Failed to delete document");}}});},et=Math.ceil(g/h),St=M||I.length>0||K;return jsxs("div",{className:"space-y-6",children:[jsx(Pt,{title:e.label||i,description:e.admin?.description||`Manage your ${e.label||i}`,metadata:g>0?[jsxs("span",{className:"text-xs font-bold opacity-60",children:[g," documents"]},"count")]:void 0,action:d?{label:`Create ${e.singularLabel||e.label||i}`,onClick:v,icon:Plus}:void 0}),jsxs("div",{className:"surface-tile p-4 flex flex-col lg:flex-row gap-4 items-start lg:items-center",children:[jsxs("div",{className:"relative flex-1 w-full lg:max-w-md",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",placeholder:"Search...",value:M,onChange:B=>D(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"})]}),jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[jsxs("button",{type:"button",onClick:()=>T(!Re),className:`flex items-center gap-2 px-4 py-2 rounded-xl font-bold text-sm transition-all ${Re||I.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:[jsx(Filter,{className:"w-4 h-4"}),"Filters",I.length>0&&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:I.length})]}),jsxs("div",{className:"relative",children:[jsxs("button",{type:"button",onClick:()=>de(!_),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:[jsx(Columns3,{className:"w-4 h-4"}),"Columns"]}),_&&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:[jsx("div",{className:"p-3 border-b border-[var(--kyro-border)]",children:jsx("span",{className:"text-xs font-bold tracking-wider text-[var(--kyro-text-secondary)]",children:"Toggle Columns"})}),jsx("div",{className:"p-2 max-h-64 overflow-y-auto",children:Ce.map(B=>B.name?jsxs("label",{className:"flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-[var(--kyro-surface-accent)] cursor-pointer",children:[jsx("input",{type:"checkbox",checked:L.has(B.name),onChange:()=>We(B.name),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"}),jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:B.label||B.name})]},B.name):null)})]})]}),St&&jsx("button",{type:"button",onClick:W,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"})]})]}),Re&&jsxs("div",{className:"surface-tile p-4 border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsx("h3",{className:"font-medium text-[var(--kyro-text-primary)]",children:"Advanced Filters"}),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:[jsx(Plus,{className:"w-4 h-4"}),"Add Filter"]})]}),jsxs("div",{className:"space-y-3",children:[I.map((B,G)=>jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[jsx("select",{value:B.field,onChange:ae=>X$1(G,{field:ae.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:Ce.map(ae=>jsx("option",{value:ae.name,children:ae.label||ae.name},ae.name))}),jsxs("select",{value:B.operator,onChange:ae=>X$1(G,{operator:ae.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:[jsx("option",{value:"equals",children:"Equals"}),jsx("option",{value:"contains",children:"Contains"}),jsx("option",{value:"gt",children:"Greater than"}),jsx("option",{value:"lt",children:"Less than"}),jsx("option",{value:"gte",children:"Greater or equal"}),jsx("option",{value:"lte",children:"Less or equal"})]}),jsx("input",{type:"text",value:B.value,onChange:ae=>X$1(G,{value:ae.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)]"}),jsx("button",{type:"button",onClick:()=>se(G),className:"p-2 text-[var(--kyro-text-muted)] hover:text-red-500 transition-colors",children:jsx(X,{className:"w-4 h-4"})})]},G)),I.length===0&&jsx("p",{className:"text-sm text-[var(--kyro-text-muted)]",children:'No filters applied. Click "Add Filter" to create one.'})]})]}),p.size>0&&jsxs("div",{className:"surface-tile p-4 flex items-center justify-between border-l-4 border-[var(--kyro-sidebar-active)]",children:[jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:[p.size," selected"]}),jsxs("div",{className:"flex gap-2",children:[c&&jsxs("button",{type:"button",onClick:xe,className:"flex items-center gap-2 px-4 py-2 bg-red-500 text-white rounded-lg font-bold text-sm hover:bg-red-600 transition-all",children:[jsx(Trash2,{className:"w-4 h-4"}),"Delete Selected"]}),jsx("button",{type:"button",onClick:()=>P(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"})]})]}),jsx("div",{className:"surface-tile overflow-hidden",children:u?jsx("div",{className:"space-y-2 p-4",children:jsx(Ot,{variant:"table-row",count:8})}):b.length===0?jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-8",children:[jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:jsx(Archive,{className:"w-4 h-4"})}),jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:"No documents found"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:St?"Try adjusting your filters or search query.":`Get started by creating your first ${(e.singularLabel||e.label||i).toLowerCase()}.`}),!St&&d&&jsxs("button",{type:"button",onClick:v,className:"mt-4 kyro-btn kyro-btn-md kyro-btn-primary shadow-md flex items-center gap-2",children:[jsx(Plus,{className:"w-4 h-4"}),"Create"," ",String(e.singularLabel||e.label||i)]})]}):jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-left",children:[jsx("thead",{children:jsxs("tr",{className:"text-[var(--kyro-text-secondary)] font-bold text-[10px] tracking-[0.3em] border-b border-[var(--kyro-border)] whitespace-nowrap",children:[jsx("th",{className:"px-4 py-4 w-10",children:jsx("input",{type:"checkbox",checked:p.size===b.length&&b.length>0,onChange:Z,className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),ct.map(B=>jsx("th",{className:"px-4 py-4 cursor-pointer hover:text-[var(--kyro-text-primary)] transition-colors",onClick:()=>Ae(B.name),children:jsxs("div",{className:"flex items-center gap-2",children:[Zc(ct,B.type)??(B.label||B.name),K&&K.field===B.name&&jsx(ChevronUp,{className:"w-4 h-4"})]})},B.name)),e.timestamps?jsx("th",{className:"px-4 py-4",children:"Created"}):null,jsx("th",{className:"px-4 py-4 text-right",children:"Actions"})]})}),jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:b.map(B=>jsxs("tr",{className:"hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer group",onClick:()=>f(B.id),children:[jsx("td",{className:"px-4 py-3",onClick:G=>G.stopPropagation(),children:jsx("input",{type:"checkbox",checked:p.has(B.id),onChange:()=>le(B.id),className:"w-4 h-4 rounded border-[var(--kyro-border-strong)] text-[var(--kyro-sidebar-active)] focus:ring-[var(--kyro-sidebar-active)]"})}),ct.map(G=>{let ae=qt(B,G),sr=G.type==="select"&&ae?G.options?.find(io=>io.value===ae)?.label||ae:Yc(ae,G.type);return jsx("td",{className:`px-4 py-3 ${At(G)?"font-medium text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)]"}`,children:sr},G.name)}),e.timestamps?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,jsx("td",{className:"px-4 py-3 text-right",onClick:G=>G.stopPropagation(),children:jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>f(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:m?"Edit":"View",children:jsx(Pencil,{className:"w-4 h-4"})}),c&&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:jsx(Trash2,{className:"w-4 h-4"})})]})})]},B.id))})]})})}),jsx(gn,{page:R,totalPages:et,totalDocs:g,limit:h,onPageChange:S,onLimitChange:B=>{C(B),S(1);}})]})}function Yc(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 Zc(e,t){return t!=="tabs"?void 0:e[0]?.tabs?.[0]?.fields?.[0]?.label}var gs=(e,t)=>{let r=e?.toLowerCase()||"",o=t?.toLowerCase()||"";return r.startsWith("image/")||o.match(/\.(jpe?g|png|gif|webp|avif|svg)$/i)?"image":r.startsWith("video/")||o.match(/\.(mp4|webm|ogg|mov)$/i)?"video":r.startsWith("audio/")||o.match(/\.(mp3|wav|ogg|m4a)$/i)?"audio":r.includes("pdf")||o.endsWith(".pdf")?"pdf":o.match(/\.(doc|docx|txt|rtf|odt)$/i)?"document":o.match(/\.(xls|xlsx|csv)$/i)?"spreadsheet":o.match(/\.(zip|tar|gz|7z|rar)$/i)?"archive":"other"},il=({type:e,className:t})=>{switch(e){case "image":return jsx(Image,{className:t});case "video":return jsx(Film,{className:t});case "audio":return jsx(Music,{className:t});case "pdf":case "document":return jsx(FileText,{className:t});default:return jsx(File,{className:t})}};function dr({field:e,value:t,onChange:r,disabled:o}){let a=useRef(null),n=useRef(null),[s,i]=useState(false),[l,d]=useState(false),[c,m]=useState(false),[v,f]=useState([]),[b,x]=useState([]),[g,y]=useState(""),[u,N]=useState(false),[R,S]=useState(""),[h,C]=useState(false),[p,P]=useState(""),[M,D]=useState(""),[I,A]=useState([]),re=e?.label||e?.name||"File",me=e.maxCount??(e.hasMany?999:1),O=me>1,W=Array.isArray(t)?t:t?[t]:[],se=W.length<me;useEffect(()=>{(async()=>{let z=W.filter(Ae=>typeof Ae=="string").map(Ae=>Ae),We=W.filter(Ae=>typeof Ae=="object"&&Ae!==null&&typeof Ae.id=="string"&&!Ae.url&&!Ae.filename&&!Ae.mimeType).map(Ae=>Ae.id),ye=[...z,...We];if(ye.length!==0)try{let Ae=await Promise.all(ye.map(At=>Be(`/api/media/${At}`))),ct=[...W];Ae.forEach(At=>{let qt=At.id,gt=ct.findIndex(Z=>Z===qt);if(gt!==-1){ct[gt]=At;return}let J=ct.findIndex(Z=>typeof Z=="object"&&Z!==null&&Z.id===qt);J!==-1&&(ct[J]=At);}),r(O?ct:ct[0]);}catch(Ae){console.error("Failed to fetch media details:",Ae);}})();},[t]),useEffect(()=>{l&&(X$1(),K());},[l,g]);let X$1=async()=>{try{let L=await Be(Ur("/api/media/folders"));x(L.folders||[]);}catch{x([]);}},K=async()=>{N(true);try{let L=Ur("/api/media?limit=60&sortBy=createdAt&sortDir=desc");g&&(L+="&folder="+encodeURIComponent(g));let z=await Be(L);f(z.docs||[]);}catch{f([]);}finally{N(false);}},Ne=async L=>{i(true);try{let z=new FormData;z.append("file",L),g&&z.append("folder",g);let We=await va("/api/media/upload",z),ye={id:We.id,filename:We.filename,originalName:We.originalName??L.name,url:We.url,mimeType:L.type};r(O?[...W,ye]:ye),E.success(`Asset synchronized: ${ye.filename}`);}catch(z){console.error("Upload failed:",z),E.error(`Upload failed: ${z instanceof Error?z.message:"Unknown error"}`);}finally{i(false);}},Re=async()=>{let L=p.trim();if(L){D("");try{let z=await ot("/api/media/upload",{url:L}),We=(()=>{try{return new URL(L).pathname.split("/").pop()||z.originalName||"url-image"}catch{return z.originalName||"url-image"}})(),ye={id:z.id,filename:z.filename,originalName:We,url:z.url,mimeType:z.mimeType||"image/*"};r(O?[...W,ye]:ye),E.success(`URL asset established: ${ye.filename}`),P(""),C(!1);}catch(z){let We=z instanceof Error?z.message:"Invalid URL";D(We);}}},T=L=>({id:L.id,filename:L.filename,url:L.url,mimeType:L.mimeType}),_=L=>{O?A(z=>z.find(ye=>ye.id===L.id)?z.filter(ye=>ye.id!==L.id):[...z,L]):(r(T(L)),d(false),S(""));},de=()=>{if(I.length>0){let L=[...W,...I.map(T)];r(L);}A([]),d(false),S("");},ke=L=>{let z=[...W];z.splice(L,1),r(O?z:z[0]||null);},Ce=useMemo(()=>v.filter(L=>!R||L.filename?.toLowerCase().includes(R.toLowerCase())||L.title?.toLowerCase().includes(R.toLowerCase())),[v,R]);if(s)return jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] p-2",children:"Uploading..."});let he=(L,z)=>{if(!L)return null;let We=gs(L.mimeType,L.filename||L.url);return 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:[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:We==="image"?jsx("img",{src:fa(L.url),alt:L.filename||"Preview",className:"w-full h-full object-cover"}):jsx(il,{type:We,className:"w-5 h-5 text-[var(--kyro-text-secondary)]"})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-[11px] font-medium truncate text-[var(--kyro-text-primary)]",children:L.originalName||L.filename||"Unnamed File"}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] tracking-wider font-bold",children:re})]}),jsx("button",{type:"button",onClick:()=>z!==void 0?ke(z):r(null),disabled:o,className:"p-1.5 rounded-md text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] hover:bg-[var(--kyro-danger-bg)] transition-all opacity-0 group-hover:opacity-100",children:jsx(X,{className:"w-4 h-4"})})]},z)};return t?jsxs("div",{className:"space-y-2",children:[O?jsxs("div",{className:"grid grid-cols-2 gap-2",children:[W.map((L,z)=>he(L,z)),se&&jsxs("button",{type:"button",onClick:()=>{A([]),d(true);},disabled:o,className:"flex items-center justify-center h-12 border-2 border-dashed border-[var(--kyro-border)] rounded-lg text-sm text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-border-active)] cursor-pointer transition-colors",children:["+ Add ",re]})]}):he(t),jsx("input",{ref:a,type:"file",accept:"image/*",onChange:L=>{let z=L.target.files?.[0];z&&Ne(z);},disabled:o,className:"hidden"})]}):jsxs("div",{className:"space-y-2 relative",children:[jsx("input",{ref:a,type:"file",accept:e.allowedTypes?.join(",")||"*/*",onChange:L=>{let z=L.target.files?.[0];z&&Ne(z);},disabled:o,className:"hidden"}),jsxs("div",{className:"flex gap-2 flex-wrap",children:[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 ",re]}),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"}),jsx("button",{type:"button",onClick:()=>C(!h),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"})]}),h&&jsxs("div",{className:"flex gap-2 items-center",children:[jsx("input",{ref:n,type:"url",placeholder:"https://example.com/image.jpg",value:p,onChange:L=>{P(L.target.value),D("");},onKeyDown:L=>L.key==="Enter"&&Re(),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)]"}),jsx("button",{type:"button",onClick:Re,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"}),M&&jsx("span",{className:"text-xs text-[var(--kyro-error)]",children:M})]}),l&&(c?createPortal(jsx(sl,{isFullscreen:true,isMultiple:O,selectedItems:I,pickerSearch:R,setPickerSearch:S,folders:b,selectedFolder:g,setSelectedFolder:y,mediaLoading:u,filteredMedia:Ce,selectFromLibrary:_,onDone:de,setIsPickerFullscreen:m,setShowPicker:d}),document.body):jsx(sl,{isFullscreen:false,isMultiple:O,selectedItems:I,pickerSearch:R,setPickerSearch:S,folders:b,selectedFolder:g,setSelectedFolder:y,mediaLoading:u,filteredMedia:Ce,selectFromLibrary:_,onDone:de,setIsPickerFullscreen:m,setShowPicker:d}))]})}function sl({isFullscreen:e,isMultiple:t,selectedItems:r,pickerSearch:o,setPickerSearch:a,folders:n,selectedFolder:s,setSelectedFolder:i,mediaLoading:l,filteredMedia:d,selectFromLibrary:c,onDone:m,setIsPickerFullscreen:v,setShowPicker:f}){let b=x=>r.some(g=>g.id===x);return 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:[jsxs("div",{className:"p-2 border-b border-[var(--kyro-border)] flex flex-col gap-2",children:[jsx("input",{type:"text",placeholder:"Search media...",value:o,onChange:x=>a(x.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&&jsxs("div",{className:"flex gap-1 flex-wrap",children:[jsx("button",{type:"button",onClick:()=>i(""),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===""?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:"All"}),n.slice(0,6).map(x=>jsx("button",{type:"button",onClick:()=>i(x.path),className:`kyro-btn-primary px-2 py-1 text-xs rounded transition-colors ${s===x.path?"":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:x.name},x.path))]})]}),jsx("div",{className:"flex-1 overflow-auto p-2",children:l?jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsx("div",{className:"text-center py-5 text-xs text-[var(--kyro-text-muted)]",children:"No media found"}):jsx("div",{className:`grid gap-1 ${e?"grid-cols-[repeat(auto-fill,minmax(140px,1fr))]":"grid-cols-3"}`,children:d.map(x=>{let g=b(x.id);return jsxs("button",{type:"button",onClick:()=>c(x),className:`border rounded-md overflow-hidden cursor-pointer p-0 bg-[var(--kyro-surface)] transition-all relative group ${g?"border-[var(--kyro-primary)] ring-2 ring-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]"}`,children:[jsx("div",{className:`w-full flex items-center justify-center bg-[var(--kyro-surface-accent)] ${e?"h-[120px]":"h-[80px]"}`,children:gs(x.mimeType,x.filename)==="image"?jsx("img",{src:fa(x.thumbnailUrl||x.url),alt:x.filename,className:"w-full h-full object-cover"}):jsx(il,{type:gs(x.mimeType,x.filename),className:e?"w-10 h-10":"w-8 h-8"})}),t&&g&&jsx("div",{className:"absolute top-1 right-1 w-5 h-5 rounded-full bg-[var(--kyro-primary)] flex items-center justify-center",children:jsx(Check,{className:"w-3 h-3 text-white"})})]},x.id)})})}),jsxs("div",{className:"p-2 border-t border-[var(--kyro-border)] flex justify-between items-center",children:[jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[d.length," items"]}),jsxs("div",{className:"flex gap-2 items-center",children:[t&&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})`:""]}),jsx("button",{type:"button",onClick:()=>v(!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?jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children: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"})}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"})})}),jsx("button",{type:"button",onClick:()=>{f(false),v(false);},className:"text-xs text-[var(--kyro-text-secondary)] bg-transparent border-none cursor-pointer hover:text-[var(--kyro-text-primary)]",children:"Close"})]})]})]})}function lt({field:e,error:t,children:r,hideLabel:o=false}){return jsxs("div",{className:"space-y-2.5 w-full group",children:[e.label&&!o&&jsx("div",{className:"flex justify-between items-end mb-1",children: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&&jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})}),jsx("div",{className:"relative transform transition-transform duration-200 focus-within:scale-[1.002]",children:r}),(e.admin?.description||t)&&jsxs("div",{className:"flex flex-col gap-1.5 px-1",children:[e.admin?.description&&!t&&jsx("p",{className:"text-[11px] leading-relaxed text-[var(--kyro-text-muted)] font-medium opacity-60 italic",children:e.admin.description}),t&&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:[jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-error)] shadow-[0_0_8px_var(--kyro-error)]"}),t]})]})]})}function cr({open:e,onClose:t,title:r,children:o,width:a="md",showOverlay:n=false,accentClass:s}){let i=useRef(null),[l,d]=useState(false);useEffect(()=>{d(true);},[]),useEffect(()=>{let m=v=>{v.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",m),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",m),document.body.style.overflow="";}},[e,t]);let c={sm:"w-full sm:w-[320px]",md:"w-full sm:w-[400px]",lg:"w-full sm:w-[550px]",xl:"w-full sm:w-[700px]"};return !e||!l?null:createPortal(jsxs(Fragment,{children:[n&&jsx("div",{className:"fixed inset-0 z-[99998] bg-black/50 backdrop-blur-sm",onClick:t}),jsxs("div",{ref:i,"data-kyro-slide-panel":"true","data-kyro-slide-width":a,className:`fixed right-0 top-0 bottom-0 z-[99999] ${c[a]} bg-[var(--kyro-surface)] ${s?`border-l-2 ${s}`:"border-l border-[var(--kyro-border)]"} shadow-2xl flex flex-col animate-slideIn`,children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsx("h2",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:r}),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:jsx(X,{className:"w-4 h-4"})})]}),jsx("div",{className:"flex-1 overflow-y-auto p-4",children:o})]}),jsx("style",{children:`
2
2
  @keyframes slideIn {
3
3
  from { transform: translateX(100%); }
4
4
  to { transform: translateX(0); }
@@ -6,24 +6,24 @@ import ka,{createContext,lazy,useState,useRef,useEffect,useCallback,useContext,u
6
6
  .animate-slideIn {
7
7
  animation: slideIn 300ms ease-out;
8
8
  }
9
- `})]}),document.body)}function Or({children:e}){return jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:e})}function Ur({children:e}){return jsx("div",{className:"flex items-center justify-end gap-3 mt-6",children:e})}function Ut({open:e,onClose:t,title:r,children:o,footer:a,size:n="md",variant:s="default"}){if(useEffect(()=>{let d=c=>{c.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",d),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",d),document.body.style.overflow="";}},[e,t]),!e)return null;let i={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",full:"w-full h-full max-w-none rounded-none border-0"},l=s==="lightbox";return createPortal(jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",children:[jsx("div",{className:`absolute inset-0 transition-all duration-500 ${l?"bg-black/95 backdrop-blur-none":"bg-[var(--kyro-black)]/40 backdrop-blur-md"}`,onClick:t}),jsxs("div",{className:`relative ${i[n]} ${l?"bg-transparent text-white":"bg-[var(--kyro-surface)]"} ${!l&&n!=="full"?"rounded-[var(--kyro-radius-lg)]":""} shadow-2xl animate-in fade-in zoom-in-95 duration-300 ${l?"":"border"} ${s==="danger"?"border-red-500/30":"border-[var(--kyro-border)]"} flex flex-col overflow-hidden`,children:[!l&&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:[jsx("h2",{className:"text-xl font-bold text-[var(--kyro-text-primary)]",children:r}),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:jsx(X,{className:"w-4 h-4"})})]}),jsx("div",{className:`flex-1 overflow-auto ${l?"":"px-8 py-8"}`,children:o}),a&&!l&&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 bs({open:e,onClose:t,onConfirm:r,title:o,message:a,confirmLabel:n="Confirm",cancelLabel:s="Cancel",variant:i="default",loading:l=false}){return jsx(Ut,{open:e,onClose:t,title:o,size:"sm",footer:jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:t,disabled:l,className:"kyro-btn kyro-btn-md kyro-btn-secondary",children:s}),jsx("button",{type:"button",onClick:r,disabled:l,className:`kyro-btn kyro-btn-md ${i==="danger"?"kyro-btn-danger":"kyro-btn-primary"}`,children:l?"Loading...":n})]}),children:jsx("p",{className:"text-[var(--kyro-text-secondary)]",children:a})})}function sl({open:e,onClose:t,onSubmit:r,title:o,placeholder:a="",defaultValue:n=""}){let[s,i]=useState(n),l=d=>{d.preventDefault(),s.trim()&&(r(s.trim()),i(""),t());};return e?createPortal(jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",children:[jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),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:[jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-[var(--kyro-border)]",children:[jsx("h2",{className:"text-lg font-semibold text-[var(--kyro-text-primary)]",children:o}),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:jsx(X,{className:"w-4 h-4"})})]}),jsxs("form",{onSubmit:l,children:[jsx("div",{className:"px-6 py-4",children:jsx("input",{type:"text",value:s,onChange:d=>i(d.target.value),placeholder:a,autoFocus:true,className:"w-full px-3 py-2 border border-[var(--kyro-input-border)] rounded-lg bg-[var(--kyro-input-bg)] text-[var(--kyro-text-primary)] placeholder-[var(--kyro-text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent"})}),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:[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"}),jsx("button",{type:"submit",disabled:!s.trim(),className:"px-4 py-2 rounded-lg font-medium text-sm bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] hover:opacity-90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"Confirm"})]})]})]})]}),document.body):null}function yo(e){if(typeof e!="string"||!e)return "";if(typeof window>"u"||e.startsWith("http")||e.startsWith("blob:"))return e;let t=e.replace(/^\/+/,"/");return `${window.location.origin}${t}`}function bn(e){if(e===0)return "0 B";let t=1024,r=["B","KB","MB","GB"],o=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,o)).toFixed(1))+" "+r[o]}function pp(e){return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function mp(e){return e.startsWith("image/")?"image":e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":e.includes("zip")||e.includes("tar")||e.includes("archive")?"archive":e.includes("pdf")||e.includes("doc")||e.includes("text")?"document":"other"}function xn({onSelect:e,multiple:t=true,pickerMode:r=false}){let{permissions:o}=Lr(),a=o?.media?.create!==false,n=o?.media?.delete!==false,s=o?.media?.update!==false,[i,l]=useState([]),[d,c]=useState(true),[m,u]=useState([]),[g,x]=useState(""),[f,y]=useState(""),[b,v]=useState("all"),[R,L]=useState("grid"),[C,w]=useState(null),[N,p]=useState(false),[A,O]=useState(false),[F,P]=useState(false),[S,M]=useState({}),[j,se]=useState(false),[ie,ue]=useState(false),[oe,ne]=useState(null),[je,ft]=useState(false),[B,K]=useState(false),[ce,he]=useState(1),[Pe,Ce]=useState(0),[I,z]=useState(1),Ve=40,[ye,Se]=useState(new Set),{confirm:lt,alert:At}=ot(),[qt,vt]=useState(false),q=useRef(null),[X$1,le]=useState(),xe=useRef(null),we=useCallback(async()=>{c(true);try{let h=new URLSearchParams({page:ce.toString(),limit:Ve.toString()});g&&h.append("folder",g),f&&h.append("search",f),b!=="all"&&h.append("type",b);let re=await De(Mr(`/api/media?${h}`));l((re.docs||[]).map(Re=>({...Re,type:mp(Re.mimeType)}))),Ce(re.totalDocs||0),z(re.totalPages||1);}catch(h){console.error("Failed to load media:",h);}finally{c(false);}},[ce,g,f,b]),Qe=useCallback(async()=>{try{let h=await De(Mr("/api/media/folders"));u(Array.isArray(h)?h:h.folders||[]);}catch(h){console.error("Failed to load folders:",h);}},[]),Ct=useCallback(async()=>{try{let re=!!(await De("/api/globals/storage-settings"))?.data?.provider;ne(re);}catch{ne(false);}},[]);useEffect(()=>{r||Ct();},[Ct,r]),useEffect(()=>{r||oe===false&&!je&&(ft(true),K(true));},[r,oe,je]),useEffect(()=>{we();},[we]),useEffect(()=>{Qe();},[Qe]),useEffect(()=>{if(r)return;let h=re=>{let Re=re.clipboardData?.files;Re&&Re.length>0&&D(Re);};return window.addEventListener("paste",h),()=>window.removeEventListener("paste",h)},[r,g,oe]);let D=async h=>{if(!oe){K(true);return}P(true);let re=0,Re=0;for(let Jt=0;Jt<h.length;Jt++){let Lt=h[Jt];try{let vr=new FormData;vr.append("file",Lt),g&&vr.append("folder",g),await ya("/api/media/upload",vr,ir=>{M(es=>({...es,[Lt.name]:ir}));}),re++;}catch(vr){console.error(`Upload failed for ${Lt.name}:`,vr),Re++;}}P(false),M({}),we(),Qe(),Re>0&&$.error(`${Re} file(s) failed to upload`),re>0&&$.success(`${re} file(s) uploaded successfully`);},G=()=>{lt({title:"Delete Media",message:`Are you sure you want to delete ${ye.size} item(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let h of Array.from(ye))await kt(`/api/media/${h}`);Se(new Set),we(),$.success(`${ye.size} item(s) deleted`);}catch(h){console.error("Bulk delete failed:",h),$.error("Failed to delete some items");}}});},ee=(h,re)=>{re.stopPropagation();let Re=new Set(ye);Re.has(h)?Re.delete(h):(t||Re.clear(),Re.add(h)),Se(Re);},sr=async h=>{try{await et("/api/media/folders",{name:h}),Qe(),se(!1),$.success(`Folder "${h}" created`);}catch(re){console.error("Failed to create folder:",re),$.error("Failed to create folder");}},no=h=>{lt({title:"Delete Folder",message:`Are you sure you want to delete the folder "${h}"? All media in this folder will be moved to the root.`,variant:"danger",confirmLabel:"Delete Folder",onConfirm:async()=>{try{await kt(`/api/media/folders?path=${encodeURIComponent(h)}`),g===h&&x(""),Qe(),we(),$.success(`Folder "${h}" deleted`);}catch(re){console.error("Failed to delete folder:",re),$.error("Failed to delete folder");}}});},da=async(h,re)=>{try{let Re=await Xt(`/api/media/${h}`,re);l(Jt=>Jt.map(Lt=>Lt.id===h?Re.doc:Lt)),C?.id===h&&w(Re.doc),$.success("Metadata updated");}catch(Re){console.error("Failed to update metadata:",Re),$.error("Failed to update metadata");}},Ka=h=>{let{width:re,height:Re}=h.currentTarget,Jt=centerCrop(makeAspectCrop({unit:"%",width:90},1,re,Re),re,Re);le(Jt);},Zn=async()=>{if(!(!X$1||!xe.current||!C)){P(true);try{let h=convertToPixelCrop(X$1,xe.current.width,xe.current.height),re=document.createElement("canvas"),Re=xe.current.naturalWidth/xe.current.width,Jt=xe.current.naturalHeight/xe.current.height;re.width=h.width,re.height=h.height;let Lt=re.getContext("2d");if(Lt){Lt.drawImage(xe.current,h.x*Re,h.y*Jt,h.width*Re,h.height*Jt,0,0,h.width,h.height);let vr=await new Promise(ir=>re.toBlob(ir,C.mimeType));if(vr){let ir=new FormData;ir.append("file",vr,`cropped-${C.filename}`),g&&ir.append("folder",g),await ya("/api/media",ir),we(),O(!1),$.success("Cropped image saved");}}}catch(h){console.error("Crop failed:",h),$.error("Crop failed");}finally{P(false);}}},gt=useMemo(()=>i.reduce((h,re)=>(h.totalSize+=re.fileSize||0,h),{totalSize:0}),[i]);return jsxs("div",{className:`flex flex-col h-full bg-[var(--kyro-bg)] transition-all duration-300 ${qt?"ring-4 ring-[var(--kyro-sidebar-active)] ring-inset":""}`,...r?{}:{onDragOver:h=>{h.preventDefault(),vt(true);},onDragLeave:()=>vt(false),onDrop:h=>{h.preventDefault(),vt(false),h.dataTransfer.files&&D(h.dataTransfer.files);}},children:[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&&jsx("div",{className:"flex items-center gap-4",children:jsxs("div",{children:[jsx("h2",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:"Media Library"}),jsx("div",{className:"flex items-center gap-3 mt-1",children:jsxs("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50",children:[Pe," Items \xB7 ",bn(gt.totalSize)]})})]})}),jsxs("div",{className:`flex items-center gap-3 flex-wrap lg:flex-nowrap ${r?"w-full":""}`,children:[jsxs("div",{className:"relative group flex-1 min-w-[200px]",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",placeholder:"Search assets...",value:f,onChange:h=>y(h.target.value),className:"w-full pl-11 pr-4 py-2.5 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] transition-all text-xs font-bold"})]}),!r&&jsxs(Fragment,{children:[jsxs("div",{className:"flex items-center gap-2",children:[jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsx("button",{onClick:()=>L("grid"),className:`p-2 rounded-lg transition-all ${R==="grid"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsx(Grid3X3,{className:"w-4 h-4"})}),jsx("button",{onClick:()=>L("list"),className:`p-2 rounded-lg transition-all ${R==="list"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsx(File,{className:"w-4 h-4"})})]}),jsx("button",{onClick:()=>ue(true),className:"md:hidden p-2 rounded-xl bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] transition-colors",children:jsx(Filter,{className:"w-4 h-4"})})]}),a&&jsxs("button",{onClick:()=>q.current?.click(),className:"flex items-center gap-2 px-6 py-2.5 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs shadow-lg active:scale-95 transition-all",children:[jsx(Maximize2,{className:"w-4 h-4"}),"Upload"]})]})]})]}),jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[!r&&jsx("div",{className:"w-64 border-r border-[var(--kyro-border)] surface-tile mt-6 overflow-y-auto hidden md:block",children:jsxs("div",{className:"p-6 space-y-6",children:[jsxs("div",{children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsx("div",{className:"space-y-1",children:["all","image","video","audio","document","archive"].map(h=>jsxs("button",{onClick:()=>v(h),className:`w-full flex items-center gap-3 px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all ${b===h?"text-[var(--kyro-text-primary)] bg-[var(--kyro-surface-accent)]":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]/50"}`,children:[jsx("span",{className:`w-1.5 h-1.5 rounded-full ${b===h?"bg-[var(--kyro-primary)]":"bg-transparent border border-current opacity-30"}`}),h]},h))})]}),jsxs("div",{className:"pt-6 border-t border-[var(--kyro-border)]",children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),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:jsx(FolderPlus,{className:"w-4 h-4"})})]}),jsxs("nav",{className:"space-y-1",children:[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:[jsx(FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(h=>jsxs("div",{className:"group relative",children:[jsxs("button",{onClick:()=>x(h),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsx(Folder,{fill:g===h?"currentColor":"none"})}),h]}),jsx("button",{onClick:re=>{re.stopPropagation(),no(h);},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-red-500 opacity-0 group-hover:opacity-100 transition-all hover:bg-red-50 rounded-lg",children:jsx(Trash2,{className:"w-3.5 h-3.5"})})]},h))]})]})]})}),jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-[var(--kyro-bg)]",children:[jsx("div",{className:`flex-1 overflow-y-auto custom-scrollbar ${r?"px-2 py-4":"py-4 px-2 md:py-8 md:px-4"}`,children:d?jsx("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5",children:jsx(Ot,{variant:"media-card",count:12})}):i.length===0?jsxs("div",{className:"flex flex-col items-center justify-center py-32 text-center",children:[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:jsx(Grid3X3,{className:"w-10 h-10 text-[var(--kyro-text-muted)] opacity-30"})}),jsx("h3",{className:"text-xl font-bold text-[var(--kyro-text-primary)] tracking-tight",children:"No assets found"}),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&&jsx("button",{onClick:()=>q.current?.click(),className:"mt-8 px-8 py-3 bg-[var(--kyro-text-primary)] text-[var(--kyro-bg)] rounded-2xl font-bold text-xs hover:scale-105 transition-all shadow-xl",children:"Start Uploading"})]}):R==="grid"?jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-1",children:i.map((h,re)=>jsxs("div",{className:`group relative aspect-square rounded-lg overflow-hidden bg-[var(--kyro-surface-accent)] border-2 transition-all duration-300 cursor-pointer ${ye.has(h.id)?"border-[var(--kyro-primary)]":"border-transparent hover:border-[var(--kyro-border-strong)] hover:shadow-2xl hover:-translate-y-1"}`,onClick:()=>w(h),onContextMenu:Re=>{Re.preventDefault(),ee(h.id,Re);},children:[h.type==="image"?jsx("img",{src:h.url,alt:h.title,className:"w-full h-full object-cover transition-transform duration-700 group-hover:scale-110",loading:"lazy"}):jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-6 gap-4",children:[jsx("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface)] shadow-inner text-[var(--kyro-text-secondary)] group-hover:scale-110 transition-transform duration-500",children:h.type==="video"?jsx(Film,{className:"w-8 h-8"}):h.type==="audio"?jsx(Music,{className:"w-8 h-8"}):h.type==="document"?jsx(FileText,{className:"w-8 h-8"}):h.type==="archive"?jsx(Archive,{className:"w-8 h-8"}):jsx(File,{className:"w-8 h-8"})}),jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 text-center px-4 line-clamp-2",children:h.title})]}),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:jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-white font-bold text-[10px] truncate max-w-[120px]",children:h.filename}),jsx("div",{className:"flex gap-1",children:jsx("button",{onClick:Re=>ee(h.id,Re),className:`kyro-btn-primary p-1.5 rounded-lg transition-all ${ye.has(h.id)?"":"bg-white/10 text-white hover:bg-white/20"}`,children:jsx(Check,{className:"w-4 h-4"})})})]})}),ye.has(h.id)&&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:jsx(Check,{className:"w-4 h-4"})})]},h.id))}):jsx("div",{className:"surface-tile overflow-hidden animate-in fade-in duration-500",children:jsxs("table",{className:"w-full text-left",children:[jsx("thead",{children:jsxs("tr",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 border-b border-[var(--kyro-border)]",children:[jsx("th",{className:"px-6 py-4 w-12",children:jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]",checked:ye.size===i.length,onChange:h=>{h.target.checked?Se(new Set(i.map(re=>re.id))):Se(new Set);}})}),jsx("th",{className:"px-6 py-4",children:"Asset"}),jsx("th",{className:"px-6 py-4",children:"Type"}),jsx("th",{className:"px-6 py-4",children:"Size"}),jsx("th",{className:"px-6 py-4",children:"Date"}),jsx("th",{className:"px-6 py-4 text-right",children:"Actions"})]})}),jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:i.map(h=>jsxs("tr",{className:`group hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer ${ye.has(h.id)?"bg-[var(--kyro-surface-accent)]":""}`,onClick:()=>w(h),children:[jsx("td",{className:"px-6 py-4",onClick:re=>re.stopPropagation(),children:jsx("input",{type:"checkbox",checked:ye.has(h.id),onChange:re=>ee(h.id,re),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]"})}),jsx("td",{className:"px-6 py-4",children:jsxs("div",{className:"flex items-center gap-4",children:[jsx("div",{className:"w-12 h-12 rounded-xl bg-[var(--kyro-bg)] overflow-hidden border border-[var(--kyro-border)] flex-shrink-0 flex items-center justify-center",children:h.type==="image"?jsx("img",{src:h.url,alt:"",className:"w-full h-full object-cover"}):jsx(File,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50"})}),jsxs("div",{className:"flex flex-col min-w-0",children:[jsx("span",{className:"font-bold text-xs text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:h.title||h.filename}),jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:h.filename})]})]})}),jsx("td",{className:"px-6 py-4",children:jsx(Pt,{variant:"outline",className:"text-[9px]",children:h.mimeType})}),jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:bn(h.fileSize)}),jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:pp(h.createdAt)}),jsx("td",{className:"px-6 py-4 text-right",children:jsx("button",{onClick:re=>{re.stopPropagation(),ee(h.id,re);},className:`kyro-btn-primary p-2 rounded-lg transition-all ${ye.has(h.id)?"":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] opacity-0 group-hover:opacity-100"}`,children:jsx(Grid3X3,{className:"w-4 h-4"})})})]},h.id))})]})})}),jsx(fn,{page:ce,totalPages:I,onPageChange:he})]})]}),!r&&F&&jsx("div",{className:"fixed bottom-12 left-1/2 -translate-x-1/2 z-[60] w-full max-w-lg",children: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:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxs("div",{className:"flex items-center gap-3",children:[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:jsx(Ar,{})}),jsx("span",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Uploading Files"})]}),jsxs("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-50",children:[Object.keys(S).length," Total"]})]}),jsx("div",{className:"space-y-4 max-h-[160px] overflow-y-auto pr-2 custom-scrollbar",children:Object.entries(S).map(([h,re])=>jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"flex justify-between text-[10px] font-bold",children:[jsx("span",{className:"text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:h}),jsxs("span",{className:"text-[var(--kyro-primary)]",children:[re,"%"]})]}),jsx("div",{className:"h-1.5 w-full bg-[var(--kyro-surface-accent)] rounded-full overflow-hidden",children:jsx("div",{className:"h-full bg-[var(--kyro-primary)] transition-all duration-300 rounded-full",style:{width:`${re}%`}})})]},h))})]})}),ye.size>0&&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:[jsxs("div",{className:"flex items-center gap-5 border-r border-[var(--kyro-border)] ",children:[jsx("div",{className:"w-12 h-12 rounded-full bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center text-lg font-bold shadow-inner",children:ye.size}),jsxs("div",{children:[jsx("p",{className:"text-[11px] font-bold tracking-[0.2em] text-[var(--kyro-text-primary)]",children:"Selected"}),jsx("button",{onClick:()=>Se(new Set),className:"text-[10px] font-bold text-[var(--kyro-primary)] hover:underline opacity-80",children:"Clear all"})]})]}),jsxs("div",{className:"flex items-center gap-4",children:[e&&jsx("button",{onClick:()=>{let h=i.filter(re=>ye.has(re.id));e(h);},className:"px-8 py-3 bg-[var(--kyro-text-primary)] text-[var(--kyro-bg)] rounded-full font-bold text-xs hover:scale-105 transition-all shadow-xl",children:"Confirm Selection"}),!r&&n&&jsx("button",{onClick:G,className:"p-3 bg-red-500/10 text-red-500 hover:bg-red-500 hover:text-white rounded-full transition-all active:scale-90",children:jsx(Trash2,{className:"w-5 h-5"})})]})]}),ie&&!r&&jsxs("div",{className:"fixed inset-0 z-[70] md:hidden",children:[jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>ue(false)}),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:[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:[jsx("h3",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Filters"}),jsx("button",{onClick:()=>ue(false),className:"p-2 rounded-xl hover:bg-[var(--kyro-surface-accent)] transition-colors text-[var(--kyro-text-muted)]",children:jsx(X,{className:"w-4 h-4"})})]}),jsxs("div",{className:"p-6 space-y-8",children:[jsxs("div",{children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsx("div",{className:"flex flex-wrap gap-2",children:["all","image","video","audio","document","archive"].map(h=>jsx("button",{onClick:()=>{v(h),ue(false);},className:`px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all border ${b===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] border-transparent":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] border-[var(--kyro-border)] hover:border-[var(--kyro-text-muted)]"}`,children:h},h))})]}),jsxs("div",{children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),jsx("button",{onClick:()=>{se(true),ue(false);},className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors text-[var(--kyro-text-primary)]",children:jsx(FolderPlus,{className:"w-4 h-4"})})]}),jsxs("nav",{className:"space-y-1",children:[jsxs("button",{onClick:()=>{x(""),ue(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===""?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsx(FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(h=>jsxs("div",{className:"group relative",children:[jsxs("button",{onClick:()=>{x(h),ue(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${g===h?"bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] shadow-md":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] hover:text-[var(--kyro-text-primary)]"}`,children:[jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsx(Folder,{fill:g===h?"currentColor":"none"})}),h]}),jsx("button",{onClick:re=>{re.stopPropagation(),no(h),ue(false);},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-red-500 opacity-0 group-hover:opacity-100 transition-all hover:bg-red-50 rounded-lg",children:jsx(Trash2,{className:"w-3.5 h-3.5"})})]},h))]})]})]})]})]}),jsx(dr,{open:!!C,onClose:()=>w(null),title:"Asset Details",subtitle:C?.filename,children:C&&jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"aspect-video w-full rounded-2xl bg-[var(--kyro-bg)] border border-[var(--kyro-border)] overflow-hidden relative group",children:[C.type==="image"?jsx("img",{src:yo(C.url),alt:"",className:"w-full h-full object-contain p-4"}):C.type==="video"?jsx("video",{src:yo(C.url),controls:true,className:"w-full h-full"}):jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-12 gap-6",children:[jsx("div",{className:"w-20 h-20 rounded-[2rem] bg-[var(--kyro-surface-accent)] flex items-center justify-center",children:jsx(File,{className:"w-10 h-10 text-[var(--kyro-text-secondary)]"})}),jsx(Pt,{variant:"outline",className:"text-xs font-bold",children:C.mimeType})]}),jsx("div",{className:"absolute top-4 right-4 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:jsx("button",{onClick:()=>p(true),className:"p-2.5 bg-black/50 backdrop-blur-md text-white rounded-xl hover:bg-black/70 transition-all",children:jsx(Maximize2,{className:"w-4 h-4"})})})]}),jsxs("div",{className:"mt-8 space-y-8 flex-1",children:[jsxs("div",{className:"grid grid-cols-2 gap-4",children:[jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"Dimensions"}),jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:C.type==="image"?"Original Resolution":"N/A"})]}),jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"File Size"}),jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:bn(C.fileSize)})]})]}),jsxs("div",{className:"space-y-4",children:[jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Public Link"}),jsxs("div",{className:"flex gap-2",children:[jsx("input",{type:"text",readOnly:true,value:yo(C.url),className:"flex-1 px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-xl text-[10px] font-bold font-mono focus:outline-none"}),jsx("button",{onClick:()=>{navigator.clipboard.writeText(yo(C.url)),$.success("URL copied to clipboard");},className:"p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] border border-[var(--kyro-border)] rounded-xl transition-all",children:jsx(Link,{className:"w-4 h-4 text-[var(--kyro-text-primary)]"})})]})]}),jsxs("div",{className:"space-y-4",children:[jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Alt Text"}),jsx("textarea",{value:C.alt||"",onChange:h=>da(C.id,{alt:h.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-lg text-xs font-bold transition-all resize-none min-h-[80px] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Describe this asset..."})]}),jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Caption"}),jsx("textarea",{value:C.caption||"",onChange:h=>da(C.id,{caption:h.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] rounded-lg text-xs font-bold transition-all resize-none min-h-[80px] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Add a caption..."})]})]})]})]}),!r&&jsxs("div",{className:"pt-8 border-t border-[var(--kyro-border)] mt-8 flex gap-3 pb-8",children:[jsxs("button",{onClick:()=>{let h=document.createElement("a");h.href=yo(C.url),h.download=C.filename,h.click();},className:"flex-1 flex items-center justify-center gap-2 px-6 py-3 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-xl font-bold text-xs shadow-lg hover:opacity-90 transition-all",children:[jsx(Download,{className:"w-4 h-4"}),"Download"]}),C.type==="image"&&s&&jsx("button",{onClick:()=>O(true),className:"p-3 border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:jsx(Crop,{className:"w-4 h-4"})}),n&&jsx("button",{onClick:()=>{lt({title:"Delete Asset",message:`Are you sure you want to delete ${C.filename}? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await kt(`/api/media/${C.id}`),w(null),we();}catch(h){console.error("Delete failed:",h),$.error("Failed to delete asset");}}});},className:"p-3 border border-red-100 text-red-500 rounded-xl hover:bg-red-50 transition-all",children:jsx(Trash2,{className:"w-4 h-4"})})]})]})}),N&&C&&jsxs(Ut,{open:N,onClose:()=>p(false),title:"",size:"full",variant:"lightbox",children:[jsxs("div",{className:"flex items-center justify-between p-6",children:[jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-white font-bold text-lg tracking-tight",children:C.filename}),jsxs("span",{className:"text-white/40 text-[10px] font-bold tracking-widest mt-1",children:[bn(C.fileSize)," \xB7 ",C.mimeType]})]}),jsx("button",{onClick:()=>p(false),className:"p-3 bg-white/10 hover:bg-white/20 text-white rounded-2xl transition-all active:scale-90",children:jsx(X,{className:"w-6 h-6"})})]}),jsx("div",{className:"flex-1 w-full flex items-center justify-center p-12",children:C.type==="image"?jsx("img",{src:yo(C.url),alt:"",className:"max-h-full max-w-full object-contain shadow-2xl rounded-lg animate-in zoom-in-95 duration-500"}):C.type==="video"?jsx("video",{src:yo(C.url),controls:true,autoPlay:true,className:"max-h-full max-w-full rounded-lg shadow-2xl"}):jsxs("div",{className:"text-white text-center",children:[jsx(File,{className:"w-24 h-24 mx-auto mb-6 opacity-20"}),jsx("p",{className:"text-xl font-bold opacity-50",children:"Preview not available for this file type"})]})})]}),!r&&A&&C&&jsx(Ut,{open:A,onClose:()=>O(false),title:"",size:"full",variant:"lightbox",children:jsxs("div",{className:"flex flex-col h-full p-8",children:[jsxs("div",{className:"flex items-center justify-between mb-8",children:[jsx("h3",{className:"text-white font-bold text-2xl tracking-tighter",children:"Crop Image"}),jsxs("div",{className:"flex gap-3",children:[jsx("button",{type:"button",onClick:()=>O(false),className:"px-4 py-2 border border-white/20 text-white/80 hover:bg-white/10 rounded-lg font-bold text-sm transition-colors",children:"Cancel"}),jsx("button",{type:"button",disabled:F,onClick:Zn,className:"px-4 py-2 bg-[var(--kyro-sidebar-active)] hover:opacity-90 text-[var(--kyro-sidebar-text-active)] rounded-lg font-bold text-sm transition-colors",children:F?"Saving...":"Save Crop"})]})]}),jsx("div",{className:"flex-1 w-full flex items-center justify-center overflow-auto",children:jsx(ip,{crop:X$1,onChange:h=>le(h),children:jsx("img",{ref:xe,src:C.url,alt:"Crop preview",className:"max-h-[70vh] object-contain",onLoad:Ka})})})]})}),!r&&jsx(sl,{open:j,onClose:()=>se(false),onSubmit:sr,title:"Create New Folder",placeholder:"Folder name"}),!r&&jsx(Ut,{open:B,onClose:()=>K(false),title:"Storage Not Configured",size:"md",children:jsxs("div",{className:"text-center",children:[jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-[var(--kyro-sidebar-active)] flex items-center justify-center",children:jsx(Server,{className:"w-8 h-8 text-[var(--kyro-sidebar-text-active)]"})}),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."}),jsxs("div",{className:"flex gap-3",children:[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"}),jsx("button",{type:"button",onClick:()=>{et("/api/globals/storage-settings",{provider:"local",local:{uploadDir:"./public/uploads",baseUrl:"/uploads"}}).then(()=>{K(false),ne(true),window.location.reload();}).catch(()=>{$.error("Failed to configure storage");});},className:"flex-1 px-4 py-3 border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded-xl font-bold hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Use Defaults"})]})]})}),!r&&jsx("input",{type:"file",ref:q,onChange:h=>{h.target.files&&D(h.target.files);},multiple:true,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.txt,.zip,.rar,.tar"})]})}var Hp=[{name:"Default",value:"inherit"},{name:"Red",value:"#ef4444"},{name:"Orange",value:"#f97316"},{name:"Amber",value:"#f59e0b"},{name:"Emerald",value:"#10b981"},{name:"Blue",value:"#3b82f6"},{name:"Indigo",value:"#6366f1"},{name:"Violet",value:"#8b5cf6"},{name:"Rose",value:"#f43f5e"},{name:"Slate",value:"#64748b"}],gl=({editor:e,isExpanded:t,setIsExpanded:r,onOpenMediaPicker:o})=>{let[a,n]=useState(null),s=useRef(null);if(useEffect(()=>{function b(v){s.current&&!s.current.contains(v.target)&&n(null);}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]),!e)return null;let i=()=>{o();},l=()=>{let b=e.getAttributes("link").href,v=window.prompt("URL",b);if(v!==null){if(v===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:v}).run();}},d=b=>{b==="inherit"?e.chain().focus().unsetColor().run():e.chain().focus().setColor(b).run(),n(null);},c=b=>{n(a===b?null:b);},m=()=>e.isActive("heading",{level:1})?"Heading 1":e.isActive("heading",{level:2})?"Heading 2":e.isActive("heading",{level:3})?"Heading 3":e.isActive("heading",{level:4})?"Heading 4":"Normal Text",u=()=>e.isActive({textAlign:"center"})?jsx(AlignCenter,{size:12}):e.isActive({textAlign:"right"})?jsx(AlignRight,{size:12}):jsx(AlignLeft,{size:12}),g=()=>e.isActive("orderedList")?jsx(ListOrdered,{size:12}):e.isActive("taskList")?jsx(CheckSquare,{size:12}):jsx(List,{size:12}),x=()=>e.isActive("codeBlock")?jsx(Terminal,{size:12}):jsx(Quote,{size:12}),f=({onClick:b,isActive:v=false,disabled:R=false,children:L,title:C})=>jsx("button",{type:"button",onClick:b,disabled:R,title:C,className:`p-1 rounded flex items-center justify-center transition-all duration-150 relative
10
- ${v?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] shadow-xs scale-95":"text-[var(--kyro-text)] hover:bg-[var(--kyro-bg-hover)]"}
11
- ${R?"opacity-35 cursor-not-allowed":"cursor-pointer active:scale-90"}`,children:L}),y=({onClick:b,isActive:v,children:R,title:L})=>jsxs("button",{type:"button",onClick:b,title:L,className:`px-2 py-1 rounded flex items-center gap-1 transition-all duration-150 text-xs border border-transparent hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] active:scale-98
12
- ${v?"bg-[var(--kyro-bg-hover)] border-[var(--kyro-border)]":""}`,children:[R,jsx(ChevronDown,{size:10,className:"opacity-60"})]});return 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:[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:[jsx(f,{onClick:()=>e.chain().focus().undo().run(),disabled:!e.can().chain().focus().undo().run(),title:"Undo (Ctrl+Z)",children:jsx(Undo,{size:12})}),jsx(f,{onClick:()=>e.chain().focus().redo().run(),disabled:!e.can().chain().focus().redo().run(),title:"Redo (Ctrl+Y)",children:jsx(Redo,{size:12})})]}),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:[jsx(f,{onClick:()=>e.chain().focus().toggleBold().run(),disabled:!e.can().chain().focus().toggleBold().run(),isActive:e.isActive("bold"),title:"Bold (Ctrl+B)",children:jsx(Bold,{size:12})}),jsx(f,{onClick:()=>e.chain().focus().toggleItalic().run(),disabled:!e.can().chain().focus().toggleItalic().run(),isActive:e.isActive("italic"),title:"Italic (Ctrl+I)",children:jsx(Italic,{size:12})}),jsx(f,{onClick:()=>e.chain().focus().toggleUnderline().run(),disabled:!e.can().chain().focus().toggleUnderline().run(),isActive:e.isActive("underline"),title:"Underline (Ctrl+U)",children:jsx(Underline,{size:12})}),jsx(f,{onClick:()=>e.chain().focus().toggleStrike().run(),disabled:!e.can().chain().focus().toggleStrike().run(),isActive:e.isActive("strike"),title:"Strikethrough",children:jsx(Strikethrough,{size:12})}),jsx(f,{onClick:()=>e.chain().focus().toggleCode().run(),disabled:!e.can().chain().focus().toggleCode().run(),isActive:e.isActive("code"),title:"Inline Code",children:jsx(Code,{size:12})}),jsx(f,{onClick:()=>e.chain().focus().toggleHighlight().run(),isActive:e.isActive("highlight"),title:"Highlight Text",children:jsx(Highlighter,{size:12})}),jsxs("div",{className:"relative flex items-center justify-center",children:[jsx(f,{onClick:()=>c("color"),title:"Text Color",isActive:a==="color"||e.isActive("textStyle"),children:jsx(Palette,{size:12})}),a==="color"&&jsx("div",{className:"absolute top-full left-0 mt-1.5 p-2 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 flex flex-wrap gap-1 w-44 animate-in fade-in slide-in-from-top-1 duration-150",children:Hp.map(b=>jsx("button",{type:"button",onClick:()=>d(b.value),title:b.name,className:"w-6 h-6 rounded-full border border-[var(--kyro-border)] transition-transform hover:scale-115 active:scale-95 cursor-pointer relative",style:{backgroundColor:b.value==="inherit"?"transparent":b.value},children:b.value==="inherit"&&jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[10px] text-[var(--kyro-text)] font-semibold",children:"\u2205"})},b.name))})]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(y,{onClick:()=>c("heading"),isActive:a==="heading",title:"Heading hierarchy",children:jsx("span",{className:"font-medium text-[11px] leading-none min-w-[70px] text-left",children:m()})}),a==="heading"&&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:[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(b=>jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleHeading({level:b}).run(),n(null);},className:`px-2.5 py-1.5 text-xs text-left rounded-md hover:bg-[var(--kyro-bg-hover)] cursor-pointer text-[var(--kyro-text)] transition-colors
14
- ${e.isActive("heading",{level:b})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:["Heading ",b]},b))]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(y,{onClick:()=>c("lists"),isActive:a==="lists",title:"List Types",children:g()}),a==="lists"&&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:[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 _r({children:e}){return jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:e})}function Hr({children:e}){return jsx("div",{className:"flex items-center justify-end gap-3 mt-6",children:e})}function Ut({open:e,onClose:t,title:r,children:o,footer:a,size:n="md",variant:s="default"}){if(useEffect(()=>{let d=c=>{c.key==="Escape"&&t();};return e&&(document.addEventListener("keydown",d),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",d),document.body.style.overflow="";}},[e,t]),!e)return null;let i={sm:"max-w-sm",md:"max-w-md",lg:"max-w-lg",full:"w-full h-full max-w-none rounded-none border-0"},l=s==="lightbox";return createPortal(jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",children:[jsx("div",{className:`absolute inset-0 transition-all duration-500 ${l?"bg-black/95 backdrop-blur-none":"bg-[var(--kyro-black)]/40 backdrop-blur-md"}`,onClick:t}),jsxs("div",{className:`relative ${i[n]} ${l?"bg-transparent text-white":"bg-[var(--kyro-surface)]"} ${!l&&n!=="full"?"rounded-[var(--kyro-radius-lg)]":""} shadow-2xl animate-in fade-in zoom-in-95 duration-300 ${l?"":"border"} ${s==="danger"?"border-red-500/30":"border-[var(--kyro-border)]"} flex flex-col overflow-hidden`,children:[!l&&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:[jsx("h2",{className:"text-xl font-bold text-[var(--kyro-text-primary)]",children:r}),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:jsx(X,{className:"w-4 h-4"})})]}),jsx("div",{className:`flex-1 overflow-auto ${l?"":"px-8 py-8"}`,children:o}),a&&!l&&jsx("div",{className:"flex items-center justify-end gap-3 px-8 py-6 border-t border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/50",children:a})]})]}),document.body)}function xs({open:e,onClose:t,onConfirm:r,title:o,message:a,confirmLabel:n="Confirm",cancelLabel:s="Cancel",variant:i="default",loading:l=false}){return jsx(Ut,{open:e,onClose:t,title:o,size:"sm",footer:jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:t,disabled:l,className:"kyro-btn kyro-btn-md kyro-btn-secondary",children:s}),jsx("button",{type:"button",onClick:r,disabled:l,className:`kyro-btn kyro-btn-md ${i==="danger"?"kyro-btn-danger":"kyro-btn-primary"}`,children:l?"Loading...":n})]}),children:jsx("p",{className:"text-[var(--kyro-text-secondary)]",children:a})})}function dl({open:e,onClose:t,onSubmit:r,title:o,placeholder:a="",defaultValue:n=""}){let[s,i]=useState(n),l=d=>{d.preventDefault(),s.trim()&&(r(s.trim()),i(""),t());};return e?createPortal(jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",children:[jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),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:[jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-[var(--kyro-border)]",children:[jsx("h2",{className:"text-lg font-semibold text-[var(--kyro-text-primary)]",children:o}),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:jsx(X,{className:"w-4 h-4"})})]}),jsxs("form",{onSubmit:l,children:[jsx("div",{className:"px-6 py-4",children:jsx("input",{type:"text",value:s,onChange:d=>i(d.target.value),placeholder:a,autoFocus:true,className:"w-full px-3 py-2 border border-[var(--kyro-input-border)] rounded-lg bg-[var(--kyro-input-bg)] text-[var(--kyro-text-primary)] placeholder-[var(--kyro-text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent"})}),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:[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"}),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 vo(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 kn(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 vp(e){return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function gp(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 hn({onSelect:e,multiple:t=true,pickerMode:r=false}){let{permissions:o}=Or(),a=o?.media?.create!==false,n=o?.media?.delete!==false,s=o?.media?.update!==false,[i,l]=useState([]),[d,c]=useState(true),[m,v]=useState([]),[f,b]=useState(""),[x,g]=useState(""),[y,u]=useState("all"),[N,R]=useState("grid"),[S,h]=useState(null),[C,p]=useState(false),[P,M]=useState(false),[D,I]=useState(false),[A,re]=useState({}),[me,O]=useState(false),[W,se]=useState(false),[X$1,K]=useState(null),[Ne,Re]=useState(false),[T,_]=useState(false),[de,ke]=useState(1),[Ce,he]=useState(0),[L,z]=useState(1),We=40,[ye,Ae]=useState(new Set),{confirm:ct,alert:At}=st(),[qt,gt]=useState(false),J=useRef(null),[Z,le]=useState(),xe=useRef(null),Se=useCallback(async()=>{c(true);try{let w=new URLSearchParams({page:de.toString(),limit:We.toString()});f&&w.append("folder",f),x&&w.append("search",x),y!=="all"&&w.append("type",y);let ne=await Be(Ur(`/api/media?${w}`));l((ne.docs||[]).map(De=>({...De,type:gp(De.mimeType)}))),he(ne.totalDocs||0),z(ne.totalPages||1);}catch(w){console.error("Failed to load media:",w);}finally{c(false);}},[de,f,x,y]),et=useCallback(async()=>{try{let w=await Be(Ur("/api/media/folders"));v(Array.isArray(w)?w:w.folders||[]);}catch(w){console.error("Failed to load folders:",w);}},[]),St=useCallback(async()=>{try{let ne=!!(await Be("/api/globals/storage-settings"))?.data?.provider;K(ne);}catch{K(false);}},[]);useEffect(()=>{r||St();},[St,r]),useEffect(()=>{r||X$1===false&&!Ne&&(Re(true),_(true));},[r,X$1,Ne]),useEffect(()=>{Se();},[Se]),useEffect(()=>{et();},[et]),useEffect(()=>{if(r)return;let w=ne=>{let De=ne.clipboardData?.files;De&&De.length>0&&B(De);};return window.addEventListener("paste",w),()=>window.removeEventListener("paste",w)},[r,f,X$1]);let B=async w=>{if(!X$1){_(true);return}I(true);let ne=0,De=0;for(let Jt=0;Jt<w.length;Jt++){let Lt=w[Jt];try{let gr=new FormData;gr.append("file",Lt),f&&gr.append("folder",f),await va("/api/media/upload",gr,ir=>{re(ts=>({...ts,[Lt.name]:ir}));}),ne++;}catch(gr){console.error(`Upload failed for ${Lt.name}:`,gr),De++;}}I(false),re({}),Se(),et(),De>0&&E.error(`${De} file(s) failed to upload`),ne>0&&E.success(`${ne} file(s) uploaded successfully`);},G=()=>{ct({title:"Delete Media",message:`Are you sure you want to delete ${ye.size} item(s)? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{for(let w of Array.from(ye))await ht(`/api/media/${w}`);Ae(new Set),Se(),E.success(`${ye.size} item(s) deleted`);}catch(w){console.error("Bulk delete failed:",w),E.error("Failed to delete some items");}}});},ae=(w,ne)=>{ne.stopPropagation();let De=new Set(ye);De.has(w)?De.delete(w):(t||De.clear(),De.add(w)),Ae(De);},sr=async w=>{try{await ot("/api/media/folders",{name:w}),et(),O(!1),E.success(`Folder "${w}" created`);}catch(ne){console.error("Failed to create folder:",ne),E.error("Failed to create folder");}},io=w=>{ct({title:"Delete Folder",message:`Are you sure you want to delete the folder "${w}"? All media in this folder will be moved to the root.`,variant:"danger",confirmLabel:"Delete Folder",onConfirm:async()=>{try{await ht(`/api/media/folders?path=${encodeURIComponent(w)}`),f===w&&b(""),et(),Se(),E.success(`Folder "${w}" deleted`);}catch(ne){console.error("Failed to delete folder:",ne),E.error("Failed to delete folder");}}});},pa=async(w,ne)=>{try{let De=await Xt(`/api/media/${w}`,ne);l(Jt=>Jt.map(Lt=>Lt.id===w?De.doc:Lt)),S?.id===w&&h(De.doc),E.success("Metadata updated");}catch(De){console.error("Failed to update metadata:",De),E.error("Failed to update metadata");}},Wa=w=>{let{width:ne,height:De}=w.currentTarget,Jt=centerCrop(makeAspectCrop({unit:"%",width:90},1,ne,De),ne,De);le(Jt);},es=async()=>{if(!(!Z||!xe.current||!S)){I(true);try{let w=convertToPixelCrop(Z,xe.current.width,xe.current.height),ne=document.createElement("canvas"),De=xe.current.naturalWidth/xe.current.width,Jt=xe.current.naturalHeight/xe.current.height;ne.width=w.width,ne.height=w.height;let Lt=ne.getContext("2d");if(Lt){Lt.drawImage(xe.current,w.x*De,w.y*Jt,w.width*De,w.height*Jt,0,0,w.width,w.height);let gr=await new Promise(ir=>ne.toBlob(ir,S.mimeType));if(gr){let ir=new FormData;ir.append("file",gr,`cropped-${S.filename}`),f&&ir.append("folder",f),await va("/api/media",ir),Se(),M(!1),E.success("Cropped image saved");}}}catch(w){console.error("Crop failed:",w),E.error("Crop failed");}finally{I(false);}}},bt=useMemo(()=>i.reduce((w,ne)=>(w.totalSize+=ne.fileSize||0,w),{totalSize:0}),[i]);return jsxs("div",{className:`flex flex-col h-full bg-[var(--kyro-bg)] transition-all duration-300 ${qt?"ring-4 ring-[var(--kyro-sidebar-active)] ring-inset":""}`,...r?{}:{onDragOver:w=>{w.preventDefault(),gt(true);},onDragLeave:()=>gt(false),onDrop:w=>{w.preventDefault(),gt(false),w.dataTransfer.files&&B(w.dataTransfer.files);}},children:[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&&jsx("div",{className:"flex items-center gap-4",children:jsxs("div",{children:[jsx("h2",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:"Media Library"}),jsx("div",{className:"flex items-center gap-3 mt-1",children:jsxs("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50",children:[Ce," Items \xB7 ",kn(bt.totalSize)]})})]})}),jsxs("div",{className:`flex items-center gap-3 flex-wrap lg:flex-nowrap ${r?"w-full":""}`,children:[jsxs("div",{className:"relative group flex-1 min-w-[200px]",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",placeholder:"Search assets...",value:x,onChange:w=>g(w.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&&jsxs(Fragment,{children:[jsxs("div",{className:"flex items-center gap-2",children:[jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[jsx("button",{onClick:()=>R("grid"),className:`p-2 rounded-lg transition-all ${N==="grid"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsx(Grid3X3,{className:"w-4 h-4"})}),jsx("button",{onClick:()=>R("list"),className:`p-2 rounded-lg transition-all ${N==="list"?"bg-[var(--kyro-surface)] shadow-sm text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:jsx(File,{className:"w-4 h-4"})})]}),jsx("button",{onClick:()=>se(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:jsx(Filter,{className:"w-4 h-4"})})]}),a&&jsxs("button",{onClick:()=>J.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:[jsx(Maximize2,{className:"w-4 h-4"}),"Upload"]})]})]})]}),jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[!r&&jsx("div",{className:"w-64 border-r border-[var(--kyro-border)] surface-tile mt-6 overflow-y-auto hidden md:block",children:jsxs("div",{className:"p-6 space-y-6",children:[jsxs("div",{children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsx("div",{className:"space-y-1",children:["all","image","video","audio","document","archive"].map(w=>jsxs("button",{onClick:()=>u(w),className:`w-full flex items-center gap-3 px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all ${y===w?"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:[jsx("span",{className:`w-1.5 h-1.5 rounded-full ${y===w?"bg-[var(--kyro-primary)]":"bg-transparent border border-current opacity-30"}`}),w]},w))})]}),jsxs("div",{className:"pt-6 border-t border-[var(--kyro-border)]",children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),jsx("button",{onClick:()=>O(true),className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors text-[var(--kyro-text-primary)]",children:jsx(FolderPlus,{className:"w-4 h-4"})})]}),jsxs("nav",{className:"space-y-1",children:[jsxs("button",{onClick:()=>b(""),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${f===""?"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:[jsx(FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(w=>jsxs("div",{className:"group relative",children:[jsxs("button",{onClick:()=>b(w),className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${f===w?"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:[jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsx(Folder,{fill:f===w?"currentColor":"none"})}),w]}),jsx("button",{onClick:ne=>{ne.stopPropagation(),io(w);},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:jsx(Trash2,{className:"w-3.5 h-3.5"})})]},w))]})]})]})}),jsxs("div",{className:"flex-1 flex flex-col min-h-0 bg-[var(--kyro-bg)]",children:[jsx("div",{className:`flex-1 overflow-y-auto custom-scrollbar ${r?"px-2 py-4":"py-4 px-2 md:py-8 md:px-4"}`,children:d?jsx("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5",children:jsx(Ot,{variant:"media-card",count:12})}):i.length===0?jsxs("div",{className:"flex flex-col items-center justify-center py-32 text-center",children:[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:jsx(Grid3X3,{className:"w-10 h-10 text-[var(--kyro-text-muted)] opacity-30"})}),jsx("h3",{className:"text-xl font-bold text-[var(--kyro-text-primary)] tracking-tight",children:"No assets found"}),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&&jsx("button",{onClick:()=>J.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"})]}):N==="grid"?jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-1",children:i.map((w,ne)=>jsxs("div",{className:`group relative aspect-square rounded-lg overflow-hidden bg-[var(--kyro-surface-accent)] border-2 transition-all duration-300 cursor-pointer ${ye.has(w.id)?"border-[var(--kyro-primary)]":"border-transparent hover:border-[var(--kyro-border-strong)] hover:shadow-2xl hover:-translate-y-1"}`,onClick:()=>h(w),onContextMenu:De=>{De.preventDefault(),ae(w.id,De);},children:[w.type==="image"?jsx("img",{src:w.url,alt:w.title,className:"w-full h-full object-cover transition-transform duration-700 group-hover:scale-110",loading:"lazy"}):jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-6 gap-4",children:[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:w.type==="video"?jsx(Film,{className:"w-8 h-8"}):w.type==="audio"?jsx(Music,{className:"w-8 h-8"}):w.type==="document"?jsx(FileText,{className:"w-8 h-8"}):w.type==="archive"?jsx(Archive,{className:"w-8 h-8"}):jsx(File,{className:"w-8 h-8"})}),jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 text-center px-4 line-clamp-2",children:w.title})]}),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:jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-white font-bold text-[10px] truncate max-w-[120px]",children:w.filename}),jsx("div",{className:"flex gap-1",children:jsx("button",{onClick:De=>ae(w.id,De),className:`kyro-btn-primary p-1.5 rounded-lg transition-all ${ye.has(w.id)?"":"bg-white/10 text-white hover:bg-white/20"}`,children:jsx(Check,{className:"w-4 h-4"})})})]})}),ye.has(w.id)&&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:jsx(Check,{className:"w-4 h-4"})})]},w.id))}):jsx("div",{className:"surface-tile overflow-hidden animate-in fade-in duration-500",children:jsxs("table",{className:"w-full text-left",children:[jsx("thead",{children:jsxs("tr",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 border-b border-[var(--kyro-border)]",children:[jsx("th",{className:"px-6 py-4 w-12",children:jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]",checked:ye.size===i.length,onChange:w=>{w.target.checked?Ae(new Set(i.map(ne=>ne.id))):Ae(new Set);}})}),jsx("th",{className:"px-6 py-4",children:"Asset"}),jsx("th",{className:"px-6 py-4",children:"Type"}),jsx("th",{className:"px-6 py-4",children:"Size"}),jsx("th",{className:"px-6 py-4",children:"Date"}),jsx("th",{className:"px-6 py-4 text-right",children:"Actions"})]})}),jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:i.map(w=>jsxs("tr",{className:`group hover:bg-[var(--kyro-surface-accent)] transition-colors cursor-pointer ${ye.has(w.id)?"bg-[var(--kyro-surface-accent)]":""}`,onClick:()=>h(w),children:[jsx("td",{className:"px-6 py-4",onClick:ne=>ne.stopPropagation(),children:jsx("input",{type:"checkbox",checked:ye.has(w.id),onChange:ne=>ae(w.id,ne),className:"w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)]"})}),jsx("td",{className:"px-6 py-4",children:jsxs("div",{className:"flex items-center gap-4",children:[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:w.type==="image"?jsx("img",{src:w.url,alt:"",className:"w-full h-full object-cover"}):jsx(File,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50"})}),jsxs("div",{className:"flex flex-col min-w-0",children:[jsx("span",{className:"font-bold text-xs text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:w.title||w.filename}),jsx("span",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:w.filename})]})]})}),jsx("td",{className:"px-6 py-4",children:jsx(Dt,{variant:"outline",className:"text-[9px]",children:w.mimeType})}),jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:kn(w.fileSize)}),jsx("td",{className:"px-6 py-4 text-[11px] font-bold text-[var(--kyro-text-secondary)]",children:vp(w.createdAt)}),jsx("td",{className:"px-6 py-4 text-right",children:jsx("button",{onClick:ne=>{ne.stopPropagation(),ae(w.id,ne);},className:`kyro-btn-primary p-2 rounded-lg transition-all ${ye.has(w.id)?"":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] opacity-0 group-hover:opacity-100"}`,children:jsx(Grid3X3,{className:"w-4 h-4"})})})]},w.id))})]})})}),jsx(gn,{page:de,totalPages:L,onPageChange:ke})]})]}),!r&&D&&jsx("div",{className:"fixed bottom-12 left-1/2 -translate-x-1/2 z-[60] w-full max-w-lg",children: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:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsxs("div",{className:"flex items-center gap-3",children:[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:jsx(Pr,{})}),jsx("span",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Uploading Files"})]}),jsxs("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-50",children:[Object.keys(A).length," Total"]})]}),jsx("div",{className:"space-y-4 max-h-[160px] overflow-y-auto pr-2 custom-scrollbar",children:Object.entries(A).map(([w,ne])=>jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"flex justify-between text-[10px] font-bold",children:[jsx("span",{className:"text-[var(--kyro-text-primary)] truncate max-w-[200px]",children:w}),jsxs("span",{className:"text-[var(--kyro-primary)]",children:[ne,"%"]})]}),jsx("div",{className:"h-1.5 w-full bg-[var(--kyro-surface-accent)] rounded-full overflow-hidden",children:jsx("div",{className:"h-full bg-[var(--kyro-primary)] transition-all duration-300 rounded-full",style:{width:`${ne}%`}})})]},w))})]})}),ye.size>0&&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:[jsxs("div",{className:"flex items-center gap-5 border-r border-[var(--kyro-border)] ",children:[jsx("div",{className:"w-12 h-12 rounded-full bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] flex items-center justify-center text-lg font-bold shadow-inner",children:ye.size}),jsxs("div",{children:[jsx("p",{className:"text-[11px] font-bold tracking-[0.2em] text-[var(--kyro-text-primary)]",children:"Selected"}),jsx("button",{onClick:()=>Ae(new Set),className:"text-[10px] font-bold text-[var(--kyro-primary)] hover:underline opacity-80",children:"Clear all"})]})]}),jsxs("div",{className:"flex items-center gap-4",children:[e&&jsx("button",{onClick:()=>{let w=i.filter(ne=>ye.has(ne.id));e(w);},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&&jsx("button",{onClick:G,className:"p-3 bg-red-500/10 text-red-500 hover:bg-red-500 hover:text-white rounded-full transition-all active:scale-90",children:jsx(Trash2,{className:"w-5 h-5"})})]})]}),W&&!r&&jsxs("div",{className:"fixed inset-0 z-[70] md:hidden",children:[jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>se(false)}),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:[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:[jsx("h3",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Filters"}),jsx("button",{onClick:()=>se(false),className:"p-2 rounded-xl hover:bg-[var(--kyro-surface-accent)] transition-colors text-[var(--kyro-text-muted)]",children:jsx(X,{className:"w-4 h-4"})})]}),jsxs("div",{className:"p-6 space-y-8",children:[jsxs("div",{children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40 block mb-4",children:"Quick Filters"}),jsx("div",{className:"flex flex-wrap gap-2",children:["all","image","video","audio","document","archive"].map(w=>jsx("button",{onClick:()=>{u(w),se(false);},className:`px-4 py-2 rounded-xl text-[11px] font-bold capitalize transition-all border ${y===w?"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:w},w))})]}),jsxs("div",{children:[jsxs("div",{className:"flex items-center justify-between mb-4",children:[jsx("span",{className:"text-[10px] font-bold tracking-[0.2em] text-[var(--kyro-text-secondary)] opacity-40",children:"Folders"}),jsx("button",{onClick:()=>{O(true),se(false);},className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-colors text-[var(--kyro-text-primary)]",children:jsx(FolderPlus,{className:"w-4 h-4"})})]}),jsxs("nav",{className:"space-y-1",children:[jsxs("button",{onClick:()=>{b(""),se(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${f===""?"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:[jsx(FolderInput,{className:"w-4 h-4 opacity-70"}),"All Assets"]}),m.map(w=>jsxs("div",{className:"group relative",children:[jsxs("button",{onClick:()=>{b(w),se(false);},className:`w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-xs font-bold transition-all ${f===w?"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:[jsx("div",{className:"w-4 h-4 flex items-center justify-center opacity-70",children:jsx(Folder,{fill:f===w?"currentColor":"none"})}),w]}),jsx("button",{onClick:ne=>{ne.stopPropagation(),io(w),se(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:jsx(Trash2,{className:"w-3.5 h-3.5"})})]},w))]})]})]})]})]}),jsx(cr,{open:!!S,onClose:()=>h(null),title:"Asset Details",subtitle:S?.filename,children:S&&jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"aspect-video w-full rounded-2xl bg-[var(--kyro-bg)] border border-[var(--kyro-border)] overflow-hidden relative group",children:[S.type==="image"?jsx("img",{src:vo(S.url),alt:"",className:"w-full h-full object-contain p-4"}):S.type==="video"?jsx("video",{src:vo(S.url),controls:true,className:"w-full h-full"}):jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center p-12 gap-6",children:[jsx("div",{className:"w-20 h-20 rounded-[2rem] bg-[var(--kyro-surface-accent)] flex items-center justify-center",children:jsx(File,{className:"w-10 h-10 text-[var(--kyro-text-secondary)]"})}),jsx(Dt,{variant:"outline",className:"text-xs font-bold",children:S.mimeType})]}),jsx("div",{className:"absolute top-4 right-4 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:jsx("button",{onClick:()=>p(true),className:"p-2.5 bg-black/50 backdrop-blur-md text-white rounded-xl hover:bg-black/70 transition-all",children:jsx(Maximize2,{className:"w-4 h-4"})})})]}),jsxs("div",{className:"mt-8 space-y-8 flex-1",children:[jsxs("div",{className:"grid grid-cols-2 gap-4",children:[jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"Dimensions"}),jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:S.type==="image"?"Original Resolution":"N/A"})]}),jsxs("div",{className:"p-4 rounded-2xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsx("span",{className:"text-[9px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-1",children:"File Size"}),jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-primary)]",children:kn(S.fileSize)})]})]}),jsxs("div",{className:"space-y-4",children:[jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Public Link"}),jsxs("div",{className:"flex gap-2",children:[jsx("input",{type:"text",readOnly:true,value:vo(S.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"}),jsx("button",{onClick:()=>{navigator.clipboard.writeText(vo(S.url)),E.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:jsx(Link,{className:"w-4 h-4 text-[var(--kyro-text-primary)]"})})]})]}),jsxs("div",{className:"space-y-4",children:[jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Alt Text"}),jsx("textarea",{value:S.alt||"",onChange:w=>pa(S.id,{alt:w.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..."})]}),jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-secondary)] opacity-50 block mb-2 px-1",children:"Caption"}),jsx("textarea",{value:S.caption||"",onChange:w=>pa(S.id,{caption:w.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&&jsxs("div",{className:"pt-8 border-t border-[var(--kyro-border)] mt-8 flex gap-3 pb-8",children:[jsxs("button",{onClick:()=>{let w=document.createElement("a");w.href=vo(S.url),w.download=S.filename,w.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:[jsx(Download,{className:"w-4 h-4"}),"Download"]}),S.type==="image"&&s&&jsx("button",{onClick:()=>M(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:jsx(Crop,{className:"w-4 h-4"})}),n&&jsx("button",{onClick:()=>{ct({title:"Delete Asset",message:`Are you sure you want to delete ${S.filename}? This cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await ht(`/api/media/${S.id}`),h(null),Se();}catch(w){console.error("Delete failed:",w),E.error("Failed to delete asset");}}});},className:"p-3 border border-red-100 text-red-500 rounded-xl hover:bg-red-50 transition-all",children:jsx(Trash2,{className:"w-4 h-4"})})]})]})}),C&&S&&jsxs(Ut,{open:C,onClose:()=>p(false),title:"",size:"full",variant:"lightbox",children:[jsxs("div",{className:"flex items-center justify-between p-6",children:[jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-white font-bold text-lg tracking-tight",children:S.filename}),jsxs("span",{className:"text-white/40 text-[10px] font-bold tracking-widest mt-1",children:[kn(S.fileSize)," \xB7 ",S.mimeType]})]}),jsx("button",{onClick:()=>p(false),className:"p-3 bg-white/10 hover:bg-white/20 text-white rounded-2xl transition-all active:scale-90",children:jsx(X,{className:"w-6 h-6"})})]}),jsx("div",{className:"flex-1 w-full flex items-center justify-center p-12",children:S.type==="image"?jsx("img",{src:vo(S.url),alt:"",className:"max-h-full max-w-full object-contain shadow-2xl rounded-lg animate-in zoom-in-95 duration-500"}):S.type==="video"?jsx("video",{src:vo(S.url),controls:true,autoPlay:true,className:"max-h-full max-w-full rounded-lg shadow-2xl"}):jsxs("div",{className:"text-white text-center",children:[jsx(File,{className:"w-24 h-24 mx-auto mb-6 opacity-20"}),jsx("p",{className:"text-xl font-bold opacity-50",children:"Preview not available for this file type"})]})})]}),!r&&P&&S&&jsx(Ut,{open:P,onClose:()=>M(false),title:"",size:"full",variant:"lightbox",children:jsxs("div",{className:"flex flex-col h-full p-8",children:[jsxs("div",{className:"flex items-center justify-between mb-8",children:[jsx("h3",{className:"text-white font-bold text-2xl tracking-tighter",children:"Crop Image"}),jsxs("div",{className:"flex gap-3",children:[jsx("button",{type:"button",onClick:()=>M(false),className:"px-4 py-2 border border-white/20 text-white/80 hover:bg-white/10 rounded-lg font-bold text-sm transition-colors",children:"Cancel"}),jsx("button",{type:"button",disabled:D,onClick:es,className:"px-4 py-2 bg-[var(--kyro-sidebar-active)] hover:opacity-90 text-[var(--kyro-sidebar-text-active)] rounded-lg font-bold text-sm transition-colors",children:D?"Saving...":"Save Crop"})]})]}),jsx("div",{className:"flex-1 w-full flex items-center justify-center overflow-auto",children:jsx(mp,{crop:Z,onChange:w=>le(w),children:jsx("img",{ref:xe,src:S.url,alt:"Crop preview",className:"max-h-[70vh] object-contain",onLoad:Wa})})})]})}),!r&&jsx(dl,{open:me,onClose:()=>O(false),onSubmit:sr,title:"Create New Folder",placeholder:"Folder name"}),!r&&jsx(Ut,{open:T,onClose:()=>_(false),title:"Storage Not Configured",size:"md",children:jsxs("div",{className:"text-center",children:[jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-[var(--kyro-sidebar-active)] flex items-center justify-center",children:jsx(Server,{className:"w-8 h-8 text-[var(--kyro-sidebar-text-active)]"})}),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."}),jsxs("div",{className:"flex gap-3",children:[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"}),jsx("button",{type:"button",onClick:()=>{ot("/api/globals/storage-settings",{provider:"local",local:{uploadDir:"./public/uploads",baseUrl:"/uploads"}}).then(()=>{_(false),K(true),window.location.reload();}).catch(()=>{E.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&&jsx("input",{type:"file",ref:J,onChange:w=>{w.target.files&&B(w.target.files);},multiple:true,className:"hidden",accept:"image/*,video/*,audio/*,.pdf,.doc,.docx,.txt,.zip,.rar,.tar"})]})}var Wp=[{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"}],kl=({editor:e,isExpanded:t,setIsExpanded:r,onOpenMediaPicker:o})=>{let[a,n]=useState(null),s=useRef(null);if(useEffect(()=>{function y(u){s.current&&!s.current.contains(u.target)&&n(null);}return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]),!e)return null;let i=()=>{o();},l=()=>{let y=e.getAttributes("link").href,u=window.prompt("URL",y);if(u!==null){if(u===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:u}).run();}},d=y=>{y==="inherit"?e.chain().focus().unsetColor().run():e.chain().focus().setColor(y).run(),n(null);},c=y=>{n(a===y?null:y);},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",v=()=>e.isActive({textAlign:"center"})?jsx(AlignCenter,{size:12}):e.isActive({textAlign:"right"})?jsx(AlignRight,{size:12}):jsx(AlignLeft,{size:12}),f=()=>e.isActive("orderedList")?jsx(ListOrdered,{size:12}):e.isActive("taskList")?jsx(CheckSquare,{size:12}):jsx(List,{size:12}),b=()=>e.isActive("codeBlock")?jsx(Terminal,{size:12}):jsx(Quote,{size:12}),x=({onClick:y,isActive:u=false,disabled:N=false,children:R,title:S})=>jsx("button",{type:"button",onClick:y,disabled:N,title:S,className:`p-1 rounded flex items-center justify-center transition-all duration-150 relative
10
+ ${u?"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
+ ${N?"opacity-35 cursor-not-allowed":"cursor-pointer active:scale-90"}`,children:R}),g=({onClick:y,isActive:u,children:N,title:R})=>jsxs("button",{type:"button",onClick:y,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
+ ${u?"bg-[var(--kyro-bg-hover)] border-[var(--kyro-border)]":""}`,children:[N,jsx(ChevronDown,{size:10,className:"opacity-60"})]});return 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:[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:[jsx(x,{onClick:()=>e.chain().focus().undo().run(),disabled:!e.can().chain().focus().undo().run(),title:"Undo (Ctrl+Z)",children:jsx(Undo,{size:12})}),jsx(x,{onClick:()=>e.chain().focus().redo().run(),disabled:!e.can().chain().focus().redo().run(),title:"Redo (Ctrl+Y)",children:jsx(Redo,{size:12})})]}),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:[jsx(x,{onClick:()=>e.chain().focus().toggleBold().run(),disabled:!e.can().chain().focus().toggleBold().run(),isActive:e.isActive("bold"),title:"Bold (Ctrl+B)",children:jsx(Bold,{size:12})}),jsx(x,{onClick:()=>e.chain().focus().toggleItalic().run(),disabled:!e.can().chain().focus().toggleItalic().run(),isActive:e.isActive("italic"),title:"Italic (Ctrl+I)",children:jsx(Italic,{size:12})}),jsx(x,{onClick:()=>e.chain().focus().toggleUnderline().run(),disabled:!e.can().chain().focus().toggleUnderline().run(),isActive:e.isActive("underline"),title:"Underline (Ctrl+U)",children:jsx(Underline,{size:12})}),jsx(x,{onClick:()=>e.chain().focus().toggleStrike().run(),disabled:!e.can().chain().focus().toggleStrike().run(),isActive:e.isActive("strike"),title:"Strikethrough",children:jsx(Strikethrough,{size:12})}),jsx(x,{onClick:()=>e.chain().focus().toggleCode().run(),disabled:!e.can().chain().focus().toggleCode().run(),isActive:e.isActive("code"),title:"Inline Code",children:jsx(Code,{size:12})}),jsx(x,{onClick:()=>e.chain().focus().toggleHighlight().run(),isActive:e.isActive("highlight"),title:"Highlight Text",children:jsx(Highlighter,{size:12})}),jsxs("div",{className:"relative flex items-center justify-center",children:[jsx(x,{onClick:()=>c("color"),title:"Text Color",isActive:a==="color"||e.isActive("textStyle"),children:jsx(Palette,{size:12})}),a==="color"&&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:Wp.map(y=>jsx("button",{type:"button",onClick:()=>d(y.value),title:y.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:y.value==="inherit"?"transparent":y.value},children:y.value==="inherit"&&jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[10px] text-[var(--kyro-text)] font-semibold",children:"\u2205"})},y.name))})]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(g,{onClick:()=>c("heading"),isActive:a==="heading",title:"Heading hierarchy",children:jsx("span",{className:"font-medium text-[11px] leading-none min-w-[70px] text-left",children:m()})}),a==="heading"&&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:[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(y=>jsxs("button",{type:"button",onClick:()=>{e.chain().focus().toggleHeading({level:y}).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:y})?"font-semibold text-[var(--kyro-primary)] bg-[var(--kyro-bg-hover)]":""}`,children:["Heading ",y]},y))]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(g,{onClick:()=>c("lists"),isActive:a==="lists",title:"List Types",children:f()}),a==="lists"&&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:[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:[jsx(List,{size:12}),"Bullet List"]}),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:[jsx(ListOrdered,{size:12}),"Ordered List"]}),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:[jsx(CheckSquare,{size:12}),"Task Checklist"]})]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(y,{onClick:()=>c("blocks"),isActive:a==="blocks",title:"Structural Blocks",children:x()}),a==="blocks"&&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:[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:[jsx(CheckSquare,{size:12}),"Task Checklist"]})]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(g,{onClick:()=>c("blocks"),isActive:a==="blocks",title:"Structural Blocks",children:b()}),a==="blocks"&&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:[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:[jsx(Quote,{size:12}),"Blockquote"]}),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:[jsx(Terminal,{size:12}),"Code Block"]}),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:[jsx(Minus,{size:12}),"Horizontal Rule"]})]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(y,{onClick:()=>c("align"),isActive:a==="align",title:"Alignment",children:u()}),a==="align"&&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:[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:[jsx(Terminal,{size:12}),"Code Block"]}),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:[jsx(Minus,{size:12}),"Horizontal Rule"]})]})]}),jsxs("div",{className:"relative flex items-center p-0.5 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-xs",children:[jsx(g,{onClick:()=>c("align"),isActive:a==="align",title:"Alignment",children:v()}),a==="align"&&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:[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:[jsx(AlignLeft,{size:12}),"Align Left"]}),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:[jsx(AlignCenter,{size:12}),"Align Center"]}),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:[jsx(AlignRight,{size:12}),"Align Right"]})]})]}),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:[jsx(f,{onClick:l,isActive:e.isActive("link"),title:"Link",children:jsx(Link,{size:12})}),jsx(f,{onClick:i,title:"Add Image",children:jsx(Image,{size:12})})]}),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:jsx(f,{onClick:()=>r(!t),title:t?"Collapse Workspace":"Enlarge Workspace",children:t?jsx(Minimize2,{size:12}):jsx(Maximize2,{size:12})})})]})};function $o({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false);return useEffect(()=>{s(true);},[]),n?jsx(_p,{field:e,value:t,onChange:r,error:o,disabled:a}):jsx(nt,{field:e,error:o,children: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:[jsx(AlignRight,{size:12}),"Align Right"]})]})]}),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:[jsx(x,{onClick:l,isActive:e.isActive("link"),title:"Link",children:jsx(Link,{size:12})}),jsx(x,{onClick:i,title:"Add Image",children:jsx(Image,{size:12})})]}),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:jsx(x,{onClick:()=>r(!t),title:t?"Collapse Workspace":"Enlarge Workspace",children:t?jsx(Minimize2,{size:12}):jsx(Maximize2,{size:12})})})]})};function Oo({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false);return useEffect(()=>{s(true);},[]),n?jsx(qp,{field:e,value:t,onChange:r,error:o,disabled:a}):jsx(lt,{field:e,error:o,children: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:[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]"}),jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px] p-4"})]})})}function _p({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false),[i,l]=useState(0),[d,c]=useState(false);useEffect(()=>{if(!n){l(0);return}let u=document.querySelector('[data-kyro-slide-panel="true"]'),g=()=>{l(u?u.getBoundingClientRect().width:0);};g();let x=new MutationObserver(()=>{g();});u&&x.observe(u),window.addEventListener("resize",g);let f=setInterval(g,100);return ()=>{x&&x.disconnect(),window.removeEventListener("resize",g),clearInterval(f);}},[n]);let m=useEditor({extensions:[gp.configure({codeBlock:true,link:false,underline:false}),bp.configure({openOnClick:false}),xp,kp.configure({types:["heading","paragraph"]}),hp,wp.configure({multicolor:true}),Np,Cp.configure({nested:true}),TextStyle,Tp],content:Array.isArray(t)?{type:"doc",content:t}:t||{type:"doc",content:[]},editable:!a,onUpdate:({editor:u})=>{r(u.getJSON());},editorProps:{attributes:{class:"prose prose-sm dark:prose-invert focus:outline-none min-h-[160px] p-4 max-w-none kyro-richtext text-[0.875rem] leading-relaxed"}}});return useEffect(()=>{m&&t&&JSON.stringify(t)!==JSON.stringify(m.getJSON())&&m.commands.setContent(Array.isArray(t)?{type:"doc",content:t}:t);},[t,m]),jsxs(nt,{field:e,error:o,children:[n?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:[jsx("span",{className:"font-medium",children:"Rich text editor workspace is currently maximized."}),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"})]}):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:[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]"}),jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px] p-4"})]})})}function qp({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false),[i,l]=useState(0),[d,c]=useState(false);useEffect(()=>{if(!n){l(0);return}let v=document.querySelector('[data-kyro-slide-panel="true"]'),f=()=>{l(v?v.getBoundingClientRect().width:0);};f();let b=new MutationObserver(()=>{f();});v&&b.observe(v),window.addEventListener("resize",f);let x=setInterval(f,100);return ()=>{b&&b.disconnect(),window.removeEventListener("resize",f),clearInterval(x);}},[n]);let m=useEditor({extensions:[wp.configure({codeBlock:true,link:false,underline:false}),Np.configure({openOnClick:false}),Cp,Sp.configure({types:["heading","paragraph"]}),Tp,Rp.configure({multicolor:true}),Ap,Fp.configure({nested:true}),TextStyle,Dp],content:Array.isArray(t)?{type:"doc",content:t}:t||{type:"doc",content:[]},editable:!a,onUpdate:({editor:v})=>{r(v.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 useEffect(()=>{m&&t&&JSON.stringify(t)!==JSON.stringify(m.getJSON())&&m.commands.setContent(Array.isArray(t)?{type:"doc",content:t}:t);},[t,m]),jsxs(lt,{field:e,error:o,children:[n?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:[jsx("span",{className:"font-medium",children:"Rich text editor workspace is currently maximized."}),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"})]}):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:[jsx(gl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px]",children:jsx(EditorContent,{editor:m})})]}),n&&typeof document<"u"&&createPortal(jsxs("div",{style:{position:"fixed",top:"16px",bottom:"16px",left:"16px",right:i>0?`${i+16}px`:"16px",zIndex:9999},className:"flex flex-col bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-200 transition-all duration-300",children:[jsx(gl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsx("div",{className:"overflow-y-auto flex-1 h-[calc(100vh-140px)] bg-[var(--kyro-bg)]",children:jsx(EditorContent,{editor:m})})]}),document.body),jsx("style",{children:`
26
+ ${a?"opacity-60 cursor-not-allowed":""}`,children:[jsx(kl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsx("div",{className:"overflow-y-auto min-h-[160px] max-h-[400px]",children:jsx(EditorContent,{editor:m})})]}),n&&typeof document<"u"&&createPortal(jsxs("div",{style:{position:"fixed",top:"16px",bottom:"16px",left:"16px",right:i>0?`${i+16}px`:"16px",zIndex:9999},className:"flex flex-col bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-md shadow-2xl overflow-hidden animate-in fade-in zoom-in-95 duration-200 transition-all duration-300",children:[jsx(kl,{editor:m,isExpanded:n,setIsExpanded:s,onOpenMediaPicker:()=>c(true)}),jsx("div",{className:"overflow-y-auto flex-1 h-[calc(100vh-140px)] bg-[var(--kyro-bg)]",children:jsx(EditorContent,{editor:m})})]}),document.body),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 @@ import ka,{createContext,lazy,useState,useRef,useEffect,useCallback,useContext,u
79
79
  font-style: italic !important;
80
80
  }
81
81
 
82
- `}),d&&jsx(dr,{open:d,onClose:()=>c(false),title:"Select Image",width:"xl",children:jsx(xn,{pickerMode:true,multiple:false,onSelect:u=>{if(u&&u.length>0){let g=u[0];m.chain().focus().setImage({src:g.url,alt:g.alt||g.title||"",title:g.title||""}).run();}c(false);}})})]})}var Eo={id:"light",label:"Light",colors:{primary:"#3b82f6",secondary:"#8b5cf6",background:"#f8fafc",surface:"#ffffff",text:"#0f172a",textMuted:"#64748b",border:"#e2e8f0",success:"#22c55e",error:"#ef4444",warning:"#f59e0b",info:"#06b6d4"},typography:{fontFamily:"'Inter', system-ui, -apple-system, sans-serif",fontFamilyMono:"'Fira Code', 'Cascadia Code', monospace"},spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem","2xl":"3rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},shadows:{sm:"0 1px 2px rgba(0,0,0,0.05)",md:"0 4px 6px -1px rgba(0,0,0,0.1)",lg:"0 10px 15px -3px rgba(0,0,0,0.1)",xl:"0 20px 25px -5px rgba(0,0,0,0.1)"}},Sa={id:"dark",label:"Dark",colors:{primary:"#60a5fa",secondary:"#a78bfa",background:"#0b1222",surface:"#1e293b",text:"#f1f5f9",textMuted:"#94a3b8",border:"#334155",success:"#4ade80",error:"#f87171",warning:"#fbbf24",info:"#22d3ee"},typography:{fontFamily:"'Inter', system-ui, -apple-system, sans-serif",fontFamilyMono:"'Fira Code', 'Cascadia Code', monospace"},spacing:{xs:"0.25rem",sm:"0.5rem",md:"1rem",lg:"1.5rem",xl:"2rem","2xl":"3rem"},borderRadius:{sm:"0.25rem",md:"0.5rem",lg:"0.75rem",full:"9999px"},shadows:{sm:"0 1px 2px rgba(0,0,0,0.3)",md:"0 4px 6px -1px rgba(0,0,0,0.4)",lg:"0 10px 15px -3px rgba(0,0,0,0.4)",xl:"0 20px 25px -5px rgba(0,0,0,0.5)"}};function Ta(e,t){return {...e,...t,colors:{...e.colors,...t.colors},typography:{...e.typography,...t.typography},spacing:{...e.spacing,...t.spacing},borderRadius:{...e.borderRadius,...t.borderRadius},shadows:{...e.shadows,...t.shadows},blocks:e.blocks?{...e.blocks,...t.blocks}:t.blocks,fields:e.fields?{...e.fields,...t.fields}:t.fields}}var hl=createContext(null);function Oo(){let e=useContext(hl);return e||{mode:"light",theme:Eo,lightTheme:Eo,darkTheme:Sa,setMode:()=>{},updateTheme:()=>{},getCssVar:t=>`var(--kyro-${t})`}}function xl(e){let t=document.documentElement;t&&(e.colors&&Object.entries(e.colors).forEach(([r,o])=>{o&&(t.style.setProperty(`--kyro-${r}`,o),t.style.setProperty(`--kyro-${r}-light`,kl(o,.9)),t.style.setProperty(`--kyro-${r}-dark`,kl(o,.8)));}),e.typography&&(e.typography.fontFamily&&t.style.setProperty("--kyro-font-family",e.typography.fontFamily),e.typography.fontFamilyMono&&t.style.setProperty("--kyro-font-mono",e.typography.fontFamilyMono)),e.spacing&&Object.entries(e.spacing).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-spacing-${r}`,o);}),e.borderRadius&&Object.entries(e.borderRadius).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-radius-${r}`,o);}),e.shadows&&Object.entries(e.shadows).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-shadow-${r}`,o);}),e.blocks&&(e.blocks.card&&Object.entries(e.blocks.card).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-block-card-${r}`,o);}),e.blocks.hero?.background&&t.style.setProperty("--kyro-block-hero-bg",e.blocks.hero.background),e.blocks.code&&Object.entries(e.blocks.code).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-block-code-${r}`,o);})),e.fields&&(e.fields.input&&Object.entries(e.fields.input).forEach(([r,o])=>{o&&t.style.setProperty(`--kyro-field-input-${r}`,o);}),e.fields.upload&&e.fields.upload.dropzoneBackground&&t.style.setProperty("--kyro-field-upload-dropzone-bg",e.fields.upload.dropzoneBackground)));}function kl(e,t){if(!e.startsWith("#"))return e;let r=parseInt(e.slice(1,3),16),o=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16),n=s=>Math.round(s*t).toString(16).padStart(2,"0");return `#${n(r)}${n(o)}${n(a)}`}function kr({children:e,defaultMode:t="light",light:r,dark:o}){let[a,n]=useState(t),[s,i]=useState(r||{}),[l,d]=useState(o||{}),c=Ta(Eo,s),m=Ta(Sa,l),u=useCallback(()=>a==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?m:c:a==="dark"?m:c,[a,c,m]),[g,x]=useState(u());useEffect(()=>{let b=u();x(b),xl(b);},[u]),useEffect(()=>{if(a!=="system")return;let b=window.matchMedia("(prefers-color-scheme: dark)"),v=()=>{let R=u();x(R),xl(R);};return b.addEventListener("change",v),()=>b.removeEventListener("change",v)},[a,u]);let f=useCallback(b=>{i(v=>({...v,...b})),d(v=>({...v,...b}));},[]),y=useCallback(b=>`var(--kyro-${b})`,[]);return jsx(hl.Provider,{value:{mode:a,theme:g,lightTheme:c,darkTheme:m,setMode:n,updateTheme:f,getCssVar:y},children:e})}var wn=e=>jsx(kr,{defaultMode:"light",...e}),Nn=e=>jsx(kr,{defaultMode:"dark",...e});var Xp=lazy(()=>import('@uiw/react-codemirror').then(e=>({default:e.default}))),Qp=[{value:"javascript",label:"JavaScript"},{value:"typescript",label:"TypeScript"},{value:"json",label:"JSON"},{value:"html",label:"HTML"},{value:"css",label:"CSS"},{value:"sql",label:"SQL"},{value:"python",label:"Python"},{value:"rust",label:"Rust"},{value:"java",label:"Java"},{value:"php",label:"PHP"},{value:"markdown",label:"Markdown"}],Nl={javascript:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true,typescript:true})),typescript:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true,typescript:true})),js:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true})),jsx:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({jsx:true})),ts:()=>import('@codemirror/lang-javascript').then(e=>e.javascript({typescript:true})),json:()=>import('@codemirror/lang-json').then(e=>e.json()),css:()=>import('@codemirror/lang-css').then(e=>e.css()),sql:()=>import('@codemirror/lang-sql').then(e=>e.sql()),python:()=>import('@codemirror/lang-python').then(e=>e.python()),html:()=>import('@codemirror/lang-html').then(e=>e.html()),rust:()=>import('@codemirror/lang-rust').then(e=>e.rust()),java:()=>import('@codemirror/lang-java').then(e=>e.java()),cpp:()=>import('@codemirror/lang-cpp').then(e=>e.cpp()),c:()=>import('@codemirror/lang-cpp').then(e=>e.cpp()),php:()=>import('@codemirror/lang-php').then(e=>e.php()),markdown:()=>import('@codemirror/lang-markdown').then(e=>e.markdown()),py:()=>import('@codemirror/lang-python').then(e=>e.python())},Aa=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=useState(false),[i,l]=useState(false),[d,c]=useState([]),[m,u]=useState(false),[g,x]=useState(false),[f,y]=useState(false),{theme:b}=Oo(),v=b.colors?.accent||b.colors?.primary||"#6366f1",R=e.language?.toLowerCase()||"javascript";useEffect(()=>{s(true),l(document.documentElement.classList.contains("dark"));let O=new MutationObserver(()=>{l(document.documentElement.classList.contains("dark"));});return O.observe(document.documentElement,{attributes:true,attributeFilter:["class"]}),()=>O.disconnect()},[]),useEffect(()=>{if(!n)return;(async()=>{u(true);try{let P=await(Nl[R]||Nl.javascript)();c([P]);}catch(F){console.error("Failed to load language extension:",F),c([]);}finally{u(false);}})();},[R,n]);let L=useCallback(O=>r?.(O),[r]),C=useCallback(()=>{navigator.clipboard.writeText(t),x(true),setTimeout(()=>x(false),1500);},[t]),w=useCallback(()=>{y(O=>!O),document.body.style.overflow=f?"":"hidden";},[f]),N=i?aura:githubLight,p=Qp.find(O=>O.value===R)?.label||R,A=(O,F=1)=>{let P=parseInt(O.slice(1,3),16),S=parseInt(O.slice(3,5),16),M=parseInt(O.slice(5,7),16);return `rgba(${P}, ${S}, ${M}, ${F})`};return n?jsxs("div",{className:"group",style:{"--accent":v,"--accent-light":A(v,.1),"--accent-light-2":A(v,.05)},children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:e.label||e.name}),jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-semibold transition-colors",style:{backgroundColor:m?"var(--kyro-surface-accent)":v,color:m?"var(--kyro-text-muted)":"white"},children:m?"...":p})]}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",onClick:C,className:"text-[10px] px-2 py-0.5 rounded font-medium transition-all",style:{backgroundColor:g?"var(--kyro-success)":"var(--kyro-surface-accent)",color:g?"white":"var(--kyro-text-secondary)"},children:g?"Copied":"Copy"}),jsx("button",{type:"button",onClick:w,className:"text-[10px] px-2 py-0.5 rounded font-medium bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] transition-all",style:{color:"var(--kyro-text-secondary)"},children:f?"Exit":"Expand"})]})]}),jsxs("div",{className:`relative rounded-md overflow-hidden transition-all duration-200 ${f?"fixed inset-4 z-50":""}`,style:{backgroundColor:"var(--kyro-surface)",borderColor:o?"var(--kyro-error)":"var(--kyro-border)",borderWidth:"1px"},children:[jsx("div",{className:"absolute top-0 left-0 right-0 h-0.5 transition-all duration-200",style:{backgroundColor:v}}),jsx(Suspense,{fallback:jsx("div",{className:"h-[280px] flex items-center justify-center",style:{backgroundColor:"var(--kyro-surface)"},children:jsx("div",{className:"w-6 h-6 rounded-full animate-spin",style:{borderColor:"var(--kyro-border)",borderTopColor:v,borderWidth:"2px"}})}),children:jsx(Xp,{value:t??"",height:f?"calc(100vh - 100px)":"280px",width:"100%",extensions:d,theme:N,onChange:L,editable:!a,basicSetup:{lineNumbers:true,highlightActiveLine:true,bracketMatching:true,closeBrackets:true,autocompletion:true,foldGutter:true},style:{fontSize:"13px",fontFamily:"'JetBrains Mono', 'Fira Code', monospace"}})}),o&&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})]}),jsxs("div",{className:"flex items-center justify-between mt-2 text-[10px]",style:{color:"var(--kyro-text-muted)"},children:[jsxs("span",{children:[t.split(`
83
- `).length," lines"]}),jsx("span",{style:{color:v},children:"CodeMirror"})]})]}):jsxs("div",{className:"space-y-3",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"h-5 w-24 rounded bg-[var(--kyro-surface-accent)] animate-pulse"}),jsx("div",{className:"h-5 w-16 rounded bg-[var(--kyro-surface-accent)] animate-pulse"})]}),jsx("div",{className:"h-[280px] rounded-xl bg-[var(--kyro-surface-accent)] animate-pulse"})]})};function tm(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/```(\w+)?\n([\s\S]*?)```/g,'<pre class="bg-gray-100 dark:bg-gray-800 p-3 rounded overflow-x-auto my-2"><code>$2</code></pre>').replace(/`([^`]+)`/g,'<code class="bg-gray-100 dark:bg-gray-800 px-1 rounded text-sm font-mono">$1</code>').replace(/^### (.+)$/gm,'<h3 class="text-lg font-semibold mt-4 mb-2">$1</h3>').replace(/^## (.+)$/gm,'<h2 class="text-xl font-semibold mt-4 mb-2">$1</h2>').replace(/^# (.+)$/gm,'<h1 class="text-2xl font-bold mt-4 mb-2">$1</h1>').replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>").replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/\*(.+?)\*/g,"<em>$1</em>").replace(/___(.+?)___/g,"<strong><em>$1</em></strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/_(.+?)_/g,"<em>$1</em>").replace(/~~(.+?)~~/g,"<del>$1</del>").replace(/^> (.+)$/gm,'<blockquote class="border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic my-2 text-gray-600 dark:text-gray-400">$1</blockquote>').replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" class="text-blue-600 hover:underline" target="_blank" rel="noopener noreferrer">$1</a>').replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" class="max-w-full h-auto rounded my-2" />').replace(/^---$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^\*\*\*$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^[\*\-] (.+)$/gm,'<li class="ml-4">$1</li>').replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>').replace(/^(?!<[a-z]|$)(.+)$/gm,'<p class="my-2">$1</p>').replace(/<p class="my-2"><\/p>/g,"").replace(/(<li class="ml-4">.*<\/li>\n?)+/g,'<ul class="list-disc pl-6 my-2">$&</ul>'):""}var Ns=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=useState(false),[i,l]=useState(false);useEffect(()=>{l(true);},[]);let d=useCallback(u=>{r?.(u.target.value);},[r]),c=useMemo(()=>t?t.trim().split(/\s+/).filter(Boolean).length:0,[t]),m=t?.length||0;return i?jsxs("div",{className:"kyro-form-field",style:{position:"relative",zIndex:10,pointerEvents:"auto"},children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxs("div",{className:"flex items-center gap-3",children:[jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[c," words \u2022 ",m," chars"]}),jsxs("div",{className:"flex rounded-md overflow-hidden border border-[var(--kyro-border)]",children:[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"}),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"})]})]})]}),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?jsx("div",{className:"p-6 min-h-[300px] overflow-auto bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)]",children:t?jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",dangerouslySetInnerHTML:{__html:tm(t)}}):jsx("p",{className:"text-[var(--kyro-text-muted)] italic",children:"Nothing to preview"})}):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&&jsx(cr,{open:d,onClose:()=>c(false),title:"Select Image",width:"xl",children:jsx(hn,{pickerMode:true,multiple:false,onSelect:v=>{if(v&&v.length>0){let f=v[0];m.chain().focus().setImage({src:f.url,alt:f.alt||f.title||"",title:f.title||""}).run();}c(false);}})})]})}var Uo={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)"}},Ra={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 Aa(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 Cl=createContext(null);function zo(){let e=useContext(Cl);return e||{mode:"light",theme:Uo,lightTheme:Uo,darkTheme:Ra,setMode:()=>{},updateTheme:()=>{},getCssVar:t=>`var(--kyro-${t})`}}function wl(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`,Nl(o,.9)),t.style.setProperty(`--kyro-${r}-dark`,Nl(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 Nl(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]=useState(t),[s,i]=useState(r||{}),[l,d]=useState(o||{}),c=Aa(Uo,s),m=Aa(Ra,l),v=useCallback(()=>a==="system"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?m:c:a==="dark"?m:c,[a,c,m]),[f,b]=useState(v());useEffect(()=>{let y=v();b(y),wl(y);},[v]),useEffect(()=>{if(a!=="system")return;let y=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{let N=v();b(N),wl(N);};return y.addEventListener("change",u),()=>y.removeEventListener("change",u)},[a,v]);let x=useCallback(y=>{i(u=>({...u,...y})),d(u=>({...u,...y}));},[]),g=useCallback(y=>`var(--kyro-${y})`,[]);return jsx(Cl.Provider,{value:{mode:a,theme:f,lightTheme:c,darkTheme:m,setMode:n,updateTheme:x,getCssVar:g},children:e})}var Cn=e=>jsx(hr,{defaultMode:"light",...e}),Sn=e=>jsx(hr,{defaultMode:"dark",...e});var tm=lazy(()=>import('@uiw/react-codemirror').then(e=>({default:e.default}))),rm=[{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"}],Tl={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())},Fa=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=useState(false),[i,l]=useState(false),[d,c]=useState([]),[m,v]=useState(false),[f,b]=useState(false),[x,g]=useState(false),{theme:y}=zo(),u=y.colors?.accent||y.colors?.primary||"#6366f1",N=e.language?.toLowerCase()||"javascript";useEffect(()=>{s(true),l(document.documentElement.classList.contains("dark"));let M=new MutationObserver(()=>{l(document.documentElement.classList.contains("dark"));});return M.observe(document.documentElement,{attributes:true,attributeFilter:["class"]}),()=>M.disconnect()},[]),useEffect(()=>{if(!n)return;(async()=>{v(true);try{let I=await(Tl[N]||Tl.javascript)();c([I]);}catch(D){console.error("Failed to load language extension:",D),c([]);}finally{v(false);}})();},[N,n]);let R=useCallback(M=>r?.(M),[r]),S=useCallback(()=>{navigator.clipboard.writeText(t),b(true),setTimeout(()=>b(false),1500);},[t]),h=useCallback(()=>{g(M=>!M),document.body.style.overflow=x?"":"hidden";},[x]),C=i?aura:githubLight,p=rm.find(M=>M.value===N)?.label||N,P=(M,D=1)=>{let I=parseInt(M.slice(1,3),16),A=parseInt(M.slice(3,5),16),re=parseInt(M.slice(5,7),16);return `rgba(${I}, ${A}, ${re}, ${D})`};return n?jsxs("div",{className:"group",style:{"--accent":u,"--accent-light":P(u,.1),"--accent-light-2":P(u,.05)},children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-sm font-semibold text-[var(--kyro-text-primary)]",children:e.label||e.name}),jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-semibold transition-colors",style:{backgroundColor:m?"var(--kyro-surface-accent)":u,color:m?"var(--kyro-text-muted)":"white"},children:m?"...":p})]}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",onClick:S,className:"text-[10px] px-2 py-0.5 rounded font-medium transition-all",style:{backgroundColor:f?"var(--kyro-success)":"var(--kyro-surface-accent)",color:f?"white":"var(--kyro-text-secondary)"},children:f?"Copied":"Copy"}),jsx("button",{type:"button",onClick:h,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:x?"Exit":"Expand"})]})]}),jsxs("div",{className:`relative rounded-md overflow-hidden transition-all duration-200 ${x?"fixed inset-4 z-50":""}`,style:{backgroundColor:"var(--kyro-surface)",borderColor:o?"var(--kyro-error)":"var(--kyro-border)",borderWidth:"1px"},children:[jsx("div",{className:"absolute top-0 left-0 right-0 h-0.5 transition-all duration-200",style:{backgroundColor:u}}),jsx(Suspense,{fallback:jsx("div",{className:"h-[280px] flex items-center justify-center",style:{backgroundColor:"var(--kyro-surface)"},children:jsx("div",{className:"w-6 h-6 rounded-full animate-spin",style:{borderColor:"var(--kyro-border)",borderTopColor:u,borderWidth:"2px"}})}),children:jsx(tm,{value:t??"",height:x?"calc(100vh - 100px)":"280px",width:"100%",extensions:d,theme:C,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&&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})]}),jsxs("div",{className:"flex items-center justify-between mt-2 text-[10px]",style:{color:"var(--kyro-text-muted)"},children:[jsxs("span",{children:[t.split(`
83
+ `).length," lines"]}),jsx("span",{style:{color:u},children:"CodeMirror"})]})]}):jsxs("div",{className:"space-y-3",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"h-5 w-24 rounded bg-[var(--kyro-surface-accent)] animate-pulse"}),jsx("div",{className:"h-5 w-16 rounded bg-[var(--kyro-surface-accent)] animate-pulse"})]}),jsx("div",{className:"h-[280px] rounded-xl bg-[var(--kyro-surface-accent)] animate-pulse"})]})};function sm(e){return e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/```(\w+)?\n([\s\S]*?)```/g,'<pre class="bg-gray-100 dark:bg-gray-800 p-3 rounded overflow-x-auto my-2"><code>$2</code></pre>').replace(/`([^`]+)`/g,'<code class="bg-gray-100 dark:bg-gray-800 px-1 rounded text-sm font-mono">$1</code>').replace(/^### (.+)$/gm,'<h3 class="text-lg font-semibold mt-4 mb-2">$1</h3>').replace(/^## (.+)$/gm,'<h2 class="text-xl font-semibold mt-4 mb-2">$1</h2>').replace(/^# (.+)$/gm,'<h1 class="text-2xl font-bold mt-4 mb-2">$1</h1>').replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>").replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/\*(.+?)\*/g,"<em>$1</em>").replace(/___(.+?)___/g,"<strong><em>$1</em></strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/_(.+?)_/g,"<em>$1</em>").replace(/~~(.+?)~~/g,"<del>$1</del>").replace(/^> (.+)$/gm,'<blockquote class="border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic my-2 text-gray-600 dark:text-gray-400">$1</blockquote>').replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" class="text-blue-600 hover:underline" target="_blank" rel="noopener noreferrer">$1</a>').replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" class="max-w-full h-auto rounded my-2" />').replace(/^---$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^\*\*\*$/gm,'<hr class="border-gray-300 dark:border-gray-600 my-4" />').replace(/^[\*\-] (.+)$/gm,'<li class="ml-4">$1</li>').replace(/^\d+\. (.+)$/gm,'<li class="ml-4 list-decimal">$1</li>').replace(/^(?!<[a-z]|$)(.+)$/gm,'<p class="my-2">$1</p>').replace(/<p class="my-2"><\/p>/g,"").replace(/(<li class="ml-4">.*<\/li>\n?)+/g,'<ul class="list-disc pl-6 my-2">$&</ul>'):""}var Cs=({field:e,value:t="",onChange:r,error:o,disabled:a})=>{let[n,s]=useState(false),[i,l]=useState(false);useEffect(()=>{l(true);},[]);let d=useCallback(v=>{r?.(v.target.value);},[r]),c=useMemo(()=>t?t.trim().split(/\s+/).filter(Boolean).length:0,[t]),m=t?.length||0;return i?jsxs("div",{className:"kyro-form-field",style:{position:"relative",zIndex:10,pointerEvents:"auto"},children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsxs("div",{className:"flex items-center gap-3",children:[jsxs("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:[c," words \u2022 ",m," chars"]}),jsxs("div",{className:"flex rounded-md overflow-hidden border border-[var(--kyro-border)]",children:[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"}),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"})]})]})]}),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?jsx("div",{className:"p-6 min-h-[300px] overflow-auto bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)]",children:t?jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",dangerouslySetInnerHTML:{__html:sm(t)}}):jsx("p",{className:"text-[var(--kyro-text-muted)] italic",children:"Nothing to preview"})}):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,16 +96,16 @@ import ka,{createContext,lazy,useState,useRef,useEffect,useCallback,useContext,u
96
96
 
97
97
  \`\`\`
98
98
  code block
99
- \`\`\``})}),!n&&jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs text-[var(--kyro-text-muted)]",children:[jsx("span",{children:"**bold**"}),jsx("span",{children:"*italic*"}),jsx("span",{children:"`code`"}),jsx("span",{children:"[link](url)"}),jsx("span",{children:"# heading"})]}),e.admin?.description&&!o&&jsx("p",{className:"kyro-form-help",children:e.admin.description}),o&&jsx("p",{className:"kyro-form-error",children:o})]}):jsxs("div",{className:"kyro-form-field",children:[jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsx("div",{className:"h-[200px] bg-[var(--kyro-surface)] animate-pulse rounded-md border border-[var(--kyro-border)]"})]})};function Cn({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false),[i,l]=useState(false),d=t??"",c=d.length>8?d.slice(0,-8)+"*".repeat(8):d,m=async()=>{if(d)try{await navigator.clipboard.writeText(d),s(!0),setTimeout(()=>s(!1),1800);}catch{let g=document.createElement("textarea");g.value=d,g.style.position="fixed",g.style.opacity="0",document.body.appendChild(g),g.select(),document.execCommand("copy"),document.body.removeChild(g),s(true),setTimeout(()=>s(false),1800);}},u=()=>{if(i||a)return;l(true);let g=new Uint8Array(32);crypto.getRandomValues(g);let x=Array.from(g).map(f=>f.toString(16).padStart(2,"0")).join("");r?.(x),setTimeout(()=>l(false),400);};return jsx(nt,{field:e,error:o,children:jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("div",{className:"relative flex-1",children: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})}),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?jsx(Check,{className:"w-3.5 h-3.5 text-[var(--kyro-success)]"}):jsx(Copy,{className:"w-3.5 h-3.5"})}),jsx("button",{type:"button",onClick:u,disabled:a,className:"p-2 rounded-lg border border-[var(--kyro-border)] bg-[var(--kyro-surface)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-warning)] hover:bg-[var(--kyro-warning)]/10 transition-all disabled:opacity-40 disabled:cursor-not-allowed active:scale-95",title:"Regenerate secret",children:jsx(RefreshCw,{className:`w-3.5 h-3.5 ${i?"animate-spin":""}`})})]})})}var Sn=null,Tl=false,Cs=async()=>(Sn&&Tl||(Sn=createStorage({driver:im({dbName:"kyro-autosave",storeName:"autosave"})}),Tl=true),Sn),lm=()=>typeof window>"u"?{getItem:async()=>null,setItem:async()=>{},removeItem:async()=>{}}:{getItem:async e=>{try{return await(await Cs()).getItem(e)??null}catch(t){return console.error("Storage getItem error:",t),localStorage.getItem(e)}},setItem:async(e,t)=>{try{await(await Cs()).setItem(e,t);}catch(r){console.error("Storage setItem error:",r),localStorage.setItem(e,t);}},removeItem:async e=>{try{await(await Cs()).removeItem(e);}catch(t){console.error("Storage removeItem error:",t),localStorage.removeItem(e);}}},Le=create()(persist((e,t)=>({formData:{},lastSavedData:{},sidebarCollapsed:false,draftCache:{},dirtyFields:new Set,activeTab:0,isSlugLocked:true,view:"edit",isDropdownOpen:false,versions:[],loadingVersions:false,showPreview:false,isMenuOpen:false,hasUnsavedChanges:false,loadingFields:{},compareMode:false,compareSelected:[],compareDiffs:[],loadingDiffs:false,isAutoSaving:false,autoSaveStatus:"idle",backgroundProcessing:false,lastAutoSaveTime:0,lastSavedAt:null,retryCount:0,autoSaveSkip:false,autoSaveTimer:null,setField:(r,o)=>{let a=t(),n=new Set(a.dirtyFields);JSON.stringify(o)!==JSON.stringify(a.lastSavedData[r])?n.add(r):n.delete(r),e({formData:{...a.formData,[r]:o},dirtyFields:n,hasUnsavedChanges:n.size>0});},setFormData:r=>{e({formData:r});},setNestedField:(r,o)=>{e(a=>{let n=r.split("."),s={...a.formData},i=s;for(let l=0;l<n.length-1;l++)i[n[l]]===void 0&&(i[n[l]]={}),i[n[l]]={...i[n[l]]},i=i[n[l]];return i[n[n.length-1]]=o,{formData:s}});},setActiveTab:r=>e({activeTab:r}),setIsSlugLocked:r=>e(o=>({isSlugLocked:typeof r=="function"?r(o.isSlugLocked):r})),setView:r=>e({view:r}),setIsDropdownOpen:r=>e(o=>({isDropdownOpen:typeof r=="function"?r(o.isDropdownOpen):r})),setVersions:r=>e({versions:r}),setLoadingVersions:r=>e({loadingVersions:r}),setShowPreview:r=>e(o=>({showPreview:typeof r=="function"?r(o.showPreview):r})),setIsMenuOpen:r=>e(o=>({isMenuOpen:typeof r=="function"?r(o.isMenuOpen):r})),setHasUnsavedChanges:r=>e({hasUnsavedChanges:r}),setLoadingFields:r=>e(o=>({loadingFields:typeof r=="function"?r(o.loadingFields):r})),updateLoadingField:(r,o)=>e(a=>({loadingFields:{...a.loadingFields,[r]:o}})),setCompareMode:r=>e({compareMode:r}),setCompareSelected:r=>e(o=>({compareSelected:typeof r=="function"?r(o.compareSelected):r})),setCompareDiffs:r=>e({compareDiffs:r}),setLoadingDiffs:r=>e({loadingDiffs:r}),setIsAutoSaving:r=>e({isAutoSaving:r}),setAutoSaveStatus:r=>e({autoSaveStatus:r}),setBackgroundProcessing:r=>e({backgroundProcessing:r}),setSidebarCollapsed:r=>e({sidebarCollapsed:r}),setLastSavedAt:r=>e({lastSavedAt:r}),setRetryCount:r=>e({retryCount:r}),setAutoSaveSkip:r=>e({autoSaveSkip:r}),setLastAutoSaveTime:r=>e({lastAutoSaveTime:r}),startAutoSaveTimer:(r,o)=>{let{autoSaveTimer:a}=t();a&&clearTimeout(a);let n=setTimeout(r,o);e({autoSaveTimer:n});},clearAutoSaveTimer:()=>{let{autoSaveTimer:r}=t();r&&(clearTimeout(r),e({autoSaveTimer:null}));},markSaved:()=>{let{formData:r}=t();e({lastSavedData:r,hasUnsavedChanges:false,dirtyFields:new Set,lastSavedAt:Date.now()});},setLastSavedData:r=>{e({lastSavedData:r});},resetForm:()=>{e({formData:{},lastSavedData:{},hasUnsavedChanges:false,dirtyFields:new Set,activeTab:0});},loadDocument:(r,o)=>{let a=t();a.formData===r&&a.lastSavedData===(o||r)&&!a.hasUnsavedChanges||e({formData:r,lastSavedData:o||r,hasUnsavedChanges:false,dirtyFields:new Set});},getField:r=>t().formData[r],getNestedField:r=>{let o=r.split("."),a=t().formData;for(let n of o){if(a==null)return;a=a[n];}return a},getHasChanges:()=>t().dirtyFields.size>0,hasDirtyFields:()=>t().dirtyFields.size>0,getDirtyData:()=>{let{formData:r,dirtyFields:o}=t(),a={};for(let n of o)a[n]=r[n];return a},clearDirtyFields:()=>{e({dirtyFields:new Set,hasUnsavedChanges:false});},pruneExpiredDrafts:()=>{let o=Date.now(),{draftCache:a}=t(),n={};for(let[s,i]of Object.entries(a))o-new Date(i.draftUpdatedAt).getTime()<6048e5&&(n[s]=i);e({draftCache:n});},setDraftCache:(r,o)=>e(a=>({draftCache:{...a.draftCache,[r]:o}})),getDraftCache:r=>t().draftCache[r]||null,clearDraftCache:r=>e(o=>{let a={...o.draftCache};return delete a[r],{draftCache:a}})}),{name:"kyro-autoform-storage",storage:createJSONStorage(()=>lm()),partialize:e=>({sidebarCollapsed:e.sidebarCollapsed,draftCache:e.draftCache}),onRehydrateStorage:()=>e=>{e&&e.pruneExpiredDrafts();}}));function Tn(e){return e?e.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function jo({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.variant==="textarea",i=e.name==="slug",{isSlugLocked:l,setIsSlugLocked:d,formData:c}=Le(),m=e.variant==="email"?"email":e.variant==="password"?"password":e.variant==="url"?"url":"text",u=t==null?"":String(t),g={id:e.name,value:u,onChange:x=>r?.(x.target.value),placeholder:e.admin?.placeholder,disabled:a||n||i&&l,minLength:e.minLength,maxLength:e.maxLength,required:e.required,className:`kyro-form-input ${i?"pr-24":""} ${a||n||i&&l?"opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed":""}`};return jsx(nt,{field:e,error:o,children:jsxs("div",{className:"relative",children:[s?jsx("textarea",{...g,rows:e.rows||4}):jsx("input",{type:m,...g,pattern:e.pattern}),i&&jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:[!l&&jsx("button",{type:"button",onClick:()=>r?.(Tn(c[e.admin?.autoGenerate||"title"]||"")),className:"p-1 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)]",title:"Regenerate slug",children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),jsx("path",{d:"M21 3v5h-5"})]})}),jsx("button",{type:"button",onClick:()=>d(!l),className:`p-1.5 rounded transition-colors ${l?"text-[var(--kyro-primary)] bg-[var(--kyro-primary-alpha)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,title:l?"Unlock slug":"Lock slug",children:l?jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}):jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})})]}),e.name?.toLowerCase().includes("metatitle")&&jsx("div",{className:"flex items-center justify-between mt-1 text-[10px] font-bold tracking-wider",children:jsxs("span",{className:u.length>60?"text-red-500":u.length>=40?"text-green-500":"text-amber-600",children:[u.length," / 60 \u2014 ",u.length>60?"Too Long":u.length>=40?"Ideal":"Short"]})})]})})}function An({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsx(nt,{field:e,error:o,children:jsx("input",{type:"number",id:e.name,value:t??"",onChange:s=>r?.(parseFloat(s.target.value)||0),placeholder:e.admin?.placeholder,disabled:a||n,min:e.min,max:e.max,step:e.step||(e.integer?1:"any"),required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`})})}function Rn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsx(nt,{field:e,error:o,hideLabel:true,children:jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer group py-0.5",children:[jsx("input",{type:"checkbox",checked:t??false,onChange:i=>r?.(i.target.checked),disabled:a||n,className:`w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)] transition-all ${a||n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`}),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&&jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})]})})}function Fn({field:e,value:t="",onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsx(nt,{field:e,error:o,children:jsx("input",{type:e.time?"datetime-local":"date",id:e.name,value:t??"",onChange:s=>r?.(s.target.value),disabled:a||n,min:e.minDate,max:e.maxDate,required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`})})}function Fa(e){return e?Array.isArray(e)?e:Object.values(e):[]}function Dn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Bn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Ra(e,t){let r=new Set(e.map(o=>o.slug));for(let o of t)r.has(o.slug)||(e.push(o),r.add(o.slug));}var cm={pages:"FileText",posts:"Newspaper",categories:"Tags",menu:"Menu",products:"ShoppingBag",customers:"Users",orders:"ShoppingCart",coupons:"Ticket",forms:"FileInput","form-entries":"Inbox"};function fo(e,t,r){let o=t.split(".");if(o.length===0)return false;let a=o[0],n=o.slice(1).join(".");for(let s of e){if(s.name===a)if(n){if(s.fields&&Array.isArray(s.fields))return fo(s.fields,n,r);if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&fo(l.fields,n,r))return true;return false}if(s.type==="blocks"&&s.blocks&&Array.isArray(s.blocks)){let l=n.split(".")[0],d=n.split(".").slice(1).join(".");if(!d)return false;for(let c of s.blocks)if(c.slug===l&&c.fields&&Array.isArray(c.fields))return fo(c.fields,d,r);return false}return s.type==="array"&&s.fields&&Array.isArray(s.fields)?fo(s.fields,n,r):false}else return Object.assign(s,r),true;if(!s.name||s.type==="tabs"||s.type==="row"||s.type==="collapsible"){if(s.fields&&Array.isArray(s.fields)&&fo(s.fields,t,r))return true;if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&fo(l.fields,t,r))return true}}}return false}function pm(e,t){for(let[r,o]of Object.entries(e)){let a=cm[r],n=t?.[r];if(a&&!o.admin?.icon&&(o.admin={...o.admin,icon:a}),n){let{fields:s,...i}=n;if(o.admin={...o.admin,...i},s&&o.fields&&Array.isArray(o.fields))for(let[l,d]of Object.entries(s))fo(o.fields,l,d);}}}function mm(e="blog"){let t=[],r=[];switch(e){case "minimal":t.push(...Object.values(minimalCollections)),r.push(...coreSettingsGlobals);break;case "starter":t.push(...Object.values(starterCollections)),r.push(...coreSettingsGlobals);break;case "blog":t.push(...Object.values(blogCollections)),r.push(...coreSettingsGlobals);break;case "ecommerce":t.push(...Object.values(ecommerceCollections)),r.push(...allSettingsGlobals);break;case "kitchen-sink":t.push(...Object.values(minimalCollections),...Object.values(starterCollections),...Object.values(blogCollections),...Object.values(ecommerceCollections),...Object.values(kitchenSinkCollections)),r.push(...allSettingsGlobals);break}return Ra(t,Object.values(mediaCollections)),Ra(t,Object.values(authCollections)),{collections:Dn(t),globals:Bn(r)}}function um(e){let t=Fa(e.collections),r=Fa(e.globals);if(t.length===0&&r.length===0)return mm("kitchen-sink");let o=[];return Ra(o,Object.values(mediaCollections)),Ra(o,Object.values(authCollections)),Ra(o,t),{collections:Dn(o),globals:Bn(r)}}var Pn=null;function ym(){if(Pn)return Pn;try{if(typeof __KYRO_ADMIN_CONFIG_FILE__=="string"&&Ro.existsSync(__KYRO_ADMIN_CONFIG_FILE__))return Pn=JSON.parse(Ro.readFileSync(__KYRO_ADMIN_CONFIG_FILE__,"utf8")),Pn}catch{}return null}var Ol=ym()||{collections:[],globals:[]},Ul=um(Ol);pm(Ul.collections,Ol.collectionOverrides);var zl=Ul,Ho=zl.collections,jl=zl.globals,As=["users","audit_logs"];Object.values(Ho).filter(e=>!As.includes(e.slug)&&e.admin?.hidden!==true);function In({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.options||[];return e.dynamicOptions==="collections"&&(s=Object.keys(Ho).filter(i=>i!=="media").map(i=>({label:Ho[i]?.label||i,value:i}))),jsx(nt,{field:e,error:o,children:jsxs("select",{id:e.name,value:e.hasMany?Array.isArray(t)?t:[]:t||"",onChange:i=>{if(e.hasMany){let l=Array.from(i.target.selectedOptions,d=>d.value);r?.(l);}else r?.(i.target.value||void 0);},multiple:e.hasMany,disabled:a||n,required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`,children:[!e.required&&!e.hasMany&&jsx("option",{value:"",children:"Select..."}),s.map(i=>jsx("option",{value:i.value,children:i.label},i.value))]})})}function Ln({icon:e,title:t,description:r,action:o}){return jsxs("div",{className:"flex flex-col items-center gap-3 justify-center py-16 px-8",children:[e&&jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:e}),jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:t}),r&&jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:r}),o]})}function Hl(e){let t=e?.mainTabs;return e?.title||t?.title||e?.name||e?.label||e?.email||e?.filename||e?.slug||"Untitled"}function gm({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false),[i,l]=useState(""),[d,c]=useState([]),[m,u]=useState(false),[g,x]=useState([]),f=useRef(new Set),y=useRef(null),b=useRef(()=>{});b.current=r||(()=>{});let v=e.hasMany,R=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],L=R.length>1,[C,w]=useState(R[0]||""),N=useCallback(()=>t?(v?Array.isArray(t)?t:[]:t?[t]:[]).map(j=>typeof j=="object"&&j!==null?j.value||j.id||"":String(j)).filter(Boolean):[],[t,v]),p=useCallback(M=>{M.length!==0&&M.forEach(j=>{if(f.current.has(j))return;f.current.add(j);let se=L?(()=>{if(!t)return C;let ue=(v?Array.isArray(t)?t:[]:[t]).find(oe=>typeof oe=="object"&&oe!==null?oe.value===j||oe.id===j:false);return ue&&typeof ue=="object"&&ue.relationTo||C})():C;De(`/api/${se}/${j}`).then(ie=>{let ue=ie.data||ie;!ue||typeof ue!="object"||x(oe=>oe.some(ne=>ne.id===j)?oe:[...oe,{...ue,id:String(ue.id),relationTo:se}]);}).catch(()=>{});});},[L,t,C,v]);useEffect(()=>{let M=N();p(M);},[N,p]);let A=useCallback((M="")=>{u(true);let se=`/api/${C}?${Ja(M,["title","name","label","email"])}`;De(se).then(ie=>{c(ue=>{let oe=new Set(ue.map(je=>je.id)),ne=(ie.docs||[]).filter(je=>!oe.has(je.id)).map(je=>({...je,id:je.id}));return [...ue,...ne]}),u(false);}).catch(()=>{u(false);});},[C]);useEffect(()=>{n&&(c([]),A(i));},[n,C]),useEffect(()=>{let M=j=>{y.current&&!y.current.contains(j.target)&&s(false);};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]);let O=M=>typeof M=="object"&&M!==null?M.value||M.id||"":String(M),F=M=>{let j=M.id;return t?v&&Array.isArray(t)?t.some(se=>O(se)===j):O(t)===j:false},P=M=>{let j=M.id;if(v){let se=Array.isArray(t)?t:[];if(F(M))b.current?.(se.filter(ie=>O(ie)!==j));else {let ie=L?{relationTo:C,value:j}:j;b.current?.([...se,ie]);}}else if(F(M))b.current?.(null);else {let se=L?{relationTo:C,value:j}:j;b.current?.(se),s(false),l("");}},S=()=>{if(!t)return null;let M=v?Array.isArray(t)?t:[]:t?[t]:[];return jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:M.map(j=>{let se=O(j),ie=g.find(ne=>ne.id===se),ue=ie?Hl(ie):se.slice(0,12),oe=L&&ie?ie.relationTo:null;return jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-md bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]",children:[oe&&jsxs("span",{className:"opacity-60 mr-0.5",children:[oe,":"]}),ue,!a&&jsx("button",{type:"button",onClick:()=>{let ne=M.filter(je=>O(je)!==se);b.current?.(v?ne:ne[0]??null);},className:"hover:opacity-70",children:jsx(X,{className:"w-3 h-3"})})]},se)})})};return jsxs("div",{className:"space-y-1.5",children:[e.label&&jsxs("label",{className:"block text-sm font-medium text-[var(--kyro-text-primary)]",children:[e.label,e.required&&jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]}),jsxs("div",{ref:y,className:"relative",children:[L&&jsx("div",{className:"flex gap-1 mb-1.5",children:R.map(M=>jsx("button",{type:"button",onClick:()=>{w(M),c([]),l("");},className:`px-2 py-0.5 text-[10px] font-bold rounded transition-colors ${C===M?"kyro-btn-primary":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:M},M))}),jsxs("div",{className:"relative",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",value:i,onChange:M=>{l(M.target.value),s(true),A(M.target.value);},onFocus:()=>s(true),placeholder:e.admin?.placeholder||`Search ${C}...`,disabled:a||(typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly),className:"w-full pl-9 pr-10 py-2 border border-[var(--kyro-border)] rounded-md bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent disabled:opacity-50"}),jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:m?jsx(LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"}):jsx(ChevronDown,{className:`w-4 h-4 text-[var(--kyro-text-muted)] transition-transform ${n?"rotate-180":""}`})})]}),n&&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?jsx("div",{className:"p-4 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsx(Ln,{title:"No results found"}):jsx("div",{className:"py-1",children:d.map(M=>jsxs("button",{type:"button",onClick:()=>P(M),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors ${F(M)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:Hl(M)}),F(M)&&jsx("span",{className:"text-[var(--kyro-sidebar-active)]",children:"\u2713"})]}),"slug"in M&&typeof M.slug=="string"&&jsx("div",{className:"text-xs text-[var(--kyro-text-muted)]",children:M.slug})]},M.id))})}),S()]}),e.admin?.description&&!o&&jsx("p",{className:"text-xs text-[var(--kyro-text-muted)]",children:e.admin.description}),o&&jsx("p",{className:"text-xs text-[var(--kyro-error)]",children:o})]})}var Pa=gm;var vo=createContext(null);function Vl(e=[],t=[]){return createStore((r,o)=>({blocks:[],allowedBlocks:e,dynamicCategories:t,setBlocks:a=>{let n=Is(a||[]);r({blocks:n});},onBlocksChange:null,setOnBlocksChange:a=>r({onBlocksChange:a}),addBlock:(a,n)=>{let s=Vo(a),{blocks:i}=o(),l=[...i];n!==void 0?l.splice(n,0,s):l.push(s),r({blocks:l});let{onBlocksChange:d}=o();d&&d();},updateBlock:(a,n)=>{let{blocks:s}=o(),i=Da(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=[...l];return c[d]={...c[d],...n},{newList:c,found:true}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}},removeBlock:a=>{if(!a)return;let{blocks:n}=o(),s=Da(n,i=>{let l=i.filter(d=>d.id!==a);return l.length!==i.length?{newList:l,found:true}:{newList:i,found:false}});if(s!==n){r({blocks:s});let{onBlocksChange:i}=o();i&&i();}},moveBlock:(a,n)=>{let{blocks:s}=o(),i=Da(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=n==="up"?d-1:d+1;if(c>=0&&c<l.length){let m=[...l];return [m[d],m[c]]=[m[c],m[d]],{newList:m,found:true}}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}}}))}function Is(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=Is(r.children)),r.data?.columnData&&Array.isArray(r.data.columnData)&&(r.data={...r.data,columnData:r.data.columnData.map(o=>({...o,children:o.children?Is(o.children):o.children}))}),r}):[]}function Vo(e){let t=hm(e),{options:r,children:o,...a}=t;return {id:Math.random().toString(36).substr(2,9),type:e,name:"",data:a,options:r,children:o,order:Date.now()}}function hm(e){return {heading:{level:1,text:""},"heading-subheading":{heading:"",subheading:""},hero:{isMultiScreen:false},card:{title:"",description:"",icon:"",link:"",linkText:"",isMultiCard:false},paragraph:{text:""},divider:{},callout:{text:"",variant:"info"},image:{src:"",alt:"",caption:""},video:{src:"",title:""},list:{type:"unordered",items:""},code:{language:"plaintext",code:""},link:{url:"",text:""},table:{rows:3,columns:3,content:""},quote:{text:"",author:""},file:{filename:"",url:""},columns:{columns:2,direction:"horizontal"},vstack:{direction:"vertical",gap:"md"},container:{options:{backgroundColor:"transparent",padding:"md",width:"full",margin:"none",minHeight:"none",borderRadius:"none"},children:[]},button:{text:"Button",url:"",variant:"primary",size:"md"},accordion:{title:"Accordion Item",content:""},gallery:{images:[]},tabs:{tabs:[{label:"Tab 1",content:""}]}}[e]||{}}function Ee(e){let t=useContext(vo);if(t)return useStore(t,r=>{let o=a=>{for(let n of a){if(n.id===e)return n;if(n.children&&n.children.length>0){let s=o(n.children);if(s)return s}if(n.data?.columnData){for(let s of n.data.columnData)if(s&&s.children&&s.children.length>0){let i=o(s.children);if(i)return i}}}};return o(r.blocks)})}function Be(){let e=useContext(vo);if(!e)throw new Error("useBlockActions must be used within a BlocksContext.Provider");return {updateBlock:(t,r)=>e.getState().updateBlock(t,r),removeBlock:t=>e.getState().removeBlock(t),moveBlock:(t,r)=>e.getState().moveBlock(t,r)}}function Da(e,t){let{newList:r,found:o}=t(e);if(o)return r;let a=false,n=e.map(s=>{let i={...s},l=false;if(s.children&&s.children.length>0){let d=Da(s.children,t);d!==s.children&&(i.children=d,l=true);}if(s.data?.columnData&&Array.isArray(s.data.columnData)){let d=s.data.columnData.map(c=>{if(c.children&&c.children.length>0){let m=Da(c.children,t);if(m!==c.children)return {...c,children:m}}return c});d.some((c,m)=>c!==s.data.columnData[m])&&(i.data={...i.data,columnData:d},l=true);}return l&&(a=true),l?i:s});return a?n:e}function Ia({open:e,onClose:t,onSelect:r,children:o}){return e?jsxs(dr,{open:e,onClose:t,title:"Insert Block",width:"md",children:[jsx("p",{className:"text-sm text-[var(--kyro-text-muted)] mb-4",children:"Drag blocks into the editor or click to insert"}),o]}):null}function Kl({block:e,onSelect:t,children:r}){let{attributes:o,listeners:a,setNodeRef:n,isDragging:s}=useDraggable({id:`drawer-${e.type}`,data:{source:"drawer",blockType:e.type}});return 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:[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||jsx("span",{className:"text-[var(--kyro-text-muted)]"})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)] leading-tight",children:e.label}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 leading-tight",children:e.description})]})]})}var Ms=({text:e="",onChange:t,compact:r=false})=>jsx("div",{className:r?"":"space-y-3",children:jsx("input",{type:"text",value:e,onChange:a=>t("text",a.target.value),className:r?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Enter heading text..."})});var go=({id:e,type:t,label:r,children:o,className:a=""})=>{let{moveBlock:n,removeBlock:s}=Be();return 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:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] tracking-wider",children:r||t}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[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:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),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:jsx(ChevronRight,{className:"w-3 h-3"})}),jsx("button",{type:"button",onClick:()=>s(e),className:"p-1 hover:bg-[var(--kyro-error)]/10 rounded text-[var(--kyro-error)]",title:"Remove",children:jsx(X,{className:"w-3 h-3"})})]})]}),jsx("div",{className:"block-content",children:o})]})};var ql=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o}=Be(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsx(go,{id:e.id,type:"heading",label:"Heading",children:jsx(Ms,{text:a.text||"",onChange:n,compact:true})})};var Xl=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o}=Be(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsx(go,{id:e.id,type:"paragraph",label:"Paragraph",children:jsx("textarea",{value:a.text||"",onChange:s=>n("text",s.target.value),className:"w-full px-3 py-3 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm min-h-[100px] resize-none",placeholder:"Enter paragraph text..."})})};var Ql=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data||e.data||{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-image border border-[var(--kyro-border)] rounded-lg p-4 mb-4 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Image"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Remove",children:jsx(X,{className:"w-3 h-3"})})]})]}),jsxs("div",{className:"space-y-3",children:[jsxs("div",{children:[jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Image Asset"}),jsx(lr,{field:{label:"Image Asset",name:"src",maxCount:1},value:s.src,onChange:l=>i("src",l)})]}),jsxs("div",{children:[jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Alt Text"}),jsx("input",{type:"text",value:s.alt||"",onChange:l=>i("alt",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Alternative text..."})]}),jsxs("div",{children:[jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Caption"}),jsx("input",{type:"text",value:s.caption||"",onChange:l=>i("caption",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Image caption..."})]})]})]})};var Es=({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?jsxs("div",{className:"space-y-2",children:[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..."}),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)..."})]}):jsxs("div",{className:"space-y-3",children:[jsx(lr,{field:{label:"Video Asset",name:"src",maxCount:1},value:e,onChange:o||(s=>r("src",s))}),jsx("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:"or paste a URL"}),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..."}),jsx("input",{type:"text",value:t,onChange:s=>r("title",s.target.value),className:"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"Video title (optional)..."})]})};var Zl=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-video border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Video"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(Es,{src:s.src||"",title:s.title||"",onChange:i,onUploadChange:l=>i("src",l),compact:true})]})};var La=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=ka.useState(""),n=()=>{o.trim()&&(t([...e,o.trim()]),a(""));},s=d=>{d.key==="Enter"&&(d.preventDefault(),n());},i=d=>{t(e.filter((c,m)=>m!==d));},l=r?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded-md bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxs("div",{className:r?"space-y-1.5":"space-y-2",children:[e.length===0?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."}):jsx("div",{className:"space-y-1",children:e.map((d,c)=>jsxs("div",{className:"flex items-center gap-2 group/item",children:[jsxs("span",{className:"text-sm text-[var(--kyro-text-primary)] flex-1",children:["\u2022 ",d]}),jsx("button",{type:"button",onClick:()=>i(c),className:"opacity-0 group-hover/item:opacity-100 p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",children:"\xD7"})]},c))}),jsx("input",{type:"text",value:o,onChange:d=>a(d.target.value),onKeyDown:s,className:l,placeholder:"Type and press Enter to add..."})]})};var ed=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data||e.data||{},i=Array.isArray(s.items)?s.items:[];return jsxs("div",{className:"block-list border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"List"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(La,{items:i,onChange:d=>{o(e.id,{data:{...s,items:d}});},compact:true})]})};var td=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return 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:[jsxs("div",{className:"flex items-center justify-between mb-6",children:[jsxs("div",{className:"flex items-center gap-3",children:[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:jsx(CodeXml,{className:"w-5 h-5"})}),jsxs("div",{children:[jsx("h4",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Code Snippet"}),jsxs("p",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] tracking-widest",children:["Block Editor \u2022 ",s.language||"javascript"]})]})]}),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:jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)]/50 p-1 rounded-xl border border-[var(--kyro-border)]",children:[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:jsx(ChevronRight,{className:"w-4 h-4 rotate-[-90deg]"})}),jsx("div",{className:"w-px h-4 bg-[var(--kyro-border)] mx-1 self-center"}),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:jsx(X,{className:"w-4 h-4"})})]})})]}),jsxs("div",{className:"space-y-6",children:[jsx(Aa,{field:{type:"code",name:"code",label:"Source Code",language:s.language||"javascript"},value:s.code||"",onChange:l=>i("code",l)}),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:[jsxs("div",{className:"flex-1",children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2 block",children:"Syntax Highlighting"}),jsxs("div",{className:"relative",children:[jsxs("select",{value:s.language||"javascript",onChange:l=>i("language",l.target.value),className:"w-full pl-4 pr-10 py-2.5 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl text-xs font-medium text-[var(--kyro-text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)]/20 focus:border-[var(--kyro-primary)] transition-all appearance-none cursor-pointer",children:[jsx("option",{value:"plaintext",children:"Plain Text"}),jsx("option",{value:"javascript",children:"JavaScript"}),jsx("option",{value:"typescript",children:"TypeScript"}),jsx("option",{value:"python",children:"Python"}),jsx("option",{value:"json",children:"JSON"}),jsx("option",{value:"html",children:"HTML"}),jsx("option",{value:"css",children:"CSS"}),jsx("option",{value:"sql",children:"SQL"}),jsx("option",{value:"rust",children:"Rust"}),jsx("option",{value:"markdown",children:"Markdown"})]}),jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--kyro-text-muted)]",children:jsx(ChevronRight,{className:"w-4 h-4 rotate-90"})})]})]}),jsx("div",{className:"hidden sm:block w-px h-10 bg-[var(--kyro-border)]"}),jsxs("div",{className:"hidden sm:flex flex-col justify-center",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2",children:"Status"}),jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl",children:[jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500 animate-pulse"}),jsx("span",{className:"text-[10px] font-medium text-[var(--kyro-text-primary)] tracking-wide",children:"EDITING"})]})]})]})]})]})};var rd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-file border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"File"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(lr,{field:{label:"File",name:"file",maxCount:1},value:s.file,onChange:l=>i("file",l)})]})};var Hs=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=ka.useState(0),n=(m,u)=>{let g=[...e];g[m]={...g[m],title:u},t(g);},s=(m,u)=>{let g=[...e];g[m]={...g[m],content:u},t(g);},i=m=>{let u=e.filter((g,x)=>x!==m);t(u),o===m?a(null):o!==null&&o>m&&a(o-1);},l=()=>{t([...e,{title:`Item ${e.length+1}`,content:""}]),a(e.length);},d="w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",c="w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return r?jsxs("div",{className:"space-y-2",children:[e.length===0?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.'}):jsx("div",{className:"space-y-1.5",children:e.map((m,u)=>{let g=o===u;return jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxs("button",{type:"button",onClick:()=>a(g?null:u),className:"w-full flex items-center justify-between p-2.5 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors",children:[jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${u+1}`}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),i(u);},className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",title:"Remove",children:jsx(X,{className:"w-3.5 h-3.5"})}),g?jsx(ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsx(ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),g&&jsxs("div",{className:"p-2.5 bg-[var(--kyro-surface)] space-y-2",children:[jsx("input",{type:"text",value:m.title||"",onChange:x=>n(u,x.target.value),onClick:x=>x.stopPropagation(),className:c,placeholder:"Item title..."}),jsx("textarea",{value:m.content||"",onChange:x=>s(u,x.target.value),onClick:x=>x.stopPropagation(),className:`${c} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},u)})}),jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsx(Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]}):jsxs("div",{className:"space-y-2",children:[e.length===0?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.'}):jsx("div",{className:"space-y-2",children:e.map((m,u)=>{let g=o===u;return jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxs("button",{type:"button",onClick:()=>a(g?null:u),className:"w-full flex items-center justify-between p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors",children:[jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${u+1}`}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),i(u);},className:"opacity-0 group-hover:opacity-100 p-1.5 hover:bg-[var(--kyro-danger-bg)] rounded text-[var(--kyro-error)] transition-opacity",title:"Remove",children:jsx(X,{className:"w-4 h-4"})}),g?jsx(ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsx(ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),g&&jsxs("div",{className:"p-3 bg-[var(--kyro-surface)] space-y-2",children:[jsx("input",{type:"text",value:m.title||"",onChange:x=>n(u,x.target.value),className:d,placeholder:"Item title..."}),jsx("textarea",{value:m.content||"",onChange:x=>s(u,x.target.value),className:`${d} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},u)})}),jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsx(Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]})};var od=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=Array.isArray(s.items)?s.items:[],l=d=>{o(e.id,{data:{...s,items:d}});};return jsxs("div",{className:"block-accordion border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Accordion"}),jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(Hs,{items:i,onChange:l,compact:true})]})};var ad=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data||e.data||{},i=l=>{o(e.id,{data:{...s,content:l}});};return jsxs("div",{className:"block-richtext border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx(AlignLeft,{className:"w-3.5 h-3.5 text-[var(--kyro-primary)]"}),jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Rich Text"})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx($o,{field:{name:"content",label:"Content",type:"richtext"},value:s.content,onChange:i})]})};var _s=({heading:e="",subheading:t="",ctaText:r="",ctaUrl:o="",onChange:a,compact:n=false})=>{let s=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",i=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return n?jsxs("div",{className:"space-y-2",children:[jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]}):jsxs("div",{className:"space-y-3",children:[jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]})};function On({field:e,value:t,onChange:r,renderField:o}){let a=t||{};return 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:[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}),jsx("div",{className:e.admin?.inline?"flex items-start gap-4":"space-y-6",children:e.fields.map(n=>o(n,a,r))})]})}var Am=new Set(["text","textarea","number","checkbox","select","radio","color","email","password","code","markdown","upload"]);function Rm(e){let t=e.fields||[];return t.length===0||t.length>4?false:t.every(r=>Am.has(r.type))}function Un({field:e,value:t,onChange:r,renderField:o,disabled:a}){let n=Array.isArray(t)?t:[],s=e.fields||[],i=s[0],l=i?.name||"user",d=i?.type==="relationship",[c,m]=ka.useState(0);function u(x){for(let f of ["label","title","name"]){let y=x[f];if(y&&typeof y=="string")return y}for(let f of s){if(f.type==="text"||f.type==="textarea"){let y=x[f.name];if(y&&typeof y=="string")return y}if(f.type==="group"&&f.fields){for(let y of f.fields)if(y.type==="text"||y.type==="textarea"){let v=x[f.name]?.[y.name];if(v&&typeof v=="string")return v}}}return ""}let g=Rm(e);return jsxs("div",{className:"kyro-form-field",children:[jsx("label",{className:"kyro-form-label",children:e.label||e.name}),d?jsx(Pa,{field:{name:l,relationTo:e.fields?.[0]?.relationTo||"",hasMany:true,label:e.fields?.[0]?.label},value:n.map(x=>x[l]).filter(Boolean),onChange:x=>{let f=(x||[]).map(y=>({[l]:y}));r(f);},disabled:a}):g?jsxs("div",{className:"kyro-form-array kyro-form-array--compact border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30 rounded-md overflow-hidden",children:[n.map((x,f)=>jsxs("div",{className:"flex items-start gap-2 px-3 py-1.5 border-b border-[var(--kyro-border)] last:border-b-0 hover:bg-[var(--kyro-sidebar-active)]/5 transition-colors",children:[jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] pt-2 min-w-[18px] text-center",children:f+1}),jsx("div",{className:"flex-1 flex items-start gap-1.5 min-w-0",children:e.fields.map(y=>jsx("div",{className:"flex-1 min-w-0",children:o(y,x,b=>{let v=[...n];v[f]=b,r(v);})},y.name))}),jsx("button",{type:"button",disabled:a,onClick:()=>r(n.filter((y,b)=>b!==f)),className:"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-error)] transition-colors disabled:opacity-30 p-0.5 mt-1.5 flex-shrink-0",title:"Remove",children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},f)),jsx("button",{type:"button",className:"w-full py-2 border-2 border-dashed border-[var(--kyro-border)] rounded-none text-xs font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:border-[var(--kyro-primary)] transition-all disabled:opacity-50",disabled:a,onClick:()=>r([...n,{}]),children:"+ Add Item"})]}):jsxs("div",{className:"kyro-form-array border border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30 rounded-md p-3 space-y-4",children:[n.map((x,f)=>{let y=c===f;return jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxs("div",{role:"button",tabIndex:0,onClick:()=>m(y?null:f),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),m(y?null:f));},className:"w-full flex items-center justify-between p-3 bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-sidebar-active)]/10 transition-colors cursor-pointer",children:[jsx("span",{className:"text-xs font-bold tracking-widest text-[var(--kyro-text-muted)] truncate",children:u(x)||`Item ${f+1}`}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",disabled:a,onClick:b=>{b.stopPropagation(),r(n.filter((v,R)=>R!==f));},className:"text-[11px] font-bold text-[var(--kyro-error)] opacity-0 group-hover:opacity-100 transition-opacity disabled:opacity-30 hover:bg-[var(--kyro-danger-bg)] rounded px-1.5 py-0.5",children:"Remove"}),y?jsx(ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsx(ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),y&&jsx("div",{className:"p-4 bg-[var(--kyro-surface)] space-y-4",children:e.fields.map(b=>o(b,x,v=>{let R=[...n];R[f]=v,r(R);}))})]},f)}),jsx("button",{type:"button",className:"w-full py-3 border-2 border-dashed border-[var(--kyro-border)] rounded-lg text-xs font-bold text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:border-[var(--kyro-primary)] transition-all disabled:opacity-50",disabled:a,onClick:()=>r([...n,{}]),children:"+ Add Item"})]})]})}var sd="other";function id(){return sd}function zn(e){sd=e;}var xo=({field:e,value:t,onChange:r,error:o,disabled:a})=>{if(e.hidden===true||e.admin?.hidden===true)return null;let n=s=>{zn("keystroke"),r(s);};switch(e.type){case "text":case "email":case "url":return jsx(jo,{field:e,value:t,onChange:n,error:o,disabled:a});case "textarea":return jsx(jo,{field:{...e,variant:"textarea"},value:t,onChange:n,error:o,disabled:a});case "password":return jsx(jo,{field:{...e,variant:"password"},value:t,onChange:n,error:o,disabled:a});case "secret":return jsx(Cn,{field:e,value:t,onChange:r,error:o,disabled:a});case "number":return jsx(An,{field:e,value:t,onChange:r,disabled:a,error:o});case "checkbox":return jsx(Rn,{field:e,value:t,onChange:r,disabled:a,error:o});case "select":return jsx(In,{field:e,value:t,onChange:r,disabled:a,error:o});case "date":return jsx(Fn,{field:e,value:t,onChange:r,disabled:a,error:o});case "richtext":return jsx($o,{field:e,value:t,onChange:n,disabled:a,error:o});case "markdown":return jsx(Ns,{field:e,value:t,onChange:n,disabled:a,error:o});case "code":return jsx(Aa,{field:e,value:t,onChange:n,disabled:a,error:o});case "image":case "upload":return jsx(nt,{field:e,error:o,children:jsx(lr,{field:e,value:t,onChange:r,disabled:a})});case "relationship":return jsx(Pa,{field:e,value:t,onChange:r,disabled:a,error:o});case "list":return jsx(nt,{field:e,error:o,children:jsx(La,{items:Array.isArray(t)?t:[],onChange:r,compact:true})});case "array":return jsx(Un,{field:e,value:Array.isArray(t)?t:[],onChange:r,disabled:a,renderField:(s,i,l)=>{let d=i[s.name];return jsx(xo,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "blocks":return jsx(Vs,{field:e,value:t,onChange:n,disabled:a,error:o});case "group":return jsx(On,{field:e,value:t,onChange:r,renderField:(s,i,l)=>{let d=i[s.name];return jsx(xo,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "color":return jsx(nt,{field:e,error:o,children:jsxs("div",{className:"flex items-center gap-3",children:[jsx("input",{type:"color",value:t||"#000000",onChange:s=>r(s.target.value),disabled:a,className:"h-10 w-14 p-1 cursor-pointer bg-[var(--kyro-input-bg)] border border-[var(--kyro-input-border)] rounded-lg"}),jsx("input",{type:"text",className:"kyro-form-input font-mono ",value:t||"",onChange:s=>r(s.target.value),disabled:a,placeholder:"#000000"})]})});default:return jsxs("div",{className:"p-4 bg-amber-50 border border-amber-200 rounded-lg text-amber-800 text-xs italic",children:['Field type "',e.type,'" is not yet supported in this renderer.']})}};var Wo=({block:e,blockSchema:t,onClose:r})=>{let o=Ee(e.id),{updateBlock:a}=Be(),n=o?.data||e.data||{},s=o?.children||e.children||[],i=(m,u)=>{a(e.id,{data:{...n,[m]:u}});},l=m=>{a(e.id,{children:m});},d=()=>t&&Array.isArray(t.fields)?jsx("div",{className:"space-y-4 pt-2",children:t.fields.map(m=>{if(m.admin?.condition){if(typeof m.admin.condition=="function")try{let g={values:n,...n};if(!m.admin.condition(g,g))return null}catch(g){console.warn(`Condition error for field ${m.name}:`,g);}else if(typeof m.admin.condition=="object")try{let g=m.admin.condition,x=g.field,f=n[x],y=!0;if("equals"in g?y=f===g.equals:"notEquals"in g?y=f!==g.notEquals:"in"in g&&Array.isArray(g.in)&&(y=g.in.includes(f)),!y)return null}catch(g){console.warn(`Declarative condition error for field ${m.name}:`,g);}}let u=n[m.name];return jsx("div",{className:"kyro-block-field-row border-b border-[var(--kyro-border)]/30 pb-3 last:border-b-0 last:pb-0",children:jsx(xo,{field:m,value:u,onChange:g=>i(m.name,g)})},m.name)})}):jsxs("div",{className:"text-center py-8 text-[var(--kyro-text-muted)] text-sm italic",children:['No schema defined for block type "',e.type,'"']}),c=Fe[e.type]||Fe.default;return jsxs(dr,{open:true,onClose:r,title:`Edit ${t?.label||e.type}`,width:"xl",showOverlay:false,accentClass:c.border,children:[jsxs("div",{className:"space-y-4",children:[d(),s.length>0&&jsxs("div",{className:"pt-4 border-t border-[var(--kyro-border)]",children:[jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",s.length,")"]}),jsx(Jr,{blockId:e.id,children:s,onUpdateChildren:l})]})]}),jsx("div",{className:"mt-6 pt-4 border-t border-[var(--kyro-border)]",children:jsx("button",{type:"button",onClick:r,className:"w-full py-2.5 bg-[var(--kyro-sidebar-active)] text-[var(--kyro-sidebar-text-active)] rounded-lg font-medium hover:opacity-90 transition-opacity",children:"Done"})})]})};var Fm=6,Jr=({blockId:e,children:t,onUpdateChildren:r,depth:o=0,maxDepth:a=Fm})=>{let[n,s]=useState(false),[i,l]=useState(new Set),[d,c]=useState(null),[m,u]=useState(null),g=useContext(vo);if(!g)throw new Error("ChildBlocksTree must be used within a BlocksContext");let x=useStore(g,p=>p.dynamicCategories),f=useStore(g,p=>p.allowedBlocks),y=o<a,b=16,v=p=>{let A=Vo(p);r([...t,A]),c(A.id);},R=p=>{let A=t.filter(O=>O.id!==p);r(A);},C=(p,A)=>{let O=t.map(F=>F.id===p?{...F,children:A}:F);r(O);},w=p=>{l(A=>{let O=new Set(A);return O.has(p)?O.delete(p):O.add(p),O});},N=p=>{let A=p.children&&p.children.length>0,O=i.has(p.id);Ks(p.type);let P=A,S=d===p.id,M=f.find(j=>j.slug===p.type);return jsxs("div",{className:"relative group",children:[jsxs("div",{className:`flex items-center group/column gap-2 p-2 bg-[var(--kyro-bg-secondary)] rounded border transition-colors ${S?"bg-[var(--kyro-primary)]/10 border-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"} ${y?"cursor-pointer":""}`,style:{marginLeft:o*b},onClick:()=>{y&&c(S?null:p.id);},children:[P?jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:O?jsx(ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsx(ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsx("span",{className:"w-4"}),jt[p.type]&&jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:jt[p.type]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ea(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),M?.admin?.description&&jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:M.admin.description})]}),A&&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?jsxs("div",{className:"flex items-center gap-1",onClick:j=>j.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{R(p.id),u(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsx("button",{type:"button",onClick:()=>u(null),className:"px-2 py-1 text-xs bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] rounded hover:bg-[var(--kyro-border)]",children:"Cancel"})]}):jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),u(p.id);},className:"p-1.5 rounded-md transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsx(X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)] invisible group-hover/column:visible"})})]}),S&&jsx(Wo,{block:p,onClose:()=>c(null)}),A&&O&&jsx("div",{className:"mt-1",children:jsx(cd,{parentId:p.id,children:p.children,onUpdateChildren:j=>C(p.id,j),depth:o+1,maxDepth:a})})]},p.id)};return jsxs("div",{className:"space-y-2",children:[t.length>0&&jsx("div",{className:"space-y-1",children:t.map(N)}),y&&jsxs("div",{style:{marginLeft:o*b},children:[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:[jsx(Plus,{className:"w-3 h-3"}),"Add Block"]}),jsx(Ia,{open:n,onClose:()=>s(false),onSelect:v,children:x.map(p=>jsxs("div",{className:"mb-4",children:[jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(A=>jsxs("button",{type:"button",onClick:()=>{v(A.slug),s(false);},className:"flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group",children:[jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:jt[A.slug]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:A.label}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:A.admin?.description||""})]})]},A.slug))})]},p.title))})]}),t.length===0&&y&&jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*b},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*b},children:["Maximum nesting level (",a,") reached"]})]})},cd=({parentId:e,children:t,onUpdateChildren:r,depth:o,maxDepth:a})=>{let[n,s]=useState(false),[i,l]=useState(new Set),[d,c]=useState(null),[m,u]=useState(null),g=useContext(vo);if(!g)throw new Error("NestedChildBlocks must be used within a BlocksContext");let x=useStore(g,p=>p.dynamicCategories),f=useStore(g,p=>p.allowedBlocks),y=o<a,b=16,v=p=>{let A=Vo(p);r([...t,A]),c(A.id);},R=p=>{let A=t.filter(O=>O.id!==p);r(A);},C=(p,A)=>{let O=t.map(F=>F.id===p?{...F,children:A}:F);r(O);},w=p=>{l(A=>{let O=new Set(A);return O.has(p)?O.delete(p):O.add(p),O});},N=p=>{let A=p.children&&p.children.length>0,O=i.has(p.id);Ks(p.type);let P=A,S=d===p.id,M=f.find(j=>j.slug===p.type);return jsxs("div",{className:"relative group",children:[jsxs("div",{className:`flex items-center gap-2 p-2 bg-[var(--kyro-bg-secondary)] rounded border transition-colors ${S?"bg-[var(--kyro-primary)]/10 border-[var(--kyro-primary)]":"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"} ${y?"cursor-pointer":""}`,style:{marginLeft:o*b},onClick:()=>{y&&c(S?null:p.id);},children:[P?jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),w(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:O?jsx(ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsx(ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsx("span",{className:"w-4"}),jt[p.type]&&jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:jt[p.type]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ea(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),M?.admin?.description&&jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:M.admin.description})]}),A&&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?jsxs("div",{className:"flex items-center gap-1",onClick:j=>j.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{R(p.id),u(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsx("button",{type:"button",onClick:()=>u(null),className:"px-2 py-1 text-xs bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] rounded hover:bg-[var(--kyro-border)]",children:"Cancel"})]}):jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),u(p.id);},className:"p-1.5 rounded-md invisible group-hover:visible transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsx(X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)]"})})]}),S&&jsx(Wo,{block:p,onClose:()=>c(null)}),A&&O&&jsx("div",{className:"mt-1",children:jsx(cd,{parentId:p.id,children:p.children,onUpdateChildren:j=>C(p.id,j),depth:o+1,maxDepth:a})})]},p.id)};return jsxs("div",{className:"space-y-2",children:[t.length>0&&jsx("div",{className:"space-y-1",children:t.map(N)}),y&&jsxs("div",{style:{marginLeft:o*b},children:[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:[jsx(Plus,{className:"w-3 h-3"}),"Add Block"]}),jsx(Ia,{open:n,onClose:()=>s(false),onSelect:v,children:x.map(p=>jsxs("div",{className:"mb-4",children:[jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(A=>jsxs("button",{type:"button",onClick:()=>{v(A.slug),s(false);},className:"flex flex-col items-center text-center gap-1 p-2 rounded-md border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/60 hover:bg-[var(--kyro-surface-accent)]/30 transition-all cursor-pointer group",children:[jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:jt[A.slug]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:A.label}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:A.admin?.description||""})]})]},A.slug))})]},p.title))})]}),t.length===0&&y&&jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*b},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*b},children:["Maximum nesting level (",a,") reached"]})]})};var pd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=r?.children??e.children??[],l=(d,c)=>{o(e.id,{data:{...s,[d]:c}});};return jsxs("div",{className:"block-hero border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("div",{className:"flex items-center gap-2",children:jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Hero Section"})}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsxs("div",{className:"space-y-3",children:[jsx(_s,{heading:s.heading||"",subheading:s.subheading||"",ctaText:s.ctaText||"",ctaUrl:s.ctaUrl||"",onChange:l,compact:true}),jsx(lr,{field:{label:"Background",name:"bgImage",maxCount:1},value:s.bgImage,onChange:d=>l("bgImage",d)}),jsxs("div",{className:"pt-3 border-t border-[var(--kyro-border)]",children:[jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",i.length,")"]}),jsx(Jr,{blockId:e.id,children:i,onUpdateChildren:d=>o(e.id,{children:d})})]})]})]})};var Gs=({title:e="",description:t="",icon:r="",link:o="",linkText:a="",onChange:n,compact:s=false})=>{let i=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",l=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxs("div",{className:s?"space-y-2":"space-y-3",children:[jsx("input",{type:"text",value:e,onChange:d=>n("title",d.target.value),className:`${i} font-bold text-base`,placeholder:"Card title..."}),jsx("textarea",{value:t,onChange:d=>n("description",d.target.value),className:l,placeholder:"Card description..."}),jsx("input",{type:"text",value:r,onChange:d=>n("icon",d.target.value),className:i,placeholder:"Icon (emoji or name)..."}),jsxs("div",{className:"flex items-center gap-2",children:[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..."}),jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsx("input",{type:"url",value:o,onChange:d=>n("link",d.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]})};var yd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o}=Be(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsx(go,{id:e.id,type:"card",label:"Card",children:jsx(Gs,{title:a.title||"",description:a.description||"",icon:a.icon||"",link:a.link||"",linkText:a.linkText||"",onChange:n,compact:true})})};var fd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be();r?.data??e.data??{};let i=r?.children??e.children??[];return jsxs("div",{className:"block-array border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Repeater"}),jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx("div",{className:"space-y-3",children:jsx(Jr,{blockId:e.id,children:i,onUpdateChildren:l=>o(e.id,{children:l})})})]})};var Ua=({relationTo:e="pages",hasMany:t=false,selectedIds:r=[],selectedId:o,labelField:a="title",onChange:n,compact:s=false})=>{let[i,l]=useState(false),[d,c]=useState(""),[m,u]=useState([]),[g,x]=useState(false),[f,y]=useState([]),[b,v]=useState(true);useEffect(()=>{De("/api/collections").then(F=>{y((F.collections||[]).map(P=>P.slug||P.name||P)),v(false);}).catch(()=>v(false));},[]);let R=(F="")=>{x(true);let P=`/api/${e}?${Ja(F,[a],20)}`;De(P).then(S=>{u(S.docs||[]),x(false);}).catch(()=>x(false));};useEffect(()=>{i&&R(d);},[i,d,e,a]);let L=F=>F?.[a]||F?.title||F?.name||F?.label||F?.filename||F?.slug||F?.id||"Untitled",C=t?r:o?[o]:[],w=F=>{t?C.includes(F.id)?n("selectedIds",C.filter(P=>P!==F.id)):n("selectedIds",[...C,F.id]):(n("selectedId",F.id),n("selectedIds",[F.id]),l(false));},N=F=>C.includes(F),p=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",A=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",O=e&&typeof e=="string"&&e.length>0;return jsxs("div",{className:s?"space-y-2":"space-y-4",children:[jsxs("div",{className:s?"flex items-center gap-2":"space-y-3",children:[!O&&jsx(Fragment,{children:b?jsx("div",{className:A+" text-[var(--kyro-text-muted)]",children:"Loading..."}):jsxs("select",{value:e,onChange:F=>n("relationTo",F.target.value),className:A,children:[jsx("option",{value:"",children:"Select collection..."}),f.map(F=>jsx("option",{value:F,children:F},F))]})}),!s&&jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[jsx("input",{type:"checkbox",checked:t,onChange:F=>n("hasMany",F.target.checked),className:"w-4 h-4 rounded border-[var(--kyro-border)] focus:ring-[var(--kyro-sidebar-active)] focus:ring-offset-0"}),jsx("span",{className:"text-sm text-[var(--kyro-text-primary)]",children:"Allow multiple"})]})]}),jsxs("div",{className:"relative",children:[jsxs("div",{className:"relative",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",value:d,onChange:F=>{c(F.target.value),l(true);},onFocus:()=>l(true),onBlur:()=>setTimeout(()=>l(false),200),placeholder:`Search ${e}...`,className:`${p} pl-9`}),jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:g&&jsx(LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"})})]}),i&&jsx("div",{className:"absolute z-20 w-full mt-1 border border-[var(--kyro-border)] rounded-lg shadow-lg bg-[var(--kyro-surface)] max-h-48 overflow-auto",children:g?jsx("div",{className:"p-3 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):m.length===0?jsx(Ln,{title:"No results found"}):jsx("div",{className:"py-1",children:m.map(F=>jsxs("button",{type:"button",onMouseDown:P=>P.preventDefault(),onClick:()=>w(F),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors flex items-center justify-between ${N(F.id)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsx("span",{children:L(F)}),N(F.id)&&jsx("span",{children:"\u2713"})]},F.id))})})]}),C.length>0&&jsx("div",{className:"flex flex-wrap gap-1.5",children:C.map(F=>{let P=m.find(S=>S.id===F)||{id:F};return jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-md bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]",children:[L(P),jsx("button",{type:"button",onMouseDown:S=>S.preventDefault(),onClick:()=>{t?n("selectedIds",C.filter(S=>S!==F)):(n("selectedId",null),n("selectedIds",[]));},className:"hover:opacity-70",children:jsx(X,{className:"w-3 h-3"})})]},F)})})]})};var gd=({block:e,index:t})=>{let r=Ee(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Be(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-relationship border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Relationship"}),jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["\u2192 ",s.relationTo||"pages"]})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(Ua,{relationTo:s.relationTo||"pages",hasMany:s.hasMany||false,selectedIds:Array.isArray(s.selectedIds)?s.selectedIds:[],selectedId:s.selectedId,labelField:s.labelField||"title",onChange:i,compact:true})]})};var Dm={heading:ql,paragraph:Xl,image:Ql,video:Zl,list:ed,code:td,file:rd,accordion:od,richtext:ad,hero:pd,card:yd,array:fd,relationship:gd},Fe={featureSplit:{text:"text-indigo-500",border:"border-indigo-500",borderLeft:"border-l-indigo-500"},featureGrid:{text:"text-blue-500",border:"border-blue-500",borderLeft:"border-l-blue-500"},ctaBanner:{text:"text-amber-500",border:"border-amber-500",borderLeft:"border-l-amber-500"},testimonials:{text:"text-emerald-500",border:"border-emerald-500",borderLeft:"border-l-emerald-500"},faq:{text:"text-orange-500",border:"border-orange-500",borderLeft:"border-l-orange-500"},stats:{text:"text-rose-500",border:"border-rose-500",borderLeft:"border-l-rose-500"},logoCloud:{text:"text-cyan-500",border:"border-cyan-500",borderLeft:"border-l-cyan-500"},pricing:{text:"text-green-500",border:"border-green-500",borderLeft:"border-l-green-500"},team:{text:"text-violet-500",border:"border-violet-500",borderLeft:"border-l-violet-500"},recentFeed:{text:"text-sky-500",border:"border-sky-500",borderLeft:"border-l-sky-500"},processSteps:{text:"text-fuchsia-500",border:"border-fuchsia-500",borderLeft:"border-l-fuchsia-500"},formEmbed:{text:"text-pink-500",border:"border-pink-500",borderLeft:"border-l-pink-500"},videoShowcase:{text:"text-red-500",border:"border-red-500",borderLeft:"border-l-red-500"},hero:{text:"text-yellow-500",border:"border-yellow-500",borderLeft:"border-l-yellow-500"},card:{text:"text-teal-500",border:"border-teal-500",borderLeft:"border-l-teal-500"},default:{text:"text-zinc-400",border:"border-zinc-400",borderLeft:"border-l-zinc-400"}},jt={heading:jsx(Heading1,{className:`w-4 h-4 ${Fe.default.text}`}),paragraph:jsx(AlignLeft,{className:`w-4 h-4 ${Fe.default.text}`}),image:jsx(Image,{className:`w-4 h-4 ${Fe.default.text}`}),video:jsx(Video,{className:`w-4 h-4 ${Fe.default.text}`}),list:jsx(List,{className:`w-4 h-4 ${Fe.default.text}`}),code:jsx(Code,{className:`w-4 h-4 ${Fe.default.text}`}),file:jsx(File,{className:`w-4 h-4 ${Fe.default.text}`}),accordion:jsx(ChevronDown,{className:`w-4 h-4 ${Fe.default.text}`}),richtext:jsx(AlignLeft,{className:`w-4 h-4 ${Fe.default.text}`}),hero:jsx(Star,{className:`w-4 h-4 ${Fe.hero.text}`}),card:jsx(Box,{className:`w-4 h-4 ${Fe.card.text}`}),array:jsx(ListOrdered,{className:`w-4 h-4 ${Fe.default.text}`}),relationship:jsx(Link2,{className:`w-4 h-4 ${Fe.default.text}`}),featureSplit:jsx(Columns3,{className:`w-4 h-4 ${Fe.featureSplit.text}`}),featureGrid:jsx(Blocks,{className:`w-4 h-4 ${Fe.featureGrid.text}`}),ctaBanner:jsx(Sparkles,{className:`w-4 h-4 ${Fe.ctaBanner.text}`}),testimonials:jsx(Users,{className:`w-4 h-4 ${Fe.testimonials.text}`}),faq:jsx(CircleHelp,{className:`w-4 h-4 ${Fe.faq.text}`}),stats:jsx(Activity,{className:`w-4 h-4 ${Fe.stats.text}`}),logoCloud:jsx(Image,{className:`w-4 h-4 ${Fe.logoCloud.text}`}),pricing:jsx(Tag,{className:`w-4 h-4 ${Fe.pricing.text}`}),team:jsx(Users,{className:`w-4 h-4 ${Fe.team.text}`}),recentFeed:jsx(Database,{className:`w-4 h-4 ${Fe.recentFeed.text}`}),processSteps:jsx(Clock,{className:`w-4 h-4 ${Fe.processSteps.text}`}),formEmbed:jsx(Mail,{className:`w-4 h-4 ${Fe.formEmbed.text}`}),videoShowcase:jsx(Video,{className:`w-4 h-4 ${Fe.videoShowcase.text}`})};function Ks(e){return Dm[e]||null}function Ws(e){return {paragraph:"Paragraph",heading:"Heading",image:"Image",video:"Video",list:"List",code:"Code",file:"File",accordion:"Accordion",array:"Repeater",relationship:"Relationship",richtext:"Rich Text",hero:"Hero Section",card:"Card Block",featureSplit:"Feature Split",featureGrid:"Feature Grid",ctaBanner:"CTA Banner",testimonials:"Testimonials Stack",faq:"FAQ Section",stats:"Stats & Metrics",logoCloud:"Logo Cloud",pricing:"Pricing Grid / Plan",team:"Team Profiles Showcase",recentFeed:"Dynamic Content Feed",processSteps:"Process Timeline / Steps",formEmbed:"Lead Intake Form",videoShowcase:"Cinematic Video Showcase",headingElement:"Heading",textElement:"Text",imageElement:"Image",richtextElement:"Rich Text",buttonElement:"Button",videoElement:"Video",listElement:"List"}[e]||e}function Ea(e){let t=e.name;return t&&t.trim()?t.trim():Ws(e.type)}function Vm(e,t){if(t?.fields){for(let r of t.fields)if(r.type==="text"||r.type==="textarea"){let o=e[r.name];if(o&&typeof o=="string")return o}}return e.heading||e.title||e.text||e.name||e.label||e.sectionTitle||""}var Km=({block:e,index:t,blockSchema:r,editingBlockId:o,setEditingBlockId:a,onDuplicate:n,compact:s})=>{let{attributes:i,listeners:l,setNodeRef:d,transform:c,transition:m,isDragging:u}=useSortable({id:e.id}),{removeBlock:g,updateBlock:x}=Be(),f=o===e.id,[y,b]=useState(false),[v,R]=useState(false),[L,C]=useState(e.name||""),w=useRef(null);useEffect(()=>{v&&w.current&&(w.current.focus(),w.current.select());},[v]);let N=useCallback(()=>{R(false);let P=L.trim();P!==(e.name||"").trim()&&x(e.id,{name:P||""});},[L,e.name,e.id,x]),p={transform:CSS.Transform.toString(c),transition:m,zIndex:u?10:1,opacity:u?.8:1},A=Ea(e),O=e.data||{},F=Vm(O,r);return s?jsxs("div",{ref:d,style:p,className:"relative group",children:[jsxs("div",{onClick:()=>a(e.id),className:`flex items-center gap-1 pl-5 pr-1.5 py-1 bg-[var(--kyro-bg-secondary)] rounded-md border transition-colors cursor-pointer text-xs whitespace-nowrap ${f?`${(Fe[e.type]||Fe.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[jsx("div",{className:"absolute left-0.5 top-1/2 -translate-y-1/2 p-0.5 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] opacity-0 group-hover:opacity-100 transition-opacity hover:bg-[var(--kyro-surface-accent)] rounded",...i,...l,onClick:P=>P.stopPropagation(),children:jsx(GripVertical,{className:"w-2.5 h-2.5"})}),jt[e.type]&&jsx("span",{className:"text-[var(--kyro-text-secondary)] flex-shrink-0",children:jt[e.type]}),v?jsx("input",{ref:w,value:L,onChange:P=>C(P.target.value),onBlur:N,onKeyDown:P=>{P.key==="Enter"&&N(),P.key==="Escape"&&(C(e.name||""),R(false));},onClick:P=>P.stopPropagation(),className:"flex-1 min-w-0 bg-[var(--kyro-surface-accent)] border border-[var(--kyro-primary)] rounded px-1.5 py-0.5 text-[10px] font-medium text-[var(--kyro-text-primary)] outline-none"}):jsx("span",{onClick:P=>{P.stopPropagation(),C(e.name||""),R(true);},className:"font-medium text-[var(--kyro-text-secondary)] truncate max-w-[120px] cursor-text hover:text-[var(--kyro-text-primary)] transition-colors",title:"Click to rename",children:A}),y?jsxs("div",{className:"flex items-center gap-0.5",onClick:P=>P.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{g(e.id),b(false);},className:"px-1.5 py-0.5 text-[9px] bg-[var(--kyro-danger)] text-white rounded font-semibold transition-colors hover:brightness-90",children:"Remove"}),jsx("button",{type:"button",onClick:()=>b(false),className:"px-1.5 py-0.5 text-[9px] bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded font-semibold transition-colors",children:"Cancel"})]}):jsxs("div",{className:"flex items-center gap-0.5",children:[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:jsx(Copy,{className:"w-3 h-3"})}),jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),b(true);},className:"p-0.5 hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] rounded text-[var(--kyro-text-muted)] transition-colors",title:"Remove",children:jsx(X,{className:"w-3 h-3"})})]})]}),f&&jsx(Wo,{block:e,blockSchema:r,onClose:()=>a(null)})]}):jsxs("div",{ref:d,style:p,className:"relative group mb-2",children:[jsxs("div",{...i,...l,onClick:()=>a(e.id),className:`flex items-center gap-3 p-3 bg-[var(--kyro-bg-secondary)] rounded-lg border transition-colors cursor-grab active:cursor-grabbing ${f?`${(Fe[e.type]||Fe.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[jt[e.type]&&jsx("span",{className:"text-[var(--kyro-text-secondary)]",children:jt[e.type]}),jsxs("div",{className:"flex-1 min-w-0",children:[v?jsx("input",{ref:w,value:L,onChange:P=>C(P.target.value),onBlur:N,onKeyDown:P=>{P.key==="Enter"&&N(),P.key==="Escape"&&(C(e.name||""),R(false));},onClick:P=>P.stopPropagation(),placeholder:Ws(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"}):jsxs("div",{onClick:P=>{window.innerWidth>=768&&(P.stopPropagation(),C(e.name||""),R(true));},className:"text-xs font-semibold text-[var(--kyro-text-secondary)] truncate md:cursor-text hover:text-[var(--kyro-text-primary)] transition-colors",title:"Click to rename",children:[A,F&&typeof F=="string"&&jsxs("span",{className:"text-[var(--kyro-text-muted)] font-normal ml-1.5",children:["- ",F.length>40?`${F.slice(0,40)}...`:F]})]}),r?.admin?.description&&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&&jsxs("span",{className:"text-[10px] bg-[var(--kyro-surface-accent)] px-2 py-0.5 rounded text-[var(--kyro-text-muted)] font-medium",children:[e.children.length," nested"]}),y?jsxs("div",{className:"flex items-center gap-1.5",onClick:P=>P.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{g(e.id),b(false);},className:"px-2.5 py-1 text-[10px] bg-[var(--kyro-danger)] text-white rounded font-semibold transition-colors hover:brightness-90",children:"Remove"}),jsx("button",{type:"button",onClick:()=>b(false),className:"px-2.5 py-1 text-[10px] bg-[var(--kyro-surface-accent)] hover:bg-[var(--kyro-border)] text-[var(--kyro-text-secondary)] rounded font-semibold transition-colors",children:"Cancel"})]}):jsxs("div",{className:"flex items-center gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),C(e.name||""),R(true);},className:"md:hidden p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Rename Block",children: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:[jsx("path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"}),jsx("path",{d:"m15 5 4 4"})]})}),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:jsx(Copy,{className:"w-3.5 h-3.5"})}),jsx("button",{type:"button",onClick:P=>{P.stopPropagation(),b(true);},className:"p-1 hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] rounded text-[var(--kyro-text-muted)] transition-colors",title:"Remove Block",children:jsx(X,{className:"w-3.5 h-3.5"})})]})]}),f&&jsx(Wo,{block:e,blockSchema:r,onClose:()=>a(null)})]})},Gm=ka.memo(Km),Vs=({field:e,value:t,onChange:r,onBlocksChange:o,error:a,disabled:n,documentStatus:s,justSaved:i})=>{let[l,d]=useState(false),[c,m]=useState(false),u=useRef(null),g=e.admin?.pickerMode||"drawer",x=e.blocks||[],f=x.reduce((B,K)=>{let ce=K.admin?.group||"Custom Blocks";return B[ce]||(B[ce]=[]),B[ce].push(K),B},{}),y=["Structural Sections","Marketing Grids","Lead Capture & Interactive","Dynamic Content","Basic Content Elements","Custom Blocks"],b=Object.entries(f).sort(([B],[K])=>{let ce=y.indexOf(B),he=y.indexOf(K);return ce!==-1&&he!==-1?ce-he:ce!==-1?-1:he!==-1?1:B.localeCompare(K)}).map(([B,K])=>({title:B,blocks:K})),v=useRef(null);v.current||(v.current=Vl(x,b));let R=v.current,L=useStore(R,B=>B.blocks),[C,w]=useState(null),[N,p]=useState(null),A=useRef(L.length),O=useRef(new Set(L.map(B=>B.id))),F=useRef(false);useEffect(()=>{if(F.current&&L.length>A.current){let B=L.find(K=>K.id&&!O.current.has(K.id));B&&p(B.id);}A.current=L.length,O.current=new Set(L.map(B=>B.id));},[L]),useEffect(()=>(o&&R.getState().setOnBlocksChange(o),()=>{R.getState().setOnBlocksChange(()=>{});}),[o,R]);let P=useRef(null);useEffect(()=>{let B=Array.isArray(t)?t:[],K=P.current||[];if(JSON.stringify(B)!==JSON.stringify(K)){let ce=[...B];A.current=ce.length,O.current=new Set(ce.map(he=>he.id)),R.getState().setBlocks(ce),P.current=ce,F.current=true;}else B.length===0&&!F.current&&(F.current=true,P.current=[]);},[t,e.name,R]);let S=useRef(r);S.current=r,useEffect(()=>{if(!S.current)return;let B=P.current;B&&JSON.stringify(L)!==JSON.stringify(B)&&(P.current=[...L],S.current(L));},[L]);let j=useCallback(B=>{R.getState().addBlock(B);},[R]),se=useCallback(B=>{let K=L.findIndex(I=>I.id===B);if(K===-1)return;let ce=L[K],he=I=>{let z=Math.random().toString(36).substr(2,9);return {...I,id:z,children:I.children?I.children.map(Ve=>he(Ve)):I.children,data:I.data?JSON.parse(JSON.stringify(I.data)):I.data}},Pe=he(ce),Ce=[...L];Ce.splice(K+1,0,Pe),R.getState().setBlocks(Ce);},[L,R]),ie=useSensors(useSensor(PointerSensor,{activationConstraint:{delay:200,tolerance:5}}),useSensor(KeyboardSensor)),ue=B=>{w(B.active);},oe=B=>{let{active:K,over:ce}=B;if(w(null),!!ce){if(K.id.toString().startsWith("drawer-")){let he=K.id.toString().replace("drawer-","");if(ce.id.toString().startsWith("container-")){let Pe=ce.id.toString().replace("container-",""),Ce=L.find(I=>I.id===Pe);if(Ce){let I=Vo(he);R.getState().updateBlock(Pe,{children:[...Ce.children||[],I]});}}else j(he);return}if(K.id!==ce.id){let he=L.findIndex(Ce=>Ce.id===K.id),Pe=L.findIndex(Ce=>Ce.id===ce.id);if(he!==-1&&Pe!==-1){let Ce=[...L],[I]=Ce.splice(he,1);Ce.splice(Pe,0,I),R.getState().setBlocks(Ce);}}}},ne=C?b.flatMap(B=>B.blocks).find(B=>`drawer-${B.type}`===C.id)||L.find(B=>B.id===C.id):null;ne?"label"in ne?ne.label:ne.type:"Block";return useEffect(()=>{if(!c)return;let B=K=>{u.current&&!u.current.contains(K.target)&&m(false);};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[c]),jsx(vo.Provider,{value:v.current,children:jsxs("div",{className:"kyro-blocks-field",children:[jsxs(DndContext,{sensors:ie,collisionDetection:closestCenter,onDragStart:ue,onDragEnd:oe,children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("label",{className:"kyro-form-label",children:e.label||e.name}),g==="dropdown"?jsxs("div",{ref:u,className:"relative",children:[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:[jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add Element",jsx(ChevronDown,{className:`w-3.5 h-3.5 transition-transform ${c?"rotate-180":""}`})]}),c&&jsx("div",{className:"absolute right-0 top-full mt-1 w-56 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 py-2 max-h-80 overflow-y-auto",children:b.map(B=>jsxs("div",{children:[b.length>1&&jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold tracking-wider text-[var(--kyro-text-muted)] uppercase",children:B.title}),B.blocks.map(K=>jsxs("button",{type:"button",onClick:()=>{j(K.slug),m(false);},className:"w-full flex items-center gap-3 px-3 py-2 text-sm text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)]/50 transition-colors text-left",children:[jsx("span",{className:"flex-shrink-0 w-5 h-5 flex items-center justify-center text-[var(--kyro-text-muted)]",children:jt[K.slug]||jsx(Box,{className:"w-4 h-4"})}),jsxs("div",{className:"min-w-0 flex-1",children:[jsx("div",{className:"text-xs font-semibold truncate",children:K.label}),K.admin?.description&&jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] truncate",children:K.admin.description})]})]},K.slug))]},B.title))})]}):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:[jsx(Plus,{className:"w-4 h-4"}),"Add Block"]})]}),jsx("div",{className:"mb-4",children:jsx(Ia,{open:l,onClose:()=>d(false),onSelect:j,children:jsx("div",{className:"space-y-4",children:b.map(B=>jsxs("div",{children:[jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] mb-2 tracking-wider",children:B.title}),jsx("div",{className:"grid grid-cols-3 gap-2",children:B.blocks.map(K=>jsx(Kl,{block:{type:K.slug,label:K.label,description:K.admin?.description||"",icon:null},onSelect:j,children: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:jsx("span",{className:"text-[var(--kyro-text-muted)]",children:jt[K.slug]||jsx(Box,{className:"w-4 h-4"})})})},K.slug))})]},B.title))})})}),jsx(SortableContext,{items:L.map(B=>B.id),strategy:verticalListSortingStrategy,children:jsxs("div",{className:g==="dropdown"?"flex flex-wrap gap-1.5":"space-y-4",children:[L.map((B,K)=>{let ce=e.blocks?.find(he=>he.slug===B.type);return jsx(Gm,{block:B,index:K,blockSchema:ce,editingBlockId:N,setEditingBlockId:p,onDuplicate:se,compact:g==="dropdown"},B.id||K)}),L.length===0&&jsx("div",{className:g==="dropdown"?"text-xs text-[var(--kyro-text-muted)] italic py-1":"text-center py-12 text-[var(--kyro-text-muted)] border-2 border-dashed border-[var(--kyro-border)] rounded-lg",children:g==="dropdown"?"No elements added":"Click the button above to add your first block"})]})}),jsx(DragOverlay,{children:C&&ne&&jsx("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-primary)] rounded-md p-3 shadow-lg",children:ne.label||ne.type||"Block"})})]}),a&&jsx("p",{className:"kyro-form-error",children:a})]})})};function mr(e){if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(mr);if(typeof e=="object"){let t=e,r=Object.keys(t),o="id"in t&&(typeof t.id=="string"||t.id===null),a="url"in t||"filename"in t||"mimeType"in t;if(o&&(a||r.length<=2)&&r.length<=8)return t.id;let n={};for(let s of r)n[s]=mr(t[s]);return n}return e}function kd(){let e=useRef([]),t=useRef(false);return {queueTask:useCallback((o,a)=>{e.current.push(o);async function n(){if(!t.current&&!(typeof a?.beforeProcess=="function"&&a.beforeProcess()===false))for(;e.current.length>0;){let s=e.current.pop();e.current=[],t.current=true;try{await s();}catch(i){console.error("Error in queued function:",i);}finally{t.current=false,typeof a?.afterProcess=="function"&&a.afterProcess();}}}n();},[])}}function hd({config:e,initialData:t,collectionSlug:r,globalSlug:o,documentId:a,onChange:n,onActionSuccess:s,onActionError:i}){let l=Le(),{confirm:d}=ot(),{formData:c,setFormData:m,setField:u,lastSavedData:g,setLastSavedData:x,setHasUnsavedChanges:f,isSlugLocked:y,loadDocument:b,setIsAutoSaving:v,setAutoSaveStatus:R,setVersions:L,setLoadingVersions:C,sidebarCollapsed:w,setSidebarCollapsed:N,getDraftCache:p,setDraftCache:A,clearDraftCache:O,resetForm:F}=l,P=!!e.versions,S=o||t?.id||a||r,M=useRef(false);!o&&S&&c&&Object.keys(c).length>0&&c.id!==S&&(M.current=true),useEffect(()=>{M.current&&(M.current=false,F());},[F]);let j=useRef(null),se=useRef(null),ie=useRef(null),ue=useRef(typeof navigator<"u"?navigator.onLine:true),oe=useRef(0),ne=useRef(false),je=useRef(null),ft=useRef(""),B=useRef(""),{queueTask:K}=kd(),ce=useCallback(q=>o?`global:${o}`:r&&q?`${r}:${q}`:null,[r,o]),he=useCallback((q,X,le)=>{A(q,{data:X,baseUpdatedAt:g.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:le?.lastSyncedAt??null});},[g.updatedAt,A]),Pe=useCallback(async()=>{let q=o?qe(`/api/globals/${o}/versions`):r&&c.id?qe(`/api/${r}/${c.id}/versions`):null;if(q){C(true);try{let le=await(await ct(q)).json();L(le.docs||[]);}catch(X){console.error("Failed to fetch versions:",X);}finally{C(false);}}},[c.id,r,o,C,L]),Ce=useCallback(()=>{let q=Le.getState(),X=q.formData;if(ne.current||!r||!X.id||!q.hasDirtyFields())return;let le=ce(X.id);le&&he(le,X);},[r,ce,he]),I=useCallback(async q=>{let X=Le.getState(),le=X.formData,xe=X.lastSavedData;if(ne.current||!P&&o||!o&&(!r||!le.id)||!X.hasDirtyFields())return;let we=ce(le.id);if(we&&he(we,le),!ue.current){R("offline");return}v(true),R("saving"),X.setBackgroundProcessing(true);try{let Qe=o?qe(`/api/globals/${o}?autosave=true`):qe(`/api/${r}/${le.id}?autosave=true`),Ct=await ct(Qe,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":"true"},keepalive:q?.keepalive,body:JSON.stringify({...mr(le),baseUpdatedAt:xe.updatedAt??null})});if(Ct.ok)oe.current=Date.now(),X.setRetryCount(0),X.setLastSavedAt(Date.now()),ie.current&&clearTimeout(ie.current),we&&A(we,{data:le,baseUpdatedAt:xe.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:(await Ct.clone().json()).data?.updatedAt||new Date().toISOString()}),R("success"),setTimeout(()=>{Le.getState().autoSaveStatus==="success"&&R("idle");},2e3);else if(Ct.status===409)R("conflict");else throw new Error(`Draft auto-save failed with status ${Ct.status}`)}catch(Qe){console.error("Auto-save failed:",Qe);let Ct=Le.getState(),D=Ct.retryCount;if(D<5){Ct.setRetryCount(D+1),R("retrying");let G=Math.min(1e3*Math.pow(2,D),6e4);ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>z(q),G);}else R("offline");}finally{v(false),Le.getState().setBackgroundProcessing(false);}},[r,ce,o,he,R,A,v,P]),z=useCallback(q=>{K(()=>I(q),{beforeProcess:()=>true,afterProcess:()=>{}});},[I,K]),Ve=useCallback(async(q,X=true)=>{let le=Le.getState(),xe=q||le.formData,we=o?qe(`/api/globals/${o}`):qe(`/api/${r}/${xe.id}`),Qe=await ct(we,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":String(X)},body:JSON.stringify({...mr(xe),baseUpdatedAt:le.lastSavedData.updatedAt??null})});return Qe.status===409&&R("conflict"),Qe},[r,o,R]);useEffect(()=>{let q=()=>{N(!w);};return window.addEventListener("toggle-sidebar",q),()=>window.removeEventListener("toggle-sidebar",q)},[w,N]);let ye=useRef(null),Se=useRef(""),lt=useRef(false);useEffect(()=>{let q=o||t?.id,X=JSON.stringify(t);lt.current&&ye.current===q&&Se.current===X||(b(t||{},t||{}),lt.current=true,ye.current=q,Se.current=X);},[r,c.id,o,t,b]),useEffect(()=>{if(!r||!t?.id)return;let q=ce(t.id);if(!q||je.current===q)return;let X=false;return (async()=>{if(!P)return;let xe=p(q);if(xe){if(JSON.stringify(xe.data)===JSON.stringify(t)){O(q);return}je.current=q,d({title:"Restore draft?",message:"A newer autosaved draft was found for this document. Restore it or discard it and continue with the saved version.",confirmLabel:"Restore draft",cancelLabel:"Discard draft",onConfirm:async()=>{if(X)return;let Qe={...Le.getState().formData,...xe.data};m(Qe),s?.("Recovered autosaved draft");},onCancel:async()=>{O(q);}});}})(),()=>{X=true;}},[O,r,d,ce,p,t,s,m,P]);function At(q,X){for(let le of q){if(le.name===X&&le.admin?.autoGenerate==="title")return le;if(le.type==="tabs"&&"tabs"in le)for(let xe of le.tabs){let we=At(xe.fields,X);if(we)return we}if((le.type==="group"||le.type==="collapsible")&&"fields"in le){let xe=At(le.fields,X);if(xe)return xe}}}useEffect(()=>{let q=e.fields;if(!At(q,"metaTitle"))return;let le=uo(q,c,"title"),xe=le?String(le):"";xe&&(!c.metaTitle||c.metaTitle===c._lastMetaTitle)&&u("metaTitle",xe);},[c,e.fields,u]),useEffect(()=>{let q=e.fields,X=q.find(we=>we.name==="slug"&&we.admin?.autoGenerate);if(!X?.admin?.autoGenerate)return;let le=X.admin.autoGenerate,xe=uo(q,c,le);if(y&&xe){let we=Tn(xe);we!==c.slug&&u("slug",we);}},[c,y,e.fields,u]),useEffect(()=>{if(w||!o&&(!r||!c.id)||!Le.getState().hasDirtyFields()||id()!=="keystroke")return;zn("other");let X=JSON.stringify(c);X!==ft.current&&(j.current&&clearTimeout(j.current),j.current=setTimeout(Ce,1500),se.current&&clearTimeout(se.current),se.current=setTimeout(()=>{ft.current=X,z();},8e3));},[c,w,r,o,Ce,z]),useEffect(()=>{if(!o&&(!r||!c.id))return;let q=()=>{ne.current||!Le.getState().hasDirtyFields()||z({keepalive:true});},X=()=>{document.hidden&&q();},le=()=>{ue.current=true,q();},xe=()=>{ue.current=false;let we=Le.getState();we.hasDirtyFields()&&we.setAutoSaveStatus("offline");};return window.addEventListener("blur",q),window.addEventListener("pagehide",q),window.addEventListener("online",le),window.addEventListener("offline",xe),document.addEventListener("visibilitychange",X),()=>{window.removeEventListener("blur",q),window.removeEventListener("pagehide",q),window.removeEventListener("online",le),window.removeEventListener("offline",xe),document.removeEventListener("visibilitychange",X);}},[r,o,c.id,z]),useEffect(()=>{let q=JSON.stringify(c);if(q===B.current)return;B.current=q;let X=document.getElementById("form-data");X&&(X.value=q),n?.(c);},[c,n]),useEffect(()=>{(o||c.id)&&Pe();},[c.id,o,Pe]);let qt=!c.id&&!o?"draft":P&&c.status||"published",vt=(!!c.id||!!o)&&qt==="draft";return {...l,fetchVersions:Pe,performAutoSave:z,saveDocument:Ve,autoSaveSkipRef:ne,lastAutoSaveTimeRef:oe,documentStatus:qt,hasUnpublishedChanges:vt,versionsEnabled:P}}function wo({trigger:e,children:t,align:r="right",direction:o="up"}){let[a,n]=useState(false),s=useRef(null);return useEffect(()=>{let i=l=>{s.current&&!s.current.contains(l.target)&&n(false);};return a&&document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[a]),jsxs("div",{className:"relative",ref:s,children:[jsx("div",{onClick:()=>n(!a),className:"cursor-pointer",children:e}),a&&jsx("div",{className:`absolute z-[100] min-w-[200px] py-2 bg-[var(--kyro-surface)] rounded-2xl shadow-2xl border border-[var(--kyro-border)] animate-in fade-in zoom-in-95 duration-100 ${r==="right"?"right-0":"left-0"} ${o==="down"?"top-full mt-2":"bottom-full mb-2"}`,onClick:()=>n(false),children:t})]})}function Ht({children:e,onClick:t,icon:r,danger:o,disabled:a,className:n=""}){return jsx("div",{className:"px-1.5",children: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&&jsx("span",{className:"w-4 h-4 opacity-70",children:r}),jsx("span",{className:"flex-1",children:e})]})})}function ja(){return jsx("div",{className:"my-1 border-t border-[var(--kyro-border)] opacity-50"})}function Co({status:e,saveStatus:t,hasChanges:r,onPublish:o,children:a,disabled:n,direction:s="down"}){let i=e==="published"&&!r&&t!=="saving"&&t!=="error",l=n||t==="saving"||i,d="kyro-btn kyro-btn-sm text-[11px] font-regular tracking-widest transition-all duration-300 rounded-lg",c=()=>t==="saving"?`${d} bg-[var(--kyro-primary)]/70 border-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] cursor-wait`:t==="saved"?`${d} bg-[var(--kyro-success)] border-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)]`:t==="error"?`${d} bg-[var(--kyro-error)] border-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)]`:i?`${d} bg-[var(--kyro-gray-200)] border-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] cursor-not-allowed`:`${d} bg-[var(--kyro-primary)] border-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] hover:bg-[var(--kyro-primary-hover)]`,m="kyro-btn kyro-btn-md px-2 rounded-l-none border-l-[1px] border-white/20 transition-all duration-300",u=()=>t==="saving"?`${m} bg-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)]/70`:t==="saved"?`${m} bg-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-success)]`:t==="error"?`${m} bg-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-error)]`:i?`${m} bg-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] border-[var(--kyro-gray-200)]`:`${m} bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)] hover:bg-[var(--kyro-primary-hover)]`,g=()=>t==="saving"?"Publishing...":t==="saved"?"Published \u2713":t==="error"?"Retry":i?"Published":"Publish Changes";return jsxs("div",{className:"inline-flex items-center",children:[jsxs("button",{type:"button",onClick:o,disabled:l,className:`${c()} ${a?"":"rounded-r-lg border-r border-[var(--kyro-border)]"}`,children:[t==="saving"&&jsx(Ar,{size:"sm",className:"inline mr-1.5"}),i&&jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"inline mr-1",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),g()]}),a&&jsx(wo,{trigger:jsx("button",{type:"button",className:u(),disabled:t==="saving",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"m6 9 6 6 6-6"})})}),direction:s,children:a})]})}var Cd=({title:e,description:t,slug:r})=>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:[jsxs("div",{className:"flex items-center gap-2 mb-2",children:[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"}),jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-tight",children:"kyro-cms.com"}),jsxs("span",{className:"text-[12px] text-[var(--kyro-text-secondary)] leading-tight opacity-80",children:["https://kyro-cms.com \u203A posts \u203A ",r]})]})]}),jsx("h3",{className:"text-[20px] text-[#2563eb] dark:text-[#60a5fa] font-medium hover:underline cursor-pointer mb-1 leading-tight transition-colors",children:e}),jsx("p",{className:"text-[14px] text-[var(--kyro-text-secondary)] leading-relaxed line-clamp-2",children:t})]});function Td({field:e,formData:t,onTabDataChange:r,renderField:o}){let[a,n]=useState(0),s=e.tabs||[],i=s[a]||s[0],l=e.name?t[e.name]||{}:t;return jsxs("div",{className:"space-y-8",children:[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)=>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))}),jsx("div",{className:"space-y-6",children:i?.fields.map(d=>o(d,l,r))}),i?.label==="SEO"&&jsxs("div",{className:"mt-12 pt-8 border-t border-[var(--kyro-border)]",children:[jsx("h4",{className:"text-[10px] font-bold text-[var(--kyro-text-secondary)] tracking-[0.2em] mb-6 opacity-50",children:"Live Google Preview"}),jsx(Cd,{title:String((typeof l.metaTitle=="object"?"":l.metaTitle)||(typeof l.title=="object"?"":l.title)||"Untitled"),description:String((typeof l.metaDescription=="object"?"":l.metaDescription)||"Please enter a description..."),slug:String((typeof t.slug=="object"?"":t.slug)||"your-slug")})]})]})}function Fd({collectionSlug:e,globalSlug:t,documentStatus:r,hasUnpublishedChanges:o,localSaveStatus:a,handleCreateNew:n,handleDuplicate:s,handleUnpublish:i,handleDelete:l,handlePublish:d,handleSchedulePublish:c}){let[m,u]=useState(Date.now()),[g,x]=useState(false),f=useRef(null),{formData:y,hasUnsavedChanges:b,autoSaveStatus:v,lastSavedAt:R,retryCount:L,view:C,setView:w,showPreview:N,setShowPreview:p,setFormData:A,markSaved:O,lastSavedData:F}=Le(),P=!y.id;useEffect(()=>{let B=setInterval(()=>u(Date.now()),1e4);return ()=>clearInterval(B)},[]),useEffect(()=>{let B=K=>{f.current&&!f.current.contains(K.target)&&x(false);};if(g)return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[g]);let S=String(y.mainTabs?.title||(typeof y.title=="object"?"":y.title)||(typeof y.name=="object"?"":y.name)||"Untitled"),M=y.updatedAt?new Date(y.updatedAt).toLocaleString():"Just now",j=y.createdAt?new Date(y.createdAt).toLocaleString():"Just now",se=o?"Draft (unpublished changes)":r==="published"?"Published":"Draft",ie=o?"Unpublished":r==="published"?"Published":"Draft",ue=r==="published"&&!b?"bg-[var(--kyro-success)]":o?"bg-[var(--kyro-warning)]":"bg-[var(--kyro-text-muted)]",oe=r==="published"&&!o?"bg-[var(--kyro-success)]/10 text-[var(--kyro-success)] border-[var(--kyro-success)]/20":o?"bg-[var(--kyro-warning)]/10 text-[var(--kyro-warning)] border-[var(--kyro-warning)]/20":"bg-[var(--kyro-text-muted)]/10 text-[var(--kyro-text-muted)] border-[var(--kyro-text-muted)]/20",ne=(B=false)=>jsxs(Fragment,{children:[v==="saving"&&jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),B?"Saving\u2026":"Saving draft..."]}),v==="success"&&jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsx(Check,{className:"w-3.5 h-3.5 shrink-0"}),B?"Saved":R?`Saved ${Math.floor((Date.now()-R)/6e4)}m ago`:"Draft saved"]}),v==="retrying"&&jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),B?`Retry ${L}/5`:`Retrying save (${L}/5)`]}),v==="offline"&&jsxs("span",{className:"text-[var(--kyro-text-muted)] flex items-center gap-1.5",children:[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:[jsx("path",{d:"M10.61 10.61a3 3 0 0 0 4.24 4.24"}),jsx("path",{d:"M13.36 13.36a3 3 0 0 0-4.24-4.24"}),jsx("path",{d:"m2 2 20 20"}),jsx("path",{d:"M18.36 5.64a9 9 0 0 0-12.72 0"}),jsx("path",{d:"M22.61 1.39a15 15 0 0 0-21.22 0"})]}),B?"Offline":"Offline \u2014 cached locally"]}),v==="error"&&jsx("span",{className:"text-[var(--kyro-danger)]",children:B?"Failed":"Draft save failed"}),v==="conflict"&&(B?jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict"}):jsxs("div",{className:"flex items-center gap-3",children:[jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict detected"}),jsx("span",{className:"opacity-30",children:"\u2014"}),jsx("button",{type:"button",onClick:async()=>{},className:"text-[var(--kyro-primary)] hover:underline",children:"Keep my changes"}),jsx("span",{className:"opacity-30",children:"|"}),jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"text-[var(--kyro-danger)] hover:underline",children:"Reload server version"})]}))]}),je=()=>!P&&jsxs(wo,{trigger: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:jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[jsx("circle",{cx:"12",cy:"5",r:"1.5"}),jsx("circle",{cx:"12",cy:"12",r:"1.5"}),jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})}),direction:"down",children:[!t&&jsx(Ht,{onClick:n,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),children:"Create New"}),!t&&jsx(Ht,{onClick:s,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),children:"Duplicate"}),jsx(Ht,{onClick:()=>x(true),icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),children:"Schedule Publish"}),r==="published"&&jsx(Ht,{onClick:i,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[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"}),jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}),children:"Unpublish"}),!t&&jsxs(Fragment,{children:[jsx(ja,{}),jsx(Ht,{onClick:l,danger:true,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("polyline",{points:"3 6 5 6 21 6"}),jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),children:"Delete"})]})]}),ft=()=>g&&jsx("div",{ref:f,className:"relative",children: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:[jsx("p",{className:"text-xs font-medium mb-2",children:"Schedule Publish"}),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)}),jsxs("div",{className:"flex items-center gap-2 justify-end",children:[jsx("button",{type:"button",onClick:()=>x(false),className:"px-3 py-1.5 text-xs kyro-btn rounded-lg",children:"Cancel"}),jsx("button",{type:"button",onClick:()=>{let B=document.getElementById("schedule-datetime")?.value;B&&c(B);},className:"px-3 py-1.5 text-xs kyro-btn-success rounded-lg",children:"Schedule"})]})]})});return jsxs(Fragment,{children:[jsxs("header",{className:"md:hidden border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)] backdrop-blur-md rounded-lg",children:[jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[jsx("a",{href:`${Ye}/${e}`,className:"p-1.5 rounded-lg hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsx(ChevronRight,{className:"w-4 h-4"})}),jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[jsx("h1",{className:"text-base font-bold tracking-tight truncate min-w-0",children:S}),jsxs("span",{className:`shrink-0 inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[9px] font-medium border ${oe}`,children:[jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ue}`}),ie]})]}),jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[jsx(Co,{status:r,saveStatus:a,hasChanges:b,onPublish:d,disabled:a==="saving"}),je(),ft()]})]}),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:[jsx("div",{className:"flex items-center gap-0.5 bg-[var(--kyro-bg-secondary)] p-0.5 rounded-lg border border-[var(--kyro-border)]/50",children:["edit","version","api"].map(B=>jsx("button",{type:"button",onClick:()=>w(B),className:`px-3 py-1 text-[10px] font-bold rounded-md transition-all ${C===B?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 active:opacity-100"}`,children:B==="edit"?"Edit":B==="version"?"History":"API"},B))}),jsxs("div",{className:"flex items-center gap-2 text-[10px] font-medium",children:[ne(true),b&&v!=="saving"&&v!=="retrying"&&v!=="conflict"&&jsx("button",{type:"button",onClick:()=>{A(F),O();},className:"text-[var(--kyro-primary)] text-[10px] font-medium hover:underline",children:"Revert"}),jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),jsx("button",{type:"button",onClick:()=>p(!N),className:`p-1.5 rounded-lg transition-all ${N?"bg-[var(--kyro-primary)]/10 text-[var(--kyro-primary)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,children:jsx(ExternalLink,{className:"w-3.5 h-3.5"})})]})]})]}),jsxs("header",{className:"hidden md:flex surface-tile px-8 py-6 items-center justify-between sticky top-0 border-b border-[var(--kyro-border)] mb-8 bg-[var(--kyro-surface)] backdrop-blur-md",children:[jsxs("div",{className:"flex flex-col gap-2 min-w-0",children:[jsxs("div",{className:"flex items-center gap-3 flex-wrap min-w-0",children:[jsx("a",{href:`${Ye}/${e}`,className:"p-2 border border-[var(--kyro-border)] rounded-xl hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsx(ChevronRight,{className:"w-4 h-4"})}),jsx("h1",{className:"text-xl font-bold tracking-tighter truncate min-w-0",children:S}),jsxs("span",{className:`shrink-0 inline-flex items-center gap-1.5 px-2 rounded-full text-[10px] font-regular border ${oe}`,children:[jsx("span",{className:`h-1.5 w-1.5 rounded-full ${ue}`}),se]})]}),jsxs("div",{className:"flex items-center gap-4 text-[11px] font-medium tracking-wide opacity-60 ml-12",children:[ne(false),b&&v!=="saving"&&v!=="retrying"&&v!=="conflict"&&jsxs(Fragment,{children:[jsx("span",{className:"opacity-30",children:"\u2014"}),jsx("button",{type:"button",onClick:()=>{A(F),O();},className:"text-[var(--kyro-primary)] hover:underline",children:"Revert changes"})]}),R&&v!=="saving"&&v!=="retrying"&&v!=="success"&&jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Draft saved ",(()=>{let B=m-R,K=Math.floor(B/6e4),ce=Math.floor(B/1e3);return K>=1?`${K}m ago`:ce>=5?`${ce}s ago`:"just now"})()]}),jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Modified ",M]}),jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Created ",j]})]})]}),jsxs("div",{className:"flex items-center gap-6",children:[jsx("div",{className:"flex items-center gap-1 bg-[var(--kyro-bg-secondary)] p-1 rounded-xl border border-[var(--kyro-border)]",children:["edit","version","api"].map(B=>jsx("button",{type:"button",onClick:()=>w(B),className:`px-5 py-2 text-xs font-bold rounded-lg transition-all ${C===B?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] opacity-50 hover:opacity-100"}`,children:B.toUpperCase()},B))}),jsx("div",{className:"h-8 w-px bg-[var(--kyro-border)] mx-2"}),jsxs("div",{className:"flex items-center gap-3",children:[jsxs("button",{type:"button",onClick:()=>p(!N),className:`kyro-btn p-2.5 rounded-xl transition-all flex items-center gap-2 ${N?"shadow-lg":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,title:"Live Preview",children:[jsx(ExternalLink,{className:"w-4 h-4"}),N&&jsx("span",{className:"text-[10px] font-bold tracking-widest pr-1",children:"Active"})]}),je(),ft(),jsx(Co,{status:r,saveStatus:a,hasChanges:b,onPublish:d,disabled:a==="saving"})]})]})]})]})}function Pd({config:e,layout:t,collectionSlug:r,renderField:o}){let{showPreview:a,sidebarCollapsed:n,formData:s}=Le();if(t==="single")return jsx("div",{className:"w-full space-y-6 md:space-y-8",children:jsx("div",{className:"surface-tile p-4 md:p-8 space-y-6 md:space-y-8",children:e.fields.map(d=>o(d))})});let l=e.fields.some(d=>d.admin?.position==="sidebar")&&!a;return jsxs("div",{className:`w-full mx-auto grid gap-4 md:gap-8 pb-32 transition-all duration-700 ${a?"grid-cols-1 lg:grid-cols-2":n||!l?"grid-cols-1":"grid-cols-1 lg:grid-cols-[1fr_380px]"}`,children:[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}):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?jsx("div",{className:"sticky top-36 h-[calc(100vh-280px)] animate-in fade-in slide-in-from-right-10 duration-700",children: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:[jsxs("div",{className:"absolute top-4 left-4 z-10 flex items-center gap-2",children:[jsx("div",{className:"h-2 w-2 rounded-full bg-green-500 animate-pulse"}),jsx("span",{className:"text-[10px] font-bold tracking-widest text-white/60",children:"Live Preview Mode"})]}),jsx("iframe",{src:`/${r}/${s.slug||s.id}?preview=true`,className:"w-full h-full border-none",title:"Live Preview"}),jsx("div",{className:"absolute inset-0 bg-transparent pointer-events-none border-[12px] border-[var(--kyro-surface)] rounded-3xl"})]})}):n?null: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")&&jsxs("div",{className:"surface-tile p-4 md:p-6 space-y-4 md:space-y-6",children:[jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Settings"}),e.fields.filter(d=>d.admin?.position==="sidebar").map(d=>o(d))]})})]})}function Dd({handleRestoreVersion:e,handleCompareVersions:t,toggleCompareSelection:r}){let{compareMode:o,setCompareMode:a,compareSelected:n,setCompareSelected:s,compareDiffs:i,setCompareDiffs:l,loadingDiffs:d,loadingVersions:c,versions:m}=Le();return jsx("div",{className:"w-full animate-in fade-in slide-in-from-bottom-4 pb-12",children:jsxs("div",{className:"surface-tile p-0 overflow-hidden",children:[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:[jsxs("div",{children:[jsx("h2",{className:"text-base md:text-lg font-bold text-[var(--kyro-text-primary)]",children:"Version History"}),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`})]}),jsxs("div",{className:"flex items-center gap-2",children:[o&&n.length===2&&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"}),jsx("button",{type:"button",onClick:()=>{a(!o),s([]),l([]);},className:`px-3 py-1.5 rounded-lg text-[11px] font-bold tracking-wider transition-all ${o?"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]":"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:o?"Done":"Compare"})]})]}),i.length>0&&jsxs("div",{className:"border-b border-[var(--kyro-border)]",children:[jsxs("div",{className:"px-6 py-3 flex items-center justify-between",children:[jsxs("span",{className:"text-[11px] font-bold text-[var(--kyro-text-primary)] tracking-wider",children:[i.length," change",i.length!==1?"s":""]}),jsx("button",{type:"button",onClick:()=>l([]),className:"p-1 rounded hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-muted)]",children:jsx(X,{className:"w-4 h-4"})})]}),jsx("div",{className:"max-h-[400px] overflow-y-auto",children:i.map((u,g)=>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:[jsx("div",{className:"text-[var(--kyro-text-muted)] truncate font-semibold md:font-normal",children:u.field}),jsx("div",{className:"text-[var(--kyro-text-muted)] truncate hidden md:block",children:typeof u.oldValue=="object"?JSON.stringify(u.oldValue):String(u.oldValue??"null")}),jsxs("div",{className:"md:col-span-2 text-[var(--kyro-text-primary)] truncate",children:[jsx("span",{className:"md:hidden text-[var(--kyro-text-muted)]",children:"\u2192 "}),typeof u.newValue=="object"?JSON.stringify(u.newValue):String(u.newValue??"null")]})]},g))})]}),c?jsx("div",{className:"flex justify-center py-16",children:jsx("span",{className:"animate-spin text-[var(--kyro-primary)]",children:"\u231B"})}):m.length===0?jsx("div",{className:"text-center py-16 text-[var(--kyro-text-muted)] text-sm italic",children:"No versions yet."}):jsx("div",{className:"divide-y divide-[var(--kyro-border)]",children:m.map((u,g)=>{let x=n.includes(u.id),f=(u.changeDescription||"").toLowerCase().includes("auto");return jsxs("div",{onClick:o?()=>r(u.id):void 0,className:`transition-all ${o?x?"bg-[var(--kyro-primary)]/5 cursor-pointer":"hover:bg-[var(--kyro-bg-secondary)] cursor-pointer":"hover:bg-[var(--kyro-bg-secondary)]"}`,children:[jsxs("div",{className:"hidden md:grid grid-cols-12 gap-3 px-6 py-3 items-center",children:[jsx("div",{className:"col-span-1 flex items-center gap-2",children:o?jsx("div",{className:`w-4 h-4 rounded-full border ${x?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:x&&jsx(Check,{className:"w-4 h-4"})}):jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5",children:m.length-g})}),jsxs("div",{className:"col-span-4 min-w-0",children:[jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-2",children:[u.changeDescription||"Snapshot",f&&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"})]}),jsx("div",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(u.createdAt||u.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),jsx("div",{className:"col-span-3",children:u.status&&jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold capitalize tracking-wider ${u.status==="published"?" text-[var(--kyro-success)]":" text-[var(--kyro-warning)]"}`,children:[jsx("span",{className:`w-1.5 h-1.5 rounded-full ${u.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),u.status]})}),jsx("div",{className:"col-span-2 text-[11px] text-[var(--kyro-text-muted)]",children:u.createdBy||"system"}),jsx("div",{className:"col-span-2 flex justify-end",children:!o&&jsx("button",{type:"button",onClick:()=>e(u.id),className:"px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[11px] font-bold tracking-wider text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] transition-all active:scale-95",children:"Restore"})})]}),jsxs("div",{className:"md:hidden flex items-start gap-3 px-4 py-3",children:[jsx("div",{className:"pt-0.5 shrink-0",children:o?jsx("div",{className:`w-4 h-4 rounded-full border ${x?"border-[var(--kyro-primary)] bg-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:x&&jsx(Check,{className:"w-4 h-4"})}):jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5 inline-block text-center",children:m.length-g})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-1.5",children:[u.changeDescription||"Snapshot",f&&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"})]}),jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(u.createdAt||u.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}),u.status&&jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-bold capitalize tracking-wider ${u.status==="published"?"text-[var(--kyro-success)]":"text-[var(--kyro-warning)]"}`,children:[jsx("span",{className:`w-1 h-1 rounded-full ${u.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),u.status]}),jsx("span",{className:"text-[10px] text-[var(--kyro-text-muted)] opacity-60",children:u.createdBy||"system"})]})]}),!o&&jsx("button",{type:"button",onClick:()=>e(u.id),className:"shrink-0 px-2.5 py-1 rounded-lg border border-[var(--kyro-border)] text-[10px] font-bold tracking-wider text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)] hover:border-[var(--kyro-primary)] transition-all active:scale-95",children:"Restore"})]})]},u.id)})})]})})}function Bd({collectionSlug:e,globalSlug:t}){let{formData:r}=Le();return jsx("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4",children:jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_300px] gap-8",children:[jsxs("div",{className:"surface-tile p-8 min-w-0",children:[jsx("h2",{className:"text-xl font-bold mb-6",children:"Response Payload"}),jsx("div",{className:"bg-[#0f172a] p-6 rounded-2xl border border-white/5 overflow-x-auto max-h-[800px]",children:jsx("pre",{className:"text-blue-300 text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(r,null,2)})})]}),jsx("div",{className:"space-y-6",children:jsxs("div",{className:"surface-tile p-8 space-y-6",children:[jsx("h2",{className:"text-xl font-bold mb-6",children:"API Info"}),jsxs("div",{className:"space-y-6",children:[jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Reference Path"}),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&&jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Document ID"}),jsxs("div",{className:"flex items-center gap-2",children:[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)}),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:jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]}),t&&jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Global Slug"}),jsx("code",{className:"text-xs font-mono bg-[var(--kyro-bg-secondary)] px-3 py-1.5 rounded-lg border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]",children:t})]})]})]})})]})})}var Id={};function _a({config:e,data:t=Id,errors:r=Id,onChange:o,disabled:a,collectionSlug:n,globalSlug:s,documentId:i,documentName:l,layout:d="split",onActionSuccess:c,onActionError:m,justSaved:u}){let g=e||(s?jl[s]:n?Ho[n]:null),[x,f]=useState(g);useEffect(()=>{s==="storage-settings"?De("/api/kyro/schema").then(T=>{T?.globals?.["storage-settings"]&&f(T.globals["storage-settings"]);}).catch(T=>console.error("[AutoForm] Failed to fetch dynamic schema",T)):f(g);},[s,g]);let y=x||g,{confirm:b}=ot(),{formData:v,hasUnsavedChanges:L,autoSaveStatus:N,lastSavedAt:p,view:se,setView:ie,setShowPreview:B,isMenuOpen:K,setIsMenuOpen:ce,loadingFields:he,setLoadingFields:Pe,compareSelected:z,setCompareSelected:Ve,setCompareDiffs:Se,setLoadingDiffs:At,setField:qt,setFormData:vt,setLastSavedData:X,setAutoSaveStatus:le,fetchVersions:xe,saveDocument:we,autoSaveSkipRef:Qe,lastAutoSaveTimeRef:Ct,documentStatus:D,hasUnpublishedChanges:G,versionsEnabled:ee}=hd({config:y,initialData:t,collectionSlug:n,globalSlug:s,documentId:i,onChange:o,onActionSuccess:c,onActionError:m}),sr=useRef(null),no=useRef(null),[da,Ka]=useState(false),[Zn,gt]=useState("idle"),[h,re]=useState(Date.now()),Re=a,[Jt,Lt]=useState(false),[vr,ir]=useState(false),[es,Cc]=useState(0),ai=useRef(new Map),Sc=3e4;useEffect(()=>{let T=s?`global:${s}`:`${n}:${i}`;if(!(s||n&&i&&i!=="new")||t&&Object.keys(t).length>0)return;let Ne=ai.current.get(T),Te=Ne&&Date.now()-Ne.ts<Sc,bt=Ne&&!Te;if(Te){Le.getState().loadDocument(Ne.data,Ne.data);return}bt&&Le.getState().loadDocument(Ne.data,Ne.data);let xt=new AbortController;ir(false),Ne||Lt(true);let Mt=s?`/api/globals/${s}`:`/api/${n}/${i}`;return De(Mt,{autoToast:false,signal:xt.signal}).then(dt=>{let so=dt.data||{};ai.current.set(T,{data:so,ts:Date.now()}),Le.getState().loadDocument(so,so),Lt(false);}).catch(dt=>{dt.name!=="AbortError"&&(Lt(false),Ne||ir(true));}),()=>xt.abort()},[n,i,s,t,es]),useEffect(()=>{let T=setInterval(()=>re(Date.now()),1e4);return ()=>clearInterval(T)},[]);let ni=(T,J)=>{if(typeof T=="function")try{return T(v,J)}catch(Ne){return console.warn("Error evaluating admin runtime flag:",Ne),false}return !!T},Tc=T=>{b({title:"Restore Version",message:"Are you sure you want to restore this version? This will overwrite your current changes.",onConfirm:async()=>{try{let J=s?qe(`/api/globals/${s}/versions/${T}/restore`):qe(`/api/${n}/${v.id}/versions/${T}/restore`),Ne=await ct(J,{method:"POST"});!Ne.ok&&n&&(Ne=await ct(qe(`/api/${n}/${v.id}/versions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({versionId:T,action:"restore"})}));let Te=await Ne.json();if(Te.data){let{updatedAt:bt,createdAt:xt,...Mt}=Te.data,dt={...v,...Mt};vt(dt),Le.getState().loadDocument(dt,dt),c?.("Version restored successfully"),xe(),ie("edit");}else $.error(Te.error||"Failed to restore version");}catch(J){console.error("Failed to restore version:",J),$.error("Failed to restore version");}}});},Ac=async()=>{if(z.length===2){At(true);try{let J=await(await ct(qe(`/api/${n}/${v.id}/versions?compareA=${z[0]}&compareB=${z[1]}`))).json();Se(J.diffs||[]);}catch(T){console.error("Compare failed:",T),Se([]);}finally{At(false);}}},Rc=T=>{Ve(J=>J.includes(T)?J.filter(Ne=>Ne!==T):J.length>=2?[J[1],T]:[...J,T]);};useEffect(()=>{let T=J=>{(J.metaKey||J.ctrlKey)&&J.key==="s"&&(J.preventDefault(),si()),(J.metaKey||J.ctrlKey)&&J.shiftKey&&(J.key==="P"||J.key==="p")&&(J.preventDefault(),document.getElementById("btn-publish")?.click()),(J.metaKey||J.ctrlKey)&&!J.shiftKey&&J.key==="p"&&(J.preventDefault(),B(Ne=>!Ne)),document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA"&&(J.key==="1"&&ie("edit"),J.key==="2"&&ie("version"),J.key==="3"&&ie("api"));};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]),useEffect(()=>{let T=()=>ie("version");return window.addEventListener("kyro:show-version-history",T),()=>window.removeEventListener("kyro:show-version-history",T)},[]),useEffect(()=>{let T=J=>{sr.current&&!sr.current.contains(J.target)&&ce(false);};if(K)return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[K]),useEffect(()=>{let T=J=>{no.current&&!no.current.contains(J.target)&&Ka(false);};if(da)return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[da]);let Fc=()=>{L?b({title:"Unsaved Changes",message:"You have unsaved changes. Save before creating new?",onConfirm:async()=>{await si(),await new Promise(T=>setTimeout(T,1e3)),window.location.href=`${Ye}/${n}/new`;}}):window.location.href=`${Ye}/${n}/new`;},Pc=()=>{b({title:"Duplicate Document",message:"Are you sure you want to duplicate this document?",onConfirm:async()=>{try{let{id:T,createdAt:J,updatedAt:Ne,...Te}=v,bt=mr(Te),xt=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...bt,title:`${Te.title||Te.name||"Copy"} (Copy)`,slug:`${Te.slug||"copy"}-${Date.now()}`,status:"draft"})});if(xt.ok){let Mt=await xt.json();c?.("Document duplicated successfully"),Mt.data?.id&&(window.location.href=`${Ye}/${n}/${Mt.data.id}`);}else {let Mt=await xt.json();$.error(Mt.error||"Failed to duplicate document");}}catch{$.error("Failed to duplicate document");}}});},Dc=()=>{b({title:"Delete Document",message:"Delete this document? This cannot be undone. Are you absolutely sure?",variant:"danger",onConfirm:async()=>{try{await kt(`/api/${n}/${v.id}`),window.location.href=`${Ye}/${n}`;}catch(T){$.error(T.message||"Failed to delete document");}}});},Bc=()=>{b({title:"Unpublish Document",message:"Unpublish this document?",onConfirm:async()=>{try{let T=await we({...v,status:"draft"},!1);if(T?.ok)c?.("Document unpublished successfully"),Le.getState().loadDocument({...v,status:"draft"},{...v,status:"draft"});else {let J=await T?.json().catch(()=>({}));$.error(J?.error||"Failed to unpublish");}}catch{$.error("Failed to unpublish");}}});},si=async()=>{let T=!v.id;Qe.current=true,gt("saving");try{let J=mr({...v}),Ne=T&&!s,Te=Ne?await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J)}):await we(J);if(Te.ok){let xt=(await Te.json()).data||J;vt({...v,...xt}),X({...v,...xt}),Ct.current=Date.now(),le("success"),gt("saved"),ee&&xe(),setTimeout(()=>{le("idle"),gt("idle");},2e3),c?.(Ne?"Document created successfully":"Changes saved"),Ne&&setTimeout(()=>{window.location.href=`${Ye}/${n}`;},800);}else {let bt=await Te.json();Te.status===409&&le("conflict"),gt("error"),$.error(bt.error||"Failed to save"),setTimeout(()=>gt("idle"),3e3);}}catch{gt("error"),$.error("Failed to save document"),setTimeout(()=>gt("idle"),3e3);}finally{Qe.current=false;}},Ic=async()=>{let T=!v.id;Qe.current=true,gt("saving");try{let J={...v};if(T&&!s){let bt=mr({...v}),xt=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(bt)});if(!xt.ok){let so=await xt.json().catch(()=>({}));xt.status===409&&le("conflict"),gt("error"),$.error(so.error||"Failed to create document"),setTimeout(()=>gt("idle"),3e3);return}let dt=(await xt.json()).data||bt;vt({...v,...dt}),X({...v,...dt}),J={...v,...dt};}let Ne=mr(J),Te=await we(Ne,!1);if(Te?.ok)gt("saved"),c?.("Published successfully");else {let bt=await Te?.json().catch(()=>({}));Te?.status===409&&le("conflict"),gt("error"),$.error(bt?.error||"Failed to publish"),setTimeout(()=>gt("idle"),3e3);}}catch{gt("error"),$.error("Failed to publish"),setTimeout(()=>gt("idle"),3e3);}finally{Qe.current=false;}},Lc=async T=>{let J=!v.id;Qe.current=true;try{let Ne={...mr({...v}),_schedulePublishAt:T};if(J&&!s){let Te=await ct(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Ne)});if(!Te.ok){let bt=await Te.json().catch(()=>({}));$.error(bt.error||"Failed to schedule publish");return}}else {let Te=await we(Ne);if(!Te.ok){let bt=await Te.json().catch(()=>({}));$.error(bt.error||"Failed to schedule publish");return}}c?.(`Scheduled publish for ${new Date(T).toLocaleString()}`),Ka(!1);}catch{$.error("Failed to schedule publish");}finally{Qe.current=false;}},Mc=(T,J)=>{qt(T,J);},ca=(T,J,Ne)=>{let Te=J!==void 0?J:v;if(ni(T.hidden!==void 0?T.hidden:T.admin?.hidden,Te))return null;let xt=ni(T.readOnly!==void 0?T.readOnly:T.admin?.readOnly,Te),Mt=!!(Re||xt);if(T.admin?.condition){if(typeof T.admin.condition=="function")try{let Me={values:v||{},...v||{}};if(!T.admin.condition(Me,Te))return null}catch(Me){console.warn(`Condition error for field ${T.name}:`,Me);}else if(typeof T.admin.condition=="object")try{let Me=T.admin.condition,Ue=Me.field,Vt=Te&&Te[Ue]!==void 0?Te[Ue]:v&&v[Ue]!==void 0?v[Ue]:void 0,Cr=!0;if("equals"in Me?Cr=Vt===Me.equals:"notEquals"in Me?Cr=Vt!==Me.notEquals:"in"in Me&&Array.isArray(Me.in)&&(Cr=Me.in.includes(Vt)),!Cr)return null}catch(Me){console.warn(`Declarative condition error for field ${T.name}:`,Me);}}let dt=Te[T.name],so=r[T.name],Ga=Me=>{Ne?Ne({...Te,[T.name]:Me}):Mc(T.name,Me);};if(T.type==="row"&&"fields"in T){let Me=T.fields;return jsx("div",{className:"kyro-form-row flex flex-col md:flex-row gap-4 md:gap-6 items-start md:items-end w-full",children:Me?.map(Ue=>{let Vt=Ue.admin||{},Cr=Vt?.action;if((Ue.type==="button"||Ue.type==="action")&&Cr){let gr=Me?.find(pa=>pa.type==="email");return jsx("div",{className:"flex-shrink-0",children:jsx("button",{type:"button",onClick:async()=>{let pa=T.name,Wa=gr?.name,qa=Wa?v[Wa]:void 0;if(!qa&&pa&&typeof pa=="string"&&Wa&&(qa=v[pa]?.[Wa]),!!qa){Pe(br=>({...br,[Ue.name]:true}));try{let br=await ct(qe(Cr),{method:Vt.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:qa})}),ma={};try{ma=await br.json();}catch{ma={};}if(br.ok&&ma.success)c?.(ma.message||"Action completed successfully");else {let $c=ma.error||`Request failed (${br.status})`;m?.($c);}}catch(br){m?.(br instanceof Error?br.message:"Error connecting to server");}finally{Pe(br=>({...br,[Ue.name]:false}));}}},disabled:he[Ue.name]||Mt,className:"kyro-btn kyro-btn-primary px-4 py-2 rounded-lg font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:he[Ue.name]?"Sending...":Ue.label||"Click"})},Ue.name)}return jsx("div",{className:Ue.type==="button"||Ue.type==="action"?"flex-shrink-0":"flex-1",style:Vt?.width?{width:Vt.width,flex:"none"}:{},children:ca(Ue,J,Ne)},Ue.name)})},T.name||`row-${Math.random()}`)}switch(T.type){case "tabs":return jsx(Td,{field:T,formData:v,onTabDataChange:Me=>{qt(T.name,Me);},renderField:(Me,Ue,Vt)=>ca(Me,Ue,Vt)},T.name||`tabs-${Math.random()}`);case "group":return jsx(On,{field:T,value:dt,onChange:Ga,renderField:ca},T.name);case "array":return jsx(Un,{field:T,value:dt,onChange:Ga,renderField:ca,disabled:Mt},T.name);case "button":case "action":{let Me=T.name,Ue=he[Me];return jsx("div",{className:"kyro-form-field",children:jsxs("button",{type:"button",disabled:Ue||Mt,onClick:async()=>{let Vt=T.admin?.action||T.action,Cr=T.admin?.method||T.method||"POST";if(Vt){Pe(gr=>({...gr,[Me]:true}));try{let gr=await ct(Vt,{method:Cr,headers:{"Content-Type":"application/json"},body:JSON.stringify(v)});await gr.json(),gr.ok;}catch(gr){console.error("Error executing action:",gr);}finally{Pe(gr=>({...gr,[Me]:false}));}}},className:`kyro-btn kyro-btn-md kyro-btn-secondary transition-all active:scale-95 whitespace-nowrap flex items-center gap-2 ${Ue?"opacity-70 cursor-not-allowed":""}`,children:[Ue&&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:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),Ue?"Processing...":T.label||"Click"]})},Me)}case "relationship-block":return jsxs("div",{className:"kyro-form-field",children:[jsxs("label",{className:"kyro-form-label",children:[T.label||T.name,T.required&&jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsx(Ua,{relationTo:T.relationTo,hasMany:T.hasMany,selectedIds:Array.isArray(dt)?dt:dt?[dt]:[],onChange:(Me,Ue)=>{Ga(Ue);},compact:true}),T.admin?.description?jsx("p",{className:"kyro-form-help",children:String(T.admin?.description)}):null]},T.name);default:return jsx(xo,{field:T,value:dt,onChange:Ga,error:so,disabled:Mt},T.name||Math.random().toString())}};return Jt?jsxs("div",{className:"space-y-6 p-4",children:[jsxs("div",{className:"space-y-2",children:[jsx(Ot,{variant:"text",className:"w-1/3"}),jsx(Ot,{variant:"text",className:"w-2/3"})]}),jsx("div",{className:"space-y-4",children:jsx(Ot,{variant:"rect",count:4})})]}):vr?jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-16",children:[jsx(TriangleAlert,{className:"w-8 h-8 text-[var(--kyro-danger)]"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)]",children:"Failed to load document. Check your connection."}),jsx("button",{type:"button",onClick:()=>{ir(false),Lt(true),Cc(T=>T+1);},className:"kyro-btn kyro-btn-primary px-6 py-2 rounded-xl text-sm font-bold",children:"Retry"})]}):jsxs("div",{className:"flex flex-col h-full",children:[d!=="single"&&jsx(Fd,{collectionSlug:n,globalSlug:s,documentStatus:D||"draft",hasUnpublishedChanges:G,localSaveStatus:Zn,handleCreateNew:Fc,handleDuplicate:Pc,handleUnpublish:Bc,handleDelete:Dc,handlePublish:Ic,handleSchedulePublish:Lc}),d==="single"&&jsxs(Fragment,{children:[jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxs("div",{className:"flex items-center gap-3 text-[11px] font-medium",children:[N==="saving"&&jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Saving..."]}),N==="success"&&jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsx(Check,{className:"w-4 h-4"}),p?`Saved ${Math.floor((Date.now()-p)/6e4)}m ago`:"Saved"]}),N==="retrying"&&jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Retrying..."]}),N==="offline"&&jsx("span",{className:"text-[var(--kyro-text-muted)]",children:"Offline \u2014 cached locally"}),N==="error"&&jsx("span",{className:"text-[var(--kyro-danger)]",children:"Save failed"}),N==="conflict"&&jsx("span",{className:"text-[var(--kyro-danger)]",children:"Conflict detected"}),L&&N!=="saving"&&N!=="retrying"&&N!=="conflict"&&jsx("span",{className:"text-[var(--kyro-warning)]",children:"Unsaved changes"}),!L&&N!=="success"&&N!=="saving"&&N!=="error"&&jsx("span",{className:"text-[var(--kyro-success)]",children:"All changes saved"})]}),jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)] opacity-60",children:v.updatedAt?`Modified ${new Date(v.updatedAt).toLocaleString()}`:""})]}),jsx("button",{id:"btn-save",type:"button",style:{width:0,height:0,opacity:0,padding:0,margin:0,border:"none",position:"absolute"},onClick:async()=>{try{let T=await we(v);if(T.ok){let Ne=(await T.json()).data||v;vt({...v,...Ne}),X({...v,...Ne}),c?.("Changes saved");}}catch(T){console.error("Save error exception:",T),m?.("Save failed: "+T.message);}}})]}),jsxs("main",{className:"w-full pt-6 md:pt-0",children:[se==="edit"&&jsx(Pd,{config:y,layout:d,collectionSlug:n,renderField:ca}),se==="version"&&jsx(Dd,{handleRestoreVersion:Tc,handleCompareVersions:Ac,toggleCompareSelection:Rc}),se==="api"&&jsx(Bd,{collectionSlug:n,globalSlug:s})]})]})}var Ld={draft:"bg-[var(--kyro-warning)]",published:"bg-[var(--kyro-success)]",scheduled:"bg-[var(--kyro-primary)]",archived:"bg-[var(--kyro-text-muted)]"};function Xs({status:e,saveStatus:t,hasChanges:r,onSave:o,onPublish:a,onUnpublish:n,onDuplicate:s,onViewHistory:i,onPreview:l,onDelete:d,onBack:c,onToggleSidebar:m,publishedAt:u,updatedAt:g}){let x=Le(N=>N.view)||"edit",f=Le(N=>N.setView),[y,b]=useState(false),v=useRef(null);useEffect(()=>{let N=p=>{v.current&&!v.current.contains(p.target)&&b(false);};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);let R=()=>t==="saving"?"Saving...":t==="saved"?"Saved":t==="error"?"Error saving":r?"Unsaved":null,L=["edit","version","api"],C=R(),w="p-1.5 rounded-lg hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)] transition-all shrink-0";return 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&&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:jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${Ld[e]||"bg-[var(--kyro-text-muted)]"}`}),C&&jsxs("span",{className:`text-[10px] whitespace-nowrap max-md:hidden ${t==="error"?"text-[var(--kyro-error)]":"text-[var(--kyro-text-muted)]"}`,children:[t==="saving"&&jsx(Ar,{size:"sm",className:"inline mr-0.5"}),C]}),jsx("div",{className:"flex items-center gap-0.5 bg-[var(--kyro-bg-secondary)] p-0.5 rounded-lg border border-[var(--kyro-border)] shrink-0 max-md:hidden",children:L.map(N=>jsx("button",{type:"button",onClick:()=>f(N),className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all ${x===N?"bg-[var(--kyro-surface)] shadow-sm border border-[var(--kyro-border)] text-[var(--kyro-text-primary)]":"text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:N==="edit"?"Edit":N==="version"?"Ver":"API"},N))}),jsxs("div",{className:"flex items-center gap-1 ml-auto shrink-0",children:[l&&jsx("button",{type:"button",onClick:l,className:`${w} max-md:hidden`,title:"Preview",children:jsx(Eye,{className:"w-3.5 h-3.5"})}),i&&jsx("button",{type:"button",onClick:i,className:`${w} max-md:hidden`,title:"View History",children:jsx(Clock,{className:"w-3.5 h-3.5"})}),s&&jsx("button",{type:"button",onClick:s,className:`${w} max-md:hidden`,title:"Duplicate",children:jsx(Copy,{className:"w-3.5 h-3.5"})}),d&&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:jsx(Trash2,{className:"w-3.5 h-3.5"})}),m&&jsx("button",{type:"button",onClick:m,className:`${w} max-md:hidden`,title:"Toggle Sidebar",children:jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsxs("div",{ref:v,className:"relative md:hidden",children:[jsx("button",{type:"button",onClick:()=>b(!y),className:w,title:"More",children:jsx(EllipsisVertical,{className:"w-3.5 h-3.5"})}),y&&jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-lg shadow-xl z-50 py-1 max-h-[70vh] overflow-y-auto",children:[C&&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:[jsx("div",{className:`w-1.5 h-1.5 rounded-full ${Ld[e]}`}),jsx("span",{className:"capitalize",children:e}),jsx("span",{children:"\xB7"}),t==="saving"&&jsx(Ar,{size:"sm",className:"inline"}),jsx("span",{children:C})]}),jsx("div",{className:"flex gap-1 px-2 py-2 border-b border-[var(--kyro-border)]",children:L.map(N=>jsx("button",{type:"button",onClick:()=>{f(N),b(false);},className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all flex-1 ${x===N?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)]"}`,children:N==="edit"?"Edit":N==="version"?"Ver":"API"},N))}),i&&jsxs("button",{type:"button",onClick:()=>{i(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsx(Clock,{className:"w-3.5 h-3.5"})," View History"]}),s&&jsxs("button",{type:"button",onClick:()=>{s(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsx(Copy,{className:"w-3.5 h-3.5"})," Duplicate"]}),l&&jsxs("button",{type:"button",onClick:()=>{l(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-text-primary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:[jsx(Eye,{className:"w-3.5 h-3.5"})," Preview"]}),d&&jsx("div",{className:"border-t border-[var(--kyro-border)] mt-1 pt-1",children:jsxs("button",{type:"button",onClick:()=>{d(),b(false);},className:"w-full flex items-center gap-2 px-3 py-2 text-xs text-[var(--kyro-danger)] hover:bg-[var(--kyro-danger-bg)] transition-colors",children:[jsx(Trash2,{className:"w-3.5 h-3.5"})," Delete"]})})]})]}),jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),e==="draft"&&a&&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:[jsx(Send,{className:"w-3.5 h-3.5"}),jsx("span",{className:"max-md:hidden",children:"Publish"})]}),e==="published"&&n&&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:[jsx(Undo,{className:"w-3.5 h-3.5"}),jsx("span",{className:"max-md:hidden",children:"Unpublish"})]}),jsxs(Co,{status:e,saveStatus:t,hasChanges:r,onPublish:o,children:[s&&jsx(Ht,{icon:jsx(Copy,{className:"w-4 h-4"}),children:"Duplicate"}),i&&jsx(Ht,{icon:jsx(Clock,{className:"w-4 h-4"}),children:"View History"}),l&&jsx(Ht,{icon:jsx(Eye,{className:"w-4 h-4"}),children:"Preview"}),(s||i||l)&&jsx(ja,{}),d&&jsx(Ht,{onClick:d,danger:true,icon:jsx(Trash2,{className:"w-4 h-4"}),children:"Delete"})]})]})]})}function Ys({config:e,collection:t,global:r,documentId:o,onBack:a,onSave:n,onDelete:s,onError:i,mode:l="collection"}){let{confirm:d,alert:c}=ot(),[m,u]=useState({}),[g,x]=useState({}),[f,y]=useState(true),[b,v]=useState(false),[R,L]=useState("idle"),[C,w]=useState(false),[N,p]=useState("draft"),[A,O]=useState(null),[F,P]=useState(null),[S,M]=useState(null),[j,se]=useState(false),ie=r?.fields||t?.fields||[],ue=r?.label||t?.label||"Document",oe=r?.slug||t?.slug||"",ne=JSON.stringify(m)!==JSON.stringify(g);useEffect(()=>{ne&&N==="published"&&p("draft");},[ne,N]),useEffect(()=>{ne&&R==="saved"&&L("idle");},[ne,R]),useEffect(()=>{l==="global"?ft():o&&je();},[o,l,oe]);let je=async()=>{try{y(!0);let I=await De(`/api/${oe}/${o}`,{autoToast:!1}),z=I.data||{};u(z),x(z),p(z?.status||I.status||"draft"),O(I.createdAt||z.createdAt||null),P(I.updatedAt||z.updatedAt||null),M(I.publishedAt||z.publishedAt||null);}catch{i("Failed to load document");}finally{y(false);}},ft=async()=>{try{y(!0);let I=await De(`/api/globals/${oe}`,{autoToast:!1}),z=I.data||{};u(z),x(z),O(I.createdAt||null),P(I.updatedAt||null);}catch{i("Failed to load global");}finally{y(false);}},B=useCallback(async(I=false)=>{try{L("saving");let z=l==="global"?`/api/globals/${oe}`:`/api/${oe}/${o}`,Ve=N==="draft"||m?.status==="draft",ye=await Xt(z,m,{autoToast:!1,headers:{"X-Draft":String(Ve)}}),Se=ye&&(ye.data||ye)||m;I||(x(Se),n()),u(Se),p(Se?.status||N),L("saved"),P(new Date().toISOString()),se(!0),setTimeout(()=>se(!1),3e3),I||(N==="draft"||Se?.status==="draft"?$.warning("Draft saved"):$.success("Updated")),setTimeout(()=>{L("idle");},2e3);}catch{L("error"),I||(i("Failed to save changes"),$.error("Failed to save changes"));}finally{v(false);}},[m,l,oe,o,N,n,i]),K=async()=>{try{v(!0),await Xt(`/api/${oe}/${o}`,m,{autoToast:!1,headers:{"X-Draft":"false"}}),p("published"),M(new Date().toISOString()),$.success("Published successfully"),n();}catch{i("Failed to publish"),$.error("Failed to publish");}finally{v(false);}},ce=async()=>{try{v(!0),await Xt(`/api/${oe}/${o}`,{status:"draft"},{autoToast:!1,headers:{"X-Draft":"false"}}),p("draft"),$.warning("Document unpublished"),n();}catch{i("Failed to unpublish"),$.error("Failed to unpublish");}finally{v(false);}},he=async()=>{try{v(!0),await et(`/api/${oe}/${o}/duplicate`,void 0,{autoToast:!1}),$.success("Document duplicated");}catch(I){let z=I instanceof Error?I.message:"Failed to duplicate document";i(z),$.error(z);}finally{v(false);}},Pe=()=>{d({title:`Delete ${ue}?`,message:"This action cannot be undone.",variant:"danger",onConfirm:async()=>{try{w(!0),await kt(`/api/${oe}/${o}`,{autoToast:!1}),s?.(),$.error("Document deleted");}catch(I){let z=I instanceof Error?I.message:"Failed to delete document";$.error(z);}finally{w(false);}}});};if(f)return jsx("div",{className:"kyro-detail",children:jsxs("div",{className:"space-y-6 p-4",children:[jsxs("div",{className:"space-y-2",children:[jsx(Ot,{variant:"text",className:"w-1/3"}),jsx(Ot,{variant:"text",className:"w-2/3"})]}),jsx("div",{className:"space-y-4",children:jsx(Ot,{variant:"rect",count:4})})]})});let Ce=l==="global"||t?.admin?.layout==="single";return jsxs("div",{className:"kyro-detail",children:[jsx(Ft,{back:{onClick:a},breadcrumbs:[{label:l==="global"?"Globals":"Collections"},{label:ue,href:l==="collection"?`${Ye}/${oe}`:void 0},{label:l==="global"||o?"Edit":"New"}],title:l==="global"?ue:uo(t?.fields,m,t?.admin?.useAsTitle||"title")||m.name||o||`New ${t?.singularLabel||ue}`,metadata:[jsx(Pt,{variant:N==="published"?"success":"warning",dot:true,className:"text-[10px] font-bold ",children:N},"status")]}),jsx(Xs,{status:N,saveStatus:R,hasChanges:ne,onSave:()=>B(false),onPublish:K,onUnpublish:N==="published"?ce:void 0,onDuplicate:he,onViewHistory:()=>{window.dispatchEvent(new CustomEvent("kyro:show-version-history"));},onPreview:()=>window.open(`/preview/${oe}/${o}`,"_blank"),onDelete:Pe,onBack:a,onToggleSidebar:()=>window.dispatchEvent(new CustomEvent("toggle-sidebar")),publishedAt:S,updatedAt:F}),jsxs("div",{className:Ce?"w-full pt-4 md:pt-8":"w-full mx-auto grid grid-cols-1 lg:grid-cols-[1fr_360px] gap-4 md:gap-8 pt-4 md:pt-0",children:[jsx("div",{className:"space-y-4 md:space-y-8 min-w-0",children:jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsxs("div",{className:"flex items-center justify-between mb-8 px-1",children:[jsx("h2",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Core Configuration"}),jsx("div",{className:"h-px flex-1 bg-[var(--kyro-border)] ml-6 opacity-30"})]}),jsx(_a,{config:t?{...t,fields:ie}:{slug:"unknown",fields:ie},data:m,onChange:u,layout:Ce?"single":"split",globalSlug:l==="global"?oe:void 0,collectionSlug:l==="collection"?oe:void 0,onActionSuccess:I=>$.success(I),onActionError:I=>$.error(I),documentStatus:N,justSaved:j}),Ce&&jsxs("div",{className:"mt-8 pt-8 border-t border-[var(--kyro-border)] flex justify-end gap-3",children:[l==="collection"&&o&&jsx("button",{type:"button",onClick:Pe,className:"kyro-btn kyro-btn-lg kyro-btn-ghost text-[var(--kyro-error)]",children:"Delete"}),jsx(Co,{status:N,saveStatus:b?"saving":"idle",hasChanges:ne,onPublish:()=>B(false),disabled:b})]})]})}),!Ce&&jsxs("div",{className:"space-y-4 md:space-y-6 animate-in fade-in slide-in-from-right-4 duration-500",children:[jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4 md:mb-6",children:"Metadata"}),jsxs("div",{className:"space-y-4 md:space-y-6",children:[jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Dynamic Status"}),jsx("div",{children:jsx("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-[9px] font-bold tracking-widest ${N==="published"?"bg-green-500/10 text-green-500":"bg-amber-500/10 text-amber-500"}`,children:N||"draft"})})]}),jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Date Created"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:A?new Date(A).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"N/A"})]}),jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Last Modified"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:F?new Date(F).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"Just now"})]}),S&&jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Public At"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:new Date(S).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"})})]})]})]}),jsxs("div",{className:"surface-tile p-4 md:p-8 bg-[var(--kyro-bg-secondary)]",children:[jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-3 md:mb-4",children:"Quick Links"}),jsxs("div",{className:"space-y-2 md:space-y-3",children:[jsx("button",{type:"button",onClick:he,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"Duplicate Document"}),jsx("button",{type:"button",onClick:()=>window.open(`/preview/${oe}/${o}`,"_blank"),className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"View Public Page"}),jsx("button",{type:"button",onClick:Pe,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start text-[var(--kyro-error)] hover:bg-[var(--kyro-danger-bg)]",children:"Delete Entry"})]})]})]})]})]})}function Zs({config:e,collection:t,onCancel:r,onSuccess:o,onError:a}){let[n,s]=useState({}),[i,l]=useState(false),d=t.fields||[],c=t.label||t.slug,m=async u=>{try{l(!0),await et(`/api/${t.slug}`,n),$.success(`${t.singularLabel||t.label||"Document"} created`),o();}catch(g){a(g instanceof Error?g.message:"Failed to create");}finally{l(false);}};return jsxs("div",{className:"kyro-detail",children:[jsx(Ft,{back:{onClick:r},breadcrumbs:[{label:"Collections"},{label:c,href:`${Ye}/${t.slug}`},{label:"New"}],title:`Create ${t.singularLabel||c}`,action:{label:i?"Creating...":`Create ${t.singularLabel||c}`,onClick:()=>m()}}),jsx("div",{className:"kyro-detail-body",children:jsx("div",{className:"kyro-card",children:jsx("div",{className:"kyro-card-content",children:jsx("form",{children:jsx(_a,{config:{...t,fields:d},data:n,onChange:s})})})})})]})}function $d({type:e,message:t,onClose:r}){let[o,a]=ka.useState(false),n=ka.useRef(null),s=()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(r,5e3);},i=()=>{n.current&&clearTimeout(n.current);};ka.useEffect(()=>(o?i():s(),i),[o,r]);let l={success:CircleCheck,error:ShieldAlert,warning:TriangleAlert,info:Info}[e];return 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:[jsx("div",{className:"kyro-toast-accent"}),jsx("div",{className:"kyro-toast-icon-container",children:jsx(l,{className:"w-4 h-4"})}),jsx("div",{className:"kyro-toast-content",children:jsx("p",{className:"kyro-toast-message",children:t})}),jsx("button",{type:"button",className:"kyro-toast-close group-hover:opacity-100 opacity-40 transition-opacity",onClick:r,children:jsx(X,{className:"w-3.5 h-3.5"})})]})}function B4({children:e}){return jsx(Fragment,{children:e})}function I4(){let e=Kt(o=>o.addToast),t=Kt(o=>o.removeToast);return {toasts:Kt(o=>o.toasts),addToast:e,removeToast:t}}function Gn(){let e=Kt(r=>r.toasts),t=Kt(r=>r.removeToast);return jsx("div",{className:"kyro-toasts-container",style:{position:"fixed",bottom:"24px",right:"24px",display:"flex",flexDirection:"column",gap:"12px",zIndex:9999,pointerEvents:"none"},children:e.map(r=>jsx("div",{style:{pointerEvents:"auto"},children:jsx($d,{type:r.type,message:r.message,onClose:()=>t(r.id)})},r.id))})}function ri({onAuth:e,theme:t="light"}){let[r,o]=useState("login"),[a,n]=useState(""),[s,i]=useState(""),[l,d]=useState(""),[c,m]=useState(false),[u,g]=useState(false),x=Kt(b=>b.addToast);useEffect(()=>{f();},[]);let f=async()=>{try{await De("/api/users");}catch{g(true),o("register");}};return jsx(kr,{defaultMode:t,children:jsxs("div",{className:"kyro-login-page",children:[jsxs("div",{className:"kyro-login-container",children:[jsxs("div",{className:"kyro-login-header",children:[jsx("h1",{className:"kyro-login-title",children:u?"Create Admin Account":r==="login"?"Sign In":"Create Account"}),jsx("p",{className:"kyro-login-subtitle",children:u?"Set up your admin account to get started":r==="login"?"Enter your credentials to access the admin":"Create an account to access the admin"})]}),jsxs("form",{onSubmit:async b=>{b.preventDefault(),m(true);try{let v=r==="login"?"/api/auth/login":"/api/auth/register",R={email:a,password:s};r==="register"&&(R.confirmPassword=l);let L=await et(v,R);L.isFirstUser&&g(!0),localStorage.setItem("kyro_user",JSON.stringify(L.user)),x("success",r==="login"?"Welcome back!":"Account created!"),e(L.token,L.user);}catch{x("error","Connection failed");}finally{m(false);}},className:"kyro-login-form",children:[jsxs("div",{className:"kyro-form-group",children:[jsx("label",{htmlFor:"email",children:"Email"}),jsx("input",{id:"email",type:"email",value:a,onChange:b=>n(b.target.value),placeholder:"admin@example.com",required:true,autoComplete:"email"})]}),jsxs("div",{className:"kyro-form-group",children:[jsx("label",{htmlFor:"password",children:"Password"}),jsx("input",{id:"password",type:"password",value:s,onChange:b=>i(b.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:r==="login"?"current-password":"new-password"})]}),r==="register"&&jsxs("div",{className:"kyro-form-group",children:[jsx("label",{htmlFor:"confirmPassword",children:"Confirm Password"}),jsx("input",{id:"confirmPassword",type:"password",value:l,onChange:b=>d(b.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:"new-password"})]}),jsx("button",{type:"submit",className:"kyro-btn kyro-btn-primary kyro-btn-lg",disabled:c,children:c?r==="login"?"Signing in...":"Creating account...":r==="login"?"Sign In":"Create Account"})]}),!u&&jsx("div",{className:"kyro-login-footer",children:jsx("p",{children:r==="login"?jsxs(Fragment,{children:["Don't have an account?"," ",jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("register"),children:"Sign up"})]}):jsxs(Fragment,{children:["Already have an account?"," ",jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("login"),children:"Sign in"})]})})})]}),jsx(Gn,{})]})})}function Ud({collections:e,onNavigate:t,user:r}){let{permissions:o}=Lr(),[a,n]=useState({totalDocs:0,totalMedia:0,totalUsers:0,recentActivity:[]}),[s,i]=useState(true);useEffect(()=>{let d=setTimeout(()=>{n({totalDocs:124,totalMedia:856,totalUsers:12,recentActivity:[{id:1,type:"edit",user:"Daniel Dozie",doc:"Getting Started with Kyro",collection:"posts",time:"2m ago"},{id:2,type:"create",user:"Jane Smith",doc:"New Product Launch",collection:"products",time:"15m ago"},{id:3,type:"upload",user:"Daniel Dozie",doc:"hero-banner.jpg",collection:"media",time:"1h ago"},{id:4,type:"publish",user:"System",doc:"Weekly Update",collection:"posts",time:"3h ago"}]}),i(false);},800);return ()=>clearTimeout(d)},[]);let l=Object.entries(e).filter(([d])=>!As.includes(d)&&o?.collections?.[d]?.read!==false);return jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 px-8 pb-12",children:[jsx(Ft,{title:`Welcome back, ${r?.email?.split("@")[0]||"Admin"}`,description:"Everything looks great in your command center today.",action:l.length>0&&o?.collections?.[l[0]?.[0]]?.create!==false?{label:"New Document",onClick:()=>t("create",l[0]?.[0]),icon:Plus}:void 0}),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:FileText,color:"text-blue-500"},{label:"Media Assets",value:a.totalMedia,icon:Image,color:"text-purple-500"},{label:"Active Users",value:a.totalUsers,icon:Users,color:"text-green-500"},{label:"System Health",value:"100%",icon:Activity,color:"text-amber-500"}].map((d,c)=>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:[jsxs("div",{children:[jsx("p",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-1",children:d.label}),jsx("h3",{className:"text-3xl font-bold tracking-tighter",children:s?jsx(Ot,{variant:"text",className:"w-16"}):d.value})]}),jsx("div",{className:`p-3 rounded-2xl bg-[var(--kyro-bg-secondary)] group-hover:scale-110 transition-transform duration-500 ${d.color}`,children:jsx(d.icon,{className:"w-6 h-6"})})]},c))}),jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_400px] gap-8",children:[jsxs("div",{className:"space-y-8 min-w-0",children:[jsxs("section",{className:"surface-tile p-8",children:[jsxs("h2",{className:"text-xl font-bold mb-1 tracking-tight flex items-center gap-2",children:[jsx(LayoutDashboard,{className:"w-5 h-5 opacity-40"}),"Content Growth"]}),jsx("p",{className:"text-[10px] font-bold tracking-widest opacity-40 mb-8",children:"Snapshot of document velocity over the last 7 days"}),jsxs("div",{className:"h-48 w-full relative mb-12",children:[jsxs("svg",{className:"w-full h-full",viewBox:"0 0 1000 200",preserveAspectRatio:"none",children:[jsx("defs",{children:jsxs("linearGradient",{id:"chartGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[jsx("stop",{offset:"0%",stopColor:"var(--kyro-primary)",stopOpacity:"0.3"}),jsx("stop",{offset:"100%",stopColor:"var(--kyro-primary)",stopOpacity:"0"})]})}),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]"}),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)]"})]}),jsxs("div",{className:"flex justify-between mt-4 text-[10px] font-bold opacity-30 tracking-widest ",children:[jsx("span",{children:"Mon"}),jsx("span",{children:"Tue"}),jsx("span",{children:"Wed"}),jsx("span",{children:"Thu"}),jsx("span",{children:"Fri"}),jsx("span",{children:"Sat"}),jsx("span",{children:"Sun"})]})]}),jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:l.map(([d,c])=>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:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("h3",{className:"font-bold text-lg tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors",children:c.label||d}),jsx(ArrowUpRight,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-all"})]}),jsx("div",{className:"w-full h-1 bg-[var(--kyro-bg-secondary)] rounded-full mb-3 overflow-hidden",children:jsx("div",{className:"h-full bg-[var(--kyro-primary)]",style:{width:`${Math.random()*60+20}%`}})}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] line-clamp-1",children:c.admin?.description||`Manage ${d} content.`})]},d))})]}),jsxs("section",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[jsxs("section",{className:"surface-tile p-6 border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] transition-all cursor-pointer group",children:[jsx("div",{className:"flex items-center justify-between mb-4",children:jsxs("h3",{className:"text-xl font-bold tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors flex items-center gap-2",children:[jsx(Plus,{className:"w-5 h-5"}),"Quick Links"]})}),jsxs("div",{className:"space-y-3",children:[l.filter(([d])=>o?.collections?.[d]?.create!==false).map(([d])=>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:[jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:["New ",e[d]?.singularLabel||e[d]?.label||d]}),jsx(Plus,{className:"w-4 h-4 text-[var(--kyro-text-secondary)] group-hover/btn:text-[var(--kyro-primary)]"})]},d)),l.every(([d])=>o?.collections?.[d]?.create===false)&&jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] py-2",children:"No collections available for creation."})]})]}),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:[jsxs("div",{className:"relative z-10",children:[jsx("h3",{className:"text-2xl font-bold tracking-tighter mb-2",children:"Media Library"}),jsx("p",{className:"opacity-80 text-sm font-medium mb-6",children:"Manage high-fidelity assets with our liquid masonry gallery."}),jsxs("div",{className:"flex items-center gap-2 font-bold text-xs tracking-widest text-blue-400",children:["Open Assets"," ",jsx(ArrowRight,{className:"w-4 h-4 group-hover:translate-x-1 transition-transform"})]})]}),jsx(Image,{className:"absolute bottom-[-20px] right-[-20px] w-48 h-48 opacity-10 rotate-12 group-hover:scale-110 transition-transform duration-1000"})]})]})]}),jsxs("div",{className:"space-y-6",children:[jsxs("section",{className:"surface-tile p-8",children:[jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsx(Clock,{className:"w-5 h-5 opacity-40"}),"Recent Activity"]}),jsx("div",{className:"space-y-6",children:a.recentActivity.map(d=>jsxs("div",{className:"flex gap-4 group",children:[jsx("div",{className:"mt-1",children: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:jsx("span",{className:"text-[10px] font-bold",children:d.user[0]})})}),jsxs("div",{className:"flex-1 border-b border-[var(--kyro-border)] pb-4 group-last:border-none",children:[jsxs("p",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-snug",children:[jsx("span",{className:"font-bold",children:d.user})," ",d.type==="create"?"created":d.type==="edit"?"edited":d.type==="publish"?"published":"uploaded"," ",jsxs("span",{className:"text-[var(--kyro-primary)] italic",children:['"',d.doc,'"']})," ","in ",jsx("span",{className:"opacity-60",children:d.collection})]}),jsx("span",{className:"text-[10px] font-bold opacity-40 mt-1 block",children:d.time})]})]},d.id))}),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"})]}),jsxs("section",{className:"surface-tile p-8",children:[jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsx(Activity,{className:"w-5 h-5 opacity-40"}),"System Status"]}),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)=>jsxs("div",{className:"flex items-center justify-between p-4 bg-[var(--kyro-bg-secondary)] rounded-2xl border border-[var(--kyro-border)]",children:[jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-secondary)]",children:d.label}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:d.status}),jsx("div",{className:`w-2 h-2 rounded-full ${d.pulse} animate-pulse shadow-[0_0_8px] shadow-current`})]})]},c))})]})]})]})]})}function jd(){let[e,t]=useState([]),[r,o]=useState(true),[a,n]=useState(""),[s,i]=useState(false),[l,d]=useState({name:"",email:"",password:"",role:"customer"}),[c,m]=useState(""),[u,g]=useState(false),{confirm:x,alert:f}=ot();useEffect(()=>{y();},[]);let y=async()=>{try{o(!0);let w=await De("/api/users");t(w.docs||[]);}catch(w){console.error("Failed to load users:",w);}finally{o(false);}},b=w=>{let N=!w.locked;x({title:N?"Lock User Account?":"Unlock User Account?",message:N?`Are you sure you want to lock ${w.email}? They will be immediately logged out and unable to return.`:`Restore system access for ${w.email}?`,variant:N?"danger":"success",onConfirm:async()=>{try{await Xt(`/api/users/${w.id}`,{locked:N}),t(p=>p.map(A=>A.id===w.id?{...A,locked:N}:A)),$.success(N?`Account locked: ${w.email}`:`Account restored: ${w.email}`);}catch(p){console.error("Failed to toggle user lock:",p),$.error("Failed to update account status");}}});},v=w=>{x({title:"Destroy User Account",message:`You are about to permanently delete ${w.email}. This will remove all their data and cannot be undone.`,variant:"danger",confirmLabel:"Destroy Account",onConfirm:async()=>{try{await kt(`/api/users/${w.id}`),t(N=>N.filter(p=>p.id!==w.id)),$.success(`Identity purged: ${w.email}`);}catch(N){console.error("Failed to delete user:",N),$.error("Failed to delete user");}}});},R=async()=>{if(!l.email.trim()||!l.password.trim()){m("Email and password are required");return}g(true),m("");try{await et("/api/users",{name:l.name.trim()||void 0,email:l.email.trim(),password:l.password,role:l.role}),i(!1),d({name:"",email:"",password:"",role:"customer"}),$.success("User created successfully"),y();}catch(w){let N=w instanceof Error?w.message:"Failed to create user";m(N),$.error(N);}finally{g(false);}},L=["super_admin","admin","editor","author","customer","guest"],C=e.filter(w=>w.email.toLowerCase().includes(a.toLowerCase())||w.name?.toLowerCase().includes(a.toLowerCase()));return 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:[jsx(Ft,{title:"Identity & Access",description:"Manage the core administrative team and security permissions.",icon:Users,action:{label:"New User",onClick:()=>{d({name:"",email:"",password:"",role:"customer"}),m(""),i(true);},icon:UserPlus}}),jsxs("div",{className:"flex flex-col md:flex-row gap-3",children:[jsxs("div",{className:"relative flex-1 group",children:[jsx(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"}),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"})]}),jsxs("div",{className:"flex items-center gap-1 bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[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"}),jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"ADMINS"}),jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"LOCKED"})]})]}),jsx("div",{className:"surface-tile overflow-x-auto",children:jsxs("table",{className:"w-full text-left",children:[jsx("thead",{children: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:[jsx("th",{className:"px-6 py-4 w-64",children:"Member Identity"}),jsx("th",{className:"px-6 py-4",children:"Administrative Role"}),jsx("th",{className:"px-6 py-4",children:"Security Status"}),jsx("th",{className:"px-6 py-4",children:"Last Activity"}),jsx("th",{className:"px-6 py-4 w-32 text-right",children:"Actions"})]})}),jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:r?Array.from({length:6}).map((w,N)=>jsx("tr",{className:"animate-pulse",children:jsx("td",{colSpan:5,className:"px-6 py-5 bg-[var(--kyro-surface-accent)]/30"})},N)):C.length===0?jsx("tr",{children:jsx("td",{colSpan:5,className:"px-6 py-20 text-center",children:jsx("p",{className:"text-xs font-bold opacity-30 tracking-widest uppercase italic",children:"No identity matches found"})})}):C.map(w=>jsxs("tr",{className:`hover:bg-[var(--kyro-surface-accent)]/50 transition-colors group ${w.locked?"opacity-50 grayscale":""}`,children:[jsx("td",{className:"px-6 py-3.5",children:jsxs("div",{className:"flex items-center gap-3",children:[jsx(du,{user:w}),jsxs("div",{className:"min-w-0",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{className:"text-xs font-bold text-[var(--kyro-text-primary)] truncate",children:w.name||w.email.split("@")[0]}),w.tenantId&&jsx(Pt,{variant:"outline",className:"text-[7px] px-1 py-0 border-none bg-[var(--kyro-surface-accent)] opacity-50",children:w.tenantId})]}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:w.email})]})]})}),jsx("td",{className:"px-6 py-3.5",children:jsxs("div",{className:"flex items-center gap-2",children:[jsx(Shield,{className:"w-3.5 h-3.5 opacity-30"}),jsx("span",{className:"text-[10px] font-bold tracking-widest uppercase opacity-70",children:w.role})]})}),jsx("td",{className:"px-6 py-3.5",children:jsx(Pt,{variant:w.locked?"danger":"success",dot:true,className:"text-[8px] font-bold uppercase tracking-widest",children:w.locked?"Restricted":"Authorized"})}),jsx("td",{className:"px-6 py-3.5",children:jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold text-[var(--kyro-text-secondary)] opacity-50 uppercase tabular-nums",children:[jsx(Clock,{className:"w-3 h-3"}),w.lastLogin?new Date(w.lastLogin).toLocaleDateString():"Never"]})}),jsx("td",{className:"px-6 py-3.5 text-right",children:jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-all",children:[jsx("button",{onClick:()=>b(w),className:`p-1.5 rounded-lg border transition-all ${w.locked?"bg-green-500/10 text-green-500 border-green-500/20 hover:bg-green-500/20":"bg-amber-500/10 text-amber-500 border-amber-500/20 hover:bg-amber-500/20"}`,title:w.locked?"Restore Access":"Restrict Access",children:w.locked?jsx(LockOpen,{className:"w-3.5 h-3.5"}):jsx(Lock,{className:"w-3.5 h-3.5"})}),jsx("button",{onClick:()=>v(w),className:"p-1.5 rounded-lg border border-red-500/20 bg-red-500/10 text-red-500 hover:bg-red-500/20 transition-all",title:"Delete User",children:jsx(Trash2,{className:"w-3.5 h-3.5"})})]})})]},w.id))})]})}),jsxs(Ut,{open:s,onClose:()=>i(false),title:"Create User",size:"lg",children:[jsx(Or,{children:jsxs("div",{className:"space-y-6",children:[jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Name (optional)"}),jsx("input",{type:"text",value:l.name,onChange:w=>d({...l,name:w.target.value}),placeholder:"John Doe",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Email Address"}),jsx("input",{type:"email",value:l.email,onChange:w=>d({...l,email:w.target.value}),placeholder:"user@example.com",required:true,className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Password"}),jsx("input",{type:"password",value:l.password,onChange:w=>d({...l,password:w.target.value}),placeholder:"Minimum 12 characters",required:true,minLength:12,className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Role"}),jsx("select",{value:l.role,onChange:w=>d({...l,role:w.target.value}),className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]",children:L.map(w=>jsx("option",{value:w,children:w},w))})]}),c&&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:[jsx(TriangleAlert,{className:"w-4 h-4"}),c]})]})}),jsxs(Ur,{children:[jsx("button",{type:"button",onClick:()=>i(false),className:"px-6 py-2.5 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Cancel"}),jsx("button",{type:"button",onClick:R,disabled:u,className:"kyro-btn kyro-btn-primary px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10 disabled:opacity-50",children:u?"Creating...":"Create User"})]})]})]})}function du({user:e}){let[t,r]=useState(null);return useEffect(()=>{let o=e.avatar;typeof o=="string"&&/^[0-9a-f-]+$/i.test(o)&&De(`/api/media/${o}`).then(a=>r(a?.thumbnailUrl||a?.url||null)).catch(()=>r(null));},[e.avatar]),t?jsx("div",{className:"w-8 h-8 rounded-lg overflow-hidden border border-[var(--kyro-border)] flex-shrink-0",children:jsx("img",{src:t,alt:"",className:"w-full h-full object-cover"})}):jsx("div",{className:"w-8 h-8 rounded-lg bg-[var(--kyro-surface-accent)] border border-[var(--kyro-border)] flex items-center justify-center text-xs font-bold text-[var(--kyro-primary)] flex-shrink-0",children:e.name?e.name[0]:e.email[0].toUpperCase()})}function Hd(){let[e,t]=useState("Kyro CMS"),[r,o]=useState("Command Center"),[a,n]=useState("#6366f1"),[s,i]=useState("Welcome back to your Command Center."),[l,d]=useState(false),[c,m]=useState(false);return useEffect(()=>{(async()=>{try{let f=await De("/api/globals/site-settings"),y=f.data||f;y&&Object.keys(y).length>0&&(y.siteName&&t(y.siteName),y.adminTitle&&o(y.adminTitle),y.primaryColor&&n(y.primaryColor),y.dashboardGreeting&&i(y.dashboardGreeting));}catch(f){console.error("Failed to load branding:",f);}})();},[]),jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 pt-4",children:[jsxs("div",{children:[jsxs("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:["Branding ",jsx("span",{className:"text-[var(--kyro-primary)]",children:"Hub"})]}),jsx("p",{className:"text-[var(--kyro-text-secondary)] mt-1 font-medium opacity-60",children:"Customize the identity and aesthetic of your administrative ecosystem."})]}),jsx("div",{className:"flex items-center gap-3",children:jsxs("button",{type:"button",onClick:async()=>{d(true);try{await Xt("/api/globals/site-settings",{siteName:e,adminTitle:r,primaryColor:a,dashboardGreeting:s}),m(!0),$.success("Branding updated"),document.documentElement.style.setProperty("--kyro-primary",a),setTimeout(()=>window.location.reload(),800);}catch(x){$.error("Failed to save branding"),console.error(x);}finally{d(false);}},disabled:l,className:`flex items-center gap-2 px-8 py-3 rounded-2xl font-bold text-sm shadow-xl transition-all active:scale-95 ${c?"bg-green-500 text-white":"kyro-btn-primary hover:shadow-[var(--kyro-primary)]"}`,children:[l?jsx(RefreshCcw,{className:"w-4 h-4 animate-spin"}):c?jsx(Check,{className:"w-4 h-4"}):jsx(Save,{className:"w-4 h-4"}),l?"Saving...":c?"Identity Updated":"Publish Branding"]})})]}),jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsx(Tag,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Core Identity"})]}),jsxs("div",{className:"space-y-6",children:[jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Site Public Name"}),jsx("input",{type:"text",value:e,onChange:x=>t(x.target.value),className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all",placeholder:"e.g. Acme Corp CMS"})]}),jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Admin Dashboard Title"}),jsx("input",{type:"text",value:r,onChange:x=>o(x.target.value),className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all",placeholder:"e.g. Command Center"})]}),jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"System Greeting"}),jsx("textarea",{value:s,onChange:x=>i(x.target.value),rows:3,className:"w-full bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)] rounded-xl py-3 px-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)] transition-all resize-none",placeholder:"Greeting text for the dashboard..."})]})]})]}),jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsx(Palette,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Visual Aesthetic"})]}),jsxs("div",{className:"space-y-8",children:[jsxs("div",{className:"space-y-4",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Primary Brand Color"}),jsx("div",{className:"grid grid-cols-6 gap-3",children:[{name:"Indigo",hex:"#6366f1"},{name:"Emerald",hex:"#10b981"},{name:"Rose",hex:"#f43f5e"},{name:"Amber",hex:"#f59e0b"},{name:"Sky",hex:"#0ea5e9"},{name:"Violet",hex:"#8b5cf6"}].map(x=>jsx("button",{type:"button",onClick:()=>n(x.hex),className:`aspect-square rounded-xl transition-all border-4 ${a===x.hex?"border-white ring-2 ring-[var(--kyro-primary)]":"border-transparent opacity-60 hover:opacity-100"}`,style:{backgroundColor:x.hex},title:x.name},x.name))})]}),jsxs("div",{className:"space-y-4 pt-4 border-t border-[var(--kyro-border)]",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Project Logo (SVG/PNG)"}),jsxs("div",{className:"flex items-center gap-6",children:[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:[jsx(Image,{className:"w-6 h-6 mb-1 opacity-40"}),jsx("span",{className:"text-[8px] font-bold ",children:"Upload"})]}),jsxs("div",{className:"flex-1",children:[jsx("p",{className:"text-xs font-bold mb-1",children:"Upload global CMS logo"}),jsx("p",{className:"text-[10px] opacity-40 leading-relaxed",children:"This will replace the Kyro brand in the sidebar and login screens."})]})]})]})]})]}),jsxs("section",{className:"lg:col-span-2 surface-tile p-8 overflow-hidden relative group",children:[jsxs("div",{className:"absolute top-0 right-0 p-8 flex items-center gap-2 text-[var(--kyro-primary)]",children:[jsx(Sparkles,{className:"w-4 h-4"}),jsx("span",{className:"text-[10px] font-bold tracking-widest",children:"Live Preview"})]}),jsxs("div",{className:"max-w-2xl mx-auto py-12 text-center space-y-6",children:[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:[jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),jsxs("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:[r," Online"]})]}),jsxs("h2",{className:"text-5xl font-bold tracking-tighter leading-none italic",children:["Welcome to ",e,"."]}),jsx("p",{className:"text-xl font-medium text-[var(--kyro-text-secondary)] opacity-60",children:s})]}),jsx("style",{dangerouslySetInnerHTML:{__html:`
99
+ \`\`\``})}),!n&&jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs text-[var(--kyro-text-muted)]",children:[jsx("span",{children:"**bold**"}),jsx("span",{children:"*italic*"}),jsx("span",{children:"`code`"}),jsx("span",{children:"[link](url)"}),jsx("span",{children:"# heading"})]}),e.admin?.description&&!o&&jsx("p",{className:"kyro-form-help",children:e.admin.description}),o&&jsx("p",{className:"kyro-form-error",children:o})]}):jsxs("div",{className:"kyro-form-field",children:[jsxs("label",{className:"kyro-form-label",children:[e.label||e.name,e.required&&jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsx("div",{className:"h-[200px] bg-[var(--kyro-surface)] animate-pulse rounded-md border border-[var(--kyro-border)]"})]})};function Tn({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false),[i,l]=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 f=document.createElement("textarea");f.value=d,f.style.position="fixed",f.style.opacity="0",document.body.appendChild(f),f.select(),document.execCommand("copy"),document.body.removeChild(f),s(true),setTimeout(()=>s(false),1800);}},v=()=>{if(i||a)return;l(true);let f=new Uint8Array(32);crypto.getRandomValues(f);let b=Array.from(f).map(x=>x.toString(16).padStart(2,"0")).join("");r?.(b),setTimeout(()=>l(false),400);};return jsx(lt,{field:e,error:o,children:jsxs("div",{className:"flex items-center gap-1.5",children:[jsx("div",{className:"relative flex-1",children: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})}),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?jsx(Check,{className:"w-3.5 h-3.5 text-[var(--kyro-success)]"}):jsx(Copy,{className:"w-3.5 h-3.5"})}),jsx("button",{type:"button",onClick:v,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:jsx(RefreshCw,{className:`w-3.5 h-3.5 ${i?"animate-spin":""}`})})]})})}var Rn=null,Fl=false,Ss=async()=>(Rn&&Fl||(Rn=createStorage({driver:mm({dbName:"kyro-autosave",storeName:"autosave"})}),Fl=true),Rn),um=()=>typeof window>"u"?{getItem:async()=>null,setItem:async()=>{},removeItem:async()=>{}}:{getItem:async e=>{try{return await(await Ss()).getItem(e)??null}catch(t){return console.error("Storage getItem error:",t),localStorage.getItem(e)}},setItem:async(e,t)=>{try{await(await Ss()).setItem(e,t);}catch(r){console.error("Storage setItem error:",r),localStorage.setItem(e,t);}},removeItem:async e=>{try{await(await Ss()).removeItem(e);}catch(t){console.error("Storage removeItem error:",t),localStorage.removeItem(e);}}},Ee=create()(persist((e,t)=>({formData:{},lastSavedData:{},sidebarCollapsed:false,draftCache:{},dirtyFields:new Set,activeTab:0,isSlugLocked:true,view:"edit",isDropdownOpen:false,versions:[],loadingVersions:false,showPreview:false,isMenuOpen:false,hasUnsavedChanges:false,loadingFields:{},compareMode:false,compareSelected:[],compareDiffs:[],loadingDiffs:false,isAutoSaving:false,autoSaveStatus:"idle",backgroundProcessing:false,lastAutoSaveTime:0,lastSavedAt:null,retryCount:0,autoSaveSkip:false,autoSaveTimer:null,setField:(r,o)=>{let a=t(),n=new Set(a.dirtyFields);JSON.stringify(o)!==JSON.stringify(a.lastSavedData[r])?n.add(r):n.delete(r),e({formData:{...a.formData,[r]:o},dirtyFields:n,hasUnsavedChanges:n.size>0});},setFormData:r=>{e({formData:r});},setNestedField:(r,o)=>{e(a=>{let n=r.split("."),s={...a.formData},i=s;for(let l=0;l<n.length-1;l++)i[n[l]]===void 0&&(i[n[l]]={}),i[n[l]]={...i[n[l]]},i=i[n[l]];return i[n[n.length-1]]=o,{formData:s}});},setActiveTab:r=>e({activeTab:r}),setIsSlugLocked:r=>e(o=>({isSlugLocked:typeof r=="function"?r(o.isSlugLocked):r})),setView:r=>e({view:r}),setIsDropdownOpen:r=>e(o=>({isDropdownOpen:typeof r=="function"?r(o.isDropdownOpen):r})),setVersions:r=>e({versions:r}),setLoadingVersions:r=>e({loadingVersions:r}),setShowPreview:r=>e(o=>({showPreview:typeof r=="function"?r(o.showPreview):r})),setIsMenuOpen:r=>e(o=>({isMenuOpen:typeof r=="function"?r(o.isMenuOpen):r})),setHasUnsavedChanges:r=>e({hasUnsavedChanges:r}),setLoadingFields:r=>e(o=>({loadingFields:typeof r=="function"?r(o.loadingFields):r})),updateLoadingField:(r,o)=>e(a=>({loadingFields:{...a.loadingFields,[r]:o}})),setCompareMode:r=>e({compareMode:r}),setCompareSelected:r=>e(o=>({compareSelected:typeof r=="function"?r(o.compareSelected):r})),setCompareDiffs:r=>e({compareDiffs:r}),setLoadingDiffs:r=>e({loadingDiffs:r}),setIsAutoSaving:r=>e({isAutoSaving:r}),setAutoSaveStatus:r=>e({autoSaveStatus:r}),setBackgroundProcessing:r=>e({backgroundProcessing:r}),setSidebarCollapsed:r=>e({sidebarCollapsed:r}),setLastSavedAt:r=>e({lastSavedAt:r}),setRetryCount:r=>e({retryCount:r}),setAutoSaveSkip:r=>e({autoSaveSkip:r}),setLastAutoSaveTime:r=>e({lastAutoSaveTime:r}),startAutoSaveTimer:(r,o)=>{let{autoSaveTimer:a}=t();a&&clearTimeout(a);let n=setTimeout(r,o);e({autoSaveTimer:n});},clearAutoSaveTimer:()=>{let{autoSaveTimer:r}=t();r&&(clearTimeout(r),e({autoSaveTimer:null}));},markSaved:()=>{let{formData:r}=t();e({lastSavedData:r,hasUnsavedChanges:false,dirtyFields:new Set,lastSavedAt:Date.now()});},setLastSavedData:r=>{e({lastSavedData:r});},resetForm:()=>{e({formData:{},lastSavedData:{},hasUnsavedChanges:false,dirtyFields:new Set,activeTab:0});},loadDocument:(r,o)=>{let a=t();a.formData===r&&a.lastSavedData===(o||r)&&!a.hasUnsavedChanges||e({formData:r,lastSavedData:o||r,hasUnsavedChanges:false,dirtyFields:new Set});},getField:r=>t().formData[r],getNestedField:r=>{let o=r.split("."),a=t().formData;for(let n of o){if(a==null)return;a=a[n];}return a},getHasChanges:()=>t().dirtyFields.size>0,hasDirtyFields:()=>t().dirtyFields.size>0,getDirtyData:()=>{let{formData:r,dirtyFields:o}=t(),a={};for(let n of o)a[n]=r[n];return a},clearDirtyFields:()=>{e({dirtyFields:new Set,hasUnsavedChanges:false});},pruneExpiredDrafts:()=>{let o=Date.now(),{draftCache:a}=t(),n={};for(let[s,i]of Object.entries(a))o-new Date(i.draftUpdatedAt).getTime()<6048e5&&(n[s]=i);e({draftCache:n});},setDraftCache:(r,o)=>e(a=>({draftCache:{...a.draftCache,[r]:o}})),getDraftCache:r=>t().draftCache[r]||null,clearDraftCache:r=>e(o=>{let a={...o.draftCache};return delete a[r],{draftCache:a}})}),{name:"kyro-autoform-storage",storage:createJSONStorage(()=>um()),partialize:e=>({sidebarCollapsed:e.sidebarCollapsed,draftCache:e.draftCache}),onRehydrateStorage:()=>e=>{e&&e.pruneExpiredDrafts();}}));function An(e){return e?e.toString().toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function Ho({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.variant==="textarea",i=e.name==="slug",{isSlugLocked:l,setIsSlugLocked:d,formData:c}=Ee(),m=e.variant==="email"?"email":e.variant==="password"?"password":e.variant==="url"?"url":"text",v=t==null?"":String(t),f={id:e.name,value:v,onChange:b=>r?.(b.target.value),placeholder:e.admin?.placeholder,disabled:a||n||i&&l,minLength:e.minLength,maxLength:e.maxLength,required:e.required,className:`kyro-form-input ${i?"pr-24":""} ${a||n||i&&l?"opacity-70 bg-[var(--kyro-bg-secondary)] cursor-not-allowed":""}`};return jsx(lt,{field:e,error:o,children:jsxs("div",{className:"relative",children:[s?jsx("textarea",{...f,rows:e.rows||4}):jsx("input",{type:m,...f,pattern:e.pattern}),i&&jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:[!l&&jsx("button",{type:"button",onClick:()=>r?.(An(c[e.admin?.autoGenerate||"title"]||"")),className:"p-1 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)]",title:"Regenerate slug",children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsx("path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"}),jsx("path",{d:"M21 3v5h-5"})]})}),jsx("button",{type:"button",onClick:()=>d(!l),className:`p-1.5 rounded transition-colors ${l?"text-[var(--kyro-primary)] bg-[var(--kyro-primary-alpha)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)]"}`,title:l?"Unlock slug":"Lock slug",children:l?jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}):jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]})})]}),e.name?.toLowerCase().includes("metatitle")&&jsx("div",{className:"flex items-center justify-between mt-1 text-[10px] font-bold tracking-wider",children:jsxs("span",{className:v.length>60?"text-red-500":v.length>=40?"text-green-500":"text-amber-600",children:[v.length," / 60 \u2014 ",v.length>60?"Too Long":v.length>=40?"Ideal":"Short"]})})]})})}function Fn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsx(lt,{field:e,error:o,children: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 Pn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsx(lt,{field:e,error:o,hideLabel:true,children:jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer group py-0.5",children:[jsx("input",{type:"checkbox",checked:t??false,onChange:i=>r?.(i.target.checked),disabled:a||n,className:`w-4 h-4 rounded border-[var(--kyro-border)] text-[var(--kyro-primary)] focus:ring-[var(--kyro-primary)] transition-all ${a||n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`}),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&&jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]})]})})}function Dn({field:e,value:t="",onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly;return jsx(lt,{field:e,error:o,children: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 Da(e){return e?Array.isArray(e)?e:Object.values(e):[]}function Bn(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Ln(e){return e.reduce((t,r)=>(r.slug&&(t[r.slug]=r),t),{})}function Pa(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 fm={pages:"FileText",posts:"Newspaper",categories:"Tags",menu:"Menu",products:"ShoppingBag",customers:"Users",orders:"ShoppingCart",coupons:"Ticket",forms:"FileInput","form-entries":"Inbox"};function go(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 go(s.fields,n,r);if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&go(l.fields,n,r))return true;return false}if(s.type==="blocks"&&s.blocks&&Array.isArray(s.blocks)){let l=n.split(".")[0],d=n.split(".").slice(1).join(".");if(!d)return false;for(let c of s.blocks)if(c.slug===l&&c.fields&&Array.isArray(c.fields))return go(c.fields,d,r);return false}return s.type==="array"&&s.fields&&Array.isArray(s.fields)?go(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)&&go(s.fields,t,r))return true;if(s.type==="tabs"&&s.tabs&&Array.isArray(s.tabs)){for(let l of s.tabs)if(l.fields&&Array.isArray(l.fields)&&go(l.fields,t,r))return true}}}return false}function vm(e,t){for(let[r,o]of Object.entries(e)){let a=fm[r],n=t?.[r];if(a&&!o.admin?.icon&&(o.admin={...o.admin,icon:a}),n){let{fields:s,...i}=n;if(o.admin={...o.admin,...i},s&&o.fields&&Array.isArray(o.fields))for(let[l,d]of Object.entries(s))go(o.fields,l,d);}}}function gm(e="blog"){let t=[],r=[];switch(e){case "minimal":t.push(...Object.values(minimalCollections)),r.push(...coreSettingsGlobals);break;case "starter":t.push(...Object.values(starterCollections)),r.push(...coreSettingsGlobals);break;case "blog":t.push(...Object.values(blogCollections)),r.push(...coreSettingsGlobals);break;case "ecommerce":t.push(...Object.values(ecommerceCollections)),r.push(...allSettingsGlobals);break;case "kitchen-sink":t.push(...Object.values(minimalCollections),...Object.values(starterCollections),...Object.values(blogCollections),...Object.values(ecommerceCollections),...Object.values(kitchenSinkCollections)),r.push(...allSettingsGlobals);break}return Pa(t,Object.values(mediaCollections)),Pa(t,Object.values(authCollections)),{collections:Bn(t),globals:Ln(r)}}function bm(e){let t=Da(e.collections),r=Da(e.globals);if(t.length===0&&r.length===0)return gm("kitchen-sink");let o=[];return Pa(o,Object.values(mediaCollections)),Pa(o,Object.values(authCollections)),Pa(o,t),{collections:Bn(o),globals:Ln(r)}}var In=null;function xm(){if(In)return In;try{if(typeof __KYRO_ADMIN_CONFIG_FILE__=="string"&&Po.existsSync(__KYRO_ADMIN_CONFIG_FILE__))return In=JSON.parse(Po.readFileSync(__KYRO_ADMIN_CONFIG_FILE__,"utf8")),In}catch{}return null}var jl=xm()||{collections:[],globals:[]},_l=bm(jl);vm(_l.collections,jl.collectionOverrides);var Hl=_l,Vo=Hl.collections,Vl=Hl.globals,As=["users","audit_logs"];Object.values(Vo).filter(e=>!As.includes(e.slug)&&e.admin?.hidden!==true);function Mn({field:e,value:t,onChange:r,error:o,disabled:a}){let n=typeof e.admin?.readOnly=="function"?false:!!e.admin?.readOnly,s=e.options||[];return e.dynamicOptions==="collections"&&(s=Object.keys(Vo).filter(i=>i!=="media").map(i=>({label:Vo[i]?.label||i,value:i}))),jsx(lt,{field:e,error:o,children:jsxs("select",{id:e.name,value:e.hasMany?Array.isArray(t)?t:[]:t||"",onChange:i=>{if(e.hasMany){let l=Array.from(i.target.selectedOptions,d=>d.value);r?.(l);}else r?.(i.target.value||void 0);},multiple:e.hasMany,disabled:a||n,required:e.required,className:`kyro-form-input ${a||n?"opacity-50 cursor-not-allowed":""}`,children:[!e.required&&!e.hasMany&&jsx("option",{value:"",children:"Select..."}),s.map(i=>jsx("option",{value:i.value,children:i.label},i.value))]})})}function En({icon:e,title:t,description:r,action:o}){return jsxs("div",{className:"flex flex-col items-center gap-3 justify-center py-16 px-8",children:[e&&jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--kyro-surface-accent)] flex items-center justify-center mb-4",children:e}),jsx("p",{className:"font-medium text-[var(--kyro-text-primary)] text-base",children:t}),r&&jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] mt-1",children:r}),o]})}function Ls(e){let t=e?.mainTabs;return e?.title||t?.title||e?.name||e?.label||e?.email||e?.filename||e?.slug||"Untitled"}function Dm({id:e,label:t,relation:r,onRemove:o,disabled:a}){let{attributes:n,listeners:s,setNodeRef:i,transform:l,transition:d,isDragging:c}=useSortable({id:e}),m={transform:CSS.Transform.toString(l),transition:d,zIndex:c?10:1,opacity:c?.8:1};return jsxs("span",{ref:i,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&&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:jsx(GripVertical,{className:"w-2.5 h-2.5"})}),r&&jsxs("span",{className:"opacity-60 mr-0.5",children:[r,":"]}),t,!a&&jsx("button",{type:"button",onClick:o,className:"hover:opacity-70 p-0.5 ml-0.5 flex items-center justify-center",children:jsx(X,{className:"w-3 h-3"})})]})}function Im({field:e,value:t,onChange:r,error:o,disabled:a}){let[n,s]=useState(false),[i,l]=useState(""),[d,c]=useState([]),[m,v]=useState(false),[f,b]=useState([]),x=useRef(new Set),g=useRef(null),y=useRef(()=>{});y.current=r||(()=>{});let u=e.hasMany,N=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],R=N.length>1,[S,h]=useState(N[0]||""),C=useCallback(()=>t?(u?Array.isArray(t)?t:[]:t?[t]:[]).map(W=>typeof W=="object"&&W!==null?W.value||W.id||"":String(W)).filter(Boolean):[],[t,u]),p=useCallback(O=>{O.length!==0&&O.forEach(W=>{if(x.current.has(W))return;x.current.add(W);let se=R?(()=>{if(!t)return S;let K=(u?Array.isArray(t)?t:[]:[t]).find(Ne=>typeof Ne=="object"&&Ne!==null?Ne.value===W||Ne.id===W:false);return K&&typeof K=="object"&&K.relationTo||S})():S;Be(`/api/${se}/${W}`).then(X=>{let K=X.data||X;!K||typeof K!="object"||b(Ne=>Ne.some(Re=>Re.id===W)?Ne:[...Ne,{...K,id:String(K.id),relationTo:se}]);}).catch(()=>{});});},[R,t,S,u]);useEffect(()=>{let O=C();p(O);},[C,p]);let P=useCallback((O="")=>{v(true);let se=`/api/${S}?${Qa(O,["title","name","label","email"])}`;Be(se).then(X=>{c(K=>{let Ne=new Set(K.map(T=>T.id)),Re=(X.docs||[]).filter(T=>!Ne.has(T.id)).map(T=>({...T,id:T.id}));return [...K,...Re]}),v(false);}).catch(()=>{v(false);});},[S]);useEffect(()=>{n&&(c([]),P(i));},[n,S]),useEffect(()=>{let O=W=>{g.current&&!g.current.contains(W.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),D=O=>{let W=O.id;return t?u&&Array.isArray(t)?t.some(se=>M(se)===W):M(t)===W:false},I=O=>{let W=O.id;if(u){let se=Array.isArray(t)?t:[];if(D(O))y.current?.(se.filter(X=>M(X)!==W));else {let X=R?{relationTo:S,value:W}:W;y.current?.([...se,X]);}}else if(D(O))y.current?.(null);else {let se=R?{relationTo:S,value:W}:W;y.current?.(se),s(false),l("");}},A=useSensors(useSensor(PointerSensor,{activationConstraint:{distance:3}})),re=O=>{let{active:W,over:se}=O;if(!se||W.id===se.id)return;let X=u?Array.isArray(t)?t:[]:[],K=X.findIndex(Re=>M(Re)===W.id),Ne=X.findIndex(Re=>M(Re)===se.id);if(K!==-1&&Ne!==-1){let Re=[...X],[T]=Re.splice(K,1);Re.splice(Ne,0,T),y.current?.(Re);}},me=()=>{if(!t)return null;let O=u?Array.isArray(t)?t:[]:t?[t]:[],W=O.map(se=>M(se));return u&&O.length>1?jsx(DndContext,{sensors:A,collisionDetection:closestCenter,onDragEnd:re,children:jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:jsx(SortableContext,{items:W,strategy:horizontalListSortingStrategy,children:O.map(se=>{let X=M(se),K=f.find(T=>T.id===X),Ne=K?Ls(K):X.slice(0,12),Re=R&&K?K.relationTo:null;return jsx(Dm,{id:X,label:Ne,relation:Re,onRemove:()=>{let T=O.filter(_=>M(_)!==X);y.current?.(T);},disabled:a},X)})})})}):jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:O.map(se=>{let X$1=M(se),K=f.find(T=>T.id===X$1),Ne=K?Ls(K):X$1.slice(0,12),Re=R&&K?K.relationTo:null;return 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:[Re&&jsxs("span",{className:"opacity-60 mr-0.5",children:[Re,":"]}),Ne,!a&&jsx("button",{type:"button",onClick:()=>{let T=O.filter(_=>M(_)!==X$1);y.current?.(u?T:T[0]??null);},className:"hover:opacity-70 flex items-center justify-center",children:jsx(X,{className:"w-3 h-3"})})]},X$1)})})};return jsxs("div",{className:"space-y-1.5",children:[e.label&&jsxs("label",{className:"block text-sm font-medium text-[var(--kyro-text-primary)]",children:[e.label,e.required&&jsx("span",{className:"text-[var(--kyro-error)] ml-1",children:"*"})]}),jsxs("div",{ref:g,className:"relative",children:[R&&jsx("div",{className:"flex gap-1 mb-1.5",children:N.map(O=>jsx("button",{type:"button",onClick:()=>{h(O),c([]),l("");},className:`px-2 py-0.5 text-[10px] font-bold rounded transition-colors ${S===O?"kyro-btn-primary":"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-border)]"}`,children:O},O))}),jsxs("div",{className:"relative",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",value:i,onChange:O=>{l(O.target.value),s(true),P(O.target.value);},onFocus:()=>s(true),placeholder:e.admin?.placeholder||`Search ${S}...`,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"}),jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:m?jsx(LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"}):jsx(ChevronDown,{className:`w-4 h-4 text-[var(--kyro-text-muted)] transition-transform ${n?"rotate-180":""}`})})]}),n&&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?jsx("div",{className:"p-4 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):d.length===0?jsx(En,{title:"No results found"}):jsx("div",{className:"py-1",children:d.map(O=>jsxs("button",{type:"button",onClick:()=>I(O),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors ${D(O)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:Ls(O)}),D(O)&&jsx("span",{className:"text-[var(--kyro-sidebar-active)]",children:"\u2713"})]}),"slug"in O&&typeof O.slug=="string"&&jsx("div",{className:"text-xs text-[var(--kyro-text-muted)]",children:O.slug})]},O.id))})}),me()]}),e.admin?.description&&!o&&jsx("p",{className:"text-xs text-[var(--kyro-text-muted)]",children:e.admin.description}),o&&jsx("p",{className:"text-xs text-[var(--kyro-error)]",children:o})]})}var Ia=Im;var bo=createContext(null);function Gl(e=[],t=[]){return createStore((r,o)=>({blocks:[],allowedBlocks:e,dynamicCategories:t,setBlocks:a=>{let n=Ms(a||[]);r({blocks:n});},onBlocksChange:null,setOnBlocksChange:a=>r({onBlocksChange:a}),addBlock:(a,n)=>{let s=Go(a),{blocks:i}=o(),l=[...i];n!==void 0?l.splice(n,0,s):l.push(s),r({blocks:l});let{onBlocksChange:d}=o();d&&d();},updateBlock:(a,n)=>{let{blocks:s}=o(),i=Ba(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=[...l];return c[d]={...c[d],...n},{newList:c,found:true}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}},removeBlock:a=>{if(!a)return;let{blocks:n}=o(),s=Ba(n,i=>{let l=i.filter(d=>d.id!==a);return l.length!==i.length?{newList:l,found:true}:{newList:i,found:false}});if(s!==n){r({blocks:s});let{onBlocksChange:i}=o();i&&i();}},moveBlock:(a,n)=>{let{blocks:s}=o(),i=Ba(s,l=>{let d=l.findIndex(c=>c.id===a);if(d!==-1){let c=n==="up"?d-1:d+1;if(c>=0&&c<l.length){let m=[...l];return [m[d],m[c]]=[m[c],m[d]],{newList:m,found:true}}}return {newList:l,found:false}});if(i!==s){r({blocks:i});let{onBlocksChange:l}=o();l&&l();}}}))}function Ms(e){return Array.isArray(e)?e.map(t=>{let r={...t,id:t.id||Math.random().toString(36).substr(2,9)};return r.children&&Array.isArray(r.children)&&(r.children=Ms(r.children)),r.data?.columnData&&Array.isArray(r.data.columnData)&&(r.data={...r.data,columnData:r.data.columnData.map(o=>({...o,children:o.children?Ms(o.children):o.children}))}),r}):[]}function Go(e){let t=Em(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 Em(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 Ue(e){let t=useContext(bo);if(t)return useStore(t,r=>{let o=a=>{for(let n of a){if(n.id===e)return n;if(n.children&&n.children.length>0){let s=o(n.children);if(s)return s}if(n.data?.columnData){for(let s of n.data.columnData)if(s&&s.children&&s.children.length>0){let i=o(s.children);if(i)return i}}}};return o(r.blocks)})}function Le(){let e=useContext(bo);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 Ba(e,t){let{newList:r,found:o}=t(e);if(o)return r;let a=false,n=e.map(s=>{let i={...s},l=false;if(s.children&&s.children.length>0){let d=Ba(s.children,t);d!==s.children&&(i.children=d,l=true);}if(s.data?.columnData&&Array.isArray(s.data.columnData)){let d=s.data.columnData.map(c=>{if(c.children&&c.children.length>0){let m=Ba(c.children,t);if(m!==c.children)return {...c,children:m}}return c});d.some((c,m)=>c!==s.data.columnData[m])&&(i.data={...i.data,columnData:d},l=true);}return l&&(a=true),l?i:s});return a?n:e}function Ma({open:e,onClose:t,onSelect:r,children:o}){return e?jsxs(cr,{open:e,onClose:t,title:"Insert Block",width:"md",children:[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 Wl({block:e,onSelect:t,children:r}){let{attributes:o,listeners:a,setNodeRef:n,isDragging:s}=useDraggable({id:`drawer-${e.type}`,data:{source:"drawer",blockType:e.type}});return 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:[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||jsx("span",{className:"text-[var(--kyro-text-muted)]"})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)] leading-tight",children:e.label}),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})=>jsx("div",{className:r?"":"space-y-3",children: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 xo=({id:e,type:t,label:r,children:o,className:a=""})=>{let{moveBlock:n,removeBlock:s}=Le();return 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:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] tracking-wider",children:r||t}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[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:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),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:jsx(ChevronRight,{className:"w-3 h-3"})}),jsx("button",{type:"button",onClick:()=>s(e),className:"p-1 hover:bg-[var(--kyro-error)]/10 rounded text-[var(--kyro-error)]",title:"Remove",children:jsx(X,{className:"w-3 h-3"})})]})]}),jsx("div",{className:"block-content",children:o})]})};var Xl=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsx(xo,{id:e.id,type:"heading",label:"Heading",children:jsx($s,{text:a.text||"",onChange:n,compact:true})})};var Yl=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsx(xo,{id:e.id,type:"paragraph",label:"Paragraph",children: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 Zl=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-image border border-[var(--kyro-border)] rounded-lg p-4 mb-4 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Image"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>a(e.id),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Remove",children:jsx(X,{className:"w-3 h-3"})})]})]}),jsxs("div",{className:"space-y-3",children:[jsxs("div",{children:[jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Image Asset"}),jsx(dr,{field:{label:"Image Asset",name:"src",maxCount:1},value:s.src,onChange:l=>i("src",l)})]}),jsxs("div",{children:[jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Alt Text"}),jsx("input",{type:"text",value:s.alt||"",onChange:l=>i("alt",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Alternative text..."})]}),jsxs("div",{children:[jsx("label",{className:"text-xs font-medium text-[var(--kyro-text-muted)] mb-1 block",children:"Caption"}),jsx("input",{type:"text",value:s.caption||"",onChange:l=>i("caption",l.target.value),className:"w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-surface)] text-[var(--kyro-text-primary)] text-sm",placeholder:"Image caption..."})]})]})]})};var Us=({src:e="",title:t="",onChange:r,onUploadChange:o,compact:a=false})=>{e.includes("youtube.com")||e.includes("vimeo.com")||e.includes("youtu.be");return a?jsxs("div",{className:"space-y-2",children:[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..."}),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)..."})]}):jsxs("div",{className:"space-y-3",children:[jsx(dr,{field:{label:"Video Asset",name:"src",maxCount:1},value:e,onChange:o||(s=>r("src",s))}),jsx("span",{className:"text-xs text-[var(--kyro-text-muted)]",children:"or paste a URL"}),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..."}),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 td=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-video border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Video"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(Us,{src:s.src||"",title:s.title||"",onChange:i,onUploadChange:l=>i("src",l),compact:true})]})};function Wm({id:e,text:t,onRemove:r}){let{attributes:o,listeners:a,setNodeRef:n,transform:s,transition:i,isDragging:l}=useSortable({id:e}),d={transform:CSS.Transform.toString(s),transition:i,zIndex:l?10:1,opacity:l?.8:1};return 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 ${l?"bg-[var(--kyro-surface-accent)] shadow-sm":""}`,children:[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:jsx(GripVertical,{className:"w-3.5 h-3.5"})}),jsxs("span",{className:"text-sm text-[var(--kyro-text-primary)] flex-1",children:["\u2022 ",t]}),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 Ea=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=wa.useState(""),[n,s]=wa.useState([]);wa.useEffect(()=>{let f=n.map(b=>b.text);JSON.stringify(f)!==JSON.stringify(e)&&s(e.map((b,x)=>({id:`${b}-${x}-${Math.random().toString(36).substr(2,4)}`,text:b})));},[e]);let i=()=>{o.trim()&&(t([...e,o.trim()]),a(""));},l=f=>{f.key==="Enter"&&(f.preventDefault(),i());},d=f=>{t(e.filter((b,x)=>x!==f));},c=useSensors(useSensor(PointerSensor,{activationConstraint:{distance:3}})),m=f=>{let{active:b,over:x}=f;if(!x||b.id===x.id)return;let g=n.findIndex(u=>u.id===b.id),y=n.findIndex(u=>u.id===x.id);if(g!==-1&&y!==-1){let u=[...e],[N]=u.splice(g,1);u.splice(y,0,N),t(u);}},v=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 jsx(DndContext,{sensors:c,collisionDetection:closestCenter,onDragEnd:m,children:jsxs("div",{className:r?"space-y-1.5":"space-y-2",children:[e.length===0?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."}):jsx(SortableContext,{items:n.map(f=>f.id),strategy:verticalListSortingStrategy,children:jsx("div",{className:"space-y-1",children:n.map((f,b)=>jsx(Wm,{id:f.id,text:f.text,onRemove:()=>d(b)},f.id))})}),jsx("input",{type:"text",value:o,onChange:f=>a(f.target.value),onKeyDown:l,className:v,placeholder:"Type and press Enter to add..."})]})})};var rd=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},i=Array.isArray(s.items)?s.items:[];return jsxs("div",{className:"block-list border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"List"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(Ea,{items:i,onChange:d=>{o(e.id,{data:{...s,items:d}});},compact:true})]})};var od=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return 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:[jsxs("div",{className:"flex items-center justify-between mb-6",children:[jsxs("div",{className:"flex items-center gap-3",children:[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:jsx(CodeXml,{className:"w-5 h-5"})}),jsxs("div",{children:[jsx("h4",{className:"text-sm font-bold tracking-tight text-[var(--kyro-text-primary)]",children:"Code Snippet"}),jsxs("p",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] tracking-widest",children:["Block Editor \u2022 ",s.language||"javascript"]})]})]}),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:jsxs("div",{className:"flex bg-[var(--kyro-surface-accent)]/50 p-1 rounded-xl border border-[var(--kyro-border)]",children:[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:jsx(ChevronRight,{className:"w-4 h-4 rotate-[-90deg]"})}),jsx("div",{className:"w-px h-4 bg-[var(--kyro-border)] mx-1 self-center"}),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:jsx(X,{className:"w-4 h-4"})})]})})]}),jsxs("div",{className:"space-y-6",children:[jsx(Fa,{field:{type:"code",name:"code",label:"Source Code",language:s.language||"javascript"},value:s.code||"",onChange:l=>i("code",l)}),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:[jsxs("div",{className:"flex-1",children:[jsx("label",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2 block",children:"Syntax Highlighting"}),jsxs("div",{className:"relative",children:[jsxs("select",{value:s.language||"javascript",onChange:l=>i("language",l.target.value),className:"w-full pl-4 pr-10 py-2.5 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl text-xs font-medium text-[var(--kyro-text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--kyro-primary)]/20 focus:border-[var(--kyro-primary)] transition-all appearance-none cursor-pointer",children:[jsx("option",{value:"plaintext",children:"Plain Text"}),jsx("option",{value:"javascript",children:"JavaScript"}),jsx("option",{value:"typescript",children:"TypeScript"}),jsx("option",{value:"python",children:"Python"}),jsx("option",{value:"json",children:"JSON"}),jsx("option",{value:"html",children:"HTML"}),jsx("option",{value:"css",children:"CSS"}),jsx("option",{value:"sql",children:"SQL"}),jsx("option",{value:"rust",children:"Rust"}),jsx("option",{value:"markdown",children:"Markdown"})]}),jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--kyro-text-muted)]",children:jsx(ChevronRight,{className:"w-4 h-4 rotate-90"})})]})]}),jsx("div",{className:"hidden sm:block w-px h-10 bg-[var(--kyro-border)]"}),jsxs("div",{className:"hidden sm:flex flex-col justify-center",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest text-[var(--kyro-text-muted)] mb-2",children:"Status"}),jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl",children:[jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500 animate-pulse"}),jsx("span",{className:"text-[10px] font-medium text-[var(--kyro-text-primary)] tracking-wide",children:"EDITING"})]})]})]})]})]})};var ad=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-file border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"File"}),jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(dr,{field:{label:"File",name:"file",maxCount:1},value:s.file,onChange:l=>i("file",l)})]})};var Ks=({items:e=[],onChange:t,compact:r=false})=>{let[o,a]=wa.useState(0),n=(m,v)=>{let f=[...e];f[m]={...f[m],title:v},t(f);},s=(m,v)=>{let f=[...e];f[m]={...f[m],content:v},t(f);},i=m=>{let v=e.filter((f,b)=>b!==m);t(v),o===m?a(null):o!==null&&o>m&&a(o-1);},l=()=>{t([...e,{title:`Item ${e.length+1}`,content:""}]),a(e.length);},d="w-full px-3 py-2 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",c="w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return r?jsxs("div",{className:"space-y-2",children:[e.length===0?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.'}):jsx("div",{className:"space-y-1.5",children:e.map((m,v)=>{let f=o===v;return jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxs("button",{type:"button",onClick:()=>a(f?null:v),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:[jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${v+1}`}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),i(v);},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:jsx(X,{className:"w-3.5 h-3.5"})}),f?jsx(ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsx(ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),f&&jsxs("div",{className:"p-2.5 bg-[var(--kyro-surface)] space-y-2",children:[jsx("input",{type:"text",value:m.title||"",onChange:b=>n(v,b.target.value),onClick:b=>b.stopPropagation(),className:c,placeholder:"Item title..."}),jsx("textarea",{value:m.content||"",onChange:b=>s(v,b.target.value),onClick:b=>b.stopPropagation(),className:`${c} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},v)})}),jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsx(Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]}):jsxs("div",{className:"space-y-2",children:[e.length===0?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.'}):jsx("div",{className:"space-y-2",children:e.map((m,v)=>{let f=o===v;return jsxs("div",{className:"border border-[var(--kyro-border)] rounded-lg overflow-hidden group",children:[jsxs("button",{type:"button",onClick:()=>a(f?null:v),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:[jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] truncate",children:m.title||`Item ${v+1}`}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),i(v);},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:jsx(X,{className:"w-4 h-4"})}),f?jsx(ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsx(ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})]})]}),f&&jsxs("div",{className:"p-3 bg-[var(--kyro-surface)] space-y-2",children:[jsx("input",{type:"text",value:m.title||"",onChange:b=>n(v,b.target.value),className:d,placeholder:"Item title..."}),jsx("textarea",{value:m.content||"",onChange:b=>s(v,b.target.value),className:`${d} min-h-[60px] resize-none`,placeholder:"Item content..."})]})]},v)})}),jsxs("button",{type:"button",onClick:l,className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 text-xs font-medium rounded-lg border border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:border-[var(--kyro-sidebar-active)] hover:text-[var(--kyro-text-primary)] transition-colors",children:[jsx(Plus,{className:"w-3.5 h-3.5"}),"Add Item"]})]})};var nd=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},i=Array.isArray(s.items)?s.items:[],l=d=>{o(e.id,{data:{...s,items:d}});};return jsxs("div",{className:"block-accordion border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Accordion"}),jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(Ks,{items:i,onChange:l,compact:true})]})};var sd=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data||e.data||{},i=l=>{o(e.id,{data:{...s,content:l}});};return jsxs("div",{className:"block-richtext border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx(AlignLeft,{className:"w-3.5 h-3.5 text-[var(--kyro-primary)]"}),jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Rich Text"})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(Oo,{field:{name:"content",label:"Content",type:"richtext"},value:s.content,onChange:i})]})};var Gs=({heading:e="",subheading:t="",ctaText:r="",ctaUrl:o="",onChange:a,compact:n=false})=>{let s=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",i=n?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return n?jsxs("div",{className:"space-y-2",children:[jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]}):jsxs("div",{className:"space-y-3",children:[jsx("input",{type:"text",value:e,onChange:l=>a("heading",l.target.value),className:`${s} font-bold text-base`,placeholder:"Hero heading..."}),jsx("textarea",{value:t,onChange:l=>a("subheading",l.target.value),className:i,placeholder:"Hero subheading..."}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("input",{type:"text",value:r,onChange:l=>a("ctaText",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",placeholder:"CTA text..."}),jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),jsx("input",{type:"url",value:o,onChange:l=>a("ctaUrl",l.target.value),className:"flex-1 px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent font-mono text-xs",placeholder:"https://..."})]})]})};function Un({field:e,value:t,onChange:r,renderField:o}){let a=t||{};return 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:[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}),jsx("div",{className:e.admin?.inline?"flex items-start gap-4":"space-y-6",children:e.fields.map(n=>o(n,a,r))})]})}var ou=new Set(["text","textarea","number","checkbox","select","radio","color","email","password","code","markdown","upload"]);function au(e){let t=e.fields||[];return t.length===0||t.length>4?false:t.every(r=>ou.has(r.type))}function cd({id:e,index:t,isOpen:r,setOpenIndex:o,item:a,field:n,renderField:s,onChangeItem:i,onRemove:l,disabled:d,compact:c,getItemLabel:m}){let{attributes:v,listeners:f,setNodeRef:b,transform:x,transition:g,isDragging:y}=useSortable({id:e}),u={transform:CSS.Transform.toString(x),transition:g,zIndex:y?10:1,opacity:y?.8:1};return c?jsxs("div",{ref:b,style:u,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 ${y?"bg-[var(--kyro-surface-accent)]/50":""}`,children:[jsx("div",{...v,...f,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:jsx(GripVertical,{className:"w-3.5 h-3.5"})}),jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] pt-2.5 min-w-[18px] text-center",children:t+1}),jsx("div",{className:"flex-1 flex items-start gap-1.5 min-w-0",children:(n.fields||[]).map(N=>jsx("div",{className:"flex-1 min-w-0",children:s(N,a,i)},N.name))}),jsx("button",{type:"button",disabled:d,onClick:l,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:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}):jsxs("div",{ref:b,style:u,className:`border border-[var(--kyro-border)] rounded-lg overflow-hidden group bg-[var(--kyro-surface)] ${y?"border-[var(--kyro-primary)] shadow-md":""}`,children:[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:[jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[jsx("div",{...v,...f,className:"p-1 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] hover:bg-[var(--kyro-border)] rounded flex-shrink-0",children:jsx(GripVertical,{className:"w-4 h-4"})}),jsx("span",{role:"button",tabIndex:0,onClick:()=>o(r?null:t),onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.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}`})]}),jsxs("div",{className:"flex items-center gap-1",children:[jsx("button",{type:"button",disabled:d,onClick:N=>{N.stopPropagation(),l();},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"}),jsx("button",{type:"button",onClick:()=>o(r?null:t),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",children:r?jsx(ChevronUp,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"}):jsx(ChevronDown,{className:"w-4 h-4 text-[var(--kyro-text-muted)]"})})]})]}),r&&jsx("div",{className:"p-4 bg-[var(--kyro-surface)] space-y-4",children:(n.fields||[]).map(N=>s(N,a,i))})]})}function zn({field:e,value:t,onChange:r,renderField:o,disabled:a}){let n=Array.isArray(t)?t:[],s=e.fields||[],i=s[0],l=i?.name||"user",d=i?.type==="relationship",[c,m]=wa.useState(0);wa.useEffect(()=>{let y=false,u=n.filter(N=>typeof N!="object"||N===null?(y=true,false):true).map(N=>!N.id&&!N._key?(y=true,{...N,id:Math.random().toString(36).substr(2,9)}):N);y&&r(u);},[t,r]);function v(y){for(let u of ["label","title","name"]){let N=y[u];if(N&&typeof N=="string")return N}for(let u of s){if(u.type==="text"||u.type==="textarea"){let N=y[u.name];if(N&&typeof N=="string")return N}if(u.type==="group"&&u.fields){for(let N of u.fields)if(N.type==="text"||N.type==="textarea"){let S=y[u.name]?.[N.name];if(S&&typeof S=="string")return S}}}return ""}let f=au(e),b=useSensors(useSensor(PointerSensor,{activationConstraint:{distance:3}})),x=y=>{let{active:u,over:N}=y;if(!N||u.id===N.id)return;let R=n.findIndex(h=>(h.id||h._key)===u.id),S=n.findIndex(h=>(h.id||h._key)===N.id);if(R!==-1&&S!==-1){let h=[...n],[C]=h.splice(R,1);h.splice(S,0,C),r(h);}},g=wa.useMemo(()=>n.map(y=>y?.id||y?._key||""),[n]);return d?jsxs("div",{className:"kyro-form-field",children:[jsx("label",{className:"kyro-form-label",children:e.label||e.name}),jsx(Ia,{field:{name:l,relationTo:e.fields?.[0]?.relationTo||"",hasMany:true,label:e.fields?.[0]?.label},value:n.map(y=>y[l]).filter(Boolean),onChange:y=>{let u=(y||[]).map(N=>({[l]:N,id:Math.random().toString(36).substr(2,9)}));r(u);},disabled:a})]}):jsxs("div",{className:"kyro-form-field",children:[jsx("label",{className:"kyro-form-label",children:e.label||e.name}),jsx(DndContext,{sensors:b,collisionDetection:closestCenter,onDragEnd:x,children:f?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:[jsx(SortableContext,{items:g,strategy:verticalListSortingStrategy,children:n.map((y,u)=>jsx(cd,{id:y.id||y._key||`idx-${u}`,index:u,isOpen:false,setOpenIndex:()=>{},item:y,field:e,renderField:o,onChangeItem:N=>{let R=[...n];R[u]=N,r(R);},onRemove:()=>r(n.filter((N,R)=>R!==u)),disabled:a,compact:true,getItemLabel:v},y.id||y._key||u))}),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"})]}):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:[jsx(SortableContext,{items:g,strategy:verticalListSortingStrategy,children:jsx("div",{className:"space-y-2",children:n.map((y,u)=>{let N=c===u;return jsx(cd,{id:y.id||y._key||`idx-${u}`,index:u,isOpen:N,setOpenIndex:m,item:y,field:e,renderField:o,onChangeItem:R=>{let S=[...n];S[u]=R,r(S);},onRemove:()=>r(n.filter((R,S)=>S!==u)),disabled:a,compact:false,getItemLabel:v},y.id||y._key||u)})})}),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 y=Math.random().toString(36).substr(2,9);r([...n,{id:y}]),m(n.length);},children:"+ Add Item"})]})})]})}var pd="other";function md(){return pd}function jn(e){pd=e;}var ho=({field:e,value:t,onChange:r,error:o,disabled:a})=>{if(e.hidden===true||e.admin?.hidden===true)return null;let n=s=>{jn("keystroke"),r(s);};switch(e.type){case "text":case "email":case "url":return jsx(Ho,{field:e,value:t,onChange:n,error:o,disabled:a});case "textarea":return jsx(Ho,{field:{...e,variant:"textarea"},value:t,onChange:n,error:o,disabled:a});case "password":return jsx(Ho,{field:{...e,variant:"password"},value:t,onChange:n,error:o,disabled:a});case "secret":return jsx(Tn,{field:e,value:t,onChange:r,error:o,disabled:a});case "number":return jsx(Fn,{field:e,value:t,onChange:r,disabled:a,error:o});case "checkbox":return jsx(Pn,{field:e,value:t,onChange:r,disabled:a,error:o});case "select":return jsx(Mn,{field:e,value:t,onChange:r,disabled:a,error:o});case "date":return jsx(Dn,{field:e,value:t,onChange:r,disabled:a,error:o});case "richtext":return jsx(Oo,{field:e,value:t,onChange:n,disabled:a,error:o});case "markdown":return jsx(Cs,{field:e,value:t,onChange:n,disabled:a,error:o});case "code":return jsx(Fa,{field:e,value:t,onChange:n,disabled:a,error:o});case "image":case "upload":return jsx(lt,{field:e,error:o,children:jsx(dr,{field:e,value:t,onChange:r,disabled:a})});case "relationship":return jsx(Ia,{field:e,value:t,onChange:r,disabled:a,error:o});case "list":return jsx(lt,{field:e,error:o,children:jsx(Ea,{items:Array.isArray(t)?t:[],onChange:r,compact:true})});case "array":return jsx(zn,{field:e,value:Array.isArray(t)?t:[],onChange:r,disabled:a,renderField:(s,i,l)=>{let d=i[s.name];return jsx(ho,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "blocks":return jsx(qs,{field:e,value:t,onChange:n,disabled:a,error:o});case "group":return jsx(Un,{field:e,value:t,onChange:r,renderField:(s,i,l)=>{let d=i[s.name];return jsx(ho,{field:s,value:d,onChange:c=>{l({...i,[s.name]:c});},disabled:a,error:o},s.name)}});case "color":return jsx(lt,{field:e,error:o,children:jsxs("div",{className:"flex items-center gap-3",children:[jsx("input",{type:"color",value:t||"#000000",onChange:s=>r(s.target.value),disabled:a,className:"h-10 w-14 p-1 cursor-pointer bg-[var(--kyro-input-bg)] border border-[var(--kyro-input-border)] rounded-lg"}),jsx("input",{type:"text",className:"kyro-form-input font-mono ",value:t||"",onChange:s=>r(s.target.value),disabled:a,placeholder:"#000000"})]})});default:return 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 Jo=({block:e,blockSchema:t,onClose:r})=>{let o=Ue(e.id),{updateBlock:a}=Le(),n=o?.data||e.data||{},s=o?.children||e.children||[],i=(m,v)=>{a(e.id,{data:{...n,[m]:v}});},l=m=>{a(e.id,{children:m});},d=()=>t&&Array.isArray(t.fields)?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 f={values:n,...n};if(!m.admin.condition(f,f))return null}catch(f){console.warn(`Condition error for field ${m.name}:`,f);}else if(typeof m.admin.condition=="object")try{let f=m.admin.condition,b=f.field,x=n[b],g=!0;if("equals"in f?g=x===f.equals:"notEquals"in f?g=x!==f.notEquals:"in"in f&&Array.isArray(f.in)&&(g=f.in.includes(x)),!g)return null}catch(f){console.warn(`Declarative condition error for field ${m.name}:`,f);}}let v=n[m.name];return jsx("div",{className:"kyro-block-field-row border-b border-[var(--kyro-border)]/30 pb-3 last:border-b-0 last:pb-0",children:jsx(ho,{field:m,value:v,onChange:f=>i(m.name,f)})},m.name)})}):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=Ie[e.type]||Ie.default;return jsxs(cr,{open:true,onClose:r,title:`Edit ${t?.label||e.type}`,width:"xl",showOverlay:false,accentClass:c.border,children:[jsxs("div",{className:"space-y-4",children:[d(),s.length>0&&jsxs("div",{className:"pt-4 border-t border-[var(--kyro-border)]",children:[jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",s.length,")"]}),jsx(Qr,{blockId:e.id,children:s,onUpdateChildren:l})]})]}),jsx("div",{className:"mt-6 pt-4 border-t border-[var(--kyro-border)]",children: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 nu=6,Qr=({blockId:e,children:t,onUpdateChildren:r,depth:o=0,maxDepth:a=nu})=>{let[n,s]=useState(false),[i,l]=useState(new Set),[d,c]=useState(null),[m,v]=useState(null),f=useContext(bo);if(!f)throw new Error("ChildBlocksTree must be used within a BlocksContext");let b=useStore(f,p=>p.dynamicCategories),x=useStore(f,p=>p.allowedBlocks),g=o<a,y=16,u=p=>{let P=Go(p);r([...t,P]),c(P.id);},N=p=>{let P=t.filter(M=>M.id!==p);r(P);},S=(p,P)=>{let M=t.map(D=>D.id===p?{...D,children:P}:D);r(M);},h=p=>{l(P=>{let M=new Set(P);return M.has(p)?M.delete(p):M.add(p),M});},C=p=>{let P=p.children&&p.children.length>0,M=i.has(p.id);Js(p.type);let I=P,A=d===p.id,re=x.find(me=>me.slug===p.type);return jsxs("div",{className:"relative group",children:[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"} ${g?"cursor-pointer":""}`,style:{marginLeft:o*y},onClick:()=>{g&&c(A?null:p.id);},children:[I?jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),h(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:M?jsx(ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsx(ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsx("span",{className:"w-4"}),jt[p.type]&&jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:jt[p.type]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ua(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),re?.admin?.description&&jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:re.admin.description})]}),P&&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?jsxs("div",{className:"flex items-center gap-1",onClick:me=>me.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{N(p.id),v(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsx("button",{type:"button",onClick:()=>v(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"})]}):jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),v(p.id);},className:"p-1.5 rounded-md transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsx(X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)] invisible group-hover/column:visible"})})]}),A&&jsx(Jo,{block:p,onClose:()=>c(null)}),P&&M&&jsx("div",{className:"mt-1",children:jsx(fd,{parentId:p.id,children:p.children,onUpdateChildren:me=>S(p.id,me),depth:o+1,maxDepth:a})})]},p.id)};return jsxs("div",{className:"space-y-2",children:[t.length>0&&jsx("div",{className:"space-y-1",children:t.map(C)}),g&&jsxs("div",{style:{marginLeft:o*y},children:[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:[jsx(Plus,{className:"w-3 h-3"}),"Add Block"]}),jsx(Ma,{open:n,onClose:()=>s(false),onSelect:u,children:b.map(p=>jsxs("div",{className:"mb-4",children:[jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(P=>jsxs("button",{type:"button",onClick:()=>{u(P.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:[jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:jt[P.slug]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:P.label}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:P.admin?.description||""})]})]},P.slug))})]},p.title))})]}),t.length===0&&g&&jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*y},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*y},children:["Maximum nesting level (",a,") reached"]})]})},fd=({parentId:e,children:t,onUpdateChildren:r,depth:o,maxDepth:a})=>{let[n,s]=useState(false),[i,l]=useState(new Set),[d,c]=useState(null),[m,v]=useState(null),f=useContext(bo);if(!f)throw new Error("NestedChildBlocks must be used within a BlocksContext");let b=useStore(f,p=>p.dynamicCategories),x=useStore(f,p=>p.allowedBlocks),g=o<a,y=16,u=p=>{let P=Go(p);r([...t,P]),c(P.id);},N=p=>{let P=t.filter(M=>M.id!==p);r(P);},S=(p,P)=>{let M=t.map(D=>D.id===p?{...D,children:P}:D);r(M);},h=p=>{l(P=>{let M=new Set(P);return M.has(p)?M.delete(p):M.add(p),M});},C=p=>{let P=p.children&&p.children.length>0,M=i.has(p.id);Js(p.type);let I=P,A=d===p.id,re=x.find(me=>me.slug===p.type);return jsxs("div",{className:"relative group",children:[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"} ${g?"cursor-pointer":""}`,style:{marginLeft:o*y},onClick:()=>{g&&c(A?null:p.id);},children:[I?jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),h(p.id);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded",children:M?jsx(ChevronDown,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"}):jsx(ChevronRight,{className:"w-3 h-3 text-[var(--kyro-text-muted)]"})}):jsx("span",{className:"w-4"}),jt[p.type]&&jsx("div",{className:"w-8 h-8 rounded bg-[var(--kyro-surface-accent)] flex items-center justify-center text-[var(--kyro-text-secondary)]",children:jt[p.type]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"text-xs font-medium text-[var(--kyro-text-secondary)] truncate",children:[Ua(p),p.data?.text?` - ${p.data.text.slice(0,30)}`:"",p.data?.heading?` - ${p.data.heading.slice(0,30)}`:""]}),re?.admin?.description&&jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5 truncate opacity-80",children:re.admin.description})]}),P&&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?jsxs("div",{className:"flex items-center gap-1",onClick:me=>me.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{N(p.id),v(null);},className:"px-2 py-1 text-xs bg-[var(--kyro-danger)] text-white rounded",children:"Remove"}),jsx("button",{type:"button",onClick:()=>v(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"})]}):jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),v(p.id);},className:"p-1.5 rounded-md invisible group-hover:visible transition-opacity cursor-pointer hover:bg-[var(--kyro-danger-bg)]",children:jsx(X,{className:"w-3.5 h-3.5 text-[var(--kyro-danger)]"})})]}),A&&jsx(Jo,{block:p,onClose:()=>c(null)}),P&&M&&jsx("div",{className:"mt-1",children:jsx(fd,{parentId:p.id,children:p.children,onUpdateChildren:me=>S(p.id,me),depth:o+1,maxDepth:a})})]},p.id)};return jsxs("div",{className:"space-y-2",children:[t.length>0&&jsx("div",{className:"space-y-1",children:t.map(C)}),g&&jsxs("div",{style:{marginLeft:o*y},children:[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:[jsx(Plus,{className:"w-3 h-3"}),"Add Block"]}),jsx(Ma,{open:n,onClose:()=>s(false),onSelect:u,children:b.map(p=>jsxs("div",{className:"mb-4",children:[jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] tracking-wide mb-2",children:p.title}),jsx("div",{className:"grid grid-cols-3 gap-2",children:p.blocks.map(P=>jsxs("button",{type:"button",onClick:()=>{u(P.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:[jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded group-hover:bg-[var(--kyro-primary)]/10 group-hover:text-[var(--kyro-primary)] transition-all",children:jt[P.slug]}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("div",{className:"text-xs font-medium tracking-tight text-[var(--kyro-text-primary)]",children:P.label}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] mt-0.5",children:P.admin?.description||""})]})]},P.slug))})]},p.title))})]}),t.length===0&&g&&jsx("div",{className:"text-xs text-[var(--kyro-text-muted)] italic py-2",style:{marginLeft:o*y},children:'No blocks added. Click "Add Block" to add elements.'}),o>=a&&t.length>0&&jsxs("div",{className:"text-xs text-[var(--kyro-text-muted)] italic",style:{marginLeft:o*y},children:["Maximum nesting level (",a,") reached"]})]})};var vd=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},i=r?.children??e.children??[],l=(d,c)=>{o(e.id,{data:{...s,[d]:c}});};return jsxs("div",{className:"block-hero border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("div",{className:"flex items-center gap-2",children:jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Hero Section"})}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsxs("div",{className:"space-y-3",children:[jsx(Gs,{heading:s.heading||"",subheading:s.subheading||"",ctaText:s.ctaText||"",ctaUrl:s.ctaUrl||"",onChange:l,compact:true}),jsx(dr,{field:{label:"Background",name:"bgImage",maxCount:1},value:s.bgImage,onChange:d=>l("bgImage",d)}),jsxs("div",{className:"pt-3 border-t border-[var(--kyro-border)]",children:[jsxs("label",{className:"text-[10px] font-medium text-[var(--kyro-text-muted)] mb-1.5 block",children:["Children (",i.length,")"]}),jsx(Qr,{blockId:e.id,children:i,onUpdateChildren:d=>o(e.id,{children:d})})]})]})]})};var Xs=({title:e="",description:t="",icon:r="",link:o="",linkText:a="",onChange:n,compact:s=false})=>{let i=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent",l=s?"w-full px-2.5 py-1.5 border border-[var(--kyro-border)] rounded bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[50px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent":"w-full px-3 py-2.5 border border-[var(--kyro-border)] rounded-lg bg-[var(--kyro-bg-secondary)] text-sm text-[var(--kyro-text-primary)] min-h-[80px] resize-none focus:outline-none focus:ring-1 focus:ring-[var(--kyro-sidebar-active)] focus:border-transparent";return jsxs("div",{className:s?"space-y-2":"space-y-3",children:[jsx("input",{type:"text",value:e,onChange:d=>n("title",d.target.value),className:`${i} font-bold text-base`,placeholder:"Card title..."}),jsx("textarea",{value:t,onChange:d=>n("description",d.target.value),className:l,placeholder:"Card description..."}),jsx("input",{type:"text",value:r,onChange:d=>n("icon",d.target.value),className:i,placeholder:"Icon (emoji or name)..."}),jsxs("div",{className:"flex items-center gap-2",children:[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..."}),jsx("span",{className:"text-[var(--kyro-text-muted)] text-xs",children:"\u2192"}),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 xd=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o}=Le(),a=r?.data||e.data||{},n=(s,i)=>{o(e.id,{data:{...a,[s]:i}});};return jsx(xo,{id:e.id,type:"card",label:"Card",children:jsx(Xs,{title:a.title||"",description:a.description||"",icon:a.icon||"",link:a.link||"",linkText:a.linkText||"",onChange:n,compact:true})})};var kd=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le();r?.data??e.data??{};let i=r?.children??e.children??[];return jsxs("div",{className:"block-array border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Repeater"}),jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["(",i.length," items)"]})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx("div",{className:"space-y-3",children:jsx(Qr,{blockId:e.id,children:i,onUpdateChildren:l=>o(e.id,{children:l})})})]})};var ja=({relationTo:e="pages",hasMany:t=false,selectedIds:r=[],selectedId:o,labelField:a="title",onChange:n,compact:s=false})=>{let[i,l]=useState(false),[d,c]=useState(""),[m,v]=useState([]),[f,b]=useState(false),[x,g]=useState([]),[y,u]=useState(true);useEffect(()=>{Be("/api/collections").then(D=>{g((D.collections||[]).map(I=>I.slug||I.name||I)),u(false);}).catch(()=>u(false));},[]);let N=(D="")=>{b(true);let I=`/api/${e}?${Qa(D,[a],20)}`;Be(I).then(A=>{v(A.docs||[]),b(false);}).catch(()=>b(false));};useEffect(()=>{i&&N(d);},[i,d,e,a]);let R=D=>D?.[a]||D?.title||D?.name||D?.label||D?.filename||D?.slug||D?.id||"Untitled",S=t?r:o?[o]:[],h=D=>{t?S.includes(D.id)?n("selectedIds",S.filter(I=>I!==D.id)):n("selectedIds",[...S,D.id]):(n("selectedId",D.id),n("selectedIds",[D.id]),l(false));},C=D=>S.includes(D),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",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",M=e&&typeof e=="string"&&e.length>0;return jsxs("div",{className:s?"space-y-2":"space-y-4",children:[jsxs("div",{className:s?"flex items-center gap-2":"space-y-3",children:[!M&&jsx(Fragment,{children:y?jsx("div",{className:P+" text-[var(--kyro-text-muted)]",children:"Loading..."}):jsxs("select",{value:e,onChange:D=>n("relationTo",D.target.value),className:P,children:[jsx("option",{value:"",children:"Select collection..."}),x.map(D=>jsx("option",{value:D,children:D},D))]})}),!s&&jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[jsx("input",{type:"checkbox",checked:t,onChange:D=>n("hasMany",D.target.checked),className:"w-4 h-4 rounded border-[var(--kyro-border)] focus:ring-[var(--kyro-sidebar-active)] focus:ring-offset-0"}),jsx("span",{className:"text-sm text-[var(--kyro-text-primary)]",children:"Allow multiple"})]})]}),jsxs("div",{className:"relative",children:[jsxs("div",{className:"relative",children:[jsx(Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--kyro-text-muted)]"}),jsx("input",{type:"text",value:d,onChange:D=>{c(D.target.value),l(true);},onFocus:()=>l(true),onBlur:()=>setTimeout(()=>l(false),200),placeholder:`Search ${e}...`,className:`${p} pl-9`}),jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:f&&jsx(LoaderCircle,{className:"w-4 h-4 text-[var(--kyro-text-muted)] animate-spin"})})]}),i&&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:f?jsx("div",{className:"p-3 text-center text-sm text-[var(--kyro-text-muted)]",children:"Loading..."}):m.length===0?jsx(En,{title:"No results found"}):jsx("div",{className:"py-1",children:m.map(D=>jsxs("button",{type:"button",onMouseDown:I=>I.preventDefault(),onClick:()=>h(D),className:`w-full px-3 py-2 text-left text-sm hover:bg-[var(--kyro-surface-accent)] transition-colors flex items-center justify-between ${C(D.id)?"bg-[var(--kyro-sidebar-active)]/10 text-[var(--kyro-sidebar-active)]":"text-[var(--kyro-text-primary)]"}`,children:[jsx("span",{children:R(D)}),C(D.id)&&jsx("span",{children:"\u2713"})]},D.id))})})]}),S.length>0&&jsx("div",{className:"flex flex-wrap gap-1.5",children:S.map(D=>{let I=m.find(A=>A.id===D)||{id:D};return 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(I),jsx("button",{type:"button",onMouseDown:A=>A.preventDefault(),onClick:()=>{t?n("selectedIds",S.filter(A=>A!==D)):(n("selectedId",null),n("selectedIds",[]));},className:"hover:opacity-70",children:jsx(X,{className:"w-3 h-3"})})]},D)})})]})};var wd=({block:e,index:t})=>{let r=Ue(e.id),{updateBlock:o,removeBlock:a,moveBlock:n}=Le(),s=r?.data??e.data??{},i=(l,d)=>{o(e.id,{data:{...s,[l]:d}});};return jsxs("div",{className:"block-relationship border border-[var(--kyro-border)] rounded-md p-3 mb-2 relative group",children:[jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] ",children:"Relationship"}),jsxs("span",{className:"text-[10px] text-[var(--kyro-text-muted)]",children:["\u2192 ",s.relationTo||"pages"]})]}),jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:()=>n(e.id,"up"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move up",children:jsx(ChevronRight,{className:"w-3 h-3 rotate-90"})}),jsx("button",{type:"button",onClick:()=>n(e.id,"down"),className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded",title:"Move down",children:jsx(ChevronRight,{className:"w-3 h-3"})}),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:jsx(X,{className:"w-3 h-3"})})]})]}),jsx(ja,{relationTo:s.relationTo||"pages",hasMany:s.hasMany||false,selectedIds:Array.isArray(s.selectedIds)?s.selectedIds:[],selectedId:s.selectedId,labelField:s.labelField||"title",onChange:i,compact:true})]})};var iu={heading:Xl,paragraph:Yl,image:Zl,video:td,list:rd,code:od,file:ad,accordion:nd,richtext:sd,hero:vd,card:xd,array:kd,relationship:wd},Ie={featureSplit:{text:"text-indigo-500",border:"border-indigo-500",borderLeft:"border-l-indigo-500"},featureGrid:{text:"text-blue-500",border:"border-blue-500",borderLeft:"border-l-blue-500"},ctaBanner:{text:"text-amber-500",border:"border-amber-500",borderLeft:"border-l-amber-500"},testimonials:{text:"text-emerald-500",border:"border-emerald-500",borderLeft:"border-l-emerald-500"},faq:{text:"text-orange-500",border:"border-orange-500",borderLeft:"border-l-orange-500"},stats:{text:"text-rose-500",border:"border-rose-500",borderLeft:"border-l-rose-500"},logoCloud:{text:"text-cyan-500",border:"border-cyan-500",borderLeft:"border-l-cyan-500"},pricing:{text:"text-green-500",border:"border-green-500",borderLeft:"border-l-green-500"},team:{text:"text-violet-500",border:"border-violet-500",borderLeft:"border-l-violet-500"},recentFeed:{text:"text-sky-500",border:"border-sky-500",borderLeft:"border-l-sky-500"},processSteps:{text:"text-fuchsia-500",border:"border-fuchsia-500",borderLeft:"border-l-fuchsia-500"},formEmbed:{text:"text-pink-500",border:"border-pink-500",borderLeft:"border-l-pink-500"},videoShowcase:{text:"text-red-500",border:"border-red-500",borderLeft:"border-l-red-500"},hero:{text:"text-yellow-500",border:"border-yellow-500",borderLeft:"border-l-yellow-500"},card:{text:"text-teal-500",border:"border-teal-500",borderLeft:"border-l-teal-500"},default:{text:"text-zinc-400",border:"border-zinc-400",borderLeft:"border-l-zinc-400"}},jt={heading:jsx(Heading1,{className:`w-4 h-4 ${Ie.default.text}`}),paragraph:jsx(AlignLeft,{className:`w-4 h-4 ${Ie.default.text}`}),image:jsx(Image,{className:`w-4 h-4 ${Ie.default.text}`}),video:jsx(Video,{className:`w-4 h-4 ${Ie.default.text}`}),list:jsx(List,{className:`w-4 h-4 ${Ie.default.text}`}),code:jsx(Code,{className:`w-4 h-4 ${Ie.default.text}`}),file:jsx(File,{className:`w-4 h-4 ${Ie.default.text}`}),accordion:jsx(ChevronDown,{className:`w-4 h-4 ${Ie.default.text}`}),richtext:jsx(AlignLeft,{className:`w-4 h-4 ${Ie.default.text}`}),hero:jsx(Star,{className:`w-4 h-4 ${Ie.hero.text}`}),card:jsx(Box,{className:`w-4 h-4 ${Ie.card.text}`}),array:jsx(ListOrdered,{className:`w-4 h-4 ${Ie.default.text}`}),relationship:jsx(Link2,{className:`w-4 h-4 ${Ie.default.text}`}),featureSplit:jsx(Columns3,{className:`w-4 h-4 ${Ie.featureSplit.text}`}),featureGrid:jsx(Blocks,{className:`w-4 h-4 ${Ie.featureGrid.text}`}),ctaBanner:jsx(Sparkles,{className:`w-4 h-4 ${Ie.ctaBanner.text}`}),testimonials:jsx(Users,{className:`w-4 h-4 ${Ie.testimonials.text}`}),faq:jsx(CircleHelp,{className:`w-4 h-4 ${Ie.faq.text}`}),stats:jsx(Activity,{className:`w-4 h-4 ${Ie.stats.text}`}),logoCloud:jsx(Image,{className:`w-4 h-4 ${Ie.logoCloud.text}`}),pricing:jsx(Tag,{className:`w-4 h-4 ${Ie.pricing.text}`}),team:jsx(Users,{className:`w-4 h-4 ${Ie.team.text}`}),recentFeed:jsx(Database,{className:`w-4 h-4 ${Ie.recentFeed.text}`}),processSteps:jsx(Clock,{className:`w-4 h-4 ${Ie.processSteps.text}`}),formEmbed:jsx(Mail,{className:`w-4 h-4 ${Ie.formEmbed.text}`}),videoShowcase:jsx(Video,{className:`w-4 h-4 ${Ie.videoShowcase.text}`})};function Js(e){return iu[e]||null}function Qs(e){return {paragraph:"Paragraph",heading:"Heading",image:"Image",video:"Video",list:"List",code:"Code",file:"File",accordion:"Accordion",array:"Repeater",relationship:"Relationship",richtext:"Rich Text",hero:"Hero Section",card:"Card Block",featureSplit:"Feature Split",featureGrid:"Feature Grid",ctaBanner:"CTA Banner",testimonials:"Testimonials Stack",faq:"FAQ Section",stats:"Stats & Metrics",logoCloud:"Logo Cloud",pricing:"Pricing Grid / Plan",team:"Team Profiles Showcase",recentFeed:"Dynamic Content Feed",processSteps:"Process Timeline / Steps",formEmbed:"Lead Intake Form",videoShowcase:"Cinematic Video Showcase",headingElement:"Heading",textElement:"Text",imageElement:"Image",richtextElement:"Rich Text",buttonElement:"Button",videoElement:"Video",listElement:"List"}[e]||e}function Ua(e){let t=e.name;return t&&t.trim()?t.trim():Qs(e.type)}function ku(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 hu=({block:e,index:t,blockSchema:r,editingBlockId:o,setEditingBlockId:a,onDuplicate:n,compact:s})=>{let{attributes:i,listeners:l,setNodeRef:d,transform:c,transition:m,isDragging:v}=useSortable({id:e.id}),{removeBlock:f,updateBlock:b}=Le(),x=o===e.id,[g,y]=useState(false),[u,N]=useState(false),[R,S]=useState(e.name||""),h=useRef(null);useEffect(()=>{u&&h.current&&(h.current.focus(),h.current.select());},[u]);let C=useCallback(()=>{N(false);let I=R.trim();I!==(e.name||"").trim()&&b(e.id,{name:I||""});},[R,e.name,e.id,b]),p={transform:CSS.Transform.toString(c),transition:m,zIndex:v?10:1,opacity:v?.8:1},P=Ua(e),M=e.data||{},D=ku(M,r);return s?jsxs("div",{ref:d,style:p,className:"relative group",children:[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 ${x?`${(Ie[e.type]||Ie.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[jsx("div",{className:"absolute left-0.5 top-1/2 -translate-y-1/2 p-0.5 cursor-grab active:cursor-grabbing text-[var(--kyro-text-muted)] opacity-0 group-hover:opacity-100 transition-opacity hover:bg-[var(--kyro-surface-accent)] rounded",...i,...l,onClick:I=>I.stopPropagation(),children:jsx(GripVertical,{className:"w-2.5 h-2.5"})}),jt[e.type]&&jsx("span",{className:"text-[var(--kyro-text-secondary)] flex-shrink-0",children:jt[e.type]}),u?jsx("input",{ref:h,value:R,onChange:I=>S(I.target.value),onBlur:C,onKeyDown:I=>{I.key==="Enter"&&C(),I.key==="Escape"&&(S(e.name||""),N(false));},onClick:I=>I.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"}):jsx("span",{className:"font-medium text-[var(--kyro-text-secondary)] truncate max-w-[120px] transition-colors",children:P}),g?jsxs("div",{className:"flex items-center gap-0.5",onClick:I=>I.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{f(e.id),y(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"}),jsx("button",{type:"button",onClick:()=>y(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"})]}):jsxs("div",{className:"flex items-center gap-0.5",children:[jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),S(e.name||""),N(true);},className:"p-0.5 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Rename",children: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:[jsx("path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"}),jsx("path",{d:"m15 5 4 4"})]})}),jsx("button",{type:"button",onClick:I=>{I.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:jsx(Copy,{className:"w-3 h-3"})}),jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),y(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:jsx(X,{className:"w-3 h-3"})})]})]}),x&&jsx(Jo,{block:e,blockSchema:r,onClose:()=>a(null)})]}):jsxs("div",{ref:d,style:p,className:"relative group mb-2",children:[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 ${x?`${(Ie[e.type]||Ie.default).border} bg-[var(--kyro-primary)]/5`:"border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/50 hover:bg-[var(--kyro-primary)]/5"}`,children:[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",...i,...l,onClick:I=>I.stopPropagation(),children:jsx(GripVertical,{className:"w-4 h-4"})}),jt[e.type]&&jsx("span",{className:"text-[var(--kyro-text-secondary)]",children:jt[e.type]}),jsxs("div",{className:"flex-1 min-w-0",children:[u?jsx("input",{ref:h,value:R,onChange:I=>S(I.target.value),onBlur:C,onKeyDown:I=>{I.key==="Enter"&&C(),I.key==="Escape"&&(S(e.name||""),N(false));},onClick:I=>I.stopPropagation(),placeholder:Qs(e.type),className:"w-full max-w-[150px] sm:max-w-[250px] md:max-w-[400px] bg-[var(--kyro-surface-accent)] border border-[var(--kyro-primary)] rounded px-2 py-0.5 text-xs font-semibold text-[var(--kyro-text-primary)] outline-none"}):jsxs("div",{className:"text-xs font-semibold text-[var(--kyro-text-secondary)] truncate transition-colors",children:[P,D&&typeof D=="string"&&jsxs("span",{className:"text-[var(--kyro-text-muted)] font-normal ml-1.5",children:["- ",D.length>40?`${D.slice(0,40)}...`:D]})]}),r?.admin?.description&&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&&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"]}),g?jsxs("div",{className:"flex items-center gap-1.5",onClick:I=>I.stopPropagation(),children:[jsx("button",{type:"button",onClick:()=>{f(e.id),y(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"}),jsx("button",{type:"button",onClick:()=>y(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"})]}):jsxs("div",{className:"flex items-center gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity",children:[jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),S(e.name||""),N(true);},className:"p-1 hover:bg-[var(--kyro-surface-accent)] rounded text-[var(--kyro-text-secondary)] transition-colors",title:"Rename Block",children: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:[jsx("path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"}),jsx("path",{d:"m15 5 4 4"})]})}),jsx("button",{type:"button",onClick:I=>{I.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:jsx(Copy,{className:"w-3.5 h-3.5"})}),jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),y(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:jsx(X,{className:"w-3.5 h-3.5"})})]})]}),x&&jsx(Jo,{block:e,blockSchema:r,onClose:()=>a(null)})]})},wu=wa.memo(hu),qs=({field:e,value:t,onChange:r,onBlocksChange:o,error:a,disabled:n,documentStatus:s,justSaved:i})=>{let[l,d]=useState(false),[c,m]=useState(false),v=useRef(null),f=e.admin?.pickerMode||"drawer",b=e.blocks||[],x=b.reduce((T,_)=>{let de=_.admin?.group||"Custom Blocks";return T[de]||(T[de]=[]),T[de].push(_),T},{}),g=["Structural Sections","Marketing Grids","Lead Capture & Interactive","Dynamic Content","Basic Content Elements","Custom Blocks"],y=Object.entries(x).sort(([T],[_])=>{let de=g.indexOf(T),ke=g.indexOf(_);return de!==-1&&ke!==-1?de-ke:de!==-1?-1:ke!==-1?1:T.localeCompare(_)}).map(([T,_])=>({title:T,blocks:_})),u=useRef(null);u.current||(u.current=Gl(b,y));let N=u.current,R=useStore(N,T=>T.blocks),[S,h]=useState(null),[C,p]=useState(null),P=useRef(R.length),M=useRef(new Set(R.map(T=>T.id))),D=useRef(false);useEffect(()=>{if(D.current&&R.length>P.current){let T=R.find(_=>_.id&&!M.current.has(_.id));T&&p(T.id);}P.current=R.length,M.current=new Set(R.map(T=>T.id));},[R]),useEffect(()=>(o&&N.getState().setOnBlocksChange(o),()=>{N.getState().setOnBlocksChange(()=>{});}),[o,N]);let I=useRef(null);useEffect(()=>{let T=Array.isArray(t)?t:[],_=I.current||[];if(JSON.stringify(T)!==JSON.stringify(_)){let de=[...T];P.current=de.length,M.current=new Set(de.map(ke=>ke.id)),N.getState().setBlocks(de),I.current=de,D.current=true;}else T.length===0&&!D.current&&(D.current=true,I.current=[]);},[t,e.name,N]);let A=useRef(r);A.current=r,useEffect(()=>{if(!A.current)return;let T=I.current;T&&JSON.stringify(R)!==JSON.stringify(T)&&(I.current=[...R],A.current(R));},[R]);let me=useCallback(T=>{N.getState().addBlock(T);},[N]),O=useCallback(T=>{let _=R.findIndex(L=>L.id===T);if(_===-1)return;let de=R[_],ke=L=>{let z=Math.random().toString(36).substr(2,9);return {...L,id:z,children:L.children?L.children.map(We=>ke(We)):L.children,data:L.data?JSON.parse(JSON.stringify(L.data)):L.data}},Ce=ke(de),he=[...R];he.splice(_+1,0,Ce),N.getState().setBlocks(he);},[R,N]),W=useSensors(useSensor(PointerSensor,{activationConstraint:{distance:3}}),useSensor(KeyboardSensor)),se=T=>{h(T.active);},X=T=>{let{active:_,over:de}=T;if(h(null),!!de){if(_.id.toString().startsWith("drawer-")){let ke=_.id.toString().replace("drawer-","");if(de.id.toString().startsWith("container-")){let Ce=de.id.toString().replace("container-",""),he=R.find(L=>L.id===Ce);if(he){let L=Go(ke);N.getState().updateBlock(Ce,{children:[...he.children||[],L]});}}else {let Ce=R.findIndex(he=>he.id===de.id);Ce!==-1?N.getState().addBlock(ke,Ce):me(ke);}return}if(_.id!==de.id){let ke=R.findIndex(he=>he.id===_.id),Ce=R.findIndex(he=>he.id===de.id);if(ke!==-1&&Ce!==-1){let he=[...R],[L]=he.splice(ke,1);he.splice(Ce,0,L),N.getState().setBlocks(he);}}}},K=S?y.flatMap(T=>T.blocks).find(T=>`drawer-${T.type}`===S.id)||R.find(T=>T.id===S.id):null;K?"label"in K?K.label:K.type:"Block";return useEffect(()=>{if(!c)return;let T=_=>{v.current&&!v.current.contains(_.target)&&m(false);};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[c]),jsx(bo.Provider,{value:u.current,children:jsxs("div",{className:"kyro-blocks-field",children:[jsxs(DndContext,{sensors:W,collisionDetection:closestCenter,onDragStart:se,onDragEnd:X,children:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("label",{className:"kyro-form-label",children:e.label||e.name}),f==="dropdown"?jsxs("div",{ref:v,className:"relative",children:[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:[jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add Element",jsx(ChevronDown,{className:`w-3.5 h-3.5 transition-transform ${c?"rotate-180":""}`})]}),c&&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:y.map(T=>jsxs("div",{children:[y.length>1&&jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold tracking-wider text-[var(--kyro-text-muted)] uppercase",children:T.title}),T.blocks.map(_=>jsxs("button",{type:"button",onClick:()=>{me(_.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:[jsx("span",{className:"flex-shrink-0 w-5 h-5 flex items-center justify-center text-[var(--kyro-text-muted)]",children:jt[_.slug]||jsx(Box,{className:"w-4 h-4"})}),jsxs("div",{className:"min-w-0 flex-1",children:[jsx("div",{className:"text-xs font-semibold truncate",children:_.label}),_.admin?.description&&jsx("div",{className:"text-[10px] text-[var(--kyro-text-muted)] truncate",children:_.admin.description})]})]},_.slug))]},T.title))})]}):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:[jsx(Plus,{className:"w-4 h-4"}),"Add Block"]})]}),jsx("div",{className:"mb-4",children:jsx(Ma,{open:l,onClose:()=>d(false),onSelect:me,children:jsx("div",{className:"space-y-4",children:y.map(T=>jsxs("div",{children:[jsx("h3",{className:"text-xs font-semibold text-[var(--kyro-text-muted)] mb-2 tracking-wider",children:T.title}),jsx("div",{className:"grid grid-cols-3 gap-2",children:T.blocks.map(_=>jsx(Wl,{block:{type:_.slug,label:_.label,description:_.admin?.description||"",icon:null},onSelect:me,children: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:jsx("span",{className:"text-[var(--kyro-text-muted)]",children:jt[_.slug]||jsx(Box,{className:"w-4 h-4"})})})},_.slug))})]},T.title))})})}),jsx(SortableContext,{items:R.map(T=>T.id),strategy:verticalListSortingStrategy,children:jsxs("div",{className:f==="dropdown"?"flex flex-wrap gap-1.5":"space-y-4",children:[R.map((T,_)=>{let de=e.blocks?.find(ke=>ke.slug===T.type);return jsx(wu,{block:T,index:_,blockSchema:de,editingBlockId:C,setEditingBlockId:p,onDuplicate:O,compact:f==="dropdown"},T.id||_)}),R.length===0&&jsx("div",{className:f==="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:f==="dropdown"?"No elements added":"Click the button above to add your first block"})]})}),jsx(DragOverlay,{children:S&&K&&jsx("div",{className:"bg-[var(--kyro-surface)] border border-[var(--kyro-primary)] rounded-md p-3 shadow-lg",children:K.label||K.type||"Block"})})]}),a&&jsx("p",{className:"kyro-form-error",children:a})]})})};function ur(e){if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map(ur);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<=8)return t.id;let n={};for(let s of r)n[s]=ur(t[s]);return n}return e}function Sd(){let e=useRef([]),t=useRef(false);return {queueTask:useCallback((o,a)=>{e.current.push(o);async function n(){if(!t.current&&!(typeof a?.beforeProcess=="function"&&a.beforeProcess()===false))for(;e.current.length>0;){let s=e.current.pop();e.current=[],t.current=true;try{await s();}catch(i){console.error("Error in queued function:",i);}finally{t.current=false,typeof a?.afterProcess=="function"&&a.afterProcess();}}}n();},[])}}function Td({config:e,initialData:t,collectionSlug:r,globalSlug:o,documentId:a,onChange:n,onActionSuccess:s,onActionError:i}){let l=Ee(),{confirm:d}=st(),{formData:c,setFormData:m,setField:v,lastSavedData:f,setLastSavedData:b,setHasUnsavedChanges:x,isSlugLocked:g,loadDocument:y,setIsAutoSaving:u,setAutoSaveStatus:N,setVersions:R,setLoadingVersions:S,sidebarCollapsed:h,setSidebarCollapsed:C,getDraftCache:p,setDraftCache:P,clearDraftCache:M,resetForm:D}=l,I=!!e.versions,A=o||t?.id||a||r,re=useRef(false);!o&&A&&c&&Object.keys(c).length>0&&c.id!==A&&(re.current=true),useEffect(()=>{re.current&&(re.current=false,D());},[D]);let me=useRef(null),O=useRef(null),W=useRef(null),se=useRef(typeof navigator<"u"?navigator.onLine:true),X=useRef(0),K=useRef(false),Ne=useRef(null),Re=useRef(""),T=useRef(""),{queueTask:_}=Sd(),de=useCallback(J=>o?`global:${o}`:r&&J?`${r}:${J}`:null,[r,o]),ke=useCallback((J,Z,le)=>{P(J,{data:Z,baseUpdatedAt:f.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:le?.lastSyncedAt??null});},[f.updatedAt,P]),Ce=useCallback(async()=>{let J=o?Ye(`/api/globals/${o}/versions`):r&&c.id?Ye(`/api/${r}/${c.id}/versions`):null;if(J){S(true);try{let le=await(await mt(J)).json();R(le.docs||[]);}catch(Z){console.error("Failed to fetch versions:",Z);}finally{S(false);}}},[c.id,r,o,S,R]),he=useCallback(()=>{let J=Ee.getState(),Z=J.formData;if(K.current||!r||!Z.id||!J.hasDirtyFields())return;let le=de(Z.id);le&&ke(le,Z);},[r,de,ke]),L=useCallback(async J=>{let Z=Ee.getState(),le=Z.formData,xe=Z.lastSavedData;if(K.current||!I&&o||!o&&(!r||!le.id)||!Z.hasDirtyFields())return;let Se=de(le.id);if(Se&&ke(Se,le),!se.current){N("offline");return}u(true),N("saving"),Z.setBackgroundProcessing(true);try{let et=o?Ye(`/api/globals/${o}?autosave=true`):Ye(`/api/${r}/${le.id}?autosave=true`),St=await mt(et,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":"true"},keepalive:J?.keepalive,body:JSON.stringify({...ur(le),baseUpdatedAt:xe.updatedAt??null})});if(St.ok)X.current=Date.now(),Z.setRetryCount(0),Z.setLastSavedAt(Date.now()),W.current&&clearTimeout(W.current),Se&&P(Se,{data:le,baseUpdatedAt:xe.updatedAt??null,draftUpdatedAt:new Date().toISOString(),lastSyncedAt:(await St.clone().json()).data?.updatedAt||new Date().toISOString()}),N("success"),setTimeout(()=>{Ee.getState().autoSaveStatus==="success"&&N("idle");},2e3);else if(St.status===409)N("conflict");else throw new Error(`Draft auto-save failed with status ${St.status}`)}catch(et){console.error("Auto-save failed:",et);let St=Ee.getState(),B=St.retryCount;if(B<5){St.setRetryCount(B+1),N("retrying");let G=Math.min(1e3*Math.pow(2,B),6e4);W.current&&clearTimeout(W.current),W.current=setTimeout(()=>z(J),G);}else N("offline");}finally{u(false),Ee.getState().setBackgroundProcessing(false);}},[r,de,o,ke,N,P,u,I]),z=useCallback(J=>{_(()=>L(J),{beforeProcess:()=>true,afterProcess:()=>{}});},[L,_]),We=useCallback(async(J,Z=true)=>{let le=Ee.getState(),xe=J||le.formData,Se=o?Ye(`/api/globals/${o}`):Ye(`/api/${r}/${xe.id}`),et=await mt(Se,{method:"PATCH",headers:{"Content-Type":"application/json","X-Draft":String(Z)},body:JSON.stringify({...ur(xe),baseUpdatedAt:le.lastSavedData.updatedAt??null})});return et.status===409&&N("conflict"),et},[r,o,N]);useEffect(()=>{let J=()=>{C(!h);};return window.addEventListener("toggle-sidebar",J),()=>window.removeEventListener("toggle-sidebar",J)},[h,C]);let ye=useRef(null),Ae=useRef(""),ct=useRef(false);useEffect(()=>{let J=o||t?.id,Z=JSON.stringify(t);ct.current&&ye.current===J&&Ae.current===Z||(y(t||{},t||{}),ct.current=true,ye.current=J,Ae.current=Z);},[r,c.id,o,t,y]),useEffect(()=>{if(!r||!t?.id)return;let J=de(t.id);if(!J||Ne.current===J)return;let Z=false;return (async()=>{if(!I)return;let xe=p(J);if(xe){if(JSON.stringify(xe.data)===JSON.stringify(t)){M(J);return}Ne.current=J,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(Z)return;let et={...Ee.getState().formData,...xe.data};m(et),s?.("Recovered autosaved draft");},onCancel:async()=>{M(J);}});}})(),()=>{Z=true;}},[M,r,d,de,p,t,s,m,I]);function At(J,Z){for(let le of J){if(le.name===Z&&le.admin?.autoGenerate==="title")return le;if(le.type==="tabs"&&"tabs"in le)for(let xe of le.tabs){let Se=At(xe.fields,Z);if(Se)return Se}if((le.type==="group"||le.type==="collapsible")&&"fields"in le){let xe=At(le.fields,Z);if(xe)return xe}}}useEffect(()=>{let J=e.fields;if(!At(J,"metaTitle"))return;let le=fo(J,c,"title"),xe=le?String(le):"";xe&&(!c.metaTitle||c.metaTitle===c._lastMetaTitle)&&v("metaTitle",xe);},[c,e.fields,v]),useEffect(()=>{let J=e.fields,Z=J.find(Se=>Se.name==="slug"&&Se.admin?.autoGenerate);if(!Z?.admin?.autoGenerate)return;let le=Z.admin.autoGenerate,xe=fo(J,c,le);if(g&&xe){let Se=An(xe);Se!==c.slug&&v("slug",Se);}},[c,g,e.fields,v]),useEffect(()=>{if(h||!o&&(!r||!c.id)||!Ee.getState().hasDirtyFields()||md()!=="keystroke")return;jn("other");let Z=JSON.stringify(c);Z!==Re.current&&(me.current&&clearTimeout(me.current),me.current=setTimeout(he,1500),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{Re.current=Z,z();},8e3));},[c,h,r,o,he,z]),useEffect(()=>{if(!o&&(!r||!c.id))return;let J=()=>{K.current||!Ee.getState().hasDirtyFields()||z({keepalive:true});},Z=()=>{document.hidden&&J();},le=()=>{se.current=true,J();},xe=()=>{se.current=false;let Se=Ee.getState();Se.hasDirtyFields()&&Se.setAutoSaveStatus("offline");};return window.addEventListener("blur",J),window.addEventListener("pagehide",J),window.addEventListener("online",le),window.addEventListener("offline",xe),document.addEventListener("visibilitychange",Z),()=>{window.removeEventListener("blur",J),window.removeEventListener("pagehide",J),window.removeEventListener("online",le),window.removeEventListener("offline",xe),document.removeEventListener("visibilitychange",Z);}},[r,o,c.id,z]),useEffect(()=>{let J=JSON.stringify(c);if(J===T.current)return;T.current=J;let Z=document.getElementById("form-data");Z&&(Z.value=J),n?.(c);},[c,n]),useEffect(()=>{(o||c.id)&&Ce();},[c.id,o,Ce]);let qt=!c.id&&!o?"draft":I&&c.status||"published",gt=(!!c.id||!!o)&&qt==="draft";return {...l,fetchVersions:Ce,performAutoSave:z,saveDocument:We,autoSaveSkipRef:K,lastAutoSaveTimeRef:X,documentStatus:qt,hasUnpublishedChanges:gt,versionsEnabled:I}}function Co({trigger:e,children:t,align:r="right",direction:o="up"}){let[a,n]=useState(false),s=useRef(null);return useEffect(()=>{let i=l=>{s.current&&!s.current.contains(l.target)&&n(false);};return a&&document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[a]),jsxs("div",{className:"relative",ref:s,children:[jsx("div",{onClick:()=>n(!a),className:"cursor-pointer",children:e}),a&&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 _t({children:e,onClick:t,icon:r,danger:o,disabled:a,className:n=""}){return jsx("div",{className:"px-1.5",children: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&&jsx("span",{className:"w-4 h-4 opacity-70",children:r}),jsx("span",{className:"flex-1",children:e})]})})}function Ha(){return jsx("div",{className:"my-1 border-t border-[var(--kyro-border)] opacity-50"})}function To({status:e,saveStatus:t,hasChanges:r,onPublish:o,children:a,disabled:n,direction:s="down"}){let i=e==="published"&&!r&&t!=="saving"&&t!=="error",l=n||t==="saving"||i,d="kyro-btn kyro-btn-sm text-[11px] font-regular tracking-widest transition-all duration-300 rounded-lg",c=()=>t==="saving"?`${d} bg-[var(--kyro-primary)]/70 border-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] cursor-wait`:t==="saved"?`${d} bg-[var(--kyro-success)] border-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)]`:t==="error"?`${d} bg-[var(--kyro-error)] border-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)]`:i?`${d} bg-[var(--kyro-gray-200)] border-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] cursor-not-allowed`:`${d} bg-[var(--kyro-primary)] border-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] hover:bg-[var(--kyro-primary-hover)]`,m="kyro-btn kyro-btn-md px-2 rounded-l-none border-l-[1px] border-white/20 transition-all duration-300",v=()=>t==="saving"?`${m} bg-[var(--kyro-primary)]/70 text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)]/70`:t==="saved"?`${m} bg-[var(--kyro-success)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-success)]`:t==="error"?`${m} bg-[var(--kyro-error)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-error)]`:i?`${m} bg-[var(--kyro-gray-200)] text-[var(--kyro-text-muted)] border-[var(--kyro-gray-200)]`:`${m} bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] border-[var(--kyro-primary)] hover:bg-[var(--kyro-primary-hover)]`,f=()=>t==="saving"?"Publishing...":t==="saved"?"Published \u2713":t==="error"?"Retry":i?"Published":"Publish Changes";return jsxs("div",{className:"inline-flex items-center",children:[jsxs("button",{type:"button",onClick:o,disabled:l,className:`${c()} ${a?"":"rounded-r-lg border-r border-[var(--kyro-border)]"}`,children:[t==="saving"&&jsx(Pr,{size:"sm",className:"inline mr-1.5"}),i&&jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"inline mr-1",children:jsx("polyline",{points:"20 6 9 17 4 12"})}),f()]}),a&&jsx(Co,{trigger:jsx("button",{type:"button",className:v(),disabled:t==="saving",children:jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"m6 9 6 6 6-6"})})}),direction:s,children:a})]})}var Fd=({title:e,description:t,slug:r})=>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:[jsxs("div",{className:"flex items-center gap-2 mb-2",children:[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"}),jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-tight",children:"kyro-cms.com"}),jsxs("span",{className:"text-[12px] text-[var(--kyro-text-secondary)] leading-tight opacity-80",children:["https://kyro-cms.com \u203A posts \u203A ",r]})]})]}),jsx("h3",{className:"text-[20px] text-[#2563eb] dark:text-[#60a5fa] font-medium hover:underline cursor-pointer mb-1 leading-tight transition-colors",children:e}),jsx("p",{className:"text-[14px] text-[var(--kyro-text-secondary)] leading-relaxed line-clamp-2",children:t})]});function Dd({field:e,formData:t,onTabDataChange:r,renderField:o}){let[a,n]=useState(0),s=e.tabs||[],i=s[a]||s[0],l=e.name?t[e.name]||{}:t;return jsxs("div",{className:"space-y-8",children:[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)=>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))}),jsx("div",{className:"space-y-6",children:i?.fields.map(d=>o(d,l,r))}),i?.label==="SEO"&&jsxs("div",{className:"mt-12 pt-8 border-t border-[var(--kyro-border)]",children:[jsx("h4",{className:"text-[10px] font-bold text-[var(--kyro-text-secondary)] tracking-[0.2em] mb-6 opacity-50",children:"Live Google Preview"}),jsx(Fd,{title:String((typeof l.metaTitle=="object"?"":l.metaTitle)||(typeof l.title=="object"?"":l.title)||"Untitled"),description:String((typeof l.metaDescription=="object"?"":l.metaDescription)||"Please enter a description..."),slug:String((typeof t.slug=="object"?"":t.slug)||"your-slug")})]})]})}function Ld({collectionSlug:e,globalSlug:t,documentStatus:r,hasUnpublishedChanges:o,localSaveStatus:a,handleCreateNew:n,handleDuplicate:s,handleUnpublish:i,handleDelete:l,handlePublish:d,handleSchedulePublish:c}){let[m,v]=useState(Date.now()),[f,b]=useState(false),x=useRef(null),{formData:g,hasUnsavedChanges:y,autoSaveStatus:u,lastSavedAt:N,retryCount:R,view:S,setView:h,showPreview:C,setShowPreview:p,setFormData:P,markSaved:M,lastSavedData:D}=Ee(),I=!g.id;useEffect(()=>{let T=setInterval(()=>v(Date.now()),1e4);return ()=>clearInterval(T)},[]),useEffect(()=>{let T=_=>{x.current&&!x.current.contains(_.target)&&b(false);};if(f)return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[f]);let A=String(g.mainTabs?.title||(typeof g.title=="object"?"":g.title)||(typeof g.name=="object"?"":g.name)||"Untitled"),re=g.updatedAt?new Date(g.updatedAt).toLocaleString():"Just now",me=g.createdAt?new Date(g.createdAt).toLocaleString():"Just now",O=o?"Draft (unpublished changes)":r==="published"?"Published":"Draft",W=o?"Unpublished":r==="published"?"Published":"Draft",se=r==="published"&&!y?"bg-[var(--kyro-success)]":o?"bg-[var(--kyro-warning)]":"bg-[var(--kyro-text-muted)]",X=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",K=(T=false)=>jsxs(Fragment,{children:[u==="saving"&&jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),T?"Saving\u2026":"Saving draft..."]}),u==="success"&&jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsx(Check,{className:"w-3.5 h-3.5 shrink-0"}),T?"Saved":N?`Saved ${Math.floor((Date.now()-N)/6e4)}m ago`:"Draft saved"]}),u==="retrying"&&jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxs("svg",{className:"animate-spin h-3 w-3 shrink-0",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),T?`Retry ${R}/5`:`Retrying save (${R}/5)`]}),u==="offline"&&jsxs("span",{className:"text-[var(--kyro-text-muted)] flex items-center gap-1.5",children:[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:[jsx("path",{d:"M10.61 10.61a3 3 0 0 0 4.24 4.24"}),jsx("path",{d:"M13.36 13.36a3 3 0 0 0-4.24-4.24"}),jsx("path",{d:"m2 2 20 20"}),jsx("path",{d:"M18.36 5.64a9 9 0 0 0-12.72 0"}),jsx("path",{d:"M22.61 1.39a15 15 0 0 0-21.22 0"})]}),T?"Offline":"Offline \u2014 cached locally"]}),u==="error"&&jsx("span",{className:"text-[var(--kyro-danger)]",children:T?"Failed":"Draft save failed"}),u==="conflict"&&(T?jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict"}):jsxs("div",{className:"flex items-center gap-3",children:[jsx("span",{className:"text-[var(--kyro-danger)] font-semibold",children:"Conflict detected"}),jsx("span",{className:"opacity-30",children:"\u2014"}),jsx("button",{type:"button",onClick:async()=>{},className:"text-[var(--kyro-primary)] hover:underline",children:"Keep my changes"}),jsx("span",{className:"opacity-30",children:"|"}),jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"text-[var(--kyro-danger)] hover:underline",children:"Reload server version"})]}))]}),Ne=()=>!I&&jsxs(Co,{trigger: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:jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[jsx("circle",{cx:"12",cy:"5",r:"1.5"}),jsx("circle",{cx:"12",cy:"12",r:"1.5"}),jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})}),direction:"down",children:[!t&&jsx(_t,{onClick:n,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),children:"Create New"}),!t&&jsx(_t,{onClick:s,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),children:"Duplicate"}),jsx(_t,{onClick:()=>b(true),icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"}),jsx("line",{x1:"16",y1:"2",x2:"16",y2:"6"}),jsx("line",{x1:"8",y1:"2",x2:"8",y2:"6"}),jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"})]}),children:"Schedule Publish"}),r==="published"&&jsx(_t,{onClick:i,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[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"}),jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}),children:"Unpublish"}),!t&&jsxs(Fragment,{children:[jsx(Ha,{}),jsx(_t,{onClick:l,danger:true,icon:jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("polyline",{points:"3 6 5 6 21 6"}),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"})]})]}),Re=()=>f&&jsx("div",{ref:x,className:"relative",children: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:[jsx("p",{className:"text-xs font-medium mb-2",children:"Schedule Publish"}),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)}),jsxs("div",{className:"flex items-center gap-2 justify-end",children:[jsx("button",{type:"button",onClick:()=>b(false),className:"px-3 py-1.5 text-xs kyro-btn rounded-lg",children:"Cancel"}),jsx("button",{type:"button",onClick:()=>{let T=document.getElementById("schedule-datetime")?.value;T&&c(T);},className:"px-3 py-1.5 text-xs kyro-btn-success rounded-lg",children:"Schedule"})]})]})});return jsxs(Fragment,{children:[jsxs("header",{className:"md:hidden border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)] backdrop-blur-md rounded-lg",children:[jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[jsx("a",{href:`${tt}/${e}`,className:"p-1.5 rounded-lg hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsx(ChevronRight,{className:"w-4 h-4"})}),jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[jsx("h1",{className:"text-base font-bold tracking-tight truncate min-w-0",children:A}),jsxs("span",{className:`shrink-0 inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[9px] font-medium border ${X}`,children:[jsx("span",{className:`h-1.5 w-1.5 rounded-full ${se}`}),W]})]}),jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[jsx(To,{status:r,saveStatus:a,hasChanges:y,onPublish:d,disabled:a==="saving"}),Ne(),Re()]})]}),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:[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(T=>jsx("button",{type:"button",onClick:()=>h(T),className:`px-3 py-1 text-[10px] font-bold rounded-md transition-all ${S===T?"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:T==="edit"?"Edit":T==="version"?"History":"API"},T))}),jsxs("div",{className:"flex items-center gap-2 text-[10px] font-medium",children:[K(true),y&&u!=="saving"&&u!=="retrying"&&u!=="conflict"&&jsx("button",{type:"button",onClick:()=>{P(D),M();},className:"text-[var(--kyro-primary)] text-[10px] font-medium hover:underline",children:"Revert"}),jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),jsx("button",{type:"button",onClick:()=>p(!C),className:`p-1.5 rounded-lg transition-all ${C?"bg-[var(--kyro-primary)]/10 text-[var(--kyro-primary)]":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,children:jsx(ExternalLink,{className:"w-3.5 h-3.5"})})]})]})]}),jsxs("header",{className:"hidden md:flex surface-tile px-8 py-6 items-center justify-between sticky top-0 border-b border-[var(--kyro-border)] mb-8 bg-[var(--kyro-surface)] backdrop-blur-md",children:[jsxs("div",{className:"flex flex-col gap-2 min-w-0",children:[jsxs("div",{className:"flex items-center gap-3 flex-wrap min-w-0",children:[jsx("a",{href:`${tt}/${e}`,className:"p-2 border border-[var(--kyro-border)] rounded-xl hover:bg-[var(--kyro-bg-secondary)] transition-colors shrink-0",children:jsx(ChevronRight,{className:"w-4 h-4"})}),jsx("h1",{className:"text-xl font-bold tracking-tighter truncate min-w-0",children:A}),jsxs("span",{className:`shrink-0 inline-flex items-center gap-1.5 px-2 rounded-full text-[10px] font-regular border ${X}`,children:[jsx("span",{className:`h-1.5 w-1.5 rounded-full ${se}`}),O]})]}),jsxs("div",{className:"flex items-center gap-4 text-[11px] font-medium tracking-wide opacity-60 ml-12",children:[K(false),y&&u!=="saving"&&u!=="retrying"&&u!=="conflict"&&jsxs(Fragment,{children:[jsx("span",{className:"opacity-30",children:"\u2014"}),jsx("button",{type:"button",onClick:()=>{P(D),M();},className:"text-[var(--kyro-primary)] hover:underline",children:"Revert changes"})]}),N&&u!=="saving"&&u!=="retrying"&&u!=="success"&&jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Draft saved ",(()=>{let T=m-N,_=Math.floor(T/6e4),de=Math.floor(T/1e3);return _>=1?`${_}m ago`:de>=5?`${de}s ago`:"just now"})()]}),jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Modified ",re]}),jsxs("span",{className:"border-l border-[var(--kyro-border)] pl-4",children:["Created ",me]})]})]}),jsxs("div",{className:"flex items-center gap-6",children:[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(T=>jsx("button",{type:"button",onClick:()=>h(T),className:`px-5 py-2 text-xs font-bold rounded-lg transition-all ${S===T?"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:T.toUpperCase()},T))}),jsx("div",{className:"h-8 w-px bg-[var(--kyro-border)] mx-2"}),jsxs("div",{className:"flex items-center gap-3",children:[jsxs("button",{type:"button",onClick:()=>p(!C),className:`kyro-btn p-2.5 rounded-xl transition-all flex items-center gap-2 ${C?"shadow-lg":"text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-bg-secondary)]"}`,title:"Live Preview",children:[jsx(ExternalLink,{className:"w-4 h-4"}),C&&jsx("span",{className:"text-[10px] font-bold tracking-widest pr-1",children:"Active"})]}),Ne(),Re(),jsx(To,{status:r,saveStatus:a,hasChanges:y,onPublish:d,disabled:a==="saving"})]})]})]})]})}function Md({config:e,layout:t,collectionSlug:r,renderField:o}){let{showPreview:a,sidebarCollapsed:n,formData:s}=Ee();if(t==="single")return jsx("div",{className:"w-full space-y-6 md:space-y-8",children:jsx("div",{className:"surface-tile p-4 md:p-8 space-y-6 md:space-y-8",children:e.fields.map(d=>o(d))})});let l=e.fields.some(d=>d.admin?.position==="sidebar")&&!a;return jsxs("div",{className:`w-full mx-auto grid gap-4 md:gap-8 pb-32 transition-all duration-700 ${a?"grid-cols-1 lg:grid-cols-2":n||!l?"grid-cols-1":"grid-cols-1 lg:grid-cols-[1fr_380px]"}`,children:[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}):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?jsx("div",{className:"sticky top-36 h-[calc(100vh-280px)] animate-in fade-in slide-in-from-right-10 duration-700",children: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:[jsxs("div",{className:"absolute top-4 left-4 z-10 flex items-center gap-2",children:[jsx("div",{className:"h-2 w-2 rounded-full bg-green-500 animate-pulse"}),jsx("span",{className:"text-[10px] font-bold tracking-widest text-white/60",children:"Live Preview Mode"})]}),jsx("iframe",{src:`/${r}/${s.slug||s.id}?preview=true`,className:"w-full h-full border-none",title:"Live Preview"}),jsx("div",{className:"absolute inset-0 bg-transparent pointer-events-none border-[12px] border-[var(--kyro-surface)] rounded-3xl"})]})}):n?null: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")&&jsxs("div",{className:"surface-tile p-4 md:p-6 space-y-4 md:space-y-6",children:[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 Ed({handleRestoreVersion:e,handleCompareVersions:t,toggleCompareSelection:r}){let{compareMode:o,setCompareMode:a,compareSelected:n,setCompareSelected:s,compareDiffs:i,setCompareDiffs:l,loadingDiffs:d,loadingVersions:c,versions:m}=Ee();return jsx("div",{className:"w-full animate-in fade-in slide-in-from-bottom-4 pb-12",children:jsxs("div",{className:"surface-tile p-0 overflow-hidden",children:[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:[jsxs("div",{children:[jsx("h2",{className:"text-base md:text-lg font-bold text-[var(--kyro-text-primary)]",children:"Version History"}),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`})]}),jsxs("div",{className:"flex items-center gap-2",children:[o&&n.length===2&&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"}),jsx("button",{type:"button",onClick:()=>{a(!o),s([]),l([]);},className:`px-3 py-1.5 rounded-lg text-[11px] font-bold tracking-wider transition-all ${o?"bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]":"border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-text-primary)]"}`,children:o?"Done":"Compare"})]})]}),i.length>0&&jsxs("div",{className:"border-b border-[var(--kyro-border)]",children:[jsxs("div",{className:"px-6 py-3 flex items-center justify-between",children:[jsxs("span",{className:"text-[11px] font-bold text-[var(--kyro-text-primary)] tracking-wider",children:[i.length," change",i.length!==1?"s":""]}),jsx("button",{type:"button",onClick:()=>l([]),className:"p-1 rounded hover:bg-[var(--kyro-surface-accent)] text-[var(--kyro-text-muted)]",children:jsx(X,{className:"w-4 h-4"})})]}),jsx("div",{className:"max-h-[400px] overflow-y-auto",children:i.map((v,f)=>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:[jsx("div",{className:"text-[var(--kyro-text-muted)] truncate font-semibold md:font-normal",children:v.field}),jsx("div",{className:"text-[var(--kyro-text-muted)] truncate hidden md:block",children:typeof v.oldValue=="object"?JSON.stringify(v.oldValue):String(v.oldValue??"null")}),jsxs("div",{className:"md:col-span-2 text-[var(--kyro-text-primary)] truncate",children:[jsx("span",{className:"md:hidden text-[var(--kyro-text-muted)]",children:"\u2192 "}),typeof v.newValue=="object"?JSON.stringify(v.newValue):String(v.newValue??"null")]})]},f))})]}),c?jsx("div",{className:"flex justify-center py-16",children:jsx("span",{className:"animate-spin text-[var(--kyro-primary)]",children:"\u231B"})}):m.length===0?jsx("div",{className:"text-center py-16 text-[var(--kyro-text-muted)] text-sm italic",children:"No versions yet."}):jsx("div",{className:"divide-y divide-[var(--kyro-border)]",children:m.map((v,f)=>{let b=n.includes(v.id),x=(v.changeDescription||"").toLowerCase().includes("auto");return jsxs("div",{onClick:o?()=>r(v.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:[jsxs("div",{className:"hidden md:grid grid-cols-12 gap-3 px-6 py-3 items-center",children:[jsx("div",{className:"col-span-1 flex items-center gap-2",children:o?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&&jsx(Check,{className:"w-4 h-4"})}):jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5",children:m.length-f})}),jsxs("div",{className:"col-span-4 min-w-0",children:[jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-2",children:[v.changeDescription||"Snapshot",x&&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"})]}),jsx("div",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(v.createdAt||v.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]}),jsx("div",{className:"col-span-3",children:v.status&&jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold capitalize tracking-wider ${v.status==="published"?" text-[var(--kyro-success)]":" text-[var(--kyro-warning)]"}`,children:[jsx("span",{className:`w-1.5 h-1.5 rounded-full ${v.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),v.status]})}),jsx("div",{className:"col-span-2 text-[11px] text-[var(--kyro-text-muted)]",children:v.createdBy||"system"}),jsx("div",{className:"col-span-2 flex justify-end",children:!o&&jsx("button",{type:"button",onClick:()=>e(v.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"})})]}),jsxs("div",{className:"md:hidden flex items-start gap-3 px-4 py-3",children:[jsx("div",{className:"pt-0.5 shrink-0",children:o?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&&jsx(Check,{className:"w-4 h-4"})}):jsx("span",{className:"text-[10px] font-bold text-[var(--kyro-text-muted)] w-5 inline-block text-center",children:m.length-f})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"text-[13px] font-medium text-[var(--kyro-text-primary)] truncate flex items-center gap-1.5",children:[v.changeDescription||"Snapshot",x&&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"})]}),jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)]",children:new Date(v.createdAt||v.created_at).toLocaleString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}),v.status&&jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-bold capitalize tracking-wider ${v.status==="published"?"text-[var(--kyro-success)]":"text-[var(--kyro-warning)]"}`,children:[jsx("span",{className:`w-1 h-1 rounded-full ${v.status==="published"?"bg-[var(--kyro-success)]":"bg-[var(--kyro-warning)]"}`}),v.status]}),jsx("span",{className:"text-[10px] text-[var(--kyro-text-muted)] opacity-60",children:v.createdBy||"system"})]})]}),!o&&jsx("button",{type:"button",onClick:()=>e(v.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"})]})]},v.id)})})]})})}function $d({collectionSlug:e,globalSlug:t}){let{formData:r}=Ee();return jsx("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4",children:jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_300px] gap-8",children:[jsxs("div",{className:"surface-tile p-8 min-w-0",children:[jsx("h2",{className:"text-xl font-bold mb-6",children:"Response Payload"}),jsx("div",{className:"bg-[#0f172a] p-6 rounded-2xl border border-white/5 overflow-x-auto max-h-[800px]",children:jsx("pre",{className:"text-blue-300 text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(r,null,2)})})]}),jsx("div",{className:"space-y-6",children:jsxs("div",{className:"surface-tile p-8 space-y-6",children:[jsx("h2",{className:"text-xl font-bold mb-6",children:"API Info"}),jsxs("div",{className:"space-y-6",children:[jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Reference Path"}),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&&jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Document ID"}),jsxs("div",{className:"flex items-center gap-2",children:[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)}),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:jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})]}),t&&jsxs("div",{children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.1em] text-[var(--kyro-text-secondary)] opacity-50 block mb-2",children:"Global Slug"}),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 Od={};function Ka({config:e,data:t=Od,errors:r=Od,onChange:o,disabled:a,collectionSlug:n,globalSlug:s,documentId:i,documentName:l,layout:d="split",onActionSuccess:c,onActionError:m,justSaved:v}){let f=e||(s?Vl[s]:n?Vo[n]:null),[b,x]=useState(f);useEffect(()=>{s==="storage-settings"?Be("/api/kyro/schema").then(F=>{F?.globals?.["storage-settings"]&&x(F.globals["storage-settings"]);}).catch(F=>console.error("[AutoForm] Failed to fetch dynamic schema",F)):x(f);},[s,f]);let g=b||f,{confirm:y}=st(),{formData:u,hasUnsavedChanges:R,autoSaveStatus:C,lastSavedAt:p,view:O,setView:W,setShowPreview:T,isMenuOpen:_,setIsMenuOpen:de,loadingFields:ke,setLoadingFields:Ce,compareSelected:z,setCompareSelected:We,setCompareDiffs:Ae,setLoadingDiffs:At,setField:qt,setFormData:gt,setLastSavedData:Z,setAutoSaveStatus:le,fetchVersions:xe,saveDocument:Se,autoSaveSkipRef:et,lastAutoSaveTimeRef:St,documentStatus:B,hasUnpublishedChanges:G,versionsEnabled:ae}=Td({config:g,initialData:t,collectionSlug:n,globalSlug:s,documentId:i,onChange:o,onActionSuccess:c,onActionError:m}),sr=useRef(null),io=useRef(null),[pa,Wa]=useState(false),[es,bt]=useState("idle"),[w,ne]=useState(Date.now()),De=a,[Jt,Lt]=useState(false),[gr,ir]=useState(false),[ts,Fc]=useState(0),li=useRef(new Map),Pc=3e4;useEffect(()=>{let F=s?`global:${s}`:`${n}:${i}`;if(!(s||n&&i&&i!=="new")||t&&Object.keys(t).length>0)return;let Te=li.current.get(F),Fe=Te&&Date.now()-Te.ts<Pc,xt=Te&&!Fe;if(Fe){Ee.getState().loadDocument(Te.data,Te.data);return}xt&&Ee.getState().loadDocument(Te.data,Te.data);let kt=new AbortController;ir(false),Te||Lt(true);let Mt=s?`/api/globals/${s}`:`/api/${n}/${i}`;return Be(Mt,{autoToast:false,signal:kt.signal}).then(pt=>{let lo=pt.data||{};li.current.set(F,{data:lo,ts:Date.now()}),Ee.getState().loadDocument(lo,lo),Lt(false);}).catch(pt=>{pt.name!=="AbortError"&&(Lt(false),Te||ir(true));}),()=>kt.abort()},[n,i,s,t,ts]),useEffect(()=>{let F=setInterval(()=>ne(Date.now()),1e4);return ()=>clearInterval(F)},[]);let di=(F,Q)=>{if(typeof F=="function")try{return F(u,Q)}catch(Te){return console.warn("Error evaluating admin runtime flag:",Te),false}return !!F},Dc=F=>{y({title:"Restore Version",message:"Are you sure you want to restore this version? This will overwrite your current changes.",onConfirm:async()=>{try{let Q=s?Ye(`/api/globals/${s}/versions/${F}/restore`):Ye(`/api/${n}/${u.id}/versions/${F}/restore`),Te=await mt(Q,{method:"POST"});!Te.ok&&n&&(Te=await mt(Ye(`/api/${n}/${u.id}/versions`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({versionId:F,action:"restore"})}));let Fe=await Te.json();if(Fe.data){let{updatedAt:xt,createdAt:kt,...Mt}=Fe.data,pt={...u,...Mt};gt(pt),Ee.getState().loadDocument(pt,pt),c?.("Version restored successfully"),xe(),W("edit");}else E.error(Fe.error||"Failed to restore version");}catch(Q){console.error("Failed to restore version:",Q),E.error("Failed to restore version");}}});},Ic=async()=>{if(z.length===2){At(true);try{let Q=await(await mt(Ye(`/api/${n}/${u.id}/versions?compareA=${z[0]}&compareB=${z[1]}`))).json();Ae(Q.diffs||[]);}catch(F){console.error("Compare failed:",F),Ae([]);}finally{At(false);}}},Bc=F=>{We(Q=>Q.includes(F)?Q.filter(Te=>Te!==F):Q.length>=2?[Q[1],F]:[...Q,F]);};useEffect(()=>{let F=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key==="s"&&(Q.preventDefault(),ci()),(Q.metaKey||Q.ctrlKey)&&Q.shiftKey&&(Q.key==="P"||Q.key==="p")&&(Q.preventDefault(),document.getElementById("btn-publish")?.click()),(Q.metaKey||Q.ctrlKey)&&!Q.shiftKey&&Q.key==="p"&&(Q.preventDefault(),T(Te=>!Te)),document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA"&&(Q.key==="1"&&W("edit"),Q.key==="2"&&W("version"),Q.key==="3"&&W("api"));};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]),useEffect(()=>{let F=()=>W("version");return window.addEventListener("kyro:show-version-history",F),()=>window.removeEventListener("kyro:show-version-history",F)},[]),useEffect(()=>{let F=Q=>{sr.current&&!sr.current.contains(Q.target)&&de(false);};if(_)return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[_]),useEffect(()=>{let F=Q=>{io.current&&!io.current.contains(Q.target)&&Wa(false);};if(pa)return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[pa]);let Lc=()=>{R?y({title:"Unsaved Changes",message:"You have unsaved changes. Save before creating new?",onConfirm:async()=>{await ci(),await new Promise(F=>setTimeout(F,1e3)),window.location.href=`${tt}/${n}/new`;}}):window.location.href=`${tt}/${n}/new`;},Mc=()=>{y({title:"Duplicate Document",message:"Are you sure you want to duplicate this document?",onConfirm:async()=>{try{let{id:F,createdAt:Q,updatedAt:Te,...Fe}=u,xt=ur(Fe),kt=await mt(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...xt,title:`${Fe.title||Fe.name||"Copy"} (Copy)`,slug:`${Fe.slug||"copy"}-${Date.now()}`,status:"draft"})});if(kt.ok){let Mt=await kt.json();c?.("Document duplicated successfully"),Mt.data?.id&&(window.location.href=`${tt}/${n}/${Mt.data.id}`);}else {let Mt=await kt.json();E.error(Mt.error||"Failed to duplicate document");}}catch{E.error("Failed to duplicate document");}}});},Ec=()=>{y({title:"Delete Document",message:"Delete this document? This cannot be undone. Are you absolutely sure?",variant:"danger",onConfirm:async()=>{try{await ht(`/api/${n}/${u.id}`),window.location.href=`${tt}/${n}`;}catch(F){E.error(F.message||"Failed to delete document");}}});},$c=()=>{y({title:"Unpublish Document",message:"Unpublish this document?",onConfirm:async()=>{try{let F=await Se({...u,status:"draft"},!1);if(F?.ok)c?.("Document unpublished successfully"),Ee.getState().loadDocument({...u,status:"draft"},{...u,status:"draft"});else {let Q=await F?.json().catch(()=>({}));E.error(Q?.error||"Failed to unpublish");}}catch{E.error("Failed to unpublish");}}});},ci=async()=>{let F=!u.id;et.current=true,bt("saving");try{let Q=ur({...u}),Te=F&&!s,Fe=Te?await mt(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}):await Se(Q);if(Fe.ok){let kt=(await Fe.json()).data||Q;gt({...u,...kt}),Z({...u,...kt}),St.current=Date.now(),le("success"),bt("saved"),ae&&xe(),setTimeout(()=>{le("idle"),bt("idle");},2e3),c?.(Te?"Document created successfully":"Changes saved"),Te&&setTimeout(()=>{window.location.href=`${tt}/${n}`;},800);}else {let xt=await Fe.json();Fe.status===409&&le("conflict"),bt("error"),E.error(xt.error||"Failed to save"),setTimeout(()=>bt("idle"),3e3);}}catch{bt("error"),E.error("Failed to save document"),setTimeout(()=>bt("idle"),3e3);}finally{et.current=false;}},Oc=async()=>{let F=!u.id;et.current=true,bt("saving");try{let Q={...u};if(F&&!s){let xt=ur({...u}),kt=await mt(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(xt)});if(!kt.ok){let lo=await kt.json().catch(()=>({}));kt.status===409&&le("conflict"),bt("error"),E.error(lo.error||"Failed to create document"),setTimeout(()=>bt("idle"),3e3);return}let pt=(await kt.json()).data||xt;gt({...u,...pt}),Z({...u,...pt}),Q={...u,...pt};}let Te=ur(Q),Fe=await Se(Te,!1);if(Fe?.ok)bt("saved"),c?.("Published successfully");else {let xt=await Fe?.json().catch(()=>({}));Fe?.status===409&&le("conflict"),bt("error"),E.error(xt?.error||"Failed to publish"),setTimeout(()=>bt("idle"),3e3);}}catch{bt("error"),E.error("Failed to publish"),setTimeout(()=>bt("idle"),3e3);}finally{et.current=false;}},Uc=async F=>{let Q=!u.id;et.current=true;try{let Te={...ur({...u}),_schedulePublishAt:F};if(Q&&!s){let Fe=await mt(`/api/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Te)});if(!Fe.ok){let xt=await Fe.json().catch(()=>({}));E.error(xt.error||"Failed to schedule publish");return}}else {let Fe=await Se(Te);if(!Fe.ok){let xt=await Fe.json().catch(()=>({}));E.error(xt.error||"Failed to schedule publish");return}}c?.(`Scheduled publish for ${new Date(F).toLocaleString()}`),Wa(!1);}catch{E.error("Failed to schedule publish");}finally{et.current=false;}},zc=(F,Q)=>{qt(F,Q);},ma=(F,Q,Te)=>{let Fe=Q!==void 0?Q:u;if(di(F.hidden!==void 0?F.hidden:F.admin?.hidden,Fe))return null;let kt=di(F.readOnly!==void 0?F.readOnly:F.admin?.readOnly,Fe),Mt=!!(De||kt);if(F.admin?.condition){if(typeof F.admin.condition=="function")try{let $e={values:u||{},...u||{}};if(!F.admin.condition($e,Fe))return null}catch($e){console.warn(`Condition error for field ${F.name}:`,$e);}else if(typeof F.admin.condition=="object")try{let $e=F.admin.condition,je=$e.field,Vt=Fe&&Fe[je]!==void 0?Fe[je]:u&&u[je]!==void 0?u[je]:void 0,Rr=!0;if("equals"in $e?Rr=Vt===$e.equals:"notEquals"in $e?Rr=Vt!==$e.notEquals:"in"in $e&&Array.isArray($e.in)&&(Rr=$e.in.includes(Vt)),!Rr)return null}catch($e){console.warn(`Declarative condition error for field ${F.name}:`,$e);}}let pt=Fe[F.name],lo=r[F.name],qa=$e=>{Te?Te({...Fe,[F.name]:$e}):zc(F.name,$e);};if(F.type==="row"&&"fields"in F){let $e=F.fields;return jsx("div",{className:"kyro-form-row flex flex-col md:flex-row gap-4 md:gap-6 items-start md:items-end w-full",children:$e?.map(je=>{let Vt=je.admin||{},Rr=Vt?.action;if((je.type==="button"||je.type==="action")&&Rr){let br=$e?.find(ua=>ua.type==="email");return jsx("div",{className:"flex-shrink-0",children:jsx("button",{type:"button",onClick:async()=>{let ua=F.name,Ja=br?.name,Xa=Ja?u[Ja]:void 0;if(!Xa&&ua&&typeof ua=="string"&&Ja&&(Xa=u[ua]?.[Ja]),!!Xa){Ce(xr=>({...xr,[je.name]:true}));try{let xr=await mt(Ye(Rr),{method:Vt.method||"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:Xa})}),ya={};try{ya=await xr.json();}catch{ya={};}if(xr.ok&&ya.success)c?.(ya.message||"Action completed successfully");else {let jc=ya.error||`Request failed (${xr.status})`;m?.(jc);}}catch(xr){m?.(xr instanceof Error?xr.message:"Error connecting to server");}finally{Ce(xr=>({...xr,[je.name]:false}));}}},disabled:ke[je.name]||Mt,className:"kyro-btn kyro-btn-primary px-4 py-2 rounded-lg font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:ke[je.name]?"Sending...":je.label||"Click"})},je.name)}return jsx("div",{className:je.type==="button"||je.type==="action"?"flex-shrink-0":"flex-1",style:Vt?.width?{width:Vt.width,flex:"none"}:{},children:ma(je,Q,Te)},je.name)})},F.name||`row-${Math.random()}`)}switch(F.type){case "tabs":return jsx(Dd,{field:F,formData:u,onTabDataChange:$e=>{qt(F.name,$e);},renderField:($e,je,Vt)=>ma($e,je,Vt)},F.name||`tabs-${Math.random()}`);case "group":return jsx(Un,{field:F,value:pt,onChange:qa,renderField:ma},F.name);case "array":return jsx(zn,{field:F,value:pt,onChange:qa,renderField:ma,disabled:Mt},F.name);case "button":case "action":{let $e=F.name,je=ke[$e];return jsx("div",{className:"kyro-form-field",children:jsxs("button",{type:"button",disabled:je||Mt,onClick:async()=>{let Vt=F.admin?.action||F.action,Rr=F.admin?.method||F.method||"POST";if(Vt){Ce(br=>({...br,[$e]:true}));try{let br=await mt(Vt,{method:Rr,headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});await br.json(),br.ok;}catch(br){console.error("Error executing action:",br);}finally{Ce(br=>({...br,[$e]:false}));}}},className:`kyro-btn kyro-btn-md kyro-btn-secondary transition-all active:scale-95 whitespace-nowrap flex items-center gap-2 ${je?"opacity-70 cursor-not-allowed":""}`,children:[je&&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:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),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"})]}),je?"Processing...":F.label||"Click"]})},$e)}case "relationship-block":return jsxs("div",{className:"kyro-form-field",children:[jsxs("label",{className:"kyro-form-label",children:[F.label||F.name,F.required&&jsx("span",{className:"kyro-form-label-required",children:"*"})]}),jsx(ja,{relationTo:F.relationTo,hasMany:F.hasMany,selectedIds:Array.isArray(pt)?pt:pt?[pt]:[],onChange:($e,je)=>{qa(je);},compact:true}),F.admin?.description?jsx("p",{className:"kyro-form-help",children:String(F.admin?.description)}):null]},F.name);default:return jsx(ho,{field:F,value:pt,onChange:qa,error:lo,disabled:Mt},F.name||Math.random().toString())}};return Jt?jsxs("div",{className:"space-y-6 p-4",children:[jsxs("div",{className:"space-y-2",children:[jsx(Ot,{variant:"text",className:"w-1/3"}),jsx(Ot,{variant:"text",className:"w-2/3"})]}),jsx("div",{className:"space-y-4",children:jsx(Ot,{variant:"rect",count:4})})]}):gr?jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-16",children:[jsx(TriangleAlert,{className:"w-8 h-8 text-[var(--kyro-danger)]"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)]",children:"Failed to load document. Check your connection."}),jsx("button",{type:"button",onClick:()=>{ir(false),Lt(true),Fc(F=>F+1);},className:"kyro-btn kyro-btn-primary px-6 py-2 rounded-xl text-sm font-bold",children:"Retry"})]}):jsxs("div",{className:"flex flex-col h-full",children:[d!=="single"&&jsx(Ld,{collectionSlug:n,globalSlug:s,documentStatus:B||"draft",hasUnpublishedChanges:G,localSaveStatus:es,handleCreateNew:Lc,handleDuplicate:Mc,handleUnpublish:$c,handleDelete:Ec,handlePublish:Oc,handleSchedulePublish:Uc}),d==="single"&&jsxs(Fragment,{children:[jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-[var(--kyro-border)] bg-[var(--kyro-surface)]",children:[jsxs("div",{className:"flex items-center gap-3 text-[11px] font-medium",children:[C==="saving"&&jsxs("span",{className:"flex items-center gap-1.5 text-[var(--kyro-text-muted)]",children:[jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Saving..."]}),C==="success"&&jsxs("span",{className:"text-[var(--kyro-success)] flex items-center gap-1",children:[jsx(Check,{className:"w-4 h-4"}),p?`Saved ${Math.floor((Date.now()-p)/6e4)}m ago`:"Saved"]}),C==="retrying"&&jsxs("span",{className:"text-[var(--kyro-warning)] flex items-center gap-1.5",children:[jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Retrying..."]}),C==="offline"&&jsx("span",{className:"text-[var(--kyro-text-muted)]",children:"Offline \u2014 cached locally"}),C==="error"&&jsx("span",{className:"text-[var(--kyro-danger)]",children:"Save failed"}),C==="conflict"&&jsx("span",{className:"text-[var(--kyro-danger)]",children:"Conflict detected"}),R&&C!=="saving"&&C!=="retrying"&&C!=="conflict"&&jsx("span",{className:"text-[var(--kyro-warning)]",children:"Unsaved changes"}),!R&&C!=="success"&&C!=="saving"&&C!=="error"&&jsx("span",{className:"text-[var(--kyro-success)]",children:"All changes saved"})]}),jsx("span",{className:"text-[11px] text-[var(--kyro-text-muted)] opacity-60",children:u.updatedAt?`Modified ${new Date(u.updatedAt).toLocaleString()}`:""})]}),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 F=await Se(u);if(F.ok){let Te=(await F.json()).data||u;gt({...u,...Te}),Z({...u,...Te}),c?.("Changes saved");}}catch(F){console.error("Save error exception:",F),m?.("Save failed: "+F.message);}}})]}),jsxs("main",{className:"w-full pt-6 md:pt-0",children:[O==="edit"&&jsx(Md,{config:g,layout:d,collectionSlug:n,renderField:ma}),O==="version"&&jsx(Ed,{handleRestoreVersion:Dc,handleCompareVersions:Ic,toggleCompareSelection:Bc}),O==="api"&&jsx($d,{collectionSlug:n,globalSlug:s})]})]})}var Ud={draft:"bg-[var(--kyro-warning)]",published:"bg-[var(--kyro-success)]",scheduled:"bg-[var(--kyro-primary)]",archived:"bg-[var(--kyro-text-muted)]"};function ei({status:e,saveStatus:t,hasChanges:r,onSave:o,onPublish:a,onUnpublish:n,onDuplicate:s,onViewHistory:i,onPreview:l,onDelete:d,onBack:c,onToggleSidebar:m,publishedAt:v,updatedAt:f}){let b=Ee(C=>C.view)||"edit",x=Ee(C=>C.setView),[g,y]=useState(false),u=useRef(null);useEffect(()=>{let C=p=>{u.current&&!u.current.contains(p.target)&&y(false);};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]);let N=()=>t==="saving"?"Saving...":t==="saved"?"Saved":t==="error"?"Error saving":r?"Unsaved":null,R=["edit","version","api"],S=N(),h="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 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&&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:jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})})}),jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${Ud[e]||"bg-[var(--kyro-text-muted)]"}`}),S&&jsxs("span",{className:`text-[10px] whitespace-nowrap max-md:hidden ${t==="error"?"text-[var(--kyro-error)]":"text-[var(--kyro-text-muted)]"}`,children:[t==="saving"&&jsx(Pr,{size:"sm",className:"inline mr-0.5"}),S]}),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(C=>jsx("button",{type:"button",onClick:()=>x(C),className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all ${b===C?"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:C==="edit"?"Edit":C==="version"?"Ver":"API"},C))}),jsxs("div",{className:"flex items-center gap-1 ml-auto shrink-0",children:[l&&jsx("button",{type:"button",onClick:l,className:`${h} max-md:hidden`,title:"Preview",children:jsx(Eye,{className:"w-3.5 h-3.5"})}),i&&jsx("button",{type:"button",onClick:i,className:`${h} max-md:hidden`,title:"View History",children:jsx(Clock,{className:"w-3.5 h-3.5"})}),s&&jsx("button",{type:"button",onClick:s,className:`${h} max-md:hidden`,title:"Duplicate",children:jsx(Copy,{className:"w-3.5 h-3.5"})}),d&&jsx("button",{type:"button",onClick:d,className:`${h} hover:bg-[var(--kyro-danger-bg)] hover:text-[var(--kyro-danger)] max-md:hidden`,title:"Delete",children:jsx(Trash2,{className:"w-3.5 h-3.5"})}),m&&jsx("button",{type:"button",onClick:m,className:`${h} max-md:hidden`,title:"Toggle Sidebar",children:jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsxs("div",{ref:u,className:"relative md:hidden",children:[jsx("button",{type:"button",onClick:()=>y(!g),className:h,title:"More",children:jsx(EllipsisVertical,{className:"w-3.5 h-3.5"})}),g&&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:[S&&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:[jsx("div",{className:`w-1.5 h-1.5 rounded-full ${Ud[e]}`}),jsx("span",{className:"capitalize",children:e}),jsx("span",{children:"\xB7"}),t==="saving"&&jsx(Pr,{size:"sm",className:"inline"}),jsx("span",{children:S})]}),jsx("div",{className:"flex gap-1 px-2 py-2 border-b border-[var(--kyro-border)]",children:R.map(C=>jsx("button",{type:"button",onClick:()=>{x(C),y(false);},className:`px-2.5 py-1 text-[11px] font-semibold rounded-md transition-all flex-1 ${b===C?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)]":"text-[var(--kyro-text-muted)] hover:text-[var(--kyro-text-primary)]"}`,children:C==="edit"?"Edit":C==="version"?"Ver":"API"},C))}),i&&jsxs("button",{type:"button",onClick:()=>{i(),y(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:[jsx(Clock,{className:"w-3.5 h-3.5"})," View History"]}),s&&jsxs("button",{type:"button",onClick:()=>{s(),y(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:[jsx(Copy,{className:"w-3.5 h-3.5"})," Duplicate"]}),l&&jsxs("button",{type:"button",onClick:()=>{l(),y(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:[jsx(Eye,{className:"w-3.5 h-3.5"})," Preview"]}),d&&jsx("div",{className:"border-t border-[var(--kyro-border)] mt-1 pt-1",children:jsxs("button",{type:"button",onClick:()=>{d(),y(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:[jsx(Trash2,{className:"w-3.5 h-3.5"})," Delete"]})})]})]}),jsx("div",{className:"h-4 w-px bg-[var(--kyro-border)] mx-0.5"}),e==="draft"&&a&&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:[jsx(Send,{className:"w-3.5 h-3.5"}),jsx("span",{className:"max-md:hidden",children:"Publish"})]}),e==="published"&&n&&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:[jsx(Undo,{className:"w-3.5 h-3.5"}),jsx("span",{className:"max-md:hidden",children:"Unpublish"})]}),jsxs(To,{status:e,saveStatus:t,hasChanges:r,onPublish:o,children:[s&&jsx(_t,{icon:jsx(Copy,{className:"w-4 h-4"}),children:"Duplicate"}),i&&jsx(_t,{icon:jsx(Clock,{className:"w-4 h-4"}),children:"View History"}),l&&jsx(_t,{icon:jsx(Eye,{className:"w-4 h-4"}),children:"Preview"}),(s||i||l)&&jsx(Ha,{}),d&&jsx(_t,{onClick:d,danger:true,icon:jsx(Trash2,{className:"w-4 h-4"}),children:"Delete"})]})]})]})}function ri({config:e,collection:t,global:r,documentId:o,onBack:a,onSave:n,onDelete:s,onError:i,mode:l="collection"}){let{confirm:d,alert:c}=st(),[m,v]=useState({}),[f,b]=useState({}),[x,g]=useState(true),[y,u]=useState(false),[N,R]=useState("idle"),[S,h]=useState(false),[C,p]=useState("draft"),[P,M]=useState(null),[D,I]=useState(null),[A,re]=useState(null),[me,O]=useState(false),W=r?.fields||t?.fields||[],se=r?.label||t?.label||"Document",X=r?.slug||t?.slug||"",K=JSON.stringify(m)!==JSON.stringify(f);useEffect(()=>{K&&C==="published"&&p("draft");},[K,C]),useEffect(()=>{K&&N==="saved"&&R("idle");},[K,N]),useEffect(()=>{l==="global"?Re():o&&Ne();},[o,l,X]);let Ne=async()=>{try{g(!0);let L=await Be(`/api/${X}/${o}`,{autoToast:!1}),z=L.data||{};v(z),b(z),p(z?.status||L.status||"draft"),M(L.createdAt||z.createdAt||null),I(L.updatedAt||z.updatedAt||null),re(L.publishedAt||z.publishedAt||null);}catch{i("Failed to load document");}finally{g(false);}},Re=async()=>{try{g(!0);let L=await Be(`/api/globals/${X}`,{autoToast:!1}),z=L.data||{};v(z),b(z),M(L.createdAt||null),I(L.updatedAt||null);}catch{i("Failed to load global");}finally{g(false);}},T=useCallback(async(L=false)=>{try{R("saving");let z=l==="global"?`/api/globals/${X}`:`/api/${X}/${o}`,We=C==="draft"||m?.status==="draft",ye=await Xt(z,m,{autoToast:!1,headers:{"X-Draft":String(We)}}),Ae=ye&&(ye.data||ye)||m;L||(b(Ae),n()),v(Ae),p(Ae?.status||C),R("saved"),I(new Date().toISOString()),O(!0),setTimeout(()=>O(!1),3e3),L||(C==="draft"||Ae?.status==="draft"?E.warning("Draft saved"):E.success("Updated")),setTimeout(()=>{R("idle");},2e3);}catch{R("error"),L||(i("Failed to save changes"),E.error("Failed to save changes"));}finally{u(false);}},[m,l,X,o,C,n,i]),_=async()=>{try{u(!0),await Xt(`/api/${X}/${o}`,m,{autoToast:!1,headers:{"X-Draft":"false"}}),p("published"),re(new Date().toISOString()),E.success("Published successfully"),n();}catch{i("Failed to publish"),E.error("Failed to publish");}finally{u(false);}},de=async()=>{try{u(!0),await Xt(`/api/${X}/${o}`,{status:"draft"},{autoToast:!1,headers:{"X-Draft":"false"}}),p("draft"),E.warning("Document unpublished"),n();}catch{i("Failed to unpublish"),E.error("Failed to unpublish");}finally{u(false);}},ke=async()=>{try{u(!0),await ot(`/api/${X}/${o}/duplicate`,void 0,{autoToast:!1}),E.success("Document duplicated");}catch(L){let z=L instanceof Error?L.message:"Failed to duplicate document";i(z),E.error(z);}finally{u(false);}},Ce=()=>{d({title:`Delete ${se}?`,message:"This action cannot be undone.",variant:"danger",onConfirm:async()=>{try{h(!0),await ht(`/api/${X}/${o}`,{autoToast:!1}),s?.(),E.error("Document deleted");}catch(L){let z=L instanceof Error?L.message:"Failed to delete document";E.error(z);}finally{h(false);}}});};if(x)return jsx("div",{className:"kyro-detail",children:jsxs("div",{className:"space-y-6 p-4",children:[jsxs("div",{className:"space-y-2",children:[jsx(Ot,{variant:"text",className:"w-1/3"}),jsx(Ot,{variant:"text",className:"w-2/3"})]}),jsx("div",{className:"space-y-4",children:jsx(Ot,{variant:"rect",count:4})})]})});let he=l==="global"||t?.admin?.layout==="single";return jsxs("div",{className:"kyro-detail",children:[jsx(Pt,{back:{onClick:a},breadcrumbs:[{label:l==="global"?"Globals":"Collections"},{label:se,href:l==="collection"?`${tt}/${X}`:void 0},{label:l==="global"||o?"Edit":"New"}],title:l==="global"?se:fo(t?.fields,m,t?.admin?.useAsTitle||"title")||m.name||o||`New ${t?.singularLabel||se}`,metadata:[jsx(Dt,{variant:C==="published"?"success":"warning",dot:true,className:"text-[10px] font-bold ",children:C},"status")]}),jsx(ei,{status:C,saveStatus:N,hasChanges:K,onSave:()=>T(false),onPublish:_,onUnpublish:C==="published"?de:void 0,onDuplicate:ke,onViewHistory:()=>{window.dispatchEvent(new CustomEvent("kyro:show-version-history"));},onPreview:()=>window.open(`/preview/${X}/${o}`,"_blank"),onDelete:Ce,onBack:a,onToggleSidebar:()=>window.dispatchEvent(new CustomEvent("toggle-sidebar")),publishedAt:A,updatedAt:D}),jsxs("div",{className:he?"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:[jsx("div",{className:"space-y-4 md:space-y-8 min-w-0",children:jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsxs("div",{className:"flex items-center justify-between mb-8 px-1",children:[jsx("h2",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Core Configuration"}),jsx("div",{className:"h-px flex-1 bg-[var(--kyro-border)] ml-6 opacity-30"})]}),jsx(Ka,{config:t?{...t,fields:W}:{slug:"unknown",fields:W},data:m,onChange:v,layout:he?"single":"split",globalSlug:l==="global"?X:void 0,collectionSlug:l==="collection"?X:void 0,onActionSuccess:L=>E.success(L),onActionError:L=>E.error(L),documentStatus:C,justSaved:me}),he&&jsxs("div",{className:"mt-8 pt-8 border-t border-[var(--kyro-border)] flex justify-end gap-3",children:[l==="collection"&&o&&jsx("button",{type:"button",onClick:Ce,className:"kyro-btn kyro-btn-lg kyro-btn-ghost text-[var(--kyro-error)]",children:"Delete"}),jsx(To,{status:C,saveStatus:y?"saving":"idle",hasChanges:K,onPublish:()=>T(false),disabled:y})]})]})}),!he&&jsxs("div",{className:"space-y-4 md:space-y-6 animate-in fade-in slide-in-from-right-4 duration-500",children:[jsxs("div",{className:"surface-tile p-4 md:p-8",children:[jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4 md:mb-6",children:"Metadata"}),jsxs("div",{className:"space-y-4 md:space-y-6",children:[jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Dynamic Status"}),jsx("div",{children:jsx("span",{className:`inline-flex items-center px-3 py-1 rounded-full text-[9px] font-bold tracking-widest ${C==="published"?"bg-green-500/10 text-green-500":"bg-amber-500/10 text-amber-500"}`,children:C||"draft"})})]}),jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Date Created"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:P?new Date(P).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"}):"N/A"})]}),jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Last Modified"}),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"})]}),A&&jsxs("div",{className:"flex flex-col gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-40",children:"Public At"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-text-secondary)]",children:new Date(A).toLocaleString("en-US",{dateStyle:"medium",timeStyle:"short"})})]})]})]}),jsxs("div",{className:"surface-tile p-4 md:p-8 bg-[var(--kyro-bg-secondary)]",children:[jsx("h3",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-3 md:mb-4",children:"Quick Links"}),jsxs("div",{className:"space-y-2 md:space-y-3",children:[jsx("button",{type:"button",onClick:ke,className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"Duplicate Document"}),jsx("button",{type:"button",onClick:()=>window.open(`/preview/${X}/${o}`,"_blank"),className:"kyro-btn kyro-btn-sm kyro-btn-ghost w-full justify-start",children:"View Public Page"}),jsx("button",{type:"button",onClick:Ce,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 oi({config:e,collection:t,onCancel:r,onSuccess:o,onError:a}){let[n,s]=useState({}),[i,l]=useState(false),d=t.fields||[],c=t.label||t.slug,m=async v=>{try{l(!0),await ot(`/api/${t.slug}`,n),E.success(`${t.singularLabel||t.label||"Document"} created`),o();}catch(f){a(f instanceof Error?f.message:"Failed to create");}finally{l(false);}};return jsxs("div",{className:"kyro-detail",children:[jsx(Pt,{back:{onClick:r},breadcrumbs:[{label:"Collections"},{label:c,href:`${tt}/${t.slug}`},{label:"New"}],title:`Create ${t.singularLabel||c}`,action:{label:i?"Creating...":`Create ${t.singularLabel||c}`,onClick:()=>m()}}),jsx("div",{className:"kyro-detail-body",children:jsx("div",{className:"kyro-card",children:jsx("div",{className:"kyro-card-content",children:jsx("form",{children:jsx(Ka,{config:{...t,fields:d},data:n,onChange:s})})})})})]})}function jd({type:e,message:t,onClose:r}){let[o,a]=wa.useState(false),n=wa.useRef(null),s=()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(r,5e3);},i=()=>{n.current&&clearTimeout(n.current);};wa.useEffect(()=>(o?i():s(),i),[o,r]);let l={success:CircleCheck,error:ShieldAlert,warning:TriangleAlert,info:Info}[e];return 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:[jsx("div",{className:"kyro-toast-accent"}),jsx("div",{className:"kyro-toast-icon-container",children:jsx(l,{className:"w-4 h-4"})}),jsx("div",{className:"kyro-toast-content",children:jsx("p",{className:"kyro-toast-message",children:t})}),jsx("button",{type:"button",className:"kyro-toast-close group-hover:opacity-100 opacity-40 transition-opacity",onClick:r,children:jsx(X,{className:"w-3.5 h-3.5"})})]})}function D3({children:e}){return jsx(Fragment,{children:e})}function I3(){let e=Kt(o=>o.addToast),t=Kt(o=>o.removeToast);return {toasts:Kt(o=>o.toasts),addToast:e,removeToast:t}}function Wn(){let e=Kt(r=>r.toasts),t=Kt(r=>r.removeToast);return jsx("div",{className:"kyro-toasts-container",style:{position:"fixed",bottom:"24px",right:"24px",display:"flex",flexDirection:"column",gap:"12px",zIndex:9999,pointerEvents:"none"},children:e.map(r=>jsx("div",{style:{pointerEvents:"auto"},children:jsx(jd,{type:r.type,message:r.message,onClose:()=>t(r.id)})},r.id))})}function si({onAuth:e,theme:t="light"}){let[r,o]=useState("login"),[a,n]=useState(""),[s,i]=useState(""),[l,d]=useState(""),[c,m]=useState(false),[v,f]=useState(false),b=Kt(y=>y.addToast);useEffect(()=>{x();},[]);let x=async()=>{try{await Be("/api/users");}catch{f(true),o("register");}};return jsx(hr,{defaultMode:t,children:jsxs("div",{className:"kyro-login-page",children:[jsxs("div",{className:"kyro-login-container",children:[jsxs("div",{className:"kyro-login-header",children:[jsx("h1",{className:"kyro-login-title",children:v?"Create Admin Account":r==="login"?"Sign In":"Create Account"}),jsx("p",{className:"kyro-login-subtitle",children:v?"Set up your admin account to get started":r==="login"?"Enter your credentials to access the admin":"Create an account to access the admin"})]}),jsxs("form",{onSubmit:async y=>{y.preventDefault(),m(true);try{let u=r==="login"?"/api/auth/login":"/api/auth/register",N={email:a,password:s};r==="register"&&(N.confirmPassword=l);let R=await ot(u,N);R.isFirstUser&&f(!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:[jsxs("div",{className:"kyro-form-group",children:[jsx("label",{htmlFor:"email",children:"Email"}),jsx("input",{id:"email",type:"email",value:a,onChange:y=>n(y.target.value),placeholder:"admin@example.com",required:true,autoComplete:"email"})]}),jsxs("div",{className:"kyro-form-group",children:[jsx("label",{htmlFor:"password",children:"Password"}),jsx("input",{id:"password",type:"password",value:s,onChange:y=>i(y.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:r==="login"?"current-password":"new-password"})]}),r==="register"&&jsxs("div",{className:"kyro-form-group",children:[jsx("label",{htmlFor:"confirmPassword",children:"Confirm Password"}),jsx("input",{id:"confirmPassword",type:"password",value:l,onChange:y=>d(y.target.value),placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",required:true,minLength:8,autoComplete:"new-password"})]}),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"})]}),!v&&jsx("div",{className:"kyro-login-footer",children:jsx("p",{children:r==="login"?jsxs(Fragment,{children:["Don't have an account?"," ",jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("register"),children:"Sign up"})]}):jsxs(Fragment,{children:["Already have an account?"," ",jsx("button",{type:"button",className:"kyro-login-link",onClick:()=>o("login"),children:"Sign in"})]})})})]}),jsx(Wn,{})]})})}function Vd({collections:e,onNavigate:t,user:r}){let{permissions:o}=Or(),[a,n]=useState({totalDocs:0,totalMedia:0,totalUsers:0,recentActivity:[]}),[s,i]=useState(true);useEffect(()=>{let d=setTimeout(()=>{n({totalDocs:124,totalMedia:856,totalUsers:12,recentActivity:[{id:1,type:"edit",user:"Daniel Dozie",doc:"Getting Started with Kyro",collection:"posts",time:"2m ago"},{id:2,type:"create",user:"Jane Smith",doc:"New Product Launch",collection:"products",time:"15m ago"},{id:3,type:"upload",user:"Daniel Dozie",doc:"hero-banner.jpg",collection:"media",time:"1h ago"},{id:4,type:"publish",user:"System",doc:"Weekly Update",collection:"posts",time:"3h ago"}]}),i(false);},800);return ()=>clearTimeout(d)},[]);let l=Object.entries(e).filter(([d])=>!As.includes(d)&&o?.collections?.[d]?.read!==false);return jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 px-8 pb-12",children:[jsx(Pt,{title:`Welcome back, ${r?.email?.split("@")[0]||"Admin"}`,description:"Everything looks great in your command center today.",action:l.length>0&&o?.collections?.[l[0]?.[0]]?.create!==false?{label:"New Document",onClick:()=>t("create",l[0]?.[0]),icon:Plus}:void 0}),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:FileText,color:"text-blue-500"},{label:"Media Assets",value:a.totalMedia,icon:Image,color:"text-purple-500"},{label:"Active Users",value:a.totalUsers,icon:Users,color:"text-green-500"},{label:"System Health",value:"100%",icon:Activity,color:"text-amber-500"}].map((d,c)=>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:[jsxs("div",{children:[jsx("p",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40 mb-1",children:d.label}),jsx("h3",{className:"text-3xl font-bold tracking-tighter",children:s?jsx(Ot,{variant:"text",className:"w-16"}):d.value})]}),jsx("div",{className:`p-3 rounded-2xl bg-[var(--kyro-bg-secondary)] group-hover:scale-110 transition-transform duration-500 ${d.color}`,children:jsx(d.icon,{className:"w-6 h-6"})})]},c))}),jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_400px] gap-8",children:[jsxs("div",{className:"space-y-8 min-w-0",children:[jsxs("section",{className:"surface-tile p-8",children:[jsxs("h2",{className:"text-xl font-bold mb-1 tracking-tight flex items-center gap-2",children:[jsx(LayoutDashboard,{className:"w-5 h-5 opacity-40"}),"Content Growth"]}),jsx("p",{className:"text-[10px] font-bold tracking-widest opacity-40 mb-8",children:"Snapshot of document velocity over the last 7 days"}),jsxs("div",{className:"h-48 w-full relative mb-12",children:[jsxs("svg",{className:"w-full h-full",viewBox:"0 0 1000 200",preserveAspectRatio:"none",children:[jsx("defs",{children:jsxs("linearGradient",{id:"chartGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[jsx("stop",{offset:"0%",stopColor:"var(--kyro-primary)",stopOpacity:"0.3"}),jsx("stop",{offset:"100%",stopColor:"var(--kyro-primary)",stopOpacity:"0"})]})}),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]"}),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)]"})]}),jsxs("div",{className:"flex justify-between mt-4 text-[10px] font-bold opacity-30 tracking-widest ",children:[jsx("span",{children:"Mon"}),jsx("span",{children:"Tue"}),jsx("span",{children:"Wed"}),jsx("span",{children:"Thu"}),jsx("span",{children:"Fri"}),jsx("span",{children:"Sat"}),jsx("span",{children:"Sun"})]})]}),jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:l.map(([d,c])=>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:[jsxs("div",{className:"flex items-center justify-between mb-2",children:[jsx("h3",{className:"font-bold text-lg tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors",children:c.label||d}),jsx(ArrowUpRight,{className:"w-4 h-4 opacity-0 group-hover:opacity-100 transition-all"})]}),jsx("div",{className:"w-full h-1 bg-[var(--kyro-bg-secondary)] rounded-full mb-3 overflow-hidden",children:jsx("div",{className:"h-full bg-[var(--kyro-primary)]",style:{width:`${Math.random()*60+20}%`}})}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] line-clamp-1",children:c.admin?.description||`Manage ${d} content.`})]},d))})]}),jsxs("section",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[jsxs("section",{className:"surface-tile p-6 border border-[var(--kyro-border)] hover:border-[var(--kyro-primary)] transition-all cursor-pointer group",children:[jsx("div",{className:"flex items-center justify-between mb-4",children:jsxs("h3",{className:"text-xl font-bold tracking-tight group-hover:text-[var(--kyro-primary)] transition-colors flex items-center gap-2",children:[jsx(Plus,{className:"w-5 h-5"}),"Quick Links"]})}),jsxs("div",{className:"space-y-3",children:[l.filter(([d])=>o?.collections?.[d]?.create!==false).map(([d])=>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:[jsxs("span",{className:"text-sm font-medium text-[var(--kyro-text-primary)]",children:["New ",e[d]?.singularLabel||e[d]?.label||d]}),jsx(Plus,{className:"w-4 h-4 text-[var(--kyro-text-secondary)] group-hover/btn:text-[var(--kyro-primary)]"})]},d)),l.every(([d])=>o?.collections?.[d]?.create===false)&&jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] py-2",children:"No collections available for creation."})]})]}),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:[jsxs("div",{className:"relative z-10",children:[jsx("h3",{className:"text-2xl font-bold tracking-tighter mb-2",children:"Media Library"}),jsx("p",{className:"opacity-80 text-sm font-medium mb-6",children:"Manage high-fidelity assets with our liquid masonry gallery."}),jsxs("div",{className:"flex items-center gap-2 font-bold text-xs tracking-widest text-blue-400",children:["Open Assets"," ",jsx(ArrowRight,{className:"w-4 h-4 group-hover:translate-x-1 transition-transform"})]})]}),jsx(Image,{className:"absolute bottom-[-20px] right-[-20px] w-48 h-48 opacity-10 rotate-12 group-hover:scale-110 transition-transform duration-1000"})]})]})]}),jsxs("div",{className:"space-y-6",children:[jsxs("section",{className:"surface-tile p-8",children:[jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsx(Clock,{className:"w-5 h-5 opacity-40"}),"Recent Activity"]}),jsx("div",{className:"space-y-6",children:a.recentActivity.map(d=>jsxs("div",{className:"flex gap-4 group",children:[jsx("div",{className:"mt-1",children: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:jsx("span",{className:"text-[10px] font-bold",children:d.user[0]})})}),jsxs("div",{className:"flex-1 border-b border-[var(--kyro-border)] pb-4 group-last:border-none",children:[jsxs("p",{className:"text-sm font-medium text-[var(--kyro-text-primary)] leading-snug",children:[jsx("span",{className:"font-bold",children:d.user})," ",d.type==="create"?"created":d.type==="edit"?"edited":d.type==="publish"?"published":"uploaded"," ",jsxs("span",{className:"text-[var(--kyro-primary)] italic",children:['"',d.doc,'"']})," ","in ",jsx("span",{className:"opacity-60",children:d.collection})]}),jsx("span",{className:"text-[10px] font-bold opacity-40 mt-1 block",children:d.time})]})]},d.id))}),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"})]}),jsxs("section",{className:"surface-tile p-8",children:[jsxs("h2",{className:"text-xl font-bold mb-6 tracking-tight flex items-center gap-2",children:[jsx(Activity,{className:"w-5 h-5 opacity-40"}),"System Status"]}),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)=>jsxs("div",{className:"flex items-center justify-between p-4 bg-[var(--kyro-bg-secondary)] rounded-2xl border border-[var(--kyro-border)]",children:[jsx("span",{className:"text-xs font-bold text-[var(--kyro-text-secondary)]",children:d.label}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:d.status}),jsx("div",{className:`w-2 h-2 rounded-full ${d.pulse} animate-pulse shadow-[0_0_8px] shadow-current`})]})]},c))})]})]})]})]})}function Gd(){let[e,t]=useState([]),[r,o]=useState(true),[a,n]=useState(""),[s,i]=useState(false),[l,d]=useState({name:"",email:"",password:"",role:"customer"}),[c,m]=useState(""),[v,f]=useState(false),{confirm:b,alert:x}=st();useEffect(()=>{g();},[]);let g=async()=>{try{o(!0);let h=await Be("/api/users");t(h.docs||[]);}catch(h){console.error("Failed to load users:",h);}finally{o(false);}},y=h=>{let C=!h.locked;b({title:C?"Lock User Account?":"Unlock User Account?",message:C?`Are you sure you want to lock ${h.email}? They will be immediately logged out and unable to return.`:`Restore system access for ${h.email}?`,variant:C?"danger":"success",onConfirm:async()=>{try{await Xt(`/api/users/${h.id}`,{locked:C}),t(p=>p.map(P=>P.id===h.id?{...P,locked:C}:P)),E.success(C?`Account locked: ${h.email}`:`Account restored: ${h.email}`);}catch(p){console.error("Failed to toggle user lock:",p),E.error("Failed to update account status");}}});},u=h=>{b({title:"Destroy User Account",message:`You are about to permanently delete ${h.email}. This will remove all their data and cannot be undone.`,variant:"danger",confirmLabel:"Destroy Account",onConfirm:async()=>{try{await ht(`/api/users/${h.id}`),t(C=>C.filter(p=>p.id!==h.id)),E.success(`Identity purged: ${h.email}`);}catch(C){console.error("Failed to delete user:",C),E.error("Failed to delete user");}}});},N=async()=>{if(!l.email.trim()||!l.password.trim()){m("Email and password are required");return}f(true),m("");try{await ot("/api/users",{name:l.name.trim()||void 0,email:l.email.trim(),password:l.password,role:l.role}),i(!1),d({name:"",email:"",password:"",role:"customer"}),E.success("User created successfully"),g();}catch(h){let C=h instanceof Error?h.message:"Failed to create user";m(C),E.error(C);}finally{f(false);}},R=["super_admin","admin","editor","author","customer","guest"],S=e.filter(h=>h.email.toLowerCase().includes(a.toLowerCase())||h.name?.toLowerCase().includes(a.toLowerCase()));return 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:[jsx(Pt,{title:"Identity & Access",description:"Manage the core administrative team and security permissions.",icon:Users,action:{label:"New User",onClick:()=>{d({name:"",email:"",password:"",role:"customer"}),m(""),i(true);},icon:UserPlus}}),jsxs("div",{className:"flex flex-col md:flex-row gap-3",children:[jsxs("div",{className:"relative flex-1 group",children:[jsx(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"}),jsx("input",{type:"text",placeholder:"Search by identity or email...",value:a,onChange:h=>n(h.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"})]}),jsxs("div",{className:"flex items-center gap-1 bg-[var(--kyro-surface-accent)] p-1 rounded-xl border border-[var(--kyro-border)]",children:[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"}),jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"ADMINS"}),jsx("button",{className:"px-4 py-1.5 text-[10px] font-bold tracking-widest opacity-40 hover:opacity-100 transition-all",children:"LOCKED"})]})]}),jsx("div",{className:"surface-tile overflow-x-auto",children:jsxs("table",{className:"w-full text-left",children:[jsx("thead",{children: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:[jsx("th",{className:"px-6 py-4 w-64",children:"Member Identity"}),jsx("th",{className:"px-6 py-4",children:"Administrative Role"}),jsx("th",{className:"px-6 py-4",children:"Security Status"}),jsx("th",{className:"px-6 py-4",children:"Last Activity"}),jsx("th",{className:"px-6 py-4 w-32 text-right",children:"Actions"})]})}),jsx("tbody",{className:"divide-y divide-[var(--kyro-border)]",children:r?Array.from({length:6}).map((h,C)=>jsx("tr",{className:"animate-pulse",children:jsx("td",{colSpan:5,className:"px-6 py-5 bg-[var(--kyro-surface-accent)]/30"})},C)):S.length===0?jsx("tr",{children:jsx("td",{colSpan:5,className:"px-6 py-20 text-center",children:jsx("p",{className:"text-xs font-bold opacity-30 tracking-widest uppercase italic",children:"No identity matches found"})})}):S.map(h=>jsxs("tr",{className:`hover:bg-[var(--kyro-surface-accent)]/50 transition-colors group ${h.locked?"opacity-50 grayscale":""}`,children:[jsx("td",{className:"px-6 py-3.5",children:jsxs("div",{className:"flex items-center gap-3",children:[jsx(Uu,{user:h}),jsxs("div",{className:"min-w-0",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{className:"text-xs font-bold text-[var(--kyro-text-primary)] truncate",children:h.name||h.email.split("@")[0]}),h.tenantId&&jsx(Dt,{variant:"outline",className:"text-[7px] px-1 py-0 border-none bg-[var(--kyro-surface-accent)] opacity-50",children:h.tenantId})]}),jsx("div",{className:"text-[10px] text-[var(--kyro-text-secondary)] opacity-50 truncate",children:h.email})]})]})}),jsx("td",{className:"px-6 py-3.5",children:jsxs("div",{className:"flex items-center gap-2",children:[jsx(Shield,{className:"w-3.5 h-3.5 opacity-30"}),jsx("span",{className:"text-[10px] font-bold tracking-widest uppercase opacity-70",children:h.role})]})}),jsx("td",{className:"px-6 py-3.5",children:jsx(Dt,{variant:h.locked?"danger":"success",dot:true,className:"text-[8px] font-bold uppercase tracking-widest",children:h.locked?"Restricted":"Authorized"})}),jsx("td",{className:"px-6 py-3.5",children:jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold text-[var(--kyro-text-secondary)] opacity-50 uppercase tabular-nums",children:[jsx(Clock,{className:"w-3 h-3"}),h.lastLogin?new Date(h.lastLogin).toLocaleDateString():"Never"]})}),jsx("td",{className:"px-6 py-3.5 text-right",children:jsxs("div",{className:"flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-all",children:[jsx("button",{onClick:()=>y(h),className:`p-1.5 rounded-lg border transition-all ${h.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:h.locked?"Restore Access":"Restrict Access",children:h.locked?jsx(LockOpen,{className:"w-3.5 h-3.5"}):jsx(Lock,{className:"w-3.5 h-3.5"})}),jsx("button",{onClick:()=>u(h),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:jsx(Trash2,{className:"w-3.5 h-3.5"})})]})})]},h.id))})]})}),jsxs(Ut,{open:s,onClose:()=>i(false),title:"Create User",size:"lg",children:[jsx(_r,{children:jsxs("div",{className:"space-y-6",children:[jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Name (optional)"}),jsx("input",{type:"text",value:l.name,onChange:h=>d({...l,name:h.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)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Email Address"}),jsx("input",{type:"email",value:l.email,onChange:h=>d({...l,email:h.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)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Password"}),jsx("input",{type:"password",value:l.password,onChange:h=>d({...l,password:h.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)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Role"}),jsx("select",{value:l.role,onChange:h=>d({...l,role:h.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(h=>jsx("option",{value:h,children:h},h))})]}),c&&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:[jsx(TriangleAlert,{className:"w-4 h-4"}),c]})]})}),jsxs(Hr,{children:[jsx("button",{type:"button",onClick:()=>i(false),className:"px-6 py-2.5 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-colors",children:"Cancel"}),jsx("button",{type:"button",onClick:N,disabled:v,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:v?"Creating...":"Create User"})]})]})]})}function Uu({user:e}){let[t,r]=useState(null);return 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?jsx("div",{className:"w-8 h-8 rounded-lg overflow-hidden border border-[var(--kyro-border)] flex-shrink-0",children:jsx("img",{src:t,alt:"",className:"w-full h-full object-cover"})}):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 Wd(){let[e,t]=useState("Kyro CMS"),[r,o]=useState("Command Center"),[a,n]=useState("#6366f1"),[s,i]=useState("Welcome back to your Command Center."),[l,d]=useState(false),[c,m]=useState(false);return useEffect(()=>{(async()=>{try{let x=await Be("/api/globals/site-settings"),g=x.data||x;g&&Object.keys(g).length>0&&(g.siteName&&t(g.siteName),g.adminTitle&&o(g.adminTitle),g.primaryColor&&n(g.primaryColor),g.dashboardGreeting&&i(g.dashboardGreeting));}catch(x){console.error("Failed to load branding:",x);}})();},[]),jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 pt-4",children:[jsxs("div",{children:[jsxs("h1",{className:"text-xl font-bold tracking-tighter text-[var(--kyro-text-primary)]",children:["Branding ",jsx("span",{className:"text-[var(--kyro-primary)]",children:"Hub"})]}),jsx("p",{className:"text-[var(--kyro-text-secondary)] mt-1 font-medium opacity-60",children:"Customize the identity and aesthetic of your administrative ecosystem."})]}),jsx("div",{className:"flex items-center gap-3",children:jsxs("button",{type:"button",onClick:async()=>{d(true);try{await Xt("/api/globals/site-settings",{siteName:e,adminTitle:r,primaryColor:a,dashboardGreeting:s}),m(!0),E.success("Branding updated"),document.documentElement.style.setProperty("--kyro-primary",a),setTimeout(()=>window.location.reload(),800);}catch(b){E.error("Failed to save branding"),console.error(b);}finally{d(false);}},disabled:l,className:`flex items-center gap-2 px-8 py-3 rounded-2xl font-bold text-sm shadow-xl transition-all active:scale-95 ${c?"bg-green-500 text-white":"kyro-btn-primary hover:shadow-[var(--kyro-primary)]"}`,children:[l?jsx(RefreshCcw,{className:"w-4 h-4 animate-spin"}):c?jsx(Check,{className:"w-4 h-4"}):jsx(Save,{className:"w-4 h-4"}),l?"Saving...":c?"Identity Updated":"Publish Branding"]})})]}),jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsx(Tag,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Core Identity"})]}),jsxs("div",{className:"space-y-6",children:[jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Site Public Name"}),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"})]}),jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Admin Dashboard Title"}),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"})]}),jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"System Greeting"}),jsx("textarea",{value:s,onChange:b=>i(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..."})]})]})]}),jsxs("section",{className:"surface-tile p-8 space-y-8",children:[jsxs("div",{className:"flex items-center gap-3 mb-2",children:[jsx(Palette,{className:"w-5 h-5 text-[var(--kyro-primary)]"}),jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Visual Aesthetic"})]}),jsxs("div",{className:"space-y-8",children:[jsxs("div",{className:"space-y-4",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Primary Brand Color"}),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=>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))})]}),jsxs("div",{className:"space-y-4 pt-4 border-t border-[var(--kyro-border)]",children:[jsx("label",{className:"text-[10px] font-bold tracking-[0.2em] opacity-40",children:"Project Logo (SVG/PNG)"}),jsxs("div",{className:"flex items-center gap-6",children:[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:[jsx(Image,{className:"w-6 h-6 mb-1 opacity-40"}),jsx("span",{className:"text-[8px] font-bold ",children:"Upload"})]}),jsxs("div",{className:"flex-1",children:[jsx("p",{className:"text-xs font-bold mb-1",children:"Upload global CMS logo"}),jsx("p",{className:"text-[10px] opacity-40 leading-relaxed",children:"This will replace the Kyro brand in the sidebar and login screens."})]})]})]})]})]}),jsxs("section",{className:"lg:col-span-2 surface-tile p-8 overflow-hidden relative group",children:[jsxs("div",{className:"absolute top-0 right-0 p-8 flex items-center gap-2 text-[var(--kyro-primary)]",children:[jsx(Sparkles,{className:"w-4 h-4"}),jsx("span",{className:"text-[10px] font-bold tracking-widest",children:"Live Preview"})]}),jsxs("div",{className:"max-w-2xl mx-auto py-12 text-center space-y-6",children:[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:[jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),jsxs("span",{className:"text-[10px] font-bold tracking-widest opacity-60",children:[r," Online"]})]}),jsxs("h2",{className:"text-5xl font-bold tracking-tighter leading-none italic",children:["Welcome to ",e,"."]}),jsx("p",{className:"text-xl font-medium text-[var(--kyro-text-secondary)] opacity-60",children:s})]}),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 fu=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function _d({collections:e}){let[t,r]=useState([]),[o,a]=useState(false),[n,s]=useState(null),[i,l]=useState(""),[d,c]=useState(null),[m,u]=useState(false),{confirm:g,alert:x}=ot(),[f,y]=useState(false),[b,v]=useState(""),R=async()=>{try{let p=await De("/api/keys");r(p);}catch(p){console.error(p);}};useEffect(()=>{R();},[]);let L=async()=>{v(""),y(true);},C=async()=>{if(b.trim())try{await et("/api/keys",{name:b}),R(),y(!1),v(""),$.success("API key generated");}catch(p){console.error(p),$.error("Failed to generate API key");}},w=p=>{g({title:"Revoke API Key",message:"Are you sure you want to revoke this key? Any integrations using it will stop working.",variant:"danger",onConfirm:async()=>{try{await kt(`/api/keys/${p}`),R(),$.success("API key revoked");}catch(A){console.error(A),$.error("Failed to revoke API key");}}});},N=async()=>{if(i){u(true);try{let A=await(await fetch(qe(`/api/${i}`))).json();c(A);}catch{c({error:"Failed to fetch. Ensure the endpoint exists."});}finally{u(false);}}};return jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsx(Ft,{title:"Developer Center",description:"Provision access keys and explore the headless API ecosystem.",icon:CodeXml,actions:[{label:"Generate Key",onClick:L,icon:Key}]}),jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-8",children:[jsxs("section",{className:"xl:col-span-2 space-y-6",children:[jsxs("div",{className:"flex items-center gap-2 px-2",children:[jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40 uppercase",children:"Access Credentials"})]}),jsx("div",{className:"space-y-4",children:t.length===0?jsxs("div",{className:"p-12 text-center rounded-[2rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[jsx(Lock,{className:"w-10 h-10 mx-auto mb-4 opacity-20"}),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=>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:jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 relative z-10",children:[jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsx(Key,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors truncate",children:p.name})]}),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:[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"}),jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[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?jsx(EyeOff,{className:"w-4 h-4"}):jsx(Eye,{className:"w-4 h-4"})}),jsx("button",{type:"button",className:"p-1.5 hover:bg-[var(--kyro-surface-accent)] rounded-lg transition-all text-[var(--kyro-text-secondary)]",onClick:()=>{navigator.clipboard.writeText(p.key),$.success("API key copied to clipboard");},children:jsx(Copy,{className:"w-4 h-4"})})]})]}),jsxs("div",{className:"flex items-center gap-6 mt-4 text-[10px] font-bold opacity-30 uppercase tracking-widest",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{children:"Issued:"}),jsx("span",{children:new Date(p.createdAt).toLocaleDateString()})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{children:"Status:"}),jsx("span",{className:"text-green-500",children:"Active"})]})]})]}),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:jsx(Trash2,{className:"w-5 h-5"})})]})},p.id))})]}),jsxs("section",{className:"space-y-6",children:[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:[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:jsx(Terminal,{className:"w-48 h-48 rotate-12"})}),jsxs("div",{className:"relative z-10",children:[jsx("div",{className:"w-12 h-12 bg-white/20 backdrop-blur-md rounded-2xl flex items-center justify-center mb-6",children:jsx(Terminal,{className:"w-6 h-6 text-white"})}),jsx("h3",{className:"text-white text-2xl font-bold tracking-tight mb-3",children:"Endpoint Hub"}),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."}),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",jsx(ExternalLink,{className:"w-3.5 h-3.5"})]})]})]}),jsxs("div",{className:"rounded-[2.5rem] border border-[var(--kyro-border)] bg-[var(--kyro-surface)]/50 p-8 space-y-6",children:[jsx("h4",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Environment Matrix"}),jsxs("div",{className:"space-y-5",children:[jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-xs font-bold",children:"Content API"}),jsx(Pt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Production"})]}),jsxs("div",{className:"group relative",children:[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"}),jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://api.kyro.io/v1"}),jsx(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")})]})]})]}),jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-xs font-bold",children:"Draft Explorer"}),jsx(Pt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Staging"})]}),jsxs("div",{className:"group relative",children:[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"}),jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://preview.kyro.io/v1"}),jsx(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")})]})]})]})]})]})]}),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:[jsx("div",{className:"absolute top-0 right-0 p-20 opacity-[0.02] pointer-events-none",children:jsx(CirclePlay,{className:"w-96 h-96"})}),jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-10 relative z-10",children:[jsxs("div",{className:"max-w-xl",children:[jsxs("h2",{className:"text-3xl font-bold tracking-tighter flex items-center gap-4 mb-3",children:[jsx("div",{className:"w-12 h-12 bg-[var(--kyro-primary)]/10 rounded-2xl flex items-center justify-center",children:jsx(CirclePlay,{className:"w-7 h-7 text-[var(--kyro-primary)]"})}),"API ",jsx("span",{className:"text-[var(--kyro-primary)]",children:"Explorer"})]}),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."})]}),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:[jsxs("div",{className:"flex-1 relative flex items-center pl-6",children:[jsxs("span",{className:"text-[11px] font-bold opacity-30 uppercase tracking-widest mr-2 whitespace-nowrap",children:["GET ",fu,"/"]}),jsx("input",{type:"text",value:i,onChange:p=>l(p.target.value),placeholder:"collection-slug",className:"w-full py-4 bg-transparent focus:outline-none font-mono text-sm font-bold text-[var(--kyro-primary)]"})]}),jsxs("button",{type:"button",onClick:N,disabled:m||!i,className:"kyro-btn kyro-btn-primary px-8 py-4 rounded-[1.5rem] font-bold text-sm shadow-xl disabled:opacity-50 disabled:cursor-not-allowed hover:scale-[1.02] transition-all flex items-center gap-3 shrink-0",children:[m?jsx(RefreshCcw,{className:"w-4 h-4 animate-spin"}):jsx(ChevronRight,{className:"w-5 h-5"}),"Run Query"]})]})]}),d?jsxs("div",{className:"animate-in fade-in zoom-in-95 duration-500 relative z-10",children:[jsxs("div",{className:"flex items-center justify-between mb-4 px-2",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"w-1 h-3 bg-[var(--kyro-primary)] rounded-full"}),jsx("span",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Response Payload"})]}),jsx(Pt,{variant:"outline",className:"text-[9px] font-mono px-3",children:"200 OK"})]}),jsxs("div",{className:"rounded-[2rem] overflow-hidden border border-[var(--kyro-border)] shadow-2xl bg-[#090b10]",children:[jsxs("div",{className:"flex items-center gap-2 px-6 py-4 bg-[#11141d] border-b border-[var(--kyro-border)]/50",children:[jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500/20"}),jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-amber-500/20"}),jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500/20"})]}),jsx(mu,{value:JSON.stringify(d,null,2),height:"450px",theme:aura,extensions:[json()],editable:false,className:"text-sm"})]})]}):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:[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:jsx(CodeXml,{className:"w-10 h-10"})}),jsx("p",{className:"font-bold text-sm opacity-30 uppercase tracking-[0.2em]",children:"Awaiting request dispatch..."})]})]})]}),jsxs(Ut,{open:f,onClose:()=>y(false),title:"Generate Access Token",size:"lg",children:[jsx(Or,{children:jsxs("div",{className:"space-y-6",children:[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."}),jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Token Name"}),jsx("input",{type:"text",value:b,onChange:p=>v(p.target.value),placeholder:"e.g., Mobile App SDK, Production Server",className:"w-full px-6 py-4 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-2xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)] shadow-sm transition-all",onKeyDown:p=>p.key==="Enter"&&C()})]})]})}),jsxs(Ur,{children:[jsx("button",{type:"button",onClick:()=>y(false),className:"px-6 py-3 rounded-xl font-bold text-sm border border-[var(--kyro-border)] text-[var(--kyro-text-secondary)] hover:bg-[var(--kyro-surface-accent)] transition-all",children:"Cancel"}),jsx("button",{type:"button",onClick:C,className:"kyro-btn kyro-btn-primary px-8 py-3 rounded-xl font-bold text-sm hover:opacity-90 shadow-lg shadow-[var(--kyro-primary)]/20 transition-all",children:"Generate Token"})]})]})]})}function Vd(e){let[t,r]=useState([]),[o,a]=useState(false),[n,s]=useState(null),[i,l]=useState(false),{confirm:d}=ot(),c=useCallback(async()=>{a(true),s(null);try{let x=await De(e.endpoint),f=Array.isArray(x)?x:x.docs||[],y=e.transformLoad?e.transformLoad(f):f;r(y),e.onSuccess?.("load",y);}catch(x){let f=x instanceof Error?x.message:"Failed to load resources";s(f),e.onError?.("load",x);}finally{a(false);}},[e.endpoint,e.transformLoad]);useEffect(()=>{c();},[c]);let m=useCallback((x,f="item")=>{d({title:`Delete ${f}`,message:`Are you sure you want to delete this ${f.toLowerCase()}? This action cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await kt(`${e.endpoint}/${x}`),r(y=>y.filter(b=>b.id!==x)),e.onSuccess?.("delete",x),$.success(`${f} deleted`);}catch(y){let b=y instanceof Error?y.message:`Failed to delete ${f}`;$.error(b),e.onError?.("delete",y);}}});},[e.endpoint,d]),u=useCallback(async x=>{s(null);try{let f=await et(e.endpoint,x);return r(y=>[f,...y]),l(!1),e.onSuccess?.("create",f),f}catch(f){let y=f instanceof Error?f.message:"Failed to create resource";throw s(y),e.onError?.("create",f),f}},[e.endpoint]),g=useCallback(async(x,f)=>{s(null);try{let y=await Xt(`${e.endpoint}/${x}`,f);return r(b=>b.map(v=>v.id===x?y:v)),e.onSuccess?.("update",y),y}catch(y){let b=y instanceof Error?y.message:"Failed to update resource";throw s(b),e.onError?.("update",y),y}},[e.endpoint]);return {items:t,setItems:r,loading:o,error:n,load:c,remove:m,create:u,update:g,isCreateModalOpen:i,setIsCreateModalOpen:l}}function Kd(){let{items:e,loading:t,create:r,remove:o,update:a,isCreateModalOpen:n,setIsCreateModalOpen:s}=Vd({endpoint:"/api/webhooks"}),{confirm:i}=ot(),[l,d]=useState(false),[c,m]=useState(false),[u,g]=useState(null),[x,f]=useState(null),[y,b]=useState({name:"",url:"",events:[],secret:""}),[v,R]=useState(""),L=async()=>{if(!y.name.trim()||!y.url.trim()){R("Name and URL are required");return}try{await r(y),b({name:"",url:"",events:[],secret:""}),$.success(`Webhook established: ${y.name}`);}catch{R("Failed to create webhook"),$.error("Failed to create webhook");}},C=async p=>{f(p),g(null),d(true);try{let A=await et(`/api/webhooks/${p}/test`);g({success:!0,message:A.message||"Webhook triggered successfully"}),$.success("Dispatch verified: Remote endpoint responded");}catch{g({success:false,message:"Failed to trigger webhook"});}},w=async(p,A)=>{try{let O=A==="active"?"paused":"active";await a(p,{status:O}),$.success(O==="active"?"Signals resumed":"Dispatcher paused");}catch(O){console.error(O),$.error("Failed to toggle webhook status");}},N=[{label:"Create",value:"create",description:"When a new document is created"},{label:"Update",value:"update",description:"When a document is updated"},{label:"Delete",value:"delete",description:"When a document is deleted"},{label:"Auth",value:"auth",description:"User login/logout events"}];return jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsx(Ft,{title:"Webhooks",description:"Receive real-time notifications when your content changes.",icon:Webhook,actions:[{label:"Create Webhook",onClick:()=>{b({name:"",url:"",events:["collection.create","collection.update","collection.delete"],secret:""}),R(""),s(true);},icon:Plus},{label:"Guide",onClick:()=>m(true),icon:Info,variant:"outline"}]}),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:[jsx("div",{className:"absolute top-0 right-0 p-8 opacity-[0.03] pointer-events-none",children:jsx(Zap,{className:"w-64 h-64 rotate-12"})}),jsxs("div",{className:"flex flex-col md:flex-row items-center gap-8 relative z-10",children:[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:jsx(Zap,{className:"w-8 h-8 text-white"})}),jsxs("div",{className:"flex-1 text-center md:text-left",children:[jsx("h3",{className:"text-xl font-bold mb-2",children:"Real-time Event Synchronization"}),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."})]}),jsxs("div",{className:"flex gap-4",children:[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:[jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Collections"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"Triggered"})]}),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:[jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Latency"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"<200ms"})]})]})]})]}),jsxs("section",{className:"space-y-6",children:[jsxs("div",{className:"flex items-center justify-between px-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40",children:"ACTIVE ENDPOINTS"})]}),jsxs("div",{className:"text-[10px] font-bold opacity-40 uppercase",children:[e.length," Hook",e.length!==1&&"s"]})]}),t?jsx("div",{className:"flex items-center justify-center p-20 surface-tile rounded-3xl opacity-50 italic",children:"Connecting to dispatcher..."}):e.length===0?jsxs("div",{className:"p-16 text-center rounded-[3rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[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:jsx(Webhook,{className:"w-10 h-10 text-[var(--kyro-primary)]"})}),jsx("h3",{className:"text-2xl font-bold mb-3",children:"No Webhooks Found"}),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."}),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:[jsx(Plus,{className:"w-5 h-5"}),"Configure Webhook"]})]}):jsx("div",{className:"grid gap-4",children:e.map(p=>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:jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 relative z-10",children:[jsxs("div",{className:"flex-1",children:[jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsx(Webhook,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsxs("div",{children:[jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors",children:p.name}),jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[jsx("span",{className:`w-2 h-2 rounded-full ${p.status==="active"?"bg-green-500 animate-pulse":"bg-amber-500"}`}),jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${p.status==="active"?"text-green-500":"text-amber-500"}`,children:p.status})]})]})]}),jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 pt-2",children:[jsxs("div",{className:"space-y-1",children:[jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Destination"}),jsx("div",{className:"font-mono text-xs opacity-60 truncate max-w-[200px]",title:p.url,children:p.url})]}),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:[jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Events"}),jsxs("div",{className:"flex flex-wrap gap-1",children:[p.events.slice(0,2).map(A=>jsx(Pt,{variant:"outline",className:"text-[8px] font-bold px-1.5 opacity-60",children:A},A)),p.events.length>2&&jsxs("span",{className:"text-[8px] font-bold opacity-30",children:["+",p.events.length-2," more"]})]})]}),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:[jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Activity"}),jsxs("div",{className:"text-[10px] font-bold opacity-60 flex items-center gap-1.5",children:[jsx(Clock,{className:"w-3 h-3"}),p.lastTriggered?`Last triggered: ${new Date(p.lastTriggered).toLocaleDateString()}`:"Never triggered"]})]})]})]}),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:[jsxs("button",{type:"button",onClick:()=>C(p.id),className:"flex-1 lg:flex-none p-3 bg-[var(--kyro-surface)] border border-[var(--kyro-border)] rounded-xl hover:border-[var(--kyro-primary)] transition-all flex items-center justify-center gap-2",title:"Send test request",children:[jsx(Send,{className:"w-4 h-4"}),jsx("span",{className:"text-xs font-bold",children:"Test"})]}),jsx("div",{className:"w-px h-6 bg-[var(--kyro-border)] mx-1 hidden lg:block"}),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"?jsx(Pause,{className:"w-4 h-4"}):jsx(Play,{className:"w-4 h-4"})}),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:jsx(Trash2,{className:"w-4 h-4 text-red-500/50 group-hover/delete:text-red-500"})})]})]})},p.id))})]}),jsxs(Ut,{open:n,onClose:()=>s(false),title:"Register Webhook",size:"lg",children:[jsx(Or,{children:jsxs("div",{className:"space-y-6",children:[jsxs("div",{className:"flex flex-col gap-6",children:[jsxs("div",{className:"space-y-4",children:[jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Webhook Name"}),jsx("input",{type:"text",value:y.name,onChange:p=>b({...y,name:p.target.value}),placeholder:"e.g., Slack Notifications",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Payload URL"}),jsx("input",{type:"url",value:y.url,onChange:p=>b({...y,url:p.target.value}),placeholder:"https://your-server.com/webhook",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Signing Secret"}),jsx("input",{type:"text",value:y.secret,onChange:p=>b({...y,secret:p.target.value}),placeholder:"Optional secret for verification",className:"w-full px-4 py-3 bg-[var(--kyro-bg)] border border-[var(--kyro-border)] rounded-xl text-[var(--kyro-text-primary)] focus:outline-none focus:border-[var(--kyro-primary)]"})]})]}),jsxs("div",{className:"space-y-4",children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Subscribed Events"}),jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:N.map(p=>jsxs("button",{type:"button",onClick:()=>{let A=y.events.includes(p.value)?y.events.filter(O=>O!==p.value):[...y.events,p.value];b({...y,events:A});},className:`flex items-center gap-3 p-3 rounded-lg border transition-all text-left ${y.events.includes(p.value)?"bg-[var(--kyro-primary)]/5 border-[var(--kyro-primary)]/30 text-[var(--kyro-primary)]":"bg-[var(--kyro-surface-accent)]/50 border-[var(--kyro-border)] hover:border-[var(--kyro-primary)]/30"}`,children:[jsx("div",{className:`w-4 h-4 rounded flex items-center justify-center border transition-all ${y.events.includes(p.value)?"bg-[var(--kyro-primary)] border-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:y.events.includes(p.value)&&jsx(CircleCheck,{className:"w-3 h-3 text-white"})}),jsxs("div",{children:[jsx("div",{className:"text-xs font-bold",children:p.label}),jsx("div",{className:"text-[10px] opacity-50",children:p.description})]})]},p.value))})]})]}),v&&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:[jsx(TriangleAlert,{className:"w-4 h-4"}),v]})]})}),jsxs(Ur,{children:[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"}),jsx("button",{type:"button",onClick:L,className:"kyro-btn kyro-btn-primary px-6 py-2.5 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/10",children:"Create Webhook"})]})]}),jsxs(Ut,{open:l,onClose:()=>d(false),title:"Webhook Test Dispatcher",children:[jsx(Or,{children:jsx("div",{className:"p-8 rounded-[2rem] bg-[var(--kyro-surface-accent)]/30 border border-[var(--kyro-border)] text-center",children:u?jsxs("div",{className:"space-y-6",children:[jsx("div",{className:`w-16 h-16 mx-auto rounded-2xl flex items-center justify-center shadow-xl ${u.success?"bg-green-500/10 text-green-500":"bg-red-500/10 text-red-500"}`,children:u.success?jsx(CircleCheck,{className:"w-8 h-8"}):jsx(TriangleAlert,{className:"w-8 h-8"})}),jsxs("div",{children:[jsx("h4",{className:"text-xl font-bold mb-2",children:u.success?"Dispatch Successful":"Dispatch Failed"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70",children:u.message})]})]}):jsxs("div",{className:"space-y-6 py-4",children:[jsx(RefreshCw,{className:"w-12 h-12 text-[var(--kyro-primary)] animate-spin mx-auto opacity-50"}),jsxs("div",{children:[jsx("h4",{className:"text-xl font-bold mb-1",children:"Synthesizing Payload"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-50 italic",children:"Dispatching to remote endpoint..."})]})]})})}),jsx(Ur,{children: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"})})]}),jsxs(Ut,{open:c,onClose:()=>m(false),title:"Webhook Integration Guide",size:"lg",children:[jsx(Or,{children:jsxs("div",{className:"space-y-8",children:[jsxs("div",{className:"grid grid-cols-1 gap-6",children:[jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsx(ExternalLink,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Request Context"]}),jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["When an event triggers, Kyro sends a standard ",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."]})]}),jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsx(Shield,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Security Verification"]}),jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["If a secret is provided, each request includes an ",jsx("span",{className:"font-mono text-[var(--kyro-primary)]",children:"X-Kyro-Signature"})," header. Always verify this signature in production environments."]})]})]}),jsxs("div",{className:"space-y-3",children:[jsx("h4",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Payload Architecture"}),jsxs("div",{className:"relative group",children:[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"}),jsxs("div",{className:"relative bg-[var(--kyro-bg)] rounded-2xl border border-[var(--kyro-border)] p-6 font-mono text-sm overflow-hidden",children:[jsxs("div",{className:"flex items-center gap-2 mb-4 border-b border-[var(--kyro-border)] pb-4 opacity-30",children:[jsx("div",{className:"w-2 h-2 rounded-full bg-red-500/50"}),jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500/50"}),jsx("div",{className:"w-2 h-2 rounded-full bg-green-500/50"}),jsx("span",{className:"text-[10px] ml-2 tracking-tighter",children:"payload.json"})]}),jsxs("div",{className:"space-y-1",children:[jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"{"}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"event"'}),": ",jsx("span",{className:"text-green-500",children:'"collection.create"'}),","]}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"collection"'}),": ",jsx("span",{className:"text-green-500",children:'"products"'}),","]}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"id"'}),": ",jsx("span",{className:"text-green-500",children:'"prod_8273"'}),","]}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"timestamp"'}),": ",jsx("span",{className:"text-green-500",children:'"2026-05-14T02:53:22Z"'})]}),jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"}"})]})]})]})]})]})}),jsx(Ur,{children:jsx("button",{type:"button",onClick:()=>m(false),className:"kyro-btn kyro-btn-primary w-full py-3 rounded-xl font-bold text-sm hover:opacity-90 transition-all shadow-lg shadow-[var(--kyro-primary)]/20",children:"I Understand"})})]})]})}function qd({isOpen:e,onClose:t,collections:r,globals:o,onNavigate:a}){let{user:n,permissions:s}=Lr(),[i,l]=useState(""),[d,c]=useState(0),[m,u]=useState(false),[g,x]=useState([]),f=useRef(null),y=useRef(null);useEffect(()=>{e&&(l(""),c(0),x([]),u(false),setTimeout(()=>f.current?.focus(),100));},[e]);let b=useCallback(async S=>{if(!S||S.length<2){x([]);return}u(true);try{let j=await(await fetch(qe(`/api/search?q=${encodeURIComponent(S)}&limit=15`))).json();j.results&&x(j.results);}catch(M){console.error("Search error:",M),x([]);}finally{u(false);}},[]);if(useEffect(()=>(y.current&&clearTimeout(y.current),i.length>=2?y.current=setTimeout(()=>b(i),300):x([]),()=>{y.current&&clearTimeout(y.current);}),[i,b]),!e)return null;let v=Object.entries(r).filter(([S])=>s?.collections?.[S]?.read!==false).map(([S,M])=>({id:`col-${S}`,label:M.label||S,type:"collection",slug:S,icon:FileText})),R=Object.entries(o).filter(([S])=>s?.globals?.[S]?.read!==false).map(([S,M])=>({id:`global-${S}`,label:M.label||S,type:"global",slug:S,icon:Settings})),L=typeof document<"u"&&document.documentElement.classList.contains("dark"),C=n?.role==="admin",w=[{id:"action-media",label:"Media Gallery",type:"action",view:"media",icon:Image,visible:s?.collections?.media?.read!==false},{id:"action-users",label:"Team Management",type:"action",view:"users",icon:Clock,visible:C},{id:"action-audit",label:"Audit Logs",type:"action",view:"audit",icon:File,visible:C},{id:"action-roles",label:"Roles & Permissions",type:"action",view:"roles",icon:Shield,visible:C},{id:"action-api",label:"REST API Explorer",type:"action",view:"api-explorer",icon:Database,visible:C},{id:"action-graphql",label:"GraphQL Playground",type:"action",view:"graphql",icon:Hexagon,visible:C},{id:"action-rest",label:"REST Playground",type:"action",view:"rest",icon:Network,visible:C},{id:"action-theme",label:L?"Switch to Light Mode":"Switch to Dark Mode",type:"action",view:"theme",icon:L?Sun:Moon,visible:true},{id:"action-logout",label:"Sign Out",type:"action",view:"logout",icon:LogOut,visible:true}].filter(S=>S.visible),N=g.map((S,M)=>({id:`doc-${S.collection}-${S.id}`,label:S.title,type:"document",collection:S.collection,label2:S.label,docId:S.id,icon:File,doc:S.doc})),p=i.length>=2?[...w,...v,...R,...N]:[...w,...v,...R],A=i===""?p:p.filter(S=>S.label.toLowerCase().includes(i.toLowerCase())),O=S=>{if(S.key==="ArrowDown")S.preventDefault(),c(M=>(M+1)%A.length);else if(S.key==="ArrowUp")S.preventDefault(),c(M=>(M-1+A.length)%A.length);else if(S.key==="Enter"){let M=A[d];M&&F(M);}else S.key==="Escape"&&t();},F=S=>{S.type==="collection"?S.slug==="users"?a(S.slug,S.slug):a("list",S.slug):S.type==="global"?a("settings",S.slug):S.type==="document"?S.collection==="users"?a("users","users",S.docId):a("edit",S.collection,S.docId):S.type==="action"&&(S.view==="users"?a("users","users"):S.view==="media"?a("media","media"):a(S.view,S.view)),t();},P=()=>i===""?"Quick Actions & Collections":g.length>0?"Documents":m?"Searching...":"Search Results";return jsxs("div",{className:"fixed inset-0 z-[1000] flex items-start justify-center pt-[15vh] px-4",children:[jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm animate-in fade-in duration-300",onClick:t}),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:[jsxs("div",{className:"flex items-center px-6 py-5 border-b border-[var(--kyro-border)]",children:[m?jsx(LoaderCircle,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4 animate-spin"}):jsx(Search,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4"}),jsx("input",{ref:f,placeholder:"Search anything...",className:"flex-1 bg-transparent border-none focus:outline-none text-lg font-medium text-[var(--kyro-text-primary)] placeholder:text-[var(--kyro-text-muted)]",value:i,onChange:S=>l(S.target.value),onKeyDown:O}),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:jsx("span",{className:"text-[10px] font-bold opacity-40 tracking-widest",children:"ESC"})})]}),jsx("div",{className:"max-h-[400px] overflow-y-auto py-4",children:A.length>0?jsxs("div",{className:"space-y-1 px-4",children:[jsx("p",{className:"px-4 text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4",children:P()}),A.map((S,M)=>jsxs("div",{onClick:()=>F(S),onMouseEnter:()=>c(M),className:`flex items-center justify-between px-4 py-4 rounded-2xl cursor-pointer ${M===d?"bg-[var(--kyro-primary)] text-[var(--kyro-sidebar-text-active)] shadow-xl shadow-[var(--kyro-primary)]":"hover:bg-[var(--kyro-bg-secondary)] text-[var(--kyro-text-secondary)]"}`,children:[jsxs("div",{className:"flex items-center gap-4",children:[jsx("div",{className:`p-2 rounded-xl ${M===d?"bg-white/20":"bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)]"}`,children:jsx(S.icon,{className:"w-4 h-4"})}),jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"font-bold text-sm",children:S.label}),S.type==="document"&&S.label2&&jsx("span",{className:`text-[10px] font-bold tracking-widest ${M===d?"text-[var(--kyro-sidebar-text-active)]/60":"opacity-40"}`,children:S.label2})]})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:`text-[10px] font-bold tracking-widest opacity-40 ${M===d?"text-[var(--kyro-sidebar-text-active)] p-1":""}`,children:S.type}),M===d&&jsx(ArrowRight,{className:"w-4 h-4 mr-2"})]})]},S.id))]}):jsx("div",{className:"py-12 text-center",children:jsx("p",{className:"text-[var(--kyro-text-secondary)] italic opacity-60",children:i.length>=2&&!m?`No results found for "${i}"`:"Start typing to search..."})})}),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:[jsxs("div",{className:"flex gap-6",children:[jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u2191\u2193 Navigate"}),jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u23CE Select"})]}),jsx("div",{children:"Kyro Universal Search"})]})]})]})}function Jd(){let{modal:e,closeModal:t}=ot(),[r,o]=useState(false);if(!e.open||!e.config)return null;let{config:a}=e,n=async()=>{if(a.onConfirm)try{o(!0),await a.onConfirm();}catch(i){console.error("Modal confirm action failed:",i);}finally{o(false),t();}else t();},s=()=>{a.onCancel&&a.onCancel(),t();};return jsx(bs,{open:e.open,onClose:s,onConfirm:n,title:a.title,message:a.message,confirmLabel:a.confirmLabel,cancelLabel:a.cancelLabel,variant:a.variant==="danger"?"danger":"default",loading:r})}function ku({config:e,theme:t="light",onThemeChange:r}){let[o,a]=useState(false),[n,s]=useState(null),i=useMemo(()=>Dn(Fa(e.collections)),[e.collections]),l=useMemo(()=>Bn(Fa(e.globals)),[e.globals]),[d,c]=useState(null),[m,u]=useState(null),[g,x]=useState("list"),[f,y]=useState(null),[b,v]=useState(false);useEffect(()=>{(async()=>{try{let N=await fetch("/api/users/me");if(N.ok){let p=await N.json();s(p),a(!0);}}catch(N){console.error("Auth check failed",N);}})();},[]),useEffect(()=>{if(o&&!d){let w=Object.keys(i)[0];w&&c(w);}},[o,i,d]);let R=(w,N=null,p=null)=>{x(w),N&&c(N),p&&y(p),v(false);};useEffect(()=>{let w=N=>{(N.metaKey||N.ctrlKey)&&N.key==="k"&&(N.preventDefault(),v(p=>!p));};return window.addEventListener("keydown",w),window.openCommandPalette=()=>v(true),()=>{window.removeEventListener("keydown",w),delete window.openCommandPalette;}},[]);return o?jsx(kr,{mode:t,onChange:r,children:jsxs("div",{className:"kyro-admin min-h-screen bg-[var(--kyro-bg)] text-[var(--kyro-text-primary)]",children:[jsx("div",{className:"flex h-screen overflow-hidden",children:jsx("main",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:jsxs("div",{className:"flex-1 overflow-y-auto",children:[jsx(qd,{isOpen:b,onClose:()=>v(false),collections:i,globals:l,onNavigate:R}),(()=>{let w=d?i[d]:null;switch(g){case "create":return w?jsx(Zs,{config:e,collection:w,onSuccess:()=>x("list"),onCancel:()=>x("list"),onError:N=>$.error(N)}):null;case "detail":return w&&f?jsx(Ys,{config:e,collection:w,documentId:f,onBack:()=>x("list"),onSave:()=>{},onError:N=>$.error(N)}):null;case "users":return jsx(jd,{});case "media":return jsx(xn,{});case "branding":return jsx(Hd,{});case "developer":return jsx(_d,{collections:i});case "webhooks":return jsx(Kd,{});default:return w?jsx(fs,{config:e,collection:w,onCreate:()=>x("create"),onEdit:N=>R("detail",d,N)}):jsx(Ud,{onNavigate:R,collections:i,user:n})}})()]})})}),jsx(Jd,{}),jsx(Gn,{})]})}):jsx(ri,{onAuth:(w,N)=>{s(N),a(true);},theme:t})}function hu({selectedCount:e,onClearSelection:t,actions:r,onSelectAll:o}){return e===0?null:jsxs("div",{className:"flex items-center justify-between py-2 px-4 bg-gray-50 border-b border-gray-200",children:[jsxs("div",{className:"flex items-center gap-4",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx(ps,{count:e}),jsx("span",{className:"text-sm text-gray-600",children:"selected"})]}),jsx("button",{type:"button",onClick:t,className:"text-sm text-gray-500 hover:text-gray-700",children:"Clear selection"}),o&&jsx("button",{type:"button",onClick:o,className:"text-sm text-gray-500 hover:text-gray-700",children:"Select all"})]}),jsx(wo,{trigger:jsxs("button",{type:"button",className:"kyro-btn kyro-btn-secondary kyro-btn-sm",children:["Actions",jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M6 9l6 6 6-6"})})]}),children:r.map((a,n)=>jsx(Ht,{onClick:a.onClick,icon:a.icon,danger:a.danger,children:a.label},n))})]})}function Fu({open:e,onClose:t,versions:r,currentVersionId:o,onPreview:a,onRestore:n,onCompare:s,loading:i=false}){let l=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime())){let u=Date.parse(c);return isNaN(u)?"Invalid date":new Date(u).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}return m.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})},d=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime()))return l(c);let g=new Date().getTime()-m.getTime();if(g<0)return "Just now";let x=Math.floor(g/6e4),f=Math.floor(g/36e5),y=Math.floor(g/864e5);return x<1?"Just now":x<60?`${x}m ago`:f<24?`${f}h ago`:y<7?`${y}d ago`:l(c)};return jsx(dr,{open:e,onClose:t,title:"Version History",width:"md",children:i?jsx("div",{className:"flex items-center justify-center py-12",children:jsx(Ar,{})}):r.length===0?jsxs("div",{className:"text-center flex flex-col items-center justify-center py-16 text-[var(--kyro-text-muted)]",children:[jsx(History,{className:"w-12 h-12 mb-4 opacity-20"}),jsx("p",{className:"font-medium text-[var(--kyro-text)]",children:"No version history yet"}),jsx("p",{className:"text-sm mt-1",children:"Versions are automatically saved as you work."})]}):jsx("div",{className:"space-y-3 px-1 pb-4 pt-1",children:r.map(c=>{let m=c.id===o;return 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&&jsx("div",{className:"absolute top-0 left-0 w-1 h-full bg-[var(--kyro-primary)] shadow-[0_0_8px_var(--kyro-primary)]"}),jsxs("div",{className:"flex items-start justify-between gap-4",children:[jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-2 mb-2",children:[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"&&jsx(CheckCircle2,{className:"w-3 h-3"}),c.status==="published"?"Published":"Draft"]}),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&&jsxs("span",{className:"text-[10px] font-medium text-[var(--kyro-primary)] flex items-center gap-1",children:[jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-primary)] animate-pulse"}),"Current"]})]}),jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium text-[var(--kyro-text)] truncate mb-1",children:[jsx(Clock,{className:"w-3.5 h-3.5 text-[var(--kyro-text-muted)]"}),d(c.createdAt)]}),c.createdBy&&jsxs("div",{className:"flex items-center gap-1.5 text-xs text-[var(--kyro-text-muted)] mt-1.5",children:[jsx(User,{className:"w-3.5 h-3.5"}),jsx("span",{children:c.createdBy.name||c.createdBy.email})]}),c.changelog&&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,'"']})]}),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:[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:jsx(Eye,{className:"w-4 h-4"})}),s&&jsx("button",{type:"button",onClick:()=>s(c,r.find(u=>u.id===o)||c),className:"p-2 text-[var(--kyro-text-secondary)] hover:text-[var(--kyro-primary)] hover:bg-[var(--kyro-primary)]/10 rounded-md transition-colors",title:"Compare with current",children:jsx(GitCompare,{className:"w-4 h-4"})}),!m&&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:jsx(Undo2,{className:"w-4 h-4"})})]})]})]},c.id)})})})}function ZT({title:e,onMenuClick:t,actions:r}){return jsxs("header",{className:"kyro-header",children:[jsxs("div",{className:"kyro-header-left",children:[jsx("button",{type:"button",className:"kyro-header-menu",onClick:t,"aria-label":"Toggle menu",children:jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M3 12h18M3 6h18M3 18h18"})})}),jsx("h1",{className:"kyro-header-title",children:e})]}),jsxs("div",{className:"kyro-header-right",children:[r,jsx("div",{className:"kyro-header-user",children:jsx("button",{type:"button",className:"kyro-header-user-btn",children:jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("circle",{cx:"12",cy:"8",r:"4"}),jsx("path",{d:"M4 20c0-4 4-6 8-6s8 2 8 6"})]})})})]})]})}var nr={ready:[],beforeDeploy:[],afterDeploy:[]};function Yn(e){return nr.ready.push(e),()=>{nr.ready=nr.ready.filter(t=>t!==e);}}function Yd(e){return nr.beforeDeploy.push(e),()=>{nr.beforeDeploy=nr.beforeDeploy.filter(t=>t!==e);}}function Zd(e){return nr.afterDeploy.push(e),()=>{nr.afterDeploy=nr.afterDeploy.filter(t=>t!==e);}}async function ec(e){let t=[];for(let r of nr.ready)try{let o=await r(e);o&&typeof o=="object"&&"success"in o&&t.push(o);}catch(o){t.push({success:false,error:String(o)});}return t}async function tc(e){let t=[];for(let r of nr.beforeDeploy)try{let o=await r(e);o&&typeof o=="object"&&"success"in o&&t.push(o);}catch(o){t.push({success:false,error:String(o)});}return t}async function rc(e,t){for(let r of nr.afterDeploy)try{await r(e,t);}catch{}}function ac(e){return `${typeof window<"u"?window.location.origin:""}${e}`}function nc(e,t={}){let[r,o]=useState(null),[a,n]=useState(true),[s,i]=useState(null),l=useCallback(async()=>{n(true),i(null);try{let d=new URLSearchParams;t.page&&d.set("page",String(t.page)),t.limit&&d.set("limit",String(t.limit)),t.sort&&d.set("sort",t.sort),t.order&&d.set("order",t.order);let c=`${ac(`/api/${e}`)}?${d.toString()}`,m=await fetch(c,{credentials:"include"});if(!m.ok)throw new Error(`HTTP ${m.status}: ${m.statusText}`);let u=await m.json();o(u.data??u);}catch(d){i(d instanceof Error?d.message:String(d));}finally{n(false);}},[e,t.page,t.limit,t.sort,t.order]);return useEffect(()=>{l();},[l]),{data:r,loading:a,error:s,refetch:l}}function sc(e,t="POST"){let[r,o]=useState(false),[a,n]=useState(null);return {mutate:useCallback(async i=>{o(true),n(null);try{let l=ac(`/api/${e}`),d=await fetch(l,{method:t,credentials:"include",headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0});if(!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);let c=await d.json();return c.data??c}catch(l){return n(l instanceof Error?l.message:String(l)),null}finally{o(false);}},[e,t]),loading:r,error:a}}var oa=new Map;function aa(e){if(!e.name||typeof e.name!="string")throw new Error("Plugin must have a valid name");oa.has(e.name)&&console.warn(`Plugin "${e.name}" is already registered. Overwriting.`),oa.set(e.name,e),e.apply&&e.apply({});}function ic(e){oa.delete(e);}function lc(e){return oa.get(e)}function dc(){return Array.from(oa.values())}function cc(e){return Array.from(oa.values()).filter(t=>t.hooks&&typeof t.hooks[e]=="function")}var Du={name:"sample-plugin",version:"0.1.0",description:"A tiny sample plugin to demonstrate the extensibility surface",hooks:{onAdminReady:()=>{}}};aa(Du);var Bu={name:"sample-plugin-2",version:"0.1.0",description:"Second MVP plugin demonstrating beforeDeploy hook",hooks:{beforeDeploy:e=>({success:true})}};aa(Bu);var na=new Map;function sa(e){if(!e.id||typeof e.id!="string")throw new Error("Block must have a valid id");if(!e.label)throw new Error("Block must have a label");na.set(e.id,e);}function pc(e){na.delete(e);}function mc(e){return na.get(e)}function uc(){return Array.from(na.values())}function yc(e){return Array.from(na.values()).filter(t=>t.category===e)}function fc(e){let t=na.get(e);return t?t.render:(console.warn(`Block "${e}" not found in registry`),null)}var Iu=e=>{let{data:t}=e;return jsxs("div",{style:{border:"1px solid #ccc",padding:8,borderRadius:6},children:[jsx("strong",{children:"Sample Block"}),jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},Lu={id:"sample-block",label:"Sample Block",category:"demo",schema:[{name:"title",label:"Title",type:"text",required:true}],render:Iu};sa(Lu);var $u=e=>{let{data:t}=e;return jsxs("div",{style:{border:"2px dashed #888",padding:10,borderRadius:8},children:[jsx("strong",{children:"Sample Block 2"}),jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},Eu={id:"sample-block-2",label:"Sample Block 2",category:"demo",schema:[{name:"subtitle",label:"Subtitle",type:"text",required:false}],render:$u};sa(Eu);var ia=new Map;function la(e){if(!e.id||typeof e.id!="string")throw new Error("Field must have a valid id");if(!e.type||typeof e.type!="string")throw new Error("Field must have a valid type");ia.set(e.id,e);}function bc(e){ia.delete(e);}function xc(e){return ia.get(e)}function kc(){return Array.from(ia.values())}function hc(e){return Array.from(ia.values()).find(t=>t.type===e)}function wc(e,t){let r=ia.get(e);if(!r)return console.warn(`Field "${e}" not found in registry`),null;let o=r.editor;return jsx(o,{...t})}var zu=({name:e,value:t,onChange:r})=>jsx("input",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample text"}),ju={id:"sample-text",type:"text",label:"Sample Text",editor:zu};la(ju);var _u=({name:e,value:t,onChange:r})=>jsx("textarea",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample textarea"}),Vu={id:"sample-textarea",type:"textarea",label:"Sample Textarea",editor:_u};la(Vu);var Nc=fr.resolve(new URL(".",import.meta.url).pathname,"lib/shim");fr.join(Nc,"use-sync-external-store.js");fr.join(Nc,"use-sync-external-store-with-selector.js");function Xu(e={}){let{basePath:t="/admin",apiPath:r="/api",configPath:o="kyro.config.ts"}=e;return {name:"@kyro-cms/admin",hooks:{"astro:config:setup":async({config:a,updateConfig:n,injectRoute:s,logger:i})=>{i.info(`Kyro Admin mounted at ${t} (API: ${r})`);let l=fr.resolve(new URL(".",import.meta.url).pathname,"lib/default-kyro-config.ts"),d=fr.resolve(a.root.pathname,"..",o),c=fr.resolve(a.root.pathname,o),m=Ro.existsSync(d)?d:Ro.existsSync(c)?c:l;m!==l?i.info(`Loaded config from ${m}`):i.warn("Config file not found. Using defaults.");let u=fr.join(fr.dirname(m),".kyro-admin-config.json"),g="";try{let f=fr.join(fr.dirname(m),".env");Ro.existsSync(f)&&config({path:f});let y=await build({entryPoints:[m],bundle:!0,format:"esm",platform:"node",target:"es2022",write:!1,sourcemap:!1,loader:{".ts":"ts",".tsx":"tsx"},resolveExtensions:[".ts",".tsx",".js",".jsx",".mjs",".cjs",".json"],external:["@kyro-cms/*"]});g=m.replace(/\.ts$/,".admin.mjs"),Ro.writeFileSync(g,y.outputFiles[0].text,"utf8");let b=`
106
+ `}})]})]})]})}var Ku=typeof __KYRO_API_PATH__<"u"?__KYRO_API_PATH__:"/api";function qd({collections:e}){let[t,r]=useState([]),[o,a]=useState(false),[n,s]=useState(null),[i,l]=useState(""),[d,c]=useState(null),[m,v]=useState(false),{confirm:f,alert:b}=st(),[x,g]=useState(false),[y,u]=useState(""),N=async()=>{try{let p=await Be("/api/keys");r(p);}catch(p){console.error(p);}};useEffect(()=>{N();},[]);let R=async()=>{u(""),g(true);},S=async()=>{if(y.trim())try{await ot("/api/keys",{name:y}),N(),g(!1),u(""),E.success("API key generated");}catch(p){console.error(p),E.error("Failed to generate API key");}},h=p=>{f({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 ht(`/api/keys/${p}`),N(),E.success("API key revoked");}catch(P){console.error(P),E.error("Failed to revoke API key");}}});},C=async()=>{if(i){v(true);try{let P=await(await fetch(Ye(`/api/${i}`))).json();c(P);}catch{c({error:"Failed to fetch. Ensure the endpoint exists."});}finally{v(false);}}};return jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsx(Pt,{title:"Developer Center",description:"Provision access keys and explore the headless API ecosystem.",icon:CodeXml,actions:[{label:"Generate Key",onClick:R,icon:Key}]}),jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-8",children:[jsxs("section",{className:"xl:col-span-2 space-y-6",children:[jsxs("div",{className:"flex items-center gap-2 px-2",children:[jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40 uppercase",children:"Access Credentials"})]}),jsx("div",{className:"space-y-4",children:t.length===0?jsxs("div",{className:"p-12 text-center rounded-[2rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[jsx(Lock,{className:"w-10 h-10 mx-auto mb-4 opacity-20"}),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=>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:jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 relative z-10",children:[jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsx(Key,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors truncate",children:p.name})]}),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:[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"}),jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[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?jsx(EyeOff,{className:"w-4 h-4"}):jsx(Eye,{className:"w-4 h-4"})}),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),E.success("API key copied to clipboard");},children:jsx(Copy,{className:"w-4 h-4"})})]})]}),jsxs("div",{className:"flex items-center gap-6 mt-4 text-[10px] font-bold opacity-30 uppercase tracking-widest",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{children:"Issued:"}),jsx("span",{children:new Date(p.createdAt).toLocaleDateString()})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{children:"Status:"}),jsx("span",{className:"text-green-500",children:"Active"})]})]})]}),jsx("button",{type:"button",onClick:()=>h(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:jsx(Trash2,{className:"w-5 h-5"})})]})},p.id))})]}),jsxs("section",{className:"space-y-6",children:[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:[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:jsx(Terminal,{className:"w-48 h-48 rotate-12"})}),jsxs("div",{className:"relative z-10",children:[jsx("div",{className:"w-12 h-12 bg-white/20 backdrop-blur-md rounded-2xl flex items-center justify-center mb-6",children:jsx(Terminal,{className:"w-6 h-6 text-white"})}),jsx("h3",{className:"text-white text-2xl font-bold tracking-tight mb-3",children:"Endpoint Hub"}),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."}),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",jsx(ExternalLink,{className:"w-3.5 h-3.5"})]})]})]}),jsxs("div",{className:"rounded-[2.5rem] border border-[var(--kyro-border)] bg-[var(--kyro-surface)]/50 p-8 space-y-6",children:[jsx("h4",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Environment Matrix"}),jsxs("div",{className:"space-y-5",children:[jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-xs font-bold",children:"Content API"}),jsx(Dt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Production"})]}),jsxs("div",{className:"group relative",children:[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"}),jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://api.kyro.io/v1"}),jsx(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")})]})]})]}),jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-xs font-bold",children:"Draft Explorer"}),jsx(Dt,{variant:"outline",className:"text-[8px] font-bold uppercase py-0.5",children:"Staging"})]}),jsxs("div",{className:"group relative",children:[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"}),jsxs("div",{className:"relative bg-[var(--kyro-bg)] p-3.5 rounded-xl border border-[var(--kyro-border)] flex items-center justify-between",children:[jsx("code",{className:"text-[10px] font-mono opacity-60",children:"https://preview.kyro.io/v1"}),jsx(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")})]})]})]})]})]})]}),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:[jsx("div",{className:"absolute top-0 right-0 p-20 opacity-[0.02] pointer-events-none",children:jsx(CirclePlay,{className:"w-96 h-96"})}),jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-10 relative z-10",children:[jsxs("div",{className:"max-w-xl",children:[jsxs("h2",{className:"text-3xl font-bold tracking-tighter flex items-center gap-4 mb-3",children:[jsx("div",{className:"w-12 h-12 bg-[var(--kyro-primary)]/10 rounded-2xl flex items-center justify-center",children:jsx(CirclePlay,{className:"w-7 h-7 text-[var(--kyro-primary)]"})}),"API ",jsx("span",{className:"text-[var(--kyro-primary)]",children:"Explorer"})]}),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."})]}),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:[jsxs("div",{className:"flex-1 relative flex items-center pl-6",children:[jsxs("span",{className:"text-[11px] font-bold opacity-30 uppercase tracking-widest mr-2 whitespace-nowrap",children:["GET ",Ku,"/"]}),jsx("input",{type:"text",value:i,onChange:p=>l(p.target.value),placeholder:"collection-slug",className:"w-full py-4 bg-transparent focus:outline-none font-mono text-sm font-bold text-[var(--kyro-primary)]"})]}),jsxs("button",{type:"button",onClick:C,disabled:m||!i,className:"kyro-btn kyro-btn-primary px-8 py-4 rounded-[1.5rem] font-bold text-sm shadow-xl disabled:opacity-50 disabled:cursor-not-allowed hover:scale-[1.02] transition-all flex items-center gap-3 shrink-0",children:[m?jsx(RefreshCcw,{className:"w-4 h-4 animate-spin"}):jsx(ChevronRight,{className:"w-5 h-5"}),"Run Query"]})]})]}),d?jsxs("div",{className:"animate-in fade-in zoom-in-95 duration-500 relative z-10",children:[jsxs("div",{className:"flex items-center justify-between mb-4 px-2",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx("div",{className:"w-1 h-3 bg-[var(--kyro-primary)] rounded-full"}),jsx("span",{className:"text-[10px] font-bold uppercase tracking-[0.2em] opacity-40",children:"Response Payload"})]}),jsx(Dt,{variant:"outline",className:"text-[9px] font-mono px-3",children:"200 OK"})]}),jsxs("div",{className:"rounded-[2rem] overflow-hidden border border-[var(--kyro-border)] shadow-2xl bg-[#090b10]",children:[jsxs("div",{className:"flex items-center gap-2 px-6 py-4 bg-[#11141d] border-b border-[var(--kyro-border)]/50",children:[jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500/20"}),jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-amber-500/20"}),jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500/20"})]}),jsx(_u,{value:JSON.stringify(d,null,2),height:"450px",theme:aura,extensions:[json()],editable:false,className:"text-sm"})]})]}):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:[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:jsx(CodeXml,{className:"w-10 h-10"})}),jsx("p",{className:"font-bold text-sm opacity-30 uppercase tracking-[0.2em]",children:"Awaiting request dispatch..."})]})]})]}),jsxs(Ut,{open:x,onClose:()=>g(false),title:"Generate Access Token",size:"lg",children:[jsx(_r,{children:jsxs("div",{className:"space-y-6",children:[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."}),jsxs("div",{className:"space-y-2",children:[jsx("label",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Token Name"}),jsx("input",{type:"text",value:y,onChange:p=>u(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"&&S()})]})]})}),jsxs(Hr,{children:[jsx("button",{type:"button",onClick:()=>g(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"}),jsx("button",{type:"button",onClick:S,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 Jd(e){let[t,r]=useState([]),[o,a]=useState(false),[n,s]=useState(null),[i,l]=useState(false),{confirm:d}=st(),c=useCallback(async()=>{a(true),s(null);try{let b=await Be(e.endpoint),x=Array.isArray(b)?b:b.docs||[],g=e.transformLoad?e.transformLoad(x):x;r(g),e.onSuccess?.("load",g);}catch(b){let x=b instanceof Error?b.message:"Failed to load resources";s(x),e.onError?.("load",b);}finally{a(false);}},[e.endpoint,e.transformLoad]);useEffect(()=>{c();},[c]);let m=useCallback((b,x="item")=>{d({title:`Delete ${x}`,message:`Are you sure you want to delete this ${x.toLowerCase()}? This action cannot be undone.`,variant:"danger",onConfirm:async()=>{try{await ht(`${e.endpoint}/${b}`),r(g=>g.filter(y=>y.id!==b)),e.onSuccess?.("delete",b),E.success(`${x} deleted`);}catch(g){let y=g instanceof Error?g.message:`Failed to delete ${x}`;E.error(y),e.onError?.("delete",g);}}});},[e.endpoint,d]),v=useCallback(async b=>{s(null);try{let x=await ot(e.endpoint,b);return r(g=>[x,...g]),l(!1),e.onSuccess?.("create",x),x}catch(x){let g=x instanceof Error?x.message:"Failed to create resource";throw s(g),e.onError?.("create",x),x}},[e.endpoint]),f=useCallback(async(b,x)=>{s(null);try{let g=await Xt(`${e.endpoint}/${b}`,x);return r(y=>y.map(u=>u.id===b?g:u)),e.onSuccess?.("update",g),g}catch(g){let y=g instanceof Error?g.message:"Failed to update resource";throw s(y),e.onError?.("update",g),g}},[e.endpoint]);return {items:t,setItems:r,loading:o,error:n,load:c,remove:m,create:v,update:f,isCreateModalOpen:i,setIsCreateModalOpen:l}}function Xd(){let{items:e,loading:t,create:r,remove:o,update:a,isCreateModalOpen:n,setIsCreateModalOpen:s}=Jd({endpoint:"/api/webhooks"}),{confirm:i}=st(),[l,d]=useState(false),[c,m]=useState(false),[v,f]=useState(null),[b,x]=useState(null),[g,y]=useState({name:"",url:"",events:[],secret:""}),[u,N]=useState(""),R=async()=>{if(!g.name.trim()||!g.url.trim()){N("Name and URL are required");return}try{await r(g),y({name:"",url:"",events:[],secret:""}),E.success(`Webhook established: ${g.name}`);}catch{N("Failed to create webhook"),E.error("Failed to create webhook");}},S=async p=>{x(p),f(null),d(true);try{let P=await ot(`/api/webhooks/${p}/test`);f({success:!0,message:P.message||"Webhook triggered successfully"}),E.success("Dispatch verified: Remote endpoint responded");}catch{f({success:false,message:"Failed to trigger webhook"});}},h=async(p,P)=>{try{let M=P==="active"?"paused":"active";await a(p,{status:M}),E.success(M==="active"?"Signals resumed":"Dispatcher paused");}catch(M){console.error(M),E.error("Failed to toggle webhook status");}},C=[{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 jsxs("div",{className:"w-full space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700 pb-32",children:[jsx(Pt,{title:"Webhooks",description:"Receive real-time notifications when your content changes.",icon:Webhook,actions:[{label:"Create Webhook",onClick:()=>{y({name:"",url:"",events:["collection.create","collection.update","collection.delete"],secret:""}),N(""),s(true);},icon:Plus},{label:"Guide",onClick:()=>m(true),icon:Info,variant:"outline"}]}),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:[jsx("div",{className:"absolute top-0 right-0 p-8 opacity-[0.03] pointer-events-none",children:jsx(Zap,{className:"w-64 h-64 rotate-12"})}),jsxs("div",{className:"flex flex-col md:flex-row items-center gap-8 relative z-10",children:[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:jsx(Zap,{className:"w-8 h-8 text-white"})}),jsxs("div",{className:"flex-1 text-center md:text-left",children:[jsx("h3",{className:"text-xl font-bold mb-2",children:"Real-time Event Synchronization"}),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."})]}),jsxs("div",{className:"flex gap-4",children:[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:[jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Collections"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"Triggered"})]}),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:[jsx("span",{className:"text-[10px] font-bold opacity-40 uppercase tracking-tighter",children:"Latency"}),jsx("span",{className:"text-sm font-bold text-[var(--kyro-primary)]",children:"<200ms"})]})]})]})]}),jsxs("section",{className:"space-y-6",children:[jsxs("div",{className:"flex items-center justify-between px-2",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{className:"w-1 h-4 bg-[var(--kyro-primary)] rounded-full"}),jsx("h2",{className:"text-sm font-medium tracking-[0.2em] opacity-40",children:"ACTIVE ENDPOINTS"})]}),jsxs("div",{className:"text-[10px] font-bold opacity-40 uppercase",children:[e.length," Hook",e.length!==1&&"s"]})]}),t?jsx("div",{className:"flex items-center justify-center p-20 surface-tile rounded-3xl opacity-50 italic",children:"Connecting to dispatcher..."}):e.length===0?jsxs("div",{className:"p-16 text-center rounded-[3rem] border-2 border-dashed border-[var(--kyro-border)] bg-[var(--kyro-surface-accent)]/30",children:[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:jsx(Webhook,{className:"w-10 h-10 text-[var(--kyro-primary)]"})}),jsx("h3",{className:"text-2xl font-bold mb-3",children:"No Webhooks Found"}),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."}),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:[jsx(Plus,{className:"w-5 h-5"}),"Configure Webhook"]})]}):jsx("div",{className:"grid gap-4",children:e.map(p=>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:jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-6 relative z-10",children:[jsxs("div",{className:"flex-1",children:[jsxs("div",{className:"flex items-center gap-3 mb-4",children:[jsx("div",{className:"p-2.5 bg-[var(--kyro-surface-accent)] rounded-xl group-hover:bg-[var(--kyro-primary)]/10 transition-colors",children:jsx(Webhook,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] group-hover:text-[var(--kyro-primary)] transition-colors"})}),jsxs("div",{children:[jsx("h3",{className:"text-lg font-bold group-hover:text-[var(--kyro-primary)] transition-colors",children:p.name}),jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[jsx("span",{className:`w-2 h-2 rounded-full ${p.status==="active"?"bg-green-500 animate-pulse":"bg-amber-500"}`}),jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${p.status==="active"?"text-green-500":"text-amber-500"}`,children:p.status})]})]})]}),jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 pt-2",children:[jsxs("div",{className:"space-y-1",children:[jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Destination"}),jsx("div",{className:"font-mono text-xs opacity-60 truncate max-w-[200px]",title:p.url,children:p.url})]}),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:[jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Events"}),jsxs("div",{className:"flex flex-wrap gap-1",children:[p.events.slice(0,2).map(P=>jsx(Dt,{variant:"outline",className:"text-[8px] font-bold px-1.5 opacity-60",children:P},P)),p.events.length>2&&jsxs("span",{className:"text-[8px] font-bold opacity-30",children:["+",p.events.length-2," more"]})]})]}),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:[jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest opacity-30",children:"Activity"}),jsxs("div",{className:"text-[10px] font-bold opacity-60 flex items-center gap-1.5",children:[jsx(Clock,{className:"w-3 h-3"}),p.lastTriggered?`Last triggered: ${new Date(p.lastTriggered).toLocaleDateString()}`:"Never triggered"]})]})]})]}),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:[jsxs("button",{type:"button",onClick:()=>S(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:[jsx(Send,{className:"w-4 h-4"}),jsx("span",{className:"text-xs font-bold",children:"Test"})]}),jsx("div",{className:"w-px h-6 bg-[var(--kyro-border)] mx-1 hidden lg:block"}),jsx("button",{type:"button",onClick:()=>h(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"?jsx(Pause,{className:"w-4 h-4"}):jsx(Play,{className:"w-4 h-4"})}),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:jsx(Trash2,{className:"w-4 h-4 text-red-500/50 group-hover/delete:text-red-500"})})]})]})},p.id))})]}),jsxs(Ut,{open:n,onClose:()=>s(false),title:"Register Webhook",size:"lg",children:[jsx(_r,{children:jsxs("div",{className:"space-y-6",children:[jsxs("div",{className:"flex flex-col gap-6",children:[jsxs("div",{className:"space-y-4",children:[jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Webhook Name"}),jsx("input",{type:"text",value:g.name,onChange:p=>y({...g,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)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Payload URL"}),jsx("input",{type:"url",value:g.url,onChange:p=>y({...g,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)]"})]}),jsxs("div",{children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Signing Secret"}),jsx("input",{type:"text",value:g.secret,onChange:p=>y({...g,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)]"})]})]}),jsxs("div",{className:"space-y-4",children:[jsx("label",{className:"block text-xs font-bold mb-1.5 text-[var(--kyro-text-secondary)] uppercase tracking-wider",children:"Subscribed Events"}),jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:C.map(p=>jsxs("button",{type:"button",onClick:()=>{let P=g.events.includes(p.value)?g.events.filter(M=>M!==p.value):[...g.events,p.value];y({...g,events:P});},className:`flex items-center gap-3 p-3 rounded-lg border transition-all text-left ${g.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:[jsx("div",{className:`w-4 h-4 rounded flex items-center justify-center border transition-all ${g.events.includes(p.value)?"bg-[var(--kyro-primary)] border-[var(--kyro-primary)]":"border-[var(--kyro-border)]"}`,children:g.events.includes(p.value)&&jsx(CircleCheck,{className:"w-3 h-3 text-white"})}),jsxs("div",{children:[jsx("div",{className:"text-xs font-bold",children:p.label}),jsx("div",{className:"text-[10px] opacity-50",children:p.description})]})]},p.value))})]})]}),u&&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:[jsx(TriangleAlert,{className:"w-4 h-4"}),u]})]})}),jsxs(Hr,{children:[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"}),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"})]})]}),jsxs(Ut,{open:l,onClose:()=>d(false),title:"Webhook Test Dispatcher",children:[jsx(_r,{children:jsx("div",{className:"p-8 rounded-[2rem] bg-[var(--kyro-surface-accent)]/30 border border-[var(--kyro-border)] text-center",children:v?jsxs("div",{className:"space-y-6",children:[jsx("div",{className:`w-16 h-16 mx-auto rounded-2xl flex items-center justify-center shadow-xl ${v.success?"bg-green-500/10 text-green-500":"bg-red-500/10 text-red-500"}`,children:v.success?jsx(CircleCheck,{className:"w-8 h-8"}):jsx(TriangleAlert,{className:"w-8 h-8"})}),jsxs("div",{children:[jsx("h4",{className:"text-xl font-bold mb-2",children:v.success?"Dispatch Successful":"Dispatch Failed"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-70",children:v.message})]})]}):jsxs("div",{className:"space-y-6 py-4",children:[jsx(RefreshCw,{className:"w-12 h-12 text-[var(--kyro-primary)] animate-spin mx-auto opacity-50"}),jsxs("div",{children:[jsx("h4",{className:"text-xl font-bold mb-1",children:"Synthesizing Payload"}),jsx("p",{className:"text-sm text-[var(--kyro-text-secondary)] opacity-50 italic",children:"Dispatching to remote endpoint..."})]})]})})}),jsx(Hr,{children: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"})})]}),jsxs(Ut,{open:c,onClose:()=>m(false),title:"Webhook Integration Guide",size:"lg",children:[jsx(_r,{children:jsxs("div",{className:"space-y-8",children:[jsxs("div",{className:"grid grid-cols-1 gap-6",children:[jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsx(ExternalLink,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Request Context"]}),jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["When an event triggers, Kyro sends a standard ",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."]})]}),jsxs("div",{className:"p-6 rounded-3xl bg-[var(--kyro-surface-accent)]/50 border border-[var(--kyro-border)]",children:[jsxs("h4",{className:"font-bold mb-3 flex items-center gap-2",children:[jsx(Shield,{className:"w-4 h-4 text-[var(--kyro-primary)]"}),"Security Verification"]}),jsxs("p",{className:"text-sm text-[var(--kyro-text-secondary)] leading-relaxed",children:["If a secret is provided, each request includes an ",jsx("span",{className:"font-mono text-[var(--kyro-primary)]",children:"X-Kyro-Signature"})," header. Always verify this signature in production environments."]})]})]}),jsxs("div",{className:"space-y-3",children:[jsx("h4",{className:"text-xs font-bold uppercase tracking-widest opacity-40 px-1",children:"Payload Architecture"}),jsxs("div",{className:"relative group",children:[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"}),jsxs("div",{className:"relative bg-[var(--kyro-bg)] rounded-2xl border border-[var(--kyro-border)] p-6 font-mono text-sm overflow-hidden",children:[jsxs("div",{className:"flex items-center gap-2 mb-4 border-b border-[var(--kyro-border)] pb-4 opacity-30",children:[jsx("div",{className:"w-2 h-2 rounded-full bg-red-500/50"}),jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500/50"}),jsx("div",{className:"w-2 h-2 rounded-full bg-green-500/50"}),jsx("span",{className:"text-[10px] ml-2 tracking-tighter",children:"payload.json"})]}),jsxs("div",{className:"space-y-1",children:[jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"{"}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"event"'}),": ",jsx("span",{className:"text-green-500",children:'"collection.create"'}),","]}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"collection"'}),": ",jsx("span",{className:"text-green-500",children:'"products"'}),","]}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"id"'}),": ",jsx("span",{className:"text-green-500",children:'"prod_8273"'}),","]}),jsxs("div",{className:"pl-4",children:[jsx("span",{className:"text-[var(--kyro-primary)]",children:'"timestamp"'}),": ",jsx("span",{className:"text-green-500",children:'"2026-05-14T02:53:22Z"'})]}),jsx("div",{className:"text-[var(--kyro-text-secondary)]",children:"}"})]})]})]})]})]})}),jsx(Hr,{children: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 Zd({isOpen:e,onClose:t,collections:r,globals:o,onNavigate:a}){let{user:n,permissions:s}=Or(),[i,l]=useState(""),[d,c]=useState(0),[m,v]=useState(false),[f,b]=useState([]),x=useRef(null),g=useRef(null);useEffect(()=>{e&&(l(""),c(0),b([]),v(false),setTimeout(()=>x.current?.focus(),100));},[e]);let y=useCallback(async A=>{if(!A||A.length<2){b([]);return}v(true);try{let me=await(await fetch(Ye(`/api/search?q=${encodeURIComponent(A)}&limit=15`))).json();me.results&&b(me.results);}catch(re){console.error("Search error:",re),b([]);}finally{v(false);}},[]);if(useEffect(()=>(g.current&&clearTimeout(g.current),i.length>=2?g.current=setTimeout(()=>y(i),300):b([]),()=>{g.current&&clearTimeout(g.current);}),[i,y]),!e)return null;let u=Object.entries(r).filter(([A])=>s?.collections?.[A]?.read!==false).map(([A,re])=>({id:`col-${A}`,label:re.label||A,type:"collection",slug:A,icon:FileText})),N=Object.entries(o).filter(([A])=>s?.globals?.[A]?.read!==false).map(([A,re])=>({id:`global-${A}`,label:re.label||A,type:"global",slug:A,icon:Settings})),R=typeof document<"u"&&document.documentElement.classList.contains("dark"),S=n?.role==="admin",h=[{id:"action-media",label:"Media Gallery",type:"action",view:"media",icon:Image,visible:s?.collections?.media?.read!==false},{id:"action-users",label:"Team Management",type:"action",view:"users",icon:Clock,visible:S},{id:"action-audit",label:"Audit Logs",type:"action",view:"audit",icon:File,visible:S},{id:"action-roles",label:"Roles & Permissions",type:"action",view:"roles",icon:Shield,visible:S},{id:"action-api",label:"REST API Explorer",type:"action",view:"api-explorer",icon:Database,visible:S},{id:"action-graphql",label:"GraphQL Playground",type:"action",view:"graphql",icon:Hexagon,visible:S},{id:"action-rest",label:"REST Playground",type:"action",view:"rest",icon:Network,visible:S},{id:"action-theme",label:R?"Switch to Light Mode":"Switch to Dark Mode",type:"action",view:"theme",icon:R?Sun:Moon,visible:true},{id:"action-logout",label:"Sign Out",type:"action",view:"logout",icon:LogOut,visible:true}].filter(A=>A.visible),C=f.map((A,re)=>({id:`doc-${A.collection}-${A.id}`,label:A.title,type:"document",collection:A.collection,label2:A.label,docId:A.id,icon:File,doc:A.doc})),p=i.length>=2?[...h,...u,...N,...C]:[...h,...u,...N],P=i===""?p:p.filter(A=>A.label.toLowerCase().includes(i.toLowerCase())),M=A=>{if(A.key==="ArrowDown")A.preventDefault(),c(re=>(re+1)%P.length);else if(A.key==="ArrowUp")A.preventDefault(),c(re=>(re-1+P.length)%P.length);else if(A.key==="Enter"){let re=P[d];re&&D(re);}else A.key==="Escape"&&t();},D=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();},I=()=>i===""?"Quick Actions & Collections":f.length>0?"Documents":m?"Searching...":"Search Results";return jsxs("div",{className:"fixed inset-0 z-[1000] flex items-start justify-center pt-[15vh] px-4",children:[jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm animate-in fade-in duration-300",onClick:t}),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:[jsxs("div",{className:"flex items-center px-6 py-5 border-b border-[var(--kyro-border)]",children:[m?jsx(LoaderCircle,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4 animate-spin"}):jsx(Search,{className:"w-5 h-5 text-[var(--kyro-text-secondary)] opacity-50 mr-4"}),jsx("input",{ref:x,placeholder:"Search anything...",className:"flex-1 bg-transparent border-none focus:outline-none text-lg font-medium text-[var(--kyro-text-primary)] placeholder:text-[var(--kyro-text-muted)]",value:i,onChange:A=>l(A.target.value),onKeyDown:M}),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:jsx("span",{className:"text-[10px] font-bold opacity-40 tracking-widest",children:"ESC"})})]}),jsx("div",{className:"max-h-[400px] overflow-y-auto py-4",children:P.length>0?jsxs("div",{className:"space-y-1 px-4",children:[jsx("p",{className:"px-4 text-[10px] font-bold tracking-[0.2em] opacity-40 mb-4",children:I()}),P.map((A,re)=>jsxs("div",{onClick:()=>D(A),onMouseEnter:()=>c(re),className:`flex items-center justify-between px-4 py-4 rounded-2xl cursor-pointer ${re===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:[jsxs("div",{className:"flex items-center gap-4",children:[jsx("div",{className:`p-2 rounded-xl ${re===d?"bg-white/20":"bg-[var(--kyro-bg-secondary)] border border-[var(--kyro-border)]"}`,children:jsx(A.icon,{className:"w-4 h-4"})}),jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"font-bold text-sm",children:A.label}),A.type==="document"&&A.label2&&jsx("span",{className:`text-[10px] font-bold tracking-widest ${re===d?"text-[var(--kyro-sidebar-text-active)]/60":"opacity-40"}`,children:A.label2})]})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:`text-[10px] font-bold tracking-widest opacity-40 ${re===d?"text-[var(--kyro-sidebar-text-active)] p-1":""}`,children:A.type}),re===d&&jsx(ArrowRight,{className:"w-4 h-4 mr-2"})]})]},A.id))]}):jsx("div",{className:"py-12 text-center",children:jsx("p",{className:"text-[var(--kyro-text-secondary)] italic opacity-60",children:i.length>=2&&!m?`No results found for "${i}"`:"Start typing to search..."})})}),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:[jsxs("div",{className:"flex gap-6",children:[jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u2191\u2193 Navigate"}),jsx("span",{className:"flex items-center gap-2 underline underline-offset-4 decoration-2 decoration-[var(--kyro-primary)]",children:"\u23CE Select"})]}),jsx("div",{children:"Kyro Universal Search"})]})]})]})}function ec(){let{modal:e,closeModal:t}=st(),[r,o]=useState(false);if(!e.open||!e.config)return null;let{config:a}=e,n=async()=>{if(a.onConfirm)try{o(!0),await a.onConfirm();}catch(i){console.error("Modal confirm action failed:",i);}finally{o(false),t();}else t();},s=()=>{a.onCancel&&a.onCancel(),t();};return jsx(xs,{open:e.open,onClose:s,onConfirm:n,title:a.title,message:a.message,confirmLabel:a.confirmLabel,cancelLabel:a.cancelLabel,variant:a.variant==="danger"?"danger":"default",loading:r})}function Xu({config:e,theme:t="light",onThemeChange:r}){let[o,a]=useState(false),[n,s]=useState(null),i=useMemo(()=>Bn(Da(e.collections)),[e.collections]),l=useMemo(()=>Ln(Da(e.globals)),[e.globals]),[d,c]=useState(null),[m,v]=useState(null),[f,b]=useState("list"),[x,g]=useState(null),[y,u]=useState(false);useEffect(()=>{(async()=>{try{let C=await fetch("/api/users/me");if(C.ok){let p=await C.json();s(p),a(!0);}}catch(C){console.error("Auth check failed",C);}})();},[]),useEffect(()=>{if(o&&!d){let h=Object.keys(i)[0];h&&c(h);}},[o,i,d]);let N=(h,C=null,p=null)=>{b(h),C&&c(C),p&&g(p),u(false);};useEffect(()=>{let h=C=>{(C.metaKey||C.ctrlKey)&&C.key==="k"&&(C.preventDefault(),u(p=>!p));};return window.addEventListener("keydown",h),window.openCommandPalette=()=>u(true),()=>{window.removeEventListener("keydown",h),delete window.openCommandPalette;}},[]);return o?jsx(hr,{mode:t,onChange:r,children:jsxs("div",{className:"kyro-admin min-h-screen bg-[var(--kyro-bg)] text-[var(--kyro-text-primary)]",children:[jsx("div",{className:"flex h-screen overflow-hidden",children:jsx("main",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:jsxs("div",{className:"flex-1 overflow-y-auto",children:[jsx(Zd,{isOpen:y,onClose:()=>u(false),collections:i,globals:l,onNavigate:N}),(()=>{let h=d?i[d]:null;switch(f){case "create":return h?jsx(oi,{config:e,collection:h,onSuccess:()=>b("list"),onCancel:()=>b("list"),onError:C=>E.error(C)}):null;case "detail":return h&&x?jsx(ri,{config:e,collection:h,documentId:x,onBack:()=>b("list"),onSave:()=>{},onError:C=>E.error(C)}):null;case "users":return jsx(Gd,{});case "media":return jsx(hn,{});case "branding":return jsx(Wd,{});case "developer":return jsx(qd,{collections:i});case "webhooks":return jsx(Xd,{});default:return h?jsx(vs,{config:e,collection:h,onCreate:()=>b("create"),onEdit:C=>N("detail",d,C)}):jsx(Vd,{onNavigate:N,collections:i,user:n})}})()]})})}),jsx(ec,{}),jsx(Wn,{})]})}):jsx(si,{onAuth:(h,C)=>{s(C),a(true);},theme:t})}function Qu({selectedCount:e,onClearSelection:t,actions:r,onSelectAll:o}){return e===0?null:jsxs("div",{className:"flex items-center justify-between py-2 px-4 bg-gray-50 border-b border-gray-200",children:[jsxs("div",{className:"flex items-center gap-4",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx(ms,{count:e}),jsx("span",{className:"text-sm text-gray-600",children:"selected"})]}),jsx("button",{type:"button",onClick:t,className:"text-sm text-gray-500 hover:text-gray-700",children:"Clear selection"}),o&&jsx("button",{type:"button",onClick:o,className:"text-sm text-gray-500 hover:text-gray-700",children:"Select all"})]}),jsx(Co,{trigger:jsxs("button",{type:"button",className:"kyro-btn kyro-btn-secondary kyro-btn-sm",children:["Actions",jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M6 9l6 6 6-6"})})]}),children:r.map((a,n)=>jsx(_t,{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:i=false}){let l=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime())){let v=Date.parse(c);return isNaN(v)?"Invalid date":new Date(v).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}return m.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})},d=c=>{if(!c)return "Unknown date";let m=new Date(c);if(isNaN(m.getTime()))return l(c);let f=new Date().getTime()-m.getTime();if(f<0)return "Just now";let b=Math.floor(f/6e4),x=Math.floor(f/36e5),g=Math.floor(f/864e5);return b<1?"Just now":b<60?`${b}m ago`:x<24?`${x}h ago`:g<7?`${g}d ago`:l(c)};return jsx(cr,{open:e,onClose:t,title:"Version History",width:"md",children:i?jsx("div",{className:"flex items-center justify-center py-12",children:jsx(Pr,{})}):r.length===0?jsxs("div",{className:"text-center flex flex-col items-center justify-center py-16 text-[var(--kyro-text-muted)]",children:[jsx(History,{className:"w-12 h-12 mb-4 opacity-20"}),jsx("p",{className:"font-medium text-[var(--kyro-text)]",children:"No version history yet"}),jsx("p",{className:"text-sm mt-1",children:"Versions are automatically saved as you work."})]}):jsx("div",{className:"space-y-3 px-1 pb-4 pt-1",children:r.map(c=>{let m=c.id===o;return 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&&jsx("div",{className:"absolute top-0 left-0 w-1 h-full bg-[var(--kyro-primary)] shadow-[0_0_8px_var(--kyro-primary)]"}),jsxs("div",{className:"flex items-start justify-between gap-4",children:[jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{className:"flex items-center gap-2 mb-2",children:[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"&&jsx(CheckCircle2,{className:"w-3 h-3"}),c.status==="published"?"Published":"Draft"]}),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&&jsxs("span",{className:"text-[10px] font-medium text-[var(--kyro-primary)] flex items-center gap-1",children:[jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--kyro-primary)] animate-pulse"}),"Current"]})]}),jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium text-[var(--kyro-text)] truncate mb-1",children:[jsx(Clock,{className:"w-3.5 h-3.5 text-[var(--kyro-text-muted)]"}),d(c.createdAt)]}),c.createdBy&&jsxs("div",{className:"flex items-center gap-1.5 text-xs text-[var(--kyro-text-muted)] mt-1.5",children:[jsx(User,{className:"w-3.5 h-3.5"}),jsx("span",{children:c.createdBy.name||c.createdBy.email})]}),c.changelog&&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,'"']})]}),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:[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:jsx(Eye,{className:"w-4 h-4"})}),s&&jsx("button",{type:"button",onClick:()=>s(c,r.find(v=>v.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:jsx(GitCompare,{className:"w-4 h-4"})}),!m&&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:jsx(Undo2,{className:"w-4 h-4"})})]})]})]},c.id)})})})}function YR({title:e,onMenuClick:t,actions:r}){return jsxs("header",{className:"kyro-header",children:[jsxs("div",{className:"kyro-header-left",children:[jsx("button",{type:"button",className:"kyro-header-menu",onClick:t,"aria-label":"Toggle menu",children:jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("path",{d:"M3 12h18M3 6h18M3 18h18"})})}),jsx("h1",{className:"kyro-header-title",children:e})]}),jsxs("div",{className:"kyro-header-right",children:[r,jsx("div",{className:"kyro-header-user",children:jsx("button",{type:"button",className:"kyro-header-user-btn",children:jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[jsx("circle",{cx:"12",cy:"8",r:"4"}),jsx("path",{d:"M4 20c0-4 4-6 8-6s8 2 8 6"})]})})})]})]})}var nr={ready:[],beforeDeploy:[],afterDeploy:[]};function Zn(e){return nr.ready.push(e),()=>{nr.ready=nr.ready.filter(t=>t!==e);}}function oc(e){return nr.beforeDeploy.push(e),()=>{nr.beforeDeploy=nr.beforeDeploy.filter(t=>t!==e);}}function ac(e){return nr.afterDeploy.push(e),()=>{nr.afterDeploy=nr.afterDeploy.filter(t=>t!==e);}}async function nc(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 sc(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 ic(e,t){for(let r of nr.afterDeploy)try{await r(e,t);}catch{}}function dc(e){return `${typeof window<"u"?window.location.origin:""}${e}`}function cc(e,t={}){let[r,o]=useState(null),[a,n]=useState(true),[s,i]=useState(null),l=useCallback(async()=>{n(true),i(null);try{let d=new URLSearchParams;t.page&&d.set("page",String(t.page)),t.limit&&d.set("limit",String(t.limit)),t.sort&&d.set("sort",t.sort),t.order&&d.set("order",t.order);let c=`${dc(`/api/${e}`)}?${d.toString()}`,m=await fetch(c,{credentials:"include"});if(!m.ok)throw new Error(`HTTP ${m.status}: ${m.statusText}`);let v=await m.json();o(v.data??v);}catch(d){i(d instanceof Error?d.message:String(d));}finally{n(false);}},[e,t.page,t.limit,t.sort,t.order]);return useEffect(()=>{l();},[l]),{data:r,loading:a,error:s,refetch:l}}function pc(e,t="POST"){let[r,o]=useState(false),[a,n]=useState(null);return {mutate:useCallback(async i=>{o(true),n(null);try{let l=dc(`/api/${e}`),d=await fetch(l,{method:t,credentials:"include",headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0});if(!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);let c=await d.json();return c.data??c}catch(l){return n(l instanceof Error?l.message:String(l)),null}finally{o(false);}},[e,t]),loading:r,error:a}}var na=new Map;function sa(e){if(!e.name||typeof e.name!="string")throw new Error("Plugin must have a valid name");na.has(e.name)&&console.warn(`Plugin "${e.name}" is already registered. Overwriting.`),na.set(e.name,e),e.apply&&e.apply({});}function mc(e){na.delete(e);}function uc(e){return na.get(e)}function yc(){return Array.from(na.values())}function fc(e){return Array.from(na.values()).filter(t=>t.hooks&&typeof t.hooks[e]=="function")}var iy={name:"sample-plugin",version:"0.1.0",description:"A tiny sample plugin to demonstrate the extensibility surface",hooks:{onAdminReady:()=>{}}};sa(iy);var ly={name:"sample-plugin-2",version:"0.1.0",description:"Second MVP plugin demonstrating beforeDeploy hook",hooks:{beforeDeploy:e=>({success:true})}};sa(ly);var ia=new Map;function la(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");ia.set(e.id,e);}function vc(e){ia.delete(e);}function gc(e){return ia.get(e)}function bc(){return Array.from(ia.values())}function xc(e){return Array.from(ia.values()).filter(t=>t.category===e)}function kc(e){let t=ia.get(e);return t?t.render:(console.warn(`Block "${e}" not found in registry`),null)}var dy=e=>{let{data:t}=e;return jsxs("div",{style:{border:"1px solid #ccc",padding:8,borderRadius:6},children:[jsx("strong",{children:"Sample Block"}),jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},cy={id:"sample-block",label:"Sample Block",category:"demo",schema:[{name:"title",label:"Title",type:"text",required:true}],render:dy};la(cy);var my=e=>{let{data:t}=e;return jsxs("div",{style:{border:"2px dashed #888",padding:10,borderRadius:8},children:[jsx("strong",{children:"Sample Block 2"}),jsx("pre",{style:{marginTop:6},children:JSON.stringify(t??{},null,2)})]})},uy={id:"sample-block-2",label:"Sample Block 2",category:"demo",schema:[{name:"subtitle",label:"Subtitle",type:"text",required:false}],render:my};la(uy);var da=new Map;function ca(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");da.set(e.id,e);}function Nc(e){da.delete(e);}function Cc(e){return da.get(e)}function Sc(){return Array.from(da.values())}function Tc(e){return Array.from(da.values()).find(t=>t.type===e)}function Rc(e,t){let r=da.get(e);if(!r)return console.warn(`Field "${e}" not found in registry`),null;let o=r.editor;return jsx(o,{...t})}var vy=({name:e,value:t,onChange:r})=>jsx("input",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample text"}),gy={id:"sample-text",type:"text",label:"Sample Text",editor:vy};ca(gy);var xy=({name:e,value:t,onChange:r})=>jsx("textarea",{name:e,value:typeof t=="string"?t:"",onChange:o=>r?.(o.target.value),placeholder:"Sample textarea"}),ky={id:"sample-textarea",type:"textarea",label:"Sample Textarea",editor:xy};ca(ky);var Ac=vr.resolve(new URL(".",import.meta.url).pathname,"lib/shim");vr.join(Ac,"use-sync-external-store.js");vr.join(Ac,"use-sync-external-store-with-selector.js");function Ty(e={}){let{basePath:t="/admin",apiPath:r="/api",configPath:o="kyro.config.ts"}=e;return {name:"@kyro-cms/admin",hooks:{"astro:config:setup":async({config:a,updateConfig:n,injectRoute:s,logger:i})=>{i.info(`Kyro Admin mounted at ${t} (API: ${r})`);let l=vr.resolve(new URL(".",import.meta.url).pathname,"lib/default-kyro-config.ts"),d=vr.resolve(a.root.pathname,"..",o),c=vr.resolve(a.root.pathname,o),m=Po.existsSync(d)?d:Po.existsSync(c)?c:l;m!==l?i.info(`Loaded config from ${m}`):i.warn("Config file not found. Using defaults.");let v=vr.join(vr.dirname(m),".kyro-admin-config.json"),f="";try{let x=vr.join(vr.dirname(m),".env");Po.existsSync(x)&&config({path:x});let g=await 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/*"]});f=m.replace(/\.ts$/,".admin.mjs"),Po.writeFileSync(f,g.outputFiles[0].text,"utf8");let y=`
107
107
  import { parentPort } from 'worker_threads';
108
- import('${pathToFileURL(g).href}').then(mod => {
108
+ import('${pathToFileURL(f).href}').then(mod => {
109
109
  const cfg = mod.default || mod;
110
110
  const serialize = (obj) => {
111
111
  if (obj === null || obj === undefined) return obj;
@@ -129,7 +129,7 @@ code block
129
129
  }).catch(err => {
130
130
  parentPort.postMessage({ error: err.message });
131
131
  });
132
- `,v=new Worker(b,{eval:!0,env:{...process.env,NODE_OPTIONS:""}}),R=await new Promise((L,C)=>{v.on("message",L),v.on("error",C);let w=setTimeout(()=>{v.terminate(),C(new Error("Config loading timed out"));},3e4);});if(v.terminate(),R.error)throw new Error(R.error);Ro.writeFileSync(u,JSON.stringify(R,null,2),"utf8"),i.info("Project config loaded for admin");}catch(f){i.error(`Could not load project config: ${f.message}`);}finally{if(g&&Ro.existsSync(g))try{Ro.unlinkSync(g);}catch{}}n({vite:{plugins:[{name:"kyro-admin-tsx-loader",enforce:"pre",config(f){let y=f.esbuild,b=y?.exclude,v=/\/node_modules\/(?!.*@kyro-cms\/(admin|core))/;return {esbuild:{...y||{},exclude:b?Array.isArray(b)?[...b,v]:[b,v]:v}}}},{name:"kyro-cjs-shim",enforce:"pre",resolveId(f){if(f.includes("react/compiler-runtime"))return "\0react-compiler-runtime";if(f==="debug"||f.includes("debug/src/browser.js"))return "\0debug-browser"},load(f){if(f==="\0react-compiler-runtime")return `
132
+ `,u=new Worker(y,{eval:!0,env:{...process.env,NODE_OPTIONS:""}}),N=await new Promise((R,S)=>{u.on("message",R),u.on("error",S);let h=setTimeout(()=>{u.terminate(),S(new Error("Config loading timed out"));},3e4);});if(u.terminate(),N.error)throw new Error(N.error);Po.writeFileSync(v,JSON.stringify(N,null,2),"utf8"),i.info("Project config loaded for admin");}catch(x){i.error(`Could not load project config: ${x.message}`);}finally{if(f&&Po.existsSync(f))try{Po.unlinkSync(f);}catch{}}n({vite:{plugins:[{name:"kyro-admin-tsx-loader",enforce:"pre",config(x){let g=x.esbuild,y=g?.exclude,u=/\/node_modules\/(?!.*@kyro-cms\/(admin|core))/;return {esbuild:{...g||{},exclude:y?Array.isArray(y)?[...y,u]:[y,u]:u}}}},{name:"kyro-cjs-shim",enforce:"pre",resolveId(x){if(x.includes("react/compiler-runtime"))return "\0react-compiler-runtime";if(x==="debug"||x.includes("debug/src/browser.js"))return "\0debug-browser"},load(x){if(x==="\0react-compiler-runtime")return `
133
133
  import React from "react";
134
134
  export function c(size) {
135
135
  const internals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
@@ -138,7 +138,7 @@ export function c(size) {
138
138
  }
139
139
  return internals.H.useMemoCache(size);
140
140
  }
141
- `;if(f==="\0debug-browser")return `
141
+ `;if(x==="\0debug-browser")return `
142
142
  function debug(namespace) {
143
143
  function d(...args) {
144
144
  if (typeof localStorage !== "undefined" && localStorage.getItem("DEBUG")) {
@@ -151,4 +151,4 @@ debug.enable = function() {};
151
151
  debug.disable = function() {};
152
152
  debug.enabled = function() { return false; };
153
153
  export default debug;
154
- `}}],resolve:{alias:{"kyro:config":m}},optimizeDeps:{include:["@kyro-cms/admin"],exclude:["debug","react/compiler-runtime"]},define:{__KYRO_ADMIN_PATH__:JSON.stringify(t),__KYRO_API_PATH__:JSON.stringify(r),__KYRO_ADMIN_CONFIG_FILE__:JSON.stringify(u)},ssr:{noExternal:["@kyro-cms/admin","@kyro-cms/core","@tiptap/core","@tiptap/react","@tiptap/pm","@tiptap/starter-kit","@tiptap/extension-link","@tiptap/extension-image","@tiptap/extension-text-align","@tiptap/extension-underline","@tiptap/extension-highlight","@tiptap/extension-task-list","@tiptap/extension-task-item","@tiptap/extension-text-style","@tiptap/extension-color","prosemirror-model","prosemirror-state","prosemirror-view","prosemirror-schema-list","prosemirror-commands","prosemirror-keymap","prosemirror-transform","prosemirror-inputrules"]}}}),globalThis.__KYRO_ADMIN_PROJECT_CONFIG__={collections:[],globals:[],adapter:null};let x=[{pattern:"",entrypoint:"./pages/index.astro"},{pattern:"/login",entrypoint:"./pages/auth/login.astro"},{pattern:"/register",entrypoint:"./pages/auth/register.astro"},{pattern:"/media",entrypoint:"./pages/media.astro"},{pattern:"/users",entrypoint:"./pages/users/index.astro"},{pattern:"/users/new",entrypoint:"./pages/users/new.astro"},{pattern:"/users/[id]",entrypoint:"./pages/users/[id].astro"},{pattern:"/roles",entrypoint:"./pages/roles/index.astro"},{pattern:"/settings",entrypoint:"./pages/settings/index.astro"},{pattern:"/settings/[slug]",entrypoint:"./pages/settings/[slug].astro"},{pattern:"/audit",entrypoint:"./pages/audit/index.astro"},{pattern:"/sessions",entrypoint:"./pages/sessions.astro"},{pattern:"/keys",entrypoint:"./pages/keys.astro"},{pattern:"/webhooks",entrypoint:"./pages/webhooks.astro"},{pattern:"/plugins",entrypoint:"./pages/plugins.astro"},{pattern:"/marketplace",entrypoint:"./pages/marketplace.astro"},{pattern:"/graphql",entrypoint:"./pages/graphql.astro"},{pattern:"/rest-playground",entrypoint:"./pages/rest-playground.astro"},{pattern:"/[collection]",entrypoint:"./pages/[collection]/index.astro"},{pattern:"/[collection]/[id]",entrypoint:"./pages/[collection]/[id].astro"}];for(let f of x){let y=`${t}${f.pattern}`.replace(/\/$/,"");s({pattern:y||"/",entrypoint:fr.resolve(new URL(".",import.meta.url).pathname,f.entrypoint)});}},"astro:build:done":({logger:a})=>{a.info("Kyro Admin build complete");}}}}export{Xs as ActionBar,ku as Admin,_a as AutoForm,Pt as Badge,hu as BulkActionsBar,ms as Button,bs as ConfirmModal,ps as CountBadge,Zs as CreateView,Sa as DARK_THEME,Nn as DarkThemeProvider,Ys as DetailView,wo as Dropdown,Ht as DropdownItem,ja as DropdownSeparator,Nn as ExtDarkThemeProvider,wn as ExtLightThemeProvider,kr as ExtThemeProvider,ZT as Header,Eo as LIGHT_THEME,wn as LightThemeProvider,fs as ListView,ri as LoginPage,Ut as Modal,Ft as PageHeader,dr as SlidePanel,Ar as Spinner,kr as ThemeProvider,$d as Toast,B4 as ToastProvider,Fu as VersionHistoryPanel,Ye as adminPath,Zd as afterDeploy,io as apiPath,Yd as beforeDeploy,ec as emitAdminReady,rc as emitAfterDeploy,tc as emitBeforeDeploy,mc as getBlock,uc as getBlocks,yc as getBlocksByCategory,xc as getField,hc as getFieldByType,kc as getFields,lc as getPlugin,dc as getPlugins,cc as getPluginsWithHook,Xu as kyroAdmin,Ta as mergeThemes,Yn as onAdminReady,Ec as paths,sa as registerBlock,la as registerField,aa as registerPlugin,ts as resolveAdmin,qe as resolveApi,pc as unregisterBlock,bc as unregisterField,ic as unregisterPlugin,fc as useBlockRenderer,Oo as useExtTheme,wc as useFieldRenderer,sc as useKyroMutation,nc as useKyroQuery,Oo as useTheme,I4 as useToast};
154
+ `}}],resolve:{alias:{"kyro:config":m}},optimizeDeps:{include:["@kyro-cms/admin"],exclude:["debug","react/compiler-runtime"]},define:{__KYRO_ADMIN_PATH__:JSON.stringify(t),__KYRO_API_PATH__:JSON.stringify(r),__KYRO_ADMIN_CONFIG_FILE__:JSON.stringify(v)},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 x of b){let g=`${t}${x.pattern}`.replace(/\/$/,"");s({pattern:g||"/",entrypoint:vr.resolve(new URL(".",import.meta.url).pathname,x.entrypoint)});}},"astro:build:done":({logger:a})=>{a.info("Kyro Admin build complete");}}}}export{ei as ActionBar,Xu as Admin,Ka as AutoForm,Dt as Badge,Qu as BulkActionsBar,us as Button,xs as ConfirmModal,ms as CountBadge,oi as CreateView,Ra as DARK_THEME,Sn as DarkThemeProvider,ri as DetailView,Co as Dropdown,_t as DropdownItem,Ha as DropdownSeparator,Sn as ExtDarkThemeProvider,Cn as ExtLightThemeProvider,hr as ExtThemeProvider,YR as Header,Uo as LIGHT_THEME,Cn as LightThemeProvider,vs as ListView,si as LoginPage,Ut as Modal,Pt as PageHeader,cr as SlidePanel,Pr as Spinner,hr as ThemeProvider,jd as Toast,D3 as ToastProvider,ny as VersionHistoryPanel,tt as adminPath,ac as afterDeploy,co as apiPath,oc as beforeDeploy,nc as emitAdminReady,ic as emitAfterDeploy,sc as emitBeforeDeploy,gc as getBlock,bc as getBlocks,xc as getBlocksByCategory,Cc as getField,Tc as getFieldByType,Sc as getFields,uc as getPlugin,yc as getPlugins,fc as getPluginsWithHook,Ty as kyroAdmin,Aa as mergeThemes,Zn as onAdminReady,_c as paths,la as registerBlock,ca as registerField,sa as registerPlugin,rs as resolveAdmin,Ye as resolveApi,vc as unregisterBlock,Nc as unregisterField,mc as unregisterPlugin,kc as useBlockRenderer,zo as useExtTheme,Rc as useFieldRenderer,pc as useKyroMutation,cc as useKyroQuery,zo as useTheme,I3 as useToast};