firebase-os 1.1.3 → 1.1.5

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.
Files changed (124) hide show
  1. package/dist/FirebaseOS.d.ts +15 -0
  2. package/dist/firebase-os.cjs.js +2 -17
  3. package/dist/firebase-os.es.js +63 -72
  4. package/dist/index.d.ts +3 -0
  5. package/dist/lib/ConfigContext.d.ts +12 -0
  6. package/package.json +3 -2
  7. package/scripts/postinstall.js +89 -10
  8. package/src/App.css +184 -0
  9. package/src/App.tsx +214 -0
  10. package/src/FirebaseOS.tsx +80 -0
  11. package/src/assets/hero.png +0 -0
  12. package/src/assets/react.svg +1 -0
  13. package/src/assets/vite.svg +1 -0
  14. package/src/components/AdminNotifications.test.tsx +98 -0
  15. package/src/components/AdminNotifications.tsx +194 -0
  16. package/src/components/Button.test.tsx +22 -0
  17. package/src/components/Button.tsx +53 -0
  18. package/src/components/ConfirmModal.test.tsx +98 -0
  19. package/src/components/ConfirmModal.tsx +73 -0
  20. package/src/components/ContactPopup.test.tsx +98 -0
  21. package/src/components/ContactPopup.tsx +437 -0
  22. package/src/components/CustomSelect.test.tsx +47 -0
  23. package/src/components/CustomSelect.tsx +89 -0
  24. package/src/components/DashboardNav.test.tsx +98 -0
  25. package/src/components/DashboardNav.tsx +281 -0
  26. package/src/components/Input.test.tsx +33 -0
  27. package/src/components/Input.tsx +61 -0
  28. package/src/components/JsonEditor.tsx +579 -0
  29. package/src/components/Navbar.test.tsx +98 -0
  30. package/src/components/Navbar.tsx +563 -0
  31. package/src/configs/forms/contactForm.config.ts +15 -0
  32. package/src/configs/forms/index.ts +29 -0
  33. package/src/configs/forms/pubForm.config.ts +11 -0
  34. package/src/configs/forms/supportForm.config.ts +14 -0
  35. package/src/configs/forms/userForm.config.ts +11 -0
  36. package/src/configs/pages/admin.config.ts +29 -0
  37. package/src/configs/pages/contact.config.ts +6 -0
  38. package/src/configs/pages/home.config.ts +18 -0
  39. package/src/configs/pages/mem.config.ts +2 -0
  40. package/src/configs/pages/menuOrders.config.ts +11 -0
  41. package/src/configs/pages/pub.config.ts +11 -0
  42. package/src/configs/pages/shared.config.ts +29 -0
  43. package/src/configs/pages/support.config.ts +7 -0
  44. package/src/configs/pages/tabOrders.config.ts +33 -0
  45. package/src/configs/pages/user.config.ts +29 -0
  46. package/src/configs/theme.config.ts +93 -0
  47. package/src/index.css +403 -0
  48. package/src/index.ts +22 -0
  49. package/src/lib/AuthContext.test.tsx +88 -0
  50. package/src/lib/AuthContext.tsx +191 -0
  51. package/src/lib/ConfigContext.tsx +45 -0
  52. package/src/lib/ThemeContext.tsx +227 -0
  53. package/src/lib/firebase.ts +91 -0
  54. package/src/main.tsx +22 -0
  55. package/src/microcomponents/AdminExampleContent.tsx +44 -0
  56. package/src/microcomponents/PrivateExampleContent.tsx +39 -0
  57. package/src/microcomponents/Public.tsx +126 -0
  58. package/src/microcomponents/SharedExampleContent.tsx +53 -0
  59. package/src/pages/Dashboard.test.tsx +98 -0
  60. package/src/pages/Dashboard.tsx +60 -0
  61. package/src/pages/DynamicPage.tsx +237 -0
  62. package/src/pages/FormsAdmin.test.tsx +98 -0
  63. package/src/pages/FormsAdmin.tsx +459 -0
  64. package/src/pages/Home.test.tsx +98 -0
  65. package/src/pages/Home.tsx +144 -0
  66. package/src/pages/Login.test.tsx +98 -0
  67. package/src/pages/Login.tsx +108 -0
  68. package/src/pages/PagesAdmin.test.tsx +98 -0
  69. package/src/pages/PagesAdmin.tsx +1022 -0
  70. package/src/pages/Profile.test.tsx +98 -0
  71. package/src/pages/Profile.tsx +319 -0
  72. package/src/pages/Register.test.tsx +98 -0
  73. package/src/pages/Register.tsx +116 -0
  74. package/src/pages/Requests.test.tsx +95 -0
  75. package/src/pages/Requests.tsx +422 -0
  76. package/src/pages/ResetPassword.test.tsx +98 -0
  77. package/src/pages/ResetPassword.tsx +92 -0
  78. package/src/pages/Settings.test.tsx +98 -0
  79. package/src/pages/Settings.tsx +393 -0
  80. package/src/pages/Setup.tsx +401 -0
  81. package/src/pages/StorageAdmin.test.tsx +150 -0
  82. package/src/pages/StorageAdmin.tsx +769 -0
  83. package/src/pages/Submissions.test.tsx +95 -0
  84. package/src/pages/Submissions.tsx +372 -0
  85. package/src/pages/Templates.test.tsx +98 -0
  86. package/src/pages/Templates.tsx +103 -0
  87. package/src/pages/ThemeAdmin.test.tsx +144 -0
  88. package/src/pages/ThemeAdmin.tsx +1000 -0
  89. package/src/pages/Users.test.tsx +95 -0
  90. package/src/pages/Users.tsx +334 -0
  91. package/src/pages/Verify.test.tsx +98 -0
  92. package/src/pages/Verify.tsx +95 -0
  93. package/src/prompts/index.ts +13 -0
  94. package/src/prompts/pages/publicPage.ts +44 -0
  95. package/src/prompts/sharedConstants.ts +12 -0
  96. package/src/prompts/tabs/board/adminboard.ts +32 -0
  97. package/src/prompts/tabs/board/privateboard.ts +36 -0
  98. package/src/prompts/tabs/board/publicboard.ts +36 -0
  99. package/src/prompts/tabs/calendar/admincalendar.ts +32 -0
  100. package/src/prompts/tabs/calendar/privatecalendar.ts +36 -0
  101. package/src/prompts/tabs/calendar/publiccalendar.ts +36 -0
  102. package/src/prompts/tabs/crud/admin.ts +54 -0
  103. package/src/prompts/tabs/crud/private.ts +55 -0
  104. package/src/prompts/tabs/crud/shared.ts +53 -0
  105. package/src/prompts/tabs/table/admintable.ts +32 -0
  106. package/src/prompts/tabs/table/privatetable.ts +36 -0
  107. package/src/prompts/tabs/table/publictable.ts +36 -0
  108. package/src/setupTests.ts +1 -0
  109. package/src/templates/AdminPageTemplate.tsx +678 -0
  110. package/src/templates/PrivatePageTemplate.tsx +594 -0
  111. package/src/templates/PublicPageTemplate.tsx +92 -0
  112. package/src/templates/SharedPageTemplate.tsx +551 -0
  113. package/src/templates/TemplateBoard.test.tsx +106 -0
  114. package/src/templates/TemplateBoard.tsx +642 -0
  115. package/src/templates/TemplateCalendar.test.tsx +106 -0
  116. package/src/templates/TemplateCalendar.tsx +848 -0
  117. package/src/templates/TemplateConfirmation.test.tsx +106 -0
  118. package/src/templates/TemplateConfirmation.tsx +145 -0
  119. package/src/templates/TemplateInlineForm.test.tsx +106 -0
  120. package/src/templates/TemplateInlineForm.tsx +129 -0
  121. package/src/templates/TemplatePopupForm.test.tsx +106 -0
  122. package/src/templates/TemplatePopupForm.tsx +174 -0
  123. package/src/templates/TemplateTable.test.tsx +106 -0
  124. package/src/templates/TemplateTable.tsx +675 -0
