your-ai-workflow-firebase-os 1.2.7 → 1.2.8
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.
|
@@ -503,7 +503,7 @@ export const themeConfig = {
|
|
|
503
503
|
cardRadius: ${i.cardRadius||1.5}, // 24px (2xl, 3xl)
|
|
504
504
|
modalRadius: ${i.modalRadius||2.5}, // Global popups and main internal boxes
|
|
505
505
|
}
|
|
506
|
-
};`;navigator.clipboard.writeText(a),l(!0),setTimeout(()=>l(!1),2e3)}};return(0,m.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`a`&&document.activeElement===document.body&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&e.key===`c`&&!window.getSelection()?.toString()&&t&&_()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Theme`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/theme`]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col min-h-[600px]`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Theme Config`}),(0,y.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Changes here immediately format natively. Save to update your Live Preview panel entirely.`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:f,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-xl flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:a?(0,y.jsx)(W,{className:`w-4 h-4 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(Z,{variant:`secondary`,onClick:_,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors`,title:`Copy Config (Ctrl+C)`,children:c?(0,y.jsx)(be,{className:`w-4 h-4 text-emerald-500`}):(0,y.jsx)(je,{className:`w-4 h-4 text-foreground/60 hover:text-foreground transition-colors`})})]})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 w-full relative z-10 items-start`,children:[a&&(0,y.jsx)(`div`,{className:`absolute inset-0 bg-background/60 backdrop-blur-[2px] z-50 flex items-center justify-center rounded-3xl pointer-events-none transition-all duration-300`,children:(0,y.jsx)(W,{className:`w-8 h-8 animate-spin text-accent`})}),(0,y.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-8 shadow-inner overflow-hidden relative bg-background`,children:[(0,y.jsx)(`h3`,{className:`text-lg font-extrabold text-foreground tracking-tight mb-4 flex items-center gap-3`,children:`Branding & Colours`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-4 pt-2 mb-6 border-b border-[var(--panel-border)]/50 shrink-0`,children:[(0,y.jsx)(`div`,{className:`text-[12px] font-bold text-foreground/40 shrink-0 uppercase tracking-widest pl-1 mr-2`,children:`Presets`}),$Vn.map(e=>{let n=t?.colors?.dark?.accent===e.dark.accent&&t?.colors?.dark?.buttonGradient?.[0]===e.dark.gradient[0],r=e.name===`Black & White`;return(0,y.jsx)(`button`,{onClick:()=>g(e),className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative group overflow-visible ${n?`ring-[3px] ring-foreground ring-offset-2 ring-offset-[var(--background)] scale-110 z-10`:`opacity-80 hover:opacity-100 hover:ring-2 hover:ring-foreground/30 hover:ring-offset-2 hover:ring-offset-[var(--background)] hover:scale-105`}`,title:e.name,children:(0,y.jsx)(`div`,{className:`absolute inset-0 rounded-full`,style:r?{backgroundColor:`#ffffff`,border:`3px solid #000000`,boxShadow:`inset 0 0 0 1px rgba(0,0,0,0.1)`}:{backgroundImage:`linear-gradient(135deg, ${e.preview[0]}, ${e.preview[1]})`}})},e.name)})]}),(0,y.jsx)(`div`,{className:`w-full relative min-h-[100px]`,children:t?(0,y.jsxs)(`div`,{className:`flex flex-col pl-2`,children:[(0,y.jsxs)(`span`,{className:`text-yellow-500 font-mono text-[13px] mb-2`,children:[`export const themeConfig = `,`{`]}),(0,y.jsx)(q9,{value:t,keysToRender:[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`,`cornerRounding`,`cornerRadii`,`fontFamily`],onChange:e=>n(e),isLast:!1,isGlobalSaving:r}),(0,y.jsx)(`div`,{className:`mt-4`,children:(0,y.jsx)(q9,{objectKey:`colors`,value:t.colors,onChange:e=>n({...t,colors:e}),isLast:!1,isGlobalSaving:r})})]}):(0,y.jsx)(`div`,{className:`flex items-center justify-center w-full h-full text-foreground/40 font-mono text-[13px] animate-pulse py-10`,children:`Loading Data Tree...`})})]})]})]})]})]})}var rHn={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},iHn={tabName:`New Private Page`,iconName:``,route:`/new-private-page`,template:`none`,form:`support`,showPrompt:!0,tabTitle:`Private Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},aHn={tabName:`Admin Tab`,iconName:``,route:`/admin-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Admin Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},oHn={tabName:`Shared Tab`,iconName:``,route:`/shared-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Shared Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},sHn=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],cHn=({enabled:e,onChange:t,disabled:n,className:r=``})=>(0,y.jsx)(`button`,{disabled:n,onClick:()=>t(!e),title:e?`Page Active`:`Page Hidden`,className:`p-1.5 transition-colors rounded-lg flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity ${r} ${e?`text-accent hover:bg-accent/10`:`text-foreground/40 hover:bg-foreground/5`} ${n?`!opacity-50 cursor-not-allowed`:`cursor-pointer`}`,children:e?(0,y.jsx)(Ie,{className:`w-4 h-4`}):(0,y.jsx)(Fe,{className:`w-4 h-4`})});function lHn(){let{userRole:e}=B(),t=(0,b.useLocation)(),[n,r]=(0,m.useState)(sHn),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)({}),[u,d]=(0,m.useState)({}),[f,p]=(0,m.useState)({}),[g,_]=(0,m.useState)(null),[v,x]=(0,m.useState)(!1),S=(0,m.useRef)(null);(0,m.useEffect)(()=>{function e(e){S.current&&!S.current.contains(e.target)&&s(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[C,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(new Set),[M,N]=(0,m.useState)(new Set),[P,F]=(0,m.useState)([]),[I,ee]=(0,m.useState)([]),L=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden});(0,m.useEffect)(()=>{let e=(0,h.onSnapshot)((0,h.doc)(w,`sys_configs`,`page_order`),e=>{let t=L(e.exists()&&e.data().order||[]);F(t),j(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),t=(0,h.onSnapshot)((0,h.doc)(w,`sys_configs`,`tab_order`),e=>{let t=L(e.exists()&&e.data().order||[]);ee(t),N(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),t()}},[]),(0,m.useEffect)(()=>{let e=t.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!i&&n.some(t=>t.id===e)&&a(e)},[t.pathname,n]),(0,m.useEffect)(()=>{let e=(e,t)=>{if(!t)return e;let n=Object.fromEntries(Object.entries(t).filter(([e,t])=>t!=null&&t!==``));return{...e,...n}},t=(0,h.onSnapshot)((0,h.doc)(w,`sys_pages`,`home`),t=>{T(t.exists()?e(Ao,t.data()):Ao)});return()=>{t()}},[]),(0,m.useEffect)(()=>{(async()=>{try{let[e,t]=await Promise.all([(0,h.getDocs)((0,h.collection)(w,`sys_pages`)),(0,h.getDocs)((0,h.collection)(w,`sys_tabs`))]),n=[`home`,`contact`,`support`,`theme`,`page_order`,`tab_order`],i=[],a={};e.forEach(e=>{if(!n.includes(e.id)){let t=e.data();i.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),t.forEach(e=>{if(!n.includes(e.id)){let t=e.data(),n=t.pageType||`private`;i.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),i.length>0&&(r(e=>{let t=e.filter(e=>e.isSystem||e.id.startsWith(`draft_`)),n=i.filter(e=>!t.some(t=>t.id===e.id));return[...t,...n]}),l(e=>({...e,...a})))}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[R,te]=(0,m.useState)([`contact`]),[z,ne]=(0,m.useState)([`support`]);(0,m.useEffect)(()=>{(0,h.getDocs)((0,h.collection)(w,`sys_forms`)).then(e=>{let t=[],n=[];e.forEach(e=>{e.data().formType===`private`?n.push(e.id):t.push(e.id)}),t.length>0&&te(t),n.length>0&&ne(n)}).catch(console.error)},[]);let[re,V]=(0,m.useState)(null),ie=(e,t)=>{let n=JSON.stringify(t,null,2);navigator.clipboard.writeText(n),V(e),setTimeout(()=>V(null),2e3)},H=async(e,t)=>{t.route&&!t.route.startsWith(`/`)&&(t.route=`/`+t.route);let o=n.find(t=>t.id===e)?.type,s=o===`public`?`sys_pages`:`sys_tabs`;o&&o!==`public`&&(t.pageType=o);let c=[`home`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?D(!0):d(t=>({...t,[e]:!0,[c]:!0}));try{if(c!==e&&c.trim()!==``&&c!==`draft`){try{let{deleteDoc:t}=await import(`firebase/firestore`);await t((0,h.doc)(w,s,e))}catch{}await(0,h.setDoc)((0,h.doc)(w,s,c),t),r(n=>n.map(n=>n.id===e?{...n,id:c,_uiKey:n._uiKey||e,path:t.route,title:t.pageName||t.tabName||t.title||n.title}:n)),l(n=>{let r={...n};return r[c]=t,delete r[e],r}),i===e&&(a(c),window.history.replaceState(null,``,`/pages/${c}`));let n=o===`public`,u=n?`page_order`:`tab_order`,d=n?P:I;if(!d.some(e=>e.id===c)){let t=[...d.filter(t=>t.id!==e),{id:c,hidden:!1}];try{await(0,h.setDoc)((0,h.doc)(w,`sys_configs`,u),{order:t})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,h.setDoc)((0,h.doc)(w,s,e),t),e===`home`?T(t):(l(n=>({...n,[e]:t})),r(n=>n.map(n=>n.id===e?{...n,path:t.route||n.path,title:t.pageName||t.tabName||t.title||n.title}:n)))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{e===`home`?D(!1):d(t=>({...t,[e]:!1,[c]:!1}))},500)}},ae=async e=>{e.stopPropagation(),k(!0),await H(`home`,Ao),setTimeout(()=>k(!1),500)},oe=async(e,t,n)=>{e.stopPropagation(),p(e=>({...e,[t]:!0})),await H(t,n),setTimeout(()=>p(e=>({...e,[t]:!1})),500)},se=e=>{let t=`draft_`+Math.floor(Math.random()*1e4);r([...n,{id:t,title:`New Tab`,path:`/draft`,type:e,isSystem:!1,enabled:!0}]);let i={};e===`public`?i={...rHn}:e===`private`?i={...iHn}:e===`admin`?i={...aHn}:e===`shared`&&(i={...oHn}),l(e=>({...e,[t]:i})),a(t),s(!1),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)};if(e!==`admin`)return(0,y.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,y.jsx)(tt,{className:`w-12 h-12 text-red-500 mb-4`}),(0,y.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,y.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let ce=async(e,t,i)=>{let a=i===`public`,o=a?`page_order`:`tab_order`,s=a?P:I,c=(a?A:M).has(e);r(n.map(t=>t.id===e?{...t,enabled:c}:t));let l=[...s],u=l.findIndex(t=>t.id===e);u===-1?l.push({id:e,hidden:!0}):l[u]={...l[u],hidden:!c},await(0,h.setDoc)((0,h.doc)(w,`sys_configs`,o),{order:l})},U=(e,t)=>{t||_(e)},le=async()=>{if(g){x(!0);try{let{deleteDoc:e,collection:t,getDocs:o,doc:s}=await import(`firebase/firestore`),c=n.find(e=>e.id===g),l=c?.type===`public`?`sys_pages`:`sys_tabs`;if(await e(s(w,l,g)),l===`sys_tabs`&&c){let n=c.id;try{let r=[`admin_${n}_records`,`mem_${n}_records`,`user_${n}_records`];for(let n of r){let r=(await o(t(w,n))).docs.map(t=>e(t.ref));await Promise.all(r)}}catch(e){console.error(`Error cleaning up tab records:`,e)}}let u=l===`sys_pages`?`page_order`:`tab_order`,d=l===`sys_pages`?P:I,{setDoc:f}=await import(`firebase/firestore`),p=d.filter(e=>e.id!==g);await f(s(w,`sys_configs`,u),{order:p}),r(e=>e.filter(e=>e.id!==g)),i===g&&a(null)}catch(e){console.error(`Error deleting page:`,e)}x(!1),_(null)}},ue=e=>{let t=e.id+`_`+Math.floor(Math.random()*1e3),n={...e,id:t,title:`${e.title} (Copy)`,path:`${e.path}_copy`,isSystem:!1,enabled:!0};r(e=>[...e,n]);let i=c[e.id];!i&&e.id===`home`&&(i=C);let o={...i||{},route:n.path,pageName:n.title};n.type!==`public`&&(o.tabName=n.title,o.pageType=n.type),l(e=>({...e,[t]:o})),a(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},de=[{id:`public`,title:`Public Pages`,icon:ze,color:`bg-amber-500`,description:`Creates external menu items. Invisible to signed-in dashboard users.`,filter:e=>e.type===`public`},{id:`private`,title:`Private Pages`,icon:Ke,color:`bg-emerald-500`,description:`Internal dashboard tabs for regular users.`,filter:e=>e.type===`private`},{id:`shared`,title:`Shared Pages`,icon:Ie,color:`bg-blue-500`,description:`Dashboard tabs visible to all members, editors, and admins.`,filter:e=>e.type===`shared`},{id:`admin`,title:`Admin Pages`,icon:tt,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[fe,pe]=(0,m.useState)(!1),[me,he]=(0,m.useState)(!1);return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Pages`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`,i?`/${i}`:``]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Architecture`}),(0,y.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Manage the structure of your application tabs and public pages.`})]}),(0,y.jsxs)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:()=>pe(!0),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Reset Defaults`,children:(0,y.jsx)($e,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,y.jsxs)(`div`,{className:`relative`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:()=>s(!o),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Add New Page`,children:(0,y.jsx)(Qe,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,y.jsx)(K,{children:o&&(0,y.jsx)(q.div,{ref:S,initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},className:`absolute top-full mt-2 right-0 w-48 glass-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-xl z-50 flex flex-col gap-1`,children:[`public`,`private`,`shared`,`admin`].map(e=>(0,y.jsxs)(`button`,{onClick:()=>{se(e),s(!1)},className:`text-left px-3 py-2 text-[13px] font-bold uppercase tracking-wider text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:[e,` Page`]},e))})})]})]})]}),(0,y.jsxs)(`div`,{className:`px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-0 gap-10 overflow-y-auto mt-2 relative min-h-[400px]`,children:[(0,y.jsx)(K,{children:me&&(0,y.jsx)(q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-[2px] rounded-3xl`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-6 glass-panel rounded-2xl shadow-xl`,children:[(0,y.jsx)(W,{className:`w-8 h-8 md:w-10 md:h-10 animate-spin text-accent mb-4`}),(0,y.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:`Synchronizing Architecture...`})]})})}),de.map((e,t)=>{let r=n.filter(e.filter),o=e.id===`public`?P:I,s=r.sort((e,t)=>{let n=o.findIndex(t=>t.id===e.id),r=o.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),l=e.icon,d=e=>e.type===`public`?A.has(e.id):M.has(e.id),p=s.filter(e=>!d(e)),m=s.filter(e=>d(e)),h=e=>{if(!e)return[];let t=[`route`,`pageName`,`template`];return e.template===`none`?(t.push(`pageTitle`,`copyPrompt`),t.push(`showButton`),e.showButton!==!1&&(t.push(`buttonText`,`action`),e.action===`form`?t.push(`form`):e.action===`redirect`&&t.push(`redirectUrl`))):(e.template===`popup_form`||e.template===`inline_form`)&&(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)),t},g=e=>{if(!e)return[];let t=[`tabName`,`iconName`,`route`,`template`];return e.template===`popup_form`||e.template===`inline_form`?(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)):e.template===`none`?(t.push(`showPrompt`,`tabTitle`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonStyle`,`buttonText`,`buttonAction`),t.push(`storage`),e.storage!==!1&&t.push(`buttonStorageIcon`,`buttonStorageText`,`buttonStorageStyle`,`buttonStorageAction`)):e.template===`calendar`?(t.push(`tabTitle`,`showPrompt`),t.push(`defaultView`,`defaultTimeFormat`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showViewsButton`),e.showViewsButton!==!1&&t.push(`viewsButtonStyle`)):e.template===`table`?(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showExportButton`),e.showExportButton!==!1&&t.push(`exportButtonIcon`)):e.template===`board`&&(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`keyName`,`valueName`)),t},_=(t,n,r)=>{let o=t.id===`home`,s=i===t.id,l=o||!t.isSystem;return(0,y.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(l){let e=s?null:t.id;a(e),window.history.replaceState(null,``,e?`/pages/${e}`:`/pages`)}},className:`group flex flex-col py-4 px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${l?`cursor-pointer hover:border-accent/40`:``} ${r?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-center justify-between w-full gap-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-1 w-full flex-1`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:t.title}),o&&E&&(0,y.jsx)(W,{className:`w-3 h-3 animate-spin text-accent ml-2`})]}),(0,y.jsxs)(`div`,{className:`text-[11px] font-medium font-mono px-2 py-0.5 rounded w-fit ml-6 border ${r?`text-foreground/50 border-foreground/10 bg-foreground/5`:`text-accent/70 bg-accent/5 border-accent/10`}`,children:[window.location.host,t.path]})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-4 shrink-0`,children:[!t.isSystem||[`contact`,`support`,`templates`].includes(t.id)?(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ue(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Duplicate Page`,children:(0,y.jsx)(je,{className:`w-4 h-4`})}):(0,y.jsx)(`div`,{className:`w-[28px] shrink-0`}),(0,y.jsx)(`div`,{className:`flex items-center justify-end w-8 shrink-0`,children:t.id===`home`?(0,y.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,y.jsx)(cHn,{enabled:!d(t),onChange:()=>ce(t.id,t.isSystem,t.type)})}),t.isSystem?(0,y.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),U(t.id,t.isSystem)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Delete Page`,children:(0,y.jsx)(rt,{className:`w-4 h-4`})}),l?(0,y.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${s?`rotate-180`:``}`,children:(0,y.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,y.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}):(0,y.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,y.jsxs)(K,{children:[s&&o&&C&&(0,y.jsx)(q.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,y.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,y.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,y.jsx)(`button`,{onClick:ae,className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:O?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ie(`home`,C)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===`home`?(0,y.jsx)(Ee,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,y.jsx)(je,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,y.jsx)(q9,{value:C,keysToRender:[`hero`],onChange:e=>H(`home`,e),isLast:!0,isGlobalSaving:E,customEnums:{form:R},customExplanations:{form:`User can click to switch to any public form we have in the forms tab. Private forms are not an option here. Add a new form in forms with a link that actually works.`}})]})}),s&&!t.isSystem&&c[t.id]&&(0,y.jsx)(q.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,y.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,y.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,y.jsx)(`button`,{onClick:e=>oe(e,t.id,t.type===`admin`?aHn:t.type===`shared`?oHn:t.type===`public`?rHn:iHn),className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:f[t.id]?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ie(t.id,c[t.id])},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===t.id?(0,y.jsx)(Ee,{className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`}):(0,y.jsx)(je,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,y.jsx)(q9,{value:c[t.id],keysToRender:t.type===`public`?h(c[t.id]):g(c[t.id]),onChange:e=>H(t.id,e),isLast:!0,isGlobalSaving:u[t.id],customEnums:{form:t.type===`public`?R:z,template:t.type===`public`?[`none`,`popup_form`,`inline_form`]:t.type===`admin`||t.type===`shared`?[`none`,`calendar`,`table`,`board`]:[`none`,`calendar`,`table`,`board`,`popup_form`,`inline_form`],action:[`save_Info`,`form`],defaultTimeFormat:[`12h`,`24h`],defaultView:[`calendar`,`board`],buttonStyle:[`primary`,`secondary`],buttonAction:[`save_info`],viewsButtonStyle:[`primary`,`secondary`],buttonStorageStyle:[`primary`,`secondary`],buttonStorageAction:[`upload_file`]},customExplanations:{tabName:`Defines the tab label in the dashboard navigation.`,iconName:`Visit https://iconoir.com/, find an icon, and paste its exact name (e.g. 'learning', 'server', 'cloud-upload').`,route:`The URL path for this tab (e.g. '/my-tab'). Must start with /.`,template:`Page layout type. 'none' gives you a freeform dashboard with add/upload buttons.`,form:`Which form to display. Only applies to popup_form or inline_form templates. Go to /forms to edit forms.`,tabTitle:`The heading that appears at the top of the page content area.`,showPrompt:`Shows the developer AI prompt copy button in the header.`,showButton:`Toggles the + add record button in the header.`,buttonStyle:`Visual style of the add button: 'primary' (accent) or 'secondary' (subtle).`,buttonText:`Label on the add button. Use '+' for a minimal icon-only button.`,buttonAction:`'save_info' saves a name + note record to the tab's Firestore collection.`,storage:`Enables the file upload button for this tab.`,buttonStorageIcon:`Icon name from https://iconoir.com/ for the upload button (e.g. 'upload', 'cloud-upload').`,buttonStorageText:`Label next to the upload icon. Leave empty for icon-only.`,buttonStorageStyle:`'primary' or 'secondary' visual style for the upload button.`,buttonStorageAction:t.type===`admin`?`'upload_file' uploads to admin_files/ in Storage and mirrors metadata to admin_files collection (Drive > Admin).`:t.type===`shared`?`'upload_file' uploads to mem_files/ in Storage and mirrors metadata to mem_files collection (Drive > Shared).`:`'upload_file' uploads to user_files/ in Storage and mirrors metadata to user_files collection (Drive > Private).`,defaultView:`Starting view: 'calendar' (month grid) or 'board' (event list). Users can switch between them.`,defaultTimeFormat:`12h or 24h time format. Users can toggle this in the toolbar.`,showViewsButton:`Show the calendar/board view toggle button in the toolbar.`,viewsButtonStyle:`'primary' or 'secondary' visual style for the view toggle.`,showExportButton:`Show the CSV export/download button in the table toolbar.`,exportButtonIcon:`Icon name from https://iconoir.com/ for the export button (e.g. 'download-square', 'import').`,keyName:`Label for the key/title field in board items (e.g. 'Task', 'Name').`,valueName:`Label for the value/description field in board items (e.g. 'Notes', 'Details').`},hideInnerLoader:!0})]})})]})]},`${e.id}-${t._uiKey||t.id}`)};return(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,y.jsx)(`div`,{className:`w-8 h-8 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center -ml-1 shadow-sm`,children:(0,y.jsx)(l,{className:`w-4 h-4 text-accent`})}),(0,y.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,y.jsx)(`p`,{className:`text-[13px] leading-relaxed text-foreground/50 font-medium max-w-3xl mb-4 ml-[2px]`,children:e.description}),s.length===0?(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 opacity-40 glass-panel rounded-2xl border border-[var(--panel-border)]/50 border-dashed`,children:[(0,y.jsx)(Ue,{className:`w-5 h-5 mb-2`}),(0,y.jsx)(`p`,{className:`text-[12px] font-bold`,children:`This section is currently empty.`})]}):(0,y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[p.map(e=>_(e,s.findIndex(t=>t.id===e.id),!1)),m.length>0&&(0,y.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,y.jsxs)(`summary`,{className:`text-[11px] font-bold uppercase tracking-wider text-foreground/40 cursor-pointer list-none flex items-center gap-2 select-none hover:text-foreground/70 transition-colors w-fit pb-1 ml-1 outline-none`,children:[(0,y.jsx)(xe,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,m.length,`)`]}),(0,y.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:m.map(e=>_(e,s.findIndex(t=>t.id===e.id),!0))})]})]}),t<de.length-1&&(0,y.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})]})]})]}),(0,y.jsx)(m9,{isOpen:fe,onCancel:()=>pe(!1),onConfirm:async()=>{he(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,h.doc)(w,`sys_pages`,`home`))]),T(Ao)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{he(!1),pe(!1)},1e3)},title:`Reset System Pages`,message:`Are you sure you want to reset all system page configurations? Custom pages and their order will remain intact.`,confirmText:`Reset`,isProcessing:me}),(0,y.jsx)(m9,{isOpen:!!g,onCancel:()=>_(null),onConfirm:le,title:`Delete Page`,message:`Are you sure you want to delete this page? This action cannot be undone and will remove all associated configurations.`,confirmText:`Remove Page`,isProcessing:v})]})}var J9={contact:f.t,support:p.t};function uHn(){let{userRole:e}=B(),t=(0,b.useNavigate)();(0,b.useLocation)();let[n,r]=(0,m.useState)({}),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)({}),[c,l]=(0,m.useState)(null),[u,d]=(0,m.useState)({}),[f,p]=(0,m.useState)(null),[g,_]=(0,m.useState)(!1),[v,x]=(0,m.useState)(null),S=(e,t)=>{let n=JSON.stringify(t,null,2);navigator.clipboard.writeText(n),x(e),setTimeout(()=>x(null),2e3)};(0,m.useEffect)(()=>{C()},[]);let C=async()=>{try{let e=await(0,h.getDocs)((0,h.collection)(w,`sys_forms`)),t={};e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let n=e.data();n._uiKey||=Math.random().toString(36).substring(7),t[e.id]=n}});try{await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,`pubForm`)),await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,`userForm`))}catch{}for(let[e,n]of Object.entries(J9))if(!t[e]){await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),n);let r={...n};r._uiKey=Math.random().toString(36).substring(7),t[e]=r}else if(!t[e].fields||t[e].fields.length===0){let n=J9[e];t[e].fields=n.fields||[],await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),t[e])}let n=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];n&&t[n]&&d({[n]:!0}),r(t)}catch(e){console.error(`Failed to load forms:`,e)}finally{a(!1)}},T=async(e,t)=>{let i={...t};n[e]?._uiKey&&(i._uiKey=n[e]._uiKey),e===`contact`?(i.systemName=`contact`,i.formType=`public`,i.submitPage=`submissions`):e===`support`&&(i.systemName=`support`,i.formType=`private`,i.submitPage=`requests`);let a=i.systemName||e;if(a!==e&&a.trim()!==``){r(t=>{let n={};for(let r of Object.keys(t))r===e?n[a]=i:n[r]=t[r];return n}),u[e]&&d(t=>{let n={};for(let r of Object.keys(t))r===e?n[a]=t[r]:n[r]=t[r];return n}),s(e=>({...e,[a]:!0}));try{await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,a),i),await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,e))}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{s(e=>({...e,[a]:!1}))},500)}}else{r(t=>({...t,[e]:i})),s(t=>({...t,[e]:!0}));try{await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),i)}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{s(t=>({...t,[e]:!1}))},500)}}},[E,D]=(0,m.useState)(!1),O=async()=>{if(E)return;D(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,n={title:`New Custom Form`,systemName:e,formType:`public`,submitPage:`submissions`,redirectTo:``,submitText:`Submit`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{s(t=>({...t,[e]:!0})),await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),n),r(t=>({[e]:n,...t})),d(t=>({[e]:!0,...t})),t(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{s(t=>({...t,[e]:!1})),D(!1)}},k=async e=>{if(!(e===`contact`||e===`support`)){_(!0);try{await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,e)),r(t=>{let n={...t};return delete n[e],n}),t(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{_(!1),p(null)}}};if(e!==`admin`)return(0,y.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,y.jsx)(at,{className:`w-12 h-12 text-red-500 mb-4`}),(0,y.jsx)(`h2`,{className:`text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-br from-red-400 to-red-600`,children:`Access Restricted`}),(0,y.jsx)(`p`,{className:`text-foreground/60 max-w-sm text-center mt-2 font-medium leading-relaxed`,children:`This area is exclusively for system administrators.`})]})});let A=e=>{d(t=>{let n={...t,[e]:!t[e]};if(n[e])window.history.replaceState(null,``,`/forms/${e}`);else{let e=Object.keys(n).filter(e=>n[e]);e.length>0?window.history.replaceState(null,``,`/forms/${e[0]}`):window.history.replaceState(null,``,`/forms`)}return n})},j=Object.keys(u).find(e=>u[e]);return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Forms`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,j?`/${j}`:``]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10 bg-background/50`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Custom Forms`}),(0,y.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`This is the central page where you configure and manage your application's forms. Easily add and customize the fields for your users.`})]}),(0,y.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,y.jsx)(Z,{variant:`secondary`,onClick:O,title:`Add Custom Form`,disabled:E,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,children:E?(0,y.jsx)(W,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,y.jsx)(Qe,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,y.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:i?(0,y.jsx)(`div`,{className:`flex items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)]`,children:(0,y.jsx)(W,{className:`w-6 h-6 animate-spin text-accent`})}):Object.keys(n).length===0?(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed opacity-50`,children:[(0,y.jsx)(aee,{className:`w-6 h-6 mb-3 text-foreground/40`}),(0,y.jsx)(`p`,{className:`text-[13px] font-bold`,children:`No forms currently configured.`})]}):(0,y.jsx)(K,{children:Object.entries(n).map(([e,t])=>{let n=u[e],r=o[e];return(0,y.jsxs)(q.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},onClick:()=>A(e),className:`group flex flex-col p-3 px-4 glass-panel border transition-all rounded-2xl hover:shadow-sm cursor-pointer hover:border-accent/40 ${n?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${t.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:t.title||`Untitled Form`}),r&&(0,y.jsx)(W,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,y.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border border-[var(--panel-border)] bg-foreground/5 text-foreground/60 px-2 py-0.5 rounded-md`,children:t.systemName||e}),(0,y.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${t.formType===`private`?`text-blue-500 bg-blue-500/10 border-blue-500/20`:`text-green-500 bg-green-500/10 border-green-500/20`}`,children:t.formType||`public`})]})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),l(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center mr-2`,title:`Preview Form`,children:(0,y.jsx)(Ie,{className:`w-4 h-4`})}),e!==`contact`&&e!==`support`?(0,y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),p(e)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg opacity-0 group-hover:opacity-100 flex items-center justify-center mr-2`,title:`Delete Form`,children:(0,y.jsx)(rt,{className:`w-4 h-4`})}):(0,y.jsx)(`div`,{className:`w-7 mr-2 shrink-0`}),(0,y.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${n?`rotate-180`:``}`,children:(0,y.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,y.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,y.jsx)(K,{children:n&&(0,y.jsx)(q.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50`,onClick:e=>e.stopPropagation(),children:(0,y.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,y.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),T(e,J9[e]||J9.contact)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:r?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(`button`,{onClick:n=>{n.stopPropagation(),S(e,t)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:v===e?(0,y.jsx)(Ee,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,y.jsx)(je,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,y.jsx)(q9,{value:{systemName:t.systemName||e,formType:t.formType||`public`,submitPage:t.submitPage||(t.formType===`private`?`requests`:`submissions`),redirectTo:t.redirectTo||``,title:t.title||``,buttonName:t.buttonName||t.submitText||``,fields:t.fields||[]},keysToRender:[`systemName`,`formType`,`submitPage`,`redirectTo`,`title`,`buttonName`,`fields`],meta:{formType:t.formType||`public`},onChange:n=>{n.formType===t.formType?n.submitPage!==t.submitPage&&(n.formType=n.submitPage===`requests`?`private`:`public`):n.submitPage=n.formType===`public`?`submissions`:`requests`,T(e,{...t,...n,submitText:n.buttonName})},isLast:!0,isGlobalSaving:r,disabledKeys:e===`contact`||e===`support`?[`systemName`,`formType`,`submitPage`]:[],customEnums:{type:[`text`,`email`,`tel`,`textarea`,`number`,`select`,`checkbox`,`currency`,`age`]},customExplanations:{formType:e===`contact`?`Public means its for not signed in users. Private is disabled for contact so don't allow the user to change it.`:e===`support`?`This means that the form is available to signed in users only.`:`Public means it's for non-signed in users.`,submitPage:e===`contact`?`Means the form submissions go to this folder. User can't change that since it's directly linked. Public is tied to submissions.`:e===`support`?`Can't change since all private forms go there.`:`Where to route data submissions.`,redirectTo:`If not added form will just show a success message. If added, in 30 seconds after success user is redirected.`}})]})})})]},t._uiKey||e)})})})]})]}),(0,y.jsx)(m9,{isOpen:!!f,onCancel:()=>p(null),onConfirm:()=>{f&&k(f)},title:`Delete Form`,message:`Are you sure you want to permanently delete "${f}"? This action cannot be reversed.`,confirmText:`Delete form`,isProcessing:g}),c&&(0,y.jsx)(wo,{formConfig:c,onClose:()=>l(null)})]})}function dHn({config:e}){let[t,n]=(0,m.useState)(!1),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)([]);(0,m.useEffect)(()=>{document.title=e.pageName||e.pageTitle||`Firebase OS`,(0,h.getDocs)((0,h.collection)(w,`sys_forms`)).then(e=>{o(e.docs.filter(e=>e.data().formType===`public`).map(e=>e.id))})},[e.pageName,e.pageTitle]);let s=MBn(e,a);return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 relative min-h-screen`,children:[(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,y.jsxs)(`div`,{className:`flex justify-between items-center mb-6 pt-2 border-b border-[var(--panel-border)] pb-6 relative z-20 overflow-x-auto no-scrollbar gap-4`,children:[(0,y.jsxs)(`button`,{onClick:()=>window.history.back(),className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 cursor-pointer shadow-sm text-foreground/70 whitespace-nowrap shrink-0`,children:[(0,y.jsx)(fe,{className:`w-4 h-4`}),` Go Back`]}),(0,y.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[e.copyPrompt&&(0,y.jsxs)(`button`,{onClick:()=>{navigator.clipboard.writeText(s),n(!0),setTimeout(()=>n(!1),2e3)},title:`Copy Developer Prompt`,className:`px-6 py-2.5 rounded-xl border border-[var(--panel-border)] bg-background flex items-center gap-2 hover:bg-foreground/5 hover:text-accent transition-all cursor-pointer text-[14px] font-bold tracking-wide shadow-sm whitespace-nowrap`,children:[(0,y.jsx)(ge,{className:`w-4 h-4`}),(0,y.jsx)(`span`,{className:`hidden sm:inline`,children:t?`Copied!`:`Copy Prompt`})]}),e.showButton&&(0,y.jsx)(`button`,{onClick:()=>{e.action===`redirect`?window.location.href=e.url||`/`:e.action===`form`&&i(e.form||`contact`)},className:`px-6 py-2.5 rounded-xl font-bold tracking-wide transition-all duration-300 flex items-center justify-center btn-primary shadow-xl hover:-translate-y-1 active:scale-95 text-[14px] whitespace-nowrap`,children:e.buttonText||`Action Button`})]})]}),(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:(0,y.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-40 glass-panel border border-[var(--panel-border)]/50 border-dashed m-4 md:m-8 rounded-2xl p-8 py-20 text-center`,children:[(0,y.jsx)(ge,{className:`w-8 h-8 md:w-12 md:h-12 mb-4 text-foreground/80 opacity-50`}),(0,y.jsx)(`p`,{className:`text-[14px] font-bold mb-2`,children:`Click copy prompt at the top to start adding changes`}),(0,y.jsx)(`div`,{className:`mt-8 text-left bg-background p-6 rounded-2xl text-[12px] font-mono whitespace-pre-wrap max-w-2xl border border-[var(--panel-border)]/50 text-foreground/60 shadow-inner`,children:s})]})}),(0,y.jsx)(K,{children:r&&(0,y.jsx)(wo,{onClose:()=>i(null),formId:r})})]})}function fHn({config:e}){let{user:t}=B(),[n,r]=(0,m.useState)([]),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(``),[f,p]=(0,m.useState)(!1),[g,_]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(``),P=(0,m.useRef)(null),[F,I]=(0,m.useState)([]),ee=(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),L=`user_${ee}_records`;(0,m.useEffect)(()=>{document.title=e.tabTitle||e.tabName||`Firebase OS`,(0,h.getDocs)((0,h.collection)(w,`sys_forms`)).then(e=>{I(e.docs.filter(e=>e.data().formType===`private`).map(e=>e.id))})},[e.tabTitle,e.tabName]),(0,m.useEffect)(()=>{t&&(async()=>{a(!0);try{let e=(await(0,h.getDocs)((0,h.query)((0,h.collection)(w,L),(0,h.where)(`uid`,`==`,t.uid)))).docs.map(e=>({id:e.id,...e.data()}));e.sort((e,t)=>{let n=e.createdAt?.toMillis?.()||0;return(t.createdAt?.toMillis?.()||0)-n}),r(e)}catch(e){console.error(`Error fetching records:`,e)}a(!1)})()},[t,L]);let R=async e=>{if(e.preventDefault(),!(!t||!c.trim())){p(!0);try{let e=await(0,h.addDoc)((0,h.collection)(w,L),{name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,createdAt:(0,h.serverTimestamp)()});r(n=>[{id:e.id,name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,createdAt:{toMillis:()=>Date.now()}},...n]),l(``),d(``),s(!1)}catch(e){console.error(`Error saving record:`,e)}p(!1)}},te=async e=>{let n=e.target.files?.[0];if(!(!n||!t)){x(!0);try{let e=(0,v.ref)(T,`user_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,v.uploadBytes)(e,n,{customMetadata:{ownerId:t.uid}});let i=await(0,v.getDownloadURL)(e);await(0,h.addDoc)((0,h.collection)(w,`user_files`),{fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:i,uid:t.uid,uploaderEmail:t.email||`user`,sourceTab:ee,accessPrefix:`user_`,createdAt:(0,h.serverTimestamp)()});let a=await(0,h.addDoc)((0,h.collection)(w,L),{name:n.name,note:`${n.type||`File`} · ${V(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:i,createdAt:(0,h.serverTimestamp)()});r(e=>[{id:a.id,name:n.name,note:`${n.type||`File`} · ${V(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type,fileSize:n.size,downloadURL:i,createdAt:{toMillis:()=>Date.now()}},...e])}catch(e){console.error(`Error uploading file:`,e)}x(!1),P.current&&(P.current.value=``)}},z=async()=>{if(S){D(!0);try{let e=n.find(e=>e.id===S);if(await(0,h.deleteDoc)((0,h.doc)(w,L,S)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];t&&await(0,v.deleteObject)((0,v.ref)(T,`user_files/${decodeURIComponent(t)}`)).catch(()=>{});let n=await(0,h.getDocs)((0,h.query)((0,h.collection)(w,`user_files`),(0,h.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of n.docs)await(0,h.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up user file:`,e)}r(e=>e.filter(e=>e.id!==S)),C(null)}catch(e){console.error(`Error deleting record:`,e)}D(!1)}},ne=e=>{k(e.id),j(e.name),N(e.note||``)},re=async()=>{if(!O||!A.trim()){k(null);return}let e=n.find(e=>e.id===O);if(e&&e.name===A.trim()&&(e.note||``)===M.trim()){k(null);return}try{await(0,h.updateDoc)((0,h.doc)(w,L,O),{name:A.trim(),note:M.trim()}),r(e=>e.map(e=>e.id===O?{...e,name:A.trim(),note:M.trim()}:e))}catch(e){console.error(`Error updating record:`,e)}k(null)},V=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ie=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},H=WBn(e,L,F),ae=()=>{navigator.clipboard.writeText(H),_(!0),setTimeout(()=>_(!1),2e3)},oe=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),n=[t,t.charAt(0).toUpperCase()+t.slice(1),t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),t.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)];for(let e of n)if(f9[e])return f9[e];return s2||Qe})(),se=e.buttonStyle!==`secondary`,ce=e.buttonStorageStyle===`primary`;return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Private Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:i?`Loading…`:`${n.length} ${n.length===1?`item`:`items`}`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ae,title:g?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${g?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:g?(0,y.jsx)(be,{className:`w-4 h-4`}):(0,y.jsx)(ge,{className:`w-4 h-4`})}),e.storage!==!1&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`input`,{type:`file`,ref:P,onChange:te,className:`hidden`}),(0,y.jsxs)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>P.current?.click(),disabled:b,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${ce?`btn-primary`:`btn-secondary`}`,children:[b?(0,y.jsx)(W,{className:`w-4 h-4 animate-spin`}):(0,y.jsx)(oe,{className:`w-4 h-4`}),e.buttonStorageText&&(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>s(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,y.jsx)(Qe,{className:`w-4 h-4`}):(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,y.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[i&&(0,y.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,y.jsx)(W,{className:`w-8 h-8 text-accent animate-spin`})}),!i&&n.length===0&&(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,y.jsx)(Qe,{className:`w-6 h-6 text-accent/40`})}),(0,y.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!i&&n.length>0&&(0,y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,y.jsx)(K,{children:n.map((e,t)=>{let n=O===e.id;return(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:t*.03,duration:.25},className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[!n&&(0,y.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all`,children:[e.recordType===`file`&&e.downloadURL&&(0,y.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,y.jsx)(Ne,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>ne(e),className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,y.jsx)(Ze,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>C(e.id),className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,y.jsx)(rt,{className:`w-3.5 h-3.5`})})]}),(0,y.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,y.jsx)(`div`,{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`bg-blue-500/10 text-blue-500`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?(0,y.jsx)(Le,{className:`w-4 h-4`}):(0,y.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[n?(0,y.jsx)(`input`,{autoFocus:!0,value:A,onChange:e=>j(e.target.value),onBlur:re,onKeyDown:e=>{e.key===`Enter`&&re(),e.key===`Escape`&&k(null)},className:`text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),(0,y.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ie(e.createdAt)})]})]}),n?(0,y.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),onBlur:re,onKeyDown:e=>{e.key===`Escape`&&k(null)},placeholder:`Note (optional)`,rows:2,className:`text-[13px] text-foreground/70 font-medium bg-transparent border-b border-accent/20 outline-none resize-none w-full mb-1 placeholder:text-foreground/30`}):e.note&&(0,y.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note})]},e.id)})})})]}),(0,y.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,y.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,y.jsx)(Ve,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,y.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:L}),` · Files: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / Private`]})]})})]})]}),(0,y.jsx)(K,{children:o&&(0,y.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,y.jsx)(q.div,{onClick:()=>!f&&s(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,y.jsx)(q.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,y.jsxs)(`form`,{onSubmit:R,className:`p-5 flex flex-col gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>!f&&s(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,y.jsx)(ct,{className:`w-4 h-4`})})]}),(0,y.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:c,onChange:e=>l(e.target.value),placeholder:`Name *`,disabled:f,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Note (optional)`,disabled:f,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,y.jsx)(Z,{type:`submit`,isLoading:f,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:f?`Saving…`:`Save`})})]})})]})}),(0,y.jsx)(m9,{isOpen:!!S,onCancel:()=>C(null),onConfirm:z,title:`Delete Record`,message:`Are you sure you want to delete this record? This action cannot be undone.`,confirmText:`Delete`,isProcessing:E})]})}function pHn({config:e}){let{user:t}=B(),[n,r]=(0,m.useState)([]),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(``),[f,p]=(0,m.useState)(!1),[g,_]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(``),P=(0,m.useRef)(null),[F,I]=(0,m.useState)({}),ee=(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),L=`admin_${ee}_records`;(0,m.useEffect)(()=>{document.title=e.tabTitle||e.tabName||`Firebase OS`},[e.tabTitle,e.tabName]);let R=(0,m.useCallback)(async e=>{if(F[e])return F[e];try{let t=await(0,h.getDoc)((0,h.doc)(w,`user_profiles`,e));if(t.exists()){let n=t.data(),r={name:n.displayName||n.name||n.email?.split(`@`)[0]||`Admin`,email:n.email||``,avatar:n.avatar||``};return I(t=>({...t,[e]:r})),r}}catch{}let t={name:`Admin`,email:``,avatar:``};return I(n=>({...n,[e]:t})),t},[F]);(0,m.useEffect)(()=>{if(!t)return;a(!0);let e=(0,h.onSnapshot)((0,h.query)((0,h.collection)(w,L),(0,h.orderBy)(`createdAt`,`desc`)),e=>{let t=e.docs.map(e=>({id:e.id,...e.data()}));r(t),a(!1);let n=[...new Set(t.map(e=>e.uid).filter(Boolean))];for(let e of n)R(e)},e=>{console.error(`Error listening to admin records:`,e);let t=(0,h.onSnapshot)((0,h.collection)(w,L),e=>{let t=e.docs.map(e=>({id:e.id,...e.data()}));t.sort((e,t)=>(t.createdAt?.toMillis?.()||0)-(e.createdAt?.toMillis?.()||0)),r(t),a(!1);let n=[...new Set(t.map(e=>e.uid).filter(Boolean))];for(let e of n)R(e)});return()=>t()});return()=>e()},[t,L]);let te=async e=>{if(e.preventDefault(),!(!t||!c.trim())){p(!0);try{let e=await ie();await(0,h.addDoc)((0,h.collection)(w,L),{name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,h.serverTimestamp)()}),l(``),d(``),s(!1)}catch(e){console.error(`Error saving admin record:`,e)}p(!1)}},z=async e=>{let n=e.target.files?.[0];if(!(!n||!t)){x(!0);try{let e=(0,v.ref)(T,`admin_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,v.uploadBytes)(e,n,{customMetadata:{ownerId:t.uid}});let r=await(0,v.getDownloadURL)(e),i=await ie();await(0,h.addDoc)((0,h.collection)(w,`admin_files`),{fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,uid:t.uid,uploaderEmail:t.email||`admin`,sourceTab:ee,accessPrefix:`admin_`,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()}),await(0,h.addDoc)((0,h.collection)(w,L),{name:n.name,note:`${n.type||`File`} · ${H(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()})}catch(e){console.error(`Error uploading admin file:`,e)}x(!1),P.current&&(P.current.value=``)}},ne=async()=>{if(S){D(!0);try{let e=n.find(e=>e.id===S);if(await(0,h.deleteDoc)((0,h.doc)(w,L,S)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];t&&await(0,v.deleteObject)((0,v.ref)(T,`admin_files/${decodeURIComponent(t)}`)).catch(()=>{});let n=await(0,h.getDocs)((0,h.query)((0,h.collection)(w,`admin_files`),(0,h.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of n.docs)await(0,h.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up admin file:`,e)}C(null)}catch(e){console.error(`Error deleting admin record:`,e)}D(!1)}},re=e=>{k(e.id),j(e.name),N(e.note||``)},V=async()=>{if(!O||!A.trim()){k(null);return}let e=n.find(e=>e.id===O);if(e&&e.name===A.trim()&&(e.note||``)===M.trim()){k(null);return}try{await(0,h.updateDoc)((0,h.doc)(w,L,O),{name:A.trim(),note:M.trim()})}catch(e){console.error(`Error updating admin record:`,e)}k(null)},ie=async()=>{try{let e=await(0,h.getDoc)((0,h.doc)(w,`user_profiles`,t.uid));if(e.exists()){let n=e.data(),r={name:n.displayName||n.name||t.email?.split(`@`)[0]||`Admin`,email:n.email||t.email||``,avatar:n.avatar||t.photoURL||``};return I(e=>({...e,[t.uid]:r})),r}}catch{}return{name:t.displayName||t.email?.split(`@`)[0]||`Admin`,email:t.email||``,avatar:t.photoURL||``}},H=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ae=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},oe=UBn(e,L),se=()=>{navigator.clipboard.writeText(oe),_(!0),setTimeout(()=>_(!1),2e3)},ce=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),n=[t,t.charAt(0).toUpperCase()+t.slice(1),t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),t.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)];for(let e of n)if(f9[e])return f9[e];return s2||Qe})(),U=e.buttonStyle!==`secondary`,le=e.buttonStorageStyle===`primary`,ue=e=>e.uid===t?.uid,de=({record:e})=>{let t=F[e.uid],n=t?.name||e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,r=t?.email||e.creatorEmail||``,i=t?.avatar||e.creatorAvatar||``,a=n.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[i?(0,y.jsx)(`img`,{src:i,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,y.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:a}),(0,y.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:n}),r&&(0,y.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,r]})]})]})};return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:i?`Loading…`:`${n.length} ${n.length===1?`item`:`items`} · Shared between admins`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:se,title:g?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${g?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:g?(0,y.jsx)(be,{className:`w-4 h-4`}):(0,y.jsx)(ge,{className:`w-4 h-4`})}),e.storage!==!1&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`input`,{type:`file`,ref:P,onChange:z,className:`hidden`}),(0,y.jsxs)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>P.current?.click(),disabled:b,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${le?`btn-primary`:`btn-secondary`}`,children:[b?(0,y.jsx)(W,{className:`w-4 h-4 animate-spin`}):(0,y.jsx)(ce,{className:`w-4 h-4`}),e.buttonStorageText&&(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>s(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${U?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,y.jsx)(Qe,{className:`w-4 h-4`}):(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,y.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[i&&(0,y.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,y.jsx)(W,{className:`w-8 h-8 text-accent animate-spin`})}),!i&&n.length===0&&(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,y.jsx)(Qe,{className:`w-6 h-6 text-accent/40`})}),(0,y.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!i&&n.length>0&&(0,y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,y.jsx)(K,{children:n.map((e,t)=>{let n=O===e.id,r=ue(e);return(0,y.jsxs)(q.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[!n&&(0,y.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all`,children:[e.recordType===`file`&&e.downloadURL&&(0,y.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,y.jsx)(Ne,{className:`w-3.5 h-3.5`})}),r&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{onClick:()=>re(e),className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,y.jsx)(Ze,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>C(e.id),className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,y.jsx)(rt,{className:`w-3.5 h-3.5`})})]})]}),(0,y.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,y.jsx)(`div`,{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`bg-blue-500/10 text-blue-500`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?(0,y.jsx)(Le,{className:`w-4 h-4`}):(0,y.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[n?(0,y.jsx)(`input`,{autoFocus:!0,value:A,onChange:e=>j(e.target.value),onBlur:V,onKeyDown:e=>{e.key===`Enter`&&V(),e.key===`Escape`&&k(null)},className:`text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),(0,y.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ae(e.createdAt)})]})]}),n?(0,y.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),onBlur:V,onKeyDown:e=>{e.key===`Escape`&&k(null)},placeholder:`Note (optional)`,rows:2,className:`text-[13px] text-foreground/70 font-medium bg-transparent border-b border-accent/20 outline-none resize-none w-full mb-1 placeholder:text-foreground/30`}):e.note&&(0,y.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),(0,y.jsx)(de,{record:e})]},e.id)})})})]}),(0,y.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,y.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,y.jsx)(Ve,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,y.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:L}),` · Files: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,y.jsx)(K,{children:o&&(0,y.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,y.jsx)(q.div,{onClick:()=>!f&&s(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,y.jsx)(q.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,y.jsxs)(`form`,{onSubmit:te,className:`p-5 flex flex-col gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>!f&&s(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,y.jsx)(ct,{className:`w-4 h-4`})})]}),(0,y.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:c,onChange:e=>l(e.target.value),placeholder:`Name *`,disabled:f,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Note (optional)`,disabled:f,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,y.jsx)(Z,{type:`submit`,isLoading:f,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:f?`Saving…`:`Save`})})]})})]})}),(0,y.jsx)(m9,{isOpen:!!S,onCancel:()=>C(null),onConfirm:ne,title:`Delete Record`,message:`Are you sure you want to delete this record? This action cannot be undone.`,confirmText:`Delete`,isProcessing:E})]})}function mHn({config:e}){let{user:t}=B(),[n,r]=(0,m.useState)([]),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(``),[f,p]=(0,m.useState)(!1),[g,_]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(``),P=(0,m.useRef)(null),F=(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),I=`mem_${F}_records`;(0,m.useEffect)(()=>{document.title=e.tabTitle||e.tabName||`Firebase OS`},[e.tabTitle,e.tabName]),(0,m.useEffect)(()=>{if(!t)return;a(!0);let e=(0,h.onSnapshot)((0,h.query)((0,h.collection)(w,I),(0,h.orderBy)(`createdAt`,`desc`)),e=>{r(e.docs.map(e=>({id:e.id,...e.data()}))),a(!1)},e=>{console.error(`Error listening to shared records:`,e);let t=(0,h.onSnapshot)((0,h.collection)(w,I),e=>{let t=e.docs.map(e=>({id:e.id,...e.data()}));t.sort((e,t)=>(t.createdAt?.toMillis?.()||0)-(e.createdAt?.toMillis?.()||0)),r(t),a(!1)});return()=>t()});return()=>e()},[t,I]);let ee=()=>({name:t.displayName||t.email?.split(`@`)[0]||`Member`,email:t.email||``,avatar:t.photoURL||``}),L=async e=>{if(e.preventDefault(),!(!t||!c.trim())){p(!0);try{let e=ee();await(0,h.addDoc)((0,h.collection)(w,I),{name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,h.serverTimestamp)()}),l(``),d(``),s(!1)}catch(e){console.error(`Error saving shared record:`,e)}p(!1)}},R=async e=>{let n=e.target.files?.[0];if(!(!n||!t)){x(!0);try{let e=(0,v.ref)(T,`mem_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,v.uploadBytes)(e,n,{customMetadata:{ownerId:t.uid}});let r=await(0,v.getDownloadURL)(e),i=ee();await(0,h.addDoc)((0,h.collection)(w,`mem_files`),{fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,uid:t.uid,uploaderEmail:t.email||`member`,sourceTab:F,accessPrefix:`mem_`,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()}),await(0,h.addDoc)((0,h.collection)(w,I),{name:n.name,note:`${n.type||`File`} · ${re(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()})}catch(e){console.error(`Error uploading shared file:`,e)}x(!1),P.current&&(P.current.value=``)}},te=async()=>{if(S){D(!0);try{let e=n.find(e=>e.id===S);if(await(0,h.deleteDoc)((0,h.doc)(w,I,S)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];t&&await(0,v.deleteObject)((0,v.ref)(T,`mem_files/${decodeURIComponent(t)}`)).catch(()=>{});let n=await(0,h.getDocs)((0,h.query)((0,h.collection)(w,`mem_files`),(0,h.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of n.docs)await(0,h.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up shared file:`,e)}C(null)}catch(e){console.error(`Error deleting shared record:`,e)}D(!1)}},z=e=>{k(e.id),j(e.name),N(e.note||``)},ne=async()=>{if(!O||!A.trim()){k(null);return}let e=n.find(e=>e.id===O);if(e&&e.name===A.trim()&&(e.note||``)===M.trim()){k(null);return}try{await(0,h.updateDoc)((0,h.doc)(w,I,O),{name:A.trim(),note:M.trim()})}catch(e){console.error(`Error updating shared record:`,e)}k(null)},re=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},V=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ie=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),n=[t,t.charAt(0).toUpperCase()+t.slice(1),t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),t.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)];for(let e of n)if(f9[e])return f9[e];return s2||Qe})(),H=e.buttonStyle!==`secondary`,ae=e.buttonStorageStyle===`primary`,oe=e=>e.uid===t?.uid,se=HBn(e,I),ce=()=>{navigator.clipboard.writeText(se),_(!0),setTimeout(()=>_(!1),2e3)},U=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,y.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,y.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,y.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,y.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Shared Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:i?`Loading…`:`${n.length} ${n.length===1?`item`:`items`} · Shared`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ce,title:g?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${g?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:g?(0,y.jsx)(be,{className:`w-4 h-4`}):(0,y.jsx)(ge,{className:`w-4 h-4`})}),e.storage!==!1&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`input`,{type:`file`,ref:P,onChange:R,className:`hidden`}),(0,y.jsxs)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>P.current?.click(),disabled:b,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${ae?`btn-primary`:`btn-secondary`}`,children:[b?(0,y.jsx)(W,{className:`w-4 h-4 animate-spin`}):(0,y.jsx)(ie,{className:`w-4 h-4`}),e.buttonStorageText&&(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>s(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${H?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,y.jsx)(Qe,{className:`w-4 h-4`}):(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,y.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[i&&(0,y.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,y.jsx)(W,{className:`w-8 h-8 text-accent animate-spin`})}),!i&&n.length===0&&(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,y.jsx)(Qe,{className:`w-6 h-6 text-accent/40`})}),(0,y.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!i&&n.length>0&&(0,y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,y.jsx)(K,{children:n.map(e=>{let t=O===e.id,n=oe(e);return(0,y.jsxs)(q.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${t?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[!t&&(0,y.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all`,children:[e.recordType===`file`&&e.downloadURL&&(0,y.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,y.jsx)(Ne,{className:`w-3.5 h-3.5`})}),n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{onClick:()=>z(e),className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,y.jsx)(Ze,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>C(e.id),className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,y.jsx)(rt,{className:`w-3.5 h-3.5`})})]})]}),(0,y.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,y.jsx)(`div`,{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`bg-blue-500/10 text-blue-500`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?(0,y.jsx)(Le,{className:`w-4 h-4`}):(0,y.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[t?(0,y.jsx)(`input`,{autoFocus:!0,value:A,onChange:e=>j(e.target.value),onBlur:ne,onKeyDown:e=>{e.key===`Enter`&&ne(),e.key===`Escape`&&k(null)},className:`text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),(0,y.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:V(e.createdAt)})]})]}),t?(0,y.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),onBlur:ne,onKeyDown:e=>{e.key===`Escape`&&k(null)},placeholder:`Note (optional)`,rows:2,className:`text-[13px] text-foreground/70 font-medium bg-transparent border-b border-accent/20 outline-none resize-none w-full mb-1 placeholder:text-foreground/30`}):e.note&&(0,y.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),(0,y.jsx)(U,{record:e})]},e.id)})})})]}),(0,y.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,y.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,y.jsx)(Ve,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,y.jsxs)(`span`,{children:[`Shared between all members · Edit and delete available on your own items only · Records: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:I}),` · Files: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Shared`]})]})})]})]}),(0,y.jsx)(K,{children:o&&(0,y.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,y.jsx)(q.div,{onClick:()=>!f&&s(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,y.jsx)(q.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,y.jsxs)(`form`,{onSubmit:L,className:`p-5 flex flex-col gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>!f&&s(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,y.jsx)(ct,{className:`w-4 h-4`})})]}),(0,y.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:c,onChange:e=>l(e.target.value),placeholder:`Name *`,disabled:f,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Note (optional)`,disabled:f,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,y.jsx)(Z,{type:`submit`,isLoading:f,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:f?`Saving…`:`Save`})})]})})]})}),(0,y.jsx)(m9,{isOpen:!!S,onCancel:()=>C(null),onConfirm:te,title:`Delete Record`,message:`Are you sure you want to delete this record? This action cannot be undone.`,confirmText:`Delete`,isProcessing:E})]})}function hHn(){let e=(0,b.useLocation)(),{user:t}=B(),n=R(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(!0);(0,m.useEffect)(()=>{(async()=>{o(!0);try{let[t,n]=await Promise.all([(0,h.getDocs)((0,h.collection)(w,`sys_pages`)),(0,h.getDocs)((0,h.collection)(w,`sys_tabs`))]),r=null,a=null,o=(t,n)=>{t.forEach(t=>{let i=t.data(),o=i.route;o&&!o.startsWith(`/`)&&(o=`/`+o);let s=`/`+t.id===e.pathname;(o===e.pathname||s)&&(r={...i,isPrivate:n,isAdmin:i.pageType===`admin`,isShared:i.pageType===`shared`},a=t.id)})};if(o(t,!1),r||o(n,!0),r||(e.pathname===`/contact`?(r={route:`/contact`,template:`popup_form`,form:`contact`},a=`contact`):e.pathname===`/support`&&(r={route:`/support`,template:`popup_form`,form:`support`},a=`support`)),r){if((a===`contact`||a===`support`)&&!r.form&&(r.form=a),r.pageId=a,r.form){let e=await(0,h.getDoc)((0,h.doc)(w,`sys_forms`,r.form));if(e.exists())r.formConfigOverride={...e.data(),id:e.id};else if(r.form===`contact`){let{contactFormConfig:e}=await Promise.resolve().then(()=>require(`./contactForm.config-ki9OzidM.cjs`));r.formConfigOverride=e}else if(r.form===`support`){let{supportFormConfig:e}=await Promise.resolve().then(()=>require(`./supportForm.config-BwZqJ5CZ.cjs`));r.formConfigOverride=e}}let e=r.pageName||r.tabName||r.title;e&&(document.title=e),i(r)}else i(`not-found`)}catch{i(`not-found`)}finally{o(!1)}})()},[e.pathname]);let[s,c]=(0,m.useState)(!1);if((0,m.useEffect)(()=>{let e;return a?e=setTimeout(()=>c(!0),150):c(!1),()=>clearTimeout(e)},[a]),a)return s?t?(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsxs)(`div`,{className:`mb-6`,children:[(0,y.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,y.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsx)(`div`,{className:`flex-1 glass-panel border border-[var(--panel-border)] rounded-3xl flex items-center justify-center min-h-[400px] bg-background shadow-2xl`,children:(0,y.jsx)(W,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,y.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[60vh] z-10`,children:(0,y.jsx)(W,{className:`w-6 h-6 animate-spin text-accent`})}):null;if(r===`not-found`)return(0,y.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 bg-red-500/10 text-red-500 rounded-full flex items-center justify-center mb-6`,children:(0,y.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-8 h-8`,children:[(0,y.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,y.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,y.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,y.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,y.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`})]})});if((r.pageId===`support`||r.isPrivate)&&!t)return(0,y.jsx)(b.Navigate,{to:`/login`,state:{from:e}});let l=r.pageName?.toLowerCase().replace(/\s+/g,`_`)||r.pageId||`custom_page`,u=`pub_${l}`;if(r.template===`none`)return r.isAdmin?(0,y.jsx)(pHn,{config:r}):r.isShared?(0,y.jsx)(mHn,{config:r}):r.isPrivate?(0,y.jsx)(fHn,{config:r}):(0,y.jsx)(dHn,{config:r});if(r.template===`board`){let e=r.isAdmin?`admin_${r.pageId||l}`:r.isShared?`mem_${r.pageId||l}`:r.isPrivate?`user_${r.pageId||l}`:u;return(0,y.jsx)(n.components?.TemplateBoard||GBn,{title:r.tabTitle||r.tabName||r.title||r.pageName||`Board`,subtitle:r.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:r})}if(r.template===`table`){let e=r.isAdmin?`admin_${r.pageId||l}`:r.isShared?`mem_${r.pageId||l}`:r.isPrivate?`user_${r.pageId||l}`:u;return(0,y.jsx)(n.components?.TemplateTable||XVn,{title:r.tabTitle||r.tabName||r.title||r.pageName||`Table`,subtitle:r.route,tableCollection:`${e}_table`,config:r})}if(r.template===`calendar`){let e=r.isAdmin?`admin_${r.pageId||l}`:r.isShared?`mem_${r.pageId||l}`:r.isPrivate?`user_${r.pageId||l}`:u;return(0,y.jsx)(n.components?.TemplateCalendar||ZVn,{title:r.tabTitle||r.tabName||r.title||r.pageName||`Calendar`,subtitle:r.route,eventsCollection:`${e}_events`,defaultTimeFormat:r.defaultTimeFormat||r.defaulttimeformat||`12h`,config:r})}return r.template===`inline_form`?(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,y.jsx)(wo,{isInline:!0,formId:r.form,formConfig:r.formConfigOverride})}):(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,y.jsx)(wo,{formId:r.form,formConfig:r.formConfigOverride,onClose:()=>window.history.back()})})}var gHn=`rules_version = '2';
|
|
506
|
+
};`;navigator.clipboard.writeText(a),l(!0),setTimeout(()=>l(!1),2e3)}};return(0,m.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`a`&&document.activeElement===document.body&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&e.key===`c`&&!window.getSelection()?.toString()&&t&&_()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Theme`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/theme`]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col min-h-[600px]`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Theme Config`}),(0,y.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Changes here immediately format natively. Save to update your Live Preview panel entirely.`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:f,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-xl flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:a?(0,y.jsx)(W,{className:`w-4 h-4 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(Z,{variant:`secondary`,onClick:_,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors`,title:`Copy Config (Ctrl+C)`,children:c?(0,y.jsx)(be,{className:`w-4 h-4 text-emerald-500`}):(0,y.jsx)(je,{className:`w-4 h-4 text-foreground/60 hover:text-foreground transition-colors`})})]})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 w-full relative z-10 items-start`,children:[a&&(0,y.jsx)(`div`,{className:`absolute inset-0 bg-background/60 backdrop-blur-[2px] z-50 flex items-center justify-center rounded-3xl pointer-events-none transition-all duration-300`,children:(0,y.jsx)(W,{className:`w-8 h-8 animate-spin text-accent`})}),(0,y.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-8 shadow-inner overflow-hidden relative bg-background`,children:[(0,y.jsx)(`h3`,{className:`text-lg font-extrabold text-foreground tracking-tight mb-4 flex items-center gap-3`,children:`Branding & Colours`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-4 pt-2 mb-6 border-b border-[var(--panel-border)]/50 shrink-0`,children:[(0,y.jsx)(`div`,{className:`text-[12px] font-bold text-foreground/40 shrink-0 uppercase tracking-widest pl-1 mr-2`,children:`Presets`}),$Vn.map(e=>{let n=t?.colors?.dark?.accent===e.dark.accent&&t?.colors?.dark?.buttonGradient?.[0]===e.dark.gradient[0],r=e.name===`Black & White`;return(0,y.jsx)(`button`,{onClick:()=>g(e),className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative group overflow-visible ${n?`ring-[3px] ring-foreground ring-offset-2 ring-offset-[var(--background)] scale-110 z-10`:`opacity-80 hover:opacity-100 hover:ring-2 hover:ring-foreground/30 hover:ring-offset-2 hover:ring-offset-[var(--background)] hover:scale-105`}`,title:e.name,children:(0,y.jsx)(`div`,{className:`absolute inset-0 rounded-full`,style:r?{backgroundColor:`#ffffff`,border:`3px solid #000000`,boxShadow:`inset 0 0 0 1px rgba(0,0,0,0.1)`}:{backgroundImage:`linear-gradient(135deg, ${e.preview[0]}, ${e.preview[1]})`}})},e.name)})]}),(0,y.jsx)(`div`,{className:`w-full relative min-h-[100px]`,children:t?(0,y.jsxs)(`div`,{className:`flex flex-col pl-2`,children:[(0,y.jsxs)(`span`,{className:`text-yellow-500 font-mono text-[13px] mb-2`,children:[`export const themeConfig = `,`{`]}),(0,y.jsx)(q9,{value:t,keysToRender:[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`,`cornerRounding`,`cornerRadii`,`fontFamily`],onChange:e=>n(e),isLast:!1,isGlobalSaving:r}),(0,y.jsx)(`div`,{className:`mt-4`,children:(0,y.jsx)(q9,{objectKey:`colors`,value:t.colors,onChange:e=>n({...t,colors:e}),isLast:!1,isGlobalSaving:r})})]}):(0,y.jsx)(`div`,{className:`flex items-center justify-center w-full h-full text-foreground/40 font-mono text-[13px] animate-pulse py-10`,children:`Loading Data Tree...`})})]})]})]})]})]})}var rHn={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},iHn={tabName:`New Private Page`,iconName:``,route:`/new-private-page`,template:`none`,form:`support`,showPrompt:!0,tabTitle:`Private Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},aHn={tabName:`Admin Tab`,iconName:``,route:`/admin-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Admin Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},oHn={tabName:`Shared Tab`,iconName:``,route:`/shared-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Shared Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},sHn=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],cHn=({enabled:e,onChange:t,disabled:n,className:r=``})=>(0,y.jsx)(`button`,{disabled:n,onClick:()=>t(!e),title:e?`Page Active`:`Page Hidden`,className:`p-1.5 transition-colors rounded-lg flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity ${r} ${e?`text-accent hover:bg-accent/10`:`text-foreground/40 hover:bg-foreground/5`} ${n?`!opacity-50 cursor-not-allowed`:`cursor-pointer`}`,children:e?(0,y.jsx)(Ie,{className:`w-4 h-4`}):(0,y.jsx)(Fe,{className:`w-4 h-4`})});function lHn(){let{userRole:e}=B(),t=(0,b.useLocation)(),[n,r]=(0,m.useState)(sHn),[i,a]=(0,m.useState)(null),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)({}),[u,d]=(0,m.useState)({}),[f,p]=(0,m.useState)({}),[g,_]=(0,m.useState)(null),[v,x]=(0,m.useState)(!1),S=(0,m.useRef)(null);(0,m.useEffect)(()=>{function e(e){S.current&&!S.current.contains(e.target)&&s(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[C,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(new Set),[M,N]=(0,m.useState)(new Set),[P,F]=(0,m.useState)([]),[I,ee]=(0,m.useState)([]),L=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden});(0,m.useEffect)(()=>{let e=(0,h.onSnapshot)((0,h.doc)(w,`sys_configs`,`page_order`),e=>{let t=L(e.exists()&&e.data().order||[]);F(t),j(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),t=(0,h.onSnapshot)((0,h.doc)(w,`sys_configs`,`tab_order`),e=>{let t=L(e.exists()&&e.data().order||[]);ee(t),N(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),t()}},[]),(0,m.useEffect)(()=>{let e=t.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!i&&n.some(t=>t.id===e)&&a(e)},[t.pathname,n]),(0,m.useEffect)(()=>{let e=(e,t)=>{if(!t)return e;let n=Object.fromEntries(Object.entries(t).filter(([e,t])=>t!=null&&t!==``));return{...e,...n}},t=(0,h.onSnapshot)((0,h.doc)(w,`sys_pages`,`home`),t=>{T(t.exists()?e(Ao,t.data()):Ao)});return()=>{t()}},[]),(0,m.useEffect)(()=>{(async()=>{try{let[e,t]=await Promise.all([(0,h.getDocs)((0,h.collection)(w,`sys_pages`)),(0,h.getDocs)((0,h.collection)(w,`sys_tabs`))]),n=[`home`,`contact`,`support`,`theme`,`page_order`,`tab_order`],i=[],a={};e.forEach(e=>{if(!n.includes(e.id)){let t=e.data();i.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),t.forEach(e=>{if(!n.includes(e.id)){let t=e.data(),n=t.pageType||`private`;i.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),i.length>0&&(r(e=>{let t=e.filter(e=>e.isSystem||e.id.startsWith(`draft_`)),n=i.filter(e=>!t.some(t=>t.id===e.id));return[...t,...n]}),l(e=>({...e,...a})))}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[R,te]=(0,m.useState)([`contact`]),[z,ne]=(0,m.useState)([`support`]);(0,m.useEffect)(()=>{(0,h.getDocs)((0,h.collection)(w,`sys_forms`)).then(e=>{let t=[],n=[];e.forEach(e=>{e.data().formType===`private`?n.push(e.id):t.push(e.id)}),t.length>0&&te(t),n.length>0&&ne(n)}).catch(console.error)},[]);let[re,V]=(0,m.useState)(null),ie=(e,t)=>{let n;n=e===`home`?`export const defaultHomeConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),V(e),setTimeout(()=>V(null),2e3)},H=async(e,t)=>{t.route&&!t.route.startsWith(`/`)&&(t.route=`/`+t.route);let o=n.find(t=>t.id===e)?.type,s=o===`public`?`sys_pages`:`sys_tabs`;o&&o!==`public`&&(t.pageType=o);let c=[`home`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?D(!0):d(t=>({...t,[e]:!0,[c]:!0}));try{if(c!==e&&c.trim()!==``&&c!==`draft`){try{let{deleteDoc:t}=await import(`firebase/firestore`);await t((0,h.doc)(w,s,e))}catch{}await(0,h.setDoc)((0,h.doc)(w,s,c),t),r(n=>n.map(n=>n.id===e?{...n,id:c,_uiKey:n._uiKey||e,path:t.route,title:t.pageName||t.tabName||t.title||n.title}:n)),l(n=>{let r={...n};return r[c]=t,delete r[e],r}),i===e&&(a(c),window.history.replaceState(null,``,`/pages/${c}`));let n=o===`public`,u=n?`page_order`:`tab_order`,d=n?P:I;if(!d.some(e=>e.id===c)){let t=[...d.filter(t=>t.id!==e),{id:c,hidden:!1}];try{await(0,h.setDoc)((0,h.doc)(w,`sys_configs`,u),{order:t})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,h.setDoc)((0,h.doc)(w,s,e),t),e===`home`?T(t):(l(n=>({...n,[e]:t})),r(n=>n.map(n=>n.id===e?{...n,path:t.route||n.path,title:t.pageName||t.tabName||t.title||n.title}:n)))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{e===`home`?D(!1):d(t=>({...t,[e]:!1,[c]:!1}))},500)}},ae=async e=>{e.stopPropagation(),k(!0),await H(`home`,Ao),setTimeout(()=>k(!1),500)},oe=async(e,t,n)=>{e.stopPropagation(),p(e=>({...e,[t]:!0})),await H(t,n),setTimeout(()=>p(e=>({...e,[t]:!1})),500)},se=e=>{let t=`draft_`+Math.floor(Math.random()*1e4);r([...n,{id:t,title:`New Tab`,path:`/draft`,type:e,isSystem:!1,enabled:!0}]);let i={};e===`public`?i={...rHn}:e===`private`?i={...iHn}:e===`admin`?i={...aHn}:e===`shared`&&(i={...oHn}),l(e=>({...e,[t]:i})),a(t),s(!1),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)};if(e!==`admin`)return(0,y.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,y.jsx)(tt,{className:`w-12 h-12 text-red-500 mb-4`}),(0,y.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,y.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let ce=async(e,t,i)=>{let a=i===`public`,o=a?`page_order`:`tab_order`,s=a?P:I,c=(a?A:M).has(e);r(n.map(t=>t.id===e?{...t,enabled:c}:t));let l=[...s],u=l.findIndex(t=>t.id===e);u===-1?l.push({id:e,hidden:!0}):l[u]={...l[u],hidden:!c},await(0,h.setDoc)((0,h.doc)(w,`sys_configs`,o),{order:l})},U=(e,t)=>{t||_(e)},le=async()=>{if(g){x(!0);try{let{deleteDoc:e,collection:t,getDocs:o,doc:s}=await import(`firebase/firestore`),c=n.find(e=>e.id===g),l=c?.type===`public`?`sys_pages`:`sys_tabs`;if(await e(s(w,l,g)),l===`sys_tabs`&&c){let n=c.id;try{let r=[`admin_${n}_records`,`mem_${n}_records`,`user_${n}_records`];for(let n of r){let r=(await o(t(w,n))).docs.map(t=>e(t.ref));await Promise.all(r)}}catch(e){console.error(`Error cleaning up tab records:`,e)}}let u=l===`sys_pages`?`page_order`:`tab_order`,d=l===`sys_pages`?P:I,{setDoc:f}=await import(`firebase/firestore`),p=d.filter(e=>e.id!==g);await f(s(w,`sys_configs`,u),{order:p}),r(e=>e.filter(e=>e.id!==g)),i===g&&a(null)}catch(e){console.error(`Error deleting page:`,e)}x(!1),_(null)}},ue=e=>{let t=e.id+`_`+Math.floor(Math.random()*1e3),n={...e,id:t,title:`${e.title} (Copy)`,path:`${e.path}_copy`,isSystem:!1,enabled:!0};r(e=>[...e,n]);let i=c[e.id];!i&&e.id===`home`&&(i=C);let o={...i||{},route:n.path,pageName:n.title};n.type!==`public`&&(o.tabName=n.title,o.pageType=n.type),l(e=>({...e,[t]:o})),a(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},de=[{id:`public`,title:`Public Pages`,icon:ze,color:`bg-amber-500`,description:`Creates external menu items. Invisible to signed-in dashboard users.`,filter:e=>e.type===`public`},{id:`private`,title:`Private Pages`,icon:Ke,color:`bg-emerald-500`,description:`Internal dashboard tabs for regular users.`,filter:e=>e.type===`private`},{id:`shared`,title:`Shared Pages`,icon:Ie,color:`bg-blue-500`,description:`Dashboard tabs visible to all members, editors, and admins.`,filter:e=>e.type===`shared`},{id:`admin`,title:`Admin Pages`,icon:tt,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[fe,pe]=(0,m.useState)(!1),[me,he]=(0,m.useState)(!1);return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Pages`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`,i?`/${i}`:``]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Architecture`}),(0,y.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Manage the structure of your application tabs and public pages.`})]}),(0,y.jsxs)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:()=>pe(!0),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Reset Defaults`,children:(0,y.jsx)($e,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,y.jsxs)(`div`,{className:`relative`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:()=>s(!o),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Add New Page`,children:(0,y.jsx)(Qe,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,y.jsx)(K,{children:o&&(0,y.jsx)(q.div,{ref:S,initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},className:`absolute top-full mt-2 right-0 w-48 glass-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-xl z-50 flex flex-col gap-1`,children:[`public`,`private`,`shared`,`admin`].map(e=>(0,y.jsxs)(`button`,{onClick:()=>{se(e),s(!1)},className:`text-left px-3 py-2 text-[13px] font-bold uppercase tracking-wider text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:[e,` Page`]},e))})})]})]})]}),(0,y.jsxs)(`div`,{className:`px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-0 gap-10 overflow-y-auto mt-2 relative min-h-[400px]`,children:[(0,y.jsx)(K,{children:me&&(0,y.jsx)(q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-[2px] rounded-3xl`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-6 glass-panel rounded-2xl shadow-xl`,children:[(0,y.jsx)(W,{className:`w-8 h-8 md:w-10 md:h-10 animate-spin text-accent mb-4`}),(0,y.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:`Synchronizing Architecture...`})]})})}),de.map((e,t)=>{let r=n.filter(e.filter),o=e.id===`public`?P:I,s=r.sort((e,t)=>{let n=o.findIndex(t=>t.id===e.id),r=o.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),l=e.icon,d=e=>e.type===`public`?A.has(e.id):M.has(e.id),p=s.filter(e=>!d(e)),m=s.filter(e=>d(e)),h=e=>{if(!e)return[];let t=[`route`,`pageName`,`template`];return e.template===`none`?(t.push(`pageTitle`,`copyPrompt`),t.push(`showButton`),e.showButton!==!1&&(t.push(`buttonText`,`action`),e.action===`form`?t.push(`form`):e.action===`redirect`&&t.push(`redirectUrl`))):(e.template===`popup_form`||e.template===`inline_form`)&&(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)),t},g=e=>{if(!e)return[];let t=[`tabName`,`iconName`,`route`,`template`];return e.template===`popup_form`||e.template===`inline_form`?(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)):e.template===`none`?(t.push(`showPrompt`,`tabTitle`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonStyle`,`buttonText`,`buttonAction`),t.push(`storage`),e.storage!==!1&&t.push(`buttonStorageIcon`,`buttonStorageText`,`buttonStorageStyle`,`buttonStorageAction`)):e.template===`calendar`?(t.push(`tabTitle`,`showPrompt`),t.push(`defaultView`,`defaultTimeFormat`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showViewsButton`),e.showViewsButton!==!1&&t.push(`viewsButtonStyle`)):e.template===`table`?(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showExportButton`),e.showExportButton!==!1&&t.push(`exportButtonIcon`)):e.template===`board`&&(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`keyName`,`valueName`)),t},_=(t,n,r)=>{let o=t.id===`home`,s=i===t.id,l=o||!t.isSystem;return(0,y.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(l){let e=s?null:t.id;a(e),window.history.replaceState(null,``,e?`/pages/${e}`:`/pages`)}},className:`group flex flex-col py-4 px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${l?`cursor-pointer hover:border-accent/40`:``} ${r?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-center justify-between w-full gap-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-1 w-full flex-1`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:t.title}),o&&E&&(0,y.jsx)(W,{className:`w-3 h-3 animate-spin text-accent ml-2`})]}),(0,y.jsxs)(`div`,{className:`text-[11px] font-medium font-mono px-2 py-0.5 rounded w-fit ml-6 border ${r?`text-foreground/50 border-foreground/10 bg-foreground/5`:`text-accent/70 bg-accent/5 border-accent/10`}`,children:[window.location.host,t.path]})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-4 shrink-0`,children:[!t.isSystem||[`contact`,`support`,`templates`].includes(t.id)?(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ue(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Duplicate Page`,children:(0,y.jsx)(je,{className:`w-4 h-4`})}):(0,y.jsx)(`div`,{className:`w-[28px] shrink-0`}),(0,y.jsx)(`div`,{className:`flex items-center justify-end w-8 shrink-0`,children:t.id===`home`?(0,y.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,y.jsx)(cHn,{enabled:!d(t),onChange:()=>ce(t.id,t.isSystem,t.type)})}),t.isSystem?(0,y.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),U(t.id,t.isSystem)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Delete Page`,children:(0,y.jsx)(rt,{className:`w-4 h-4`})}),l?(0,y.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${s?`rotate-180`:``}`,children:(0,y.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,y.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}):(0,y.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,y.jsxs)(K,{children:[s&&o&&C&&(0,y.jsx)(q.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,y.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,y.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,y.jsx)(`button`,{onClick:ae,className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:O?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ie(`home`,C)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===`home`?(0,y.jsx)(Ee,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,y.jsx)(je,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,y.jsx)(q9,{value:C,keysToRender:[`hero`],onChange:e=>H(`home`,e),isLast:!0,isGlobalSaving:E,customEnums:{form:R},customExplanations:{form:`User can click to switch to any public form we have in the forms tab. Private forms are not an option here. Add a new form in forms with a link that actually works.`}})]})}),s&&!t.isSystem&&c[t.id]&&(0,y.jsx)(q.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,y.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,y.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,y.jsx)(`button`,{onClick:e=>oe(e,t.id,t.type===`admin`?aHn:t.type===`shared`?oHn:t.type===`public`?rHn:iHn),className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:f[t.id]?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ie(t.id,c[t.id])},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===t.id?(0,y.jsx)(Ee,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,y.jsx)(je,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,y.jsx)(q9,{value:c[t.id],keysToRender:t.type===`public`?h(c[t.id]):g(c[t.id]),onChange:e=>H(t.id,e),isLast:!0,isGlobalSaving:u[t.id],customEnums:{form:t.type===`public`?R:z,template:t.type===`public`?[`none`,`popup_form`,`inline_form`]:t.type===`admin`||t.type===`shared`?[`none`,`calendar`,`table`,`board`]:[`none`,`calendar`,`table`,`board`,`popup_form`,`inline_form`],action:[`save_Info`,`form`],defaultTimeFormat:[`12h`,`24h`],defaultView:[`calendar`,`board`],buttonStyle:[`primary`,`secondary`],buttonAction:[`save_info`],viewsButtonStyle:[`primary`,`secondary`],buttonStorageStyle:[`primary`,`secondary`],buttonStorageAction:[`upload_file`]},customExplanations:{tabName:`Defines the tab label in the dashboard navigation.`,iconName:`Visit https://iconoir.com/, find an icon, and paste its exact name (e.g. 'learning', 'server', 'cloud-upload').`,route:`The URL path for this tab (e.g. '/my-tab'). Must start with /.`,template:`Page layout type. 'none' gives you a freeform dashboard with add/upload buttons.`,form:`Which form to display. Only applies to popup_form or inline_form templates. Go to /forms to edit forms.`,tabTitle:`The heading that appears at the top of the page content area.`,showPrompt:`Shows the developer AI prompt copy button in the header.`,showButton:`Toggles the + add record button in the header.`,buttonStyle:`Visual style of the add button: 'primary' (accent) or 'secondary' (subtle).`,buttonText:`Label on the add button. Use '+' for a minimal icon-only button.`,buttonAction:`'save_info' saves a name + note record to the tab's Firestore collection.`,storage:`Enables the file upload button for this tab.`,buttonStorageIcon:`Icon name from https://iconoir.com/ for the upload button (e.g. 'upload', 'cloud-upload').`,buttonStorageText:`Label next to the upload icon. Leave empty for icon-only.`,buttonStorageStyle:`'primary' or 'secondary' visual style for the upload button.`,buttonStorageAction:t.type===`admin`?`'upload_file' uploads to admin_files/ in Storage and mirrors metadata to admin_files collection (Drive > Admin).`:t.type===`shared`?`'upload_file' uploads to mem_files/ in Storage and mirrors metadata to mem_files collection (Drive > Shared).`:`'upload_file' uploads to user_files/ in Storage and mirrors metadata to user_files collection (Drive > Private).`,defaultView:`Starting view: 'calendar' (month grid) or 'board' (event list). Users can switch between them.`,defaultTimeFormat:`12h or 24h time format. Users can toggle this in the toolbar.`,showViewsButton:`Show the calendar/board view toggle button in the toolbar.`,viewsButtonStyle:`'primary' or 'secondary' visual style for the view toggle.`,showExportButton:`Show the CSV export/download button in the table toolbar.`,exportButtonIcon:`Icon name from https://iconoir.com/ for the export button (e.g. 'download-square', 'import').`,keyName:`Label for the key/title field in board items (e.g. 'Task', 'Name').`,valueName:`Label for the value/description field in board items (e.g. 'Notes', 'Details').`},hideInnerLoader:!0})]})})]})]},`${e.id}-${t._uiKey||t.id}`)};return(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,y.jsx)(`div`,{className:`w-8 h-8 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center -ml-1 shadow-sm`,children:(0,y.jsx)(l,{className:`w-4 h-4 text-accent`})}),(0,y.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,y.jsx)(`p`,{className:`text-[13px] leading-relaxed text-foreground/50 font-medium max-w-3xl mb-4 ml-[2px]`,children:e.description}),s.length===0?(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 opacity-40 glass-panel rounded-2xl border border-[var(--panel-border)]/50 border-dashed`,children:[(0,y.jsx)(Ue,{className:`w-5 h-5 mb-2`}),(0,y.jsx)(`p`,{className:`text-[12px] font-bold`,children:`This section is currently empty.`})]}):(0,y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[p.map(e=>_(e,s.findIndex(t=>t.id===e.id),!1)),m.length>0&&(0,y.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,y.jsxs)(`summary`,{className:`text-[11px] font-bold uppercase tracking-wider text-foreground/40 cursor-pointer list-none flex items-center gap-2 select-none hover:text-foreground/70 transition-colors w-fit pb-1 ml-1 outline-none`,children:[(0,y.jsx)(xe,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,m.length,`)`]}),(0,y.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:m.map(e=>_(e,s.findIndex(t=>t.id===e.id),!0))})]})]}),t<de.length-1&&(0,y.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})]})]})]}),(0,y.jsx)(m9,{isOpen:fe,onCancel:()=>pe(!1),onConfirm:async()=>{he(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,h.doc)(w,`sys_pages`,`home`))]),T(Ao)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{he(!1),pe(!1)},1e3)},title:`Reset System Pages`,message:`Are you sure you want to reset all system page configurations? Custom pages and their order will remain intact.`,confirmText:`Reset`,isProcessing:me}),(0,y.jsx)(m9,{isOpen:!!g,onCancel:()=>_(null),onConfirm:le,title:`Delete Page`,message:`Are you sure you want to delete this page? This action cannot be undone and will remove all associated configurations.`,confirmText:`Remove Page`,isProcessing:v})]})}var J9={contact:f.t,support:p.t};function uHn(){let{userRole:e}=B(),t=(0,b.useNavigate)();(0,b.useLocation)();let[n,r]=(0,m.useState)({}),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)({}),[c,l]=(0,m.useState)(null),[u,d]=(0,m.useState)({}),[f,p]=(0,m.useState)(null),[g,_]=(0,m.useState)(!1),[v,x]=(0,m.useState)(null),S=(e,t)=>{let n=JSON.stringify(t,null,2);navigator.clipboard.writeText(n),x(e),setTimeout(()=>x(null),2e3)};(0,m.useEffect)(()=>{C()},[]);let C=async()=>{try{let e=await(0,h.getDocs)((0,h.collection)(w,`sys_forms`)),t={};e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let n=e.data();n._uiKey||=Math.random().toString(36).substring(7),t[e.id]=n}});try{await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,`pubForm`)),await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,`userForm`))}catch{}for(let[e,n]of Object.entries(J9))if(!t[e]){await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),n);let r={...n};r._uiKey=Math.random().toString(36).substring(7),t[e]=r}else if(!t[e].fields||t[e].fields.length===0){let n=J9[e];t[e].fields=n.fields||[],await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),t[e])}let n=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];n&&t[n]&&d({[n]:!0}),r(t)}catch(e){console.error(`Failed to load forms:`,e)}finally{a(!1)}},T=async(e,t)=>{let i={...t};n[e]?._uiKey&&(i._uiKey=n[e]._uiKey),e===`contact`?(i.systemName=`contact`,i.formType=`public`,i.submitPage=`submissions`):e===`support`&&(i.systemName=`support`,i.formType=`private`,i.submitPage=`requests`);let a=i.systemName||e;if(a!==e&&a.trim()!==``){r(t=>{let n={};for(let r of Object.keys(t))r===e?n[a]=i:n[r]=t[r];return n}),u[e]&&d(t=>{let n={};for(let r of Object.keys(t))r===e?n[a]=t[r]:n[r]=t[r];return n}),s(e=>({...e,[a]:!0}));try{await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,a),i),await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,e))}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{s(e=>({...e,[a]:!1}))},500)}}else{r(t=>({...t,[e]:i})),s(t=>({...t,[e]:!0}));try{await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),i)}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{s(t=>({...t,[e]:!1}))},500)}}},[E,D]=(0,m.useState)(!1),O=async()=>{if(E)return;D(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,n={title:`New Custom Form`,systemName:e,formType:`public`,submitPage:`submissions`,redirectTo:``,submitText:`Submit`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{s(t=>({...t,[e]:!0})),await(0,h.setDoc)((0,h.doc)(w,`sys_forms`,e),n),r(t=>({[e]:n,...t})),d(t=>({[e]:!0,...t})),t(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{s(t=>({...t,[e]:!1})),D(!1)}},k=async e=>{if(!(e===`contact`||e===`support`)){_(!0);try{await(0,h.deleteDoc)((0,h.doc)(w,`sys_forms`,e)),r(t=>{let n={...t};return delete n[e],n}),t(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{_(!1),p(null)}}};if(e!==`admin`)return(0,y.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,y.jsx)(at,{className:`w-12 h-12 text-red-500 mb-4`}),(0,y.jsx)(`h2`,{className:`text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-br from-red-400 to-red-600`,children:`Access Restricted`}),(0,y.jsx)(`p`,{className:`text-foreground/60 max-w-sm text-center mt-2 font-medium leading-relaxed`,children:`This area is exclusively for system administrators.`})]})});let A=e=>{d(t=>{let n={...t,[e]:!t[e]};if(n[e])window.history.replaceState(null,``,`/forms/${e}`);else{let e=Object.keys(n).filter(e=>n[e]);e.length>0?window.history.replaceState(null,``,`/forms/${e[0]}`):window.history.replaceState(null,``,`/forms`)}return n})},j=Object.keys(u).find(e=>u[e]);return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Forms`}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,j?`/${j}`:``]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10 bg-background/50`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Custom Forms`}),(0,y.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`This is the central page where you configure and manage your application's forms. Easily add and customize the fields for your users.`})]}),(0,y.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,y.jsx)(Z,{variant:`secondary`,onClick:O,title:`Add Custom Form`,disabled:E,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,children:E?(0,y.jsx)(W,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,y.jsx)(Qe,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,y.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:i?(0,y.jsx)(`div`,{className:`flex items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)]`,children:(0,y.jsx)(W,{className:`w-6 h-6 animate-spin text-accent`})}):Object.keys(n).length===0?(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed opacity-50`,children:[(0,y.jsx)(aee,{className:`w-6 h-6 mb-3 text-foreground/40`}),(0,y.jsx)(`p`,{className:`text-[13px] font-bold`,children:`No forms currently configured.`})]}):(0,y.jsx)(K,{children:Object.entries(n).map(([e,t])=>{let n=u[e],r=o[e];return(0,y.jsxs)(q.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},onClick:()=>A(e),className:`group flex flex-col p-3 px-4 glass-panel border transition-all rounded-2xl hover:shadow-sm cursor-pointer hover:border-accent/40 ${n?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${t.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:t.title||`Untitled Form`}),r&&(0,y.jsx)(W,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,y.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border border-[var(--panel-border)] bg-foreground/5 text-foreground/60 px-2 py-0.5 rounded-md`,children:t.systemName||e}),(0,y.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${t.formType===`private`?`text-blue-500 bg-blue-500/10 border-blue-500/20`:`text-green-500 bg-green-500/10 border-green-500/20`}`,children:t.formType||`public`})]})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),l(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center mr-2`,title:`Preview Form`,children:(0,y.jsx)(Ie,{className:`w-4 h-4`})}),e!==`contact`&&e!==`support`?(0,y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),p(e)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg opacity-0 group-hover:opacity-100 flex items-center justify-center mr-2`,title:`Delete Form`,children:(0,y.jsx)(rt,{className:`w-4 h-4`})}):(0,y.jsx)(`div`,{className:`w-7 mr-2 shrink-0`}),(0,y.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${n?`rotate-180`:``}`,children:(0,y.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,y.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,y.jsx)(K,{children:n&&(0,y.jsx)(q.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50`,onClick:e=>e.stopPropagation(),children:(0,y.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,y.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,y.jsx)(`button`,{onClick:t=>{t.stopPropagation(),T(e,J9[e]||J9.contact)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:r?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)($e,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(`button`,{onClick:n=>{n.stopPropagation(),S(e,t)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:v===e?(0,y.jsx)(Ee,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,y.jsx)(je,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,y.jsx)(q9,{value:{systemName:t.systemName||e,formType:t.formType||`public`,submitPage:t.submitPage||(t.formType===`private`?`requests`:`submissions`),redirectTo:t.redirectTo||``,title:t.title||``,buttonName:t.buttonName||t.submitText||``,fields:t.fields||[]},keysToRender:[`systemName`,`formType`,`submitPage`,`redirectTo`,`title`,`buttonName`,`fields`],meta:{formType:t.formType||`public`},onChange:n=>{n.formType===t.formType?n.submitPage!==t.submitPage&&(n.formType=n.submitPage===`requests`?`private`:`public`):n.submitPage=n.formType===`public`?`submissions`:`requests`,T(e,{...t,...n,submitText:n.buttonName})},isLast:!0,isGlobalSaving:r,disabledKeys:e===`contact`||e===`support`?[`systemName`,`formType`,`submitPage`]:[],customEnums:{type:[`text`,`email`,`tel`,`textarea`,`number`,`select`,`checkbox`,`currency`,`age`]},customExplanations:{formType:e===`contact`?`Public means its for not signed in users. Private is disabled for contact so don't allow the user to change it.`:e===`support`?`This means that the form is available to signed in users only.`:`Public means it's for non-signed in users.`,submitPage:e===`contact`?`Means the form submissions go to this folder. User can't change that since it's directly linked. Public is tied to submissions.`:e===`support`?`Can't change since all private forms go there.`:`Where to route data submissions.`,redirectTo:`If not added form will just show a success message. If added, in 30 seconds after success user is redirected.`}})]})})})]},t._uiKey||e)})})})]})]}),(0,y.jsx)(m9,{isOpen:!!f,onCancel:()=>p(null),onConfirm:()=>{f&&k(f)},title:`Delete Form`,message:`Are you sure you want to permanently delete "${f}"? This action cannot be reversed.`,confirmText:`Delete form`,isProcessing:g}),c&&(0,y.jsx)(wo,{formConfig:c,onClose:()=>l(null)})]})}function dHn({config:e}){let[t,n]=(0,m.useState)(!1),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)([]);(0,m.useEffect)(()=>{document.title=e.pageName||e.pageTitle||`Firebase OS`,(0,h.getDocs)((0,h.collection)(w,`sys_forms`)).then(e=>{o(e.docs.filter(e=>e.data().formType===`public`).map(e=>e.id))})},[e.pageName,e.pageTitle]);let s=MBn(e,a);return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 relative min-h-screen`,children:[(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,y.jsxs)(`div`,{className:`flex justify-between items-center mb-6 pt-2 border-b border-[var(--panel-border)] pb-6 relative z-20 overflow-x-auto no-scrollbar gap-4`,children:[(0,y.jsxs)(`button`,{onClick:()=>window.history.back(),className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 cursor-pointer shadow-sm text-foreground/70 whitespace-nowrap shrink-0`,children:[(0,y.jsx)(fe,{className:`w-4 h-4`}),` Go Back`]}),(0,y.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[e.copyPrompt&&(0,y.jsxs)(`button`,{onClick:()=>{navigator.clipboard.writeText(s),n(!0),setTimeout(()=>n(!1),2e3)},title:`Copy Developer Prompt`,className:`px-6 py-2.5 rounded-xl border border-[var(--panel-border)] bg-background flex items-center gap-2 hover:bg-foreground/5 hover:text-accent transition-all cursor-pointer text-[14px] font-bold tracking-wide shadow-sm whitespace-nowrap`,children:[(0,y.jsx)(ge,{className:`w-4 h-4`}),(0,y.jsx)(`span`,{className:`hidden sm:inline`,children:t?`Copied!`:`Copy Prompt`})]}),e.showButton&&(0,y.jsx)(`button`,{onClick:()=>{e.action===`redirect`?window.location.href=e.url||`/`:e.action===`form`&&i(e.form||`contact`)},className:`px-6 py-2.5 rounded-xl font-bold tracking-wide transition-all duration-300 flex items-center justify-center btn-primary shadow-xl hover:-translate-y-1 active:scale-95 text-[14px] whitespace-nowrap`,children:e.buttonText||`Action Button`})]})]}),(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:(0,y.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-40 glass-panel border border-[var(--panel-border)]/50 border-dashed m-4 md:m-8 rounded-2xl p-8 py-20 text-center`,children:[(0,y.jsx)(ge,{className:`w-8 h-8 md:w-12 md:h-12 mb-4 text-foreground/80 opacity-50`}),(0,y.jsx)(`p`,{className:`text-[14px] font-bold mb-2`,children:`Click copy prompt at the top to start adding changes`}),(0,y.jsx)(`div`,{className:`mt-8 text-left bg-background p-6 rounded-2xl text-[12px] font-mono whitespace-pre-wrap max-w-2xl border border-[var(--panel-border)]/50 text-foreground/60 shadow-inner`,children:s})]})}),(0,y.jsx)(K,{children:r&&(0,y.jsx)(wo,{onClose:()=>i(null),formId:r})})]})}function fHn({config:e}){let{user:t}=B(),[n,r]=(0,m.useState)([]),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(``),[f,p]=(0,m.useState)(!1),[g,_]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(``),P=(0,m.useRef)(null),[F,I]=(0,m.useState)([]),ee=(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),L=`user_${ee}_records`;(0,m.useEffect)(()=>{document.title=e.tabTitle||e.tabName||`Firebase OS`,(0,h.getDocs)((0,h.collection)(w,`sys_forms`)).then(e=>{I(e.docs.filter(e=>e.data().formType===`private`).map(e=>e.id))})},[e.tabTitle,e.tabName]),(0,m.useEffect)(()=>{t&&(async()=>{a(!0);try{let e=(await(0,h.getDocs)((0,h.query)((0,h.collection)(w,L),(0,h.where)(`uid`,`==`,t.uid)))).docs.map(e=>({id:e.id,...e.data()}));e.sort((e,t)=>{let n=e.createdAt?.toMillis?.()||0;return(t.createdAt?.toMillis?.()||0)-n}),r(e)}catch(e){console.error(`Error fetching records:`,e)}a(!1)})()},[t,L]);let R=async e=>{if(e.preventDefault(),!(!t||!c.trim())){p(!0);try{let e=await(0,h.addDoc)((0,h.collection)(w,L),{name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,createdAt:(0,h.serverTimestamp)()});r(n=>[{id:e.id,name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,createdAt:{toMillis:()=>Date.now()}},...n]),l(``),d(``),s(!1)}catch(e){console.error(`Error saving record:`,e)}p(!1)}},te=async e=>{let n=e.target.files?.[0];if(!(!n||!t)){x(!0);try{let e=(0,v.ref)(T,`user_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,v.uploadBytes)(e,n,{customMetadata:{ownerId:t.uid}});let i=await(0,v.getDownloadURL)(e);await(0,h.addDoc)((0,h.collection)(w,`user_files`),{fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:i,uid:t.uid,uploaderEmail:t.email||`user`,sourceTab:ee,accessPrefix:`user_`,createdAt:(0,h.serverTimestamp)()});let a=await(0,h.addDoc)((0,h.collection)(w,L),{name:n.name,note:`${n.type||`File`} · ${V(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:i,createdAt:(0,h.serverTimestamp)()});r(e=>[{id:a.id,name:n.name,note:`${n.type||`File`} · ${V(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type,fileSize:n.size,downloadURL:i,createdAt:{toMillis:()=>Date.now()}},...e])}catch(e){console.error(`Error uploading file:`,e)}x(!1),P.current&&(P.current.value=``)}},z=async()=>{if(S){D(!0);try{let e=n.find(e=>e.id===S);if(await(0,h.deleteDoc)((0,h.doc)(w,L,S)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];t&&await(0,v.deleteObject)((0,v.ref)(T,`user_files/${decodeURIComponent(t)}`)).catch(()=>{});let n=await(0,h.getDocs)((0,h.query)((0,h.collection)(w,`user_files`),(0,h.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of n.docs)await(0,h.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up user file:`,e)}r(e=>e.filter(e=>e.id!==S)),C(null)}catch(e){console.error(`Error deleting record:`,e)}D(!1)}},ne=e=>{k(e.id),j(e.name),N(e.note||``)},re=async()=>{if(!O||!A.trim()){k(null);return}let e=n.find(e=>e.id===O);if(e&&e.name===A.trim()&&(e.note||``)===M.trim()){k(null);return}try{await(0,h.updateDoc)((0,h.doc)(w,L,O),{name:A.trim(),note:M.trim()}),r(e=>e.map(e=>e.id===O?{...e,name:A.trim(),note:M.trim()}:e))}catch(e){console.error(`Error updating record:`,e)}k(null)},V=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ie=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},H=WBn(e,L,F),ae=()=>{navigator.clipboard.writeText(H),_(!0),setTimeout(()=>_(!1),2e3)},oe=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),n=[t,t.charAt(0).toUpperCase()+t.slice(1),t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),t.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)];for(let e of n)if(f9[e])return f9[e];return s2||Qe})(),se=e.buttonStyle!==`secondary`,ce=e.buttonStorageStyle===`primary`;return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Private Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:i?`Loading…`:`${n.length} ${n.length===1?`item`:`items`}`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ae,title:g?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${g?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:g?(0,y.jsx)(be,{className:`w-4 h-4`}):(0,y.jsx)(ge,{className:`w-4 h-4`})}),e.storage!==!1&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`input`,{type:`file`,ref:P,onChange:te,className:`hidden`}),(0,y.jsxs)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>P.current?.click(),disabled:b,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${ce?`btn-primary`:`btn-secondary`}`,children:[b?(0,y.jsx)(W,{className:`w-4 h-4 animate-spin`}):(0,y.jsx)(oe,{className:`w-4 h-4`}),e.buttonStorageText&&(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>s(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,y.jsx)(Qe,{className:`w-4 h-4`}):(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,y.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[i&&(0,y.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,y.jsx)(W,{className:`w-8 h-8 text-accent animate-spin`})}),!i&&n.length===0&&(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,y.jsx)(Qe,{className:`w-6 h-6 text-accent/40`})}),(0,y.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!i&&n.length>0&&(0,y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,y.jsx)(K,{children:n.map((e,t)=>{let n=O===e.id;return(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:t*.03,duration:.25},className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[!n&&(0,y.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all`,children:[e.recordType===`file`&&e.downloadURL&&(0,y.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,y.jsx)(Ne,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>ne(e),className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,y.jsx)(Ze,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>C(e.id),className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,y.jsx)(rt,{className:`w-3.5 h-3.5`})})]}),(0,y.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,y.jsx)(`div`,{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`bg-blue-500/10 text-blue-500`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?(0,y.jsx)(Le,{className:`w-4 h-4`}):(0,y.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[n?(0,y.jsx)(`input`,{autoFocus:!0,value:A,onChange:e=>j(e.target.value),onBlur:re,onKeyDown:e=>{e.key===`Enter`&&re(),e.key===`Escape`&&k(null)},className:`text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),(0,y.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ie(e.createdAt)})]})]}),n?(0,y.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),onBlur:re,onKeyDown:e=>{e.key===`Escape`&&k(null)},placeholder:`Note (optional)`,rows:2,className:`text-[13px] text-foreground/70 font-medium bg-transparent border-b border-accent/20 outline-none resize-none w-full mb-1 placeholder:text-foreground/30`}):e.note&&(0,y.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note})]},e.id)})})})]}),(0,y.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,y.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,y.jsx)(Ve,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,y.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:L}),` · Files: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / Private`]})]})})]})]}),(0,y.jsx)(K,{children:o&&(0,y.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,y.jsx)(q.div,{onClick:()=>!f&&s(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,y.jsx)(q.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,y.jsxs)(`form`,{onSubmit:R,className:`p-5 flex flex-col gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>!f&&s(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,y.jsx)(ct,{className:`w-4 h-4`})})]}),(0,y.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:c,onChange:e=>l(e.target.value),placeholder:`Name *`,disabled:f,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Note (optional)`,disabled:f,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,y.jsx)(Z,{type:`submit`,isLoading:f,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:f?`Saving…`:`Save`})})]})})]})}),(0,y.jsx)(m9,{isOpen:!!S,onCancel:()=>C(null),onConfirm:z,title:`Delete Record`,message:`Are you sure you want to delete this record? This action cannot be undone.`,confirmText:`Delete`,isProcessing:E})]})}function pHn({config:e}){let{user:t}=B(),[n,r]=(0,m.useState)([]),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(``),[f,p]=(0,m.useState)(!1),[g,_]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(``),P=(0,m.useRef)(null),[F,I]=(0,m.useState)({}),ee=(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),L=`admin_${ee}_records`;(0,m.useEffect)(()=>{document.title=e.tabTitle||e.tabName||`Firebase OS`},[e.tabTitle,e.tabName]);let R=(0,m.useCallback)(async e=>{if(F[e])return F[e];try{let t=await(0,h.getDoc)((0,h.doc)(w,`user_profiles`,e));if(t.exists()){let n=t.data(),r={name:n.displayName||n.name||n.email?.split(`@`)[0]||`Admin`,email:n.email||``,avatar:n.avatar||``};return I(t=>({...t,[e]:r})),r}}catch{}let t={name:`Admin`,email:``,avatar:``};return I(n=>({...n,[e]:t})),t},[F]);(0,m.useEffect)(()=>{if(!t)return;a(!0);let e=(0,h.onSnapshot)((0,h.query)((0,h.collection)(w,L),(0,h.orderBy)(`createdAt`,`desc`)),e=>{let t=e.docs.map(e=>({id:e.id,...e.data()}));r(t),a(!1);let n=[...new Set(t.map(e=>e.uid).filter(Boolean))];for(let e of n)R(e)},e=>{console.error(`Error listening to admin records:`,e);let t=(0,h.onSnapshot)((0,h.collection)(w,L),e=>{let t=e.docs.map(e=>({id:e.id,...e.data()}));t.sort((e,t)=>(t.createdAt?.toMillis?.()||0)-(e.createdAt?.toMillis?.()||0)),r(t),a(!1);let n=[...new Set(t.map(e=>e.uid).filter(Boolean))];for(let e of n)R(e)});return()=>t()});return()=>e()},[t,L]);let te=async e=>{if(e.preventDefault(),!(!t||!c.trim())){p(!0);try{let e=await ie();await(0,h.addDoc)((0,h.collection)(w,L),{name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,h.serverTimestamp)()}),l(``),d(``),s(!1)}catch(e){console.error(`Error saving admin record:`,e)}p(!1)}},z=async e=>{let n=e.target.files?.[0];if(!(!n||!t)){x(!0);try{let e=(0,v.ref)(T,`admin_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,v.uploadBytes)(e,n,{customMetadata:{ownerId:t.uid}});let r=await(0,v.getDownloadURL)(e),i=await ie();await(0,h.addDoc)((0,h.collection)(w,`admin_files`),{fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,uid:t.uid,uploaderEmail:t.email||`admin`,sourceTab:ee,accessPrefix:`admin_`,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()}),await(0,h.addDoc)((0,h.collection)(w,L),{name:n.name,note:`${n.type||`File`} · ${H(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()})}catch(e){console.error(`Error uploading admin file:`,e)}x(!1),P.current&&(P.current.value=``)}},ne=async()=>{if(S){D(!0);try{let e=n.find(e=>e.id===S);if(await(0,h.deleteDoc)((0,h.doc)(w,L,S)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];t&&await(0,v.deleteObject)((0,v.ref)(T,`admin_files/${decodeURIComponent(t)}`)).catch(()=>{});let n=await(0,h.getDocs)((0,h.query)((0,h.collection)(w,`admin_files`),(0,h.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of n.docs)await(0,h.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up admin file:`,e)}C(null)}catch(e){console.error(`Error deleting admin record:`,e)}D(!1)}},re=e=>{k(e.id),j(e.name),N(e.note||``)},V=async()=>{if(!O||!A.trim()){k(null);return}let e=n.find(e=>e.id===O);if(e&&e.name===A.trim()&&(e.note||``)===M.trim()){k(null);return}try{await(0,h.updateDoc)((0,h.doc)(w,L,O),{name:A.trim(),note:M.trim()})}catch(e){console.error(`Error updating admin record:`,e)}k(null)},ie=async()=>{try{let e=await(0,h.getDoc)((0,h.doc)(w,`user_profiles`,t.uid));if(e.exists()){let n=e.data(),r={name:n.displayName||n.name||t.email?.split(`@`)[0]||`Admin`,email:n.email||t.email||``,avatar:n.avatar||t.photoURL||``};return I(e=>({...e,[t.uid]:r})),r}}catch{}return{name:t.displayName||t.email?.split(`@`)[0]||`Admin`,email:t.email||``,avatar:t.photoURL||``}},H=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ae=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},oe=UBn(e,L),se=()=>{navigator.clipboard.writeText(oe),_(!0),setTimeout(()=>_(!1),2e3)},ce=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),n=[t,t.charAt(0).toUpperCase()+t.slice(1),t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),t.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)];for(let e of n)if(f9[e])return f9[e];return s2||Qe})(),U=e.buttonStyle!==`secondary`,le=e.buttonStorageStyle===`primary`,ue=e=>e.uid===t?.uid,de=({record:e})=>{let t=F[e.uid],n=t?.name||e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,r=t?.email||e.creatorEmail||``,i=t?.avatar||e.creatorAvatar||``,a=n.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[i?(0,y.jsx)(`img`,{src:i,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,y.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:a}),(0,y.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:n}),r&&(0,y.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,r]})]})]})};return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:i?`Loading…`:`${n.length} ${n.length===1?`item`:`items`} · Shared between admins`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:se,title:g?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${g?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:g?(0,y.jsx)(be,{className:`w-4 h-4`}):(0,y.jsx)(ge,{className:`w-4 h-4`})}),e.storage!==!1&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`input`,{type:`file`,ref:P,onChange:z,className:`hidden`}),(0,y.jsxs)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>P.current?.click(),disabled:b,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${le?`btn-primary`:`btn-secondary`}`,children:[b?(0,y.jsx)(W,{className:`w-4 h-4 animate-spin`}):(0,y.jsx)(ce,{className:`w-4 h-4`}),e.buttonStorageText&&(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>s(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${U?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,y.jsx)(Qe,{className:`w-4 h-4`}):(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,y.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[i&&(0,y.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,y.jsx)(W,{className:`w-8 h-8 text-accent animate-spin`})}),!i&&n.length===0&&(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,y.jsx)(Qe,{className:`w-6 h-6 text-accent/40`})}),(0,y.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!i&&n.length>0&&(0,y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,y.jsx)(K,{children:n.map((e,t)=>{let n=O===e.id,r=ue(e);return(0,y.jsxs)(q.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[!n&&(0,y.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all`,children:[e.recordType===`file`&&e.downloadURL&&(0,y.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,y.jsx)(Ne,{className:`w-3.5 h-3.5`})}),r&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{onClick:()=>re(e),className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,y.jsx)(Ze,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>C(e.id),className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,y.jsx)(rt,{className:`w-3.5 h-3.5`})})]})]}),(0,y.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,y.jsx)(`div`,{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`bg-blue-500/10 text-blue-500`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?(0,y.jsx)(Le,{className:`w-4 h-4`}):(0,y.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[n?(0,y.jsx)(`input`,{autoFocus:!0,value:A,onChange:e=>j(e.target.value),onBlur:V,onKeyDown:e=>{e.key===`Enter`&&V(),e.key===`Escape`&&k(null)},className:`text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),(0,y.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ae(e.createdAt)})]})]}),n?(0,y.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),onBlur:V,onKeyDown:e=>{e.key===`Escape`&&k(null)},placeholder:`Note (optional)`,rows:2,className:`text-[13px] text-foreground/70 font-medium bg-transparent border-b border-accent/20 outline-none resize-none w-full mb-1 placeholder:text-foreground/30`}):e.note&&(0,y.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),(0,y.jsx)(de,{record:e})]},e.id)})})})]}),(0,y.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,y.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,y.jsx)(Ve,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,y.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:L}),` · Files: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,y.jsx)(K,{children:o&&(0,y.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,y.jsx)(q.div,{onClick:()=>!f&&s(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,y.jsx)(q.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,y.jsxs)(`form`,{onSubmit:te,className:`p-5 flex flex-col gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>!f&&s(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,y.jsx)(ct,{className:`w-4 h-4`})})]}),(0,y.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:c,onChange:e=>l(e.target.value),placeholder:`Name *`,disabled:f,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Note (optional)`,disabled:f,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,y.jsx)(Z,{type:`submit`,isLoading:f,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:f?`Saving…`:`Save`})})]})})]})}),(0,y.jsx)(m9,{isOpen:!!S,onCancel:()=>C(null),onConfirm:ne,title:`Delete Record`,message:`Are you sure you want to delete this record? This action cannot be undone.`,confirmText:`Delete`,isProcessing:E})]})}function mHn({config:e}){let{user:t}=B(),[n,r]=(0,m.useState)([]),[i,a]=(0,m.useState)(!0),[o,s]=(0,m.useState)(!1),[c,l]=(0,m.useState)(``),[u,d]=(0,m.useState)(``),[f,p]=(0,m.useState)(!1),[g,_]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(``),P=(0,m.useRef)(null),F=(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),I=`mem_${F}_records`;(0,m.useEffect)(()=>{document.title=e.tabTitle||e.tabName||`Firebase OS`},[e.tabTitle,e.tabName]),(0,m.useEffect)(()=>{if(!t)return;a(!0);let e=(0,h.onSnapshot)((0,h.query)((0,h.collection)(w,I),(0,h.orderBy)(`createdAt`,`desc`)),e=>{r(e.docs.map(e=>({id:e.id,...e.data()}))),a(!1)},e=>{console.error(`Error listening to shared records:`,e);let t=(0,h.onSnapshot)((0,h.collection)(w,I),e=>{let t=e.docs.map(e=>({id:e.id,...e.data()}));t.sort((e,t)=>(t.createdAt?.toMillis?.()||0)-(e.createdAt?.toMillis?.()||0)),r(t),a(!1)});return()=>t()});return()=>e()},[t,I]);let ee=()=>({name:t.displayName||t.email?.split(`@`)[0]||`Member`,email:t.email||``,avatar:t.photoURL||``}),L=async e=>{if(e.preventDefault(),!(!t||!c.trim())){p(!0);try{let e=ee();await(0,h.addDoc)((0,h.collection)(w,I),{name:c.trim(),note:u.trim(),uid:t.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,h.serverTimestamp)()}),l(``),d(``),s(!1)}catch(e){console.error(`Error saving shared record:`,e)}p(!1)}},R=async e=>{let n=e.target.files?.[0];if(!(!n||!t)){x(!0);try{let e=(0,v.ref)(T,`mem_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,v.uploadBytes)(e,n,{customMetadata:{ownerId:t.uid}});let r=await(0,v.getDownloadURL)(e),i=ee();await(0,h.addDoc)((0,h.collection)(w,`mem_files`),{fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,uid:t.uid,uploaderEmail:t.email||`member`,sourceTab:F,accessPrefix:`mem_`,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()}),await(0,h.addDoc)((0,h.collection)(w,I),{name:n.name,note:`${n.type||`File`} · ${re(n.size)}`,uid:t.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:r,creatorName:i.name,creatorEmail:i.email,creatorAvatar:i.avatar,createdAt:(0,h.serverTimestamp)()})}catch(e){console.error(`Error uploading shared file:`,e)}x(!1),P.current&&(P.current.value=``)}},te=async()=>{if(S){D(!0);try{let e=n.find(e=>e.id===S);if(await(0,h.deleteDoc)((0,h.doc)(w,I,S)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];t&&await(0,v.deleteObject)((0,v.ref)(T,`mem_files/${decodeURIComponent(t)}`)).catch(()=>{});let n=await(0,h.getDocs)((0,h.query)((0,h.collection)(w,`mem_files`),(0,h.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of n.docs)await(0,h.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up shared file:`,e)}C(null)}catch(e){console.error(`Error deleting shared record:`,e)}D(!1)}},z=e=>{k(e.id),j(e.name),N(e.note||``)},ne=async()=>{if(!O||!A.trim()){k(null);return}let e=n.find(e=>e.id===O);if(e&&e.name===A.trim()&&(e.note||``)===M.trim()){k(null);return}try{await(0,h.updateDoc)((0,h.doc)(w,I,O),{name:A.trim(),note:M.trim()})}catch(e){console.error(`Error updating shared record:`,e)}k(null)},re=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},V=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ie=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),n=[t,t.charAt(0).toUpperCase()+t.slice(1),t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),t.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)];for(let e of n)if(f9[e])return f9[e];return s2||Qe})(),H=e.buttonStyle!==`secondary`,ae=e.buttonStorageStyle===`primary`,oe=e=>e.uid===t?.uid,se=HBn(e,I),ce=()=>{navigator.clipboard.writeText(se),_(!0),setTimeout(()=>_(!1),2e3)},U=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,y.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,y.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,y.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,y.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,y.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsx)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Shared Page`}),e.route&&(0,y.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,y.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,y.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:i?`Loading…`:`${n.length} ${n.length===1?`item`:`items`} · Shared`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ce,title:g?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${g?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:g?(0,y.jsx)(be,{className:`w-4 h-4`}):(0,y.jsx)(ge,{className:`w-4 h-4`})}),e.storage!==!1&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`input`,{type:`file`,ref:P,onChange:R,className:`hidden`}),(0,y.jsxs)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>P.current?.click(),disabled:b,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${ae?`btn-primary`:`btn-secondary`}`,children:[b?(0,y.jsx)(W,{className:`w-4 h-4 animate-spin`}):(0,y.jsx)(ie,{className:`w-4 h-4`}),e.buttonStorageText&&(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,y.jsx)(q.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>s(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${H?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,y.jsx)(Qe,{className:`w-4 h-4`}):(0,y.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,y.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[i&&(0,y.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,y.jsx)(W,{className:`w-8 h-8 text-accent animate-spin`})}),!i&&n.length===0&&(0,y.jsxs)(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,y.jsx)(Qe,{className:`w-6 h-6 text-accent/40`})}),(0,y.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!i&&n.length>0&&(0,y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,y.jsx)(K,{children:n.map(e=>{let t=O===e.id,n=oe(e);return(0,y.jsxs)(q.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${t?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[!t&&(0,y.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all`,children:[e.recordType===`file`&&e.downloadURL&&(0,y.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,y.jsx)(Ne,{className:`w-3.5 h-3.5`})}),n&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`button`,{onClick:()=>z(e),className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,y.jsx)(Ze,{className:`w-3.5 h-3.5`})}),(0,y.jsx)(`button`,{onClick:()=>C(e.id),className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,y.jsx)(rt,{className:`w-3.5 h-3.5`})})]})]}),(0,y.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,y.jsx)(`div`,{className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`bg-blue-500/10 text-blue-500`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?(0,y.jsx)(Le,{className:`w-4 h-4`}):(0,y.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,y.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[t?(0,y.jsx)(`input`,{autoFocus:!0,value:A,onChange:e=>j(e.target.value),onBlur:ne,onKeyDown:e=>{e.key===`Enter`&&ne(),e.key===`Escape`&&k(null)},className:`text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),(0,y.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:V(e.createdAt)})]})]}),t?(0,y.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),onBlur:ne,onKeyDown:e=>{e.key===`Escape`&&k(null)},placeholder:`Note (optional)`,rows:2,className:`text-[13px] text-foreground/70 font-medium bg-transparent border-b border-accent/20 outline-none resize-none w-full mb-1 placeholder:text-foreground/30`}):e.note&&(0,y.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),(0,y.jsx)(U,{record:e})]},e.id)})})})]}),(0,y.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,y.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,y.jsx)(Ve,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,y.jsxs)(`span`,{children:[`Shared between all members · Edit and delete available on your own items only · Records: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:I}),` · Files: `,(0,y.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Shared`]})]})})]})]}),(0,y.jsx)(K,{children:o&&(0,y.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,y.jsx)(q.div,{onClick:()=>!f&&s(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,y.jsx)(q.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,y.jsxs)(`form`,{onSubmit:L,className:`p-5 flex flex-col gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,y.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>!f&&s(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,y.jsx)(ct,{className:`w-4 h-4`})})]}),(0,y.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:c,onChange:e=>l(e.target.value),placeholder:`Name *`,disabled:f,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Note (optional)`,disabled:f,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,y.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,y.jsx)(Z,{type:`submit`,isLoading:f,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:f?`Saving…`:`Save`})})]})})]})}),(0,y.jsx)(m9,{isOpen:!!S,onCancel:()=>C(null),onConfirm:te,title:`Delete Record`,message:`Are you sure you want to delete this record? This action cannot be undone.`,confirmText:`Delete`,isProcessing:E})]})}function hHn(){let e=(0,b.useLocation)(),{user:t}=B(),n=R(),[r,i]=(0,m.useState)(null),[a,o]=(0,m.useState)(!0);(0,m.useEffect)(()=>{(async()=>{o(!0);try{let[t,n]=await Promise.all([(0,h.getDocs)((0,h.collection)(w,`sys_pages`)),(0,h.getDocs)((0,h.collection)(w,`sys_tabs`))]),r=null,a=null,o=(t,n)=>{t.forEach(t=>{let i=t.data(),o=i.route;o&&!o.startsWith(`/`)&&(o=`/`+o);let s=`/`+t.id===e.pathname;(o===e.pathname||s)&&(r={...i,isPrivate:n,isAdmin:i.pageType===`admin`,isShared:i.pageType===`shared`},a=t.id)})};if(o(t,!1),r||o(n,!0),r||(e.pathname===`/contact`?(r={route:`/contact`,template:`popup_form`,form:`contact`},a=`contact`):e.pathname===`/support`&&(r={route:`/support`,template:`popup_form`,form:`support`},a=`support`)),r){if((a===`contact`||a===`support`)&&!r.form&&(r.form=a),r.pageId=a,r.form){let e=await(0,h.getDoc)((0,h.doc)(w,`sys_forms`,r.form));if(e.exists())r.formConfigOverride={...e.data(),id:e.id};else if(r.form===`contact`){let{contactFormConfig:e}=await Promise.resolve().then(()=>require(`./contactForm.config-ki9OzidM.cjs`));r.formConfigOverride=e}else if(r.form===`support`){let{supportFormConfig:e}=await Promise.resolve().then(()=>require(`./supportForm.config-BwZqJ5CZ.cjs`));r.formConfigOverride=e}}let e=r.pageName||r.tabName||r.title;e&&(document.title=e),i(r)}else i(`not-found`)}catch{i(`not-found`)}finally{o(!1)}})()},[e.pathname]);let[s,c]=(0,m.useState)(!1);if((0,m.useEffect)(()=>{let e;return a?e=setTimeout(()=>c(!0),150):c(!1),()=>clearTimeout(e)},[a]),a)return s?t?(0,y.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,y.jsxs)(`div`,{className:`mb-6`,children:[(0,y.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,y.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,y.jsx)(p9,{}),(0,y.jsx)(`div`,{className:`flex-1 glass-panel border border-[var(--panel-border)] rounded-3xl flex items-center justify-center min-h-[400px] bg-background shadow-2xl`,children:(0,y.jsx)(W,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,y.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[60vh] z-10`,children:(0,y.jsx)(W,{className:`w-6 h-6 animate-spin text-accent`})}):null;if(r===`not-found`)return(0,y.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,y.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 bg-red-500/10 text-red-500 rounded-full flex items-center justify-center mb-6`,children:(0,y.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-8 h-8`,children:[(0,y.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,y.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,y.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,y.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,y.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`})]})});if((r.pageId===`support`||r.isPrivate)&&!t)return(0,y.jsx)(b.Navigate,{to:`/login`,state:{from:e}});let l=r.pageName?.toLowerCase().replace(/\s+/g,`_`)||r.pageId||`custom_page`,u=`pub_${l}`;if(r.template===`none`)return r.isAdmin?(0,y.jsx)(pHn,{config:r}):r.isShared?(0,y.jsx)(mHn,{config:r}):r.isPrivate?(0,y.jsx)(fHn,{config:r}):(0,y.jsx)(dHn,{config:r});if(r.template===`board`){let e=r.isAdmin?`admin_${r.pageId||l}`:r.isShared?`mem_${r.pageId||l}`:r.isPrivate?`user_${r.pageId||l}`:u;return(0,y.jsx)(n.components?.TemplateBoard||GBn,{title:r.tabTitle||r.tabName||r.title||r.pageName||`Board`,subtitle:r.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:r})}if(r.template===`table`){let e=r.isAdmin?`admin_${r.pageId||l}`:r.isShared?`mem_${r.pageId||l}`:r.isPrivate?`user_${r.pageId||l}`:u;return(0,y.jsx)(n.components?.TemplateTable||XVn,{title:r.tabTitle||r.tabName||r.title||r.pageName||`Table`,subtitle:r.route,tableCollection:`${e}_table`,config:r})}if(r.template===`calendar`){let e=r.isAdmin?`admin_${r.pageId||l}`:r.isShared?`mem_${r.pageId||l}`:r.isPrivate?`user_${r.pageId||l}`:u;return(0,y.jsx)(n.components?.TemplateCalendar||ZVn,{title:r.tabTitle||r.tabName||r.title||r.pageName||`Calendar`,subtitle:r.route,eventsCollection:`${e}_events`,defaultTimeFormat:r.defaultTimeFormat||r.defaulttimeformat||`12h`,config:r})}return r.template===`inline_form`?(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,y.jsx)(wo,{isInline:!0,formId:r.form,formConfig:r.formConfigOverride})}):(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,y.jsx)(wo,{formId:r.form,formConfig:r.formConfigOverride,onClose:()=>window.history.back()})})}var gHn=`rules_version = '2';
|
|
507
507
|
service cloud.firestore {
|
|
508
508
|
match /databases/{database}/documents {
|
|
509
509
|
|
|
@@ -86536,8 +86536,8 @@ function fUn() {
|
|
|
86536
86536
|
}).catch(console.error);
|
|
86537
86537
|
}, []);
|
|
86538
86538
|
let [se, ce] = x(null), le = (e, t) => {
|
|
86539
|
-
let n
|
|
86540
|
-
navigator.clipboard.writeText(n), ce(e), setTimeout(() => ce(null), 2e3);
|
|
86539
|
+
let n;
|
|
86540
|
+
n = e === "home" ? `export const defaultHomeConfig = ${JSON.stringify(t, null, 2)};\n` : JSON.stringify(t, null, 2), navigator.clipboard.writeText(n), ce(e), setTimeout(() => ce(null), 2e3);
|
|
86541
86541
|
}, ue = async (e, t) => {
|
|
86542
86542
|
t.route && !t.route.startsWith("/") && (t.route = "/" + t.route);
|
|
86543
86543
|
let o = n.find((t) => t.id === e)?.type, s = o === "public" ? "sys_pages" : "sys_tabs";
|
|
@@ -87011,7 +87011,7 @@ function fUn() {
|
|
|
87011
87011
|
},
|
|
87012
87012
|
className: "w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors",
|
|
87013
87013
|
title: "Copy JSON",
|
|
87014
|
-
children: se === t.id ? /* @__PURE__ */ V(lt, { className: "w-
|
|
87014
|
+
children: se === t.id ? /* @__PURE__ */ V(lt, { className: "w-3.5 h-3.5 text-emerald-500" }) : /* @__PURE__ */ V(dt, { className: "w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors" })
|
|
87015
87015
|
})]
|
|
87016
87016
|
}), /* @__PURE__ */ V(q9, {
|
|
87017
87017
|
value: c[t.id],
|
package/package.json
CHANGED
package/src/pages/PagesAdmin.tsx
CHANGED
|
@@ -179,12 +179,21 @@ export function PagesAdmin() {
|
|
|
179
179
|
const [copyStateId, setCopyStateId] = useState<string | null>(null);
|
|
180
180
|
|
|
181
181
|
const handleCopyBtn = (id: string, val: any) => {
|
|
182
|
-
let str
|
|
182
|
+
let str: string;
|
|
183
|
+
if (id === 'home') {
|
|
184
|
+
// Output a complete TypeScript file so it can be pasted directly into home.config.ts
|
|
185
|
+
const json = JSON.stringify(val, null, 2);
|
|
186
|
+
str = `export const defaultHomeConfig = ${json};\n`;
|
|
187
|
+
} else {
|
|
188
|
+
str = JSON.stringify(val, null, 2);
|
|
189
|
+
}
|
|
183
190
|
navigator.clipboard.writeText(str);
|
|
184
191
|
setCopyStateId(id);
|
|
185
192
|
setTimeout(() => setCopyStateId(null), 2000);
|
|
186
193
|
};
|
|
187
194
|
|
|
195
|
+
|
|
196
|
+
|
|
188
197
|
const handleSaveConfig = async (id: string, val: any) => {
|
|
189
198
|
if (val.route && !val.route.startsWith('/')) {
|
|
190
199
|
val.route = '/' + val.route;
|
|
@@ -736,6 +745,7 @@ export function PagesAdmin() {
|
|
|
736
745
|
<button onClick={(e) => { e.stopPropagation(); handleCopyBtn('home', homeConfig); }} className="w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors" title="Copy JSON">
|
|
737
746
|
{copyStateId === 'home' ? <CheckCircle2 className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors" />}
|
|
738
747
|
</button>
|
|
748
|
+
|
|
739
749
|
</div>
|
|
740
750
|
<JsonNode
|
|
741
751
|
value={homeConfig}
|
|
@@ -767,8 +777,9 @@ export function PagesAdmin() {
|
|
|
767
777
|
{resettingMap[page.id] ? <Loader2 className="w-3.5 h-3.5 text-red-500 animate-spin" /> : <RotateCcw className="w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors" />}
|
|
768
778
|
</button>
|
|
769
779
|
<button onClick={(e) => { e.stopPropagation(); handleCopyBtn(page.id, draftConfigs[page.id]); }} className="w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors" title="Copy JSON">
|
|
770
|
-
{copyStateId === page.id ? <CheckCircle2 className="w-
|
|
780
|
+
{copyStateId === page.id ? <CheckCircle2 className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors" />}
|
|
771
781
|
</button>
|
|
782
|
+
|
|
772
783
|
</div>
|
|
773
784
|
<JsonNode
|
|
774
785
|
value={draftConfigs[page.id]}
|