@@ -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),c(!0),setTimeout(()=>c(!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&&g()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,m.useEffect)(()=>{if(!t?.colors)return;let e=(document.documentElement.getAttribute(`data-theme`)||`dark`)===`dark`?t.colors.dark:t.colors.light,n=document.documentElement;n.style.setProperty(`--bg-color`,e.background),e.backgroundSecondary&&n.style.setProperty(`--bg-secondary-color`,e.backgroundSecondary),n.style.setProperty(`--fg-color`,e.foreground),n.style.setProperty(`--accent-color`,e.accent),n.style.setProperty(`--accent-deep`,e.accentDeep),n.style.setProperty(`--panel-bg`,e.panelBg),n.style.setProperty(`--panel-border`,e.panelBorder),n.style.setProperty(`--button-bg`,`linear-gradient(135deg, ${e.buttonGradient[0]} 0%, ${e.buttonGradient[1]} 100%)`),n.style.setProperty(`--button-hover-bg`,`linear-gradient(135deg, ${e.buttonHoverGradient?.[0]||e.buttonGradient[0]} 0%, ${e.buttonHoverGradient?.[1]||e.buttonGradient[1]} 100%)`),n.style.setProperty(`--text-gradient`,`linear-gradient(135deg, ${e.textGradient[0]} 0%, ${e.textGradient[1]} 50%, ${e.textGradient[2]} 100%)`),n.style.setProperty(`--glow-color`,e.glowColor||`rgba(124, 58, 237, 0.3)`),n.style.setProperty(`--button-fg`,e.buttonText||`#ffffff`),e.notificationIconColor&&n.style.setProperty(`--notification-icon-color`,e.notificationIconColor)},[t]),(0,m.useEffect)(()=>()=>{if(!e?.colors)return;let t=(document.documentElement.getAttribute(`data-theme`)||`dark`)===`dark`?e.colors.dark:e.colors.light,n=document.documentElement;n.style.setProperty(`--bg-color`,t.background),t.backgroundSecondary&&n.style.setProperty(`--bg-secondary-color`,t.backgroundSecondary),n.style.setProperty(`--fg-color`,t.foreground),n.style.setProperty(`--accent-color`,t.accent),n.style.setProperty(`--accent-deep`,t.accentDeep),n.style.setProperty(`--panel-bg`,t.panelBg),n.style.setProperty(`--panel-border`,t.panelBorder),n.style.setProperty(`--button-bg`,`linear-gradient(135deg, ${t.buttonGradient[0]} 0%, ${t.buttonGradient[1]} 100%)`),n.style.setProperty(`--button-hover-bg`,`linear-gradient(135deg, ${t.buttonHoverGradient?.[0]||t.buttonGradient[0]} 0%, ${t.buttonHoverGradient?.[1]||t.buttonGradient[1]} 100%)`),n.style.setProperty(`--text-gradient`,`linear-gradient(135deg, ${t.textGradient[0]} 0%, ${t.textGradient[1]} 50%, ${t.textGradient[2]} 100%)`),n.style.setProperty(`--glow-color`,t.glowColor||`rgba(124, 58, 237, 0.3)`),n.style.setProperty(`--button-fg`,t.buttonText||`#ffffff`),t.notificationIconColor&&n.style.setProperty(`--notification-icon-color`,t.notificationIconColor)},[e]),(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 flex-col md:flex-row items-start md:items-center 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 w-full md:w-auto shrink-0`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:d,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)(rt,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(Z,{variant:`secondary`,onClick:g,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:s?(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`}),eHn.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:()=>p(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)(K9,{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)(K9,{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 q9={route:`/contact`,template:`popup_form`,form:`contact`,pageName:`Contact`},iHn={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},aHn={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`},oHn={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`},sHn={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`},cHn=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0},{id:`contact`,title:`Contact`,path:`/contact`,type:`public`,isSystem:!0,enabled:!0},{id:`support`,title:`Request Support`,path:`/support`,type:`private`,isSystem:!0,enabled:!0}],lHn=({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 uHn(){let{userRole:e}=B(),t=(0,b.useLocation)(),[n,r]=(0,m.useState)(cHn),[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)(null),[M,N]=(0,m.useState)(!1),[P,F]=(0,m.useState)(!1),[I,ee]=(0,m.useState)(null),[L,R]=(0,m.useState)(!1),[te,z]=(0,m.useState)(!1),[ne,re]=(0,m.useState)(new Set),[V,ie]=(0,m.useState)(new Set),[H,ae]=(0,m.useState)([]),[oe,se]=(0,m.useState)([]),ce=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=ce(e.exists()&&e.data().order||[]);ae(t),re(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=ce(e.exists()&&e.data().order||[]);se(t),ie(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(Zo,t.data()):Zo)}),n=(0,h.onSnapshot)((0,h.doc)(w,`sys_pages`,`contact`),t=>{j(t.exists()?e(q9,t.data()):q9)}),r=(0,h.onSnapshot)((0,h.doc)(w,`sys_tabs`,`support`),t=>{ee(t.exists()?e(Jo,t.data()):Jo)});return()=>{t(),n(),r()}},[]),(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[U,le]=(0,m.useState)([`contact`]),[ue,de]=(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&&le(t),n.length>0&&de(n)}).catch(console.error)},[]);let[fe,pe]=(0,m.useState)(null),me=(e,t)=>{let n=JSON.stringify(t,null,2);navigator.clipboard.writeText(n),pe(e),setTimeout(()=>pe(null),2e3)},he=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`,`contact`,`support`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?D(!0):e===`contact`?N(!0):e===`support`?R(!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?H:oe;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):e===`contact`?j(t):e===`support`?ee(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):e===`contact`?N(!1):e===`support`?R(!1):d(t=>({...t,[e]:!1,[c]:!1}))},500)}},ge=async e=>{e.stopPropagation(),k(!0),await he(`home`,Zo),setTimeout(()=>k(!1),500)},_e=async e=>{e.stopPropagation(),F(!0),await he(`contact`,q9),setTimeout(()=>F(!1),500)},ve=async e=>{e.stopPropagation(),z(!0),await he(`support`,Jo),setTimeout(()=>z(!1),500)},ye=async(e,t,n)=>{e.stopPropagation(),p(e=>({...e,[t]:!0})),await he(t,n),setTimeout(()=>p(e=>({...e,[t]:!1})),500)},be=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={...iHn}:e===`private`?i={...aHn}:e===`admin`?i={...oHn}:e===`shared`&&(i={...sHn}),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)(at,{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 Se=async(e,t,i)=>{let a=i===`public`,o=a?`page_order`:`tab_order`,s=a?H:oe,c=(a?ne:V).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})},Ce=(e,t)=>{t||_(e)},we=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`?H:oe,{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)}},Te=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===`contact`&&(i=A||q9),e.id===`support`&&(i=I||Jo));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:Ye,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:at,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[Oe,ke]=(0,m.useState)(!1),[Ae,Me]=(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 flex-col md:flex-row items-start md:items-center 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 w-full md:w-auto flex justify-end gap-1`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:()=>ke(!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)(rt,{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)(tt,{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:()=>{be(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:Ae&&(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`?H:oe,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`?ne.has(e.id):V.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=t.id===`contact`,l=t.id===`support`,p=i===t.id,m=o||s||l||!t.isSystem;return(0,y.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(m){let e=p?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 ${m?`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||s&&M||l&&L)&&(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(),Te(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)(lHn,{enabled:!d(t),onChange:()=>Se(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(),Ce(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)(st,{className:`w-4 h-4`})}),m?(0,y.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${p?`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:[p&&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:ge,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)(rt,{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(),me(`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:fe===`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)(K9,{value:C,keysToRender:[`hero`],onChange:e=>he(`home`,e),isLast:!0,isGlobalSaving:E,customEnums:{form:U},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.`}})]})}),p&&s&&A&&(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,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:P?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)(rt,{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(),me(`contact`,A)},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:fe===`contact`?(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)(K9,{value:A,keysToRender:A.showButton===!1?[`pageName`,`route`,`template`,`showButton`]:[`pageName`,`route`,`template`,`showButton`,`form`],disabledKeys:[`route`],onChange:e=>he(`contact`,e),isLast:!0,isGlobalSaving:M,customEnums:{form:U,template:[`popup_form`,`inline_form`]},customExplanations:{pageName:`This defines the text that actually appears globally in the Navigation menus.`,template:`This just simply tells our app when a user clicks on the contact page item what type of form do we load? is it a page or popup? this doesn't define form content! this setting just defines page layout.`,form:`This is the form that will be used. Go to /forms to edit it.`}})]})}),p&&l&&I&&(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:ve,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:te?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)(rt,{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(),me(`support`,I)},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:fe===`support`?(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)(K9,{value:I,keysToRender:I.showButton===!1?[`pageName`,`iconName`,`route`,`template`,`showButton`]:[`pageName`,`iconName`,`route`,`template`,`showButton`,`form`],disabledKeys:[`route`],onChange:e=>he(`support`,e),isLast:!0,isGlobalSaving:L,customEnums:{form:ue,template:[`popup_form`,`inline_form`]},customExplanations:{pageName:`Defines the textual title label rendering in internal sidebars.`,iconName:`To modify this icon, visit https://iconoir.com/, find an icon, and copy its exact name (e.g. 'learning', 'server'). Then paste it here.`,template:`This just simply tells our app when a user clicks on the support page item what type of form do we load? is it a page or popup? this doesn't define form content! this setting just defines page layout.`,form:`This is the form that will be used. Go to /forms to edit it.`}})]})}),p&&!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=>ye(e,t.id,t.type===`admin`?oHn:t.type===`shared`?sHn:t.type===`public`?iHn:aHn),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)(rt,{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(),me(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:fe===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)(K9,{value:c[t.id],keysToRender:t.type===`public`?h(c[t.id]):g(c[t.id]),onChange:e=>he(t.id,e),isLast:!0,isGlobalSaving:u[t.id],customEnums:{form:t.type===`public`?U:ue,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)(We,{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:Oe,onCancel:()=>ke(!1),onConfirm:async()=>{Me(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,h.doc)(w,`sys_pages`,`home`)),e((0,h.doc)(w,`sys_pages`,`contact`)),e((0,h.doc)(w,`sys_tabs`,`support`))]),T(Zo),j(q9),ee(Jo)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{Me(!1),ke(!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:Ae}),(0,y.jsx)(m9,{isOpen:!!g,onCancel:()=>_(null),onConfirm:we,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 dHn(){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)(lt,{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 flex-col md:flex-row items-start md:items-center 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 w-full md:w-auto flex 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)(tt,{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)(nt,{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)(st,{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)(rt,{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)(K9,{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 fHn({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 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||`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||tt})(),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)(tt,{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)(tt,{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)(et,{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)(st,{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)(ft,{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 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,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||tt})(),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)(tt,{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)(tt,{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)(et,{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)(st,{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)(ft,{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 hHn({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||tt})(),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)(tt,{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)(tt,{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)(et,{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)(st,{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)(ft,{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 gHn(){let e=(0,b.useLocation)(),{user:t}=B(),[n,r]=(0,m.useState)(null),[i,a]=(0,m.useState)(!0);(0,m.useEffect)(()=>{(async()=>{a(!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`))]),i=null,a=null,o=(t,n)=>{t.forEach(t=>{let r=t.data(),o=r.route;o&&!o.startsWith(`/`)&&(o=`/`+o);let s=`/`+t.id===e.pathname;(o===e.pathname||s)&&(i={...r,isPrivate:n,isAdmin:r.pageType===`admin`,isShared:r.pageType===`shared`},a=t.id)})};if(o(t,!1),i||o(n,!0),i||(e.pathname===`/contact`?(i={route:`/contact`,template:`popup_form`,form:`contact`},a=`contact`):e.pathname===`/support`&&(i={route:`/support`,template:`popup_form`,form:`support`},a=`support`)),i){if((a===`contact`||a===`support`)&&!i.form&&(i.form=a),i.pageId=a,i.form){let e=await(0,h.getDoc)((0,h.doc)(w,`sys_forms`,i.form));if(e.exists())i.formConfigOverride={...e.data(),id:e.id};else if(i.form===`contact`){let{contactFormConfig:e}=await Promise.resolve().then(()=>require(`./contactForm.config-Dfh0WPXL.cjs`));i.formConfigOverride=e}else if(i.form===`support`){let{supportFormConfig:e}=await Promise.resolve().then(()=>require(`./supportForm.config-3dz3ymzX.cjs`));i.formConfigOverride=e}}let e=i.pageName||i.tabName||i.title;e&&(document.title=e),r(i)}else r(`not-found`)}catch{r(`not-found`)}finally{a(!1)}})()},[e.pathname]);let[o,s]=(0,m.useState)(!1);if((0,m.useEffect)(()=>{let e;return i?e=setTimeout(()=>s(!0),150):s(!1),()=>clearTimeout(e)},[i]),i)return o?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(n===`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((n.pageId===`support`||n.isPrivate)&&!t)return(0,y.jsx)(b.Navigate,{to:`/login`,state:{from:e}});let c=n.pageName?.toLowerCase().replace(/\s+/g,`_`)||n.pageId||`custom_page`,l=`pub_${c}`;if(n.template===`none`)return n.isAdmin?(0,y.jsx)(mHn,{config:n}):n.isShared?(0,y.jsx)(hHn,{config:n}):n.isPrivate?(0,y.jsx)(pHn,{config:n}):(0,y.jsx)(fHn,{config:n});if(n.template===`board`){let e=n.isAdmin?`admin_${n.pageId||c}`:n.isShared?`mem_${n.pageId||c}`:n.isPrivate?`user_${n.pageId||c}`:l;return(0,y.jsx)(GBn,{title:n.tabTitle||n.tabName||n.title||n.pageName||`Board`,subtitle:n.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:n})}if(n.template===`table`){let e=n.isAdmin?`admin_${n.pageId||c}`:n.isShared?`mem_${n.pageId||c}`:n.isPrivate?`user_${n.pageId||c}`:l;return(0,y.jsx)(XVn,{title:n.tabTitle||n.tabName||n.title||n.pageName||`Table`,subtitle:n.route,tableCollection:`${e}_table`,config:n})}if(n.template===`calendar`){let e=n.isAdmin?`admin_${n.pageId||c}`:n.isShared?`mem_${n.pageId||c}`:n.isPrivate?`user_${n.pageId||c}`:l;return(0,y.jsx)(QVn,{title:n.tabTitle||n.tabName||n.title||n.pageName||`Calendar`,subtitle:n.route,eventsCollection:`${e}_events`,defaultTimeFormat:n.defaultTimeFormat||n.defaulttimeformat||`12h`,config:n})}return n.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:n.form,formConfig:n.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:n.form,formConfig:n.formConfigOverride,onClose:()=>window.history.back()})})}var _Hn=`rules_version = '2';
506
+ };`;navigator.clipboard.writeText(a),c(!0),setTimeout(()=>c(!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&&g()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,m.useEffect)(()=>{if(!t?.colors)return;let e=(document.documentElement.getAttribute(`data-theme`)||`dark`)===`dark`?t.colors.dark:t.colors.light,n=document.documentElement;n.style.setProperty(`--bg-color`,e.background),e.backgroundSecondary&&n.style.setProperty(`--bg-secondary-color`,e.backgroundSecondary),n.style.setProperty(`--fg-color`,e.foreground),n.style.setProperty(`--accent-color`,e.accent),n.style.setProperty(`--accent-deep`,e.accentDeep),n.style.setProperty(`--panel-bg`,e.panelBg),n.style.setProperty(`--panel-border`,e.panelBorder),n.style.setProperty(`--button-bg`,`linear-gradient(135deg, ${e.buttonGradient[0]} 0%, ${e.buttonGradient[1]} 100%)`),n.style.setProperty(`--button-hover-bg`,`linear-gradient(135deg, ${e.buttonHoverGradient?.[0]||e.buttonGradient[0]} 0%, ${e.buttonHoverGradient?.[1]||e.buttonGradient[1]} 100%)`),n.style.setProperty(`--text-gradient`,`linear-gradient(135deg, ${e.textGradient[0]} 0%, ${e.textGradient[1]} 50%, ${e.textGradient[2]} 100%)`),n.style.setProperty(`--glow-color`,e.glowColor||`rgba(124, 58, 237, 0.3)`),n.style.setProperty(`--button-fg`,e.buttonText||`#ffffff`),e.notificationIconColor&&n.style.setProperty(`--notification-icon-color`,e.notificationIconColor)},[t]),(0,m.useEffect)(()=>()=>{if(!e?.colors)return;let t=(document.documentElement.getAttribute(`data-theme`)||`dark`)===`dark`?e.colors.dark:e.colors.light,n=document.documentElement;n.style.setProperty(`--bg-color`,t.background),t.backgroundSecondary&&n.style.setProperty(`--bg-secondary-color`,t.backgroundSecondary),n.style.setProperty(`--fg-color`,t.foreground),n.style.setProperty(`--accent-color`,t.accent),n.style.setProperty(`--accent-deep`,t.accentDeep),n.style.setProperty(`--panel-bg`,t.panelBg),n.style.setProperty(`--panel-border`,t.panelBorder),n.style.setProperty(`--button-bg`,`linear-gradient(135deg, ${t.buttonGradient[0]} 0%, ${t.buttonGradient[1]} 100%)`),n.style.setProperty(`--button-hover-bg`,`linear-gradient(135deg, ${t.buttonHoverGradient?.[0]||t.buttonGradient[0]} 0%, ${t.buttonHoverGradient?.[1]||t.buttonGradient[1]} 100%)`),n.style.setProperty(`--text-gradient`,`linear-gradient(135deg, ${t.textGradient[0]} 0%, ${t.textGradient[1]} 50%, ${t.textGradient[2]} 100%)`),n.style.setProperty(`--glow-color`,t.glowColor||`rgba(124, 58, 237, 0.3)`),n.style.setProperty(`--button-fg`,t.buttonText||`#ffffff`),t.notificationIconColor&&n.style.setProperty(`--notification-icon-color`,t.notificationIconColor)},[e]),(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 flex-col md:flex-row items-start md:items-center 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 w-full md:w-auto shrink-0`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:d,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)(rt,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,y.jsx)(Z,{variant:`secondary`,onClick:g,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:s?(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`}),eHn.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:()=>p(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)(K9,{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)(K9,{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 q9={route:`/contact`,template:`popup_form`,form:`contact`,pageName:`Contact`},iHn={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},aHn={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`},oHn={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`},sHn={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`},cHn=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0},{id:`contact`,title:`Contact`,path:`/contact`,type:`public`,isSystem:!0,enabled:!0},{id:`support`,title:`Request Support`,path:`/support`,type:`private`,isSystem:!0,enabled:!0}],lHn=({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 uHn(){let{userRole:e}=B(),t=(0,b.useLocation)(),[n,r]=(0,m.useState)(cHn),[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)(null),[M,N]=(0,m.useState)(!1),[P,F]=(0,m.useState)(!1),[I,ee]=(0,m.useState)(null),[L,R]=(0,m.useState)(!1),[te,z]=(0,m.useState)(!1),[ne,re]=(0,m.useState)(new Set),[V,ie]=(0,m.useState)(new Set),[H,ae]=(0,m.useState)([]),[oe,se]=(0,m.useState)([]),ce=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=ce(e.exists()&&e.data().order||[]);ae(t),re(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=ce(e.exists()&&e.data().order||[]);se(t),ie(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(Zo,t.data()):Zo)}),n=(0,h.onSnapshot)((0,h.doc)(w,`sys_pages`,`contact`),t=>{j(t.exists()?e(q9,t.data()):q9)}),r=(0,h.onSnapshot)((0,h.doc)(w,`sys_tabs`,`support`),t=>{ee(t.exists()?e(Jo,t.data()):Jo)});return()=>{t(),n(),r()}},[]),(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[U,le]=(0,m.useState)([`contact`]),[ue,de]=(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&&le(t),n.length>0&&de(n)}).catch(console.error)},[]);let[fe,pe]=(0,m.useState)(null),me=(e,t)=>{let n=JSON.stringify(t,null,2);navigator.clipboard.writeText(n),pe(e),setTimeout(()=>pe(null),2e3)},he=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`,`contact`,`support`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?D(!0):e===`contact`?N(!0):e===`support`?R(!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?H:oe;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):e===`contact`?j(t):e===`support`?ee(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):e===`contact`?N(!1):e===`support`?R(!1):d(t=>({...t,[e]:!1,[c]:!1}))},500)}},ge=async e=>{e.stopPropagation(),k(!0),await he(`home`,Zo),setTimeout(()=>k(!1),500)},_e=async e=>{e.stopPropagation(),F(!0),await he(`contact`,q9),setTimeout(()=>F(!1),500)},ve=async e=>{e.stopPropagation(),z(!0),await he(`support`,Jo),setTimeout(()=>z(!1),500)},ye=async(e,t,n)=>{e.stopPropagation(),p(e=>({...e,[t]:!0})),await he(t,n),setTimeout(()=>p(e=>({...e,[t]:!1})),500)},be=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={...iHn}:e===`private`?i={...aHn}:e===`admin`?i={...oHn}:e===`shared`&&(i={...sHn}),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)(at,{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 Se=async(e,t,i)=>{let a=i===`public`,o=a?`page_order`:`tab_order`,s=a?H:oe,c=(a?ne:V).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})},Ce=(e,t)=>{t||_(e)},we=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`?H:oe,{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)}},Te=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===`contact`&&(i=A||q9),e.id===`support`&&(i=I||Jo));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:Ye,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:at,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[Oe,ke]=(0,m.useState)(!1),[Ae,Me]=(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 flex-col md:flex-row items-start md:items-center 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 w-full md:w-auto flex justify-end gap-1`,children:[(0,y.jsx)(Z,{variant:`secondary`,onClick:()=>ke(!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)(rt,{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)(tt,{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:()=>{be(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:Ae&&(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`?H:oe,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`?ne.has(e.id):V.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=t.id===`contact`,l=t.id===`support`,p=i===t.id,m=o||s||l||!t.isSystem;return(0,y.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(m){let e=p?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 ${m?`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||s&&M||l&&L)&&(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(),Te(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)(lHn,{enabled:!d(t),onChange:()=>Se(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(),Ce(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)(st,{className:`w-4 h-4`})}),m?(0,y.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${p?`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:[p&&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:ge,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)(rt,{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(),me(`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:fe===`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)(K9,{value:C,keysToRender:[`hero`],onChange:e=>he(`home`,e),isLast:!0,isGlobalSaving:E,customEnums:{form:U},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.`}})]})}),p&&s&&A&&(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,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:P?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)(rt,{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(),me(`contact`,A)},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:fe===`contact`?(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)(K9,{value:A,keysToRender:A.showButton===!1?[`pageName`,`route`,`template`,`showButton`]:[`pageName`,`route`,`template`,`showButton`,`form`],disabledKeys:[`route`],onChange:e=>he(`contact`,e),isLast:!0,isGlobalSaving:M,customEnums:{form:U,template:[`popup_form`,`inline_form`]},customExplanations:{pageName:`This defines the text that actually appears globally in the Navigation menus.`,template:`This just simply tells our app when a user clicks on the contact page item what type of form do we load? is it a page or popup? this doesn't define form content! this setting just defines page layout.`,form:`This is the form that will be used. Go to /forms to edit it.`}})]})}),p&&l&&I&&(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:ve,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:te?(0,y.jsx)(W,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,y.jsx)(rt,{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(),me(`support`,I)},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:fe===`support`?(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)(K9,{value:I,keysToRender:I.showButton===!1?[`pageName`,`iconName`,`route`,`template`,`showButton`]:[`pageName`,`iconName`,`route`,`template`,`showButton`,`form`],disabledKeys:[`route`],onChange:e=>he(`support`,e),isLast:!0,isGlobalSaving:L,customEnums:{form:ue,template:[`popup_form`,`inline_form`]},customExplanations:{pageName:`Defines the textual title label rendering in internal sidebars.`,iconName:`To modify this icon, visit https://iconoir.com/, find an icon, and copy its exact name (e.g. 'learning', 'server'). Then paste it here.`,template:`This just simply tells our app when a user clicks on the support page item what type of form do we load? is it a page or popup? this doesn't define form content! this setting just defines page layout.`,form:`This is the form that will be used. Go to /forms to edit it.`}})]})}),p&&!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=>ye(e,t.id,t.type===`admin`?oHn:t.type===`shared`?sHn:t.type===`public`?iHn:aHn),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)(rt,{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(),me(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:fe===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)(K9,{value:c[t.id],keysToRender:t.type===`public`?h(c[t.id]):g(c[t.id]),onChange:e=>he(t.id,e),isLast:!0,isGlobalSaving:u[t.id],customEnums:{form:t.type===`public`?U:ue,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)(We,{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:Oe,onCancel:()=>ke(!1),onConfirm:async()=>{Me(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,h.doc)(w,`sys_pages`,`home`)),e((0,h.doc)(w,`sys_pages`,`contact`)),e((0,h.doc)(w,`sys_tabs`,`support`))]),T(Zo),j(q9),ee(Jo)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{Me(!1),ke(!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:Ae}),(0,y.jsx)(m9,{isOpen:!!g,onCancel:()=>_(null),onConfirm:we,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 dHn(){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)(lt,{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 flex-col md:flex-row items-start md:items-center 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 w-full md:w-auto flex 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)(tt,{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)(nt,{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)(st,{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)(rt,{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)(K9,{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 fHn({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 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||`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||tt})(),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)(tt,{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)(tt,{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)(et,{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)(st,{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)(ft,{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 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,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||tt})(),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)(tt,{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)(tt,{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)(et,{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)(st,{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)(ft,{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 hHn({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||tt})(),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)(tt,{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)(tt,{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)(et,{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)(st,{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)(ft,{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 gHn(){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-Dfh0WPXL.cjs`));r.formConfigOverride=e}else if(r.form===`support`){let{supportFormConfig:e}=await Promise.resolve().then(()=>require(`./supportForm.config-3dz3ymzX.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)(mHn,{config:r}):r.isShared?(0,y.jsx)(hHn,{config:r}):r.isPrivate?(0,y.jsx)(pHn,{config:r}):(0,y.jsx)(fHn,{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||QVn,{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 _Hn=`rules_version = '2';
507
507
  service cloud.firestore {
508
508
  match /databases/{database}/documents {
509
509
 
@@ -615,19 +615,4 @@ VITE_ADMIN_EMAILS=your@email.com,other@email.com`;function EHn({code:e,label:t})
615
615
  storageBucket: "myproject.firebasestorage.app",
616
616
  messagingSenderId: "123456789012",
617
617
  appId: "1:123456789012:web:abcdef123456"
618
- };`})})]}),(0,y.jsxs)(Y9,{title:`Configure your .env file`,children:[(0,y.jsxs)(`p`,{children:[`Open the `,(0,y.jsx)(`code`,{className:`text-accent font-bold text-[13px]`,children:`.env`}),` file in your source code root. Map the keys from your Firebase Web SDK to the `,(0,y.jsx)(`code`,{className:`bg-foreground/5 rounded px-2 py-0.5 font-mono text-[11px]`,children:`VITE_ FIREBASE_`}),` variables.`]}),(0,y.jsxs)(`p`,{className:`text-[13px] bg-accent/10 border border-accent/20 p-3 rounded-xl mt-2 text-foreground/80`,children:[(0,y.jsx)(`strong`,{children:`Important:`}),` Provide your own emails in `,(0,y.jsx)(`code`,{className:`bg-background/80 rounded px-1.5 py-0.5 font-mono text-[11px]`,children:`VITE_ADMIN_EMAILS`}),` separated by commas. These users will automatically get full admin privileges upon their first registration. No quotes or spaces!`]}),(0,y.jsx)(DHn,{code:THn})]}),(0,y.jsx)(Y9,{title:`Enable Authentication`,children:(0,y.jsxs)(`p`,{children:[`1. In Firebase console Sidebar, go to `,(0,y.jsx)(`strong`,{children:`Product categories`}),` → `,(0,y.jsx)(`strong`,{children:`Security`}),` → `,(0,y.jsx)(`strong`,{children:`Authentication`}),`. Click `,(0,y.jsx)(`strong`,{children:`Get Started`}),`. `,(0,y.jsx)(`br`,{}),`2. Click the `,(0,y.jsx)(`strong`,{children:`Sign-in method`}),` tab. `,(0,y.jsx)(`br`,{}),`3. Enable `,(0,y.jsx)(`strong`,{children:`Email/Password`}),` (no need to enable email links). `,(0,y.jsx)(`br`,{}),`4. Enable `,(0,y.jsx)(`strong`,{children:`Google`}),`. `,(0,y.jsx)(`br`,{}),`5. Enable `,(0,y.jsx)(`strong`,{children:`Anonymous`}),`.`]})}),(0,y.jsxs)(Y9,{title:`Create Firestore Database`,children:[(0,y.jsxs)(`p`,{children:[`1. In the Sidebar, go to `,(0,y.jsx)(`strong`,{children:`Product categories`}),` → `,(0,y.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,y.jsx)(`strong`,{children:`Firestore`}),`. Click `,(0,y.jsx)(`strong`,{children:`Create database`}),`. `,(0,y.jsx)(`br`,{}),`2. Keep the default location and start in `,(0,y.jsx)(`strong`,{children:`Production mode`}),`. `,(0,y.jsx)(`br`,{}),`3. Go to the `,(0,y.jsx)(`strong`,{children:`Rules`}),` tab, paste the rules below, and click `,(0,y.jsx)(`strong`,{children:`Publish`}),`.`]}),(0,y.jsx)(EHn,{code:CHn,label:`Copy Firestore Rules`})]}),(0,y.jsxs)(Y9,{title:`Configure Storage (Optional but Recommended)`,children:[(0,y.jsxs)(`p`,{children:[`1. In the Sidebar, go to `,(0,y.jsx)(`strong`,{children:`Product categories`}),` → `,(0,y.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,y.jsx)(`strong`,{children:`Storage`}),`. Click `,(0,y.jsx)(`strong`,{children:`Get started`}),`. Start in production mode. `,(0,y.jsx)(`br`,{}),`2. Once created, copy the bucket URL (e.g. `,(0,y.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`your-project.firebasestorage.app`}),`) and paste it into `,(0,y.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`VITE_FIREBASE_STORAGE_BUCKET`}),` in your `,(0,y.jsx)(`code`,{className:`text-[13px] font-bold`,children:`.env`}),`. `,(0,y.jsx)(`br`,{}),`3. In Firebase Storage, go to the `,(0,y.jsx)(`strong`,{children:`Rules`}),` tab, paste tracking rules, and click `,(0,y.jsx)(`strong`,{children:`Publish`}),`.`]}),(0,y.jsx)(EHn,{code:wHn,label:`Copy Storage Rules`}),(0,y.jsx)(`p`,{className:`text-[12px] mt-4 opacity-60 font-medium border-l-2 border-foreground/20 pl-3`,children:`Note: Storage rules require the Blaze pay-as-you-go plan, but there are large free tiers so you won't be charged for development usage.`})]})]})]})})]})}function kHn(){let{user:e}=B(),t=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],n=t.charAt(0).toUpperCase()+t.slice(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.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,y.jsxs)(`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:[`Welcome back, `,n,`.`]}),(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`}),`/dashboard`]})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,y.jsx)(`div`,{className:`flex justify-start`,children:(0,y.jsx)(p9,{})}),(0,y.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl p-8 md:p-12 flex items-center justify-center relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,y.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),(0,y.jsx)(K,{mode:`wait`,children:(0,y.jsxs)(q.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.3},className:`text-center z-10`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-3xl bg-accent/10 border border-accent/20 flex items-center justify-center text-accent mx-auto mb-6 shadow-inner`,children:(0,y.jsx)(Me,{className:`w-6 h-6`})}),(0,y.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,y.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var X9=()=>(0,y.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center min-h-[60vh] z-10 animate-in fade-in duration-500`,children:[(0,y.jsx)(`div`,{className:`w-12 h-12 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mb-6 shadow-xl`,children:(0,y.jsx)(Me,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,y.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,y.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,y.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function Z9({children:e}){let{user:t,loading:n,userInactive:r,signOut:i,roleResolved:a}=B(),o=(0,b.useLocation)();return n||!a?(0,y.jsx)(X9,{}):t?r?(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500`,children:(0,y.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,y.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,y.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,y.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,y.jsx)(`button`,{onClick:()=>i(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?(0,y.jsx)(y.Fragment,{children:e}):(0,y.jsx)(b.Navigate,{to:`/verify`}):(0,y.jsx)(b.Navigate,{to:`/login?from=${encodeURIComponent(o.pathname)}`})}function Q9({children:e}){let{user:t,loading:n,roleResolved:r}=B(),[i]=(0,b.useSearchParams)();return n||!r?(0,y.jsx)(X9,{}):t&&t.emailVerified?(0,y.jsx)(b.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,y.jsx)(y.Fragment,{children:e})}function AHn({children:e}){let{user:t,loading:n,roleResolved:r}=B();return n||!r?(0,y.jsx)(X9,{}):t?t.emailVerified?(0,y.jsx)(b.Navigate,{to:`/dashboard`}):(0,y.jsx)(y.Fragment,{children:e}):(0,y.jsx)(b.Navigate,{to:`/`})}function $9({children:e}){let{user:t,userRole:n,loading:r,userInactive:i,signOut:a,roleResolved:o}=B(),s=(0,b.useLocation)();return r||!o?(0,y.jsx)(X9,{}):t?i?(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500`,children:(0,y.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,y.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,y.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,y.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,y.jsx)(`button`,{onClick:()=>a(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?n===`admin`?(0,y.jsx)(y.Fragment,{children:e}):(0,y.jsx)(b.Navigate,{to:`/dashboard`}):(0,y.jsx)(b.Navigate,{to:`/verify`}):(0,y.jsx)(b.Navigate,{to:`/login?from=${encodeURIComponent(s.pathname)}`})}function jHn(){return(0,y.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,y.jsx)(q.div,{animate:{scale:[1,1.1,1],opacity:[.6,1,.6]},transition:{duration:12,repeat:1/0,ease:`easeInOut`},className:`absolute -top-[30%] md:-top-[400px] -right-[10%] md:-right-[200px] w-[500px] md:w-[800px] h-[500px] md:h-[800px] rounded-full bg-decorator-1 blur-[80px] md:blur-[120px]`}),(0,y.jsx)(q.div,{animate:{scale:[1,1.2,1],opacity:[.5,.9,.5]},transition:{duration:18,repeat:1/0,ease:`easeInOut`,delay:2},className:`absolute -bottom-[20%] md:-bottom-[300px] -left-[10%] md:-left-[100px] w-[400px] md:w-[600px] h-[400px] md:h-[600px] rounded-full bg-decorator-2 blur-[60px] md:blur-[100px]`})]})}function MHn(){return(0,y.jsx)(z,{children:(0,y.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,y.jsx)(Xo,{}),(0,y.jsxs)(b.Routes,{children:[(0,y.jsx)(b.Route,{path:`/`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(Gse,{})})}),(0,y.jsx)(b.Route,{path:`/register`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(Kse,{})})}),(0,y.jsx)(b.Route,{path:`/login`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(qse,{})})}),(0,y.jsx)(b.Route,{path:`/reset-password`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(bBn,{})})}),(0,y.jsx)(b.Route,{path:`/verify`,element:(0,y.jsx)(AHn,{children:(0,y.jsx)(Jse,{})})}),(0,y.jsx)(b.Route,{path:`/templates`,element:(0,y.jsx)(OBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/inline_form`,element:(0,y.jsx)(kBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/popup_form`,element:(0,y.jsx)(ABn,{})}),(0,y.jsx)(b.Route,{path:`/templates/confirmation`,element:(0,y.jsx)(jBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/board`,element:(0,y.jsx)(GBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/table`,element:(0,y.jsx)(XVn,{})}),(0,y.jsx)(b.Route,{path:`/templates/calendar`,element:(0,y.jsx)(QVn,{})}),(0,y.jsx)(b.Route,{path:`/users`,element:(0,y.jsx)($9,{children:(0,y.jsx)(xBn,{})})}),(0,y.jsx)(b.Route,{path:`/users/:id`,element:(0,y.jsx)($9,{children:(0,y.jsx)(xBn,{})})}),(0,y.jsx)(b.Route,{path:`/submissions`,element:(0,y.jsx)($9,{children:(0,y.jsx)(TBn,{})})}),(0,y.jsx)(b.Route,{path:`/requests`,element:(0,y.jsx)($9,{children:(0,y.jsx)(EBn,{})})}),(0,y.jsx)(b.Route,{path:`/drive/*`,element:(0,y.jsx)(Z9,{children:(0,y.jsx)(DBn,{})})}),(0,y.jsx)(b.Route,{path:`/theme`,element:(0,y.jsx)($9,{children:(0,y.jsx)(rHn,{})})}),(0,y.jsx)(b.Route,{path:`/pages/*`,element:(0,y.jsx)($9,{children:(0,y.jsx)(uHn,{})})}),(0,y.jsx)(b.Route,{path:`/forms/*`,element:(0,y.jsx)($9,{children:(0,y.jsx)(dHn,{})})}),(0,y.jsx)(b.Route,{path:`/settings`,element:(0,y.jsx)($9,{children:(0,y.jsx)(wBn,{})})}),(0,y.jsx)(b.Route,{path:`/profile`,element:(0,y.jsx)(Z9,{children:(0,y.jsx)(yBn,{})})}),(0,y.jsx)(b.Route,{path:`/dashboard`,element:(0,y.jsx)(Z9,{children:(0,y.jsx)(kHn,{})})}),(0,y.jsx)(b.Route,{path:`/setup`,element:(0,y.jsx)(OHn,{})}),(0,y.jsx)(b.Route,{path:`*`,element:(0,y.jsx)(gHn,{})})]}),(0,y.jsx)(jHn,{})]})})}function NHn(){return(0,y.jsx)(b.BrowserRouter,{children:(0,y.jsx)(PHn,{})})}function PHn(){let e=R();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||SHn()?(0,y.jsx)(MHn,{}):(0,y.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,y.jsx)(Xo,{standalone:!0}),(0,y.jsx)(OHn,{standalone:!0}),(0,y.jsx)(jHn,{})]})}function FHn(e){return e.firebaseConfig&&E(e.firebaseConfig),(0,y.jsx)(L,{config:{firebaseConfig:e.firebaseConfig,adminEmails:e.adminEmails,basename:e.basename,onAuthChange:e.onAuthChange},children:(0,y.jsx)(F,{scopeSelector:`.firebase-os`,children:(0,y.jsxs)(`div`,{className:`firebase-os`,style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,zIndex:9999,overflowY:`auto`,overflowX:`hidden`,textAlign:`left`,margin:0,padding:0},children:[(0,y.jsx)(`style`,{children:`
619
- /* Defensive Typography Reset: Specificity 0,0,0 */
620
- /* This ensures we provide base styles without overriding ANY utility classes */
621
- :where(.firebase-os) :where(h1, h2, h3, h4, h5, h6, p, span, li, label, a, td, th) {
622
- color: var(--fg-color);
623
- font-family: var(--font-family, 'Inter', system-ui, sans-serif);
624
- }
625
- :where(.firebase-os) :where(h1, h2, h3, h4, h5, h6, p) {
626
- margin: 0;
627
- }
628
- :where(.firebase-os) :where(code, pre) {
629
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
630
- background: transparent;
631
- border: none;
632
- }
633
- `}),(0,y.jsx)(NHn,{})]})})})}exports.FirebaseOS=FHn,exports.t=u,exports.useAuth=B,exports.useConfig=R,exports.useTheme=I;
618
+ };`})})]}),(0,y.jsxs)(Y9,{title:`Configure your .env file`,children:[(0,y.jsxs)(`p`,{children:[`Open the `,(0,y.jsx)(`code`,{className:`text-accent font-bold text-[13px]`,children:`.env`}),` file in your source code root. Map the keys from your Firebase Web SDK to the `,(0,y.jsx)(`code`,{className:`bg-foreground/5 rounded px-2 py-0.5 font-mono text-[11px]`,children:`VITE_ FIREBASE_`}),` variables.`]}),(0,y.jsxs)(`p`,{className:`text-[13px] bg-accent/10 border border-accent/20 p-3 rounded-xl mt-2 text-foreground/80`,children:[(0,y.jsx)(`strong`,{children:`Important:`}),` Provide your own emails in `,(0,y.jsx)(`code`,{className:`bg-background/80 rounded px-1.5 py-0.5 font-mono text-[11px]`,children:`VITE_ADMIN_EMAILS`}),` separated by commas. These users will automatically get full admin privileges upon their first registration. No quotes or spaces!`]}),(0,y.jsx)(DHn,{code:THn})]}),(0,y.jsx)(Y9,{title:`Enable Authentication`,children:(0,y.jsxs)(`p`,{children:[`1. In Firebase console Sidebar, go to `,(0,y.jsx)(`strong`,{children:`Product categories`}),` → `,(0,y.jsx)(`strong`,{children:`Security`}),` → `,(0,y.jsx)(`strong`,{children:`Authentication`}),`. Click `,(0,y.jsx)(`strong`,{children:`Get Started`}),`. `,(0,y.jsx)(`br`,{}),`2. Click the `,(0,y.jsx)(`strong`,{children:`Sign-in method`}),` tab. `,(0,y.jsx)(`br`,{}),`3. Enable `,(0,y.jsx)(`strong`,{children:`Email/Password`}),` (no need to enable email links). `,(0,y.jsx)(`br`,{}),`4. Enable `,(0,y.jsx)(`strong`,{children:`Google`}),`. `,(0,y.jsx)(`br`,{}),`5. Enable `,(0,y.jsx)(`strong`,{children:`Anonymous`}),`.`]})}),(0,y.jsxs)(Y9,{title:`Create Firestore Database`,children:[(0,y.jsxs)(`p`,{children:[`1. In the Sidebar, go to `,(0,y.jsx)(`strong`,{children:`Product categories`}),` → `,(0,y.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,y.jsx)(`strong`,{children:`Firestore`}),`. Click `,(0,y.jsx)(`strong`,{children:`Create database`}),`. `,(0,y.jsx)(`br`,{}),`2. Keep the default location and start in `,(0,y.jsx)(`strong`,{children:`Production mode`}),`. `,(0,y.jsx)(`br`,{}),`3. Go to the `,(0,y.jsx)(`strong`,{children:`Rules`}),` tab, paste the rules below, and click `,(0,y.jsx)(`strong`,{children:`Publish`}),`.`]}),(0,y.jsx)(EHn,{code:CHn,label:`Copy Firestore Rules`})]}),(0,y.jsxs)(Y9,{title:`Configure Storage (Optional but Recommended)`,children:[(0,y.jsxs)(`p`,{children:[`1. In the Sidebar, go to `,(0,y.jsx)(`strong`,{children:`Product categories`}),` → `,(0,y.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,y.jsx)(`strong`,{children:`Storage`}),`. Click `,(0,y.jsx)(`strong`,{children:`Get started`}),`. Start in production mode. `,(0,y.jsx)(`br`,{}),`2. Once created, copy the bucket URL (e.g. `,(0,y.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`your-project.firebasestorage.app`}),`) and paste it into `,(0,y.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`VITE_FIREBASE_STORAGE_BUCKET`}),` in your `,(0,y.jsx)(`code`,{className:`text-[13px] font-bold`,children:`.env`}),`. `,(0,y.jsx)(`br`,{}),`3. In Firebase Storage, go to the `,(0,y.jsx)(`strong`,{children:`Rules`}),` tab, paste tracking rules, and click `,(0,y.jsx)(`strong`,{children:`Publish`}),`.`]}),(0,y.jsx)(EHn,{code:wHn,label:`Copy Storage Rules`}),(0,y.jsx)(`p`,{className:`text-[12px] mt-4 opacity-60 font-medium border-l-2 border-foreground/20 pl-3`,children:`Note: Storage rules require the Blaze pay-as-you-go plan, but there are large free tiers so you won't be charged for development usage.`})]})]})]})})]})}function kHn(){let{user:e}=B(),t=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],n=t.charAt(0).toUpperCase()+t.slice(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.jsxs)(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,y.jsxs)(`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:[`Welcome back, `,n,`.`]}),(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`}),`/dashboard`]})]}),(0,y.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,y.jsx)(`div`,{className:`flex justify-start`,children:(0,y.jsx)(p9,{})}),(0,y.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl p-8 md:p-12 flex items-center justify-center relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,y.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),(0,y.jsx)(K,{mode:`wait`,children:(0,y.jsxs)(q.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.3},className:`text-center z-10`,children:[(0,y.jsx)(`div`,{className:`w-16 h-16 rounded-3xl bg-accent/10 border border-accent/20 flex items-center justify-center text-accent mx-auto mb-6 shadow-inner`,children:(0,y.jsx)(Me,{className:`w-6 h-6`})}),(0,y.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,y.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var X9=()=>(0,y.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center min-h-[60vh] z-10 animate-in fade-in duration-500`,children:[(0,y.jsx)(`div`,{className:`w-12 h-12 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mb-6 shadow-xl`,children:(0,y.jsx)(Me,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,y.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,y.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,y.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function Z9({children:e}){let{user:t,loading:n,userInactive:r,signOut:i,roleResolved:a}=B(),o=(0,b.useLocation)();return n||!a?(0,y.jsx)(X9,{}):t?r?(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500`,children:(0,y.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,y.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,y.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,y.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,y.jsx)(`button`,{onClick:()=>i(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?(0,y.jsx)(y.Fragment,{children:e}):(0,y.jsx)(b.Navigate,{to:`/verify`}):(0,y.jsx)(b.Navigate,{to:`/login?from=${encodeURIComponent(o.pathname)}`})}function Q9({children:e}){let{user:t,loading:n,roleResolved:r}=B(),[i]=(0,b.useSearchParams)();return n||!r?(0,y.jsx)(X9,{}):t&&t.emailVerified?(0,y.jsx)(b.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,y.jsx)(y.Fragment,{children:e})}function AHn({children:e}){let{user:t,loading:n,roleResolved:r}=B();return n||!r?(0,y.jsx)(X9,{}):t?t.emailVerified?(0,y.jsx)(b.Navigate,{to:`/dashboard`}):(0,y.jsx)(y.Fragment,{children:e}):(0,y.jsx)(b.Navigate,{to:`/`})}function $9({children:e}){let{user:t,userRole:n,loading:r,userInactive:i,signOut:a,roleResolved:o}=B(),s=(0,b.useLocation)();return r||!o?(0,y.jsx)(X9,{}):t?i?(0,y.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500`,children:(0,y.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,y.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,y.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,y.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,y.jsx)(`button`,{onClick:()=>a(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?n===`admin`?(0,y.jsx)(y.Fragment,{children:e}):(0,y.jsx)(b.Navigate,{to:`/dashboard`}):(0,y.jsx)(b.Navigate,{to:`/verify`}):(0,y.jsx)(b.Navigate,{to:`/login?from=${encodeURIComponent(s.pathname)}`})}function jHn(){return(0,y.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,y.jsx)(q.div,{animate:{scale:[1,1.1,1],opacity:[.6,1,.6]},transition:{duration:12,repeat:1/0,ease:`easeInOut`},className:`absolute -top-[30%] md:-top-[400px] -right-[10%] md:-right-[200px] w-[500px] md:w-[800px] h-[500px] md:h-[800px] rounded-full bg-decorator-1 blur-[80px] md:blur-[120px]`}),(0,y.jsx)(q.div,{animate:{scale:[1,1.2,1],opacity:[.5,.9,.5]},transition:{duration:18,repeat:1/0,ease:`easeInOut`,delay:2},className:`absolute -bottom-[20%] md:-bottom-[300px] -left-[10%] md:-left-[100px] w-[400px] md:w-[600px] h-[400px] md:h-[600px] rounded-full bg-decorator-2 blur-[60px] md:blur-[100px]`})]})}function MHn(){let e=R().components?.Home||Gse;return(0,y.jsx)(z,{children:(0,y.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,y.jsx)(Xo,{}),(0,y.jsxs)(b.Routes,{children:[(0,y.jsx)(b.Route,{path:`/`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(e,{})})}),(0,y.jsx)(b.Route,{path:`/register`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(Kse,{})})}),(0,y.jsx)(b.Route,{path:`/login`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(qse,{})})}),(0,y.jsx)(b.Route,{path:`/reset-password`,element:(0,y.jsx)(Q9,{children:(0,y.jsx)(bBn,{})})}),(0,y.jsx)(b.Route,{path:`/verify`,element:(0,y.jsx)(AHn,{children:(0,y.jsx)(Jse,{})})}),(0,y.jsx)(b.Route,{path:`/templates`,element:(0,y.jsx)(OBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/inline_form`,element:(0,y.jsx)(kBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/popup_form`,element:(0,y.jsx)(ABn,{})}),(0,y.jsx)(b.Route,{path:`/templates/confirmation`,element:(0,y.jsx)(jBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/board`,element:(0,y.jsx)(GBn,{})}),(0,y.jsx)(b.Route,{path:`/templates/table`,element:(0,y.jsx)(XVn,{})}),(0,y.jsx)(b.Route,{path:`/templates/calendar`,element:(0,y.jsx)(QVn,{})}),(0,y.jsx)(b.Route,{path:`/users`,element:(0,y.jsx)($9,{children:(0,y.jsx)(xBn,{})})}),(0,y.jsx)(b.Route,{path:`/users/:id`,element:(0,y.jsx)($9,{children:(0,y.jsx)(xBn,{})})}),(0,y.jsx)(b.Route,{path:`/submissions`,element:(0,y.jsx)($9,{children:(0,y.jsx)(TBn,{})})}),(0,y.jsx)(b.Route,{path:`/requests`,element:(0,y.jsx)($9,{children:(0,y.jsx)(EBn,{})})}),(0,y.jsx)(b.Route,{path:`/drive/*`,element:(0,y.jsx)(Z9,{children:(0,y.jsx)(DBn,{})})}),(0,y.jsx)(b.Route,{path:`/theme`,element:(0,y.jsx)($9,{children:(0,y.jsx)(rHn,{})})}),(0,y.jsx)(b.Route,{path:`/pages/*`,element:(0,y.jsx)($9,{children:(0,y.jsx)(uHn,{})})}),(0,y.jsx)(b.Route,{path:`/forms/*`,element:(0,y.jsx)($9,{children:(0,y.jsx)(dHn,{})})}),(0,y.jsx)(b.Route,{path:`/settings`,element:(0,y.jsx)($9,{children:(0,y.jsx)(wBn,{})})}),(0,y.jsx)(b.Route,{path:`/profile`,element:(0,y.jsx)(Z9,{children:(0,y.jsx)(yBn,{})})}),(0,y.jsx)(b.Route,{path:`/dashboard`,element:(0,y.jsx)(Z9,{children:(0,y.jsx)(kHn,{})})}),(0,y.jsx)(b.Route,{path:`/setup`,element:(0,y.jsx)(OHn,{})}),(0,y.jsx)(b.Route,{path:`*`,element:(0,y.jsx)(gHn,{})})]}),(0,y.jsx)(jHn,{})]})})}function NHn(){return(0,y.jsx)(b.BrowserRouter,{children:(0,y.jsx)(PHn,{})})}function PHn(){let e=R();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||SHn()?(0,y.jsx)(MHn,{}):(0,y.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,y.jsx)(Xo,{standalone:!0}),(0,y.jsx)(OHn,{standalone:!0}),(0,y.jsx)(jHn,{})]})}function FHn(e){return e.firebaseConfig&&E(e.firebaseConfig),(0,y.jsx)(L,{config:{firebaseConfig:e.firebaseConfig,adminEmails:e.adminEmails,basename:e.basename,onAuthChange:e.onAuthChange,themeConfig:e.themeConfig,components:e.components},children:(0,y.jsx)(F,{scopeSelector:`.firebase-os`,children:(0,y.jsx)(`div`,{className:`firebase-os flex-1 flex flex-col min-h-screen`,children:(0,y.jsx)(NHn,{})})})})}exports.ContactPopup=Wo,exports.FirebaseOS=FHn,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return w}}),exports.defaultHomeConfig=Zo,Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return T}}),exports.t=u,exports.useAuth=B,exports.useConfig=R,exports.useTheme=I;